@reyaxyz/common 0.135.1 → 0.135.2
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 +1 -1
- package/dist/types/utils/number.d.ts +1 -0
- package/dist/types/utils/number.d.ts.map +1 -1
- package/dist/types/utils/token.d.ts +11 -0
- package/dist/types/utils/token.d.ts.map +1 -1
- package/dist/utils/number.js +6 -1
- package/dist/utils/number.js.map +1 -1
- package/dist/utils/token.js +56 -1
- package/dist/utils/token.js.map +1 -1
- package/package.json +2 -2
- package/src/utils/number.ts +7 -0
- package/src/utils/token.ts +54 -0
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -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,QAA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AM,CAqBzC,CAAC;AAEF,eAAO,MAAM,oBAAoB,4CAI9B,wBAAwB,KAAG,QAAQ,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"}
|
package/dist/utils/number.js
CHANGED
|
@@ -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
|
package/dist/utils/number.js.map
CHANGED
|
@@ -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"]}
|
package/dist/utils/token.js
CHANGED
|
@@ -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
|
package/dist/utils/token.js.map
CHANGED
|
@@ -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,EAA7C,KAAK,QAAA,EAAE,UAAe,EAAf,UAAU,mBAAG,EAAE,KAAuB,CAAC;QACnD,oFAAoF;QACpF,UAAU,GAAG,UAAU;aACpB,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC;aAC1B,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;QAC/B,+EAA+E;QAC/E,IAAM,cAAc,GAAG,KAAK,GAAG,UAAU,CAAC;QAC1C,mHAAmH;QACnH,2GAA2G;QAC3G,OAAO,MAAM,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,KAAK,SAiBhB;AAEK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BAAA,EACZ,aAAa,mBAAA,EACb,KAAK,WAAA;;;;;;oBAEC,OAAO,GAAG,sBAAY,CAAC,KAAK,CAAC,CAAC;oBACpC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;wBACrC,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,KAAK,CAAC,CAAC;oBACpE,CAAC;oBAEG,SAAS,GAAG,IAAI,CAAC;0BAEI,EAAP,mBAAO;;;yBAAP,CAAA,qBAAO,CAAA;oBAAd,GAAG;;;;oBAEJ,QAAQ,GAAG,IAAI,eAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oBAC3C,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBACrC,qBAAM,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,EAAA;;oBAArD,cAAc,GAAG,SAAoC;oBAErD,SAAS,GAAG,IAAA,6BAAqB,EAAC,IAAA,wBAAgB,EAAC,YAAY,CAAC,CAAC,CAAC;oBACxE,sBAAO,IAAA,eAAO,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAEnD,SAAS,GAAG,OAAK,CAAC;;;oBATJ,IAAO,CAAA;;wBAazB,MAAM,IAAI,KAAK,CAAC,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,GAAG,UAAU;aACpB,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC;aAC1B,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;QAC/B,+EAA+E;QAC/E,IAAM,cAAc,GAAG,KAAK,GAAG,UAAU,CAAC;QAC1C,mHAAmH;QACnH,2GAA2G;QAC3G,OAAO,MAAM,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,KAAK,SAiBhB;AAEK,IAAM,qBAAqB,GAAG,UACnC,YAAoB,EACpB,OAA0B;IAE1B,IAAM,GAAG,GAAa;QACpB,4DAA4D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AAA,eAAO,EAAC,EAAE,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAEnC,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,OAAK,CAAC,CAAC;;;;;CAEhE,CAAC;AAlBW,QAAA,iBAAiB,qBAkB5B;AAEK,IAAM,mBAAmB,GAAG,UAAO,EAIhB;QAHxB,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,KAAK,WAAA;;;;;;;oBAGG,QAAQ,GAAG,eAAM,CAAC,kBAAkB,CACxC,KAAK,KAAK,mBAAW,CAAC,UAAU;wBAC9B,CAAC,CAAC,wCAAwC;wBAC1C,CAAC,CAAC,0BAA0B,CAC/B,CAAC;oBACI,UAAQ,IAAA,6BAAqB,EAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBACrC,qBAAM,IAAA,0BAAkB,EAAC;4BAC9C,OAAA,OAAK,CAAC,SAAS,CAAC,aAAa,CAAC;wBAA9B,CAA8B,CAC/B,EAAA;;oBAFK,cAAc,GAAG,SAEtB;oBAEK,SAAS,GAAG,IAAA,6BAAqB,EAAC,IAAA,wBAAgB,EAAC,YAAY,CAAC,CAAC,CAAC;oBACxE,sBAAO,IAAA,eAAO,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAEnD,MAAM,IAAI,KAAK,CAAC,mCAAmC,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.
|
|
3
|
+
"version": "0.135.2",
|
|
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": "
|
|
46
|
+
"gitHead": "ac45d4c179f0fcfff0bdcb555c49140b861a89f7"
|
|
47
47
|
}
|
package/src/utils/number.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/utils/token.ts
CHANGED
|
@@ -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
|
+
};
|