@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/CHANGELOG.md +26 -0
- package/package.json +15 -15
- package/LICENSE +0 -674
- package/lib/broker.d.ts +0 -15
- package/lib/broker.js +0 -128
- package/lib/chainflipGatewayABI.d.ts +0 -80
- package/lib/chainflipGatewayABI.js +0 -333
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -198
- package/lib/plugin.d.ts +0 -42
- package/lib/plugin.js +0 -83
- package/lib/types.d.ts +0 -17
- package/lib/types.js +0 -2
package/lib/index.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
chainflip Integration
|
|
4
|
-
- Highlander
|
|
5
|
-
|
|
6
|
-
Notes:
|
|
7
|
-
lol polkadot cant ts bro, https://substrate.stackexchange.com/questions/4542/typescript-errors-when-using-polkadot-api
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
const TAG = " | chainflip | ";
|
|
21
|
-
const { uuid } = require('uuidv4');
|
|
22
|
-
const log = require('@pioneer-platform/loggerdog')();
|
|
23
|
-
let { Chain, caipToNetworkId, shortListSymbolToCaip, ChainToNetworkId, NetworkIdToChain, getChainEnumValue } = require("@pioneer-platform/pioneer-caip");
|
|
24
|
-
const { createMemo, parseMemo } = require('@pioneer-platform/pioneer-coins');
|
|
25
|
-
const axios = require('axios');
|
|
26
|
-
let networkSupport = [
|
|
27
|
-
ChainToNetworkId["BTC"],
|
|
28
|
-
ChainToNetworkId["ETH"],
|
|
29
|
-
];
|
|
30
|
-
let assetSupport = [
|
|
31
|
-
shortListSymbolToCaip["BTC"],
|
|
32
|
-
shortListSymbolToCaip["ETH"],
|
|
33
|
-
];
|
|
34
|
-
module.exports = {
|
|
35
|
-
init: function (settings) {
|
|
36
|
-
return true;
|
|
37
|
-
},
|
|
38
|
-
networkSupport: function () {
|
|
39
|
-
return networkSupport;
|
|
40
|
-
},
|
|
41
|
-
assetSupport: function () {
|
|
42
|
-
return assetSupport;
|
|
43
|
-
},
|
|
44
|
-
getQuote: function (quote) {
|
|
45
|
-
return get_quote(quote);
|
|
46
|
-
},
|
|
47
|
-
lookupTx: function (quoteId) {
|
|
48
|
-
return get_quote_info(quoteId);
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
const get_quote_info = function (quoteId) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
let tag = TAG + " | get_quote_info | ";
|
|
54
|
-
try {
|
|
55
|
-
let output = {};
|
|
56
|
-
// Make a GET request using Axios
|
|
57
|
-
const response = yield axios.get(`https://chainflip-swap.chainflip.io/swaps/${quoteId}`);
|
|
58
|
-
// Assuming the response data is what you want to use
|
|
59
|
-
output.data = response.data;
|
|
60
|
-
return output;
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
console.error(tag, "e: ", e);
|
|
64
|
-
throw e;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
const get_quote = function (quote) {
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
let tag = TAG + " | get_quote | ";
|
|
71
|
-
try {
|
|
72
|
-
let output = {};
|
|
73
|
-
output.steps = 1;
|
|
74
|
-
output.memoless = true;
|
|
75
|
-
output.complete = true;
|
|
76
|
-
output.meta = {
|
|
77
|
-
quoteMode: "CHANGELLY"
|
|
78
|
-
};
|
|
79
|
-
output.complete = true;
|
|
80
|
-
if (!quote.sellAsset)
|
|
81
|
-
throw new Error("missing sellAsset");
|
|
82
|
-
if (!quote.buyAsset)
|
|
83
|
-
throw new Error("missing buyAsset");
|
|
84
|
-
if (!quote.sellAmount)
|
|
85
|
-
throw new Error("missing sellAmount");
|
|
86
|
-
if (!quote.recipientAddress)
|
|
87
|
-
throw new Error("missing recipientAddress");
|
|
88
|
-
if (!quote.slippage)
|
|
89
|
-
throw new Error("missing slippage");
|
|
90
|
-
if (!networkSupport.includes(caipToNetworkId(quote.buyAsset))) {
|
|
91
|
-
throw new Error("unsupported buyAsset");
|
|
92
|
-
}
|
|
93
|
-
if (!networkSupport.includes(caipToNetworkId(quote.sellAsset))) {
|
|
94
|
-
throw new Error("unsupported sellAsset");
|
|
95
|
-
}
|
|
96
|
-
output.sellAsset = {};
|
|
97
|
-
output.sellAsset.caip = quote.sellAsset;
|
|
98
|
-
output.sellAmount = quote.sellAmount;
|
|
99
|
-
output.buyAsset = {};
|
|
100
|
-
output.buyAsset.caip = quote.buyAsset;
|
|
101
|
-
let chainSell = NetworkIdToChain[caipToNetworkId(quote.sellAsset)];
|
|
102
|
-
let chainBuy = NetworkIdToChain[caipToNetworkId(quote.buyAsset)];
|
|
103
|
-
log.info(tag, "chainSell: ", chainSell);
|
|
104
|
-
log.info(tag, "chainBuy: ", chainBuy);
|
|
105
|
-
let longNameSell = Object.keys(Chain).find(key => Chain[key] === chainSell);
|
|
106
|
-
let longNameBuy = Object.keys(Chain).find(key => Chain[key] === chainBuy);
|
|
107
|
-
log.info(tag, "chainSell: ", longNameSell);
|
|
108
|
-
log.info(tag, "chainBuy: ", longNameBuy);
|
|
109
|
-
const decimals = {
|
|
110
|
-
'BTC': 8, // Bitcoin uses 8 decimal places
|
|
111
|
-
'ETH': 18, // Ethereum uses 18 decimal places
|
|
112
|
-
};
|
|
113
|
-
// Helper function to scale the amount by the number of decimals
|
|
114
|
-
function scaleAmount(amount, decimals) {
|
|
115
|
-
return amount * Math.pow(10, decimals);
|
|
116
|
-
}
|
|
117
|
-
// Adjusting the amount according to the asset's decimals
|
|
118
|
-
const amountToQuote = scaleAmount(quote.sellAmount, decimals[chainSell]); // Assumes 1 unit of the selling asset
|
|
119
|
-
log.info(tag, "amountToQuote: ", amountToQuote);
|
|
120
|
-
//get quote
|
|
121
|
-
let params = {
|
|
122
|
-
amount: amountToQuote,
|
|
123
|
-
srcChain: longNameSell,
|
|
124
|
-
srcAsset: chainSell,
|
|
125
|
-
destChain: longNameBuy,
|
|
126
|
-
destAsset: chainBuy
|
|
127
|
-
};
|
|
128
|
-
log.info(tag, "params: ", params);
|
|
129
|
-
const responseQuote = yield axios.get('https://chainflip-swap.chainflip.io/quote', {
|
|
130
|
-
params
|
|
131
|
-
});
|
|
132
|
-
function convertToReadableAmount(amount, decimals) {
|
|
133
|
-
return amount / Math.pow(10, decimals);
|
|
134
|
-
}
|
|
135
|
-
console.log("responseQuote: ", responseQuote.data); // Handle the response data as needed
|
|
136
|
-
const egressAmountReadable = convertToReadableAmount(responseQuote.data.egressAmount, decimals[chainBuy]);
|
|
137
|
-
log.info(tag, "egressAmountReadable: ", egressAmountReadable);
|
|
138
|
-
output.amountOut = egressAmountReadable;
|
|
139
|
-
// //https://chainflip-swap.chainflip.io/trpc/openSwapDepositChannel?batch=1
|
|
140
|
-
const url = 'https://chainflip-swap.chainflip.io/trpc/openSwapDepositChannel?batch=1';
|
|
141
|
-
const data = {
|
|
142
|
-
"0": {
|
|
143
|
-
"json": {
|
|
144
|
-
"srcChain": longNameSell,
|
|
145
|
-
"destChain": longNameBuy,
|
|
146
|
-
"srcAsset": chainSell,
|
|
147
|
-
"destAsset": chainBuy,
|
|
148
|
-
"amount": amountToQuote.toString(),
|
|
149
|
-
"quote": responseQuote.data,
|
|
150
|
-
"destAddress": quote.recipientAddress,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
log.info("data good: ", data);
|
|
155
|
-
const headers = {
|
|
156
|
-
'Accept': '*/*',
|
|
157
|
-
'Accept-Encoding': 'gzip, deflate, br, zstd',
|
|
158
|
-
'Accept-Language': 'en-US,en;q=0.9',
|
|
159
|
-
'Content-Type': 'application/json',
|
|
160
|
-
'Origin': 'https://swap.chainflip.io',
|
|
161
|
-
'Referer': 'https://swap.chainflip.io/',
|
|
162
|
-
'Sec-Ch-Ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
|
|
163
|
-
'Sec-Ch-Ua-Mobile': '?0',
|
|
164
|
-
'Sec-Ch-Ua-Platform': '"macOS"',
|
|
165
|
-
'Sec-Fetch-Dest': 'empty',
|
|
166
|
-
'Sec-Fetch-Mode': 'cors',
|
|
167
|
-
'Sec-Fetch-Site': 'same-site',
|
|
168
|
-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
|
|
169
|
-
};
|
|
170
|
-
const response = yield axios.post(url, data, { headers });
|
|
171
|
-
// console.log(response); // Log the response data
|
|
172
|
-
// console.log(response.data); // Log the response data
|
|
173
|
-
// console.log(JSON.stringify(response.data)); // Log the response data
|
|
174
|
-
let result = response.data[0].result.data.json;
|
|
175
|
-
log.info(tag, "result: ", result);
|
|
176
|
-
output.id = result.id;
|
|
177
|
-
output.source = 'chainflip';
|
|
178
|
-
output.inboundAddress = result.depositAddress;
|
|
179
|
-
output.estimatedExpiryTime = result.estimatedExpiryTime;
|
|
180
|
-
let tx = {
|
|
181
|
-
type: "transfer",
|
|
182
|
-
chain: caipToNetworkId(quote.sellAsset),
|
|
183
|
-
txParams: {
|
|
184
|
-
address: result.depositAddress,
|
|
185
|
-
amount: quote.sellAmount
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
output.txs = [tx];
|
|
189
|
-
output.raw = data;
|
|
190
|
-
return output;
|
|
191
|
-
}
|
|
192
|
-
catch (e) {
|
|
193
|
-
console.error(tag, "e: ", e);
|
|
194
|
-
console.error(tag, "e: ", JSON.stringify(e));
|
|
195
|
-
throw e;
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
};
|
package/lib/plugin.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AssetValue, type BaseWallet } from "@swapkit/helpers";
|
|
2
|
-
export declare function confirmSwap({ buyAsset, sellAsset, recipient, brokerEndpoint, }: {
|
|
3
|
-
buyAsset: AssetValue;
|
|
4
|
-
sellAsset: AssetValue;
|
|
5
|
-
recipient: string;
|
|
6
|
-
brokerEndpoint: string;
|
|
7
|
-
}): Promise<{
|
|
8
|
-
channelId: string;
|
|
9
|
-
depositAddress: string;
|
|
10
|
-
chain: string;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const ChainflipPlugin: {
|
|
13
|
-
readonly chainflip: {
|
|
14
|
-
readonly plugin: ({ wallets, config: { brokerEndpoint }, }: {
|
|
15
|
-
wallets: BaseWallet<{
|
|
16
|
-
[key: string]: NotWorth;
|
|
17
|
-
}>;
|
|
18
|
-
config: {
|
|
19
|
-
brokerEndpoint: string;
|
|
20
|
-
};
|
|
21
|
-
}) => {
|
|
22
|
-
swap: ({ recipient, ...rest }: SwapParams<"chainflip">) => Promise<string>;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated Use import { ChainflipPlugin } from "@swapkit/chainflip" instead
|
|
28
|
-
*/
|
|
29
|
-
export declare const ChainflipProvider: {
|
|
30
|
-
readonly chainflip: {
|
|
31
|
-
readonly plugin: ({ wallets, config: { brokerEndpoint }, }: {
|
|
32
|
-
wallets: BaseWallet<{
|
|
33
|
-
[key: string]: NotWorth;
|
|
34
|
-
}>;
|
|
35
|
-
config: {
|
|
36
|
-
brokerEndpoint: string;
|
|
37
|
-
};
|
|
38
|
-
}) => {
|
|
39
|
-
swap: ({ recipient, ...rest }: SwapParams<"chainflip">) => Promise<string>;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
};
|
package/lib/plugin.js
DELETED
|
@@ -1,83 +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
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.ChainflipProvider = exports.ChainflipPlugin = exports.confirmSwap = void 0;
|
|
24
|
-
const helpers_1 = require("@swapkit/helpers");
|
|
25
|
-
function confirmSwap({ buyAsset, sellAsset, recipient, brokerEndpoint, }) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
try {
|
|
28
|
-
const response = yield fetch(brokerEndpoint, {
|
|
29
|
-
method: "POST",
|
|
30
|
-
headers: { "Content-Type": "application/json" },
|
|
31
|
-
body: JSON.stringify({
|
|
32
|
-
buyAsset: buyAsset.toString(),
|
|
33
|
-
sellAsset: sellAsset.toString(),
|
|
34
|
-
destinationAddress: recipient,
|
|
35
|
-
}),
|
|
36
|
-
}).then((res) => res.json());
|
|
37
|
-
return response;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
throw new helpers_1.SwapKitError("chainflip_channel_error", error);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
exports.confirmSwap = confirmSwap;
|
|
45
|
-
const plugin = ({ wallets, config: { brokerEndpoint }, }) => {
|
|
46
|
-
function swap(_a) {
|
|
47
|
-
var _b, _c;
|
|
48
|
-
var { recipient } = _a, rest = __rest(_a, ["recipient"]);
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
if (!("route" in rest && ((_b = rest.route) === null || _b === void 0 ? void 0 : _b.buyAsset) && brokerEndpoint)) {
|
|
51
|
-
throw new helpers_1.SwapKitError("core_swap_invalid_params");
|
|
52
|
-
}
|
|
53
|
-
const { buyAsset: buyString, sellAsset: sellString, sellAmount } = rest.route;
|
|
54
|
-
if (!(sellString && buyString)) {
|
|
55
|
-
throw new helpers_1.SwapKitError("core_swap_asset_not_recognized");
|
|
56
|
-
}
|
|
57
|
-
const sellAsset = yield helpers_1.AssetValue.fromString(sellString);
|
|
58
|
-
if (!(wallets === null || wallets === void 0 ? void 0 : wallets[sellAsset.chain])) {
|
|
59
|
-
throw new helpers_1.SwapKitError("core_wallet_connection_not_found");
|
|
60
|
-
}
|
|
61
|
-
const buyAsset = yield helpers_1.AssetValue.fromString(buyString);
|
|
62
|
-
const assetValue = sellAsset.set(sellAmount);
|
|
63
|
-
const { depositAddress } = yield confirmSwap({
|
|
64
|
-
brokerEndpoint,
|
|
65
|
-
buyAsset,
|
|
66
|
-
recipient,
|
|
67
|
-
sellAsset,
|
|
68
|
-
});
|
|
69
|
-
const tx = yield wallets[sellAsset.chain].transfer({
|
|
70
|
-
assetValue,
|
|
71
|
-
from: (_c = wallets[sellAsset.chain]) === null || _c === void 0 ? void 0 : _c.address,
|
|
72
|
-
recipient: depositAddress,
|
|
73
|
-
});
|
|
74
|
-
return tx;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
return { swap };
|
|
78
|
-
};
|
|
79
|
-
exports.ChainflipPlugin = { chainflip: { plugin } };
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated Use import { ChainflipPlugin } from "@swapkit/chainflip" instead
|
|
82
|
-
*/
|
|
83
|
-
exports.ChainflipProvider = exports.ChainflipPlugin;
|
package/lib/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { AssetValue } from "@swapkit/helpers";
|
|
2
|
-
export type WithdrawFeeResponse = {
|
|
3
|
-
egressId: string;
|
|
4
|
-
egressAsset: string;
|
|
5
|
-
egressAmount: string;
|
|
6
|
-
egressFee: string;
|
|
7
|
-
destinationAddress: string;
|
|
8
|
-
};
|
|
9
|
-
export type SwapDepositResponse = {
|
|
10
|
-
depositChannelId: string;
|
|
11
|
-
depositAddress: string;
|
|
12
|
-
srcChainExpiryBlock: number;
|
|
13
|
-
sellAsset: AssetValue;
|
|
14
|
-
buyAsset: AssetValue;
|
|
15
|
-
recipient: string;
|
|
16
|
-
brokerCommissionBPS: number;
|
|
17
|
-
};
|
package/lib/types.js
DELETED