Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v2 v3 migration #1352

Closed
wants to merge 109 commits into from
Closed

Conversation

satanworker
Copy link
Contributor

@satanworker satanworker commented Dec 9, 2022

General changes

Dedicated page with logic to handle migration from AAVE v2 to v3.
In nutshell, migrating from v2 to v3 positions requires, to set current market to v2, while simultaneously fetching data for v3.
Selecting positions from v2 should dynamically change health factor and display both before and after migration HF for both v2 and v3.

When user selects multiple assets to migrate, supply asset amount should be slightly increased to allow migrating the whole position, or the balance would grow during approving and transaction execution and method would fail as HF will fell below 1, with no supply and a little bit of debt.

In order to properly do that, changes in the whole transaction flow on the aave interface required. More specifically, changes to how useTransactionHandler is working.
On any modal opens in the app after small delay, transactions are filtered into approval and actions by transaction type.
If approval state is not empty, that means we need to approve action first with permit if available after with on chain approval.

Currently, AAVE interface assumes that each Action in the app will have single approve or single permit and single following transaction. Although it worked great for most parts, specifically for migration it didn't work, since migrating multiple positions would require approving/signing permit for each supply asset.

Also, it's the first pr with new changes done in zustand completely, which also changed a bit the flow working with Actions component, as mentioned in this discussion, we want to migrate from idea of dedicated actions component anyway. It also showcases how easy it is to nest multiple non-destructive data manipulation in selectors. i.e. increasing amount, filtering for non-empty states, etc. Which is the bulk of the logic in the app.

Isolation mode

When user has 0 collateral on v3, the order of supply assets will define the isolation mode, if isolated supply is supplied on v2.
Supply USDT as collateral to empty balance on v3, will automatically enable it as collateral and activate isolation mode, therefore supplying any other collateral will be ignored.
To make it easier for user to understand enabled as collateral toggles are presented.
The logic is following, if only isolated supplies are selected, the last one will be selected as collateral and therefore migrated first.
if any non-isolated supply is available, non-isolated supplies will be selected as collateral. Non-isolated supplies will be migrated first. Since it’s way harder to migrate from isolated supply to non-isolated one.
It’s still possible though to enable isolated supply manually and user choice will be respected.
The situation gets more complicated with non-empty balance on v3, which is not enabled as collateral.
In that case supplied assets on v3 can not be toggled as collateral, but the rest of the assets will still follow the same rules of the first migrated supply will trigger isolation mode. For example
image

In this example, user has DAI disabled as collateral on v3 and that’s why it’s disabled for usage as collateral on migration page.
But MATIC or USDT can be triggered as collateral and therefore define the isolation mode

Balancer will be enabled/disabled for migration based on isolation mode dynamically

Developer notes

Since v2-v3 migrator is not deployed, use this RPC for testing

localStorage.setItem('forkEnabled', 'true');
localStorage.setItem('forkBaseChainId', 137);
localStorage.setItem('forkNetworkId', 137);
localStorage.setItem("forkRPCUrl", "https://rpc.tenderly.co/fork/f1fcc2cc-c0ca-45c6-9f8b-92a4ab4b053f");

Be careful fork chain is equal to real chain ID on purpose, in order to test permits, both fork and base chain id required to be the same

contract helpers version is set to deployed of this PR
aave/aave-utilities#459 once we merge it to main will change to bumped version

Demo

(top UI was changed a bit)

CleanShot.2022-12-06.at.18.54.07.1.mp4

To discuss

[ ] Discuss how to dynamically change market names based on chain ID after migration deployment

@MareskoY
Copy link
Contributor

MareskoY commented Dec 19, 2022

Previous bugs

#1352 (comment)

  • Bug1: fixed
  • Bug2: exist
  • Bug3: exist
  • Bug4: exist

#1352 (comment)

  • Bug1: exist
  • Bug2: exist

New bugs

BUG1:
if v3 market is empty and first asset which we migrate is USDT it move to

Case1:

Before migration:
v2 - USDT supplied- not collateral
v2 - LINK supplied - is collateral
v3 - empty

After migration:
v2 - empty
v3 - USDT supplied- is collateral - in isolated mode
v3 - LINK supplied - is not collateral

Should be:
v2 - empty
v3 - USDT supplied- not collateral
v3 - LINK supplied - is collateral

Case2:

Before migration:
v2 - USDT 0.1 supplied- not collateral
v2 - LINK 100 supplied - is collateral
v2 - USDT borrow 0.1
v3 - empty

Migration will fail cause not enough HF cause case 1
tx error:

cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"id\":86,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"execution reverted\",\"data\":{\"error_id\":\"359ace5c-ef4b-4e7f-aa14-cdaf7a8c6d5a\"}}}","error":{"code":-32000,"data":{"error_id":"359ace5c-ef4b-4e7f-aa14-cdaf7a8c6d5a"}},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"value\":\"0x0\",\"from\":\"0xe4217040c894e8873ee19d675b6d0eec992c2c0d\",\"to\":\"0x794a61358d6845594f94dc1db02a252b5b4814ad\",\"data\":\"0xab9c4b5d00000000000000000000000001ce9bbcc0418614a8bba983fe79cf77211996f200000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000160000000000000000000000000e4217040c894e8873ee19d675b6d0eec992c2c0d00000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000186cf0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f00000000000000000000000053e0bca35ec356bd5dddfebbd1fc0fd03fabad390000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f00000000000000000000000000000000000000000000000000000000000186cf0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000060d55f02a771d515e077c9c2403a1ef324885cec00000000000000000000000000000000000000000000000000000000000187040000000000000000000000000000000000000000000000000000000063a0c36a000000000000000000000000000000000000000000000000000000000000001bb338dc3c2a0c7fa5bfa8ff5cc1fb8b8ce81b0aa9870d1448cdd8d7aaa608e9e24828112fe325629bd6431c57ee432a753d2ca85a3b3b21ee8952c0687a0ea3d00000000000000000000000000ca2e42e8c21954af73bc9af1213e4e81d6a669a000000000000000000000000000000000000000000000000011c8055f942d30d0000000000000000000000000000000000000000000000000000000063a0c36a000000000000000000000000000000000000000000000000000000000000001c514bfa4c3fb665112886f2fbff024e35786e89a5e539643095599db58043f3ce33149cbfa7400bd87b3e3d0637538ec1c2e10b7b1393ab3e72358bb0c87826a0\"}],\"id\":86,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://rpc.tenderly.co/fork/f1fcc2cc-c0ca-45c6-9f8b-92a4ab4b053f"}, method="estimateGas", transaction={"from":"0xE4217040c894e8873EE19d675b6d0EeC992c2c0D","to":"0x794a61358D6845594F94dc1DB02A252b5b4814aD","value":{"type":"BigNumber","hex":"0x00"},"data":"0xab9c4b5d00000000000000000000000001ce9bbcc0418614a8bba983fe79cf77211996f200000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000160000000000000000000000000e4217040c894e8873ee19d675b6d0eec992c2c0d00000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000186cf0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000002e0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f00000000000000000000000053e0bca35ec356bd5dddfebbd1fc0fd03fabad390000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c2132d05d31c914a87c6611c10748aeb04b58e8f00000000000000000000000000000000000000000000000000000000000186cf0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000060d55f02a771d515e077c9c2403a1ef324885cec00000000000000000000000000000000000000000000000000000000000187040000000000000000000000000000000000000000000000000000000063a0c36a000000000000000000000000000000000000000000000000000000000000001bb338dc3c2a0c7fa5bfa8ff5cc1fb8b8ce81b0aa9870d1448cdd8d7aaa608e9e24828112fe325629bd6431c57ee432a753d2ca85a3b3b21ee8952c0687a0ea3d00000000000000000000000000ca2e42e8c21954af73bc9af1213e4e81d6a669a000000000000000000000000000000000000000000000000011c8055f942d30d0000000000000000000000000000000000000000000000000000000063a0c36a000000000000000000000000000000000000000000000000000000000000001c514bfa4c3fb665112886f2fbff024e35786e89a5e539643095599db58043f3ce33149cbfa7400bd87b3e3d0637538ec1c2e10b7b1393ab3e72358bb0c87826a0","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.3)

BUG2:
Calculation HF with enabling e-mode on v3 is wrong, counted without regard of e-mode
This applies to both new and old HF

calculation on the migration page
Screenshot 2022-12-19 at 19 11 45

real value
Screenshot 2022-12-19 at 19 11 58


BUG3:
Migration v2 asset which not included into in e-mode list migration failing

setup of case:

  • v3 - e-mode turn on
  • v2 LINK borrowed

if try to migrate LINK we get tx error

cannot estimate gas; transaction may fail or may require manual gas limit (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"id\":1166,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"execution reverted\",\"data\":{\"error_id\":\"ddd7b1f7-04c1-46a9-84dd-58bc9360188a\"}}}","error":{"code":-32000,"data":{"error_id":"ddd7b1f7-04c1-46a9-84dd-58bc9360188a"}},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"value\":\"0x0\",\"from\":\"0xe4217040c894e8873ee19d675b6d0eec992c2c0d\",\"to\":\"0x794a61358d6845594f94dc1db02a252b5b4814ad\",\"data\":\"0xab9c4b5d00000000000000000000000001ce9bbcc0418614a8bba983fe79cf77211996f200000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000160000000000000000000000000e4217040c894e8873ee19d675b6d0eec992c2c0d00000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000053e0bca35ec356bd5dddfebbd1fc0fd03fabad39000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000001634c5e3d99b5060000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000053e0bca35ec356bd5dddfebbd1fc0fd03fabad3900000000000000000000000000000000000000000000000001634c5e3d99b50600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000\"}],\"id\":1166,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"https://rpc.tenderly.co/fork/f1fcc2cc-c0ca-45c6-9f8b-92a4ab4b053f"}, method="estimateGas", transaction={"from":"0xE4217040c894e8873EE19d675b6d0EeC992c2c0D","to":"0x794a61358D6845594F94dc1DB02A252b5b4814aD","value":{"type":"BigNumber","hex":"0x00"},"data":"0xab9c4b5d00000000000000000000000001ce9bbcc0418614a8bba983fe79cf77211996f200000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000160000000000000000000000000e4217040c894e8873ee19d675b6d0eec992c2c0d00000000000000000000000000000000000000000000000000000000000001a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000053e0bca35ec356bd5dddfebbd1fc0fd03fabad39000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000001634c5e3d99b5060000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000053e0bca35ec356bd5dddfebbd1fc0fd03fabad3900000000000000000000000000000000000000000000000001634c5e3d99b50600000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000","accessList":null}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.5.3)

@MareskoY
Copy link
Contributor

MareskoY commented Jan 4, 2023

a new circle of testing brings new bugs @satanworker

BUG1:
after the first migration (of one asset) migration button stay in an active state with an open empty modal

Screenshot 2023-01-04 at 13 49 04

steps for reproduction:

  1. open migration tool
  2. migrate just one asset from 2+ total count of assets
  3. complete migration steps

should be:

  1. button has to be disabled
  2. checkbox have to go to false

BUG2:

  • if the v3 market is empty on the migration page toggles of collateral looks clickable, but it is not, need to disable there if we don't give the option for a customer to switch them

Screenshot 2023-01-04 at 14 16 14


BUG3:

  • wrong migration option with isolated mode

markets before migration

  • v2 has usdt as supply, usdc and link as borrow
  • v3 is empty

in this case we get
Screenshot 2023-01-04 at 14 19 03

where:

  • USDC - is not possible to migrate
  • LINK(and another assets which not include in isolated mode to borrow ) - possible

should be:

  • USDC(and another available assets in isolated mode) - is possible
  • LINK - is not possible

p.s. also this bug blocked some cases for testing


@satanworker
Copy link
Contributor Author

a new circle of testing brings new bugs @satanworker

BUG1: after the first migration (of one asset) migration button stay in an active state with an open empty modal

Screenshot 2023-01-04 at 13 49 04

steps for reproduction:

  1. open migration tool
  2. migrate just one asset from 2+ total count of assets
  3. complete migration steps

should be:

  1. button has to be disabled
  2. checkbox have to go to false

BUG2:

  • if the v3 market is empty on the migration page toggles of collateral looks clickable, but it is not, need to disable there if we don't give the option for a customer to switch them
Screenshot 2023-01-04 at 14 16 14

BUG3:

  • wrong migration option with isolated mode

markets before migration

  • v2 has usdt as supply, usdc and link as borrow
  • v3 is empty

in this case we get Screenshot 2023-01-04 at 14 19 03

where:

  • USDC - is not possible to migrate
  • LINK(and another assets which not include in isolated mode to borrow ) - possible

should be:

  • USDC(and another available assets in isolated mode) - is possible
  • LINK - is not possible

p.s. also this bug blocked some cases for testing

Good to see previous bugs with HF are fixed, 2 first bugs looks minor, but the last one is weird, looking into it

@MareskoY
Copy link
Contributor

MareskoY commented Jan 5, 2023

@satanworker there is one more issue

in case of switching market on another tab migration page upload data from another market

steps:

  1. TAB1: open migration page from polygon v2
  2. TAB2: switch to polygon v3
  3. TAB1: Refresh page

result:

  • TAB1: upload and show data(assets) from polygon v3 - have to stay on the market from which we switch to the migration page

@satanworker
Copy link
Contributor Author

closed due to #1442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants