Skip to content

Commit

Permalink
fix: deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Jan 19, 2024
1 parent e414a93 commit 972f987
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
30 changes: 13 additions & 17 deletions script/DeployAprOracle.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ import "forge-std/Script.sol";
// Deploy a contract to a deterministic address with create2
contract DeployAprOracle is Script {

Deployer public deployer = Deployer(0x8D85e7c9A4e369E53Acc8d5426aE1568198b0112);
Deployer public deployer = Deployer(0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed);

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Encode constructor arguments
bytes memory construct = abi.encode(0x33333333D5eFb92f19a5F94a43456b3cec2797AE);

// Get the bytecode
bytes memory bytecode = abi.encodePacked(vm.getCode("AprOracle.sol:AprOracle"));
bytes memory bytecode = abi.encodePacked(vm.getCode("AprOracle.sol:AprOracle"), construct);

// Pick an unique salt
uint256 salt = uint256(keccak256("APR Oracle"));
bytes32 salt = keccak256("APR Oracle");

address contractAddress = deployer.deploy(bytecode, salt);
address contractAddress = deployer.deployCreate2(salt, bytecode);

console.log("Address is ", contractAddress);

Expand All @@ -27,17 +30,10 @@ contract DeployAprOracle is Script {
}

contract Deployer {
event Deployed(address addr, uint256 salt);

function deploy(bytes memory code, uint256 salt) external returns (address) {
address addr;
assembly {
addr := create2(0, add(code, 0x20), mload(code), salt)
if iszero(extcodesize(addr)) {
revert(0, 0)
}
}
emit Deployed(addr, salt);
return addr;
}
event ContractCreation(address indexed newContract, bytes32 indexed salt);

function deployCreate2(
bytes32 salt,
bytes memory initCode
) public payable returns (address newContract) {}
}
17 changes: 10 additions & 7 deletions src/AprOracle/AprOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ contract AprOracle is Governance {
*
* @param _strategy Address of the strategy to check.
* @param _debtChange Positive or negative change in debt.
* @return . The expected APR it will be earning represented as 1e18.
* @return apr The expected APR it will be earning represented as 1e18.
*/
function getStrategyApr(
address _strategy,
int256 _debtChange
) public view virtual returns (uint256) {
) public view virtual returns (uint256 apr) {
// Get the oracle set for this specific strategy.
address oracle = oracles[_strategy];

// Don't revert if a oracle is not set.
if (oracle == address(0)) return 0;

return IOracle(oracle).aprAfterDebtChange(_strategy, _debtChange);
if (oracle != address(0)) {
return IOracle(oracle).aprAfterDebtChange(_strategy, _debtChange);
}
}

/**
Expand Down Expand Up @@ -93,8 +93,11 @@ contract AprOracle is Governance {
* @param _oracle Address of the APR Oracle.
*/
function setOracle(address _strategy, address _oracle) external virtual {
if(governance != msg.sender) {
require(msg.sender == IStrategy(_strategy).management(), "!authorized");
if (governance != msg.sender) {
require(
msg.sender == IStrategy(_strategy).management(),
"!authorized"
);
}

oracles[_strategy] = _oracle;
Expand Down

0 comments on commit 972f987

Please sign in to comment.