diff --git a/contracts/LiquidityBridgeContract.sol b/contracts/LiquidityBridgeContract.sol index b848e06..93ed1de 100644 --- a/contracts/LiquidityBridgeContract.sol +++ b/contracts/LiquidityBridgeContract.sol @@ -153,11 +153,11 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable { uint256 private minCollateral; uint256 private minPegIn; - uint256 public maxQuoteValue; uint32 private rewardP; uint32 private resignDelayInBlocks; uint private dust; + uint256 private maxQuoteValue; uint providerId; bool private locked; @@ -237,6 +237,10 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable { require(msg.sender == address(bridge), "Not allowed"); } + function getMaxQuoteValue() external view returns (uint256) { + return maxQuoteValue; + } + function getProviderIds() external view returns (uint) { return providerId; } @@ -385,8 +389,6 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable { "Max transaction value must be greater than min transaction value" ); require(_maxTransactionValue <= maxQuoteValue, "Max transaction value can't be higher than maximum quote value"); - uint256 bridgeMinimun = uint256(bridge.getMinimumLockTxValue()); - require(_minTransactionValue >= bridgeMinimun, "Min transaction value can't be lower than bridge minimum lock tx value"); require( bytes(_apiBaseUrl).length > 0, "API base URL must not be empty" @@ -763,12 +765,15 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable { } function depositPegout( - bytes32 quoteHash, - address lpAddress + PegOutQuote calldata quote ) external payable { - require(isRegisteredForPegout(lpAddress), "Provider not registered"); + require(isRegisteredForPegout(quote.lpRskAddress), "Provider not registered"); + bytes32 quoteHash = hashPegoutQuote(quote); PegOutQuoteState storage state = pegOutQuotesStates[quoteHash]; require(!state.refunded, "LBC: Quote already refunded"); + if(state.receivedAmount == 0) { + registeredPegoutQuotes[quoteHash] = quote; + } state.receivedAmount += msg.value; emit PegOutDeposit(quoteHash, state.receivedAmount, block.timestamp); } @@ -793,7 +798,6 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable { ); pegOutQuotesStates[quoteHash].statusCode = PROCESSED_QUOTE_CODE; - registeredPegoutQuotes[quoteHash] = quote; emit PegOut( msg.sender, diff --git a/test/basic.tests.js b/test/basic.tests.js index eb93a58..43b0a65 100644 --- a/test/basic.tests.js +++ b/test/basic.tests.js @@ -119,22 +119,6 @@ contract("LiquidityBridgeContract", async (accounts) => { it("should validate provider limits on register", async () => { const minCollateral = await instance.getMinCollateral(); - await truffleAssertions.reverts( - instance.register( - "First contract", - 10, - 7200, - 3600, - 1, - 100, - "http://localhost/api", - true, - "both", - { from: accounts[1], value: minCollateral } - ), - "Min transaction value can't be lower than bridge minimum lock tx value" - ); - await truffleAssertions.reverts( instance.register( "First contract", @@ -800,9 +784,6 @@ contract("LiquidityBridgeContract", async (accounts) => { userPegInBalanceAfter.toString() ); expect(+contractBalanceAfter).to.be.eq(+contractBalanceBefore - +msgValue); - // check that stores quote - const storedQuote = await instance.getRegisteredPegOutQuote(quoteHash) - expect(storedQuote.lbcAddress).to.not.be.eq('0x0000000000000000000000000000000000000000') }); it("should fail on a false signature", async () => { @@ -1213,30 +1194,40 @@ contract("LiquidityBridgeContract", async (accounts) => { }); it("Should emit event when pegout is deposited", async () => { - const quoteHash = - "0x9fbfd385b8b19b130ae787ba3f14a0ab53274be939cdcf66018c9ba3014a8284"; + const quote = utils.getTestPegOutQuote( + instance.address, //lbc address + liquidityProviderRskAddress, + accounts[2], + 1 + ); + const quoteHash = await instance.hashPegoutQuote(quote); const tx = await instance.depositPegout( - quoteHash, - liquidityProviderRskAddress, + quote, { value: web3.utils.toBN("500") } ); await truffleAssertions.eventEmitted(tx, "PegOutDeposit", { quoteHash: quoteHash, accumulatedAmount: web3.utils.toBN("500"), }); + // check that stores quote + const storedQuote = await instance.getRegisteredPegOutQuote(quoteHash) + expect(storedQuote.lbcAddress).to.not.be.eq('0x0000000000000000000000000000000000000000') }); it("Should update quote received amount when pegout is deposited", async () => { - const quoteHash = - "0x9fbfd385b8b19b130ae787ba3f14a0ab53274be939cdcf66118c9ba3014a8284"; - const firstTx = await instance.depositPegout( - quoteHash, + const quote = utils.getTestPegOutQuote( + instance.address, //lbc address liquidityProviderRskAddress, + accounts[2], + 2 + ); + const quoteHash = await instance.hashPegoutQuote(quote); + const firstTx = await instance.depositPegout( + quote, { value: web3.utils.toBN("500") } ); const secondTx = await instance.depositPegout( - quoteHash, - liquidityProviderRskAddress, + quote, { value: web3.utils.toBN("500") } ); await truffleAssertions.eventEmitted(firstTx, "PegOutDeposit", { @@ -1250,11 +1241,15 @@ contract("LiquidityBridgeContract", async (accounts) => { }); it("Should fail if provider is not registered", async () => { - const quoteHash = - "0x9fbfd385b8b19b130ae787ba3f14a0ab53274be939cdcf66118c9ba3014a8284"; - const tx = instance.depositPegout(quoteHash, accounts[4], { - value: web3.utils.toBN("500"), - }); + const quote = utils.getTestPegOutQuote( + instance.address, //lbc address + liquidityProviderRskAddress, + accounts[2], + web3.utils.toBN(3) + ); + await instance.resign(); + await instance.withdrawPegoutCollateral(); + const tx = instance.depositPegout(quote, { value: web3.utils.toBN("500") }); await truffleAssertions.reverts(tx, "Provider not registered"); }); @@ -1263,36 +1258,32 @@ contract("LiquidityBridgeContract", async (accounts) => { instance.address, //lbc address liquidityProviderRskAddress, accounts[1], - web3.utils.toBN(1) + web3.utils.toBN(4) ); // so its expired after deposit quote.expireDate = quote.agreementTimestamp + 5 quote.expireBlock = await web3.eth.getBlock("latest").then(block => block.number + 1); - const quoteHash = await instance.hashPegoutQuote(utils.asArray(quote)); + const quoteHash = await instance.hashPegoutQuote(quote); const signature = await web3.eth.sign( quoteHash, liquidityProviderRskAddress ); - const firstTx = await instance.depositPegout( - quoteHash, - liquidityProviderRskAddress, - { value: web3.utils.toBN(1) } - ); + const firstTx = await instance.depositPegout(quote, { value: web3.utils.toBN(4) }); await truffleAssertions.eventEmitted(firstTx, "PegOutDeposit", { quoteHash: quoteHash, - accumulatedAmount: web3.utils.toBN(1), + accumulatedAmount: web3.utils.toBN(4), }); - const tx = await instance.refundUserPegOut(utils.asArray(quote), signature); + const tx = await instance.refundUserPegOut(quote, signature); await truffleAssertions.eventEmitted(tx, "PegOutUserRefunded", { quoteHash: quoteHash, - value: web3.utils.toBN(1), + value: web3.utils.toBN(4), userAddress: quote.rskRefundAddress, }); }); diff --git a/test/utils/index.js b/test/utils/index.js index 7597160..a991b9c 100644 --- a/test/utils/index.js +++ b/test/utils/index.js @@ -87,8 +87,9 @@ async function ensureLiquidityProviderAvailable( liquidityProviderRskAddress, amount ) { - let lpIsAvailable = await instance.isOperational(liquidityProviderRskAddress); - if (!lpIsAvailable) { + let lpIsAvailableForPegin = await instance.isOperational(liquidityProviderRskAddress); + let lpIsAvailableForPegout = await instance.isOperationalForPegout(liquidityProviderRskAddress); + if (!lpIsAvailableForPegin || !lpIsAvailableForPegout) { return await instance.register( "First contract", 10, diff --git a/truffle-config.js b/truffle-config.js index 7dee421..4a55479 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -49,7 +49,7 @@ module.exports = { settings: { // See the solidity docs for advice about optimization and evmVersion optimizer: { enabled: true, - runs: 50 + runs: 1 }, evmVersion: "byzantium" }