@swaptoshi/dex-module
Version:
Klayr decentralized exchange (dex) on-chain module
29 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyValidTransfer = verifyValidTransfer;
const klayr_framework_1 = require("klayr-framework");
const codec_1 = require("@klayr/codec");
const constants_1 = require("../../constants");
const pool_1 = require("../../stores/pool");
const schema_1 = require("../../schema");
const INVALID_TRANSFER_RECIPIENTS = [constants_1.POSITION_MANAGER_ADDRESS, constants_1.ROUTER_ADDRESS];
async function verifyValidTransfer(context) {
if (context.transaction.module === 'token' && context.transaction.command === 'transfer') {
const { schema } = new klayr_framework_1.Modules.Token.TransferCommand(this.stores, this.events);
const params = codec_1.codec.decode(schema, context.transaction.params);
if (INVALID_TRANSFER_RECIPIENTS.findIndex(t => t.equals(params.recipientAddress)) >= 0) {
throw new Error(`Invalid token transfer recipient. Address already reserved by dex module`);
}
}
if (context.transaction.module === 'nft' && context.transaction.command === 'transfer') {
const params = codec_1.codec.decode(schema_1.nftTransferParamsSchema, context.transaction.params);
if (INVALID_TRANSFER_RECIPIENTS.findIndex(t => t.equals(params.recipientAddress)) >= 0) {
throw new Error(`Invalid nft transfer recipient. Address already reserved by dex module`);
}
const poolStore = this.stores.get(pool_1.PoolStore);
if (await poolStore.has(context, params.recipientAddress)) {
throw new Error(`Invalid nft transfer recipient. A dex pool can't receive any nft`);
}
}
}
//# sourceMappingURL=verifyValidTransfer.js.map