TokenSponsor

Allow FunWallets to pay gas in ERC-20 tokens

Overview

TokenSponsor allows FunWallets to pay gas in ERC-20 tokens. This works by having 2 parties stake assets in a Paymaster smart contract:

  • An external funder account (EOA, FunWallet or other) stakes the native gas token

  • The FunWallet stakes the token it intends to pay gas with (e.g. USDC). The FunWallet can stake this token in one of 2 ways:

    • By sending the token to the Paymaster contract & locking it before a Transaction is executed, via FunWallet.transfer()

    • By giving token spend authorization to the Paymaster contract so it can transfer tokens to itself within the same Transaction, via FunWallet.approve()


When a FunWallet wants to perform a Transaction, the native gas token staked by the external funder account in the Paymaster contract is drained to cover the Transaction's gas requirements. In the same Transaction, the tokens a FunWallet either sent or gave spend authorization to the Paymaster contract are sent to the external funder account to cover the drained native gas token at an exchange rate determined by a Chainlink oracle.

Constructor


const tokenSponsor = new TokenSponsor()

Methods


addWalletToWhitelist

Add a FunWallet to a TokenSponsor whitelist
const actionFunc = tokenSponsor.addWalletToWhitelist(walletAddress)

Parameters

walletAddress
address
Required

The address of a FunWallet to add to the whitelist

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


removeWalletFromWhitelist

Remove a FunWallet from a TokenSponsor whitelist
const actionFunc = tokenSponsor.removeWalletFromWhitelist(walletAddress)

Parameters

walletAddress
address
Required

The address of a FunWallet to remove from the whitelist

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


addWalletToBlacklist

Add a FunWallet to a TokenSponsor blacklist
const actionFunc = tokenSponsor.addWalletToBlacklist(walletAddress)

Parameters

walletAddress
address
Required

The address of a FunWallet to add to the blacklist

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


removeWalletFromBlacklist

Remove a FunWallet from a TokenSponsor blacklist
const actionFunc = tokenSponsor.removeWalletFromBlacklist(walletAddress)

Parameters

walletAddress
address
Required

The address of a FunWallet to remove from the blacklist

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


setWhitelistMode

Set a TokenSponsor to whitelist mode
const actionFunc = tokenSponsor.setWhitelistMode()

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


setBlacklistMode

Set a TokenSponsor to blacklist mode
const actionFunc = tokenSponsor.setBlacklistMode()

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


stake

Stake some native gas tokens in the TokenSponsor
const actionFunc = tokenSponsor.stake(walletAddress, amount)

Parameters

walletAddress
address
Required

The address of a FunWallet to add native gas token stake for

amount
float
Required

Amount of native gas token to stake

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


unstake

Unstake some native gas tokens from the TokenSponsor
const actionFunc = tokenSponsor.unstake(walletAddress, amount)

Parameters

walletAddress
address
Required

The address of a FunWallet to remove native gas token stake for

amount
float
Required

Amount of native gas token to unstake

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


stakeToken

Stake some ERC-20 tokens in the TokenSponsor
const actionFunc = tokenSponsor.stake(walletAddress, amount)

Parameters

walletAddress
address
Required

The address of a FunWallet to add ERC-20 token stake for

amount
float
Required

Amount of ERC-20 token to stake

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


unstakeToken

Unstake some ERC-20 tokens in the TokenSponsor
const actionFunc = tokenSponsor.unstakeToken(walletAddress, amount)

Parameters

walletAddress
address
Required

The address of a FunWallet to remove ERC-20 token stake for

amount
float
Required

Amount of ERC-20 token to unstake

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed


approve

Give the TokenSponsor contract approval to spend an entities tokens
const actionFunc = tokenSponsor.approve(amount)

Parameters

amount
float
Required

Amount of ERC-20 tokens to give approval to

Returns

actionFunc
actionFunc

actionFunc object ready to be signed & executed/deployed