@drift-labs/sdk 2.24.0 → 2.25.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/README.md +1 -1
- package/lib/accounts/fetch.d.ts +1 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingOracleAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +1 -1
- package/lib/addresses/pda.d.ts +1 -2
- package/lib/addresses/pda.js +1 -1
- package/lib/adminClient.d.ts +1 -2
- package/lib/adminClient.js +2 -2
- package/lib/constants/numericConstants.d.ts +59 -61
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/constants/spotMarkets.d.ts +0 -1
- package/lib/dlob/DLOB.d.ts +0 -1
- package/lib/dlob/DLOBNode.d.ts +0 -1
- package/lib/dlob/DLOBOrders.d.ts +1 -1
- package/lib/dlob/DLOBOrders.js +1 -1
- package/lib/dlob/NodeList.d.ts +0 -1
- package/lib/driftClient.d.ts +38 -23
- package/lib/driftClient.js +85 -131
- package/lib/events/eventSubscriber.d.ts +1 -1
- package/lib/events/eventSubscriber.js +3 -2
- package/lib/events/fetchLogs.d.ts +1 -1
- package/lib/events/fetchLogs.js +3 -2
- package/lib/examples/loadDlob.js +1 -1
- package/lib/examples/makeTradeExample.js +1 -1
- package/lib/factory/bigNum.d.ts +8 -9
- package/lib/factory/bigNum.js +1 -1
- package/lib/factory/oracleClient.js +1 -1
- package/lib/idl/drift.json +181 -14
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/math/amm.d.ts +2 -3
- package/lib/math/amm.js +1 -1
- package/lib/math/auction.d.ts +0 -1
- package/lib/math/conversion.d.ts +1 -2
- package/lib/math/funding.d.ts +1 -2
- package/lib/math/funding.js +1 -1
- package/lib/math/insurance.d.ts +1 -1
- package/lib/math/insurance.js +17 -1
- package/lib/math/margin.d.ts +1 -2
- package/lib/math/margin.js +1 -1
- package/lib/math/market.d.ts +1 -2
- package/lib/math/market.js +1 -1
- package/lib/math/oracles.d.ts +0 -1
- package/lib/math/oracles.js +2 -3
- package/lib/math/orders.d.ts +1 -2
- package/lib/math/orders.js +1 -1
- package/lib/math/position.d.ts +0 -1
- package/lib/math/repeg.d.ts +1 -2
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.d.ts +1 -2
- package/lib/math/spotBalance.js +1 -1
- package/lib/math/spotMarket.d.ts +1 -2
- package/lib/math/spotMarket.js +1 -1
- package/lib/math/spotPosition.d.ts +1 -2
- package/lib/math/trade.d.ts +1 -2
- package/lib/math/trade.js +1 -1
- package/lib/math/utils.d.ts +0 -1
- package/lib/oracles/pythClient.d.ts +2 -3
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/types.d.ts +1 -2
- package/lib/orderParams.d.ts +1 -2
- package/lib/serum/serumSubscriber.d.ts +1 -2
- package/lib/serum/serumSubscriber.js +1 -1
- package/lib/tokenFaucet.d.ts +2 -3
- package/lib/tokenFaucet.js +2 -2
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +8 -3
- package/lib/types.js +2 -1
- package/lib/user.d.ts +0 -1
- package/package.json +2 -2
- package/src/accounts/fetch.ts +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/pollingOracleAccountSubscriber.ts +1 -1
- package/src/accounts/pollingTokenAccountSubscriber.ts +1 -1
- package/src/accounts/pollingUserAccountSubscriber.ts +1 -1
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketUserAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +1 -1
- package/src/addresses/pda.ts +2 -2
- package/src/adminClient.ts +2 -2
- package/src/constants/perpMarkets.ts +10 -0
- package/src/dlob/DLOBOrders.ts +2 -2
- package/src/driftClient.ts +136 -153
- package/src/events/eventSubscriber.ts +7 -3
- package/src/events/fetchLogs.ts +7 -3
- package/src/examples/loadDlob.ts +1 -1
- package/src/examples/makeTradeExample.ts +1 -1
- package/src/factory/bigNum.ts +1 -1
- package/src/factory/oracleClient.ts +1 -1
- package/src/idl/drift.json +181 -14
- package/src/index.ts +1 -1
- package/src/math/amm.ts +1 -1
- package/src/math/funding.ts +1 -1
- package/src/math/insurance.ts +29 -0
- package/src/math/margin.ts +1 -1
- package/src/math/market.ts +1 -1
- package/src/math/oracles.ts +2 -3
- package/src/math/orders.ts +1 -1
- package/src/math/repeg.ts +1 -1
- package/src/math/spotBalance.ts +1 -1
- package/src/math/spotMarket.ts +1 -1
- package/src/math/spotPosition.ts +1 -1
- package/src/math/trade.ts +1 -1
- package/src/oracles/pythClient.ts +1 -1
- package/src/oracles/quoteAssetOracleClient.ts +1 -1
- package/src/oracles/types.ts +1 -1
- package/src/orderParams.ts +1 -1
- package/src/serum/serumSubscriber.ts +1 -1
- package/src/tokenFaucet.ts +2 -2
- package/src/tx/retryTxSender.ts +1 -1
- package/src/tx/types.ts +1 -1
- package/src/types.ts +6 -1
- package/src/userMap/userStatsMap.ts +1 -1
package/src/driftClient.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
Idl,
|
|
5
5
|
Program,
|
|
6
6
|
ProgramAccount,
|
|
7
|
-
} from '@
|
|
7
|
+
} from '@coral-xyz/anchor';
|
|
8
8
|
import bs58 from 'bs58';
|
|
9
9
|
import {
|
|
10
10
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
@@ -33,13 +33,12 @@ import {
|
|
|
33
33
|
isVariant,
|
|
34
34
|
ReferrerNameAccount,
|
|
35
35
|
OrderTriggerCondition,
|
|
36
|
-
isOneOfVariant,
|
|
37
|
-
PostOnlyParams,
|
|
38
36
|
SpotBalanceType,
|
|
39
37
|
PerpMarketExtendedInfo,
|
|
40
38
|
UserStatsAccount,
|
|
39
|
+
ModifyOrderParams,
|
|
41
40
|
} from './types';
|
|
42
|
-
import * as anchor from '@
|
|
41
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
43
42
|
import driftIDL from './idl/drift.json';
|
|
44
43
|
|
|
45
44
|
import {
|
|
@@ -3390,221 +3389,205 @@ export class DriftClient {
|
|
|
3390
3389
|
/**
|
|
3391
3390
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
3392
3391
|
* @param orderId: The open order to modify
|
|
3393
|
-
* @param
|
|
3394
|
-
* @param
|
|
3395
|
-
* @param
|
|
3396
|
-
* @param
|
|
3392
|
+
* @param newDirection: The new direction for the order
|
|
3393
|
+
* @param newBaseAmount: The new base amount for the order
|
|
3394
|
+
* @param newLimitPice: The new limit price for the order
|
|
3395
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
3397
3396
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3398
|
-
* @param
|
|
3399
|
-
* @param
|
|
3400
|
-
* @param
|
|
3401
|
-
* @param
|
|
3397
|
+
* @param auctionDuration:
|
|
3398
|
+
* @param auctionStartPrice:
|
|
3399
|
+
* @param auctionEndPrice:
|
|
3400
|
+
* @param reduceOnly:
|
|
3401
|
+
* @param postOnly:
|
|
3402
|
+
* @param immediateOrCancel:
|
|
3403
|
+
* @param maxTs:
|
|
3402
3404
|
* @returns
|
|
3403
3405
|
*/
|
|
3404
3406
|
public async modifyOrder({
|
|
3405
3407
|
orderId,
|
|
3408
|
+
newDirection,
|
|
3406
3409
|
newBaseAmount,
|
|
3407
3410
|
newLimitPrice,
|
|
3408
3411
|
newOraclePriceOffset,
|
|
3409
|
-
newOrderType,
|
|
3410
3412
|
newTriggerPrice,
|
|
3411
3413
|
newTriggerCondition,
|
|
3412
|
-
isSpot,
|
|
3413
3414
|
auctionDuration,
|
|
3414
3415
|
auctionStartPrice,
|
|
3415
3416
|
auctionEndPrice,
|
|
3417
|
+
reduceOnly,
|
|
3418
|
+
postOnly,
|
|
3419
|
+
immediateOrCancel,
|
|
3420
|
+
maxTs,
|
|
3421
|
+
txParams,
|
|
3416
3422
|
}: {
|
|
3417
3423
|
orderId: number;
|
|
3424
|
+
newDirection?: PositionDirection;
|
|
3418
3425
|
newBaseAmount?: BN;
|
|
3419
3426
|
newLimitPrice?: BN;
|
|
3420
3427
|
newOraclePriceOffset?: number;
|
|
3421
|
-
newOrderType?: OrderType;
|
|
3422
3428
|
newTriggerPrice?: BN;
|
|
3423
3429
|
newTriggerCondition?: OrderTriggerCondition;
|
|
3424
|
-
isSpot?: boolean;
|
|
3425
3430
|
auctionDuration?: number;
|
|
3426
3431
|
auctionStartPrice?: BN;
|
|
3427
3432
|
auctionEndPrice?: BN;
|
|
3433
|
+
reduceOnly?: boolean;
|
|
3434
|
+
postOnly?: boolean;
|
|
3435
|
+
immediateOrCancel?: boolean;
|
|
3436
|
+
maxTs?: BN;
|
|
3437
|
+
txParams?: TxParams;
|
|
3428
3438
|
}): Promise<TransactionSignature> {
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
3444
|
-
const orderTypeHasLimitPrice = newOrderType
|
|
3445
|
-
? isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
3446
|
-
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
3447
|
-
|
|
3448
|
-
const newOrderParams: OptionalOrderParams = {
|
|
3449
|
-
orderType: newOrderType || openOrder.orderType,
|
|
3450
|
-
marketType: openOrder.marketType,
|
|
3451
|
-
direction: openOrder.direction,
|
|
3452
|
-
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
3453
|
-
price: orderTypeHasLimitPrice
|
|
3454
|
-
? newLimitPrice || openOrder.price
|
|
3455
|
-
: undefined,
|
|
3456
|
-
marketIndex: openOrder.marketIndex,
|
|
3457
|
-
reduceOnly: openOrder.reduceOnly,
|
|
3458
|
-
postOnly: openOrder.postOnly
|
|
3459
|
-
? PostOnlyParams.MUST_POST_ONLY
|
|
3460
|
-
: PostOnlyParams.NONE,
|
|
3461
|
-
immediateOrCancel: openOrder.immediateOrCancel,
|
|
3462
|
-
triggerPrice: orderTypeHasTrigger
|
|
3463
|
-
? newTriggerPrice || openOrder.triggerPrice
|
|
3464
|
-
: undefined,
|
|
3465
|
-
triggerCondition: orderTypeHasTrigger
|
|
3466
|
-
? newTriggerCondition || openOrder.triggerCondition
|
|
3467
|
-
: undefined,
|
|
3468
|
-
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3469
|
-
auctionDuration: auctionDuration ?? openOrder.auctionDuration,
|
|
3470
|
-
maxTs: openOrder.maxTs,
|
|
3471
|
-
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
3472
|
-
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
|
3473
|
-
userOrderId: openOrder.userOrderId,
|
|
3439
|
+
const orderParams: ModifyOrderParams = {
|
|
3440
|
+
baseAssetAmount: newBaseAmount || null,
|
|
3441
|
+
direction: newDirection || null,
|
|
3442
|
+
price: newLimitPrice || null,
|
|
3443
|
+
oraclePriceOffset: newOraclePriceOffset || null,
|
|
3444
|
+
triggerPrice: newTriggerPrice || null,
|
|
3445
|
+
triggerCondition: newTriggerCondition || null,
|
|
3446
|
+
auctionDuration: auctionDuration || null,
|
|
3447
|
+
auctionStartPrice: auctionStartPrice || null,
|
|
3448
|
+
auctionEndPrice: auctionEndPrice || null,
|
|
3449
|
+
reduceOnly: reduceOnly || null,
|
|
3450
|
+
postOnly: postOnly || null,
|
|
3451
|
+
immediateOrCancel: immediateOrCancel || null,
|
|
3452
|
+
maxTs: maxTs || null,
|
|
3474
3453
|
};
|
|
3475
|
-
const placeOrderIx = isSpot
|
|
3476
|
-
? await this.getPlaceSpotOrderIx(newOrderParams)
|
|
3477
|
-
: await this.getPlacePerpOrderIx(newOrderParams);
|
|
3478
3454
|
|
|
3479
|
-
const
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3455
|
+
const { txSig } = await this.sendTransaction(
|
|
3456
|
+
wrapInTx(
|
|
3457
|
+
await this.getModifyOrderIx(orderId, orderParams),
|
|
3458
|
+
txParams?.computeUnits,
|
|
3459
|
+
txParams?.computeUnitsPrice
|
|
3460
|
+
),
|
|
3461
|
+
[],
|
|
3462
|
+
this.opts
|
|
3484
3463
|
);
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
3464
|
+
return txSig;
|
|
3465
|
+
}
|
|
3488
3466
|
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
}
|
|
3467
|
+
public async getModifyOrderIx(
|
|
3468
|
+
orderId: number,
|
|
3469
|
+
orderParams: ModifyOrderParams
|
|
3470
|
+
): Promise<TransactionInstruction> {
|
|
3471
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3495
3472
|
|
|
3496
|
-
|
|
3473
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
3474
|
+
userAccounts: [this.getUserAccount()],
|
|
3475
|
+
useMarketLastSlotCache: true,
|
|
3476
|
+
});
|
|
3477
|
+
|
|
3478
|
+
return await this.program.instruction.modifyOrder(orderId, orderParams, {
|
|
3479
|
+
accounts: {
|
|
3480
|
+
state: await this.getStatePublicKey(),
|
|
3481
|
+
user: userAccountPublicKey,
|
|
3482
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
3483
|
+
authority: this.wallet.publicKey,
|
|
3484
|
+
},
|
|
3485
|
+
remainingAccounts,
|
|
3486
|
+
});
|
|
3497
3487
|
}
|
|
3498
3488
|
|
|
3499
3489
|
/**
|
|
3500
3490
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
3501
3491
|
* @param userOrderId: The open order to modify
|
|
3502
|
-
* @param
|
|
3503
|
-
* @param
|
|
3504
|
-
* @param
|
|
3505
|
-
* @param
|
|
3492
|
+
* @param newDirection: The new direction for the order
|
|
3493
|
+
* @param newBaseAmount: The new base amount for the order
|
|
3494
|
+
* @param newLimitPice: The new limit price for the order
|
|
3495
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
3506
3496
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3507
|
-
* @param isSpot: Set to true if the order is a spot order
|
|
3508
3497
|
* @param auctionDuration: Only required if order type changed to market from something else
|
|
3509
3498
|
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
3510
3499
|
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
3500
|
+
* @param reduceOnly:
|
|
3501
|
+
* @param postOnly:
|
|
3502
|
+
* @param immediateOrCancel:
|
|
3503
|
+
* @param maxTs:
|
|
3511
3504
|
* @returns
|
|
3512
3505
|
*/
|
|
3513
3506
|
public async modifyOrderByUserOrderId({
|
|
3514
3507
|
userOrderId,
|
|
3508
|
+
newDirection,
|
|
3515
3509
|
newBaseAmount,
|
|
3516
3510
|
newLimitPrice,
|
|
3517
3511
|
newOraclePriceOffset,
|
|
3518
|
-
newOrderType,
|
|
3519
3512
|
newTriggerPrice,
|
|
3520
3513
|
newTriggerCondition,
|
|
3521
|
-
isSpot,
|
|
3522
3514
|
auctionDuration,
|
|
3523
3515
|
auctionStartPrice,
|
|
3524
3516
|
auctionEndPrice,
|
|
3517
|
+
reduceOnly,
|
|
3518
|
+
postOnly,
|
|
3519
|
+
immediateOrCancel,
|
|
3520
|
+
maxTs,
|
|
3521
|
+
txParams,
|
|
3525
3522
|
}: {
|
|
3526
3523
|
userOrderId: number;
|
|
3524
|
+
newDirection?: PositionDirection;
|
|
3527
3525
|
newBaseAmount?: BN;
|
|
3528
3526
|
newLimitPrice?: BN;
|
|
3529
3527
|
newOraclePriceOffset?: number;
|
|
3530
|
-
newOrderType?: OrderType;
|
|
3531
3528
|
newTriggerPrice?: BN;
|
|
3532
3529
|
newTriggerCondition?: OrderTriggerCondition;
|
|
3533
|
-
isSpot?: boolean;
|
|
3534
3530
|
auctionDuration?: number;
|
|
3535
3531
|
auctionStartPrice?: BN;
|
|
3536
3532
|
auctionEndPrice?: BN;
|
|
3533
|
+
reduceOnly?: boolean;
|
|
3534
|
+
postOnly?: boolean;
|
|
3535
|
+
immediateOrCancel?: boolean;
|
|
3536
|
+
maxTs?: BN;
|
|
3537
|
+
txParams?: TxParams;
|
|
3537
3538
|
}): Promise<TransactionSignature> {
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
const orderTypeHasTrigger = newOrderType
|
|
3553
|
-
? isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
3554
|
-
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
3555
|
-
const orderTypeHasLimitPrice = newOrderType
|
|
3556
|
-
? isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
3557
|
-
: isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
3558
|
-
|
|
3559
|
-
const newOrderParams: OptionalOrderParams = {
|
|
3560
|
-
orderType: newOrderType || openOrder.orderType,
|
|
3561
|
-
marketType: openOrder.marketType,
|
|
3562
|
-
direction: openOrder.direction,
|
|
3563
|
-
baseAssetAmount: newBaseAmount || openOrder.baseAssetAmount,
|
|
3564
|
-
price: orderTypeHasLimitPrice
|
|
3565
|
-
? newLimitPrice || openOrder.price
|
|
3566
|
-
: undefined,
|
|
3567
|
-
marketIndex: openOrder.marketIndex,
|
|
3568
|
-
reduceOnly: openOrder.reduceOnly,
|
|
3569
|
-
postOnly: openOrder.postOnly
|
|
3570
|
-
? PostOnlyParams.MUST_POST_ONLY
|
|
3571
|
-
: PostOnlyParams.NONE,
|
|
3572
|
-
immediateOrCancel: openOrder.immediateOrCancel,
|
|
3573
|
-
triggerPrice: orderTypeHasTrigger
|
|
3574
|
-
? newTriggerPrice || openOrder.triggerPrice
|
|
3575
|
-
: undefined,
|
|
3576
|
-
triggerCondition: orderTypeHasTrigger
|
|
3577
|
-
? newTriggerCondition || openOrder.triggerCondition
|
|
3578
|
-
: undefined,
|
|
3579
|
-
oraclePriceOffset: newOraclePriceOffset || openOrder.oraclePriceOffset,
|
|
3580
|
-
auctionDuration: auctionDuration || openOrder.auctionDuration,
|
|
3581
|
-
maxTs: openOrder.maxTs,
|
|
3582
|
-
auctionStartPrice: auctionStartPrice || openOrder.auctionStartPrice,
|
|
3583
|
-
auctionEndPrice: auctionEndPrice || openOrder.auctionEndPrice,
|
|
3584
|
-
userOrderId: openOrder.userOrderId,
|
|
3539
|
+
const orderParams: ModifyOrderParams = {
|
|
3540
|
+
baseAssetAmount: newBaseAmount || null,
|
|
3541
|
+
direction: newDirection || null,
|
|
3542
|
+
price: newLimitPrice || null,
|
|
3543
|
+
oraclePriceOffset: newOraclePriceOffset || null,
|
|
3544
|
+
triggerPrice: newTriggerPrice || null,
|
|
3545
|
+
triggerCondition: newTriggerCondition || null,
|
|
3546
|
+
auctionDuration: auctionDuration || null,
|
|
3547
|
+
auctionStartPrice: auctionStartPrice || null,
|
|
3548
|
+
auctionEndPrice: auctionEndPrice || null,
|
|
3549
|
+
reduceOnly: reduceOnly || null,
|
|
3550
|
+
postOnly: postOnly || null,
|
|
3551
|
+
immediateOrCancel: immediateOrCancel || null,
|
|
3552
|
+
maxTs: maxTs || null,
|
|
3585
3553
|
};
|
|
3586
|
-
const placeOrderIx = isSpot
|
|
3587
|
-
? await this.getPlaceSpotOrderIx(newOrderParams)
|
|
3588
|
-
: await this.getPlacePerpOrderIx(newOrderParams);
|
|
3589
3554
|
|
|
3590
|
-
const
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3555
|
+
const { txSig } = await this.sendTransaction(
|
|
3556
|
+
wrapInTx(
|
|
3557
|
+
await this.getModifyOrderByUserIdIx(userOrderId, orderParams),
|
|
3558
|
+
txParams?.computeUnits,
|
|
3559
|
+
txParams?.computeUnitsPrice
|
|
3560
|
+
),
|
|
3561
|
+
[],
|
|
3562
|
+
this.opts
|
|
3595
3563
|
);
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
3564
|
+
return txSig;
|
|
3565
|
+
}
|
|
3599
3566
|
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
}
|
|
3567
|
+
public async getModifyOrderByUserIdIx(
|
|
3568
|
+
userOrderId: number,
|
|
3569
|
+
orderParams: ModifyOrderParams
|
|
3570
|
+
): Promise<TransactionInstruction> {
|
|
3571
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3606
3572
|
|
|
3607
|
-
|
|
3573
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
3574
|
+
userAccounts: [this.getUserAccount()],
|
|
3575
|
+
useMarketLastSlotCache: true,
|
|
3576
|
+
});
|
|
3577
|
+
|
|
3578
|
+
return await this.program.instruction.modifyOrderByUserId(
|
|
3579
|
+
userOrderId,
|
|
3580
|
+
orderParams,
|
|
3581
|
+
{
|
|
3582
|
+
accounts: {
|
|
3583
|
+
state: await this.getStatePublicKey(),
|
|
3584
|
+
user: userAccountPublicKey,
|
|
3585
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
3586
|
+
authority: this.wallet.publicKey,
|
|
3587
|
+
},
|
|
3588
|
+
remainingAccounts,
|
|
3589
|
+
}
|
|
3590
|
+
);
|
|
3608
3591
|
}
|
|
3609
3592
|
|
|
3610
3593
|
public async settlePNLs(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Connection, TransactionSignature } from '@solana/web3.js';
|
|
2
|
-
import { Program } from '@
|
|
2
|
+
import { Program } from '@coral-xyz/anchor';
|
|
3
3
|
import {
|
|
4
4
|
DefaultEventSubscriptionOptions,
|
|
5
5
|
EventSubscriptionOptions,
|
|
@@ -164,7 +164,11 @@ export class EventSubscriber {
|
|
|
164
164
|
): WrappedEvents {
|
|
165
165
|
const records = [];
|
|
166
166
|
// @ts-ignore
|
|
167
|
-
this.program._events._eventParser.parseLogs(
|
|
167
|
+
const eventGenerator = this.program._events._eventParser.parseLogs(
|
|
168
|
+
logs,
|
|
169
|
+
false
|
|
170
|
+
);
|
|
171
|
+
for (const event of eventGenerator) {
|
|
168
172
|
const expectRecordType = this.eventListMap.has(event.name);
|
|
169
173
|
if (expectRecordType) {
|
|
170
174
|
event.data.txSig = txSig;
|
|
@@ -172,7 +176,7 @@ export class EventSubscriber {
|
|
|
172
176
|
event.data.eventType = event.name;
|
|
173
177
|
records.push(event.data);
|
|
174
178
|
}
|
|
175
|
-
}
|
|
179
|
+
}
|
|
176
180
|
return records;
|
|
177
181
|
}
|
|
178
182
|
|
package/src/events/fetchLogs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Program } from '@
|
|
1
|
+
import { Program } from '@coral-xyz/anchor';
|
|
2
2
|
import {
|
|
3
3
|
Connection,
|
|
4
4
|
Finality,
|
|
@@ -120,12 +120,16 @@ export class LogParser {
|
|
|
120
120
|
public parseEventsFromLogs(event: Log): WrappedEvents {
|
|
121
121
|
const records: WrappedEvents = [];
|
|
122
122
|
// @ts-ignore
|
|
123
|
-
this.program._events._eventParser.parseLogs(
|
|
123
|
+
const eventGenerator = this.program._events._eventParser.parseLogs(
|
|
124
|
+
event.logs,
|
|
125
|
+
false
|
|
126
|
+
);
|
|
127
|
+
for (const eventLog of eventGenerator) {
|
|
124
128
|
eventLog.data.txSig = event.txSig;
|
|
125
129
|
eventLog.data.slot = event.slot;
|
|
126
130
|
eventLog.data.eventType = eventLog.name;
|
|
127
131
|
records.push(eventLog.data);
|
|
128
|
-
}
|
|
132
|
+
}
|
|
129
133
|
return records;
|
|
130
134
|
}
|
|
131
135
|
}
|
package/src/examples/loadDlob.ts
CHANGED
package/src/factory/bigNum.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { OracleClient } from '../oracles/types';
|
|
|
4
4
|
import { PythClient } from '../oracles/pythClient';
|
|
5
5
|
// import { SwitchboardClient } from '../oracles/switchboardClient';
|
|
6
6
|
import { QuoteAssetOracleClient } from '../oracles/quoteAssetOracleClient';
|
|
7
|
-
import { BN } from '@
|
|
7
|
+
import { BN } from '@coral-xyz/anchor';
|
|
8
8
|
|
|
9
9
|
export function getOracleClient(
|
|
10
10
|
oracleSource: OracleSource,
|