@synthra-swap/sdk 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/chains.d.ts +1 -0
- package/chains.js +1 -0
- package/core.d.ts +1 -0
- package/core.js +1 -0
- package/dist/chain-registry.d.ts +22 -0
- package/dist/chain-registry.js +315 -0
- package/dist/chain-registry.js.map +1 -0
- package/dist/chains.d.ts +5 -0
- package/dist/chains.js +29 -0
- package/dist/chains.js.map +1 -0
- package/dist/core/addresses.d.ts +21 -0
- package/dist/core/addresses.js +76 -0
- package/dist/core/addresses.js.map +1 -0
- package/dist/core/chains.d.ts +51 -0
- package/dist/core/chains.js +82 -0
- package/dist/core/chains.js.map +1 -0
- package/dist/core/constants.d.ts +12 -0
- package/dist/core/constants.js +20 -0
- package/dist/core/constants.js.map +1 -0
- package/dist/core/entities/baseCurrency.d.ts +48 -0
- package/dist/core/entities/baseCurrency.js +29 -0
- package/dist/core/entities/baseCurrency.js.map +1 -0
- package/dist/core/entities/currency.d.ts +3 -0
- package/dist/core/entities/currency.js +3 -0
- package/dist/core/entities/currency.js.map +1 -0
- package/dist/core/entities/ether.d.ts +13 -0
- package/dist/core/entities/ether.js +32 -0
- package/dist/core/entities/ether.js.map +1 -0
- package/dist/core/entities/fractions/currencyAmount.d.ts +31 -0
- package/dist/core/entities/fractions/currencyAmount.js +74 -0
- package/dist/core/entities/fractions/currencyAmount.js.map +1 -0
- package/dist/core/entities/fractions/fraction.d.ts +24 -0
- package/dist/core/entities/fractions/fraction.js +106 -0
- package/dist/core/entities/fractions/fraction.js.map +1 -0
- package/dist/core/entities/fractions/index.d.ts +4 -0
- package/dist/core/entities/fractions/index.js +12 -0
- package/dist/core/entities/fractions/index.js.map +1 -0
- package/dist/core/entities/fractions/percent.d.ts +14 -0
- package/dist/core/entities/fractions/percent.js +45 -0
- package/dist/core/entities/fractions/percent.js.map +1 -0
- package/dist/core/entities/fractions/price.d.ts +38 -0
- package/dist/core/entities/fractions/price.js +75 -0
- package/dist/core/entities/fractions/price.js.map +1 -0
- package/dist/core/entities/index.d.ts +7 -0
- package/dist/core/entities/index.js +24 -0
- package/dist/core/entities/index.js.map +1 -0
- package/dist/core/entities/nativeCurrency.d.ts +8 -0
- package/dist/core/entities/nativeCurrency.js +16 -0
- package/dist/core/entities/nativeCurrency.js.map +1 -0
- package/dist/core/entities/nativeOnChain.d.ts +19 -0
- package/dist/core/entities/nativeOnChain.js +141 -0
- package/dist/core/entities/nativeOnChain.js.map +1 -0
- package/dist/core/entities/token.d.ts +48 -0
- package/dist/core/entities/token.js +71 -0
- package/dist/core/entities/token.js.map +1 -0
- package/dist/core/entities/weth9.d.ts +7 -0
- package/dist/core/entities/weth9.js +28 -0
- package/dist/core/entities/weth9.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +22 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/utils/computePriceImpact.d.ts +8 -0
- package/dist/core/utils/computePriceImpact.js +18 -0
- package/dist/core/utils/computePriceImpact.js.map +1 -0
- package/dist/core/utils/index.d.ts +4 -0
- package/dist/core/utils/index.js +12 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/core/utils/sortedInsert.d.ts +1 -0
- package/dist/core/utils/sortedInsert.js +40 -0
- package/dist/core/utils/sortedInsert.js.map +1 -0
- package/dist/core/utils/sqrt.d.ts +7 -0
- package/dist/core/utils/sqrt.js +34 -0
- package/dist/core/utils/sqrt.js.map +1 -0
- package/dist/core/utils/validateAndParseAddress.d.ts +10 -0
- package/dist/core/utils/validateAndParseAddress.js +31 -0
- package/dist/core/utils/validateAndParseAddress.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/universal-router/entities/Command.d.ts +12 -0
- package/dist/universal-router/entities/Command.js +9 -0
- package/dist/universal-router/entities/Command.js.map +1 -0
- package/dist/universal-router/entities/index.d.ts +3 -0
- package/dist/universal-router/entities/index.js +20 -0
- package/dist/universal-router/entities/index.js.map +1 -0
- package/dist/universal-router/entities/protocols/index.d.ts +2 -0
- package/dist/universal-router/entities/protocols/index.js +19 -0
- package/dist/universal-router/entities/protocols/index.js.map +1 -0
- package/dist/universal-router/entities/protocols/uniswap.d.ts +32 -0
- package/dist/universal-router/entities/protocols/uniswap.js +143 -0
- package/dist/universal-router/entities/protocols/uniswap.js.map +1 -0
- package/dist/universal-router/entities/protocols/unwrapWETH.d.ts +12 -0
- package/dist/universal-router/entities/protocols/unwrapWETH.js +35 -0
- package/dist/universal-router/entities/protocols/unwrapWETH.js.map +1 -0
- package/dist/universal-router/entities/trade.d.ts +41 -0
- package/dist/universal-router/entities/trade.js +114 -0
- package/dist/universal-router/entities/trade.js.map +1 -0
- package/dist/universal-router/index.d.ts +5 -0
- package/dist/universal-router/index.js +31 -0
- package/dist/universal-router/index.js.map +1 -0
- package/dist/universal-router/swapRouter.d.ts +29 -0
- package/dist/universal-router/swapRouter.js +102 -0
- package/dist/universal-router/swapRouter.js.map +1 -0
- package/dist/universal-router/utils/constants.d.ts +8 -0
- package/dist/universal-router/utils/constants.js +21 -0
- package/dist/universal-router/utils/constants.js.map +1 -0
- package/dist/universal-router/utils/getNativeCurrencyValue.d.ts +2 -0
- package/dist/universal-router/utils/getNativeCurrencyValue.js +19 -0
- package/dist/universal-router/utils/getNativeCurrencyValue.js.map +1 -0
- package/dist/universal-router/utils/inputTokens.d.ts +16 -0
- package/dist/universal-router/utils/inputTokens.js +44 -0
- package/dist/universal-router/utils/inputTokens.js.map +1 -0
- package/dist/universal-router/utils/numbers.d.ts +6 -0
- package/dist/universal-router/utils/numbers.js +24 -0
- package/dist/universal-router/utils/numbers.js.map +1 -0
- package/dist/universal-router/utils/routerCommands.d.ts +29 -0
- package/dist/universal-router/utils/routerCommands.js +64 -0
- package/dist/universal-router/utils/routerCommands.js.map +1 -0
- package/dist/universal-router/utils/routerTradeAdapter.d.ts +40 -0
- package/dist/universal-router/utils/routerTradeAdapter.js +82 -0
- package/dist/universal-router/utils/routerTradeAdapter.js.map +1 -0
- package/dist/v3/abis.d.ts +6 -0
- package/dist/v3/abis.js +39 -0
- package/dist/v3/abis.js.map +1 -0
- package/dist/v3/constants.d.ts +18 -0
- package/dist/v3/constants.js +26 -0
- package/dist/v3/constants.js.map +1 -0
- package/dist/v3/entities/index.d.ts +7 -0
- package/dist/v3/entities/index.js +24 -0
- package/dist/v3/entities/index.js.map +1 -0
- package/dist/v3/entities/pool.d.ts +81 -0
- package/dist/v3/entities/pool.js +215 -0
- package/dist/v3/entities/pool.js.map +1 -0
- package/dist/v3/entities/position.d.ts +131 -0
- package/dist/v3/entities/position.js +250 -0
- package/dist/v3/entities/position.js.map +1 -0
- package/dist/v3/entities/route.d.ts +26 -0
- package/dist/v3/entities/route.js +77 -0
- package/dist/v3/entities/route.js.map +1 -0
- package/dist/v3/entities/tick.d.ts +13 -0
- package/dist/v3/entities/tick.js +19 -0
- package/dist/v3/entities/tick.js.map +1 -0
- package/dist/v3/entities/tickDataProvider.d.ts +31 -0
- package/dist/v3/entities/tickDataProvider.js +18 -0
- package/dist/v3/entities/tickDataProvider.js.map +1 -0
- package/dist/v3/entities/tickListDataProvider.d.ts +15 -0
- package/dist/v3/entities/tickListDataProvider.js +23 -0
- package/dist/v3/entities/tickListDataProvider.js.map +1 -0
- package/dist/v3/entities/trade.d.ts +220 -0
- package/dist/v3/entities/trade.js +442 -0
- package/dist/v3/entities/trade.js.map +1 -0
- package/dist/v3/index.d.ts +9 -0
- package/dist/v3/index.js +26 -0
- package/dist/v3/index.js.map +1 -0
- package/dist/v3/internalConstants.d.ts +6 -0
- package/dist/v3/internalConstants.js +15 -0
- package/dist/v3/internalConstants.js.map +1 -0
- package/dist/v3/multicall.d.ts +9 -0
- package/dist/v3/multicall.js +20 -0
- package/dist/v3/multicall.js.map +1 -0
- package/dist/v3/nonfungiblePositionManager.d.ts +146 -0
- package/dist/v3/nonfungiblePositionManager.js +231 -0
- package/dist/v3/nonfungiblePositionManager.js.map +1 -0
- package/dist/v3/payments.d.ts +24 -0
- package/dist/v3/payments.js +55 -0
- package/dist/v3/payments.js.map +1 -0
- package/dist/v3/quoter.d.ts +37 -0
- package/dist/v3/quoter.js +76 -0
- package/dist/v3/quoter.js.map +1 -0
- package/dist/v3/selfPermit.d.ts +25 -0
- package/dist/v3/selfPermit.js +37 -0
- package/dist/v3/selfPermit.js.map +1 -0
- package/dist/v3/swapRouter.d.ts +51 -0
- package/dist/v3/swapRouter.js +147 -0
- package/dist/v3/swapRouter.js.map +1 -0
- package/dist/v3/utils/calldata.d.ts +20 -0
- package/dist/v3/utils/calldata.js +22 -0
- package/dist/v3/utils/calldata.js.map +1 -0
- package/dist/v3/utils/computePoolAddress.d.ts +18 -0
- package/dist/v3/utils/computePoolAddress.js +22 -0
- package/dist/v3/utils/computePoolAddress.js.map +1 -0
- package/dist/v3/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/v3/utils/encodeRouteToPath.js +32 -0
- package/dist/v3/utils/encodeRouteToPath.js.map +1 -0
- package/dist/v3/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/v3/utils/encodeSqrtRatioX96.js +22 -0
- package/dist/v3/utils/encodeSqrtRatioX96.js.map +1 -0
- package/dist/v3/utils/fullMath.d.ts +8 -0
- package/dist/v3/utils/fullMath.js +23 -0
- package/dist/v3/utils/fullMath.js.map +1 -0
- package/dist/v3/utils/index.d.ts +17 -0
- package/dist/v3/utils/index.js +34 -0
- package/dist/v3/utils/index.js.map +1 -0
- package/dist/v3/utils/isSorted.d.ts +7 -0
- package/dist/v3/utils/isSorted.js +19 -0
- package/dist/v3/utils/isSorted.js.map +1 -0
- package/dist/v3/utils/liquidityMath.d.ts +8 -0
- package/dist/v3/utils/liquidityMath.js +24 -0
- package/dist/v3/utils/liquidityMath.js.map +1 -0
- package/dist/v3/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/v3/utils/maxLiquidityForAmounts.js +89 -0
- package/dist/v3/utils/maxLiquidityForAmounts.js.map +1 -0
- package/dist/v3/utils/mostSignificantBit.d.ts +2 -0
- package/dist/v3/utils/mostSignificantBit.js +29 -0
- package/dist/v3/utils/mostSignificantBit.js.map +1 -0
- package/dist/v3/utils/nearestUsableTick.d.ts +6 -0
- package/dist/v3/utils/nearestUsableTick.js +27 -0
- package/dist/v3/utils/nearestUsableTick.js.map +1 -0
- package/dist/v3/utils/position.d.ts +8 -0
- package/dist/v3/utils/position.js +23 -0
- package/dist/v3/utils/position.js.map +1 -0
- package/dist/v3/utils/priceTickConversions.d.ts +15 -0
- package/dist/v3/utils/priceTickConversions.js +52 -0
- package/dist/v3/utils/priceTickConversions.js.map +1 -0
- package/dist/v3/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/v3/utils/sqrtPriceMath.js +97 -0
- package/dist/v3/utils/sqrtPriceMath.js.map +1 -0
- package/dist/v3/utils/swapMath.d.ts +9 -0
- package/dist/v3/utils/swapMath.js +79 -0
- package/dist/v3/utils/swapMath.js.map +1 -0
- package/dist/v3/utils/tickLibrary.d.ts +14 -0
- package/dist/v3/utils/tickLibrary.js +53 -0
- package/dist/v3/utils/tickLibrary.js.map +1 -0
- package/dist/v3/utils/tickList.d.ts +23 -0
- package/dist/v3/utils/tickList.js +110 -0
- package/dist/v3/utils/tickList.js.map +1 -0
- package/dist/v3/utils/tickMath.d.ts +34 -0
- package/dist/v3/utils/tickMath.js +127 -0
- package/dist/v3/utils/tickMath.js.map +1 -0
- package/package.json +80 -0
- package/universal-router.d.ts +1 -0
- package/universal-router.js +1 -0
- package/v3.d.ts +1 -0
- package/v3.js +1 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SwapQuoter = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const core_1 = require("../core");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const abis_1 = require("./abis");
|
|
11
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
12
|
+
const QUOTER_V2_ABI = [
|
|
13
|
+
'function quoteExactInput(bytes path, uint256 amountIn) returns (uint256 amountOut, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)',
|
|
14
|
+
'function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint24 fee, uint160 sqrtPriceLimitX96) params) returns (uint256 amountOut, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)',
|
|
15
|
+
'function quoteExactOutput(bytes path, uint256 amountOut) returns (uint256 amountIn, uint160[] sqrtPriceX96AfterList, uint32[] initializedTicksCrossedList, uint256 gasEstimate)',
|
|
16
|
+
'function quoteExactOutputSingle((address tokenIn, address tokenOut, uint256 amount, uint24 fee, uint160 sqrtPriceLimitX96) params) returns (uint256 amountIn, uint160 sqrtPriceX96After, uint32 initializedTicksCrossed, uint256 gasEstimate)'
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Represents the V3 Quoter contract with a method for returning the formatted
|
|
20
|
+
* calldata needed to call the quoter contract.
|
|
21
|
+
*/
|
|
22
|
+
class SwapQuoter {
|
|
23
|
+
/**
|
|
24
|
+
* Produces the on-chain method name of the appropriate function within QuoterV2,
|
|
25
|
+
* and the relevant hex encoded parameters.
|
|
26
|
+
* @template TInput The input token, either Ether or an ERC-20
|
|
27
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
|
28
|
+
* @param route The swap route, a list of pools through which a swap can occur
|
|
29
|
+
* @param amount The amount of the quote, either an amount in, or an amount out
|
|
30
|
+
* @param tradeType The trade type, either exact input or exact output
|
|
31
|
+
* @param options The optional params including price limit and Quoter contract switch
|
|
32
|
+
* @returns The formatted calldata
|
|
33
|
+
*/
|
|
34
|
+
static quoteCallParameters(route, amount, tradeType, options = {}) {
|
|
35
|
+
var _a;
|
|
36
|
+
const singleHop = route.pools.length === 1;
|
|
37
|
+
const quoteAmount = (0, utils_1.toHex)(amount.quotient);
|
|
38
|
+
let calldata;
|
|
39
|
+
const swapInterface = options.useQuoterV2 ? this.V2INTERFACE : this.V1INTERFACE;
|
|
40
|
+
if (singleHop) {
|
|
41
|
+
const baseQuoteParams = {
|
|
42
|
+
tokenIn: route.tokenPath[0].address,
|
|
43
|
+
tokenOut: route.tokenPath[1].address,
|
|
44
|
+
fee: route.pools[0].fee,
|
|
45
|
+
sqrtPriceLimitX96: (0, utils_1.toHex)((_a = options === null || options === void 0 ? void 0 : options.sqrtPriceLimitX96) !== null && _a !== void 0 ? _a : 0)
|
|
46
|
+
};
|
|
47
|
+
const v2QuoteParams = {
|
|
48
|
+
...baseQuoteParams,
|
|
49
|
+
...(tradeType == core_1.TradeType.EXACT_INPUT ? { amountIn: quoteAmount } : { amount: quoteAmount })
|
|
50
|
+
};
|
|
51
|
+
const v1QuoteParams = [
|
|
52
|
+
baseQuoteParams.tokenIn,
|
|
53
|
+
baseQuoteParams.tokenOut,
|
|
54
|
+
baseQuoteParams.fee,
|
|
55
|
+
quoteAmount,
|
|
56
|
+
baseQuoteParams.sqrtPriceLimitX96
|
|
57
|
+
];
|
|
58
|
+
const tradeTypeFunctionName = tradeType === core_1.TradeType.EXACT_INPUT ? 'quoteExactInputSingle' : 'quoteExactOutputSingle';
|
|
59
|
+
calldata = swapInterface.encodeFunctionData(tradeTypeFunctionName, options.useQuoterV2 ? [v2QuoteParams] : v1QuoteParams);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
(0, tiny_invariant_1.default)((options === null || options === void 0 ? void 0 : options.sqrtPriceLimitX96) === undefined, 'MULTIHOP_PRICE_LIMIT');
|
|
63
|
+
const path = (0, utils_1.encodeRouteToPath)(route, tradeType === core_1.TradeType.EXACT_OUTPUT);
|
|
64
|
+
const tradeTypeFunctionName = tradeType === core_1.TradeType.EXACT_INPUT ? 'quoteExactInput' : 'quoteExactOutput';
|
|
65
|
+
calldata = swapInterface.encodeFunctionData(tradeTypeFunctionName, [path, quoteAmount]);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
calldata,
|
|
69
|
+
value: (0, utils_1.toHex)(0)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.SwapQuoter = SwapQuoter;
|
|
74
|
+
SwapQuoter.V1INTERFACE = new abi_1.Interface(abis_1.QUOTER_ABI);
|
|
75
|
+
SwapQuoter.V2INTERFACE = new abi_1.Interface(QUOTER_V2_ABI);
|
|
76
|
+
//# sourceMappingURL=quoter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quoter.js","sourceRoot":"","sources":["../../src/v3/quoter.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA8C;AAC9C,kCAAwE;AACxE,mCAAoE;AACpE,iCAAmC;AAEnC,oEAAsC;AAGtC,MAAM,aAAa,GAAG;IACpB,gLAAgL;IAChL,iPAAiP;IACjP,iLAAiL;IACjL,+OAA+O;CAChP,CAAA;AAwBD;;;GAGG;AACH,MAAsB,UAAU;IAI9B;;;;;;;;;;OAUG;IACI,MAAM,CAAC,mBAAmB,CAC/B,KAA6B,EAC7B,MAAwC,EACxC,SAAoB,EACpB,UAAwB,EAAE;;QAE1B,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;QAC1C,MAAM,WAAW,GAAW,IAAA,aAAK,EAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;QAClD,IAAI,QAAgB,CAAA;QACpB,MAAM,aAAa,GAAc,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAA;QAE1F,IAAI,SAAS,EAAE;YACb,MAAM,eAAe,GAAo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AC,WAAW,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,kBAAkB,CAAA;YAC1G,QAAQ,GAAG,aAAa,CAAC,kBAAkB,CAAC,qBAAqB,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAA;SACxF;QACD,OAAO;YACL,QAAQ;YACR,KAAK,EAAE,IAAA,aAAK,EAAC,CAAC,CAAC;SAChB,CAAA;IACH,CAAC;;AA/DH,gCAgEC;AA/De,sBAAW,GAAc,IAAI,eAAS,CAAC,iBAAU,CAAC,CAAA;AAClD,sBAAW,GAAc,IAAI,eAAS,CAAC,aAAa,CAAC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BigintIsh, Token } from '../core';
|
|
2
|
+
import { Interface } from '@ethersproject/abi';
|
|
3
|
+
export interface StandardPermitArguments {
|
|
4
|
+
v: 0 | 1 | 27 | 28;
|
|
5
|
+
r: string;
|
|
6
|
+
s: string;
|
|
7
|
+
amount: BigintIsh;
|
|
8
|
+
deadline: BigintIsh;
|
|
9
|
+
}
|
|
10
|
+
export interface AllowedPermitArguments {
|
|
11
|
+
v: 0 | 1 | 27 | 28;
|
|
12
|
+
r: string;
|
|
13
|
+
s: string;
|
|
14
|
+
nonce: BigintIsh;
|
|
15
|
+
expiry: BigintIsh;
|
|
16
|
+
}
|
|
17
|
+
export type PermitOptions = StandardPermitArguments | AllowedPermitArguments;
|
|
18
|
+
export declare abstract class SelfPermit {
|
|
19
|
+
static INTERFACE: Interface;
|
|
20
|
+
/**
|
|
21
|
+
* Cannot be constructed.
|
|
22
|
+
*/
|
|
23
|
+
private constructor();
|
|
24
|
+
static encodePermit(token: Token, options: PermitOptions): string;
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelfPermit = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const abis_1 = require("./abis");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
function isAllowedPermit(permitOptions) {
|
|
8
|
+
return 'nonce' in permitOptions;
|
|
9
|
+
}
|
|
10
|
+
class SelfPermit {
|
|
11
|
+
/**
|
|
12
|
+
* Cannot be constructed.
|
|
13
|
+
*/
|
|
14
|
+
constructor() { }
|
|
15
|
+
static encodePermit(token, options) {
|
|
16
|
+
return isAllowedPermit(options)
|
|
17
|
+
? SelfPermit.INTERFACE.encodeFunctionData('selfPermitAllowed', [
|
|
18
|
+
token.address,
|
|
19
|
+
(0, utils_1.toHex)(options.nonce),
|
|
20
|
+
(0, utils_1.toHex)(options.expiry),
|
|
21
|
+
options.v,
|
|
22
|
+
options.r,
|
|
23
|
+
options.s
|
|
24
|
+
])
|
|
25
|
+
: SelfPermit.INTERFACE.encodeFunctionData('selfPermit', [
|
|
26
|
+
token.address,
|
|
27
|
+
(0, utils_1.toHex)(options.amount),
|
|
28
|
+
(0, utils_1.toHex)(options.deadline),
|
|
29
|
+
options.v,
|
|
30
|
+
options.r,
|
|
31
|
+
options.s
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.SelfPermit = SelfPermit;
|
|
36
|
+
SelfPermit.INTERFACE = new abi_1.Interface(abis_1.SELF_PERMIT_ABI);
|
|
37
|
+
//# sourceMappingURL=selfPermit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selfPermit.js","sourceRoot":"","sources":["../../src/v3/selfPermit.ts"],"names":[],"mappings":";;;AACA,4CAA8C;AAC9C,iCAAwC;AACxC,mCAA+B;AAoB/B,SAAS,eAAe,CAAC,aAA4B;IACnD,OAAO,OAAO,IAAI,aAAa,CAAA;AACjC,CAAC;AAED,MAAsB,UAAU;IAG9B;;OAEG;IACH,gBAAuB,CAAC;IAEjB,MAAM,CAAC,YAAY,CAAC,KAAY,EAAE,OAAsB;QAC7D,OAAO,eAAe,CAAC,OAAO,CAAC;YAC7B,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,kBAAkB,CAAC,mBAAmB,EAAE;gBAC3D,KAAK,CAAC,OAAO;gBACb,IAAA,aAAK,EAAC,OAAO,CAAC,KAAK,CAAC;gBACpB,IAAA,aAAK,EAAC,OAAO,CAAC,MAAM,CAAC;gBACrB,OAAO,CAAC,CAAC;gBACT,OAAO,CAAC,CAAC;gBACT,OAAO,CAAC,CAAC;aACV,CAAC;YACJ,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,kBAAkB,CAAC,YAAY,EAAE;gBACpD,KAAK,CAAC,OAAO;gBACb,IAAA,aAAK,EAAC,OAAO,CAAC,MAAM,CAAC;gBACrB,IAAA,aAAK,EAAC,OAAO,CAAC,QAAQ,CAAC;gBACvB,OAAO,CAAC,CAAC;gBACT,OAAO,CAAC,CAAC;gBACT,OAAO,CAAC,CAAC;aACV,CAAC,CAAA;IACR,CAAC;;AA1BH,gCA2BC;AA1Be,oBAAS,GAAc,IAAI,eAAS,CAAC,sBAAe,CAAC,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { BigintIsh, Currency, Percent, TradeType } from '../core';
|
|
3
|
+
import { Trade } from './entities/trade';
|
|
4
|
+
import { PermitOptions } from './selfPermit';
|
|
5
|
+
import { MethodParameters } from './utils/calldata';
|
|
6
|
+
import { FeeOptions } from './payments';
|
|
7
|
+
/**
|
|
8
|
+
* Options for producing the arguments to send calls to the router.
|
|
9
|
+
*/
|
|
10
|
+
export interface SwapOptions {
|
|
11
|
+
/**
|
|
12
|
+
* How much the execution price is allowed to move unfavorably from the trade execution price.
|
|
13
|
+
*/
|
|
14
|
+
slippageTolerance: Percent;
|
|
15
|
+
/**
|
|
16
|
+
* The account that should receive the output.
|
|
17
|
+
*/
|
|
18
|
+
recipient: string;
|
|
19
|
+
/**
|
|
20
|
+
* When the transaction expires, in epoch seconds.
|
|
21
|
+
*/
|
|
22
|
+
deadline: BigintIsh;
|
|
23
|
+
/**
|
|
24
|
+
* The optional permit parameters for spending the input.
|
|
25
|
+
*/
|
|
26
|
+
inputTokenPermit?: PermitOptions;
|
|
27
|
+
/**
|
|
28
|
+
* The optional price limit for the trade.
|
|
29
|
+
*/
|
|
30
|
+
sqrtPriceLimitX96?: BigintIsh;
|
|
31
|
+
/**
|
|
32
|
+
* Optional information for taking a fee on output.
|
|
33
|
+
*/
|
|
34
|
+
fee?: FeeOptions;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Represents the V3 SwapRouter, and has static methods for helping execute trades.
|
|
38
|
+
*/
|
|
39
|
+
export declare abstract class SwapRouter {
|
|
40
|
+
static INTERFACE: Interface;
|
|
41
|
+
/**
|
|
42
|
+
* Cannot be constructed.
|
|
43
|
+
*/
|
|
44
|
+
private constructor();
|
|
45
|
+
/**
|
|
46
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
47
|
+
* @param trade to produce call parameters for
|
|
48
|
+
* @param options options for the call parameters
|
|
49
|
+
*/
|
|
50
|
+
static swapCallParameters(trades: Trade<Currency, Currency, TradeType> | Trade<Currency, Currency, TradeType>[], options: SwapOptions): MethodParameters;
|
|
51
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SwapRouter = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const core_1 = require("../core");
|
|
9
|
+
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
10
|
+
const constants_1 = require("./constants");
|
|
11
|
+
const selfPermit_1 = require("./selfPermit");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const calldata_1 = require("./utils/calldata");
|
|
14
|
+
const abis_1 = require("./abis");
|
|
15
|
+
const multicall_1 = require("./multicall");
|
|
16
|
+
const payments_1 = require("./payments");
|
|
17
|
+
/**
|
|
18
|
+
* Represents the V3 SwapRouter, and has static methods for helping execute trades.
|
|
19
|
+
*/
|
|
20
|
+
class SwapRouter {
|
|
21
|
+
/**
|
|
22
|
+
* Cannot be constructed.
|
|
23
|
+
*/
|
|
24
|
+
constructor() { }
|
|
25
|
+
/**
|
|
26
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
27
|
+
* @param trade to produce call parameters for
|
|
28
|
+
* @param options options for the call parameters
|
|
29
|
+
*/
|
|
30
|
+
static swapCallParameters(trades, options) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
if (!Array.isArray(trades)) {
|
|
33
|
+
trades = [trades];
|
|
34
|
+
}
|
|
35
|
+
const sampleTrade = trades[0];
|
|
36
|
+
const tokenIn = sampleTrade.inputAmount.currency.wrapped;
|
|
37
|
+
const tokenOut = sampleTrade.outputAmount.currency.wrapped;
|
|
38
|
+
// All trades should have the same starting and ending token.
|
|
39
|
+
(0, tiny_invariant_1.default)(trades.every(trade => trade.inputAmount.currency.wrapped.equals(tokenIn)), 'TOKEN_IN_DIFF');
|
|
40
|
+
(0, tiny_invariant_1.default)(trades.every(trade => trade.outputAmount.currency.wrapped.equals(tokenOut)), 'TOKEN_OUT_DIFF');
|
|
41
|
+
const calldatas = [];
|
|
42
|
+
const ZERO_IN = core_1.CurrencyAmount.fromRawAmount(trades[0].inputAmount.currency, 0);
|
|
43
|
+
const ZERO_OUT = core_1.CurrencyAmount.fromRawAmount(trades[0].outputAmount.currency, 0);
|
|
44
|
+
const totalAmountOut = trades.reduce((sum, trade) => sum.add(trade.minimumAmountOut(options.slippageTolerance)), ZERO_OUT);
|
|
45
|
+
// flag for whether a refund needs to happen
|
|
46
|
+
const mustRefund = sampleTrade.inputAmount.currency.isNative && sampleTrade.tradeType === core_1.TradeType.EXACT_OUTPUT;
|
|
47
|
+
const inputIsNative = sampleTrade.inputAmount.currency.isNative;
|
|
48
|
+
// flags for whether funds should be send first to the router
|
|
49
|
+
const outputIsNative = sampleTrade.outputAmount.currency.isNative;
|
|
50
|
+
const routerMustCustody = outputIsNative || !!options.fee;
|
|
51
|
+
const totalValue = inputIsNative
|
|
52
|
+
? trades.reduce((sum, trade) => sum.add(trade.maximumAmountIn(options.slippageTolerance)), ZERO_IN)
|
|
53
|
+
: ZERO_IN;
|
|
54
|
+
// encode permit if necessary
|
|
55
|
+
if (options.inputTokenPermit) {
|
|
56
|
+
(0, tiny_invariant_1.default)(sampleTrade.inputAmount.currency.isToken, 'NON_TOKEN_PERMIT');
|
|
57
|
+
calldatas.push(selfPermit_1.SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit));
|
|
58
|
+
}
|
|
59
|
+
const recipient = (0, core_1.validateAndParseAddress)(options.recipient);
|
|
60
|
+
const deadline = (0, calldata_1.toHex)(options.deadline);
|
|
61
|
+
for (const trade of trades) {
|
|
62
|
+
for (const { route, inputAmount, outputAmount } of trade.swaps) {
|
|
63
|
+
const amountIn = (0, calldata_1.toHex)(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
|
|
64
|
+
const amountOut = (0, calldata_1.toHex)(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
|
|
65
|
+
// flag for whether the trade is single hop or not
|
|
66
|
+
const singleHop = route.pools.length === 1;
|
|
67
|
+
if (singleHop) {
|
|
68
|
+
if (trade.tradeType === core_1.TradeType.EXACT_INPUT) {
|
|
69
|
+
const exactInputSingleParams = {
|
|
70
|
+
tokenIn: route.tokenPath[0].address,
|
|
71
|
+
tokenOut: route.tokenPath[1].address,
|
|
72
|
+
fee: route.pools[0].fee,
|
|
73
|
+
recipient: routerMustCustody ? constants_1.ADDRESS_ZERO : recipient,
|
|
74
|
+
deadline,
|
|
75
|
+
amountIn,
|
|
76
|
+
amountOutMinimum: amountOut,
|
|
77
|
+
sqrtPriceLimitX96: (0, calldata_1.toHex)((_a = options.sqrtPriceLimitX96) !== null && _a !== void 0 ? _a : 0)
|
|
78
|
+
};
|
|
79
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const exactOutputSingleParams = {
|
|
83
|
+
tokenIn: route.tokenPath[0].address,
|
|
84
|
+
tokenOut: route.tokenPath[1].address,
|
|
85
|
+
fee: route.pools[0].fee,
|
|
86
|
+
recipient: routerMustCustody ? constants_1.ADDRESS_ZERO : recipient,
|
|
87
|
+
deadline,
|
|
88
|
+
amountOut,
|
|
89
|
+
amountInMaximum: amountIn,
|
|
90
|
+
sqrtPriceLimitX96: (0, calldata_1.toHex)((_b = options.sqrtPriceLimitX96) !== null && _b !== void 0 ? _b : 0)
|
|
91
|
+
};
|
|
92
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutputSingle', [exactOutputSingleParams]));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
(0, tiny_invariant_1.default)(options.sqrtPriceLimitX96 === undefined, 'MULTIHOP_PRICE_LIMIT');
|
|
97
|
+
const path = (0, utils_1.encodeRouteToPath)(route, trade.tradeType === core_1.TradeType.EXACT_OUTPUT);
|
|
98
|
+
if (trade.tradeType === core_1.TradeType.EXACT_INPUT) {
|
|
99
|
+
const exactInputParams = {
|
|
100
|
+
path,
|
|
101
|
+
recipient: routerMustCustody ? constants_1.ADDRESS_ZERO : recipient,
|
|
102
|
+
deadline,
|
|
103
|
+
amountIn,
|
|
104
|
+
amountOutMinimum: amountOut
|
|
105
|
+
};
|
|
106
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [exactInputParams]));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const exactOutputParams = {
|
|
110
|
+
path,
|
|
111
|
+
recipient: routerMustCustody ? constants_1.ADDRESS_ZERO : recipient,
|
|
112
|
+
deadline,
|
|
113
|
+
amountOut,
|
|
114
|
+
amountInMaximum: amountIn
|
|
115
|
+
};
|
|
116
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutput', [exactOutputParams]));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// unwrap
|
|
122
|
+
if (routerMustCustody) {
|
|
123
|
+
if (!!options.fee) {
|
|
124
|
+
if (outputIsNative) {
|
|
125
|
+
calldatas.push(payments_1.Payments.encodeUnwrapWETH9(totalAmountOut.quotient, recipient, options.fee));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
calldatas.push(payments_1.Payments.encodeSweepToken(sampleTrade.outputAmount.currency.wrapped, totalAmountOut.quotient, recipient, options.fee));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
calldatas.push(payments_1.Payments.encodeUnwrapWETH9(totalAmountOut.quotient, recipient));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// refund
|
|
136
|
+
if (mustRefund) {
|
|
137
|
+
calldatas.push(payments_1.Payments.encodeRefundETH());
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
calldata: multicall_1.Multicall.encodeMulticall(calldatas),
|
|
141
|
+
value: (0, calldata_1.toHex)(totalValue.quotient)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.SwapRouter = SwapRouter;
|
|
146
|
+
SwapRouter.INTERFACE = new abi_1.Interface(abis_1.SWAP_ROUTER_ABI);
|
|
147
|
+
//# sourceMappingURL=swapRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swapRouter.js","sourceRoot":"","sources":["../../src/v3/swapRouter.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA8C;AAC9C,kCAOgB;AAChB,oEAAsC;AAEtC,2CAA0C;AAC1C,6CAA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
|
|
4
|
+
*/
|
|
5
|
+
export interface MethodParameters {
|
|
6
|
+
/**
|
|
7
|
+
* The hex encoded calldata to perform the given operation
|
|
8
|
+
*/
|
|
9
|
+
calldata: string;
|
|
10
|
+
/**
|
|
11
|
+
* The amount of ether (wei) to send in hex.
|
|
12
|
+
*/
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Converts a big int to a hex string
|
|
17
|
+
* @param bigintIsh
|
|
18
|
+
* @returns The hex encoded calldata
|
|
19
|
+
*/
|
|
20
|
+
export declare function toHex(bigintIsh: BigintIsh): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.toHex = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
/**
|
|
9
|
+
* Converts a big int to a hex string
|
|
10
|
+
* @param bigintIsh
|
|
11
|
+
* @returns The hex encoded calldata
|
|
12
|
+
*/
|
|
13
|
+
function toHex(bigintIsh) {
|
|
14
|
+
const bigInt = jsbi_1.default.BigInt(bigintIsh);
|
|
15
|
+
let hex = bigInt.toString(16);
|
|
16
|
+
if (hex.length % 2 !== 0) {
|
|
17
|
+
hex = `0${hex}`;
|
|
18
|
+
}
|
|
19
|
+
return `0x${hex}`;
|
|
20
|
+
}
|
|
21
|
+
exports.toHex = toHex;
|
|
22
|
+
//# sourceMappingURL=calldata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calldata.js","sourceRoot":"","sources":["../../../src/v3/utils/calldata.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AAgBvB;;;;GAIG;AACH,SAAgB,KAAK,CAAC,SAAoB;IACxC,MAAM,MAAM,GAAG,cAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IACrC,IAAI,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC7B,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,GAAG,GAAG,IAAI,GAAG,EAAE,CAAA;KAChB;IACD,OAAO,KAAK,GAAG,EAAE,CAAA;AACnB,CAAC;AAPD,sBAOC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Token } from '../../core';
|
|
2
|
+
import { FeeAmount } from '../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Computes a pool address
|
|
5
|
+
* @param factoryAddress The Synthra V3 factory address
|
|
6
|
+
* @param tokenA The first token of the pair, irrespective of sort order
|
|
7
|
+
* @param tokenB The second token of the pair, irrespective of sort order
|
|
8
|
+
* @param fee The fee tier of the pool
|
|
9
|
+
* @param initCodeHashManualOverride Override the init code hash used to compute the pool address if necessary
|
|
10
|
+
* @returns The pool address
|
|
11
|
+
*/
|
|
12
|
+
export declare function computePoolAddress({ factoryAddress, tokenA, tokenB, fee, initCodeHashManualOverride }: {
|
|
13
|
+
factoryAddress: string;
|
|
14
|
+
tokenA: Token;
|
|
15
|
+
tokenB: Token;
|
|
16
|
+
fee: FeeAmount;
|
|
17
|
+
initCodeHashManualOverride?: string;
|
|
18
|
+
}): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computePoolAddress = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const address_1 = require("@ethersproject/address");
|
|
6
|
+
const solidity_1 = require("@ethersproject/solidity");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
/**
|
|
9
|
+
* Computes a pool address
|
|
10
|
+
* @param factoryAddress The Synthra V3 factory address
|
|
11
|
+
* @param tokenA The first token of the pair, irrespective of sort order
|
|
12
|
+
* @param tokenB The second token of the pair, irrespective of sort order
|
|
13
|
+
* @param fee The fee tier of the pool
|
|
14
|
+
* @param initCodeHashManualOverride Override the init code hash used to compute the pool address if necessary
|
|
15
|
+
* @returns The pool address
|
|
16
|
+
*/
|
|
17
|
+
function computePoolAddress({ factoryAddress, tokenA, tokenB, fee, initCodeHashManualOverride }) {
|
|
18
|
+
const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA]; // does safety checks
|
|
19
|
+
return (0, address_1.getCreate2Address)(factoryAddress, (0, solidity_1.keccak256)(['bytes'], [abi_1.defaultAbiCoder.encode(['address', 'address', 'uint24'], [token0.address, token1.address, fee])]), initCodeHashManualOverride !== null && initCodeHashManualOverride !== void 0 ? initCodeHashManualOverride : constants_1.POOL_INIT_CODE_HASH);
|
|
20
|
+
}
|
|
21
|
+
exports.computePoolAddress = computePoolAddress;
|
|
22
|
+
//# sourceMappingURL=computePoolAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computePoolAddress.js","sourceRoot":"","sources":["../../../src/v3/utils/computePoolAddress.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AACpD,oDAA0D;AAC1D,sDAAmD;AAEnD,4CAA6D;AAE7D;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAAC,EACjC,cAAc,EACd,MAAM,EACN,MAAM,EACN,GAAG,EACH,0BAA0B,EAO3B;IACC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA,CAAC,qBAAqB;IAC/G,OAAO,IAAA,2BAAiB,EACtB,cAAc,EACd,IAAA,oBAAS,EACP,CAAC,OAAO,CAAC,EACT,CAAC,qBAAe,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,CAClG,EACD,0BAA0B,aAA1B,0BAA0B,cAA1B,0BAA0B,GAAI,+BAAmB,CAClD,CAAA;AACH,CAAC;AAtBD,gDAsBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Currency } from '../../core';
|
|
2
|
+
import { Route } from '../entities/route';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a route to a hex encoded path
|
|
5
|
+
* @param route the v3 path to convert to an encoded path
|
|
6
|
+
* @param exactOutput whether the route should be encoded in reverse, for making exact output swaps
|
|
7
|
+
*/
|
|
8
|
+
export declare function encodeRouteToPath(route: Route<Currency, Currency>, exactOutput: boolean): string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeRouteToPath = void 0;
|
|
4
|
+
const solidity_1 = require("@ethersproject/solidity");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a route to a hex encoded path
|
|
7
|
+
* @param route the v3 path to convert to an encoded path
|
|
8
|
+
* @param exactOutput whether the route should be encoded in reverse, for making exact output swaps
|
|
9
|
+
*/
|
|
10
|
+
function encodeRouteToPath(route, exactOutput) {
|
|
11
|
+
const firstInputToken = route.input.wrapped;
|
|
12
|
+
const { path, types } = route.pools.reduce(({ inputToken, path, types }, pool, index) => {
|
|
13
|
+
const outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
|
|
14
|
+
if (index === 0) {
|
|
15
|
+
return {
|
|
16
|
+
inputToken: outputToken,
|
|
17
|
+
types: ['address', 'uint24', 'address'],
|
|
18
|
+
path: [inputToken.address, pool.fee, outputToken.address]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return {
|
|
23
|
+
inputToken: outputToken,
|
|
24
|
+
types: [...types, 'uint24', 'address'],
|
|
25
|
+
path: [...path, pool.fee, outputToken.address]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}, { inputToken: firstInputToken, path: [], types: [] });
|
|
29
|
+
return exactOutput ? (0, solidity_1.pack)(types.reverse(), path.reverse()) : (0, solidity_1.pack)(types, path);
|
|
30
|
+
}
|
|
31
|
+
exports.encodeRouteToPath = encodeRouteToPath;
|
|
32
|
+
//# sourceMappingURL=encodeRouteToPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeRouteToPath.js","sourceRoot":"","sources":["../../../src/v3/utils/encodeRouteToPath.ts"],"names":[],"mappings":";;;AAAA,sDAA8C;AAK9C;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,KAAgC,EAAE,WAAoB;IACtF,MAAM,eAAe,GAAU,KAAK,CAAC,KAAK,CAAC,OAAO,CAAA;IAElD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CACxC,CACE,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAqE,EAC9F,IAAU,EACV,KAAK,EAC8D,EAAE;QACrE,MAAM,WAAW,GAAU,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAA;QACrF,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,OAAO;gBACL,UAAU,EAAE,WAAW;gBACvB,KAAK,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,SAAS,CAAC;gBACvC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC;aAC1D,CAAA;SACF;aAAM;YACL,OAAO;gBACL,UAAU,EAAE,WAAW;gBACvB,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC;gBACtC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC;aAC/C,CAAA;SACF;IACH,CAAC,EACD,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CACrD,CAAA;IAED,OAAO,WAAW,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,KAAK,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAA,eAAI,EAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAChF,CAAC;AA5BD,8CA4BC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
import { BigintIsh } from '../../core';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
|
|
5
|
+
* @param amount1 The numerator amount i.e., the amount of token1
|
|
6
|
+
* @param amount0 The denominator amount i.e., the amount of token0
|
|
7
|
+
* @returns The sqrt ratio
|
|
8
|
+
*/
|
|
9
|
+
export declare function encodeSqrtRatioX96(amount1: BigintIsh, amount0: BigintIsh): JSBI;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.encodeSqrtRatioX96 = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
const core_1 = require("../../core");
|
|
9
|
+
/**
|
|
10
|
+
* Returns the sqrt ratio as a Q64.96 corresponding to a given ratio of amount1 and amount0
|
|
11
|
+
* @param amount1 The numerator amount i.e., the amount of token1
|
|
12
|
+
* @param amount0 The denominator amount i.e., the amount of token0
|
|
13
|
+
* @returns The sqrt ratio
|
|
14
|
+
*/
|
|
15
|
+
function encodeSqrtRatioX96(amount1, amount0) {
|
|
16
|
+
const numerator = jsbi_1.default.leftShift(jsbi_1.default.BigInt(amount1), jsbi_1.default.BigInt(192));
|
|
17
|
+
const denominator = jsbi_1.default.BigInt(amount0);
|
|
18
|
+
const ratioX192 = jsbi_1.default.divide(numerator, denominator);
|
|
19
|
+
return (0, core_1.sqrt)(ratioX192);
|
|
20
|
+
}
|
|
21
|
+
exports.encodeSqrtRatioX96 = encodeSqrtRatioX96;
|
|
22
|
+
//# sourceMappingURL=encodeSqrtRatioX96.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodeSqrtRatioX96.js","sourceRoot":"","sources":["../../../src/v3/utils/encodeSqrtRatioX96.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,qCAA4C;AAE5C;;;;;GAKG;AAEH,SAAgB,kBAAkB,CAAC,OAAkB,EAAE,OAAkB;IACvE,MAAM,SAAS,GAAG,cAAI,CAAC,SAAS,CAAC,cAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,cAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IACxE,MAAM,WAAW,GAAG,cAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACxC,MAAM,SAAS,GAAG,cAAI,CAAC,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;IACrD,OAAO,IAAA,WAAI,EAAC,SAAS,CAAC,CAAA;AACxB,CAAC;AALD,gDAKC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FullMath = void 0;
|
|
7
|
+
const jsbi_1 = __importDefault(require("jsbi"));
|
|
8
|
+
const internalConstants_1 = require("../internalConstants");
|
|
9
|
+
class FullMath {
|
|
10
|
+
/**
|
|
11
|
+
* Cannot be constructed.
|
|
12
|
+
*/
|
|
13
|
+
constructor() { }
|
|
14
|
+
static mulDivRoundingUp(a, b, denominator) {
|
|
15
|
+
const product = jsbi_1.default.multiply(a, b);
|
|
16
|
+
let result = jsbi_1.default.divide(product, denominator);
|
|
17
|
+
if (jsbi_1.default.notEqual(jsbi_1.default.remainder(product, denominator), internalConstants_1.ZERO))
|
|
18
|
+
result = jsbi_1.default.add(result, internalConstants_1.ONE);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.FullMath = FullMath;
|
|
23
|
+
//# sourceMappingURL=fullMath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fullMath.js","sourceRoot":"","sources":["../../../src/v3/utils/fullMath.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,4DAAgD;AAEhD,MAAsB,QAAQ;IAC5B;;OAEG;IACH,gBAAuB,CAAC;IAEjB,MAAM,CAAC,gBAAgB,CAAC,CAAO,EAAE,CAAO,EAAE,WAAiB;QAChE,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QACnC,IAAI,MAAM,GAAG,cAAI,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QAC9C,IAAI,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,wBAAI,CAAC;YAAE,MAAM,GAAG,cAAI,CAAC,GAAG,CAAC,MAAM,EAAE,uBAAG,CAAC,CAAA;QAC7F,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAZD,4BAYC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './calldata';
|
|
2
|
+
export * from './computePoolAddress';
|
|
3
|
+
export * from './encodeRouteToPath';
|
|
4
|
+
export * from './encodeSqrtRatioX96';
|
|
5
|
+
export * from './fullMath';
|
|
6
|
+
export * from './isSorted';
|
|
7
|
+
export * from './liquidityMath';
|
|
8
|
+
export * from './maxLiquidityForAmounts';
|
|
9
|
+
export * from './mostSignificantBit';
|
|
10
|
+
export * from './nearestUsableTick';
|
|
11
|
+
export * from './position';
|
|
12
|
+
export * from './priceTickConversions';
|
|
13
|
+
export * from './sqrtPriceMath';
|
|
14
|
+
export * from './swapMath';
|
|
15
|
+
export * from './tickLibrary';
|
|
16
|
+
export * from './tickList';
|
|
17
|
+
export * from './tickMath';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./calldata"), exports);
|
|
18
|
+
__exportStar(require("./computePoolAddress"), exports);
|
|
19
|
+
__exportStar(require("./encodeRouteToPath"), exports);
|
|
20
|
+
__exportStar(require("./encodeSqrtRatioX96"), exports);
|
|
21
|
+
__exportStar(require("./fullMath"), exports);
|
|
22
|
+
__exportStar(require("./isSorted"), exports);
|
|
23
|
+
__exportStar(require("./liquidityMath"), exports);
|
|
24
|
+
__exportStar(require("./maxLiquidityForAmounts"), exports);
|
|
25
|
+
__exportStar(require("./mostSignificantBit"), exports);
|
|
26
|
+
__exportStar(require("./nearestUsableTick"), exports);
|
|
27
|
+
__exportStar(require("./position"), exports);
|
|
28
|
+
__exportStar(require("./priceTickConversions"), exports);
|
|
29
|
+
__exportStar(require("./sqrtPriceMath"), exports);
|
|
30
|
+
__exportStar(require("./swapMath"), exports);
|
|
31
|
+
__exportStar(require("./tickLibrary"), exports);
|
|
32
|
+
__exportStar(require("./tickList"), exports);
|
|
33
|
+
__exportStar(require("./tickMath"), exports);
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,uDAAoC;AACpC,sDAAmC;AACnC,uDAAoC;AACpC,6CAA0B;AAC1B,6CAA0B;AAC1B,kDAA+B;AAC/B,2DAAwC;AACxC,uDAAoC;AACpC,sDAAmC;AACnC,6CAA0B;AAC1B,yDAAsC;AACtC,kDAA+B;AAC/B,6CAA0B;AAC1B,gDAA6B;AAC7B,6CAA0B;AAC1B,6CAA0B"}
|