@render-foundation/utils 0.0.169 → 0.0.171

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.
@@ -19,7 +19,7 @@ const solscanProClient = (apiKey) => {
19
19
  const headers = {
20
20
  token: apiKey,
21
21
  };
22
- const baseUrl = "https://pro-api.solscan.io/v2.0";
22
+ const baseUrl = 'https://pro-api.solscan.io/v2.0';
23
23
  return {
24
24
  getSignaturesForAddress(addr, options) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
@@ -32,7 +32,7 @@ const solscanProClient = (apiKey) => {
32
32
  limit: limit.toString(),
33
33
  });
34
34
  if (before) {
35
- params.append("before", before);
35
+ params.append('before', before);
36
36
  }
37
37
  const endpoint = `${baseUrl}/account/transactions?${params}`;
38
38
  const response = yield fetch(endpoint, { headers });
@@ -44,15 +44,18 @@ const solscanProClient = (apiKey) => {
44
44
  const transformedSigs = signatures.map((tx) => ({
45
45
  signature: tx.txHash || tx.signature,
46
46
  blockTime: tx.blockTime || tx.block_time || 0,
47
- err: tx.status !== "Success" ? { err: tx.status } : null,
47
+ err: tx.status !== 'Success' ? { err: tx.status } : null,
48
48
  }));
49
49
  allSignatures.push(...transformedSigs);
50
- if (signatures.length < limit || ((options === null || options === void 0 ? void 0 : options.limit) && allSignatures.length >= options.limit)) {
50
+ if (signatures.length < limit ||
51
+ ((options === null || options === void 0 ? void 0 : options.limit) && allSignatures.length >= options.limit)) {
51
52
  break;
52
53
  }
53
54
  // Set before to the last signature for next page
54
55
  if (signatures.length > 0) {
55
- before = signatures[signatures.length - 1].txHash || signatures[signatures.length - 1].signature;
56
+ before =
57
+ signatures[signatures.length - 1].txHash ||
58
+ signatures[signatures.length - 1].signature;
56
59
  }
57
60
  }
58
61
  return allSignatures.slice(0, options === null || options === void 0 ? void 0 : options.limit);
@@ -68,14 +71,14 @@ const solscanProClient = (apiKey) => {
68
71
  const data = yield response.json();
69
72
  return {
70
73
  meta: {
71
- err: data.status !== "Success" ? { err: data.status } : null,
74
+ err: data.status !== 'Success' ? { err: data.status } : null,
72
75
  logMessages: data.logMessages || [],
73
76
  preTokenBalances: data.inputAccount || [],
74
77
  postTokenBalances: data.outputAccount || [],
75
78
  },
76
79
  blockTime: data.blockTime || data.block_time || 0,
77
80
  status: data.status,
78
- err: data.status !== "Success" ? { err: data.status } : null,
81
+ err: data.status !== 'Success' ? { err: data.status } : null,
79
82
  tokenBalances: data.tokenBalances || [],
80
83
  preTokenBalances: data.inputAccount || [],
81
84
  postTokenBalances: data.outputAccount || [],
@@ -96,24 +99,30 @@ const solscanProClient = (apiKey) => {
96
99
  page_size: pageSize.toString(),
97
100
  });
98
101
  if (f.mint) {
99
- params.append("token", f.mint.toString());
102
+ params.append('token', f.mint.toString());
100
103
  }
101
104
  if (f.flow) {
102
- params.append("flow", f.flow);
105
+ params.append('flow', f.flow);
103
106
  }
104
107
  if (f.tokenAccount) {
105
- params.append("token_account", f.tokenAccount.toString());
108
+ params.append('token_account', f.tokenAccount.toString());
106
109
  }
107
110
  const endpoint = `${baseUrl}/account/balance_change?${params}`;
108
111
  const response = yield fetch(endpoint, { headers });
112
+ if (f.tokenAccount.toString() === constants_1.polyBridgeEscrow) {
113
+ console.log('Poly solscan response: ', JSON.stringify(response));
114
+ }
109
115
  if (!response.ok) {
110
116
  console.error(`Failed to fetch balance changes: ${response.statusText}`);
111
117
  break;
112
118
  }
113
119
  const body = yield response.json();
114
120
  const transfers = [];
121
+ if (f.tokenAccount.toString() === constants_1.polyBridgeEscrow) {
122
+ console.log('poly solscan data: ', JSON.stringify(body));
123
+ }
115
124
  for (const item of body.data || []) {
116
- if (item.change_type === (f.flow === "in" ? "inc" : "dec")) {
125
+ if (item.change_type === (f.flow === 'in' ? 'inc' : 'dec')) {
117
126
  transfers.push({
118
127
  amount: Math.abs(item.amount || 0),
119
128
  tokenDecimals: item.token_decimals || 0,
@@ -131,7 +140,7 @@ const solscanProClient = (apiKey) => {
131
140
  return allTransfers.filter((t) => t.amount !== 0);
132
141
  }
133
142
  catch (error) {
134
- console.error("Error in getBalanceChange:", error);
143
+ console.error('Error in getBalanceChange:', error);
135
144
  return [];
136
145
  }
137
146
  });
@@ -161,8 +170,12 @@ const solscanProClient = (apiKey) => {
161
170
  transfers.push({
162
171
  amount: item.amount || 0,
163
172
  tokenDecimals: item.token_decimals || 0,
164
- fromAddress: item.from_address ? new web3_js_1.PublicKey(item.from_address) : undefined,
165
- toAddress: item.to_address ? new web3_js_1.PublicKey(item.to_address) : undefined,
173
+ fromAddress: item.from_address
174
+ ? new web3_js_1.PublicKey(item.from_address)
175
+ : undefined,
176
+ toAddress: item.to_address
177
+ ? new web3_js_1.PublicKey(item.to_address)
178
+ : undefined,
166
179
  sig: item.trans_id,
167
180
  blockTime: item.block_time || 0,
168
181
  });
@@ -176,7 +189,7 @@ const solscanProClient = (apiKey) => {
176
189
  return allTransfers.filter((t) => t.amount !== 0);
177
190
  }
178
191
  catch (error) {
179
- console.error("Error in getTransfers:", error);
192
+ console.error('Error in getTransfers:', error);
180
193
  throw new Error(`Failed to get transfers: ${error}`);
181
194
  }
182
195
  });
@@ -233,7 +246,8 @@ const heliusClient = (apiKey) => {
233
246
  const change = postAmount - preAmount;
234
247
  if (change !== 0) {
235
248
  const isInflow = change > 0;
236
- if ((f.flow === 'in' && isInflow) || (f.flow === 'out' && !isInflow)) {
249
+ if ((f.flow === 'in' && isInflow) ||
250
+ (f.flow === 'out' && !isInflow)) {
237
251
  transfers.push({
238
252
  amount: Math.abs(change),
239
253
  tokenDecimals: ((_d = postBalance.uiTokenAmount) === null || _d === void 0 ? void 0 : _d.decimals) || 0,
@@ -248,7 +262,7 @@ const heliusClient = (apiKey) => {
248
262
  console.error(`Error processing signature ${sig.signature}:`, e);
249
263
  }
250
264
  }
251
- return transfers.filter(t => t.amount !== 0);
265
+ return transfers.filter((t) => t.amount !== 0);
252
266
  }
253
267
  catch (error) {
254
268
  console.error('Error in getBalanceChange:', error);
@@ -280,7 +294,7 @@ const heliusClient = (apiKey) => {
280
294
  for (const postBalance of postTokenBalances) {
281
295
  if (postBalance.mint !== f.mint.toString())
282
296
  continue;
283
- const preBalance = preTokenBalances.find(pre => pre.accountIndex === postBalance.accountIndex);
297
+ const preBalance = preTokenBalances.find((pre) => pre.accountIndex === postBalance.accountIndex);
284
298
  const preAmount = Number(((_b = preBalance === null || preBalance === void 0 ? void 0 : preBalance.uiTokenAmount) === null || _b === void 0 ? void 0 : _b.amount) || 0);
285
299
  const postAmount = Number(((_c = postBalance.uiTokenAmount) === null || _c === void 0 ? void 0 : _c.amount) || 0);
286
300
  const change = postAmount - preAmount;
@@ -289,15 +303,18 @@ const heliusClient = (apiKey) => {
289
303
  mint: postBalance.mint,
290
304
  owner: postBalance.owner,
291
305
  change,
292
- decimals: ((_d = postBalance.uiTokenAmount) === null || _d === void 0 ? void 0 : _d.decimals) || 0
306
+ decimals: ((_d = postBalance.uiTokenAmount) === null || _d === void 0 ? void 0 : _d.decimals) || 0,
293
307
  });
294
308
  }
295
309
  }
296
310
  // Find transfers involving the target address
297
311
  for (const [accountIndex, balanceChange] of balanceChanges) {
298
- const isFromTarget = balanceChange.owner === f.addr.toString() && balanceChange.change < 0;
299
- const isToTarget = balanceChange.owner === f.addr.toString() && balanceChange.change > 0;
300
- if ((f.flow === 'out' && isFromTarget) || (f.flow === 'in' && isToTarget)) {
312
+ const isFromTarget = balanceChange.owner === f.addr.toString() &&
313
+ balanceChange.change < 0;
314
+ const isToTarget = balanceChange.owner === f.addr.toString() &&
315
+ balanceChange.change > 0;
316
+ if ((f.flow === 'out' && isFromTarget) ||
317
+ (f.flow === 'in' && isToTarget)) {
301
318
  // Find the counterpart transfer
302
319
  let fromAddress;
303
320
  let toAddress;
@@ -305,7 +322,8 @@ const heliusClient = (apiKey) => {
305
322
  fromAddress = f.addr;
306
323
  // Find who received the tokens
307
324
  for (const [_, otherChange] of balanceChanges) {
308
- if (otherChange.owner !== f.addr.toString() && otherChange.change > 0) {
325
+ if (otherChange.owner !== f.addr.toString() &&
326
+ otherChange.change > 0) {
309
327
  toAddress = new web3_js_1.PublicKey(otherChange.owner);
310
328
  break;
311
329
  }
@@ -315,7 +333,8 @@ const heliusClient = (apiKey) => {
315
333
  toAddress = f.addr;
316
334
  // Find who sent the tokens
317
335
  for (const [_, otherChange] of balanceChanges) {
318
- if (otherChange.owner !== f.addr.toString() && otherChange.change < 0) {
336
+ if (otherChange.owner !== f.addr.toString() &&
337
+ otherChange.change < 0) {
319
338
  fromAddress = new web3_js_1.PublicKey(otherChange.owner);
320
339
  break;
321
340
  }
@@ -336,7 +355,7 @@ const heliusClient = (apiKey) => {
336
355
  console.error(`Error processing signature ${sig.signature}:`, e);
337
356
  }
338
357
  }
339
- return transfers.filter(t => t.amount !== 0);
358
+ return transfers.filter((t) => t.amount !== 0);
340
359
  }
341
360
  catch (error) {
342
361
  console.error('Error in getTransfers:', error);
@@ -360,23 +379,23 @@ class Backfiller {
360
379
  this.isDryRun = isDryRun;
361
380
  }
362
381
  emit() {
363
- this._types["emit"] = {};
382
+ this._types['emit'] = {};
364
383
  return this;
365
384
  }
366
385
  loans() {
367
- this._types["loan"] = {};
386
+ this._types['loan'] = {};
368
387
  return this;
369
388
  }
370
389
  buyBurnUSDCInflow() {
371
- this._types["buyBurnUSDCInflow"] = {};
390
+ this._types['buyBurnUSDCInflow'] = {};
372
391
  return this;
373
392
  }
374
393
  manualMint() {
375
- this._types["manualMint"] = {};
394
+ this._types['manualMint'] = {};
376
395
  return this;
377
396
  }
378
397
  vaultOutflows(p) {
379
- this._types["vaultOutflows"] = {};
398
+ this._types['vaultOutflows'] = {};
380
399
  this.solscan.pageSize = p.pageSize || 100;
381
400
  return this;
382
401
  }
@@ -384,7 +403,7 @@ class Backfiller {
384
403
  this._txs.push(...sigs);
385
404
  }
386
405
  formatAmount(amount, decimals = 8) {
387
- const amt = typeof amount === "bigint" ? Number(amount) : amount;
406
+ const amt = typeof amount === 'bigint' ? Number(amount) : amount;
388
407
  return (amt / Math.pow(10, decimals)).toLocaleString(undefined, {
389
408
  maximumFractionDigits: 8,
390
409
  minimumFractionDigits: 0,
@@ -398,67 +417,67 @@ class Backfiller {
398
417
  const trs = [
399
418
  {
400
419
  transfer: {
401
- toSolKey: "2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC",
420
+ toSolKey: '2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC',
402
421
  fromSolKey: constants_1.v3SquadsVault,
403
- solTx: "3oC8BybX5YrkfPyvV8rAE1tnJr6egtZFHLghqHuLi3eaT4aWm87qZPJFrjFRn6nwVemd2ponsew85tBs6VVQzTJv",
404
- executedAt: new Date("December 22, 2023 04:13:58 UTC"),
405
- symbol: "RENDER",
406
- channel: "loan",
422
+ solTx: '3oC8BybX5YrkfPyvV8rAE1tnJr6egtZFHLghqHuLi3eaT4aWm87qZPJFrjFRn6nwVemd2ponsew85tBs6VVQzTJv',
423
+ executedAt: new Date('December 22, 2023 04:13:58 UTC'),
424
+ symbol: 'RENDER',
425
+ channel: 'loan',
407
426
  amountPayed: BigInt(44999 * Math.pow(10, 8)),
408
427
  },
409
428
  },
410
429
  {
411
430
  transfer: {
412
- toSolKey: "2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC",
431
+ toSolKey: '2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC',
413
432
  fromSolKey: constants_1.v3SquadsVault,
414
- channel: "loan",
415
- solTx: "2f5sEBHcP8wpF79voUEUiP8pryDt7FvqrTXQrEpXzAxbzyFYPkavZGtJc5N8CXhfbJav8hQTr9YcENKseiouaWzc",
416
- executedAt: new Date("December 22, 2023 02:39:53 UTC"),
417
- symbol: "RENDER",
433
+ channel: 'loan',
434
+ solTx: '2f5sEBHcP8wpF79voUEUiP8pryDt7FvqrTXQrEpXzAxbzyFYPkavZGtJc5N8CXhfbJav8hQTr9YcENKseiouaWzc',
435
+ executedAt: new Date('December 22, 2023 02:39:53 UTC'),
436
+ symbol: 'RENDER',
418
437
  amountPayed: BigInt(1 * Math.pow(10, 8)),
419
438
  },
420
439
  },
421
440
  {
422
441
  transfer: {
423
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
442
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
424
443
  fromSolKey: constants_1.v3SquadsVault,
425
- channel: "loan",
426
- solTx: "42n55BZcKVBCSZQoaneBQLn57v7zZGZorGe3uBLheGu4BQtpaTChdT1z3vHwgU4MHghJw3wJ72rFLkib761ewJCj",
427
- executedAt: new Date("January 12, 2024 00:17:02 UTC"),
428
- symbol: "RENDER",
444
+ channel: 'loan',
445
+ solTx: '42n55BZcKVBCSZQoaneBQLn57v7zZGZorGe3uBLheGu4BQtpaTChdT1z3vHwgU4MHghJw3wJ72rFLkib761ewJCj',
446
+ executedAt: new Date('January 12, 2024 00:17:02 UTC'),
447
+ symbol: 'RENDER',
429
448
  amountPayed: BigInt(1 * Math.pow(10, 8)),
430
449
  },
431
450
  },
432
451
  {
433
452
  transfer: {
434
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
453
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
435
454
  fromSolKey: constants_1.v3SquadsVault,
436
- channel: "loan",
437
- solTx: "THJLvA1UTqH22hNP7Ecnfn4iY736VJAZ8scgSUjrDDaGpSQJmGYKJYXGtDu6TB96fKo6mJBtUBZvLb4ors17JUR",
438
- executedAt: new Date("January 17, 2024 22:09:58 UTC"),
439
- symbol: "RENDER",
455
+ channel: 'loan',
456
+ solTx: 'THJLvA1UTqH22hNP7Ecnfn4iY736VJAZ8scgSUjrDDaGpSQJmGYKJYXGtDu6TB96fKo6mJBtUBZvLb4ors17JUR',
457
+ executedAt: new Date('January 17, 2024 22:09:58 UTC'),
458
+ symbol: 'RENDER',
440
459
  amountPayed: BigInt(49999 * Math.pow(10, 8)),
441
460
  },
442
461
  },
443
462
  {
444
463
  transfer: {
445
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
464
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
446
465
  fromSolKey: constants_1.devsSquadsVault,
447
- channel: "loan",
448
- solTx: "5BcxrMExq34jtMB5c3bH3A8TN4pCp9sxjC5HMcS7Mh8pig3r2eQhvRnJeE1RBTyQ4JDXyANWmDU9SKdYFyT2wDoq",
449
- executedAt: new Date("February 28, 2024 22:43:21 UTC"),
450
- symbol: "RENDER",
466
+ channel: 'loan',
467
+ solTx: '5BcxrMExq34jtMB5c3bH3A8TN4pCp9sxjC5HMcS7Mh8pig3r2eQhvRnJeE1RBTyQ4JDXyANWmDU9SKdYFyT2wDoq',
468
+ executedAt: new Date('February 28, 2024 22:43:21 UTC'),
469
+ symbol: 'RENDER',
451
470
  amountPayed: BigInt(1 * Math.pow(10, 8)),
452
471
  },
453
472
  },
454
473
  {
455
474
  transfer: {
456
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
475
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
457
476
  fromSolKey: constants_1.devsSquadsVault,
458
- channel: "loan",
459
- solTx: "5E4E35CT4e3fhbMAwcKdfAvJL4uUHR8hHE8REmKnDCEsFZ6mxaE1YyeYK8Sbg5AJqBJxsZkcYSohY8T14YLC5pXs",
460
- executedAt: new Date("February 29, 2024 01:17:51 UTC"),
461
- symbol: "RENDER",
477
+ channel: 'loan',
478
+ solTx: '5E4E35CT4e3fhbMAwcKdfAvJL4uUHR8hHE8REmKnDCEsFZ6mxaE1YyeYK8Sbg5AJqBJxsZkcYSohY8T14YLC5pXs',
479
+ executedAt: new Date('February 29, 2024 01:17:51 UTC'),
480
+ symbol: 'RENDER',
462
481
  amountPayed: BigInt(199999 * Math.pow(10, 8)),
463
482
  },
464
483
  },
@@ -526,7 +545,8 @@ class Backfiller {
526
545
  }
527
546
  const logMessages = ((_b = p === null || p === void 0 ? void 0 : p.meta) === null || _b === void 0 ? void 0 : _b.logMessages) || [];
528
547
  for (const l of logMessages) {
529
- if (l.includes("DistributeEmissionsV0") || l.includes("DistributeEmissionsV1")) {
548
+ if (l.includes('DistributeEmissionsV0') ||
549
+ l.includes('DistributeEmissionsV1')) {
530
550
  out.push(s.signature);
531
551
  if (this.isDryRun) {
532
552
  console.log(`${s.signature} | ${this.formatTimestamp(s.blockTime)} | emission | Emission Distributor -> Various Recipients | N/A RENDER`);
@@ -543,26 +563,34 @@ class Backfiller {
543
563
  return out;
544
564
  });
545
565
  }
546
- indexTxs(txs, channel, reindexTx = false, deleteFailed = false, mints = [constants_1.renderMint, constants_1.usdcMint], senders = [constants_1.passthruEscrow, constants_1.v3SquadsVault, constants_1.upgradeRewardsEscrow, constants_1.upgradeRewardsCircuitBreaker, constants_1.renderMint], assertSender = "") {
566
+ indexTxs(txs, channel, reindexTx = false, deleteFailed = false, mints = [constants_1.renderMint, constants_1.usdcMint], senders = [
567
+ constants_1.passthruEscrow,
568
+ constants_1.v3SquadsVault,
569
+ constants_1.upgradeRewardsEscrow,
570
+ constants_1.upgradeRewardsCircuitBreaker,
571
+ constants_1.renderMint,
572
+ ], assertSender = '') {
547
573
  var _a, _b, _c, _d, _e;
548
574
  return __awaiter(this, void 0, void 0, function* () {
549
575
  let proced = 0;
550
576
  console.log(`processing ${txs.length} txs`);
551
577
  const insertedIds = [];
552
578
  for (const solTx of txs) {
553
- if (solTx == "") {
579
+ if (solTx == '') {
554
580
  continue;
555
581
  }
556
582
  console.log(`solTx ${solTx}`);
557
583
  const tx = yield this.heliusClient.getParsedTransaction(solTx);
558
- if (!tx || (tx.status !== "Success" && tx.err)) {
584
+ if (!tx || (tx.status !== 'Success' && tx.err)) {
559
585
  if (this.isDryRun) {
560
586
  console.log(`Would delete failed transaction ${solTx} from database`);
561
587
  continue;
562
588
  }
563
589
  console.log(`shouldnt exist ${solTx} in db. deleting`);
564
590
  try {
565
- const res = yield this.pg.db.trx.deleteFrom("sol_tx").where("sig", "=", solTx).execute();
591
+ const res = yield this.pg.db.trx.deleteFrom('sol_tx')
592
+ .where('sig', '=', solTx)
593
+ .execute();
566
594
  console.log(`deleted ${res.length > 0 ? res[0].numDeletedRows || 0 : 0} tx`);
567
595
  }
568
596
  catch (e) {
@@ -581,19 +609,22 @@ class Backfiller {
581
609
  onchain[balance.owner] = { mint, amt };
582
610
  }
583
611
  }
584
- let sender = "";
612
+ let sender = '';
585
613
  for (const balance of preTokenBalances) {
586
614
  const mint = mints.find((m) => balance.mint === m);
587
615
  if (mint) {
588
616
  const amt = Number(((_e = balance.uiTokenAmount) === null || _e === void 0 ? void 0 : _e.amount) || balance.amount || 0);
589
617
  if (onchain[balance.owner]) {
590
- onchain[balance.owner] = { mint, amt: onchain[balance.owner].amt - amt };
618
+ onchain[balance.owner] = {
619
+ mint,
620
+ amt: onchain[balance.owner].amt - amt,
621
+ };
591
622
  if (onchain[balance.owner].amt < 0) {
592
623
  const foundSender = senders.find((s) => s === balance.owner.toString());
593
624
  if (!foundSender) {
594
625
  throw new Error(`sender ${balance.owner} not in expected senders ${senders}`);
595
626
  }
596
- if (assertSender !== "" && foundSender !== assertSender) {
627
+ if (assertSender !== '' && foundSender !== assertSender) {
597
628
  throw new Error(`assert sender ${balance.owner} != ${assertSender}`);
598
629
  }
599
630
  sender = foundSender;
@@ -601,7 +632,7 @@ class Backfiller {
601
632
  }
602
633
  }
603
634
  }
604
- if (channel === "emit") {
635
+ if (channel === 'emit') {
605
636
  sender = constants_1.renderMint;
606
637
  }
607
638
  if (!sender) {
@@ -624,7 +655,7 @@ class Backfiller {
624
655
  console.log(`proced ${proced}`);
625
656
  }
626
657
  }
627
- console.log(`done. inserted ${insertedIds.length} transfers: ${insertedIds.join(",")}`);
658
+ console.log(`done. inserted ${insertedIds.length} transfers: ${insertedIds.join(',')}`);
628
659
  });
629
660
  }
630
661
  indexTransfers(onchain, tx, sender, channel, reindexTx = false) {
@@ -637,12 +668,12 @@ class Backfiller {
637
668
  }
638
669
  const symbol = (() => {
639
670
  if (mint == constants_1.renderMint) {
640
- return "RENDER";
671
+ return 'RENDER';
641
672
  }
642
673
  if (mint == constants_1.usdcMint) {
643
- return "USDC";
674
+ return 'USDC';
644
675
  }
645
- return "UNKNOWN";
676
+ return 'UNKNOWN';
646
677
  })();
647
678
  const amount = this.formatAmount(amt);
648
679
  const timestamp = this.formatTimestamp(tx.blockTime);
@@ -652,7 +683,9 @@ class Backfiller {
652
683
  }
653
684
  if (reindexTx) {
654
685
  try {
655
- const res = yield this.pg.db.trx.deleteFrom("sol_tx").where("sig", "=", tx.sig).execute();
686
+ const res = yield this.pg.db.trx.deleteFrom('sol_tx')
687
+ .where('sig', '=', tx.sig)
688
+ .execute();
656
689
  console.log(`deleted ${res.length > 0 ? res[0].numDeletedRows || 0 : 0} tx`);
657
690
  }
658
691
  catch (e) {
@@ -674,10 +707,10 @@ class Backfiller {
674
707
  toSolKey: k,
675
708
  symbol: (() => {
676
709
  if (mint == constants_1.renderMint) {
677
- return "RENDER";
710
+ return 'RENDER';
678
711
  }
679
712
  if (mint == constants_1.usdcMint) {
680
- return "USDC";
713
+ return 'USDC';
681
714
  }
682
715
  throw new Error(`unknown mint ${mint}`);
683
716
  })(),
@@ -694,7 +727,7 @@ class Backfiller {
694
727
  }
695
728
  catch (e) {
696
729
  trx.rollback();
697
- if (`${e}`.includes("duplicate key value violates unique constraint")) {
730
+ if (`${e}`.includes('duplicate key value violates unique constraint')) {
698
731
  console.log(`caught up indexing ${e}`);
699
732
  return { stop: true, insertedIds };
700
733
  }
@@ -708,63 +741,68 @@ class Backfiller {
708
741
  run() {
709
742
  return __awaiter(this, void 0, void 0, function* () {
710
743
  for (const t of Object.keys(this._types)) {
711
- if (t == "emit") {
744
+ if (t == 'emit') {
712
745
  const txs = yield this.findEmitTxs();
713
- yield this.indexTxs(txs, "emit");
746
+ yield this.indexTxs(txs, 'emit');
714
747
  }
715
- else if (t == "buyBurnUSDCInflow") {
748
+ else if (t == 'buyBurnUSDCInflow') {
716
749
  const trs = yield this.solscanClient.getTransfers({
717
750
  mint: new web3_js_1.PublicKey(constants_1.usdcMint),
718
- flow: "in",
751
+ flow: 'in',
719
752
  addr: new web3_js_1.PublicKey(constants_1.buyAndBurnEscrow),
720
753
  });
721
754
  for (const t of trs) {
722
755
  if (!this.isDryRun) {
723
756
  console.log(`buyBurnUSDCInflows: ${JSON.stringify(t)}`);
724
757
  }
725
- const { stop } = yield this.indexTransfers({ [constants_1.buyAndBurnEscrow]: { mint: constants_1.usdcMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, t.fromAddress.toString(), "internal");
758
+ const { stop } = yield this.indexTransfers({ [constants_1.buyAndBurnEscrow]: { mint: constants_1.usdcMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, t.fromAddress.toString(), 'internal');
726
759
  if (stop) {
727
760
  break;
728
761
  }
729
762
  }
730
763
  }
731
- else if (t == "manualMint") {
764
+ else if (t == 'manualMint') {
765
+ console.log(`About to fetch manual mints - renderMint: ${constants_1.renderMint}, bridgeEscrow: ${constants_1.bridgeEscrow}, isDryRun: ${this.isDryRun}`);
732
766
  const trs = yield this.solscanClient.getBalanceChange({
733
767
  mint: new web3_js_1.PublicKey(constants_1.renderMint),
734
- addr: new web3_js_1.PublicKey("AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy"),
735
- flow: "in",
768
+ addr: new web3_js_1.PublicKey('AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy'),
769
+ flow: 'in',
736
770
  tokenAccount: new web3_js_1.PublicKey(constants_1.bridgeEscrow),
737
771
  });
772
+ console.log(`polyTrs result: ${trs.length} transactions`);
738
773
  for (const t of trs) {
739
774
  if (!this.isDryRun) {
740
775
  console.log(`manualMints: ${JSON.stringify(t)}`);
741
776
  }
742
- const { stop } = yield this.indexTransfers({ [constants_1.bridgeEscrow]: { mint: constants_1.renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, constants_1.renderMint, "manual_mint");
777
+ const { stop } = yield this.indexTransfers({ [constants_1.bridgeEscrow]: { mint: constants_1.renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, constants_1.renderMint, 'manual_mint');
743
778
  if (stop) {
744
779
  break;
745
780
  }
746
781
  }
782
+ console.log(`About to fetch poly manual mints - renderMint: ${constants_1.renderMint}, polyBridgeEscrow: ${constants_1.polyBridgeEscrow}, isDryRun: ${this.isDryRun}`);
783
+ // polygon bridge escrow
747
784
  const polyTrs = yield this.solscanClient.getBalanceChange({
748
785
  mint: new web3_js_1.PublicKey(constants_1.renderMint),
749
- addr: new web3_js_1.PublicKey("AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy"),
750
- flow: "in",
786
+ addr: new web3_js_1.PublicKey('E5uyafHUFpNTsiPvGmUpr8BmM1L8t1gx3g6H4Y4vraU5'),
787
+ flow: 'in',
751
788
  tokenAccount: new web3_js_1.PublicKey(constants_1.polyBridgeEscrow),
752
789
  });
790
+ console.log(`polyTrs result: ${polyTrs.length} transactions`);
753
791
  for (const t of polyTrs) {
754
792
  if (!this.isDryRun) {
755
793
  console.log(`polyManualMints: ${JSON.stringify(t)}`);
756
794
  }
757
- const { stop } = yield this.indexTransfers({ [constants_1.polyBridgeEscrow]: { mint: constants_1.renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, constants_1.renderMint, "manual_mint");
795
+ const { stop } = yield this.indexTransfers({ [constants_1.polyBridgeEscrow]: { mint: constants_1.renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, constants_1.renderMint, 'manual_mint');
758
796
  if (stop) {
759
797
  break;
760
798
  }
761
799
  }
762
800
  }
763
- else if (t == "vaultOutflows") {
801
+ else if (t == 'vaultOutflows') {
764
802
  for (const addr of [constants_1.devsSquadsVault, constants_1.masterSquadsVault]) {
765
803
  const trs = yield this.solscanClient.getTransfers({
766
804
  mint: new web3_js_1.PublicKey(constants_1.renderMint),
767
- flow: "out",
805
+ flow: 'out',
768
806
  addr: new web3_js_1.PublicKey(addr),
769
807
  pageSize: this.solscan.pageSize,
770
808
  });
@@ -774,14 +812,14 @@ class Backfiller {
774
812
  }
775
813
  const { stop } = yield this.indexTransfers({
776
814
  [t.toAddress.toString()]: { mint: constants_1.renderMint, amt: t.amount },
777
- }, { blockTime: t.blockTime, sig: t.sig }, addr, "internal");
815
+ }, { blockTime: t.blockTime, sig: t.sig }, addr, 'internal');
778
816
  if (stop) {
779
817
  break;
780
818
  }
781
819
  }
782
820
  }
783
821
  }
784
- else if (t == "loan") {
822
+ else if (t == 'loan') {
785
823
  yield this.indexLoans();
786
824
  }
787
825
  }
@@ -794,27 +832,29 @@ function main() {
794
832
  const args = process.argv.slice(2);
795
833
  const getArgValue = (argName) => {
796
834
  const argIndex = args.indexOf(`--${argName}`);
797
- return argIndex !== -1 && argIndex + 1 < args.length ? args[argIndex + 1] : undefined;
835
+ return argIndex !== -1 && argIndex + 1 < args.length
836
+ ? args[argIndex + 1]
837
+ : undefined;
798
838
  };
799
839
  const hasFlag = (flagName) => {
800
840
  return args.includes(`--${flagName}`);
801
841
  };
802
- const solscanApiKey = getArgValue("solscanApiKey");
842
+ const solscanApiKey = getArgValue('solscanApiKey');
803
843
  if (!solscanApiKey) {
804
- console.error("Error: --solscanApiKey is required");
844
+ console.error('Error: --solscanApiKey is required');
805
845
  process.exit(1);
806
846
  }
807
- const heliusApiKey = getArgValue("heliusApiKey");
847
+ const heliusApiKey = getArgValue('heliusApiKey');
808
848
  if (!heliusApiKey) {
809
- console.error("Error: --heliusApiKey is required");
849
+ console.error('Error: --heliusApiKey is required');
810
850
  process.exit(1);
811
851
  }
812
- const isDryRun = hasFlag("dryRun");
852
+ const isDryRun = hasFlag('dryRun');
813
853
  let pg;
814
854
  if (!isDryRun) {
815
- const pgUrl = getArgValue("pgUrl");
855
+ const pgUrl = getArgValue('pgUrl');
816
856
  if (!pgUrl) {
817
- console.error("Error: --pgUrl is required (unless using --dryRun)");
857
+ console.error('Error: --pgUrl is required (unless using --dryRun)');
818
858
  process.exit(1);
819
859
  }
820
860
  pg = (0, v2Client_1.pgClient)({
@@ -822,30 +862,30 @@ function main() {
822
862
  });
823
863
  }
824
864
  const backfiller = new Backfiller(solscanApiKey, heliusApiKey, pg, isDryRun);
825
- if (hasFlag("loans")) {
865
+ if (hasFlag('loans')) {
826
866
  backfiller.loans();
827
867
  }
828
- if (hasFlag("vaultOutflows")) {
868
+ if (hasFlag('vaultOutflows')) {
829
869
  backfiller.vaultOutflows({});
830
870
  }
831
- if (hasFlag("emissions")) {
871
+ if (hasFlag('emissions')) {
832
872
  backfiller.emit();
833
873
  }
834
- if (hasFlag("buyBurnUSDCInflow")) {
874
+ if (hasFlag('buyBurnUSDCInflow')) {
835
875
  backfiller.buyBurnUSDCInflow();
836
876
  }
837
- if (hasFlag("manualMints")) {
877
+ if (hasFlag('manualMints')) {
838
878
  backfiller.manualMint();
839
879
  }
840
- if (hasFlag("loans") ||
841
- hasFlag("vaultOutflows") ||
842
- hasFlag("emissions") ||
843
- hasFlag("buyBurnUSDCInflow") ||
844
- hasFlag("manualMints")) {
880
+ if (hasFlag('loans') ||
881
+ hasFlag('vaultOutflows') ||
882
+ hasFlag('emissions') ||
883
+ hasFlag('buyBurnUSDCInflow') ||
884
+ hasFlag('manualMints')) {
845
885
  yield backfiller.run();
846
886
  }
847
887
  else {
848
- console.log("No operations specified. Available flags: --loans, --vaultOutflows, --emissions, --buyBurnUSDCInflow, --manualMints, --dryRun");
888
+ console.log('No operations specified. Available flags: --loans, --vaultOutflows, --emissions, --buyBurnUSDCInflow, --manualMints, --dryRun');
849
889
  }
850
890
  });
851
891
  }