Skip to content
This repository was archived by the owner on Aug 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/common/feature-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ function matchesInterface(contract: BaseContract, interfaceToMatch: Interface) {
/**
* @internal
* @param abi
* @param interfaceAbi
* @param interfaceAbis
*/
function matchesAbiInterface(
abi: z.input<typeof AbiSchema>,
interfaceAbi: z.input<typeof AbiSchema>,
interfaceAbis: readonly z.input<typeof AbiSchema>[],
): boolean {
// returns true if all the functions in `interfaceToMatch` are found in `contract`
const contractFn = extractFunctionsFromAbi(abi).map((f) => f.name);
const interfaceFn = extractFunctionsFromAbi(interfaceAbi).map((f) => f.name);
const interfaceFn = interfaceAbis
.flatMap((i) => extractFunctionsFromAbi(i))
.map((f) => f.name);
return (
contractFn.filter((k) => interfaceFn.includes(k)).length ===
interfaceFn.length
Expand Down Expand Up @@ -188,7 +190,7 @@ export function detectFeatures(
const results: Record<string, FeatureWithEnabled> = {};
for (const featureKey in features) {
const feature = features[featureKey];
const enabled = matchesAbiInterface(abi, feature.abi);
const enabled = matchesAbiInterface(abi, feature.abis);
const childResults = detectFeatures(abi, feature.features);
results[featureKey] = {
...feature,
Expand Down
8 changes: 4 additions & 4 deletions src/constants/erc1155-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const FEATURE_EDITION_BATCH_MINTABLE = {
sdk: "sdk.erc1155batchmintable",
contracts: "IMulticall",
},
abi: MulticallAbi,
abis: [Erc1155Abi, IMintableERC1155Abi, MulticallAbi],
features: {},
} as const;

Expand All @@ -21,7 +21,7 @@ export const FEATURE_EDITION_MINTABLE = {
sdk: "sdk.erc1155mintable",
contracts: "IMintableERC1155",
},
abi: IMintableERC1155Abi,
abis: [Erc1155Abi, IMintableERC1155Abi],
features: {
[FEATURE_EDITION_BATCH_MINTABLE.name]: FEATURE_EDITION_BATCH_MINTABLE,
},
Expand All @@ -34,7 +34,7 @@ export const FEATURE_EDITION_ENUMERABLE = {
sdk: "sdk.erc1155",
contracts: "ERC1155",
},
abi: Erc1155EnumerableAbi,
abis: [Erc1155Abi, Erc1155EnumerableAbi],
features: {},
} as const;

Expand All @@ -45,7 +45,7 @@ export const FEATURE_EDITION = {
sdk: "sdk.erc1155enumerable",
contracts: "ERC1155Enumerable",
},
abi: Erc1155Abi,
abis: [Erc1155Abi],
features: {
[FEATURE_EDITION_ENUMERABLE.name]: FEATURE_EDITION_ENUMERABLE,
[FEATURE_EDITION_MINTABLE.name]: FEATURE_EDITION_MINTABLE,
Expand Down
6 changes: 3 additions & 3 deletions src/constants/erc20-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const FEATURE_TOKEN_BATCH_MINTABLE = {
sdk: "sdk.erc20batchmintable",
contracts: "IMulticall",
},
abi: MulticallAbi,
abis: [ERC20Abi, IMintableERC20Abi, MulticallAbi],
features: {},
} as const;

Expand All @@ -20,7 +20,7 @@ export const FEATURE_TOKEN_MINTABLE = {
sdk: "sdk.erc20mintable",
contracts: "IMintableERC20",
},
abi: IMintableERC20Abi,
abis: [ERC20Abi, IMintableERC20Abi],
features: {
[FEATURE_TOKEN_BATCH_MINTABLE.name]: FEATURE_TOKEN_BATCH_MINTABLE,
},
Expand All @@ -33,7 +33,7 @@ export const FEATURE_TOKEN = {
sdk: "sdk.erc20",
contracts: "ERC20",
},
abi: ERC20Abi,
abis: [ERC20Abi],
features: {
[FEATURE_TOKEN_MINTABLE.name]: FEATURE_TOKEN_MINTABLE,
},
Expand Down
10 changes: 5 additions & 5 deletions src/constants/erc721-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const FEATURE_NFT_BATCH_MINTABLE = {
sdk: "sdk.erc721batchmintable",
contracts: "IMulticall",
},
abi: MulticallAbi,
abis: [Erc721Abi, IMintableERC721Abi, MulticallAbi],
features: {},
} as const;

Expand All @@ -22,7 +22,7 @@ export const FEATURE_NFT_MINTABLE = {
sdk: "sdk.erc721mintable",
contracts: "IMintableERC721",
},
abi: IMintableERC721Abi,
abis: [Erc721Abi, IMintableERC721Abi],
features: {
[FEATURE_NFT_BATCH_MINTABLE.name]: FEATURE_NFT_BATCH_MINTABLE,
},
Expand All @@ -35,7 +35,7 @@ export const FEATURE_NFT_ENUMERABLE = {
sdk: "sdk.erc721enumerable",
contracts: "ERC721Enumerable",
},
abi: Erc721EnumerableAbi,
abis: [Erc721Abi, Erc721EnumerableAbi],
features: {},
} as const;

Expand All @@ -46,7 +46,7 @@ export const FEATURE_NFT_SUPPLY = {
sdk: "sdk.erc721supply",
contracts: "ERC721Supply",
},
abi: Erc721SupplyAbi,
abis: [Erc721Abi, Erc721SupplyAbi],
features: {
[FEATURE_NFT_ENUMERABLE.name]: FEATURE_NFT_ENUMERABLE,
},
Expand All @@ -59,7 +59,7 @@ export const FEATURE_NFT = {
sdk: "sdk.erc721",
contracts: "ERC721",
},
abi: Erc721Abi,
abis: [Erc721Abi],
features: {
[FEATURE_NFT_SUPPLY.name]: FEATURE_NFT_SUPPLY,
[FEATURE_NFT_MINTABLE.name]: FEATURE_NFT_MINTABLE,
Expand Down
8 changes: 4 additions & 4 deletions src/constants/thirdweb-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const FEATURE_ROYALTY = {
sdk: "sdk.contractroyalty",
contracts: "IThirdwebPrimarySale",
},
abi: IThirdwebRoyaltyAbi,
abis: [IThirdwebRoyaltyAbi],
features: {},
} as const;

Expand All @@ -21,7 +21,7 @@ export const FEATURE_PRIMARY_SALE = {
sdk: "sdk.contractprimarysale",
contracts: "IThirdwebPrimarySale",
},
abi: IThirdwebPrimarySaleAbi,
abis: [IThirdwebPrimarySaleAbi],
features: {},
} as const;

Expand All @@ -32,7 +32,7 @@ export const FEATURE_PLATFORM_FEE = {
sdk: "sdk.platformfee",
contracts: "IThirdwebPlatformFee",
},
abi: IThirdwebPlatformFeeAbi,
abis: [IThirdwebPlatformFeeAbi],
features: {},
} as const;

Expand All @@ -43,6 +43,6 @@ export const FEATURE_PERMISSIONS = {
sdk: "sdk.contractroles",
contracts: "IPermissionsEnumerable",
},
abi: IPermissionsEnumerableAbi,
abis: [IPermissionsEnumerableAbi],
features: {},
} as const;