smart-contracts
smart-contracts copied to clipboard
Send excess tokens when using maxDestAmount on Kyber trade
Current trade flow (assuming maxDestAmount is valid):
- network query rate from reserve with src amount. rate result name networkRate
- actualSrcAmount = destAmount / networkRate
- call reserve.trade with actualSrcAmount and networkRate
- 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.
- reserve calculates expectedDestAmount = actualSrcAmoun * networkRate
- reserve sends to network expectedDestAmount
required fixes:
- reserve sends network total received amount from the trade.
- reserve.trade API returns totalAmount as return value.
- network reads total amount and claims the full amount.
- network sends trader the full amount.
This fix requires API change = reserve interface should be updated across all deployed reserves.