Skip to content

v0.32.0 - Add custom ERC20 approval amount support

Compare
Choose a tag to compare
@johnrjj johnrjj released this 12 Jun 22:06
· 2 commits to main since this release

Context

Originally, the NFT swap sdk defaulted to max approvals to make it easier to use and for convenience of users. However, wallets are now being more aggressive in the way they notify/allow users to set approvals. MetaMask is specifically only recommending minimum viable approval to complete the transaction, so this PR adds first class support for custom approval amounts, both loading/fetching an approval and constructing an approval transaction. In the future, a breaking v1 release will prioritize minimum required approvals over max approvals by default, but to maintain maximum backwards compatibility, custom/minimum approvals are opt-in.

Changes

  • Added a new function loadApprovalStatusForOrder that will check exact approval amounts for an order.
  • loadApprovalStatus now supports a custom approval amount, but still defaults to max approval to maintain backwards comaptability until v1 release, in which we will default to minimum approval amount necessary for all interactions.

Prefer loadApprovalStatusForOrder over loadApprovalStatus, as it is easier to use right now because the order contains everything required to determine approval data:

const approvalStatus = await this.loadApprovalStatusForOrder(
  order,
  "MAKER" // or 'TAKER'
);

approvalStatus result will take into consideration minimum approval amount required by default, as it uses the order object to infer what approvals is required to make the swap successful.

You can optionally continue to use loadApprovalStatus, but note that this requires providing a custom approval amount since there is no order context to infer the amount from:

const approvalStatus = await nftSwap.loadApprovalStatus(asset, walletAddress, undefined, {
  approvalAmount: CUSTOM_APPROVAL_AMOUNT_TO_CHECK,
});