Skip to content

Commit

Permalink
Merge pull request #189 from VenusProtocol/feat/sfrax-oracle-deployment
Browse files Browse the repository at this point in the history
[VEN-2550] sFrax Oracle Deployment
  • Loading branch information
web3rover authored May 6, 2024
2 parents a33c8dc + 867c0fd commit 8911278
Show file tree
Hide file tree
Showing 11 changed files with 2,415 additions and 166 deletions.
33 changes: 33 additions & 0 deletions contracts/test/MockSFrax.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { ISFrax } from "../interfaces/ISFrax.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MockSFrax is ERC20, Ownable, ISFrax {
uint8 private immutable _decimals;
uint256 public exchangeRate;

constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) Ownable() {
_decimals = decimals_;
}

function faucet(uint256 amount) external {
_mint(msg.sender, amount);
}

function setRate(uint256 rate) external onlyOwner {
exchangeRate = rate;
}

function convertToAssets(uint256 shares) external view override returns (uint256) {
return (shares * exchangeRate) / (10 ** uint256(_decimals));
}

function decimals() public view virtual override(ERC20, ISFrax) returns (uint8) {
return _decimals;
}
}
51 changes: 51 additions & 0 deletions deploy/7-deploy-sfrax-oracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/dist/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESSES } from "../helpers/deploymentConfig";

const func: DeployFunction = async ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) => {
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const oracle = await ethers.getContract("ResilientOracle");
const proxyOwnerAddress = network.live ? ADDRESSES[network.name].timelock : deployer;

const { sFRAX, FRAX } = ADDRESSES[network.name];

let sFRAXAddress = sFRAX;
if (!sFRAXAddress) {
await deploy("MockSFrax", {
contract: "MockSFrax",
from: deployer,
log: true,
autoMine: true, // speed up deployment on local network (ganache, hardhat), no effect on live networks
skipIfAlreadyDeployed: true,
args: ["Staked FRAX", "sFRAX", 18],
});

const mockSFraxContract = await ethers.getContract("MockSFrax");
sFRAXAddress = mockSFraxContract.address;

if ((await mockSFraxContract.owner()) === deployer) {
await mockSFraxContract.transferOwnership(proxyOwnerAddress);
}
}

await deploy("SFraxOracle", {
contract: "SFraxOracle",
from: deployer,
log: true,
deterministicDeployment: false,
args: [sFRAXAddress, FRAX, oracle.address],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
},
skipIfAlreadyDeployed: true,
});
};

export default func;
func.tags = ["sFraxOracle"];
func.skip = async (hre: HardhatRuntimeEnvironment) => hre.network.name !== "ethereum" && hre.network.name !== "sepolia";
Loading

0 comments on commit 8911278

Please sign in to comment.