@chainflip/sdk 1.10.0 → 1.10.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 +8 -5
- package/dist/swap.d.cts +35 -7
- package/dist/swap.d.ts +35 -7
- package/dist/swap.js +8 -5
- package/package.json +2 -2
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 }; }
|
|
@@ -189,7 +190,7 @@ var ccmParamsSchema = z6.z.object({
|
|
|
189
190
|
}).transform(({ gasBudget, message, ccmAdditionalData, cfParameters }) => ({
|
|
190
191
|
gasBudget,
|
|
191
192
|
message,
|
|
192
|
-
ccmAdditionalData: ccmAdditionalData ?? cfParameters
|
|
193
|
+
ccmAdditionalData: ccmAdditionalData ?? cfParameters ?? "0x"
|
|
193
194
|
}));
|
|
194
195
|
var affiliateBroker = z6.z.object({
|
|
195
196
|
account: chainflipAddress,
|
|
@@ -732,6 +733,7 @@ var MultiCache = class {
|
|
|
732
733
|
}
|
|
733
734
|
};
|
|
734
735
|
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);
|
|
736
|
+
var blocksPerMinute = 60 / consts.CHAINFLIP_BLOCK_TIME_SECONDS;
|
|
735
737
|
function parseFoKParams(params, quote) {
|
|
736
738
|
const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
|
|
737
739
|
const destAsset = chainflip.getInternalAsset(quote.destAsset);
|
|
@@ -756,11 +758,12 @@ function parseFoKParams(params, quote) {
|
|
|
756
758
|
} else {
|
|
757
759
|
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
758
760
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
retryDurationBlocks
|
|
761
|
+
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
762
|
+
const parsed = {
|
|
763
|
+
retryDurationBlocks,
|
|
762
764
|
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
|
|
763
765
|
};
|
|
766
|
+
return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
|
|
764
767
|
}
|
|
765
768
|
var isTestnet = (network) => network !== "mainnet";
|
|
766
769
|
var camelCase = (str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
@@ -932,7 +935,7 @@ var getChainData = (chain2, network, env) => ({
|
|
|
932
935
|
|
|
933
936
|
// package.json
|
|
934
937
|
var package_default = {
|
|
935
|
-
version: "1.10.
|
|
938
|
+
version: "1.10.1"};
|
|
936
939
|
|
|
937
940
|
// src/swap/consts.ts
|
|
938
941
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
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}
|
|
25
|
+
ccmAdditionalData: `0x${string}`;
|
|
26
26
|
}, {
|
|
27
27
|
message: string;
|
|
28
28
|
gasBudget: string;
|
|
@@ -117,6 +117,7 @@ interface BaseQuoteDetails {
|
|
|
117
117
|
};
|
|
118
118
|
estimatedPrice: string;
|
|
119
119
|
recommendedSlippageTolerancePercent: number;
|
|
120
|
+
recommendedRetryDurationMinutes: number;
|
|
120
121
|
}
|
|
121
122
|
type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
|
|
122
123
|
interface RegularQuote extends BaseQuoteDetails {
|
|
@@ -132,8 +133,35 @@ type Quote = RegularQuote | DCAQuote;
|
|
|
132
133
|
type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
|
|
133
134
|
type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
|
|
134
135
|
type BoostQuote = RegularBoostQuote | DCABoostQuote;
|
|
135
|
-
type
|
|
136
|
+
type FillOrKillParamsWithoutRefundAddress = {
|
|
137
|
+
minPrice: string;
|
|
138
|
+
retryDurationBlocks: number;
|
|
139
|
+
} | {
|
|
140
|
+
minPrice: string;
|
|
141
|
+
retryDurationMinutes: number;
|
|
142
|
+
} | {
|
|
143
|
+
slippageTolerancePercent: string | number;
|
|
144
|
+
retryDurationBlocks: number;
|
|
145
|
+
} | {
|
|
146
|
+
slippageTolerancePercent: string | number;
|
|
147
|
+
retryDurationMinutes: number;
|
|
148
|
+
};
|
|
149
|
+
type FillOrKillParams = {
|
|
150
|
+
refundAddress: string;
|
|
151
|
+
minPrice: string;
|
|
152
|
+
retryDurationBlocks: number;
|
|
153
|
+
} | {
|
|
154
|
+
refundAddress: string;
|
|
155
|
+
minPrice: string;
|
|
156
|
+
retryDurationMinutes: number;
|
|
157
|
+
} | {
|
|
158
|
+
refundAddress: string;
|
|
159
|
+
slippageTolerancePercent: string | number;
|
|
160
|
+
retryDurationBlocks: number;
|
|
161
|
+
} | {
|
|
162
|
+
refundAddress: string;
|
|
136
163
|
slippageTolerancePercent: string | number;
|
|
164
|
+
retryDurationMinutes: number;
|
|
137
165
|
};
|
|
138
166
|
|
|
139
167
|
interface ChainData {
|
|
@@ -363,7 +391,7 @@ interface DepositAddressRequestV2 {
|
|
|
363
391
|
quote: Quote | BoostQuote;
|
|
364
392
|
srcAddress?: string;
|
|
365
393
|
destAddress: string;
|
|
366
|
-
fillOrKillParams:
|
|
394
|
+
fillOrKillParams: FillOrKillParams;
|
|
367
395
|
affiliateBrokers?: {
|
|
368
396
|
account: `cF${string}` | `0x${string}`;
|
|
369
397
|
commissionBps: number;
|
|
@@ -377,7 +405,7 @@ interface DepositAddressResponseV2 extends Omit<QuoteRequest, 'ccmParams'> {
|
|
|
377
405
|
maxBoostFeeBps?: number;
|
|
378
406
|
srcAddress?: string;
|
|
379
407
|
dcaParams?: DcaParams;
|
|
380
|
-
fillOrKillParams:
|
|
408
|
+
fillOrKillParams: FillOrKillParams;
|
|
381
409
|
depositChannelId: string;
|
|
382
410
|
depositAddress: string;
|
|
383
411
|
brokerCommissionBps: number;
|
|
@@ -390,7 +418,7 @@ interface VaultSwapRequest {
|
|
|
390
418
|
quote: Quote | BoostQuote;
|
|
391
419
|
srcAddress?: string;
|
|
392
420
|
destAddress: string;
|
|
393
|
-
fillOrKillParams:
|
|
421
|
+
fillOrKillParams: FillOrKillParams;
|
|
394
422
|
affiliateBrokers?: {
|
|
395
423
|
account: `cF${string}` | `0x${string}`;
|
|
396
424
|
commissionBps: number;
|
|
@@ -426,7 +454,7 @@ interface EncodeCfParametersRequest {
|
|
|
426
454
|
quote: Quote | BoostQuote;
|
|
427
455
|
srcAddress?: string;
|
|
428
456
|
destAddress: string;
|
|
429
|
-
fillOrKillParams:
|
|
457
|
+
fillOrKillParams: FillOrKillParams;
|
|
430
458
|
affiliateBrokers?: {
|
|
431
459
|
account: `cF${string}` | `0x${string}`;
|
|
432
460
|
commissionBps: number;
|
|
@@ -487,7 +515,7 @@ declare class SwapSDK {
|
|
|
487
515
|
encodeCfParameters({ quote, srcAddress, destAddress, fillOrKillParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, }: EncodeCfParametersRequest): Promise<HexString>;
|
|
488
516
|
getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
|
|
489
517
|
quote: Quote;
|
|
490
|
-
fillOrKillParams:
|
|
518
|
+
fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
|
|
491
519
|
}): [
|
|
492
520
|
amount: string,
|
|
493
521
|
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}
|
|
25
|
+
ccmAdditionalData: `0x${string}`;
|
|
26
26
|
}, {
|
|
27
27
|
message: string;
|
|
28
28
|
gasBudget: string;
|
|
@@ -117,6 +117,7 @@ interface BaseQuoteDetails {
|
|
|
117
117
|
};
|
|
118
118
|
estimatedPrice: string;
|
|
119
119
|
recommendedSlippageTolerancePercent: number;
|
|
120
|
+
recommendedRetryDurationMinutes: number;
|
|
120
121
|
}
|
|
121
122
|
type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
|
|
122
123
|
interface RegularQuote extends BaseQuoteDetails {
|
|
@@ -132,8 +133,35 @@ type Quote = RegularQuote | DCAQuote;
|
|
|
132
133
|
type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
|
|
133
134
|
type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
|
|
134
135
|
type BoostQuote = RegularBoostQuote | DCABoostQuote;
|
|
135
|
-
type
|
|
136
|
+
type FillOrKillParamsWithoutRefundAddress = {
|
|
137
|
+
minPrice: string;
|
|
138
|
+
retryDurationBlocks: number;
|
|
139
|
+
} | {
|
|
140
|
+
minPrice: string;
|
|
141
|
+
retryDurationMinutes: number;
|
|
142
|
+
} | {
|
|
143
|
+
slippageTolerancePercent: string | number;
|
|
144
|
+
retryDurationBlocks: number;
|
|
145
|
+
} | {
|
|
146
|
+
slippageTolerancePercent: string | number;
|
|
147
|
+
retryDurationMinutes: number;
|
|
148
|
+
};
|
|
149
|
+
type FillOrKillParams = {
|
|
150
|
+
refundAddress: string;
|
|
151
|
+
minPrice: string;
|
|
152
|
+
retryDurationBlocks: number;
|
|
153
|
+
} | {
|
|
154
|
+
refundAddress: string;
|
|
155
|
+
minPrice: string;
|
|
156
|
+
retryDurationMinutes: number;
|
|
157
|
+
} | {
|
|
158
|
+
refundAddress: string;
|
|
159
|
+
slippageTolerancePercent: string | number;
|
|
160
|
+
retryDurationBlocks: number;
|
|
161
|
+
} | {
|
|
162
|
+
refundAddress: string;
|
|
136
163
|
slippageTolerancePercent: string | number;
|
|
164
|
+
retryDurationMinutes: number;
|
|
137
165
|
};
|
|
138
166
|
|
|
139
167
|
interface ChainData {
|
|
@@ -363,7 +391,7 @@ interface DepositAddressRequestV2 {
|
|
|
363
391
|
quote: Quote | BoostQuote;
|
|
364
392
|
srcAddress?: string;
|
|
365
393
|
destAddress: string;
|
|
366
|
-
fillOrKillParams:
|
|
394
|
+
fillOrKillParams: FillOrKillParams;
|
|
367
395
|
affiliateBrokers?: {
|
|
368
396
|
account: `cF${string}` | `0x${string}`;
|
|
369
397
|
commissionBps: number;
|
|
@@ -377,7 +405,7 @@ interface DepositAddressResponseV2 extends Omit<QuoteRequest, 'ccmParams'> {
|
|
|
377
405
|
maxBoostFeeBps?: number;
|
|
378
406
|
srcAddress?: string;
|
|
379
407
|
dcaParams?: DcaParams;
|
|
380
|
-
fillOrKillParams:
|
|
408
|
+
fillOrKillParams: FillOrKillParams;
|
|
381
409
|
depositChannelId: string;
|
|
382
410
|
depositAddress: string;
|
|
383
411
|
brokerCommissionBps: number;
|
|
@@ -390,7 +418,7 @@ interface VaultSwapRequest {
|
|
|
390
418
|
quote: Quote | BoostQuote;
|
|
391
419
|
srcAddress?: string;
|
|
392
420
|
destAddress: string;
|
|
393
|
-
fillOrKillParams:
|
|
421
|
+
fillOrKillParams: FillOrKillParams;
|
|
394
422
|
affiliateBrokers?: {
|
|
395
423
|
account: `cF${string}` | `0x${string}`;
|
|
396
424
|
commissionBps: number;
|
|
@@ -426,7 +454,7 @@ interface EncodeCfParametersRequest {
|
|
|
426
454
|
quote: Quote | BoostQuote;
|
|
427
455
|
srcAddress?: string;
|
|
428
456
|
destAddress: string;
|
|
429
|
-
fillOrKillParams:
|
|
457
|
+
fillOrKillParams: FillOrKillParams;
|
|
430
458
|
affiliateBrokers?: {
|
|
431
459
|
account: `cF${string}` | `0x${string}`;
|
|
432
460
|
commissionBps: number;
|
|
@@ -487,7 +515,7 @@ declare class SwapSDK {
|
|
|
487
515
|
encodeCfParameters({ quote, srcAddress, destAddress, fillOrKillParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, }: EncodeCfParametersRequest): Promise<HexString>;
|
|
488
516
|
getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
|
|
489
517
|
quote: Quote;
|
|
490
|
-
fillOrKillParams:
|
|
518
|
+
fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
|
|
491
519
|
}): [
|
|
492
520
|
amount: string,
|
|
493
521
|
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
|
|
@@ -149,7 +150,7 @@ var ccmParamsSchema = z.object({
|
|
|
149
150
|
}).transform(({ gasBudget, message, ccmAdditionalData, cfParameters }) => ({
|
|
150
151
|
gasBudget,
|
|
151
152
|
message,
|
|
152
|
-
ccmAdditionalData: ccmAdditionalData ?? cfParameters
|
|
153
|
+
ccmAdditionalData: ccmAdditionalData ?? cfParameters ?? "0x"
|
|
153
154
|
}));
|
|
154
155
|
var affiliateBroker = z.object({
|
|
155
156
|
account: chainflipAddress,
|
|
@@ -692,6 +693,7 @@ var MultiCache = class {
|
|
|
692
693
|
}
|
|
693
694
|
};
|
|
694
695
|
var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber3(price).multipliedBy(new BigNumber3(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
|
|
696
|
+
var blocksPerMinute = 60 / CHAINFLIP_BLOCK_TIME_SECONDS;
|
|
695
697
|
function parseFoKParams(params, quote) {
|
|
696
698
|
const srcAsset = getInternalAsset(quote.srcAsset);
|
|
697
699
|
const destAsset = getInternalAsset(quote.destAsset);
|
|
@@ -716,11 +718,12 @@ function parseFoKParams(params, quote) {
|
|
|
716
718
|
} else {
|
|
717
719
|
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
718
720
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
retryDurationBlocks
|
|
721
|
+
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
722
|
+
const parsed = {
|
|
723
|
+
retryDurationBlocks,
|
|
722
724
|
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
|
|
723
725
|
};
|
|
726
|
+
return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
|
|
724
727
|
}
|
|
725
728
|
var isTestnet = (network) => network !== "mainnet";
|
|
726
729
|
var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
|
|
@@ -800,7 +803,7 @@ var getChainData = (chain2, network, env) => ({
|
|
|
800
803
|
|
|
801
804
|
// package.json
|
|
802
805
|
var package_default = {
|
|
803
|
-
version: "1.10.
|
|
806
|
+
version: "1.10.1"};
|
|
804
807
|
|
|
805
808
|
// src/swap/consts.ts
|
|
806
809
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainflip/sdk",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./swap": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@chainflip/bitcoin": "^1.2.6",
|
|
56
|
-
"@chainflip/rpc": "~1.
|
|
56
|
+
"@chainflip/rpc": "~1.11.0-beta.3",
|
|
57
57
|
"@chainflip/solana": "^2.1.9",
|
|
58
58
|
"@chainflip/utils": "^0.8.11",
|
|
59
59
|
"@ts-rest/core": "^3.52.1",
|