@drift-labs/vaults-sdk 0.6.31 → 0.6.33

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.
@@ -5,6 +5,7 @@ import {
5
5
  TEN,
6
6
  convertToNumber,
7
7
  decodeName,
8
+ getSignedMsgUserAccountPublicKey,
8
9
  } from "@drift-labs/sdk";
9
10
  import {
10
11
  OptionValues,
@@ -122,8 +123,8 @@ export const initVault = async (program: Command, cmdOpts: OptionValues) => {
122
123
 
123
124
  const vaultAddress = getVaultAddressSync(VAULT_PROGRAM_ID, vaultNameBytes);
124
125
 
125
- if (cmdOpts.dumpTransactionMessage) {
126
- const initIx = await driftVault.getInitializeVaultIx({
126
+ const ixs = [
127
+ await driftVault.getInitializeVaultIx({
127
128
  name: vaultNameBytes,
128
129
  spotMarketIndex,
129
130
  redeemPeriod: new BN(redeemPeriodSec),
@@ -134,42 +135,41 @@ export const initVault = async (program: Command, cmdOpts: OptionValues) => {
134
135
  permissioned,
135
136
  minDepositAmount: minDepositAmountBN,
136
137
  manager: cmdOpts.manager,
137
- });
138
- const updateDelegateIx = await driftVault.getUpdateDelegateIx(vaultAddress, delegate);
138
+ }),
139
+ await driftVault.getUpdateDelegateIx(vaultAddress, delegate)
140
+ ];
141
+
142
+ const signedOrdersAccountAddress = getSignedMsgUserAccountPublicKey(
143
+ driftClient.program.programId,
144
+ vaultAddress,
145
+ );
146
+
147
+ let swiftUsersAccountExists = false;
148
+ try {
149
+ const acc = await driftClient.connection.getAccountInfo(signedOrdersAccountAddress);
150
+ swiftUsersAccountExists = acc !== null;
151
+ } catch (_err) {
152
+ // Error getting account info is non-critical, default to false
153
+ }
139
154
 
140
- console.log(`New vault address will be: ${vaultAddress.toBase58()}`);
141
- console.log(`Setting trading delegate to: ${delegate.toBase58()}`);
155
+ if (!swiftUsersAccountExists) {
156
+ ixs.push(
157
+ await driftClient.getInitializeSignedMsgUserOrdersAccountIx(
158
+ vaultAddress,
159
+ 8
160
+ )[1]
161
+ );
162
+ }
142
163
 
143
- console.log('');
164
+ console.log(`New vault address will be: ${vaultAddress.toBase58()}`);
165
+ console.log(`Setting trading delegate to: ${delegate.toBase58()}`);
166
+ console.log('');
167
+
168
+ if (cmdOpts.dumpTransactionMessage) {
144
169
  console.log(`Base 58 encoded transaction:`);
145
- console.log(dumpTransactionMessage(cmdOpts.manager ? new PublicKey(cmdOpts.manager) : driftClient.wallet.publicKey, [initIx, updateDelegateIx]));
170
+ console.log(dumpTransactionMessage(cmdOpts.manager ? new PublicKey(cmdOpts.manager) : driftClient.wallet.publicKey, ixs));
146
171
  } else {
147
- const initSignedOrdersAccIx = await driftClient.getInitializeSignedMsgUserOrdersAccountIx(
148
- vaultAddress,
149
- 8
150
- );
151
- const initIx = await driftVault.getInitializeVaultIx({
152
- name: vaultNameBytes,
153
- spotMarketIndex,
154
- redeemPeriod: new BN(redeemPeriodSec),
155
- maxTokens: maxTokensBN,
156
- managementFee: managementFeeBN,
157
- profitShare: profitShareBN.toNumber(),
158
- hurdleRate: 0,
159
- permissioned,
160
- minDepositAmount: minDepositAmountBN,
161
- manager: cmdOpts.manager,
162
- });
163
- const initTx = await driftVault.createAndSendTxn([
164
- initSignedOrdersAccIx[1],
165
- initIx,
166
- ]);
172
+ const initTx = await driftVault.createAndSendTxn(ixs);
167
173
  console.log(`Initialized vault, tx: https://solana.fm/tx/${initTx}${driftClient.env === "devnet" ? "?cluster=devnet-solana" : ""}`);
168
-
169
- console.log(`\nNew vault address: ${vaultAddress}\n`);
170
-
171
- console.log(`Updating the drift account delegate to: ${delegate}...`);
172
- const updateDelegateTx = await driftVault.updateDelegate(vaultAddress, delegate);
173
- console.log(`update delegate tx: https://solana.fm/tx/${updateDelegateTx}${driftClient.env === "devnet" ? "?cluster=devnet-solana" : ""}`);
174
174
  }
175
175
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/vaults-sdk",
3
- "version": "0.6.31",
3
+ "version": "0.6.33",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "directories": {
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@coral-xyz/anchor": "0.29.0",
11
- "@drift-labs/sdk": "2.119.0-beta.1",
11
+ "@drift-labs/sdk": "2.119.0-beta.2",
12
12
  "@metaplex-foundation/js": "0.20.1",
13
13
  "@solana/web3.js": "1.92.3",
14
14
  "commander": "11.1.0",