nahmii-community / bridge

The Nahmii gateway, for bridging assets between L1 <-> L2.
1 stars 2 forks source link

Improve approval mechanism #33

Closed HDauven closed 2 years ago

HDauven commented 2 years ago

The current ERC20 approval flow is not transparent. A new implementation should take into account potential edge cases where ERC20 tokens require a reset of the approved amount when it is not stackable or exceeds the to deposit amount.

A potential flow would be:

if allowance is equal to MAXIMUM_APPROVAL_AMOUNT
    deposit
else if allowance is equal to ZERO
    approve unlimited
else if allowance is larger than amount to bridge
    reset approval to zero

This flow allows the UI to more appropriately react to allowance state changes.