UNPKG

minter-js-sdk

Version:
83 lines (76 loc) 2.53 kB
'use strict'; var minterjsTx = require('minterjs-tx'); var minterjsUtil = require('minterjs-util'); var utils = require('../utils.js'); /** * @param {object} txData * @param {number|string} txData.coin0 - coin id * @param {number|string} txData.coin1 - coin id * @param {number|string} txData.volume0 * @param {number|string} txData.volume1 * @param {TxOptions} [options] * @constructor */ function CreatePoolTxData(_ref) { var coin0 = _ref.coin0, coin1 = _ref.coin1, volume0 = _ref.volume0, volume1 = _ref.volume1; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (!options.disableValidation) { utils.validateUint(coin0, 'coin0'); utils.validateUint(coin1, 'coin1'); utils.validateAmount(volume0, 'volume0'); utils.validateAmount(volume1, 'volume1'); } // swap values to sort by id ascending (make tx hash independent of coin order) if (Number(coin0) > Number(coin1)) { var _ref2 = [coin1, coin0]; coin0 = _ref2[0]; coin1 = _ref2[1]; var _ref3 = [volume1, volume0]; volume0 = _ref3[0]; volume1 = _ref3[1]; } this.coin0 = coin0; this.coin1 = coin1; this.volume0 = volume0; this.volume1 = volume1; this.txData = new minterjsTx.TxDataCreateSwapPool({ coin0: utils.integerToHexString(coin0), coin1: utils.integerToHexString(coin1), volume0: "0x".concat(minterjsUtil.convertToPip(volume0, 'hex')), volume1: "0x".concat(minterjsUtil.convertToPip(volume1, 'hex')) }); utils.proxyNestedTxData(this); } /** * @param {object} txData * @param {Buffer|string} txData.coin0 * @param {Buffer|string} txData.volume0 * @param {Buffer|string} txData.coin1 * @param {Buffer|string} txData.volume1 * @param {TxOptions} [options] * @return {CreatePoolTxData} */ CreatePoolTxData.fromBufferFields = function fromBufferFields(_ref4) { var coin0 = _ref4.coin0, volume0 = _ref4.volume0, coin1 = _ref4.coin1, volume1 = _ref4.volume1; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return new CreatePoolTxData({ coin0: utils.dataToInteger(coin0), coin1: utils.dataToInteger(coin1), volume0: utils.dataPipToAmount(volume0), volume1: utils.dataPipToAmount(volume1) }, options); }; /** * @param {Buffer|string} data * @return {CreatePoolTxData} */ CreatePoolTxData.fromRlp = function fromRlp(data) { return CreatePoolTxData.fromBufferFields(new minterjsTx.TxDataCreateSwapPool(data)); }; module.exports = CreatePoolTxData;