@chainflip/sdk 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-7N46BL6F.mjs → chunk-DBYVPLEW.mjs} +21 -1
- package/dist/funding.js +18 -0
- package/dist/funding.mjs +1 -1
- package/dist/swap.d.ts +2 -0
- package/dist/swap.js +832 -802
- package/dist/swap.mjs +17 -7
- package/package.json +3 -3
package/dist/swap.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var ethers = require('ethers');
|
|
4
3
|
var utilCrypto = require('@polkadot/util-crypto');
|
|
4
|
+
var ethers = require('ethers');
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
var util = require('@polkadot/util');
|
|
7
7
|
var axios = require('axios');
|
|
@@ -117,140 +117,565 @@ function assert(condition, message) {
|
|
|
117
117
|
__name(assert, "assert");
|
|
118
118
|
var isTokenSwap = /* @__PURE__ */ __name((params) => params.srcAsset !== Assets.ETH, "isTokenSwap");
|
|
119
119
|
var isTokenCall = /* @__PURE__ */ __name((params) => params.srcAsset !== Assets.ETH, "isTokenCall");
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
stateMutability: "view",
|
|
143
|
-
type: "function"
|
|
120
|
+
|
|
121
|
+
// ../shared/src/validation/segwitAddr.ts
|
|
122
|
+
var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
123
|
+
var GENERATOR = [
|
|
124
|
+
996825010,
|
|
125
|
+
642813549,
|
|
126
|
+
513874426,
|
|
127
|
+
1027748829,
|
|
128
|
+
705979059
|
|
129
|
+
];
|
|
130
|
+
var Encoding;
|
|
131
|
+
(function(Encoding2) {
|
|
132
|
+
Encoding2["Bech32"] = "bech32";
|
|
133
|
+
Encoding2["Bech32m"] = "bech32m";
|
|
134
|
+
})(Encoding || (Encoding = {}));
|
|
135
|
+
var bech32 = {
|
|
136
|
+
getEncodingConst(enc) {
|
|
137
|
+
if (enc === Encoding.Bech32)
|
|
138
|
+
return 1;
|
|
139
|
+
if (enc === Encoding.Bech32m)
|
|
140
|
+
return 734539939;
|
|
141
|
+
return null;
|
|
144
142
|
},
|
|
145
|
-
{
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
name: "amount",
|
|
155
|
-
type: "uint256"
|
|
156
|
-
}
|
|
157
|
-
],
|
|
158
|
-
name: "approve",
|
|
159
|
-
outputs: [
|
|
160
|
-
{
|
|
161
|
-
internalType: "bool",
|
|
162
|
-
name: "",
|
|
163
|
-
type: "bool"
|
|
143
|
+
polymod(values) {
|
|
144
|
+
let chk = 1;
|
|
145
|
+
for (let p = 0; p < values.length; p += 1) {
|
|
146
|
+
const top = chk >> 25;
|
|
147
|
+
chk = (chk & 33554431) << 5 ^ values[p];
|
|
148
|
+
for (let i = 0; i < 5; i += 1) {
|
|
149
|
+
if (top >> i & 1) {
|
|
150
|
+
chk ^= GENERATOR[i];
|
|
151
|
+
}
|
|
164
152
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
type: "function"
|
|
153
|
+
}
|
|
154
|
+
return chk;
|
|
168
155
|
},
|
|
169
|
-
{
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
156
|
+
hrpExpand(hrp) {
|
|
157
|
+
const ret = [];
|
|
158
|
+
let p;
|
|
159
|
+
for (p = 0; p < hrp.length; p += 1) {
|
|
160
|
+
ret.push(hrp.charCodeAt(p) >> 5);
|
|
161
|
+
}
|
|
162
|
+
ret.push(0);
|
|
163
|
+
for (p = 0; p < hrp.length; p += 1) {
|
|
164
|
+
ret.push(hrp.charCodeAt(p) & 31);
|
|
165
|
+
}
|
|
166
|
+
return ret;
|
|
167
|
+
},
|
|
168
|
+
verifyChecksum(hrp, data, enc) {
|
|
169
|
+
return this.polymod(this.hrpExpand(hrp).concat(data)) === this.getEncodingConst(enc);
|
|
170
|
+
},
|
|
171
|
+
createChecksum(hrp, data, enc) {
|
|
172
|
+
const values = this.hrpExpand(hrp).concat(data).concat([
|
|
173
|
+
0,
|
|
174
|
+
0,
|
|
175
|
+
0,
|
|
176
|
+
0,
|
|
177
|
+
0,
|
|
178
|
+
0
|
|
179
|
+
]);
|
|
180
|
+
const mod = this.polymod(values) ^ this.getEncodingConst(enc);
|
|
181
|
+
const ret = [];
|
|
182
|
+
for (let p = 0; p < 6; p += 1) {
|
|
183
|
+
ret.push(mod >> 5 * (5 - p) & 31);
|
|
184
|
+
}
|
|
185
|
+
return ret;
|
|
186
|
+
},
|
|
187
|
+
encode(hrp, data, enc) {
|
|
188
|
+
const combined = data.concat(this.createChecksum(hrp, data, enc));
|
|
189
|
+
let ret = `${hrp}1`;
|
|
190
|
+
for (let p = 0; p < combined.length; p += 1) {
|
|
191
|
+
ret += CHARSET.charAt(combined[p]);
|
|
192
|
+
}
|
|
193
|
+
return ret;
|
|
194
|
+
},
|
|
195
|
+
decode(bechString, enc) {
|
|
196
|
+
let p;
|
|
197
|
+
let hasLower = false;
|
|
198
|
+
let hasUpper = false;
|
|
199
|
+
for (p = 0; p < bechString.length; p += 1) {
|
|
200
|
+
if (bechString.charCodeAt(p) < 33 || bechString.charCodeAt(p) > 126) {
|
|
201
|
+
return null;
|
|
175
202
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
outputs: [
|
|
179
|
-
{
|
|
180
|
-
internalType: "uint256",
|
|
181
|
-
name: "",
|
|
182
|
-
type: "uint256"
|
|
203
|
+
if (bechString.charCodeAt(p) >= 97 && bechString.charCodeAt(p) <= 122) {
|
|
204
|
+
hasLower = true;
|
|
183
205
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
206
|
+
if (bechString.charCodeAt(p) >= 65 && bechString.charCodeAt(p) <= 90) {
|
|
207
|
+
hasUpper = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (hasLower && hasUpper)
|
|
211
|
+
return null;
|
|
212
|
+
const lowercase = bechString.toLowerCase();
|
|
213
|
+
const pos = lowercase.lastIndexOf("1");
|
|
214
|
+
if (pos < 1 || pos + 7 > lowercase.length || lowercase.length > 90) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
const hrp = lowercase.substring(0, pos);
|
|
218
|
+
const data = [];
|
|
219
|
+
for (p = pos + 1; p < lowercase.length; p += 1) {
|
|
220
|
+
const d = CHARSET.indexOf(lowercase.charAt(p));
|
|
221
|
+
if (d === -1)
|
|
222
|
+
return null;
|
|
223
|
+
data.push(d);
|
|
224
|
+
}
|
|
225
|
+
if (!this.verifyChecksum(hrp, data, enc)) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
hrp,
|
|
230
|
+
data: data.slice(0, data.length - 6)
|
|
231
|
+
};
|
|
195
232
|
}
|
|
196
233
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
234
|
+
var segwitAddress = {
|
|
235
|
+
convertbits(data, frombits, tobits, pad) {
|
|
236
|
+
let acc = 0;
|
|
237
|
+
let bits = 0;
|
|
238
|
+
const ret = [];
|
|
239
|
+
const maxv = (1 << tobits) - 1;
|
|
240
|
+
for (let p = 0; p < data.length; p += 1) {
|
|
241
|
+
const value = data[p];
|
|
242
|
+
if (value < 0 || value >> frombits !== 0) {
|
|
243
|
+
return null;
|
|
206
244
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
anonymous: false,
|
|
213
|
-
inputs: [
|
|
214
|
-
{
|
|
215
|
-
indexed: false,
|
|
216
|
-
internalType: "bytes32",
|
|
217
|
-
name: "swapID",
|
|
218
|
-
type: "bytes32"
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
indexed: false,
|
|
222
|
-
internalType: "uint256",
|
|
223
|
-
name: "amount",
|
|
224
|
-
type: "uint256"
|
|
245
|
+
acc = acc << frombits | value;
|
|
246
|
+
bits += frombits;
|
|
247
|
+
while (bits >= tobits) {
|
|
248
|
+
bits -= tobits;
|
|
249
|
+
ret.push(acc >> bits & maxv);
|
|
225
250
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
{
|
|
231
|
-
anonymous: false,
|
|
232
|
-
inputs: [
|
|
233
|
-
{
|
|
234
|
-
indexed: false,
|
|
235
|
-
internalType: "bytes32",
|
|
236
|
-
name: "swapID",
|
|
237
|
-
type: "bytes32"
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
indexed: false,
|
|
241
|
-
internalType: "uint256",
|
|
242
|
-
name: "amount",
|
|
243
|
-
type: "uint256"
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
indexed: false,
|
|
247
|
-
internalType: "address",
|
|
248
|
-
name: "token",
|
|
249
|
-
type: "address"
|
|
251
|
+
}
|
|
252
|
+
if (pad) {
|
|
253
|
+
if (bits > 0) {
|
|
254
|
+
ret.push(acc << tobits - bits & maxv);
|
|
250
255
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
256
|
+
} else if (bits >= frombits || acc << tobits - bits & maxv) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
return ret;
|
|
260
|
+
},
|
|
261
|
+
decode(hrp, addr) {
|
|
262
|
+
let bech32m = false;
|
|
263
|
+
let dec = bech32.decode(addr, Encoding.Bech32);
|
|
264
|
+
if (dec === null) {
|
|
265
|
+
dec = bech32.decode(addr, Encoding.Bech32m);
|
|
266
|
+
bech32m = true;
|
|
267
|
+
}
|
|
268
|
+
if (dec === null || dec.hrp !== hrp || dec.data.length < 1 || dec.data[0] > 16) {
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
const res = this.convertbits(dec.data.slice(1), 5, 8, false);
|
|
272
|
+
if (res === null || res.length < 2 || res.length > 40) {
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
if (dec.data[0] === 0 && res.length !== 20 && res.length !== 32) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
if (dec.data[0] === 0 && bech32m) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
if (dec.data[0] !== 0 && !bech32m) {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
version: dec.data[0],
|
|
286
|
+
program: res
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
encode(hrp, version, program) {
|
|
290
|
+
let enc = Encoding.Bech32;
|
|
291
|
+
if (version > 0) {
|
|
292
|
+
enc = Encoding.Bech32m;
|
|
293
|
+
}
|
|
294
|
+
const ret = bech32.encode(
|
|
295
|
+
hrp,
|
|
296
|
+
// @ts-expect-error can be null
|
|
297
|
+
[
|
|
298
|
+
version
|
|
299
|
+
].concat(this.convertbits(program, 8, 5, true)),
|
|
300
|
+
enc
|
|
301
|
+
);
|
|
302
|
+
if (this.decode(hrp, ret) === null) {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
return ret;
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
var isValidSegwitAddress = /* @__PURE__ */ __name((address) => {
|
|
309
|
+
const hrp = /^(bc|tb|bcrt)1/.exec(address)?.[1];
|
|
310
|
+
if (!hrp)
|
|
311
|
+
return false;
|
|
312
|
+
return segwitAddress.decode(hrp, address) !== null;
|
|
313
|
+
}, "isValidSegwitAddress");
|
|
314
|
+
|
|
315
|
+
// ../shared/src/validation/addressValidation.ts
|
|
316
|
+
var assertArraylikeEqual = /* @__PURE__ */ __name((a, b) => {
|
|
317
|
+
assert(a.length === b.length, "arraylike lengths must be equal");
|
|
318
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
319
|
+
assert(a[i] === b[i], "arraylike elements must be equal");
|
|
320
|
+
}
|
|
321
|
+
}, "assertArraylikeEqual");
|
|
322
|
+
var validateP2PKHOrP2SHAddress = /* @__PURE__ */ __name((address, network) => {
|
|
323
|
+
try {
|
|
324
|
+
const decoded = ethers__namespace.utils.base58.decode(address);
|
|
325
|
+
assert(decoded.length === 25, "decoded address must be 25 bytes long");
|
|
326
|
+
if (network === "mainnet") {
|
|
327
|
+
assert(decoded[0] === 0 || decoded[0] === 5, "decoded address must start with 0x00 or 0x05");
|
|
328
|
+
} else {
|
|
329
|
+
assert(decoded[0] === 111 || decoded[0] === 196, "decoded address must start with 0x6f or 0xc4");
|
|
330
|
+
}
|
|
331
|
+
const checksum = decoded.slice(-4);
|
|
332
|
+
const doubleHash = ethers__namespace.utils.arrayify(ethers__namespace.utils.sha256(ethers__namespace.utils.sha256(decoded.slice(0, 21))));
|
|
333
|
+
assertArraylikeEqual(checksum, doubleHash.slice(0, 4));
|
|
334
|
+
return true;
|
|
335
|
+
} catch (error) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
}, "validateP2PKHOrP2SHAddress");
|
|
339
|
+
var validateSegwitAddress = /* @__PURE__ */ __name((address, network) => {
|
|
340
|
+
try {
|
|
341
|
+
assert(
|
|
342
|
+
// On mainnet, the address must start with "bc1"
|
|
343
|
+
network === "mainnet" && address.startsWith("bc1") || // on testnet it must start with "tb1"
|
|
344
|
+
network === "testnet" && address.startsWith("tb1") || // on regtest it must start with "bcrt1"
|
|
345
|
+
network === "regtest" && address.startsWith("bcrt1"),
|
|
346
|
+
"address must start with bc1, tb1 or bcrt1"
|
|
347
|
+
);
|
|
348
|
+
return isValidSegwitAddress(address);
|
|
349
|
+
} catch {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
}, "validateSegwitAddress");
|
|
353
|
+
var validateBitcoinAddress = /* @__PURE__ */ __name((address, network) => validateP2PKHOrP2SHAddress(address, network) || validateSegwitAddress(address, network), "validateBitcoinAddress");
|
|
354
|
+
var validateBitcoinMainnetAddress = /* @__PURE__ */ __name((address) => validateBitcoinAddress(address, "mainnet"), "validateBitcoinMainnetAddress");
|
|
355
|
+
var validateBitcoinTestnetAddress = /* @__PURE__ */ __name((address) => validateBitcoinAddress(address, "testnet"), "validateBitcoinTestnetAddress");
|
|
356
|
+
var validateBitcoinRegtestAddress = /* @__PURE__ */ __name((address) => validateBitcoinAddress(address, "regtest"), "validateBitcoinRegtestAddress");
|
|
357
|
+
|
|
358
|
+
// ../shared/src/parsers.ts
|
|
359
|
+
var errorMap = /* @__PURE__ */ __name((_issue, context) => ({
|
|
360
|
+
message: `received: ${JSON.stringify(context.data)}`
|
|
361
|
+
}), "errorMap");
|
|
362
|
+
var string = zod.z.string({
|
|
363
|
+
errorMap
|
|
364
|
+
});
|
|
365
|
+
zod.z.number({
|
|
366
|
+
errorMap
|
|
367
|
+
});
|
|
368
|
+
var numericString = string.regex(/^[0-9]+$/);
|
|
369
|
+
var hexString = zod.z.custom((val) => typeof val === "string" && /^0x[0-9a-f]+$/i.test(val));
|
|
370
|
+
numericString.transform((arg) => ethers__namespace.BigNumber.from(arg).toHexString()).refine((arg) => arg.startsWith("0x"));
|
|
371
|
+
string.regex(/^[0-9a-f]+$/);
|
|
372
|
+
var btcAddress = /* @__PURE__ */ __name((env) => {
|
|
373
|
+
const network = env ?? process.env.CHAINFLIP_NETWORK;
|
|
374
|
+
if (network === "mainnet")
|
|
375
|
+
return string.regex(/^(1|3|bc1)/).refine(validateBitcoinMainnetAddress);
|
|
376
|
+
return zod.z.union([
|
|
377
|
+
string.regex(/^(m|n|2|tb1)/).refine(validateBitcoinTestnetAddress),
|
|
378
|
+
string.regex(/^bcrt1/).refine(validateBitcoinRegtestAddress)
|
|
379
|
+
]);
|
|
380
|
+
}, "btcAddress");
|
|
381
|
+
var dotAddress = zod.z.union([
|
|
382
|
+
string,
|
|
383
|
+
hexString
|
|
384
|
+
]).transform((arg) => {
|
|
385
|
+
try {
|
|
386
|
+
if (arg.startsWith("0x")) {
|
|
387
|
+
return utilCrypto.encodeAddress(util.hexToU8a(arg));
|
|
388
|
+
}
|
|
389
|
+
utilCrypto.decodeAddress(arg);
|
|
390
|
+
return arg;
|
|
391
|
+
} catch {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
}).refine(isString);
|
|
395
|
+
var ethereumAddress = hexString.refine((address) => ethers__namespace.utils.isAddress(address));
|
|
396
|
+
numericString.transform((arg) => BigInt(arg));
|
|
397
|
+
var u128 = zod.z.union([
|
|
398
|
+
numericString,
|
|
399
|
+
hexString
|
|
400
|
+
]).transform((arg) => BigInt(arg));
|
|
401
|
+
var unsignedInteger = zod.z.union([
|
|
402
|
+
u128,
|
|
403
|
+
zod.z.number().transform((n) => BigInt(n))
|
|
404
|
+
]);
|
|
405
|
+
zod.z.object({
|
|
406
|
+
__kind: zod.z.enum([
|
|
407
|
+
"Usdc",
|
|
408
|
+
"Flip",
|
|
409
|
+
"Dot",
|
|
410
|
+
"Eth",
|
|
411
|
+
"Btc"
|
|
412
|
+
])
|
|
413
|
+
}).transform(({ __kind }) => __kind.toUpperCase());
|
|
414
|
+
zod.z.nativeEnum(Chains);
|
|
415
|
+
zod.z.nativeEnum(Assets);
|
|
416
|
+
var chainflipNetwork = zod.z.nativeEnum(ChainflipNetworks);
|
|
417
|
+
zod.z.union([
|
|
418
|
+
zod.z.object({
|
|
419
|
+
__kind: zod.z.literal("CcmPrincipal"),
|
|
420
|
+
value: unsignedInteger
|
|
421
|
+
}).transform(({ value: ccmId }) => ({
|
|
422
|
+
type: "PRINCIPAL",
|
|
423
|
+
ccmId
|
|
424
|
+
})),
|
|
425
|
+
zod.z.object({
|
|
426
|
+
__kind: zod.z.literal("CcmGas"),
|
|
427
|
+
value: unsignedInteger
|
|
428
|
+
}).transform(({ value: ccmId }) => ({
|
|
429
|
+
type: "GAS",
|
|
430
|
+
ccmId
|
|
431
|
+
})),
|
|
432
|
+
zod.z.object({
|
|
433
|
+
__kind: zod.z.literal("Swap")
|
|
434
|
+
}).transform(() => ({
|
|
435
|
+
type: "SWAP"
|
|
436
|
+
}))
|
|
437
|
+
]);
|
|
438
|
+
|
|
439
|
+
// ../shared/src/vault/schemas.ts
|
|
440
|
+
var bytesToHex = /* @__PURE__ */ __name((arr) => `0x${[
|
|
441
|
+
...arr
|
|
442
|
+
].map((v) => v.toString(16).padStart(2, "0")).join("")}`, "bytesToHex");
|
|
443
|
+
var utf8ToHex = /* @__PURE__ */ __name((str) => `0x${Buffer.from(str).toString("hex")}`, "utf8ToHex");
|
|
444
|
+
var eth = zod.z.object({
|
|
445
|
+
amount: zod.z.union([
|
|
446
|
+
numericString,
|
|
447
|
+
hexString,
|
|
448
|
+
zod.z.bigint()
|
|
449
|
+
]),
|
|
450
|
+
srcChain: zod.z.literal(Chains.Ethereum),
|
|
451
|
+
srcAsset: zod.z.literal(Assets.ETH)
|
|
452
|
+
});
|
|
453
|
+
var ethToEthereum = eth.extend({
|
|
454
|
+
destChain: zod.z.literal(Chains.Ethereum),
|
|
455
|
+
destAddress: ethereumAddress
|
|
456
|
+
});
|
|
457
|
+
var ethToDot = eth.extend({
|
|
458
|
+
destChain: zod.z.literal(Chains.Polkadot),
|
|
459
|
+
destAddress: dotAddress.transform((addr) => bytesToHex(utilCrypto.decodeAddress(addr))),
|
|
460
|
+
destAsset: zod.z.literal(Assets.DOT)
|
|
461
|
+
});
|
|
462
|
+
var ethToBtc = eth.extend({
|
|
463
|
+
destChain: zod.z.literal(Chains.Bitcoin),
|
|
464
|
+
destAddress: btcAddress().transform(utf8ToHex),
|
|
465
|
+
destAsset: zod.z.literal(Assets.BTC)
|
|
466
|
+
});
|
|
467
|
+
var erc20Asset = zod.z.union([
|
|
468
|
+
zod.z.literal(Assets.FLIP),
|
|
469
|
+
zod.z.literal(Assets.USDC)
|
|
470
|
+
]);
|
|
471
|
+
var ethToERC20 = ethToEthereum.extend({
|
|
472
|
+
destAsset: erc20Asset
|
|
473
|
+
});
|
|
474
|
+
var nativeSwapParamsSchema = zod.z.union([
|
|
475
|
+
ethToERC20,
|
|
476
|
+
ethToDot,
|
|
477
|
+
ethToBtc
|
|
478
|
+
]);
|
|
479
|
+
var flipToEthereumAsset = ethToEthereum.extend({
|
|
480
|
+
srcAsset: zod.z.literal(Assets.FLIP),
|
|
481
|
+
destAsset: zod.z.union([
|
|
482
|
+
zod.z.literal(Assets.USDC),
|
|
483
|
+
zod.z.literal(Assets.ETH)
|
|
484
|
+
])
|
|
485
|
+
});
|
|
486
|
+
var usdcToEthereumAsset = ethToEthereum.extend({
|
|
487
|
+
srcAsset: zod.z.literal(Assets.USDC),
|
|
488
|
+
destAsset: zod.z.union([
|
|
489
|
+
zod.z.literal(Assets.FLIP),
|
|
490
|
+
zod.z.literal(Assets.ETH)
|
|
491
|
+
])
|
|
492
|
+
});
|
|
493
|
+
var erc20ToDot = ethToDot.extend({
|
|
494
|
+
srcAsset: erc20Asset
|
|
495
|
+
});
|
|
496
|
+
var erc20ToBtc = ethToBtc.extend({
|
|
497
|
+
srcAsset: erc20Asset
|
|
498
|
+
});
|
|
499
|
+
var tokenSwapParamsSchema = zod.z.union([
|
|
500
|
+
flipToEthereumAsset,
|
|
501
|
+
usdcToEthereumAsset,
|
|
502
|
+
erc20ToDot,
|
|
503
|
+
erc20ToBtc
|
|
504
|
+
]);
|
|
505
|
+
var ccmMetadataSchema = zod.z.object({
|
|
506
|
+
message: zod.z.string(),
|
|
507
|
+
gasBudget: numericString
|
|
508
|
+
});
|
|
509
|
+
var ccmFlipToEthereumAssset = flipToEthereumAsset.extend({
|
|
510
|
+
ccmMetadata: ccmMetadataSchema
|
|
511
|
+
});
|
|
512
|
+
var ccmUsdcToEthereumAsset = usdcToEthereumAsset.extend({
|
|
513
|
+
ccmMetadata: ccmMetadataSchema
|
|
514
|
+
});
|
|
515
|
+
var tokenCallParamsSchema = zod.z.union([
|
|
516
|
+
ccmFlipToEthereumAssset,
|
|
517
|
+
ccmUsdcToEthereumAsset
|
|
518
|
+
]);
|
|
519
|
+
var nativeCallParamsSchema = ethToERC20.extend({
|
|
520
|
+
ccmMetadata: ccmMetadataSchema
|
|
521
|
+
});
|
|
522
|
+
var executeSwapParamsSchema = zod.z.union([
|
|
523
|
+
// call schemas needs to precede swap schemas
|
|
524
|
+
nativeCallParamsSchema,
|
|
525
|
+
tokenCallParamsSchema,
|
|
526
|
+
nativeSwapParamsSchema,
|
|
527
|
+
tokenSwapParamsSchema
|
|
528
|
+
]);
|
|
529
|
+
var stripOverrides = /* @__PURE__ */ __name((obj) => {
|
|
530
|
+
const { to, from, value, data, ...rest } = obj;
|
|
531
|
+
return rest;
|
|
532
|
+
}, "stripOverrides");
|
|
533
|
+
var executeOptionsSchema = zod.z.intersection(zod.z.object({
|
|
534
|
+
signer: zod.z.instanceof(ethers.Signer)
|
|
535
|
+
}).passthrough(), zod.z.union([
|
|
536
|
+
zod.z.object({
|
|
537
|
+
network: chainflipNetwork
|
|
538
|
+
}).passthrough(),
|
|
539
|
+
zod.z.object({
|
|
540
|
+
network: zod.z.literal("localnet"),
|
|
541
|
+
vaultContractAddress: zod.z.string(),
|
|
542
|
+
srcTokenContractAddress: zod.z.string().optional()
|
|
543
|
+
}).passthrough()
|
|
544
|
+
])).transform(stripOverrides);
|
|
545
|
+
var _abi = [
|
|
546
|
+
{
|
|
547
|
+
inputs: [
|
|
548
|
+
{
|
|
549
|
+
internalType: "address",
|
|
550
|
+
name: "owner",
|
|
551
|
+
type: "address"
|
|
552
|
+
},
|
|
553
|
+
{
|
|
554
|
+
internalType: "address",
|
|
555
|
+
name: "spender",
|
|
556
|
+
type: "address"
|
|
557
|
+
}
|
|
558
|
+
],
|
|
559
|
+
name: "allowance",
|
|
560
|
+
outputs: [
|
|
561
|
+
{
|
|
562
|
+
internalType: "uint256",
|
|
563
|
+
name: "",
|
|
564
|
+
type: "uint256"
|
|
565
|
+
}
|
|
566
|
+
],
|
|
567
|
+
stateMutability: "view",
|
|
568
|
+
type: "function"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
inputs: [
|
|
572
|
+
{
|
|
573
|
+
internalType: "address",
|
|
574
|
+
name: "spender",
|
|
575
|
+
type: "address"
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
internalType: "uint256",
|
|
579
|
+
name: "amount",
|
|
580
|
+
type: "uint256"
|
|
581
|
+
}
|
|
582
|
+
],
|
|
583
|
+
name: "approve",
|
|
584
|
+
outputs: [
|
|
585
|
+
{
|
|
586
|
+
internalType: "bool",
|
|
587
|
+
name: "",
|
|
588
|
+
type: "bool"
|
|
589
|
+
}
|
|
590
|
+
],
|
|
591
|
+
stateMutability: "nonpayable",
|
|
592
|
+
type: "function"
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
inputs: [
|
|
596
|
+
{
|
|
597
|
+
internalType: "address",
|
|
598
|
+
name: "account",
|
|
599
|
+
type: "address"
|
|
600
|
+
}
|
|
601
|
+
],
|
|
602
|
+
name: "balanceOf",
|
|
603
|
+
outputs: [
|
|
604
|
+
{
|
|
605
|
+
internalType: "uint256",
|
|
606
|
+
name: "",
|
|
607
|
+
type: "uint256"
|
|
608
|
+
}
|
|
609
|
+
],
|
|
610
|
+
stateMutability: "view",
|
|
611
|
+
type: "function"
|
|
612
|
+
}
|
|
613
|
+
];
|
|
614
|
+
var ERC20__factory = class {
|
|
615
|
+
static createInterface() {
|
|
616
|
+
return new ethers.utils.Interface(_abi);
|
|
617
|
+
}
|
|
618
|
+
static connect(address, signerOrProvider) {
|
|
619
|
+
return new ethers.Contract(address, _abi, signerOrProvider);
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
__name(ERC20__factory, "ERC20__factory");
|
|
623
|
+
__publicField(ERC20__factory, "abi", _abi);
|
|
624
|
+
var _abi2 = [
|
|
625
|
+
{
|
|
626
|
+
inputs: [
|
|
627
|
+
{
|
|
628
|
+
internalType: "contract IKeyManager",
|
|
629
|
+
name: "keyManager",
|
|
630
|
+
type: "address"
|
|
631
|
+
}
|
|
632
|
+
],
|
|
633
|
+
stateMutability: "nonpayable",
|
|
634
|
+
type: "constructor"
|
|
635
|
+
},
|
|
636
|
+
{
|
|
637
|
+
anonymous: false,
|
|
638
|
+
inputs: [
|
|
639
|
+
{
|
|
640
|
+
indexed: false,
|
|
641
|
+
internalType: "bytes32",
|
|
642
|
+
name: "swapID",
|
|
643
|
+
type: "bytes32"
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
indexed: false,
|
|
647
|
+
internalType: "uint256",
|
|
648
|
+
name: "amount",
|
|
649
|
+
type: "uint256"
|
|
650
|
+
}
|
|
651
|
+
],
|
|
652
|
+
name: "AddGasNative",
|
|
653
|
+
type: "event"
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
anonymous: false,
|
|
657
|
+
inputs: [
|
|
658
|
+
{
|
|
659
|
+
indexed: false,
|
|
660
|
+
internalType: "bytes32",
|
|
661
|
+
name: "swapID",
|
|
662
|
+
type: "bytes32"
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
indexed: false,
|
|
666
|
+
internalType: "uint256",
|
|
667
|
+
name: "amount",
|
|
668
|
+
type: "uint256"
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
indexed: false,
|
|
672
|
+
internalType: "address",
|
|
673
|
+
name: "token",
|
|
674
|
+
type: "address"
|
|
675
|
+
}
|
|
676
|
+
],
|
|
677
|
+
name: "AddGasToken",
|
|
678
|
+
type: "event"
|
|
254
679
|
},
|
|
255
680
|
{
|
|
256
681
|
anonymous: false,
|
|
@@ -1197,707 +1622,302 @@ var _abi2 = [
|
|
|
1197
1622
|
type: "address"
|
|
1198
1623
|
},
|
|
1199
1624
|
{
|
|
1200
|
-
internalType: "uint256",
|
|
1201
|
-
name: "amount",
|
|
1202
|
-
type: "uint256"
|
|
1203
|
-
}
|
|
1204
|
-
],
|
|
1205
|
-
internalType: "struct IShared.TransferParams[]",
|
|
1206
|
-
name: "transferParamsArray",
|
|
1207
|
-
type: "tuple[]"
|
|
1208
|
-
}
|
|
1209
|
-
],
|
|
1210
|
-
name: "transferBatch",
|
|
1211
|
-
outputs: [],
|
|
1212
|
-
stateMutability: "nonpayable",
|
|
1213
|
-
type: "function"
|
|
1214
|
-
},
|
|
1215
|
-
{
|
|
1216
|
-
inputs: [
|
|
1217
|
-
{
|
|
1218
|
-
components: [
|
|
1219
|
-
{
|
|
1220
|
-
internalType: "uint256",
|
|
1221
|
-
name: "sig",
|
|
1222
|
-
type: "uint256"
|
|
1223
|
-
},
|
|
1224
|
-
{
|
|
1225
|
-
internalType: "uint256",
|
|
1226
|
-
name: "nonce",
|
|
1227
|
-
type: "uint256"
|
|
1228
|
-
},
|
|
1229
|
-
{
|
|
1230
|
-
internalType: "address",
|
|
1231
|
-
name: "kTimesGAddress",
|
|
1232
|
-
type: "address"
|
|
1233
|
-
}
|
|
1234
|
-
],
|
|
1235
|
-
internalType: "struct IShared.SigData",
|
|
1236
|
-
name: "sigData",
|
|
1237
|
-
type: "tuple"
|
|
1238
|
-
},
|
|
1239
|
-
{
|
|
1240
|
-
internalType: "contract IKeyManager",
|
|
1241
|
-
name: "keyManager",
|
|
1242
|
-
type: "address"
|
|
1243
|
-
},
|
|
1244
|
-
{
|
|
1245
|
-
internalType: "bool",
|
|
1246
|
-
name: "omitChecks",
|
|
1247
|
-
type: "bool"
|
|
1248
|
-
}
|
|
1249
|
-
],
|
|
1250
|
-
name: "updateKeyManager",
|
|
1251
|
-
outputs: [],
|
|
1252
|
-
stateMutability: "nonpayable",
|
|
1253
|
-
type: "function"
|
|
1254
|
-
},
|
|
1255
|
-
{
|
|
1256
|
-
inputs: [
|
|
1257
|
-
{
|
|
1258
|
-
internalType: "uint32",
|
|
1259
|
-
name: "dstChain",
|
|
1260
|
-
type: "uint32"
|
|
1261
|
-
},
|
|
1262
|
-
{
|
|
1263
|
-
internalType: "bytes",
|
|
1264
|
-
name: "dstAddress",
|
|
1265
|
-
type: "bytes"
|
|
1266
|
-
},
|
|
1267
|
-
{
|
|
1268
|
-
internalType: "uint32",
|
|
1269
|
-
name: "dstToken",
|
|
1270
|
-
type: "uint32"
|
|
1271
|
-
},
|
|
1272
|
-
{
|
|
1273
|
-
internalType: "bytes",
|
|
1274
|
-
name: "message",
|
|
1275
|
-
type: "bytes"
|
|
1276
|
-
},
|
|
1277
|
-
{
|
|
1278
|
-
internalType: "uint256",
|
|
1279
|
-
name: "gasAmount",
|
|
1280
|
-
type: "uint256"
|
|
1281
|
-
},
|
|
1282
|
-
{
|
|
1283
|
-
internalType: "bytes",
|
|
1284
|
-
name: "cfParameters",
|
|
1285
|
-
type: "bytes"
|
|
1286
|
-
}
|
|
1287
|
-
],
|
|
1288
|
-
name: "xCallNative",
|
|
1289
|
-
outputs: [],
|
|
1290
|
-
stateMutability: "payable",
|
|
1291
|
-
type: "function"
|
|
1292
|
-
},
|
|
1293
|
-
{
|
|
1294
|
-
inputs: [
|
|
1295
|
-
{
|
|
1296
|
-
internalType: "uint32",
|
|
1297
|
-
name: "dstChain",
|
|
1298
|
-
type: "uint32"
|
|
1299
|
-
},
|
|
1300
|
-
{
|
|
1301
|
-
internalType: "bytes",
|
|
1302
|
-
name: "dstAddress",
|
|
1303
|
-
type: "bytes"
|
|
1304
|
-
},
|
|
1305
|
-
{
|
|
1306
|
-
internalType: "uint32",
|
|
1307
|
-
name: "dstToken",
|
|
1308
|
-
type: "uint32"
|
|
1309
|
-
},
|
|
1310
|
-
{
|
|
1311
|
-
internalType: "bytes",
|
|
1312
|
-
name: "message",
|
|
1313
|
-
type: "bytes"
|
|
1314
|
-
},
|
|
1315
|
-
{
|
|
1316
|
-
internalType: "uint256",
|
|
1317
|
-
name: "gasAmount",
|
|
1318
|
-
type: "uint256"
|
|
1319
|
-
},
|
|
1320
|
-
{
|
|
1321
|
-
internalType: "contract IERC20",
|
|
1322
|
-
name: "srcToken",
|
|
1323
|
-
type: "address"
|
|
1324
|
-
},
|
|
1325
|
-
{
|
|
1326
|
-
internalType: "uint256",
|
|
1327
|
-
name: "amount",
|
|
1328
|
-
type: "uint256"
|
|
1329
|
-
},
|
|
1330
|
-
{
|
|
1331
|
-
internalType: "bytes",
|
|
1332
|
-
name: "cfParameters",
|
|
1333
|
-
type: "bytes"
|
|
1334
|
-
}
|
|
1335
|
-
],
|
|
1336
|
-
name: "xCallToken",
|
|
1337
|
-
outputs: [],
|
|
1338
|
-
stateMutability: "nonpayable",
|
|
1339
|
-
type: "function"
|
|
1340
|
-
},
|
|
1341
|
-
{
|
|
1342
|
-
inputs: [
|
|
1343
|
-
{
|
|
1344
|
-
internalType: "uint32",
|
|
1345
|
-
name: "dstChain",
|
|
1346
|
-
type: "uint32"
|
|
1347
|
-
},
|
|
1348
|
-
{
|
|
1349
|
-
internalType: "bytes",
|
|
1350
|
-
name: "dstAddress",
|
|
1351
|
-
type: "bytes"
|
|
1352
|
-
},
|
|
1353
|
-
{
|
|
1354
|
-
internalType: "uint32",
|
|
1355
|
-
name: "dstToken",
|
|
1356
|
-
type: "uint32"
|
|
1357
|
-
},
|
|
1358
|
-
{
|
|
1359
|
-
internalType: "bytes",
|
|
1360
|
-
name: "cfParameters",
|
|
1361
|
-
type: "bytes"
|
|
1625
|
+
internalType: "uint256",
|
|
1626
|
+
name: "amount",
|
|
1627
|
+
type: "uint256"
|
|
1628
|
+
}
|
|
1629
|
+
],
|
|
1630
|
+
internalType: "struct IShared.TransferParams[]",
|
|
1631
|
+
name: "transferParamsArray",
|
|
1632
|
+
type: "tuple[]"
|
|
1362
1633
|
}
|
|
1363
1634
|
],
|
|
1364
|
-
name: "
|
|
1635
|
+
name: "transferBatch",
|
|
1365
1636
|
outputs: [],
|
|
1366
|
-
stateMutability: "
|
|
1637
|
+
stateMutability: "nonpayable",
|
|
1367
1638
|
type: "function"
|
|
1368
1639
|
},
|
|
1369
1640
|
{
|
|
1370
1641
|
inputs: [
|
|
1371
1642
|
{
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1643
|
+
components: [
|
|
1644
|
+
{
|
|
1645
|
+
internalType: "uint256",
|
|
1646
|
+
name: "sig",
|
|
1647
|
+
type: "uint256"
|
|
1648
|
+
},
|
|
1649
|
+
{
|
|
1650
|
+
internalType: "uint256",
|
|
1651
|
+
name: "nonce",
|
|
1652
|
+
type: "uint256"
|
|
1653
|
+
},
|
|
1654
|
+
{
|
|
1655
|
+
internalType: "address",
|
|
1656
|
+
name: "kTimesGAddress",
|
|
1657
|
+
type: "address"
|
|
1658
|
+
}
|
|
1659
|
+
],
|
|
1660
|
+
internalType: "struct IShared.SigData",
|
|
1661
|
+
name: "sigData",
|
|
1662
|
+
type: "tuple"
|
|
1385
1663
|
},
|
|
1386
1664
|
{
|
|
1387
|
-
internalType: "contract
|
|
1388
|
-
name: "
|
|
1665
|
+
internalType: "contract IKeyManager",
|
|
1666
|
+
name: "keyManager",
|
|
1389
1667
|
type: "address"
|
|
1390
1668
|
},
|
|
1391
1669
|
{
|
|
1392
|
-
internalType: "
|
|
1393
|
-
name: "
|
|
1394
|
-
type: "
|
|
1395
|
-
},
|
|
1396
|
-
{
|
|
1397
|
-
internalType: "bytes",
|
|
1398
|
-
name: "cfParameters",
|
|
1399
|
-
type: "bytes"
|
|
1670
|
+
internalType: "bool",
|
|
1671
|
+
name: "omitChecks",
|
|
1672
|
+
type: "bool"
|
|
1400
1673
|
}
|
|
1401
1674
|
],
|
|
1402
|
-
name: "
|
|
1675
|
+
name: "updateKeyManager",
|
|
1403
1676
|
outputs: [],
|
|
1404
1677
|
stateMutability: "nonpayable",
|
|
1405
1678
|
type: "function"
|
|
1406
|
-
},
|
|
1407
|
-
{
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0xC960C4eEe4ADf40d24374D85094f3219cf2DD8EB"
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
var GOERLI_USDC_CONTRACT_ADDRESS = "0x07865c6E87B9F70255377e024ace6630C1Eaa37F";
|
|
1442
|
-
|
|
1443
|
-
// ../shared/src/contracts.ts
|
|
1444
|
-
var getTokenContractAddress = /* @__PURE__ */ __name((asset, network) => {
|
|
1445
|
-
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
1446
|
-
if (asset === Assets.FLIP)
|
|
1447
|
-
return ADDRESSES[network].FLIP_CONTRACT_ADDRESS;
|
|
1448
|
-
assert(asset === Assets.USDC, "Only FLIP and USDC are supported for now");
|
|
1449
|
-
return GOERLI_USDC_CONTRACT_ADDRESS;
|
|
1450
|
-
}, "getTokenContractAddress");
|
|
1451
|
-
var checkAllowance = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20Address, signer) => {
|
|
1452
|
-
const erc20 = ERC20__factory.connect(erc20Address, signer);
|
|
1453
|
-
const signerAddress = await signer.getAddress();
|
|
1454
|
-
const allowance = await erc20.allowance(signerAddress, spenderAddress);
|
|
1455
|
-
return {
|
|
1456
|
-
allowance,
|
|
1457
|
-
isAllowable: allowance.gte(amount),
|
|
1458
|
-
erc20
|
|
1459
|
-
};
|
|
1460
|
-
}, "checkAllowance");
|
|
1461
|
-
var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance, nonce) => {
|
|
1462
|
-
const amountBigNumber = ethers.BigNumber.from(amount);
|
|
1463
|
-
const allowanceBigNumber = ethers.BigNumber.from(allowance);
|
|
1464
|
-
if (allowanceBigNumber.gte(amountBigNumber))
|
|
1465
|
-
return null;
|
|
1466
|
-
const requiredAmount = amountBigNumber.sub(allowanceBigNumber);
|
|
1467
|
-
const tx = await erc20.approve(spenderAddress, requiredAmount, {
|
|
1468
|
-
nonce
|
|
1469
|
-
});
|
|
1470
|
-
return tx.wait(1);
|
|
1471
|
-
}, "approve");
|
|
1472
|
-
var getVaultManagerContractAddress = /* @__PURE__ */ __name((network) => {
|
|
1473
|
-
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
1474
|
-
return ADDRESSES[network].VAULT_CONTRACT_ADDRESS;
|
|
1475
|
-
}, "getVaultManagerContractAddress");
|
|
1476
|
-
|
|
1477
|
-
// ../shared/src/validation/segwitAddr.ts
|
|
1478
|
-
var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
1479
|
-
var GENERATOR = [
|
|
1480
|
-
996825010,
|
|
1481
|
-
642813549,
|
|
1482
|
-
513874426,
|
|
1483
|
-
1027748829,
|
|
1484
|
-
705979059
|
|
1485
|
-
];
|
|
1486
|
-
var Encoding;
|
|
1487
|
-
(function(Encoding2) {
|
|
1488
|
-
Encoding2["Bech32"] = "bech32";
|
|
1489
|
-
Encoding2["Bech32m"] = "bech32m";
|
|
1490
|
-
})(Encoding || (Encoding = {}));
|
|
1491
|
-
var bech32 = {
|
|
1492
|
-
getEncodingConst(enc) {
|
|
1493
|
-
if (enc === Encoding.Bech32)
|
|
1494
|
-
return 1;
|
|
1495
|
-
if (enc === Encoding.Bech32m)
|
|
1496
|
-
return 734539939;
|
|
1497
|
-
return null;
|
|
1498
|
-
},
|
|
1499
|
-
polymod(values) {
|
|
1500
|
-
let chk = 1;
|
|
1501
|
-
for (let p = 0; p < values.length; p += 1) {
|
|
1502
|
-
const top = chk >> 25;
|
|
1503
|
-
chk = (chk & 33554431) << 5 ^ values[p];
|
|
1504
|
-
for (let i = 0; i < 5; i += 1) {
|
|
1505
|
-
if (top >> i & 1) {
|
|
1506
|
-
chk ^= GENERATOR[i];
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
return chk;
|
|
1511
|
-
},
|
|
1512
|
-
hrpExpand(hrp) {
|
|
1513
|
-
const ret = [];
|
|
1514
|
-
let p;
|
|
1515
|
-
for (p = 0; p < hrp.length; p += 1) {
|
|
1516
|
-
ret.push(hrp.charCodeAt(p) >> 5);
|
|
1517
|
-
}
|
|
1518
|
-
ret.push(0);
|
|
1519
|
-
for (p = 0; p < hrp.length; p += 1) {
|
|
1520
|
-
ret.push(hrp.charCodeAt(p) & 31);
|
|
1521
|
-
}
|
|
1522
|
-
return ret;
|
|
1523
|
-
},
|
|
1524
|
-
verifyChecksum(hrp, data, enc) {
|
|
1525
|
-
return this.polymod(this.hrpExpand(hrp).concat(data)) === this.getEncodingConst(enc);
|
|
1526
|
-
},
|
|
1527
|
-
createChecksum(hrp, data, enc) {
|
|
1528
|
-
const values = this.hrpExpand(hrp).concat(data).concat([
|
|
1529
|
-
0,
|
|
1530
|
-
0,
|
|
1531
|
-
0,
|
|
1532
|
-
0,
|
|
1533
|
-
0,
|
|
1534
|
-
0
|
|
1535
|
-
]);
|
|
1536
|
-
const mod = this.polymod(values) ^ this.getEncodingConst(enc);
|
|
1537
|
-
const ret = [];
|
|
1538
|
-
for (let p = 0; p < 6; p += 1) {
|
|
1539
|
-
ret.push(mod >> 5 * (5 - p) & 31);
|
|
1540
|
-
}
|
|
1541
|
-
return ret;
|
|
1542
|
-
},
|
|
1543
|
-
encode(hrp, data, enc) {
|
|
1544
|
-
const combined = data.concat(this.createChecksum(hrp, data, enc));
|
|
1545
|
-
let ret = `${hrp}1`;
|
|
1546
|
-
for (let p = 0; p < combined.length; p += 1) {
|
|
1547
|
-
ret += CHARSET.charAt(combined[p]);
|
|
1548
|
-
}
|
|
1549
|
-
return ret;
|
|
1550
|
-
},
|
|
1551
|
-
decode(bechString, enc) {
|
|
1552
|
-
let p;
|
|
1553
|
-
let hasLower = false;
|
|
1554
|
-
let hasUpper = false;
|
|
1555
|
-
for (p = 0; p < bechString.length; p += 1) {
|
|
1556
|
-
if (bechString.charCodeAt(p) < 33 || bechString.charCodeAt(p) > 126) {
|
|
1557
|
-
return null;
|
|
1558
|
-
}
|
|
1559
|
-
if (bechString.charCodeAt(p) >= 97 && bechString.charCodeAt(p) <= 122) {
|
|
1560
|
-
hasLower = true;
|
|
1561
|
-
}
|
|
1562
|
-
if (bechString.charCodeAt(p) >= 65 && bechString.charCodeAt(p) <= 90) {
|
|
1563
|
-
hasUpper = true;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
if (hasLower && hasUpper)
|
|
1567
|
-
return null;
|
|
1568
|
-
const lowercase = bechString.toLowerCase();
|
|
1569
|
-
const pos = lowercase.lastIndexOf("1");
|
|
1570
|
-
if (pos < 1 || pos + 7 > lowercase.length || lowercase.length > 90) {
|
|
1571
|
-
return null;
|
|
1572
|
-
}
|
|
1573
|
-
const hrp = lowercase.substring(0, pos);
|
|
1574
|
-
const data = [];
|
|
1575
|
-
for (p = pos + 1; p < lowercase.length; p += 1) {
|
|
1576
|
-
const d = CHARSET.indexOf(lowercase.charAt(p));
|
|
1577
|
-
if (d === -1)
|
|
1578
|
-
return null;
|
|
1579
|
-
data.push(d);
|
|
1580
|
-
}
|
|
1581
|
-
if (!this.verifyChecksum(hrp, data, enc)) {
|
|
1582
|
-
return null;
|
|
1583
|
-
}
|
|
1584
|
-
return {
|
|
1585
|
-
hrp,
|
|
1586
|
-
data: data.slice(0, data.length - 6)
|
|
1587
|
-
};
|
|
1588
|
-
}
|
|
1589
|
-
};
|
|
1590
|
-
var segwitAddress = {
|
|
1591
|
-
convertbits(data, frombits, tobits, pad) {
|
|
1592
|
-
let acc = 0;
|
|
1593
|
-
let bits = 0;
|
|
1594
|
-
const ret = [];
|
|
1595
|
-
const maxv = (1 << tobits) - 1;
|
|
1596
|
-
for (let p = 0; p < data.length; p += 1) {
|
|
1597
|
-
const value = data[p];
|
|
1598
|
-
if (value < 0 || value >> frombits !== 0) {
|
|
1599
|
-
return null;
|
|
1679
|
+
},
|
|
1680
|
+
{
|
|
1681
|
+
inputs: [
|
|
1682
|
+
{
|
|
1683
|
+
internalType: "uint32",
|
|
1684
|
+
name: "dstChain",
|
|
1685
|
+
type: "uint32"
|
|
1686
|
+
},
|
|
1687
|
+
{
|
|
1688
|
+
internalType: "bytes",
|
|
1689
|
+
name: "dstAddress",
|
|
1690
|
+
type: "bytes"
|
|
1691
|
+
},
|
|
1692
|
+
{
|
|
1693
|
+
internalType: "uint32",
|
|
1694
|
+
name: "dstToken",
|
|
1695
|
+
type: "uint32"
|
|
1696
|
+
},
|
|
1697
|
+
{
|
|
1698
|
+
internalType: "bytes",
|
|
1699
|
+
name: "message",
|
|
1700
|
+
type: "bytes"
|
|
1701
|
+
},
|
|
1702
|
+
{
|
|
1703
|
+
internalType: "uint256",
|
|
1704
|
+
name: "gasAmount",
|
|
1705
|
+
type: "uint256"
|
|
1706
|
+
},
|
|
1707
|
+
{
|
|
1708
|
+
internalType: "bytes",
|
|
1709
|
+
name: "cfParameters",
|
|
1710
|
+
type: "bytes"
|
|
1600
1711
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1712
|
+
],
|
|
1713
|
+
name: "xCallNative",
|
|
1714
|
+
outputs: [],
|
|
1715
|
+
stateMutability: "payable",
|
|
1716
|
+
type: "function"
|
|
1717
|
+
},
|
|
1718
|
+
{
|
|
1719
|
+
inputs: [
|
|
1720
|
+
{
|
|
1721
|
+
internalType: "uint32",
|
|
1722
|
+
name: "dstChain",
|
|
1723
|
+
type: "uint32"
|
|
1724
|
+
},
|
|
1725
|
+
{
|
|
1726
|
+
internalType: "bytes",
|
|
1727
|
+
name: "dstAddress",
|
|
1728
|
+
type: "bytes"
|
|
1729
|
+
},
|
|
1730
|
+
{
|
|
1731
|
+
internalType: "uint32",
|
|
1732
|
+
name: "dstToken",
|
|
1733
|
+
type: "uint32"
|
|
1734
|
+
},
|
|
1735
|
+
{
|
|
1736
|
+
internalType: "bytes",
|
|
1737
|
+
name: "message",
|
|
1738
|
+
type: "bytes"
|
|
1739
|
+
},
|
|
1740
|
+
{
|
|
1741
|
+
internalType: "uint256",
|
|
1742
|
+
name: "gasAmount",
|
|
1743
|
+
type: "uint256"
|
|
1744
|
+
},
|
|
1745
|
+
{
|
|
1746
|
+
internalType: "contract IERC20",
|
|
1747
|
+
name: "srcToken",
|
|
1748
|
+
type: "address"
|
|
1749
|
+
},
|
|
1750
|
+
{
|
|
1751
|
+
internalType: "uint256",
|
|
1752
|
+
name: "amount",
|
|
1753
|
+
type: "uint256"
|
|
1754
|
+
},
|
|
1755
|
+
{
|
|
1756
|
+
internalType: "bytes",
|
|
1757
|
+
name: "cfParameters",
|
|
1758
|
+
type: "bytes"
|
|
1606
1759
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1760
|
+
],
|
|
1761
|
+
name: "xCallToken",
|
|
1762
|
+
outputs: [],
|
|
1763
|
+
stateMutability: "nonpayable",
|
|
1764
|
+
type: "function"
|
|
1765
|
+
},
|
|
1766
|
+
{
|
|
1767
|
+
inputs: [
|
|
1768
|
+
{
|
|
1769
|
+
internalType: "uint32",
|
|
1770
|
+
name: "dstChain",
|
|
1771
|
+
type: "uint32"
|
|
1772
|
+
},
|
|
1773
|
+
{
|
|
1774
|
+
internalType: "bytes",
|
|
1775
|
+
name: "dstAddress",
|
|
1776
|
+
type: "bytes"
|
|
1777
|
+
},
|
|
1778
|
+
{
|
|
1779
|
+
internalType: "uint32",
|
|
1780
|
+
name: "dstToken",
|
|
1781
|
+
type: "uint32"
|
|
1782
|
+
},
|
|
1783
|
+
{
|
|
1784
|
+
internalType: "bytes",
|
|
1785
|
+
name: "cfParameters",
|
|
1786
|
+
type: "bytes"
|
|
1611
1787
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1788
|
+
],
|
|
1789
|
+
name: "xSwapNative",
|
|
1790
|
+
outputs: [],
|
|
1791
|
+
stateMutability: "payable",
|
|
1792
|
+
type: "function"
|
|
1616
1793
|
},
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1794
|
+
{
|
|
1795
|
+
inputs: [
|
|
1796
|
+
{
|
|
1797
|
+
internalType: "uint32",
|
|
1798
|
+
name: "dstChain",
|
|
1799
|
+
type: "uint32"
|
|
1800
|
+
},
|
|
1801
|
+
{
|
|
1802
|
+
internalType: "bytes",
|
|
1803
|
+
name: "dstAddress",
|
|
1804
|
+
type: "bytes"
|
|
1805
|
+
},
|
|
1806
|
+
{
|
|
1807
|
+
internalType: "uint32",
|
|
1808
|
+
name: "dstToken",
|
|
1809
|
+
type: "uint32"
|
|
1810
|
+
},
|
|
1811
|
+
{
|
|
1812
|
+
internalType: "contract IERC20",
|
|
1813
|
+
name: "srcToken",
|
|
1814
|
+
type: "address"
|
|
1815
|
+
},
|
|
1816
|
+
{
|
|
1817
|
+
internalType: "uint256",
|
|
1818
|
+
name: "amount",
|
|
1819
|
+
type: "uint256"
|
|
1820
|
+
},
|
|
1821
|
+
{
|
|
1822
|
+
internalType: "bytes",
|
|
1823
|
+
name: "cfParameters",
|
|
1824
|
+
type: "bytes"
|
|
1825
|
+
}
|
|
1826
|
+
],
|
|
1827
|
+
name: "xSwapToken",
|
|
1828
|
+
outputs: [],
|
|
1829
|
+
stateMutability: "nonpayable",
|
|
1830
|
+
type: "function"
|
|
1644
1831
|
},
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
enc = Encoding.Bech32m;
|
|
1649
|
-
}
|
|
1650
|
-
const ret = bech32.encode(
|
|
1651
|
-
hrp,
|
|
1652
|
-
// @ts-expect-error can be null
|
|
1653
|
-
[
|
|
1654
|
-
version
|
|
1655
|
-
].concat(this.convertbits(program, 8, 5, true)),
|
|
1656
|
-
enc
|
|
1657
|
-
);
|
|
1658
|
-
if (this.decode(hrp, ret) === null) {
|
|
1659
|
-
return null;
|
|
1660
|
-
}
|
|
1661
|
-
return ret;
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
var isValidSegwitAddress = /* @__PURE__ */ __name((address) => {
|
|
1665
|
-
const hrp = /^(bc|tb|bcrt)1/.exec(address)?.[1];
|
|
1666
|
-
if (!hrp)
|
|
1667
|
-
return false;
|
|
1668
|
-
return segwitAddress.decode(hrp, address) !== null;
|
|
1669
|
-
}, "isValidSegwitAddress");
|
|
1670
|
-
|
|
1671
|
-
// ../shared/src/validation/addressValidation.ts
|
|
1672
|
-
var assertArraylikeEqual = /* @__PURE__ */ __name((a, b) => {
|
|
1673
|
-
assert(a.length === b.length, "arraylike lengths must be equal");
|
|
1674
|
-
for (let i = 0; i < a.length; i += 1) {
|
|
1675
|
-
assert(a[i] === b[i], "arraylike elements must be equal");
|
|
1832
|
+
{
|
|
1833
|
+
stateMutability: "payable",
|
|
1834
|
+
type: "receive"
|
|
1676
1835
|
}
|
|
1677
|
-
|
|
1678
|
-
var
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
assert(decoded.length === 25, "decoded address must be 25 bytes long");
|
|
1682
|
-
if (network === "mainnet") {
|
|
1683
|
-
assert(decoded[0] === 0 || decoded[0] === 5, "decoded address must start with 0x00 or 0x05");
|
|
1684
|
-
} else {
|
|
1685
|
-
assert(decoded[0] === 111 || decoded[0] === 196, "decoded address must start with 0x6f or 0xc4");
|
|
1686
|
-
}
|
|
1687
|
-
const checksum = decoded.slice(-4);
|
|
1688
|
-
const doubleHash = ethers__namespace.utils.arrayify(ethers__namespace.utils.sha256(ethers__namespace.utils.sha256(decoded.slice(0, 21))));
|
|
1689
|
-
assertArraylikeEqual(checksum, doubleHash.slice(0, 4));
|
|
1690
|
-
return true;
|
|
1691
|
-
} catch (error) {
|
|
1692
|
-
return false;
|
|
1836
|
+
];
|
|
1837
|
+
var Vault__factory = class {
|
|
1838
|
+
static createInterface() {
|
|
1839
|
+
return new ethers.utils.Interface(_abi2);
|
|
1693
1840
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
try {
|
|
1697
|
-
assert(
|
|
1698
|
-
// On mainnet, the address must start with "bc1"
|
|
1699
|
-
network === "mainnet" && address.startsWith("bc1") || // on testnet it must start with "tb1"
|
|
1700
|
-
network === "testnet" && address.startsWith("tb1") || // on regtest it must start with "bcrt1"
|
|
1701
|
-
network === "regtest" && address.startsWith("bcrt1"),
|
|
1702
|
-
"address must start with bc1, tb1 or bcrt1"
|
|
1703
|
-
);
|
|
1704
|
-
return isValidSegwitAddress(address);
|
|
1705
|
-
} catch {
|
|
1706
|
-
return false;
|
|
1841
|
+
static connect(address, signerOrProvider) {
|
|
1842
|
+
return new ethers.Contract(address, _abi2, signerOrProvider);
|
|
1707
1843
|
}
|
|
1708
|
-
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
var validateBitcoinTestnetAddress = /* @__PURE__ */ __name((address) => validateBitcoinAddress(address, "testnet"), "validateBitcoinTestnetAddress");
|
|
1712
|
-
var validateBitcoinRegtestAddress = /* @__PURE__ */ __name((address) => validateBitcoinAddress(address, "regtest"), "validateBitcoinRegtestAddress");
|
|
1844
|
+
};
|
|
1845
|
+
__name(Vault__factory, "Vault__factory");
|
|
1846
|
+
__publicField(Vault__factory, "abi", _abi2);
|
|
1713
1847
|
|
|
1714
|
-
// ../shared/src/
|
|
1715
|
-
var
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
errorMap
|
|
1723
|
-
});
|
|
1724
|
-
var numericString = string.regex(/^[0-9]+$/);
|
|
1725
|
-
var hexString = zod.z.custom((val) => typeof val === "string" && /^0x[0-9a-f]+$/i.test(val));
|
|
1726
|
-
numericString.transform((arg) => ethers__namespace.BigNumber.from(arg).toHexString()).refine((arg) => arg.startsWith("0x"));
|
|
1727
|
-
string.regex(/^[0-9a-f]+$/);
|
|
1728
|
-
var btcAddress = /* @__PURE__ */ __name((env) => {
|
|
1729
|
-
const network = env ?? process.env.CHAINFLIP_NETWORK;
|
|
1730
|
-
if (network === "mainnet")
|
|
1731
|
-
return string.regex(/^(1|3|bc1)/).refine(validateBitcoinMainnetAddress);
|
|
1732
|
-
return zod.z.union([
|
|
1733
|
-
string.regex(/^(m|n|2|tb1)/).refine(validateBitcoinTestnetAddress),
|
|
1734
|
-
string.regex(/^bcrt1/).refine(validateBitcoinRegtestAddress)
|
|
1735
|
-
]);
|
|
1736
|
-
}, "btcAddress");
|
|
1737
|
-
var dotAddress = zod.z.union([
|
|
1738
|
-
string,
|
|
1739
|
-
hexString
|
|
1740
|
-
]).transform((arg) => {
|
|
1741
|
-
try {
|
|
1742
|
-
if (arg.startsWith("0x")) {
|
|
1743
|
-
return utilCrypto.encodeAddress(util.hexToU8a(arg));
|
|
1744
|
-
}
|
|
1745
|
-
utilCrypto.decodeAddress(arg);
|
|
1746
|
-
return arg;
|
|
1747
|
-
} catch {
|
|
1748
|
-
return null;
|
|
1848
|
+
// ../shared/src/consts.ts
|
|
1849
|
+
var MINIMUM_DEPOSIT_AMOUNTS = {
|
|
1850
|
+
[ChainflipNetworks.partnernet]: {
|
|
1851
|
+
[Assets.ETH]: "0",
|
|
1852
|
+
[Assets.FLIP]: "0",
|
|
1853
|
+
[Assets.USDC]: "0",
|
|
1854
|
+
[Assets.BTC]: "0",
|
|
1855
|
+
[Assets.DOT]: "10000000000"
|
|
1749
1856
|
}
|
|
1750
|
-
}
|
|
1751
|
-
var
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
]
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
"
|
|
1765
|
-
"
|
|
1766
|
-
"
|
|
1767
|
-
|
|
1768
|
-
]
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
})),
|
|
1781
|
-
zod.z.object({
|
|
1782
|
-
__kind: zod.z.literal("CcmGas"),
|
|
1783
|
-
value: unsignedInteger
|
|
1784
|
-
}).transform(({ value: ccmId }) => ({
|
|
1785
|
-
type: "GAS",
|
|
1786
|
-
ccmId
|
|
1787
|
-
})),
|
|
1788
|
-
zod.z.object({
|
|
1789
|
-
__kind: zod.z.literal("Swap")
|
|
1790
|
-
}).transform(() => ({
|
|
1791
|
-
type: "SWAP"
|
|
1792
|
-
}))
|
|
1793
|
-
]);
|
|
1857
|
+
};
|
|
1858
|
+
var getMinimumDepositAmount = /* @__PURE__ */ __name((network, asset) => MINIMUM_DEPOSIT_AMOUNTS[network]?.[asset] ?? "0", "getMinimumDepositAmount");
|
|
1859
|
+
var MINIMUM_SWAP_AMOUNTS = {
|
|
1860
|
+
[ChainflipNetworks.partnernet]: {
|
|
1861
|
+
[Assets.ETH]: "580000000000000",
|
|
1862
|
+
[Assets.FLIP]: "1000000000000000000",
|
|
1863
|
+
[Assets.USDC]: "1000000",
|
|
1864
|
+
[Assets.BTC]: "390000",
|
|
1865
|
+
[Assets.DOT]: "2000000000"
|
|
1866
|
+
}
|
|
1867
|
+
};
|
|
1868
|
+
var getMinimumSwapAmount = /* @__PURE__ */ __name((network, asset) => MINIMUM_SWAP_AMOUNTS[network]?.[asset] ?? "0", "getMinimumSwapAmount");
|
|
1869
|
+
var ADDRESSES = {
|
|
1870
|
+
[ChainflipNetworks.sisyphos]: {
|
|
1871
|
+
FLIP_CONTRACT_ADDRESS: "0x2FD78122663A07672e9ac63486573A99EB00125d",
|
|
1872
|
+
VAULT_CONTRACT_ADDRESS: "0xd498606dcb9F440CD9F06B397C40fd3327FC2550",
|
|
1873
|
+
STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0xCCF267Bc5B709F1A1738122f3b76Cd01F0d9f947"
|
|
1874
|
+
},
|
|
1875
|
+
[ChainflipNetworks.partnernet]: {
|
|
1876
|
+
FLIP_CONTRACT_ADDRESS: "0x1Ea4F05a319A8f779F05E153974605756bB13D4F",
|
|
1877
|
+
VAULT_CONTRACT_ADDRESS: "0xAfD0C34E6d25F707d931F8b7EE9cf0Ff52160A46",
|
|
1878
|
+
STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0x07B3Bef16c640B072085BF83C24b6C43000aE056"
|
|
1879
|
+
},
|
|
1880
|
+
[ChainflipNetworks.perseverance]: {
|
|
1881
|
+
FLIP_CONTRACT_ADDRESS: "0x1194C91d47Fc1b65bE18db38380B5344682b67db",
|
|
1882
|
+
VAULT_CONTRACT_ADDRESS: "0xF1B061aCCDAa4B7c029128b49aBc047F89D5CB8d",
|
|
1883
|
+
STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0xC960C4eEe4ADf40d24374D85094f3219cf2DD8EB"
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
var GOERLI_USDC_CONTRACT_ADDRESS = "0x07865c6E87B9F70255377e024ace6630C1Eaa37F";
|
|
1794
1887
|
|
|
1795
|
-
// ../shared/src/
|
|
1796
|
-
var
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
});
|
|
1813
|
-
var
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
]
|
|
1827
|
-
|
|
1828
|
-
destAsset: erc20Asset
|
|
1829
|
-
});
|
|
1830
|
-
var nativeSwapParamsSchema = zod.z.union([
|
|
1831
|
-
ethToERC20,
|
|
1832
|
-
ethToDot,
|
|
1833
|
-
ethToBtc
|
|
1834
|
-
]);
|
|
1835
|
-
var flipToEthereumAsset = ethToEthereum.extend({
|
|
1836
|
-
srcAsset: zod.z.literal(Assets.FLIP),
|
|
1837
|
-
destAsset: zod.z.union([
|
|
1838
|
-
zod.z.literal(Assets.USDC),
|
|
1839
|
-
zod.z.literal(Assets.ETH)
|
|
1840
|
-
])
|
|
1841
|
-
});
|
|
1842
|
-
var usdcToEthereumAsset = ethToEthereum.extend({
|
|
1843
|
-
srcAsset: zod.z.literal(Assets.USDC),
|
|
1844
|
-
destAsset: zod.z.union([
|
|
1845
|
-
zod.z.literal(Assets.FLIP),
|
|
1846
|
-
zod.z.literal(Assets.ETH)
|
|
1847
|
-
])
|
|
1848
|
-
});
|
|
1849
|
-
var erc20ToDot = ethToDot.extend({
|
|
1850
|
-
srcAsset: erc20Asset
|
|
1851
|
-
});
|
|
1852
|
-
var erc20ToBtc = ethToBtc.extend({
|
|
1853
|
-
srcAsset: erc20Asset
|
|
1854
|
-
});
|
|
1855
|
-
var tokenSwapParamsSchema = zod.z.union([
|
|
1856
|
-
flipToEthereumAsset,
|
|
1857
|
-
usdcToEthereumAsset,
|
|
1858
|
-
erc20ToDot,
|
|
1859
|
-
erc20ToBtc
|
|
1860
|
-
]);
|
|
1861
|
-
var ccmMetadataSchema = zod.z.object({
|
|
1862
|
-
message: zod.z.string(),
|
|
1863
|
-
gasBudget: numericString
|
|
1864
|
-
});
|
|
1865
|
-
var ccmFlipToEthereumAssset = flipToEthereumAsset.extend({
|
|
1866
|
-
ccmMetadata: ccmMetadataSchema
|
|
1867
|
-
});
|
|
1868
|
-
var ccmUsdcToEthereumAsset = usdcToEthereumAsset.extend({
|
|
1869
|
-
ccmMetadata: ccmMetadataSchema
|
|
1870
|
-
});
|
|
1871
|
-
var tokenCallParamsSchema = zod.z.union([
|
|
1872
|
-
ccmFlipToEthereumAssset,
|
|
1873
|
-
ccmUsdcToEthereumAsset
|
|
1874
|
-
]);
|
|
1875
|
-
var nativeCallParamsSchema = ethToERC20.extend({
|
|
1876
|
-
ccmMetadata: ccmMetadataSchema
|
|
1877
|
-
});
|
|
1878
|
-
var executeSwapParamsSchema = zod.z.union([
|
|
1879
|
-
// call schemas needs to precede swap schemas
|
|
1880
|
-
nativeCallParamsSchema,
|
|
1881
|
-
tokenCallParamsSchema,
|
|
1882
|
-
nativeSwapParamsSchema,
|
|
1883
|
-
tokenSwapParamsSchema
|
|
1884
|
-
]);
|
|
1885
|
-
var stripOverrides = /* @__PURE__ */ __name((obj) => {
|
|
1886
|
-
const { to, from, value, data, ...rest } = obj;
|
|
1887
|
-
return rest;
|
|
1888
|
-
}, "stripOverrides");
|
|
1889
|
-
var executeOptionsSchema = zod.z.intersection(zod.z.object({
|
|
1890
|
-
signer: zod.z.instanceof(ethers.Signer)
|
|
1891
|
-
}).passthrough(), zod.z.union([
|
|
1892
|
-
zod.z.object({
|
|
1893
|
-
network: chainflipNetwork
|
|
1894
|
-
}).passthrough(),
|
|
1895
|
-
zod.z.object({
|
|
1896
|
-
network: zod.z.literal("localnet"),
|
|
1897
|
-
vaultContractAddress: zod.z.string(),
|
|
1898
|
-
srcTokenContractAddress: zod.z.string().optional()
|
|
1899
|
-
}).passthrough()
|
|
1900
|
-
])).transform(stripOverrides);
|
|
1888
|
+
// ../shared/src/contracts.ts
|
|
1889
|
+
var getTokenContractAddress = /* @__PURE__ */ __name((asset, network) => {
|
|
1890
|
+
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
1891
|
+
if (asset === Assets.FLIP)
|
|
1892
|
+
return ADDRESSES[network].FLIP_CONTRACT_ADDRESS;
|
|
1893
|
+
assert(asset === Assets.USDC, "Only FLIP and USDC are supported for now");
|
|
1894
|
+
return GOERLI_USDC_CONTRACT_ADDRESS;
|
|
1895
|
+
}, "getTokenContractAddress");
|
|
1896
|
+
var checkAllowance = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20Address, signer) => {
|
|
1897
|
+
const erc20 = ERC20__factory.connect(erc20Address, signer);
|
|
1898
|
+
const signerAddress = await signer.getAddress();
|
|
1899
|
+
const allowance = await erc20.allowance(signerAddress, spenderAddress);
|
|
1900
|
+
return {
|
|
1901
|
+
allowance,
|
|
1902
|
+
isAllowable: allowance.gte(amount),
|
|
1903
|
+
erc20
|
|
1904
|
+
};
|
|
1905
|
+
}, "checkAllowance");
|
|
1906
|
+
var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance, nonce) => {
|
|
1907
|
+
const amountBigNumber = ethers.BigNumber.from(amount);
|
|
1908
|
+
const allowanceBigNumber = ethers.BigNumber.from(allowance);
|
|
1909
|
+
if (allowanceBigNumber.gte(amountBigNumber))
|
|
1910
|
+
return null;
|
|
1911
|
+
const requiredAmount = amountBigNumber.sub(allowanceBigNumber);
|
|
1912
|
+
const tx = await erc20.approve(spenderAddress, requiredAmount, {
|
|
1913
|
+
nonce
|
|
1914
|
+
});
|
|
1915
|
+
return tx.wait(1);
|
|
1916
|
+
}, "approve");
|
|
1917
|
+
var getVaultManagerContractAddress = /* @__PURE__ */ __name((network) => {
|
|
1918
|
+
assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
|
|
1919
|
+
return ADDRESSES[network].VAULT_CONTRACT_ADDRESS;
|
|
1920
|
+
}, "getVaultManagerContractAddress");
|
|
1901
1921
|
|
|
1902
1922
|
// ../shared/src/vault/executeSwap.ts
|
|
1903
1923
|
var swapNative = /* @__PURE__ */ __name(async ({ destChain, destAsset, destAddress, amount }, { network, vaultContractAddress: address, signer, ...opts }) => {
|
|
@@ -1978,7 +1998,9 @@ var eth$ = /* @__PURE__ */ __name((network) => ({
|
|
|
1978
1998
|
decimals: assetDecimals[Assets.ETH],
|
|
1979
1999
|
name: "Ether",
|
|
1980
2000
|
symbol: "ETH",
|
|
1981
|
-
isMainnet: !isTestnet(network)
|
|
2001
|
+
isMainnet: !isTestnet(network),
|
|
2002
|
+
minimumDepositAmount: getMinimumDepositAmount(network, Assets.ETH),
|
|
2003
|
+
minimumSwapAmount: getMinimumSwapAmount(network, Assets.ETH)
|
|
1982
2004
|
}), "eth$");
|
|
1983
2005
|
var usdc$ = /* @__PURE__ */ __name((network) => ({
|
|
1984
2006
|
id: Assets.USDC,
|
|
@@ -1987,7 +2009,9 @@ var usdc$ = /* @__PURE__ */ __name((network) => ({
|
|
|
1987
2009
|
decimals: assetDecimals[Assets.USDC],
|
|
1988
2010
|
name: "USDC",
|
|
1989
2011
|
symbol: "USDC",
|
|
1990
|
-
isMainnet: !isTestnet(network)
|
|
2012
|
+
isMainnet: !isTestnet(network),
|
|
2013
|
+
minimumDepositAmount: getMinimumDepositAmount(network, Assets.USDC),
|
|
2014
|
+
minimumSwapAmount: getMinimumSwapAmount(network, Assets.USDC)
|
|
1991
2015
|
}), "usdc$");
|
|
1992
2016
|
var flip$ = /* @__PURE__ */ __name((network) => ({
|
|
1993
2017
|
id: Assets.FLIP,
|
|
@@ -1996,7 +2020,9 @@ var flip$ = /* @__PURE__ */ __name((network) => ({
|
|
|
1996
2020
|
decimals: assetDecimals[Assets.FLIP],
|
|
1997
2021
|
name: "FLIP",
|
|
1998
2022
|
symbol: "FLIP",
|
|
1999
|
-
isMainnet: !isTestnet(network)
|
|
2023
|
+
isMainnet: !isTestnet(network),
|
|
2024
|
+
minimumDepositAmount: getMinimumDepositAmount(network, Assets.FLIP),
|
|
2025
|
+
minimumSwapAmount: getMinimumSwapAmount(network, Assets.FLIP)
|
|
2000
2026
|
}), "flip$");
|
|
2001
2027
|
var dot$ = /* @__PURE__ */ __name((network) => ({
|
|
2002
2028
|
id: Assets.DOT,
|
|
@@ -2005,7 +2031,9 @@ var dot$ = /* @__PURE__ */ __name((network) => ({
|
|
|
2005
2031
|
decimals: assetDecimals[Assets.DOT],
|
|
2006
2032
|
name: "Polkadot",
|
|
2007
2033
|
symbol: "DOT",
|
|
2008
|
-
isMainnet: !isTestnet(network)
|
|
2034
|
+
isMainnet: !isTestnet(network),
|
|
2035
|
+
minimumDepositAmount: getMinimumDepositAmount(network, Assets.DOT),
|
|
2036
|
+
minimumSwapAmount: getMinimumSwapAmount(network, Assets.DOT)
|
|
2009
2037
|
}), "dot$");
|
|
2010
2038
|
var btc$ = /* @__PURE__ */ __name((network) => ({
|
|
2011
2039
|
id: Assets.BTC,
|
|
@@ -2014,7 +2042,9 @@ var btc$ = /* @__PURE__ */ __name((network) => ({
|
|
|
2014
2042
|
decimals: assetDecimals[Assets.BTC],
|
|
2015
2043
|
name: "Bitcoin",
|
|
2016
2044
|
symbol: "BTC",
|
|
2017
|
-
isMainnet: !isTestnet(network)
|
|
2045
|
+
isMainnet: !isTestnet(network),
|
|
2046
|
+
minimumDepositAmount: getMinimumDepositAmount(network, Assets.BTC),
|
|
2047
|
+
minimumSwapAmount: getMinimumSwapAmount(network, Assets.BTC)
|
|
2018
2048
|
}), "btc$");
|
|
2019
2049
|
|
|
2020
2050
|
// src/swap/chains.ts
|