@gearbox-protocol/sdk 2.1.31 → 2.1.33

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.
@@ -2,7 +2,7 @@ import { TradeType } from "../pathfinder/tradeTypes";
2
2
  import { NormalToken } from "./normal";
3
3
  import type { TokenBase } from "./token";
4
4
  import { TokenType } from "./tokenType";
5
- export type BalancerLPToken = "50OHM_50DAI" | "50OHM_50WETH" | "OHM_wstETH" | "USDC-DAI-USDT";
5
+ export type BalancerLPToken = "50OHM_50DAI" | "50OHM_50WETH" | "OHM_wstETH" | "USDC_DAI_USDT";
6
6
  export type BalancerLpTokenData = {
7
7
  symbol: BalancerLPToken;
8
8
  type: TokenType.BALANCER_LP_TOKEN;
@@ -46,9 +46,9 @@ exports.balancerLpTokens = {
46
46
  },
47
47
  ],
48
48
  },
49
- "USDC-DAI-USDT": {
50
- name: "Balancer USDC-DAI-USDT",
51
- symbol: "USDC-DAI-USDT",
49
+ USDC_DAI_USDT: {
50
+ name: "Balancer USDC_DAI_USDT",
51
+ symbol: "USDC_DAI_USDT",
52
52
  type: tokenType_1.TokenType.BALANCER_LP_TOKEN,
53
53
  underlying: ["USDC", "DAI", "USDT"],
54
54
  poolId: "0x79c58f70905f734641735bc61e45c19dd9ad60bc0000000000000000000004e7",
@@ -97,7 +97,7 @@ exports.decimals = {
97
97
  "50OHM_50DAI": 18,
98
98
  "50OHM_50WETH": 18,
99
99
  OHM_wstETH: 18,
100
- "USDC-DAI-USDT": 18,
100
+ USDC_DAI_USDT: 18,
101
101
  aDAI: 18,
102
102
  aUSDC: 6,
103
103
  aUSDT: 6,
@@ -125,7 +125,7 @@ exports.tokenDataByNetwork = {
125
125
  "50OHM_50DAI": "0x76FCf0e8C7Ff37A47a799FA2cd4c13cDe0D981C9",
126
126
  "50OHM_50WETH": "0xD1eC5e215E8148D76F4460e4097FD3d5ae0A3558",
127
127
  OHM_wstETH: "0xd4f79CA0Ac83192693bce4699d0c10C66Aa6Cf0F",
128
- "USDC-DAI-USDT": "0x79c58f70905f734641735bc61e45c19dd9ad60bc",
128
+ USDC_DAI_USDT: "0x79c58f70905F734641735BC61e45c19dD9Ad60bC",
129
129
  // GEARBOX
130
130
  dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
131
131
  dUSDC: "0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3",
@@ -251,7 +251,7 @@ exports.tokenDataByNetwork = {
251
251
  "50OHM_50DAI": constants_1.NOT_DEPLOYED,
252
252
  "50OHM_50WETH": "0x89dc7e71e362faF88D92288fE2311D25c6a1B5E0",
253
253
  OHM_wstETH: constants_1.NOT_DEPLOYED,
254
- "USDC-DAI-USDT": constants_1.NOT_DEPLOYED,
254
+ USDC_DAI_USDT: constants_1.NOT_DEPLOYED,
255
255
  // GEARBOX
256
256
  dDAI: constants_1.NOT_DEPLOYED,
257
257
  dUSDC: constants_1.NOT_DEPLOYED,
@@ -7,6 +7,21 @@ const types_1 = require("../types");
7
7
  const multicall_1 = require("../utils/multicall");
8
8
  const token_1 = require("./token");
9
9
  const erc20 = types_1.IERC20Metadata__factory.createInterface();
10
+ // Some contracts return something other than string for symbol
11
+ const NON_ERC20_SYMBOLS = {
12
+ [token_1.tokenDataByNetwork.Mainnet.MKR]: {
13
+ interface: new ethers_1.ethers.utils.Interface([
14
+ "function symbol() view returns (bytes32)",
15
+ ]),
16
+ // convert bytes32 to string
17
+ stringifySymbol: (result) => ethers_1.ethers.utils
18
+ .toUtf8String(ethers_1.ethers.utils.arrayify(result))
19
+ .replaceAll(String.fromCharCode(0), ""), // trim tail of zeroes
20
+ },
21
+ };
22
+ function identity(value) {
23
+ return value;
24
+ }
10
25
  const EXCEPTIONS_IN_SYMBOLS = {
11
26
  Mainnet: {
12
27
  // Our Symbol <-> On-chain Symbol
@@ -38,7 +53,7 @@ class TokenSuite {
38
53
  const entries = Object.entries(token_1.tokenDataByNetwork[network]).filter(([_, addr]) => addr?.startsWith("0x"));
39
54
  this.calls = entries.map(([symbol, address]) => ({
40
55
  address,
41
- interface: erc20,
56
+ interface: NON_ERC20_SYMBOLS[address]?.interface ?? erc20,
42
57
  method: "symbol()",
43
58
  key: symbol,
44
59
  }));
@@ -46,6 +61,7 @@ class TokenSuite {
46
61
  async fetchSymbols() {
47
62
  // even safe multicall fails when one of addresses is an EOA and not contract address
48
63
  if (this.network === "Arbitrum") {
64
+ // if (true) {
49
65
  for (const call of this.calls) {
50
66
  const c = types_1.IERC20Metadata__factory.connect(call.address, this.provider);
51
67
  try {
@@ -68,10 +84,15 @@ class TokenSuite {
68
84
  for (let i = 0; i < resps.length; i++) {
69
85
  const call = this.calls[i];
70
86
  const resp = resps[i];
87
+ // most symbols are ok, but some return non-string value for symbol.
88
+ // stringifySymbol makes sure that we get symbol as string
89
+ const stringifySymbol = NON_ERC20_SYMBOLS[call.address]?.stringifySymbol ?? identity;
71
90
  this.responses[call.key] = {
72
91
  address: call.address,
73
- symbol: resp.error ? undefined : this.sanitize(resp.value ?? ""),
74
- error: resp.error ? new Error("multicall error") : undefined,
92
+ symbol: resp.error
93
+ ? undefined
94
+ : this.sanitize(stringifySymbol(resp.value ?? "")),
95
+ error: resp.error,
75
96
  };
76
97
  }
77
98
  }
@@ -84,7 +105,7 @@ class TokenSuite {
84
105
  assertSymbol(sdkSymbol) {
85
106
  const r = this.responses[sdkSymbol];
86
107
  if (r.error) {
87
- throw new Error(`failed to verify ${sdkSymbol} on address ${r.address}: ${console.error}`);
108
+ throw new Error(`failed to verify ${sdkSymbol} on address ${r.address}: ${r.error}`);
88
109
  }
89
110
  const expectedSymbol = EXCEPTIONS_IN_SYMBOLS[this.network][r.address] ?? sdkSymbol;
90
111
  if (r.symbol !== expectedSymbol) {
@@ -22,7 +22,7 @@ export declare function multicall<R extends Array<any>>(calls: Array<MCall<any>>
22
22
  * @returns
23
23
  */
24
24
  export declare function safeMulticall<V = any, T extends MCall<any> = MCall<any>>(calls: T[], p: Signer | ethers.providers.Provider, overrides?: CallOverrides): Promise<Array<{
25
- error: boolean;
25
+ error?: Error;
26
26
  value?: V;
27
27
  }>>;
28
28
  export declare class MultiCallContract<T extends ethers.utils.Interface> {
@@ -30,12 +30,27 @@ async function safeMulticall(calls, p, overrides) {
30
30
  target: c.address,
31
31
  callData: c.interface.encodeFunctionData(c.method, c.params),
32
32
  })), overrides ?? {});
33
- return resp.map((d, num) => ({
34
- error: !d.success,
35
- value: d.success
36
- ? unwrapArray(calls[num].interface.decodeFunctionResult(calls[num].method, d.returnData))
37
- : undefined,
38
- }));
33
+ return resp.map((d, num) => {
34
+ let value;
35
+ let error;
36
+ if (d.success) {
37
+ try {
38
+ value = unwrapArray(calls[num].interface.decodeFunctionResult(calls[num].method, d.returnData));
39
+ }
40
+ catch (e) {
41
+ if (e instanceof Error) {
42
+ error = e;
43
+ }
44
+ else {
45
+ error = new Error(`${e}`);
46
+ }
47
+ }
48
+ }
49
+ else {
50
+ error = new Error("multicall call failed");
51
+ }
52
+ return { error, value };
53
+ });
39
54
  }
40
55
  exports.safeMulticall = safeMulticall;
41
56
  function unwrapArray(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "2.1.31",
3
+ "version": "2.1.33",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",