ref-finance / ref-contracts

Smart contracts for Ref Finance
MIT License
96 stars 55 forks source link

Swap calculates the amount of token in instead of token out #20

Open mehtaphysical opened 3 years ago

mehtaphysical commented 3 years ago

Right now swap is expecting an amount for the token in and will calculate the amount of the token out.

What if we added a feature to set how much token out we want from the swap and then calculate the amount of token in is required. We could do this sort of calculation on the front-end and set the min amount out appropriately, but there is a chance that we over pay and get more out than we wanted.

This would allow people to use the swap for "Buy Now" buttons that allow people to pay in any token:

With out this, the buyer could receive more wNEAR than the sale price.

If this sounds good I'm happy to make a PR.