---
description: How Will The Collateral Size Determined Against The Issued Bonds?
---

# Collateral Size Determination & Oracle

To determine the price of RDTN tokens and how many tokens to lock in the collateral pool, an oracle will be used. The oracle will provide a price feed for RDTN and the smart contract will use this price to calculate the required amount of RDTN tokens to lock in the collateral pool. The formula for calculating the required amount of RDTN tokens is:



| requiredRDTN = requiredCollateral / RDTNPrice |
| --------------------------------------------- |



Where RDTNPrice is the current price of RDTN as provided by the oracle.

For example, if the collateralized assets are $100,000 and the current price of RDTN tokens is $0.10, the amount of RDTN tokens required to be locked in the pool will be 1,000,000 RDTN tokens.

here's an example of how the oracle integration function will look like in Solidity programming language:

{% code title="Collateral Size Determination" overflow="wrap" lineNumbers="true" %}
```solidity
// Importing the required contracts and libraries
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

// Defining the contract for RDTN price oracle
contract RDTNPriceOracle {
    
    // Defining the aggregator contract for RDTN price feed
    AggregatorV3Interface internal priceFeed;
    
    // Constructor function to set the RDTN price feed contract address
    constructor() public {
        priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
    }
    
    // Function to get the current RDTN price in USD
    function getRDTNPrice() public view returns (uint256) {
        (
            uint80 roundID, 
            int256 price,
            uint256 startedAt,
            uint256 timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
        return uint256(price);
    }
    
    // Function to calculate the amount of RDTN to be locked in collateral pool
    function calculateCollateralAmount(uint256 totalBondAmount) public view returns (uint256) {
        uint256 rdtPrice = getRDTNPrice();
        uint256 collateralAmount = totalBondAmount * rdtPrice / 1e18;
        return collateralAmount;
    }
    
}

```
{% endcode %}

In this example, we are using the Chainlink AggregatorV3Interface to fetch the latest RDTN price feed data. We set the RDTN price feed contract address in the constructor function, and then define a <mark style="color:green;">**`‘getRDTNPrice()’`**</mark> function to return the current RDTN price in USD.

We also define a <mark style="color:green;">**`‘calculateCollateralAmount()’`**</mark> function that takes the total bond amount as input and uses the RDTN price to calculate the amount of RDTN tokens that need to be locked in the collateral pool to back the bonds at a 1:1 ratio. This function will be called by the smart contract to determine the amount of collateral to be locked in the pool.

We can further integrate these functions in our smart contract, along with other functions and workflows that we have discussed earlier, to create a fully functional Redemption Bonds system on the blockchain.

