@drift-labs/vaults-sdk 0.1.188 → 0.1.190
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/bun.lockb +0 -0
- package/lib/vaultClient.d.ts +8 -3
- package/lib/vaultClient.js +34 -12
- package/package.json +1 -1
- package/src/vaultClient.ts +51 -24
package/bun.lockb
CHANGED
|
Binary file
|
package/lib/vaultClient.d.ts
CHANGED
|
@@ -5,9 +5,14 @@ import { BN, DriftClient, UserMap } from '@drift-labs/sdk';
|
|
|
5
5
|
import { Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
6
6
|
import { DriftVaults } from './types/drift_vaults';
|
|
7
7
|
import { CompetitionsClient } from '@drift-labs/competitions-sdk';
|
|
8
|
-
import { PublicKey,
|
|
8
|
+
import { PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
9
9
|
import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
|
|
10
10
|
import { UserMapConfig } from '@drift-labs/sdk/lib/userMap/userMapConfig';
|
|
11
|
+
export type TxParams = {
|
|
12
|
+
cuLimit?: number;
|
|
13
|
+
cuPriceMicroLamports?: number;
|
|
14
|
+
simulateTransaction?: boolean;
|
|
15
|
+
};
|
|
11
16
|
export declare class VaultClient {
|
|
12
17
|
driftClient: DriftClient;
|
|
13
18
|
program: Program<DriftVaults>;
|
|
@@ -110,7 +115,7 @@ export declare class VaultClient {
|
|
|
110
115
|
vault: PublicKey;
|
|
111
116
|
}): Promise<TransactionSignature>;
|
|
112
117
|
requestWithdraw(vaultDepositor: PublicKey, amount: BN, withdrawUnit: WithdrawUnit): Promise<TransactionSignature>;
|
|
113
|
-
withdraw(vaultDepositor: PublicKey): Promise<TransactionSignature>;
|
|
118
|
+
withdraw(vaultDepositor: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
114
119
|
forceWithdraw(vaultDepositor: PublicKey): Promise<TransactionSignature>;
|
|
115
120
|
cancelRequestWithdraw(vaultDepositor: PublicKey): Promise<TransactionSignature>;
|
|
116
121
|
/**
|
|
@@ -123,7 +128,7 @@ export declare class VaultClient {
|
|
|
123
128
|
/**
|
|
124
129
|
* Used for UI wallet adapters compatibility
|
|
125
130
|
*/
|
|
126
|
-
createAndSendTxn(
|
|
131
|
+
createAndSendTxn(vaultIxs: TransactionInstruction[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
127
132
|
/**
|
|
128
133
|
* Initializes an insurance fund stake for the vault.
|
|
129
134
|
* @param vault vault address to update
|
package/lib/vaultClient.js
CHANGED
|
@@ -316,7 +316,7 @@ class VaultClient {
|
|
|
316
316
|
remainingAccounts,
|
|
317
317
|
});
|
|
318
318
|
return this.createAndSendTxn([ix], {
|
|
319
|
-
|
|
319
|
+
cuLimit: 1000000,
|
|
320
320
|
});
|
|
321
321
|
}
|
|
322
322
|
async managerUpdateVault(vault, params) {
|
|
@@ -496,11 +496,12 @@ class VaultClient {
|
|
|
496
496
|
remainingAccounts,
|
|
497
497
|
});
|
|
498
498
|
return await this.createAndSendTxn([requestWithdrawIx], {
|
|
499
|
-
|
|
499
|
+
cuLimit: 650000,
|
|
500
500
|
});
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
|
-
async withdraw(vaultDepositor) {
|
|
503
|
+
async withdraw(vaultDepositor, txParams) {
|
|
504
|
+
var _a;
|
|
504
505
|
const vaultDepositorAccount = await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
505
506
|
const vaultAccount = await this.program.account.vault.fetch(vaultDepositorAccount.vault);
|
|
506
507
|
const user = await this.getSubscribedVaultUser(vaultAccount.user);
|
|
@@ -543,7 +544,8 @@ class VaultClient {
|
|
|
543
544
|
remainingAccounts,
|
|
544
545
|
});
|
|
545
546
|
return await this.createAndSendTxn([withdrawIx], {
|
|
546
|
-
|
|
547
|
+
cuLimit: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.cuLimit) !== null && _a !== void 0 ? _a : 650000,
|
|
548
|
+
...txParams,
|
|
547
549
|
});
|
|
548
550
|
}
|
|
549
551
|
}
|
|
@@ -678,14 +680,34 @@ class VaultClient {
|
|
|
678
680
|
/**
|
|
679
681
|
* Used for UI wallet adapters compatibility
|
|
680
682
|
*/
|
|
681
|
-
async createAndSendTxn(
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
683
|
+
async createAndSendTxn(vaultIxs, txParams) {
|
|
684
|
+
var _a, _b;
|
|
685
|
+
const ixs = [
|
|
686
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
687
|
+
units: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.cuLimit) !== null && _a !== void 0 ? _a : 400000,
|
|
688
|
+
}),
|
|
689
|
+
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
690
|
+
microLamports: (_b = txParams === null || txParams === void 0 ? void 0 : txParams.cuPriceMicroLamports) !== null && _b !== void 0 ? _b : 1000000,
|
|
691
|
+
}),
|
|
692
|
+
...vaultIxs,
|
|
693
|
+
];
|
|
694
|
+
const tx = await this.driftClient.txSender.getVersionedTransaction(ixs, [], undefined, undefined);
|
|
695
|
+
let txSig = bytes_1.bs58.encode(tx.signatures[0]);
|
|
696
|
+
if (txParams === null || txParams === void 0 ? void 0 : txParams.simulateTransaction) {
|
|
697
|
+
const resp = await this.driftClient.connection.simulateTransaction(tx, {
|
|
698
|
+
// replaceRecentBlockhash: true,
|
|
699
|
+
sigVerify: false,
|
|
700
|
+
commitment: this.driftClient.connection.commitment,
|
|
701
|
+
});
|
|
702
|
+
console.log(`Simulated transaction:\n${JSON.stringify(resp, null, 2)}`);
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
const resp = await this.driftClient.sendTransaction(tx, [], this.driftClient.opts);
|
|
706
|
+
if (resp.txSig !== txSig) {
|
|
707
|
+
console.error(`Transaction signature mismatch with self calculated value: ${resp.txSig} !== ${txSig}`);
|
|
708
|
+
txSig = resp.txSig;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
689
711
|
return txSig;
|
|
690
712
|
}
|
|
691
713
|
/**
|
package/package.json
CHANGED
package/src/vaultClient.ts
CHANGED
|
@@ -23,10 +23,8 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
ComputeBudgetProgram,
|
|
25
25
|
PublicKey,
|
|
26
|
-
SetComputeUnitLimitParams,
|
|
27
26
|
SystemProgram,
|
|
28
27
|
SYSVAR_RENT_PUBKEY,
|
|
29
|
-
Transaction,
|
|
30
28
|
TransactionInstruction,
|
|
31
29
|
TransactionSignature,
|
|
32
30
|
} from '@solana/web3.js';
|
|
@@ -38,6 +36,12 @@ import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
|
|
|
38
36
|
import { bs58 } from '@coral-xyz/anchor/dist/cjs/utils/bytes';
|
|
39
37
|
import { UserMapConfig } from '@drift-labs/sdk/lib/userMap/userMapConfig';
|
|
40
38
|
|
|
39
|
+
export type TxParams = {
|
|
40
|
+
cuLimit?: number;
|
|
41
|
+
cuPriceMicroLamports?: number;
|
|
42
|
+
simulateTransaction?: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
41
45
|
export class VaultClient {
|
|
42
46
|
driftClient: DriftClient;
|
|
43
47
|
program: Program<DriftVaults>;
|
|
@@ -505,7 +509,7 @@ export class VaultClient {
|
|
|
505
509
|
remainingAccounts,
|
|
506
510
|
});
|
|
507
511
|
return this.createAndSendTxn([ix], {
|
|
508
|
-
|
|
512
|
+
cuLimit: 1_000_000,
|
|
509
513
|
});
|
|
510
514
|
}
|
|
511
515
|
|
|
@@ -784,13 +788,14 @@ export class VaultClient {
|
|
|
784
788
|
);
|
|
785
789
|
|
|
786
790
|
return await this.createAndSendTxn([requestWithdrawIx], {
|
|
787
|
-
|
|
791
|
+
cuLimit: 650_000,
|
|
788
792
|
});
|
|
789
793
|
}
|
|
790
794
|
}
|
|
791
795
|
|
|
792
796
|
public async withdraw(
|
|
793
|
-
vaultDepositor: PublicKey
|
|
797
|
+
vaultDepositor: PublicKey,
|
|
798
|
+
txParams?: TxParams
|
|
794
799
|
): Promise<TransactionSignature> {
|
|
795
800
|
const vaultDepositorAccount =
|
|
796
801
|
await this.program.account.vaultDepositor.fetch(vaultDepositor);
|
|
@@ -854,7 +859,8 @@ export class VaultClient {
|
|
|
854
859
|
});
|
|
855
860
|
|
|
856
861
|
return await this.createAndSendTxn([withdrawIx], {
|
|
857
|
-
|
|
862
|
+
cuLimit: txParams?.cuLimit ?? 650_000,
|
|
863
|
+
...txParams,
|
|
858
864
|
});
|
|
859
865
|
}
|
|
860
866
|
}
|
|
@@ -1041,28 +1047,49 @@ export class VaultClient {
|
|
|
1041
1047
|
* Used for UI wallet adapters compatibility
|
|
1042
1048
|
*/
|
|
1043
1049
|
public async createAndSendTxn(
|
|
1044
|
-
|
|
1045
|
-
|
|
1050
|
+
vaultIxs: TransactionInstruction[],
|
|
1051
|
+
txParams?: TxParams
|
|
1046
1052
|
): Promise<TransactionSignature> {
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
)
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
const { txSig } = await this.driftClient.sendTransaction(
|
|
1060
|
-
tx,
|
|
1053
|
+
const ixs = [
|
|
1054
|
+
ComputeBudgetProgram.setComputeUnitLimit({
|
|
1055
|
+
units: txParams?.cuLimit ?? 400_000,
|
|
1056
|
+
}),
|
|
1057
|
+
ComputeBudgetProgram.setComputeUnitPrice({
|
|
1058
|
+
microLamports: txParams?.cuPriceMicroLamports ?? 1_000_000,
|
|
1059
|
+
}),
|
|
1060
|
+
...vaultIxs,
|
|
1061
|
+
];
|
|
1062
|
+
|
|
1063
|
+
const tx = await this.driftClient.txSender.getVersionedTransaction(
|
|
1064
|
+
ixs,
|
|
1061
1065
|
[],
|
|
1062
|
-
|
|
1066
|
+
undefined,
|
|
1067
|
+
undefined
|
|
1063
1068
|
);
|
|
1064
1069
|
|
|
1065
|
-
|
|
1070
|
+
let txSig = bs58.encode(tx.signatures[0]);
|
|
1071
|
+
if (txParams?.simulateTransaction) {
|
|
1072
|
+
const resp = await this.driftClient.connection.simulateTransaction(tx, {
|
|
1073
|
+
// replaceRecentBlockhash: true,
|
|
1074
|
+
sigVerify: false,
|
|
1075
|
+
commitment: this.driftClient.connection.commitment,
|
|
1076
|
+
});
|
|
1077
|
+
console.log(`Simulated transaction:\n${JSON.stringify(resp, null, 2)}`);
|
|
1078
|
+
} else {
|
|
1079
|
+
const resp = await this.driftClient.sendTransaction(
|
|
1080
|
+
tx,
|
|
1081
|
+
[],
|
|
1082
|
+
this.driftClient.opts
|
|
1083
|
+
);
|
|
1084
|
+
if (resp.txSig !== txSig) {
|
|
1085
|
+
console.error(
|
|
1086
|
+
`Transaction signature mismatch with self calculated value: ${resp.txSig} !== ${txSig}`
|
|
1087
|
+
);
|
|
1088
|
+
txSig = resp.txSig;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
return txSig!;
|
|
1066
1093
|
}
|
|
1067
1094
|
|
|
1068
1095
|
/**
|