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

Support LSE collateral auctions #622

Merged
merged 28 commits into from
Oct 22, 2024
Merged

Support LSE collateral auctions #622

merged 28 commits into from
Oct 22, 2024

Conversation

valiafetisov
Copy link
Contributor

Adds support for the upcoming new type of auctions based on the new and untypical LockstakeClipper contract.

Note: the addition require multiple code refactorings:

  • Non-standard contract names in the chainlog required specifying exact contract names in the config for all collateral
  • Non-standard swapping path required specifying start and end path for all collaterals in the config
  • ...etc

@valiafetisov
Copy link
Contributor Author

valiafetisov commented Oct 21, 2024

LSE auction is successfully executed on the mainnet_sep_30_0 testnet using both bot and the frontend. Note that the CI is failing due to the new collateral is not yet initialised on the mainnet. Should pass after 1c executive spell is casted.

Logs of the bot
ℹ WHITELISTED_COLLATERALS is provided, only fetching auctions of type "ETH-A, LOCKSTAKE"                                                                                                          14:10:02
ℹ wallet: setup complete, using wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"                                                                                                               14:10:02
ℹ collateral keeper: setup complete, looking for minimum net profit of "-100000000" DAI                                                                                                           14:10:02
ℹ collateral auctions: found "1" auctions "LOCKSTAKE:1" on "custom" network                                                                                                                       14:10:02
ℹ collateral auctions: "0" of "1" auctions are new                                                                                                                                                14:10:02
ℹ collateral keeper: auction "LOCKSTAKE:1" is not yet executable (current gross profit: -380 DAI)                                                                                                 14:10:02
ℹ collateral auctions: found "1" auctions "LOCKSTAKE:1" on "custom" network                                                                                                                       14:10:04
ℹ collateral auctions: "0" of "1" auctions are new                                                                                                                                                14:10:04
ℹ collateral keeper: auction "LOCKSTAKE:1" is not yet executable (current gross profit: -158 DAI)                                                                                                 14:10:20
ℹ collateral auctions: found "1" auctions "LOCKSTAKE:1" on "custom" network                                                                                                                       14:10:22
ℹ collateral auctions: "0" of "1" auctions are new                                                                                                                                                14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1" gross profit is 7 DAI, moving on to check net profit                                                                                                   14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1" net profit is 3 DAI after transaction fees, moving on to the execution                                                                                 14:10:22
ℹ keeper: wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" has not been authorized yet. Attempting authorization now...                                                                        14:10:22
ℹ Transaction is preparing to be mined...                                                                                                                                                         14:10:22
ℹ Transaction is pending to be mined...                                                                                                                                                           14:10:22
ℹ Transaction was mined into block "20864054"                                                                                                                                                     14:10:22
ℹ keeper: wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" successfully authorized via "0x0c54bc7f50c0d3e992b19020a5b5e266760cf6f0a13166b2458e972558f547b6" transaction                        14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1" gross profit is 7 DAI, moving on to check net profit                                                                                                   14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1" net profit is 4 DAI after transaction fees, moving on to the execution                                                                                 14:10:22
ℹ keeper: wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" has already been authorized                                                                                                         14:10:22
ℹ keeper: collateral "LOCKSTAKE" has not been authorized on wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" yet. Attempting authorization now...                                              14:10:22
ℹ Transaction is preparing to be mined...                                                                                                                                                         14:10:22
ℹ Transaction is pending to be mined...                                                                                                                                                           14:10:22
ℹ Transaction was mined into block "20864055"                                                                                                                                                     14:10:22
ℹ keeper: collateral "LOCKSTAKE" successfully authorized on wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" via "0x8d24a599a1a07e54b648abb4eb6a92a6bdd8ec837ea0f6849690b92536fbedaf" transaction
ℹ collateral keeper: auction "LOCKSTAKE:1" gross profit is 8 DAI, moving on to check net profit                                                                                                   14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1" net profit is 5 DAI after transaction fees, moving on to the execution                                                                                 14:10:22
ℹ keeper: wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" has already been authorized                                                                                                         14:10:22
ℹ keeper: collateral "LOCKSTAKE" has already been authorized on wallet "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"                                                                               14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1": attempting swap execution                                                                                                                             14:10:22
Duplicate definition of File (File(bytes32,uint256), File(bytes32,address))                                                                                                                       14:10:22
ℹ Transaction is preparing to be mined...                                                                                                                                                         14:10:22
ℹ Transaction is pending to be mined...                                                                                                                                                           14:10:22
ℹ Transaction was mined into block "20864056"                                                                                                                                                     14:10:22
ℹ collateral keeper: auction "LOCKSTAKE:1" was succesfully executed via "0x2b43caa5eb81df62193695a17e6f2bdcb03cf2e86a1ffbaecbdf2baba32df03f" transaction                                          14:10:22
ℹ DAI VAT   profit from the transaction: 0                                                                                                                                                        14:10:22
ℹ DAI ERC20 profit from the transaction: 8.255878516957174195                                                                                                                                     14:10:22
ℹ collateral auctions: found "0" auctions "" on "custom" network                                                                                                                                  14:10:24

@valiafetisov
Copy link
Contributor Author

Functional testing

  1. Using tenderly testnet

    1. Copy HTTP RPC url from the testnet. E.g.: for the mainnet_sep_30_0 that would be
    https://virtual.mainnet.rpc.tenderly.co/b333d3ac-c24f-41fa-ad41-9176fa719ac3
    
    1. Configure auction simulations by editing core/.env file. Using url from the above it would be:
    LOCAL_RPC_URL="http://127.0.0.1:8545"
    REMOTE_RPC_URL="https://virtual.mainnet.rpc.tenderly.co/b333d3ac-c24f-41fa-ad41-9176fa719ac3"
    
  2. Run simulation inside hardhat

    1. Change node version to 16 (using nvm or n)
    2. Install node modules via npm install
    3. Start simulations npm run simulate inside core folder
    4. Select via keyboard
      • Create collateral auction -> enter
      • Block number to fork from -> enter
      • Select the collateral type -> LOCKSTAKE/LSE-MKR-A
      • Create underwater vault -> enter
      • Liquidate the vault -> enter
      • Skip time -> wait till you have frontend running
  3. Start frontend

    1. Configure frontend by editing frontend/.env with RPC_URL="http://127.0.0.1:8545"
    2. Open another terminal tab to start frontend
    3. Install node modules via npm install (using the same node 16)
    4. Run npm run dev
    5. Open http://localhost:3000/collateral to see collateral auctions
    6. Connect hardhat wallet to frontend. Use one of the hardhat default addresses to test participation, e.g.:
      ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
      
    7. Participate in the auction (if not yet executable, you can switch back to the simulation tab and then "Skip time" a few times)

Copy link
Contributor

@LukSteib LukSteib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Getting an error in the simulation step create underwater vault (see console error below)
✔ Press Enter to proceed to the next step "Create underwater vault" … 
Transaction is preparing to be mined...
Transaction is pending to be mined...
Transaction was mined into block "20863585"
Initial oracle price is 1000 DAI
Duplicate definition of File (File(bytes32,uint256), File(bytes32,bytes32,uint256), File(bytes32,bytes32,address))
Duplicate definition of File (File(bytes32,uint256), File(bytes32,address))
Duplicate definition of File (File(bytes32,uint256), File(bytes32,bytes32,uint256), File(bytes32,bytes32,address))
Duplicate definition of File (File(bytes32,uint256), File(bytes32,address))
Minimum collateral amount to open vault: 33.011
Balance slot is 0x1, language format is solidity, contract address is 0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2
Wallet has 33.011 MCD_GOV
Duplicate definition of File (File(bytes32,address), File(bytes32,uint256))

/Users/lukassteib/Github/unified-auctions-ui/core/node_modules/@ethersproject/logger/src.ts/index.ts:261
        const error: any = new Error(message);
                           ^
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (error={"reason":"Error: VM Exception while processing transaction: reverted with reason string 'LockstakeEngine/wrong-urn-index'","code":"UNPREDICTABLE_GAS_LIMIT","method":"estimateGas","transaction":{"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"maxFeePerGas":{"type":"BigNumber","hex":"0x59682f02"},"to":"0x9581c795DBcaf408E477F6f1908a41BE43093122","data":"0x690e7c090000000000000000000000000000000000000000000000000000000000000001","type":2,"accessList":null},"error":{"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"id\":74,\"error\":{\"code\":-32603,\"message\":\"Error: VM Exception while processing transaction: reverted with reason string 'LockstakeEngine/wrong-urn-index'\",\"data\":{\"message\":\"Error: VM Exception while processing transaction: reverted with reason string 'LockstakeEngine/wrong-urn-index'\",\"data\":\"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f4c6f636b7374616b65456e67696e652f77726f6e672d75726e2d696e64657800\"}}}","error":{"code":-32603,"data":{"message":"Error: VM Exception while processing transaction: reverted with reason string 'LockstakeEngine/wrong-urn-index'","data":"0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f4c6f636b7374616b65456e67696e652f77726f6e672d75726e2d696e64657800"}},"requestBody":"{\"method\":\"eth_estimateGas\",\"params\":[{\"type\":\"0x2\",\"maxFeePerGas\":\"0x59682f02\",\"maxPriorityFeePerGas\":\"0x59682f00\",\"from\":\"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266\",\"to\":\"0x9581c795dbcaf408e477f6f1908a41be43093122\",\"data\":\"0x690e7c090000000000000000000000000000000000000000000000000000000000000001\"}],\"id\":74,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"http://127.0.0.1:8545"}}, tx={"data":"0x690e7c090000000000000000000000000000000000000000000000000000000000000001","to":{},"from":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","type":2,"maxFeePerGas":{"type":"BigNumber","hex":"0x59682f02"},"maxPriorityFeePerGas":{"type":"BigNumber","hex":"0x59682f00"},"nonce":{},"gasLimit":{},"chainId":{}}, code=UNPREDICTABLE_GAS_LIMIT, version=abstract-signer/5.6.2)
    at Logger.makeError (/Users/lukassteib/Github/unified-auctions-ui/core/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/Users/lukassteib/Github/unified-auctions-ui/core/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at /Users/lukassteib/Github/unified-auctions-ui/core/node_modules/@ethersproject/abstract-signer/src.ts/index.ts:301:31
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 7)
ERROR: "hardhat:simulations" exited with 1.

@valiafetisov
Copy link
Contributor Author

I've updated opening logic, which should solve the problem.

Also note: since the 1c spell was already executed you no longer need to use Tenderly Testnet, but can directly test against mainnet simulation.

@valiafetisov valiafetisov marked this pull request as ready for review October 21, 2024 16:07
Copy link
Contributor

@LukSteib LukSteib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes:

  • Able to create and liquidate LSE-MKR-A vault via hardhat simulation ✅
  • Auction is fetched in UI with right amount of MKR as collateral ✅
  • Was able to participate in auction via swap transaction ✅
  • Profit indication was correct ✅ (just overestimating fees on fork) (see Dai balance before, estimations and Dai balance after)
  • Bid with DAI flow 🔴

Dai balance before
Screenshot 2024-10-21 at 17 57 52

Estimations
Screenshot 2024-10-21 at 17 57 29

Dai balance after:
Screenshot 2024-10-21 at 17 58 29


Review requests:

  • NIT: The Bid wit Dai modal shows MCD_GOV instead of MKR (see s1)
  • In the bid with DAI flow when trying to deposit DAI to VAT getting Internal JSON RPC error (see e1 for console screenshot)

s1
image

e1
image


Questions:

  • I would expect the correct (or at least a realistic MKR price from uniswap) (see s2) based on us forking mainnet at a very recent block. Is this assumption wrong?
  • What's the exchange route the new callee is using?

s2
image

@valiafetisov
Copy link
Contributor Author

In the bid with DAI flow when trying to deposit DAI to VAT getting Internal JSON RPC error (see e1 for console screenshot)

Most likely you forgot to reset nonce after swapping in your metamask settings. Every time you restart the simulation, you need to go into 3 dots -> Settings -> Advanced -> Clear activity tab data.

What's the exchange route the new callee is using?

The MKR is currently directly exchanged in the MKR/DAI uniswap pool.

I would expect the correct (or at least a realistic MKR price from uniswap) (see s2) based on us forking mainnet at a very recent block.

Most likely a simulation issue unrelated to this PR. Let's look into it in another issue

Copy link
Contributor

@LukSteib LukSteib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next review iteration:

  • able to use bid with DAI flow ✅

Requests:

  • not able to withdraw MKR from VAT after succesfull auction participation (no MKR balance displayed neither in auction flow s1 nor in collateral popup s2)

s1
image

s2
image

@valiafetisov
Copy link
Contributor Author

not able to withdraw MKR from VAT after succesfull auction participation

There is no MKR in VAT because this collateral is different from all others and have no join contract which normally holds VAT deposits. When you take LSE-MKR-A auction with DAI, plain MKR tokens lend directly into your wallet. You can check that by importing MKR tokens into your Metamask and checking the balance.

LukSteib
LukSteib previously approved these changes Oct 21, 2024
@valiafetisov
Copy link
Contributor Author

I've replaced MKR/DAI Uniswap v2 market with SKY/USDS. Also improved indication of the market on the frontend:

Screenshot 2024-10-21 at 23 31 04

Copy link
Contributor

@LukSteib LukSteib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • IMO after changing to the new pool we should update the UI as well to denominate values in USDS instead of DAI. After swap based execution we will end up with user receiving USDS and displaying the net profit in DAI might cause confusion in a way the user expects to receive DAI

Copy link
Contributor

@LukSteib LukSteib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Sorry for being picky here but having the following assumption: There is a difference in the price per MKR on uniswap when comparing USDS and DAI. The calculations we make in the UI are based on the DAI price. However, since the actual swap is happening via USDS I have a feeling that the calculations are slightly off.

What UI shows:
image

Uniswap UI for swap of DAI / MKR
image

Uniswap UI for swap of USDS / MKR
image

@valiafetisov
Copy link
Contributor Author

The calculations we make in the UI are based on the DAI price

This is not true. For this particular token, the swap is done like so: MKR is auctioned for DAI or USDS by the lockstake clipper, callee takes MKR converts it into SKY using maker converter with fixed rate and then use SKY/USDS univ2 pool to convert it to USDS. So technically it's correct to say that Market Unit Price (Uniswap V2) 1,173.08 USDS per MKR. It's just the path is a bit longer (via SKY as also indicated in the UI). But we had the same simplification for other collaterals in the past: for example, WSTETH-A is also shown as DAI per WSTETH while the path is much longer than WSTETH -> DAI (unwrap -> unstake -> swap)

@LukSteib
Copy link
Contributor

Makes sense, thanks for the explainer. I think the root of my confusion was the different denominations for the auction price. While on the swap page we now have the denomination USDS per MKR (which is good) in the table (see s1) and on the first auction page (see s2) we keep denominating the auction price in DAI per MKR.
Do you think it's fine to keep as is since as you outlined MKR is auctioned for DAI or USDS or would you change it in the other places as well since we decided to leverage the USDS route for the swap?

s1
image

s2
image

@valiafetisov
Copy link
Contributor Author

Do you think it's fine to keep as is since as you outlined MKR is auctioned for DAI or USDS or would you change it in the other places as well since we decided to leverage the USDS route for the swap?

Since DAI and USDS are 1-to-1 convertible into each other, I don't think this indication is a problem. Since on the "Bid with DAI" page we would still need to display everything in DAI.

But ultimately, I don't know a perfect solution for this duality UI-wise, since it's a quite complex issue. In fact the same collateral (LSE-MKR-A) can be traded both with DAI or USDS. So currently (the way it is implemented) indicated profit token depends on the selected market: if we are to add MKR/DAI as a second market, switching to it will result in different profit token being displayed in the swap table. In other words it's already quite complex UI-wise, let's first ensure that this collateral is liquidatable by merging this PR and then fix what is displayed on the frontend. I think your initial concern (of confusing the user with incorrectly specified profit token) is resolved now.

@LukSteib LukSteib merged commit 02a0f1c into main Oct 22, 2024
8 checks passed
@LukSteib LukSteib deleted the add-lse-collateral-auctions branch October 22, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants