Sending Tokens
What might not be immediately apparent is how Savmswap receives tokens in exchange for the swap. Typically, smart contracts needing tokens for functionality require an approval on the token contract, followed by a function call that executes transferFrom on the token contract. However, this isn't the approach taken by Savmswap pairs. Instead, pairs assess their token balances at the end of each interaction. The next interaction begins by comparing the current balances with stored values to ascertain the amount of tokens sent by the current interactor (refer to the whitepaper for a detailed rationale).
The key takeaway is that tokens must be transferred to pairs before the swap function is called (Flash Swaps being the sole exception). To ensure safe usage of the swap function, it must be called from another smart contract. The alternative method of transferring tokens to the pair and then calling swap is risky and non-atomic, as the sent tokens could be exposed to arbitrage.
Last updated