@drift-labs/vaults-sdk 0.1.334 → 0.1.336
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 +65 -1
- package/lib/vaultClient.js +60 -35
- package/package.json +2 -2
- package/src/vaultClient.ts +101 -40
package/bun.lockb
CHANGED
|
Binary file
|
package/lib/vaultClient.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BN, DriftClient, UserMap } from '@drift-labs/sdk';
|
|
|
2
2
|
import { Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
3
3
|
import { DriftVaults } from './types/drift_vaults';
|
|
4
4
|
import { CompetitionsClient } from '@drift-labs/competitions-sdk';
|
|
5
|
-
import { AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
5
|
+
import { AddressLookupTableAccount, PublicKey, TransactionInstruction, TransactionSignature, VersionedTransaction } from '@solana/web3.js';
|
|
6
6
|
import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
|
|
7
7
|
import { UserMapConfig } from '@drift-labs/sdk/lib/userMap/userMapConfig';
|
|
8
8
|
export type TxParams = {
|
|
@@ -110,6 +110,68 @@ export declare class VaultClient {
|
|
|
110
110
|
* @returns
|
|
111
111
|
*/
|
|
112
112
|
initializeVaultDepositor(vault: PublicKey, authority?: PublicKey): Promise<TransactionSignature>;
|
|
113
|
+
prepDepositTx(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
|
|
114
|
+
authority: PublicKey;
|
|
115
|
+
vault: PublicKey;
|
|
116
|
+
}): Promise<{
|
|
117
|
+
vaultAccount: {
|
|
118
|
+
name: number[];
|
|
119
|
+
pubkey: PublicKey;
|
|
120
|
+
manager: PublicKey;
|
|
121
|
+
tokenAccount: PublicKey;
|
|
122
|
+
userStats: PublicKey;
|
|
123
|
+
user: PublicKey;
|
|
124
|
+
delegate: PublicKey;
|
|
125
|
+
liquidationDelegate: PublicKey;
|
|
126
|
+
userShares: BN;
|
|
127
|
+
totalShares: BN;
|
|
128
|
+
lastFeeUpdateTs: BN;
|
|
129
|
+
liquidationStartTs: BN;
|
|
130
|
+
redeemPeriod: BN;
|
|
131
|
+
totalWithdrawRequested: BN;
|
|
132
|
+
maxTokens: BN;
|
|
133
|
+
managementFee: BN;
|
|
134
|
+
initTs: BN;
|
|
135
|
+
netDeposits: BN;
|
|
136
|
+
managerNetDeposits: BN;
|
|
137
|
+
totalDeposits: BN;
|
|
138
|
+
totalWithdraws: BN;
|
|
139
|
+
managerTotalDeposits: BN;
|
|
140
|
+
managerTotalWithdraws: BN;
|
|
141
|
+
managerTotalFee: BN;
|
|
142
|
+
managerTotalProfitShare: BN;
|
|
143
|
+
minDepositAmount: BN;
|
|
144
|
+
lastManagerWithdrawRequest: {
|
|
145
|
+
shares: BN;
|
|
146
|
+
value: BN;
|
|
147
|
+
ts: BN;
|
|
148
|
+
};
|
|
149
|
+
sharesBase: number;
|
|
150
|
+
profitShare: number;
|
|
151
|
+
hurdleRate: number;
|
|
152
|
+
spotMarketIndex: number;
|
|
153
|
+
bump: number;
|
|
154
|
+
permissioned: boolean;
|
|
155
|
+
padding: BN[];
|
|
156
|
+
};
|
|
157
|
+
accounts: {
|
|
158
|
+
vault: PublicKey;
|
|
159
|
+
vaultDepositor: PublicKey;
|
|
160
|
+
vaultTokenAccount: PublicKey;
|
|
161
|
+
driftUserStats: PublicKey;
|
|
162
|
+
driftUser: PublicKey;
|
|
163
|
+
driftState: PublicKey;
|
|
164
|
+
driftSpotMarketVault: PublicKey;
|
|
165
|
+
userTokenAccount: PublicKey;
|
|
166
|
+
driftProgram: PublicKey;
|
|
167
|
+
tokenProgram: PublicKey;
|
|
168
|
+
};
|
|
169
|
+
remainingAccounts: import("@solana/web3.js").AccountMeta[];
|
|
170
|
+
}>;
|
|
171
|
+
createDepositTx(vaultDepositor: PublicKey, amount: BN, initVaultDepositor?: {
|
|
172
|
+
authority: PublicKey;
|
|
173
|
+
vault: PublicKey;
|
|
174
|
+
}, txParams?: TxParams): Promise<VersionedTransaction>;
|
|
113
175
|
/**
|
|
114
176
|
* Depositor funds into the specified vault.
|
|
115
177
|
* @param vaultDepositor
|
|
@@ -132,6 +194,8 @@ export declare class VaultClient {
|
|
|
132
194
|
* @returns
|
|
133
195
|
*/
|
|
134
196
|
liquidate(vaultDepositor: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
197
|
+
createTxn(vaultIxs: TransactionInstruction[], txParams?: TxParams): Promise<VersionedTransaction>;
|
|
198
|
+
sendTxn(transaction: VersionedTransaction, simulateTransaction?: boolean): Promise<TransactionSignature>;
|
|
135
199
|
/**
|
|
136
200
|
* Used for UI wallet adapters compatibility
|
|
137
201
|
*/
|
package/lib/vaultClient.js
CHANGED
|
@@ -269,7 +269,9 @@ class VaultClient {
|
|
|
269
269
|
.rpc();
|
|
270
270
|
}
|
|
271
271
|
else {
|
|
272
|
-
const requestWithdrawIx = this.program.instruction.managerRequestWithdraw(
|
|
272
|
+
const requestWithdrawIx = this.program.instruction.managerRequestWithdraw(
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
amount, withdrawUnit, {
|
|
273
275
|
accounts: {
|
|
274
276
|
manager: this.driftClient.wallet.publicKey,
|
|
275
277
|
...accounts,
|
|
@@ -427,14 +429,7 @@ class VaultClient {
|
|
|
427
429
|
return await this.createAndSendTxn([initIx]);
|
|
428
430
|
}
|
|
429
431
|
}
|
|
430
|
-
|
|
431
|
-
* Depositor funds into the specified vault.
|
|
432
|
-
* @param vaultDepositor
|
|
433
|
-
* @param amount
|
|
434
|
-
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
435
|
-
* @returns
|
|
436
|
-
*/
|
|
437
|
-
async deposit(vaultDepositor, amount, initVaultDepositor, txParams) {
|
|
432
|
+
async prepDepositTx(vaultDepositor, amount, initVaultDepositor) {
|
|
438
433
|
let vaultPubKey;
|
|
439
434
|
if (initVaultDepositor) {
|
|
440
435
|
vaultPubKey = initVaultDepositor.vault;
|
|
@@ -467,7 +462,39 @@ class VaultClient {
|
|
|
467
462
|
driftProgram: this.driftClient.program.programId,
|
|
468
463
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
469
464
|
};
|
|
465
|
+
return {
|
|
466
|
+
vaultAccount,
|
|
467
|
+
accounts,
|
|
468
|
+
remainingAccounts,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async createDepositTx(vaultDepositor, amount, initVaultDepositor, txParams) {
|
|
472
|
+
const { vaultAccount, accounts, remainingAccounts } = await this.prepDepositTx(vaultDepositor, amount, initVaultDepositor);
|
|
473
|
+
const depositIx = this.program.instruction.deposit(amount, {
|
|
474
|
+
accounts: {
|
|
475
|
+
authority: this.driftClient.wallet.publicKey,
|
|
476
|
+
...accounts,
|
|
477
|
+
},
|
|
478
|
+
remainingAccounts,
|
|
479
|
+
});
|
|
480
|
+
if (initVaultDepositor) {
|
|
481
|
+
const initIx = this.createInitVaultDepositorIx(vaultAccount.pubkey, initVaultDepositor.authority);
|
|
482
|
+
return await this.createTxn([initIx, depositIx], txParams);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
return await this.createTxn([depositIx], txParams);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Depositor funds into the specified vault.
|
|
490
|
+
* @param vaultDepositor
|
|
491
|
+
* @param amount
|
|
492
|
+
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
493
|
+
* @returns
|
|
494
|
+
*/
|
|
495
|
+
async deposit(vaultDepositor, amount, initVaultDepositor, txParams) {
|
|
470
496
|
if (this.cliMode) {
|
|
497
|
+
const { vaultAccount, accounts, remainingAccounts } = await this.prepDepositTx(vaultDepositor, amount, initVaultDepositor);
|
|
471
498
|
if (initVaultDepositor) {
|
|
472
499
|
await this.initializeVaultDepositor(vaultAccount.pubkey, initVaultDepositor.authority);
|
|
473
500
|
}
|
|
@@ -478,20 +505,8 @@ class VaultClient {
|
|
|
478
505
|
.rpc();
|
|
479
506
|
}
|
|
480
507
|
else {
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
authority: this.driftClient.wallet.publicKey,
|
|
484
|
-
...accounts,
|
|
485
|
-
},
|
|
486
|
-
remainingAccounts,
|
|
487
|
-
});
|
|
488
|
-
if (initVaultDepositor) {
|
|
489
|
-
const initIx = this.createInitVaultDepositorIx(vaultAccount.pubkey, initVaultDepositor.authority);
|
|
490
|
-
return await this.createAndSendTxn([initIx, depositIx], txParams);
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
return await this.createAndSendTxn([depositIx], txParams);
|
|
494
|
-
}
|
|
508
|
+
const depositTxn = await this.createDepositTx(vaultDepositor, amount, initVaultDepositor, txParams);
|
|
509
|
+
return this.sendTxn(depositTxn, txParams === null || txParams === void 0 ? void 0 : txParams.simulateTransaction);
|
|
495
510
|
}
|
|
496
511
|
}
|
|
497
512
|
async requestWithdraw(vaultDepositor, amount, withdrawUnit, txParams) {
|
|
@@ -519,7 +534,9 @@ class VaultClient {
|
|
|
519
534
|
.rpc();
|
|
520
535
|
}
|
|
521
536
|
else {
|
|
522
|
-
const requestWithdrawIx = this.program.instruction.requestWithdraw(
|
|
537
|
+
const requestWithdrawIx = this.program.instruction.requestWithdraw(
|
|
538
|
+
// @ts-ignore
|
|
539
|
+
amount, withdrawUnit, {
|
|
523
540
|
accounts: {
|
|
524
541
|
authority: this.driftClient.wallet.publicKey,
|
|
525
542
|
...accounts,
|
|
@@ -720,11 +737,8 @@ class VaultClient {
|
|
|
720
737
|
return await this.createAndSendTxn([liquidateIx], txParams);
|
|
721
738
|
}
|
|
722
739
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
*/
|
|
726
|
-
async createAndSendTxn(vaultIxs, txParams) {
|
|
727
|
-
var _a, _b, _c, _d;
|
|
740
|
+
async createTxn(vaultIxs, txParams) {
|
|
741
|
+
var _a, _b, _c;
|
|
728
742
|
const ixs = [
|
|
729
743
|
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
730
744
|
units: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.cuLimit) !== null && _a !== void 0 ? _a : 400000,
|
|
@@ -734,7 +748,7 @@ class VaultClient {
|
|
|
734
748
|
}),
|
|
735
749
|
...vaultIxs,
|
|
736
750
|
];
|
|
737
|
-
|
|
751
|
+
return (await this.driftClient.txHandler.buildTransaction({
|
|
738
752
|
connection: this.driftClient.connection,
|
|
739
753
|
instructions: ixs,
|
|
740
754
|
lookupTables: (_c = txParams === null || txParams === void 0 ? void 0 : txParams.lookupTables) !== null && _c !== void 0 ? _c : [],
|
|
@@ -743,10 +757,13 @@ class VaultClient {
|
|
|
743
757
|
txVersion: 0,
|
|
744
758
|
fetchMarketLookupTableAccount: this.driftClient.fetchMarketLookupTableAccount.bind(this.driftClient),
|
|
745
759
|
}));
|
|
746
|
-
|
|
747
|
-
|
|
760
|
+
}
|
|
761
|
+
async sendTxn(transaction, simulateTransaction) {
|
|
762
|
+
var _a;
|
|
763
|
+
let txSig = bytes_1.bs58.encode(transaction.signatures[0]);
|
|
764
|
+
if (simulateTransaction) {
|
|
748
765
|
try {
|
|
749
|
-
const resp = await this.driftClient.connection.simulateTransaction(
|
|
766
|
+
const resp = await this.driftClient.connection.simulateTransaction(transaction, {
|
|
750
767
|
sigVerify: false,
|
|
751
768
|
commitment: this.driftClient.connection.commitment,
|
|
752
769
|
});
|
|
@@ -754,11 +771,11 @@ class VaultClient {
|
|
|
754
771
|
}
|
|
755
772
|
catch (e) {
|
|
756
773
|
const err = e;
|
|
757
|
-
console.error(`Error simulating transaction: ${err.message}\n:${(
|
|
774
|
+
console.error(`Error simulating transaction: ${err.message}\n:${(_a = err.stack) !== null && _a !== void 0 ? _a : ''}`);
|
|
758
775
|
}
|
|
759
776
|
}
|
|
760
777
|
else {
|
|
761
|
-
const resp = await this.driftClient.sendTransaction(
|
|
778
|
+
const resp = await this.driftClient.sendTransaction(transaction, [], this.driftClient.opts);
|
|
762
779
|
if (resp.txSig !== txSig) {
|
|
763
780
|
console.error(`Transaction signature mismatch with self calculated value: ${resp.txSig} !== ${txSig}`);
|
|
764
781
|
txSig = resp.txSig;
|
|
@@ -766,6 +783,14 @@ class VaultClient {
|
|
|
766
783
|
}
|
|
767
784
|
return txSig;
|
|
768
785
|
}
|
|
786
|
+
/**
|
|
787
|
+
* Used for UI wallet adapters compatibility
|
|
788
|
+
*/
|
|
789
|
+
async createAndSendTxn(vaultIxs, txParams) {
|
|
790
|
+
const tx = await this.createTxn(vaultIxs, txParams);
|
|
791
|
+
const txSig = await this.sendTxn(tx, txParams === null || txParams === void 0 ? void 0 : txParams.simulateTransaction);
|
|
792
|
+
return txSig;
|
|
793
|
+
}
|
|
769
794
|
/**
|
|
770
795
|
* Initializes an insurance fund stake for the vault.
|
|
771
796
|
* @param vault vault address to update
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/vaults-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.336",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"directories": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@coral-xyz/anchor": "0.28.0",
|
|
11
11
|
"@drift-labs/competitions-sdk": "0.2.334",
|
|
12
|
-
"@drift-labs/sdk": "2.85.0-beta.
|
|
12
|
+
"@drift-labs/sdk": "2.85.0-beta.12",
|
|
13
13
|
"@solana/web3.js": "1.73.2",
|
|
14
14
|
"commander": "^11.0.0",
|
|
15
15
|
"dotenv": "^16.3.1",
|
package/src/vaultClient.ts
CHANGED
|
@@ -437,6 +437,7 @@ export class VaultClient {
|
|
|
437
437
|
.rpc();
|
|
438
438
|
} else {
|
|
439
439
|
const requestWithdrawIx = this.program.instruction.managerRequestWithdraw(
|
|
440
|
+
// @ts-ignore
|
|
440
441
|
amount,
|
|
441
442
|
withdrawUnit,
|
|
442
443
|
{
|
|
@@ -681,22 +682,14 @@ export class VaultClient {
|
|
|
681
682
|
}
|
|
682
683
|
}
|
|
683
684
|
|
|
684
|
-
|
|
685
|
-
* Depositor funds into the specified vault.
|
|
686
|
-
* @param vaultDepositor
|
|
687
|
-
* @param amount
|
|
688
|
-
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
689
|
-
* @returns
|
|
690
|
-
*/
|
|
691
|
-
public async deposit(
|
|
685
|
+
public async prepDepositTx(
|
|
692
686
|
vaultDepositor: PublicKey,
|
|
693
687
|
amount: BN,
|
|
694
688
|
initVaultDepositor?: {
|
|
695
689
|
authority: PublicKey;
|
|
696
690
|
vault: PublicKey;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
): Promise<TransactionSignature> {
|
|
691
|
+
}
|
|
692
|
+
) {
|
|
700
693
|
let vaultPubKey: PublicKey;
|
|
701
694
|
if (initVaultDepositor) {
|
|
702
695
|
vaultPubKey = initVaultDepositor.vault;
|
|
@@ -747,7 +740,64 @@ export class VaultClient {
|
|
|
747
740
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
748
741
|
};
|
|
749
742
|
|
|
743
|
+
return {
|
|
744
|
+
vaultAccount,
|
|
745
|
+
accounts,
|
|
746
|
+
remainingAccounts,
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
public async createDepositTx(
|
|
751
|
+
vaultDepositor: PublicKey,
|
|
752
|
+
amount: BN,
|
|
753
|
+
initVaultDepositor?: {
|
|
754
|
+
authority: PublicKey;
|
|
755
|
+
vault: PublicKey;
|
|
756
|
+
},
|
|
757
|
+
txParams?: TxParams
|
|
758
|
+
): Promise<VersionedTransaction> {
|
|
759
|
+
const { vaultAccount, accounts, remainingAccounts } =
|
|
760
|
+
await this.prepDepositTx(vaultDepositor, amount, initVaultDepositor);
|
|
761
|
+
|
|
762
|
+
const depositIx = this.program.instruction.deposit(amount, {
|
|
763
|
+
accounts: {
|
|
764
|
+
authority: this.driftClient.wallet.publicKey,
|
|
765
|
+
...accounts,
|
|
766
|
+
},
|
|
767
|
+
remainingAccounts,
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
if (initVaultDepositor) {
|
|
771
|
+
const initIx = this.createInitVaultDepositorIx(
|
|
772
|
+
vaultAccount.pubkey,
|
|
773
|
+
initVaultDepositor.authority
|
|
774
|
+
);
|
|
775
|
+
return await this.createTxn([initIx, depositIx], txParams);
|
|
776
|
+
} else {
|
|
777
|
+
return await this.createTxn([depositIx], txParams);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Depositor funds into the specified vault.
|
|
783
|
+
* @param vaultDepositor
|
|
784
|
+
* @param amount
|
|
785
|
+
* @param initVaultDepositor If true, will initialize the vault depositor account
|
|
786
|
+
* @returns
|
|
787
|
+
*/
|
|
788
|
+
public async deposit(
|
|
789
|
+
vaultDepositor: PublicKey,
|
|
790
|
+
amount: BN,
|
|
791
|
+
initVaultDepositor?: {
|
|
792
|
+
authority: PublicKey;
|
|
793
|
+
vault: PublicKey;
|
|
794
|
+
},
|
|
795
|
+
txParams?: TxParams
|
|
796
|
+
): Promise<TransactionSignature> {
|
|
750
797
|
if (this.cliMode) {
|
|
798
|
+
const { vaultAccount, accounts, remainingAccounts } =
|
|
799
|
+
await this.prepDepositTx(vaultDepositor, amount, initVaultDepositor);
|
|
800
|
+
|
|
751
801
|
if (initVaultDepositor) {
|
|
752
802
|
await this.initializeVaultDepositor(
|
|
753
803
|
vaultAccount.pubkey,
|
|
@@ -760,23 +810,14 @@ export class VaultClient {
|
|
|
760
810
|
.remainingAccounts(remainingAccounts)
|
|
761
811
|
.rpc();
|
|
762
812
|
} else {
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
});
|
|
813
|
+
const depositTxn = await this.createDepositTx(
|
|
814
|
+
vaultDepositor,
|
|
815
|
+
amount,
|
|
816
|
+
initVaultDepositor,
|
|
817
|
+
txParams
|
|
818
|
+
);
|
|
770
819
|
|
|
771
|
-
|
|
772
|
-
const initIx = this.createInitVaultDepositorIx(
|
|
773
|
-
vaultAccount.pubkey,
|
|
774
|
-
initVaultDepositor.authority
|
|
775
|
-
);
|
|
776
|
-
return await this.createAndSendTxn([initIx, depositIx], txParams);
|
|
777
|
-
} else {
|
|
778
|
-
return await this.createAndSendTxn([depositIx], txParams);
|
|
779
|
-
}
|
|
820
|
+
return this.sendTxn(depositTxn, txParams?.simulateTransaction);
|
|
780
821
|
}
|
|
781
822
|
}
|
|
782
823
|
|
|
@@ -821,6 +862,7 @@ export class VaultClient {
|
|
|
821
862
|
.rpc();
|
|
822
863
|
} else {
|
|
823
864
|
const requestWithdrawIx = this.program.instruction.requestWithdraw(
|
|
865
|
+
// @ts-ignore
|
|
824
866
|
amount,
|
|
825
867
|
withdrawUnit,
|
|
826
868
|
{
|
|
@@ -1111,13 +1153,10 @@ export class VaultClient {
|
|
|
1111
1153
|
}
|
|
1112
1154
|
}
|
|
1113
1155
|
|
|
1114
|
-
|
|
1115
|
-
* Used for UI wallet adapters compatibility
|
|
1116
|
-
*/
|
|
1117
|
-
public async createAndSendTxn(
|
|
1156
|
+
public async createTxn(
|
|
1118
1157
|
vaultIxs: TransactionInstruction[],
|
|
1119
1158
|
txParams?: TxParams
|
|
1120
|
-
): Promise<
|
|
1159
|
+
): Promise<VersionedTransaction> {
|
|
1121
1160
|
const ixs = [
|
|
1122
1161
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
1123
1162
|
units: txParams?.cuLimit ?? 400_000,
|
|
@@ -1128,7 +1167,7 @@ export class VaultClient {
|
|
|
1128
1167
|
...vaultIxs,
|
|
1129
1168
|
];
|
|
1130
1169
|
|
|
1131
|
-
|
|
1170
|
+
return (await this.driftClient.txHandler.buildTransaction({
|
|
1132
1171
|
connection: this.driftClient.connection,
|
|
1133
1172
|
instructions: ixs,
|
|
1134
1173
|
lookupTables: txParams?.lookupTables ?? [],
|
|
@@ -1138,13 +1177,22 @@ export class VaultClient {
|
|
|
1138
1177
|
fetchMarketLookupTableAccount:
|
|
1139
1178
|
this.driftClient.fetchMarketLookupTableAccount.bind(this.driftClient),
|
|
1140
1179
|
})) as VersionedTransaction;
|
|
1141
|
-
|
|
1142
|
-
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
public async sendTxn(
|
|
1183
|
+
transaction: VersionedTransaction,
|
|
1184
|
+
simulateTransaction?: boolean
|
|
1185
|
+
): Promise<TransactionSignature> {
|
|
1186
|
+
let txSig = bs58.encode(transaction.signatures[0]);
|
|
1187
|
+
if (simulateTransaction) {
|
|
1143
1188
|
try {
|
|
1144
|
-
const resp = await this.driftClient.connection.simulateTransaction(
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1189
|
+
const resp = await this.driftClient.connection.simulateTransaction(
|
|
1190
|
+
transaction,
|
|
1191
|
+
{
|
|
1192
|
+
sigVerify: false,
|
|
1193
|
+
commitment: this.driftClient.connection.commitment,
|
|
1194
|
+
}
|
|
1195
|
+
);
|
|
1148
1196
|
console.log(`Simulated transaction:\n${JSON.stringify(resp, null, 2)}`);
|
|
1149
1197
|
} catch (e) {
|
|
1150
1198
|
const err = e as Error;
|
|
@@ -1154,7 +1202,7 @@ export class VaultClient {
|
|
|
1154
1202
|
}
|
|
1155
1203
|
} else {
|
|
1156
1204
|
const resp = await this.driftClient.sendTransaction(
|
|
1157
|
-
|
|
1205
|
+
transaction,
|
|
1158
1206
|
[],
|
|
1159
1207
|
this.driftClient.opts
|
|
1160
1208
|
);
|
|
@@ -1169,6 +1217,19 @@ export class VaultClient {
|
|
|
1169
1217
|
return txSig!;
|
|
1170
1218
|
}
|
|
1171
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* Used for UI wallet adapters compatibility
|
|
1222
|
+
*/
|
|
1223
|
+
public async createAndSendTxn(
|
|
1224
|
+
vaultIxs: TransactionInstruction[],
|
|
1225
|
+
txParams?: TxParams
|
|
1226
|
+
): Promise<TransactionSignature> {
|
|
1227
|
+
const tx = await this.createTxn(vaultIxs, txParams);
|
|
1228
|
+
const txSig = await this.sendTxn(tx, txParams?.simulateTransaction);
|
|
1229
|
+
|
|
1230
|
+
return txSig;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1172
1233
|
/**
|
|
1173
1234
|
* Initializes an insurance fund stake for the vault.
|
|
1174
1235
|
* @param vault vault address to update
|