@xyo-network/chain-bridge 1.20.21 → 1.20.22
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/dist/node/BridgeActor.d.ts +2 -0
- package/dist/node/BridgeActor.d.ts.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.mjs +171 -7
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/monitoring/createBalanceMonitor.d.ts +21 -0
- package/dist/node/monitoring/createBalanceMonitor.d.ts.map +1 -0
- package/dist/node/monitoring/createQueueMetrics.d.ts +13 -0
- package/dist/node/monitoring/createQueueMetrics.d.ts.map +1 -0
- package/dist/node/monitoring/index.d.ts +3 -0
- package/dist/node/monitoring/index.d.ts.map +1 -0
- package/dist/node/server/server.d.ts +7 -1
- package/dist/node/server/server.d.ts.map +1 -1
- package/package.json +18 -18
|
@@ -6,6 +6,8 @@ export type BridgeActorParams = ActorParamsV3<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export declare class BridgeActor extends ActorV3<BridgeActorParams> {
|
|
8
8
|
protected _gatewayRunner: XyoGatewayRunner;
|
|
9
|
+
private _balanceMonitor?;
|
|
10
|
+
private _queueMetrics?;
|
|
9
11
|
private server?;
|
|
10
12
|
protected get gatewayRunner(): XyoGatewayRunner;
|
|
11
13
|
createHandler(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BridgeActor.d.ts","sourceRoot":"","sources":["../../src/BridgeActor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,OAAO,EAER,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"BridgeActor.d.ts","sourceRoot":"","sources":["../../src/BridgeActor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,OAAO,EAER,MAAM,sBAAsB,CAAA;AAO7B,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;IAC5C,MAAM,EAAE,YAAY,CAAA;CACrB,CAAC,CAAA;AAEF,qBACa,WAAY,SAAQ,OAAO,CAAC,iBAAiB,CAAC;IACzD,SAAS,CAAC,cAAc,EAAG,gBAAgB,CAAA;IAC3C,OAAO,CAAC,eAAe,CAAC,CAAsB;IAC9C,OAAO,CAAC,aAAa,CAAC,CAAoB;IAC1C,OAAO,CAAC,MAAM,CAAC,CAAQ;IAEvB,SAAS,KAAK,aAAa,qBAE1B;IAEc,aAAa;IAKb,YAAY;IAMZ,WAAW;YASZ,WAAW;IA0BzB,OAAO,CAAC,UAAU;CAInB"}
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,uBAAuB,CAAA"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -6,10 +6,138 @@ import { creatable } from "@xylabs/sdk-js";
|
|
|
6
6
|
import { asBridgeConfigContext } from "@xyo-network/chain-orchestration";
|
|
7
7
|
import { ActorV3, XyoGatewayRunnerMoniker } from "@xyo-network/xl1-sdk";
|
|
8
8
|
|
|
9
|
-
// src/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// src/monitoring/createBalanceMonitor.ts
|
|
10
|
+
var DEFAULT_INTERVAL_MS = 6e4;
|
|
11
|
+
var WEI_PER_GWEI = 10n ** 9n;
|
|
12
|
+
var TOKEN_DECIMALS = 10n ** 18n;
|
|
13
|
+
function createBalanceMonitor(config) {
|
|
14
|
+
const { account, bridge, bridgeableToken, gateway, meter, provider, wallet, intervalMs = DEFAULT_INTERVAL_MS } = config;
|
|
15
|
+
let timer;
|
|
16
|
+
const ethWalletGasBalance = meter.createGauge("bridge_eth_wallet_gas_balance_gwei", {
|
|
17
|
+
description: "ETH balance of the bridge runner wallet (in gwei)",
|
|
18
|
+
unit: "gwei"
|
|
19
|
+
});
|
|
20
|
+
const liquidityTokenBalance = meter.createGauge("bridge_eth_liquidity_token_balance", {
|
|
21
|
+
description: "ERC-20 token balance of the liquidity source (in whole tokens)",
|
|
22
|
+
unit: "tokens"
|
|
23
|
+
});
|
|
24
|
+
const liquidityTokenAllowance = meter.createGauge("bridge_eth_liquidity_token_allowance", {
|
|
25
|
+
description: "ERC-20 token allowance from liquidity source to bridge contract (in whole tokens)",
|
|
26
|
+
unit: "tokens"
|
|
27
|
+
});
|
|
28
|
+
const xl1AccountBalance = meter.createGauge("bridge_xl1_account_balance", {
|
|
29
|
+
description: "XL1 native balance of the bridge account (in whole XL1)",
|
|
30
|
+
unit: "xl1"
|
|
31
|
+
});
|
|
32
|
+
const walletAddress = wallet.address;
|
|
33
|
+
async function poll() {
|
|
34
|
+
try {
|
|
35
|
+
const balance = await provider.getBalance(walletAddress);
|
|
36
|
+
ethWalletGasBalance.record(Number(balance / WEI_PER_GWEI), {
|
|
37
|
+
address: walletAddress
|
|
38
|
+
});
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error("[BalanceMonitor] Failed to read ETH wallet gas balance:", err);
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
44
|
+
const balance = await bridgeableToken.balanceOf(liquiditySourceAddress);
|
|
45
|
+
liquidityTokenBalance.record(Number(balance / TOKEN_DECIMALS), {
|
|
46
|
+
address: liquiditySourceAddress
|
|
47
|
+
});
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error("[BalanceMonitor] Failed to read liquidity source token balance:", err);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
53
|
+
const bridgeAddress = await bridge.getAddress();
|
|
54
|
+
const allowance = await bridgeableToken.allowance(liquiditySourceAddress, bridgeAddress);
|
|
55
|
+
liquidityTokenAllowance.record(Number(allowance / TOKEN_DECIMALS), {
|
|
56
|
+
address: liquiditySourceAddress
|
|
57
|
+
});
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error("[BalanceMonitor] Failed to read liquidity source token allowance:", err);
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const viewer = gateway.connection.viewer;
|
|
63
|
+
if (viewer) {
|
|
64
|
+
const balance = await viewer.account.balance.accountBalance(account.address);
|
|
65
|
+
xl1AccountBalance.record(Number(balance / TOKEN_DECIMALS), {
|
|
66
|
+
address: account.address.toString()
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
console.error("[BalanceMonitor] Failed to read XL1 account balance:", err);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
__name(poll, "poll");
|
|
74
|
+
return {
|
|
75
|
+
start() {
|
|
76
|
+
void poll();
|
|
77
|
+
timer = setInterval(() => void poll(), intervalMs);
|
|
78
|
+
},
|
|
79
|
+
stop() {
|
|
80
|
+
if (timer) {
|
|
81
|
+
clearInterval(timer);
|
|
82
|
+
timer = void 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
__name(createBalanceMonitor, "createBalanceMonitor");
|
|
88
|
+
|
|
89
|
+
// src/monitoring/createQueueMetrics.ts
|
|
90
|
+
var DEFAULT_INTERVAL_MS2 = 3e4;
|
|
91
|
+
function createQueueMetrics(config) {
|
|
92
|
+
const { meter, queues, intervalMs = DEFAULT_INTERVAL_MS2 } = config;
|
|
93
|
+
let timer;
|
|
94
|
+
const waitingGauge = meter.createGauge("bridge_queue_waiting", {
|
|
95
|
+
description: "Number of waiting jobs in the bridge queue"
|
|
96
|
+
});
|
|
97
|
+
const activeGauge = meter.createGauge("bridge_queue_active", {
|
|
98
|
+
description: "Number of active jobs in the bridge queue"
|
|
99
|
+
});
|
|
100
|
+
const completedGauge = meter.createGauge("bridge_queue_completed", {
|
|
101
|
+
description: "Number of completed jobs in the bridge queue"
|
|
102
|
+
});
|
|
103
|
+
const failedGauge = meter.createGauge("bridge_queue_failed", {
|
|
104
|
+
description: "Number of failed jobs in the bridge queue"
|
|
105
|
+
});
|
|
106
|
+
const delayedGauge = meter.createGauge("bridge_queue_delayed", {
|
|
107
|
+
description: "Number of delayed jobs in the bridge queue"
|
|
108
|
+
});
|
|
109
|
+
async function poll() {
|
|
110
|
+
for (const [name10, queue] of Object.entries(queues)) {
|
|
111
|
+
try {
|
|
112
|
+
const counts = await queue.getJobCounts("waiting", "active", "completed", "failed", "delayed");
|
|
113
|
+
const attrs = {
|
|
114
|
+
queue_name: name10
|
|
115
|
+
};
|
|
116
|
+
waitingGauge.record(counts.waiting ?? 0, attrs);
|
|
117
|
+
activeGauge.record(counts.active ?? 0, attrs);
|
|
118
|
+
completedGauge.record(counts.completed ?? 0, attrs);
|
|
119
|
+
failedGauge.record(counts.failed ?? 0, attrs);
|
|
120
|
+
delayedGauge.record(counts.delayed ?? 0, attrs);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
console.error(`[QueueMetrics] Failed to read job counts for queue ${name10}:`, err);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
__name(poll, "poll");
|
|
127
|
+
return {
|
|
128
|
+
start() {
|
|
129
|
+
void poll();
|
|
130
|
+
timer = setInterval(() => void poll(), intervalMs);
|
|
131
|
+
},
|
|
132
|
+
stop() {
|
|
133
|
+
if (timer) {
|
|
134
|
+
clearInterval(timer);
|
|
135
|
+
timer = void 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
__name(createQueueMetrics, "createQueueMetrics");
|
|
13
141
|
|
|
14
142
|
// src/queue/connection.ts
|
|
15
143
|
import { isDefined } from "@xylabs/sdk-js";
|
|
@@ -1091,6 +1219,11 @@ var getTelemetry = /* @__PURE__ */ __name(() => {
|
|
|
1091
1219
|
return telemetry;
|
|
1092
1220
|
}, "getTelemetry");
|
|
1093
1221
|
|
|
1222
|
+
// src/server/app.ts
|
|
1223
|
+
import { standardErrors } from "@xylabs/express";
|
|
1224
|
+
import { sharedMiddleware } from "@xyo-network/chain-orchestration";
|
|
1225
|
+
import express from "express";
|
|
1226
|
+
|
|
1094
1227
|
// src/server/addFlowProducer.ts
|
|
1095
1228
|
var addFlowProducer = /* @__PURE__ */ __name((app, config) => {
|
|
1096
1229
|
const connection2 = getConnection(config);
|
|
@@ -1636,7 +1769,10 @@ var getServer = /* @__PURE__ */ __name(async (context, gateway) => {
|
|
|
1636
1769
|
addWorkers(config, services);
|
|
1637
1770
|
const server = app.listen(port, hostname, () => logger?.log(`[Bridge] Server listening at http://${hostname}:${port}`));
|
|
1638
1771
|
server.setTimeout(2e4);
|
|
1639
|
-
return
|
|
1772
|
+
return {
|
|
1773
|
+
server,
|
|
1774
|
+
services
|
|
1775
|
+
};
|
|
1640
1776
|
}, "getServer");
|
|
1641
1777
|
|
|
1642
1778
|
// src/BridgeActor.ts
|
|
@@ -1652,6 +1788,8 @@ var BridgeActor = class extends ActorV3 {
|
|
|
1652
1788
|
__name(this, "BridgeActor");
|
|
1653
1789
|
}
|
|
1654
1790
|
_gatewayRunner;
|
|
1791
|
+
_balanceMonitor;
|
|
1792
|
+
_queueMetrics;
|
|
1655
1793
|
server;
|
|
1656
1794
|
get gatewayRunner() {
|
|
1657
1795
|
return this._gatewayRunner;
|
|
@@ -1667,10 +1805,34 @@ var BridgeActor = class extends ActorV3 {
|
|
|
1667
1805
|
}
|
|
1668
1806
|
async stopHandler() {
|
|
1669
1807
|
await super.stopHandler();
|
|
1808
|
+
this._balanceMonitor?.stop();
|
|
1809
|
+
this._queueMetrics?.stop();
|
|
1810
|
+
this._balanceMonitor = void 0;
|
|
1811
|
+
this._queueMetrics = void 0;
|
|
1670
1812
|
this.stopServer();
|
|
1671
1813
|
}
|
|
1672
1814
|
async startServer() {
|
|
1673
|
-
|
|
1815
|
+
const context = asBridgeConfigContext(this.context, true);
|
|
1816
|
+
const { server, services } = await getServer(context, this._gatewayRunner);
|
|
1817
|
+
this.server = server;
|
|
1818
|
+
if (this.meter) {
|
|
1819
|
+
this._balanceMonitor = createBalanceMonitor({
|
|
1820
|
+
account: services.account,
|
|
1821
|
+
bridge: services.bridge,
|
|
1822
|
+
bridgeableToken: services.bridgeableToken,
|
|
1823
|
+
gateway: services.gateway,
|
|
1824
|
+
meter: this.meter,
|
|
1825
|
+
provider: services.provider,
|
|
1826
|
+
wallet: services.wallet
|
|
1827
|
+
});
|
|
1828
|
+
this._balanceMonitor.start();
|
|
1829
|
+
const queues = getXl1ToEthQueues(context.config);
|
|
1830
|
+
this._queueMetrics = createQueueMetrics({
|
|
1831
|
+
meter: this.meter,
|
|
1832
|
+
queues
|
|
1833
|
+
});
|
|
1834
|
+
this._queueMetrics.start();
|
|
1835
|
+
}
|
|
1674
1836
|
}
|
|
1675
1837
|
stopServer() {
|
|
1676
1838
|
this.server?.close();
|
|
@@ -1681,6 +1843,8 @@ BridgeActor = _ts_decorate([
|
|
|
1681
1843
|
creatable()
|
|
1682
1844
|
], BridgeActor);
|
|
1683
1845
|
export {
|
|
1684
|
-
BridgeActor
|
|
1846
|
+
BridgeActor,
|
|
1847
|
+
createBalanceMonitor,
|
|
1848
|
+
createQueueMetrics
|
|
1685
1849
|
};
|
|
1686
1850
|
//# sourceMappingURL=index.mjs.map
|