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 whitelistconst actionFunc = tokenSponsor.addWalletToWhitelist(walletAddress)
Parameters
Returns
removeWalletFromWhitelist
Remove a FunWallet from a TokenSponsor whitelistconst actionFunc = tokenSponsor.removeWalletFromWhitelist(walletAddress)
Parameters
Returns
addWalletToBlacklist
Add a FunWallet to a TokenSponsor blacklistconst actionFunc = tokenSponsor.addWalletToBlacklist(walletAddress)
Parameters
Returns
removeWalletFromBlacklist
Remove a FunWallet from a TokenSponsor blacklistconst actionFunc = tokenSponsor.removeWalletFromBlacklist(walletAddress)
Parameters
Returns
setWhitelistMode
Set a TokenSponsor to whitelist modeconst actionFunc = tokenSponsor.setWhitelistMode()
Returns
setBlacklistMode
Set a TokenSponsor to blacklist modeconst actionFunc = tokenSponsor.setBlacklistMode()
Returns
stake
Stake some native gas tokens in the TokenSponsorconst actionFunc = tokenSponsor.stake(walletAddress, amount)
Parameters
Returns
unstake
Unstake some native gas tokens from the TokenSponsorconst actionFunc = tokenSponsor.unstake(walletAddress, amount)
Parameters
Returns
stakeToken
Stake some ERC-20 tokens in the TokenSponsorconst actionFunc = tokenSponsor.stake(walletAddress, amount)
Parameters
Returns
unstakeToken
Unstake some ERC-20 tokens in the TokenSponsorconst actionFunc = tokenSponsor.unstakeToken(walletAddress, amount)
Parameters
Returns
approve
Give the TokenSponsor contract approval to spend an entities tokensconst actionFunc = tokenSponsor.approve(amount)