@drift-labs/sdk 2.18.0 → 2.19.1
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/bulkAccountLoader.d.ts +2 -1
- package/lib/accounts/bulkAccountLoader.js +3 -3
- package/lib/accounts/fetch.js +2 -2
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
- package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/accounts/types.d.ts +5 -4
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.js +5 -1
- package/lib/adminClient.js +61 -57
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/perpMarkets.js +33 -3
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +4 -4
- package/lib/dlob/DLOB.js +89 -76
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +2 -2
- package/lib/dlob/NodeList.js +4 -4
- package/lib/driftClient.d.ts +1 -1
- package/lib/driftClient.js +99 -95
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +14 -14
- package/lib/examples/loadDlob.js +2 -2
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +13 -13
- package/lib/factory/oracleClient.js +6 -3
- package/lib/idl/drift.json +7 -4
- package/lib/index.js +5 -1
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +33 -38
- package/lib/math/auction.js +6 -6
- package/lib/math/exchangeStatus.js +2 -2
- package/lib/math/funding.js +2 -2
- package/lib/math/margin.js +4 -4
- package/lib/math/market.js +15 -15
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +24 -24
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +9 -9
- package/lib/math/spotMarket.js +3 -3
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +43 -43
- package/lib/math/utils.js +1 -1
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/serumSubscriber.d.ts +4 -3
- package/lib/serum/serumSubscriber.js +40 -11
- package/lib/serum/types.d.ts +3 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/tokenFaucet.js +5 -1
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +49 -46
- package/lib/types.js +2 -1
- package/lib/user.js +63 -63
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/constants/perpMarkets.ts +33 -3
- package/src/dlob/DLOB.ts +17 -5
- package/src/dlob/NodeList.ts +2 -5
- package/src/factory/oracleClient.ts +5 -1
- package/src/idl/drift.json +7 -4
- package/src/math/amm.ts +22 -23
- package/src/math/trade.ts +1 -1
- package/src/serum/serumSubscriber.ts +62 -20
- package/src/serum/types.ts +9 -5
- package/src/types.ts +2 -1
- package/tests/amm/test.ts +177 -5
- package/tests/dlob/test.ts +2 -1
package/lib/adminClient.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];
|
|
@@ -38,7 +42,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
38
42
|
if (stateAccountRPCResponse.value !== null) {
|
|
39
43
|
throw new Error('Clearing house already initialized');
|
|
40
44
|
}
|
|
41
|
-
const [driftStatePublicKey] = await pda_1.getDriftStateAccountPublicKeyAndNonce(this.program.programId);
|
|
45
|
+
const [driftStatePublicKey] = await (0, pda_1.getDriftStateAccountPublicKeyAndNonce)(this.program.programId);
|
|
42
46
|
const initializeTx = await this.program.transaction.initialize({
|
|
43
47
|
accounts: {
|
|
44
48
|
admin: this.wallet.publicKey,
|
|
@@ -55,10 +59,10 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
55
59
|
}
|
|
56
60
|
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
57
61
|
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
58
|
-
const spotMarket = await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex);
|
|
59
|
-
const spotMarketVault = await pda_1.getSpotMarketVaultPublicKey(this.program.programId, spotMarketIndex);
|
|
60
|
-
const insuranceFundVault = await pda_1.getInsuranceFundVaultPublicKey(this.program.programId, spotMarketIndex);
|
|
61
|
-
const nameBuffer = userName_1.encodeName(name);
|
|
62
|
+
const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
63
|
+
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
64
|
+
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
65
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
62
66
|
const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, activeStatus, nameBuffer, {
|
|
63
67
|
accounts: {
|
|
64
68
|
admin: this.wallet.publicKey,
|
|
@@ -83,8 +87,8 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
83
87
|
return txSig;
|
|
84
88
|
}
|
|
85
89
|
async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
|
|
86
|
-
const serumOpenOrders = pda_1.getSerumOpenOrdersPublicKey(this.program.programId, serumMarket);
|
|
87
|
-
const serumFulfillmentConfig = pda_1.getSerumFulfillmentConfigPublicKey(this.program.programId, serumMarket);
|
|
90
|
+
const serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
|
|
91
|
+
const serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
88
92
|
const tx = await this.program.transaction.initializeSerumFulfillmentConfig(marketIndex, {
|
|
89
93
|
accounts: {
|
|
90
94
|
admin: this.wallet.publicKey,
|
|
@@ -105,8 +109,8 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
105
109
|
}
|
|
106
110
|
async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
107
111
|
const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
|
|
108
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, currentPerpMarketIndex);
|
|
109
|
-
const nameBuffer = userName_1.encodeName(name);
|
|
112
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, currentPerpMarketIndex);
|
|
113
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
110
114
|
const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
|
|
111
115
|
accounts: {
|
|
112
116
|
state: await this.getStatePublicKey(),
|
|
@@ -129,9 +133,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
129
133
|
return txSig;
|
|
130
134
|
}
|
|
131
135
|
async moveAmmPrice(perpMarketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
|
|
132
|
-
const marketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
136
|
+
const marketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
133
137
|
if (sqrtK == undefined) {
|
|
134
|
-
sqrtK = utils_1.squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
|
|
138
|
+
sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
|
|
135
139
|
}
|
|
136
140
|
const tx = await this.program.transaction.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
|
|
137
141
|
accounts: {
|
|
@@ -148,7 +152,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
148
152
|
accounts: {
|
|
149
153
|
state: await this.getStatePublicKey(),
|
|
150
154
|
admin: this.wallet.publicKey,
|
|
151
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
155
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
152
156
|
oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
|
|
153
157
|
},
|
|
154
158
|
});
|
|
@@ -160,16 +164,16 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
160
164
|
accounts: {
|
|
161
165
|
state: await this.getStatePublicKey(),
|
|
162
166
|
admin: this.wallet.publicKey,
|
|
163
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
167
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
164
168
|
},
|
|
165
169
|
});
|
|
166
170
|
}
|
|
167
171
|
async moveAmmToPrice(perpMarketIndex, targetPrice) {
|
|
168
172
|
const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
|
|
169
|
-
const [direction, tradeSize, _] = trade_1.calculateTargetPriceTrade(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
|
|
173
|
+
const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
|
|
170
174
|
);
|
|
171
|
-
const [newQuoteAssetAmount, newBaseAssetAmount] = amm_1.calculateAmmReservesAfterSwap(perpMarket.amm, 'quote', tradeSize, amm_1.getSwapDirection('quote', direction));
|
|
172
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
175
|
+
const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(perpMarket.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
|
|
176
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
173
177
|
const tx = await this.program.transaction.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, perpMarket.amm.sqrtK, {
|
|
174
178
|
accounts: {
|
|
175
179
|
state: await this.getStatePublicKey(),
|
|
@@ -181,7 +185,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
181
185
|
return txSig;
|
|
182
186
|
}
|
|
183
187
|
async repegAmmCurve(newPeg, perpMarketIndex) {
|
|
184
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
188
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
185
189
|
const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
|
|
186
190
|
const tx = await this.program.transaction.repegAmmCurve(newPeg, {
|
|
187
191
|
accounts: {
|
|
@@ -196,7 +200,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
196
200
|
}
|
|
197
201
|
async updatePerpMarketAmmOracleTwap(perpMarketIndex) {
|
|
198
202
|
const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
|
|
199
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
203
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
200
204
|
return await this.program.rpc.updatePerpMarketAmmOracleTwap({
|
|
201
205
|
accounts: {
|
|
202
206
|
state: await this.getStatePublicKey(),
|
|
@@ -208,7 +212,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
208
212
|
}
|
|
209
213
|
async resetPerpMarketAmmOracleTwap(perpMarketIndex) {
|
|
210
214
|
const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
|
|
211
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
215
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
212
216
|
return await this.program.rpc.resetPerpMarketAmmOracleTwap({
|
|
213
217
|
accounts: {
|
|
214
218
|
state: await this.getStatePublicKey(),
|
|
@@ -224,7 +228,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
224
228
|
accounts: {
|
|
225
229
|
admin: this.wallet.publicKey,
|
|
226
230
|
state: await this.getStatePublicKey(),
|
|
227
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
231
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
228
232
|
sourceVault,
|
|
229
233
|
driftSigner: this.getSignerPublicKey(),
|
|
230
234
|
quoteSpotMarket: spotMarket.pubkey,
|
|
@@ -252,7 +256,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
252
256
|
accounts: {
|
|
253
257
|
admin: this.wallet.publicKey,
|
|
254
258
|
state: await this.getStatePublicKey(),
|
|
255
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
259
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
256
260
|
},
|
|
257
261
|
});
|
|
258
262
|
}
|
|
@@ -261,7 +265,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
261
265
|
accounts: {
|
|
262
266
|
admin: this.wallet.publicKey,
|
|
263
267
|
state: await this.getStatePublicKey(),
|
|
264
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
268
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
265
269
|
},
|
|
266
270
|
});
|
|
267
271
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -272,7 +276,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
272
276
|
accounts: {
|
|
273
277
|
admin: this.wallet.publicKey,
|
|
274
278
|
state: await this.getStatePublicKey(),
|
|
275
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
279
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
276
280
|
},
|
|
277
281
|
});
|
|
278
282
|
}
|
|
@@ -281,7 +285,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
281
285
|
accounts: {
|
|
282
286
|
admin: this.wallet.publicKey,
|
|
283
287
|
state: await this.getStatePublicKey(),
|
|
284
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
288
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
285
289
|
},
|
|
286
290
|
});
|
|
287
291
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -292,36 +296,36 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
292
296
|
accounts: {
|
|
293
297
|
admin: this.wallet.publicKey,
|
|
294
298
|
state: await this.getStatePublicKey(),
|
|
295
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
299
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
296
300
|
},
|
|
297
301
|
});
|
|
298
302
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
299
303
|
return txSig;
|
|
300
304
|
}
|
|
301
305
|
async updatePerpMarketName(perpMarketIndex, name) {
|
|
302
|
-
const nameBuffer = userName_1.encodeName(name);
|
|
306
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
303
307
|
const tx = await this.program.transaction.updatePerpMarketName(nameBuffer, {
|
|
304
308
|
accounts: {
|
|
305
309
|
admin: this.wallet.publicKey,
|
|
306
310
|
state: await this.getStatePublicKey(),
|
|
307
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
311
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
308
312
|
},
|
|
309
313
|
});
|
|
310
314
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
311
315
|
return txSig;
|
|
312
316
|
}
|
|
313
317
|
async updateSpotMarketName(spotMarketIndex, name) {
|
|
314
|
-
const nameBuffer = userName_1.encodeName(name);
|
|
318
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
315
319
|
return await this.program.rpc.updateSpotMarketName(nameBuffer, {
|
|
316
320
|
accounts: {
|
|
317
321
|
admin: this.wallet.publicKey,
|
|
318
322
|
state: await this.getStatePublicKey(),
|
|
319
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
323
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
320
324
|
},
|
|
321
325
|
});
|
|
322
326
|
}
|
|
323
327
|
async updatePerpMarketMaxSpread(perpMarketIndex, maxSpread) {
|
|
324
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
328
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
325
329
|
return await this.program.rpc.updatePerpMarketMaxSpread(maxSpread, {
|
|
326
330
|
accounts: {
|
|
327
331
|
admin: this.wallet.publicKey,
|
|
@@ -389,7 +393,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
389
393
|
accounts: {
|
|
390
394
|
admin: this.wallet.publicKey,
|
|
391
395
|
state: await this.getStatePublicKey(),
|
|
392
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
396
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
393
397
|
},
|
|
394
398
|
});
|
|
395
399
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -400,7 +404,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
400
404
|
accounts: {
|
|
401
405
|
admin: this.wallet.publicKey,
|
|
402
406
|
state: await this.getStatePublicKey(),
|
|
403
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
407
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
404
408
|
},
|
|
405
409
|
});
|
|
406
410
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -411,7 +415,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
411
415
|
accounts: {
|
|
412
416
|
admin: this.wallet.publicKey,
|
|
413
417
|
state: await this.getStatePublicKey(),
|
|
414
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
418
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
415
419
|
},
|
|
416
420
|
});
|
|
417
421
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -422,7 +426,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
422
426
|
accounts: {
|
|
423
427
|
admin: this.wallet.publicKey,
|
|
424
428
|
state: await this.getStatePublicKey(),
|
|
425
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
429
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
426
430
|
},
|
|
427
431
|
});
|
|
428
432
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -433,7 +437,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
433
437
|
accounts: {
|
|
434
438
|
admin: this.wallet.publicKey,
|
|
435
439
|
state: await this.getStatePublicKey(),
|
|
436
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
440
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
437
441
|
},
|
|
438
442
|
});
|
|
439
443
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -454,7 +458,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
454
458
|
accounts: {
|
|
455
459
|
admin: this.wallet.publicKey,
|
|
456
460
|
state: await this.getStatePublicKey(),
|
|
457
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
461
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
458
462
|
oracle: oracle,
|
|
459
463
|
},
|
|
460
464
|
});
|
|
@@ -466,7 +470,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
466
470
|
accounts: {
|
|
467
471
|
admin: this.wallet.publicKey,
|
|
468
472
|
state: await this.getStatePublicKey(),
|
|
469
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
473
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
470
474
|
},
|
|
471
475
|
});
|
|
472
476
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -477,7 +481,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
477
481
|
accounts: {
|
|
478
482
|
admin: this.wallet.publicKey,
|
|
479
483
|
state: await this.getStatePublicKey(),
|
|
480
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
484
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
481
485
|
},
|
|
482
486
|
});
|
|
483
487
|
}
|
|
@@ -486,7 +490,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
486
490
|
accounts: {
|
|
487
491
|
admin: this.wallet.publicKey,
|
|
488
492
|
state: await this.getStatePublicKey(),
|
|
489
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
493
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
490
494
|
},
|
|
491
495
|
});
|
|
492
496
|
}
|
|
@@ -495,7 +499,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
495
499
|
accounts: {
|
|
496
500
|
admin: this.wallet.publicKey,
|
|
497
501
|
state: await this.getStatePublicKey(),
|
|
498
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
502
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
499
503
|
},
|
|
500
504
|
});
|
|
501
505
|
}
|
|
@@ -504,7 +508,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
504
508
|
accounts: {
|
|
505
509
|
admin: this.wallet.publicKey,
|
|
506
510
|
state: await this.getStatePublicKey(),
|
|
507
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
511
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
508
512
|
},
|
|
509
513
|
});
|
|
510
514
|
}
|
|
@@ -513,7 +517,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
513
517
|
accounts: {
|
|
514
518
|
admin: this.wallet.publicKey,
|
|
515
519
|
state: await this.getStatePublicKey(),
|
|
516
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
520
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
517
521
|
oracle: oracle,
|
|
518
522
|
},
|
|
519
523
|
});
|
|
@@ -523,7 +527,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
523
527
|
accounts: {
|
|
524
528
|
admin: this.wallet.publicKey,
|
|
525
529
|
state: await this.getStatePublicKey(),
|
|
526
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
530
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
527
531
|
},
|
|
528
532
|
});
|
|
529
533
|
}
|
|
@@ -541,7 +545,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
541
545
|
accounts: {
|
|
542
546
|
admin: this.wallet.publicKey,
|
|
543
547
|
state: await this.getStatePublicKey(),
|
|
544
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
548
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
545
549
|
},
|
|
546
550
|
});
|
|
547
551
|
}
|
|
@@ -570,7 +574,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
570
574
|
accounts: {
|
|
571
575
|
admin: this.wallet.publicKey,
|
|
572
576
|
state: await this.getStatePublicKey(),
|
|
573
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
577
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
574
578
|
},
|
|
575
579
|
});
|
|
576
580
|
}
|
|
@@ -579,7 +583,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
579
583
|
accounts: {
|
|
580
584
|
admin: this.wallet.publicKey,
|
|
581
585
|
state: await this.getStatePublicKey(),
|
|
582
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
586
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
583
587
|
},
|
|
584
588
|
});
|
|
585
589
|
}
|
|
@@ -588,7 +592,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
588
592
|
accounts: {
|
|
589
593
|
admin: this.wallet.publicKey,
|
|
590
594
|
state: await this.getStatePublicKey(),
|
|
591
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
595
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
592
596
|
},
|
|
593
597
|
});
|
|
594
598
|
const { txSig } = await this.sendTransaction(tx);
|
|
@@ -599,7 +603,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
599
603
|
accounts: {
|
|
600
604
|
admin: this.wallet.publicKey,
|
|
601
605
|
state: await this.getStatePublicKey(),
|
|
602
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
606
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
603
607
|
},
|
|
604
608
|
});
|
|
605
609
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -610,7 +614,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
610
614
|
accounts: {
|
|
611
615
|
admin: this.wallet.publicKey,
|
|
612
616
|
state: await this.getStatePublicKey(),
|
|
613
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
617
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
614
618
|
},
|
|
615
619
|
});
|
|
616
620
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -621,7 +625,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
621
625
|
accounts: {
|
|
622
626
|
admin: this.wallet.publicKey,
|
|
623
627
|
state: await this.getStatePublicKey(),
|
|
624
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
628
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
625
629
|
},
|
|
626
630
|
});
|
|
627
631
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -658,7 +662,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
658
662
|
accounts: {
|
|
659
663
|
admin: this.wallet.publicKey,
|
|
660
664
|
state: await this.getStatePublicKey(),
|
|
661
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
665
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
662
666
|
},
|
|
663
667
|
});
|
|
664
668
|
}
|
|
@@ -676,7 +680,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
676
680
|
accounts: {
|
|
677
681
|
admin: this.wallet.publicKey,
|
|
678
682
|
state: await this.getStatePublicKey(),
|
|
679
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
683
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
680
684
|
},
|
|
681
685
|
});
|
|
682
686
|
}
|
|
@@ -685,7 +689,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
685
689
|
accounts: {
|
|
686
690
|
admin: this.wallet.publicKey,
|
|
687
691
|
state: await this.getStatePublicKey(),
|
|
688
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
692
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
689
693
|
},
|
|
690
694
|
});
|
|
691
695
|
}
|
|
@@ -694,7 +698,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
694
698
|
accounts: {
|
|
695
699
|
admin: this.wallet.publicKey,
|
|
696
700
|
state: await this.getStatePublicKey(),
|
|
697
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
701
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
698
702
|
},
|
|
699
703
|
});
|
|
700
704
|
}
|
|
@@ -712,7 +716,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
712
716
|
accounts: {
|
|
713
717
|
admin: this.wallet.publicKey,
|
|
714
718
|
state: await this.getStatePublicKey(),
|
|
715
|
-
perpMarket: await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex),
|
|
719
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
716
720
|
},
|
|
717
721
|
});
|
|
718
722
|
}
|
|
@@ -721,7 +725,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
721
725
|
accounts: {
|
|
722
726
|
admin: this.wallet.publicKey,
|
|
723
727
|
state: await this.getStatePublicKey(),
|
|
724
|
-
spotMarket: await pda_1.getSpotMarketPublicKey(this.program.programId, spotMarketIndex),
|
|
728
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
725
729
|
},
|
|
726
730
|
});
|
|
727
731
|
}
|
package/lib/config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PerpMarketConfig } from './constants/perpMarkets';
|
|
2
2
|
import { SpotMarketConfig } from './constants/spotMarkets';
|
|
3
3
|
import { OracleInfo } from './oracles/types';
|
|
4
|
-
|
|
4
|
+
type DriftConfig = {
|
|
5
5
|
ENV: DriftEnv;
|
|
6
6
|
PYTH_ORACLE_MAPPING_ADDRESS: string;
|
|
7
7
|
DRIFT_PROGRAM_ID: string;
|
|
@@ -12,7 +12,7 @@ declare type DriftConfig = {
|
|
|
12
12
|
SPOT_MARKETS: SpotMarketConfig[];
|
|
13
13
|
MARKET_LOOKUP_TABLE: string;
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type DriftEnv = 'devnet' | 'mainnet-beta';
|
|
16
16
|
export declare const configs: {
|
|
17
17
|
[key in DriftEnv]: DriftConfig;
|
|
18
18
|
};
|
|
@@ -47,12 +47,22 @@ exports.DevnetPerpMarkets = [
|
|
|
47
47
|
{
|
|
48
48
|
fullName: 'Bonk',
|
|
49
49
|
category: ['Meme'],
|
|
50
|
-
symbol: '
|
|
51
|
-
baseAssetSymbol: '
|
|
50
|
+
symbol: '1MBONK-PERP',
|
|
51
|
+
baseAssetSymbol: '1MBONK',
|
|
52
52
|
marketIndex: 4,
|
|
53
53
|
oracle: new web3_js_1.PublicKey('6bquU99ktV1VRiHDr8gMhDFt3kMfhCQo5nfNrg2Urvsn'),
|
|
54
54
|
launchTs: 1677068931000,
|
|
55
|
-
oracleSource: __1.OracleSource.
|
|
55
|
+
oracleSource: __1.OracleSource.PYTH_1M,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
fullName: 'Polygon',
|
|
59
|
+
category: ['L2', 'Infra'],
|
|
60
|
+
symbol: 'MATIC-PERP',
|
|
61
|
+
baseAssetSymbol: 'MATIC',
|
|
62
|
+
marketIndex: 5,
|
|
63
|
+
oracle: new web3_js_1.PublicKey('FBirwuDFuRAu4iSGc7RGxN5koHB7EJM1wbCmyPuQoGur'),
|
|
64
|
+
launchTs: 1677690149000,
|
|
65
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
56
66
|
},
|
|
57
67
|
];
|
|
58
68
|
exports.MainnetPerpMarkets = [
|
|
@@ -96,6 +106,26 @@ exports.MainnetPerpMarkets = [
|
|
|
96
106
|
launchTs: 1675802661000,
|
|
97
107
|
oracleSource: __1.OracleSource.PYTH,
|
|
98
108
|
},
|
|
109
|
+
{
|
|
110
|
+
fullName: 'Bonk',
|
|
111
|
+
category: ['Meme'],
|
|
112
|
+
symbol: '1MBONK-PERP',
|
|
113
|
+
baseAssetSymbol: '1MBONK',
|
|
114
|
+
marketIndex: 4,
|
|
115
|
+
oracle: new web3_js_1.PublicKey('8ihFLu5FimgTQ1Unh4dVyEHUGodJ5gJQCrQf4KUVB9bN'),
|
|
116
|
+
launchTs: 1677690149000,
|
|
117
|
+
oracleSource: __1.OracleSource.PYTH_1M,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
fullName: 'Polygon',
|
|
121
|
+
category: ['L2', 'Infra'],
|
|
122
|
+
symbol: 'MATIC-PERP',
|
|
123
|
+
baseAssetSymbol: 'MATIC',
|
|
124
|
+
marketIndex: 5,
|
|
125
|
+
oracle: new web3_js_1.PublicKey('7KVswB9vkCgeM3SHP7aGDijvdRAHK8P5wi9JXViCrtYh'),
|
|
126
|
+
launchTs: 1677690149000,
|
|
127
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
128
|
+
},
|
|
99
129
|
];
|
|
100
130
|
exports.PerpMarkets = {
|
|
101
131
|
devnet: exports.DevnetPerpMarkets,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BN, DriftEnv, OracleSource } from '../';
|
|
4
|
-
export
|
|
4
|
+
export type SpotMarketConfig = {
|
|
5
5
|
symbol: string;
|
|
6
6
|
marketIndex: number;
|
|
7
7
|
oracle: PublicKey;
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccoun
|
|
|
4
4
|
import { PublicKey } from '@solana/web3.js';
|
|
5
5
|
import { DLOBNode, DLOBNodeType, TriggerOrderNode } from '..';
|
|
6
6
|
import { DLOBOrders } from './DLOBOrders';
|
|
7
|
-
export
|
|
7
|
+
export type MarketNodeLists = {
|
|
8
8
|
restingLimit: {
|
|
9
9
|
ask: NodeList<'restingLimit'>;
|
|
10
10
|
bid: NodeList<'restingLimit'>;
|
|
@@ -26,12 +26,12 @@ export declare type MarketNodeLists = {
|
|
|
26
26
|
below: NodeList<'trigger'>;
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
-
|
|
30
|
-
export
|
|
29
|
+
type OrderBookCallback = () => void;
|
|
30
|
+
export type NodeToFill = {
|
|
31
31
|
node: DLOBNode;
|
|
32
32
|
makerNode?: DLOBNode;
|
|
33
33
|
};
|
|
34
|
-
export
|
|
34
|
+
export type NodeToTrigger = {
|
|
35
35
|
node: TriggerOrderNode;
|
|
36
36
|
};
|
|
37
37
|
export declare class DLOB {
|