@xyo-network/chain-bridge 1.19.14 → 1.19.16
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 +3 -2
- package/dist/node/BridgeActor.d.ts.map +1 -1
- package/dist/node/config/getBridgeEscrowAddress.d.ts +3 -3
- package/dist/node/config/getBridgeEscrowAddress.d.ts.map +1 -1
- package/dist/node/config/getBridgeFeesAddress.d.ts +3 -3
- package/dist/node/config/getBridgeFeesAddress.d.ts.map +1 -1
- package/dist/node/config/getBridgeSettings.d.ts +2 -2
- package/dist/node/config/getBridgeSettings.d.ts.map +1 -1
- package/dist/node/config/getBridgeWalletAccount.d.ts +3 -3
- package/dist/node/config/getBridgeWalletAccount.d.ts.map +1 -1
- package/dist/node/config/getFeeStructure.d.ts +2 -2
- package/dist/node/config/getFeeStructure.d.ts.map +1 -1
- package/dist/node/config/getGateway.d.ts +3 -2
- package/dist/node/config/getGateway.d.ts.map +1 -1
- package/dist/node/config/getMaxBridgeAmount.d.ts +2 -2
- package/dist/node/config/getMaxBridgeAmount.d.ts.map +1 -1
- package/dist/node/config/getMinBridgeAmount.d.ts +2 -2
- package/dist/node/config/getMinBridgeAmount.d.ts.map +1 -1
- package/dist/node/config/getRemoteChainId.d.ts +3 -2
- package/dist/node/config/getRemoteChainId.d.ts.map +1 -1
- package/dist/node/config/getRemoteTokenAddress.d.ts +2 -2
- package/dist/node/config/getRemoteTokenAddress.d.ts.map +1 -1
- package/dist/node/config/getTransferAddresses.d.ts +2 -2
- package/dist/node/config/getTransferAddresses.d.ts.map +1 -1
- package/dist/node/config/getXl1ChainId.d.ts +3 -2
- package/dist/node/config/getXl1ChainId.d.ts.map +1 -1
- package/dist/node/config/getXl1TokenAddress.d.ts +2 -2
- package/dist/node/config/getXl1TokenAddress.d.ts.map +1 -1
- package/dist/node/index.mjs +178 -624
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.d.ts +1 -1
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.d.ts.map +1 -1
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts +1 -2
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts +1 -2
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/queue/connection.d.ts +2 -2
- package/dist/node/queue/connection.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/util/index.d.ts +2 -0
- package/dist/node/queue/workers/util/index.d.ts.map +1 -1
- package/dist/node/queue/workers/util/validateSufficientAllowance.d.ts +19 -0
- package/dist/node/queue/workers/util/validateSufficientAllowance.d.ts.map +1 -0
- package/dist/node/queue/workers/util/validateSufficientBalance.d.ts +19 -0
- package/dist/node/queue/workers/util/validateSufficientBalance.d.ts.map +1 -0
- package/dist/node/server/addFlowProducer.d.ts +2 -2
- package/dist/node/server/addFlowProducer.d.ts.map +1 -1
- package/dist/node/server/addWorkers.d.ts +2 -2
- package/dist/node/server/addWorkers.d.ts.map +1 -1
- package/dist/node/server/app.d.ts +3 -3
- package/dist/node/server/app.d.ts.map +1 -1
- package/dist/node/server/index.d.ts +0 -2
- package/dist/node/server/index.d.ts.map +1 -1
- package/dist/node/server/routes/addRoutes.d.ts +3 -2
- package/dist/node/server/routes/addRoutes.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/addBridgeRoutes.d.ts +3 -2
- package/dist/node/server/routes/bridge/addBridgeRoutes.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts +3 -2
- package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.d.ts +2 -2
- package/dist/node/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeConfig.d.ts +2 -2
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeConfig.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.d.ts +2 -2
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts +3 -3
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts +4 -3
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts +2 -2
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts.map +1 -1
- package/dist/node/server/server.d.ts +3 -10
- package/dist/node/server/server.d.ts.map +1 -1
- package/dist/node/{manifest → services}/getIterableMap.d.ts +2 -2
- package/dist/node/services/getIterableMap.d.ts.map +1 -0
- package/dist/node/services/getServices.d.ts +9 -0
- package/dist/node/services/getServices.d.ts.map +1 -0
- package/dist/node/services/index.d.ts +1 -0
- package/dist/node/services/index.d.ts.map +1 -1
- package/dist/node/util/BridgeFees.d.ts +7 -0
- package/dist/node/util/BridgeFees.d.ts.map +1 -0
- package/dist/node/util/bridgeFeesAsBigInt.d.ts +7 -0
- package/dist/node/util/bridgeFeesAsBigInt.d.ts.map +1 -0
- package/dist/node/util/calculateBridgeFees.d.ts +4 -8
- package/dist/node/util/calculateBridgeFees.d.ts.map +1 -1
- package/dist/node/util/createBridgeTransfer.d.ts +14 -0
- package/dist/node/util/createBridgeTransfer.d.ts.map +1 -0
- package/dist/node/util/generateBridgeEstimate.d.ts +3 -2
- package/dist/node/util/generateBridgeEstimate.d.ts.map +1 -1
- package/dist/node/util/index.d.ts +3 -0
- package/dist/node/util/index.d.ts.map +1 -1
- package/dist/node/util/validateBridgeEstimate.d.ts +3 -2
- package/dist/node/util/validateBridgeEstimate.d.ts.map +1 -1
- package/dist/node/util/validateBridgeEstimateExact.d.ts +3 -2
- package/dist/node/util/validateBridgeEstimateExact.d.ts.map +1 -1
- package/dist/node/util/validateBridgeTransaction.d.ts +3 -2
- package/dist/node/util/validateBridgeTransaction.d.ts.map +1 -1
- package/package.json +46 -59
- package/src/BridgeActor.ts +3 -3
- package/src/config/getBridgeEscrowAddress.ts +5 -5
- package/src/config/getBridgeFeesAddress.ts +5 -5
- package/src/config/getBridgeSettings.ts +2 -2
- package/src/config/getBridgeWalletAccount.ts +7 -4
- package/src/config/getFeeStructure.ts +3 -3
- package/src/config/getGateway.ts +5 -4
- package/src/config/getMaxBridgeAmount.ts +3 -3
- package/src/config/getMinBridgeAmount.ts +3 -3
- package/src/config/getRemoteChainId.ts +4 -3
- package/src/config/getRemoteTokenAddress.ts +3 -3
- package/src/config/getTransferAddresses.ts +2 -2
- package/src/config/getXl1ChainId.ts +4 -3
- package/src/config/getXl1TokenAddress.ts +3 -3
- package/src/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.ts +1 -1
- package/src/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.ts +1 -1
- package/src/interface/util/getBridgeIntentIdentifier.ts +1 -1
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +2 -3
- package/src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts +2 -3
- package/src/queue/connection.ts +3 -3
- package/src/queue/workers/EthTransactionMonitor.ts +1 -1
- package/src/queue/workers/EthTransactionPreparation.ts +14 -4
- package/src/queue/workers/EthTransactionSubmission.ts +1 -1
- package/src/queue/workers/Xl1TransactionMonitor.ts +1 -1
- package/src/queue/workers/Xl1TransactionPreparation.ts +1 -1
- package/src/queue/workers/Xl1TransactionSubmission.ts +1 -1
- package/src/queue/workers/util/index.ts +2 -0
- package/src/queue/workers/util/submitEthTransaction.ts +1 -1
- package/src/queue/workers/util/validateSufficientAllowance.ts +38 -0
- package/src/queue/workers/util/validateSufficientBalance.ts +37 -0
- package/src/server/addFlowProducer.ts +2 -2
- package/src/server/addWorkers.ts +2 -2
- package/src/server/app.ts +3 -4
- package/src/server/index.ts +2 -2
- package/src/server/routes/addRoutes.ts +3 -2
- package/src/server/routes/bridge/addBridgeRoutes.ts +3 -2
- package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +3 -2
- package/src/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.ts +3 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeConfig.ts +3 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts +4 -3
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +6 -4
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +4 -3
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +4 -5
- package/src/server/server.ts +7 -48
- package/src/{manifest → services}/getIterableMap.ts +2 -2
- package/src/{manifest → services}/getServices.ts +9 -13
- package/src/services/index.ts +1 -0
- package/src/util/BridgeFees.ts +7 -0
- package/src/util/bridgeFeesAsBigInt.ts +15 -0
- package/src/util/calculateBridgeFees.ts +5 -11
- package/src/util/createBridgeTransfer.ts +31 -0
- package/src/util/generateBridgeEstimate.ts +9 -17
- package/src/util/index.ts +3 -0
- package/src/util/validateBridgeEstimate.ts +4 -5
- package/src/util/validateBridgeEstimateExact.ts +4 -5
- package/src/util/validateBridgeTransaction.ts +4 -3
- package/dist/node/indexers/index.d.ts +0 -2
- package/dist/node/indexers/index.d.ts.map +0 -1
- package/dist/node/manifest/getIterableMap.d.ts.map +0 -1
- package/dist/node/manifest/getModuleLocator.d.ts +0 -15
- package/dist/node/manifest/getModuleLocator.d.ts.map +0 -1
- package/dist/node/manifest/getNode.d.ts +0 -15
- package/dist/node/manifest/getNode.d.ts.map +0 -1
- package/dist/node/manifest/getServices.d.ts +0 -13
- package/dist/node/manifest/getServices.d.ts.map +0 -1
- package/dist/node/manifest/index.d.ts +0 -7
- package/dist/node/manifest/index.d.ts.map +0 -1
- package/dist/node/manifest/nodeManifest.d.ts +0 -6
- package/dist/node/manifest/nodeManifest.d.ts.map +0 -1
- package/dist/node/manifest/private/index.d.ts +0 -5
- package/dist/node/manifest/private/index.d.ts.map +0 -1
- package/dist/node/manifest/public/index.d.ts +0 -14
- package/dist/node/manifest/public/index.d.ts.map +0 -1
- package/dist/node/server/routes/dataLake/addDataLakeRoutes.d.ts +0 -3
- package/dist/node/server/routes/dataLake/addDataLakeRoutes.d.ts.map +0 -1
- package/dist/node/server/routes/dataLake/archivistMiddleware.d.ts +0 -10
- package/dist/node/server/routes/dataLake/archivistMiddleware.d.ts.map +0 -1
- package/dist/node/server/routes/dataLake/index.d.ts +0 -2
- package/dist/node/server/routes/dataLake/index.d.ts.map +0 -1
- package/src/indexers/index.ts +0 -1
- package/src/manifest/getModuleLocator.ts +0 -153
- package/src/manifest/getNode.ts +0 -40
- package/src/manifest/index.ts +0 -6
- package/src/manifest/node.json +0 -17
- package/src/manifest/nodeManifest.ts +0 -8
- package/src/manifest/private/index.ts +0 -4
- package/src/manifest/public/Ethereum.json +0 -48
- package/src/manifest/public/XL1.json +0 -48
- package/src/manifest/public/index.ts +0 -23
- package/src/server/routes/dataLake/addDataLakeRoutes.ts +0 -9
- package/src/server/routes/dataLake/archivistMiddleware.ts +0 -85
- package/src/server/routes/dataLake/index.ts +0 -1
package/dist/node/index.mjs
CHANGED
|
@@ -3,7 +3,8 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
|
|
4
4
|
// src/BridgeActor.ts
|
|
5
5
|
import { creatable } from "@xylabs/sdk-js";
|
|
6
|
-
import {
|
|
6
|
+
import { asBridgeConfigContext } from "@xyo-network/chain-orchestration";
|
|
7
|
+
import { ActorV3, XyoGatewayRunnerMoniker } from "@xyo-network/xl1-sdk";
|
|
7
8
|
|
|
8
9
|
// src/server/app.ts
|
|
9
10
|
import { customPoweredByHeader, disableCaseSensitiveRouting, disableExpressDefaultPoweredByHeader, getJsonBodyParser, getJsonBodyParserOptions, responseProfiler, standardErrors, standardResponses } from "@xylabs/express";
|
|
@@ -18,7 +19,7 @@ var connection;
|
|
|
18
19
|
var maxRetriesPerRequest = null;
|
|
19
20
|
var getConnection = /* @__PURE__ */ __name((config) => {
|
|
20
21
|
if (isDefined(connection)) return connection;
|
|
21
|
-
const { redisHost: host, redisPort: port } = config
|
|
22
|
+
const { redisHost: host, redisPort: port } = config;
|
|
22
23
|
connection = new Redis({
|
|
23
24
|
host,
|
|
24
25
|
port,
|
|
@@ -52,7 +53,7 @@ var createWorkers = /* @__PURE__ */ __name((connection2, services) => {
|
|
|
52
53
|
|
|
53
54
|
// src/queue/workers/EthTransactionMonitor.ts
|
|
54
55
|
import { assertEx } from "@xylabs/sdk-js";
|
|
55
|
-
import { PayloadBuilder } from "@xyo-network/
|
|
56
|
+
import { PayloadBuilder } from "@xyo-network/sdk-js";
|
|
56
57
|
import { Worker } from "bullmq";
|
|
57
58
|
var name = "Monitor Submitted ETH Transaction";
|
|
58
59
|
var queueName = "eth-tx-monitor";
|
|
@@ -90,26 +91,88 @@ var EthTransactionMonitor = {
|
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
// src/queue/workers/EthTransactionPreparation.ts
|
|
93
|
-
import { assertEx as
|
|
94
|
-
import { PayloadBuilder as
|
|
95
|
-
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
94
|
+
import { assertEx as assertEx5, hexToBigInt as hexToBigInt4 } from "@xylabs/sdk-js";
|
|
95
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
96
|
+
import { isBridgeIntent as isBridgeIntent4 } from "@xyo-network/xl1-sdk";
|
|
96
97
|
import { Worker as Worker2 } from "bullmq";
|
|
97
98
|
import { getAddress } from "ethers";
|
|
99
|
+
|
|
100
|
+
// src/queue/workers/util/submitEthTransaction.ts
|
|
101
|
+
import { assertEx as assertEx2, hexToBigInt, toEthAddress } from "@xylabs/sdk-js";
|
|
102
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
103
|
+
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
104
|
+
var submitEthTransaction = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, wallet) => {
|
|
105
|
+
const xl1Transaction = assertEx2(tx[0], () => "No corresponding XL1 transaction found");
|
|
106
|
+
const bridgeIntent = assertEx2(tx[1].find(isBridgeIntent), () => "No bridge intent found");
|
|
107
|
+
const srcAddress = toEthAddress(bridgeIntent.srcAddress);
|
|
108
|
+
const destAddress = toEthAddress(bridgeIntent.destAddress);
|
|
109
|
+
const amount = hexToBigInt(bridgeIntent.destAmount);
|
|
110
|
+
const nonce = hexToBigInt(await PayloadBuilder2.hash(xl1Transaction));
|
|
111
|
+
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
112
|
+
const receipt = await bridgeTx.wait(1);
|
|
113
|
+
return receipt?.hash;
|
|
114
|
+
}, "submitEthTransaction");
|
|
115
|
+
|
|
116
|
+
// src/queue/workers/util/submitXl1Transaction.ts
|
|
117
|
+
import { isAllowedBlockPayload } from "@xyo-network/xl1-sdk";
|
|
118
|
+
var submitXl1Transaction = /* @__PURE__ */ __name(async (preparedTx, gateway) => {
|
|
119
|
+
const offChainPayloads = preparedTx[1].filter((p) => !isAllowedBlockPayload(p));
|
|
120
|
+
const result = await gateway.addTransactionToChain(preparedTx, offChainPayloads);
|
|
121
|
+
return result;
|
|
122
|
+
}, "submitXl1Transaction");
|
|
123
|
+
|
|
124
|
+
// src/queue/workers/util/validateSufficientAllowance.ts
|
|
125
|
+
import { assertEx as assertEx3, hexToBigInt as hexToBigInt2 } from "@xylabs/sdk-js";
|
|
126
|
+
import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
|
|
127
|
+
var validateSufficientAllowance = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, logger) => {
|
|
128
|
+
const bridgeIntent = assertEx3(tx[1].find(isBridgeIntent2), () => "No bridge intent found");
|
|
129
|
+
const amount = hexToBigInt2(bridgeIntent.destAmount);
|
|
130
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
131
|
+
const bridgeAddress = await bridge.getAddress();
|
|
132
|
+
const remainingAllowance = await bridgeableToken.allowance(liquiditySourceAddress, bridgeAddress);
|
|
133
|
+
await logger?.log(`Remaining allowance: ${remainingAllowance.toString()}`);
|
|
134
|
+
return remainingAllowance >= amount;
|
|
135
|
+
}, "validateSufficientAllowance");
|
|
136
|
+
|
|
137
|
+
// src/queue/workers/util/validateSufficientBalance.ts
|
|
138
|
+
import { assertEx as assertEx4, hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
|
|
139
|
+
import { isBridgeIntent as isBridgeIntent3 } from "@xyo-network/xl1-sdk";
|
|
140
|
+
var validateSufficientBalance = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, logger) => {
|
|
141
|
+
const bridgeIntent = assertEx4(tx[1].find(isBridgeIntent3), () => "No bridge intent found");
|
|
142
|
+
const amount = hexToBigInt3(bridgeIntent.destAmount);
|
|
143
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
144
|
+
const balance = await bridgeableToken.balanceOf(liquiditySourceAddress);
|
|
145
|
+
await logger?.log(`Remaining balance: ${balance.toString()}`);
|
|
146
|
+
return balance >= amount;
|
|
147
|
+
}, "validateSufficientBalance");
|
|
148
|
+
|
|
149
|
+
// src/queue/workers/EthTransactionPreparation.ts
|
|
98
150
|
var name2 = "Prepare ETH Transaction";
|
|
99
151
|
var queueName2 = "eth-tx-prepare";
|
|
100
152
|
var createWorker2 = /* @__PURE__ */ __name((connection2, services) => {
|
|
101
|
-
const bridge =
|
|
102
|
-
const
|
|
153
|
+
const bridge = assertEx5(services?.bridge, () => "bridge service not provided");
|
|
154
|
+
const bridgeableToken = assertEx5(services?.bridgeableToken, () => "bridgeableToken service not provided");
|
|
155
|
+
const stateMap = assertEx5(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
|
|
103
156
|
const worker = new Worker2(queueName2, async (job) => {
|
|
104
157
|
const { tx } = job.data;
|
|
105
|
-
const hash = await
|
|
158
|
+
const hash = await PayloadBuilder3.hash(tx[0]);
|
|
106
159
|
await job.log(`[${hash}] preparing ETH transaction`);
|
|
160
|
+
await job.log(`[${hash}] validating liquiditySource has sufficient allowance`);
|
|
161
|
+
if (!await validateSufficientAllowance(tx, bridgeableToken, bridge, job)) {
|
|
162
|
+
throw new Error("Liquidity source does not have sufficient allowance for the bridge to execute the transaction");
|
|
163
|
+
}
|
|
164
|
+
await job.log(`[${hash}] validated liquiditySource has sufficient allowance`);
|
|
165
|
+
await job.log(`[${hash}] validating liquiditySource has sufficient balance`);
|
|
166
|
+
if (!await validateSufficientBalance(tx, bridgeableToken, bridge, job)) {
|
|
167
|
+
throw new Error("Liquidity source does not have sufficient balance for the bridge to execute the transaction");
|
|
168
|
+
}
|
|
169
|
+
await job.log(`[${hash}] validated liquiditySource has sufficient balance`);
|
|
107
170
|
await job.log(`[${hash}] building ETH transaction`);
|
|
108
|
-
const bridgeIntent =
|
|
109
|
-
const amount =
|
|
171
|
+
const bridgeIntent = assertEx5(tx[1].find(isBridgeIntent4), () => "No bridge intent found");
|
|
172
|
+
const amount = hexToBigInt4(bridgeIntent.destAmount);
|
|
110
173
|
const srcAddress = getAddress(bridgeIntent.srcAddress);
|
|
111
174
|
const destAddress = getAddress(bridgeIntent.destAddress);
|
|
112
|
-
const nonce =
|
|
175
|
+
const nonce = hexToBigInt4(await PayloadBuilder3.hash(tx[0]));
|
|
113
176
|
const preparedTx = await bridge.getFunction("bridgeFromRemote").populateTransaction(srcAddress, destAddress, amount, nonce);
|
|
114
177
|
await job.log(`[${hash}] built ETH transaction`);
|
|
115
178
|
await job.log(`[${hash}] storing ETH preparedTx`);
|
|
@@ -136,47 +199,21 @@ var EthTransactionPreparation = {
|
|
|
136
199
|
};
|
|
137
200
|
|
|
138
201
|
// src/queue/workers/EthTransactionSubmission.ts
|
|
139
|
-
import { assertEx as
|
|
140
|
-
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/
|
|
202
|
+
import { assertEx as assertEx6, isDefined as isDefined3 } from "@xylabs/sdk-js";
|
|
203
|
+
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/sdk-js";
|
|
141
204
|
import { Worker as Worker3 } from "bullmq";
|
|
142
|
-
|
|
143
|
-
// src/queue/workers/util/submitEthTransaction.ts
|
|
144
|
-
import { assertEx as assertEx3, hexToBigInt as hexToBigInt2, toEthAddress } from "@xylabs/sdk-js";
|
|
145
|
-
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/payload-builder";
|
|
146
|
-
import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
|
|
147
|
-
var submitEthTransaction = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, wallet) => {
|
|
148
|
-
const xl1Transaction = assertEx3(tx[0], () => "No corresponding XL1 transaction found");
|
|
149
|
-
const bridgeIntent = assertEx3(tx[1].find(isBridgeIntent2), () => "No bridge intent found");
|
|
150
|
-
const srcAddress = toEthAddress(bridgeIntent.srcAddress);
|
|
151
|
-
const destAddress = toEthAddress(bridgeIntent.destAddress);
|
|
152
|
-
const amount = hexToBigInt2(bridgeIntent.destAmount);
|
|
153
|
-
const nonce = hexToBigInt2(await PayloadBuilder3.hash(xl1Transaction));
|
|
154
|
-
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
155
|
-
const receipt = await bridgeTx.wait(1);
|
|
156
|
-
return receipt?.hash;
|
|
157
|
-
}, "submitEthTransaction");
|
|
158
|
-
|
|
159
|
-
// src/queue/workers/util/submitXl1Transaction.ts
|
|
160
|
-
import { isAllowedBlockPayload } from "@xyo-network/xl1-sdk";
|
|
161
|
-
var submitXl1Transaction = /* @__PURE__ */ __name(async (preparedTx, gateway) => {
|
|
162
|
-
const offChainPayloads = preparedTx[1].filter((p) => !isAllowedBlockPayload(p));
|
|
163
|
-
const result = await gateway.addTransactionToChain(preparedTx, offChainPayloads);
|
|
164
|
-
return result;
|
|
165
|
-
}, "submitXl1Transaction");
|
|
166
|
-
|
|
167
|
-
// src/queue/workers/EthTransactionSubmission.ts
|
|
168
205
|
var name3 = "Submit ETH Transaction";
|
|
169
206
|
var queueName3 = "eth-tx-submit";
|
|
170
207
|
var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
|
|
171
|
-
const bridge =
|
|
172
|
-
const bridgeableToken =
|
|
173
|
-
const wallet =
|
|
174
|
-
const stateMap =
|
|
208
|
+
const bridge = assertEx6(services?.bridge, () => "bridge service not provided");
|
|
209
|
+
const bridgeableToken = assertEx6(services?.bridgeableToken, () => "bridgeableToken service not provided");
|
|
210
|
+
const wallet = assertEx6(services?.wallet, () => "wallet service not provided");
|
|
211
|
+
const stateMap = assertEx6(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
|
|
175
212
|
const worker = new Worker3(queueName3, async (job) => {
|
|
176
213
|
const { tx } = job.data;
|
|
177
214
|
const hash = await PayloadBuilder4.hash(tx[0]);
|
|
178
|
-
const state =
|
|
179
|
-
const preparedTx =
|
|
215
|
+
const state = assertEx6(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
216
|
+
const preparedTx = assertEx6(state?.preparedTx, () => `[${hash}] preparedTx not found`);
|
|
180
217
|
const { submissionHash: existingSubmissionHash } = state;
|
|
181
218
|
if (isDefined3(existingSubmissionHash)) {
|
|
182
219
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
|
|
@@ -185,7 +222,7 @@ var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
|
|
|
185
222
|
};
|
|
186
223
|
}
|
|
187
224
|
await job.log(`[${hash}] Submitting ETH tx`);
|
|
188
|
-
const submissionHash =
|
|
225
|
+
const submissionHash = assertEx6(await submitEthTransaction(tx, bridgeableToken, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`);
|
|
189
226
|
await job.log(`[${hash}] Submitted ETH tx and received submission response hash ${submissionHash}`);
|
|
190
227
|
await job.log(`[${hash}] Storing ETH submissionHash`);
|
|
191
228
|
state.submissionHash = submissionHash;
|
|
@@ -239,20 +276,20 @@ var Xl1ToEthBridgeParent = {
|
|
|
239
276
|
};
|
|
240
277
|
|
|
241
278
|
// src/queue/workers/Xl1TransactionMonitor.ts
|
|
242
|
-
import { assertEx as
|
|
243
|
-
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/
|
|
279
|
+
import { assertEx as assertEx7, isDefined as isDefined4, isNull } from "@xylabs/sdk-js";
|
|
280
|
+
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/sdk-js";
|
|
244
281
|
import { UnrecoverableError, Worker as Worker5 } from "bullmq";
|
|
245
282
|
var name5 = "Monitor Submitted XL1 Transaction";
|
|
246
283
|
var queueName5 = "xl1-tx-monitor";
|
|
247
284
|
var createWorker5 = /* @__PURE__ */ __name((connection2, services) => {
|
|
248
|
-
const gateway =
|
|
249
|
-
const stateMap =
|
|
285
|
+
const gateway = assertEx7(services?.gateway, () => "gateway service not provided");
|
|
286
|
+
const stateMap = assertEx7(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
250
287
|
const worker = new Worker5(queueName5, async (job) => {
|
|
251
288
|
const { tx } = job.data;
|
|
252
289
|
const hash = await PayloadBuilder5.hash(tx[0]);
|
|
253
|
-
const viewer =
|
|
254
|
-
const state =
|
|
255
|
-
const submissionHash =
|
|
290
|
+
const viewer = assertEx7(gateway.connection.viewer, () => `[${hash}] viewer not defined on gateway`);
|
|
291
|
+
const state = assertEx7(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
292
|
+
const submissionHash = assertEx7(state?.submissionHash, () => `[${hash}] submissionHash not found`);
|
|
256
293
|
await job.log(`[${hash}] Checking for XL1 transaction inclusion on chain`);
|
|
257
294
|
const foundTx = await viewer.transactionByHash(submissionHash);
|
|
258
295
|
if (isDefined4(foundTx) && !isNull(foundTx)) {
|
|
@@ -285,13 +322,13 @@ var Xl1TransactionMonitor = {
|
|
|
285
322
|
};
|
|
286
323
|
|
|
287
324
|
// src/queue/workers/Xl1TransactionPreparation.ts
|
|
288
|
-
import { assertEx as
|
|
289
|
-
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/
|
|
325
|
+
import { assertEx as assertEx8 } from "@xylabs/sdk-js";
|
|
326
|
+
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/sdk-js";
|
|
290
327
|
import { Worker as Worker6 } from "bullmq";
|
|
291
328
|
var name6 = "Prepare XL1 Transaction";
|
|
292
329
|
var queueName6 = "xl1-tx-prepare";
|
|
293
330
|
var createWorker6 = /* @__PURE__ */ __name((connection2, services) => {
|
|
294
|
-
const stateMap =
|
|
331
|
+
const stateMap = assertEx8(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
295
332
|
const worker = new Worker6(queueName6, async (job) => {
|
|
296
333
|
const { tx } = job.data;
|
|
297
334
|
const hash = await PayloadBuilder6.hash(tx[0]);
|
|
@@ -321,19 +358,19 @@ var Xl1TransactionPreparation = {
|
|
|
321
358
|
};
|
|
322
359
|
|
|
323
360
|
// src/queue/workers/Xl1TransactionSubmission.ts
|
|
324
|
-
import { assertEx as
|
|
325
|
-
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/
|
|
361
|
+
import { assertEx as assertEx9, isDefined as isDefined5 } from "@xylabs/sdk-js";
|
|
362
|
+
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/sdk-js";
|
|
326
363
|
import { Worker as Worker7 } from "bullmq";
|
|
327
364
|
var name7 = "Submit XL1 Transaction";
|
|
328
365
|
var queueName7 = "xl1-tx-submit";
|
|
329
366
|
var createWorker7 = /* @__PURE__ */ __name((connection2, services) => {
|
|
330
|
-
const gateway =
|
|
331
|
-
const stateMap =
|
|
367
|
+
const gateway = assertEx9(services?.gateway, () => "gateway service not provided");
|
|
368
|
+
const stateMap = assertEx9(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
332
369
|
const worker = new Worker7(queueName7, async (job) => {
|
|
333
370
|
const { tx } = job.data;
|
|
334
371
|
const hash = await PayloadBuilder7.hash(tx[0]);
|
|
335
|
-
const state =
|
|
336
|
-
const preparedTx =
|
|
372
|
+
const state = assertEx9(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
373
|
+
const preparedTx = assertEx9(state?.preparedTx, () => `[${hash}] preparedTx not found`);
|
|
337
374
|
const { submissionHash: existingSubmissionHash } = state;
|
|
338
375
|
if (isDefined5(existingSubmissionHash)) {
|
|
339
376
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
|
|
@@ -477,7 +514,7 @@ var addInstrumentation = /* @__PURE__ */ __name(() => {
|
|
|
477
514
|
|
|
478
515
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeConfig.ts
|
|
479
516
|
import { requestHandlerValidator } from "@xylabs/express";
|
|
480
|
-
import { BridgeSettingsZod } from "@xyo-network/
|
|
517
|
+
import { BridgeSettingsZod } from "@xyo-network/chain-orchestration";
|
|
481
518
|
|
|
482
519
|
// src/config/asChainId.ts
|
|
483
520
|
import { asHex } from "@xylabs/sdk-js";
|
|
@@ -494,22 +531,22 @@ var asToken = /* @__PURE__ */ __name((value) => {
|
|
|
494
531
|
}, "asToken");
|
|
495
532
|
|
|
496
533
|
// src/config/getBridgeEscrowAddress.ts
|
|
497
|
-
import { asAddress as asAddress2, assertEx as
|
|
534
|
+
import { asAddress as asAddress2, assertEx as assertEx10 } from "@xylabs/sdk-js";
|
|
498
535
|
var tryGetBridgeEscrowAddress = /* @__PURE__ */ __name((config) => {
|
|
499
|
-
const address = asAddress2(config.
|
|
536
|
+
const address = asAddress2(config.escrowAddress);
|
|
500
537
|
return address;
|
|
501
538
|
}, "tryGetBridgeEscrowAddress");
|
|
502
539
|
|
|
503
540
|
// src/config/getBridgeFeesAddress.ts
|
|
504
|
-
import { asAddress as asAddress3, assertEx as
|
|
541
|
+
import { asAddress as asAddress3, assertEx as assertEx11 } from "@xylabs/sdk-js";
|
|
505
542
|
var tryGetBridgeFeesAddress = /* @__PURE__ */ __name((config) => {
|
|
506
|
-
const address = asAddress3(config.
|
|
543
|
+
const address = asAddress3(config.feesAddress);
|
|
507
544
|
return address;
|
|
508
545
|
}, "tryGetBridgeFeesAddress");
|
|
509
546
|
|
|
510
547
|
// src/config/getFeeStructure.ts
|
|
511
548
|
var getFeeStructure = /* @__PURE__ */ __name((config) => {
|
|
512
|
-
const { feeFixed, feeRateBasisPoints } = config
|
|
549
|
+
const { feeFixed, feeRateBasisPoints } = config;
|
|
513
550
|
return {
|
|
514
551
|
feeFixed,
|
|
515
552
|
feeRateBasisPoints
|
|
@@ -518,28 +555,28 @@ var getFeeStructure = /* @__PURE__ */ __name((config) => {
|
|
|
518
555
|
|
|
519
556
|
// src/config/getMaxBridgeAmount.ts
|
|
520
557
|
var getMaxBridgeAmount = /* @__PURE__ */ __name((config) => {
|
|
521
|
-
const { maxBridgeAmount } = config
|
|
558
|
+
const { maxBridgeAmount } = config;
|
|
522
559
|
return maxBridgeAmount;
|
|
523
560
|
}, "getMaxBridgeAmount");
|
|
524
561
|
|
|
525
562
|
// src/config/getMinBridgeAmount.ts
|
|
526
563
|
var getMinBridgeAmount = /* @__PURE__ */ __name((config) => {
|
|
527
|
-
const { minBridgeAmount } = config
|
|
564
|
+
const { minBridgeAmount } = config;
|
|
528
565
|
return minBridgeAmount;
|
|
529
566
|
}, "getMinBridgeAmount");
|
|
530
567
|
|
|
531
568
|
// src/config/getRemoteChainId.ts
|
|
532
|
-
import { assertEx as
|
|
569
|
+
import { assertEx as assertEx12 } from "@xylabs/sdk-js";
|
|
533
570
|
var getRemoteChainId = /* @__PURE__ */ __name((config) => {
|
|
534
|
-
const remoteChainId =
|
|
571
|
+
const remoteChainId = assertEx12(asChainId(config.remoteChainId), () => "Invalid remote chain ID in config");
|
|
535
572
|
return remoteChainId;
|
|
536
573
|
}, "getRemoteChainId");
|
|
537
574
|
|
|
538
575
|
// src/config/getRemoteTokenAddress.ts
|
|
539
|
-
import { assertEx as
|
|
576
|
+
import { assertEx as assertEx13 } from "@xylabs/sdk-js";
|
|
540
577
|
var getRemoteTokenAddress = /* @__PURE__ */ __name((config) => {
|
|
541
|
-
const token = asToken(config.
|
|
542
|
-
return
|
|
578
|
+
const token = asToken(config.remoteTokenAddress);
|
|
579
|
+
return assertEx13(token, () => "Remote token address is not defined in bridge configuration");
|
|
543
580
|
}, "getRemoteTokenAddress");
|
|
544
581
|
|
|
545
582
|
// src/config/getBridgeWalletAccount.ts
|
|
@@ -549,7 +586,7 @@ import { ADDRESS_INDEX, generateXyoBaseWalletFromPhrase } from "@xyo-network/xl1
|
|
|
549
586
|
var accountServiceSingleton;
|
|
550
587
|
var getBridgeWalletAccount = /* @__PURE__ */ __name(async (config) => {
|
|
551
588
|
if (accountServiceSingleton) return accountServiceSingleton;
|
|
552
|
-
let walletPhrase = config.
|
|
589
|
+
let walletPhrase = config.mnemonic;
|
|
553
590
|
if (isUndefined(walletPhrase)) {
|
|
554
591
|
console.log("[Bridge] No wallet mnemonic specified!");
|
|
555
592
|
const randomMnemonic = HDWallet.generateMnemonic();
|
|
@@ -577,19 +614,19 @@ var getTransferAddresses = /* @__PURE__ */ __name(async (config) => {
|
|
|
577
614
|
}, "getTransferAddresses");
|
|
578
615
|
|
|
579
616
|
// src/config/getXl1ChainId.ts
|
|
580
|
-
import { assertEx as
|
|
617
|
+
import { assertEx as assertEx14, isDefined as isDefined7 } from "@xylabs/sdk-js";
|
|
581
618
|
var getXl1ChainId = /* @__PURE__ */ __name((config) => {
|
|
582
|
-
const xl1ChainId = config.
|
|
619
|
+
const xl1ChainId = config.xl1ChainId;
|
|
583
620
|
if (isDefined7(xl1ChainId)) {
|
|
584
|
-
return
|
|
621
|
+
return assertEx14(asChainId(xl1ChainId), () => "Invalid xl1ChainId in bridge config");
|
|
585
622
|
}
|
|
586
|
-
return
|
|
623
|
+
return assertEx14(asChainId(config.chain.id), () => "Invalid chain.id in config");
|
|
587
624
|
}, "getXl1ChainId");
|
|
588
625
|
|
|
589
626
|
// src/config/getXl1TokenAddress.ts
|
|
590
627
|
import { isDefined as isDefined8 } from "@xylabs/sdk-js";
|
|
591
628
|
var getXl1TokenAddress = /* @__PURE__ */ __name((config) => {
|
|
592
|
-
const token = asToken(config.
|
|
629
|
+
const token = asToken(config.xl1TokenAddress);
|
|
593
630
|
if (isDefined8(token)) return token;
|
|
594
631
|
return getXl1ChainId(config);
|
|
595
632
|
}, "getXl1TokenAddress");
|
|
@@ -649,7 +686,7 @@ var makeBridgeConfigRoute = /* @__PURE__ */ __name((config) => {
|
|
|
649
686
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts
|
|
650
687
|
import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
|
|
651
688
|
import { toAddress, toHex } from "@xylabs/sdk-js";
|
|
652
|
-
import { PayloadZodStrictOfSchema } from "@xyo-network/
|
|
689
|
+
import { PayloadZodStrictOfSchema } from "@xyo-network/sdk-js";
|
|
653
690
|
import { BridgeDestinationObservationFieldsZod, BridgeDestinationObservationSchema } from "@xyo-network/xl1-sdk";
|
|
654
691
|
import { z } from "zod";
|
|
655
692
|
|
|
@@ -709,33 +746,49 @@ var makeBridgeFromRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
|
|
|
709
746
|
|
|
710
747
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts
|
|
711
748
|
import { requestHandlerValidator as requestHandlerValidator3 } from "@xylabs/express";
|
|
712
|
-
import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/
|
|
713
|
-
import { PayloadZodLooseOfSchema, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema2 } from "@xyo-network/payload-model";
|
|
749
|
+
import { PayloadBuilder as PayloadBuilder11, PayloadZodLooseOfSchema, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema2 } from "@xyo-network/sdk-js";
|
|
714
750
|
import { BridgeIntentFieldsZod, BridgeIntentSchema as BridgeIntentSchema2, BridgeSourceObservationFieldsZod, BridgeSourceObservationSchema, SignedTransactionBoundWitnessZod, TransferZod } from "@xyo-network/xl1-sdk";
|
|
715
751
|
import { z as z2 } from "zod";
|
|
716
752
|
|
|
717
753
|
// src/util/calculateBridgeFees.ts
|
|
718
|
-
import { hexToBigInt as
|
|
754
|
+
import { hexToBigInt as hexToBigInt5, toHex as toHex2 } from "@xylabs/sdk-js";
|
|
719
755
|
var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
720
756
|
const { feeFixed, feeRateBasisPoints } = feeStructure;
|
|
721
|
-
const srcAmountBigInt =
|
|
722
|
-
const feeFixedBigInt =
|
|
757
|
+
const srcAmountBigInt = hexToBigInt5(srcAmount);
|
|
758
|
+
const feeFixedBigInt = hexToBigInt5(feeFixed);
|
|
723
759
|
const feeVariableBigInt = srcAmountBigInt * BigInt(feeRateBasisPoints) / 10000n;
|
|
724
760
|
const feeVariable = toHex2(feeVariableBigInt);
|
|
725
761
|
const feeTotalBigInt = feeFixedBigInt + feeVariableBigInt;
|
|
726
762
|
const destAmountBigInt = srcAmountBigInt > feeTotalBigInt ? srcAmountBigInt - feeTotalBigInt : 0n;
|
|
727
763
|
const destAmount = toHex2(destAmountBigInt);
|
|
728
764
|
return {
|
|
729
|
-
destAmount,
|
|
730
765
|
feeFixed,
|
|
731
|
-
feeVariable
|
|
766
|
+
feeVariable,
|
|
767
|
+
srcAmount
|
|
732
768
|
};
|
|
733
769
|
}, "calculateBridgeFees");
|
|
734
770
|
|
|
771
|
+
// src/util/createBridgeTransfer.ts
|
|
772
|
+
import { hexToBigInt as hexToBigInt6 } from "@xylabs/sdk-js";
|
|
773
|
+
import { createTransferPayload } from "@xyo-network/xl1-sdk";
|
|
774
|
+
var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddress, feesAddress, context) => {
|
|
775
|
+
const { feeFixed, feeVariable } = context;
|
|
776
|
+
const escrowAmount = hexToBigInt6(srcAmount);
|
|
777
|
+
const feesAmount = hexToBigInt6(feeFixed) + hexToBigInt6(feeVariable);
|
|
778
|
+
const transfers = escrowAddress === feesAddress ? {
|
|
779
|
+
[feesAddress]: escrowAmount + feesAmount
|
|
780
|
+
} : {
|
|
781
|
+
[escrowAddress]: escrowAmount,
|
|
782
|
+
[feesAddress]: feesAmount
|
|
783
|
+
};
|
|
784
|
+
const transfer = createTransferPayload(sender, transfers, context);
|
|
785
|
+
return transfer;
|
|
786
|
+
}, "createBridgeTransfer");
|
|
787
|
+
|
|
735
788
|
// src/util/generateBridgeEstimate.ts
|
|
736
|
-
import {
|
|
737
|
-
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/
|
|
738
|
-
import { BridgeIntentSchema
|
|
789
|
+
import { toAddress as toAddress2 } from "@xylabs/sdk-js";
|
|
790
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/sdk-js";
|
|
791
|
+
import { BridgeIntentSchema } from "@xyo-network/xl1-sdk";
|
|
739
792
|
import { v4 } from "uuid";
|
|
740
793
|
var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount, destAddress, config, nonceOverride) => {
|
|
741
794
|
const { escrowAddress, feeFixed, feeRateBasisPoints, feesAddress, remoteChainId, remoteTokenAddress, xl1ChainId, xl1TokenAddress } = await getBridgeSettings(config);
|
|
@@ -744,7 +797,6 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
|
|
|
744
797
|
feeFixed,
|
|
745
798
|
feeRateBasisPoints
|
|
746
799
|
});
|
|
747
|
-
const { destAmount, feeFixed: feeFixedAmount, feeVariable } = fees;
|
|
748
800
|
const nonce = nonceOverride ?? v4();
|
|
749
801
|
const bridgeIntentFields = {
|
|
750
802
|
// Source
|
|
@@ -755,22 +807,14 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
|
|
|
755
807
|
// Destination
|
|
756
808
|
dest: remoteChainId,
|
|
757
809
|
destAddress,
|
|
758
|
-
destAmount,
|
|
810
|
+
destAmount: srcAmount,
|
|
759
811
|
destToken: remoteTokenAddress,
|
|
760
812
|
nonce
|
|
761
813
|
};
|
|
762
814
|
const bridgeIntent = new PayloadBuilder8({
|
|
763
815
|
schema: BridgeIntentSchema
|
|
764
816
|
}).fields(bridgeIntentFields).build();
|
|
765
|
-
const
|
|
766
|
-
destAmount,
|
|
767
|
-
feeFixed: feeFixedAmount,
|
|
768
|
-
feeVariable
|
|
769
|
-
};
|
|
770
|
-
const transfer = createTransferPayload(sender, {
|
|
771
|
-
[escrowAddress]: hexToBigInt4(destAmount),
|
|
772
|
-
[feesAddress]: hexToBigInt4(feeFixedAmount) + hexToBigInt4(feeVariable)
|
|
773
|
-
}, context);
|
|
817
|
+
const transfer = createBridgeTransfer(sender, srcAmount, escrowAddress, feesAddress, fees);
|
|
774
818
|
return [
|
|
775
819
|
bridgeIntent,
|
|
776
820
|
transfer
|
|
@@ -779,7 +823,7 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
|
|
|
779
823
|
|
|
780
824
|
// src/util/validateBridgeEstimateExact.ts
|
|
781
825
|
import { isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
782
|
-
import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/
|
|
826
|
+
import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/sdk-js";
|
|
783
827
|
var validateBridgeEstimateExact = /* @__PURE__ */ __name(async (intent, transfer, config) => {
|
|
784
828
|
const { srcAddress, srcAmount, destAddress } = intent;
|
|
785
829
|
const [calculatedIntent, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
@@ -796,7 +840,7 @@ var validateBridgeEstimateExact = /* @__PURE__ */ __name(async (intent, transfer
|
|
|
796
840
|
// src/util/validateBridgeTransaction.ts
|
|
797
841
|
import { asAddress as asAddress4, isDefined as isDefined9 } from "@xylabs/sdk-js";
|
|
798
842
|
import { addressesContains, BoundWitnessValidator, payloadHashesContainsAll } from "@xyo-network/boundwitness-validator";
|
|
799
|
-
import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/
|
|
843
|
+
import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/sdk-js";
|
|
800
844
|
var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent, transfer, config) => {
|
|
801
845
|
const { srcAddress } = intent;
|
|
802
846
|
const chainId = getXl1ChainId(config);
|
|
@@ -870,8 +914,8 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
|
|
|
870
914
|
|
|
871
915
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts
|
|
872
916
|
import { requestHandlerValidator as requestHandlerValidator4 } from "@xylabs/express";
|
|
873
|
-
import { assertEx as
|
|
874
|
-
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/
|
|
917
|
+
import { assertEx as assertEx15, toAddress as toAddress3 } from "@xylabs/sdk-js";
|
|
918
|
+
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/sdk-js";
|
|
875
919
|
import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema3, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
|
|
876
920
|
import { z as z3 } from "zod";
|
|
877
921
|
var BridgeToRemoteEstimateBodyZod = BridgeIntentFieldsZod2.pick({
|
|
@@ -901,7 +945,7 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
901
945
|
const { srcAddress, srcAmount, destAddress } = req.body;
|
|
902
946
|
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
903
947
|
const sender = toAddress3(srcAddress);
|
|
904
|
-
const viewer =
|
|
948
|
+
const viewer = assertEx15(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
|
|
905
949
|
const currentBlockNumber = await viewer.currentBlockNumber();
|
|
906
950
|
const nbf = toXL1BlockNumber(currentBlockNumber, true);
|
|
907
951
|
const exp = toXL1BlockNumber(currentBlockNumber + 1e3, true);
|
|
@@ -922,7 +966,7 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
922
966
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts
|
|
923
967
|
import { requestHandlerValidator as requestHandlerValidator5 } from "@xylabs/express";
|
|
924
968
|
import { asAddress as asAddress5, asHex as asHex3, toHex as toHex3 } from "@xylabs/sdk-js";
|
|
925
|
-
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/
|
|
969
|
+
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/sdk-js";
|
|
926
970
|
import { BridgeDestinationObservationFieldsZod as BridgeDestinationObservationFieldsZod2, BridgeDestinationObservationSchema as BridgeDestinationObservationSchema2, BridgeIntentFieldsZod as BridgeIntentFieldsZod3, BridgeIntentSchema as BridgeIntentSchema4, BridgeSourceObservationFieldsZod as BridgeSourceObservationFieldsZod2, BridgeSourceObservationSchema as BridgeSourceObservationSchema2 } from "@xyo-network/xl1-sdk";
|
|
927
971
|
import { z as z4 } from "zod";
|
|
928
972
|
var BridgeToRemoteStatusResponseZod = z4.union([
|
|
@@ -1034,7 +1078,7 @@ var addRoutes = /* @__PURE__ */ __name((app, config, gateway) => {
|
|
|
1034
1078
|
}, "addRoutes");
|
|
1035
1079
|
|
|
1036
1080
|
// src/server/app.ts
|
|
1037
|
-
var getApp = /* @__PURE__ */ __name((
|
|
1081
|
+
var getApp = /* @__PURE__ */ __name((config, gateway) => {
|
|
1038
1082
|
addInstrumentation();
|
|
1039
1083
|
const app = express();
|
|
1040
1084
|
app.set("etag", false);
|
|
@@ -1048,390 +1092,23 @@ var getApp = /* @__PURE__ */ __name((node, config, gateway) => {
|
|
|
1048
1092
|
disableExpressDefaultPoweredByHeader(app);
|
|
1049
1093
|
app.use(customPoweredByHeader);
|
|
1050
1094
|
disableCaseSensitiveRouting(app);
|
|
1051
|
-
app.node = node;
|
|
1052
1095
|
addFlowProducer(app, config);
|
|
1053
1096
|
addRoutes(app, config, gateway);
|
|
1054
1097
|
app.use(standardErrors);
|
|
1055
1098
|
return app;
|
|
1056
1099
|
}, "getApp");
|
|
1057
1100
|
|
|
1058
|
-
// src/
|
|
1059
|
-
import { assertEx as
|
|
1060
|
-
import {
|
|
1061
|
-
import {
|
|
1101
|
+
// src/services/getServices.ts
|
|
1102
|
+
import { assertEx as assertEx16, isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
1103
|
+
import { initEvmProvider } from "@xyo-network/chain-orchestration";
|
|
1104
|
+
import { BridgeableToken__factory, LiquidityPoolBridge__factory } from "@xyo-network/typechain";
|
|
1105
|
+
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
1106
|
+
import { getAddress as getAddress2, Wallet } from "ethers";
|
|
1062
1107
|
|
|
1063
|
-
// src/
|
|
1108
|
+
// src/services/getIterableMap.ts
|
|
1064
1109
|
import { BaseMongoSdk } from "@xylabs/mongo";
|
|
1065
|
-
import { assertEx as assertEx16, isDefined as isDefined12 } from "@xylabs/sdk-js";
|
|
1066
|
-
import { MemoryArchivist } from "@xyo-network/archivist-memory";
|
|
1067
|
-
import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
|
|
1068
|
-
import { ViewArchivist } from "@xyo-network/archivist-view";
|
|
1069
|
-
import { initEvmProvider } from "@xyo-network/chain-orchestration";
|
|
1070
1110
|
import { MongoMap } from "@xyo-network/chain-protocol";
|
|
1071
|
-
import {
|
|
1072
|
-
import { AbstractModule, LoggerModuleStatusReporter } from "@xyo-network/module-abstract";
|
|
1073
|
-
import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
|
|
1074
|
-
import { MemorySentinel } from "@xyo-network/sentinel-memory";
|
|
1075
|
-
import { hasMongoConfig, mapToMapType, XyoGatewayRunnerMoniker } from "@xyo-network/xl1-sdk";
|
|
1076
|
-
|
|
1077
|
-
// src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts
|
|
1078
|
-
import { asAddress as asAddress6, asHex as asHex4, assertEx as assertEx14, delay, hexFromBigInt, hexToBigInt as hexToBigInt5, isDefined as isDefined10, isUndefined as isUndefined4 } from "@xylabs/sdk-js";
|
|
1079
|
-
import { PayloadBuilder as PayloadBuilder12 } from "@xyo-network/payload-builder";
|
|
1080
|
-
import { asSchema } from "@xyo-network/payload-model";
|
|
1081
|
-
import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
|
|
1082
|
-
import { LiquidityPoolBridge__factory } from "@xyo-network/typechain";
|
|
1083
|
-
import { BridgeDestinationObservationSchema as BridgeDestinationObservationSchema3, flattenHydratedTransaction, flattenHydratedTransactions, isBridgeIntent as isBridgeIntent3, tryUnflattenHydratedTransaction } from "@xyo-network/xl1-sdk";
|
|
1084
|
-
import { Mutex } from "async-mutex";
|
|
1085
|
-
import { getAddress as getAddress2 } from "ethers/address";
|
|
1086
|
-
import { Wallet } from "ethers/wallet";
|
|
1087
|
-
var EVMLiquidityBridgeTransactionCompletionMonitorSentinelConfigSchema = asSchema("network.xyo.sentinel.chain.evm.liquidity.bridge.transaction.completion.monitor.config", true);
|
|
1088
|
-
var defaultJobCheckIntervalMs = 15e3;
|
|
1089
|
-
var EVMLiquidityBridgeTransactionCompletionMonitorSentinel = class extends AbstractSentinel {
|
|
1090
|
-
static {
|
|
1091
|
-
__name(this, "EVMLiquidityBridgeTransactionCompletionMonitorSentinel");
|
|
1092
|
-
}
|
|
1093
|
-
static configSchemas = [
|
|
1094
|
-
EVMLiquidityBridgeTransactionCompletionMonitorSentinelConfigSchema
|
|
1095
|
-
];
|
|
1096
|
-
static defaultConfigSchema = EVMLiquidityBridgeTransactionCompletionMonitorSentinelConfigSchema;
|
|
1097
|
-
_attemptsCounter;
|
|
1098
|
-
_bridge;
|
|
1099
|
-
_bridgeChainId;
|
|
1100
|
-
_bridgeRemoteChainId;
|
|
1101
|
-
_bridgeTokenAddress;
|
|
1102
|
-
_checkCounter;
|
|
1103
|
-
_errorCounter;
|
|
1104
|
-
_reportMutex = new Mutex();
|
|
1105
|
-
_successCounter;
|
|
1106
|
-
_wallet;
|
|
1107
|
-
get bridge() {
|
|
1108
|
-
return assertEx14(this._bridge, () => new Error("Bridge contract not initialized"));
|
|
1109
|
-
}
|
|
1110
|
-
get completedTransactions() {
|
|
1111
|
-
return assertEx14(this.params.completedTransactions, () => "Completed transactions map is not defined");
|
|
1112
|
-
}
|
|
1113
|
-
get jobCheckInterval() {
|
|
1114
|
-
return isDefined10(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs;
|
|
1115
|
-
}
|
|
1116
|
-
get pendingTransactions() {
|
|
1117
|
-
return assertEx14(this.params.pendingTransactions, () => "Pending transactions map is not defined");
|
|
1118
|
-
}
|
|
1119
|
-
get wallet() {
|
|
1120
|
-
return assertEx14(this._wallet, () => "wallet is required");
|
|
1121
|
-
}
|
|
1122
|
-
async createHandler() {
|
|
1123
|
-
await super.createHandler();
|
|
1124
|
-
this._attemptsCounter = this.meter?.createCounter("evm_liquidity_bridge_transaction_completion_monitor_sentinel_attempts_total", {
|
|
1125
|
-
description: "Number of attempts"
|
|
1126
|
-
});
|
|
1127
|
-
this._checkCounter = this.meter?.createCounter("evm_liquidity_bridge_transaction_completion_monitor_sentinel_check_total", {
|
|
1128
|
-
description: "Number of checks"
|
|
1129
|
-
});
|
|
1130
|
-
this._successCounter = this.meter?.createCounter("evm_liquidity_bridge_transaction_completion_monitor_sentinel_success_total", {
|
|
1131
|
-
description: "Number of successes"
|
|
1132
|
-
});
|
|
1133
|
-
this._errorCounter = this.meter?.createCounter("evm_liquidity_bridge_transaction_completion_monitor_sentinel_errors_total", {
|
|
1134
|
-
description: "Number of errors"
|
|
1135
|
-
});
|
|
1136
|
-
const { provider, bridgeAddress } = this.params;
|
|
1137
|
-
const key = assertEx14(this.account?.private?.hex, () => new Error("Account private key is required"));
|
|
1138
|
-
this._wallet = new Wallet(key, provider);
|
|
1139
|
-
this._bridge = LiquidityPoolBridge__factory.connect(getAddress2(bridgeAddress), this._wallet);
|
|
1140
|
-
const network = await provider.getNetwork();
|
|
1141
|
-
this._bridgeChainId = assertEx14(hexFromBigInt(network.chainId), () => new Error("Failed to parse bridgeChainId"));
|
|
1142
|
-
const tokenAddress = await this.bridge.token();
|
|
1143
|
-
this._bridgeTokenAddress = asAddress6(tokenAddress, true);
|
|
1144
|
-
const bridgeRemoteChain = await this.bridge.remoteChain();
|
|
1145
|
-
this._bridgeRemoteChainId = asHex4(bridgeRemoteChain);
|
|
1146
|
-
}
|
|
1147
|
-
async reportHandler(payloads) {
|
|
1148
|
-
if (isDefined10(payloads) && payloads.length > 0) {
|
|
1149
|
-
const signedHydratedTransaction = tryUnflattenHydratedTransaction(payloads);
|
|
1150
|
-
if (isDefined10(signedHydratedTransaction)) {
|
|
1151
|
-
const txHash = await PayloadBuilder12.hash(signedHydratedTransaction[0]);
|
|
1152
|
-
this.logger?.info(`Adding transaction ${signedHydratedTransaction[0]} with hash ${txHash} to pending transactions for monitoring`);
|
|
1153
|
-
await this.pendingTransactions.set(txHash, signedHydratedTransaction);
|
|
1154
|
-
return flattenHydratedTransaction(signedHydratedTransaction);
|
|
1155
|
-
}
|
|
1156
|
-
return [];
|
|
1157
|
-
} else {
|
|
1158
|
-
if (this._reportMutex.isLocked()) {
|
|
1159
|
-
this.logger?.debug(`EVMLiquidityBridgeTransactionCompletionMonitorSentinel [${this.id}] is already running, skipping report [${Date.now()}]`);
|
|
1160
|
-
return [];
|
|
1161
|
-
}
|
|
1162
|
-
return await this._reportMutex.runExclusive(async () => {
|
|
1163
|
-
const response = [];
|
|
1164
|
-
if (isUndefined4(payloads) || payloads.length === 0) {
|
|
1165
|
-
await this.processAllTransactions();
|
|
1166
|
-
}
|
|
1167
|
-
return response;
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
async processAllTransactions() {
|
|
1172
|
-
const results = [];
|
|
1173
|
-
for await (const [hash, signedHydratedTransaction] of this.pendingTransactions) {
|
|
1174
|
-
const result = await this.processTransaction([
|
|
1175
|
-
hash,
|
|
1176
|
-
signedHydratedTransaction
|
|
1177
|
-
]);
|
|
1178
|
-
if (isDefined10(result)) results.push(result[1]);
|
|
1179
|
-
await delay(this.jobCheckInterval);
|
|
1180
|
-
}
|
|
1181
|
-
return flattenHydratedTransactions(results);
|
|
1182
|
-
}
|
|
1183
|
-
async processTransaction([hash, signedHydratedTransaction]) {
|
|
1184
|
-
this.logger?.info(`Checking for transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
|
|
1185
|
-
try {
|
|
1186
|
-
let ret = void 0;
|
|
1187
|
-
this._checkCounter?.add(1);
|
|
1188
|
-
const bridgeIntents = signedHydratedTransaction[1].filter(isBridgeIntent3);
|
|
1189
|
-
if (bridgeIntents.length !== 1) {
|
|
1190
|
-
await this.pendingTransactions.delete(hash);
|
|
1191
|
-
return ret;
|
|
1192
|
-
}
|
|
1193
|
-
const bridgeIntent = bridgeIntents[0];
|
|
1194
|
-
this._attemptsCounter?.add(1);
|
|
1195
|
-
const bridgeDestinationObservation = await this.relayBridgeIntentSync(bridgeIntent);
|
|
1196
|
-
await this.completedTransactions.set(hash, bridgeDestinationObservation);
|
|
1197
|
-
await this.pendingTransactions.delete(hash);
|
|
1198
|
-
this._successCounter?.add(1);
|
|
1199
|
-
return ret;
|
|
1200
|
-
} catch (error) {
|
|
1201
|
-
this._errorCounter?.add(1);
|
|
1202
|
-
this.logger?.error(`Error checking for transaction ${signedHydratedTransaction[0]} with hash ${hash}:`, error);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* Relays a given BridgeIntent.
|
|
1207
|
-
* @param bridgeIntent The BridgeIntent to relay
|
|
1208
|
-
* @returns Relays the intent in a blocking manner, returning the resulting BridgeDestinationObservation if successful
|
|
1209
|
-
*/
|
|
1210
|
-
async relayBridgeIntentSync(bridgeIntent) {
|
|
1211
|
-
const amount = hexToBigInt5(bridgeIntent.destAmount);
|
|
1212
|
-
const nonce = await this.wallet.getNonce();
|
|
1213
|
-
const srcAddress = getAddress2(bridgeIntent.srcAddress);
|
|
1214
|
-
const destAddress = getAddress2(bridgeIntent.destAddress);
|
|
1215
|
-
const tx = await this.bridge.bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
1216
|
-
const confirmation = await tx.wait();
|
|
1217
|
-
const transactionResponse = await confirmation?.getTransaction();
|
|
1218
|
-
const destConfirmation = asHex4(transactionResponse?.hash ?? "", true);
|
|
1219
|
-
const { schema, ...rest } = bridgeIntent;
|
|
1220
|
-
const result = new PayloadBuilder12({
|
|
1221
|
-
schema: BridgeDestinationObservationSchema3
|
|
1222
|
-
}).fields({
|
|
1223
|
-
...rest,
|
|
1224
|
-
destConfirmation
|
|
1225
|
-
}).build();
|
|
1226
|
-
return result;
|
|
1227
|
-
}
|
|
1228
|
-
};
|
|
1229
|
-
|
|
1230
|
-
// src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts
|
|
1231
|
-
import { assertEx as assertEx15, delay as delay2, isDefined as isDefined11, isNull as isNull2, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
|
|
1232
|
-
import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/payload-builder";
|
|
1233
|
-
import { asSchema as asSchema2 } from "@xyo-network/payload-model";
|
|
1234
|
-
import { AbstractSentinel as AbstractSentinel2 } from "@xyo-network/sentinel-abstract";
|
|
1235
|
-
import { flattenHydratedTransaction as flattenHydratedTransaction2, flattenHydratedTransactions as flattenHydratedTransactions2, tryUnflattenHydratedTransaction as tryUnflattenHydratedTransaction2 } from "@xyo-network/xl1-sdk";
|
|
1236
|
-
import { Mutex as Mutex2 } from "async-mutex";
|
|
1237
|
-
var XL1TransactionCompletionMonitorSentinelConfigSchema = asSchema2("network.xyo.sentinel.chain.transaction.completion.monitor.config", true);
|
|
1238
|
-
var defaultJobCheckIntervalMs2 = 15e3;
|
|
1239
|
-
var XL1TransactionCompletionMonitorSentinel = class extends AbstractSentinel2 {
|
|
1240
|
-
static {
|
|
1241
|
-
__name(this, "XL1TransactionCompletionMonitorSentinel");
|
|
1242
|
-
}
|
|
1243
|
-
static configSchemas = [
|
|
1244
|
-
XL1TransactionCompletionMonitorSentinelConfigSchema
|
|
1245
|
-
];
|
|
1246
|
-
static defaultConfigSchema = XL1TransactionCompletionMonitorSentinelConfigSchema;
|
|
1247
|
-
_attemptsCounter;
|
|
1248
|
-
_checkCounter;
|
|
1249
|
-
_errorCounter;
|
|
1250
|
-
_reportMutex = new Mutex2();
|
|
1251
|
-
_successCounter;
|
|
1252
|
-
get completedTransactions() {
|
|
1253
|
-
return assertEx15(this.params.completedTransactions, () => "Completed transactions map is not defined");
|
|
1254
|
-
}
|
|
1255
|
-
get jobCheckInterval() {
|
|
1256
|
-
return isDefined11(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs2;
|
|
1257
|
-
}
|
|
1258
|
-
get pendingTransactions() {
|
|
1259
|
-
return assertEx15(this.params.pendingTransactions, () => "Pending transactions map is not defined");
|
|
1260
|
-
}
|
|
1261
|
-
get viewer() {
|
|
1262
|
-
return assertEx15(this.params.viewer, () => "Viewer is not defined in params");
|
|
1263
|
-
}
|
|
1264
|
-
async createHandler() {
|
|
1265
|
-
await super.createHandler();
|
|
1266
|
-
this._attemptsCounter = this.meter?.createCounter("xl1_transaction_completion_monitor_sentinel_attempts_total", {
|
|
1267
|
-
description: "Number of attempts"
|
|
1268
|
-
});
|
|
1269
|
-
this._checkCounter = this.meter?.createCounter("xl1_transaction_completion_monitor_sentinel_check_total", {
|
|
1270
|
-
description: "Number of checks"
|
|
1271
|
-
});
|
|
1272
|
-
this._successCounter = this.meter?.createCounter("xl1_transaction_completion_monitor_sentinel_success_total", {
|
|
1273
|
-
description: "Number of successes"
|
|
1274
|
-
});
|
|
1275
|
-
this._errorCounter = this.meter?.createCounter("xl1_transaction_completion_monitor_sentinel_errors_total", {
|
|
1276
|
-
description: "Number of errors"
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
async reportHandler(payloads) {
|
|
1280
|
-
if (isDefined11(payloads) && payloads.length > 0) {
|
|
1281
|
-
const signedHydratedTransaction = tryUnflattenHydratedTransaction2(payloads);
|
|
1282
|
-
if (isDefined11(signedHydratedTransaction)) {
|
|
1283
|
-
const txHash = await PayloadBuilder13.hash(signedHydratedTransaction[0]);
|
|
1284
|
-
this.logger?.info(`Adding transaction ${signedHydratedTransaction[0]} with hash ${txHash} to pending transactions for monitoring`);
|
|
1285
|
-
await this.pendingTransactions.set(txHash, signedHydratedTransaction);
|
|
1286
|
-
return flattenHydratedTransaction2(signedHydratedTransaction);
|
|
1287
|
-
}
|
|
1288
|
-
return [];
|
|
1289
|
-
} else {
|
|
1290
|
-
if (this._reportMutex.isLocked()) {
|
|
1291
|
-
this.logger?.debug(`XL1TransactionCompletionMonitorSentinel [${this.id}] is already running, skipping report [${Date.now()}]`);
|
|
1292
|
-
return [];
|
|
1293
|
-
}
|
|
1294
|
-
return await this._reportMutex.runExclusive(async () => {
|
|
1295
|
-
const response = [];
|
|
1296
|
-
if (isUndefined5(payloads) || payloads.length === 0) {
|
|
1297
|
-
await this.processAllTransactions();
|
|
1298
|
-
}
|
|
1299
|
-
return response;
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
async processAllTransactions() {
|
|
1304
|
-
const results = [];
|
|
1305
|
-
for await (const [hash, signedHydratedTransaction] of this.pendingTransactions) {
|
|
1306
|
-
const result = await this.processTransaction([
|
|
1307
|
-
hash,
|
|
1308
|
-
signedHydratedTransaction
|
|
1309
|
-
]);
|
|
1310
|
-
if (isDefined11(result)) results.push(result[1]);
|
|
1311
|
-
await delay2(this.jobCheckInterval);
|
|
1312
|
-
}
|
|
1313
|
-
return flattenHydratedTransactions2(results);
|
|
1314
|
-
}
|
|
1315
|
-
async processTransaction([hash, signedHydratedTransaction]) {
|
|
1316
|
-
this.logger?.info(`Checking for transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
|
|
1317
|
-
try {
|
|
1318
|
-
let ret = void 0;
|
|
1319
|
-
this._checkCounter?.add(1);
|
|
1320
|
-
this._attemptsCounter?.add(1);
|
|
1321
|
-
const tx = await this.viewer.transactionByHash(hash);
|
|
1322
|
-
if (isDefined11(tx) && !isNull2(tx)) {
|
|
1323
|
-
await this.completedTransactions.set(hash, signedHydratedTransaction);
|
|
1324
|
-
this.logger?.info(`Found transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
|
|
1325
|
-
this.logger?.info(`Removing completed transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
|
|
1326
|
-
await this.pendingTransactions.delete(hash);
|
|
1327
|
-
ret = [
|
|
1328
|
-
hash,
|
|
1329
|
-
signedHydratedTransaction
|
|
1330
|
-
];
|
|
1331
|
-
} else {
|
|
1332
|
-
const currentBlockNumber = await this.viewer.currentBlockNumber();
|
|
1333
|
-
if (signedHydratedTransaction[0].exp < currentBlockNumber) {
|
|
1334
|
-
this.logger?.info(`Removing expired transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
|
|
1335
|
-
await this.pendingTransactions.delete(hash);
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
this._successCounter?.add(1);
|
|
1339
|
-
return ret;
|
|
1340
|
-
} catch (error) {
|
|
1341
|
-
this._errorCounter?.add(1);
|
|
1342
|
-
this.logger?.error(`Error checking for transaction ${signedHydratedTransaction[0]} with hash ${hash}:`, error);
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
|
|
1347
|
-
// src/manifest/getModuleLocator.ts
|
|
1348
|
-
var getModuleLocator = /* @__PURE__ */ __name(async (context) => {
|
|
1349
|
-
const { config, locator, logger } = context;
|
|
1350
|
-
const { otlpEndpoint } = config.telemetry?.otel ?? {};
|
|
1351
|
-
const { path: endpoint = "/metrics", port = 9468 } = config.telemetry?.metrics?.scrape ?? {};
|
|
1352
|
-
const { traceProvider, meterProvider } = await initTelemetry({
|
|
1353
|
-
attributes: {
|
|
1354
|
-
serviceName: "xl1-bridge",
|
|
1355
|
-
serviceVersion: "1.0.0"
|
|
1356
|
-
},
|
|
1357
|
-
otlpEndpoint,
|
|
1358
|
-
metricsConfig: {
|
|
1359
|
-
endpoint,
|
|
1360
|
-
port
|
|
1361
|
-
}
|
|
1362
|
-
});
|
|
1363
|
-
if (isDefined12(logger)) AbstractModule.defaultLogger = logger;
|
|
1364
|
-
const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : void 0;
|
|
1365
|
-
const moduleLocator = new ModuleFactoryLocator();
|
|
1366
|
-
const mongoConfig = config.storage?.mongo;
|
|
1367
|
-
if (hasMongoConfig(mongoConfig)) {
|
|
1368
|
-
const { connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName } = mongoConfig;
|
|
1369
|
-
const payloadSdkConfig = {
|
|
1370
|
-
dbConnectionString,
|
|
1371
|
-
dbDomain,
|
|
1372
|
-
dbName,
|
|
1373
|
-
dbPassword,
|
|
1374
|
-
dbUserName
|
|
1375
|
-
};
|
|
1376
|
-
const params = {
|
|
1377
|
-
meterProvider,
|
|
1378
|
-
payloadSdkConfig,
|
|
1379
|
-
statusReporter,
|
|
1380
|
-
traceProvider
|
|
1381
|
-
};
|
|
1382
|
-
moduleLocator.register(MongoDBArchivistV2.factory(params), void 0, true);
|
|
1383
|
-
}
|
|
1384
|
-
moduleLocator.register(MemoryArchivist.factory({
|
|
1385
|
-
traceProvider,
|
|
1386
|
-
meterProvider,
|
|
1387
|
-
statusReporter
|
|
1388
|
-
}));
|
|
1389
|
-
moduleLocator.register(MemorySentinel.factory({
|
|
1390
|
-
traceProvider,
|
|
1391
|
-
meterProvider,
|
|
1392
|
-
statusReporter
|
|
1393
|
-
}));
|
|
1394
|
-
moduleLocator.register(ViewArchivist.factory({
|
|
1395
|
-
traceProvider,
|
|
1396
|
-
meterProvider,
|
|
1397
|
-
statusReporter
|
|
1398
|
-
}));
|
|
1399
|
-
const gateway = await locator.getInstance(XyoGatewayRunnerMoniker);
|
|
1400
|
-
const viewer = assertEx16(gateway.connection.viewer, () => "Gateway viewer is not defined");
|
|
1401
|
-
const pendingXl1ToEthXl1BridgeIntentTransactions = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_xl1_pending");
|
|
1402
|
-
const completedXl1ToEthXl1BridgeIntentTransactions = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_xl1_completed");
|
|
1403
|
-
const xl1TransactionCompletionMonitorSentinelParams = {
|
|
1404
|
-
completedTransactions: completedXl1ToEthXl1BridgeIntentTransactions,
|
|
1405
|
-
config: {
|
|
1406
|
-
schema: XL1TransactionCompletionMonitorSentinelConfigSchema
|
|
1407
|
-
},
|
|
1408
|
-
meterProvider,
|
|
1409
|
-
pendingTransactions: pendingXl1ToEthXl1BridgeIntentTransactions,
|
|
1410
|
-
statusReporter,
|
|
1411
|
-
traceProvider,
|
|
1412
|
-
viewer
|
|
1413
|
-
};
|
|
1414
|
-
moduleLocator.register(XL1TransactionCompletionMonitorSentinel.factory(xl1TransactionCompletionMonitorSentinelParams));
|
|
1415
|
-
const completedEthXl1BridgeTransactions = await getIterableMap(config, "liquidity_bridge_eth_xl1_bridge_completed");
|
|
1416
|
-
const provider = await initEvmProvider({
|
|
1417
|
-
config
|
|
1418
|
-
});
|
|
1419
|
-
const bridgeAddress = config.actors.bridge.remoteBridgeContractAddress;
|
|
1420
|
-
const evmLiquidityBridgeTransactionCompletionMonitorSentinelParams = {
|
|
1421
|
-
bridgeAddress,
|
|
1422
|
-
completedTransactions: completedEthXl1BridgeTransactions,
|
|
1423
|
-
config: {
|
|
1424
|
-
schema: EVMLiquidityBridgeTransactionCompletionMonitorSentinelConfigSchema
|
|
1425
|
-
},
|
|
1426
|
-
meterProvider,
|
|
1427
|
-
pendingTransactions: completedXl1ToEthXl1BridgeIntentTransactions,
|
|
1428
|
-
provider,
|
|
1429
|
-
statusReporter,
|
|
1430
|
-
traceProvider
|
|
1431
|
-
};
|
|
1432
|
-
moduleLocator.register(EVMLiquidityBridgeTransactionCompletionMonitorSentinel.factory(evmLiquidityBridgeTransactionCompletionMonitorSentinelParams));
|
|
1433
|
-
return moduleLocator;
|
|
1434
|
-
}, "getModuleLocator");
|
|
1111
|
+
import { hasMongoConfig, mapToMapType } from "@xyo-network/xl1-sdk";
|
|
1435
1112
|
var getIterableMap = /* @__PURE__ */ __name(async (config, collection) => {
|
|
1436
1113
|
const mongoConfig = config.storage?.mongo;
|
|
1437
1114
|
if (hasMongoConfig(mongoConfig)) {
|
|
@@ -1460,110 +1137,19 @@ var getIterableMap = /* @__PURE__ */ __name(async (config, collection) => {
|
|
|
1460
1137
|
}
|
|
1461
1138
|
}, "getIterableMap");
|
|
1462
1139
|
|
|
1463
|
-
// src/
|
|
1464
|
-
import { assertEx as assertEx17 } from "@xylabs/sdk-js";
|
|
1465
|
-
import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
|
|
1466
|
-
import { buildJsonRpcProviderLocator, HttpRpcTransport } from "@xyo-network/xl1-sdk";
|
|
1467
|
-
|
|
1468
|
-
// src/manifest/node.json
|
|
1469
|
-
var node_default = {
|
|
1470
|
-
$schema: "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
|
|
1471
|
-
nodes: [
|
|
1472
|
-
{
|
|
1473
|
-
config: {
|
|
1474
|
-
accountPath: "44'/60'/1",
|
|
1475
|
-
name: "XYOEthereumBridge",
|
|
1476
|
-
schema: "network.xyo.node.config"
|
|
1477
|
-
},
|
|
1478
|
-
modules: {
|
|
1479
|
-
private: [],
|
|
1480
|
-
public: []
|
|
1481
|
-
}
|
|
1482
|
-
}
|
|
1483
|
-
],
|
|
1484
|
-
schema: "network.xyo.manifest"
|
|
1485
|
-
};
|
|
1486
|
-
|
|
1487
|
-
// src/manifest/nodeManifest.ts
|
|
1488
|
-
var NodeManifest = node_default;
|
|
1489
|
-
|
|
1490
|
-
// src/manifest/getNode.ts
|
|
1491
|
-
var getNode = /* @__PURE__ */ __name(async (context) => {
|
|
1492
|
-
const { config, wallet } = context;
|
|
1493
|
-
const endpoint = assertEx17(config.actors.bridge.remote?.rpc?.url ?? config.remote?.rpc?.url, () => "RPC URL is required for Node");
|
|
1494
|
-
const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport(endpoint, schemas), "transportFactory");
|
|
1495
|
-
const signerAccount = await getBridgeWalletAccount(config);
|
|
1496
|
-
const locator = await buildJsonRpcProviderLocator({
|
|
1497
|
-
signerAccount,
|
|
1498
|
-
transportFactory
|
|
1499
|
-
});
|
|
1500
|
-
const moduleLocator = await getModuleLocator({
|
|
1501
|
-
...context,
|
|
1502
|
-
locator
|
|
1503
|
-
});
|
|
1504
|
-
const wrapper = new ManifestWrapper(NodeManifest, wallet, moduleLocator, [], []);
|
|
1505
|
-
const [node, ...childNodes] = await wrapper.loadNodes();
|
|
1506
|
-
if (childNodes?.length > 0) {
|
|
1507
|
-
await Promise.all(childNodes.map((childNode) => node.register(childNode)));
|
|
1508
|
-
await Promise.all(childNodes.map((childNode) => node.attach(childNode.address, true)));
|
|
1509
|
-
}
|
|
1510
|
-
return node;
|
|
1511
|
-
}, "getNode");
|
|
1512
|
-
|
|
1513
|
-
// src/manifest/getServices.ts
|
|
1514
|
-
import { assertEx as assertEx18, isDefined as isDefined13 } from "@xylabs/sdk-js";
|
|
1515
|
-
import { initEvmProvider as initEvmProvider2 } from "@xyo-network/chain-orchestration";
|
|
1516
|
-
import { BridgeableToken__factory, LiquidityPoolBridge__factory as LiquidityPoolBridge__factory2 } from "@xyo-network/typechain";
|
|
1517
|
-
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
1518
|
-
import { getAddress as getAddress3, Wallet as Wallet2 } from "ethers";
|
|
1519
|
-
|
|
1520
|
-
// src/manifest/getIterableMap.ts
|
|
1521
|
-
import { BaseMongoSdk as BaseMongoSdk2 } from "@xylabs/mongo";
|
|
1522
|
-
import { MongoMap as MongoMap2 } from "@xyo-network/chain-protocol";
|
|
1523
|
-
import { hasMongoConfig as hasMongoConfig2, mapToMapType as mapToMapType2 } from "@xyo-network/xl1-sdk";
|
|
1524
|
-
var getIterableMap2 = /* @__PURE__ */ __name(async (config, collection) => {
|
|
1525
|
-
const mongoConfig = config.storage?.mongo;
|
|
1526
|
-
if (hasMongoConfig2(mongoConfig)) {
|
|
1527
|
-
const { connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName } = mongoConfig;
|
|
1528
|
-
const payloadSdkConfig = {
|
|
1529
|
-
dbConnectionString,
|
|
1530
|
-
dbDomain,
|
|
1531
|
-
dbName,
|
|
1532
|
-
dbPassword,
|
|
1533
|
-
dbUserName
|
|
1534
|
-
};
|
|
1535
|
-
const sdkBalanceSummaryMap = new BaseMongoSdk2({
|
|
1536
|
-
...payloadSdkConfig,
|
|
1537
|
-
collection
|
|
1538
|
-
});
|
|
1539
|
-
const result = await MongoMap2.create({
|
|
1540
|
-
sdk: sdkBalanceSummaryMap,
|
|
1541
|
-
getCache: {
|
|
1542
|
-
enabled: true,
|
|
1543
|
-
maxEntries: 5e3
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
return result;
|
|
1547
|
-
} else {
|
|
1548
|
-
return mapToMapType2(/* @__PURE__ */ new Map());
|
|
1549
|
-
}
|
|
1550
|
-
}, "getIterableMap");
|
|
1551
|
-
|
|
1552
|
-
// src/manifest/getServices.ts
|
|
1140
|
+
// src/services/getServices.ts
|
|
1553
1141
|
var getServices = /* @__PURE__ */ __name(async (context, gateway) => {
|
|
1554
1142
|
const { config } = context;
|
|
1555
|
-
const ethTxStateMap = await
|
|
1556
|
-
const xl1TxStateMap = await
|
|
1557
|
-
const provider = await
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
const
|
|
1561
|
-
const
|
|
1562
|
-
const
|
|
1563
|
-
const bridgeableToken = BridgeableToken__factory.connect(getAddress3(remoteTokenAddress), wallet);
|
|
1564
|
-
const bridge = LiquidityPoolBridge__factory2.connect(getAddress3(remoteBridgeContractAddress), wallet);
|
|
1143
|
+
const ethTxStateMap = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_eth_tx_state");
|
|
1144
|
+
const xl1TxStateMap = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_xl1_tx_state");
|
|
1145
|
+
const provider = await initEvmProvider(context);
|
|
1146
|
+
const { remoteBridgeContractAddress, remoteChainWalletPrivateKey, remoteTokenAddress, mnemonic } = config;
|
|
1147
|
+
const account = isDefined10(mnemonic) ? await HDWallet2.fromPhrase(mnemonic) : await HDWallet2.random();
|
|
1148
|
+
const wallet = new Wallet(remoteChainWalletPrivateKey, provider);
|
|
1149
|
+
const bridgeableToken = BridgeableToken__factory.connect(getAddress2(remoteTokenAddress), wallet);
|
|
1150
|
+
const bridge = LiquidityPoolBridge__factory.connect(getAddress2(remoteBridgeContractAddress), wallet);
|
|
1565
1151
|
const bridgeOwner = await bridge.owner();
|
|
1566
|
-
|
|
1152
|
+
assertEx16(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
|
|
1567
1153
|
return {
|
|
1568
1154
|
account,
|
|
1569
1155
|
bridge,
|
|
@@ -1584,43 +1170,11 @@ var addWorkers = /* @__PURE__ */ __name((config, services) => {
|
|
|
1584
1170
|
|
|
1585
1171
|
// src/server/server.ts
|
|
1586
1172
|
var hostname = "::";
|
|
1587
|
-
var getSeedPhrase = /* @__PURE__ */ __name(async (bios, config, logger) => {
|
|
1588
|
-
const storedSeedPhrase = await bios.seedPhraseStore.get("os");
|
|
1589
|
-
logger?.debug(`[Bridge] Stored mnemonic: ${storedSeedPhrase}`);
|
|
1590
|
-
const { mnemonic } = config.actors.api;
|
|
1591
|
-
if (isString(storedSeedPhrase) && isString(mnemonic)) {
|
|
1592
|
-
logger?.warn("[Bridge] Stored mnemonic does not match supplied. Updating stored mnemonic to supplied.");
|
|
1593
|
-
await bios.seedPhraseStore.set("os", mnemonic);
|
|
1594
|
-
} else {
|
|
1595
|
-
let seedPhrase;
|
|
1596
|
-
if (isString(mnemonic)) {
|
|
1597
|
-
seedPhrase = mnemonic;
|
|
1598
|
-
} else {
|
|
1599
|
-
seedPhrase = HDWallet3.generateMnemonic();
|
|
1600
|
-
logger?.log("[Bridge] No mnemonic provided, using random mnemonic. This is not recommended for production use.");
|
|
1601
|
-
logger?.log(`[Bridge] Mnemonic: ${seedPhrase}`);
|
|
1602
|
-
}
|
|
1603
|
-
await bios.seedPhraseStore.set("os", seedPhrase);
|
|
1604
|
-
}
|
|
1605
|
-
return assertEx19(await bios.seedPhraseStore.get("os"), () => "Unable to acquire mnemonic from bios");
|
|
1606
|
-
}, "getSeedPhrase");
|
|
1607
1173
|
var getServer = /* @__PURE__ */ __name(async (context, gateway) => {
|
|
1608
1174
|
const { logger, config } = context;
|
|
1609
|
-
const { port
|
|
1610
|
-
const
|
|
1611
|
-
const
|
|
1612
|
-
const wallet = await HDWallet3.fromPhrase(seedPhrase);
|
|
1613
|
-
const nodeContext = {
|
|
1614
|
-
wallet,
|
|
1615
|
-
logger,
|
|
1616
|
-
config
|
|
1617
|
-
};
|
|
1618
|
-
const node = context.node ?? await getNode(nodeContext);
|
|
1619
|
-
const app = getApp(node, config, gateway);
|
|
1620
|
-
const services = await getServices({
|
|
1621
|
-
config,
|
|
1622
|
-
logger
|
|
1623
|
-
}, gateway);
|
|
1175
|
+
const { port } = config;
|
|
1176
|
+
const app = getApp(config, gateway);
|
|
1177
|
+
const services = await getServices(context, gateway);
|
|
1624
1178
|
addWorkers(config, services);
|
|
1625
1179
|
const server = app.listen(port, hostname, () => logger?.log(`[Bridge] Server listening at http://${hostname}:${port}`));
|
|
1626
1180
|
server.setTimeout(2e4);
|
|
@@ -1646,7 +1200,7 @@ var BridgeActor = class extends ActorV3 {
|
|
|
1646
1200
|
}
|
|
1647
1201
|
async createHandler() {
|
|
1648
1202
|
await super.createHandler();
|
|
1649
|
-
this._gatewayRunner = await this.locator.getInstance(
|
|
1203
|
+
this._gatewayRunner = await this.locator.getInstance(XyoGatewayRunnerMoniker);
|
|
1650
1204
|
}
|
|
1651
1205
|
async startHandler() {
|
|
1652
1206
|
await super.startHandler();
|
|
@@ -1658,7 +1212,7 @@ var BridgeActor = class extends ActorV3 {
|
|
|
1658
1212
|
this.stopServer();
|
|
1659
1213
|
}
|
|
1660
1214
|
async startServer() {
|
|
1661
|
-
this.server = await getServer(this.context, this._gatewayRunner);
|
|
1215
|
+
this.server = await getServer(asBridgeConfigContext(this.context, true), this._gatewayRunner);
|
|
1662
1216
|
}
|
|
1663
1217
|
stopServer() {
|
|
1664
1218
|
this.server?.close();
|