Skip to content

Commit

Permalink
Merge pull request #229 from rsksmart/feature/GBI-1770
Browse files Browse the repository at this point in the history
feat: add lp url update capability
  • Loading branch information
Luisfc68 authored Apr 25, 2024
2 parents aa08a8b + e01e502 commit 7fce963
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
22 changes: 16 additions & 6 deletions contracts/LiquidityBridgeContractV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
}
}
3 changes: 2 additions & 1 deletion errorCodes.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
69 changes: 66 additions & 3 deletions test/basic.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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");
})
});

0 comments on commit 7fce963

Please sign in to comment.