@chainflip/sdk 1.10.1 → 1.11.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-Q64VYHIA.js → chunk-EZ2C77JH.js} +89 -24
- package/dist/funding.cjs +10 -10
- package/dist/funding.js +1 -1
- package/dist/swap.cjs +166 -89
- package/dist/swap.d.cts +75 -10
- package/dist/swap.d.ts +75 -10
- package/dist/swap.js +76 -61
- package/package.json +5 -5
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { getInternalAsset, assetConstants } from '@chainflip/utils/chainflip';
|
|
2
|
+
import { CHAINFLIP_BLOCK_TIME_SECONDS } from '@chainflip/utils/consts';
|
|
3
|
+
import BigNumber from 'bignumber.js';
|
|
1
4
|
import { HttpClient, constants } from '@chainflip/rpc';
|
|
2
|
-
import { getInternalAsset } from '@chainflip/utils/chainflip';
|
|
3
5
|
|
|
4
6
|
// ../shared/src/guards.ts
|
|
5
7
|
var isNotNullish = (value) => value !== null && value !== void 0;
|
|
@@ -11,29 +13,67 @@ function assert(condition, message, Constructor = Error) {
|
|
|
11
13
|
}
|
|
12
14
|
throw error;
|
|
13
15
|
}
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
var getPriceX128FromPrice = (price, srcAsset, destAsset) => BigNumber(price).multipliedBy(new BigNumber(2).pow(128)).shiftedBy(assetConstants[destAsset].decimals - assetConstants[srcAsset].decimals).toFixed(0);
|
|
17
|
+
var blocksPerMinute = 60 / CHAINFLIP_BLOCK_TIME_SECONDS;
|
|
18
|
+
function parseFoKParams(params, quote) {
|
|
19
|
+
const srcAsset = getInternalAsset(quote.srcAsset);
|
|
20
|
+
const destAsset = getInternalAsset(quote.destAsset);
|
|
21
|
+
const livePriceProtectionDisabled = params.livePriceSlippageTolerancePercent === false;
|
|
22
|
+
const livePriceProtectionEnabled = typeof params.livePriceSlippageTolerancePercent === "string" || typeof params.livePriceSlippageTolerancePercent === "number";
|
|
23
|
+
const livePriceProtectionAvailable = isNotNullish(
|
|
24
|
+
quote.recommendedLivePriceSlippageTolerancePercent
|
|
20
25
|
);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
if (livePriceProtectionEnabled && !livePriceProtectionAvailable) {
|
|
27
|
+
throw new Error("Live price protection is not available for this asset pair");
|
|
28
|
+
}
|
|
29
|
+
let minPrice;
|
|
30
|
+
let livePriceSlippageTolerancePercent = null;
|
|
31
|
+
if (!livePriceProtectionDisabled) {
|
|
32
|
+
if (isNotNullish(params.livePriceSlippageTolerancePercent) && params.livePriceSlippageTolerancePercent !== false) {
|
|
33
|
+
livePriceSlippageTolerancePercent = new BigNumber(params.livePriceSlippageTolerancePercent);
|
|
34
|
+
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
35
|
+
assert(
|
|
36
|
+
livePriceSlippageTolerancePercent.gte(0) && livePriceSlippageTolerancePercent.lte(100),
|
|
37
|
+
"Live price slippage tolerance must be between 0 and 100 inclusive"
|
|
38
|
+
);
|
|
39
|
+
} else if (quote.recommendedLivePriceSlippageTolerancePercent) {
|
|
40
|
+
livePriceSlippageTolerancePercent = new BigNumber(
|
|
41
|
+
quote.recommendedLivePriceSlippageTolerancePercent
|
|
42
|
+
);
|
|
43
|
+
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if ("minPrice" in params) {
|
|
47
|
+
assert(
|
|
48
|
+
!("slippageTolerancePercent" in params),
|
|
49
|
+
"Cannot have both minPrice and slippageTolerancePercent"
|
|
50
|
+
);
|
|
51
|
+
minPrice = params.minPrice;
|
|
52
|
+
} else if ("slippageTolerancePercent" in params) {
|
|
53
|
+
const tolerance = new BigNumber(params.slippageTolerancePercent);
|
|
54
|
+
assert(!tolerance.isNaN(), "Invalid slippage tolerance");
|
|
55
|
+
assert(
|
|
56
|
+
tolerance.gte(0) && tolerance.lte(100),
|
|
57
|
+
"Slippage tolerance must be between 0 and 100 inclusive",
|
|
58
|
+
RangeError
|
|
59
|
+
);
|
|
60
|
+
const estimatedPrice = new BigNumber(quote.estimatedPrice);
|
|
61
|
+
assert(!estimatedPrice.isNaN(), "Invalid estimated price");
|
|
62
|
+
minPrice = estimatedPrice.times(new BigNumber(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
|
|
63
|
+
} else {
|
|
64
|
+
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
65
|
+
}
|
|
66
|
+
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
67
|
+
const maxOraclePriceSlippage = livePriceSlippageTolerancePercent?.multipliedBy(100).toNumber() ?? null;
|
|
68
|
+
const parsed = {
|
|
69
|
+
retryDurationBlocks,
|
|
70
|
+
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
|
|
71
|
+
maxOraclePriceSlippage,
|
|
72
|
+
refundCcmMetadata: params.refundCcmMetadata ?? null
|
|
73
|
+
};
|
|
74
|
+
return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
|
|
75
|
+
}
|
|
76
|
+
var isTestnet = (network) => network !== "mainnet";
|
|
37
77
|
|
|
38
78
|
// ../shared/src/consts.ts
|
|
39
79
|
var ETHEREUM_EVM_CHAIN_ID = {
|
|
@@ -102,5 +142,30 @@ var ADDRESSES = {
|
|
|
102
142
|
SOLUSDC_CONTRACT_ADDRESS: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
103
143
|
}
|
|
104
144
|
};
|
|
145
|
+
var ASSET_BLACKLIST = ["Dot"];
|
|
146
|
+
var envSafeAssetBlacklist = (network) => isTestnet(network) ? ASSET_BLACKLIST : [];
|
|
147
|
+
var camelCase = (str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
148
|
+
var camelCaseKeys = (obj) => {
|
|
149
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
150
|
+
if (Array.isArray(obj)) return obj.map((item) => camelCaseKeys(item));
|
|
151
|
+
return Object.fromEntries(
|
|
152
|
+
Object.entries(obj).map(([key, value]) => [camelCase(key), camelCaseKeys(value)])
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
var createRequest = (method) => async (urlOrNetwork, ...params) => {
|
|
156
|
+
const url = "network" in urlOrNetwork ? constants.PUBLIC_RPC_ENDPOINTS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
|
|
157
|
+
const result = await new HttpClient(url).sendRequest(method, ...params);
|
|
158
|
+
return camelCaseKeys(result);
|
|
159
|
+
};
|
|
160
|
+
var transform = (fn, cb) => (...args) => fn(...args).then(cb);
|
|
161
|
+
var getFundingEnvironment = createRequest("cf_funding_environment");
|
|
162
|
+
var getEnvironment = createRequest("cf_environment");
|
|
163
|
+
var getAllBoostPoolsDepth = transform(
|
|
164
|
+
createRequest("cf_boost_pools_depth"),
|
|
165
|
+
(result) => result.filter(({ chain }) => chain !== "Polkadot").map(({ chain, asset, ...rest }) => ({
|
|
166
|
+
asset: getInternalAsset({ chain, asset }),
|
|
167
|
+
...rest
|
|
168
|
+
}))
|
|
169
|
+
);
|
|
105
170
|
|
|
106
|
-
export { ADDRESSES, assert, getAllBoostPoolsDepth, getEnvironment, getEvmChainId, getFundingEnvironment, isNotNullish };
|
|
171
|
+
export { ADDRESSES, assert, envSafeAssetBlacklist, getAllBoostPoolsDepth, getEnvironment, getEvmChainId, getFundingEnvironment, isNotNullish, isTestnet, parseFoKParams };
|
package/dist/funding.cjs
CHANGED
|
@@ -752,6 +752,16 @@ var StateChainGateway__factory = class {
|
|
|
752
752
|
}
|
|
753
753
|
};
|
|
754
754
|
|
|
755
|
+
// ../shared/src/guards.ts
|
|
756
|
+
function assert(condition, message, Constructor = Error) {
|
|
757
|
+
if (condition) return;
|
|
758
|
+
const error = new Constructor(message);
|
|
759
|
+
if (error.stack) {
|
|
760
|
+
error.stack = error.stack.replace(/\n.+/, "\n");
|
|
761
|
+
}
|
|
762
|
+
throw error;
|
|
763
|
+
}
|
|
764
|
+
|
|
755
765
|
// ../shared/src/consts.ts
|
|
756
766
|
var SEPOLIA_USDC_CONTRACT_ADDRESS = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";
|
|
757
767
|
var SEPOLIA_USDT_CONTRACT_ADDRESS = "0x27CEA6Eb8a21Aae05Eb29C91c5CA10592892F584";
|
|
@@ -839,16 +849,6 @@ var getStateChainGateway = (networkOpts) => {
|
|
|
839
849
|
return StateChainGateway__factory.connect(stateChainGatewayContractAddress, networkOpts.signer);
|
|
840
850
|
};
|
|
841
851
|
|
|
842
|
-
// ../shared/src/guards.ts
|
|
843
|
-
function assert(condition, message, Constructor = Error) {
|
|
844
|
-
if (condition) return;
|
|
845
|
-
const error = new Constructor(message);
|
|
846
|
-
if (error.stack) {
|
|
847
|
-
error.stack = error.stack.replace(/\n.+/, "\n");
|
|
848
|
-
}
|
|
849
|
-
throw error;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
852
|
// ../shared/src/stateChainGateway/approval.ts
|
|
853
853
|
var checkStateChainGatewayAllowance = async (amount, networkOpts) => {
|
|
854
854
|
const flipContractAddress = networkOpts.network === "localnet" ? networkOpts.flipContractAddress : getFlipContractAddress(networkOpts.network);
|
package/dist/funding.js
CHANGED
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),
|
|
@@ -138,6 +139,13 @@ z6.z.object({
|
|
|
138
139
|
});
|
|
139
140
|
hadError = true;
|
|
140
141
|
}
|
|
142
|
+
if (srcAsset === "Dot" || destAsset === "Dot") {
|
|
143
|
+
ctx.addIssue({
|
|
144
|
+
message: "Dot is not supported",
|
|
145
|
+
code: z6.z.ZodIssueCode.custom
|
|
146
|
+
});
|
|
147
|
+
hadError = true;
|
|
148
|
+
}
|
|
141
149
|
if (args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes === void 0) {
|
|
142
150
|
ctx.addIssue({
|
|
143
151
|
message: `ccmMessageLengthBytes must be set if ccmGasBudget is set`,
|
|
@@ -203,7 +211,15 @@ var dcaParams = z6.z.object({
|
|
|
203
211
|
var fillOrKillParams = z6.z.object({
|
|
204
212
|
retryDurationBlocks: z6.z.number(),
|
|
205
213
|
refundAddress: z6.z.string(),
|
|
206
|
-
minPriceX128: numericString
|
|
214
|
+
minPriceX128: numericString,
|
|
215
|
+
maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null),
|
|
216
|
+
refundCcmMetadata: ccmParamsSchema.nullish().optional().default(null).transform(
|
|
217
|
+
(v) => v && {
|
|
218
|
+
...v,
|
|
219
|
+
cfParameters: v.ccmAdditionalData
|
|
220
|
+
// deprecated
|
|
221
|
+
}
|
|
222
|
+
)
|
|
207
223
|
});
|
|
208
224
|
var validatePolkadotAddress = (address) => {
|
|
209
225
|
if (string.isHex(address)) return address.length === 66;
|
|
@@ -264,15 +280,6 @@ var validators = {
|
|
|
264
280
|
var validateAddress = (chain2, address, network) => validators[network][chain2](address);
|
|
265
281
|
|
|
266
282
|
// ../shared/src/broker.ts
|
|
267
|
-
var transformedFokSchema = z6.z.object({
|
|
268
|
-
retryDurationBlocks: z6.z.number(),
|
|
269
|
-
refundAddress: z6.z.string(),
|
|
270
|
-
minPriceX128: numericString
|
|
271
|
-
}).transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
|
|
272
|
-
retry_duration: retryDurationBlocks,
|
|
273
|
-
refund_address: refundAddress,
|
|
274
|
-
min_price: `0x${BigInt(minPriceX128).toString(16)}`
|
|
275
|
-
}));
|
|
276
283
|
var transformedDcaParamsSchema = dcaParams.transform(
|
|
277
284
|
({ numberOfChunks, chunkIntervalBlocks }) => ({
|
|
278
285
|
number_of_chunks: numberOfChunks,
|
|
@@ -288,6 +295,27 @@ var transformedCcmParamsSchema = ccmParamsSchema.transform(
|
|
|
288
295
|
cf_parameters: ccmAdditionalData
|
|
289
296
|
})
|
|
290
297
|
);
|
|
298
|
+
var transformedFokSchema = z6.z.object({
|
|
299
|
+
retryDurationBlocks: z6.z.number(),
|
|
300
|
+
refundAddress: z6.z.string(),
|
|
301
|
+
minPriceX128: numericString,
|
|
302
|
+
maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null),
|
|
303
|
+
refundCcmMetadata: transformedCcmParamsSchema.nullable().optional().default(null)
|
|
304
|
+
}).transform(
|
|
305
|
+
({
|
|
306
|
+
retryDurationBlocks,
|
|
307
|
+
refundAddress,
|
|
308
|
+
minPriceX128,
|
|
309
|
+
maxOraclePriceSlippage,
|
|
310
|
+
refundCcmMetadata
|
|
311
|
+
}) => ({
|
|
312
|
+
retry_duration: retryDurationBlocks,
|
|
313
|
+
refund_address: refundAddress,
|
|
314
|
+
min_price: `0x${BigInt(minPriceX128).toString(16)}`,
|
|
315
|
+
max_oracle_price_slippage: maxOraclePriceSlippage,
|
|
316
|
+
refund_ccm_metadata: refundCcmMetadata
|
|
317
|
+
})
|
|
318
|
+
);
|
|
291
319
|
var getDepositAddressRequestSchema = (network) => z6.z.object({
|
|
292
320
|
srcAsset: assetAndChain,
|
|
293
321
|
destAsset: assetAndChain,
|
|
@@ -305,7 +333,6 @@ var getDepositAddressRequestSchema = (network) => z6.z.object({
|
|
|
305
333
|
code: z6.z.ZodIssueCode.custom
|
|
306
334
|
});
|
|
307
335
|
}
|
|
308
|
-
}).superRefine((val, ctx) => {
|
|
309
336
|
if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
|
|
310
337
|
ctx.addIssue({
|
|
311
338
|
message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
|
|
@@ -325,7 +352,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z6.z.object({
|
|
|
325
352
|
affiliates: z6.z.array(affiliateBroker).optional(),
|
|
326
353
|
fillOrKillParams: transformedFokSchema,
|
|
327
354
|
dcaParams: transformedDcaParamsSchema.optional(),
|
|
328
|
-
extraParams: z6.z.object({ seed: hexString.optional() }).optional()
|
|
355
|
+
extraParams: z6.z.object({ seed: hexString.optional() }).optional(),
|
|
356
|
+
brokerAccount: chainflipAddress.optional()
|
|
329
357
|
}).superRefine((val, ctx) => {
|
|
330
358
|
if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
|
|
331
359
|
ctx.addIssue({
|
|
@@ -355,7 +383,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z6.z.object({
|
|
|
355
383
|
extraParams = {
|
|
356
384
|
chain: "Bitcoin",
|
|
357
385
|
min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
|
|
358
|
-
retry_duration: data.fillOrKillParams.retry_duration
|
|
386
|
+
retry_duration: data.fillOrKillParams.retry_duration,
|
|
387
|
+
max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
|
|
359
388
|
};
|
|
360
389
|
} else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
|
|
361
390
|
extraParams = {
|
|
@@ -399,7 +428,6 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork) {
|
|
|
399
428
|
params.dcaParams
|
|
400
429
|
);
|
|
401
430
|
switch (params.srcAsset.chain) {
|
|
402
|
-
case "Polkadot":
|
|
403
431
|
case "Assethub":
|
|
404
432
|
if (string.isHex(response.address)) {
|
|
405
433
|
response.address = ss58__namespace.encode({ data: response.address, ss58Format: DOT_PREFIX });
|
|
@@ -499,10 +527,24 @@ var TransformedCcmParams = ccmParamsSchema.transform(
|
|
|
499
527
|
})
|
|
500
528
|
);
|
|
501
529
|
var FillOrKillParams = fillOrKillParams.transform(
|
|
502
|
-
({
|
|
530
|
+
({
|
|
531
|
+
retryDurationBlocks,
|
|
532
|
+
refundAddress,
|
|
533
|
+
minPriceX128,
|
|
534
|
+
maxOraclePriceSlippage,
|
|
535
|
+
refundCcmMetadata
|
|
536
|
+
}) => ({
|
|
503
537
|
retry_duration: retryDurationBlocks,
|
|
504
538
|
refund_address: refundAddress,
|
|
505
|
-
min_price: `0x${BigInt(minPriceX128).toString(16)}
|
|
539
|
+
min_price: `0x${BigInt(minPriceX128).toString(16)}`,
|
|
540
|
+
max_oracle_price_slippage: maxOraclePriceSlippage,
|
|
541
|
+
refund_ccm_metadata: refundCcmMetadata && {
|
|
542
|
+
gas_budget: refundCcmMetadata.gasBudget,
|
|
543
|
+
message: refundCcmMetadata.message,
|
|
544
|
+
ccm_additional_data: refundCcmMetadata.ccmAdditionalData,
|
|
545
|
+
/** @deprecated DEPRECATED(1.10) */
|
|
546
|
+
cf_parameters: refundCcmMetadata.cfParameters
|
|
547
|
+
}
|
|
506
548
|
})
|
|
507
549
|
);
|
|
508
550
|
var TransformedDcaParams = dcaParams.transform(
|
|
@@ -524,7 +566,8 @@ var EncodeVaultSwapBody = z6.z.object({
|
|
|
524
566
|
fillOrKillParams: FillOrKillParams,
|
|
525
567
|
dcaParams: TransformedDcaParams.optional(),
|
|
526
568
|
extraParams: z6.z.object({ seed: hexString.optional() }).optional(),
|
|
527
|
-
network: z6.z.enum(chainflip.chainflipNetworks)
|
|
569
|
+
network: z6.z.enum(chainflip.chainflipNetworks),
|
|
570
|
+
brokerAccount: chainflipAddress.optional()
|
|
528
571
|
}).superRefine(({ network, ...val }, ctx) => {
|
|
529
572
|
if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
|
|
530
573
|
ctx.addIssue({
|
|
@@ -550,11 +593,12 @@ var EncodeVaultSwapBody = z6.z.object({
|
|
|
550
593
|
}).transform(({ network, ...data }) => {
|
|
551
594
|
let extraParams;
|
|
552
595
|
if (data.srcAsset.chain === "Bitcoin") {
|
|
553
|
-
const minOutputAmount = BigNumber(data.amount.toString()).multipliedBy(tickMath.priceX128ToPrice(data.fillOrKillParams.min_price)).toFixed(0);
|
|
596
|
+
const minOutputAmount = BigNumber3.BigNumber(data.amount.toString()).multipliedBy(tickMath.priceX128ToPrice(data.fillOrKillParams.min_price)).toFixed(0);
|
|
554
597
|
extraParams = {
|
|
555
598
|
chain: "Bitcoin",
|
|
556
599
|
min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
|
|
557
|
-
retry_duration: data.fillOrKillParams.retry_duration
|
|
600
|
+
retry_duration: data.fillOrKillParams.retry_duration,
|
|
601
|
+
max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
|
|
558
602
|
};
|
|
559
603
|
} else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
|
|
560
604
|
extraParams = {
|
|
@@ -641,7 +685,8 @@ var OpenSwapDepositChannelBody = z6.z.object({
|
|
|
641
685
|
intermediateAmount: z6.z.string().optional(),
|
|
642
686
|
egressAmount: z6.z.string(),
|
|
643
687
|
estimatedPrice: z6.z.string(),
|
|
644
|
-
recommendedSlippageTolerancePercent: z6.z.number().optional()
|
|
688
|
+
recommendedSlippageTolerancePercent: z6.z.number().optional(),
|
|
689
|
+
recommendedLivePriceSlippageTolerancePercent: z6.z.number().optional()
|
|
645
690
|
}).optional(),
|
|
646
691
|
takeCommission: z6.z.boolean().optional()
|
|
647
692
|
}).transform(({ amount, ...rest }) => ({
|
|
@@ -709,35 +754,36 @@ var apiContract = c.router(
|
|
|
709
754
|
pathPrefix: "/api"
|
|
710
755
|
}
|
|
711
756
|
);
|
|
712
|
-
|
|
713
|
-
// ../shared/src/dataStructures.ts
|
|
714
|
-
var MultiCache = class {
|
|
715
|
-
constructor(fetchers) {
|
|
716
|
-
this.fetchers = fetchers;
|
|
717
|
-
}
|
|
718
|
-
values = {};
|
|
719
|
-
read(type) {
|
|
720
|
-
const { fetch, ttl } = this.fetchers[type];
|
|
721
|
-
let cached = this.values[type];
|
|
722
|
-
if (!cached || cached.timestamp + ttl < Date.now()) {
|
|
723
|
-
cached = {
|
|
724
|
-
timestamp: Date.now(),
|
|
725
|
-
value: fetch().catch((err) => {
|
|
726
|
-
this.values[type] = void 0;
|
|
727
|
-
throw err;
|
|
728
|
-
})
|
|
729
|
-
};
|
|
730
|
-
this.values[type] = cached;
|
|
731
|
-
}
|
|
732
|
-
return cached.value;
|
|
733
|
-
}
|
|
734
|
-
};
|
|
735
757
|
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
758
|
var blocksPerMinute = 60 / consts.CHAINFLIP_BLOCK_TIME_SECONDS;
|
|
737
759
|
function parseFoKParams(params, quote) {
|
|
738
760
|
const srcAsset = chainflip.getInternalAsset(quote.srcAsset);
|
|
739
761
|
const destAsset = chainflip.getInternalAsset(quote.destAsset);
|
|
762
|
+
const livePriceProtectionDisabled = params.livePriceSlippageTolerancePercent === false;
|
|
763
|
+
const livePriceProtectionEnabled = typeof params.livePriceSlippageTolerancePercent === "string" || typeof params.livePriceSlippageTolerancePercent === "number";
|
|
764
|
+
const livePriceProtectionAvailable = isNotNullish(
|
|
765
|
+
quote.recommendedLivePriceSlippageTolerancePercent
|
|
766
|
+
);
|
|
767
|
+
if (livePriceProtectionEnabled && !livePriceProtectionAvailable) {
|
|
768
|
+
throw new Error("Live price protection is not available for this asset pair");
|
|
769
|
+
}
|
|
740
770
|
let minPrice;
|
|
771
|
+
let livePriceSlippageTolerancePercent = null;
|
|
772
|
+
if (!livePriceProtectionDisabled) {
|
|
773
|
+
if (isNotNullish(params.livePriceSlippageTolerancePercent) && params.livePriceSlippageTolerancePercent !== false) {
|
|
774
|
+
livePriceSlippageTolerancePercent = new BigNumber3__default.default(params.livePriceSlippageTolerancePercent);
|
|
775
|
+
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
776
|
+
assert(
|
|
777
|
+
livePriceSlippageTolerancePercent.gte(0) && livePriceSlippageTolerancePercent.lte(100),
|
|
778
|
+
"Live price slippage tolerance must be between 0 and 100 inclusive"
|
|
779
|
+
);
|
|
780
|
+
} else if (quote.recommendedLivePriceSlippageTolerancePercent) {
|
|
781
|
+
livePriceSlippageTolerancePercent = new BigNumber3__default.default(
|
|
782
|
+
quote.recommendedLivePriceSlippageTolerancePercent
|
|
783
|
+
);
|
|
784
|
+
assert(!livePriceSlippageTolerancePercent.isNaN(), "Invalid live price slippage tolerance");
|
|
785
|
+
}
|
|
786
|
+
}
|
|
741
787
|
if ("minPrice" in params) {
|
|
742
788
|
assert(
|
|
743
789
|
!("slippageTolerancePercent" in params),
|
|
@@ -759,53 +805,16 @@ function parseFoKParams(params, quote) {
|
|
|
759
805
|
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
760
806
|
}
|
|
761
807
|
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
808
|
+
const maxOraclePriceSlippage = livePriceSlippageTolerancePercent?.multipliedBy(100).toNumber() ?? null;
|
|
762
809
|
const parsed = {
|
|
763
810
|
retryDurationBlocks,
|
|
764
|
-
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
|
|
811
|
+
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset),
|
|
812
|
+
maxOraclePriceSlippage,
|
|
813
|
+
refundCcmMetadata: params.refundCcmMetadata ?? null
|
|
765
814
|
};
|
|
766
815
|
return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
|
|
767
816
|
}
|
|
768
817
|
var isTestnet = (network) => network !== "mainnet";
|
|
769
|
-
var camelCase = (str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
770
|
-
var camelCaseKeys = (obj) => {
|
|
771
|
-
if (typeof obj !== "object" || obj === null) return obj;
|
|
772
|
-
if (Array.isArray(obj)) return obj.map((item) => camelCaseKeys(item));
|
|
773
|
-
return Object.fromEntries(
|
|
774
|
-
Object.entries(obj).map(([key, value]) => [camelCase(key), camelCaseKeys(value)])
|
|
775
|
-
);
|
|
776
|
-
};
|
|
777
|
-
var createRequest = (method) => async (urlOrNetwork, ...params) => {
|
|
778
|
-
const url = "network" in urlOrNetwork ? rpc.constants.PUBLIC_RPC_ENDPOINTS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
|
|
779
|
-
const result = await new rpc.HttpClient(url).sendRequest(method, ...params);
|
|
780
|
-
return camelCaseKeys(result);
|
|
781
|
-
};
|
|
782
|
-
var transform = (fn, cb) => (...args) => fn(...args).then(cb);
|
|
783
|
-
var getEnvironment = createRequest("cf_environment");
|
|
784
|
-
var getAllBoostPoolsDepth = transform(
|
|
785
|
-
createRequest("cf_boost_pools_depth"),
|
|
786
|
-
(result) => result.map(({ chain: chain2, asset: asset2, ...rest }) => ({
|
|
787
|
-
asset: chainflip.getInternalAsset({ chain: chain2, asset: asset2 }),
|
|
788
|
-
...rest
|
|
789
|
-
}))
|
|
790
|
-
);
|
|
791
|
-
var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
|
|
792
|
-
var validateSwapAmount = (env, asset2, amount) => {
|
|
793
|
-
const minimumAmount = chainflip.readAssetValue(env.ingressEgress.minimumDepositAmounts, asset2);
|
|
794
|
-
if (amount < minimumAmount) {
|
|
795
|
-
return {
|
|
796
|
-
success: false,
|
|
797
|
-
reason: `expected amount is below minimum swap amount (${minimumAmount})`
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
const maxAmount = chainflip.readAssetValue(env.swapping.maximumSwapAmounts, asset2) ?? MAX_SWAP_AMOUNT;
|
|
801
|
-
if (maxAmount != null && amount > maxAmount) {
|
|
802
|
-
return {
|
|
803
|
-
success: false,
|
|
804
|
-
reason: `expected amount is above maximum swap amount (${maxAmount})`
|
|
805
|
-
};
|
|
806
|
-
}
|
|
807
|
-
return { success: true };
|
|
808
|
-
};
|
|
809
818
|
|
|
810
819
|
// ../shared/src/consts.ts
|
|
811
820
|
var ETHEREUM_EVM_CHAIN_ID = {
|
|
@@ -874,8 +883,71 @@ var ADDRESSES = {
|
|
|
874
883
|
SOLUSDC_CONTRACT_ADDRESS: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
875
884
|
}
|
|
876
885
|
};
|
|
886
|
+
var ASSET_BLACKLIST = ["Dot"];
|
|
887
|
+
var envSafeAssetBlacklist = (network) => isTestnet(network) ? ASSET_BLACKLIST : [];
|
|
877
888
|
|
|
878
|
-
// src/
|
|
889
|
+
// ../shared/src/dataStructures.ts
|
|
890
|
+
var MultiCache = class {
|
|
891
|
+
constructor(fetchers) {
|
|
892
|
+
this.fetchers = fetchers;
|
|
893
|
+
}
|
|
894
|
+
values = {};
|
|
895
|
+
read(type) {
|
|
896
|
+
const { fetch, ttl } = this.fetchers[type];
|
|
897
|
+
let cached = this.values[type];
|
|
898
|
+
if (!cached || cached.timestamp + ttl < Date.now()) {
|
|
899
|
+
cached = {
|
|
900
|
+
timestamp: Date.now(),
|
|
901
|
+
value: fetch().catch((err) => {
|
|
902
|
+
this.values[type] = void 0;
|
|
903
|
+
throw err;
|
|
904
|
+
})
|
|
905
|
+
};
|
|
906
|
+
this.values[type] = cached;
|
|
907
|
+
}
|
|
908
|
+
return cached.value;
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
var camelCase = (str) => str.replace(/_([a-z])/g, (_, char) => char.toUpperCase());
|
|
912
|
+
var camelCaseKeys = (obj) => {
|
|
913
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
914
|
+
if (Array.isArray(obj)) return obj.map((item) => camelCaseKeys(item));
|
|
915
|
+
return Object.fromEntries(
|
|
916
|
+
Object.entries(obj).map(([key, value]) => [camelCase(key), camelCaseKeys(value)])
|
|
917
|
+
);
|
|
918
|
+
};
|
|
919
|
+
var createRequest = (method) => async (urlOrNetwork, ...params) => {
|
|
920
|
+
const url = "network" in urlOrNetwork ? rpc.constants.PUBLIC_RPC_ENDPOINTS[urlOrNetwork.network] : urlOrNetwork.rpcUrl;
|
|
921
|
+
const result = await new rpc.HttpClient(url).sendRequest(method, ...params);
|
|
922
|
+
return camelCaseKeys(result);
|
|
923
|
+
};
|
|
924
|
+
var transform = (fn, cb) => (...args) => fn(...args).then(cb);
|
|
925
|
+
var getEnvironment = createRequest("cf_environment");
|
|
926
|
+
var getAllBoostPoolsDepth = transform(
|
|
927
|
+
createRequest("cf_boost_pools_depth"),
|
|
928
|
+
(result) => result.filter(({ chain: chain2 }) => chain2 !== "Polkadot").map(({ chain: chain2, asset: asset2, ...rest }) => ({
|
|
929
|
+
asset: chainflip.getInternalAsset({ chain: chain2, asset: asset2 }),
|
|
930
|
+
...rest
|
|
931
|
+
}))
|
|
932
|
+
);
|
|
933
|
+
var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
|
|
934
|
+
var validateSwapAmount = (env, asset2, amount) => {
|
|
935
|
+
const minimumAmount = chainflip.readAssetValue(env.ingressEgress.minimumDepositAmounts, asset2);
|
|
936
|
+
if (amount < minimumAmount) {
|
|
937
|
+
return {
|
|
938
|
+
success: false,
|
|
939
|
+
reason: `expected amount is below minimum swap amount (${minimumAmount})`
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
const maxAmount = chainflip.readAssetValue(env.swapping.maximumSwapAmounts, asset2) ?? MAX_SWAP_AMOUNT;
|
|
943
|
+
if (maxAmount != null && amount > maxAmount) {
|
|
944
|
+
return {
|
|
945
|
+
success: false,
|
|
946
|
+
reason: `expected amount is above maximum swap amount (${maxAmount})`
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
return { success: true };
|
|
950
|
+
};
|
|
879
951
|
var getTokenContractAddress = (asset2, network) => {
|
|
880
952
|
switch (asset2) {
|
|
881
953
|
case "Btc":
|
|
@@ -929,13 +1001,15 @@ var getChainData = (chain2, network, env) => ({
|
|
|
929
1001
|
name: chain2,
|
|
930
1002
|
evmChainId: getEvmChainId(chain2, network),
|
|
931
1003
|
isMainnet: !isTestnet(network),
|
|
932
|
-
requiredBlockConfirmations: isNotNullish(
|
|
1004
|
+
requiredBlockConfirmations: isNotNullish(
|
|
1005
|
+
env.ingressEgress.witnessSafetyMargins[chain2]
|
|
1006
|
+
) ? Number(env.ingressEgress.witnessSafetyMargins[chain2]) + 1 : void 0,
|
|
933
1007
|
maxRetryDurationBlocks: env.swapping.maxSwapRetryDurationBlocks
|
|
934
1008
|
});
|
|
935
1009
|
|
|
936
1010
|
// package.json
|
|
937
1011
|
var package_default = {
|
|
938
|
-
version: "1.
|
|
1012
|
+
version: "1.11.0-beta.2"};
|
|
939
1013
|
|
|
940
1014
|
// src/swap/consts.ts
|
|
941
1015
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
|
@@ -1000,6 +1074,7 @@ var SwapSDK = class {
|
|
|
1000
1074
|
apiClient;
|
|
1001
1075
|
cache;
|
|
1002
1076
|
dcaEnabled = false;
|
|
1077
|
+
blackListedAssets;
|
|
1003
1078
|
constructor(options = {}) {
|
|
1004
1079
|
const network = options.network ?? "perseverance";
|
|
1005
1080
|
this.options = {
|
|
@@ -1029,6 +1104,7 @@ var SwapSDK = class {
|
|
|
1029
1104
|
ttl: 6e4
|
|
1030
1105
|
}
|
|
1031
1106
|
});
|
|
1107
|
+
this.blackListedAssets = envSafeAssetBlacklist(this.options.network);
|
|
1032
1108
|
}
|
|
1033
1109
|
async getChains(sourceChain, type = "all") {
|
|
1034
1110
|
if (sourceChain && !chainflip.chainflipChains.includes(sourceChain)) {
|
|
@@ -1047,7 +1123,7 @@ var SwapSDK = class {
|
|
|
1047
1123
|
}
|
|
1048
1124
|
async getSupportedAssets(type) {
|
|
1049
1125
|
const assets = await this.cache.read("networkInfo");
|
|
1050
|
-
return assets.assets.filter((a) => {
|
|
1126
|
+
return assets.assets.filter((a) => !this.blackListedAssets.includes(a.asset)).filter((a) => {
|
|
1051
1127
|
switch (type) {
|
|
1052
1128
|
case "all":
|
|
1053
1129
|
return true;
|
|
@@ -1119,7 +1195,7 @@ var SwapSDK = class {
|
|
|
1119
1195
|
const {
|
|
1120
1196
|
ingressEgress: { witnessSafetyMargins }
|
|
1121
1197
|
} = await this.getStateChainEnvironment();
|
|
1122
|
-
return chainflip.chainflipChains.reduce(
|
|
1198
|
+
return chainflip.chainflipChains.filter((chain2) => chain2 !== "Polkadot").reduce(
|
|
1123
1199
|
(acc, chain2) => {
|
|
1124
1200
|
acc[chain2] = witnessSafetyMargins[chain2] ? Number(witnessSafetyMargins[chain2]) + 1 : null;
|
|
1125
1201
|
return acc;
|
|
@@ -1354,6 +1430,7 @@ var SwapSDK = class {
|
|
|
1354
1430
|
}
|
|
1355
1431
|
return res.body;
|
|
1356
1432
|
}
|
|
1433
|
+
/** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
|
|
1357
1434
|
// eslint-disable-next-line class-methods-use-this
|
|
1358
1435
|
getOnChainSwapExtrinsicArgs({
|
|
1359
1436
|
quote,
|
package/dist/swap.d.cts
CHANGED
|
@@ -65,14 +65,65 @@ 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>;
|
|
69
|
+
refundCcmMetadata: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodObject<{
|
|
70
|
+
gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
|
|
71
|
+
message: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
|
|
72
|
+
ccmAdditionalData: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
|
|
73
|
+
/** @deprecated DEPRECATED(1.10) pass additionalData instead */
|
|
74
|
+
cfParameters: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
message: `0x${string}`;
|
|
77
|
+
gasBudget: `0x${string}`;
|
|
78
|
+
ccmAdditionalData?: `0x${string}` | undefined;
|
|
79
|
+
cfParameters?: `0x${string}` | undefined;
|
|
80
|
+
}, {
|
|
81
|
+
message: string;
|
|
82
|
+
gasBudget: string;
|
|
83
|
+
ccmAdditionalData?: string | undefined;
|
|
84
|
+
cfParameters?: string | undefined;
|
|
85
|
+
}>, {
|
|
86
|
+
gasBudget: `0x${string}`;
|
|
87
|
+
message: `0x${string}`;
|
|
88
|
+
ccmAdditionalData: `0x${string}`;
|
|
89
|
+
}, {
|
|
90
|
+
message: string;
|
|
91
|
+
gasBudget: string;
|
|
92
|
+
ccmAdditionalData?: string | undefined;
|
|
93
|
+
cfParameters?: string | undefined;
|
|
94
|
+
}>>>>>, {
|
|
95
|
+
cfParameters: `0x${string}`;
|
|
96
|
+
gasBudget: `0x${string}`;
|
|
97
|
+
message: `0x${string}`;
|
|
98
|
+
ccmAdditionalData: `0x${string}`;
|
|
99
|
+
} | null, {
|
|
100
|
+
message: string;
|
|
101
|
+
gasBudget: string;
|
|
102
|
+
ccmAdditionalData?: string | undefined;
|
|
103
|
+
cfParameters?: string | undefined;
|
|
104
|
+
} | null | undefined>;
|
|
68
105
|
}, "strip", z.ZodTypeAny, {
|
|
69
106
|
retryDurationBlocks: number;
|
|
70
107
|
refundAddress: string;
|
|
71
108
|
minPriceX128: string;
|
|
109
|
+
maxOraclePriceSlippage: number | null;
|
|
110
|
+
refundCcmMetadata: {
|
|
111
|
+
cfParameters: `0x${string}`;
|
|
112
|
+
gasBudget: `0x${string}`;
|
|
113
|
+
message: `0x${string}`;
|
|
114
|
+
ccmAdditionalData: `0x${string}`;
|
|
115
|
+
} | null;
|
|
72
116
|
}, {
|
|
73
117
|
retryDurationBlocks: number;
|
|
74
118
|
refundAddress: string;
|
|
75
119
|
minPriceX128: string;
|
|
120
|
+
maxOraclePriceSlippage?: number | null | undefined;
|
|
121
|
+
refundCcmMetadata?: {
|
|
122
|
+
message: string;
|
|
123
|
+
gasBudget: string;
|
|
124
|
+
ccmAdditionalData?: string | undefined;
|
|
125
|
+
cfParameters?: string | undefined;
|
|
126
|
+
} | null | undefined;
|
|
76
127
|
}>;
|
|
77
128
|
type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
|
|
78
129
|
type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
|
|
@@ -118,6 +169,7 @@ interface BaseQuoteDetails {
|
|
|
118
169
|
estimatedPrice: string;
|
|
119
170
|
recommendedSlippageTolerancePercent: number;
|
|
120
171
|
recommendedRetryDurationMinutes: number;
|
|
172
|
+
recommendedLivePriceSlippageTolerancePercent: number | undefined;
|
|
121
173
|
}
|
|
122
174
|
type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
|
|
123
175
|
interface RegularQuote extends BaseQuoteDetails {
|
|
@@ -134,6 +186,9 @@ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
|
|
|
134
186
|
type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
|
|
135
187
|
type BoostQuote = RegularBoostQuote | DCABoostQuote;
|
|
136
188
|
type FillOrKillParamsWithoutRefundAddress = {
|
|
189
|
+
livePriceSlippageTolerancePercent?: string | number | false;
|
|
190
|
+
refundCcmMetadata?: CcmParams | null;
|
|
191
|
+
} & ({
|
|
137
192
|
minPrice: string;
|
|
138
193
|
retryDurationBlocks: number;
|
|
139
194
|
} | {
|
|
@@ -145,24 +200,24 @@ type FillOrKillParamsWithoutRefundAddress = {
|
|
|
145
200
|
} | {
|
|
146
201
|
slippageTolerancePercent: string | number;
|
|
147
202
|
retryDurationMinutes: number;
|
|
148
|
-
};
|
|
203
|
+
});
|
|
149
204
|
type FillOrKillParams = {
|
|
205
|
+
livePriceSlippageTolerancePercent?: string | number | false;
|
|
150
206
|
refundAddress: string;
|
|
207
|
+
refundCcmMetadata?: CcmParams | null;
|
|
208
|
+
} & ({
|
|
151
209
|
minPrice: string;
|
|
152
210
|
retryDurationBlocks: number;
|
|
153
211
|
} | {
|
|
154
|
-
refundAddress: string;
|
|
155
212
|
minPrice: string;
|
|
156
213
|
retryDurationMinutes: number;
|
|
157
214
|
} | {
|
|
158
|
-
refundAddress: string;
|
|
159
215
|
slippageTolerancePercent: string | number;
|
|
160
216
|
retryDurationBlocks: number;
|
|
161
217
|
} | {
|
|
162
|
-
refundAddress: string;
|
|
163
218
|
slippageTolerancePercent: string | number;
|
|
164
219
|
retryDurationMinutes: number;
|
|
165
|
-
};
|
|
220
|
+
});
|
|
166
221
|
|
|
167
222
|
interface ChainData {
|
|
168
223
|
chain: ChainflipChain;
|
|
@@ -173,8 +228,8 @@ interface ChainData {
|
|
|
173
228
|
maxRetryDurationBlocks: number | undefined;
|
|
174
229
|
}
|
|
175
230
|
type AssetData = {
|
|
176
|
-
[C in ChainflipChain]: {
|
|
177
|
-
chainflipId: ChainflipAsset
|
|
231
|
+
[C in Exclude<ChainflipChain, 'Polkadot'>]: {
|
|
232
|
+
chainflipId: Exclude<ChainflipAsset, 'Dot'>;
|
|
178
233
|
asset: AssetOfChain<C>;
|
|
179
234
|
chain: C;
|
|
180
235
|
contractAddress: string | undefined;
|
|
@@ -186,11 +241,11 @@ type AssetData = {
|
|
|
186
241
|
maximumSwapAmount: string | null;
|
|
187
242
|
minimumEgressAmount: string;
|
|
188
243
|
};
|
|
189
|
-
}[ChainflipChain];
|
|
244
|
+
}[Exclude<ChainflipChain, 'Polkadot'>];
|
|
190
245
|
interface ChainsAndAssets {
|
|
191
|
-
srcChain: ChainflipChain
|
|
246
|
+
srcChain: Exclude<ChainflipChain, 'Polkadot'>;
|
|
192
247
|
srcAsset: AssetSymbol;
|
|
193
|
-
destChain: ChainflipChain
|
|
248
|
+
destChain: Exclude<ChainflipChain, 'Polkadot'>;
|
|
194
249
|
destAsset: AssetSymbol;
|
|
195
250
|
}
|
|
196
251
|
interface QuoteRequest extends ChainsAndAssets {
|
|
@@ -220,6 +275,7 @@ type BoostPoolDepth = {
|
|
|
220
275
|
chain: ChainflipChain;
|
|
221
276
|
};
|
|
222
277
|
|
|
278
|
+
type ChunkFailureReason = 'PriceImpactLimit' | 'MinPriceViolation' | 'OraclePriceSlippageExceeded' | 'OraclePriceStale' | 'PredecessorSwapFailure' | 'SafeModeActive';
|
|
223
279
|
interface Failure {
|
|
224
280
|
failedAt: number;
|
|
225
281
|
failedBlockIndex: string;
|
|
@@ -278,6 +334,12 @@ type ChunkInfo = {
|
|
|
278
334
|
executedAt: number | undefined;
|
|
279
335
|
executedBlockIndex: string | undefined;
|
|
280
336
|
retryCount: number;
|
|
337
|
+
rescheduledAt: number | undefined;
|
|
338
|
+
rescheduledBlockIndex: string | undefined;
|
|
339
|
+
rescheduledReason: ChunkFailureReason | undefined;
|
|
340
|
+
abortedAt: number | undefined;
|
|
341
|
+
abortedBlockIndex: string | undefined;
|
|
342
|
+
abortedReason: ChunkFailureReason | undefined;
|
|
281
343
|
};
|
|
282
344
|
type PickRequired<T> = {
|
|
283
345
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
@@ -288,6 +350,7 @@ interface SwapFields {
|
|
|
288
350
|
swappedInputAmount: string;
|
|
289
351
|
swappedIntermediateAmount: string;
|
|
290
352
|
swappedOutputAmount: string;
|
|
353
|
+
livePriceExecutionDeltaPercentage: number | undefined;
|
|
291
354
|
regular: ChunkInfo | undefined;
|
|
292
355
|
dca: {
|
|
293
356
|
lastExecutedChunk: ChunkInfo | null;
|
|
@@ -488,6 +551,7 @@ declare class SwapSDK {
|
|
|
488
551
|
private readonly apiClient;
|
|
489
552
|
private cache;
|
|
490
553
|
private dcaEnabled;
|
|
554
|
+
private blackListedAssets;
|
|
491
555
|
constructor(options?: SwapSDKOptions);
|
|
492
556
|
getChains(sourceChain?: ChainflipChain, type?: AssetState): Promise<ChainData[]>;
|
|
493
557
|
private getStateChainEnvironment;
|
|
@@ -513,6 +577,7 @@ declare class SwapSDK {
|
|
|
513
577
|
requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
|
|
514
578
|
encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
|
|
515
579
|
encodeCfParameters({ quote, srcAddress, destAddress, fillOrKillParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, }: EncodeCfParametersRequest): Promise<HexString>;
|
|
580
|
+
/** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
|
|
516
581
|
getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
|
|
517
582
|
quote: Quote;
|
|
518
583
|
fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
|
package/dist/swap.d.ts
CHANGED
|
@@ -65,14 +65,65 @@ 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>;
|
|
69
|
+
refundCcmMetadata: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodEffects<z.ZodObject<{
|
|
70
|
+
gasBudget: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodEffects<z.ZodString, `0x${string}`, string>]>, `0x${string}`, string>;
|
|
71
|
+
message: z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>;
|
|
72
|
+
ccmAdditionalData: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
|
|
73
|
+
/** @deprecated DEPRECATED(1.10) pass additionalData instead */
|
|
74
|
+
cfParameters: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, `0x${string}`, string>, `0x${string}`, string>>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
message: `0x${string}`;
|
|
77
|
+
gasBudget: `0x${string}`;
|
|
78
|
+
ccmAdditionalData?: `0x${string}` | undefined;
|
|
79
|
+
cfParameters?: `0x${string}` | undefined;
|
|
80
|
+
}, {
|
|
81
|
+
message: string;
|
|
82
|
+
gasBudget: string;
|
|
83
|
+
ccmAdditionalData?: string | undefined;
|
|
84
|
+
cfParameters?: string | undefined;
|
|
85
|
+
}>, {
|
|
86
|
+
gasBudget: `0x${string}`;
|
|
87
|
+
message: `0x${string}`;
|
|
88
|
+
ccmAdditionalData: `0x${string}`;
|
|
89
|
+
}, {
|
|
90
|
+
message: string;
|
|
91
|
+
gasBudget: string;
|
|
92
|
+
ccmAdditionalData?: string | undefined;
|
|
93
|
+
cfParameters?: string | undefined;
|
|
94
|
+
}>>>>>, {
|
|
95
|
+
cfParameters: `0x${string}`;
|
|
96
|
+
gasBudget: `0x${string}`;
|
|
97
|
+
message: `0x${string}`;
|
|
98
|
+
ccmAdditionalData: `0x${string}`;
|
|
99
|
+
} | null, {
|
|
100
|
+
message: string;
|
|
101
|
+
gasBudget: string;
|
|
102
|
+
ccmAdditionalData?: string | undefined;
|
|
103
|
+
cfParameters?: string | undefined;
|
|
104
|
+
} | null | undefined>;
|
|
68
105
|
}, "strip", z.ZodTypeAny, {
|
|
69
106
|
retryDurationBlocks: number;
|
|
70
107
|
refundAddress: string;
|
|
71
108
|
minPriceX128: string;
|
|
109
|
+
maxOraclePriceSlippage: number | null;
|
|
110
|
+
refundCcmMetadata: {
|
|
111
|
+
cfParameters: `0x${string}`;
|
|
112
|
+
gasBudget: `0x${string}`;
|
|
113
|
+
message: `0x${string}`;
|
|
114
|
+
ccmAdditionalData: `0x${string}`;
|
|
115
|
+
} | null;
|
|
72
116
|
}, {
|
|
73
117
|
retryDurationBlocks: number;
|
|
74
118
|
refundAddress: string;
|
|
75
119
|
minPriceX128: string;
|
|
120
|
+
maxOraclePriceSlippage?: number | null | undefined;
|
|
121
|
+
refundCcmMetadata?: {
|
|
122
|
+
message: string;
|
|
123
|
+
gasBudget: string;
|
|
124
|
+
ccmAdditionalData?: string | undefined;
|
|
125
|
+
cfParameters?: string | undefined;
|
|
126
|
+
} | null | undefined;
|
|
76
127
|
}>;
|
|
77
128
|
type FillOrKillParamsX128 = z.input<typeof fillOrKillParams>;
|
|
78
129
|
type FillOrKillParamsWithMinPrice = Omit<FillOrKillParamsX128, 'minPriceX128'> & {
|
|
@@ -118,6 +169,7 @@ interface BaseQuoteDetails {
|
|
|
118
169
|
estimatedPrice: string;
|
|
119
170
|
recommendedSlippageTolerancePercent: number;
|
|
120
171
|
recommendedRetryDurationMinutes: number;
|
|
172
|
+
recommendedLivePriceSlippageTolerancePercent: number | undefined;
|
|
121
173
|
}
|
|
122
174
|
type WithBoostQuote<T> = Omit<T, 'boostQuote'> & BoostedQuoteDetails;
|
|
123
175
|
interface RegularQuote extends BaseQuoteDetails {
|
|
@@ -134,6 +186,9 @@ type DCABoostQuote = NonNullable<DCAQuote['boostQuote']>;
|
|
|
134
186
|
type RegularBoostQuote = NonNullable<RegularQuote['boostQuote']>;
|
|
135
187
|
type BoostQuote = RegularBoostQuote | DCABoostQuote;
|
|
136
188
|
type FillOrKillParamsWithoutRefundAddress = {
|
|
189
|
+
livePriceSlippageTolerancePercent?: string | number | false;
|
|
190
|
+
refundCcmMetadata?: CcmParams | null;
|
|
191
|
+
} & ({
|
|
137
192
|
minPrice: string;
|
|
138
193
|
retryDurationBlocks: number;
|
|
139
194
|
} | {
|
|
@@ -145,24 +200,24 @@ type FillOrKillParamsWithoutRefundAddress = {
|
|
|
145
200
|
} | {
|
|
146
201
|
slippageTolerancePercent: string | number;
|
|
147
202
|
retryDurationMinutes: number;
|
|
148
|
-
};
|
|
203
|
+
});
|
|
149
204
|
type FillOrKillParams = {
|
|
205
|
+
livePriceSlippageTolerancePercent?: string | number | false;
|
|
150
206
|
refundAddress: string;
|
|
207
|
+
refundCcmMetadata?: CcmParams | null;
|
|
208
|
+
} & ({
|
|
151
209
|
minPrice: string;
|
|
152
210
|
retryDurationBlocks: number;
|
|
153
211
|
} | {
|
|
154
|
-
refundAddress: string;
|
|
155
212
|
minPrice: string;
|
|
156
213
|
retryDurationMinutes: number;
|
|
157
214
|
} | {
|
|
158
|
-
refundAddress: string;
|
|
159
215
|
slippageTolerancePercent: string | number;
|
|
160
216
|
retryDurationBlocks: number;
|
|
161
217
|
} | {
|
|
162
|
-
refundAddress: string;
|
|
163
218
|
slippageTolerancePercent: string | number;
|
|
164
219
|
retryDurationMinutes: number;
|
|
165
|
-
};
|
|
220
|
+
});
|
|
166
221
|
|
|
167
222
|
interface ChainData {
|
|
168
223
|
chain: ChainflipChain;
|
|
@@ -173,8 +228,8 @@ interface ChainData {
|
|
|
173
228
|
maxRetryDurationBlocks: number | undefined;
|
|
174
229
|
}
|
|
175
230
|
type AssetData = {
|
|
176
|
-
[C in ChainflipChain]: {
|
|
177
|
-
chainflipId: ChainflipAsset
|
|
231
|
+
[C in Exclude<ChainflipChain, 'Polkadot'>]: {
|
|
232
|
+
chainflipId: Exclude<ChainflipAsset, 'Dot'>;
|
|
178
233
|
asset: AssetOfChain<C>;
|
|
179
234
|
chain: C;
|
|
180
235
|
contractAddress: string | undefined;
|
|
@@ -186,11 +241,11 @@ type AssetData = {
|
|
|
186
241
|
maximumSwapAmount: string | null;
|
|
187
242
|
minimumEgressAmount: string;
|
|
188
243
|
};
|
|
189
|
-
}[ChainflipChain];
|
|
244
|
+
}[Exclude<ChainflipChain, 'Polkadot'>];
|
|
190
245
|
interface ChainsAndAssets {
|
|
191
|
-
srcChain: ChainflipChain
|
|
246
|
+
srcChain: Exclude<ChainflipChain, 'Polkadot'>;
|
|
192
247
|
srcAsset: AssetSymbol;
|
|
193
|
-
destChain: ChainflipChain
|
|
248
|
+
destChain: Exclude<ChainflipChain, 'Polkadot'>;
|
|
194
249
|
destAsset: AssetSymbol;
|
|
195
250
|
}
|
|
196
251
|
interface QuoteRequest extends ChainsAndAssets {
|
|
@@ -220,6 +275,7 @@ type BoostPoolDepth = {
|
|
|
220
275
|
chain: ChainflipChain;
|
|
221
276
|
};
|
|
222
277
|
|
|
278
|
+
type ChunkFailureReason = 'PriceImpactLimit' | 'MinPriceViolation' | 'OraclePriceSlippageExceeded' | 'OraclePriceStale' | 'PredecessorSwapFailure' | 'SafeModeActive';
|
|
223
279
|
interface Failure {
|
|
224
280
|
failedAt: number;
|
|
225
281
|
failedBlockIndex: string;
|
|
@@ -278,6 +334,12 @@ type ChunkInfo = {
|
|
|
278
334
|
executedAt: number | undefined;
|
|
279
335
|
executedBlockIndex: string | undefined;
|
|
280
336
|
retryCount: number;
|
|
337
|
+
rescheduledAt: number | undefined;
|
|
338
|
+
rescheduledBlockIndex: string | undefined;
|
|
339
|
+
rescheduledReason: ChunkFailureReason | undefined;
|
|
340
|
+
abortedAt: number | undefined;
|
|
341
|
+
abortedBlockIndex: string | undefined;
|
|
342
|
+
abortedReason: ChunkFailureReason | undefined;
|
|
281
343
|
};
|
|
282
344
|
type PickRequired<T> = {
|
|
283
345
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
@@ -288,6 +350,7 @@ interface SwapFields {
|
|
|
288
350
|
swappedInputAmount: string;
|
|
289
351
|
swappedIntermediateAmount: string;
|
|
290
352
|
swappedOutputAmount: string;
|
|
353
|
+
livePriceExecutionDeltaPercentage: number | undefined;
|
|
291
354
|
regular: ChunkInfo | undefined;
|
|
292
355
|
dca: {
|
|
293
356
|
lastExecutedChunk: ChunkInfo | null;
|
|
@@ -488,6 +551,7 @@ declare class SwapSDK {
|
|
|
488
551
|
private readonly apiClient;
|
|
489
552
|
private cache;
|
|
490
553
|
private dcaEnabled;
|
|
554
|
+
private blackListedAssets;
|
|
491
555
|
constructor(options?: SwapSDKOptions);
|
|
492
556
|
getChains(sourceChain?: ChainflipChain, type?: AssetState): Promise<ChainData[]>;
|
|
493
557
|
private getStateChainEnvironment;
|
|
@@ -513,6 +577,7 @@ declare class SwapSDK {
|
|
|
513
577
|
requestDepositAddressV2({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerCommissionBps: brokerCommissionBpsParam, }: DepositAddressRequestV2): Promise<DepositAddressResponseV2>;
|
|
514
578
|
encodeVaultSwapData({ quote, srcAddress, destAddress, fillOrKillParams: inputFoKParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps: brokerCommissionBpsParam, extraParams, }: VaultSwapRequest): Promise<VaultSwapResponse>;
|
|
515
579
|
encodeCfParameters({ quote, srcAddress, destAddress, fillOrKillParams, affiliateBrokers: affiliates, ccmParams, brokerAccount, brokerCommissionBps, }: EncodeCfParametersRequest): Promise<HexString>;
|
|
580
|
+
/** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
|
|
516
581
|
getOnChainSwapExtrinsicArgs({ quote, fillOrKillParams, }: {
|
|
517
582
|
quote: Quote;
|
|
518
583
|
fillOrKillParams: FillOrKillParamsWithoutRefundAddress;
|
package/dist/swap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert, getEnvironment, getEvmChainId, getAllBoostPoolsDepth, isNotNullish, ADDRESSES } from './chunk-
|
|
1
|
+
import { assert, getEnvironment, envSafeAssetBlacklist, getEvmChainId, getAllBoostPoolsDepth, parseFoKParams, isNotNullish, isTestnet, ADDRESSES } from './chunk-EZ2C77JH.js';
|
|
2
2
|
import { unreachable } from '@chainflip/utils/assertion';
|
|
3
3
|
import { chainflipChains, assetSymbols, isValidAssetAndChain, getInternalAssets, chainflipNetworks, chainflipAssets, assetConstants, getInternalAsset, internalAssetToRpcAsset, readAssetValue } from '@chainflip/utils/chainflip';
|
|
4
4
|
export { getInternalAsset as getChainflipId } from '@chainflip/utils/chainflip';
|
|
@@ -9,12 +9,11 @@ import { bytesToHex } from '@chainflip/utils/bytes';
|
|
|
9
9
|
import * as ss58 from '@chainflip/utils/ss58';
|
|
10
10
|
import { isHex, toUpperCase } from '@chainflip/utils/string';
|
|
11
11
|
import { priceX128ToPrice } from '@chainflip/utils/tickMath';
|
|
12
|
-
import
|
|
12
|
+
import BigNumber$1, { BigNumber } from 'bignumber.js';
|
|
13
13
|
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';
|
|
18
17
|
import axios from 'axios';
|
|
19
18
|
|
|
20
19
|
// ../shared/src/strings.ts
|
|
@@ -42,6 +41,7 @@ var hexString = z.string().refine((v) => /^0x[0-9a-f]*$/i.test(v));
|
|
|
42
41
|
var hexStringWithMaxByteSize = (maxByteSize) => hexString.refine((val) => val.length / 2 <= maxByteSize + 1, {
|
|
43
42
|
message: `String must be less than or equal to ${maxByteSize} bytes`
|
|
44
43
|
});
|
|
44
|
+
var basisPoints = z.number().int({ message: "must be in basis points" });
|
|
45
45
|
var DOT_PREFIX = 0;
|
|
46
46
|
var chainflipAddress = z.string().refine(
|
|
47
47
|
(address) => address.startsWith("cF") && ss58.decode(address),
|
|
@@ -98,6 +98,13 @@ z.object({
|
|
|
98
98
|
});
|
|
99
99
|
hadError = true;
|
|
100
100
|
}
|
|
101
|
+
if (srcAsset === "Dot" || destAsset === "Dot") {
|
|
102
|
+
ctx.addIssue({
|
|
103
|
+
message: "Dot is not supported",
|
|
104
|
+
code: z.ZodIssueCode.custom
|
|
105
|
+
});
|
|
106
|
+
hadError = true;
|
|
107
|
+
}
|
|
101
108
|
if (args.ccmGasBudget !== void 0 && args.ccmMessageLengthBytes === void 0) {
|
|
102
109
|
ctx.addIssue({
|
|
103
110
|
message: `ccmMessageLengthBytes must be set if ccmGasBudget is set`,
|
|
@@ -163,7 +170,15 @@ var dcaParams = z.object({
|
|
|
163
170
|
var fillOrKillParams = z.object({
|
|
164
171
|
retryDurationBlocks: z.number(),
|
|
165
172
|
refundAddress: z.string(),
|
|
166
|
-
minPriceX128: numericString
|
|
173
|
+
minPriceX128: numericString,
|
|
174
|
+
maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null),
|
|
175
|
+
refundCcmMetadata: ccmParamsSchema.nullish().optional().default(null).transform(
|
|
176
|
+
(v) => v && {
|
|
177
|
+
...v,
|
|
178
|
+
cfParameters: v.ccmAdditionalData
|
|
179
|
+
// deprecated
|
|
180
|
+
}
|
|
181
|
+
)
|
|
167
182
|
});
|
|
168
183
|
var validatePolkadotAddress = (address) => {
|
|
169
184
|
if (isHex(address)) return address.length === 66;
|
|
@@ -224,15 +239,6 @@ var validators = {
|
|
|
224
239
|
var validateAddress = (chain2, address, network) => validators[network][chain2](address);
|
|
225
240
|
|
|
226
241
|
// ../shared/src/broker.ts
|
|
227
|
-
var transformedFokSchema = z.object({
|
|
228
|
-
retryDurationBlocks: z.number(),
|
|
229
|
-
refundAddress: z.string(),
|
|
230
|
-
minPriceX128: numericString
|
|
231
|
-
}).transform(({ retryDurationBlocks, refundAddress, minPriceX128 }) => ({
|
|
232
|
-
retry_duration: retryDurationBlocks,
|
|
233
|
-
refund_address: refundAddress,
|
|
234
|
-
min_price: `0x${BigInt(minPriceX128).toString(16)}`
|
|
235
|
-
}));
|
|
236
242
|
var transformedDcaParamsSchema = dcaParams.transform(
|
|
237
243
|
({ numberOfChunks, chunkIntervalBlocks }) => ({
|
|
238
244
|
number_of_chunks: numberOfChunks,
|
|
@@ -248,6 +254,27 @@ var transformedCcmParamsSchema = ccmParamsSchema.transform(
|
|
|
248
254
|
cf_parameters: ccmAdditionalData
|
|
249
255
|
})
|
|
250
256
|
);
|
|
257
|
+
var transformedFokSchema = z.object({
|
|
258
|
+
retryDurationBlocks: z.number(),
|
|
259
|
+
refundAddress: z.string(),
|
|
260
|
+
minPriceX128: numericString,
|
|
261
|
+
maxOraclePriceSlippage: basisPoints.nullish().transform((v) => v ?? null),
|
|
262
|
+
refundCcmMetadata: transformedCcmParamsSchema.nullable().optional().default(null)
|
|
263
|
+
}).transform(
|
|
264
|
+
({
|
|
265
|
+
retryDurationBlocks,
|
|
266
|
+
refundAddress,
|
|
267
|
+
minPriceX128,
|
|
268
|
+
maxOraclePriceSlippage,
|
|
269
|
+
refundCcmMetadata
|
|
270
|
+
}) => ({
|
|
271
|
+
retry_duration: retryDurationBlocks,
|
|
272
|
+
refund_address: refundAddress,
|
|
273
|
+
min_price: `0x${BigInt(minPriceX128).toString(16)}`,
|
|
274
|
+
max_oracle_price_slippage: maxOraclePriceSlippage,
|
|
275
|
+
refund_ccm_metadata: refundCcmMetadata
|
|
276
|
+
})
|
|
277
|
+
);
|
|
251
278
|
var getDepositAddressRequestSchema = (network) => z.object({
|
|
252
279
|
srcAsset: assetAndChain,
|
|
253
280
|
destAsset: assetAndChain,
|
|
@@ -265,7 +292,6 @@ var getDepositAddressRequestSchema = (network) => z.object({
|
|
|
265
292
|
code: z.ZodIssueCode.custom
|
|
266
293
|
});
|
|
267
294
|
}
|
|
268
|
-
}).superRefine((val, ctx) => {
|
|
269
295
|
if (!validateAddress(val.srcAsset.chain, val.fillOrKillParams.refund_address, network)) {
|
|
270
296
|
ctx.addIssue({
|
|
271
297
|
message: `Address "${val.fillOrKillParams.refund_address}" is not a valid "${val.srcAsset.chain}" address for "${network}"`,
|
|
@@ -285,7 +311,8 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
|
|
|
285
311
|
affiliates: z.array(affiliateBroker).optional(),
|
|
286
312
|
fillOrKillParams: transformedFokSchema,
|
|
287
313
|
dcaParams: transformedDcaParamsSchema.optional(),
|
|
288
|
-
extraParams: z.object({ seed: hexString.optional() }).optional()
|
|
314
|
+
extraParams: z.object({ seed: hexString.optional() }).optional(),
|
|
315
|
+
brokerAccount: chainflipAddress.optional()
|
|
289
316
|
}).superRefine((val, ctx) => {
|
|
290
317
|
if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
|
|
291
318
|
ctx.addIssue({
|
|
@@ -311,11 +338,12 @@ var getVaultSwapParameterEncodingRequestSchema = (network) => z.object({
|
|
|
311
338
|
}).transform((data) => {
|
|
312
339
|
let extraParams;
|
|
313
340
|
if (data.srcAsset.chain === "Bitcoin") {
|
|
314
|
-
const minOutputAmount =
|
|
341
|
+
const minOutputAmount = BigNumber$1(data.amount.toString()).multipliedBy(priceX128ToPrice(data.fillOrKillParams.min_price)).toFixed(0);
|
|
315
342
|
extraParams = {
|
|
316
343
|
chain: "Bitcoin",
|
|
317
344
|
min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
|
|
318
|
-
retry_duration: data.fillOrKillParams.retry_duration
|
|
345
|
+
retry_duration: data.fillOrKillParams.retry_duration,
|
|
346
|
+
max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
|
|
319
347
|
};
|
|
320
348
|
} else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
|
|
321
349
|
extraParams = {
|
|
@@ -359,7 +387,6 @@ async function requestSwapDepositAddress(request, opts, chainflipNetwork) {
|
|
|
359
387
|
params.dcaParams
|
|
360
388
|
);
|
|
361
389
|
switch (params.srcAsset.chain) {
|
|
362
|
-
case "Polkadot":
|
|
363
390
|
case "Assethub":
|
|
364
391
|
if (isHex(response.address)) {
|
|
365
392
|
response.address = ss58.encode({ data: response.address, ss58Format: DOT_PREFIX });
|
|
@@ -459,10 +486,24 @@ var TransformedCcmParams = ccmParamsSchema.transform(
|
|
|
459
486
|
})
|
|
460
487
|
);
|
|
461
488
|
var FillOrKillParams = fillOrKillParams.transform(
|
|
462
|
-
({
|
|
489
|
+
({
|
|
490
|
+
retryDurationBlocks,
|
|
491
|
+
refundAddress,
|
|
492
|
+
minPriceX128,
|
|
493
|
+
maxOraclePriceSlippage,
|
|
494
|
+
refundCcmMetadata
|
|
495
|
+
}) => ({
|
|
463
496
|
retry_duration: retryDurationBlocks,
|
|
464
497
|
refund_address: refundAddress,
|
|
465
|
-
min_price: `0x${BigInt(minPriceX128).toString(16)}
|
|
498
|
+
min_price: `0x${BigInt(minPriceX128).toString(16)}`,
|
|
499
|
+
max_oracle_price_slippage: maxOraclePriceSlippage,
|
|
500
|
+
refund_ccm_metadata: refundCcmMetadata && {
|
|
501
|
+
gas_budget: refundCcmMetadata.gasBudget,
|
|
502
|
+
message: refundCcmMetadata.message,
|
|
503
|
+
ccm_additional_data: refundCcmMetadata.ccmAdditionalData,
|
|
504
|
+
/** @deprecated DEPRECATED(1.10) */
|
|
505
|
+
cf_parameters: refundCcmMetadata.cfParameters
|
|
506
|
+
}
|
|
466
507
|
})
|
|
467
508
|
);
|
|
468
509
|
var TransformedDcaParams = dcaParams.transform(
|
|
@@ -484,7 +525,8 @@ var EncodeVaultSwapBody = z.object({
|
|
|
484
525
|
fillOrKillParams: FillOrKillParams,
|
|
485
526
|
dcaParams: TransformedDcaParams.optional(),
|
|
486
527
|
extraParams: z.object({ seed: hexString.optional() }).optional(),
|
|
487
|
-
network: z.enum(chainflipNetworks)
|
|
528
|
+
network: z.enum(chainflipNetworks),
|
|
529
|
+
brokerAccount: chainflipAddress.optional()
|
|
488
530
|
}).superRefine(({ network, ...val }, ctx) => {
|
|
489
531
|
if (val.srcAddress && !validateAddress(val.srcAsset.chain, val.srcAddress, network)) {
|
|
490
532
|
ctx.addIssue({
|
|
@@ -514,7 +556,8 @@ var EncodeVaultSwapBody = z.object({
|
|
|
514
556
|
extraParams = {
|
|
515
557
|
chain: "Bitcoin",
|
|
516
558
|
min_output_amount: `0x${BigInt(minOutputAmount).toString(16)}`,
|
|
517
|
-
retry_duration: data.fillOrKillParams.retry_duration
|
|
559
|
+
retry_duration: data.fillOrKillParams.retry_duration,
|
|
560
|
+
max_oracle_price_slippage: data.fillOrKillParams.max_oracle_price_slippage
|
|
518
561
|
};
|
|
519
562
|
} else if (data.srcAsset.chain === "Ethereum" || data.srcAsset.chain === "Arbitrum") {
|
|
520
563
|
extraParams = {
|
|
@@ -601,7 +644,8 @@ var OpenSwapDepositChannelBody = z.object({
|
|
|
601
644
|
intermediateAmount: z.string().optional(),
|
|
602
645
|
egressAmount: z.string(),
|
|
603
646
|
estimatedPrice: z.string(),
|
|
604
|
-
recommendedSlippageTolerancePercent: z.number().optional()
|
|
647
|
+
recommendedSlippageTolerancePercent: z.number().optional(),
|
|
648
|
+
recommendedLivePriceSlippageTolerancePercent: z.number().optional()
|
|
605
649
|
}).optional(),
|
|
606
650
|
takeCommission: z.boolean().optional()
|
|
607
651
|
}).transform(({ amount, ...rest }) => ({
|
|
@@ -692,40 +736,6 @@ var MultiCache = class {
|
|
|
692
736
|
return cached.value;
|
|
693
737
|
}
|
|
694
738
|
};
|
|
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;
|
|
697
|
-
function parseFoKParams(params, quote) {
|
|
698
|
-
const srcAsset = getInternalAsset(quote.srcAsset);
|
|
699
|
-
const destAsset = getInternalAsset(quote.destAsset);
|
|
700
|
-
let minPrice;
|
|
701
|
-
if ("minPrice" in params) {
|
|
702
|
-
assert(
|
|
703
|
-
!("slippageTolerancePercent" in params),
|
|
704
|
-
"Cannot have both minPrice and slippageTolerancePercent"
|
|
705
|
-
);
|
|
706
|
-
minPrice = params.minPrice;
|
|
707
|
-
} else if ("slippageTolerancePercent" in params) {
|
|
708
|
-
const tolerance = new BigNumber3(params.slippageTolerancePercent);
|
|
709
|
-
assert(!tolerance.isNaN(), "Invalid slippage tolerance");
|
|
710
|
-
assert(
|
|
711
|
-
tolerance.gte(0) && tolerance.lte(100),
|
|
712
|
-
"Slippage tolerance must be between 0 and 100 inclusive",
|
|
713
|
-
RangeError
|
|
714
|
-
);
|
|
715
|
-
const estimatedPrice = new BigNumber3(quote.estimatedPrice);
|
|
716
|
-
assert(!estimatedPrice.isNaN(), "Invalid estimated price");
|
|
717
|
-
minPrice = estimatedPrice.times(new BigNumber3(100).minus(tolerance).dividedBy(100)).toFixed(assetConstants[destAsset].decimals);
|
|
718
|
-
} else {
|
|
719
|
-
throw new Error("Either minPrice or slippageTolerancePercent must be provided");
|
|
720
|
-
}
|
|
721
|
-
const retryDurationBlocks = "retryDurationBlocks" in params ? params.retryDurationBlocks : Math.max(Math.ceil(params.retryDurationMinutes * blocksPerMinute), 0);
|
|
722
|
-
const parsed = {
|
|
723
|
-
retryDurationBlocks,
|
|
724
|
-
minPriceX128: getPriceX128FromPrice(minPrice, srcAsset, destAsset)
|
|
725
|
-
};
|
|
726
|
-
return "refundAddress" in params ? { ...parsed, refundAddress: params.refundAddress } : parsed;
|
|
727
|
-
}
|
|
728
|
-
var isTestnet = (network) => network !== "mainnet";
|
|
729
739
|
var MAX_SWAP_AMOUNT = 2n ** 128n - 1n;
|
|
730
740
|
var validateSwapAmount = (env, asset2, amount) => {
|
|
731
741
|
const minimumAmount = readAssetValue(env.ingressEgress.minimumDepositAmounts, asset2);
|
|
@@ -797,13 +807,15 @@ var getChainData = (chain2, network, env) => ({
|
|
|
797
807
|
name: chain2,
|
|
798
808
|
evmChainId: getEvmChainId(chain2, network),
|
|
799
809
|
isMainnet: !isTestnet(network),
|
|
800
|
-
requiredBlockConfirmations: isNotNullish(
|
|
810
|
+
requiredBlockConfirmations: isNotNullish(
|
|
811
|
+
env.ingressEgress.witnessSafetyMargins[chain2]
|
|
812
|
+
) ? Number(env.ingressEgress.witnessSafetyMargins[chain2]) + 1 : void 0,
|
|
801
813
|
maxRetryDurationBlocks: env.swapping.maxSwapRetryDurationBlocks
|
|
802
814
|
});
|
|
803
815
|
|
|
804
816
|
// package.json
|
|
805
817
|
var package_default = {
|
|
806
|
-
version: "1.
|
|
818
|
+
version: "1.11.0-beta.2"};
|
|
807
819
|
|
|
808
820
|
// src/swap/consts.ts
|
|
809
821
|
var CF_SDK_VERSION_HEADERS = { "X-Chainflip-Sdk-Version": package_default.version };
|
|
@@ -868,6 +880,7 @@ var SwapSDK = class {
|
|
|
868
880
|
apiClient;
|
|
869
881
|
cache;
|
|
870
882
|
dcaEnabled = false;
|
|
883
|
+
blackListedAssets;
|
|
871
884
|
constructor(options = {}) {
|
|
872
885
|
const network = options.network ?? "perseverance";
|
|
873
886
|
this.options = {
|
|
@@ -897,6 +910,7 @@ var SwapSDK = class {
|
|
|
897
910
|
ttl: 6e4
|
|
898
911
|
}
|
|
899
912
|
});
|
|
913
|
+
this.blackListedAssets = envSafeAssetBlacklist(this.options.network);
|
|
900
914
|
}
|
|
901
915
|
async getChains(sourceChain, type = "all") {
|
|
902
916
|
if (sourceChain && !chainflipChains.includes(sourceChain)) {
|
|
@@ -915,7 +929,7 @@ var SwapSDK = class {
|
|
|
915
929
|
}
|
|
916
930
|
async getSupportedAssets(type) {
|
|
917
931
|
const assets = await this.cache.read("networkInfo");
|
|
918
|
-
return assets.assets.filter((a) => {
|
|
932
|
+
return assets.assets.filter((a) => !this.blackListedAssets.includes(a.asset)).filter((a) => {
|
|
919
933
|
switch (type) {
|
|
920
934
|
case "all":
|
|
921
935
|
return true;
|
|
@@ -987,7 +1001,7 @@ var SwapSDK = class {
|
|
|
987
1001
|
const {
|
|
988
1002
|
ingressEgress: { witnessSafetyMargins }
|
|
989
1003
|
} = await this.getStateChainEnvironment();
|
|
990
|
-
return chainflipChains.reduce(
|
|
1004
|
+
return chainflipChains.filter((chain2) => chain2 !== "Polkadot").reduce(
|
|
991
1005
|
(acc, chain2) => {
|
|
992
1006
|
acc[chain2] = witnessSafetyMargins[chain2] ? Number(witnessSafetyMargins[chain2]) + 1 : null;
|
|
993
1007
|
return acc;
|
|
@@ -1222,6 +1236,7 @@ var SwapSDK = class {
|
|
|
1222
1236
|
}
|
|
1223
1237
|
return res.body;
|
|
1224
1238
|
}
|
|
1239
|
+
/** @deprecated DEPRECATED(1.11) removing this method as it appears to not be used */
|
|
1225
1240
|
// eslint-disable-next-line class-methods-use-this
|
|
1226
1241
|
getOnChainSwapExtrinsicArgs({
|
|
1227
1242
|
quote,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainflip/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./swap": {
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@chainflip/bitcoin": "^1.2.
|
|
56
|
-
"@chainflip/rpc": "~1.11.0-beta.
|
|
57
|
-
"@chainflip/solana": "^2.
|
|
58
|
-
"@chainflip/utils": "^0.
|
|
55
|
+
"@chainflip/bitcoin": "^1.2.7",
|
|
56
|
+
"@chainflip/rpc": "~1.11.0-beta.16",
|
|
57
|
+
"@chainflip/solana": "^2.2.0",
|
|
58
|
+
"@chainflip/utils": "^0.11.1",
|
|
59
59
|
"@ts-rest/core": "^3.52.1",
|
|
60
60
|
"axios": "^1.10.0",
|
|
61
61
|
"bignumber.js": "^9.3.0",
|