weweswap / contracts

smart contracts
MIT License
1 stars 4 forks source link

ADD: WEWE-VULT Merge Contract #16

Closed jpthor closed 1 month ago

jpthor commented 2 months ago

Context

WEWE holders can merge into VULT

Implementation

The Merge Contract is given 10m VULT and 10bn WEWE. The starting ratio is 1:1000.

It is Owned. The Owner cannot withdraw, but can set a flag for Two-way. Default is not enabled.

allowTwoWay = 0 | 1

Use Approve And Call Flow

weweContract
approveAndCall(mergeContract, balance, handler){}

mergeContract
receiveApproval(msg.sender, amount, wewe, bytes){
if(wewe){
   weweContract.transferFrom(msg.sender, amount);
   mergeWEWEforVULT()
   }
if(vult){
   vultContract.transferFrom(msg.sender, amount);
   mergeVULTforWEWE()
   }
}

Merge Math

The math is

w: input WEWE
v: output VULT
W: WEWE Balance
V: VULT Balance

v = (w*V)/(w+W)

Make sure is a public function to compute the math ahead of time, so the interface can "quote" the user on how much VULT they will get.

image

Direction

If owner allows TwoWay, then VULT holders can go back to WEWE.

Lock

The owner of the VULT Token on Base can lock it. Use _beforeTransferHook() to stop the user moving their VULT after the merge until the Owner allows them to.

jp-smart commented 2 months ago

based on the formular above, if allowTwoWay is on, then w = (W*v)/(V-v)