@reyaxyz/common 0.76.0 → 0.78.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 +1 -1
- package/dist/services/getSocketAddresses.js +3 -2
- package/dist/services/getSocketAddresses.js.map +1 -1
- package/dist/types/services/getSocketAddresses.d.ts.map +1 -1
- package/dist/types/utils/network.d.ts +1 -1
- package/dist/types/utils/network.d.ts.map +1 -1
- package/dist/types/utils/token.d.ts +6 -0
- package/dist/types/utils/token.d.ts.map +1 -1
- package/dist/utils/network.js +32 -8
- package/dist/utils/network.js.map +1 -1
- package/dist/utils/token.js +43 -1
- package/dist/utils/token.js.map +1 -1
- package/package.json +2 -2
- package/src/services/getSocketAddresses.ts +5 -2
- package/src/utils/network.ts +33 -9
- package/src/utils/token.ts +36 -0
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -91,8 +91,9 @@ var getMoneyInOutChainIdFromReyaConnector = function (params) {
|
|
|
91
91
|
var deploymentJSON = getSocketDeploymentJSON(params.reyaChainId);
|
|
92
92
|
for (var _i = 0, _e = (0, network_1.getMoneyInOutNetworksFromReyaChainId)(params.reyaChainId); _i < _e.length; _i++) {
|
|
93
93
|
var moneyInOutChainId = _e[_i];
|
|
94
|
-
var
|
|
95
|
-
if (
|
|
94
|
+
var withdrawConnector = (_d = (_c = (_b = (_a = deploymentJSON === null || deploymentJSON === void 0 ? void 0 : deploymentJSON[params.reyaChainId]) === null || _a === void 0 ? void 0 : _a[params.tokenName]) === null || _b === void 0 ? void 0 : _b.connectors) === null || _c === void 0 ? void 0 : _c[moneyInOutChainId]) === null || _d === void 0 ? void 0 : _d.FAST;
|
|
95
|
+
if (withdrawConnector &&
|
|
96
|
+
withdrawConnector.toLowerCase() === params.socketConnector.toLowerCase()) {
|
|
96
97
|
return moneyInOutChainId;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSocketAddresses.js","sourceRoot":"/","sources":["services/getSocketAddresses.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kCAUkB;AAClB,4CAG0B;AAC1B,wCAAkD;AAElD,2EAA+D;AAC/D,6EAAiE;AA4BjE,IAAK,0BAQJ;AARD,WAAK,0BAA0B;IAC7B,6DAA+B,CAAA;IAC/B,mEAAqC,CAAA;IACrC,6CAAe,CAAA;IACf,uDAAyB,CAAA;IACzB,mFAAqD,CAAA;IACrD,2DAA6B,CAAA;IAC7B,6DAA+B,CAAA;AACjC,CAAC,EARI,0BAA0B,KAA1B,0BAA0B,QAQ9B;AAUD,IAAM,uBAAuB,GAAG,UAC9B,WAAwB;IAExB,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,mBAAW,CAAC,WAAW;YAC1B,OAAO,YAAY,CAAC;QACtB,KAAK,mBAAW,CAAC,UAAU;YACzB,OAAO,WAAW,CAAC;IACvB,CAAC;AACH,CAAC,CAAC;AAEK,IAAM,mBAAmB,GAAG,UACjC,MAAiC;;IAEjC,IAAM,WAAW,GAAG,IAAA,6CAAmC,EACrD,MAAM,CAAC,iBAAiB,CACzB,CAAC;IACF,IAAM,cAAc,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC;IAC5D,IAAM,gBAAgB,GACpB,MAAA,MAAA,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,MAAM,CAAC,iBAAiB,CAAC,0CAAG,MAAM,CAAC,SAAS,CAAC,0CAC1D,UAAU,0CAAG,WAAW,CAAC,0CAAE,IAAI,CAAC;IAEtC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,2DAAoD,IAAI,CAAC,SAAS,CAChE,MAAM,CACP,CAAE,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A;QAG1B,IAAM,iBAAiB,GACrB,MAAA,MAAA,MAAA,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAG,MAAM,CAAC,WAAW,CAAC,0CAAG,MAAM,CAAC,SAAS,CAAC,0CAAE,UAAU,0CAClE,iBAAiB,CAClB,0CAAE,IAAI,CAAC;QAEV,IACE,iBAAiB;YACjB,iBAAiB,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,EACxE,CAAC;YACD,OAAO,iBAAiB,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,wEAAwE,CACzE,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,qCAAqC,yCAuBhD","sourcesContent":["import {\n ReyaChainId,\n GetSocketConnectorsParams,\n Address,\n GetSocketControllerParams,\n MoneyInOutChainId,\n GetSocketVaultParams,\n SocketTokenConnectors,\n TokenName,\n GetMoneyInOutChainIdFromReyaConnectorParams,\n} from '../types';\nimport {\n getMoneyInOutNetworksFromReyaChainId,\n getReyaNetworkFromMoneyInOutChainId,\n} from '../utils/network';\nimport { convertToAddress } from '../utils/token';\n\nimport * as REYA_CRONOS from '../utils/socket/reyaCronos.json';\nimport * as REYA_NETWORK from '../utils/socket/reyaNetwork.json';\n\ntype SocketDeploymentAddresses = {\n [chain in ReyaChainId | MoneyInOutChainId]?: SocketChainAddresses;\n};\n\ntype SocketChainAddresses = {\n [token in TokenName]?: SocketTokenAddresses;\n};\n\ntype SocketTokenAddresses =\n | SocketAppChainAddresses\n | SocketNonAppChainAddresses;\n\ninterface SocketAppChainAddresses {\n isAppChain: true;\n [SocketSuperBridgeContracts.MintableToken]?: string;\n [SocketSuperBridgeContracts.Controller]?: string;\n [SocketSuperBridgeContracts.ExchangeRate]?: string;\n connectors?: SocketConnectors;\n}\ninterface SocketNonAppChainAddresses {\n isAppChain: false;\n [SocketSuperBridgeContracts.NonMintableToken]?: string;\n [SocketSuperBridgeContracts.Vault]?: string;\n connectors?: SocketConnectors;\n}\n\nenum SocketSuperBridgeContracts {\n MintableToken = 'MintableToken',\n NonMintableToken = 'NonMintableToken',\n Vault = 'Vault',\n Controller = 'Controller',\n FiatTokenV2_1_Controller = 'FiatTokenV2_1_Controller',\n ExchangeRate = 'ExchangeRate',\n ConnectorPlug = 'ConnectorPlug',\n}\n\nexport type SocketConnectors = {\n [chainSlug in ReyaChainId | MoneyInOutChainId]?: SocketConnectorAddresses;\n};\n\nexport type SocketConnectorAddresses = {\n ['FAST']?: string;\n};\n\nconst getSocketDeploymentJSON = (\n reyaChainId: ReyaChainId,\n): SocketDeploymentAddresses => {\n switch (reyaChainId) {\n case ReyaChainId.reyaNetwork:\n return REYA_NETWORK;\n case ReyaChainId.reyaCronos:\n return REYA_CRONOS;\n }\n};\n\nexport const getSocketConnectors = (\n params: GetSocketConnectorsParams,\n): SocketTokenConnectors => {\n const reyaChainId = getReyaNetworkFromMoneyInOutChainId(\n params.moneyInOutChainId,\n );\n const deploymentJSON = getSocketDeploymentJSON(reyaChainId);\n const depositConnector =\n deploymentJSON?.[params.moneyInOutChainId]?.[params.tokenName]\n ?.connectors?.[reyaChainId]?.FAST;\n\n if (!depositConnector) {\n throw new Error(\n `getSocketConnectors: deposit connector not found ${JSON.stringify(\n params,\n )}`,\n );\n }\n\n const withdrawConnector =\n deploymentJSON?.[reyaChainId]?.[params.tokenName]?.connectors?.[\n params.moneyInOutChainId\n ]?.FAST;\n\n if (!withdrawConnector) {\n throw new Error(\n `getSocketConnectors: withdraw connector not found ${JSON.stringify(\n params,\n )}`,\n );\n }\n\n return {\n deposit: convertToAddress(depositConnector),\n withdraw: convertToAddress(withdrawConnector),\n };\n};\n\nexport const getSocketController = (\n params: GetSocketControllerParams,\n): Address => {\n const deploymentJSON = getSocketDeploymentJSON(params.reyaChainId);\n const controller = (\n deploymentJSON?.[params.reyaChainId]?.[\n params.tokenName\n ] as SocketAppChainAddresses\n )?.[SocketSuperBridgeContracts.Controller];\n\n if (!controller) {\n throw new Error(\n `getSocketController: controller not found ${JSON.stringify(params)}`,\n );\n }\n\n return convertToAddress(controller);\n};\n\nexport const getSocketVault = (params: GetSocketVaultParams): Address => {\n const reyaChainId = getReyaNetworkFromMoneyInOutChainId(\n params.moneyInOutChainId,\n );\n const deploymentJSON = getSocketDeploymentJSON(reyaChainId);\n\n const vault = (\n deploymentJSON?.[params.moneyInOutChainId]?.[\n params.tokenName\n ] as SocketNonAppChainAddresses\n )?.[SocketSuperBridgeContracts.Vault];\n\n if (!vault) {\n throw new Error(\n `getSocketVault: vault not found ${JSON.stringify(params)}`,\n );\n }\n\n return convertToAddress(vault);\n};\n\nexport const getMoneyInOutChainIdFromReyaConnector = (\n params: GetMoneyInOutChainIdFromReyaConnectorParams,\n): MoneyInOutChainId => {\n const deploymentJSON = getSocketDeploymentJSON(params.reyaChainId);\n for (const moneyInOutChainId of getMoneyInOutNetworksFromReyaChainId(\n params.reyaChainId,\n )) {\n const withdrawConnector =\n deploymentJSON?.[params.reyaChainId]?.[params.tokenName]?.connectors?.[\n moneyInOutChainId\n ]?.FAST;\n\n if (\n withdrawConnector &&\n withdrawConnector.toLowerCase() === params.socketConnector.toLowerCase()\n ) {\n return moneyInOutChainId;\n }\n }\n\n throw new Error(\n 'getMoneyInOutChainIdFromReyaConnector: money in out chain id not found',\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSocketAddresses.d.ts","sourceRoot":"/","sources":["services/getSocketAddresses.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EACzB,OAAO,EACP,yBAAyB,EACzB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EAErB,2CAA2C,EAC5C,MAAM,UAAU,CAAC;AA8ClB,MAAM,MAAM,gBAAgB,GAAG;KAC5B,SAAS,IAAI,WAAW,GAAG,iBAAiB,CAAC,CAAC,EAAE,wBAAwB;CAC1E,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAaF,eAAO,MAAM,mBAAmB,WACtB,yBAAyB,KAChC,qBAkCF,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACtB,yBAAyB,KAChC,OAeF,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,oBAAoB,KAAG,OAmB7D,CAAC;AAEF,eAAO,MAAM,qCAAqC,WACxC,2CAA2C,KAClD,
|
|
1
|
+
{"version":3,"file":"getSocketAddresses.d.ts","sourceRoot":"/","sources":["services/getSocketAddresses.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EACzB,OAAO,EACP,yBAAyB,EACzB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EAErB,2CAA2C,EAC5C,MAAM,UAAU,CAAC;AA8ClB,MAAM,MAAM,gBAAgB,GAAG;KAC5B,SAAS,IAAI,WAAW,GAAG,iBAAiB,CAAC,CAAC,EAAE,wBAAwB;CAC1E,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAaF,eAAO,MAAM,mBAAmB,WACtB,yBAAyB,KAChC,qBAkCF,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACtB,yBAAyB,KAChC,OAeF,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,oBAAoB,KAAG,OAmB7D,CAAC;AAEF,eAAO,MAAM,qCAAqC,WACxC,2CAA2C,KAClD,iBAqBF,CAAC"}
|
|
@@ -5,7 +5,7 @@ export declare function getReyaNetworkFromMoneyInOutChainId(moneyInOutChainId: M
|
|
|
5
5
|
export declare function getMoneyInOutNetworksFromReyaChainId(reyaChainId: ReyaChainId): MoneyInOutChainId[];
|
|
6
6
|
export declare const chainIdToExplorerURL: Record<number, string>;
|
|
7
7
|
export declare const ChainRpcUrls: {
|
|
8
|
-
[key in MoneyInOutChainId]: string;
|
|
8
|
+
[key in MoneyInOutChainId]: string[];
|
|
9
9
|
};
|
|
10
10
|
export declare const AlchemyChainRpcUrls: {
|
|
11
11
|
[key in MoneyInOutChainId]: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"/","sources":["utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE1D,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,WAAW,CAKtE;AAED,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,YAAY,GAAG,MAAM,GACzB,iBAAiB,EAAE,CAkBrB;AAED,wBAAgB,mCAAmC,CACjD,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,CAWb;AAED,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,WAAW,GACvB,iBAAiB,EAAE,CAWrB;AAED,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAWvD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE;KAAG,GAAG,IAAI,iBAAiB,GAAG,MAAM;
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"/","sources":["utils/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE1D,wBAAgB,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,GAAG,WAAW,CAKtE;AAED,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,YAAY,GAAG,MAAM,GACzB,iBAAiB,EAAE,CAkBrB;AAED,wBAAgB,mCAAmC,CACjD,iBAAiB,EAAE,iBAAiB,GACnC,WAAW,CAWb;AAED,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,WAAW,GACvB,iBAAiB,EAAE,CAWrB;AAED,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAWvD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE;KAAG,GAAG,IAAI,iBAAiB,GAAG,MAAM,EAAE;CAoChE,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE;KAAG,GAAG,IAAI,iBAAiB,GAAG,MAAM;CAYrE,CAAC"}
|
|
@@ -15,8 +15,14 @@ export type GetERC20BalanceArgs = {
|
|
|
15
15
|
walletAddress: string;
|
|
16
16
|
subject: Signer | Provider;
|
|
17
17
|
};
|
|
18
|
+
export type GetERC20BalanceBatchArgs = {
|
|
19
|
+
tokenAddress: string;
|
|
20
|
+
walletAddress: string;
|
|
21
|
+
chain: MoneyInOutChainId;
|
|
22
|
+
};
|
|
18
23
|
export type GetBalancesForBridgeArgs = {
|
|
19
24
|
walletAddress: string;
|
|
20
25
|
};
|
|
21
26
|
export declare const getERC20Balance: ({ tokenAddress, walletAddress, subject, }: GetERC20BalanceArgs) => Promise<number>;
|
|
27
|
+
export declare const getERC20BalanceBatch: ({ tokenAddress, walletAddress, chain, }: GetERC20BalanceBatchArgs) => Promise<number>;
|
|
22
28
|
//# 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,EACjB,WAAW,EACX,SAAS,EACT,SAAS,EACV,MAAM,UAAU,CAAC;
|
|
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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G,QAAQ,MAAM,CAuB3C,CAAC"}
|
package/dist/utils/network.js
CHANGED
|
@@ -62,15 +62,39 @@ exports.chainIdToExplorerURL = (_a = {},
|
|
|
62
62
|
_a[types_1.ReyaChainId.reyaCronos] = 'https://reya-cronos.blockscout.com',
|
|
63
63
|
_a);
|
|
64
64
|
exports.ChainRpcUrls = (_b = {},
|
|
65
|
-
_b[types_1.MoneyInOutChainId.ethereumMainnet] =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
_b[types_1.MoneyInOutChainId.ethereumMainnet] = [
|
|
66
|
+
'https://mainnet.gateway.tenderly.co',
|
|
67
|
+
'https://eth.llamarpc.com',
|
|
68
|
+
],
|
|
69
|
+
_b[types_1.MoneyInOutChainId.opMainnet] = [
|
|
70
|
+
'https://mainnet.optimism.io',
|
|
71
|
+
'https://optimism.llamarpc.com',
|
|
72
|
+
],
|
|
73
|
+
_b[types_1.MoneyInOutChainId.polygonMainnet] = [
|
|
74
|
+
'https://polygon-rpc.com',
|
|
75
|
+
'https://gateway.tenderly.co/public/polygon',
|
|
76
|
+
],
|
|
77
|
+
_b[types_1.MoneyInOutChainId.arbitrumOne] = [
|
|
78
|
+
'https://arb1.arbitrum.io/rpc',
|
|
79
|
+
'https://arbitrum.llamarpc.com',
|
|
80
|
+
],
|
|
69
81
|
// Add the rest of the mainnet URLs above
|
|
70
|
-
_b[types_1.MoneyInOutChainId.polygonMumbai] =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
82
|
+
_b[types_1.MoneyInOutChainId.polygonMumbai] = [
|
|
83
|
+
'https://polygon-mumbai.gateway.tenderly.co',
|
|
84
|
+
'https://polygon-mumbai-bor-rpc.publicnode.com',
|
|
85
|
+
],
|
|
86
|
+
_b[types_1.MoneyInOutChainId.arbitrumSepolia] = [
|
|
87
|
+
'https://sepolia-rollup.arbitrum.io/rpc',
|
|
88
|
+
'https://endpoints.omniatech.io/v1/arbitrum/sepolia/public',
|
|
89
|
+
],
|
|
90
|
+
_b[types_1.MoneyInOutChainId.opSepolia] = [
|
|
91
|
+
'https://sepolia.optimism.io',
|
|
92
|
+
'https://optimism-sepolia.blockpi.network/v1/rpc/public',
|
|
93
|
+
],
|
|
94
|
+
_b[types_1.MoneyInOutChainId.ethereumSepolia] = [
|
|
95
|
+
'https://sepolia.gateway.tenderly.co',
|
|
96
|
+
'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
|
|
97
|
+
],
|
|
74
98
|
_b);
|
|
75
99
|
exports.AlchemyChainRpcUrls = (_c = {},
|
|
76
100
|
// mainnet
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"/","sources":["utils/network.ts"],"names":[],"mappings":";;;;AAAA,kCAA0D;AAE1D,SAAgB,cAAc,CAAC,GAA0B;IACvD,IAAI,GAAG,KAAK,YAAY;QAAE,OAAO,mBAAW,CAAC,WAAW,CAAC;IACzD,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,mBAAW,CAAC,UAAU,CAAC;IAElD,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;AACpD,CAAC;AALD,wCAKC;AAED,SAAgB,qBAAqB,CACnC,GAA0B;IAE1B,IAAI,GAAG,KAAK,YAAY;QACtB,OAAO;YACL,yBAAiB,CAAC,eAAe;YACjC,yBAAiB,CAAC,SAAS;YAC3B,yBAAiB,CAAC,cAAc;YAChC,yBAAiB,CAAC,WAAW;SAC9B,CAAC;IAEJ,IAAI,GAAG,KAAK,MAAM;QAChB,OAAO;YACL,yBAAiB,CAAC,eAAe;YACjC,yBAAiB,CAAC,SAAS;YAC3B,yBAAiB,CAAC,eAAe;YACjC,yBAAiB,CAAC,aAAa;SAChC,CAAC;IAEJ,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;AAC3D,CAAC;AApBD,sDAoBC;AAED,SAAgB,mCAAmC,CACjD,iBAAoC;IAEpC,IAAI,qBAAqB,CAAC,YAAY,CAAC,CAAC,QAA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AiB,CAAC,SAAS,IAAG;QAC7B,6BAA6B;QAC7B,wDAAwD;KACzD;IACD,GAAC,yBAAiB,CAAC,eAAe,IAAG;QACnC,qCAAqC;QACrC,wDAAwD;KACzD;QAED;AAEW,QAAA,mBAAmB;IAC9B,UAAU;IACV,GAAC,yBAAiB,CAAC,eAAe,IAAG,sCAAsC;IAC3E,GAAC,yBAAiB,CAAC,SAAS,IAAG,sCAAsC;IACrE,GAAC,yBAAiB,CAAC,cAAc,IAC/B,0CAA0C;IAC5C,GAAC,yBAAiB,CAAC,WAAW,IAAG,sCAAsC;IACvE,UAAU;IACV,GAAC,yBAAiB,CAAC,aAAa,IAAG,yCAAyC;IAC5E,GAAC,yBAAiB,CAAC,eAAe,IAAG,sCAAsC;IAC3E,GAAC,yBAAiB,CAAC,SAAS,IAAG,sCAAsC;IACrE,GAAC,yBAAiB,CAAC,eAAe,IAAG,sCAAsC;QAC3E","sourcesContent":["import { MoneyInOutChainId, ReyaChainId } from '../types';\n\nexport function getReyaNetwork(env: 'production' | 'test'): ReyaChainId {\n if (env === 'production') return ReyaChainId.reyaNetwork;\n if (env === 'test') return ReyaChainId.reyaCronos;\n\n throw new Error('Unknown env for getReyaNetwork');\n}\n\nexport function getMoneyInOutNetworks(\n env: 'production' | 'test',\n): MoneyInOutChainId[] {\n if (env === 'production')\n return [\n MoneyInOutChainId.ethereumMainnet,\n MoneyInOutChainId.opMainnet,\n MoneyInOutChainId.polygonMainnet,\n MoneyInOutChainId.arbitrumOne,\n ];\n\n if (env === 'test')\n return [\n MoneyInOutChainId.ethereumSepolia,\n MoneyInOutChainId.opSepolia,\n MoneyInOutChainId.arbitrumSepolia,\n MoneyInOutChainId.polygonMumbai,\n ];\n\n throw new Error('Unknown env for getMoneyInOutNetworks');\n}\n\nexport function getReyaNetworkFromMoneyInOutChainId(\n moneyInOutChainId: MoneyInOutChainId,\n): ReyaChainId {\n if (getMoneyInOutNetworks('production').includes(moneyInOutChainId)) {\n return getReyaNetwork('production');\n }\n if (getMoneyInOutNetworks('test').includes(moneyInOutChainId)) {\n return getReyaNetwork('test');\n }\n\n throw new Error(\n 'Unknown money in out network in getReyaNetworkFromMoneyInOutChainId',\n );\n}\n\nexport function getMoneyInOutNetworksFromReyaChainId(\n reyaChainId: ReyaChainId,\n): MoneyInOutChainId[] {\n if (getReyaNetwork('production') === reyaChainId) {\n return getMoneyInOutNetworks('production');\n }\n if (getReyaNetwork('test') === reyaChainId) {\n return getMoneyInOutNetworks('test');\n }\n\n throw new Error(\n 'Unknown money in out network in getMoneyInOutNetworksFromReyaChainId',\n );\n}\n\nexport const chainIdToExplorerURL: Record<number, string> = {\n [MoneyInOutChainId.ethereumMainnet]: 'https://etherscan.io',\n [MoneyInOutChainId.opMainnet]: 'https://optimistic.etherscan.io',\n [MoneyInOutChainId.polygonMainnet]: 'https://polygonscan.com',\n [MoneyInOutChainId.arbitrumOne]: 'https://arbiscan.io',\n [MoneyInOutChainId.polygonMumbai]: 'https://mumbai.polygonscan.com',\n [MoneyInOutChainId.arbitrumSepolia]: 'https://sepolia.arbiscan.io',\n [MoneyInOutChainId.opSepolia]: 'https://sepolia-optimism.etherscan.io',\n [MoneyInOutChainId.ethereumSepolia]: 'https://sepolia.etherscan.io',\n [ReyaChainId.reyaNetwork]: 'https://explorer.reya.network',\n [ReyaChainId.reyaCronos]: 'https://reya-cronos.blockscout.com',\n};\n\nexport const ChainRpcUrls: { [key in MoneyInOutChainId]: string[] } = {\n [MoneyInOutChainId.ethereumMainnet]: [\n 'https://mainnet.gateway.tenderly.co',\n 'https://eth.llamarpc.com',\n ],\n [MoneyInOutChainId.opMainnet]: [\n 'https://mainnet.optimism.io',\n 'https://optimism.llamarpc.com',\n ],\n [MoneyInOutChainId.polygonMainnet]: [\n 'https://polygon-rpc.com',\n 'https://gateway.tenderly.co/public/polygon',\n ],\n [MoneyInOutChainId.arbitrumOne]: [\n 'https://arb1.arbitrum.io/rpc',\n 'https://arbitrum.llamarpc.com',\n ],\n // Add the rest of the mainnet URLs above\n\n [MoneyInOutChainId.polygonMumbai]: [\n 'https://polygon-mumbai.gateway.tenderly.co',\n 'https://polygon-mumbai-bor-rpc.publicnode.com',\n ],\n [MoneyInOutChainId.arbitrumSepolia]: [\n 'https://sepolia-rollup.arbitrum.io/rpc',\n 'https://endpoints.omniatech.io/v1/arbitrum/sepolia/public',\n ],\n [MoneyInOutChainId.opSepolia]: [\n 'https://sepolia.optimism.io',\n 'https://optimism-sepolia.blockpi.network/v1/rpc/public',\n ],\n [MoneyInOutChainId.ethereumSepolia]: [\n 'https://sepolia.gateway.tenderly.co',\n 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',\n ],\n // Add the rest of the testnet URLs above\n};\n\nexport const AlchemyChainRpcUrls: { [key in MoneyInOutChainId]: string } = {\n // mainnet\n [MoneyInOutChainId.ethereumMainnet]: 'https://eth-mainnet.g.alchemy.com/v2',\n [MoneyInOutChainId.opMainnet]: 'https://opt-mainnet.g.alchemy.com/v2',\n [MoneyInOutChainId.polygonMainnet]:\n 'https://polygon-mainnet.g.alchemy.com/v2',\n [MoneyInOutChainId.arbitrumOne]: 'https://arb-mainnet.g.alchemy.com/v2',\n // testnet\n [MoneyInOutChainId.polygonMumbai]: 'https://polygon-mumbai.g.alchemy.com/v2',\n [MoneyInOutChainId.arbitrumSepolia]: 'https://arb-sepolia.g.alchemy.com/v2',\n [MoneyInOutChainId.opSepolia]: 'https://opt-sepolia.g.alchemy.com/v2',\n [MoneyInOutChainId.ethereumSepolia]: 'https://eth-sepolia.g.alchemy.com/v2',\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.getERC20Balance = exports.getERC20Allowance = exports.getRUSDUnderlyingTokenInfo = exports.getTokenInfosByChain = exports.getTokenInfoByName = exports.getTokenInfoByAddress = exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
|
|
39
|
+
exports.getERC20BalanceBatch = 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 network_1 = require("./network");
|
|
44
45
|
var descale = function (tokenDecimals) {
|
|
45
46
|
var f = function (value) {
|
|
46
47
|
return Number(ethers_1.ethers.formatUnits(value.toString(), tokenDecimals));
|
|
@@ -167,4 +168,45 @@ var getERC20Balance = function (_a) {
|
|
|
167
168
|
});
|
|
168
169
|
};
|
|
169
170
|
exports.getERC20Balance = getERC20Balance;
|
|
171
|
+
var getERC20BalanceBatch = function (_a) {
|
|
172
|
+
var tokenAddress = _a.tokenAddress, walletAddress = _a.walletAddress, chain = _a.chain;
|
|
173
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
174
|
+
var rpcUrls, lastError, _i, rpcUrls_1, url, provider, token, currentBalance, tokenInfo, error_1;
|
|
175
|
+
return __generator(this, function (_b) {
|
|
176
|
+
switch (_b.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
rpcUrls = network_1.ChainRpcUrls[chain];
|
|
179
|
+
if (!rpcUrls || rpcUrls.length === 0) {
|
|
180
|
+
throw new Error('No RPC URLs configured for the chain: ' + chain);
|
|
181
|
+
}
|
|
182
|
+
lastError = null;
|
|
183
|
+
_i = 0, rpcUrls_1 = rpcUrls;
|
|
184
|
+
_b.label = 1;
|
|
185
|
+
case 1:
|
|
186
|
+
if (!(_i < rpcUrls_1.length)) return [3 /*break*/, 6];
|
|
187
|
+
url = rpcUrls_1[_i];
|
|
188
|
+
_b.label = 2;
|
|
189
|
+
case 2:
|
|
190
|
+
_b.trys.push([2, 4, , 5]);
|
|
191
|
+
provider = new ethers_1.ethers.JsonRpcProvider(url);
|
|
192
|
+
token = (0, exports.getERC20TokenContract)(tokenAddress, provider);
|
|
193
|
+
return [4 /*yield*/, token.balanceOf(walletAddress)];
|
|
194
|
+
case 3:
|
|
195
|
+
currentBalance = _b.sent();
|
|
196
|
+
tokenInfo = (0, exports.getTokenInfoByAddress)((0, exports.convertToAddress)(tokenAddress));
|
|
197
|
+
return [2 /*return*/, (0, exports.descale)(tokenInfo.decimals)(currentBalance)];
|
|
198
|
+
case 4:
|
|
199
|
+
error_1 = _b.sent();
|
|
200
|
+
console.error("Failed to fetch from ".concat(url, ":"), error_1);
|
|
201
|
+
lastError = error_1;
|
|
202
|
+
return [3 /*break*/, 5];
|
|
203
|
+
case 5:
|
|
204
|
+
_i++;
|
|
205
|
+
return [3 /*break*/, 1];
|
|
206
|
+
case 6: throw new Error('All RPC URLs failed; last error: ' + lastError);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
exports.getERC20BalanceBatch = getERC20BalanceBatch;
|
|
170
212
|
//# 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;AAStC,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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EACb,OAAO,aAAA;;;;;;oBAED,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAErD,SAAS,GAAG,IAAA,6BAAqB,EAAC,IAAA,wBAAgB,EAAC,YAAY,CAAC,CAAC,CAAC;oBAEjD,qBAAM,IAAA,0BAAkB,EAAC;4BAC9C,OAAA,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC;wBAA9B,CAA8B,CAC/B,EAAA;;oBAFK,cAAc,GAAG,SAEtB;oBAED,sBAAO,IAAA,eAAO,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAC;;;;CACpD,CAAC;AAdW,QAAA,eAAe,mBAc1B","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';\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 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"]}
|
|
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,C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,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAEnD,OAAO,CAAC,KAAK,CAAC,+BAAwB,GAAG,MAAG,EAAE,OAAK,CAAC,CAAC;oBACrD,SAAS,GAAG,OAAK,CAAC;;;oBAVJ,IAAO,CAAA;;wBAczB,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,SAAS,CAAC,CAAC;;;;CAClE,CAAC;AA3BW,QAAA,oBAAoB,wBA2B/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 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 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 console.error(`Failed to fetch from ${url}:`, error);\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
43
43
|
},
|
|
44
44
|
"packageManager": "pnpm@8.10.4",
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "8b14b2df0a11bc31e97c569c7cc504143f8a5219"
|
|
46
46
|
}
|
|
@@ -158,12 +158,15 @@ export const getMoneyInOutChainIdFromReyaConnector = (
|
|
|
158
158
|
for (const moneyInOutChainId of getMoneyInOutNetworksFromReyaChainId(
|
|
159
159
|
params.reyaChainId,
|
|
160
160
|
)) {
|
|
161
|
-
const
|
|
161
|
+
const withdrawConnector =
|
|
162
162
|
deploymentJSON?.[params.reyaChainId]?.[params.tokenName]?.connectors?.[
|
|
163
163
|
moneyInOutChainId
|
|
164
164
|
]?.FAST;
|
|
165
165
|
|
|
166
|
-
if (
|
|
166
|
+
if (
|
|
167
|
+
withdrawConnector &&
|
|
168
|
+
withdrawConnector.toLowerCase() === params.socketConnector.toLowerCase()
|
|
169
|
+
) {
|
|
167
170
|
return moneyInOutChainId;
|
|
168
171
|
}
|
|
169
172
|
}
|
package/src/utils/network.ts
CHANGED
|
@@ -72,17 +72,41 @@ export const chainIdToExplorerURL: Record<number, string> = {
|
|
|
72
72
|
[ReyaChainId.reyaCronos]: 'https://reya-cronos.blockscout.com',
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
-
export const ChainRpcUrls: { [key in MoneyInOutChainId]: string } = {
|
|
76
|
-
[MoneyInOutChainId.ethereumMainnet]:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
export const ChainRpcUrls: { [key in MoneyInOutChainId]: string[] } = {
|
|
76
|
+
[MoneyInOutChainId.ethereumMainnet]: [
|
|
77
|
+
'https://mainnet.gateway.tenderly.co',
|
|
78
|
+
'https://eth.llamarpc.com',
|
|
79
|
+
],
|
|
80
|
+
[MoneyInOutChainId.opMainnet]: [
|
|
81
|
+
'https://mainnet.optimism.io',
|
|
82
|
+
'https://optimism.llamarpc.com',
|
|
83
|
+
],
|
|
84
|
+
[MoneyInOutChainId.polygonMainnet]: [
|
|
85
|
+
'https://polygon-rpc.com',
|
|
86
|
+
'https://gateway.tenderly.co/public/polygon',
|
|
87
|
+
],
|
|
88
|
+
[MoneyInOutChainId.arbitrumOne]: [
|
|
89
|
+
'https://arb1.arbitrum.io/rpc',
|
|
90
|
+
'https://arbitrum.llamarpc.com',
|
|
91
|
+
],
|
|
80
92
|
// Add the rest of the mainnet URLs above
|
|
81
93
|
|
|
82
|
-
[MoneyInOutChainId.polygonMumbai]:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
[MoneyInOutChainId.polygonMumbai]: [
|
|
95
|
+
'https://polygon-mumbai.gateway.tenderly.co',
|
|
96
|
+
'https://polygon-mumbai-bor-rpc.publicnode.com',
|
|
97
|
+
],
|
|
98
|
+
[MoneyInOutChainId.arbitrumSepolia]: [
|
|
99
|
+
'https://sepolia-rollup.arbitrum.io/rpc',
|
|
100
|
+
'https://endpoints.omniatech.io/v1/arbitrum/sepolia/public',
|
|
101
|
+
],
|
|
102
|
+
[MoneyInOutChainId.opSepolia]: [
|
|
103
|
+
'https://sepolia.optimism.io',
|
|
104
|
+
'https://optimism-sepolia.blockpi.network/v1/rpc/public',
|
|
105
|
+
],
|
|
106
|
+
[MoneyInOutChainId.ethereumSepolia]: [
|
|
107
|
+
'https://sepolia.gateway.tenderly.co',
|
|
108
|
+
'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
|
|
109
|
+
],
|
|
86
110
|
// Add the rest of the testnet URLs above
|
|
87
111
|
};
|
|
88
112
|
|
package/src/utils/token.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
TokenInfo,
|
|
12
12
|
TokenName,
|
|
13
13
|
} from '../types';
|
|
14
|
+
import { ChainRpcUrls } from './network';
|
|
14
15
|
export const descale = (tokenDecimals: number) => {
|
|
15
16
|
const f = (value: bigint) => {
|
|
16
17
|
return Number(ethers.formatUnits(value.toString(), tokenDecimals));
|
|
@@ -157,6 +158,12 @@ export type GetERC20BalanceArgs = {
|
|
|
157
158
|
subject: Signer | Provider;
|
|
158
159
|
};
|
|
159
160
|
|
|
161
|
+
export type GetERC20BalanceBatchArgs = {
|
|
162
|
+
tokenAddress: string;
|
|
163
|
+
walletAddress: string;
|
|
164
|
+
chain: MoneyInOutChainId;
|
|
165
|
+
};
|
|
166
|
+
|
|
160
167
|
export type GetBalancesForBridgeArgs = {
|
|
161
168
|
walletAddress: string;
|
|
162
169
|
};
|
|
@@ -176,3 +183,32 @@ export const getERC20Balance = async ({
|
|
|
176
183
|
|
|
177
184
|
return descale(tokenInfo.decimals)(currentBalance);
|
|
178
185
|
};
|
|
186
|
+
|
|
187
|
+
export const getERC20BalanceBatch = async ({
|
|
188
|
+
tokenAddress,
|
|
189
|
+
walletAddress,
|
|
190
|
+
chain,
|
|
191
|
+
}: GetERC20BalanceBatchArgs): Promise<number> => {
|
|
192
|
+
const rpcUrls = ChainRpcUrls[chain];
|
|
193
|
+
if (!rpcUrls || rpcUrls.length === 0) {
|
|
194
|
+
throw new Error('No RPC URLs configured for the chain: ' + chain);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let lastError = null;
|
|
198
|
+
|
|
199
|
+
for (const url of rpcUrls) {
|
|
200
|
+
try {
|
|
201
|
+
const provider = new ethers.JsonRpcProvider(url);
|
|
202
|
+
const token = getERC20TokenContract(tokenAddress, provider);
|
|
203
|
+
const currentBalance = await token.balanceOf(walletAddress);
|
|
204
|
+
|
|
205
|
+
const tokenInfo = getTokenInfoByAddress(convertToAddress(tokenAddress));
|
|
206
|
+
return descale(tokenInfo.decimals)(currentBalance);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
console.error(`Failed to fetch from ${url}:`, error);
|
|
209
|
+
lastError = error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
throw new Error('All RPC URLs failed; last error: ' + lastError);
|
|
214
|
+
};
|