Explain code to overwrite fromAmount in comment

Fixes MixBytes Comment 1.
This commit is contained in:
Jason Raymond Bell 2021-05-20 14:00:34 +01:00
parent b13a01d8b8
commit 11d0367d3c

View File

@ -66,9 +66,14 @@ abstract contract BaseParaSwapSellAdapter is BaseParaSwapAdapter {
IERC20(assetToSwapFrom).safeApprove(tokenTransferProxy, amountToSwap);
if (fromAmountOffset != 0) {
// Ensure 256 bit (32 bytes) fromAmount value is within bounds of the
// calldata, not overlapping with the first 4 bytes (function selector).
require(fromAmountOffset >= 4 &&
fromAmountOffset <= swapCalldata.length.sub(32),
'FROM_AMOUNT_OFFSET_OUT_OF_RANGE');
// Overwrite the fromAmount with the correct amount for the swap.
// In memory, swapCalldata consists of a 256 bit length field, followed by
// the actual bytes data, that is why 32 is added to the byte offset.
assembly {
mstore(add(swapCalldata, add(fromAmountOffset, 32)), amountToSwap)
}