smart-contracts icon indicating copy to clipboard operation
smart-contracts copied to clipboard

Send excess tokens when using maxDestAmount on Kyber trade

Open ilanDoron opened this issue 5 years ago • 0 comments

Current trade flow (assuming maxDestAmount is valid):

  1. network query rate from reserve with src amount. rate result name networkRate
  2. actualSrcAmount = destAmount / networkRate
  3. call reserve.trade with actualSrcAmount and networkRate
  4. when actualSrcAmount << traderSrcAmount --> actualRate << networkRate and we have extra tokens from trade.
  • for FPR we don't have extra tokens, since it uses networkRate for the trade.
  1. reserve calculates expectedDestAmount = actualSrcAmoun * networkRate
  2. reserve sends to network expectedDestAmount

required fixes:

  1. reserve sends network total received amount from the trade.
  2. reserve.trade API returns totalAmount as return value.
  3. network reads total amount and claims the full amount.
  4. network sends trader the full amount.

This fix requires API change = reserve interface should be updated across all deployed reserves.

ilanDoron avatar Oct 10 '19 06:10 ilanDoron