@chainflip/sdk 1.9.2 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/swap.cjs CHANGED
@@ -119,37 +119,54 @@ zod.z.object({
119
119
  // sdk version 1.8.2 sends undefined string if not set
120
120
  ]).optional(),
121
121
  dcaEnabled: booleanString.default("false"),
122
- isVaultSwap: booleanString.default("false")
122
+ isVaultSwap: booleanString.optional(),
123
+ isOnChain: booleanString.optional()
123
124
  }).transform((args, ctx) => {
124
125
  const { srcAsset, destAsset } = chainflip.getInternalAssets(args, false);
126
+ let hadError = false;
125
127
  if (srcAsset === null) {
126
128
  ctx.addIssue({
127
129
  message: `invalid asset and chain combination: ${JSON.stringify({ asset: args.srcAsset, chain: args.srcChain })}`,
128
130
  code: zod.z.ZodIssueCode.custom
129
131
  });
130
- return zod.z.NEVER;
132
+ hadError = true;
131
133
  }
132
134
  if (destAsset === null) {
133
135
  ctx.addIssue({
134
136
  message: `invalid asset and chain combination: ${JSON.stringify({ asset: args.destAsset, chain: args.destChain })}`,
135
137
  code: zod.z.ZodIssueCode.custom
136
138
  });
137
- return zod.z.NEVER;
139
+ hadError = true;
138
140
  }
139
141
  if (args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes === void 0) {
140
142
  ctx.addIssue({
141
143
  message: `ccmMessageLengthBytes must be set if ccmGasBudget is set`,
142
144
  code: zod.z.ZodIssueCode.custom
143
145
  });
144
- return zod.z.NEVER;
146
+ hadError = true;
145
147
  }
146
148
  if (args.ccmGasBudget === void 0 && args.ccmMessageLengthBytes !== void 0) {
147
149
  ctx.addIssue({
148
150
  message: `ccmGasBudget must be set if ccmMessageLengthBytes is set`,
149
151
  code: zod.z.ZodIssueCode.custom
150
152
  });
151
- return zod.z.NEVER;
153
+ hadError = true;
152
154
  }
155
+ if (args.isOnChain !== void 0 && args.isVaultSwap !== void 0) {
156
+ ctx.addIssue({
157
+ message: "isOnChain and isVaultSwap cannot be set at the same time",
158
+ code: zod.z.ZodIssueCode.custom
159
+ });
160
+ hadError = true;
161
+ }
162
+ if (args.isOnChain !== void 0 && args.brokerCommissionBps !== void 0 && args.brokerCommissionBps > 0) {
163
+ ctx.addIssue({
164
+ message: "isOnChain cannot be set with a non-zero broker commission",
165
+ code: zod.z.ZodIssueCode.custom
166
+ });
167
+ hadError = true;
168
+ }
169
+ if (hadError) return zod.z.NEVER;
153
170
  const ccmParams = args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes !== void 0 ? { gasBudget: args.ccmGasBudget, messageLengthBytes: args.ccmMessageLengthBytes } : void 0;
154
171
  return {
155
172
  srcAsset,
@@ -158,7 +175,8 @@ zod.z.object({
158
175
  brokerCommissionBps: args.brokerCommissionBps,
159
176
  ccmParams,
160
177
  dcaEnabled: args.dcaEnabled,
161
- isVaultSwap: args.isVaultSwap
178
+ isVaultSwap: args.isVaultSwap,
179
+ isOnChain: args.isOnChain
162
180
  };
163
181
  });
164
182
  var ccmParamsSchema = zod.z.object({
@@ -438,7 +456,7 @@ var MultiCache = class {
438
456
  }
439
457
  };
440
458
  var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2__default.default(price).multipliedBy(new BigNumber2__default.default(2).pow(128)).shiftedBy(chainflip.assetConstants[destAsset].decimals - chainflip.assetConstants[srcAsset].decimals).toFixed(0);
441
- var parseFoKParams = (params, quote) => {
459
+ function parseFoKParams(params, quote) {
442
460
  const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
443
461
  const destAsset = chainflip.getInternalAsset(quote.destAsset);
444
462
  let minPrice;
@@ -467,7 +485,7 @@ var parseFoKParams = (params, quote) => {
467
485
  retryDurationBlocks: params.retryDurationBlocks,
468
486
  minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
469
487
  };
470
- };
488
+ }
471
489
  var isTestnet = (network) => network !== "mainnet";
472
490
  var camelCase = (str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
473
491
  var camelCaseKeys = (obj) => {
@@ -638,7 +656,7 @@ var getChainData = (chain2, network, env) => ({
638
656
 
639
657
  // package.json
640
658
  var package_default = {
641
- version: "1.9.2"};
659
+ version: "1.9.3"};
642
660
 
643
661
  // src/swap/consts.ts
644
662
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -658,6 +676,7 @@ var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
658
676
  destChain: quoteRequest.destChain,
659
677
  destAsset: quoteRequest.destAsset,
660
678
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
679
+ isOnChain: String(Boolean(quoteRequest.isOnChain)),
661
680
  ...totalBrokerCommissionBps && {
662
681
  brokerCommissionBps: String(totalBrokerCommissionBps)
663
682
  },
@@ -847,6 +866,7 @@ var SwapSDK = class {
847
866
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
848
867
  assertQuoteValid(quote);
849
868
  assert(!quote.isVaultSwap, "Cannot open a deposit channel for a vault swap quote");
869
+ assert(!quote.isOnChain, "Cannot open a deposit channel for an on-chain quote");
850
870
  if (ccmParams) {
851
871
  assert(quote.ccmParams, "Cannot open CCM channel for quote without CCM params");
852
872
  } else {
@@ -926,7 +946,7 @@ var SwapSDK = class {
926
946
  }) {
927
947
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
928
948
  assertQuoteValid(quote);
929
- assert(quote.isVaultSwap, "Cannot encode vault swap data for a deposit channel quote");
949
+ assert(quote.isVaultSwap, "Cannot encode vault swap data for non-vault swap quotes");
930
950
  if (ccmParams) {
931
951
  assert(quote.ccmParams, "Cannot encode CCM swap for quote without CCM params");
932
952
  } else {
@@ -969,6 +989,25 @@ var SwapSDK = class {
969
989
  );
970
990
  return this.trpc.encodeVaultSwapData.mutate(vaultSwapRequest);
971
991
  }
992
+ // eslint-disable-next-line class-methods-use-this
993
+ getOnChainSwapExtrinsicArgs({
994
+ quote,
995
+ fillOrKillParams: fillOrKillParams2
996
+ }) {
997
+ assert(quote.isOnChain, "Cannot get extrinsic args for non-on-chain quotes");
998
+ const { retryDurationBlocks, minPriceX128 } = parseFoKParams(fillOrKillParams2, quote);
999
+ return [
1000
+ quote.depositAmount,
1001
+ chainflip.getInternalAsset(quote.srcAsset),
1002
+ chainflip.getInternalAsset(quote.destAsset),
1003
+ retryDurationBlocks,
1004
+ minPriceX128,
1005
+ quote.type === "DCA" ? {
1006
+ number_of_chunks: quote.dcaParams.numberOfChunks,
1007
+ chunk_interval: quote.dcaParams.chunkIntervalBlocks
1008
+ } : null
1009
+ ];
1010
+ }
972
1011
  async checkBoostEnabled() {
973
1012
  const { boostDepositsEnabled } = await this.cache.read("networkStatus");
974
1013
  return boostDepositsEnabled;
package/dist/swap.d.cts CHANGED
@@ -3,8 +3,139 @@ import { AssetAndChain, UncheckedAssetAndChain, ChainflipChain, ChainflipAsset,
3
3
  export { AssetSymbol as Asset, ChainflipChain as Chain, ChainflipAsset as ChainflipId, ChainflipNetwork, UncheckedAssetAndChain, getInternalAsset as getChainflipId } from '@chainflip/utils/chainflip';
4
4
  import * as _trpc_server from '@trpc/server';
5
5
  import { inferRouterOutputs } from '@trpc/server';
6
- import superjson from 'superjson';
7
6
  import { z } from 'zod';
7
+ import superjson from 'superjson';
8
+
9
+ declare const ccmParamsSchema: z.ZodEffects<z.ZodObject<{
10
+ gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
11
+ message: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
12
+ ccmAdditionalData: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
13
+ cfParameters: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ message: `0x${string}`;
16
+ gasBudget: `0x${string}`;
17
+ ccmAdditionalData?: `0x${string}` | undefined;
18
+ cfParameters?: `0x${string}` | undefined;
19
+ }, {
20
+ message: string;
21
+ gasBudget: string;
22
+ ccmAdditionalData?: string | undefined;
23
+ cfParameters?: string | undefined;
24
+ }>, {
25
+ gasBudget: `0x${string}`;
26
+ message: `0x${string}`;
27
+ ccmAdditionalData: `0x${string}` | undefined;
28
+ }, {
29
+ message: string;
30
+ gasBudget: string;
31
+ ccmAdditionalData?: string | undefined;
32
+ cfParameters?: string | undefined;
33
+ }>;
34
+ type CcmParams = Omit<z.input<typeof ccmParamsSchema>, 'cfParameters'> & {
35
+ cfParameters?: string;
36
+ };
37
+ declare const affiliateBroker: z.ZodEffects<z.ZodObject<{
38
+ account: z.ZodEffects<z.ZodString, string, string>;
39
+ commissionBps: z.ZodNumber;
40
+ }, "strip", z.ZodTypeAny, {
41
+ account: string;
42
+ commissionBps: number;
43
+ }, {
44
+ account: string;
45
+ commissionBps: number;
46
+ }>, {
47
+ account: string;
48
+ bps: number;
49
+ }, {
50
+ account: string;
51
+ commissionBps: number;
52
+ }>;
53
+ type AffiliateBroker = z.input<typeof affiliateBroker>;
54
+ declare const dcaParams: z.ZodObject<{
55
+ numberOfChunks: z.ZodNumber;
56
+ chunkIntervalBlocks: z.ZodNumber;
57
+ }, "strip", z.ZodTypeAny, {
58
+ numberOfChunks: number;
59
+ chunkIntervalBlocks: number;
60
+ }, {
61
+ numberOfChunks: number;
62
+ chunkIntervalBlocks: number;
63
+ }>;
64
+ type DcaParams = z.input<typeof dcaParams>;
65
+ declare const fillOrKillParams: z.ZodObject<{
66
+ retryDurationBlocks: z.ZodNumber;
67
+ refundAddress: z.ZodString;
68
+ minPriceX128: z.ZodString;
69
+ }, "strip", z.ZodTypeAny, {
70
+ retryDurationBlocks: number;
71
+ refundAddress: string;
72
+ minPriceX128: string;
73
+ }, {
74
+ retryDurationBlocks: number;
75
+ refundAddress: string;
76
+ minPriceX128: string;
77
+ }>;
78
+ type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
79
+ type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
80
+ minPrice: string;
81
+ };
82
+ interface Fee<T> extends UncheckedAssetAndChain {
83
+ type: T;
84
+ amount: string;
85
+ }
86
+ type SwapFee = Fee<'NETWORK' | 'INGRESS' | 'EGRESS' | 'BROKER' | 'BOOST' | 'REFUND'>;
87
+ type PoolFee = Fee<'LIQUIDITY'>;
88
+ type PaidFee = SwapFee | PoolFee;
89
+ type PoolInfo = {
90
+ baseAsset: AssetAndChain;
91
+ quoteAsset: AssetAndChain;
92
+ fee: Omit<PoolFee, 'type'>;
93
+ };
94
+ type BoostedQuoteDetails = {
95
+ estimatedBoostFeeBps: number;
96
+ maxBoostFeeBps: number;
97
+ };
98
+ interface BaseQuoteDetails {
99
+ srcAsset: AssetAndChain;
100
+ destAsset: AssetAndChain;
101
+ isVaultSwap: boolean;
102
+ isOnChain: boolean;
103
+ ccmParams?: {
104
+ gasBudget: string;
105
+ messageLengthBytes: number;
106
+ };
107
+ depositAmount: string;
108
+ intermediateAmount?: string;
109
+ egressAmount: string;
110
+ includedFees: SwapFee[];
111
+ poolInfo: PoolInfo[];
112
+ lowLiquidityWarning: boolean | undefined;
113
+ estimatedDurationSeconds: number;
114
+ estimatedDurationsSeconds: {
115
+ deposit: number;
116
+ swap: number;
117
+ egress: number;
118
+ };
119
+ estimatedPrice: string;
120
+ recommendedSlippageTolerancePercent: number;
121
+ }
122
+ type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
123
+ interface RegularQuote extends BaseQuoteDetails {
124
+ type: 'REGULAR';
125
+ boostQuote?: WithBoostQuote<RegularQuote>;
126
+ }
127
+ interface DCAQuote extends BaseQuoteDetails {
128
+ type: 'DCA';
129
+ dcaParams: DcaParams;
130
+ boostQuote?: WithBoostQuote<DCAQuote>;
131
+ }
132
+ type Quote = RegularQuote | DCAQuote;
133
+ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
134
+ type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
135
+ type BoostQuote = RegularBoostQuote | DCABoostQuote;
136
+ type FillOrKillParamsWithSlippage$1 = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
137
+ slippageTolerancePercent: string | number;
138
+ };
8
139
 
9
140
  declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<{
10
141
  ctx: object;
@@ -262,136 +393,6 @@ declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<
262
393
  }>;
263
394
  type AppRouter = typeof appRouter;
264
395
 
265
- declare const ccmParamsSchema: z.ZodEffects<z.ZodObject<{
266
- gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
267
- message: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
268
- ccmAdditionalData: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
269
- cfParameters: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
270
- }, "strip", z.ZodTypeAny, {
271
- message: `0x${string}`;
272
- gasBudget: `0x${string}`;
273
- ccmAdditionalData?: `0x${string}` | undefined;
274
- cfParameters?: `0x${string}` | undefined;
275
- }, {
276
- message: string;
277
- gasBudget: string;
278
- ccmAdditionalData?: string | undefined;
279
- cfParameters?: string | undefined;
280
- }>, {
281
- gasBudget: `0x${string}`;
282
- message: `0x${string}`;
283
- ccmAdditionalData: `0x${string}` | undefined;
284
- }, {
285
- message: string;
286
- gasBudget: string;
287
- ccmAdditionalData?: string | undefined;
288
- cfParameters?: string | undefined;
289
- }>;
290
- type CcmParams = Omit<z.input<typeof ccmParamsSchema>, 'cfParameters'> & {
291
- cfParameters?: string;
292
- };
293
- declare const affiliateBroker: z.ZodEffects<z.ZodObject<{
294
- account: z.ZodEffects<z.ZodString, string, string>;
295
- commissionBps: z.ZodNumber;
296
- }, "strip", z.ZodTypeAny, {
297
- account: string;
298
- commissionBps: number;
299
- }, {
300
- account: string;
301
- commissionBps: number;
302
- }>, {
303
- account: string;
304
- bps: number;
305
- }, {
306
- account: string;
307
- commissionBps: number;
308
- }>;
309
- type AffiliateBroker = z.input<typeof affiliateBroker>;
310
- declare const dcaParams: z.ZodObject<{
311
- numberOfChunks: z.ZodNumber;
312
- chunkIntervalBlocks: z.ZodNumber;
313
- }, "strip", z.ZodTypeAny, {
314
- numberOfChunks: number;
315
- chunkIntervalBlocks: number;
316
- }, {
317
- numberOfChunks: number;
318
- chunkIntervalBlocks: number;
319
- }>;
320
- type DcaParams = z.input<typeof dcaParams>;
321
- declare const fillOrKillParams: z.ZodObject<{
322
- retryDurationBlocks: z.ZodNumber;
323
- refundAddress: z.ZodString;
324
- minPriceX128: z.ZodString;
325
- }, "strip", z.ZodTypeAny, {
326
- retryDurationBlocks: number;
327
- refundAddress: string;
328
- minPriceX128: string;
329
- }, {
330
- retryDurationBlocks: number;
331
- refundAddress: string;
332
- minPriceX128: string;
333
- }>;
334
- type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
335
- type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
336
- minPrice: string;
337
- };
338
- interface Fee<T> extends UncheckedAssetAndChain {
339
- type: T;
340
- amount: string;
341
- }
342
- type SwapFee = Fee<'NETWORK' | 'INGRESS' | 'EGRESS' | 'BROKER' | 'BOOST' | 'REFUND'>;
343
- type PoolFee = Fee<'LIQUIDITY'>;
344
- type PaidFee = SwapFee | PoolFee;
345
- type PoolInfo = {
346
- baseAsset: AssetAndChain;
347
- quoteAsset: AssetAndChain;
348
- fee: Omit<PoolFee, 'type'>;
349
- };
350
- type BoostedQuoteDetails = {
351
- estimatedBoostFeeBps: number;
352
- maxBoostFeeBps: number;
353
- };
354
- interface BaseQuoteDetails {
355
- srcAsset: AssetAndChain;
356
- destAsset: AssetAndChain;
357
- isVaultSwap: boolean;
358
- ccmParams?: {
359
- gasBudget: string;
360
- messageLengthBytes: number;
361
- };
362
- depositAmount: string;
363
- intermediateAmount?: string;
364
- egressAmount: string;
365
- includedFees: SwapFee[];
366
- poolInfo: PoolInfo[];
367
- lowLiquidityWarning: boolean | undefined;
368
- estimatedDurationSeconds: number;
369
- estimatedDurationsSeconds: {
370
- deposit: number;
371
- swap: number;
372
- egress: number;
373
- };
374
- estimatedPrice: string;
375
- recommendedSlippageTolerancePercent: number;
376
- }
377
- type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
378
- interface RegularQuote extends BaseQuoteDetails {
379
- type: 'REGULAR';
380
- boostQuote?: WithBoostQuote<RegularQuote>;
381
- }
382
- interface DCAQuote extends BaseQuoteDetails {
383
- type: 'DCA';
384
- dcaParams: DcaParams;
385
- boostQuote?: WithBoostQuote<DCAQuote>;
386
- }
387
- type Quote = RegularQuote | DCAQuote;
388
- type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
389
- type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
390
- type BoostQuote = RegularBoostQuote | DCABoostQuote;
391
- type FillOrKillParamsWithSlippage$1 = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
392
- slippageTolerancePercent: string | number;
393
- };
394
-
395
396
  interface ChainData {
396
397
  chain: ChainflipChain;
397
398
  name: string;
@@ -426,6 +427,7 @@ interface QuoteRequest extends ChainsAndAssets {
426
427
  brokerCommissionBps?: number;
427
428
  affiliateBrokers?: AffiliateBroker[];
428
429
  isVaultSwap?: boolean;
430
+ isOnChain?: boolean;
429
431
  ccmParams?: {
430
432
  gasBudget: string;
431
433
  messageLengthBytes: number;
@@ -697,6 +699,20 @@ declare class SwapSDK {
697
699
  } & UncheckedAssetAndChain)): Promise<BoostPoolDepth[]>;
698
700
  requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
699
701
  encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
702
+ getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
703
+ quote: Quote;
704
+ fillOrKillParams: Omit<FillOrKillParamsWithMinPrice, 'refundAddress'> | Omit<FillOrKillParamsWithSlippage, 'refundAddress'>;
705
+ }): [
706
+ amount: string,
707
+ inputAsset: ChainflipAsset,
708
+ outputAsset: ChainflipAsset,
709
+ retryDuration: number,
710
+ minPrice: string,
711
+ dcaParams: {
712
+ number_of_chunks: number;
713
+ chunk_interval: number;
714
+ } | null
715
+ ];
700
716
  checkBoostEnabled(): Promise<boolean>;
701
717
  }
702
718
 
package/dist/swap.d.ts CHANGED
@@ -3,8 +3,139 @@ import { AssetAndChain, UncheckedAssetAndChain, ChainflipChain, ChainflipAsset,
3
3
  export { AssetSymbol as Asset, ChainflipChain as Chain, ChainflipAsset as ChainflipId, ChainflipNetwork, UncheckedAssetAndChain, getInternalAsset as getChainflipId } from '@chainflip/utils/chainflip';
4
4
  import * as _trpc_server from '@trpc/server';
5
5
  import { inferRouterOutputs } from '@trpc/server';
6
- import superjson from 'superjson';
7
6
  import { z } from 'zod';
7
+ import superjson from 'superjson';
8
+
9
+ declare const ccmParamsSchema: z.ZodEffects<z.ZodObject<{
10
+ gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
11
+ message: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
12
+ ccmAdditionalData: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
13
+ cfParameters: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
14
+ }, "strip", z.ZodTypeAny, {
15
+ message: `0x${string}`;
16
+ gasBudget: `0x${string}`;
17
+ ccmAdditionalData?: `0x${string}` | undefined;
18
+ cfParameters?: `0x${string}` | undefined;
19
+ }, {
20
+ message: string;
21
+ gasBudget: string;
22
+ ccmAdditionalData?: string | undefined;
23
+ cfParameters?: string | undefined;
24
+ }>, {
25
+ gasBudget: `0x${string}`;
26
+ message: `0x${string}`;
27
+ ccmAdditionalData: `0x${string}` | undefined;
28
+ }, {
29
+ message: string;
30
+ gasBudget: string;
31
+ ccmAdditionalData?: string | undefined;
32
+ cfParameters?: string | undefined;
33
+ }>;
34
+ type CcmParams = Omit<z.input<typeof ccmParamsSchema>, 'cfParameters'> & {
35
+ cfParameters?: string;
36
+ };
37
+ declare const affiliateBroker: z.ZodEffects<z.ZodObject<{
38
+ account: z.ZodEffects<z.ZodString, string, string>;
39
+ commissionBps: z.ZodNumber;
40
+ }, "strip", z.ZodTypeAny, {
41
+ account: string;
42
+ commissionBps: number;
43
+ }, {
44
+ account: string;
45
+ commissionBps: number;
46
+ }>, {
47
+ account: string;
48
+ bps: number;
49
+ }, {
50
+ account: string;
51
+ commissionBps: number;
52
+ }>;
53
+ type AffiliateBroker = z.input<typeof affiliateBroker>;
54
+ declare const dcaParams: z.ZodObject<{
55
+ numberOfChunks: z.ZodNumber;
56
+ chunkIntervalBlocks: z.ZodNumber;
57
+ }, "strip", z.ZodTypeAny, {
58
+ numberOfChunks: number;
59
+ chunkIntervalBlocks: number;
60
+ }, {
61
+ numberOfChunks: number;
62
+ chunkIntervalBlocks: number;
63
+ }>;
64
+ type DcaParams = z.input<typeof dcaParams>;
65
+ declare const fillOrKillParams: z.ZodObject<{
66
+ retryDurationBlocks: z.ZodNumber;
67
+ refundAddress: z.ZodString;
68
+ minPriceX128: z.ZodString;
69
+ }, "strip", z.ZodTypeAny, {
70
+ retryDurationBlocks: number;
71
+ refundAddress: string;
72
+ minPriceX128: string;
73
+ }, {
74
+ retryDurationBlocks: number;
75
+ refundAddress: string;
76
+ minPriceX128: string;
77
+ }>;
78
+ type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
79
+ type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
80
+ minPrice: string;
81
+ };
82
+ interface Fee<T> extends UncheckedAssetAndChain {
83
+ type: T;
84
+ amount: string;
85
+ }
86
+ type SwapFee = Fee<'NETWORK' | 'INGRESS' | 'EGRESS' | 'BROKER' | 'BOOST' | 'REFUND'>;
87
+ type PoolFee = Fee<'LIQUIDITY'>;
88
+ type PaidFee = SwapFee | PoolFee;
89
+ type PoolInfo = {
90
+ baseAsset: AssetAndChain;
91
+ quoteAsset: AssetAndChain;
92
+ fee: Omit<PoolFee, 'type'>;
93
+ };
94
+ type BoostedQuoteDetails = {
95
+ estimatedBoostFeeBps: number;
96
+ maxBoostFeeBps: number;
97
+ };
98
+ interface BaseQuoteDetails {
99
+ srcAsset: AssetAndChain;
100
+ destAsset: AssetAndChain;
101
+ isVaultSwap: boolean;
102
+ isOnChain: boolean;
103
+ ccmParams?: {
104
+ gasBudget: string;
105
+ messageLengthBytes: number;
106
+ };
107
+ depositAmount: string;
108
+ intermediateAmount?: string;
109
+ egressAmount: string;
110
+ includedFees: SwapFee[];
111
+ poolInfo: PoolInfo[];
112
+ lowLiquidityWarning: boolean | undefined;
113
+ estimatedDurationSeconds: number;
114
+ estimatedDurationsSeconds: {
115
+ deposit: number;
116
+ swap: number;
117
+ egress: number;
118
+ };
119
+ estimatedPrice: string;
120
+ recommendedSlippageTolerancePercent: number;
121
+ }
122
+ type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
123
+ interface RegularQuote extends BaseQuoteDetails {
124
+ type: 'REGULAR';
125
+ boostQuote?: WithBoostQuote<RegularQuote>;
126
+ }
127
+ interface DCAQuote extends BaseQuoteDetails {
128
+ type: 'DCA';
129
+ dcaParams: DcaParams;
130
+ boostQuote?: WithBoostQuote<DCAQuote>;
131
+ }
132
+ type Quote = RegularQuote | DCAQuote;
133
+ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
134
+ type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
135
+ type BoostQuote = RegularBoostQuote | DCABoostQuote;
136
+ type FillOrKillParamsWithSlippage$1 = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
137
+ slippageTolerancePercent: string | number;
138
+ };
8
139
 
9
140
  declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<{
10
141
  ctx: object;
@@ -262,136 +393,6 @@ declare const appRouter: _trpc_server.CreateRouterInner<_trpc_server.RootConfig<
262
393
  }>;
263
394
  type AppRouter = typeof appRouter;
264
395
 
265
- declare const ccmParamsSchema: z.ZodEffects<z.ZodObject<{
266
- gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
267
- message: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
268
- ccmAdditionalData: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
269
- cfParameters: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
270
- }, "strip", z.ZodTypeAny, {
271
- message: `0x${string}`;
272
- gasBudget: `0x${string}`;
273
- ccmAdditionalData?: `0x${string}` | undefined;
274
- cfParameters?: `0x${string}` | undefined;
275
- }, {
276
- message: string;
277
- gasBudget: string;
278
- ccmAdditionalData?: string | undefined;
279
- cfParameters?: string | undefined;
280
- }>, {
281
- gasBudget: `0x${string}`;
282
- message: `0x${string}`;
283
- ccmAdditionalData: `0x${string}` | undefined;
284
- }, {
285
- message: string;
286
- gasBudget: string;
287
- ccmAdditionalData?: string | undefined;
288
- cfParameters?: string | undefined;
289
- }>;
290
- type CcmParams = Omit<z.input<typeof ccmParamsSchema>, 'cfParameters'> & {
291
- cfParameters?: string;
292
- };
293
- declare const affiliateBroker: z.ZodEffects<z.ZodObject<{
294
- account: z.ZodEffects<z.ZodString, string, string>;
295
- commissionBps: z.ZodNumber;
296
- }, "strip", z.ZodTypeAny, {
297
- account: string;
298
- commissionBps: number;
299
- }, {
300
- account: string;
301
- commissionBps: number;
302
- }>, {
303
- account: string;
304
- bps: number;
305
- }, {
306
- account: string;
307
- commissionBps: number;
308
- }>;
309
- type AffiliateBroker = z.input<typeof affiliateBroker>;
310
- declare const dcaParams: z.ZodObject<{
311
- numberOfChunks: z.ZodNumber;
312
- chunkIntervalBlocks: z.ZodNumber;
313
- }, "strip", z.ZodTypeAny, {
314
- numberOfChunks: number;
315
- chunkIntervalBlocks: number;
316
- }, {
317
- numberOfChunks: number;
318
- chunkIntervalBlocks: number;
319
- }>;
320
- type DcaParams = z.input<typeof dcaParams>;
321
- declare const fillOrKillParams: z.ZodObject<{
322
- retryDurationBlocks: z.ZodNumber;
323
- refundAddress: z.ZodString;
324
- minPriceX128: z.ZodString;
325
- }, "strip", z.ZodTypeAny, {
326
- retryDurationBlocks: number;
327
- refundAddress: string;
328
- minPriceX128: string;
329
- }, {
330
- retryDurationBlocks: number;
331
- refundAddress: string;
332
- minPriceX128: string;
333
- }>;
334
- type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
335
- type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
336
- minPrice: string;
337
- };
338
- interface Fee<T> extends UncheckedAssetAndChain {
339
- type: T;
340
- amount: string;
341
- }
342
- type SwapFee = Fee<'NETWORK' | 'INGRESS' | 'EGRESS' | 'BROKER' | 'BOOST' | 'REFUND'>;
343
- type PoolFee = Fee<'LIQUIDITY'>;
344
- type PaidFee = SwapFee | PoolFee;
345
- type PoolInfo = {
346
- baseAsset: AssetAndChain;
347
- quoteAsset: AssetAndChain;
348
- fee: Omit<PoolFee, 'type'>;
349
- };
350
- type BoostedQuoteDetails = {
351
- estimatedBoostFeeBps: number;
352
- maxBoostFeeBps: number;
353
- };
354
- interface BaseQuoteDetails {
355
- srcAsset: AssetAndChain;
356
- destAsset: AssetAndChain;
357
- isVaultSwap: boolean;
358
- ccmParams?: {
359
- gasBudget: string;
360
- messageLengthBytes: number;
361
- };
362
- depositAmount: string;
363
- intermediateAmount?: string;
364
- egressAmount: string;
365
- includedFees: SwapFee[];
366
- poolInfo: PoolInfo[];
367
- lowLiquidityWarning: boolean | undefined;
368
- estimatedDurationSeconds: number;
369
- estimatedDurationsSeconds: {
370
- deposit: number;
371
- swap: number;
372
- egress: number;
373
- };
374
- estimatedPrice: string;
375
- recommendedSlippageTolerancePercent: number;
376
- }
377
- type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
378
- interface RegularQuote extends BaseQuoteDetails {
379
- type: 'REGULAR';
380
- boostQuote?: WithBoostQuote<RegularQuote>;
381
- }
382
- interface DCAQuote extends BaseQuoteDetails {
383
- type: 'DCA';
384
- dcaParams: DcaParams;
385
- boostQuote?: WithBoostQuote<DCAQuote>;
386
- }
387
- type Quote = RegularQuote | DCAQuote;
388
- type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
389
- type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
390
- type BoostQuote = RegularBoostQuote | DCABoostQuote;
391
- type FillOrKillParamsWithSlippage$1 = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
392
- slippageTolerancePercent: string | number;
393
- };
394
-
395
396
  interface ChainData {
396
397
  chain: ChainflipChain;
397
398
  name: string;
@@ -426,6 +427,7 @@ interface QuoteRequest extends ChainsAndAssets {
426
427
  brokerCommissionBps?: number;
427
428
  affiliateBrokers?: AffiliateBroker[];
428
429
  isVaultSwap?: boolean;
430
+ isOnChain?: boolean;
429
431
  ccmParams?: {
430
432
  gasBudget: string;
431
433
  messageLengthBytes: number;
@@ -697,6 +699,20 @@ declare class SwapSDK {
697
699
  } & UncheckedAssetAndChain)): Promise<BoostPoolDepth[]>;
698
700
  requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
699
701
  encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
702
+ getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
703
+ quote: Quote;
704
+ fillOrKillParams: Omit<FillOrKillParamsWithMinPrice, 'refundAddress'> | Omit<FillOrKillParamsWithSlippage, 'refundAddress'>;
705
+ }): [
706
+ amount: string,
707
+ inputAsset: ChainflipAsset,
708
+ outputAsset: ChainflipAsset,
709
+ retryDuration: number,
710
+ minPrice: string,
711
+ dcaParams: {
712
+ number_of_chunks: number;
713
+ chunk_interval: number;
714
+ } | null
715
+ ];
700
716
  checkBoostEnabled(): Promise<boolean>;
701
717
  }
702
718
 
package/dist/swap.js CHANGED
@@ -79,37 +79,54 @@ z.object({
79
79
  // sdk version 1.8.2 sends undefined string if not set
80
80
  ]).optional(),
81
81
  dcaEnabled: booleanString.default("false"),
82
- isVaultSwap: booleanString.default("false")
82
+ isVaultSwap: booleanString.optional(),
83
+ isOnChain: booleanString.optional()
83
84
  }).transform((args, ctx) => {
84
85
  const { srcAsset, destAsset } = getInternalAssets(args, false);
86
+ let hadError = false;
85
87
  if (srcAsset === null) {
86
88
  ctx.addIssue({
87
89
  message: `invalid asset and chain combination: ${JSON.stringify({ asset: args.srcAsset, chain: args.srcChain })}`,
88
90
  code: z.ZodIssueCode.custom
89
91
  });
90
- return z.NEVER;
92
+ hadError = true;
91
93
  }
92
94
  if (destAsset === null) {
93
95
  ctx.addIssue({
94
96
  message: `invalid asset and chain combination: ${JSON.stringify({ asset: args.destAsset, chain: args.destChain })}`,
95
97
  code: z.ZodIssueCode.custom
96
98
  });
97
- return z.NEVER;
99
+ hadError = true;
98
100
  }
99
101
  if (args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes === void 0) {
100
102
  ctx.addIssue({
101
103
  message: `ccmMessageLengthBytes must be set if ccmGasBudget is set`,
102
104
  code: z.ZodIssueCode.custom
103
105
  });
104
- return z.NEVER;
106
+ hadError = true;
105
107
  }
106
108
  if (args.ccmGasBudget === void 0 && args.ccmMessageLengthBytes !== void 0) {
107
109
  ctx.addIssue({
108
110
  message: `ccmGasBudget must be set if ccmMessageLengthBytes is set`,
109
111
  code: z.ZodIssueCode.custom
110
112
  });
111
- return z.NEVER;
113
+ hadError = true;
112
114
  }
115
+ if (args.isOnChain !== void 0 && args.isVaultSwap !== void 0) {
116
+ ctx.addIssue({
117
+ message: "isOnChain and isVaultSwap cannot be set at the same time",
118
+ code: z.ZodIssueCode.custom
119
+ });
120
+ hadError = true;
121
+ }
122
+ if (args.isOnChain !== void 0 && args.brokerCommissionBps !== void 0 && args.brokerCommissionBps > 0) {
123
+ ctx.addIssue({
124
+ message: "isOnChain cannot be set with a non-zero broker commission",
125
+ code: z.ZodIssueCode.custom
126
+ });
127
+ hadError = true;
128
+ }
129
+ if (hadError) return z.NEVER;
113
130
  const ccmParams = args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes !== void 0 ? { gasBudget: args.ccmGasBudget, messageLengthBytes: args.ccmMessageLengthBytes } : void 0;
114
131
  return {
115
132
  srcAsset,
@@ -118,7 +135,8 @@ z.object({
118
135
  brokerCommissionBps: args.brokerCommissionBps,
119
136
  ccmParams,
120
137
  dcaEnabled: args.dcaEnabled,
121
- isVaultSwap: args.isVaultSwap
138
+ isVaultSwap: args.isVaultSwap,
139
+ isOnChain: args.isOnChain
122
140
  };
123
141
  });
124
142
  var ccmParamsSchema = z.object({
@@ -398,7 +416,7 @@ var MultiCache = class {
398
416
  }
399
417
  };
400
418
  var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber2(price).multipliedBy(new BigNumber2(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
401
- var parseFoKParams = (params, quote) => {
419
+ function parseFoKParams(params, quote) {
402
420
  const srcAsset = getInternalAsset(quote.srcAsset);
403
421
  const destAsset = getInternalAsset(quote.destAsset);
404
422
  let minPrice;
@@ -427,7 +445,7 @@ var parseFoKParams = (params, quote) => {
427
445
  retryDurationBlocks: params.retryDurationBlocks,
428
446
  minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
429
447
  };
430
- };
448
+ }
431
449
  var isTestnet = (network) => network !== "mainnet";
432
450
  var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
433
451
  var validateSwapAmount = (env, asset2, amount) => {
@@ -506,7 +524,7 @@ var getChainData = (chain2, network, env) => ({
506
524
 
507
525
  // package.json
508
526
  var package_default = {
509
- version: "1.9.2"};
527
+ version: "1.9.3"};
510
528
 
511
529
  // src/swap/consts.ts
512
530
  var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
@@ -526,6 +544,7 @@ var getQuoteV2 = async (baseUrl, quoteRequest, { signal }) => {
526
544
  destChain: quoteRequest.destChain,
527
545
  destAsset: quoteRequest.destAsset,
528
546
  isVaultSwap: String(Boolean(quoteRequest.isVaultSwap)),
547
+ isOnChain: String(Boolean(quoteRequest.isOnChain)),
529
548
  ...totalBrokerCommissionBps && {
530
549
  brokerCommissionBps: String(totalBrokerCommissionBps)
531
550
  },
@@ -715,6 +734,7 @@ var SwapSDK = class {
715
734
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
716
735
  assertQuoteValid(quote);
717
736
  assert(!quote.isVaultSwap, "Cannot open a deposit channel for a vault swap quote");
737
+ assert(!quote.isOnChain, "Cannot open a deposit channel for an on-chain quote");
718
738
  if (ccmParams) {
719
739
  assert(quote.ccmParams, "Cannot open CCM channel for quote without CCM params");
720
740
  } else {
@@ -794,7 +814,7 @@ var SwapSDK = class {
794
814
  }) {
795
815
  await this.validateSwapAmount(quote.srcAsset, BigInt(quote.depositAmount));
796
816
  assertQuoteValid(quote);
797
- assert(quote.isVaultSwap, "Cannot encode vault swap data for a deposit channel quote");
817
+ assert(quote.isVaultSwap, "Cannot encode vault swap data for non-vault swap quotes");
798
818
  if (ccmParams) {
799
819
  assert(quote.ccmParams, "Cannot encode CCM swap for quote without CCM params");
800
820
  } else {
@@ -837,6 +857,25 @@ var SwapSDK = class {
837
857
  );
838
858
  return this.trpc.encodeVaultSwapData.mutate(vaultSwapRequest);
839
859
  }
860
+ // eslint-disable-next-line class-methods-use-this
861
+ getOnChainSwapExtrinsicArgs({
862
+ quote,
863
+ fillOrKillParams: fillOrKillParams2
864
+ }) {
865
+ assert(quote.isOnChain, "Cannot get extrinsic args for non-on-chain quotes");
866
+ const { retryDurationBlocks, minPriceX128 } = parseFoKParams(fillOrKillParams2, quote);
867
+ return [
868
+ quote.depositAmount,
869
+ getInternalAsset(quote.srcAsset),
870
+ getInternalAsset(quote.destAsset),
871
+ retryDurationBlocks,
872
+ minPriceX128,
873
+ quote.type === "DCA" ? {
874
+ number_of_chunks: quote.dcaParams.numberOfChunks,
875
+ chunk_interval: quote.dcaParams.chunkIntervalBlocks
876
+ } : null
877
+ ];
878
+ }
840
879
  async checkBoostEnabled() {
841
880
  const { boostDepositsEnabled } = await this.cache.read("networkStatus");
842
881
  return boostDepositsEnabled;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chainflip/sdk",
3
- "version": "1.9.2",
3
+ "version": "1.9.3",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./swap": {
@@ -55,17 +55,17 @@
55
55
  "@chainflip/bitcoin": "^1.2.5",
56
56
  "@chainflip/rpc": "~1.9.7",
57
57
  "@chainflip/solana": "^2.1.9",
58
- "@chainflip/utils": "^0.8.6",
58
+ "@chainflip/utils": "^0.8.7",
59
59
  "@trpc/client": "^10.45.2",
60
- "axios": "^1.8.4",
60
+ "axios": "^1.9.0",
61
61
  "bignumber.js": "^9.3.0",
62
- "ethers": "^6.13.3",
62
+ "ethers": "^6.14.1",
63
63
  "superjson": "^1.13.3",
64
- "zod": "^3.24.3"
64
+ "zod": "^3.25.7"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@trpc/server": "^10.45.2",
68
- "tsup": "^8.4.0"
68
+ "tsup": "^8.5.0"
69
69
  },
70
70
  "scripts": {
71
71
  "test": "vitest",