RiskProtocol / core-protocol

1 stars 0 forks source link

Research: Balancer as AMM for our rebase tokens #117

Open mz7mz7mz7 opened 1 year ago

mz7mz7mz7 commented 1 year ago

Ampleforth, as a rebase protocol, uses Balancer as the AMM for its liquidity. Every time when they rebase their token (ie, every 24h in their case), they are calling, atomically, 4 post-rebase transactions as documented here: https://forum.ampleforth.org/t/technical-implementation-of-the-rebase-operation/578/2 Some more details: https://blog.ampleforth.org/ampl-usdc-smart-pool-on-balancer-be8eed9a264a https://docs.balancer.fi/concepts/pools/weighted.html

In our case, we would want to create a pool with always RiskOn and RiskOff tokens and optionally some 3rd token (ie, underlying)? This way, when the rebase happens, and RiskOff is created (or RiskOn is created) for a given liquidity pool wallet address, that liquidity pool is already aware of both Risk smart tokens. What would need to be done is the adjustment of weights of these tokens in the pool. Something that https://github.com/ampleforth/ampl-balancer/blob/master/contracts/AmplElasticCRP.sol seems to actually do, for AMPL tokens. Here is a similar implementation from Balancer directly: https://github.com/balancer/configurable-rights-pool/blob/master/contracts/templates/ESPFactory.sol

Task: Let's explore this whole setup a bit more and decide if Balancer AMM could work for our smart tokens.

haidarally commented 1 year ago

Balancer AMM could work for us in a pool of X:Y:Underlying where X and Y are the smart tokens

The Smart Pool ampleforth is using is a bit deprecated i think, We can use the managed pools for our use cases and we ll have a lot of freedom accordingly. https://docs.balancer.fi/concepts/pools/managed.html#examples

mz7mz7mz7 commented 1 year ago

Let's also explore 4-tokens pool: X:Y:Underlying:USDT/C

Here are some simulations @haidarally prepared: https://docs.google.com/spreadsheets/d/1AlclSm4ZTqxWmbF2-h4FltTUWIxZaCdJIC3WwYIakLo/edit#gid=810205788

haidarally commented 1 year ago

@mz7mz7mz7 One Project of interest could be KassandraFinance

The built a factory to deploy custom(or managed pools with certain limitations for their own interest) They also got a grant from balancer for this https://github.com/KassandraFinance/kassandra-core-v2/blob/master/contracts/KassandraControlledManagedPoolFactory.sol

haidarally commented 1 year ago
haidarally commented 1 year ago

Tests/Simulations are paused, Sepolia/Goerli -> Issues with depositing token Arbitrum/Polygon -> pool creation is stopped on the official deployed factories

mz7mz7mz7 commented 1 year ago
  1. For v1 @haidarally will check with Balancer people how long is it going to exist, ie can we rely on it to exist?
  2. For v2 question would be what is the alternative to gulp?
  3. @haidarally will try to run v1 locally.
  4. @haidarally will check Sanctions contract if the mock is deployed on the other chains, so it is not a source of revert.
haidarally commented 1 year ago
  1. V1 will continue to exist in the future
  2. Balancer V2 isnt compatible with rebasing tokens
  3. Issue was with the Sanctions Contract on Goerli, Deployed a new sanction contract fixed issue Ref: https://discord.com/channels/638460494168064021/739109162536927385/1128309608935608452

Note: The only way you can do something like that is by having a token wrapper. For example, this is why Lido's stETH is wrapped into wstETH in the Vault. Additionally, it's why Aave Boosted Pools use Aave token wrappers - The only way of using V2 with rebase tokens

haidarally commented 1 year ago

@mz7mz7mz7 Thread on discord: https://discord.com/channels/638460494168064021/739109162536927385/1128760047393054821