@drift-labs/vaults-sdk 0.1.532 → 0.1.534
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/lib/addresses.d.ts +1 -0
- package/lib/addresses.js +8 -0
- package/lib/types/drift_vaults.d.ts +262 -0
- package/lib/types/drift_vaults.js +262 -0
- package/lib/vaultClient.d.ts +11 -0
- package/lib/vaultClient.js +114 -0
- package/package.json +1 -1
- package/src/addresses.ts +15 -0
- package/src/idl/drift_vaults.json +262 -0
- package/src/types/drift_vaults.ts +524 -0
- package/src/vaultClient.ts +205 -0
package/src/vaultClient.ts
CHANGED
|
@@ -9,12 +9,14 @@ import {
|
|
|
9
9
|
UserMap,
|
|
10
10
|
unstakeSharesToAmount as depositSharesToVaultAmount,
|
|
11
11
|
ZERO,
|
|
12
|
+
getInsuranceFundVaultPublicKey,
|
|
12
13
|
} from '@drift-labs/sdk';
|
|
13
14
|
import { BorshAccountsCoder, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
14
15
|
import { DriftVaults } from './types/drift_vaults';
|
|
15
16
|
import {
|
|
16
17
|
getTokenizedVaultAddressSync,
|
|
17
18
|
getTokenizedVaultMintAddressSync,
|
|
19
|
+
getInsuranceFundTokenVaultAddressSync,
|
|
18
20
|
getTokenVaultAddressSync,
|
|
19
21
|
getVaultAddressSync,
|
|
20
22
|
getVaultDepositorAddressSync,
|
|
@@ -1994,11 +1996,19 @@ export class VaultClient {
|
|
|
1994
1996
|
);
|
|
1995
1997
|
}
|
|
1996
1998
|
|
|
1999
|
+
const ifVaultTokenAccount = getInsuranceFundTokenVaultAddressSync(
|
|
2000
|
+
this.program.programId,
|
|
2001
|
+
vault,
|
|
2002
|
+
spotMarketIndex
|
|
2003
|
+
);
|
|
2004
|
+
|
|
1997
2005
|
return await this.program.methods
|
|
1998
2006
|
.initializeInsuranceFundStake(spotMarketIndex)
|
|
1999
2007
|
.accounts({
|
|
2000
2008
|
vault: vault,
|
|
2001
2009
|
driftSpotMarket: spotMarket.pubkey,
|
|
2010
|
+
driftSpotMarketMint: spotMarket.mint,
|
|
2011
|
+
vaultTokenAccount: ifVaultTokenAccount,
|
|
2002
2012
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2003
2013
|
driftUserStats: vaultAccount.userStats,
|
|
2004
2014
|
driftState: await this.driftClient.getStatePublicKey(),
|
|
@@ -2007,6 +2017,201 @@ export class VaultClient {
|
|
|
2007
2017
|
.rpc();
|
|
2008
2018
|
}
|
|
2009
2019
|
|
|
2020
|
+
/**
|
|
2021
|
+
* Adds an amount to an insurance fund stake for the vault.
|
|
2022
|
+
* @param vault vault address to update
|
|
2023
|
+
* @param spotMarketIndex spot market index of the insurance fund stake
|
|
2024
|
+
* @param amount amount to add to the insurance fund stake, in spotMarketIndex precision
|
|
2025
|
+
* @returns
|
|
2026
|
+
*/
|
|
2027
|
+
public async addToInsuranceFundStake(
|
|
2028
|
+
vault: PublicKey,
|
|
2029
|
+
spotMarketIndex: number,
|
|
2030
|
+
amount: BN,
|
|
2031
|
+
managerTokenAccount?: PublicKey
|
|
2032
|
+
): Promise<TransactionSignature> {
|
|
2033
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2034
|
+
|
|
2035
|
+
if (!vaultAccount.manager.equals(this.driftClient.wallet.publicKey)) {
|
|
2036
|
+
throw new Error(
|
|
2037
|
+
`Only the manager of the vault can add to the insurance fund stake.`
|
|
2038
|
+
);
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2042
|
+
this.driftClient.program.programId,
|
|
2043
|
+
vault,
|
|
2044
|
+
spotMarketIndex
|
|
2045
|
+
);
|
|
2046
|
+
const ifVaultPublicKey = await getInsuranceFundVaultPublicKey(
|
|
2047
|
+
this.driftClient.program.programId,
|
|
2048
|
+
spotMarketIndex
|
|
2049
|
+
);
|
|
2050
|
+
|
|
2051
|
+
const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
|
|
2052
|
+
if (!spotMarket) {
|
|
2053
|
+
throw new Error(
|
|
2054
|
+
`Spot market ${spotMarketIndex} not found on driftClient`
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
if (!managerTokenAccount) {
|
|
2059
|
+
managerTokenAccount = getAssociatedTokenAddressSync(
|
|
2060
|
+
spotMarket.mint,
|
|
2061
|
+
this.driftClient.wallet.publicKey
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
const ifVaultTokenAccount = getInsuranceFundTokenVaultAddressSync(
|
|
2066
|
+
this.program.programId,
|
|
2067
|
+
vault,
|
|
2068
|
+
spotMarketIndex
|
|
2069
|
+
);
|
|
2070
|
+
|
|
2071
|
+
return await this.program.methods
|
|
2072
|
+
.addInsuranceFundStake(spotMarketIndex, amount)
|
|
2073
|
+
.accounts({
|
|
2074
|
+
vault: vault,
|
|
2075
|
+
driftSpotMarket: spotMarket.pubkey,
|
|
2076
|
+
driftSpotMarketVault: spotMarket.vault,
|
|
2077
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2078
|
+
insuranceFundVault: ifVaultPublicKey,
|
|
2079
|
+
managerTokenAccount,
|
|
2080
|
+
vaultIfTokenAccount: ifVaultTokenAccount,
|
|
2081
|
+
driftUserStats: vaultAccount.userStats,
|
|
2082
|
+
driftState: await this.driftClient.getStatePublicKey(),
|
|
2083
|
+
driftProgram: this.driftClient.program.programId,
|
|
2084
|
+
driftSigner: this.driftClient.getStateAccount().signer,
|
|
2085
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2086
|
+
})
|
|
2087
|
+
.rpc();
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
public async requestRemoveInsuranceFundStake(
|
|
2091
|
+
vault: PublicKey,
|
|
2092
|
+
spotMarketIndex: number,
|
|
2093
|
+
amount: BN
|
|
2094
|
+
): Promise<TransactionSignature> {
|
|
2095
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2096
|
+
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2097
|
+
this.driftClient.program.programId,
|
|
2098
|
+
vault,
|
|
2099
|
+
spotMarketIndex
|
|
2100
|
+
);
|
|
2101
|
+
const ifVaultPublicKey = await getInsuranceFundVaultPublicKey(
|
|
2102
|
+
this.driftClient.program.programId,
|
|
2103
|
+
spotMarketIndex
|
|
2104
|
+
);
|
|
2105
|
+
|
|
2106
|
+
const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
|
|
2107
|
+
if (!spotMarket) {
|
|
2108
|
+
throw new Error(
|
|
2109
|
+
`Spot market ${spotMarketIndex} not found on driftClient`
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
return await this.program.methods
|
|
2114
|
+
.requestRemoveInsuranceFundStake(spotMarketIndex, amount)
|
|
2115
|
+
.accounts({
|
|
2116
|
+
vault,
|
|
2117
|
+
manager: this.driftClient.wallet.publicKey,
|
|
2118
|
+
driftSpotMarket: spotMarket.pubkey,
|
|
2119
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2120
|
+
insuranceFundVault: ifVaultPublicKey,
|
|
2121
|
+
driftUserStats: vaultAccount.userStats,
|
|
2122
|
+
driftProgram: this.driftClient.program.programId,
|
|
2123
|
+
})
|
|
2124
|
+
.rpc();
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
public async cancelRequestRemoveInsuranceFundStake(
|
|
2128
|
+
vault: PublicKey,
|
|
2129
|
+
spotMarketIndex: number
|
|
2130
|
+
): Promise<TransactionSignature> {
|
|
2131
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2132
|
+
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2133
|
+
this.driftClient.program.programId,
|
|
2134
|
+
vault,
|
|
2135
|
+
spotMarketIndex
|
|
2136
|
+
);
|
|
2137
|
+
const ifVaultPublicKey = await getInsuranceFundVaultPublicKey(
|
|
2138
|
+
this.driftClient.program.programId,
|
|
2139
|
+
spotMarketIndex
|
|
2140
|
+
);
|
|
2141
|
+
const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
|
|
2142
|
+
if (!spotMarket) {
|
|
2143
|
+
throw new Error(
|
|
2144
|
+
`Spot market ${spotMarketIndex} not found on driftClient`
|
|
2145
|
+
);
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
return await this.program.methods
|
|
2149
|
+
.cancelRequestRemoveInsuranceFundStake(spotMarketIndex)
|
|
2150
|
+
.accounts({
|
|
2151
|
+
vault: vault,
|
|
2152
|
+
manager: this.driftClient.wallet.publicKey,
|
|
2153
|
+
driftSpotMarket: spotMarket.pubkey,
|
|
2154
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2155
|
+
insuranceFundVault: ifVaultPublicKey,
|
|
2156
|
+
driftUserStats: vaultAccount.userStats,
|
|
2157
|
+
driftProgram: this.driftClient.program.programId,
|
|
2158
|
+
})
|
|
2159
|
+
.rpc();
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
public async removeInsuranceFundStake(
|
|
2163
|
+
vault: PublicKey,
|
|
2164
|
+
spotMarketIndex: number,
|
|
2165
|
+
managerTokenAccount?: PublicKey
|
|
2166
|
+
): Promise<TransactionSignature> {
|
|
2167
|
+
const vaultAccount = await this.program.account.vault.fetch(vault);
|
|
2168
|
+
const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey(
|
|
2169
|
+
this.driftClient.program.programId,
|
|
2170
|
+
vault,
|
|
2171
|
+
spotMarketIndex
|
|
2172
|
+
);
|
|
2173
|
+
const ifVaultPublicKey = await getInsuranceFundVaultPublicKey(
|
|
2174
|
+
this.driftClient.program.programId,
|
|
2175
|
+
spotMarketIndex
|
|
2176
|
+
);
|
|
2177
|
+
const spotMarket = this.driftClient.getSpotMarketAccount(spotMarketIndex);
|
|
2178
|
+
if (!spotMarket) {
|
|
2179
|
+
throw new Error(
|
|
2180
|
+
`Spot market ${spotMarketIndex} not found on driftClient`
|
|
2181
|
+
);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
if (!managerTokenAccount) {
|
|
2185
|
+
managerTokenAccount = getAssociatedTokenAddressSync(
|
|
2186
|
+
spotMarket.mint,
|
|
2187
|
+
this.driftClient.wallet.publicKey
|
|
2188
|
+
);
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
const ifVaultTokenAccount = getInsuranceFundTokenVaultAddressSync(
|
|
2192
|
+
this.program.programId,
|
|
2193
|
+
vault,
|
|
2194
|
+
spotMarketIndex
|
|
2195
|
+
);
|
|
2196
|
+
|
|
2197
|
+
return await this.program.methods
|
|
2198
|
+
.removeInsuranceFundStake(spotMarketIndex)
|
|
2199
|
+
.accounts({
|
|
2200
|
+
vault: vault,
|
|
2201
|
+
driftSpotMarket: spotMarket.pubkey,
|
|
2202
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
2203
|
+
insuranceFundVault: ifVaultPublicKey,
|
|
2204
|
+
managerTokenAccount,
|
|
2205
|
+
vaultIfTokenAccount: ifVaultTokenAccount,
|
|
2206
|
+
driftState: await this.driftClient.getStatePublicKey(),
|
|
2207
|
+
driftUserStats: vaultAccount.userStats,
|
|
2208
|
+
driftSigner: this.driftClient.getStateAccount().signer,
|
|
2209
|
+
driftProgram: this.driftClient.program.programId,
|
|
2210
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2211
|
+
})
|
|
2212
|
+
.rpc();
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2010
2215
|
public async protocolRequestWithdraw(
|
|
2011
2216
|
vault: PublicKey,
|
|
2012
2217
|
amount: BN,
|