-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(txwrapper-substrate): Add nominationPools calls (#330)
- Loading branch information
Showing
46 changed files
with
1,677 additions
and
0 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
22 changes: 22 additions & 0 deletions
22
packages/txwrapper-substrate/src/methods/nominationPools/bondExtra.spec.ts
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,22 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
KUSAMA_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-dev'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { bondExtra } from './bondExtra'; | ||
|
||
describe('nominationPools::bondExtra', () => { | ||
it('should work', () => { | ||
const unsigned = bondExtra( | ||
TEST_METHOD_ARGS.nominationPools.bondExtra, | ||
TEST_BASE_TX_INFO, | ||
KUSAMA_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe('0x29010040420f00000000000000000000000000'); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
packages/txwrapper-substrate/src/methods/nominationPools/bondExtra.ts
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,55 @@ | ||
import { | ||
Args, | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
export interface NominationPoolsBondExtra extends Args { | ||
extra: { | ||
/** | ||
* Take from the free balance. | ||
*/ | ||
FreeBalance: string | null; | ||
/** | ||
* Take the entire amount from the accumulated rewards. | ||
*/ | ||
Rewards: boolean | null; | ||
}; | ||
} | ||
|
||
/** | ||
* Bond `extra` more funds from `origin` into the pool to which they already belong. | ||
* | ||
* Additional funds can come from either the free balance of the account, or from the | ||
* accumulated rewards, see [`BondExtra`]. | ||
* | ||
* Bonding extra funds implies an automatic payout of all pending rewards as well. | ||
* See `bond_extra_other` to bond pending rewards of `other` members. | ||
* | ||
* NOTE: this transaction is implemented with the sole purpose of readability and | ||
* correctness, not optimization. We read/write several storage items multiple times instead | ||
* of just once, in the spirit of reusing code. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function bondExtra( | ||
args: NominationPoolsBondExtra, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'bondExtra', | ||
pallet: 'nominationPools', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/txwrapper-substrate/src/methods/nominationPools/bondExtraOther.spec.ts
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,24 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
KUSAMA_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-dev'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { bondExtraOther } from './bondExtraOther'; | ||
|
||
describe('nominationPools::bondExtraOther', () => { | ||
it('should work', () => { | ||
const unsigned = bondExtraOther( | ||
TEST_METHOD_ARGS.nominationPools.bondExtraOther, | ||
TEST_BASE_TX_INFO, | ||
KUSAMA_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe( | ||
'0x290e00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0040420f00000000000000000000000000' | ||
); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
packages/txwrapper-substrate/src/methods/nominationPools/bondExtraOther.ts
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,49 @@ | ||
import { | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
import { NominationPoolsBondExtra } from './bondExtra'; | ||
|
||
export interface NominationPoolsBondExtraOther | ||
extends NominationPoolsBondExtra { | ||
/** | ||
* AccountId. | ||
*/ | ||
member: string; | ||
} | ||
|
||
/** | ||
* `origin` bonds funds from `extra` for some pool member `member` into their respective | ||
* pools. | ||
* | ||
* `origin` can bond extra funds from free balance or pending rewards when `origin == | ||
* other`. | ||
* | ||
* In the case of `origin != other`, `origin` can only bond extra pending rewards of | ||
* `other` members assuming set_claim_permission for the given member is | ||
* `PermissionlessAll` or `PermissionlessCompound`. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function bondExtraOther( | ||
args: NominationPoolsBondExtraOther, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'bondExtraOther', | ||
pallet: 'nominationPools', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/txwrapper-substrate/src/methods/nominationPools/chill.spec.ts
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,22 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
KUSAMA_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-dev'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { chill } from './chill'; | ||
|
||
describe('nominationPools::chill', () => { | ||
it('should work', () => { | ||
const unsigned = chill( | ||
TEST_METHOD_ARGS.nominationPools.chill, | ||
TEST_BASE_TX_INFO, | ||
KUSAMA_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe('0x290d04000000'); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/txwrapper-substrate/src/methods/nominationPools/chill.ts
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,45 @@ | ||
import { | ||
Args, | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
export interface NominationPoolsChill extends Args { | ||
/** | ||
* A valid PoolId. | ||
*/ | ||
poolId: number | string; | ||
} | ||
|
||
/** | ||
* Chill on behalf of the pool. | ||
* | ||
* The dispatch origin of this call must be signed by the pool nominator or the pool | ||
* root role, same as [`Pallet::nominate`]. | ||
* | ||
* This directly forwards the call to the staking pallet, on behalf of the pool bonded | ||
* account. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function chill( | ||
args: NominationPoolsChill, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'chill', | ||
pallet: 'nominationPools', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/txwrapper-substrate/src/methods/nominationPools/claimCommission.spec.ts
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,22 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
KUSAMA_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-dev'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { claimCommission } from './claimCommission'; | ||
|
||
describe('nominationPools::claimCommission', () => { | ||
it('should work', () => { | ||
const unsigned = claimCommission( | ||
TEST_METHOD_ARGS.nominationPools.claimCommission, | ||
TEST_BASE_TX_INFO, | ||
KUSAMA_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe('0x291404000000'); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/txwrapper-substrate/src/methods/nominationPools/claimCommission.ts
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,43 @@ | ||
import { | ||
Args, | ||
BaseTxInfo, | ||
defineMethod, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
export interface NominationPoolsClaimCommission extends Args { | ||
/** | ||
* A valid poolId. | ||
*/ | ||
poolId: number | string; | ||
} | ||
|
||
/** | ||
* Claim pending commission. | ||
* | ||
* The dispatch origin of this call must be signed by the `root` role of the pool. Pending | ||
* commission is paid out and added to total claimed commission`. Total pending commission | ||
* is reset to zero. the current. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function claimCommission( | ||
args: NominationPoolsClaimCommission, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'claimCommission', | ||
pallet: 'nominationPools', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/txwrapper-substrate/src/methods/nominationPools/claimPayout.spec.ts
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,17 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
KUSAMA_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-dev'; | ||
|
||
import { claimPayout } from './claimPayout'; | ||
|
||
describe('nominationPools::claimPayout', () => { | ||
it('should work', () => { | ||
const unsigned = claimPayout({}, TEST_BASE_TX_INFO, KUSAMA_TEST_OPTIONS); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe('0x2902'); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/txwrapper-substrate/src/methods/nominationPools/claimPayout.ts
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,39 @@ | ||
import { | ||
BaseTxInfo, | ||
defineMethod, | ||
EmptyArgs, | ||
OptionsWithMeta, | ||
UnsignedTransaction, | ||
} from '@substrate/txwrapper-core'; | ||
|
||
/** | ||
* A bonded member can use this to claim their payout based on the rewards that the pool | ||
* has accumulated since their last claimed payout (OR since joining if this is their first | ||
* time claiming rewards). The payout will be transferred to the member's account. | ||
* | ||
* The member will earn rewards pro rata based on the members stake vs the sum of the | ||
* members in the pools stake. Rewards do not "expire". | ||
* | ||
* See `claim_payout_other` to caim rewards on bahalf of some `other` pool member. | ||
* | ||
* @param args - Arguments specific to this method. | ||
* @param info - Information required to construct the transaction. | ||
* @param options - Registry and metadata used for constructing the method. | ||
*/ | ||
export function claimPayout( | ||
args: EmptyArgs, | ||
info: BaseTxInfo, | ||
options: OptionsWithMeta | ||
): UnsignedTransaction { | ||
return defineMethod( | ||
{ | ||
method: { | ||
args, | ||
name: 'claimPayout', | ||
pallet: 'nominationPools', | ||
}, | ||
...info, | ||
}, | ||
options | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/txwrapper-substrate/src/methods/nominationPools/claimPayoutOther.spec.ts
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,24 @@ | ||
import { | ||
itHasCorrectBaseTxInfo, | ||
KUSAMA_TEST_OPTIONS, | ||
TEST_BASE_TX_INFO, | ||
} from '@substrate/txwrapper-dev'; | ||
|
||
import { TEST_METHOD_ARGS } from '../../test-helpers'; | ||
import { claimPayoutOther } from './claimPayoutOther'; | ||
|
||
describe('nominationPools::claimPayoutOther', () => { | ||
it('should work', () => { | ||
const unsigned = claimPayoutOther( | ||
TEST_METHOD_ARGS.nominationPools.claimPayoutOther, | ||
TEST_BASE_TX_INFO, | ||
KUSAMA_TEST_OPTIONS | ||
); | ||
|
||
itHasCorrectBaseTxInfo(unsigned); | ||
|
||
expect(unsigned.method).toBe( | ||
'0x2910d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.