@drift-labs/sdk 0.2.0-master.0 → 0.2.0-master.11
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/admin.d.ts +8 -5
- package/lib/admin.js +43 -11
- package/lib/clearingHouse.d.ts +28 -18
- package/lib/clearingHouse.js +366 -143
- package/lib/clearingHouseUser.d.ts +2 -2
- package/lib/clearingHouseUser.js +8 -17
- package/lib/config.js +1 -1
- package/lib/constants/banks.js +9 -2
- package/lib/constants/numericConstants.d.ts +2 -0
- package/lib/constants/numericConstants.js +3 -1
- package/lib/factory/bigNum.d.ts +8 -2
- package/lib/factory/bigNum.js +14 -6
- package/lib/idl/clearing_house.json +805 -202
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +3 -2
- package/lib/index.js +7 -2
- package/lib/math/amm.d.ts +6 -1
- package/lib/math/amm.js +124 -41
- package/lib/math/auction.js +4 -1
- package/lib/math/orders.d.ts +2 -2
- package/lib/math/orders.js +18 -11
- package/lib/math/position.js +3 -1
- package/lib/math/repeg.js +1 -1
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +7 -10
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.d.ts +1 -2
- package/lib/orders.js +6 -85
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +137 -14
- package/lib/types.js +53 -1
- package/lib/util/computeUnits.js +1 -1
- package/package.json +3 -3
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/fetch.js +29 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/types.js +10 -0
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/addresses/marketAddresses.js +26 -0
- package/src/addresses/pda.js +104 -0
- package/src/admin.ts +66 -14
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +558 -230
- package/src/clearingHouseUser.ts +12 -23
- package/src/config.ts +1 -1
- package/src/constants/banks.ts +9 -2
- package/src/constants/numericConstants.ts +2 -0
- package/src/events/eventList.js +77 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/sort.js +44 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/types.js +20 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/factory/bigNum.js +364 -0
- package/src/factory/bigNum.ts +26 -9
- package/src/factory/oracleClient.js +20 -0
- package/src/idl/clearing_house.json +805 -202
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +100 -0
- package/src/index.ts +3 -2
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +207 -52
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +5 -1
- package/src/math/bankBalance.js +75 -0
- package/src/math/conversion.js +11 -0
- package/src/math/funding.js +248 -0
- package/src/math/market.js +57 -0
- package/src/math/oracles.js +26 -0
- package/src/math/orders.js +110 -0
- package/src/math/orders.ts +17 -13
- package/src/math/position.js +140 -0
- package/src/math/position.ts +5 -1
- package/src/math/repeg.js +128 -0
- package/src/math/repeg.ts +2 -1
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +23 -25
- package/src/math/utils.js +0 -1
- package/src/mockUSDCFaucet.js +280 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/types.js +2 -0
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.js +134 -0
- package/src/orders.ts +7 -131
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/token/index.js +38 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
- package/src/tx/retryTxSender.js +188 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.js +114 -0
- package/src/types.ts +132 -16
- package/src/userName.js +20 -0
- package/src/util/computeUnits.ts +1 -1
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/src/util/computeUnits.js +0 -17
- package/src/util/computeUnits.js.map +0 -1
package/src/admin.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from './addresses/pda';
|
|
21
21
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
22
|
import { ClearingHouse } from './clearingHouse';
|
|
23
|
-
import { PEG_PRECISION } from './constants/numericConstants';
|
|
23
|
+
import { PEG_PRECISION, ZERO } from './constants/numericConstants';
|
|
24
24
|
import { calculateTargetPriceTrade } from './math/trade';
|
|
25
25
|
import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
|
|
26
26
|
|
|
@@ -85,7 +85,9 @@ export class Admin extends ClearingHouse {
|
|
|
85
85
|
initialAssetWeight: BN,
|
|
86
86
|
maintenanceAssetWeight: BN,
|
|
87
87
|
initialLiabilityWeight: BN,
|
|
88
|
-
maintenanceLiabilityWeight: BN
|
|
88
|
+
maintenanceLiabilityWeight: BN,
|
|
89
|
+
imfFactor = new BN(0),
|
|
90
|
+
liquidationFee = ZERO
|
|
89
91
|
): Promise<TransactionSignature> {
|
|
90
92
|
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
91
93
|
const bank = await getBankPublicKey(this.program.programId, bankIndex);
|
|
@@ -109,6 +111,8 @@ export class Admin extends ClearingHouse {
|
|
|
109
111
|
maintenanceAssetWeight,
|
|
110
112
|
initialLiabilityWeight,
|
|
111
113
|
maintenanceLiabilityWeight,
|
|
114
|
+
imfFactor,
|
|
115
|
+
liquidationFee,
|
|
112
116
|
{
|
|
113
117
|
accounts: {
|
|
114
118
|
admin: this.wallet.publicKey,
|
|
@@ -144,8 +148,8 @@ export class Admin extends ClearingHouse {
|
|
|
144
148
|
pegMultiplier: BN = PEG_PRECISION,
|
|
145
149
|
oracleSource: OracleSource = OracleSource.PYTH,
|
|
146
150
|
marginRatioInitial = 2000,
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
marginRatioMaintenance = 500,
|
|
152
|
+
liquidationFee = ZERO
|
|
149
153
|
): Promise<TransactionSignature> {
|
|
150
154
|
const marketPublicKey = await getMarketPublicKey(
|
|
151
155
|
this.program.programId,
|
|
@@ -159,8 +163,8 @@ export class Admin extends ClearingHouse {
|
|
|
159
163
|
pegMultiplier,
|
|
160
164
|
oracleSource,
|
|
161
165
|
marginRatioInitial,
|
|
162
|
-
marginRatioPartial,
|
|
163
166
|
marginRatioMaintenance,
|
|
167
|
+
liquidationFee,
|
|
164
168
|
{
|
|
165
169
|
accounts: {
|
|
166
170
|
state: await this.getStatePublicKey(),
|
|
@@ -329,10 +333,12 @@ export class Admin extends ClearingHouse {
|
|
|
329
333
|
recipient: PublicKey
|
|
330
334
|
): Promise<TransactionSignature> {
|
|
331
335
|
const state = await this.getStateAccount();
|
|
336
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
332
337
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
333
338
|
accounts: {
|
|
334
339
|
admin: this.wallet.publicKey,
|
|
335
340
|
state: await this.getStatePublicKey(),
|
|
341
|
+
bank: bank.pubkey,
|
|
336
342
|
insuranceVault: state.insuranceVault,
|
|
337
343
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
338
344
|
recipient: recipient,
|
|
@@ -341,7 +347,7 @@ export class Admin extends ClearingHouse {
|
|
|
341
347
|
});
|
|
342
348
|
}
|
|
343
349
|
|
|
344
|
-
public async
|
|
350
|
+
public async withdrawFromMarketToInsuranceVault(
|
|
345
351
|
marketIndex: BN,
|
|
346
352
|
amount: BN,
|
|
347
353
|
recipient: PublicKey
|
|
@@ -351,7 +357,7 @@ export class Admin extends ClearingHouse {
|
|
|
351
357
|
marketIndex
|
|
352
358
|
);
|
|
353
359
|
const bank = this.getQuoteAssetBankAccount();
|
|
354
|
-
return await this.program.rpc.
|
|
360
|
+
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
355
361
|
accounts: {
|
|
356
362
|
admin: this.wallet.publicKey,
|
|
357
363
|
state: await this.getStatePublicKey(),
|
|
@@ -370,6 +376,8 @@ export class Admin extends ClearingHouse {
|
|
|
370
376
|
amount: BN
|
|
371
377
|
): Promise<TransactionSignature> {
|
|
372
378
|
const state = await this.getStateAccount();
|
|
379
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
380
|
+
|
|
373
381
|
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
374
382
|
accounts: {
|
|
375
383
|
admin: this.wallet.publicKey,
|
|
@@ -377,7 +385,9 @@ export class Admin extends ClearingHouse {
|
|
|
377
385
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
378
386
|
insuranceVault: state.insuranceVault,
|
|
379
387
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
380
|
-
|
|
388
|
+
bank: bank.pubkey,
|
|
389
|
+
bankVault: bank.vault,
|
|
390
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
381
391
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
382
392
|
},
|
|
383
393
|
});
|
|
@@ -414,12 +424,10 @@ export class Admin extends ClearingHouse {
|
|
|
414
424
|
public async updateMarginRatio(
|
|
415
425
|
marketIndex: BN,
|
|
416
426
|
marginRatioInitial: number,
|
|
417
|
-
marginRatioPartial: number,
|
|
418
427
|
marginRatioMaintenance: number
|
|
419
428
|
): Promise<TransactionSignature> {
|
|
420
429
|
return await this.program.rpc.updateMarginRatio(
|
|
421
430
|
marginRatioInitial,
|
|
422
|
-
marginRatioPartial,
|
|
423
431
|
marginRatioMaintenance,
|
|
424
432
|
{
|
|
425
433
|
accounts: {
|
|
@@ -444,6 +452,19 @@ export class Admin extends ClearingHouse {
|
|
|
444
452
|
});
|
|
445
453
|
}
|
|
446
454
|
|
|
455
|
+
public async updateMarketMaxSpread(
|
|
456
|
+
marketIndex: BN,
|
|
457
|
+
maxSpread: number
|
|
458
|
+
): Promise<TransactionSignature> {
|
|
459
|
+
return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
|
|
460
|
+
accounts: {
|
|
461
|
+
admin: this.wallet.publicKey,
|
|
462
|
+
state: await this.getStatePublicKey(),
|
|
463
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
447
468
|
public async updatePartialLiquidationClosePercentage(
|
|
448
469
|
numerator: BN,
|
|
449
470
|
denominator: BN
|
|
@@ -662,11 +683,13 @@ export class Admin extends ClearingHouse {
|
|
|
662
683
|
});
|
|
663
684
|
}
|
|
664
685
|
|
|
665
|
-
public async
|
|
666
|
-
|
|
686
|
+
public async updateAuctionDuration(
|
|
687
|
+
minDuration: BN | number,
|
|
688
|
+
maxDuration: BN | number
|
|
667
689
|
): Promise<TransactionSignature> {
|
|
668
|
-
return await this.program.rpc.
|
|
669
|
-
typeof
|
|
690
|
+
return await this.program.rpc.updateAuctionDuration(
|
|
691
|
+
typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
|
|
692
|
+
typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
|
|
670
693
|
{
|
|
671
694
|
accounts: {
|
|
672
695
|
admin: this.wallet.publicKey,
|
|
@@ -675,4 +698,33 @@ export class Admin extends ClearingHouse {
|
|
|
675
698
|
}
|
|
676
699
|
);
|
|
677
700
|
}
|
|
701
|
+
|
|
702
|
+
public async updateMaxBaseAssetAmountRatio(
|
|
703
|
+
marketIndex: BN,
|
|
704
|
+
maxBaseAssetAmountRatio: number
|
|
705
|
+
): Promise<TransactionSignature> {
|
|
706
|
+
return await this.program.rpc.updateMaxBaseAssetAmountRatio(
|
|
707
|
+
maxBaseAssetAmountRatio,
|
|
708
|
+
{
|
|
709
|
+
accounts: {
|
|
710
|
+
admin: this.wallet.publicKey,
|
|
711
|
+
state: await this.getStatePublicKey(),
|
|
712
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
713
|
+
},
|
|
714
|
+
}
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
public async updateMaxSlippageRatio(
|
|
719
|
+
marketIndex: BN,
|
|
720
|
+
maxSlippageRatio: number
|
|
721
|
+
): Promise<TransactionSignature> {
|
|
722
|
+
return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
723
|
+
accounts: {
|
|
724
|
+
admin: this.wallet.publicKey,
|
|
725
|
+
state: await this.getStatePublicKey(),
|
|
726
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
}
|
|
678
730
|
}
|