@chainflip/sdk 1.10.1 → 1.11.0-beta.1

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
@@ -82,6 +82,7 @@ var hexString = z6.z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
82
82
  var hexStringWithMaxByteSize = (maxByteSize) => hexString.refine((val) => val.length / 2 <= maxByteSize + 1, {
83
83
  message: `String must be less than or equal to ${maxByteSize} bytes`
84
84
  });
85
+ var basisPoints = z6.z.number().int({ message: "must be in basis points" });
85
86
  var DOT_PREFIX = 0;
86
87
  var chainflipAddress = z6.z.string().refine(
87
88
  (address) => address.startsWith("cF") && ss58__namespace.decode(address),
@@ -203,7 +204,8 @@ var dcaParams = z6.z.object({
203
204
  var fillOrKillParams = z6.z.object({
204
205
  retryDurationBlocks: z6.z.number(),
205
206
  refundAddress: z6.z.string(),
206
- minPriceX128: numericString
207
+ minPriceX128: numericString,
208
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
207
209
  });
208
210
  var validatePolkadotAddress = (address) => {
209
211
  if (string.isHex(address)) return address.length === 66;
@@ -267,11 +269,13 @@ var validateAddress = (chain2, address, network) => validators[network][chain2](
267
269
  var transformedFokSchema = z6.z.object({
268
270
  retryDurationBlocks: z6.z.number(),
269
271
  refundAddress: z6.z.string(),
270
- minPriceX128: numericString
271
- }).transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
272
+ minPriceX128: numericString,
273
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
274
+ }).transform(({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
272
275
  retry_duration: retryDurationBlocks,
273
276
  refund_address: refundAddress,
274
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
277
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
278
+ max_oracle_price_slippage: maxOraclePriceSlippage
275
279
  }));
276
280
  var transformedDcaParamsSchema = dcaParams.transform(
277
281
  ({ numberOfChunks, chunkIntervalBlocks }) => ({
@@ -325,7 +329,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z6.z.object({
325
329
  affiliates: z6.z.array(affiliateBroker).optional(),
326
330
  fillOrKillParams: transformedFokSchema,
327
331
  dcaParams: transformedDcaParamsSchema.optional(),
328
- extraParams: z6.z.object({ seed: hexString.optional() }).optional()
332
+ extraParams: z6.z.object({ seed: hexString.optional() }).optional(),
333
+ brokerAccount: chainflipAddress.optional()
329
334
  }).superRefine((val, ctx) => {
330
335
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
331
336
  ctx.addIssue({
@@ -355,7 +360,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z6.z.object({
355
360
  extraParams = {
356
361
  chain: "Bitcoin",
357
362
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
358
- retry_duration: data.fillOrKillParams.retry_duration
363
+ retry_duration: data.fillOrKillParams.retry_duration,
364
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
359
365
  };
360
366
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
361
367
  extraParams = {
@@ -499,10 +505,11 @@ var TransformedCcmParams = ccmParamsSchema.transform(
499
505
  })
500
506
  );
501
507
  var FillOrKillParams = fillOrKillParams.transform(
502
- ({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
508
+ ({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
503
509
  retry_duration: retryDurationBlocks,
504
510
  refund_address: refundAddress,
505
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
511
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
512
+ max_oracle_price_slippage: maxOraclePriceSlippage
506
513
  })
507
514
  );
508
515
  var TransformedDcaParams = dcaParams.transform(
@@ -524,7 +531,8 @@ var EncodeVaultSwapBody = z6.z.object({
524
531
  fillOrKillParams: FillOrKillParams,
525
532
  dcaParams: TransformedDcaParams.optional(),
526
533
  extraParams: z6.z.object({ seed: hexString.optional() }).optional(),
527
- network: z6.z.enum(chainflip.chainflipNetworks)
534
+ network: z6.z.enum(chainflip.chainflipNetworks),
535
+ brokerAccount: chainflipAddress.optional()
528
536
  }).superRefine(({ network, ...val }, ctx) => {
529
537
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
530
538
  ctx.addIssue({
@@ -554,7 +562,8 @@ var EncodeVaultSwapBody = z6.z.object({
554
562
  extraParams = {
555
563
  chain: "Bitcoin",
556
564
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
557
- retry_duration: data.fillOrKillParams.retry_duration
565
+ retry_duration: data.fillOrKillParams.retry_duration,
566
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
558
567
  };
559
568
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
560
569
  extraParams = {
@@ -641,7 +650,8 @@ var OpenSwapDepositChannelBody = z6.z.object({
641
650
  intermediateAmount: z6.z.string().optional(),
642
651
  egressAmount: z6.z.string(),
643
652
  estimatedPrice: z6.z.string(),
644
- recommendedSlippageTolerancePercent: z6.z.number().optional()
653
+ recommendedSlippageTolerancePercent: z6.z.number().optional(),
654
+ recommendedLivePriceSlippageTolerancePercent: z6.z.number().optional()
645
655
  }).optional(),
646
656
  takeCommission: z6.z.boolean().optional()
647
657
  }).transform(({ amount, ...rest }) => ({
@@ -737,7 +747,27 @@ var blocksPerMinute = 60 / consts.CHAINFLIP_BLOCK_TIME_SECONDS;
737
747
  function parseFoKParams(params, quote) {
738
748
  const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
739
749
  const destAsset = chainflip.getInternalAsset(quote.destAsset);
750
+ const livePriceProtectionDisabled = params.livePriceSlippageTolerancePercent === false;
751
+ const livePriceProtectionEnabled = typeof params.livePriceSlippageTolerancePercent === "string" || typeof params.livePriceSlippageTolerancePercent === "number";
752
+ const livePriceProtectionAvailable = isNotNullish(
753
+ quote.recommendedLivePriceSlippageTolerancePercent
754
+ );
755
+ if (livePriceProtectionEnabled && !livePriceProtectionAvailable) {
756
+ throw new Error("Live price protection is not available for this asset pair");
757
+ }
740
758
  let minPrice;
759
+ let livePriceSlippageTolerancePercent = null;
760
+ if (!livePriceProtectionDisabled) {
761
+ if (params.livePriceSlippageTolerancePercent) {
762
+ livePriceSlippageTolerancePercent = new BigNumber3__default.default(params.livePriceSlippageTolerancePercent);
763
+ assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
764
+ } else if (quote.recommendedLivePriceSlippageTolerancePercent) {
765
+ livePriceSlippageTolerancePercent = new BigNumber3__default.default(
766
+ quote.recommendedLivePriceSlippageTolerancePercent
767
+ );
768
+ assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
769
+ }
770
+ }
741
771
  if ("minPrice" in params) {
742
772
  assert(
743
773
  !("slippageTolerancePercent" in params),
@@ -759,9 +789,11 @@ function parseFoKParams(params, quote) {
759
789
  throw new Error("Either minPrice or slippageTolerancePercent must be provided");
760
790
  }
761
791
  const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
792
+ const maxOraclePriceSlippage = livePriceSlippageTolerancePercent?.multipliedBy(100).toNumber() ?? null;
762
793
  const parsed = {
763
794
  retryDurationBlocks,
764
- minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
795
+ minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
796
+ maxOraclePriceSlippage
765
797
  };
766
798
  return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
767
799
  }
@@ -935,7 +967,7 @@ var getChainData = (chain2, network, env) => ({
935
967
 
936
968
  // package.json
937
969
  var package_default = {
938
- version: "1.10.1"};
970
+ version: "1.11.0-beta.1"};
939
971
 
940
972
  // src/swap/consts.ts
941
973
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -1354,6 +1386,7 @@ var SwapSDK = class {
1354
1386
  }
1355
1387
  return res.body;
1356
1388
  }
1389
+ /** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
1357
1390
  // eslint-disable-next-line class-methods-use-this
1358
1391
  getOnChainSwapExtrinsicArgs({
1359
1392
  quote,
package/dist/swap.d.cts CHANGED
@@ -65,14 +65,17 @@ declare const fillOrKillParams: z.ZodObject<{
65
65
  retryDurationBlocks: z.ZodNumber;
66
66
  refundAddress: z.ZodString;
67
67
  minPriceX128: z.ZodString;
68
+ maxOraclePriceSlippage: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodNumber>>, number | null, number | null | undefined>;
68
69
  }, "strip", z.ZodTypeAny, {
69
70
  retryDurationBlocks: number;
70
71
  refundAddress: string;
71
72
  minPriceX128: string;
73
+ maxOraclePriceSlippage: number | null;
72
74
  }, {
73
75
  retryDurationBlocks: number;
74
76
  refundAddress: string;
75
77
  minPriceX128: string;
78
+ maxOraclePriceSlippage?: number | null | undefined;
76
79
  }>;
77
80
  type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
78
81
  type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
@@ -118,6 +121,7 @@ interface BaseQuoteDetails {
118
121
  estimatedPrice: string;
119
122
  recommendedSlippageTolerancePercent: number;
120
123
  recommendedRetryDurationMinutes: number;
124
+ recommendedLivePriceSlippageTolerancePercent: number | undefined;
121
125
  }
122
126
  type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
123
127
  interface RegularQuote extends BaseQuoteDetails {
@@ -134,6 +138,8 @@ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
134
138
  type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
135
139
  type BoostQuote = RegularBoostQuote | DCABoostQuote;
136
140
  type FillOrKillParamsWithoutRefundAddress = {
141
+ livePriceSlippageTolerancePercent?: string | number | false;
142
+ } & ({
137
143
  minPrice: string;
138
144
  retryDurationBlocks: number;
139
145
  } | {
@@ -145,8 +151,10 @@ type FillOrKillParamsWithoutRefundAddress = {
145
151
  } | {
146
152
  slippageTolerancePercent: string | number;
147
153
  retryDurationMinutes: number;
148
- };
154
+ });
149
155
  type FillOrKillParams = {
156
+ livePriceSlippageTolerancePercent?: string | number | false;
157
+ } & ({
150
158
  refundAddress: string;
151
159
  minPrice: string;
152
160
  retryDurationBlocks: number;
@@ -162,7 +170,7 @@ type FillOrKillParams = {
162
170
  refundAddress: string;
163
171
  slippageTolerancePercent: string | number;
164
172
  retryDurationMinutes: number;
165
- };
173
+ });
166
174
 
167
175
  interface ChainData {
168
176
  chain: ChainflipChain;
@@ -220,6 +228,7 @@ type BoostPoolDepth = {
220
228
  chain: ChainflipChain;
221
229
  };
222
230
 
231
+ type ChunkFailureReason = 'PriceImpactLimit' | 'MinPriceViolation' | 'OraclePriceSlippageExceeded' | 'OraclePriceStale' | 'PredecessorSwapFailure' | 'SafeModeActive';
223
232
  interface Failure {
224
233
  failedAt: number;
225
234
  failedBlockIndex: string;
@@ -278,6 +287,12 @@ type ChunkInfo = {
278
287
  executedAt: number | undefined;
279
288
  executedBlockIndex: string | undefined;
280
289
  retryCount: number;
290
+ rescheduledAt: number | undefined;
291
+ rescheduledBlockIndex: string | undefined;
292
+ rescheduledReason: ChunkFailureReason | undefined;
293
+ abortedAt: number | undefined;
294
+ abortedBlockIndex: string | undefined;
295
+ abortedReason: ChunkFailureReason | undefined;
281
296
  };
282
297
  type PickRequired<T> = {
283
298
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
@@ -288,6 +303,7 @@ interface SwapFields {
288
303
  swappedInputAmount: string;
289
304
  swappedIntermediateAmount: string;
290
305
  swappedOutputAmount: string;
306
+ livePriceExecutionDeltaPercentage: number | undefined;
291
307
  regular: ChunkInfo | undefined;
292
308
  dca: {
293
309
  lastExecutedChunk: ChunkInfo | null;
@@ -513,6 +529,7 @@ declare class SwapSDK {
513
529
  requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
514
530
  encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
515
531
  encodeCfParameters({ quote, srcAddress, destAddress, fillOrKillParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, }: EncodeCfParametersRequest): Promise<HexString>;
532
+ /** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
516
533
  getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
517
534
  quote: Quote;
518
535
  fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
package/dist/swap.d.ts CHANGED
@@ -65,14 +65,17 @@ declare const fillOrKillParams: z.ZodObject<{
65
65
  retryDurationBlocks: z.ZodNumber;
66
66
  refundAddress: z.ZodString;
67
67
  minPriceX128: z.ZodString;
68
+ maxOraclePriceSlippage: z.ZodEffects<z.ZodOptional<z.ZodNullable<z.ZodNumber>>, number | null, number | null | undefined>;
68
69
  }, "strip", z.ZodTypeAny, {
69
70
  retryDurationBlocks: number;
70
71
  refundAddress: string;
71
72
  minPriceX128: string;
73
+ maxOraclePriceSlippage: number | null;
72
74
  }, {
73
75
  retryDurationBlocks: number;
74
76
  refundAddress: string;
75
77
  minPriceX128: string;
78
+ maxOraclePriceSlippage?: number | null | undefined;
76
79
  }>;
77
80
  type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
78
81
  type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
@@ -118,6 +121,7 @@ interface BaseQuoteDetails {
118
121
  estimatedPrice: string;
119
122
  recommendedSlippageTolerancePercent: number;
120
123
  recommendedRetryDurationMinutes: number;
124
+ recommendedLivePriceSlippageTolerancePercent: number | undefined;
121
125
  }
122
126
  type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
123
127
  interface RegularQuote extends BaseQuoteDetails {
@@ -134,6 +138,8 @@ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
134
138
  type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
135
139
  type BoostQuote = RegularBoostQuote | DCABoostQuote;
136
140
  type FillOrKillParamsWithoutRefundAddress = {
141
+ livePriceSlippageTolerancePercent?: string | number | false;
142
+ } & ({
137
143
  minPrice: string;
138
144
  retryDurationBlocks: number;
139
145
  } | {
@@ -145,8 +151,10 @@ type FillOrKillParamsWithoutRefundAddress = {
145
151
  } | {
146
152
  slippageTolerancePercent: string | number;
147
153
  retryDurationMinutes: number;
148
- };
154
+ });
149
155
  type FillOrKillParams = {
156
+ livePriceSlippageTolerancePercent?: string | number | false;
157
+ } & ({
150
158
  refundAddress: string;
151
159
  minPrice: string;
152
160
  retryDurationBlocks: number;
@@ -162,7 +170,7 @@ type FillOrKillParams = {
162
170
  refundAddress: string;
163
171
  slippageTolerancePercent: string | number;
164
172
  retryDurationMinutes: number;
165
- };
173
+ });
166
174
 
167
175
  interface ChainData {
168
176
  chain: ChainflipChain;
@@ -220,6 +228,7 @@ type BoostPoolDepth = {
220
228
  chain: ChainflipChain;
221
229
  };
222
230
 
231
+ type ChunkFailureReason = 'PriceImpactLimit' | 'MinPriceViolation' | 'OraclePriceSlippageExceeded' | 'OraclePriceStale' | 'PredecessorSwapFailure' | 'SafeModeActive';
223
232
  interface Failure {
224
233
  failedAt: number;
225
234
  failedBlockIndex: string;
@@ -278,6 +287,12 @@ type ChunkInfo = {
278
287
  executedAt: number | undefined;
279
288
  executedBlockIndex: string | undefined;
280
289
  retryCount: number;
290
+ rescheduledAt: number | undefined;
291
+ rescheduledBlockIndex: string | undefined;
292
+ rescheduledReason: ChunkFailureReason | undefined;
293
+ abortedAt: number | undefined;
294
+ abortedBlockIndex: string | undefined;
295
+ abortedReason: ChunkFailureReason | undefined;
281
296
  };
282
297
  type PickRequired<T> = {
283
298
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
@@ -288,6 +303,7 @@ interface SwapFields {
288
303
  swappedInputAmount: string;
289
304
  swappedIntermediateAmount: string;
290
305
  swappedOutputAmount: string;
306
+ livePriceExecutionDeltaPercentage: number | undefined;
291
307
  regular: ChunkInfo | undefined;
292
308
  dca: {
293
309
  lastExecutedChunk: ChunkInfo | null;
@@ -513,6 +529,7 @@ declare class SwapSDK {
513
529
  requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
514
530
  encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
515
531
  encodeCfParameters({ quote, srcAddress, destAddress, fillOrKillParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, }: EncodeCfParametersRequest): Promise<HexString>;
532
+ /** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
516
533
  getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
517
534
  quote: Quote;
518
535
  fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
package/dist/swap.js CHANGED
@@ -42,6 +42,7 @@ var hexString = z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
42
42
  var hexStringWithMaxByteSize = (maxByteSize) => hexString.refine((val) => val.length / 2 <= maxByteSize + 1, {
43
43
  message: `String must be less than or equal to ${maxByteSize} bytes`
44
44
  });
45
+ var basisPoints = z.number().int({ message: "must be in basis points" });
45
46
  var DOT_PREFIX = 0;
46
47
  var chainflipAddress = z.string().refine(
47
48
  (address) => address.startsWith("cF") && ss58.decode(address),
@@ -163,7 +164,8 @@ var dcaParams = z.object({
163
164
  var fillOrKillParams = z.object({
164
165
  retryDurationBlocks: z.number(),
165
166
  refundAddress: z.string(),
166
- minPriceX128: numericString
167
+ minPriceX128: numericString,
168
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
167
169
  });
168
170
  var validatePolkadotAddress = (address) => {
169
171
  if (isHex(address)) return address.length === 66;
@@ -227,11 +229,13 @@ var validateAddress = (chain2, address, network) => validators[network][chain2](
227
229
  var transformedFokSchema = z.object({
228
230
  retryDurationBlocks: z.number(),
229
231
  refundAddress: z.string(),
230
- minPriceX128: numericString
231
- }).transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
232
+ minPriceX128: numericString,
233
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
234
+ }).transform(({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
232
235
  retry_duration: retryDurationBlocks,
233
236
  refund_address: refundAddress,
234
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
237
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
238
+ max_oracle_price_slippage: maxOraclePriceSlippage
235
239
  }));
236
240
  var transformedDcaParamsSchema = dcaParams.transform(
237
241
  ({ numberOfChunks, chunkIntervalBlocks }) => ({
@@ -285,7 +289,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
285
289
  affiliates: z.array(affiliateBroker).optional(),
286
290
  fillOrKillParams: transformedFokSchema,
287
291
  dcaParams: transformedDcaParamsSchema.optional(),
288
- extraParams: z.object({ seed: hexString.optional() }).optional()
292
+ extraParams: z.object({ seed: hexString.optional() }).optional(),
293
+ brokerAccount: chainflipAddress.optional()
289
294
  }).superRefine((val, ctx) => {
290
295
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
291
296
  ctx.addIssue({
@@ -315,7 +320,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
315
320
  extraParams = {
316
321
  chain: "Bitcoin",
317
322
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
318
- retry_duration: data.fillOrKillParams.retry_duration
323
+ retry_duration: data.fillOrKillParams.retry_duration,
324
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
319
325
  };
320
326
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
321
327
  extraParams = {
@@ -459,10 +465,11 @@ var TransformedCcmParams = ccmParamsSchema.transform(
459
465
  })
460
466
  );
461
467
  var FillOrKillParams = fillOrKillParams.transform(
462
- ({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
468
+ ({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
463
469
  retry_duration: retryDurationBlocks,
464
470
  refund_address: refundAddress,
465
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
471
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
472
+ max_oracle_price_slippage: maxOraclePriceSlippage
466
473
  })
467
474
  );
468
475
  var TransformedDcaParams = dcaParams.transform(
@@ -484,7 +491,8 @@ var EncodeVaultSwapBody = z.object({
484
491
  fillOrKillParams: FillOrKillParams,
485
492
  dcaParams: TransformedDcaParams.optional(),
486
493
  extraParams: z.object({ seed: hexString.optional() }).optional(),
487
- network: z.enum(chainflipNetworks)
494
+ network: z.enum(chainflipNetworks),
495
+ brokerAccount: chainflipAddress.optional()
488
496
  }).superRefine(({ network, ...val }, ctx) => {
489
497
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
490
498
  ctx.addIssue({
@@ -514,7 +522,8 @@ var EncodeVaultSwapBody = z.object({
514
522
  extraParams = {
515
523
  chain: "Bitcoin",
516
524
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
517
- retry_duration: data.fillOrKillParams.retry_duration
525
+ retry_duration: data.fillOrKillParams.retry_duration,
526
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
518
527
  };
519
528
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
520
529
  extraParams = {
@@ -601,7 +610,8 @@ var OpenSwapDepositChannelBody = z.object({
601
610
  intermediateAmount: z.string().optional(),
602
611
  egressAmount: z.string(),
603
612
  estimatedPrice: z.string(),
604
- recommendedSlippageTolerancePercent: z.number().optional()
613
+ recommendedSlippageTolerancePercent: z.number().optional(),
614
+ recommendedLivePriceSlippageTolerancePercent: z.number().optional()
605
615
  }).optional(),
606
616
  takeCommission: z.boolean().optional()
607
617
  }).transform(({ amount, ...rest }) => ({
@@ -697,7 +707,27 @@ var blocksPerMinute = 60 / CHAINFLIP_BLOCK_TIME_SECONDS;
697
707
  function parseFoKParams(params, quote) {
698
708
  const srcAsset = getInternalAsset(quote.srcAsset);
699
709
  const destAsset = getInternalAsset(quote.destAsset);
710
+ const livePriceProtectionDisabled = params.livePriceSlippageTolerancePercent === false;
711
+ const livePriceProtectionEnabled = typeof params.livePriceSlippageTolerancePercent === "string" || typeof params.livePriceSlippageTolerancePercent === "number";
712
+ const livePriceProtectionAvailable = isNotNullish(
713
+ quote.recommendedLivePriceSlippageTolerancePercent
714
+ );
715
+ if (livePriceProtectionEnabled && !livePriceProtectionAvailable) {
716
+ throw new Error("Live price protection is not available for this asset pair");
717
+ }
700
718
  let minPrice;
719
+ let livePriceSlippageTolerancePercent = null;
720
+ if (!livePriceProtectionDisabled) {
721
+ if (params.livePriceSlippageTolerancePercent) {
722
+ livePriceSlippageTolerancePercent = new BigNumber3(params.livePriceSlippageTolerancePercent);
723
+ assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
724
+ } else if (quote.recommendedLivePriceSlippageTolerancePercent) {
725
+ livePriceSlippageTolerancePercent = new BigNumber3(
726
+ quote.recommendedLivePriceSlippageTolerancePercent
727
+ );
728
+ assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
729
+ }
730
+ }
701
731
  if ("minPrice" in params) {
702
732
  assert(
703
733
  !("slippageTolerancePercent" in params),
@@ -719,9 +749,11 @@ function parseFoKParams(params, quote) {
719
749
  throw new Error("Either minPrice or slippageTolerancePercent must be provided");
720
750
  }
721
751
  const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
752
+ const maxOraclePriceSlippage = livePriceSlippageTolerancePercent?.multipliedBy(100).toNumber() ?? null;
722
753
  const parsed = {
723
754
  retryDurationBlocks,
724
- minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
755
+ minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
756
+ maxOraclePriceSlippage
725
757
  };
726
758
  return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
727
759
  }
@@ -803,7 +835,7 @@ var getChainData = (chain2, network, env) => ({
803
835
 
804
836
  // package.json
805
837
  var package_default = {
806
- version: "1.10.1"};
838
+ version: "1.11.0-beta.1"};
807
839
 
808
840
  // src/swap/consts.ts
809
841
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -1222,6 +1254,7 @@ var SwapSDK = class {
1222
1254
  }
1223
1255
  return res.body;
1224
1256
  }
1257
+ /** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
1225
1258
  // eslint-disable-next-line class-methods-use-this
1226
1259
  getOnChainSwapExtrinsicArgs({
1227
1260
  quote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.10.1",
3
+ "version": "1.11.0-beta.1",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -55,7 +55,7 @@
55
55
  "@chainflip/bitcoin": "^1.2.6",
56
56
  "@chainflip/rpc": "~1.11.0-beta.3",
57
57
  "@chainflip/solana": "^2.1.9",
58
- "@chainflip/utils": "^0.8.11",
58
+ "@chainflip/utils": "^0.8.19",
59
59
  "@ts-rest/core": "^3.52.1",
60
60
  "axios": "^1.10.0",
61
61
  "bignumber.js": "^9.3.0",