This documentation outlines the implementation and deployment process for a stablecoin (ETHIXUSD) system with two alternative collateralization methods:
- Option A: Using real-world ETH price - Leveraging Chainlink Oracle data feeds to maintain the peg
- Option B: Using custom unstable collateral - Using ETHIX token as collateral with simulated price fluctuations
Both approaches demonstrate how the governance mechanism automatically rebalances collateral to maintain the target price peg.
The ETHIXUSD stablecoin system consists of several interconnected smart contracts:
- USDT.sol: Acts as the stable collateral token
- WETH.sol/ETHIX.sol: Acts as the unstable collateral token
- WETH for Option A (using real-world ETH price)
- ETHIX for Option B (using custom unstable collateral)
- Reserves.sol: Manages collateral assets
- PriceOracle.sol: Interfaces with Chainlink data feeds
- Governance.sol: Manages the stablecoin peg mechanism
- ETHIXUSD.sol: The stablecoin token itself
-
Deploy USDT Contract
- Deploy the USDT.sol contract
- Mint 200,000 USDT tokens in wei:
200,000 * 10^18 = 200,000,000,000,000,000,000,000
-
Deploy WETH Contract
- Deploy the WETH.sol contract
-
Deploy Reserves Contract
- Deploy the Reserves.sol contract
- In USDT.sol, approve the Reserves contract to spend 200,000 USDT tokens
- In Reserves.sol, call
addReservefunction:- Add USDT.sol address (ID 0)
- Add WETH.sol address (ID 1)
- Call
depositfunction with ID 0 and amount200,000 * 10^18 - Verify the amount by checking
rsvVaultfor ID 0
-
Deploy PriceOracle Contract
- Deploy the PriceOracle.sol contract
- Call
setDataFeedAddresswith the Chainlink ETH/USD data feed address - Reference: Chainlink Data Feeds
-
Deploy Governance Contract
- Deploy the Governance-option1.sol with USDT.sol address in the constructor
- Add collateral token addresses:
- Call
addCollateralTokenwith USDT.sol address - Call
addCollateralTokenwith WETH.sol address
- Call
- Set data feed address with
setDataFeedAddress - Set reserve contract address with
reserveSmartContractfunction
-
Fetch Collateral Price
- In Reserve.sol, call
fetchCollateralPriceto get real-time ETH/USD value - Check the value in
unstableColPricevariable and convert from wei to ETH - Calculate required ETH amount:
800,000 / real-time ETH price
- In Reserve.sol, call
-
Mint WETH Tokens
- Mint the calculated amount of ETH in wei using WETH.sol's
mintfunction - Call
approvefunction with the Reserves.sol address and the minted amount
- Mint the calculated amount of ETH in wei using WETH.sol's
-
Deposit WETH to Reserves
- In Reserves.sol, deposit the minted WETH amount to ID 1
-
Configure ETHIXUSD Permissions
- In ETHIXUSD.sol, call
grantRolefunction with:- Governance.sol address
- Output of the
MANAGER_ROLEvariable
- In ETHIXUSD.sol, call
-
Mint and Configure ETHIXUSD
- Mint 1,000,000 ETHIXUSD tokens in wei:
1,000,000 * 10^18 - Transfer 500,000 ETHIXUSD tokens to Governance.sol
- In Governance.sol, call
validatePegfunction to equalize the stable collateral - Check
ethixUSDsupplyto view the stabilized amount
- Mint 1,000,000 ETHIXUSD tokens in wei:
-
Test Peg Mechanism
- In Reserves.sol, call
withdrawfunction with:- pid = 1
- Amount of ETH to withdraw (simulates ETH price change)
- In Governance.sol, call
validatePegfunction - Check
ethixUSDsupplyto verify peg adjustment
- In Reserves.sol, call
-
Deploy and Configure USDT
- Deploy USDT.sol contract
- Mint 200,000 USDT tokens in wei:
200,000 * 10^18 - Approve Reserves.sol to spend 200,000 USDT
-
Deploy and Configure ETHIX Token
- Deploy ETHIX.sol contract
- Mint 1 billion ETHIX tokens in wei:
10^27 - Approve Reserves.sol and Governance.sol to spend 1 billion ETHIX tokens
-
Deploy Reserves Contract
- Deploy Reserves.sol
- Add collateral token addresses with
addReserve:- USDT.sol (ID 0)
- ETHIX.sol (ID 1)
- Deposit 200,000 USDT to ID 0
- Deposit 10,000,000 ETHIX tokens to ID 1
- Verify deposits using
rsvVaultfunction
-
Deploy ETHIXUSD
- Deploy ETHIXUSD.sol contract
- Mint 1,000,000 ETHIXUSD tokens in wei:
10^24
-
Deploy Governance Contract
- Deploy Governance.sol
- Add collateral token addresses:
- USDT.sol
- ETHIX.sol
- Set Reserves contract with
setReserveContract
-
Configure Permissions
- In ETHIX.sol, call
grantRolewith:- Governance.sol address
- MANAGER_ROLE bytes32 value
- In ETHIX.sol, call
-
Configure and Test Peg Mechanism
- In Governance.sol:
- Set ETHIX token price to 80,000,000 with
ethixTokenPrice - Set ETHIXUSD supply to 1,000,000 tokens
- Set ETHIX token price to 80,000,000 with
- Transfer 500,000,000 ETHIX tokens to Governance.sol
- Call
validatePegfunction - Verify the following:
- Unstable collateral amount: should show 10 million ETHIX tokens
- Unstable collateral price: should be ~0.08
- Stable collateral amount: should show 200,000 USDT
- Stable collateral price: should be ~10^18
- ETHIX supply: should remain at 1 billion tokens
- Change ETHIX token price with
ethixTokenPrice - Run
validatePegagain to verify rebalancing
- In Governance.sol:
- Option A uses Chainlink Oracle for real-world
ETHprice data andWETH.solcontract. - Option B allows price simulation via the
ethixTokenPricefunction of theETHIX.solcontract. - Both options demonstrate how the stablecoin maintains its peg through automatic rebalancing
- The
governancecontract is key to maintaining the peg value - To stabilize the stablecoin, always run
validatePegafter collateral price changes