@chainflip/sdk 0.1.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.
@@ -0,0 +1,998 @@
1
+ 'use strict';
2
+
3
+ var ethers = require('ethers');
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __publicField = (obj, key, value) => {
9
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
+ return value;
11
+ };
12
+ var _abi = [
13
+ {
14
+ inputs: [
15
+ {
16
+ internalType: "address",
17
+ name: "owner",
18
+ type: "address"
19
+ },
20
+ {
21
+ internalType: "address",
22
+ name: "spender",
23
+ type: "address"
24
+ }
25
+ ],
26
+ name: "allowance",
27
+ outputs: [
28
+ {
29
+ internalType: "uint256",
30
+ name: "",
31
+ type: "uint256"
32
+ }
33
+ ],
34
+ stateMutability: "view",
35
+ type: "function"
36
+ },
37
+ {
38
+ inputs: [
39
+ {
40
+ internalType: "address",
41
+ name: "spender",
42
+ type: "address"
43
+ },
44
+ {
45
+ internalType: "uint256",
46
+ name: "amount",
47
+ type: "uint256"
48
+ }
49
+ ],
50
+ name: "approve",
51
+ outputs: [
52
+ {
53
+ internalType: "bool",
54
+ name: "",
55
+ type: "bool"
56
+ }
57
+ ],
58
+ stateMutability: "nonpayable",
59
+ type: "function"
60
+ },
61
+ {
62
+ inputs: [
63
+ {
64
+ internalType: "address",
65
+ name: "account",
66
+ type: "address"
67
+ }
68
+ ],
69
+ name: "balanceOf",
70
+ outputs: [
71
+ {
72
+ internalType: "uint256",
73
+ name: "",
74
+ type: "uint256"
75
+ }
76
+ ],
77
+ stateMutability: "view",
78
+ type: "function"
79
+ }
80
+ ];
81
+ var ERC20__factory = class {
82
+ static createInterface() {
83
+ return new ethers.utils.Interface(_abi);
84
+ }
85
+ static connect(address, signerOrProvider) {
86
+ return new ethers.Contract(address, _abi, signerOrProvider);
87
+ }
88
+ };
89
+ __name(ERC20__factory, "ERC20__factory");
90
+ __publicField(ERC20__factory, "abi", _abi);
91
+ var _abi2 = [
92
+ {
93
+ inputs: [
94
+ {
95
+ internalType: "contract IKeyManager",
96
+ name: "keyManager",
97
+ type: "address"
98
+ },
99
+ {
100
+ internalType: "uint256",
101
+ name: "minFunding",
102
+ type: "uint256"
103
+ }
104
+ ],
105
+ stateMutability: "nonpayable",
106
+ type: "constructor"
107
+ },
108
+ {
109
+ anonymous: false,
110
+ inputs: [
111
+ {
112
+ indexed: false,
113
+ internalType: "bool",
114
+ name: "communityGuardDisabled",
115
+ type: "bool"
116
+ }
117
+ ],
118
+ name: "CommunityGuardDisabled",
119
+ type: "event"
120
+ },
121
+ {
122
+ anonymous: false,
123
+ inputs: [
124
+ {
125
+ indexed: false,
126
+ internalType: "address",
127
+ name: "flip",
128
+ type: "address"
129
+ }
130
+ ],
131
+ name: "FLIPSet",
132
+ type: "event"
133
+ },
134
+ {
135
+ anonymous: false,
136
+ inputs: [
137
+ {
138
+ indexed: false,
139
+ internalType: "uint256",
140
+ name: "oldSupply",
141
+ type: "uint256"
142
+ },
143
+ {
144
+ indexed: false,
145
+ internalType: "uint256",
146
+ name: "newSupply",
147
+ type: "uint256"
148
+ },
149
+ {
150
+ indexed: false,
151
+ internalType: "uint256",
152
+ name: "stateChainBlockNumber",
153
+ type: "uint256"
154
+ }
155
+ ],
156
+ name: "FlipSupplyUpdated",
157
+ type: "event"
158
+ },
159
+ {
160
+ anonymous: false,
161
+ inputs: [
162
+ {
163
+ indexed: true,
164
+ internalType: "bytes32",
165
+ name: "nodeID",
166
+ type: "bytes32"
167
+ },
168
+ {
169
+ indexed: false,
170
+ internalType: "uint256",
171
+ name: "amount",
172
+ type: "uint256"
173
+ },
174
+ {
175
+ indexed: false,
176
+ internalType: "address",
177
+ name: "funder",
178
+ type: "address"
179
+ }
180
+ ],
181
+ name: "Funded",
182
+ type: "event"
183
+ },
184
+ {
185
+ anonymous: false,
186
+ inputs: [
187
+ {
188
+ indexed: false,
189
+ internalType: "address",
190
+ name: "to",
191
+ type: "address"
192
+ },
193
+ {
194
+ indexed: false,
195
+ internalType: "uint256",
196
+ name: "amount",
197
+ type: "uint256"
198
+ }
199
+ ],
200
+ name: "GovernanceWithdrawal",
201
+ type: "event"
202
+ },
203
+ {
204
+ anonymous: false,
205
+ inputs: [
206
+ {
207
+ indexed: false,
208
+ internalType: "uint256",
209
+ name: "oldMinFunding",
210
+ type: "uint256"
211
+ },
212
+ {
213
+ indexed: false,
214
+ internalType: "uint256",
215
+ name: "newMinFunding",
216
+ type: "uint256"
217
+ }
218
+ ],
219
+ name: "MinFundingChanged",
220
+ type: "event"
221
+ },
222
+ {
223
+ anonymous: false,
224
+ inputs: [
225
+ {
226
+ indexed: true,
227
+ internalType: "bytes32",
228
+ name: "nodeID",
229
+ type: "bytes32"
230
+ },
231
+ {
232
+ indexed: false,
233
+ internalType: "uint256",
234
+ name: "amount",
235
+ type: "uint256"
236
+ }
237
+ ],
238
+ name: "RedemptionExecuted",
239
+ type: "event"
240
+ },
241
+ {
242
+ anonymous: false,
243
+ inputs: [
244
+ {
245
+ indexed: true,
246
+ internalType: "bytes32",
247
+ name: "nodeID",
248
+ type: "bytes32"
249
+ },
250
+ {
251
+ indexed: false,
252
+ internalType: "uint256",
253
+ name: "amount",
254
+ type: "uint256"
255
+ }
256
+ ],
257
+ name: "RedemptionExpired",
258
+ type: "event"
259
+ },
260
+ {
261
+ anonymous: false,
262
+ inputs: [
263
+ {
264
+ indexed: true,
265
+ internalType: "bytes32",
266
+ name: "nodeID",
267
+ type: "bytes32"
268
+ },
269
+ {
270
+ indexed: false,
271
+ internalType: "uint256",
272
+ name: "amount",
273
+ type: "uint256"
274
+ },
275
+ {
276
+ indexed: true,
277
+ internalType: "address",
278
+ name: "redeemAddress",
279
+ type: "address"
280
+ },
281
+ {
282
+ indexed: false,
283
+ internalType: "uint48",
284
+ name: "startTime",
285
+ type: "uint48"
286
+ },
287
+ {
288
+ indexed: false,
289
+ internalType: "uint48",
290
+ name: "expiryTime",
291
+ type: "uint48"
292
+ }
293
+ ],
294
+ name: "RedemptionRegistered",
295
+ type: "event"
296
+ },
297
+ {
298
+ anonymous: false,
299
+ inputs: [
300
+ {
301
+ indexed: false,
302
+ internalType: "bool",
303
+ name: "suspended",
304
+ type: "bool"
305
+ }
306
+ ],
307
+ name: "Suspended",
308
+ type: "event"
309
+ },
310
+ {
311
+ anonymous: false,
312
+ inputs: [
313
+ {
314
+ indexed: false,
315
+ internalType: "address",
316
+ name: "keyManager",
317
+ type: "address"
318
+ }
319
+ ],
320
+ name: "UpdatedKeyManager",
321
+ type: "event"
322
+ },
323
+ {
324
+ inputs: [],
325
+ name: "REDEMPTION_DELAY",
326
+ outputs: [
327
+ {
328
+ internalType: "uint48",
329
+ name: "",
330
+ type: "uint48"
331
+ }
332
+ ],
333
+ stateMutability: "view",
334
+ type: "function"
335
+ },
336
+ {
337
+ inputs: [],
338
+ name: "disableCommunityGuard",
339
+ outputs: [],
340
+ stateMutability: "nonpayable",
341
+ type: "function"
342
+ },
343
+ {
344
+ inputs: [],
345
+ name: "enableCommunityGuard",
346
+ outputs: [],
347
+ stateMutability: "nonpayable",
348
+ type: "function"
349
+ },
350
+ {
351
+ inputs: [
352
+ {
353
+ internalType: "bytes32",
354
+ name: "nodeID",
355
+ type: "bytes32"
356
+ }
357
+ ],
358
+ name: "executeRedemption",
359
+ outputs: [],
360
+ stateMutability: "nonpayable",
361
+ type: "function"
362
+ },
363
+ {
364
+ inputs: [
365
+ {
366
+ internalType: "bytes32",
367
+ name: "nodeID",
368
+ type: "bytes32"
369
+ },
370
+ {
371
+ internalType: "uint256",
372
+ name: "amount",
373
+ type: "uint256"
374
+ }
375
+ ],
376
+ name: "fundStateChainAccount",
377
+ outputs: [],
378
+ stateMutability: "nonpayable",
379
+ type: "function"
380
+ },
381
+ {
382
+ inputs: [],
383
+ name: "getCommunityGuardDisabled",
384
+ outputs: [
385
+ {
386
+ internalType: "bool",
387
+ name: "",
388
+ type: "bool"
389
+ }
390
+ ],
391
+ stateMutability: "view",
392
+ type: "function"
393
+ },
394
+ {
395
+ inputs: [],
396
+ name: "getCommunityKey",
397
+ outputs: [
398
+ {
399
+ internalType: "address",
400
+ name: "",
401
+ type: "address"
402
+ }
403
+ ],
404
+ stateMutability: "view",
405
+ type: "function"
406
+ },
407
+ {
408
+ inputs: [],
409
+ name: "getFLIP",
410
+ outputs: [
411
+ {
412
+ internalType: "contract IFLIP",
413
+ name: "",
414
+ type: "address"
415
+ }
416
+ ],
417
+ stateMutability: "view",
418
+ type: "function"
419
+ },
420
+ {
421
+ inputs: [],
422
+ name: "getGovernor",
423
+ outputs: [
424
+ {
425
+ internalType: "address",
426
+ name: "",
427
+ type: "address"
428
+ }
429
+ ],
430
+ stateMutability: "view",
431
+ type: "function"
432
+ },
433
+ {
434
+ inputs: [],
435
+ name: "getKeyManager",
436
+ outputs: [
437
+ {
438
+ internalType: "contract IKeyManager",
439
+ name: "",
440
+ type: "address"
441
+ }
442
+ ],
443
+ stateMutability: "view",
444
+ type: "function"
445
+ },
446
+ {
447
+ inputs: [],
448
+ name: "getLastSupplyUpdateBlockNumber",
449
+ outputs: [
450
+ {
451
+ internalType: "uint256",
452
+ name: "",
453
+ type: "uint256"
454
+ }
455
+ ],
456
+ stateMutability: "view",
457
+ type: "function"
458
+ },
459
+ {
460
+ inputs: [],
461
+ name: "getMinimumFunding",
462
+ outputs: [
463
+ {
464
+ internalType: "uint256",
465
+ name: "",
466
+ type: "uint256"
467
+ }
468
+ ],
469
+ stateMutability: "view",
470
+ type: "function"
471
+ },
472
+ {
473
+ inputs: [
474
+ {
475
+ internalType: "bytes32",
476
+ name: "nodeID",
477
+ type: "bytes32"
478
+ }
479
+ ],
480
+ name: "getPendingRedemption",
481
+ outputs: [
482
+ {
483
+ components: [
484
+ {
485
+ internalType: "uint256",
486
+ name: "amount",
487
+ type: "uint256"
488
+ },
489
+ {
490
+ internalType: "address",
491
+ name: "redeemAddress",
492
+ type: "address"
493
+ },
494
+ {
495
+ internalType: "uint48",
496
+ name: "startTime",
497
+ type: "uint48"
498
+ },
499
+ {
500
+ internalType: "uint48",
501
+ name: "expiryTime",
502
+ type: "uint48"
503
+ }
504
+ ],
505
+ internalType: "struct IStateChainGateway.Redemption",
506
+ name: "",
507
+ type: "tuple"
508
+ }
509
+ ],
510
+ stateMutability: "view",
511
+ type: "function"
512
+ },
513
+ {
514
+ inputs: [],
515
+ name: "getSuspendedState",
516
+ outputs: [
517
+ {
518
+ internalType: "bool",
519
+ name: "",
520
+ type: "bool"
521
+ }
522
+ ],
523
+ stateMutability: "view",
524
+ type: "function"
525
+ },
526
+ {
527
+ inputs: [],
528
+ name: "govUpdateFlipIssuer",
529
+ outputs: [],
530
+ stateMutability: "nonpayable",
531
+ type: "function"
532
+ },
533
+ {
534
+ inputs: [],
535
+ name: "govWithdraw",
536
+ outputs: [],
537
+ stateMutability: "nonpayable",
538
+ type: "function"
539
+ },
540
+ {
541
+ inputs: [
542
+ {
543
+ components: [
544
+ {
545
+ internalType: "uint256",
546
+ name: "sig",
547
+ type: "uint256"
548
+ },
549
+ {
550
+ internalType: "uint256",
551
+ name: "nonce",
552
+ type: "uint256"
553
+ },
554
+ {
555
+ internalType: "address",
556
+ name: "kTimesGAddress",
557
+ type: "address"
558
+ }
559
+ ],
560
+ internalType: "struct IShared.SigData",
561
+ name: "sigData",
562
+ type: "tuple"
563
+ },
564
+ {
565
+ internalType: "bytes32",
566
+ name: "nodeID",
567
+ type: "bytes32"
568
+ },
569
+ {
570
+ internalType: "uint256",
571
+ name: "amount",
572
+ type: "uint256"
573
+ },
574
+ {
575
+ internalType: "address",
576
+ name: "redeemAddress",
577
+ type: "address"
578
+ },
579
+ {
580
+ internalType: "uint48",
581
+ name: "expiryTime",
582
+ type: "uint48"
583
+ }
584
+ ],
585
+ name: "registerRedemption",
586
+ outputs: [],
587
+ stateMutability: "nonpayable",
588
+ type: "function"
589
+ },
590
+ {
591
+ inputs: [],
592
+ name: "resume",
593
+ outputs: [],
594
+ stateMutability: "nonpayable",
595
+ type: "function"
596
+ },
597
+ {
598
+ inputs: [
599
+ {
600
+ internalType: "contract IFLIP",
601
+ name: "flip",
602
+ type: "address"
603
+ }
604
+ ],
605
+ name: "setFlip",
606
+ outputs: [],
607
+ stateMutability: "nonpayable",
608
+ type: "function"
609
+ },
610
+ {
611
+ inputs: [
612
+ {
613
+ internalType: "uint256",
614
+ name: "newMinFunding",
615
+ type: "uint256"
616
+ }
617
+ ],
618
+ name: "setMinFunding",
619
+ outputs: [],
620
+ stateMutability: "nonpayable",
621
+ type: "function"
622
+ },
623
+ {
624
+ inputs: [],
625
+ name: "suspend",
626
+ outputs: [],
627
+ stateMutability: "nonpayable",
628
+ type: "function"
629
+ },
630
+ {
631
+ inputs: [
632
+ {
633
+ components: [
634
+ {
635
+ internalType: "uint256",
636
+ name: "sig",
637
+ type: "uint256"
638
+ },
639
+ {
640
+ internalType: "uint256",
641
+ name: "nonce",
642
+ type: "uint256"
643
+ },
644
+ {
645
+ internalType: "address",
646
+ name: "kTimesGAddress",
647
+ type: "address"
648
+ }
649
+ ],
650
+ internalType: "struct IShared.SigData",
651
+ name: "sigData",
652
+ type: "tuple"
653
+ },
654
+ {
655
+ internalType: "address",
656
+ name: "newIssuer",
657
+ type: "address"
658
+ },
659
+ {
660
+ internalType: "bool",
661
+ name: "omitChecks",
662
+ type: "bool"
663
+ }
664
+ ],
665
+ name: "updateFlipIssuer",
666
+ outputs: [],
667
+ stateMutability: "nonpayable",
668
+ type: "function"
669
+ },
670
+ {
671
+ inputs: [
672
+ {
673
+ components: [
674
+ {
675
+ internalType: "uint256",
676
+ name: "sig",
677
+ type: "uint256"
678
+ },
679
+ {
680
+ internalType: "uint256",
681
+ name: "nonce",
682
+ type: "uint256"
683
+ },
684
+ {
685
+ internalType: "address",
686
+ name: "kTimesGAddress",
687
+ type: "address"
688
+ }
689
+ ],
690
+ internalType: "struct IShared.SigData",
691
+ name: "sigData",
692
+ type: "tuple"
693
+ },
694
+ {
695
+ internalType: "uint256",
696
+ name: "newTotalSupply",
697
+ type: "uint256"
698
+ },
699
+ {
700
+ internalType: "uint256",
701
+ name: "stateChainBlockNumber",
702
+ type: "uint256"
703
+ }
704
+ ],
705
+ name: "updateFlipSupply",
706
+ outputs: [],
707
+ stateMutability: "nonpayable",
708
+ type: "function"
709
+ },
710
+ {
711
+ inputs: [
712
+ {
713
+ components: [
714
+ {
715
+ internalType: "uint256",
716
+ name: "sig",
717
+ type: "uint256"
718
+ },
719
+ {
720
+ internalType: "uint256",
721
+ name: "nonce",
722
+ type: "uint256"
723
+ },
724
+ {
725
+ internalType: "address",
726
+ name: "kTimesGAddress",
727
+ type: "address"
728
+ }
729
+ ],
730
+ internalType: "struct IShared.SigData",
731
+ name: "sigData",
732
+ type: "tuple"
733
+ },
734
+ {
735
+ internalType: "contract IKeyManager",
736
+ name: "keyManager",
737
+ type: "address"
738
+ },
739
+ {
740
+ internalType: "bool",
741
+ name: "omitChecks",
742
+ type: "bool"
743
+ }
744
+ ],
745
+ name: "updateKeyManager",
746
+ outputs: [],
747
+ stateMutability: "nonpayable",
748
+ type: "function"
749
+ }
750
+ ];
751
+ var StateChainGateway__factory = class {
752
+ static createInterface() {
753
+ return new ethers.utils.Interface(_abi2);
754
+ }
755
+ static connect(address, signerOrProvider) {
756
+ return new ethers.Contract(address, _abi2, signerOrProvider);
757
+ }
758
+ };
759
+ __name(StateChainGateway__factory, "StateChainGateway__factory");
760
+ __publicField(StateChainGateway__factory, "abi", _abi2);
761
+
762
+ // ../shared/src/enums.ts
763
+ var arrayToMap = /* @__PURE__ */ __name((array) => Object.fromEntries(array.map((key) => [
764
+ key,
765
+ key
766
+ ])), "arrayToMap");
767
+ var Chains = arrayToMap([
768
+ "Bitcoin",
769
+ "Ethereum",
770
+ "Polkadot"
771
+ ]);
772
+ var Assets = arrayToMap([
773
+ "FLIP",
774
+ "USDC",
775
+ "DOT",
776
+ "ETH",
777
+ "BTC"
778
+ ]);
779
+ var ChainflipNetworks = arrayToMap([
780
+ "sisyphos",
781
+ "perseverance",
782
+ "mainnet",
783
+ "partnernet"
784
+ ]);
785
+ ({
786
+ [Assets.ETH]: Chains.Ethereum,
787
+ [Assets.FLIP]: Chains.Ethereum,
788
+ [Assets.USDC]: Chains.Ethereum,
789
+ [Assets.BTC]: Chains.Bitcoin,
790
+ [Assets.DOT]: Chains.Polkadot
791
+ });
792
+ ({
793
+ [Assets.DOT]: 10,
794
+ [Assets.ETH]: 18,
795
+ [Assets.FLIP]: 18,
796
+ [Assets.USDC]: 6,
797
+ [Assets.BTC]: 8
798
+ });
799
+ ({
800
+ // 0 is reservered for particular cross chain messaging scenarios where we want to pass
801
+ // through a message without making a swap.
802
+ [Assets.ETH]: 1,
803
+ [Assets.FLIP]: 2,
804
+ [Assets.USDC]: 3,
805
+ [Assets.DOT]: 4,
806
+ [Assets.BTC]: 5
807
+ });
808
+ ({
809
+ [Chains.Ethereum]: [
810
+ Assets.ETH,
811
+ Assets.USDC,
812
+ Assets.FLIP
813
+ ],
814
+ [Chains.Bitcoin]: [
815
+ Assets.BTC
816
+ ],
817
+ [Chains.Polkadot]: [
818
+ Assets.DOT
819
+ ]
820
+ });
821
+ ({
822
+ [Chains.Ethereum]: 1,
823
+ [Chains.Polkadot]: 2,
824
+ [Chains.Bitcoin]: 3
825
+ });
826
+
827
+ // ../shared/src/consts.ts
828
+ var ADDRESSES = {
829
+ [ChainflipNetworks.sisyphos]: {
830
+ FLIP_CONTRACT_ADDRESS: "0x2FD78122663A07672e9ac63486573A99EB00125d",
831
+ VAULT_CONTRACT_ADDRESS: "0xd498606dcb9F440CD9F06B397C40fd3327FC2550",
832
+ STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0xCCF267Bc5B709F1A1738122f3b76Cd01F0d9f947"
833
+ },
834
+ [ChainflipNetworks.partnernet]: {
835
+ FLIP_CONTRACT_ADDRESS: "0x7D18Ed38e962FA25f39109f4aC8FbC4C75a0475C",
836
+ VAULT_CONTRACT_ADDRESS: "0xE781866455c5EF1f791975512f7E27814Dc200E1",
837
+ STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0x5aC721F46b88E8671c1B62A501CD78b7C8b07a62"
838
+ },
839
+ [ChainflipNetworks.perseverance]: {
840
+ FLIP_CONTRACT_ADDRESS: "0x1194C91d47Fc1b65bE18db38380B5344682b67db",
841
+ VAULT_CONTRACT_ADDRESS: "0xF1B061aCCDAa4B7c029128b49aBc047F89D5CB8d",
842
+ STATE_CHAIN_MANAGER_CONTRACT_ADDRESS: "0xC960C4eEe4ADf40d24374D85094f3219cf2DD8EB"
843
+ }
844
+ };
845
+ var GOERLI_USDC_CONTRACT_ADDRESS = "0x07865c6E87B9F70255377e024ace6630C1Eaa37F";
846
+
847
+ // ../shared/src/guards.ts
848
+ function assert(condition, message) {
849
+ if (condition)
850
+ return;
851
+ const error = new Error(message);
852
+ if (error.stack) {
853
+ error.stack = error.stack.replace(/\n.+/, "\n");
854
+ }
855
+ throw error;
856
+ }
857
+ __name(assert, "assert");
858
+
859
+ // ../shared/src/contracts.ts
860
+ var getTokenContractAddress = /* @__PURE__ */ __name((asset, network) => {
861
+ assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
862
+ if (asset === Assets.FLIP)
863
+ return ADDRESSES[network].FLIP_CONTRACT_ADDRESS;
864
+ assert(asset === Assets.USDC, "Only FLIP and USDC are supported for now");
865
+ return GOERLI_USDC_CONTRACT_ADDRESS;
866
+ }, "getTokenContractAddress");
867
+ var getStateChainGatewayContractAddress = /* @__PURE__ */ __name((network) => {
868
+ assert(network !== ChainflipNetworks.mainnet, "Mainnet is not yet supported");
869
+ return ADDRESSES[network].STATE_CHAIN_MANAGER_CONTRACT_ADDRESS;
870
+ }, "getStateChainGatewayContractAddress");
871
+ var checkAllowance = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20Address, signer) => {
872
+ const erc20 = ERC20__factory.connect(erc20Address, signer);
873
+ const signerAddress = await signer.getAddress();
874
+ const allowance = await erc20.allowance(signerAddress, spenderAddress);
875
+ return {
876
+ allowance,
877
+ isAllowable: allowance.gte(amount),
878
+ erc20
879
+ };
880
+ }, "checkAllowance");
881
+ var approve = /* @__PURE__ */ __name(async (amount, spenderAddress, erc20, allowance, nonce) => {
882
+ const amountBigNumber = ethers.BigNumber.from(amount);
883
+ const allowanceBigNumber = ethers.BigNumber.from(allowance);
884
+ if (allowanceBigNumber.gte(amountBigNumber))
885
+ return null;
886
+ const requiredAmount = amountBigNumber.sub(allowanceBigNumber);
887
+ const tx = await erc20.approve(spenderAddress, requiredAmount, {
888
+ nonce
889
+ });
890
+ return tx.wait(1);
891
+ }, "approve");
892
+ var getFlipBalance = /* @__PURE__ */ __name(async (network, signer) => {
893
+ const flipAddress = getTokenContractAddress("FLIP", network);
894
+ const flip = ERC20__factory.connect(flipAddress, signer);
895
+ const balance = await flip.balanceOf(await signer.getAddress());
896
+ return balance.toBigInt();
897
+ }, "getFlipBalance");
898
+
899
+ // ../shared/src/stateChainGateway/utils.ts
900
+ var getStateChainGateway = /* @__PURE__ */ __name((options) => {
901
+ const stateChainGatewayContractAddress = options.network === "localnet" ? options.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(options.network);
902
+ return StateChainGateway__factory.connect(stateChainGatewayContractAddress, options.signer);
903
+ }, "getStateChainGateway");
904
+
905
+ // ../shared/src/stateChainGateway/approval.ts
906
+ var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount, options) => {
907
+ const flipContractAddress = options.network === "localnet" ? options.flipContractAddress : getTokenContractAddress(Assets.FLIP, options.network);
908
+ const stateChainGatewayContractAddress = options.network === "localnet" ? options.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(options.network);
909
+ return checkAllowance(amount, stateChainGatewayContractAddress, flipContractAddress, options.signer);
910
+ }, "checkStateChainGatewayAllowance");
911
+ var approveStateChainGateway = /* @__PURE__ */ __name(async (amount, options) => {
912
+ const { allowance, erc20, isAllowable } = await checkStateChainGatewayAllowance(amount, options);
913
+ if (isAllowable)
914
+ return null;
915
+ const stateChainGatewayContractAddress = options.network === "localnet" ? options.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(options.network);
916
+ const receipt = await approve(amount, stateChainGatewayContractAddress, erc20, allowance, options.nonce);
917
+ return receipt;
918
+ }, "approveStateChainGateway");
919
+
920
+ // ../shared/src/stateChainGateway/index.ts
921
+ var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount, options) => {
922
+ const flipContractAddress = options.network === "localnet" ? options.flipContractAddress : getTokenContractAddress(Assets.FLIP, options.network);
923
+ const stateChainGateway = getStateChainGateway(options);
924
+ const { isAllowable } = await checkAllowance(amount, stateChainGateway.address, flipContractAddress, options.signer);
925
+ assert(isAllowable, "Insufficient allowance");
926
+ const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount, {
927
+ nonce: options.nonce
928
+ });
929
+ return transaction.wait(1);
930
+ }, "fundStateChainAccount");
931
+ var executeRedemption = /* @__PURE__ */ __name(async (accountId, { nonce, ...options }) => {
932
+ const stateChainGateway = getStateChainGateway(options);
933
+ const transaction = await stateChainGateway.executeRedemption(accountId, {
934
+ nonce
935
+ });
936
+ return transaction.wait(1);
937
+ }, "executeRedemption");
938
+ var getMinimumFunding = /* @__PURE__ */ __name((options) => {
939
+ const stateChainGateway = getStateChainGateway(options);
940
+ return stateChainGateway.getMinimumFunding();
941
+ }, "getMinimumFunding");
942
+ var getRedemptionDelay = /* @__PURE__ */ __name((options) => {
943
+ const stateChainGateway = getStateChainGateway(options);
944
+ return stateChainGateway.REDEMPTION_DELAY();
945
+ }, "getRedemptionDelay");
946
+
947
+ // src/funding/index.ts
948
+ var FundingSDK = class {
949
+ constructor(options) {
950
+ this.options = {
951
+ signer: options.signer,
952
+ network: options.network ?? ChainflipNetworks.perseverance
953
+ };
954
+ }
955
+ /**
956
+ * @param accountId the hex-encoded validator account id
957
+ * @param amount the amount to fund in base units of FLIP
958
+ * @param signer a signer to use for the transaction if different from the one
959
+ * provided in the constructor
960
+ */
961
+ async fundStateChainAccount(accountId, amount) {
962
+ const tx = await fundStateChainAccount(accountId, amount, this.options);
963
+ return tx.transactionHash;
964
+ }
965
+ /**
966
+ * @param accountId the hex-encoded validator account id
967
+ * @param signer a signer to use for the transaction if different from the one
968
+ * provided in the constructor
969
+ */
970
+ async executeRedemption(accountId) {
971
+ const tx = await executeRedemption(accountId, this.options);
972
+ return tx.transactionHash;
973
+ }
974
+ async getMinimumFunding() {
975
+ const amount = await getMinimumFunding(this.options);
976
+ return amount.toBigInt();
977
+ }
978
+ async getRedemptionDelay() {
979
+ return getRedemptionDelay(this.options);
980
+ }
981
+ async getFlipBalance() {
982
+ return getFlipBalance(this.options.network, this.options.signer);
983
+ }
984
+ /**
985
+ * @param amount the amount of FLIP to request approval for
986
+ * @returns the transaction hash or null if no approval was required
987
+ */
988
+ async approveStateChainGateway(amount, nonce) {
989
+ const receipt = await approveStateChainGateway(amount, {
990
+ nonce,
991
+ ...this.options
992
+ });
993
+ return receipt && receipt.transactionHash;
994
+ }
995
+ };
996
+ __name(FundingSDK, "FundingSDK");
997
+
998
+ exports.FundingSDK = FundingSDK;