Skip to content

Commit

Permalink
test: finish initial draft of tree
Browse files Browse the repository at this point in the history
  • Loading branch information
pakim249CAL committed Aug 14, 2023
1 parent 3e67c80 commit 672fe44
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 10 deletions.
6 changes: 3 additions & 3 deletions test/forge/tree/BaseBulker.tree
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
└── multicall(uint256 deadline, bytes[] calldata data) returns (bytes[] memory)
├── locks initiator
├── if deadline <= block.timestamp
| └── revert DEADLINE_EXPIRED
└── revert DEADLINE_EXPIRED
├── if deadline > block.timestamp
| └── do _multicall(data)
└── do _multicall(data)
└── return results from _multicall

.
└── callBulker(address bulker, bytes[] calldata data)
├── if bulker == address(0)
| └── revert ZERO_ADDRESS
└── revert ZERO_ADDRESS
└── call multicall(block.timestamp, data) on bulker
14 changes: 7 additions & 7 deletions test/forge/tree/BaseSelfMulticall.tree
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
└── _multicall(bytes[] memory data) returns (bytes[] memory results)
├── for i in range [0, data.length - 1]
│ ├── address(this) is delegate called with data[i]
| ├── if returned bool is failure
| | ├── if return data length < 68
| | | └── revert without message
| | └── if return data length >= 68
| | └── revert with abi decoded string message
| └── if returned bool is success
| └── add result to results array (Not testable)
├── if returned bool is failure
├── if return data length < 68
└── revert without message
└── if return data length >= 68
└── revert with abi decoded string message
└── if returned bool is success
└── add result to results array (Not testable)
└── return results from each delegatecall
24 changes: 24 additions & 0 deletions test/forge/tree/ERC20Bulker.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.
└── transfer(address asset, address recipient, uint256 amount)
├── if recipient == address(0)
│ └── revert ZERO_ADDRESS
├── if recipient == address(this)
│ └── revert BULKER_ADDRESS
├── amount is set to min of balance(bulker) and amount
│ ├── if amount == 0
│ │ └── revert ZERO_AMOUNT
│ └── if balance(bulker) == 0
│ └── revert ZERO_AMOUNT
└── recipient is transferred `amount` of `asset`

.
└── approve2(address asset, uint256 amount, uint256 deadline, Signature calldata signature)
├── if amount == 0
│ └── revert ZERO_AMOUNT
└── use simplePermit2 from uniswap lib on asset to approve bulker

.
└── transferFrom2(address asset, uint256 amount)
├── if amount == 0
│ └── revert ZERO_AMOUNT
└── use transferFrom2 from uniswap lib on asset to transfer tokens from initiator to bulker
3 changes: 3 additions & 0 deletions test/forge/tree/EVMBulker.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.
└── constructor(address morpho)
└── call constructor of MorphoBulker
87 changes: 87 additions & 0 deletions test/forge/tree/MorphoBulker.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
.
└── constructor(address morpho)
├── if morpho == address(0)
│ └── revert ZERO_ADDRESS
└── set MORPHO to IMorpho(morpho)

.
└── onMorphoSupply(uint256, bytes calldata data)
├── internal call checkInitiator (BaseCallbackReceiver)
└── internal call multicall

.
└── onMorphoSupplyCollateral(uint256, bytes calldata data)
├── internal call checkInitiator (BaseCallbackReceiver)
└── internal call multicall

.
└── onMorphoRepay(uint256, bytes calldata data)
├── internal call checkInitiator (BaseCallbackReceiver)
└── internal call multicall

.
└── onMorphoFlashLoan(uint256, bytes calldata data)
├── internal call checkInitiator (BaseCallbackReceiver)
└── internal call multicall

.
└── morphoSetAuthorizationWithSig(Authorization calldata authorization, Signature calldata signature)
└── call setAuthorizationWithSig(authorization, signature) on MORPHO

.
└── morphoSupply(Market calldata market, uint256 amount, uint256 shares, address onBehalf, bytes calldata data)
├── if onBehalf == address(this)
│ └── revert BULKER_ADDRESS
├── internal call _approveMaxBlue(borrowableToken)
└── call supply(market, amount, shares, onBehalf, data) on MORPHO
├── if amount == type(uint256).max
│ └── amount = balance of borrowableToken
└── else amount = amount

.
└── morphoSupplyCollateral(Market calldata market, uint256 amount, address onBehalf, bytes calldata data)
├── if onBehalf == address(this)
│ └── revert BULKER_ADDRESS
├── internal call _approveMaxBlue(collateralToken)
└── call supplyCollateral(market, amount, onBehalf, data) on MORPHO
├── if amount == type(uint256).max
│ └── amount = balance of collateralToken
└── else amount = amount

.
└── morphoBorrow(Market calldata market, uint256 amount, uint256 shares, address receiver)
└── call on MORPHO borrow(market, amount, shares, _initiator, receiver)

.
└── morphoRepay(Market calldata market, uint256 amount, uint256 shares, address onBehalf, bytes calldata data)
├── if onBehalf == address(this)
│ └── revert BULKER_ADDRESS
├── internal call _approveMaxBlue(borrowableToken)
└── call repay(market, amount, shares, onBehalf, data) on MORPHO
├── if amount == type(uint256).max
│ └── amount = balance of borrowableToken
└── else amount = amount

.
└── morphoWithdraw(Market calldata market, uint256 amount, uint256 shares, address receiver)
└── call on MORPHO withdraw(market, amount, shares, _initiator, receiver)

.
└── morphoWithdrawCollateral(Market calldata market, uint256 amount, address receiver)
└── call on MORPHO withdrawCollateral(market, amount, _initiator, receiver)

.
└── morphoLiquidate(Market calldata market, address borrower, uint256 seized, bytes memory data)
├── internal call approveMaxBlue(borrowableToken)
└── call liquidate(market, borrower, seized, data) on MORPHO

.
└── morphoFlashLoan(address asset, uint256 amount, bytes calldata data)
├── internal call approveMaxBlue(asset)
└── call flashLoan(asset, amount, data) on MORPHO

.
└── _approveMaxBlue(address asset)
├── if allowance(address(this), address(MORPHO)) == 0
│ └── call ERC20(asset).safeApprove(address(MORPHO), type(uint256).max)
└── otherwise do nothing

0 comments on commit 672fe44

Please sign in to comment.