@pioneer-platform/osmosis-client 0.0.8 → 0.0.9
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.d.ts +2 -1
- package/lib/index.js +13 -8
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ declare let networkAtom: any;
|
|
|
6
6
|
declare const uuid: any;
|
|
7
7
|
declare let networkSupport: any[];
|
|
8
8
|
interface QuoteResult {
|
|
9
|
+
amountOutMin: string;
|
|
9
10
|
amountOut: string;
|
|
10
11
|
slippage: string;
|
|
11
12
|
}
|
|
12
|
-
declare function quoteFromPool(amountAtomSwap: string, amountAtomPool: string, amountOsmoPool: string): QuoteResult;
|
|
13
|
+
declare function quoteFromPool(amountAtomSwap: string, amountAtomPool: string, amountOsmoPool: string, maxSlippage: number): QuoteResult;
|
|
13
14
|
declare const get_quote: (quote: any) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -61,7 +61,7 @@ module.exports = {
|
|
|
61
61
|
return get_quote(quote);
|
|
62
62
|
},
|
|
63
63
|
};
|
|
64
|
-
function quoteFromPool(amountAtomSwap, amountAtomPool, amountOsmoPool) {
|
|
64
|
+
function quoteFromPool(amountAtomSwap, amountAtomPool, amountOsmoPool, maxSlippage) {
|
|
65
65
|
// Convert string inputs to numbers and scale the swap amount
|
|
66
66
|
var swapAmount = parseFloat(amountAtomSwap) * 1e6;
|
|
67
67
|
var atomPoolAmount = parseFloat(amountAtomPool);
|
|
@@ -81,7 +81,10 @@ function quoteFromPool(amountAtomSwap, amountAtomPool, amountOsmoPool) {
|
|
|
81
81
|
var idealRate = osmoPoolAmount / atomPoolAmount;
|
|
82
82
|
// Calculate the slippage
|
|
83
83
|
var slippage = ((idealRate - actualRate) / idealRate) * 100;
|
|
84
|
+
// Calculate amountOutMin considering the maximum slippage
|
|
85
|
+
var amountOutMin = scaledOsmoReceived * (1 - maxSlippage / 100);
|
|
84
86
|
return {
|
|
87
|
+
amountOutMin: amountOutMin.toFixed(6).toString(),
|
|
85
88
|
amountOut: scaledOsmoReceived.toFixed(6),
|
|
86
89
|
slippage: Math.max(slippage, 0).toFixed(6)
|
|
87
90
|
};
|
|
@@ -107,6 +110,8 @@ var get_quote = function (quote) {
|
|
|
107
110
|
throw new Error("missing senderAddress");
|
|
108
111
|
if (!quote.recipientAddress)
|
|
109
112
|
throw new Error("missing recipientAddress");
|
|
113
|
+
if (!quote.slippage)
|
|
114
|
+
throw new Error("missing slippage");
|
|
110
115
|
return [4 /*yield*/, networkOsmo.getPools()];
|
|
111
116
|
case 2:
|
|
112
117
|
pools = _a.sent();
|
|
@@ -129,17 +134,17 @@ var get_quote = function (quote) {
|
|
|
129
134
|
output.complete = true;
|
|
130
135
|
result = void 0;
|
|
131
136
|
if (quote.sellAsset === shortListSymbolToCaip["OSMO"]) {
|
|
132
|
-
result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo);
|
|
137
|
+
result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo, quote.slippage);
|
|
133
138
|
output.result = result;
|
|
134
139
|
tx1 = {
|
|
135
140
|
type: "sendSwapTx",
|
|
136
141
|
chain: caipToNetworkId(shortListSymbolToCaip["OSMO"]),
|
|
137
142
|
txParams: {
|
|
138
143
|
senderAddress: quote.senderAddress,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
tokenIn: 'uosmo',
|
|
145
|
+
tokenOut: 'ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2',
|
|
146
|
+
amountIn: quote.sellAmount,
|
|
147
|
+
amountOutMin: result.amountOutMin,
|
|
143
148
|
}
|
|
144
149
|
};
|
|
145
150
|
log.info(tag, "tx1: ", tx1);
|
|
@@ -150,14 +155,14 @@ var get_quote = function (quote) {
|
|
|
150
155
|
senderAddress: quote.senderAddress, // Address initiating the IBC withdrawal
|
|
151
156
|
recipientAddress: quote.recipientAddress, // Destination address for the ATOM tokens
|
|
152
157
|
amount: result.amountOut, // Amount of ATOM tokens to withdraw
|
|
153
|
-
// Other parameters required for the IBC withdrawal can be added here
|
|
158
|
+
token: 'uatom' // Other parameters required for the IBC withdrawal can be added here
|
|
154
159
|
}
|
|
155
160
|
};
|
|
156
161
|
log.info(tag, "tx2: ", tx2);
|
|
157
162
|
output.txs = [tx1, tx2];
|
|
158
163
|
}
|
|
159
164
|
else if (quote.sellAsset === shortListSymbolToCaip["ATOM"]) {
|
|
160
|
-
result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo);
|
|
165
|
+
result = quoteFromPool(quote.sellAmount, amountAtom, amountOsmo, quote.slippage);
|
|
161
166
|
output.result = result;
|
|
162
167
|
tx1 = {
|
|
163
168
|
type: "ibcTransfer",
|