UNPKG

@swaptoshi/dex-module

Version:

Klayr decentralized exchange (dex) on-chain module

48 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DexMethod = void 0; const klayr_framework_1 = require("klayr-framework"); const pool_1 = require("./stores/pool"); const context_1 = require("./stores/context"); const position_manager_1 = require("./stores/position_manager"); const lens_1 = require("./stores/library/lens"); const periphery_1 = require("./stores/library/periphery"); const config_1 = require("./config"); class DexMethod extends klayr_framework_1.Modules.BaseMethod { async getConfig(context) { const configStore = this.stores.get(config_1.DexGovernableConfig); const config = await configStore.getConfig(context); return config; } async createPool(context, senderAddress, timestamp, tokenA, tokenASymbol, tokenADecimal, tokenB, tokenBSymbol, tokenBDecimal, fee) { const poolStore = this.stores.get(pool_1.PoolStore); const _context = (0, context_1.methodSwapContext)(context, senderAddress, timestamp); return poolStore.createPool(_context, tokenA, tokenASymbol, tokenADecimal, tokenB, tokenBSymbol, tokenBDecimal, fee); } async getPoolInstance(context, senderAddress, timestamp, tokenA, tokenB, fee) { const poolStore = this.stores.get(pool_1.PoolStore); const _context = (0, context_1.methodSwapContext)(context, senderAddress, timestamp); return poolStore.getMutablePool(_context, tokenA, tokenB, fee); } async poolExists(context, tokenA, tokenB, fee) { const poolStore = this.stores.get(pool_1.PoolStore); const poolAddress = periphery_1.PoolAddress.computeAddress(periphery_1.PoolAddress.getPoolKey(tokenA, tokenB, fee)); return poolStore.has(context, poolAddress); } async getPositionManagerInstance(context, senderAddress, timestamp, poolAddress) { const positionManagerStore = this.stores.get(position_manager_1.PositionManagerStore); const _context = (0, context_1.methodSwapContext)(context, senderAddress, timestamp); return positionManagerStore.getMutablePositionManager(_context, poolAddress); } async getRouterInstance(context, senderAddress, timestamp) { const poolStore = this.stores.get(pool_1.PoolStore); const _context = (0, context_1.methodSwapContext)(context, senderAddress, timestamp); return poolStore.getMutableRouter(_context); } async getQuoterInstance(context, senderAddress, timestamp) { const _context = (0, context_1.immutableMethodSwapContext)(context, senderAddress, timestamp); return new lens_1.Quoter(_context, this.stores); } } exports.DexMethod = DexMethod; //# sourceMappingURL=method.js.map