Badger-Finance / badger-strategies

5 stars 1 forks source link

[TECH] bveCVXBribesProcessor - onChain Pricing POC + Fair Selling with Cowswap Integration #46

Closed GalloDaSballo closed 2 years ago

GalloDaSballo commented 2 years ago

Strategy Review

Description

Plaintext logic. Can be a link to README or other doc.

Code Link

https://github.com/GalloDaSballo/fair-selling/tree/poc.0

Due Diligence Document (Link, but could also just be a .md file in repo)

For the onChain Pricing see our work on DCA Vaults As well as HarleyTheDog's Peer Review

For Cowswap see their docs and work

Additionally, some of the work in this contract will be informally reviewed by Gnosis and Balancer Developers, as well as some additional help by Poolpi (Yearn Dev, and author of the original CowSwap Gnosis Safe Tutorial)

Deployed Contract (If present)

OnChainPricingMainnet (UniV2, Sushi, Curve): https://etherscan.io/address/0x330ef672417412a80960b48c77c7891b39df3d5c

CowswapDemoSeller (only for my EOA), only for demo swap purposes: https://etherscan.io/address/0x684E4AE5B28f251642E50AEcf8C5D469723f68Ae

SOON -> bveCVXBribesProcessor

Review By

Review by Security Board

Test Checks (screen shot of all test passing)

GalloDaSballo commented 2 years ago

Deployment (POC / DO NOT USE IN PROD)

OnChainPricingMainnet (UniV2, Sushi, Curve): https://etherscan.io/address/0x330ef672417412a80960b48c77c7891b39df3d5c

CowswapDemoSeller (only for my EOA), only for demo swap purposes: https://etherscan.io/address/0x684E4AE5B28f251642E50AEcf8C5D469723f68Ae

GalloDaSballo commented 2 years ago

DEMO: Sent 0.035 WETH https://etherscan.io/tx/0x59af599890650b34090b36efdaf1f1b6d466065ffcc8669b31ec82527db9bc53

>>> from scripts.send_order import get_cowswap_order
>>> weth = interface.ERC20("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
>>> usdc = interface.ERC20("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
>>> seller = CowSwapDemoSeller.at("0x684E4AE5B28f251642E50AEcf8C5D469723f68Ae")
>>> dev = accounts.load("hot")
>>> order = get_cowswap_order(seller, weth, usdc, weth.balanceOf(seller))

Payload: {'sellToken': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 'buyToken': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'sellAmount': '31913580246913581', 'buyAmount': '90061296', 'validTo': 1647562491, 'appData': '0x2B8694ED30082129598720860E8E972F07AA10D9B81CAE16CA0E2CFB24743E24', 'feeAmount': '3086419753086419', 'kind': 'sell', 'partiallyFillable': False, 'receiver': '0x684E4AE5B28f251642E50AEcf8C5D469723f68Ae', 'signature': '0x684E4AE5B28f251642E50AEcf8C5D469723f68Ae', 'from': '0x684E4AE5B28f251642E50AEcf8C5D469723f68Ae', 'sellTokenBalance': 'erc20', 'buyTokenBalance': 'erc20', 'signingScheme': 'presign'}
Order uid: 0x75195a3c3a11730d6b032ef9035d280cc11463c5df127d38e7ab42781b940f23684e4ae5b28f251642e50aecf8c5d469723f68ae6233cefb
GalloDaSballo commented 2 years ago
Screenshot 2022-03-18 at 00 13 45

In this instance cowswap quotes us 8 wei too little so we seem to be getting a revert. Will wait for better conditions to get a swap to go

GalloDaSballo commented 2 years ago
Screenshot 2022-03-18 at 00 15 39

I got a second order and got a better price and as such this one went through

GalloDaSballo commented 2 years ago
Screenshot 2022-03-18 at 00 16 47

The order has now been received by Cowswap and will be processed within 1 hour (or expire)

GalloDaSballo commented 2 years ago

Note: Prod API is here: https://protocol-mainnet.gnosis.io/api/v1/solvable_orders

GalloDaSballo commented 2 years ago

There it is!!! https://etherscan.io/tx/0x7039c17e061e5530786e71aaabfa2783ce68dd648e2f19411e37a13efa5de154 COWWWWWWWED

GalloDaSballo commented 2 years ago

Had multiple layers of feedback that I'll incorporate for next steps

GalloDaSballo commented 2 years ago

Closing in favour of new issue to keep it simple