@rabby-wallet/rabby-swap 0.0.88-alpha.4 → 0.0.89-alpha.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.
@@ -11,7 +11,7 @@ export const decodeDexAggregator = (data) => ({
11
11
  // LibRouter.getData(): byte 274 holds the fee count, followed by three
12
12
  // arrays of compact descriptors (asset, receiver, amount), 3 bytes per entry.
13
13
  // transferFees() transfers these separately from the swap's amountIn.
14
- // Only fees paid in the input asset belong in its total debit.
14
+ // Only input-asset fees fit the single-asset payment checked against the quote.
15
15
  // https://sourcify.dev/server/v2/contract/42161/0x20F6ee51340aDEed01A59B0e65cB3703f3dc860c?fields=sources
16
16
  // https://docs.fly.trade/developers/api-reference/evm-swap-integration-guide#step-1-get-a-quote
17
17
  export const decodeDexAggregatorInputFee = (data) => {
@@ -25,6 +25,8 @@ export const decodeDexAggregatorInputFee = (data) => {
25
25
  const amount = data.compact(amountOffset, amountOffset + 1);
26
26
  if (inputAsset.eq(asset))
27
27
  total = total.plus(amount);
28
+ else if (new BigNumber(amount).gt(0))
29
+ throw new Error("Non-input-asset Magpie fees are not supported");
28
30
  }
29
31
  return total.toFixed(0);
30
32
  };
@@ -1,11 +1,11 @@
1
- import { utils } from "ethers";
1
+ import { Interface } from "@ethersproject/abi";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { getNativeTokenAddress } from "../chain";
4
4
  import { isSameAddress, NULL_ADDRESS } from "../../utils";
5
5
  import { MagpieABI } from "./abi";
6
6
  import { decodeDexAggregator, decodeDexAggregatorInputFee, } from "./dexAggregator";
7
7
  import { PackedReader } from "./packed";
8
- const magpieInterface = new utils.Interface(MagpieABI);
8
+ const magpieInterface = new Interface(MagpieABI);
9
9
  const dexAggregatorSelector = magpieInterface.getSighash("swapWithBackendSignature");
10
10
  // Keep parsing details private and tied to the decoded result's lifetime.
11
11
  const decodedPayloads = new WeakMap();
@@ -15,7 +15,7 @@ const readPayload = (tx) => {
15
15
  throw new Error(`Unsupported Magpie calldata selector: ${selector}`);
16
16
  }
17
17
  const transaction = magpieInterface.parseTransaction({ data: tx.data });
18
- const payloadLength = utils.arrayify(transaction.args[0]).length;
18
+ const payloadLength = (transaction.args[0].length - 2) / 2;
19
19
  return new PackedReader(tx.data, payloadLength);
20
20
  };
21
21
  export const decodeInputFee = (tx, decoded) => {
@@ -1,4 +1,4 @@
1
- import { utils } from "ethers";
1
+ import { Interface } from "@ethersproject/abi";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { getNativeTokenAddress } from "../chain";
4
4
  import { UniABI } from "./abi";
@@ -6,7 +6,7 @@ import { chainToken, finishSwap } from "./shared";
6
6
  import { walkCommands } from "./universalRouter/commands";
7
7
  import { getRouterProfile } from "./universalRouter/profiles";
8
8
  import { normalizeUniAssets } from "./assets";
9
- const uniInterface = new utils.Interface(UniABI);
9
+ const uniInterface = new Interface(UniABI);
10
10
  export const decodeCalldata = (tx, options = {}) => {
11
11
  var _a;
12
12
  const native = getNativeTokenAddress(tx.chainId, options.nativeTokenAddress);
@@ -128,9 +128,10 @@ export const setOutput = (swap, ctx, token, recipient, minimum, exactAmount = fa
128
128
  .toFixed();
129
129
  return;
130
130
  }
131
- // A trailing sweep of the original input is a refund. It must not replace
132
- // an already identified payout in a different asset.
133
- if (isInputRefund(swap, ctx, output))
131
+ // Only input returned to the user is a refund; third-party transfers must
132
+ // remain visible to the final payout checks.
133
+ if (isInputRefund(swap, ctx, output) &&
134
+ isSameAddress(resolveRecipient(recipient, ctx), ctx.sender))
134
135
  return;
135
136
  recordPayout(swap, ctx, output, recipient, amount);
136
137
  };
@@ -8,8 +8,11 @@ export const walkCommands = (commands, inputs, swap, ctx, profile) => {
8
8
  if (hex.length / 2 !== inputs.length)
9
9
  throw new Error("Commands and inputs lengths differ");
10
10
  for (let i = 0; i < inputs.length; i++) {
11
- // Strip execution flags before passing the command to the SDK parser.
12
- const command = parseInt(hex.slice(i * 2, i * 2 + 2), 16) & profile.commandMask;
11
+ const commandByte = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
12
+ const command = commandByte & profile.commandMask;
13
+ // Optional sub-plans do not guarantee their decoded minimum output.
14
+ if (command === CommandType.EXECUTE_SUB_PLAN && (commandByte & 0x80) !== 0)
15
+ throw new Error("Sub-plans with allow-revert are not supported");
13
16
  const unsupported = () => new Error(`Unsupported command 0x${command.toString(16)} for the current exact-input quote flow (Router ${profile.version})`);
14
17
  if (command === CommandType.V4_SWAP) {
15
18
  if (profile.version === UniversalRouterVersion.V1_2) {
@@ -1,19 +1,19 @@
1
1
  import { CommandParser, CommandType } from "@uniswap/universal-router-sdk";
2
- import { utils } from "ethers";
2
+ import { defaultAbiCoder } from "@ethersproject/abi";
3
3
  const planTypes = ["bytes", "bytes[]"];
4
4
  export const readPlan = (input) => {
5
- const [commands, inputs] = utils.defaultAbiCoder.decode(planTypes, input);
5
+ const [commands, inputs] = defaultAbiCoder.decode(planTypes, input);
6
6
  return { commands: commands, inputs: inputs };
7
7
  };
8
8
  export const paramValues = (params) => Object.fromEntries(params.map(({ name, value }) => [name, value]));
9
9
  // The SDK selects version-specific parameter schemas and V3 path parsers.
10
10
  export const decodeCommand = (command, input, version) => {
11
- const calldata = CommandParser.INTERFACE.encodeFunctionData("execute(bytes,bytes[])", [utils.hexlify(command), [input]]);
11
+ const calldata = CommandParser.INTERFACE.encodeFunctionData("execute(bytes,bytes[])", [`0x${command.toString(16).padStart(2, "0")}`, [input]]);
12
12
  return CommandParser.parseCalldata(calldata, version).commands[0];
13
13
  };
14
14
  export const decodeV4Action = (action, input, version) => {
15
- const plan = utils.defaultAbiCoder.encode(planTypes, [
16
- utils.hexlify(action),
15
+ const plan = defaultAbiCoder.encode(planTypes, [
16
+ `0x${action.toString(16).padStart(2, "0")}`,
17
17
  [input],
18
18
  ]);
19
19
  const decoded = decodeCommand(CommandType.V4_SWAP, plan, version).params[0];
@@ -1,18 +1,24 @@
1
- import { Token, V2_FACTORY_ADDRESSES } from "@uniswap/sdk-core";
2
- import { computePairAddress } from "@uniswap/v2-sdk";
1
+ import { isAddress, soliditySha3Raw, toChecksumAddress } from "web3-utils";
2
+ import { UNI_V2_FACTORY_ADDRESSES, UNI_V2_PAIR_INIT_CODE_HASH, } from "../../../consts";
3
3
  // A mixed route can pay directly into the next V2 pair instead of the Router.
4
4
  // Use the official chain-specific factory and CREATE2 derivation; never guess a
5
5
  // mainnet factory when deployment metadata is missing.
6
6
  // https://github.com/Uniswap/sdks/blob/main/sdks/universal-router-sdk/src/entities/actions/uniswap.ts
7
7
  // https://github.com/Uniswap/sdks/blob/main/sdks/v2-sdk/src/entities/pair.ts
8
8
  export const getV2InputPair = (chainId, path) => {
9
- const factoryAddress = V2_FACTORY_ADDRESSES[chainId];
9
+ const factoryAddress = UNI_V2_FACTORY_ADDRESSES[chainId];
10
10
  if (!factoryAddress)
11
11
  return undefined;
12
- return computePairAddress({
13
- factoryAddress,
14
- // Only chain and addresses participate in CREATE2; decimals are unused.
15
- tokenA: new Token(chainId, path[0], 0),
16
- tokenB: new Token(chainId, path[1], 0),
17
- });
12
+ if (!isAddress(path[0]) || !isAddress(path[1])) {
13
+ throw new Error("Invalid V2 token address");
14
+ }
15
+ const [token0, token1] = path
16
+ .slice(0, 2)
17
+ .map((token) => token.toLowerCase())
18
+ .sort();
19
+ if (token0 === token1)
20
+ throw new Error("V2 pair requires two distinct tokens");
21
+ const salt = soliditySha3Raw({ type: "address", value: token0 }, { type: "address", value: token1 });
22
+ const hash = soliditySha3Raw({ type: "bytes1", value: "0xff" }, { type: "address", value: factoryAddress }, { type: "bytes32", value: salt }, { type: "bytes32", value: UNI_V2_PAIR_INIT_CODE_HASH });
23
+ return toChecksumAddress(`0x${hash.slice(-40)}`);
18
24
  };
package/dist/consts.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export declare const UNI_V2_FACTORY_ADDRESSES: Record<number, string>;
2
+ export declare const UNI_V2_PAIR_INIT_CODE_HASH = "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f";
1
3
  /** Arc ERC-20 USDC (6 decimals); dual view of native gas USDC (18 decimals). */
2
4
  export declare const ARC_ERC20_USDC = "0x3600000000000000000000000000000000000000";
3
5
  export declare enum DEX_ENUM {
package/dist/consts.js CHANGED
@@ -1,3 +1,32 @@
1
+ // Uniswap sdk-core 7.19.4 / v2-sdk 4.21.5 deployment constants.
2
+ export const UNI_V2_FACTORY_ADDRESSES = {
3
+ "1": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
4
+ "5": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
5
+ "10": "0x0c3c1c532F1e39EdF36BE9Fe0bE1410313E074Bf",
6
+ "56": "0x8909Dc15e40173Ff4699343b6eB8132c65e18eC6",
7
+ "130": "0x1f98400000000000000000000000000000000002",
8
+ "137": "0x9e5A52f57b3038F1B8EeE45F28b3C1967e22799C",
9
+ "143": "0x182a927119d56008d921126764bf884221b10f59",
10
+ "196": "0xdf38f24fe153761634be942f9d859f3dba857e95",
11
+ "480": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
12
+ "1301": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
13
+ "1868": "0x97febbc2adbd5644ba22736e962564b23f5828ce",
14
+ "4217": "0xf9ec577a4e45b5278bb7cf60fcbc20c3acaef68f",
15
+ "4326": "0xbf56488c857a881ae7e3bed27cf99c10a7ab7e50",
16
+ "4663": "0x8bceaa40b9acdfaedf85adf4ff01f5ad6517937f",
17
+ "5042": "0x89e5db8b5aa49aa85ac63f691524311aeb649eba",
18
+ "8453": "0x8909dc15e40173ff4699343b6eb8132c65e18ec6",
19
+ "10143": "0x733e88f248b742db6c14c0b1713af5ad7fdd59d0",
20
+ "42161": "0xf1D7CC64Fb4452F05c498126312eBE29f30Fbcf9",
21
+ "42220": "0x79a530c8e2fA8748B7B40dd3629C0520c2cCf03f",
22
+ "43114": "0x9e5A52f57b3038F1B8EeE45F28b3C1967e22799C",
23
+ "57073": "0xfe57a6ba1951f69ae2ed4abe23e0f095df500c04",
24
+ "59144": "0x114A43DF6C5f54EBB8A9d70Cd1951D3dD68004c7",
25
+ "81457": "0x5C346464d33F90bABaf70dB6388507CC889C1070",
26
+ "84532": "0x7Ae58f10f7849cA6F5fB71b7f45CB416c9204b1e",
27
+ "11155111": "0xF62c03E08ada871A0bEb309762E260a7a6a880E6",
28
+ };
29
+ export const UNI_V2_PAIR_INIT_CODE_HASH = "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f";
1
30
  /** Arc ERC-20 USDC (6 decimals); dual view of native gas USDC (18 decimals). */
2
31
  export const ARC_ERC20_USDC = "0x3600000000000000000000000000000000000000";
3
32
  export var DEX_ENUM;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-swap",
3
- "version": "0.0.88-alpha.4",
3
+ "version": "0.0.89-alpha.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -19,13 +19,11 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@ethersproject/abi": "^5.7.0",
22
- "@uniswap/sdk-core": "7.19.4",
23
22
  "@uniswap/universal-router-sdk": "5.14.0",
24
- "@uniswap/v2-sdk": "4.21.5",
25
23
  "axios": "^0.27.2",
26
24
  "bignumber.js": "^9.1.1",
27
- "ethers": "5.8.0",
28
- "web3-eth-abi": "^1.8.1"
25
+ "web3-eth-abi": "^1.8.1",
26
+ "web3-utils": "1.8.1"
29
27
  },
30
28
  "devDependencies": {
31
29
  "@debank/common": "^0.3.60",