@polkadot/types/interfaces#Permill TypeScript Examples
The following examples show how to use
@polkadot/types/interfaces#Permill.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: treasury.ts From commonwealth with GNU General Public License v3.0 | 6 votes |
public async init(ChainInfo: SubstrateChain, Accounts: SubstrateAccounts): Promise<void> {
this._disabled = !ChainInfo.api.query.treasury;
if (this._initializing || this._initialized || this.disabled) return;
this._initializing = true;
this._Chain = ChainInfo;
this._Accounts = Accounts;
// load server proposals
const entities = this.app.chain.chainEntities.store.getByType(SubstrateTypes.EntityKind.TreasuryProposal);
entities.forEach((e) => this._entityConstructor(e));
// save parameters
this._bondPct = +(ChainInfo.api.consts.treasury.proposalBond as Permill) / 1_000_000;
this._bondMinimum = this._Chain.coins(ChainInfo.api.consts.treasury.proposalBondMinimum as BalanceOf);
this._spendPeriod = +(ChainInfo.api.consts.treasury.spendPeriod as BlockNumber);
this._burnPct = +(ChainInfo.api.consts.treasury.burn as Permill) / 1_000_000;
const TREASURY_ACCOUNT = u8aToHex(stringToU8a('modlpy/trsry'.padEnd(32, '\0')));
const pot = await ChainInfo.api.derive.balances.account(TREASURY_ACCOUNT);
this._pot = this._Chain.coins(pot.freeBalance);
// register new chain-event handlers
this.app.chain.chainEntities.registerEntityHandler(
SubstrateTypes.EntityKind.TreasuryProposal, (entity, event) => {
this.updateProposal(entity, event);
}
);
// fetch proposals from chain
await this.app.chain.chainEntities.fetchEntities(
this.app.chain.id,
chainToEventNetwork(this.app.chain.meta),
() => this._Chain.fetcher.fetchTreasuryProposals(this.app.chain.block.height),
);
this._initialized = true;
this._initializing = false;
}
Example #2
Source File: bountyTreasury.ts From commonwealth with GNU General Public License v3.0 | 5 votes |
public async init(ChainInfo: SubstrateChain, Accounts: SubstrateAccounts): Promise<void> {
this._disabled = !ChainInfo.api.consts.bounties && !ChainInfo.api.consts.treasury;
if (this._initializing || this._initialized || this.disabled) return;
this._initializing = true;
this._Chain = ChainInfo;
this._Accounts = Accounts;
// load server proposals
const entities = this.app.chain.chainEntities.store.getByType(SubstrateTypes.EntityKind.TreasuryBounty);
entities.forEach((e) => this._entityConstructor(e));
// save parameters
const bountyModule = ChainInfo.api.consts.bounties || ChainInfo.api.consts.treasury;
this._bountyCuratorDeposit = this._Chain.coins(bountyModule.bountyCuratorDeposit as Permill);
this._bountyDepositBase = this._Chain.coins(bountyModule.bountyDepositBase as BalanceOf);
this._bountyDepositPayoutDelay = bountyModule.bountyDepositPayoutDelay as BlockNumber;
this._bountyValueMinimum = this._Chain.coins(bountyModule.bountyValueMinimum as BalanceOf);
// kick off subscriptions
// const TREASURY_ACCOUNT = u8aToHex(stringToU8a('modlpy/trsry'.padEnd(32, '\0')));
// register new chain-event handlers
this.app.chain.chainEntities.registerEntityHandler(
SubstrateTypes.EntityKind.TreasuryBounty, (entity, event) => {
this.updateProposal(entity, event);
}
);
// fetch proposals from chain
await this.app.chain.chainEntities.fetchEntities(
this.app.chain.id,
chainToEventNetwork(this.app.chain.meta),
() => this._Chain.fetcher.fetchBounties(this.app.chain.block.height),
);
// fetch extra metadata
// TODO: this should be picked up by the chain-events system
const extra = await ChainInfo.api.derive.bounties.bounties();
extra.forEach((b) => {
const index = b.index.toNumber();
const bounty = this.store.getByIdentifier(index);
if (!bounty) {
console.log('Unexpected missing bounty, on chain but not returned by chain-events');
return;
}
const data = {
title: b.description,
// state
isActive: b.bounty.status.isActive,
isApproved: b.bounty.status.isApproved,
isCuratorProposed: b.bounty.status.isCuratorProposed,
isFunded: b.bounty.status.isFunded,
isPendingPayout: b.bounty.status.isPendingPayout,
isProposed: b.bounty.status.isProposed,
// metadata
fee: b.bounty.fee,
curatorDeposit: b.bounty.curatorDeposit,
bond: b.bounty.bond,
curator: b.bounty.status.isCuratorProposed ? b.bounty.status.asCuratorProposed?.curator
: b.bounty.status.isActive ? b.bounty.status.asActive.curator
: b.bounty.status.isPendingPayout ? b.bounty.status.asPendingPayout.curator : null,
updateDue: b.bounty.status.isActive ? b.bounty.status.asActive.updateDue : null,
beneficiary: b.bounty.status.isPendingPayout ? b.bounty.status.asPendingPayout.beneficiary : null,
unlockAt: b.bounty.status.isPendingPayout ? b.bounty.status.asPendingPayout.unlockAt : null,
};
bounty.setStatus(data);
});
this._initialized = true;
this._initializing = false;
}
Example #3
Source File: LiquidityPoolTask.ts From guardian with Apache License 2.0 | 5 votes |
toFixed128 = (value: Permill): Big => {
return Big(value.toString()).mul(1e12);
}