@swaptoshi/dex-module
Version:
Klayr decentralized exchange (dex) on-chain module
26 lines • 923 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.compute = compute;
exports.getNFTId = getNFTId;
exports.decodeNFTId = decodeNFTId;
const Position = require("../core/position");
function compute(owner, tickLower, tickUpper) {
return Position.positionKey(owner, tickLower, tickUpper);
}
function getNFTId(chainId, collectionId, tokenId) {
if (chainId.length !== 4)
throw new Error('invalid chainId');
if (collectionId.length !== 4)
throw new Error('invalid collectionId');
const tokenIdBuf = Buffer.allocUnsafe(8);
tokenIdBuf.writeBigInt64BE(BigInt(tokenId));
return Buffer.concat([chainId, collectionId, tokenIdBuf]);
}
function decodeNFTId(nftId) {
return {
chainId: nftId.subarray(0, 4),
collectionId: nftId.subarray(4, 8),
index: nftId.subarray(8).readBigUInt64BE(),
};
}
//# sourceMappingURL=position_key.js.map