@drift-labs/sdk 0.2.0-master.25 → 0.2.0-master.27
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 +14 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +30 -27
- package/lib/accounts/types.d.ts +9 -9
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +15 -14
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +38 -34
- package/lib/addresses/pda.d.ts +7 -6
- package/lib/addresses/pda.js +31 -27
- package/lib/admin.d.ts +13 -7
- package/lib/admin.js +111 -44
- package/lib/clearingHouse.d.ts +71 -42
- package/lib/clearingHouse.js +767 -278
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +24 -22
- package/lib/clearingHouseUser.js +273 -177
- 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/lib/constants/{markets.js → 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/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +557 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/events/types.d.ts +2 -1
- package/lib/events/types.js +1 -0
- package/lib/examples/makeTradeExample.js +7 -7
- package/lib/idl/clearing_house.json +1152 -503
- package/lib/index.d.ts +10 -3
- package/lib/index.js +10 -3
- package/lib/math/amm.d.ts +2 -2
- package/lib/math/amm.js +1 -1
- 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 +11 -10
- package/lib/math/market.js +30 -7
- package/lib/math/oracles.d.ts +2 -1
- package/lib/math/oracles.js +11 -1
- package/lib/math/orders.d.ts +6 -6
- package/lib/math/orders.js +31 -16
- package/lib/math/position.d.ts +13 -13
- package/lib/math/position.js +19 -19
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +193 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -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 -57
- package/lib/types.js +39 -11
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/package.json +6 -3
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +42 -38
- package/src/accounts/types.ts +12 -9
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +65 -52
- package/src/addresses/pda.ts +49 -44
- package/src/admin.ts +190 -55
- package/src/clearingHouse.ts +1092 -365
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.ts +518 -255
- package/src/config.ts +30 -30
- package/src/constants/numericConstants.ts +17 -15
- package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
- package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
- package/src/dlob/DLOB.ts +884 -0
- package/src/dlob/DLOBNode.ts +163 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/events/types.ts +3 -0
- package/src/examples/makeTradeExample.js +152 -75
- package/src/examples/makeTradeExample.ts +10 -8
- package/src/idl/clearing_house.json +1152 -503
- package/src/index.ts +10 -3
- package/src/math/amm.ts +6 -3
- package/src/math/funding.ts +7 -7
- package/src/math/margin.ts +34 -23
- package/src/math/market.ts +72 -20
- package/src/math/oracles.ts +18 -1
- package/src/math/orders.ts +33 -25
- package/src/math/position.ts +31 -31
- package/src/math/spotBalance.ts +316 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/state.ts +2 -2
- package/src/math/trade.ts +4 -4
- package/src/orderParams.ts +16 -8
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.ts +13 -0
- package/src/tx/retryTxSender.ts +5 -2
- package/src/tx/types.ts +2 -1
- package/src/types.ts +135 -56
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/tests/bn/test.ts +2 -3
- package/tests/dlob/helpers.ts +322 -0
- package/tests/dlob/test.ts +2865 -0
- package/lib/math/bankBalance.d.ts +0 -15
- package/lib/math/bankBalance.js +0 -150
- package/src/constants/numericConstants.js +0 -41
- package/src/math/bankBalance.ts +0 -258
- package/src/math/oracles.js +0 -26
- package/src/math/state.js +0 -15
- package/src/orderParams.js +0 -20
- package/src/slot/SlotSubscriber.js +0 -39
- package/src/tokenFaucet.js +0 -189
package/src/addresses/pda.ts
CHANGED
|
@@ -85,45 +85,30 @@ export async function getMarketPublicKey(
|
|
|
85
85
|
)[0];
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export async function
|
|
88
|
+
export async function getSpotMarketPublicKey(
|
|
89
89
|
programId: PublicKey,
|
|
90
|
-
|
|
91
|
-
): Promise<PublicKey> {
|
|
92
|
-
return (
|
|
93
|
-
await anchor.web3.PublicKey.findProgramAddress(
|
|
94
|
-
[
|
|
95
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('bank')),
|
|
96
|
-
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
97
|
-
],
|
|
98
|
-
programId
|
|
99
|
-
)
|
|
100
|
-
)[0];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function getBankVaultPublicKey(
|
|
104
|
-
programId: PublicKey,
|
|
105
|
-
bankIndex: BN
|
|
90
|
+
marketIndex: BN
|
|
106
91
|
): Promise<PublicKey> {
|
|
107
92
|
return (
|
|
108
93
|
await anchor.web3.PublicKey.findProgramAddress(
|
|
109
94
|
[
|
|
110
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
111
|
-
|
|
95
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
96
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
112
97
|
],
|
|
113
98
|
programId
|
|
114
99
|
)
|
|
115
100
|
)[0];
|
|
116
101
|
}
|
|
117
102
|
|
|
118
|
-
export async function
|
|
103
|
+
export async function getSpotMarketVaultPublicKey(
|
|
119
104
|
programId: PublicKey,
|
|
120
|
-
|
|
105
|
+
marketIndex: BN
|
|
121
106
|
): Promise<PublicKey> {
|
|
122
107
|
return (
|
|
123
108
|
await anchor.web3.PublicKey.findProgramAddress(
|
|
124
109
|
[
|
|
125
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
126
|
-
|
|
110
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
111
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
127
112
|
],
|
|
128
113
|
programId
|
|
129
114
|
)
|
|
@@ -132,30 +117,13 @@ export async function getBankVaultAuthorityPublicKey(
|
|
|
132
117
|
|
|
133
118
|
export async function getInsuranceFundVaultPublicKey(
|
|
134
119
|
programId: PublicKey,
|
|
135
|
-
|
|
120
|
+
marketIndex: BN
|
|
136
121
|
): Promise<PublicKey> {
|
|
137
122
|
return (
|
|
138
123
|
await anchor.web3.PublicKey.findProgramAddress(
|
|
139
124
|
[
|
|
140
125
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
141
|
-
|
|
142
|
-
],
|
|
143
|
-
programId
|
|
144
|
-
)
|
|
145
|
-
)[0];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export async function getInsuranceFundVaultAuthorityPublicKey(
|
|
149
|
-
programId: PublicKey,
|
|
150
|
-
bankIndex: BN
|
|
151
|
-
): Promise<PublicKey> {
|
|
152
|
-
return (
|
|
153
|
-
await anchor.web3.PublicKey.findProgramAddress(
|
|
154
|
-
[
|
|
155
|
-
Buffer.from(
|
|
156
|
-
anchor.utils.bytes.utf8.encode('insurance_fund_vault_authority')
|
|
157
|
-
),
|
|
158
|
-
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
126
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
159
127
|
],
|
|
160
128
|
programId
|
|
161
129
|
)
|
|
@@ -165,13 +133,13 @@ export async function getInsuranceFundVaultAuthorityPublicKey(
|
|
|
165
133
|
export function getInsuranceFundStakeAccountPublicKey(
|
|
166
134
|
programId: PublicKey,
|
|
167
135
|
authority: PublicKey,
|
|
168
|
-
|
|
136
|
+
marketIndex: BN
|
|
169
137
|
): PublicKey {
|
|
170
138
|
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
171
139
|
[
|
|
172
140
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
173
141
|
authority.toBuffer(),
|
|
174
|
-
|
|
142
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
175
143
|
],
|
|
176
144
|
programId
|
|
177
145
|
)[0];
|
|
@@ -185,3 +153,40 @@ export function getClearingHouseSignerPublicKey(
|
|
|
185
153
|
programId
|
|
186
154
|
)[0];
|
|
187
155
|
}
|
|
156
|
+
|
|
157
|
+
export function getSerumOpenOrdersPublicKey(
|
|
158
|
+
programId: PublicKey,
|
|
159
|
+
market: PublicKey
|
|
160
|
+
): PublicKey {
|
|
161
|
+
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
162
|
+
[
|
|
163
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
164
|
+
market.toBuffer(),
|
|
165
|
+
],
|
|
166
|
+
programId
|
|
167
|
+
)[0];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getSerumSignerPublicKey(
|
|
171
|
+
programId: PublicKey,
|
|
172
|
+
market: PublicKey,
|
|
173
|
+
nonce: BN
|
|
174
|
+
): PublicKey {
|
|
175
|
+
return anchor.web3.PublicKey.createProgramAddressSync(
|
|
176
|
+
[market.toBuffer(), nonce.toArrayLike(Buffer, 'le', 8)],
|
|
177
|
+
programId
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function getSerumFulfillmentConfigPublicKey(
|
|
182
|
+
programId: PublicKey,
|
|
183
|
+
market: PublicKey
|
|
184
|
+
): PublicKey {
|
|
185
|
+
return anchor.web3.PublicKey.findProgramAddressSync(
|
|
186
|
+
[
|
|
187
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
|
|
188
|
+
market.toBuffer(),
|
|
189
|
+
],
|
|
190
|
+
programId
|
|
191
|
+
)[0];
|
|
192
|
+
}
|
package/src/admin.ts
CHANGED
|
@@ -13,11 +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
|
-
|
|
16
|
+
getSpotMarketPublicKey,
|
|
17
|
+
getSpotMarketVaultPublicKey,
|
|
18
18
|
getMarketPublicKey,
|
|
19
19
|
getInsuranceFundVaultPublicKey,
|
|
20
|
+
getSerumOpenOrdersPublicKey,
|
|
21
|
+
getSerumFulfillmentConfigPublicKey,
|
|
20
22
|
} from './addresses/pda';
|
|
23
|
+
import { squareRootBN } from './math/utils';
|
|
21
24
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
25
|
import { ClearingHouse } from './clearingHouse';
|
|
23
26
|
import { PEG_PRECISION, ZERO } from './constants/numericConstants';
|
|
@@ -71,7 +74,7 @@ export class Admin extends ClearingHouse {
|
|
|
71
74
|
return [initializeTxSig];
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
public async
|
|
77
|
+
public async initializeSpotMarket(
|
|
75
78
|
mint: PublicKey,
|
|
76
79
|
optimalUtilization: BN,
|
|
77
80
|
optimalRate: BN,
|
|
@@ -85,20 +88,23 @@ export class Admin extends ClearingHouse {
|
|
|
85
88
|
imfFactor = new BN(0),
|
|
86
89
|
liquidationFee = ZERO
|
|
87
90
|
): Promise<TransactionSignature> {
|
|
88
|
-
const
|
|
89
|
-
const
|
|
91
|
+
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
92
|
+
const spotMarket = await getSpotMarketPublicKey(
|
|
93
|
+
this.program.programId,
|
|
94
|
+
spotMarketIndex
|
|
95
|
+
);
|
|
90
96
|
|
|
91
|
-
const
|
|
97
|
+
const spotMarketVault = await getSpotMarketVaultPublicKey(
|
|
92
98
|
this.program.programId,
|
|
93
|
-
|
|
99
|
+
spotMarketIndex
|
|
94
100
|
);
|
|
95
101
|
|
|
96
102
|
const insuranceFundVault = await getInsuranceFundVaultPublicKey(
|
|
97
103
|
this.program.programId,
|
|
98
|
-
|
|
104
|
+
spotMarketIndex
|
|
99
105
|
);
|
|
100
106
|
|
|
101
|
-
const initializeTx = await this.program.transaction.
|
|
107
|
+
const initializeTx = await this.program.transaction.initializeSpotMarket(
|
|
102
108
|
optimalUtilization,
|
|
103
109
|
optimalRate,
|
|
104
110
|
maxRate,
|
|
@@ -113,11 +119,11 @@ export class Admin extends ClearingHouse {
|
|
|
113
119
|
accounts: {
|
|
114
120
|
admin: this.wallet.publicKey,
|
|
115
121
|
state: await this.getStatePublicKey(),
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
spotMarket,
|
|
123
|
+
spotMarketVault,
|
|
118
124
|
insuranceFundVault,
|
|
119
125
|
clearingHouseSigner: this.getSignerPublicKey(),
|
|
120
|
-
|
|
126
|
+
spotMarketMint: mint,
|
|
121
127
|
oracle,
|
|
122
128
|
rent: SYSVAR_RENT_PUBKEY,
|
|
123
129
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
@@ -128,7 +134,7 @@ export class Admin extends ClearingHouse {
|
|
|
128
134
|
|
|
129
135
|
const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
130
136
|
|
|
131
|
-
await this.accountSubscriber.
|
|
137
|
+
await this.accountSubscriber.addSpotMarket(spotMarketIndex);
|
|
132
138
|
await this.accountSubscriber.addOracle({
|
|
133
139
|
source: oracleSource,
|
|
134
140
|
publicKey: oracle,
|
|
@@ -137,6 +143,41 @@ export class Admin extends ClearingHouse {
|
|
|
137
143
|
return txSig;
|
|
138
144
|
}
|
|
139
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
|
+
|
|
140
181
|
public async initializeMarket(
|
|
141
182
|
priceOracle: PublicKey,
|
|
142
183
|
baseAssetReserve: BN,
|
|
@@ -179,7 +220,7 @@ export class Admin extends ClearingHouse {
|
|
|
179
220
|
this.opts
|
|
180
221
|
);
|
|
181
222
|
|
|
182
|
-
await this.accountSubscriber.
|
|
223
|
+
await this.accountSubscriber.addPerpMarket(
|
|
183
224
|
this.getStateAccount().numberOfMarkets
|
|
184
225
|
);
|
|
185
226
|
await this.accountSubscriber.addOracle({
|
|
@@ -191,23 +232,29 @@ export class Admin extends ClearingHouse {
|
|
|
191
232
|
}
|
|
192
233
|
|
|
193
234
|
public async moveAmmPrice(
|
|
235
|
+
marketIndex: BN,
|
|
194
236
|
baseAssetReserve: BN,
|
|
195
237
|
quoteAssetReserve: BN,
|
|
196
|
-
|
|
238
|
+
sqrtK?: BN
|
|
197
239
|
): Promise<TransactionSignature> {
|
|
198
240
|
const marketPublicKey = await getMarketPublicKey(
|
|
199
241
|
this.program.programId,
|
|
200
242
|
marketIndex
|
|
201
243
|
);
|
|
202
244
|
|
|
245
|
+
if (sqrtK == undefined) {
|
|
246
|
+
sqrtK = squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
|
|
247
|
+
}
|
|
248
|
+
|
|
203
249
|
return await this.program.rpc.moveAmmPrice(
|
|
204
250
|
baseAssetReserve,
|
|
205
251
|
quoteAssetReserve,
|
|
252
|
+
sqrtK,
|
|
206
253
|
{
|
|
207
254
|
accounts: {
|
|
208
255
|
state: await this.getStatePublicKey(),
|
|
209
256
|
admin: this.wallet.publicKey,
|
|
210
|
-
|
|
257
|
+
perpMarket: marketPublicKey,
|
|
211
258
|
},
|
|
212
259
|
}
|
|
213
260
|
);
|
|
@@ -222,16 +269,29 @@ export class Admin extends ClearingHouse {
|
|
|
222
269
|
state: await this.getStatePublicKey(),
|
|
223
270
|
admin: this.wallet.publicKey,
|
|
224
271
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
225
|
-
oracle: this.
|
|
272
|
+
oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
|
|
226
273
|
},
|
|
227
274
|
});
|
|
228
275
|
}
|
|
229
276
|
|
|
230
|
-
public async
|
|
277
|
+
public async updateConcentrationScale(
|
|
231
278
|
marketIndex: BN,
|
|
279
|
+
concentrationScale: BN
|
|
280
|
+
): Promise<TransactionSignature> {
|
|
281
|
+
return await this.program.rpc.updateConcentrationScale(concentrationScale, {
|
|
282
|
+
accounts: {
|
|
283
|
+
state: await this.getStatePublicKey(),
|
|
284
|
+
admin: this.wallet.publicKey,
|
|
285
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public async moveAmmToPrice(
|
|
291
|
+
perpMarketIndex: BN,
|
|
232
292
|
targetPrice: BN
|
|
233
293
|
): Promise<TransactionSignature> {
|
|
234
|
-
const market = this.
|
|
294
|
+
const market = this.getPerpMarketAccount(perpMarketIndex);
|
|
235
295
|
|
|
236
296
|
const [direction, tradeSize, _] = calculateTargetPriceTrade(
|
|
237
297
|
market,
|
|
@@ -251,17 +311,18 @@ export class Admin extends ClearingHouse {
|
|
|
251
311
|
|
|
252
312
|
const marketPublicKey = await getMarketPublicKey(
|
|
253
313
|
this.program.programId,
|
|
254
|
-
|
|
314
|
+
perpMarketIndex
|
|
255
315
|
);
|
|
256
316
|
|
|
257
317
|
return await this.program.rpc.moveAmmPrice(
|
|
258
318
|
newBaseAssetAmount,
|
|
259
319
|
newQuoteAssetAmount,
|
|
320
|
+
market.amm.sqrtK,
|
|
260
321
|
{
|
|
261
322
|
accounts: {
|
|
262
323
|
state: await this.getStatePublicKey(),
|
|
263
324
|
admin: this.wallet.publicKey,
|
|
264
|
-
|
|
325
|
+
perpMarket: marketPublicKey,
|
|
265
326
|
},
|
|
266
327
|
}
|
|
267
328
|
);
|
|
@@ -275,7 +336,7 @@ export class Admin extends ClearingHouse {
|
|
|
275
336
|
this.program.programId,
|
|
276
337
|
marketIndex
|
|
277
338
|
);
|
|
278
|
-
const ammData = this.
|
|
339
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
279
340
|
|
|
280
341
|
return await this.program.rpc.repegAmmCurve(newPeg, {
|
|
281
342
|
accounts: {
|
|
@@ -290,7 +351,7 @@ export class Admin extends ClearingHouse {
|
|
|
290
351
|
public async updateAmmOracleTwap(
|
|
291
352
|
marketIndex: BN
|
|
292
353
|
): Promise<TransactionSignature> {
|
|
293
|
-
const ammData = this.
|
|
354
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
294
355
|
const marketPublicKey = await getMarketPublicKey(
|
|
295
356
|
this.program.programId,
|
|
296
357
|
marketIndex
|
|
@@ -309,7 +370,7 @@ export class Admin extends ClearingHouse {
|
|
|
309
370
|
public async resetAmmOracleTwap(
|
|
310
371
|
marketIndex: BN
|
|
311
372
|
): Promise<TransactionSignature> {
|
|
312
|
-
const ammData = this.
|
|
373
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
313
374
|
const marketPublicKey = await getMarketPublicKey(
|
|
314
375
|
this.program.programId,
|
|
315
376
|
marketIndex
|
|
@@ -330,12 +391,12 @@ export class Admin extends ClearingHouse {
|
|
|
330
391
|
recipient: PublicKey
|
|
331
392
|
): Promise<TransactionSignature> {
|
|
332
393
|
const state = await this.getStateAccount();
|
|
333
|
-
const
|
|
394
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
334
395
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
335
396
|
accounts: {
|
|
336
397
|
admin: this.wallet.publicKey,
|
|
337
398
|
state: await this.getStatePublicKey(),
|
|
338
|
-
|
|
399
|
+
spotMarket: spotMarket.pubkey,
|
|
339
400
|
insuranceVault: state.insuranceVault,
|
|
340
401
|
clearingHouseSigner: this.getSignerPublicKey(),
|
|
341
402
|
recipient: recipient,
|
|
@@ -353,14 +414,14 @@ export class Admin extends ClearingHouse {
|
|
|
353
414
|
this.program.programId,
|
|
354
415
|
marketIndex
|
|
355
416
|
);
|
|
356
|
-
const
|
|
417
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
357
418
|
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
358
419
|
accounts: {
|
|
359
420
|
admin: this.wallet.publicKey,
|
|
360
421
|
state: await this.getStatePublicKey(),
|
|
361
422
|
market: marketPublicKey,
|
|
362
|
-
|
|
363
|
-
|
|
423
|
+
spotMarket: spotMarket.pubkey,
|
|
424
|
+
spotMarketVault: spotMarket.vault,
|
|
364
425
|
clearingHouseSigner: this.getSignerPublicKey(),
|
|
365
426
|
recipient: recipient,
|
|
366
427
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
@@ -373,7 +434,7 @@ export class Admin extends ClearingHouse {
|
|
|
373
434
|
amount: BN
|
|
374
435
|
): Promise<TransactionSignature> {
|
|
375
436
|
const state = await this.getStateAccount();
|
|
376
|
-
const
|
|
437
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
377
438
|
|
|
378
439
|
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
379
440
|
accounts: {
|
|
@@ -382,8 +443,8 @@ export class Admin extends ClearingHouse {
|
|
|
382
443
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
383
444
|
insuranceVault: state.insuranceVault,
|
|
384
445
|
clearingHouseSigner: this.getSignerPublicKey(),
|
|
385
|
-
|
|
386
|
-
|
|
446
|
+
quoteSpotMarket: spotMarket.pubkey,
|
|
447
|
+
spotMarketVault: spotMarket.vault,
|
|
387
448
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
388
449
|
},
|
|
389
450
|
});
|
|
@@ -584,54 +645,80 @@ export class Admin extends ClearingHouse {
|
|
|
584
645
|
});
|
|
585
646
|
}
|
|
586
647
|
|
|
587
|
-
public async
|
|
588
|
-
|
|
648
|
+
public async updateWithdrawGuardThreshold(
|
|
649
|
+
marketIndex: BN,
|
|
589
650
|
withdrawGuardThreshold: BN
|
|
590
651
|
): Promise<TransactionSignature> {
|
|
591
|
-
return await this.program.rpc.
|
|
652
|
+
return await this.program.rpc.updateWithdrawGuardThreshold(
|
|
592
653
|
withdrawGuardThreshold,
|
|
593
654
|
{
|
|
594
655
|
accounts: {
|
|
595
656
|
admin: this.wallet.publicKey,
|
|
596
657
|
state: await this.getStatePublicKey(),
|
|
597
|
-
|
|
658
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
659
|
+
this.program.programId,
|
|
660
|
+
marketIndex
|
|
661
|
+
),
|
|
598
662
|
},
|
|
599
663
|
}
|
|
600
664
|
);
|
|
601
665
|
}
|
|
602
666
|
|
|
603
|
-
public async
|
|
604
|
-
|
|
667
|
+
public async updateSpotMarketIfFactor(
|
|
668
|
+
marketIndex: BN,
|
|
605
669
|
userIfFactor: BN,
|
|
606
|
-
totalIfFactor: BN
|
|
607
|
-
liquidationIfFactor: BN
|
|
670
|
+
totalIfFactor: BN
|
|
608
671
|
): Promise<TransactionSignature> {
|
|
609
|
-
return await this.program.rpc.
|
|
610
|
-
|
|
672
|
+
return await this.program.rpc.updateSpotMarketIfFactor(
|
|
673
|
+
marketIndex,
|
|
611
674
|
userIfFactor,
|
|
612
675
|
totalIfFactor,
|
|
613
|
-
liquidationIfFactor,
|
|
614
676
|
{
|
|
615
677
|
accounts: {
|
|
616
678
|
admin: this.wallet.publicKey,
|
|
617
679
|
state: await this.getStatePublicKey(),
|
|
618
|
-
|
|
680
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
681
|
+
this.program.programId,
|
|
682
|
+
marketIndex
|
|
683
|
+
),
|
|
619
684
|
},
|
|
620
685
|
}
|
|
621
686
|
);
|
|
622
687
|
}
|
|
623
688
|
|
|
624
|
-
public async
|
|
625
|
-
|
|
689
|
+
public async updateSpotMarketRevenueSettlePeriod(
|
|
690
|
+
marketIndex: BN,
|
|
691
|
+
revenueSettlePeriod: BN
|
|
692
|
+
): Promise<TransactionSignature> {
|
|
693
|
+
return await this.program.rpc.updateSpotMarketRevenueSettlePeriod(
|
|
694
|
+
revenueSettlePeriod,
|
|
695
|
+
{
|
|
696
|
+
accounts: {
|
|
697
|
+
admin: this.wallet.publicKey,
|
|
698
|
+
state: await this.getStatePublicKey(),
|
|
699
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
700
|
+
this.program.programId,
|
|
701
|
+
marketIndex
|
|
702
|
+
),
|
|
703
|
+
},
|
|
704
|
+
}
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
public async updateInsuranceWithdrawEscrowPeriod(
|
|
709
|
+
marketIndex: BN,
|
|
626
710
|
insuranceWithdrawEscrowPeriod: BN
|
|
627
711
|
): Promise<TransactionSignature> {
|
|
628
|
-
return await this.program.rpc.
|
|
712
|
+
return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(
|
|
629
713
|
insuranceWithdrawEscrowPeriod,
|
|
630
714
|
{
|
|
631
715
|
accounts: {
|
|
632
716
|
admin: this.wallet.publicKey,
|
|
633
717
|
state: await this.getStatePublicKey(),
|
|
634
|
-
|
|
718
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
719
|
+
this.program.programId,
|
|
720
|
+
marketIndex
|
|
721
|
+
),
|
|
635
722
|
},
|
|
636
723
|
}
|
|
637
724
|
);
|
|
@@ -696,6 +783,22 @@ export class Admin extends ClearingHouse {
|
|
|
696
783
|
);
|
|
697
784
|
}
|
|
698
785
|
|
|
786
|
+
public async updateMarketExpiry(
|
|
787
|
+
perpMarketIndex: BN,
|
|
788
|
+
expiryTs: BN
|
|
789
|
+
): Promise<TransactionSignature> {
|
|
790
|
+
return await this.program.rpc.updateMarketExpiry(expiryTs, {
|
|
791
|
+
accounts: {
|
|
792
|
+
admin: this.wallet.publicKey,
|
|
793
|
+
state: await this.getStatePublicKey(),
|
|
794
|
+
perpMarket: await getMarketPublicKey(
|
|
795
|
+
this.program.programId,
|
|
796
|
+
perpMarketIndex
|
|
797
|
+
),
|
|
798
|
+
},
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
|
|
699
802
|
public async updateWhitelistMint(
|
|
700
803
|
whitelistMint?: PublicKey
|
|
701
804
|
): Promise<TransactionSignature> {
|
|
@@ -757,13 +860,25 @@ export class Admin extends ClearingHouse {
|
|
|
757
860
|
});
|
|
758
861
|
}
|
|
759
862
|
|
|
760
|
-
public async
|
|
761
|
-
minDuration: BN | number
|
|
762
|
-
maxDuration: BN | number
|
|
863
|
+
public async updatePerpAuctionDuration(
|
|
864
|
+
minDuration: BN | number
|
|
763
865
|
): Promise<TransactionSignature> {
|
|
764
|
-
return await this.program.rpc.
|
|
866
|
+
return await this.program.rpc.updatePerpAuctionDuration(
|
|
765
867
|
typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
|
|
766
|
-
|
|
868
|
+
{
|
|
869
|
+
accounts: {
|
|
870
|
+
admin: this.wallet.publicKey,
|
|
871
|
+
state: await this.getStatePublicKey(),
|
|
872
|
+
},
|
|
873
|
+
}
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
public async updateSpotAuctionDuration(
|
|
878
|
+
defaultAuctionDuration: number
|
|
879
|
+
): Promise<TransactionSignature> {
|
|
880
|
+
return await this.program.rpc.updateSpotAuctionDuration(
|
|
881
|
+
defaultAuctionDuration,
|
|
767
882
|
{
|
|
768
883
|
accounts: {
|
|
769
884
|
admin: this.wallet.publicKey,
|
|
@@ -783,7 +898,7 @@ export class Admin extends ClearingHouse {
|
|
|
783
898
|
accounts: {
|
|
784
899
|
admin: this.wallet.publicKey,
|
|
785
900
|
state: await this.getStatePublicKey(),
|
|
786
|
-
market: this.
|
|
901
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
787
902
|
},
|
|
788
903
|
}
|
|
789
904
|
);
|
|
@@ -797,8 +912,28 @@ export class Admin extends ClearingHouse {
|
|
|
797
912
|
accounts: {
|
|
798
913
|
admin: this.wallet.publicKey,
|
|
799
914
|
state: await this.getStatePublicKey(),
|
|
800
|
-
market: this.
|
|
915
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
801
916
|
},
|
|
802
917
|
});
|
|
803
918
|
}
|
|
919
|
+
|
|
920
|
+
public async updateMarketMaxImbalances(
|
|
921
|
+
marketIndex: BN,
|
|
922
|
+
unrealizedMaxImbalance: BN,
|
|
923
|
+
maxRevenueWithdrawPerPeriod: BN,
|
|
924
|
+
quoteMaxInsurance: BN
|
|
925
|
+
): Promise<TransactionSignature> {
|
|
926
|
+
return await this.program.rpc.updateMarketMaxImbalances(
|
|
927
|
+
unrealizedMaxImbalance,
|
|
928
|
+
maxRevenueWithdrawPerPeriod,
|
|
929
|
+
quoteMaxInsurance,
|
|
930
|
+
{
|
|
931
|
+
accounts: {
|
|
932
|
+
admin: this.wallet.publicKey,
|
|
933
|
+
state: await this.getStatePublicKey(),
|
|
934
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
935
|
+
},
|
|
936
|
+
}
|
|
937
|
+
);
|
|
938
|
+
}
|
|
804
939
|
}
|