-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: fee calculation logic and improve modularity.
- Loading branch information
Showing
5 changed files
with
71 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { BN } from "@polkadot/util"; | ||
|
||
/// Recreation of fees.ration(burn_part, treasury_part) | ||
export const split = (value: BN, part1: BN, part2: BN): [BN, BN] => { | ||
const total = part1.add(part2); | ||
if (total.eq(new BN(0)) || value.eq(new BN(0))) { | ||
return [new BN(0), new BN(0)]; | ||
} | ||
const part1BN = value.mul(part1).div(total); | ||
const part2BN = value.sub(part1BN); | ||
return [part1BN, part2BN]; | ||
}; | ||
|
||
export const calculateFeePortions = ( | ||
feesTreasuryProportion: bigint, | ||
fees: bigint | ||
): { | ||
burnt: bigint; | ||
treasury: bigint; | ||
} => { | ||
const feesBN = new BN(fees.toString()); | ||
const treasuryPartBN = new BN(feesTreasuryProportion.toString()); | ||
const burntPartBN = new BN(1e9).sub(treasuryPartBN); | ||
|
||
const [burntBN, treasuryBN] = split(feesBN, burntPartBN, treasuryPartBN); | ||
|
||
return { | ||
burnt: BigInt(burntBN.toString()), | ||
treasury: BigInt(treasuryBN.toString()), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { DevModeContext } from "@moonwall/cli"; | ||
|
||
export const getFeesTreasuryProportion = async (context: DevModeContext): Promise<bigint> => { | ||
const parameter = await context.polkadotJs().query.parameters.parameters({ | ||
RuntimeConfig: "FeesTreasuryProportion", | ||
}); | ||
|
||
// 20% default value | ||
let feesTreasuryProportion = 200_000_000n; | ||
if (parameter.isSome) { | ||
feesTreasuryProportion = parameter.value.asRuntimeConfig.asFeesTreasuryProportion.toBigInt(); | ||
} | ||
return feesTreasuryProportion; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters