From e01e502cc8207e75c97f96b51f88ea4b1c0bdacc Mon Sep 17 00:00:00 2001 From: Luisfc68 Date: Wed, 17 Apr 2024 17:58:23 +0200 Subject: [PATCH] feat: add lp url update capability --- contracts/LiquidityBridgeContractV2.sol | 22 +++++--- errorCodes.json | 3 +- test/basic.tests.js | 69 +++++++++++++++++++++++-- 3 files changed, 84 insertions(+), 10 deletions(-) diff --git a/contracts/LiquidityBridgeContractV2.sol b/contracts/LiquidityBridgeContractV2.sol index 521900f..f6e4db2 100644 --- a/contracts/LiquidityBridgeContractV2.sol +++ b/contracts/LiquidityBridgeContractV2.sol @@ -88,6 +88,7 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra address userAddress ); event DaoFeeSent(bytes32 indexed quoteHash, uint256 amount); + event ProviderUpdate(address indexed providerAddress, string name, string url); Bridge public bridge; mapping(address => uint256) private balances; @@ -173,12 +174,6 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra return dust; } - function getRegisteredPegOutQuote( - bytes32 quoteHash - ) external view returns (QuotesV2.PegOutQuote memory) { - return registeredPegoutQuotes[quoteHash]; - } - function isPegOutQuoteCompleted(bytes32 quoteHash) external view returns (bool) { return pegoutRegistry[quoteHash].completed; } @@ -959,4 +954,19 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra emit DaoFeeSent(quoteHash, amount); } } + + function updateProvider(string memory _name, string memory _url) external { + require(bytes(_name).length > 0 && bytes(_url).length > 0, "LBC076"); + LiquidityProvider storage lp; + for (uint i = 1; i <= providerId; i++) { + lp = liquidityProviders[i]; + if (msg.sender == lp.provider) { + lp.name = _name; + lp.apiBaseUrl = _url; + emit ProviderUpdate(msg.sender, lp.name, lp.apiBaseUrl); + return; + } + } + revert("LBC001"); + } } diff --git a/errorCodes.json b/errorCodes.json index 0eb1472..3c60feb 100644 --- a/errorCodes.json +++ b/errorCodes.json @@ -68,5 +68,6 @@ "LBC072": "Minimum collateral for registration can't be lower than 0.6 RBTC", "LBC073": "Resign delay blocks lower than minimal", "LBC074": "Error sending fee to DAO", - "LBC075": "Malformed BTC transaction output" + "LBC075": "Malformed BTC transaction output", + "LBC076": "Invalid information update" } diff --git a/test/basic.tests.js b/test/basic.tests.js index 84fffd8..ac356e9 100644 --- a/test/basic.tests.js +++ b/test/basic.tests.js @@ -1244,9 +1244,9 @@ contract("LiquidityBridgeContractV2.sol", async (accounts) => { quoteHash: quoteHash, amount: value, }); - // check that stores quote - const storedQuote = await instance.getRegisteredPegOutQuote(quoteHash) - expect(storedQuote.lbcAddress).to.not.be.eq('0x0000000000000000000000000000000000000000') + // deposit again an expect an error to ensure quote is stored + const failedTx = instance.depositPegout(quote, signature, { value: value.toNumber() }); + await truffleAssertions.reverts(failedTx, "LBC028"); }); it("Should not allow to deposit less than total required on pegout", async () => { @@ -2020,4 +2020,67 @@ contract("LiquidityBridgeContractV2.sol", async (accounts) => { "LBC071" ); }) + + it('Should update the liquidity provider information correctly', async () => { + const providerAddress = accounts[9] + const maxId = await instance.getProviderIds() + const ids = Array.from({length: maxId.toNumber()}, (_, i) => i + 1) + let provider = await instance.getProviders(ids).then(result => result.at(0)) + + const initialState = { + id: provider.id, + provider: provider.provider, + name: provider.name, + apiBaseUrl: provider.apiBaseUrl, + status: provider.status, + providerType: provider.providerType + } + + const newName = 'modified name' + const newApiBaseUrl = 'https://modified.com' + + const tx = await instance.updateProvider(newName, newApiBaseUrl, { from: providerAddress }) + truffleAssertions.eventEmitted(tx, "ProviderUpdate", { + providerAddress: providerAddress, + name: newName, + url: newApiBaseUrl + }); + + provider = await instance.getProviders(ids).then(result => result.at(0)) + const finalState = { + id: provider.id, + provider: provider.provider, + name: provider.name, + apiBaseUrl: provider.apiBaseUrl, + status: provider.status, + providerType: provider.providerType + } + + expect(initialState.id).to.eq(finalState.id) + expect(initialState.provider).to.eq(finalState.provider) + expect(initialState.status).to.eq(finalState.status) + expect(initialState.providerType).to.eq(finalState.providerType) + expect(initialState.name).to.not.eq(finalState.name) + expect(initialState.apiBaseUrl).to.not.eq(finalState.apiBaseUrl) + expect(finalState.name).to.eq(newName) + expect(finalState.apiBaseUrl).to.eq(newApiBaseUrl) + }) + + it('Should fail if unregistered provider updates his information', async () => { + const providerAddress = accounts[8] + const newName = 'not-existing name' + const newApiBaseUrl = 'https://not-existing.com' + const tx = instance.updateProvider(newName, newApiBaseUrl, { from: providerAddress }) + await truffleAssertions.reverts(tx, "LBC001"); + }) + + it('Should fail if provider makes update with invalid information', async () => { + const providerAddress = accounts[9] + const newName = 'any name' + const newApiBaseUrl = 'https://any.com' + const wrongName = instance.updateProvider('', newApiBaseUrl, { from: providerAddress }) + await truffleAssertions.reverts(wrongName, "LBC076"); + const wrongUrl = instance.updateProvider(newName, '', { from: providerAddress }) + await truffleAssertions.reverts(wrongUrl, "LBC076"); + }) });