Skip to content

Commit

Permalink
fix(sdk-coin-sol): update split with latest SOL library
Browse files Browse the repository at this point in the history
TICKET: WP-0000
  • Loading branch information
noel-bitgo authored and alebusse committed Apr 17, 2024
1 parent 5c97588 commit 689c635
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 125 deletions.
2 changes: 1 addition & 1 deletion modules/account-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"bs58": "^4.0.1"
},
"devDependencies": {
"@solana/web3.js": "1.91.3",
"@solana/web3.js": "1.91.6",
"@types/bs58": "^4.0.1",
"keccak": "3.0.3",
"paillier-bigint": "3.3.0",
Expand Down
4 changes: 2 additions & 2 deletions modules/sdk-coin-sol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@bitgo/sdk-core": "^26.7.0",
"@bitgo/sdk-lib-mpc": "^9.2.0",
"@bitgo/statics": "^48.6.0",
"@solana/spl-token": "0.3.1",
"@solana/web3.js": "1.91.3",
"@solana/spl-token": "0.4.3",
"@solana/web3.js": "1.91.6",
"bignumber.js": "^9.0.0",
"bs58": "^4.0.1",
"lodash": "^4.17.14",
Expand Down
1 change: 1 addition & 0 deletions modules/sdk-coin-sol/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const MEMO_PROGRAM_PK = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
export const SEED_LENGTH = 32;

export const MAX_MEMO_LENGTH = 100;
export const STAKE_ACCOUNT_RENT_EXEMPT_AMOUNT = 2282880;

export const UNAVAILABLE_TEXT = 'UNAVAILABLE';

Expand Down
15 changes: 9 additions & 6 deletions modules/sdk-coin-sol/src/lib/solInstructionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,15 @@ function stakingDeactivateInstruction(data: StakingDeactivate): TransactionInstr
});
tx.add(assignAccount);

const splitStake = StakeProgram.split({
stakePubkey: new PublicKey(stakingAddress),
authorizedPubkey: new PublicKey(fromAddress),
splitStakePubkey: unstakingAddress,
lamports: new BigNumber(data.params.amount).toNumber(),
});
const splitStake = StakeProgram.split(
{
stakePubkey: new PublicKey(stakingAddress),
authorizedPubkey: new PublicKey(fromAddress),
splitStakePubkey: unstakingAddress,
lamports: new BigNumber(data.params.amount).toNumber(),
},
0
);
tx.add(splitStake.instructions[1]);

const deactivateStaking = StakeProgram.deactivate({
Expand Down
5 changes: 2 additions & 3 deletions modules/sdk-coin-sol/src/lib/stakingDeactivateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseCoin as CoinConfig } from '@bitgo/statics';
import assert from 'assert';

import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core';
import { InstructionBuilderTypes } from './constants';
import { InstructionBuilderTypes, STAKE_ACCOUNT_RENT_EXEMPT_AMOUNT } from './constants';
import { StakingDeactivate, Transfer } from './iface';
import { Transaction } from './transaction';
import { TransactionBuilder } from './transactionBuilder';
Expand All @@ -12,7 +12,6 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
protected _stakingAddress: string;
protected _stakingAddresses: string[];
protected _amount?: string;
protected _fundUnstakeAddress = 2282880;
protected _unstakingAddress: string;

constructor(_coinConfig: Readonly<CoinConfig>) {
Expand Down Expand Up @@ -146,7 +145,7 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
type: InstructionBuilderTypes.Transfer,
params: {
fromAddress: this._sender,
amount: this._fundUnstakeAddress.toString(),
amount: STAKE_ACCOUNT_RENT_EXEMPT_AMOUNT.toString(),
toAddress: this._unstakingAddress,
},
};
Expand Down
139 changes: 83 additions & 56 deletions modules/sdk-coin-sol/test/unit/instructionParamsFactory.staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as testData from '../resources/sol';
import { instructionParamsFactory } from '../../src/lib/instructionParamsFactory';
import { TransactionType } from '@bitgo/sdk-core';
import { InstructionParams, Nonce, StakingActivate, StakingDeactivate, StakingWithdraw } from '../../src/lib/iface';
import { InstructionBuilderTypes, MEMO_PROGRAM_PK } from '../../src/lib/constants';
import { InstructionBuilderTypes, MEMO_PROGRAM_PK, STAKE_ACCOUNT_RENT_EXEMPT_AMOUNT } from '../../src/lib/constants';
import {
Keypair as SolKeypair,
Lockup,
Expand Down Expand Up @@ -484,12 +484,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: StakeProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -532,12 +535,15 @@ describe('Instruction Parser Staking Tests: ', function () {
space: StakeProgram.space,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -624,12 +630,15 @@ describe('Instruction Parser Staking Tests: ', function () {
space: StakeProgram.space,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const assignInstruction = SystemProgram.assign({
accountPubkey: splitStakeAccount,
Expand Down Expand Up @@ -683,12 +692,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: StakeProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -738,12 +750,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: StakeProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -793,12 +808,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: SystemProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -848,12 +866,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: StakeProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: stakingAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: stakingAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -902,12 +923,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: StakeProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: stakingAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: stakingAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down Expand Up @@ -951,7 +975,7 @@ describe('Instruction Parser Staking Tests: ', function () {
const transferInstruction = SystemProgram.transfer({
fromPubkey: new PublicKey(fromAccount),
toPubkey: new PublicKey(splitStakeAccount),
lamports: parseInt((2282880).toString(), 10),
lamports: parseInt(STAKE_ACCOUNT_RENT_EXEMPT_AMOUNT.toString(), 10),
});

const allocateInstruction = SystemProgram.allocate({
Expand All @@ -964,12 +988,15 @@ describe('Instruction Parser Staking Tests: ', function () {
programId: StakeProgram.programId,
});

const splitInstructions = StakeProgram.split({
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
}).instructions;
const splitInstructions = StakeProgram.split(
{
stakePubkey: stakingAccount,
authorizedPubkey: fromAccount,
splitStakePubkey: splitStakeAccount,
lamports: 100000,
},
0
).instructions;

const stakingDeactivateInstructions = StakeProgram.deactivate({
authorizedPubkey: fromAccount,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@polkadot/x-global": "12.3.2",
"@polkadot/x-randomvalues": "12.3.2",
"@polkadot/x-ws": "12.3.2",
"@solana/web3.js": "1.91.6",
"@substrate/txwrapper-core": "7.0.1",
"@substrate/txwrapper-polkadot": "7.0.1",
"buffer": "^6.0.3",
Expand Down
Loading

0 comments on commit 689c635

Please sign in to comment.