dexie-space / partial-cli-beta

Partial Offer WIP
3 stars 0 forks source link

Replace `RATE` with `REMAINING_AMOUNT` #8

Open Yakuhito opened 4 days ago

Yakuhito commented 4 days ago

Note: Best implemented after SELF_HASH

If you want to implement CAT-CAT swaps as well, precision will become a problem. Instead by multiplying RATE by a constant and then dividing the output amount, you can 'borrow' the mechanism of AMM liquidity distribution.

In short, every coin will have its amount, my_amount (the amount of asset to offer), and REMAINING_AMOUNT, the remaining amount of the asset to receive (if you can find a better naming thing, go for it!). When a user gives partial_amount <= REMAINING_AMOUNT from the coin, they'll receive my_amount * partial_amount / REMAINING_AMOUNT.

Note that doing it this way (as opposed to calculating what the user should give based on given_amount / my_amount) will slightly favor the partial coin until the very last trade.