@pioneer-platform/chainflip-client 0.0.10 → 0.1.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/lib/broker.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { type AssetValue, type GenericSwapParams } from "@swapkit/helpers";
2
- import type { ETHToolbox } from "@swapkit/toolbox-evm";
3
- import type { ChainflipToolbox } from "@swapkit/toolbox-substrate";
4
- import type { SwapDepositResponse, WithdrawFeeResponse } from "./types.ts";
5
- export declare const ChainflipBroker: (chainflipToolbox: Awaited<ReturnType<typeof ChainflipToolbox>>) => {
6
- registerAsBroker: (address: string) => Promise<string | (() => void)>;
7
- requestSwapDepositAddress: (chainflipTransaction: GenericSwapParams & {
8
- brokerCommissionBPS: number;
9
- }) => Promise<SwapDepositResponse>;
10
- fundStateChainAccount: (stateChainAccount: string, amount: AssetValue, evmToolbox: ReturnType<typeof ETHToolbox>) => Promise<string>;
11
- withdrawFee: (params: {
12
- feeAsset: AssetValue;
13
- recipient: string;
14
- }) => Promise<WithdrawFeeResponse>;
15
- };
package/lib/broker.js DELETED
@@ -1,128 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ChainflipBroker = void 0;
13
- const swap_1 = require("@chainflip/sdk/swap");
14
- const helpers_1 = require("@swapkit/helpers");
15
- const helpers_2 = require("@swapkit/helpers");
16
- const keyring_1 = require("@polkadot/keyring");
17
- const util_1 = require("@polkadot/util");
18
- const chainflipGatewayABI_ts_1 = require("./chainflipGatewayABI.ts");
19
- const chainToChainflipChain = new Map([
20
- [helpers_2.Chain.Ethereum, swap_1.Chains.Ethereum],
21
- [helpers_2.Chain.Bitcoin, swap_1.Chains.Bitcoin],
22
- [helpers_2.Chain.Polkadot, swap_1.Chains.Polkadot],
23
- ]);
24
- const registerAsBroker = (toolbox, address) => {
25
- var _a, _b;
26
- const extrinsic = (_b = (_a = toolbox.api.tx.swapping) === null || _a === void 0 ? void 0 : _a.registerAsBroker) === null || _b === void 0 ? void 0 : _b.call(_a, address);
27
- if (!extrinsic) {
28
- throw new Error("chainflip_broker_register");
29
- }
30
- return toolbox.signAndBroadcast(extrinsic);
31
- };
32
- const requestSwapDepositAddress = (toolbox, { sellAsset, buyAsset, recipient, brokerCommissionBPS, }) => __awaiter(void 0, void 0, void 0, function* () {
33
- const isBuyChainPolkadot = buyAsset.chain === helpers_2.Chain.Polkadot;
34
- const recipientAddress = (0, helpers_1.wrapWithThrow)(() => {
35
- return isBuyChainPolkadot
36
- ? toolbox.encodeAddress(toolbox.decodeAddress(recipient), "hex")
37
- : recipient;
38
- }, "chainflip_broker_recipient_error");
39
- return new Promise((resolve) => {
40
- var _a, _b;
41
- const tx = (_b = (_a = toolbox.api.tx.swapping) === null || _a === void 0 ? void 0 : _a.requestSwapDepositAddress) === null || _b === void 0 ? void 0 : _b.call(_a, sellAsset.ticker.toLowerCase(), buyAsset.ticker.toLowerCase(), { [buyAsset.chain.toLowerCase()]: recipientAddress }, helpers_1.SwapKitNumber.fromBigInt(BigInt(brokerCommissionBPS)).getBaseValue("number"), null, 0);
42
- if (!tx) {
43
- throw new Error("chainflip_broker_tx_error");
44
- }
45
- toolbox.signAndBroadcast(tx, (result) => __awaiter(void 0, void 0, void 0, function* () {
46
- var _c, _d, _e;
47
- if (!((_c = result.status) === null || _c === void 0 ? void 0 : _c.isFinalized)) {
48
- return;
49
- }
50
- const depositChannelEvent = result.events.find((event) => event.event.method === "SwapDepositAddressReady");
51
- if (!depositChannelEvent) {
52
- throw new helpers_1.SwapKitError("chainflip_channel_error", "Could not find 'SwapDepositAddressReady' event");
53
- }
54
- const { event: { data: { depositAddress, sourceChainExpiryBlock, destinationAddress, channelId }, }, } = depositChannelEvent.toHuman();
55
- const hash = (_e = (_d = result.status) === null || _d === void 0 ? void 0 : _d.toJSON) === null || _e === void 0 ? void 0 : _e.call(_d);
56
- const header = yield toolbox.api.rpc.chain.getHeader(hash === null || hash === void 0 ? void 0 : hash.finalized);
57
- const depositChannelId = `${header.number}-${chainToChainflipChain.get(sellAsset.chain)}-${channelId.replaceAll(",", "")}`;
58
- resolve({
59
- brokerCommissionBPS,
60
- buyAsset,
61
- depositAddress: Object.values(depositAddress)[0],
62
- depositChannelId,
63
- recipient: Object.values(destinationAddress)[0],
64
- sellAsset,
65
- srcChainExpiryBlock: Number(sourceChainExpiryBlock.replaceAll(",", "")),
66
- });
67
- }));
68
- });
69
- });
70
- const withdrawFee = (toolbox, { feeAsset, recipient }) => {
71
- const isFeeChainPolkadot = feeAsset.chain === helpers_2.Chain.Polkadot;
72
- const recipientAddress = (0, helpers_1.wrapWithThrow)(() => {
73
- return isFeeChainPolkadot
74
- ? toolbox.encodeAddress(toolbox.decodeAddress(recipient), "hex")
75
- : recipient;
76
- }, "chainflip_broker_recipient_error");
77
- return new Promise((resolve) => {
78
- var _a, _b, _c;
79
- const extrinsic = (_c = (_b = (_a = toolbox.api.tx) === null || _a === void 0 ? void 0 : _a.swapping) === null || _b === void 0 ? void 0 : _b.withdraw) === null || _c === void 0 ? void 0 : _c.call(_b, feeAsset.ticker.toLowerCase(), {
80
- [feeAsset.chain.toLowerCase()]: recipientAddress,
81
- });
82
- if (!extrinsic) {
83
- throw new Error("chainflip_broker_withdraw");
84
- }
85
- toolbox.signAndBroadcast(extrinsic, (result) => __awaiter(void 0, void 0, void 0, function* () {
86
- var _d;
87
- if (!((_d = result.status) === null || _d === void 0 ? void 0 : _d.isFinalized)) {
88
- return;
89
- }
90
- const withdrawEvent = result.events.find((event) => event.event.method === "WithdrawalRequested");
91
- if (!withdrawEvent) {
92
- throw new helpers_1.SwapKitError("chainflip_channel_error", "Could not find 'WithdrawalRequested' event");
93
- }
94
- const { event: { data: { egressId, egressAsset, egressAmount, egressFee, destinationAddress }, }, } = withdrawEvent.toHuman();
95
- resolve({
96
- egressId,
97
- egressAsset,
98
- egressAmount,
99
- egressFee,
100
- destinationAddress,
101
- });
102
- }));
103
- });
104
- };
105
- const fundStateChainAccount = (evmToolbox, chainflipToolbox, stateChainAccount, amount) => {
106
- if (amount.symbol !== "FLIP") {
107
- throw new Error("Only FLIP is supported");
108
- }
109
- if (!chainflipToolbox.validateAddress(stateChainAccount)) {
110
- throw new Error("Invalid address");
111
- }
112
- const hexAddress = (0, util_1.isHex)(stateChainAccount)
113
- ? stateChainAccount
114
- : (0, util_1.u8aToHex)((0, keyring_1.decodeAddress)(stateChainAccount));
115
- return evmToolbox.call({
116
- abi: chainflipGatewayABI_ts_1.chainflipGateway,
117
- contractAddress: "0x6995ab7c4d7f4b03f467cf4c8e920427d9621dbd",
118
- funcName: "fundStateChainAccount",
119
- funcParams: [hexAddress, amount],
120
- });
121
- };
122
- const ChainflipBroker = (chainflipToolbox) => ({
123
- registerAsBroker: (address) => registerAsBroker(chainflipToolbox, address),
124
- requestSwapDepositAddress: (chainflipTransaction) => requestSwapDepositAddress(chainflipToolbox, chainflipTransaction),
125
- fundStateChainAccount: (stateChainAccount, amount, evmToolbox) => fundStateChainAccount(evmToolbox, chainflipToolbox, stateChainAccount, amount),
126
- withdrawFee: (params) => withdrawFee(chainflipToolbox, params),
127
- });
128
- exports.ChainflipBroker = ChainflipBroker;
@@ -1,80 +0,0 @@
1
- export declare const chainflipGateway: ({
2
- inputs: {
3
- internalType: string;
4
- name: string;
5
- type: string;
6
- }[];
7
- stateMutability: string;
8
- type: string;
9
- anonymous?: undefined;
10
- name?: undefined;
11
- outputs?: undefined;
12
- } | {
13
- anonymous: boolean;
14
- inputs: {
15
- indexed: boolean;
16
- internalType: string;
17
- name: string;
18
- type: string;
19
- }[];
20
- name: string;
21
- type: string;
22
- stateMutability?: undefined;
23
- outputs?: undefined;
24
- } | {
25
- inputs: {
26
- internalType: string;
27
- name: string;
28
- type: string;
29
- }[];
30
- name: string;
31
- outputs: {
32
- internalType: string;
33
- name: string;
34
- type: string;
35
- }[];
36
- stateMutability: string;
37
- type: string;
38
- anonymous?: undefined;
39
- } | {
40
- inputs: {
41
- internalType: string;
42
- name: string;
43
- type: string;
44
- }[];
45
- name: string;
46
- outputs: {
47
- components: {
48
- internalType: string;
49
- name: string;
50
- type: string;
51
- }[];
52
- internalType: string;
53
- name: string;
54
- type: string;
55
- }[];
56
- stateMutability: string;
57
- type: string;
58
- anonymous?: undefined;
59
- } | {
60
- inputs: ({
61
- components: {
62
- internalType: string;
63
- name: string;
64
- type: string;
65
- }[];
66
- internalType: string;
67
- name: string;
68
- type: string;
69
- } | {
70
- internalType: string;
71
- name: string;
72
- type: string;
73
- components?: undefined;
74
- })[];
75
- name: string;
76
- outputs: never[];
77
- stateMutability: string;
78
- type: string;
79
- anonymous?: undefined;
80
- })[];
@@ -1,333 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chainflipGateway = void 0;
4
- exports.chainflipGateway = [
5
- {
6
- inputs: [
7
- { internalType: "contract IKeyManager", name: "keyManager", type: "address" },
8
- { internalType: "uint256", name: "minFunding", type: "uint256" },
9
- { internalType: "uint48", name: "redemptionDelay", type: "uint48" },
10
- ],
11
- stateMutability: "nonpayable",
12
- type: "constructor",
13
- },
14
- {
15
- anonymous: false,
16
- inputs: [
17
- { indexed: false, internalType: "bool", name: "communityGuardDisabled", type: "bool" },
18
- ],
19
- name: "CommunityGuardDisabled",
20
- type: "event",
21
- },
22
- {
23
- anonymous: false,
24
- inputs: [{ indexed: false, internalType: "address", name: "flip", type: "address" }],
25
- name: "FLIPSet",
26
- type: "event",
27
- },
28
- {
29
- anonymous: false,
30
- inputs: [
31
- { indexed: false, internalType: "uint256", name: "oldSupply", type: "uint256" },
32
- { indexed: false, internalType: "uint256", name: "newSupply", type: "uint256" },
33
- { indexed: false, internalType: "uint256", name: "stateChainBlockNumber", type: "uint256" },
34
- ],
35
- name: "FlipSupplyUpdated",
36
- type: "event",
37
- },
38
- {
39
- anonymous: false,
40
- inputs: [
41
- { indexed: true, internalType: "bytes32", name: "nodeID", type: "bytes32" },
42
- { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
43
- { indexed: false, internalType: "address", name: "funder", type: "address" },
44
- ],
45
- name: "Funded",
46
- type: "event",
47
- },
48
- {
49
- anonymous: false,
50
- inputs: [
51
- { indexed: false, internalType: "address", name: "to", type: "address" },
52
- { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
53
- ],
54
- name: "GovernanceWithdrawal",
55
- type: "event",
56
- },
57
- {
58
- anonymous: false,
59
- inputs: [
60
- { indexed: false, internalType: "uint256", name: "oldMinFunding", type: "uint256" },
61
- { indexed: false, internalType: "uint256", name: "newMinFunding", type: "uint256" },
62
- ],
63
- name: "MinFundingChanged",
64
- type: "event",
65
- },
66
- {
67
- anonymous: false,
68
- inputs: [
69
- { indexed: true, internalType: "bytes32", name: "nodeID", type: "bytes32" },
70
- { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
71
- ],
72
- name: "RedemptionExecuted",
73
- type: "event",
74
- },
75
- {
76
- anonymous: false,
77
- inputs: [
78
- { indexed: true, internalType: "bytes32", name: "nodeID", type: "bytes32" },
79
- { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
80
- ],
81
- name: "RedemptionExpired",
82
- type: "event",
83
- },
84
- {
85
- anonymous: false,
86
- inputs: [
87
- { indexed: true, internalType: "bytes32", name: "nodeID", type: "bytes32" },
88
- { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
89
- { indexed: true, internalType: "address", name: "redeemAddress", type: "address" },
90
- { indexed: false, internalType: "uint48", name: "startTime", type: "uint48" },
91
- { indexed: false, internalType: "uint48", name: "expiryTime", type: "uint48" },
92
- { indexed: false, internalType: "address", name: "executor", type: "address" },
93
- ],
94
- name: "RedemptionRegistered",
95
- type: "event",
96
- },
97
- {
98
- anonymous: false,
99
- inputs: [{ indexed: false, internalType: "bool", name: "suspended", type: "bool" }],
100
- name: "Suspended",
101
- type: "event",
102
- },
103
- {
104
- anonymous: false,
105
- inputs: [{ indexed: false, internalType: "address", name: "keyManager", type: "address" }],
106
- name: "UpdatedKeyManager",
107
- type: "event",
108
- },
109
- {
110
- inputs: [],
111
- name: "REDEMPTION_DELAY",
112
- outputs: [{ internalType: "uint48", name: "", type: "uint48" }],
113
- stateMutability: "view",
114
- type: "function",
115
- },
116
- {
117
- inputs: [],
118
- name: "disableCommunityGuard",
119
- outputs: [],
120
- stateMutability: "nonpayable",
121
- type: "function",
122
- },
123
- {
124
- inputs: [],
125
- name: "enableCommunityGuard",
126
- outputs: [],
127
- stateMutability: "nonpayable",
128
- type: "function",
129
- },
130
- {
131
- inputs: [{ internalType: "bytes32", name: "nodeID", type: "bytes32" }],
132
- name: "executeRedemption",
133
- outputs: [
134
- { internalType: "address", name: "", type: "address" },
135
- { internalType: "uint256", name: "", type: "uint256" },
136
- ],
137
- stateMutability: "nonpayable",
138
- type: "function",
139
- },
140
- {
141
- inputs: [
142
- { internalType: "bytes32", name: "nodeID", type: "bytes32" },
143
- { internalType: "uint256", name: "amount", type: "uint256" },
144
- ],
145
- name: "fundStateChainAccount",
146
- outputs: [],
147
- stateMutability: "nonpayable",
148
- type: "function",
149
- },
150
- {
151
- inputs: [],
152
- name: "getCommunityGuardDisabled",
153
- outputs: [{ internalType: "bool", name: "", type: "bool" }],
154
- stateMutability: "view",
155
- type: "function",
156
- },
157
- {
158
- inputs: [],
159
- name: "getCommunityKey",
160
- outputs: [{ internalType: "address", name: "", type: "address" }],
161
- stateMutability: "view",
162
- type: "function",
163
- },
164
- {
165
- inputs: [],
166
- name: "getFLIP",
167
- outputs: [{ internalType: "contract IFLIP", name: "", type: "address" }],
168
- stateMutability: "view",
169
- type: "function",
170
- },
171
- {
172
- inputs: [],
173
- name: "getGovernor",
174
- outputs: [{ internalType: "address", name: "", type: "address" }],
175
- stateMutability: "view",
176
- type: "function",
177
- },
178
- {
179
- inputs: [],
180
- name: "getKeyManager",
181
- outputs: [{ internalType: "contract IKeyManager", name: "", type: "address" }],
182
- stateMutability: "view",
183
- type: "function",
184
- },
185
- {
186
- inputs: [],
187
- name: "getLastSupplyUpdateBlockNumber",
188
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
189
- stateMutability: "view",
190
- type: "function",
191
- },
192
- {
193
- inputs: [],
194
- name: "getMinimumFunding",
195
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
196
- stateMutability: "view",
197
- type: "function",
198
- },
199
- {
200
- inputs: [{ internalType: "bytes32", name: "nodeID", type: "bytes32" }],
201
- name: "getPendingRedemption",
202
- outputs: [
203
- {
204
- components: [
205
- { internalType: "uint256", name: "amount", type: "uint256" },
206
- { internalType: "address", name: "redeemAddress", type: "address" },
207
- { internalType: "uint48", name: "startTime", type: "uint48" },
208
- { internalType: "uint48", name: "expiryTime", type: "uint48" },
209
- { internalType: "address", name: "executor", type: "address" },
210
- ],
211
- internalType: "struct IStateChainGateway.Redemption",
212
- name: "",
213
- type: "tuple",
214
- },
215
- ],
216
- stateMutability: "view",
217
- type: "function",
218
- },
219
- {
220
- inputs: [],
221
- name: "getSuspendedState",
222
- outputs: [{ internalType: "bool", name: "", type: "bool" }],
223
- stateMutability: "view",
224
- type: "function",
225
- },
226
- {
227
- inputs: [],
228
- name: "govUpdateFlipIssuer",
229
- outputs: [],
230
- stateMutability: "nonpayable",
231
- type: "function",
232
- },
233
- { inputs: [], name: "govWithdraw", outputs: [], stateMutability: "nonpayable", type: "function" },
234
- {
235
- inputs: [
236
- {
237
- components: [
238
- { internalType: "uint256", name: "sig", type: "uint256" },
239
- { internalType: "uint256", name: "nonce", type: "uint256" },
240
- { internalType: "address", name: "kTimesGAddress", type: "address" },
241
- ],
242
- internalType: "struct IShared.SigData",
243
- name: "sigData",
244
- type: "tuple",
245
- },
246
- { internalType: "bytes32", name: "nodeID", type: "bytes32" },
247
- { internalType: "uint256", name: "amount", type: "uint256" },
248
- { internalType: "address", name: "redeemAddress", type: "address" },
249
- { internalType: "uint48", name: "expiryTime", type: "uint48" },
250
- { internalType: "address", name: "executor", type: "address" },
251
- ],
252
- name: "registerRedemption",
253
- outputs: [],
254
- stateMutability: "nonpayable",
255
- type: "function",
256
- },
257
- { inputs: [], name: "resume", outputs: [], stateMutability: "nonpayable", type: "function" },
258
- {
259
- inputs: [{ internalType: "contract IFLIP", name: "flip", type: "address" }],
260
- name: "setFlip",
261
- outputs: [],
262
- stateMutability: "nonpayable",
263
- type: "function",
264
- },
265
- {
266
- inputs: [{ internalType: "uint256", name: "newMinFunding", type: "uint256" }],
267
- name: "setMinFunding",
268
- outputs: [],
269
- stateMutability: "nonpayable",
270
- type: "function",
271
- },
272
- { inputs: [], name: "suspend", outputs: [], stateMutability: "nonpayable", type: "function" },
273
- {
274
- inputs: [
275
- {
276
- components: [
277
- { internalType: "uint256", name: "sig", type: "uint256" },
278
- { internalType: "uint256", name: "nonce", type: "uint256" },
279
- { internalType: "address", name: "kTimesGAddress", type: "address" },
280
- ],
281
- internalType: "struct IShared.SigData",
282
- name: "sigData",
283
- type: "tuple",
284
- },
285
- { internalType: "address", name: "newIssuer", type: "address" },
286
- { internalType: "bool", name: "omitChecks", type: "bool" },
287
- ],
288
- name: "updateFlipIssuer",
289
- outputs: [],
290
- stateMutability: "nonpayable",
291
- type: "function",
292
- },
293
- {
294
- inputs: [
295
- {
296
- components: [
297
- { internalType: "uint256", name: "sig", type: "uint256" },
298
- { internalType: "uint256", name: "nonce", type: "uint256" },
299
- { internalType: "address", name: "kTimesGAddress", type: "address" },
300
- ],
301
- internalType: "struct IShared.SigData",
302
- name: "sigData",
303
- type: "tuple",
304
- },
305
- { internalType: "uint256", name: "newTotalSupply", type: "uint256" },
306
- { internalType: "uint256", name: "stateChainBlockNumber", type: "uint256" },
307
- ],
308
- name: "updateFlipSupply",
309
- outputs: [],
310
- stateMutability: "nonpayable",
311
- type: "function",
312
- },
313
- {
314
- inputs: [
315
- {
316
- components: [
317
- { internalType: "uint256", name: "sig", type: "uint256" },
318
- { internalType: "uint256", name: "nonce", type: "uint256" },
319
- { internalType: "address", name: "kTimesGAddress", type: "address" },
320
- ],
321
- internalType: "struct IShared.SigData",
322
- name: "sigData",
323
- type: "tuple",
324
- },
325
- { internalType: "contract IKeyManager", name: "keyManager", type: "address" },
326
- { internalType: "bool", name: "omitChecks", type: "bool" },
327
- ],
328
- name: "updateKeyManager",
329
- outputs: [],
330
- stateMutability: "nonpayable",
331
- type: "function",
332
- },
333
- ];
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};