@centurion_project/v3-sdk 3.30.0-ctn.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/cjs/src/constants.d.ts +23 -0
- package/dist/cjs/src/constants.js +44 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/cjs/src/entities/index.d.ts +7 -0
- package/dist/cjs/src/entities/index.js +11 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/cjs/src/entities/pool.d.ts +81 -0
- package/dist/cjs/src/entities/pool.js +142 -0
- package/dist/cjs/src/entities/pool.js.map +1 -0
- package/dist/cjs/src/entities/position.d.ts +131 -0
- package/dist/cjs/src/entities/position.js +248 -0
- package/dist/cjs/src/entities/position.js.map +1 -0
- package/dist/cjs/src/entities/route.d.ts +26 -0
- package/dist/cjs/src/entities/route.js +75 -0
- package/dist/cjs/src/entities/route.js.map +1 -0
- package/dist/cjs/src/entities/tick.d.ts +13 -0
- package/dist/cjs/src/entities/tick.js +17 -0
- package/dist/cjs/src/entities/tick.js.map +1 -0
- package/dist/cjs/src/entities/tickDataProvider.d.ts +31 -0
- package/dist/cjs/src/entities/tickDataProvider.js +18 -0
- package/dist/cjs/src/entities/tickDataProvider.js.map +1 -0
- package/dist/cjs/src/entities/tickListDataProvider.d.ts +15 -0
- package/dist/cjs/src/entities/tickListDataProvider.js +23 -0
- package/dist/cjs/src/entities/tickListDataProvider.js.map +1 -0
- package/dist/cjs/src/entities/trade.d.ts +220 -0
- package/dist/cjs/src/entities/trade.js +440 -0
- package/dist/cjs/src/entities/trade.js.map +1 -0
- package/dist/cjs/src/index.d.ts +10 -0
- package/dist/cjs/src/index.js +14 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/internalConstants.d.ts +6 -0
- package/dist/cjs/src/internalConstants.js +13 -0
- package/dist/cjs/src/internalConstants.js.map +1 -0
- package/dist/cjs/src/multicall.d.ts +10 -0
- package/dist/cjs/src/multicall.js +24 -0
- package/dist/cjs/src/multicall.js.map +1 -0
- package/dist/cjs/src/nonfungiblePositionManager.d.ts +159 -0
- package/dist/cjs/src/nonfungiblePositionManager.js +250 -0
- package/dist/cjs/src/nonfungiblePositionManager.js.map +1 -0
- package/dist/cjs/src/payments.d.ts +24 -0
- package/dist/cjs/src/payments.js +56 -0
- package/dist/cjs/src/payments.js.map +1 -0
- package/dist/cjs/src/quoter.d.ts +37 -0
- package/dist/cjs/src/quoter.js +69 -0
- package/dist/cjs/src/quoter.js.map +1 -0
- package/dist/cjs/src/selfPermit.d.ts +25 -0
- package/dist/cjs/src/selfPermit.js +38 -0
- package/dist/cjs/src/selfPermit.js.map +1 -0
- package/dist/cjs/src/staker.d.ts +101 -0
- package/dist/cjs/src/staker.js +129 -0
- package/dist/cjs/src/staker.js.map +1 -0
- package/dist/cjs/src/swapRouter.d.ts +51 -0
- package/dist/cjs/src/swapRouter.js +145 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/cjs/src/utils/calldata.d.ts +20 -0
- package/dist/cjs/src/utils/calldata.js +20 -0
- package/dist/cjs/src/utils/calldata.js.map +1 -0
- package/dist/cjs/src/utils/computePoolAddress.d.ts +20 -0
- package/dist/cjs/src/utils/computePoolAddress.js +33 -0
- package/dist/cjs/src/utils/computePoolAddress.js.map +1 -0
- package/dist/cjs/src/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/cjs/src/utils/encodeRouteToPath.js +32 -0
- package/dist/cjs/src/utils/encodeRouteToPath.js.map +1 -0
- package/dist/cjs/src/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/cjs/src/utils/encodeSqrtRatioX96.js +20 -0
- package/dist/cjs/src/utils/encodeSqrtRatioX96.js.map +1 -0
- package/dist/cjs/src/utils/fullMath.d.ts +8 -0
- package/dist/cjs/src/utils/fullMath.js +21 -0
- package/dist/cjs/src/utils/fullMath.js.map +1 -0
- package/dist/cjs/src/utils/index.d.ts +18 -0
- package/dist/cjs/src/utils/index.js +22 -0
- package/dist/cjs/src/utils/index.js.map +1 -0
- package/dist/cjs/src/utils/isSorted.d.ts +7 -0
- package/dist/cjs/src/utils/isSorted.js +19 -0
- package/dist/cjs/src/utils/isSorted.js.map +1 -0
- package/dist/cjs/src/utils/liquidityMath.d.ts +8 -0
- package/dist/cjs/src/utils/liquidityMath.js +22 -0
- package/dist/cjs/src/utils/liquidityMath.js.map +1 -0
- package/dist/cjs/src/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/cjs/src/utils/maxLiquidityForAmounts.js +87 -0
- package/dist/cjs/src/utils/maxLiquidityForAmounts.js.map +1 -0
- package/dist/cjs/src/utils/mostSignificantBit.d.ts +2 -0
- package/dist/cjs/src/utils/mostSignificantBit.js +27 -0
- package/dist/cjs/src/utils/mostSignificantBit.js.map +1 -0
- package/dist/cjs/src/utils/nearestUsableTick.d.ts +6 -0
- package/dist/cjs/src/utils/nearestUsableTick.js +25 -0
- package/dist/cjs/src/utils/nearestUsableTick.js.map +1 -0
- package/dist/cjs/src/utils/position.d.ts +8 -0
- package/dist/cjs/src/utils/position.js +21 -0
- package/dist/cjs/src/utils/position.js.map +1 -0
- package/dist/cjs/src/utils/priceTickConversions.d.ts +15 -0
- package/dist/cjs/src/utils/priceTickConversions.js +50 -0
- package/dist/cjs/src/utils/priceTickConversions.js.map +1 -0
- package/dist/cjs/src/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/cjs/src/utils/sqrtPriceMath.js +95 -0
- package/dist/cjs/src/utils/sqrtPriceMath.js.map +1 -0
- package/dist/cjs/src/utils/swapMath.d.ts +9 -0
- package/dist/cjs/src/utils/swapMath.js +78 -0
- package/dist/cjs/src/utils/swapMath.js.map +1 -0
- package/dist/cjs/src/utils/tickLibrary.d.ts +14 -0
- package/dist/cjs/src/utils/tickLibrary.js +51 -0
- package/dist/cjs/src/utils/tickLibrary.js.map +1 -0
- package/dist/cjs/src/utils/tickList.d.ts +23 -0
- package/dist/cjs/src/utils/tickList.js +108 -0
- package/dist/cjs/src/utils/tickList.js.map +1 -0
- package/dist/cjs/src/utils/tickMath.d.ts +34 -0
- package/dist/cjs/src/utils/tickMath.js +125 -0
- package/dist/cjs/src/utils/tickMath.js.map +1 -0
- package/dist/cjs/src/utils/v3swap.d.ts +8 -0
- package/dist/cjs/src/utils/v3swap.js +85 -0
- package/dist/cjs/src/utils/v3swap.js.map +1 -0
- package/dist/esm/src/constants.d.ts +23 -0
- package/dist/esm/src/constants.js +40 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +7 -0
- package/dist/esm/src/entities/index.js +8 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/entities/pool.d.ts +81 -0
- package/dist/esm/src/entities/pool.js +137 -0
- package/dist/esm/src/entities/pool.js.map +1 -0
- package/dist/esm/src/entities/position.d.ts +131 -0
- package/dist/esm/src/entities/position.js +243 -0
- package/dist/esm/src/entities/position.js.map +1 -0
- package/dist/esm/src/entities/route.d.ts +26 -0
- package/dist/esm/src/entities/route.js +70 -0
- package/dist/esm/src/entities/route.js.map +1 -0
- package/dist/esm/src/entities/tick.d.ts +13 -0
- package/dist/esm/src/entities/tick.js +12 -0
- package/dist/esm/src/entities/tick.js.map +1 -0
- package/dist/esm/src/entities/tickDataProvider.d.ts +31 -0
- package/dist/esm/src/entities/tickDataProvider.js +14 -0
- package/dist/esm/src/entities/tickDataProvider.js.map +1 -0
- package/dist/esm/src/entities/tickListDataProvider.d.ts +15 -0
- package/dist/esm/src/entities/tickListDataProvider.js +19 -0
- package/dist/esm/src/entities/tickListDataProvider.js.map +1 -0
- package/dist/esm/src/entities/trade.d.ts +220 -0
- package/dist/esm/src/entities/trade.js +434 -0
- package/dist/esm/src/entities/trade.js.map +1 -0
- package/dist/esm/src/index.d.ts +10 -0
- package/dist/esm/src/index.js +11 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/internalConstants.d.ts +6 -0
- package/dist/esm/src/internalConstants.js +9 -0
- package/dist/esm/src/internalConstants.js.map +1 -0
- package/dist/esm/src/multicall.d.ts +10 -0
- package/dist/esm/src/multicall.js +19 -0
- package/dist/esm/src/multicall.js.map +1 -0
- package/dist/esm/src/nonfungiblePositionManager.d.ts +159 -0
- package/dist/esm/src/nonfungiblePositionManager.js +245 -0
- package/dist/esm/src/nonfungiblePositionManager.js.map +1 -0
- package/dist/esm/src/payments.d.ts +24 -0
- package/dist/esm/src/payments.js +51 -0
- package/dist/esm/src/payments.js.map +1 -0
- package/dist/esm/src/quoter.d.ts +37 -0
- package/dist/esm/src/quoter.js +64 -0
- package/dist/esm/src/quoter.js.map +1 -0
- package/dist/esm/src/selfPermit.d.ts +25 -0
- package/dist/esm/src/selfPermit.js +33 -0
- package/dist/esm/src/selfPermit.js.map +1 -0
- package/dist/esm/src/staker.d.ts +101 -0
- package/dist/esm/src/staker.js +124 -0
- package/dist/esm/src/staker.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +51 -0
- package/dist/esm/src/swapRouter.js +140 -0
- package/dist/esm/src/swapRouter.js.map +1 -0
- package/dist/esm/src/utils/calldata.d.ts +20 -0
- package/dist/esm/src/utils/calldata.js +15 -0
- package/dist/esm/src/utils/calldata.js.map +1 -0
- package/dist/esm/src/utils/computePoolAddress.d.ts +20 -0
- package/dist/esm/src/utils/computePoolAddress.js +29 -0
- package/dist/esm/src/utils/computePoolAddress.js.map +1 -0
- package/dist/esm/src/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/esm/src/utils/encodeRouteToPath.js +28 -0
- package/dist/esm/src/utils/encodeRouteToPath.js.map +1 -0
- package/dist/esm/src/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/esm/src/utils/encodeSqrtRatioX96.js +15 -0
- package/dist/esm/src/utils/encodeSqrtRatioX96.js.map +1 -0
- package/dist/esm/src/utils/fullMath.d.ts +8 -0
- package/dist/esm/src/utils/fullMath.js +16 -0
- package/dist/esm/src/utils/fullMath.js.map +1 -0
- package/dist/esm/src/utils/index.d.ts +18 -0
- package/dist/esm/src/utils/index.js +19 -0
- package/dist/esm/src/utils/index.js.map +1 -0
- package/dist/esm/src/utils/isSorted.d.ts +7 -0
- package/dist/esm/src/utils/isSorted.js +15 -0
- package/dist/esm/src/utils/isSorted.js.map +1 -0
- package/dist/esm/src/utils/liquidityMath.d.ts +8 -0
- package/dist/esm/src/utils/liquidityMath.js +17 -0
- package/dist/esm/src/utils/liquidityMath.js.map +1 -0
- package/dist/esm/src/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/esm/src/utils/maxLiquidityForAmounts.js +82 -0
- package/dist/esm/src/utils/maxLiquidityForAmounts.js.map +1 -0
- package/dist/esm/src/utils/mostSignificantBit.d.ts +2 -0
- package/dist/esm/src/utils/mostSignificantBit.js +22 -0
- package/dist/esm/src/utils/mostSignificantBit.js.map +1 -0
- package/dist/esm/src/utils/nearestUsableTick.d.ts +6 -0
- package/dist/esm/src/utils/nearestUsableTick.js +20 -0
- package/dist/esm/src/utils/nearestUsableTick.js.map +1 -0
- package/dist/esm/src/utils/position.d.ts +8 -0
- package/dist/esm/src/utils/position.js +16 -0
- package/dist/esm/src/utils/position.js.map +1 -0
- package/dist/esm/src/utils/priceTickConversions.d.ts +15 -0
- package/dist/esm/src/utils/priceTickConversions.js +44 -0
- package/dist/esm/src/utils/priceTickConversions.js.map +1 -0
- package/dist/esm/src/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/esm/src/utils/sqrtPriceMath.js +90 -0
- package/dist/esm/src/utils/sqrtPriceMath.js.map +1 -0
- package/dist/esm/src/utils/swapMath.d.ts +9 -0
- package/dist/esm/src/utils/swapMath.js +73 -0
- package/dist/esm/src/utils/swapMath.js.map +1 -0
- package/dist/esm/src/utils/tickLibrary.d.ts +14 -0
- package/dist/esm/src/utils/tickLibrary.js +45 -0
- package/dist/esm/src/utils/tickLibrary.js.map +1 -0
- package/dist/esm/src/utils/tickList.d.ts +23 -0
- package/dist/esm/src/utils/tickList.js +103 -0
- package/dist/esm/src/utils/tickList.js.map +1 -0
- package/dist/esm/src/utils/tickMath.d.ts +34 -0
- package/dist/esm/src/utils/tickMath.js +120 -0
- package/dist/esm/src/utils/tickMath.js.map +1 -0
- package/dist/esm/src/utils/v3swap.d.ts +8 -0
- package/dist/esm/src/utils/v3swap.js +80 -0
- package/dist/esm/src/utils/v3swap.js.map +1 -0
- package/dist/types/src/constants.d.ts +23 -0
- package/dist/types/src/entities/index.d.ts +7 -0
- package/dist/types/src/entities/pool.d.ts +81 -0
- package/dist/types/src/entities/position.d.ts +131 -0
- package/dist/types/src/entities/route.d.ts +26 -0
- package/dist/types/src/entities/tick.d.ts +13 -0
- package/dist/types/src/entities/tickDataProvider.d.ts +31 -0
- package/dist/types/src/entities/tickListDataProvider.d.ts +15 -0
- package/dist/types/src/entities/trade.d.ts +220 -0
- package/dist/types/src/index.d.ts +10 -0
- package/dist/types/src/internalConstants.d.ts +6 -0
- package/dist/types/src/multicall.d.ts +10 -0
- package/dist/types/src/nonfungiblePositionManager.d.ts +159 -0
- package/dist/types/src/payments.d.ts +24 -0
- package/dist/types/src/quoter.d.ts +37 -0
- package/dist/types/src/selfPermit.d.ts +25 -0
- package/dist/types/src/staker.d.ts +101 -0
- package/dist/types/src/swapRouter.d.ts +51 -0
- package/dist/types/src/utils/calldata.d.ts +20 -0
- package/dist/types/src/utils/computePoolAddress.d.ts +20 -0
- package/dist/types/src/utils/encodeRouteToPath.d.ts +8 -0
- package/dist/types/src/utils/encodeSqrtRatioX96.d.ts +9 -0
- package/dist/types/src/utils/fullMath.d.ts +8 -0
- package/dist/types/src/utils/index.d.ts +18 -0
- package/dist/types/src/utils/isSorted.d.ts +7 -0
- package/dist/types/src/utils/liquidityMath.d.ts +8 -0
- package/dist/types/src/utils/maxLiquidityForAmounts.d.ts +14 -0
- package/dist/types/src/utils/mostSignificantBit.d.ts +2 -0
- package/dist/types/src/utils/nearestUsableTick.d.ts +6 -0
- package/dist/types/src/utils/position.d.ts +8 -0
- package/dist/types/src/utils/priceTickConversions.d.ts +15 -0
- package/dist/types/src/utils/sqrtPriceMath.d.ts +13 -0
- package/dist/types/src/utils/swapMath.d.ts +9 -0
- package/dist/types/src/utils/tickLibrary.d.ts +14 -0
- package/dist/types/src/utils/tickList.d.ts +23 -0
- package/dist/types/src/utils/tickMath.d.ts +34 -0
- package/dist/types/src/utils/v3swap.d.ts +8 -0
- package/package.json +72 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { TradeType } from '@centurion_project/sdk-core';
|
|
3
|
+
import { encodeRouteToPath, toHex } from './utils';
|
|
4
|
+
import IQuoter from '@uniswap/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json';
|
|
5
|
+
import IQuoterV2 from '@uniswap/swap-router-contracts/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json';
|
|
6
|
+
import invariant from 'tiny-invariant';
|
|
7
|
+
/**
|
|
8
|
+
* Represents the Uniswap V3 QuoterV1 contract with a method for returning the formatted
|
|
9
|
+
* calldata needed to call the quoter contract.
|
|
10
|
+
*/
|
|
11
|
+
export class SwapQuoter {
|
|
12
|
+
/**
|
|
13
|
+
* Produces the on-chain method name of the appropriate function within QuoterV2,
|
|
14
|
+
* and the relevant hex encoded parameters.
|
|
15
|
+
* @template TInput The input token, either Ether or an ERC-20
|
|
16
|
+
* @template TOutput The output token, either Ether or an ERC-20
|
|
17
|
+
* @param route The swap route, a list of pools through which a swap can occur
|
|
18
|
+
* @param amount The amount of the quote, either an amount in, or an amount out
|
|
19
|
+
* @param tradeType The trade type, either exact input or exact output
|
|
20
|
+
* @param options The optional params including price limit and Quoter contract switch
|
|
21
|
+
* @returns The formatted calldata
|
|
22
|
+
*/
|
|
23
|
+
static quoteCallParameters(route, amount, tradeType, options = {}) {
|
|
24
|
+
var _a;
|
|
25
|
+
const singleHop = route.pools.length === 1;
|
|
26
|
+
const quoteAmount = toHex(amount.quotient);
|
|
27
|
+
let calldata;
|
|
28
|
+
const swapInterface = options.useQuoterV2 ? this.V2INTERFACE : this.V1INTERFACE;
|
|
29
|
+
if (singleHop) {
|
|
30
|
+
const baseQuoteParams = {
|
|
31
|
+
tokenIn: route.tokenPath[0].address,
|
|
32
|
+
tokenOut: route.tokenPath[1].address,
|
|
33
|
+
fee: route.pools[0].fee,
|
|
34
|
+
sqrtPriceLimitX96: toHex((_a = options === null || options === void 0 ? void 0 : options.sqrtPriceLimitX96) !== null && _a !== void 0 ? _a : 0),
|
|
35
|
+
};
|
|
36
|
+
const v2QuoteParams = {
|
|
37
|
+
...baseQuoteParams,
|
|
38
|
+
...(tradeType === TradeType.EXACT_INPUT ? { amountIn: quoteAmount } : { amount: quoteAmount }),
|
|
39
|
+
};
|
|
40
|
+
const v1QuoteParams = [
|
|
41
|
+
baseQuoteParams.tokenIn,
|
|
42
|
+
baseQuoteParams.tokenOut,
|
|
43
|
+
baseQuoteParams.fee,
|
|
44
|
+
quoteAmount,
|
|
45
|
+
baseQuoteParams.sqrtPriceLimitX96,
|
|
46
|
+
];
|
|
47
|
+
const tradeTypeFunctionName = tradeType === TradeType.EXACT_INPUT ? 'quoteExactInputSingle' : 'quoteExactOutputSingle';
|
|
48
|
+
calldata = swapInterface.encodeFunctionData(tradeTypeFunctionName, options.useQuoterV2 ? [v2QuoteParams] : v1QuoteParams);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
invariant((options === null || options === void 0 ? void 0 : options.sqrtPriceLimitX96) === undefined, 'MULTIHOP_PRICE_LIMIT');
|
|
52
|
+
const path = encodeRouteToPath(route, tradeType === TradeType.EXACT_OUTPUT);
|
|
53
|
+
const tradeTypeFunctionName = tradeType === TradeType.EXACT_INPUT ? 'quoteExactInput' : 'quoteExactOutput';
|
|
54
|
+
calldata = swapInterface.encodeFunctionData(tradeTypeFunctionName, [path, quoteAmount]);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
calldata,
|
|
58
|
+
value: toHex(0),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
SwapQuoter.V1INTERFACE = new Interface(IQuoter.abi);
|
|
63
|
+
SwapQuoter.V2INTERFACE = new Interface(IQuoterV2.abi);
|
|
64
|
+
//# sourceMappingURL=quoter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quoter.js","sourceRoot":"","sources":["../../../src/quoter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAuC,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5F,OAAO,EAAE,iBAAiB,EAAoB,KAAK,EAAE,MAAM,SAAS,CAAA;AACpE,OAAO,OAAO,MAAM,uEAAuE,CAAA;AAC3F,OAAO,SAAS,MAAM,oFAAoF,CAAA;AAE1G,OAAO,SAAS,MAAM,gBAAgB,CAAA;AAyBtC;;;GAGG;AACH,MAAM,OAAgB,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,KAAK,CAAC,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,GAAoB;gBACvC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO;gBACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO;gBACpC,GAAG,EAAE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D,OAAO;YACL,QAAQ;YACR,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;SAChB,CAAA;IACH,CAAC;;AA9Da,sBAAW,GAAc,IAAI,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACnD,sBAAW,GAAc,IAAI,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BigintIsh, Token } from '@centurion_project/sdk-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,33 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import ISelfPermit from '@uniswap/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json';
|
|
3
|
+
import { toHex } from './utils';
|
|
4
|
+
function isAllowedPermit(permitOptions) {
|
|
5
|
+
return 'nonce' in permitOptions;
|
|
6
|
+
}
|
|
7
|
+
export class SelfPermit {
|
|
8
|
+
/**
|
|
9
|
+
* Cannot be constructed.
|
|
10
|
+
*/
|
|
11
|
+
constructor() { }
|
|
12
|
+
static encodePermit(token, options) {
|
|
13
|
+
return isAllowedPermit(options)
|
|
14
|
+
? SelfPermit.INTERFACE.encodeFunctionData('selfPermitAllowed', [
|
|
15
|
+
token.address,
|
|
16
|
+
toHex(options.nonce),
|
|
17
|
+
toHex(options.expiry),
|
|
18
|
+
options.v,
|
|
19
|
+
options.r,
|
|
20
|
+
options.s,
|
|
21
|
+
])
|
|
22
|
+
: SelfPermit.INTERFACE.encodeFunctionData('selfPermit', [
|
|
23
|
+
token.address,
|
|
24
|
+
toHex(options.amount),
|
|
25
|
+
toHex(options.deadline),
|
|
26
|
+
options.v,
|
|
27
|
+
options.r,
|
|
28
|
+
options.s,
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
SelfPermit.INTERFACE = new Interface(ISelfPermit.abi);
|
|
33
|
+
//# sourceMappingURL=selfPermit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selfPermit.js","sourceRoot":"","sources":["../../../src/selfPermit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,WAAW,MAAM,uFAAuF,CAAA;AAC/G,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAoB/B,SAAS,eAAe,CAAC,aAA4B;IACnD,OAAO,OAAO,IAAI,aAAa,CAAA;AACjC,CAAC;AAED,MAAM,OAAgB,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,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBACpB,KAAK,CAAC,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,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;gBACrB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACvB,OAAO,CAAC,CAAC;gBACT,OAAO,CAAC,CAAC;gBACT,OAAO,CAAC,CAAC;aACV,CAAC,CAAA;IACR,CAAC;;AAzBa,oBAAS,GAAc,IAAI,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { BigintIsh, Token } from '@centurion_project/sdk-core';
|
|
2
|
+
import { MethodParameters } from './utils/calldata';
|
|
3
|
+
import { Interface } from '@ethersproject/abi';
|
|
4
|
+
import { Pool } from './entities';
|
|
5
|
+
export type FullWithdrawOptions = ClaimOptions & WithdrawOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Represents a unique staking program.
|
|
8
|
+
*/
|
|
9
|
+
export interface IncentiveKey {
|
|
10
|
+
/**
|
|
11
|
+
* The token rewarded for participating in the staking program.
|
|
12
|
+
*/
|
|
13
|
+
rewardToken: Token;
|
|
14
|
+
/**
|
|
15
|
+
* The pool that the staked positions must provide in.
|
|
16
|
+
*/
|
|
17
|
+
pool: Pool;
|
|
18
|
+
/**
|
|
19
|
+
* The time when the incentive program begins.
|
|
20
|
+
*/
|
|
21
|
+
startTime: BigintIsh;
|
|
22
|
+
/**
|
|
23
|
+
* The time that the incentive program ends.
|
|
24
|
+
*/
|
|
25
|
+
endTime: BigintIsh;
|
|
26
|
+
/**
|
|
27
|
+
* The address which receives any remaining reward tokens at `endTime`.
|
|
28
|
+
*/
|
|
29
|
+
refundee: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options to specify when claiming rewards.
|
|
33
|
+
*/
|
|
34
|
+
export interface ClaimOptions {
|
|
35
|
+
/**
|
|
36
|
+
* The id of the NFT
|
|
37
|
+
*/
|
|
38
|
+
tokenId: BigintIsh;
|
|
39
|
+
/**
|
|
40
|
+
* Address to send rewards to.
|
|
41
|
+
*/
|
|
42
|
+
recipient: string;
|
|
43
|
+
/**
|
|
44
|
+
* The amount of `rewardToken` to claim. 0 claims all.
|
|
45
|
+
*/
|
|
46
|
+
amount?: BigintIsh;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Options to specify when withdrawing a position.
|
|
50
|
+
*/
|
|
51
|
+
export interface WithdrawOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Set when withdrawing. The position will be sent to `owner` on withdraw.
|
|
54
|
+
*/
|
|
55
|
+
owner: string;
|
|
56
|
+
/**
|
|
57
|
+
* Set when withdrawing. `data` is passed to `safeTransferFrom` when transferring the position from contract back to owner.
|
|
58
|
+
*/
|
|
59
|
+
data?: string;
|
|
60
|
+
}
|
|
61
|
+
export declare abstract class Staker {
|
|
62
|
+
static INTERFACE: Interface;
|
|
63
|
+
protected constructor();
|
|
64
|
+
private static INCENTIVE_KEY_ABI;
|
|
65
|
+
/**
|
|
66
|
+
* To claim rewards, must unstake and then claim.
|
|
67
|
+
* @param incentiveKey The unique identifier of a staking program.
|
|
68
|
+
* @param options Options for producing the calldata to claim. Can't claim unless you unstake.
|
|
69
|
+
* @returns The calldatas for 'unstakeToken' and 'claimReward'.
|
|
70
|
+
*/
|
|
71
|
+
private static encodeClaim;
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* Note: A `tokenId` can be staked in many programs but to claim rewards and continue the program you must unstake, claim, and then restake.
|
|
75
|
+
* @param incentiveKeys An IncentiveKey or array of IncentiveKeys that `tokenId` is staked in.
|
|
76
|
+
* Input an array of IncentiveKeys to claim rewards for each program.
|
|
77
|
+
* @param options ClaimOptions to specify tokenId, recipient, and amount wanting to collect.
|
|
78
|
+
* Note that you can only specify one amount and one recipient across the various programs if you are collecting from multiple programs at once.
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
static collectRewards(incentiveKeys: IncentiveKey | IncentiveKey[], options: ClaimOptions): MethodParameters;
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param incentiveKeys A list of incentiveKeys to unstake from. Should include all incentiveKeys (unique staking programs) that `options.tokenId` is staked in.
|
|
85
|
+
* @param withdrawOptions Options for producing claim calldata and withdraw calldata. Can't withdraw without unstaking all programs for `tokenId`.
|
|
86
|
+
* @returns Calldata for unstaking, claiming, and withdrawing.
|
|
87
|
+
*/
|
|
88
|
+
static withdrawToken(incentiveKeys: IncentiveKey | IncentiveKey[], withdrawOptions: FullWithdrawOptions): MethodParameters;
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param incentiveKeys A single IncentiveKey or array of IncentiveKeys to be encoded and used in the data parameter in `safeTransferFrom`
|
|
92
|
+
* @returns An IncentiveKey as a string
|
|
93
|
+
*/
|
|
94
|
+
static encodeDeposit(incentiveKeys: IncentiveKey | IncentiveKey[]): string;
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param incentiveKey An `IncentiveKey` which represents a unique staking program.
|
|
98
|
+
* @returns An encoded IncentiveKey to be read by ethers
|
|
99
|
+
*/
|
|
100
|
+
private static _encodeIncentiveKey;
|
|
101
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { validateAndParseAddress } from '@centurion_project/sdk-core';
|
|
2
|
+
import { toHex } from './utils/calldata';
|
|
3
|
+
import { defaultAbiCoder, Interface } from '@ethersproject/abi';
|
|
4
|
+
import IUniswapV3Staker from '@uniswap/v3-staker/artifacts/contracts/UniswapV3Staker.sol/UniswapV3Staker.json';
|
|
5
|
+
import { Pool } from './entities';
|
|
6
|
+
import { Multicall } from './multicall';
|
|
7
|
+
export class Staker {
|
|
8
|
+
constructor() { }
|
|
9
|
+
/**
|
|
10
|
+
* To claim rewards, must unstake and then claim.
|
|
11
|
+
* @param incentiveKey The unique identifier of a staking program.
|
|
12
|
+
* @param options Options for producing the calldata to claim. Can't claim unless you unstake.
|
|
13
|
+
* @returns The calldatas for 'unstakeToken' and 'claimReward'.
|
|
14
|
+
*/
|
|
15
|
+
static encodeClaim(incentiveKey, options) {
|
|
16
|
+
var _a;
|
|
17
|
+
const calldatas = [];
|
|
18
|
+
calldatas.push(Staker.INTERFACE.encodeFunctionData('unstakeToken', [
|
|
19
|
+
this._encodeIncentiveKey(incentiveKey),
|
|
20
|
+
toHex(options.tokenId),
|
|
21
|
+
]));
|
|
22
|
+
const recipient = validateAndParseAddress(options.recipient);
|
|
23
|
+
const amount = (_a = options.amount) !== null && _a !== void 0 ? _a : 0;
|
|
24
|
+
calldatas.push(Staker.INTERFACE.encodeFunctionData('claimReward', [incentiveKey.rewardToken.address, recipient, toHex(amount)]));
|
|
25
|
+
return calldatas;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* Note: A `tokenId` can be staked in many programs but to claim rewards and continue the program you must unstake, claim, and then restake.
|
|
30
|
+
* @param incentiveKeys An IncentiveKey or array of IncentiveKeys that `tokenId` is staked in.
|
|
31
|
+
* Input an array of IncentiveKeys to claim rewards for each program.
|
|
32
|
+
* @param options ClaimOptions to specify tokenId, recipient, and amount wanting to collect.
|
|
33
|
+
* Note that you can only specify one amount and one recipient across the various programs if you are collecting from multiple programs at once.
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
static collectRewards(incentiveKeys, options) {
|
|
37
|
+
incentiveKeys = Array.isArray(incentiveKeys) ? incentiveKeys : [incentiveKeys];
|
|
38
|
+
let calldatas = [];
|
|
39
|
+
for (let i = 0; i < incentiveKeys.length; i++) {
|
|
40
|
+
// the unique program tokenId is staked in
|
|
41
|
+
const incentiveKey = incentiveKeys[i];
|
|
42
|
+
// unstakes and claims for the unique program
|
|
43
|
+
calldatas = calldatas.concat(this.encodeClaim(incentiveKey, options));
|
|
44
|
+
// re-stakes the position for the unique program
|
|
45
|
+
calldatas.push(Staker.INTERFACE.encodeFunctionData('stakeToken', [
|
|
46
|
+
this._encodeIncentiveKey(incentiveKey),
|
|
47
|
+
toHex(options.tokenId),
|
|
48
|
+
]));
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
calldata: Multicall.encodeMulticall(calldatas),
|
|
52
|
+
value: toHex(0),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param incentiveKeys A list of incentiveKeys to unstake from. Should include all incentiveKeys (unique staking programs) that `options.tokenId` is staked in.
|
|
58
|
+
* @param withdrawOptions Options for producing claim calldata and withdraw calldata. Can't withdraw without unstaking all programs for `tokenId`.
|
|
59
|
+
* @returns Calldata for unstaking, claiming, and withdrawing.
|
|
60
|
+
*/
|
|
61
|
+
static withdrawToken(incentiveKeys, withdrawOptions) {
|
|
62
|
+
let calldatas = [];
|
|
63
|
+
incentiveKeys = Array.isArray(incentiveKeys) ? incentiveKeys : [incentiveKeys];
|
|
64
|
+
const claimOptions = {
|
|
65
|
+
tokenId: withdrawOptions.tokenId,
|
|
66
|
+
recipient: withdrawOptions.recipient,
|
|
67
|
+
amount: withdrawOptions.amount,
|
|
68
|
+
};
|
|
69
|
+
for (let i = 0; i < incentiveKeys.length; i++) {
|
|
70
|
+
const incentiveKey = incentiveKeys[i];
|
|
71
|
+
calldatas = calldatas.concat(this.encodeClaim(incentiveKey, claimOptions));
|
|
72
|
+
}
|
|
73
|
+
const owner = validateAndParseAddress(withdrawOptions.owner);
|
|
74
|
+
calldatas.push(Staker.INTERFACE.encodeFunctionData('withdrawToken', [
|
|
75
|
+
toHex(withdrawOptions.tokenId),
|
|
76
|
+
owner,
|
|
77
|
+
withdrawOptions.data ? withdrawOptions.data : toHex(0),
|
|
78
|
+
]));
|
|
79
|
+
return {
|
|
80
|
+
calldata: Multicall.encodeMulticall(calldatas),
|
|
81
|
+
value: toHex(0),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param incentiveKeys A single IncentiveKey or array of IncentiveKeys to be encoded and used in the data parameter in `safeTransferFrom`
|
|
87
|
+
* @returns An IncentiveKey as a string
|
|
88
|
+
*/
|
|
89
|
+
static encodeDeposit(incentiveKeys) {
|
|
90
|
+
incentiveKeys = Array.isArray(incentiveKeys) ? incentiveKeys : [incentiveKeys];
|
|
91
|
+
let data;
|
|
92
|
+
if (incentiveKeys.length > 1) {
|
|
93
|
+
const keys = [];
|
|
94
|
+
for (let i = 0; i < incentiveKeys.length; i++) {
|
|
95
|
+
const incentiveKey = incentiveKeys[i];
|
|
96
|
+
keys.push(this._encodeIncentiveKey(incentiveKey));
|
|
97
|
+
}
|
|
98
|
+
data = defaultAbiCoder.encode([`${Staker.INCENTIVE_KEY_ABI}[]`], [keys]);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
data = defaultAbiCoder.encode([Staker.INCENTIVE_KEY_ABI], [this._encodeIncentiveKey(incentiveKeys[0])]);
|
|
102
|
+
}
|
|
103
|
+
return data;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param incentiveKey An `IncentiveKey` which represents a unique staking program.
|
|
108
|
+
* @returns An encoded IncentiveKey to be read by ethers
|
|
109
|
+
*/
|
|
110
|
+
static _encodeIncentiveKey(incentiveKey) {
|
|
111
|
+
const { token0, token1, fee } = incentiveKey.pool;
|
|
112
|
+
const refundee = validateAndParseAddress(incentiveKey.refundee);
|
|
113
|
+
return {
|
|
114
|
+
rewardToken: incentiveKey.rewardToken.address,
|
|
115
|
+
pool: Pool.getAddress(token0, token1, fee),
|
|
116
|
+
startTime: toHex(incentiveKey.startTime),
|
|
117
|
+
endTime: toHex(incentiveKey.endTime),
|
|
118
|
+
refundee,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
Staker.INTERFACE = new Interface(IUniswapV3Staker.abi);
|
|
123
|
+
Staker.INCENTIVE_KEY_ABI = 'tuple(address rewardToken, address pool, uint256 startTime, uint256 endTime, address refundee)';
|
|
124
|
+
//# sourceMappingURL=staker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staker.js","sourceRoot":"","sources":["../../../src/staker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACvF,OAAO,EAAoB,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,gBAAgB,MAAM,iFAAiF,CAAA;AAC9G,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AA+DvC,MAAM,OAAgB,MAAM;IAG1B,gBAAyB,CAAC;IAI1B;;;;;OAKG;IACK,MAAM,CAAC,WAAW,CAAC,YAA0B,EAAE,OAAqB;;QAC1E,MAAM,SAAS,GAAa,EAAE,CAAA;QAC9B,SAAS,CAAC,IAAI,CACZ,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,cAAc,EAAE;YAClD,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC;YACtC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;SACvB,CAAC,CACH,CAAA;QACD,MAAM,SAAS,GAAW,uBAAuB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACpE,MAAM,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,CAAC,CAAA;QAClC,SAAS,CAAC,IAAI,CACZ,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CACjH,CAAA;QACD,OAAO,SAAS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,CAAC,CAAC,CAAA;aAClD;YACD,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,iBAAiB,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;SACzE;aAAM;YACL,IAAI,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;SACxG;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IACD;;;;OAIG;IACK,MAAM,CAAC,mBAAmB,CAAC,YAA0B;QAC3D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC,IAAI,CAAA;QACjD,MAAM,QAAQ,GAAG,uBAAuB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QAC/D,OAAO;YACL,WAAW,EAAE,YAAY,CAAC,WAAW,CAAC,OAAO;YAC7C,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC;YAC1C,SAAS,EAAE,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC;YACxC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC;YACpC,QAAQ;SACT,CAAA;IACH,CAAC;;AAtIa,gBAAS,GAAc,IAAI,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;AAGzD,wBAAiB,GAC9B,gGAAgG,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { BigintIsh, Currency, Percent, TradeType } from '@centurion_project/sdk-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 Uniswap 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,140 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { CurrencyAmount, TradeType, validateAndParseAddress } from '@centurion_project/sdk-core';
|
|
3
|
+
import invariant from 'tiny-invariant';
|
|
4
|
+
import { ADDRESS_ZERO } from './constants';
|
|
5
|
+
import { SelfPermit } from './selfPermit';
|
|
6
|
+
import { encodeRouteToPath } from './utils';
|
|
7
|
+
import { toHex } from './utils/calldata';
|
|
8
|
+
import ISwapRouter from '@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json';
|
|
9
|
+
import { Multicall } from './multicall';
|
|
10
|
+
import { Payments } from './payments';
|
|
11
|
+
/**
|
|
12
|
+
* Represents the Uniswap V3 SwapRouter, and has static methods for helping execute trades.
|
|
13
|
+
*/
|
|
14
|
+
export class SwapRouter {
|
|
15
|
+
/**
|
|
16
|
+
* Cannot be constructed.
|
|
17
|
+
*/
|
|
18
|
+
constructor() { }
|
|
19
|
+
/**
|
|
20
|
+
* Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
|
|
21
|
+
* @param trade to produce call parameters for
|
|
22
|
+
* @param options options for the call parameters
|
|
23
|
+
*/
|
|
24
|
+
static swapCallParameters(trades, options) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
if (!Array.isArray(trades)) {
|
|
27
|
+
trades = [trades];
|
|
28
|
+
}
|
|
29
|
+
const sampleTrade = trades[0];
|
|
30
|
+
const tokenIn = sampleTrade.inputAmount.currency.wrapped;
|
|
31
|
+
const tokenOut = sampleTrade.outputAmount.currency.wrapped;
|
|
32
|
+
// All trades should have the same starting and ending token.
|
|
33
|
+
invariant(trades.every((trade) => trade.inputAmount.currency.wrapped.equals(tokenIn)), 'TOKEN_IN_DIFF');
|
|
34
|
+
invariant(trades.every((trade) => trade.outputAmount.currency.wrapped.equals(tokenOut)), 'TOKEN_OUT_DIFF');
|
|
35
|
+
const calldatas = [];
|
|
36
|
+
const ZERO_IN = CurrencyAmount.fromRawAmount(trades[0].inputAmount.currency, 0);
|
|
37
|
+
const ZERO_OUT = CurrencyAmount.fromRawAmount(trades[0].outputAmount.currency, 0);
|
|
38
|
+
const totalAmountOut = trades.reduce((sum, trade) => sum.add(trade.minimumAmountOut(options.slippageTolerance)), ZERO_OUT);
|
|
39
|
+
// flag for whether a refund needs to happen
|
|
40
|
+
const mustRefund = sampleTrade.inputAmount.currency.isNative && sampleTrade.tradeType === TradeType.EXACT_OUTPUT;
|
|
41
|
+
const inputIsNative = sampleTrade.inputAmount.currency.isNative;
|
|
42
|
+
// flags for whether funds should be send first to the router
|
|
43
|
+
const outputIsNative = sampleTrade.outputAmount.currency.isNative;
|
|
44
|
+
const routerMustCustody = outputIsNative || !!options.fee;
|
|
45
|
+
const totalValue = inputIsNative
|
|
46
|
+
? trades.reduce((sum, trade) => sum.add(trade.maximumAmountIn(options.slippageTolerance)), ZERO_IN)
|
|
47
|
+
: ZERO_IN;
|
|
48
|
+
// encode permit if necessary
|
|
49
|
+
if (options.inputTokenPermit) {
|
|
50
|
+
invariant(sampleTrade.inputAmount.currency.isToken, 'NON_TOKEN_PERMIT');
|
|
51
|
+
calldatas.push(SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit));
|
|
52
|
+
}
|
|
53
|
+
const recipient = validateAndParseAddress(options.recipient);
|
|
54
|
+
const deadline = toHex(options.deadline);
|
|
55
|
+
for (const trade of trades) {
|
|
56
|
+
for (const { route, inputAmount, outputAmount } of trade.swaps) {
|
|
57
|
+
const amountIn = toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
|
|
58
|
+
const amountOut = toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
|
|
59
|
+
// flag for whether the trade is single hop or not
|
|
60
|
+
const singleHop = route.pools.length === 1;
|
|
61
|
+
if (singleHop) {
|
|
62
|
+
if (trade.tradeType === TradeType.EXACT_INPUT) {
|
|
63
|
+
const exactInputSingleParams = {
|
|
64
|
+
tokenIn: route.tokenPath[0].address,
|
|
65
|
+
tokenOut: route.tokenPath[1].address,
|
|
66
|
+
fee: route.pools[0].fee,
|
|
67
|
+
recipient: routerMustCustody ? ADDRESS_ZERO : recipient,
|
|
68
|
+
deadline,
|
|
69
|
+
amountIn,
|
|
70
|
+
amountOutMinimum: amountOut,
|
|
71
|
+
sqrtPriceLimitX96: toHex((_a = options.sqrtPriceLimitX96) !== null && _a !== void 0 ? _a : 0),
|
|
72
|
+
};
|
|
73
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const exactOutputSingleParams = {
|
|
77
|
+
tokenIn: route.tokenPath[0].address,
|
|
78
|
+
tokenOut: route.tokenPath[1].address,
|
|
79
|
+
fee: route.pools[0].fee,
|
|
80
|
+
recipient: routerMustCustody ? ADDRESS_ZERO : recipient,
|
|
81
|
+
deadline,
|
|
82
|
+
amountOut,
|
|
83
|
+
amountInMaximum: amountIn,
|
|
84
|
+
sqrtPriceLimitX96: toHex((_b = options.sqrtPriceLimitX96) !== null && _b !== void 0 ? _b : 0),
|
|
85
|
+
};
|
|
86
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutputSingle', [exactOutputSingleParams]));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
invariant(options.sqrtPriceLimitX96 === undefined, 'MULTIHOP_PRICE_LIMIT');
|
|
91
|
+
const path = encodeRouteToPath(route, trade.tradeType === TradeType.EXACT_OUTPUT);
|
|
92
|
+
if (trade.tradeType === TradeType.EXACT_INPUT) {
|
|
93
|
+
const exactInputParams = {
|
|
94
|
+
path,
|
|
95
|
+
recipient: routerMustCustody ? ADDRESS_ZERO : recipient,
|
|
96
|
+
deadline,
|
|
97
|
+
amountIn,
|
|
98
|
+
amountOutMinimum: amountOut,
|
|
99
|
+
};
|
|
100
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [exactInputParams]));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const exactOutputParams = {
|
|
104
|
+
path,
|
|
105
|
+
recipient: routerMustCustody ? ADDRESS_ZERO : recipient,
|
|
106
|
+
deadline,
|
|
107
|
+
amountOut,
|
|
108
|
+
amountInMaximum: amountIn,
|
|
109
|
+
};
|
|
110
|
+
calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutput', [exactOutputParams]));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// unwrap
|
|
116
|
+
if (routerMustCustody) {
|
|
117
|
+
if (!!options.fee) {
|
|
118
|
+
if (outputIsNative) {
|
|
119
|
+
calldatas.push(Payments.encodeUnwrapWETH9(totalAmountOut.quotient, recipient, options.fee));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
calldatas.push(Payments.encodeSweepToken(sampleTrade.outputAmount.currency.wrapped, totalAmountOut.quotient, recipient, options.fee));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
calldatas.push(Payments.encodeUnwrapWETH9(totalAmountOut.quotient, recipient));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// refund
|
|
130
|
+
if (mustRefund) {
|
|
131
|
+
calldatas.push(Payments.encodeRefundETH());
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
calldata: Multicall.encodeMulticall(calldatas),
|
|
135
|
+
value: toHex(totalValue.quotient),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
SwapRouter.INTERFACE = new Interface(ISwapRouter.abi);
|
|
140
|
+
//# sourceMappingURL=swapRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swapRouter.js","sourceRoot":"","sources":["../../../src/swapRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAuB,cAAc,EAAW,SAAS,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAC9H,OAAO,SAAS,MAAM,gBAAgB,CA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C;;AA/Ja,oBAAS,GAAc,IAAI,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BigintIsh } from '@centurion_project/sdk-core';
|
|
2
|
+
/**
|
|
3
|
+
* Generated method parameters for executing a call.
|
|
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,15 @@
|
|
|
1
|
+
import JSBI from 'jsbi';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a big int to a hex string
|
|
4
|
+
* @param bigintIsh
|
|
5
|
+
* @returns The hex encoded calldata
|
|
6
|
+
*/
|
|
7
|
+
export function toHex(bigintIsh) {
|
|
8
|
+
const bigInt = JSBI.BigInt(bigintIsh);
|
|
9
|
+
let hex = bigInt.toString(16);
|
|
10
|
+
if (hex.length % 2 !== 0) {
|
|
11
|
+
hex = `0${hex}`;
|
|
12
|
+
}
|
|
13
|
+
return `0x${hex}`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=calldata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calldata.js","sourceRoot":"","sources":["../../../../src/utils/calldata.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AAgBvB;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,SAAoB;IACxC,MAAM,MAAM,GAAG,IAAI,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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ChainId, Token } from '@centurion_project/sdk-core';
|
|
2
|
+
import { FeeAmount } from '../constants';
|
|
3
|
+
/**
|
|
4
|
+
* Computes a pool address
|
|
5
|
+
* @param factoryAddress The Uniswap 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
|
+
* @param chainId
|
|
11
|
+
* @returns The pool address
|
|
12
|
+
*/
|
|
13
|
+
export declare function computePoolAddress({ factoryAddress, tokenA, tokenB, fee, initCodeHashManualOverride, chainId, }: {
|
|
14
|
+
factoryAddress: string;
|
|
15
|
+
tokenA: Token;
|
|
16
|
+
tokenB: Token;
|
|
17
|
+
fee: FeeAmount;
|
|
18
|
+
initCodeHashManualOverride?: string;
|
|
19
|
+
chainId?: ChainId;
|
|
20
|
+
}): string;
|