@rabby-wallet/rabby-swap 0.0.88-alpha.2 → 0.0.88-alpha.3

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 CHANGED
@@ -337,3 +337,4 @@ export declare const SushiABI: ({
337
337
  })[];
338
338
  export { UniABI } from "./calldata/uni/abi";
339
339
  export { MagpieABI } from "./calldata/magpie/abi";
340
+ export declare const PancakeSwapABI: string[];
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
+ ];
@@ -1,5 +1,8 @@
1
- import { CHAINS_ENUM } from "@debank/common";
2
- import { generateGetQuote } from "../utils";
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
- return null;
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-swap",
3
- "version": "0.0.88-alpha.2",
3
+ "version": "0.0.88-alpha.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {