From 0b7a93be46146de18785118b757a4a5de0bffd85 Mon Sep 17 00:00:00 2001 From: Fabian Vogelsteller Date: Wed, 30 Mar 2022 14:10:45 +0500 Subject: [PATCH 01/17] improved example titles encodeData --- docs/classes/ERC725.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index 3bfc2895..e02357c5 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -104,7 +104,7 @@ An object with the same keys as the object that was passed in as a parameter con #### Example -```javascript title="Encoding object with one key" +```javascript title="Encode a JSONURL with json and uploaded URL" const encodedDataOneKey = erc725.encodeData({ LSP3Profile: { json: profileJson, // check instantiation.js to see the actual JSON @@ -121,7 +121,7 @@ const encodedDataOneKey = erc725.encodeData({ */ ``` -```javascript title="Encoding object with one key" +```javascript title="Encode a JSONURL with json, hash function, hash and uploaded URL" const encodedDataOneKeyV2 = erc725.encodeData({ LSP3Profile: { hashFunction: 'keccak256(utf8)', @@ -140,7 +140,7 @@ const encodedDataOneKeyV2 = erc725.encodeData({ */ ``` -```javascript title="Encoding object with multiple keys" +```javascript title="Encode multiple keys at once" const encodedDataManyKeys = erc725.encodeData({ LSP3Profile: { hashFunction: 'keccak256(utf8)', From 866ba2cdc231a111c4fdd54884e8bd04fb11646c Mon Sep 17 00:00:00 2001 From: Hugo Masclet Date: Thu, 3 Aug 2023 12:22:31 +0200 Subject: [PATCH 02/17] chore(release): 0.18.0 --- CHANGELOG.md | 23 ++++++++++++++++++++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d380e1..1f5c284d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.18.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.2...v0.18.0) (2023-08-03) + +### ⚠ BREAKING CHANGES + +- new encoding for static value types (not arrays `[]`) (#288) +- change `ArrayLength` value from `uint256` to `uint128` (#287) + +### Features + +- add checkPermissions function ([17d2258](https://github.com/ERC725Alliance/erc725.js/commit/17d225843c236951ef1515a0ff91095b5ef27cd3)) +- Add new feature "Decode Mapping Key" ([8c1f1fc](https://github.com/ERC725Alliance/erc725.js/commit/8c1f1fcfb15fa43d1d3934b0b15f09d47902bb41)) + +### Bug Fixes + +- decode any uint256 as number not string ([#289](https://github.com/ERC725Alliance/erc725.js/issues/289)) ([37203f1](https://github.com/ERC725Alliance/erc725.js/commit/37203f14d313a0caff75724dc74175c741c1b540)) +- variable naming ([44b4785](https://github.com/ERC725Alliance/erc725.js/commit/44b47851ed63b817edc21c63655d67bac13a7e7f)) + +### improvement + +- change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) ([c95ee8a](https://github.com/ERC725Alliance/erc725.js/commit/c95ee8a53bf25bcf47777054af27cae1fbad8b2f)) +- new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) ([f0b04da](https://github.com/ERC725Alliance/erc725.js/commit/f0b04daa57a281c537a8f28594439573188f0dce)) + ### [0.17.2](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.1...v0.17.2) (2023-03-14) - removed ERC725JSONSchemaKeyType duplicate value ([060ee6c](https://github.com/ERC725Alliance/erc725.js/commit/060ee6ce23bda328f727140419de7590f48fc394)) @@ -103,7 +125,6 @@ Minor update to update the LSP-2 schemas. ### improvement -- change fetchData output to non object ([1d4d570](https://github.com/ERC725Alliance/erc725.js/commit/1d4d57077a7766b3490477efb20f194fc4e00da4)) - fetchData as same output as decodeData ([59c3a87](https://github.com/ERC725Alliance/erc725.js/commit/59c3a879fefb2b9bfe46b9bea91ff6bd2a528df1)) - getData as same output as decodeData ([0f3b149](https://github.com/ERC725Alliance/erc725.js/commit/0f3b149f2280e6025a05e8e9ed306facfa63601a)) - use array for decodeData ([261d100](https://github.com/ERC725Alliance/erc725.js/commit/261d1007f4ff63abd9d794f4e64e5b408ce7c1a3)) diff --git a/package-lock.json b/package-lock.json index 01181bfa..d068a9f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.17.2", + "version": "0.18.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.17.2", + "version": "0.18.0", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 217f6c87..25e73534 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.17.2", + "version": "0.18.0", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 100d42becf2478d98d8e9f40356089edb8012a08 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 09:56:42 +0000 Subject: [PATCH 03/17] chore(main): release 0.19.0 --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5c284d..71b2249f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,36 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.19.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.18.0...v0.19.0) (2023-10-05) + + +### ⚠ BREAKING CHANGES + +* change LSP3 to SupportedStandards:LSP3Profile ([#307](https://github.com/ERC725Alliance/erc725.js/issues/307)) +* new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) +* change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) + +### Features + +* add checkPermissions function ([17d2258](https://github.com/ERC725Alliance/erc725.js/commit/17d225843c236951ef1515a0ff91095b5ef27cd3)) +* add schemas for LSP8 + LSP17 ([#311](https://github.com/ERC725Alliance/erc725.js/issues/311)) ([1e8dbf7](https://github.com/ERC725Alliance/erc725.js/commit/1e8dbf765c6c5e250539b402e9bd5a395966a8c2)) + + +### Bug Fixes + +* decode any uint256 as number not string ([#289](https://github.com/ERC725Alliance/erc725.js/issues/289)) ([37203f1](https://github.com/ERC725Alliance/erc725.js/commit/37203f14d313a0caff75724dc74175c741c1b540)) +* dependencies & example ([#302](https://github.com/ERC725Alliance/erc725.js/issues/302)) ([9979e89](https://github.com/ERC725Alliance/erc725.js/commit/9979e89e438cd9f7cc586d7dc271de969f13b125)) +* incorrect value in schema for array length in `...Map` ([#310](https://github.com/ERC725Alliance/erc725.js/issues/310)) ([0d28b13](https://github.com/ERC725Alliance/erc725.js/commit/0d28b1317dc085078090a8babacf4db517d91a87)) +* Remove hardcoded require ([5279278](https://github.com/ERC725Alliance/erc725.js/commit/527927812b1a05b13f8dc6b14aecaa6d24e98d61)) +* variable naming ([44b4785](https://github.com/ERC725Alliance/erc725.js/commit/44b47851ed63b817edc21c63655d67bac13a7e7f)) + + +### Code Refactoring + +* change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) ([c95ee8a](https://github.com/ERC725Alliance/erc725.js/commit/c95ee8a53bf25bcf47777054af27cae1fbad8b2f)) +* change LSP3 to SupportedStandards:LSP3Profile ([#307](https://github.com/ERC725Alliance/erc725.js/issues/307)) ([73f3481](https://github.com/ERC725Alliance/erc725.js/commit/73f34818fe152c3ab5299177adc0eddfed6886c5)) +* new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) ([f0b04da](https://github.com/ERC725Alliance/erc725.js/commit/f0b04daa57a281c537a8f28594439573188f0dce)) + ## [0.18.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.2...v0.18.0) (2023-08-03) ### ⚠ BREAKING CHANGES diff --git a/package-lock.json b/package-lock.json index d068a9f6..7029f5ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.18.0", + "version": "0.19.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.18.0", + "version": "0.19.0", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 25e73534..0e326f26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.18.0", + "version": "0.19.0", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 2aaeeb17125f069b691b81ba6c24f603cdaae4ed Mon Sep 17 00:00:00 2001 From: Fabian Vogelsteller Date: Wed, 18 Oct 2023 14:07:41 +0200 Subject: [PATCH 04/17] Update schemas.md --- docs/schemas.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/schemas.md b/docs/schemas.md index 91549769..1d133093 100644 --- a/docs/schemas.md +++ b/docs/schemas.md @@ -45,4 +45,7 @@ import LSP5 from '@erc725/erc725.js/schemas/LSP5ReceivedAssets.json'; // Later use them on instantiation const myErc725Contract = new ERC725js(LSP3, address, web3.currentProvider); + +// You can retrieve the current loaded schema via +myErc725Contract.options.schemas ``` From 4c5860d32a7f59e8dc8766dcd6525ae036ed9dec Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:47:44 +0000 Subject: [PATCH 05/17] chore(main): release 0.20.0 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b2249f..93c639e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.20.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.19.0...v0.20.0) (2023-10-18) + + +### Features + +* add permission `EXECUTE_RELAY_CALL` ([6db8835](https://github.com/ERC725Alliance/erc725.js/commit/6db8835ccd9d1082d9e8184bb2f14972760bea69)) + ## [0.19.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.18.0...v0.19.0) (2023-10-05) diff --git a/package-lock.json b/package-lock.json index 7029f5ea..14c78fbf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.19.0", + "version": "0.20.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.19.0", + "version": "0.20.0", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 0e326f26..69ded2bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.19.0", + "version": "0.20.0", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 4635125888c37c24d3215a3eed615fe27c112a36 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:47:58 +0000 Subject: [PATCH 06/17] chore(main): release 0.20.1 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c639e1..51882859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.20.1](https://github.com/ERC725Alliance/erc725.js/compare/v0.20.0...v0.20.1) (2023-10-30) + + +### Bug Fixes + +* incorrect permission value for `EXECUTE_RELAY_CALL` ([55b8f5e](https://github.com/ERC725Alliance/erc725.js/commit/55b8f5e64c29c5a85d872f605667c88c1546f6b3)) + ## [0.20.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.19.0...v0.20.0) (2023-10-18) diff --git a/package-lock.json b/package-lock.json index 196959bf..c7997238 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.20.0", + "version": "0.20.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.20.0", + "version": "0.20.1", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 69ded2bd..625e93ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.20.0", + "version": "0.20.1", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From f975707c9ad34e4fb9de76f6e0e1d3c0ab7cd094 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:09:26 +0100 Subject: [PATCH 07/17] add new gas parameter + remove unused gasPrice --- src/constants/constants.ts | 14 ++------------ src/index.ts | 23 +++++++++++++++------- src/lib/provider-wrapper-utils.ts | 7 +++++-- src/provider/providerWrapper.ts | 32 +++++++++++++++++++++++++------ src/types/Config.ts | 1 + src/types/Method.ts | 2 -- 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 4915183d..21eb28f5 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -58,47 +58,35 @@ export const METHODS: Record = { [Method.GET_DATA_LEGACY]: { // Legacy version of ERC725Y - before v0.3.0 sig: '0x54f6127f', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES, }, [Method.GET_DATA]: { // https://github.com/ERC725Alliance/ERC725/blob/v4.0.0/docs/ERC-725.md#erc725y sig: '0x4e3e6e9c', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, [Method.GET_DATA_BATCH]: { // https://github.com/ERC725Alliance/ERC725/blob/v5.1.0/docs/ERC-725.md#erc725y sig: '0xdedff9c6', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, [Method.OWNER]: { sig: '0x8da5cb5b', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.ADDRESS, }, [Method.SUPPORTS_INTERFACE]: { // https://eips.ethereum.org/EIPS/eip-165 sig: '0x01ffc9a7', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BOOL, }, [Method.IS_VALID_SIGNATURE]: { // https://eips.ethereum.org/EIPS/eip-1271 sig: '0x1626ba7e', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES4, }, @@ -183,3 +171,5 @@ export const LSP6_ALL_PERMISSIONS = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; + +export const DEFAULT_GAS_VALUE = 2000000; diff --git a/src/index.ts b/src/index.ts index 6a07e404..ec12ebbe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ import { isValidSignature } from './lib/isValidSignature'; import { LSP6_ALL_PERMISSIONS, LSP6_DEFAULT_PERMISSIONS, + DEFAULT_GAS_VALUE, } from './constants/constants'; import { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName'; @@ -105,15 +106,20 @@ export class ERC725 { const defaultConfig = { ipfsGateway: 'https://cloudflare-ipfs.com/ipfs/', + gas: DEFAULT_GAS_VALUE, }; this.options = { schemas: this.validateSchemas(schemas), address, - provider: ERC725.initializeProvider(provider), + provider: ERC725.initializeProvider( + provider, + config?.gas ? config?.gas : defaultConfig.gas, + ), ipfsGateway: config?.ipfsGateway ? convertIPFSGatewayUrl(config?.ipfsGateway) : defaultConfig.ipfsGateway, + gas: config?.gas ? config?.gas : defaultConfig.gas, }; } @@ -151,20 +157,20 @@ export class ERC725 { }); } - private static initializeProvider(providerOrRpcUrl) { + private static initializeProvider(providerOrRpcUrl, gasInfo) { // do not fail on no-provider if (!providerOrRpcUrl) return undefined; // if provider is a string, assume it's a rpcUrl if (typeof providerOrRpcUrl === 'string') { - return new ProviderWrapper(new HttpProvider(providerOrRpcUrl)); + return new ProviderWrapper(new HttpProvider(providerOrRpcUrl), gasInfo); } if ( typeof providerOrRpcUrl.request === 'function' || typeof providerOrRpcUrl.send === 'function' ) - return new ProviderWrapper(providerOrRpcUrl); + return new ProviderWrapper(providerOrRpcUrl, gasInfo); throw new Error(`Incorrect or unsupported provider ${providerOrRpcUrl}`); } @@ -593,12 +599,12 @@ export class ERC725 { * supports a certain interface. * * @param {string} interfaceIdOrName Interface ID or supported interface name. - * @param options Object of address and RPC URL. + * @param options Object of address, RPC URL and optional gas. * @returns {Promise} if interface is supported. */ static async supportsInterface( interfaceIdOrName: string, - options: { address: string; rpcUrl: string }, + options: { address: string; rpcUrl: string; gas?: number }, ): Promise { if (!isAddress(options.address)) { throw new Error('Invalid address'); @@ -609,7 +615,10 @@ export class ERC725 { return supportsInterface(interfaceIdOrName, { address: options.address, - provider: this.initializeProvider(options.rpcUrl), + provider: this.initializeProvider( + options.rpcUrl, + options?.gas ? options?.gas : DEFAULT_GAS_VALUE, + ), }); } diff --git a/src/lib/provider-wrapper-utils.ts b/src/lib/provider-wrapper-utils.ts index 5f2adf67..0a0d52a0 100644 --- a/src/lib/provider-wrapper-utils.ts +++ b/src/lib/provider-wrapper-utils.ts @@ -13,6 +13,7 @@ */ import * as abi from 'web3-eth-abi'; +import { numberToHex } from 'web3-utils'; import { JsonRpc, @@ -49,6 +50,7 @@ export function decodeResult(method: Method, hexString: string) { const constructJSONRPCParams = ( address: string, method: Method, + gasInfo: number, methodParam?: string, ): JsonRpcEthereumProviderParamsWithLatest => { const data = methodParam @@ -59,7 +61,7 @@ const constructJSONRPCParams = ( { to: address, value: METHODS[method].value, - gas: METHODS[method].gas, + gas: numberToHex(gasInfo), data, }, 'latest', @@ -69,13 +71,14 @@ const constructJSONRPCParams = ( export function constructJSONRPC( address: string, method: Method, + gasInfo: number, methodParam?: string, ): JsonRpc { idCount += 1; return { jsonrpc: '2.0', method: 'eth_call', - params: constructJSONRPCParams(address, method, methodParam), + params: constructJSONRPCParams(address, method, gasInfo, methodParam), id: idCount, }; } diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index 3f7026db..a3f235d1 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -40,18 +40,20 @@ interface GetDataReturn { export class ProviderWrapper { type: ProviderTypes; provider: any; - constructor(provider: any) { + gas: number; + constructor(provider: any, gasInfo: number) { if (typeof provider.request === 'function') { this.type = ProviderTypes.ETHEREUM; } else { this.type = ProviderTypes.WEB3; } this.provider = provider; + this.gas = gasInfo; } async getOwner(address: string) { const result = await this.callContract( - constructJSONRPC(address, Method.OWNER), + constructJSONRPC(address, Method.OWNER, this.gas), ); if (result.error) { throw result.error; @@ -115,6 +117,7 @@ export class ProviderWrapper { constructJSONRPC( address, Method.SUPPORTS_INTERFACE, + this.gas, `${interfaceId}${'00000000000000000000000000000000000000000000000000000000'}`, ), ); @@ -152,7 +155,12 @@ export class ProviderWrapper { ); const result = await this.callContract( - constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams), + constructJSONRPC( + address, + Method.IS_VALID_SIGNATURE, + this.gas, + encodedParams, + ), ); if (result.error) { @@ -172,7 +180,12 @@ export class ProviderWrapper { ); const results = await this.callContract([ - constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams), + constructJSONRPC( + address, + Method.IS_VALID_SIGNATURE, + this.gas, + encodedParams, + ), ]); if (results.error) { throw results.error; @@ -232,6 +245,7 @@ export class ProviderWrapper { constructJSONRPC( address, method, + this.gas, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ); @@ -248,6 +262,7 @@ export class ProviderWrapper { constructJSONRPC( address, method, + this.gas, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ]; @@ -270,7 +285,7 @@ export class ProviderWrapper { // But this is already legacy and it won't be used anymore.. const encodedResultsPromises = keyHashes.map((keyHash) => this.callContract( - constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHash), + constructJSONRPC(address, Method.GET_DATA_LEGACY, this.gas, keyHash), ), ); @@ -287,7 +302,12 @@ export class ProviderWrapper { // But this is already legacy and it won't be used anymore.. for (let index = 0; index < keyHashes.length; index++) { payload.push( - constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHashes[index]), + constructJSONRPC( + address, + Method.GET_DATA_LEGACY, + this.gas, + keyHashes[index], + ), ); } diff --git a/src/types/Config.ts b/src/types/Config.ts index 24e4ab33..fa40adbb 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -11,6 +11,7 @@ export interface ERC725Config { * Another example: `https://cloudflare-ipfs.com/ipfs/` */ ipfsGateway: string; + gas: number; } export interface ERC725Options { diff --git a/src/types/Method.ts b/src/types/Method.ts index e28b49ab..1c794a67 100644 --- a/src/types/Method.ts +++ b/src/types/Method.ts @@ -19,8 +19,6 @@ export enum Encoding { export interface MethodData { sig: string; - gas: string; - gasPrice: string; value: string; returnEncoding: Encoding; } From aae8d52cff3cabe6e54a8472e7e14684ba3b818b Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:27:54 +0100 Subject: [PATCH 08/17] fixing test + no magic number --- src/constants/constants.ts | 2 +- src/provider/providerWrapper.test.ts | 7 ++++--- src/types/Config.ts | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 21eb28f5..c9948fc9 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -172,4 +172,4 @@ export const LSP6_ALL_PERMISSIONS = export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; -export const DEFAULT_GAS_VALUE = 2000000; +export const DEFAULT_GAS_VALUE = 2_000_000; diff --git a/src/provider/providerWrapper.test.ts b/src/provider/providerWrapper.test.ts index 91748eb3..75e8ed94 100644 --- a/src/provider/providerWrapper.test.ts +++ b/src/provider/providerWrapper.test.ts @@ -3,6 +3,7 @@ import assert from 'assert'; import { ProviderWrapper } from './providerWrapper'; const erc725AccountAddress = '0x214be121bB52e6909c5158579b3458f8760f1b2f'; +const defaultGas = 2_000_000; describe('ProviderWrapper', () => { describe('#getOwner', () => { @@ -15,7 +16,7 @@ describe('ProviderWrapper', () => { }); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); const owner = await ethSource.getOwner(erc725AccountAddress); assert.deepStrictEqual( @@ -30,7 +31,7 @@ describe('ProviderWrapper', () => { cb(new Error('some error')); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); try { await ethSource.getOwner(erc725AccountAddress); @@ -47,7 +48,7 @@ describe('ProviderWrapper', () => { }); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); try { await ethSource.getOwner(erc725AccountAddress); diff --git a/src/types/Config.ts b/src/types/Config.ts index fa40adbb..15707591 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -5,13 +5,14 @@ export interface ERC725Config { * ```js title=Example * const config = { * ipfsGateway: 'https://ipfs.lukso.network/ipfs/' + * gas: 20_000_000 // Optional, default 2_000_000 * }; * ``` * Make sure to use the following format: `/ipfs/`.
* Another example: `https://cloudflare-ipfs.com/ipfs/` */ ipfsGateway: string; - gas: number; + gas?: number; } export interface ERC725Options { From 1b1ee162fb76839ee8e91e2fa24bf550794eb53c Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:37:29 +0100 Subject: [PATCH 09/17] update docs --- docs/classes/ERC725.md | 2 ++ docs/getting-started.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index c6a41019..48985771 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -1446,6 +1446,7 @@ On non instantiated class, you should provide an `options` object. | :-------- | :----- | :------------------------------------------------------------------- | | `address` | string | Address of the smart contract to check against a certain interface. | | `rpcUrl` | string | RPC URL to connect to the network the smart contract is deployed to. | +| `gas` | number | Optional: gas parameter to use. Default: 2_000_000. | #### Returns @@ -1473,6 +1474,7 @@ myErc725.supportsInterface('LSP0ERC725Account'); ERC725.supportsInterface('LSP0ERC725Account', { address: '0x0Dc07C77985fE31996Ed612F568eb441afe5768D', rpcUrl: 'https://rpc.testnet.lukso.network', + gas: 20_000_000, }); // true ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index cbe47702..71b05e92 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -61,6 +61,7 @@ const address = '0x0Dc07C77985fE31996Ed612F568eb441afe5768D'; const RPC_URL = 'https://rpc.testnet.lukso.network'; const config = { ipfsGateway: 'https://YOUR-IPFS-GATEWAY/ipfs/', + gas: 20_000_000, // optional, default is 2_000_000 }; const erc725 = new ERC725(schemas, address, RPC_URL, config); @@ -110,7 +111,7 @@ await erc725.fetchData('LSP3Profile'); // downloads and verifies the linked JSON ``` :::tip Try it out -You can run the code snippit within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js). +You can run the code snippet within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js). :::note Whenever you can you should import `ERC725` via the named export. However currently we are also providing a default export. @@ -127,6 +128,7 @@ After the instance has been created, it is still possible to change settings thr myERC725.options.schema = '' // change schema myERC725.options.address '
' // change address myERC725.options.ipfsGateway = '' // used for fetchData(), default: 'https://cloudflare-ipfs.com/ipfs/' +myERC725.options.gas = 20_000_000 // change gas setting // NOTE: ERC725.provider can not be changed ``` From 456a00a68223818357e7db83961e47a606bb000b Mon Sep 17 00:00:00 2001 From: Fabian Vogelsteller Date: Wed, 30 Mar 2022 14:10:45 +0500 Subject: [PATCH 10/17] improved example titles encodeData --- docs/classes/ERC725.md | 75 +++++++++++------------------------------- 1 file changed, 19 insertions(+), 56 deletions(-) diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index c6a41019..e42636ea 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -454,37 +454,14 @@ myErc725.encodeData([ */ ``` -```javascript -myErc725.encodeData([ - { - keyName: 'LSP1UniversalReceiverDelegate', - value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb', - }, -]); -/** -{ - keys: ['0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47'], - values: ['0x1183790f29be3cdfd0a102862fea1a4a30b3adab'], -} -*/ -``` - - - -
- Encode a JSONURL with hash function, hash and uploaded URL - -```javascript title="Encode a JSONURL with hash function, hash and uploaded URL" -myErc725.encodeData([ - { - keyName: 'LSP3Profile', - value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', - url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', - }, +```javascript title="Encoding object with one key" +const encodedDataOneKeyV2 = erc725.encodeData({ + LSP3Profile: { + hashFunction: 'keccak256(utf8)', + hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + url: 'ifps://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, -]); +}); /** { keys: ['0x5ef83ad9559033e6e941db7d7c495acdce616347d28e90c7ce47cbfcfcad3bc5'], @@ -554,33 +531,19 @@ myErc725.encodeData( */ ``` -
- -
- Encode multiple keys at once - -```javascript title="Encode multiple keys at once" -myErc725.encodeData([ - { - keyName: 'LSP3Profile', - value: { - hashFunction: 'keccak256(utf8)', - hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', - url: 'ipfs://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', - }, - }, - { - keyName: 'LSP12IssuedAssets[]', - value: [ - '0xD94353D9B005B3c0A9Da169b768a31C57844e490', - '0xDaea594E385Fc724449E3118B2Db7E86dFBa1826', - ], - }, - { - keyName: 'LSP1UniversalReceiverDelegate', - value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb', +```javascript title="Encoding object with multiple keys" +const encodedDataManyKeys = erc725.encodeData({ + LSP3Profile: { + hashFunction: 'keccak256(utf8)', + hash: '0x820464ddfac1bec070cc14a8daf04129871d458f2ca94368aae8391311af6361', + url: 'ifps://QmYr1VJLwerg6pEoscdhVGugo39pa6rycEZLjtRPDfW84UAx', }, -]); + 'LSP3IssuedAssets[]': [ + '0xD94353D9B005B3c0A9Da169b768a31C57844e490', + '0xDaea594E385Fc724449E3118B2Db7E86dFBa1826', + ], + LSP1UniversalReceiverDelegate: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb', +}); /** { keys: [ From 603c5f4d0de1a9dee51d1319e17b7437c8d79d65 Mon Sep 17 00:00:00 2001 From: Hugo Masclet Date: Thu, 3 Aug 2023 12:22:31 +0200 Subject: [PATCH 11/17] chore(release): 0.18.0 --- CHANGELOG.md | 23 ++++++++++++++++++++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09d380e1..1f5c284d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.18.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.2...v0.18.0) (2023-08-03) + +### ⚠ BREAKING CHANGES + +- new encoding for static value types (not arrays `[]`) (#288) +- change `ArrayLength` value from `uint256` to `uint128` (#287) + +### Features + +- add checkPermissions function ([17d2258](https://github.com/ERC725Alliance/erc725.js/commit/17d225843c236951ef1515a0ff91095b5ef27cd3)) +- Add new feature "Decode Mapping Key" ([8c1f1fc](https://github.com/ERC725Alliance/erc725.js/commit/8c1f1fcfb15fa43d1d3934b0b15f09d47902bb41)) + +### Bug Fixes + +- decode any uint256 as number not string ([#289](https://github.com/ERC725Alliance/erc725.js/issues/289)) ([37203f1](https://github.com/ERC725Alliance/erc725.js/commit/37203f14d313a0caff75724dc74175c741c1b540)) +- variable naming ([44b4785](https://github.com/ERC725Alliance/erc725.js/commit/44b47851ed63b817edc21c63655d67bac13a7e7f)) + +### improvement + +- change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) ([c95ee8a](https://github.com/ERC725Alliance/erc725.js/commit/c95ee8a53bf25bcf47777054af27cae1fbad8b2f)) +- new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) ([f0b04da](https://github.com/ERC725Alliance/erc725.js/commit/f0b04daa57a281c537a8f28594439573188f0dce)) + ### [0.17.2](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.1...v0.17.2) (2023-03-14) - removed ERC725JSONSchemaKeyType duplicate value ([060ee6c](https://github.com/ERC725Alliance/erc725.js/commit/060ee6ce23bda328f727140419de7590f48fc394)) @@ -103,7 +125,6 @@ Minor update to update the LSP-2 schemas. ### improvement -- change fetchData output to non object ([1d4d570](https://github.com/ERC725Alliance/erc725.js/commit/1d4d57077a7766b3490477efb20f194fc4e00da4)) - fetchData as same output as decodeData ([59c3a87](https://github.com/ERC725Alliance/erc725.js/commit/59c3a879fefb2b9bfe46b9bea91ff6bd2a528df1)) - getData as same output as decodeData ([0f3b149](https://github.com/ERC725Alliance/erc725.js/commit/0f3b149f2280e6025a05e8e9ed306facfa63601a)) - use array for decodeData ([261d100](https://github.com/ERC725Alliance/erc725.js/commit/261d1007f4ff63abd9d794f4e64e5b408ce7c1a3)) diff --git a/package-lock.json b/package-lock.json index 813b016f..d0cf9e1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.17.2", + "version": "0.18.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.17.2", + "version": "0.18.0", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 217f6c87..25e73534 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.17.2", + "version": "0.18.0", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 1c4d6141ad6dfcb50af5d70a5f582b7d4812df98 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 09:56:42 +0000 Subject: [PATCH 12/17] chore(main): release 0.19.0 --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5c284d..71b2249f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,36 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.19.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.18.0...v0.19.0) (2023-10-05) + + +### ⚠ BREAKING CHANGES + +* change LSP3 to SupportedStandards:LSP3Profile ([#307](https://github.com/ERC725Alliance/erc725.js/issues/307)) +* new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) +* change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) + +### Features + +* add checkPermissions function ([17d2258](https://github.com/ERC725Alliance/erc725.js/commit/17d225843c236951ef1515a0ff91095b5ef27cd3)) +* add schemas for LSP8 + LSP17 ([#311](https://github.com/ERC725Alliance/erc725.js/issues/311)) ([1e8dbf7](https://github.com/ERC725Alliance/erc725.js/commit/1e8dbf765c6c5e250539b402e9bd5a395966a8c2)) + + +### Bug Fixes + +* decode any uint256 as number not string ([#289](https://github.com/ERC725Alliance/erc725.js/issues/289)) ([37203f1](https://github.com/ERC725Alliance/erc725.js/commit/37203f14d313a0caff75724dc74175c741c1b540)) +* dependencies & example ([#302](https://github.com/ERC725Alliance/erc725.js/issues/302)) ([9979e89](https://github.com/ERC725Alliance/erc725.js/commit/9979e89e438cd9f7cc586d7dc271de969f13b125)) +* incorrect value in schema for array length in `...Map` ([#310](https://github.com/ERC725Alliance/erc725.js/issues/310)) ([0d28b13](https://github.com/ERC725Alliance/erc725.js/commit/0d28b1317dc085078090a8babacf4db517d91a87)) +* Remove hardcoded require ([5279278](https://github.com/ERC725Alliance/erc725.js/commit/527927812b1a05b13f8dc6b14aecaa6d24e98d61)) +* variable naming ([44b4785](https://github.com/ERC725Alliance/erc725.js/commit/44b47851ed63b817edc21c63655d67bac13a7e7f)) + + +### Code Refactoring + +* change `ArrayLength` value from `uint256` to `uint128` ([#287](https://github.com/ERC725Alliance/erc725.js/issues/287)) ([c95ee8a](https://github.com/ERC725Alliance/erc725.js/commit/c95ee8a53bf25bcf47777054af27cae1fbad8b2f)) +* change LSP3 to SupportedStandards:LSP3Profile ([#307](https://github.com/ERC725Alliance/erc725.js/issues/307)) ([73f3481](https://github.com/ERC725Alliance/erc725.js/commit/73f34818fe152c3ab5299177adc0eddfed6886c5)) +* new encoding for static value types (not arrays `[]`) ([#288](https://github.com/ERC725Alliance/erc725.js/issues/288)) ([f0b04da](https://github.com/ERC725Alliance/erc725.js/commit/f0b04daa57a281c537a8f28594439573188f0dce)) + ## [0.18.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.17.2...v0.18.0) (2023-08-03) ### ⚠ BREAKING CHANGES diff --git a/package-lock.json b/package-lock.json index d0cf9e1c..e79f1cc7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.18.0", + "version": "0.19.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.18.0", + "version": "0.19.0", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 25e73534..0e326f26 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.18.0", + "version": "0.19.0", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 2290d4f4199962b1e4bd03e393ca293c621261db Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 12:47:44 +0000 Subject: [PATCH 13/17] chore(main): release 0.20.0 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71b2249f..93c639e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.20.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.19.0...v0.20.0) (2023-10-18) + + +### Features + +* add permission `EXECUTE_RELAY_CALL` ([6db8835](https://github.com/ERC725Alliance/erc725.js/commit/6db8835ccd9d1082d9e8184bb2f14972760bea69)) + ## [0.19.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.18.0...v0.19.0) (2023-10-05) diff --git a/package-lock.json b/package-lock.json index e79f1cc7..196959bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.19.0", + "version": "0.20.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.19.0", + "version": "0.20.0", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 0e326f26..69ded2bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.19.0", + "version": "0.20.0", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From c7bb408dd8123dc64df4a8c75558852378f926de Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:47:58 +0000 Subject: [PATCH 14/17] chore(main): release 0.20.1 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c639e1..51882859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [0.20.1](https://github.com/ERC725Alliance/erc725.js/compare/v0.20.0...v0.20.1) (2023-10-30) + + +### Bug Fixes + +* incorrect permission value for `EXECUTE_RELAY_CALL` ([55b8f5e](https://github.com/ERC725Alliance/erc725.js/commit/55b8f5e64c29c5a85d872f605667c88c1546f6b3)) + ## [0.20.0](https://github.com/ERC725Alliance/erc725.js/compare/v0.19.0...v0.20.0) (2023-10-18) diff --git a/package-lock.json b/package-lock.json index 196959bf..c7997238 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erc725/erc725.js", - "version": "0.20.0", + "version": "0.20.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@erc725/erc725.js", - "version": "0.20.0", + "version": "0.20.1", "license": "Apache-2.0", "dependencies": { "ethereumjs-util": "^7.1.5", diff --git a/package.json b/package.json index 69ded2bd..625e93ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@erc725/erc725.js", - "version": "0.20.0", + "version": "0.20.1", "description": "Library to interact with ERC725 smart contracts", "main": "build/main/src/index.js", "typings": "build/main/src/index.d.ts", From 8cbab227a5463e70b1d7352104784d8c84ed8279 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:09:26 +0100 Subject: [PATCH 15/17] add new gas parameter + remove unused gasPrice --- src/constants/constants.ts | 14 ++------------ src/index.ts | 23 +++++++++++++++------- src/lib/provider-wrapper-utils.ts | 7 +++++-- src/provider/providerWrapper.ts | 32 +++++++++++++++++++++++++------ src/types/Config.ts | 1 + src/types/Method.ts | 2 -- 6 files changed, 50 insertions(+), 29 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 4915183d..21eb28f5 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -58,47 +58,35 @@ export const METHODS: Record = { [Method.GET_DATA_LEGACY]: { // Legacy version of ERC725Y - before v0.3.0 sig: '0x54f6127f', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES, }, [Method.GET_DATA]: { // https://github.com/ERC725Alliance/ERC725/blob/v4.0.0/docs/ERC-725.md#erc725y sig: '0x4e3e6e9c', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, [Method.GET_DATA_BATCH]: { // https://github.com/ERC725Alliance/ERC725/blob/v5.1.0/docs/ERC-725.md#erc725y sig: '0xdedff9c6', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES_ARRAY, }, [Method.OWNER]: { sig: '0x8da5cb5b', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.ADDRESS, }, [Method.SUPPORTS_INTERFACE]: { // https://eips.ethereum.org/EIPS/eip-165 sig: '0x01ffc9a7', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BOOL, }, [Method.IS_VALID_SIGNATURE]: { // https://eips.ethereum.org/EIPS/eip-1271 sig: '0x1626ba7e', - gas: numberToHex(2000000), - gasPrice: numberToHex(100000000), value: numberToHex(0), returnEncoding: Encoding.BYTES4, }, @@ -183,3 +171,5 @@ export const LSP6_ALL_PERMISSIONS = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'; export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; + +export const DEFAULT_GAS_VALUE = 2000000; diff --git a/src/index.ts b/src/index.ts index 6a07e404..ec12ebbe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ import { isValidSignature } from './lib/isValidSignature'; import { LSP6_ALL_PERMISSIONS, LSP6_DEFAULT_PERMISSIONS, + DEFAULT_GAS_VALUE, } from './constants/constants'; import { encodeKeyName, isDynamicKeyName } from './lib/encodeKeyName'; @@ -105,15 +106,20 @@ export class ERC725 { const defaultConfig = { ipfsGateway: 'https://cloudflare-ipfs.com/ipfs/', + gas: DEFAULT_GAS_VALUE, }; this.options = { schemas: this.validateSchemas(schemas), address, - provider: ERC725.initializeProvider(provider), + provider: ERC725.initializeProvider( + provider, + config?.gas ? config?.gas : defaultConfig.gas, + ), ipfsGateway: config?.ipfsGateway ? convertIPFSGatewayUrl(config?.ipfsGateway) : defaultConfig.ipfsGateway, + gas: config?.gas ? config?.gas : defaultConfig.gas, }; } @@ -151,20 +157,20 @@ export class ERC725 { }); } - private static initializeProvider(providerOrRpcUrl) { + private static initializeProvider(providerOrRpcUrl, gasInfo) { // do not fail on no-provider if (!providerOrRpcUrl) return undefined; // if provider is a string, assume it's a rpcUrl if (typeof providerOrRpcUrl === 'string') { - return new ProviderWrapper(new HttpProvider(providerOrRpcUrl)); + return new ProviderWrapper(new HttpProvider(providerOrRpcUrl), gasInfo); } if ( typeof providerOrRpcUrl.request === 'function' || typeof providerOrRpcUrl.send === 'function' ) - return new ProviderWrapper(providerOrRpcUrl); + return new ProviderWrapper(providerOrRpcUrl, gasInfo); throw new Error(`Incorrect or unsupported provider ${providerOrRpcUrl}`); } @@ -593,12 +599,12 @@ export class ERC725 { * supports a certain interface. * * @param {string} interfaceIdOrName Interface ID or supported interface name. - * @param options Object of address and RPC URL. + * @param options Object of address, RPC URL and optional gas. * @returns {Promise} if interface is supported. */ static async supportsInterface( interfaceIdOrName: string, - options: { address: string; rpcUrl: string }, + options: { address: string; rpcUrl: string; gas?: number }, ): Promise { if (!isAddress(options.address)) { throw new Error('Invalid address'); @@ -609,7 +615,10 @@ export class ERC725 { return supportsInterface(interfaceIdOrName, { address: options.address, - provider: this.initializeProvider(options.rpcUrl), + provider: this.initializeProvider( + options.rpcUrl, + options?.gas ? options?.gas : DEFAULT_GAS_VALUE, + ), }); } diff --git a/src/lib/provider-wrapper-utils.ts b/src/lib/provider-wrapper-utils.ts index 5f2adf67..0a0d52a0 100644 --- a/src/lib/provider-wrapper-utils.ts +++ b/src/lib/provider-wrapper-utils.ts @@ -13,6 +13,7 @@ */ import * as abi from 'web3-eth-abi'; +import { numberToHex } from 'web3-utils'; import { JsonRpc, @@ -49,6 +50,7 @@ export function decodeResult(method: Method, hexString: string) { const constructJSONRPCParams = ( address: string, method: Method, + gasInfo: number, methodParam?: string, ): JsonRpcEthereumProviderParamsWithLatest => { const data = methodParam @@ -59,7 +61,7 @@ const constructJSONRPCParams = ( { to: address, value: METHODS[method].value, - gas: METHODS[method].gas, + gas: numberToHex(gasInfo), data, }, 'latest', @@ -69,13 +71,14 @@ const constructJSONRPCParams = ( export function constructJSONRPC( address: string, method: Method, + gasInfo: number, methodParam?: string, ): JsonRpc { idCount += 1; return { jsonrpc: '2.0', method: 'eth_call', - params: constructJSONRPCParams(address, method, methodParam), + params: constructJSONRPCParams(address, method, gasInfo, methodParam), id: idCount, }; } diff --git a/src/provider/providerWrapper.ts b/src/provider/providerWrapper.ts index 3f7026db..a3f235d1 100644 --- a/src/provider/providerWrapper.ts +++ b/src/provider/providerWrapper.ts @@ -40,18 +40,20 @@ interface GetDataReturn { export class ProviderWrapper { type: ProviderTypes; provider: any; - constructor(provider: any) { + gas: number; + constructor(provider: any, gasInfo: number) { if (typeof provider.request === 'function') { this.type = ProviderTypes.ETHEREUM; } else { this.type = ProviderTypes.WEB3; } this.provider = provider; + this.gas = gasInfo; } async getOwner(address: string) { const result = await this.callContract( - constructJSONRPC(address, Method.OWNER), + constructJSONRPC(address, Method.OWNER, this.gas), ); if (result.error) { throw result.error; @@ -115,6 +117,7 @@ export class ProviderWrapper { constructJSONRPC( address, Method.SUPPORTS_INTERFACE, + this.gas, `${interfaceId}${'00000000000000000000000000000000000000000000000000000000'}`, ), ); @@ -152,7 +155,12 @@ export class ProviderWrapper { ); const result = await this.callContract( - constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams), + constructJSONRPC( + address, + Method.IS_VALID_SIGNATURE, + this.gas, + encodedParams, + ), ); if (result.error) { @@ -172,7 +180,12 @@ export class ProviderWrapper { ); const results = await this.callContract([ - constructJSONRPC(address, Method.IS_VALID_SIGNATURE, encodedParams), + constructJSONRPC( + address, + Method.IS_VALID_SIGNATURE, + this.gas, + encodedParams, + ), ]); if (results.error) { throw results.error; @@ -232,6 +245,7 @@ export class ProviderWrapper { constructJSONRPC( address, method, + this.gas, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ); @@ -248,6 +262,7 @@ export class ProviderWrapper { constructJSONRPC( address, method, + this.gas, abiCoder.encodeParameter('bytes32[]', keyHashes), ), ]; @@ -270,7 +285,7 @@ export class ProviderWrapper { // But this is already legacy and it won't be used anymore.. const encodedResultsPromises = keyHashes.map((keyHash) => this.callContract( - constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHash), + constructJSONRPC(address, Method.GET_DATA_LEGACY, this.gas, keyHash), ), ); @@ -287,7 +302,12 @@ export class ProviderWrapper { // But this is already legacy and it won't be used anymore.. for (let index = 0; index < keyHashes.length; index++) { payload.push( - constructJSONRPC(address, Method.GET_DATA_LEGACY, keyHashes[index]), + constructJSONRPC( + address, + Method.GET_DATA_LEGACY, + this.gas, + keyHashes[index], + ), ); } diff --git a/src/types/Config.ts b/src/types/Config.ts index 24e4ab33..fa40adbb 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -11,6 +11,7 @@ export interface ERC725Config { * Another example: `https://cloudflare-ipfs.com/ipfs/` */ ipfsGateway: string; + gas: number; } export interface ERC725Options { diff --git a/src/types/Method.ts b/src/types/Method.ts index e28b49ab..1c794a67 100644 --- a/src/types/Method.ts +++ b/src/types/Method.ts @@ -19,8 +19,6 @@ export enum Encoding { export interface MethodData { sig: string; - gas: string; - gasPrice: string; value: string; returnEncoding: Encoding; } From 1d7f116c551763952a333204badbfa04704c6f59 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:27:54 +0100 Subject: [PATCH 16/17] fixing test + no magic number --- src/constants/constants.ts | 2 +- src/provider/providerWrapper.test.ts | 7 ++++--- src/types/Config.ts | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 21eb28f5..c9948fc9 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -172,4 +172,4 @@ export const LSP6_ALL_PERMISSIONS = export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]'; -export const DEFAULT_GAS_VALUE = 2000000; +export const DEFAULT_GAS_VALUE = 2_000_000; diff --git a/src/provider/providerWrapper.test.ts b/src/provider/providerWrapper.test.ts index 91748eb3..75e8ed94 100644 --- a/src/provider/providerWrapper.test.ts +++ b/src/provider/providerWrapper.test.ts @@ -3,6 +3,7 @@ import assert from 'assert'; import { ProviderWrapper } from './providerWrapper'; const erc725AccountAddress = '0x214be121bB52e6909c5158579b3458f8760f1b2f'; +const defaultGas = 2_000_000; describe('ProviderWrapper', () => { describe('#getOwner', () => { @@ -15,7 +16,7 @@ describe('ProviderWrapper', () => { }); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); const owner = await ethSource.getOwner(erc725AccountAddress); assert.deepStrictEqual( @@ -30,7 +31,7 @@ describe('ProviderWrapper', () => { cb(new Error('some error')); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); try { await ethSource.getOwner(erc725AccountAddress); @@ -47,7 +48,7 @@ describe('ProviderWrapper', () => { }); }, }; - const ethSource = new ProviderWrapper(mockProvider); + const ethSource = new ProviderWrapper(mockProvider, defaultGas); try { await ethSource.getOwner(erc725AccountAddress); diff --git a/src/types/Config.ts b/src/types/Config.ts index fa40adbb..15707591 100644 --- a/src/types/Config.ts +++ b/src/types/Config.ts @@ -5,13 +5,14 @@ export interface ERC725Config { * ```js title=Example * const config = { * ipfsGateway: 'https://ipfs.lukso.network/ipfs/' + * gas: 20_000_000 // Optional, default 2_000_000 * }; * ``` * Make sure to use the following format: `/ipfs/`.
* Another example: `https://cloudflare-ipfs.com/ipfs/` */ ipfsGateway: string; - gas: number; + gas?: number; } export interface ERC725Options { From 26e5b0a373fc477a27741b78b5d5b3ca1b2bf9b0 Mon Sep 17 00:00:00 2001 From: Johann BICH <2253470+kalote@users.noreply.github.com> Date: Tue, 31 Oct 2023 10:37:29 +0100 Subject: [PATCH 17/17] update docs --- docs/classes/ERC725.md | 2 ++ docs/getting-started.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/classes/ERC725.md b/docs/classes/ERC725.md index e42636ea..02300358 100644 --- a/docs/classes/ERC725.md +++ b/docs/classes/ERC725.md @@ -1409,6 +1409,7 @@ On non instantiated class, you should provide an `options` object. | :-------- | :----- | :------------------------------------------------------------------- | | `address` | string | Address of the smart contract to check against a certain interface. | | `rpcUrl` | string | RPC URL to connect to the network the smart contract is deployed to. | +| `gas` | number | Optional: gas parameter to use. Default: 2_000_000. | #### Returns @@ -1436,6 +1437,7 @@ myErc725.supportsInterface('LSP0ERC725Account'); ERC725.supportsInterface('LSP0ERC725Account', { address: '0x0Dc07C77985fE31996Ed612F568eb441afe5768D', rpcUrl: 'https://rpc.testnet.lukso.network', + gas: 20_000_000, }); // true ``` diff --git a/docs/getting-started.md b/docs/getting-started.md index cbe47702..71b05e92 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -61,6 +61,7 @@ const address = '0x0Dc07C77985fE31996Ed612F568eb441afe5768D'; const RPC_URL = 'https://rpc.testnet.lukso.network'; const config = { ipfsGateway: 'https://YOUR-IPFS-GATEWAY/ipfs/', + gas: 20_000_000, // optional, default is 2_000_000 }; const erc725 = new ERC725(schemas, address, RPC_URL, config); @@ -110,7 +111,7 @@ await erc725.fetchData('LSP3Profile'); // downloads and verifies the linked JSON ``` :::tip Try it out -You can run the code snippit within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js). +You can run the code snippet within your browser using the corresponding [StackBlitz example](https://stackblitz.com/edit/erc725js-instantiation?devtoolsheight=66&file=index.js). :::note Whenever you can you should import `ERC725` via the named export. However currently we are also providing a default export. @@ -127,6 +128,7 @@ After the instance has been created, it is still possible to change settings thr myERC725.options.schema = '' // change schema myERC725.options.address '
' // change address myERC725.options.ipfsGateway = '' // used for fetchData(), default: 'https://cloudflare-ipfs.com/ipfs/' +myERC725.options.gas = 20_000_000 // change gas setting // NOTE: ERC725.provider can not be changed ```