diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 420f0aa5..3f1b511d 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -45,10 +45,13 @@ export const ERC725Y_INTERFACE_IDS = { }; export enum ERC725_VERSION { - ERC725_BATCH = 'ERC725_BATCH', // https://github.com/ERC725Alliance/ERC725/pull/209 - ERC725 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/commit/cca7f98cdf243f1ebf1c0a3ae89b1e46931481b0 - ERC725_LEGACY = 'ERC725_LEGACY', NOT_ERC725 = 'NOT_ERC725', + // The ERC725Y_LEGACY version uses getData(bytes32) function + ERC725_LEGACY = 'ERC725_LEGACY', + // The ERC725_v2 version uses getData(bytes32[]) function, as well as v3 and v4 + ERC725_v2 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/releases/tag/v2.2.0 + // The ERC725_v5 version uses getDataBatch(bytes32[]) function + ERC725_v5 = 'ERC725_v5', // https://github.com/ERC725Alliance/ERC725/releases/tag/v5.0.0 } export const METHODS: Record = { diff --git a/src/index.test.ts b/src/index.test.ts index 911197a8..ca2c64d4 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -306,7 +306,7 @@ describe('Running @erc725/erc725.js tests...', () => { describe('Getting data (using new getDataBatch) in schema by provider [e2e] - luksoTestnet', () => { const web3 = new Web3('https://rpc.testnet.lukso.network'); - const ERC725_BATCH_CONTRACT_ADDRESS = + const ERC725_V5_CONTRACT_ADDRESS = '0x4b30900F119E11D2A8CAe18176c4f9840E586Cc4'; const e2eSchema: any = [ @@ -346,7 +346,7 @@ describe('Running @erc725/erc725.js tests...', () => { it('with web3.currentProvider [ERC725Y_BATCH]', async () => { const erc725 = new ERC725( e2eSchema, - ERC725_BATCH_CONTRACT_ADDRESS, + ERC725_V5_CONTRACT_ADDRESS, web3.currentProvider, ); const result = await erc725.getData(); diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index 7b2d5d86..d097fae5 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -61,31 +61,32 @@ export class ProviderWrapper { } async getErc725YVersion(address: string): Promise { - const isErc725YBatch = await this.supportsInterface( + const isErc725Yv5 = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['5.0'], ); - if (isErc725YBatch) { - return ERC725_VERSION.ERC725_BATCH; + if (isErc725Yv5) { + return ERC725_VERSION.ERC725_v5; } - const isErc725Y = await this.supportsInterface( + const isErc725Yv3 = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['3.0'], ); - if (isErc725Y) { - return ERC725_VERSION.ERC725; + // The version 3 of the package can use the getData function from v2, still compatible + if (isErc725Yv3) { + return ERC725_VERSION.ERC725_v2; } - const isErc725Yv200 = await this.supportsInterface( + const isErc725Yv2 = await this.supportsInterface( address, ERC725Y_INTERFACE_IDS['2.0'], ); - if (isErc725Yv200) { - return ERC725_VERSION.ERC725; + if (isErc725Yv2) { + return ERC725_VERSION.ERC725_v2; } // v0.2.0 and v0.6.0 have the same function signatures for getData, only versions before v0.2.0 requires a different call @@ -206,9 +207,9 @@ export class ProviderWrapper { } switch (erc725Version) { - case ERC725_VERSION.ERC725_BATCH: + case ERC725_VERSION.ERC725_v5: return this._getAllDataBatch(address, keyHashes); - case ERC725_VERSION.ERC725: + case ERC725_VERSION.ERC725_v2: return this._getAllData(address, keyHashes); case ERC725_VERSION.ERC725_LEGACY: return this._getAllDataLegacy(address, keyHashes);