@render-foundation/utils 0.0.188 → 0.0.189
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/backfiller.js +932 -0
- package/lib/cjs/backfiller.js.map +1 -0
- package/lib/cjs/client/onchain.js +132 -0
- package/lib/cjs/client/onchain.js.map +1 -0
- package/lib/cjs/client/pg/base.js +198 -0
- package/lib/cjs/client/pg/base.js.map +1 -0
- package/lib/cjs/client/pg/v1.js +623 -0
- package/lib/cjs/client/pg/v1.js.map +1 -0
- package/lib/cjs/client/pg/v2Client.js +1619 -0
- package/lib/cjs/client/pg/v2Client.js.map +1 -0
- package/lib/cjs/client/pg/viewClient.js +107 -0
- package/lib/cjs/client/pg/viewClient.js.map +1 -0
- package/lib/cjs/client/price.js +63 -0
- package/lib/cjs/client/price.js.map +1 -0
- package/lib/cjs/client/render.js +173 -0
- package/lib/cjs/client/render.js.map +1 -0
- package/lib/cjs/client/squads.js +204 -0
- package/lib/cjs/client/squads.js.map +1 -0
- package/lib/cjs/client/trade.js +235 -0
- package/lib/cjs/client/trade.js.map +1 -0
- package/lib/cjs/client/wormhole.js +69 -0
- package/lib/cjs/client/wormhole.js.map +1 -0
- package/lib/cjs/constants.js +48 -0
- package/lib/cjs/constants.js.map +1 -0
- package/lib/cjs/dbTypes.js +3 -0
- package/lib/cjs/dbTypes.js.map +1 -0
- package/lib/cjs/dbTypesV2.js +3 -0
- package/lib/cjs/dbTypesV2.js.map +1 -0
- package/lib/cjs/dbViewTypes.js +3 -0
- package/lib/cjs/dbViewTypes.js.map +1 -0
- package/lib/cjs/errorReporter.js +126 -0
- package/lib/cjs/errorReporter.js.map +1 -0
- package/lib/cjs/index.js +44 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/logger.js +21 -0
- package/lib/cjs/logger.js.map +1 -0
- package/lib/esm/src/backfiller.js +886 -0
- package/lib/esm/src/backfiller.js.map +1 -0
- package/lib/esm/src/client/onchain.js +122 -0
- package/lib/esm/src/client/onchain.js.map +1 -0
- package/lib/esm/src/client/pg/base.js +162 -0
- package/lib/esm/src/client/pg/base.js.map +1 -0
- package/lib/esm/src/client/pg/v1.js +559 -0
- package/lib/esm/src/client/pg/v1.js.map +1 -0
- package/lib/esm/src/client/pg/v2Client.js +1500 -0
- package/lib/esm/src/client/pg/v2Client.js.map +1 -0
- package/lib/esm/src/client/pg/viewClient.js +91 -0
- package/lib/esm/src/client/pg/viewClient.js.map +1 -0
- package/lib/esm/src/client/price.js +41 -0
- package/lib/esm/src/client/price.js.map +1 -0
- package/lib/esm/src/client/render.js +147 -0
- package/lib/esm/src/client/render.js.map +1 -0
- package/lib/esm/src/client/squads.js +163 -0
- package/lib/esm/src/client/squads.js.map +1 -0
- package/lib/esm/src/client/trade.js +219 -0
- package/lib/esm/src/client/trade.js.map +1 -0
- package/lib/esm/src/client/wormhole.js +33 -0
- package/lib/esm/src/client/wormhole.js.map +1 -0
- package/lib/esm/src/constants.js +45 -0
- package/lib/esm/src/constants.js.map +1 -0
- package/lib/esm/src/dbTypes.js +2 -0
- package/lib/esm/src/dbTypes.js.map +1 -0
- package/lib/esm/src/dbTypesV2.js +2 -0
- package/lib/esm/src/dbTypesV2.js.map +1 -0
- package/lib/esm/src/dbViewTypes.js +2 -0
- package/lib/esm/src/dbViewTypes.js.map +1 -0
- package/lib/esm/src/errorReporter.js +117 -0
- package/lib/esm/src/errorReporter.js.map +1 -0
- package/lib/esm/src/index.js +15 -0
- package/lib/esm/src/index.js.map +1 -0
- package/lib/esm/src/logger.js +18 -0
- package/lib/esm/src/logger.js.map +1 -0
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/lib/types/src/backfiller.d.ts +64 -0
- package/lib/types/src/backfiller.d.ts.map +1 -0
- package/lib/types/src/client/onchain.d.ts +24 -0
- package/lib/types/src/client/onchain.d.ts.map +1 -0
- package/lib/types/src/client/pg/base.d.ts +82 -0
- package/lib/types/src/client/pg/base.d.ts.map +1 -0
- package/lib/types/src/client/pg/v1.d.ts +137 -0
- package/lib/types/src/client/pg/v1.d.ts.map +1 -0
- package/lib/types/src/client/pg/v2Client.d.ts +307 -0
- package/lib/types/src/client/pg/v2Client.d.ts.map +1 -0
- package/lib/types/src/client/pg/viewClient.d.ts +55 -0
- package/lib/types/src/client/pg/viewClient.d.ts.map +1 -0
- package/lib/types/src/client/price.d.ts +12 -0
- package/lib/types/src/client/price.d.ts.map +1 -0
- package/lib/types/src/client/render.d.ts +24 -0
- package/lib/types/src/client/render.d.ts.map +1 -0
- package/lib/types/src/client/squads.d.ts +17 -0
- package/lib/types/src/client/squads.d.ts.map +1 -0
- package/lib/types/src/client/trade.d.ts +24 -0
- package/lib/types/src/client/trade.d.ts.map +1 -0
- package/lib/types/src/client/wormhole.d.ts +9 -0
- package/lib/types/src/client/wormhole.d.ts.map +1 -0
- package/lib/types/src/constants.d.ts +43 -0
- package/lib/types/src/constants.d.ts.map +1 -0
- package/lib/types/src/dbTypes.d.ts +123 -0
- package/lib/types/src/dbTypes.d.ts.map +1 -0
- package/lib/types/src/dbTypesV2.d.ts +194 -0
- package/lib/types/src/dbTypesV2.d.ts.map +1 -0
- package/lib/types/src/dbViewTypes.d.ts +35 -0
- package/lib/types/src/dbViewTypes.d.ts.map +1 -0
- package/lib/types/src/errorReporter.d.ts +13 -0
- package/lib/types/src/errorReporter.d.ts.map +1 -0
- package/lib/types/src/index.d.ts +15 -0
- package/lib/types/src/index.d.ts.map +1 -0
- package/lib/types/src/logger.d.ts +16 -0
- package/lib/types/src/logger.d.ts.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,932 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Backfiller = exports.heliusClient = exports.solscanProClient = void 0;
|
|
13
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const v2Client_1 = require("./client/pg/v2Client");
|
|
16
|
+
const emission_distributor_sdk_1 = require("@render-foundation/emission-distributor-sdk");
|
|
17
|
+
const helius_sdk_1 = require("helius-sdk");
|
|
18
|
+
const solscanProClient = (apiKey) => {
|
|
19
|
+
const headers = {
|
|
20
|
+
token: apiKey,
|
|
21
|
+
};
|
|
22
|
+
const baseUrl = "https://pro-api.solscan.io/v2.0";
|
|
23
|
+
return {
|
|
24
|
+
getSignaturesForAddress(addr, options) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const allSignatures = [];
|
|
27
|
+
let before = options === null || options === void 0 ? void 0 : options.before;
|
|
28
|
+
const limit = Math.min((options === null || options === void 0 ? void 0 : options.limit) || 40, 40);
|
|
29
|
+
while (true) {
|
|
30
|
+
const params = new URLSearchParams({
|
|
31
|
+
address: addr.toString(),
|
|
32
|
+
limit: limit.toString(),
|
|
33
|
+
});
|
|
34
|
+
if (before) {
|
|
35
|
+
params.append("before", before);
|
|
36
|
+
}
|
|
37
|
+
const endpoint = `${baseUrl}/account/transactions?${params}`;
|
|
38
|
+
const response = yield fetch(endpoint, { headers });
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`Failed to fetch signatures: ${response.statusText}`);
|
|
41
|
+
}
|
|
42
|
+
const data = yield response.json();
|
|
43
|
+
const signatures = data.data || [];
|
|
44
|
+
const transformedSigs = signatures.map((tx) => ({
|
|
45
|
+
signature: tx.txHash || tx.signature,
|
|
46
|
+
blockTime: tx.blockTime || tx.block_time || 0,
|
|
47
|
+
err: tx.status !== "Success" ? { err: tx.status } : null,
|
|
48
|
+
}));
|
|
49
|
+
allSignatures.push(...transformedSigs);
|
|
50
|
+
if (signatures.length < limit || ((options === null || options === void 0 ? void 0 : options.limit) && allSignatures.length >= options.limit)) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
// Set before to the last signature for next page
|
|
54
|
+
if (signatures.length > 0) {
|
|
55
|
+
before = signatures[signatures.length - 1].txHash || signatures[signatures.length - 1].signature;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return allSignatures.slice(0, options === null || options === void 0 ? void 0 : options.limit);
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
getParsedTransaction(signature) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const endpoint = `${baseUrl}/transaction/details?tx=${signature}`;
|
|
64
|
+
const response = yield fetch(endpoint, { headers });
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new Error(`Failed to fetch transaction: ${response.statusText}`);
|
|
67
|
+
}
|
|
68
|
+
const data = yield response.json();
|
|
69
|
+
return {
|
|
70
|
+
meta: {
|
|
71
|
+
err: data.status !== "Success" ? { err: data.status } : null,
|
|
72
|
+
logMessages: data.logMessages || [],
|
|
73
|
+
preTokenBalances: data.inputAccount || [],
|
|
74
|
+
postTokenBalances: data.outputAccount || [],
|
|
75
|
+
},
|
|
76
|
+
blockTime: data.blockTime || data.block_time || 0,
|
|
77
|
+
status: data.status,
|
|
78
|
+
err: data.status !== "Success" ? { err: data.status } : null,
|
|
79
|
+
tokenBalances: data.tokenBalances || [],
|
|
80
|
+
preTokenBalances: data.inputAccount || [],
|
|
81
|
+
postTokenBalances: data.outputAccount || [],
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
getBalanceChange(f) {
|
|
86
|
+
var _a;
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
try {
|
|
89
|
+
const allTransfers = [];
|
|
90
|
+
let page = 1;
|
|
91
|
+
const pageSize = Math.min(((_a = f.options) === null || _a === void 0 ? void 0 : _a.limit) || 100, 100);
|
|
92
|
+
while (true) {
|
|
93
|
+
const params = new URLSearchParams({
|
|
94
|
+
address: f.addr.toString(),
|
|
95
|
+
page: page.toString(),
|
|
96
|
+
page_size: pageSize.toString(),
|
|
97
|
+
});
|
|
98
|
+
if (f.mint) {
|
|
99
|
+
params.append("token", f.mint.toString());
|
|
100
|
+
}
|
|
101
|
+
if (f.flow) {
|
|
102
|
+
params.append("flow", f.flow);
|
|
103
|
+
}
|
|
104
|
+
if (f.tokenAccount) {
|
|
105
|
+
params.append("token_account", f.tokenAccount.toString());
|
|
106
|
+
}
|
|
107
|
+
const endpoint = `${baseUrl}/account/balance_change?${params}`;
|
|
108
|
+
const response = yield fetch(endpoint, { headers });
|
|
109
|
+
if (f.tokenAccount.toString() === constants_1.polyBridgeEscrow) {
|
|
110
|
+
console.log("Poly solscan response: ", JSON.stringify(response));
|
|
111
|
+
}
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
console.error(`Failed to fetch balance changes: ${response.statusText}`);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const body = yield response.json();
|
|
117
|
+
const transfers = [];
|
|
118
|
+
if (f.tokenAccount.toString() === constants_1.polyBridgeEscrow) {
|
|
119
|
+
console.log("poly solscan data: ", JSON.stringify(body));
|
|
120
|
+
}
|
|
121
|
+
for (const item of body.data || []) {
|
|
122
|
+
if (item.change_type === (f.flow === "in" ? "inc" : "dec")) {
|
|
123
|
+
transfers.push({
|
|
124
|
+
amount: Math.abs(item.amount || 0),
|
|
125
|
+
tokenDecimals: item.token_decimals || 0,
|
|
126
|
+
sig: item.trans_id,
|
|
127
|
+
blockTime: item.block_time || 0,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
allTransfers.push(...transfers);
|
|
132
|
+
if (transfers.length === 0 || transfers.length < pageSize) {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
page++;
|
|
136
|
+
}
|
|
137
|
+
return allTransfers.filter((t) => t.amount !== 0);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error("Error in getBalanceChange:", error);
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
getTransfers(f) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
try {
|
|
148
|
+
const allTransfers = [];
|
|
149
|
+
let page = 1;
|
|
150
|
+
const pageSize = Math.min(f.pageSize || 100, 100);
|
|
151
|
+
while (true) {
|
|
152
|
+
const params = new URLSearchParams({
|
|
153
|
+
address: f.addr.toString(),
|
|
154
|
+
token: f.mint.toString(),
|
|
155
|
+
flow: f.flow,
|
|
156
|
+
page: page.toString(),
|
|
157
|
+
page_size: pageSize.toString(),
|
|
158
|
+
});
|
|
159
|
+
const endpoint = `${baseUrl}/account/transfer?${params}`;
|
|
160
|
+
const response = yield fetch(endpoint, { headers });
|
|
161
|
+
if (!response.ok) {
|
|
162
|
+
throw new Error(`Failed to fetch transfers: ${response.statusText}`);
|
|
163
|
+
}
|
|
164
|
+
const body = yield response.json();
|
|
165
|
+
const transfers = [];
|
|
166
|
+
for (const item of body.data || []) {
|
|
167
|
+
transfers.push({
|
|
168
|
+
amount: item.amount || 0,
|
|
169
|
+
tokenDecimals: item.token_decimals || 0,
|
|
170
|
+
fromAddress: item.from_address ? new web3_js_1.PublicKey(item.from_address) : undefined,
|
|
171
|
+
toAddress: item.to_address ? new web3_js_1.PublicKey(item.to_address) : undefined,
|
|
172
|
+
sig: item.trans_id,
|
|
173
|
+
blockTime: item.block_time || 0,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
allTransfers.push(...transfers);
|
|
177
|
+
if (transfers.length === 0 || transfers.length < pageSize) {
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
page++;
|
|
181
|
+
}
|
|
182
|
+
return allTransfers.filter((t) => t.amount !== 0);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
console.error("Error in getTransfers:", error);
|
|
186
|
+
throw new Error(`Failed to get transfers: ${error}`);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
exports.solscanProClient = solscanProClient;
|
|
193
|
+
const heliusClient = (apiKey) => {
|
|
194
|
+
const helius = new helius_sdk_1.Helius(apiKey, "mainnet-beta");
|
|
195
|
+
return {
|
|
196
|
+
getSignaturesForAddress(addr, options) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
return helius.connection.getSignaturesForAddress(addr, {
|
|
199
|
+
before: options === null || options === void 0 ? void 0 : options.before,
|
|
200
|
+
limit: (options === null || options === void 0 ? void 0 : options.limit) || 1000,
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
getParsedTransaction(signature) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
return helius.connection.getTransaction(signature, {
|
|
207
|
+
maxSupportedTransactionVersion: 0,
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
getBalanceChange(f) {
|
|
212
|
+
var _a, _b, _c, _d;
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
try {
|
|
215
|
+
// Get transactions for the address
|
|
216
|
+
const response = yield helius.connection.getSignaturesForAddress(f.addr, {
|
|
217
|
+
limit: 100,
|
|
218
|
+
});
|
|
219
|
+
const transfers = [];
|
|
220
|
+
// Process each signature to get transaction details
|
|
221
|
+
for (const sig of response) {
|
|
222
|
+
try {
|
|
223
|
+
const tx = yield helius.connection.getTransaction(sig.signature, {
|
|
224
|
+
maxSupportedTransactionVersion: 0,
|
|
225
|
+
});
|
|
226
|
+
if (!tx || ((_a = tx.meta) === null || _a === void 0 ? void 0 : _a.err))
|
|
227
|
+
continue;
|
|
228
|
+
// Look for token balance changes
|
|
229
|
+
const preBalances = tx.meta.preTokenBalances || [];
|
|
230
|
+
const postBalances = tx.meta.postTokenBalances || [];
|
|
231
|
+
for (const postBalance of postBalances) {
|
|
232
|
+
if (postBalance.mint !== f.mint.toString())
|
|
233
|
+
continue;
|
|
234
|
+
if (postBalance.owner !== f.addr.toString())
|
|
235
|
+
continue;
|
|
236
|
+
const preBalance = preBalances.find((pre) => pre.accountIndex === postBalance.accountIndex);
|
|
237
|
+
const preAmount = Number(((_b = preBalance === null || preBalance === void 0 ? void 0 : preBalance.uiTokenAmount) === null || _b === void 0 ? void 0 : _b.amount) || 0);
|
|
238
|
+
const postAmount = Number(((_c = postBalance.uiTokenAmount) === null || _c === void 0 ? void 0 : _c.amount) || 0);
|
|
239
|
+
const change = postAmount - preAmount;
|
|
240
|
+
if (change !== 0) {
|
|
241
|
+
const isInflow = change > 0;
|
|
242
|
+
if ((f.flow === "in" && isInflow) || (f.flow === "out" && !isInflow)) {
|
|
243
|
+
transfers.push({
|
|
244
|
+
amount: Math.abs(change),
|
|
245
|
+
tokenDecimals: ((_d = postBalance.uiTokenAmount) === null || _d === void 0 ? void 0 : _d.decimals) || 0,
|
|
246
|
+
sig: sig.signature,
|
|
247
|
+
blockTime: tx.blockTime || 0,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
console.error(`Error processing signature ${sig.signature}:`, e);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return transfers.filter((t) => t.amount !== 0);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
console.error("Error in getBalanceChange:", error);
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
getTransfers(f) {
|
|
266
|
+
var _a, _b, _c, _d;
|
|
267
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
+
try {
|
|
269
|
+
// Use enhanced transactions API for better token transfer data
|
|
270
|
+
const response = yield helius.connection.getSignaturesForAddress(f.addr, {
|
|
271
|
+
limit: f.pageSize || 100,
|
|
272
|
+
});
|
|
273
|
+
const transfers = [];
|
|
274
|
+
for (const sig of response) {
|
|
275
|
+
try {
|
|
276
|
+
const tx = yield helius.connection.getTransaction(sig.signature, {
|
|
277
|
+
maxSupportedTransactionVersion: 0,
|
|
278
|
+
});
|
|
279
|
+
if (!tx || ((_a = tx.meta) === null || _a === void 0 ? void 0 : _a.err))
|
|
280
|
+
continue;
|
|
281
|
+
// Parse token transfers from transaction
|
|
282
|
+
const preTokenBalances = tx.meta.preTokenBalances || [];
|
|
283
|
+
const postTokenBalances = tx.meta.postTokenBalances || [];
|
|
284
|
+
// Group by account index to track transfers
|
|
285
|
+
const balanceChanges = new Map();
|
|
286
|
+
for (const postBalance of postTokenBalances) {
|
|
287
|
+
if (postBalance.mint !== f.mint.toString())
|
|
288
|
+
continue;
|
|
289
|
+
const preBalance = preTokenBalances.find((pre) => pre.accountIndex === postBalance.accountIndex);
|
|
290
|
+
const preAmount = Number(((_b = preBalance === null || preBalance === void 0 ? void 0 : preBalance.uiTokenAmount) === null || _b === void 0 ? void 0 : _b.amount) || 0);
|
|
291
|
+
const postAmount = Number(((_c = postBalance.uiTokenAmount) === null || _c === void 0 ? void 0 : _c.amount) || 0);
|
|
292
|
+
const change = postAmount - preAmount;
|
|
293
|
+
if (change !== 0) {
|
|
294
|
+
balanceChanges.set(postBalance.accountIndex, {
|
|
295
|
+
mint: postBalance.mint,
|
|
296
|
+
owner: postBalance.owner,
|
|
297
|
+
change,
|
|
298
|
+
decimals: ((_d = postBalance.uiTokenAmount) === null || _d === void 0 ? void 0 : _d.decimals) || 0,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Find transfers involving the target address
|
|
303
|
+
for (const [accountIndex, balanceChange] of balanceChanges) {
|
|
304
|
+
const isFromTarget = balanceChange.owner === f.addr.toString() && balanceChange.change < 0;
|
|
305
|
+
const isToTarget = balanceChange.owner === f.addr.toString() && balanceChange.change > 0;
|
|
306
|
+
if ((f.flow === "out" && isFromTarget) || (f.flow === "in" && isToTarget)) {
|
|
307
|
+
// Find the counterpart transfer
|
|
308
|
+
let fromAddress;
|
|
309
|
+
let toAddress;
|
|
310
|
+
if (isFromTarget) {
|
|
311
|
+
fromAddress = f.addr;
|
|
312
|
+
// Find who received the tokens
|
|
313
|
+
for (const [_, otherChange] of balanceChanges) {
|
|
314
|
+
if (otherChange.owner !== f.addr.toString() && otherChange.change > 0) {
|
|
315
|
+
toAddress = new web3_js_1.PublicKey(otherChange.owner);
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
toAddress = f.addr;
|
|
322
|
+
// Find who sent the tokens
|
|
323
|
+
for (const [_, otherChange] of balanceChanges) {
|
|
324
|
+
if (otherChange.owner !== f.addr.toString() && otherChange.change < 0) {
|
|
325
|
+
fromAddress = new web3_js_1.PublicKey(otherChange.owner);
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
transfers.push({
|
|
331
|
+
amount: Math.abs(balanceChange.change),
|
|
332
|
+
tokenDecimals: balanceChange.decimals,
|
|
333
|
+
fromAddress,
|
|
334
|
+
toAddress,
|
|
335
|
+
sig: sig.signature,
|
|
336
|
+
blockTime: tx.blockTime || 0,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
catch (e) {
|
|
342
|
+
console.error(`Error processing signature ${sig.signature}:`, e);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return transfers.filter((t) => t.amount !== 0);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
console.error("Error in getTransfers:", error);
|
|
349
|
+
throw new Error(`Failed to get transfers: ${error}`);
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
exports.heliusClient = heliusClient;
|
|
356
|
+
class Backfiller {
|
|
357
|
+
constructor(solscanApiKey, heliusApiKey, pg, isDryRun = false) {
|
|
358
|
+
this._types = {};
|
|
359
|
+
this._txs = [];
|
|
360
|
+
this.isDryRun = false;
|
|
361
|
+
this.solscan = { pageSize: 100 };
|
|
362
|
+
this.solscan.apiKey = solscanApiKey;
|
|
363
|
+
this.solscanClient = (0, exports.solscanProClient)(solscanApiKey);
|
|
364
|
+
this.heliusClient = (0, exports.heliusClient)(heliusApiKey);
|
|
365
|
+
this.pg = pg;
|
|
366
|
+
this.isDryRun = isDryRun;
|
|
367
|
+
}
|
|
368
|
+
emit() {
|
|
369
|
+
this._types["emit"] = {};
|
|
370
|
+
return this;
|
|
371
|
+
}
|
|
372
|
+
loans() {
|
|
373
|
+
this._types["loan"] = {};
|
|
374
|
+
return this;
|
|
375
|
+
}
|
|
376
|
+
buyBurnUSDCInflow() {
|
|
377
|
+
this._types["buyBurnUSDCInflow"] = {};
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
manualMint() {
|
|
381
|
+
this._types["manualMint"] = {};
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
renderComputeNetwork() {
|
|
385
|
+
this._types["renderComputeNetwork"] = {};
|
|
386
|
+
return this;
|
|
387
|
+
}
|
|
388
|
+
burnRENDERInflow() {
|
|
389
|
+
this._types["burnRENDERInflow"] = {};
|
|
390
|
+
return this;
|
|
391
|
+
}
|
|
392
|
+
vaultOutflows(p) {
|
|
393
|
+
this._types["vaultOutflows"] = {};
|
|
394
|
+
this.solscan.pageSize = p.pageSize || 100;
|
|
395
|
+
return this;
|
|
396
|
+
}
|
|
397
|
+
txs(...sigs) {
|
|
398
|
+
this._txs.push(...sigs);
|
|
399
|
+
}
|
|
400
|
+
formatAmount(amount, decimals = 8) {
|
|
401
|
+
const amt = typeof amount === "bigint" ? Number(amount) : amount;
|
|
402
|
+
return (amt / Math.pow(10, decimals)).toLocaleString(undefined, {
|
|
403
|
+
maximumFractionDigits: 8,
|
|
404
|
+
minimumFractionDigits: 0,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
formatTimestamp(blockTime) {
|
|
408
|
+
return new Date(blockTime * 1000).toISOString();
|
|
409
|
+
}
|
|
410
|
+
indexLoans() {
|
|
411
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
412
|
+
const trs = [
|
|
413
|
+
{
|
|
414
|
+
transfer: {
|
|
415
|
+
toSolKey: "2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC",
|
|
416
|
+
fromSolKey: constants_1.v3SquadsVault,
|
|
417
|
+
solTx: "3oC8BybX5YrkfPyvV8rAE1tnJr6egtZFHLghqHuLi3eaT4aWm87qZPJFrjFRn6nwVemd2ponsew85tBs6VVQzTJv",
|
|
418
|
+
executedAt: new Date("December 22, 2023 04:13:58 UTC"),
|
|
419
|
+
symbol: "RENDER",
|
|
420
|
+
channel: "loan",
|
|
421
|
+
amountPayed: BigInt(44999 * Math.pow(10, 8)),
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
transfer: {
|
|
426
|
+
toSolKey: "2P2gisXpbsYEUsTDQKdcDKSg1UZvx7qxfLTkvJGZdeJC",
|
|
427
|
+
fromSolKey: constants_1.v3SquadsVault,
|
|
428
|
+
channel: "loan",
|
|
429
|
+
solTx: "2f5sEBHcP8wpF79voUEUiP8pryDt7FvqrTXQrEpXzAxbzyFYPkavZGtJc5N8CXhfbJav8hQTr9YcENKseiouaWzc",
|
|
430
|
+
executedAt: new Date("December 22, 2023 02:39:53 UTC"),
|
|
431
|
+
symbol: "RENDER",
|
|
432
|
+
amountPayed: BigInt(1 * Math.pow(10, 8)),
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
transfer: {
|
|
437
|
+
toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
|
|
438
|
+
fromSolKey: constants_1.v3SquadsVault,
|
|
439
|
+
channel: "loan",
|
|
440
|
+
solTx: "42n55BZcKVBCSZQoaneBQLn57v7zZGZorGe3uBLheGu4BQtpaTChdT1z3vHwgU4MHghJw3wJ72rFLkib761ewJCj",
|
|
441
|
+
executedAt: new Date("January 12, 2024 00:17:02 UTC"),
|
|
442
|
+
symbol: "RENDER",
|
|
443
|
+
amountPayed: BigInt(1 * Math.pow(10, 8)),
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
transfer: {
|
|
448
|
+
toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
|
|
449
|
+
fromSolKey: constants_1.v3SquadsVault,
|
|
450
|
+
channel: "loan",
|
|
451
|
+
solTx: "THJLvA1UTqH22hNP7Ecnfn4iY736VJAZ8scgSUjrDDaGpSQJmGYKJYXGtDu6TB96fKo6mJBtUBZvLb4ors17JUR",
|
|
452
|
+
executedAt: new Date("January 17, 2024 22:09:58 UTC"),
|
|
453
|
+
symbol: "RENDER",
|
|
454
|
+
amountPayed: BigInt(49999 * Math.pow(10, 8)),
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
transfer: {
|
|
459
|
+
toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
|
|
460
|
+
fromSolKey: constants_1.devsSquadsVault,
|
|
461
|
+
channel: "loan",
|
|
462
|
+
solTx: "5BcxrMExq34jtMB5c3bH3A8TN4pCp9sxjC5HMcS7Mh8pig3r2eQhvRnJeE1RBTyQ4JDXyANWmDU9SKdYFyT2wDoq",
|
|
463
|
+
executedAt: new Date("February 28, 2024 22:43:21 UTC"),
|
|
464
|
+
symbol: "RENDER",
|
|
465
|
+
amountPayed: BigInt(1 * Math.pow(10, 8)),
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
transfer: {
|
|
470
|
+
toSolKey: "5DGbogKUo8haEYC9Tt4FTHE5ue55bjLC4DpSgE1g6yT1",
|
|
471
|
+
fromSolKey: constants_1.devsSquadsVault,
|
|
472
|
+
channel: "loan",
|
|
473
|
+
solTx: "5E4E35CT4e3fhbMAwcKdfAvJL4uUHR8hHE8REmKnDCEsFZ6mxaE1YyeYK8Sbg5AJqBJxsZkcYSohY8T14YLC5pXs",
|
|
474
|
+
executedAt: new Date("February 29, 2024 01:17:51 UTC"),
|
|
475
|
+
symbol: "RENDER",
|
|
476
|
+
amountPayed: BigInt(199999 * Math.pow(10, 8)),
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
];
|
|
480
|
+
if (this.isDryRun) {
|
|
481
|
+
for (const t of trs) {
|
|
482
|
+
const amount = this.formatAmount(t.transfer.amountPayed);
|
|
483
|
+
const timestamp = this.formatTimestamp(t.transfer.executedAt.getTime() / 1000);
|
|
484
|
+
console.log(`${t.transfer.solTx} | ${timestamp} | ${t.transfer.channel} | ${t.transfer.fromSolKey} -> ${t.transfer.toSolKey} | ${amount} ${t.transfer.symbol}`);
|
|
485
|
+
}
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
for (const t of trs) {
|
|
489
|
+
try {
|
|
490
|
+
yield this.pg.createPayments(this.pg.db, [t]);
|
|
491
|
+
}
|
|
492
|
+
catch (e) {
|
|
493
|
+
console.log(`except ${e}`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
findEmitTxs() {
|
|
499
|
+
var _a, _b;
|
|
500
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
501
|
+
const fetchSigs = (ads) => __awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
const uniqSigs = {};
|
|
503
|
+
const sigsAgg = [];
|
|
504
|
+
for (const ad of ads) {
|
|
505
|
+
const sigs = [];
|
|
506
|
+
while (true) {
|
|
507
|
+
const sigsBatch = yield this.heliusClient.getSignaturesForAddress(ad, {
|
|
508
|
+
before: sigs.length > 0 ? sigs[sigs.length - 1].signature : undefined,
|
|
509
|
+
limit: 1000,
|
|
510
|
+
});
|
|
511
|
+
sigs.push(...sigsBatch.filter((s) => !uniqSigs[s.signature]));
|
|
512
|
+
for (const s of sigsBatch) {
|
|
513
|
+
uniqSigs[s.signature] = true;
|
|
514
|
+
}
|
|
515
|
+
if (sigsBatch.length < 1000) {
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (!this.isDryRun) {
|
|
520
|
+
console.log(`fetched ${sigs.length} sigs for ${ad}`);
|
|
521
|
+
}
|
|
522
|
+
sigsAgg.push(...sigs);
|
|
523
|
+
}
|
|
524
|
+
sigsAgg.sort((a, b) => b.blockTime - a.blockTime);
|
|
525
|
+
return sigsAgg;
|
|
526
|
+
});
|
|
527
|
+
const sigs = yield fetchSigs([
|
|
528
|
+
(0, emission_distributor_sdk_1.emissionDistributorKey)(new web3_js_1.PublicKey(constants_1.renderMint))[0],
|
|
529
|
+
(0, emission_distributor_sdk_1.emissionDistributorV1Key)(new web3_js_1.PublicKey(constants_1.renderMint))[0],
|
|
530
|
+
]);
|
|
531
|
+
if (!this.isDryRun) {
|
|
532
|
+
console.log(`sigs ${sigs.length}`);
|
|
533
|
+
}
|
|
534
|
+
let proced = 0;
|
|
535
|
+
const out = [];
|
|
536
|
+
for (const s of sigs) {
|
|
537
|
+
const p = yield this.heliusClient.getParsedTransaction(s.signature);
|
|
538
|
+
if (((_a = p === null || p === void 0 ? void 0 : p.meta) === null || _a === void 0 ? void 0 : _a.err) || (p === null || p === void 0 ? void 0 : p.err)) {
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
const logMessages = ((_b = p === null || p === void 0 ? void 0 : p.meta) === null || _b === void 0 ? void 0 : _b.logMessages) || [];
|
|
542
|
+
for (const l of logMessages) {
|
|
543
|
+
if (l.includes('DistributeEmissionsV0') ||
|
|
544
|
+
l.includes('DistributeEmissionsV1')) {
|
|
545
|
+
out.push(s.signature);
|
|
546
|
+
if (this.isDryRun) {
|
|
547
|
+
console.log(`${s.signature} | ${this.formatTimestamp(s.blockTime)} | emission | Emission Distributor -> Various Recipients | N/A RENDER`);
|
|
548
|
+
}
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
proced += 1;
|
|
553
|
+
if (proced % 10 == 0 && !this.isDryRun) {
|
|
554
|
+
console.log(`proced ${proced}`);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
console.log(`emit txs: ${out.length}`);
|
|
558
|
+
return out;
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
indexTxs(txs, channel, reindexTx = false, deleteFailed = false, mints = [constants_1.renderMint, constants_1.usdcMint], senders = [
|
|
562
|
+
constants_1.passthruEscrow,
|
|
563
|
+
constants_1.v3SquadsVault,
|
|
564
|
+
constants_1.upgradeRewardsEscrow,
|
|
565
|
+
constants_1.upgradeRewardsCircuitBreaker,
|
|
566
|
+
constants_1.renderMint,
|
|
567
|
+
], assertSender = '') {
|
|
568
|
+
var _a, _b, _c, _d, _e;
|
|
569
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
570
|
+
let proced = 0;
|
|
571
|
+
console.log(`processing ${txs.length} txs`);
|
|
572
|
+
const insertedIds = [];
|
|
573
|
+
for (const solTx of txs) {
|
|
574
|
+
if (solTx == '') {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
console.log(`solTx ${solTx}`);
|
|
578
|
+
const tx = yield this.heliusClient.getParsedTransaction(solTx);
|
|
579
|
+
if (!tx || (tx.status !== 'Success' && tx.err)) {
|
|
580
|
+
if (this.isDryRun) {
|
|
581
|
+
console.log(`Would delete failed transaction ${solTx} from database`);
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
console.log(`shouldnt exist ${solTx} in db. deleting`);
|
|
585
|
+
try {
|
|
586
|
+
const res = yield this.pg.db.trx.deleteFrom('sol_tx')
|
|
587
|
+
.where('sig', '=', solTx)
|
|
588
|
+
.execute();
|
|
589
|
+
console.log(`deleted ${res.length > 0 ? res[0].numDeletedRows || 0 : 0} tx`);
|
|
590
|
+
}
|
|
591
|
+
catch (e) {
|
|
592
|
+
console.log(`failed to delete tx ${solTx}: ${e}`);
|
|
593
|
+
}
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
const onchain = {};
|
|
597
|
+
const tokenBalances = ((_a = tx.meta) === null || _a === void 0 ? void 0 : _a.tokenBalances) || [];
|
|
598
|
+
const preTokenBalances = ((_b = tx.meta) === null || _b === void 0 ? void 0 : _b.preTokenBalances) || [];
|
|
599
|
+
const postTokenBalances = ((_c = tx.meta) === null || _c === void 0 ? void 0 : _c.postTokenBalances) || [];
|
|
600
|
+
for (const balance of postTokenBalances) {
|
|
601
|
+
const mint = mints.find((m) => balance.mint === m);
|
|
602
|
+
if (mint) {
|
|
603
|
+
const amt = Number(((_d = balance.uiTokenAmount) === null || _d === void 0 ? void 0 : _d.amount) || balance.amount || 0);
|
|
604
|
+
onchain[balance.owner] = { mint, amt };
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
let sender = '';
|
|
608
|
+
for (const balance of preTokenBalances) {
|
|
609
|
+
const mint = mints.find((m) => balance.mint === m);
|
|
610
|
+
if (mint) {
|
|
611
|
+
const amt = Number(((_e = balance.uiTokenAmount) === null || _e === void 0 ? void 0 : _e.amount) || balance.amount || 0);
|
|
612
|
+
if (onchain[balance.owner]) {
|
|
613
|
+
onchain[balance.owner] = {
|
|
614
|
+
mint,
|
|
615
|
+
amt: onchain[balance.owner].amt - amt,
|
|
616
|
+
};
|
|
617
|
+
if (onchain[balance.owner].amt < 0) {
|
|
618
|
+
const foundSender = senders.find((s) => s === balance.owner.toString());
|
|
619
|
+
if (!foundSender) {
|
|
620
|
+
throw new Error(`sender ${balance.owner} not in expected senders ${senders}`);
|
|
621
|
+
}
|
|
622
|
+
if (assertSender !== '' && foundSender !== assertSender) {
|
|
623
|
+
throw new Error(`assert sender ${balance.owner} != ${assertSender}`);
|
|
624
|
+
}
|
|
625
|
+
sender = foundSender;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (channel === 'emit') {
|
|
631
|
+
sender = constants_1.renderMint;
|
|
632
|
+
}
|
|
633
|
+
if (!sender) {
|
|
634
|
+
console.log(`no matching sender found`);
|
|
635
|
+
}
|
|
636
|
+
if (Object.keys(onchain).length === 0) {
|
|
637
|
+
console.log(`skipping ${solTx}. nothing to index`);
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
const result = yield this.indexTransfers(onchain, { blockTime: tx.blockTime || tx.blocktime || 0, sig: solTx }, sender, channel, reindexTx);
|
|
641
|
+
if (!this.isDryRun && result.insertedIds) {
|
|
642
|
+
insertedIds.push(...result.insertedIds);
|
|
643
|
+
}
|
|
644
|
+
if (result.stop) {
|
|
645
|
+
console.log(`stopping processing due to catch-up at tx ${solTx}`);
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
proced += 1;
|
|
649
|
+
if (proced % 10 === 0 && !this.isDryRun) {
|
|
650
|
+
console.log(`proced ${proced}`);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
console.log(`done. inserted ${insertedIds.length} transfers: ${insertedIds.join(',')}`);
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
indexTransfers(onchain, tx, sender, channel, reindexTx = false) {
|
|
657
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
+
const ents = Object.entries(onchain).filter(([k, { mint, amt }]) => amt != 0);
|
|
659
|
+
if (this.isDryRun) {
|
|
660
|
+
for (const [k, { amt, mint }] of ents) {
|
|
661
|
+
if (k == sender) {
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const symbol = (() => {
|
|
665
|
+
if (mint == constants_1.renderMint) {
|
|
666
|
+
return 'RENDER';
|
|
667
|
+
}
|
|
668
|
+
if (mint == constants_1.usdcMint) {
|
|
669
|
+
return 'USDC';
|
|
670
|
+
}
|
|
671
|
+
return 'UNKNOWN';
|
|
672
|
+
})();
|
|
673
|
+
const amount = this.formatAmount(amt);
|
|
674
|
+
const timestamp = this.formatTimestamp(tx.blockTime);
|
|
675
|
+
console.log(`would insert ${tx.sig.slice(0, 8)}... | ${timestamp} | ${channel} | ${sender} -> ${k} | ${amount} ${symbol}`);
|
|
676
|
+
}
|
|
677
|
+
return { stop: false, insertedIds: [] };
|
|
678
|
+
}
|
|
679
|
+
if (reindexTx) {
|
|
680
|
+
try {
|
|
681
|
+
const res = yield this.pg.db.trx.deleteFrom('sol_tx')
|
|
682
|
+
.where('sig', '=', tx.sig)
|
|
683
|
+
.execute();
|
|
684
|
+
console.log(`deleted ${res.length > 0 ? res[0].numDeletedRows || 0 : 0} tx`);
|
|
685
|
+
}
|
|
686
|
+
catch (e) {
|
|
687
|
+
console.log(`failed to delete tx ${tx.sig}: ${e}`);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
console.log(`diffs: ${ents.map(([k, v]) => `k ${k} v -> ${JSON.stringify(v)}`)}`);
|
|
691
|
+
const insertedIds = [];
|
|
692
|
+
for (const [k, { amt, mint }] of ents) {
|
|
693
|
+
if (k == sender) {
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
const trx = yield this.pg.startTransaction();
|
|
697
|
+
try {
|
|
698
|
+
const { inserted } = yield this.pg.createPayments(trx, [
|
|
699
|
+
{
|
|
700
|
+
transfer: {
|
|
701
|
+
fromSolKey: sender,
|
|
702
|
+
toSolKey: k,
|
|
703
|
+
symbol: (() => {
|
|
704
|
+
if (mint == constants_1.renderMint) {
|
|
705
|
+
return 'RENDER';
|
|
706
|
+
}
|
|
707
|
+
if (mint == constants_1.usdcMint) {
|
|
708
|
+
return 'USDC';
|
|
709
|
+
}
|
|
710
|
+
throw new Error(`unknown mint ${mint}`);
|
|
711
|
+
})(),
|
|
712
|
+
channel: channel,
|
|
713
|
+
solTx: tx.sig,
|
|
714
|
+
executedAt: new Date(tx.blockTime * 1000),
|
|
715
|
+
amountPayed: BigInt(amt),
|
|
716
|
+
},
|
|
717
|
+
},
|
|
718
|
+
]);
|
|
719
|
+
console.log(`inserted ${JSON.stringify(inserted)}`);
|
|
720
|
+
insertedIds.push(...inserted.map((t) => t.transferId).filter((i) => !!i));
|
|
721
|
+
trx.commit();
|
|
722
|
+
}
|
|
723
|
+
catch (e) {
|
|
724
|
+
trx.rollback();
|
|
725
|
+
if (`${e}`.includes('duplicate key value violates unique constraint')) {
|
|
726
|
+
console.log(`caught up indexing ${e}`);
|
|
727
|
+
return { stop: true, insertedIds };
|
|
728
|
+
}
|
|
729
|
+
throw e;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
console.log(`tx ${tx.sig} -> insertedIds ${insertedIds.length}`);
|
|
733
|
+
return { stop: false, insertedIds };
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
run() {
|
|
737
|
+
var _a;
|
|
738
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
739
|
+
for (const t of Object.keys(this._types)) {
|
|
740
|
+
if (t == 'emit') {
|
|
741
|
+
const txs = yield this.findEmitTxs();
|
|
742
|
+
yield this.indexTxs(txs, 'emit');
|
|
743
|
+
}
|
|
744
|
+
else if (t == 'buyBurnUSDCInflow') {
|
|
745
|
+
const trs = yield this.solscanClient.getTransfers({
|
|
746
|
+
mint: new web3_js_1.PublicKey(constants_1.usdcMint),
|
|
747
|
+
flow: 'in',
|
|
748
|
+
addr: new web3_js_1.PublicKey(constants_1.buyAndBurnEscrow),
|
|
749
|
+
});
|
|
750
|
+
for (const t of trs) {
|
|
751
|
+
if (!this.isDryRun) {
|
|
752
|
+
console.log(`buyBurnUSDCInflows: ${JSON.stringify(t)}`);
|
|
753
|
+
}
|
|
754
|
+
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');
|
|
755
|
+
if (stop) {
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
else if (t == 'manualMint') {
|
|
761
|
+
console.log(`About to fetch manual mints - renderMint: ${constants_1.renderMint}, bridgeEscrow: ${constants_1.bridgeEscrow}, isDryRun: ${this.isDryRun}`);
|
|
762
|
+
const trs = yield this.solscanClient.getBalanceChange({
|
|
763
|
+
mint: new web3_js_1.PublicKey(constants_1.renderMint),
|
|
764
|
+
addr: new web3_js_1.PublicKey('AYm4Knn6Sw1f52Eq42ujQ2ez5Xb7iBJeviprFCA7ADCy'),
|
|
765
|
+
flow: 'in',
|
|
766
|
+
tokenAccount: new web3_js_1.PublicKey(constants_1.bridgeEscrow),
|
|
767
|
+
});
|
|
768
|
+
console.log(`polyTrs result: ${trs.length} transactions`);
|
|
769
|
+
for (const t of trs) {
|
|
770
|
+
if (!this.isDryRun) {
|
|
771
|
+
console.log(`manualMints: ${JSON.stringify(t)}`);
|
|
772
|
+
}
|
|
773
|
+
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');
|
|
774
|
+
if (stop) {
|
|
775
|
+
break;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
console.log(`About to fetch poly manual mints - renderMint: ${constants_1.renderMint}, polyBridgeEscrow: ${constants_1.polyBridgeEscrow}, isDryRun: ${this.isDryRun}`);
|
|
779
|
+
// polygon bridge escrow
|
|
780
|
+
const polyTrs = yield this.solscanClient.getBalanceChange({
|
|
781
|
+
mint: new web3_js_1.PublicKey(constants_1.renderMint),
|
|
782
|
+
addr: new web3_js_1.PublicKey('E5uyafHUFpNTsiPvGmUpr8BmM1L8t1gx3g6H4Y4vraU5'),
|
|
783
|
+
flow: 'in',
|
|
784
|
+
tokenAccount: new web3_js_1.PublicKey(constants_1.polyBridgeEscrow),
|
|
785
|
+
});
|
|
786
|
+
console.log(`polyTrs result: ${polyTrs.length} transactions`);
|
|
787
|
+
for (const t of polyTrs) {
|
|
788
|
+
if (!this.isDryRun) {
|
|
789
|
+
console.log(`polyManualMints: ${JSON.stringify(t)}`);
|
|
790
|
+
}
|
|
791
|
+
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');
|
|
792
|
+
if (stop) {
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
else if (t == 'vaultOutflows') {
|
|
798
|
+
for (const addr of [constants_1.devsSquadsVault, constants_1.masterSquadsVault]) {
|
|
799
|
+
const trs = yield this.solscanClient.getTransfers({
|
|
800
|
+
mint: new web3_js_1.PublicKey(constants_1.renderMint),
|
|
801
|
+
flow: 'out',
|
|
802
|
+
addr: new web3_js_1.PublicKey(addr),
|
|
803
|
+
pageSize: this.solscan.pageSize,
|
|
804
|
+
});
|
|
805
|
+
for (const t of trs) {
|
|
806
|
+
if (!this.isDryRun) {
|
|
807
|
+
console.log(`vaultOutflow: ${JSON.stringify(t)}`);
|
|
808
|
+
}
|
|
809
|
+
const { stop } = yield this.indexTransfers({
|
|
810
|
+
[t.toAddress.toString()]: { mint: constants_1.renderMint, amt: t.amount },
|
|
811
|
+
}, { blockTime: t.blockTime, sig: t.sig }, addr, 'internal');
|
|
812
|
+
if (stop) {
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
else if (t == "loan") {
|
|
819
|
+
yield this.indexLoans();
|
|
820
|
+
}
|
|
821
|
+
else if (t == "renderComputeNetwork") {
|
|
822
|
+
const trs = yield this.solscanClient.getTransfers({
|
|
823
|
+
mint: new web3_js_1.PublicKey(constants_1.renderMint),
|
|
824
|
+
flow: "in",
|
|
825
|
+
addr: new web3_js_1.PublicKey(constants_1.renderComputeNetworkEscrow),
|
|
826
|
+
});
|
|
827
|
+
for (const t of trs) {
|
|
828
|
+
if (!this.isDryRun) {
|
|
829
|
+
console.log(`renderComputeNetwork: ${JSON.stringify(t)}`);
|
|
830
|
+
}
|
|
831
|
+
const { stop } = yield this.indexTransfers({ [constants_1.renderComputeNetworkEscrow]: { mint: constants_1.renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, t.fromAddress.toString(), "internal");
|
|
832
|
+
if (stop) {
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
else if (t == "burnRENDERInflow") {
|
|
838
|
+
const trs = yield this.solscanClient.getTransfers({
|
|
839
|
+
mint: new web3_js_1.PublicKey(constants_1.renderMint),
|
|
840
|
+
flow: "out",
|
|
841
|
+
addr: new web3_js_1.PublicKey(constants_1.devsSquadsVault),
|
|
842
|
+
});
|
|
843
|
+
for (const t of trs) {
|
|
844
|
+
if (((_a = t.toAddress) === null || _a === void 0 ? void 0 : _a.toString()) !== constants_1.buyAndBurnEscrow) {
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
if (!this.isDryRun) {
|
|
848
|
+
console.log(`burnRENDERInflow: ${JSON.stringify(t)}`);
|
|
849
|
+
}
|
|
850
|
+
const { stop } = yield this.indexTransfers({ [constants_1.buyAndBurnEscrow]: { mint: constants_1.renderMint, amt: t.amount } }, { blockTime: t.blockTime, sig: t.sig }, t.fromAddress.toString(), "internal");
|
|
851
|
+
if (stop) {
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
exports.Backfiller = Backfiller;
|
|
861
|
+
function main() {
|
|
862
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
863
|
+
const args = process.argv.slice(2);
|
|
864
|
+
const getArgValue = (argName) => {
|
|
865
|
+
const argIndex = args.indexOf(`--${argName}`);
|
|
866
|
+
return argIndex !== -1 && argIndex + 1 < args.length ? args[argIndex + 1] : undefined;
|
|
867
|
+
};
|
|
868
|
+
const hasFlag = (flagName) => {
|
|
869
|
+
return args.includes(`--${flagName}`);
|
|
870
|
+
};
|
|
871
|
+
const solscanApiKey = getArgValue("solscanApiKey");
|
|
872
|
+
if (!solscanApiKey) {
|
|
873
|
+
console.error("Error: --solscanApiKey is required");
|
|
874
|
+
process.exit(1);
|
|
875
|
+
}
|
|
876
|
+
const heliusApiKey = getArgValue("heliusApiKey");
|
|
877
|
+
if (!heliusApiKey) {
|
|
878
|
+
console.error("Error: --heliusApiKey is required");
|
|
879
|
+
process.exit(1);
|
|
880
|
+
}
|
|
881
|
+
const isDryRun = hasFlag("dryRun");
|
|
882
|
+
let pg;
|
|
883
|
+
if (!isDryRun) {
|
|
884
|
+
const pgUrl = getArgValue("pgUrl");
|
|
885
|
+
if (!pgUrl) {
|
|
886
|
+
console.error("Error: --pgUrl is required (unless using --dryRun)");
|
|
887
|
+
process.exit(1);
|
|
888
|
+
}
|
|
889
|
+
pg = (0, v2Client_1.pgClient)({
|
|
890
|
+
connectionString: pgUrl,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
const backfiller = new Backfiller(solscanApiKey, heliusApiKey, pg, isDryRun);
|
|
894
|
+
if (hasFlag("loans")) {
|
|
895
|
+
backfiller.loans();
|
|
896
|
+
}
|
|
897
|
+
if (hasFlag("vaultOutflows")) {
|
|
898
|
+
backfiller.vaultOutflows({});
|
|
899
|
+
}
|
|
900
|
+
if (hasFlag("emissions")) {
|
|
901
|
+
backfiller.emit();
|
|
902
|
+
}
|
|
903
|
+
if (hasFlag("buyBurnUSDCInflow")) {
|
|
904
|
+
backfiller.buyBurnUSDCInflow();
|
|
905
|
+
}
|
|
906
|
+
if (hasFlag("manualMints")) {
|
|
907
|
+
backfiller.manualMint();
|
|
908
|
+
}
|
|
909
|
+
if (hasFlag("renderComputeNetwork")) {
|
|
910
|
+
backfiller.renderComputeNetwork();
|
|
911
|
+
}
|
|
912
|
+
if (hasFlag("burnRENDERInflow")) {
|
|
913
|
+
backfiller.burnRENDERInflow();
|
|
914
|
+
}
|
|
915
|
+
if (hasFlag("loans") ||
|
|
916
|
+
hasFlag("vaultOutflows") ||
|
|
917
|
+
hasFlag("emissions") ||
|
|
918
|
+
hasFlag("buyBurnUSDCInflow") ||
|
|
919
|
+
hasFlag("manualMints") ||
|
|
920
|
+
hasFlag("renderComputeNetwork") ||
|
|
921
|
+
hasFlag("burnRENDERInflow")) {
|
|
922
|
+
yield backfiller.run();
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
console.log("No operations specified. Available flags: --loans, --vaultOutflows, --emissions, --buyBurnUSDCInflow, --manualMints, --renderComputeNetwork, --burnRENDERInflow, --dryRun");
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
if (require.main === module) {
|
|
930
|
+
main().catch(console.error);
|
|
931
|
+
}
|
|
932
|
+
//# sourceMappingURL=backfiller.js.map
|