@drift-labs/vaults-sdk 0.4.41 → 0.4.43
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.
- package/lib/types/drift_vaults.d.ts +31 -0
- package/lib/types/drift_vaults.js +31 -0
- package/lib/vaultClient.d.ts +15 -0
- package/lib/vaultClient.js +44 -0
- package/package.json +1 -1
- package/src/idl/drift_vaults.json +31 -0
- package/src/types/drift_vaults.ts +62 -0
- package/src/vaultClient.ts +73 -0
|
@@ -225,6 +225,37 @@ export type DriftVaults = {
|
|
|
225
225
|
}
|
|
226
226
|
];
|
|
227
227
|
},
|
|
228
|
+
{
|
|
229
|
+
name: 'updateUserPoolId';
|
|
230
|
+
accounts: [
|
|
231
|
+
{
|
|
232
|
+
name: 'vault';
|
|
233
|
+
isMut: true;
|
|
234
|
+
isSigner: false;
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'manager';
|
|
238
|
+
isMut: false;
|
|
239
|
+
isSigner: true;
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: 'driftUser';
|
|
243
|
+
isMut: true;
|
|
244
|
+
isSigner: false;
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'driftProgram';
|
|
248
|
+
isMut: false;
|
|
249
|
+
isSigner: false;
|
|
250
|
+
}
|
|
251
|
+
];
|
|
252
|
+
args: [
|
|
253
|
+
{
|
|
254
|
+
name: 'poolId';
|
|
255
|
+
type: 'u8';
|
|
256
|
+
}
|
|
257
|
+
];
|
|
258
|
+
},
|
|
228
259
|
{
|
|
229
260
|
name: 'updateVaultProtocol';
|
|
230
261
|
accounts: [
|
|
@@ -228,6 +228,37 @@ exports.IDL = {
|
|
|
228
228
|
},
|
|
229
229
|
],
|
|
230
230
|
},
|
|
231
|
+
{
|
|
232
|
+
name: 'updateUserPoolId',
|
|
233
|
+
accounts: [
|
|
234
|
+
{
|
|
235
|
+
name: 'vault',
|
|
236
|
+
isMut: true,
|
|
237
|
+
isSigner: false,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: 'manager',
|
|
241
|
+
isMut: false,
|
|
242
|
+
isSigner: true,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: 'driftUser',
|
|
246
|
+
isMut: true,
|
|
247
|
+
isSigner: false,
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: 'driftProgram',
|
|
251
|
+
isMut: false,
|
|
252
|
+
isSigner: false,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
args: [
|
|
256
|
+
{
|
|
257
|
+
name: 'poolId',
|
|
258
|
+
type: 'u8',
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
},
|
|
231
262
|
{
|
|
232
263
|
name: 'updateVaultProtocol',
|
|
233
264
|
accounts: [
|
package/lib/vaultClient.d.ts
CHANGED
|
@@ -130,6 +130,21 @@ export declare class VaultClient {
|
|
|
130
130
|
* @returns
|
|
131
131
|
*/
|
|
132
132
|
updateMarginTradingEnabled(vault: PublicKey, enabled: boolean, uiTxParams?: TxParams): Promise<TransactionSignature>;
|
|
133
|
+
/**
|
|
134
|
+
* Updates the vault's pool id (for isolated pools).
|
|
135
|
+
* @param vault vault address to update
|
|
136
|
+
* @param poolId pool id to update to
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
updateUserPoolId(vault: PublicKey, poolId: number, uiTxParams?: TxParams): Promise<TransactionSignature>;
|
|
140
|
+
/**
|
|
141
|
+
* Gets the instruction to update the pool id for a vault.
|
|
142
|
+
* @param vault vault address to update
|
|
143
|
+
* @param vaultAccount vault account data (optional, will be fetched if not provided)
|
|
144
|
+
* @param poolId pool id to update to
|
|
145
|
+
* @returns instruction to update pool id
|
|
146
|
+
*/
|
|
147
|
+
getUpdatePoolIdIx(vault: PublicKey, poolId: number, vaultAccount?: any): Promise<TransactionInstruction>;
|
|
133
148
|
private handleWSolMovement;
|
|
134
149
|
/**
|
|
135
150
|
*
|
package/lib/vaultClient.js
CHANGED
|
@@ -446,6 +446,50 @@ class VaultClient {
|
|
|
446
446
|
.instruction();
|
|
447
447
|
return await this.createAndSendTxn([updateMarginTradingEnabledIx], uiTxParams);
|
|
448
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Updates the vault's pool id (for isolated pools).
|
|
451
|
+
* @param vault vault address to update
|
|
452
|
+
* @param poolId pool id to update to
|
|
453
|
+
* @returns
|
|
454
|
+
*/
|
|
455
|
+
async updateUserPoolId(vault, poolId, uiTxParams) {
|
|
456
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
457
|
+
const updatePoolIdIx = await this.getUpdatePoolIdIx(vault, poolId, vaultAccount);
|
|
458
|
+
return await this.createAndSendTxn([updatePoolIdIx], uiTxParams);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Gets the instruction to update the pool id for a vault.
|
|
462
|
+
* @param vault vault address to update
|
|
463
|
+
* @param vaultAccount vault account data (optional, will be fetched if not provided)
|
|
464
|
+
* @param poolId pool id to update to
|
|
465
|
+
* @returns instruction to update pool id
|
|
466
|
+
*/
|
|
467
|
+
async getUpdatePoolIdIx(vault, poolId, vaultAccount) {
|
|
468
|
+
if (!vaultAccount) {
|
|
469
|
+
vaultAccount = await this.program.account.vault.fetch(vault);
|
|
470
|
+
}
|
|
471
|
+
const accounts = {
|
|
472
|
+
vault: vault,
|
|
473
|
+
driftUser: vaultAccount.user,
|
|
474
|
+
driftProgram: this.driftClient.program.programId,
|
|
475
|
+
};
|
|
476
|
+
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
477
|
+
const remainingAccounts = [];
|
|
478
|
+
try {
|
|
479
|
+
const userStatsKey = (0, sdk_1.getUserStatsAccountPublicKey)(this.driftClient.program.programId, vault);
|
|
480
|
+
const userStats = (await this.driftClient.program.account.userStats.fetch(userStatsKey));
|
|
481
|
+
remainingAccounts.push(...this.getRemainingAccountsForUser([user.getUserAccount()], [], vaultAccount, userStats));
|
|
482
|
+
}
|
|
483
|
+
catch (err) {
|
|
484
|
+
console.error('failed to get remaining accounts', err);
|
|
485
|
+
// do nothing
|
|
486
|
+
}
|
|
487
|
+
return await this.program.methods
|
|
488
|
+
.updateUserPoolId(poolId)
|
|
489
|
+
.accounts({ ...accounts, manager: this.driftClient.wallet.publicKey })
|
|
490
|
+
.remainingAccounts(remainingAccounts)
|
|
491
|
+
.instruction();
|
|
492
|
+
}
|
|
449
493
|
async handleWSolMovement(amount, driftSpotMarket, userTokenAccount) {
|
|
450
494
|
const isSolDeposit = driftSpotMarket.mint.equals(sdk_1.WRAPPED_SOL_MINT);
|
|
451
495
|
const preIxs = [];
|
package/package.json
CHANGED
|
@@ -225,6 +225,37 @@
|
|
|
225
225
|
}
|
|
226
226
|
]
|
|
227
227
|
},
|
|
228
|
+
{
|
|
229
|
+
"name": "updateUserPoolId",
|
|
230
|
+
"accounts": [
|
|
231
|
+
{
|
|
232
|
+
"name": "vault",
|
|
233
|
+
"isMut": true,
|
|
234
|
+
"isSigner": false
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"name": "manager",
|
|
238
|
+
"isMut": false,
|
|
239
|
+
"isSigner": true
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
"name": "driftUser",
|
|
243
|
+
"isMut": true,
|
|
244
|
+
"isSigner": false
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"name": "driftProgram",
|
|
248
|
+
"isMut": false,
|
|
249
|
+
"isSigner": false
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
"args": [
|
|
253
|
+
{
|
|
254
|
+
"name": "poolId",
|
|
255
|
+
"type": "u8"
|
|
256
|
+
}
|
|
257
|
+
]
|
|
258
|
+
},
|
|
228
259
|
{
|
|
229
260
|
"name": "updateVaultProtocol",
|
|
230
261
|
"accounts": [
|
|
@@ -225,6 +225,37 @@ export type DriftVaults = {
|
|
|
225
225
|
}
|
|
226
226
|
];
|
|
227
227
|
},
|
|
228
|
+
{
|
|
229
|
+
name: 'updateUserPoolId';
|
|
230
|
+
accounts: [
|
|
231
|
+
{
|
|
232
|
+
name: 'vault';
|
|
233
|
+
isMut: true;
|
|
234
|
+
isSigner: false;
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: 'manager';
|
|
238
|
+
isMut: false;
|
|
239
|
+
isSigner: true;
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: 'driftUser';
|
|
243
|
+
isMut: true;
|
|
244
|
+
isSigner: false;
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'driftProgram';
|
|
248
|
+
isMut: false;
|
|
249
|
+
isSigner: false;
|
|
250
|
+
}
|
|
251
|
+
];
|
|
252
|
+
args: [
|
|
253
|
+
{
|
|
254
|
+
name: 'poolId';
|
|
255
|
+
type: 'u8';
|
|
256
|
+
}
|
|
257
|
+
];
|
|
258
|
+
},
|
|
228
259
|
{
|
|
229
260
|
name: 'updateVaultProtocol';
|
|
230
261
|
accounts: [
|
|
@@ -3150,6 +3181,37 @@ export const IDL: DriftVaults = {
|
|
|
3150
3181
|
},
|
|
3151
3182
|
],
|
|
3152
3183
|
},
|
|
3184
|
+
{
|
|
3185
|
+
name: 'updateUserPoolId',
|
|
3186
|
+
accounts: [
|
|
3187
|
+
{
|
|
3188
|
+
name: 'vault',
|
|
3189
|
+
isMut: true,
|
|
3190
|
+
isSigner: false,
|
|
3191
|
+
},
|
|
3192
|
+
{
|
|
3193
|
+
name: 'manager',
|
|
3194
|
+
isMut: false,
|
|
3195
|
+
isSigner: true,
|
|
3196
|
+
},
|
|
3197
|
+
{
|
|
3198
|
+
name: 'driftUser',
|
|
3199
|
+
isMut: true,
|
|
3200
|
+
isSigner: false,
|
|
3201
|
+
},
|
|
3202
|
+
{
|
|
3203
|
+
name: 'driftProgram',
|
|
3204
|
+
isMut: false,
|
|
3205
|
+
isSigner: false,
|
|
3206
|
+
},
|
|
3207
|
+
],
|
|
3208
|
+
args: [
|
|
3209
|
+
{
|
|
3210
|
+
name: 'poolId',
|
|
3211
|
+
type: 'u8',
|
|
3212
|
+
},
|
|
3213
|
+
],
|
|
3214
|
+
},
|
|
3153
3215
|
{
|
|
3154
3216
|
name: 'updateVaultProtocol',
|
|
3155
3217
|
accounts: [
|
package/src/vaultClient.ts
CHANGED
|
@@ -712,6 +712,79 @@ export class VaultClient {
|
|
|
712
712
|
);
|
|
713
713
|
}
|
|
714
714
|
|
|
715
|
+
/**
|
|
716
|
+
* Updates the vault's pool id (for isolated pools).
|
|
717
|
+
* @param vault vault address to update
|
|
718
|
+
* @param poolId pool id to update to
|
|
719
|
+
* @returns
|
|
720
|
+
*/
|
|
721
|
+
public async updateUserPoolId(
|
|
722
|
+
vault: PublicKey,
|
|
723
|
+
poolId: number,
|
|
724
|
+
uiTxParams?: TxParams
|
|
725
|
+
): Promise<TransactionSignature> {
|
|
726
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
727
|
+
const updatePoolIdIx = await this.getUpdatePoolIdIx(
|
|
728
|
+
vault,
|
|
729
|
+
poolId,
|
|
730
|
+
vaultAccount
|
|
731
|
+
);
|
|
732
|
+
return await this.createAndSendTxn([updatePoolIdIx], uiTxParams);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Gets the instruction to update the pool id for a vault.
|
|
737
|
+
* @param vault vault address to update
|
|
738
|
+
* @param vaultAccount vault account data (optional, will be fetched if not provided)
|
|
739
|
+
* @param poolId pool id to update to
|
|
740
|
+
* @returns instruction to update pool id
|
|
741
|
+
*/
|
|
742
|
+
public async getUpdatePoolIdIx(
|
|
743
|
+
vault: PublicKey,
|
|
744
|
+
poolId: number,
|
|
745
|
+
vaultAccount?: any
|
|
746
|
+
): Promise<TransactionInstruction> {
|
|
747
|
+
if (!vaultAccount) {
|
|
748
|
+
vaultAccount = await this.program.account.vault.fetch(vault);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const accounts = {
|
|
752
|
+
vault: vault,
|
|
753
|
+
driftUser: vaultAccount.user,
|
|
754
|
+
driftProgram: this.driftClient.program.programId,
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
758
|
+
|
|
759
|
+
const remainingAccounts: AccountMeta[] = [];
|
|
760
|
+
try {
|
|
761
|
+
const userStatsKey = getUserStatsAccountPublicKey(
|
|
762
|
+
this.driftClient.program.programId,
|
|
763
|
+
vault
|
|
764
|
+
);
|
|
765
|
+
const userStats = (await this.driftClient.program.account.userStats.fetch(
|
|
766
|
+
userStatsKey
|
|
767
|
+
)) as UserStatsAccount;
|
|
768
|
+
remainingAccounts.push(
|
|
769
|
+
...this.getRemainingAccountsForUser(
|
|
770
|
+
[user.getUserAccount()],
|
|
771
|
+
[],
|
|
772
|
+
vaultAccount,
|
|
773
|
+
userStats
|
|
774
|
+
)
|
|
775
|
+
);
|
|
776
|
+
} catch (err) {
|
|
777
|
+
console.error('failed to get remaining accounts', err);
|
|
778
|
+
// do nothing
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return await this.program.methods
|
|
782
|
+
.updateUserPoolId(poolId)
|
|
783
|
+
.accounts({ ...accounts, manager: this.driftClient.wallet.publicKey })
|
|
784
|
+
.remainingAccounts(remainingAccounts)
|
|
785
|
+
.instruction();
|
|
786
|
+
}
|
|
787
|
+
|
|
715
788
|
private async handleWSolMovement(
|
|
716
789
|
amount: BN,
|
|
717
790
|
driftSpotMarket: SpotMarketAccount,
|