Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update DOT sdk #3816

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/account-lib/resources/dot/westend.ts

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions modules/sdk-coin-dot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"dependencies": {
"@bitgo/sdk-core": "^8.15.0",
"@bitgo/statics": "^18.4.0",
"@polkadot/api": "9.3.3",
"@polkadot/keyring": "^10.1.8",
"@polkadot/types": "9.3.3",
"@polkadot/util": "^10.1.8",
"@polkadot/util-crypto": "^10.1.8",
"@substrate/txwrapper-core": "3.2.2",
"@substrate/txwrapper-polkadot": "3.2.2",
"@polkadot/api": "10.9.1",
"@polkadot/keyring": "12.3.2",
"@polkadot/types": "10.9.1",
"@polkadot/util": "12.3.2",
"@polkadot/util-crypto": "12.3.2",
"@substrate/txwrapper-core": "7.0.1",
"@substrate/txwrapper-polkadot": "7.0.1",
"bignumber.js": "^9.0.0",
"bs58": "^4.0.1",
"hi-base32": "^0.5.1",
Expand Down
2 changes: 0 additions & 2 deletions modules/sdk-coin-dot/src/lib/batchTransactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ export class BatchTransactionBuilder extends TransactionBuilder {
const baseTxInfo = this.createBaseTxInfo();
const unsigned = methods.staking.bond(
{
// TODO(EA-1242): update DOT library to remove controller optional field -> https://github.com/paritytech/txwrapper-core/pull/309 and https://github.com/paritytech/substrate/pull/14039
controller: args.controller?.id || '',
value: args.value,
payee: this.getPayee(args.payee),
},
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-dot/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export type StakeArgsPayeeRaw = { controller?: null; stash?: null; staked?: null
*/
export interface StakeArgs {
value: string;
controller?: { id: string };
controller: { id: string };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undocumented breaking change. Need a BREAKING CHANGE: in the commit footer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually reverting the previous change a6f6a0d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll keep that in mind for future breaking changes

payee: StakeArgsPayee;
}

Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-dot/src/lib/nativeTransferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export abstract class NativeTransferBuilder extends TransactionBuilder {
if (this._sweepFreeBalance) {
transferTx = methods.balances.transferAll(
{
dest: this._to,
dest: { id: this._to },
keepAlive: this._keepAddressAlive,
},
baseTxInfo.baseTxInfo,
Expand All @@ -47,7 +47,7 @@ export abstract class NativeTransferBuilder extends TransactionBuilder {
transferTx = methods.balances.transferKeepAlive(
{
value: this._amount,
dest: this._to,
dest: { id: this._to },
},
baseTxInfo.baseTxInfo,
baseTxInfo.options
Expand Down
8 changes: 2 additions & 6 deletions modules/sdk-coin-dot/src/lib/stakingBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class StakingBuilder extends TransactionBuilder {
return methods.staking.bond(
{
value: this._amount,
controller: this._controller,
payee: this._payee,
},
baseTxInfo.baseTxInfo,
Expand Down Expand Up @@ -117,7 +116,7 @@ export class StakingBuilder extends TransactionBuilder {
if (decodedTxn.method?.name === MethodNames.Bond) {
const txMethod = decodedTxn.method.args as unknown as StakeArgs;
const value = txMethod.value;
const controller = txMethod.controller?.id;
const controller = this._sender;
const payee = txMethod.payee;
const validationResult = StakeTransactionSchema.validate({ value, controller, payee });
if (validationResult.error) {
Expand All @@ -140,10 +139,7 @@ export class StakingBuilder extends TransactionBuilder {
const txMethod = this._method.args as StakeArgs;
this.amount(txMethod.value);
this.owner({
address: utils.decodeDotAddress(
txMethod.controller?.id || '',
utils.getAddressFormat(this._coinConfig.name as DotAssetTypes)
),
address: utils.decodeDotAddress(this._sender, utils.getAddressFormat(this._coinConfig.name as DotAssetTypes)),
});

const payee = txMethod.payee as StakeArgsPayeeRaw;
Expand Down
4 changes: 1 addition & 3 deletions modules/sdk-coin-dot/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ export class Transaction extends BaseTransaction {
const txMethod = decodedTx.method.args;
if (utils.isBond(txMethod)) {
const keypair = new KeyPair({
pub: Buffer.from(decodeAddress(txMethod.controller?.id || '', false, this._registry.chainSS58)).toString(
'hex'
),
pub: Buffer.from(decodeAddress(this._sender, false, this._registry.chainSS58)).toString('hex'),
});

result.controller = keypair.getAddress(utils.getAddressFormat(this._coinConfig.name as DotAssetTypes));
Expand Down
12 changes: 2 additions & 10 deletions modules/sdk-coin-dot/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,7 @@ export class Utils implements BaseUtils {
* @return true if arg is of type StakeBatchCallArgs, false otherwise.
*/
isStakeBatchCallArgs(arg: BatchCallObject['args']): arg is StakeBatchCallArgs {
return (
(arg as StakeBatchCallArgs).value !== undefined &&
(arg as StakeBatchCallArgs).controller !== undefined &&
(arg as StakeBatchCallArgs).payee !== undefined
);
return (arg as StakeBatchCallArgs).value !== undefined && (arg as StakeBatchCallArgs).payee !== undefined;
}

/**
Expand Down Expand Up @@ -398,11 +394,7 @@ export class Utils implements BaseUtils {
* @return true if arg is of type StakeArgs, false otherwise.
*/
isBond(arg: TxMethod['args']): arg is StakeArgs {
return (
(arg as StakeArgs).value !== undefined &&
(arg as StakeArgs).controller !== undefined &&
(arg as StakeArgs).payee !== undefined
);
return (arg as StakeArgs).value !== undefined && (arg as StakeArgs).payee !== undefined;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-dot/src/resources/westend.ts

Large diffs are not rendered by default.

26 changes: 11 additions & 15 deletions modules/sdk-coin-dot/test/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,16 @@ export const rawTx = {
},
stake: {
signed:
'0x4d02840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d0071858cd3a8db8e1903769108ee1be4ee1ccc8764129dde75bd64a8fbb16f8c96c90758b800d00fd10e40899251cf4644c73fdd1f9fe653fd9ec34a34a71e380dd5012103000600009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae25100',
'0xc501840082765e9588dce23285a48ce49feaafdf6f6de61b4bde9b96d193232108464dd90047c1d752eacd8afca9f0ea8ccf5fd3f5960e728f0097f32ffca6caee2af18c1e240c38dfc5f783a70002a24962d7fafe1c410f99e62f006b9c9e725a9ec54f0d5500000006000b005039278c0400',
unsigned:
'0xac0600009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae25100d501210300be23000008000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
signedAlt:
'0xcd02840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00e4842614d3271515f20c794a3f00669c15673ee56a7b4d9dfa901f7792445dfc0919a0de98b4b390806a66ad4f764a57f6c786659809921f1dd87a3671d81507d5012103000600009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae251039f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254',
unsignedAlt:
'0x2d010600009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae251039f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254d501210300be23000008000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
'0xc501840082765e9588dce23285a48ce49feaafdf6f6de61b4bde9b96d193232108464dd90047c1d752eacd8afca9f0ea8ccf5fd3f5960e728f0097f32ffca6caee2af18c1e240c38dfc5f783a70002a24962d7fafe1c410f99e62f006b9c9e725a9ec54f0d5500000006000b005039278c0400',
batchAll: {
signed:
'0xf102840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50e3502000010020806000061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d070088526a74001601009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540200000000',
'0x6d02840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50e350200001002080600070088526a74001601009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540200000000',
unsigned:
'0x550110020806000061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d070088526a74001601009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254020000000035020000682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
'0xd01002080600070088526a74001601009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254020000000035020000d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
batch: [
'0x06000061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d070088526a7400',
'0x0600070088526a7400',
'0x1601009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540200000000',
],
},
Expand All @@ -85,7 +81,7 @@ export const rawTx = {
signed:
'0xc501840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50ed50121030006010bfadb9bbae251',
unsigned:
'0x2406010bfadb9bbae251d501210300682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
'0x2406010bfadb9bbae251d501210300d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
},
addProxy: {
signed:
Expand All @@ -111,28 +107,28 @@ export const rawTx = {
signed:
'0x1502840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d0040ddb0cb7d290d14cd17f4d96f4261233d7add26505cb35bbbb93692467b88d31ba5e7d16fc8b3fd7a6e496d3c4a101dbc2a97f4ee81b2a16f4be672fdf1fd043502000010000c160400000000000000160400000000000100160400000000000200',
unsigned:
'0x7810000c16040000000000000016040000000000010016040000000000020035020000682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
'0x7810000c16040000000000000016040000000000010016040000000000020035020000d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
},
twoAddPureProxies: {
signed:
'0xf101840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50e15030000100008160400000000000000160400000000000100',
unsigned:
'0x541000081604000000000000001604000000000001003502210300682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
'0x541000081604000000000000001604000000000001003502210300d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
},
},
batchAll: {
twoAddPureProxies: {
signed:
'0xf101840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50e15030000100208160400000000000000160400000000000100',
unsigned:
'0x541002081604000000000000001604000000000001003502210300682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
'0x541002081604000000000000001604000000000001003502210300d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
},
},
proxy: {
signed:
'0xdd028400d472bd6e0f1f92297631938e30edb682208c2cd2698d80cf678c53a69979eb9f00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50ed50121030016000061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d01000403009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae251',
unsigned:
'0x3d0116000061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d01000403009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae251d501210300682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
'0x3d0116000061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d01000403009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae251d501210300d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e149799bc9602cb5cf201f3425fb8d253b2d4e61fc119dcab3249f307f594754d',
transferCall: '0x0503009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540bfadb9bbae251',
},
unstake: {
Expand All @@ -144,7 +140,7 @@ export const rawTx = {
signed:
'0x7102840061b18c6dc02ddcabdeac56cb4f21a971cc41cc97640f6f85b073480008c53a0d00aadae7fa1f53e7a5c900b330ff71bee6782cf3c29a2c6f9599162381cd021ad581c74ded89f49ec79adefed64af8ff16649553523dda9cb4f017cbf15681e50e3502000010020c1602009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254020000000006060602070088526a74',
unsigned:
'0xd410020c1602009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254020000000006060602070088526a7435020000682400000e000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
'0xd410020c1602009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f0254020000000006060602070088526a7435020000d624000016000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e462ab5246361febb9294ffa41dd099edddec30a205ea15fbd247abb0ddbabd51',
batch: [
'0x1602009f7b0675db59d19b4bd9c8c72eaabba75a9863d02b30115b8b3c3ca5c20f02540200000000',
'0x0606',
Expand Down
6 changes: 3 additions & 3 deletions modules/sdk-coin-dot/test/resources/materialData.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/sdk-coin-dot/test/resources/testnet.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ describe('Dot Batch Transaction Builder', () => {
const txJson = tx.toJson();
should.deepEqual(txJson.batchCalls.length, rawTx.stake.batchAll.batch.length);
should.deepEqual(txJson.batchCalls[0].callIndex, rawTx.stake.batchAll.batch[0].slice(0, 6));
should.deepEqual(txJson.batchCalls[0].args?.controller, { id: sender.address });
should.deepEqual(txJson.batchCalls[0].args?.value, 500000000000);
should.deepEqual(txJson.batchCalls[0].args?.payee, { staked: null });
should.deepEqual(txJson.batchCalls[1].callIndex, rawTx.stake.batchAll.batch[1].slice(0, 6));
Expand Down Expand Up @@ -255,7 +254,6 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.sender, sender.address);
should.deepEqual(txJson.batchCalls.length, rawTx.stake.batchAll.batch.length);
should.deepEqual(txJson.batchCalls[0].callIndex, rawTx.stake.batchAll.batch[0].slice(0, 6));
should.deepEqual(txJson.batchCalls[0].args?.controller, { id: sender.address });
should.deepEqual(txJson.batchCalls[0].args?.value, 500000000000);
should.deepEqual(txJson.batchCalls[0].args?.payee, { staked: null });
should.deepEqual(txJson.batchCalls[1].callIndex, rawTx.stake.batchAll.batch[1].slice(0, 6));
Expand Down Expand Up @@ -396,7 +394,6 @@ describe('Dot Batch Transaction Builder', () => {
const txJson = tx.toJson();
should.deepEqual(txJson.batchCalls.length, rawTx.stake.batchAll.batch.length);
should.deepEqual(txJson.batchCalls[0].callIndex, rawTx.stake.batchAll.batch[0].slice(0, 6));
should.deepEqual(txJson.batchCalls[0].args?.controller, { id: sender.address });
should.deepEqual(txJson.batchCalls[0].args?.value, 500000000000);
should.deepEqual(txJson.batchCalls[0].args?.payee, { staked: null });
should.deepEqual(txJson.batchCalls[1].callIndex, rawTx.stake.batchAll.batch[1].slice(0, 6));
Expand Down Expand Up @@ -534,7 +531,6 @@ describe('Dot Batch Transaction Builder', () => {
should.deepEqual(txJson.sender, sender.address);
should.deepEqual(txJson.batchCalls.length, rawTx.stake.batchAll.batch.length);
should.deepEqual(txJson.batchCalls[0].callIndex, rawTx.stake.batchAll.batch[0].slice(0, 6));
should.deepEqual(txJson.batchCalls[0].args?.controller, { id: sender.address });
should.deepEqual(txJson.batchCalls[0].args?.value, 500000000000);
should.deepEqual(txJson.batchCalls[0].args?.payee, { staked: null });
should.deepEqual(txJson.batchCalls[1].callIndex, rawTx.stake.batchAll.batch[1].slice(0, 6));
Expand Down
Loading
Loading