@reyaxyz/common 0.135.1 → 0.136.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.
package/README.md CHANGED
@@ -6,5 +6,5 @@
6
6
 
7
7
  | Statements | Branches | Functions | Lines |
8
8
  | --------------------------- | ----------------------- | ------------------------- | ----------------- |
9
- | ![Statements](https://img.shields.io/badge/statements-13.84%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-13.33%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-9.16%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-14.33%25-red.svg?style=flat) |
9
+ | ![Statements](https://img.shields.io/badge/statements-13.83%25-red.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-12.94%25-red.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-8.82%25-red.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-14.36%25-red.svg?style=flat) |
10
10
 
@@ -46,17 +46,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var _a;
49
50
  Object.defineProperty(exports, "__esModule", { value: true });
50
51
  exports.executeTransaction = exports.estimateGas = void 0;
52
+ var ethers_1 = require("ethers");
51
53
  var types_1 = require("../types");
52
54
  var contractAddresses_1 = require("./contractAddresses");
53
- var txHelpers_1 = require("./txHelpers");
54
55
  var Errors_json_1 = require("./abis/Errors.json");
55
56
  var ethers_decode_error_1 = require("ethers-decode-error");
57
+ var reyaChainIdRPCMapper = (_a = {},
58
+ _a[types_1.ReyaChainId.reyaNetwork] = 'https://rpc.reya.network',
59
+ _a[types_1.ReyaChainId.reyaCronos] = 'https://rpc.reya-cronos.gelato.digital',
60
+ _a);
56
61
  var errorDecoder = ethers_decode_error_1.ErrorDecoder.create([Errors_json_1.abi]);
57
62
  function estimateGas(signer, data, value, chainId, targetContract) {
58
63
  return __awaiter(this, void 0, void 0, function () {
59
- var accountAddress, contractAddress, tx, gasLimit, gasEstimate, error_1, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
64
+ var accountAddress, contractAddress, tx, gasLimit, provider, error_1, decodedError, reason, maxPriorityFeePerGas, maxFeePerGas;
60
65
  return __generator(this, function (_a) {
61
66
  switch (_a.label) {
62
67
  case 0: return [4 /*yield*/, signer.getAddress()];
@@ -70,10 +75,10 @@ function estimateGas(signer, data, value, chainId, targetContract) {
70
75
  _a.label = 2;
71
76
  case 2:
72
77
  _a.trys.push([2, 4, , 6]);
73
- return [4 /*yield*/, signer.estimateGas(tx)];
78
+ provider = ethers_1.ethers.getDefaultProvider(reyaChainIdRPCMapper[chainId]);
79
+ return [4 /*yield*/, provider.call(tx)];
74
80
  case 3:
75
- gasEstimate = _a.sent();
76
- gasLimit = (0, txHelpers_1.getGasBuffer)(gasEstimate);
81
+ _a.sent();
77
82
  return [3 /*break*/, 6];
78
83
  case 4:
79
84
  error_1 = _a.sent();
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kCAAuC;AACvC,yDAA+D;AAC/D,yCAA2C;AAC3C,kDAAyC;AACzC,2DAAmD;AASnD,IAAM,YAAY,GAAG,kCAAY,CAAC,MAAM,CAAC,CAAC,iBAAG,CAAC,CAAC,CAAC;AAEhD,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAE1C,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO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f,cAAqC;;;;;wBAEtB,qBAAM,WAAW,CAC9B,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,cAAc,CACf,EAAA;;oBANK,MAAM,GAAG,SAMd;;;;oBAGoB,qBAAM,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,EAAA;;oBAAjD,UAAU,GAAG,SAAoC;oBACrC,qBAAM,UAAU,CAAC,IAAI,EAAE,EAAA;;oBAAnC,SAAS,GAAG,SAAuB;oBACzC,sBAAO,SAAS,EAAC;;;oBAEjB,OAAO,CAAC,IAAI,CAAC,OAAK,CAAC,CAAC;oBACpB,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;;;;;CAElD;AAvBD,gDAuBC;AACD,IAAM,kBAAkB,GAAG,UAAC,EAA8B;QAA5B,IAAI,UAAA,EAAE,MAAM,YAAA;IACxC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAkB;YACrB,OAAO,sDAAsD,CAAC;QAChE,KAAK,oBAAoB;YACvB,OAAO,iDAAiD,CAAC;QAC3D,KAAK,gBAAgB;YACnB,OAAO,0BAA0B,CAAC;QACpC,KAAK,gBAAgB;YACnB,OAAO,qDAAqD,CAAC;QAC/D,KAAK,gBAAgB;YACnB,OAAO,+BAA+B,CAAC;QACzC;YACE,qCAAqC;YACrC,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,6BAA6B,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { JsonRpcSigner, Signer } from 'ethers';\nimport { ReyaChainId } from '../types';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { getGasBuffer } from './txHelpers';\nimport { abi } from './abis/Errors.json';\nimport { ErrorDecoder } from 'ethers-decode-error';\nimport type { DecodedError } from 'ethers-decode-error';\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\nconst errorDecoder = ErrorDecoder.create([abi]);\n\nexport async function estimateGas(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const gasEstimate = await signer.estimateGas(tx);\n gasLimit = getGasBuffer(gasEstimate);\n } catch (error) {\n const decodedError = await errorDecoder.decode(error);\n const reason = customReasonMapper(decodedError);\n console.error(\n `Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,\n );\n throw new Error(reason);\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\nconst customReasonMapper = ({ name, reason }: DecodedError): string => {\n switch (name) {\n case 'SignatureInvalid':\n return `Invalid signature. Please refresh page and try again`;\n case 'StalePriceDetected':\n return `Price not updated, please try again a bit later`;\n case 'SmallOrderSize':\n return `Order size below minimum`;\n case 'DustyOrderSize':\n return `Order amount is not divisible by trade size spacing`;\n case 'AccountBelowIM':\n return `Account below required margin`;\n default:\n // This handles the non-custom errors\n return reason ?? 'Error executing transaction';\n }\n};\n"]}
1
+ {"version":3,"file":"executeTransaction.js","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAuD;AACvD,kCAAuC;AACvC,yDAA+D;AAC/D,kDAAyC;AACzC,2DAAmD;AAGnD,IAAM,oBAAoB;IACxB,GAAC,mBAAW,CAAC,WAAW,IAAG,0BAA0B;IACrD,GAAC,mBAAW,CAAC,UAAU,IAAG,wCAAwC;OACnE,CAAC;AAQF,IAAM,YAAY,GAAG,kCAAY,CAAC,MAAM,CAAC,CAAC,iBAAG,CAAC,CAAC,CAAC;AAEhD,SAAsB,WAAW,CAC/B,MAA8B,EAC9B,IAAY,EACZ,KAAa,EACb,OAAe,EACf,cAAqC;;;;;wBAQd,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;oBAA1C,cAAc,GAAG,SAAyB;oBAE1C,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAY,CAAC,CAAC,QAAQ,CAC1D,cAA8B,CAC/B;wBACC,CAAC,CAAC,IAAA,8BAAU,EAAC,OAAO,EAAE,cAA8B,CAAC;wBACrD,CAAC,CAAC,cAAc,CAAC;oBACb,EAAE,cACN,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,eAAe,EACnB,IAAI,MAAA,IACD,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CACpD,CAAC;oBAEI,QAAQ,GAAW,MAAM,CAAC,SAAS,CAAC,CAAC;;;;oBAGnC,QAAQ,GAAG,eAAM,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC1E,qBAAM,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAA;;oBAA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gDAuBC;AACD,IAAM,kBAAkB,GAAG,UAAC,EAA8B;QAA5B,IAAI,UAAA,EAAE,MAAM,YAAA;IACxC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAkB;YACrB,OAAO,sDAAsD,CAAC;QAChE,KAAK,oBAAoB;YACvB,OAAO,iDAAiD,CAAC;QAC3D,KAAK,gBAAgB;YACnB,OAAO,0BAA0B,CAAC;QACpC,KAAK,gBAAgB;YACnB,OAAO,qDAAqD,CAAC;QAC/D,KAAK,gBAAgB;YACnB,OAAO,+BAA+B,CAAC;QACzC;YACE,qCAAqC;YACrC,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,6BAA6B,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { ethers, JsonRpcSigner, Signer } from 'ethers';\nimport { ReyaChainId } from '../types';\nimport { ContractType, getAddress } from './contractAddresses';\nimport { abi } from './abis/Errors.json';\nimport { ErrorDecoder } from 'ethers-decode-error';\nimport type { DecodedError } from 'ethers-decode-error';\n\nconst reyaChainIdRPCMapper: { [key: number]: string } = {\n [ReyaChainId.reyaNetwork]: 'https://rpc.reya.network',\n [ReyaChainId.reyaCronos]: 'https://rpc.reya-cronos.gelato.digital',\n};\n\nexport type Transaction = {\n from: string;\n to: string;\n data: string;\n value?: string;\n};\nconst errorDecoder = ErrorDecoder.create([abi]);\n\nexport async function estimateGas(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n): Promise<\n Transaction & {\n gasLimit: bigint;\n maxPriorityFeePerGas?: bigint;\n maxFeePerGas?: bigint;\n }\n> {\n const accountAddress = await signer.getAddress();\n\n const contractAddress = Object.values(ContractType).includes(\n targetContract as ContractType,\n )\n ? getAddress(chainId, targetContract as ContractType)\n : targetContract;\n const tx = {\n from: accountAddress, // @todo Update with relayer address\n to: contractAddress,\n data,\n ...(value && value !== '0' ? { value: value } : {}),\n };\n\n const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate\n\n try {\n const provider = ethers.getDefaultProvider(reyaChainIdRPCMapper[chainId]);\n await provider.call(tx);\n } catch (error) {\n const decodedError = await errorDecoder.decode(error);\n const reason = customReasonMapper(decodedError);\n console.error(\n `Error simulating transaction account address ${accountAddress} reason ${decodedError?.name} ${decodedError} ${error}`,\n );\n throw new Error(reason);\n }\n\n if (Object.values(ReyaChainId).includes(chainId as ReyaChainId)) {\n const maxPriorityFeePerGas: bigint = BigInt('0');\n const maxFeePerGas: bigint = BigInt('100000000');\n return { ...tx, gasLimit, maxPriorityFeePerGas, maxFeePerGas };\n }\n\n return { ...tx, gasLimit };\n}\n\nexport async function executeTransaction(\n signer: Signer | JsonRpcSigner,\n data: string,\n value: string,\n chainId: number,\n targetContract: ContractType | string,\n) {\n const txData = await estimateGas(\n signer,\n data,\n value,\n chainId,\n targetContract,\n );\n\n try {\n const txResponse = await signer.sendTransaction(txData);\n const txReceipt = await txResponse.wait();\n return txReceipt;\n } catch (error) {\n console.warn(error);\n throw new Error('Transaction Execution Error');\n }\n}\nconst customReasonMapper = ({ name, reason }: DecodedError): string => {\n switch (name) {\n case 'SignatureInvalid':\n return `Invalid signature. Please refresh page and try again`;\n case 'StalePriceDetected':\n return `Price not updated, please try again a bit later`;\n case 'SmallOrderSize':\n return `Order size below minimum`;\n case 'DustyOrderSize':\n return `Order amount is not divisible by trade size spacing`;\n case 'AccountBelowIM':\n return `Account below required margin`;\n default:\n // This handles the non-custom errors\n return reason ?? 'Error executing transaction';\n }\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { JsonRpcSigner, Signer } from 'ethers';
1
+ import { ethers, JsonRpcSigner, Signer } from 'ethers';
2
2
  import { ContractType } from './contractAddresses';
3
3
  export type Transaction = {
4
4
  from: string;
@@ -11,5 +11,5 @@ export declare function estimateGas(signer: Signer | JsonRpcSigner, data: string
11
11
  maxPriorityFeePerGas?: bigint;
12
12
  maxFeePerGas?: bigint;
13
13
  }>;
14
- export declare function executeTransaction(signer: Signer | JsonRpcSigner, data: string, value: string, chainId: number, targetContract: ContractType | string): Promise<import("ethers").TransactionReceipt | null>;
14
+ export declare function executeTransaction(signer: Signer | JsonRpcSigner, data: string, value: string, chainId: number, targetContract: ContractType | string): Promise<ethers.TransactionReceipt | null>;
15
15
  //# sourceMappingURL=executeTransaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAM/D,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,GACpC,OAAO,CACR,WAAW,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CACF,CAoCA;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,uDAkBtC"}
1
+ {"version":3,"file":"executeTransaction.d.ts","sourceRoot":"/","sources":["transactions/executeTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAc,MAAM,qBAAqB,CAAC;AAU/D,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAGF,wBAAsB,WAAW,CAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,GACpC,OAAO,CACR,WAAW,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CACF,CAoCA;AAED,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,GAAG,aAAa,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,YAAY,GAAG,MAAM,6CAkBtC"}
@@ -1,3 +1,4 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
  export declare function amountNormalizer(value: BigNumber | number | string, decimals?: number): BigNumber;
3
+ export declare function amountDenormalizer(value: BigNumber | number | string, decimals?: number): BigNumber;
3
4
  //# sourceMappingURL=number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"/","sources":["utils/number.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,EAClC,QAAQ,GAAE,MAAW,GACpB,SAAS,CAEX"}
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"/","sources":["utils/number.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,EAClC,QAAQ,GAAE,MAAW,GACpB,SAAS,CAEX;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,EAClC,QAAQ,GAAE,MAAW,GACpB,SAAS,CAEX"}
@@ -28,6 +28,15 @@ export type GetERC20BalanceBatchArgs = {
28
28
  walletAddress: string;
29
29
  chain: MoneyInOutChainId;
30
30
  };
31
+ export type GetReyaETHBalanceArgs = {
32
+ walletAddress: string;
33
+ chain: ReyaChainId;
34
+ };
35
+ export type GetReyaERC20BalanceArgs = {
36
+ tokenAddress: string;
37
+ walletAddress: string;
38
+ chain: ReyaChainId;
39
+ };
31
40
  export type GetBalancesForBridgeArgs = {
32
41
  walletAddress: string;
33
42
  };
@@ -35,4 +44,6 @@ export declare const getERC20Balance: ({ tokenAddress, walletAddress, subject, }
35
44
  export declare const getETHBalance: ({ walletAddress, subject, }: GetETHBalanceArgs) => Promise<number>;
36
45
  export declare const getETHBalanceBatch: ({ walletAddress, chain, }: GetETHBalanceBatchArgs) => Promise<number>;
37
46
  export declare const getERC20BalanceBatch: ({ tokenAddress, walletAddress, chain, }: GetERC20BalanceBatchArgs) => Promise<number>;
47
+ export declare const getReyaETHBalance: ({ walletAddress, chain, }: GetReyaETHBalanceArgs) => Promise<number>;
48
+ export declare const getReyaERC20Balance: ({ tokenAddress, walletAddress, chain, }: GetReyaERC20BalanceArgs) => Promise<number>;
38
49
  //# sourceMappingURL=token.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"/","sources":["utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EACL,OAAO,EACP,uBAAuB,EACvB,iBAAiB,E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AQ,MAAM,CAsB3C,CAAC;AAEF,eAAO,MAAM,iBAAiB,8BAG3B,qBAAqB,KAAG,QAAQ,MAAM,CAexC,CAAC;AAEF,eAAO,MAAM,mBAAmB,4CAI7B,uBAAuB,KAAG,QAAQ,MAAM,CAiB1C,CAAC"}
@@ -3,11 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.amountNormalizer = void 0;
6
+ exports.amountDenormalizer = exports.amountNormalizer = void 0;
7
7
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
8
8
  function amountNormalizer(value, decimals) {
9
9
  if (decimals === void 0) { decimals = 18; }
10
10
  return (0, bignumber_js_1.default)(value).div((0, bignumber_js_1.default)(10).pow(decimals));
11
11
  }
12
12
  exports.amountNormalizer = amountNormalizer;
13
+ function amountDenormalizer(value, decimals) {
14
+ if (decimals === void 0) { decimals = 18; }
15
+ return (0, bignumber_js_1.default)(value).times((0, bignumber_js_1.default)(10).pow(decimals));
16
+ }
17
+ exports.amountDenormalizer = amountDenormalizer;
13
18
  //# sourceMappingURL=number.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"number.js","sourceRoot":"/","sources":["utils/number.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,SAAgB,gBAAgB,CAC9B,KAAkC,EAClC,QAAqB;IAArB,yBAAA,EAAA,aAAqB;IAErB,OAAO,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAA,sBAAS,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3D,CAAC;AALD,4CAKC","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport function amountNormalizer(\n value: BigNumber | number | string,\n decimals: number = 18,\n): BigNumber {\n return BigNumber(value).div(BigNumber(10).pow(decimals));\n}\n"]}
1
+ {"version":3,"file":"number.js","sourceRoot":"/","sources":["utils/number.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,SAAgB,gBAAgB,CAC9B,KAAkC,EAClC,QAAqB;IAArB,yBAAA,EAAA,aAAqB;IAErB,OAAO,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAA,sBAAS,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3D,CAAC;AALD,4CAKC;AAED,SAAgB,kBAAkB,CAChC,KAAkC,EAClC,QAAqB;IAArB,yBAAA,EAAA,aAAqB;IAErB,OAAO,IAAA,sBAAS,EAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAA,sBAAS,EAAC,EAAE,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC7D,CAAC;AALD,gDAKC","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport function amountNormalizer(\n value: BigNumber | number | string,\n decimals: number = 18,\n): BigNumber {\n return BigNumber(value).div(BigNumber(10).pow(decimals));\n}\n\nexport function amountDenormalizer(\n value: BigNumber | number | string,\n decimals: number = 18,\n): BigNumber {\n return BigNumber(value).times(BigNumber(10).pow(decimals));\n}\n"]}
@@ -36,11 +36,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getERC20BalanceBatch = exports.getETHBalanceBatch = exports.getETHBalance = exports.getERC20Balance = exports.getERC20Allowance = exports.getRUSDUnderlyingTokenInfo = exports.getTokenInfosByChain = exports.getTokenInfoByName = exports.getTokenInfoByAddress = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
39
+ exports.getReyaERC20Balance = exports.getReyaETHBalance = exports.getERC20BalanceBatch = exports.getETHBalanceBatch = exports.getETHBalance = exports.getERC20Balance = exports.getERC20Allowance = exports.getRUSDUnderlyingTokenInfo = exports.getTokenInfosByChain = exports.getTokenInfoByName = exports.getTokenInfoByAddress = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
40
40
  var ethers_1 = require("ethers");
41
41
  var ethers_2 = require("ethers");
42
42
  var token_info_1 = require("./token-info");
43
43
  var retry_1 = require("./retry");
44
+ var types_1 = require("../types");
44
45
  var network_1 = require("./network");
45
46
  var descale = function (tokenDecimals) {
46
47
  var f = function (value) {
@@ -282,4 +283,58 @@ var getERC20BalanceBatch = function (_a) {
282
283
  });
283
284
  };
284
285
  exports.getERC20BalanceBatch = getERC20BalanceBatch;
286
+ var getReyaETHBalance = function (_a) {
287
+ var walletAddress = _a.walletAddress, chain = _a.chain;
288
+ return __awaiter(void 0, void 0, void 0, function () {
289
+ var provider_2, currentBalance, error_3;
290
+ return __generator(this, function (_b) {
291
+ switch (_b.label) {
292
+ case 0:
293
+ _b.trys.push([0, 2, , 3]);
294
+ provider_2 = ethers_1.ethers.getDefaultProvider(chain === types_1.ReyaChainId.reyaCronos
295
+ ? 'https://rpc.reya-cronos.gelato.digital'
296
+ : 'https://rpc.reya.network');
297
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
298
+ return provider_2.getBalance(ethers_1.ethers.getAddress(walletAddress));
299
+ })];
300
+ case 1:
301
+ currentBalance = _b.sent();
302
+ return [2 /*return*/, (0, exports.descale)(18)(currentBalance)];
303
+ case 2:
304
+ error_3 = _b.sent();
305
+ throw new Error('All RPC URLs failed; last error: ' + error_3);
306
+ case 3: return [2 /*return*/];
307
+ }
308
+ });
309
+ });
310
+ };
311
+ exports.getReyaETHBalance = getReyaETHBalance;
312
+ var getReyaERC20Balance = function (_a) {
313
+ var tokenAddress = _a.tokenAddress, walletAddress = _a.walletAddress, chain = _a.chain;
314
+ return __awaiter(void 0, void 0, void 0, function () {
315
+ var provider, token_1, currentBalance, tokenInfo, error_4;
316
+ return __generator(this, function (_b) {
317
+ switch (_b.label) {
318
+ case 0:
319
+ _b.trys.push([0, 2, , 3]);
320
+ provider = ethers_1.ethers.getDefaultProvider(chain === types_1.ReyaChainId.reyaCronos
321
+ ? 'https://rpc.reya-cronos.gelato.digital'
322
+ : 'https://rpc.reya.network');
323
+ token_1 = (0, exports.getERC20TokenContract)(tokenAddress, provider);
324
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
325
+ return token_1.balanceOf(walletAddress);
326
+ })];
327
+ case 1:
328
+ currentBalance = _b.sent();
329
+ tokenInfo = (0, exports.getTokenInfoByAddress)((0, exports.convertToAddress)(tokenAddress));
330
+ return [2 /*return*/, (0, exports.descale)(tokenInfo.decimals)(currentBalance)];
331
+ case 2:
332
+ error_4 = _b.sent();
333
+ throw new Error('All RPC URLs failed; last error: ' + error_4);
334
+ case 3: return [2 /*return*/];
335
+ }
336
+ });
337
+ });
338
+ };
339
+ exports.getReyaERC20Balance = getReyaERC20Balance;
285
340
  //# sourceMappingURL=token.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"token.js","sourceRoot":"/","sources":["utils/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0C;AAE1C,iCAA0C;AAC1C,2CAA0C;AAC1C,iCAA6C;AAS7C,qCAAyC;AAClC,IAAM,OAAO,GAAG,UAAC,aAAqB;IAC3C,IAAM,CAAC,GAAG,UAAC,KAAa;QACtB,OAAO,MAAM,CAAC,eAAM,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC;IAEF,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AANW,QAAA,OAAO,WAMlB;AAEK,IAAM,KAAK,GAAG,UAAC,aAAqB;IACzC,OAAO,UAAC,KAAa;QACnB,iCAAiC;QACjC,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QAClC,mDAAmD;QACnD,wCAAwC;QACpC,IAAA,KAA2B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,EA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mCAAmC,GAAG,SAAS,CAAC,CAAC;;;;CAClE,CAAC;AA1BW,QAAA,oBAAoB,wBA0B/B","sourcesContent":["import { ethers, Provider } from 'ethers';\n\nimport { Contract, Signer } from 'ethers';\nimport { TOKEN_INFO } from './token-info';\nimport { exponentialBackoff } from './retry';\nimport {\n Address,\n GetERC20AllowanceParams,\n MoneyInOutChainId,\n ReyaChainId,\n TokenInfo,\n TokenName,\n} from '../types';\nimport { ChainRpcUrls } from './network';\nexport const descale = (tokenDecimals: number) => {\n const f = (value: bigint) => {\n return Number(ethers.formatUnits(value.toString(), tokenDecimals));\n };\n\n return f;\n};\n\nexport const scale = (tokenDecimals: number): ((value: number) => bigint) => {\n return (value: number): bigint => {\n // Convert the number to a string\n const valueStr = value.toString();\n // Split the string into whole and fractional parts\n // eslint-disable-next-line prefer-const\n let [whole, fractional = ''] = valueStr.split('.');\n // Ensure the fractional part is the correct length, padding with zeros if necessary\n fractional = fractional\n .padEnd(tokenDecimals, '0')\n .substring(0, tokenDecimals);\n // Concatenate the whole part with the correctly length-limited fractional part\n const scaledValueStr = whole + fractional;\n // Convert the concatenated string to a BigInt, assuming it represents a value in wei (or equivalent smallest unit)\n // This is safe as we're not losing precision - just scaling the number to its smallest unit representation\n return BigInt(scaledValueStr);\n };\n};\n\nexport const getERC20TokenContract = (\n tokenAddress: string,\n subject: Signer | Provider,\n): Contract => {\n const abi: string[] = [\n `function approve(address, uint256) external returns (bool)`,\n `function balanceOf(address) external view returns (uint256)`,\n `function allowance(address,address) external view returns (uint256)`,\n `function approve(address,uint256) external returns (bool)`,\n ];\n\n const contract = new Contract(tokenAddress, abi, subject);\n\n return contract;\n};\n\nexport const convertToAddress = (str: string): Address => {\n return str.toLowerCase() as Address;\n};\n\nexport const getTokenInfoByAddress = (\n tokenAddressParam: Address | string,\n chainId?: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenAddress =\n typeof tokenAddressParam === 'string'\n ? convertToAddress(tokenAddressParam)\n : tokenAddressParam;\n\n if (chainId) {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.address === tokenAddress,\n );\n if (!tokenInfo) {\n throw new Error(\n `getTokenInfoByAddress: no token info found [chainId ${chainId}, token address ${tokenAddress}]`,\n );\n }\n return tokenInfo;\n } else {\n for (const chainId in TOKEN_INFO) {\n const tokenInfos =\n TOKEN_INFO[chainId as unknown as keyof typeof TOKEN_INFO];\n const tokenInfo = tokenInfos.find(\n (tokenInfo) => tokenInfo.address === tokenAddress,\n );\n if (tokenInfo) {\n return tokenInfo;\n }\n }\n throw new Error(\n `getTokenInfoByAddress: no token info found [token address ${tokenAddress}]`,\n );\n }\n};\n\nexport const getTokenInfoByName = (\n tokenName: TokenName,\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.name === tokenName,\n );\n\n if (!tokenInfo) {\n throw new Error(\n `getTokenInfoByName: no token info found [chain id ${chainId}, token name ${tokenName}]`,\n );\n }\n\n return tokenInfo;\n};\n\nexport const getTokenInfosByChain = (\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo[] => {\n return TOKEN_INFO[chainId];\n};\n\nexport const getRUSDUnderlyingTokenInfo = (\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.isRUSDUnderlying === true,\n );\n\n if (!tokenInfo) {\n throw new Error(\n `getRUSDUnderlyingTokenInfo: no token info found [chain id ${chainId}]`,\n );\n }\n\n return tokenInfo;\n};\n\nexport const getERC20Allowance = async ({\n walletAddress,\n tokenAddress,\n spenderAddress,\n subject,\n}: GetERC20AllowanceParams): Promise<number> => {\n const tokenContract = getERC20TokenContract(tokenAddress, subject);\n const tokenInfo = getTokenInfoByAddress(tokenAddress);\n\n const allowance = await exponentialBackoff(() =>\n tokenContract.allowance(walletAddress, spenderAddress),\n );\n\n return BigInt(allowance) > scale(tokenInfo.decimals)(Number.MAX_SAFE_INTEGER)\n ? Number.MAX_SAFE_INTEGER\n : descale(tokenInfo.decimals)(allowance);\n};\n\nexport type GetERC20BalanceArgs = {\n tokenAddress: string;\n walletAddress: string;\n subject: Signer | Provider;\n};\n\nexport type GetETHBalanceArgs = {\n walletAddress: string;\n subject: Signer | Provider;\n};\n\nexport type GetETHBalanceBatchArgs = {\n walletAddress: string;\n chain: MoneyInOutChainId;\n};\n\nexport type GetERC20BalanceBatchArgs = {\n tokenAddress: string;\n walletAddress: string;\n chain: MoneyInOutChainId;\n};\n\nexport type GetBalancesForBridgeArgs = {\n walletAddress: string;\n};\n\nexport const getERC20Balance = async ({\n tokenAddress,\n walletAddress,\n subject,\n}: GetERC20BalanceArgs): Promise<number> => {\n const token = getERC20TokenContract(tokenAddress, subject);\n\n const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));\n\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n return descale(tokenInfo.decimals)(currentBalance);\n};\n\nexport const getETHBalance = async ({\n walletAddress,\n subject,\n}: GetETHBalanceArgs): Promise<number> => {\n const provider = subject.provider;\n if (!provider) throw new Error(\"User's provider not found\");\n\n const currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n\n return descale(18)(currentBalance);\n};\n\nexport const getETHBalanceBatch = async ({\n walletAddress,\n chain,\n}: GetETHBalanceBatchArgs): Promise<number> => {\n const rpcUrls = ChainRpcUrls[chain];\n if (!rpcUrls || rpcUrls.length === 0) {\n throw new Error('No RPC URLs configured for the chain: ' + chain);\n }\n\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n return descale(18)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n\nexport const getERC20BalanceBatch = async ({\n tokenAddress,\n walletAddress,\n chain,\n}: GetERC20BalanceBatchArgs): Promise<number> => {\n const rpcUrls = ChainRpcUrls[chain];\n if (!rpcUrls || rpcUrls.length === 0) {\n throw new Error('No RPC URLs configured for the chain: ' + chain);\n }\n\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const token = getERC20TokenContract(tokenAddress, provider);\n const currentBalance = await token.balanceOf(walletAddress);\n\n const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));\n return descale(tokenInfo.decimals)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n"]}
1
+ {"version":3,"file":"token.js","sourceRoot":"/","sources":["utils/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0C;AAE1C,iCAA0C;AAC1C,2CAA0C;AAC1C,iCAA6C;AAC7C,kCAOkB;AAClB,qCAAyC;AAClC,IAAM,OAAO,GAAG,UAAC,aAAqB;IAC3C,IAAM,CAAC,GAAG,UAAC,KAAa;QACtB,OAAO,MAAM,CAAC,eAAM,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,aAAa,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC;IAEF,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AANW,QAAA,OAAO,WAMlB;AAEK,IAAM,KAAK,GAAG,UAAC,aAAqB;IACzC,OAAO,UAAC,KAAa;QACnB,iCAAiC;QACjC,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QAClC,mDAAmD;QACnD,wCAAwC;QACpC,IAAA,KAA2B,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,EAA7C,KAAK,QAAA,EAAE,UAAe,EAAf,UAAU,mBAAG,EAAE,KAAuB,CAAC;QACnD,oFAAoF;QACpF,UAAU,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mC,GAAG,OAAK,CAAC,CAAC;;;;;CAEhE,CAAC;AArBW,QAAA,mBAAmB,uBAqB9B","sourcesContent":["import { ethers, Provider } from 'ethers';\n\nimport { Contract, Signer } from 'ethers';\nimport { TOKEN_INFO } from './token-info';\nimport { exponentialBackoff } from './retry';\nimport {\n Address,\n GetERC20AllowanceParams,\n MoneyInOutChainId,\n ReyaChainId,\n TokenInfo,\n TokenName,\n} from '../types';\nimport { ChainRpcUrls } from './network';\nexport const descale = (tokenDecimals: number) => {\n const f = (value: bigint) => {\n return Number(ethers.formatUnits(value.toString(), tokenDecimals));\n };\n\n return f;\n};\n\nexport const scale = (tokenDecimals: number): ((value: number) => bigint) => {\n return (value: number): bigint => {\n // Convert the number to a string\n const valueStr = value.toString();\n // Split the string into whole and fractional parts\n // eslint-disable-next-line prefer-const\n let [whole, fractional = ''] = valueStr.split('.');\n // Ensure the fractional part is the correct length, padding with zeros if necessary\n fractional = fractional\n .padEnd(tokenDecimals, '0')\n .substring(0, tokenDecimals);\n // Concatenate the whole part with the correctly length-limited fractional part\n const scaledValueStr = whole + fractional;\n // Convert the concatenated string to a BigInt, assuming it represents a value in wei (or equivalent smallest unit)\n // This is safe as we're not losing precision - just scaling the number to its smallest unit representation\n return BigInt(scaledValueStr);\n };\n};\n\nexport const getERC20TokenContract = (\n tokenAddress: string,\n subject: Signer | Provider,\n): Contract => {\n const abi: string[] = [\n `function approve(address, uint256) external returns (bool)`,\n `function balanceOf(address) external view returns (uint256)`,\n `function allowance(address,address) external view returns (uint256)`,\n `function approve(address,uint256) external returns (bool)`,\n ];\n\n const contract = new Contract(tokenAddress, abi, subject);\n\n return contract;\n};\n\nexport const convertToAddress = (str: string): Address => {\n return str.toLowerCase() as Address;\n};\n\nexport const getTokenInfoByAddress = (\n tokenAddressParam: Address | string,\n chainId?: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenAddress =\n typeof tokenAddressParam === 'string'\n ? convertToAddress(tokenAddressParam)\n : tokenAddressParam;\n\n if (chainId) {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.address === tokenAddress,\n );\n if (!tokenInfo) {\n throw new Error(\n `getTokenInfoByAddress: no token info found [chainId ${chainId}, token address ${tokenAddress}]`,\n );\n }\n return tokenInfo;\n } else {\n for (const chainId in TOKEN_INFO) {\n const tokenInfos =\n TOKEN_INFO[chainId as unknown as keyof typeof TOKEN_INFO];\n const tokenInfo = tokenInfos.find(\n (tokenInfo) => tokenInfo.address === tokenAddress,\n );\n if (tokenInfo) {\n return tokenInfo;\n }\n }\n throw new Error(\n `getTokenInfoByAddress: no token info found [token address ${tokenAddress}]`,\n );\n }\n};\n\nexport const getTokenInfoByName = (\n tokenName: TokenName,\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.name === tokenName,\n );\n\n if (!tokenInfo) {\n throw new Error(\n `getTokenInfoByName: no token info found [chain id ${chainId}, token name ${tokenName}]`,\n );\n }\n\n return tokenInfo;\n};\n\nexport const getTokenInfosByChain = (\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo[] => {\n return TOKEN_INFO[chainId];\n};\n\nexport const getRUSDUnderlyingTokenInfo = (\n chainId: ReyaChainId | MoneyInOutChainId,\n): TokenInfo => {\n const tokenInfo = TOKEN_INFO[chainId].find(\n (tokenInfo) => tokenInfo.isRUSDUnderlying === true,\n );\n\n if (!tokenInfo) {\n throw new Error(\n `getRUSDUnderlyingTokenInfo: no token info found [chain id ${chainId}]`,\n );\n }\n\n return tokenInfo;\n};\n\nexport const getERC20Allowance = async ({\n walletAddress,\n tokenAddress,\n spenderAddress,\n subject,\n}: GetERC20AllowanceParams): Promise<number> => {\n const tokenContract = getERC20TokenContract(tokenAddress, subject);\n const tokenInfo = getTokenInfoByAddress(tokenAddress);\n\n const allowance = await exponentialBackoff(() =>\n tokenContract.allowance(walletAddress, spenderAddress),\n );\n\n return BigInt(allowance) > scale(tokenInfo.decimals)(Number.MAX_SAFE_INTEGER)\n ? Number.MAX_SAFE_INTEGER\n : descale(tokenInfo.decimals)(allowance);\n};\n\nexport type GetERC20BalanceArgs = {\n tokenAddress: string;\n walletAddress: string;\n subject: Signer | Provider;\n};\n\nexport type GetETHBalanceArgs = {\n walletAddress: string;\n subject: Signer | Provider;\n};\n\nexport type GetETHBalanceBatchArgs = {\n walletAddress: string;\n chain: MoneyInOutChainId;\n};\n\nexport type GetERC20BalanceBatchArgs = {\n tokenAddress: string;\n walletAddress: string;\n chain: MoneyInOutChainId;\n};\n\nexport type GetReyaETHBalanceArgs = {\n walletAddress: string;\n chain: ReyaChainId;\n};\n\nexport type GetReyaERC20BalanceArgs = {\n tokenAddress: string;\n walletAddress: string;\n chain: ReyaChainId;\n};\n\nexport type GetBalancesForBridgeArgs = {\n walletAddress: string;\n};\n\nexport const getERC20Balance = async ({\n tokenAddress,\n walletAddress,\n subject,\n}: GetERC20BalanceArgs): Promise<number> => {\n const token = getERC20TokenContract(tokenAddress, subject);\n\n const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));\n\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n return descale(tokenInfo.decimals)(currentBalance);\n};\n\nexport const getETHBalance = async ({\n walletAddress,\n subject,\n}: GetETHBalanceArgs): Promise<number> => {\n const provider = subject.provider;\n if (!provider) throw new Error(\"User's provider not found\");\n\n const currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n\n return descale(18)(currentBalance);\n};\n\nexport const getETHBalanceBatch = async ({\n walletAddress,\n chain,\n}: GetETHBalanceBatchArgs): Promise<number> => {\n const rpcUrls = ChainRpcUrls[chain];\n if (!rpcUrls || rpcUrls.length === 0) {\n throw new Error('No RPC URLs configured for the chain: ' + chain);\n }\n\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n return descale(18)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n\nexport const getERC20BalanceBatch = async ({\n tokenAddress,\n walletAddress,\n chain,\n}: GetERC20BalanceBatchArgs): Promise<number> => {\n const rpcUrls = ChainRpcUrls[chain];\n if (!rpcUrls || rpcUrls.length === 0) {\n throw new Error('No RPC URLs configured for the chain: ' + chain);\n }\n\n let lastError = null;\n\n for (const url of rpcUrls) {\n try {\n const provider = new ethers.JsonRpcProvider(url);\n const token = getERC20TokenContract(tokenAddress, provider);\n const currentBalance = await token.balanceOf(walletAddress);\n\n const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));\n return descale(tokenInfo.decimals)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n\nexport const getReyaETHBalance = async ({\n walletAddress,\n chain,\n}: GetReyaETHBalanceArgs): Promise<number> => {\n try {\n const provider = ethers.getDefaultProvider(\n chain === ReyaChainId.reyaCronos\n ? 'https://rpc.reya-cronos.gelato.digital'\n : 'https://rpc.reya.network',\n );\n const currentBalance = await exponentialBackoff(() =>\n provider.getBalance(ethers.getAddress(walletAddress)),\n );\n\n return descale(18)(currentBalance);\n } catch (error) {\n throw new Error('All RPC URLs failed; last error: ' + error);\n }\n};\n\nexport const getReyaERC20Balance = async ({\n tokenAddress,\n walletAddress,\n chain,\n}: GetReyaERC20BalanceArgs): Promise<number> => {\n try {\n const provider = ethers.getDefaultProvider(\n chain === ReyaChainId.reyaCronos\n ? 'https://rpc.reya-cronos.gelato.digital'\n : 'https://rpc.reya.network',\n );\n const token = getERC20TokenContract(tokenAddress, provider);\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));\n return descale(tokenInfo.decimals)(currentBalance);\n } catch (error) {\n throw new Error('All RPC URLs failed; last error: ' + error);\n }\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/common",
3
- "version": "0.135.1",
3
+ "version": "0.136.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -43,5 +43,5 @@
43
43
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
44
44
  },
45
45
  "packageManager": "pnpm@8.3.1",
46
- "gitHead": "a62a3d6caff6693ad0877b4b40eea7107ab2d32f"
46
+ "gitHead": "51ccbadf06f7980fbcbaac1a1fc43157d6c90ad5"
47
47
  }
@@ -1,11 +1,15 @@
1
- import { JsonRpcSigner, Signer } from 'ethers';
1
+ import { ethers, JsonRpcSigner, Signer } from 'ethers';
2
2
  import { ReyaChainId } from '../types';
3
3
  import { ContractType, getAddress } from './contractAddresses';
4
- import { getGasBuffer } from './txHelpers';
5
4
  import { abi } from './abis/Errors.json';
6
5
  import { ErrorDecoder } from 'ethers-decode-error';
7
6
  import type { DecodedError } from 'ethers-decode-error';
8
7
 
8
+ const reyaChainIdRPCMapper: { [key: number]: string } = {
9
+ [ReyaChainId.reyaNetwork]: 'https://rpc.reya.network',
10
+ [ReyaChainId.reyaCronos]: 'https://rpc.reya-cronos.gelato.digital',
11
+ };
12
+
9
13
  export type Transaction = {
10
14
  from: string;
11
15
  to: string;
@@ -41,11 +45,11 @@ export async function estimateGas(
41
45
  ...(value && value !== '0' ? { value: value } : {}),
42
46
  };
43
47
 
44
- let gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate
48
+ const gasLimit: bigint = BigInt('5000000'); // hardcode to 5m gas limit if fails to get estimate
45
49
 
46
50
  try {
47
- const gasEstimate = await signer.estimateGas(tx);
48
- gasLimit = getGasBuffer(gasEstimate);
51
+ const provider = ethers.getDefaultProvider(reyaChainIdRPCMapper[chainId]);
52
+ await provider.call(tx);
49
53
  } catch (error) {
50
54
  const decodedError = await errorDecoder.decode(error);
51
55
  const reason = customReasonMapper(decodedError);
@@ -6,3 +6,10 @@ export function amountNormalizer(
6
6
  ): BigNumber {
7
7
  return BigNumber(value).div(BigNumber(10).pow(decimals));
8
8
  }
9
+
10
+ export function amountDenormalizer(
11
+ value: BigNumber | number | string,
12
+ decimals: number = 18,
13
+ ): BigNumber {
14
+ return BigNumber(value).times(BigNumber(10).pow(decimals));
15
+ }
@@ -174,6 +174,17 @@ export type GetERC20BalanceBatchArgs = {
174
174
  chain: MoneyInOutChainId;
175
175
  };
176
176
 
177
+ export type GetReyaETHBalanceArgs = {
178
+ walletAddress: string;
179
+ chain: ReyaChainId;
180
+ };
181
+
182
+ export type GetReyaERC20BalanceArgs = {
183
+ tokenAddress: string;
184
+ walletAddress: string;
185
+ chain: ReyaChainId;
186
+ };
187
+
177
188
  export type GetBalancesForBridgeArgs = {
178
189
  walletAddress: string;
179
190
  };
@@ -261,3 +272,46 @@ export const getERC20BalanceBatch = async ({
261
272
 
262
273
  throw new Error('All RPC URLs failed; last error: ' + lastError);
263
274
  };
275
+
276
+ export const getReyaETHBalance = async ({
277
+ walletAddress,
278
+ chain,
279
+ }: GetReyaETHBalanceArgs): Promise<number> => {
280
+ try {
281
+ const provider = ethers.getDefaultProvider(
282
+ chain === ReyaChainId.reyaCronos
283
+ ? 'https://rpc.reya-cronos.gelato.digital'
284
+ : 'https://rpc.reya.network',
285
+ );
286
+ const currentBalance = await exponentialBackoff(() =>
287
+ provider.getBalance(ethers.getAddress(walletAddress)),
288
+ );
289
+
290
+ return descale(18)(currentBalance);
291
+ } catch (error) {
292
+ throw new Error('All RPC URLs failed; last error: ' + error);
293
+ }
294
+ };
295
+
296
+ export const getReyaERC20Balance = async ({
297
+ tokenAddress,
298
+ walletAddress,
299
+ chain,
300
+ }: GetReyaERC20BalanceArgs): Promise<number> => {
301
+ try {
302
+ const provider = ethers.getDefaultProvider(
303
+ chain === ReyaChainId.reyaCronos
304
+ ? 'https://rpc.reya-cronos.gelato.digital'
305
+ : 'https://rpc.reya.network',
306
+ );
307
+ const token = getERC20TokenContract(tokenAddress, provider);
308
+ const currentBalance = await exponentialBackoff(() =>
309
+ token.balanceOf(walletAddress),
310
+ );
311
+
312
+ const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));
313
+ return descale(tokenInfo.decimals)(currentBalance);
314
+ } catch (error) {
315
+ throw new Error('All RPC URLs failed; last error: ' + error);
316
+ }
317
+ };