wyvernprotocol / wyvern-v3

Wyvern Protocol v3.1, Ethereum implementation
https://wyvernprotocol.com
MIT License
298 stars 121 forks source link

Having issues with ExchangeCore code #67

Closed jackcpku closed 2 years ago

jackcpku commented 2 years ago

Hi all!

I'm currently studying the contracts in order to build on top of wyvern later on. But now I'm having trouble understanding the code. In the following function:

https://github.com/wyvernprotocol/wyvern-v3/blob/e09e6ec319af65773fb4db52d2a43ef7dbb7f574/contracts/exchange/ExchangeCore.sol#L304-L385

Why must the static calls be after the effectful calls? How can they "check the resulting state"? It seems to me that swapping the effectful calls and static calls makes no difference.

I also have great difficulty understanding the purpose of all the "static" things. I'll appreciate it if someone could help.

cwgoes commented 2 years ago

The static calls must be after the effectful calls in case they wish to check state changes performed by the effectful calls. For example, a static call could check that another contract is in a certain state, that a user now owns a particular asset, etc.

jackcpku commented 2 years ago

The static calls must be after the effectful calls in case they wish to check state changes performed by the effectful calls. For example, a static call could check that another contract is in a certain state, that a user now owns a particular asset, etc.

Thanks for the response! So the point of static callings are

  1. check if the current condition meets each party's requirement in order for the transaction to happen
  2. check if a certain state is achieved after the transaction, say, Alice will have cryptopunk#9999 in her address.

Is my understanding right now?

cwgoes commented 2 years ago

Yes. Static calls can also (and will often) check the calldata executed (say, transferring a CryptoKitty) instead of checking the final state. They're just provided access to all the relevant data so the author of the static call can decide what specifically to do.

jackcpku commented 2 years ago

Yes. Static calls can also (and will often) check the calldata executed (say, transferring a CryptoKitty) instead of checking the final state. They're just provided access to all the relevant data so the author of the static call can decide what specifically to do.

Thank you! It's all clear now.