@chainflip/sdk 1.9.0-beta.2 → 1.9.0-beta.3

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/swap.cjs CHANGED
@@ -4,6 +4,7 @@ var chainflip = require('@chainflip/utils/chainflip');
4
4
  var client = require('@trpc/client');
5
5
  var superjson = require('superjson');
6
6
  var rpc = require('@chainflip/rpc');
7
+ var assertion = require('@chainflip/utils/assertion');
7
8
  var ss58 = require('@chainflip/utils/ss58');
8
9
  var string = require('@chainflip/utils/string');
9
10
  var tickMath = require('@chainflip/utils/tickMath');
@@ -378,8 +379,20 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork) {
378
379
  params.fillOrKillParams,
379
380
  params.dcaParams
380
381
  );
381
- if (params.srcAsset.chain === "Polkadot" && string.isHex(response.address)) {
382
- response.address = ss58__namespace.encode({ data: response.address, ss58Format: DOT_PREFIX });
382
+ switch (params.srcAsset.chain) {
383
+ case "Polkadot":
384
+ case "Assethub":
385
+ if (string.isHex(response.address)) {
386
+ response.address = ss58__namespace.encode({ data: response.address, ss58Format: DOT_PREFIX });
387
+ }
388
+ break;
389
+ case "Ethereum":
390
+ case "Arbitrum":
391
+ case "Bitcoin":
392
+ case "Solana":
393
+ break;
394
+ default:
395
+ return assertion.unreachable(params.srcAsset, "unexpected chain");
383
396
  }
384
397
  return transformKeysToCamelCase(response);
385
398
  }
@@ -402,7 +415,7 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork) {
402
415
  }
403
416
 
404
417
  // ../shared/src/dataStructures.ts
405
- var Cache = class {
418
+ var MultiCache = class {
406
419
  constructor(fetchers) {
407
420
  this.fetchers = fetchers;
408
421
  }
@@ -624,7 +637,7 @@ var getChainData = (chain2, network, env) => ({
624
637
 
625
638
  // package.json
626
639
  var package_default = {
627
- version: "1.9.0-beta.2"};
640
+ version: "1.9.0-beta.3"};
628
641
 
629
642
  // src/swap/consts.ts
630
643
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -706,7 +719,7 @@ var SwapSDK = class {
706
719
  ]
707
720
  });
708
721
  this.dcaEnabled = options.enabledFeatures?.dca ?? false;
709
- this.cache = new Cache({
722
+ this.cache = new MultiCache({
710
723
  environment: {
711
724
  fetch: () => getEnvironment(this.rpcConfig),
712
725
  ttl: 6e4
@@ -747,13 +760,20 @@ var SwapSDK = class {
747
760
  ]);
748
761
  return supportedAssets.map((asset2) => getAssetData(asset2, this.options.network, env)).filter((asset2) => !chain2 || asset2.chain === chain2);
749
762
  }
750
- async getQuoteV2(quoteRequest, options = {}) {
751
- let submitterBrokerCommissionBps;
752
- if (this.options.broker) {
753
- submitterBrokerCommissionBps = quoteRequest.brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
754
- } else {
755
- submitterBrokerCommissionBps = (await this.cache.read("networkStatus")).cfBrokerCommissionBps;
763
+ // eslint-disable-next-line class-methods-use-this
764
+ shouldTakeCommission() {
765
+ return false;
766
+ }
767
+ async getCommissionBps(brokerCommissionBps) {
768
+ if (this.shouldTakeCommission()) {
769
+ return (await this.cache.read("networkStatus")).cfBrokerCommissionBps;
756
770
  }
771
+ return brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
772
+ }
773
+ async getQuoteV2(quoteRequest, options = {}) {
774
+ const submitterBrokerCommissionBps = await this.getCommissionBps(
775
+ quoteRequest.brokerCommissionBps
776
+ );
757
777
  return getQuoteV2(
758
778
  this.options.backendUrl,
759
779
  {
@@ -821,7 +841,7 @@ var SwapSDK = class {
821
841
  fillOrKillParams: inputFoKParams,
822
842
  affiliateBrokers: affiliates,
823
843
  ccmParams,
824
- brokerCommissionBps
844
+ brokerCommissionBps: brokerCommissionBpsParam
825
845
  }) {
826
846
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
827
847
  assertQuoteValid(quote);
@@ -831,6 +851,7 @@ var SwapSDK = class {
831
851
  } else {
832
852
  assert(!quote.ccmParams, "Cannot open regular channel for quote with CCM params");
833
853
  }
854
+ const brokerCommissionBps = await this.getCommissionBps(brokerCommissionBpsParam);
834
855
  const depositAddressRequest = {
835
856
  srcAsset: quote.srcAsset.asset,
836
857
  srcChain: quote.srcAsset.chain,
@@ -849,7 +870,7 @@ var SwapSDK = class {
849
870
  const result = await requestSwapDepositAddress(
850
871
  {
851
872
  ...depositAddressRequest,
852
- commissionBps: brokerCommissionBps ?? this.options.broker.commissionBps,
873
+ commissionBps: brokerCommissionBps,
853
874
  affiliates
854
875
  },
855
876
  { url: this.options.broker.url },
@@ -858,14 +879,14 @@ var SwapSDK = class {
858
879
  response = {
859
880
  id: `${result.issuedBlock}-${quote.srcAsset.chain}-${result.channelId}`,
860
881
  depositAddress: result.address,
861
- brokerCommissionBps: brokerCommissionBps ?? this.options.broker.commissionBps ?? 0,
882
+ brokerCommissionBps,
862
883
  srcChainExpiryBlock: result.sourceChainExpiryBlock,
863
884
  maxBoostFeeBps: depositAddressRequest.maxBoostFeeBps,
864
885
  channelOpeningFee: result.channelOpeningFee
865
886
  };
866
887
  } else {
867
888
  assert(
868
- !brokerCommissionBps,
889
+ !brokerCommissionBps || this.shouldTakeCommission(),
869
890
  "Broker commission is supported only when initializing the SDK with a brokerUrl"
870
891
  );
871
892
  assert(
@@ -874,7 +895,8 @@ var SwapSDK = class {
874
895
  );
875
896
  response = await this.trpc.openSwapDepositChannel.mutate({
876
897
  ...depositAddressRequest,
877
- quote
898
+ quote,
899
+ takeCommission: this.shouldTakeCommission()
878
900
  });
879
901
  }
880
902
  return {
@@ -898,7 +920,7 @@ var SwapSDK = class {
898
920
  affiliateBrokers: affiliates,
899
921
  ccmParams,
900
922
  brokerAccount,
901
- brokerCommissionBps,
923
+ brokerCommissionBps: brokerCommissionBpsParam,
902
924
  extraParams
903
925
  }) {
904
926
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
@@ -909,6 +931,7 @@ var SwapSDK = class {
909
931
  } else {
910
932
  assert(!quote.ccmParams, "Cannot encode regular swap for quote with CCM params");
911
933
  }
934
+ const brokerCommissionBps = await this.getCommissionBps(brokerCommissionBpsParam);
912
935
  const vaultSwapRequest = {
913
936
  srcAsset: quote.srcAsset,
914
937
  destAsset: quote.destAsset,
@@ -930,16 +953,13 @@ var SwapSDK = class {
930
953
  "Cannot overwrite broker account when initializing the SDK with a brokerUrl"
931
954
  );
932
955
  return requestSwapParameterEncoding(
933
- {
934
- ...vaultSwapRequest,
935
- commissionBps: vaultSwapRequest.commissionBps ?? this.options.broker.commissionBps
936
- },
956
+ vaultSwapRequest,
937
957
  { url: this.options.broker.url },
938
958
  this.options.network
939
959
  );
940
960
  }
941
961
  assert(
942
- !vaultSwapRequest.commissionBps || vaultSwapRequest.brokerAccount,
962
+ !vaultSwapRequest.commissionBps || vaultSwapRequest.brokerAccount || this.shouldTakeCommission(),
943
963
  "Broker commission is supported only when setting a broker account"
944
964
  );
945
965
  assert(
package/dist/swap.d.cts CHANGED
@@ -51,6 +51,7 @@ declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<
51
51
  intermediateAmount?: string | undefined;
52
52
  recommendedSlippageTolerancePercent?: number | undefined;
53
53
  } | undefined;
54
+ takeCommission?: boolean | undefined;
54
55
  };
55
56
  _input_out: {
56
57
  expectedDepositAmount: string;
@@ -81,6 +82,7 @@ declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<
81
82
  intermediateAmount?: string | undefined;
82
83
  recommendedSlippageTolerancePercent?: number | undefined;
83
84
  } | undefined;
85
+ takeCommission?: boolean | undefined;
84
86
  };
85
87
  _output_in: typeof _trpc_server.unsetMarker;
86
88
  _output_out: typeof _trpc_server.unsetMarker;
@@ -676,6 +678,8 @@ declare class SwapSDK {
676
678
  private getSupportedAssets;
677
679
  private getBoostPoolsDepth;
678
680
  getAssets(chain?: ChainflipChain, type?: keyof NetworkStatus['assets']): Promise<AssetData[]>;
681
+ protected shouldTakeCommission(): boolean;
682
+ private getCommissionBps;
679
683
  getQuoteV2(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponseV2>;
680
684
  getStatusV2(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponseV2>;
681
685
  private validateSwapAmount;
@@ -690,8 +694,8 @@ declare class SwapSDK {
690
694
  } | ({
691
695
  feeTierBps?: number;
692
696
  } & UncheckedAssetAndChain)): Promise<BoostPoolDepth[]>;
693
- requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
694
- encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
697
+ requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
698
+ encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
695
699
  checkBoostEnabled(): Promise<boolean>;
696
700
  }
697
701
 
package/dist/swap.d.ts CHANGED
@@ -51,6 +51,7 @@ declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<
51
51
  intermediateAmount?: string | undefined;
52
52
  recommendedSlippageTolerancePercent?: number | undefined;
53
53
  } | undefined;
54
+ takeCommission?: boolean | undefined;
54
55
  };
55
56
  _input_out: {
56
57
  expectedDepositAmount: string;
@@ -81,6 +82,7 @@ declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<
81
82
  intermediateAmount?: string | undefined;
82
83
  recommendedSlippageTolerancePercent?: number | undefined;
83
84
  } | undefined;
85
+ takeCommission?: boolean | undefined;
84
86
  };
85
87
  _output_in: typeof _trpc_server.unsetMarker;
86
88
  _output_out: typeof _trpc_server.unsetMarker;
@@ -676,6 +678,8 @@ declare class SwapSDK {
676
678
  private getSupportedAssets;
677
679
  private getBoostPoolsDepth;
678
680
  getAssets(chain?: ChainflipChain, type?: keyof NetworkStatus['assets']): Promise<AssetData[]>;
681
+ protected shouldTakeCommission(): boolean;
682
+ private getCommissionBps;
679
683
  getQuoteV2(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponseV2>;
680
684
  getStatusV2(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponseV2>;
681
685
  private validateSwapAmount;
@@ -690,8 +694,8 @@ declare class SwapSDK {
690
694
  } | ({
691
695
  feeTierBps?: number;
692
696
  } & UncheckedAssetAndChain)): Promise<BoostPoolDepth[]>;
693
- requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
694
- encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
697
+ requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
698
+ encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
695
699
  checkBoostEnabled(): Promise<boolean>;
696
700
  }
697
701
 
package/dist/swap.js CHANGED
@@ -4,6 +4,7 @@ export { getInternalAsset as getChainflipId } from '@chainflip/utils/chainflip';
4
4
  import { createTRPCProxyClient, httpLink } from '@trpc/client';
5
5
  import superjson from 'superjson';
6
6
  import { HttpClient } from '@chainflip/rpc';
7
+ import { unreachable } from '@chainflip/utils/assertion';
7
8
  import * as ss58 from '@chainflip/utils/ss58';
8
9
  import { isHex, toUpperCase } from '@chainflip/utils/string';
9
10
  import { priceX128ToPrice } from '@chainflip/utils/tickMath';
@@ -338,8 +339,20 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork) {
338
339
  params.fillOrKillParams,
339
340
  params.dcaParams
340
341
  );
341
- if (params.srcAsset.chain === "Polkadot" && isHex(response.address)) {
342
- response.address = ss58.encode({ data: response.address, ss58Format: DOT_PREFIX });
342
+ switch (params.srcAsset.chain) {
343
+ case "Polkadot":
344
+ case "Assethub":
345
+ if (isHex(response.address)) {
346
+ response.address = ss58.encode({ data: response.address, ss58Format: DOT_PREFIX });
347
+ }
348
+ break;
349
+ case "Ethereum":
350
+ case "Arbitrum":
351
+ case "Bitcoin":
352
+ case "Solana":
353
+ break;
354
+ default:
355
+ return unreachable(params.srcAsset, "unexpected chain");
343
356
  }
344
357
  return transformKeysToCamelCase(response);
345
358
  }
@@ -362,7 +375,7 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork) {
362
375
  }
363
376
 
364
377
  // ../shared/src/dataStructures.ts
365
- var Cache = class {
378
+ var MultiCache = class {
366
379
  constructor(fetchers) {
367
380
  this.fetchers = fetchers;
368
381
  }
@@ -492,7 +505,7 @@ var getChainData = (chain2, network, env) => ({
492
505
 
493
506
  // package.json
494
507
  var package_default = {
495
- version: "1.9.0-beta.2"};
508
+ version: "1.9.0-beta.3"};
496
509
 
497
510
  // src/swap/consts.ts
498
511
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -574,7 +587,7 @@ var SwapSDK = class {
574
587
  ]
575
588
  });
576
589
  this.dcaEnabled = options.enabledFeatures?.dca ?? false;
577
- this.cache = new Cache({
590
+ this.cache = new MultiCache({
578
591
  environment: {
579
592
  fetch: () => getEnvironment(this.rpcConfig),
580
593
  ttl: 6e4
@@ -615,13 +628,20 @@ var SwapSDK = class {
615
628
  ]);
616
629
  return supportedAssets.map((asset2) => getAssetData(asset2, this.options.network, env)).filter((asset2) => !chain2 || asset2.chain === chain2);
617
630
  }
618
- async getQuoteV2(quoteRequest, options = {}) {
619
- let submitterBrokerCommissionBps;
620
- if (this.options.broker) {
621
- submitterBrokerCommissionBps = quoteRequest.brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
622
- } else {
623
- submitterBrokerCommissionBps = (await this.cache.read("networkStatus")).cfBrokerCommissionBps;
631
+ // eslint-disable-next-line class-methods-use-this
632
+ shouldTakeCommission() {
633
+ return false;
634
+ }
635
+ async getCommissionBps(brokerCommissionBps) {
636
+ if (this.shouldTakeCommission()) {
637
+ return (await this.cache.read("networkStatus")).cfBrokerCommissionBps;
624
638
  }
639
+ return brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
640
+ }
641
+ async getQuoteV2(quoteRequest, options = {}) {
642
+ const submitterBrokerCommissionBps = await this.getCommissionBps(
643
+ quoteRequest.brokerCommissionBps
644
+ );
625
645
  return getQuoteV2(
626
646
  this.options.backendUrl,
627
647
  {
@@ -689,7 +709,7 @@ var SwapSDK = class {
689
709
  fillOrKillParams: inputFoKParams,
690
710
  affiliateBrokers: affiliates,
691
711
  ccmParams,
692
- brokerCommissionBps
712
+ brokerCommissionBps: brokerCommissionBpsParam
693
713
  }) {
694
714
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
695
715
  assertQuoteValid(quote);
@@ -699,6 +719,7 @@ var SwapSDK = class {
699
719
  } else {
700
720
  assert(!quote.ccmParams, "Cannot open regular channel for quote with CCM params");
701
721
  }
722
+ const brokerCommissionBps = await this.getCommissionBps(brokerCommissionBpsParam);
702
723
  const depositAddressRequest = {
703
724
  srcAsset: quote.srcAsset.asset,
704
725
  srcChain: quote.srcAsset.chain,
@@ -717,7 +738,7 @@ var SwapSDK = class {
717
738
  const result = await requestSwapDepositAddress(
718
739
  {
719
740
  ...depositAddressRequest,
720
- commissionBps: brokerCommissionBps ?? this.options.broker.commissionBps,
741
+ commissionBps: brokerCommissionBps,
721
742
  affiliates
722
743
  },
723
744
  { url: this.options.broker.url },
@@ -726,14 +747,14 @@ var SwapSDK = class {
726
747
  response = {
727
748
  id: `${result.issuedBlock}-${quote.srcAsset.chain}-${result.channelId}`,
728
749
  depositAddress: result.address,
729
- brokerCommissionBps: brokerCommissionBps ?? this.options.broker.commissionBps ?? 0,
750
+ brokerCommissionBps,
730
751
  srcChainExpiryBlock: result.sourceChainExpiryBlock,
731
752
  maxBoostFeeBps: depositAddressRequest.maxBoostFeeBps,
732
753
  channelOpeningFee: result.channelOpeningFee
733
754
  };
734
755
  } else {
735
756
  assert(
736
- !brokerCommissionBps,
757
+ !brokerCommissionBps || this.shouldTakeCommission(),
737
758
  "Broker commission is supported only when initializing the SDK with a brokerUrl"
738
759
  );
739
760
  assert(
@@ -742,7 +763,8 @@ var SwapSDK = class {
742
763
  );
743
764
  response = await this.trpc.openSwapDepositChannel.mutate({
744
765
  ...depositAddressRequest,
745
- quote
766
+ quote,
767
+ takeCommission: this.shouldTakeCommission()
746
768
  });
747
769
  }
748
770
  return {
@@ -766,7 +788,7 @@ var SwapSDK = class {
766
788
  affiliateBrokers: affiliates,
767
789
  ccmParams,
768
790
  brokerAccount,
769
- brokerCommissionBps,
791
+ brokerCommissionBps: brokerCommissionBpsParam,
770
792
  extraParams
771
793
  }) {
772
794
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
@@ -777,6 +799,7 @@ var SwapSDK = class {
777
799
  } else {
778
800
  assert(!quote.ccmParams, "Cannot encode regular swap for quote with CCM params");
779
801
  }
802
+ const brokerCommissionBps = await this.getCommissionBps(brokerCommissionBpsParam);
780
803
  const vaultSwapRequest = {
781
804
  srcAsset: quote.srcAsset,
782
805
  destAsset: quote.destAsset,
@@ -798,16 +821,13 @@ var SwapSDK = class {
798
821
  "Cannot overwrite broker account when initializing the SDK with a brokerUrl"
799
822
  );
800
823
  return requestSwapParameterEncoding(
801
- {
802
- ...vaultSwapRequest,
803
- commissionBps: vaultSwapRequest.commissionBps ?? this.options.broker.commissionBps
804
- },
824
+ vaultSwapRequest,
805
825
  { url: this.options.broker.url },
806
826
  this.options.network
807
827
  );
808
828
  }
809
829
  assert(
810
- !vaultSwapRequest.commissionBps || vaultSwapRequest.brokerAccount,
830
+ !vaultSwapRequest.commissionBps || vaultSwapRequest.brokerAccount || this.shouldTakeCommission(),
811
831
  "Broker commission is supported only when setting a broker account"
812
832
  );
813
833
  assert(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.9.0-beta.2",
3
+ "version": "1.9.0-beta.3",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -47,7 +47,7 @@
47
47
  "@chainflip/solana": "^2.1.7",
48
48
  "@chainflip/utils": "^0.8.6",
49
49
  "@trpc/client": "^10.45.2",
50
- "axios": "^1.7.7",
50
+ "axios": "^1.8.4",
51
51
  "bignumber.js": "^9.3.0",
52
52
  "ethers": "^6.13.3",
53
53
  "superjson": "^1.13.3",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@trpc/server": "^10.45.2",
58
- "tsup": "^8.3.6"
58
+ "tsup": "^8.4.0"
59
59
  },
60
60
  "scripts": {
61
61
  "test": "vitest",