Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pay gasFee on refundPegout #256

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/LiquidityBridgeContractV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions test/basic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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 });
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Loading