@drift-labs/sdk 0.2.0-master.10 → 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 +3 -3
- package/lib/admin.js +6 -6
- package/lib/clearingHouse.d.ts +15 -4
- package/lib/clearingHouse.js +200 -37
- package/lib/clearingHouseUser.d.ts +2 -2
- package/lib/clearingHouseUser.js +8 -17
- package/lib/config.js +1 -1
- package/lib/constants/banks.js +1 -1
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +2 -1
- package/lib/idl/clearing_house.json +484 -103
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
- package/lib/types.d.ts +62 -13
- package/lib/types.js +12 -1
- package/lib/util/computeUnits.js +1 -1
- package/package.json +1 -1
- package/src/admin.ts +7 -7
- package/src/clearingHouse.ts +335 -47
- package/src/clearingHouseUser.ts +12 -23
- package/src/config.ts +1 -1
- package/src/constants/banks.ts +1 -1
- package/src/constants/numericConstants.ts +1 -0
- package/src/idl/clearing_house.json +484 -103
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +98 -67
- package/src/index.ts +1 -1
- package/src/mockUSDCFaucet.js +276 -167
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
- package/src/types.ts +63 -13
- package/src/util/computeUnits.ts +1 -1
package/src/types.ts
CHANGED
|
@@ -161,20 +161,67 @@ export type FundingPaymentRecord = {
|
|
|
161
161
|
|
|
162
162
|
export type LiquidationRecord = {
|
|
163
163
|
ts: BN;
|
|
164
|
-
recordId: BN;
|
|
165
|
-
userAuthority: PublicKey;
|
|
166
164
|
user: PublicKey;
|
|
167
|
-
partial: boolean;
|
|
168
|
-
baseAssetValue: BN;
|
|
169
|
-
baseAssetValueClosed: BN;
|
|
170
|
-
liquidationFee: BN;
|
|
171
|
-
feeToLiquidator: BN;
|
|
172
|
-
feeToInsuranceFund: BN;
|
|
173
165
|
liquidator: PublicKey;
|
|
166
|
+
liquidationType: LiquidationType;
|
|
167
|
+
marginRequirement: BN;
|
|
174
168
|
totalCollateral: BN;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
169
|
+
liquidatePerp: LiquidatePerpRecord;
|
|
170
|
+
liquidateBorrow: LiquidateBorrowRecord;
|
|
171
|
+
liquidateBorrowForPerpPnl: LiquidateBorrowForPerpPnlRecord;
|
|
172
|
+
liquidatePerpPnlForDeposit: LiquidatePerpPnlForDepositRecord;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export class LiquidationType {
|
|
176
|
+
static readonly LIQUIDATE_PERP = { liquidatePerp: {} };
|
|
177
|
+
static readonly LIQUIDATE_BORROW = { liquidateBorrow: {} };
|
|
178
|
+
static readonly LIQUIDATE_BORROW_FOR_PERP_PNL = {
|
|
179
|
+
liquidateBorrowForPerpPnl: {},
|
|
180
|
+
};
|
|
181
|
+
static readonly LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
182
|
+
liquidatePerpPnlForDeposit: {},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type LiquidatePerpRecord = {
|
|
187
|
+
marketIndex: BN;
|
|
188
|
+
orderIds: BN[];
|
|
189
|
+
oraclePrice: BN;
|
|
190
|
+
baseAssetAmount: BN;
|
|
191
|
+
quoteAssetAmount: BN;
|
|
192
|
+
userPnl: BN;
|
|
193
|
+
liquidatorPnl: BN;
|
|
194
|
+
canceledOrdersFee: BN;
|
|
195
|
+
userOrderId: BN;
|
|
196
|
+
liquidatorOrderId: BN;
|
|
197
|
+
fillRecordId: BN;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export type LiquidateBorrowRecord = {
|
|
201
|
+
assetBankIndex: BN;
|
|
202
|
+
assetPrice: BN;
|
|
203
|
+
assetTransfer: BN;
|
|
204
|
+
liabilityBankIndex: BN;
|
|
205
|
+
liabilityPrice: BN;
|
|
206
|
+
liabilityTransfer: BN;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export type LiquidateBorrowForPerpPnlRecord = {
|
|
210
|
+
marketIndex: BN;
|
|
211
|
+
marketOraclePrice: BN;
|
|
212
|
+
pnlTransfer: BN;
|
|
213
|
+
liabilityBankIndex: BN;
|
|
214
|
+
liabilityPrice: BN;
|
|
215
|
+
liabilityTransfer: BN;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export type LiquidatePerpPnlForDepositRecord = {
|
|
219
|
+
marketIndex: BN;
|
|
220
|
+
marketOraclePrice: BN;
|
|
221
|
+
pnlTransfer: BN;
|
|
222
|
+
assetBankIndex: BN;
|
|
223
|
+
assetPrice: BN;
|
|
224
|
+
assetTransfer: BN;
|
|
178
225
|
};
|
|
179
226
|
|
|
180
227
|
export type OrderRecord = {
|
|
@@ -241,9 +288,9 @@ export type MarketAccount = {
|
|
|
241
288
|
openInterest: BN;
|
|
242
289
|
marginRatioInitial: number;
|
|
243
290
|
marginRatioMaintenance: number;
|
|
244
|
-
marginRatioPartial: number;
|
|
245
291
|
nextFillRecordId: BN;
|
|
246
292
|
pnlPool: PoolBalance;
|
|
293
|
+
liquidationFee: BN;
|
|
247
294
|
};
|
|
248
295
|
|
|
249
296
|
export type BankAccount = {
|
|
@@ -267,6 +314,7 @@ export type BankAccount = {
|
|
|
267
314
|
maintenanceAssetWeight: BN;
|
|
268
315
|
initialLiabilityWeight: BN;
|
|
269
316
|
maintenanceLiabilityWeight: BN;
|
|
317
|
+
liquidationFee: BN;
|
|
270
318
|
};
|
|
271
319
|
|
|
272
320
|
export type PoolBalance = {
|
|
@@ -349,6 +397,7 @@ export type UserAccount = {
|
|
|
349
397
|
};
|
|
350
398
|
positions: UserPosition[];
|
|
351
399
|
orders: Order[];
|
|
400
|
+
beingLiquidated: boolean;
|
|
352
401
|
};
|
|
353
402
|
|
|
354
403
|
export type UserBankBalance = {
|
|
@@ -493,6 +542,7 @@ export type FeeStructure = {
|
|
|
493
542
|
makerRebateNumerator: BN;
|
|
494
543
|
makerRebateDenominator: BN;
|
|
495
544
|
fillerRewardStructure: OrderFillerRewardStructure;
|
|
545
|
+
cancelOrderFee: BN;
|
|
496
546
|
};
|
|
497
547
|
|
|
498
548
|
export type OracleGuardRails = {
|
|
@@ -514,4 +564,4 @@ export type OrderFillerRewardStructure = {
|
|
|
514
564
|
timeBasedRewardLowerBound: BN;
|
|
515
565
|
};
|
|
516
566
|
|
|
517
|
-
export type MarginCategory = 'Initial' | '
|
|
567
|
+
export type MarginCategory = 'Initial' | 'Maintenance';
|
package/src/util/computeUnits.ts
CHANGED
|
@@ -9,7 +9,7 @@ export async function findComputeUnitConsumption(
|
|
|
9
9
|
const tx = await connection.getTransaction(txSignature, { commitment });
|
|
10
10
|
const computeUnits = [];
|
|
11
11
|
const regex = new RegExp(
|
|
12
|
-
`Program ${programId.toString()} consumed ([0-9]{0,6}) of
|
|
12
|
+
`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`
|
|
13
13
|
);
|
|
14
14
|
tx.meta.logMessages.forEach((logMessage) => {
|
|
15
15
|
const match = logMessage.match(regex);
|