@chainflip/sdk 0.1.0
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/README.md +3 -0
- package/dist/chunk-BSY2FXE7.mjs +2128 -0
- package/dist/enums-d5fa72fa.d.ts +32 -0
- package/dist/funding.d.ts +20 -0
- package/dist/funding.js +998 -0
- package/dist/funding.mjs +102 -0
- package/dist/swap.d.ts +430 -0
- package/dist/swap.js +2229 -0
- package/dist/swap.mjs +754 -0
- package/package.json +60 -0
package/dist/funding.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { __name, ChainflipNetworks, getFlipBalance, getStateChainGatewayContractAddress, approve, getTokenContractAddress, Assets, checkAllowance, assert, StateChainGateway__factory } from './chunk-BSY2FXE7.mjs';
|
|
2
|
+
|
|
3
|
+
// ../shared/src/stateChainGateway/utils.ts
|
|
4
|
+
var getStateChainGateway = /* @__PURE__ */ __name((options) => {
|
|
5
|
+
const stateChainGatewayContractAddress = options.network === "localnet" ? options.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(options.network);
|
|
6
|
+
return StateChainGateway__factory.connect(stateChainGatewayContractAddress, options.signer);
|
|
7
|
+
}, "getStateChainGateway");
|
|
8
|
+
|
|
9
|
+
// ../shared/src/stateChainGateway/approval.ts
|
|
10
|
+
var checkStateChainGatewayAllowance = /* @__PURE__ */ __name(async (amount, options) => {
|
|
11
|
+
const flipContractAddress = options.network === "localnet" ? options.flipContractAddress : getTokenContractAddress(Assets.FLIP, options.network);
|
|
12
|
+
const stateChainGatewayContractAddress = options.network === "localnet" ? options.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(options.network);
|
|
13
|
+
return checkAllowance(amount, stateChainGatewayContractAddress, flipContractAddress, options.signer);
|
|
14
|
+
}, "checkStateChainGatewayAllowance");
|
|
15
|
+
var approveStateChainGateway = /* @__PURE__ */ __name(async (amount, options) => {
|
|
16
|
+
const { allowance, erc20, isAllowable } = await checkStateChainGatewayAllowance(amount, options);
|
|
17
|
+
if (isAllowable)
|
|
18
|
+
return null;
|
|
19
|
+
const stateChainGatewayContractAddress = options.network === "localnet" ? options.stateChainGatewayContractAddress : getStateChainGatewayContractAddress(options.network);
|
|
20
|
+
const receipt = await approve(amount, stateChainGatewayContractAddress, erc20, allowance, options.nonce);
|
|
21
|
+
return receipt;
|
|
22
|
+
}, "approveStateChainGateway");
|
|
23
|
+
|
|
24
|
+
// ../shared/src/stateChainGateway/index.ts
|
|
25
|
+
var fundStateChainAccount = /* @__PURE__ */ __name(async (accountId, amount, options) => {
|
|
26
|
+
const flipContractAddress = options.network === "localnet" ? options.flipContractAddress : getTokenContractAddress(Assets.FLIP, options.network);
|
|
27
|
+
const stateChainGateway = getStateChainGateway(options);
|
|
28
|
+
const { isAllowable } = await checkAllowance(amount, stateChainGateway.address, flipContractAddress, options.signer);
|
|
29
|
+
assert(isAllowable, "Insufficient allowance");
|
|
30
|
+
const transaction = await stateChainGateway.fundStateChainAccount(accountId, amount, {
|
|
31
|
+
nonce: options.nonce
|
|
32
|
+
});
|
|
33
|
+
return transaction.wait(1);
|
|
34
|
+
}, "fundStateChainAccount");
|
|
35
|
+
var executeRedemption = /* @__PURE__ */ __name(async (accountId, { nonce, ...options }) => {
|
|
36
|
+
const stateChainGateway = getStateChainGateway(options);
|
|
37
|
+
const transaction = await stateChainGateway.executeRedemption(accountId, {
|
|
38
|
+
nonce
|
|
39
|
+
});
|
|
40
|
+
return transaction.wait(1);
|
|
41
|
+
}, "executeRedemption");
|
|
42
|
+
var getMinimumFunding = /* @__PURE__ */ __name((options) => {
|
|
43
|
+
const stateChainGateway = getStateChainGateway(options);
|
|
44
|
+
return stateChainGateway.getMinimumFunding();
|
|
45
|
+
}, "getMinimumFunding");
|
|
46
|
+
var getRedemptionDelay = /* @__PURE__ */ __name((options) => {
|
|
47
|
+
const stateChainGateway = getStateChainGateway(options);
|
|
48
|
+
return stateChainGateway.REDEMPTION_DELAY();
|
|
49
|
+
}, "getRedemptionDelay");
|
|
50
|
+
|
|
51
|
+
// src/funding/index.ts
|
|
52
|
+
var FundingSDK = class {
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.options = {
|
|
55
|
+
signer: options.signer,
|
|
56
|
+
network: options.network ?? ChainflipNetworks.perseverance
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @param accountId the hex-encoded validator account id
|
|
61
|
+
* @param amount the amount to fund in base units of FLIP
|
|
62
|
+
* @param signer a signer to use for the transaction if different from the one
|
|
63
|
+
* provided in the constructor
|
|
64
|
+
*/
|
|
65
|
+
async fundStateChainAccount(accountId, amount) {
|
|
66
|
+
const tx = await fundStateChainAccount(accountId, amount, this.options);
|
|
67
|
+
return tx.transactionHash;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @param accountId the hex-encoded validator account id
|
|
71
|
+
* @param signer a signer to use for the transaction if different from the one
|
|
72
|
+
* provided in the constructor
|
|
73
|
+
*/
|
|
74
|
+
async executeRedemption(accountId) {
|
|
75
|
+
const tx = await executeRedemption(accountId, this.options);
|
|
76
|
+
return tx.transactionHash;
|
|
77
|
+
}
|
|
78
|
+
async getMinimumFunding() {
|
|
79
|
+
const amount = await getMinimumFunding(this.options);
|
|
80
|
+
return amount.toBigInt();
|
|
81
|
+
}
|
|
82
|
+
async getRedemptionDelay() {
|
|
83
|
+
return getRedemptionDelay(this.options);
|
|
84
|
+
}
|
|
85
|
+
async getFlipBalance() {
|
|
86
|
+
return getFlipBalance(this.options.network, this.options.signer);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @param amount the amount of FLIP to request approval for
|
|
90
|
+
* @returns the transaction hash or null if no approval was required
|
|
91
|
+
*/
|
|
92
|
+
async approveStateChainGateway(amount, nonce) {
|
|
93
|
+
const receipt = await approveStateChainGateway(amount, {
|
|
94
|
+
nonce,
|
|
95
|
+
...this.options
|
|
96
|
+
});
|
|
97
|
+
return receipt && receipt.transactionHash;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__name(FundingSDK, "FundingSDK");
|
|
101
|
+
|
|
102
|
+
export { FundingSDK };
|
package/dist/swap.d.ts
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { Signer } from 'ethers';
|
|
2
|
+
import { C as Chain, c as chainAssets, A as Asset, a as ChainflipNetwork } from './enums-d5fa72fa.js';
|
|
3
|
+
export { d as Assets, e as ChainflipNetworks, b as Chains, f as assetChains, h as assetContractIds, g as assetDecimals, i as chainContractIds } from './enums-d5fa72fa.js';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
declare const tokenSwapParamsSchema: z.ZodUnion<[z.ZodObject<{
|
|
7
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
8
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
9
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
10
|
+
srcAsset: z.ZodLiteral<"FLIP">;
|
|
11
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"USDC">, z.ZodLiteral<"ETH">]>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
amount: string | bigint;
|
|
14
|
+
destChain: "Ethereum";
|
|
15
|
+
destAddress: `0x${string}`;
|
|
16
|
+
destAsset: "USDC" | "ETH";
|
|
17
|
+
srcAsset: "FLIP";
|
|
18
|
+
}, {
|
|
19
|
+
amount: string | bigint;
|
|
20
|
+
destChain: "Ethereum";
|
|
21
|
+
destAddress: `0x${string}`;
|
|
22
|
+
destAsset: "USDC" | "ETH";
|
|
23
|
+
srcAsset: "FLIP";
|
|
24
|
+
}>, z.ZodObject<{
|
|
25
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
26
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
27
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
28
|
+
srcAsset: z.ZodLiteral<"USDC">;
|
|
29
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"ETH">]>;
|
|
30
|
+
}, "strip", z.ZodTypeAny, {
|
|
31
|
+
amount: string | bigint;
|
|
32
|
+
destChain: "Ethereum";
|
|
33
|
+
destAddress: `0x${string}`;
|
|
34
|
+
destAsset: "FLIP" | "ETH";
|
|
35
|
+
srcAsset: "USDC";
|
|
36
|
+
}, {
|
|
37
|
+
amount: string | bigint;
|
|
38
|
+
destChain: "Ethereum";
|
|
39
|
+
destAddress: `0x${string}`;
|
|
40
|
+
destAsset: "FLIP" | "ETH";
|
|
41
|
+
srcAsset: "USDC";
|
|
42
|
+
}>, z.ZodObject<{
|
|
43
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
44
|
+
destChain: z.ZodLiteral<"Polkadot">;
|
|
45
|
+
destAddress: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>]>, string | null, string>, string, string>, string, string>;
|
|
46
|
+
destAsset: z.ZodLiteral<"DOT">;
|
|
47
|
+
srcAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
48
|
+
}, "strict", z.ZodTypeAny, {
|
|
49
|
+
amount: string | bigint;
|
|
50
|
+
destChain: "Polkadot";
|
|
51
|
+
destAddress: string;
|
|
52
|
+
destAsset: "DOT";
|
|
53
|
+
srcAsset: "FLIP" | "USDC";
|
|
54
|
+
}, {
|
|
55
|
+
amount: string | bigint;
|
|
56
|
+
destChain: "Polkadot";
|
|
57
|
+
destAddress: string;
|
|
58
|
+
destAsset: "DOT";
|
|
59
|
+
srcAsset: "FLIP" | "USDC";
|
|
60
|
+
}>, z.ZodObject<{
|
|
61
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
62
|
+
destChain: z.ZodLiteral<"Bitcoin">;
|
|
63
|
+
destAddress: z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>, string, string>;
|
|
64
|
+
destAsset: z.ZodLiteral<"BTC">;
|
|
65
|
+
srcAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
66
|
+
}, "strict", z.ZodTypeAny, {
|
|
67
|
+
amount: string | bigint;
|
|
68
|
+
destChain: "Bitcoin";
|
|
69
|
+
destAddress: string;
|
|
70
|
+
destAsset: "BTC";
|
|
71
|
+
srcAsset: "FLIP" | "USDC";
|
|
72
|
+
}, {
|
|
73
|
+
amount: string | bigint;
|
|
74
|
+
destChain: "Bitcoin";
|
|
75
|
+
destAddress: string;
|
|
76
|
+
destAsset: "BTC";
|
|
77
|
+
srcAsset: "FLIP" | "USDC";
|
|
78
|
+
}>]>;
|
|
79
|
+
type TokenSwapParams = z.infer<typeof tokenSwapParamsSchema>;
|
|
80
|
+
declare const executeSwapParamsSchema: z.ZodUnion<[z.ZodUnion<[z.ZodObject<{
|
|
81
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
82
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
83
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
84
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
85
|
+
}, "strict", z.ZodTypeAny, {
|
|
86
|
+
amount: string | bigint;
|
|
87
|
+
destChain: "Ethereum";
|
|
88
|
+
destAddress: `0x${string}`;
|
|
89
|
+
destAsset: "FLIP" | "USDC";
|
|
90
|
+
}, {
|
|
91
|
+
amount: string | bigint;
|
|
92
|
+
destChain: "Ethereum";
|
|
93
|
+
destAddress: `0x${string}`;
|
|
94
|
+
destAsset: "FLIP" | "USDC";
|
|
95
|
+
}>, z.ZodObject<{
|
|
96
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
97
|
+
destChain: z.ZodLiteral<"Polkadot">;
|
|
98
|
+
destAddress: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>]>, string | null, string>, string, string>, string, string>;
|
|
99
|
+
destAsset: z.ZodLiteral<"DOT">;
|
|
100
|
+
}, "strict", z.ZodTypeAny, {
|
|
101
|
+
amount: string | bigint;
|
|
102
|
+
destChain: "Polkadot";
|
|
103
|
+
destAddress: string;
|
|
104
|
+
destAsset: "DOT";
|
|
105
|
+
}, {
|
|
106
|
+
amount: string | bigint;
|
|
107
|
+
destChain: "Polkadot";
|
|
108
|
+
destAddress: string;
|
|
109
|
+
destAsset: "DOT";
|
|
110
|
+
}>, z.ZodObject<{
|
|
111
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
112
|
+
destChain: z.ZodLiteral<"Bitcoin">;
|
|
113
|
+
destAddress: z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>, string, string>;
|
|
114
|
+
destAsset: z.ZodLiteral<"BTC">;
|
|
115
|
+
}, "strict", z.ZodTypeAny, {
|
|
116
|
+
amount: string | bigint;
|
|
117
|
+
destChain: "Bitcoin";
|
|
118
|
+
destAddress: string;
|
|
119
|
+
destAsset: "BTC";
|
|
120
|
+
}, {
|
|
121
|
+
amount: string | bigint;
|
|
122
|
+
destChain: "Bitcoin";
|
|
123
|
+
destAddress: string;
|
|
124
|
+
destAsset: "BTC";
|
|
125
|
+
}>]>, z.ZodUnion<[z.ZodObject<{
|
|
126
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
127
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
128
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
129
|
+
srcAsset: z.ZodLiteral<"FLIP">;
|
|
130
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"USDC">, z.ZodLiteral<"ETH">]>;
|
|
131
|
+
}, "strip", z.ZodTypeAny, {
|
|
132
|
+
amount: string | bigint;
|
|
133
|
+
destChain: "Ethereum";
|
|
134
|
+
destAddress: `0x${string}`;
|
|
135
|
+
destAsset: "USDC" | "ETH";
|
|
136
|
+
srcAsset: "FLIP";
|
|
137
|
+
}, {
|
|
138
|
+
amount: string | bigint;
|
|
139
|
+
destChain: "Ethereum";
|
|
140
|
+
destAddress: `0x${string}`;
|
|
141
|
+
destAsset: "USDC" | "ETH";
|
|
142
|
+
srcAsset: "FLIP";
|
|
143
|
+
}>, z.ZodObject<{
|
|
144
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
145
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
146
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
147
|
+
srcAsset: z.ZodLiteral<"USDC">;
|
|
148
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"ETH">]>;
|
|
149
|
+
}, "strip", z.ZodTypeAny, {
|
|
150
|
+
amount: string | bigint;
|
|
151
|
+
destChain: "Ethereum";
|
|
152
|
+
destAddress: `0x${string}`;
|
|
153
|
+
destAsset: "FLIP" | "ETH";
|
|
154
|
+
srcAsset: "USDC";
|
|
155
|
+
}, {
|
|
156
|
+
amount: string | bigint;
|
|
157
|
+
destChain: "Ethereum";
|
|
158
|
+
destAddress: `0x${string}`;
|
|
159
|
+
destAsset: "FLIP" | "ETH";
|
|
160
|
+
srcAsset: "USDC";
|
|
161
|
+
}>, z.ZodObject<{
|
|
162
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
163
|
+
destChain: z.ZodLiteral<"Polkadot">;
|
|
164
|
+
destAddress: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>]>, string | null, string>, string, string>, string, string>;
|
|
165
|
+
destAsset: z.ZodLiteral<"DOT">;
|
|
166
|
+
srcAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
167
|
+
}, "strict", z.ZodTypeAny, {
|
|
168
|
+
amount: string | bigint;
|
|
169
|
+
destChain: "Polkadot";
|
|
170
|
+
destAddress: string;
|
|
171
|
+
destAsset: "DOT";
|
|
172
|
+
srcAsset: "FLIP" | "USDC";
|
|
173
|
+
}, {
|
|
174
|
+
amount: string | bigint;
|
|
175
|
+
destChain: "Polkadot";
|
|
176
|
+
destAddress: string;
|
|
177
|
+
destAsset: "DOT";
|
|
178
|
+
srcAsset: "FLIP" | "USDC";
|
|
179
|
+
}>, z.ZodObject<{
|
|
180
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
181
|
+
destChain: z.ZodLiteral<"Bitcoin">;
|
|
182
|
+
destAddress: z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>, string, string>;
|
|
183
|
+
destAsset: z.ZodLiteral<"BTC">;
|
|
184
|
+
srcAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
185
|
+
}, "strict", z.ZodTypeAny, {
|
|
186
|
+
amount: string | bigint;
|
|
187
|
+
destChain: "Bitcoin";
|
|
188
|
+
destAddress: string;
|
|
189
|
+
destAsset: "BTC";
|
|
190
|
+
srcAsset: "FLIP" | "USDC";
|
|
191
|
+
}, {
|
|
192
|
+
amount: string | bigint;
|
|
193
|
+
destChain: "Bitcoin";
|
|
194
|
+
destAddress: string;
|
|
195
|
+
destAsset: "BTC";
|
|
196
|
+
srcAsset: "FLIP" | "USDC";
|
|
197
|
+
}>]>]>;
|
|
198
|
+
type ExecuteSwapParams = z.infer<typeof executeSwapParamsSchema>;
|
|
199
|
+
declare const executeCallParamsSchema: z.ZodUnion<[z.ZodObject<{
|
|
200
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
201
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
202
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
203
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"USDC">]>;
|
|
204
|
+
message: z.ZodString;
|
|
205
|
+
gasAmount: z.ZodString;
|
|
206
|
+
}, "strict", z.ZodTypeAny, {
|
|
207
|
+
amount: string | bigint;
|
|
208
|
+
message: string;
|
|
209
|
+
gasAmount: string;
|
|
210
|
+
destChain: "Ethereum";
|
|
211
|
+
destAddress: `0x${string}`;
|
|
212
|
+
destAsset: "FLIP" | "USDC";
|
|
213
|
+
}, {
|
|
214
|
+
amount: string | bigint;
|
|
215
|
+
message: string;
|
|
216
|
+
gasAmount: string;
|
|
217
|
+
destChain: "Ethereum";
|
|
218
|
+
destAddress: `0x${string}`;
|
|
219
|
+
destAsset: "FLIP" | "USDC";
|
|
220
|
+
}>, z.ZodUnion<[z.ZodObject<{
|
|
221
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
222
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
223
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
224
|
+
srcAsset: z.ZodLiteral<"FLIP">;
|
|
225
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"USDC">, z.ZodLiteral<"ETH">]>;
|
|
226
|
+
message: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
227
|
+
gasAmount: z.ZodString;
|
|
228
|
+
}, "strip", z.ZodTypeAny, {
|
|
229
|
+
amount: string | bigint;
|
|
230
|
+
message: `0x${string}`;
|
|
231
|
+
gasAmount: string;
|
|
232
|
+
destChain: "Ethereum";
|
|
233
|
+
destAddress: `0x${string}`;
|
|
234
|
+
destAsset: "USDC" | "ETH";
|
|
235
|
+
srcAsset: "FLIP";
|
|
236
|
+
}, {
|
|
237
|
+
amount: string | bigint;
|
|
238
|
+
message: `0x${string}`;
|
|
239
|
+
gasAmount: string;
|
|
240
|
+
destChain: "Ethereum";
|
|
241
|
+
destAddress: `0x${string}`;
|
|
242
|
+
destAsset: "USDC" | "ETH";
|
|
243
|
+
srcAsset: "FLIP";
|
|
244
|
+
}>, z.ZodObject<{
|
|
245
|
+
amount: z.ZodUnion<[z.ZodString, z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodBigInt]>;
|
|
246
|
+
destChain: z.ZodLiteral<"Ethereum">;
|
|
247
|
+
destAddress: z.ZodEffects<z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, `0x${string}`, `0x${string}`>;
|
|
248
|
+
srcAsset: z.ZodLiteral<"USDC">;
|
|
249
|
+
destAsset: z.ZodUnion<[z.ZodLiteral<"FLIP">, z.ZodLiteral<"ETH">]>;
|
|
250
|
+
message: z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>;
|
|
251
|
+
gasAmount: z.ZodString;
|
|
252
|
+
}, "strip", z.ZodTypeAny, {
|
|
253
|
+
amount: string | bigint;
|
|
254
|
+
message: `0x${string}`;
|
|
255
|
+
gasAmount: string;
|
|
256
|
+
destChain: "Ethereum";
|
|
257
|
+
destAddress: `0x${string}`;
|
|
258
|
+
destAsset: "FLIP" | "ETH";
|
|
259
|
+
srcAsset: "USDC";
|
|
260
|
+
}, {
|
|
261
|
+
amount: string | bigint;
|
|
262
|
+
message: `0x${string}`;
|
|
263
|
+
gasAmount: string;
|
|
264
|
+
destChain: "Ethereum";
|
|
265
|
+
destAddress: `0x${string}`;
|
|
266
|
+
destAsset: "FLIP" | "ETH";
|
|
267
|
+
srcAsset: "USDC";
|
|
268
|
+
}>]>]>;
|
|
269
|
+
type ExecuteCallParams = z.infer<typeof executeCallParamsSchema>;
|
|
270
|
+
|
|
271
|
+
declare const ccmMetadataSchema: z.ZodObject<{
|
|
272
|
+
gasBudget: z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodNumber]>;
|
|
273
|
+
message: z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodString]>;
|
|
274
|
+
cfParameters: z.ZodOptional<z.ZodUnion<[z.ZodType<`0x${string}`, z.ZodTypeDef, `0x${string}`>, z.ZodString]>>;
|
|
275
|
+
}, "strip", z.ZodTypeAny, {
|
|
276
|
+
message: string;
|
|
277
|
+
gasBudget: number | `0x${string}`;
|
|
278
|
+
cfParameters?: string | undefined;
|
|
279
|
+
}, {
|
|
280
|
+
message: string;
|
|
281
|
+
gasBudget: number | `0x${string}`;
|
|
282
|
+
cfParameters?: string | undefined;
|
|
283
|
+
}>;
|
|
284
|
+
type CcmMetadata = z.infer<typeof ccmMetadataSchema>;
|
|
285
|
+
declare const quoteResponseSchema: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
|
|
286
|
+
id: z.ZodString;
|
|
287
|
+
intermediate_amount: z.ZodString;
|
|
288
|
+
egress_amount: z.ZodString;
|
|
289
|
+
}, "strip", z.ZodTypeAny, {
|
|
290
|
+
id: string;
|
|
291
|
+
intermediate_amount: string;
|
|
292
|
+
egress_amount: string;
|
|
293
|
+
}, {
|
|
294
|
+
id: string;
|
|
295
|
+
intermediate_amount: string;
|
|
296
|
+
egress_amount: string;
|
|
297
|
+
}>, {
|
|
298
|
+
id: string;
|
|
299
|
+
intermediateAmount: string;
|
|
300
|
+
egressAmount: string;
|
|
301
|
+
}, {
|
|
302
|
+
id: string;
|
|
303
|
+
intermediate_amount: string;
|
|
304
|
+
egress_amount: string;
|
|
305
|
+
}>, z.ZodEffects<z.ZodObject<{
|
|
306
|
+
id: z.ZodString;
|
|
307
|
+
egress_amount: z.ZodString;
|
|
308
|
+
}, "strip", z.ZodTypeAny, {
|
|
309
|
+
id: string;
|
|
310
|
+
egress_amount: string;
|
|
311
|
+
}, {
|
|
312
|
+
id: string;
|
|
313
|
+
egress_amount: string;
|
|
314
|
+
}>, {
|
|
315
|
+
id: string;
|
|
316
|
+
egressAmount: string;
|
|
317
|
+
}, {
|
|
318
|
+
id: string;
|
|
319
|
+
egress_amount: string;
|
|
320
|
+
}>]>;
|
|
321
|
+
type QuoteQueryResponse = z.infer<typeof quoteResponseSchema>;
|
|
322
|
+
|
|
323
|
+
interface ChainData {
|
|
324
|
+
id: Chain;
|
|
325
|
+
name: string;
|
|
326
|
+
isMainnet: boolean;
|
|
327
|
+
}
|
|
328
|
+
type AssetData = {
|
|
329
|
+
[K in keyof typeof chainAssets]: {
|
|
330
|
+
id: (typeof chainAssets)[K][number];
|
|
331
|
+
chain: K;
|
|
332
|
+
contractAddress: string;
|
|
333
|
+
decimals: number;
|
|
334
|
+
name: string;
|
|
335
|
+
symbol: string;
|
|
336
|
+
isMainnet: boolean;
|
|
337
|
+
};
|
|
338
|
+
}[keyof typeof chainAssets];
|
|
339
|
+
interface ChainsAndAssets {
|
|
340
|
+
srcChain: Chain;
|
|
341
|
+
destChain: Chain;
|
|
342
|
+
srcAsset: Asset;
|
|
343
|
+
destAsset: Asset;
|
|
344
|
+
}
|
|
345
|
+
interface QuoteRequest extends ChainsAndAssets {
|
|
346
|
+
amount: string;
|
|
347
|
+
}
|
|
348
|
+
interface QuoteResponse extends QuoteRequest {
|
|
349
|
+
quote: QuoteQueryResponse;
|
|
350
|
+
}
|
|
351
|
+
interface DepositAddressRequest extends QuoteRequest {
|
|
352
|
+
destAddress: string;
|
|
353
|
+
ccmMetadata?: CcmMetadata;
|
|
354
|
+
}
|
|
355
|
+
interface DepositAddressResponse extends DepositAddressRequest {
|
|
356
|
+
depositChannelId: string;
|
|
357
|
+
depositAddress: string;
|
|
358
|
+
}
|
|
359
|
+
interface SwapStatusRequest {
|
|
360
|
+
id: string;
|
|
361
|
+
}
|
|
362
|
+
interface CommonStatusFields extends ChainsAndAssets {
|
|
363
|
+
destAddress: string;
|
|
364
|
+
depositAddress: string;
|
|
365
|
+
expectedDepositAmount: string;
|
|
366
|
+
}
|
|
367
|
+
type SwapStatusResponse = CommonStatusFields & ({
|
|
368
|
+
state: 'AWAITING_DEPOSIT';
|
|
369
|
+
} | {
|
|
370
|
+
state: 'DEPOSIT_RECEIVED';
|
|
371
|
+
depositAmount: string;
|
|
372
|
+
depositReceivedAt: number;
|
|
373
|
+
depositReceivedBlockIndex: string;
|
|
374
|
+
} | {
|
|
375
|
+
state: 'SWAP_EXECUTED';
|
|
376
|
+
depositAmount: string;
|
|
377
|
+
depositReceivedAt: number;
|
|
378
|
+
depositReceivedBlockIndex: string;
|
|
379
|
+
swapExecutedAt: number;
|
|
380
|
+
swapExecutedBlockIndex: string;
|
|
381
|
+
} | {
|
|
382
|
+
state: 'EGRESS_SCHEDULED';
|
|
383
|
+
depositAmount: string;
|
|
384
|
+
depositReceivedAt: number;
|
|
385
|
+
depositReceivedBlockIndex: string;
|
|
386
|
+
swapExecutedAt: number;
|
|
387
|
+
swapExecutedBlockIndex: string;
|
|
388
|
+
egressAmount: string;
|
|
389
|
+
egressScheduledAt: number;
|
|
390
|
+
} | {
|
|
391
|
+
state: 'COMPLETE';
|
|
392
|
+
depositAmount: string;
|
|
393
|
+
depositReceivedAt: number;
|
|
394
|
+
depositReceivedBlockIndex: string;
|
|
395
|
+
swapExecutedAt: number;
|
|
396
|
+
swapExecutedBlockIndex: string;
|
|
397
|
+
egressAmount: string;
|
|
398
|
+
egressScheduledAt: number;
|
|
399
|
+
egressCompletedAt: number;
|
|
400
|
+
egressCompletedBlockIndex: string;
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
type RequestOptions = {
|
|
404
|
+
signal?: AbortSignal;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
type TransactionHash = string;
|
|
408
|
+
type SDKOptions = {
|
|
409
|
+
network?: Exclude<ChainflipNetwork, 'mainnet'>;
|
|
410
|
+
signer?: Signer;
|
|
411
|
+
backendUrl?: string;
|
|
412
|
+
};
|
|
413
|
+
declare class SwapSDK {
|
|
414
|
+
private readonly baseUrl;
|
|
415
|
+
private readonly network;
|
|
416
|
+
private readonly signer?;
|
|
417
|
+
constructor(options?: SDKOptions);
|
|
418
|
+
getChains(sourceChain?: Chain): Promise<ChainData[]>;
|
|
419
|
+
getAssets(chain: Chain): Promise<AssetData[]>;
|
|
420
|
+
getQuote(quoteRequest: QuoteRequest, options?: RequestOptions): Promise<QuoteResponse>;
|
|
421
|
+
requestDepositAddress(depositAddressRequest: DepositAddressRequest, options?: RequestOptions): Promise<DepositAddressResponse>;
|
|
422
|
+
getStatus(swapStatusRequest: SwapStatusRequest, options?: RequestOptions): Promise<SwapStatusResponse>;
|
|
423
|
+
executeSwap(params: ExecuteSwapParams): Promise<TransactionHash>;
|
|
424
|
+
executeCall(params: ExecuteCallParams): Promise<TransactionHash>;
|
|
425
|
+
approveVault(params: Pick<TokenSwapParams, 'srcAsset' | 'amount'>, options?: {
|
|
426
|
+
nonce?: bigint | number | string;
|
|
427
|
+
}): Promise<TransactionHash | null>;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export { Asset, AssetData, Chain, ChainData, ChainflipNetwork, DepositAddressRequest, DepositAddressResponse, QuoteRequest, QuoteResponse, SDKOptions, SwapSDK, SwapStatusRequest, SwapStatusResponse, chainAssets };
|