@clonegod/ttd-sui-common 1.0.54 → 1.0.55
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.
|
@@ -29,7 +29,7 @@ export declare abstract class AbstractSuiDexTradePlus extends AbastrcatTrade {
|
|
|
29
29
|
inputToken: any;
|
|
30
30
|
outputToken: any;
|
|
31
31
|
};
|
|
32
|
-
local_calculate_output_amt(context: TradeContext):
|
|
32
|
+
local_calculate_output_amt(context: TradeContext): QuoteResultType;
|
|
33
33
|
protected getWalletAssetsFromRedis(walletAddress: string): Promise<any>;
|
|
34
34
|
protected getObjectInfo(objectId: string): Promise<PoolObjectInfo | null>;
|
|
35
35
|
protected compareBigIntBalance(a: any, b: any): number;
|
|
@@ -214,38 +214,36 @@ class AbstractSuiDexTradePlus extends dist_1.AbastrcatTrade {
|
|
|
214
214
|
return { inputToken, outputToken };
|
|
215
215
|
}
|
|
216
216
|
local_calculate_output_amt(context) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return quote_result;
|
|
248
|
-
});
|
|
217
|
+
const { price_msg, order_msg, pool_info, trade_runtime, slippage_bps } = context;
|
|
218
|
+
let { ask, bid } = price_msg;
|
|
219
|
+
const { aToB, amount: uiAmount, price: cex_order_price } = order_msg;
|
|
220
|
+
let { inputToken, outputToken } = (0, dist_1.get_input_out_token)(pool_info, aToB);
|
|
221
|
+
let amountIn = new decimal_js_1.default(uiAmount).mul(Math.pow(10, inputToken.decimals));
|
|
222
|
+
let slippage = slippage_bps / 10000;
|
|
223
|
+
let price;
|
|
224
|
+
let amountOut;
|
|
225
|
+
let amountOutMin;
|
|
226
|
+
if (aToB) {
|
|
227
|
+
price = cex_order_price !== null && cex_order_price !== void 0 ? cex_order_price : bid.price;
|
|
228
|
+
amountOut = new decimal_js_1.default(uiAmount).mul(price).mul(Math.pow(10, outputToken.decimals));
|
|
229
|
+
amountOutMin = amountOut.mul(1 - slippage);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
price = cex_order_price !== null && cex_order_price !== void 0 ? cex_order_price : ask.price;
|
|
233
|
+
amountOut = new decimal_js_1.default(uiAmount).div(price).mul(Math.pow(10, outputToken.decimals));
|
|
234
|
+
amountOutMin = amountOut.mul(1 - slippage);
|
|
235
|
+
}
|
|
236
|
+
let quote_result = {
|
|
237
|
+
inputToken,
|
|
238
|
+
outputToken,
|
|
239
|
+
amountIn: Number(amountIn.toFixed(0)),
|
|
240
|
+
amountOut: Number(amountOut.toFixed(0)),
|
|
241
|
+
amountOutMin: Number(amountOutMin.toFixed(0)),
|
|
242
|
+
slippageBps: slippage_bps,
|
|
243
|
+
priceImpact: 0,
|
|
244
|
+
price: price.toString()
|
|
245
|
+
};
|
|
246
|
+
return quote_result;
|
|
249
247
|
}
|
|
250
248
|
getWalletAssetsFromRedis(walletAddress) {
|
|
251
249
|
return __awaiter(this, void 0, void 0, function* () {
|