0
function fillQuote(
    // The `sellTokenAddress` field from the API response.
    IERC20 sellToken,
    // The `buyTokenAddress` field from the API response.
    IERC20 buyToken,
    // The `allowanceTarget` field from the API response.
    address spender,
    // The `to` field from the API response.
    address payable swapTarget,
    // The `data` field from the API response.
    bytes calldata swapCallData,
    // amount of tokens that needs to be sold
    uint _tokenamount
)
    external
    onlyOwner
    payable // Must attach ETH equal to the `value` field from the API response.
{
    // Give `spender` an infinite allowance to spend this contract's `sellToken`.
    // Note that for some tokens (e.g., USDT, KNC), you must first reset any existing
    // allowance to 0 before being able to update it.

    // require(sellToken.approve(spender, uint256(-1)));
   require(_tokenamount <= GetAllowance(sellToken, spender), "Please approve tokens before transferring");
    // Call the encoded swap function call on the contract at `swapTarget`,
    // passing along any ETH attached to this function call to cover protocol fees.
    (bool success,bytes memory _data) = swapTarget.delegatecall(swapCallData);
    // (bool success,) = swapTarget.call{value: msg.value}(swapCallData); // Note the line above is a delegate call
    require(success, 'SWAP_CALL_FAILED');
    // Refund any unspent protocol fees to the sender.
    // msg.sender.transfer(address(this).balance);
    emit FilledSwapOrder(sellToken, buyToken, _tokenamount, _data);
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.