Skip to content

Commit

Permalink
formatted?
Browse files Browse the repository at this point in the history
  • Loading branch information
Astodialo committed Nov 5, 2024
1 parent ed3acee commit 9640327
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 328 deletions.
44 changes: 9 additions & 35 deletions src/Bread.sol
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;


// Bread - An ERC20 stablecoin fully collateralized by DAI
// which earns yield in Aave for the Breadchain Ecosystem
// implemented by: kassandra.eth

import {
SafeERC20,
IERC20
} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {
ERC20Upgradeable
} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {
OwnableUpgradeable
} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {
ReentrancyGuardUpgradeable
} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {IPool} from "./interfaces/IPool.sol";
import {IRewardsController} from "./interfaces/IRewardsController.sol";

contract Bread is
ERC20Upgradeable,
OwnableUpgradeable,
ReentrancyGuardUpgradeable
{
contract Bread is ERC20Upgradeable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
using SafeERC20 for IERC20;

IERC20 public immutable token;
IERC20 public immutable aToken;
IPool public immutable pool;
Expand All @@ -39,13 +26,7 @@ contract Bread is
event ClaimedYield(uint256 amount);
event ClaimedRewards(address[] rewardsList, uint256[] claimedAmounts);

constructor(
address _token,
address _aToken,
address _pool,
address _rewards

) {
constructor(address _token, address _aToken, address _pool, address _rewards) {
token = IERC20(_token);
aToken = IERC20(_aToken);
pool = IPool(_pool);
Expand Down Expand Up @@ -89,10 +70,7 @@ contract Bread is
function claimRewards() external nonReentrant {
address[] memory assets;
assets[0] = address(aToken);
(
address[] memory rewardsList,
uint256[] memory claimedAmounts
) = rewards.claimAllRewards(assets, owner());
(address[] memory rewardsList, uint256[] memory claimedAmounts) = rewards.claimAllRewards(assets, owner());

emit ClaimedRewards(rewardsList, claimedAmounts);
}
Expand All @@ -106,11 +84,7 @@ contract Bread is
return _yieldAccrued();
}

function rewardsAccrued()
external
view
returns (address[] memory rewardsList, uint256[] memory unclaimedAmounts)
{
function rewardsAccrued() external view returns (address[] memory rewardsList, uint256[] memory unclaimedAmounts) {
address[] memory assets;
assets[0] = address(aToken);
return rewards.getAllUserRewards(assets, address(this));
Expand Down
13 changes: 2 additions & 11 deletions src/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@
pragma solidity ^0.8.20;

interface IPool {
function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;

function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
function withdraw(address asset, uint256 amount, address to) external returns (uint256);
}
1 change: 0 additions & 1 deletion src/interfaces/IRewardsController.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


interface IRewardsController {
function claimAllRewards(address[] calldata assets, address to)
external
Expand Down
30 changes: 6 additions & 24 deletions src/proxy/EIP173Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@ interface ERC165 {
contract EIP173Proxy is Proxy {
// ////////////////////////// EVENTS ///////////////////////////////////////////////////////////////////////

event ProxyAdminTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
event ProxyAdminTransferred(address indexed previousAdmin, address indexed newAdmin);

// /////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////////////

constructor(
address implementationAddress,
address adminAddress,
bytes memory data
) payable {
constructor(address implementationAddress, address adminAddress, bytes memory data) payable {
_setImplementation(implementationAddress, data);
_setProxyAdmin(adminAddress);
}
Expand All @@ -44,9 +37,7 @@ contract EIP173Proxy is Proxy {
ERC165 implementation;
// solhint-disable-next-line security/no-inline-assembly
assembly {
implementation := sload(
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
)
implementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
}

// Technically this is not standard compliant as ERC-165 require 30,000 gas which that call cannot ensure
Expand All @@ -67,11 +58,7 @@ contract EIP173Proxy is Proxy {
_setImplementation(newImplementation, "");
}

function upgradeToAndCall(address newImplementation, bytes calldata data)
external
payable
onlyProxyAdmin
{
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable onlyProxyAdmin {
_setImplementation(newImplementation, data);
}

Expand All @@ -87,20 +74,15 @@ contract EIP173Proxy is Proxy {
function _proxyAdmin() internal view returns (address adminAddress) {
// solhint-disable-next-line security/no-inline-assembly
assembly {
adminAddress := sload(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
)
adminAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}

function _setProxyAdmin(address newAdmin) internal {
address previousAdmin = _proxyAdmin();
// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,
newAdmin
)
sstore(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, newAdmin)
}
emit ProxyAdminTransferred(previousAdmin, newAdmin);
}
Expand Down
46 changes: 10 additions & 36 deletions src/proxy/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ pragma solidity 0.8.20;
abstract contract Proxy {
// /////////////////////// EVENTS ///////////////////////////////////////////////////////////////////////////

event ProxyImplementationUpdated(
address indexed previousImplementation,
address indexed newImplementation
);
event ProxyImplementationUpdated(address indexed previousImplementation, address indexed newImplementation);

// ///////////////////// EXTERNAL ///////////////////////////////////////////////////////////////////////////

Expand All @@ -26,56 +23,33 @@ abstract contract Proxy {
function _fallback() internal {
// solhint-disable-next-line security/no-inline-assembly
assembly {
let implementationAddress := sload(
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
)
let implementationAddress := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
calldatacopy(0x0, 0x0, calldatasize())
let success := delegatecall(
gas(),
implementationAddress,
0x0,
calldatasize(),
0,
0
)
let success := delegatecall(gas(), implementationAddress, 0x0, calldatasize(), 0, 0)
let retSz := returndatasize()
returndatacopy(0, 0, retSz)
switch success
case 0 {
revert(0, retSz)
}
default {
return(0, retSz)
}
case 0 { revert(0, retSz) }
default { return(0, retSz) }
}
}

function _setImplementation(address newImplementation, bytes memory data)
internal
{
function _setImplementation(address newImplementation, bytes memory data) internal {
address previousImplementation;
// solhint-disable-next-line security/no-inline-assembly
assembly {
previousImplementation := sload(
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
)
previousImplementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
}

// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc,
newImplementation
)
sstore(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, newImplementation)
}

emit ProxyImplementationUpdated(
previousImplementation,
newImplementation
);
emit ProxyImplementationUpdated(previousImplementation, newImplementation);

if (data.length > 0) {
(bool success, ) = newImplementation.delegatecall(data);
(bool success,) = newImplementation.delegatecall(data);
if (!success) {
assembly {
// This assembly ensure the revert contains the exact string data
Expand Down
31 changes: 6 additions & 25 deletions src/vendor/EIP173Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


import "./Proxy.sol";

interface ERC165 {
Expand All @@ -12,18 +11,11 @@ interface ERC165 {
contract EIP173Proxy is Proxy {
// ////////////////////////// EVENTS ///////////////////////////////////////////////////////////////////////

event ProxyAdminTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
event ProxyAdminTransferred(address indexed previousAdmin, address indexed newAdmin);

// /////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////////////

constructor(
address implementationAddress,
address adminAddress,
bytes memory data
) payable {
constructor(address implementationAddress, address adminAddress, bytes memory data) payable {
_setImplementation(implementationAddress, data);
_setProxyAdmin(adminAddress);
}
Expand All @@ -45,9 +37,7 @@ contract EIP173Proxy is Proxy {
ERC165 implementation;
// solhint-disable-next-line security/no-inline-assembly
assembly {
implementation := sload(
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc
)
implementation := sload(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc)
}

// Technically this is not standard compliant as ERC-165 require 30,000 gas which that call cannot ensure
Expand All @@ -68,11 +58,7 @@ contract EIP173Proxy is Proxy {
_setImplementation(newImplementation, "");
}

function upgradeToAndCall(address newImplementation, bytes calldata data)
external
payable
onlyProxyAdmin
{
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable onlyProxyAdmin {
_setImplementation(newImplementation, data);
}

Expand All @@ -88,20 +74,15 @@ contract EIP173Proxy is Proxy {
function _proxyAdmin() internal view returns (address adminAddress) {
// solhint-disable-next-line security/no-inline-assembly
assembly {
adminAddress := sload(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
)
adminAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}

function _setProxyAdmin(address newAdmin) internal {
address previousAdmin = _proxyAdmin();
// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,
newAdmin
)
sstore(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103, newAdmin)
}
emit ProxyAdminTransferred(previousAdmin, newAdmin);
}
Expand Down
10 changes: 4 additions & 6 deletions src/vendor/EIP173ProxyWithReceive.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


import "./EIP173Proxy.sol";

///@notice Proxy implementing EIP173 for ownership management that accept ETH via receive
contract EIP173ProxyWithReceive is EIP173Proxy {
constructor(
address implementationAddress,
address ownerAddress,
bytes memory data
) payable EIP173Proxy(implementationAddress, ownerAddress, data) {}
constructor(address implementationAddress, address ownerAddress, bytes memory data)
payable
EIP173Proxy(implementationAddress, ownerAddress, data)
{}

receive() external payable override {}
}
4 changes: 1 addition & 3 deletions src/vendor/Proxied.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ abstract contract Proxied {
function _proxyAdmin() internal view returns (address adminAddress) {
// solhint-disable-next-line security/no-inline-assembly
assembly {
adminAddress := sload(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
)
adminAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}
}
Loading

0 comments on commit 9640327

Please sign in to comment.