Skip to content
Draft
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
Binary file not shown.
1 change: 1 addition & 0 deletions modules/sdk-coin-sol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@bitgo/sdk-core": "^36.29.0",
"@bitgo/sdk-lib-mpc": "^10.8.1",
"@bitgo/statics": "^58.23.0",
"@bitgo/wasm-solana": "file:bitgo-wasm-solana-0.0.1.tgz",
"@solana/spl-stake-pool": "1.1.8",
"@solana/spl-token": "0.3.1",
"@solana/web3.js": "1.92.1",
Expand Down
2 changes: 2 additions & 0 deletions modules/sdk-coin-sol/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export { StakingWithdrawBuilder } from './stakingWithdrawBuilder';
export { TokenTransferBuilder } from './tokenTransferBuilder';
export { Transaction } from './transaction';
export { TransactionBuilder } from './transactionBuilder';
export { WasmTransaction } from './wasm';
export { TransactionBuilderFactory } from './transactionBuilderFactory';
export { TransferBuilder } from './transferBuilder';
export { TransferBuilderV2 } from './transferBuilderV2';
export { WalletInitializationBuilder } from './walletInitializationBuilder';
export { Interface, Utils };
export { MessageBuilderFactory } from './messages';
export { InstructionBuilderTypes } from './constants';
49 changes: 34 additions & 15 deletions modules/sdk-coin-sol/src/lib/instructionParamsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ type StakingInstructions = {
initialize?: InitializeStakeParams;
delegate?: DelegateStakeParams;
hasAtaInit?: boolean;
ataInitInstruction?: AtaInit;
};

type JitoStakingInstructions = StakingInstructions & {
Expand Down Expand Up @@ -454,7 +455,9 @@ function parseStakingActivateInstructions(

case ValidInstructionTypesEnum.InitializeAssociatedTokenAccount:
stakingInstructions.hasAtaInit = true;
instructionData.push({
// Store the ATA init instruction - we'll decide later whether to add it to instructionData
// based on staking type (Jito staking uses a flag instead of a separate instruction)
stakingInstructions.ataInitInstruction = {
type: InstructionBuilderTypes.CreateAssociatedTokenAccount,
params: {
mintAddress: instruction.keys[ataInitInstructionKeysIndexes.MintAddress].pubkey.toString(),
Expand All @@ -463,7 +466,7 @@ function parseStakingActivateInstructions(
payerAddress: instruction.keys[ataInitInstructionKeysIndexes.PayerAddress].pubkey.toString(),
tokenName: findTokenName(instruction.keys[ataInitInstructionKeysIndexes.MintAddress].pubkey.toString()),
},
});
};
break;
}
}
Expand Down Expand Up @@ -536,6 +539,12 @@ function parseStakingActivateInstructions(
}
}

// For non-Jito staking, add the ATA instruction as a separate instruction
// (Jito staking uses the createAssociatedTokenAccount flag in extraParams instead)
if (stakingType !== SolStakingTypeEnum.JITO && stakingInstructions.ataInitInstruction) {
instructionData.push(stakingInstructions.ataInitInstruction);
}

instructionData.push(stakingActivate);

return instructionData;
Expand Down Expand Up @@ -1171,7 +1180,10 @@ function parseStakingAuthorizeInstructions(
*/
function parseStakingAuthorizeRawInstructions(instructions: TransactionInstruction[]): Array<Nonce | StakingAuthorize> {
const instructionData: Array<Nonce | StakingAuthorize> = [];
assert(instructions.length === 2, 'Invalid number of instructions');
// StakingAuthorizeRaw transactions have:
// - 2 instructions: NonceAdvance + 1 Authorize (changing either staking OR withdraw authority)
// - 3 instructions: NonceAdvance + 2 Authorizes (changing BOTH staking AND withdraw authority)
assert(instructions.length >= 2 && instructions.length <= 3, 'Invalid number of instructions');
const advanceNonceInstruction = SystemInstruction.decodeNonceAdvance(instructions[0]);
const nonce: Nonce = {
type: InstructionBuilderTypes.NonceAdvance,
Expand All @@ -1181,17 +1193,24 @@ function parseStakingAuthorizeRawInstructions(instructions: TransactionInstructi
},
};
instructionData.push(nonce);
const authorize = instructions[1];
assert(authorize.keys.length === 5, 'Invalid number of keys in authorize instruction');
instructionData.push({
type: InstructionBuilderTypes.StakingAuthorize,
params: {
stakingAddress: authorize.keys[0].pubkey.toString(),
oldAuthorizeAddress: authorize.keys[2].pubkey.toString(),
newAuthorizeAddress: authorize.keys[3].pubkey.toString(),
custodianAddress: authorize.keys[4].pubkey.toString(),
},
});

// Process all authorize instructions (1 or 2)
for (let i = 1; i < instructions.length; i++) {
const authorize = instructions[i];
// Authorize instruction keys: [stakePubkey, clockSysvar, oldAuthority, newAuthority, custodian?]
// - 4 keys: no custodian required
// - 5 keys: custodian is present (required when stake is locked)
assert(authorize.keys.length >= 4 && authorize.keys.length <= 5, 'Invalid number of keys in authorize instruction');
instructionData.push({
type: InstructionBuilderTypes.StakingAuthorize,
params: {
stakingAddress: authorize.keys[0].pubkey.toString(),
oldAuthorizeAddress: authorize.keys[2].pubkey.toString(),
newAuthorizeAddress: authorize.keys[3].pubkey.toString(),
custodianAddress: authorize.keys.length === 5 ? authorize.keys[4].pubkey.toString() : '',
},
});
}
return instructionData;
}

Expand Down Expand Up @@ -1239,7 +1258,7 @@ function parseCustomInstructions(
return instructionData;
}

function findTokenName(
export function findTokenName(
mintAddress: string,
instructionMetadata?: InstructionParams[],
_useTokenAddressTokenName?: boolean
Expand Down
7 changes: 7 additions & 0 deletions modules/sdk-coin-sol/src/lib/wasm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* WASM-only implementations for Solana.
*
* These implementations use @bitgo/wasm-solana exclusively,
* with zero @solana/web3.js dependencies.
*/
export { WasmTransaction } from './transaction';
Loading
Loading