@atomiqlabs/chain-evm 2.2.1 → 2.3.0

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.
@@ -178,4 +178,8 @@ export declare class EVMSwapData extends SwapData {
178
178
  * @param claimHandlerImpl Claim handler implementation used to resolve swap type
179
179
  */
180
180
  static deserializeFromStruct(struct: EscrowDataStruct, claimHandlerImpl: IClaimHandler<any, any>): EVMSwapData;
181
+ /**
182
+ * @inheritDoc
183
+ */
184
+ getEscrowStruct(): any;
181
185
  }
@@ -4,6 +4,7 @@ exports.EVMSwapData = void 0;
4
4
  const base_1 = require("@atomiqlabs/base");
5
5
  const ethers_1 = require("ethers");
6
6
  const TimelockRefundHandler_1 = require("./handlers/refund/TimelockRefundHandler");
7
+ const Utils_1 = require("../../utils/Utils");
7
8
  const FLAG_PAY_OUT = 0x01n;
8
9
  const FLAG_PAY_IN = 0x02n;
9
10
  const FLAG_REPUTATION = 0x04n;
@@ -413,6 +414,12 @@ class EVMSwapData extends base_1.SwapData {
413
414
  const { payOut, payIn, reputation, sequence } = EVMSwapData.toFlags(BigInt(struct.flags));
414
415
  return new EVMSwapData(struct.offerer, struct.claimer, struct.token, struct.refundHandler, struct.claimHandler, payOut, payIn, reputation, sequence, (0, ethers_1.hexlify)(struct.claimData), (0, ethers_1.hexlify)(struct.refundData), BigInt(struct.amount), struct.depositToken, BigInt(struct.securityDeposit), BigInt(struct.claimerBounty), claimHandlerImpl.getType(), undefined, struct.successActionCommitment);
415
416
  }
417
+ /**
418
+ * @inheritDoc
419
+ */
420
+ getEscrowStruct() {
421
+ return (0, Utils_1.replaceBigInts)(this.toEscrowStruct());
422
+ }
416
423
  }
417
424
  exports.EVMSwapData = EVMSwapData;
418
425
  base_1.SwapData.deserializers["evm"] = EVMSwapData;
@@ -1,3 +1,6 @@
1
+ export type ReplaceBigInt<T> = T extends bigint ? string : T extends (infer U)[] ? ReplaceBigInt<U>[] : T extends readonly (infer U)[] ? readonly ReplaceBigInt<U>[] : T extends object ? {
2
+ [K in keyof T]: ReplaceBigInt<T[K]>;
3
+ } : T;
1
4
  /**
2
5
  * Logger interface used across EVM modules.
3
6
  *
@@ -67,3 +70,4 @@ export declare const allowedEthersErrorNumbers: Set<number>;
67
70
  * @category Internal/Utils
68
71
  */
69
72
  export declare const allowedEthersErrorMessages: Set<string>;
73
+ export declare function replaceBigInts<T>(obj: T): ReplaceBigInt<T>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.allowedEthersErrorMessages = exports.allowedEthersErrorNumbers = exports.allowedEthersErrorCodes = exports.bigIntMax = exports.uint32ReverseEndianness = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = void 0;
3
+ exports.replaceBigInts = exports.allowedEthersErrorMessages = exports.allowedEthersErrorNumbers = exports.allowedEthersErrorCodes = exports.bigIntMax = exports.uint32ReverseEndianness = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = void 0;
4
4
  /**
5
5
  * Returns a promise that resolves after `timeoutMillis` unless aborted first.
6
6
  *
@@ -142,3 +142,21 @@ exports.allowedEthersErrorNumbers = new Set([
142
142
  exports.allowedEthersErrorMessages = new Set([
143
143
  "already known"
144
144
  ]);
145
+ function replaceBigInts(obj) {
146
+ const replace = (value) => {
147
+ if (typeof (value) === "bigint")
148
+ return "0x" + value.toString(16);
149
+ if (value == null || typeof (value) !== "object")
150
+ return value;
151
+ if (Array.isArray(value)) {
152
+ return value.map(replace);
153
+ }
154
+ const mapped = {};
155
+ for (const key of Object.keys(value)) {
156
+ mapped[key] = replace(value[key]);
157
+ }
158
+ return mapped;
159
+ };
160
+ return replace(obj);
161
+ }
162
+ exports.replaceBigInts = replaceBigInts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-evm",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "EVM specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "author": "adambor",
28
28
  "license": "Apache-2.0",
29
29
  "dependencies": {
30
- "@atomiqlabs/base": "^13.2.0",
30
+ "@atomiqlabs/base": "^13.3.0",
31
31
  "@noble/hashes": "^1.8.0",
32
32
  "@scure/btc-signer": "^1.6.0",
33
33
  "buffer": "6.0.3",
@@ -3,6 +3,7 @@ import {AbiCoder, hexlify, keccak256, ZeroHash} from "ethers";
3
3
  import {EscrowDataStruct, EscrowDataStructOutput} from "./EscrowManagerTypechain";
4
4
  import {IClaimHandler} from "./handlers/claim/ClaimHandlers";
5
5
  import {TimelockRefundHandler} from "./handlers/refund/TimelockRefundHandler";
6
+ import {replaceBigInts} from "../../utils/Utils";
6
7
 
7
8
  const FLAG_PAY_OUT: bigint = 0x01n;
8
9
  const FLAG_PAY_IN: bigint = 0x02n;
@@ -513,6 +514,13 @@ export class EVMSwapData extends SwapData {
513
514
  );
514
515
  }
515
516
 
517
+ /**
518
+ * @inheritDoc
519
+ */
520
+ getEscrowStruct(): any {
521
+ return replaceBigInts(this.toEscrowStruct());
522
+ }
523
+
516
524
  }
517
525
 
518
526
  SwapData.deserializers["evm"] = EVMSwapData;
@@ -1,4 +1,16 @@
1
1
 
2
+
3
+ export type ReplaceBigInt<T> =
4
+ T extends bigint
5
+ ? string
6
+ : T extends (infer U)[]
7
+ ? ReplaceBigInt<U>[]
8
+ : T extends readonly (infer U)[]
9
+ ? readonly ReplaceBigInt<U>[]
10
+ : T extends object
11
+ ? { [K in keyof T]: ReplaceBigInt<T[K]> }
12
+ : T;
13
+
2
14
  /**
3
15
  * Logger interface used across EVM modules.
4
16
  *
@@ -159,3 +171,23 @@ export const allowedEthersErrorNumbers: Set<number> = new Set([
159
171
  export const allowedEthersErrorMessages: Set<string> = new Set([
160
172
  "already known"
161
173
  ]);
174
+
175
+ export function replaceBigInts<T>(obj: T): ReplaceBigInt<T> {
176
+ const replace = (value: any): any => {
177
+ if(typeof(value)==="bigint") return "0x"+value.toString(16);
178
+ if(value==null || typeof(value)!=="object") return value;
179
+
180
+ if(Array.isArray(value)) {
181
+ return value.map(replace);
182
+ }
183
+
184
+ const mapped: any = {};
185
+ for(const key of Object.keys(value)) {
186
+ mapped[key] = replace(value[key]);
187
+ }
188
+ return mapped;
189
+ };
190
+
191
+ return replace(obj);
192
+ }
193
+