wormhole
wormhole copied to clipboard
NFT bridge causing unnecessary Approval transactions
Description and context
When using the transferFromEth
function to transfer an NFT from Ethereum mainnet, the Wormhole SDK script always has the user send an approve()
call, even if the Wormhole bridge contract already has access to that token.
https://github.com/wormhole-foundation/wormhole/blob/main/sdk/js/src/nft_bridge/transfer.ts#L44-L46
This is a wasteful behavior, since if the bridge contract already has access (through some other approval process, or the user started a bridge process and got interrupted partway through), triggering another on-chain approve()
call is just wasted gas.
Steps to reproduce
- Trigger a
transferFromEth
call for a specific token - In the wallet, submit the initial
approve()
action. - While the
approve
action is pending, close the Dapp tab, or navigate away from the app. - After the
approve
action succeeds, come back to the Dapp and attempt to continue the transfer.
Experienced behavior
There's no way to "continue" the transfer. If transferFromEth
is called again, the user is requested to submit an additional (useless) approve()
action.
Expected behavior
The transferFromEth
call skips the approve()
call and goes on to the bridge.transferNFT
call.
Solution recommendation
Knowing that the token is an ERC721-compliant token, the transferFromEth
function should check token.getApproved(tokenID)
and see if it's equal to nftBridgeAddress
, and token.isApprovedForAll(signer.address, nftBridgeAddress)
and see if that's true
. If either of those checks pass, skip the step of the user needing to call token.approve
again.