@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
package/src/vaultClient.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BN,
|
|
3
3
|
DriftClient,
|
|
4
|
+
encodeName,
|
|
5
|
+
getInsuranceFundStakeAccountPublicKey,
|
|
4
6
|
getUserAccountPublicKey,
|
|
5
7
|
getUserAccountPublicKeySync,
|
|
6
8
|
getUserStatsAccountPublicKey,
|
|
@@ -8,6 +10,11 @@ import {
|
|
|
8
10
|
} from '@drift-labs/sdk';
|
|
9
11
|
import { BorshAccountsCoder, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
10
12
|
import { DriftVaults } from './types/drift_vaults';
|
|
13
|
+
import {
|
|
14
|
+
getCompetitionAddressSync,
|
|
15
|
+
getCompetitorAddressSync,
|
|
16
|
+
} from '@drift-labs/competitions-sdk/lib/addresses';
|
|
17
|
+
import { CompetitionsClient } from '@drift-labs/competitions-sdk/lib/competitionClient';
|
|
11
18
|
import {
|
|
12
19
|
getTokenVaultAddressSync,
|
|
13
20
|
getVaultAddressSync,
|
|
@@ -191,6 +198,27 @@ export class VaultClient {
|
|
|
191
198
|
.rpc();
|
|
192
199
|
}
|
|
193
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Updates the vault margin trading status.
|
|
203
|
+
* @param vault vault address to update
|
|
204
|
+
* @param enabeld whether to enable margin trading
|
|
205
|
+
* @returns
|
|
206
|
+
*/
|
|
207
|
+
public async updateMarginTradingEnabled(
|
|
208
|
+
vault: PublicKey,
|
|
209
|
+
enabled: boolean
|
|
210
|
+
): Promise<TransactionSignature> {
|
|
211
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
212
|
+
return await this.program.methods
|
|
213
|
+
.updateMarginTradingEnabled(enabled)
|
|
214
|
+
.accounts({
|
|
215
|
+
vault: vault,
|
|
216
|
+
driftUser: vaultAccount.user,
|
|
217
|
+
driftProgram: this.driftClient.program.programId,
|
|
218
|
+
})
|
|
219
|
+
.rpc();
|
|
220
|
+
}
|
|
221
|
+
|
|
194
222
|
/**
|
|
195
223
|
*
|
|
196
224
|
* @param vault vault address to deposit to
|
|
@@ -901,4 +929,73 @@ export class VaultClient {
|
|
|
901
929
|
|
|
902
930
|
return txSig;
|
|
903
931
|
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Initializes an insurance fund stake for the vault.
|
|
935
|
+
* @param vault vault address to update
|
|
936
|
+
* @param spotMarketIndex spot market index of the insurance fund stake
|
|
937
|
+
* @returns
|
|
938
|
+
*/
|
|
939
|
+
public async initializeInsuranceFundStake(
|
|
940
|
+
vault: PublicKey,
|
|
941
|
+
spotMarketIndex: number
|
|
942
|
+
): Promise<TransactionSignature> {
|
|
943
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
944
|
+
|
|
945
|
+
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
946
|
+
this.driftClient.program.programId,
|
|
947
|
+
vault,
|
|
948
|
+
spotMarketIndex
|
|
949
|
+
);
|
|
950
|
+
|
|
951
|
+
return await this.program.methods
|
|
952
|
+
.initializeInsuranceFundStake(spotMarketIndex)
|
|
953
|
+
.accounts({
|
|
954
|
+
vault: vault,
|
|
955
|
+
driftSpotMarket:
|
|
956
|
+
this.driftClient.getSpotMarketAccount(spotMarketIndex).pubkey,
|
|
957
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
958
|
+
driftUserStats: vaultAccount.userStats,
|
|
959
|
+
driftState: await this.driftClient.getStatePublicKey(),
|
|
960
|
+
driftProgram: this.driftClient.program.programId,
|
|
961
|
+
})
|
|
962
|
+
.rpc();
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Initializes a DriftCompetitions Competitor account for the vault.
|
|
967
|
+
* @param vault vault address to initialize Competitor for
|
|
968
|
+
* @param competitionName name of the competition to initialize for
|
|
969
|
+
* @returns
|
|
970
|
+
*/
|
|
971
|
+
public async initializeCompetitor(
|
|
972
|
+
vault: PublicKey,
|
|
973
|
+
competitionsClient: CompetitionsClient,
|
|
974
|
+
competitionName: string
|
|
975
|
+
): Promise<TransactionSignature> {
|
|
976
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
977
|
+
|
|
978
|
+
const encodedName = encodeName(competitionName);
|
|
979
|
+
|
|
980
|
+
const competitionAddress = getCompetitionAddressSync(
|
|
981
|
+
competitionsClient.program.programId,
|
|
982
|
+
encodedName
|
|
983
|
+
);
|
|
984
|
+
const competitorAddress = getCompetitorAddressSync(
|
|
985
|
+
competitionsClient.program.programId,
|
|
986
|
+
competitionAddress,
|
|
987
|
+
vault
|
|
988
|
+
);
|
|
989
|
+
|
|
990
|
+
return await this.program.methods
|
|
991
|
+
.initializeCompetitor()
|
|
992
|
+
.accounts({
|
|
993
|
+
vault: vault,
|
|
994
|
+
competitor: competitorAddress,
|
|
995
|
+
driftCompetitions: competitionAddress,
|
|
996
|
+
driftUserStats: vaultAccount.userStats,
|
|
997
|
+
driftCompetitionsProgram: competitionsClient.program.programId,
|
|
998
|
+
})
|
|
999
|
+
.rpc();
|
|
1000
|
+
}
|
|
904
1001
|
}
|