@ercworldio/blockchain-shared 1.0.0-dev.4 → 1.0.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/build/chains/networks_dev.json +9 -55
- package/build/chains/networks_prod-bu.json +26 -0
- package/build/chains/networks_prod.json +233 -221
- package/build/services/AccountingService.d.ts +1 -1
- package/build/services/AccountingService.d.ts.map +1 -1
- package/build/services/ChainManager.d.ts.map +1 -1
- package/build/services/ChainManager.js +10 -8
- package/build/services/ClaimJobService.d.ts +1 -0
- package/build/services/ClaimJobService.d.ts.map +1 -1
- package/build/services/ClaimJobService.js +9 -0
- package/build/services/DepositAddressService.d.ts +1 -0
- package/build/services/DepositAddressService.d.ts.map +1 -1
- package/build/services/DepositAddressService.js +11 -0
- package/build/services/InvoiceQueue.d.ts +1 -1
- package/build/services/InvoiceQueue.d.ts.map +1 -1
- package/build/services/ProviderManager.d.ts.map +1 -1
- package/build/services/ProviderManager.js +6 -1
- package/build/services/Redis.d.ts +20 -9
- package/build/services/Redis.d.ts.map +1 -1
- package/build/services/Redis.js +246 -199
- package/build/services/RedisListQueue.d.ts.map +1 -1
- package/build/services/RedisListQueue.js +7 -1
- package/build/services/SweepJobService.d.ts +1 -0
- package/build/services/SweepJobService.d.ts.map +1 -1
- package/build/services/SweepJobService.js +9 -0
- package/build/services/TimerManager.d.ts.map +1 -1
- package/build/services/TimerManager.js +9 -1
- package/build/services/WithdrawalManager.d.ts +1 -1
- package/build/services/WithdrawalManager.d.ts.map +1 -1
- package/build/services/WithdrawalManager.js +41 -37
- package/build/services/solana/escrow/SolanaEscrowAdmin.d.ts +1 -1
- package/build/services/solana/escrow/SolanaEscrowAdmin.d.ts.map +1 -1
- package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts +2 -1
- package/build/services/solana/escrow/services/EscrowAdminUtility.d.ts.map +1 -1
- package/build/services/solana/escrow/services/EscrowAdminUtility.js +4 -2
- package/build/services/utils/alchemy.js +1 -1
- package/build/utils/AsyncRateLimiter.d.ts.map +1 -1
- package/build/utils/AsyncRateLimiter.js +3 -0
- package/build/utils/custodial.js +2 -2
- package/package.json +2 -2
|
@@ -142,7 +142,9 @@ class TimerManager {
|
|
|
142
142
|
exists_timer(userId, blockchain) {
|
|
143
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
144
|
const key = this.getTimerKey(userId, blockchain);
|
|
145
|
+
console.log(`Getting existing timer for user ID ${userId} blockchain ${blockchain}`);
|
|
145
146
|
const timer = yield this.redis.get(key);
|
|
147
|
+
console.log(`Got timer: `, timer);
|
|
146
148
|
if (!timer)
|
|
147
149
|
return false;
|
|
148
150
|
return true;
|
|
@@ -150,12 +152,15 @@ class TimerManager {
|
|
|
150
152
|
}
|
|
151
153
|
create_if_not_exists(wallet_1, timeout_ms_1, subscription_1) {
|
|
152
154
|
return __awaiter(this, arguments, void 0, function* (wallet, timeout_ms, subscription, bonus_code = "") {
|
|
155
|
+
console.log(``);
|
|
153
156
|
if (!this.initialized)
|
|
154
157
|
yield this.initialize();
|
|
155
158
|
const exists = yield this.exists_timer(wallet.userId, wallet.blockchain);
|
|
156
159
|
if (exists)
|
|
157
160
|
return true;
|
|
161
|
+
console.log(`Timer does not exist, creating...`);
|
|
158
162
|
yield this.create_timer(wallet, timeout_ms, subscription, bonus_code);
|
|
163
|
+
console.log(`Created timer...`, { wallet, timeout_ms, subscription, bonus_code });
|
|
159
164
|
return true;
|
|
160
165
|
});
|
|
161
166
|
}
|
|
@@ -171,11 +176,14 @@ class TimerManager {
|
|
|
171
176
|
create_timer(wallet_1, timeout_ms_1, subscription_1) {
|
|
172
177
|
return __awaiter(this, arguments, void 0, function* (wallet, timeout_ms, subscription, bonus_code = "") {
|
|
173
178
|
try {
|
|
174
|
-
|
|
179
|
+
console.log(`Creating timer, clearing old first..`);
|
|
175
180
|
// Clear existing timer if any
|
|
176
181
|
yield this.clear_timer(wallet.userId, wallet.blockchain);
|
|
182
|
+
console.log(`Cleared timer.`);
|
|
177
183
|
yield this.set_clear_address_data(wallet, subscription, timeout_ms + 100000);
|
|
184
|
+
console.log(`Set clear address data..`);
|
|
178
185
|
yield this._create_timer(wallet, timeout_ms, bonus_code);
|
|
186
|
+
console.log(`Created timer.`);
|
|
179
187
|
return true;
|
|
180
188
|
}
|
|
181
189
|
catch (error) {
|
|
@@ -30,7 +30,7 @@ declare class WithdrawalManager extends Errors {
|
|
|
30
30
|
estimate_in_decimals: number;
|
|
31
31
|
estimate_in_usdt: bigint;
|
|
32
32
|
estimate_in_usdt_decimals: number;
|
|
33
|
-
token_price:
|
|
33
|
+
token_price: number;
|
|
34
34
|
estimate_in_usdt_precision: number;
|
|
35
35
|
}>;
|
|
36
36
|
get_estimate_for_batch: (blockchain: BlockchainType, chain_id: ChainId, queue: ClaimJobs[], extra_config?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithdrawalManager.d.ts","sourceRoot":"","sources":["../../src/services/WithdrawalManager.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,MAAM,8BAA8B,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAYxD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAIrF,cAAM,iBAAkB,SAAQ,MAAM;IAClC,OAAO,CAAC,kBAAkB,CAAmB;IAC7C,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAgB;gBAClB,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO;IAQlD,OAAO,CAAC,2BAA2B,CAGlC;IAGM,oBAAoB,GAAU,IAA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,cAAc,EAAE,UAAU,OAAO,EAAE,OAAO,SAAS,EAAE;;;OAgB7G;IAMM,sBAAsB,GAAU,YAAY,cAAc,EAAE,UAAU,OAAO,EAAE,UAAU,MAAM,EAAE,OAAO,MAAM,EAAE,kBAAkB,MAAM,EAAE,SAAS,MAAM;;;;;;;;;;;;;;OA2E/J;IAIM,sBAAsB,GAAU,YAAY,cAAc,EAAE,UAAU,OAAO,EAAE,OAAO,SAAS,EAAE,EAAE,eAAe;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;;;;OAiD/K;IAKD,OAAO,CAAC,sBAAsB,CAoC7B;IAKD,OAAO,CAAC,2BAA2B,CAsDlC;IAED,OAAO,CAAC,sBAAsB,CAuB7B;IAED,OAAO,CAAC,sCAAsC,CAiG7C;CAGJ;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -61,15 +61,14 @@ class WithdrawalManager extends TransactionsErrors_1.default {
|
|
|
61
61
|
this.estimate_batch_withdraw_cost = (blockchain, chain_id, queue) => __awaiter(this, void 0, void 0, function* () {
|
|
62
62
|
if (blockchain !== "solana" && blockchain !== "evm")
|
|
63
63
|
throw new Error();
|
|
64
|
-
|
|
64
|
+
if (queue.length === 0)
|
|
65
|
+
return { estimation_map: new Map(), updated_queue: [] };
|
|
65
66
|
const accounting = new AccountingService_1.default(this.dbPool, this.config);
|
|
66
67
|
// Get native token price in usdt
|
|
67
68
|
const token_price = yield (0, Utility_1.retryWithExponentialBackoff)(() => accounting.get_crypto_rate(chain_id));
|
|
68
|
-
const user_id_set = new Set();
|
|
69
|
-
queue.map(j => user_id_set.add(j.user_id));
|
|
70
69
|
// Estimate total transaction cost with batch withdrawal
|
|
71
70
|
const { estimate, tx_count } = yield this.get_estimate_for_batch(blockchain, chain_id, queue);
|
|
72
|
-
const { estimation_map, updated_queue } = this.calculate_estimate_for_user(blockchain, token_price,
|
|
71
|
+
const { estimation_map, updated_queue } = this.calculate_estimate_for_user(blockchain, token_price, estimate, tx_count, queue);
|
|
73
72
|
return { estimation_map, updated_queue };
|
|
74
73
|
});
|
|
75
74
|
// Estimates the cost to be paid by the user when their transaction is included in a batch withdrawal
|
|
@@ -125,7 +124,7 @@ class WithdrawalManager extends TransactionsErrors_1.default {
|
|
|
125
124
|
}
|
|
126
125
|
else {
|
|
127
126
|
// Calculate payable cost for user
|
|
128
|
-
const { estimation_map, user_cost } = this.calculate_estimate_for_user(blockchain, token_price,
|
|
127
|
+
const { estimation_map, user_cost } = this.calculate_estimate_for_user(blockchain, token_price, estimate, tx_count, recent_queue);
|
|
129
128
|
const display_exchange_rate = yield accounting.convert_amount_to_currency(user_cost.estimate_in_usdt_decimals, "USD", display_currency);
|
|
130
129
|
// Return user estimation
|
|
131
130
|
return {
|
|
@@ -151,19 +150,17 @@ class WithdrawalManager extends TransactionsErrors_1.default {
|
|
|
151
150
|
}
|
|
152
151
|
else if (blockchain === "evm") {
|
|
153
152
|
// Build evm batch withdraw payload
|
|
154
|
-
const payloads = queue.map(j => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (payloads.length === 0 && extra_config && extra_config.token) {
|
|
164
|
-
const amount = extra_config.token === ethers_1.ethers.ZeroAddress ? (0, ethers_1.parseEther)('0.1') : (0, ethers_1.parseUnits)('100', 6);
|
|
153
|
+
const payloads = queue.map(j => ({
|
|
154
|
+
amount_in_tokens: j.amount,
|
|
155
|
+
requestId: j.request_id,
|
|
156
|
+
token: j.token,
|
|
157
|
+
receiver: j.receiver
|
|
158
|
+
}));
|
|
159
|
+
// In case queue is empty, push a mock tx for gas estimation only
|
|
160
|
+
// amount_in_tokens = 1 (minimum unit) to avoid triggering balance checks in the contract
|
|
161
|
+
if (payloads.length === 0 && (extra_config === null || extra_config === void 0 ? void 0 : extra_config.token)) {
|
|
165
162
|
payloads.push({
|
|
166
|
-
amount_in_tokens:
|
|
163
|
+
amount_in_tokens: BigInt(1),
|
|
167
164
|
requestId: 0,
|
|
168
165
|
token: extra_config.token,
|
|
169
166
|
receiver: funds_manager.address
|
|
@@ -173,7 +170,7 @@ class WithdrawalManager extends TransactionsErrors_1.default {
|
|
|
173
170
|
const transaction_cost = yield (0, custodial_1.estimate_escrow_method_call_cost)(chain_id, payloads, this.dbPool, this.config);
|
|
174
171
|
return { estimate: transaction_cost, estimate_decimals: Number(ethers_1.ethers.formatEther(transaction_cost)), tx_count: payloads.length };
|
|
175
172
|
}
|
|
176
|
-
//
|
|
173
|
+
// Implement tron estimation
|
|
177
174
|
else if (blockchain === constants_1.BLOCKCHAINS.TRON) {
|
|
178
175
|
const tronFeeConfig = (_a = ChainManager_1.default.getInstance(this.config).getChainConfigForChainIdSync(parseInt(chain_id))) === null || _a === void 0 ? void 0 : _a.tronConfig;
|
|
179
176
|
if (!tronFeeConfig) {
|
|
@@ -227,42 +224,36 @@ class WithdrawalManager extends TransactionsErrors_1.default {
|
|
|
227
224
|
};
|
|
228
225
|
return estimation;
|
|
229
226
|
};
|
|
230
|
-
// Given
|
|
231
|
-
// Returns mapping of userid to total cost
|
|
232
|
-
|
|
233
|
-
// TODO: CHECK THIS LOGIC
|
|
234
|
-
this.calculate_estimate_for_user = (blockchain, token_price, user_ids, total_fee, tx_count, queue) => {
|
|
227
|
+
// Given a queue of jobs, calculates each user's share of the batch cost
|
|
228
|
+
// Returns mapping of userid to total cost and a queue with adjusted amounts
|
|
229
|
+
this.calculate_estimate_for_user = (blockchain, token_price, total_fee, tx_count, queue) => {
|
|
235
230
|
// Userid to estimation map
|
|
236
231
|
const user_map = new Map();
|
|
237
232
|
const user_cost = this.calculate_cost_per_job(blockchain, token_price, total_fee, tx_count);
|
|
233
|
+
// Calculate cost per unit = total_fee / tx_count (user_job_count is always 1 in calculate_cost_per_job)
|
|
234
|
+
const unit_cost = BigInt(user_cost.estimate_units) / BigInt(user_cost.user_job_count);
|
|
238
235
|
// Calculate new amounts including the payable fee
|
|
239
236
|
const updated_queue = queue.map(j => {
|
|
240
|
-
// const user_cost = user_map.get(j.user_id);
|
|
241
|
-
// TODO: Handle error
|
|
242
|
-
if (!user_cost)
|
|
243
|
-
throw new Error();
|
|
244
|
-
// Calculate cost on avg in native tokens
|
|
245
|
-
const unit_cost = BigInt(user_cost.estimate_units) / BigInt(user_cost.user_job_count);
|
|
246
237
|
if (blockchain === constants_1.BLOCKCHAINS.SOLANA) {
|
|
247
|
-
// Solana token
|
|
238
|
+
// Solana native token
|
|
248
239
|
if (new web3_js_1.PublicKey(j.token).toBase58() === web3_js_1.SystemProgram.programId.toBase58()) {
|
|
249
|
-
|
|
240
|
+
// Intentional in-place mutation: mutates the original ClaimJobs object so spread picks up the updated amount
|
|
241
|
+
if (unit_cost < BigInt(j.amount))
|
|
250
242
|
j.amount = BigInt(j.amount) - unit_cost;
|
|
251
|
-
|
|
252
|
-
// TODO: Drop this job since the cost is higher
|
|
243
|
+
// TODO: Drop this job since the cost is higher than amount
|
|
253
244
|
return Object.assign(Object.assign({}, j), { fee_data: user_cost });
|
|
254
245
|
}
|
|
255
246
|
else {
|
|
256
|
-
// SPL token
|
|
247
|
+
// SPL token
|
|
257
248
|
return this.parse_cost_stable_coin(blockchain, user_cost, j, unit_cost, token_price);
|
|
258
249
|
}
|
|
259
250
|
}
|
|
260
251
|
else if (blockchain === constants_1.BLOCKCHAINS.EVM) {
|
|
261
|
-
// Directly deduct
|
|
252
|
+
// Directly deduct from native amount
|
|
262
253
|
if (j.token === ethers_1.ethers.ZeroAddress) {
|
|
263
|
-
|
|
254
|
+
// Intentional in-place mutation: mutates the original ClaimJobs object so spread picks up the updated amount
|
|
255
|
+
if (unit_cost < BigInt(j.amount))
|
|
264
256
|
j.amount = BigInt(j.amount) - unit_cost;
|
|
265
|
-
}
|
|
266
257
|
return Object.assign(Object.assign({}, j), { fee_data: user_cost });
|
|
267
258
|
}
|
|
268
259
|
else {
|
|
@@ -273,6 +264,19 @@ class WithdrawalManager extends TransactionsErrors_1.default {
|
|
|
273
264
|
else
|
|
274
265
|
throw new Error(this.UnsupportedResource(`blockchain ${blockchain}`));
|
|
275
266
|
});
|
|
267
|
+
// Populate estimation_map: aggregate per-user total cost (user may have multiple jobs)
|
|
268
|
+
const user_job_counts = new Map();
|
|
269
|
+
queue.forEach(j => { var _a; return user_job_counts.set(j.user_id, ((_a = user_job_counts.get(j.user_id)) !== null && _a !== void 0 ? _a : 0) + 1); });
|
|
270
|
+
for (const [uid, count] of user_job_counts.entries()) {
|
|
271
|
+
user_map.set(uid, {
|
|
272
|
+
user_job_count: count,
|
|
273
|
+
estimate_units: user_cost.estimate_units * BigInt(count),
|
|
274
|
+
estimate_in_decimals: user_cost.estimate_in_decimals * count,
|
|
275
|
+
estimate_in_usdt: user_cost.estimate_in_usdt * BigInt(count),
|
|
276
|
+
estimate_in_usdt_decimals: user_cost.estimate_in_usdt_decimals * count,
|
|
277
|
+
token_price
|
|
278
|
+
});
|
|
279
|
+
}
|
|
276
280
|
return { estimation_map: user_map, updated_queue, user_cost };
|
|
277
281
|
};
|
|
278
282
|
this.parse_cost_stable_coin = (blockchain, user_cost, job, unit_cost, token_price) => {
|
|
@@ -40,7 +40,7 @@ declare class SolanaEscrowAdmin {
|
|
|
40
40
|
* @returns
|
|
41
41
|
*/
|
|
42
42
|
is_payment_token: (token_address: string) => Promise<boolean>;
|
|
43
|
-
get_balances: () => Promise<[string,
|
|
43
|
+
get_balances: () => Promise<[string, number][]>;
|
|
44
44
|
/**
|
|
45
45
|
* Gets the payment tokens list
|
|
46
46
|
* @returns string[]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaEscrowAdmin.d.ts","sourceRoot":"","sources":["../../../../src/services/solana/escrow/SolanaEscrowAdmin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAqC,MAAM,iB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AAkB,MAAM,iCAEnG;IAED;;;;;OAKG;IACI,OAAO,GAAU,eAAe,MAAM,EAAE,oBAAoB,MAAM,qBAExE;CAKJ;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -24,7 +24,7 @@ export declare class EscrowAdminUtility {
|
|
|
24
24
|
* @returns
|
|
25
25
|
*/
|
|
26
26
|
is_payment_token(target_address: string): Promise<boolean>;
|
|
27
|
-
get_balances(): Promise<[string,
|
|
27
|
+
get_balances(): Promise<[string, number][]>;
|
|
28
28
|
/**
|
|
29
29
|
* Gets the list of allowed payment tokens registered in the escrow program
|
|
30
30
|
* @returns string[] - array of payment token addresses
|
|
@@ -90,6 +90,7 @@ export declare class EscrowAdminUtility {
|
|
|
90
90
|
* @returns string - signature
|
|
91
91
|
*/
|
|
92
92
|
withdraw_batch(token_address: string, recipients: BatchReceiver[], signer?: Keypair): Promise<string>;
|
|
93
|
+
/** @dev this might fail if the recipient does not have an ATA - take care of it in funding worker task */
|
|
93
94
|
private batch_withdraw_spl;
|
|
94
95
|
private batch_withdraw_sol;
|
|
95
96
|
private withdraw_sol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EscrowAdminUtility.d.ts","sourceRoot":"","sources":["../../../../../src/services/solana/escrow/services/EscrowAdminUtility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAoB,SAAS,EAA0E,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGjL,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qBAAa,kBAAkB;IACpB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC;gBAE3B,OA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yB,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,GAAG,kBAAkB;CAM/H;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -140,7 +140,7 @@ class EscrowAdminUtility {
|
|
|
140
140
|
balances.set(token_pubkey.toBase58(), Number(bal.value.amount));
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
return
|
|
143
|
+
return Array.from(balances.entries());
|
|
144
144
|
}
|
|
145
145
|
catch (error) {
|
|
146
146
|
throw Errors_1.default.decode(error);
|
|
@@ -371,6 +371,7 @@ class EscrowAdminUtility {
|
|
|
371
371
|
}
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
|
+
/** @dev this might fail if the recipient does not have an ATA - take care of it in funding worker task */
|
|
374
375
|
batch_withdraw_spl(mint, recipients, signer) {
|
|
375
376
|
return __awaiter(this, void 0, void 0, function* () {
|
|
376
377
|
const escrowConfigPda = EscrowService.findEscrowConfigPda(this.program.programId);
|
|
@@ -379,9 +380,10 @@ class EscrowAdminUtility {
|
|
|
379
380
|
const amounts = recipients.map(r => new anchor.BN(r.amount_in_lamports));
|
|
380
381
|
const request_ids = recipients.map(r => new anchor.BN(r.request_id));
|
|
381
382
|
const receivers = recipients.map(r => {
|
|
383
|
+
const ata = (0, spl_token_1.getAssociatedTokenAddressSync)(mint, new web3_js_1.PublicKey(r.receiver_pubkey));
|
|
382
384
|
return {
|
|
383
385
|
isSigner: false,
|
|
384
|
-
pubkey:
|
|
386
|
+
pubkey: ata,
|
|
385
387
|
isWritable: true
|
|
386
388
|
};
|
|
387
389
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncRateLimiter.d.ts","sourceRoot":"","sources":["../../src/utils/AsyncRateLimiter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE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D,YAAY;IAS1B,KAAK;;;;CAMR;AAED,wBAAsB,SAAS,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACtB,OAAO,SAAI,EACX,OAAO,SAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAgBZ"}
|
|
@@ -72,9 +72,12 @@ function withRetry(task_1) {
|
|
|
72
72
|
let lastError;
|
|
73
73
|
for (let i = 0; i < retries; i++) {
|
|
74
74
|
try {
|
|
75
|
+
if (i > 0)
|
|
76
|
+
console.log(`Retrying ${i}...`);
|
|
75
77
|
return yield task();
|
|
76
78
|
}
|
|
77
79
|
catch (err) {
|
|
80
|
+
console.error(`Error retying: `, err);
|
|
78
81
|
lastError = err;
|
|
79
82
|
yield new Promise(r => setTimeout(r, delayMs));
|
|
80
83
|
}
|
package/build/utils/custodial.js
CHANGED
|
@@ -177,11 +177,10 @@ const estimate_escrow_method_call_cost = (chain_id, payloads, dbPool, config) =>
|
|
|
177
177
|
if (payloads.length === 0)
|
|
178
178
|
throw new Error(errors.EmptyPayload("estimating Escrow withdrawal cost"));
|
|
179
179
|
const chain_manager = ChainManager_1.default.getInstance(config);
|
|
180
|
-
const escrow_config =
|
|
180
|
+
const escrow_config = chain_manager.getEscrowContractForChain(parseInt(chain_id));
|
|
181
181
|
const provider = ProviderManager_1.default.getInstance(config).getNewProvider(chain_id).provider;
|
|
182
182
|
const Escrow = new ethers_1.ethers.Contract(escrow_config.addresses[0], Escrow_json_1.default, provider);
|
|
183
183
|
const batch_payloads = payloads.map(p => {
|
|
184
|
-
// const target_token = chain_manager.get_payment_token_for_chain("evm", chain_id, p.token);
|
|
185
184
|
return {
|
|
186
185
|
amount: p.amount_in_tokens,
|
|
187
186
|
requestId: p.requestId,
|
|
@@ -201,6 +200,7 @@ const estimate_escrow_method_call_cost = (chain_id, payloads, dbPool, config) =>
|
|
|
201
200
|
chainId: chain_id.toString(),
|
|
202
201
|
value: 0
|
|
203
202
|
};
|
|
203
|
+
console.log(`BATCh WITHDRAW DAT: `, { batch_payloads, data, txDetails });
|
|
204
204
|
// Estimate gas units and get current gas price
|
|
205
205
|
const [gasUnits, gasPrice] = yield Promise.all([
|
|
206
206
|
(0, Utility_1.retryWithExponentialBackoff)(() => __awaiter(void 0, void 0, void 0, function* () { return yield provider.estimateGas(txDetails); })),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ercworldio/blockchain-shared",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Shared library for blockchain projects",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -104,4 +104,4 @@
|
|
|
104
104
|
"ts-node": "^10.9.1",
|
|
105
105
|
"typescript": "^5.0.4"
|
|
106
106
|
}
|
|
107
|
-
}
|
|
107
|
+
}
|