@pioneer-platform/chainflip-client 0.0.2 → 0.0.4
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/index.js +29 -8
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -37,6 +37,26 @@ module.exports = {
|
|
|
37
37
|
getQuote: function (quote) {
|
|
38
38
|
return get_quote(quote);
|
|
39
39
|
},
|
|
40
|
+
lookupTx: function (quoteId) {
|
|
41
|
+
return get_quote_info(quoteId);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const get_quote_info = function (quoteId) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
let tag = TAG + " | get_quote_info | ";
|
|
47
|
+
try {
|
|
48
|
+
let output = {};
|
|
49
|
+
// Make a GET request using Axios
|
|
50
|
+
const response = yield axios.get(`https://chainflip-swap.chainflip.io/swaps/${quoteId}`);
|
|
51
|
+
// Assuming the response data is what you want to use
|
|
52
|
+
output.data = response.data;
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(tag, "e: ", e);
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
40
60
|
};
|
|
41
61
|
const get_quote = function (quote) {
|
|
42
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -60,9 +80,12 @@ const get_quote = function (quote) {
|
|
|
60
80
|
throw new Error("missing recipientAddress");
|
|
61
81
|
if (!quote.slippage)
|
|
62
82
|
throw new Error("missing slippage");
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
83
|
+
if (!networkSupport.includes(caipToNetworkId(quote.buyAsset))) {
|
|
84
|
+
throw new Error("unsupported buyAsset");
|
|
85
|
+
}
|
|
86
|
+
if (!networkSupport.includes(caipToNetworkId(quote.sellAsset))) {
|
|
87
|
+
throw new Error("unsupported sellAsset");
|
|
88
|
+
}
|
|
66
89
|
//https://chainflip-swap.chainflip.io/quote?amount=100000000&srcChain=Bitcoin&srcAsset=BTC&destChain=Ethereum&destAsset=ETH
|
|
67
90
|
//get quote
|
|
68
91
|
const responseQuote = yield axios.get('https://chainflip-swap.chainflip.io/quote', {
|
|
@@ -110,18 +133,16 @@ const get_quote = function (quote) {
|
|
|
110
133
|
// console.log(response.data); // Log the response data
|
|
111
134
|
// console.log(JSON.stringify(response.data)); // Log the response data
|
|
112
135
|
let result = response.data[0].result.data.json;
|
|
113
|
-
log.info(tag,
|
|
136
|
+
// log.info(tag,"result: ",result)
|
|
114
137
|
output.id = result.id;
|
|
115
138
|
output.source = 'chainflip';
|
|
116
139
|
output.estimatedExpiryTime = result.estimatedExpiryTime;
|
|
117
140
|
output.amountOut = responseQuote.data.egressAmount;
|
|
118
|
-
|
|
119
|
-
console.log("caipToNetworkId(quote.sellAsset): ", caipToNetworkId(quote.sellAsset));
|
|
120
|
-
if (caipToNetworkId(quote.sellAsset) == caipToNetworkId(ChainToNetworkId["BTC"])) {
|
|
141
|
+
if (caipToNetworkId(quote.buyAsset) == caipToNetworkId(ChainToNetworkId["BTC"])) {
|
|
121
142
|
// Convert from satoshis to BTC
|
|
122
143
|
output.amountOut /= 1e8;
|
|
123
144
|
}
|
|
124
|
-
else if (caipToNetworkId(quote.
|
|
145
|
+
else if (caipToNetworkId(quote.buyAsset) == caipToNetworkId(ChainToNetworkId["ETH"])) {
|
|
125
146
|
// Convert from wei to ETH
|
|
126
147
|
output.amountOut /= 1e18;
|
|
127
148
|
}
|