@drift-labs/vaults-sdk 0.1.531 → 0.1.533
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/cli.ts +6 -0
- package/cli/commands/applyProfitShare.ts +14 -16
- package/cli/commands/forceWithdrawAll.ts +101 -0
- package/cli/commands/index.ts +1 -0
- package/cli/utils.ts +2 -0
- package/lib/addresses.d.ts +3 -0
- package/lib/addresses.js +24 -0
- package/lib/types/drift_vaults.d.ts +673 -60
- package/lib/types/drift_vaults.js +668 -55
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +20 -1
- package/lib/vaultClient.d.ts +39 -8
- package/lib/vaultClient.js +347 -44
- package/package.json +2 -2
- package/src/addresses.ts +45 -0
- package/src/idl/drift_vaults.json +1527 -207
- package/src/types/drift_vaults.ts +1322 -96
- package/src/utils.ts +37 -1
- package/src/vaultClient.ts +642 -60
package/src/utils.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { AnchorProvider } from '@coral-xyz/anchor';
|
|
2
2
|
import { DriftClient, IWallet } from '@drift-labs/sdk';
|
|
3
|
-
import { Connection } from '@solana/web3.js';
|
|
3
|
+
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
4
4
|
import { DriftVaults, IDL } from './types/drift_vaults';
|
|
5
5
|
import { VaultClient } from './vaultClient';
|
|
6
6
|
import * as anchor from '@coral-xyz/anchor';
|
|
7
7
|
import { VAULT_PROGRAM_ID } from './types/types';
|
|
8
|
+
import {
|
|
9
|
+
createAssociatedTokenAccountInstruction,
|
|
10
|
+
getAssociatedTokenAddress,
|
|
11
|
+
} from '@solana/spl-token';
|
|
8
12
|
|
|
9
13
|
export const getDriftVaultProgram = (
|
|
10
14
|
connection: Connection,
|
|
@@ -31,3 +35,35 @@ export const getVaultClient = (
|
|
|
31
35
|
|
|
32
36
|
return vaultClient;
|
|
33
37
|
};
|
|
38
|
+
|
|
39
|
+
export const getOrCreateATAInstruction = async (
|
|
40
|
+
tokenMint: PublicKey,
|
|
41
|
+
owner: PublicKey,
|
|
42
|
+
connection: Connection,
|
|
43
|
+
allowOwnerOffCurve = true,
|
|
44
|
+
payer = owner
|
|
45
|
+
): Promise<[PublicKey, TransactionInstruction?]> => {
|
|
46
|
+
let toAccount;
|
|
47
|
+
try {
|
|
48
|
+
toAccount = await getAssociatedTokenAddress(
|
|
49
|
+
tokenMint,
|
|
50
|
+
owner,
|
|
51
|
+
allowOwnerOffCurve
|
|
52
|
+
);
|
|
53
|
+
const account = await connection.getAccountInfo(toAccount);
|
|
54
|
+
if (!account) {
|
|
55
|
+
const ix = createAssociatedTokenAccountInstruction(
|
|
56
|
+
payer,
|
|
57
|
+
toAccount,
|
|
58
|
+
owner,
|
|
59
|
+
tokenMint
|
|
60
|
+
);
|
|
61
|
+
return [toAccount, ix];
|
|
62
|
+
}
|
|
63
|
+
return [toAccount, undefined];
|
|
64
|
+
} catch (e) {
|
|
65
|
+
/* handle error */
|
|
66
|
+
console.error('Error::getOrCreateATAInstruction', e);
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
};
|