@socket.tech/dl-common 1.0.6 → 1.0.7
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/dl-common/constants/confirmations.d.ts +5 -0
- package/dist/dl-common/constants/confirmations.js +17 -0
- package/dist/dl-common/constants/enums.d.ts +44 -0
- package/dist/dl-common/constants/enums.js +52 -0
- package/dist/dl-common/constants/index.d.ts +3 -0
- package/dist/dl-common/constants/index.js +19 -0
- package/dist/dl-common/constants/types.d.ts +126 -0
- package/dist/dl-common/constants/types.js +45 -0
- package/dist/dl-common/constants/waitTime.d.ts +8 -0
- package/dist/dl-common/constants/waitTime.js +49 -0
- package/dist/dl-common/index.d.ts +4 -0
- package/dist/dl-common/index.js +20 -0
- package/dist/dl-common/models/attestSignature.d.ts +35 -0
- package/dist/dl-common/models/attestSignature.js +53 -0
- package/dist/dl-common/models/attestation.d.ts +70 -0
- package/dist/dl-common/models/attestation.js +86 -0
- package/dist/dl-common/models/index.d.ts +7 -0
- package/dist/dl-common/models/index.js +23 -0
- package/dist/dl-common/models/lastBlock.d.ts +28 -0
- package/dist/dl-common/models/lastBlock.js +27 -0
- package/dist/dl-common/models/message.d.ts +166 -0
- package/dist/dl-common/models/message.js +183 -0
- package/dist/dl-common/models/packet.d.ts +241 -0
- package/dist/dl-common/models/packet.js +250 -0
- package/dist/dl-common/models/proposal.d.ts +127 -0
- package/dist/dl-common/models/proposal.js +141 -0
- package/dist/dl-common/models/switchboard.d.ts +69 -0
- package/dist/dl-common/models/switchboard.js +92 -0
- package/dist/dl-common/models/transaction.d.ts +0 -0
- package/dist/dl-common/models/transaction.js +280 -0
- package/dist/dl-common/services/cacheService.d.ts +14 -0
- package/dist/dl-common/services/cacheService.js +77 -0
- package/dist/dl-common/services/eventBridgeService.d.ts +8 -0
- package/dist/dl-common/services/eventBridgeService.js +40 -0
- package/dist/dl-common/services/index.d.ts +3 -0
- package/dist/dl-common/services/index.js +20 -0
- package/dist/dl-common/services/queueService.d.ts +10 -0
- package/dist/dl-common/services/queueService.js +62 -0
- package/dist/dl-common/utils/address.d.ts +2 -0
- package/dist/dl-common/utils/address.js +8 -0
- package/dist/dl-common/utils/axios.d.ts +2 -0
- package/dist/dl-common/utils/axios.js +54 -0
- package/dist/dl-common/utils/dataStructHelper.d.ts +2 -0
- package/dist/dl-common/utils/dataStructHelper.js +10 -0
- package/dist/dl-common/utils/discord.d.ts +2 -0
- package/dist/dl-common/utils/discord.js +35 -0
- package/dist/dl-common/utils/ethersAwsKmsSigner.d.ts +2 -0
- package/dist/dl-common/utils/ethersAwsKmsSigner.js +26 -0
- package/dist/dl-common/utils/eventGetter.d.ts +4 -0
- package/dist/dl-common/utils/eventGetter.js +50 -0
- package/dist/dl-common/utils/extraUtils.d.ts +32 -0
- package/dist/dl-common/utils/extraUtils.js +103 -0
- package/dist/dl-common/utils/idUtils.d.ts +14 -0
- package/dist/dl-common/utils/idUtils.js +50 -0
- package/dist/dl-common/utils/index.d.ts +13 -0
- package/dist/dl-common/utils/index.js +29 -0
- package/dist/dl-common/utils/relaySigner.d.ts +21 -0
- package/dist/dl-common/utils/relaySigner.js +68 -0
- package/dist/dl-common/utils/s3Service.d.ts +5 -0
- package/dist/dl-common/utils/s3Service.js +45 -0
- package/dist/dl-common/utils/secretManagerService.d.ts +2 -0
- package/dist/dl-common/utils/secretManagerService.js +33 -0
- package/dist/dl-common/utils/signer/adapter.d.ts +18 -0
- package/dist/dl-common/utils/signer/adapter.js +71 -0
- package/dist/dl-common/utils/signer/address.d.ts +10 -0
- package/dist/dl-common/utils/signer/address.js +42 -0
- package/dist/dl-common/utils/signer/asn1-parser.d.ts +11 -0
- package/dist/dl-common/utils/signer/asn1-parser.js +80 -0
- package/dist/dl-common/utils/signer/crypto.d.ts +6 -0
- package/dist/dl-common/utils/signer/crypto.js +34 -0
- package/dist/dl-common/utils/signer/index.d.ts +4 -0
- package/dist/dl-common/utils/signer/index.js +20 -0
- package/dist/dl-common/utils/signer/kms-ethers-signer.d.ts +19 -0
- package/dist/dl-common/utils/signer/kms-ethers-signer.js +32 -0
- package/dist/dl-common/utils/signer/kms-signer.d.ts +14 -0
- package/dist/dl-common/utils/signer/kms-signer.js +46 -0
- package/dist/dl-common/utils/signer/signature.d.ts +17 -0
- package/dist/dl-common/utils/signer/signature.js +65 -0
- package/dist/dl-common/utils/signer/signer.d.ts +7 -0
- package/dist/dl-common/utils/signer/signer.js +2 -0
- package/dist/dl-common/utils/time.d.ts +2 -0
- package/dist/dl-common/utils/time.js +7 -0
- package/dist/index.js +30 -14
- package/dist/src/constants/batcherModes.d.ts +7 -0
- package/dist/src/constants/batcherModes.js +56 -0
- package/dist/src/constants/config.d.ts +39 -0
- package/dist/src/constants/config.js +77 -0
- package/dist/src/constants/enums.d.ts +21 -0
- package/dist/src/constants/enums.js +27 -0
- package/dist/src/constants/gasEstimation.d.ts +8 -0
- package/dist/src/constants/gasEstimation.js +61 -0
- package/dist/src/constants/index.d.ts +11 -0
- package/dist/src/constants/index.js +28 -0
- package/dist/src/constants/limits.d.ts +21 -0
- package/dist/src/constants/limits.js +91 -0
- package/dist/src/constants/prometheus.config.d.ts +43 -0
- package/dist/src/constants/prometheus.config.js +316 -0
- package/dist/src/constants/relayer.d.ts +6 -0
- package/dist/src/constants/relayer.js +15 -0
- package/dist/src/constants/s3Config.d.ts +13 -0
- package/dist/src/constants/s3Config.js +61 -0
- package/dist/src/constants/stageConfig.d.ts +7 -0
- package/dist/src/constants/stageConfig.js +24 -0
- package/dist/src/constants/types.d.ts +45 -0
- package/dist/src/constants/types.js +2 -0
- package/dist/src/constants/watchers.d.ts +15 -0
- package/dist/src/constants/watchers.js +137 -0
- package/dist/src/controllers/index.d.ts +0 -0
- package/dist/src/controllers/index.js +3 -0
- package/dist/src/db/associations.d.ts +1 -0
- package/dist/src/db/associations.js +46 -0
- package/dist/src/db/connection.d.ts +4 -0
- package/dist/src/db/connection.js +73 -0
- package/dist/src/db/index.d.ts +2 -0
- package/dist/src/db/index.js +18 -0
- package/dist/src/db/init.d.ts +2 -0
- package/dist/src/db/init.js +27 -0
- package/dist/src/handlers/common.d.ts +2 -0
- package/dist/src/handlers/common.js +59 -0
- package/dist/src/handlers/cronHandler.d.ts +10 -0
- package/dist/src/handlers/cronHandler.js +268 -0
- package/dist/src/handlers/executeHandler.d.ts +3 -0
- package/dist/src/handlers/executeHandler.js +66 -0
- package/dist/src/handlers/handler.d.ts +2 -0
- package/dist/src/handlers/handler.js +29 -0
- package/dist/src/handlers/proposeHandler.d.ts +3 -0
- package/dist/src/handlers/proposeHandler.js +69 -0
- package/dist/src/handlers/routes.d.ts +2 -0
- package/dist/src/handlers/routes.js +26 -0
- package/dist/src/handlers/sealHandler.d.ts +4 -0
- package/dist/src/handlers/sealHandler.js +245 -0
- package/dist/src/handlers/statusHandler.d.ts +5 -0
- package/dist/src/handlers/statusHandler.js +116 -0
- package/dist/src/handlers/taskHandler.d.ts +2 -0
- package/dist/src/handlers/taskHandler.js +110 -0
- package/dist/src/handlers/testHandler.d.ts +4 -0
- package/dist/src/handlers/testHandler.js +99 -0
- package/dist/src/main.d.ts +0 -0
- package/dist/src/main.js +12 -0
- package/dist/src/relayers/common.d.ts +7 -0
- package/dist/src/relayers/common.js +55 -0
- package/dist/src/relayers/index.d.ts +2 -0
- package/dist/src/relayers/index.js +19 -0
- package/dist/src/relayers/proposeRelayer.d.ts +7 -0
- package/dist/src/relayers/proposeRelayer.js +587 -0
- package/dist/src/relayers/sealRelayer.d.ts +8 -0
- package/dist/src/relayers/sealRelayer.js +276 -0
- package/dist/src/services/attestService.d.ts +45 -0
- package/dist/src/services/attestService.js +269 -0
- package/dist/src/services/batcherService.d.ts +9 -0
- package/dist/src/services/batcherService.js +197 -0
- package/dist/src/services/executeService.d.ts +16 -0
- package/dist/src/services/executeService.js +209 -0
- package/dist/src/services/gasEstimationService.d.ts +3 -0
- package/dist/src/services/gasEstimationService.js +12 -0
- package/dist/src/services/index.d.ts +4 -0
- package/dist/src/services/index.js +23 -0
- package/dist/src/services/indexSealService.d.ts +15 -0
- package/dist/src/services/indexSealService.js +120 -0
- package/dist/src/services/proposalCheckService.d.ts +9 -0
- package/dist/src/services/proposalCheckService.js +119 -0
- package/dist/src/services/sealService.d.ts +27 -0
- package/dist/src/services/sealService.js +190 -0
- package/dist/src/statusTrackers/failedMessage.d.ts +8 -0
- package/dist/src/statusTrackers/failedMessage.js +72 -0
- package/dist/src/statusTrackers/failedPacket.d.ts +13 -0
- package/dist/src/statusTrackers/failedPacket.js +110 -0
- package/dist/src/statusTrackers/index.d.ts +3 -0
- package/dist/src/statusTrackers/index.js +26 -0
- package/dist/src/statusTrackers/message.d.ts +4 -0
- package/dist/src/statusTrackers/message.js +257 -0
- package/dist/src/statusTrackers/packet.d.ts +33 -0
- package/dist/src/statusTrackers/packet.js +477 -0
- package/dist/src/utils/chain-utils.d.ts +5 -0
- package/dist/src/utils/chain-utils.js +42 -0
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.js +18 -0
- package/dist/src/utils/logger.d.ts +9 -0
- package/dist/src/utils/logger.js +9 -0
- package/dist/utils/s3Service.js +1 -1
- package/dist/utils/signer/socketSigner.d.ts +32 -0
- package/dist/utils/signer/socketSigner.js +121 -0
- package/package.json +1 -1
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateSelectedProposalCount = exports.updateSelectedProposalCountForPackets = exports.getIncompletePackets = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const models_1 = require("../../dl-common/models");
|
|
7
|
+
const sequelize_1 = require("sequelize");
|
|
8
|
+
const savePacketDbUpdates = async (updates) => {
|
|
9
|
+
try {
|
|
10
|
+
(0, utils_1.logInfo)({
|
|
11
|
+
info: "UPDATING_DB_PROPOSAL_COUNT",
|
|
12
|
+
packetIds: updates.map((u) => u.packetId),
|
|
13
|
+
messageIds: [],
|
|
14
|
+
});
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
await models_1.Packet.bulkCreate(updates, {
|
|
17
|
+
updateOnDuplicate: ["selectedProposalCount"],
|
|
18
|
+
});
|
|
19
|
+
(0, utils_1.logInfo)({
|
|
20
|
+
info: "UPDATED_DB_PROPOSAL_COUNT",
|
|
21
|
+
packetIds: updates.map((u) => u.packetId),
|
|
22
|
+
messageIds: [],
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
utils_1.logger.error("Error while saving selectedProposalCount updates", error);
|
|
27
|
+
throw new Error("Error while saving selectedProposalCount updates");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const getIncompletePackets = async (dstChainSlug) => {
|
|
31
|
+
const packets = await models_1.Packet.findAll({
|
|
32
|
+
limit: constants_1.rootMatchIndexerQueryLimit,
|
|
33
|
+
attributes: [
|
|
34
|
+
"packetId",
|
|
35
|
+
"root",
|
|
36
|
+
"rootSealed",
|
|
37
|
+
"dstSwitchboard",
|
|
38
|
+
"srcChainSlug",
|
|
39
|
+
],
|
|
40
|
+
// add a limit and order by id desc clause
|
|
41
|
+
where: {
|
|
42
|
+
// here NO means not checked yet, default state
|
|
43
|
+
selectedProposalCount: null,
|
|
44
|
+
// isFullyExecuted:false, // TODO: remove this line after test done
|
|
45
|
+
srcChainSlug: {
|
|
46
|
+
[sequelize_1.Op.in]: constants_1.supportedChainSlugs,
|
|
47
|
+
},
|
|
48
|
+
dstChainSlug,
|
|
49
|
+
},
|
|
50
|
+
include: [
|
|
51
|
+
{
|
|
52
|
+
model: models_1.Proposal,
|
|
53
|
+
attributes: ["root", "packetId", "switchboard", "proposalCount"],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
// order: [[Sequelize.col("Packet.updatedAt"), "ASC"]],
|
|
57
|
+
});
|
|
58
|
+
console.log(dstChainSlug, "incomplete packets count", packets.length);
|
|
59
|
+
return packets;
|
|
60
|
+
};
|
|
61
|
+
exports.getIncompletePackets = getIncompletePackets;
|
|
62
|
+
const updateSelectedProposalCountForPackets = async (chainSlug) => {
|
|
63
|
+
const chains = chainSlug != null ? [chainSlug] : constants_1.supportedChainSlugs;
|
|
64
|
+
for (const chain of chains) {
|
|
65
|
+
await (0, exports.updateSelectedProposalCount)(chain);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
exports.updateSelectedProposalCountForPackets = updateSelectedProposalCountForPackets;
|
|
69
|
+
const updateSelectedProposalCount = async (dstChainSlug) => {
|
|
70
|
+
const packetDbUpdates = [];
|
|
71
|
+
const packetIdsWithoutValidProposals = [];
|
|
72
|
+
try {
|
|
73
|
+
// find packets where proposal and packet root is not matched, and switchboard type is fast or optimistic
|
|
74
|
+
const packets = await (0, exports.getIncompletePackets)(dstChainSlug);
|
|
75
|
+
(0, utils_1.logInfo)({
|
|
76
|
+
info: "UPDATING_PROPOSAL_COUNT",
|
|
77
|
+
packetIds: packets.map((u) => u.packetId),
|
|
78
|
+
messageIds: [],
|
|
79
|
+
});
|
|
80
|
+
for (const packet of packets) {
|
|
81
|
+
const proposals = packet.Proposals;
|
|
82
|
+
if (!(proposals === null || proposals === void 0 ? void 0 : proposals.length)) {
|
|
83
|
+
packetIdsWithoutValidProposals.push(packet.packetId);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
let isValidProposalFound = false;
|
|
87
|
+
for (const proposal of proposals) {
|
|
88
|
+
if (packet.dstSwitchboard === proposal.switchboard &&
|
|
89
|
+
packet.rootSealed === proposal.root) {
|
|
90
|
+
isValidProposalFound = true;
|
|
91
|
+
packetDbUpdates.push({
|
|
92
|
+
packetId: packet.packetId,
|
|
93
|
+
selectedProposalCount: proposal.proposalCount,
|
|
94
|
+
});
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!isValidProposalFound) {
|
|
99
|
+
packetIdsWithoutValidProposals.push(packet.packetId);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
(0, utils_1.logInfo)({
|
|
103
|
+
info: "VALID_PROPOSALS",
|
|
104
|
+
packetIds: packetIdsWithoutValidProposals,
|
|
105
|
+
messageIds: [],
|
|
106
|
+
});
|
|
107
|
+
await savePacketDbUpdates(packetDbUpdates);
|
|
108
|
+
(0, utils_1.logInfo)({
|
|
109
|
+
info: "UPDATED_PROPOSAL_COUNT",
|
|
110
|
+
packetIds: packetDbUpdates.map((u) => u.packetId),
|
|
111
|
+
messageIds: [],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
utils_1.logger.error(`error in updateSelectedProposalCount: ${error}`);
|
|
116
|
+
throw new Error(`error in updateSelectedProposalCount`);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.updateSelectedProposalCount = updateSelectedProposalCount;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type SealParams } from "../../dl-common";
|
|
2
|
+
export declare const seal: (sealRequests: SealParams[]) => Promise<any>;
|
|
3
|
+
interface MessageDBUpdate {
|
|
4
|
+
srcChainSlug: number;
|
|
5
|
+
dstChainSlug: number;
|
|
6
|
+
srcPlug: string;
|
|
7
|
+
destPlug: string;
|
|
8
|
+
messageId: string;
|
|
9
|
+
minMsgGasLimit: string;
|
|
10
|
+
executionParams: string;
|
|
11
|
+
transmissionParams: string;
|
|
12
|
+
executionFee: string;
|
|
13
|
+
transmissionFees: string;
|
|
14
|
+
switchboardFees: string;
|
|
15
|
+
fees: string;
|
|
16
|
+
decapacitorProof: string;
|
|
17
|
+
payload: string;
|
|
18
|
+
packedMessage: string;
|
|
19
|
+
outboundTxHash: string;
|
|
20
|
+
outboundTime: number;
|
|
21
|
+
capacitorMsgCount: string;
|
|
22
|
+
capacitorPacketCount: string;
|
|
23
|
+
rootHash: string;
|
|
24
|
+
packetId: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const registerFeesCollected: (messageUpdates: MessageDBUpdate[]) => Promise<void>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerFeesCollected = exports.seal = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const dl_core_1 = require("@socket.tech/dl-core");
|
|
7
|
+
const dl_common_1 = require("../../dl-common");
|
|
8
|
+
const utils_2 = require("ethers/lib/utils");
|
|
9
|
+
const seal = async (sealRequests) => {
|
|
10
|
+
var _a;
|
|
11
|
+
try {
|
|
12
|
+
(0, utils_1.logInfo)({
|
|
13
|
+
info: "SEAL_REQUESTS_INDEXING",
|
|
14
|
+
packetIds: sealRequests.map((s) => s.packet.packetId),
|
|
15
|
+
messageIds: sealRequests.map((s) => s.message.messageId),
|
|
16
|
+
});
|
|
17
|
+
const chainSlug = (_a = sealRequests[0]) === null || _a === void 0 ? void 0 : _a.srcChainSlug;
|
|
18
|
+
const sealRequestPacketIds = sealRequests.map((s) => s.packet.packetId);
|
|
19
|
+
const packetDbUpdates = [];
|
|
20
|
+
const messageDbUpdates = [];
|
|
21
|
+
// signatureDbUpdates = [];
|
|
22
|
+
sealRequests.map((sealRequest) => {
|
|
23
|
+
const { srcChainSlug, dstChainSlug, dstSwitchboard, srcSwitchboard, integrationType, } = sealRequest;
|
|
24
|
+
const { root, capacitorPacketCount } = sealRequest.packet;
|
|
25
|
+
const { outboundTime, outboundTxHash } = sealRequest.message;
|
|
26
|
+
messageDbUpdates.push({
|
|
27
|
+
...sealRequest.message,
|
|
28
|
+
srcChainSlug,
|
|
29
|
+
dstChainSlug,
|
|
30
|
+
packetId: sealRequest.packet.packetId,
|
|
31
|
+
rootHash: root,
|
|
32
|
+
capacitorPacketCount,
|
|
33
|
+
});
|
|
34
|
+
packetDbUpdates.push({
|
|
35
|
+
srcChainSlug,
|
|
36
|
+
dstChainSlug,
|
|
37
|
+
switchboardId: `${srcChainSlug}-${dstChainSlug}-${srcSwitchboard.toLowerCase()}`,
|
|
38
|
+
dstSwitchboard,
|
|
39
|
+
integrationType,
|
|
40
|
+
...sealRequest.packet,
|
|
41
|
+
outboundTime,
|
|
42
|
+
outboundTxHash,
|
|
43
|
+
isFilled: true,
|
|
44
|
+
executionWaitTime: Date.now() / 1000 +
|
|
45
|
+
(0, dl_common_1.getWaitTime)(integrationType, srcChainSlug, dstChainSlug), // seconds
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
if (packetDbUpdates.length > 0)
|
|
49
|
+
await savePacketUpdates(packetDbUpdates);
|
|
50
|
+
if (messageDbUpdates.length > 0)
|
|
51
|
+
await saveMessageUpdates(messageDbUpdates);
|
|
52
|
+
(0, utils_1.logInfo)({
|
|
53
|
+
info: "SEAL_REQUESTS_QUEUING",
|
|
54
|
+
packetIds: sealRequests.map((s) => s.packet.packetId),
|
|
55
|
+
messageIds: sealRequests.map((s) => s.message.messageId),
|
|
56
|
+
});
|
|
57
|
+
await (0, dl_common_1.sendStandardSqsMessage)(constants_1.SQS_BASE_URL + constants_1.QueueName.BATCHER_TASK_QUEUE, {
|
|
58
|
+
type: constants_1.TaskNames.RELAY_SEAL,
|
|
59
|
+
data: {
|
|
60
|
+
chainSlug,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
(0, utils_1.logInfo)({
|
|
64
|
+
info: "SEAL_REQUESTS_QUEUED",
|
|
65
|
+
packetIds: sealRequests.map((s) => s.packet.packetId),
|
|
66
|
+
messageIds: sealRequests.map((s) => s.message.messageId),
|
|
67
|
+
});
|
|
68
|
+
await (0, exports.registerFeesCollected)(messageDbUpdates);
|
|
69
|
+
// await sendPendingSimulationRequest();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
utils_1.logger.error("Error", error);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.seal = seal;
|
|
77
|
+
const saveMessageUpdates = async (dbUpdates) => {
|
|
78
|
+
try {
|
|
79
|
+
(0, utils_1.logInfo)({
|
|
80
|
+
info: "SEAL_REQUESTS_UPDATING_MSG_DB",
|
|
81
|
+
messageIds: dbUpdates.map((s) => s.messageId),
|
|
82
|
+
packetIds: [],
|
|
83
|
+
});
|
|
84
|
+
//@ts-ignore
|
|
85
|
+
await dl_common_1.Message.bulkCreate(dbUpdates, {
|
|
86
|
+
updateOnDuplicate: [
|
|
87
|
+
"srcChainSlug",
|
|
88
|
+
"dstChainSlug",
|
|
89
|
+
"srcPlug",
|
|
90
|
+
"destPlug",
|
|
91
|
+
"executionParams",
|
|
92
|
+
"transmissionParams",
|
|
93
|
+
"minMsgGasLimit",
|
|
94
|
+
"executionFee",
|
|
95
|
+
"transmissionFees",
|
|
96
|
+
"switchboardFees",
|
|
97
|
+
"fees",
|
|
98
|
+
"payload",
|
|
99
|
+
"decapacitorProof",
|
|
100
|
+
"packedMessage",
|
|
101
|
+
"outboundTime",
|
|
102
|
+
"outboundTxHash",
|
|
103
|
+
"capacitorMsgCount",
|
|
104
|
+
"capacitorPacketCount",
|
|
105
|
+
"rootHash",
|
|
106
|
+
"packetId",
|
|
107
|
+
],
|
|
108
|
+
});
|
|
109
|
+
(0, utils_1.logInfo)({
|
|
110
|
+
info: "SEAL_REQUESTS_UPDATED_MSG_DB",
|
|
111
|
+
messageIds: dbUpdates.map((s) => s.messageId),
|
|
112
|
+
packetIds: [],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
utils_1.logger.error("Error while saving new message updates", error);
|
|
117
|
+
throw new Error(`Error while saving new message updates ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const savePacketUpdates = async (dbUpdates) => {
|
|
121
|
+
(0, utils_1.logInfo)({
|
|
122
|
+
info: "SEAL_REQUESTS_UPDATING_PKT_DB",
|
|
123
|
+
packetIds: dbUpdates.map((s) => s.packetId),
|
|
124
|
+
messageIds: [],
|
|
125
|
+
});
|
|
126
|
+
try {
|
|
127
|
+
//@ts-ignore
|
|
128
|
+
await dl_common_1.Packet.bulkCreate(dbUpdates, {
|
|
129
|
+
updateOnDuplicate: [
|
|
130
|
+
"srcChainSlug",
|
|
131
|
+
"dstChainSlug",
|
|
132
|
+
"srcCapacitor",
|
|
133
|
+
"dstSwitchboard",
|
|
134
|
+
"switchboardId",
|
|
135
|
+
"capacitorPacketCount",
|
|
136
|
+
"integrationType",
|
|
137
|
+
"root",
|
|
138
|
+
"isFilled",
|
|
139
|
+
"outboundTime",
|
|
140
|
+
"executionWaitTime",
|
|
141
|
+
"outboundTxHash",
|
|
142
|
+
"sealSignature",
|
|
143
|
+
],
|
|
144
|
+
});
|
|
145
|
+
(0, utils_1.logInfo)({
|
|
146
|
+
info: "SEAL_REQUESTS_UPDATED_PKT_DB",
|
|
147
|
+
packetIds: dbUpdates.map((s) => s.packetId),
|
|
148
|
+
messageIds: [],
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
utils_1.logger.error("Error while saving new packet updates", error);
|
|
153
|
+
throw new Error(`Error while saving new packet updates ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const registerFeesCollected = async (messageUpdates) => {
|
|
157
|
+
try {
|
|
158
|
+
let feesCollectedArray = [];
|
|
159
|
+
messageUpdates.map((message) => {
|
|
160
|
+
var _a;
|
|
161
|
+
feesCollectedArray.push({
|
|
162
|
+
chainId: dl_core_1.ChainSlugToId[message.srcChainSlug],
|
|
163
|
+
txHash: message.outboundTxHash,
|
|
164
|
+
identifier: message.messageId,
|
|
165
|
+
metadata: {
|
|
166
|
+
packetId: message.packetId,
|
|
167
|
+
},
|
|
168
|
+
feeToken: (_a = constants_1.s3Config.chains[message.srcChainSlug]) === null || _a === void 0 ? void 0 : _a.nativeToken,
|
|
169
|
+
feeAmount: (0, utils_2.formatEther)(message.fees),
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
await (0, dl_common_1.axiosPost)(constants_1.relayerBaseUrl + "/registerFeesCollected", {
|
|
173
|
+
feesCollectedArray,
|
|
174
|
+
}, {
|
|
175
|
+
headers: {
|
|
176
|
+
"x-api-key": constants_1.relayerAPIKey,
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
(0, utils_1.logInfo)({
|
|
180
|
+
info: "REGISTERED_COLLECTED_FEES",
|
|
181
|
+
messagesCount: messageUpdates.length,
|
|
182
|
+
packetIds: [],
|
|
183
|
+
messageIds: []
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.log("Error while registering collected fees : ", error);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
exports.registerFeesCollected = registerFeesCollected;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface MessageDbUpdate {
|
|
2
|
+
messageId?: string;
|
|
3
|
+
isExecuted?: boolean;
|
|
4
|
+
executeRelayStatus?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const checkFailedMessages: (messageIds: string[], dryRun?: boolean) => Promise<MessageDbUpdate[] | undefined>;
|
|
7
|
+
export declare const saveMessageUpdates: (dbUpdates: MessageDbUpdate[]) => Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveMessageUpdates = exports.checkFailedMessages = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
5
|
+
const models_1 = require("@dl-common/models");
|
|
6
|
+
const common_1 = require("../relayers/common");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const checkFailedMessages = async (messageIds, dryRun = true) => {
|
|
9
|
+
if (!(messageIds === null || messageIds === void 0 ? void 0 : messageIds.length))
|
|
10
|
+
return;
|
|
11
|
+
const messages = await models_1.Message.findAll({
|
|
12
|
+
where: { messageId: messageIds },
|
|
13
|
+
raw: true,
|
|
14
|
+
});
|
|
15
|
+
const messageMap = new Map();
|
|
16
|
+
const response = [];
|
|
17
|
+
for (const message of messages) {
|
|
18
|
+
messageMap.set(message.messageId, message);
|
|
19
|
+
}
|
|
20
|
+
const messageDbUpdates = {};
|
|
21
|
+
for (const message of messages) {
|
|
22
|
+
const messageId = message.messageId;
|
|
23
|
+
messageDbUpdates[messageId] = { messageId };
|
|
24
|
+
if (message.executeRelayStatus === models_1.ExecutionRelayStatus.EXECUTE_FAILED ||
|
|
25
|
+
message.executeRelayStatus === models_1.ExecutionRelayStatus.NO) {
|
|
26
|
+
const isExecuted = await checkIfExecuted(message);
|
|
27
|
+
console.log({ messageId, isExecuted });
|
|
28
|
+
if (isExecuted) {
|
|
29
|
+
messageDbUpdates[messageId] = {
|
|
30
|
+
isExecuted: true,
|
|
31
|
+
executeRelayStatus: models_1.ExecutionRelayStatus.EXECUTED,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
messageDbUpdates[messageId] = {
|
|
36
|
+
isExecuted: false,
|
|
37
|
+
executeRelayStatus: models_1.ExecutionRelayStatus.NO,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
response.push(messageDbUpdates[messageId]);
|
|
42
|
+
messageDbUpdates[messageId] = {
|
|
43
|
+
...message,
|
|
44
|
+
...messageDbUpdates[messageId],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
console.log({ response });
|
|
48
|
+
if (dryRun)
|
|
49
|
+
return response;
|
|
50
|
+
await (0, exports.saveMessageUpdates)(Object.values(messageDbUpdates));
|
|
51
|
+
return response;
|
|
52
|
+
};
|
|
53
|
+
exports.checkFailedMessages = checkFailedMessages;
|
|
54
|
+
const checkIfExecuted = async (message) => {
|
|
55
|
+
const socketContract = await (0, common_1.getSocket)(message.dstChainSlug, {});
|
|
56
|
+
return await socketContract.messageExecuted(message.messageId);
|
|
57
|
+
};
|
|
58
|
+
const saveMessageUpdates = async (dbUpdates) => {
|
|
59
|
+
try {
|
|
60
|
+
if (dbUpdates.length === 0)
|
|
61
|
+
return;
|
|
62
|
+
// TODO: fix this
|
|
63
|
+
await models_1.Message.bulkCreate(dbUpdates, {
|
|
64
|
+
updateOnDuplicate: ["isExecuted", "executeRelayStatus"],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
utils_1.logger.error("Error while saving failed message updates", error);
|
|
69
|
+
throw new Error(`Error while saving failed message updates ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.saveMessageUpdates = saveMessageUpdates;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface PacketDbUpdate {
|
|
2
|
+
packetId?: string;
|
|
3
|
+
isSealed?: boolean;
|
|
4
|
+
sealRelayStatus?: string;
|
|
5
|
+
isProposed?: boolean;
|
|
6
|
+
proposeRelayStatus?: string;
|
|
7
|
+
selectedProposalCount?: number;
|
|
8
|
+
isAttested?: boolean;
|
|
9
|
+
attestRelayStatus?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const checkFailedPackets: (packetIds: string[], dryRun?: boolean) => Promise<PacketDbUpdate[] | undefined>;
|
|
12
|
+
export declare const savePacketUpdates: (dbUpdates: PacketDbUpdate[]) => Promise<void>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.savePacketUpdates = exports.checkFailedPackets = void 0;
|
|
4
|
+
const models_1 = require("@dl-common/models");
|
|
5
|
+
const common_1 = require("../relayers/common");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const utils_2 = require("@dl-common/utils");
|
|
8
|
+
const checkFailedPackets = async (packetIds, dryRun = true) => {
|
|
9
|
+
if (!(packetIds === null || packetIds === void 0 ? void 0 : packetIds.length))
|
|
10
|
+
return;
|
|
11
|
+
const packets = await models_1.Packet.findAll({
|
|
12
|
+
where: { packetId: packetIds },
|
|
13
|
+
raw: true,
|
|
14
|
+
});
|
|
15
|
+
const response = [];
|
|
16
|
+
const packetMap = new Map();
|
|
17
|
+
for (const packet of packets) {
|
|
18
|
+
packetMap.set(packet.packetId, packet);
|
|
19
|
+
}
|
|
20
|
+
const packetDbUpdates = {};
|
|
21
|
+
for (const packet of packets) {
|
|
22
|
+
const packetId = packet.packetId;
|
|
23
|
+
packetDbUpdates[packetId] = { packetId };
|
|
24
|
+
if (packet.proposeRelayStatus === models_1.ProposeRelayStatus.PROPOSE_FAILED) {
|
|
25
|
+
const { isProposed, selectedProposalCount } = await checkIfProposed(packet);
|
|
26
|
+
if (isProposed) {
|
|
27
|
+
packetDbUpdates[packetId] = {
|
|
28
|
+
...packetDbUpdates[packetId],
|
|
29
|
+
isProposed: true,
|
|
30
|
+
proposeRelayStatus: models_1.ProposeRelayStatus.PROPOSED,
|
|
31
|
+
selectedProposalCount,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
packetDbUpdates[packetId] = {
|
|
36
|
+
...packetDbUpdates[packetId],
|
|
37
|
+
isProposed: false,
|
|
38
|
+
proposeRelayStatus: models_1.ProposeRelayStatus.NO,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (packet.attestRelayStatus === models_1.AttestRelayStatus.ATTEST_FAILED) {
|
|
43
|
+
const isAttested = await checkIfAttested(packet);
|
|
44
|
+
if (isAttested) {
|
|
45
|
+
packetDbUpdates[packetId] = {
|
|
46
|
+
...packetDbUpdates[packetId],
|
|
47
|
+
isAttested: true,
|
|
48
|
+
attestRelayStatus: models_1.AttestRelayStatus.ATTESTED,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
packetDbUpdates[packetId] = {
|
|
53
|
+
...packetDbUpdates[packetId],
|
|
54
|
+
isAttested: false,
|
|
55
|
+
attestRelayStatus: models_1.AttestRelayStatus.NO,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
response.push(packetDbUpdates[packetId]);
|
|
60
|
+
packetDbUpdates[packetId] = {
|
|
61
|
+
...packet,
|
|
62
|
+
...packetDbUpdates[packetId],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
console.log({ response });
|
|
66
|
+
if (dryRun)
|
|
67
|
+
return response;
|
|
68
|
+
await (0, exports.savePacketUpdates)(Object.values(packetDbUpdates));
|
|
69
|
+
return response;
|
|
70
|
+
};
|
|
71
|
+
exports.checkFailedPackets = checkFailedPackets;
|
|
72
|
+
const checkIfProposed = async (packet) => {
|
|
73
|
+
let isProposed = false, selectedProposalCount = 0;
|
|
74
|
+
for (let i = 0; i < 5; i++) {
|
|
75
|
+
const socketContract = await (0, common_1.getSocket)(packet.dstChainSlug, {});
|
|
76
|
+
const packetRoot = await socketContract.packetIdRoots(packet.packetId, i, packet.dstSwitchboard);
|
|
77
|
+
if (packetRoot == packet.root) {
|
|
78
|
+
isProposed = true;
|
|
79
|
+
selectedProposalCount = i;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { isProposed, selectedProposalCount };
|
|
84
|
+
};
|
|
85
|
+
const checkIfAttested = async (packet) => {
|
|
86
|
+
const fastSwitchboard = await (0, common_1.getFastSwitchboard)(packet.dstChainSlug, {});
|
|
87
|
+
console.log(packet.root, packet.packetId, packet.selectedProposalCount, packet.srcChainSlug, (0, utils_2.currentTimestampInSeconds)());
|
|
88
|
+
return await fastSwitchboard.allowPacket(packet.root, packet.packetId, packet.selectedProposalCount, packet.srcChainSlug, (0, utils_2.currentTimestampInSeconds)() - 1000);
|
|
89
|
+
};
|
|
90
|
+
const savePacketUpdates = async (dbUpdates) => {
|
|
91
|
+
try {
|
|
92
|
+
if (dbUpdates.length === 0)
|
|
93
|
+
return;
|
|
94
|
+
// TODO: fix this
|
|
95
|
+
await models_1.Packet.bulkCreate(dbUpdates, {
|
|
96
|
+
updateOnDuplicate: [
|
|
97
|
+
"isProposed",
|
|
98
|
+
"proposeRelayStatus",
|
|
99
|
+
"selectedProposalCount",
|
|
100
|
+
"isAttested",
|
|
101
|
+
"attestRelayStatus",
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
utils_1.logger.error("Error while saving packet trip reason updates", error);
|
|
107
|
+
throw new Error(`Error while saving packet trip reason updates ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
exports.savePacketUpdates = savePacketUpdates;
|
|
@@ -0,0 +1,26 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.checkAndUpdateStatus = void 0;
|
|
18
|
+
const message_1 = require("./message");
|
|
19
|
+
const packet_1 = require("./packet");
|
|
20
|
+
__exportStar(require("./message"), exports);
|
|
21
|
+
__exportStar(require("./packet"), exports);
|
|
22
|
+
const checkAndUpdateStatus = async () => {
|
|
23
|
+
await (0, message_1.checkAndUpdateMessageRelayStatus)();
|
|
24
|
+
await (0, packet_1.checkAndUpdatePacketRelayStatus)();
|
|
25
|
+
};
|
|
26
|
+
exports.checkAndUpdateStatus = checkAndUpdateStatus;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type TxStatusUpdate } from "../constants";
|
|
2
|
+
export declare const checkAndUpdateMessageRelayStatus: () => Promise<void>;
|
|
3
|
+
export declare const getMessagesByTxId: (txIds: string[]) => Promise<any[]>;
|
|
4
|
+
export declare const updateMessageTxStatus: (updates: TxStatusUpdate[]) => Promise<void>;
|