Open naddison36 opened 1 year ago
Okay, here's a radical simplification idea.
Currently our best case execution is 2% fee plus 0.6% swap. Our worse case is 2% fee plus 3% slippage + swap (total 5%). Instead of hardcoding a swap path, or even doing any swap, a harvest()
method could just offer tokens at a discount rate.
The harvester would:
So we offer a discount off the oracle price. The swapper profits/pays for gas by keeping the difference. We could have a discount ramp over time from 0% to 4%, over nine days from the last harvest.
But it now up to the swappers to get good execution on the swaps. We don't have to write any code evermore to follow the ever shifting liquidity / fees.
(We could have an example swap contract we deploy that let people run harvests with no contract writing skill, as a baseline.)
I like this idea @DanielVF
The callback will transfer the target asset back to the harvester or dripper, correct? eg USDT FYI, I did something similar for wallet swaps https://github.com/naddison36/abstract-accounts#dexwallet
Another alternative is we reuse the collateral swap solution being built for OETH. https://github.com/OriginProtocol/origin-dollar/issues/1518
Or the Harvester be a market maker on asynchronous DEXs like 0x Protocol, CoW swap, 1Inch Fusion or 1Inch limit orders. That is, the Harvester publishes the swap order for market makers to fill.
One concern I have for the radical simplification idea is how discoverable this will be to arbitragers. I know MEV is good these days, but is it that good?
The caller has to be a contract that implements the swap in a callback function and transfers an amount of USDT back to the harvester. The caller gets to keep any extra USDT they acquire from the swap to cover the gas costs and incentive to execute the tx. Ideally there would be an existing standard/protocol for this to increase the likelihood that arbitragers will call the harvest function.
What we are really doing here is market making swaps from reward tokens like CRV and CVX back to a stablecoins. eg USDT. Publishing our limit orders on a protocol that offers price discovery and a standard way of executing the swap will increase the changes the swap will be executed.
I think asynchronous DEXs like CowSwap and 1Inch Fusion can do this. As an example using CowSwap, we'd have an automated job that publishes the Harvester's limit order to the CowSwap API, which is an off-chain marketplace. CowSwap Solvers then compete to fill the order. The winning Solver executes the swap by transferring the CRV from the Harvester via CowSwap's settlement contract, the Solver does the swap and transfers the USDT back to the Harvester. The solver pays for the gas to do this. Its also worth noting that the solvers are competing so there is incentive to transfer back more USDT than what the Harvester was asking for as a minimum.
1Inch Fusion works different in its a dutch auction. The Harvester publishes a high CRV to USDT swap price and over time the price drops until it becomes economical for an arbitrager to execute the swap. Again, there is competition for the best swap price and gas is paid for by the arbitrager.
As part of the vault collateral swap, I looked at the 0x Protocol but it can't be used for this as contracts, the Harvester, can't sign limit orders that are published to the protocol.
I really like the idea of publishing our swap transactions to CowSwap or 1Inch thus greatly increasing the discoverability of our Harvester ( maybe also Buyback transactions) transactions and we should be getting better swap prices.
If I understand correctly the CowSwap & 1Inch would require us to take control of when the limit order swaps are published. Meaning that we can not keep the profit sharing incentive we have with the executor of the swap ensuring swaps will execute without any off-chain keepers running.
I think for Harvester and Buyback ( https://github.com/OriginProtocol/origin-dollar/issues/1560 ) the ideal composition of swap properties would be to include both:
Below is the current state of Harvesting the CVX and CRV rewards from the Convex based OUSD strategies.
Even with the AMO Harvest being profitable, there is either not enough incentive or discoverability for arbitragers to run the swap and harvest function.
The OUSD Convex OUSD+3Crv (AMO) strategy hasn't been run in 12 days. It is current collecting 200.88 USDT from CVX and 2,316.60 USDT from CRV rewards. With 2.009 + 46.332 = 48.34 USDT paid to the harvester, it is economical with $19.15 in gas costs (601,607 gas used with 20 Gwei gas price). Simulation of the harvest and swap https://dashboard.tenderly.co/nicka-origin/project/simulator/1d7e0ff9-c8e2-4f72-815e-8c24c64397ac The real harvest and swap tx run by myself 0xc619d2298797e8e0c8ab9d7677259684bede99fef1d14d7a250dc493b6b8e22b
The OUSD Convex DAI+USDC+USDT strategy is current collecting 42.04 USDT from CVX and 488.79 USDT from CRV rewards. With only 0.42 + 9.776 = 10.196 USDT paid to the harvester, it is not economical with $17.48 in gas costs (549,109 gas used with 20 Gwei gas price). Simulation of the harvest and swap https://dashboard.tenderly.co/nicka-origin/project/simulator/942387e7-9677-4c5e-aea3-8de61d742d14
The OUSD Convex LUSD+3Crv strategy is current collecting 6.55 USDT from CVX and 76.29 USDT from CRV rewards. With only 0.065 + 1.526 = 1.591 USDT paid to the harvester, it is not economical with $18.31 in gas costs (575,330 gas used with 20 Gwei gas price). Simulation of the harvest and swap https://dashboard.tenderly.co/nicka-origin/project/simulator/9f6e147b-d243-4804-9315-10ea6ef61398
The OUD Harvester is currently configured to pay 1% of USDT from the swapped CVX to the harvester and 2% of the USDT from the swapped CRV.
Some simple changes to the Harvester that could help
But I think the longer term solution should be implemented rather than an these shorter term changes.
I've also run the OETH Harvester https://etherscan.io/tx/0xcac8394f80e566a19ff46b98d0018e5db93dad4c53d5c42b3d6780419089b4ad
Some Dune queries
USDT flowing through the OUSD Dripper
https://dune.com/queries/2621709/4351258
WETH flowing through the OETH Dripper
0xSplits's Swapper contract is doing what @DanielVF has suggested. I still think the problem is discovery of the swap.
As identified in https://github.com/OriginProtocol/origin-dollar/issues/1448, there is not much CRV->USDT liquidity in SushiSwap for the OUSD Harvester. This change is to replace SushiSwap with Uniswap V3. This will require a contract change the Uniswap V3 interface is different to V2.
OUSD liquidations CRV->USDT CVX->USDT
OETH liquidations CRV->WETH CVX->WETH