Skip to content

Commit 1d66b5a

Browse files
committed
feat: 🎸 add chain v8 support
adds chain version detection and relevant conversions to provide a smooth upgrade experience
1 parent b93fd0c commit 1d66b5a

File tree

22 files changed

+807
-562
lines changed

22 files changed

+807
-562
lines changed

package.json

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
"@commitlint/config-conventional": "^17.7.0",
5858
"@graphql-codegen/cli": "5.0.0",
5959
"@graphql-codegen/typescript": "4.0.1",
60-
"@polkadot/dev-ts": "^0.79.3",
61-
"@polkadot/typegen": "11.2.1",
62-
"@polymeshassociation/local-signing-manager": "^3.0.1",
63-
"@polymeshassociation/signing-manager-types": "^3.0.0",
60+
"@polkadot/dev-ts": "^0.83.3",
61+
"@polkadot/typegen": "16.5.2",
62+
"@polymeshassociation/local-signing-manager": "^4.0.0",
63+
"@polymeshassociation/signing-manager-types": "^3.5.0",
6464
"@semantic-release/changelog": "^6.0.3",
6565
"@types/jest": "^29.5.14",
6666
"@types/jest-when": "^3.5.2",
@@ -123,10 +123,10 @@
123123
},
124124
"dependencies": {
125125
"@apollo/client": "^3.8.1",
126-
"@polkadot/api": "11.2.1",
127-
"@polkadot/util": "12.6.2",
128-
"@polkadot/util-crypto": "12.6.2",
129-
"@polymeshassociation/polymesh-types": "^6.2.0",
126+
"@polkadot/api": "16.5.2",
127+
"@polkadot/util": "13.5.8",
128+
"@polkadot/util-crypto": "13.5.8",
129+
"@polymeshassociation/polymesh-types": "^7.0.0",
130130
"bignumber.js": "9.0.1",
131131
"cross-fetch": "^4.0.0",
132132
"dayjs": "1.11.9",
@@ -139,61 +139,43 @@
139139
"ts-morph": "^25.0.1",
140140
"websocket": "^1.0.34"
141141
},
142-
"resolutions": {
143-
"@polkadot/keyring": "12.6.2",
144-
"@polkadot/api-augment": "11.2.1",
145-
"@polkadot/api-base": "11.2.1",
146-
"@polkadot/api-derive": "11.2.1",
147-
"@polkadot/rpc-augment": "11.2.1",
148-
"@polkadot/rpc-core": "11.2.1",
149-
"@polkadot/rpc-provider": "11.2.1",
150-
"@polkadot/types": "11.2.1",
151-
"@polkadot/types-augment": "11.2.1",
152-
"@polkadot/types-codec": "11.2.1",
153-
"@polkadot/types-create": "11.2.1",
154-
"@polkadot/types-known": "11.2.1",
155-
"@polkadot/util": "12.6.2",
156-
"@polkadot/networks": "12.6.2",
157-
"@polkadot/util-crypto": "12.6.2",
158-
"@polkadot/x-bigint": "12.6.2"
159-
},
160142
"overrides": {
161-
"@polkadot/keyring": "12.6.2",
162-
"@polkadot/api-augment": "11.2.1",
163-
"@polkadot/api-base": "11.2.1",
164-
"@polkadot/api-derive": "11.2.1",
165-
"@polkadot/rpc-augment": "11.2.1",
166-
"@polkadot/rpc-core": "11.2.1",
167-
"@polkadot/rpc-provider": "11.2.1",
168-
"@polkadot/types": "11.2.1",
169-
"@polkadot/types-augment": "11.2.1",
170-
"@polkadot/types-codec": "11.2.1",
171-
"@polkadot/types-create": "11.2.1",
172-
"@polkadot/types-known": "11.2.1",
173-
"@polkadot/util": "12.6.2",
174-
"@polkadot/networks": "12.6.2",
175-
"@polkadot/util-crypto": "12.6.2",
176-
"@polkadot/x-bigint": "12.6.2"
143+
"@polkadot/keyring": "13.5.8",
144+
"@polkadot/api-augment": "16.5.2",
145+
"@polkadot/api-base": "16.5.2",
146+
"@polkadot/api-derive": "16.5.2",
147+
"@polkadot/rpc-augment": "16.5.2",
148+
"@polkadot/rpc-core": "16.5.2",
149+
"@polkadot/rpc-provider": "16.5.2",
150+
"@polkadot/types": "16.5.2",
151+
"@polkadot/types-augment": "16.5.2",
152+
"@polkadot/types-codec": "16.5.2",
153+
"@polkadot/types-create": "16.5.2",
154+
"@polkadot/types-known": "16.5.2",
155+
"@polkadot/util": "13.5.8",
156+
"@polkadot/networks": "13.5.8",
157+
"@polkadot/util-crypto": "13.5.8",
158+
"@polkadot/x-bigint": "13.5.8"
177159
},
178160
"pnpm": {
179161
"overrides": {
180-
"@polkadot/keyring": "12.6.2",
181-
"@polkadot/api-augment": "11.2.1",
182-
"@polkadot/api-base": "11.2.1",
183-
"@polkadot/api-derive": "11.2.1",
184-
"@polkadot/rpc-augment": "11.2.1",
185-
"@polkadot/rpc-core": "11.2.1",
186-
"@polkadot/rpc-provider": "11.2.1",
187-
"@polkadot/types": "11.2.1",
188-
"@polkadot/types-augment": "11.2.1",
189-
"@polkadot/types-codec": "11.2.1",
190-
"@polkadot/types-create": "11.2.1",
191-
"@polkadot/types-known": "11.2.1",
192-
"@polkadot/util": "12.6.2",
193-
"@polkadot/networks": "12.6.2",
194-
"@polkadot/util-crypto": "12.6.2",
195-
"@polkadot/x-bigint": "12.6.2"
162+
"@polkadot/keyring": "13.5.8",
163+
"@polkadot/api-augment": "16.5.2",
164+
"@polkadot/api-base": "16.5.2",
165+
"@polkadot/api-derive": "16.5.2",
166+
"@polkadot/rpc-augment": "16.5.2",
167+
"@polkadot/rpc-core": "16.5.2",
168+
"@polkadot/rpc-provider": "16.5.2",
169+
"@polkadot/types": "16.5.2",
170+
"@polkadot/types-augment": "16.5.2",
171+
"@polkadot/types-codec": "16.5.2",
172+
"@polkadot/types-create": "16.5.2",
173+
"@polkadot/types-known": "16.5.2",
174+
"@polkadot/util": "13.5.8",
175+
"@polkadot/networks": "13.5.8",
176+
"@polkadot/util-crypto": "13.5.8",
177+
"@polkadot/x-bigint": "13.5.8"
196178
}
197179
},
198180
"packageManager": "[email protected]+sha512.1fc009bc09d13cfd0e19efa44cbfc2b9cf6ca61482725eb35bbc5e257e093ebf4130db6dfe15d604ff4b79efd8e1e8e99b25fa7d0a6197c9f9826358d4d65c3c"
199-
}
181+
}

scripts/fetchMetadata.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933 > metadata.json
1+
curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9944 > metadata.json

src/api/client/Polymesh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class Polymesh {
169169
: new WsProvider(nodeUrl);
170170

171171
polymeshApi = await ApiPromise.create({
172+
// @ts-expect-error - exactPropertyType causes provider from ttl?.
172173
provider,
173174
types,
174175
rpc,

src/api/client/Staking.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export class Staking {
137137
* Allow for a stash account to update its controller
138138
*
139139
* @note the transaction must be signed by a stash account
140+
* @note Polymesh v8 makes it so the stash will become its own controller account
140141
*/
141142
public setController: ProcedureMethod<SetStakingControllerParams, void>;
142143

src/api/entities/Account/Staking/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Option } from '@polkadot/types';
22
import { AccountId, RewardDestination } from '@polkadot/types/interfaces';
3-
import { PalletStakingNominations } from '@polkadot/types/lookup';
3+
import { PalletStakingNominations, PalletStakingRewardDestination } from '@polkadot/types/lookup';
44

55
import { Account, Namespace } from '~/internal';
66
import {
@@ -79,10 +79,10 @@ export class Staking extends Namespace<Account> {
7979
const rawAddress = stringToAccountId(this.parent.address, context);
8080

8181
const assembleResult = (
82-
rawPayee: RewardDestination,
82+
rawPayee: RewardDestination | null,
8383
controller: Account | null
8484
): StakingPayee | null => {
85-
if (!controller) {
85+
if (!controller || !rawPayee) {
8686
return null;
8787
}
8888

@@ -96,7 +96,11 @@ export class Staking extends Namespace<Account> {
9696
});
9797

9898
const payeeUnsub = await query.staking.payee(rawAddress, rawPayee => {
99-
const result = assembleResult(rawPayee, controller);
99+
// istanbul ignore next: will be removed with v7 support
100+
const payee = context.isV7
101+
? (rawPayee as unknown as PalletStakingRewardDestination)
102+
: rawPayee.unwrapOr(null);
103+
const result = assembleResult(payee, controller);
100104

101105
// eslint-disable-next-line @typescript-eslint/no-floating-promises
102106
callback(result);
@@ -113,7 +117,12 @@ export class Staking extends Namespace<Account> {
113117
this.getController(),
114118
]);
115119

116-
return assembleResult(rawPayee, controller);
120+
// istanbul ignore next: will be removed with v7 support
121+
const payee = context.isV7
122+
? (rawPayee as unknown as PalletStakingRewardDestination)
123+
: rawPayee.unwrap();
124+
125+
return assembleResult(payee, controller);
117126
}
118127

119128
/**

src/api/entities/Account/__tests__/Staking.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Staking namespace', () => {
7474
dsMockUtils.createMockU128(new BigNumber(5).times(10 ** 6))
7575
),
7676
unlocking: dsMockUtils.createMockVec(),
77-
claimedRewards: dsMockUtils.createMockVec(),
77+
legacyClaimedRewards: dsMockUtils.createMockVec(),
7878
})
7979
),
8080
});
@@ -104,7 +104,9 @@ describe('Staking namespace', () => {
104104
describe('method: getPayee', () => {
105105
it('should return payee info for Staked', async () => {
106106
dsMockUtils.createQueryMock('staking', 'payee', {
107-
returnValue: dsMockUtils.createMockRewardDestination('Staked'),
107+
returnValue: dsMockUtils.createMockOption(
108+
dsMockUtils.createMockRewardDestination('Staked')
109+
),
108110
});
109111

110112
jest
@@ -122,7 +124,7 @@ describe('Staking namespace', () => {
122124

123125
it('should return payee info for Stash', async () => {
124126
dsMockUtils.createQueryMock('staking', 'payee', {
125-
returnValue: dsMockUtils.createMockRewardDestination('Stash'),
127+
returnValue: dsMockUtils.createMockOption(dsMockUtils.createMockRewardDestination('Stash')),
126128
});
127129

128130
jest
@@ -140,7 +142,9 @@ describe('Staking namespace', () => {
140142

141143
it('should return payee info for Controller', async () => {
142144
dsMockUtils.createQueryMock('staking', 'payee', {
143-
returnValue: dsMockUtils.createMockRewardDestination('Controller'),
145+
returnValue: dsMockUtils.createMockOption(
146+
dsMockUtils.createMockRewardDestination('Controller')
147+
),
144148
});
145149

146150
jest.spyOn(staking, 'getController').mockResolvedValue(
@@ -158,9 +162,11 @@ describe('Staking namespace', () => {
158162

159163
it('should return payee info for Account', async () => {
160164
dsMockUtils.createQueryMock('staking', 'payee', {
161-
returnValue: dsMockUtils.createMockRewardDestination({
162-
Account: dsMockUtils.createMockAccountId('someAddress'),
163-
}),
165+
returnValue: dsMockUtils.createMockOption(
166+
dsMockUtils.createMockRewardDestination({
167+
Account: dsMockUtils.createMockAccountId('someAddress'),
168+
})
169+
),
164170
});
165171

166172
jest
@@ -178,7 +184,7 @@ describe('Staking namespace', () => {
178184

179185
it('should return null for None payee', async () => {
180186
dsMockUtils.createQueryMock('staking', 'payee', {
181-
returnValue: dsMockUtils.createMockRewardDestination('None'),
187+
returnValue: dsMockUtils.createMockOption(dsMockUtils.createMockRewardDestination('None')),
182188
});
183189

184190
jest
@@ -193,7 +199,7 @@ describe('Staking namespace', () => {
193199

194200
it('should return null for no controller', async () => {
195201
dsMockUtils.createQueryMock('staking', 'payee', {
196-
returnValue: dsMockUtils.createMockRewardDestination('Stash'),
202+
returnValue: dsMockUtils.createMockOption(dsMockUtils.createMockRewardDestination('Stash')),
197203
});
198204

199205
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -212,7 +218,7 @@ describe('Staking namespace', () => {
212218
const payeeQueryMock = dsMockUtils.createQueryMock('staking', 'payee');
213219

214220
payeeQueryMock.mockImplementation((rawAddr: unknown, cb: (arg: unknown) => void) => {
215-
cb(dsMockUtils.createMockRewardDestination('Stash'));
221+
cb(dsMockUtils.createMockOption(dsMockUtils.createMockRewardDestination('Stash')));
216222

217223
return payeeUnsub;
218224
});

src/api/procedures/__tests__/bondPolyx.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,40 @@ describe('bondPolyx procedure', () => {
178178

179179
const result = await prepareBondPolyx.call(proc, args);
180180

181+
expect(result).toEqual({
182+
transaction: bondTx,
183+
args: [rawAmount, rewardDestination],
184+
resolver: undefined,
185+
});
186+
});
187+
188+
it('should return a v7 bond transaction spec with controller', async () => {
189+
mockContext = dsMockUtils.getContextInstance({ isV7: true });
190+
bondTx = dsMockUtils.createTxMock('staking', 'bond');
191+
192+
when(bigNumberToBalanceSpy).calledWith(amount, mockContext).mockReturnValue(rawAmount);
193+
when(stringToAccountIdSpy)
194+
.calledWith(actingAccount.address, mockContext)
195+
.mockReturnValue(rawAccountId);
196+
when(stakingRewardDestinationToRawSpy)
197+
.calledWith({ stash: true }, mockContext)
198+
.mockReturnValue(rewardDestination);
199+
200+
const proc = procedureMockUtils.getInstance<Params, void, Storage>(mockContext, {
201+
actingBalance,
202+
actingAccount,
203+
});
204+
205+
const args = {
206+
payee: actingAccount,
207+
controller: actingAccount,
208+
rewardDestination: actingAccount,
209+
amount,
210+
autoStake: false,
211+
};
212+
213+
const result = await prepareBondPolyx.call(proc, args);
214+
181215
expect(result).toEqual({
182216
transaction: bondTx,
183217
args: [rawAccountId, rawAmount, rewardDestination],

src/api/procedures/__tests__/setStakingController.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@ describe('setStakingController procedure', () => {
127127

128128
const result = await prepareSetStakingController.call(proc, args);
129129

130+
expect(result).toEqual({
131+
transaction: setControllerTx,
132+
args: undefined,
133+
resolver: undefined,
134+
});
135+
});
136+
137+
it('should return a v7 setController transaction spec with controller arg', async () => {
138+
mockContext = dsMockUtils.getContextInstance({ isV7: true });
139+
setControllerTx = dsMockUtils.createTxMock('staking', 'setController');
140+
141+
when(stringToAccountIdSpy)
142+
.calledWith(newController.address, mockContext)
143+
.mockReturnValue(rawAccountId);
144+
145+
const proc = procedureMockUtils.getInstance<Params, void, Storage>(mockContext, {
146+
actingAccount,
147+
currentController,
148+
newControllerLedger: null,
149+
});
150+
151+
const args = {
152+
controller: newController,
153+
};
154+
155+
const result = await prepareSetStakingController.call(proc, args);
156+
130157
expect(result).toEqual({
131158
transaction: setControllerTx,
132159
args: [rawAccountId],

0 commit comments

Comments
 (0)