From d5af9df57577ebfd81ddb4425bd8be0885607ff1 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Sat, 26 Nov 2022 13:39:51 -0600 Subject: [PATCH] add draft ERC4626Wrapper contracts --- abi/ERC4626Wrapper.json | 679 ++++++++++++++++++ abi/ERC4626WrapperInternal.json | 175 +++++ abi/IERC4626Wrapper.json | 624 ++++++++++++++++ abi/IERC4626WrapperInternal.json | 80 +++ .../token/ERC4626/wrapper/ERC4626Wrapper.sol | 56 ++ .../wrapper/ERC4626WrapperInternal.sol | 62 ++ .../token/ERC4626/wrapper/IERC4626Wrapper.sol | 13 + .../wrapper/IERC4626WrapperInternal.sol | 12 + 8 files changed, 1701 insertions(+) create mode 100644 abi/ERC4626Wrapper.json create mode 100644 abi/ERC4626WrapperInternal.json create mode 100644 abi/IERC4626Wrapper.json create mode 100644 abi/IERC4626WrapperInternal.json create mode 100644 contracts/token/ERC4626/wrapper/ERC4626Wrapper.sol create mode 100644 contracts/token/ERC4626/wrapper/ERC4626WrapperInternal.sol create mode 100644 contracts/token/ERC4626/wrapper/IERC4626Wrapper.sol create mode 100644 contracts/token/ERC4626/wrapper/IERC4626WrapperInternal.sol diff --git a/abi/ERC4626Wrapper.json b/abi/ERC4626Wrapper.json new file mode 100644 index 00000000..b3346c57 --- /dev/null +++ b/abi/ERC4626Wrapper.json @@ -0,0 +1,679 @@ +[ + { + "inputs": [], + "name": "AddressUtils__NotContract", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__ApproveFromZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__ApproveToZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__BurnExceedsBalance", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__BurnFromZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__InsufficientAllowance", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__MintToZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__TransferExceedsBalance", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__TransferFromZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__TransferToZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC4626Base__AllowanceExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "ERC4626Base__MaximumAmountExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "SafeERC20__OperationFailed", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "holder", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "asset", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "name": "convertToAssets", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "name": "convertToShares", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "maxDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "maxAssets", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "maxMint", + "outputs": [ + { + "internalType": "uint256", + "name": "maxShares", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "maxRedeem", + "outputs": [ + { + "internalType": "uint256", + "name": "maxShares", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "maxWithdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "maxAssets", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "name": "previewDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "name": "previewMint", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "name": "previewRedeem", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "name": "previewWithdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "redeem", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "holder", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "withdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/abi/ERC4626WrapperInternal.json b/abi/ERC4626WrapperInternal.json new file mode 100644 index 00000000..f5e72985 --- /dev/null +++ b/abi/ERC4626WrapperInternal.json @@ -0,0 +1,175 @@ +[ + { + "inputs": [], + "name": "ERC20Base__ApproveFromZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__ApproveToZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__BurnExceedsBalance", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__BurnFromZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__InsufficientAllowance", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__MintToZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__TransferExceedsBalance", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__TransferFromZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC20Base__TransferToZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ERC4626Base__AllowanceExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "ERC4626Base__MaximumAmountExceeded", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + } +] diff --git a/abi/IERC4626Wrapper.json b/abi/IERC4626Wrapper.json new file mode 100644 index 00000000..5b597721 --- /dev/null +++ b/abi/IERC4626Wrapper.json @@ -0,0 +1,624 @@ +[ + { + "inputs": [], + "name": "ERC4626Base__AllowanceExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "ERC4626Base__MaximumAmountExceeded", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "holder", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "asset", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "name": "convertToAssets", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "name": "convertToShares", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "maxDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "maxAssets", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "maxMint", + "outputs": [ + { + "internalType": "uint256", + "name": "maxShares", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "maxRedeem", + "outputs": [ + { + "internalType": "uint256", + "name": "maxShares", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "maxWithdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "maxAssets", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "name": "previewDeposit", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "name": "previewMint", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "name": "previewRedeem", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "name": "previewWithdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "redeem", + "outputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "holder", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "assetAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "withdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "shareAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/abi/IERC4626WrapperInternal.json b/abi/IERC4626WrapperInternal.json new file mode 100644 index 00000000..086bd195 --- /dev/null +++ b/abi/IERC4626WrapperInternal.json @@ -0,0 +1,80 @@ +[ + { + "inputs": [], + "name": "ERC4626Base__AllowanceExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "ERC4626Base__MaximumAmountExceeded", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + } +] diff --git a/contracts/token/ERC4626/wrapper/ERC4626Wrapper.sol b/contracts/token/ERC4626/wrapper/ERC4626Wrapper.sol new file mode 100644 index 00000000..8ef092f9 --- /dev/null +++ b/contracts/token/ERC4626/wrapper/ERC4626Wrapper.sol @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.8; + +import { ERC4626Base } from '../base/ERC4626Base.sol'; +import { ERC4626BaseInternal } from '../base/ERC4626BaseInternal.sol'; +import { ERC4626WrapperInternal } from './ERC4626WrapperInternal.sol'; + +/** + * @title ERC4626 functions implemented for 1:1 token wrappers + */ +contract ERC4626Wrapper is ERC4626Base, ERC4626WrapperInternal { + function _convertToAssets( + uint256 shareAmount + ) + internal + view + override(ERC4626BaseInternal, ERC4626WrapperInternal) + returns (uint256 assetAmount) + { + assetAmount = super._convertToAssets(shareAmount); + } + + function _convertToShares( + uint256 assetAmount + ) + internal + view + override(ERC4626BaseInternal, ERC4626WrapperInternal) + returns (uint256 shareAmount) + { + shareAmount = super._convertToAssets(assetAmount); + } + + function _previewMint( + uint256 shareAmount + ) + internal + view + override(ERC4626BaseInternal, ERC4626WrapperInternal) + returns (uint256 assetAmount) + { + assetAmount = super._previewMint(shareAmount); + } + + function _previewWithdraw( + uint256 assetAmount + ) + internal + view + override(ERC4626BaseInternal, ERC4626WrapperInternal) + returns (uint256 shareAmount) + { + shareAmount = super._previewMint(assetAmount); + } +} diff --git a/contracts/token/ERC4626/wrapper/ERC4626WrapperInternal.sol b/contracts/token/ERC4626/wrapper/ERC4626WrapperInternal.sol new file mode 100644 index 00000000..0f6b1c2a --- /dev/null +++ b/contracts/token/ERC4626/wrapper/ERC4626WrapperInternal.sol @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.8; + +import { ERC4626BaseInternal } from '../base/ERC4626BaseInternal.sol'; +import { IERC4626WrapperInternal } from './IERC4626WrapperInternal.sol'; + +/** + * @title ERC4626 internal functions implemented for 1:1 token wrappers + */ +contract ERC4626WrapperInternal is + ERC4626BaseInternal, + IERC4626WrapperInternal +{ + /** + * @inheritdoc ERC4626BaseInternal + * @dev assets and shares are pegged 1:1, so this override is made for gas savings + */ + function _totalAssets() internal view override returns (uint256) { + return _totalSupply(); + } + + /** + * @inheritdoc ERC4626BaseInternal + * @dev assets and shares are pegged 1:1, so this override is made for gas savings + */ + function _convertToAssets( + uint256 shareAmount + ) internal view virtual override returns (uint256 assetAmount) { + assetAmount = shareAmount; + } + + /** + * @inheritdoc ERC4626BaseInternal + * @dev assets and shares are pegged 1:1, so this override is made for gas savings + */ + function _convertToShares( + uint256 assetAmount + ) internal view virtual override returns (uint256 shareAmount) { + shareAmount = assetAmount; + } + + /** + * @inheritdoc ERC4626BaseInternal + * @dev assets and shares are pegged 1:1, so this function acts as an alias of _previewDeposit + */ + function _previewMint( + uint256 shareAmount + ) internal view virtual override returns (uint256 assetAmount) { + assetAmount = _previewDeposit(shareAmount); + } + + /** + * @inheritdoc ERC4626BaseInternal + * @dev assets and shares are pegged 1:1, so this function acts as an alias of _previewRedeem + */ + function _previewWithdraw( + uint256 assetAmount + ) internal view virtual override returns (uint256 shareAmount) { + shareAmount = _previewRedeem(assetAmount); + } +} diff --git a/contracts/token/ERC4626/wrapper/IERC4626Wrapper.sol b/contracts/token/ERC4626/wrapper/IERC4626Wrapper.sol new file mode 100644 index 00000000..bcac7392 --- /dev/null +++ b/contracts/token/ERC4626/wrapper/IERC4626Wrapper.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.8; + +import { IERC4626Base } from '../base/IERC4626Base.sol'; +import { IERC4626WrapperInternal } from './IERC4626WrapperInternal.sol'; + +/** + * @title ERC4626 wrapper interface + */ +interface IERC4626Wrapper is IERC4626Base, IERC4626WrapperInternal { + +} diff --git a/contracts/token/ERC4626/wrapper/IERC4626WrapperInternal.sol b/contracts/token/ERC4626/wrapper/IERC4626WrapperInternal.sol new file mode 100644 index 00000000..ab4f6cae --- /dev/null +++ b/contracts/token/ERC4626/wrapper/IERC4626WrapperInternal.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.8; + +import { IERC4626BaseInternal } from '../base/IERC4626BaseInternal.sol'; + +/** + * @title ERC4626 wrapper interface + */ +interface IERC4626WrapperInternal is IERC4626BaseInternal { + +}