@velocity-exchange/sdk 0.9.0 → 0.11.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/lib/browser/adminClient.d.ts +4 -3
- package/lib/browser/adminClient.js +5 -13
- package/lib/browser/equityFloorManager.d.ts +9 -5
- package/lib/browser/equityFloorManager.js +9 -5
- package/lib/browser/idl/velocity.d.ts +119 -3
- package/lib/browser/idl/velocity.json +119 -3
- package/lib/browser/index.d.ts +2 -0
- package/lib/browser/index.js +3 -0
- package/lib/browser/jupiter/jupiterClient.d.ts +31 -27
- package/lib/browser/jupiter/jupiterClient.js +61 -35
- package/lib/browser/math/amm.d.ts +6 -5
- package/lib/browser/math/amm.js +39 -19
- package/lib/browser/math/margin.d.ts +12 -10
- package/lib/browser/math/margin.js +16 -14
- package/lib/browser/math/superStake.d.ts +9 -9
- package/lib/browser/math/superStake.js +8 -8
- package/lib/browser/swap/UnifiedSwapClient.d.ts +38 -76
- package/lib/browser/swap/UnifiedSwapClient.js +46 -117
- package/lib/browser/swap/routeInstructions.d.ts +19 -0
- package/lib/browser/swap/routeInstructions.js +43 -0
- package/lib/browser/swap/types.d.ts +196 -0
- package/lib/browser/swap/types.js +88 -0
- package/lib/browser/titan/titanClient.d.ts +32 -68
- package/lib/browser/titan/titanClient.js +128 -102
- package/lib/browser/types.d.ts +2 -0
- package/lib/browser/user.d.ts +16 -18
- package/lib/browser/user.js +24 -26
- package/lib/browser/velocityClient.d.ts +122 -101
- package/lib/browser/velocityClient.js +221 -289
- package/lib/node/adminClient.d.ts +4 -3
- package/lib/node/adminClient.d.ts.map +1 -1
- package/lib/node/adminClient.js +5 -13
- package/lib/node/equityFloorManager.d.ts +9 -5
- package/lib/node/equityFloorManager.d.ts.map +1 -1
- package/lib/node/equityFloorManager.js +9 -5
- package/lib/node/idl/velocity.d.ts +119 -3
- package/lib/node/idl/velocity.d.ts.map +1 -1
- package/lib/node/idl/velocity.json +119 -3
- package/lib/node/index.d.ts +2 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +3 -0
- package/lib/node/jupiter/jupiterClient.d.ts +31 -27
- package/lib/node/jupiter/jupiterClient.d.ts.map +1 -1
- package/lib/node/jupiter/jupiterClient.js +61 -35
- package/lib/node/math/amm.d.ts +6 -5
- package/lib/node/math/amm.d.ts.map +1 -1
- package/lib/node/math/amm.js +39 -19
- package/lib/node/math/margin.d.ts +12 -10
- package/lib/node/math/margin.d.ts.map +1 -1
- package/lib/node/math/margin.js +16 -14
- package/lib/node/math/superStake.d.ts +9 -9
- package/lib/node/math/superStake.d.ts.map +1 -1
- package/lib/node/math/superStake.js +8 -8
- package/lib/node/swap/UnifiedSwapClient.d.ts +38 -76
- package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
- package/lib/node/swap/UnifiedSwapClient.js +46 -117
- package/lib/node/swap/routeInstructions.d.ts +20 -0
- package/lib/node/swap/routeInstructions.d.ts.map +1 -0
- package/lib/node/swap/routeInstructions.js +43 -0
- package/lib/node/swap/types.d.ts +197 -0
- package/lib/node/swap/types.d.ts.map +1 -0
- package/lib/node/swap/types.js +88 -0
- package/lib/node/titan/titanClient.d.ts +32 -68
- package/lib/node/titan/titanClient.d.ts.map +1 -1
- package/lib/node/titan/titanClient.js +128 -102
- package/lib/node/types.d.ts +2 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +16 -18
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +24 -26
- package/lib/node/velocityClient.d.ts +122 -101
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +221 -289
- package/package.json +1 -1
|
@@ -104,13 +104,14 @@ export declare function calculateCollateralDepositRequiredForTrade(velocityClien
|
|
|
104
104
|
* Minimal equity floor to carry along with a quote transfer of `amount` out
|
|
105
105
|
* of a subaccount so the debited side ends at/above its buffered floor
|
|
106
106
|
* (`equityFloor + equityFloorBuffer`): the first
|
|
107
|
-
* `
|
|
107
|
+
* `netEquity - (floor + buffer)` of the transfer carries no floor, the
|
|
108
108
|
* remainder carries floor one-for-one, capped at the floor the subaccount
|
|
109
|
-
* actually holds.
|
|
110
|
-
*
|
|
111
|
-
*
|
|
109
|
+
* actually holds. `netEquity` is `User.getNetUsdValue()`, the metric the
|
|
110
|
+
* onchain floor checks use. Returns zero when no floor is set. The result
|
|
111
|
+
* never exceeds `amount`, so a credited side that met its own buffered floor
|
|
112
|
+
* before the transfer still meets it after. All values QUOTE_PRECISION.
|
|
112
113
|
*/
|
|
113
|
-
export declare function calculateEquityFloorAutoDelta(amount: BN,
|
|
114
|
+
export declare function calculateEquityFloorAutoDelta(amount: BN, netEquity: BN, equityFloor: BN, equityFloorBuffer: BN): BN;
|
|
114
115
|
/**
|
|
115
116
|
* Severity of a subaccount's equity relative to its floor, most to least
|
|
116
117
|
* severe. `breached`: below the floor, the permissionless breaker can trip.
|
|
@@ -120,10 +121,11 @@ export declare function calculateEquityFloorAutoDelta(amount: BN, totalCollatera
|
|
|
120
121
|
*/
|
|
121
122
|
export type EquityFloorLevel = 'breached' | 'critical' | 'warning' | 'healthy' | 'disabled';
|
|
122
123
|
/**
|
|
123
|
-
* Classifies `
|
|
124
|
-
* `EquityFloorManager` and the equity-floor guard bot
|
|
125
|
-
* levels. `warningBufferMultiple` scales the warning
|
|
126
|
-
* floor (default 2: warn inside `floor + 2 * buffer`).
|
|
124
|
+
* Classifies `netEquity` (`User.getNetUsdValue()`) against the floor
|
|
125
|
+
* thresholds. Used by the `EquityFloorManager` and the equity-floor guard bot
|
|
126
|
+
* so both report the same levels. `warningBufferMultiple` scales the warning
|
|
127
|
+
* threshold above the floor (default 2: warn inside `floor + 2 * buffer`).
|
|
128
|
+
* All QUOTE_PRECISION.
|
|
127
129
|
*/
|
|
128
|
-
export declare function getEquityFloorLevel(
|
|
130
|
+
export declare function getEquityFloorLevel(netEquity: BN, equityFloor: BN, equityFloorBuffer: BN, warningBufferMultiple?: number): EquityFloorLevel;
|
|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E,CASJ;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GACzB,UAAU,GACV,UAAU,GACV,SAAS,GACT,SAAS,GACT,UAAU,CAAC;AAEd;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,EAAE,EACb,WAAW,EAAE,EAAE,EACf,iBAAiB,EAAE,EAAE,EACrB,qBAAqB,SAAI,GACvB,gBAAgB,CAgBlB"}
|
package/lib/node/math/margin.js
CHANGED
|
@@ -214,37 +214,39 @@ exports.calculateCollateralDepositRequiredForTrade = calculateCollateralDepositR
|
|
|
214
214
|
* Minimal equity floor to carry along with a quote transfer of `amount` out
|
|
215
215
|
* of a subaccount so the debited side ends at/above its buffered floor
|
|
216
216
|
* (`equityFloor + equityFloorBuffer`): the first
|
|
217
|
-
* `
|
|
217
|
+
* `netEquity - (floor + buffer)` of the transfer carries no floor, the
|
|
218
218
|
* remainder carries floor one-for-one, capped at the floor the subaccount
|
|
219
|
-
* actually holds.
|
|
220
|
-
*
|
|
221
|
-
*
|
|
219
|
+
* actually holds. `netEquity` is `User.getNetUsdValue()`, the metric the
|
|
220
|
+
* onchain floor checks use. Returns zero when no floor is set. The result
|
|
221
|
+
* never exceeds `amount`, so a credited side that met its own buffered floor
|
|
222
|
+
* before the transfer still meets it after. All values QUOTE_PRECISION.
|
|
222
223
|
*/
|
|
223
|
-
function calculateEquityFloorAutoDelta(amount,
|
|
224
|
+
function calculateEquityFloorAutoDelta(amount, netEquity, equityFloor, equityFloorBuffer) {
|
|
224
225
|
if (equityFloor.lte(numericConstants_1.ZERO)) {
|
|
225
226
|
return numericConstants_1.ZERO;
|
|
226
227
|
}
|
|
227
|
-
const excess = anchor_1.BN.max(
|
|
228
|
+
const excess = anchor_1.BN.max(netEquity.sub(equityFloor.add(equityFloorBuffer)), numericConstants_1.ZERO);
|
|
228
229
|
return anchor_1.BN.min(anchor_1.BN.max(amount.sub(excess), numericConstants_1.ZERO), equityFloor);
|
|
229
230
|
}
|
|
230
231
|
exports.calculateEquityFloorAutoDelta = calculateEquityFloorAutoDelta;
|
|
231
232
|
/**
|
|
232
|
-
* Classifies `
|
|
233
|
-
* `EquityFloorManager` and the equity-floor guard bot
|
|
234
|
-
* levels. `warningBufferMultiple` scales the warning
|
|
235
|
-
* floor (default 2: warn inside `floor + 2 * buffer`).
|
|
233
|
+
* Classifies `netEquity` (`User.getNetUsdValue()`) against the floor
|
|
234
|
+
* thresholds. Used by the `EquityFloorManager` and the equity-floor guard bot
|
|
235
|
+
* so both report the same levels. `warningBufferMultiple` scales the warning
|
|
236
|
+
* threshold above the floor (default 2: warn inside `floor + 2 * buffer`).
|
|
237
|
+
* All QUOTE_PRECISION.
|
|
236
238
|
*/
|
|
237
|
-
function getEquityFloorLevel(
|
|
239
|
+
function getEquityFloorLevel(netEquity, equityFloor, equityFloorBuffer, warningBufferMultiple = 2) {
|
|
238
240
|
if (equityFloor.lte(numericConstants_1.ZERO)) {
|
|
239
241
|
return 'disabled';
|
|
240
242
|
}
|
|
241
|
-
if (
|
|
243
|
+
if (netEquity.lt(equityFloor)) {
|
|
242
244
|
return 'breached';
|
|
243
245
|
}
|
|
244
|
-
if (
|
|
246
|
+
if (netEquity.lt(equityFloor.add(equityFloorBuffer))) {
|
|
245
247
|
return 'critical';
|
|
246
248
|
}
|
|
247
|
-
if (
|
|
249
|
+
if (netEquity.lt(equityFloor.add(equityFloorBuffer.muln(warningBufferMultiple)))) {
|
|
248
250
|
return 'warning';
|
|
249
251
|
}
|
|
250
252
|
return 'healthy';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AddressLookupTableAccount, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
import { JupiterClient,
|
|
2
|
+
import { JupiterClient, JupiterSwapQuote } from '../jupiter/jupiterClient';
|
|
3
3
|
import { VelocityClient } from '../velocityClient';
|
|
4
4
|
import { BN } from '../isomorphic/anchor';
|
|
5
5
|
import { User } from '../user';
|
|
@@ -61,7 +61,7 @@ export declare function fetchBSolVelocityEmissions(): Promise<fetch.Response>;
|
|
|
61
61
|
* @param {boolean} [params.forceMarinade] - Force the direct Marinade stake path over a Jupiter
|
|
62
62
|
* swap even if Jupiter would be cheaper (market index 2 only)
|
|
63
63
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
64
|
-
* @param {
|
|
64
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse instead of
|
|
65
65
|
* fetching a fresh one
|
|
66
66
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
67
67
|
* method: 'jupiter' | 'marinade'; price?: number }>} The instructions to submit, any address
|
|
@@ -78,7 +78,7 @@ export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClie
|
|
|
78
78
|
userAccountPublicKey?: PublicKey;
|
|
79
79
|
forceMarinade?: boolean;
|
|
80
80
|
onlyDirectRoutes?: boolean;
|
|
81
|
-
jupiterQuote?:
|
|
81
|
+
jupiterQuote?: JupiterSwapQuote;
|
|
82
82
|
}): Promise<{
|
|
83
83
|
ixs: TransactionInstruction[];
|
|
84
84
|
lookupTables: AddressLookupTableAccount[];
|
|
@@ -100,7 +100,7 @@ export declare function findBestSuperStakeIxs({ marketIndex, amount, jupiterClie
|
|
|
100
100
|
* @param {PublicKey} [params.userAccountPublicKey] - The target sub-account
|
|
101
101
|
* @param {boolean} [params.forceMarinade] - Force the Marinade path regardless of Jupiter pricing
|
|
102
102
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
103
|
-
* @param {
|
|
103
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse
|
|
104
104
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
105
105
|
* method: 'jupiter' | 'marinade'; price: number }>} The chosen route's instructions, required
|
|
106
106
|
* lookup tables, the method used, and the mSOL/SOL price used for the decision
|
|
@@ -113,7 +113,7 @@ export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, veloc
|
|
|
113
113
|
userAccountPublicKey?: PublicKey;
|
|
114
114
|
forceMarinade?: boolean;
|
|
115
115
|
onlyDirectRoutes?: boolean;
|
|
116
|
-
jupiterQuote?:
|
|
116
|
+
jupiterQuote?: JupiterSwapQuote;
|
|
117
117
|
}): Promise<{
|
|
118
118
|
ixs: TransactionInstruction[];
|
|
119
119
|
lookupTables: AddressLookupTableAccount[];
|
|
@@ -130,7 +130,7 @@ export declare function findBestMSolSuperStakeIxs({ amount, jupiterClient, veloc
|
|
|
130
130
|
* @param {VelocityClient} params.velocityClient - Velocity client
|
|
131
131
|
* @param {PublicKey} [params.userAccountPublicKey] - The target sub-account
|
|
132
132
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
133
|
-
* @param {
|
|
133
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse
|
|
134
134
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
135
135
|
* method: 'jupiter' | 'marinade'; price?: number }>} Always resolves with `method: 'jupiter'`
|
|
136
136
|
*/
|
|
@@ -140,7 +140,7 @@ export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, ve
|
|
|
140
140
|
velocityClient: VelocityClient;
|
|
141
141
|
userAccountPublicKey?: PublicKey;
|
|
142
142
|
onlyDirectRoutes?: boolean;
|
|
143
|
-
jupiterQuote?:
|
|
143
|
+
jupiterQuote?: JupiterSwapQuote;
|
|
144
144
|
}): Promise<{
|
|
145
145
|
ixs: TransactionInstruction[];
|
|
146
146
|
lookupTables: AddressLookupTableAccount[];
|
|
@@ -161,7 +161,7 @@ export declare function findBestJitoSolSuperStakeIxs({ amount, jupiterClient, ve
|
|
|
161
161
|
* @param {VelocityClient} params.velocityClient - Velocity client
|
|
162
162
|
* @param {PublicKey} [params.userAccountPublicKey] - The target sub-account
|
|
163
163
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
164
|
-
* @param {
|
|
164
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse
|
|
165
165
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
166
166
|
* method: 'jupiter' | 'marinade' }>} Always resolves with `method: 'jupiter'`
|
|
167
167
|
*/
|
|
@@ -173,7 +173,7 @@ export declare function findBestLstSuperStakeIxs({ amount, jupiterClient, veloci
|
|
|
173
173
|
velocityClient: VelocityClient;
|
|
174
174
|
userAccountPublicKey?: PublicKey;
|
|
175
175
|
onlyDirectRoutes?: boolean;
|
|
176
|
-
jupiterQuote?:
|
|
176
|
+
jupiterQuote?: JupiterSwapQuote;
|
|
177
177
|
}): Promise<{
|
|
178
178
|
ixs: TransactionInstruction[];
|
|
179
179
|
lookupTables: AddressLookupTableAccount[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superStake.d.ts","sourceRoot":"","sources":["../../../src/math/superStake.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,yBAAyB,EAEzB,SAAS,EACT,sBAAsB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"superStake.d.ts","sourceRoot":"","sources":["../../../src/math/superStake.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,yBAAyB,EAEzB,SAAS,EACT,sBAAsB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,aAA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EAAE,IAAI,CAAC;IACX,cAAc,EAAE,aAAa,EAAE,CAAC;CAChC,GAAG,OAAO,CAAC,EAAE,CAAC,CA6Fd;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,4CAA4C,CAC3D,gBAAgB,EAAE,MAAM,EACxB,yBAAyB,EAAE,MAAM,EACjC,eAAe,EAAE,MAAM,EACvB,6BAA6B,EAAE,MAAM,EACrC,aAAa,EAAE,MAAM,GACnB,MAAM,CAMR"}
|
|
@@ -49,7 +49,7 @@ exports.fetchBSolVelocityEmissions = fetchBSolVelocityEmissions;
|
|
|
49
49
|
* @param {boolean} [params.forceMarinade] - Force the direct Marinade stake path over a Jupiter
|
|
50
50
|
* swap even if Jupiter would be cheaper (market index 2 only)
|
|
51
51
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
52
|
-
* @param {
|
|
52
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse instead of
|
|
53
53
|
* fetching a fresh one
|
|
54
54
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
55
55
|
* method: 'jupiter' | 'marinade'; price?: number }>} The instructions to submit, any address
|
|
@@ -112,7 +112,7 @@ exports.findBestSuperStakeIxs = findBestSuperStakeIxs;
|
|
|
112
112
|
* @param {PublicKey} [params.userAccountPublicKey] - The target sub-account
|
|
113
113
|
* @param {boolean} [params.forceMarinade] - Force the Marinade path regardless of Jupiter pricing
|
|
114
114
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
115
|
-
* @param {
|
|
115
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse
|
|
116
116
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
117
117
|
* method: 'jupiter' | 'marinade'; price: number }>} The chosen route's instructions, required
|
|
118
118
|
* lookup tables, the method used, and the mSOL/SOL price used for the decision
|
|
@@ -155,10 +155,10 @@ async function findBestMSolSuperStakeIxs({ amount, jupiterClient, velocityClient
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
else {
|
|
158
|
-
const { ixs, lookupTables } = await velocityClient.
|
|
158
|
+
const { ixs, lookupTables } = await velocityClient.getProviderSwapIx({
|
|
159
159
|
inMarketIndex: 1,
|
|
160
160
|
outMarketIndex: 2,
|
|
161
|
-
jupiterClient,
|
|
161
|
+
swapProvider: jupiterClient,
|
|
162
162
|
amount,
|
|
163
163
|
userAccountPublicKey,
|
|
164
164
|
onlyDirectRoutes,
|
|
@@ -183,7 +183,7 @@ exports.findBestMSolSuperStakeIxs = findBestMSolSuperStakeIxs;
|
|
|
183
183
|
* @param {VelocityClient} params.velocityClient - Velocity client
|
|
184
184
|
* @param {PublicKey} [params.userAccountPublicKey] - The target sub-account
|
|
185
185
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
186
|
-
* @param {
|
|
186
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse
|
|
187
187
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
188
188
|
* method: 'jupiter' | 'marinade'; price?: number }>} Always resolves with `method: 'jupiter'`
|
|
189
189
|
*/
|
|
@@ -214,15 +214,15 @@ exports.findBestJitoSolSuperStakeIxs = findBestJitoSolSuperStakeIxs;
|
|
|
214
214
|
* @param {VelocityClient} params.velocityClient - Velocity client
|
|
215
215
|
* @param {PublicKey} [params.userAccountPublicKey] - The target sub-account
|
|
216
216
|
* @param {boolean} [params.onlyDirectRoutes] - Restrict Jupiter routing to direct swaps only
|
|
217
|
-
* @param {
|
|
217
|
+
* @param {JupiterSwapQuote} [params.jupiterQuote] - A pre-fetched Jupiter quote to reuse
|
|
218
218
|
* @return {Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[];
|
|
219
219
|
* method: 'jupiter' | 'marinade' }>} Always resolves with `method: 'jupiter'`
|
|
220
220
|
*/
|
|
221
221
|
async function findBestLstSuperStakeIxs({ amount, jupiterClient, velocityClient, userAccountPublicKey, onlyDirectRoutes, lstMarketIndex, jupiterQuote, }) {
|
|
222
|
-
const { ixs, lookupTables } = await velocityClient.
|
|
222
|
+
const { ixs, lookupTables } = await velocityClient.getProviderSwapIx({
|
|
223
223
|
inMarketIndex: 1,
|
|
224
224
|
outMarketIndex: lstMarketIndex,
|
|
225
|
-
jupiterClient,
|
|
225
|
+
swapProvider: jupiterClient,
|
|
226
226
|
amount,
|
|
227
227
|
userAccountPublicKey,
|
|
228
228
|
onlyDirectRoutes,
|
|
@@ -1,66 +1,23 @@
|
|
|
1
|
-
import { Connection,
|
|
2
|
-
import { BN } from '../isomorphic/anchor';
|
|
1
|
+
import { Connection, VersionedTransaction } from '@solana/web3.js';
|
|
3
2
|
import { JupiterClient } from '../jupiter/jupiterClient';
|
|
4
3
|
import { TitanClient } from '../titan/titanClient';
|
|
5
|
-
|
|
6
|
-
export type SwapClientType
|
|
4
|
+
import { GetRouteInstructionsParams, SwapClientType, SwapProvider, SwapQuote, SwapQuoteParams, SwapRouteInstructions } from './types';
|
|
5
|
+
export type { GetRouteInstructionsParams, SwapProviderRoute, SwapClientType, SwapMode, SwapProvider, SwapQuote, SwapQuoteParams, SwapRouteInstructions, UnifiedQuoteResponse, } from './types';
|
|
6
|
+
/** Byte budget handed to a swap provider for the route portion of the tx. */
|
|
7
|
+
export declare const DEFAULT_ROUTE_SIZE_CONSTRAINT: number;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* Routes swap calls to the configured provider.
|
|
10
|
+
*
|
|
11
|
+
* Intentionally thin: it picks a provider and forwards. Anything that varies
|
|
12
|
+
* between Jupiter and Titan belongs in the provider, behind
|
|
13
|
+
* {@link SwapProvider} — branching on the provider here is how the two paths
|
|
14
|
+
* drifted apart previously, since nothing forced them to keep the same
|
|
15
|
+
* semantics.
|
|
10
16
|
*/
|
|
11
|
-
export
|
|
12
|
-
inputMint: string;
|
|
13
|
-
inAmount: string;
|
|
14
|
-
outputMint: string;
|
|
15
|
-
outAmount: string;
|
|
16
|
-
swapMode: SwapMode;
|
|
17
|
-
slippageBps: number;
|
|
18
|
-
routePlan: Array<{
|
|
19
|
-
swapInfo: any;
|
|
20
|
-
percent: number;
|
|
21
|
-
}>;
|
|
22
|
-
otherAmountThreshold?: string;
|
|
23
|
-
priceImpactPct?: string;
|
|
24
|
-
platformFee?: {
|
|
25
|
-
amount?: string;
|
|
26
|
-
feeBps?: number;
|
|
27
|
-
};
|
|
28
|
-
contextSlot?: number;
|
|
29
|
-
timeTaken?: number;
|
|
30
|
-
error?: string;
|
|
31
|
-
errorCode?: string;
|
|
32
|
-
}
|
|
33
|
-
export interface SwapQuoteParams {
|
|
34
|
-
inputMint: PublicKey;
|
|
35
|
-
outputMint: PublicKey;
|
|
36
|
-
amount: BN;
|
|
37
|
-
userPublicKey?: PublicKey;
|
|
38
|
-
maxAccounts?: number;
|
|
39
|
-
slippageBps?: number;
|
|
40
|
-
swapMode?: SwapMode;
|
|
41
|
-
onlyDirectRoutes?: boolean;
|
|
42
|
-
excludeDexes?: string[];
|
|
43
|
-
sizeConstraint?: number;
|
|
44
|
-
accountsLimitWritable?: number;
|
|
45
|
-
autoSlippage?: boolean;
|
|
46
|
-
maxAutoSlippageBps?: number;
|
|
47
|
-
usdEstimate?: number;
|
|
48
|
-
}
|
|
49
|
-
export interface SwapTransactionParams {
|
|
50
|
-
quote: UnifiedQuoteResponse;
|
|
51
|
-
userPublicKey: PublicKey;
|
|
52
|
-
slippageBps?: number;
|
|
53
|
-
}
|
|
54
|
-
export interface SwapTransactionResult {
|
|
55
|
-
transaction?: VersionedTransaction;
|
|
56
|
-
transactionMessage?: TransactionMessage;
|
|
57
|
-
lookupTables?: AddressLookupTableAccount[];
|
|
58
|
-
}
|
|
59
|
-
export declare class UnifiedSwapClient {
|
|
17
|
+
export declare class UnifiedSwapClient implements SwapProvider {
|
|
60
18
|
private client;
|
|
61
19
|
private clientType;
|
|
62
20
|
/**
|
|
63
|
-
* Create a unified swap client
|
|
64
21
|
* @param clientType - 'jupiter' or 'titan'
|
|
65
22
|
* @param connection - Solana connection
|
|
66
23
|
* @param authToken - For Titan: auth token (required when not using proxy). For Jupiter: API key (required for api.jup.ag, get free key at https://portal.jup.ag)
|
|
@@ -74,32 +31,37 @@ export declare class UnifiedSwapClient {
|
|
|
74
31
|
url?: string;
|
|
75
32
|
proxyUrl?: string;
|
|
76
33
|
});
|
|
34
|
+
get providerName(): SwapClientType;
|
|
35
|
+
/**
|
|
36
|
+
* The configured client, seen only as {@link SwapProvider}.
|
|
37
|
+
*
|
|
38
|
+
* Forwarding through the interface rather than the concrete union is what
|
|
39
|
+
* makes goal of this class enforceable: a provider added to the union that
|
|
40
|
+
* implements only part of the contract fails to compile here, instead of
|
|
41
|
+
* resolving against whichever call signatures the union happens to share.
|
|
42
|
+
*/
|
|
43
|
+
private get provider();
|
|
77
44
|
/**
|
|
78
|
-
* Get a swap quote from the
|
|
45
|
+
* Get a swap quote from the configured provider.
|
|
46
|
+
*
|
|
47
|
+
* Provider-specific fields on {@link SwapQuoteParams} are mapped by the
|
|
48
|
+
* provider, so the ones it doesn't recognise are simply ignored.
|
|
79
49
|
*/
|
|
80
|
-
getQuote(params: SwapQuoteParams): Promise<
|
|
50
|
+
getQuote(params: SwapQuoteParams): Promise<SwapQuote>;
|
|
81
51
|
/**
|
|
82
|
-
*
|
|
52
|
+
* Builds the route instructions for a quote from {@link getQuote}, at the
|
|
53
|
+
* slippage that quote was priced at.
|
|
54
|
+
* @throws If the quote came from a different provider or a different wallet.
|
|
83
55
|
*/
|
|
84
|
-
|
|
56
|
+
getRouteInstructions(params: GetRouteInstructionsParams): Promise<SwapRouteInstructions>;
|
|
85
57
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
58
|
+
* Builds a standalone swap transaction for a quote from {@link getQuote},
|
|
59
|
+
* keeping the provider's own compute budget, token account creation and SOL
|
|
60
|
+
* wrapping. Use {@link getRouteInstructions} for a swap that runs inside
|
|
61
|
+
* velocity's `beginSwap`/`endSwap` bracket.
|
|
62
|
+
* @throws If the quote came from a different provider or a different wallet.
|
|
88
63
|
*/
|
|
89
|
-
|
|
90
|
-
inputMint: PublicKey;
|
|
91
|
-
outputMint: PublicKey;
|
|
92
|
-
amount: BN;
|
|
93
|
-
userPublicKey: PublicKey;
|
|
94
|
-
slippageBps?: number;
|
|
95
|
-
swapMode?: SwapMode;
|
|
96
|
-
onlyDirectRoutes?: boolean;
|
|
97
|
-
quote?: UnifiedQuoteResponse;
|
|
98
|
-
sizeConstraint?: number;
|
|
99
|
-
}): Promise<{
|
|
100
|
-
instructions: TransactionInstruction[];
|
|
101
|
-
lookupTables: AddressLookupTableAccount[];
|
|
102
|
-
}>;
|
|
64
|
+
getSwapTransaction(params: GetRouteInstructionsParams): Promise<VersionedTransaction>;
|
|
103
65
|
/**
|
|
104
66
|
* Get the underlying client instance
|
|
105
67
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnifiedSwapClient.d.ts","sourceRoot":"","sources":["../../../src/swap/UnifiedSwapClient.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"UnifiedSwapClient.d.ts","sourceRoot":"","sources":["../../../src/swap/UnifiedSwapClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EACN,0BAA0B,EAC1B,cAAc,EACd,YAAY,EACZ,SAAS,EACT,eAAe,EACf,qBAAqB,EACrB,MAAM,SAAS,CAAC;AAIjB,YAAY,EACX,0BAA0B,EAC1B,iBAAiB,EACjB,cAAc,EACd,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,SAAS,CAAC;AAQjB,6EAA6E;AAC7E,eAAO,MAAM,6BAA6B,QACM,CAAC;AAEjD;;;;;;;;GAQG;AACH,qBAAa,iBAAkB,YAAW,YAAY;IACrD,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,UAAU,CAAiB;IAEnC;;;;;;OAMG;gBACS,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,GAAG,EACH,QAAQ,GACR,EAAE;QACF,UAAU,EAAE,cAAc,CAAC;QAC3B,UAAU,EAAE,UAAU,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB;IAqBD,IAAW,YAAY,IAAI,cAAc,CAExC;IAED;;;;;;;OAOG;IACH,OAAO,KAAK,QAAQ,GAEnB;IAED;;;;;OAKG;IACU,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC;IAOlE;;;;OAIG;IACU,oBAAoB,CAChC,MAAM,EAAE,0BAA0B,GAChC,OAAO,CAAC,qBAAqB,CAAC;IAIjC;;;;;;OAMG;IACU,kBAAkB,CAC9B,MAAM,EAAE,0BAA0B,GAChC,OAAO,CAAC,oBAAoB,CAAC;IAIhC;;OAEG;IACI,SAAS,IAAI,aAAa,GAAG,WAAW;IAI/C;;OAEG;IACI,aAAa,IAAI,cAAc;IAItC;;OAEG;IACI,SAAS,IAAI,OAAO;IAI3B;;OAEG;IACI,OAAO,IAAI,OAAO;CAGzB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnifiedSwapClient = void 0;
|
|
3
|
+
exports.UnifiedSwapClient = exports.DEFAULT_ROUTE_SIZE_CONSTRAINT = void 0;
|
|
4
4
|
const jupiterClient_1 = require("../jupiter/jupiterClient");
|
|
5
5
|
const titanClient_1 = require("../titan/titanClient");
|
|
6
6
|
const utils_1 = require("../tx/utils");
|
|
@@ -10,10 +10,18 @@ const utils_1 = require("../tx/utils");
|
|
|
10
10
|
*/
|
|
11
11
|
const VELOCITY_SWAP_IX_SIZE_BUFFER = 375;
|
|
12
12
|
/** Byte budget handed to a swap provider for the route portion of the tx. */
|
|
13
|
-
|
|
13
|
+
exports.DEFAULT_ROUTE_SIZE_CONSTRAINT = utils_1.MAX_TX_BYTE_SIZE - VELOCITY_SWAP_IX_SIZE_BUFFER;
|
|
14
|
+
/**
|
|
15
|
+
* Routes swap calls to the configured provider.
|
|
16
|
+
*
|
|
17
|
+
* Intentionally thin: it picks a provider and forwards. Anything that varies
|
|
18
|
+
* between Jupiter and Titan belongs in the provider, behind
|
|
19
|
+
* {@link SwapProvider} — branching on the provider here is how the two paths
|
|
20
|
+
* drifted apart previously, since nothing forced them to keep the same
|
|
21
|
+
* semantics.
|
|
22
|
+
*/
|
|
14
23
|
class UnifiedSwapClient {
|
|
15
24
|
/**
|
|
16
|
-
* Create a unified swap client
|
|
17
25
|
* @param clientType - 'jupiter' or 'titan'
|
|
18
26
|
* @param connection - Solana connection
|
|
19
27
|
* @param authToken - For Titan: auth token (required when not using proxy). For Jupiter: API key (required for api.jup.ag, get free key at https://portal.jup.ag)
|
|
@@ -41,129 +49,50 @@ class UnifiedSwapClient {
|
|
|
41
49
|
throw new Error(`Unsupported client type: ${clientType}`);
|
|
42
50
|
}
|
|
43
51
|
}
|
|
52
|
+
get providerName() {
|
|
53
|
+
return this.clientType;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The configured client, seen only as {@link SwapProvider}.
|
|
57
|
+
*
|
|
58
|
+
* Forwarding through the interface rather than the concrete union is what
|
|
59
|
+
* makes goal of this class enforceable: a provider added to the union that
|
|
60
|
+
* implements only part of the contract fails to compile here, instead of
|
|
61
|
+
* resolving against whichever call signatures the union happens to share.
|
|
62
|
+
*/
|
|
63
|
+
get provider() {
|
|
64
|
+
return this.client;
|
|
65
|
+
}
|
|
44
66
|
/**
|
|
45
|
-
* Get a swap quote from the
|
|
67
|
+
* Get a swap quote from the configured provider.
|
|
68
|
+
*
|
|
69
|
+
* Provider-specific fields on {@link SwapQuoteParams} are mapped by the
|
|
70
|
+
* provider, so the ones it doesn't recognise are simply ignored.
|
|
46
71
|
*/
|
|
47
72
|
async getQuote(params) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
sizeConstraint:
|
|
52
|
-
|
|
53
|
-
return await jupiterClient.getQuote(jupiterParams);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
const titanClient = this.client;
|
|
57
|
-
const { autoSlippage: _autoSlippage, // Titan-specific params to exclude
|
|
58
|
-
maxAutoSlippageBps: _maxAutoSlippageBps, usdEstimate: _usdEstimate, ...titanParams } = params;
|
|
59
|
-
if (!titanParams.userPublicKey) {
|
|
60
|
-
throw new Error('userPublicKey is required for Titan quotes');
|
|
61
|
-
}
|
|
62
|
-
// Cast to ensure TypeScript knows userPublicKey is defined
|
|
63
|
-
const titanParamsWithUser = {
|
|
64
|
-
...titanParams,
|
|
65
|
-
userPublicKey: titanParams.userPublicKey,
|
|
66
|
-
swapMode: titanParams.swapMode, // Titan expects string
|
|
67
|
-
sizeConstraint: titanParams.sizeConstraint || DEFAULT_ROUTE_SIZE_CONSTRAINT,
|
|
68
|
-
};
|
|
69
|
-
return await titanClient.getQuote(titanParamsWithUser);
|
|
70
|
-
}
|
|
73
|
+
var _a;
|
|
74
|
+
return this.provider.getQuote({
|
|
75
|
+
...params,
|
|
76
|
+
sizeConstraint: (_a = params.sizeConstraint) !== null && _a !== void 0 ? _a : exports.DEFAULT_ROUTE_SIZE_CONSTRAINT,
|
|
77
|
+
});
|
|
71
78
|
}
|
|
72
79
|
/**
|
|
73
|
-
*
|
|
80
|
+
* Builds the route instructions for a quote from {@link getQuote}, at the
|
|
81
|
+
* slippage that quote was priced at.
|
|
82
|
+
* @throws If the quote came from a different provider or a different wallet.
|
|
74
83
|
*/
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
const jupiterClient = this.client;
|
|
78
|
-
// Cast the quote to Jupiter's specific QuoteResponse type
|
|
79
|
-
const jupiterParams = {
|
|
80
|
-
...params,
|
|
81
|
-
quote: params.quote,
|
|
82
|
-
};
|
|
83
|
-
const transaction = await jupiterClient.getSwap(jupiterParams);
|
|
84
|
-
return { transaction };
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
const titanClient = this.client;
|
|
88
|
-
const { userPublicKey } = params;
|
|
89
|
-
// For Titan, we need to reconstruct the parameters from the quote
|
|
90
|
-
const result = await titanClient.getSwap({
|
|
91
|
-
userPublicKey,
|
|
92
|
-
});
|
|
93
|
-
return {
|
|
94
|
-
transactionMessage: result.transactionMessage,
|
|
95
|
-
lookupTables: result.lookupTables,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
84
|
+
async getRouteInstructions(params) {
|
|
85
|
+
return this.provider.getRouteInstructions(params);
|
|
98
86
|
}
|
|
99
87
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
88
|
+
* Builds a standalone swap transaction for a quote from {@link getQuote},
|
|
89
|
+
* keeping the provider's own compute budget, token account creation and SOL
|
|
90
|
+
* wrapping. Use {@link getRouteInstructions} for a swap that runs inside
|
|
91
|
+
* velocity's `beginSwap`/`endSwap` bracket.
|
|
92
|
+
* @throws If the quote came from a different provider or a different wallet.
|
|
102
93
|
*/
|
|
103
|
-
async
|
|
104
|
-
|
|
105
|
-
let swapInstructions;
|
|
106
|
-
let lookupTables;
|
|
107
|
-
if (this.clientType === 'jupiter') {
|
|
108
|
-
const jupiterClient = this.client;
|
|
109
|
-
// Get quote if not provided
|
|
110
|
-
let finalQuote = quote;
|
|
111
|
-
if (!finalQuote) {
|
|
112
|
-
finalQuote = await jupiterClient.getQuote({
|
|
113
|
-
inputMint,
|
|
114
|
-
outputMint,
|
|
115
|
-
amount,
|
|
116
|
-
slippageBps,
|
|
117
|
-
swapMode,
|
|
118
|
-
onlyDirectRoutes,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (!finalQuote) {
|
|
122
|
-
throw new Error('Could not fetch swap quote. Please try again.');
|
|
123
|
-
}
|
|
124
|
-
// Get swap transaction and extract instructions
|
|
125
|
-
const transaction = await jupiterClient.getSwap({
|
|
126
|
-
quote: finalQuote,
|
|
127
|
-
userPublicKey,
|
|
128
|
-
slippageBps,
|
|
129
|
-
});
|
|
130
|
-
const { transactionMessage, lookupTables: jupiterLookupTables } = await jupiterClient.getTransactionMessageAndLookupTables({
|
|
131
|
-
transaction,
|
|
132
|
-
});
|
|
133
|
-
swapInstructions = jupiterClient.getJupiterInstructions({
|
|
134
|
-
transactionMessage,
|
|
135
|
-
inputMint,
|
|
136
|
-
outputMint,
|
|
137
|
-
});
|
|
138
|
-
lookupTables = jupiterLookupTables;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const titanClient = this.client;
|
|
142
|
-
// For Titan, get swap directly (it handles quote internally).
|
|
143
|
-
//
|
|
144
|
-
// NOTE: `getSwap` reads only `userPublicKey` — it replays the route
|
|
145
|
-
// cached by the preceding `getQuote`, so every other argument here is
|
|
146
|
-
// inert. The size constraint is therefore enforced at quote time (see
|
|
147
|
-
// `getQuote` above), which means an explicit `sizeConstraint` passed
|
|
148
|
-
// only to this method does not affect route selection.
|
|
149
|
-
const { transactionMessage, lookupTables: titanLookupTables } = await titanClient.getSwap({
|
|
150
|
-
inputMint,
|
|
151
|
-
outputMint,
|
|
152
|
-
amount,
|
|
153
|
-
userPublicKey,
|
|
154
|
-
slippageBps,
|
|
155
|
-
swapMode: isExactOut ? titanClient_1.SwapMode.ExactOut : titanClient_1.SwapMode.ExactIn,
|
|
156
|
-
onlyDirectRoutes,
|
|
157
|
-
sizeConstraint: sizeConstraint || DEFAULT_ROUTE_SIZE_CONSTRAINT,
|
|
158
|
-
});
|
|
159
|
-
swapInstructions = titanClient.getTitanInstructions({
|
|
160
|
-
transactionMessage,
|
|
161
|
-
inputMint,
|
|
162
|
-
outputMint,
|
|
163
|
-
});
|
|
164
|
-
lookupTables = titanLookupTables;
|
|
165
|
-
}
|
|
166
|
-
return { instructions: swapInstructions, lookupTables };
|
|
94
|
+
async getSwapTransaction(params) {
|
|
95
|
+
return this.provider.getSwapTransaction(params);
|
|
167
96
|
}
|
|
168
97
|
/**
|
|
169
98
|
* Get the underlying client instance
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
/**
|
|
3
|
+
* Strips the setup and teardown a provider wraps around its route, leaving the
|
|
4
|
+
* instructions that go between `beginSwap` and `endSwap`.
|
|
5
|
+
*
|
|
6
|
+
* Velocity supplies its own compute budget, funds the input token account from
|
|
7
|
+
* the spot market vault, and sweeps the output back, so the provider's versions
|
|
8
|
+
* of all three are redundant. Its ATA creation for the input or output mint is
|
|
9
|
+
* dropped too, since velocity creates those itself; ATAs for any other mint
|
|
10
|
+
* (intermediate hops, fee accounts) are kept because nothing else creates them.
|
|
11
|
+
*
|
|
12
|
+
* Shared by both providers on purpose — when this lived in each client the two
|
|
13
|
+
* copies drifted, and the difference only showed up as a malformed transaction.
|
|
14
|
+
*/
|
|
15
|
+
export declare function filterRouteInstructions({ instructions, inputMint, outputMint, }: {
|
|
16
|
+
instructions: TransactionInstruction[];
|
|
17
|
+
inputMint: PublicKey;
|
|
18
|
+
outputMint: PublicKey;
|
|
19
|
+
}): TransactionInstruction[];
|
|
20
|
+
//# sourceMappingURL=routeInstructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routeInstructions.d.ts","sourceRoot":"","sources":["../../../src/swap/routeInstructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAWpE;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,EACvC,YAAY,EACZ,SAAS,EACT,UAAU,GACV,EAAE;IACF,YAAY,EAAE,sBAAsB,EAAE,CAAC;IACvC,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;CACtB,GAAG,sBAAsB,EAAE,CAwB3B"}
|