@fenine/universal-router-sdk 1.0.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/README.md +331 -0
- package/dist/cjs/src/entities/Command.d.ts +12 -0
- package/dist/cjs/src/entities/Command.js +9 -0
- package/dist/cjs/src/entities/Command.js.map +1 -0
- package/dist/cjs/src/entities/actions/across.d.ts +21 -0
- package/dist/cjs/src/entities/actions/across.js +7 -0
- package/dist/cjs/src/entities/actions/across.js.map +1 -0
- package/dist/cjs/src/entities/actions/index.d.ts +3 -0
- package/dist/cjs/src/entities/actions/index.js +7 -0
- package/dist/cjs/src/entities/actions/index.js.map +1 -0
- package/dist/cjs/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/cjs/src/entities/actions/uniswap.js +545 -0
- package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/cjs/src/entities/index.d.ts +2 -0
- package/dist/cjs/src/entities/index.js +6 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/cjs/src/index.d.ts +14 -0
- package/dist/cjs/src/index.js +36 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/swapRouter.d.ts +103 -0
- package/dist/cjs/src/swapRouter.js +338 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/cjs/src/types/encodeSwaps.d.ts +149 -0
- package/dist/cjs/src/types/encodeSwaps.js +3 -0
- package/dist/cjs/src/types/encodeSwaps.js.map +1 -0
- package/dist/cjs/src/utils/commandParser.d.ts +34 -0
- package/dist/cjs/src/utils/commandParser.js +145 -0
- package/dist/cjs/src/utils/commandParser.js.map +1 -0
- package/dist/cjs/src/utils/computeEncodeSwapsAmounts.d.ts +8 -0
- package/dist/cjs/src/utils/computeEncodeSwapsAmounts.js +47 -0
- package/dist/cjs/src/utils/computeEncodeSwapsAmounts.js.map +1 -0
- package/dist/cjs/src/utils/constants.d.ts +39 -0
- package/dist/cjs/src/utils/constants.js +560 -0
- package/dist/cjs/src/utils/constants.js.map +1 -0
- package/dist/cjs/src/utils/eip712.d.ts +17 -0
- package/dist/cjs/src/utils/eip712.js +43 -0
- package/dist/cjs/src/utils/eip712.js.map +1 -0
- package/dist/cjs/src/utils/encodeSwapStep.d.ts +4 -0
- package/dist/cjs/src/utils/encodeSwapStep.js +61 -0
- package/dist/cjs/src/utils/encodeSwapStep.js.map +1 -0
- package/dist/cjs/src/utils/encodeV4Action.d.ts +8 -0
- package/dist/cjs/src/utils/encodeV4Action.js +97 -0
- package/dist/cjs/src/utils/encodeV4Action.js.map +1 -0
- package/dist/cjs/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/cjs/src/utils/inputTokens.d.ts +23 -0
- package/dist/cjs/src/utils/inputTokens.js +58 -0
- package/dist/cjs/src/utils/inputTokens.js.map +1 -0
- package/dist/cjs/src/utils/normalizeEncodeSwapsSpec.d.ts +2 -0
- package/dist/cjs/src/utils/normalizeEncodeSwapsSpec.js +18 -0
- package/dist/cjs/src/utils/normalizeEncodeSwapsSpec.js.map +1 -0
- package/dist/cjs/src/utils/numbers.d.ts +7 -0
- package/dist/cjs/src/utils/numbers.js +27 -0
- package/dist/cjs/src/utils/numbers.js.map +1 -0
- package/dist/cjs/src/utils/pathCurrency.d.ts +3 -0
- package/dist/cjs/src/utils/pathCurrency.js +27 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/cjs/src/utils/routerCommands.d.ts +77 -0
- package/dist/cjs/src/utils/routerCommands.js +334 -0
- package/dist/cjs/src/utils/routerCommands.js.map +1 -0
- package/dist/cjs/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/cjs/src/utils/routerTradeAdapter.js +139 -0
- package/dist/cjs/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/cjs/src/utils/validateEncodeSwaps.d.ts +2 -0
- package/dist/cjs/src/utils/validateEncodeSwaps.js +135 -0
- package/dist/cjs/src/utils/validateEncodeSwaps.js.map +1 -0
- package/dist/esm/src/entities/Command.d.ts +12 -0
- package/dist/esm/src/entities/Command.js +6 -0
- package/dist/esm/src/entities/Command.js.map +1 -0
- package/dist/esm/src/entities/actions/across.d.ts +21 -0
- package/dist/esm/src/entities/actions/across.js +3 -0
- package/dist/esm/src/entities/actions/across.js.map +1 -0
- package/dist/esm/src/entities/actions/index.d.ts +3 -0
- package/dist/esm/src/entities/actions/index.js +4 -0
- package/dist/esm/src/entities/actions/index.js.map +1 -0
- package/dist/esm/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/esm/src/entities/actions/uniswap.js +541 -0
- package/dist/esm/src/entities/actions/uniswap.js.map +1 -0
- package/dist/esm/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js +28 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +2 -0
- package/dist/esm/src/entities/index.js +3 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/index.d.ts +14 -0
- package/dist/esm/src/index.js +11 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +103 -0
- package/dist/esm/src/swapRouter.js +333 -0
- package/dist/esm/src/swapRouter.js.map +1 -0
- package/dist/esm/src/types/encodeSwaps.d.ts +149 -0
- package/dist/esm/src/types/encodeSwaps.js +2 -0
- package/dist/esm/src/types/encodeSwaps.js.map +1 -0
- package/dist/esm/src/utils/commandParser.d.ts +34 -0
- package/dist/esm/src/utils/commandParser.js +137 -0
- package/dist/esm/src/utils/commandParser.js.map +1 -0
- package/dist/esm/src/utils/computeEncodeSwapsAmounts.d.ts +8 -0
- package/dist/esm/src/utils/computeEncodeSwapsAmounts.js +43 -0
- package/dist/esm/src/utils/computeEncodeSwapsAmounts.js.map +1 -0
- package/dist/esm/src/utils/constants.d.ts +39 -0
- package/dist/esm/src/utils/constants.js +552 -0
- package/dist/esm/src/utils/constants.js.map +1 -0
- package/dist/esm/src/utils/eip712.d.ts +17 -0
- package/dist/esm/src/utils/eip712.js +38 -0
- package/dist/esm/src/utils/eip712.js.map +1 -0
- package/dist/esm/src/utils/encodeSwapStep.d.ts +4 -0
- package/dist/esm/src/utils/encodeSwapStep.js +57 -0
- package/dist/esm/src/utils/encodeSwapStep.js.map +1 -0
- package/dist/esm/src/utils/encodeV4Action.d.ts +8 -0
- package/dist/esm/src/utils/encodeV4Action.js +92 -0
- package/dist/esm/src/utils/encodeV4Action.js.map +1 -0
- package/dist/esm/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/esm/src/utils/getCurrencyAddress.js +5 -0
- package/dist/esm/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/esm/src/utils/inputTokens.d.ts +23 -0
- package/dist/esm/src/utils/inputTokens.js +51 -0
- package/dist/esm/src/utils/inputTokens.js.map +1 -0
- package/dist/esm/src/utils/normalizeEncodeSwapsSpec.d.ts +2 -0
- package/dist/esm/src/utils/normalizeEncodeSwapsSpec.js +14 -0
- package/dist/esm/src/utils/normalizeEncodeSwapsSpec.js.map +1 -0
- package/dist/esm/src/utils/numbers.d.ts +7 -0
- package/dist/esm/src/utils/numbers.js +19 -0
- package/dist/esm/src/utils/numbers.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.d.ts +3 -0
- package/dist/esm/src/utils/pathCurrency.js +23 -0
- package/dist/esm/src/utils/pathCurrency.js.map +1 -0
- package/dist/esm/src/utils/routerCommands.d.ts +77 -0
- package/dist/esm/src/utils/routerCommands.js +329 -0
- package/dist/esm/src/utils/routerCommands.js.map +1 -0
- package/dist/esm/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/esm/src/utils/routerTradeAdapter.js +134 -0
- package/dist/esm/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/esm/src/utils/validateEncodeSwaps.d.ts +2 -0
- package/dist/esm/src/utils/validateEncodeSwaps.js +130 -0
- package/dist/esm/src/utils/validateEncodeSwaps.js.map +1 -0
- package/dist/types/src/entities/Command.d.ts +12 -0
- package/dist/types/src/entities/actions/across.d.ts +21 -0
- package/dist/types/src/entities/actions/index.d.ts +3 -0
- package/dist/types/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/types/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/types/src/entities/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +14 -0
- package/dist/types/src/swapRouter.d.ts +103 -0
- package/dist/types/src/types/encodeSwaps.d.ts +149 -0
- package/dist/types/src/utils/commandParser.d.ts +34 -0
- package/dist/types/src/utils/computeEncodeSwapsAmounts.d.ts +8 -0
- package/dist/types/src/utils/constants.d.ts +39 -0
- package/dist/types/src/utils/eip712.d.ts +17 -0
- package/dist/types/src/utils/encodeSwapStep.d.ts +4 -0
- package/dist/types/src/utils/encodeV4Action.d.ts +8 -0
- package/dist/types/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/types/src/utils/inputTokens.d.ts +23 -0
- package/dist/types/src/utils/normalizeEncodeSwapsSpec.d.ts +2 -0
- package/dist/types/src/utils/numbers.d.ts +7 -0
- package/dist/types/src/utils/pathCurrency.d.ts +3 -0
- package/dist/types/src/utils/routerCommands.d.ts +77 -0
- package/dist/types/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/types/src/utils/validateEncodeSwaps.d.ts +2 -0
- package/package.json +78 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import invariant from 'tiny-invariant';
|
|
3
|
+
import { TradeType } from '@fenine/sdk-core';
|
|
4
|
+
import { TokenTransferMode } from '../entities/actions/uniswap';
|
|
5
|
+
import { ROUTER_AS_RECIPIENT, SENDER_AS_RECIPIENT, UniversalRouterVersion, ZERO_ADDRESS } from './constants';
|
|
6
|
+
// V3 path: 20-byte address + N × (3-byte fee + 20-byte address); minimum is 43 bytes (single hop, N=1)
|
|
7
|
+
// Returns N or undefined if malformed
|
|
8
|
+
function getV3HopCount(path) {
|
|
9
|
+
if (!path.startsWith('0x'))
|
|
10
|
+
return undefined;
|
|
11
|
+
const byteLength = (path.length - 2) / 2;
|
|
12
|
+
if (byteLength < 43)
|
|
13
|
+
return undefined;
|
|
14
|
+
const variableSegmentLength = byteLength - 20;
|
|
15
|
+
if (variableSegmentLength < 23 || variableSegmentLength % 23 !== 0)
|
|
16
|
+
return undefined;
|
|
17
|
+
return variableSegmentLength / 23;
|
|
18
|
+
}
|
|
19
|
+
function hasV4MinHopPriceX36(action) {
|
|
20
|
+
switch (action.action) {
|
|
21
|
+
case 'SWAP_EXACT_IN':
|
|
22
|
+
case 'SWAP_EXACT_OUT':
|
|
23
|
+
case 'SWAP_EXACT_IN_SINGLE':
|
|
24
|
+
case 'SWAP_EXACT_OUT_SINGLE':
|
|
25
|
+
return action.minHopPriceX36 !== undefined;
|
|
26
|
+
default:
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function validateV4HopCounts(actions) {
|
|
31
|
+
for (const action of actions) {
|
|
32
|
+
switch (action.action) {
|
|
33
|
+
case 'SWAP_EXACT_IN':
|
|
34
|
+
case 'SWAP_EXACT_OUT':
|
|
35
|
+
invariant(!action.minHopPriceX36 || action.minHopPriceX36.length === action.path.length, 'V4_MIN_HOP_PRICE_X36_LENGTH_MISMATCH');
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function assertRouterRecipient(recipient) {
|
|
43
|
+
invariant(recipient === ROUTER_AS_RECIPIENT, 'STEP_RECIPIENT_MUST_BE_ROUTER');
|
|
44
|
+
}
|
|
45
|
+
function assertRouterActionRecipient(recipient) {
|
|
46
|
+
invariant(recipient === ROUTER_AS_RECIPIENT, 'V4_ACTION_RECIPIENT_MUST_BE_ROUTER');
|
|
47
|
+
}
|
|
48
|
+
// V4 actions that take a recipient must use router custody so the SDK's settlement sweeps see the funds
|
|
49
|
+
function validateV4Recipients(actions) {
|
|
50
|
+
for (const action of actions) {
|
|
51
|
+
switch (action.action) {
|
|
52
|
+
case 'TAKE':
|
|
53
|
+
case 'TAKE_PORTION':
|
|
54
|
+
assertRouterActionRecipient(action.recipient);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function validateEncodeSwaps(spec, swapSteps) {
|
|
62
|
+
var _a, _b, _c, _d;
|
|
63
|
+
invariant(swapSteps.length > 0, 'EMPTY_SWAP_STEPS');
|
|
64
|
+
const amountCurrency = spec.routing.amount.currency.wrapped;
|
|
65
|
+
const quoteCurrency = spec.routing.quote.currency.wrapped;
|
|
66
|
+
const inputCurrency = spec.routing.inputToken.wrapped;
|
|
67
|
+
const outputCurrency = spec.routing.outputToken.wrapped;
|
|
68
|
+
invariant(!spec.slippageTolerance.lessThan(0), 'SLIPPAGE_TOLERANCE');
|
|
69
|
+
invariant(spec.recipient !== ZERO_ADDRESS, 'RECIPIENT_CANNOT_BE_ZERO');
|
|
70
|
+
invariant(spec.recipient !== ROUTER_AS_RECIPIENT, 'RECIPIENT_CANNOT_BE_ROUTER');
|
|
71
|
+
// routing.amount is on the exact side of the trade; routing.quote is on the slippage side
|
|
72
|
+
if (spec.tradeType === TradeType.EXACT_INPUT) {
|
|
73
|
+
invariant(amountCurrency.equals(inputCurrency), 'INVALID_ROUTING_AMOUNT_CURRENCY');
|
|
74
|
+
invariant(quoteCurrency.equals(outputCurrency), 'INVALID_ROUTING_QUOTE_CURRENCY');
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
invariant(amountCurrency.equals(outputCurrency), 'INVALID_ROUTING_AMOUNT_CURRENCY');
|
|
78
|
+
invariant(quoteCurrency.equals(inputCurrency), 'INVALID_ROUTING_QUOTE_CURRENCY');
|
|
79
|
+
}
|
|
80
|
+
// ApproveProxy ingress lives upstream in the proxy contract: needs chain id, ERC20 input, no permit2, explicit recipient
|
|
81
|
+
if (spec.tokenTransferMode === TokenTransferMode.ApproveProxy) {
|
|
82
|
+
invariant(!!spec.chainId, 'PROXY_MISSING_CHAIN_ID');
|
|
83
|
+
invariant(!spec.routing.inputToken.isNative, 'PROXY_NATIVE_INPUT');
|
|
84
|
+
invariant(!spec.permit, 'PROXY_PERMIT_CONFLICT');
|
|
85
|
+
invariant(spec.recipient !== SENDER_AS_RECIPIENT, 'PROXY_EXPLICIT_RECIPIENT_REQUIRED');
|
|
86
|
+
}
|
|
87
|
+
// permit2 is ERC20-only; native input pays via msg.value
|
|
88
|
+
invariant(!(spec.routing.inputToken.isNative && spec.permit), 'NATIVE_INPUT_PERMIT');
|
|
89
|
+
// portion fees pair with exact-input (% of variable output); flat fees pair with exact-output (fixed deduction from the target)
|
|
90
|
+
invariant(!(((_a = spec.fee) === null || _a === void 0 ? void 0 : _a.kind) === 'portion' && spec.tradeType !== TradeType.EXACT_INPUT), 'INVALID_PORTION_FEE_TRADE_TYPE');
|
|
91
|
+
invariant(!(((_b = spec.fee) === null || _b === void 0 ? void 0 : _b.kind) === 'flat' && spec.tradeType !== TradeType.EXACT_OUTPUT), 'INVALID_FLAT_FEE_TRADE_TYPE');
|
|
92
|
+
invariant(!(((_c = spec.fee) === null || _c === void 0 ? void 0 : _c.kind) === 'flat' &&
|
|
93
|
+
BigNumber.from(spec.fee.amount).gt(BigNumber.from(spec.routing.amount.quotient.toString()))), 'FLAT_FEE_GT_AMOUNT');
|
|
94
|
+
// v2.0 PAY_PORTION takes whole bps; fractional bps need >=v2.1.1's PAY_PORTION_FULL_PRECISION
|
|
95
|
+
invariant(!(((_d = spec.fee) === null || _d === void 0 ? void 0 : _d.kind) === 'portion' &&
|
|
96
|
+
spec.urVersion === UniversalRouterVersion.V2_0 &&
|
|
97
|
+
!spec.fee.fee.multiply(10000).remainder.equalTo(0)), 'FRACTIONAL_BPS_PORTION_FEE_UNSUPPORTED_ON_V2_0');
|
|
98
|
+
// per-step: capability-gate by UR version, recipients must be router custody, per-hop arrays must match hop counts
|
|
99
|
+
for (const step of swapSteps) {
|
|
100
|
+
if (spec.urVersion === UniversalRouterVersion.V2_0) {
|
|
101
|
+
invariant(!('minHopPriceX36' in step) || step.minHopPriceX36 === undefined, 'MIN_HOP_PRICE_X36_UNSUPPORTED_ON_V2_0');
|
|
102
|
+
invariant(!(step.type === 'V4_SWAP' && step.v4Actions.some(hasV4MinHopPriceX36)), 'MIN_HOP_PRICE_X36_UNSUPPORTED_ON_V2_0');
|
|
103
|
+
}
|
|
104
|
+
switch (step.type) {
|
|
105
|
+
case 'V2_SWAP_EXACT_IN':
|
|
106
|
+
case 'V2_SWAP_EXACT_OUT':
|
|
107
|
+
assertRouterRecipient(step.recipient);
|
|
108
|
+
invariant(!step.minHopPriceX36 || step.minHopPriceX36.length === step.path.length - 1, 'V2_MIN_HOP_PRICE_X36_LENGTH_MISMATCH');
|
|
109
|
+
break;
|
|
110
|
+
case 'V3_SWAP_EXACT_IN':
|
|
111
|
+
case 'V3_SWAP_EXACT_OUT': {
|
|
112
|
+
assertRouterRecipient(step.recipient);
|
|
113
|
+
const hopCount = getV3HopCount(step.path);
|
|
114
|
+
invariant(hopCount === undefined || !step.minHopPriceX36 || step.minHopPriceX36.length === hopCount, 'V3_MIN_HOP_PRICE_X36_LENGTH_MISMATCH');
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'WRAP_ETH':
|
|
118
|
+
case 'UNWRAP_WETH':
|
|
119
|
+
assertRouterRecipient(step.recipient);
|
|
120
|
+
break;
|
|
121
|
+
case 'V4_SWAP':
|
|
122
|
+
validateV4HopCounts(step.v4Actions);
|
|
123
|
+
validateV4Recipients(step.v4Actions);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=validateEncodeSwaps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateEncodeSwaps.js","sourceRoot":"","sources":["../../../../src/utils/validateEncodeSwaps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,SAAS,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAC/D,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG5G,uGAAuG;AACvG,sCAAsC;AACtC,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAA;IAE5C,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;IACxC,IAAI,UAAU,GAAG,EAAE;QAAE,OAAO,SAAS,CAAA;IAErC,MAAM,qBAAqB,GAAG,UAAU,GAAG,EAAE,CAAA;IAC7C,IAAI,qBAAqB,GAAG,EAAE,IAAI,qBAAqB,GAAG,EAAE,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAEpF,OAAO,qBAAqB,GAAG,EAAE,CAAA;AACnC,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAgB;IAC3C,QAAQ,MAAM,CAAC,MAAM,EAAE;QACrB,KAAK,eAAe,CAAC;QACrB,KAAK,gBAAgB,CAAC;QACtB,KAAK,sBAAsB,CAAC;QAC5B,KAAK,uBAAuB;YAC1B,OAAO,MAAM,CAAC,cAAc,KAAK,SAAS,CAAA;QAC5C;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|
5
|
+
export declare enum RouterActionType {
|
|
6
|
+
UniswapTrade = "UniswapTrade",
|
|
7
|
+
UnwrapWETH = "UnwrapWETH"
|
|
8
|
+
}
|
|
9
|
+
export interface Command {
|
|
10
|
+
tradeType: RouterActionType;
|
|
11
|
+
encode(planner: RoutePlanner, config: TradeConfig): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BigNumberish } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for Across V4 Deposit V3 command
|
|
4
|
+
* Used for cross-chain bridging via Across Protocol V3 SpokePool
|
|
5
|
+
*/
|
|
6
|
+
export type AcrossV4DepositV3Params = {
|
|
7
|
+
depositor: string;
|
|
8
|
+
recipient: string;
|
|
9
|
+
inputToken: string;
|
|
10
|
+
outputToken: string;
|
|
11
|
+
inputAmount: BigNumberish;
|
|
12
|
+
outputAmount: BigNumberish;
|
|
13
|
+
destinationChainId: number;
|
|
14
|
+
exclusiveRelayer: string;
|
|
15
|
+
quoteTimestamp: number;
|
|
16
|
+
fillDeadline: number;
|
|
17
|
+
exclusivityDeadline: number;
|
|
18
|
+
message: string;
|
|
19
|
+
useNative: boolean;
|
|
20
|
+
};
|
|
21
|
+
export { CONTRACT_BALANCE } from '../../utils/constants';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RoutePlanner } from '../../utils/routerCommands';
|
|
2
|
+
import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap/router-sdk';
|
|
3
|
+
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
|
+
import { Currency, TradeType } from '@fenine/sdk-core';
|
|
5
|
+
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
6
|
+
import { UniversalRouterVersion } from '../../utils/constants';
|
|
7
|
+
import { BigNumberish } from 'ethers';
|
|
8
|
+
export type FlatFeeOptions = {
|
|
9
|
+
amount: BigNumberish;
|
|
10
|
+
recipient: string;
|
|
11
|
+
};
|
|
12
|
+
export declare enum TokenTransferMode {
|
|
13
|
+
Permit2 = "Permit2",
|
|
14
|
+
ApproveProxy = "ApproveProxy"
|
|
15
|
+
}
|
|
16
|
+
export type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
|
|
17
|
+
useRouterBalance?: boolean;
|
|
18
|
+
inputTokenPermit?: Permit2Permit;
|
|
19
|
+
flatFee?: FlatFeeOptions;
|
|
20
|
+
safeMode?: boolean;
|
|
21
|
+
urVersion?: UniversalRouterVersion;
|
|
22
|
+
tokenTransferMode?: TokenTransferMode;
|
|
23
|
+
chainId?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare class UniswapTrade implements Command {
|
|
26
|
+
trade: RouterTrade<Currency, Currency, TradeType>;
|
|
27
|
+
options: SwapOptions;
|
|
28
|
+
readonly tradeType: RouterActionType;
|
|
29
|
+
readonly payerIsUser: boolean;
|
|
30
|
+
constructor(trade: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions);
|
|
31
|
+
get isAllV4(): boolean;
|
|
32
|
+
get inputRequiresWrap(): boolean;
|
|
33
|
+
get inputRequiresUnwrap(): boolean;
|
|
34
|
+
get outputRequiresWrap(): boolean;
|
|
35
|
+
get outputRequiresUnwrap(): boolean;
|
|
36
|
+
get outputRequiresTransition(): boolean;
|
|
37
|
+
encode(planner: RoutePlanner, _config: TradeConfig): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BigNumberish } from 'ethers';
|
|
2
|
+
import { RoutePlanner } from '../../utils/routerCommands';
|
|
3
|
+
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
|
+
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
5
|
+
export declare class UnwrapWETH implements Command {
|
|
6
|
+
readonly tradeType: RouterActionType;
|
|
7
|
+
readonly permit2Data?: Permit2Permit;
|
|
8
|
+
readonly wethAddress: string;
|
|
9
|
+
readonly amount: BigNumberish;
|
|
10
|
+
constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit);
|
|
11
|
+
encode(planner: RoutePlanner, _: TradeConfig): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { SwapRouter } from './swapRouter';
|
|
2
|
+
export type { MigrateV3ToV4Options, SignedRouteOptions, EIP712Payload } from './swapRouter';
|
|
3
|
+
export * from './types/encodeSwaps';
|
|
4
|
+
export * from './entities';
|
|
5
|
+
export * from './utils/routerTradeAdapter';
|
|
6
|
+
export { RoutePlanner, CommandType, COMMAND_DEFINITION, Parser, Subparser } from './utils/routerCommands';
|
|
7
|
+
export type { CommandDefinition, ParamType } from './utils/routerCommands';
|
|
8
|
+
export { UNIVERSAL_ROUTER_CREATION_BLOCK, UNIVERSAL_ROUTER_ADDRESS, SWAP_PROXY_ADDRESS, ROUTER_AS_RECIPIENT, WETH_ADDRESS, UniversalRouterVersion, isAtLeastV2_1_1, } from './utils/constants';
|
|
9
|
+
export { CommandParser, GenericCommandParser } from './utils/commandParser';
|
|
10
|
+
export type { UniversalRouterCommand, UniversalRouterCall, Param, CommandsDefinition } from './utils/commandParser';
|
|
11
|
+
export type { Permit2Permit } from './utils/inputTokens';
|
|
12
|
+
export { normalizeEncodeSwapsSpec } from './utils/normalizeEncodeSwapsSpec';
|
|
13
|
+
export { validateEncodeSwaps } from './utils/validateEncodeSwaps';
|
|
14
|
+
export { NONCE_SKIP_CHECK, generateNonce, EXECUTE_SIGNED_TYPES, getUniversalRouterDomain } from './utils/eip712';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { BigNumber, BigNumberish } from 'ethers';
|
|
3
|
+
import { MethodParameters, Position as V3Position, RemoveLiquidityOptions as V3RemoveLiquidityOptions } from '@fenine/v3-sdk';
|
|
4
|
+
import { Position as V4Position, AddLiquidityOptions as V4AddLiquidityOptions } from '@uniswap/v4-sdk';
|
|
5
|
+
import { Trade as RouterTrade } from '@uniswap/router-sdk';
|
|
6
|
+
import { Currency, TradeType } from '@fenine/sdk-core';
|
|
7
|
+
import { SwapOptions } from './entities/actions/uniswap';
|
|
8
|
+
import { AcrossV4DepositV3Params } from './entities/actions/across';
|
|
9
|
+
import { SwapSpecification, SwapStep } from './types/encodeSwaps';
|
|
10
|
+
import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
|
|
11
|
+
export type SwapRouterConfig = {
|
|
12
|
+
sender?: string;
|
|
13
|
+
deadline?: BigNumberish;
|
|
14
|
+
};
|
|
15
|
+
export type SignedRouteOptions = {
|
|
16
|
+
intent: string;
|
|
17
|
+
data: string;
|
|
18
|
+
sender: string;
|
|
19
|
+
nonce?: string;
|
|
20
|
+
};
|
|
21
|
+
export type EIP712Payload = {
|
|
22
|
+
domain: TypedDataDomain;
|
|
23
|
+
types: Record<string, TypedDataField[]>;
|
|
24
|
+
value: {
|
|
25
|
+
commands: string;
|
|
26
|
+
inputs: string[];
|
|
27
|
+
intent: string;
|
|
28
|
+
data: string;
|
|
29
|
+
sender: string;
|
|
30
|
+
nonce: string;
|
|
31
|
+
deadline: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export interface MigrateV3ToV4Options {
|
|
35
|
+
inputPosition: V3Position;
|
|
36
|
+
outputPosition: V4Position;
|
|
37
|
+
v3RemoveLiquidityOptions: V3RemoveLiquidityOptions;
|
|
38
|
+
v4AddLiquidityOptions: V4AddLiquidityOptions;
|
|
39
|
+
}
|
|
40
|
+
export declare abstract class SwapRouter {
|
|
41
|
+
static INTERFACE: Interface;
|
|
42
|
+
static PROXY_INTERFACE: Interface;
|
|
43
|
+
static swapCallParameters(trades: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions, bridgeOptions?: AcrossV4DepositV3Params[]): MethodParameters;
|
|
44
|
+
/**
|
|
45
|
+
* Encodes router-provided swap steps inside the SDK safety envelope.
|
|
46
|
+
*
|
|
47
|
+
* Routers own `swapSteps` (V2/V3/V4 swaps, plus any `WRAP_ETH` / `UNWRAP_WETH` required by the route).
|
|
48
|
+
* The SDK owns ingress, fees, final settlement, exact-output refund, and optional `safeMode`.
|
|
49
|
+
*
|
|
50
|
+
* Router contract: end with final output in `spec.routing.outputToken`; for `EXACT_OUTPUT`, unused input
|
|
51
|
+
* must end in `spec.routing.inputToken`. Don't include a top-level `SWEEP` — the SDK appends settlement,
|
|
52
|
+
* refund, and safeMode sweeps itself.
|
|
53
|
+
*
|
|
54
|
+
* Router custody with `payerIsUser = false` is deliberate for safety, even if it costs an extra command
|
|
55
|
+
* or transfer; the SDK does not infer route topology on behalf of routers.
|
|
56
|
+
*/
|
|
57
|
+
static encodeSwaps(spec: SwapSpecification, swapSteps: SwapStep[]): MethodParameters;
|
|
58
|
+
/**
|
|
59
|
+
* Generate EIP712 payload for signed execution (no signing performed)
|
|
60
|
+
* Decodes existing execute() calldata and prepares it for signing
|
|
61
|
+
*
|
|
62
|
+
* @param calldata The calldata from swapCallParameters() or similar
|
|
63
|
+
* @param signedOptions Options for signed execution (intent, data, sender, nonce)
|
|
64
|
+
* @param deadline The deadline timestamp
|
|
65
|
+
* @param chainId The chain ID
|
|
66
|
+
* @param routerAddress The Universal Router contract address
|
|
67
|
+
* @returns EIP712 payload ready to be signed externally
|
|
68
|
+
*/
|
|
69
|
+
static getExecuteSignedPayload(calldata: string, signedOptions: SignedRouteOptions, deadline: BigNumberish, chainId: number, routerAddress: string): EIP712Payload;
|
|
70
|
+
/**
|
|
71
|
+
* Encode executeSigned() call with signature
|
|
72
|
+
*
|
|
73
|
+
* @param calldata The original calldata from swapCallParameters()
|
|
74
|
+
* @param signature The signature obtained from external signing
|
|
75
|
+
* @param signedOptions The same options used in getExecuteSignedPayload()
|
|
76
|
+
* @param deadline The deadline timestamp
|
|
77
|
+
* @param nativeCurrencyValue The native currency value (ETH) to send
|
|
78
|
+
* @returns Method parameters for executeSigned()
|
|
79
|
+
*/
|
|
80
|
+
static encodeExecuteSigned(calldata: string, signature: string, signedOptions: SignedRouteOptions, deadline: BigNumberish, nativeCurrencyValue?: BigNumber): MethodParameters;
|
|
81
|
+
/**
|
|
82
|
+
* Builds the call parameters for a migration from a V3 position to a V4 position.
|
|
83
|
+
* Some requirements of the parameters:
|
|
84
|
+
* - v3RemoveLiquidityOptions.collectOptions.recipient must equal v4PositionManager
|
|
85
|
+
* - v3RemoveLiquidityOptions.liquidityPercentage must be 100%
|
|
86
|
+
* - input pool and output pool must have the same tokens
|
|
87
|
+
* - V3 NFT must be approved, or valid inputV3NFTPermit must be provided with UR as spender
|
|
88
|
+
*/
|
|
89
|
+
static migrateV3ToV4CallParameters(options: MigrateV3ToV4Options, positionManagerOverride?: string): MethodParameters;
|
|
90
|
+
/**
|
|
91
|
+
* Encodes a planned route into a method name and parameters for the Router contract.
|
|
92
|
+
* @param planner the planned route
|
|
93
|
+
* @param nativeCurrencyValue the native currency value of the planned route
|
|
94
|
+
* @param config the router config
|
|
95
|
+
*/
|
|
96
|
+
private static encodePlan;
|
|
97
|
+
/**
|
|
98
|
+
* Wraps an inner UR plan in calldata targeting the SwapProxy contract.
|
|
99
|
+
* The proxy pulls ERC20 tokens from the user into the UR, then executes commands.
|
|
100
|
+
*/
|
|
101
|
+
private static encodeProxyPlan;
|
|
102
|
+
private static encodeProxyCall;
|
|
103
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { BigNumberish } from 'ethers';
|
|
2
|
+
import { Currency, CurrencyAmount, Percent, TradeType } from '@fenine/sdk-core';
|
|
3
|
+
import { type PathKey, type PoolKey } from '@uniswap/v4-sdk';
|
|
4
|
+
import { TokenTransferMode } from '../entities/actions/uniswap';
|
|
5
|
+
import { Permit2Permit } from '../utils/inputTokens';
|
|
6
|
+
import { UniversalRouterVersion } from '../utils/constants';
|
|
7
|
+
export type { PathKey, PoolKey };
|
|
8
|
+
export type Fee = {
|
|
9
|
+
kind: 'portion';
|
|
10
|
+
recipient: string;
|
|
11
|
+
fee: Percent;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'flat';
|
|
14
|
+
recipient: string;
|
|
15
|
+
amount: BigNumberish;
|
|
16
|
+
};
|
|
17
|
+
export type SwapSpecification = {
|
|
18
|
+
tradeType: TradeType;
|
|
19
|
+
routing: {
|
|
20
|
+
inputToken: Currency;
|
|
21
|
+
outputToken: Currency;
|
|
22
|
+
amount: CurrencyAmount<Currency>;
|
|
23
|
+
quote: CurrencyAmount<Currency>;
|
|
24
|
+
};
|
|
25
|
+
slippageTolerance: Percent;
|
|
26
|
+
recipient?: string;
|
|
27
|
+
fee?: Fee;
|
|
28
|
+
tokenTransferMode?: TokenTransferMode;
|
|
29
|
+
permit?: Permit2Permit;
|
|
30
|
+
chainId?: number;
|
|
31
|
+
deadline?: BigNumberish;
|
|
32
|
+
urVersion?: UniversalRouterVersion;
|
|
33
|
+
safeMode?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type NormalizedSwapSpecification = Omit<SwapSpecification, 'recipient' | 'tokenTransferMode' | 'urVersion' | 'safeMode'> & {
|
|
36
|
+
recipient: string;
|
|
37
|
+
tokenTransferMode: TokenTransferMode;
|
|
38
|
+
urVersion: UniversalRouterVersion;
|
|
39
|
+
safeMode: boolean;
|
|
40
|
+
};
|
|
41
|
+
export type V2SwapExactIn = {
|
|
42
|
+
type: 'V2_SWAP_EXACT_IN';
|
|
43
|
+
recipient: string;
|
|
44
|
+
amountIn: BigNumberish;
|
|
45
|
+
amountOutMin: BigNumberish;
|
|
46
|
+
path: string[];
|
|
47
|
+
minHopPriceX36?: BigNumberish[];
|
|
48
|
+
};
|
|
49
|
+
export type V2SwapExactOut = {
|
|
50
|
+
type: 'V2_SWAP_EXACT_OUT';
|
|
51
|
+
recipient: string;
|
|
52
|
+
amountOut: BigNumberish;
|
|
53
|
+
amountInMax: BigNumberish;
|
|
54
|
+
path: string[];
|
|
55
|
+
minHopPriceX36?: BigNumberish[];
|
|
56
|
+
};
|
|
57
|
+
export type V3SwapExactIn = {
|
|
58
|
+
type: 'V3_SWAP_EXACT_IN';
|
|
59
|
+
recipient: string;
|
|
60
|
+
amountIn: BigNumberish;
|
|
61
|
+
amountOutMin: BigNumberish;
|
|
62
|
+
path: string;
|
|
63
|
+
minHopPriceX36?: BigNumberish[];
|
|
64
|
+
};
|
|
65
|
+
export type V3SwapExactOut = {
|
|
66
|
+
type: 'V3_SWAP_EXACT_OUT';
|
|
67
|
+
recipient: string;
|
|
68
|
+
amountOut: BigNumberish;
|
|
69
|
+
amountInMax: BigNumberish;
|
|
70
|
+
path: string;
|
|
71
|
+
minHopPriceX36?: BigNumberish[];
|
|
72
|
+
};
|
|
73
|
+
export type V4Swap = {
|
|
74
|
+
type: 'V4_SWAP';
|
|
75
|
+
v4Actions: V4Action[];
|
|
76
|
+
};
|
|
77
|
+
export type WrapEth = {
|
|
78
|
+
type: 'WRAP_ETH';
|
|
79
|
+
recipient: string;
|
|
80
|
+
amount: BigNumberish;
|
|
81
|
+
};
|
|
82
|
+
export type UnwrapWeth = {
|
|
83
|
+
type: 'UNWRAP_WETH';
|
|
84
|
+
recipient: string;
|
|
85
|
+
amountMin: BigNumberish;
|
|
86
|
+
};
|
|
87
|
+
export type SwapStep = V2SwapExactIn | V2SwapExactOut | V3SwapExactIn | V3SwapExactOut | V4Swap | WrapEth | UnwrapWeth;
|
|
88
|
+
export type V4SwapExactIn = {
|
|
89
|
+
action: 'SWAP_EXACT_IN';
|
|
90
|
+
currencyIn: string;
|
|
91
|
+
path: PathKey[];
|
|
92
|
+
amountIn: BigNumberish;
|
|
93
|
+
amountOutMinimum: BigNumberish;
|
|
94
|
+
minHopPriceX36?: BigNumberish[];
|
|
95
|
+
};
|
|
96
|
+
export type V4SwapExactInSingle = {
|
|
97
|
+
action: 'SWAP_EXACT_IN_SINGLE';
|
|
98
|
+
poolKey: PoolKey;
|
|
99
|
+
zeroForOne: boolean;
|
|
100
|
+
amountIn: BigNumberish;
|
|
101
|
+
amountOutMinimum: BigNumberish;
|
|
102
|
+
minHopPriceX36?: BigNumberish;
|
|
103
|
+
hookData: string;
|
|
104
|
+
};
|
|
105
|
+
export type V4SwapExactOut = {
|
|
106
|
+
action: 'SWAP_EXACT_OUT';
|
|
107
|
+
currencyOut: string;
|
|
108
|
+
path: PathKey[];
|
|
109
|
+
amountOut: BigNumberish;
|
|
110
|
+
amountInMaximum: BigNumberish;
|
|
111
|
+
minHopPriceX36?: BigNumberish[];
|
|
112
|
+
};
|
|
113
|
+
export type V4SwapExactOutSingle = {
|
|
114
|
+
action: 'SWAP_EXACT_OUT_SINGLE';
|
|
115
|
+
poolKey: PoolKey;
|
|
116
|
+
zeroForOne: boolean;
|
|
117
|
+
amountOut: BigNumberish;
|
|
118
|
+
amountInMaximum: BigNumberish;
|
|
119
|
+
minHopPriceX36?: BigNumberish;
|
|
120
|
+
hookData: string;
|
|
121
|
+
};
|
|
122
|
+
export type V4Settle = {
|
|
123
|
+
action: 'SETTLE';
|
|
124
|
+
currency: string;
|
|
125
|
+
amount: BigNumberish;
|
|
126
|
+
};
|
|
127
|
+
export type V4SettleAll = {
|
|
128
|
+
action: 'SETTLE_ALL';
|
|
129
|
+
currency: string;
|
|
130
|
+
maxAmount: BigNumberish;
|
|
131
|
+
};
|
|
132
|
+
export type V4Take = {
|
|
133
|
+
action: 'TAKE';
|
|
134
|
+
currency: string;
|
|
135
|
+
recipient: string;
|
|
136
|
+
amount: BigNumberish;
|
|
137
|
+
};
|
|
138
|
+
export type V4TakeAll = {
|
|
139
|
+
action: 'TAKE_ALL';
|
|
140
|
+
currency: string;
|
|
141
|
+
minAmount: BigNumberish;
|
|
142
|
+
};
|
|
143
|
+
export type V4TakePortion = {
|
|
144
|
+
action: 'TAKE_PORTION';
|
|
145
|
+
currency: string;
|
|
146
|
+
recipient: string;
|
|
147
|
+
bips: BigNumberish;
|
|
148
|
+
};
|
|
149
|
+
export type V4Action = V4SwapExactIn | V4SwapExactInSingle | V4SwapExactOut | V4SwapExactOutSingle | V4Settle | V4SettleAll | V4Take | V4TakeAll | V4TakePortion;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { CommandType, CommandDefinition } from '../utils/routerCommands';
|
|
3
|
+
export type Param = {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly value: any;
|
|
6
|
+
};
|
|
7
|
+
export type UniversalRouterCommand = {
|
|
8
|
+
readonly commandName: string;
|
|
9
|
+
readonly commandType: CommandType;
|
|
10
|
+
readonly params: readonly Param[];
|
|
11
|
+
};
|
|
12
|
+
export type UniversalRouterCall = {
|
|
13
|
+
readonly commands: readonly UniversalRouterCommand[];
|
|
14
|
+
};
|
|
15
|
+
export type V3PathItem = {
|
|
16
|
+
readonly tokenIn: string;
|
|
17
|
+
readonly tokenOut: string;
|
|
18
|
+
readonly fee: number;
|
|
19
|
+
};
|
|
20
|
+
export interface CommandsDefinition {
|
|
21
|
+
[key: number]: CommandDefinition;
|
|
22
|
+
}
|
|
23
|
+
export declare abstract class CommandParser {
|
|
24
|
+
static INTERFACE: Interface;
|
|
25
|
+
static parseCalldata(calldata: string): UniversalRouterCall;
|
|
26
|
+
}
|
|
27
|
+
export declare class GenericCommandParser {
|
|
28
|
+
private readonly commandDefinition;
|
|
29
|
+
constructor(commandDefinition: CommandsDefinition);
|
|
30
|
+
parse(commands: string, inputs: string[]): UniversalRouterCall;
|
|
31
|
+
private static getCommands;
|
|
32
|
+
}
|
|
33
|
+
export declare function parseV3PathExactIn(path: string): readonly V3PathItem[];
|
|
34
|
+
export declare function parseV3PathExactOut(path: string): readonly V3PathItem[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import { NormalizedSwapSpecification } from '../types/encodeSwaps';
|
|
3
|
+
export type EncodeSwapsAmounts = {
|
|
4
|
+
exactOrMaxAmountIn: BigNumber;
|
|
5
|
+
grossMinOrExactAmountOut: BigNumber;
|
|
6
|
+
netMinOrExactAmountOut: BigNumber;
|
|
7
|
+
};
|
|
8
|
+
export declare function computeEncodeSwapsAmounts(spec: NormalizedSwapSpecification): EncodeSwapsAmounts;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
export declare enum UniversalRouterVersion {
|
|
3
|
+
V1_2 = "1.2",
|
|
4
|
+
V2_0 = "2.0",
|
|
5
|
+
V2_1_1 = "2.1.1"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check if a UniversalRouterVersion is at least V2_1_1.
|
|
9
|
+
* Duplicated from @uniswap/v4-sdk's isAtLeastV2_1_1 (which operates on URVersion)
|
|
10
|
+
* to avoid coupling universal-router-sdk's version logic to v4-sdk.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isAtLeastV2_1_1(version?: UniversalRouterVersion): boolean;
|
|
13
|
+
export type RouterConfig = {
|
|
14
|
+
address: string;
|
|
15
|
+
creationBlock: number;
|
|
16
|
+
};
|
|
17
|
+
type ChainConfig = {
|
|
18
|
+
weth: string;
|
|
19
|
+
routerConfigs: {
|
|
20
|
+
[key in UniversalRouterVersion]?: RouterConfig;
|
|
21
|
+
};
|
|
22
|
+
swapProxy?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare const CHAIN_CONFIGS: {
|
|
25
|
+
[key: number]: ChainConfig;
|
|
26
|
+
};
|
|
27
|
+
export declare const UNIVERSAL_ROUTER_ADDRESS: (version: UniversalRouterVersion, chainId: number) => string;
|
|
28
|
+
export declare const SWAP_PROXY_ADDRESS: (chainId: number) => string;
|
|
29
|
+
export declare const UNIVERSAL_ROUTER_CREATION_BLOCK: (version: UniversalRouterVersion, chainId: number) => number;
|
|
30
|
+
export declare const WETH_ADDRESS: (chainId: number) => string;
|
|
31
|
+
export declare const CONTRACT_BALANCE: BigNumber;
|
|
32
|
+
export declare const ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
33
|
+
export declare const E_ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
34
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
35
|
+
export declare const MAX_UINT256: BigNumber;
|
|
36
|
+
export declare const MAX_UINT160: BigNumber;
|
|
37
|
+
export declare const SENDER_AS_RECIPIENT = "0x0000000000000000000000000000000000000001";
|
|
38
|
+
export declare const ROUTER_AS_RECIPIENT = "0x0000000000000000000000000000000000000002";
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
|
|
2
|
+
export declare const EIP712_DOMAIN_NAME = "UniversalRouter";
|
|
3
|
+
export declare const EIP712_DOMAIN_VERSION = "2";
|
|
4
|
+
export declare const EXECUTE_SIGNED_TYPES: Record<string, TypedDataField[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Generate EIP712 domain for Universal Router
|
|
7
|
+
*/
|
|
8
|
+
export declare function getUniversalRouterDomain(chainId: number, verifyingContract: string): TypedDataDomain;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a random nonce for signed execution
|
|
11
|
+
* Uses ethers.utils.randomBytes for secure randomness
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateNonce(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Sentinel value to skip nonce checking (allows signature replay)
|
|
16
|
+
*/
|
|
17
|
+
export declare const NONCE_SKIP_CHECK: string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UniversalRouterVersion } from './constants';
|
|
2
|
+
import { RoutePlanner } from './routerCommands';
|
|
3
|
+
import { SwapStep } from '../types/encodeSwaps';
|
|
4
|
+
export declare function encodeSwapStep(planner: RoutePlanner, step: SwapStep, urVersion?: UniversalRouterVersion): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Actions, URVersion } from '@uniswap/v4-sdk';
|
|
2
|
+
import { UniversalRouterVersion } from './constants';
|
|
3
|
+
import { V4Action } from '../types/encodeSwaps';
|
|
4
|
+
export declare function toV4URVersion(version?: UniversalRouterVersion): URVersion;
|
|
5
|
+
export declare function encodeV4Action(v4Action: V4Action, urVersion?: UniversalRouterVersion): {
|
|
6
|
+
action: Actions;
|
|
7
|
+
params: any[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BigintIsh } from '@fenine/sdk-core';
|
|
2
|
+
import { NFTPermitOptions } from '@fenine/v3-sdk';
|
|
3
|
+
import { PermitSingle } from '@fenine/permit2-sdk';
|
|
4
|
+
import { RoutePlanner } from './routerCommands';
|
|
5
|
+
export interface Permit2Permit extends PermitSingle {
|
|
6
|
+
signature: string;
|
|
7
|
+
}
|
|
8
|
+
export type ApproveProtocol = {
|
|
9
|
+
token: string;
|
|
10
|
+
protocol: string;
|
|
11
|
+
};
|
|
12
|
+
export type Permit2TransferFrom = {
|
|
13
|
+
token: string;
|
|
14
|
+
amount: string;
|
|
15
|
+
recipient?: string;
|
|
16
|
+
};
|
|
17
|
+
export type InputTokenOptions = {
|
|
18
|
+
permit2Permit?: Permit2Permit;
|
|
19
|
+
permit2TransferFrom?: Permit2TransferFrom;
|
|
20
|
+
};
|
|
21
|
+
export declare function encodePermit(planner: RoutePlanner, permit2: Permit2Permit): void;
|
|
22
|
+
export declare function encodeV3PositionPermit(planner: RoutePlanner, permit: NFTPermitOptions, tokenId: BigintIsh): void;
|
|
23
|
+
export declare function encodeInputTokenOptions(planner: RoutePlanner, options: InputTokenOptions): void;
|