The speedBump contract acts as a temporary holder of ERC-20's and ERC-721's when they are withdrawn from the pool. It forces the user to wait until the next block to remove liquidity. This is done to reduce the risk of exploits that make use of flash loans. Flash loans revert if all liquidity + fees are not returned in the same block, thus the speedBump makes a flash loan exploit less likely.
Register Withdrawal ERC-721:
The positionManager sends the NFT (ERC-721) to the SpeedBump contract.
The positionManager calls a function on the SpeedBump contract to register the withdrawal request, providing the user’s address and the current block number. This is protected by nonReentrant modifier
User Withdraw (ERC-721)
The user sends a message to `withdrawNft`` with tokenID.
If the user has a deposit on the speedBump, and the current block number is at least the block number at registration + 1, the NFT will be transfered to the user
Depositing ERC-20
The positionManager sends the ERC-20 to the SpeedBump contract.
The position manager call registerToken with the ERC-20 token address and an amount of the token, registering it to the user in a withdrawl struct
Withdraw ERC-20
The user sends a message to withdrawToken with the associated address of the ERC-20 contract.
If the block number is at least the block number registered in the withdraw struct + 1, the ERC-20 is withdrawn to the user. This is protected by the non-reentrant modifier.
Parameters
structETH {uint256 blockNumber;uint256 amount;}structToken {uint256 blockNumber;uint256 amount;}structNFT {uint256 blockNumber;address owner;}// owner address => ETHmapping(address=> ETH) public eths;// token address => owner address => Tokenmapping(address=>mapping(address=> Token)) public tokens;// collection address => nft id => NFTmapping(address=>mapping(uint256=> NFT)) public collections;
Functions
initialize
The initialize takes as an argument the associated address for the position Manager. The functions "registerXXXX" have a modifier that makes it so they can only be called by the positionManager.
/*** @notice Batch register nft when withdrawing(removing liquidity) from SeacowsPositionManager* @param collection The collection address to register then store* @param tokenIds The NFT ids to register then store* @param owner The address that own the NFTs.*/functionbatchRegisterNFTs(address collection,uint256[] memory tokenIds,address owner) publiconlyPositionManagernonReentrant
batchWithdrawNFTs
/*** @notice Batch withdraw nft from SpeedBump contract* @param collection The collection address user want to withdraw* @param tokenIds The NFT ids user want to withdraw*/functionbatchWithdrawNFTs(address collection,uint256[] memory tokenIds) publicnonReentrant
registerToken
/** @dev Register token when withdrawing(removing liquidity) from SeacowsPositionManager* @param owner The address that own the token.* @param token The token contract address.* @param amount The token amount store in contract.*/functionregisterToken(address token,uint256 amount,address owner) publiconlyPositionManagernonReentrant
withdrawToken
/*** @notice Withdraw all token from SpeedBump contract* @param token The token address user want to withdraw*/functionwithdrawToken(address token) publicnonReentrant
registerETH
/** @dev Register ETH when withdrawing(removing liquidity) from SeacowsPositionManager* @param owner The address that own the ETH.* @param amount The eth amount store in contract.*/functionregisterETH(uint256 amount,address owner) publiconlyPositionManagernonReentrant
withdrawETH
/*** @notice Withdraw all ETH from SpeedBump contract*/functionwithdrawETH() publicnonReentrant
Events
/** @dev Emit at the end of the registerETH function call* @param owner The address that own the ETH.* @param amount The eth amount store in contract.*/eventRegisterETH(addressindexed owner, uint256 amount);/** @dev Emit at the end of the registerToken function call* @param owner The address that own the token.* @param token The token contract address.* @param amount The token amount store in contract.*/eventRegisterToken(addressindexed owner, addressindexed token, uint256 amount);/** @dev Emit at the end of the batchRegisterNFTs function call* @param owner The address that own the nft.* @param collection The collection contract address.* @param tokenIds The nft ids store in contract.*/eventRegisterNFTs(addressindexed owner, addressindexed collection, uint256[] tokenIds);/** @dev Emit at the end of the withdrawETH function call* @param sender The address that send the withdraw request.* @param amount The eth amount user withdraw.*/eventWithdrawETH(addressindexed sender, uint256 amount);/** @dev Emit at the end of the withdrawToken function call* @param sender The address that send the withdraw request.* @param token The token contract address.* @param amount The eth amount user want to withdraw.*/eventWithdrawToken(addressindexed sender, addressindexed token, uint256 amount);/** @dev Emit at the end of the batchWithdrawNFTs function call* @param sender The address that send the withdraw request.* @param collection The collection contract address.* @param tokenIds The nft ids user want to withdraw.*/eventWithdrawNFTs(addressindexed sender, addressindexed collection, uint256[] tokenIds);