@drift-labs/sdk 2.65.0-beta.9 → 2.66.0-beta.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/VERSION +1 -1
- package/lib/adminClient.js +83 -44
- package/lib/constants/spotMarkets.js +11 -0
- package/lib/events/eventSubscriber.js +1 -1
- package/lib/events/fetchLogs.js +3 -3
- package/lib/events/parse.d.ts +1 -1
- package/lib/events/parse.js +4 -1
- package/lib/idl/drift.json +1 -1
- package/package.json +1 -1
- package/src/adminClient.ts +364 -261
- package/src/constants/spotMarkets.ts +11 -0
- package/src/events/eventSubscriber.ts +1 -1
- package/src/events/fetchLogs.ts +3 -6
- package/src/events/parse.ts +5 -5
- package/src/idl/drift.json +1 -1
- package/tests/amm/test.ts +8 -2
- package/tests/dlob/helpers.ts +40 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.66.0-beta.1
|
package/lib/adminClient.js
CHANGED
|
@@ -44,7 +44,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
44
44
|
throw new Error('Clearing house already initialized');
|
|
45
45
|
}
|
|
46
46
|
const [driftStatePublicKey] = await (0, pda_1.getDriftStateAccountPublicKeyAndNonce)(this.program.programId);
|
|
47
|
-
const
|
|
47
|
+
const initializeIx = await this.program.instruction.initialize({
|
|
48
48
|
accounts: {
|
|
49
49
|
admin: this.wallet.publicKey,
|
|
50
50
|
state: driftStatePublicKey,
|
|
@@ -55,8 +55,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
55
55
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
56
56
|
},
|
|
57
57
|
});
|
|
58
|
-
const
|
|
59
|
-
|
|
58
|
+
const tx = await this.buildTransaction(initializeIx);
|
|
59
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
60
|
+
return [txSig];
|
|
60
61
|
}
|
|
61
62
|
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
62
63
|
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
@@ -64,7 +65,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
64
65
|
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
65
66
|
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
66
67
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
67
|
-
const
|
|
68
|
+
const initializeIx = await this.program.instruction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, activeStatus, nameBuffer, {
|
|
68
69
|
accounts: {
|
|
69
70
|
admin: this.wallet.publicKey,
|
|
70
71
|
state: await this.getStatePublicKey(),
|
|
@@ -79,7 +80,9 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
79
80
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
80
81
|
},
|
|
81
82
|
});
|
|
82
|
-
const
|
|
83
|
+
const tx = await this.buildTransaction(initializeIx);
|
|
84
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
85
|
+
// const { txSig } = await this.sendTransaction(initializeTx, [], this.opts);
|
|
83
86
|
await this.accountSubscriber.addSpotMarket(spotMarketIndex);
|
|
84
87
|
await this.accountSubscriber.addOracle({
|
|
85
88
|
source: oracleSource,
|
|
@@ -90,7 +93,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
90
93
|
async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
|
|
91
94
|
const serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
|
|
92
95
|
const serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
93
|
-
const
|
|
96
|
+
const initializeIx = await this.program.instruction.initializeSerumFulfillmentConfig(marketIndex, {
|
|
94
97
|
accounts: {
|
|
95
98
|
admin: this.wallet.publicKey,
|
|
96
99
|
state: await this.getStatePublicKey(),
|
|
@@ -105,12 +108,13 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
105
108
|
serumFulfillmentConfig,
|
|
106
109
|
},
|
|
107
110
|
});
|
|
111
|
+
const tx = await this.buildTransaction(initializeIx);
|
|
108
112
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
109
113
|
return txSig;
|
|
110
114
|
}
|
|
111
115
|
async initializePhoenixFulfillmentConfig(marketIndex, phoenixMarket) {
|
|
112
116
|
const phoenixFulfillmentConfig = (0, pda_1.getPhoenixFulfillmentConfigPublicKey)(this.program.programId, phoenixMarket);
|
|
113
|
-
const
|
|
117
|
+
const initializeIx = await this.program.instruction.initializePhoenixFulfillmentConfig(marketIndex, {
|
|
114
118
|
accounts: {
|
|
115
119
|
admin: this.wallet.publicKey,
|
|
116
120
|
state: await this.getStatePublicKey(),
|
|
@@ -124,6 +128,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
124
128
|
phoenixFulfillmentConfig,
|
|
125
129
|
},
|
|
126
130
|
});
|
|
131
|
+
const tx = await this.buildTransaction(initializeIx);
|
|
127
132
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
128
133
|
return txSig;
|
|
129
134
|
}
|
|
@@ -131,7 +136,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
131
136
|
const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
|
|
132
137
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, currentPerpMarketIndex);
|
|
133
138
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
134
|
-
const
|
|
139
|
+
const initializeMarketIx = await this.program.instruction.initializePerpMarket(marketIndex, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
|
|
135
140
|
accounts: {
|
|
136
141
|
state: await this.getStatePublicKey(),
|
|
137
142
|
admin: this.wallet.publicKey,
|
|
@@ -141,7 +146,8 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
141
146
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
142
147
|
},
|
|
143
148
|
});
|
|
144
|
-
const
|
|
149
|
+
const tx = await this.buildTransaction(initializeMarketIx);
|
|
150
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
145
151
|
while (this.getStateAccount().numberOfMarkets <= currentPerpMarketIndex) {
|
|
146
152
|
await this.fetchAccounts();
|
|
147
153
|
}
|
|
@@ -154,14 +160,15 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
154
160
|
}
|
|
155
161
|
async deleteInitializedPerpMarket(marketIndex) {
|
|
156
162
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
157
|
-
const
|
|
163
|
+
const deleteInitializeMarketIx = await this.program.instruction.deleteInitializedPerpMarket(marketIndex, {
|
|
158
164
|
accounts: {
|
|
159
165
|
state: await this.getStatePublicKey(),
|
|
160
166
|
admin: this.wallet.publicKey,
|
|
161
167
|
perpMarket: perpMarketPublicKey,
|
|
162
168
|
},
|
|
163
169
|
});
|
|
164
|
-
const
|
|
170
|
+
const tx = await this.buildTransaction(deleteInitializeMarketIx);
|
|
171
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
165
172
|
return txSig;
|
|
166
173
|
}
|
|
167
174
|
async moveAmmPrice(perpMarketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
|
|
@@ -169,18 +176,19 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
169
176
|
if (sqrtK == undefined) {
|
|
170
177
|
sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
|
|
171
178
|
}
|
|
172
|
-
const
|
|
179
|
+
const moveAmmPriceIx = await this.program.instruction.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
|
|
173
180
|
accounts: {
|
|
174
181
|
state: await this.getStatePublicKey(),
|
|
175
182
|
admin: this.wallet.publicKey,
|
|
176
183
|
perpMarket: marketPublicKey,
|
|
177
184
|
},
|
|
178
185
|
});
|
|
186
|
+
const tx = await this.buildTransaction(moveAmmPriceIx);
|
|
179
187
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
180
188
|
return txSig;
|
|
181
189
|
}
|
|
182
190
|
async updateK(perpMarketIndex, sqrtK) {
|
|
183
|
-
const
|
|
191
|
+
const updateKIx = await this.program.instruction.updateK(sqrtK, {
|
|
184
192
|
accounts: {
|
|
185
193
|
state: await this.getStatePublicKey(),
|
|
186
194
|
admin: this.wallet.publicKey,
|
|
@@ -188,18 +196,20 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
188
196
|
oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
|
|
189
197
|
},
|
|
190
198
|
});
|
|
199
|
+
const tx = await this.buildTransaction(updateKIx);
|
|
191
200
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
192
201
|
return txSig;
|
|
193
202
|
}
|
|
194
203
|
async recenterPerpMarketAmm(perpMarketIndex, pegMultiplier, sqrtK) {
|
|
195
204
|
const marketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
196
|
-
const
|
|
205
|
+
const recenterPerpMarketAmmIx = await this.program.instruction.recenterPerpMarketAmm(pegMultiplier, sqrtK, {
|
|
197
206
|
accounts: {
|
|
198
207
|
state: await this.getStatePublicKey(),
|
|
199
208
|
admin: this.wallet.publicKey,
|
|
200
209
|
perpMarket: marketPublicKey,
|
|
201
210
|
},
|
|
202
211
|
});
|
|
212
|
+
const tx = await this.buildTransaction(recenterPerpMarketAmmIx);
|
|
203
213
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
204
214
|
return txSig;
|
|
205
215
|
}
|
|
@@ -218,20 +228,21 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
218
228
|
);
|
|
219
229
|
const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(perpMarket.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
|
|
220
230
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
221
|
-
const
|
|
231
|
+
const moveAmmPriceIx = await this.program.instruction.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, perpMarket.amm.sqrtK, {
|
|
222
232
|
accounts: {
|
|
223
233
|
state: await this.getStatePublicKey(),
|
|
224
234
|
admin: this.wallet.publicKey,
|
|
225
235
|
perpMarket: perpMarketPublicKey,
|
|
226
236
|
},
|
|
227
237
|
});
|
|
238
|
+
const tx = await this.buildTransaction(moveAmmPriceIx);
|
|
228
239
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
229
240
|
return txSig;
|
|
230
241
|
}
|
|
231
242
|
async repegAmmCurve(newPeg, perpMarketIndex) {
|
|
232
243
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
233
244
|
const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
|
|
234
|
-
const
|
|
245
|
+
const repegAmmCurveIx = await this.program.instruction.repegAmmCurve(newPeg, {
|
|
235
246
|
accounts: {
|
|
236
247
|
state: await this.getStatePublicKey(),
|
|
237
248
|
admin: this.wallet.publicKey,
|
|
@@ -239,6 +250,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
239
250
|
perpMarket: perpMarketPublicKey,
|
|
240
251
|
},
|
|
241
252
|
});
|
|
253
|
+
const tx = await this.buildTransaction(repegAmmCurveIx);
|
|
242
254
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
243
255
|
return txSig;
|
|
244
256
|
}
|
|
@@ -268,7 +280,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
268
280
|
}
|
|
269
281
|
async depositIntoPerpMarketFeePool(perpMarketIndex, amount, sourceVault) {
|
|
270
282
|
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
271
|
-
const
|
|
283
|
+
const depositIntoPerpMarketFeePoolIx = await this.program.instruction.depositIntoPerpMarketFeePool(amount, {
|
|
272
284
|
accounts: {
|
|
273
285
|
admin: this.wallet.publicKey,
|
|
274
286
|
state: await this.getStatePublicKey(),
|
|
@@ -280,16 +292,18 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
280
292
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
281
293
|
},
|
|
282
294
|
});
|
|
295
|
+
const tx = await this.buildTransaction(depositIntoPerpMarketFeePoolIx);
|
|
283
296
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
284
297
|
return txSig;
|
|
285
298
|
}
|
|
286
299
|
async updateAdmin(admin) {
|
|
287
|
-
const
|
|
300
|
+
const updateAdminIx = await this.program.instruction.updateAdmin(admin, {
|
|
288
301
|
accounts: {
|
|
289
302
|
admin: this.wallet.publicKey,
|
|
290
303
|
state: await this.getStatePublicKey(),
|
|
291
304
|
},
|
|
292
305
|
});
|
|
306
|
+
const tx = await this.buildTransaction(updateAdminIx);
|
|
293
307
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
294
308
|
return txSig;
|
|
295
309
|
}
|
|
@@ -314,13 +328,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
314
328
|
});
|
|
315
329
|
}
|
|
316
330
|
async updatePerpMarketMarginRatio(perpMarketIndex, marginRatioInitial, marginRatioMaintenance) {
|
|
317
|
-
const
|
|
331
|
+
const updatePerpMarketMarginRatioIx = await this.program.instruction.updatePerpMarketMarginRatio(marginRatioInitial, marginRatioMaintenance, {
|
|
318
332
|
accounts: {
|
|
319
333
|
admin: this.wallet.publicKey,
|
|
320
334
|
state: await this.getStatePublicKey(),
|
|
321
335
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
322
336
|
},
|
|
323
337
|
});
|
|
338
|
+
const tx = await this.buildTransaction(updatePerpMarketMarginRatioIx);
|
|
324
339
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
325
340
|
return txSig;
|
|
326
341
|
}
|
|
@@ -334,36 +349,39 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
334
349
|
});
|
|
335
350
|
}
|
|
336
351
|
async updatePerpMarketBaseSpread(perpMarketIndex, baseSpread) {
|
|
337
|
-
const
|
|
352
|
+
const updatePerpMarketBaseSpreadIx = await this.program.instruction.updatePerpMarketBaseSpread(baseSpread, {
|
|
338
353
|
accounts: {
|
|
339
354
|
admin: this.wallet.publicKey,
|
|
340
355
|
state: await this.getStatePublicKey(),
|
|
341
356
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
342
357
|
},
|
|
343
358
|
});
|
|
359
|
+
const tx = await this.buildTransaction(updatePerpMarketBaseSpreadIx);
|
|
344
360
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
345
361
|
return txSig;
|
|
346
362
|
}
|
|
347
363
|
async updateAmmJitIntensity(perpMarketIndex, ammJitIntensity) {
|
|
348
|
-
const
|
|
364
|
+
const updateAmmJitIntensityIx = await this.program.instruction.updateAmmJitIntensity(ammJitIntensity, {
|
|
349
365
|
accounts: {
|
|
350
366
|
admin: this.wallet.publicKey,
|
|
351
367
|
state: await this.getStatePublicKey(),
|
|
352
368
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
353
369
|
},
|
|
354
370
|
});
|
|
371
|
+
const tx = await this.buildTransaction(updateAmmJitIntensityIx);
|
|
355
372
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
356
373
|
return txSig;
|
|
357
374
|
}
|
|
358
375
|
async updatePerpMarketName(perpMarketIndex, name) {
|
|
359
376
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
360
|
-
const
|
|
377
|
+
const updatePerpMarketNameIx = await this.program.instruction.updatePerpMarketName(nameBuffer, {
|
|
361
378
|
accounts: {
|
|
362
379
|
admin: this.wallet.publicKey,
|
|
363
380
|
state: await this.getStatePublicKey(),
|
|
364
381
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
365
382
|
},
|
|
366
383
|
});
|
|
384
|
+
const tx = await this.buildTransaction(updatePerpMarketNameIx);
|
|
367
385
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
368
386
|
return txSig;
|
|
369
387
|
}
|
|
@@ -398,22 +416,24 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
398
416
|
});
|
|
399
417
|
}
|
|
400
418
|
async updatePerpFeeStructure(feeStructure) {
|
|
401
|
-
const
|
|
419
|
+
const updatePerpFeeStructureIx = this.program.instruction.updatePerpFeeStructure(feeStructure, {
|
|
402
420
|
accounts: {
|
|
403
421
|
admin: this.wallet.publicKey,
|
|
404
422
|
state: await this.getStatePublicKey(),
|
|
405
423
|
},
|
|
406
424
|
});
|
|
425
|
+
const tx = await this.buildTransaction(updatePerpFeeStructureIx);
|
|
407
426
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
408
427
|
return txSig;
|
|
409
428
|
}
|
|
410
429
|
async updateSpotFeeStructure(feeStructure) {
|
|
411
|
-
const
|
|
430
|
+
const updateSpotFeeStructureIx = await this.program.instruction.updateSpotFeeStructure(feeStructure, {
|
|
412
431
|
accounts: {
|
|
413
432
|
admin: this.wallet.publicKey,
|
|
414
433
|
state: await this.getStatePublicKey(),
|
|
415
434
|
},
|
|
416
435
|
});
|
|
436
|
+
const tx = await this.buildTransaction(updateSpotFeeStructureIx);
|
|
417
437
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
418
438
|
return txSig;
|
|
419
439
|
}
|
|
@@ -442,12 +462,13 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
442
462
|
});
|
|
443
463
|
}
|
|
444
464
|
async updateOracleGuardRails(oracleGuardRails) {
|
|
445
|
-
const
|
|
465
|
+
const updateOracleGuardRailsIx = await this.program.instruction.updateOracleGuardRails(oracleGuardRails, {
|
|
446
466
|
accounts: {
|
|
447
467
|
admin: this.wallet.publicKey,
|
|
448
468
|
state: await this.getStatePublicKey(),
|
|
449
469
|
},
|
|
450
470
|
});
|
|
471
|
+
const tx = await this.buildTransaction(updateOracleGuardRailsIx);
|
|
451
472
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
452
473
|
return txSig;
|
|
453
474
|
}
|
|
@@ -476,83 +497,90 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
476
497
|
});
|
|
477
498
|
}
|
|
478
499
|
async updateWithdrawGuardThreshold(spotMarketIndex, withdrawGuardThreshold) {
|
|
479
|
-
const
|
|
500
|
+
const updateWithdrawGuardThresholdIx = await this.program.instruction.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
|
|
480
501
|
accounts: {
|
|
481
502
|
admin: this.wallet.publicKey,
|
|
482
503
|
state: await this.getStatePublicKey(),
|
|
483
504
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
484
505
|
},
|
|
485
506
|
});
|
|
507
|
+
const tx = await this.buildTransaction(updateWithdrawGuardThresholdIx);
|
|
486
508
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
487
509
|
return txSig;
|
|
488
510
|
}
|
|
489
511
|
async updateSpotMarketIfFactor(spotMarketIndex, userIfFactor, totalIfFactor) {
|
|
490
|
-
const
|
|
512
|
+
const updateSpotMarketIfFactorIx = await this.program.instruction.updateSpotMarketIfFactor(spotMarketIndex, userIfFactor, totalIfFactor, {
|
|
491
513
|
accounts: {
|
|
492
514
|
admin: this.wallet.publicKey,
|
|
493
515
|
state: await this.getStatePublicKey(),
|
|
494
516
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
495
517
|
},
|
|
496
518
|
});
|
|
519
|
+
const tx = await this.buildTransaction(updateSpotMarketIfFactorIx);
|
|
497
520
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
498
521
|
return txSig;
|
|
499
522
|
}
|
|
500
523
|
async updateSpotMarketRevenueSettlePeriod(spotMarketIndex, revenueSettlePeriod) {
|
|
501
|
-
const
|
|
524
|
+
const updateSpotMarketRevenueSettlePeriodIx = await this.program.instruction.updateSpotMarketRevenueSettlePeriod(revenueSettlePeriod, {
|
|
502
525
|
accounts: {
|
|
503
526
|
admin: this.wallet.publicKey,
|
|
504
527
|
state: await this.getStatePublicKey(),
|
|
505
528
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
506
529
|
},
|
|
507
530
|
});
|
|
531
|
+
const tx = await this.buildTransaction(updateSpotMarketRevenueSettlePeriodIx);
|
|
508
532
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
509
533
|
return txSig;
|
|
510
534
|
}
|
|
511
535
|
async updateSpotMarketMaxTokenDeposits(spotMarketIndex, maxTokenDeposits) {
|
|
512
|
-
const
|
|
536
|
+
const updateSpotMarketMaxTokenDepositsIx = this.program.instruction.updateSpotMarketMaxTokenDeposits(maxTokenDeposits, {
|
|
513
537
|
accounts: {
|
|
514
538
|
admin: this.wallet.publicKey,
|
|
515
539
|
state: await this.getStatePublicKey(),
|
|
516
540
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
517
541
|
},
|
|
518
542
|
});
|
|
543
|
+
const tx = await this.buildTransaction(updateSpotMarketMaxTokenDepositsIx);
|
|
519
544
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
520
545
|
return txSig;
|
|
521
546
|
}
|
|
522
547
|
async updateSpotMarketScaleInitialAssetWeightStart(spotMarketIndex, scaleInitialAssetWeightStart) {
|
|
523
|
-
const
|
|
548
|
+
const updateSpotMarketScaleInitialAssetWeightStartIx = this.program.instruction.updateSpotMarketScaleInitialAssetWeightStart(scaleInitialAssetWeightStart, {
|
|
524
549
|
accounts: {
|
|
525
550
|
admin: this.wallet.publicKey,
|
|
526
551
|
state: await this.getStatePublicKey(),
|
|
527
552
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
528
553
|
},
|
|
529
554
|
});
|
|
555
|
+
const tx = await this.buildTransaction(updateSpotMarketScaleInitialAssetWeightStartIx);
|
|
530
556
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
531
557
|
return txSig;
|
|
532
558
|
}
|
|
533
559
|
async updateInsuranceFundUnstakingPeriod(spotMarketIndex, insuranceWithdrawEscrowPeriod) {
|
|
534
|
-
const
|
|
560
|
+
const updateInsuranceFundUnstakingPeriodIx = await this.program.instruction.updateInsuranceFundUnstakingPeriod(insuranceWithdrawEscrowPeriod, {
|
|
535
561
|
accounts: {
|
|
536
562
|
admin: this.wallet.publicKey,
|
|
537
563
|
state: await this.getStatePublicKey(),
|
|
538
564
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
539
565
|
},
|
|
540
566
|
});
|
|
567
|
+
const tx = await this.buildTransaction(updateInsuranceFundUnstakingPeriodIx);
|
|
541
568
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
542
569
|
return txSig;
|
|
543
570
|
}
|
|
544
571
|
async updateLpCooldownTime(cooldownTime) {
|
|
545
|
-
const
|
|
572
|
+
const updateLpCooldownTimeIx = await this.program.instruction.updateLpCooldownTime(cooldownTime, {
|
|
546
573
|
accounts: {
|
|
547
574
|
admin: this.wallet.publicKey,
|
|
548
575
|
state: await this.getStatePublicKey(),
|
|
549
576
|
},
|
|
550
577
|
});
|
|
578
|
+
const tx = await this.buildTransaction(updateLpCooldownTimeIx);
|
|
551
579
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
552
580
|
return txSig;
|
|
553
581
|
}
|
|
554
582
|
async updatePerpMarketOracle(perpMarketIndex, oracle, oracleSource) {
|
|
555
|
-
const
|
|
583
|
+
const updatePerpMarketOracleIx = await this.program.instruction.updatePerpMarketOracle(oracle, oracleSource, {
|
|
556
584
|
accounts: {
|
|
557
585
|
admin: this.wallet.publicKey,
|
|
558
586
|
state: await this.getStatePublicKey(),
|
|
@@ -560,17 +588,19 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
560
588
|
oracle: oracle,
|
|
561
589
|
},
|
|
562
590
|
});
|
|
591
|
+
const tx = await this.buildTransaction(updatePerpMarketOracleIx);
|
|
563
592
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
564
593
|
return txSig;
|
|
565
594
|
}
|
|
566
595
|
async updatePerpMarketStepSizeAndTickSize(perpMarketIndex, stepSize, tickSize) {
|
|
567
|
-
const
|
|
596
|
+
const updatePerpMarketStepSizeAndTickSizeIx = await this.program.instruction.updatePerpMarketStepSizeAndTickSize(stepSize, tickSize, {
|
|
568
597
|
accounts: {
|
|
569
598
|
admin: this.wallet.publicKey,
|
|
570
599
|
state: await this.getStatePublicKey(),
|
|
571
600
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
572
601
|
},
|
|
573
602
|
});
|
|
603
|
+
const tx = await this.buildTransaction(updatePerpMarketStepSizeAndTickSizeIx);
|
|
574
604
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
575
605
|
return txSig;
|
|
576
606
|
}
|
|
@@ -657,22 +687,24 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
657
687
|
});
|
|
658
688
|
}
|
|
659
689
|
async updateWhitelistMint(whitelistMint) {
|
|
660
|
-
const
|
|
690
|
+
const updateWhitelistMintIx = await this.program.instruction.updateWhitelistMint(whitelistMint, {
|
|
661
691
|
accounts: {
|
|
662
692
|
admin: this.wallet.publicKey,
|
|
663
693
|
state: await this.getStatePublicKey(),
|
|
664
694
|
},
|
|
665
695
|
});
|
|
696
|
+
const tx = await this.buildTransaction(updateWhitelistMintIx);
|
|
666
697
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
667
698
|
return txSig;
|
|
668
699
|
}
|
|
669
700
|
async updateDiscountMint(discountMint) {
|
|
670
|
-
const
|
|
701
|
+
const updateDiscountMintIx = await this.program.instruction.updateDiscountMint(discountMint, {
|
|
671
702
|
accounts: {
|
|
672
703
|
admin: this.wallet.publicKey,
|
|
673
704
|
state: await this.getStatePublicKey(),
|
|
674
705
|
},
|
|
675
706
|
});
|
|
707
|
+
const tx = await this.buildTransaction(updateDiscountMintIx);
|
|
676
708
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
677
709
|
return txSig;
|
|
678
710
|
}
|
|
@@ -695,78 +727,85 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
695
727
|
});
|
|
696
728
|
}
|
|
697
729
|
async updateSpotMarketAssetTier(spotMarketIndex, assetTier) {
|
|
698
|
-
const
|
|
730
|
+
const updateSpotMarketAssetTierIx = await this.program.instruction.updateSpotMarketAssetTier(assetTier, {
|
|
699
731
|
accounts: {
|
|
700
732
|
admin: this.wallet.publicKey,
|
|
701
733
|
state: await this.getStatePublicKey(),
|
|
702
734
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
703
735
|
},
|
|
704
736
|
});
|
|
705
|
-
const
|
|
737
|
+
const tx = await this.buildTransaction(updateSpotMarketAssetTierIx);
|
|
738
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
706
739
|
return txSig;
|
|
707
740
|
}
|
|
708
741
|
async updateSpotMarketStatus(spotMarketIndex, marketStatus) {
|
|
709
|
-
const
|
|
742
|
+
const updateSpotMarketStatusIx = await this.program.instruction.updateSpotMarketStatus(marketStatus, {
|
|
710
743
|
accounts: {
|
|
711
744
|
admin: this.wallet.publicKey,
|
|
712
745
|
state: await this.getStatePublicKey(),
|
|
713
746
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
714
747
|
},
|
|
715
748
|
});
|
|
749
|
+
const tx = await this.buildTransaction(updateSpotMarketStatusIx);
|
|
716
750
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
717
751
|
return txSig;
|
|
718
752
|
}
|
|
719
753
|
async updateSpotMarketPausedOperations(spotMarketIndex, pausedOperations) {
|
|
720
|
-
const
|
|
754
|
+
const updateSpotMarketPausedOperationsIx = await this.program.instruction.updateSpotMarketPausedOperations(pausedOperations, {
|
|
721
755
|
accounts: {
|
|
722
756
|
admin: this.wallet.publicKey,
|
|
723
757
|
state: await this.getStatePublicKey(),
|
|
724
758
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
725
759
|
},
|
|
726
760
|
});
|
|
761
|
+
const tx = await this.buildTransaction(updateSpotMarketPausedOperationsIx);
|
|
727
762
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
728
763
|
return txSig;
|
|
729
764
|
}
|
|
730
765
|
async updatePerpMarketStatus(perpMarketIndex, marketStatus) {
|
|
731
|
-
const
|
|
766
|
+
const updatePerpMarketStatusIx = await this.program.instruction.updatePerpMarketStatus(marketStatus, {
|
|
732
767
|
accounts: {
|
|
733
768
|
admin: this.wallet.publicKey,
|
|
734
769
|
state: await this.getStatePublicKey(),
|
|
735
770
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
736
771
|
},
|
|
737
772
|
});
|
|
773
|
+
const tx = await this.buildTransaction(updatePerpMarketStatusIx);
|
|
738
774
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
739
775
|
return txSig;
|
|
740
776
|
}
|
|
741
777
|
async updatePerpMarketPausedOperations(perpMarketIndex, pausedOperations) {
|
|
742
|
-
const
|
|
778
|
+
const updatePerpMarketPausedOperationsIx = await this.program.instruction.updatePerpMarketPausedOperations(pausedOperations, {
|
|
743
779
|
accounts: {
|
|
744
780
|
admin: this.wallet.publicKey,
|
|
745
781
|
state: await this.getStatePublicKey(),
|
|
746
782
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
747
783
|
},
|
|
748
784
|
});
|
|
785
|
+
const tx = await this.buildTransaction(updatePerpMarketPausedOperationsIx);
|
|
749
786
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
750
787
|
return txSig;
|
|
751
788
|
}
|
|
752
789
|
async updatePerpMarketContractTier(perpMarketIndex, contractTier) {
|
|
753
|
-
const
|
|
790
|
+
const updatePerpMarketContractTierIx = await this.program.instruction.updatePerpMarketContractTier(contractTier, {
|
|
754
791
|
accounts: {
|
|
755
792
|
admin: this.wallet.publicKey,
|
|
756
793
|
state: await this.getStatePublicKey(),
|
|
757
794
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
758
795
|
},
|
|
759
796
|
});
|
|
797
|
+
const tx = await this.buildTransaction(updatePerpMarketContractTierIx);
|
|
760
798
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
761
799
|
return txSig;
|
|
762
800
|
}
|
|
763
801
|
async updateExchangeStatus(exchangeStatus) {
|
|
764
|
-
const
|
|
802
|
+
const updateExchangeStatusIx = await this.program.instruction.updateExchangeStatus(exchangeStatus, {
|
|
765
803
|
accounts: {
|
|
766
804
|
admin: this.wallet.publicKey,
|
|
767
805
|
state: await this.getStatePublicKey(),
|
|
768
806
|
},
|
|
769
807
|
});
|
|
808
|
+
const tx = await this.buildTransaction(updateExchangeStatusIx);
|
|
770
809
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
771
810
|
return txSig;
|
|
772
811
|
}
|
|
@@ -164,6 +164,17 @@ exports.MainnetSpotMarkets = [
|
|
|
164
164
|
phoenixMarket: new web3_js_1.PublicKey('2pspvjWWaf3dNgt3jsgSzFCNvMGPb7t8FrEYvLGjvcCe'),
|
|
165
165
|
launchTs: 1706731200000,
|
|
166
166
|
},
|
|
167
|
+
{
|
|
168
|
+
symbol: 'RNDR',
|
|
169
|
+
marketIndex: 12,
|
|
170
|
+
oracle: new web3_js_1.PublicKey('CYGfrBJB9HgLf9iZyN4aH5HvUAi2htQ4MjPxeXMf4Egn'),
|
|
171
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
172
|
+
mint: new web3_js_1.PublicKey('rndrizKT3MK1iimdxRdWabcF7Zg7AR5T4nud4EkHBof'),
|
|
173
|
+
precision: new __1.BN(10).pow(numericConstants_1.EIGHT),
|
|
174
|
+
precisionExp: numericConstants_1.EIGHT,
|
|
175
|
+
serumMarket: new web3_js_1.PublicKey('2m7ZLEKtxWF29727DSb5D91erpXPUY1bqhRWRC3wQX7u'),
|
|
176
|
+
launchTs: 1708964021000,
|
|
177
|
+
},
|
|
167
178
|
];
|
|
168
179
|
exports.SpotMarkets = {
|
|
169
180
|
devnet: exports.DevnetSpotMarkets,
|
|
@@ -122,7 +122,7 @@ class EventSubscriber {
|
|
|
122
122
|
parseEventsFromLogs(txSig, slot, logs) {
|
|
123
123
|
const records = [];
|
|
124
124
|
// @ts-ignore
|
|
125
|
-
const events = (0, parse_1.parseLogs)(this.program,
|
|
125
|
+
const events = (0, parse_1.parseLogs)(this.program, logs);
|
|
126
126
|
let runningEventIndex = 0;
|
|
127
127
|
for (const event of events) {
|
|
128
128
|
// @ts-ignore
|
package/lib/events/fetchLogs.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LogParser = exports.fetchTransactionLogs = exports.fetchLogs = void 0;
|
|
4
4
|
const promiseTimeout_1 = require("../util/promiseTimeout");
|
|
5
|
+
const parse_1 = require("./parse");
|
|
5
6
|
function mapTransactionResponseToLog(transaction) {
|
|
6
7
|
return {
|
|
7
8
|
txSig: transaction.transaction.signatures[0],
|
|
@@ -82,14 +83,13 @@ class LogParser {
|
|
|
82
83
|
const records = [];
|
|
83
84
|
if (!event.logs)
|
|
84
85
|
return records;
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
const eventGenerator = this.program._events._eventParser.parseLogs(event.logs, false);
|
|
87
86
|
let runningEventIndex = 0;
|
|
88
|
-
for (const eventLog of
|
|
87
|
+
for (const eventLog of (0, parse_1.parseLogs)(this.program, event.logs)) {
|
|
89
88
|
eventLog.data.txSig = event.txSig;
|
|
90
89
|
eventLog.data.slot = event.slot;
|
|
91
90
|
eventLog.data.eventType = eventLog.name;
|
|
92
91
|
eventLog.data.txSigIndex = runningEventIndex;
|
|
92
|
+
// @ts-ignore
|
|
93
93
|
records.push(eventLog.data);
|
|
94
94
|
runningEventIndex++;
|
|
95
95
|
}
|
package/lib/events/parse.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Program, Event } from '@coral-xyz/anchor';
|
|
2
|
-
export declare function parseLogs(program: Program,
|
|
2
|
+
export declare function parseLogs(program: Program, logs: string[]): Event[];
|
package/lib/events/parse.js
CHANGED
|
@@ -7,10 +7,13 @@ const PROGRAM_LOG = 'Program log: ';
|
|
|
7
7
|
const PROGRAM_DATA = 'Program data: ';
|
|
8
8
|
const PROGRAM_LOG_START_INDEX = PROGRAM_LOG.length;
|
|
9
9
|
const PROGRAM_DATA_START_INDEX = PROGRAM_DATA.length;
|
|
10
|
-
function parseLogs(program,
|
|
10
|
+
function parseLogs(program, logs) {
|
|
11
11
|
const events = [];
|
|
12
12
|
const execution = new ExecutionContext();
|
|
13
13
|
for (const log of logs) {
|
|
14
|
+
if (log.startsWith('Log truncated')) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
14
17
|
const [event, newProgram, didPop] = handleLog(execution, log, program);
|
|
15
18
|
if (event) {
|
|
16
19
|
events.push(event);
|
package/lib/idl/drift.json
CHANGED