@rabby-wallet/rabby-swap 0.0.88-alpha.2 → 0.0.88-alpha.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/dist/abi.d.ts +1 -0
- package/dist/abi.js +5 -0
- package/dist/dexs/pancake.js +29 -3
- package/dist/dexs/uni.d.ts +1 -0
- package/dist/dexs/uni.js +20 -0
- package/dist/verify/contracts.d.ts +1 -1
- package/dist/verify/contracts.js +11 -7
- package/package.json +1 -1
package/dist/abi.d.ts
CHANGED
package/dist/abi.js
CHANGED
|
@@ -1654,3 +1654,8 @@ export const ZeroXABIV2 = [
|
|
|
1654
1654
|
export const SushiABI = [{ "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [{ "internalType": "address", "name": "tokenOut", "type": "address" }, { "internalType": "uint256", "name": "amountOut", "type": "uint256" }], "name": "MinimalOutputBalanceViolation", "type": "error" }, { "inputs": [], "name": "safeExecutor", "outputs": [{ "internalType": "contract SafeExecutor", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "contract IERC20", "name": "tokenIn", "type": "address" }, { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, { "internalType": "address", "name": "recipient", "type": "address" }, { "internalType": "contract IERC20", "name": "tokenOut", "type": "address" }, { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }, { "internalType": "address", "name": "executor", "type": "address" }, { "internalType": "bytes", "name": "executorData", "type": "bytes" }], "name": "snwap", "outputs": [{ "internalType": "uint256", "name": "amountOut", "type": "uint256" }], "stateMutability": "payable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "contract IERC20", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, { "internalType": "address", "name": "transferTo", "type": "address" }], "internalType": "struct InputToken[]", "name": "inputTokens", "type": "tuple[]" }, { "components": [{ "internalType": "contract IERC20", "name": "token", "type": "address" }, { "internalType": "address", "name": "recipient", "type": "address" }, { "internalType": "uint256", "name": "amountOutMin", "type": "uint256" }], "internalType": "struct OutputToken[]", "name": "outputTokens", "type": "tuple[]" }, { "components": [{ "internalType": "address", "name": "executor", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" }], "internalType": "struct Executor[]", "name": "executors", "type": "tuple[]" }], "name": "snwapMultiple", "outputs": [{ "internalType": "uint256[]", "name": "amountOut", "type": "uint256[]" }], "stateMutability": "payable", "type": "function" }];
|
|
1655
1655
|
export { UniABI } from "./calldata/uni/abi";
|
|
1656
1656
|
export { MagpieABI } from "./calldata/magpie/abi";
|
|
1657
|
+
// IAggregator.swapExactIn from the official router's verified implementation:
|
|
1658
|
+
// https://sourcify.dev/server/v2/contract/56/0x88b20da52208607e3bf06a59605acebbe7d2e3d6?fields=abi,sources
|
|
1659
|
+
export const PancakeSwapABI = [
|
|
1660
|
+
"function swapExactIn(uint256 orderId, (address inputToken, address outputToken, uint256 minOutputAmount, uint256 deadline) request, uint256[] routesAmount, (uint256[] mixAdapters, address[] assetTo, uint256[] rawData, bytes[] extraData, address fromToken)[][] routes, uint256 feeConfig, address recipient) payable returns (uint256 outputAmtReceived)",
|
|
1661
|
+
];
|
package/dist/dexs/pancake.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { CHAINS_ENUM } from "@debank/common";
|
|
2
|
-
import {
|
|
1
|
+
import { CHAINS, CHAINS_ENUM } from "@debank/common";
|
|
2
|
+
import { Interface } from "@ethersproject/abi";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { generateGetQuote, isSameAddress, NULL_ADDRESS, resolveToTokenReceiver, } from "../utils";
|
|
5
|
+
import { PancakeSwapABI } from "../abi";
|
|
3
6
|
import { DEX_ENUM } from "../consts";
|
|
4
7
|
export const SUPPORT_CHAINS = [
|
|
5
8
|
CHAINS_ENUM.ETH,
|
|
@@ -13,5 +16,28 @@ export const getQuote = generateGetQuote({
|
|
|
13
16
|
dex: DEX_ENUM.PANCAKESWAP,
|
|
14
17
|
});
|
|
15
18
|
export const decodeCalldata = (tx) => {
|
|
16
|
-
|
|
19
|
+
const chain = Object.values(CHAINS).find((item) => item.id === tx.chainId);
|
|
20
|
+
// Older @debank/common versions do not include Robinhood Chain yet.
|
|
21
|
+
const nativeTokenAddress = (chain === null || chain === void 0 ? void 0 : chain.nativeTokenAddress) || (tx.chainId === 4663 ? "hood" : undefined);
|
|
22
|
+
if (!nativeTokenAddress)
|
|
23
|
+
return null;
|
|
24
|
+
const contractInterface = new Interface(PancakeSwapABI);
|
|
25
|
+
const result = contractInterface.parseTransaction({ data: tx.data });
|
|
26
|
+
if (result.name !== "swapExactIn")
|
|
27
|
+
return null;
|
|
28
|
+
const { request, routesAmount, recipient } = result.args;
|
|
29
|
+
// Aggregator._swapExactIn sums the exact input budget across split routes.
|
|
30
|
+
const amount = routesAmount.reduce((total, value) => total.plus(value.toString()), new BigNumber(0));
|
|
31
|
+
return {
|
|
32
|
+
fromToken: isSameAddress(request.inputToken, NULL_ADDRESS)
|
|
33
|
+
? nativeTokenAddress
|
|
34
|
+
: request.inputToken,
|
|
35
|
+
fromTokenAmount: amount.toFixed(0),
|
|
36
|
+
toToken: isSameAddress(request.outputToken, NULL_ADDRESS)
|
|
37
|
+
? nativeTokenAddress
|
|
38
|
+
: request.outputToken,
|
|
39
|
+
// The contract checks this minimum against the recipient's post-fee output.
|
|
40
|
+
minReceiveToTokenAmount: request.minOutputAmount.toString(),
|
|
41
|
+
toTokenReceiver: resolveToTokenReceiver(recipient, tx.from),
|
|
42
|
+
};
|
|
17
43
|
};
|
package/dist/dexs/uni.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { CHAINS_ENUM } from "@debank/common";
|
|
|
2
2
|
export { decodeCalldata } from "../calldata/uni";
|
|
3
3
|
export declare const SUPPORT_CHAINS: CHAINS_ENUM[];
|
|
4
4
|
export declare const UNI_NATIVE_TO_ADDRESSES: Record<CHAINS_ENUM, string>;
|
|
5
|
+
export declare const UNI_LEGACY_NATIVE_TO_ADDRESSES: Record<CHAINS_ENUM, string>;
|
|
5
6
|
export declare const getQuote: (options: import("../quote").QuoteParams, api: import("@rabby-wallet/rabby-api").OpenApiService) => Promise<import("../quote").QuoteResult>;
|
package/dist/dexs/uni.js
CHANGED
|
@@ -19,7 +19,27 @@ export const SUPPORT_CHAINS = [
|
|
|
19
19
|
"HOOD",
|
|
20
20
|
"ARC",
|
|
21
21
|
];
|
|
22
|
+
// Native-input tx.to: UR 2.1.2, zkSync 2.0, or SwapProxy on Celo/Tempo.
|
|
23
|
+
// https://github.com/Uniswap/universal-router/tree/543e1a19d6e21e31ced2512eec5792b50f13a0ba/deploy-addresses
|
|
22
24
|
export const UNI_NATIVE_TO_ADDRESSES = {
|
|
25
|
+
[CHAINS_ENUM.ETH]: "0x23617e59A5925b2A4Bf75d73ff6711cD0b29De85",
|
|
26
|
+
[CHAINS_ENUM.OP]: "0xC09255D86DB563cBc11C2fCf4a0C512e160111B4",
|
|
27
|
+
[CHAINS_ENUM.BSC]: "0xDc264714F68d84CF29BC605589405E78bDBE7C9f",
|
|
28
|
+
[CHAINS_ENUM.POLYGON]: "0xDc264714F68d84CF29BC605589405E78bDBE7C9f",
|
|
29
|
+
[CHAINS_ENUM.ARBITRUM]: "0x2d01411773c8C24805306E89A41F7855C3c4Fe65",
|
|
30
|
+
[CHAINS_ENUM.AVAX]: "0x661E93cca42AfacB172121EF892830cA3b70F08d",
|
|
31
|
+
[CHAINS_ENUM.BASE]: "0xd6145b2D3F379919E8CdEda7B97e37c4b2Ca9c40",
|
|
32
|
+
[CHAINS_ENUM.BLAST]: "0x661E93cca42AfacB172121EF892830cA3b70F08d",
|
|
33
|
+
[CHAINS_ENUM.CELO]: "0x02E5be68D46DAc0B524905bfF209cf47EE6dB2a9",
|
|
34
|
+
[CHAINS_ENUM.ERA]: "0x28731BCC616B5f51dD52CF2e4dF0E78dD1136C06",
|
|
35
|
+
["UNI"]: "0xD1b797D92d87B688193A2B976eFc8D577D204343",
|
|
36
|
+
["TEMPO"]: "0x02E5be68D46DAc0B524905bfF209cf47EE6dB2a9",
|
|
37
|
+
["MONAD"]: "0xa6CE4F10d83dBdDAc17E68e1837ca9cE6a1b596e",
|
|
38
|
+
["HOOD"]: "0x204FAca1764B154221e35c0d20aBb3c525710498",
|
|
39
|
+
["ARC"]: "0x8702463e73f74d0b6765aBceb314Ef07aCb92650",
|
|
40
|
+
};
|
|
41
|
+
// Keep the pre-upgrade native entry points valid during the backend rollout.
|
|
42
|
+
export const UNI_LEGACY_NATIVE_TO_ADDRESSES = {
|
|
23
43
|
[CHAINS_ENUM.ETH]: "0x66a9893cC07D91D95644AEDD05D03f95e1dBA8Af",
|
|
24
44
|
[CHAINS_ENUM.OP]: "0x851116D9223fabED8E56C0E6b8Ad0c31d98B3507",
|
|
25
45
|
[CHAINS_ENUM.BSC]: "0x1906c1d672b88cD1B9aC7593301cA990F94Eae07",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CHAINS_ENUM } from "@debank/common";
|
|
2
2
|
import { DEX_ENUM } from "../consts";
|
|
3
|
-
/** Uni 的 native 输入(含 Arc ERC20 USDC
|
|
3
|
+
/** Uni 的 native 输入(含 Arc ERC20 USDC)按链选择执行入口,其余走 proxy。 */
|
|
4
4
|
export declare const getRouter: (dexId: DEX_ENUM, chain: CHAINS_ENUM, payTokenId: string, nativeTokenAddress: string) => string | undefined;
|
|
5
5
|
/** wrap 无 spender;其余读白名单。 */
|
|
6
6
|
export declare const getSpender: (dexId: DEX_ENUM, chain: CHAINS_ENUM) => string | undefined;
|
package/dist/verify/contracts.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ARC_ERC20_USDC, DEX_ENUM } from "../consts";
|
|
2
|
-
import { UNI_NATIVE_TO_ADDRESSES } from "../dexs/uni";
|
|
2
|
+
import { UNI_LEGACY_NATIVE_TO_ADDRESSES, UNI_NATIVE_TO_ADDRESSES, } from "../dexs/uni";
|
|
3
3
|
import { DEX_ROUTER_WHITELIST, DEX_SPENDER_WHITELIST } from "../list";
|
|
4
4
|
import { isSameAddress } from "../utils";
|
|
5
5
|
import { isSwapWrapToken } from "./wrap";
|
|
6
6
|
const isNativeToken = (tokenId, nativeTokenAddress) => isSameAddress(tokenId, nativeTokenAddress);
|
|
7
|
-
|
|
7
|
+
const isUniNativeInput = (dexId, chain, payTokenId, nativeTokenAddress) => dexId === DEX_ENUM.UNI &&
|
|
8
|
+
(isNativeToken(payTokenId, nativeTokenAddress) ||
|
|
9
|
+
(chain === "ARC" &&
|
|
10
|
+
isSameAddress(payTokenId, ARC_ERC20_USDC)));
|
|
11
|
+
/** Uni 的 native 输入(含 Arc ERC20 USDC)按链选择执行入口,其余走 proxy。 */
|
|
8
12
|
export const getRouter = (dexId, chain, payTokenId, nativeTokenAddress) => {
|
|
9
|
-
if (dexId
|
|
10
|
-
(isNativeToken(payTokenId, nativeTokenAddress) ||
|
|
11
|
-
(chain === "ARC" &&
|
|
12
|
-
isSameAddress(payTokenId, ARC_ERC20_USDC)))) {
|
|
13
|
+
if (isUniNativeInput(dexId, chain, payTokenId, nativeTokenAddress)) {
|
|
13
14
|
return UNI_NATIVE_TO_ADDRESSES[chain];
|
|
14
15
|
}
|
|
15
16
|
const list = DEX_ROUTER_WHITELIST[dexId];
|
|
@@ -41,11 +42,14 @@ export const verifyRouterAndSpender = (p) => {
|
|
|
41
42
|
}
|
|
42
43
|
const routerWhitelist = getRouter(dexId, chain, payTokenId, nativeTokenAddress);
|
|
43
44
|
const spenderWhitelist = getSpender(dexId, chain);
|
|
45
|
+
const routerPass = isSameAddress(routerWhitelist || "", router) ||
|
|
46
|
+
(isUniNativeInput(dexId, chain, payTokenId, nativeTokenAddress) &&
|
|
47
|
+
isSameAddress(UNI_LEGACY_NATIVE_TO_ADDRESSES[chain] || "", router));
|
|
44
48
|
const skipSpender = !spender ||
|
|
45
49
|
isNativeToken(payTokenId, nativeTokenAddress) ||
|
|
46
50
|
isSwapWrapToken(payTokenId, receiveTokenId, chain, nativeTokenAddress);
|
|
47
51
|
return [
|
|
48
|
-
|
|
52
|
+
routerPass,
|
|
49
53
|
skipSpender ? true : isSameAddress(spenderWhitelist || "", spender),
|
|
50
54
|
];
|
|
51
55
|
};
|