@drift-labs/vaults-sdk 0.6.31 → 0.6.32
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/cli/commands/initVault.ts +34 -34
- package/package.json +1 -1
|
@@ -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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
|
|
141
|
-
|
|
155
|
+
if (!swiftUsersAccountExists) {
|
|
156
|
+
ixs.push(
|
|
157
|
+
await driftClient.getInitializeSignedMsgUserOrdersAccountIx(
|
|
158
|
+
vaultAddress,
|
|
159
|
+
8
|
|
160
|
+
)[1]
|
|
161
|
+
);
|
|
162
|
+
}
|
|
142
163
|
|
|
143
|
-
|
|
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,
|
|
170
|
+
console.log(dumpTransactionMessage(cmdOpts.manager ? new PublicKey(cmdOpts.manager) : driftClient.wallet.publicKey, ixs));
|
|
146
171
|
} else {
|
|
147
|
-
const
|
|
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
|
};
|