hifi-finance / hifi

Monorepo implementing the Hifi fixed-rate, fixed-term lending protocol
https://app.hifi.finance
Other
106 stars 15 forks source link

feat(flash-swap): improve pair contract assertion logic #39

Closed scorpion9979 closed 3 years ago

scorpion9979 commented 3 years ago

Addresses https://github.com/hifi-finance/hifi/issues/37

PaulRBerg commented 3 years ago

Just like #39, this needs to be tested before a proper review!

PaulRBerg commented 3 years ago

I was wondering why you swapped the token0Amount with the token1Amount ...

The order of tokens depends on what addresses the tokens will have. But what addresses the tokens will have depends on what MNEMONIC we're using, because of the way the CREATE opcode computes addresses. This wasn't an issue before because we were deploying the pair contract ourselves, but now the factory is taking care of that.

There are two solutions:

  1. Ask anyone in the team to use the same development MNEMONIC. This is not practical, and doesn't scale well.
  2. Handle the arbitrary order of the tokens in the tests themselves.
PaulRBerg commented 3 years ago

This is good to merge now, though coverage has decreased a bit. I created a new issue for that: https://github.com/hifi-finance/hifi/issues/45.