From ae40798c97cd51d8fd2286ee0889d8dbe88c6817 Mon Sep 17 00:00:00 2001 From: Luisfc68 Date: Mon, 7 Oct 2024 19:44:12 +0200 Subject: [PATCH] fix: pay gasFee on refundPegout --- contracts/LiquidityBridgeContractV2.sol | 2 +- package-lock.json | 2 -- test/basic.tests.js | 20 ++++++++++---------- test/utils/index.js | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/contracts/LiquidityBridgeContractV2.sol b/contracts/LiquidityBridgeContractV2.sol index c5d61a4..8f9b15b 100644 --- a/contracts/LiquidityBridgeContractV2.sol +++ b/contracts/LiquidityBridgeContractV2.sol @@ -730,7 +730,7 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra } (bool sent,) = quote.lpRskAddress.call{ - value: quote.value + quote.callFee + value: quote.value + quote.callFee + quote.gasFee }(""); require(sent, "LBC050"); diff --git a/package-lock.json b/package-lock.json index eba9ae0..4944847 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8847,7 +8847,6 @@ "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.5.tgz", "integrity": "sha512-HTm14iMQKK2FjFLRTM5lAVcyaUzOnqbPtesFIvREgXpJHdQm8bWS+GkQgIkfaBYRHuCnea7w8UVNfwiAQhlr9A==", "dev": true, - "hasInstallScript": true, "optional": true, "peer": true, "dependencies": { @@ -9233,7 +9232,6 @@ "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.7.tgz", "integrity": "sha512-vLt1O5Pp+flcArHGIyKEQq883nBt8nN8tVBcoL0qUXj2XT1n7p70yGIq2VK98I5FdZ1YHc0wk/koOnHjnXWk1Q==", "dev": true, - "hasInstallScript": true, "optional": true, "peer": true, "dependencies": { diff --git a/test/basic.tests.js b/test/basic.tests.js index f69df6c..4cdb8d4 100644 --- a/test/basic.tests.js +++ b/test/basic.tests.js @@ -890,7 +890,7 @@ contract("LiquidityBridgeContractV2.sol", async (accounts) => { web3.eth.getBalance(instance.address), ]); - const [userPegInBalanceBefore, contractBalanceBefore] = await getBalances(); + const [lpBalanceBeforeDeposit, contractBalanceBefore] = await getBalances(); let quote = utils.getTestPegOutQuote( instance.address, //lbc address @@ -920,14 +920,14 @@ contract("LiquidityBridgeContractV2.sol", async (accounts) => { await truffleAssertions.eventEmitted(pegOut, "PegOutDeposit"); const btcTx = await utils.generateRawTx(instance, quote, scriptType); - const [userPegInBalanceAfter, contractBalanceAfter] = await getBalances(); + const [lpBalanceAfterDeposit, contractBalanceAfter] = await getBalances(); - expect(userPegInBalanceBefore.toString()).to.be.eq( - userPegInBalanceAfter.toString() + expect(lpBalanceBeforeDeposit.toString()).to.be.eq( + lpBalanceAfterDeposit.toString() ); expect(+contractBalanceAfter).to.be.eq(+contractBalanceBefore + msgValue.toNumber()); - const lpBalanceBefore = await web3.eth.getBalance( + const lpBalanceBeforeRefund = await web3.eth.getBalance( liquidityProviderRskAddress ); const refund = await instance.refundPegOut( @@ -937,19 +937,19 @@ contract("LiquidityBridgeContractV2.sol", async (accounts) => { partialMerkleTree, merkleBranchHashes ); - const lpBalanceAfter = await web3.eth.getBalance( + const lpBalanceAfterRefund = await web3.eth.getBalance( liquidityProviderRskAddress ); const usedInGas = refund.receipt.gasUsed * refund.receipt.effectiveGasPrice; - const refundedAmount = quote.value.add(quote.callFee); + const refundedAmount = quote.value.add(quote.callFee).add(quote.gasFee); truffleAssertions.eventEmitted(refund, "DaoFeeSent", { quoteHash: quoteHash, amount: quote.productFeeAmount }); - expect(lpBalanceAfter).to.be.a.bignumber.eq( - web3.utils.toBN(lpBalanceBefore).add(refundedAmount).sub(web3.utils.toBN(usedInGas)) + expect(lpBalanceAfterRefund).to.be.a.bignumber.eq( + web3.utils.toBN(lpBalanceBeforeRefund).add(refundedAmount).sub(web3.utils.toBN(usedInGas)) ); - truffleAssertions.eventEmitted(refund, "PegOutRefunded"); + truffleAssertions.eventEmitted(refund, "PegOutRefunded", { quoteHash }); }); }); diff --git a/test/utils/index.js b/test/utils/index.js index 21024cb..df1ee4d 100644 --- a/test/utils/index.js +++ b/test/utils/index.js @@ -75,7 +75,7 @@ function getTestPegOutQuote(lbcAddress, lpRskAddress, rskRefundAddress, value, b } let valueToTransfer = value || web3.utils.toBN(0); - let callFee = web3.utils.toBN(1); + const callFee = web3.utils.toBN(2); let nonce = 0; let agreementTimestamp = 1661788988; let expireDate = Math.round(new Date().getTime() / 1000) + 3600; @@ -86,7 +86,7 @@ function getTestPegOutQuote(lbcAddress, lpRskAddress, rskRefundAddress, value, b let transferConfirmations = 10; let penaltyFee = web3.utils.toBN(0); let productFeeAmount = web3.utils.toBN(1); - const gasFee = web3.utils.toBN(1); + const gasFee = web3.utils.toBN(42); let quote = { lbcAddress,