Skip to content

Commit f5f91d4

Browse files
Merge pull request #6961 from BitGo/COIN-5605/implement-ata-address-explanation
fix(sdk-coin-sol): explain init ata address transactions
2 parents be6980a + 076f4cc commit f5f91d4

File tree

4 files changed

+185
-42
lines changed

4 files changed

+185
-42
lines changed

modules/sdk-coin-sol/src/lib/transaction.ts

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
BaseTransaction,
33
Entry,
44
InvalidTransactionError,
5+
ITokenEnablement,
56
ParseTransactionError,
67
SigningError,
78
TransactionRecipient,
@@ -19,6 +20,7 @@ import {
1920
ValidInstructionTypesEnum,
2021
} from './constants';
2122
import {
23+
AtaInit,
2224
DurableNonceParams,
2325
InstructionParams,
2426
Memo,
@@ -430,6 +432,8 @@ export class Transaction extends BaseTransaction {
430432

431433
let outputAmount = new BigNumber(0);
432434
const outputs: TransactionRecipient[] = [];
435+
// Create a separate array for token enablements
436+
const tokenEnablements: ITokenEnablement[] = [];
433437

434438
for (const instruction of decodedInstructions) {
435439
switch (instruction.type) {
@@ -480,6 +484,13 @@ export class Transaction extends BaseTransaction {
480484
outputAmount = outputAmount.plus(stakingWithdrawInstruction.params.amount);
481485
break;
482486
case InstructionBuilderTypes.CreateAssociatedTokenAccount:
487+
// Process token enablement instructions and collect them in the tokenEnablements array
488+
const ataInit = instruction as AtaInit;
489+
tokenEnablements.push({
490+
address: ataInit.params.ataAddress,
491+
tokenName: ataInit.params.tokenName,
492+
tokenAddress: ataInit.params.mintAddress,
493+
});
483494
break;
484495
case InstructionBuilderTypes.CustomInstruction:
485496
// Custom instructions are arbitrary and cannot be explained
@@ -500,7 +511,7 @@ export class Transaction extends BaseTransaction {
500511
}
501512
}
502513

503-
return this.getExplainedTransaction(outputAmount, outputs, memo, durableNonce);
514+
return this.getExplainedTransaction(outputAmount, outputs, memo, durableNonce, tokenEnablements);
504515
}
505516

506517
private calculateFee(): string {
@@ -520,22 +531,29 @@ export class Transaction extends BaseTransaction {
520531
outputAmount: BigNumber,
521532
outputs: TransactionRecipient[],
522533
memo: undefined | string = undefined,
523-
durableNonce: undefined | DurableNonceParams = undefined
534+
durableNonce: undefined | DurableNonceParams = undefined,
535+
tokenEnablements: ITokenEnablement[] = []
524536
): TransactionExplanation {
525537
const feeString = this.calculateFee();
526-
return {
527-
displayOrder: [
528-
'id',
529-
'type',
530-
'blockhash',
531-
'durableNonce',
532-
'outputAmount',
533-
'changeAmount',
534-
'outputs',
535-
'changeOutputs',
536-
'fee',
537-
'memo',
538-
],
538+
539+
// Create displayOrder with tokenEnablements always included
540+
const displayOrder = [
541+
'id',
542+
'type',
543+
'blockhash',
544+
'durableNonce',
545+
'outputAmount',
546+
'changeAmount',
547+
'outputs',
548+
'changeOutputs',
549+
'tokenEnablements',
550+
'fee',
551+
'memo',
552+
];
553+
554+
// Create the base explanation object with tokenEnablements always included
555+
const explanation: TransactionExplanation = {
556+
displayOrder,
539557
id: this.id,
540558
type: TransactionType[this.type].toString(),
541559
changeOutputs: [],
@@ -549,7 +567,10 @@ export class Transaction extends BaseTransaction {
549567
memo: memo,
550568
blockhash: this.getNonce(),
551569
durableNonce: durableNonce,
570+
tokenEnablements: tokenEnablements,
552571
};
572+
573+
return explanation;
553574
}
554575

555576
private explainRawMsgAuthorizeTransaction(): TransactionExplanation {
@@ -586,6 +607,7 @@ export class Transaction extends BaseTransaction {
586607
'changeAmount',
587608
'outputs',
588609
'changeOutputs',
610+
'tokenEnablements',
589611
'fee',
590612
'memo',
591613
],
@@ -602,6 +624,7 @@ export class Transaction extends BaseTransaction {
602624
blockhash: this.getNonce(),
603625
durableNonce: durableNonce,
604626
stakingAuthorize: stakingAuthorizeParams,
627+
tokenEnablements: [], // Always include tokenEnablements as an empty array for consistency
605628
};
606629
}
607630
}

modules/sdk-coin-sol/test/unit/sol.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ describe('SOL:', function () {
798798
'changeAmount',
799799
'outputs',
800800
'changeOutputs',
801+
'tokenEnablements',
801802
'fee',
802803
'memo',
803804
],
@@ -822,6 +823,7 @@ describe('SOL:', function () {
822823
authWalletAddress: '5hr5fisPi6DXNuuRpm5XUbzpiEnmdyxXuBDTwzwZj5Pe',
823824
walletNonceAddress: '8Y7RM6JfcX4ASSNBkrkrmSbRu431YVi9Y3oLFnzC2dCh',
824825
},
826+
tokenEnablements: [],
825827
});
826828
});
827829

@@ -842,6 +844,7 @@ describe('SOL:', function () {
842844
'changeAmount',
843845
'outputs',
844846
'changeOutputs',
847+
'tokenEnablements',
845848
'fee',
846849
'memo',
847850
],
@@ -866,6 +869,7 @@ describe('SOL:', function () {
866869
authWalletAddress: '5hr5fisPi6DXNuuRpm5XUbzpiEnmdyxXuBDTwzwZj5Pe',
867870
walletNonceAddress: '8Y7RM6JfcX4ASSNBkrkrmSbRu431YVi9Y3oLFnzC2dCh',
868871
},
872+
tokenEnablements: [],
869873
});
870874
});
871875

@@ -887,6 +891,7 @@ describe('SOL:', function () {
887891
'changeAmount',
888892
'outputs',
889893
'changeOutputs',
894+
'tokenEnablements',
890895
'fee',
891896
'memo',
892897
],
@@ -908,6 +913,7 @@ describe('SOL:', function () {
908913
blockhash: 'GHtXQBsoZHVnNFa9YevAzFr17DJjgHXk3ycTKD5xD3Zi',
909914
durableNonce: undefined,
910915
memo: undefined,
916+
tokenEnablements: [],
911917
});
912918
});
913919

@@ -929,6 +935,7 @@ describe('SOL:', function () {
929935
'changeAmount',
930936
'outputs',
931937
'changeOutputs',
938+
'tokenEnablements',
932939
'fee',
933940
'memo',
934941
],
@@ -950,6 +957,7 @@ describe('SOL:', function () {
950957
blockhash: 'GHtXQBsoZHVnNFa9YevAzFr17DJjgHXk3ycTKD5xD3Zi',
951958
durableNonce: undefined,
952959
memo: undefined,
960+
tokenEnablements: [],
953961
});
954962
});
955963

@@ -970,6 +978,7 @@ describe('SOL:', function () {
970978
'changeAmount',
971979
'outputs',
972980
'changeOutputs',
981+
'tokenEnablements',
973982
'fee',
974983
'memo',
975984
],
@@ -995,6 +1004,7 @@ describe('SOL:', function () {
9951004
authWalletAddress: '12f6D3WubGVeQoH2m8kTvvcrasWdXWwtVzUCyRNDZxA2',
9961005
walletNonceAddress: '8Y7RM6JfcX4ASSNBkrkrmSbRu431YVi9Y3oLFnzC2dCh',
9971006
},
1007+
tokenEnablements: [],
9981008
});
9991009
});
10001010

@@ -1015,6 +1025,7 @@ describe('SOL:', function () {
10151025
'changeAmount',
10161026
'outputs',
10171027
'changeOutputs',
1028+
'tokenEnablements',
10181029
'fee',
10191030
'memo',
10201031
],
@@ -1040,6 +1051,7 @@ describe('SOL:', function () {
10401051
authWalletAddress: '12f6D3WubGVeQoH2m8kTvvcrasWdXWwtVzUCyRNDZxA2',
10411052
walletNonceAddress: '8Y7RM6JfcX4ASSNBkrkrmSbRu431YVi9Y3oLFnzC2dCh',
10421053
},
1054+
tokenEnablements: [],
10431055
});
10441056
});
10451057

@@ -1071,6 +1083,7 @@ describe('SOL:', function () {
10711083
'changeAmount',
10721084
'outputs',
10731085
'changeOutputs',
1086+
'tokenEnablements',
10741087
'fee',
10751088
'memo',
10761089
],
@@ -1092,6 +1105,7 @@ describe('SOL:', function () {
10921105
memo: 'test memo',
10931106
blockhash: '5ne7phA48Jrvpn39AtupB8ZkCCAy8gLTfpGihZPuDqen',
10941107
durableNonce: undefined,
1108+
tokenEnablements: [],
10951109
});
10961110
});
10971111

@@ -1121,6 +1135,7 @@ describe('SOL:', function () {
11211135
'changeAmount',
11221136
'outputs',
11231137
'changeOutputs',
1138+
'tokenEnablements',
11241139
'fee',
11251140
'memo',
11261141
],
@@ -1137,6 +1152,7 @@ describe('SOL:', function () {
11371152
memo: 'test memo',
11381153
blockhash: '5ne7phA48Jrvpn39AtupB8ZkCCAy8gLTfpGihZPuDqen',
11391154
durableNonce: undefined,
1155+
tokenEnablements: [],
11401156
});
11411157
});
11421158

@@ -1167,6 +1183,7 @@ describe('SOL:', function () {
11671183
'changeAmount',
11681184
'outputs',
11691185
'changeOutputs',
1186+
'tokenEnablements',
11701187
'fee',
11711188
'memo',
11721189
],
@@ -1188,6 +1205,7 @@ describe('SOL:', function () {
11881205
memo: 'test memo',
11891206
blockhash: '5ne7phA48Jrvpn39AtupB8ZkCCAy8gLTfpGihZPuDqen',
11901207
durableNonce: undefined,
1208+
tokenEnablements: [],
11911209
});
11921210
});
11931211

@@ -1221,6 +1239,7 @@ describe('SOL:', function () {
12211239
'changeAmount',
12221240
'outputs',
12231241
'changeOutputs',
1242+
'tokenEnablements',
12241243
'fee',
12251244
'memo',
12261245
],
@@ -1237,6 +1256,13 @@ describe('SOL:', function () {
12371256
memo: 'test memo',
12381257
blockhash: '5ne7phA48Jrvpn39AtupB8ZkCCAy8gLTfpGihZPuDqen',
12391258
durableNonce: undefined,
1259+
tokenEnablements: [
1260+
{
1261+
address: '141BFNem3pknc8CzPVLv1Ri3btgKdCsafYP5nXwmXfxU',
1262+
tokenAddress: 'F4uLeXJoFz3hw13MposuwaQbMcZbCjqvEGPPeRRB1Byf',
1263+
tokenName: 'tsol:usdc',
1264+
},
1265+
],
12401266
});
12411267
});
12421268

@@ -1280,6 +1306,7 @@ describe('SOL:', function () {
12801306
'changeAmount',
12811307
'outputs',
12821308
'changeOutputs',
1309+
'tokenEnablements',
12831310
'fee',
12841311
'memo',
12851312
],
@@ -1296,6 +1323,18 @@ describe('SOL:', function () {
12961323
memo: 'test memo',
12971324
blockhash: '5ne7phA48Jrvpn39AtupB8ZkCCAy8gLTfpGihZPuDqen',
12981325
durableNonce: undefined,
1326+
tokenEnablements: [
1327+
{
1328+
address: '141BFNem3pknc8CzPVLv1Ri3btgKdCsafYP5nXwmXfxU',
1329+
tokenAddress: 'F4uLeXJoFz3hw13MposuwaQbMcZbCjqvEGPPeRRB1Byf',
1330+
tokenName: 'tsol:usdc',
1331+
},
1332+
{
1333+
address: '9KaLinZFNW5chL4J8UoKnTECppWVMz3ewgx4FAkxUDcf',
1334+
tokenAddress: '9kLJoGbMgSteptkhKKuh7ken4JEvHrT83157ezEGrZ7R',
1335+
tokenName: 'tsol:ray',
1336+
},
1337+
],
12991338
});
13001339
});
13011340

@@ -1317,6 +1356,7 @@ describe('SOL:', function () {
13171356
'changeAmount',
13181357
'outputs',
13191358
'changeOutputs',
1359+
'tokenEnablements',
13201360
'fee',
13211361
'memo',
13221362
],
@@ -1336,6 +1376,13 @@ describe('SOL:', function () {
13361376
memo: undefined,
13371377
blockhash: '27E3MXFvXMUNYeMJeX1pAbERGsJfUbkaZTfgMgpmNN5g',
13381378
durableNonce: undefined,
1379+
tokenEnablements: [
1380+
{
1381+
address: '2eKjVtzV3oPTXFdtRSDj3Em9k1MV7k8WjKkBszQUwizS',
1382+
tokenAddress: 'F4uLeXJoFz3hw13MposuwaQbMcZbCjqvEGPPeRRB1Byf',
1383+
tokenName: 'tsol:usdc',
1384+
},
1385+
],
13391386
});
13401387
});
13411388
});

0 commit comments

Comments
 (0)