@gearbox-protocol/sdk 3.0.0-vfour.380 → 3.0.0-vfour.382

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.
@@ -21,6 +21,7 @@ __export(UniswapV2AdapterContract_exports, {
21
21
  UniswapV2AdapterContract: () => UniswapV2AdapterContract
22
22
  });
23
23
  module.exports = __toCommonJS(UniswapV2AdapterContract_exports);
24
+ var import_sdk = require("../sdk/index.js");
24
25
  var import_abi = require("./abi/index.js");
25
26
  var import_AbstractAdapter = require("./AbstractAdapter.js");
26
27
  const abi = import_abi.iUniswapV2AdapterAbi;
@@ -31,6 +32,26 @@ class UniswapV2AdapterContract extends import_AbstractAdapter.AbstractAdapterCon
31
32
  abi
32
33
  });
33
34
  }
35
+ parseFunctionParams(params) {
36
+ switch (params.functionName) {
37
+ case "swapDiffTokensForTokens": {
38
+ const [leftoverAmount, rateMinRAY, path, _deadline] = params.args;
39
+ const leftoverAmountStr = this.sdk.tokensMeta.formatBN(
40
+ path[0],
41
+ leftoverAmount
42
+ );
43
+ const pathStr = path.map((t) => this.labelAddress(t)).join(" => ");
44
+ return [
45
+ `(leftoverAmount: ${leftoverAmountStr}, rate: ${(0, import_sdk.formatBN)(
46
+ rateMinRAY,
47
+ 27
48
+ )}, path: ${pathStr}`
49
+ ];
50
+ }
51
+ default:
52
+ return void 0;
53
+ }
54
+ }
34
55
  }
35
56
  // Annotate the CommonJS export names for ESM import in node:
36
57
  0 && (module.exports = {
@@ -114,43 +114,29 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
114
114
  },
115
115
  "calling routeOpenManyToOne"
116
116
  );
117
- try {
118
- const { result } = await this.contract.simulate.routeOpenManyToOne([
119
- cm.address,
117
+ const { result } = await this.contract.simulate.routeOpenManyToOne([
118
+ cm.address,
119
+ target,
120
+ BigInt(slippage),
121
+ tData
122
+ ]);
123
+ return {
124
+ balances: balancesAfterOpen(
120
125
  target,
121
- BigInt(slippage),
122
- tData
123
- ]);
124
- return {
125
- balances: balancesAfterOpen(
126
- target,
127
- result.amount,
128
- expectedMap,
129
- leftoverMap
130
- ),
131
- minBalances: balancesAfterOpen(
132
- target,
133
- result.minAmount,
134
- expectedMap,
135
- leftoverMap
136
- ),
137
- amount: result.amount,
138
- minAmount: result.minAmount,
139
- calls: [...result.calls]
140
- };
141
- } catch (e) {
142
- if (e instanceof import_viem.ContractFunctionExecutionError) {
143
- const callData = (0, import_viem.encodeFunctionData)({
144
- abi: e.abi,
145
- args: e.args,
146
- functionName: e.functionName
147
- });
148
- console.log(
149
- `cast call --trace --rpc-url https://carrot.megaeth.com/rpc ${e.contractAddress} ${callData}`
150
- );
151
- }
152
- throw e;
153
- }
126
+ result.amount,
127
+ expectedMap,
128
+ leftoverMap
129
+ ),
130
+ minBalances: balancesAfterOpen(
131
+ target,
132
+ result.minAmount,
133
+ expectedMap,
134
+ leftoverMap
135
+ ),
136
+ amount: result.amount,
137
+ minAmount: result.minAmount,
138
+ calls: [...result.calls]
139
+ };
154
140
  }
155
141
  /**
156
142
  * Implements {@link IRouterContract.findBestClosePath}
@@ -54,12 +54,13 @@ const getTestnetByMainnet = (mainnetId) => TESTNET_BY_MAINNET_ID[mainnetId];
54
54
  const getMainnetByTestnet = (testnetId) => MAINNET_BY_TESTNET_ID[testnetId];
55
55
  const getTestNetworkType = (chainId) => CHAINS_BY_ID[chainId];
56
56
  const isTestNetwork = (chainId) => chainId !== void 0 && !!CHAINS_BY_ID[chainId];
57
+ const HARDHAT = 1337;
57
58
  const CHARTS_BACKEND_ADDRESSES = {
58
59
  ...Object.values(import_chain.chains).reduce((acc, chain) => {
59
60
  acc[chain.id] = "https://charts-server.fly.dev";
60
61
  return acc;
61
62
  }, {}),
62
- 1337: "https://charts-server.fly.dev",
63
+ [HARDHAT]: "https://charts-server.fly.dev",
63
64
  [TESTNET_CHAINS.Mainnet]: "https://testnet.gearbox.foundation",
64
65
  [TESTNET_CHAINS.Arbitrum]: "https://arbtest.gearbox.foundation",
65
66
  [TESTNET_CHAINS.Optimism]: "https://opttest.gearbox.foundation"
@@ -70,6 +71,7 @@ const LEADERBOARD_APIS = {
70
71
  [import_chain.chains.Mainnet.id]: "https://gpointbot.fly.dev",
71
72
  [import_chain.chains.Optimism.id]: "https://gpointbot.fly.dev",
72
73
  [import_chain.chains.Arbitrum.id]: "https://gpointbot.fly.dev",
74
+ [HARDHAT]: "https://gpointbot.fly.dev",
73
75
  // !& new chains
74
76
  [TESTNET_CHAINS.Mainnet]: "https://testnet.gearbox.foundation/gpointbot",
75
77
  [TESTNET_CHAINS.Optimism]: "https://testnet.gearbox.foundation/gpointbot",
@@ -81,7 +83,7 @@ class GearboxBackendApi {
81
83
  static getChartsUrl = (url, chainId, options = { params: {} }, priceSource) => {
82
84
  const domain = CHARTS_BACKEND_ADDRESSES[chainId];
83
85
  const priceSourceArr = priceSource ? [priceSource] : [];
84
- const isMain = (0, import_chain.isSupportedNetwork)(chainId);
86
+ const isMain = (0, import_chain.isSupportedNetwork)(chainId) || chainId === HARDHAT;
85
87
  const relativePath = URLApi.getRelativeUrl(
86
88
  url,
87
89
  isMain ? {
@@ -1,3 +1,4 @@
1
+ import { formatBN } from "../sdk/index.js";
1
2
  import { iUniswapV2AdapterAbi } from "./abi/index.js";
2
3
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
3
4
  const abi = iUniswapV2AdapterAbi;
@@ -8,6 +9,26 @@ class UniswapV2AdapterContract extends AbstractAdapterContract {
8
9
  abi
9
10
  });
10
11
  }
12
+ parseFunctionParams(params) {
13
+ switch (params.functionName) {
14
+ case "swapDiffTokensForTokens": {
15
+ const [leftoverAmount, rateMinRAY, path, _deadline] = params.args;
16
+ const leftoverAmountStr = this.sdk.tokensMeta.formatBN(
17
+ path[0],
18
+ leftoverAmount
19
+ );
20
+ const pathStr = path.map((t) => this.labelAddress(t)).join(" => ");
21
+ return [
22
+ `(leftoverAmount: ${leftoverAmountStr}, rate: ${formatBN(
23
+ rateMinRAY,
24
+ 27
25
+ )}, path: ${pathStr}`
26
+ ];
27
+ }
28
+ default:
29
+ return void 0;
30
+ }
31
+ }
11
32
  }
12
33
  export {
13
34
  UniswapV2AdapterContract
@@ -1,8 +1,4 @@
1
- import {
2
- ContractFunctionExecutionError,
3
- encodeFunctionData,
4
- getAddress
5
- } from "viem";
1
+ import { getAddress } from "viem";
6
2
  import { iGearboxRouterV310Abi } from "../../abi/routerV310.js";
7
3
  import { BigIntMath } from "../sdk-legacy/index.js";
8
4
  import { AddressMap } from "../utils/AddressMap.js";
@@ -95,43 +91,29 @@ class RouterV310Contract extends AbstractRouterContract {
95
91
  },
96
92
  "calling routeOpenManyToOne"
97
93
  );
98
- try {
99
- const { result } = await this.contract.simulate.routeOpenManyToOne([
100
- cm.address,
94
+ const { result } = await this.contract.simulate.routeOpenManyToOne([
95
+ cm.address,
96
+ target,
97
+ BigInt(slippage),
98
+ tData
99
+ ]);
100
+ return {
101
+ balances: balancesAfterOpen(
101
102
  target,
102
- BigInt(slippage),
103
- tData
104
- ]);
105
- return {
106
- balances: balancesAfterOpen(
107
- target,
108
- result.amount,
109
- expectedMap,
110
- leftoverMap
111
- ),
112
- minBalances: balancesAfterOpen(
113
- target,
114
- result.minAmount,
115
- expectedMap,
116
- leftoverMap
117
- ),
118
- amount: result.amount,
119
- minAmount: result.minAmount,
120
- calls: [...result.calls]
121
- };
122
- } catch (e) {
123
- if (e instanceof ContractFunctionExecutionError) {
124
- const callData = encodeFunctionData({
125
- abi: e.abi,
126
- args: e.args,
127
- functionName: e.functionName
128
- });
129
- console.log(
130
- `cast call --trace --rpc-url https://carrot.megaeth.com/rpc ${e.contractAddress} ${callData}`
131
- );
132
- }
133
- throw e;
134
- }
103
+ result.amount,
104
+ expectedMap,
105
+ leftoverMap
106
+ ),
107
+ minBalances: balancesAfterOpen(
108
+ target,
109
+ result.minAmount,
110
+ expectedMap,
111
+ leftoverMap
112
+ ),
113
+ amount: result.amount,
114
+ minAmount: result.minAmount,
115
+ calls: [...result.calls]
116
+ };
135
117
  }
136
118
  /**
137
119
  * Implements {@link IRouterContract.findBestClosePath}
@@ -25,12 +25,13 @@ const getTestnetByMainnet = (mainnetId) => TESTNET_BY_MAINNET_ID[mainnetId];
25
25
  const getMainnetByTestnet = (testnetId) => MAINNET_BY_TESTNET_ID[testnetId];
26
26
  const getTestNetworkType = (chainId) => CHAINS_BY_ID[chainId];
27
27
  const isTestNetwork = (chainId) => chainId !== void 0 && !!CHAINS_BY_ID[chainId];
28
+ const HARDHAT = 1337;
28
29
  const CHARTS_BACKEND_ADDRESSES = {
29
30
  ...Object.values(CHAINS).reduce((acc, chain) => {
30
31
  acc[chain.id] = "https://charts-server.fly.dev";
31
32
  return acc;
32
33
  }, {}),
33
- 1337: "https://charts-server.fly.dev",
34
+ [HARDHAT]: "https://charts-server.fly.dev",
34
35
  [TESTNET_CHAINS.Mainnet]: "https://testnet.gearbox.foundation",
35
36
  [TESTNET_CHAINS.Arbitrum]: "https://arbtest.gearbox.foundation",
36
37
  [TESTNET_CHAINS.Optimism]: "https://opttest.gearbox.foundation"
@@ -41,6 +42,7 @@ const LEADERBOARD_APIS = {
41
42
  [CHAINS.Mainnet.id]: "https://gpointbot.fly.dev",
42
43
  [CHAINS.Optimism.id]: "https://gpointbot.fly.dev",
43
44
  [CHAINS.Arbitrum.id]: "https://gpointbot.fly.dev",
45
+ [HARDHAT]: "https://gpointbot.fly.dev",
44
46
  // !& new chains
45
47
  [TESTNET_CHAINS.Mainnet]: "https://testnet.gearbox.foundation/gpointbot",
46
48
  [TESTNET_CHAINS.Optimism]: "https://testnet.gearbox.foundation/gpointbot",
@@ -52,7 +54,7 @@ class GearboxBackendApi {
52
54
  static getChartsUrl = (url, chainId, options = { params: {} }, priceSource) => {
53
55
  const domain = CHARTS_BACKEND_ADDRESSES[chainId];
54
56
  const priceSourceArr = priceSource ? [priceSource] : [];
55
- const isMain = isSupportedNetwork(chainId);
57
+ const isMain = isSupportedNetwork(chainId) || chainId === HARDHAT;
56
58
  const relativePath = URLApi.getRelativeUrl(
57
59
  url,
58
60
  isMain ? {
@@ -1,3 +1,4 @@
1
+ import type { DecodeFunctionDataReturnType } from "viem";
1
2
  import type { GearboxSDK } from "../sdk/index.js";
2
3
  import type { AbstractAdapterContractOptions } from "./AbstractAdapter.js";
3
4
  import { AbstractAdapterContract } from "./AbstractAdapter.js";
@@ -205,5 +206,6 @@ declare const abi: readonly [{
205
206
  }];
206
207
  export declare class UniswapV2AdapterContract extends AbstractAdapterContract<typeof abi> {
207
208
  constructor(sdk: GearboxSDK, args: Omit<AbstractAdapterContractOptions<typeof abi>, "abi">);
209
+ protected parseFunctionParams(params: DecodeFunctionDataReturnType<typeof abi>): string[] | undefined;
208
210
  }
209
211
  export {};
@@ -135,7 +135,7 @@ export interface FindOneTokenPathProps {
135
135
  */
136
136
  tokenOut: Address;
137
137
  /**
138
- * Incominga mount of tokenIn to swap
138
+ * Incoming amount of tokenIn to swap
139
139
  */
140
140
  amount: bigint;
141
141
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-vfour.380",
3
+ "version": "3.0.0-vfour.382",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",