@bluefin-exchange/bluefin7k-aggregator-sdk
Version:
31 lines (30 loc) • 1.25 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObricContract = void 0;
const utils_1 = require("@mysten/sui/utils");
const base_1 = require("../base");
class ObricContract extends base_1.BaseContract {
async swap(tx) {
const [coinX, coinY] = this.swapInfo.pool.allTokens;
const xToY = this.swapInfo.swapXtoY;
const { x_price_id, y_price_id } = this.swapInfo.extra || {};
if (!x_price_id || !y_price_id) {
throw new Error("x_price_id and y_price_id are required");
}
const { package: PACKAGE_ID, pythState: PYTH_STATE } = this.config.obric;
const [coinOut] = tx.moveCall({
target: `${PACKAGE_ID}::v2::${xToY ? "swap_x_to_y" : "swap_y_to_x"}`,
typeArguments: [coinX.address, coinY.address],
arguments: [
tx.object(this.swapInfo.poolId),
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
tx.object(PYTH_STATE),
tx.object(x_price_id), // pyth pricefeed for x
tx.object(y_price_id), // pyth pricefeed for y
this.inputCoinObject,
],
});
return coinOut;
}
}
exports.ObricContract = ObricContract;
;