@chainflip/sdk 0.2.20 → 1.1.0-rc.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/{broker-LHEVQ6DT.mjs → broker-EAUQOE44.mjs} +2 -2
- package/dist/{chunk-TCRJUCSA.mjs → chunk-LBKEYET5.mjs} +16 -6
- package/dist/{chunk-N4SMMWKH.mjs → chunk-LEMOY2A2.mjs} +1 -1
- package/dist/{chunk-B2TZXL7C.mjs → chunk-O4RYZWBW.mjs} +14 -1
- package/dist/contracts-rsXvYw7v.d.mts +41 -0
- package/dist/funding.d.mts +1 -1
- package/dist/funding.js +15 -5
- package/dist/funding.mjs +2 -2
- package/dist/swap.d.mts +4 -2
- package/dist/swap.d.ts +2 -0
- package/dist/swap.js +82 -16
- package/dist/swap.mjs +58 -16
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { chainflipAssetAndChain, numericString, hexString, btcAddress, ccmMetadataSchema, hexStringFromNumber, dotAddress, unsignedInteger } from './chunk-
|
|
2
|
-
import { z, isNotNullish, __name, Assets } from './chunk-
|
|
1
|
+
import { chainflipAssetAndChain, numericString, hexString, btcAddress, ccmMetadataSchema, hexStringFromNumber, dotAddress, unsignedInteger } from './chunk-LEMOY2A2.mjs';
|
|
2
|
+
import { z, isNotNullish, __name, Assets } from './chunk-O4RYZWBW.mjs';
|
|
3
3
|
import { u8aToHex } from '@polkadot/util';
|
|
4
4
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
5
5
|
import axios from 'axios';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z, ChainflipNetworks, __name, __publicField, Assets } from './chunk-
|
|
1
|
+
import { z, ChainflipNetworks, __name, __publicField, Assets } from './chunk-O4RYZWBW.mjs';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import { Interface, Contract } from 'ethers';
|
|
4
4
|
|
|
@@ -56,8 +56,10 @@ var chainAssetMap = /* @__PURE__ */ __name((parser) => z.object({
|
|
|
56
56
|
})
|
|
57
57
|
}), "chainAssetMap");
|
|
58
58
|
var chainAssetNumberMap = chainAssetMap(numberOrHex);
|
|
59
|
+
var chainAssetNumberNullableMap = chainAssetMap(numberOrHex.nullable());
|
|
59
60
|
var swappingEnvironment = z.object({
|
|
60
|
-
minimum_swap_amounts: chainAssetNumberMap
|
|
61
|
+
minimum_swap_amounts: chainAssetNumberMap,
|
|
62
|
+
maximum_swap_amounts: chainAssetNumberNullableMap
|
|
61
63
|
});
|
|
62
64
|
createRequest("cf_swapping_environment", swappingEnvironment);
|
|
63
65
|
var ingressEgressEnvironment = z.object({
|
|
@@ -91,11 +93,19 @@ var rpcAsset = z.union([
|
|
|
91
93
|
asset: z.literal("USDC")
|
|
92
94
|
})
|
|
93
95
|
]);
|
|
94
|
-
var poolInfo = z.object({
|
|
96
|
+
var poolInfo = z.intersection(z.object({
|
|
95
97
|
limit_order_fee_hundredth_pips: z.number(),
|
|
96
|
-
range_order_fee_hundredth_pips: z.number()
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
range_order_fee_hundredth_pips: z.number()
|
|
99
|
+
}), z.union([
|
|
100
|
+
z.object({
|
|
101
|
+
quote_asset: rpcAsset
|
|
102
|
+
}),
|
|
103
|
+
z.object({
|
|
104
|
+
pair_asset: rpcAsset
|
|
105
|
+
}).transform(({ pair_asset }) => ({
|
|
106
|
+
quote_asset: pair_asset
|
|
107
|
+
}))
|
|
108
|
+
]));
|
|
99
109
|
var feesInfo = z.object({
|
|
100
110
|
Bitcoin: z.object({
|
|
101
111
|
BTC: poolInfo
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z, isString, Chains, Assets, assetChains, ChainflipNetworks, __name, assert } from './chunk-
|
|
1
|
+
import { z, isString, Chains, Assets, assetChains, ChainflipNetworks, __name, assert } from './chunk-O4RYZWBW.mjs';
|
|
2
2
|
import { hexToU8a } from '@polkadot/util';
|
|
3
3
|
import { encodeAddress, decodeAddress, base58Decode } from '@polkadot/util-crypto';
|
|
4
4
|
import * as ethers from 'ethers';
|
|
@@ -71,6 +71,19 @@ var chainContractIds = {
|
|
|
71
71
|
[Chains.Polkadot]: 2,
|
|
72
72
|
[Chains.Bitcoin]: 3
|
|
73
73
|
};
|
|
74
|
+
function assertAsset(asset) {
|
|
75
|
+
if (!(asset in Assets))
|
|
76
|
+
throw new Error("invalid asset");
|
|
77
|
+
}
|
|
78
|
+
__name(assertAsset, "assertAsset");
|
|
79
|
+
function assertIsValidAssetAndChain(assetAndChain) {
|
|
80
|
+
const { asset, chain } = assetAndChain;
|
|
81
|
+
assertAsset(asset);
|
|
82
|
+
if (chain !== assetChains[asset]) {
|
|
83
|
+
throw new Error("invalid asset and chain combination");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
__name(assertIsValidAssetAndChain, "assertIsValidAssetAndChain");
|
|
74
87
|
|
|
75
88
|
// ../shared/src/guards.ts
|
|
76
89
|
var isString = /* @__PURE__ */ __name((value) => typeof value === "string", "isString");
|
|
@@ -3917,4 +3930,4 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
3917
3930
|
ZodError
|
|
3918
3931
|
});
|
|
3919
3932
|
|
|
3920
|
-
export { Assets, ChainflipNetworks, Chains, __name, __publicField, assert, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap, z };
|
|
3933
|
+
export { Assets, ChainflipNetworks, Chains, __name, __publicField, assert, assertIsValidAssetAndChain, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds, isNotNullish, isString, isTestnet, isTokenCall, isTokenSwap, z };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
type ArrayToMap<T extends readonly string[]> = {
|
|
2
|
+
[K in T[number]]: K;
|
|
3
|
+
};
|
|
4
|
+
declare const Chains: ArrayToMap<readonly ["Bitcoin", "Ethereum", "Polkadot"]>;
|
|
5
|
+
type Chain = (typeof Chains)[keyof typeof Chains];
|
|
6
|
+
declare const Assets: ArrayToMap<readonly ["FLIP", "USDC", "DOT", "ETH", "BTC"]>;
|
|
7
|
+
type Asset = (typeof Assets)[keyof typeof Assets];
|
|
8
|
+
declare const ChainflipNetworks: ArrayToMap<readonly ["backspin", "sisyphos", "perseverance", "mainnet"]>;
|
|
9
|
+
type ChainflipNetwork = (typeof ChainflipNetworks)[keyof typeof ChainflipNetworks];
|
|
10
|
+
declare const assetChains: {
|
|
11
|
+
ETH: "Ethereum";
|
|
12
|
+
FLIP: "Ethereum";
|
|
13
|
+
USDC: "Ethereum";
|
|
14
|
+
BTC: "Bitcoin";
|
|
15
|
+
DOT: "Polkadot";
|
|
16
|
+
};
|
|
17
|
+
declare const assetDecimals: {
|
|
18
|
+
DOT: number;
|
|
19
|
+
ETH: number;
|
|
20
|
+
FLIP: number;
|
|
21
|
+
USDC: number;
|
|
22
|
+
BTC: number;
|
|
23
|
+
};
|
|
24
|
+
declare const assetContractIds: Record<Asset, number>;
|
|
25
|
+
declare const chainAssets: {
|
|
26
|
+
Ethereum: ("FLIP" | "USDC" | "ETH")[];
|
|
27
|
+
Bitcoin: "BTC"[];
|
|
28
|
+
Polkadot: "DOT"[];
|
|
29
|
+
};
|
|
30
|
+
declare const chainContractIds: Record<Chain, number>;
|
|
31
|
+
|
|
32
|
+
type TransactionOptions = {
|
|
33
|
+
gasLimit?: bigint;
|
|
34
|
+
gasPrice?: bigint;
|
|
35
|
+
maxFeePerGas?: bigint;
|
|
36
|
+
maxPriorityFeePerGas?: bigint;
|
|
37
|
+
nonce?: number;
|
|
38
|
+
wait?: number;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export { type Asset as A, type Chain as C, type TransactionOptions as T, type ChainflipNetwork as a, Chains as b, chainAssets as c, Assets as d, ChainflipNetworks as e, assetChains as f, assetDecimals as g, assetContractIds as h, chainContractIds as i };
|
package/dist/funding.d.mts
CHANGED
package/dist/funding.js
CHANGED
|
@@ -4782,8 +4782,10 @@ var chainAssetMap = /* @__PURE__ */ __name((parser) => z.object({
|
|
|
4782
4782
|
})
|
|
4783
4783
|
}), "chainAssetMap");
|
|
4784
4784
|
var chainAssetNumberMap = chainAssetMap(numberOrHex);
|
|
4785
|
+
var chainAssetNumberNullableMap = chainAssetMap(numberOrHex.nullable());
|
|
4785
4786
|
var swappingEnvironment = z.object({
|
|
4786
|
-
minimum_swap_amounts: chainAssetNumberMap
|
|
4787
|
+
minimum_swap_amounts: chainAssetNumberMap,
|
|
4788
|
+
maximum_swap_amounts: chainAssetNumberNullableMap
|
|
4787
4789
|
});
|
|
4788
4790
|
createRequest("cf_swapping_environment", swappingEnvironment);
|
|
4789
4791
|
var ingressEgressEnvironment = z.object({
|
|
@@ -4817,11 +4819,19 @@ var rpcAsset = z.union([
|
|
|
4817
4819
|
asset: z.literal("USDC")
|
|
4818
4820
|
})
|
|
4819
4821
|
]);
|
|
4820
|
-
var poolInfo = z.object({
|
|
4822
|
+
var poolInfo = z.intersection(z.object({
|
|
4821
4823
|
limit_order_fee_hundredth_pips: z.number(),
|
|
4822
|
-
range_order_fee_hundredth_pips: z.number()
|
|
4823
|
-
|
|
4824
|
-
|
|
4824
|
+
range_order_fee_hundredth_pips: z.number()
|
|
4825
|
+
}), z.union([
|
|
4826
|
+
z.object({
|
|
4827
|
+
quote_asset: rpcAsset
|
|
4828
|
+
}),
|
|
4829
|
+
z.object({
|
|
4830
|
+
pair_asset: rpcAsset
|
|
4831
|
+
}).transform(({ pair_asset }) => ({
|
|
4832
|
+
quote_asset: pair_asset
|
|
4833
|
+
}))
|
|
4834
|
+
]));
|
|
4825
4835
|
var feesInfo = z.object({
|
|
4826
4836
|
Bitcoin: z.object({
|
|
4827
4837
|
BTC: poolInfo
|
package/dist/funding.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, checkAllowance, extractOverrides, StateChainGateway__factory } from './chunk-
|
|
2
|
-
import { __name, __publicField, ChainflipNetworks, Assets, assert } from './chunk-
|
|
1
|
+
import { getFlipBalance, getFundingEnvironment, getStateChainGatewayContractAddress, approve, getTokenContractAddress, checkAllowance, extractOverrides, StateChainGateway__factory } from './chunk-LBKEYET5.mjs';
|
|
2
|
+
import { __name, __publicField, ChainflipNetworks, Assets, assert } from './chunk-O4RYZWBW.mjs';
|
|
3
3
|
|
|
4
4
|
// ../shared/src/stateChainGateway/utils.ts
|
|
5
5
|
var getStateChainGateway = /* @__PURE__ */ __name((networkOpts) => {
|
package/dist/swap.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Signer } from 'ethers';
|
|
2
|
-
import { A as Asset, C as Chain, c as chainAssets, a as ChainflipNetwork, T as TransactionOptions } from './contracts-rsXvYw7v.
|
|
3
|
-
export { d as Assets, e as ChainflipNetworks, b as Chains, f as assetChains, h as assetContractIds, g as assetDecimals, i as chainContractIds } from './contracts-rsXvYw7v.
|
|
2
|
+
import { A as Asset, C as Chain, c as chainAssets, a as ChainflipNetwork, T as TransactionOptions } from './contracts-rsXvYw7v.mjs';
|
|
3
|
+
export { d as Assets, e as ChainflipNetworks, b as Chains, f as assetChains, h as assetContractIds, g as assetDecimals, i as chainContractIds } from './contracts-rsXvYw7v.mjs';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
6
6
|
declare const tokenSwapParamsSchema: z.ZodUnion<[z.ZodObject<{
|
|
@@ -429,6 +429,7 @@ interface CommonStatusFields extends ChainsAndAssets {
|
|
|
429
429
|
depositChannelExpiryBlock: bigint;
|
|
430
430
|
estimatedDepositChannelExpiryTime: number | undefined;
|
|
431
431
|
isDepositChanneExpired: boolean;
|
|
432
|
+
depositChannelOpenedThroughBackend: boolean;
|
|
432
433
|
ccmDepositReceivedBlockIndex: string | undefined;
|
|
433
434
|
ccmMetadata: {
|
|
434
435
|
gasBudget: string;
|
|
@@ -547,6 +548,7 @@ declare class SwapSDK {
|
|
|
547
548
|
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
548
549
|
executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions): Promise<TransactionHash>;
|
|
549
550
|
approveVault(params: Pick<TokenSwapParams, 'srcAsset' | 'amount'>, txOpts?: TransactionOptions): Promise<TransactionHash | null>;
|
|
551
|
+
private validateSwapAmount;
|
|
550
552
|
}
|
|
551
553
|
|
|
552
554
|
export { Asset, type AssetData, Chain, type ChainData, ChainflipNetwork, type DepositAddressRequest, type DepositAddressResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, chainAssets };
|
package/dist/swap.d.ts
CHANGED
|
@@ -429,6 +429,7 @@ interface CommonStatusFields extends ChainsAndAssets {
|
|
|
429
429
|
depositChannelExpiryBlock: bigint;
|
|
430
430
|
estimatedDepositChannelExpiryTime: number | undefined;
|
|
431
431
|
isDepositChanneExpired: boolean;
|
|
432
|
+
depositChannelOpenedThroughBackend: boolean;
|
|
432
433
|
ccmDepositReceivedBlockIndex: string | undefined;
|
|
433
434
|
ccmMetadata: {
|
|
434
435
|
gasBudget: string;
|
|
@@ -547,6 +548,7 @@ declare class SwapSDK {
|
|
|
547
548
|
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
548
549
|
executeSwap(params: ExecuteSwapParams, txOpts?: TransactionOptions): Promise<TransactionHash>;
|
|
549
550
|
approveVault(params: Pick<TokenSwapParams, 'srcAsset' | 'amount'>, txOpts?: TransactionOptions): Promise<TransactionHash | null>;
|
|
551
|
+
private validateSwapAmount;
|
|
550
552
|
}
|
|
551
553
|
|
|
552
554
|
export { Asset, type AssetData, Chain, type ChainData, ChainflipNetwork, type DepositAddressRequest, type DepositAddressResponse, type QuoteRequest, type QuoteResponse, SwapSDK, type SwapSDKOptions, type SwapStatusRequest, type SwapStatusResponse, chainAssets };
|
package/dist/swap.js
CHANGED
|
@@ -45,6 +45,17 @@ var __publicField = (obj, key, value) => {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// ../shared/src/enums.ts
|
|
48
|
+
function assertAsset(asset) {
|
|
49
|
+
if (!(asset in exports.Assets))
|
|
50
|
+
throw new Error("invalid asset");
|
|
51
|
+
}
|
|
52
|
+
function assertIsValidAssetAndChain(assetAndChain) {
|
|
53
|
+
const { asset, chain } = assetAndChain;
|
|
54
|
+
assertAsset(asset);
|
|
55
|
+
if (chain !== exports.assetChains[asset]) {
|
|
56
|
+
throw new Error("invalid asset and chain combination");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
48
59
|
var arrayToMap; exports.Chains = void 0; exports.Assets = void 0; exports.ChainflipNetworks = void 0; var isTestnet; exports.assetChains = void 0; exports.assetDecimals = void 0; exports.assetContractIds = void 0; exports.chainAssets = void 0; exports.chainContractIds = void 0;
|
|
49
60
|
var init_enums = __esm({
|
|
50
61
|
"../shared/src/enums.ts"() {
|
|
@@ -112,6 +123,8 @@ var init_enums = __esm({
|
|
|
112
123
|
[exports.Chains.Polkadot]: 2,
|
|
113
124
|
[exports.Chains.Bitcoin]: 3
|
|
114
125
|
};
|
|
126
|
+
__name(assertAsset, "assertAsset");
|
|
127
|
+
__name(assertIsValidAssetAndChain, "assertIsValidAssetAndChain");
|
|
115
128
|
}
|
|
116
129
|
});
|
|
117
130
|
|
|
@@ -4478,7 +4491,7 @@ var init_broker = __esm({
|
|
|
4478
4491
|
}
|
|
4479
4492
|
});
|
|
4480
4493
|
|
|
4481
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
4494
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/observable-ade1bad8.mjs
|
|
4482
4495
|
function identity(x) {
|
|
4483
4496
|
return x;
|
|
4484
4497
|
}
|
|
@@ -4557,7 +4570,7 @@ function observable(subscribe) {
|
|
|
4557
4570
|
}
|
|
4558
4571
|
__name(observable, "observable");
|
|
4559
4572
|
|
|
4560
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
4573
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/observable/index.mjs
|
|
4561
4574
|
function share(_opts) {
|
|
4562
4575
|
return (originalObserver) => {
|
|
4563
4576
|
let refCount = 0;
|
|
@@ -4662,7 +4675,7 @@ function observableToPromise(observable2) {
|
|
|
4662
4675
|
}
|
|
4663
4676
|
__name(observableToPromise, "observableToPromise");
|
|
4664
4677
|
|
|
4665
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
4678
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/splitLink-4c75f7be.mjs
|
|
4666
4679
|
function createChain(opts) {
|
|
4667
4680
|
return observable((observer) => {
|
|
4668
4681
|
function execute(index = 0, op = opts.op) {
|
|
@@ -4686,7 +4699,7 @@ function createChain(opts) {
|
|
|
4686
4699
|
}
|
|
4687
4700
|
__name(createChain, "createChain");
|
|
4688
4701
|
|
|
4689
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
4702
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/transformResult-ace864b8.mjs
|
|
4690
4703
|
function isObject(value) {
|
|
4691
4704
|
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
4692
4705
|
}
|
|
@@ -4739,7 +4752,7 @@ function transformResult(response, runtime) {
|
|
|
4739
4752
|
}
|
|
4740
4753
|
__name(transformResult, "transformResult");
|
|
4741
4754
|
|
|
4742
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
4755
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/TRPCClientError-0de4d231.mjs
|
|
4743
4756
|
function isTRPCClientError(cause) {
|
|
4744
4757
|
return cause instanceof TRPCClientError || /**
|
|
4745
4758
|
* @deprecated
|
|
@@ -4797,7 +4810,7 @@ var _TRPCClientError = class _TRPCClientError extends Error {
|
|
|
4797
4810
|
__name(_TRPCClientError, "TRPCClientError");
|
|
4798
4811
|
var TRPCClientError = _TRPCClientError;
|
|
4799
4812
|
|
|
4800
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
4813
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/codes-c924c3db.mjs
|
|
4801
4814
|
function invert(obj) {
|
|
4802
4815
|
const newObj = /* @__PURE__ */ Object.create(null);
|
|
4803
4816
|
for (const key in obj) {
|
|
@@ -4835,7 +4848,7 @@ var TRPC_ERROR_CODES_BY_KEY = {
|
|
|
4835
4848
|
};
|
|
4836
4849
|
invert(TRPC_ERROR_CODES_BY_KEY);
|
|
4837
4850
|
|
|
4838
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
4851
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/index-f91d720c.mjs
|
|
4839
4852
|
invert(TRPC_ERROR_CODES_BY_KEY);
|
|
4840
4853
|
var noop = /* @__PURE__ */ __name(() => {
|
|
4841
4854
|
}, "noop");
|
|
@@ -4873,7 +4886,7 @@ var createFlatProxy = /* @__PURE__ */ __name((callback) => {
|
|
|
4873
4886
|
});
|
|
4874
4887
|
}, "createFlatProxy");
|
|
4875
4888
|
|
|
4876
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
4889
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/httpUtils-f58ceda1.mjs
|
|
4877
4890
|
var isFunction = /* @__PURE__ */ __name((fn) => typeof fn === "function", "isFunction");
|
|
4878
4891
|
function getFetch(customFetchImpl) {
|
|
4879
4892
|
if (customFetchImpl) {
|
|
@@ -5017,7 +5030,7 @@ function httpRequest(opts) {
|
|
|
5017
5030
|
}
|
|
5018
5031
|
__name(httpRequest, "httpRequest");
|
|
5019
5032
|
|
|
5020
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
5033
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs
|
|
5021
5034
|
var throwFatalError = /* @__PURE__ */ __name(() => {
|
|
5022
5035
|
throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new");
|
|
5023
5036
|
}, "throwFatalError");
|
|
@@ -5247,7 +5260,7 @@ var batchRequester = /* @__PURE__ */ __name((requesterOpts) => {
|
|
|
5247
5260
|
}, "batchRequester");
|
|
5248
5261
|
var httpBatchLink = createHTTPBatchLink(batchRequester);
|
|
5249
5262
|
|
|
5250
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
5263
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/links/httpLink.mjs
|
|
5251
5264
|
function httpLinkFactory(factoryOpts) {
|
|
5252
5265
|
return (opts) => {
|
|
5253
5266
|
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
@@ -5299,7 +5312,7 @@ function httpLinkFactory(factoryOpts) {
|
|
|
5299
5312
|
}
|
|
5300
5313
|
__name(httpLinkFactory, "httpLinkFactory");
|
|
5301
5314
|
|
|
5302
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
5315
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/index.mjs
|
|
5303
5316
|
var _TRPCUntypedClient = class _TRPCUntypedClient {
|
|
5304
5317
|
$request({ type, input, path, context = {} }) {
|
|
5305
5318
|
const chain$ = createChain({
|
|
@@ -6708,8 +6721,10 @@ var chainAssetMap = /* @__PURE__ */ __name((parser) => z.object({
|
|
|
6708
6721
|
})
|
|
6709
6722
|
}), "chainAssetMap");
|
|
6710
6723
|
var chainAssetNumberMap = chainAssetMap(numberOrHex);
|
|
6724
|
+
var chainAssetNumberNullableMap = chainAssetMap(numberOrHex.nullable());
|
|
6711
6725
|
var swappingEnvironment = z.object({
|
|
6712
|
-
minimum_swap_amounts: chainAssetNumberMap
|
|
6726
|
+
minimum_swap_amounts: chainAssetNumberMap,
|
|
6727
|
+
maximum_swap_amounts: chainAssetNumberNullableMap
|
|
6713
6728
|
});
|
|
6714
6729
|
createRequest("cf_swapping_environment", swappingEnvironment);
|
|
6715
6730
|
var ingressEgressEnvironment = z.object({
|
|
@@ -6743,11 +6758,19 @@ var rpcAsset = z.union([
|
|
|
6743
6758
|
asset: z.literal("USDC")
|
|
6744
6759
|
})
|
|
6745
6760
|
]);
|
|
6746
|
-
var poolInfo = z.object({
|
|
6761
|
+
var poolInfo = z.intersection(z.object({
|
|
6747
6762
|
limit_order_fee_hundredth_pips: z.number(),
|
|
6748
|
-
range_order_fee_hundredth_pips: z.number()
|
|
6749
|
-
|
|
6750
|
-
|
|
6763
|
+
range_order_fee_hundredth_pips: z.number()
|
|
6764
|
+
}), z.union([
|
|
6765
|
+
z.object({
|
|
6766
|
+
quote_asset: rpcAsset
|
|
6767
|
+
}),
|
|
6768
|
+
z.object({
|
|
6769
|
+
pair_asset: rpcAsset
|
|
6770
|
+
}).transform(({ pair_asset }) => ({
|
|
6771
|
+
quote_asset: pair_asset
|
|
6772
|
+
}))
|
|
6773
|
+
]));
|
|
6751
6774
|
var feesInfo = z.object({
|
|
6752
6775
|
Bitcoin: z.object({
|
|
6753
6776
|
BTC: poolInfo
|
|
@@ -6771,6 +6794,33 @@ var getEnvironment = createRequest("cf_environment", z.object({
|
|
|
6771
6794
|
pools: poolsEnvironment
|
|
6772
6795
|
}));
|
|
6773
6796
|
|
|
6797
|
+
// ../shared/src/rpc/utils.ts
|
|
6798
|
+
init_enums();
|
|
6799
|
+
var readAssetValue = /* @__PURE__ */ __name((minimums, asset) => {
|
|
6800
|
+
const chainMinimums = minimums[asset.chain];
|
|
6801
|
+
return chainMinimums[asset.asset];
|
|
6802
|
+
}, "readAssetValue");
|
|
6803
|
+
var validateSwapAmount = /* @__PURE__ */ __name((swapEnv, asset, amount) => {
|
|
6804
|
+
assertIsValidAssetAndChain(asset);
|
|
6805
|
+
const minAmount = readAssetValue(swapEnv.minimumSwapAmounts, asset);
|
|
6806
|
+
if (amount < minAmount) {
|
|
6807
|
+
return {
|
|
6808
|
+
success: false,
|
|
6809
|
+
reason: `expected amount is below minimum swap amount (${minAmount})`
|
|
6810
|
+
};
|
|
6811
|
+
}
|
|
6812
|
+
const maxAmount = readAssetValue(swapEnv.maximumSwapAmounts, asset);
|
|
6813
|
+
if (maxAmount != null && amount > maxAmount) {
|
|
6814
|
+
return {
|
|
6815
|
+
success: false,
|
|
6816
|
+
reason: `expected amount is above maximum swap amount (${maxAmount})`
|
|
6817
|
+
};
|
|
6818
|
+
}
|
|
6819
|
+
return {
|
|
6820
|
+
success: true
|
|
6821
|
+
};
|
|
6822
|
+
}, "validateSwapAmount");
|
|
6823
|
+
|
|
6774
6824
|
// ../shared/src/vault/schemas.ts
|
|
6775
6825
|
init_lib();
|
|
6776
6826
|
init_enums();
|
|
@@ -8498,6 +8548,11 @@ var _SwapSDK = class _SwapSDK {
|
|
|
8498
8548
|
return ApiService_default.getQuote(this.baseUrl, quoteRequest, options);
|
|
8499
8549
|
}
|
|
8500
8550
|
async requestDepositAddress(depositAddressRequest) {
|
|
8551
|
+
const { srcChain, srcAsset, amount } = depositAddressRequest;
|
|
8552
|
+
await this.validateSwapAmount({
|
|
8553
|
+
chain: srcChain,
|
|
8554
|
+
asset: srcAsset
|
|
8555
|
+
}, BigInt(amount));
|
|
8501
8556
|
let response;
|
|
8502
8557
|
if (this.brokerConfig !== void 0) {
|
|
8503
8558
|
const { requestSwapDepositAddress: requestSwapDepositAddress2 } = await Promise.resolve().then(() => (init_broker(), broker_exports));
|
|
@@ -8522,6 +8577,11 @@ var _SwapSDK = class _SwapSDK {
|
|
|
8522
8577
|
return ApiService_default.getStatus(this.baseUrl, swapStatusRequest, options);
|
|
8523
8578
|
}
|
|
8524
8579
|
async executeSwap(params, txOpts = {}) {
|
|
8580
|
+
const { srcChain, srcAsset, amount } = params;
|
|
8581
|
+
await this.validateSwapAmount({
|
|
8582
|
+
chain: srcChain,
|
|
8583
|
+
asset: srcAsset
|
|
8584
|
+
}, BigInt(amount));
|
|
8525
8585
|
assert(this.signer, "No signer provided");
|
|
8526
8586
|
const receipt = await executeSwap_default(params, {
|
|
8527
8587
|
network: this.network,
|
|
@@ -8539,6 +8599,12 @@ var _SwapSDK = class _SwapSDK {
|
|
|
8539
8599
|
}, txOpts);
|
|
8540
8600
|
return receipt ? receipt.hash : null;
|
|
8541
8601
|
}
|
|
8602
|
+
async validateSwapAmount(asset, amount) {
|
|
8603
|
+
const stateChainEnv = await this.getStateChainEnvironment();
|
|
8604
|
+
const result = validateSwapAmount(stateChainEnv.swapping, asset, amount);
|
|
8605
|
+
if (!result.success)
|
|
8606
|
+
throw new Error(result.reason);
|
|
8607
|
+
}
|
|
8542
8608
|
};
|
|
8543
8609
|
__name(_SwapSDK, "SwapSDK");
|
|
8544
8610
|
var SwapSDK = _SwapSDK;
|
package/dist/swap.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getEnvironment, getVaultManagerContractAddress, approve, getTokenContractAddress, checkAllowance, Vault__factory, extractOverrides } from './chunk-
|
|
2
|
-
import { numericString, ethereumAddress, dotAddress, btcAddress, ccmMetadataSchema } from './chunk-
|
|
3
|
-
import { __name, z, Chains, Assets, ChainflipNetworks, __publicField, assert, isTokenCall, isTokenSwap, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-
|
|
4
|
-
export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-
|
|
1
|
+
import { getEnvironment, getVaultManagerContractAddress, approve, getTokenContractAddress, checkAllowance, Vault__factory, extractOverrides } from './chunk-LBKEYET5.mjs';
|
|
2
|
+
import { numericString, ethereumAddress, dotAddress, btcAddress, ccmMetadataSchema } from './chunk-LEMOY2A2.mjs';
|
|
3
|
+
import { __name, z, Chains, Assets, ChainflipNetworks, __publicField, assert, assertIsValidAssetAndChain, isTokenCall, isTokenSwap, chainContractIds, assetContractIds, assetDecimals, isTestnet } from './chunk-O4RYZWBW.mjs';
|
|
4
|
+
export { Assets, ChainflipNetworks, Chains, assetChains, assetContractIds, assetDecimals, chainAssets, chainContractIds } from './chunk-O4RYZWBW.mjs';
|
|
5
5
|
import { decodeAddress } from '@polkadot/util-crypto';
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
|
|
8
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
8
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/observable-ade1bad8.mjs
|
|
9
9
|
function identity(x) {
|
|
10
10
|
return x;
|
|
11
11
|
}
|
|
@@ -84,7 +84,7 @@ function observable(subscribe) {
|
|
|
84
84
|
}
|
|
85
85
|
__name(observable, "observable");
|
|
86
86
|
|
|
87
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
87
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/observable/index.mjs
|
|
88
88
|
function share(_opts) {
|
|
89
89
|
return (originalObserver) => {
|
|
90
90
|
let refCount = 0;
|
|
@@ -189,7 +189,7 @@ function observableToPromise(observable2) {
|
|
|
189
189
|
}
|
|
190
190
|
__name(observableToPromise, "observableToPromise");
|
|
191
191
|
|
|
192
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
192
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/splitLink-4c75f7be.mjs
|
|
193
193
|
function createChain(opts) {
|
|
194
194
|
return observable((observer) => {
|
|
195
195
|
function execute(index = 0, op = opts.op) {
|
|
@@ -213,7 +213,7 @@ function createChain(opts) {
|
|
|
213
213
|
}
|
|
214
214
|
__name(createChain, "createChain");
|
|
215
215
|
|
|
216
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
216
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/transformResult-ace864b8.mjs
|
|
217
217
|
function isObject(value) {
|
|
218
218
|
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
219
219
|
}
|
|
@@ -266,7 +266,7 @@ function transformResult(response, runtime) {
|
|
|
266
266
|
}
|
|
267
267
|
__name(transformResult, "transformResult");
|
|
268
268
|
|
|
269
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
269
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/TRPCClientError-0de4d231.mjs
|
|
270
270
|
function isTRPCClientError(cause) {
|
|
271
271
|
return cause instanceof TRPCClientError || /**
|
|
272
272
|
* @deprecated
|
|
@@ -324,7 +324,7 @@ var _TRPCClientError = class _TRPCClientError extends Error {
|
|
|
324
324
|
__name(_TRPCClientError, "TRPCClientError");
|
|
325
325
|
var TRPCClientError = _TRPCClientError;
|
|
326
326
|
|
|
327
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
327
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/codes-c924c3db.mjs
|
|
328
328
|
function invert(obj) {
|
|
329
329
|
const newObj = /* @__PURE__ */ Object.create(null);
|
|
330
330
|
for (const key in obj) {
|
|
@@ -362,7 +362,7 @@ var TRPC_ERROR_CODES_BY_KEY = {
|
|
|
362
362
|
};
|
|
363
363
|
invert(TRPC_ERROR_CODES_BY_KEY);
|
|
364
364
|
|
|
365
|
-
// ../../node_modules/.pnpm/@trpc+server@10.
|
|
365
|
+
// ../../node_modules/.pnpm/@trpc+server@10.44.1/node_modules/@trpc/server/dist/index-f91d720c.mjs
|
|
366
366
|
invert(TRPC_ERROR_CODES_BY_KEY);
|
|
367
367
|
var noop = /* @__PURE__ */ __name(() => {
|
|
368
368
|
}, "noop");
|
|
@@ -400,7 +400,7 @@ var createFlatProxy = /* @__PURE__ */ __name((callback) => {
|
|
|
400
400
|
});
|
|
401
401
|
}, "createFlatProxy");
|
|
402
402
|
|
|
403
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
403
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/httpUtils-f58ceda1.mjs
|
|
404
404
|
var isFunction = /* @__PURE__ */ __name((fn) => typeof fn === "function", "isFunction");
|
|
405
405
|
function getFetch(customFetchImpl) {
|
|
406
406
|
if (customFetchImpl) {
|
|
@@ -544,7 +544,7 @@ function httpRequest(opts) {
|
|
|
544
544
|
}
|
|
545
545
|
__name(httpRequest, "httpRequest");
|
|
546
546
|
|
|
547
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
547
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/httpBatchLink-204206a5.mjs
|
|
548
548
|
var throwFatalError = /* @__PURE__ */ __name(() => {
|
|
549
549
|
throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new");
|
|
550
550
|
}, "throwFatalError");
|
|
@@ -774,7 +774,7 @@ var batchRequester = /* @__PURE__ */ __name((requesterOpts) => {
|
|
|
774
774
|
}, "batchRequester");
|
|
775
775
|
var httpBatchLink = createHTTPBatchLink(batchRequester);
|
|
776
776
|
|
|
777
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
777
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/links/httpLink.mjs
|
|
778
778
|
function httpLinkFactory(factoryOpts) {
|
|
779
779
|
return (opts) => {
|
|
780
780
|
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
@@ -826,7 +826,7 @@ function httpLinkFactory(factoryOpts) {
|
|
|
826
826
|
}
|
|
827
827
|
__name(httpLinkFactory, "httpLinkFactory");
|
|
828
828
|
|
|
829
|
-
// ../../node_modules/.pnpm/@trpc+client@10.
|
|
829
|
+
// ../../node_modules/.pnpm/@trpc+client@10.44.1_@trpc+server@10.44.1/node_modules/@trpc/client/dist/index.mjs
|
|
830
830
|
var _TRPCUntypedClient = class _TRPCUntypedClient {
|
|
831
831
|
$request({ type, input, path, context = {} }) {
|
|
832
832
|
const chain$ = createChain({
|
|
@@ -2173,6 +2173,32 @@ SuperJSON.registerClass;
|
|
|
2173
2173
|
SuperJSON.registerCustom;
|
|
2174
2174
|
SuperJSON.registerSymbol;
|
|
2175
2175
|
SuperJSON.allowErrorProps;
|
|
2176
|
+
|
|
2177
|
+
// ../shared/src/rpc/utils.ts
|
|
2178
|
+
var readAssetValue = /* @__PURE__ */ __name((minimums, asset) => {
|
|
2179
|
+
const chainMinimums = minimums[asset.chain];
|
|
2180
|
+
return chainMinimums[asset.asset];
|
|
2181
|
+
}, "readAssetValue");
|
|
2182
|
+
var validateSwapAmount = /* @__PURE__ */ __name((swapEnv, asset, amount) => {
|
|
2183
|
+
assertIsValidAssetAndChain(asset);
|
|
2184
|
+
const minAmount = readAssetValue(swapEnv.minimumSwapAmounts, asset);
|
|
2185
|
+
if (amount < minAmount) {
|
|
2186
|
+
return {
|
|
2187
|
+
success: false,
|
|
2188
|
+
reason: `expected amount is below minimum swap amount (${minAmount})`
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
const maxAmount = readAssetValue(swapEnv.maximumSwapAmounts, asset);
|
|
2192
|
+
if (maxAmount != null && amount > maxAmount) {
|
|
2193
|
+
return {
|
|
2194
|
+
success: false,
|
|
2195
|
+
reason: `expected amount is above maximum swap amount (${maxAmount})`
|
|
2196
|
+
};
|
|
2197
|
+
}
|
|
2198
|
+
return {
|
|
2199
|
+
success: true
|
|
2200
|
+
};
|
|
2201
|
+
}, "validateSwapAmount");
|
|
2176
2202
|
var bytesToHex = /* @__PURE__ */ __name((arr) => `0x${[
|
|
2177
2203
|
...arr
|
|
2178
2204
|
].map((v) => v.toString(16).padStart(2, "0")).join("")}`, "bytesToHex");
|
|
@@ -2518,9 +2544,14 @@ var _SwapSDK = class _SwapSDK {
|
|
|
2518
2544
|
return ApiService_default.getQuote(this.baseUrl, quoteRequest, options);
|
|
2519
2545
|
}
|
|
2520
2546
|
async requestDepositAddress(depositAddressRequest) {
|
|
2547
|
+
const { srcChain, srcAsset, amount } = depositAddressRequest;
|
|
2548
|
+
await this.validateSwapAmount({
|
|
2549
|
+
chain: srcChain,
|
|
2550
|
+
asset: srcAsset
|
|
2551
|
+
}, BigInt(amount));
|
|
2521
2552
|
let response;
|
|
2522
2553
|
if (this.brokerConfig !== void 0) {
|
|
2523
|
-
const { requestSwapDepositAddress } = await import('./broker-
|
|
2554
|
+
const { requestSwapDepositAddress } = await import('./broker-EAUQOE44.mjs');
|
|
2524
2555
|
const result = await requestSwapDepositAddress(depositAddressRequest, this.brokerConfig);
|
|
2525
2556
|
response = {
|
|
2526
2557
|
id: `${result.issuedBlock}-${depositAddressRequest.srcChain}-${result.channelId}`,
|
|
@@ -2542,6 +2573,11 @@ var _SwapSDK = class _SwapSDK {
|
|
|
2542
2573
|
return ApiService_default.getStatus(this.baseUrl, swapStatusRequest, options);
|
|
2543
2574
|
}
|
|
2544
2575
|
async executeSwap(params, txOpts = {}) {
|
|
2576
|
+
const { srcChain, srcAsset, amount } = params;
|
|
2577
|
+
await this.validateSwapAmount({
|
|
2578
|
+
chain: srcChain,
|
|
2579
|
+
asset: srcAsset
|
|
2580
|
+
}, BigInt(amount));
|
|
2545
2581
|
assert(this.signer, "No signer provided");
|
|
2546
2582
|
const receipt = await executeSwap_default(params, {
|
|
2547
2583
|
network: this.network,
|
|
@@ -2559,6 +2595,12 @@ var _SwapSDK = class _SwapSDK {
|
|
|
2559
2595
|
}, txOpts);
|
|
2560
2596
|
return receipt ? receipt.hash : null;
|
|
2561
2597
|
}
|
|
2598
|
+
async validateSwapAmount(asset, amount) {
|
|
2599
|
+
const stateChainEnv = await this.getStateChainEnvironment();
|
|
2600
|
+
const result = validateSwapAmount(stateChainEnv.swapping, asset, amount);
|
|
2601
|
+
if (!result.success)
|
|
2602
|
+
throw new Error(result.reason);
|
|
2603
|
+
}
|
|
2562
2604
|
};
|
|
2563
2605
|
__name(_SwapSDK, "SwapSDK");
|
|
2564
2606
|
var SwapSDK = _SwapSDK;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainflip/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.1.0-rc.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./swap": {
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@polkadot/util": "^12.6.1",
|
|
45
45
|
"@polkadot/util-crypto": "^12.6.1",
|
|
46
46
|
"axios": "^1.6.0",
|
|
47
|
-
"ethers": "6.
|
|
47
|
+
"ethers": "6.9.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"tsup": "^8.0.
|
|
50
|
+
"tsup": "^8.0.1"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"test": "jest --forceExit",
|