This repository consists out of 4 independent contracts:
The BalancerSharedPoolPriceProvider
is a price provider for balancer v1 pools.
The price provider will return the price as arithmetic mean when the pool is in equilibrium and as weighted geometric mean when the pool is imbalanced. This calculation helps to determine a manipulation resistant fair market price.
This price provider will provide the price for abpt shares determined in USD, based on the AaveOracle prices and is intended to be used to determine the fair market value of a users shares.
The BalancerV2SharedPoolPriceProvider
is a price provider for balancer v2 pools.
The price calculation is analog to BalancerSharedPoolPriceProvider
.
The StkABPTMigrator
is a migration contract that allows migrating stkABPT to stkABPTv2.
The contract offers a migrateStkABPT
and a migrateStkABPTWithPermit
external function that allows migrating funds within the safety module.
The contract call will:
- pull funds from stkABPT
- pull funds from abpt
- wrap weth into wstETH
- deposit into abptv2
- deposit into stkabptv2
These methods allow two types of migration:
- exact migration
- proportional migration
In the exact migration path
migrateStkABPT(
uint256 amount,
[0,0],
minAmountOut, // slippage control
true // all
)
The amount is withdrawn from stkABPT and fully deposited into stkABPTv2. minAmountOut
in this case acts as slippage control and should be calculated as ((amount * uint256(abptOracle.latestAnswer())) / uint256(abptv2Oracle.latestAnswer())) * slippage
. By making slippage sufficiently small (e.g. 0.01%
), the swap will revert if one of the pools is highly imbalanced. As long as the pools have reasonable liquidity, we expect this path to be preferrable as arbitrage bots will keep the pool close to equilibrium.
In the proportional migration path:
migrateStkABPT(
uint256 amount,
tokenOutAmountsMin,
minAmountOut, // slippage control
false // all
)
The slippage control is on both the tokenOutAmountsMin
and minAmountsOut
. Instead of joining with the full balance withdrawn from v1, the join on v2 will be proportional to reach equlibrium. The remaining funds will be sent back to the sender.
This contract is intended to be used as the proposal payload to initiate the migration process. The payload does multiple actions:
- stop liquidity incentives on stkabptv1
- upgrade the token implementation to allow withdrawals without cooldown
- create the nem stkabptv2 sm
- start liquidity incentives on stkabptv2
This repository also contains storage and code diffs of the affected contracts:
- StkABPTv2 vs StkAbptV1 code
- StkABPTv2 vs StkAbptV1 storage
- StkABPTv1Upgrade vs StkAbptV1 code
- StkABPTv1Upgrade vs StkAbptV1 storage
This project uses Foundry. See the book for detailed instructions on how to install and use Foundry.
The template ships with sensible default so you can use default foundry
commands without resorting to MakeFile
.
cp .env.example .env
forge install
forge test
Copyright © 2023, BGD Labs. Released under the MIT License.