Skip to content

Commit

Permalink
♻️ Add extcall and staticcall Keywords
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <[email protected]>
  • Loading branch information
pcaversaccio committed Mar 6, 2024
1 parent a7e0ead commit 40010d1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/snekmate/extensions/ERC4626.vy
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ def _total_assets() -> uint256:
https://eips.ethereum.org/EIPS/eip-4626#totalassets.
@return uint256 The 32-byte total managed assets.
"""
return asset.balanceOf(self)
return staticcall asset.balanceOf(self)


@internal
Expand Down Expand Up @@ -1010,7 +1010,7 @@ def _deposit(sender: address, receiver: address, assets: uint256, shares: uint25
# always performs an external code size check on the target address unless
# you add the kwarg `skip_contract_check=True`. If the check fails (i.e.
# the target address is an EOA), the call reverts.
assert asset.transferFrom(sender, self, assets, default_return_value=True), "ERC4626: transferFrom operation did not succeed"
assert extcall asset.transferFrom(sender, self, assets, default_return_value=True), "ERC4626: transferFrom operation did not succeed"
self._mint(receiver, shares)
log Deposit(sender, receiver, assets, shares)

Expand Down Expand Up @@ -1050,7 +1050,7 @@ def _withdraw(sender: address, receiver: address, owner: address, assets: uint25
# always performs an external code size check on the target address unless
# you add the kwarg `skip_contract_check=True`. If the check fails (i.e.
# the target address is an EOA), the call reverts.
assert asset.transfer(receiver, assets, default_return_value=True), "ERC4626: transfer operation did not succeed"
assert extcall asset.transfer(receiver, assets, default_return_value=True), "ERC4626: transfer operation did not succeed"
log Withdraw(sender, receiver, owner, assets, shares)


Expand Down
4 changes: 2 additions & 2 deletions src/snekmate/tokens/ERC1155.vy
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def _check_on_erc1155_received(owner: address, to: address, id: uint256, amount:
"""
# Contract case.
if (to.is_contract):
return_value: bytes4 = IERC1155Receiver(to).onERC1155Received(msg.sender, owner, id, amount, data)
return_value: bytes4 = extcall IERC1155Receiver(to).onERC1155Received(msg.sender, owner, id, amount, data)
assert return_value == method_id("onERC1155Received(address,address,uint256,uint256,bytes)", output_type=bytes4),\
"ERC1155: transfer to non-ERC1155Receiver implementer"
return True
Expand Down Expand Up @@ -897,7 +897,7 @@ def _check_on_erc1155_batch_received(owner: address, to: address, ids: DynArray[
"""
# Contract case.
if (to.is_contract):
return_value: bytes4 = IERC1155Receiver(to).onERC1155BatchReceived(msg.sender, owner, ids, amounts, data)
return_value: bytes4 = extcall IERC1155Receiver(to).onERC1155BatchReceived(msg.sender, owner, ids, amounts, data)
assert return_value == method_id("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)", output_type=bytes4),\
"ERC1155: transfer to non-ERC1155Receiver implementer"
return True
Expand Down
2 changes: 1 addition & 1 deletion src/snekmate/tokens/ERC721.vy
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def _check_on_erc721_received(owner: address, to: address, token_id: uint256, da
"""
# Contract case.
if (to.is_contract):
return_value: bytes4 = IERC721Receiver(to).onERC721Received(msg.sender, owner, token_id, data)
return_value: bytes4 = extcall IERC721Receiver(to).onERC721Received(msg.sender, owner, token_id, data)
assert return_value == method_id("onERC721Received(address,address,uint256,bytes)", output_type=bytes4), "ERC721: transfer to non-ERC721Receiver implementer"
return True
# EOA case.
Expand Down
4 changes: 2 additions & 2 deletions src/snekmate/utils/BatchDistributor.vy
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def distribute_token(token: IERC20, data: Batch):
# always performs an external code size check on the target address unless
# you add the kwarg `skip_contract_check=True`. If the check fails (i.e.
# the target address is an EOA), the call reverts.
assert token.transferFrom(msg.sender, self, total, default_return_value=True), "BatchDistributor: transferFrom operation did not succeed"
assert extcall token.transferFrom(msg.sender, self, total, default_return_value=True), "BatchDistributor: transferFrom operation did not succeed"

for txn: Transaction in data.txns:
assert token.transfer(txn.recipient, txn.amount, default_return_value=True), "BatchDistributor: transfer operation did not succeed"
assert extcall token.transfer(txn.recipient, txn.amount, default_return_value=True), "BatchDistributor: transfer operation did not succeed"

0 comments on commit 40010d1

Please sign in to comment.