@ercworldio/blockchain-shared 1.0.0-dev.25 → 1.0.0-dev.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/services/BalanceService.d.ts +5 -1
- package/build/services/BalanceService.d.ts.map +1 -1
- package/build/services/BalanceService.js +32 -11
- package/build/services/quicknode-notifications/QnNotificationsApi.d.ts +3 -1
- package/build/services/quicknode-notifications/QnNotificationsApi.d.ts.map +1 -1
- package/build/services/quicknode-notifications/QnNotificationsApi.js +6 -0
- package/build/services/quicknode-notifications/QnWebhookAddressManager.d.ts +0 -2
- package/build/services/quicknode-notifications/QnWebhookAddressManager.d.ts.map +1 -1
- package/build/services/quicknode-notifications/QnWebhookAddressManager.js +3 -46
- package/build/services/quicknode-notifications/SetupNotifications.js +1 -1
- package/package.json +1 -1
|
@@ -15,7 +15,11 @@ declare class BalanceService extends BaseErrors {
|
|
|
15
15
|
private config;
|
|
16
16
|
private logger;
|
|
17
17
|
constructor(dbPool: IDatabasePool, config: IConfig);
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Creates the balance row with zero balance if it doesnt exist.
|
|
20
|
+
* Used for wallets that were partially initialized
|
|
21
|
+
*/
|
|
22
|
+
private getOrCreateEntity;
|
|
19
23
|
getBalance(userId: number, blockchain: string, chainId: ChainId, paymentToken: string): Promise<GetWalletBalanceResult>;
|
|
20
24
|
getBalancesNeedSweepByToken(blockchain: BlockchainType, chainId: ChainId, paymentToken: string): Promise<DepositWalletBalance[]>;
|
|
21
25
|
removeWalletBalances(walletId: number, blockchain: string): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BalanceService.d.ts","sourceRoot":"","sources":["../../src/services/BalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAgB,OAAO,EAAgB,WAAW,EAAE,cAAc,EAAE,M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.logger = (0, Logger_1.createLogger)(`BalanceService`, this.config.pipelineConfig.azureAppName);
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Creates the balance row with zero balance if it doesnt exist.
|
|
33
|
+
* Used for wallets that were partially initialized
|
|
34
|
+
*/
|
|
35
|
+
getOrCreateEntity(userId, blockchain, chainId, paymentToken) {
|
|
32
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a, _b;
|
|
33
38
|
const dbDriver = this.dbPool;
|
|
34
39
|
if (!dbDriver.balancesRepo || !dbDriver.accountsRepo) {
|
|
35
40
|
throw new Error(`Db Driver appDataSource is not initialized.`);
|
|
36
41
|
}
|
|
37
42
|
const accountsService = new DepositAddressService_1.default(this.dbPool);
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
43
|
+
const account = yield accountsService.findByUserId(userId, blockchain);
|
|
44
|
+
if (!account) {
|
|
40
45
|
throw new Error(`Account not found for userId ${userId} on ${blockchain} chain`);
|
|
41
46
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
47
|
+
const normalizedToken = (0, Wallets_1.normalizeAddress)(paymentToken, blockchain);
|
|
48
|
+
const existing = yield dbDriver.balancesRepo.findOne({
|
|
49
|
+
where: { blockchain, chain_id: chainId, wallet_id: account.id, token: normalizedToken }
|
|
44
50
|
});
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
if (existing)
|
|
52
|
+
return existing;
|
|
53
|
+
// Entity is missing, wallet initialization was probably interrupted
|
|
54
|
+
// Create it with zero balance so the update doesnt fail
|
|
55
|
+
const chainManager = ChainManager_1.default.getInstance(this.config);
|
|
56
|
+
const tokenConfig = (_a = chainManager.getPaymentTokensForChain(parseInt(chainId))) === null || _a === void 0 ? void 0 : _a.find(t => (0, Wallets_1.normalizeAddress)(t.address, blockchain) === normalizedToken);
|
|
57
|
+
this.logger.warn(`Balance entity missing for userId=${userId} blockchain=${blockchain} chainId=${chainId} token=${normalizedToken} — creating with zero balance`);
|
|
58
|
+
const entity = new DepositWalletBalance_1.DepositWalletBalance();
|
|
59
|
+
entity.blockchain = blockchain;
|
|
60
|
+
entity.chain_id = chainId;
|
|
61
|
+
entity.wallet_id = account.id;
|
|
62
|
+
entity.token = normalizedToken;
|
|
63
|
+
entity.decimals = (_b = tokenConfig === null || tokenConfig === void 0 ? void 0 : tokenConfig.decimals) !== null && _b !== void 0 ? _b : 0;
|
|
64
|
+
entity.balance = BigInt(0);
|
|
65
|
+
entity.transaction_count = 0;
|
|
66
|
+
entity.needs_sweep = false;
|
|
67
|
+
entity.created_at = new Date();
|
|
68
|
+
entity.updated_at = new Date();
|
|
69
|
+
return dbDriver.balancesRepo.save(entity);
|
|
49
70
|
});
|
|
50
71
|
}
|
|
51
72
|
// Gets the token balance of the wallet on the given chain
|
|
@@ -212,7 +233,7 @@ class BalanceService extends errors_1.default {
|
|
|
212
233
|
for (const wallet of walletMap.values()) {
|
|
213
234
|
const { balance: currentBalance, decimals } = yield (0, custodial_1.getWalletBalance)(wallet.blockchain, wallet.chainId, wallet.depositWallet, wallet.tokenAddress, this.dbPool, this.config);
|
|
214
235
|
// Load entity from DB
|
|
215
|
-
const entity = yield this.
|
|
236
|
+
const entity = yield this.getOrCreateEntity(wallet.userId, wallet.blockchain, wallet.chainId, wallet.tokenAddress);
|
|
216
237
|
// Update balance
|
|
217
238
|
entity.balance = currentBalance;
|
|
218
239
|
// Optional: check sweep thresholds (reuse your current logic)
|
|
@@ -265,7 +286,7 @@ class BalanceService extends errors_1.default {
|
|
|
265
286
|
if (!account) {
|
|
266
287
|
throw new Error(`Account not found for userId ${userId} on ${blockchain} chain`);
|
|
267
288
|
}
|
|
268
|
-
const entity = yield this.
|
|
289
|
+
const entity = yield this.getOrCreateEntity(userId, blockchain, chainId, paymentToken);
|
|
269
290
|
let needs_sweep = false;
|
|
270
291
|
switch (operationType) {
|
|
271
292
|
case "add":
|
|
@@ -3,11 +3,13 @@ import { IConfig } from "../../interfaces/config";
|
|
|
3
3
|
import BaseErrors from "../../errors/errors";
|
|
4
4
|
import { RateLimiterOptions } from "../../utils/AsyncRateLimiter";
|
|
5
5
|
declare class QnNotificationsApi extends BaseErrors {
|
|
6
|
+
private static instance;
|
|
6
7
|
private api_key;
|
|
7
8
|
private base_url;
|
|
8
9
|
private rate_limiter;
|
|
9
10
|
private rlc;
|
|
10
|
-
constructor(
|
|
11
|
+
private constructor();
|
|
12
|
+
static getInstance(config: IConfig, rlc?: RateLimiterOptions): QnNotificationsApi;
|
|
11
13
|
create_webhook(template: string, name: string, network: string, webhook_url: string, initial_addresses: string[]): Promise<QnNotificationCreateResponse>;
|
|
12
14
|
get_all_webhooks(): Promise<QnNotificationListResponse>;
|
|
13
15
|
update_webhook_addresses(webhook_id: string, template: string, all_addresses: string[]): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QnNotificationsApi.d.ts","sourceRoot":"","sources":["../../../src/services/quicknode-notifications/QnNotificationsApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAyB,EAAE,kBAAkB,EAAa,MAAM,8BAA8B,CAAC;AAE/F,cAAM,kBAAmB,SAAQ,UAAU;IACvC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAgD;IAChE,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,GAAG,CAA6D;
|
|
1
|
+
{"version":3,"file":"QnNotificationsApi.d.ts","sourceRoot":"","sources":["../../../src/services/quicknode-notifications/QnNotificationsApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAyB,EAAE,kBAAkB,EAAa,MAAM,8BAA8B,CAAC;AAE/F,cAAM,kBAAmB,SAAQ,UAAU;IACvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAC5C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAgD;IAChE,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,GAAG,CAA6D;IAExE,OAAO;IAWP,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,kBAAkB,GAAG,kBAAkB;IAOpE,cAAc,CACvB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,MAAM,EAAE,GAC5B,OAAO,CAAC,4BAA4B,CAAC;IAY3B,gBAAgB,IAAI,OAAO,CAAC,0BAA0B,CAAC;IAIvD,wBAAwB,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,IAAI,CAAC;IAQH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIhD,IAAI;CAsCrB;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -60,6 +60,12 @@ class QnNotificationsApi extends errors_1.default {
|
|
|
60
60
|
}
|
|
61
61
|
this.rate_limiter = new AsyncRateLimiter_1.default(this.rlc);
|
|
62
62
|
}
|
|
63
|
+
static getInstance(config, rlc) {
|
|
64
|
+
if (!this.instance) {
|
|
65
|
+
this.instance = new QnNotificationsApi(config, rlc);
|
|
66
|
+
}
|
|
67
|
+
return this.instance;
|
|
68
|
+
}
|
|
63
69
|
create_webhook(template, name, network, webhook_url, initial_addresses) {
|
|
64
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
71
|
const template_arg_key = template === 'solanaWalletFilter' ? 'accounts' : 'wallets';
|
|
@@ -6,8 +6,6 @@ declare class QnWebhookAddressManager {
|
|
|
6
6
|
private api;
|
|
7
7
|
private config;
|
|
8
8
|
private cache;
|
|
9
|
-
private limiter;
|
|
10
|
-
private rlc;
|
|
11
9
|
private constructor();
|
|
12
10
|
static getInstance(config: IConfig, rlc?: RateLimiterOptions): QnWebhookAddressManager;
|
|
13
11
|
private get_blockchain_for_chain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QnWebhookAddressManager.d.ts","sourceRoot":"","sources":["../../../src/services/quicknode-notifications/QnWebhookAddressManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAiB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,
|
|
1
|
+
{"version":3,"file":"QnWebhookAddressManager.d.ts","sourceRoot":"","sources":["../../../src/services/quicknode-notifications/QnWebhookAddressManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,OAAO,EAAiB,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA0BlE,cAAM,uBAAuB;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA0B;IACjD,OAAO,CAAC,GAAG,CAAqB;IAChC,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,KAAK,CAAmD;IAEhE,OAAO;IAKP,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,kBAAkB,GAAG,uBAAuB;IAOtF,OAAO,CAAC,wBAAwB;IAKhC,yFAAyF;IACzF,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,QAAQ;YAMF,IAAI;YAuCJ,aAAa;IAO3B,OAAO,CAAC,WAAW;IAIN,WAAW,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiB1E,cAAc,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAiB1F;;;;OAIG;IACU,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBvF;;;;OAIG;IACU,yBAAyB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuB5F;;;;OAIG;IACU,qBAAqB,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBzH;;;;OAIG;IACU,0BAA0B,CAAC,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBjI;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -45,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
13
|
};
|
|
47
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
const AsyncRateLimiter_1 = __importStar(require("../../utils/AsyncRateLimiter"));
|
|
49
15
|
const ChainManager_1 = __importDefault(require("../ChainManager"));
|
|
50
16
|
const QnNotificationsApi_1 = __importDefault(require("./QnNotificationsApi"));
|
|
51
17
|
const CACHE_TTL_MS = 10 * 60 * 1000; // 10 minutes
|
|
@@ -53,15 +19,7 @@ class QnWebhookAddressManager {
|
|
|
53
19
|
constructor(config, rlc) {
|
|
54
20
|
this.cache = new Map();
|
|
55
21
|
this.config = config;
|
|
56
|
-
this.api =
|
|
57
|
-
if (rlc) {
|
|
58
|
-
this.rlc = rlc;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.rlc = { maxConcurrent: 1, minDelayMs: 1000 };
|
|
62
|
-
}
|
|
63
|
-
;
|
|
64
|
-
this.limiter = new AsyncRateLimiter_1.default(this.rlc);
|
|
22
|
+
this.api = QnNotificationsApi_1.default.getInstance(config, rlc);
|
|
65
23
|
}
|
|
66
24
|
static getInstance(config, rlc) {
|
|
67
25
|
if (!this.instance) {
|
|
@@ -268,7 +226,7 @@ class QnWebhookAddressManager {
|
|
|
268
226
|
continue;
|
|
269
227
|
entry.address_set.add(address);
|
|
270
228
|
try {
|
|
271
|
-
yield this.
|
|
229
|
+
yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
|
|
272
230
|
console.log(`QnWebhookAddressManager: Synced add ${address} to ${entry.name} webhook`);
|
|
273
231
|
}
|
|
274
232
|
catch (error) {
|
|
@@ -293,8 +251,7 @@ class QnWebhookAddressManager {
|
|
|
293
251
|
continue;
|
|
294
252
|
entry.address_set.delete(address);
|
|
295
253
|
try {
|
|
296
|
-
|
|
297
|
-
yield this.limiter.execute(() => (0, AsyncRateLimiter_1.withRetry)(() => __awaiter(this, void 0, void 0, function* () { return yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set)); }), 3, 500));
|
|
254
|
+
yield this.api.update_webhook_addresses(entry.webhook_id, entry.template, Array.from(entry.address_set));
|
|
298
255
|
console.log(`QnWebhookAddressManager: Synced remove ${address} from ${entry.name} webhook`);
|
|
299
256
|
}
|
|
300
257
|
catch (error) {
|
|
@@ -30,7 +30,7 @@ class SetupNotifications extends errors_1.default {
|
|
|
30
30
|
this.pending_configs = new Map();
|
|
31
31
|
this.config = config;
|
|
32
32
|
this.db = db;
|
|
33
|
-
this.api =
|
|
33
|
+
this.api = QnNotificationsApi_1.default.getInstance(config, rlc);
|
|
34
34
|
}
|
|
35
35
|
static getInstance(config, db, rlc) {
|
|
36
36
|
if (!this.instance) {
|