Code Monkey home page Code Monkey logo

stroller-protocol's Introduction

Stroller Protocol

Need for a Stroller

Currently users have no option other than wrapping surplus ERC20 tokens to keep the streams running. These tokens do not earn interest since Superfluid protocol is relatively new and DeFi is yet to be introduced on streams.

Stroller Protocol allows users to earn yield on ERC20 tokens without the compulsion of having to wrap them to Super Tokens. This is enabled by creating Strollers which top-up the streams with just enough Super tokens to keep the streams running without any penalties.

Use Case

Users can invest their tokens in other DeFi protocols like AAVE, Harvest, etc. and approve the receipt tokens for our contracts. For example, Alex invests USDT in AAVE and gets amUSDT in return. She approves amUSDT for our contracts and creates a stroller. Whenever her USDTx stream will have low balance to keep the stream running for a threshold, these amUSDT tokens will be converted to USDT and transferred to Alex as USDTx.

Using the Top-Up service provided by Stroller Protocol, users can now be tension free about their streams running dry. Approve, create a stroller and relax. The protocol handles the headaches for you.

Deployments

Chain Addresses
Polygon Mumbai StrollManager: 0x896d448119F6901d27845f77083Dfe5456C05099
ERC20StrollOut: 0x20af3f0f49237D0c3f8557dBED9d4B1A6ed4d552
AaveV2StrollOut: 0x7606bC78f13d8e9A1B38CE69Fb508cbB0dFa7e13
Rinkeby StrollManager: 0x1166363D3005F96E6e2D940860BC346414E0cFB9
ERC20StrollOut: 0xa6C537b0e5162b6a220522D0657749144d1a180e
Polygon PoS (mainnet) StrollManager: 0x74EC90e367493b3d0e57F0B09eeD760dfdAeDC89
ERC20StrollOut: 0x74408A7979a361dB0e16C9D471ab786cF9A59ed3
GelatoStrollKeeper: 0xc8c9E0E1B2E77Bb846b90a08A4E5F2567cFA69f4

stroller-protocol's People

Contributors

harsh132 avatar jayeshbhole avatar jtriley-eth avatar ngmachado avatar pushkar1809 avatar rashtrakoff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

stroller-protocol's Issues

Change license version.

We have decided to use the AGPLv3 license for our codebase. We need to specify the SPDX license identifier in every file to be AGPLv3. Also, include the license notice for AGPLv3

Optimize loops to be more efficient.

Description:
All of the for-loops in the project are using the standard way of declaring them, which is slightly inefficient gas-wise.

The following loops are not optimized:

  • StrollManager.sol - Line 116

Solution:
Consider optimizing the for-loops in each contract to be more efficient in terms of its
gas usage, including:

  • Not initializing variables with their default value
  • Using the more efficient way to increment a variable

Not using SafeERC20 transfers.

Location: strategies/AaveV2StrollOut.sol - Line 86 - 87

Description:
In the topUp function, supertokens are transferred to the user without making use of the SafeERC20 variant even though it’s imported and used for other transfers. This might be the case as superTokens can be trusted with their implementation being very familiar with the developers, but it would still be consistent to use SafeERC20 for any transfers. The same also applies to strategies/ERC20StrollOut.sol in lines 62 - 63.

Justification:
Forgot the fact that a supertoken inherits IERC20.

Solution:
Will change the code to make it consistent with other types of transfers.

Unnecessary cast to ISuperToken.

Location: StrollManager.sol - Line 172

Description:
As topUp.superToken is already of type ISuperToken and not an address, the cast is unnecessary.

Justification:
Slipped by us.

Solution:
Consider not unnecessarily casting topUp.superToken to ISuperToken.

Missing check on existence of index.

Location: StrollManager.sol - Line 69 - 70

Description:
The index is the keccak256 hash of the users' address, the superToken address, and the liquidityToken address. Subsequently, the index is used to store the top-up of the user. In order not to overwrite anything, it is important to check whether there is already a top-up stored for the user, which is also indicated by the comment. However, this check is currently not implemented.

Justification:
The purpose of not having a check in the first place was to allow for top-up updates to happen using this same function (createTopUp). However, it makes more sense to separate these two functionalities as this would also allow us to save some gas costs.

Unlimited Allowance

For upgrading ERC20 tokens to supertokens, we require providing allowance to the supertoken contract. This is done in individual strategy contracts. However, there is a chance that we might hit uint256 max amount (very unlikely but possible).

Suggest to check for allowance and also check if the top up is possible with the current allowance to the supertoken contract. If not, approve the contract once again.

The code for the same should ideally be in StrollManager.sol. However, to not break existing deployments, it's recommended to not change it from strategy contracts. However for the next version, see to it that it's moved. This will also help us with gas savings.

Add more checks to constructor.

Location: StrollManager.sol - Line 27 - 35

Description:
There is no logic in the contract that actually enforces minLower to be less than minUpper and vice versa. As there is no way to change the values of minLower and minUpper, it should be ensured that they are correct. Additionally, if minLower is set to 0, this would allow for unnecessary 0 TopUps by the Keepers to potentially happen.

Justification:
Just wanted to save some gas by avoiding trivial checks. However, a good point has been raised as we need a way to change minUpper and minLower parameters.

Solution:
Add some trivial checks but more importantly, add functions to change minLower and minUpper limits. It's worth noting that existing top-ups whose limits may not adhere changed global limits i.e., minLower > userTopUpLowerLimit or minUpper > userTopUpUpperLimit; we need to enforce the global limits on them as well.

Docs

We are getting to the point that documentation will be needed to Stroller Protocol.

Any opinions on this? Was thinking on using gitbook to create a doc based website to the protocol and "how to".

Natspec comments missing.

Natsoec comments are missing from StrollManager.sol. Add them in the interfaces of the implementation contracts.

Don’t use change-function for initialization.

Location: strategies/StrategyBase.sol - General

Description:
In the StrategyBase contract, there is a changeStrollManager() function, which is seemingly also used to initialize the value of the strollManager variable. According to the best practice, this should be done via the constructor.

Justification:
We included this function to allow for changing strollManager in case we discover any bugs in strollManager.

Solution:
None.

Create deployment scripts.

We need deployment scripts to allow for contract deployments on different chains quickly. These scripts already exist but are outdated and need modification.

Return reason string for non-execution of top-ups.

Currently, the contracts don't give any reason as to why a top-up isn't necessary. However, we need the reason for monitoring purposes. Change the checkTopUpByIndex function to return the reason code.

Use try-catch to control error message.

Location: strategies/StrategyBase.sol - Line 31 - 32

Description:
In the emergencyWithdraw() function, arbitrary tokens can be transferred out of the contract in case they got stuck, etc. As errors can also occur in the ERC20 contract itself during the transfer() call, the custom TransferFailed error may not be emitted accordingly.

As an additional remark, using safeTransfer instead of
transfer() would make a lot of sense here, as downstream contracts use it anyways, and subsequently not using it would not save any gas cost otherwise.

Justification:
Slipped by us.

Solution:
Will implement the recommended solution of making use of a try-catch-block to ensure that the custom TransferFailed error is thrown each time a transfer failed due to any reason.

Also will use safeTransfer instead of a regular transfer.

Cache certain variables to save gas

Description:
In certain circumstances, it saves gas to cache variables that are read often, especially if they are stored in the storage and not in the memory.

The affected variables are:

  • StrollManager.sol - Line 116 (_indices.length)

Solution:
Consider caching the affected variables and reading from the cached version instead of doing costly read actions.

Incorrect error message for disabled strategy.

Location: StrollManager.sol - Line 165 - 167

Description:
The checkTopUpByIndex function determines the required top-up amount, which returns zero in cases where e.g. the user's balance or allowance doesn’t suffice. Additionally, however, the case of a supertoken being disabled for the corresponding strategy is handled in the same if-clause and returns the same zero output. Subsequently, it also triggers the TopUpNotRequired error, which in this case is not correct, as there might very well be a top-up required.

Justification:
Never really thought about showing the reason why performing a top-up may fail.

Solution:
As recommended, the checkTopUpByIndex function will return the error along with the amount so, in case of the amount being 0, an error is checked for.

Missing a helpful zero check.

Location: strategies/AaveV2StrollOut.sol - Line 43

Description:
Generally, it is advisable to properly verify return values early, especially if they are used for subsequent calls without a potential error quickly appearing. In this case, an underlying token with the zero address in line 43 would lead to a lot of unnecessary calls and computations that could have been prevented. The same also applies to strategies/ERC20StrollOut.sol in line 29.

Justification:
We are already checking if the underlying token is correct (non-zero) or not when creating a top-up. Unless a supertoken can change its underlying token, this issue isn't a problem at all.

Do not emit events without state change.

Location: StrollManager.sol - Line 122 - 131

Description:
Similar to the way the removeApprovedStrategy() function works, it is a common best practice to only emit events in cases where the state actually changed. This allows external tools to reconstruct the current state and all of the state changes without diving into the code or any specific transactions. The same also applies to strategies/StrategyBase.sol in lines 15 - 25.

Justification:
Slipped by us.

Solution:
Consider changing the function to only emit the event if the strategy wasn’t approved already, e.g. via something like this
if (approvedStrategies[strategy]) return;
or revert the transaction in case the strategy is already approved.

Migrate to Foundry

This project is small enough to learn and take advantage of Foundry test suite. Once the contracts have stabilised and sent for audit, process of migration can begin.

Support partial amount top-ups.

Currently, the contracts don't allow for partial amount top-ups. For example, if the supertoken amount to be topped up is worth that of 8 days of liquidity but the user only has the liquidity tokens worth 5 days of supertoken amount, the contract/strategy should still top up using all the available liquidity.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.