Skip to content
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
1 change: 1 addition & 0 deletions modules/sdk-coin-sol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
]
},
"dependencies": {
"@bitgo/public-types": "5.18.0",
"@bitgo/sdk-core": "^36.3.0",
"@bitgo/sdk-lib-mpc": "^10.6.0",
"@bitgo/statics": "^57.3.0",
Expand Down
11 changes: 3 additions & 8 deletions modules/sdk-coin-sol/src/lib/iface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SolStakingTypeEnum } from '@bitgo/public-types';
import { TransactionExplanation as BaseTransactionExplanation, Recipient, SolInstruction } from '@bitgo/sdk-core';
import { DecodedCloseAccountInstruction } from '@solana/spl-token';
import { Blockhash, StakeInstructionType, SystemInstructionType, TransactionSignature } from '@solana/web3.js';
Expand Down Expand Up @@ -120,12 +121,6 @@ export interface Approve {
};
}

export enum StakingType {
NATIVE = 'NATIVE',
MARINADE = 'MARINADE',
JITO = 'JITO',
}

export interface JitoStakingActivateParams {
stakePoolData: DepositSolStakePoolData;
}
Expand All @@ -139,7 +134,7 @@ export interface StakingActivate {
stakingAddress: string;
amount: string;
validator: string;
stakingType: StakingType;
stakingType: SolStakingTypeEnum;
extraParams?: StakingActivateExtraParams;
};
}
Expand All @@ -164,7 +159,7 @@ export interface StakingDeactivate {
stakingAddress: string;
amount?: string;
unstakingAddress?: string;
stakingType: StakingType;
stakingType: SolStakingTypeEnum;
extraParams?: StakingDeactivateExtraParams;
recipients?: Recipient[];
};
Expand Down
30 changes: 15 additions & 15 deletions modules/sdk-coin-sol/src/lib/instructionParamsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
ComputeBudgetInstruction,
} from '@solana/web3.js';

import { SolStakingTypeEnum } from '@bitgo/public-types';
import { NotSupported, TransactionType } from '@bitgo/sdk-core';
import { coins, SolCoin } from '@bitgo/statics';
import assert from 'assert';
Expand All @@ -47,7 +48,6 @@ import {
SetPriorityFee,
CustomInstruction,
Approve,
StakingType,
} from './iface';
import { getInstructionType } from './utils';
import { DepositSolParams, WithdrawStakeParams } from '@solana/spl-stake-pool';
Expand Down Expand Up @@ -359,14 +359,14 @@ function isNativeStakingInstructions(si: StakingInstructions): si is NativeStaki
return si.create !== undefined && si.initialize !== undefined && si.delegate !== undefined;
}

function getStakingTypeFromStakingInstructions(si: StakingInstructions): StakingType {
function getStakingTypeFromStakingInstructions(si: StakingInstructions): SolStakingTypeEnum {
const isJito = isJitoStakingInstructions(si);
const isMarinade = isMarinadeStakingInstructions(si);
const isNative = isNativeStakingInstructions(si);
assert([isJito, isMarinade, isNative].filter((x) => x).length === 1, 'StakingType is ambiguous');
if (isJito) return StakingType.JITO;
if (isMarinade) return StakingType.MARINADE;
if (isNative) return StakingType.NATIVE;
if (isJito) return SolStakingTypeEnum.JITO;
if (isMarinade) return SolStakingTypeEnum.MARINADE;
if (isNative) return SolStakingTypeEnum.NATIVE;
assert(false, 'No StakingType found');
}

Expand Down Expand Up @@ -439,7 +439,7 @@ function parseStakingActivateInstructions(
let stakingActivate: StakingActivate | undefined;

switch (stakingType) {
case StakingType.JITO: {
case SolStakingTypeEnum.JITO: {
assert(isJitoStakingInstructions(stakingInstructions));
const { depositSol } = stakingInstructions;
stakingActivate = {
Expand All @@ -462,7 +462,7 @@ function parseStakingActivateInstructions(
break;
}

case StakingType.MARINADE: {
case SolStakingTypeEnum.MARINADE: {
assert(isMarinadeStakingInstructions(stakingInstructions));
const { create, initialize } = stakingInstructions;
stakingActivate = {
Expand All @@ -478,7 +478,7 @@ function parseStakingActivateInstructions(
break;
}

case StakingType.NATIVE: {
case SolStakingTypeEnum.NATIVE: {
assert(isNativeStakingInstructions(stakingInstructions));
const { create, initialize, delegate } = stakingInstructions;
stakingActivate = {
Expand Down Expand Up @@ -595,14 +595,14 @@ function isNativeUnstakingInstructions(ui: UnstakingInstructions): ui is NativeU
return ui.deactivate !== undefined;
}

function getStakingTypeFromUnstakingInstructions(ui: UnstakingInstructions): StakingType {
function getStakingTypeFromUnstakingInstructions(ui: UnstakingInstructions): SolStakingTypeEnum {
const isJito = isJitoUnstakingInstructions(ui);
const isMarinade = isMarinadeUnstakingInstructions(ui);
const isNative = isNativeUnstakingInstructions(ui);
assert([isJito, isMarinade, isNative].filter((x) => x).length === 1, 'StakingType is ambiguous');
if (isJito) return StakingType.JITO;
if (isMarinade) return StakingType.MARINADE;
if (isNative) return StakingType.NATIVE;
if (isJito) return SolStakingTypeEnum.JITO;
if (isMarinade) return SolStakingTypeEnum.MARINADE;
if (isNative) return SolStakingTypeEnum.NATIVE;
assert(false, 'No StakingType found');
}

Expand Down Expand Up @@ -739,7 +739,7 @@ function parseStakingDeactivateInstructions(
let stakingDeactivate: StakingDeactivate | undefined;

switch (stakingType) {
case StakingType.JITO: {
case SolStakingTypeEnum.JITO: {
assert(isJitoUnstakingInstructions(unstakingInstruction));
const { withdrawStake } = unstakingInstruction;
stakingDeactivate = {
Expand All @@ -764,7 +764,7 @@ function parseStakingDeactivateInstructions(
break;
}

case StakingType.MARINADE: {
case SolStakingTypeEnum.MARINADE: {
assert(isMarinadeUnstakingInstructions(unstakingInstruction));
const { transfer } = unstakingInstruction;

Expand All @@ -785,7 +785,7 @@ function parseStakingDeactivateInstructions(
break;
}

case StakingType.NATIVE: {
case SolStakingTypeEnum.NATIVE: {
assert(isNativeUnstakingInstructions(unstakingInstruction));
const { deactivate, split } = unstakingInstruction;
stakingDeactivate = {
Expand Down
14 changes: 7 additions & 7 deletions modules/sdk-coin-sol/src/lib/solInstructionFactory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SolStakingTypeEnum } from '@bitgo/public-types';
import { SolCoin } from '@bitgo/statics';
import {
createAssociatedTokenAccountInstruction,
Expand Down Expand Up @@ -41,7 +42,6 @@ import {
SetPriorityFee,
CustomInstruction,
Approve,
StakingType,
} from './iface';
import { getSolTokenFromTokenName, isValidBase64, isValidHex } from './utils';
import { depositSolInstructions, withdrawStakeInstructions } from './jitoStakePoolOperations';
Expand Down Expand Up @@ -288,7 +288,7 @@ function stakingInitializeInstruction(data: StakingActivate): TransactionInstruc
const tx = new Transaction();

switch (stakingType) {
case StakingType.JITO: {
case SolStakingTypeEnum.JITO: {
assert(extraParams !== undefined, 'Missing extraParams param');
const instructions = depositSolInstructions(
{
Expand All @@ -302,7 +302,7 @@ function stakingInitializeInstruction(data: StakingActivate): TransactionInstruc
break;
}

case StakingType.MARINADE: {
case SolStakingTypeEnum.MARINADE: {
const walletInitStaking = StakeProgram.createAccount({
fromPubkey,
stakePubkey,
Expand All @@ -314,7 +314,7 @@ function stakingInitializeInstruction(data: StakingActivate): TransactionInstruc
break;
}

case StakingType.NATIVE: {
case SolStakingTypeEnum.NATIVE: {
const walletInitStaking = StakeProgram.createAccount({
fromPubkey,
stakePubkey,
Expand Down Expand Up @@ -355,7 +355,7 @@ function stakingDeactivateInstruction(data: StakingDeactivate): TransactionInstr
assert(fromAddress, 'Missing fromAddress param');

switch (stakingType) {
case StakingType.JITO: {
case SolStakingTypeEnum.JITO: {
assert(stakingAddress, 'Missing stakingAddress param');
assert(unstakingAddress, 'Missing unstakingAddress param');
assert(amount, 'Missing amount param');
Expand All @@ -378,7 +378,7 @@ function stakingDeactivateInstruction(data: StakingDeactivate): TransactionInstr
return tx.instructions;
}

case StakingType.MARINADE: {
case SolStakingTypeEnum.MARINADE: {
assert(recipients, 'Missing recipients param');

const tx = new Transaction();
Expand All @@ -393,7 +393,7 @@ function stakingDeactivateInstruction(data: StakingDeactivate): TransactionInstr
return tx.instructions;
}

case StakingType.NATIVE: {
case SolStakingTypeEnum.NATIVE: {
assert(stakingAddress, 'Missing stakingAddress param');

if (data.params.amount && data.params.unstakingAddress) {
Expand Down
9 changes: 5 additions & 4 deletions modules/sdk-coin-sol/src/lib/stakingActivateBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { SolStakingTypeEnum } from '@bitgo/public-types';
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core';
import { Transaction } from './transaction';
import { TransactionBuilder } from './transactionBuilder';
import { InstructionBuilderTypes } from './constants';

import assert from 'assert';
import { StakingActivate, StakingActivateExtraParams, StakingType } from './iface';
import { StakingActivate, StakingActivateExtraParams } from './iface';
import { isValidStakingAmount, validateAddress } from './utils';

export class StakingActivateBuilder extends TransactionBuilder {
protected _amount: string;
protected _stakingAddress: string;
protected _validator: string;
protected _stakingType: StakingType = StakingType.NATIVE;
protected _stakingType: SolStakingTypeEnum = SolStakingTypeEnum.NATIVE;
protected _extraParams?: StakingActivateExtraParams;

constructor(_coinConfig: Readonly<CoinConfig>) {
Expand Down Expand Up @@ -84,10 +85,10 @@ export class StakingActivateBuilder extends TransactionBuilder {
/**
* Set staking type.
*
* @param {StakingType} stakingType a staking type.
* @param {SolStakingType} stakingType a staking type.
* @returns {StakingActivateBuilder} This staking builder.
*/
stakingType(stakingType: StakingType): this {
stakingType(stakingType: SolStakingTypeEnum): this {
this._stakingType = stakingType;
return this;
}
Expand Down
21 changes: 11 additions & 10 deletions modules/sdk-coin-sol/src/lib/stakingDeactivateBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { SolStakingTypeEnum } from '@bitgo/public-types';
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import assert from 'assert';

import { BuildTransactionError, Recipient, TransactionType } from '@bitgo/sdk-core';
import { InstructionBuilderTypes, STAKE_ACCOUNT_RENT_EXEMPT_AMOUNT } from './constants';
import { StakingDeactivate, StakingDeactivateExtraParams, StakingType, Transfer } from './iface';
import { StakingDeactivate, StakingDeactivateExtraParams, Transfer } from './iface';
import { Transaction } from './transaction';
import { TransactionBuilder } from './transactionBuilder';
import { isValidStakingAmount, validateAddress } from './utils';
Expand All @@ -14,7 +15,7 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
protected _amount?: string;
protected _unstakingAddress: string;
protected _recipients: Recipient[];
protected _stakingType: StakingType = StakingType.NATIVE;
protected _stakingType: SolStakingTypeEnum = SolStakingTypeEnum.NATIVE;
protected _extraParams?: StakingDeactivateExtraParams;

constructor(_coinConfig: Readonly<CoinConfig>) {
Expand All @@ -36,7 +37,7 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
stakingAddresses.push(deactivateInstruction.params.stakingAddress);

// Marinade staking also cares about sender.
if (deactivateInstruction.params.stakingType !== StakingType.MARINADE) {
if (deactivateInstruction.params.stakingType !== SolStakingTypeEnum.MARINADE) {
this.sender(deactivateInstruction.params.fromAddress);
}

Expand All @@ -61,7 +62,7 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
if (stakingAddresses.length > 1) {
this.stakingAddresses(stakingAddresses);
} else {
if (this._stakingType !== StakingType.MARINADE) {
if (this._stakingType !== SolStakingTypeEnum.MARINADE) {
this.stakingAddress(stakingAddresses[0]);
}
}
Expand Down Expand Up @@ -143,10 +144,10 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
/**
* Set staking type.
*
* @param {StakingType} stakingType a staking type.
* @param {SolStakingType} stakingType a staking type.
* @returns {StakingDeactivateBuilder} This staking builder.
*/
stakingType(stakingType: StakingType): this {
stakingType(stakingType: SolStakingTypeEnum): this {
this._stakingType = stakingType;
return this;
}
Expand Down Expand Up @@ -174,13 +175,13 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
params: {
fromAddress: this._sender,
stakingAddress: stakingAddress,
stakingType: StakingType.NATIVE,
stakingType: SolStakingTypeEnum.NATIVE,
},
};
this._instructionsData.push(stakingDeactivateData);
}
} else {
if (this._stakingType === StakingType.NATIVE) {
if (this._stakingType === SolStakingTypeEnum.NATIVE) {
// we don't need stakingAddress in marinade staking deactivate txn
assert(this._stakingAddress, 'Staking address must be set before building the transaction');
}
Expand All @@ -189,15 +190,15 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
throw new BuildTransactionError('Sender address cannot be the same as the Staking address');
}

if (this._stakingType === StakingType.NATIVE && this._amount) {
if (this._stakingType === SolStakingTypeEnum.NATIVE && this._amount) {
assert(
this._unstakingAddress,
'When partially unstaking the unstaking address must be set before building the transaction'
);
}

this._instructionsData = [];
if (this._stakingType === StakingType.NATIVE && this._unstakingAddress) {
if (this._stakingType === SolStakingTypeEnum.NATIVE && this._unstakingAddress) {
assert(
this._amount,
'If an unstaking address is given then a partial amount to unstake must also be set before building the transaction'
Expand Down
Loading
Loading