编译器
0.8.23+commit.f704f362
文件 1 的 13:Constants.sol
pragma solidity >=0.5.0;
import { ICbETH } from "interfaces/external/coinbase/ICbETH.sol";
import { ISfrxETH } from "interfaces/external/frax/ISfrxETH.sol";
import { IStETH } from "interfaces/external/lido/IStETH.sol";
import { IRETH } from "interfaces/external/rocketPool/IRETH.sol";
bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b;
bytes32 constant TRANSMUTER_STORAGE_POSITION = 0xc1f2f38dde3351ac0a64934139e816326caa800303a1235dc53707d0de05d8bd;
bytes32 constant IMPLEMENTATION_STORAGE_POSITION = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
uint256 constant BASE_6 = 1e6;
uint256 constant BASE_8 = 1e8;
uint256 constant BASE_9 = 1e9;
uint256 constant BASE_12 = 1e12;
uint256 constant BPS = 1e14;
uint256 constant BASE_18 = 1e18;
uint256 constant HALF_BASE_27 = 1e27 / 2;
uint256 constant BASE_27 = 1e27;
uint256 constant BASE_36 = 1e36;
uint256 constant MAX_BURN_FEE = 999_000_000;
uint256 constant MAX_MINT_FEE = BASE_12 - 1;
uint8 constant NOT_ENTERED = 1;
uint8 constant ENTERED = 2;
address constant PERMIT_2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
address constant ONE_INCH_ROUTER = 0x1111111254EEB25477B68fb85Ed929f73A960582;
address constant AGEUR = 0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8;
ICbETH constant CBETH = ICbETH(0xBe9895146f7AF43049ca1c1AE358B0541Ea49704);
IRETH constant RETH = IRETH(0xae78736Cd615f374D3085123A210448E74Fc6393);
IStETH constant STETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
ISfrxETH constant SFRXETH = ISfrxETH(0xac3E018457B222d93114458476f3E3416Abbe38F);
文件 2 的 13:DiamondProxy.sol
pragma solidity ^0.8.19;
import { LibDiamond } from "./libraries/LibDiamond.sol";
import { LibStorage as s } from "./libraries/LibStorage.sol";
import "../utils/Errors.sol";
import "./Storage.sol";
contract DiamondProxy {
constructor(FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) payable {
LibDiamond.diamondCut(_diamondCut, _init, _calldata);
}
fallback() external payable {
DiamondStorage storage ds = s.diamondStorage();
address facetAddress = ds.selectorInfo[msg.sig].facetAddress;
if (facetAddress == address(0)) {
revert FunctionNotFound(msg.sig);
}
assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize())
let result := delegatecall(gas(), facetAddress, ptr, calldatasize(), 0, 0)
let size := returndatasize()
returndatacopy(ptr, 0, size)
switch result
case 0 {
revert(ptr, size)
}
default {
return(ptr, size)
}
}
}
}
文件 3 的 13:Errors.sol
pragma solidity ^0.8.19;
error AlreadyAdded();
error CannotAddFunctionToDiamondThatAlreadyExists(bytes4 _selector);
error CannotAddSelectorsToZeroAddress(bytes4[] _selectors);
error CannotRemoveFunctionThatDoesNotExist(bytes4 _selector);
error CannotRemoveImmutableFunction(bytes4 _selector);
error CannotReplaceFunctionsFromFacetWithZeroAddress(bytes4[] _selectors);
error CannotReplaceFunctionThatDoesNotExists(bytes4 _selector);
error CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(bytes4 _selector);
error CannotReplaceImmutableFunction(bytes4 _selector);
error ContractHasNoCode();
error FunctionNotFound(bytes4 _functionSelector);
error IncorrectFacetCutAction(uint8 _action);
error InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata);
error InvalidChainlinkRate();
error InvalidLengths();
error InvalidNegativeFees();
error InvalidOracleType();
error InvalidParam();
error InvalidParams();
error InvalidRate();
error InvalidSwap();
error InvalidTokens();
error ManagerHasAssets();
error NoSelectorsProvidedForFacetForCut(address _facetAddress);
error NotAllowed();
error NotCollateral();
error NotGovernor();
error NotGovernorOrGuardian();
error NotTrusted();
error NotWhitelisted();
error OneInchSwapFailed();
error OracleUpdateFailed();
error Paused();
error ReentrantCall();
error RemoveFacetAddressMustBeZeroAddress(address _facetAddress);
error TooBigAmountIn();
error TooLate();
error TooSmallAmountOut();
error ZeroAddress();
error ZeroAmount();
文件 4 的 13:IAccessControlManager.sol
pragma solidity >=0.5.0;
interface IAccessControlManager {
function isGovernor(address admin) external view returns (bool);
function isGovernorOrGuardian(address admin) external view returns (bool);
}
文件 5 的 13:IAgToken.sol
pragma solidity >=0.5.0;
import { IERC20 } from "oz/token/ERC20/IERC20.sol";
interface IAgToken is IERC20 {
function mint(address account, uint256 amount) external;
function burnFrom(uint256 amount, address burner, address sender) external;
function burnSelf(uint256 amount, address burner) external;
function addMinter(address minter) external;
function removeMinter(address minter) external;
function setTreasury(address _treasury) external;
function isMinter(address minter) external view returns (bool);
function decimals() external view returns (uint8);
}
文件 6 的 13:ICbETH.sol
pragma solidity >=0.5.0;
interface ICbETH {
function exchangeRate() external view returns (uint256);
}
文件 7 的 13:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 8 的 13:IRETH.sol
pragma solidity >=0.5.0;
interface IRETH {
function getExchangeRate() external view returns (uint256);
}
文件 9 的 13:ISfrxETH.sol
pragma solidity >=0.5.0;
interface ISfrxETH {
function pricePerShare() external view returns (uint256);
}
文件 10 的 13:IStETH.sol
pragma solidity >=0.5.0;
interface IStETH {
function getPooledEthByShares(uint256 _sharesAmount) external view returns (uint256);
function submit(address) external payable returns (uint256);
function getSharesByPooledEth(uint256 _ethAmount) external view returns (uint256);
}
文件 11 的 13:LibDiamond.sol
pragma solidity ^0.8.0;
import { LibStorage as s } from "./LibStorage.sol";
import "../../utils/Errors.sol";
import "../Storage.sol";
library LibDiamond {
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
function isGovernor(address admin) internal view returns (bool) {
return s.diamondStorage().accessControlManager.isGovernor(admin);
}
function isGovernorOrGuardian(address admin) internal view returns (bool) {
return s.diamondStorage().accessControlManager.isGovernorOrGuardian(admin);
}
function diamondCut(FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) internal {
uint256 diamondCutLength = _diamondCut.length;
for (uint256 facetIndex; facetIndex < diamondCutLength; facetIndex++) {
bytes4[] memory functionSelectors = _diamondCut[facetIndex].functionSelectors;
address facetAddress = _diamondCut[facetIndex].facetAddress;
if (functionSelectors.length == 0) {
revert NoSelectorsProvidedForFacetForCut(facetAddress);
}
FacetCutAction action = _diamondCut[facetIndex].action;
if (action == FacetCutAction.Add) {
_addFunctions(facetAddress, functionSelectors);
} else if (action == FacetCutAction.Replace) {
_replaceFunctions(facetAddress, functionSelectors);
} else if (action == FacetCutAction.Remove) {
_removeFunctions(facetAddress, functionSelectors);
}
}
emit DiamondCut(_diamondCut, _init, _calldata);
_initializeDiamondCut(_init, _calldata);
}
function _initializeDiamondCut(address _init, bytes memory _calldata) private {
if (_init == address(0)) {
return;
}
_enforceHasContractCode(_init);
(bool success, bytes memory error) = _init.delegatecall(_calldata);
if (!success) {
if (error.length > 0) {
assembly {
let returndata_size := mload(error)
revert(add(32, error), returndata_size)
}
} else {
revert InitializationFunctionReverted(_init, _calldata);
}
}
}
function _addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
if (_facetAddress == address(0)) {
revert CannotAddSelectorsToZeroAddress(_functionSelectors);
}
DiamondStorage storage ds = s.diamondStorage();
uint16 selectorCount = uint16(ds.selectors.length);
_enforceHasContractCode(_facetAddress);
uint256 functionSelectorsLength = _functionSelectors.length;
for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorInfo[selector].facetAddress;
if (oldFacetAddress != address(0)) {
revert CannotAddFunctionToDiamondThatAlreadyExists(selector);
}
ds.selectorInfo[selector] = FacetInfo(_facetAddress, selectorCount);
ds.selectors.push(selector);
selectorCount++;
}
}
function _replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
DiamondStorage storage ds = s.diamondStorage();
if (_facetAddress == address(0)) {
revert CannotReplaceFunctionsFromFacetWithZeroAddress(_functionSelectors);
}
_enforceHasContractCode(_facetAddress);
uint256 functionSelectorsLength = _functionSelectors.length;
for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds.selectorInfo[selector].facetAddress;
if (oldFacetAddress == address(this)) {
revert CannotReplaceImmutableFunction(selector);
}
if (oldFacetAddress == _facetAddress) {
revert CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet(selector);
}
if (oldFacetAddress == address(0)) {
revert CannotReplaceFunctionThatDoesNotExists(selector);
}
ds.selectorInfo[selector].facetAddress = _facetAddress;
}
}
function _removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) private {
DiamondStorage storage ds = s.diamondStorage();
uint256 selectorCount = ds.selectors.length;
if (_facetAddress != address(0)) {
revert RemoveFacetAddressMustBeZeroAddress(_facetAddress);
}
uint256 functionSelectorsLength = _functionSelectors.length;
for (uint256 selectorIndex; selectorIndex < functionSelectorsLength; selectorIndex++) {
bytes4 selector = _functionSelectors[selectorIndex];
FacetInfo memory oldFacetAddressAndSelectorPosition = ds.selectorInfo[selector];
if (oldFacetAddressAndSelectorPosition.facetAddress == address(0)) {
revert CannotRemoveFunctionThatDoesNotExist(selector);
}
if (oldFacetAddressAndSelectorPosition.facetAddress == address(this)) {
revert CannotRemoveImmutableFunction(selector);
}
selectorCount--;
if (oldFacetAddressAndSelectorPosition.selectorPosition != selectorCount) {
bytes4 lastSelector = ds.selectors[selectorCount];
ds.selectors[oldFacetAddressAndSelectorPosition.selectorPosition] = lastSelector;
ds.selectorInfo[lastSelector].selectorPosition = oldFacetAddressAndSelectorPosition.selectorPosition;
}
ds.selectors.pop();
delete ds.selectorInfo[selector];
}
}
function _enforceHasContractCode(address _contract) private view {
uint256 contractSize;
assembly {
contractSize := extcodesize(_contract)
}
if (contractSize == 0) {
revert ContractHasNoCode();
}
}
}
文件 12 的 13:LibStorage.sol
pragma solidity ^0.8.19;
import "../../utils/Constants.sol";
import { DiamondStorage, ImplementationStorage, TransmuterStorage } from "../Storage.sol";
library LibStorage {
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
function transmuterStorage() internal pure returns (TransmuterStorage storage ts) {
bytes32 position = TRANSMUTER_STORAGE_POSITION;
assembly {
ts.slot := position
}
}
function implementationStorage() internal pure returns (ImplementationStorage storage ims) {
bytes32 position = IMPLEMENTATION_STORAGE_POSITION;
assembly {
ims.slot := position
}
}
}
文件 13 的 13:Storage.sol
pragma solidity ^0.8.19;
import { IERC20 } from "oz/token/ERC20/IERC20.sol";
import { IAccessControlManager } from "interfaces/IAccessControlManager.sol";
import { IAgToken } from "interfaces/IAgToken.sol";
enum FacetCutAction {
Add,
Replace,
Remove
}
enum ManagerType {
EXTERNAL
}
enum ActionType {
Mint,
Burn,
Redeem
}
enum TrustedType {
Updater,
Seller
}
enum QuoteType {
MintExactInput,
MintExactOutput,
BurnExactInput,
BurnExactOutput
}
enum OracleReadType {
CHAINLINK_FEEDS,
EXTERNAL,
NO_ORACLE,
STABLE,
WSTETH,
CBETH,
RETH,
SFRXETH,
PYTH,
MAX,
MORPHO_ORACLE
}
enum OracleQuoteType {
UNIT,
TARGET
}
enum WhitelistType {
BACKED
}
struct Permit2Details {
address to;
uint256 nonce;
bytes signature;
}
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
struct Facet {
address facetAddress;
bytes4[] functionSelectors;
}
struct FacetInfo {
address facetAddress;
uint16 selectorPosition;
}
struct DiamondStorage {
bytes4[] selectors;
mapping(bytes4 => FacetInfo) selectorInfo;
IAccessControlManager accessControlManager;
}
struct ImplementationStorage {
address implementation;
}
struct ManagerStorage {
IERC20[] subCollaterals;
bytes config;
}
struct Collateral {
uint8 isManaged;
uint8 isMintLive;
uint8 isBurnLive;
uint8 decimals;
uint8 onlyWhitelisted;
uint216 normalizedStables;
uint64[] xFeeMint;
int64[] yFeeMint;
uint64[] xFeeBurn;
int64[] yFeeBurn;
bytes oracleConfig;
bytes whitelistData;
ManagerStorage managerData;
uint256 stablecoinCap;
}
struct TransmuterStorage {
IAgToken agToken;
uint8 isRedemptionLive;
uint8 statusReentrant;
uint128 normalizedStables;
uint128 normalizer;
address[] collateralList;
uint64[] xRedemptionCurve;
int64[] yRedemptionCurve;
mapping(address => Collateral) collaterals;
mapping(address => uint256) isTrusted;
mapping(address => uint256) isSellerTrusted;
mapping(WhitelistType => mapping(address => uint256)) isWhitelistedForType;
}
{
"compilationTarget": {
"contracts/transmuter/DiamondProxy.sol": "DiamondProxy"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": [
":@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
":@prb/test/=lib/prb-math/lib/prb-test/src/",
":contracts/=contracts/",
":ds-test/=lib/forge-std/lib/ds-test/src/",
":erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
":forge-std/=lib/forge-std/src/",
":interfaces/=contracts/interfaces/",
":lz/=lib/utils/lib/solidity-examples/contracts/",
":mock/=test/mock/",
":openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":oz-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
":oz/=lib/openzeppelin-contracts/contracts/",
":prb-math/=lib/prb-math/src/",
":prb-test/=lib/prb-math/lib/prb-test/src/",
":prb/math/=lib/prb-math/src/",
":solidity-examples/=lib/utils/lib/solidity-examples/contracts/",
":solidity-stringutils/=lib/solidity-stringutils/",
":src/=lib/prb-math/src/",
":stringutils/=lib/solidity-stringutils/",
":test/=test/",
":utils/=lib/utils/"
],
"viaIR": true
}
[{"inputs":[{"components":[{"internalType":"address","name":"facetAddress","type":"address"},{"internalType":"enum FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"functionSelectors","type":"bytes4[]"}],"internalType":"struct FacetCut[]","name":"_diamondCut","type":"tuple[]"},{"internalType":"address","name":"_init","type":"address"},{"internalType":"bytes","name":"_calldata","type":"bytes"}],"stateMutability":"payable","type":"constructor"},{"inputs":[{"internalType":"bytes4","name":"_selector","type":"bytes4"}],"name":"CannotAddFunctionToDiamondThatAlreadyExists","type":"error"},{"inputs":[{"internalType":"bytes4[]","name":"_selectors","type":"bytes4[]"}],"name":"CannotAddSelectorsToZeroAddress","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_selector","type":"bytes4"}],"name":"CannotRemoveFunctionThatDoesNotExist","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_selector","type":"bytes4"}],"name":"CannotRemoveImmutableFunction","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_selector","type":"bytes4"}],"name":"CannotReplaceFunctionThatDoesNotExists","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_selector","type":"bytes4"}],"name":"CannotReplaceFunctionWithTheSameFunctionFromTheSameFacet","type":"error"},{"inputs":[{"internalType":"bytes4[]","name":"_selectors","type":"bytes4[]"}],"name":"CannotReplaceFunctionsFromFacetWithZeroAddress","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_selector","type":"bytes4"}],"name":"CannotReplaceImmutableFunction","type":"error"},{"inputs":[],"name":"ContractHasNoCode","type":"error"},{"inputs":[{"internalType":"bytes4","name":"_functionSelector","type":"bytes4"}],"name":"FunctionNotFound","type":"error"},{"inputs":[{"internalType":"address","name":"_initializationContractAddress","type":"address"},{"internalType":"bytes","name":"_calldata","type":"bytes"}],"name":"InitializationFunctionReverted","type":"error"},{"inputs":[{"internalType":"address","name":"_facetAddress","type":"address"}],"name":"NoSelectorsProvidedForFacetForCut","type":"error"},{"inputs":[{"internalType":"address","name":"_facetAddress","type":"address"}],"name":"RemoveFacetAddressMustBeZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"facetAddress","type":"address"},{"internalType":"enum FacetCutAction","name":"action","type":"uint8"},{"internalType":"bytes4[]","name":"functionSelectors","type":"bytes4[]"}],"indexed":false,"internalType":"struct FacetCut[]","name":"_diamondCut","type":"tuple[]"},{"indexed":false,"internalType":"address","name":"_init","type":"address"},{"indexed":false,"internalType":"bytes","name":"_calldata","type":"bytes"}],"name":"DiamondCut","type":"event"},{"stateMutability":"payable","type":"fallback"}]