diff --git a/package.json b/package.json index 16480f9..eab21f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lumerin/wallet-core", - "version": "1.0.64", + "version": "1.0.65", "author": { "name": "Lumerin", "email": "developer@lumerin.io", diff --git a/src/plugins/contracts/api.js b/src/plugins/contracts/api.js index 8037bd2..f234fd6 100644 --- a/src/plugins/contracts/api.js +++ b/src/plugins/contracts/api.js @@ -155,11 +155,18 @@ async function getContract( return contractInfo.data } +/** + * @param {import('contracts-js').CloneFactoryContext} cloneFactory + */ +const getMarketplaceFee = (cloneFactory) => async () => { + return await cloneFactory.methods.marketplaceFee().call(); +} + /** * @param {import('web3').default} web3 * @param {import('contracts-js').CloneFactoryContext} cloneFactory */ -function createContract(web3, cloneFactory, plugins) { +function createContract(web3, cloneFactory) { if (!web3) { logger.error('Not a valid Web3 instance') return @@ -205,6 +212,8 @@ function createContract(web3, cloneFactory, plugins) { from: sellerAddress, }) + const marketplaceFee = await cloneFactory.methods.marketplaceFee().call(); + return cloneFactory.methods .setCreateNewRentalContract( price, @@ -214,14 +223,14 @@ function createContract(web3, cloneFactory, plugins) { validatorAddress, pubKey.toString('hex') ) - .send({ from: sellerAddress, gas }) + .send({ from: sellerAddress, gas, value: marketplaceFee }) } } /** * @param {import('web3').default} web3 */ -function cancelContract(web3) { +function cancelContract(web3, cloneFactory) { if (!web3) { logger.error('Not a valid Web3 instance') return @@ -245,11 +254,14 @@ function cancelContract(web3) { from: walletAddress, }) + const marketplaceFee = await cloneFactory.methods.marketplaceFee().call(); + return await Implementation(web3, contractId) .methods.setContractCloseOut(closeOutType) .send({ from: walletAddress, gas, + value: marketplaceFee }) } } @@ -335,10 +347,8 @@ function purchaseContract(web3, cloneFactory, lumerin) { throw new Error('Contract is deleted already') } - const totalPrice = (+price + price * 0.01).toString() - await lumerin.methods - .increaseAllowance(cloneFactory.options.address, totalPrice) + .increaseAllowance(cloneFactory.options.address, price) .send(sendOptions) const purchaseGas = await cloneFactory.methods @@ -346,12 +356,14 @@ function purchaseContract(web3, cloneFactory, lumerin) { .estimateGas({ from: sendOptions.from, }) + const marketplaceFee = await cloneFactory.methods.marketplaceFee().call(); const purchaseResult = await cloneFactory.methods .setPurchaseRentalContract(contractId, ciphertext.toString('hex')) .send({ ...sendOptions, gas: purchaseGas, + value: marketplaceFee }) logger.debug('Finished puchase transaction', purchaseResult) @@ -406,4 +418,5 @@ module.exports = { purchaseContract, setContractDeleteStatus, editContract, + getMarketplaceFee } diff --git a/src/plugins/contracts/index.js b/src/plugins/contracts/index.js index 9d0ae9a..f58222d 100644 --- a/src/plugins/contracts/index.js +++ b/src/plugins/contracts/index.js @@ -18,6 +18,7 @@ const { purchaseContract, setContractDeleteStatus, editContract, + getMarketplaceFee } = require('./api') const { ContractEventsListener } = require('./events-listener') @@ -91,10 +92,11 @@ function createPlugin() { return { api: { refreshContracts: refreshContracts(web3, lumerin, cloneFactory), - createContract: createContract(web3, cloneFactory, plugins), - cancelContract: cancelContract(web3), + createContract: createContract(web3, cloneFactory), + cancelContract: cancelContract(web3, cloneFactory), purchaseContract: purchaseContract(web3, cloneFactory, lumerin), editContract: editContract(web3, cloneFactory, lumerin), + getMarketplaceFee: getMarketplaceFee(cloneFactory), setContractDeleteStatus: setContractDeleteStatus( web3, cloneFactory,