Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/gas config #331

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8a518eb
Merge pull request #72 from ERC725Alliance/develop
frozeman Jan 5, 2022
ff19b0e
Merge pull request #81 from ERC725Alliance/develop
Hugoo Jan 5, 2022
a63b82d
Merge pull request #88 from ERC725Alliance/develop
frozeman Jan 6, 2022
8ecbc25
Merge pull request #102 from ERC725Alliance/develop
Hugoo Feb 2, 2022
dfdd027
Merge pull request #112 from ERC725Alliance/develop
frozeman Mar 3, 2022
3bd4b93
Merge pull request #115 from ERC725Alliance/develop
frozeman Mar 16, 2022
0b7a93b
improved example titles encodeData
frozeman Mar 30, 2022
b050aeb
Merge pull request #128 from ERC725Alliance/develop
Hugoo Apr 6, 2022
269a540
Merge pull request #131 from ERC725Alliance/develop
Hugoo Apr 6, 2022
ebea7f5
Merge pull request #144 from ERC725Alliance/develop
Hugoo May 20, 2022
0c75f63
Merge pull request #170 from ERC725Alliance/develop
Hugoo Jun 2, 2022
4401e62
Merge pull request #177 from ERC725Alliance/develop
Hugoo Jun 9, 2022
22c5e1a
Merge pull request #186 from ERC725Alliance/develop
Hugoo Jun 14, 2022
303720a
Merge pull request #190 from ERC725Alliance/develop
Hugoo Jun 15, 2022
714495f
Merge pull request #198 from ERC725Alliance/develop
Hugoo Jun 24, 2022
44ab226
Merge pull request #211 from ERC725Alliance/develop
Hugoo Jul 7, 2022
0d0064d
Merge pull request #218 from ERC725Alliance/develop
Hugoo Jul 25, 2022
6ef86bc
Merge pull request #226 from ERC725Alliance/develop
CallumGrindle Sep 14, 2022
ed3522b
Merge pull request #250 from ERC725Alliance/develop
Hugoo Oct 28, 2022
fbca5c4
Merge pull request #273 from ERC725Alliance/develop
Hugoo Feb 7, 2023
88b0e03
Merge pull request #276 from ERC725Alliance/develop
Hugoo Feb 8, 2023
3ec90bf
Merge pull request #284 from ERC725Alliance/develop
Hugoo Mar 14, 2023
866ba2c
chore(release): 0.18.0
Hugoo Aug 3, 2023
b3027c6
Merge pull request #305 from ERC725Alliance/release-v0.18.0
Hugoo Aug 3, 2023
89c41e5
Merge pull request #314 from ERC725Alliance/develop
CallumGrindle Oct 5, 2023
100d42b
chore(main): release 0.19.0
github-actions[bot] Oct 5, 2023
20198f4
Merge pull request #315 from ERC725Alliance/release-please--branches-…
CallumGrindle Oct 13, 2023
2aaeeb1
Update schemas.md
frozeman Oct 18, 2023
e4c09c7
Merge pull request #318 from ERC725Alliance/develop
CallumGrindle Oct 18, 2023
4c5860d
chore(main): release 0.20.0
github-actions[bot] Oct 18, 2023
d9e647c
Merge pull request #322 from ERC725Alliance/develop
CallumGrindle Oct 18, 2023
42e105e
Merge pull request #320 from ERC725Alliance/release-please--branches-…
CallumGrindle Oct 18, 2023
6982b23
Merge pull request #329 from ERC725Alliance/develop
CJ42 Oct 30, 2023
4635125
chore(main): release 0.20.1
github-actions[bot] Oct 30, 2023
51c29c5
Merge pull request #330 from ERC725Alliance/release-please--branches-…
CJ42 Oct 30, 2023
f975707
add new gas parameter + remove unused gasPrice
kalote Oct 31, 2023
aae8d52
fixing test + no magic number
kalote Oct 31, 2023
1b1ee16
update docs
kalote Oct 31, 2023
456a00a
improved example titles encodeData
frozeman Mar 30, 2022
603c5f4
chore(release): 0.18.0
Hugoo Aug 3, 2023
1c4d614
chore(main): release 0.19.0
github-actions[bot] Oct 5, 2023
2290d4f
chore(main): release 0.20.0
github-actions[bot] Oct 18, 2023
c7bb408
chore(main): release 0.20.1
github-actions[bot] Oct 30, 2023
8cbab22
add new gas parameter + remove unused gasPrice
kalote Oct 31, 2023
1d7f116
fixing test + no magic number
kalote Oct 31, 2023
26e5b0a
update docs
kalote Oct 31, 2023
e14844f
Merge branch 'feat/gas-config' of github.com:kalote/erc725.js into fe…
kalote Oct 31, 2023
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
67 changes: 66 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,72 @@

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)


### 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)


### ⚠ 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

- 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))
Expand Down Expand Up @@ -103,7 +169,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))
Expand Down
77 changes: 21 additions & 56 deletions docs/classes/ERC725.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,37 +454,14 @@ myErc725.encodeData([
*/
```

```javascript
myErc725.encodeData([
{
keyName: 'LSP1UniversalReceiverDelegate',
value: '0x1183790f29BE3cDfD0A102862fEA1a4a30b3AdAb',
},
]);
/**
{
keys: ['0x0cfc51aec37c55a4d0b1a65c6255c4bf2fbdf6277f3cc0730c45b828b6db8b47'],
values: ['0x1183790f29be3cdfd0a102862fea1a4a30b3adab'],
}
*/
```

</details>

<details>
<summary>Encode a <code>JSONURL</code> with hash function, hash and uploaded URL</summary>

```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'],
Expand Down Expand Up @@ -554,33 +531,19 @@ myErc725.encodeData(
*/
```

</details>

<details>
<summary>Encode multiple keys at once</summary>

```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: [
Expand Down Expand Up @@ -1446,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

Expand Down Expand Up @@ -1473,6 +1437,7 @@ myErc725.supportsInterface('LSP0ERC725Account');
ERC725.supportsInterface('LSP0ERC725Account', {
address: '0x0Dc07C77985fE31996Ed612F568eb441afe5768D',
rpcUrl: 'https://rpc.testnet.lukso.network',
gas: 20_000_000,
});
// true
```
4 changes: 3 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -127,6 +128,7 @@ After the instance has been created, it is still possible to change settings thr
myERC725.options.schema = '<schema>' // change schema
myERC725.options.address '<address>' // change address
myERC725.options.ipfsGateway = '<url>' // 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
```
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erc725/erc725.js",
"version": "0.17.2",
"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",
Expand Down
14 changes: 2 additions & 12 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,35 @@ export const METHODS: Record<Method, MethodData> = {
[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,
},
Expand Down Expand Up @@ -183,3 +171,5 @@ export const LSP6_ALL_PERMISSIONS =
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';

export const COMPACT_BYTES_ARRAY_STRING = '[CompactBytesArray]';

export const DEFAULT_GAS_VALUE = 2_000_000;
23 changes: 16 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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}`);
}
Expand Down Expand Up @@ -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<boolean>} if interface is supported.
*/
static async supportsInterface(
interfaceIdOrName: string,
options: { address: string; rpcUrl: string },
options: { address: string; rpcUrl: string; gas?: number },
): Promise<boolean> {
if (!isAddress(options.address)) {
throw new Error('Invalid address');
Expand All @@ -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,
),
});
}

Expand Down
Loading
Loading