Skip to content

Commit

Permalink
feat!: update [email protected] (#1061)
Browse files Browse the repository at this point in the history
* feat: update [email protected]

* show only relevant contracts

* fix

* up

* fix

* fix and improve

* up

* allow custom url, ids and other overrides for any env

* Apply automatic changes

* fix and add deployment addrs

* Apply automatic changes

* fix blockscout url

* some improvements

* up

* up

* improvements

---------

Co-authored-by: shamsartem <[email protected]>
  • Loading branch information
shamsartem and shamsartem authored Oct 16, 2024
1 parent e90c087 commit d760683
Show file tree
Hide file tree
Showing 48 changed files with 1,175 additions and 1,235 deletions.
880 changes: 429 additions & 451 deletions cli/docs/commands/README.md

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions cli/docs/configs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ Defines user project preferences

## Properties

| Property | Type | Required | Description |
|--------------|---------|----------|----------------------------------------------------------------------------------------------------------|
| `version` | integer | **Yes** | |
| `fluenceEnv` | string | No | Fluence environment to connect to Possible values are: `testnet`, `mainnet`, `stage`, `local`, `custom`. |
| Property | Type | Required | Description |
|-----------------|-----------------------|----------|------------------------------------------------------------------------------------------------|
| `version` | integer | **Yes** | |
| `blockScoutUrl` | string | No | BlockScout URL to use |
| `chainId` | number | No | Chain ID to use |
| `deployment` | [object](#deployment) | No | Deployed contract address overrides |
| `fluenceEnv` | string | No | Fluence environment to connect to Possible values are: `testnet`, `mainnet`, `stage`, `local`. |
| `relays` | string[] | No | List of custom relay multiaddresses to use when connecting to Fluence network |
| `rpcUrl` | string | No | RPC URL to use |
| `subgraphUrl` | string | No | Subgraph URL to use |

## deployment

Deployed contract address overrides

### Properties

| Property | Type | Required | Description |
|--------------|--------|----------|-------------|
| `diamond` | string | No | |
| `multicall3` | string | No | |
| `usdc` | string | No | |

2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@fluencelabs/air-beautify-wasm": "0.3.9",
"@fluencelabs/aqua-api": "0.14.10",
"@fluencelabs/aqua-to-js": "0.3.13",
"@fluencelabs/deal-ts-clients": "0.20.0",
"@fluencelabs/deal-ts-clients": "0.22.0",
"@fluencelabs/fluence-network-environment": "1.2.3",
"@fluencelabs/js-client": "0.9.0",
"@fluencelabs/npm-aqua-compiler": "0.0.3",
Expand Down
30 changes: 11 additions & 19 deletions cli/src/commands/chain/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
*/

import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { jsonStringify, LOCAL_NET_DEFAULT_ACCOUNTS } from "../../common.js";
import {
BLOCK_SCOUT_URLS,
jsonStringify,
LOCAL_NET_DEFAULT_ACCOUNTS,
} from "../../common.js";
import { CHAIN_URLS } from "../../common.js";
import { getChainId } from "../../lib/chain/chainId.js";
getBlockScoutUrl,
getChainId,
getRpcUrl,
getSubgraphUrl,
} from "../../lib/chain/chainConfig.js";
import { commandObj } from "../../lib/commandObj.js";
import { CHAIN_FLAGS } from "../../lib/const.js";
import { resolveDeployment } from "../../lib/dealClient.js";
import { ensureChainEnv } from "../../lib/ensureChainNetwork.js";
import { initCli } from "../../lib/lifeCycle.js";

Expand All @@ -40,25 +41,16 @@ export default class Info extends BaseCommand<typeof Info> {
await initCli(this, await this.parse(Info));
const chainEnv = await ensureChainEnv();

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { default: contracts }: { default: unknown } = await import(
`@fluencelabs/deal-ts-clients/dist/deployments/${chainEnv === "testnet" ? "dar" : chainEnv}.json`,
{
assert: { type: "json" },
}
);

commandObj.log(
jsonStringify({
...(chainEnv === "local"
? { defaultAccountsForLocalEnv: LOCAL_NET_DEFAULT_ACCOUNTS }
: {}),
contracts,
contracts: await resolveDeployment(),
subgraphUrl: await getSubgraphUrl(),
chainId: await getChainId(),
chainRPC: CHAIN_URLS[chainEnv],
...(chainEnv === "local"
? {}
: { blockScoutUrl: BLOCK_SCOUT_URLS[chainEnv] }),
chainRPC: await getRpcUrl(),
...(await getBlockScoutUrl()),
}),
);
}
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/deal/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
DEPLOYMENT_NAMES_ARG,
} from "../../lib/const.js";
import { getDeals } from "../../lib/deal.js";
import { getDealClient, sign } from "../../lib/dealClient.js";
import { getContracts, sign } from "../../lib/dealClient.js";
import { initCli } from "../../lib/lifeCycle.js";

export default class Stop extends BaseCommand<typeof Stop> {
Expand All @@ -43,10 +43,10 @@ export default class Stop extends BaseCommand<typeof Stop> {
async run(): Promise<void> {
const flagsAndArgs = await initCli(this, await this.parse(Stop), true);
const deals = await getDeals(flagsAndArgs);
const { dealClient } = await getDealClient();
const { contracts } = await getContracts();

for (const { dealId, dealName } of deals) {
const deal = dealClient.getDeal(dealId);
const deal = contracts.getDeal(dealId);

await sign({
title: `Stop the deal ${dealName} (${dealId})`,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/deal/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
PT_SYMBOL,
} from "../../lib/const.js";
import { getDeals } from "../../lib/deal.js";
import { getDealClient, sign } from "../../lib/dealClient.js";
import { getContracts, sign } from "../../lib/dealClient.js";
import { initCli } from "../../lib/lifeCycle.js";
import { input } from "../../lib/prompt.js";

Expand All @@ -49,7 +49,7 @@ export default class Withdraw extends BaseCommand<typeof Withdraw> {

async run(): Promise<void> {
const flagsAndArgs = await initCli(this, await this.parse(Withdraw));
const { dealClient } = await getDealClient();
const { contracts } = await getContracts();
const deals = await getDeals(flagsAndArgs);

const amount =
Expand All @@ -65,7 +65,7 @@ export default class Withdraw extends BaseCommand<typeof Withdraw> {
);

for (const { dealId, dealName } of deals) {
const deal = dealClient.getDeal(dealId);
const deal = contracts.getDeal(dealId);

await sign({
title: `Withdraw ${await ptFormatWithSymbol(parsedAmount)} tokens from the deal ${dealName}`,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/deal/workers-remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
WORKERS_CONFIG_FULL_FILE_NAME,
} from "../../lib/const.js";
import { getDeal } from "../../lib/deal.js";
import { sign, getDealClient } from "../../lib/dealClient.js";
import { sign, getContracts } from "../../lib/dealClient.js";
import { commaSepStrToArr } from "../../lib/helpers/utils.js";
import { initCli } from "../../lib/lifeCycle.js";
import { input } from "../../lib/prompt.js";
Expand Down Expand Up @@ -57,9 +57,9 @@ export default class WorkersRemove extends BaseCommand<typeof WorkersRemove> {
await this.parse(WorkersRemove),
);

const { dealClient } = await getDealClient();
const { contracts } = await getContracts();
const { dealId } = await getDeal({ flags });
const dealContract = dealClient.getDeal(dealId);
const dealContract = contracts.getDeal(dealId);

const workerIds = commaSepStrToArr(
args["WORKER-IDS"] ??
Expand Down
8 changes: 0 additions & 8 deletions cli/src/commands/default/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { ENV_ARG } from "../../lib/const.js";
import { ensureAquaFileWithWorkerInfo } from "../../lib/deployWorkers.js";
import { initCli } from "../../lib/lifeCycle.js";
import { updateRelaysJSON } from "../../lib/multiaddres.js";
import { ensureCustomAddrsAndPeerIds } from "../../lib/multiaddresWithoutLocal.js";
import { ensureValidFluenceEnv } from "../../lib/resolveFluenceEnv.js";

export default class Env extends BaseCommand<typeof Env> {
Expand All @@ -48,13 +47,6 @@ export default class Env extends BaseCommand<typeof Env> {
setEnvConfig(newEnvConfig);
const fluenceEnv = await ensureValidFluenceEnv(args.ENV);

if (
fluenceEnv === "custom" &&
fluenceConfig?.customFluenceEnv === undefined
) {
await ensureCustomAddrsAndPeerIds();
}

newEnvConfig.fluenceEnv = fluenceEnv;
await newEnvConfig.$commit();

Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/default/peers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { setChainFlags } from "../../lib/chainFlags.js";
import { commandObj } from "../../lib/commandObj.js";
import { ENV_ARG, ENV_ARG_NAME, ENV_FLAG_NAME } from "../../lib/const.js";
import { initCli } from "../../lib/lifeCycle.js";
import { resolveRelays } from "../../lib/multiaddres.js";
import { resolveDefaultRelays } from "../../lib/multiaddres.js";

export default class Peers extends BaseCommand<typeof Peers> {
static override description = "Print default Fluence network peer addresses";
Expand All @@ -34,7 +34,7 @@ export default class Peers extends BaseCommand<typeof Peers> {
async run(): Promise<void> {
const { args } = await initCli(this, await this.parse(Peers));
setChainFlags({ [ENV_FLAG_NAME]: args[ENV_ARG_NAME] });
const relays = await resolveRelays();
const relays = await resolveDefaultRelays();
commandObj.log(relays.join("\n"));
}
}
10 changes: 4 additions & 6 deletions cli/src/commands/provider/deal-exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
DEAL_IDS_FLAG_NAME,
} from "../../lib/const.js";
import {
getDealClient,
getContracts,
getSignerAddress,
populateTx,
signBatch,
Expand All @@ -50,13 +50,11 @@ export default class DealExit extends BaseCommand<typeof DealExit> {

async run(): Promise<void> {
const { flags } = await initCli(this, await this.parse(DealExit));
const { dealClient } = await getDealClient();
const { contracts } = await getContracts();
const signerAddress = await getSignerAddress();

const dealIds = flags.all
? (await getProviderDeals()).map(({ id }) => {
return id;
})
? await getProviderDeals()
: commaSepStrToArr(
flags[DEAL_IDS_FLAG_NAME] ??
(await input({
Expand All @@ -67,7 +65,7 @@ export default class DealExit extends BaseCommand<typeof DealExit> {
const workers = (
await Promise.all(
dealIds.map(async (id) => {
const deal = dealClient.getDeal(id);
const deal = contracts.getDeal(id);
return (await deal.getWorkers()).map((worker) => {
return { deal, worker };
});
Expand Down
11 changes: 1 addition & 10 deletions cli/src/commands/provider/deal-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ export default class DealsList extends BaseCommand<typeof DealsList> {

async run(): Promise<void> {
await initCli(this, await this.parse(DealsList));

const deals = await getProviderDeals();

commandObj.log(
deals
.map(({ id }) => {
return id;
})
.join("\n"),
);
commandObj.log((await getProviderDeals()).join("\n"));
}
}
6 changes: 3 additions & 3 deletions cli/src/commands/provider/deal-rewards-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { BaseCommand, baseFlags } from "../../baseCommand.js";
import { ptFormatWithSymbol } from "../../lib/chain/currencies.js";
import { commandObj } from "../../lib/commandObj.js";
import { CHAIN_FLAGS } from "../../lib/const.js";
import { getReadonlyDealClient } from "../../lib/dealClient.js";
import { getReadonlyContracts } from "../../lib/dealClient.js";
import { initCli } from "../../lib/lifeCycle.js";
import { input } from "../../lib/prompt.js";

Expand Down Expand Up @@ -55,8 +55,8 @@ export default class DealRewardsInfo extends BaseCommand<
args["ON-CHAIN-WORKER-ID"] ??
(await input({ message: "Enter on-chain worker id" }));

const { readonlyDealClient } = await getReadonlyDealClient();
const deal = readonlyDealClient.getDeal(dealAddress);
const { readonlyContracts } = await getReadonlyContracts();
const deal = readonlyContracts.getDeal(dealAddress);
const rewardAmount = await deal.getRewardAmount(onChainWorkerId);

commandObj.log(
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/provider/deal-rewards-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
DEAL_IDS_FLAG_NAME,
PT_SYMBOL,
} from "../../lib/const.js";
import { getDealClient, getEventValue, sign } from "../../lib/dealClient.js";
import { getContracts, getEventValue, sign } from "../../lib/dealClient.js";
import { commaSepStrToArr } from "../../lib/helpers/utils.js";
import { initCli } from "../../lib/lifeCycle.js";
import { input } from "../../lib/prompt.js";
Expand Down Expand Up @@ -58,10 +58,10 @@ export default class DealRewardsWithdraw extends BaseCommand<
return commandObj.error("Got empty list of deal ids. Aborting");
}

const { dealClient } = await getDealClient();
const { contracts } = await getContracts();

for (const dealId of dealIds) {
const deal = dealClient.getDeal(dealId);
const deal = contracts.getDeal(dealId);
const workers = await deal.getWorkers();

let providerRewards = 0n;
Expand Down
16 changes: 11 additions & 5 deletions cli/src/lib/ajvInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ import addFormats from "ajv-formats";

import { jsonStringify } from "../common.js";

export const ajv = new Ajv.default({
allowUnionTypes: true,
code: { esm: true },
});
export function getAjv() {
const ajv = new Ajv.default({
allowUnionTypes: true,
code: { esm: true },
});

addFormats.default(ajv);
addFormats.default(ajv);
ajv.addFormat("hex", /^0x[0-9a-fA-F]*$/);
return ajv;
}

export const ajv = getAjv();

type AjvErrors =
| Ajv.ErrorObject<string, Record<string, unknown>>[]
Expand Down
Loading

0 comments on commit d760683

Please sign in to comment.