@velocity-exchange/vaults-sdk 0.0.1
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/.env.example +3 -0
- package/README.md +152 -0
- package/cli/cli.ts +751 -0
- package/cli/commands/adminDeleteFeeUpdate.ts +73 -0
- package/cli/commands/adminInitFeeUpdate.ts +73 -0
- package/cli/commands/adminUpdateVaultClass.ts +49 -0
- package/cli/commands/applyProfitShare.ts +139 -0
- package/cli/commands/decodeLogs.ts +98 -0
- package/cli/commands/deposit.ts +98 -0
- package/cli/commands/deriveVaultAddress.ts +14 -0
- package/cli/commands/forceWithdraw.ts +56 -0
- package/cli/commands/forceWithdrawAll.ts +142 -0
- package/cli/commands/index.ts +28 -0
- package/cli/commands/initVault.ts +227 -0
- package/cli/commands/initVaultDepositor.ts +42 -0
- package/cli/commands/listDepositorsForVault.ts +32 -0
- package/cli/commands/managerApplyProfitShare.ts +32 -0
- package/cli/commands/managerBorrow.ts +77 -0
- package/cli/commands/managerCancelWithdraw.ts +30 -0
- package/cli/commands/managerDeposit.ts +45 -0
- package/cli/commands/managerRepay.ts +94 -0
- package/cli/commands/managerRequestWithdraw.ts +86 -0
- package/cli/commands/managerUpdateBorrow.ts +56 -0
- package/cli/commands/managerUpdateFees.ts +156 -0
- package/cli/commands/managerUpdateMarginTradingEnabled.ts +32 -0
- package/cli/commands/managerUpdatePoolId.ts +36 -0
- package/cli/commands/managerUpdateVault.ts +210 -0
- package/cli/commands/managerUpdateVaultDelegate.ts +43 -0
- package/cli/commands/managerUpdateVaultManager.ts +77 -0
- package/cli/commands/managerWithdraw.ts +30 -0
- package/cli/commands/requestWithdraw.ts +58 -0
- package/cli/commands/vaultDeposit.ts +42 -0
- package/cli/commands/vaultInvariantChecks.ts +407 -0
- package/cli/commands/vaultWithdraw.ts +42 -0
- package/cli/commands/viewVault.ts +50 -0
- package/cli/commands/viewVaultDepositor.ts +36 -0
- package/cli/commands/withdraw.ts +40 -0
- package/cli/ledgerWallet.test.ts +49 -0
- package/cli/ledgerWallet.ts +111 -0
- package/cli/utils.ts +389 -0
- package/package.json +48 -0
- package/src/accountSubscribers/index.ts +2 -0
- package/src/accountSubscribers/pollingVaultDepositorSubscriber.ts +69 -0
- package/src/accountSubscribers/pollingVaultSubscriber.ts +63 -0
- package/src/accountSubscribers/pollingVaultsProgramAccountSubscriber.ts +114 -0
- package/src/accounts/index.ts +2 -0
- package/src/accounts/vaultAccount.ts +255 -0
- package/src/accounts/vaultDepositorAccount.ts +77 -0
- package/src/accounts/vaultsProgramAccount.ts +38 -0
- package/src/addresses.ts +114 -0
- package/src/constants/index.ts +15 -0
- package/src/idl/drift_vaults.json +5698 -0
- package/src/index.ts +11 -0
- package/src/math/index.ts +2 -0
- package/src/math/vault.ts +71 -0
- package/src/math/vaultDepositor.ts +90 -0
- package/src/name.ts +18 -0
- package/src/parsers/index.ts +1 -0
- package/src/parsers/logParser.ts +28 -0
- package/src/types/drift_vaults.ts +6211 -0
- package/src/types/types.ts +336 -0
- package/src/utils.ts +74 -0
- package/src/vaultClient.ts +3666 -0
- package/tsconfig.json +24 -0
- package/velocity-exchange-vaults-sdk-0.0.1.tgz +0 -0
package/src/addresses.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
3
|
+
|
|
4
|
+
export function getVaultAddressSync(
|
|
5
|
+
programId: PublicKey,
|
|
6
|
+
encodedName: number[]
|
|
7
|
+
): PublicKey {
|
|
8
|
+
return PublicKey.findProgramAddressSync(
|
|
9
|
+
[
|
|
10
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault')),
|
|
11
|
+
Buffer.from(encodedName),
|
|
12
|
+
],
|
|
13
|
+
programId
|
|
14
|
+
)[0];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getVaultDepositorAddressSync(
|
|
18
|
+
programId: PublicKey,
|
|
19
|
+
vault: PublicKey,
|
|
20
|
+
authority: PublicKey
|
|
21
|
+
): PublicKey {
|
|
22
|
+
return PublicKey.findProgramAddressSync(
|
|
23
|
+
[
|
|
24
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault_depositor')),
|
|
25
|
+
vault.toBuffer(),
|
|
26
|
+
authority.toBuffer(),
|
|
27
|
+
],
|
|
28
|
+
programId
|
|
29
|
+
)[0];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getTokenVaultAddressSync(
|
|
33
|
+
programId: PublicKey,
|
|
34
|
+
vault: PublicKey
|
|
35
|
+
): PublicKey {
|
|
36
|
+
return PublicKey.findProgramAddressSync(
|
|
37
|
+
[
|
|
38
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault_token_account')),
|
|
39
|
+
vault.toBuffer(),
|
|
40
|
+
],
|
|
41
|
+
programId
|
|
42
|
+
)[0];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getInsuranceFundTokenVaultAddressSync(
|
|
46
|
+
programId: PublicKey,
|
|
47
|
+
vault: PublicKey,
|
|
48
|
+
marketIndex: number
|
|
49
|
+
): PublicKey {
|
|
50
|
+
return PublicKey.findProgramAddressSync(
|
|
51
|
+
[
|
|
52
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault_token_account')),
|
|
53
|
+
vault.toBuffer(),
|
|
54
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
55
|
+
],
|
|
56
|
+
programId
|
|
57
|
+
)[0];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getVaultProtocolAddressSync(
|
|
61
|
+
programId: PublicKey,
|
|
62
|
+
vault: PublicKey
|
|
63
|
+
): PublicKey {
|
|
64
|
+
return PublicKey.findProgramAddressSync(
|
|
65
|
+
[
|
|
66
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('vault_protocol')),
|
|
67
|
+
vault.toBuffer(),
|
|
68
|
+
],
|
|
69
|
+
programId
|
|
70
|
+
)[0];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getTokenizedVaultAddressSync(
|
|
74
|
+
programId: PublicKey,
|
|
75
|
+
vault: PublicKey,
|
|
76
|
+
sharesBase: number
|
|
77
|
+
): PublicKey {
|
|
78
|
+
return PublicKey.findProgramAddressSync(
|
|
79
|
+
[
|
|
80
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('tokenized_vault_depositor')),
|
|
81
|
+
vault.toBuffer(),
|
|
82
|
+
Buffer.from(anchor.utils.bytes.utf8.encode(sharesBase.toString())),
|
|
83
|
+
],
|
|
84
|
+
programId
|
|
85
|
+
)[0];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function getTokenizedVaultMintAddressSync(
|
|
89
|
+
programId: PublicKey,
|
|
90
|
+
vault: PublicKey,
|
|
91
|
+
sharesBase: number
|
|
92
|
+
): PublicKey {
|
|
93
|
+
return PublicKey.findProgramAddressSync(
|
|
94
|
+
[
|
|
95
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('mint')),
|
|
96
|
+
vault.toBuffer(),
|
|
97
|
+
Buffer.from(anchor.utils.bytes.utf8.encode(sharesBase.toString())),
|
|
98
|
+
],
|
|
99
|
+
programId
|
|
100
|
+
)[0];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function getFeeUpdateAddressSync(
|
|
104
|
+
programId: PublicKey,
|
|
105
|
+
vault: PublicKey
|
|
106
|
+
): PublicKey {
|
|
107
|
+
return PublicKey.findProgramAddressSync(
|
|
108
|
+
[
|
|
109
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('fee_update')),
|
|
110
|
+
vault.toBuffer(),
|
|
111
|
+
],
|
|
112
|
+
programId
|
|
113
|
+
)[0];
|
|
114
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BN, TEN } from '@velocity-exchange/sdk';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
|
|
4
|
+
export const VAULT_SHARES_PRECISION_EXP = new BN(6);
|
|
5
|
+
|
|
6
|
+
// arbitrarily large fuel per share precision
|
|
7
|
+
export const FUEL_SHARE_PRECISION_EXP = new BN(18);
|
|
8
|
+
export const FUEL_SHARE_PRECISION = TEN.pow(FUEL_SHARE_PRECISION_EXP);
|
|
9
|
+
|
|
10
|
+
// some arbitrary timestamp to identify VaultDepositors created after fuel distribution started.
|
|
11
|
+
export const MAGIC_FUEL_START_TS = 123;
|
|
12
|
+
|
|
13
|
+
export const VAULT_ADMIN_KEY = new PublicKey(
|
|
14
|
+
'4wbNjWbj3kPDbyKnSq8SXVEtAJw4uzE8mJ2QwuK1BCYZ'
|
|
15
|
+
);
|