@swaptoshi/dex-module
Version:
Klayr decentralized exchange (dex) on-chain module
50 lines • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DexGovernableConfig = void 0;
const klayr_framework_1 = require("klayr-framework");
const governance_module_1 = require("@swaptoshi/governance-module");
const constants_1 = require("./constants");
const schema_1 = require("./schema");
const utils_1 = require("./utils");
const fc_method_1 = require("./fc_method");
class DexGovernableConfig extends governance_module_1.BaseGovernableConfig {
constructor() {
super(...arguments);
this.schema = schema_1.configSchema;
this.default = constants_1.defaultConfig;
this.stores = new klayr_framework_1.Modules.NamedRegistry();
}
addDependencies(stores, feeConversionMethod) {
this.stores = stores;
this._feeConversionMethod = feeConversionMethod;
}
async afterSetConfig(_context) {
if (this._feeConversionMethod) {
if (_context.newConfig.feeConversionEnabled) {
this._feeConversionMethod.register('token', ['transfer'], new fc_method_1.DexTransferFeeConversionMethod(this.stores, this.governanceEvent));
this._feeConversionMethod.register(this.name, ['exactInput', 'exactInputSingle', 'exactOutput', 'exactOutputSingle'], new fc_method_1.DexSwapFeeConversionMethod(this.stores, this.governanceEvent));
}
else {
this._feeConversionMethod.unregister('token', ['transfer'], new fc_method_1.DexTransferFeeConversionMethod(this.stores, this.governanceEvent));
this._feeConversionMethod.unregister(this.name, ['exactInput', 'exactInputSingle', 'exactOutput', 'exactOutputSingle'], new fc_method_1.DexSwapFeeConversionMethod(this.stores, this.governanceEvent));
}
}
}
async verify(_context) {
try {
await (0, utils_1.verifyModuleConfig)(_context.config);
if (_context.config.feeConversionEnabled && !this._feeConversionMethod) {
throw new Error('feeConversionMethod dependencies is not configured, make sure to add FeeConversionModule.method to DexModule.addDependencies()');
}
}
catch (error) {
return {
status: klayr_framework_1.StateMachine.VerifyStatus.FAIL,
error: new Error(error.message),
};
}
return { status: klayr_framework_1.StateMachine.VerifyStatus.OK };
}
}
exports.DexGovernableConfig = DexGovernableConfig;
//# sourceMappingURL=config.js.map