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

Sell Pressure Dampening via Transfer Hook - Proof of Concept #347

Closed
zgorizzo69 opened this issue Nov 28, 2022 · 14 comments
Closed

Sell Pressure Dampening via Transfer Hook - Proof of Concept #347

zgorizzo69 opened this issue Nov 28, 2022 · 14 comments
Assignees
Labels
Research Bounties that may include a report only, without code. Solidity Solidity development work is expected.

Comments

@zgorizzo69
Copy link
Contributor

zgorizzo69 commented Nov 28, 2022

Let's say that a whale is selling huge amount of uAD on the curve metapool. This can very affect the peg and trigger an unwanted chain of events leading to a bank run.
The idea is to use the transfer hook to detect and counter that sell with a one sided liquidity provision
so the flow is
use sells uAD from uAD-3crv metapool
that triggers a hook that will transfer an ERC20 (e.g) to the metapool as a one sided liquidity
the erc20 belongs to the hook contract and only the hook contract can provide it as liquidity and thus receive the corresponding LP token

  • POC to make sure it is safe and sound
  • it should trigger is uAD sell is > X Amount
  • it should provide Y Amount of DAI USDC USDT as liquity where Y = z * X
  • Nice-to-have accurate calculation of the price change due to the liquidity deposit

estimation between 1 and 2 days

@zgorizzo69 zgorizzo69 added Solidity Solidity development work is expected. Time: <1 Week labels Nov 28, 2022
@zgorizzo69 zgorizzo69 self-assigned this Nov 28, 2022
@0x4007
Copy link
Member

0x4007 commented Nov 28, 2022

Reference #218

@0x4007
Copy link
Member

0x4007 commented Nov 28, 2022

  • it should trigger is uAD sell is > X Amount

POC should be as simple as possible but ideally if you can do it off of post-swap-price e.g. (0.98 and below)

@0x4007 0x4007 changed the title prevent whales to mess with ubq peg Sell Pressure Dampening via Transfer Hook - Proof of Concept Nov 28, 2022
@zgorizzo69
Copy link
Contributor Author

zgorizzo69 commented Dec 2, 2022

Report for sell pressure Dampening

0x10693e86f2e7151B3010469E33b6C1C2dA8887d6

Transfer hook

to fight a big sell off the idea was to leverage the transfer hook to immediately counter it by adding 3CRV in the curve pool

I started by adding an incentive contract + test on this branch to assess the price change I simulate a balance change and get the price based on the updated balances.

As seen in the test either swapping or adding liquidity fails and the reason is reentrancy guard inside curve metapool

image

indeed the transfer hook happens inside the swap function when the metapool is tranfering uAD from the seller. It is then impossible to add liquidity to curve when we sell on curve.

Another idea is to instead add liquidity to uniswap pool (uAD/DAI for instance) when we sell on curve and add liquidity to curve when we sell on curve
The drawbacks are

  • there could be several uniswap pool (uAD/DAI uAD/USDC uAD/USDT etc..)
  • liquidity is not really the same between curve and uniswap
  • Our oracle only take into account curve
  • adding liquidity on uniswap is even more expensive than curve

Offchain Automation

We can monitor for transfer event from the metapool to detect a sell and based on the same calculation as before trigger a tx that will provide liquidity to the curve pool. This can be done with Open Zeppelin defender for instance as they not only provide a convenient event watcher but also a relay that includes a private key secure storage.

@pavlovcik wants a fully onchain mechanism

@0x4007 0x4007 added the Research Bounties that may include a report only, without code. label Dec 2, 2022
@0x4007
Copy link
Member

0x4007 commented Dec 2, 2022

The drawbacks are

  • there could be several uniswap pool (uAD/DAI uAD/USDC uAD/USDT etc..)

Lets only do whatever the collateral reserve is in (LUSD/RAI/ETH?)

  • liquidity is not really the same between curve and uniswap

We can arbitrage this (and profit?) with transfer hooks. Famously coined by 1inch "positive slippage"

  • Our oracle only take into account curve

Because theres profit with arbitraging, I think that this should be resolved naturally by market forces.

  • adding liquidity on uniswap is even more expensive than curve

We should consider using a rollup that Uniswap is on. We also must define what liquidity range. Probably 1 tick below market price and down to 1.00 would make the most sense for adding single sided liquidity. We could also recycle NFT positions that we already made, for example, always add to the NFT position we made at $1.00 - $1.000001 etc

@0x4007
Copy link
Member

0x4007 commented Dec 2, 2022

I'll release the bounty but I hope that we can continue working on this research together. I see your wallet address at the top of report (as confirmed in our Telegram chat)

0x10693e86f2e7151B3010469E33b6C1C2dA8887d6

https://etherscan.io/tx/0xaa514f34d2e6d0903e889b12c889c75dc4b54a3d2b4f50410ac3fd09716fc820
https://etherscan.io/tx/0x0d24b00399566d0b84c04ad10a5a56a3a91fefa15184156bb50610f93593848f

@zgorizzo69
Copy link
Contributor Author

The drawbacks are

  • there could be several uniswap pool (uAD/DAI uAD/USDC uAD/USDT etc..)

Lets only do whatever the collateral reserve is in (LUSD/RAI/ETH?)

it depends if we want an absolute peg to $USD

  • liquidity is not really the same between curve and uniswap

We can arbitrage this (and profit?) with transfer hooks. Famously coined by 1inch "positive slippage"

arbitrage here would mean buy cheap uAD for 3CRV on curve thus increasing its price on curve and sell it on uniswap
thus decreasing its price on uniswap and getting back a stable coin (or $ETH/ $RAI)

  • Our oracle only take into account curve

Because theres profit with arbitraging, I think that this should be resolved naturally by market forces.

I agree with that

  • adding liquidity on uniswap is even more expensive than curve

We should consider using a rollup that Uniswap is on. We also must define what liquidity range. Probably 1 tick below market price and down to 1.00 would make the most sense for adding single sided liquidity. We could also recycle NFT positions that we already made, for example, always add to the NFT position we made at $1.00 - $1.000001 etc

so making a cross chain call from mainnet (triggered by the transfer hook) to let say optimism uniswap pool uAD/LUSD
I will check that up

@0x4007
Copy link
Member

0x4007 commented Dec 2, 2022

it depends if we want an absolute peg to $USD

Economically I think that floating, like RAI, makes more sense; but from an adoption standpoint I think that "absolute peg" makes more sense for normal people to use and understand.

arbitrage here would mean buy cheap uAD for 3CRV on curve thus increasing its price on curve and sell it on uniswap thus decreasing its price on uniswap and getting back a stable coin (or $ETH/ $RAI)

And getting back LUSD/RAI/ETH(?) and then storing it back in the collateral reserve, yes. That, or ideally putting it right back into the market but I don't think thats possible due to re-entrancy.

so making a cross chain call from mainnet (triggered by the transfer hook) to let say optimism uniswap pool uAD/LUSD I will check that up

No I think that we should consider a full new protocol deployment on Optimism etc if we're going to depend heavily on complex logic for transfer hooks for stability etc.


We might have to do the boring, simple solution of letting people take their uAD and redeeming directly from our collateral reserve, and letting those people arbitrage to save the price.

@0x4007
Copy link
Member

0x4007 commented Dec 5, 2022

Does it make sense to preserve your code in some type of tests/research folder? I fear if it only lives on some obscure branch that it may get deleted on accident at some point in the future.

@0x4007
Copy link
Member

0x4007 commented Dec 17, 2022

@zgorizzo69 following up on my previous comment.

@zgorizzo69
Copy link
Contributor Author

I think we can fork that branch to another repo indeed if we are worried about it being deleted

@0x4007
Copy link
Member

0x4007 commented Dec 17, 2022

Okay I'll let you handle that cause I'm not sure exactly what you mean.

@zgorizzo69
Copy link
Contributor Author

Okay I'll let you handle that cause I'm not sure exactly what you mean.

actually I created a tag and we also can create a release if you want
image

@0x4007
Copy link
Member

0x4007 commented Dec 17, 2022

Seems cleaner than making separate repos. Sure let's use tags.

@ubiquibot
Copy link

ubiquibot bot commented Jun 3, 2023

Permit generation skipped because the issue was not closed as completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Research Bounties that may include a report only, without code. Solidity Solidity development work is expected.
Projects
None yet
Development

No branches or pull requests

2 participants