@drift-labs/vaults-sdk 0.1.0 → 0.1.2
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/README.md +44 -8
- package/cli/cli.ts +45 -9
- package/cli/commands/applyProfitShare.ts +3 -6
- package/cli/commands/deposit.ts +0 -1
- package/cli/commands/deriveVaultAddress.ts +15 -0
- package/cli/commands/index.ts +4 -1
- package/cli/commands/initVault.ts +104 -23
- package/cli/commands/initVaultDepositor.ts +0 -1
- package/cli/commands/listDepositorsForVault.ts +0 -1
- package/cli/commands/managerCancelWithdraw.ts +0 -1
- package/cli/commands/managerDeposit.ts +0 -1
- package/cli/commands/managerRequestWithdraw.ts +0 -1
- package/cli/commands/managerUpdateMarginTradingEnabled.ts +26 -0
- package/cli/commands/managerUpdateVault.ts +91 -9
- package/cli/commands/managerUpdateVaultDelegate.ts +35 -0
- package/cli/commands/managerWithdraw.ts +0 -1
- package/cli/commands/requestWithdraw.ts +0 -1
- package/cli/commands/vaultDeposit.ts +0 -1
- package/cli/commands/vaultWithdraw.ts +0 -1
- package/cli/commands/viewVault.ts +4 -4
- package/cli/commands/viewVaultDepositor.ts +0 -1
- package/cli/commands/withdraw.ts +0 -1
- package/cli/utils.ts +15 -8
- package/lib/accountSubscribers/index.js +5 -1
- package/lib/accounts/index.js +5 -1
- package/lib/accounts/vaultAccount.js +1 -1
- package/lib/accounts/vaultDepositorAccount.js +1 -1
- package/lib/addresses.js +5 -1
- package/lib/index.js +5 -1
- package/lib/parsers/index.js +5 -1
- package/lib/parsers/logParser.d.ts +1 -1
- package/lib/types/drift_vaults.d.ts +113 -1
- package/lib/types/drift_vaults.js +112 -0
- package/lib/types/types.d.ts +13 -13
- package/lib/utils.js +6 -2
- package/lib/vaultClient.d.ts +22 -0
- package/lib/vaultClient.js +85 -24
- package/package.json +2 -4
- package/src/idl/drift_vaults.json +112 -0
- package/src/types/drift_vaults.ts +224 -0
- package/src/vaultClient.ts +97 -0
|
@@ -18,13 +18,13 @@ export const viewVault = async (program: Command, cmdOpts: OptionValues) => {
|
|
|
18
18
|
|
|
19
19
|
const {
|
|
20
20
|
driftVault
|
|
21
|
-
} = await getCommandContext(program,
|
|
21
|
+
} = await getCommandContext(program, false);
|
|
22
22
|
|
|
23
23
|
const vault = await driftVault.getVault(address);
|
|
24
|
-
printVault(vault);
|
|
24
|
+
const { managerSharePct } = printVault(vault);
|
|
25
25
|
const vaultEquity = await driftVault.calculateVaultEquity({
|
|
26
26
|
vault,
|
|
27
27
|
});
|
|
28
|
-
console.log(`vaultEquity:
|
|
29
|
-
console.log(
|
|
28
|
+
console.log(`vaultEquity: $${convertToNumber(vaultEquity, QUOTE_PRECISION)}`);
|
|
29
|
+
console.log(`manager share: $${managerSharePct * convertToNumber(vaultEquity, QUOTE_PRECISION)}`);
|
|
30
30
|
};
|
package/cli/commands/withdraw.ts
CHANGED
package/cli/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DriftClient,
|
|
2
|
-
import { Vault, VaultClient, decodeName } from "../src";
|
|
1
|
+
import { DriftClient, Wallet, loadKeypair } from "@drift-labs/sdk";
|
|
2
|
+
import { VAULT_PROGRAM_ID, Vault, VaultClient, decodeName } from "../src";
|
|
3
3
|
import { Command } from "commander";
|
|
4
4
|
import { Connection, Keypair } from "@solana/web3.js";
|
|
5
5
|
import { AnchorProvider } from "@coral-xyz/anchor";
|
|
@@ -18,7 +18,8 @@ export function printVault(vault: Vault) {
|
|
|
18
18
|
console.log(`userShares: ${vault.userShares.toString()}`);
|
|
19
19
|
console.log(`totalShares: ${vault.totalShares.toString()}`);
|
|
20
20
|
const managerShares = vault.totalShares.sub(vault.userShares);
|
|
21
|
-
|
|
21
|
+
const managerSharePct = managerShares.toNumber() / vault.totalShares.toNumber();
|
|
22
|
+
console.log(` [managerShares]: ${managerShares.toString()} (${(managerSharePct * 100.0).toFixed(4)}%)`);
|
|
22
23
|
console.log(`totalShares: ${vault.totalShares.toString()}`);
|
|
23
24
|
console.log(`lastFeeUpdateTs: ${vault.lastFeeUpdateTs.toString()}`);
|
|
24
25
|
console.log(`liquidationStartTs: ${vault.liquidationStartTs.toString()}`);
|
|
@@ -46,6 +47,11 @@ export function printVault(vault: Vault) {
|
|
|
46
47
|
console.log(`hurdleRate: ${vault.hurdleRate}`);
|
|
47
48
|
console.log(`spotMarketIndex: ${vault.spotMarketIndex}`);
|
|
48
49
|
console.log(`permissioned: ${vault.permissioned}`);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
managerShares,
|
|
53
|
+
managerSharePct,
|
|
54
|
+
};
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
export function printVaultDepositor(vaultDepositor) {
|
|
@@ -53,9 +59,9 @@ export function printVaultDepositor(vaultDepositor) {
|
|
|
53
59
|
console.log(`pubkey: ${vaultDepositor.pubkey.toBase58()}`);
|
|
54
60
|
console.log(`authority: ${vaultDepositor.authority.toBase58()}`);
|
|
55
61
|
console.log(`vaultShares: ${vaultDepositor.vaultShares.toString()}`);
|
|
56
|
-
console.log(`
|
|
57
|
-
console.log(`
|
|
58
|
-
console.log(`
|
|
62
|
+
console.log(`lastWithdrawRequest.Shares: ${vaultDepositor.lastWithdrawRequest.shares.toString()}`);
|
|
63
|
+
console.log(`lastWithdrawRequest.Value: ${vaultDepositor.lastWithdrawRequest.value.toString()}`);
|
|
64
|
+
console.log(`lastWithdrawRequest.Ts: ${vaultDepositor.lastWithdrawRequest.ts.toString()}`);
|
|
59
65
|
console.log(`lastValidTs: ${vaultDepositor.lastValidTs.toString()}`);
|
|
60
66
|
console.log(`netDeposits: ${vaultDepositor.netDeposits.toString()}`);
|
|
61
67
|
console.log(`totalDeposits: ${vaultDepositor.totalDeposits.toString()}`);
|
|
@@ -74,6 +80,7 @@ export async function getCommandContext(program: Command, needToSign: boolean):
|
|
|
74
80
|
let keypair: Keypair;
|
|
75
81
|
if (needToSign) {
|
|
76
82
|
try {
|
|
83
|
+
console.log(opts.keypair);
|
|
77
84
|
keypair = loadKeypair(opts.keypair as string);
|
|
78
85
|
} catch (e) {
|
|
79
86
|
console.error(`Need to provide a valid keypair: ${e}`);
|
|
@@ -86,7 +93,7 @@ export async function getCommandContext(program: Command, needToSign: boolean):
|
|
|
86
93
|
const wallet = new Wallet(keypair);
|
|
87
94
|
console.log(`Signing wallet address (need to sign: ${needToSign}): `, wallet.publicKey.toBase58());
|
|
88
95
|
|
|
89
|
-
const connection = new Connection(opts.
|
|
96
|
+
const connection = new Connection(opts.url, {
|
|
90
97
|
commitment: opts.commitment,
|
|
91
98
|
});
|
|
92
99
|
const driftClient = new DriftClient({
|
|
@@ -103,7 +110,7 @@ export async function getCommandContext(program: Command, needToSign: boolean):
|
|
|
103
110
|
|
|
104
111
|
const provider = new AnchorProvider(connection, wallet, {});
|
|
105
112
|
anchor.setProvider(provider);
|
|
106
|
-
const vaultProgramId =
|
|
113
|
+
const vaultProgramId = VAULT_PROGRAM_ID;
|
|
107
114
|
const vaultProgram = new anchor.Program(IDL, vaultProgramId, provider);
|
|
108
115
|
|
|
109
116
|
const driftVault = new VaultClient({
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/accounts/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -18,7 +18,7 @@ class VaultAccount extends vaultsProgramAccount_1.VaultsProgramAccount {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
static getAddressSync(programId, vaultName) {
|
|
21
|
-
return addresses_1.getVaultAddressSync(programId, name_1.encodeName(vaultName));
|
|
21
|
+
return (0, addresses_1.getVaultAddressSync)(programId, (0, name_1.encodeName)(vaultName));
|
|
22
22
|
}
|
|
23
23
|
calcSharesAfterManagementFee(vaultEquity) {
|
|
24
24
|
const accountData = this.accountSubscriber.getAccountAndSlot().data;
|
|
@@ -17,7 +17,7 @@ class VaultDepositorAccount extends vaultsProgramAccount_1.VaultsProgramAccount
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
static getAddressSync(programId, vault, authority) {
|
|
20
|
-
return addresses_1.getVaultDepositorAddressSync(programId, vault, authority);
|
|
20
|
+
return (0, addresses_1.getVaultDepositorAddressSync)(programId, vault, authority);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Calculates the percentage of a depositor's equity that will be paid as profit share fees.
|
package/lib/addresses.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/parsers/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type DriftVaults = {
|
|
2
2
|
version: '0.1.0';
|
|
3
3
|
name: 'drift_vaults';
|
|
4
4
|
instructions: [
|
|
@@ -789,6 +789,118 @@ export declare type DriftVaults = {
|
|
|
789
789
|
}
|
|
790
790
|
];
|
|
791
791
|
args: [];
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
name: 'initializeInsuranceFundStake';
|
|
795
|
+
accounts: [
|
|
796
|
+
{
|
|
797
|
+
name: 'vault';
|
|
798
|
+
isMut: true;
|
|
799
|
+
isSigner: false;
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
name: 'manager';
|
|
803
|
+
isMut: false;
|
|
804
|
+
isSigner: true;
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
name: 'payer';
|
|
808
|
+
isMut: true;
|
|
809
|
+
isSigner: true;
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
name: 'rent';
|
|
813
|
+
isMut: false;
|
|
814
|
+
isSigner: false;
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
name: 'systemProgram';
|
|
818
|
+
isMut: false;
|
|
819
|
+
isSigner: false;
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
name: 'driftSpotMarket';
|
|
823
|
+
isMut: false;
|
|
824
|
+
isSigner: false;
|
|
825
|
+
},
|
|
826
|
+
{
|
|
827
|
+
name: 'insuranceFundStake';
|
|
828
|
+
isMut: true;
|
|
829
|
+
isSigner: false;
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
name: 'driftUserStats';
|
|
833
|
+
isMut: true;
|
|
834
|
+
isSigner: false;
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
name: 'driftState';
|
|
838
|
+
isMut: false;
|
|
839
|
+
isSigner: false;
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
name: 'driftProgram';
|
|
843
|
+
isMut: false;
|
|
844
|
+
isSigner: false;
|
|
845
|
+
}
|
|
846
|
+
];
|
|
847
|
+
args: [
|
|
848
|
+
{
|
|
849
|
+
name: 'marketIndex';
|
|
850
|
+
type: 'u16';
|
|
851
|
+
}
|
|
852
|
+
];
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
name: 'initializeCompetitor';
|
|
856
|
+
accounts: [
|
|
857
|
+
{
|
|
858
|
+
name: 'vault';
|
|
859
|
+
isMut: true;
|
|
860
|
+
isSigner: false;
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
name: 'manager';
|
|
864
|
+
isMut: false;
|
|
865
|
+
isSigner: true;
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
name: 'payer';
|
|
869
|
+
isMut: true;
|
|
870
|
+
isSigner: true;
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
name: 'rent';
|
|
874
|
+
isMut: false;
|
|
875
|
+
isSigner: false;
|
|
876
|
+
},
|
|
877
|
+
{
|
|
878
|
+
name: 'systemProgram';
|
|
879
|
+
isMut: false;
|
|
880
|
+
isSigner: false;
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
name: 'competitor';
|
|
884
|
+
isMut: true;
|
|
885
|
+
isSigner: false;
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
name: 'driftCompetitions';
|
|
889
|
+
isMut: true;
|
|
890
|
+
isSigner: false;
|
|
891
|
+
},
|
|
892
|
+
{
|
|
893
|
+
name: 'driftUserStats';
|
|
894
|
+
isMut: true;
|
|
895
|
+
isSigner: false;
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
name: 'driftCompetitionsProgram';
|
|
899
|
+
isMut: false;
|
|
900
|
+
isSigner: false;
|
|
901
|
+
}
|
|
902
|
+
];
|
|
903
|
+
args: [];
|
|
792
904
|
}
|
|
793
905
|
];
|
|
794
906
|
accounts: [
|
|
@@ -793,6 +793,118 @@ exports.IDL = {
|
|
|
793
793
|
],
|
|
794
794
|
args: [],
|
|
795
795
|
},
|
|
796
|
+
{
|
|
797
|
+
name: 'initializeInsuranceFundStake',
|
|
798
|
+
accounts: [
|
|
799
|
+
{
|
|
800
|
+
name: 'vault',
|
|
801
|
+
isMut: true,
|
|
802
|
+
isSigner: false,
|
|
803
|
+
},
|
|
804
|
+
{
|
|
805
|
+
name: 'manager',
|
|
806
|
+
isMut: false,
|
|
807
|
+
isSigner: true,
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
name: 'payer',
|
|
811
|
+
isMut: true,
|
|
812
|
+
isSigner: true,
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
name: 'rent',
|
|
816
|
+
isMut: false,
|
|
817
|
+
isSigner: false,
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
name: 'systemProgram',
|
|
821
|
+
isMut: false,
|
|
822
|
+
isSigner: false,
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
name: 'driftSpotMarket',
|
|
826
|
+
isMut: false,
|
|
827
|
+
isSigner: false,
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
name: 'insuranceFundStake',
|
|
831
|
+
isMut: true,
|
|
832
|
+
isSigner: false,
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
name: 'driftUserStats',
|
|
836
|
+
isMut: true,
|
|
837
|
+
isSigner: false,
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
name: 'driftState',
|
|
841
|
+
isMut: false,
|
|
842
|
+
isSigner: false,
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
name: 'driftProgram',
|
|
846
|
+
isMut: false,
|
|
847
|
+
isSigner: false,
|
|
848
|
+
},
|
|
849
|
+
],
|
|
850
|
+
args: [
|
|
851
|
+
{
|
|
852
|
+
name: 'marketIndex',
|
|
853
|
+
type: 'u16',
|
|
854
|
+
},
|
|
855
|
+
],
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
name: 'initializeCompetitor',
|
|
859
|
+
accounts: [
|
|
860
|
+
{
|
|
861
|
+
name: 'vault',
|
|
862
|
+
isMut: true,
|
|
863
|
+
isSigner: false,
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
name: 'manager',
|
|
867
|
+
isMut: false,
|
|
868
|
+
isSigner: true,
|
|
869
|
+
},
|
|
870
|
+
{
|
|
871
|
+
name: 'payer',
|
|
872
|
+
isMut: true,
|
|
873
|
+
isSigner: true,
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
name: 'rent',
|
|
877
|
+
isMut: false,
|
|
878
|
+
isSigner: false,
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
name: 'systemProgram',
|
|
882
|
+
isMut: false,
|
|
883
|
+
isSigner: false,
|
|
884
|
+
},
|
|
885
|
+
{
|
|
886
|
+
name: 'competitor',
|
|
887
|
+
isMut: true,
|
|
888
|
+
isSigner: false,
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
name: 'driftCompetitions',
|
|
892
|
+
isMut: true,
|
|
893
|
+
isSigner: false,
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
name: 'driftUserStats',
|
|
897
|
+
isMut: true,
|
|
898
|
+
isSigner: false,
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
name: 'driftCompetitionsProgram',
|
|
902
|
+
isMut: false,
|
|
903
|
+
isSigner: false,
|
|
904
|
+
},
|
|
905
|
+
],
|
|
906
|
+
args: [],
|
|
907
|
+
},
|
|
796
908
|
],
|
|
797
909
|
accounts: [
|
|
798
910
|
{
|
package/lib/types/types.d.ts
CHANGED
|
@@ -16,12 +16,12 @@ export declare class WithdrawUnit {
|
|
|
16
16
|
sharesPercent: {};
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export type WithdrawRequest = {
|
|
20
20
|
shares: BN;
|
|
21
21
|
value: BN;
|
|
22
22
|
ts: BN;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type Vault = {
|
|
25
25
|
name: number[];
|
|
26
26
|
pubkey: PublicKey;
|
|
27
27
|
manager: PublicKey;
|
|
@@ -56,7 +56,7 @@ export declare type Vault = {
|
|
|
56
56
|
permissioned: boolean;
|
|
57
57
|
lastManagerWithdrawRequest: WithdrawRequest;
|
|
58
58
|
};
|
|
59
|
-
export
|
|
59
|
+
export type VaultDepositor = {
|
|
60
60
|
vault: PublicKey;
|
|
61
61
|
pubkey: PublicKey;
|
|
62
62
|
authority: PublicKey;
|
|
@@ -71,14 +71,14 @@ export declare type VaultDepositor = {
|
|
|
71
71
|
profitShareFeePaid: BN;
|
|
72
72
|
padding: number[];
|
|
73
73
|
};
|
|
74
|
-
export
|
|
74
|
+
export type VaultsProgramAccountBaseEvents = {
|
|
75
75
|
update: void;
|
|
76
76
|
error: (e: Error) => void;
|
|
77
77
|
};
|
|
78
|
-
export
|
|
78
|
+
export type VaultDepositorAccountEvents = {
|
|
79
79
|
vaultDepositorUpdate: (payload: VaultDepositor) => void;
|
|
80
80
|
} & VaultsProgramAccountBaseEvents;
|
|
81
|
-
export
|
|
81
|
+
export type VaultAccountEvents = {
|
|
82
82
|
vaultUpdate: (payload: Vault) => void;
|
|
83
83
|
} & VaultsProgramAccountBaseEvents;
|
|
84
84
|
export interface VaultsProgramAccountSubscriber<Account, AccountEvents extends VaultsProgramAccountBaseEvents> {
|
|
@@ -90,8 +90,8 @@ export interface VaultsProgramAccountSubscriber<Account, AccountEvents extends V
|
|
|
90
90
|
unsubscribe(): Promise<void>;
|
|
91
91
|
getAccountAndSlot(): DataAndSlot<Account>;
|
|
92
92
|
}
|
|
93
|
-
export
|
|
94
|
-
export
|
|
93
|
+
export type VaultAccountSubscriber = VaultsProgramAccountSubscriber<Vault, VaultAccountEvents>;
|
|
94
|
+
export type VaultDepositorAccountSubscriber = VaultsProgramAccountSubscriber<VaultDepositor, VaultDepositorAccountEvents>;
|
|
95
95
|
export declare class VaultDepositorAction {
|
|
96
96
|
static readonly DEPOSIT: {
|
|
97
97
|
deposit: {};
|
|
@@ -109,7 +109,7 @@ export declare class VaultDepositorAction {
|
|
|
109
109
|
feePayment: {};
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
export
|
|
112
|
+
export type VaultDepositorRecord = {
|
|
113
113
|
ts: BN;
|
|
114
114
|
vault: PublicKey;
|
|
115
115
|
depositorAuthority: PublicKey;
|
|
@@ -127,11 +127,11 @@ export declare type VaultDepositorRecord = {
|
|
|
127
127
|
managementFee: BN;
|
|
128
128
|
managementFeeShares: BN;
|
|
129
129
|
};
|
|
130
|
-
export
|
|
130
|
+
export type VaultsEventMap = {
|
|
131
131
|
VaultDepositorRecord: Event<VaultDepositorRecord>;
|
|
132
132
|
};
|
|
133
|
-
export
|
|
134
|
-
export
|
|
133
|
+
export type EventType = keyof VaultsEventMap;
|
|
134
|
+
export type WrappedEvent<Type extends EventType> = VaultsEventMap[Type] & {
|
|
135
135
|
eventType: Type;
|
|
136
136
|
};
|
|
137
|
-
export
|
|
137
|
+
export type WrappedEvents = WrappedEvent<EventType>[];
|
package/lib/utils.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -33,7 +37,7 @@ const getDriftVaultProgram = (connection, wallet) => {
|
|
|
33
37
|
};
|
|
34
38
|
exports.getDriftVaultProgram = getDriftVaultProgram;
|
|
35
39
|
const getVaultClient = (connection, wallet, driftClient) => {
|
|
36
|
-
const vaultProgram = exports.getDriftVaultProgram(connection, wallet);
|
|
40
|
+
const vaultProgram = (0, exports.getDriftVaultProgram)(connection, wallet);
|
|
37
41
|
const vaultClient = new vaultClient_1.VaultClient({
|
|
38
42
|
driftClient,
|
|
39
43
|
program: vaultProgram,
|
package/lib/vaultClient.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { BN, DriftClient } from '@drift-labs/sdk';
|
|
3
3
|
import { Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
4
4
|
import { DriftVaults } from './types/drift_vaults';
|
|
5
|
+
import { CompetitionsClient } from '@drift-labs/competitions-sdk/lib/competitionClient';
|
|
5
6
|
import { PublicKey, SetComputeUnitLimitParams, TransactionInstruction, TransactionSignature } from '@solana/web3.js';
|
|
6
7
|
import { Vault, VaultDepositor, WithdrawUnit } from './types/types';
|
|
7
8
|
export declare class VaultClient {
|
|
@@ -44,6 +45,13 @@ export declare class VaultClient {
|
|
|
44
45
|
* @returns
|
|
45
46
|
*/
|
|
46
47
|
updateDelegate(vault: PublicKey, delegate: PublicKey): Promise<TransactionSignature>;
|
|
48
|
+
/**
|
|
49
|
+
* Updates the vault margin trading status.
|
|
50
|
+
* @param vault vault address to update
|
|
51
|
+
* @param enabeld whether to enable margin trading
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
updateMarginTradingEnabled(vault: PublicKey, enabled: boolean): Promise<TransactionSignature>;
|
|
47
55
|
/**
|
|
48
56
|
*
|
|
49
57
|
* @param vault vault address to deposit to
|
|
@@ -97,4 +105,18 @@ export declare class VaultClient {
|
|
|
97
105
|
* Used for UI wallet adapters compatibility
|
|
98
106
|
*/
|
|
99
107
|
createAndSendTxn(ixs: TransactionInstruction[], computeUnitParams?: SetComputeUnitLimitParams): Promise<TransactionSignature>;
|
|
108
|
+
/**
|
|
109
|
+
* Initializes an insurance fund stake for the vault.
|
|
110
|
+
* @param vault vault address to update
|
|
111
|
+
* @param spotMarketIndex spot market index of the insurance fund stake
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
114
|
+
initializeInsuranceFundStake(vault: PublicKey, spotMarketIndex: number): Promise<TransactionSignature>;
|
|
115
|
+
/**
|
|
116
|
+
* Initializes a DriftCompetitions Competitor account for the vault.
|
|
117
|
+
* @param vault vault address to initialize Competitor for
|
|
118
|
+
* @param competitionName name of the competition to initialize for
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
initializeCompetitor(vault: PublicKey, competitionsClient: CompetitionsClient, competitionName: string): Promise<TransactionSignature>;
|
|
100
122
|
}
|