@chainflip/sdk 1.9.5 → 1.10.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/swap.js CHANGED
@@ -1,16 +1,15 @@
1
- import { getEnvironment, getEvmChainId, getAllBoostPoolsDepth, assert, isNotNullish, ADDRESSES } from './chunk-6IYYRTHK.js';
2
- import { chainflipChains, assetSymbols, isValidAssetAndChain, getInternalAssets, assetConstants, getInternalAsset, internalAssetToRpcAsset, chainflipNetworks, chainflipAssets, readAssetValue } from '@chainflip/utils/chainflip';
1
+ import { assert, getEnvironment, getEvmChainId, getAllBoostPoolsDepth, isNotNullish, ADDRESSES } from './chunk-Q64VYHIA.js';
2
+ import { unreachable } from '@chainflip/utils/assertion';
3
+ import { chainflipChains, assetSymbols, isValidAssetAndChain, getInternalAssets, chainflipNetworks, chainflipAssets, assetConstants, getInternalAsset, internalAssetToRpcAsset, readAssetValue } from '@chainflip/utils/chainflip';
3
4
  export { getInternalAsset as getChainflipId } from '@chainflip/utils/chainflip';
4
- import { createTRPCProxyClient, httpLink } from '@trpc/client';
5
- import superjson from 'superjson';
5
+ import { initContract, initClient } from '@ts-rest/core';
6
+ import z6, { z } from 'zod';
6
7
  import { HttpClient } from '@chainflip/rpc';
7
- import { unreachable } from '@chainflip/utils/assertion';
8
8
  import { bytesToHex } from '@chainflip/utils/bytes';
9
9
  import * as ss58 from '@chainflip/utils/ss58';
10
10
  import { isHex, toUpperCase } from '@chainflip/utils/string';
11
11
  import { priceX128ToPrice } from '@chainflip/utils/tickMath';
12
- import BigNumber2 from 'bignumber.js';
13
- import { z } from 'zod';
12
+ import BigNumber3 from 'bignumber.js';
14
13
  import { isValidSolanaAddress } from '@chainflip/solana';
15
14
  import { hexEncodeNumber } from '@chainflip/utils/number';
16
15
  import * as bitcoin from '@chainflip/bitcoin';
@@ -112,14 +111,14 @@ z.object({
112
111
  });
113
112
  hadError = true;
114
113
  }
115
- if (args.isOnChain !== void 0 && args.isVaultSwap !== void 0) {
114
+ if (args.isOnChain && args.isVaultSwap) {
116
115
  ctx.addIssue({
117
116
  message: "isOnChain and isVaultSwap cannot be set at the same time",
118
117
  code: z.ZodIssueCode.custom
119
118
  });
120
119
  hadError = true;
121
120
  }
122
- if (args.isOnChain !== void 0 && args.brokerCommissionBps !== void 0 && args.brokerCommissionBps > 0) {
121
+ if (args.isOnChain && args.brokerCommissionBps !== void 0 && args.brokerCommissionBps > 0) {
123
122
  ctx.addIssue({
124
123
  message: "isOnChain cannot be set with a non-zero broker commission",
125
124
  code: z.ZodIssueCode.custom
@@ -145,7 +144,7 @@ var ccmParamsSchema = z.object({
145
144
  message: hexStringWithMaxByteSize(15e3),
146
145
  // https://github.com/chainflip-io/chainflip-backend/blob/415aa9e20ec4046c68892cd34798e5d831c5b83f/state-chain/chains/src/lib.rs#L710
147
146
  ccmAdditionalData: hexStringWithMaxByteSize(3e3).optional(),
148
- /** @deprecated DEPRECATED(1.8) pass additionalData instead */
147
+ /** @deprecated DEPRECATED(1.10) pass additionalData instead */
149
148
  cfParameters: hexStringWithMaxByteSize(3e3).optional()
150
149
  }).transform(({ gasBudget, message, ccmAdditionalData, cfParameters }) => ({
151
150
  gasBudget,
@@ -160,7 +159,7 @@ var dcaParams = z.object({
160
159
  numberOfChunks: z.number(),
161
160
  chunkIntervalBlocks: z.number()
162
161
  });
163
- z.object({
162
+ var fillOrKillParams = z.object({
164
163
  retryDurationBlocks: z.number(),
165
164
  refundAddress: z.string(),
166
165
  minPriceX128: numericString
@@ -244,7 +243,7 @@ var transformedCcmParamsSchema = ccmParamsSchema.transform(
244
243
  message,
245
244
  gas_budget: gasBudget,
246
245
  ccm_additional_data: ccmAdditionalData,
247
- /** @deprecated DEPRECATED(1.8) we still need to pass cf_parameters until 1.8 is deployed to all networks */
246
+ /** @deprecated DEPRECATED(1.10) we still need to pass cf_parameters until 1.8 is deployed to all networks */
248
247
  cf_parameters: ccmAdditionalData
249
248
  })
250
249
  );
@@ -273,7 +272,7 @@ var getDepositAddressRequestSchema = (network) => z.object({
273
272
  });
274
273
  }
275
274
  });
276
- var getParameterEncodingRequestSchema = (network) => z.object({
275
+ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
277
276
  srcAsset: assetAndChain,
278
277
  srcAddress: z.string().optional(),
279
278
  destAsset: assetAndChain,
@@ -311,7 +310,7 @@ var getParameterEncodingRequestSchema = (network) => z.object({
311
310
  }).transform((data) => {
312
311
  let extraParams;
313
312
  if (data.srcAsset.chain === "Bitcoin") {
314
- const minOutputAmount = BigNumber2(data.amount.toString()).multipliedBy(priceX128ToPrice(data.fillOrKillParams.min_price)).toFixed(0);
313
+ const minOutputAmount = BigNumber3(data.amount.toString()).multipliedBy(priceX128ToPrice(data.fillOrKillParams.min_price)).toFixed(0);
315
314
  extraParams = {
316
315
  chain: "Bitcoin",
317
316
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
@@ -377,7 +376,7 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork) {
377
376
  }
378
377
  async function requestSwapParameterEncoding(request, opts, chainflipNetwork) {
379
378
  const client = new HttpClient(opts.url);
380
- const params = getParameterEncodingRequestSchema(chainflipNetwork).parse(request);
379
+ const params = getVaultSwapParameterEncodingRequestSchema(chainflipNetwork).parse(request);
381
380
  const response = await client.sendRequest(
382
381
  "broker_request_swap_parameter_encoding",
383
382
  params.srcAsset,
@@ -392,6 +391,283 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork) {
392
391
  );
393
392
  return transformKeysToCamelCase(response);
394
393
  }
394
+ var cfParameterEncodingRequestSchema = z.object({
395
+ srcAsset: assetAndChain,
396
+ srcAddress: z.string().optional(),
397
+ destAsset: assetAndChain,
398
+ destAddress: z.string(),
399
+ amount: unsignedInteger,
400
+ commissionBps: z.number().optional().default(0),
401
+ ccmParams: transformedCcmParamsSchema.optional(),
402
+ maxBoostFeeBps: z.number().optional(),
403
+ affiliates: z.array(affiliateBroker).optional(),
404
+ fillOrKillParams: transformedFokSchema,
405
+ dcaParams: transformedDcaParamsSchema.optional(),
406
+ network: z.enum(chainflipNetworks)
407
+ }).superRefine(({ network, ...val }, ctx) => {
408
+ if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
409
+ ctx.addIssue({
410
+ message: `Address "${val.srcAddress}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
411
+ code: z.ZodIssueCode.custom
412
+ });
413
+ }
414
+ if (!validateAddress(val.destAsset.chain, val.destAddress, network)) {
415
+ ctx.addIssue({
416
+ message: `Address "${val.destAddress}" is not a valid "${val.destAsset.chain}" address for "${network}"`,
417
+ code: z.ZodIssueCode.custom
418
+ });
419
+ }
420
+ if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
421
+ ctx.addIssue({
422
+ message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
423
+ code: z.ZodIssueCode.custom
424
+ });
425
+ }
426
+ }).transform(({ network, ...rest }) => rest);
427
+ async function requestCfParametersEncoding(request, opts) {
428
+ const client = new HttpClient(opts.url);
429
+ const params = cfParameterEncodingRequestSchema.parse(request);
430
+ const response = await client.sendRequest(
431
+ "broker_encode_cf_parameters",
432
+ params.srcAsset,
433
+ params.destAsset,
434
+ params.destAddress,
435
+ params.commissionBps,
436
+ params.fillOrKillParams,
437
+ params.ccmParams,
438
+ params.maxBoostFeeBps,
439
+ params.affiliates,
440
+ params.dcaParams
441
+ );
442
+ return response;
443
+ }
444
+
445
+ // ../shared/src/api/encodeCfParameters.ts
446
+ var CfParameterEncodingRequestWithBroker = cfParameterEncodingRequestSchema.and(
447
+ z.object({
448
+ brokerAccount: chainflipAddress.optional()
449
+ })
450
+ );
451
+ var TransformedCcmParams = ccmParamsSchema.transform(
452
+ ({ message, gasBudget, ccmAdditionalData }) => ({
453
+ message,
454
+ gas_budget: gasBudget,
455
+ ccm_additional_data: ccmAdditionalData,
456
+ /** @deprecated DEPRECATED(1.10) we still need to pass cf_parameters until 1.8 is deployed to all networks */
457
+ cf_parameters: ccmAdditionalData
458
+ })
459
+ );
460
+ var FillOrKillParams = fillOrKillParams.transform(
461
+ ({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
462
+ retry_duration: retryDurationBlocks,
463
+ refund_address: refundAddress,
464
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`
465
+ })
466
+ );
467
+ var TransformedDcaParams = dcaParams.transform(
468
+ ({ numberOfChunks, chunkIntervalBlocks }) => ({
469
+ number_of_chunks: numberOfChunks,
470
+ chunk_interval: chunkIntervalBlocks
471
+ })
472
+ );
473
+ var EncodeVaultSwapBody = z.object({
474
+ srcAsset: assetAndChain,
475
+ srcAddress: z.string().optional(),
476
+ destAsset: assetAndChain,
477
+ destAddress: z.string(),
478
+ amount: unsignedInteger,
479
+ commissionBps: z.number().optional().default(0),
480
+ ccmParams: TransformedCcmParams.optional(),
481
+ maxBoostFeeBps: z.number().optional(),
482
+ affiliates: z.array(affiliateBroker).optional(),
483
+ fillOrKillParams: FillOrKillParams,
484
+ dcaParams: TransformedDcaParams.optional(),
485
+ extraParams: z.object({ seed: hexString.optional() }).optional(),
486
+ network: z.enum(chainflipNetworks)
487
+ }).superRefine(({ network, ...val }, ctx) => {
488
+ if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
489
+ ctx.addIssue({
490
+ message: `Address "${val.srcAddress}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
491
+ code: z.ZodIssueCode.custom
492
+ });
493
+ }
494
+ if (!validateAddress(val.destAsset.chain, val.destAddress, network)) {
495
+ ctx.addIssue({
496
+ message: `Address "${val.destAddress}" is not a valid "${val.destAsset.chain}" address for "${network}"`,
497
+ code: z.ZodIssueCode.custom
498
+ });
499
+ }
500
+ if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
501
+ ctx.addIssue({
502
+ message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
503
+ code: z.ZodIssueCode.custom
504
+ });
505
+ }
506
+ if (val.extraParams?.seed && val.extraParams.seed.length !== 66) {
507
+ ctx.addIssue({ message: "Seed must be 32 bytes", code: z.ZodIssueCode.custom });
508
+ }
509
+ }).transform(({ network, ...data }) => {
510
+ let extraParams;
511
+ if (data.srcAsset.chain === "Bitcoin") {
512
+ const minOutputAmount = BigNumber(data.amount.toString()).multipliedBy(priceX128ToPrice(data.fillOrKillParams.min_price)).toFixed(0);
513
+ extraParams = {
514
+ chain: "Bitcoin",
515
+ min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
516
+ retry_duration: data.fillOrKillParams.retry_duration
517
+ };
518
+ } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
519
+ extraParams = {
520
+ chain: data.srcAsset.chain,
521
+ input_amount: `0x${data.amount.toString(16)}`,
522
+ refund_parameters: data.fillOrKillParams
523
+ };
524
+ } else if (data.srcAsset.chain === "Solana") {
525
+ assert(data.srcAddress, "srcAddress is required for Solana");
526
+ extraParams = {
527
+ chain: "Solana",
528
+ from: data.srcAddress,
529
+ seed: data.extraParams?.seed ?? bytesToHex(crypto.getRandomValues(new Uint8Array(32))),
530
+ input_amount: `0x${data.amount.toString(16)}`,
531
+ refund_parameters: data.fillOrKillParams
532
+ };
533
+ } else {
534
+ throw new Error(`parameter encoding is not supported for ${data.srcAsset.chain}`);
535
+ }
536
+ return { ...data, extraParams };
537
+ });
538
+ var EncodedVaultSwapData = z.discriminatedUnion("chain", [
539
+ z.object({
540
+ chain: z.literal("Bitcoin"),
541
+ nulldataPayload: hexString,
542
+ depositAddress: z.string()
543
+ }),
544
+ z.object({
545
+ chain: z.enum(["Ethereum", "Arbitrum"]),
546
+ value: z.string(),
547
+ to: hexString,
548
+ calldata: hexString,
549
+ sourceTokenAddress: hexString.optional()
550
+ }),
551
+ z.object({
552
+ chain: z.literal("Solana"),
553
+ programId: z.string(),
554
+ data: hexString,
555
+ accounts: z.array(
556
+ z.object({
557
+ pubkey: z.string(),
558
+ isSigner: z.boolean(),
559
+ isWritable: z.boolean()
560
+ })
561
+ )
562
+ })
563
+ ]);
564
+ var NetworkInfo = z6.object({
565
+ assets: z6.array(
566
+ z6.object({
567
+ asset: z6.enum(chainflipAssets),
568
+ vaultSwapDepositsEnabled: z6.boolean(),
569
+ depositChannelDepositsEnabled: z6.boolean(),
570
+ depositChannelCreationEnabled: z6.boolean(),
571
+ egressEnabled: z6.boolean(),
572
+ boostDepositsEnabled: z6.boolean()
573
+ })
574
+ ),
575
+ cfBrokerCommissionBps: z6.number()
576
+ });
577
+ var ChainflipAsset = z.enum(chainflipAssets);
578
+ var NetworkStatus = z.object({
579
+ assets: z.object({
580
+ deposit: z.array(ChainflipAsset),
581
+ destination: z.array(ChainflipAsset),
582
+ all: z.array(ChainflipAsset)
583
+ }),
584
+ boostDepositsEnabled: z.boolean(),
585
+ cfBrokerCommissionBps: z.number()
586
+ });
587
+ var OpenSwapDepositChannelBody = z.object({
588
+ srcAsset: asset,
589
+ destAsset: asset,
590
+ srcChain: chain,
591
+ destChain: chain,
592
+ destAddress: z.string(),
593
+ amount: numericString,
594
+ ccmParams: ccmParamsSchema.optional(),
595
+ maxBoostFeeBps: z.number().optional(),
596
+ srcAddress: z.string().optional(),
597
+ fillOrKillParams,
598
+ dcaParams: dcaParams.optional(),
599
+ quote: z.object({
600
+ intermediateAmount: z.string().optional(),
601
+ egressAmount: z.string(),
602
+ estimatedPrice: z.string(),
603
+ recommendedSlippageTolerancePercent: z.number().optional()
604
+ }).optional(),
605
+ takeCommission: z.boolean().optional()
606
+ }).transform(({ amount, ...rest }) => ({
607
+ ...rest,
608
+ expectedDepositAmount: amount
609
+ }));
610
+ var DepositChannelInfo = z.object({
611
+ id: z.string(),
612
+ depositAddress: z.string(),
613
+ brokerCommissionBps: z.number(),
614
+ maxBoostFeeBps: z.number(),
615
+ issuedBlock: z.number(),
616
+ srcChainExpiryBlock: z.string(),
617
+ estimatedExpiryTime: z.number().optional(),
618
+ channelOpeningFee: z.string()
619
+ });
620
+
621
+ // ../shared/src/api/contract.ts
622
+ var c = initContract();
623
+ var apiContract = c.router(
624
+ {
625
+ /** @deprecated DEPRECATED(1.9): using `networkInfo` now */
626
+ networkStatus: {
627
+ method: "GET",
628
+ path: "/networkStatus",
629
+ responses: {
630
+ 200: NetworkStatus
631
+ },
632
+ summary: "Get information about the Chainflip network"
633
+ },
634
+ networkInfo: {
635
+ method: "GET",
636
+ path: "/networkInfo",
637
+ responses: {
638
+ 200: NetworkInfo
639
+ },
640
+ summary: "Get information about the Chainflip network"
641
+ },
642
+ encodeCfParameters: {
643
+ method: "POST",
644
+ path: "/encodeCfParameters",
645
+ body: CfParameterEncodingRequestWithBroker,
646
+ responses: {
647
+ 200: hexString
648
+ }
649
+ },
650
+ encodeVaultSwapData: {
651
+ method: "POST",
652
+ path: "/encodeVaultSwapData",
653
+ body: EncodeVaultSwapBody,
654
+ responses: {
655
+ 200: EncodedVaultSwapData
656
+ }
657
+ },
658
+ openSwapDepositChannel: {
659
+ method: "POST",
660
+ path: "/openSwapDepositChannel",
661
+ body: OpenSwapDepositChannelBody,
662
+ responses: {
663
+ 201: DepositChannelInfo
664
+ }
665
+ }
666
+ },
667
+ {
668
+ pathPrefix: "/api"
669
+ }
670
+ );
395
671
 
396
672
  // ../shared/src/dataStructures.ts
397
673
  var MultiCache = class {
@@ -415,7 +691,7 @@ var MultiCache = class {
415
691
  return cached.value;
416
692
  }
417
693
  };
418
- var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2(price).multipliedBy(new BigNumber2(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
694
+ var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber3(price).multipliedBy(new BigNumber3(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
419
695
  function parseFoKParams(params, quote) {
420
696
  const srcAsset = getInternalAsset(quote.srcAsset);
421
697
  const destAsset = getInternalAsset(quote.destAsset);
@@ -427,16 +703,16 @@ function parseFoKParams(params, quote) {
427
703
  );
428
704
  minPrice = params.minPrice;
429
705
  } else if ("slippageTolerancePercent" in params) {
430
- const tolerance = new BigNumber2(params.slippageTolerancePercent);
706
+ const tolerance = new BigNumber3(params.slippageTolerancePercent);
431
707
  assert(!tolerance.isNaN(), "Invalid slippage tolerance");
432
708
  assert(
433
709
  tolerance.gte(0) && tolerance.lte(100),
434
710
  "Slippage tolerance must be between 0 and 100 inclusive",
435
711
  RangeError
436
712
  );
437
- const estimatedPrice = new BigNumber2(quote.estimatedPrice);
713
+ const estimatedPrice = new BigNumber3(quote.estimatedPrice);
438
714
  assert(!estimatedPrice.isNaN(), "Invalid estimated price");
439
- minPrice = estimatedPrice.times(new BigNumber2(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
715
+ minPrice = estimatedPrice.times(new BigNumber3(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
440
716
  } else {
441
717
  throw new Error("Either minPrice or slippageTolerancePercent must be provided");
442
718
  }
@@ -524,7 +800,7 @@ var getChainData = (chain2, network, env) => ({
524
800
 
525
801
  // package.json
526
802
  var package_default = {
527
- version: "1.9.5"};
803
+ version: "1.10.0"};
528
804
 
529
805
  // src/swap/consts.ts
530
806
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -586,7 +862,7 @@ var assertQuoteValid = (quote) => {
586
862
  var SwapSDK = class {
587
863
  options;
588
864
  rpcConfig;
589
- trpc;
865
+ apiClient;
590
866
  cache;
591
867
  dcaEnabled = false;
592
868
  constructor(options = {}) {
@@ -597,14 +873,11 @@ var SwapSDK = class {
597
873
  backendUrl: options.backendUrl ?? BACKEND_SERVICE_URLS[network]
598
874
  };
599
875
  this.rpcConfig = options.rpcUrl ? { rpcUrl: options.rpcUrl } : { network };
600
- this.trpc = createTRPCProxyClient({
601
- transformer: superjson,
602
- links: [
603
- httpLink({
604
- url: new URL("/trpc", this.options.backendUrl),
605
- headers: CF_SDK_VERSION_HEADERS
606
- })
607
- ]
876
+ this.apiClient = initClient(apiContract, {
877
+ // remove trailing slashes. this bug has been fixed in `@ts-rest/core`
878
+ // but it hasn't been released yet
879
+ baseUrl: this.options.backendUrl.replace(/\/+$/, ""),
880
+ baseHeaders: CF_SDK_VERSION_HEADERS
608
881
  });
609
882
  this.dcaEnabled = options.enabledFeatures?.dca ?? false;
610
883
  this.cache = new MultiCache({
@@ -612,8 +885,12 @@ var SwapSDK = class {
612
885
  fetch: () => getEnvironment(this.rpcConfig),
613
886
  ttl: 6e4
614
887
  },
615
- networkStatus: {
616
- fetch: () => this.trpc.networkStatus.query(),
888
+ networkInfo: {
889
+ fetch: async () => {
890
+ const res = await this.apiClient.networkInfo();
891
+ assert(res.status === 200, "Failed to fetch network info");
892
+ return res.body;
893
+ },
617
894
  ttl: 6e4
618
895
  }
619
896
  });
@@ -634,8 +911,23 @@ var SwapSDK = class {
634
911
  return this.cache.read("environment");
635
912
  }
636
913
  async getSupportedAssets(type) {
637
- const assets = await this.cache.read("networkStatus");
638
- return assets.assets[type];
914
+ const assets = await this.cache.read("networkInfo");
915
+ return assets.assets.filter((a) => {
916
+ switch (type) {
917
+ case "all":
918
+ return true;
919
+ case "deposit":
920
+ return a.depositChannelCreationEnabled && a.depositChannelDepositsEnabled && a.vaultSwapDepositsEnabled;
921
+ case "destination":
922
+ return a.egressEnabled;
923
+ case "depositChannel":
924
+ return a.depositChannelCreationEnabled && a.depositChannelDepositsEnabled;
925
+ case "vaultSwap":
926
+ return a.vaultSwapDepositsEnabled;
927
+ default:
928
+ return unreachable(type, "unexpected type");
929
+ }
930
+ }).map((a) => a.asset);
639
931
  }
640
932
  async getBoostPoolsDepth() {
641
933
  return getAllBoostPoolsDepth(this.rpcConfig);
@@ -654,7 +946,7 @@ var SwapSDK = class {
654
946
  }
655
947
  async getCommissionBps(brokerCommissionBps) {
656
948
  if (this.shouldTakeCommission()) {
657
- return (await this.cache.read("networkStatus")).cfBrokerCommissionBps;
949
+ return (await this.cache.read("networkInfo")).cfBrokerCommissionBps;
658
950
  }
659
951
  return brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
660
952
  }
@@ -782,11 +1074,15 @@ var SwapSDK = class {
782
1074
  !affiliates?.length,
783
1075
  "Affiliate brokers are supported only when initializing the SDK with a brokerUrl"
784
1076
  );
785
- response = await this.trpc.openSwapDepositChannel.mutate({
786
- ...depositAddressRequest,
787
- quote,
788
- takeCommission: this.shouldTakeCommission()
1077
+ const res = await this.apiClient.openSwapDepositChannel({
1078
+ body: {
1079
+ ...depositAddressRequest,
1080
+ quote,
1081
+ takeCommission: this.shouldTakeCommission()
1082
+ }
789
1083
  });
1084
+ assert(res.status === 201, "Failed to open swap deposit channel");
1085
+ response = res.body;
790
1086
  }
791
1087
  return {
792
1088
  ...depositAddressRequest,
@@ -795,9 +1091,9 @@ var SwapSDK = class {
795
1091
  brokerCommissionBps: response.brokerCommissionBps,
796
1092
  affiliateBrokers: affiliates ?? [],
797
1093
  maxBoostFeeBps: Number(response.maxBoostFeeBps) || 0,
798
- depositChannelExpiryBlock: response.srcChainExpiryBlock,
1094
+ depositChannelExpiryBlock: BigInt(response.srcChainExpiryBlock),
799
1095
  estimatedDepositChannelExpiryTime: response.estimatedExpiryTime,
800
- channelOpeningFee: response.channelOpeningFee,
1096
+ channelOpeningFee: BigInt(response.channelOpeningFee),
801
1097
  fillOrKillParams: inputFoKParams
802
1098
  };
803
1099
  }
@@ -855,7 +1151,73 @@ var SwapSDK = class {
855
1151
  !vaultSwapRequest.affiliates?.length || vaultSwapRequest.brokerAccount,
856
1152
  "Affiliate brokers are supported only when setting a broker account"
857
1153
  );
858
- return this.trpc.encodeVaultSwapData.mutate(vaultSwapRequest);
1154
+ const res = await this.apiClient.encodeVaultSwapData({
1155
+ body: { ...vaultSwapRequest, network: this.options.network }
1156
+ });
1157
+ if (res.status !== 200) {
1158
+ throw new Error("Failed to encode vault swap data", { cause: res });
1159
+ }
1160
+ switch (res.body.chain) {
1161
+ case "Arbitrum":
1162
+ case "Ethereum":
1163
+ return { ...res.body, value: BigInt(res.body.value) };
1164
+ default:
1165
+ return res.body;
1166
+ }
1167
+ }
1168
+ async encodeCfParameters({
1169
+ quote,
1170
+ srcAddress,
1171
+ destAddress,
1172
+ fillOrKillParams: fillOrKillParams2,
1173
+ affiliateBrokers: affiliates,
1174
+ ccmParams,
1175
+ brokerAccount,
1176
+ brokerCommissionBps
1177
+ }) {
1178
+ await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
1179
+ assertQuoteValid(quote);
1180
+ if (ccmParams) {
1181
+ assert(quote.ccmParams, "Cannot encode CCM swap for quote without CCM params");
1182
+ } else {
1183
+ assert(!quote.ccmParams, "Cannot encode regular swap for quote with CCM params");
1184
+ }
1185
+ const requestParams = {
1186
+ srcAsset: quote.srcAsset,
1187
+ destAsset: quote.destAsset,
1188
+ srcAddress,
1189
+ destAddress,
1190
+ amount: quote.depositAmount,
1191
+ ccmParams,
1192
+ maxBoostFeeBps: "maxBoostFeeBps" in quote ? quote.maxBoostFeeBps : void 0,
1193
+ fillOrKillParams: parseFoKParams(fillOrKillParams2, quote),
1194
+ dcaParams: quote.type === "DCA" ? quote.dcaParams : void 0,
1195
+ commissionBps: await this.getCommissionBps(brokerCommissionBps),
1196
+ affiliates,
1197
+ network: this.options.network
1198
+ };
1199
+ if (this.options.broker) {
1200
+ assert(
1201
+ !brokerAccount,
1202
+ "Cannot overwrite broker account when initializing the SDK with a brokerUrl"
1203
+ );
1204
+ return requestCfParametersEncoding(requestParams, { url: this.options.broker.url });
1205
+ }
1206
+ assert(
1207
+ !requestParams.commissionBps || brokerAccount || this.shouldTakeCommission(),
1208
+ "Broker commission is supported only when setting a broker account"
1209
+ );
1210
+ assert(
1211
+ !requestParams.affiliates?.length || brokerAccount,
1212
+ "Affiliate brokers are supported only when setting a broker account"
1213
+ );
1214
+ const res = await this.apiClient.encodeCfParameters({
1215
+ body: { ...requestParams, brokerAccount }
1216
+ });
1217
+ if (res.status !== 200) {
1218
+ throw new Error("Failed to encode cf parameters", { cause: res });
1219
+ }
1220
+ return res.body;
859
1221
  }
860
1222
  // eslint-disable-next-line class-methods-use-this
861
1223
  getOnChainSwapExtrinsicArgs({
@@ -877,8 +1239,8 @@ var SwapSDK = class {
877
1239
  ];
878
1240
  }
879
1241
  async checkBoostEnabled() {
880
- const { boostDepositsEnabled } = await this.cache.read("networkStatus");
881
- return boostDepositsEnabled;
1242
+ const { assets } = await this.cache.read("networkInfo");
1243
+ return assets.find((a) => a.asset === "Btc")?.boostDepositsEnabled ?? true;
882
1244
  }
883
1245
  };
884
1246
  var arrayToMap = (array) => Object.fromEntries(array.map((item) => [item, item]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.9.5",
3
+ "version": "1.10.0",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -52,16 +52,15 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@chainflip/bitcoin": "^1.2.5",
56
- "@chainflip/rpc": "~1.9.7",
55
+ "@chainflip/bitcoin": "^1.2.6",
56
+ "@chainflip/rpc": "~1.10.4",
57
57
  "@chainflip/solana": "^2.1.9",
58
- "@chainflip/utils": "^0.8.7",
59
- "@trpc/client": "^10.45.2",
60
- "axios": "^1.9.0",
58
+ "@chainflip/utils": "^0.8.11",
59
+ "@ts-rest/core": "^3.52.1",
60
+ "axios": "^1.10.0",
61
61
  "bignumber.js": "^9.3.0",
62
- "ethers": "^6.14.1",
63
- "superjson": "^1.13.3",
64
- "zod": "^3.25.7"
62
+ "ethers": "^6.14.4",
63
+ "zod": "^3.25.76"
65
64
  },
66
65
  "devDependencies": {
67
66
  "@trpc/server": "^10.45.2",
File without changes