diff --git a/src/sdk/v3/INftSwapV3.ts b/src/sdk/v3/INftSwapV3.ts index 0311896..aab18fd 100644 --- a/src/sdk/v3/INftSwapV3.ts +++ b/src/sdk/v3/INftSwapV3.ts @@ -2,6 +2,7 @@ import type { TransactionReceipt } from '@ethersproject/providers'; import type { ContractTransaction } from '@ethersproject/contracts'; import type { Signer } from '@ethersproject/abstract-signer'; import type { + BigNumberish, Order, OrderInfoV3, OrderStatusV3, @@ -119,6 +120,7 @@ export interface ApprovalOverrides { exchangeProxyContractAddressForAsset: string; chainId: number; gasAmountBufferMultiple: number | null; + approvalAmount: BigNumberish } export interface FillOrderOverrides { diff --git a/src/sdk/v3/NftSwapV3.ts b/src/sdk/v3/NftSwapV3.ts index 7b5c0b0..02e31cf 100644 --- a/src/sdk/v3/NftSwapV3.ts +++ b/src/sdk/v3/NftSwapV3.ts @@ -285,7 +285,8 @@ class NftSwapV3 implements INftSwapV3 { public loadApprovalStatus = async ( asset: SwappableAsset, - walletAddress: string + walletAddress: string, + approvalOverrides?: Partial | undefined ) => { // TODO(johnrjj) - Fix this... const exchangeProxyAddressForAsset = getProxyAddressForErcType( @@ -297,7 +298,8 @@ class NftSwapV3 implements INftSwapV3 { walletAddress, exchangeProxyAddressForAsset, assetInternalFmt, - this.provider + this.provider, + approvalOverrides?.approvalAmount ); }; diff --git a/src/sdk/v3/pure.ts b/src/sdk/v3/pure.ts index 6188668..7b4c9b4 100644 --- a/src/sdk/v3/pure.ts +++ b/src/sdk/v3/pure.ts @@ -12,7 +12,7 @@ import { } from '@ethersproject/bytes'; import { verifyTypedData } from '@ethersproject/wallet'; import { _TypedDataEncoder } from '@ethersproject/hash'; -import { BigNumber } from '@ethersproject/bignumber'; +import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; import { Interface } from '@ethersproject/abi'; import type { Signer, TypedDataSigner } from '@ethersproject/abstract-signer'; import { @@ -420,7 +420,8 @@ export const getApprovalStatus = async ( walletAddress: string, exchangeProxyAddressForAsset: string, asset: InterallySupportedAssetFormat, - provider: BaseProvider + provider: BaseProvider, + approvalAmount: BigNumberish = MAX_APPROVAL_WITH_BUFFER ): Promise => { switch (asset.type) { case 'ERC20': @@ -429,15 +430,10 @@ export const getApprovalStatus = async ( walletAddress, exchangeProxyAddressForAsset ); - // Weird issue with BigNumber and approvals...need to look into it, adding buffer. - const MAX_APPROVAL_WITH_BUFFER = BigNumber.from( - MAX_APPROVAL.toString() - ).sub('100000000000000000'); - const approvedForMax = erc20AllowanceBigNumber.gte( - MAX_APPROVAL_WITH_BUFFER - ); + + const hasEnoughApproval = erc20AllowanceBigNumber.gte(approvalAmount); return { - contractApproved: approvedForMax, + contractApproved: hasEnoughApproval, }; case 'ERC721': const erc721 = ERC721__factory.connect(asset.tokenAddress, provider); @@ -478,6 +474,11 @@ export const getApprovalStatus = async ( // TODO(johnrjj) - Support custom ERC20 approval amounts export const MAX_APPROVAL = BigNumber.from(2).pow(118); +// Weird issue with BigNumber and approvals...need to look into it, adding buffer. +const MAX_APPROVAL_WITH_BUFFER = BigNumber.from(MAX_APPROVAL.toString()).sub( + '100000000000000000' +); + /** * @param exchangeProxyAddressForAsset Exchange Proxy address specific to the ERC type (e.g. use the 0x ERC721 Proxy if you're using a 721 asset). This is the address that will need approval & does the spending/swap. * @param asset