@drift-labs/sdk 0.2.0-master.24 → 0.2.0-master.26
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/accounts/pollingClearingHouseAccountSubscriber.d.ts +13 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +27 -27
- package/lib/accounts/types.d.ts +8 -9
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +14 -14
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +35 -34
- package/lib/addresses/pda.d.ts +8 -6
- package/lib/addresses/pda.js +35 -27
- package/lib/admin.d.ts +9 -6
- package/lib/admin.js +90 -54
- package/lib/clearingHouse.d.ts +71 -42
- package/lib/clearingHouse.js +765 -282
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +19 -17
- package/lib/clearingHouseUser.js +145 -123
- package/lib/config.d.ts +7 -7
- package/lib/config.js +21 -21
- package/lib/constants/numericConstants.d.ts +12 -12
- package/lib/constants/numericConstants.js +13 -13
- package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
- package/{src/constants/markets.js → lib/constants/perpMarkets.js} +4 -4
- package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
- package/lib/constants/{banks.js → spotMarkets.js} +16 -16
- package/lib/events/eventSubscriber.d.ts +4 -2
- package/lib/events/eventSubscriber.js +16 -9
- package/lib/events/fetchLogs.d.ts +10 -1
- package/lib/events/fetchLogs.js +27 -7
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +6 -2
- package/lib/events/types.d.ts +4 -2
- package/lib/events/types.js +2 -0
- package/lib/examples/makeTradeExample.js +18 -6
- package/lib/idl/clearing_house.json +1128 -347
- package/lib/index.d.ts +6 -3
- package/lib/index.js +6 -3
- package/lib/math/amm.d.ts +5 -3
- package/lib/math/amm.js +42 -4
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +2 -1
- package/lib/math/margin.d.ts +4 -4
- package/lib/math/margin.js +18 -11
- package/lib/math/market.d.ts +10 -9
- package/lib/math/market.js +29 -6
- package/lib/math/oracles.d.ts +2 -1
- package/lib/math/oracles.js +11 -1
- package/lib/math/orders.d.ts +5 -5
- package/lib/math/position.d.ts +13 -13
- package/lib/math/position.js +19 -19
- package/lib/math/spotBalance.d.ts +19 -0
- package/lib/math/spotBalance.js +176 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +2 -0
- package/lib/math/spotPosition.js +8 -0
- package/lib/math/state.js +2 -2
- package/lib/math/trade.d.ts +4 -4
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumSubscriber.d.ts +23 -0
- package/lib/serum/serumSubscriber.js +41 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/serum/types.js +2 -0
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +4 -2
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +148 -39
- package/lib/types.js +37 -9
- package/my-script/.env +7 -0
- package/my-script/getUserStats.ts +106 -0
- package/my-script/multiConnections.ts +119 -0
- package/my-script/test-regex.ts +11 -0
- package/my-script/utils.ts +52 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.js +249 -0
- package/src/accounts/bulkUserStatsSubscription.js +75 -0
- package/src/accounts/bulkUserSubscription.js +75 -0
- package/src/accounts/fetch.js +92 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
- package/src/accounts/pollingOracleSubscriber.js +156 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
- package/src/accounts/pollingUserAccountSubscriber.js +208 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
- package/src/accounts/types.js +28 -0
- package/src/accounts/types.ts +11 -9
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +138 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
- package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
- package/src/addresses/pda.js +186 -0
- package/src/addresses/pda.ts +56 -42
- package/src/admin.js +1284 -0
- package/src/admin.ts +149 -75
- package/src/assert/assert.js +1 -1
- package/src/clearingHouse.js +3433 -0
- package/src/clearingHouse.ts +1097 -380
- package/src/clearingHouseConfig.js +2 -0
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.js +874 -0
- package/src/clearingHouseUser.ts +237 -172
- package/src/clearingHouseUserConfig.js +2 -0
- package/src/clearingHouseUserStats.js +115 -0
- package/src/clearingHouseUserStatsConfig.js +2 -0
- package/src/config.js +80 -0
- package/src/config.ts +30 -30
- package/src/constants/numericConstants.js +18 -11
- package/src/constants/numericConstants.ts +17 -15
- package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
- package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
- package/src/constants/spotMarkets.js +51 -0
- package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
- package/src/events/eventList.js +66 -23
- package/src/events/eventSubscriber.js +202 -0
- package/src/events/eventSubscriber.ts +20 -12
- package/src/events/fetchLogs.js +117 -0
- package/src/events/fetchLogs.ts +35 -8
- package/src/events/pollingLogProvider.js +113 -0
- package/src/events/pollingLogProvider.ts +10 -2
- package/src/events/sort.js +41 -0
- package/src/events/txEventCache.js +22 -19
- package/src/events/types.js +25 -0
- package/src/events/types.ts +7 -1
- package/src/events/webSocketLogProvider.js +76 -0
- package/src/examples/makeTradeExample.ts +27 -6
- package/src/factory/bigNum.js +183 -180
- package/src/factory/oracleClient.js +9 -9
- package/src/idl/clearing_house.json +1128 -347
- package/src/index.js +75 -0
- package/src/index.ts +6 -3
- package/src/math/amm.js +422 -0
- package/src/math/amm.ts +73 -5
- package/src/math/auction.js +10 -10
- package/src/math/conversion.js +4 -3
- package/src/math/funding.js +223 -175
- package/src/math/funding.ts +7 -7
- package/src/math/insurance.js +27 -0
- package/src/math/margin.js +77 -0
- package/src/math/margin.ts +34 -23
- package/src/math/market.js +105 -0
- package/src/math/market.ts +71 -19
- package/src/math/oracles.js +40 -10
- package/src/math/oracles.ts +18 -1
- package/src/math/orders.js +153 -0
- package/src/math/orders.ts +5 -5
- package/src/math/position.js +172 -0
- package/src/math/position.ts +31 -31
- package/src/math/repeg.js +40 -40
- package/src/math/spotBalance.js +176 -0
- package/src/math/spotBalance.ts +290 -0
- package/src/math/spotMarket.js +8 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.js +8 -0
- package/src/math/spotPosition.ts +6 -0
- package/src/math/state.ts +2 -2
- package/src/math/trade.js +81 -74
- package/src/math/trade.ts +4 -4
- package/src/math/utils.js +8 -7
- package/src/oracles/oracleClientCache.js +10 -9
- package/src/oracles/pythClient.js +52 -17
- package/src/oracles/quoteAssetOracleClient.js +44 -13
- package/src/oracles/switchboardClient.js +69 -37
- package/src/oracles/types.js +1 -1
- package/src/orderParams.js +14 -6
- package/src/orderParams.ts +16 -8
- package/src/serum/serumSubscriber.js +102 -0
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.js +2 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.js +67 -20
- package/src/token/index.js +4 -4
- package/src/tokenFaucet.js +288 -154
- package/src/tx/retryTxSender.js +280 -0
- package/src/tx/retryTxSender.ts +5 -2
- package/src/tx/types.js +1 -1
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +7 -6
- package/src/types.js +216 -0
- package/src/types.ts +131 -39
- package/src/userName.js +5 -5
- package/src/util/computeUnits.js +46 -11
- package/src/util/promiseTimeout.js +5 -5
- package/src/util/tps.js +46 -12
- package/src/wallet.js +55 -18
- package/lib/math/bankBalance.d.ts +0 -15
- package/lib/math/bankBalance.js +0 -150
- package/src/addresses/marketAddresses.js +0 -26
- package/src/constants/banks.js +0 -42
- package/src/examples/makeTradeExample.js +0 -80
- package/src/math/bankBalance.ts +0 -258
- package/src/math/state.js +0 -15
- package/src/math/utils.js.map +0 -1
- package/src/util/getTokenAddress.js +0 -9
package/src/admin.ts
CHANGED
|
@@ -13,13 +13,14 @@ import { BN } from '@project-serum/anchor';
|
|
|
13
13
|
import * as anchor from '@project-serum/anchor';
|
|
14
14
|
import {
|
|
15
15
|
getClearingHouseStateAccountPublicKeyAndNonce,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getBankVaultPublicKey,
|
|
16
|
+
getSpotMarketPublicKey,
|
|
17
|
+
getSpotMarketVaultPublicKey,
|
|
19
18
|
getMarketPublicKey,
|
|
20
19
|
getInsuranceFundVaultPublicKey,
|
|
21
|
-
|
|
20
|
+
getSerumOpenOrdersPublicKey,
|
|
21
|
+
getSerumFulfillmentConfigPublicKey,
|
|
22
22
|
} from './addresses/pda';
|
|
23
|
+
import { squareRootBN } from './math/utils';
|
|
23
24
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
24
25
|
import { ClearingHouse } from './clearingHouse';
|
|
25
26
|
import { PEG_PRECISION, ZERO } from './constants/numericConstants';
|
|
@@ -38,20 +39,16 @@ export class Admin extends ClearingHouse {
|
|
|
38
39
|
throw new Error('Clearing house already initialized');
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
const [clearingHouseStatePublicKey] =
|
|
43
|
+
await getClearingHouseStateAccountPublicKeyAndNonce(
|
|
44
|
+
this.program.programId
|
|
45
|
+
);
|
|
46
|
+
|
|
41
47
|
const [insuranceVaultPublicKey] = await PublicKey.findProgramAddress(
|
|
42
48
|
[Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))],
|
|
43
49
|
this.program.programId
|
|
44
50
|
);
|
|
45
51
|
|
|
46
|
-
const [insuranceVaultAuthority] = await PublicKey.findProgramAddress(
|
|
47
|
-
[insuranceVaultPublicKey.toBuffer()],
|
|
48
|
-
this.program.programId
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const [clearingHouseStatePublicKey] =
|
|
52
|
-
await getClearingHouseStateAccountPublicKeyAndNonce(
|
|
53
|
-
this.program.programId
|
|
54
|
-
);
|
|
55
52
|
const initializeTx = await this.program.transaction.initialize(
|
|
56
53
|
adminControlsPrices,
|
|
57
54
|
{
|
|
@@ -59,9 +56,9 @@ export class Admin extends ClearingHouse {
|
|
|
59
56
|
admin: this.wallet.publicKey,
|
|
60
57
|
state: clearingHouseStatePublicKey,
|
|
61
58
|
quoteAssetMint: usdcMint,
|
|
62
|
-
insuranceVault: insuranceVaultPublicKey,
|
|
63
|
-
insuranceVaultAuthority: insuranceVaultAuthority,
|
|
64
59
|
rent: SYSVAR_RENT_PUBKEY,
|
|
60
|
+
insuranceVault: insuranceVaultPublicKey,
|
|
61
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
65
62
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
66
63
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
67
64
|
},
|
|
@@ -77,7 +74,7 @@ export class Admin extends ClearingHouse {
|
|
|
77
74
|
return [initializeTxSig];
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
public async
|
|
77
|
+
public async initializeSpotMarket(
|
|
81
78
|
mint: PublicKey,
|
|
82
79
|
optimalUtilization: BN,
|
|
83
80
|
optimalRate: BN,
|
|
@@ -91,31 +88,23 @@ export class Admin extends ClearingHouse {
|
|
|
91
88
|
imfFactor = new BN(0),
|
|
92
89
|
liquidationFee = ZERO
|
|
93
90
|
): Promise<TransactionSignature> {
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
const bankVault = await getBankVaultPublicKey(
|
|
91
|
+
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
92
|
+
const spotMarket = await getSpotMarketPublicKey(
|
|
98
93
|
this.program.programId,
|
|
99
|
-
|
|
94
|
+
spotMarketIndex
|
|
100
95
|
);
|
|
101
96
|
|
|
102
|
-
const
|
|
97
|
+
const spotMarketVault = await getSpotMarketVaultPublicKey(
|
|
103
98
|
this.program.programId,
|
|
104
|
-
|
|
99
|
+
spotMarketIndex
|
|
105
100
|
);
|
|
106
101
|
|
|
107
102
|
const insuranceFundVault = await getInsuranceFundVaultPublicKey(
|
|
108
103
|
this.program.programId,
|
|
109
|
-
|
|
104
|
+
spotMarketIndex
|
|
110
105
|
);
|
|
111
106
|
|
|
112
|
-
const
|
|
113
|
-
await getInsuranceFundVaultAuthorityPublicKey(
|
|
114
|
-
this.program.programId,
|
|
115
|
-
bankIndex
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const initializeTx = await this.program.transaction.initializeBank(
|
|
107
|
+
const initializeTx = await this.program.transaction.initializeSpotMarket(
|
|
119
108
|
optimalUtilization,
|
|
120
109
|
optimalRate,
|
|
121
110
|
maxRate,
|
|
@@ -130,12 +119,11 @@ export class Admin extends ClearingHouse {
|
|
|
130
119
|
accounts: {
|
|
131
120
|
admin: this.wallet.publicKey,
|
|
132
121
|
state: await this.getStatePublicKey(),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
bankVaultAuthority,
|
|
122
|
+
spotMarket,
|
|
123
|
+
spotMarketVault,
|
|
136
124
|
insuranceFundVault,
|
|
137
|
-
|
|
138
|
-
|
|
125
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
126
|
+
spotMarketMint: mint,
|
|
139
127
|
oracle,
|
|
140
128
|
rent: SYSVAR_RENT_PUBKEY,
|
|
141
129
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
@@ -146,7 +134,7 @@ export class Admin extends ClearingHouse {
|
|
|
146
134
|
|
|
147
135
|
const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
148
136
|
|
|
149
|
-
await this.accountSubscriber.
|
|
137
|
+
await this.accountSubscriber.addSpotMarket(spotMarketIndex);
|
|
150
138
|
await this.accountSubscriber.addOracle({
|
|
151
139
|
source: oracleSource,
|
|
152
140
|
publicKey: oracle,
|
|
@@ -155,6 +143,41 @@ export class Admin extends ClearingHouse {
|
|
|
155
143
|
return txSig;
|
|
156
144
|
}
|
|
157
145
|
|
|
146
|
+
public async initializeSerumFulfillmentConfig(
|
|
147
|
+
marketIndex: BN,
|
|
148
|
+
serumMarket: PublicKey,
|
|
149
|
+
serumProgram: PublicKey
|
|
150
|
+
): Promise<TransactionSignature> {
|
|
151
|
+
const serumOpenOrders = getSerumOpenOrdersPublicKey(
|
|
152
|
+
this.program.programId,
|
|
153
|
+
serumMarket
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const serumFulfillmentConfig = getSerumFulfillmentConfigPublicKey(
|
|
157
|
+
this.program.programId,
|
|
158
|
+
serumMarket
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return await this.program.rpc.initializeSerumFulfillmentConfig(
|
|
162
|
+
marketIndex,
|
|
163
|
+
{
|
|
164
|
+
accounts: {
|
|
165
|
+
admin: this.wallet.publicKey,
|
|
166
|
+
state: await this.getStatePublicKey(),
|
|
167
|
+
baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
168
|
+
quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
|
|
169
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
170
|
+
serumProgram,
|
|
171
|
+
serumMarket,
|
|
172
|
+
serumOpenOrders,
|
|
173
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
174
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
175
|
+
serumFulfillmentConfig,
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
158
181
|
public async initializeMarket(
|
|
159
182
|
priceOracle: PublicKey,
|
|
160
183
|
baseAssetReserve: BN,
|
|
@@ -197,7 +220,7 @@ export class Admin extends ClearingHouse {
|
|
|
197
220
|
this.opts
|
|
198
221
|
);
|
|
199
222
|
|
|
200
|
-
await this.accountSubscriber.
|
|
223
|
+
await this.accountSubscriber.addPerpMarket(
|
|
201
224
|
this.getStateAccount().numberOfMarkets
|
|
202
225
|
);
|
|
203
226
|
await this.accountSubscriber.addOracle({
|
|
@@ -209,23 +232,29 @@ export class Admin extends ClearingHouse {
|
|
|
209
232
|
}
|
|
210
233
|
|
|
211
234
|
public async moveAmmPrice(
|
|
235
|
+
marketIndex: BN,
|
|
212
236
|
baseAssetReserve: BN,
|
|
213
237
|
quoteAssetReserve: BN,
|
|
214
|
-
|
|
238
|
+
sqrtK?: BN
|
|
215
239
|
): Promise<TransactionSignature> {
|
|
216
240
|
const marketPublicKey = await getMarketPublicKey(
|
|
217
241
|
this.program.programId,
|
|
218
242
|
marketIndex
|
|
219
243
|
);
|
|
220
244
|
|
|
245
|
+
if (sqrtK == undefined) {
|
|
246
|
+
sqrtK = squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
|
|
247
|
+
}
|
|
248
|
+
|
|
221
249
|
return await this.program.rpc.moveAmmPrice(
|
|
222
250
|
baseAssetReserve,
|
|
223
251
|
quoteAssetReserve,
|
|
252
|
+
sqrtK,
|
|
224
253
|
{
|
|
225
254
|
accounts: {
|
|
226
255
|
state: await this.getStatePublicKey(),
|
|
227
256
|
admin: this.wallet.publicKey,
|
|
228
|
-
|
|
257
|
+
perpMarket: marketPublicKey,
|
|
229
258
|
},
|
|
230
259
|
}
|
|
231
260
|
);
|
|
@@ -240,16 +269,16 @@ export class Admin extends ClearingHouse {
|
|
|
240
269
|
state: await this.getStatePublicKey(),
|
|
241
270
|
admin: this.wallet.publicKey,
|
|
242
271
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
243
|
-
oracle: this.
|
|
272
|
+
oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
|
|
244
273
|
},
|
|
245
274
|
});
|
|
246
275
|
}
|
|
247
276
|
|
|
248
277
|
public async moveAmmToPrice(
|
|
249
|
-
|
|
278
|
+
perpMarketIndex: BN,
|
|
250
279
|
targetPrice: BN
|
|
251
280
|
): Promise<TransactionSignature> {
|
|
252
|
-
const market = this.
|
|
281
|
+
const market = this.getPerpMarketAccount(perpMarketIndex);
|
|
253
282
|
|
|
254
283
|
const [direction, tradeSize, _] = calculateTargetPriceTrade(
|
|
255
284
|
market,
|
|
@@ -269,17 +298,18 @@ export class Admin extends ClearingHouse {
|
|
|
269
298
|
|
|
270
299
|
const marketPublicKey = await getMarketPublicKey(
|
|
271
300
|
this.program.programId,
|
|
272
|
-
|
|
301
|
+
perpMarketIndex
|
|
273
302
|
);
|
|
274
303
|
|
|
275
304
|
return await this.program.rpc.moveAmmPrice(
|
|
276
305
|
newBaseAssetAmount,
|
|
277
306
|
newQuoteAssetAmount,
|
|
307
|
+
market.amm.sqrtK,
|
|
278
308
|
{
|
|
279
309
|
accounts: {
|
|
280
310
|
state: await this.getStatePublicKey(),
|
|
281
311
|
admin: this.wallet.publicKey,
|
|
282
|
-
|
|
312
|
+
perpMarket: marketPublicKey,
|
|
283
313
|
},
|
|
284
314
|
}
|
|
285
315
|
);
|
|
@@ -293,7 +323,7 @@ export class Admin extends ClearingHouse {
|
|
|
293
323
|
this.program.programId,
|
|
294
324
|
marketIndex
|
|
295
325
|
);
|
|
296
|
-
const ammData = this.
|
|
326
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
297
327
|
|
|
298
328
|
return await this.program.rpc.repegAmmCurve(newPeg, {
|
|
299
329
|
accounts: {
|
|
@@ -308,7 +338,7 @@ export class Admin extends ClearingHouse {
|
|
|
308
338
|
public async updateAmmOracleTwap(
|
|
309
339
|
marketIndex: BN
|
|
310
340
|
): Promise<TransactionSignature> {
|
|
311
|
-
const ammData = this.
|
|
341
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
312
342
|
const marketPublicKey = await getMarketPublicKey(
|
|
313
343
|
this.program.programId,
|
|
314
344
|
marketIndex
|
|
@@ -327,7 +357,7 @@ export class Admin extends ClearingHouse {
|
|
|
327
357
|
public async resetAmmOracleTwap(
|
|
328
358
|
marketIndex: BN
|
|
329
359
|
): Promise<TransactionSignature> {
|
|
330
|
-
const ammData = this.
|
|
360
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
331
361
|
const marketPublicKey = await getMarketPublicKey(
|
|
332
362
|
this.program.programId,
|
|
333
363
|
marketIndex
|
|
@@ -348,14 +378,14 @@ export class Admin extends ClearingHouse {
|
|
|
348
378
|
recipient: PublicKey
|
|
349
379
|
): Promise<TransactionSignature> {
|
|
350
380
|
const state = await this.getStateAccount();
|
|
351
|
-
const
|
|
381
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
352
382
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
353
383
|
accounts: {
|
|
354
384
|
admin: this.wallet.publicKey,
|
|
355
385
|
state: await this.getStatePublicKey(),
|
|
356
|
-
|
|
386
|
+
spotMarket: spotMarket.pubkey,
|
|
357
387
|
insuranceVault: state.insuranceVault,
|
|
358
|
-
|
|
388
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
359
389
|
recipient: recipient,
|
|
360
390
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
361
391
|
},
|
|
@@ -371,15 +401,15 @@ export class Admin extends ClearingHouse {
|
|
|
371
401
|
this.program.programId,
|
|
372
402
|
marketIndex
|
|
373
403
|
);
|
|
374
|
-
const
|
|
404
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
375
405
|
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
376
406
|
accounts: {
|
|
377
407
|
admin: this.wallet.publicKey,
|
|
378
408
|
state: await this.getStatePublicKey(),
|
|
379
409
|
market: marketPublicKey,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
410
|
+
spotMarket: spotMarket.pubkey,
|
|
411
|
+
spotMarketVault: spotMarket.vault,
|
|
412
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
383
413
|
recipient: recipient,
|
|
384
414
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
385
415
|
},
|
|
@@ -391,7 +421,7 @@ export class Admin extends ClearingHouse {
|
|
|
391
421
|
amount: BN
|
|
392
422
|
): Promise<TransactionSignature> {
|
|
393
423
|
const state = await this.getStateAccount();
|
|
394
|
-
const
|
|
424
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
395
425
|
|
|
396
426
|
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
397
427
|
accounts: {
|
|
@@ -399,10 +429,9 @@ export class Admin extends ClearingHouse {
|
|
|
399
429
|
state: await this.getStatePublicKey(),
|
|
400
430
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
401
431
|
insuranceVault: state.insuranceVault,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
bankVaultAuthority: bank.vaultAuthority,
|
|
432
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
433
|
+
quoteSpotMarket: spotMarket.pubkey,
|
|
434
|
+
spotMarketVault: spotMarket.vault,
|
|
406
435
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
407
436
|
},
|
|
408
437
|
});
|
|
@@ -603,30 +632,33 @@ export class Admin extends ClearingHouse {
|
|
|
603
632
|
});
|
|
604
633
|
}
|
|
605
634
|
|
|
606
|
-
public async
|
|
607
|
-
|
|
635
|
+
public async updateWithdrawGuardThreshold(
|
|
636
|
+
marketIndex: BN,
|
|
608
637
|
withdrawGuardThreshold: BN
|
|
609
638
|
): Promise<TransactionSignature> {
|
|
610
|
-
return await this.program.rpc.
|
|
639
|
+
return await this.program.rpc.updateWithdrawGuardThreshold(
|
|
611
640
|
withdrawGuardThreshold,
|
|
612
641
|
{
|
|
613
642
|
accounts: {
|
|
614
643
|
admin: this.wallet.publicKey,
|
|
615
644
|
state: await this.getStatePublicKey(),
|
|
616
|
-
|
|
645
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
646
|
+
this.program.programId,
|
|
647
|
+
marketIndex
|
|
648
|
+
),
|
|
617
649
|
},
|
|
618
650
|
}
|
|
619
651
|
);
|
|
620
652
|
}
|
|
621
653
|
|
|
622
|
-
public async
|
|
623
|
-
|
|
654
|
+
public async updateSpotMarketIfFactor(
|
|
655
|
+
marketIndex: BN,
|
|
624
656
|
userIfFactor: BN,
|
|
625
657
|
totalIfFactor: BN,
|
|
626
658
|
liquidationIfFactor: BN
|
|
627
659
|
): Promise<TransactionSignature> {
|
|
628
|
-
return await this.program.rpc.
|
|
629
|
-
|
|
660
|
+
return await this.program.rpc.updateSpotMarketIfFactor(
|
|
661
|
+
marketIndex,
|
|
630
662
|
userIfFactor,
|
|
631
663
|
totalIfFactor,
|
|
632
664
|
liquidationIfFactor,
|
|
@@ -634,23 +666,29 @@ export class Admin extends ClearingHouse {
|
|
|
634
666
|
accounts: {
|
|
635
667
|
admin: this.wallet.publicKey,
|
|
636
668
|
state: await this.getStatePublicKey(),
|
|
637
|
-
|
|
669
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
670
|
+
this.program.programId,
|
|
671
|
+
marketIndex
|
|
672
|
+
),
|
|
638
673
|
},
|
|
639
674
|
}
|
|
640
675
|
);
|
|
641
676
|
}
|
|
642
677
|
|
|
643
|
-
public async
|
|
644
|
-
|
|
678
|
+
public async updateInsuranceWithdrawEscrowPeriod(
|
|
679
|
+
marketIndex: BN,
|
|
645
680
|
insuranceWithdrawEscrowPeriod: BN
|
|
646
681
|
): Promise<TransactionSignature> {
|
|
647
|
-
return await this.program.rpc.
|
|
682
|
+
return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(
|
|
648
683
|
insuranceWithdrawEscrowPeriod,
|
|
649
684
|
{
|
|
650
685
|
accounts: {
|
|
651
686
|
admin: this.wallet.publicKey,
|
|
652
687
|
state: await this.getStatePublicKey(),
|
|
653
|
-
|
|
688
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
689
|
+
this.program.programId,
|
|
690
|
+
marketIndex
|
|
691
|
+
),
|
|
654
692
|
},
|
|
655
693
|
}
|
|
656
694
|
);
|
|
@@ -715,6 +753,22 @@ export class Admin extends ClearingHouse {
|
|
|
715
753
|
);
|
|
716
754
|
}
|
|
717
755
|
|
|
756
|
+
public async updateMarketExpiry(
|
|
757
|
+
perpMarketIndex: BN,
|
|
758
|
+
expiryTs: BN
|
|
759
|
+
): Promise<TransactionSignature> {
|
|
760
|
+
return await this.program.rpc.updateMarketExpiry(expiryTs, {
|
|
761
|
+
accounts: {
|
|
762
|
+
admin: this.wallet.publicKey,
|
|
763
|
+
state: await this.getStatePublicKey(),
|
|
764
|
+
perpMarket: await getMarketPublicKey(
|
|
765
|
+
this.program.programId,
|
|
766
|
+
perpMarketIndex
|
|
767
|
+
),
|
|
768
|
+
},
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
|
|
718
772
|
public async updateWhitelistMint(
|
|
719
773
|
whitelistMint?: PublicKey
|
|
720
774
|
): Promise<TransactionSignature> {
|
|
@@ -802,7 +856,7 @@ export class Admin extends ClearingHouse {
|
|
|
802
856
|
accounts: {
|
|
803
857
|
admin: this.wallet.publicKey,
|
|
804
858
|
state: await this.getStatePublicKey(),
|
|
805
|
-
market: this.
|
|
859
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
806
860
|
},
|
|
807
861
|
}
|
|
808
862
|
);
|
|
@@ -816,8 +870,28 @@ export class Admin extends ClearingHouse {
|
|
|
816
870
|
accounts: {
|
|
817
871
|
admin: this.wallet.publicKey,
|
|
818
872
|
state: await this.getStatePublicKey(),
|
|
819
|
-
market: this.
|
|
873
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
820
874
|
},
|
|
821
875
|
});
|
|
822
876
|
}
|
|
877
|
+
|
|
878
|
+
public async updateMarketMaxImbalances(
|
|
879
|
+
marketIndex: BN,
|
|
880
|
+
unrealizedMaxImbalance: BN,
|
|
881
|
+
maxRevenueWithdrawPerPeriod: BN,
|
|
882
|
+
quoteMaxInsurance: BN
|
|
883
|
+
): Promise<TransactionSignature> {
|
|
884
|
+
return await this.program.rpc.updateMarketMaxImbalances(
|
|
885
|
+
unrealizedMaxImbalance,
|
|
886
|
+
maxRevenueWithdrawPerPeriod,
|
|
887
|
+
quoteMaxInsurance,
|
|
888
|
+
{
|
|
889
|
+
accounts: {
|
|
890
|
+
admin: this.wallet.publicKey,
|
|
891
|
+
state: await this.getStatePublicKey(),
|
|
892
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
893
|
+
},
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
}
|
|
823
897
|
}
|
package/src/assert/assert.js
CHANGED