Skip to content

Using Oracle for Bonds #7

@kallolborah

Description

@kallolborah

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions