Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/classes/internal_.IExecContractsClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Create a client for IExec contracts
| Name | Type | Description |
| :------ | :------ | :------ |
| `args` | `Object` | - |
| `args.chainId` | `string` \| `number` | id of the chain to use (used to resolve IExec contract address) |
| `args.chainId` | `string` \| `number` | id of the chain |
| `args.confirms?` | `number` | number of block to wait for transactions confirmation (default 1) |
| `args.hubAddress?` | `string` | override the IExec contract address to target a custom instance |
| `args.hubAddress` | `string` | IExec contract address |
| `args.isNative?` | `boolean` | true if IExec contract use the chain native token |
| `args.provider` | `Provider` | ethers Provider |
| `args.signer?` | `Signer` | ethers Signer, required to sign transactions and messages |
Expand Down
11 changes: 11 additions & 0 deletions docs/interfaces/IExecConfigOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Properties

- [allowExperimentalNetworks](IExecConfigOptions.md#allowexperimentalnetworks)
- [bridgeAddress](IExecConfigOptions.md#bridgeaddress)
- [bridgedNetworkConf](IExecConfigOptions.md#bridgednetworkconf)
- [confirms](IExecConfigOptions.md#confirms)
Expand All @@ -25,6 +26,16 @@

## Properties

### allowExperimentalNetworks

• `Optional` **allowExperimentalNetworks**: `boolean`

if true allows using a provider connected to an experimental networks (default false)

⚠️ experimental networks are networks on which the iExec's stack is partially deployed, experimental networks can be subject to instabilities or discontinuity. Access is provided without warranties.

___

### bridgeAddress

• `Optional` **bridgeAddress**: `string`
Expand Down
1 change: 1 addition & 0 deletions docs/modules/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ const iexec = new IExec({ ethProvider });
| `host` | `string` | node RPC url |
| `privateKey` | `string` | wallet private key |
| `options?` | `Object` | - |
| `options.allowExperimentalNetworks?` | `boolean` | if true allows using a provider connected to an experimental networks (default false) ⚠️ experimental networks are networks on which the iExec's stack is partially deployed, experimental networks can be subject to instabilities or discontinuity. Access is provided without warranties. |
| `options.gasPrice?` | `string` \| `number` \| `bigint` | gas price override |
| `options.getTransactionCount?` | (`blockTag?`: `BlockTag`) => `Promise`<`number`\> | nonce override |
| `options.providers` | [`ProviderOptions`](../interfaces/ProviderOptions.md) | providers options |
Expand Down
4 changes: 1 addition & 3 deletions src/cli/cmd/iexec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ infoCmd
const chain = await loadChain(opts.chain, { spinner });

const host =
chain.host === getChainDefaults({ id: chain.id }).host
? 'default'
: chain.host;
chain.host === getChainDefaults(chain.id).host ? 'default' : chain.host;
spinner.info(`Ethereum host: ${host}`);

spinner.start(info.checking('iExec contracts info'));
Expand Down
79 changes: 50 additions & 29 deletions src/cli/utils/chains.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Debug from 'debug';
import { getChainDefaults } from '../../common/utils/config.js';
import { getId, getChainDefaults } from '../../common/utils/config.js';
import IExecContractsClient from '../../common/utils/IExecContractsClient.js';
import { EnhancedWallet } from '../../common/utils/signers.js';
import { loadChainConf } from './fs.js';
Expand All @@ -8,27 +8,21 @@ import { getReadOnlyProvider } from '../../common/utils/providers.js';

const debug = Debug('iexec:chains');

const CHAIN_ALIASES_MAP = {
1: 'mainnet',
134: 'bellecour',
};

const CHAIN_NAME_MAP = {
1: { id: '1' },
mainnet: { id: '1' },
134: { id: '134' },
bellecour: { id: '134' },
};

const createChainFromConf = (
chainName,
chainConf,
{ bridgeConf, providerOptions, txOptions = {} } = {},
{
bridgeConf,
providerOptions,
txOptions = {},
allowExperimentalNetworks = false,
} = {},
) => {
try {
const chain = { ...chainConf };
const provider = getReadOnlyProvider(chainConf.host, {
providers: providerOptions,
allowExperimentalNetworks,
});

chain.name = chainName;
Expand All @@ -45,6 +39,7 @@ const createChainFromConf = (
chain.bridgedNetwork = { ...bridgeConf };
const bridgeProvider = getReadOnlyProvider(bridgeConf.host, {
providers: providerOptions,
allowExperimentalNetworks,
});
chain.bridgedNetwork.contracts = new IExecContractsClient({
provider: bridgeProvider,
Expand All @@ -63,26 +58,34 @@ const createChainFromConf = (
};

export const loadChain = async (
chainName,
chainNameOrId,
{ txOptions, spinner = Spinner() } = {},
) => {
try {
const chainsConf = await loadChainConf();
debug('chainsConf', chainsConf);
const { allowExperimentalNetworks } = chainsConf;
const providerOptions = chainsConf.providers;
let name;
let loadedConf;
if (chainName) {
if (chainsConf.chains[chainName]) {
loadedConf = chainsConf.chains[chainName];
name = chainName;
if (chainNameOrId) {
if (chainsConf.chains[chainNameOrId]) {
loadedConf = chainsConf.chains[chainNameOrId];
name = chainNameOrId;
} else {
const alias = CHAIN_ALIASES_MAP[chainName];
const { name: alias } = getChainDefaults(
getId(chainNameOrId, {
allowExperimentalNetworks,
}),
{
allowExperimentalNetworks,
},
);
if (alias && chainsConf.chains[alias]) {
loadedConf = chainsConf.chains[alias];
name = alias;
}
if (!name) throw Error(`Missing "${chainName}" chain in "chain.json"`);
if (!name)
throw Error(`Missing "${chainNameOrId}" chain in "chain.json"`);
}
} else if (chainsConf.default) {
if (chainsConf.chains[chainsConf.default]) {
Expand All @@ -96,11 +99,16 @@ export const loadChain = async (
throw Error('Missing chain parameter. Check your "chain.json" file');

const idConf = {
...CHAIN_NAME_MAP[name],
...(loadedConf.id && { id: loadedConf.id }),
id:
loadedConf.id ||
getId(name, {
allowExperimentalNetworks,
}),
};

const defaultConf = getChainDefaults(idConf);
const defaultConf = getChainDefaults(idConf.id, {
allowExperimentalNetworks,
});

debug('loading chain', name);
debug('loadedConf', loadedConf);
Expand All @@ -120,18 +128,30 @@ export const loadChain = async (
if (chainsConf.chains[bridgedChainNameOrId]) {
bridgeLoadedConf = chainsConf.chains[bridgedChainNameOrId];
} else {
const alias = CHAIN_ALIASES_MAP[bridgedChainNameOrId];
const { name: alias } = getChainDefaults(
getId(bridgedChainNameOrId, {
allowExperimentalNetworks,
}),
{
allowExperimentalNetworks,
},
);
if (alias && chainsConf.chains[alias]) {
bridgeLoadedConf = chainsConf.chains[alias];
}
if (!bridgeLoadedConf)
throw Error(`Missing "${name}" chain in "chain.json"`);
}
const bridgeIdConf = {
...CHAIN_NAME_MAP[bridgedChainNameOrId],
...(bridgeLoadedConf.id && { id: bridgeLoadedConf.id }),
id:
bridgeLoadedConf.id ||
getId(bridgedChainNameOrId, {
allowExperimentalNetworks,
}),
};
const bridgeDefaultConf = getChainDefaults(bridgeIdConf);
const bridgeDefaultConf = getChainDefaults(bridgeIdConf.id, {
allowExperimentalNetworks,
});
debug('bridgeLoadedConf', bridgeLoadedConf);
debug('bridgeDefaultConf', defaultConf);
bridgeConf = {
Expand All @@ -150,6 +170,7 @@ export const loadChain = async (
bridgeConf,
providerOptions,
txOptions,
allowExperimentalNetworks,
});
spinner.info(`Using chain ${name} [chainId: ${chain.id}]`);
return chain;
Expand Down
1 change: 1 addition & 0 deletions src/cli/utils/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const chainConfSchema = () =>
const chainsConfSchema = () =>
object({
default: string(),
allowExperimentalNetworks: boolean().default(false),
chains: object()
.test(async (chainsOjb) => {
await Promise.all(
Expand Down
2 changes: 1 addition & 1 deletion src/common/market/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ const getMatchableVolume = async (

export const estimateMatchOrders = async ({
contracts = throwIfMissing(),
voucherHubAddress = throwIfMissing(),
voucherHubAddress,
apporder,
datasetorder = NULL_DATASETORDER,
workerpoolorder,
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils/IExecContractsClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export default class IExecContractsClient {
*/
signer?: Signer;
/**
* id of the chain to use (used to resolve IExec contract address)
* id of the chain
*/
chainId: number | string;
/**
* override the IExec contract address to target a custom instance
* IExec contract address
*/
hubAddress?: string;
hubAddress: string;
/**
* if false set the gasPrice to 0 (default true)
*/
Expand Down
27 changes: 4 additions & 23 deletions src/common/utils/IExecContractsClient.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Debug from 'debug';
import { Contract } from 'ethers';
import { version as pocoVersion } from '../generated/@iexec/poco/package.js';
import { networks as iexecProxyNetworks } from '../generated/@iexec/poco/ERC1538Proxy.js';
import iexecTokenDesc from '../generated/@iexec/poco/IexecInterfaceToken.js';
import iexecNativeDesc from '../generated/@iexec/poco/IexecInterfaceNative.js';
import appRegistryDesc from '../generated/@iexec/poco/AppRegistry.js';
Expand All @@ -20,17 +19,6 @@ const gasPriceByNetwork = {
134: 0n,
};

const getHubAddress = (chainId) => {
if (
iexecProxyNetworks &&
iexecProxyNetworks[chainId] &&
iexecProxyNetworks[chainId].address
) {
return iexecProxyNetworks[chainId].address;
}
throw Error(`Missing iExec contract default address for chain ${chainId}`);
};

const getIsNative = (chainId) => nativeNetworks.includes(chainId);

const getGasPriceOverride = (chainId) => gasPriceByNetwork[chainId];
Expand Down Expand Up @@ -76,19 +64,12 @@ const getContractsDescMap = (isNative) => ({
},
});

const createClient = ({
ethSigner,
ethProvider,
chainId,
globalHubAddress,
isNative,
}) => {
const createClient = ({ ethSigner, ethProvider, hubAddress, isNative }) => {
const cachedAddresses = {};
if (!hubAddress) throw Error('Missing iExec contract address');

const contractsDescMap = getContractsDescMap(isNative);

const hubAddress = globalHubAddress || getHubAddress(chainId);

const getContract = (objName, address) => {
try {
const { contractDesc } = contractsDescMap[objName];
Expand Down Expand Up @@ -184,6 +165,7 @@ class IExecContractsClient {
} = {}) {
const stringChainId = `${chainId}`;
if (!provider) throw Error('missing provider key');
if (!hubAddress) throw Error('missing hubAddress key');
if (!stringChainId) throw Error('missing chainId key');
if (!Number.isInteger(confirms) || confirms <= 0)
throw Error('invalid confirms');
Expand All @@ -206,8 +188,7 @@ class IExecContractsClient {
const client = createClient({
ethSigner: signer,
ethProvider: provider,
chainId: stringChainId,
globalHubAddress: hubAddress,
hubAddress,
isNative: native,
});

Expand Down
Loading