bancorprotocol / sdk

Apache License 2.0
18 stars 24 forks source link

Support batch requesting for rates #20

Closed xianny closed 4 years ago

xianny commented 4 years ago

Support contract multicall for multiple input amounts at once.

For context, this is necessary for integrating Bancor liquidity into 0x API. When calculating a quote, we request rates for multiple input amounts to find the best rates to compose the total target amount of the quote. Discussed details with @yudilevi off-thread.

This PR modifies the getRates functions to support requesting rates for multiple input amounts in the same contract multicall. The output is is the rates per path, grouped by amount. E.g.:

getRates([ path1, path2 ], [ amount1, amount2 ]) = [
    [ rateForPath1Amount2, rateForPath2Amount1, rateForPath3Amount1],
    [ rateForPath1Amount2, rateForPath2Amount2, rateForPath3Amount3]
]

Interface changes:

xianny commented 4 years ago

Thanks for the review @barakman ! I made some changes, please re-review.

The first force-push is just to rebase off bancorprotocol:master. No changes to the first commit.

BMillman19 commented 4 years ago

Hey y'all, I think we've addressed the comments so far, would appreciate another look whenever you have a chance!

yudilevi commented 4 years ago

hey, we just released the new version.

BMillman19 commented 4 years ago

Thank you!