From 23110358341515041ee9abafdc339445feeac5cc Mon Sep 17 00:00:00 2001 From: gretzke Date: Tue, 24 Sep 2024 04:04:59 +0200 Subject: [PATCH 1/3] use calldata instead of memory --- docs/autogen/src/src/Vault.sol/contract.Vault.md | 4 ++-- docs/autogen/src/src/interface/IVault.sol/interface.IVault.md | 4 ++-- src/Vault.sol | 2 +- src/interface/IVault.sol | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/autogen/src/src/Vault.sol/contract.Vault.md b/docs/autogen/src/src/Vault.sol/contract.Vault.md index 28a108a..f103c70 100644 --- a/docs/autogen/src/src/Vault.sol/contract.Vault.md +++ b/docs/autogen/src/src/Vault.sol/contract.Vault.md @@ -1,5 +1,5 @@ # Vault -[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/d197f8ef7c2bfcdd8eeb0e4fc546c998a12a18f4/src/Vault.sol) +[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/3fb7671f959cafc2399d81b93557d37c7898477b/src/Vault.sol) **Inherits:** [IVault](/src/interface/IVault.sol/interface.IVault.md), AccessControl, [Multicall](/src/lib/Multicall.sol/abstract.Multicall.md) @@ -212,7 +212,7 @@ Deposits collateral into a pocket using a permit2 signature transfer ```solidity -function depositWithPermit(uint96 pocketId, uint256 amount, IPermit2.PermitTransferFrom memory permit, bytes calldata signature) +function depositWithPermit(uint96 pocketId, uint256 amount, IPermit2.PermitTransferFrom calldata permit, bytes calldata signature) external returns (uint256 shares); ``` diff --git a/docs/autogen/src/src/interface/IVault.sol/interface.IVault.md b/docs/autogen/src/src/interface/IVault.sol/interface.IVault.md index 8de5b7a..585ecc3 100644 --- a/docs/autogen/src/src/interface/IVault.sol/interface.IVault.md +++ b/docs/autogen/src/src/interface/IVault.sol/interface.IVault.md @@ -1,5 +1,5 @@ # IVault -[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/6bc13f590e0d259edfc7844b2201ce75ef760a67/src/interface/IVault.sol) +[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/3fb7671f959cafc2399d81b93557d37c7898477b/src/interface/IVault.sol) **Inherits:** IAccessControl, [IMulticall](/src/interface/IMulticall.sol/interface.IMulticall.md), [IVersioned](/src/interface/IVersioned.sol/interface.IVersioned.md) @@ -144,7 +144,7 @@ Deposits collateral into a pocket using a permit2 signature transfer ```solidity -function depositWithPermit(uint96 pocketId, uint256 collateralAmount, IPermit2.PermitTransferFrom memory permit, bytes calldata signature) +function depositWithPermit(uint96 pocketId, uint256 collateralAmount, IPermit2.PermitTransferFrom calldata permit, bytes calldata signature) external returns (uint256 shares); ``` diff --git a/src/Vault.sol b/src/Vault.sol index 85931f0..1f79bf0 100644 --- a/src/Vault.sol +++ b/src/Vault.sol @@ -143,7 +143,7 @@ contract Vault is IVault, AccessControl, Multicall { } /// @inheritdoc IVault - function depositWithPermit(uint96 pocketId, uint256 amount, IPermit2.PermitTransferFrom memory permit, bytes calldata signature) + function depositWithPermit(uint96 pocketId, uint256 amount, IPermit2.PermitTransferFrom calldata permit, bytes calldata signature) external returns (uint256 shares) { diff --git a/src/interface/IVault.sol b/src/interface/IVault.sol index 19455a2..edbacba 100644 --- a/src/interface/IVault.sol +++ b/src/interface/IVault.sol @@ -161,7 +161,7 @@ interface IVault is IAccessControl, IMulticall, IVersioned { /// @param permit The permit data /// @param signature The signature /// @return shares The amount of shares minted by the pocket - function depositWithPermit(uint96 pocketId, uint256 collateralAmount, IPermit2.PermitTransferFrom memory permit, bytes calldata signature) + function depositWithPermit(uint96 pocketId, uint256 collateralAmount, IPermit2.PermitTransferFrom calldata permit, bytes calldata signature) external returns (uint256 shares); From 495451d159fb10c010b98bdc7bc685a1a59dc8d3 Mon Sep 17 00:00:00 2001 From: gretzke Date: Tue, 24 Sep 2024 04:09:06 +0200 Subject: [PATCH 2/3] mark assembly block as memory safe --- src/lib/Multicall.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Multicall.sol b/src/lib/Multicall.sol index fa01afd..745b5c0 100644 --- a/src/lib/Multicall.sol +++ b/src/lib/Multicall.sol @@ -14,7 +14,7 @@ abstract contract Multicall is IMulticall { if (!success) { // bubble up the revert reason - assembly { + assembly ("memory-safe") { revert(add(result, 0x20), mload(result)) } } From c6e2e51d5b945da0fd53c54be302f1db634bd9a7 Mon Sep 17 00:00:00 2001 From: gretzke Date: Tue, 24 Sep 2024 04:23:04 +0200 Subject: [PATCH 3/3] approve once in initializer --- .../pockets/AaveV3Pocket.sol/contract.AaveV3Pocket.md | 9 ++++++++- .../src/pockets/BasePocket.sol/contract.BasePocket.md | 4 ++-- src/pockets/AaveV3Pocket.sol | 5 ++++- src/pockets/BasePocket.sol | 2 +- test/pockets/AaveV3Pocket.t.sol | 6 ++++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/autogen/src/src/pockets/AaveV3Pocket.sol/contract.AaveV3Pocket.md b/docs/autogen/src/src/pockets/AaveV3Pocket.sol/contract.AaveV3Pocket.md index 13f2d04..b1e3fe0 100644 --- a/docs/autogen/src/src/pockets/AaveV3Pocket.sol/contract.AaveV3Pocket.md +++ b/docs/autogen/src/src/pockets/AaveV3Pocket.sol/contract.AaveV3Pocket.md @@ -1,5 +1,5 @@ # AaveV3Pocket -[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/6bc13f590e0d259edfc7844b2201ce75ef760a67/src/pockets/AaveV3Pocket.sol) +[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/495451d159fb10c010b98bdc7bc685a1a59dc8d3/src/pockets/AaveV3Pocket.sol) **Inherits:** [BasePocket](/src/pockets/BasePocket.sol/contract.BasePocket.md), [IAaveV3Pocket](/src/interface/pockets/IAaveV3Pocket.sol/interface.IAaveV3Pocket.md) @@ -23,6 +23,13 @@ IPool public immutable POOL; constructor(address vault_, address underlyingToken_, address overlyingToken_, address aavePool) BasePocket(vault_, underlyingToken_, overlyingToken_); ``` +### initialize + + +```solidity +function initialize() public override initializer; +``` + ### _onDeposit *deposits underlying token into Aave v3, aTokens are deposited into this pocket* diff --git a/docs/autogen/src/src/pockets/BasePocket.sol/contract.BasePocket.md b/docs/autogen/src/src/pockets/BasePocket.sol/contract.BasePocket.md index 854af30..0a0b906 100644 --- a/docs/autogen/src/src/pockets/BasePocket.sol/contract.BasePocket.md +++ b/docs/autogen/src/src/pockets/BasePocket.sol/contract.BasePocket.md @@ -1,5 +1,5 @@ # BasePocket -[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/6bc13f590e0d259edfc7844b2201ce75ef760a67/src/pockets/BasePocket.sol) +[Git Source](https://github.com/cryptexfinance/tcapv2.0/blob/495451d159fb10c010b98bdc7bc685a1a59dc8d3/src/pockets/BasePocket.sol) **Inherits:** [IPocket](/src/interface/pockets/IPocket.sol/interface.IPocket.md), Initializable @@ -50,7 +50,7 @@ constructor(address vault_, address underlyingToken_, address overlyingToken_); ```solidity -function initialize() public initializer; +function initialize() public virtual initializer; ``` ### _getBasePocketStorage diff --git a/src/pockets/AaveV3Pocket.sol b/src/pockets/AaveV3Pocket.sol index 6aea13f..4b1ff18 100644 --- a/src/pockets/AaveV3Pocket.sol +++ b/src/pockets/AaveV3Pocket.sol @@ -15,9 +15,12 @@ contract AaveV3Pocket is BasePocket, IAaveV3Pocket { POOL = IPool(aavePool); } + function initialize() public override initializer { + UNDERLYING_TOKEN.approve(address(POOL), type(uint256).max); + } + /// @dev deposits underlying token into Aave v3, aTokens are deposited into this pocket function _onDeposit(uint256 amountUnderlying) internal override returns (uint256 amountOverlying) { - UNDERLYING_TOKEN.approve(address(POOL), amountUnderlying); POOL.deposit(address(UNDERLYING_TOKEN), amountUnderlying, address(this), 0); return amountUnderlying; } diff --git a/src/pockets/BasePocket.sol b/src/pockets/BasePocket.sol index 100fd0c..907aa29 100644 --- a/src/pockets/BasePocket.sol +++ b/src/pockets/BasePocket.sol @@ -32,7 +32,7 @@ contract BasePocket is IPocket, Initializable { _disableInitializers(); } - function initialize() public initializer {} + function initialize() public virtual initializer {} function _getBasePocketStorage() private pure returns (BasePocketStorage storage $) { assembly { diff --git a/test/pockets/AaveV3Pocket.t.sol b/test/pockets/AaveV3Pocket.t.sol index ff7f6f2..bc88fab 100644 --- a/test/pockets/AaveV3Pocket.t.sol +++ b/test/pockets/AaveV3Pocket.t.sol @@ -43,8 +43,10 @@ abstract contract Uninitialized is Test, TestHelpers, AaveV3PocketDeployer { abstract contract Initialized is Uninitialized { function setUp() public virtual override { super.setUp(); - address admin = address(this); - deployAaveV3PocketTransparent(admin, address(this), address(underlyingToken), address(overlyingAToken), POOL_MAINNET); + if (forked) { + address admin = address(this); + deployAaveV3PocketTransparent(admin, address(this), address(underlyingToken), address(overlyingAToken), POOL_MAINNET); + } } }