make_eip_3009_transfer

Documentation for eth_defi.usdc.eip_3009.make_eip_3009_transfer function.

make_eip_3009_transfer(token, from_, to, func, value, valid_before=0, valid_after=1, duration_seconds=0, extra_args=(), authorization_type=EIP3009AuthorizationType.TransferWithAuthorization)[source]

Perform an EIP-3009 transferWithAuthorization() and receiveWithAuthorization() transaction.

  • Constructs the EIP-3009 / EIP-712 payload

  • Signs the message

  • Builds a transaction against receiveWithAuthorization in USDC using Web3.py API, assuming there is a target smart contract function func to be called with this messge

  • The caller can then execute this by building a transaction from the resulting bound function call

Note

This currently supports only LocalAccount because of missing features in web3.py.

Example:

# Deploy some contract that supports
payment_forwarder = deploy_contract(
    web3,
    "VaultUSDCPaymentForwarder.json",
    deployer,
    usdc.address,
    comptroller.address,
)

# Construct bounded ContractFunction instance
# that will transact with MockEIP3009Receiver.deposit()
# smart contract function.
bound_func = make_receive_with_authorization_transfer(
    token=usdc,
    from_=user,
    to=payment_forwarder.address,
    func=payment_forwarder.functions.buySharesOnBehalf,
    value=500 * 10**6,  # 500 USD,
    valid_before=valid_before,
    extra_args=(1,),  # minSharesQuantity
)

# Sign and broadcast the tx
tx_hash = bound_func.transact({"from": user.address})

The receiveAuthorization() signature is:

function receiveWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s)
Parameters
  • token (eth_defi.token.TokenDetails) – USDC token details

  • from – The local account that signs the EIP-3009 transfer.

  • to (eth_typing.evm.HexAddress) – To which contract USDC is transferred.

  • func (web3.contract.contract.ContractFunction) –

    The contract function that is verifying the transfer.

    A smart contract function with the same call signature as receiveAuthorization(). However, the spec does not specify what kind of a signature of a function this is: you can transfer receiveWithAuthorization() payload in any form, with extra parameters, byte packed, etc.

  • value (int) – How many tokens in raw value

  • valid_before (int) – Transfer timeout control

  • valid_after (int) – Transfer timeout control

  • duration_seconds (int) – Automatically set valid_before based on this

  • extra_args – Arguments added after the standard receiveWithAuthorization() prologue.

  • authorization_type – Is this transferWithAuthorization or receiveWithAuthorization style transaction.

  • from_ (eth_account.signers.local.LocalAccount) –

Returns

Bound contract function for transferWithAuthorization

Return type

web3.contract.contract.ContractFunction