-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for help with debugging, all contract writes now log their arguments to the debug console
- Loading branch information
1 parent
39621bc
commit 34e5edf
Showing
13 changed files
with
128 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { MaxUint256, PERMIT2 } from '@nftx/constants'; | ||
import { ApproveContract, TokenId } from '@nftx/types'; | ||
import { getChainConstant, getUniqueTokenIds, isCryptoPunk } from '@nftx/utils'; | ||
|
||
type GetApproveContract = Pick< | ||
ApproveContract, | ||
'label' | 'spenderAddress' | 'tokenAddress' | ||
> & | ||
Partial<Pick<ApproveContract, 'amount' | 'standard' | 'tokenIds'>> & { | ||
network: number; | ||
usePermit2?: boolean; | ||
}; | ||
|
||
export const getApproveContracts = ({ | ||
label, | ||
network, | ||
spenderAddress, | ||
tokenAddress, | ||
amount, | ||
standard, | ||
tokenIds, | ||
usePermit2, | ||
}: GetApproveContract): ApproveContract[] => { | ||
if (isCryptoPunk(tokenAddress)) { | ||
return ( | ||
tokenIds?.map((tokenIdOrTuple) => { | ||
const tokenIds = getUniqueTokenIds([tokenIdOrTuple as TokenId]); | ||
|
||
return { | ||
type: 'on-chain', | ||
label: `${label} [${tokenIds}]`, | ||
tokenIds, | ||
spenderAddress, | ||
tokenAddress, | ||
standard, | ||
}; | ||
}) || [] | ||
); | ||
// Permit2 is only available for ERC20 tokens | ||
} else if (usePermit2 && (standard === 'ERC20' || standard == null)) { | ||
return [ | ||
{ | ||
label: 'Approve Permit2', | ||
type: 'on-chain', | ||
spenderAddress: getChainConstant(PERMIT2, network), | ||
tokenAddress, | ||
standard: 'ERC20', | ||
amount: MaxUint256, | ||
}, | ||
{ | ||
type: 'permit2', | ||
label, | ||
spenderAddress, | ||
tokenAddress, | ||
amount, | ||
standard, | ||
tokenIds, | ||
}, | ||
]; | ||
} else { | ||
return [ | ||
{ | ||
type: 'on-chain', | ||
label, | ||
spenderAddress, | ||
tokenAddress, | ||
amount, | ||
standard, | ||
tokenIds, | ||
}, | ||
]; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as approve } from './approve'; | ||
export { default as isApproved } from './isApproved'; | ||
export * from './approveContracts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters