@drift-labs/vaults-sdk 0.1.532 → 0.1.534

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1262,15 +1262,129 @@ class VaultClient {
1262
1262
  if (!spotMarket) {
1263
1263
  throw new Error(`Spot market ${spotMarketIndex} not found on driftClient`);
1264
1264
  }
1265
+ const ifVaultTokenAccount = (0, addresses_1.getInsuranceFundTokenVaultAddressSync)(this.program.programId, vault, spotMarketIndex);
1265
1266
  return await this.program.methods
1266
1267
  .initializeInsuranceFundStake(spotMarketIndex)
1267
1268
  .accounts({
1268
1269
  vault: vault,
1269
1270
  driftSpotMarket: spotMarket.pubkey,
1271
+ driftSpotMarketMint: spotMarket.mint,
1272
+ vaultTokenAccount: ifVaultTokenAccount,
1273
+ insuranceFundStake: ifStakeAccountPublicKey,
1274
+ driftUserStats: vaultAccount.userStats,
1275
+ driftState: await this.driftClient.getStatePublicKey(),
1276
+ driftProgram: this.driftClient.program.programId,
1277
+ })
1278
+ .rpc();
1279
+ }
1280
+ /**
1281
+ * Adds an amount to an insurance fund stake for the vault.
1282
+ * @param vault vault address to update
1283
+ * @param spotMarketIndex spot market index of the insurance fund stake
1284
+ * @param amount amount to add to the insurance fund stake, in spotMarketIndex precision
1285
+ * @returns
1286
+ */
1287
+ async addToInsuranceFundStake(vault, spotMarketIndex, amount, managerTokenAccount) {
1288
+ const vaultAccount = await this.program.account.vault.fetch(vault);
1289
+ if (!vaultAccount.manager.equals(this.driftClient.wallet.publicKey)) {
1290
+ throw new Error(`Only the manager of the vault can add to the insurance fund stake.`);
1291
+ }
1292
+ const ifStakeAccountPublicKey = (0, sdk_1.getInsuranceFundStakeAccountPublicKey)(this.driftClient.program.programId, vault, spotMarketIndex);
1293
+ const ifVaultPublicKey = await (0, sdk_1.getInsuranceFundVaultPublicKey)(this.driftClient.program.programId, spotMarketIndex);
1294
+ const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
1295
+ if (!spotMarket) {
1296
+ throw new Error(`Spot market ${spotMarketIndex} not found on driftClient`);
1297
+ }
1298
+ if (!managerTokenAccount) {
1299
+ managerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spotMarket.mint, this.driftClient.wallet.publicKey);
1300
+ }
1301
+ const ifVaultTokenAccount = (0, addresses_1.getInsuranceFundTokenVaultAddressSync)(this.program.programId, vault, spotMarketIndex);
1302
+ return await this.program.methods
1303
+ .addInsuranceFundStake(spotMarketIndex, amount)
1304
+ .accounts({
1305
+ vault: vault,
1306
+ driftSpotMarket: spotMarket.pubkey,
1307
+ driftSpotMarketVault: spotMarket.vault,
1308
+ insuranceFundStake: ifStakeAccountPublicKey,
1309
+ insuranceFundVault: ifVaultPublicKey,
1310
+ managerTokenAccount,
1311
+ vaultIfTokenAccount: ifVaultTokenAccount,
1312
+ driftUserStats: vaultAccount.userStats,
1313
+ driftState: await this.driftClient.getStatePublicKey(),
1314
+ driftProgram: this.driftClient.program.programId,
1315
+ driftSigner: this.driftClient.getStateAccount().signer,
1316
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1317
+ })
1318
+ .rpc();
1319
+ }
1320
+ async requestRemoveInsuranceFundStake(vault, spotMarketIndex, amount) {
1321
+ const vaultAccount = await this.program.account.vault.fetch(vault);
1322
+ const ifStakeAccountPublicKey = (0, sdk_1.getInsuranceFundStakeAccountPublicKey)(this.driftClient.program.programId, vault, spotMarketIndex);
1323
+ const ifVaultPublicKey = await (0, sdk_1.getInsuranceFundVaultPublicKey)(this.driftClient.program.programId, spotMarketIndex);
1324
+ const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
1325
+ if (!spotMarket) {
1326
+ throw new Error(`Spot market ${spotMarketIndex} not found on driftClient`);
1327
+ }
1328
+ return await this.program.methods
1329
+ .requestRemoveInsuranceFundStake(spotMarketIndex, amount)
1330
+ .accounts({
1331
+ vault,
1332
+ manager: this.driftClient.wallet.publicKey,
1333
+ driftSpotMarket: spotMarket.pubkey,
1270
1334
  insuranceFundStake: ifStakeAccountPublicKey,
1335
+ insuranceFundVault: ifVaultPublicKey,
1271
1336
  driftUserStats: vaultAccount.userStats,
1337
+ driftProgram: this.driftClient.program.programId,
1338
+ })
1339
+ .rpc();
1340
+ }
1341
+ async cancelRequestRemoveInsuranceFundStake(vault, spotMarketIndex) {
1342
+ const vaultAccount = await this.program.account.vault.fetch(vault);
1343
+ const ifStakeAccountPublicKey = (0, sdk_1.getInsuranceFundStakeAccountPublicKey)(this.driftClient.program.programId, vault, spotMarketIndex);
1344
+ const ifVaultPublicKey = await (0, sdk_1.getInsuranceFundVaultPublicKey)(this.driftClient.program.programId, spotMarketIndex);
1345
+ const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
1346
+ if (!spotMarket) {
1347
+ throw new Error(`Spot market ${spotMarketIndex} not found on driftClient`);
1348
+ }
1349
+ return await this.program.methods
1350
+ .cancelRequestRemoveInsuranceFundStake(spotMarketIndex)
1351
+ .accounts({
1352
+ vault: vault,
1353
+ manager: this.driftClient.wallet.publicKey,
1354
+ driftSpotMarket: spotMarket.pubkey,
1355
+ insuranceFundStake: ifStakeAccountPublicKey,
1356
+ insuranceFundVault: ifVaultPublicKey,
1357
+ driftUserStats: vaultAccount.userStats,
1358
+ driftProgram: this.driftClient.program.programId,
1359
+ })
1360
+ .rpc();
1361
+ }
1362
+ async removeInsuranceFundStake(vault, spotMarketIndex, managerTokenAccount) {
1363
+ const vaultAccount = await this.program.account.vault.fetch(vault);
1364
+ const ifStakeAccountPublicKey = (0, sdk_1.getInsuranceFundStakeAccountPublicKey)(this.driftClient.program.programId, vault, spotMarketIndex);
1365
+ const ifVaultPublicKey = await (0, sdk_1.getInsuranceFundVaultPublicKey)(this.driftClient.program.programId, spotMarketIndex);
1366
+ const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
1367
+ if (!spotMarket) {
1368
+ throw new Error(`Spot market ${spotMarketIndex} not found on driftClient`);
1369
+ }
1370
+ if (!managerTokenAccount) {
1371
+ managerTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(spotMarket.mint, this.driftClient.wallet.publicKey);
1372
+ }
1373
+ const ifVaultTokenAccount = (0, addresses_1.getInsuranceFundTokenVaultAddressSync)(this.program.programId, vault, spotMarketIndex);
1374
+ return await this.program.methods
1375
+ .removeInsuranceFundStake(spotMarketIndex)
1376
+ .accounts({
1377
+ vault: vault,
1378
+ driftSpotMarket: spotMarket.pubkey,
1379
+ insuranceFundStake: ifStakeAccountPublicKey,
1380
+ insuranceFundVault: ifVaultPublicKey,
1381
+ managerTokenAccount,
1382
+ vaultIfTokenAccount: ifVaultTokenAccount,
1272
1383
  driftState: await this.driftClient.getStatePublicKey(),
1384
+ driftUserStats: vaultAccount.userStats,
1385
+ driftSigner: this.driftClient.getStateAccount().signer,
1273
1386
  driftProgram: this.driftClient.program.programId,
1387
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
1274
1388
  })
1275
1389
  .rpc();
1276
1390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/vaults-sdk",
3
- "version": "0.1.532",
3
+ "version": "0.1.534",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "directories": {
package/src/addresses.ts CHANGED
@@ -42,6 +42,21 @@ export function getTokenVaultAddressSync(
42
42
  )[0];
43
43
  }
44
44
 
45
+ export function getInsuranceFundTokenVaultAddressSync(
46
+ programId: PublicKey,
47
+ vault: PublicKey,
48
+ marketIndex: number
49
+ ): PublicKey {
50
+ return PublicKey.findProgramAddressSync(
51
+ [
52
+ Buffer.from(anchor.utils.bytes.utf8.encode('vault_token_account')),
53
+ vault.toBuffer(),
54
+ new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
55
+ ],
56
+ programId
57
+ )[0];
58
+ }
59
+
45
60
  export function getVaultProtocolAddressSync(
46
61
  programId: PublicKey,
47
62
  vault: PublicKey
@@ -1137,21 +1137,227 @@
1137
1137
  "isMut": false,
1138
1138
  "isSigner": false
1139
1139
  },
1140
+ {
1141
+ "name": "driftSpotMarket",
1142
+ "isMut": true,
1143
+ "isSigner": false
1144
+ },
1145
+ {
1146
+ "name": "driftSpotMarketMint",
1147
+ "isMut": false,
1148
+ "isSigner": false
1149
+ },
1150
+ {
1151
+ "name": "vaultTokenAccount",
1152
+ "isMut": true,
1153
+ "isSigner": false
1154
+ },
1155
+ {
1156
+ "name": "insuranceFundStake",
1157
+ "isMut": true,
1158
+ "isSigner": false
1159
+ },
1160
+ {
1161
+ "name": "driftUserStats",
1162
+ "isMut": true,
1163
+ "isSigner": false
1164
+ },
1165
+ {
1166
+ "name": "driftState",
1167
+ "isMut": false,
1168
+ "isSigner": false
1169
+ },
1170
+ {
1171
+ "name": "driftProgram",
1172
+ "isMut": false,
1173
+ "isSigner": false
1174
+ },
1175
+ {
1176
+ "name": "tokenProgram",
1177
+ "isMut": false,
1178
+ "isSigner": false
1179
+ },
1140
1180
  {
1141
1181
  "name": "systemProgram",
1142
1182
  "isMut": false,
1143
1183
  "isSigner": false
1184
+ }
1185
+ ],
1186
+ "args": [
1187
+ {
1188
+ "name": "marketIndex",
1189
+ "type": "u16"
1190
+ }
1191
+ ]
1192
+ },
1193
+ {
1194
+ "name": "addInsuranceFundStake",
1195
+ "accounts": [
1196
+ {
1197
+ "name": "vault",
1198
+ "isMut": true,
1199
+ "isSigner": false
1200
+ },
1201
+ {
1202
+ "name": "manager",
1203
+ "isMut": true,
1204
+ "isSigner": true
1205
+ },
1206
+ {
1207
+ "name": "driftSpotMarket",
1208
+ "isMut": true,
1209
+ "isSigner": false
1210
+ },
1211
+ {
1212
+ "name": "driftSpotMarketVault",
1213
+ "isMut": true,
1214
+ "isSigner": false
1215
+ },
1216
+ {
1217
+ "name": "insuranceFundStake",
1218
+ "isMut": true,
1219
+ "isSigner": false
1220
+ },
1221
+ {
1222
+ "name": "insuranceFundVault",
1223
+ "isMut": true,
1224
+ "isSigner": false
1225
+ },
1226
+ {
1227
+ "name": "managerTokenAccount",
1228
+ "isMut": true,
1229
+ "isSigner": false
1230
+ },
1231
+ {
1232
+ "name": "vaultIfTokenAccount",
1233
+ "isMut": true,
1234
+ "isSigner": false
1235
+ },
1236
+ {
1237
+ "name": "driftUserStats",
1238
+ "isMut": true,
1239
+ "isSigner": false
1240
+ },
1241
+ {
1242
+ "name": "driftState",
1243
+ "isMut": false,
1244
+ "isSigner": false
1245
+ },
1246
+ {
1247
+ "name": "driftSigner",
1248
+ "isMut": false,
1249
+ "isSigner": false
1250
+ },
1251
+ {
1252
+ "name": "driftProgram",
1253
+ "isMut": false,
1254
+ "isSigner": false
1255
+ },
1256
+ {
1257
+ "name": "tokenProgram",
1258
+ "isMut": false,
1259
+ "isSigner": false
1260
+ }
1261
+ ],
1262
+ "args": [
1263
+ {
1264
+ "name": "marketIndex",
1265
+ "type": "u16"
1266
+ },
1267
+ {
1268
+ "name": "amount",
1269
+ "type": "u64"
1270
+ }
1271
+ ]
1272
+ },
1273
+ {
1274
+ "name": "requestRemoveInsuranceFundStake",
1275
+ "accounts": [
1276
+ {
1277
+ "name": "vault",
1278
+ "isMut": true,
1279
+ "isSigner": false
1280
+ },
1281
+ {
1282
+ "name": "manager",
1283
+ "isMut": false,
1284
+ "isSigner": true
1144
1285
  },
1145
1286
  {
1146
1287
  "name": "driftSpotMarket",
1288
+ "isMut": true,
1289
+ "isSigner": false
1290
+ },
1291
+ {
1292
+ "name": "insuranceFundStake",
1293
+ "isMut": true,
1294
+ "isSigner": false
1295
+ },
1296
+ {
1297
+ "name": "insuranceFundVault",
1298
+ "isMut": true,
1299
+ "isSigner": false
1300
+ },
1301
+ {
1302
+ "name": "driftUserStats",
1303
+ "isMut": true,
1304
+ "isSigner": false
1305
+ },
1306
+ {
1307
+ "name": "driftProgram",
1147
1308
  "isMut": false,
1148
1309
  "isSigner": false
1310
+ }
1311
+ ],
1312
+ "args": [
1313
+ {
1314
+ "name": "marketIndex",
1315
+ "type": "u16"
1316
+ },
1317
+ {
1318
+ "name": "amount",
1319
+ "type": "u64"
1320
+ }
1321
+ ]
1322
+ },
1323
+ {
1324
+ "name": "removeInsuranceFundStake",
1325
+ "accounts": [
1326
+ {
1327
+ "name": "vault",
1328
+ "isMut": true,
1329
+ "isSigner": false
1330
+ },
1331
+ {
1332
+ "name": "manager",
1333
+ "isMut": false,
1334
+ "isSigner": true
1335
+ },
1336
+ {
1337
+ "name": "driftSpotMarket",
1338
+ "isMut": true,
1339
+ "isSigner": false
1149
1340
  },
1150
1341
  {
1151
1342
  "name": "insuranceFundStake",
1152
1343
  "isMut": true,
1153
1344
  "isSigner": false
1154
1345
  },
1346
+ {
1347
+ "name": "insuranceFundVault",
1348
+ "isMut": true,
1349
+ "isSigner": false
1350
+ },
1351
+ {
1352
+ "name": "managerTokenAccount",
1353
+ "isMut": true,
1354
+ "isSigner": false
1355
+ },
1356
+ {
1357
+ "name": "vaultIfTokenAccount",
1358
+ "isMut": true,
1359
+ "isSigner": false
1360
+ },
1155
1361
  {
1156
1362
  "name": "driftUserStats",
1157
1363
  "isMut": true,
@@ -1162,6 +1368,62 @@
1162
1368
  "isMut": false,
1163
1369
  "isSigner": false
1164
1370
  },
1371
+ {
1372
+ "name": "driftSigner",
1373
+ "isMut": false,
1374
+ "isSigner": false
1375
+ },
1376
+ {
1377
+ "name": "driftProgram",
1378
+ "isMut": false,
1379
+ "isSigner": false
1380
+ },
1381
+ {
1382
+ "name": "tokenProgram",
1383
+ "isMut": false,
1384
+ "isSigner": false
1385
+ }
1386
+ ],
1387
+ "args": [
1388
+ {
1389
+ "name": "marketIndex",
1390
+ "type": "u16"
1391
+ }
1392
+ ]
1393
+ },
1394
+ {
1395
+ "name": "cancelRequestRemoveInsuranceFundStake",
1396
+ "accounts": [
1397
+ {
1398
+ "name": "vault",
1399
+ "isMut": true,
1400
+ "isSigner": false
1401
+ },
1402
+ {
1403
+ "name": "manager",
1404
+ "isMut": false,
1405
+ "isSigner": true
1406
+ },
1407
+ {
1408
+ "name": "driftSpotMarket",
1409
+ "isMut": true,
1410
+ "isSigner": false
1411
+ },
1412
+ {
1413
+ "name": "insuranceFundStake",
1414
+ "isMut": true,
1415
+ "isSigner": false
1416
+ },
1417
+ {
1418
+ "name": "insuranceFundVault",
1419
+ "isMut": true,
1420
+ "isSigner": false
1421
+ },
1422
+ {
1423
+ "name": "driftUserStats",
1424
+ "isMut": true,
1425
+ "isSigner": false
1426
+ },
1165
1427
  {
1166
1428
  "name": "driftProgram",
1167
1429
  "isMut": false,