|
@@ -2,10 +2,13 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
|
|
|
import { Option, Vec, Bytes, u32 } from '@polkadot/types';
|
|
|
import { Codec } from '@polkadot/types/types';
|
|
|
import { KeyringPair } from '@polkadot/keyring/types';
|
|
|
-import { UserInfo, PaidMembershipTerms, MemberId } from '@joystream/types/lib/members';
|
|
|
-import { Seat, VoteKind } from '@joystream/types/';
|
|
|
-import { Balance, EventRecord } from '@polkadot/types/interfaces';
|
|
|
-import BN = require('bn.js');
|
|
|
+import { UserInfo, PaidMembershipTerms, MemberId } from '@constantinople/types/lib/members';
|
|
|
+import { Mint, MintId } from '@constantinople/types/lib/mint';
|
|
|
+import { Lead, LeadId } from '@constantinople/types/lib/content-working-group';
|
|
|
+import { RoleParameters } from '@constantinople/types/lib/roles';
|
|
|
+import { Seat } from '@constantinople/types';
|
|
|
+import { Balance, EventRecord, AccountId, BlockNumber, BalanceOf } from '@polkadot/types/interfaces';
|
|
|
+import BN from 'bn.js';
|
|
|
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
|
import { Sender } from './sender';
|
|
|
import { Utils } from './utils';
|
|
@@ -61,11 +64,12 @@ export class ApiWrapper {
|
|
|
return this.getPaidMembershipTerms(paidTermsId).then(terms => terms.unwrap().fee.toBn());
|
|
|
}
|
|
|
|
|
|
- public async transferBalanceToAccounts(from: KeyringPair, to: KeyringPair[], amount: BN): Promise<void> {
|
|
|
- for (const keyPair of to) {
|
|
|
- await this.transferBalance(from, keyPair.address, amount);
|
|
|
- }
|
|
|
- return;
|
|
|
+ public async transferBalanceToAccounts(from: KeyringPair, to: KeyringPair[], amount: BN): Promise<void[]> {
|
|
|
+ return Promise.all(
|
|
|
+ to.map(async keyPair => {
|
|
|
+ await this.transferBalance(from, keyPair.address, amount);
|
|
|
+ })
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
private getBaseTxFee(): BN {
|
|
@@ -132,6 +136,82 @@ export class ApiWrapper {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public estimateProposeValidatorCountFee(title: string, description: string, stake: BN): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createSetValidatorCountProposal(stake, title, description, stake, stake)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateProposeLeadFee(title: string, description: string, stake: BN, address: string): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createSetLeadProposal(stake, title, description, stake, { stake, address })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateProposeEvictStorageProviderFee(title: string, description: string, stake: BN, address: string): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createEvictStorageProviderProposal(stake, title, description, stake, address)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateProposeStorageRoleParametersFee(
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ minStake: BN,
|
|
|
+ minActors: BN,
|
|
|
+ maxActors: BN,
|
|
|
+ reward: BN,
|
|
|
+ rewardPeriod: BN,
|
|
|
+ bondingPeriod: BN,
|
|
|
+ unbondingPeriod: BN,
|
|
|
+ minServicePeriod: BN,
|
|
|
+ startupGracePeriod: BN,
|
|
|
+ entryRequestFee: BN
|
|
|
+ ): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createSetStorageRoleParametersProposal(stake, title, description, stake, [
|
|
|
+ minStake,
|
|
|
+ minActors,
|
|
|
+ maxActors,
|
|
|
+ reward,
|
|
|
+ rewardPeriod,
|
|
|
+ bondingPeriod,
|
|
|
+ unbondingPeriod,
|
|
|
+ minServicePeriod,
|
|
|
+ startupGracePeriod,
|
|
|
+ entryRequestFee,
|
|
|
+ ])
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public estimateProposeElectionParametersFee(
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ announcingPeriod: BN,
|
|
|
+ votingPeriod: BN,
|
|
|
+ revealingPeriod: BN,
|
|
|
+ councilSize: BN,
|
|
|
+ candidacyLimit: BN,
|
|
|
+ newTermDuration: BN,
|
|
|
+ minCouncilStake: BN,
|
|
|
+ minVotingStake: BN
|
|
|
+ ): BN {
|
|
|
+ return this.estimateTxFee(
|
|
|
+ this.api.tx.proposalsCodex.createSetElectionParametersProposal(stake, title, description, stake, [
|
|
|
+ announcingPeriod,
|
|
|
+ votingPeriod,
|
|
|
+ revealingPeriod,
|
|
|
+ councilSize,
|
|
|
+ candidacyLimit,
|
|
|
+ newTermDuration,
|
|
|
+ minCouncilStake,
|
|
|
+ minVotingStake,
|
|
|
+ ])
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public estimateVoteForProposalFee(): BN {
|
|
|
return this.estimateTxFee(this.api.tx.proposalsEngine.vote(0, 0, 'Approve'));
|
|
|
}
|
|
@@ -212,6 +292,14 @@ export class ApiWrapper {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public sudoSetCouncilMintCapacity(sudo: KeyringPair, capacity: BN): Promise<void> {
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.sudo.sudo(this.api.tx.council.setCouncilMintCapacity(capacity)),
|
|
|
+ sudo,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public getBestBlock(): Promise<BN> {
|
|
|
return this.api.derive.chain.bestNumber();
|
|
|
}
|
|
@@ -293,6 +381,128 @@ export class ApiWrapper {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public async proposeValidatorCount(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ validatorCount: BN
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createSetValidatorCountProposal(memberId, title, description, stake, validatorCount),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public async proposeLead(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ leadAccount: KeyringPair
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ const leadMemberId: BN = (await this.getMemberIds(leadAccount.address))[0].toBn();
|
|
|
+ const addressString: string = leadAccount.address;
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createSetLeadProposal(memberId, title, description, stake, [
|
|
|
+ leadMemberId,
|
|
|
+ addressString,
|
|
|
+ ]),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public async proposeEvictStorageProvider(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ storageProvider: string
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createEvictStorageProviderProposal(
|
|
|
+ memberId,
|
|
|
+ title,
|
|
|
+ description,
|
|
|
+ stake,
|
|
|
+ storageProvider
|
|
|
+ ),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public async proposeStorageRoleParameters(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ minStake: BN,
|
|
|
+ minActors: BN,
|
|
|
+ maxActors: BN,
|
|
|
+ reward: BN,
|
|
|
+ rewardPeriod: BN,
|
|
|
+ bondingPeriod: BN,
|
|
|
+ unbondingPeriod: BN,
|
|
|
+ minServicePeriod: BN,
|
|
|
+ startupGracePeriod: BN,
|
|
|
+ entryRequestFee: BN
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createSetStorageRoleParametersProposal(memberId, title, description, stake, [
|
|
|
+ minStake,
|
|
|
+ minActors,
|
|
|
+ maxActors,
|
|
|
+ reward,
|
|
|
+ rewardPeriod,
|
|
|
+ bondingPeriod,
|
|
|
+ unbondingPeriod,
|
|
|
+ minServicePeriod,
|
|
|
+ startupGracePeriod,
|
|
|
+ entryRequestFee,
|
|
|
+ ]),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public async proposeElectionParameters(
|
|
|
+ account: KeyringPair,
|
|
|
+ title: string,
|
|
|
+ description: string,
|
|
|
+ stake: BN,
|
|
|
+ announcingPeriod: BN,
|
|
|
+ votingPeriod: BN,
|
|
|
+ revealingPeriod: BN,
|
|
|
+ councilSize: BN,
|
|
|
+ candidacyLimit: BN,
|
|
|
+ newTermDuration: BN,
|
|
|
+ minCouncilStake: BN,
|
|
|
+ minVotingStake: BN
|
|
|
+ ): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ return this.sender.signAndSend(
|
|
|
+ this.api.tx.proposalsCodex.createSetElectionParametersProposal(memberId, title, description, stake, [
|
|
|
+ announcingPeriod,
|
|
|
+ votingPeriod,
|
|
|
+ revealingPeriod,
|
|
|
+ councilSize,
|
|
|
+ candidacyLimit,
|
|
|
+ newTermDuration,
|
|
|
+ minCouncilStake,
|
|
|
+ minVotingStake,
|
|
|
+ ]),
|
|
|
+ account,
|
|
|
+ false
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public approveProposal(account: KeyringPair, memberId: BN, proposal: BN): Promise<void> {
|
|
|
return this.sender.signAndSend(this.api.tx.proposalsEngine.vote(memberId, proposal, 'Approve'), account, false);
|
|
|
}
|
|
@@ -354,11 +564,6 @@ export class ApiWrapper {
|
|
|
return this.api.query.balances.totalIssuance<Balance>();
|
|
|
}
|
|
|
|
|
|
- public async getProposal(id: BN) {
|
|
|
- const proposal = await this.api.query.proposalsEngine.proposals(id);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
public async getRequiredProposalStake(numerator: number, denominator: number): Promise<BN> {
|
|
|
const issuance: number = await (await this.getTotalIssuance()).toNumber();
|
|
|
const stake = (issuance * numerator) / denominator;
|
|
@@ -368,4 +573,72 @@ export class ApiWrapper {
|
|
|
public getProposalCount(): Promise<BN> {
|
|
|
return this.api.query.proposalsEngine.proposalCount<u32>();
|
|
|
}
|
|
|
+
|
|
|
+ public async getWorkingGroupMintCapacity(): Promise<BN> {
|
|
|
+ const mintId: MintId = await this.api.query.contentWorkingGroup.mint<MintId>();
|
|
|
+ const mintCodec = await this.api.query.minting.mints<Codec[]>(mintId);
|
|
|
+ const mint: Mint = (mintCodec[0] as unknown) as Mint;
|
|
|
+ return mint.getField<Balance>('capacity');
|
|
|
+ }
|
|
|
+
|
|
|
+ public getValidatorCount(): Promise<BN> {
|
|
|
+ return this.api.query.staking.validatorCount<u32>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getCurrentLeadAddress(): Promise<string> {
|
|
|
+ const leadId: Option<LeadId> = await this.api.query.contentWorkingGroup.currentLeadId<Option<LeadId>>();
|
|
|
+ const leadCodec = await this.api.query.contentWorkingGroup.leadById<Codec[]>(leadId.unwrap());
|
|
|
+ const lead = (leadCodec[0] as unknown) as Lead;
|
|
|
+ return lead.role_account.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async createStorageProvider(account: KeyringPair): Promise<void> {
|
|
|
+ const memberId: BN = (await this.getMemberIds(account.address))[0].toBn();
|
|
|
+ await this.sender.signAndSend(this.api.tx.actors.roleEntryRequest('StorageProvider', memberId), account, false);
|
|
|
+ await this.sender.signAndSend(this.api.tx.actors.stake('StorageProvider', account.address), account, false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public async isStorageProvider(address: string): Promise<boolean> {
|
|
|
+ const storageProviders: Vec<AccountId> = await this.api.query.actors.accountIdsByRole<Vec<AccountId>>(
|
|
|
+ 'StorageProvider'
|
|
|
+ );
|
|
|
+ return storageProviders.map(accountId => accountId.toString()).includes(address);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getStorageRoleParameters(): Promise<RoleParameters> {
|
|
|
+ return (await this.api.query.actors.parameters<Option<RoleParameters>>('StorageProvider')).unwrap();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getAnnouncingPeriod(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.announcingPeriod<BlockNumber>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getVotingPeriod(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.votingPeriod<BlockNumber>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getRevealingPeriod(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.revealingPeriod<BlockNumber>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getCouncilSize(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.councilSize<u32>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getCandidacyLimit(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.candidacyLimit<u32>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getNewTermDuration(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.newTermDuration<BlockNumber>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getMinCouncilStake(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.minCouncilStake<BalanceOf>();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async getMinVotingStake(): Promise<BN> {
|
|
|
+ return await this.api.query.councilElection.minVotingStake<BalanceOf>();
|
|
|
+ }
|
|
|
}
|