@steerprotocol/sdk 1.19.16 → 1.19.18
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/dist/cjs/base/vault/single-asset/simulateSwap.js +43 -17
- package/dist/cjs/base/vault/single-asset/simulateSwap.js.map +1 -1
- package/dist/cjs/base/vault/single-asset/singleAssetDeposit.js +24 -21
- package/dist/cjs/base/vault/single-asset/singleAssetDeposit.js.map +1 -1
- package/dist/cjs/const/abis/quoter.js +1337 -1
- package/dist/cjs/const/abis/quoter.js.map +1 -1
- package/dist/cjs/const/amm/configs/protocols/machinex.js +3 -0
- package/dist/cjs/const/amm/configs/protocols/machinex.js.map +1 -1
- package/dist/cjs/const/amm/configs/protocols/quickswap.js +3 -0
- package/dist/cjs/const/amm/configs/protocols/quickswap.js.map +1 -1
- package/dist/cjs/const/amm/configs/protocols/retro.js +3 -0
- package/dist/cjs/const/amm/configs/protocols/retro.js.map +1 -1
- package/dist/cjs/const/amm/configs/protocols/sushi.js +3 -0
- package/dist/cjs/const/amm/configs/protocols/sushi.js.map +1 -1
- package/dist/cjs/const/amm/utils/contracts.js +6 -0
- package/dist/cjs/const/amm/utils/contracts.js.map +1 -1
- package/dist/cjs/const/deployments/peaq.js +8 -0
- package/dist/cjs/const/deployments/peaq.js.map +1 -1
- package/dist/cjs/const/deployments/polygon.js +2 -2
- package/dist/cjs/const/index.js.map +1 -1
- package/dist/cjs/const/network.js +9 -0
- package/dist/cjs/const/network.js.map +1 -1
- package/dist/cjs/const/protocol.js +18 -1
- package/dist/cjs/const/protocol.js.map +1 -1
- package/dist/cjs/const/quoter.js +412 -25
- package/dist/cjs/const/quoter.js.map +1 -1
- package/dist/esm/base/vault/single-asset/simulateSwap.js +43 -17
- package/dist/esm/base/vault/single-asset/simulateSwap.js.map +1 -1
- package/dist/esm/base/vault/single-asset/singleAssetDeposit.js +24 -21
- package/dist/esm/base/vault/single-asset/singleAssetDeposit.js.map +1 -1
- package/dist/esm/const/abis/quoter.js +1336 -0
- package/dist/esm/const/abis/quoter.js.map +1 -1
- package/dist/esm/const/amm/configs/protocols/machinex.js +3 -0
- package/dist/esm/const/amm/configs/protocols/machinex.js.map +1 -1
- package/dist/esm/const/amm/configs/protocols/quickswap.js +3 -0
- package/dist/esm/const/amm/configs/protocols/quickswap.js.map +1 -1
- package/dist/esm/const/amm/configs/protocols/retro.js +3 -0
- package/dist/esm/const/amm/configs/protocols/retro.js.map +1 -1
- package/dist/esm/const/amm/configs/protocols/sushi.js +3 -0
- package/dist/esm/const/amm/configs/protocols/sushi.js.map +1 -1
- package/dist/esm/const/amm/utils/contracts.js +5 -0
- package/dist/esm/const/amm/utils/contracts.js.map +1 -1
- package/dist/esm/const/deployments/peaq.js +8 -0
- package/dist/esm/const/deployments/peaq.js.map +1 -1
- package/dist/esm/const/deployments/polygon.js +2 -2
- package/dist/esm/const/index.js.map +1 -1
- package/dist/esm/const/network.js +7 -0
- package/dist/esm/const/network.js.map +1 -1
- package/dist/esm/const/protocol.js +16 -0
- package/dist/esm/const/protocol.js.map +1 -1
- package/dist/esm/const/quoter.js +412 -32
- package/dist/esm/const/quoter.js.map +1 -1
- package/dist/types/base/VaultClient.d.ts +1 -1
- package/dist/types/base/vault/single-asset/simulateSwap.d.ts.map +1 -1
- package/dist/types/base/vault/single-asset/singleAssetDeposit.d.ts +1 -1
- package/dist/types/base/vault/single-asset/singleAssetDeposit.d.ts.map +1 -1
- package/dist/types/base/vault/single-asset/types.d.ts +2 -0
- package/dist/types/base/vault/single-asset/types.d.ts.map +1 -1
- package/dist/types/const/abis/quoter.d.ts +226 -0
- package/dist/types/const/abis/quoter.d.ts.map +1 -1
- package/dist/types/const/amm/configs/protocols/machinex.d.ts.map +1 -1
- package/dist/types/const/amm/configs/protocols/quickswap.d.ts.map +1 -1
- package/dist/types/const/amm/configs/protocols/retro.d.ts.map +1 -1
- package/dist/types/const/amm/configs/protocols/sushi.d.ts.map +1 -1
- package/dist/types/const/amm/utils/contracts.d.ts +2 -0
- package/dist/types/const/amm/utils/contracts.d.ts.map +1 -1
- package/dist/types/const/deployments/peaq.d.ts.map +1 -1
- package/dist/types/const/index.d.ts.map +1 -1
- package/dist/types/const/network.d.ts +2 -0
- package/dist/types/const/network.d.ts.map +1 -1
- package/dist/types/const/protocol.d.ts +2 -0
- package/dist/types/const/protocol.d.ts.map +1 -1
- package/dist/types/const/quoter.d.ts +451 -12
- package/dist/types/const/quoter.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/const/quoter.js
CHANGED
|
@@ -1,38 +1,425 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.QuoterV2Factory = void 0;
|
|
4
|
+
exports.isUniswapQuoteParams = isUniswapQuoteParams;
|
|
5
|
+
exports.isAlgebraQuoteParams = isAlgebraQuoteParams;
|
|
6
|
+
exports.isThickQuoteParams = isThickQuoteParams;
|
|
7
|
+
exports.isAlgebraIntegral21QuoteParams = isAlgebraIntegral21QuoteParams;
|
|
8
|
+
exports.isShadowQuoteParams = isShadowQuoteParams;
|
|
9
|
+
exports.validateQuoteParams = validateQuoteParams;
|
|
10
|
+
exports.getExpectedParamType = getExpectedParamType;
|
|
11
|
+
const viem_1 = require("viem");
|
|
5
12
|
const chain_1 = require("./chain");
|
|
13
|
+
const beacon_1 = require("./amm/utils/beacon");
|
|
14
|
+
const protocol_1 = require("./protocol");
|
|
15
|
+
const quoter_1 = require("./abis/quoter");
|
|
6
16
|
const amm_1 = require("./amm");
|
|
7
17
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
18
|
+
* Factory class for creating QuoterV2 contract instances with the appropriate ABI
|
|
19
|
+
* based on the protocol type detected from beacon names.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { createPublicClient, http, parseEther } from 'viem';
|
|
24
|
+
* import { polygon } from 'viem/chains';
|
|
25
|
+
* import { QuoterV2Factory } from './quoter';
|
|
26
|
+
*
|
|
27
|
+
* // Create a viem client
|
|
28
|
+
* const client = createPublicClient({
|
|
29
|
+
* chain: polygon,
|
|
30
|
+
* transport: http()
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* // Configure network with quoter addresses
|
|
34
|
+
* const networkConfig = {
|
|
35
|
+
* quoterV2: {
|
|
36
|
+
* 'QuickSwap': '0x...',
|
|
37
|
+
* 'Uniswap': '0x...',
|
|
38
|
+
* 'ThickV2': '0x...',
|
|
39
|
+
* 'Shadow': '0x...',
|
|
40
|
+
* 'KatanaIntegral': '0x...'
|
|
41
|
+
* }
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* const factory = new QuoterV2Factory(networkConfig);
|
|
45
|
+
*
|
|
46
|
+
* // Example 1: Uniswap V3 style (fee-based)
|
|
47
|
+
* const { quoter: uniQuoter, params: uniParams } = factory.createQuoterWithParams('uniswap', client, {
|
|
48
|
+
* tokenIn: '0xA0b86a33E6f73c7C6789b65f71C1ab8EbAbD3A01',
|
|
49
|
+
* tokenOut: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
50
|
+
* amountIn: parseEther('1'),
|
|
51
|
+
* fee: 3000,
|
|
52
|
+
* sqrtPriceLimitX96: 0n
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Example 2: QuickSwap (Algebra style)
|
|
56
|
+
* const { quoter: quickQuoter, params: quickParams } = factory.createQuoterWithParams('quickswap', client, {
|
|
57
|
+
* tokenIn: '0xA0b86a33E6f73c7C6789b65f71C1ab8EbAbD3A01',
|
|
58
|
+
* tokenOut: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
59
|
+
* amountIn: parseEther('1'),
|
|
60
|
+
* limitSqrtPrice: 0n
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* // Example 3: Thick V2 (tick spacing)
|
|
64
|
+
* const { quoter: thickQuoter, params: thickParams } = factory.createQuoterWithParams('thickv2', client, {
|
|
65
|
+
* tokenIn: '0xA0b86a33E6f73c7C6789b65f71C1ab8EbAbD3A01',
|
|
66
|
+
* tokenOut: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
67
|
+
* amountIn: parseEther('1'),
|
|
68
|
+
* tickSpacing: 60,
|
|
69
|
+
* sqrtPriceLimitX96: 0n
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* // Example 4: Katana Integral (with deployer)
|
|
73
|
+
* const { quoter: katanaQuoter, params: katanaParams } = factory.createQuoterWithParams('katanaintegral', client, {
|
|
74
|
+
* tokenIn: '0xA0b86a33E6f73c7C6789b65f71C1ab8EbAbD3A01',
|
|
75
|
+
* tokenOut: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
|
|
76
|
+
* amountIn: parseEther('1'),
|
|
77
|
+
* deployer: '0x...',
|
|
78
|
+
* limitSqrtPrice: 0n
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* // Use the quoter contracts
|
|
82
|
+
* const uniResult = await uniQuoter.read.quoteExactInputSingle([uniParams]);
|
|
83
|
+
* const quickResult = await quickQuoter.read.quoteExactInputSingle([quickParams]);
|
|
84
|
+
* const thickResult = await thickQuoter.read.quoteExactInputSingle([thickParams]);
|
|
85
|
+
* const katanaResult = await katanaQuoter.read.quoteExactInputSingle([katanaParams]);
|
|
86
|
+
* ```
|
|
12
87
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
88
|
+
class QuoterV2Factory {
|
|
89
|
+
constructor(networkConfig) {
|
|
90
|
+
this.networkConfig = networkConfig;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Creates quote parameters for the quoteExactInputSingle function based on the protocol type.
|
|
94
|
+
*
|
|
95
|
+
* @param beaconName - The beacon identifier to determine the protocol type
|
|
96
|
+
* @param params - The input parameters for the quote
|
|
97
|
+
* @returns Formatted parameters object for the specific protocol's quoteExactInputSingle function
|
|
98
|
+
* @throws Error if protocol type is not supported
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const factory = new QuoterV2Factory(networkConfig);
|
|
103
|
+
*
|
|
104
|
+
* // For Uniswap V3
|
|
105
|
+
* const uniParams = factory.getQuoteParams('uniswap', {
|
|
106
|
+
* tokenIn: '0x...',
|
|
107
|
+
* tokenOut: '0x...',
|
|
108
|
+
* amountIn: parseEther('1'),
|
|
109
|
+
* fee: 3000,
|
|
110
|
+
* sqrtPriceLimitX96: 0n
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* // For QuickSwap (Algebra)
|
|
114
|
+
* const quickParams = factory.getQuoteParams('quickswap', {
|
|
115
|
+
* tokenIn: '0x...',
|
|
116
|
+
* tokenOut: '0x...',
|
|
117
|
+
* amountIn: parseEther('1'),
|
|
118
|
+
* limitSqrtPrice: 0n
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
getQuoteParams(protocol, params) {
|
|
123
|
+
// Validate parameters first
|
|
124
|
+
validateQuoteParams(protocol, params);
|
|
125
|
+
if (!protocol) {
|
|
126
|
+
throw Error('Protocol not found');
|
|
127
|
+
}
|
|
128
|
+
// Check for Algebra Integral v2.1 vaults (newer version with deployer)
|
|
129
|
+
if (this.isAlgebraIntegral21Vault(protocol)) {
|
|
130
|
+
const p = params;
|
|
131
|
+
return {
|
|
132
|
+
tokenIn: p.tokenIn,
|
|
133
|
+
tokenOut: p.tokenOut,
|
|
134
|
+
deployer: p.deployer,
|
|
135
|
+
amountIn: p.amountIn,
|
|
136
|
+
limitSqrtPrice: p.limitSqrtPrice || 0n
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// Check for Shadow protocol vaults
|
|
140
|
+
if ((0, protocol_1.isShadowProtocol)(protocol)) {
|
|
141
|
+
const p = params;
|
|
142
|
+
return {
|
|
143
|
+
tokenIn: p.tokenIn,
|
|
144
|
+
tokenOut: p.tokenOut,
|
|
145
|
+
amountIn: p.amountIn,
|
|
146
|
+
tickSpacing: p.tickSpacing,
|
|
147
|
+
sqrtPriceLimitX96: p.sqrtPriceLimitX96 || 0n
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
// Check for Algebra Integral vaults (older version)
|
|
151
|
+
if ((0, protocol_1.isAlgebraIntegralProtocol)(protocol)) {
|
|
152
|
+
const p = params;
|
|
153
|
+
return {
|
|
154
|
+
tokenIn: p.tokenIn,
|
|
155
|
+
tokenOut: p.tokenOut,
|
|
156
|
+
amountIn: p.amountIn,
|
|
157
|
+
limitSqrtPrice: p.limitSqrtPrice || 0n
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// Check for Algebra-based protocols (QuickSwap, etc.)
|
|
161
|
+
if (protocol && (0, protocol_1.isAlgebraProtocol)(protocol)) {
|
|
162
|
+
const p = params;
|
|
163
|
+
return {
|
|
164
|
+
tokenIn: p.tokenIn,
|
|
165
|
+
tokenOut: p.tokenOut,
|
|
166
|
+
amountIn: p.amountIn,
|
|
167
|
+
limitSqrtPrice: p.limitSqrtPrice || 0n
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// Check for Thick V2 protocols
|
|
171
|
+
if ((0, protocol_1.isThickV2Protocol)(protocol)) {
|
|
172
|
+
const p = params;
|
|
173
|
+
return {
|
|
174
|
+
tokenIn: p.tokenIn,
|
|
175
|
+
tokenOut: p.tokenOut,
|
|
176
|
+
amountIn: p.amountIn,
|
|
177
|
+
tickSpacing: p.tickSpacing,
|
|
178
|
+
sqrtPriceLimitX96: p.sqrtPriceLimitX96 || 0n
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// Default to Uniswap V3 style (fee-based)
|
|
182
|
+
const p = params;
|
|
183
|
+
return {
|
|
184
|
+
tokenIn: p.tokenIn,
|
|
185
|
+
tokenOut: p.tokenOut,
|
|
186
|
+
amountIn: p.amountIn,
|
|
187
|
+
fee: p.fee,
|
|
188
|
+
sqrtPriceLimitX96: p.sqrtPriceLimitX96 || 0n
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Creates a QuoterV2 contract instance with the appropriate ABI for the given beacon.
|
|
193
|
+
*
|
|
194
|
+
* @param beaconName - The beacon identifier to determine the protocol type
|
|
195
|
+
* @param client - The viem client for contract interactions
|
|
196
|
+
* @returns A viem contract instance with the appropriate ABI
|
|
197
|
+
* @throws Error if quoter address is not found for the protocol
|
|
198
|
+
*/
|
|
199
|
+
createQuoterV2(protocol, client) {
|
|
200
|
+
const quoterV2Address = this.getQuoterV2Address(protocol);
|
|
201
|
+
if (!quoterV2Address) {
|
|
202
|
+
throw new Error(`QuoterV2 address not found for protocol: ${protocol}`);
|
|
203
|
+
}
|
|
204
|
+
const abi = this.getQuoterAbi(protocol);
|
|
205
|
+
return (0, viem_1.getContract)({
|
|
206
|
+
address: quoterV2Address,
|
|
207
|
+
abi,
|
|
208
|
+
client
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Convenience function that creates both the quoter contract and properly formatted quote parameters.
|
|
213
|
+
*
|
|
214
|
+
* @param beaconName - The beacon identifier to determine the protocol type
|
|
215
|
+
* @param client - The viem client for contract interactions
|
|
216
|
+
* @param params - The input parameters for the quote
|
|
217
|
+
* @returns Object containing the quoter contract and formatted parameters
|
|
218
|
+
* @throws Error if quoter address is not found for the protocol
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const factory = new QuoterV2Factory(networkConfig);
|
|
223
|
+
*
|
|
224
|
+
* const { quoter, params } = factory.createQuoterWithParams('quickswap', client, {
|
|
225
|
+
* tokenIn: '0x...',
|
|
226
|
+
* tokenOut: '0x...',
|
|
227
|
+
* amountIn: parseEther('1'),
|
|
228
|
+
* limitSqrtPrice: 0n
|
|
229
|
+
* });
|
|
230
|
+
*
|
|
231
|
+
* // Use directly
|
|
232
|
+
* const result = await quoter.read.quoteExactInputSingle([params]);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
createQuoterWithParams(protocol, client, params) {
|
|
236
|
+
const quoter = this.createQuoterV2(protocol, client);
|
|
237
|
+
const formattedParams = this.getQuoteParams(protocol, params);
|
|
238
|
+
return {
|
|
239
|
+
quoter,
|
|
240
|
+
params: formattedParams
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Gets the appropriate QuoterV2 ABI based on the beacon name and protocol.
|
|
245
|
+
*
|
|
246
|
+
* @param protocol - The detected protocol type
|
|
247
|
+
* @returns The appropriate ABI array
|
|
248
|
+
*/
|
|
249
|
+
getQuoterAbi(protocol) {
|
|
250
|
+
if (!protocol) {
|
|
251
|
+
throw Error('Protocol not avaiable');
|
|
252
|
+
}
|
|
253
|
+
// Check for Algebra Integral v2.1 vaults (newer version)
|
|
254
|
+
if (this.isAlgebraIntegral21Vault(protocol)) {
|
|
255
|
+
return quoter_1.QuoterV2AlgebgraIntegral21;
|
|
256
|
+
}
|
|
257
|
+
// Check for Shadow protocol vaults
|
|
258
|
+
if ((0, protocol_1.isShadowProtocol)(protocol)) {
|
|
259
|
+
return quoter_1.QuoterV2Shadow;
|
|
260
|
+
}
|
|
261
|
+
// Check for Algebra Integral vaults (older version)
|
|
262
|
+
if ((0, protocol_1.isAlgebraIntegralProtocol)(protocol)) {
|
|
263
|
+
return quoter_1.QuoterV2AlgebgraIntegral;
|
|
264
|
+
}
|
|
265
|
+
// Check for Lynex protocol (special case)
|
|
266
|
+
if (protocol === chain_1.Protocol.Lynex) {
|
|
267
|
+
// Note: Lynex currently uses the same ABI as QuickSwap in this implementation
|
|
268
|
+
// If Lynex has a different ABI, add it to the ABIs in quoter.ts as QuoterV2Lynex
|
|
269
|
+
// and import it at the top of this file
|
|
270
|
+
return quoter_1.QuickSwapQuoterV2;
|
|
271
|
+
}
|
|
272
|
+
// Check for Algebra-based protocols
|
|
273
|
+
if (protocol && (0, protocol_1.isAlgebraProtocol)(protocol)) {
|
|
274
|
+
return quoter_1.QuickSwapQuoterV2;
|
|
275
|
+
}
|
|
276
|
+
// Check for Thick V2 protocols
|
|
277
|
+
if ((0, protocol_1.isThickV2Protocol)(protocol)) {
|
|
278
|
+
return quoter_1.QuoterV2Thick;
|
|
279
|
+
}
|
|
280
|
+
// Default to standard Uniswap V3 QuoterV2 ABI
|
|
281
|
+
return quoter_1.UniswapV3QuoterABI;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Gets the QuoterV2 address for the given protocol from the network configuration.
|
|
285
|
+
*
|
|
286
|
+
* @param protocol - The protocol type
|
|
287
|
+
* @returns The quoter address or undefined if not found
|
|
288
|
+
*/
|
|
289
|
+
getQuoterV2Address(protocol) {
|
|
290
|
+
if (!protocol) {
|
|
291
|
+
return undefined;
|
|
292
|
+
}
|
|
293
|
+
const contractAddresses = (0, amm_1.getProtocolContractAddresses)(protocol, this.networkConfig.name, 'QuoterV2');
|
|
294
|
+
if (!protocol || !contractAddresses) {
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
return contractAddresses.quoterV2Address;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Checks if the beacon represents an Algebra Integral v2.1 vault.
|
|
301
|
+
*
|
|
302
|
+
* @param beaconName - The beacon identifier
|
|
303
|
+
* @returns True if it's an Algebra Integral v2.1 vault
|
|
304
|
+
*/
|
|
305
|
+
isAlgebraIntegral21Vault(protocol) {
|
|
306
|
+
return protocol === chain_1.Protocol.KatanaIntegral;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.QuoterV2Factory = QuoterV2Factory;
|
|
310
|
+
/**
|
|
311
|
+
* Helper function to get QuoterV2 address for a protocol from network config.
|
|
312
|
+
*
|
|
313
|
+
* @param protocol - The protocol to get the quoter address for
|
|
314
|
+
* @param networkConfig - The network configuration object
|
|
315
|
+
* @returns The quoter address or undefined if not found
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* const quoterAddress = getQuoterV2Address(Protocol.QuickSwap, networkConfig);
|
|
320
|
+
* if (quoterAddress) {
|
|
321
|
+
* // Use the quoter address
|
|
322
|
+
* }
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
/**
|
|
326
|
+
* Type guard to check if parameters are for Uniswap V3 style quoter
|
|
327
|
+
*/
|
|
328
|
+
function isUniswapQuoteParams(params) {
|
|
329
|
+
return 'fee' in params;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Type guard to check if parameters are for Algebra style quoter
|
|
333
|
+
*/
|
|
334
|
+
function isAlgebraQuoteParams(params) {
|
|
335
|
+
return 'limitSqrtPrice' in params;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Type guard to check if parameters are for Thick V2 style quoter
|
|
339
|
+
*/
|
|
340
|
+
function isThickQuoteParams(params) {
|
|
341
|
+
return 'tickSpacing' in params && 'sqrtPriceLimitX96' in params;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Type guard to check if parameters are for Algebra Integral v2.1 style quoter
|
|
345
|
+
*/
|
|
346
|
+
function isAlgebraIntegral21QuoteParams(params) {
|
|
347
|
+
return 'deployer' in params;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Type guard to check if parameters are for Shadow style quoter
|
|
351
|
+
*/
|
|
352
|
+
function isShadowQuoteParams(params) {
|
|
353
|
+
return 'tickSpacing' in params && 'sqrtPriceLimitX96' in params;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Validates quote parameters based on the protocol type detected from beacon name
|
|
357
|
+
*
|
|
358
|
+
* @param beaconName - The beacon identifier to determine the protocol type
|
|
359
|
+
* @param params - The parameters to validate
|
|
360
|
+
* @throws Error if parameters don't match the expected protocol type
|
|
361
|
+
*/
|
|
362
|
+
function validateQuoteParams(protocol, params) {
|
|
363
|
+
if (!protocol) {
|
|
364
|
+
throw Error('Protocol not found');
|
|
365
|
+
}
|
|
366
|
+
// Validate required fields
|
|
367
|
+
if (!params.tokenIn || !params.tokenOut || !params.amountIn) {
|
|
368
|
+
throw new Error('Missing required parameters: tokenIn, tokenOut, and amountIn are required');
|
|
369
|
+
}
|
|
370
|
+
// Check for Algebra Integral v2.1 vaults (newer version with deployer)
|
|
371
|
+
if (protocol === chain_1.Protocol.KatanaIntegral) {
|
|
372
|
+
if (!isAlgebraIntegral21QuoteParams(params)) {
|
|
373
|
+
throw new Error('AlgebraIntegral21QuoteParams required: must include deployer field');
|
|
374
|
+
}
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
// Check for Shadow protocol vaults
|
|
378
|
+
if (protocol && (0, protocol_1.isShadowProtocol)(protocol)) {
|
|
379
|
+
if (!isShadowQuoteParams(params) && !isThickQuoteParams(params)) {
|
|
380
|
+
throw new Error('ShadowQuoteParams required: must include tickSpacing field');
|
|
381
|
+
}
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
// Check for Thick V2 protocols
|
|
385
|
+
if (protocol && (0, protocol_1.isThickV2Protocol)(protocol)) {
|
|
386
|
+
if (!isThickQuoteParams(params)) {
|
|
387
|
+
throw new Error('ThickQuoteParams required: must include tickSpacing field');
|
|
388
|
+
}
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
// Check for Algebra-based protocols
|
|
392
|
+
if (protocol && (0, protocol_1.isAlgebraProtocol)(protocol)) {
|
|
393
|
+
if (!isAlgebraQuoteParams(params)) {
|
|
394
|
+
throw new Error('AlgebraQuoteParams required: limitSqrtPrice field expected');
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
// Default to Uniswap V3 style validation
|
|
399
|
+
if (!isUniswapQuoteParams(params)) {
|
|
400
|
+
throw new Error('UniswapQuoteParams required: must include fee field');
|
|
19
401
|
}
|
|
20
|
-
return address;
|
|
21
402
|
}
|
|
22
403
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @
|
|
26
|
-
* @
|
|
404
|
+
* Gets the expected parameter type for a given beacon name
|
|
405
|
+
*
|
|
406
|
+
* @param beaconName - The beacon identifier
|
|
407
|
+
* @returns String describing the expected parameter type
|
|
27
408
|
*/
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
409
|
+
function getExpectedParamType(beaconName) {
|
|
410
|
+
const protocol = (0, beacon_1.getProtocolTypeByBeacon)(beaconName);
|
|
411
|
+
if (beaconName.toLowerCase().includes('katanaintegral') || protocol === chain_1.Protocol.KatanaIntegral) {
|
|
412
|
+
return 'AlgebraIntegral21QuoteParams (requires: tokenIn, tokenOut, amountIn, deployer, limitSqrtPrice?)';
|
|
413
|
+
}
|
|
414
|
+
if (protocol && (0, protocol_1.isShadowProtocol)(protocol)) {
|
|
415
|
+
return 'ShadowQuoteParams (requires: tokenIn, tokenOut, amountIn, tickSpacing, sqrtPriceLimitX96?)';
|
|
416
|
+
}
|
|
417
|
+
if (protocol && (0, protocol_1.isThickV2Protocol)(protocol)) {
|
|
418
|
+
return 'ThickQuoteParams (requires: tokenIn, tokenOut, amountIn, tickSpacing, sqrtPriceLimitX96?)';
|
|
419
|
+
}
|
|
420
|
+
if (protocol && (0, protocol_1.isAlgebraProtocol)(protocol)) {
|
|
421
|
+
return 'AlgebraQuoteParams (requires: tokenIn, tokenOut, amountIn, limitSqrtPrice?)';
|
|
33
422
|
}
|
|
34
|
-
|
|
35
|
-
const chain = chainName;
|
|
36
|
-
return getQuoterAddress(chain);
|
|
423
|
+
return 'UniswapQuoteParams (requires: tokenIn, tokenOut, amountIn, fee, sqrtPriceLimitX96?)';
|
|
37
424
|
}
|
|
38
425
|
//# sourceMappingURL=quoter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quoter.js","sourceRoot":"","sources":["../../../src/const/quoter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quoter.js","sourceRoot":"","sources":["../../../src/const/quoter.ts"],"names":[],"mappings":";;;AAycA,oDAEC;AAKD,oDAEC;AAKD,gDAEC;AAKD,wEAEC;AAKD,kDAEC;AASD,kDA8CC;AAQD,oDAoBC;AAzjBD,+BAAmC;AACnC,mCAAmC;AACnC,+CAA6D;AAC7D,yCAA+G;AAC/G,0CAOuB;AAEvB,+BAAqD;AAsGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH,MAAa,eAAe;IAG1B,YAAY,aAA4B;QACtC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,cAAc,CAAC,QAAkB,EAAE,MAAmB;QACpD,4BAA4B;QAC5B,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEtC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACpC,CAAC;QACD,uEAAuE;QACvE,IAAI,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,GAAG,MAAsC,CAAC;YACjD,OAAO;gBACL,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,cAAc,EAAE,CAAC,CAAC,cAAc,IAAI,EAAE;aACvC,CAAC;QACJ,CAAC;QAED,mCAAmC;QACnC,IAAI,IAAA,2BAAgB,EAAC,QAAQ,CAAC,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,MAA2B,CAAC;YACtC,OAAO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4BAAiB,EAAC,QAAQ,CAAC,EAAE,CAAC;QAC5C,OAAO,6EAA6E,CAAC;IACvF,CAAC;IAED,OAAO,qFAAqF,CAAC;AAC/F,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { decodeFunctionResult, encodeFunctionData } from 'viem';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { getNetworkByChainId, getProtcolTypeByAmmType } from '../../../const';
|
|
3
|
+
import { QuoterV2Factory } from '../../../const/quoter';
|
|
4
4
|
import { getPoolPrice } from '../utils';
|
|
5
5
|
import { bigintToDecimal, decimalToBigint, getPoolSlot0, getQuoteFromSqrtRatioX96 } from './calculateLimitPrice';
|
|
6
6
|
import { AMMType } from './types';
|
|
@@ -35,26 +35,34 @@ import { AMMType } from './types';
|
|
|
35
35
|
export async function simulateSwap(publicClient, params, chainId) {
|
|
36
36
|
try {
|
|
37
37
|
// For now, only handle UniswapV3 - other AMMs can be added later
|
|
38
|
-
if (params.ammType !== AMMType.UniswapV3) {
|
|
39
|
-
throw new Error(`AMM type ${params.ammType} not yet supported. Use UniswapV3 for now.`);
|
|
40
|
-
}
|
|
41
38
|
// Get the appropriate Quoter contract address
|
|
42
|
-
const
|
|
39
|
+
const networkConfig = getNetworkByChainId(chainId);
|
|
40
|
+
if (!networkConfig) {
|
|
41
|
+
throw Error('Network config not found');
|
|
42
|
+
}
|
|
43
|
+
const protocol = getProtcolTypeByAmmType(params.ammType);
|
|
44
|
+
const quoterFactory = new QuoterV2Factory(networkConfig);
|
|
45
|
+
const quoterABI = quoterFactory.getQuoterAbi(protocol);
|
|
46
|
+
const quoteParams = quoterFactory.getQuoteParams(protocol, {
|
|
47
|
+
tokenIn: params.tokenIn,
|
|
48
|
+
tokenOut: params.tokenOut,
|
|
49
|
+
fee: params.fee,
|
|
50
|
+
tickSpacing: params.tickSpacing,
|
|
51
|
+
amountIn: params.amountSpecified,
|
|
52
|
+
sqrtPriceLimitX96: params.sqrtPriceLimitX96,
|
|
53
|
+
limitSqrtPrice: params.sqrtPriceLimitX96,
|
|
54
|
+
});
|
|
55
|
+
const quoterAddress = quoterFactory.getQuoterV2Address(protocol);
|
|
43
56
|
// Use Quoter's quoteExactInputSingle for simulation
|
|
44
57
|
const result = await publicClient.call({
|
|
45
58
|
to: quoterAddress,
|
|
46
59
|
data: encodeFunctionData({
|
|
47
|
-
abi:
|
|
60
|
+
abi: quoterABI,
|
|
48
61
|
functionName: 'quoteExactInputSingle',
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
amountIn: params.amountSpecified,
|
|
54
|
-
fee: params.fee,
|
|
55
|
-
sqrtPriceLimitX96: params.sqrtPriceLimitX96
|
|
56
|
-
}
|
|
57
|
-
]
|
|
62
|
+
//@ts-expect-error Parameters are dynamic in nature and very based on abi types
|
|
63
|
+
args: [{
|
|
64
|
+
...quoteParams
|
|
65
|
+
}]
|
|
58
66
|
})
|
|
59
67
|
});
|
|
60
68
|
if (!result.data) {
|
|
@@ -62,7 +70,7 @@ export async function simulateSwap(publicClient, params, chainId) {
|
|
|
62
70
|
}
|
|
63
71
|
// Decode the result - Quoter returns a tuple: [amountOut, sqrtPriceX96After, initializedTicksCrossed, gasEstimate]
|
|
64
72
|
const [amountOut, sqrtPriceX96After] = decodeFunctionResult({
|
|
65
|
-
abi:
|
|
73
|
+
abi: quoterABI,
|
|
66
74
|
functionName: 'quoteExactInputSingle',
|
|
67
75
|
data: result.data
|
|
68
76
|
});
|
|
@@ -191,6 +199,23 @@ export async function simulateSwapWithSlippage(publicClient, params, chainId) {
|
|
|
191
199
|
feeProtocol: slot0Result.data.feeProtocol,
|
|
192
200
|
unlocked: slot0Result.data.unlocked
|
|
193
201
|
};
|
|
202
|
+
const tickSpacing = await publicClient.readContract({
|
|
203
|
+
abi: [{
|
|
204
|
+
"inputs": [],
|
|
205
|
+
"name": "tickSpacing",
|
|
206
|
+
"outputs": [
|
|
207
|
+
{
|
|
208
|
+
"internalType": "int24",
|
|
209
|
+
"name": "",
|
|
210
|
+
"type": "int24"
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"stateMutability": "view",
|
|
214
|
+
"type": "function"
|
|
215
|
+
},],
|
|
216
|
+
functionName: 'tickSpacing',
|
|
217
|
+
address: params.poolAddress,
|
|
218
|
+
});
|
|
194
219
|
// Step 2: Simulate the swap using existing function
|
|
195
220
|
const swapParams = {
|
|
196
221
|
pool: params.poolAddress,
|
|
@@ -202,6 +227,7 @@ export async function simulateSwapWithSlippage(publicClient, params, chainId) {
|
|
|
202
227
|
tokenIn: params.tokenIn,
|
|
203
228
|
tokenOut: params.tokenOut,
|
|
204
229
|
fee: params.fee,
|
|
230
|
+
tickSpacing: tickSpacing,
|
|
205
231
|
quoterAddress: params.quoterAddress
|
|
206
232
|
};
|
|
207
233
|
const swapResult = await simulateSwap(publicClient, swapParams, chainId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulateSwap.js","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/simulateSwap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"simulateSwap.js","sourceRoot":"","sources":["../../../../../src/base/vault/single-asset/simulateSwap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEjH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC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