From c95bbca3dd27e826fe5e3338b29d2b31ba529009 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Thu, 2 Nov 2023 15:32:45 +0100 Subject: [PATCH 01/13] Update for fetching LSP8 metadata based on token id type --- types/assets.ts | 18 ++++++++++++------ utils/fetchLsp8Metadata.ts | 21 ++++++++++----------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/types/assets.ts b/types/assets.ts index 5a733d44..96ca2bfb 100644 --- a/types/assets.ts +++ b/types/assets.ts @@ -1,4 +1,8 @@ -import { INTERFACE_IDS, ImageMetadata } from '@lukso/lsp-smart-contracts' +import { + INTERFACE_IDS, + ImageMetadata, + LSP8_TOKEN_ID_TYPES, +} from '@lukso/lsp-smart-contracts' export type InterfaceId = keyof typeof INTERFACE_IDS @@ -16,11 +20,13 @@ export enum AssetFilter { created = 'created', } -export enum Lsp8TokenIdType { - address = '1', - number = '2', - bytes32 = '3', -} +export const Lsp8TokenIdType = { + NUMBER: 0, + STRING: 1, + UNIQUE_ID: 2, + HASH: 3, + ADDRESS: 4, +} as typeof LSP8_TOKEN_ID_TYPES export type Base64EncodedImage = `data:image/jpeg;base64${string}` diff --git a/utils/fetchLsp8Metadata.ts b/utils/fetchLsp8Metadata.ts index a98c7088..ab1e0c5a 100644 --- a/utils/fetchLsp8Metadata.ts +++ b/utils/fetchLsp8Metadata.ts @@ -29,20 +29,19 @@ export const fetchLsp8Metadata = async ( try { const lsp8DigitalAsset = await erc725.fetchData(['LSP8TokenIdType']) - const tokenIdType = lsp8DigitalAsset[0].value.toString() + const tokenIdType = Number(lsp8DigitalAsset[0].value) // fetch LSP8MetadataJSON depending on tokenIdType switch (tokenIdType) { - case Lsp8TokenIdType.address: - return lsp8MetadataGetter( - 'address', - // ethers.utils.hexDataSlice(tokenId.toString(), 12) - tokenId.toString() - ) - case Lsp8TokenIdType.number: - return lsp8MetadataGetter('uint256', parseInt(tokenId).toString()) - case Lsp8TokenIdType.bytes32: - return lsp8MetadataGetter('bytes32', tokenId.toString()) + case Lsp8TokenIdType.NUMBER: + return await lsp8MetadataGetter('uint256', parseInt(tokenId).toString()) + case Lsp8TokenIdType.STRING: + return await lsp8MetadataGetter('string', tokenId.toString()) + case Lsp8TokenIdType.UNIQUE_ID: + case Lsp8TokenIdType.HASH: + return await lsp8MetadataGetter('bytes32', tokenId.toString()) + case Lsp8TokenIdType.ADDRESS: + return await lsp8MetadataGetter('address', tokenId.slice(0, 42)) default: return { LSP4Metadata: { From 57c4e20120d33458373b3014f1e33b5a85984bd2 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Thu, 2 Nov 2023 15:41:16 +0100 Subject: [PATCH 02/13] Throw better error on wrong tokenId type --- utils/fetchLsp8Metadata.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/utils/fetchLsp8Metadata.ts b/utils/fetchLsp8Metadata.ts index ab1e0c5a..363f4fa5 100644 --- a/utils/fetchLsp8Metadata.ts +++ b/utils/fetchLsp8Metadata.ts @@ -43,15 +43,9 @@ export const fetchLsp8Metadata = async ( case Lsp8TokenIdType.ADDRESS: return await lsp8MetadataGetter('address', tokenId.slice(0, 42)) default: - return { - LSP4Metadata: { - description: '', - links: [], - images: [[]], - icon: [], - assets: [], - }, - } + throw new Error( + `Unsupported LSP8 tokenIdType '${tokenIdType}' for '${assetAddress}' asset` + ) } } catch (error) { console.error(error) From f99b503686733c3ad4f1b04f720795c389a7e353 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Mon, 6 Nov 2023 10:17:53 +0100 Subject: [PATCH 03/13] Update types --- utils/fetchLSP7Assets.ts | 3 ++- utils/fetchLSP8Assets.ts | 3 ++- utils/fetchLsp7Balance.ts | 3 ++- utils/supportInterface.ts | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/fetchLSP7Assets.ts b/utils/fetchLSP7Assets.ts index 21d2cf0f..c818edae 100644 --- a/utils/fetchLSP7Assets.ts +++ b/utils/fetchLSP7Assets.ts @@ -1,4 +1,5 @@ import LSP7DigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json' +import { AbiItem } from 'web3-utils' import { ImageMetadataEncoded } from '@/types/assets' import { LSP7DigitalAsset as LSP7DigitalAssetInterface } from '@/types/contracts' @@ -12,7 +13,7 @@ export const fetchLsp7Assets = async ( const { contract } = useWeb3(PROVIDERS.RPC) const lsp7Contract = contract( - LSP7DigitalAsset.abi as any, + LSP7DigitalAsset.abi as AbiItem[], address ) let balance = '' diff --git a/utils/fetchLSP8Assets.ts b/utils/fetchLSP8Assets.ts index eade24ef..6e55d778 100644 --- a/utils/fetchLSP8Assets.ts +++ b/utils/fetchLSP8Assets.ts @@ -1,4 +1,5 @@ import LSP8IdentifiableDigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP8IdentifiableDigitalAsset.json' +import { AbiItem } from 'web3-utils' import { LSP8IdentifiableDigitalAsset as LSP8IdentifiableDigitalAssetInterface } from '@/types/contracts/LSP8IdentifiableDigitalAsset' import { Asset } from '@/models/asset' @@ -11,7 +12,7 @@ export const fetchLsp8Assets = async ( ): Promise => { const { contract } = useWeb3(PROVIDERS.RPC) const lsp8Contract = contract( - LSP8IdentifiableDigitalAsset.abi as any, + LSP8IdentifiableDigitalAsset.abi as AbiItem[], address ) const tokenSupply = await lsp8Contract.methods.totalSupply().call() diff --git a/utils/fetchLsp7Balance.ts b/utils/fetchLsp7Balance.ts index 1a52aef7..ceaaa6b6 100644 --- a/utils/fetchLsp7Balance.ts +++ b/utils/fetchLsp7Balance.ts @@ -1,4 +1,5 @@ import LSP7DigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json' +import { AbiItem } from 'web3-utils' import { LSP7DigitalAsset as LSP7DigitalAssetInterface } from '@/types/contracts' @@ -8,7 +9,7 @@ export const fetchLsp7Balance = async ( ) => { const { contract } = useWeb3(PROVIDERS.RPC) const lsp7Contract = contract( - LSP7DigitalAsset.abi as any, + LSP7DigitalAsset.abi as AbiItem[], assetAddress ) diff --git a/utils/supportInterface.ts b/utils/supportInterface.ts index a4b092eb..b188804e 100644 --- a/utils/supportInterface.ts +++ b/utils/supportInterface.ts @@ -1,3 +1,5 @@ +import { AbiItem } from 'web3-utils' + import { LSP0ERC725Account } from '@/types/contracts' /** @@ -16,7 +18,7 @@ export const supportInterface = async ( try { const eip165Contract = contract( - eip165ABI as any, + eip165ABI as AbiItem[], address ) return await eip165Contract.methods.supportsInterface(interfaceId).call() From 817187e339faa059224974f02aa386476fd06e84 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Mon, 6 Nov 2023 10:55:01 +0100 Subject: [PATCH 04/13] Upgrade erc725js --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 14de885c..5290c10a 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "typechain": "typechain --target web3-v1 --out-dir types/contracts/ './node_modules/@lukso/lsp-smart-contracts/artifacts/*.json'" }, "devDependencies": { - "@erc725/erc725.js": "0.20.1", + "@erc725/erc725.js": "0.21.0", "@esbuild-plugins/node-globals-polyfill": "0.2.3", "@formatjs/intl": "^2.9.5", "@lukso/lsp-smart-contracts": "0.12.0-rc.0", diff --git a/yarn.lock b/yarn.lock index 58809590..8f13b10d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1020,15 +1020,15 @@ __metadata: languageName: node linkType: hard -"@erc725/erc725.js@npm:0.20.1": - version: 0.20.1 - resolution: "@erc725/erc725.js@npm:0.20.1" +"@erc725/erc725.js@npm:0.21.0": + version: 0.21.0 + resolution: "@erc725/erc725.js@npm:0.21.0" dependencies: ethereumjs-util: ^7.1.5 web3-eth-abi: ^1.10.0 web3-providers-http: ^1.10.0 web3-utils: ^1.10.0 - checksum: 2fda8c3a1c3ed32a1806e4b532f64f601c431683dadf24b943a9784d8b588d0741ba3dff3b111f6b8486d887e36eb0b500216aa19e648e17942c02b9655abe5a + checksum: d7904a6bb5339e0e6e7465822e3a33cdbd85401dd2f6bb927dbf82e027dfaf503a897036328d97f4245ca5cb97a96a2811dd8d2b10cc86b76be2e0d847c539dd languageName: node linkType: hard @@ -16375,7 +16375,7 @@ __metadata: version: 0.0.0-use.local resolution: "wallet.universalprofile.cloud@workspace:." dependencies: - "@erc725/erc725.js": 0.20.1 + "@erc725/erc725.js": 0.21.0 "@esbuild-plugins/node-globals-polyfill": 0.2.3 "@formatjs/intl": ^2.9.5 "@lukso/lsp-smart-contracts": 0.12.0-rc.0 From a528b01a00ec981114e320e64db0cb8333477f2e Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Mon, 6 Nov 2023 10:56:25 +0100 Subject: [PATCH 05/13] Show warn when asset standard is not detected --- utils/fetchAsset.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils/fetchAsset.ts b/utils/fetchAsset.ts index 9d7b8a90..18f75688 100644 --- a/utils/fetchAsset.ts +++ b/utils/fetchAsset.ts @@ -1,10 +1,8 @@ -import { Asset } from '@/models/asset' - export const fetchAsset = async ( address: Address, profileAddress?: Address, tokenIds?: string[] -): Promise => { +) => { const standard = await detectStandard(address) switch (standard) { @@ -16,6 +14,7 @@ export const fetchAsset = async ( } default: + console.warn(`Asset ${address} standard is not supported`) return [] } } From a34d6b2b2c0af6e669ccd5f4fa2a644f51c56f88 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Tue, 7 Nov 2023 09:53:24 +0100 Subject: [PATCH 06/13] Upgrade erc725js --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 5290c10a..4c703823 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "typechain": "typechain --target web3-v1 --out-dir types/contracts/ './node_modules/@lukso/lsp-smart-contracts/artifacts/*.json'" }, "devDependencies": { - "@erc725/erc725.js": "0.21.0", + "@erc725/erc725.js": "0.21.1", "@esbuild-plugins/node-globals-polyfill": "0.2.3", "@formatjs/intl": "^2.9.5", "@lukso/lsp-smart-contracts": "0.12.0-rc.0", diff --git a/yarn.lock b/yarn.lock index 8f13b10d..8bf589e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1020,15 +1020,15 @@ __metadata: languageName: node linkType: hard -"@erc725/erc725.js@npm:0.21.0": - version: 0.21.0 - resolution: "@erc725/erc725.js@npm:0.21.0" +"@erc725/erc725.js@npm:0.21.1": + version: 0.21.1 + resolution: "@erc725/erc725.js@npm:0.21.1" dependencies: ethereumjs-util: ^7.1.5 web3-eth-abi: ^1.10.0 web3-providers-http: ^1.10.0 web3-utils: ^1.10.0 - checksum: d7904a6bb5339e0e6e7465822e3a33cdbd85401dd2f6bb927dbf82e027dfaf503a897036328d97f4245ca5cb97a96a2811dd8d2b10cc86b76be2e0d847c539dd + checksum: 61e291e0a0a49ed2fdfd3ced8477b3da48261ef42b66214370a5af463a69b25ddcf50652211b54e31c1f582d973707893f50b7111a35d42af81476be9e6c1706 languageName: node linkType: hard @@ -16375,7 +16375,7 @@ __metadata: version: 0.0.0-use.local resolution: "wallet.universalprofile.cloud@workspace:." dependencies: - "@erc725/erc725.js": 0.21.0 + "@erc725/erc725.js": 0.21.1 "@esbuild-plugins/node-globals-polyfill": 0.2.3 "@formatjs/intl": ^2.9.5 "@lukso/lsp-smart-contracts": 0.12.0-rc.0 From 2ce8b71eafa86c0b5725865846044b2c924e7dfd Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Tue, 7 Nov 2023 09:55:13 +0100 Subject: [PATCH 07/13] Update for getting token id --- .../schemas/LSP8IdentifiableDigitalAsset.json | 51 ------------------- utils/fetchLsp8Metadata.ts | 49 ++++++++++-------- 2 files changed, 27 insertions(+), 73 deletions(-) delete mode 100644 shared/schemas/LSP8IdentifiableDigitalAsset.json diff --git a/shared/schemas/LSP8IdentifiableDigitalAsset.json b/shared/schemas/LSP8IdentifiableDigitalAsset.json deleted file mode 100644 index 7d0af41f..00000000 --- a/shared/schemas/LSP8IdentifiableDigitalAsset.json +++ /dev/null @@ -1,51 +0,0 @@ -[ - { - "name": "LSP8MetadataAddress:
", - "key": "0x73dcc7c3c4096cdc7f8a0000
", - "keyType": "Mapping", - "valueType": "Mixed", - "valueContent": "Mixed" - }, - { - "name": "LSP8MetadataAddress:", - "key": "0x73dcc7c3c4096cdc7f8a0000", - "keyType": "Mapping", - "valueType": "Mixed", - "valueContent": "Mixed" - }, - { - "name": "LSP8MetadataAddress:", - "key": "0x73dcc7c3c4096cdc7f8a0000", - "keyType": "Mapping", - "valueType": "Mixed", - "valueContent": "Mixed" - }, - { - "name": "LSP8MetadataJSON:
", - "key": "0x9a26b4060ae7f7d5e3cd0000
", - "keyType": "Mapping", - "valueType": "bytes", - "valueContent": "JSONURL" - }, - { - "name": "LSP8MetadataJSON:", - "key": "0x9a26b4060ae7f7d5e3cd0000", - "keyType": "Mapping", - "valueType": "bytes", - "valueContent": "JSONURL" - }, - { - "name": "LSP8MetadataJSON:", - "key": "0x9a26b4060ae7f7d5e3cd0000", - "keyType": "Mapping", - "valueType": "bytes", - "valueContent": "JSONURL" - }, - { - "name": "LSP8TokenIdType", - "key": "0x715f248956de7ce65e94d9d836bfead479f7e70d69b718d47bfe7b00e05b4fe4", - "keyType": "Singleton", - "valueType": "uint256", - "valueContent": "Number" - } -] diff --git a/utils/fetchLsp8Metadata.ts b/utils/fetchLsp8Metadata.ts index 363f4fa5..8a6e120f 100644 --- a/utils/fetchLsp8Metadata.ts +++ b/utils/fetchLsp8Metadata.ts @@ -1,26 +1,13 @@ import { LSP4DigitalAssetMetadataJSON } from '@lukso/lsp-smart-contracts' -import { ERC725JSONSchema } from '@erc725/erc725.js' +import ERC725, { ERC725JSONSchema } from '@erc725/erc725.js' +import LSP8IdentifiableDigitalAsset from '@erc725/erc725.js/schemas/LSP8IdentifiableDigitalAsset.json' import { Lsp8TokenIdType } from '@/types/assets' -import LSP8IdentifiableDigitalAsset from '@/shared/schemas/LSP8IdentifiableDigitalAsset.json' export const fetchLsp8Metadata = async ( tokenId: string, assetAddress: Address ): Promise => { - const lsp8MetadataGetter = async ( - tokenIdType: string, - tokenId: string - ): Promise => { - const lsp8Metadata = await erc725.fetchData([ - { - keyName: `LSP8MetadataJSON:<${tokenIdType}>`, - dynamicKeyParts: tokenId, - }, - ]) - return validateLsp4MetaData(lsp8Metadata[0].value) - } - const { getInstance } = useErc725() const erc725 = getInstance( assetAddress, @@ -28,20 +15,24 @@ export const fetchLsp8Metadata = async ( ) try { - const lsp8DigitalAsset = await erc725.fetchData(['LSP8TokenIdType']) - const tokenIdType = Number(lsp8DigitalAsset[0].value) + const lsp8DigitalAsset = await erc725.fetchData('LSP8TokenIdType') + const tokenIdType = Number(lsp8DigitalAsset.value) - // fetch LSP8MetadataJSON depending on tokenIdType + // fetch metadata depending on tokenIdType switch (tokenIdType) { case Lsp8TokenIdType.NUMBER: - return await lsp8MetadataGetter('uint256', parseInt(tokenId).toString()) + return await getMetadata( + 'uint256', + parseInt(tokenId).toString(), + erc725 + ) case Lsp8TokenIdType.STRING: - return await lsp8MetadataGetter('string', tokenId.toString()) + return await getMetadata('string', tokenId.toString(), erc725) case Lsp8TokenIdType.UNIQUE_ID: case Lsp8TokenIdType.HASH: - return await lsp8MetadataGetter('bytes32', tokenId.toString()) + return await getMetadata('bytes32', tokenId.toString(), erc725) case Lsp8TokenIdType.ADDRESS: - return await lsp8MetadataGetter('address', tokenId.slice(0, 42)) + return await getMetadata('address', tokenId.slice(0, 42), erc725) default: throw new Error( `Unsupported LSP8 tokenIdType '${tokenIdType}' for '${assetAddress}' asset` @@ -60,3 +51,17 @@ export const fetchLsp8Metadata = async ( } } } + +const getMetadata = async ( + tokenIdType: string, + tokenIdValue: string, + erc725: ERC725 +) => { + const lsp8Metadata = await erc725.fetchData([ + { + keyName: `LSP8MetadataTokenURI:<${tokenIdType}>`, + dynamicKeyParts: tokenIdValue, + }, + ]) + return validateLsp4MetaData(lsp8Metadata[0].value) +} From bd27f690a86aa2b553a6fe5b69caf38e13dc53be Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Thu, 2 Nov 2023 15:32:45 +0100 Subject: [PATCH 08/13] Update for fetching LSP8 metadata based on token id type --- types/assets.ts | 18 +++++--- utils/fetchLsp8Metadata.ts | 95 +++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/types/assets.ts b/types/assets.ts index 5a733d44..96ca2bfb 100644 --- a/types/assets.ts +++ b/types/assets.ts @@ -1,4 +1,8 @@ -import { INTERFACE_IDS, ImageMetadata } from '@lukso/lsp-smart-contracts' +import { + INTERFACE_IDS, + ImageMetadata, + LSP8_TOKEN_ID_TYPES, +} from '@lukso/lsp-smart-contracts' export type InterfaceId = keyof typeof INTERFACE_IDS @@ -16,11 +20,13 @@ export enum AssetFilter { created = 'created', } -export enum Lsp8TokenIdType { - address = '1', - number = '2', - bytes32 = '3', -} +export const Lsp8TokenIdType = { + NUMBER: 0, + STRING: 1, + UNIQUE_ID: 2, + HASH: 3, + ADDRESS: 4, +} as typeof LSP8_TOKEN_ID_TYPES export type Base64EncodedImage = `data:image/jpeg;base64${string}` diff --git a/utils/fetchLsp8Metadata.ts b/utils/fetchLsp8Metadata.ts index 041cbfa9..53e34603 100644 --- a/utils/fetchLsp8Metadata.ts +++ b/utils/fetchLsp8Metadata.ts @@ -1,24 +1,13 @@ import { LSP4DigitalAssetMetadataJSON } from '@lukso/lsp-smart-contracts' -import { ERC725JSONSchema } from '@erc725/erc725.js' +import ERC725, { ERC725JSONSchema } from '@erc725/erc725.js' +import LSP8IdentifiableDigitalAsset from '@erc725/erc725.js/schemas/LSP8IdentifiableDigitalAsset.json' import { Lsp8TokenIdType } from '@/types/assets' -import LSP8IdentifiableDigitalAsset from '@/shared/schemas/LSP8IdentifiableDigitalAsset.json' export const fetchLsp8Metadata = async ( tokenId: string, assetAddress: Address -): Promise<[LSP4DigitalAssetMetadataJSON, string]> => { - const lsp8MetadataGetter = async ( - tokenIdType: string, - tokenId: string - ): Promise => { - const lsp8Metadata = await erc725.fetchData({ - keyName: `LSP8MetadataJSON:<${tokenIdType}>`, - dynamicKeyParts: tokenId, - }) - return validateLsp4MetaData(lsp8Metadata.value) - } - +): Promise<[LSP4DigitalAssetMetadataJSON, number]> => { const { getInstance } = useErc725() const erc725 = getInstance( assetAddress, @@ -26,43 +15,32 @@ export const fetchLsp8Metadata = async ( ) try { - const lsp8DigitalAsset = await erc725.fetchData(['LSP8TokenIdType']) - const tokenIdType = lsp8DigitalAsset[0].value?.toString() + const lsp8DigitalAsset = await erc725.fetchData('LSP8TokenIdType') + const tokenIdType = Number(lsp8DigitalAsset.value) - // fetch LSP8MetadataJSON depending on tokenIdType + // fetch metadata depending on tokenIdType switch (tokenIdType) { - case Lsp8TokenIdType.address: + case Lsp8TokenIdType.NUMBER: return [ - await lsp8MetadataGetter( - 'address', - // ethers.utils.hexDataSlice(tokenId.toString(), 12) - tokenId.toString() - ), + await getMetadata(tokenIdType, parseInt(tokenId).toString(), erc725), tokenIdType, ] - case Lsp8TokenIdType.number: + case Lsp8TokenIdType.STRING: + case Lsp8TokenIdType.UNIQUE_ID: + case Lsp8TokenIdType.HASH: return [ - await lsp8MetadataGetter('uint256', parseInt(tokenId).toString()), + await getMetadata(tokenIdType, tokenId.toString(), erc725), tokenIdType, ] - case Lsp8TokenIdType.bytes32: + case Lsp8TokenIdType.ADDRESS: return [ - await lsp8MetadataGetter('bytes32', tokenId.toString()), + await getMetadata(tokenIdType, tokenId.slice(0, 42), erc725), tokenIdType, ] default: - return [ - { - LSP4Metadata: { - description: '', - links: [], - images: [[]], - icon: [], - assets: [], - }, - }, - '', - ] + throw new Error( + `Unsupported LSP8 tokenIdType '${tokenIdType}' for '${assetAddress}' asset` + ) } } catch (error) { console.error(error) @@ -76,14 +54,31 @@ export const fetchLsp8Metadata = async ( assets: [], }, }, - '', + -1, ] } } -export const fetchLsp8Data = async ( +const tokenIdTypeString = (tokenIdType: number) => { + switch (tokenIdType) { + case Lsp8TokenIdType.NUMBER: + return 'uint256' + case Lsp8TokenIdType.STRING: + return 'string' + case Lsp8TokenIdType.UNIQUE_ID: + return 'bytes32' + case Lsp8TokenIdType.HASH: + return 'bytes32' + case Lsp8TokenIdType.ADDRESS: + return 'address' + default: + throw new Error(`Unsupported LSP8 tokenIdType '${tokenIdType}'`) + } +} + +export const getLsp8Data = async ( assetAddress: string, - tokenIdType?: string, + tokenIdType?: number, tokenId?: string ) => { if (!tokenIdType || !tokenId) { @@ -96,9 +91,23 @@ export const fetchLsp8Data = async ( LSP8IdentifiableDigitalAsset as ERC725JSONSchema[] ) const metaData = await erc725.getData({ - keyName: `LSP8MetadataJSON:<${tokenIdType}>`, + keyName: `LSP8MetadataTokenURI:<${tokenIdTypeString(tokenIdType)}>`, dynamicKeyParts: tokenId, }) return metaData } + +const getMetadata = async ( + tokenIdType: number, + tokenIdValue: string, + erc725: ERC725 +) => { + const lsp8Metadata = await erc725.fetchData([ + { + keyName: `LSP8MetadataTokenURI:<${tokenIdTypeString(tokenIdType)}>`, + dynamicKeyParts: tokenIdValue, + }, + ]) + return validateLsp4MetaData(lsp8Metadata[0].value) +} From 35a4c72e79a930e964ce53940d5552c0656fc23f Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Mon, 6 Nov 2023 10:17:53 +0100 Subject: [PATCH 09/13] Update types --- utils/fetchLSP7Assets.ts | 3 ++- utils/fetchLSP8Assets.ts | 3 ++- utils/fetchLsp7Balance.ts | 3 ++- utils/supportInterface.ts | 4 +++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/fetchLSP7Assets.ts b/utils/fetchLSP7Assets.ts index d4b10ba3..3aac082b 100644 --- a/utils/fetchLSP7Assets.ts +++ b/utils/fetchLSP7Assets.ts @@ -1,4 +1,5 @@ import LSP7DigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json' +import { AbiItem } from 'web3-utils' import { ImageMetadataEncoded } from '@/types/assets' import { LSP7DigitalAsset as LSP7DigitalAssetInterface } from '@/types/contracts' @@ -13,7 +14,7 @@ export const fetchLsp7Assets = async ( const { contract } = useWeb3(PROVIDERS.RPC) const lsp7Contract = contract( - LSP7DigitalAsset.abi as any, + LSP7DigitalAsset.abi as AbiItem[], address ) let balance = '' diff --git a/utils/fetchLSP8Assets.ts b/utils/fetchLSP8Assets.ts index 1acf74ed..6319e52c 100644 --- a/utils/fetchLSP8Assets.ts +++ b/utils/fetchLSP8Assets.ts @@ -1,4 +1,5 @@ import LSP8IdentifiableDigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP8IdentifiableDigitalAsset.json' +import { AbiItem } from 'web3-utils' import { LSP8IdentifiableDigitalAsset as LSP8IdentifiableDigitalAssetInterface } from '@/types/contracts/LSP8IdentifiableDigitalAsset' import { Asset } from '@/models/asset' @@ -11,7 +12,7 @@ export const fetchLsp8Assets = async ( ): Promise => { const { contract } = useWeb3(PROVIDERS.RPC) const lsp8Contract = contract( - LSP8IdentifiableDigitalAsset.abi as any, + LSP8IdentifiableDigitalAsset.abi as AbiItem[], address ) const tokenSupply = await lsp8Contract.methods.totalSupply().call() diff --git a/utils/fetchLsp7Balance.ts b/utils/fetchLsp7Balance.ts index 1a52aef7..ceaaa6b6 100644 --- a/utils/fetchLsp7Balance.ts +++ b/utils/fetchLsp7Balance.ts @@ -1,4 +1,5 @@ import LSP7DigitalAsset from '@lukso/lsp-smart-contracts/artifacts/LSP7DigitalAsset.json' +import { AbiItem } from 'web3-utils' import { LSP7DigitalAsset as LSP7DigitalAssetInterface } from '@/types/contracts' @@ -8,7 +9,7 @@ export const fetchLsp7Balance = async ( ) => { const { contract } = useWeb3(PROVIDERS.RPC) const lsp7Contract = contract( - LSP7DigitalAsset.abi as any, + LSP7DigitalAsset.abi as AbiItem[], assetAddress ) diff --git a/utils/supportInterface.ts b/utils/supportInterface.ts index a4b092eb..b188804e 100644 --- a/utils/supportInterface.ts +++ b/utils/supportInterface.ts @@ -1,3 +1,5 @@ +import { AbiItem } from 'web3-utils' + import { LSP0ERC725Account } from '@/types/contracts' /** @@ -16,7 +18,7 @@ export const supportInterface = async ( try { const eip165Contract = contract( - eip165ABI as any, + eip165ABI as AbiItem[], address ) return await eip165Contract.methods.supportsInterface(interfaceId).call() From 31c446aa5a0beb04f0a6f0c8b68212c69d4bb1ad Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Mon, 6 Nov 2023 10:56:25 +0100 Subject: [PATCH 10/13] Show warn when asset standard is not detected --- utils/fetchAsset.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/utils/fetchAsset.ts b/utils/fetchAsset.ts index 9d7b8a90..18f75688 100644 --- a/utils/fetchAsset.ts +++ b/utils/fetchAsset.ts @@ -1,10 +1,8 @@ -import { Asset } from '@/models/asset' - export const fetchAsset = async ( address: Address, profileAddress?: Address, tokenIds?: string[] -): Promise => { +) => { const standard = await detectStandard(address) switch (standard) { @@ -16,6 +14,7 @@ export const fetchAsset = async ( } default: + console.warn(`Asset ${address} standard is not supported`) return [] } } From a345791449d72ef4888e5100b2187306e545446f Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Tue, 7 Nov 2023 09:55:13 +0100 Subject: [PATCH 11/13] Update for getting token id --- .../schemas/LSP8IdentifiableDigitalAsset.json | 51 ------------------- 1 file changed, 51 deletions(-) delete mode 100644 shared/schemas/LSP8IdentifiableDigitalAsset.json diff --git a/shared/schemas/LSP8IdentifiableDigitalAsset.json b/shared/schemas/LSP8IdentifiableDigitalAsset.json deleted file mode 100644 index 7d0af41f..00000000 --- a/shared/schemas/LSP8IdentifiableDigitalAsset.json +++ /dev/null @@ -1,51 +0,0 @@ -[ - { - "name": "LSP8MetadataAddress:
", - "key": "0x73dcc7c3c4096cdc7f8a0000
", - "keyType": "Mapping", - "valueType": "Mixed", - "valueContent": "Mixed" - }, - { - "name": "LSP8MetadataAddress:", - "key": "0x73dcc7c3c4096cdc7f8a0000", - "keyType": "Mapping", - "valueType": "Mixed", - "valueContent": "Mixed" - }, - { - "name": "LSP8MetadataAddress:", - "key": "0x73dcc7c3c4096cdc7f8a0000", - "keyType": "Mapping", - "valueType": "Mixed", - "valueContent": "Mixed" - }, - { - "name": "LSP8MetadataJSON:
", - "key": "0x9a26b4060ae7f7d5e3cd0000
", - "keyType": "Mapping", - "valueType": "bytes", - "valueContent": "JSONURL" - }, - { - "name": "LSP8MetadataJSON:", - "key": "0x9a26b4060ae7f7d5e3cd0000", - "keyType": "Mapping", - "valueType": "bytes", - "valueContent": "JSONURL" - }, - { - "name": "LSP8MetadataJSON:", - "key": "0x9a26b4060ae7f7d5e3cd0000", - "keyType": "Mapping", - "valueType": "bytes", - "valueContent": "JSONURL" - }, - { - "name": "LSP8TokenIdType", - "key": "0x715f248956de7ce65e94d9d836bfead479f7e70d69b718d47bfe7b00e05b4fe4", - "keyType": "Singleton", - "valueType": "uint256", - "valueContent": "Number" - } -] From 30242ad3c19c60f4430d0478442280914dc48a2e Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Thu, 16 Nov 2023 11:54:54 +0100 Subject: [PATCH 12/13] Rebase --- models/asset.ts | 4 ++-- repositories/asset.ts | 2 +- utils/fetchLSP8Assets.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/asset.ts b/models/asset.ts index c1724169..aa0fca0d 100644 --- a/models/asset.ts +++ b/models/asset.ts @@ -23,7 +23,7 @@ export class AssetModel extends BaseModel { description: this.string(''), links: this.attr([]), tokenId: this.string(''), - tokenIdType: this.string(''), + tokenIdType: this.number(null), isNativeToken: this.boolean(false), hash: this.string(''), verification: this.attr({}), @@ -46,7 +46,7 @@ export class AssetModel extends BaseModel { declare description?: string declare links?: LinkMetadata[] declare tokenId?: string - declare tokenIdType?: string + declare tokenIdType?: number declare isNativeToken?: boolean declare hash: string declare verification?: ImageMetadata['verification'] diff --git a/repositories/asset.ts b/repositories/asset.ts index 34d8531f..03e3540c 100644 --- a/repositories/asset.ts +++ b/repositories/asset.ts @@ -30,7 +30,7 @@ export class AssetRepository extends Repository { } if (storageAsset.standard === 'LSP8IdentifiableDigitalAsset') { - assetData = await fetchLsp8Data( + assetData = await getLsp8Data( assetAddress, storageAsset?.tokenIdType, storageAsset?.tokenId diff --git a/utils/fetchLSP8Assets.ts b/utils/fetchLSP8Assets.ts index 6319e52c..9a0ab36a 100644 --- a/utils/fetchLSP8Assets.ts +++ b/utils/fetchLSP8Assets.ts @@ -37,7 +37,7 @@ export const fetchLsp8Assets = async ( tokenId, address ) - const getData = await fetchLsp8Data(address, tokenIdType, tokenId) + const getData = await getLsp8Data(address, tokenIdType, tokenId) const { description, images: metadataImages, From 0f8b54fb789be479f44ffe3a091b1cf9e28df2c9 Mon Sep 17 00:00:00 2001 From: Dominik Zborowski Date: Thu, 16 Nov 2023 15:02:18 +0100 Subject: [PATCH 13/13] Lint --- utils/validateLSP4Metadata.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/validateLSP4Metadata.ts b/utils/validateLSP4Metadata.ts index 195a2968..5e52a623 100644 --- a/utils/validateLSP4Metadata.ts +++ b/utils/validateLSP4Metadata.ts @@ -1,5 +1,7 @@ -import { Verification } from '@erc725/erc725.js/build/main/src/types' -import { LSP4DigitalAssetMetadataJSON } from '@lukso/lsp-smart-contracts' +import { + LSP4DigitalAssetMetadataJSON, + AssetMetadata, +} from '@lukso/lsp-smart-contracts' export const validateLsp4MetaData = ( LSP4MetadataJSON: any @@ -142,6 +144,6 @@ export const validateVerification = (getDataObject: any) => { 'verification' in getDataObject?.value && 'data' in getDataObject?.value?.verification && 'method' in getDataObject?.value?.verification - ? (getDataObject.value?.verification as Verification) + ? (getDataObject.value?.verification as AssetMetadata['verification']) : undefined }