@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.
@@ -1,13 +1,13 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- import { renderMint, buyAndBurnEscrow, passthruEscrow, v3SquadsVault, upgradeRewardsEscrow, upgradeRewardsCircuitBreaker, usdcMint, devsSquadsVault, masterSquadsVault, bridgeEscrow, polyBridgeEscrow, } from "./constants";
3
- import { pgClient } from "./client/pg/v2Client";
4
- import { emissionDistributorKey, emissionDistributorV1Key } from "@render-foundation/emission-distributor-sdk";
5
- import { Helius } from "helius-sdk";
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import { renderMint, buyAndBurnEscrow, passthruEscrow, v3SquadsVault, upgradeRewardsEscrow, upgradeRewardsCircuitBreaker, usdcMint, devsSquadsVault, masterSquadsVault, bridgeEscrow, polyBridgeEscrow, } from './constants';
3
+ import { pgClient } from './client/pg/v2Client';
4
+ import { emissionDistributorKey, emissionDistributorV1Key, } from '@render-foundation/emission-distributor-sdk';
5
+ import { Helius } from 'helius-sdk';
6
6
  export const solscanProClient = (apiKey) => {
7
7
  const headers = {
8
8
  token: apiKey,
9
9
  };
10
- const baseUrl = "https://pro-api.solscan.io/v2.0";
10
+ const baseUrl = 'https://pro-api.solscan.io/v2.0';
11
11
  return {
12
12
  async getSignaturesForAddress(addr, options) {
13
13
  const allSignatures = [];
@@ -19,7 +19,7 @@ export const solscanProClient = (apiKey) => {
19
19
  limit: limit.toString(),
20
20
  });
21
21
  if (before) {
22
- params.append("before", before);
22
+ params.append('before', before);
23
23
  }
24
24
  const endpoint = `${baseUrl}/account/transactions?${params}`;
25
25
  const response = await fetch(endpoint, { headers });
@@ -31,15 +31,18 @@ export const solscanProClient = (apiKey) => {
31
31
  const transformedSigs = signatures.map((tx) => ({
32
32
  signature: tx.txHash || tx.signature,
33
33
  blockTime: tx.blockTime || tx.block_time || 0,
34
- err: tx.status !== "Success" ? { err: tx.status } : null,
34
+ err: tx.status !== 'Success' ? { err: tx.status } : null,
35
35
  }));
36
36
  allSignatures.push(...transformedSigs);
37
- if (signatures.length < limit || (options?.limit && allSignatures.length >= options.limit)) {
37
+ if (signatures.length < limit ||
38
+ (options?.limit && allSignatures.length >= options.limit)) {
38
39
  break;
39
40
  }
40
41
  // Set before to the last signature for next page
41
42
  if (signatures.length > 0) {
42
- before = signatures[signatures.length - 1].txHash || signatures[signatures.length - 1].signature;
43
+ before =
44
+ signatures[signatures.length - 1].txHash ||
45
+ signatures[signatures.length - 1].signature;
43
46
  }
44
47
  }
45
48
  return allSignatures.slice(0, options?.limit);
@@ -53,14 +56,14 @@ export const solscanProClient = (apiKey) => {
53
56
  const data = await response.json();
54
57
  return {
55
58
  meta: {
56
- err: data.status !== "Success" ? { err: data.status } : null,
59
+ err: data.status !== 'Success' ? { err: data.status } : null,
57
60
  logMessages: data.logMessages || [],
58
61
  preTokenBalances: data.inputAccount || [],
59
62
  postTokenBalances: data.outputAccount || [],
60
63
  },
61
64
  blockTime: data.blockTime || data.block_time || 0,
62
65
  status: data.status,
63
- err: data.status !== "Success" ? { err: data.status } : null,
66
+ err: data.status !== 'Success' ? { err: data.status } : null,
64
67
  tokenBalances: data.tokenBalances || [],
65
68
  preTokenBalances: data.inputAccount || [],
66
69
  postTokenBalances: data.outputAccount || [],
@@ -78,24 +81,30 @@ export const solscanProClient = (apiKey) => {
78
81
  page_size: pageSize.toString(),
79
82
  });
80
83
  if (f.mint) {
81
- params.append("token", f.mint.toString());
84
+ params.append('token', f.mint.toString());
82
85
  }
83
86
  if (f.flow) {
84
- params.append("flow", f.flow);
87
+ params.append('flow', f.flow);
85
88
  }
86
89
  if (f.tokenAccount) {
87
- params.append("token_account", f.tokenAccount.toString());
90
+ params.append('token_account', f.tokenAccount.toString());
88
91
  }
89
92
  const endpoint = `${baseUrl}/account/balance_change?${params}`;
90
93
  const response = await fetch(endpoint, { headers });
94
+ if (f.tokenAccount.toString() === polyBridgeEscrow) {
95
+ console.log('Poly solscan response: ', JSON.stringify(response));
96
+ }
91
97
  if (!response.ok) {
92
98
  console.error(`Failed to fetch balance changes: ${response.statusText}`);
93
99
  break;
94
100
  }
95
101
  const body = await response.json();
96
102
  const transfers = [];
103
+ if (f.tokenAccount.toString() === polyBridgeEscrow) {
104
+ console.log('poly solscan data: ', JSON.stringify(body));
105
+ }
97
106
  for (const item of body.data || []) {
98
- if (item.change_type === (f.flow === "in" ? "inc" : "dec")) {
107
+ if (item.change_type === (f.flow === 'in' ? 'inc' : 'dec')) {
99
108
  transfers.push({
100
109
  amount: Math.abs(item.amount || 0),
101
110
  tokenDecimals: item.token_decimals || 0,
@@ -113,7 +122,7 @@ export const solscanProClient = (apiKey) => {
113
122
  return allTransfers.filter((t) => t.amount !== 0);
114
123
  }
115
124
  catch (error) {
116
- console.error("Error in getBalanceChange:", error);
125
+ console.error('Error in getBalanceChange:', error);
117
126
  return [];
118
127
  }
119
128
  },
@@ -141,8 +150,12 @@ export const solscanProClient = (apiKey) => {
141
150
  transfers.push({
142
151
  amount: item.amount || 0,
143
152
  tokenDecimals: item.token_decimals || 0,
144
- fromAddress: item.from_address ? new PublicKey(item.from_address) : undefined,
145
- toAddress: item.to_address ? new PublicKey(item.to_address) : undefined,
153
+ fromAddress: item.from_address
154
+ ? new PublicKey(item.from_address)
155
+ : undefined,
156
+ toAddress: item.to_address
157
+ ? new PublicKey(item.to_address)
158
+ : undefined,
146
159
  sig: item.trans_id,
147
160
  blockTime: item.block_time || 0,
148
161
  });
@@ -156,7 +169,7 @@ export const solscanProClient = (apiKey) => {
156
169
  return allTransfers.filter((t) => t.amount !== 0);
157
170
  }
158
171
  catch (error) {
159
- console.error("Error in getTransfers:", error);
172
+ console.error('Error in getTransfers:', error);
160
173
  throw new Error(`Failed to get transfers: ${error}`);
161
174
  }
162
175
  },
@@ -205,7 +218,8 @@ export const heliusClient = (apiKey) => {
205
218
  const change = postAmount - preAmount;
206
219
  if (change !== 0) {
207
220
  const isInflow = change > 0;
208
- if ((f.flow === 'in' && isInflow) || (f.flow === 'out' && !isInflow)) {
221
+ if ((f.flow === 'in' && isInflow) ||
222
+ (f.flow === 'out' && !isInflow)) {
209
223
  transfers.push({
210
224
  amount: Math.abs(change),
211
225
  tokenDecimals: postBalance.uiTokenAmount?.decimals || 0,
@@ -220,7 +234,7 @@ export const heliusClient = (apiKey) => {
220
234
  console.error(`Error processing signature ${sig.signature}:`, e);
221
235
  }
222
236
  }
223
- return transfers.filter(t => t.amount !== 0);
237
+ return transfers.filter((t) => t.amount !== 0);
224
238
  }
225
239
  catch (error) {
226
240
  console.error('Error in getBalanceChange:', error);
@@ -249,7 +263,7 @@ export const heliusClient = (apiKey) => {
249
263
  for (const postBalance of postTokenBalances) {
250
264
  if (postBalance.mint !== f.mint.toString())
251
265
  continue;
252
- const preBalance = preTokenBalances.find(pre => pre.accountIndex === postBalance.accountIndex);
266
+ const preBalance = preTokenBalances.find((pre) => pre.accountIndex === postBalance.accountIndex);
253
267
  const preAmount = Number(preBalance?.uiTokenAmount?.amount || 0);
254
268
  const postAmount = Number(postBalance.uiTokenAmount?.amount || 0);
255
269
  const change = postAmount - preAmount;
@@ -258,15 +272,18 @@ export const heliusClient = (apiKey) => {
258
272
  mint: postBalance.mint,
259
273
  owner: postBalance.owner,
260
274
  change,
261
- decimals: postBalance.uiTokenAmount?.decimals || 0
275
+ decimals: postBalance.uiTokenAmount?.decimals || 0,
262
276
  });
263
277
  }
264
278
  }
265
279
  // Find transfers involving the target address
266
280
  for (const [accountIndex, balanceChange] of balanceChanges) {
267
- const isFromTarget = balanceChange.owner === f.addr.toString() && balanceChange.change < 0;
268
- const isToTarget = balanceChange.owner === f.addr.toString() && balanceChange.change > 0;
269
- if ((f.flow === 'out' && isFromTarget) || (f.flow === 'in' && isToTarget)) {
281
+ const isFromTarget = balanceChange.owner === f.addr.toString() &&
282
+ balanceChange.change < 0;
283
+ const isToTarget = balanceChange.owner === f.addr.toString() &&
284
+ balanceChange.change > 0;
285
+ if ((f.flow === 'out' && isFromTarget) ||
286
+ (f.flow === 'in' && isToTarget)) {
270
287
  // Find the counterpart transfer
271
288
  let fromAddress;
272
289
  let toAddress;
@@ -274,7 +291,8 @@ export const heliusClient = (apiKey) => {
274
291
  fromAddress = f.addr;
275
292
  // Find who received the tokens
276
293
  for (const [_, otherChange] of balanceChanges) {
277
- if (otherChange.owner !== f.addr.toString() && otherChange.change > 0) {
294
+ if (otherChange.owner !== f.addr.toString() &&
295
+ otherChange.change > 0) {
278
296
  toAddress = new PublicKey(otherChange.owner);
279
297
  break;
280
298
  }
@@ -284,7 +302,8 @@ export const heliusClient = (apiKey) => {
284
302
  toAddress = f.addr;
285
303
  // Find who sent the tokens
286
304
  for (const [_, otherChange] of balanceChanges) {
287
- if (otherChange.owner !== f.addr.toString() && otherChange.change < 0) {
305
+ if (otherChange.owner !== f.addr.toString() &&
306
+ otherChange.change < 0) {
288
307
  fromAddress = new PublicKey(otherChange.owner);
289
308
  break;
290
309
  }
@@ -305,7 +324,7 @@ export const heliusClient = (apiKey) => {
305
324
  console.error(`Error processing signature ${sig.signature}:`, e);
306
325
  }
307
326
  }
308
- return transfers.filter(t => t.amount !== 0);
327
+ return transfers.filter((t) => t.amount !== 0);
309
328
  }
310
329
  catch (error) {
311
330
  console.error('Error in getTransfers:', error);
@@ -330,23 +349,23 @@ export class Backfiller {
330
349
  this.isDryRun = isDryRun;
331
350
  }
332
351
  emit() {
333
- this._types["emit"] = {};
352
+ this._types['emit'] = {};
334
353
  return this;
335
354
  }
336
355
  loans() {
337
- this._types["loan"] = {};
356
+ this._types['loan'] = {};
338
357
  return this;
339
358
  }
340
359
  buyBurnUSDCInflow() {
341
- this._types["buyBurnUSDCInflow"] = {};
360
+ this._types['buyBurnUSDCInflow'] = {};
342
361
  return this;
343
362
  }
344
363
  manualMint() {
345
- this._types["manualMint"] = {};
364
+ this._types['manualMint'] = {};
346
365
  return this;
347
366
  }
348
367
  vaultOutflows(p) {
349
- this._types["vaultOutflows"] = {};
368
+ this._types['vaultOutflows'] = {};
350
369
  this.solscan.pageSize = p.pageSize || 100;
351
370
  return this;
352
371
  }
@@ -354,7 +373,7 @@ export class Backfiller {
354
373
  this._txs.push(...sigs);
355
374
  }
356
375
  formatAmount(amount, decimals = 8) {
357
- const amt = typeof amount === "bigint" ? Number(amount) : amount;
376
+ const amt = typeof amount === 'bigint' ? Number(amount) : amount;
358
377
  return (amt / Math.pow(10, decimals)).toLocaleString(undefined, {
359
378
  maximumFractionDigits: 8,
360
379
  minimumFractionDigits: 0,
@@ -367,67 +386,67 @@ export class Backfiller {
367
386
  const trs = [
368
387
  {
369
388
  transfer: {
370
- toSolKey: "2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC",
389
+ toSolKey: '2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC',
371
390
  fromSolKey: v3SquadsVault,
372
- solTx: "3oC8BybX5YrkfPyvV8rAE1tnJr6egtZFHLghqHuLi3eaT4aWm87qZPJFrjFRn6nwVemd2ponsew85tBs6VVQzTJv",
373
- executedAt: new Date("December 22, 2023 04:13:58 UTC"),
374
- symbol: "RENDER",
375
- channel: "loan",
391
+ solTx: '3oC8BybX5YrkfPyvV8rAE1tnJr6egtZFHLghqHuLi3eaT4aWm87qZPJFrjFRn6nwVemd2ponsew85tBs6VVQzTJv',
392
+ executedAt: new Date('December 22, 2023 04:13:58 UTC'),
393
+ symbol: 'RENDER',
394
+ channel: 'loan',
376
395
  amountPayed: BigInt(44999 * Math.pow(10, 8)),
377
396
  },
378
397
  },
379
398
  {
380
399
  transfer: {
381
- toSolKey: "2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC",
400
+ toSolKey: '2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC',
382
401
  fromSolKey: v3SquadsVault,
383
- channel: "loan",
384
- solTx: "2f5sEBHcP8wpF79voUEUiP8pryDt7FvqrTXQrEpXzAxbzyFYPkavZGtJc5N8CXhfbJav8hQTr9YcENKseiouaWzc",
385
- executedAt: new Date("December 22, 2023 02:39:53 UTC"),
386
- symbol: "RENDER",
402
+ channel: 'loan',
403
+ solTx: '2f5sEBHcP8wpF79voUEUiP8pryDt7FvqrTXQrEpXzAxbzyFYPkavZGtJc5N8CXhfbJav8hQTr9YcENKseiouaWzc',
404
+ executedAt: new Date('December 22, 2023 02:39:53 UTC'),
405
+ symbol: 'RENDER',
387
406
  amountPayed: BigInt(1 * Math.pow(10, 8)),
388
407
  },
389
408
  },
390
409
  {
391
410
  transfer: {
392
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
411
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
393
412
  fromSolKey: v3SquadsVault,
394
- channel: "loan",
395
- solTx: "42n55BZcKVBCSZQoaneBQLn57v7zZGZorGe3uBLheGu4BQtpaTChdT1z3vHwgU4MHghJw3wJ72rFLkib761ewJCj",
396
- executedAt: new Date("January 12, 2024 00:17:02 UTC"),
397
- symbol: "RENDER",
413
+ channel: 'loan',
414
+ solTx: '42n55BZcKVBCSZQoaneBQLn57v7zZGZorGe3uBLheGu4BQtpaTChdT1z3vHwgU4MHghJw3wJ72rFLkib761ewJCj',
415
+ executedAt: new Date('January 12, 2024 00:17:02 UTC'),
416
+ symbol: 'RENDER',
398
417
  amountPayed: BigInt(1 * Math.pow(10, 8)),
399
418
  },
400
419
  },
401
420
  {
402
421
  transfer: {
403
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
422
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
404
423
  fromSolKey: v3SquadsVault,
405
- channel: "loan",
406
- solTx: "THJLvA1UTqH22hNP7Ecnfn4iY736VJAZ8scgSUjrDDaGpSQJmGYKJYXGtDu6TB96fKo6mJBtUBZvLb4ors17JUR",
407
- executedAt: new Date("January 17, 2024 22:09:58 UTC"),
408
- symbol: "RENDER",
424
+ channel: 'loan',
425
+ solTx: 'THJLvA1UTqH22hNP7Ecnfn4iY736VJAZ8scgSUjrDDaGpSQJmGYKJYXGtDu6TB96fKo6mJBtUBZvLb4ors17JUR',
426
+ executedAt: new Date('January 17, 2024 22:09:58 UTC'),
427
+ symbol: 'RENDER',
409
428
  amountPayed: BigInt(49999 * Math.pow(10, 8)),
410
429
  },
411
430
  },
412
431
  {
413
432
  transfer: {
414
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
433
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
415
434
  fromSolKey: devsSquadsVault,
416
- channel: "loan",
417
- solTx: "5BcxrMExq34jtMB5c3bH3A8TN4pCp9sxjC5HMcS7Mh8pig3r2eQhvRnJeE1RBTyQ4JDXyANWmDU9SKdYFyT2wDoq",
418
- executedAt: new Date("February 28, 2024 22:43:21 UTC"),
419
- symbol: "RENDER",
435
+ channel: 'loan',
436
+ solTx: '5BcxrMExq34jtMB5c3bH3A8TN4pCp9sxjC5HMcS7Mh8pig3r2eQhvRnJeE1RBTyQ4JDXyANWmDU9SKdYFyT2wDoq',
437
+ executedAt: new Date('February 28, 2024 22:43:21 UTC'),
438
+ symbol: 'RENDER',
420
439
  amountPayed: BigInt(1 * Math.pow(10, 8)),
421
440
  },
422
441
  },
423
442
  {
424
443
  transfer: {
425
- toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
444
+ toSolKey: '5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1',
426
445
  fromSolKey: devsSquadsVault,
427
- channel: "loan",
428
- solTx: "5E4E35CT4e3fhbMAwcKdfAvJL4uUHR8hHE8REmKnDCEsFZ6mxaE1YyeYK8Sbg5AJqBJxsZkcYSohY8T14YLC5pXs",
429
- executedAt: new Date("February 29, 2024 01:17:51 UTC"),
430
- symbol: "RENDER",
446
+ channel: 'loan',
447
+ solTx: '5E4E35CT4e3fhbMAwcKdfAvJL4uUHR8hHE8REmKnDCEsFZ6mxaE1YyeYK8Sbg5AJqBJxsZkcYSohY8T14YLC5pXs',
448
+ executedAt: new Date('February 29, 2024 01:17:51 UTC'),
449
+ symbol: 'RENDER',
431
450
  amountPayed: BigInt(199999 * Math.pow(10, 8)),
432
451
  },
433
452
  },
@@ -492,7 +511,8 @@ export class Backfiller {
492
511
  }
493
512
  const logMessages = p?.meta?.logMessages || [];
494
513
  for (const l of logMessages) {
495
- if (l.includes("DistributeEmissionsV0") || l.includes("DistributeEmissionsV1")) {
514
+ if (l.includes('DistributeEmissionsV0') ||
515
+ l.includes('DistributeEmissionsV1')) {
496
516
  out.push(s.signature);
497
517
  if (this.isDryRun) {
498
518
  console.log(`${s.signature} | ${this.formatTimestamp(s.blockTime)} | emission | Emission Distributor -> Various Recipients | N/A RENDER`);
@@ -508,24 +528,32 @@ export class Backfiller {
508
528
  console.log(`emit txs: ${out.length}`);
509
529
  return out;
510
530
  }
511
- async indexTxs(txs, channel, reindexTx = false, deleteFailed = false, mints = [renderMint, usdcMint], senders = [passthruEscrow, v3SquadsVault, upgradeRewardsEscrow, upgradeRewardsCircuitBreaker, renderMint], assertSender = "") {
531
+ async indexTxs(txs, channel, reindexTx = false, deleteFailed = false, mints = [renderMint, usdcMint], senders = [
532
+ passthruEscrow,
533
+ v3SquadsVault,
534
+ upgradeRewardsEscrow,
535
+ upgradeRewardsCircuitBreaker,
536
+ renderMint,
537
+ ], assertSender = '') {
512
538
  let proced = 0;
513
539
  console.log(`processing ${txs.length} txs`);
514
540
  const insertedIds = [];
515
541
  for (const solTx of txs) {
516
- if (solTx == "") {
542
+ if (solTx == '') {
517
543
  continue;
518
544
  }
519
545
  console.log(`solTx ${solTx}`);
520
546
  const tx = await this.heliusClient.getParsedTransaction(solTx);
521
- if (!tx || (tx.status !== "Success" && tx.err)) {
547
+ if (!tx || (tx.status !== 'Success' && tx.err)) {
522
548
  if (this.isDryRun) {
523
549
  console.log(`Would delete failed transaction ${solTx} from database`);
524
550
  continue;
525
551
  }
526
552
  console.log(`shouldnt exist ${solTx} in db. deleting`);
527
553
  try {
528
- const res = await this.pg.db.trx.deleteFrom("sol_tx").where("sig", "=", solTx).execute();
554
+ const res = await this.pg.db.trx.deleteFrom('sol_tx')
555
+ .where('sig', '=', solTx)
556
+ .execute();
529
557
  console.log(`deleted ${res.length > 0 ? res[0].numDeletedRows || 0 : 0} tx`);
530
558
  }
531
559
  catch (e) {
@@ -544,19 +572,22 @@ export class Backfiller {
544
572
  onchain[balance.owner] = { mint, amt };
545
573
  }
546
574
  }
547
- let sender = "";
575
+ let sender = '';
548
576
  for (const balance of preTokenBalances) {
549
577
  const mint = mints.find((m) => balance.mint === m);
550
578
  if (mint) {
551
579
  const amt = Number(balance.uiTokenAmount?.amount || balance.amount || 0);
552
580
  if (onchain[balance.owner]) {
553
- onchain[balance.owner] = { mint, amt: onchain[balance.owner].amt - amt };
581
+ onchain[balance.owner] = {
582
+ mint,
583
+ amt: onchain[balance.owner].amt - amt,
584
+ };
554
585
  if (onchain[balance.owner].amt < 0) {
555
586
  const foundSender = senders.find((s) => s === balance.owner.toString());
556
587
  if (!foundSender) {
557
588
  throw new Error(`sender ${balance.owner} not in expected senders ${senders}`);
558
589
  }
559
- if (assertSender !== "" && foundSender !== assertSender) {
590
+ if (assertSender !== '' && foundSender !== assertSender) {
560
591
  throw new Error(`assert sender ${balance.owner} != ${assertSender}`);
561
592
  }
562
593
  sender = foundSender;
@@ -564,7 +595,7 @@ export class Backfiller {
564
595
  }
565
596
  }
566
597
  }
567
- if (channel === "emit") {
598
+ if (channel === 'emit') {
568
599
  sender = renderMint;
569
600
  }
570
601
  if (!sender) {
@@ -587,7 +618,7 @@ export class Backfiller {
587
618
  console.log(`proced ${proced}`);
588
619
  }
589
620
  }
590
- console.log(`done. inserted ${insertedIds.length} transfers: ${insertedIds.join(",")}`);
621
+ console.log(`done. inserted ${insertedIds.length} transfers: ${insertedIds.join(',')}`);
591
622
  }
592
623
  async indexTransfers(onchain, tx, sender, channel, reindexTx = false) {
593
624
  const ents = Object.entries(onchain).filter(([k, { mint, amt }]) => amt != 0);
@@ -598,12 +629,12 @@ export class Backfiller {
598
629
  }
599
630
  const symbol = (() => {
600
631
  if (mint == renderMint) {
601
- return "RENDER";
632
+ return 'RENDER';
602
633
  }
603
634
  if (mint == usdcMint) {
604
- return "USDC";
635
+ return 'USDC';
605
636
  }
606
- return "UNKNOWN";
637
+ return 'UNKNOWN';
607
638
  })();
608
639
  const amount = this.formatAmount(amt);
609
640
  const timestamp = this.formatTimestamp(tx.blockTime);
@@ -613,7 +644,9 @@ export class Backfiller {
613
644
  }
614
645
  if (reindexTx) {
615
646
  try {
616
- const res = await this.pg.db.trx.deleteFrom("sol_tx").where("sig", "=", tx.sig).execute();
647
+ const res = await this.pg.db.trx.deleteFrom('sol_tx')
648
+ .where('sig', '=', tx.sig)
649
+ .execute();
617
650
  console.log(`deleted ${res.length > 0 ? res[0].numDeletedRows || 0 : 0} tx`);
618
651
  }
619
652
  catch (e) {
@@ -635,10 +668,10 @@ export class Backfiller {
635
668
  toSolKey: k,
636
669
  symbol: (() => {
637
670
  if (mint == renderMint) {
638
- return "RENDER";
671
+ return 'RENDER';
639
672
  }
640
673
  if (mint == usdcMint) {
641
- return "USDC";
674
+ return 'USDC';
642
675
  }
643
676
  throw new Error(`unknown mint ${mint}`);
644
677
  })(),
@@ -655,7 +688,7 @@ export class Backfiller {
655
688
  }
656
689
  catch (e) {
657
690
  trx.rollback();
658
- if (`${e}`.includes("duplicate key value violates unique constraint")) {
691
+ if (`${e}`.includes('duplicate key value violates unique constraint')) {
659
692
  console.log(`caught up indexing ${e}`);
660
693
  return { stop: true, insertedIds };
661
694
  }
@@ -667,63 +700,68 @@ export class Backfiller {
667
700
  }
668
701
  async run() {
669
702
  for (const t of Object.keys(this._types)) {
670
- if (t == "emit") {
703
+ if (t == 'emit') {
671
704
  const txs = await this.findEmitTxs();
672
- await this.indexTxs(txs, "emit");
705
+ await this.indexTxs(txs, 'emit');
673
706
  }
674
- else if (t == "buyBurnUSDCInflow") {
707
+ else if (t == 'buyBurnUSDCInflow') {
675
708
  const trs = await this.solscanClient.getTransfers({
676
709
  mint: new PublicKey(usdcMint),
677
- flow: "in",
710
+ flow: 'in',
678
711
  addr: new PublicKey(buyAndBurnEscrow),
679
712
  });
680
713
  for (const t of trs) {
681
714
  if (!this.isDryRun) {
682
715
  console.log(`buyBurnUSDCInflows: ${JSON.stringify(t)}`);
683
716
  }
684
- const { stop } = await this.indexTransfers({ [buyAndBurnEscrow]: { mint: usdcMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, t.fromAddress.toString(), "internal");
717
+ const { stop } = await this.indexTransfers({ [buyAndBurnEscrow]: { mint: usdcMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, t.fromAddress.toString(), 'internal');
685
718
  if (stop) {
686
719
  break;
687
720
  }
688
721
  }
689
722
  }
690
- else if (t == "manualMint") {
723
+ else if (t == 'manualMint') {
724
+ console.log(`About to fetch manual mints - renderMint: ${renderMint}, bridgeEscrow: ${bridgeEscrow}, isDryRun: ${this.isDryRun}`);
691
725
  const trs = await this.solscanClient.getBalanceChange({
692
726
  mint: new PublicKey(renderMint),
693
- addr: new PublicKey("AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy"),
694
- flow: "in",
727
+ addr: new PublicKey('AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy'),
728
+ flow: 'in',
695
729
  tokenAccount: new PublicKey(bridgeEscrow),
696
730
  });
731
+ console.log(`polyTrs result: ${trs.length} transactions`);
697
732
  for (const t of trs) {
698
733
  if (!this.isDryRun) {
699
734
  console.log(`manualMints: ${JSON.stringify(t)}`);
700
735
  }
701
- const { stop } = await this.indexTransfers({ [bridgeEscrow]: { mint: renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, renderMint, "manual_mint");
736
+ const { stop } = await this.indexTransfers({ [bridgeEscrow]: { mint: renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, renderMint, 'manual_mint');
702
737
  if (stop) {
703
738
  break;
704
739
  }
705
740
  }
741
+ console.log(`About to fetch poly manual mints - renderMint: ${renderMint}, polyBridgeEscrow: ${polyBridgeEscrow}, isDryRun: ${this.isDryRun}`);
742
+ // polygon bridge escrow
706
743
  const polyTrs = await this.solscanClient.getBalanceChange({
707
744
  mint: new PublicKey(renderMint),
708
- addr: new PublicKey("AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy"),
709
- flow: "in",
745
+ addr: new PublicKey('E5uyafHUFpNTsiPvGmUpr8BmM1L8t1gx3g6H4Y4vraU5'),
746
+ flow: 'in',
710
747
  tokenAccount: new PublicKey(polyBridgeEscrow),
711
748
  });
749
+ console.log(`polyTrs result: ${polyTrs.length} transactions`);
712
750
  for (const t of polyTrs) {
713
751
  if (!this.isDryRun) {
714
752
  console.log(`polyManualMints: ${JSON.stringify(t)}`);
715
753
  }
716
- const { stop } = await this.indexTransfers({ [polyBridgeEscrow]: { mint: renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, renderMint, "manual_mint");
754
+ const { stop } = await this.indexTransfers({ [polyBridgeEscrow]: { mint: renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, renderMint, 'manual_mint');
717
755
  if (stop) {
718
756
  break;
719
757
  }
720
758
  }
721
759
  }
722
- else if (t == "vaultOutflows") {
760
+ else if (t == 'vaultOutflows') {
723
761
  for (const addr of [devsSquadsVault, masterSquadsVault]) {
724
762
  const trs = await this.solscanClient.getTransfers({
725
763
  mint: new PublicKey(renderMint),
726
- flow: "out",
764
+ flow: 'out',
727
765
  addr: new PublicKey(addr),
728
766
  pageSize: this.solscan.pageSize,
729
767
  });
@@ -733,14 +771,14 @@ export class Backfiller {
733
771
  }
734
772
  const { stop } = await this.indexTransfers({
735
773
  [t.toAddress.toString()]: { mint: renderMint, amt: t.amount },
736
- }, { blockTime: t.blockTime, sig: t.sig }, addr, "internal");
774
+ }, { blockTime: t.blockTime, sig: t.sig }, addr, 'internal');
737
775
  if (stop) {
738
776
  break;
739
777
  }
740
778
  }
741
779
  }
742
780
  }
743
- else if (t == "loan") {
781
+ else if (t == 'loan') {
744
782
  await this.indexLoans();
745
783
  }
746
784
  }
@@ -750,27 +788,29 @@ async function main() {
750
788
  const args = process.argv.slice(2);
751
789
  const getArgValue = (argName) => {
752
790
  const argIndex = args.indexOf(`--${argName}`);
753
- return argIndex !== -1 && argIndex + 1 < args.length ? args[argIndex + 1] : undefined;
791
+ return argIndex !== -1 && argIndex + 1 < args.length
792
+ ? args[argIndex + 1]
793
+ : undefined;
754
794
  };
755
795
  const hasFlag = (flagName) => {
756
796
  return args.includes(`--${flagName}`);
757
797
  };
758
- const solscanApiKey = getArgValue("solscanApiKey");
798
+ const solscanApiKey = getArgValue('solscanApiKey');
759
799
  if (!solscanApiKey) {
760
- console.error("Error: --solscanApiKey is required");
800
+ console.error('Error: --solscanApiKey is required');
761
801
  process.exit(1);
762
802
  }
763
- const heliusApiKey = getArgValue("heliusApiKey");
803
+ const heliusApiKey = getArgValue('heliusApiKey');
764
804
  if (!heliusApiKey) {
765
- console.error("Error: --heliusApiKey is required");
805
+ console.error('Error: --heliusApiKey is required');
766
806
  process.exit(1);
767
807
  }
768
- const isDryRun = hasFlag("dryRun");
808
+ const isDryRun = hasFlag('dryRun');
769
809
  let pg;
770
810
  if (!isDryRun) {
771
- const pgUrl = getArgValue("pgUrl");
811
+ const pgUrl = getArgValue('pgUrl');
772
812
  if (!pgUrl) {
773
- console.error("Error: --pgUrl is required (unless using --dryRun)");
813
+ console.error('Error: --pgUrl is required (unless using --dryRun)');
774
814
  process.exit(1);
775
815
  }
776
816
  pg = pgClient({
@@ -778,30 +818,30 @@ async function main() {
778
818
  });
779
819
  }
780
820
  const backfiller = new Backfiller(solscanApiKey, heliusApiKey, pg, isDryRun);
781
- if (hasFlag("loans")) {
821
+ if (hasFlag('loans')) {
782
822
  backfiller.loans();
783
823
  }
784
- if (hasFlag("vaultOutflows")) {
824
+ if (hasFlag('vaultOutflows')) {
785
825
  backfiller.vaultOutflows({});
786
826
  }
787
- if (hasFlag("emissions")) {
827
+ if (hasFlag('emissions')) {
788
828
  backfiller.emit();
789
829
  }
790
- if (hasFlag("buyBurnUSDCInflow")) {
830
+ if (hasFlag('buyBurnUSDCInflow')) {
791
831
  backfiller.buyBurnUSDCInflow();
792
832
  }
793
- if (hasFlag("manualMints")) {
833
+ if (hasFlag('manualMints')) {
794
834
  backfiller.manualMint();
795
835
  }
796
- if (hasFlag("loans") ||
797
- hasFlag("vaultOutflows") ||
798
- hasFlag("emissions") ||
799
- hasFlag("buyBurnUSDCInflow") ||
800
- hasFlag("manualMints")) {
836
+ if (hasFlag('loans') ||
837
+ hasFlag('vaultOutflows') ||
838
+ hasFlag('emissions') ||
839
+ hasFlag('buyBurnUSDCInflow') ||
840
+ hasFlag('manualMints')) {
801
841
  await backfiller.run();
802
842
  }
803
843
  else {
804
- console.log("No operations specified. Available flags: --loans, --vaultOutflows, --emissions, --buyBurnUSDCInflow, --manualMints, --dryRun");
844
+ console.log('No operations specified. Available flags: --loans, --vaultOutflows, --emissions, --buyBurnUSDCInflow, --manualMints, --dryRun');
805
845
  }
806
846
  }
807
847
  if (require.main === module) {