Skip to content

Commit

Permalink
feat: add func to check for correct native token (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov authored Jul 12, 2022
1 parent d118981 commit 865bc14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/allowance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js'
import { constants, Signer } from 'ethers'
import { isSameToken } from '../helpers'
import { RevokeTokenData } from '../types'
import { isZeroAddress } from '../utils/utils'
import { isNativeTokenAddress } from '../utils/utils'
import {
getAllowanceViaMulticall,
getApproved,
Expand Down Expand Up @@ -31,7 +31,7 @@ export const getTokenApproval = async (
approvalAddress: string
): Promise<string | undefined> => {
// native token don't need approval
if (isZeroAddress(token.address)) {
if (isNativeTokenAddress(token.address)) {
return
}

Expand All @@ -45,7 +45,7 @@ export const bulkGetTokenApproval = async (
): Promise<{ token: Token; approval: string | undefined }[]> => {
// filter out native tokens
const filteredTokenData = tokenData.filter(
({ token }) => !isZeroAddress(token.address)
({ token }) => !isNativeTokenAddress(token.address)
)

// group by chain
Expand All @@ -68,7 +68,7 @@ export const bulkGetTokenApproval = async (
const approvals = approvalsByChain.flat()
return tokenData.map(({ token }) => {
// native token don't need approval
if (isZeroAddress(token.address)) {
if (isNativeTokenAddress(token.address)) {
return { token, approval: undefined }
}

Expand All @@ -88,7 +88,7 @@ export const approveToken = async ({
infiniteApproval = false,
}: ApproveTokenRequest): Promise<void> => {
// native token don't need approval
if (isZeroAddress(token.address)) {
if (isNativeTokenAddress(token.address)) {
return
}

Expand Down Expand Up @@ -120,7 +120,7 @@ export const revokeTokenApproval = async ({
approvalAddress,
}: RevokeApprovalRequest): Promise<void> => {
// native token don't need approval
if (isZeroAddress(token.address)) {
if (isNativeTokenAddress(token.address)) {
return
}

Expand Down
18 changes: 15 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import BigNumber from 'bignumber.js'
import { constants, Signer } from 'ethers'
import { TransactionReceipt } from '@ethersproject/providers'
import { Token } from '@lifinance/types'
import BigNumber from 'bignumber.js'
import { constants, Signer } from 'ethers'

import { ChainId, Step } from '../types'
import { getRpcProvider } from '../connectors'
import { ChainId, Step } from '../types'

export const deepClone = <T>(src: T): T => {
return JSON.parse(JSON.stringify(src))
Expand Down Expand Up @@ -128,3 +128,15 @@ export const isZeroAddress = (address: string): boolean => {
}
return false
}

export const isNativeTokenAddress = (address: string): boolean => {
if (
address === constants.AddressZero ||
address === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' ||
// CELO native token
address === '0x471ece3750da237f93b8e339c536989b8978a438'
) {
return true
}
return false
}

0 comments on commit 865bc14

Please sign in to comment.