Skip to content

Commit

Permalink
feat: stEUR deployment on Linea
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec committed May 20, 2024
1 parent 095e021 commit f4bf913
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 69 deletions.
113 changes: 113 additions & 0 deletions contracts/helpers/Harvester.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// // SPDX-License-Identifier: GPL-3.0

// pragma solidity ^0.8.19;

// import { IERC20 } from "oz/interfaces/IERC20.sol";
// import { SafeERC20 } from "oz/token/ERC20/utils/SafeERC20.sol";
// import { SafeCast } from "oz/utils/math/SafeCast.sol";

// import { ITransmuter } from "interfaces/ITransmuter.sol";

// import { AccessControl, IAccessControlManager } from "../utils/AccessControl.sol";
// import "../utils/Constants.sol";
// import "../utils/Errors.sol";

// import { RebalancerFlashloan } from "./RebalancerFlashloan.sol";

// /// @title Rebalancer
// /// @author Angle Labs, Inc.
// /// @notice Contract built to subsidize rebalances between collateral tokens
// /// @dev This contract is meant to "wrap" the Transmuter contract and provide a way for governance to
// /// subsidize rebalances between collateral tokens. Rebalances are done through 2 swaps collateral <> agToken.
// /// @dev This contract is not meant to hold any transient funds aside from the rebalancing budget
// contract Harvester is AccessControl {
// using SafeERC20 for IERC20;
// using SafeCast for uint256;

// /// @notice Reference to the `transmuter` implementation this contract aims at rebalancing
// ITransmuter public immutable TRANSMUTER;
// /// @notice AgToken handled by the `transmuter` of interest
// RebalancerFlashloan public rebalancer;

// address public collateral;

// address public vault;

// uint64 public maxExposureYieldAsset;

// uint64 public minExposureYieldAsset;

// uint64 public targetExposureLiquid;

// uint64 public maxSlippage;

// /*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// INITIALIZATION
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/

// /// @notice Initializes the immutable variables of the contract: `accessControlManager`, `transmuter` and `agToken`
// constructor(RebalancerFlashloan _rebalancer, address _collateral, address _vault) {
// ITransmuter _transmuter = _rebalancer.TRANSMUTER();
// TRANSMUTER = _transmuter;
// rebalancer = _rebalancer;
// accessControlManager = IAccessControlManager(_transmuter.accessControlManager());
// vault = _vault;
// collateral = _collateral;
// _getLimitExposuresYieldAsset();
// }

// // Due to potential transaction fees, multiple harvests may be needed to arrive at the target exposure
// function harvest() external {
// (uint256 stablecoinsFromCollateral, uint256 stablecoinsIssued) = TRANSMUTER.getIssuedByCollateral(collateral);
// (uint256 stablecoinsFromVault, ) = TRANSMUTER.getIssuedByCollateral(vault);
// uint8 increase;
// uint256 amount;
// if (stablecoinsFromCollateral * 1e9 > targetExposureLiquid * stablecoinsIssued) {
// // Need to increase exposure to yield bearing asset
// increase = 1;
// amount = stablecoinsFromCollateral - (targetExposureLiquid * stablecoinsIssued) / 1e9;
// if (stablecoinsFromVault + amount > (maxExposureYieldAsset * stablecoinsIssued) / 1e9) {
// amount = maxExposureYieldAsset * stablecoinsIssued - stablecoinsFromVault / 1e9;
// }
// } else {
// amount = targetExposureLiquid * stablecoinsIssued - stablecoinsFromCollateral / 1e9;
// if (amount >= stablecoinsFromVault) amount = stablecoinsFromVault;
// if (stablecoinsFromVault - amount < (minExposureYieldAsset * stablecoinsIssued) / 1e9) {
// amount = stablecoinsFromVault - (minExposureYieldAsset * stablecoinsIssued) / 1e9;
// }
// }
// TRANSMUTER.updateOracle(vault);
// rebalancer.adjustYieldExposure(amount, increase, collateral, vault, (amount * (1e9 - maxSlippage)) / 1e9);
// }

// function setRebalancer(address _newRebalancer) external onlyGuardian {
// rebalancer = _newRebalancer;
// // Assumption is done that being built on the same Transmuter contract
// }

// function setTargetExposure(uint64 _targetExposure) external onlyGuardian {
// targetExposureLiquid = _targetExposure;
// }

// function setMaxSlippage(uint64 _maxSlippage) external onlyGuardian {
// maxSlippage = _maxSlippage;
// }

// function getLimitExposuresYieldAsset() external {
// _getLimitExposuresYieldAsset();
// }

// function _getLimitExposuresYieldAsset() internal {
// uint64[] memory xFeeMint;
// (xFeeMint, ) = TRANSMUTER.getCollateralMintFees(vault);
// uint256 length = xFeeMint.length;
// if (length <= 1) maxExposureYieldAsset = 1e9;
// else maxExposureYieldAsset = xFeeMint[length - 2];

// uint64[] memory xFeeBurn;
// (xFeeBurn, ) = TRANSMUTER.getCollateralBurnFees(vault);
// length = xFeeBurn.length;
// if (length <= 1) minExposureYieldAsset = 0;
// else minExposureYieldAsset = xFeeBurn[length - 2];
// }
// }
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"lint:check": "solhint --max-warnings 20 \"**/*.sol\"",
"vanity": "forge script --skip test --slow -vvvv --rpc-url mainnet ./scripts/utils/VanityAddress.s.sol",
"verify:agEUR": "forge verify-contract --chain-id 100 --num-of-optimizations 1000 --watch --constructor-args $(cast abi-encode 'constructor(string memory,string memory,uint8)' 'Mock-AgEUR' 'Mock-AgEUR' 18) --compiler-version v0.8.19+commit.7dd6d40 --etherscan-api-key HQU42G9VWZ6KFNYTYKE6VFB7V48KMJ69HS 0x5fE0E497Ac676d8bA78598FC8016EBC1E6cE14a3 lib/borrow-contracts/contracts/mock/MockTokenPermit:MockTokenPermit.sol",
"verify": "forge verify-contract --num-of-optimizations 1000 --watch --constructor-args 0000000000000000000000000000000000ffe8b47b3e2130213b802212439497000000000000000000000000fda462548ce04282f4b6d6619823a7c64fdc018500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000 --compiler-version v0.8.19+commit.7dd6d404 0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776 lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy --chain"
"verify:stUSD": "forge verify-contract --num-of-optimizations 1000 --watch --constructor-args 0000000000000000000000000000000000ffe8b47b3e2130213b802212439497000000000000000000000000fda462548ce04282f4b6d6619823a7c64fdc018500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000 --compiler-version v0.8.19+commit.7dd6d404 0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776 lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy --chain",
"verify:stEUR": "forge verify-contract --num-of-optimizations 1000 --watch --constructor-args 0000000000000000000000000000000000ffe8b47b3e2130213b802212439497000000000000000000000000fda462548ce04282f4b6d6619823a7c64fdc018500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000 --compiler-version v0.8.19+commit.7dd6d404 0x004626A008B1aCdC4c74ab51644093b155e59A23 lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol:TransparentUpgradeableProxy --chain"
},
"keywords": [],
"author": "Angle Labs, Inc.",
Expand Down
2 changes: 1 addition & 1 deletion scripts/AdjustYieldExposure.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract AdjustYieldExposure is Utils {
vm.startBroadcast(deployerPrivateKey);

RebalancerFlashloan rebalancer = RebalancerFlashloan(0x22604C0E5633A9810E01c9cb469B23Eee17AC411);
rebalancer.adjustYieldExposure(1000000 * 1 ether, 1, USDC, STEAK_USDC, 900000 * 1 ether);
rebalancer.adjustYieldExposure(1300000 * 1 ether, 0, USDC, STEAK_USDC, 1200000 * 1 ether);

vm.stopBroadcast();
}
Expand Down
43 changes: 29 additions & 14 deletions scripts/DeploySavings.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,71 @@ import { TransparentUpgradeableProxy } from "oz/proxy/transparent/TransparentUpg
import { ImmutableCreate2Factory } from "./utils/TransmuterDeploymentHelper.s.sol";

/// @dev To deploy on a different chain, just replace the chainId and be sure the sdk has the required addresses
/// To match the right computed address and init code: need to deploy with Solidity 0.8.19
contract DeploySavings is Utils {
using stdJson for string;
using strings for *;

function run() external {
// TODO: make sure that deployer has a 1 agEUR (=1e18) balance
// TODO: make sure that deployer has a 1 EURA (=1e18) balance
// TODO: change the chainId
uint256 chainId = CHAIN_SOURCE;
uint256 deployerPrivateKey = vm.deriveKey(vm.envString("MNEMONIC_MAINNET"), "m/44'/60'/0'/0/", 0);
ImmutableCreate2Factory create2Factory = ImmutableCreate2Factory(IMMUTABLE_CREATE2_FACTORY_ADDRESS);
string memory jsonVanity = vm.readFile(JSON_VANITY_PATH);
bytes32 salt = jsonVanity.readBytes32(string.concat("$.", "salt"));
// Setup addresses
/*
address proxyAdmin = _chainToContract(chainId, ContractType.ProxyAdmin);
address stablecoin = _chainToContract(chainId, ContractType.AgEUR);
address coreBorrow = _chainToContract(chainId, ContractType.CoreBorrow);
*/

address proxyAdmin = 0x1D941EF0D3Bba4ad67DBfBCeE5262F4CEE53A32b;
address stablecoin = 0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8;
address coreBorrow = 0x4b1E2c2762667331Bc91648052F646d1b0d35984;
console.log(proxyAdmin, stablecoin, coreBorrow);

vm.startBroadcast(deployerPrivateKey);

address deployer = vm.addr(deployerPrivateKey);
console.log("Deployer address: ", deployer);

// Deploying the proxy.
// To maintain chain consistency, we deploy with the deployer as a proxyAdmin before transferring
// to another address
// We use a contract that is widely deployed across many chains as an implementation to make it resilient
// to possible implementation changes

/*
bytes memory emptyData;
bytes memory initCode = abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(IMMUTABLE_CREATE2_FACTORY_ADDRESS, deployer, emptyData)
);
*/
// initCode on stEUR
initCode = hex"60406080815262000cdb80380380620000188162000364565b9283398101906060818303126200035f576200003481620003a0565b9160209262000045848401620003a0565b8584015190936001600160401b0391908282116200035f57019280601f850112156200035f57835193620000836200007d86620003b5565b62000364565b94808652878601928882840101116200035f578288620000a49301620003d1565b823b1562000305577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b03199081166001600160a01b0386811691821790935590959194600093909290917fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8580a2805115801590620002fd575b620001f5575b50505050507fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103937f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f86865493815196818616885216958684820152a18315620001a3575016179055516108869081620004558239f35b60849086519062461bcd60e51b82526004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201526564647265737360d01b6064820152fd5b8951946060860190811186821017620002e9578a52602785527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c89860152660819985a5b195960ca1b8a860152823b156200029657928092819262000280969551915af43d156200028c573d620002706200007d82620003b5565b9081528092893d92013e620003f6565b5038808080806200012d565b60609150620003f6565b895162461bcd60e51b8152600481018a9052602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b6064820152608490fd5b634e487b7160e01b85526041600452602485fd5b508362000127565b865162461bcd60e51b815260048101879052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b038111838210176200038a57604052565b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b03821682036200035f57565b6001600160401b0381116200038a57601f01601f191660200190565b60005b838110620003e55750506000910152565b8181015183820152602001620003d4565b9091901562000403575090565b815115620004145750805190602001fd5b6044604051809262461bcd60e51b825260206004830152620004468151809281602486015260208686019101620003d1565b601f01601f19168101030190fdfe60806040526004361015610019575b3661037c575b61037c565b6000803560e01c9081633659cfe61461006c575080634f1ef286146100675780635c60da1b146100625780638f2839701461005d5763f851a4400361000e57610326565b610212565b61019e565b6100ef565b346100d15760203660031901126100d1576100856100d4565b6001600160a01b037fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610354163314600014610014576100ce906100c56104af565b90838252610516565b80f35b80fd5b600435906001600160a01b03821682036100ea57565b600080fd5b60403660031901126100ea576101036100d4565b60243567ffffffffffffffff918282116100ea57366023830112156100ea5781600401359283116100ea5736602484840101116100ea576001600160a01b037fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035416331460001461001457600060208480602461018a61018561019c996104fa565b6104d4565b96828852018387013784010152610624565b005b346100ea5760003660031901126100ea576001600160a01b03807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610354163314600014610014577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5460405191168152602090f35b346100ea5760203660031901126100ea5761022b6100d4565b6001600160a01b03907fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610391808354163314600014610014577f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f604084549281519481851686521693846020820152a181156102bc5773ffffffffffffffffffffffffffffffffffffffff1916179055005b608460405162461bcd60e51b815260206004820152602660248201527f455243313936373a206e65772061646d696e20697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152fd5b346100ea5760003660031901126100ea576001600160a01b037fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61039080825416331460001461001457905460405191168152602090f35b6001600160a01b03807fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103541633146103f0577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e156103ec573d90f35b3d90fd5b60a460405162461bcd60e51b815260206004820152604260248201527f5472616e73706172656e745570677261646561626c6550726f78793a2061646d60448201527f696e2063616e6e6f742066616c6c6261636b20746f2070726f7879207461726760648201527f65740000000000000000000000000000000000000000000000000000000000006084820152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b604051906020820182811067ffffffffffffffff8211176104cf57604052565b610480565b6040519190601f01601f1916820167ffffffffffffffff8111838210176104cf57604052565b67ffffffffffffffff81116104cf57601f01601f191660200190565b803b156105ba576001600160a01b0381167f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8173ffffffffffffffffffffffffffffffffffffffff198254161790557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28151158015906105b2575b61059d575050565b6105af916105a96106b2565b91610722565b50565b506000610595565b608460405162461bcd60e51b815260206004820152602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201527f6f74206120636f6e7472616374000000000000000000000000000000000000006064820152fd5b803b156105ba576001600160a01b0381167f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8173ffffffffffffffffffffffffffffffffffffffff198254161790557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28151158015906106aa5761059d575050565b506001610595565b604051906060820182811067ffffffffffffffff8211176104cf57604052602782527f206661696c6564000000000000000000000000000000000000000000000000006040837f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c60208201520152565b9190823b1561076b576000816107609460208394519201905af43d15610763573d90610750610185836104fa565b9182523d6000602084013e6107d5565b90565b6060906107d5565b608460405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f60448201527f6e747261637400000000000000000000000000000000000000000000000000006064820152fd5b909190156107e1575090565b8151156107f15750805190602001fd5b6040519062461bcd60e51b82528160208060048301528251908160248401526000935b828510610837575050604492506000838284010152601f80199101168101030190fd5b848101820151868601604401529381019385935061081456fea2646970667358221220cd51d87f687e65d41171d5f157313805c8c9f1c12984f1d6b0d726a20f3df98e64736f6c634300081300330000000000000000000000000000000000ffe8b47b3e2130213b802212439497000000000000000000000000fda462548ce04282f4b6d6619823a7c64fdc018500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000";

console.log("Proxy bytecode");
console.logBytes(initCode);
console.log("");
/*

address computedAddress = create2Factory.findCreate2Address(salt, initCode);
console.log("Supposed to deploy: %s", computedAddress);

if (computedAddress != 0x004626A008B1aCdC4c74ab51644093b155e59A23) revert();

address saving = create2Factory.safeCreate2(salt, initCode);
console.log("Savings deployed at: ", address(saving));
// Deploying the implementation

Savings savingsImpl = new Savings();
TransparentUpgradeableProxy(payable(saving)).upgradeTo(address(savingsImpl));
TransparentUpgradeableProxy(payable(saving)).changeAdmin(_chainToContract(chainId, ContractType.ProxyAdmin));
IERC20MetadataUpgradeable(_chainToContract(chainId, ContractType.AgEUR)).approve(address(saving), 1e18);
TransparentUpgradeableProxy(payable(saving)).changeAdmin(proxyAdmin);
IERC20MetadataUpgradeable(stablecoin).approve(address(saving), 1e18);
Savings(saving).initialize(
IAccessControlManager(_chainToContract(chainId, ContractType.CoreBorrow)),
IERC20MetadataUpgradeable(_chainToContract(chainId, ContractType.AgEUR)),
"Staked agEUR",
IAccessControlManager(coreBorrow),
IERC20MetadataUpgradeable(stablecoin),
"Staked EURA",
"stEUR",
1
);
*/

vm.stopBroadcast();
}
}
Loading

0 comments on commit f4bf913

Please sign in to comment.