Skip to content

Commit c071f3c

Browse files
committed
fix: align InstructionBuilderTypes string values with WASM output
BTC-0 TICKET: BTC-0
1 parent 009f956 commit c071f3c

11 files changed

Lines changed: 32 additions & 23 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@ export enum ValidInstructionTypesEnum {
6666
// Internal instructions types
6767
export enum InstructionBuilderTypes {
6868
CreateNonceAccount = 'CreateNonceAccount',
69-
StakingActivate = 'Activate',
70-
StakingDeactivate = 'Deactivate',
71-
StakingWithdraw = 'Withdraw',
69+
StakingActivate = 'StakingActivate',
70+
StakingDeactivate = 'StakingDeactivate',
71+
StakingWithdraw = 'StakingWithdraw',
7272
Transfer = 'Transfer',
7373
Memo = 'Memo',
7474
NonceAdvance = 'NonceAdvance',
7575
CreateAssociatedTokenAccount = 'CreateAssociatedTokenAccount',
7676
CloseAssociatedTokenAccount = 'CloseAssociatedTokenAccount',
7777
TokenTransfer = 'TokenTransfer',
78-
StakingAuthorize = 'Authorize',
79-
StakingDelegate = 'Delegate',
78+
StakingAuthorize = 'StakingAuthorize',
79+
StakingDelegate = 'StakingDelegate',
8080
SetComputeUnitLimit = 'SetComputeUnitLimit',
8181
SetPriorityFee = 'SetPriorityFee',
8282
MintTo = 'MintTo',

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ExplainedOutputs {
99
tokenEnablements: ITokenEnablement[];
1010
outputAmount: bigint;
1111
memo?: string;
12+
ataOwnerMap: Record<string, string>;
1213
}
1314

1415
/**
@@ -29,6 +30,7 @@ export function extractOutputsFromInstructions(
2930
const outputs: TransactionRecipient[] = [];
3031
const inputs: Array<{ address: string; value: string; coin?: string }> = [];
3132
const tokenEnablements: ITokenEnablement[] = [];
33+
const ataOwnerMap: Record<string, string> = {};
3234
let outputAmount = 0n;
3335
let memo: string | undefined;
3436

@@ -76,6 +78,7 @@ export function extractOutputsFromInstructions(
7678
break;
7779

7880
case InstructionBuilderTypes.CreateAssociatedTokenAccount:
81+
ataOwnerMap[instr.params.ataAddress] = instr.params.ownerAddress;
7982
if (resolveTokenName) {
8083
tokenEnablements.push({
8184
address: instr.params.ataAddress,
@@ -91,5 +94,5 @@ export function extractOutputsFromInstructions(
9194
}
9295
}
9396

94-
return { outputs, inputs, tokenEnablements, outputAmount, memo };
97+
return { outputs, inputs, tokenEnablements, outputAmount, memo, ataOwnerMap };
9598
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export interface TransactionExplanation extends BaseTransactionExplanation {
289289
stakingDelegate?: StakingDelegateParams;
290290
inputs?: Array<{ address: string; value: string; coin?: string }>;
291291
feePayer?: string;
292+
ataOwnerMap?: Record<string, string>;
292293
}
293294

294295
export class TokenAssociateRecipient {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ export function getTransactionType(transaction: SolTransaction): TransactionType
332332
if (memoData?.includes('WalletConnectDefiCustomTx')) {
333333
return TransactionType.CustomTx;
334334
}
335-
if (instructions.filter((instruction) => getInstructionType(instruction) === 'Deactivate').length === 0) {
335+
if (
336+
instructions.filter(
337+
(instruction) => getInstructionType(instruction) === ValidInstructionTypesEnum.StakingDeactivate
338+
).length === 0
339+
) {
336340
for (const instruction of instructions) {
337341
const instructionType = getInstructionType(instruction);
338342
// Check if memo instruction is there and if it contains 'PrepareForRevoke' because Marinade staking deactivate transaction will have this

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ export function explainSolTransaction(
17831783
const { instructions: combinedInstructions, transactionType } = combineWasmInstructionsFromBytes(txBytes);
17841784

17851785
const resolveTokenName = (addr: string) => findTokenName(addr, undefined, true);
1786-
const { outputs, tokenEnablements, outputAmount, memo } = extractOutputsFromInstructions(
1786+
const { outputs, tokenEnablements, outputAmount, memo, ataOwnerMap } = extractOutputsFromInstructions(
17871787
combinedInstructions,
17881788
params.coinName,
17891789
resolveTokenName
@@ -1838,5 +1838,6 @@ export function explainSolTransaction(
18381838
blockhash: parsed.nonce,
18391839
durableNonce,
18401840
tokenEnablements,
1841+
ataOwnerMap,
18411842
};
18421843
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('Sol Staking Withdraw Builder', () => {
3232
should.equal(Utils.isValidRawTransaction(rawTx), true);
3333
txJson.instructionsData.should.deepEqual([
3434
{
35-
type: 'Withdraw',
35+
type: 'StakingWithdraw',
3636
params: {
3737
fromAddress: wallet.pub,
3838
stakingAddress: stakeAccount.pub,
@@ -58,7 +58,7 @@ describe('Sol Staking Withdraw Builder', () => {
5858
const txJson = tx.toJson();
5959
txJson.instructionsData.should.deepEqual([
6060
{
61-
type: 'Withdraw',
61+
type: 'StakingWithdraw',
6262
params: {
6363
fromAddress: wallet.pub,
6464
stakingAddress: stakeAccount.pub,
@@ -84,7 +84,7 @@ describe('Sol Staking Withdraw Builder', () => {
8484
const txJson = tx.toJson();
8585
txJson.instructionsData.should.deepEqual([
8686
{
87-
type: 'Withdraw',
87+
type: 'StakingWithdraw',
8888
params: {
8989
fromAddress: wallet.pub,
9090
stakingAddress: stakeAccount.pub,
@@ -109,7 +109,7 @@ describe('Sol Staking Withdraw Builder', () => {
109109
const txJson = tx.toJson();
110110
txJson.instructionsData.should.deepEqual([
111111
{
112-
type: 'Withdraw',
112+
type: 'StakingWithdraw',
113113
params: {
114114
fromAddress: wallet.pub,
115115
stakingAddress: stakeAccount.pub,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Sol Staking Activate Builder', () => {
9595
]
9696
: []),
9797
{
98-
type: 'Activate',
98+
type: 'StakingActivate',
9999
params: {
100100
fromAddress: wallet.pub,
101101
stakingAddress: stakeAccount.pub,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('Sol Staking Deactivate Builder', () => {
107107
]
108108
: []),
109109
...stakingAddresses.map((stakingAddress) => ({
110-
type: 'Deactivate',
110+
type: 'StakingDeactivate',
111111
params: {
112112
stakingAddress,
113113
amount: undefined,
@@ -213,7 +213,7 @@ describe('Sol Staking Deactivate Builder', () => {
213213
should.equal(Utils.isValidRawTransaction(rawTx), true);
214214
txJson.instructionsData.should.deepEqual([
215215
{
216-
type: 'Deactivate',
216+
type: 'StakingDeactivate',
217217
params: {
218218
fromAddress: wallet.pub,
219219
stakingAddress: stakeAccount.pub,
@@ -271,7 +271,7 @@ describe('Sol Staking Deactivate Builder', () => {
271271
type: 'Memo',
272272
},
273273
{
274-
type: 'Deactivate',
274+
type: 'StakingDeactivate',
275275
params: {
276276
fromAddress: '',
277277
stakingAddress: '',
@@ -327,7 +327,7 @@ describe('Sol Staking Deactivate Builder', () => {
327327
const txJson = tx.toJson();
328328
txJson.instructionsData.should.deepEqual([
329329
{
330-
type: 'Deactivate',
330+
type: 'StakingDeactivate',
331331
params: {
332332
fromAddress: wallet.pub,
333333
stakingAddress: JITO_STAKE_POOL_ADDRESS,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Sol Staking Delegate Builder', () => {
2929
should.equal(Utils.isValidRawTransaction(rawTx), true);
3030
txJson.instructionsData.should.deepEqual([
3131
{
32-
type: 'Delegate',
32+
type: 'StakingDelegate',
3333
params: {
3434
fromAddress: wallet.pub,
3535
stakingAddress: stakeAccount.pub,
@@ -70,15 +70,15 @@ describe('Sol Staking Delegate Builder', () => {
7070
should.equal(Utils.isValidRawTransaction(rawTx), true);
7171
txJson.instructionsData.should.deepEqual([
7272
{
73-
type: 'Delegate',
73+
type: 'StakingDelegate',
7474
params: {
7575
fromAddress: wallet.pub,
7676
stakingAddress: stakeAccount.pub,
7777
validator: validator.pub,
7878
},
7979
},
8080
{
81-
type: 'Delegate',
81+
type: 'StakingDelegate',
8282
params: {
8383
fromAddress: wallet.pub,
8484
stakingAddress: splitAccount.pub,
@@ -119,7 +119,7 @@ describe('Sol Staking Delegate Builder', () => {
119119
should.equal(Utils.isValidRawTransaction(rawTx), true);
120120
txJson.instructionsData.should.deepEqual([
121121
{
122-
type: 'Delegate',
122+
type: 'StakingDelegate',
123123
params: {
124124
fromAddress: wallet.pub,
125125
stakingAddress: stakeAccount.pub,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe('Sol Transaction Builder', async () => {
102102
jsonTx.numSignatures.should.equal(2);
103103
jsonTx.instructionsData.should.deepEqual([
104104
{
105-
type: 'Activate',
105+
type: 'StakingActivate',
106106
params: {
107107
fromAddress: '5hr5fisPi6DXNuuRpm5XUbzpiEnmdyxXuBDTwzwZj5Pe',
108108
stakingAddress: '7dRuGFbU2y2kijP6o1LYNzVyz4yf13MooqoionCzv5Za',

0 commit comments

Comments
 (0)