@pioneer-platform/mayachain-client 0.0.34 → 0.0.36
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 +14 -33
- package/package.json +1 -1
package/lib/index.js
CHANGED
@@ -57,6 +57,15 @@ var networkSupport = [
|
|
57
57
|
ChainToNetworkId["ETH"],
|
58
58
|
ChainToNetworkId["THOR"],
|
59
59
|
ChainToNetworkId["DASH"],
|
60
|
+
ChainToNetworkId["ARB"],
|
61
|
+
];
|
62
|
+
var assetSupport = [
|
63
|
+
shortListSymbolToCaip["BTC"],
|
64
|
+
shortListSymbolToCaip["ETH"],
|
65
|
+
shortListSymbolToCaip["MAYA"],
|
66
|
+
shortListSymbolToCaip["THOR"],
|
67
|
+
shortListSymbolToCaip["DASH"],
|
68
|
+
shortListSymbolToCaip["ARB"],
|
60
69
|
];
|
61
70
|
// Function to make a request to the node
|
62
71
|
function nodeRequest(path) {
|
@@ -89,41 +98,16 @@ module.exports = {
|
|
89
98
|
networkSupport: function () {
|
90
99
|
return networkSupport;
|
91
100
|
},
|
101
|
+
assetSupport: function () {
|
102
|
+
return assetSupport;
|
103
|
+
},
|
92
104
|
getQuote: function (quote) {
|
93
105
|
return get_quote(quote);
|
94
106
|
},
|
95
107
|
};
|
96
|
-
function quoteFromPool(sellAmount, assetPoolAmount, runePoolAmount, maxSlippage) {
|
97
|
-
// Convert string inputs to numbers and scale the sell amount
|
98
|
-
var swapAmount = parseFloat(sellAmount) * 1e8; // Assuming 1e6 is the scaling factor for Maya
|
99
|
-
var assetDepth = parseFloat(assetPoolAmount);
|
100
|
-
var runeDepth = parseFloat(runePoolAmount);
|
101
|
-
// Calculate the constant product
|
102
|
-
var k = assetDepth * runeDepth;
|
103
|
-
// New amount of the asset in the pool after the swap
|
104
|
-
var newAssetDepth = assetDepth + swapAmount;
|
105
|
-
// Calculate the amount of Rune received (or the other asset in the pool)
|
106
|
-
var newRuneDepth = k / newAssetDepth;
|
107
|
-
var runeReceived = runeDepth - newRuneDepth;
|
108
|
-
// Scale back down the amount of Rune received
|
109
|
-
var scaledRuneReceived = runeReceived / 1e6; // Adjust as per Rune's scaling factor
|
110
|
-
// Calculate the actual rate of the swap
|
111
|
-
var actualRate = scaledRuneReceived / (swapAmount / 1e6);
|
112
|
-
// Calculate the ideal rate
|
113
|
-
var idealRate = runeDepth / assetDepth;
|
114
|
-
// Calculate the slippage
|
115
|
-
var slippage = ((idealRate - actualRate) / idealRate) * 100;
|
116
|
-
// Calculate amountOutMin considering the maximum slippage
|
117
|
-
var amountOutMin = scaledRuneReceived * (1 - maxSlippage / 100);
|
118
|
-
return {
|
119
|
-
amountOutMin: amountOutMin.toFixed(6).toString(),
|
120
|
-
amountOut: scaledRuneReceived.toFixed(6),
|
121
|
-
slippage: Math.max(slippage, 0).toFixed(6)
|
122
|
-
};
|
123
|
-
}
|
124
108
|
var get_quote = function (quote) {
|
125
109
|
return __awaiter(this, void 0, void 0, function () {
|
126
|
-
var tag, output, pools,
|
110
|
+
var tag, output, pools, BaseDecimal_1, asset, DECIMALS, BASE_UNIT, sellAmountInBaseUnits, quoteFromNode, URL_1, amountOutEstimated, memoInput, memo, type, chain, tx, inbounds, inbound, tokenAddress, depositAbi, routerContract, quoteSellAmountInEther, numberBN, numberHex, data, gasLimit, block, baseFeePerGas, gasPrice, maxPriorityFeePerGas, maxFeePerGas, feeData, e_1;
|
127
111
|
return __generator(this, function (_a) {
|
128
112
|
switch (_a.label) {
|
129
113
|
case 0:
|
@@ -149,8 +133,7 @@ var get_quote = function (quote) {
|
|
149
133
|
pools = _a.sent();
|
150
134
|
if (!pools)
|
151
135
|
throw Error("Unable to get pools from network!");
|
152
|
-
|
153
|
-
poolOut = pools.find(function (p) { return p.asset == quote.buyAsset; });
|
136
|
+
// log.info(tag, "pools: ", pools)
|
154
137
|
output.meta = {
|
155
138
|
quoteMode: "MAYA_SUPPORTED_TO_MAYA_SUPPORTED"
|
156
139
|
};
|
@@ -198,8 +181,6 @@ var get_quote = function (quote) {
|
|
198
181
|
log.info("quoteFromNode: ", quoteFromNode);
|
199
182
|
if (quoteFromNode.error)
|
200
183
|
throw Error(quoteFromNode.error);
|
201
|
-
amountOutMin = quoteFromNode.amount_out_min;
|
202
|
-
inboundAddress = quoteFromNode.inbound_address;
|
203
184
|
amountOutEstimated = (parseInt(quoteFromNode.expected_amount_out) / BASE_UNIT).toFixed(DECIMALS);
|
204
185
|
output.amountOut = amountOutEstimated;
|
205
186
|
memoInput = {
|