@chainflip/sdk 1.8.0 → 1.8.2

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.d.mts CHANGED
@@ -97,6 +97,10 @@ interface BaseQuoteDetails {
97
97
  srcAsset: AssetAndChain;
98
98
  destAsset: AssetAndChain;
99
99
  isVaultSwap: boolean;
100
+ ccmParams?: {
101
+ gasBudget: string;
102
+ messageLengthBytes: number;
103
+ };
100
104
  depositAmount: string;
101
105
  intermediateAmount?: string;
102
106
  egressAmount: string;
@@ -164,22 +168,26 @@ interface QuoteRequest extends ChainsAndAssets {
164
168
  brokerCommissionBps?: number;
165
169
  affiliateBrokers?: AffiliateBroker[];
166
170
  isVaultSwap?: boolean;
171
+ ccmParams?: {
172
+ gasBudget: string;
173
+ messageLengthBytes: number;
174
+ };
167
175
  }
168
- interface QuoteResponse extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers'> {
176
+ interface QuoteResponse extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
169
177
  quote: Quote;
170
178
  }
171
- interface QuoteResponseV2 extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers'> {
179
+ interface QuoteResponseV2 extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
172
180
  quotes: Quote[];
173
181
  }
174
182
  type FillOrKillParamsWithSlippage = Omit<FillOrKillParamsWithMinPrice, 'minPrice'> & {
175
183
  slippageTolerancePercent: string | number;
176
184
  };
177
- interface DepositAddressRequest extends QuoteRequest {
185
+ interface DepositAddressRequest extends Omit<QuoteRequest, 'ccmParams'> {
178
186
  destAddress: string;
179
187
  ccmParams?: CcmParams;
180
188
  maxBoostFeeBps?: number;
181
189
  srcAddress?: string;
182
- fillOrKillParams?: FillOrKillParamsWithMinPrice;
190
+ fillOrKillParams: FillOrKillParamsWithMinPrice;
183
191
  dcaParams?: DcaParams;
184
192
  }
185
193
  interface DepositAddressResponse extends DepositAddressRequest {
@@ -507,7 +515,7 @@ interface DepositAddressRequestV2 {
507
515
  quote: Quote | BoostQuote;
508
516
  srcAddress?: string;
509
517
  destAddress: string;
510
- fillOrKillParams?: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
518
+ fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
511
519
  affiliateBrokers?: {
512
520
  account: `cF${string}` | `0x${string}`;
513
521
  commissionBps: number;
@@ -516,7 +524,7 @@ interface DepositAddressRequestV2 {
516
524
  brokerCommissionBps?: number;
517
525
  }
518
526
  interface DepositAddressResponseV2 extends Omit<DepositAddressRequest, 'fillOrKillParams'> {
519
- fillOrKillParams?: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
527
+ fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
520
528
  depositChannelId: string;
521
529
  depositAddress: string;
522
530
  brokerCommissionBps: number;
package/dist/swap.d.ts CHANGED
@@ -97,6 +97,10 @@ interface BaseQuoteDetails {
97
97
  srcAsset: AssetAndChain;
98
98
  destAsset: AssetAndChain;
99
99
  isVaultSwap: boolean;
100
+ ccmParams?: {
101
+ gasBudget: string;
102
+ messageLengthBytes: number;
103
+ };
100
104
  depositAmount: string;
101
105
  intermediateAmount?: string;
102
106
  egressAmount: string;
@@ -164,22 +168,26 @@ interface QuoteRequest extends ChainsAndAssets {
164
168
  brokerCommissionBps?: number;
165
169
  affiliateBrokers?: AffiliateBroker[];
166
170
  isVaultSwap?: boolean;
171
+ ccmParams?: {
172
+ gasBudget: string;
173
+ messageLengthBytes: number;
174
+ };
167
175
  }
168
- interface QuoteResponse extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers'> {
176
+ interface QuoteResponse extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
169
177
  quote: Quote;
170
178
  }
171
- interface QuoteResponseV2 extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers'> {
179
+ interface QuoteResponseV2 extends Omit<QuoteRequest, 'brokerCommissionBps' | 'affiliateBrokers' | 'ccmParams'> {
172
180
  quotes: Quote[];
173
181
  }
174
182
  type FillOrKillParamsWithSlippage = Omit<FillOrKillParamsWithMinPrice, 'minPrice'> & {
175
183
  slippageTolerancePercent: string | number;
176
184
  };
177
- interface DepositAddressRequest extends QuoteRequest {
185
+ interface DepositAddressRequest extends Omit<QuoteRequest, 'ccmParams'> {
178
186
  destAddress: string;
179
187
  ccmParams?: CcmParams;
180
188
  maxBoostFeeBps?: number;
181
189
  srcAddress?: string;
182
- fillOrKillParams?: FillOrKillParamsWithMinPrice;
190
+ fillOrKillParams: FillOrKillParamsWithMinPrice;
183
191
  dcaParams?: DcaParams;
184
192
  }
185
193
  interface DepositAddressResponse extends DepositAddressRequest {
@@ -507,7 +515,7 @@ interface DepositAddressRequestV2 {
507
515
  quote: Quote | BoostQuote;
508
516
  srcAddress?: string;
509
517
  destAddress: string;
510
- fillOrKillParams?: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
518
+ fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
511
519
  affiliateBrokers?: {
512
520
  account: `cF${string}` | `0x${string}`;
513
521
  commissionBps: number;
@@ -516,7 +524,7 @@ interface DepositAddressRequestV2 {
516
524
  brokerCommissionBps?: number;
517
525
  }
518
526
  interface DepositAddressResponseV2 extends Omit<DepositAddressRequest, 'fillOrKillParams'> {
519
- fillOrKillParams?: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
527
+ fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
520
528
  depositChannelId: string;
521
529
  depositAddress: string;
522
530
  brokerCommissionBps: number;
package/dist/swap.js CHANGED
@@ -13,7 +13,6 @@ var solana = require('@chainflip/solana');
13
13
  var base58 = require('@chainflip/utils/base58');
14
14
  var bytes = require('@chainflip/utils/bytes');
15
15
  var ethers = require('ethers');
16
- var address = require('@chainflip/solana/address');
17
16
  var number$1 = require('@chainflip/utils/number');
18
17
  var axios = require('axios');
19
18
 
@@ -271,7 +270,7 @@ var validateEvmAddress = (address) => ethers__namespace.isAddress(address);
271
270
  var validateBitcoinMainnetAddress = (address) => bitcoin__namespace.isValidAddressForNetwork(address, "mainnet");
272
271
  var validateBitcoinTestnetAddress = (address) => bitcoin__namespace.isValidAddressForNetwork(address, "testnet");
273
272
  var validateBitcoinRegtestAddress = (address) => bitcoin__namespace.isValidAddressForNetwork(address, "regtest");
274
- var validateSolanaAddress = address.isValidSolanaAddress;
273
+ var validateSolanaAddress = solana.isValidSolanaAddress;
275
274
  var validators = {
276
275
  mainnet: {
277
276
  Bitcoin: validateBitcoinMainnetAddress,
@@ -398,6 +397,8 @@ zod.z.object({
398
397
  destAsset: asset,
399
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" }),
400
399
  brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional(),
400
+ ccmGasBudget: numericString.transform((v) => BigInt(v)).optional(),
401
+ ccmMessageLengthBytes: numericString.transform((v) => Number(v)).optional(),
401
402
  dcaEnabled: booleanString.default("false"),
402
403
  isVaultSwap: booleanString.default("false")
403
404
  }).transform((args, ctx) => {
@@ -416,11 +417,27 @@ zod.z.object({
416
417
  });
417
418
  return zod.z.NEVER;
418
419
  }
420
+ if (args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes === void 0) {
421
+ ctx.addIssue({
422
+ message: `ccmMessageLengthBytes must be set if ccmGasBudget is set`,
423
+ code: zod.z.ZodIssueCode.custom
424
+ });
425
+ return zod.z.NEVER;
426
+ }
427
+ if (args.ccmGasBudget === void 0 && args.ccmMessageLengthBytes !== void 0) {
428
+ ctx.addIssue({
429
+ message: `ccmGasBudget must be set if ccmMessageLengthBytes is set`,
430
+ code: zod.z.ZodIssueCode.custom
431
+ });
432
+ return zod.z.NEVER;
433
+ }
434
+ const ccmParams = args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes !== void 0 ? { gasBudget: args.ccmGasBudget, messageLengthBytes: args.ccmMessageLengthBytes } : void 0;
419
435
  return {
420
436
  srcAsset,
421
437
  destAsset,
422
438
  amount: args.amount,
423
439
  brokerCommissionBps: args.brokerCommissionBps,
440
+ ccmParams,
424
441
  dcaEnabled: args.dcaEnabled,
425
442
  isVaultSwap: args.isVaultSwap
426
443
  };
@@ -451,15 +468,6 @@ zod.z.object({
451
468
  refundAddress: zod.z.string(),
452
469
  minPriceX128: numericString
453
470
  });
454
- var ensureDcaWithFok = (args, ctx) => {
455
- if (args.dcaParams && !args.fillOrKillParams) {
456
- ctx.addIssue({
457
- code: "custom",
458
- message: "dcaParams requires fillOrKillParams"
459
- });
460
- return zod.z.NEVER;
461
- }
462
- };
463
471
 
464
472
  // ../shared/src/broker.ts
465
473
  var transformedFokSchema = zod.z.object({
@@ -494,7 +502,7 @@ var getDepositAddressRequestSchema = (network) => zod.z.object({
494
502
  ccmParams: transformedCcmParamsSchema.optional(),
495
503
  maxBoostFeeBps: zod.z.number().optional(),
496
504
  affiliates: zod.z.array(affiliateBroker).optional(),
497
- fillOrKillParams: transformedFokSchema.optional(),
505
+ fillOrKillParams: transformedFokSchema,
498
506
  dcaParams: transformedDcaParamsSchema.optional()
499
507
  }).superRefine((val, ctx) => {
500
508
  if (!validateAddress(val.destAsset.chain, val.destAddress, network)) {
@@ -504,13 +512,13 @@ var getDepositAddressRequestSchema = (network) => zod.z.object({
504
512
  });
505
513
  }
506
514
  }).superRefine((val, ctx) => {
507
- if (val.fillOrKillParams && !validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
515
+ if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
508
516
  ctx.addIssue({
509
517
  message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
510
518
  code: zod.z.ZodIssueCode.custom
511
519
  });
512
520
  }
513
- }).superRefine(ensureDcaWithFok);
521
+ });
514
522
  var getParameterEncodingRequestSchema = (network) => zod.z.object({
515
523
  srcAsset: assetAndChain,
516
524
  srcAddress: zod.z.string().optional(),
@@ -539,7 +547,7 @@ var getParameterEncodingRequestSchema = (network) => zod.z.object({
539
547
  });
540
548
  }
541
549
  }).superRefine((val, ctx) => {
542
- if (val.fillOrKillParams && !validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
550
+ if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
543
551
  ctx.addIssue({
544
552
  message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
545
553
  code: zod.z.ZodIssueCode.custom
@@ -585,7 +593,7 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork2) {
585
593
  }
586
594
  const params = getDepositAddressRequestSchema(chainflipNetwork2).parse(request);
587
595
  const response = await client.sendRequest(
588
- "broker_requestSwapDepositAddress",
596
+ "broker_request_swap_deposit_address",
589
597
  params.srcAsset,
590
598
  params.destAsset,
591
599
  params.destAddress,
@@ -620,7 +628,6 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork2) {
620
628
  }
621
629
  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);
622
630
  var parseFoKParams = (params, quote) => {
623
- if (!params) return void 0;
624
631
  const srcAsset = getInternalAsset(quote.srcAsset);
625
632
  const destAsset = getInternalAsset(quote.destAsset);
626
633
  let minPrice;
@@ -877,7 +884,7 @@ var getChainData = (chain2, network, env) => ({
877
884
  });
878
885
 
879
886
  // package.json
880
- var version = "1.8.0";
887
+ var version = "1.8.2";
881
888
 
882
889
  // src/swap/consts.ts
883
890
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": version };
@@ -888,7 +895,7 @@ var BACKEND_SERVICE_URLS = {
888
895
  [ChainflipNetworks.mainnet]: "https://chainflip-swap.chainflip.io/"
889
896
  };
890
897
  var getQuote = async (baseUrl, quoteRequest, { signal }) => {
891
- const { brokerCommissionBps, ...returnedRequestData } = quoteRequest;
898
+ const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
892
899
  const params = {
893
900
  amount: returnedRequestData.amount,
894
901
  srcChain: returnedRequestData.srcChain,
@@ -896,6 +903,8 @@ var getQuote = async (baseUrl, quoteRequest, { signal }) => {
896
903
  destChain: returnedRequestData.destChain,
897
904
  destAsset: returnedRequestData.destAsset,
898
905
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
906
+ ccmGasBudget: String(ccmGasBudget),
907
+ ccmMessageLengthBytes: String(ccmMessageLengthBytes),
899
908
  ...brokerCommissionBps && {
900
909
  brokerCommissionBps: String(brokerCommissionBps)
901
910
  },
@@ -910,7 +919,7 @@ var getQuote = async (baseUrl, quoteRequest, { signal }) => {
910
919
  return { ...returnedRequestData, quote: data };
911
920
  };
912
921
  var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
913
- const { brokerCommissionBps, ...returnedRequestData } = quoteRequest;
922
+ const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
914
923
  const params = {
915
924
  amount: returnedRequestData.amount,
916
925
  srcChain: returnedRequestData.srcChain,
@@ -918,6 +927,8 @@ var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
918
927
  destChain: returnedRequestData.destChain,
919
928
  destAsset: returnedRequestData.destAsset,
920
929
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
930
+ ccmGasBudget: String(ccmGasBudget),
931
+ ccmMessageLengthBytes: String(ccmMessageLengthBytes),
921
932
  ...brokerCommissionBps && {
922
933
  brokerCommissionBps: String(brokerCommissionBps)
923
934
  },
@@ -1019,20 +1030,22 @@ var SwapSDK = class {
1019
1030
  console.error(
1020
1031
  "[@chainflip/sdk] The getQuote method is deprecated and will be removed in the 1.9 release. Use the getQuoteV2 method instead."
1021
1032
  );
1022
- const { brokerCommissionBps, affiliateBrokers, ...remainingRequest } = quoteRequest;
1033
+ const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
1023
1034
  const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
1024
1035
  const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
1025
1036
  return getQuote(
1026
1037
  this.options.backendUrl,
1027
1038
  {
1028
1039
  ...remainingRequest,
1040
+ ccmGasBudget: ccmParams?.gasBudget,
1041
+ ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
1029
1042
  brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps
1030
1043
  },
1031
1044
  options
1032
1045
  );
1033
1046
  }
1034
1047
  getQuoteV2(quoteRequest, options = {}) {
1035
- const { brokerCommissionBps, affiliateBrokers, ...remainingRequest } = quoteRequest;
1048
+ const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
1036
1049
  const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
1037
1050
  const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
1038
1051
  return getQuoteV2(
@@ -1040,6 +1053,8 @@ var SwapSDK = class {
1040
1053
  {
1041
1054
  ...remainingRequest,
1042
1055
  brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps,
1056
+ ccmGasBudget: ccmParams?.gasBudget,
1057
+ ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
1043
1058
  dcaEnabled: this.dcaEnabled
1044
1059
  },
1045
1060
  options
@@ -1060,14 +1075,14 @@ var SwapSDK = class {
1060
1075
  affiliateBrokers
1061
1076
  } = depositAddressRequest;
1062
1077
  await this.validateSwapAmount({ chain: srcChain, asset: srcAsset }, BigInt(amount));
1063
- const fillOrKillParams2 = depositAddressRequest.fillOrKillParams ? {
1078
+ const fillOrKillParams2 = {
1064
1079
  ...depositAddressRequest.fillOrKillParams,
1065
1080
  minPriceX128: getPriceX128FromPrice(
1066
1081
  depositAddressRequest.fillOrKillParams.minPrice,
1067
1082
  getInternalAsset({ chain: srcChain, asset: srcAsset }),
1068
1083
  getInternalAsset({ chain: destChain, asset: destAsset })
1069
1084
  )
1070
- } : void 0;
1085
+ };
1071
1086
  let response;
1072
1087
  if (this.options.broker) {
1073
1088
  const result = await requestSwapDepositAddress(
@@ -1184,6 +1199,11 @@ var SwapSDK = class {
1184
1199
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
1185
1200
  assertQuoteValid(quote);
1186
1201
  assert(!quote.isVaultSwap, "Cannot open a deposit channel for a vault swap quote");
1202
+ if (ccmParams) {
1203
+ assert(quote.ccmParams, "Cannot open CCM channel for quote without CCM params");
1204
+ } else {
1205
+ assert(!quote.ccmParams, "Cannot open regular channel for quote with CCM params");
1206
+ }
1187
1207
  const depositAddressRequest = {
1188
1208
  srcAsset: quote.srcAsset.asset,
1189
1209
  srcChain: quote.srcAsset.chain,
@@ -1217,7 +1237,6 @@ var SwapSDK = class {
1217
1237
  channelOpeningFee: result.channelOpeningFee
1218
1238
  };
1219
1239
  } else {
1220
- assert(depositAddressRequest.fillOrKillParams, "fill or kill params are required");
1221
1240
  assert(
1222
1241
  !brokerCommissionBps,
1223
1242
  "Broker commission is supported only when initializing the SDK with a brokerUrl"
@@ -1228,7 +1247,6 @@ var SwapSDK = class {
1228
1247
  );
1229
1248
  response = await this.trpc.openSwapDepositChannel.mutate({
1230
1249
  ...depositAddressRequest,
1231
- fillOrKillParams: depositAddressRequest.fillOrKillParams,
1232
1250
  quote
1233
1251
  });
1234
1252
  }
@@ -1259,6 +1277,11 @@ var SwapSDK = class {
1259
1277
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
1260
1278
  assertQuoteValid(quote);
1261
1279
  assert(quote.isVaultSwap, "Cannot encode vault swap data for a deposit channel quote");
1280
+ if (ccmParams) {
1281
+ assert(quote.ccmParams, "Cannot encode CCM swap for quote without CCM params");
1282
+ } else {
1283
+ assert(!quote.ccmParams, "Cannot encode regular swap for quote with CCM params");
1284
+ }
1262
1285
  const vaultSwapRequest = {
1263
1286
  srcAsset: quote.srcAsset,
1264
1287
  destAsset: quote.destAsset,
package/dist/swap.mjs CHANGED
@@ -13,7 +13,6 @@ import { isValidSolanaAddress } from '@chainflip/solana';
13
13
  import * as base58 from '@chainflip/utils/base58';
14
14
  import { hexToBytes } from '@chainflip/utils/bytes';
15
15
  import * as ethers from 'ethers';
16
- import { isValidSolanaAddress as isValidSolanaAddress$1 } from '@chainflip/solana/address';
17
16
  import { hexEncodeNumber } from '@chainflip/utils/number';
18
17
  import axios from 'axios';
19
18
 
@@ -48,7 +47,7 @@ var validateEvmAddress = (address) => ethers.isAddress(address);
48
47
  var validateBitcoinMainnetAddress = (address) => bitcoin.isValidAddressForNetwork(address, "mainnet");
49
48
  var validateBitcoinTestnetAddress = (address) => bitcoin.isValidAddressForNetwork(address, "testnet");
50
49
  var validateBitcoinRegtestAddress = (address) => bitcoin.isValidAddressForNetwork(address, "regtest");
51
- var validateSolanaAddress = isValidSolanaAddress$1;
50
+ var validateSolanaAddress = isValidSolanaAddress;
52
51
  var validators = {
53
52
  mainnet: {
54
53
  Bitcoin: validateBitcoinMainnetAddress,
@@ -175,6 +174,8 @@ z.object({
175
174
  destAsset: asset,
176
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" }),
177
176
  brokerCommissionBps: numericOrEmptyString.transform((v) => Number(v)).optional(),
177
+ ccmGasBudget: numericString.transform((v) => BigInt(v)).optional(),
178
+ ccmMessageLengthBytes: numericString.transform((v) => Number(v)).optional(),
178
179
  dcaEnabled: booleanString.default("false"),
179
180
  isVaultSwap: booleanString.default("false")
180
181
  }).transform((args, ctx) => {
@@ -193,11 +194,27 @@ z.object({
193
194
  });
194
195
  return z.NEVER;
195
196
  }
197
+ if (args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes === void 0) {
198
+ ctx.addIssue({
199
+ message: `ccmMessageLengthBytes must be set if ccmGasBudget is set`,
200
+ code: z.ZodIssueCode.custom
201
+ });
202
+ return z.NEVER;
203
+ }
204
+ if (args.ccmGasBudget === void 0 && args.ccmMessageLengthBytes !== void 0) {
205
+ ctx.addIssue({
206
+ message: `ccmGasBudget must be set if ccmMessageLengthBytes is set`,
207
+ code: z.ZodIssueCode.custom
208
+ });
209
+ return z.NEVER;
210
+ }
211
+ const ccmParams = args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes !== void 0 ? { gasBudget: args.ccmGasBudget, messageLengthBytes: args.ccmMessageLengthBytes } : void 0;
196
212
  return {
197
213
  srcAsset,
198
214
  destAsset,
199
215
  amount: args.amount,
200
216
  brokerCommissionBps: args.brokerCommissionBps,
217
+ ccmParams,
201
218
  dcaEnabled: args.dcaEnabled,
202
219
  isVaultSwap: args.isVaultSwap
203
220
  };
@@ -228,15 +245,6 @@ z.object({
228
245
  refundAddress: z.string(),
229
246
  minPriceX128: numericString
230
247
  });
231
- var ensureDcaWithFok = (args, ctx) => {
232
- if (args.dcaParams && !args.fillOrKillParams) {
233
- ctx.addIssue({
234
- code: "custom",
235
- message: "dcaParams requires fillOrKillParams"
236
- });
237
- return z.NEVER;
238
- }
239
- };
240
248
 
241
249
  // ../shared/src/broker.ts
242
250
  var transformedFokSchema = z.object({
@@ -271,7 +279,7 @@ var getDepositAddressRequestSchema = (network) => z.object({
271
279
  ccmParams: transformedCcmParamsSchema.optional(),
272
280
  maxBoostFeeBps: z.number().optional(),
273
281
  affiliates: z.array(affiliateBroker).optional(),
274
- fillOrKillParams: transformedFokSchema.optional(),
282
+ fillOrKillParams: transformedFokSchema,
275
283
  dcaParams: transformedDcaParamsSchema.optional()
276
284
  }).superRefine((val, ctx) => {
277
285
  if (!validateAddress(val.destAsset.chain, val.destAddress, network)) {
@@ -281,13 +289,13 @@ var getDepositAddressRequestSchema = (network) => z.object({
281
289
  });
282
290
  }
283
291
  }).superRefine((val, ctx) => {
284
- if (val.fillOrKillParams && !validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
292
+ if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
285
293
  ctx.addIssue({
286
294
  message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
287
295
  code: z.ZodIssueCode.custom
288
296
  });
289
297
  }
290
- }).superRefine(ensureDcaWithFok);
298
+ });
291
299
  var getParameterEncodingRequestSchema = (network) => z.object({
292
300
  srcAsset: assetAndChain,
293
301
  srcAddress: z.string().optional(),
@@ -316,7 +324,7 @@ var getParameterEncodingRequestSchema = (network) => z.object({
316
324
  });
317
325
  }
318
326
  }).superRefine((val, ctx) => {
319
- if (val.fillOrKillParams && !validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
327
+ if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
320
328
  ctx.addIssue({
321
329
  message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
322
330
  code: z.ZodIssueCode.custom
@@ -362,7 +370,7 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork2) {
362
370
  }
363
371
  const params = getDepositAddressRequestSchema(chainflipNetwork2).parse(request);
364
372
  const response = await client.sendRequest(
365
- "broker_requestSwapDepositAddress",
373
+ "broker_request_swap_deposit_address",
366
374
  params.srcAsset,
367
375
  params.destAsset,
368
376
  params.destAddress,
@@ -397,7 +405,6 @@ async function requestSwapParameterEncoding(request, opts, chainflipNetwork2) {
397
405
  }
398
406
  var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2(price).multipliedBy(new BigNumber2(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
399
407
  var parseFoKParams = (params, quote) => {
400
- if (!params) return void 0;
401
408
  const srcAsset = getInternalAsset(quote.srcAsset);
402
409
  const destAsset = getInternalAsset(quote.destAsset);
403
410
  let minPrice;
@@ -563,7 +570,7 @@ var getChainData = (chain2, network, env) => ({
563
570
  });
564
571
 
565
572
  // package.json
566
- var version = "1.8.0";
573
+ var version = "1.8.2";
567
574
 
568
575
  // src/swap/consts.ts
569
576
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": version };
@@ -574,7 +581,7 @@ var BACKEND_SERVICE_URLS = {
574
581
  [ChainflipNetworks.mainnet]: "https://chainflip-swap.chainflip.io/"
575
582
  };
576
583
  var getQuote = async (baseUrl, quoteRequest, { signal }) => {
577
- const { brokerCommissionBps, ...returnedRequestData } = quoteRequest;
584
+ const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
578
585
  const params = {
579
586
  amount: returnedRequestData.amount,
580
587
  srcChain: returnedRequestData.srcChain,
@@ -582,6 +589,8 @@ var getQuote = async (baseUrl, quoteRequest, { signal }) => {
582
589
  destChain: returnedRequestData.destChain,
583
590
  destAsset: returnedRequestData.destAsset,
584
591
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
592
+ ccmGasBudget: String(ccmGasBudget),
593
+ ccmMessageLengthBytes: String(ccmMessageLengthBytes),
585
594
  ...brokerCommissionBps && {
586
595
  brokerCommissionBps: String(brokerCommissionBps)
587
596
  },
@@ -596,7 +605,7 @@ var getQuote = async (baseUrl, quoteRequest, { signal }) => {
596
605
  return { ...returnedRequestData, quote: data };
597
606
  };
598
607
  var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
599
- const { brokerCommissionBps, ...returnedRequestData } = quoteRequest;
608
+ const { brokerCommissionBps, ccmGasBudget, ccmMessageLengthBytes, ...returnedRequestData } = quoteRequest;
600
609
  const params = {
601
610
  amount: returnedRequestData.amount,
602
611
  srcChain: returnedRequestData.srcChain,
@@ -604,6 +613,8 @@ var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
604
613
  destChain: returnedRequestData.destChain,
605
614
  destAsset: returnedRequestData.destAsset,
606
615
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
616
+ ccmGasBudget: String(ccmGasBudget),
617
+ ccmMessageLengthBytes: String(ccmMessageLengthBytes),
607
618
  ...brokerCommissionBps && {
608
619
  brokerCommissionBps: String(brokerCommissionBps)
609
620
  },
@@ -705,20 +716,22 @@ var SwapSDK = class {
705
716
  console.error(
706
717
  "[@chainflip/sdk] The getQuote method is deprecated and will be removed in the 1.9 release. Use the getQuoteV2 method instead."
707
718
  );
708
- const { brokerCommissionBps, affiliateBrokers, ...remainingRequest } = quoteRequest;
719
+ const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
709
720
  const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
710
721
  const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
711
722
  return getQuote(
712
723
  this.options.backendUrl,
713
724
  {
714
725
  ...remainingRequest,
726
+ ccmGasBudget: ccmParams?.gasBudget,
727
+ ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
715
728
  brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps
716
729
  },
717
730
  options
718
731
  );
719
732
  }
720
733
  getQuoteV2(quoteRequest, options = {}) {
721
- const { brokerCommissionBps, affiliateBrokers, ...remainingRequest } = quoteRequest;
734
+ const { brokerCommissionBps, affiliateBrokers, ccmParams, ...remainingRequest } = quoteRequest;
722
735
  const submitterBrokerCommissionBps = brokerCommissionBps ?? this.options.broker?.commissionBps ?? 0;
723
736
  const affiliateBrokerCommissionBps = affiliateBrokers?.reduce((acc, affiliate) => acc + affiliate.commissionBps, 0) ?? 0;
724
737
  return getQuoteV2(
@@ -726,6 +739,8 @@ var SwapSDK = class {
726
739
  {
727
740
  ...remainingRequest,
728
741
  brokerCommissionBps: submitterBrokerCommissionBps + affiliateBrokerCommissionBps,
742
+ ccmGasBudget: ccmParams?.gasBudget,
743
+ ccmMessageLengthBytes: ccmParams?.messageLengthBytes,
729
744
  dcaEnabled: this.dcaEnabled
730
745
  },
731
746
  options
@@ -746,14 +761,14 @@ var SwapSDK = class {
746
761
  affiliateBrokers
747
762
  } = depositAddressRequest;
748
763
  await this.validateSwapAmount({ chain: srcChain, asset: srcAsset }, BigInt(amount));
749
- const fillOrKillParams2 = depositAddressRequest.fillOrKillParams ? {
764
+ const fillOrKillParams2 = {
750
765
  ...depositAddressRequest.fillOrKillParams,
751
766
  minPriceX128: getPriceX128FromPrice(
752
767
  depositAddressRequest.fillOrKillParams.minPrice,
753
768
  getInternalAsset({ chain: srcChain, asset: srcAsset }),
754
769
  getInternalAsset({ chain: destChain, asset: destAsset })
755
770
  )
756
- } : void 0;
771
+ };
757
772
  let response;
758
773
  if (this.options.broker) {
759
774
  const result = await requestSwapDepositAddress(
@@ -870,6 +885,11 @@ var SwapSDK = class {
870
885
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
871
886
  assertQuoteValid(quote);
872
887
  assert(!quote.isVaultSwap, "Cannot open a deposit channel for a vault swap quote");
888
+ if (ccmParams) {
889
+ assert(quote.ccmParams, "Cannot open CCM channel for quote without CCM params");
890
+ } else {
891
+ assert(!quote.ccmParams, "Cannot open regular channel for quote with CCM params");
892
+ }
873
893
  const depositAddressRequest = {
874
894
  srcAsset: quote.srcAsset.asset,
875
895
  srcChain: quote.srcAsset.chain,
@@ -903,7 +923,6 @@ var SwapSDK = class {
903
923
  channelOpeningFee: result.channelOpeningFee
904
924
  };
905
925
  } else {
906
- assert(depositAddressRequest.fillOrKillParams, "fill or kill params are required");
907
926
  assert(
908
927
  !brokerCommissionBps,
909
928
  "Broker commission is supported only when initializing the SDK with a brokerUrl"
@@ -914,7 +933,6 @@ var SwapSDK = class {
914
933
  );
915
934
  response = await this.trpc.openSwapDepositChannel.mutate({
916
935
  ...depositAddressRequest,
917
- fillOrKillParams: depositAddressRequest.fillOrKillParams,
918
936
  quote
919
937
  });
920
938
  }
@@ -945,6 +963,11 @@ var SwapSDK = class {
945
963
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
946
964
  assertQuoteValid(quote);
947
965
  assert(quote.isVaultSwap, "Cannot encode vault swap data for a deposit channel quote");
966
+ if (ccmParams) {
967
+ assert(quote.ccmParams, "Cannot encode CCM swap for quote without CCM params");
968
+ } else {
969
+ assert(!quote.ccmParams, "Cannot encode regular swap for quote with CCM params");
970
+ }
948
971
  const vaultSwapRequest = {
949
972
  srcAsset: quote.srcAsset,
950
973
  destAsset: quote.destAsset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -42,8 +42,8 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@chainflip/bitcoin": "^1.2.4",
45
- "@chainflip/rpc": "^1.8.7",
46
- "@chainflip/solana": "^2.1.3",
45
+ "@chainflip/rpc": "^1.8.8",
46
+ "@chainflip/solana": "^2.1.4",
47
47
  "@chainflip/utils": "^0.5.0",
48
48
  "@trpc/client": "^10.45.2",
49
49
  "axios": "^1.7.7",