@chainflip/sdk 1.10.0 → 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
@@ -14,6 +14,7 @@ var solana = require('@chainflip/solana');
14
14
  var number = require('@chainflip/utils/number');
15
15
  var bitcoin = require('@chainflip/bitcoin');
16
16
  var ethers = require('ethers');
17
+ var consts = require('@chainflip/utils/consts');
17
18
  var axios = require('axios');
18
19
 
19
20
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -81,6 +82,7 @@ var hexString = z6.z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
81
82
  var hexStringWithMaxByteSize = (maxByteSize) => hexString.refine((val) => val.length / 2 <= maxByteSize + 1, {
82
83
  message: `String must be less than or equal to ${maxByteSize} bytes`
83
84
  });
85
+ var basisPoints = z6.z.number().int({ message: "must be in basis points" });
84
86
  var DOT_PREFIX = 0;
85
87
  var chainflipAddress = z6.z.string().refine(
86
88
  (address) => address.startsWith("cF") && ss58__namespace.decode(address),
@@ -189,7 +191,7 @@ var ccmParamsSchema = z6.z.object({
189
191
  }).transform(({ gasBudget, message, ccmAdditionalData, cfParameters }) => ({
190
192
  gasBudget,
191
193
  message,
192
- ccmAdditionalData: ccmAdditionalData ?? cfParameters
194
+ ccmAdditionalData: ccmAdditionalData ?? cfParameters ?? "0x"
193
195
  }));
194
196
  var affiliateBroker = z6.z.object({
195
197
  account: chainflipAddress,
@@ -202,7 +204,8 @@ var dcaParams = z6.z.object({
202
204
  var fillOrKillParams = z6.z.object({
203
205
  retryDurationBlocks: z6.z.number(),
204
206
  refundAddress: z6.z.string(),
205
- minPriceX128: numericString
207
+ minPriceX128: numericString,
208
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
206
209
  });
207
210
  var validatePolkadotAddress = (address) => {
208
211
  if (string.isHex(address)) return address.length === 66;
@@ -266,11 +269,13 @@ var validateAddress = (chain2, address, network) => validators[network][chain2](
266
269
  var transformedFokSchema = z6.z.object({
267
270
  retryDurationBlocks: z6.z.number(),
268
271
  refundAddress: z6.z.string(),
269
- minPriceX128: numericString
270
- }).transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
272
+ minPriceX128: numericString,
273
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
274
+ }).transform(({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
271
275
  retry_duration: retryDurationBlocks,
272
276
  refund_address: refundAddress,
273
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
277
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
278
+ max_oracle_price_slippage: maxOraclePriceSlippage
274
279
  }));
275
280
  var transformedDcaParamsSchema = dcaParams.transform(
276
281
  ({ numberOfChunks, chunkIntervalBlocks }) => ({
@@ -324,7 +329,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z6.z.object({
324
329
  affiliates: z6.z.array(affiliateBroker).optional(),
325
330
  fillOrKillParams: transformedFokSchema,
326
331
  dcaParams: transformedDcaParamsSchema.optional(),
327
- extraParams: z6.z.object({ seed: hexString.optional() }).optional()
332
+ extraParams: z6.z.object({ seed: hexString.optional() }).optional(),
333
+ brokerAccount: chainflipAddress.optional()
328
334
  }).superRefine((val, ctx) => {
329
335
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
330
336
  ctx.addIssue({
@@ -354,7 +360,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z6.z.object({
354
360
  extraParams = {
355
361
  chain: "Bitcoin",
356
362
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
357
- retry_duration: data.fillOrKillParams.retry_duration
363
+ retry_duration: data.fillOrKillParams.retry_duration,
364
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
358
365
  };
359
366
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
360
367
  extraParams = {
@@ -498,10 +505,11 @@ var TransformedCcmParams = ccmParamsSchema.transform(
498
505
  })
499
506
  );
500
507
  var FillOrKillParams = fillOrKillParams.transform(
501
- ({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
508
+ ({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
502
509
  retry_duration: retryDurationBlocks,
503
510
  refund_address: refundAddress,
504
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
511
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
512
+ max_oracle_price_slippage: maxOraclePriceSlippage
505
513
  })
506
514
  );
507
515
  var TransformedDcaParams = dcaParams.transform(
@@ -523,7 +531,8 @@ var EncodeVaultSwapBody = z6.z.object({
523
531
  fillOrKillParams: FillOrKillParams,
524
532
  dcaParams: TransformedDcaParams.optional(),
525
533
  extraParams: z6.z.object({ seed: hexString.optional() }).optional(),
526
- network: z6.z.enum(chainflip.chainflipNetworks)
534
+ network: z6.z.enum(chainflip.chainflipNetworks),
535
+ brokerAccount: chainflipAddress.optional()
527
536
  }).superRefine(({ network, ...val }, ctx) => {
528
537
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
529
538
  ctx.addIssue({
@@ -553,7 +562,8 @@ var EncodeVaultSwapBody = z6.z.object({
553
562
  extraParams = {
554
563
  chain: "Bitcoin",
555
564
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
556
- retry_duration: data.fillOrKillParams.retry_duration
565
+ retry_duration: data.fillOrKillParams.retry_duration,
566
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
557
567
  };
558
568
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
559
569
  extraParams = {
@@ -640,7 +650,8 @@ var OpenSwapDepositChannelBody = z6.z.object({
640
650
  intermediateAmount: z6.z.string().optional(),
641
651
  egressAmount: z6.z.string(),
642
652
  estimatedPrice: z6.z.string(),
643
- recommendedSlippageTolerancePercent: z6.z.number().optional()
653
+ recommendedSlippageTolerancePercent: z6.z.number().optional(),
654
+ recommendedLivePriceSlippageTolerancePercent: z6.z.number().optional()
644
655
  }).optional(),
645
656
  takeCommission: z6.z.boolean().optional()
646
657
  }).transform(({ amount, ...rest }) => ({
@@ -732,10 +743,31 @@ var MultiCache = class {
732
743
  }
733
744
  };
734
745
  var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber3__default.default(price).multipliedBy(new BigNumber3__default.default(2).pow(128)).shiftedBy(chainflip.assetConstants[destAsset].decimals - chainflip.assetConstants[srcAsset].decimals).toFixed(0);
746
+ var blocksPerMinute = 60 / consts.CHAINFLIP_BLOCK_TIME_SECONDS;
735
747
  function parseFoKParams(params, quote) {
736
748
  const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
737
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
+ }
738
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
+ }
739
771
  if ("minPrice" in params) {
740
772
  assert(
741
773
  !("slippageTolerancePercent" in params),
@@ -756,11 +788,14 @@ function parseFoKParams(params, quote) {
756
788
  } else {
757
789
  throw new Error("Either minPrice or slippageTolerancePercent must be provided");
758
790
  }
759
- return {
760
- refundAddress: params.refundAddress,
761
- retryDurationBlocks: params.retryDurationBlocks,
762
- minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
791
+ const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
792
+ const maxOraclePriceSlippage = livePriceSlippageTolerancePercent?.multipliedBy(100).toNumber() ?? null;
793
+ const parsed = {
794
+ retryDurationBlocks,
795
+ minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
796
+ maxOraclePriceSlippage
763
797
  };
798
+ return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
764
799
  }
765
800
  var isTestnet = (network) => network !== "mainnet";
766
801
  var camelCase = (str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
@@ -932,7 +967,7 @@ var getChainData = (chain2, network, env) => ({
932
967
 
933
968
  // package.json
934
969
  var package_default = {
935
- version: "1.10.0"};
970
+ version: "1.11.0-beta.1"};
936
971
 
937
972
  // src/swap/consts.ts
938
973
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -1351,6 +1386,7 @@ var SwapSDK = class {
1351
1386
  }
1352
1387
  return res.body;
1353
1388
  }
1389
+ /** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
1354
1390
  // eslint-disable-next-line class-methods-use-this
1355
1391
  getOnChainSwapExtrinsicArgs({
1356
1392
  quote,
package/dist/swap.d.cts CHANGED
@@ -22,7 +22,7 @@ declare const ccmParamsSchema: z.ZodEffects<z.ZodObject<{
22
22
  }>, {
23
23
  gasBudget: `0x${string}`;
24
24
  message: `0x${string}`;
25
- ccmAdditionalData: `0x${string}` | undefined;
25
+ ccmAdditionalData: `0x${string}`;
26
26
  }, {
27
27
  message: string;
28
28
  gasBudget: string;
@@ -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'> & {
@@ -117,6 +120,8 @@ interface BaseQuoteDetails {
117
120
  };
118
121
  estimatedPrice: string;
119
122
  recommendedSlippageTolerancePercent: number;
123
+ recommendedRetryDurationMinutes: number;
124
+ recommendedLivePriceSlippageTolerancePercent: number | undefined;
120
125
  }
121
126
  type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
122
127
  interface RegularQuote extends BaseQuoteDetails {
@@ -132,9 +137,40 @@ type Quote = RegularQuote | DCAQuote;
132
137
  type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
133
138
  type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
134
139
  type BoostQuote = RegularBoostQuote | DCABoostQuote;
135
- type FillOrKillParamsWithSlippage$1 = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
140
+ type FillOrKillParamsWithoutRefundAddress = {
141
+ livePriceSlippageTolerancePercent?: string | number | false;
142
+ } & ({
143
+ minPrice: string;
144
+ retryDurationBlocks: number;
145
+ } | {
146
+ minPrice: string;
147
+ retryDurationMinutes: number;
148
+ } | {
136
149
  slippageTolerancePercent: string | number;
137
- };
150
+ retryDurationBlocks: number;
151
+ } | {
152
+ slippageTolerancePercent: string | number;
153
+ retryDurationMinutes: number;
154
+ });
155
+ type FillOrKillParams = {
156
+ livePriceSlippageTolerancePercent?: string | number | false;
157
+ } & ({
158
+ refundAddress: string;
159
+ minPrice: string;
160
+ retryDurationBlocks: number;
161
+ } | {
162
+ refundAddress: string;
163
+ minPrice: string;
164
+ retryDurationMinutes: number;
165
+ } | {
166
+ refundAddress: string;
167
+ slippageTolerancePercent: string | number;
168
+ retryDurationBlocks: number;
169
+ } | {
170
+ refundAddress: string;
171
+ slippageTolerancePercent: string | number;
172
+ retryDurationMinutes: number;
173
+ });
138
174
 
139
175
  interface ChainData {
140
176
  chain: ChainflipChain;
@@ -192,6 +228,7 @@ type BoostPoolDepth = {
192
228
  chain: ChainflipChain;
193
229
  };
194
230
 
231
+ type ChunkFailureReason = 'PriceImpactLimit' | 'MinPriceViolation' | 'OraclePriceSlippageExceeded' | 'OraclePriceStale' | 'PredecessorSwapFailure' | 'SafeModeActive';
195
232
  interface Failure {
196
233
  failedAt: number;
197
234
  failedBlockIndex: string;
@@ -250,6 +287,12 @@ type ChunkInfo = {
250
287
  executedAt: number | undefined;
251
288
  executedBlockIndex: string | undefined;
252
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;
253
296
  };
254
297
  type PickRequired<T> = {
255
298
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
@@ -260,6 +303,7 @@ interface SwapFields {
260
303
  swappedInputAmount: string;
261
304
  swappedIntermediateAmount: string;
262
305
  swappedOutputAmount: string;
306
+ livePriceExecutionDeltaPercentage: number | undefined;
263
307
  regular: ChunkInfo | undefined;
264
308
  dca: {
265
309
  lastExecutedChunk: ChunkInfo | null;
@@ -363,7 +407,7 @@ interface DepositAddressRequestV2 {
363
407
  quote: Quote | BoostQuote;
364
408
  srcAddress?: string;
365
409
  destAddress: string;
366
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
410
+ fillOrKillParams: FillOrKillParams;
367
411
  affiliateBrokers?: {
368
412
  account: `cF${string}` | `0x${string}`;
369
413
  commissionBps: number;
@@ -377,7 +421,7 @@ interface DepositAddressResponseV2 extends Omit<QuoteRequest, 'ccmParams'> {
377
421
  maxBoostFeeBps?: number;
378
422
  srcAddress?: string;
379
423
  dcaParams?: DcaParams;
380
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
424
+ fillOrKillParams: FillOrKillParams;
381
425
  depositChannelId: string;
382
426
  depositAddress: string;
383
427
  brokerCommissionBps: number;
@@ -390,7 +434,7 @@ interface VaultSwapRequest {
390
434
  quote: Quote | BoostQuote;
391
435
  srcAddress?: string;
392
436
  destAddress: string;
393
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
437
+ fillOrKillParams: FillOrKillParams;
394
438
  affiliateBrokers?: {
395
439
  account: `cF${string}` | `0x${string}`;
396
440
  commissionBps: number;
@@ -426,7 +470,7 @@ interface EncodeCfParametersRequest {
426
470
  quote: Quote | BoostQuote;
427
471
  srcAddress?: string;
428
472
  destAddress: string;
429
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
473
+ fillOrKillParams: FillOrKillParams;
430
474
  affiliateBrokers?: {
431
475
  account: `cF${string}` | `0x${string}`;
432
476
  commissionBps: number;
@@ -485,9 +529,10 @@ declare class SwapSDK {
485
529
  requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
486
530
  encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
487
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 */
488
533
  getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
489
534
  quote: Quote;
490
- fillOrKillParams: Omit<FillOrKillParamsWithMinPrice, 'refundAddress'> | Omit<FillOrKillParamsWithSlippage, 'refundAddress'>;
535
+ fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
491
536
  }): [
492
537
  amount: string,
493
538
  inputAsset: ChainflipAsset,
package/dist/swap.d.ts CHANGED
@@ -22,7 +22,7 @@ declare const ccmParamsSchema: z.ZodEffects<z.ZodObject<{
22
22
  }>, {
23
23
  gasBudget: `0x${string}`;
24
24
  message: `0x${string}`;
25
- ccmAdditionalData: `0x${string}` | undefined;
25
+ ccmAdditionalData: `0x${string}`;
26
26
  }, {
27
27
  message: string;
28
28
  gasBudget: string;
@@ -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'> & {
@@ -117,6 +120,8 @@ interface BaseQuoteDetails {
117
120
  };
118
121
  estimatedPrice: string;
119
122
  recommendedSlippageTolerancePercent: number;
123
+ recommendedRetryDurationMinutes: number;
124
+ recommendedLivePriceSlippageTolerancePercent: number | undefined;
120
125
  }
121
126
  type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
122
127
  interface RegularQuote extends BaseQuoteDetails {
@@ -132,9 +137,40 @@ type Quote = RegularQuote | DCAQuote;
132
137
  type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
133
138
  type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
134
139
  type BoostQuote = RegularBoostQuote | DCABoostQuote;
135
- type FillOrKillParamsWithSlippage$1 = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
140
+ type FillOrKillParamsWithoutRefundAddress = {
141
+ livePriceSlippageTolerancePercent?: string | number | false;
142
+ } & ({
143
+ minPrice: string;
144
+ retryDurationBlocks: number;
145
+ } | {
146
+ minPrice: string;
147
+ retryDurationMinutes: number;
148
+ } | {
136
149
  slippageTolerancePercent: string | number;
137
- };
150
+ retryDurationBlocks: number;
151
+ } | {
152
+ slippageTolerancePercent: string | number;
153
+ retryDurationMinutes: number;
154
+ });
155
+ type FillOrKillParams = {
156
+ livePriceSlippageTolerancePercent?: string | number | false;
157
+ } & ({
158
+ refundAddress: string;
159
+ minPrice: string;
160
+ retryDurationBlocks: number;
161
+ } | {
162
+ refundAddress: string;
163
+ minPrice: string;
164
+ retryDurationMinutes: number;
165
+ } | {
166
+ refundAddress: string;
167
+ slippageTolerancePercent: string | number;
168
+ retryDurationBlocks: number;
169
+ } | {
170
+ refundAddress: string;
171
+ slippageTolerancePercent: string | number;
172
+ retryDurationMinutes: number;
173
+ });
138
174
 
139
175
  interface ChainData {
140
176
  chain: ChainflipChain;
@@ -192,6 +228,7 @@ type BoostPoolDepth = {
192
228
  chain: ChainflipChain;
193
229
  };
194
230
 
231
+ type ChunkFailureReason = 'PriceImpactLimit' | 'MinPriceViolation' | 'OraclePriceSlippageExceeded' | 'OraclePriceStale' | 'PredecessorSwapFailure' | 'SafeModeActive';
195
232
  interface Failure {
196
233
  failedAt: number;
197
234
  failedBlockIndex: string;
@@ -250,6 +287,12 @@ type ChunkInfo = {
250
287
  executedAt: number | undefined;
251
288
  executedBlockIndex: string | undefined;
252
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;
253
296
  };
254
297
  type PickRequired<T> = {
255
298
  [K in keyof T as undefined extends T[K] ? never : K]: T[K];
@@ -260,6 +303,7 @@ interface SwapFields {
260
303
  swappedInputAmount: string;
261
304
  swappedIntermediateAmount: string;
262
305
  swappedOutputAmount: string;
306
+ livePriceExecutionDeltaPercentage: number | undefined;
263
307
  regular: ChunkInfo | undefined;
264
308
  dca: {
265
309
  lastExecutedChunk: ChunkInfo | null;
@@ -363,7 +407,7 @@ interface DepositAddressRequestV2 {
363
407
  quote: Quote | BoostQuote;
364
408
  srcAddress?: string;
365
409
  destAddress: string;
366
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
410
+ fillOrKillParams: FillOrKillParams;
367
411
  affiliateBrokers?: {
368
412
  account: `cF${string}` | `0x${string}`;
369
413
  commissionBps: number;
@@ -377,7 +421,7 @@ interface DepositAddressResponseV2 extends Omit<QuoteRequest, 'ccmParams'> {
377
421
  maxBoostFeeBps?: number;
378
422
  srcAddress?: string;
379
423
  dcaParams?: DcaParams;
380
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
424
+ fillOrKillParams: FillOrKillParams;
381
425
  depositChannelId: string;
382
426
  depositAddress: string;
383
427
  brokerCommissionBps: number;
@@ -390,7 +434,7 @@ interface VaultSwapRequest {
390
434
  quote: Quote | BoostQuote;
391
435
  srcAddress?: string;
392
436
  destAddress: string;
393
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
437
+ fillOrKillParams: FillOrKillParams;
394
438
  affiliateBrokers?: {
395
439
  account: `cF${string}` | `0x${string}`;
396
440
  commissionBps: number;
@@ -426,7 +470,7 @@ interface EncodeCfParametersRequest {
426
470
  quote: Quote | BoostQuote;
427
471
  srcAddress?: string;
428
472
  destAddress: string;
429
- fillOrKillParams: FillOrKillParamsWithMinPrice | FillOrKillParamsWithSlippage$1;
473
+ fillOrKillParams: FillOrKillParams;
430
474
  affiliateBrokers?: {
431
475
  account: `cF${string}` | `0x${string}`;
432
476
  commissionBps: number;
@@ -485,9 +529,10 @@ declare class SwapSDK {
485
529
  requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
486
530
  encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
487
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 */
488
533
  getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
489
534
  quote: Quote;
490
- fillOrKillParams: Omit<FillOrKillParamsWithMinPrice, 'refundAddress'> | Omit<FillOrKillParamsWithSlippage, 'refundAddress'>;
535
+ fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
491
536
  }): [
492
537
  amount: string,
493
538
  inputAsset: ChainflipAsset,
package/dist/swap.js CHANGED
@@ -14,6 +14,7 @@ import { isValidSolanaAddress } from '@chainflip/solana';
14
14
  import { hexEncodeNumber } from '@chainflip/utils/number';
15
15
  import * as bitcoin from '@chainflip/bitcoin';
16
16
  import * as ethers from 'ethers';
17
+ import { CHAINFLIP_BLOCK_TIME_SECONDS } from '@chainflip/utils/consts';
17
18
  import axios from 'axios';
18
19
 
19
20
  // ../shared/src/strings.ts
@@ -41,6 +42,7 @@ var hexString = z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
41
42
  var hexStringWithMaxByteSize = (maxByteSize) => hexString.refine((val) => val.length / 2 <= maxByteSize + 1, {
42
43
  message: `String must be less than or equal to ${maxByteSize} bytes`
43
44
  });
45
+ var basisPoints = z.number().int({ message: "must be in basis points" });
44
46
  var DOT_PREFIX = 0;
45
47
  var chainflipAddress = z.string().refine(
46
48
  (address) => address.startsWith("cF") && ss58.decode(address),
@@ -149,7 +151,7 @@ var ccmParamsSchema = z.object({
149
151
  }).transform(({ gasBudget, message, ccmAdditionalData, cfParameters }) => ({
150
152
  gasBudget,
151
153
  message,
152
- ccmAdditionalData: ccmAdditionalData ?? cfParameters
154
+ ccmAdditionalData: ccmAdditionalData ?? cfParameters ?? "0x"
153
155
  }));
154
156
  var affiliateBroker = z.object({
155
157
  account: chainflipAddress,
@@ -162,7 +164,8 @@ var dcaParams = z.object({
162
164
  var fillOrKillParams = z.object({
163
165
  retryDurationBlocks: z.number(),
164
166
  refundAddress: z.string(),
165
- minPriceX128: numericString
167
+ minPriceX128: numericString,
168
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
166
169
  });
167
170
  var validatePolkadotAddress = (address) => {
168
171
  if (isHex(address)) return address.length === 66;
@@ -226,11 +229,13 @@ var validateAddress = (chain2, address, network) => validators[network][chain2](
226
229
  var transformedFokSchema = z.object({
227
230
  retryDurationBlocks: z.number(),
228
231
  refundAddress: z.string(),
229
- minPriceX128: numericString
230
- }).transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
232
+ minPriceX128: numericString,
233
+ maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null)
234
+ }).transform(({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
231
235
  retry_duration: retryDurationBlocks,
232
236
  refund_address: refundAddress,
233
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
237
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
238
+ max_oracle_price_slippage: maxOraclePriceSlippage
234
239
  }));
235
240
  var transformedDcaParamsSchema = dcaParams.transform(
236
241
  ({ numberOfChunks, chunkIntervalBlocks }) => ({
@@ -284,7 +289,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
284
289
  affiliates: z.array(affiliateBroker).optional(),
285
290
  fillOrKillParams: transformedFokSchema,
286
291
  dcaParams: transformedDcaParamsSchema.optional(),
287
- extraParams: z.object({ seed: hexString.optional() }).optional()
292
+ extraParams: z.object({ seed: hexString.optional() }).optional(),
293
+ brokerAccount: chainflipAddress.optional()
288
294
  }).superRefine((val, ctx) => {
289
295
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
290
296
  ctx.addIssue({
@@ -314,7 +320,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
314
320
  extraParams = {
315
321
  chain: "Bitcoin",
316
322
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
317
- retry_duration: data.fillOrKillParams.retry_duration
323
+ retry_duration: data.fillOrKillParams.retry_duration,
324
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
318
325
  };
319
326
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
320
327
  extraParams = {
@@ -458,10 +465,11 @@ var TransformedCcmParams = ccmParamsSchema.transform(
458
465
  })
459
466
  );
460
467
  var FillOrKillParams = fillOrKillParams.transform(
461
- ({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
468
+ ({ retryDurationBlocks, refundAddress, minPriceX128, maxOraclePriceSlippage }) => ({
462
469
  retry_duration: retryDurationBlocks,
463
470
  refund_address: refundAddress,
464
- min_price: `0x${BigInt(minPriceX128).toString(16)}`
471
+ min_price: `0x${BigInt(minPriceX128).toString(16)}`,
472
+ max_oracle_price_slippage: maxOraclePriceSlippage
465
473
  })
466
474
  );
467
475
  var TransformedDcaParams = dcaParams.transform(
@@ -483,7 +491,8 @@ var EncodeVaultSwapBody = z.object({
483
491
  fillOrKillParams: FillOrKillParams,
484
492
  dcaParams: TransformedDcaParams.optional(),
485
493
  extraParams: z.object({ seed: hexString.optional() }).optional(),
486
- network: z.enum(chainflipNetworks)
494
+ network: z.enum(chainflipNetworks),
495
+ brokerAccount: chainflipAddress.optional()
487
496
  }).superRefine(({ network, ...val }, ctx) => {
488
497
  if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
489
498
  ctx.addIssue({
@@ -513,7 +522,8 @@ var EncodeVaultSwapBody = z.object({
513
522
  extraParams = {
514
523
  chain: "Bitcoin",
515
524
  min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
516
- retry_duration: data.fillOrKillParams.retry_duration
525
+ retry_duration: data.fillOrKillParams.retry_duration,
526
+ max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
517
527
  };
518
528
  } else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
519
529
  extraParams = {
@@ -600,7 +610,8 @@ var OpenSwapDepositChannelBody = z.object({
600
610
  intermediateAmount: z.string().optional(),
601
611
  egressAmount: z.string(),
602
612
  estimatedPrice: z.string(),
603
- recommendedSlippageTolerancePercent: z.number().optional()
613
+ recommendedSlippageTolerancePercent: z.number().optional(),
614
+ recommendedLivePriceSlippageTolerancePercent: z.number().optional()
604
615
  }).optional(),
605
616
  takeCommission: z.boolean().optional()
606
617
  }).transform(({ amount, ...rest }) => ({
@@ -692,10 +703,31 @@ var MultiCache = class {
692
703
  }
693
704
  };
694
705
  var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber3(price).multipliedBy(new BigNumber3(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
706
+ var blocksPerMinute = 60 / CHAINFLIP_BLOCK_TIME_SECONDS;
695
707
  function parseFoKParams(params, quote) {
696
708
  const srcAsset = getInternalAsset(quote.srcAsset);
697
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
+ }
698
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
+ }
699
731
  if ("minPrice" in params) {
700
732
  assert(
701
733
  !("slippageTolerancePercent" in params),
@@ -716,11 +748,14 @@ function parseFoKParams(params, quote) {
716
748
  } else {
717
749
  throw new Error("Either minPrice or slippageTolerancePercent must be provided");
718
750
  }
719
- return {
720
- refundAddress: params.refundAddress,
721
- retryDurationBlocks: params.retryDurationBlocks,
722
- minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
751
+ const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
752
+ const maxOraclePriceSlippage = livePriceSlippageTolerancePercent?.multipliedBy(100).toNumber() ?? null;
753
+ const parsed = {
754
+ retryDurationBlocks,
755
+ minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
756
+ maxOraclePriceSlippage
723
757
  };
758
+ return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
724
759
  }
725
760
  var isTestnet = (network) => network !== "mainnet";
726
761
  var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
@@ -800,7 +835,7 @@ var getChainData = (chain2, network, env) => ({
800
835
 
801
836
  // package.json
802
837
  var package_default = {
803
- version: "1.10.0"};
838
+ version: "1.11.0-beta.1"};
804
839
 
805
840
  // src/swap/consts.ts
806
841
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -1219,6 +1254,7 @@ var SwapSDK = class {
1219
1254
  }
1220
1255
  return res.body;
1221
1256
  }
1257
+ /** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
1222
1258
  // eslint-disable-next-line class-methods-use-this
1223
1259
  getOnChainSwapExtrinsicArgs({
1224
1260
  quote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.10.0",
3
+ "version": "1.11.0-beta.1",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -53,9 +53,9 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@chainflip/bitcoin": "^1.2.6",
56
- "@chainflip/rpc": "~1.10.4",
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",