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
12 changes: 10 additions & 2 deletions src/common/ens/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import { checkSigner } from '../utils/utils.js';
import { NULL_ADDRESS, APP, DATASET, WORKERPOOL } from '../utils/constant.js';
import { getEnsRegistryAddress } from './registry.js';
import { getOwner, lookupAddress } from './resolution.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:ens:registration');

Expand All @@ -34,6 +38,7 @@ export const getDefaultDomain = async (
address,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
const vAddress = await addressSchema({
ethProvider: contracts.provider,
})
Expand Down Expand Up @@ -66,6 +71,7 @@ export const registerFifsEns = async (
domain = FIFS_DOMAINS.default,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
checkSigner(contracts);
const vDomain = await ensDomainSchema().validate(domain);
const vLabel = await ensLabelSchema().validate(label);
Expand Down Expand Up @@ -129,12 +135,13 @@ export const obsConfigureResolution = (
address,
) =>
new Observable((observer) => {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
checkSigner(contracts);

const safeObserver = new SafeObserver(observer);
let abort = false;

const configure = async () => {
try {
checkSigner(contracts);
const vAddress =
address !== undefined
? await addressSchema({
Expand Down Expand Up @@ -367,6 +374,7 @@ export const configureResolution = async (
address,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
checkSigner(contracts);
const vAddress =
address !== undefined
Expand Down
7 changes: 7 additions & 0 deletions src/common/ens/resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
} from '../utils/validator.js';
import { wrapCall } from '../utils/errorWrappers.js';
import { getEnsRegistryAddress, checkEns } from './registry.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:ens:resolution');

Expand All @@ -16,6 +20,7 @@ export const getOwner = async (
name = throwIfMissing(),
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
const vName = await ensDomainSchema().validate(name);
const nameHash = namehash(vName);
const ensAddress = await getEnsRegistryAddress(contracts);
Expand All @@ -36,6 +41,7 @@ export const resolveName = async (
name = throwIfMissing(),
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
const vName = await ensDomainSchema().validate(name);
await checkEns(contracts);
return await wrapCall(contracts.provider.resolveName(vName));
Expand All @@ -47,6 +53,7 @@ export const resolveName = async (

export const lookupAddress = async (contracts = throwIfMissing(), address) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
const vAddress = await addressSchema({
ethProvider: contracts.provider,
})
Expand Down
6 changes: 6 additions & 0 deletions src/common/ens/text-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { getAddress } from '../wallet/address.js';
import { wrapSend, wrapWait, wrapCall } from '../utils/errorWrappers.js';
import { NULL_ADDRESS } from '../utils/constant.js';
import { getOwner } from './resolution.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:ens:text-record');

Expand All @@ -20,6 +24,7 @@ export const readTextRecord = async (
key,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
const vName = await ensDomainSchema().validate(name);
const vKey = await textRecordKeySchema().validate(key);
const node = namehash(vName);
Expand Down Expand Up @@ -52,6 +57,7 @@ export const setTextRecord = async (
value = '',
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
const vName = await ensDomainSchema().validate(name);
const vKey = await textRecordKeySchema().validate(key);
const vValue = await textRecordValueSchema().validate(value);
Expand Down
8 changes: 8 additions & 0 deletions src/common/execution/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { jsonApi, getAuthorization } from '../utils/api-utils.js';
import { checkSigner } from '../utils/utils.js';
import { getAddress } from '../wallet/address.js';
import { CompassCallError, WorkerpoolCallError } from '../utils/errors.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

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

Expand All @@ -32,6 +36,10 @@ export const getWorkerpoolApiUrl = async (

// Compass base workerpool API URL resolution
if (compassUrl) {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.COMPASS,
);
const json = await jsonApi.get({
api: compassUrl,
endpoint: `/${contracts.chainId}/workerpools/${vAddress}`,
Expand Down
8 changes: 8 additions & 0 deletions src/common/execution/workerpool.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {
import { lookupAddress } from '../ens/resolution.js';
import { setTextRecord } from '../ens/text-record.js';
import { WORKERPOOL_URL_TEXT_RECORD_KEY } from '../utils/constant.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:execution:workerpool');

Expand All @@ -16,6 +20,10 @@ export const setWorkerpoolApiUrl = async (
url,
) => {
try {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.WORKERPOOL_API_URL_REGISTRATION,
);
const vAddress = await addressSchema({
ethProvider: contracts.provider,
})
Expand Down
13 changes: 13 additions & 0 deletions src/common/market/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ import {
import { getVoucherHubContract } from '../utils/voucher-utils.js';
import { checkAllowance } from '../account/allowance.js';
import { fetchVoucherContract } from '../voucher/voucher.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:market:order');

Expand Down Expand Up @@ -818,6 +822,9 @@ export const estimateMatchOrders = async ({
.label('voucherAddress')
.validate(voucherAddress),
]);
if (!vUseVoucher) {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
}
const matchableVolume = await getMatchableVolume(
contracts,
vAppOrder,
Expand Down Expand Up @@ -938,6 +945,12 @@ export const matchOrders = async ({
.label('voucherAddress')
.validate(voucherAddress),
]);
if (vUseVoucher) {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.VOUCHER,
);
}

// check resulting tag
await tagSchema()
Expand Down
39 changes: 39 additions & 0 deletions src/common/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import { EnsPlugin, Network } from 'ethers';
import { address as voucherHubBellecourAddress } from '../generated/@iexec/voucher-contracts/deployments/bellecour/VoucherHubERC1967Proxy.js';
import { TEE_FRAMEWORKS } from './constant.js';

export const CHAIN_SPECIFIC_FEATURES = {
ENS: 'ENS',
WORKERPOOL_API_URL_REGISTRATION: 'Workerpool API Registration',
VOUCHER: 'iExec Voucher',
COMPASS: 'iExec Compass',
XRLC_BRIDGE: 'iExec xRLC Bridge',
};

const networkConfigs = [
{
id: 134,
Expand All @@ -28,6 +36,7 @@ const networkConfigs = [
},
shouldRegisterNetwork: true,
isExperimental: false,
notImplemented: [CHAIN_SPECIFIC_FEATURES.COMPASS],
},
{
id: 1,
Expand All @@ -50,6 +59,10 @@ const networkConfigs = [
},
shouldRegisterNetwork: false,
isExperimental: false,
notImplemented: [
CHAIN_SPECIFIC_FEATURES.COMPASS,
CHAIN_SPECIFIC_FEATURES.VOUCHER,
],
},
{
id: 421614,
Expand All @@ -72,6 +85,12 @@ const networkConfigs = [
bridge: {}, // no bridge
shouldRegisterNetwork: false,
isExperimental: false,
notImplemented: [
CHAIN_SPECIFIC_FEATURES.ENS,
CHAIN_SPECIFIC_FEATURES.WORKERPOOL_API_URL_REGISTRATION,
CHAIN_SPECIFIC_FEATURES.VOUCHER,
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
],
},
{
id: 42161,
Expand All @@ -93,6 +112,12 @@ const networkConfigs = [
voucherSubgraph: undefined, // no voucher
bridge: {}, // no bridge
shouldRegisterNetwork: false,
notImplemented: [
CHAIN_SPECIFIC_FEATURES.ENS,
CHAIN_SPECIFIC_FEATURES.WORKERPOOL_API_URL_REGISTRATION,
CHAIN_SPECIFIC_FEATURES.VOUCHER,
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
],
},
];

Expand Down Expand Up @@ -147,6 +172,20 @@ export const getChainDefaults = (
};
};

export const checkImplementedOnChain = (chainId, featureName) => {
const networkConfig = networkConfigs.find(
(network) => `${network.id}` === `${chainId}`,
);
if (
networkConfig?.notImplemented &&
networkConfig.notImplemented.includes(featureName)
) {
throw new Error(
`${featureName} is not available on network ${networkConfig.name}`,
);
}
};

// Register unknown networks and their ENS settings for the ethers library
networkConfigs.forEach((networkConfig) => {
if (
Expand Down
7 changes: 7 additions & 0 deletions src/common/voucher/voucher.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {
getVoucherContract,
getVoucherSubgraphClient,
} from '../utils/voucher-utils.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

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

Expand Down Expand Up @@ -78,6 +82,7 @@ export const showUserVoucher = async (
owner = throwIfMissing(),
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
const vOwner = await addressSchema({
ethProvider: contracts.provider,
})
Expand Down Expand Up @@ -139,6 +144,7 @@ export const authorizeRequester = async (
requester,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
checkSigner(contracts);
const userAddress = await getAddress(contracts);
const vRequester = await addressSchema({
Expand Down Expand Up @@ -180,6 +186,7 @@ export const revokeRequesterAuthorization = async (
requester,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
checkSigner(contracts);
const userAddress = await getAddress(contracts);
const vRequester = await addressSchema({
Expand Down
5 changes: 5 additions & 0 deletions src/common/voucher/voucherHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { addressSchema, throwIfMissing } from '../utils/validator.js';
import { wrapCall } from '../utils/errorWrappers.js';
import { NULL_ADDRESS } from '../utils/constant.js';
import { getVoucherHubContract } from '../utils/voucher-utils.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:voucher:voucherHub');

Expand All @@ -13,6 +17,7 @@ export const fetchVoucherAddress = async (
owner,
) => {
try {
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
const vOwner = await addressSchema({ ethProvider: contracts.provider })
.required()
.label('owner')
Expand Down
20 changes: 20 additions & 0 deletions src/common/wallet/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import { abi as HomeBridgeErcToNativeAbi } from './abi/HomeBridgeErcToNative.js'
import { getAddress } from './address.js';
import { getRlcBalance } from './balance.js';
import { sendRLC } from './send.js';
import {
CHAIN_SPECIFIC_FEATURES,
checkImplementedOnChain,
} from '../utils/config.js';

const debug = Debug('iexec:wallet:bridge');

Expand Down Expand Up @@ -69,6 +73,10 @@ export const obsBridgeToSidechain = (
{ sidechainBridgeAddress, bridgedContracts } = {},
) =>
new Observable((observer) => {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
);
const safeObserver = new SafeObserver(observer);
let abort;
let stopWatchPromise;
Expand Down Expand Up @@ -289,6 +297,10 @@ export const bridgeToSidechain = async (
nRlcAmount = throwIfMissing(),
{ sidechainBridgeAddress, bridgedContracts } = {},
) => {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
);
checkSigner(contracts);
let sendTxHash;
let receiveTxHash;
Expand Down Expand Up @@ -326,6 +338,10 @@ export const obsBridgeToMainchain = (
{ mainchainBridgeAddress, bridgedContracts } = {},
) =>
new Observable((observer) => {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
);
const safeObserver = new SafeObserver(observer);
let abort;
let stopWatchPromise;
Expand Down Expand Up @@ -517,6 +533,10 @@ export const bridgeToMainchain = async (
nRlcAmount = throwIfMissing(),
{ mainchainBridgeAddress, bridgedContracts } = {},
) => {
checkImplementedOnChain(
contracts.chainId,
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
);
checkSigner(contracts);
let sendTxHash;
let receiveTxHash;
Expand Down
Loading
Loading