@chainflip/sdk 1.8.3 → 1.8.4-beta.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.
package/dist/funding.js CHANGED
@@ -74,6 +74,7 @@ var _abi = [
74
74
  }
75
75
  ];
76
76
  var ERC20__factory = class {
77
+ static abi = _abi;
77
78
  static createInterface() {
78
79
  return new ethers.Interface(_abi);
79
80
  }
@@ -81,7 +82,6 @@ var ERC20__factory = class {
81
82
  return new ethers.Contract(address, _abi, runner);
82
83
  }
83
84
  };
84
- ERC20__factory.abi = _abi;
85
85
  var _abi2 = [
86
86
  {
87
87
  inputs: [
@@ -743,6 +743,7 @@ var _abi2 = [
743
743
  }
744
744
  ];
745
745
  var StateChainGateway__factory = class {
746
+ static abi = _abi2;
746
747
  static createInterface() {
747
748
  return new ethers.Interface(_abi2);
748
749
  }
@@ -750,7 +751,6 @@ var StateChainGateway__factory = class {
750
751
  return new ethers.Contract(address, _abi2, runner);
751
752
  }
752
753
  };
753
- StateChainGateway__factory.abi = _abi2;
754
754
 
755
755
  // ../shared/src/enums.ts
756
756
  var arrayToMap = (array) => Object.fromEntries(array.map((key) => [key, key]));
@@ -930,6 +930,9 @@ var getPendingRedemption = async (accountId, networkOpts) => {
930
930
 
931
931
  // src/funding/sdk.ts
932
932
  var FundingSDK = class {
933
+ options;
934
+ rpcConfig;
935
+ redemptionTax;
933
936
  constructor(options) {
934
937
  const network = options.network ?? ChainflipNetworks.perseverance;
935
938
  this.options = {
@@ -974,7 +977,7 @@ var FundingSDK = class {
974
977
  return tx ? tx.hash : null;
975
978
  }
976
979
  async getRedemptionTax() {
977
- this.redemptionTax ?? (this.redemptionTax = (await getFundingEnvironment(this.rpcConfig)).redemptionTax);
980
+ this.redemptionTax ??= (await getFundingEnvironment(this.rpcConfig)).redemptionTax;
978
981
  return this.redemptionTax;
979
982
  }
980
983
  };
package/dist/funding.mjs CHANGED
@@ -71,6 +71,7 @@ var _abi = [
71
71
  }
72
72
  ];
73
73
  var ERC20__factory = class {
74
+ static abi = _abi;
74
75
  static createInterface() {
75
76
  return new Interface(_abi);
76
77
  }
@@ -78,7 +79,6 @@ var ERC20__factory = class {
78
79
  return new Contract(address, _abi, runner);
79
80
  }
80
81
  };
81
- ERC20__factory.abi = _abi;
82
82
  var _abi2 = [
83
83
  {
84
84
  inputs: [
@@ -740,6 +740,7 @@ var _abi2 = [
740
740
  }
741
741
  ];
742
742
  var StateChainGateway__factory = class {
743
+ static abi = _abi2;
743
744
  static createInterface() {
744
745
  return new Interface(_abi2);
745
746
  }
@@ -747,7 +748,6 @@ var StateChainGateway__factory = class {
747
748
  return new Contract(address, _abi2, runner);
748
749
  }
749
750
  };
750
- StateChainGateway__factory.abi = _abi2;
751
751
 
752
752
  // ../shared/src/contracts.ts
753
753
  var extractOverrides = (transactionOverrides) => {
@@ -849,6 +849,9 @@ var getPendingRedemption = async (accountId, networkOpts) => {
849
849
 
850
850
  // src/funding/sdk.ts
851
851
  var FundingSDK = class {
852
+ options;
853
+ rpcConfig;
854
+ redemptionTax;
852
855
  constructor(options) {
853
856
  const network = options.network ?? ChainflipNetworks.perseverance;
854
857
  this.options = {
@@ -893,7 +896,7 @@ var FundingSDK = class {
893
896
  return tx ? tx.hash : null;
894
897
  }
895
898
  async getRedemptionTax() {
896
- this.redemptionTax ?? (this.redemptionTax = (await getFundingEnvironment(this.rpcConfig)).redemptionTax);
899
+ this.redemptionTax ??= (await getFundingEnvironment(this.rpcConfig)).redemptionTax;
897
900
  return this.redemptionTax;
898
901
  }
899
902
  };
package/dist/swap.d.mts CHANGED
@@ -365,18 +365,10 @@ type BoostPoolDepth = {
365
365
  chain: Chain;
366
366
  };
367
367
 
368
- declare enum FailureMode {
369
- IngressIgnored = "DEPOSIT_IGNORED",
370
- SwapEgressIgnored = "SWAP_OUTPUT_TOO_SMALL",
371
- RefundEgressIgnored = "REFUND_OUTPUT_TOO_SMALL",
372
- BroadcastAborted = "SENDING_FAILED",
373
- DepositRejected = "DEPOSIT_REJECTED"
374
- }
375
-
376
368
  interface Failure {
377
369
  failedAt: number;
378
370
  failedBlockIndex: string;
379
- mode: FailureMode;
371
+ mode: string;
380
372
  reason: {
381
373
  code: string;
382
374
  message: string;
package/dist/swap.d.ts CHANGED
@@ -365,18 +365,10 @@ type BoostPoolDepth = {
365
365
  chain: Chain;
366
366
  };
367
367
 
368
- declare enum FailureMode {
369
- IngressIgnored = "DEPOSIT_IGNORED",
370
- SwapEgressIgnored = "SWAP_OUTPUT_TOO_SMALL",
371
- RefundEgressIgnored = "REFUND_OUTPUT_TOO_SMALL",
372
- BroadcastAborted = "SENDING_FAILED",
373
- DepositRejected = "DEPOSIT_REJECTED"
374
- }
375
-
376
368
  interface Failure {
377
369
  failedAt: number;
378
370
  failedBlockIndex: string;
379
- mode: FailureMode;
371
+ mode: string;
380
372
  reason: {
381
373
  code: string;
382
374
  message: string;
package/dist/swap.js CHANGED
@@ -634,6 +634,78 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork2) {
634
634
  );
635
635
  return transformKeysToCamelCase(response);
636
636
  }
637
+
638
+ // ../shared/src/dataStructures.ts
639
+ var Timer = class {
640
+ constructor(value, cb, ms) {
641
+ this.value = value;
642
+ this.cb = cb;
643
+ this.ms = ms;
644
+ this.reset(true);
645
+ }
646
+ timeout;
647
+ reset(resetExpiryOnLookup) {
648
+ if (resetExpiryOnLookup) {
649
+ this.clear();
650
+ this.timeout = setTimeout(this.cb, this.ms);
651
+ }
652
+ return this;
653
+ }
654
+ getValue(resetExpiryOnLookup) {
655
+ return this.reset(resetExpiryOnLookup).value;
656
+ }
657
+ clear() {
658
+ if (this.timeout) clearTimeout(this.timeout);
659
+ }
660
+ };
661
+ var CacheMap = class {
662
+ constructor(ttl, resetExpiryOnLookup = true) {
663
+ this.ttl = ttl;
664
+ this.resetExpiryOnLookup = resetExpiryOnLookup;
665
+ }
666
+ store = /* @__PURE__ */ new Map();
667
+ set(key, value) {
668
+ this.delete(key);
669
+ const timer = new Timer(value, () => this.store.delete(key), this.ttl);
670
+ this.store.set(key, timer);
671
+ return this;
672
+ }
673
+ get(key) {
674
+ return this.store.get(key)?.getValue(this.resetExpiryOnLookup);
675
+ }
676
+ delete(key) {
677
+ this.store.get(key)?.clear();
678
+ return this.store.delete(key);
679
+ }
680
+ };
681
+ var AsyncCacheMap = class extends CacheMap {
682
+ fetch;
683
+ constructor({
684
+ fetch,
685
+ ttl,
686
+ resetExpiryOnLookup = true
687
+ }) {
688
+ super(ttl, resetExpiryOnLookup);
689
+ this.fetch = fetch;
690
+ }
691
+ get(key) {
692
+ let promise = super.get(key);
693
+ if (!promise) {
694
+ promise = this.fetch(key).catch((err) => {
695
+ this.delete(key);
696
+ throw err;
697
+ });
698
+ this.set(key, promise);
699
+ }
700
+ return promise;
701
+ }
702
+ load(key) {
703
+ return this.get(key).then(
704
+ () => true,
705
+ () => false
706
+ );
707
+ }
708
+ };
637
709
  var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2__default.default(price).multipliedBy(new BigNumber2__default.default(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
638
710
  var parseFoKParams = (params, quote) => {
639
711
  const srcAsset = getInternalAsset(quote.srcAsset);
@@ -708,76 +780,6 @@ var validateSwapAmount = (env, asset2, amount) => {
708
780
  }
709
781
  return { success: true };
710
782
  };
711
-
712
- // ../swap/src/utils/dataStructures.ts
713
- var Timer = class {
714
- constructor(value, cb, ms) {
715
- this.value = value;
716
- this.cb = cb;
717
- this.ms = ms;
718
- this.reset(true);
719
- }
720
- reset(resetExpiryOnLookup) {
721
- if (resetExpiryOnLookup) {
722
- this.clear();
723
- this.timeout = setTimeout(this.cb, this.ms);
724
- }
725
- return this;
726
- }
727
- getValue(resetExpiryOnLookup) {
728
- return this.reset(resetExpiryOnLookup).value;
729
- }
730
- clear() {
731
- if (this.timeout) clearTimeout(this.timeout);
732
- }
733
- };
734
- var CacheMap = class {
735
- constructor(ttl, resetExpiryOnLookup = true) {
736
- this.ttl = ttl;
737
- this.resetExpiryOnLookup = resetExpiryOnLookup;
738
- this.store = /* @__PURE__ */ new Map();
739
- }
740
- set(key, value) {
741
- this.delete(key);
742
- const timer = new Timer(value, () => this.store.delete(key), this.ttl);
743
- this.store.set(key, timer);
744
- return this;
745
- }
746
- get(key) {
747
- return this.store.get(key)?.getValue(this.resetExpiryOnLookup);
748
- }
749
- delete(key) {
750
- this.store.get(key)?.clear();
751
- return this.store.delete(key);
752
- }
753
- };
754
- var AsyncCacheMap = class extends CacheMap {
755
- constructor({
756
- fetch,
757
- ttl,
758
- resetExpiryOnLookup = true
759
- }) {
760
- super(ttl, resetExpiryOnLookup);
761
- this.fetch = fetch;
762
- }
763
- get(key) {
764
- let promise = super.get(key);
765
- if (!promise) {
766
- promise = this.fetch(key).catch((err) => {
767
- this.delete(key);
768
- throw err;
769
- });
770
- this.set(key, promise);
771
- }
772
- return promise;
773
- }
774
- load(key) {
775
- return this.get(key).then(
776
- () => true,
777
- () => false
778
- );
779
- }
780
- };
781
783
  var ETHEREUM_EVM_CHAIN_ID = {
782
784
  [ChainflipNetworks.backspin]: 10997,
783
785
  // backspin ethereum
@@ -892,7 +894,7 @@ var getChainData = (chain2, network, env) => ({
892
894
  });
893
895
 
894
896
  // package.json
895
- var version = "1.8.3";
897
+ var version = "1.8.4-beta.0";
896
898
 
897
899
  // src/swap/consts.ts
898
900
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": version };
@@ -986,8 +988,13 @@ var assertQuoteValid = (quote) => {
986
988
  }
987
989
  };
988
990
  var SwapSDK = class {
991
+ options;
992
+ rpcConfig;
993
+ trpc;
994
+ stateChainEnvironmentCache;
995
+ supportedAssets;
996
+ dcaEnabled = false;
989
997
  constructor(options = {}) {
990
- this.dcaEnabled = false;
991
998
  const network = options.network ?? ChainflipNetworks.perseverance;
992
999
  this.options = {
993
1000
  ...options,
@@ -1025,7 +1032,7 @@ var SwapSDK = class {
1025
1032
  return this.stateChainEnvironmentCache.get("cf_environment");
1026
1033
  }
1027
1034
  async getSupportedAssets() {
1028
- this.supportedAssets ?? (this.supportedAssets = (await getSupportedAssets(this.rpcConfig)).map((asset2) => getInternalAsset(asset2, false)).filter(isNotNullish));
1035
+ this.supportedAssets ??= (await getSupportedAssets(this.rpcConfig)).map((asset2) => getInternalAsset(asset2, false)).filter(isNotNullish);
1029
1036
  return this.supportedAssets;
1030
1037
  }
1031
1038
  async getBoostPoolsDepth() {
package/dist/swap.mjs CHANGED
@@ -411,59 +411,8 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork2) {
411
411
  );
412
412
  return transformKeysToCamelCase(response);
413
413
  }
414
- var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2(price).multipliedBy(new BigNumber2(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
415
- var parseFoKParams = (params, quote) => {
416
- const srcAsset = getInternalAsset(quote.srcAsset);
417
- const destAsset = getInternalAsset(quote.destAsset);
418
- let minPrice;
419
- if ("minPrice" in params) {
420
- assert(
421
- !("slippageTolerancePercent" in params),
422
- "Cannot have both minPrice and slippageTolerancePercent"
423
- );
424
- minPrice = params.minPrice;
425
- } else if ("slippageTolerancePercent" in params) {
426
- const tolerance = new BigNumber2(params.slippageTolerancePercent);
427
- assert(!tolerance.isNaN(), "Invalid slippage tolerance");
428
- assert(
429
- tolerance.gte(0) && tolerance.lte(100),
430
- "Slippage tolerance must be between 0 and 100 inclusive",
431
- RangeError
432
- );
433
- const estimatedPrice = new BigNumber2(quote.estimatedPrice);
434
- assert(!estimatedPrice.isNaN(), "Invalid estimated price");
435
- minPrice = estimatedPrice.times(new BigNumber2(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
436
- } else {
437
- throw new Error("Either minPrice or slippageTolerancePercent must be provided");
438
- }
439
- return {
440
- refundAddress: params.refundAddress,
441
- retryDurationBlocks: params.retryDurationBlocks,
442
- minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
443
- };
444
- };
445
-
446
- // ../shared/src/rpc/utils.ts
447
- var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
448
- var validateSwapAmount = (env, asset2, amount) => {
449
- const minimumAmount = readChainAssetValue(env.ingressEgress.minimumDepositAmounts, asset2);
450
- if (amount < minimumAmount) {
451
- return {
452
- success: false,
453
- reason: `expected amount is below minimum swap amount (${minimumAmount})`
454
- };
455
- }
456
- const maxAmount = readChainAssetValue(env.swapping.maximumSwapAmounts, asset2) ?? MAX_SWAP_AMOUNT;
457
- if (maxAmount != null && amount > maxAmount) {
458
- return {
459
- success: false,
460
- reason: `expected amount is above maximum swap amount (${maxAmount})`
461
- };
462
- }
463
- return { success: true };
464
- };
465
414
 
466
- // ../swap/src/utils/dataStructures.ts
415
+ // ../shared/src/dataStructures.ts
467
416
  var Timer = class {
468
417
  constructor(value, cb, ms) {
469
418
  this.value = value;
@@ -471,6 +420,7 @@ var Timer = class {
471
420
  this.ms = ms;
472
421
  this.reset(true);
473
422
  }
423
+ timeout;
474
424
  reset(resetExpiryOnLookup) {
475
425
  if (resetExpiryOnLookup) {
476
426
  this.clear();
@@ -489,8 +439,8 @@ var CacheMap = class {
489
439
  constructor(ttl, resetExpiryOnLookup = true) {
490
440
  this.ttl = ttl;
491
441
  this.resetExpiryOnLookup = resetExpiryOnLookup;
492
- this.store = /* @__PURE__ */ new Map();
493
442
  }
443
+ store = /* @__PURE__ */ new Map();
494
444
  set(key, value) {
495
445
  this.delete(key);
496
446
  const timer = new Timer(value, () => this.store.delete(key), this.ttl);
@@ -506,6 +456,7 @@ var CacheMap = class {
506
456
  }
507
457
  };
508
458
  var AsyncCacheMap = class extends CacheMap {
459
+ fetch;
509
460
  constructor({
510
461
  fetch,
511
462
  ttl,
@@ -532,6 +483,57 @@ var AsyncCacheMap = class extends CacheMap {
532
483
  );
533
484
  }
534
485
  };
486
+ var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2(price).multipliedBy(new BigNumber2(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
487
+ var parseFoKParams = (params, quote) => {
488
+ const srcAsset = getInternalAsset(quote.srcAsset);
489
+ const destAsset = getInternalAsset(quote.destAsset);
490
+ let minPrice;
491
+ if ("minPrice" in params) {
492
+ assert(
493
+ !("slippageTolerancePercent" in params),
494
+ "Cannot have both minPrice and slippageTolerancePercent"
495
+ );
496
+ minPrice = params.minPrice;
497
+ } else if ("slippageTolerancePercent" in params) {
498
+ const tolerance = new BigNumber2(params.slippageTolerancePercent);
499
+ assert(!tolerance.isNaN(), "Invalid slippage tolerance");
500
+ assert(
501
+ tolerance.gte(0) && tolerance.lte(100),
502
+ "Slippage tolerance must be between 0 and 100 inclusive",
503
+ RangeError
504
+ );
505
+ const estimatedPrice = new BigNumber2(quote.estimatedPrice);
506
+ assert(!estimatedPrice.isNaN(), "Invalid estimated price");
507
+ minPrice = estimatedPrice.times(new BigNumber2(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
508
+ } else {
509
+ throw new Error("Either minPrice or slippageTolerancePercent must be provided");
510
+ }
511
+ return {
512
+ refundAddress: params.refundAddress,
513
+ retryDurationBlocks: params.retryDurationBlocks,
514
+ minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
515
+ };
516
+ };
517
+
518
+ // ../shared/src/rpc/utils.ts
519
+ var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
520
+ var validateSwapAmount = (env, asset2, amount) => {
521
+ const minimumAmount = readChainAssetValue(env.ingressEgress.minimumDepositAmounts, asset2);
522
+ if (amount < minimumAmount) {
523
+ return {
524
+ success: false,
525
+ reason: `expected amount is below minimum swap amount (${minimumAmount})`
526
+ };
527
+ }
528
+ const maxAmount = readChainAssetValue(env.swapping.maximumSwapAmounts, asset2) ?? MAX_SWAP_AMOUNT;
529
+ if (maxAmount != null && amount > maxAmount) {
530
+ return {
531
+ success: false,
532
+ reason: `expected amount is above maximum swap amount (${maxAmount})`
533
+ };
534
+ }
535
+ return { success: true };
536
+ };
535
537
  var getTokenContractAddress = (asset2, network) => {
536
538
  switch (asset2) {
537
539
  case "Btc":
@@ -578,7 +580,7 @@ var getChainData = (chain2, network, env) => ({
578
580
  });
579
581
 
580
582
  // package.json
581
- var version = "1.8.3";
583
+ var version = "1.8.4-beta.0";
582
584
 
583
585
  // src/swap/consts.ts
584
586
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": version };
@@ -672,8 +674,13 @@ var assertQuoteValid = (quote) => {
672
674
  }
673
675
  };
674
676
  var SwapSDK = class {
677
+ options;
678
+ rpcConfig;
679
+ trpc;
680
+ stateChainEnvironmentCache;
681
+ supportedAssets;
682
+ dcaEnabled = false;
675
683
  constructor(options = {}) {
676
- this.dcaEnabled = false;
677
684
  const network = options.network ?? ChainflipNetworks.perseverance;
678
685
  this.options = {
679
686
  ...options,
@@ -711,7 +718,7 @@ var SwapSDK = class {
711
718
  return this.stateChainEnvironmentCache.get("cf_environment");
712
719
  }
713
720
  async getSupportedAssets() {
714
- this.supportedAssets ?? (this.supportedAssets = (await getSupportedAssets(this.rpcConfig)).map((asset2) => getInternalAsset(asset2, false)).filter(isNotNullish));
721
+ this.supportedAssets ??= (await getSupportedAssets(this.rpcConfig)).map((asset2) => getInternalAsset(asset2, false)).filter(isNotNullish);
715
722
  return this.supportedAssets;
716
723
  }
717
724
  async getBoostPoolsDepth() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.8.3",
3
+ "version": "1.8.4-beta.0",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {