@reyaxyz/common 0.136.0 → 0.137.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.
Files changed (54) hide show
  1. package/README.md +1 -1
  2. package/dist/services/getSocketAddresses.js +12 -22
  3. package/dist/services/getSocketAddresses.js.map +1 -1
  4. package/dist/types/services/getSocketAddresses.d.ts +32 -2
  5. package/dist/types/services/getSocketAddresses.d.ts.map +1 -1
  6. package/dist/types/types.d.ts +1 -9
  7. package/dist/types/types.d.ts.map +1 -1
  8. package/dist/types/utils/network.d.ts +1 -1
  9. package/dist/types/utils/network.d.ts.map +1 -1
  10. package/dist/types/utils/token/batch-token-getters.d.ts +22 -0
  11. package/dist/types/utils/token/batch-token-getters.d.ts.map +1 -0
  12. package/dist/types/utils/token/index.d.ts +6 -0
  13. package/dist/types/utils/token/index.d.ts.map +1 -0
  14. package/dist/types/utils/token/token-getters.d.ts +23 -0
  15. package/dist/types/utils/token/token-getters.d.ts.map +1 -0
  16. package/dist/types/utils/token/token-info-getters.d.ts +6 -0
  17. package/dist/types/utils/token/token-info-getters.d.ts.map +1 -0
  18. package/dist/types/utils/token/token-info.d.ts +3 -0
  19. package/dist/types/utils/token/token-info.d.ts.map +1 -0
  20. package/dist/types/utils/token/utils.d.ts +7 -0
  21. package/dist/types/utils/token/utils.d.ts.map +1 -0
  22. package/dist/types.js.map +1 -1
  23. package/dist/utils/network.js +2 -0
  24. package/dist/utils/network.js.map +1 -1
  25. package/dist/utils/token/batch-token-getters.js +175 -0
  26. package/dist/utils/token/batch-token-getters.js.map +1 -0
  27. package/dist/utils/token/index.js +22 -0
  28. package/dist/utils/token/index.js.map +1 -0
  29. package/dist/utils/token/token-getters.js +104 -0
  30. package/dist/utils/token/token-getters.js.map +1 -0
  31. package/dist/utils/token/token-info-getters.js +49 -0
  32. package/dist/utils/token/token-info-getters.js.map +1 -0
  33. package/dist/utils/{token-info.js → token/token-info.js} +1 -1
  34. package/dist/utils/token/token-info.js.map +1 -0
  35. package/dist/utils/token/utils.js +46 -0
  36. package/dist/utils/token/utils.js.map +1 -0
  37. package/package.json +2 -2
  38. package/src/services/getSocketAddresses.ts +3 -23
  39. package/src/types.ts +1 -11
  40. package/src/utils/network.ts +5 -2
  41. package/src/utils/token/batch-token-getters.ts +111 -0
  42. package/src/utils/token/index.ts +5 -0
  43. package/src/utils/token/token-getters.ts +71 -0
  44. package/src/utils/token/token-info-getters.ts +84 -0
  45. package/src/utils/{token-info.ts → token/token-info.ts} +1 -1
  46. package/src/utils/token/utils.ts +49 -0
  47. package/dist/types/utils/token-info.d.ts +0 -3
  48. package/dist/types/utils/token-info.d.ts.map +0 -1
  49. package/dist/types/utils/token.d.ts +0 -49
  50. package/dist/types/utils/token.d.ts.map +0 -1
  51. package/dist/utils/token-info.js.map +0 -1
  52. package/dist/utils/token.js +0 -340
  53. package/dist/utils/token.js.map +0 -1
  54. package/src/utils/token.ts +0 -317
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getERC20AllowanceBatch = exports.getERC20BalanceBatch = exports.getETHBalanceBatch = void 0;
40
+ var ethers_1 = require("ethers");
41
+ var network_1 = require("../network");
42
+ var retry_1 = require("../retry");
43
+ var utils_1 = require("./utils");
44
+ var getETHBalanceBatch = function (_a) {
45
+ var walletAddress = _a.walletAddress, chain = _a.chain;
46
+ return __awaiter(void 0, void 0, void 0, function () {
47
+ var rpcUrls, lastError, _loop_1, _i, rpcUrls_1, url, state_1;
48
+ return __generator(this, function (_b) {
49
+ switch (_b.label) {
50
+ case 0:
51
+ rpcUrls = network_1.ChainRpcUrls[chain];
52
+ if (!rpcUrls || rpcUrls.length === 0) {
53
+ throw new Error('No RPC URLs configured for the chain: ' + chain);
54
+ }
55
+ lastError = null;
56
+ _loop_1 = function (url) {
57
+ var provider_1, currentBalance, error_1;
58
+ return __generator(this, function (_c) {
59
+ switch (_c.label) {
60
+ case 0:
61
+ _c.trys.push([0, 2, , 3]);
62
+ provider_1 = new ethers_1.ethers.JsonRpcProvider(url);
63
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
64
+ return provider_1.getBalance(ethers_1.ethers.getAddress(walletAddress));
65
+ })];
66
+ case 1:
67
+ currentBalance = _c.sent();
68
+ return [2 /*return*/, { value: (0, utils_1.descale)(18)(currentBalance) }];
69
+ case 2:
70
+ error_1 = _c.sent();
71
+ lastError = error_1;
72
+ return [3 /*break*/, 3];
73
+ case 3: return [2 /*return*/];
74
+ }
75
+ });
76
+ };
77
+ _i = 0, rpcUrls_1 = rpcUrls;
78
+ _b.label = 1;
79
+ case 1:
80
+ if (!(_i < rpcUrls_1.length)) return [3 /*break*/, 4];
81
+ url = rpcUrls_1[_i];
82
+ return [5 /*yield**/, _loop_1(url)];
83
+ case 2:
84
+ state_1 = _b.sent();
85
+ if (typeof state_1 === "object")
86
+ return [2 /*return*/, state_1.value];
87
+ _b.label = 3;
88
+ case 3:
89
+ _i++;
90
+ return [3 /*break*/, 1];
91
+ case 4: throw new Error('All RPC URLs failed; last error: ' + lastError);
92
+ }
93
+ });
94
+ });
95
+ };
96
+ exports.getETHBalanceBatch = getETHBalanceBatch;
97
+ var getERC20BalanceBatch = function (_a) {
98
+ var tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, walletAddress = _a.walletAddress, chain = _a.chain;
99
+ return __awaiter(void 0, void 0, void 0, function () {
100
+ var rpcUrls, lastError, _i, rpcUrls_2, url, provider, token, currentBalance, error_2;
101
+ return __generator(this, function (_b) {
102
+ switch (_b.label) {
103
+ case 0:
104
+ rpcUrls = network_1.ChainRpcUrls[chain];
105
+ if (!rpcUrls || rpcUrls.length === 0) {
106
+ throw new Error('No RPC URLs configured for the chain: ' + chain);
107
+ }
108
+ lastError = null;
109
+ _i = 0, rpcUrls_2 = rpcUrls;
110
+ _b.label = 1;
111
+ case 1:
112
+ if (!(_i < rpcUrls_2.length)) return [3 /*break*/, 6];
113
+ url = rpcUrls_2[_i];
114
+ _b.label = 2;
115
+ case 2:
116
+ _b.trys.push([2, 4, , 5]);
117
+ provider = new ethers_1.ethers.JsonRpcProvider(url);
118
+ token = (0, utils_1.getERC20TokenContract)(tokenAddress, provider);
119
+ return [4 /*yield*/, token.balanceOf(walletAddress)];
120
+ case 3:
121
+ currentBalance = _b.sent();
122
+ return [2 /*return*/, (0, utils_1.descale)(tokenDecimals)(currentBalance)];
123
+ case 4:
124
+ error_2 = _b.sent();
125
+ lastError = error_2;
126
+ return [3 /*break*/, 5];
127
+ case 5:
128
+ _i++;
129
+ return [3 /*break*/, 1];
130
+ case 6: throw new Error('All RPC URLs failed; last error: ' + lastError);
131
+ }
132
+ });
133
+ });
134
+ };
135
+ exports.getERC20BalanceBatch = getERC20BalanceBatch;
136
+ var getERC20AllowanceBatch = function (_a) {
137
+ var tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, walletAddress = _a.walletAddress, spenderAddress = _a.spenderAddress, chain = _a.chain;
138
+ return __awaiter(void 0, void 0, void 0, function () {
139
+ var rpcUrls, lastError, _i, rpcUrls_3, url, provider, token, currentBalance, error_3;
140
+ return __generator(this, function (_b) {
141
+ switch (_b.label) {
142
+ case 0:
143
+ rpcUrls = network_1.ChainRpcUrls[chain];
144
+ if (!rpcUrls || rpcUrls.length === 0) {
145
+ throw new Error('No RPC URLs configured for the chain: ' + chain);
146
+ }
147
+ lastError = null;
148
+ _i = 0, rpcUrls_3 = rpcUrls;
149
+ _b.label = 1;
150
+ case 1:
151
+ if (!(_i < rpcUrls_3.length)) return [3 /*break*/, 6];
152
+ url = rpcUrls_3[_i];
153
+ _b.label = 2;
154
+ case 2:
155
+ _b.trys.push([2, 4, , 5]);
156
+ provider = new ethers_1.ethers.JsonRpcProvider(url);
157
+ token = (0, utils_1.getERC20TokenContract)(tokenAddress, provider);
158
+ return [4 /*yield*/, token.allowance(walletAddress, spenderAddress)];
159
+ case 3:
160
+ currentBalance = _b.sent();
161
+ return [2 /*return*/, (0, utils_1.descale)(tokenDecimals)(currentBalance)];
162
+ case 4:
163
+ error_3 = _b.sent();
164
+ lastError = error_3;
165
+ return [3 /*break*/, 5];
166
+ case 5:
167
+ _i++;
168
+ return [3 /*break*/, 1];
169
+ case 6: throw new Error('All RPC URLs failed; last error: ' + lastError);
170
+ }
171
+ });
172
+ });
173
+ };
174
+ exports.getERC20AllowanceBatch = getERC20AllowanceBatch;
175
+ //# sourceMappingURL=batch-token-getters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch-token-getters.js","sourceRoot":"/","sources":["utils/token/batch-token-getters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAEhC,sCAA0C;AAC1C,kCAA8C;AAC9C,iCAAyD;AAsBlD,IAAM,kBAAkB,GAAG,UAAO,EAGhB;QAFvB,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;wCAEV,GAAG;;;;;;oCAEJ,aAAW,IAAI,eAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oCAC1B,qBAAM,IAAA,0BAAkB,EAAC;4CAC9C,OAAA,UAAQ,CAAC,UAAU,CAAC,eAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;wCAArD,CAAqD,CACtD,EAAA;;oCAFK,cAAc,GAAG,SAEtB;mEACM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B,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,aAAa,mBAAA,EACb,cAAc,oBAAA,EACd,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,CAC1C,aAAa,EACb,cAAc,CACf,EAAA;;oBAHK,cAAc,GAAG,SAGtB;oBAED,sBAAO,IAAA,eAAO,EAAC,aAAa,CAAC,CAAC,cAAc,CAAC,EAAC;;;oBAE9C,SAAS,GAAG,OAAK,CAAC;;;oBAXJ,IAAO,CAAA;;wBAezB,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,SAAS,CAAC,CAAC;;;;CAClE,CAAC;AA9BW,QAAA,sBAAsB,0BA8BjC","sourcesContent":["import { ethers } from 'ethers';\nimport { MoneyInOutChainId, ReyaChainId } from '../../types';\nimport { ChainRpcUrls } from '../network';\nimport { exponentialBackoff } from '../retry';\nimport { descale, getERC20TokenContract } from './utils';\n\nexport type GetETHBalanceBatchArgs = {\n walletAddress: string;\n chain: MoneyInOutChainId | ReyaChainId;\n};\n\nexport type GetERC20BalanceBatchArgs = {\n tokenAddress: string;\n tokenDecimals: number;\n walletAddress: string;\n chain: MoneyInOutChainId | ReyaChainId;\n};\n\nexport type GetERC20AllowanceBatchArgs = {\n tokenAddress: string;\n tokenDecimals: number;\n walletAddress: string;\n spenderAddress: string;\n chain: MoneyInOutChainId | ReyaChainId;\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 tokenDecimals,\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 return descale(tokenDecimals)(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 getERC20AllowanceBatch = async ({\n tokenAddress,\n tokenDecimals,\n walletAddress,\n spenderAddress,\n chain,\n}: GetERC20AllowanceBatchArgs): 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.allowance(\n walletAddress,\n spenderAddress,\n );\n\n return descale(tokenDecimals)(currentBalance);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw new Error('All RPC URLs failed; last error: ' + lastError);\n};\n"]}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./token-getters"), exports);
18
+ __exportStar(require("./batch-token-getters"), exports);
19
+ __exportStar(require("./token-info-getters"), exports);
20
+ __exportStar(require("./utils"), exports);
21
+ __exportStar(require("./token-info"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/token/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,wDAAsC;AACtC,uDAAqC;AACrC,0CAAwB;AACxB,+CAA6B","sourcesContent":["export * from './token-getters';\nexport * from './batch-token-getters';\nexport * from './token-info-getters';\nexport * from './utils';\nexport * from './token-info';\n"]}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getETHBalance = exports.getERC20Balance = exports.getERC20Allowance = void 0;
40
+ var ethers_1 = require("ethers");
41
+ var retry_1 = require("../retry");
42
+ var utils_1 = require("./utils");
43
+ var getERC20Allowance = function (_a) {
44
+ var walletAddress = _a.walletAddress, tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, spenderAddress = _a.spenderAddress, subject = _a.subject;
45
+ return __awaiter(void 0, void 0, void 0, function () {
46
+ var tokenContract, allowance;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ tokenContract = (0, utils_1.getERC20TokenContract)(tokenAddress, subject);
51
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
52
+ return tokenContract.allowance(walletAddress, spenderAddress);
53
+ })];
54
+ case 1:
55
+ allowance = _b.sent();
56
+ return [2 /*return*/, BigInt(allowance) > (0, utils_1.scale)(tokenDecimals)(Number.MAX_SAFE_INTEGER)
57
+ ? Number.MAX_SAFE_INTEGER
58
+ : (0, utils_1.descale)(tokenDecimals)(allowance)];
59
+ }
60
+ });
61
+ });
62
+ };
63
+ exports.getERC20Allowance = getERC20Allowance;
64
+ var getERC20Balance = function (_a) {
65
+ var tokenAddress = _a.tokenAddress, tokenDecimals = _a.tokenDecimals, walletAddress = _a.walletAddress, subject = _a.subject;
66
+ return __awaiter(void 0, void 0, void 0, function () {
67
+ var token, currentBalance;
68
+ return __generator(this, function (_b) {
69
+ switch (_b.label) {
70
+ case 0:
71
+ token = (0, utils_1.getERC20TokenContract)(tokenAddress, subject);
72
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
73
+ return token.balanceOf(walletAddress);
74
+ })];
75
+ case 1:
76
+ currentBalance = _b.sent();
77
+ return [2 /*return*/, (0, utils_1.descale)(tokenDecimals)(currentBalance)];
78
+ }
79
+ });
80
+ });
81
+ };
82
+ exports.getERC20Balance = getERC20Balance;
83
+ var getETHBalance = function (_a) {
84
+ var walletAddress = _a.walletAddress, subject = _a.subject;
85
+ return __awaiter(void 0, void 0, void 0, function () {
86
+ var provider, currentBalance;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
89
+ case 0:
90
+ provider = subject.provider;
91
+ if (!provider)
92
+ throw new Error("User's provider not found");
93
+ return [4 /*yield*/, (0, retry_1.exponentialBackoff)(function () {
94
+ return provider.getBalance(ethers_1.ethers.getAddress(walletAddress));
95
+ })];
96
+ case 1:
97
+ currentBalance = _b.sent();
98
+ return [2 /*return*/, (0, utils_1.descale)(18)(currentBalance)];
99
+ }
100
+ });
101
+ });
102
+ };
103
+ exports.getETHBalance = getETHBalance;
104
+ //# sourceMappingURL=token-getters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-getters.js","sourceRoot":"/","sources":["utils/token/token-getters.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAChC,kCAA8C;AAE9C,iCAAgE;AAsBzD,IAAM,iBAAiB,GAAG,UAAO,EAMhB;QALtB,aAAa,mBAAA,EACb,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,cAAc,oBAAA,EACd,OAAO,aAAA;;;;;;oBAED,aAAa,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAEjD,qBAAM,IAAA,0BAAkB,EAAC;4BACzC,OAAA,aAAa,CAAC,SAAS,CAAC,aAAa,EAAE,cAAc,CAAC;wBAAtD,CAAsD,CACvD,EAAA;;oBAFK,SAAS,GAAG,SAEjB;oBAED,sBAAO,MAAM,CAAC,SAAS,CAAC,GAAG,IAAA,aAAK,EAAC,aAAa,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC;4BACtE,CAAC,CAAC,MAAM,CAAC,gBAAgB;4BACzB,CAAC,CAAC,IAAA,eAAO,EAAC,aAAa,CAAC,CAAC,SAAS,CAAC,EAAC;;;;CACvC,CAAC;AAhBW,QAAA,iBAAiB,qBAgB5B;AAEK,IAAM,eAAe,GAAG,UAAO,EAKhB;QAJpB,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,aAAa,mBAAA,EACb,OAAO,aAAA;;;;;;oBAED,KAAK,GAAG,IAAA,6BAAqB,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;oBAEpC,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,aAAa,CAAC,CAAC,cAAc,CAAC,EAAC;;;;CAC/C,CAAC;AAbW,QAAA,eAAe,mBAa1B;AAEK,IAAM,aAAa,GAAG,UAAO,EAGhB;QAFlB,aAAa,mBAAA,EACb,OAAO,aAAA;;;;;;oBAED,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;oBAClC,IAAI,CAAC,QAAQ;wBAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;oBAErC,qBAAM,IAAA,0BAAkB,EAAC;4BAC9C,OAAA,QAAQ,CAAC,UAAU,CAAC,eAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;wBAArD,CAAqD,CACtD,EAAA;;oBAFK,cAAc,GAAG,SAEtB;oBAED,sBAAO,IAAA,eAAO,EAAC,EAAE,CAAC,CAAC,cAAc,CAAC,EAAC;;;;CACpC,CAAC;AAZW,QAAA,aAAa,iBAYxB","sourcesContent":["import { ethers } from 'ethers';\nimport { exponentialBackoff } from '../retry';\nimport { LpPoolEntity } from '../../types';\nimport { getERC20TokenContract, scale, descale } from './utils';\n\nexport type GetERC20BalanceArgs = {\n tokenAddress: string;\n tokenDecimals: number;\n walletAddress: string;\n subject: ethers.Signer | ethers.Provider;\n};\n\nexport type GetETHBalanceArgs = {\n walletAddress: string;\n subject: ethers.Signer | ethers.Provider;\n};\n\nexport type GetERC20AllowanceArgs = {\n walletAddress: string;\n tokenAddress: LpPoolEntity['tokenAddress'];\n tokenDecimals: number;\n spenderAddress: string;\n subject: ethers.Signer;\n};\n\nexport const getERC20Allowance = async ({\n walletAddress,\n tokenAddress,\n tokenDecimals,\n spenderAddress,\n subject,\n}: GetERC20AllowanceArgs): Promise<number> => {\n const tokenContract = getERC20TokenContract(tokenAddress, subject);\n\n const allowance = await exponentialBackoff(() =>\n tokenContract.allowance(walletAddress, spenderAddress),\n );\n\n return BigInt(allowance) > scale(tokenDecimals)(Number.MAX_SAFE_INTEGER)\n ? Number.MAX_SAFE_INTEGER\n : descale(tokenDecimals)(allowance);\n};\n\nexport const getERC20Balance = async ({\n tokenAddress,\n tokenDecimals,\n walletAddress,\n subject,\n}: GetERC20BalanceArgs): Promise<number> => {\n const token = getERC20TokenContract(tokenAddress, subject);\n\n const currentBalance = await exponentialBackoff(() =>\n token.balanceOf(walletAddress),\n );\n\n return descale(tokenDecimals)(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"]}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRUSDUnderlyingTokenInfo = exports.getTokenInfosByChain = exports.getTokenInfoByName = exports.getTokenInfoByAddress = void 0;
4
+ var token_info_1 = require("./token-info");
5
+ var utils_1 = require("./utils");
6
+ var getTokenInfoByAddress = function (tokenAddressParam, chainId) {
7
+ var tokenAddress = typeof tokenAddressParam === 'string'
8
+ ? (0, utils_1.convertToAddress)(tokenAddressParam)
9
+ : tokenAddressParam;
10
+ if (chainId) {
11
+ var tokenInfo = token_info_1.TOKEN_INFO[chainId].find(function (tokenInfo) { return tokenInfo.address === tokenAddress; });
12
+ if (!tokenInfo) {
13
+ throw new Error("getTokenInfoByAddress: no token info found [chainId ".concat(chainId, ", token address ").concat(tokenAddress, "]"));
14
+ }
15
+ return tokenInfo;
16
+ }
17
+ else {
18
+ for (var chainId_1 in token_info_1.TOKEN_INFO) {
19
+ var tokenInfos = token_info_1.TOKEN_INFO[chainId_1];
20
+ var tokenInfo = tokenInfos.find(function (tokenInfo) { return tokenInfo.address === tokenAddress; });
21
+ if (tokenInfo) {
22
+ return tokenInfo;
23
+ }
24
+ }
25
+ throw new Error("getTokenInfoByAddress: no token info found [token address ".concat(tokenAddress, "]"));
26
+ }
27
+ };
28
+ exports.getTokenInfoByAddress = getTokenInfoByAddress;
29
+ var getTokenInfoByName = function (tokenName, chainId) {
30
+ var tokenInfo = token_info_1.TOKEN_INFO[chainId].find(function (tokenInfo) { return tokenInfo.name === tokenName; });
31
+ if (!tokenInfo) {
32
+ throw new Error("getTokenInfoByName: no token info found [chain id ".concat(chainId, ", token name ").concat(tokenName, "]"));
33
+ }
34
+ return tokenInfo;
35
+ };
36
+ exports.getTokenInfoByName = getTokenInfoByName;
37
+ var getTokenInfosByChain = function (chainId) {
38
+ return token_info_1.TOKEN_INFO[chainId];
39
+ };
40
+ exports.getTokenInfosByChain = getTokenInfosByChain;
41
+ var getRUSDUnderlyingTokenInfo = function (chainId) {
42
+ var tokenInfo = token_info_1.TOKEN_INFO[chainId].find(function (tokenInfo) { return tokenInfo.isRUSDUnderlying === true; });
43
+ if (!tokenInfo) {
44
+ throw new Error("getRUSDUnderlyingTokenInfo: no token info found [chain id ".concat(chainId, "]"));
45
+ }
46
+ return tokenInfo;
47
+ };
48
+ exports.getRUSDUnderlyingTokenInfo = getRUSDUnderlyingTokenInfo;
49
+ //# sourceMappingURL=token-info-getters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-info-getters.js","sourceRoot":"/","sources":["utils/token/token-info-getters.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAQ1C,iCAA2C;AAEpC,IAAM,qBAAqB,GAAG,UACnC,iBAAmC,EACnC,OAAyC;IAEzC,IAAM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,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B;AAEK,IAAM,oBAAoB,GAAG,UAClC,OAAwC;IAExC,OAAO,uBAAU,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC,CAAC;AAJW,QAAA,oBAAoB,wBAI/B;AAEK,IAAM,0BAA0B,GAAG,UACxC,OAAwC;IAExC,IAAM,SAAS,GAAG,uBAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CACxC,UAAC,SAAS,IAAK,OAAA,SAAS,CAAC,gBAAgB,KAAK,IAAI,EAAnC,CAAmC,CACnD,CAAC;IAEF,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,oEAA6D,OAAO,MAAG,CACxE,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAdW,QAAA,0BAA0B,8BAcrC","sourcesContent":["import { TOKEN_INFO } from './token-info';\nimport {\n Address,\n MoneyInOutChainId,\n ReyaChainId,\n TokenInfo,\n TokenName,\n} from '../../types';\nimport { convertToAddress } from './utils';\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"]}
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
13
13
  var _a;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TOKEN_INFO = void 0;
16
- var types_1 = require("../types");
16
+ var types_1 = require("../../types");
17
17
  var defaultTokenThresholds = {
18
18
  minDepositAmount: 10,
19
19
  minWithdrawAmount: 10,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-info.js","sourceRoot":"/","sources":["utils/token/token-info.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,qCAAwE;AAExE,IAAM,sBAAsB,GAGxB;IACF,gBAAgB,EAAE,EAAE;IACpB,iBAAiB,EAAE,EAAE;IACrB,iBAAiB,EAAE,EAAE;CACtB,CAAC;AAEW,QAAA,UAAU;IAEnB,4DAA4D;IAC5D,4DAA4D;IAC5D,4DAA4D;IAC5D,GAAC,mBAAW,CAAC,WAAW,IAAG;mBAEvB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,4CA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AAgB,EAAE,KAAK,IACpB,sBAAsB;KAE5B;QACD","sourcesContent":["import { MoneyInOutChainId, ReyaChainId, TokenInfo } from '../../types';\n\nconst defaultTokenThresholds: Pick<\n TokenInfo,\n 'minDepositAmount' | 'minWithdrawAmount' | 'minTransferAmount'\n> = {\n minDepositAmount: 10,\n minWithdrawAmount: 10,\n minTransferAmount: 10,\n};\n\nexport const TOKEN_INFO: Record<ReyaChainId | MoneyInOutChainId, TokenInfo[]> =\n {\n /* ------------------------------------------------------ */\n /* MAINNET */\n /* ------------------------------------------------------ */\n [ReyaChainId.reyaNetwork]: [\n {\n name: 'RUSD',\n address: '0xa9f32a851b1800742e47725da54a09a7ef2556a3',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDC',\n address: '0x3b860c0b53f2e8bd5264aa7c3451d41263c933f2',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n },\n {\n name: 'WETH',\n address: '0x6b48c2e6a32077ec17e8ba0d98ffc676dfab1a30',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n ],\n [MoneyInOutChainId.ethereumMainnet]: [\n {\n name: 'USDC',\n address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n minWithdrawAmount: 28,\n },\n {\n name: 'WETH',\n address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',\n decimals: 18,\n isRUSDUnderlying: false,\n whitelistedWalletOnly: true,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n ],\n [MoneyInOutChainId.opMainnet]: [\n {\n name: 'USDC.E',\n address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n minWithdrawAmount: 10,\n },\n {\n name: 'WETH',\n address: '0x4200000000000000000000000000000000000006',\n decimals: 18,\n isRUSDUnderlying: false,\n whitelistedWalletOnly: true,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n ],\n [MoneyInOutChainId.polygonMainnet]: [\n {\n name: 'USDC.E',\n address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n minWithdrawAmount: 10,\n },\n {\n name: 'WETH',\n address: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n decimals: 18,\n isRUSDUnderlying: false,\n whitelistedWalletOnly: true,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n ],\n [MoneyInOutChainId.arbitrumOne]: [\n {\n name: 'USDC.E',\n address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n minWithdrawAmount: 10,\n },\n {\n name: 'WETH',\n address: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',\n decimals: 18,\n isRUSDUnderlying: false,\n whitelistedWalletOnly: true,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n ],\n [MoneyInOutChainId.baseMainnet]: [\n {\n name: 'USDC',\n address: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n minWithdrawAmount: 10,\n },\n {\n name: 'WETH',\n address: '0x4200000000000000000000000000000000000006',\n decimals: 18,\n isRUSDUnderlying: false,\n whitelistedWalletOnly: true,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n ],\n\n /* ------------------------------------------------------ */\n /* TESTNET */\n /* ------------------------------------------------------ */\n [ReyaChainId.reyaCronos]: [\n {\n name: 'RUSD',\n address: '0x26ee9dfb27f12990d90ec003af7c5e9c19ea2a4c',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDC',\n address: '0x1b700a40a0707dd5f0bc31cbc57d730558e5714d',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDT',\n address: '0x9ade781dacbd220f0161d98f496a2982b231a9d6',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'DAI',\n address: '0x733299259c45726ee1bfc9bd0deeba58e48a1853',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'WETH',\n address: '0xc123b7aeb9d2b2e8a035217d5c29e317c91842e2',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n {\n name: 'WBTC',\n address: '0xd382e2f0df859ff9e82f963dcad1aaee939c5e4f',\n decimals: 8,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n ],\n [MoneyInOutChainId.polygonMumbai]: [\n {\n name: 'USDC',\n address: '0xd9edcc943ed9729b08e52bb1e110fe43d1930773',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDT',\n address: '0x4f8ecb190b9ef36113127d97c7f9300875b6563f',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'DAI',\n address: '0x35479b023e508ee9a7b533dbb5b516bb6875f937',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'WETH',\n address: '0x6c7a28f6ae2d245b0130520b112fa3544a06d9ae',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n {\n name: 'WBTC',\n address: '0x92c7a51bd507736ac0dda48b5f35a4aad0c2bb4d',\n decimals: 8,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n ],\n [MoneyInOutChainId.arbitrumSepolia]: [\n {\n name: 'USDC',\n address: '0x8537307810fc40f4073a12a38554d4ff78efff41',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDT',\n address: '0x66dfb9987c36c4be232156e70b085f664367599a',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'DAI',\n address: '0x9a573b27d7298c6e2f4d2d4a41c37a0c8af6acca',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'WETH',\n address: '0x565810cbfa3cf1390963e5afa2fb953795686339',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n {\n name: 'WBTC',\n address: '0x1019958c2bd43b882a4e1349337a32ef9563fc4d',\n decimals: 8,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n ],\n [MoneyInOutChainId.opSepolia]: [\n {\n name: 'USDC',\n address: '0x6d290609b3f5f02d52f28d97c75a443ed8564cbf',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDT',\n address: '0x2d1aba6fabae80bf5c1c9ea433aae9030e07cb22',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'DAI',\n address: '0xdc0258dc3db980090e97ebf4f1fd9cc3c5ad5894',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'WETH',\n address: '0x2b42affd4b7c14d9b7c2579229495c052672ccd3',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n {\n name: 'WBTC',\n address: '0xfc5cc93d85861ac82d89fc2d3e56315540e9c8a7',\n decimals: 8,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n ],\n [MoneyInOutChainId.ethereumSepolia]: [\n {\n name: 'USDC',\n address: '0x565810cbfa3cf1390963e5afa2fb953795686339',\n decimals: 6,\n isRUSDUnderlying: true,\n ...defaultTokenThresholds,\n },\n {\n name: 'USDT',\n address: '0xb4130e87a180b9448286b291331aee8a9c154a3a',\n decimals: 6,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'DAI',\n address: '0x255745e5c7ae620b7f523f5e4a0ead37660ec5d6',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n {\n name: 'WETH',\n address: '0x771d1ae208377453d478df08bbc38034f72ac833',\n decimals: 18,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n minDepositAmount: 0.01,\n minWithdrawAmount: 0.01,\n minTransferAmount: 0.01,\n },\n {\n name: 'WBTC',\n address: '0x94beff5da6201cb2c8f489196fd970b3df5aa32a',\n decimals: 8,\n isRUSDUnderlying: false,\n ...defaultTokenThresholds,\n },\n ],\n };\n"]}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToAddress = exports.getERC20TokenContract = exports.scale = exports.descale = void 0;
4
+ var ethers_1 = require("ethers");
5
+ var descale = function (tokenDecimals) {
6
+ var f = function (value) {
7
+ return Number(ethers_1.ethers.formatUnits(value.toString(), tokenDecimals));
8
+ };
9
+ return f;
10
+ };
11
+ exports.descale = descale;
12
+ var scale = function (tokenDecimals) {
13
+ return function (value) {
14
+ // Convert the number to a string
15
+ var valueStr = value.toString();
16
+ // Split the string into whole and fractional parts
17
+ // eslint-disable-next-line prefer-const
18
+ var _a = valueStr.split('.'), whole = _a[0], _b = _a[1], fractional = _b === void 0 ? '' : _b;
19
+ // Ensure the fractional part is the correct length, padding with zeros if necessary
20
+ fractional = fractional
21
+ .padEnd(tokenDecimals, '0')
22
+ .substring(0, tokenDecimals);
23
+ // Concatenate the whole part with the correctly length-limited fractional part
24
+ var scaledValueStr = whole + fractional;
25
+ // Convert the concatenated string to a BigInt, assuming it represents a value in wei (or equivalent smallest unit)
26
+ // This is safe as we're not losing precision - just scaling the number to its smallest unit representation
27
+ return BigInt(scaledValueStr);
28
+ };
29
+ };
30
+ exports.scale = scale;
31
+ var getERC20TokenContract = function (tokenAddress, subject) {
32
+ var abi = [
33
+ "function approve(address, uint256) external returns (bool)",
34
+ "function balanceOf(address) external view returns (uint256)",
35
+ "function allowance(address,address) external view returns (uint256)",
36
+ "function approve(address,uint256) external returns (bool)",
37
+ ];
38
+ var contract = new ethers_1.ethers.Contract(tokenAddress, abi, subject);
39
+ return contract;
40
+ };
41
+ exports.getERC20TokenContract = getERC20TokenContract;
42
+ var convertToAddress = function (str) {
43
+ return str.toLowerCase();
44
+ };
45
+ exports.convertToAddress = convertToAddress;
46
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"/","sources":["utils/token/utils.ts"],"names":[],"mappings":";;;AAAA,iCAAgC;AAGzB,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,OAAwC;IAExC,IAAM,GAAG,GAAa;QACpB,4DAA4D;QAC5D,6DAA6D;QAC7D,qEAAqE;QACrE,2DAA2D;KAC5D,CAAC;IAEF,IAAM,QAAQ,GAAG,IAAI,eAAM,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAEjE,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAdW,QAAA,qBAAqB,yBAchC;AAEK,IAAM,gBAAgB,GAAG,UAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,WAAW,EAAa,CAAC;AACtC,CAAC,CAAC;AAFW,QAAA,gBAAgB,oBAE3B","sourcesContent":["import { ethers } from 'ethers';\nimport { Address } from '../../types';\n\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: ethers.Signer | ethers.Provider,\n): ethers.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 ethers.Contract(tokenAddress, abi, subject);\n\n return contract;\n};\n\nexport const convertToAddress = (str: string): Address => {\n return str.toLowerCase() as Address;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/common",
3
- "version": "0.136.0",
3
+ "version": "0.137.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": "51ccbadf06f7980fbcbaac1a1fc43157d6c90ad5"
46
+ "gitHead": "0af399e0a55cc36199d8a49deadf937faa6f780e"
47
47
  }
@@ -2,7 +2,6 @@ import {
2
2
  ReyaChainId,
3
3
  GetSocketConnectorsParams,
4
4
  Address,
5
- GetSocketControllerParams,
6
5
  MoneyInOutChainId,
7
6
  GetSocketVaultParams,
8
7
  SocketTokenConnectors,
@@ -12,8 +11,8 @@ import {
12
11
  import {
13
12
  getMoneyInOutNetworksFromReyaChainId,
14
13
  getReyaNetworkFromMoneyInOutChainId,
15
- } from '../utils/network';
16
- import { convertToAddress } from '../utils/token';
14
+ convertToAddress,
15
+ } from '../utils';
17
16
 
18
17
  import * as REYA_CRONOS from '../utils/socket/reyaCronos.json';
19
18
  import * as REYA_NETWORK from '../utils/socket/reyaNetwork.json';
@@ -62,7 +61,7 @@ export type SocketConnectorAddresses = {
62
61
  ['FAST']?: string;
63
62
  };
64
63
 
65
- const getSocketDeploymentJSON = (
64
+ export const getSocketDeploymentJSON = (
66
65
  reyaChainId: ReyaChainId,
67
66
  ): SocketDeploymentAddresses => {
68
67
  switch (reyaChainId) {
@@ -111,25 +110,6 @@ export const getSocketConnectors = (
111
110
  };
112
111
  };
113
112
 
114
- export const getSocketController = (
115
- params: GetSocketControllerParams,
116
- ): Address => {
117
- const deploymentJSON = getSocketDeploymentJSON(params.reyaChainId);
118
- const controller = (
119
- deploymentJSON?.[params.reyaChainId]?.[
120
- params.tokenName
121
- ] as SocketAppChainAddresses
122
- )?.[SocketSuperBridgeContracts.Controller];
123
-
124
- if (!controller) {
125
- throw new Error(
126
- `getSocketController: controller not found ${JSON.stringify(params)}`,
127
- );
128
- }
129
-
130
- return convertToAddress(controller);
131
- };
132
-
133
113
  export const getSocketVault = (params: GetSocketVaultParams): Address => {
134
114
  const reyaChainId = getReyaNetworkFromMoneyInOutChainId(
135
115
  params.moneyInOutChainId,
package/src/types.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { Signer } from 'ethers';
2
-
3
1
  export type Address = Lowercase<string>;
4
2
  export type TokenName = Uppercase<string>;
5
3
 
@@ -279,11 +277,6 @@ export type GetSocketConnectorsParams = {
279
277
  tokenName: TokenName;
280
278
  };
281
279
 
282
- export type GetSocketControllerParams = {
283
- reyaChainId: ReyaChainId;
284
- tokenName: TokenName;
285
- };
286
-
287
280
  export type GetSocketVaultParams = {
288
281
  moneyInOutChainId: MoneyInOutChainId;
289
282
  tokenName: TokenName;
@@ -418,11 +411,8 @@ export type GetFundingRateChartDataResult = {
418
411
  fundingRate: number;
419
412
  };
420
413
 
421
- export type GetERC20AllowanceParams = {
414
+ export type GetBalancesForBridgeArgs = {
422
415
  walletAddress: string;
423
- tokenAddress: LpPoolEntity['tokenAddress'];
424
- spenderAddress: string;
425
- subject: Signer;
426
416
  };
427
417
 
428
418
  export type DepthSimulationState = {
@@ -76,7 +76,10 @@ export const chainIdToExplorerURL: {
76
76
  [ReyaChainId.reyaCronos]: 'https://reya-cronos.blockscout.com',
77
77
  };
78
78
 
79
- export const ChainRpcUrls: { [key in MoneyInOutChainId]: string[] } = {
79
+ export const ChainRpcUrls: {
80
+ [key in MoneyInOutChainId | ReyaChainId]: string[];
81
+ } = {
82
+ [ReyaChainId.reyaNetwork]: ['https://rpc.reya.network'],
80
83
  [MoneyInOutChainId.ethereumMainnet]: [
81
84
  'https://mainnet.gateway.tenderly.co',
82
85
  'https://eth.llamarpc.com',
@@ -118,7 +121,7 @@ export const ChainRpcUrls: { [key in MoneyInOutChainId]: string[] } = {
118
121
  'https://base.gateway.tenderly.co/2LHAD54IBvgXiVQdhE9mIF',
119
122
  ],
120
123
  // Add the rest of the mainnet URLs above
121
-
124
+ [ReyaChainId.reyaCronos]: ['https://rpc.reya-cronos.gelato.digital'],
122
125
  [MoneyInOutChainId.polygonMumbai]: [
123
126
  'https://polygon-mumbai.gateway.tenderly.co',
124
127
  'https://polygon-mumbai-bor-rpc.publicnode.com',