@socket.tech/dl-common 1.0.2-test.3 → 1.0.2-test.5

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/README.md CHANGED
@@ -1 +1,18 @@
1
1
  # dl-batcher-service
2
+
3
+ to start server locally,
4
+ `npm run start`
5
+
6
+ to deploy complete service to dev,
7
+ `npm run deploy`
8
+
9
+ to deploy a sepific function (for example if change in apis, can only deploy routeHandler. Similarly if only change in cron timings, can deploy only cronHandler) -
10
+ `sls deploy -f cronHandler`
11
+
12
+ to check logs locally in terminal -
13
+ `sls logs -f <function>`
14
+
15
+ for publishing -
16
+ `yarn lint`
17
+ `yarn run build`
18
+ `npm publish`
@@ -0,0 +1,33 @@
1
+ export declare enum tableNames {
2
+ packet = "packets",
3
+ signature = "signatures",
4
+ attestation = "attestations",
5
+ message = "messages",
6
+ nativePacket = "native_packets",
7
+ proposal = "proposals",
8
+ switchboard = "switchboards",
9
+ tripState = "trip_states",
10
+ attestSignatures = "attest_signatures"
11
+ }
12
+ export declare enum MessageStatuses {
13
+ RECEIVED = "RECEIVED",
14
+ SEALED = "SEALED",
15
+ PROPOSED = "PROPOSED",
16
+ CONFIRMED = "CONFIRMED",
17
+ EXECUTION_SUCCESS = "EXECUTION_SUCCESS",
18
+ EXECUTION_FAILURE = "EXECUTION_FAILURE"
19
+ }
20
+ export declare enum MessageStatusStep {
21
+ RECEIVED = 0,
22
+ SEALED = 1,
23
+ PROPOSED = 2,
24
+ CONFIRMED = 3,
25
+ EXECUTION_SUCCESS = 4,
26
+ EXECUTION_FAILURE = 5
27
+ }
28
+ export declare enum StatusCodes {
29
+ SUCCESS = "SUCCESS",
30
+ NOT_FOUND = "NOT_FOUND",
31
+ BAD_REQUEST = "BAD_REQUEST",
32
+ INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"
33
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StatusCodes = exports.MessageStatusStep = exports.MessageStatuses = exports.tableNames = void 0;
4
+ var tableNames;
5
+ (function (tableNames) {
6
+ tableNames["packet"] = "packets";
7
+ tableNames["signature"] = "signatures";
8
+ tableNames["attestation"] = "attestations";
9
+ tableNames["message"] = "messages";
10
+ tableNames["nativePacket"] = "native_packets";
11
+ tableNames["proposal"] = "proposals";
12
+ tableNames["switchboard"] = "switchboards";
13
+ tableNames["tripState"] = "trip_states";
14
+ tableNames["attestSignatures"] = "attest_signatures";
15
+ })(tableNames || (exports.tableNames = tableNames = {}));
16
+ var MessageStatuses;
17
+ (function (MessageStatuses) {
18
+ MessageStatuses["RECEIVED"] = "RECEIVED";
19
+ MessageStatuses["SEALED"] = "SEALED";
20
+ MessageStatuses["PROPOSED"] = "PROPOSED";
21
+ MessageStatuses["CONFIRMED"] = "CONFIRMED";
22
+ MessageStatuses["EXECUTION_SUCCESS"] = "EXECUTION_SUCCESS";
23
+ MessageStatuses["EXECUTION_FAILURE"] = "EXECUTION_FAILURE";
24
+ })(MessageStatuses || (exports.MessageStatuses = MessageStatuses = {}));
25
+ var MessageStatusStep;
26
+ (function (MessageStatusStep) {
27
+ MessageStatusStep[MessageStatusStep["RECEIVED"] = 0] = "RECEIVED";
28
+ MessageStatusStep[MessageStatusStep["SEALED"] = 1] = "SEALED";
29
+ MessageStatusStep[MessageStatusStep["PROPOSED"] = 2] = "PROPOSED";
30
+ MessageStatusStep[MessageStatusStep["CONFIRMED"] = 3] = "CONFIRMED";
31
+ MessageStatusStep[MessageStatusStep["EXECUTION_SUCCESS"] = 4] = "EXECUTION_SUCCESS";
32
+ MessageStatusStep[MessageStatusStep["EXECUTION_FAILURE"] = 5] = "EXECUTION_FAILURE";
33
+ })(MessageStatusStep || (exports.MessageStatusStep = MessageStatusStep = {}));
34
+ var StatusCodes;
35
+ (function (StatusCodes) {
36
+ StatusCodes["SUCCESS"] = "SUCCESS";
37
+ StatusCodes["NOT_FOUND"] = "NOT_FOUND";
38
+ StatusCodes["BAD_REQUEST"] = "BAD_REQUEST";
39
+ StatusCodes["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
40
+ })(StatusCodes || (exports.StatusCodes = StatusCodes = {}));
@@ -1 +1,3 @@
1
1
  export * from "./waitTime";
2
+ export * from "./enums";
3
+ export * from "./types";
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./waitTime"), exports);
18
+ __exportStar(require("./enums"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,104 @@
1
+ import { TripReason } from "../models";
2
+ import { StatusCodes } from "./enums";
3
+ import { ChainSlug, IntegrationTypes } from "@socket.tech/dl-core";
4
+ export type Speed = "safeLow" | "average" | "fast" | "fastest";
5
+ export declare enum InboundStatus {
6
+ NOT_TRIED = "NOT_TRIED",
7
+ REVERTING = "REVERTING",
8
+ EXECUTING = "EXECUTING",
9
+ SUCCESS = "SUCCESS"
10
+ }
11
+ export interface FeeEstimate {
12
+ transmissionFees: string;
13
+ verificationFees: string;
14
+ executionFees: string;
15
+ totalFees: string;
16
+ }
17
+ export declare enum RelayerAPIStatus {
18
+ FAILED = "FAILED",
19
+ SIMULATION_FAILED = "SIMULATION_FAILED",
20
+ COMPLETED = "COMPLETED"
21
+ }
22
+ export declare class ServerError {
23
+ code: Omit<StatusCodes, StatusCodes.SUCCESS>;
24
+ message?: string;
25
+ constructor(code: Omit<StatusCodes, StatusCodes.SUCCESS>, message?: string);
26
+ toString(): string;
27
+ }
28
+ export declare const BadRequestError: (message?: string) => ServerError;
29
+ export declare const InternalServerError: (message?: string) => ServerError;
30
+ export interface EthersError {
31
+ reason?: string;
32
+ code?: string;
33
+ argument?: string;
34
+ value?: string;
35
+ }
36
+ export type SealParams = {
37
+ srcChainSlug: number;
38
+ dstChainSlug: number;
39
+ dstSwitchboard: string;
40
+ integrationType: IntegrationTypes;
41
+ message: {
42
+ messageId: string;
43
+ srcPlug: string;
44
+ destPlug: string;
45
+ minMsgGasLimit: string;
46
+ executionParams: string;
47
+ transmissionParams: string;
48
+ executionFee: string;
49
+ transmissionFees: string;
50
+ switchboardFees: string;
51
+ fees: string;
52
+ decapacitorProof: string;
53
+ payload: string;
54
+ packedMessage: string;
55
+ outboundTxHash: string;
56
+ outboundTime: number;
57
+ capacitorMsgCount: string;
58
+ };
59
+ packet: {
60
+ capacitorPacketCount: string;
61
+ packetId: string;
62
+ srcCapacitor: string;
63
+ root: string;
64
+ sealSignature: string;
65
+ };
66
+ };
67
+ export type SealIndexedParams = {
68
+ srcChainSlug: number;
69
+ sealer: string;
70
+ sealTime: number;
71
+ sealTxHash: string;
72
+ rootSealed: string;
73
+ dstSwitchboard: string;
74
+ sealSignature: string;
75
+ packetId: string;
76
+ };
77
+ export interface ExecuteSigResponse {
78
+ messageId: string;
79
+ retry: boolean;
80
+ inboundSuccess: boolean;
81
+ inboundRevertString: string;
82
+ executeSignature: string;
83
+ executeMsgGasLimit: string;
84
+ }
85
+ export interface AttestRequest {
86
+ switchboardAddress: string;
87
+ dstChainSlug: ChainSlug;
88
+ packetId: string;
89
+ root: string;
90
+ proposalCount: number;
91
+ }
92
+ export interface AttestSuccess {
93
+ proposalValid: true;
94
+ packetId: string;
95
+ proposalCount: number;
96
+ signature: string;
97
+ }
98
+ export interface AttestFailure {
99
+ proposalValid: false;
100
+ packetId: string;
101
+ proposalCount: number;
102
+ reason: TripReason;
103
+ }
104
+ export type AttestResponse = AttestSuccess | AttestFailure;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalServerError = exports.BadRequestError = exports.ServerError = exports.RelayerAPIStatus = exports.InboundStatus = void 0;
4
+ const enums_1 = require("./enums");
5
+ var InboundStatus;
6
+ (function (InboundStatus) {
7
+ InboundStatus["NOT_TRIED"] = "NOT_TRIED";
8
+ InboundStatus["REVERTING"] = "REVERTING";
9
+ InboundStatus["EXECUTING"] = "EXECUTING";
10
+ InboundStatus["SUCCESS"] = "SUCCESS";
11
+ })(InboundStatus || (exports.InboundStatus = InboundStatus = {}));
12
+ var RelayerAPIStatus;
13
+ (function (RelayerAPIStatus) {
14
+ RelayerAPIStatus["FAILED"] = "FAILED";
15
+ RelayerAPIStatus["SIMULATION_FAILED"] = "SIMULATION_FAILED";
16
+ RelayerAPIStatus["COMPLETED"] = "COMPLETED";
17
+ })(RelayerAPIStatus || (exports.RelayerAPIStatus = RelayerAPIStatus = {}));
18
+ class ServerError {
19
+ constructor(code, message) {
20
+ this.code = code;
21
+ if (message) {
22
+ this.message = message;
23
+ }
24
+ }
25
+ toString() {
26
+ return `code: ${this.code}, message: ${this.message}`;
27
+ }
28
+ }
29
+ exports.ServerError = ServerError;
30
+ const BadRequestError = (message) => {
31
+ return new ServerError(enums_1.StatusCodes.BAD_REQUEST, message);
32
+ };
33
+ exports.BadRequestError = BadRequestError;
34
+ const InternalServerError = (message) => {
35
+ return new ServerError(enums_1.StatusCodes.INTERNAL_SERVER_ERROR, message);
36
+ };
37
+ exports.InternalServerError = InternalServerError;
@@ -21,10 +21,18 @@ const getWaitTime = (integrationType, srcChainSlug, dstChainSlug) => {
21
21
  exports.getWaitTime = getWaitTime;
22
22
  exports.NativeWaitTime = {
23
23
  [dl_core_1.ChainSlug.OPTIMISM_GOERLI]: {
24
- [dl_core_1.ChainSlug.GOERLI]: 15 * 60,
24
+ [dl_core_1.ChainSlug.GOERLI]: 5 * 60,
25
25
  },
26
26
  [dl_core_1.ChainSlug.ARBITRUM_GOERLI]: {
27
- [dl_core_1.ChainSlug.GOERLI]: 15 * 60,
27
+ [dl_core_1.ChainSlug.GOERLI]: 5 * 60,
28
+ },
29
+ [dl_core_1.ChainSlug.POLYGON_MUMBAI]: {
30
+ [dl_core_1.ChainSlug.GOERLI]: 10 * 60,
31
+ },
32
+ [dl_core_1.ChainSlug.GOERLI]: {
33
+ [dl_core_1.ChainSlug.POLYGON_MUMBAI]: 5 * 60,
34
+ [dl_core_1.ChainSlug.ARBITRUM_GOERLI]: 5 * 60,
35
+ [dl_core_1.ChainSlug.OPTIMISM_GOERLI]: 5 * 60,
28
36
  },
29
37
  [dl_core_1.ChainSlug.ARBITRUM]: {
30
38
  [dl_core_1.ChainSlug.MAINNET]: 7 * 24 * 3600,
@@ -32,4 +40,12 @@ exports.NativeWaitTime = {
32
40
  [dl_core_1.ChainSlug.OPTIMISM]: {
33
41
  [dl_core_1.ChainSlug.MAINNET]: 7 * 24 * 3600,
34
42
  },
43
+ [dl_core_1.ChainSlug.POLYGON_MAINNET]: {
44
+ [dl_core_1.ChainSlug.MAINNET]: 4 * 3600,
45
+ },
46
+ [dl_core_1.ChainSlug.MAINNET]: {
47
+ [dl_core_1.ChainSlug.ARBITRUM]: 10 * 60,
48
+ [dl_core_1.ChainSlug.OPTIMISM]: 10 * 60,
49
+ [dl_core_1.ChainSlug.POLYGON_MAINNET]: 10 * 60,
50
+ },
35
51
  };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./models";
2
- export * from "./types";
3
2
  export * from "./services";
4
3
  export * from "./utils";
5
4
  export * from "./constants";
package/dist/index.js CHANGED
@@ -15,7 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./models"), exports);
18
- __exportStar(require("./types"), exports);
19
18
  __exportStar(require("./services"), exports);
20
19
  __exportStar(require("./utils"), exports);
21
20
  __exportStar(require("./constants"), exports);
@@ -32,3 +32,4 @@ export declare const AttestSignatureModel: {
32
32
  type: DataTypes.StringDataTypeConstructor;
33
33
  };
34
34
  };
35
+ export declare const addSignatureHooks: () => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttestSignatureModel = exports.AttestSignature = void 0;
3
+ exports.addSignatureHooks = exports.AttestSignatureModel = exports.AttestSignature = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ const __1 = require("..");
5
6
  class AttestSignature extends sequelize_1.Model {
6
7
  }
7
8
  exports.AttestSignature = AttestSignature;
@@ -30,3 +31,23 @@ exports.AttestSignatureModel = {
30
31
  type: sequelize_1.DataTypes.STRING,
31
32
  },
32
33
  };
34
+ function processStrings(attestSignature) {
35
+ if (attestSignature.packetId) {
36
+ attestSignature.packetId = (0, __1.toLowerCase)(attestSignature.packetId);
37
+ }
38
+ if (attestSignature.signature) {
39
+ attestSignature.signature = (0, __1.toLowerCase)(attestSignature.signature);
40
+ }
41
+ return attestSignature;
42
+ }
43
+ const addSignatureHooks = () => {
44
+ AttestSignature.beforeBulkCreate((attestSignature, options) => {
45
+ for (let index = 0; index < attestSignature.length; index++) {
46
+ attestSignature[index] = processStrings(attestSignature[index]);
47
+ }
48
+ });
49
+ AttestSignature.beforeSave((attestSignature, options) => {
50
+ attestSignature = processStrings(attestSignature);
51
+ });
52
+ };
53
+ exports.addSignatureHooks = addSignatureHooks;
@@ -67,3 +67,4 @@ export declare const AttestationModel: {
67
67
  defaultValue: number;
68
68
  };
69
69
  };
70
+ export declare const addAttestationHooks: () => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AttestationModel = exports.Attestation = void 0;
3
+ exports.addAttestationHooks = exports.AttestationModel = exports.Attestation = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ const __1 = require("..");
5
6
  class Attestation extends sequelize_1.Model {
6
7
  }
7
8
  exports.Attestation = Attestation;
@@ -57,3 +58,29 @@ exports.AttestationModel = {
57
58
  defaultValue: 0,
58
59
  },
59
60
  };
61
+ const addAttestationHooks = () => {
62
+ Attestation.beforeBulkCreate((packet, options) => {
63
+ for (let index = 0; index < packet.length; index++) {
64
+ packet[index] = processStrings(packet[index]);
65
+ }
66
+ });
67
+ Attestation.beforeSave((packet, options) => {
68
+ packet = processStrings(packet);
69
+ });
70
+ };
71
+ exports.addAttestationHooks = addAttestationHooks;
72
+ function processStrings(packet) {
73
+ if (packet.packetId)
74
+ packet.packetId = (0, __1.toLowerCase)(packet.packetId);
75
+ if (packet.root)
76
+ packet.root = (0, __1.toLowerCase)(packet.root);
77
+ if (packet.switchboard)
78
+ packet.switchboard = (0, __1.toLowerCase)(packet.switchboard);
79
+ if (packet.attester)
80
+ packet.attester = (0, __1.toLowerCase)(packet.attester);
81
+ if (packet.attestTxId)
82
+ packet.attestTxId = (0, __1.toLowerCase)(packet.attestTxId);
83
+ if (packet.attestTxHash)
84
+ packet.attestTxHash = (0, __1.toLowerCase)(packet.attestTxHash);
85
+ return packet;
86
+ }
@@ -163,3 +163,4 @@ export declare const MessageModel: {
163
163
  defaultValue: string;
164
164
  };
165
165
  };
166
+ export declare const addMessageHooks: () => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageModel = exports.Message = exports.ExecutionRelayStatus = void 0;
3
+ exports.addMessageHooks = exports.MessageModel = exports.Message = exports.ExecutionRelayStatus = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ const utils_1 = require("../utils");
5
6
  var ExecutionRelayStatus;
6
7
  (function (ExecutionRelayStatus) {
7
8
  ExecutionRelayStatus["EXECUTED"] = "EXECUTED";
@@ -133,3 +134,50 @@ exports.MessageModel = {
133
134
  defaultValue: "",
134
135
  },
135
136
  };
137
+ function processStrings(message) {
138
+ if (message.srcPlug)
139
+ message.srcPlug = (0, utils_1.toLowerCase)(message.srcPlug);
140
+ if (message.destPlug)
141
+ message.destPlug = (0, utils_1.toLowerCase)(message.destPlug);
142
+ if (message.messageId)
143
+ message.messageId = (0, utils_1.toLowerCase)(message.messageId);
144
+ if (message.executionParams) {
145
+ message.executionParams = (0, utils_1.toLowerCase)(message.executionParams);
146
+ }
147
+ if (message.transmissionParams) {
148
+ message.transmissionParams = (0, utils_1.toLowerCase)(message.transmissionParams);
149
+ }
150
+ if (message.packedMessage) {
151
+ message.packedMessage = (0, utils_1.toLowerCase)(message.packedMessage);
152
+ }
153
+ if (message.decapacitorProof) {
154
+ message.decapacitorProof = (0, utils_1.toLowerCase)(message.decapacitorProof);
155
+ }
156
+ if (message.payload)
157
+ message.payload = (0, utils_1.toLowerCase)(message.payload);
158
+ if (message.executor)
159
+ message.executor = (0, utils_1.toLowerCase)(message.executor);
160
+ if (message.executeTxHash) {
161
+ message.executeTxHash = (0, utils_1.toLowerCase)(message.executeTxHash);
162
+ }
163
+ if (message.outboundTxHash) {
164
+ message.outboundTxHash = (0, utils_1.toLowerCase)(message.outboundTxHash);
165
+ }
166
+ if (message.packedMessage) {
167
+ message.packedMessage = (0, utils_1.toLowerCase)(message.packedMessage);
168
+ }
169
+ if (message.rootHash)
170
+ message.rootHash = (0, utils_1.toLowerCase)(message.rootHash);
171
+ return message;
172
+ }
173
+ const addMessageHooks = () => {
174
+ Message.beforeBulkCreate((message, options) => {
175
+ for (let index = 0; index < message.length; index++) {
176
+ message[index] = processStrings(message[index]);
177
+ }
178
+ });
179
+ Message.beforeSave((message, options) => {
180
+ message = processStrings(message);
181
+ });
182
+ };
183
+ exports.addMessageHooks = addMessageHooks;
@@ -230,3 +230,4 @@ export declare const PacketModel: {
230
230
  defaultValue: AttestRelayStatus;
231
231
  };
232
232
  };
233
+ export declare const addPacketHooks: () => void;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PacketModel = exports.Packet = exports.TripReason = exports.AttestRelayStatus = exports.ProposeRelayStatus = exports.PacketTripRelayStatus = exports.SealRelayStatus = void 0;
3
+ exports.addPacketHooks = exports.PacketModel = exports.Packet = exports.TripReason = exports.AttestRelayStatus = exports.ProposeRelayStatus = exports.PacketTripRelayStatus = exports.SealRelayStatus = void 0;
4
4
  const dl_core_1 = require("@socket.tech/dl-core");
5
5
  const sequelize_1 = require("sequelize");
6
+ const utils_1 = require("../utils");
6
7
  var SealRelayStatus;
7
8
  (function (SealRelayStatus) {
8
9
  SealRelayStatus["SEALED"] = "SEALED";
@@ -202,3 +203,39 @@ exports.PacketModel = {
202
203
  defaultValue: AttestRelayStatus.NO,
203
204
  },
204
205
  };
206
+ function processStrings(packet) {
207
+ if (packet.packetId)
208
+ packet.packetId = (0, utils_1.toLowerCase)(packet.packetId);
209
+ if (packet.root)
210
+ packet.root = (0, utils_1.toLowerCase)(packet.root);
211
+ if (packet.rootSealed)
212
+ packet.rootSealed = (0, utils_1.toLowerCase)(packet.rootSealed);
213
+ if (packet.sealer)
214
+ packet.sealer = (0, utils_1.toLowerCase)(packet.sealer);
215
+ if (packet.outboundTxHash) {
216
+ packet.outboundTxHash = (0, utils_1.toLowerCase)(packet.outboundTxHash);
217
+ }
218
+ if (packet.sealTxHash)
219
+ packet.sealTxHash = (0, utils_1.toLowerCase)(packet.sealTxHash);
220
+ if (packet.sealSignature) {
221
+ packet.sealSignature = (0, utils_1.toLowerCase)(packet.sealSignature);
222
+ }
223
+ if (packet.dstSwitchboard) {
224
+ packet.dstSwitchboard = (0, utils_1.toLowerCase)(packet.dstSwitchboard);
225
+ }
226
+ if (packet.packetTripTxHash) {
227
+ packet.packetTripTxHash = (0, utils_1.toLowerCase)(packet.packetTripTxHash);
228
+ }
229
+ return packet;
230
+ }
231
+ const addPacketHooks = () => {
232
+ Packet.beforeBulkCreate((packet, options) => {
233
+ for (let index = 0; index < packet.length; index++) {
234
+ packet[index] = processStrings(packet[index]);
235
+ }
236
+ });
237
+ Packet.beforeSave((packet, options) => {
238
+ packet = processStrings(packet);
239
+ });
240
+ };
241
+ exports.addPacketHooks = addPacketHooks;
@@ -124,3 +124,4 @@ export declare const ProposalModel: {
124
124
  defaultValue: boolean;
125
125
  };
126
126
  };
127
+ export declare const addProposalHooks: () => void;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProposalModel = exports.Proposal = exports.ProposalTripRelayStatus = exports.MatchState = exports.RootMatchState = exports.TripStatus = void 0;
3
+ exports.addProposalHooks = exports.ProposalModel = exports.Proposal = exports.ProposalTripRelayStatus = exports.MatchState = exports.RootMatchState = exports.TripStatus = void 0;
4
4
  const sequelize_1 = require("sequelize");
5
+ const __1 = require("..");
5
6
  var TripStatus;
6
7
  (function (TripStatus) {
7
8
  TripStatus["TRIP_REQUIRED"] = "TRIP_REQUIRED";
@@ -112,3 +113,29 @@ exports.ProposalModel = {
112
113
  defaultValue: false,
113
114
  },
114
115
  };
116
+ function processStrings(proposal) {
117
+ if (proposal.packetId)
118
+ proposal.packetId = (0, __1.toLowerCase)(proposal.packetId);
119
+ if (proposal.root)
120
+ proposal.root = (0, __1.toLowerCase)(proposal.root);
121
+ if (proposal.switchboard)
122
+ proposal.switchboard = (0, __1.toLowerCase)(proposal.switchboard);
123
+ if (proposal.proposer)
124
+ proposal.proposer = (0, __1.toLowerCase)(proposal.proposer);
125
+ if (proposal.proposeTxHash)
126
+ proposal.proposeTxHash = (0, __1.toLowerCase)(proposal.proposeTxHash);
127
+ if (proposal.tripTxHash)
128
+ proposal.tripTxHash = (0, __1.toLowerCase)(proposal.tripTxHash);
129
+ return proposal;
130
+ }
131
+ const addProposalHooks = () => {
132
+ Proposal.beforeBulkCreate((proposal, options) => {
133
+ for (let index = 0; index < proposal.length; index++) {
134
+ proposal[index] = processStrings(proposal[index]);
135
+ }
136
+ });
137
+ Proposal.beforeSave((proposal, options) => {
138
+ proposal = processStrings(proposal);
139
+ });
140
+ };
141
+ exports.addProposalHooks = addProposalHooks;
@@ -1,10 +1,10 @@
1
1
  export declare let client: any;
2
- export declare const initCache: (host: string, port: number, password: string, stage: string) => void;
2
+ export declare const initCache: (host: string, port: number, password: string, stage: string, serviceName: string) => void;
3
3
  export declare const formatKey: (key: string) => string;
4
4
  export declare const getKey: (key: string) => Promise<any>;
5
5
  export declare const lock: (key: string, expire?: number) => Promise<boolean>;
6
- export declare const deleteKey: (key: string) => Promise<void>;
7
- export declare const unlock: (key: string) => Promise<void>;
6
+ export declare const deleteKey: (key: string) => Promise<any>;
7
+ export declare const unlock: (key: string) => Promise<any>;
8
8
  export declare const setKey: (key: string, value: any, expire?: number, setIfNotExist?: boolean) => Promise<boolean>;
9
9
  export declare const rpush: (key: string, values: any[]) => Promise<any>;
10
10
  export declare const lpop: (key: string) => Promise<any>;
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendCommand = exports.decrement = exports.increment = exports.getListLength = exports.lpop = exports.rpush = exports.setKey = exports.unlock = exports.deleteKey = exports.lock = exports.getKey = exports.formatKey = exports.initCache = exports.client = void 0;
4
4
  const redis = require("async-redis");
5
5
  let deploymentStage;
6
- const initCache = (host, port, password, stage) => {
6
+ let servicePrefix;
7
+ const initCache = (host, port, password, stage, serviceName) => {
7
8
  exports.client = redis.createClient({
8
9
  port,
9
10
  host,
10
11
  password,
11
12
  });
12
13
  deploymentStage = stage;
14
+ servicePrefix = serviceName;
13
15
  };
14
16
  exports.initCache = initCache;
15
17
  const formatKey = (key) => {
16
- return deploymentStage + "_" + key;
18
+ return deploymentStage + "_" + servicePrefix + "_" + key;
17
19
  };
18
20
  exports.formatKey = formatKey;
19
21
  const getKey = async (key) => {
@@ -21,24 +23,15 @@ const getKey = async (key) => {
21
23
  };
22
24
  exports.getKey = getKey;
23
25
  const lock = async (key, expire = 0) => {
24
- let result = await (0, exports.setKey)(key, "locked", expire, true);
25
- if (result)
26
- console.log("acquired lock!");
27
- else
28
- console.log("blocked");
29
- return result;
26
+ return await (0, exports.setKey)(key, "locked", expire, true);
30
27
  };
31
28
  exports.lock = lock;
32
29
  const deleteKey = async (key) => {
33
- let result = await exports.client.del((0, exports.formatKey)(key));
34
- if (result)
35
- console.log("deleted ", (0, exports.formatKey)(key));
30
+ return await exports.client.del((0, exports.formatKey)(key));
36
31
  };
37
32
  exports.deleteKey = deleteKey;
38
33
  const unlock = async (key) => {
39
- let result = await exports.client.del((0, exports.formatKey)(key));
40
- if (result)
41
- console.log("unlocked");
34
+ return await exports.client.del((0, exports.formatKey)(key));
42
35
  };
43
36
  exports.unlock = unlock;
44
37
  const setKey = async (key, value, expire = 0, setIfNotExist = false) => {
@@ -47,10 +40,8 @@ const setKey = async (key, value, expire = 0, setIfNotExist = false) => {
47
40
  params.push("EX", expire);
48
41
  if (setIfNotExist)
49
42
  params.push("NX");
50
- console.log("command : SET ", params);
51
43
  let response = await exports.client.sendCommand("SET", params);
52
44
  if (response) {
53
- console.log((0, exports.formatKey)(key) + " set to => " + value);
54
45
  return true;
55
46
  }
56
47
  else
@@ -76,14 +67,11 @@ const increment = async (key) => {
76
67
  };
77
68
  exports.increment = increment;
78
69
  const decrement = async (key) => {
79
- let value = await exports.client.decr((0, exports.formatKey)(key));
80
- console.log("decremented key : ", (0, exports.formatKey)(key), " value : ", value);
81
- return value;
70
+ return await exports.client.decr((0, exports.formatKey)(key));
82
71
  };
83
72
  exports.decrement = decrement;
84
73
  const sendCommand = async (command, params) => {
85
74
  params[0] = (0, exports.formatKey)(params[0]);
86
- let result = await exports.client.sendCommand(command, params);
87
- return result;
75
+ return await exports.client.sendCommand(command, params);
88
76
  };
89
77
  exports.sendCommand = sendCommand;
@@ -15,8 +15,7 @@ const sendStandardSqsMessage = async (queueUrl, data, DelaySeconds = 0) => {
15
15
  };
16
16
  // Send the order data to the SQS queue
17
17
  const command = new client_sqs_1.SendMessageCommand(sqsOrderData);
18
- let result = await client.send(command);
19
- return result;
18
+ return await client.send(command);
20
19
  };
21
20
  exports.sendStandardSqsMessage = sendStandardSqsMessage;
22
21
  const sendStandardBatchMessages = async (QueueUrl, dataArray, DelaySecondsArray = []) => {
@@ -34,8 +33,7 @@ const sendStandardBatchMessages = async (QueueUrl, dataArray, DelaySecondsArray
34
33
  };
35
34
  // Send the order data to the SQS queue
36
35
  const command = new client_sqs_1.SendMessageBatchCommand(sqsOrderData);
37
- let result = await client.send(command);
38
- return result;
36
+ return await client.send(command);
39
37
  };
40
38
  exports.sendStandardBatchMessages = sendStandardBatchMessages;
41
39
  const sendFifoSqsMessage = async (queueUrl, data, MessageGroupId) => {
@@ -46,8 +44,7 @@ const sendFifoSqsMessage = async (queueUrl, data, MessageGroupId) => {
46
44
  };
47
45
  // Send the order data to the SQS queue
48
46
  const command = new client_sqs_1.SendMessageCommand(sqsOrderData);
49
- let result = await client.send(command);
50
- return result;
47
+ return await client.send(command);
51
48
  };
52
49
  exports.sendFifoSqsMessage = sendFifoSqsMessage;
53
50
  exports.default = {
@@ -5,8 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.axiosPost = exports.axiosGet = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const __1 = require("..");
8
9
  const axiosGet = async (url, config = {}, errorLogging = false) => {
9
10
  var _a, _b, _c, _d;
11
+ if (!url)
12
+ throw (0, __1.InternalServerError)("GET request url not provided");
10
13
  try {
11
14
  const response = await axios_1.default.get(url, config);
12
15
  return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
@@ -27,6 +30,10 @@ const axiosGet = async (url, config = {}, errorLogging = false) => {
27
30
  exports.axiosGet = axiosGet;
28
31
  const axiosPost = async (url, data, config = {}, errorLogging = false) => {
29
32
  var _a, _b, _c, _d;
33
+ if (!url)
34
+ throw (0, __1.InternalServerError)("POST request url not provided");
35
+ if (!data)
36
+ throw (0, __1.InternalServerError)("POST request data not provided");
30
37
  try {
31
38
  const response = await axios_1.default.post(url, data, config);
32
39
  return { success: true, ...response === null || response === void 0 ? void 0 : response.data };
@@ -1 +1,2 @@
1
- export declare const sendToDiscordWebhook: (data: any) => Promise<void>;
1
+ export declare const initDiscord: (webhookUrl_: string, serviceName_: string) => void;
2
+ export declare const sendToDiscordWebhook: (title: string, data: object, optionalConfig?: object) => Promise<void>;
@@ -1,17 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendToDiscordWebhook = void 0;
3
+ exports.sendToDiscordWebhook = exports.initDiscord = void 0;
4
+ const __1 = require("..");
4
5
  const axios_1 = require("./axios");
5
- const sendToDiscordWebhook = async (data) => {
6
+ let discordWebhookUrl;
7
+ let serviceName;
8
+ const initDiscord = (webhookUrl_, serviceName_) => {
9
+ discordWebhookUrl = webhookUrl_;
10
+ serviceName = serviceName_;
11
+ };
12
+ exports.initDiscord = initDiscord;
13
+ const sendToDiscordWebhook = async (title, data, optionalConfig = {}) => {
6
14
  try {
7
- const discordWebhookUrl = process.env.DISCORD_WEBHOOK_URL;
8
15
  if (!discordWebhookUrl) {
9
- throw new Error("DISCORD_WEBHOOK_URL not provided");
16
+ throw (0, __1.InternalServerError)("DISCORD_WEBHOOK_URL not provided");
10
17
  }
11
- await (0, axios_1.axiosPost)(discordWebhookUrl, { content: JSON.stringify(data) });
18
+ let content = formatMsg(title, data);
19
+ await (0, axios_1.axiosPost)(discordWebhookUrl, { content, ...optionalConfig });
12
20
  }
13
21
  catch (error) {
14
22
  throw error;
15
23
  }
16
24
  };
17
25
  exports.sendToDiscordWebhook = sendToDiscordWebhook;
26
+ const formatMsg = (title, data) => {
27
+ let message = `**${title}**\n`;
28
+ // Iterate through the object's key-value pairs
29
+ for (const key in data) {
30
+ if (data.hasOwnProperty(key)) {
31
+ message += `${key}: ${data[key]}\n`;
32
+ }
33
+ }
34
+ return message;
35
+ };
@@ -1,3 +1,20 @@
1
+ /**
2
+ * defining functions.
3
+ */
4
+ export declare const isEmpty: (data: any) => boolean;
5
+ export declare const checkMissingFields: (fields: {
6
+ [key: string]: any;
7
+ }) => void;
8
+ export declare const checkMissingFieldsAndType: (fields: {
9
+ [key: string]: any;
10
+ }, types?: {
11
+ [key: string]: string;
12
+ }) => void;
13
+ export declare const checkObjectFieldsAndType: (data: {
14
+ [key: string]: any;
15
+ }, types?: {
16
+ [key: string]: any;
17
+ }, prefix?: string) => void;
1
18
  export declare const removeFields: (obj: any, fieldsToRemove: string[]) => any;
2
19
  export declare const filterFields: (obj: any, fieldsAllowed: string[]) => any;
3
20
  /**
@@ -12,11 +29,3 @@ export declare const responseBody: (statusCode?: number, message?: null | string
12
29
  };
13
30
  body: string;
14
31
  };
15
- declare const _default: {
16
- isEmpty: (data: any) => boolean;
17
- checkMissingFields: (fields: any) => void;
18
- checkMissingFieldsAndType: (fields: any, types?: any) => void;
19
- removeFields: (obj: any, fieldsToRemove: string[]) => any;
20
- filterFields: (obj: any, fieldsAllowed: string[]) => any;
21
- };
22
- export default _default;
@@ -1,37 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.responseBody = exports.filterFields = exports.removeFields = void 0;
3
+ exports.responseBody = exports.filterFields = exports.removeFields = exports.checkObjectFieldsAndType = exports.checkMissingFieldsAndType = exports.checkMissingFields = exports.isEmpty = void 0;
4
+ const __1 = require("..");
4
5
  /**
5
6
  * defining functions.
6
7
  */
7
8
  const isEmpty = (data) => {
8
- if (data === undefined || data === null || data === "") {
9
+ if (data === undefined || data === null) {
9
10
  return true;
10
11
  }
11
12
  else {
12
13
  return false;
13
14
  }
14
15
  }; // end of isEmpty.
16
+ exports.isEmpty = isEmpty;
15
17
  const checkMissingFields = (fields) => {
16
18
  for (const field in fields) {
17
- if (isEmpty(fields[field])) {
18
- throw { message: `missing field : ${field}`, code: 1 };
19
+ let value = fields[field];
20
+ if (!value) {
21
+ throw (0, __1.BadRequestError)(`missing field : ${field}`);
19
22
  }
20
23
  }
21
24
  };
25
+ exports.checkMissingFields = checkMissingFields;
22
26
  const checkMissingFieldsAndType = (fields, types = {}) => {
23
27
  for (const field in fields) {
24
- if (isEmpty(fields[field])) {
25
- throw { message: `missing field : ${field}`, code: 1 };
28
+ if ((0, exports.isEmpty)(fields[field])) {
29
+ throw (0, __1.BadRequestError)(`missing field : ${field}`);
26
30
  }
27
31
  if (types[field] && typeof fields[field] !== types[field]) {
28
- throw {
29
- message: `Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`,
30
- code: 1,
31
- };
32
+ throw (0, __1.BadRequestError)(`Type of ${field} expected : "${types[field]}", got : "${typeof fields[field]}"`);
32
33
  }
33
34
  }
34
35
  };
36
+ exports.checkMissingFieldsAndType = checkMissingFieldsAndType;
37
+ const checkObjectFieldsAndType = (data, types = {}, prefix = "") => {
38
+ let keys = Object.keys(types);
39
+ for (const key of keys) {
40
+ if ((0, exports.isEmpty)(data[key])) {
41
+ throw (0, __1.BadRequestError)(`missing field : ${prefix}.${key}`);
42
+ }
43
+ if (typeof data[key] === "object") {
44
+ (0, exports.checkObjectFieldsAndType)(data[key], types[key], `${prefix}.${key}`);
45
+ }
46
+ else if (typeof data[key] !== types[key]) {
47
+ throw (0, __1.BadRequestError)(`Type of ${prefix}.${key} expected : "${types[key]}", got : "${typeof data[key]}"`);
48
+ }
49
+ }
50
+ };
51
+ exports.checkObjectFieldsAndType = checkObjectFieldsAndType;
35
52
  const removeFields = (obj, fieldsToRemove) => {
36
53
  for (const field in obj) {
37
54
  if (fieldsToRemove.includes(field)) {
@@ -76,10 +93,3 @@ const responseBody = (statusCode = 400, message = null, data = null, success = t
76
93
  };
77
94
  }; // end responseBody function.
78
95
  exports.responseBody = responseBody;
79
- exports.default = {
80
- isEmpty,
81
- checkMissingFields,
82
- checkMissingFieldsAndType,
83
- removeFields: exports.removeFields,
84
- filterFields: exports.filterFields,
85
- };
@@ -11,3 +11,4 @@ export interface MessageDetails {
11
11
  export declare const unpackPacketId: (packetId: string) => PacketDetails;
12
12
  export declare const unpackMessageId: (messageId: string) => MessageDetails;
13
13
  export declare const packPacketId: (chainSlug: number, capacitorAddr: string, packetNonce: string) => string;
14
+ export declare function encodePacketId(chainSlug: number, capacitorAddress: string, packetCount: number): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.packPacketId = exports.unpackMessageId = exports.unpackPacketId = void 0;
3
+ exports.encodePacketId = exports.packPacketId = exports.unpackMessageId = exports.unpackPacketId = void 0;
4
4
  const ethers_1 = require("ethers");
5
5
  const address_1 = require("./address");
6
6
  const utils_1 = require("ethers/lib/utils");
@@ -39,3 +39,12 @@ const packPacketId = (chainSlug, capacitorAddr, packetNonce) => {
39
39
  return id.toLowerCase();
40
40
  };
41
41
  exports.packPacketId = packPacketId;
42
+ function encodePacketId(chainSlug, capacitorAddress, packetCount) {
43
+ const encodedValue = (BigInt(chainSlug) << BigInt(224)) |
44
+ (BigInt(capacitorAddress) << BigInt(64)) |
45
+ BigInt(packetCount);
46
+ // Ensure the result is a 32-byte hex string (bytes32 in Solidity)
47
+ const resultHex = encodedValue.toString(16).padStart(64, "0");
48
+ return "0x" + resultHex;
49
+ }
50
+ exports.encodePacketId = encodePacketId;
@@ -2,15 +2,17 @@ import { Provider, TransactionRequest, TransactionResponse } from "@ethersprojec
2
2
  import { Signer } from "@ethersproject/abstract-signer";
3
3
  import { Bytes } from "@ethersproject/bytes";
4
4
  import { Deferrable } from "@ethersproject/properties";
5
+ import { ChainSlug } from "@socket.tech/dl-core";
5
6
  export declare class SocketRelaySigner extends Signer {
6
7
  readonly provider: Provider;
8
+ readonly chainSlug: ChainSlug;
7
9
  readonly relayUrl: string;
8
10
  readonly relayerAPIKey: string;
9
11
  readonly sequential: boolean;
10
12
  readonly isCritical: boolean;
11
13
  readonly metadata: object;
12
14
  readonly source: string;
13
- constructor(provider: Provider, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object, source?: string);
15
+ constructor(provider: Provider, chainSlug: ChainSlug, relayUrl: string, relayerAPIKey: string, sequential?: boolean, isCritical?: boolean, metadata?: object, source?: string);
14
16
  getAddress(): Promise<string>;
15
17
  signMessage(message: string | Bytes): Promise<string>;
16
18
  connect(provider: Provider): SocketRelaySigner;
@@ -3,13 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SocketRelaySigner = void 0;
4
4
  const abstract_signer_1 = require("@ethersproject/abstract-signer");
5
5
  const axios_1 = require("./axios");
6
+ const dl_core_1 = require("@socket.tech/dl-core");
6
7
  class SocketRelaySigner extends abstract_signer_1.Signer {
7
- constructor(provider, relayUrl, relayerAPIKey, sequential = false,
8
+ constructor(provider, chainSlug, relayUrl, relayerAPIKey, sequential = false,
8
9
  // if isCritical is set to true, will try multiple relayers
9
10
  // to get the transaction included
10
11
  isCritical = false, metadata = {}, source = "Attester") {
11
12
  super();
12
13
  this.provider = provider;
14
+ this.chainSlug = chainSlug;
13
15
  this.relayUrl = relayUrl;
14
16
  this.relayerAPIKey = relayerAPIKey;
15
17
  this.sequential = sequential;
@@ -25,13 +27,13 @@ class SocketRelaySigner extends abstract_signer_1.Signer {
25
27
  throw new Error(" signMessage not Implemented");
26
28
  }
27
29
  connect(provider) {
28
- return new SocketRelaySigner(provider, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
30
+ return new SocketRelaySigner(provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, this.metadata);
29
31
  }
30
32
  setCritical(isCritical) {
31
- return new SocketRelaySigner(this.provider, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
33
+ return new SocketRelaySigner(this.provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, isCritical, this.metadata);
32
34
  }
33
35
  addMetadata(metadata) {
34
- return new SocketRelaySigner(this.provider, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
36
+ return new SocketRelaySigner(this.provider, this.chainSlug, this.relayUrl, this.relayerAPIKey, this.sequential, this.isCritical, metadata);
35
37
  }
36
38
  async signTransaction(transaction) {
37
39
  throw new Error(" signTransaction not Implemented");
@@ -43,7 +45,7 @@ class SocketRelaySigner extends abstract_signer_1.Signer {
43
45
  if (!this.relayUrl)
44
46
  throw new Error("relayUrl not provided");
45
47
  let payload = {
46
- chainId: (await this.provider.getNetwork()).chainId,
48
+ chainId: dl_core_1.ChainSlugToId[this.chainSlug],
47
49
  sequential: this.sequential,
48
50
  isCritical: this.isCritical,
49
51
  source: this.source,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socket.tech/dl-common",
3
- "version": "1.0.2-test.3",
3
+ "version": "1.0.2-test.5",
4
4
  "main": "./dist/dl-common/index.js",
5
5
  "types": "./dist/dl-common/index.d.ts",
6
6
  "description": "common utilities for socket data layer.",
@@ -34,7 +34,8 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@aws-sdk/client-sqs": "^3.421.0",
37
- "@socket.tech/dl-core": "^2.4.6-test.0",
37
+ "@aws-sdk/smithy-client": "^3.329.0",
38
+ "@socket.tech/dl-core": "2.4.9-test.1",
38
39
  "@socket.tech/ll-common": "^0.0.19",
39
40
  "async-redis": "^2.0.0",
40
41
  "ethers": "^5.7.1",