@drift-labs/sdk 2.10.0-beta.1 → 2.10.0-beta.3
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/pollingDriftClientAccountSubscriber.js +12 -3
- package/lib/accounts/types.d.ts +5 -4
- package/lib/adminClient.js +96 -34
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +4 -4
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/driftClient.d.ts +4 -3
- package/lib/driftClient.js +105 -64
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/types.d.ts +13 -13
- package/lib/factory/bigNum.js +4 -4
- package/lib/idl/drift.json +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +15 -6
- package/lib/math/oracles.js +2 -2
- package/lib/math/repeg.d.ts +1 -1
- package/lib/math/repeg.js +46 -19
- package/lib/math/trade.d.ts +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/types.d.ts +1 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/testClient.d.ts +8 -0
- package/lib/testClient.js +22 -0
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +43 -43
- package/lib/user.d.ts +1 -0
- package/lib/user.js +10 -6
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +3 -0
- package/lib/userMap/userStatsMap.js +3 -0
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +26 -3
- package/src/adminClient.ts +301 -169
- package/src/driftClient.ts +199 -118
- package/src/driftClientConfig.ts +1 -1
- package/src/idl/drift.json +1 -1
- package/src/index.ts +1 -0
- package/src/math/amm.ts +27 -12
- package/src/math/oracles.ts +6 -4
- package/src/math/repeg.ts +54 -26
- package/src/testClient.ts +40 -0
- package/src/user.ts +5 -0
- package/src/userMap/userMap.ts +2 -0
- package/src/userMap/userStatsMap.ts +2 -0
- package/src/assert/assert.js +0 -9
- package/src/examples/makeTradeExample.js +0 -157
- package/src/token/index.js +0 -38
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -17
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/src/driftClient.ts
CHANGED
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
DriftClientAccountEvents,
|
|
64
64
|
DataAndSlot,
|
|
65
65
|
} from './accounts/types';
|
|
66
|
-
import { TxSender } from './tx/types';
|
|
66
|
+
import { TxSender, TxSigAndSlot } from './tx/types';
|
|
67
67
|
import { wrapInTx } from './tx/utils';
|
|
68
68
|
import { QUOTE_SPOT_MARKET_INDEX, ZERO } from './constants/numericConstants';
|
|
69
69
|
import { findDirectionToClose, positionIsAvailable } from './math/position';
|
|
@@ -166,7 +166,7 @@ export class DriftClient {
|
|
|
166
166
|
const {
|
|
167
167
|
perpMarketIndexes: envPerpMarketIndexes,
|
|
168
168
|
spotMarketIndexes: envSpotMarketIndexes,
|
|
169
|
-
oracleInfos:
|
|
169
|
+
oracleInfos: envOracleInfos,
|
|
170
170
|
} = getMarketsAndOraclesForSubscription(config.env);
|
|
171
171
|
perpMarketIndexes = perpMarketIndexes
|
|
172
172
|
? perpMarketIndexes
|
|
@@ -174,7 +174,7 @@ export class DriftClient {
|
|
|
174
174
|
spotMarketIndexes = spotMarketIndexes
|
|
175
175
|
? spotMarketIndexes
|
|
176
176
|
: envSpotMarketIndexes;
|
|
177
|
-
oracleInfos = oracleInfos ? oracleInfos :
|
|
177
|
+
oracleInfos = oracleInfos ? oracleInfos : envOracleInfos;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
if (config.accountSubscription?.type === 'polling') {
|
|
@@ -188,9 +188,9 @@ export class DriftClient {
|
|
|
188
188
|
} else {
|
|
189
189
|
this.accountSubscriber = new WebSocketDriftClientAccountSubscriber(
|
|
190
190
|
this.program,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
perpMarketIndexes ?? [],
|
|
192
|
+
spotMarketIndexes ?? [],
|
|
193
|
+
oracleInfos ?? []
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
196
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
@@ -322,7 +322,15 @@ export class DriftClient {
|
|
|
322
322
|
marketIndex: number
|
|
323
323
|
): Promise<PerpMarketAccount | undefined> {
|
|
324
324
|
await this.accountSubscriber.fetch();
|
|
325
|
-
|
|
325
|
+
let data =
|
|
326
|
+
this.accountSubscriber.getMarketAccountAndSlot(marketIndex)?.data;
|
|
327
|
+
let i = 0;
|
|
328
|
+
while (data === undefined && i < 10) {
|
|
329
|
+
await this.accountSubscriber.fetch();
|
|
330
|
+
data = this.accountSubscriber.getMarketAccountAndSlot(marketIndex)?.data;
|
|
331
|
+
i++;
|
|
332
|
+
}
|
|
333
|
+
return data;
|
|
326
334
|
}
|
|
327
335
|
|
|
328
336
|
public getPerpMarketAccounts(): PerpMarketAccount[] {
|
|
@@ -476,7 +484,7 @@ export class DriftClient {
|
|
|
476
484
|
}
|
|
477
485
|
}
|
|
478
486
|
tx.add(initializeUserAccountIx);
|
|
479
|
-
const { txSig } = await this.
|
|
487
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
480
488
|
return [txSig, userAccountPublicKey];
|
|
481
489
|
}
|
|
482
490
|
|
|
@@ -562,19 +570,25 @@ export class DriftClient {
|
|
|
562
570
|
);
|
|
563
571
|
|
|
564
572
|
const nameBuffer = encodeName(name);
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
573
|
+
const tx = await this.program.transaction.updateUserName(
|
|
574
|
+
subAccountId,
|
|
575
|
+
nameBuffer,
|
|
576
|
+
{
|
|
577
|
+
accounts: {
|
|
578
|
+
user: userAccountPublicKey,
|
|
579
|
+
authority: this.wallet.publicKey,
|
|
580
|
+
},
|
|
581
|
+
}
|
|
582
|
+
);
|
|
583
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
584
|
+
return txSig;
|
|
571
585
|
}
|
|
572
586
|
|
|
573
587
|
public async updateUserCustomMarginRatio(
|
|
574
588
|
marginRatio: number,
|
|
575
589
|
subAccountId = 0
|
|
576
590
|
): Promise<TransactionSignature> {
|
|
577
|
-
|
|
591
|
+
const tx = await this.program.transaction.updateUserCustomMarginRatio(
|
|
578
592
|
subAccountId,
|
|
579
593
|
marginRatio,
|
|
580
594
|
{
|
|
@@ -584,6 +598,8 @@ export class DriftClient {
|
|
|
584
598
|
},
|
|
585
599
|
}
|
|
586
600
|
);
|
|
601
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
602
|
+
return txSig;
|
|
587
603
|
}
|
|
588
604
|
|
|
589
605
|
public async updateUserMarginTradingEnabled(
|
|
@@ -595,7 +611,7 @@ export class DriftClient {
|
|
|
595
611
|
this.wallet.publicKey,
|
|
596
612
|
subAccountId
|
|
597
613
|
);
|
|
598
|
-
|
|
614
|
+
const tx = await this.program.transaction.updateUserMarginTradingEnabled(
|
|
599
615
|
subAccountId,
|
|
600
616
|
marginTradingEnabled,
|
|
601
617
|
{
|
|
@@ -605,18 +621,28 @@ export class DriftClient {
|
|
|
605
621
|
},
|
|
606
622
|
}
|
|
607
623
|
);
|
|
624
|
+
|
|
625
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
626
|
+
return txSig;
|
|
608
627
|
}
|
|
609
628
|
|
|
610
629
|
public async updateUserDelegate(
|
|
611
630
|
delegate: PublicKey,
|
|
612
631
|
subAccountId = 0
|
|
613
632
|
): Promise<TransactionSignature> {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
633
|
+
const tx = await this.program.transaction.updateUserDelegate(
|
|
634
|
+
subAccountId,
|
|
635
|
+
delegate,
|
|
636
|
+
{
|
|
637
|
+
accounts: {
|
|
638
|
+
user: await this.getUserAccountPublicKey(),
|
|
639
|
+
authority: this.wallet.publicKey,
|
|
640
|
+
},
|
|
641
|
+
}
|
|
642
|
+
);
|
|
643
|
+
|
|
644
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
645
|
+
return txSig;
|
|
620
646
|
}
|
|
621
647
|
|
|
622
648
|
public async getUserAccountsForDelegate(
|
|
@@ -662,7 +688,7 @@ export class DriftClient {
|
|
|
662
688
|
subAccountId
|
|
663
689
|
);
|
|
664
690
|
|
|
665
|
-
const
|
|
691
|
+
const ix = await this.program.instruction.deleteUser({
|
|
666
692
|
accounts: {
|
|
667
693
|
user: userAccountPublicKey,
|
|
668
694
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
@@ -671,6 +697,8 @@ export class DriftClient {
|
|
|
671
697
|
},
|
|
672
698
|
});
|
|
673
699
|
|
|
700
|
+
const { txSig } = await this.sendTransaction(wrapInTx(ix), [], this.opts);
|
|
701
|
+
|
|
674
702
|
await this.users.get(subAccountId)?.unsubscribe();
|
|
675
703
|
this.users.delete(subAccountId);
|
|
676
704
|
|
|
@@ -1036,7 +1064,7 @@ export class DriftClient {
|
|
|
1036
1064
|
);
|
|
1037
1065
|
}
|
|
1038
1066
|
|
|
1039
|
-
const { txSig, slot } = await this.
|
|
1067
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1040
1068
|
tx,
|
|
1041
1069
|
additionalSigners,
|
|
1042
1070
|
this.opts
|
|
@@ -1064,7 +1092,7 @@ export class DriftClient {
|
|
|
1064
1092
|
let remainingAccounts = [];
|
|
1065
1093
|
if (userInitialized) {
|
|
1066
1094
|
remainingAccounts = this.getRemainingAccounts({
|
|
1067
|
-
userAccounts: [this.
|
|
1095
|
+
userAccounts: [await this.forceGetUserAccount()],
|
|
1068
1096
|
useMarketLastSlotCache: true,
|
|
1069
1097
|
writableSpotMarketIndexes: [marketIndex],
|
|
1070
1098
|
});
|
|
@@ -1266,12 +1294,13 @@ export class DriftClient {
|
|
|
1266
1294
|
);
|
|
1267
1295
|
}
|
|
1268
1296
|
|
|
1269
|
-
const { txSig, slot } = await this.
|
|
1297
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1270
1298
|
tx,
|
|
1271
1299
|
additionalSigners,
|
|
1272
1300
|
this.opts
|
|
1273
1301
|
);
|
|
1274
1302
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
1303
|
+
|
|
1275
1304
|
return [txSig, userAccountPublicKey];
|
|
1276
1305
|
}
|
|
1277
1306
|
|
|
@@ -1393,7 +1422,7 @@ export class DriftClient {
|
|
|
1393
1422
|
);
|
|
1394
1423
|
}
|
|
1395
1424
|
|
|
1396
|
-
const { txSig, slot } = await this.
|
|
1425
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1397
1426
|
tx,
|
|
1398
1427
|
additionalSigners,
|
|
1399
1428
|
this.opts
|
|
@@ -1446,7 +1475,7 @@ export class DriftClient {
|
|
|
1446
1475
|
fromSubAccountId: number,
|
|
1447
1476
|
toSubAccountId: number
|
|
1448
1477
|
): Promise<TransactionSignature> {
|
|
1449
|
-
const { txSig, slot } = await this.
|
|
1478
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1450
1479
|
wrapInTx(
|
|
1451
1480
|
await this.getTransferDepositIx(
|
|
1452
1481
|
amount,
|
|
@@ -1524,7 +1553,7 @@ export class DriftClient {
|
|
|
1524
1553
|
public async updateSpotMarketCumulativeInterest(
|
|
1525
1554
|
marketIndex: number
|
|
1526
1555
|
): Promise<TransactionSignature> {
|
|
1527
|
-
const { txSig } = await this.
|
|
1556
|
+
const { txSig } = await this.sendTransaction(
|
|
1528
1557
|
wrapInTx(await this.updateSpotMarketCumulativeInterestIx(marketIndex)),
|
|
1529
1558
|
[],
|
|
1530
1559
|
this.opts
|
|
@@ -1549,7 +1578,7 @@ export class DriftClient {
|
|
|
1549
1578
|
settleeUserAccountPublicKey: PublicKey,
|
|
1550
1579
|
marketIndex: number
|
|
1551
1580
|
): Promise<TransactionSignature> {
|
|
1552
|
-
const { txSig } = await this.
|
|
1581
|
+
const { txSig } = await this.sendTransaction(
|
|
1553
1582
|
wrapInTx(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex)),
|
|
1554
1583
|
[],
|
|
1555
1584
|
this.opts
|
|
@@ -1583,7 +1612,7 @@ export class DriftClient {
|
|
|
1583
1612
|
marketIndex: number,
|
|
1584
1613
|
sharesToBurn?: BN
|
|
1585
1614
|
): Promise<TransactionSignature> {
|
|
1586
|
-
const { txSig } = await this.
|
|
1615
|
+
const { txSig } = await this.sendTransaction(
|
|
1587
1616
|
wrapInTx(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn)),
|
|
1588
1617
|
[],
|
|
1589
1618
|
this.opts
|
|
@@ -1596,7 +1625,7 @@ export class DriftClient {
|
|
|
1596
1625
|
userAccountPublicKey: PublicKey,
|
|
1597
1626
|
sharesToBurn?: BN
|
|
1598
1627
|
): Promise<TransactionSignature> {
|
|
1599
|
-
const { txSig } = await this.
|
|
1628
|
+
const { txSig } = await this.sendTransaction(
|
|
1600
1629
|
wrapInTx(
|
|
1601
1630
|
await this.getRemovePerpLpSharesInExpiringMarket(
|
|
1602
1631
|
marketIndex,
|
|
@@ -1685,7 +1714,7 @@ export class DriftClient {
|
|
|
1685
1714
|
amount: BN,
|
|
1686
1715
|
marketIndex: number
|
|
1687
1716
|
): Promise<TransactionSignature> {
|
|
1688
|
-
const { txSig, slot } = await this.
|
|
1717
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1689
1718
|
wrapInTx(await this.getAddPerpLpSharesIx(amount, marketIndex)),
|
|
1690
1719
|
[],
|
|
1691
1720
|
this.opts
|
|
@@ -1731,7 +1760,12 @@ export class DriftClient {
|
|
|
1731
1760
|
}
|
|
1732
1761
|
|
|
1733
1762
|
public async sendSignedTx(tx: Transaction): Promise<TransactionSignature> {
|
|
1734
|
-
const { txSig } = await this.
|
|
1763
|
+
const { txSig } = await this.sendTransaction(
|
|
1764
|
+
tx,
|
|
1765
|
+
undefined,
|
|
1766
|
+
this.opts,
|
|
1767
|
+
true
|
|
1768
|
+
);
|
|
1735
1769
|
|
|
1736
1770
|
return txSig;
|
|
1737
1771
|
}
|
|
@@ -1779,7 +1813,7 @@ export class DriftClient {
|
|
|
1779
1813
|
const [signedMarketOrderTx, signedFillTx] =
|
|
1780
1814
|
await this.provider.wallet.signAllTransactions([marketOrderTx, fillTx]);
|
|
1781
1815
|
|
|
1782
|
-
const { txSig, slot } = await this.
|
|
1816
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1783
1817
|
signedMarketOrderTx,
|
|
1784
1818
|
[],
|
|
1785
1819
|
this.opts,
|
|
@@ -1794,7 +1828,7 @@ export class DriftClient {
|
|
|
1794
1828
|
public async placePerpOrder(
|
|
1795
1829
|
orderParams: OptionalOrderParams
|
|
1796
1830
|
): Promise<TransactionSignature> {
|
|
1797
|
-
const { txSig, slot } = await this.
|
|
1831
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
1798
1832
|
wrapInTx(await this.getPlacePerpOrderIx(orderParams)),
|
|
1799
1833
|
[],
|
|
1800
1834
|
this.opts
|
|
@@ -1838,7 +1872,7 @@ export class DriftClient {
|
|
|
1838
1872
|
public async updateAMMs(
|
|
1839
1873
|
marketIndexes: number[]
|
|
1840
1874
|
): Promise<TransactionSignature> {
|
|
1841
|
-
const { txSig } = await this.
|
|
1875
|
+
const { txSig } = await this.sendTransaction(
|
|
1842
1876
|
wrapInTx(await this.getUpdateAMMsIx(marketIndexes)),
|
|
1843
1877
|
[],
|
|
1844
1878
|
this.opts
|
|
@@ -1883,7 +1917,7 @@ export class DriftClient {
|
|
|
1883
1917
|
public async settleExpiredMarket(
|
|
1884
1918
|
marketIndex: number
|
|
1885
1919
|
): Promise<TransactionSignature> {
|
|
1886
|
-
const { txSig } = await this.
|
|
1920
|
+
const { txSig } = await this.sendTransaction(
|
|
1887
1921
|
wrapInTx(await this.getSettleExpiredMarketIx(marketIndex)),
|
|
1888
1922
|
[],
|
|
1889
1923
|
this.opts
|
|
@@ -1951,13 +1985,13 @@ export class DriftClient {
|
|
|
1951
1985
|
},
|
|
1952
1986
|
});
|
|
1953
1987
|
|
|
1954
|
-
const { txSig } = await this.
|
|
1988
|
+
const { txSig } = await this.sendTransaction(wrapInTx(ix), [], this.opts);
|
|
1955
1989
|
|
|
1956
1990
|
return txSig;
|
|
1957
1991
|
}
|
|
1958
1992
|
|
|
1959
1993
|
public async cancelOrder(orderId?: number): Promise<TransactionSignature> {
|
|
1960
|
-
const { txSig } = await this.
|
|
1994
|
+
const { txSig } = await this.sendTransaction(
|
|
1961
1995
|
wrapInTx(await this.getCancelOrderIx(orderId)),
|
|
1962
1996
|
[],
|
|
1963
1997
|
this.opts
|
|
@@ -1988,7 +2022,7 @@ export class DriftClient {
|
|
|
1988
2022
|
public async cancelOrderByUserId(
|
|
1989
2023
|
userOrderId: number
|
|
1990
2024
|
): Promise<TransactionSignature> {
|
|
1991
|
-
const { txSig } = await this.
|
|
2025
|
+
const { txSig } = await this.sendTransaction(
|
|
1992
2026
|
wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId)),
|
|
1993
2027
|
[],
|
|
1994
2028
|
this.opts
|
|
@@ -2025,7 +2059,7 @@ export class DriftClient {
|
|
|
2025
2059
|
marketIndex?: number,
|
|
2026
2060
|
direction?: PositionDirection
|
|
2027
2061
|
): Promise<TransactionSignature> {
|
|
2028
|
-
const { txSig } = await this.
|
|
2062
|
+
const { txSig } = await this.sendTransaction(
|
|
2029
2063
|
wrapInTx(
|
|
2030
2064
|
await this.getCancelOrdersIx(marketType, marketIndex, direction)
|
|
2031
2065
|
),
|
|
@@ -2042,8 +2076,20 @@ export class DriftClient {
|
|
|
2042
2076
|
): Promise<TransactionInstruction> {
|
|
2043
2077
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2044
2078
|
|
|
2079
|
+
let readablePerpMarketIndex = undefined;
|
|
2080
|
+
let readableSpotMarketIndexes = undefined;
|
|
2081
|
+
if (marketIndex) {
|
|
2082
|
+
if (marketType && isVariant(marketType, 'perp')) {
|
|
2083
|
+
readablePerpMarketIndex = marketIndex;
|
|
2084
|
+
} else if (marketType && isVariant(marketType, 'spot')) {
|
|
2085
|
+
readableSpotMarketIndexes = [marketIndex];
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2045
2089
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2046
2090
|
userAccounts: [this.getUserAccount()],
|
|
2091
|
+
readablePerpMarketIndex,
|
|
2092
|
+
readableSpotMarketIndexes,
|
|
2047
2093
|
useMarketLastSlotCache: true,
|
|
2048
2094
|
});
|
|
2049
2095
|
|
|
@@ -2069,7 +2115,7 @@ export class DriftClient {
|
|
|
2069
2115
|
makerInfo?: MakerInfo,
|
|
2070
2116
|
referrerInfo?: ReferrerInfo
|
|
2071
2117
|
): Promise<TransactionSignature> {
|
|
2072
|
-
const { txSig } = await this.
|
|
2118
|
+
const { txSig } = await this.sendTransaction(
|
|
2073
2119
|
wrapInTx(
|
|
2074
2120
|
await this.getFillPerpOrderIx(
|
|
2075
2121
|
userAccountPublicKey,
|
|
@@ -2160,7 +2206,7 @@ export class DriftClient {
|
|
|
2160
2206
|
public async placeSpotOrder(
|
|
2161
2207
|
orderParams: OptionalOrderParams
|
|
2162
2208
|
): Promise<TransactionSignature> {
|
|
2163
|
-
const { txSig, slot } = await this.
|
|
2209
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
2164
2210
|
wrapInTx(await this.getPlaceSpotOrderIx(orderParams)),
|
|
2165
2211
|
[],
|
|
2166
2212
|
this.opts
|
|
@@ -2204,7 +2250,7 @@ export class DriftClient {
|
|
|
2204
2250
|
makerInfo?: MakerInfo,
|
|
2205
2251
|
referrerInfo?: ReferrerInfo
|
|
2206
2252
|
): Promise<TransactionSignature> {
|
|
2207
|
-
const { txSig } = await this.
|
|
2253
|
+
const { txSig } = await this.sendTransaction(
|
|
2208
2254
|
wrapInTx(
|
|
2209
2255
|
await this.getFillSpotOrderIx(
|
|
2210
2256
|
userAccountPublicKey,
|
|
@@ -2426,7 +2472,7 @@ export class DriftClient {
|
|
|
2426
2472
|
user: UserAccount,
|
|
2427
2473
|
order: Order
|
|
2428
2474
|
): Promise<TransactionSignature> {
|
|
2429
|
-
const { txSig } = await this.
|
|
2475
|
+
const { txSig } = await this.sendTransaction(
|
|
2430
2476
|
wrapInTx(await this.getTriggerOrderIx(userAccountPublicKey, user, order)),
|
|
2431
2477
|
[],
|
|
2432
2478
|
this.opts
|
|
@@ -2509,7 +2555,7 @@ export class DriftClient {
|
|
|
2509
2555
|
makerInfo?: MakerInfo,
|
|
2510
2556
|
referrerInfo?: ReferrerInfo
|
|
2511
2557
|
): Promise<TransactionSignature> {
|
|
2512
|
-
const { txSig, slot } = await this.
|
|
2558
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
2513
2559
|
wrapInTx(
|
|
2514
2560
|
await this.getPlaceAndTakePerpOrderIx(
|
|
2515
2561
|
orderParams,
|
|
@@ -2591,7 +2637,7 @@ export class DriftClient {
|
|
|
2591
2637
|
takerInfo: TakerInfo,
|
|
2592
2638
|
referrerInfo?: ReferrerInfo
|
|
2593
2639
|
): Promise<TransactionSignature> {
|
|
2594
|
-
const { txSig, slot } = await this.
|
|
2640
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
2595
2641
|
wrapInTx(
|
|
2596
2642
|
await this.getPlaceAndMakePerpOrderIx(
|
|
2597
2643
|
orderParams,
|
|
@@ -2660,7 +2706,7 @@ export class DriftClient {
|
|
|
2660
2706
|
makerInfo?: MakerInfo,
|
|
2661
2707
|
referrerInfo?: ReferrerInfo
|
|
2662
2708
|
): Promise<TransactionSignature> {
|
|
2663
|
-
const { txSig, slot } = await this.
|
|
2709
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
2664
2710
|
wrapInTx(
|
|
2665
2711
|
await this.getPlaceAndTakeSpotOrderIx(
|
|
2666
2712
|
orderParams,
|
|
@@ -2756,7 +2802,7 @@ export class DriftClient {
|
|
|
2756
2802
|
fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
2757
2803
|
referrerInfo?: ReferrerInfo
|
|
2758
2804
|
): Promise<TransactionSignature> {
|
|
2759
|
-
const { txSig, slot } = await this.
|
|
2805
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
2760
2806
|
wrapInTx(
|
|
2761
2807
|
await this.getPlaceAndMakeSpotOrderIx(
|
|
2762
2808
|
orderParams,
|
|
@@ -2909,7 +2955,7 @@ export class DriftClient {
|
|
|
2909
2955
|
);
|
|
2910
2956
|
tx.add(cancelOrderIx);
|
|
2911
2957
|
tx.add(placeOrderIx);
|
|
2912
|
-
const { txSig, slot } = await this.
|
|
2958
|
+
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
2913
2959
|
this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
|
|
2914
2960
|
return txSig;
|
|
2915
2961
|
}
|
|
@@ -2941,7 +2987,7 @@ export class DriftClient {
|
|
|
2941
2987
|
)
|
|
2942
2988
|
.add(...ixs);
|
|
2943
2989
|
|
|
2944
|
-
const { txSig } = await this.
|
|
2990
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2945
2991
|
return txSig;
|
|
2946
2992
|
}
|
|
2947
2993
|
|
|
@@ -2950,7 +2996,7 @@ export class DriftClient {
|
|
|
2950
2996
|
settleeUserAccount: UserAccount,
|
|
2951
2997
|
marketIndex: number
|
|
2952
2998
|
): Promise<TransactionSignature> {
|
|
2953
|
-
const { txSig } = await this.
|
|
2999
|
+
const { txSig } = await this.sendTransaction(
|
|
2954
3000
|
wrapInTx(
|
|
2955
3001
|
await this.settlePNLIx(
|
|
2956
3002
|
settleeUserAccountPublicKey,
|
|
@@ -2993,7 +3039,7 @@ export class DriftClient {
|
|
|
2993
3039
|
maxBaseAssetAmount: BN,
|
|
2994
3040
|
limitPrice?: BN
|
|
2995
3041
|
): Promise<TransactionSignature> {
|
|
2996
|
-
const { txSig, slot } = await this.
|
|
3042
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
2997
3043
|
wrapInTx(
|
|
2998
3044
|
await this.getLiquidatePerpIx(
|
|
2999
3045
|
userAccountPublicKey,
|
|
@@ -3057,7 +3103,7 @@ export class DriftClient {
|
|
|
3057
3103
|
maxLiabilityTransfer: BN,
|
|
3058
3104
|
limitPrice?: BN
|
|
3059
3105
|
): Promise<TransactionSignature> {
|
|
3060
|
-
const { txSig, slot } = await this.
|
|
3106
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
3061
3107
|
wrapInTx(
|
|
3062
3108
|
await this.getLiquidateSpotIx(
|
|
3063
3109
|
userAccountPublicKey,
|
|
@@ -3125,7 +3171,7 @@ export class DriftClient {
|
|
|
3125
3171
|
maxLiabilityTransfer: BN,
|
|
3126
3172
|
limitPrice?: BN
|
|
3127
3173
|
): Promise<TransactionSignature> {
|
|
3128
|
-
const { txSig, slot } = await this.
|
|
3174
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
3129
3175
|
wrapInTx(
|
|
3130
3176
|
await this.getLiquidateBorrowForPerpPnlIx(
|
|
3131
3177
|
userAccountPublicKey,
|
|
@@ -3193,7 +3239,7 @@ export class DriftClient {
|
|
|
3193
3239
|
maxPnlTransfer: BN,
|
|
3194
3240
|
limitPrice?: BN
|
|
3195
3241
|
): Promise<TransactionSignature> {
|
|
3196
|
-
const { txSig, slot } = await this.
|
|
3242
|
+
const { txSig, slot } = await this.sendTransaction(
|
|
3197
3243
|
wrapInTx(
|
|
3198
3244
|
await this.getLiquidatePerpPnlForDepositIx(
|
|
3199
3245
|
userAccountPublicKey,
|
|
@@ -3258,7 +3304,7 @@ export class DriftClient {
|
|
|
3258
3304
|
userAccount: UserAccount,
|
|
3259
3305
|
marketIndex: number
|
|
3260
3306
|
): Promise<TransactionSignature> {
|
|
3261
|
-
const { txSig } = await this.
|
|
3307
|
+
const { txSig } = await this.sendTransaction(
|
|
3262
3308
|
wrapInTx(
|
|
3263
3309
|
await this.getResolvePerpBankruptcyIx(
|
|
3264
3310
|
userAccountPublicKey,
|
|
@@ -3319,7 +3365,7 @@ export class DriftClient {
|
|
|
3319
3365
|
userAccount: UserAccount,
|
|
3320
3366
|
marketIndex: number
|
|
3321
3367
|
): Promise<TransactionSignature> {
|
|
3322
|
-
const { txSig } = await this.
|
|
3368
|
+
const { txSig } = await this.sendTransaction(
|
|
3323
3369
|
wrapInTx(
|
|
3324
3370
|
await this.getResolveSpotBankruptcyIx(
|
|
3325
3371
|
userAccountPublicKey,
|
|
@@ -3374,7 +3420,7 @@ export class DriftClient {
|
|
|
3374
3420
|
perpMarketIndex: number,
|
|
3375
3421
|
oracle: PublicKey
|
|
3376
3422
|
): Promise<TransactionSignature> {
|
|
3377
|
-
const { txSig } = await this.
|
|
3423
|
+
const { txSig } = await this.sendTransaction(
|
|
3378
3424
|
wrapInTx(await this.getUpdateFundingRateIx(perpMarketIndex, oracle)),
|
|
3379
3425
|
[],
|
|
3380
3426
|
this.opts
|
|
@@ -3402,7 +3448,7 @@ export class DriftClient {
|
|
|
3402
3448
|
public async settleFundingPayment(
|
|
3403
3449
|
userAccountPublicKey: PublicKey
|
|
3404
3450
|
): Promise<TransactionSignature> {
|
|
3405
|
-
const { txSig } = await this.
|
|
3451
|
+
const { txSig } = await this.sendTransaction(
|
|
3406
3452
|
wrapInTx(await this.getSettleFundingPaymentIx(userAccountPublicKey)),
|
|
3407
3453
|
[],
|
|
3408
3454
|
this.opts
|
|
@@ -3459,7 +3505,7 @@ export class DriftClient {
|
|
|
3459
3505
|
public async initializeInsuranceFundStake(
|
|
3460
3506
|
marketIndex: number
|
|
3461
3507
|
): Promise<TransactionSignature> {
|
|
3462
|
-
const { txSig } = await this.
|
|
3508
|
+
const { txSig } = await this.sendTransaction(
|
|
3463
3509
|
wrapInTx(await this.getInitializeInsuranceFundStakeIx(marketIndex)),
|
|
3464
3510
|
[],
|
|
3465
3511
|
this.opts
|
|
@@ -3511,21 +3557,28 @@ export class DriftClient {
|
|
|
3511
3557
|
writableSpotMarketIndexes: [marketIndex],
|
|
3512
3558
|
});
|
|
3513
3559
|
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3560
|
+
const tx = await this.program.transaction.addInsuranceFundStake(
|
|
3561
|
+
marketIndex,
|
|
3562
|
+
amount,
|
|
3563
|
+
{
|
|
3564
|
+
accounts: {
|
|
3565
|
+
state: await this.getStatePublicKey(),
|
|
3566
|
+
spotMarket: spotMarket.pubkey,
|
|
3567
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
3568
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
3569
|
+
authority: this.wallet.publicKey,
|
|
3570
|
+
spotMarketVault: spotMarket.vault,
|
|
3571
|
+
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
3572
|
+
driftSigner: this.getSignerPublicKey(),
|
|
3573
|
+
userTokenAccount: collateralAccountPublicKey,
|
|
3574
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
3575
|
+
},
|
|
3576
|
+
remainingAccounts,
|
|
3577
|
+
}
|
|
3578
|
+
);
|
|
3579
|
+
|
|
3580
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3581
|
+
return txSig;
|
|
3529
3582
|
}
|
|
3530
3583
|
|
|
3531
3584
|
public async requestRemoveInsuranceFundStake(
|
|
@@ -3545,7 +3598,7 @@ export class DriftClient {
|
|
|
3545
3598
|
writableSpotMarketIndexes: [marketIndex],
|
|
3546
3599
|
});
|
|
3547
3600
|
|
|
3548
|
-
|
|
3601
|
+
const tx = await this.program.transaction.requestRemoveInsuranceFundStake(
|
|
3549
3602
|
marketIndex,
|
|
3550
3603
|
amount,
|
|
3551
3604
|
{
|
|
@@ -3560,6 +3613,9 @@ export class DriftClient {
|
|
|
3560
3613
|
remainingAccounts,
|
|
3561
3614
|
}
|
|
3562
3615
|
);
|
|
3616
|
+
|
|
3617
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3618
|
+
return txSig;
|
|
3563
3619
|
}
|
|
3564
3620
|
|
|
3565
3621
|
public async cancelRequestRemoveInsuranceFundStake(
|
|
@@ -3578,20 +3634,24 @@ export class DriftClient {
|
|
|
3578
3634
|
writableSpotMarketIndexes: [marketIndex],
|
|
3579
3635
|
});
|
|
3580
3636
|
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3637
|
+
const tx =
|
|
3638
|
+
await this.program.transaction.cancelRequestRemoveInsuranceFundStake(
|
|
3639
|
+
marketIndex,
|
|
3640
|
+
{
|
|
3641
|
+
accounts: {
|
|
3642
|
+
state: await this.getStatePublicKey(),
|
|
3643
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
3644
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
3645
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
3646
|
+
authority: this.wallet.publicKey,
|
|
3647
|
+
insuranceFundVault: spotMarketAccount.insuranceFund.vault,
|
|
3648
|
+
},
|
|
3649
|
+
remainingAccounts,
|
|
3650
|
+
}
|
|
3651
|
+
);
|
|
3652
|
+
|
|
3653
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3654
|
+
return txSig;
|
|
3595
3655
|
}
|
|
3596
3656
|
|
|
3597
3657
|
public async removeInsuranceFundStake(
|
|
@@ -3611,20 +3671,26 @@ export class DriftClient {
|
|
|
3611
3671
|
writableSpotMarketIndexes: [marketIndex],
|
|
3612
3672
|
});
|
|
3613
3673
|
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3674
|
+
const tx = await this.program.transaction.removeInsuranceFundStake(
|
|
3675
|
+
marketIndex,
|
|
3676
|
+
{
|
|
3677
|
+
accounts: {
|
|
3678
|
+
state: await this.getStatePublicKey(),
|
|
3679
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
3680
|
+
insuranceFundStake: ifStakeAccountPublicKey,
|
|
3681
|
+
userStats: this.getUserStatsAccountPublicKey(),
|
|
3682
|
+
authority: this.wallet.publicKey,
|
|
3683
|
+
insuranceFundVault: spotMarketAccount.insuranceFund.vault,
|
|
3684
|
+
driftSigner: this.getSignerPublicKey(),
|
|
3685
|
+
userTokenAccount: collateralAccountPublicKey,
|
|
3686
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
3687
|
+
},
|
|
3688
|
+
remainingAccounts,
|
|
3689
|
+
}
|
|
3690
|
+
);
|
|
3691
|
+
|
|
3692
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3693
|
+
return txSig;
|
|
3628
3694
|
}
|
|
3629
3695
|
|
|
3630
3696
|
public async settleRevenueToInsuranceFund(
|
|
@@ -3638,24 +3704,30 @@ export class DriftClient {
|
|
|
3638
3704
|
writableSpotMarketIndexes: [marketIndex],
|
|
3639
3705
|
});
|
|
3640
3706
|
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3707
|
+
const tx = await this.program.transaction.settleRevenueToInsuranceFund(
|
|
3708
|
+
marketIndex,
|
|
3709
|
+
{
|
|
3710
|
+
accounts: {
|
|
3711
|
+
state: await this.getStatePublicKey(),
|
|
3712
|
+
spotMarket: spotMarketAccount.pubkey,
|
|
3713
|
+
spotMarketVault: spotMarketAccount.vault,
|
|
3714
|
+
driftSigner: this.getSignerPublicKey(),
|
|
3715
|
+
insuranceFundVault: spotMarketAccount.insuranceFund.vault,
|
|
3716
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
3717
|
+
},
|
|
3718
|
+
remainingAccounts,
|
|
3719
|
+
}
|
|
3720
|
+
);
|
|
3721
|
+
|
|
3722
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
3723
|
+
return txSig;
|
|
3652
3724
|
}
|
|
3653
3725
|
|
|
3654
3726
|
public async resolvePerpPnlDeficit(
|
|
3655
3727
|
spotMarketIndex: number,
|
|
3656
3728
|
perpMarketIndex: number
|
|
3657
3729
|
): Promise<TransactionSignature> {
|
|
3658
|
-
const { txSig } = await this.
|
|
3730
|
+
const { txSig } = await this.sendTransaction(
|
|
3659
3731
|
wrapInTx(
|
|
3660
3732
|
await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex)
|
|
3661
3733
|
),
|
|
@@ -3694,4 +3766,13 @@ export class DriftClient {
|
|
|
3694
3766
|
}
|
|
3695
3767
|
);
|
|
3696
3768
|
}
|
|
3769
|
+
|
|
3770
|
+
sendTransaction(
|
|
3771
|
+
tx: Transaction,
|
|
3772
|
+
additionalSigners?: Array<Signer>,
|
|
3773
|
+
opts?: ConfirmOptions,
|
|
3774
|
+
preSigned?: boolean
|
|
3775
|
+
): Promise<TxSigAndSlot> {
|
|
3776
|
+
return this.txSender.send(tx, additionalSigners, opts, preSigned);
|
|
3777
|
+
}
|
|
3697
3778
|
}
|