@chainflip/sdk 1.8.2 → 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
@@ -173,10 +173,10 @@ interface QuoteRequest extends ChainsAndAssets {
173
173
  messageLengthBytes: number;
174
174
  };
175
175
  }
176
- interface QuoteResponse extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
176
+ interface QuoteResponse extends QuoteRequest {
177
177
  quote: Quote;
178
178
  }
179
- interface QuoteResponseV2 extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
179
+ interface QuoteResponseV2 extends QuoteRequest {
180
180
  quotes: Quote[];
181
181
  }
182
182
  type FillOrKillParamsWithSlippage = Omit<FillOrKillParamsWithMinPrice, 'minPrice'> & {
@@ -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
@@ -173,10 +173,10 @@ interface QuoteRequest extends ChainsAndAssets {
173
173
  messageLengthBytes: number;
174
174
  };
175
175
  }
176
- interface QuoteResponse extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
176
+ interface QuoteResponse extends QuoteRequest {
177
177
  quote: Quote;
178
178
  }
179
- interface QuoteResponseV2 extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
179
+ interface QuoteResponseV2 extends QuoteRequest {
180
180
  quotes: Quote[];
181
181
  }
182
182
  type FillOrKillParamsWithSlippage = Omit<FillOrKillParamsWithMinPrice, 'minPrice'> & {
@@ -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
@@ -397,8 +397,16 @@ zod.z.object({
397
397
  destAsset: asset,
398
398
  amount: numericString.transform((v) => BigInt(v)).refine((v) => v > 0n, { message: "swap input amount must be greater than 0" }).refine((v) => v < 2n ** 128n, { message: "swap input amount must be less than 2^128" }),
399
399
  brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional(),
400
- ccmGasBudget: numericString.transform((v) => BigInt(v)).optional(),
401
- ccmMessageLengthBytes: numericString.transform((v) => Number(v)).optional(),
400
+ ccmGasBudget: zod.z.union([
401
+ numericString.transform((v) => BigInt(v)),
402
+ zod.z.literal("undefined").transform(() => void 0)
403
+ // sdk version 1.8.2 sends undefined string if not set
404
+ ]).optional(),
405
+ ccmMessageLengthBytes: zod.z.union([
406
+ numericString.transform((v) => Number(v)),
407
+ zod.z.literal("undefined").transform(() => void 0)
408
+ // sdk version 1.8.2 sends undefined string if not set
409
+ ]).optional(),
402
410
  dcaEnabled: booleanString.default("false"),
403
411
  isVaultSwap: booleanString.default("false")
404
412
  }).transform((args, ctx) => {
@@ -626,6 +634,78 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork2) {
626
634
  );
627
635
  return transformKeysToCamelCase(response);
628
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
+ };
629
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);
630
710
  var parseFoKParams = (params, quote) => {
631
711
  const srcAsset = getInternalAsset(quote.srcAsset);
@@ -700,76 +780,6 @@ var validateSwapAmount = (env, asset2, amount) => {
700
780
  }
701
781
  return { success: true };
702
782
  };
703
-
704
- // ../swap/src/utils/dataStructures.ts
705
- var Timer = class {
706
- constructor(value, cb, ms) {
707
- this.value = value;
708
- this.cb = cb;
709
- this.ms = ms;
710
- this.reset(true);
711
- }
712
- reset(resetExpiryOnLookup) {
713
- if (resetExpiryOnLookup) {
714
- this.clear();
715
- this.timeout = setTimeout(this.cb, this.ms);
716
- }
717
- return this;
718
- }
719
- getValue(resetExpiryOnLookup) {
720
- return this.reset(resetExpiryOnLookup).value;
721
- }
722
- clear() {
723
- if (this.timeout) clearTimeout(this.timeout);
724
- }
725
- };
726
- var CacheMap = class {
727
- constructor(ttl, resetExpiryOnLookup = true) {
728
- this.ttl = ttl;
729
- this.resetExpiryOnLookup = resetExpiryOnLookup;
730
- this.store = /* @__PURE__ */ new Map();
731
- }
732
- set(key, value) {
733
- this.delete(key);
734
- const timer = new Timer(value, () => this.store.delete(key), this.ttl);
735
- this.store.set(key, timer);
736
- return this;
737
- }
738
- get(key) {
739
- return this.store.get(key)?.getValue(this.resetExpiryOnLookup);
740
- }
741
- delete(key) {
742
- this.store.get(key)?.clear();
743
- return this.store.delete(key);
744
- }
745
- };
746
- var AsyncCacheMap = class extends CacheMap {
747
- constructor({
748
- fetch,
749
- ttl,
750
- resetExpiryOnLookup = true
751
- }) {
752
- super(ttl, resetExpiryOnLookup);
753
- this.fetch = fetch;
754
- }
755
- get(key) {
756
- let promise = super.get(key);
757
- if (!promise) {
758
- promise = this.fetch(key).catch((err) => {
759
- this.delete(key);
760
- throw err;
761
- });
762
- this.set(key, promise);
763
- }
764
- return promise;
765
- }
766
- load(key) {
767
- return this.get(key).then(
768
- () => true,
769
- () => false
770
- );
771
- }
772
- };
773
783
  var ETHEREUM_EVM_CHAIN_ID = {
774
784
  [ChainflipNetworks.backspin]: 10997,
775
785
  // backspin ethereum
@@ -884,7 +894,7 @@ var getChainData = (chain2, network, env) => ({
884
894
  });
885
895
 
886
896
  // package.json
887
- var version = "1.8.2";
897
+ var version = "1.8.4-beta.0";
888
898
 
889
899
  // src/swap/consts.ts
890
900
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": version };
@@ -895,18 +905,21 @@ var BACKEND_SERVICE_URLS = {
895
905
  [ChainflipNetworks.mainnet]: "https://chainflip-swap.chainflip.io/"
896
906
  };
897
907
  var getQuote = async (baseUrl, quoteRequest, { signal }) => {
898
- const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
908
+ const affiliateCommissionBps = quoteRequest.affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
909
+ const totalBrokerCommissionBps = (quoteRequest.brokerCommissionBps ?? 0) + affiliateCommissionBps;
899
910
  const params = {
900
- amount: returnedRequestData.amount,
901
- srcChain: returnedRequestData.srcChain,
902
- srcAsset: returnedRequestData.srcAsset,
903
- destChain: returnedRequestData.destChain,
904
- destAsset: returnedRequestData.destAsset,
911
+ amount: quoteRequest.amount,
912
+ srcChain: quoteRequest.srcChain,
913
+ srcAsset: quoteRequest.srcAsset,
914
+ destChain: quoteRequest.destChain,
915
+ destAsset: quoteRequest.destAsset,
905
916
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
906
- ccmGasBudget: String(ccmGasBudget),
907
- ccmMessageLengthBytes: String(ccmMessageLengthBytes),
908
- ...brokerCommissionBps && {
909
- brokerCommissionBps: String(brokerCommissionBps)
917
+ ...totalBrokerCommissionBps && {
918
+ brokerCommissionBps: String(totalBrokerCommissionBps)
919
+ },
920
+ ...quoteRequest.ccmParams && {
921
+ ccmGasBudget: quoteRequest.ccmParams.gasBudget,
922
+ ccmMessageLengthBytes: String(quoteRequest.ccmParams.messageLengthBytes)
910
923
  },
911
924
  dcaEnabled: "false"
912
925
  };
@@ -916,21 +929,24 @@ var getQuote = async (baseUrl, quoteRequest, { signal }) => {
916
929
  signal,
917
930
  headers: CF_SDK_VERSION_HEADERS
918
931
  });
919
- return { ...returnedRequestData, quote: data };
932
+ return { ...quoteRequest, quote: data };
920
933
  };
921
934
  var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
922
- const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
935
+ const affiliateCommissionBps = quoteRequest.affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
936
+ const totalBrokerCommissionBps = (quoteRequest.brokerCommissionBps ?? 0) + affiliateCommissionBps;
923
937
  const params = {
924
- amount: returnedRequestData.amount,
925
- srcChain: returnedRequestData.srcChain,
926
- srcAsset: returnedRequestData.srcAsset,
927
- destChain: returnedRequestData.destChain,
928
- destAsset: returnedRequestData.destAsset,
938
+ amount: quoteRequest.amount,
939
+ srcChain: quoteRequest.srcChain,
940
+ srcAsset: quoteRequest.srcAsset,
941
+ destChain: quoteRequest.destChain,
942
+ destAsset: quoteRequest.destAsset,
929
943
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
930
- ccmGasBudget: String(ccmGasBudget),
931
- ccmMessageLengthBytes: String(ccmMessageLengthBytes),
932
- ...brokerCommissionBps && {
933
- brokerCommissionBps: String(brokerCommissionBps)
944
+ ...totalBrokerCommissionBps && {
945
+ brokerCommissionBps: String(totalBrokerCommissionBps)
946
+ },
947
+ ...quoteRequest.ccmParams && {
948
+ ccmGasBudget: quoteRequest.ccmParams.gasBudget,
949
+ ccmMessageLengthBytes: String(quoteRequest.ccmParams.messageLengthBytes)
934
950
  },
935
951
  dcaEnabled: String(Boolean(quoteRequest.dcaEnabled))
936
952
  };
@@ -940,7 +956,7 @@ var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
940
956
  signal,
941
957
  headers: CF_SDK_VERSION_HEADERS
942
958
  });
943
- return { ...returnedRequestData, quotes: data };
959
+ return { ...quoteRequest, quotes: data };
944
960
  };
945
961
  var getStatus = async (baseUrl, { id }, { signal }) => {
946
962
  const { data } = await axios__default.default.get(`/swaps/${id}`, {
@@ -972,8 +988,13 @@ var assertQuoteValid = (quote) => {
972
988
  }
973
989
  };
974
990
  var SwapSDK = class {
991
+ options;
992
+ rpcConfig;
993
+ trpc;
994
+ stateChainEnvironmentCache;
995
+ supportedAssets;
996
+ dcaEnabled = false;
975
997
  constructor(options = {}) {
976
- this.dcaEnabled = false;
977
998
  const network = options.network ?? ChainflipNetworks.perseverance;
978
999
  this.options = {
979
1000
  ...options,
@@ -1011,7 +1032,7 @@ var SwapSDK = class {
1011
1032
  return this.stateChainEnvironmentCache.get("cf_environment");
1012
1033
  }
1013
1034
  async getSupportedAssets() {
1014
- 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);
1015
1036
  return this.supportedAssets;
1016
1037
  }
1017
1038
  async getBoostPoolsDepth() {
@@ -1030,31 +1051,23 @@ var SwapSDK = class {
1030
1051
  console.error(
1031
1052
  "[@chainflip/sdk] The getQuote method is deprecated and will be removed in the 1.9 release. Use the getQuoteV2 method instead."
1032
1053
  );
1033
- const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
1034
- const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
1035
- const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
1054
+ const submitterBrokerCommissionBps = quoteRequest.brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
1036
1055
  return getQuote(
1037
1056
  this.options.backendUrl,
1038
1057
  {
1039
- ...remainingRequest,
1040
- ccmGasBudget: ccmParams?.gasBudget,
1041
- ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
1042
- brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps
1058
+ ...quoteRequest,
1059
+ brokerCommissionBps: submitterBrokerCommissionBps
1043
1060
  },
1044
1061
  options
1045
1062
  );
1046
1063
  }
1047
1064
  getQuoteV2(quoteRequest, options = {}) {
1048
- const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
1049
- const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
1050
- const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
1065
+ const submitterBrokerCommissionBps = quoteRequest.brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
1051
1066
  return getQuoteV2(
1052
1067
  this.options.backendUrl,
1053
1068
  {
1054
- ...remainingRequest,
1055
- brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps,
1056
- ccmGasBudget: ccmParams?.gasBudget,
1057
- ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
1069
+ ...quoteRequest,
1070
+ brokerCommissionBps: submitterBrokerCommissionBps,
1058
1071
  dcaEnabled: this.dcaEnabled
1059
1072
  },
1060
1073
  options
package/dist/swap.mjs CHANGED
@@ -174,8 +174,16 @@ z.object({
174
174
  destAsset: asset,
175
175
  amount: numericString.transform((v) => BigInt(v)).refine((v) => v > 0n, { message: "swap input amount must be greater than 0" }).refine((v) => v < 2n ** 128n, { message: "swap input amount must be less than 2^128" }),
176
176
  brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional(),
177
- ccmGasBudget: numericString.transform((v) => BigInt(v)).optional(),
178
- ccmMessageLengthBytes: numericString.transform((v) => Number(v)).optional(),
177
+ ccmGasBudget: z.union([
178
+ numericString.transform((v) => BigInt(v)),
179
+ z.literal("undefined").transform(() => void 0)
180
+ // sdk version 1.8.2 sends undefined string if not set
181
+ ]).optional(),
182
+ ccmMessageLengthBytes: z.union([
183
+ numericString.transform((v) => Number(v)),
184
+ z.literal("undefined").transform(() => void 0)
185
+ // sdk version 1.8.2 sends undefined string if not set
186
+ ]).optional(),
179
187
  dcaEnabled: booleanString.default("false"),
180
188
  isVaultSwap: booleanString.default("false")
181
189
  }).transform((args, ctx) => {
@@ -403,59 +411,8 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork2) {
403
411
  );
404
412
  return transformKeysToCamelCase(response);
405
413
  }
406
- var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2(price).multipliedBy(new BigNumber2(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
407
- var parseFoKParams = (params, quote) => {
408
- const srcAsset = getInternalAsset(quote.srcAsset);
409
- const destAsset = getInternalAsset(quote.destAsset);
410
- let minPrice;
411
- if ("minPrice" in params) {
412
- assert(
413
- !("slippageTolerancePercent" in params),
414
- "Cannot have both minPrice and slippageTolerancePercent"
415
- );
416
- minPrice = params.minPrice;
417
- } else if ("slippageTolerancePercent" in params) {
418
- const tolerance = new BigNumber2(params.slippageTolerancePercent);
419
- assert(!tolerance.isNaN(), "Invalid slippage tolerance");
420
- assert(
421
- tolerance.gte(0) && tolerance.lte(100),
422
- "Slippage tolerance must be between 0 and 100 inclusive",
423
- RangeError
424
- );
425
- const estimatedPrice = new BigNumber2(quote.estimatedPrice);
426
- assert(!estimatedPrice.isNaN(), "Invalid estimated price");
427
- minPrice = estimatedPrice.times(new BigNumber2(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
428
- } else {
429
- throw new Error("Either minPrice or slippageTolerancePercent must be provided");
430
- }
431
- return {
432
- refundAddress: params.refundAddress,
433
- retryDurationBlocks: params.retryDurationBlocks,
434
- minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
435
- };
436
- };
437
-
438
- // ../shared/src/rpc/utils.ts
439
- var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
440
- var validateSwapAmount = (env, asset2, amount) => {
441
- const minimumAmount = readChainAssetValue(env.ingressEgress.minimumDepositAmounts, asset2);
442
- if (amount < minimumAmount) {
443
- return {
444
- success: false,
445
- reason: `expected amount is below minimum swap amount (${minimumAmount})`
446
- };
447
- }
448
- const maxAmount = readChainAssetValue(env.swapping.maximumSwapAmounts, asset2) ?? MAX_SWAP_AMOUNT;
449
- if (maxAmount != null && amount > maxAmount) {
450
- return {
451
- success: false,
452
- reason: `expected amount is above maximum swap amount (${maxAmount})`
453
- };
454
- }
455
- return { success: true };
456
- };
457
414
 
458
- // ../swap/src/utils/dataStructures.ts
415
+ // ../shared/src/dataStructures.ts
459
416
  var Timer = class {
460
417
  constructor(value, cb, ms) {
461
418
  this.value = value;
@@ -463,6 +420,7 @@ var Timer = class {
463
420
  this.ms = ms;
464
421
  this.reset(true);
465
422
  }
423
+ timeout;
466
424
  reset(resetExpiryOnLookup) {
467
425
  if (resetExpiryOnLookup) {
468
426
  this.clear();
@@ -481,8 +439,8 @@ var CacheMap = class {
481
439
  constructor(ttl, resetExpiryOnLookup = true) {
482
440
  this.ttl = ttl;
483
441
  this.resetExpiryOnLookup = resetExpiryOnLookup;
484
- this.store = /* @__PURE__ */ new Map();
485
442
  }
443
+ store = /* @__PURE__ */ new Map();
486
444
  set(key, value) {
487
445
  this.delete(key);
488
446
  const timer = new Timer(value, () => this.store.delete(key), this.ttl);
@@ -498,6 +456,7 @@ var CacheMap = class {
498
456
  }
499
457
  };
500
458
  var AsyncCacheMap = class extends CacheMap {
459
+ fetch;
501
460
  constructor({
502
461
  fetch,
503
462
  ttl,
@@ -524,6 +483,57 @@ var AsyncCacheMap = class extends CacheMap {
524
483
  );
525
484
  }
526
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
+ };
527
537
  var getTokenContractAddress = (asset2, network) => {
528
538
  switch (asset2) {
529
539
  case "Btc":
@@ -570,7 +580,7 @@ var getChainData = (chain2, network, env) => ({
570
580
  });
571
581
 
572
582
  // package.json
573
- var version = "1.8.2";
583
+ var version = "1.8.4-beta.0";
574
584
 
575
585
  // src/swap/consts.ts
576
586
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": version };
@@ -581,18 +591,21 @@ var BACKEND_SERVICE_URLS = {
581
591
  [ChainflipNetworks.mainnet]: "https://chainflip-swap.chainflip.io/"
582
592
  };
583
593
  var getQuote = async (baseUrl, quoteRequest, { signal }) => {
584
- const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
594
+ const affiliateCommissionBps = quoteRequest.affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
595
+ const totalBrokerCommissionBps = (quoteRequest.brokerCommissionBps ?? 0) + affiliateCommissionBps;
585
596
  const params = {
586
- amount: returnedRequestData.amount,
587
- srcChain: returnedRequestData.srcChain,
588
- srcAsset: returnedRequestData.srcAsset,
589
- destChain: returnedRequestData.destChain,
590
- destAsset: returnedRequestData.destAsset,
597
+ amount: quoteRequest.amount,
598
+ srcChain: quoteRequest.srcChain,
599
+ srcAsset: quoteRequest.srcAsset,
600
+ destChain: quoteRequest.destChain,
601
+ destAsset: quoteRequest.destAsset,
591
602
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
592
- ccmGasBudget: String(ccmGasBudget),
593
- ccmMessageLengthBytes: String(ccmMessageLengthBytes),
594
- ...brokerCommissionBps && {
595
- brokerCommissionBps: String(brokerCommissionBps)
603
+ ...totalBrokerCommissionBps && {
604
+ brokerCommissionBps: String(totalBrokerCommissionBps)
605
+ },
606
+ ...quoteRequest.ccmParams && {
607
+ ccmGasBudget: quoteRequest.ccmParams.gasBudget,
608
+ ccmMessageLengthBytes: String(quoteRequest.ccmParams.messageLengthBytes)
596
609
  },
597
610
  dcaEnabled: "false"
598
611
  };
@@ -602,21 +615,24 @@ var getQuote = async (baseUrl, quoteRequest, { signal }) => {
602
615
  signal,
603
616
  headers: CF_SDK_VERSION_HEADERS
604
617
  });
605
- return { ...returnedRequestData, quote: data };
618
+ return { ...quoteRequest, quote: data };
606
619
  };
607
620
  var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
608
- const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
621
+ const affiliateCommissionBps = quoteRequest.affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
622
+ const totalBrokerCommissionBps = (quoteRequest.brokerCommissionBps ?? 0) + affiliateCommissionBps;
609
623
  const params = {
610
- amount: returnedRequestData.amount,
611
- srcChain: returnedRequestData.srcChain,
612
- srcAsset: returnedRequestData.srcAsset,
613
- destChain: returnedRequestData.destChain,
614
- destAsset: returnedRequestData.destAsset,
624
+ amount: quoteRequest.amount,
625
+ srcChain: quoteRequest.srcChain,
626
+ srcAsset: quoteRequest.srcAsset,
627
+ destChain: quoteRequest.destChain,
628
+ destAsset: quoteRequest.destAsset,
615
629
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
616
- ccmGasBudget: String(ccmGasBudget),
617
- ccmMessageLengthBytes: String(ccmMessageLengthBytes),
618
- ...brokerCommissionBps && {
619
- brokerCommissionBps: String(brokerCommissionBps)
630
+ ...totalBrokerCommissionBps && {
631
+ brokerCommissionBps: String(totalBrokerCommissionBps)
632
+ },
633
+ ...quoteRequest.ccmParams && {
634
+ ccmGasBudget: quoteRequest.ccmParams.gasBudget,
635
+ ccmMessageLengthBytes: String(quoteRequest.ccmParams.messageLengthBytes)
620
636
  },
621
637
  dcaEnabled: String(Boolean(quoteRequest.dcaEnabled))
622
638
  };
@@ -626,7 +642,7 @@ var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
626
642
  signal,
627
643
  headers: CF_SDK_VERSION_HEADERS
628
644
  });
629
- return { ...returnedRequestData, quotes: data };
645
+ return { ...quoteRequest, quotes: data };
630
646
  };
631
647
  var getStatus = async (baseUrl, { id }, { signal }) => {
632
648
  const { data } = await axios.get(`/swaps/${id}`, {
@@ -658,8 +674,13 @@ var assertQuoteValid = (quote) => {
658
674
  }
659
675
  };
660
676
  var SwapSDK = class {
677
+ options;
678
+ rpcConfig;
679
+ trpc;
680
+ stateChainEnvironmentCache;
681
+ supportedAssets;
682
+ dcaEnabled = false;
661
683
  constructor(options = {}) {
662
- this.dcaEnabled = false;
663
684
  const network = options.network ?? ChainflipNetworks.perseverance;
664
685
  this.options = {
665
686
  ...options,
@@ -697,7 +718,7 @@ var SwapSDK = class {
697
718
  return this.stateChainEnvironmentCache.get("cf_environment");
698
719
  }
699
720
  async getSupportedAssets() {
700
- 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);
701
722
  return this.supportedAssets;
702
723
  }
703
724
  async getBoostPoolsDepth() {
@@ -716,31 +737,23 @@ var SwapSDK = class {
716
737
  console.error(
717
738
  "[@chainflip/sdk] The getQuote method is deprecated and will be removed in the 1.9 release. Use the getQuoteV2 method instead."
718
739
  );
719
- const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
720
- const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
721
- const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
740
+ const submitterBrokerCommissionBps = quoteRequest.brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
722
741
  return getQuote(
723
742
  this.options.backendUrl,
724
743
  {
725
- ...remainingRequest,
726
- ccmGasBudget: ccmParams?.gasBudget,
727
- ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
728
- brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps
744
+ ...quoteRequest,
745
+ brokerCommissionBps: submitterBrokerCommissionBps
729
746
  },
730
747
  options
731
748
  );
732
749
  }
733
750
  getQuoteV2(quoteRequest, options = {}) {
734
- const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
735
- const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
736
- const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
751
+ const submitterBrokerCommissionBps = quoteRequest.brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
737
752
  return getQuoteV2(
738
753
  this.options.backendUrl,
739
754
  {
740
- ...remainingRequest,
741
- brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps,
742
- ccmGasBudget: ccmParams?.gasBudget,
743
- ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
755
+ ...quoteRequest,
756
+ brokerCommissionBps: submitterBrokerCommissionBps,
744
757
  dcaEnabled: this.dcaEnabled
745
758
  },
746
759
  options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.8.2",
3
+ "version": "1.8.4-beta.0",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@chainflip/bitcoin": "^1.2.4",
45
- "@chainflip/rpc": "^1.8.8",
45
+ "@chainflip/rpc": "^1.8.9",
46
46
  "@chainflip/solana": "^2.1.4",
47
47
  "@chainflip/utils": "^0.5.0",
48
48
  "@trpc/client": "^10.45.2",