@swaptoshi/dex-module
Version:
Klayr decentralized exchange (dex) on-chain module
49 lines • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollectTreasuryCommand = void 0;
const klayr_framework_1 = require("klayr-framework");
const cryptography = require("@klayr/cryptography");
const schema_1 = require("../schema");
const utils_1 = require("../utils");
const context_1 = require("../stores/context");
const position_manager_1 = require("../stores/position_manager");
const config_1 = require("../config");
const int_1 = require("../stores/library/int");
class CollectTreasuryCommand extends klayr_framework_1.Modules.BaseCommand {
constructor() {
super(...arguments);
this.schema = schema_1.collectTreasuryCommandSchema;
}
async verify(_context) {
try {
(0, utils_1.verifyCollectTreasuryParam)(_context.params);
}
catch (error) {
return {
status: klayr_framework_1.StateMachine.VerifyStatus.FAIL,
error: new Error(error.message),
};
}
return { status: klayr_framework_1.StateMachine.VerifyStatus.OK };
}
async execute(_context) {
const positionManagerStore = this.stores.get(position_manager_1.PositionManagerStore);
const configStore = this.stores.get(config_1.DexGovernableConfig);
const config = await configStore.getConfig(_context);
if (config.feeProtocolPool) {
const treasuryAddress = cryptography.address.getAddressFromKlayr32Address(config.feeProtocolPool);
const params = {
..._context.params,
recipient: treasuryAddress,
amount1Max: int_1.Uint128.MAX,
amount0Max: int_1.Uint128.MAX,
};
const context = (0, context_1.commandSwapContext)(_context);
context.senderAddress = treasuryAddress;
const positionManager = await positionManagerStore.getMutablePositionManager(context, _context.params.poolAddress);
await positionManager.collect(params);
}
}
}
exports.CollectTreasuryCommand = CollectTreasuryCommand;
//# sourceMappingURL=collect_treasury_command.js.map