@chainflip/sdk 1.1.5 → 1.2.0-rc.1

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/funding.js CHANGED
@@ -1,19 +1,481 @@
1
1
  'use strict';
2
2
 
3
- var ethers = require('ethers');
3
+ var ethers2 = require('ethers');
4
4
  var axios = require('axios');
5
+ var util$1 = require('@polkadot/util');
6
+ var utilCrypto = require('@polkadot/util-crypto');
5
7
 
6
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
9
 
10
+ function _interopNamespace(e) {
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
20
+ });
21
+ }
22
+ });
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+
28
+ var ethers2__namespace = /*#__PURE__*/_interopNamespace(ethers2);
8
29
  var axios__default = /*#__PURE__*/_interopDefault(axios);
9
30
 
31
+ var __create = Object.create;
10
32
  var __defProp = Object.defineProperty;
33
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
34
+ var __getOwnPropNames = Object.getOwnPropertyNames;
35
+ var __getProtoOf = Object.getPrototypeOf;
36
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
37
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
38
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
39
+ var __commonJS = (cb, mod) => function __require() {
40
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
+ };
42
+ var __copyProps = (to, from, except, desc) => {
43
+ if (from && typeof from === "object" || typeof from === "function") {
44
+ for (let key of __getOwnPropNames(from))
45
+ if (!__hasOwnProp.call(to, key) && key !== except)
46
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
+ }
48
+ return to;
49
+ };
50
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
51
+ // If the importer is in node compatibility mode or this is not an ESM
52
+ // file that has been converted to a CommonJS file using a Babel-
53
+ // compatible transform (i.e. "__esModule" has not been set), then set
54
+ // "default" to the CommonJS "module.exports" for node compatibility.
55
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
56
+ mod
57
+ ));
13
58
  var __publicField = (obj, key, value) => {
14
59
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
60
  return value;
16
61
  };
62
+
63
+ // ../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/bit-converter.js
64
+ var require_bit_converter = __commonJS({
65
+ "../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/bit-converter.js"(exports) {
66
+ Object.defineProperty(exports, "__esModule", {
67
+ value: true
68
+ });
69
+ exports.createBitArray = createBitArray;
70
+ exports.fromBits = fromBits;
71
+ exports.toBits = toBits;
72
+ function toBitArrayUnchecked(src) {
73
+ return src;
74
+ }
75
+ __name(toBitArrayUnchecked, "toBitArrayUnchecked");
76
+ function createBitArray(len) {
77
+ return toBitArrayUnchecked(new Uint8Array(len));
78
+ }
79
+ __name(createBitArray, "createBitArray");
80
+ function convert(src, srcBits, dst, dstBits, pad) {
81
+ var mask = (1 << dstBits) - 1;
82
+ var acc = 0;
83
+ var bits = 0;
84
+ var pos = 0;
85
+ src.forEach(function(b) {
86
+ acc = (acc << srcBits) + b;
87
+ bits += srcBits;
88
+ while (bits >= dstBits) {
89
+ bits -= dstBits;
90
+ dst[pos] = acc >> bits & mask;
91
+ pos += 1;
92
+ }
93
+ });
94
+ if (pad) {
95
+ if (bits > 0) {
96
+ dst[pos] = acc << dstBits - bits & mask;
97
+ }
98
+ } else {
99
+ if (bits >= srcBits) {
100
+ throw new Error("Excessive padding: ".concat(bits, " (max ").concat(srcBits - 1, " allowed)"));
101
+ }
102
+ if (acc % (1 << bits) !== 0) {
103
+ throw new Error("Non-zero padding");
104
+ }
105
+ }
106
+ }
107
+ __name(convert, "convert");
108
+ function toBits(src, bits, dst) {
109
+ if (bits > 8 || bits < 1) {
110
+ throw new RangeError("Invalid bits per element; 1 to 8 expected");
111
+ }
112
+ convert(toBitArrayUnchecked(src), 8, dst, bits, true);
113
+ return dst;
114
+ }
115
+ __name(toBits, "toBits");
116
+ function fromBits(src, bits, dst) {
117
+ if (bits > 8 || bits < 1) {
118
+ throw new RangeError("Invalid bits per element; 1 to 8 expected");
119
+ }
120
+ convert(src, bits, toBitArrayUnchecked(dst), 8, false);
121
+ return dst;
122
+ }
123
+ __name(fromBits, "fromBits");
124
+ }
125
+ });
126
+
127
+ // ../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/encoding.js
128
+ var require_encoding = __commonJS({
129
+ "../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/encoding.js"(exports) {
130
+ Object.defineProperty(exports, "__esModule", {
131
+ value: true
132
+ });
133
+ exports.CHECKSUM_LENGTH = void 0;
134
+ exports.createChecksum = createChecksum;
135
+ exports.decode = decode;
136
+ exports.decodeWithPrefix = decodeWithPrefix;
137
+ exports.detectCase = detectCase;
138
+ exports.encode = encode;
139
+ exports.expandPrefix = expandPrefix;
140
+ exports.verifyChecksum = verifyChecksum;
141
+ var _bitConverter = require_bit_converter();
142
+ var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
143
+ var BECH32M_CHECKSUM = 734539939;
144
+ var MIN_CHAR_CODE = 33;
145
+ var MAX_CHAR_CODE = 126;
146
+ var CHECKSUM_LENGTH = 6;
147
+ exports.CHECKSUM_LENGTH = CHECKSUM_LENGTH;
148
+ var CHAR_LOOKUP = function() {
149
+ var lookup = /* @__PURE__ */ new Map();
150
+ for (var i = 0; i < CHARSET.length; i += 1) {
151
+ lookup.set(CHARSET[i], i);
152
+ }
153
+ return lookup;
154
+ }();
155
+ var GEN = [
156
+ 996825010,
157
+ 642813549,
158
+ 513874426,
159
+ 1027748829,
160
+ 705979059
161
+ ];
162
+ function polymod(values) {
163
+ return values.reduce(
164
+ function(checksum, value) {
165
+ var bits = checksum >> 25;
166
+ var newChecksum = (checksum & 33554431) << 5 ^ value;
167
+ return GEN.reduce(function(chk, gen, i) {
168
+ return (bits >> i & 1) === 0 ? chk : chk ^ gen;
169
+ }, newChecksum);
170
+ },
171
+ /* initial checksum */
172
+ 1
173
+ );
174
+ }
175
+ __name(polymod, "polymod");
176
+ function expandPrefix(prefix, outBuffer) {
177
+ for (var i = 0; i < prefix.length; i += 1) {
178
+ var code = prefix.charCodeAt(i);
179
+ outBuffer[i] = code >> 5;
180
+ outBuffer[i + prefix.length + 1] = code & 31;
181
+ }
182
+ outBuffer[prefix.length] = 0;
183
+ }
184
+ __name(expandPrefix, "expandPrefix");
185
+ function verifyChecksum(buffer) {
186
+ switch (polymod(buffer)) {
187
+ case 1:
188
+ return "bech32";
189
+ case BECH32M_CHECKSUM:
190
+ return "bech32m";
191
+ default:
192
+ return void 0;
193
+ }
194
+ }
195
+ __name(verifyChecksum, "verifyChecksum");
196
+ function createChecksum(buffer, encoding) {
197
+ var checksumConstant;
198
+ switch (encoding) {
199
+ case "bech32":
200
+ checksumConstant = 1;
201
+ break;
202
+ case "bech32m":
203
+ checksumConstant = BECH32M_CHECKSUM;
204
+ break;
205
+ default:
206
+ throw Error("Invalid encoding value: ".concat(encoding, "; expected bech32 or bech32m"));
207
+ }
208
+ var mod = polymod(buffer) ^ checksumConstant;
209
+ for (var i = 0; i < CHECKSUM_LENGTH; i += 1) {
210
+ var shift = 5 * (5 - i);
211
+ buffer[buffer.length - CHECKSUM_LENGTH + i] = mod >> shift & 31;
212
+ }
213
+ }
214
+ __name(createChecksum, "createChecksum");
215
+ function encode(buffer) {
216
+ return buffer.reduce(function(acc, bits) {
217
+ return acc + CHARSET[bits];
218
+ }, "");
219
+ }
220
+ __name(encode, "encode");
221
+ function decode(message, dst) {
222
+ var realDst = dst || (0, _bitConverter.createBitArray)(message.length);
223
+ for (var i = 0; i < message.length; i += 1) {
224
+ var idx = CHAR_LOOKUP.get(message[i]);
225
+ if (idx === void 0) {
226
+ throw new Error("Invalid char in message: ".concat(message[i]));
227
+ }
228
+ realDst[i] = idx;
229
+ }
230
+ return realDst;
231
+ }
232
+ __name(decode, "decode");
233
+ function decodeWithPrefix(prefix, message) {
234
+ var len = message.length + 2 * prefix.length + 1;
235
+ var dst = (0, _bitConverter.createBitArray)(len);
236
+ expandPrefix(prefix, dst.subarray(0, 2 * prefix.length + 1));
237
+ decode(message, dst.subarray(2 * prefix.length + 1));
238
+ return dst;
239
+ }
240
+ __name(decodeWithPrefix, "decodeWithPrefix");
241
+ function detectCase(message) {
242
+ var messageDescription = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "message";
243
+ var hasLowerCase = false;
244
+ var hasUpperCase = false;
245
+ for (var i = 0; i < message.length; i += 1) {
246
+ var ord = message.charCodeAt(i);
247
+ if (ord < MIN_CHAR_CODE || ord > MAX_CHAR_CODE) {
248
+ throw new TypeError("Invalid char in ".concat(messageDescription, ": ").concat(ord, "; ") + "should be in ASCII range ".concat(MIN_CHAR_CODE, "-").concat(MAX_CHAR_CODE));
249
+ }
250
+ hasUpperCase = hasUpperCase || ord >= 65 && ord <= 90;
251
+ hasLowerCase = hasLowerCase || ord >= 97 && ord <= 122;
252
+ }
253
+ if (hasLowerCase && hasUpperCase) {
254
+ throw new TypeError("Mixed-case ".concat(messageDescription));
255
+ } else if (hasUpperCase) {
256
+ return "upper";
257
+ } else if (hasLowerCase) {
258
+ return "lower";
259
+ } else {
260
+ return null;
261
+ }
262
+ }
263
+ __name(detectCase, "detectCase");
264
+ }
265
+ });
266
+
267
+ // ../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/index.js
268
+ var require_lib = __commonJS({
269
+ "../../node_modules/.pnpm/bech32-buffer@0.2.1_patch_hash=elryfzb6nrq4qzi6wcigmgsdj4/node_modules/bech32-buffer/lib/index.js"(exports) {
270
+ Object.defineProperty(exports, "__esModule", {
271
+ value: true
272
+ });
273
+ exports.BitcoinAddress = void 0;
274
+ exports.decode = decode;
275
+ exports.decodeTo5BitArray = decodeTo5BitArray;
276
+ exports.encode = encode;
277
+ exports.encode5BitArray = encode5BitArray;
278
+ exports.from5BitArray = from5BitArray;
279
+ exports.to5BitArray = to5BitArray;
280
+ var _bitConverter = require_bit_converter();
281
+ var _encoding = require_encoding();
282
+ function _classCallCheck(instance, Constructor) {
283
+ if (!(instance instanceof Constructor)) {
284
+ throw new TypeError("Cannot call a class as a function");
285
+ }
286
+ }
287
+ __name(_classCallCheck, "_classCallCheck");
288
+ function _defineProperties(target, props) {
289
+ for (var i = 0; i < props.length; i++) {
290
+ var descriptor = props[i];
291
+ descriptor.enumerable = descriptor.enumerable || false;
292
+ descriptor.configurable = true;
293
+ if ("value" in descriptor)
294
+ descriptor.writable = true;
295
+ Object.defineProperty(target, descriptor.key, descriptor);
296
+ }
297
+ }
298
+ __name(_defineProperties, "_defineProperties");
299
+ function _createClass(Constructor, protoProps, staticProps) {
300
+ if (protoProps)
301
+ _defineProperties(Constructor.prototype, protoProps);
302
+ if (staticProps)
303
+ _defineProperties(Constructor, staticProps);
304
+ Object.defineProperty(Constructor, "prototype", {
305
+ writable: false
306
+ });
307
+ return Constructor;
308
+ }
309
+ __name(_createClass, "_createClass");
310
+ var MAX_ENC_LENGTH = 90;
311
+ function to5BitArray(src, dst) {
312
+ var len = Math.ceil(src.length * 8 / 5);
313
+ var realDst = dst || (0, _bitConverter.createBitArray)(len);
314
+ return (0, _bitConverter.toBits)(src, 5, realDst);
315
+ }
316
+ __name(to5BitArray, "to5BitArray");
317
+ function from5BitArray(src, dst) {
318
+ var len = Math.floor(src.length * 5 / 8);
319
+ var realDst = dst || new Uint8Array(len);
320
+ return (0, _bitConverter.fromBits)(src, 5, realDst);
321
+ }
322
+ __name(from5BitArray, "from5BitArray");
323
+ function encode5BitArray(prefix, data) {
324
+ var _detectCase;
325
+ var encoding = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "bech32";
326
+ var len = 2 * prefix.length + 1 + data.length + _encoding.CHECKSUM_LENGTH;
327
+ if (len - prefix.length > MAX_ENC_LENGTH) {
328
+ throw new Error("Message to be produced is too long (max ".concat(MAX_ENC_LENGTH, " supported)"));
329
+ }
330
+ var prefixCase = (_detectCase = (0, _encoding.detectCase)(prefix, "prefix")) !== null && _detectCase !== void 0 ? _detectCase : "lower";
331
+ var buffer = (0, _bitConverter.createBitArray)(len);
332
+ (0, _encoding.expandPrefix)(prefix.toLowerCase(), buffer.subarray(0, 2 * prefix.length + 1));
333
+ var dataBuffer = buffer.subarray(2 * prefix.length + 1, buffer.length - _encoding.CHECKSUM_LENGTH);
334
+ dataBuffer.set(data);
335
+ (0, _encoding.createChecksum)(buffer, encoding);
336
+ var encoded = (0, _encoding.encode)(buffer.subarray(2 * prefix.length + 1));
337
+ if (prefixCase === "upper") {
338
+ encoded = encoded.toUpperCase();
339
+ }
340
+ return "".concat(prefix, "1").concat(encoded);
341
+ }
342
+ __name(encode5BitArray, "encode5BitArray");
343
+ function encode(prefix, data) {
344
+ var encoding = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "bech32";
345
+ return encode5BitArray(prefix, to5BitArray(data), encoding);
346
+ }
347
+ __name(encode, "encode");
348
+ function decodeTo5BitArray(message) {
349
+ if (message.length > MAX_ENC_LENGTH) {
350
+ throw new TypeError("Message too long; max ".concat(MAX_ENC_LENGTH, " expected"));
351
+ }
352
+ (0, _encoding.detectCase)(message);
353
+ var lowerCaseMsg = message.toLowerCase();
354
+ var sepIdx = lowerCaseMsg.lastIndexOf("1");
355
+ if (sepIdx < 0) {
356
+ throw new Error('No separator char ("1") found');
357
+ }
358
+ if (sepIdx > message.length - _encoding.CHECKSUM_LENGTH - 1) {
359
+ throw new Error("Data part of the message too short (at least ".concat(_encoding.CHECKSUM_LENGTH, " chars expected)"));
360
+ }
361
+ var prefix = lowerCaseMsg.substring(0, sepIdx);
362
+ var bitArray = (0, _encoding.decodeWithPrefix)(prefix, lowerCaseMsg.substring(sepIdx + 1));
363
+ var encoding = (0, _encoding.verifyChecksum)(bitArray);
364
+ if (encoding === void 0) {
365
+ throw new Error("Invalid checksum");
366
+ }
367
+ return {
368
+ prefix,
369
+ encoding,
370
+ // Strip off the prefix from the front and the checksum from the end
371
+ data: bitArray.subarray(2 * prefix.length + 1, bitArray.length - _encoding.CHECKSUM_LENGTH)
372
+ };
373
+ }
374
+ __name(decodeTo5BitArray, "decodeTo5BitArray");
375
+ function decode(message) {
376
+ var _decodeTo5BitArray = decodeTo5BitArray(message), prefix = _decodeTo5BitArray.prefix, encoding = _decodeTo5BitArray.encoding, bitArray = _decodeTo5BitArray.data;
377
+ return {
378
+ prefix,
379
+ encoding,
380
+ data: from5BitArray(bitArray)
381
+ };
382
+ }
383
+ __name(decode, "decode");
384
+ var BitcoinAddress2 = /* @__PURE__ */ function() {
385
+ function BitcoinAddress3(prefix, scriptVersion, data) {
386
+ _classCallCheck(this, BitcoinAddress3);
387
+ if (prefix !== "bc" && prefix !== "tb" && prefix !== "bcrt") {
388
+ throw new Error('Invalid human-readable prefix, "bc", "tb", or "bcrt" expected');
389
+ }
390
+ if (scriptVersion < 0 || scriptVersion > 16) {
391
+ throw new RangeError("Invalid scriptVersion, value in range [0, 16] expected");
392
+ }
393
+ if (data.length < 2 || data.length > 40) {
394
+ throw new RangeError("Invalid script length: expected 2 to 40 bytes");
395
+ }
396
+ if (scriptVersion === 0 && data.length !== 20 && data.length !== 32) {
397
+ throw new Error("Invalid v0 script length: expected 20 or 32 bytes");
398
+ }
399
+ this.prefix = prefix;
400
+ this.scriptVersion = scriptVersion;
401
+ this.data = data;
402
+ }
403
+ __name(BitcoinAddress3, "BitcoinAddress");
404
+ _createClass(BitcoinAddress3, [
405
+ {
406
+ key: "type",
407
+ value: /* @__PURE__ */ __name(function type() {
408
+ if (this.scriptVersion !== 0) {
409
+ return void 0;
410
+ }
411
+ switch (this.data.length) {
412
+ case 20:
413
+ return "p2wpkh";
414
+ case 32:
415
+ return "p2wsh";
416
+ default:
417
+ return void 0;
418
+ }
419
+ }, "type")
420
+ },
421
+ {
422
+ key: "encode",
423
+ value: /* @__PURE__ */ __name(function encode2() {
424
+ var len = Math.ceil(this.data.length * 8 / 5);
425
+ var converted = (0, _bitConverter.createBitArray)(len + 1);
426
+ converted[0] = this.scriptVersion;
427
+ to5BitArray(this.data, converted.subarray(1));
428
+ var encoding = this.scriptVersion === 0 ? "bech32" : "bech32m";
429
+ return encode5BitArray(this.prefix, converted, encoding);
430
+ }, "encode")
431
+ }
432
+ ], [
433
+ {
434
+ key: "decode",
435
+ value: (
436
+ /**
437
+ * Human-readable prefix. Equal to `'bc'` (for mainnet addresses)
438
+ * or `'tb'` (for testnet addresses).
439
+ */
440
+ /**
441
+ * Script version. An integer between 0 and 16 (inclusive).
442
+ */
443
+ /**
444
+ * Script data. A byte string with length 2 to 40 (inclusive).
445
+ */
446
+ /**
447
+ * Decodes a Bitcoin address from a Bech32(m) string.
448
+ * As per BIP 350, the original encoding is expected for version 0 scripts, while
449
+ * other script versions expect the modified encoding.
450
+ *
451
+ * This method does not check whether the address is well-formed;
452
+ * use `type()` method on returned address to find that out.
453
+ *
454
+ * @param {string} message
455
+ * @returns {BitcoinAddress}
456
+ */
457
+ /* @__PURE__ */ __name(function decode2(message) {
458
+ var _decodeTo5BitArray2 = decodeTo5BitArray(message), prefix = _decodeTo5BitArray2.prefix, data = _decodeTo5BitArray2.data, encoding = _decodeTo5BitArray2.encoding;
459
+ if (prefix !== "bc" && prefix !== "tb" && prefix !== "bcrt") {
460
+ throw new Error('Invalid human-readable prefix, "bc", "tb", or "bcrt" expected');
461
+ }
462
+ var scriptVersion = data[0];
463
+ if (scriptVersion === 0 && encoding !== "bech32") {
464
+ throw Error("Unexpected encoding ".concat(encoding, " used for version 0 script"));
465
+ }
466
+ if (scriptVersion > 0 && encoding !== "bech32m") {
467
+ throw Error("Unexpected encoding ".concat(encoding, " used for version ").concat(scriptVersion, " script"));
468
+ }
469
+ return new this(prefix, scriptVersion, from5BitArray(data.subarray(1)));
470
+ }, "decode")
471
+ )
472
+ }
473
+ ]);
474
+ return BitcoinAddress3;
475
+ }();
476
+ exports.BitcoinAddress = BitcoinAddress2;
477
+ }
478
+ });
17
479
  var _abi = [
18
480
  {
19
481
  inputs: [
@@ -85,10 +547,10 @@ var _abi = [
85
547
  ];
86
548
  var _ERC20__factory = class _ERC20__factory {
87
549
  static createInterface() {
88
- return new ethers.Interface(_abi);
550
+ return new ethers2.Interface(_abi);
89
551
  }
90
552
  static connect(address, runner) {
91
- return new ethers.Contract(address, _abi, runner);
553
+ return new ethers2.Contract(address, _abi, runner);
92
554
  }
93
555
  };
94
556
  __name(_ERC20__factory, "ERC20__factory");
@@ -756,10 +1218,10 @@ var _abi2 = [
756
1218
  ];
757
1219
  var _StateChainGateway__factory = class _StateChainGateway__factory {
758
1220
  static createInterface() {
759
- return new ethers.Interface(_abi2);
1221
+ return new ethers2.Interface(_abi2);
760
1222
  }
761
1223
  static connect(address, runner) {
762
- return new ethers.Contract(address, _abi2, runner);
1224
+ return new ethers2.Contract(address, _abi2, runner);
763
1225
  }
764
1226
  };
765
1227
  __name(_StateChainGateway__factory, "StateChainGateway__factory");
@@ -789,13 +1251,13 @@ var ChainflipNetworks = arrayToMap([
789
1251
  "perseverance",
790
1252
  "mainnet"
791
1253
  ]);
792
- ({
1254
+ var assetChains = {
793
1255
  [Assets.ETH]: Chains.Ethereum,
794
1256
  [Assets.FLIP]: Chains.Ethereum,
795
1257
  [Assets.USDC]: Chains.Ethereum,
796
1258
  [Assets.BTC]: Chains.Bitcoin,
797
1259
  [Assets.DOT]: Chains.Polkadot
798
- });
1260
+ };
799
1261
  ({
800
1262
  [Assets.DOT]: 10,
801
1263
  [Assets.ETH]: 18,
@@ -876,13 +1338,17 @@ var extractOverrides = /* @__PURE__ */ __name((transactionOverrides) => {
876
1338
  const { wait, ...ethersOverrides } = transactionOverrides;
877
1339
  return ethersOverrides;
878
1340
  }, "extractOverrides");
879
- var getTokenContractAddress = /* @__PURE__ */ __name((asset, network) => {
1341
+ function getTokenContractAddress(asset, network, assert2 = true) {
880
1342
  if (asset === Assets.FLIP)
881
1343
  return ADDRESSES[network].FLIP_CONTRACT_ADDRESS;
882
1344
  if (asset === Assets.USDC)
883
1345
  return ADDRESSES[network].USDC_CONTRACT_ADDRESS;
884
- throw new Error("Only FLIP and USDC are supported for now");
885
- }, "getTokenContractAddress");
1346
+ if (assert2) {
1347
+ throw new Error("Only FLIP and USDC are supported for now");
1348
+ }
1349
+ return void 0;
1350
+ }
1351
+ __name(getTokenContractAddress, "getTokenContractAddress");
886
1352
  var getStateChainGatewayContractAddress = /* @__PURE__ */ __name((network) => ADDRESSES[network].STATE_CHAIN_GATEWAY_ADDRESS, "getStateChainGatewayContractAddress");
887
1353
  var checkAllowance = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20Address, signer) => {
888
1354
  const erc20 = ERC20__factory.connect(erc20Address, signer);
@@ -1406,12 +1872,12 @@ var handleResult = /* @__PURE__ */ __name((ctx, result) => {
1406
1872
  function processCreateParams(params) {
1407
1873
  if (!params)
1408
1874
  return {};
1409
- const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
1410
- if (errorMap2 && (invalid_type_error || required_error)) {
1875
+ const { errorMap: errorMap3, invalid_type_error, required_error, description } = params;
1876
+ if (errorMap3 && (invalid_type_error || required_error)) {
1411
1877
  throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
1412
1878
  }
1413
- if (errorMap2)
1414
- return { errorMap: errorMap2, description };
1879
+ if (errorMap3)
1880
+ return { errorMap: errorMap3, description };
1415
1881
  const customMap = /* @__PURE__ */ __name((iss, ctx) => {
1416
1882
  if (iss.code !== "invalid_type")
1417
1883
  return { message: ctx.defaultError };
@@ -4735,6 +5201,117 @@ var z = /* @__PURE__ */ Object.freeze({
4735
5201
  ZodError
4736
5202
  });
4737
5203
 
5204
+ // ../shared/src/guards.ts
5205
+ var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
5206
+ function assert(condition, message) {
5207
+ if (condition)
5208
+ return;
5209
+ const error = new Error(message);
5210
+ if (error.stack) {
5211
+ error.stack = error.stack.replace(/\n.+/, "\n");
5212
+ }
5213
+ throw error;
5214
+ }
5215
+ __name(assert, "assert");
5216
+
5217
+ // ../shared/src/bitcoin.ts
5218
+ __toESM(require_lib());
5219
+
5220
+ // ../shared/src/parsers.ts
5221
+ var safeStringify = /* @__PURE__ */ __name((obj) => JSON.stringify(obj, (key, value) => typeof value === "bigint" ? value.toString() : value), "safeStringify");
5222
+ var errorMap2 = /* @__PURE__ */ __name((_issue, context) => ({
5223
+ message: `received: ${safeStringify(context.data)}`
5224
+ }), "errorMap");
5225
+ var string = z.string({
5226
+ errorMap: errorMap2
5227
+ });
5228
+ var number = z.number({
5229
+ errorMap: errorMap2
5230
+ });
5231
+ var numericString = string.regex(/^[0-9]+$/);
5232
+ var hexString = string.refine((v) => /^0x[0-9a-f]+$/i.test(v));
5233
+ numericString.transform((arg) => `0x${BigInt(arg).toString(16)}`);
5234
+ string.regex(/^[0-9a-f]+$/);
5235
+ var DOT_PREFIX = 0;
5236
+ z.union([
5237
+ string,
5238
+ hexString
5239
+ ]).transform((arg) => {
5240
+ try {
5241
+ if (arg.startsWith("0x")) {
5242
+ return utilCrypto.encodeAddress(util$1.hexToU8a(arg), DOT_PREFIX);
5243
+ }
5244
+ const hex = util$1.u8aToHex(utilCrypto.decodeAddress(arg));
5245
+ return utilCrypto.encodeAddress(hex, DOT_PREFIX);
5246
+ } catch {
5247
+ return null;
5248
+ }
5249
+ }).refine(isString);
5250
+ hexString.refine((address) => ethers2__namespace.isAddress(address));
5251
+ numericString.transform((arg) => BigInt(arg));
5252
+ var u128 = z.union([
5253
+ number,
5254
+ numericString,
5255
+ hexString
5256
+ ]).transform((arg) => BigInt(arg));
5257
+ var unsignedInteger = z.union([
5258
+ u128,
5259
+ z.number().transform((n) => BigInt(n))
5260
+ ]);
5261
+ z.object({
5262
+ __kind: z.enum([
5263
+ "Usdc",
5264
+ "Flip",
5265
+ "Dot",
5266
+ "Eth",
5267
+ "Btc"
5268
+ ])
5269
+ }).transform(({ __kind }) => __kind.toUpperCase());
5270
+ var transformAsset = /* @__PURE__ */ __name((asset) => ({
5271
+ asset,
5272
+ chain: assetChains[asset]
5273
+ }), "transformAsset");
5274
+ z.nativeEnum(Chains);
5275
+ var chainflipAsset = z.nativeEnum(Assets);
5276
+ z.union([
5277
+ chainflipAsset.transform(transformAsset),
5278
+ z.object({
5279
+ asset: z.nativeEnum(Assets),
5280
+ chain: z.nativeEnum(Chains)
5281
+ })
5282
+ ]).superRefine((obj, ctx) => {
5283
+ if (assetChains[obj.asset] !== obj.chain) {
5284
+ ctx.addIssue({
5285
+ code: z.ZodIssueCode.custom,
5286
+ message: `asset ${obj.asset} does not belong to chain ${obj.chain}`,
5287
+ path: []
5288
+ });
5289
+ }
5290
+ return z.NEVER;
5291
+ });
5292
+ z.nativeEnum(ChainflipNetworks);
5293
+ z.union([
5294
+ z.object({
5295
+ __kind: z.literal("CcmPrincipal"),
5296
+ value: unsignedInteger
5297
+ }).transform(({ value: ccmId }) => ({
5298
+ type: "PRINCIPAL",
5299
+ ccmId
5300
+ })),
5301
+ z.object({
5302
+ __kind: z.literal("CcmGas"),
5303
+ value: unsignedInteger
5304
+ }).transform(({ value: ccmId }) => ({
5305
+ type: "GAS",
5306
+ ccmId
5307
+ })),
5308
+ z.object({
5309
+ __kind: z.literal("Swap")
5310
+ }).transform(() => ({
5311
+ type: "SWAP"
5312
+ }))
5313
+ ]);
5314
+
4738
5315
  // ../shared/src/rpc/index.ts
4739
5316
  var numberOrHex = z.union([
4740
5317
  z.string(),
@@ -4795,11 +5372,31 @@ var swappingEnvironment = z.object({
4795
5372
  maximum_swap_amounts: chainAssetNumberNullableMap
4796
5373
  });
4797
5374
  createRequest("cf_swapping_environment", swappingEnvironment);
5375
+ var rename = /* @__PURE__ */ __name((mapping) => (obj) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [
5376
+ key in mapping ? mapping[key] : key,
5377
+ value
5378
+ ])), "rename");
4798
5379
  var ingressEgressEnvironment = z.object({
4799
5380
  minimum_deposit_amounts: chainAssetNumberMap,
4800
5381
  ingress_fees: chainAssetNumberMap,
4801
- egress_fees: chainAssetNumberMap
4802
- });
5382
+ egress_fees: chainAssetNumberMap,
5383
+ // TODO(1.2): remove optional and default value
5384
+ egress_dust_limits: chainAssetNumberMap.optional().default({
5385
+ Bitcoin: {
5386
+ BTC: 600
5387
+ },
5388
+ Ethereum: {
5389
+ ETH: 1,
5390
+ USDC: 1,
5391
+ FLIP: 1
5392
+ },
5393
+ Polkadot: {
5394
+ DOT: 1
5395
+ }
5396
+ })
5397
+ }).transform(rename({
5398
+ egress_dust_limits: "minimum_egress_amounts"
5399
+ }));
4803
5400
  createRequest("cf_ingress_egress_environment", ingressEgressEnvironment);
4804
5401
  var rpcAsset = z.union([
4805
5402
  z.literal("BTC"),
@@ -4867,6 +5464,7 @@ var swapRate = z.object({
4867
5464
  output: numberOrHex
4868
5465
  });
4869
5466
  createRequest("cf_swap_rate", swapRate);
5467
+ createRequest("state_getMetadata", hexString);
4870
5468
 
4871
5469
  // ../shared/src/stateChainGateway/utils.ts
4872
5470
  var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
@@ -4874,18 +5472,6 @@ var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
4874
5472
  return StateChainGateway__factory.connect(stateChainGatewayContractAddress, networkOpts.signer);
4875
5473
  }, "getStateChainGateway");
4876
5474
 
4877
- // ../shared/src/guards.ts
4878
- function assert(condition, message) {
4879
- if (condition)
4880
- return;
4881
- const error = new Error(message);
4882
- if (error.stack) {
4883
- error.stack = error.stack.replace(/\n.+/, "\n");
4884
- }
4885
- throw error;
4886
- }
4887
- __name(assert, "assert");
4888
-
4889
5475
  // ../shared/src/stateChainGateway/approval.ts
4890
5476
  var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount, networkOpts) => {
4891
5477
  const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getTokenContractAddress(Assets.FLIP, networkOpts.network);