@drift-labs/sdk 2.152.0-beta.2 → 2.153.0-beta.0
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/build-browser.js +58 -0
- package/bun.lock +182 -1
- package/esbuild-shims.js +12 -0
- package/lib/browser/constants/perpMarkets.js +12 -0
- package/lib/browser/constants/txConstants.d.ts +1 -0
- package/lib/browser/constants/txConstants.js +2 -1
- package/lib/browser/driftClient.d.ts +13 -6
- package/lib/browser/driftClient.js +280 -36
- package/lib/browser/idl/drift.json +207 -18
- package/lib/browser/markets.d.ts +5 -0
- package/lib/browser/markets.js +16 -0
- package/lib/browser/swap/UnifiedSwapClient.js +2 -0
- package/lib/browser/titan/titanClient.d.ts +3 -0
- package/lib/browser/titan/titanClient.js +58 -60
- package/lib/browser/user.d.ts +1 -1
- package/lib/node/constants/perpMarkets.d.ts.map +1 -1
- package/lib/node/constants/perpMarkets.js +12 -0
- package/lib/node/constants/txConstants.d.ts +1 -0
- package/lib/node/constants/txConstants.d.ts.map +1 -1
- package/lib/node/constants/txConstants.js +2 -1
- package/lib/node/driftClient.d.ts +13 -6
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +280 -36
- package/lib/node/idl/drift.json +207 -18
- package/lib/node/markets.d.ts +6 -0
- package/lib/node/markets.d.ts.map +1 -0
- package/lib/node/markets.js +16 -0
- package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
- package/lib/node/swap/UnifiedSwapClient.js +2 -0
- package/lib/node/titan/titanClient.d.ts +3 -0
- package/lib/node/titan/titanClient.d.ts.map +1 -1
- package/lib/node/titan/titanClient.js +58 -60
- package/lib/node/user.d.ts +1 -1
- package/lib/node/user.d.ts.map +1 -1
- package/package.json +10 -2
- package/src/constants/perpMarkets.ts +13 -0
- package/src/constants/txConstants.ts +2 -0
- package/src/driftClient.ts +477 -52
- package/src/idl/drift.json +207 -18
- package/src/markets.ts +24 -0
- package/src/swap/UnifiedSwapClient.ts +2 -0
- package/src/titan/titanClient.ts +88 -72
- package/src/user.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.152.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
{
|
|
24
24
|
"name": "authority",
|
|
25
25
|
"isMut": false,
|
|
26
|
-
"isSigner":
|
|
26
|
+
"isSigner": false
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"name": "payer",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
{
|
|
74
74
|
"name": "authority",
|
|
75
75
|
"isMut": false,
|
|
76
|
-
"isSigner":
|
|
76
|
+
"isSigner": false
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
79
|
"name": "payer",
|
|
@@ -652,6 +652,163 @@
|
|
|
652
652
|
}
|
|
653
653
|
]
|
|
654
654
|
},
|
|
655
|
+
{
|
|
656
|
+
"name": "depositIntoIsolatedPerpPosition",
|
|
657
|
+
"accounts": [
|
|
658
|
+
{
|
|
659
|
+
"name": "state",
|
|
660
|
+
"isMut": false,
|
|
661
|
+
"isSigner": false
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
"name": "user",
|
|
665
|
+
"isMut": true,
|
|
666
|
+
"isSigner": false
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
"name": "userStats",
|
|
670
|
+
"isMut": true,
|
|
671
|
+
"isSigner": false
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
"name": "authority",
|
|
675
|
+
"isMut": false,
|
|
676
|
+
"isSigner": true
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
"name": "spotMarketVault",
|
|
680
|
+
"isMut": true,
|
|
681
|
+
"isSigner": false
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
"name": "userTokenAccount",
|
|
685
|
+
"isMut": true,
|
|
686
|
+
"isSigner": false
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
"name": "tokenProgram",
|
|
690
|
+
"isMut": false,
|
|
691
|
+
"isSigner": false
|
|
692
|
+
}
|
|
693
|
+
],
|
|
694
|
+
"args": [
|
|
695
|
+
{
|
|
696
|
+
"name": "spotMarketIndex",
|
|
697
|
+
"type": "u16"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
"name": "perpMarketIndex",
|
|
701
|
+
"type": "u16"
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
"name": "amount",
|
|
705
|
+
"type": "u64"
|
|
706
|
+
}
|
|
707
|
+
]
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
"name": "transferIsolatedPerpPositionDeposit",
|
|
711
|
+
"accounts": [
|
|
712
|
+
{
|
|
713
|
+
"name": "user",
|
|
714
|
+
"isMut": true,
|
|
715
|
+
"isSigner": false
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
"name": "userStats",
|
|
719
|
+
"isMut": true,
|
|
720
|
+
"isSigner": false
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
"name": "authority",
|
|
724
|
+
"isMut": false,
|
|
725
|
+
"isSigner": true
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
"name": "state",
|
|
729
|
+
"isMut": false,
|
|
730
|
+
"isSigner": false
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
"name": "spotMarketVault",
|
|
734
|
+
"isMut": false,
|
|
735
|
+
"isSigner": false
|
|
736
|
+
}
|
|
737
|
+
],
|
|
738
|
+
"args": [
|
|
739
|
+
{
|
|
740
|
+
"name": "spotMarketIndex",
|
|
741
|
+
"type": "u16"
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
"name": "perpMarketIndex",
|
|
745
|
+
"type": "u16"
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
"name": "amount",
|
|
749
|
+
"type": "i64"
|
|
750
|
+
}
|
|
751
|
+
]
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
"name": "withdrawFromIsolatedPerpPosition",
|
|
755
|
+
"accounts": [
|
|
756
|
+
{
|
|
757
|
+
"name": "state",
|
|
758
|
+
"isMut": false,
|
|
759
|
+
"isSigner": false
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
"name": "user",
|
|
763
|
+
"isMut": true,
|
|
764
|
+
"isSigner": false
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
"name": "userStats",
|
|
768
|
+
"isMut": true,
|
|
769
|
+
"isSigner": false
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
"name": "authority",
|
|
773
|
+
"isMut": false,
|
|
774
|
+
"isSigner": true
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
"name": "spotMarketVault",
|
|
778
|
+
"isMut": true,
|
|
779
|
+
"isSigner": false
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
"name": "driftSigner",
|
|
783
|
+
"isMut": false,
|
|
784
|
+
"isSigner": false
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
"name": "userTokenAccount",
|
|
788
|
+
"isMut": true,
|
|
789
|
+
"isSigner": false
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
"name": "tokenProgram",
|
|
793
|
+
"isMut": false,
|
|
794
|
+
"isSigner": false
|
|
795
|
+
}
|
|
796
|
+
],
|
|
797
|
+
"args": [
|
|
798
|
+
{
|
|
799
|
+
"name": "spotMarketIndex",
|
|
800
|
+
"type": "u16"
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
"name": "perpMarketIndex",
|
|
804
|
+
"type": "u16"
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
"name": "amount",
|
|
808
|
+
"type": "u64"
|
|
809
|
+
}
|
|
810
|
+
]
|
|
811
|
+
},
|
|
655
812
|
{
|
|
656
813
|
"name": "placePerpOrder",
|
|
657
814
|
"accounts": [
|
|
@@ -11584,7 +11741,7 @@
|
|
|
11584
11741
|
},
|
|
11585
11742
|
{
|
|
11586
11743
|
"name": "disableUpdatePerpBidAskTwap",
|
|
11587
|
-
"type": "
|
|
11744
|
+
"type": "u8"
|
|
11588
11745
|
},
|
|
11589
11746
|
{
|
|
11590
11747
|
"name": "pausedOperations",
|
|
@@ -14407,13 +14564,13 @@
|
|
|
14407
14564
|
"type": "u64"
|
|
14408
14565
|
},
|
|
14409
14566
|
{
|
|
14410
|
-
"name": "
|
|
14567
|
+
"name": "isolatedPositionScaledBalance",
|
|
14411
14568
|
"docs": [
|
|
14412
14569
|
"The last base asset amount per lp the amm had",
|
|
14413
14570
|
"Used to settle the users lp position",
|
|
14414
|
-
"precision:
|
|
14571
|
+
"precision: SPOT_BALANCE_PRECISION"
|
|
14415
14572
|
],
|
|
14416
|
-
"type": "
|
|
14573
|
+
"type": "u64"
|
|
14417
14574
|
},
|
|
14418
14575
|
{
|
|
14419
14576
|
"name": "lastQuoteAssetAmountPerLp",
|
|
@@ -14452,8 +14609,8 @@
|
|
|
14452
14609
|
"type": "u8"
|
|
14453
14610
|
},
|
|
14454
14611
|
{
|
|
14455
|
-
"name": "
|
|
14456
|
-
"type": "
|
|
14612
|
+
"name": "positionFlag",
|
|
14613
|
+
"type": "u8"
|
|
14457
14614
|
}
|
|
14458
14615
|
]
|
|
14459
14616
|
}
|
|
@@ -15133,6 +15290,17 @@
|
|
|
15133
15290
|
]
|
|
15134
15291
|
}
|
|
15135
15292
|
},
|
|
15293
|
+
{
|
|
15294
|
+
"name": "LiquidationBitFlag",
|
|
15295
|
+
"type": {
|
|
15296
|
+
"kind": "enum",
|
|
15297
|
+
"variants": [
|
|
15298
|
+
{
|
|
15299
|
+
"name": "IsolatedPosition"
|
|
15300
|
+
}
|
|
15301
|
+
]
|
|
15302
|
+
}
|
|
15303
|
+
},
|
|
15136
15304
|
{
|
|
15137
15305
|
"name": "SettlePnlExplanation",
|
|
15138
15306
|
"type": {
|
|
@@ -15262,13 +15430,7 @@
|
|
|
15262
15430
|
"kind": "enum",
|
|
15263
15431
|
"variants": [
|
|
15264
15432
|
{
|
|
15265
|
-
"name": "Standard"
|
|
15266
|
-
"fields": [
|
|
15267
|
-
{
|
|
15268
|
-
"name": "trackOpenOrdersFraction",
|
|
15269
|
-
"type": "bool"
|
|
15270
|
-
}
|
|
15271
|
-
]
|
|
15433
|
+
"name": "Standard"
|
|
15272
15434
|
},
|
|
15273
15435
|
{
|
|
15274
15436
|
"name": "Liquidation",
|
|
@@ -15910,6 +16072,23 @@
|
|
|
15910
16072
|
]
|
|
15911
16073
|
}
|
|
15912
16074
|
},
|
|
16075
|
+
{
|
|
16076
|
+
"name": "PositionFlag",
|
|
16077
|
+
"type": {
|
|
16078
|
+
"kind": "enum",
|
|
16079
|
+
"variants": [
|
|
16080
|
+
{
|
|
16081
|
+
"name": "IsolatedPosition"
|
|
16082
|
+
},
|
|
16083
|
+
{
|
|
16084
|
+
"name": "BeingLiquidated"
|
|
16085
|
+
},
|
|
16086
|
+
{
|
|
16087
|
+
"name": "Bankrupt"
|
|
16088
|
+
}
|
|
16089
|
+
]
|
|
16090
|
+
}
|
|
16091
|
+
},
|
|
15913
16092
|
{
|
|
15914
16093
|
"name": "ReferrerStatus",
|
|
15915
16094
|
"type": {
|
|
@@ -16903,6 +17082,11 @@
|
|
|
16903
17082
|
"defined": "SpotBankruptcyRecord"
|
|
16904
17083
|
},
|
|
16905
17084
|
"index": false
|
|
17085
|
+
},
|
|
17086
|
+
{
|
|
17087
|
+
"name": "bitFlags",
|
|
17088
|
+
"type": "u8",
|
|
17089
|
+
"index": false
|
|
16906
17090
|
}
|
|
16907
17091
|
]
|
|
16908
17092
|
},
|
|
@@ -18339,8 +18523,8 @@
|
|
|
18339
18523
|
},
|
|
18340
18524
|
{
|
|
18341
18525
|
"code": 6094,
|
|
18342
|
-
"name": "
|
|
18343
|
-
"msg": "
|
|
18526
|
+
"name": "CantUpdateSpotBalanceType",
|
|
18527
|
+
"msg": "CantUpdateSpotBalanceType"
|
|
18344
18528
|
},
|
|
18345
18529
|
{
|
|
18346
18530
|
"code": 6095,
|
|
@@ -19591,6 +19775,11 @@
|
|
|
19591
19775
|
"code": 6344,
|
|
19592
19776
|
"name": "MarketIndexNotFoundAmmCache",
|
|
19593
19777
|
"msg": "MarketIndexNotFoundAmmCache"
|
|
19778
|
+
},
|
|
19779
|
+
{
|
|
19780
|
+
"code": 6345,
|
|
19781
|
+
"name": "InvalidIsolatedPerpMarket",
|
|
19782
|
+
"msg": "Invalid Isolated Perp Market"
|
|
19594
19783
|
}
|
|
19595
19784
|
],
|
|
19596
19785
|
"metadata": {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DriftEnv } from './config';
|
|
2
|
+
import { SpotMarketConfig } from './constants';
|
|
3
|
+
import { PerpMarketConfig } from './constants/perpMarkets';
|
|
4
|
+
export declare const getActivePerpMarkets: (driftEnv: DriftEnv) => PerpMarketConfig[];
|
|
5
|
+
export declare const getActiveSpotMarkets: (driftEnv: DriftEnv) => SpotMarketConfig[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getActiveSpotMarkets = exports.getActivePerpMarkets = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const perpMarkets_1 = require("./constants/perpMarkets");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const getActivePerpMarkets = (driftEnv) => {
|
|
8
|
+
return perpMarkets_1.PerpMarkets[driftEnv !== null && driftEnv !== void 0 ? driftEnv : 'mainnet-beta'].filter((market) => !market.marketStatus ||
|
|
9
|
+
!(0, types_1.isOneOfVariant)(market.marketStatus, ['delisted', 'settlement']));
|
|
10
|
+
};
|
|
11
|
+
exports.getActivePerpMarkets = getActivePerpMarkets;
|
|
12
|
+
const getActiveSpotMarkets = (driftEnv) => {
|
|
13
|
+
return constants_1.SpotMarkets[driftEnv !== null && driftEnv !== void 0 ? driftEnv : 'mainnet-beta'].filter((market) => !market.marketStatus ||
|
|
14
|
+
!(0, types_1.isOneOfVariant)(market.marketStatus, ['delisted', 'settlement']));
|
|
15
|
+
};
|
|
16
|
+
exports.getActiveSpotMarkets = getActiveSpotMarkets;
|
|
@@ -49,6 +49,7 @@ class UnifiedSwapClient {
|
|
|
49
49
|
...titanParams,
|
|
50
50
|
userPublicKey: titanParams.userPublicKey,
|
|
51
51
|
swapMode: titanParams.swapMode, // Titan expects string
|
|
52
|
+
sizeConstraint: titanParams.sizeConstraint || 1280 - 375, // Use same default as getSwapInstructions
|
|
52
53
|
};
|
|
53
54
|
return await titanClient.getQuote(titanParamsWithUser);
|
|
54
55
|
}
|
|
@@ -79,6 +80,7 @@ class UnifiedSwapClient {
|
|
|
79
80
|
userPublicKey,
|
|
80
81
|
slippageBps: slippageBps || titanQuote.slippageBps,
|
|
81
82
|
swapMode: titanQuote.swapMode,
|
|
83
|
+
sizeConstraint: 1280 - 375, // MAX_TX_BYTE_SIZE - buffer for drift instructions
|
|
82
84
|
});
|
|
83
85
|
return {
|
|
84
86
|
transactionMessage: result.transactionMessage,
|
|
@@ -30,12 +30,15 @@ export declare class TitanClient {
|
|
|
30
30
|
url: string;
|
|
31
31
|
connection: Connection;
|
|
32
32
|
proxyUrl?: string;
|
|
33
|
+
private lastQuoteData?;
|
|
34
|
+
private lastQuoteParams?;
|
|
33
35
|
constructor({ connection, authToken, url, proxyUrl, }: {
|
|
34
36
|
connection: Connection;
|
|
35
37
|
authToken: string;
|
|
36
38
|
url?: string;
|
|
37
39
|
proxyUrl?: string;
|
|
38
40
|
});
|
|
41
|
+
private buildParams;
|
|
39
42
|
/**
|
|
40
43
|
* Get routes for a swap
|
|
41
44
|
*/
|
|
@@ -16,31 +16,48 @@ class TitanClient {
|
|
|
16
16
|
this.url = url !== null && url !== void 0 ? url : TITAN_API_URL;
|
|
17
17
|
this.proxyUrl = proxyUrl;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const params = new URLSearchParams({
|
|
19
|
+
buildParams({ inputMint, outputMint, amount, userPublicKey, maxAccounts, slippageBps, swapMode, onlyDirectRoutes, excludeDexes, sizeConstraint, accountsLimitWritable, }) {
|
|
20
|
+
// Normalize swapMode to enum value
|
|
21
|
+
const normalizedSwapMode = swapMode === 'ExactOut' || swapMode === SwapMode.ExactOut
|
|
22
|
+
? SwapMode.ExactOut
|
|
23
|
+
: SwapMode.ExactIn;
|
|
24
|
+
return new URLSearchParams({
|
|
26
25
|
inputMint: inputMint.toString(),
|
|
27
26
|
outputMint: outputMint.toString(),
|
|
28
27
|
amount: amount.toString(),
|
|
29
28
|
userPublicKey: userPublicKey.toString(),
|
|
30
29
|
...(slippageBps && { slippageBps: slippageBps.toString() }),
|
|
31
|
-
...(swapMode && {
|
|
32
|
-
|
|
33
|
-
}),
|
|
30
|
+
...(swapMode && { swapMode: normalizedSwapMode.toString() }),
|
|
31
|
+
...(maxAccounts && { accountsLimitTotal: maxAccounts.toString() }),
|
|
32
|
+
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
34
33
|
...(onlyDirectRoutes && {
|
|
35
34
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
36
35
|
}),
|
|
37
|
-
...(maxAccounts && { accountsLimitTotal: maxAccounts.toString() }),
|
|
38
|
-
...(excludeDexes && { excludeDexes: excludeDexes.join(',') }),
|
|
39
36
|
...(sizeConstraint && { sizeConstraint: sizeConstraint.toString() }),
|
|
40
37
|
...(accountsLimitWritable && {
|
|
41
38
|
accountsLimitWritable: accountsLimitWritable.toString(),
|
|
42
39
|
}),
|
|
43
40
|
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get routes for a swap
|
|
44
|
+
*/
|
|
45
|
+
async getQuote({ inputMint, outputMint, amount, userPublicKey, maxAccounts = 50, // 50 is an estimated amount with buffer
|
|
46
|
+
slippageBps, swapMode, onlyDirectRoutes, excludeDexes, sizeConstraint, accountsLimitWritable, }) {
|
|
47
|
+
var _a;
|
|
48
|
+
const params = this.buildParams({
|
|
49
|
+
inputMint,
|
|
50
|
+
outputMint,
|
|
51
|
+
amount,
|
|
52
|
+
userPublicKey,
|
|
53
|
+
maxAccounts,
|
|
54
|
+
slippageBps,
|
|
55
|
+
swapMode,
|
|
56
|
+
onlyDirectRoutes,
|
|
57
|
+
excludeDexes,
|
|
58
|
+
sizeConstraint,
|
|
59
|
+
accountsLimitWritable,
|
|
60
|
+
});
|
|
44
61
|
let response;
|
|
45
62
|
if (this.proxyUrl) {
|
|
46
63
|
// Use proxy route - send parameters in request body
|
|
@@ -67,8 +84,11 @@ class TitanClient {
|
|
|
67
84
|
}
|
|
68
85
|
const buffer = await response.arrayBuffer();
|
|
69
86
|
const data = (0, msgpack_1.decode)(buffer);
|
|
70
|
-
|
|
71
|
-
|
|
87
|
+
// Cache the quote data and parameters for later use in getSwap
|
|
88
|
+
this.lastQuoteData = data;
|
|
89
|
+
this.lastQuoteParams = params.toString();
|
|
90
|
+
// We are only querying for the best avaiable route so use that
|
|
91
|
+
const route = data.quotes[Object.keys(data.quotes)[0]];
|
|
72
92
|
if (!route) {
|
|
73
93
|
throw new Error('No routes available');
|
|
74
94
|
}
|
|
@@ -110,54 +130,27 @@ class TitanClient {
|
|
|
110
130
|
*/
|
|
111
131
|
async getSwap({ inputMint, outputMint, amount, userPublicKey, maxAccounts = 50, // 50 is an estimated amount with buffer
|
|
112
132
|
slippageBps, swapMode, onlyDirectRoutes, excludeDexes, sizeConstraint, accountsLimitWritable, }) {
|
|
113
|
-
const params =
|
|
114
|
-
inputMint
|
|
115
|
-
outputMint
|
|
116
|
-
amount
|
|
117
|
-
userPublicKey
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
...(sizeConstraint && { sizeConstraint: sizeConstraint.toString() }),
|
|
126
|
-
...(accountsLimitWritable && {
|
|
127
|
-
accountsLimitWritable: accountsLimitWritable.toString(),
|
|
128
|
-
}),
|
|
133
|
+
const params = this.buildParams({
|
|
134
|
+
inputMint,
|
|
135
|
+
outputMint,
|
|
136
|
+
amount,
|
|
137
|
+
userPublicKey,
|
|
138
|
+
maxAccounts,
|
|
139
|
+
slippageBps,
|
|
140
|
+
swapMode,
|
|
141
|
+
onlyDirectRoutes,
|
|
142
|
+
excludeDexes,
|
|
143
|
+
sizeConstraint,
|
|
144
|
+
accountsLimitWritable,
|
|
129
145
|
});
|
|
130
|
-
|
|
131
|
-
if (this.
|
|
132
|
-
|
|
133
|
-
response = await fetch(this.proxyUrl, {
|
|
134
|
-
method: 'POST',
|
|
135
|
-
headers: {
|
|
136
|
-
'Content-Type': 'application/json',
|
|
137
|
-
},
|
|
138
|
-
body: JSON.stringify(Object.fromEntries(params.entries())),
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// Direct request to Titan API
|
|
143
|
-
response = await fetch(`${this.url}/api/v1/quote/swap?${params.toString()}`, {
|
|
144
|
-
headers: {
|
|
145
|
-
Accept: 'application/vnd.msgpack',
|
|
146
|
-
'Accept-Encoding': 'gzip, deflate, br',
|
|
147
|
-
Authorization: `Bearer ${this.authToken}`,
|
|
148
|
-
},
|
|
149
|
-
});
|
|
146
|
+
// Check if we have cached quote data that matches the current parameters
|
|
147
|
+
if (!this.lastQuoteData || this.lastQuoteParams !== params.toString()) {
|
|
148
|
+
throw new Error('No matching quote data found. Please get a fresh quote before attempting to swap.');
|
|
150
149
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
throw new Error(`Titan API error: ${response.status} ${response.statusText}`);
|
|
156
|
-
}
|
|
157
|
-
const buffer = await response.arrayBuffer();
|
|
158
|
-
const data = (0, msgpack_1.decode)(buffer);
|
|
159
|
-
const route = data.quotes[Object.keys(data.quotes).find((key) => key.toLowerCase() === 'titan') ||
|
|
160
|
-
''];
|
|
150
|
+
// Reuse the cached quote data
|
|
151
|
+
const data = this.lastQuoteData;
|
|
152
|
+
// We are only querying for the best avaiable route so use that
|
|
153
|
+
const route = data.quotes[Object.keys(data.quotes)[0]];
|
|
161
154
|
if (!route) {
|
|
162
155
|
throw new Error('No routes available');
|
|
163
156
|
}
|
|
@@ -169,6 +162,11 @@ class TitanClient {
|
|
|
169
162
|
catch (err) {
|
|
170
163
|
throw new Error('Something went wrong with creating the Titan swap transaction. Please try again.');
|
|
171
164
|
}
|
|
165
|
+
finally {
|
|
166
|
+
// Clear cached quote data after use
|
|
167
|
+
this.lastQuoteData = undefined;
|
|
168
|
+
this.lastQuoteParams = undefined;
|
|
169
|
+
}
|
|
172
170
|
}
|
|
173
171
|
throw new Error('No instructions provided in the route');
|
|
174
172
|
}
|
package/lib/browser/user.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perpMarkets.d.ts","sourceRoot":"","sources":["../../../src/constants/perpMarkets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,EA6W/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"perpMarkets.d.ts","sourceRoot":"","sources":["../../../src/constants/perpMarkets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,SAAS,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,gBAAgB,EA6W/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,gBAAgB,EA6iChD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE;KAAG,GAAG,IAAI,QAAQ,GAAG,gBAAgB,EAAE;CAGhE,CAAC"}
|
|
@@ -1338,6 +1338,18 @@ exports.MainnetPerpMarkets = [
|
|
|
1338
1338
|
oracleSource: types_1.OracleSource.PYTH_LAZER_1K,
|
|
1339
1339
|
pythLazerId: 2396,
|
|
1340
1340
|
},
|
|
1341
|
+
{
|
|
1342
|
+
fullName: 'Lighter',
|
|
1343
|
+
category: ['DEX'],
|
|
1344
|
+
symbol: 'LIT-PERP',
|
|
1345
|
+
baseAssetSymbol: 'LIT',
|
|
1346
|
+
marketIndex: 84,
|
|
1347
|
+
oracle: new web3_js_1.PublicKey('HsfwxaJdpY5Dvd3ttrrY7YL635T7D9W443XdTwE2Dvbh'),
|
|
1348
|
+
launchTs: 1767621600000,
|
|
1349
|
+
oracleSource: types_1.OracleSource.PYTH_LAZER,
|
|
1350
|
+
pythFeedId: '0xc0c83f00c39165892d55dcd17ade2191e289697e2ac132d9ab721e20834e2a9e',
|
|
1351
|
+
pythLazerId: 2921,
|
|
1352
|
+
},
|
|
1341
1353
|
];
|
|
1342
1354
|
exports.PerpMarkets = {
|
|
1343
1355
|
devnet: exports.DevnetPerpMarkets,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"txConstants.d.ts","sourceRoot":"","sources":["../../../src/constants/txConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAC9C,eAAO,MAAM,sBAAsB,WAElC,CAAC"}
|
|
1
|
+
{"version":3,"file":"txConstants.d.ts","sourceRoot":"","sources":["../../../src/constants/txConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAC9C,eAAO,MAAM,sBAAsB,WAElC,CAAC;AAEF,eAAO,MAAM,wBAAwB,cAAc,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FUEL_RESET_LOG_ACCOUNT = exports.NOT_CONFIRMED_ERROR_CODE = void 0;
|
|
3
|
+
exports.DEFAULT_COMMITMENT_LEVEL = exports.FUEL_RESET_LOG_ACCOUNT = exports.NOT_CONFIRMED_ERROR_CODE = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.NOT_CONFIRMED_ERROR_CODE = -1001;
|
|
6
6
|
exports.FUEL_RESET_LOG_ACCOUNT = new web3_js_1.PublicKey('FuE1gqp2fzw2sDNLrbZqKsqpphJcoSW6HPaSJjGd4RZ4');
|
|
7
|
+
exports.DEFAULT_COMMITMENT_LEVEL = 'confirmed';
|
|
@@ -306,6 +306,7 @@ export declare class DriftClient {
|
|
|
306
306
|
getUserAccountAndSlot(subAccountId?: number, authority?: PublicKey): DataAndSlot<UserAccount> | undefined;
|
|
307
307
|
getSpotPosition(marketIndex: number, subAccountId?: number): SpotPosition | undefined;
|
|
308
308
|
getQuoteAssetTokenAmount(): BN;
|
|
309
|
+
getIsolatedPerpPositionTokenAmount(perpMarketIndex: number, subAccountId?: number): BN;
|
|
309
310
|
/**
|
|
310
311
|
* Returns the token amount for a given market. The spot market precision is based on the token mint decimals.
|
|
311
312
|
* Positive if it is a deposit, negative if it is a borrow.
|
|
@@ -450,6 +451,12 @@ export declare class DriftClient {
|
|
|
450
451
|
getTransferPoolsIx(depositFromMarketIndex: number, depositToMarketIndex: number, borrowFromMarketIndex: number, borrowToMarketIndex: number, depositAmount: BN | undefined, borrowAmount: BN | undefined, fromSubAccountId: number, toSubAccountId: number, isToNewSubAccount?: boolean): Promise<TransactionInstruction>;
|
|
451
452
|
transferPerpPosition(fromSubAccountId: number, toSubAccountId: number, marketIndex: number, amount: BN, txParams?: TxParams): Promise<TransactionSignature>;
|
|
452
453
|
getTransferPerpPositionIx(fromSubAccountId: number, toSubAccountId: number, marketIndex: number, amount: BN): Promise<TransactionInstruction>;
|
|
454
|
+
depositIntoIsolatedPerpPosition(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
455
|
+
getDepositIntoIsolatedPerpPositionIx(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number): Promise<TransactionInstruction>;
|
|
456
|
+
transferIsolatedPerpPositionDeposit(amount: BN, perpMarketIndex: number, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
457
|
+
getTransferIsolatedPerpPositionDepositIx(amount: BN, perpMarketIndex: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
458
|
+
withdrawFromIsolatedPerpPosition(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
459
|
+
getWithdrawFromIsolatedPerpPositionIx(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number): Promise<TransactionInstruction>;
|
|
453
460
|
updateSpotMarketCumulativeInterest(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
454
461
|
updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
455
462
|
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
@@ -991,9 +998,9 @@ export declare class DriftClient {
|
|
|
991
998
|
settleFundingPayment(userAccountPublicKey: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
992
999
|
getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
993
1000
|
triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
|
|
994
|
-
getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
|
|
995
|
-
getMMOracleDataForPerpMarket(marketIndex: number): MMOraclePriceData;
|
|
996
|
-
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
1001
|
+
getOracleDataForPerpMarket(marketIndex: number): OraclePriceData | undefined;
|
|
1002
|
+
getMMOracleDataForPerpMarket(marketIndex: number): MMOraclePriceData | undefined;
|
|
1003
|
+
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData | undefined;
|
|
997
1004
|
initializeInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
998
1005
|
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
999
1006
|
getAddInsuranceFundStakeIx(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
@@ -1062,7 +1069,7 @@ export declare class DriftClient {
|
|
|
1062
1069
|
* @returns
|
|
1063
1070
|
*/
|
|
1064
1071
|
depositIntoSpotMarketRevenuePool(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
1065
|
-
getPerpMarketExtendedInfo(marketIndex: number): PerpMarketExtendedInfo;
|
|
1072
|
+
getPerpMarketExtendedInfo(marketIndex: number): PerpMarketExtendedInfo | undefined;
|
|
1066
1073
|
/**
|
|
1067
1074
|
* Calculates taker / maker fee (as a percentage, e.g. .001 = 10 basis points) for particular marketType
|
|
1068
1075
|
* @param marketType
|
|
@@ -1084,7 +1091,7 @@ export declare class DriftClient {
|
|
|
1084
1091
|
marketType: MarketType;
|
|
1085
1092
|
} | undefined;
|
|
1086
1093
|
getReceiverProgram(): Program<PythSolanaReceiver>;
|
|
1087
|
-
getSwitchboardOnDemandProgram(): Promise<Program30<Idl30
|
|
1094
|
+
getSwitchboardOnDemandProgram(): Promise<Program30<Idl30> | undefined>;
|
|
1088
1095
|
postPythPullOracleUpdateAtomic(vaaString: string, feedId: string): Promise<TransactionSignature>;
|
|
1089
1096
|
postMultiPythPullOracleUpdatesAtomic(vaaString: string, feedIds: string[]): Promise<TransactionSignature>;
|
|
1090
1097
|
getPostPythPullOracleUpdateAtomicIxs(vaaString: string, feedIds: string | string[], numSignatures?: number): Promise<TransactionInstruction[]>;
|
|
@@ -1100,7 +1107,7 @@ export declare class DriftClient {
|
|
|
1100
1107
|
getPostPythLazerOracleUpdateIxs(feedIds: number[], pythMessageHex: string, precedingIxs?: TransactionInstruction[], overrideCustomIxIndex?: number): Promise<TransactionInstruction[]>;
|
|
1101
1108
|
getPostManySwitchboardOnDemandUpdatesAtomicIxs(feeds: PublicKey[], recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionInstruction[] | undefined>;
|
|
1102
1109
|
getPostSwitchboardOnDemandUpdateAtomicIx(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionInstruction | undefined>;
|
|
1103
|
-
postSwitchboardOnDemandUpdate(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionSignature>;
|
|
1110
|
+
postSwitchboardOnDemandUpdate(feed: PublicKey, recentSlothash?: Slothash, numSignatures?: number): Promise<TransactionSignature | undefined>;
|
|
1104
1111
|
private getBuildEncodedVaaIxs;
|
|
1105
1112
|
enableUserHighLeverageMode(subAccountId: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
1106
1113
|
getEnableHighLeverageModeIx(subAccountId: number, depositToTradeArgs?: {
|