@ercworldio/blockchain-shared 1.0.17 → 1.0.19

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.
@@ -13,7 +13,7 @@
13
13
  "funding_wallet": "0x9Ea8Fb697981Fe83599E3F90b0Bd77E3a3253fE7",
14
14
  "treasury_receiver": "0x3AECA27812d55aF8c787a4277438Ea01B39A73C4",
15
15
  "overflow_treasury_receiver": "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b",
16
- "overflow_threshold_decimal": 250,
16
+ "overflow_threshold_decimal": 0,
17
17
  "min_funding_wallet_balance_usd": 5,
18
18
  "allowed_receivers": [
19
19
  "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b"
@@ -138,7 +138,7 @@
138
138
  "funding_wallet": "0x9Ea8Fb697981Fe83599E3F90b0Bd77E3a3253fE7",
139
139
  "treasury_receiver": "0xaFF5Cf74B7fB6a13D5f3cCf2661953AB188190F3",
140
140
  "overflow_treasury_receiver": "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b",
141
- "overflow_threshold_decimal": 250,
141
+ "overflow_threshold_decimal": 0,
142
142
  "min_funding_wallet_balance_usd": 5,
143
143
  "allowed_receivers": [
144
144
  "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b"
@@ -235,7 +235,7 @@
235
235
  "funding_wallet": "7z5QwV7mg93PU8tBsbdvXscG9bf5VUP2QYHvS2czNisG",
236
236
  "treasury_receiver": "BgXb3Wd36rKaAUiz6KAo8vbQeikveDotWAm2HKFFAmjW",
237
237
  "overflow_treasury_receiver": "B5Syu8RBUWSaSeSF9Ao2TC2dheqbsYBCnaDUSumLQu2m",
238
- "overflow_threshold_decimal": 250,
238
+ "overflow_threshold_decimal": 0,
239
239
  "min_funding_wallet_balance_usd": 5,
240
240
  "allowed_receivers": [
241
241
  "B5Syu8RBUWSaSeSF9Ao2TC2dheqbsYBCnaDUSumLQu2m"
@@ -353,7 +353,7 @@
353
353
  "funding_wallet": "0x9Ea8Fb697981Fe83599E3F90b0Bd77E3a3253fE7",
354
354
  "treasury_receiver": "0x2f2982B94c0F0c325A586a32Ffd66acF7b7Ca1d8",
355
355
  "overflow_treasury_receiver": "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b",
356
- "overflow_threshold_decimal": 250,
356
+ "overflow_threshold_decimal": 0,
357
357
  "min_funding_wallet_balance_usd": 5,
358
358
  "allowed_receivers": [
359
359
  "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b"
@@ -450,7 +450,7 @@
450
450
  "funding_wallet": "0x9Ea8Fb697981Fe83599E3F90b0Bd77E3a3253fE7",
451
451
  "treasury_receiver": "0x494E3bBCe1668Cb8F388a96F6852e4CA375F2AD3",
452
452
  "overflow_treasury_receiver": "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b",
453
- "overflow_threshold_decimal": 250,
453
+ "overflow_threshold_decimal": 0,
454
454
  "min_funding_wallet_balance_usd": 5,
455
455
  "allowed_receivers": [
456
456
  "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b"
@@ -533,7 +533,7 @@
533
533
  "funding_wallet": "0x9Ea8Fb697981Fe83599E3F90b0Bd77E3a3253fE7",
534
534
  "treasury_receiver": "0x52B74AEF04b563f4Df5998DD854FcF477E385b4A",
535
535
  "overflow_treasury_receiver": "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b",
536
- "overflow_threshold_decimal": 250,
536
+ "overflow_threshold_decimal": 0,
537
537
  "min_funding_wallet_balance_usd": 5,
538
538
  "allowed_receivers": [
539
539
  "0xfBaD7977d5eD2E6eAa69d28549A2FFCa6065eA6b"
@@ -631,11 +631,11 @@
631
631
  "accounting": {
632
632
  "funding_wallet": "TBLeFCWoBrwgbvj33F41t8FErhkgbm3276",
633
633
  "treasury_receiver": "TBLeFCWoBrwgbvj33F41t8FErhkgbm3276",
634
- "overflow_treasury_receiver": "TJetV4XspjvQ3adfQV8RExniL7NAJukF2p",
635
- "overflow_threshold_decimal": 250,
634
+ "overflow_treasury_receiver": "TBQWyo8rNj9cFjgNbYav3EJEXfs7o1dp2o",
635
+ "overflow_threshold_decimal": 0,
636
636
  "min_funding_wallet_balance_usd": 5,
637
637
  "allowed_receivers": [
638
- "TJetV4XspjvQ3adfQV8RExniL7NAJukF2p"
638
+ "TBQWyo8rNj9cFjgNbYav3EJEXfs7o1dp2o"
639
639
  ]
640
640
  },
641
641
  "rpcMetadata": {
@@ -18,12 +18,14 @@ export interface FetchPriceData {
18
18
  declare class AccountingService extends BaseErrors {
19
19
  private dbPool;
20
20
  private config;
21
+ private logger;
21
22
  constructor(dbPool: IDatabasePool, config: IConfig);
22
23
  deposit_address_exists_by_user: (user_id: number, address: string, blockchain: BlockchainType) => Promise<boolean>;
23
24
  get_crypto_withdrawal_request: (request_id: number) => Promise<WithdrawRequestDetails | null>;
24
25
  get_crypto_rate: (chain_id: ChainId) => Promise<number>;
25
26
  private fetch_crypto_rate_task;
26
27
  convert_amount_to_currency: (amount_in_source: number, source_currency: string, destination_currency: string) => Promise<number>;
28
+ private validate_currency_code;
27
29
  private convert_currency_pair_task;
28
30
  find_withdrawal_by_hash: (tx_hash: string, request_id: number) => Promise<any>;
29
31
  find_withdrawals_batch: (lookups: WithdrawalLookup[]) => Promise<any>;
@@ -1 +1 @@
1
- {"version":3,"file":"AccountingService.d.ts","sourceRoot":"","sources":["../../src/services/AccountingService.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAA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AAE,YAAY,MAAM,kBAe1E;IAEM,sBAAsB,GACzB,SAAS,gBAAgB,EAAE,kBA8B7B;IAEK,4BAA4B,GAAU,QAAO,MAAY,kBAmB/D;IAqDM,qCAAqC,GAAU,QAAO,MAAY,EAAE,kBAAiB,MAAU,kBA4DrG;CACJ;AAED,eAAe,iBAAiB,CAAC"}
@@ -16,6 +16,9 @@ const errors_1 = __importDefault(require("../errors/errors"));
16
16
  const Wallets_1 = require("../utils/Wallets");
17
17
  const ChainManager_1 = __importDefault(require("./ChainManager"));
18
18
  const AsyncTTLCache_1 = __importDefault(require("../utils/AsyncTTLCache"));
19
+ const Logger_1 = require("../utils/Logger");
20
+ // Currency tickers are short alphanumeric codes (EUR, USD, USDT, ...); anything else is rejected before it reaches the DB.
21
+ const CURRENCY_CODE_PATTERN = /^[A-Z0-9]{2,10}$/;
19
22
  class AccountingService extends errors_1.default {
20
23
  constructor(dbPool, config) {
21
24
  super();
@@ -63,20 +66,45 @@ class AccountingService extends errors_1.default {
63
66
  return Number(result[0].fn_get_crypto_rate);
64
67
  });
65
68
  this.convert_amount_to_currency = (amount_in_source, source_currency, destination_currency) => __awaiter(this, void 0, void 0, function* () {
69
+ const source = this.validate_currency_code(source_currency, "source_currency");
70
+ const destination = this.validate_currency_code(destination_currency, "destination_currency");
71
+ if (typeof amount_in_source !== "number" || !Number.isFinite(amount_in_source)) {
72
+ this.logger.warn(`Rejected currency conversion: invalid amount`, { data: { amount_in_source: String(amount_in_source).slice(0, 200), source, destination } });
73
+ throw new Error(`Invalid amount for currency conversion`);
74
+ }
66
75
  // const unit_rate = await PriceCache.getInstance().get_rate(source_currency, destination_currency, this.convert_currency_pair_task);
67
- const key = `${source_currency.toUpperCase()}/${destination_currency.toUpperCase()}`;
68
- const unit_rate = yield AsyncTTLCache_1.default.getInstance().get_value(key, { amount_in_source, source_currency, destination_currency }, this.convert_currency_pair_task);
76
+ const key = `${source}/${destination}`;
77
+ const unit_rate = yield AsyncTTLCache_1.default.getInstance().get_value(key, { amount_in_source, source_currency: source, destination_currency: destination }, this.convert_currency_pair_task);
69
78
  return unit_rate * amount_in_source;
70
79
  });
80
+ this.validate_currency_code = (value, field) => {
81
+ const code = typeof value === "string" ? value.trim().toUpperCase() : "";
82
+ if (!CURRENCY_CODE_PATTERN.test(code)) {
83
+ // Warn goes to Elastic: an unexpected value here is either a client bug or an injection attempt.
84
+ this.logger.warn(`Rejected currency conversion: invalid ${field}`, { data: { field, value: String(value).slice(0, 200) } });
85
+ throw new Error(`Invalid ${field}`);
86
+ }
87
+ return code;
88
+ };
71
89
  this.convert_currency_pair_task = (data) => __awaiter(this, void 0, void 0, function* () {
72
90
  if (!this.dbPool.customerAppDataSource)
73
91
  throw new Error(this.NotInitializedDatabase());
74
92
  const { amount_in_source, source_currency, destination_currency } = data;
75
- const result = yield this.dbPool.customerAppDataSource.query(`
76
- SELECT accounting.fn_convert_amount_to_currency(${amount_in_source}, '${source_currency.toUpperCase()}'::text, '${destination_currency.toUpperCase()}'::text)
77
- `);
78
- if (result[0].fn_convert_amount_to_currency === null)
93
+ this.logger.info(`Fetching currency conversion from DB`, { data: { amount_in_source, source_currency, destination_currency } });
94
+ let result;
95
+ try {
96
+ result = yield this.dbPool.customerAppDataSource.query(`
97
+ SELECT accounting.fn_convert_amount_to_currency($1::numeric, $2::text, $3::text)
98
+ `, [amount_in_source, source_currency, destination_currency]);
99
+ }
100
+ catch (error) {
101
+ this.logger.error(`Currency conversion query failed`, { data: { error, amount_in_source, source_currency, destination_currency } });
102
+ throw error;
103
+ }
104
+ if (!result.length || result[0].fn_convert_amount_to_currency === null) {
105
+ this.logger.warn(`No conversion rate returned`, { data: { source_currency, destination_currency } });
79
106
  throw new Error(`Failed to get crypto rate for pair ${source_currency}/${destination_currency}`);
107
+ }
80
108
  return Number(result[0].fn_convert_amount_to_currency);
81
109
  });
82
110
  this.find_withdrawal_by_hash = (tx_hash, request_id) => __awaiter(this, void 0, void 0, function* () {
@@ -234,6 +262,7 @@ class AccountingService extends errors_1.default {
234
262
  });
235
263
  this.dbPool = dbPool;
236
264
  this.config = config;
265
+ this.logger = (0, Logger_1.createLogger)(`AccountingService`, this.config.pipelineConfig.azureAppName);
237
266
  }
238
267
  }
239
268
  exports.default = AccountingService;
@@ -1 +1 @@
1
- {"version":3,"file":"BalanceService.d.ts","sourceRoot":"","sources":["../../src/services/BalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAgB,OAAO,EAAgB,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACjH,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAOjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAI1C,KAAK,aAAa,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEtC,UAAU,sBAAsB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,cAAM,cAAe,SAAQ,UAAU;IACnC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO;IASlD;;;OAGG;YACW,iBAAiB;IA6CzB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAgCvH,2BAA2B,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM;IAsB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B,CAAC,MAAM,EAAE,YAAY,EAAE;IA0EjD,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa;;;;IA2FpK,qBAAqB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,GAAE,OAAe;IAmE3H,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc;IAUlD,uBAAuB;IAuBvB,kBAAkB,CAAC,KAAK,GAAE,MAAY;YAOrC,gBAAgB;IAoBxB,yBAAyB,CAAC,mBAAmB,EAAE,WAAW,EAAE;IAY5D,6BAA6B,CAAC,mBAAmB,EAAE,cAAc,EAAE;CAgE5E;AAED,eAAe,cAAc,CAAC"}
@@ -175,6 +175,7 @@ class BalanceService extends errors_1.default {
175
175
  throw new Error(`No payment tokens found for blockchain ${blockchain}`);
176
176
  }
177
177
  // Execute batch insert
178
+ // TODO: Fix
178
179
  const query = `
179
180
  INSERT INTO usersmanagement.deposit_wallet_balance
180
181
  (wallet_id, blockchain, chain_id, token, decimals, balance, transaction_count, created_at, updated_at)
@@ -542,6 +543,7 @@ class BalanceService extends errors_1.default {
542
543
  this.logger.info(`Successfully updated ${successfulTransfers.length} wallet balances`);
543
544
  });
544
545
  }
546
+ // TODO: Fix
545
547
  reflectUpdateInWalletBalances(successfulTransfers) {
546
548
  return __awaiter(this, void 0, void 0, function* () {
547
549
  if (successfulTransfers.length === 0) {
@@ -554,6 +556,7 @@ class BalanceService extends errors_1.default {
554
556
  }
555
557
  // First, get all the wallet IDs for the addresses that were swept
556
558
  const addressConditions = successfulTransfers.map(transfer => `(address = '${transfer.address}' AND blockchain = '${transfer.blockchain}')`).join(' OR ');
559
+ // TODO: Fix
557
560
  const walletQuery = `
558
561
  SELECT id as wallet_id, address, blockchain
559
562
  FROM usersmanagement.deposit_addresses
@@ -566,6 +569,7 @@ class BalanceService extends errors_1.default {
566
569
  }
567
570
  // Create a map of address to wallet_id for easy lookup
568
571
  const addressToWalletId = new Map(walletResults.map((result) => [`${result.address}-${result.blockchain}`, result.wallet_id]));
572
+ // TODO: Fix
569
573
  // Build the VALUES clause for bulk update using the looked up wallet IDs
570
574
  const updateValues = successfulTransfers.flatMap(transfer => {
571
575
  const walletId = addressToWalletId.get(`${transfer.address}-${transfer.blockchain}`);
@@ -1 +1 @@
1
- {"version":3,"file":"ClaimJobService.d.ts","sourceRoot":"","sources":["../../src/services/ClaimJobService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,SAAS,EAA0B,MAAM,eAAe,CAAC;AAElE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAKlK,cAAM,gBAAgB;IAClB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;gBAGV,MAAM,EAAE,aAAa;IAMjC,OAAO,CAAC,QAAQ,CAIf;IAED,OAAO,CAAC,gBAAgB,CAIvB;IAED,OAAO,CAAC,QAAQ,CAsBf;IAEM,yCAAyC,GAAU,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,kBAAiB,MAAU,EAAE,gBAAe,oBAAoF,KAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAOvQ;IAEM,8BAA8B,GAAU,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,kBAAiB,M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AC,CAW/H;IAEM,iBAAiB,GAAU,aAAa,MAAM,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAQrE;IAEK,gBAAgB,GAAU,YAAY,MAAM,6CAGlD;IAED,OAAO,CAAC,YAAY,CAenB;CAEJ;AAED,eAAe,gBAAgB,CAAC"}
@@ -491,6 +491,7 @@ class ClaimJobsService {
491
491
  const repo = this.get_repo();
492
492
  return repo.count({ where: { blockchain: blockchain, chain_id: chain_id } });
493
493
  });
494
+ // TODO: Fix
494
495
  this.get_next_queued_jobs = (blockchain_1, chain_id_1, ...args_1) => __awaiter(this, [blockchain_1, chain_id_1, ...args_1], void 0, function* (blockchain, chain_id, limit = 10) {
495
496
  if (limit <= 0)
496
497
  return [];
@@ -1 +1 @@
1
- {"version":3,"file":"SweepJobService.d.ts","sourceRoot":"","sources":["../../src/services/SweepJobService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI/E,cAAM,eAAe;IACjB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO;IAMlD,OAAO,CAAC,OAAO;IAOT,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,E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ACvB,QAAQ,cAAc,EACtB,YAAY,cAAc,EAC1B,OAAO,MAAM,EACb,YAAY,MAAM,KACnB,OAAO,CAAC,QAAQ,EAAE,CAAC,CA4DpB;IAyCK,6BAA6B,GAAU,SAAS,MAAM,EAAE,EAAE,iBAAiB,cAAc,mBAmB/F;IAEM,wBAAwB,GAC3B,aAAa,MAAM,EAAE,EACrB,YAAY,cAAc,EAC1B,gBAAgB,MAAM,EACtB,YAAY,OAAO,KACpB,OAAO,CAAC,IAAI,CAAC,CAcd;IAGK,mCAAmC,GACtC,MAAM,QAAQ,EAAE,EAChB,WAAW,OAAO,KACnB,OAAO,CAAC,IAAI,CAAC,CAsBf;IAEM,uBAAuB,GAAU,MAAM,WAAW,EAAE,EAAE,iBAAiB,cAAc,mBA2B3F;IAEM,iBAAiB,GAAU,SAAS,MAAM,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAQjE;IAEI,iCAAiC,CACnC,UAAU,EAAE,cAAc,EAC1B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAU,GACzB,OAAO,CAAC,QAAQ,EAAE,CAAC;CA2BzB;AAED,eAAe,eAAe,CAAC"}
@@ -602,6 +602,7 @@ WHERE job_status IN ('pending', 'queued');
602
602
  if (!dataSource) {
603
603
  throw new Error(`Database connection is not initialized.`);
604
604
  }
605
+ // TODO: Fix
605
606
  const query = `
606
607
  INSERT INTO usersmanagement.sweep_jobs
607
608
  (blockchain, chain_id, user_id, address, parent_index, child_index, token, decimals, balance, created_at, updated_at)
@@ -20,7 +20,7 @@ declare class WalletManager extends BaseErrors {
20
20
  static getInstance(config: IConfig, dbPool: IDatabasePool): WalletManager;
21
21
  getWallet: (userId: number, blockchain: BlockchainType) => Promise<IWallet | null>;
22
22
  getEscrowFundsManagerWallet: (blockchain: BlockchainType) => ethers.Wallet | Keypair | TronNodeWallet;
23
- fund_wallets_evm: (chainId: ChainId, wallets: string[], estimation_type: TransactionType) => Promise<string>;
23
+ fund_wallets_evm: (chainId: ChainId, wallets: string[], estimation_type: TransactionType, amount?: bigint) => Promise<string>;
24
24
  private get_wallet_service_mnemonic;
25
25
  createWallet: (userId: number, blockchain: BlockchainType, expiry_duration_s: number) => Promise<IWallet>;
26
26
  isAddressExpired(blockchain: BlockchainType, address: string): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"WalletManager.d.ts","sourceRoot":"","sources":["../../src/services/WalletManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoC,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAM1C,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAIxD,OAAO,EAAe,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAe,OAAO,EAAgB,cAAc,EAAc,MAAM,wBAAwB,CAAC;AACnH,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAO5D,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAG1C,OAAO,gBAA+B,MAAM,2BAA2B,CAAC;AAGxE,cAAM,aAAc,SAAQ,UAAU;IAClC,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAgB;IACvB,wBAAwB,EAAE,MAAM,CAAC;IACjC,8BAA8B,EAAE,MAAM,CAAC;IACvC,0BAA0B,EAAE,MAAM,CAAC;IAC1C,OAAO,CAAC,MAAM,CAAS;gBACX,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa;IAelD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa;IAOlD,SAAS,GAAU,QA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Y,GAAU,QAAQ,MAAM,EAAE,YAAY,cAAc;;;OAGtE;IAGM,WAAW,GAAU,cAAc,yBAAyB,EAAE,QAAQ,MAAM,EAAE,YAAY,cAAc,EAAE,iBAAiB,MAAM,EAAE,mBAAmB,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC,CA8BrL;IAEM,oBAAoB,GAAU,cAAc,yBAAyB,EAAE,YAAY,cAAc,EAAE,YAAY,OAAO,EAAE,YAAY,OAAO,EAAE,SAAS,gBAAgB,sBA8B5K;IAGM,iBAAiB,GAAU,YAAY,OAAO,EAAE,YAAY,OAAO,sBAezE;IAIM,YAAY,GAAI,aAAa,MAAM,EAAE,YAAY,MAAM,EAAE,YAAY,cAAc,EAAE,YAAY,MAAM,eA4E7G;CAIJ;AAED,eAAe,aAAa,CAAC"}
@@ -133,7 +133,8 @@ class WalletManager extends errors_1.default {
133
133
  }
134
134
  ;
135
135
  };
136
- this.fund_wallets_evm = (chainId, wallets, estimation_type) => __awaiter(this, void 0, void 0, function* () {
136
+ /// @param amount per-wallet funding amount. When omitted, funds the estimated cost of `estimation_type`
137
+ this.fund_wallets_evm = (chainId, wallets, estimation_type, amount) => __awaiter(this, void 0, void 0, function* () {
137
138
  const providerManager = ProviderManager_1.default.getInstance(this.config);
138
139
  const provider = providerManager.getNewProvider(chainId).provider;
139
140
  const funds_manager = this.getEscrowFundsManagerWallet("evm").connect(provider);
@@ -141,7 +142,7 @@ class WalletManager extends errors_1.default {
141
142
  const gas_cost = yield (0, custodial_1.estimateGas)(provider, ethers_1.ethers.ZeroAddress, null, (0, ethers_1.parseEther)("0.000001"), funds_manager.address, parseInt(chainId), estimation_type);
142
143
  if (balance <= gas_cost)
143
144
  throw new Error(`Insufficient funds in funds manager wallet. Please transfer ether tokens to the address ${funds_manager.address}`);
144
- const funding_amount = gas_cost;
145
+ const funding_amount = amount !== null && amount !== void 0 ? amount : gas_cost;
145
146
  const chain_manager = ChainManager_1.default.getInstance(this.config);
146
147
  const escrow_config = yield chain_manager.getEscrowContractForChain(parseInt(chainId));
147
148
  let connected_funds_manager = funds_manager.connect(provider);
@@ -22,10 +22,18 @@ export interface EstimateEscrowExecuteWithdrawalPayload {
22
22
  receiverAddress: string;
23
23
  executeAt: number;
24
24
  }
25
+ export declare const APPROVAL_FUNDING_BUFFER_PERCENT = 20;
26
+ export declare const approval_funding_amount: (gas_estimate: bigint, current_balance: bigint) => bigint;
25
27
  export declare const needs_approval_and_funding: (blockchain: BlockchainType, chainId: ChainId, token: string, parentIndex: number, childIndex: number, spender: string, dbPool: IDatabasePool, config: IConfig) => Promise<{
26
28
  status: boolean;
27
29
  needs_approval: boolean;
28
30
  needs_funding: boolean;
31
+ funding_amount?: undefined;
32
+ } | {
33
+ status: boolean;
34
+ needs_approval: boolean;
35
+ needs_funding: boolean;
36
+ funding_amount: bigint;
29
37
  }>;
30
38
  export declare const approve_if_not_approved: (blockchain: BlockchainType, chainId: ChainId, parentIndex: number, childIndex: number, spender: string, token: string, dbPool: IDatabasePool, config: IConfig) => Promise<{
31
39
  status: boolean;
@@ -37,5 +45,20 @@ export declare const getWalletBalance: (blockchain: BlockchainType, chainId: Cha
37
45
  }>;
38
46
  export declare const estimate_execute_withdrawal: (chain_id: ChainId, payload: EstimateEscrowExecuteWithdrawalPayload, caller: string, config: IConfig) => Promise<bigint>;
39
47
  export declare const estimate_escrow_method_call_cost: (chain_id: ChainId, payloads: EstimateEscrowBatchWithdrawPayload[], dbPool: IDatabasePool, config: IConfig) => Promise<bigint>;
48
+ export interface EvmFeeOverrides {
49
+ gasPrice?: bigint;
50
+ maxFeePerGas?: bigint;
51
+ maxPriorityFeePerGas?: bigint | null;
52
+ }
53
+ export interface EvmGasEstimate {
54
+ gasLimit: bigint;
55
+ fees: EvmFeeOverrides;
56
+ totalFee: bigint;
57
+ }
58
+ export declare const resolveFeeOverrides: (feeData: ethers.FeeData) => {
59
+ fees: EvmFeeOverrides;
60
+ perGas: bigint;
61
+ };
40
62
  export declare const estimateGas: (provider: ethers.Provider, tokenAddress: string, spenderAddress: string | null, amount: bigint, fromAddress: string, chainId: number, transactionType: TransactionType, isMockTransfer?: boolean) => Promise<bigint>;
63
+ export declare const estimateGasWithFees: (provider: ethers.Provider, tokenAddress: string, spenderAddress: string | null, amount: bigint, fromAddress: string, chainId: number, transactionType: TransactionType, isMockTransfer?: boolean) => Promise<EvmGasEstimate>;
41
64
  //# sourceMappingURL=custodial.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"custodial.d.ts","sourceRoot":"","sources":["../../src/utils/custodial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,MAAM,EAAwC,MAAM,QAAQ,CAAC;AAC7G,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAYnF,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAMvD,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,SAAS,GAAG,cAAc,CAAC;AACpE,MAAM,WAAW,iBAAiB;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,OAAO,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,kCAAkC;IAC/C,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,sCAAsC;IACnD,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,0BAA0B,GAAU,YAAY,cAAc,EAAE,SAAS,OAAO,EAAE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AAA;AAGD,eAAO,MAAM,2BAA2B,GAAU,UAAU,OAAO,EAAE,SAAS,sCAAsC,EAAE,QAAQ,MAAM,EAAE,QAAQ,OAAO,oBAwBpJ,CAAA;AAED,eAAO,MAAM,gCAAgC,GAAU,UAAU,OAAO,EAAE,UAAU,kCAAkC,EAAE,EAAE,QAAQ,aAAa,EAAE,QAAQ,OAAO,oBAoE/J,CAAA;AAED,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,eAAe,CAAC;IAEtB,QAAQ,EAAE,MAAM,CAAC;CACpB;AAKD,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,CAAC,OAAO,KAAG;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CASpG,CAAA;AAED,eAAO,MAAM,WAAW,GACpB,UAAU,MAAM,CAAC,QAAQ,EACzB,cAAc,MAAM,EACpB,gBAAgB,MAAM,GAAG,IAAI,EAC7B,QAAQ,MAAM,EACd,aAAa,MAAM,EACnB,SAAS,MAAM,EACf,iBAAiB,eAAe,EAChC,wBAAsB,oBAIzB,CAAA;AAID,eAAO,MAAM,mBAAmB,GAC5B,UAAU,MAAM,CAAC,QAAQ,EACzB,cAAc,MAAM,EACpB,gBAAgB,MAAM,GAAG,IAAI,EAC7B,QAAQ,MAAM,EACd,aAAa,MAAM,EACnB,SAAS,MAAM,EACf,iBAAiB,eAAe,EAChC,wBAAsB,KACvB,OAAO,CAAC,cAAc,CA6DxB,CAAA"}
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.estimateGas = exports.estimate_escrow_method_call_cost = exports.estimate_execute_withdrawal = exports.getWalletBalance = exports.approve_if_not_approved = exports.needs_approval_and_funding = void 0;
15
+ exports.estimateGasWithFees = exports.estimateGas = exports.resolveFeeOverrides = exports.estimate_escrow_method_call_cost = exports.estimate_execute_withdrawal = exports.getWalletBalance = exports.approve_if_not_approved = exports.needs_approval_and_funding = exports.approval_funding_amount = exports.APPROVAL_FUNDING_BUFFER_PERCENT = void 0;
16
16
  const ethers_1 = require("ethers");
17
17
  const ERC20Mock_json_1 = __importDefault(require("../contracts/artifacts/ERC20Mock.json"));
18
18
  const Escrow_json_1 = __importDefault(require("../contracts/artifacts/Escrow.json"));
@@ -25,6 +25,14 @@ const spl_token_1 = require("@solana/spl-token");
25
25
  const TransactionsErrors_1 = __importDefault(require("../errors/TransactionsErrors"));
26
26
  const ChainManager_1 = __importDefault(require("../services/ChainManager"));
27
27
  const TronHelper_1 = __importDefault(require("../services/tron/services/TronHelper"));
28
+ /// Headroom on top of the approval estimate, to absorb baseFee rising between funding and approving
29
+ exports.APPROVAL_FUNDING_BUFFER_PERCENT = 20;
30
+ /// Native amount to send so the wallet covers the approval estimate plus buffer
31
+ const approval_funding_amount = (gas_estimate, current_balance) => {
32
+ const target = gas_estimate * BigInt(100 + exports.APPROVAL_FUNDING_BUFFER_PERCENT) / BigInt(100);
33
+ return target > current_balance ? target - current_balance : BigInt(0);
34
+ };
35
+ exports.approval_funding_amount = approval_funding_amount;
28
36
  const needs_approval_and_funding = (blockchain, chainId, token, parentIndex, childIndex, spender, dbPool, config) => __awaiter(void 0, void 0, void 0, function* () {
29
37
  const walletManager = WalletManager_1.default.getInstance(config, dbPool);
30
38
  const wallet = walletManager.deriveWallet(parentIndex, childIndex, blockchain);
@@ -45,11 +53,11 @@ const needs_approval_and_funding = (blockchain, chainId, token, parentIndex, chi
45
53
  const ethers_balance = yield provider.getBalance(signer.address);
46
54
  const gas_estimate = yield (0, exports.estimateGas)(provider, token, spender, ethers_1.ethers.MaxUint256, wallet.address, parseInt(chainId), "approve");
47
55
  if (gas_estimate > ethers_balance) {
48
- return { status: true, needs_approval: true, needs_funding: true };
56
+ return { status: true, needs_approval: true, needs_funding: true, funding_amount: (0, exports.approval_funding_amount)(gas_estimate, ethers_balance) };
49
57
  }
50
- return { status: true, needs_approval: true, needs_funding: false };
58
+ return { status: true, needs_approval: true, needs_funding: false, funding_amount: BigInt(0) };
51
59
  }
52
- return { status: true, needs_approval: false, needs_funding: false };
60
+ return { status: true, needs_approval: false, needs_funding: false, funding_amount: BigInt(0) };
53
61
  }
54
62
  catch (error) {
55
63
  throw error;
@@ -76,11 +84,13 @@ const approve_if_not_approved = (blockchain, chainId, parentIndex, childIndex, s
76
84
  if (allowance === BigInt(0)) {
77
85
  const ethers_balance = yield provider.getBalance(signer.address);
78
86
  // const gas_estimate = await retryWithExponentialBackoff(() => estimateApprovalGas(provider, token, spender, balance, signer.address, parseInt(chainId)));
79
- const gas_estimate = yield (0, exports.estimateGas)(provider, token, spender, ethers_1.ethers.MaxUint256, wallet.address, parseInt(chainId), "approve");
80
- if (gas_estimate > ethers_balance) {
81
- // await walletManager.fund_wallets_evm(blockchain, chainId, signer.address, "native");
87
+ const gas_estimate = yield (0, exports.estimateGasWithFees)(provider, token, spender, ethers_1.ethers.MaxUint256, wallet.address, parseInt(chainId), "approve");
88
+ // Fail before sending; the next allowance check will flag the wallet for funding
89
+ if (gas_estimate.totalFee > ethers_balance) {
90
+ throw new Error(`Insufficient native balance for approval: have ${ethers_balance} want ${gas_estimate.totalFee}`);
82
91
  }
83
- const approveTx = yield tokenContract.approve(spender, ethers_1.ethers.MaxUint256);
92
+ // Send with the exact gas limit and fees that were estimated, so ethers doesn't re-price it
93
+ const approveTx = yield tokenContract.approve(spender, ethers_1.ethers.MaxUint256, Object.assign({ gasLimit: gas_estimate.gasLimit }, gas_estimate.fees));
84
94
  yield approveTx.wait();
85
95
  }
86
96
  return { status: true, balance: balance };
@@ -263,7 +273,28 @@ const estimate_escrow_method_call_cost = (chain_id, payloads, dbPool, config) =>
263
273
  return totalFee;
264
274
  });
265
275
  exports.estimate_escrow_method_call_cost = estimate_escrow_method_call_cost;
276
+ /// On EIP-1559 chains the node checks the sender balance against gasLimit * maxFeePerGas,
277
+ /// not gasLimit * gasPrice (maxFeePerGas defaults to ~2x baseFee + tip in ethers v6).
278
+ /// Fall back to legacy gasPrice only when the chain has no maxFeePerGas.
279
+ const resolveFeeOverrides = (feeData) => {
280
+ if (feeData.maxFeePerGas) {
281
+ return {
282
+ fees: { maxFeePerGas: feeData.maxFeePerGas, maxPriorityFeePerGas: feeData.maxPriorityFeePerGas },
283
+ perGas: feeData.maxFeePerGas
284
+ };
285
+ }
286
+ const gasPrice = feeData.gasPrice || BigInt(0);
287
+ return { fees: { gasPrice }, perGas: gasPrice };
288
+ };
289
+ exports.resolveFeeOverrides = resolveFeeOverrides;
266
290
  const estimateGas = (provider_1, tokenAddress_1, spenderAddress_1, amount_1, fromAddress_1, chainId_1, transactionType_1, ...args_1) => __awaiter(void 0, [provider_1, tokenAddress_1, spenderAddress_1, amount_1, fromAddress_1, chainId_1, transactionType_1, ...args_1], void 0, function* (provider, tokenAddress, spenderAddress, amount, fromAddress, chainId, transactionType, isMockTransfer = false) {
291
+ const estimate = yield (0, exports.estimateGasWithFees)(provider, tokenAddress, spenderAddress, amount, fromAddress, chainId, transactionType, isMockTransfer);
292
+ return estimate.totalFee;
293
+ });
294
+ exports.estimateGas = estimateGas;
295
+ /// Same as estimateGas, but also returns the gas limit and fee fields so the caller can
296
+ /// send the tx with exactly what was estimated (and funded for)
297
+ const estimateGasWithFees = (provider_1, tokenAddress_1, spenderAddress_1, amount_1, fromAddress_1, chainId_1, transactionType_1, ...args_1) => __awaiter(void 0, [provider_1, tokenAddress_1, spenderAddress_1, amount_1, fromAddress_1, chainId_1, transactionType_1, ...args_1], void 0, function* (provider, tokenAddress, spenderAddress, amount, fromAddress, chainId, transactionType, isMockTransfer = false) {
267
298
  let data = undefined;
268
299
  let value = BigInt(0);
269
300
  switch (transactionType) {
@@ -313,17 +344,15 @@ const estimateGas = (provider_1, tokenAddress_1, spenderAddress_1, amount_1, fro
313
344
  value: value
314
345
  };
315
346
  // Estimate gas units and get current gas price
316
- const [gasUnits, gasPrice] = yield Promise.all([
347
+ const [gasUnits, feeData] = yield Promise.all([
317
348
  (0, Utility_1.retryWithExponentialBackoff)(() => __awaiter(void 0, void 0, void 0, function* () { return yield provider.estimateGas(txDetails); })),
318
349
  (0, Utility_1.retryWithExponentialBackoff)(() => __awaiter(void 0, void 0, void 0, function* () { return yield provider.getFeeData(); }))
319
350
  ]);
320
351
  // Calculate total gas cost in native token
321
- const totalFee = gasPrice.gasPrice
322
- ? gasPrice.gasPrice * gasUnits
323
- : (gasPrice.maxFeePerGas || BigInt(0)) * gasUnits;
324
- return totalFee;
352
+ const { fees, perGas } = (0, exports.resolveFeeOverrides)(feeData);
353
+ return { gasLimit: gasUnits, fees, totalFee: perGas * gasUnits };
325
354
  });
326
- exports.estimateGas = estimateGas;
355
+ exports.estimateGasWithFees = estimateGasWithFees;
327
356
  const estimateApprovalGas = (provider, tokenAddress, spenderAddress, amount, fromAddress, chainId) => __awaiter(void 0, void 0, void 0, function* () {
328
357
  // Create contract interface
329
358
  const tokenContract = new ethers_1.ethers.Contract(tokenAddress, ERC20Mock_json_1.default, provider);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ercworldio/blockchain-shared",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "Shared library for blockchain projects",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -107,4 +107,4 @@
107
107
  "ts-node": "^10.9.1",
108
108
  "typescript": "^5.0.4"
109
109
  }
110
- }
110
+ }