verified-network / verified-compound-markets

RWA markets for the Compound protocol
1 stars 4 forks source link

Using Oracle for Bonds #7

Open kallolborah opened 6 months ago

kallolborah commented 6 months ago

Bonds can support multiple collateral types. In Compound, the supported collaterals are specific to each chain and market. Here is an example of 'Collateral assets' supported in the USDC market on Ethereum mainnet.

Bonds can therefore be issued and purchased with specific collaterals. To achieve this, do the following for each new collateral type -

  1. In admin UI 'configuration' menu, add - Support Token - as a separate section image Here, in the 'Support token' section, you need to call two functions on the Factory contract (not the securities factory !) a) function supportTokens(bytes32 _currency, address _address) onlyManager(msg.sender) external where, currency could be the name of the supported collateral, and address is its address. b) function setCryptoDataURL(string calldata _url, bytes32 _fromCurrency, bytes32 _toCurrency) onlyManager(msg.sender) external where, the calldata_url is the URL the oracle has to call to fetch data for the collateral, fromCurrency is the collateral token to support and toCurrency is the currency in which it is quoted. For example, await factory.setCryptoDataURL("https://api.pro.coinbase.com/products/DAI-USD/ticker", web3.utils.utf8ToHex("DAI"), web3.utils.utf8ToHex("USD"));

  2. Compute request url for oracle : do the following a) compute query, where bytes32 query = keccak256(abi.encodePacked(_ratetype, _fromCurrency, _toCurrency)), where _rateType is 'ver' or 'ir' or 'er', _fromCurrency is the collateral token, and _toCurrency is the cash token (USD, etc). You will therefore get 3 values for query b) call from the oracle on bridge during its initialization to the oracle contract this function setResult(bytes32 _query, uint256 _result) public where query is what you compute above and result is the return value in 18 decimals, for example, oracle.setResult('0x5c6eba0c2c7dfec78c1cf714a24412ec174659d5f0ec0d3a91ddcbb160736dc5', '930000000000000000');//usd-eur

  3. Update oracle contract from Oracle on bridge a) on a configurable interval (eg, 15 mins, 1 hour, etc), update all queries for NewRequest events emitted by oracle contract, which will have some of the same query variables. This way, we know which queries are being used on the bond contract


You can now proceed to issue and purchase bonds, it will work.

Mohzcrea8me commented 6 months ago

@kallolborah okay adding support tokens section, the url of collateral list is not working i'm wondering if the section will be a dropdown of accepted collaterals from compound for each chain so admin can pick and the token name and address will be automatically used when calling supporTokens

kallolborah commented 6 months ago

@kallolborah okay adding support tokens section, the url of collateral list is not working i'm wondering if the section will be a dropdown of accepted collaterals from compound for each chain so admin can pick and the token name and address will be automatically used when calling supporTokens

Just go to https://app.compound.finance and check the Ethereum-USDC market or any other market. You will see list of supported collateral there. No need to add dropdown of accepted collateral for compound only because we will be integrating to Maker DAO and Aave only. Since Admin's wallet is anyway connected to a chain, whatever you add will only get added to the Factory contract on that chain only. So, enough to show text fields here for collateral name, address, etc.

Mohzcrea8me commented 6 months ago

@kallolborah okay adding support tokens section, the url of collateral list is not working i'm wondering if the section will be a dropdown of accepted collaterals from compound for each chain so admin can pick and the token name and address will be automatically used when calling supporTokens

Just go to https://app.compound.finance and check the Ethereum-USDC market or any other market. You will see list of supported collateral there. No need to add dropdown of accepted collateral for compound only because we will be integrating to Maker DAO and Aave only. Since Admin's wallet is anyway connected to a chain, whatever you add will only get added to the Factory contract on that chain only. So, enough to show text fields here for collateral name, address, etc.

okay

Mohzcrea8me commented 6 months ago

Bonds can support multiple collateral types. In Compound, the supported collaterals are specific to each chain and market. Here is an example of 'Collateral assets' supported in the USDC market on Ethereum mainnet.

Bonds can therefore be issued and purchased with specific collaterals. To achieve this, do the following for each new collateral type -

  1. In admin UI 'configuration' menu, add - Support Token - as a separate section image Here, in the 'Support token' section, you need to call two functions on the Factory contract (not the securities factory !) a) function supportTokens(bytes32 _currency, address _address) onlyManager(msg.sender) external where, currency could be the name of the supported collateral, and address is its address. b) function setCryptoDataURL(string calldata _url, bytes32 _fromCurrency, bytes32 _toCurrency) onlyManager(msg.sender) external where, the calldata_url is the URL the oracle has to call to fetch data for the collateral, fromCurrency is the collateral token to support and toCurrency is the currency in which it is quoted. For example, await factory.setCryptoDataURL("https://api.pro.coinbase.com/products/DAI-USD/ticker", web3.utils.utf8ToHex("DAI"), web3.utils.utf8ToHex("USD"));
  2. Compute request url for oracle : do the following a) compute query, where bytes32 query = keccak256(abi.encodePacked(_ratetype, _fromCurrency, _toCurrency)), where _rateType is 'ver' or 'ir' or 'er', _fromCurrency is the collateral token, and _toCurrency is the cash token (USD, etc). You will therefore get 3 values for query b) call from the oracle on bridge during its initialization to the oracle contract this function setResult(bytes32 _query, uint256 _result) public where query is what you compute above and result is the return value in 18 decimals, for example, oracle.setResult('0x5c6eba0c2c7dfec78c1cf714a24412ec174659d5f0ec0d3a91ddcbb160736dc5', '930000000000000000');//usd-eur
  3. Update oracle contract from Oracle on bridge a) on a configurable interval (eg, 15 mins, 1 hour, etc), update all queries for NewRequest events emitted by oracle contract, which will have some of the same query variables. This way, we know which queries are being used on the bond contract

You can now proceed to issue and purchase bonds, it will work.

@kallolborah I handled 1 on dapp and tested the supportTokens and setCryptoDataUrl they both work fine for admin UI: i will push dapp update to github now and deploy to firebase when you approve it. What it looks like: Screenshot 2024-05-27 081011 Screenshot 2024-05-27 081038

Working on bridge related update for 2, i hope the size update you made helps keep the bridge on at all times, i will let you know when this is handled too