Skip to content

Commit 04602c5

Browse files
committed
add test
1 parent 4352f1a commit 04602c5

File tree

4 files changed

+187
-4
lines changed

4 files changed

+187
-4
lines changed

programs/drift/src/instructions/if_staker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@ pub fn handle_transfer_protocol_if_shares_to_revenue_pool<'c: 'info, 'info>(
821821
Ok(())
822822
}
823823

824-
825824
pub fn handle_deposit_into_insurance_fund_stake<'c: 'info, 'info>(
826825
ctx: Context<'_, '_, 'c, 'info, DepositIntoInsuranceFundStake<'info>>,
827826
market_index: u16,
@@ -1221,6 +1220,7 @@ pub struct DepositIntoInsuranceFundStake<'info> {
12211220
)]
12221221
pub spot_market_vault: Box<InterfaceAccount<'info, TokenAccount>>,
12231222
#[account(
1223+
mut,
12241224
seeds = [b"insurance_fund_vault".as_ref(), market_index.to_le_bytes().as_ref()],
12251225
bump,
12261226
)]
@@ -1232,6 +1232,6 @@ pub struct DepositIntoInsuranceFundStake<'info> {
12321232
)]
12331233
pub user_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
12341234
pub token_program: Interface<'info, TokenInterface>,
1235-
/// CHECK: forced drift_signer
1236-
pub drift_signer: AccountInfo<'info>,
1235+
/// CHECK: forced drift_signer
1236+
pub drift_signer: AccountInfo<'info>,
12371237
}

sdk/src/driftClient.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9277,6 +9277,56 @@ export class DriftClient {
92779277
return ix;
92789278
}
92799279

9280+
public async depositIntoInsuranceFundStake(
9281+
marketIndex: number,
9282+
amount: BN,
9283+
userStatsPublicKey: PublicKey,
9284+
insuranceFundStakePublicKey: PublicKey,
9285+
userTokenAccountPublicKey: PublicKey,
9286+
txParams?: TxParams
9287+
): Promise<TransactionSignature> {
9288+
const tx = await this.buildTransaction(
9289+
await this.getDepositIntoInsuranceFundStakeIx(
9290+
marketIndex,
9291+
amount,
9292+
userStatsPublicKey,
9293+
insuranceFundStakePublicKey,
9294+
userTokenAccountPublicKey
9295+
),
9296+
txParams
9297+
);
9298+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
9299+
return txSig;
9300+
}
9301+
9302+
public async getDepositIntoInsuranceFundStakeIx(
9303+
marketIndex: number,
9304+
amount: BN,
9305+
userStatsPublicKey: PublicKey,
9306+
insuranceFundStakePublicKey: PublicKey,
9307+
userTokenAccountPublicKey: PublicKey
9308+
): Promise<TransactionInstruction> {
9309+
const spotMarket = this.getSpotMarketAccount(marketIndex);
9310+
return await this.program.instruction.depositIntoInsuranceFundStake(
9311+
marketIndex,
9312+
amount,
9313+
{
9314+
accounts: {
9315+
signer: this.wallet.publicKey,
9316+
state: await this.getStatePublicKey(),
9317+
spotMarket: spotMarket.pubkey,
9318+
insuranceFundStake: insuranceFundStakePublicKey,
9319+
userStats: userStatsPublicKey,
9320+
spotMarketVault: spotMarket.vault,
9321+
insuranceFundVault: spotMarket.insuranceFund.vault,
9322+
userTokenAccount: userTokenAccountPublicKey,
9323+
tokenProgram: this.getTokenProgramForSpotMarket(spotMarket),
9324+
driftSigner: this.getSignerPublicKey(),
9325+
},
9326+
}
9327+
);
9328+
}
9329+
92809330
public async settleRevenueToInsuranceFund(
92819331
spotMarketIndex: number,
92829332
txParams?: TxParams

sdk/src/idl/drift.json

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,6 +3141,42 @@
31413141
],
31423142
"args": []
31433143
},
3144+
{
3145+
"name": "updateDelegateUserGovTokenInsuranceStake",
3146+
"accounts": [
3147+
{
3148+
"name": "spotMarket",
3149+
"isMut": true,
3150+
"isSigner": false
3151+
},
3152+
{
3153+
"name": "insuranceFundStake",
3154+
"isMut": false,
3155+
"isSigner": false
3156+
},
3157+
{
3158+
"name": "userStats",
3159+
"isMut": true,
3160+
"isSigner": false
3161+
},
3162+
{
3163+
"name": "admin",
3164+
"isMut": false,
3165+
"isSigner": true
3166+
},
3167+
{
3168+
"name": "insuranceFundVault",
3169+
"isMut": true,
3170+
"isSigner": false
3171+
},
3172+
{
3173+
"name": "state",
3174+
"isMut": false,
3175+
"isSigner": false
3176+
}
3177+
],
3178+
"args": []
3179+
},
31443180
{
31453181
"name": "initializeInsuranceFundStake",
31463182
"accounts": [
@@ -3634,6 +3670,71 @@
36343670
}
36353671
]
36363672
},
3673+
{
3674+
"name": "depositIntoInsuranceFundStake",
3675+
"accounts": [
3676+
{
3677+
"name": "signer",
3678+
"isMut": false,
3679+
"isSigner": true
3680+
},
3681+
{
3682+
"name": "state",
3683+
"isMut": true,
3684+
"isSigner": false
3685+
},
3686+
{
3687+
"name": "spotMarket",
3688+
"isMut": true,
3689+
"isSigner": false
3690+
},
3691+
{
3692+
"name": "insuranceFundStake",
3693+
"isMut": true,
3694+
"isSigner": false
3695+
},
3696+
{
3697+
"name": "userStats",
3698+
"isMut": true,
3699+
"isSigner": false
3700+
},
3701+
{
3702+
"name": "spotMarketVault",
3703+
"isMut": true,
3704+
"isSigner": false
3705+
},
3706+
{
3707+
"name": "insuranceFundVault",
3708+
"isMut": true,
3709+
"isSigner": false
3710+
},
3711+
{
3712+
"name": "userTokenAccount",
3713+
"isMut": true,
3714+
"isSigner": false
3715+
},
3716+
{
3717+
"name": "tokenProgram",
3718+
"isMut": false,
3719+
"isSigner": false
3720+
},
3721+
{
3722+
"name": "driftSigner",
3723+
"isMut": false,
3724+
"isSigner": false
3725+
}
3726+
],
3727+
"args": [
3728+
{
3729+
"name": "marketIndex",
3730+
"type": "u16"
3731+
},
3732+
{
3733+
"name": "amount",
3734+
"type": "u64"
3735+
}
3736+
]
3737+
},
36373738
{
36383739
"name": "updatePythPullOracle",
36393740
"accounts": [
@@ -16218,5 +16319,8 @@
1621816319
"name": "InvalidIfRebalanceSwap",
1621916320
"msg": "Invalid If Rebalance Swap"
1622016321
}
16221-
]
16322+
],
16323+
"metadata": {
16324+
"address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH"
16325+
}
1622216326
}

tests/insuranceFundStake.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
unstakeSharesToAmount,
3030
MarketStatus,
3131
LIQUIDATION_PCT_PRECISION,
32+
getUserStatsAccountPublicKey,
3233
} from '../sdk/src';
3334

3435
import {
@@ -40,6 +41,7 @@ import {
4041
sleep,
4142
mockOracleNoProgram,
4243
setFeedPriceNoProgram,
44+
mintUSDCToUser,
4345
} from './testHelpers';
4446
import { ContractTier, PERCENTAGE_PRECISION, UserStatus } from '../sdk';
4547
import { startAnchor } from 'solana-bankrun';
@@ -1163,6 +1165,33 @@ describe('insurance fund stake', () => {
11631165
// assert(usdcBefore.eq(usdcAfter));
11641166
});
11651167

1168+
it('admin deposit into insurance fund stake', async () => {
1169+
await mintUSDCToUser(
1170+
usdcMint,
1171+
userUSDCAccount.publicKey,
1172+
usdcAmount,
1173+
bankrunContextWrapper
1174+
);
1175+
const marketIndex = 0;
1176+
const insuranceFundStakePublicKey = getInsuranceFundStakeAccountPublicKey(
1177+
driftClient.program.programId,
1178+
driftClient.wallet.publicKey,
1179+
marketIndex
1180+
);
1181+
const userStatsPublicKey = getUserStatsAccountPublicKey(
1182+
driftClient.program.programId,
1183+
driftClient.wallet.publicKey
1184+
);
1185+
const txSig = await driftClient.depositIntoInsuranceFundStake(
1186+
marketIndex,
1187+
usdcAmount,
1188+
userStatsPublicKey,
1189+
insuranceFundStakePublicKey,
1190+
userUSDCAccount.publicKey
1191+
);
1192+
bankrunContextWrapper.printTxLogs(txSig);
1193+
});
1194+
11661195
// it('settle spotMarket to insurance vault', async () => {
11671196
// const marketIndex = new BN(0);
11681197

0 commit comments

Comments
 (0)