Feat: Add Topos Funding Manager + Token Vault#667
Conversation
* Create Reservepool Contract * Rename and adapt * Create FM_EXT_ReservePool_v1.t.sol * Rename to TokenVault * Adapt to not send native token * Address comments * Add: - Internal function to modifier - Trailing underscore to parameters - Gherkin to test - Cleaned up tests * Update FM_EXT_TokenVault_v1.t.sol --------- Co-authored-by: Zitzak <marvin88gr@gmail.com> Co-authored-by: Marvin <43185740+Zitzak@users.noreply.github.com>
cb64317 to
fe7bc8d
Compare
* Create Reservepool Contract * Rename and adapt * Create FM_EXT_ReservePool_v1.t.sol * Topos FM * remove liquidity vault controller contracts * Rename to TokenVault * Adapt to not send native token * Rename to Token Vault * Address comments * Outcomment Burn tests for now * Create setTokenVault * Fix most Burn functions * AddSpentAllowance to ERC20Issuance * Add _spendAllowance to BondingCurveBase * Add _spendAllowance to BurnIssuanceFor * Fix Dependency Issue * Rename Redeemable to Redeeming * Create FM_BC_BondingSurface_Redeeming_v1.sol * WIP * Add: - Internal function to modifier - Trailing underscore to parameters - Gherkin to test - Cleaned up tests * restructure contracts * Add tag for testing file split * Setup seperate Tests * Update Base BondingSurface test * Rename Mock * Remove Tests that are included in the base contract * Remove parameters from BondingSurface Struct * Go over comments * Address comments * Address Comments * Adapt Naming of events * Adding Restricted to the name * Update comments * resolve comments in implementations * Fix: Finalize moving of error into funding manager base * Fix: Typos in ERC20Issuance * Chore: Start cleanup of FM_BC's * Fix: Resolve failing test Was mismatched with implementation, didn't cover the address(this) case. --------- Co-authored-by: FHieser <felix_hieser@web.de> Co-authored-by: Felix Hieser <47272854+FHieser@users.noreply.github.com> Co-authored-by: Marvin Kruse <marvinkruse@users.noreply.github.com>
| override(BondingCurveBase_v1) | ||
| returns (uint) | ||
| { | ||
| return _issueTokensFormulaWrapper(1); |
There was a problem hiding this comment.
Here it's calculating the how much you can buy with 1 wei of the collateral token, but in another contract this function calculates the price for a whole issuance token.
There was a problem hiding this comment.
Same for getStaticPriceForSelling
There was a problem hiding this comment.
So... @0xNuggan rightfully pointed me towards the fact that there is actually a function in the bonding surface which does exactly what we need, calculate the spot price 🤦
So @FHieser the function can redirect to the spot price calculation function in the formula
| ); | ||
|
|
||
| // The asset pool must never be empty. | ||
| if (capitalAvailable - redeemAmount < MIN_RESERVE) { |
There was a problem hiding this comment.
MIN_RESERVE is always 1 ether, this will not work well for tokens with low decimals.
There was a problem hiding this comment.
Good point
we will calculate out of the decimals of the token itself
|
|
||
| // The asset pool must never be empty. | ||
| if (capitalAvailable - redeemAmount < MIN_RESERVE) { | ||
| redeemAmount = capitalAvailable - MIN_RESERVE; |
There was a problem hiding this comment.
This will reduce the amount the user gets while still taking the entire issued token when they sell. The issued taken from the user should be reduced as well in this case.
There was a problem hiding this comment.
Agree. We are going to add a revert here instead of reducing the amount
| ) { | ||
| revert InvalidOrchestratorTokenWithdrawAmount(); | ||
| } | ||
| token().safeTransfer(to, amount); |
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
| override(FM_BC_BondingSurface_Redeeming_v1) | ||
| isBuyAndSellRestricted | ||
| { | ||
| super._sellOrder(_msgSender(), _depositAmount, _minAmountOut); |
There was a problem hiding this comment.
super is not doing anything here and can be removed
| } | ||
|
|
||
| // solhint-disable-next-line not-rely-on-time | ||
| lastSeizeTimestamp = uint64(block.timestamp); |
|
|
||
| /// @dev Processes project fee by transfer | ||
| /// @param _workflowFeeAmount The amount of project fee to transfer | ||
| function _projectFeeCollected(uint _workflowFeeAmount) internal override { |
There was a problem hiding this comment.
if buyFee is 0, then (I think) also the projectfee is always 0, and so youc an save some gas by not callign the transfer at all
There was a problem hiding this comment.
The sell fee should also use this to send out the collateral fee that was collected.
Forgot to add that though 😅 👍
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
| // 1 / C_a_2 | ||
| uint ca2inv = _inverse(_capitalAvailable); | ||
|
|
||
| return _capitalAvailable - _inverse(BCrM + ca2inv); |
There was a problem hiding this comment.
Is this correct? The formula in the docstring is:
/// B 1
/// x = (----- * m + -------)^-1
/// C_r C_a_2
```
There was a problem hiding this comment.
@rororowyourboat could you please confirm this?
There was a problem hiding this comment.
The formula implementation has been confirmed by the data department
* Add empty BondingSurface test file * Remove tokenVault from init The tokenvault cant be set during init because is created simultaneously to the BondingCurve contract. It has to be added via Dependency Injection * Remove unnecessary overrides * Add and adapt tests * Adapt inheritance of functions * Update Comments * Update Tests * Update fmt * Add event to projectFeeCollected * Address comments of PR --------- Co-authored-by: Zitzak <marvin88gr@gmail.com>
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
* Add empty BondingSurface test file * Remove tokenVault from init The tokenvault cant be set during init because is created simultaneously to the BondingCurve contract. It has to be added via Dependency Injection * Remove unnecessary overrides * Add and adapt tests * Adapt inheritance of functions * Update Comments * Update Tests * Update fmt * Add event to projectFeeCollected * Address comments of PR * Revert if redeemamount reaches Min Reserve * Check for Min Reserve in TransferOrchestrator Token * Add MinReserveCheck to transferRepayment * Rename Modifier * Remove time casting * Enable BuyFee * Use function that can be overriden * Add gap * Make Min_Reserves variable based on Token Decimals * Use SpotPrice to get StaticPrice * adapt based on comments * Update FM_BC_BondingSurface_Redeeming_v1.t.sol --------- Co-authored-by: Zitzak <marvin88gr@gmail.com>
| "@oz-up/utils/introspection/ERC165Upgradeable.sol"; | ||
|
|
||
| /** | ||
| * @title Inverter Token Vault |
There was a problem hiding this comment.
I don't really see how this is an extension to a funding manager to be honest, the naming is confusing. It's a contract that in itself has no resemblance to a funding manager and does not interact with it or depend on it in any form.
It provides additional logic to a workflow in the form of a vault that can receive any form of tokens and withdraw them again, governed by the workflow admin. To me that looks more like a logic module, but not an extension, if we judge this according to our definitions.
An extension - to me - is the EXT_VotingRoles_v1 module: it extends the functionality of another module within the same workflow, but wouldn't make sense on its own. This module here can exist on its own, so it doesn't extend anything.
There was a problem hiding this comment.
Yes and no:
It definitely has properties of a logicmodule as you suggested, but the point here is to not use the paymentProcessor to transfer tokens, which I would say is one of the main points of a logicmodule.
In regards of it being a extension: For me the VotingRoles argument doesnt work here. Yes the Module extends the functionality of another module, but it also makes sense on its own. It can act as a Controller of other contracts for example and doesnt necessarily have to be linked into our authorizer setup. Broken down its just a voting mechanism contract that can call stuff. The same goes for the Vault. It may work on its own but in this context it extends the functionality of the workflow by providing a Auhtorized setup for storing tokens, that are not included in the classic token flow of the workflow
I would agree, that FM in the naming might be misleading here, but we currently dont have a system to categorize this appropriately yet.
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
...undingManager/bondingCurve/FM_BC_BondingSurface_Redeeming_Restricted_Repayer_Seizable_v1.sol
Outdated
Show resolved
Hide resolved
…de of conduct * Add empty BondingSurface test file * Remove tokenVault from init The tokenvault cant be set during init because is created simultaneously to the BondingCurve contract. It has to be added via Dependency Injection * Remove unnecessary overrides * Add and adapt tests * Adapt inheritance of functions * Update Comments * Update Tests * Update fmt * Add event to projectFeeCollected * Address comments of PR * Revert if redeemamount reaches Min Reserve * Check for Min Reserve in TransferOrchestrator Token * Add MinReserveCheck to transferRepayment * Rename Modifier * Remove time casting * Enable BuyFee * Use function that can be overriden * Add gap * Make Min_Reserves variable based on Token Decimals * Use SpotPrice to get StaticPrice * adapt based on comments * Update FM_BC_BondingSurface_Redeeming_v1.t.sol * WIP push * Rename seizable * Make state internal * Rename Parameters and Return Values * Rename Contracts * Adapt to code of conduct * Adapting Interfaces to have Contract Overview Documentation * Adapt Sectioning * Adapt Mocks and Tests to parameter conventions * Remove Todos/notes * Adapt merge aftermath * Update BondingSurface.sol * Rename to prevent shadow * Adapt remapping * Address comments * Adapt init * Update inverter standard versioning * Delete FM_BC_BondingSurface_RedeemingV1_exposed.sol * Adapt Contract Naming Standards * Fix naming references * Fix test * Update naming reference * Adapt modifier to call internal function * Adapt naming of internal function * update modifier Naming * Adapt tests * Adapt naming internal functions * Adapt Parameters * Adapt naming of function state * Adapt sections * Update Interface Inheritance * Update versioning * Update natspec to be rule compliant * Fix naming * Delete ILiquidityVaultProviderWhitelist_v1.sol * Remove Liquidity Vault Controller Interface * Rename Modifier * Add solmate as lib * Revert "Add solmate as lib" This reverts commit 050b9d2. * Remove comment * Adapt natspec * Apply comment suggestions from code review Co-authored-by: Marvin Kruse <marvinkruse@users.noreply.github.com> * Adapt internal function state * Add . to comments * Adapt spacing in natspec comments * Adapt spacing * Replace @dev with @notice * Adapt comment length * Adapt naming * Address Comments * Adapt Version * Reposition MIN_RESERVE * Adapt sectioning * Update more sectioning * Add title section and increment version --------- Co-authored-by: Zitzak <marvin88gr@gmail.com> Co-authored-by: Marvin Kruse <marvinkruse@users.noreply.github.com>
|
Afaik, this audit was done right, or are we waiting for another review from someone? @FHieser @marvinkruse What still need to happen for sure is the documentation for this contracts ser @FHieser. |
…rterNetwork/contracts into feature/ToposFundingManager
Contains the Topos-related contracts, including:
Ready to be reviewed by Team Omega, after which it will be merged into
dev.