@reyaxyz/common 0.115.0 → 0.117.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.
@@ -2,6 +2,9 @@ import { JsonRpcSigner, Signer } from 'ethers';
2
2
  import { ReyaChainId } from '../types';
3
3
  import { ContractType, getAddress } from './contractAddresses';
4
4
  import { getGasBuffer } from './txHelpers';
5
+ import { abi } from './abis/Errors.json';
6
+ import { ErrorDecoder } from 'ethers-decode-error';
7
+ import type { DecodedError } from 'ethers-decode-error';
5
8
 
6
9
  export type Transaction = {
7
10
  from: string;
@@ -9,6 +12,7 @@ export type Transaction = {
9
12
  data: string;
10
13
  value?: string;
11
14
  };
15
+ const errorDecoder = ErrorDecoder.create([abi]);
12
16
 
13
17
  export async function estimateGas(
14
18
  signer: Signer | JsonRpcSigner,
@@ -43,11 +47,12 @@ export async function estimateGas(
43
47
  const gasEstimate = await signer.estimateGas(tx);
44
48
  gasLimit = getGasBuffer(gasEstimate);
45
49
  } catch (error) {
46
- // sentry error & thorw
50
+ const decodedError = await errorDecoder.decode(error);
51
+ const reason = customReasonMapper(decodedError);
47
52
  console.error(
48
- `Error simulating transaction account address ${accountAddress} ${error}`,
53
+ `Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,
49
54
  );
50
- throw new Error('Error executing transaction'); // @todo introduce error parsing
55
+ throw new Error(reason);
51
56
  }
52
57
 
53
58
  if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {
@@ -83,3 +88,20 @@ export async function executeTransaction(
83
88
  throw new Error('Transaction Execution Error');
84
89
  }
85
90
  }
91
+ const customReasonMapper = ({ name, reason }: DecodedError): string => {
92
+ switch (name) {
93
+ case 'SignatureInvalid':
94
+ return `Invalid signature. Please refresh page and try again`;
95
+ case 'StalePriceDetected':
96
+ return `Price not updated, please try again a bit later`;
97
+ case 'SmallOrderSize':
98
+ return `Order size below minimum`;
99
+ case 'DustyOrderSize':
100
+ return `Order amount is not divisible by trade size spacing`;
101
+ case 'AccountBelowIM':
102
+ return `Account below required margin`;
103
+ default:
104
+ // This handles the non-custom errors
105
+ return reason ?? 'Error executing transaction';
106
+ }
107
+ };
package/src/types.ts CHANGED
@@ -636,6 +636,7 @@ export type TokenInfo = {
636
636
  minDepositAmount: number;
637
637
  minWithdrawAmount: number;
638
638
  minTransferAmount: number;
639
+ whitelistedWalletOnly?: boolean;
639
640
  };
640
641
 
641
642
  // --- TOS ----
@@ -2,3 +2,5 @@ export const MAX_UINT128 = 2 ** 128 - 1;
2
2
  export const API_TIMEOUT: number = 2500;
3
3
 
4
4
  export const CHANNEL_NAME: string = 'redis-pub-sub';
5
+
6
+ export const WHITELISTED_WALLETS = ['some_id'];
@@ -5,3 +5,4 @@ export * from './retry';
5
5
  export * from './timestamp';
6
6
  export * from './token';
7
7
  export * from './task-wrapper';
8
+ export * from './whitelisted-wallets';
@@ -39,6 +39,14 @@ export const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =
39
39
  ...defaultTokenThresholds,
40
40
  minWithdrawAmount: 28,
41
41
  },
42
+ {
43
+ name: 'WETH',
44
+ address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
45
+ decimals: 18,
46
+ isRUSDUnderlying: false,
47
+ whitelistedWalletOnly: true,
48
+ ...defaultTokenThresholds,
49
+ },
42
50
  ],
43
51
  [MoneyInOutChainId.opMainnet]: [
44
52
  {
@@ -49,6 +57,14 @@ export const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =
49
57
  ...defaultTokenThresholds,
50
58
  minWithdrawAmount: 10,
51
59
  },
60
+ {
61
+ name: 'WETH',
62
+ address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
63
+ decimals: 18,
64
+ isRUSDUnderlying: false,
65
+ whitelistedWalletOnly: true,
66
+ ...defaultTokenThresholds,
67
+ },
52
68
  ],
53
69
  [MoneyInOutChainId.polygonMainnet]: [
54
70
  {
@@ -59,6 +75,14 @@ export const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =
59
75
  ...defaultTokenThresholds,
60
76
  minWithdrawAmount: 10,
61
77
  },
78
+ {
79
+ name: 'WETH',
80
+ address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
81
+ decimals: 18,
82
+ isRUSDUnderlying: false,
83
+ whitelistedWalletOnly: true,
84
+ ...defaultTokenThresholds,
85
+ },
62
86
  ],
63
87
  [MoneyInOutChainId.arbitrumOne]: [
64
88
  {
@@ -69,6 +93,14 @@ export const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =
69
93
  ...defaultTokenThresholds,
70
94
  minWithdrawAmount: 10,
71
95
  },
96
+ {
97
+ name: 'WETH',
98
+ address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
99
+ decimals: 18,
100
+ isRUSDUnderlying: false,
101
+ whitelistedWalletOnly: true,
102
+ ...defaultTokenThresholds,
103
+ },
72
104
  ],
73
105
  [MoneyInOutChainId.baseMainnet]: [
74
106
  {
@@ -79,6 +111,14 @@ export const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =
79
111
  ...defaultTokenThresholds,
80
112
  minWithdrawAmount: 10,
81
113
  },
114
+ {
115
+ name: 'WETH',
116
+ address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',
117
+ decimals: 18,
118
+ isRUSDUnderlying: false,
119
+ whitelistedWalletOnly: true,
120
+ ...defaultTokenThresholds,
121
+ },
82
122
  ],
83
123
 
84
124
  /* ------------------------------------------------------ */
@@ -0,0 +1,4 @@
1
+ import { WHITELISTED_WALLETS } from './consts';
2
+
3
+ export const getIsWalletWhitelisted = (walletAddress: string) =>
4
+ WHITELISTED_WALLETS.includes(walletAddress);