diff --git a/cli/docs/commands/README.md b/cli/docs/commands/README.md index d683b1acf..021410dc7 100644 --- a/cli/docs/commands/README.md +++ b/cli/docs/commands/README.md @@ -250,16 +250,14 @@ Build all application services, described in fluence.yaml and generate aqua inte ``` USAGE $ fluence build [--no-input] [--marine-build-args <--flag arg>] [--import ...] [--env ] + mainnet | stage | local>] FLAGS - --env= Fluence Environment to use when running the command - --import=... Path to a directory to import aqua files from. May be used several - times - --marine-build-args=<--flag arg> Space separated `cargo build` flags and args to pass to marine - build. Overrides 'marineBuildArgs' property in fluence.yaml. - Default: --release - --no-input Don't interactively ask for any input from the user + --env= Fluence Environment to use when running the command + --import=... Path to a directory to import aqua files from. May be used several times + --marine-build-args=<--flag arg> Space separated `cargo build` flags and args to pass to marine build. + Overrides 'marineBuildArgs' property in fluence.yaml. Default: --release + --no-input Don't interactively ask for any input from the user DESCRIPTION Build all application services, described in fluence.yaml and generate aqua interfaces for them @@ -276,16 +274,15 @@ Show contract addresses for the fluence environment and accounts for the local e ``` USAGE - $ fluence chain info [--no-input] [--env ] [--priv-key - ] + $ fluence chain info [--no-input] [--env ] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Show contract addresses for the fluence environment and accounts for the local environment @@ -299,20 +296,20 @@ Change app id in the deal ``` USAGE - $ fluence deal change-app [DEAL-ADDRESS] [NEW-APP-CID] [--no-input] [--env ] [--priv-key ] + $ fluence deal change-app [DEAL-ADDRESS] [NEW-APP-CID] [--no-input] [--env ] + [--priv-key ] ARGUMENTS DEAL-ADDRESS Deal address NEW-APP-CID New app CID for the deal FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Change app id in the deal @@ -329,27 +326,27 @@ USAGE $ fluence deal create --app-cid --collateral-per-worker --min-workers --target-workers --max-workers-per-provider --price-per-cu-per-epoch --cu-count-per-worker [--no-input] [--initial-balance ] [--effectors ] [--whitelist | --blacklist ] - [--protocol-version ] [--env ] [--priv-key ] - -FLAGS - --app-cid= (required) CID of the application that will be deployed - --blacklist= Comma-separated list of blacklisted providers - --collateral-per-worker= (required) Collateral per worker - --cu-count-per-worker= (required) Compute unit count per worker - --effectors= Comma-separated list of effector to be used in the deal - --env= Fluence Environment to use when running the command - --initial-balance= Initial balance - --max-workers-per-provider= (required) Max workers per provider - --min-workers= (required) Required workers to activate the deal - --no-input Don't interactively ask for any input from the user - --price-per-cu-per-epoch= (required) Price per CU per epoch - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode - --protocol-version= Protocol version - --target-workers= (required) Max workers in the deal - --whitelist= Comma-separated list of whitelisted providers + [--protocol-version ] [--env ] [--priv-key ] + +FLAGS + --app-cid= (required) CID of the application that will be deployed + --blacklist= Comma-separated list of blacklisted providers + --collateral-per-worker= (required) Collateral per worker + --cu-count-per-worker= (required) Compute unit count per worker + --effectors= Comma-separated list of effector to be used in the deal + --env= Fluence Environment to use when running the command + --initial-balance= Initial balance + --max-workers-per-provider= (required) Max workers per provider + --min-workers= (required) Required workers to activate the deal + --no-input Don't interactively ask for any input from the user + --price-per-cu-per-epoch= (required) Price per CU per epoch + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode + --protocol-version= Protocol version + --target-workers= (required) Max workers in the deal + --whitelist= Comma-separated list of whitelisted providers DESCRIPTION Create your deal with the specified parameters @@ -363,21 +360,21 @@ Deposit do the deal ``` USAGE - $ fluence deal deposit [AMOUNT] [DEPLOYMENT-NAMES] [--no-input] [--env ] [--priv-key ] [--deal-ids ] + $ fluence deal deposit [AMOUNT] [DEPLOYMENT-NAMES] [--no-input] [--env ] + [--priv-key ] [--deal-ids ] ARGUMENTS AMOUNT Amount of USDC tokens to deposit DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Deposit do the deal @@ -391,20 +388,20 @@ Get info about the deal ``` USAGE - $ fluence deal info [DEPLOYMENT-NAMES] [--no-input] [--env ] - [--priv-key ] [--deal-ids ] + $ fluence deal info [DEPLOYMENT-NAMES] [--no-input] [--env ] [--priv-key + ] [--deal-ids ] ARGUMENTS DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Get info about the deal @@ -419,30 +416,27 @@ Get logs from deployed workers for deals listed in workers.yaml ``` USAGE $ fluence deal logs [DEPLOYMENT-NAMES] [--no-input] [-k ] [--relay ] [--ttl - ] [--dial-timeout ] [--particle-id] [--env ] + ] [--dial-timeout ] [--particle-id] [--env ] [--off-aqua-logs] [--tracing] [--deal-ids ] [--spell ] ARGUMENTS DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - -k, --sk= Name of the secret key for js-client inside CLI to use. If not - specified, will use the default key for the project. If there - is no fluence project or there is no default key, will use - user's default key - --deal-ids= Comma-separated deal ids - --dial-timeout= [default: 15000] Timeout for Fluence js-client to connect to - relay peer - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --off-aqua-logs Turns off logs from Console.print in aqua and from IPFS - service - --particle-id Print particle ids when running Fluence js-client - --relay= Relay for Fluence js-client to connect to - --spell= [default: worker-spell] Spell name to get logs for - --tracing Compile aqua in tracing mode (for debugging purposes) - --ttl= [default: 15000] Particle Time To Live since 'now'. After - that, particle is expired and not processed. + -k, --sk= Name of the secret key for js-client inside CLI to use. If not + specified, will use the default key for the project. If there is no + fluence project or there is no default key, will use user's default key + --deal-ids= Comma-separated deal ids + --dial-timeout= [default: 15000] Timeout for Fluence js-client to connect to relay peer + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --off-aqua-logs Turns off logs from Console.print in aqua and from IPFS service + --particle-id Print particle ids when running Fluence js-client + --relay= Relay for Fluence js-client to connect to + --spell= [default: worker-spell] Spell name to get logs for + --tracing Compile aqua in tracing mode (for debugging purposes) + --ttl= [default: 15000] Particle Time To Live since 'now'. After that, + particle is expired and not processed. DESCRIPTION Get logs from deployed workers for deals listed in workers.yaml @@ -459,20 +453,20 @@ Stop the deal ``` USAGE - $ fluence deal stop [DEPLOYMENT-NAMES] [--no-input] [--env ] - [--priv-key ] [--deal-ids ] + $ fluence deal stop [DEPLOYMENT-NAMES] [--no-input] [--env ] [--priv-key + ] [--deal-ids ] ARGUMENTS DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Stop the deal @@ -486,21 +480,21 @@ Withdraw tokens from the deal ``` USAGE - $ fluence deal withdraw [AMOUNT] [DEPLOYMENT-NAMES] [--no-input] [--env ] [--priv-key ] [--deal-ids ] + $ fluence deal withdraw [AMOUNT] [DEPLOYMENT-NAMES] [--no-input] [--env ] + [--priv-key ] [--deal-ids ] ARGUMENTS AMOUNT Amount of USDC tokens to withdraw DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Withdraw tokens from the deal @@ -514,20 +508,20 @@ Add missing workers to the deal ``` USAGE - $ fluence deal workers-add [DEPLOYMENT-NAMES] [--no-input] [--env ] - [--priv-key ] [--deal-ids ] + $ fluence deal workers-add [DEPLOYMENT-NAMES] [--no-input] [--env ] [--priv-key + ] [--deal-ids ] ARGUMENTS DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Add missing workers to the deal @@ -544,21 +538,21 @@ Remove unit from the deal ``` USAGE - $ fluence deal workers-remove [WORKER-IDS] [--no-input] [--env ] - [--priv-key ] [--deal-id ] [--name ] + $ fluence deal workers-remove [WORKER-IDS] [--no-input] [--env ] [--priv-key + ] [--deal-id ] [--name ] ARGUMENTS WORKER-IDS Comma-separated compute unit ids. You can get them using 'fluence deal info' command FLAGS - --deal-id= Deal id. You can get it using 'fluence deal info' command - --env= Fluence Environment to use when running the command - --name= Name of the deployment from workers.yaml - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-id= Deal id. You can get it using 'fluence deal info' command + --env= Fluence Environment to use when running the command + --name= Name of the deployment from workers.yaml + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Remove unit from the deal @@ -621,19 +615,19 @@ Add FLT collateral to capacity commitment ``` USAGE - $ fluence delegator collateral-add [IDS] [--no-input] [--env ] [--priv-key - ] + $ fluence delegator collateral-add [IDS] [--no-input] [--env ] [--priv-key + ] ARGUMENTS IDS Comma separated capacity commitment IDs FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Add FLT collateral to capacity commitment @@ -650,20 +644,20 @@ Withdraw FLT collateral from capacity commitment ``` USAGE - $ fluence delegator collateral-withdraw [IDS] [--no-input] [--env ] [--priv-key - ] [--finish] + $ fluence delegator collateral-withdraw [IDS] [--no-input] [--env ] [--priv-key ] + [--finish] ARGUMENTS IDS Comma separated capacity commitment IDs FLAGS - --env= Fluence Environment to use when running the command - --finish Finish capacity commitment after collateral withdrawal - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --finish Finish capacity commitment after collateral withdrawal + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Withdraw FLT collateral from capacity commitment @@ -680,19 +674,19 @@ Withdraw FLT rewards from capacity commitment ``` USAGE - $ fluence delegator reward-withdraw [IDS] [--no-input] [--env ] [--priv-key - ] + $ fluence delegator reward-withdraw [IDS] [--no-input] [--env ] [--priv-key + ] ARGUMENTS IDS Comma separated capacity commitment IDs FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Withdraw FLT rewards from capacity commitment @@ -812,30 +806,28 @@ Deploy according to 'deployments' property in fluence.yaml ``` USAGE - $ fluence deploy [DEPLOYMENT-NAMES] [--no-input] [--env ] - [--priv-key ] [--import ...] [--no-build] [--marine-build-args <--flag arg>] [-u] [--peer-ids - ] + $ fluence deploy [DEPLOYMENT-NAMES] [--no-input] [--env ] [--priv-key + ] [--import ...] [--no-build] [--marine-build-args <--flag arg>] [-u] [--peer-ids ] ARGUMENTS DEPLOYMENT-NAMES Comma separated names of deployments. Can't be used together with --deal-ids flag FLAGS - -u, --update Update your previous deployment - --env= Fluence Environment to use when running the command - --import=... Path to a directory to import aqua files from. May be used - several times - --marine-build-args=<--flag arg> Space separated `cargo build` flags and args to pass to marine - build. Overrides 'marineBuildArgs' property in fluence.yaml. - Default: --release - --no-build Don't build the project before running the command - --no-input Don't interactively ask for any input from the user - --peer-ids= Comma separated list of peer ids to deploy to. Creates 1 - worker for each peer with 'cuCountPerWorker' number of compute - units - --priv-key= !WARNING! for debug purposes only. Passing private keys - through flags is unsecure. On local env 0xac0974bec39a17e36ba4 - a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used by - default when CLI is used in non-interactive mode + -u, --update Update your previous deployment + --env= Fluence Environment to use when running the command + --import=... Path to a directory to import aqua files from. May be used several + times + --marine-build-args=<--flag arg> Space separated `cargo build` flags and args to pass to marine build. + Overrides 'marineBuildArgs' property in fluence.yaml. Default: + --release + --no-build Don't build the project before running the command + --no-input Don't interactively ask for any input from the user + --peer-ids= Comma separated list of peer ids to deploy to. Creates 1 worker for + each peer with 'cuCountPerWorker' number of compute units + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags + is unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is + used by default when CLI is used in non-interactive mode DESCRIPTION Deploy according to 'deployments' property in fluence.yaml @@ -872,19 +864,17 @@ Initialize fluence project ``` USAGE - $ fluence init [PATH] [--no-input] [-t ] [--env ] - [--noxes ] + $ fluence init [PATH] [--no-input] [-t ] [--env ] [--noxes + ] ARGUMENTS PATH Project path FLAGS - -t, --template= Template to use for the project. One of: quickstart, minimal, - ts, js - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --noxes= Number of Compute Peers to generate when a new provider.yaml - is created + -t, --template= Template to use for the project. One of: quickstart, minimal, ts, js + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --noxes= Number of Compute Peers to generate when a new provider.yaml is created DESCRIPTION Initialize fluence project @@ -997,16 +987,15 @@ Init docker-compose.yaml according to provider.yaml ``` USAGE - $ fluence local init [--no-input] [--env ] [--priv-key - ] + $ fluence local init [--no-input] [--env ] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Init docker-compose.yaml according to provider.yaml @@ -1230,21 +1219,21 @@ Add FLT collateral to capacity commitment to activate it ``` USAGE - $ fluence provider cc-activate [--no-input] [--env ] [--priv-key - ] [--nox-names | --cc-ids ] [--offers ] + $ fluence provider cc-activate [--no-input] [--env ] [--priv-key ] + [--nox-names | --cc-ids ] [--offers ] FLAGS - --cc-ids= Comma separated capacity commitment IDs - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --cc-ids= Comma separated capacity commitment IDs + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Add FLT collateral to capacity commitment to activate it @@ -1261,20 +1250,20 @@ Create Capacity commitment ``` USAGE - $ fluence provider cc-create [--no-input] [--env ] [--priv-key - ] [--nox-names ] [--offers ] + $ fluence provider cc-create [--no-input] [--env ] [--priv-key ] + [--nox-names ] [--offers ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Create Capacity commitment @@ -1292,20 +1281,20 @@ Move resources from deals, withdraw FLT collateral from capacity commitments, re ``` USAGE $ fluence provider cc-finish [--no-input] [--nox-names | --cc-ids ] [--offers ] - [--env ] [--priv-key ] + [--env ] [--priv-key ] FLAGS - --cc-ids= Comma separated capacity commitment IDs - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --cc-ids= Comma separated capacity commitment IDs + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Move resources from deals, withdraw FLT collateral from capacity commitments, remove compute units from capacity @@ -1323,22 +1312,22 @@ Get info about capacity commitments ``` USAGE - $ fluence provider cc-info [--no-input] [--env ] [--priv-key - ] [--nox-names | --cc-ids ] [--offers ] [--json] + $ fluence provider cc-info [--no-input] [--env ] [--priv-key ] + [--nox-names | --cc-ids ] [--offers ] [--json] FLAGS - --cc-ids= Comma separated capacity commitment IDs - --env= Fluence Environment to use when running the command - --json Output JSON - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --cc-ids= Comma separated capacity commitment IDs + --env= Fluence Environment to use when running the command + --json Output JSON + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Get info about capacity commitments @@ -1355,21 +1344,21 @@ Remove Capacity commitment. You can remove it only BEFORE you activated it by de ``` USAGE - $ fluence provider cc-remove [--no-input] [--env ] [--priv-key - ] [--nox-names | --cc-ids ] [--offers ] + $ fluence provider cc-remove [--no-input] [--env ] [--priv-key ] + [--nox-names | --cc-ids ] [--offers ] FLAGS - --cc-ids= Comma separated capacity commitment IDs - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --cc-ids= Comma separated capacity commitment IDs + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Remove Capacity commitment. You can remove it only BEFORE you activated it by depositing collateral @@ -1387,20 +1376,20 @@ Withdraw FLT rewards from capacity commitments ``` USAGE $ fluence provider cc-rewards-withdraw [--no-input] [--nox-names | --cc-ids ] [--offers ] - [--env ] [--priv-key ] + [--env ] [--priv-key ] FLAGS - --cc-ids= Comma separated capacity commitment IDs - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --cc-ids= Comma separated capacity commitment IDs + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Withdraw FLT rewards from capacity commitments @@ -1417,19 +1406,18 @@ Exit from deal ``` USAGE - $ fluence provider deal-exit [--no-input] [--env ] [--priv-key - ] [--deal-ids ] [--all] + $ fluence provider deal-exit [--no-input] [--env ] [--priv-key ] + [--deal-ids ] [--all] FLAGS - --all To use all deal ids that indexer is aware of for your provider - address - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --all To use all deal ids that indexer is aware of for your provider address + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Exit from deal @@ -1446,16 +1434,15 @@ List all deals ``` USAGE - $ fluence provider deal-list [--no-input] [--env ] [--priv-key - ] + $ fluence provider deal-list [--no-input] [--env ] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION List all deals @@ -1473,19 +1460,19 @@ Deal rewards info ``` USAGE $ fluence provider deal-rewards-info [DEAL-ADDRESS] [ON-CHAIN-WORKER-ID] [--no-input] [--env ] [--priv-key ] + local>] [--priv-key ] ARGUMENTS DEAL-ADDRESS Deal address ON-CHAIN-WORKER-ID On-chain worker id FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Deal rewards info @@ -1502,17 +1489,17 @@ Withdraw USDC rewards from deals ``` USAGE - $ fluence provider deal-rewards-withdraw [--no-input] [--env ] [--priv-key - ] [--deal-ids ] + $ fluence provider deal-rewards-withdraw [--no-input] [--env ] [--priv-key ] + [--deal-ids ] FLAGS - --deal-ids= Comma-separated deal ids - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --deal-ids= Comma-separated deal ids + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Withdraw USDC rewards from deals @@ -1529,22 +1516,21 @@ Generate Config.toml files according to provider.yaml and secrets according to p ``` USAGE - $ fluence provider gen [--no-input] [--env ] [--priv-key - ] [--reset-nox-secrets] [--no-withdraw] + $ fluence provider gen [--no-input] [--env ] [--priv-key ] + [--reset-nox-secrets] [--no-withdraw] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --no-withdraw Is used only when --reset-nox-secrets flag is present. Will not - withdraw tokens from noxes (if you don't need it or it fails for - some reason) - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode - --reset-nox-secrets Withdraw remaining tokens from your noxes, backup nox secrets from - .fluence/provider-secrets.yaml and .fluence/secrets (if they - exist) to .fluence/backups and generate new ones + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --no-withdraw Is used only when --reset-nox-secrets flag is present. Will not withdraw + tokens from noxes (if you don't need it or it fails for some reason) + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode + --reset-nox-secrets Withdraw remaining tokens from your noxes, backup nox secrets from + .fluence/provider-secrets.yaml and .fluence/secrets (if they exist) to + .fluence/backups and generate new ones DESCRIPTION Generate Config.toml files according to provider.yaml and secrets according to provider-secrets.yaml @@ -1561,20 +1547,20 @@ Print nox signing wallets and peer ids ``` USAGE - $ fluence provider info [--no-input] [--env ] [--priv-key - ] [--nox-names ] [--json] [--address
] + $ fluence provider info [--no-input] [--env ] [--priv-key ] + [--nox-names ] [--json] [--address
] FLAGS - --address=
Provider address - --env= Fluence Environment to use when running the command - --json Output JSON - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --address=
Provider address + --env= Fluence Environment to use when running the command + --json Output JSON + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Print nox signing wallets and peer ids @@ -1591,19 +1577,18 @@ Init provider config. Creates a provider.yaml file ``` USAGE - $ fluence provider init [--no-input] [--noxes ] [--env ] - [--priv-key ] [--no-vm] + $ fluence provider init [--no-input] [--noxes ] [--env ] [--priv-key + ] [--no-vm] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --no-vm Generate provider.yaml without vm configuration - --noxes= Number of Compute Peers to generate when a new provider.yaml is - created - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --no-vm Generate provider.yaml without vm configuration + --noxes= Number of Compute Peers to generate when a new provider.yaml is created + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Init provider config. Creates a provider.yaml file @@ -1617,18 +1602,18 @@ Create offers. You have to be registered as a provider to do that ``` USAGE - $ fluence provider offer-create [--no-input] [--env ] [--priv-key - ] [--offers ] + $ fluence provider offer-create [--no-input] [--env ] [--priv-key ] + [--offers ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Create offers. You have to be registered as a provider to do that @@ -1646,19 +1631,19 @@ Get info about offers ``` USAGE $ fluence provider offer-info [--no-input] [--offers | --offer-ids ] [--env ] [--priv-key ] + mainnet | stage | local>] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --offer-ids= Comma-separated list of offer ids. Can't be used together with - --offers flag - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --offer-ids= Comma-separated list of offer ids. Can't be used together with --offers + flag + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Get info about offers @@ -1676,19 +1661,19 @@ Remove offers ``` USAGE $ fluence provider offer-remove [--no-input] [--offers | --offer-ids ] [--env ] [--priv-key ] + mainnet | stage | local>] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --offer-ids= Comma-separated list of offer ids. Can't be used together with - --offers flag - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --offer-ids= Comma-separated list of offer ids. Can't be used together with --offers + flag + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Remove offers @@ -1705,18 +1690,18 @@ Update offers ``` USAGE - $ fluence provider offer-update [--no-input] [--offers ] [--env ] [--priv-key ] + $ fluence provider offer-update [--no-input] [--offers ] [--env ] + [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Update offers @@ -1733,16 +1718,15 @@ Register as a provider ``` USAGE - $ fluence provider register [--no-input] [--env ] [--priv-key - ] + $ fluence provider register [--no-input] [--env ] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Register as a provider @@ -1759,21 +1743,21 @@ Distribute FLT tokens to noxes ``` USAGE - $ fluence provider tokens-distribute [--no-input] [--env ] [--priv-key - ] [--nox-names ] [--offers ] [--amount ] + $ fluence provider tokens-distribute [--no-input] [--env ] [--priv-key ] + [--nox-names ] [--offers ] [--amount ] FLAGS - --amount= Amount of FLT tokens to distribute to noxes - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --offers= Comma-separated list of offer names. To use all of your offers: - --offers all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --amount= Amount of FLT tokens to distribute to noxes + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --offers= Comma-separated list of offer names. To use all of your offers: --offers + all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Distribute FLT tokens to noxes @@ -1790,20 +1774,20 @@ Withdraw FLT tokens from noxes ``` USAGE - $ fluence provider tokens-withdraw [--no-input] [--env ] [--priv-key - ] [--nox-names ] [--amount ] + $ fluence provider tokens-withdraw [--no-input] [--env ] [--priv-key ] + [--nox-names ] [--amount ] FLAGS - --amount= Amount of FLT tokens to withdraw from noxes. Use --amount max to - withdraw maximum possible amount - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --nox-names= Comma-separated names of noxes from provider.yaml. To use all of - your noxes: --nox-names all - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --amount= Amount of FLT tokens to withdraw from noxes. Use --amount max to withdraw + maximum possible amount + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --nox-names= Comma-separated names of noxes from provider.yaml. To use all of your + noxes: --nox-names all + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Withdraw FLT tokens from noxes @@ -1820,16 +1804,15 @@ Update provider info ``` USAGE - $ fluence provider update [--no-input] [--env ] [--priv-key - ] + $ fluence provider update [--no-input] [--env ] [--priv-key ] FLAGS - --env= Fluence Environment to use when running the command - --no-input Don't interactively ask for any input from the user - --priv-key= !WARNING! for debug purposes only. Passing private keys through - flags is unsecure. On local env - 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 - is used by default when CLI is used in non-interactive mode + --env= Fluence Environment to use when running the command + --no-input Don't interactively ask for any input from the user + --priv-key= !WARNING! for debug purposes only. Passing private keys through flags is + unsecure. On local env + 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 is used + by default when CLI is used in non-interactive mode DESCRIPTION Update provider info @@ -1848,48 +1831,43 @@ Run the first aqua function CLI is able to find and compile among all aqua files USAGE $ fluence run [--no-input] [--data ] [--data-path ] [--quiet] [-f ] [--print-air | -b] [--off-aqua-logs] [-k ] [--relay ] [--ttl ] [--dial-timeout - ] [--particle-id] [--env ] [--import ...] [-i - ] [--const ...] [--log-level-compiler ] [--no-relay] [--no-xor] [--tracing] - [--no-empty-response] - -FLAGS - -b, --print-beautified-air Prints beautified AIR code instead of function execution - -f, --func= Function call. Example: funcName("stringArg") - -i, --input= Path to an aqua file or a directory that contains your aqua - files - -k, --sk= Name of the secret key for js-client inside CLI to use. If not - specified, will use the default key for the project. If there - is no fluence project or there is no default key, will use - user's default key - --const=... Constants to be passed to the compiler - --data= JSON in { [argumentName]: argumentValue } format. You can call - a function using these argument names like this: -f - 'myFunc(argumentName)'. Arguments in this flag override - arguments in the --data-path flag - --data-path= Path to a JSON file in { [argumentName]: argumentValue } - format. You can call a function using these argument names - like this: -f 'myFunc(argumentName)'. Arguments in this flag - can be overridden using --data flag - --dial-timeout= [default: 15000] Timeout for Fluence js-client to connect to - relay peer - --env= Fluence Environment to use when running the command - --import=... Path to a directory to import aqua files from. May be used - several times - --log-level-compiler= Set log level for the compiler. Must be one of: all, trace, - debug, info, warn, error, off - --no-empty-response Do not generate response call if there are no returned values - --no-input Don't interactively ask for any input from the user - --no-relay Do not generate a pass through the relay node - --no-xor Do not generate a wrapper that catches and displays errors - --off-aqua-logs Turns off logs from Console.print in aqua and from IPFS - service - --particle-id Print particle ids when running Fluence js-client - --print-air Prints generated AIR code instead of function execution - --quiet Print only execution result. Overrides all --log-level-* flags - --relay= Relay for Fluence js-client to connect to - --tracing Compile aqua in tracing mode (for debugging purposes) - --ttl= [default: 15000] Particle Time To Live since 'now'. After - that, particle is expired and not processed. + ] [--particle-id] [--env ] [--import ...] [-i ] + [--const ...] [--log-level-compiler ] [--no-relay] [--no-xor] [--tracing] [--no-empty-response] + +FLAGS + -b, --print-beautified-air Prints beautified AIR code instead of function execution + -f, --func= Function call. Example: funcName("stringArg") + -i, --input= Path to an aqua file or a directory that contains your aqua files + -k, --sk= Name of the secret key for js-client inside CLI to use. If not + specified, will use the default key for the project. If there is no + fluence project or there is no default key, will use user's default key + --const=... Constants to be passed to the compiler + --data= JSON in { [argumentName]: argumentValue } format. You can call a + function using these argument names like this: -f + 'myFunc(argumentName)'. Arguments in this flag override arguments in + the --data-path flag + --data-path= Path to a JSON file in { [argumentName]: argumentValue } format. You + can call a function using these argument names like this: -f + 'myFunc(argumentName)'. Arguments in this flag can be overridden using + --data flag + --dial-timeout= [default: 15000] Timeout for Fluence js-client to connect to relay peer + --env= Fluence Environment to use when running the command + --import=... Path to a directory to import aqua files from. May be used several + times + --log-level-compiler= Set log level for the compiler. Must be one of: all, trace, debug, + info, warn, error, off + --no-empty-response Do not generate response call if there are no returned values + --no-input Don't interactively ask for any input from the user + --no-relay Do not generate a pass through the relay node + --no-xor Do not generate a wrapper that catches and displays errors + --off-aqua-logs Turns off logs from Console.print in aqua and from IPFS service + --particle-id Print particle ids when running Fluence js-client + --print-air Prints generated AIR code instead of function execution + --quiet Print only execution result. Overrides all --log-level-* flags + --relay= Relay for Fluence js-client to connect to + --tracing Compile aqua in tracing mode (for debugging purposes) + --ttl= [default: 15000] Particle Time To Live since 'now'. After that, + particle is expired and not processed. DESCRIPTION Run the first aqua function CLI is able to find and compile among all aqua files specified in 'compileAqua' property diff --git a/cli/docs/configs/env.md b/cli/docs/configs/env.md index 29b70b5b1..2335d30e7 100644 --- a/cli/docs/configs/env.md +++ b/cli/docs/configs/env.md @@ -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 | | diff --git a/cli/package.json b/cli/package.json index 1b5fc1b99..0908de11f 100644 --- a/cli/package.json +++ b/cli/package.json @@ -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", diff --git a/cli/src/commands/chain/info.ts b/cli/src/commands/chain/info.ts index bd94e4f49..35768dbb0 100644 --- a/cli/src/commands/chain/info.ts +++ b/cli/src/commands/chain/info.ts @@ -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"; @@ -40,25 +41,16 @@ export default class Info extends BaseCommand { 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()), }), ); } diff --git a/cli/src/commands/deal/stop.ts b/cli/src/commands/deal/stop.ts index ee9bf3c41..70bf39a5e 100644 --- a/cli/src/commands/deal/stop.ts +++ b/cli/src/commands/deal/stop.ts @@ -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 { @@ -43,10 +43,10 @@ export default class Stop extends BaseCommand { async run(): Promise { 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})`, diff --git a/cli/src/commands/deal/withdraw.ts b/cli/src/commands/deal/withdraw.ts index 2b45dc06d..c918a788f 100644 --- a/cli/src/commands/deal/withdraw.ts +++ b/cli/src/commands/deal/withdraw.ts @@ -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"; @@ -49,7 +49,7 @@ export default class Withdraw extends BaseCommand { async run(): Promise { const flagsAndArgs = await initCli(this, await this.parse(Withdraw)); - const { dealClient } = await getDealClient(); + const { contracts } = await getContracts(); const deals = await getDeals(flagsAndArgs); const amount = @@ -65,7 +65,7 @@ export default class Withdraw extends BaseCommand { ); 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}`, diff --git a/cli/src/commands/deal/workers-remove.ts b/cli/src/commands/deal/workers-remove.ts index 20547844d..aa385d8c1 100644 --- a/cli/src/commands/deal/workers-remove.ts +++ b/cli/src/commands/deal/workers-remove.ts @@ -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"; @@ -57,9 +57,9 @@ export default class WorkersRemove extends BaseCommand { 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"] ?? diff --git a/cli/src/commands/default/env.ts b/cli/src/commands/default/env.ts index f24fa559a..3a695c12a 100644 --- a/cli/src/commands/default/env.ts +++ b/cli/src/commands/default/env.ts @@ -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 { @@ -48,13 +47,6 @@ export default class Env extends BaseCommand { setEnvConfig(newEnvConfig); const fluenceEnv = await ensureValidFluenceEnv(args.ENV); - if ( - fluenceEnv === "custom" && - fluenceConfig?.customFluenceEnv === undefined - ) { - await ensureCustomAddrsAndPeerIds(); - } - newEnvConfig.fluenceEnv = fluenceEnv; await newEnvConfig.$commit(); diff --git a/cli/src/commands/default/peers.ts b/cli/src/commands/default/peers.ts index 594bc0ccd..eca6cb2e2 100644 --- a/cli/src/commands/default/peers.ts +++ b/cli/src/commands/default/peers.ts @@ -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 { static override description = "Print default Fluence network peer addresses"; @@ -34,7 +34,7 @@ export default class Peers extends BaseCommand { async run(): Promise { 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")); } } diff --git a/cli/src/commands/provider/deal-exit.ts b/cli/src/commands/provider/deal-exit.ts index 0399d4d6f..745d2e1bd 100644 --- a/cli/src/commands/provider/deal-exit.ts +++ b/cli/src/commands/provider/deal-exit.ts @@ -25,7 +25,7 @@ import { DEAL_IDS_FLAG_NAME, } from "../../lib/const.js"; import { - getDealClient, + getContracts, getSignerAddress, populateTx, signBatch, @@ -50,13 +50,11 @@ export default class DealExit extends BaseCommand { async run(): Promise { 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({ @@ -67,7 +65,7 @@ export default class DealExit extends BaseCommand { 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 }; }); diff --git a/cli/src/commands/provider/deal-list.ts b/cli/src/commands/provider/deal-list.ts index fd3c01967..78a4b2326 100644 --- a/cli/src/commands/provider/deal-list.ts +++ b/cli/src/commands/provider/deal-list.ts @@ -31,15 +31,6 @@ export default class DealsList extends BaseCommand { async run(): Promise { 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")); } } diff --git a/cli/src/commands/provider/deal-rewards-info.ts b/cli/src/commands/provider/deal-rewards-info.ts index 272bfd7e0..608a88876 100644 --- a/cli/src/commands/provider/deal-rewards-info.ts +++ b/cli/src/commands/provider/deal-rewards-info.ts @@ -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"; @@ -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( diff --git a/cli/src/commands/provider/deal-rewards-withdraw.ts b/cli/src/commands/provider/deal-rewards-withdraw.ts index b13f2abde..547970a69 100644 --- a/cli/src/commands/provider/deal-rewards-withdraw.ts +++ b/cli/src/commands/provider/deal-rewards-withdraw.ts @@ -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"; @@ -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; diff --git a/cli/src/lib/ajvInstance.ts b/cli/src/lib/ajvInstance.ts index 20fabcfe7..f9b7c5234 100644 --- a/cli/src/lib/ajvInstance.ts +++ b/cli/src/lib/ajvInstance.ts @@ -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>[] diff --git a/cli/src/lib/chain/chainConfig.ts b/cli/src/lib/chain/chainConfig.ts new file mode 100644 index 000000000..09ee84d7b --- /dev/null +++ b/cli/src/lib/chain/chainConfig.ts @@ -0,0 +1,165 @@ +/** + * Fluence CLI + * Copyright (C) 2024 Fluence DAO + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import capitalize from "lodash-es/capitalize.js"; + +import { commandObj } from "../commandObj.js"; +import { envConfig } from "../configs/globalConfigs.js"; +import { dbg } from "../dbg.js"; +import { ensureChainEnv } from "../ensureChainNetwork.js"; +import { numToStr } from "../helpers/typesafeStringify.js"; + +let chainIdPromise: Promise | undefined; + +export async function getChainId() { + if (chainIdPromise === undefined) { + chainIdPromise = (async () => { + const chainEnv = await ensureChainEnv(); + const { CHAIN_IDS } = await import("@fluencelabs/deal-ts-clients"); + let chainId: number = CHAIN_IDS[chainEnv]; + + if (envConfig?.chainId !== undefined) { + commandObj.logToStderr( + `Using custom chain ID: ${numToStr(envConfig.chainId)} from ${envConfig.$getPath()}`, + ); + + chainId = envConfig.chainId; + } + + dbg(`chainId: ${numToStr(chainId)}`); + return chainId; + })(); + } + + return chainIdPromise; +} + +let rpcUrlPromise: Promise | undefined; + +export async function getRpcUrl() { + if (rpcUrlPromise === undefined) { + rpcUrlPromise = (async () => { + const chainEnv = await ensureChainEnv(); + const { RPC_URLS } = await import("@fluencelabs/deal-ts-clients"); + let rpcUrl: string = RPC_URLS[chainEnv]; + + if (envConfig?.rpcUrl !== undefined) { + commandObj.logToStderr( + `Using custom RPC URL: ${envConfig.rpcUrl} from ${envConfig.$getPath()}`, + ); + + rpcUrl = envConfig.rpcUrl; + } + + dbg(`rpcUrl: ${rpcUrl}`); + return rpcUrl; + })(); + } + + return rpcUrlPromise; +} + +let blockScoutUrlPromise: + | Promise< + | { + blockExplorers: { + default: { name: "Blockscout"; url: string; apiUrl: string }; + }; + } + | Record + > + | undefined; + +/** + * Returns blockExplorer config or empty object if env is local + * cause we currently don't run Blockscout for local env + */ +export async function getBlockScoutUrl() { + if (blockScoutUrlPromise === undefined) { + blockScoutUrlPromise = (async () => { + const chainEnv = await ensureChainEnv(); + + if (chainEnv === "local") { + return {}; + } + + const { BLOCK_SCOUT_URLS } = await import("@fluencelabs/deal-ts-clients"); + let blockScoutUrl: string = BLOCK_SCOUT_URLS[chainEnv]; + + if (envConfig?.blockScoutUrl !== undefined) { + commandObj.logToStderr( + `Using custom BlockScout URL: ${envConfig.blockScoutUrl} from ${envConfig.$getPath()}`, + ); + + blockScoutUrl = envConfig.blockScoutUrl; + } + + dbg(`blockScoutUrl: ${blockScoutUrl}`); + return { + blockExplorers: { + default: { + name: "Blockscout", + url: blockScoutUrl, + apiUrl: `${blockScoutUrl}api`, + }, + }, + }; + })(); + } + + return blockScoutUrlPromise; +} + +let subgraphUrlPromise: Promise | undefined; + +export async function getSubgraphUrl() { + if (subgraphUrlPromise === undefined) { + subgraphUrlPromise = (async () => { + const chainEnv = await ensureChainEnv(); + const { SUBGRAPH_URLS } = await import("@fluencelabs/deal-ts-clients"); + let subgraphUrl: string = SUBGRAPH_URLS[chainEnv]; + + if (envConfig?.subgraphUrl !== undefined) { + commandObj.logToStderr( + `Using custom Subgraph URL: ${envConfig.subgraphUrl} from ${envConfig.$getPath()}`, + ); + + subgraphUrl = envConfig.subgraphUrl; + } + + dbg(`subgraphUrl: ${subgraphUrl}`); + return subgraphUrl; + })(); + } + + return subgraphUrlPromise; +} + +let networkNamePromise: Promise | undefined; + +export async function getNetworkName() { + if (networkNamePromise === undefined) { + networkNamePromise = (async () => { + const env = await ensureChainEnv(); + const networkName = `Fluence ${capitalize(env)}`; + dbg(`networkName: ${networkName}`); + return networkName; + })(); + } + + return networkNamePromise; +} diff --git a/cli/src/lib/chain/chainId.ts b/cli/src/lib/chain/chainId.ts deleted file mode 100644 index a3ae262fc..000000000 --- a/cli/src/lib/chain/chainId.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Fluence CLI - * Copyright (C) 2024 Fluence DAO - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import { CHAIN_IDS } from "../../common.js"; -import { ensureChainEnv } from "../ensureChainNetwork.js"; - -export async function getChainId() { - const chainEnv = await ensureChainEnv(); - return CHAIN_IDS[chainEnv]; -} diff --git a/cli/src/lib/chain/chainValidators.ts b/cli/src/lib/chain/chainValidators.ts index 0bba41093..b727b1b6e 100644 --- a/cli/src/lib/chain/chainValidators.ts +++ b/cli/src/lib/chain/chainValidators.ts @@ -19,7 +19,7 @@ import { color } from "@oclif/color"; import parseDuration from "parse-duration"; import { versions } from "../../versions.js"; -import { getReadonlyDealClient } from "../dealClient.js"; +import { getReadonlyContracts } from "../dealClient.js"; import { ensureChainEnv } from "../ensureChainNetwork.js"; import { bigintToStr, numToStr } from "../helpers/typesafeStringify.js"; import { stringifyUnknown } from "../helpers/utils.js"; @@ -30,9 +30,8 @@ export async function getMinCCDuration(): Promise { if ((await ensureChainEnv()) !== "local") { try { - const { readonlyDealClient } = await getReadonlyDealClient(); - const core = readonlyDealClient.getCore(); - minDuration = await core.minDuration(); + const { readonlyContracts } = await getReadonlyContracts(); + minDuration = await readonlyContracts.diamond.minDuration(); } catch {} } @@ -62,13 +61,11 @@ export async function ccDurationValidator() { export async function validateAddress( input: unknown, ): Promise { - const { ethers } = await import("ethers"); - - if (ethers.isAddress(input)) { - return true; - } - - return `Must be a valid address. Got: ${color.yellow(stringifyUnknown(input))}`; + const { isAddress } = await import("ethers"); + return ( + isAddress(input) || + `Must be a valid address. Got: ${color.yellow(stringifyUnknown(input))}` + ); } let protocolVersions: @@ -82,12 +79,11 @@ export async function getProtocolVersions() { let maxProtocolVersion = minProtocolVersion; if ((await ensureChainEnv()) !== "local") { - const { readonlyDealClient } = await getReadonlyDealClient(); - const core = readonlyDealClient.getCore(); + const { readonlyContracts } = await getReadonlyContracts(); [minProtocolVersion, maxProtocolVersion] = await Promise.all([ - core.minProtocolVersion(), - core.maxProtocolVersion(), + readonlyContracts.diamond.minProtocolVersion(), + readonlyContracts.diamond.maxProtocolVersion(), ]); } diff --git a/cli/src/lib/chain/commitment.ts b/cli/src/lib/chain/commitment.ts index a382eb342..d2b132a99 100644 --- a/cli/src/lib/chain/commitment.ts +++ b/cli/src/lib/chain/commitment.ts @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -import { CommitmentStatus, type ICapacity } from "@fluencelabs/deal-ts-clients"; +import type { CommitmentStatus, ICapacity } from "@fluencelabs/deal-ts-clients"; import { color } from "@oclif/color"; import isUndefined from "lodash-es/isUndefined.js"; import omitBy from "lodash-es/omitBy.js"; @@ -35,11 +35,11 @@ import { import { dbg } from "../dbg.js"; import { batchRead, - getDealClient, + getContracts, getEventValues, signBatch, populateTx, - getReadonlyDealClient, + getReadonlyContracts, sign, getDealExplorerClient, } from "../dealClient.js"; @@ -71,24 +71,24 @@ export type ComputePeersWithCC = Awaited< export async function getComputePeersWithCC( computePeers: ResolvedComputePeer[], ) { - const { readonlyDealClient } = await getReadonlyDealClient(); - const market = readonlyDealClient.getMarket(); - const capacity = readonlyDealClient.getCapacity(); + const { readonlyContracts } = await getReadonlyContracts(); const commitmentCreatedEvents = Object.fromEntries( await Promise.all( - (await capacity.queryFilter(capacity.filters.CommitmentCreated)).map( - async (event) => { - return [ - await peerIdHexStringToBase58String(event.args.peerId), - event, - ] as const; - }, - ), + ( + await readonlyContracts.diamond.queryFilter( + readonlyContracts.diamond.filters.CommitmentCreated, + ) + ).map(async (event) => { + return [ + await peerIdHexStringToBase58String(event.args.peerId), + event, + ] as const; + }), ), ); - const { ethers } = await import("ethers"); + const { ZeroHash } = await import("ethers"); const computePeersWithChainInfo = ( await Promise.all( @@ -102,7 +102,9 @@ export async function getComputePeersWithCC( const marketGetComputePeerRes = await (async () => { try { - return await market.getComputePeer(peerIdUint8Array); + return await readonlyContracts.diamond.getComputePeer( + peerIdUint8Array, + ); } catch { return undefined; } @@ -128,7 +130,7 @@ export async function getComputePeersWithCC( c.commitmentCreatedEvent?.args.commitmentId ?? c.marketGetComputePeerRes?.commitmentId; - if (commitmentId === undefined || commitmentId === ethers.ZeroHash) { + if (commitmentId === undefined || commitmentId === ZeroHash) { return c; } @@ -208,12 +210,10 @@ export async function createCommitments(flags: { [OFFER_FLAG_NAME]?: string | undefined; }) { const computePeers = await resolveComputePeersByNames(flags); - const { dealClient } = await getDealClient(); - const core = dealClient.getCore(); - const capacity = dealClient.getCapacity(); - const precision = await core.precision(); - const { ethers } = await import("ethers"); - const epochDuration = await core.epochDuration(); + const { contracts } = await getContracts(); + const precision = await contracts.diamond.precision(); + const { ZeroAddress } = await import("ethers"); + const epochDuration = await contracts.diamond.epochDuration(); const [createCommitmentsTxsErrors, createCommitmentsTxs] = splitErrorsAndResults( @@ -235,10 +235,10 @@ export async function createCommitments(flags: { dbg( `initTimestamp: ${bigintToStr( - await core.initTimestamp(), + await contracts.diamond.initTimestamp(), )} Epoch duration: ${bigintToStr( epochDuration, - )}. Current epoch: ${bigintToStr(await core.currentEpoch())}`, + )}. Current epoch: ${bigintToStr(await contracts.diamond.currentEpoch())}`, ); dbg(`Duration in seconds: ${bigintToStr(durationInSec)}`); @@ -246,7 +246,7 @@ export async function createCommitments(flags: { dbg(`Duration in epochs: ${bigintToStr(durationEpoch)}`); const ccDelegator = capacityCommitment.delegator; - const minDuration = await core.minDuration(); + const minDuration = await contracts.diamond.minDuration(); if (durationEpoch < minDuration) { return { @@ -265,10 +265,10 @@ export async function createCommitments(flags: { return { result: populateTx( - capacity.createCommitment, + contracts.diamond.createCommitment, peerIdUint8Arr, durationEpoch, - ccDelegator ?? ethers.ZeroAddress, + ccDelegator ?? ZeroAddress, ccStakerReward, ), }; @@ -323,7 +323,7 @@ export async function createCommitments(flags: { const commitmentIds = createCommitmentsTxReceipts.flatMap((txReceipt) => { return getEventValues({ txReceipt, - contract: capacity, + contract: contracts.diamond, eventName: "CommitmentCreated", value: "commitmentId", }); @@ -365,8 +365,7 @@ export async function createCommitments(flags: { export async function removeCommitments(flags: CCFlags) { const commitments = await getCommitments(flags); - const { dealClient } = await getDealClient(); - const capacity = dealClient.getCapacity(); + const { contracts } = await getContracts(); const [commitmentInfoErrors, commitmentInfo] = splitErrorsAndResults( await Promise.all( @@ -375,7 +374,9 @@ export async function removeCommitments(flags: CCFlags) { return { result: { commitment, - info: await capacity.getCommitment(commitment.commitmentId), + info: await contracts.diamond.getCommitment( + commitment.commitmentId, + ), }, }; } catch (error) { @@ -425,7 +426,7 @@ export async function removeCommitments(flags: CCFlags) { }) .join("\n\n")}`, commitments.map(({ commitmentId }) => { - return populateTx(capacity.removeCommitment, commitmentId); + return populateTx(contracts.diamond.removeCommitment, commitmentId); }), ); @@ -443,7 +444,7 @@ export async function collateralWithdraw( [FINISH_COMMITMENT_FLAG_NAME]?: boolean; }, ) { - const { ethers } = await import("ethers"); + const { ZeroAddress } = await import("ethers"); const { CommitmentStatus } = await import("@fluencelabs/deal-ts-clients"); const [invalidCommitments, commitments] = splitErrorsAndResults( @@ -474,9 +475,7 @@ export async function collateralWithdraw( ); } - const { dealClient } = await getDealClient(); - const capacity = dealClient.getCapacity(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); for (const commitment of commitments.flatMap(({ ccInfos }) => { return ccInfos; @@ -484,14 +483,14 @@ export async function collateralWithdraw( const { commitmentId, noxName } = commitment; const [unitIds, isExitedStatuses] = - await capacity.getUnitExitStatuses(commitmentId); + await contracts.diamond.getUnitExitStatuses(commitmentId); const units = await batchRead( unitIds.map((unitId, i) => { return async () => { return { unitId, - unitInfo: await market.getComputeUnit(unitId), + unitInfo: await contracts.diamond.getComputeUnit(unitId), isExited: isExitedStatuses[i] ?? (() => { @@ -505,7 +504,7 @@ export async function collateralWithdraw( ); const unitsWithDeals = units.filter((unit) => { - return unit.unitInfo.deal !== ethers.ZeroAddress; + return unit.unitInfo.deal !== ZeroAddress; }); const unitIdsByOnChainWorkerId: Record = {}; @@ -526,7 +525,7 @@ export async function collateralWithdraw( ).flatMap(([onchainWorkerId, unitIds]) => { return unitIds.map((unit) => { return populateTx( - market.moveResourcesFromDeal, + contracts.diamond.moveResourcesFromDeal, [unit], onchainWorkerId, ); @@ -556,8 +555,8 @@ export async function collateralWithdraw( } await sign({ - title: `Withdraw collateral from: ${commitment.commitmentId}}`, - method: capacity.withdrawCollateral, + title: `withdraw collateral from: ${commitment.commitmentId}`, + method: contracts.diamond.withdrawCollateral, args: [commitmentId], }); @@ -579,9 +578,11 @@ export async function collateralWithdraw( return !isExited; }) .map(({ unitId }) => { - return populateTx(capacity.removeCUFromCC, commitmentId, [unitId]); + return populateTx(contracts.diamond.removeCUFromCC, commitmentId, [ + unitId, + ]); }), - populateTx(capacity.finishCommitment, commitmentId), + populateTx(contracts.diamond.finishCommitment, commitmentId), ], ); } @@ -589,8 +590,7 @@ export async function collateralWithdraw( export async function collateralRewardWithdraw(flags: CCFlags) { const commitments = await getCommitments(flags); - const { dealClient } = await getDealClient(); - const capacity = dealClient.getCapacity(); + const { contracts } = await getContracts(); // TODO: add logs here await signBatch( @@ -600,7 +600,7 @@ export async function collateralRewardWithdraw(flags: CCFlags) { }) .join("\n")}`, commitments.map(({ commitmentId }) => { - return populateTx(capacity.withdrawReward, commitmentId); + return populateTx(contracts.diamond.withdrawReward, commitmentId); }), ); } @@ -638,10 +638,8 @@ export function stringifyBasicCommitmentInfo( } export async function getCommitmentsInfo(flags: CCFlags) { - const { readonlyDealClient } = await getReadonlyDealClient(); + const { readonlyContracts } = await getReadonlyContracts(); const { CommitmentStatus } = await import("@fluencelabs/deal-ts-clients"); - const capacity = readonlyDealClient.getCapacity(); - const core = readonlyDealClient.getCore(); const [ commitments, @@ -651,10 +649,10 @@ export async function getCommitmentsInfo(flags: CCFlags) { maxFailedRatio, ] = await Promise.all([ getCommitments(flags), - core.currentEpoch(), - core.epochDuration(), - core.initTimestamp(), - core.maxFailedRatio(), + readonlyContracts.diamond.currentEpoch(), + readonlyContracts.diamond.epochDuration(), + readonlyContracts.diamond.initTimestamp(), + readonlyContracts.diamond.maxFailedRatio(), ]); const dealExplorerClient = await getDealExplorerClient(); @@ -674,7 +672,9 @@ export async function getCommitmentsInfo(flags: CCFlags) { : {}; try { - commitment = await capacity.getCommitment(c.commitmentId); + commitment = await readonlyContracts.diamond.getCommitment( + c.commitmentId, + ); } catch (e) { dbg( `Failed to get commitment from chain ${c.commitmentId}. Error: ${stringifyUnknown(e)}`, @@ -780,9 +780,8 @@ async function stakerRewardToString(stakerReward: bigint | undefined) { return undefined; } - const { readonlyDealClient } = await getReadonlyDealClient(); - const core = readonlyDealClient.getCore(); - const precision = await core.precision(); + const { readonlyContracts } = await getReadonlyContracts(); + const precision = await readonlyContracts.diamond.precision(); return `${numToStr( (Number(stakerReward) * HUNDRED_PERCENT) / Number(precision), )}%`; @@ -835,7 +834,7 @@ async function getCommitmentInfoString( ReturnType >[number]["ccInfos"][number], ) { - const { ethers } = await import("ethers"); + const { ZeroAddress } = await import("ethers"); const staker = ccInfo.delegator ?? ccInfo.ccFromExplorer?.stakerAddress ?? undefined; @@ -860,7 +859,7 @@ async function getCommitmentInfoString( "Capacity commitment ID": ccInfo.commitmentId, Status: await ccStatusToString(ccInfo.status), Staker: - staker === ethers.ZeroAddress + staker === ZeroAddress ? "Anyone can activate capacity commitment" : staker, "Staker reward": diff --git a/cli/src/lib/chain/currencies.ts b/cli/src/lib/chain/currencies.ts index f839c1649..e15568a44 100644 --- a/cli/src/lib/chain/currencies.ts +++ b/cli/src/lib/chain/currencies.ts @@ -17,17 +17,17 @@ import { FLT_SYMBOL, PT_SYMBOL } from "../const.js"; import { dbg } from "../dbg.js"; -import { getReadonlyDealClient } from "../dealClient.js"; +import { getReadonlyContracts } from "../dealClient.js"; import { numToStr } from "../helpers/typesafeStringify.js"; export async function fltParse(value: string): Promise { - const { ethers } = await import("ethers"); - return ethers.parseEther(value); + const { parseEther } = await import("ethers"); + return parseEther(value); } export async function fltFormat(value: bigint): Promise { - const { ethers } = await import("ethers"); - return ethers.formatEther(value); + const { formatEther } = await import("ethers"); + return formatEther(value); } export async function fltFormatWithSymbol(value: bigint): Promise { @@ -35,13 +35,13 @@ export async function fltFormatWithSymbol(value: bigint): Promise { } export async function ptParse(value: string): Promise { - const { ethers } = await import("ethers"); - return ethers.parseUnits(value, await getPtDecimals()); + const { parseUnits } = await import("ethers"); + return parseUnits(value, await getPtDecimals()); } export async function ptFormat(value: bigint): Promise { - const { ethers } = await import("ethers"); - return ethers.formatUnits(value, await getPtDecimals()); + const { formatUnits } = await import("ethers"); + return formatUnits(value, await getPtDecimals()); } export async function ptFormatWithSymbol(value: bigint): Promise { @@ -53,13 +53,12 @@ let ptDecimalsPromise: Promise | undefined; export async function getPtDecimals() { if (ptDecimalsPromise === undefined) { ptDecimalsPromise = (async () => { - const { ethers } = await import("ethers"); - const { readonlyDealClient, provider } = await getReadonlyDealClient(); - const usdc = readonlyDealClient.getUSDC(); + const { id } = await import("ethers"); + const { readonlyContracts, provider } = await getReadonlyContracts(); const decimalsRaw = await provider.call({ - to: await usdc.getAddress(), - data: ethers.id("decimals()").substring(0, 10), + to: readonlyContracts.deployment.usdc, + data: id("decimals()").substring(0, 10), }); const decimals = parseInt(decimalsRaw); diff --git a/cli/src/lib/chain/depositCollateral.ts b/cli/src/lib/chain/depositCollateral.ts index 176faf255..c3cd57798 100644 --- a/cli/src/lib/chain/depositCollateral.ts +++ b/cli/src/lib/chain/depositCollateral.ts @@ -18,7 +18,7 @@ import { color } from "@oclif/color"; import { commandObj } from "../commandObj.js"; -import { getDealClient, getReadonlyDealClient, sign } from "../dealClient.js"; +import { getContracts, getReadonlyContracts, sign } from "../dealClient.js"; import { splitErrorsAndResults } from "../helpers/utils.js"; import { @@ -65,8 +65,7 @@ export async function depositCollateral(flags: CCFlags) { firstCommitment !== undefined && "providerConfigComputePeer" in firstCommitment; - const { dealClient } = await getDealClient(); - const capacity = dealClient.getCapacity(); + const { contracts } = await getContracts(); const commitmentsWithCollateral = await Promise.all( commitments.map(async (commitment) => { @@ -90,7 +89,7 @@ export async function depositCollateral(flags: CCFlags) { return [noxName, peerId, commitmentId].filter(Boolean).join("\n"); }) .join("\n\n")}`, - method: capacity.depositCollateral, + method: contracts.diamond.depositCollateral, args: [ commitments.map(({ commitmentId }) => { return commitmentId; @@ -125,8 +124,10 @@ ${( } async function getCollateral(commitmentId: string) { - const { readonlyDealClient } = await getReadonlyDealClient(); - const capacity = readonlyDealClient.getCapacity(); - const commitment = await capacity.getCommitment(commitmentId); + const { readonlyContracts } = await getReadonlyContracts(); + + const commitment = + await readonlyContracts.diamond.getCommitment(commitmentId); + return commitment.collateralPerUnit * commitment.unitCount; } diff --git a/cli/src/lib/chain/depositToDeal.ts b/cli/src/lib/chain/depositToDeal.ts index 7b45b1599..3912b9c81 100644 --- a/cli/src/lib/chain/depositToDeal.ts +++ b/cli/src/lib/chain/depositToDeal.ts @@ -19,7 +19,7 @@ import { color } from "@oclif/color"; import { commandObj } from "../commandObj.js"; import { getDeals } from "../deal.js"; -import { getDealClient, sign } from "../dealClient.js"; +import { getContracts, sign } from "../dealClient.js"; import { ptFormatWithSymbol, ptParse } from "./currencies.js"; @@ -36,20 +36,15 @@ export async function depositToDeal( ) { const parsedAmount = await ptParse(amount); const deals = await getDeals(flagsAndArgs); - const { ERC20__factory } = await import("@fluencelabs/deal-ts-clients"); - - const { dealClient, providerOrWallet } = await getDealClient(); + const { contracts } = await getContracts(); for (const { dealName, dealId } of deals) { - const deal = dealClient.getDeal(dealId); + const deal = contracts.getDeal(dealId); const tokensString = await ptFormatWithSymbol(parsedAmount); await sign({ title: `Approve ${tokensString} tokens to be deposited to the deal ${dealName}`, - method: ERC20__factory.connect( - await deal.paymentToken(), - providerOrWallet, - ).approve, + method: contracts.usdc.approve, args: [await deal.getAddress(), parsedAmount], }); diff --git a/cli/src/lib/chain/distributeToNox.ts b/cli/src/lib/chain/distributeToNox.ts index 6679b3c1e..4b353577e 100644 --- a/cli/src/lib/chain/distributeToNox.ts +++ b/cli/src/lib/chain/distributeToNox.ts @@ -19,17 +19,15 @@ import assert from "assert"; import { color } from "@oclif/color"; -import { setChainFlags, chainFlags } from "../chainFlags.js"; import { commandObj } from "../commandObj.js"; import { NOX_NAMES_FLAG_NAME, FLT_SYMBOL, OFFER_FLAG_NAME, - PRIV_KEY_FLAG_NAME, MAX_TOKEN_AMOUNT_KEYWORD, } from "../const.js"; import { - getDealClient, + getWallet, sendRawTransaction, getSignerAddress, } from "../dealClient.js"; @@ -104,16 +102,13 @@ export async function withdrawFromNox(flags: { }, })); - const providerPrivateKey = chainFlags[PRIV_KEY_FLAG_NAME]; - for (const { walletKey: noxWalletKey, name: noxName } of computePeers) { const { amountBigInt, txReceipt, noxAddress } = amount === MAX_TOKEN_AMOUNT_KEYWORD - ? await withdrawMaxAmount({ noxWalletKey, noxName, providerPrivateKey }) + ? await withdrawMaxAmount({ noxWalletKey, noxName }) : await withdrawSpecificAmount({ noxWalletKey, noxName, - providerPrivateKey, amountBigInt: await fltParse(amount), }); @@ -134,30 +129,23 @@ export async function withdrawFromNox(flags: { type WithdrawMaxAmountArgs = { noxWalletKey: string; noxName: string; - providerPrivateKey: string | undefined; }; async function withdrawMaxAmount({ noxWalletKey, noxName, - providerPrivateKey, }: WithdrawMaxAmountArgs) { - setChainFlags({ - ...chainFlags, - [PRIV_KEY_FLAG_NAME]: noxWalletKey, - }); - - const { providerOrWallet } = await getDealClient(); + const noxWallet = await getWallet(noxWalletKey); const noxAddress = await getSignerAddress(); - const gasLimit = await providerOrWallet.estimateGas({ + const gasLimit = await noxWallet.estimateGas({ to: noxAddress, value: 0n, }); - const provider = providerOrWallet.provider; - assert(provider !== null, "Unreachable. We ensure provider is not null"); - const gasPrice = await provider.getFeeData(); + const noxProvider = noxWallet.provider; + assert(noxProvider !== null, "Unreachable. We ensure provider is not null"); + const gasPrice = await noxProvider.getFeeData(); if ( gasPrice.maxFeePerGas === null || @@ -171,7 +159,7 @@ async function withdrawMaxAmount({ const feeAmount = (gasPrice.maxFeePerGas + gasPrice.maxPriorityFeePerGas) * gasLimit; - const totalBalance = await provider.getBalance(noxAddress); + const totalBalance = await noxProvider.getBalance(noxAddress); const amountBigInt = totalBalance - feeAmount; if (amountBigInt <= 0n) { @@ -186,18 +174,8 @@ async function withdrawMaxAmount({ }; } - setChainFlags({ - ...chainFlags, - [PRIV_KEY_FLAG_NAME]: providerPrivateKey, - }); - const providerAddress = await getSignerAddress(); - setChainFlags({ - ...chainFlags, - [PRIV_KEY_FLAG_NAME]: noxWalletKey, - }); - const result = { txReceipt: await sendRawTransaction( `Withdraw max amount of ${await fltFormatWithSymbol(amountBigInt)} from ${noxName} (${noxAddress}) to ${providerAddress}`, @@ -208,35 +186,24 @@ async function withdrawMaxAmount({ maxFeePerGas: gasPrice.maxFeePerGas, maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas, }, + noxWallet, ), amountBigInt, noxAddress, }; - setChainFlags({ - ...chainFlags, - [PRIV_KEY_FLAG_NAME]: providerPrivateKey, - }); - return result; } async function withdrawSpecificAmount({ noxWalletKey, noxName, - providerPrivateKey, amountBigInt, }: WithdrawMaxAmountArgs & { amountBigInt: bigint }) { const providerAddress = await getSignerAddress(); + const { address: noxAddress } = await getWallet(noxWalletKey); - setChainFlags({ - ...chainFlags, - [PRIV_KEY_FLAG_NAME]: noxWalletKey, - }); - - const noxAddress = await getSignerAddress(); - - const result = { + return { txReceipt: await sendRawTransaction( `Withdraw ${await fltFormatWithSymbol(amountBigInt)} from ${noxName} (${noxAddress}) to ${providerAddress}`, { to: providerAddress, value: amountBigInt }, @@ -244,11 +211,4 @@ async function withdrawSpecificAmount({ amountBigInt, noxAddress, }; - - setChainFlags({ - ...chainFlags, - [PRIV_KEY_FLAG_NAME]: providerPrivateKey, - }); - - return result; } diff --git a/cli/src/lib/chain/offer/offer.ts b/cli/src/lib/chain/offer/offer.ts index 75b2114c3..494227cc1 100644 --- a/cli/src/lib/chain/offer/offer.ts +++ b/cli/src/lib/chain/offer/offer.ts @@ -15,7 +15,6 @@ * along with this program. If not, see . */ -import type { IMarket } from "@fluencelabs/deal-ts-clients"; import type { OfferDetail } from "@fluencelabs/deal-ts-clients/dist/dealCliClient/types/schemes.js"; import { color } from "@oclif/color"; import times from "lodash-es/times.js"; @@ -41,7 +40,7 @@ import { } from "../../const.js"; import { dbg } from "../../dbg.js"; import { - getDealClient, + getContracts, getDealCliClient, getSignerAddress, guessTxSizeAndSign, @@ -79,9 +78,7 @@ export async function createOffers(flags: OffersArgs) { const allOffers = await resolveOffersFromProviderConfig(flags); const providerConfig = await ensureReadonlyProviderConfig(); const providerConfigPath = providerConfig.$getPath(); - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); - const usdc = dealClient.getUSDC(); + const { contracts } = await getContracts(); const providerArtifactsConfig = await initNewProviderArtifactsConfig(); const fluenceEnv = await ensureFluenceEnv(); @@ -107,40 +104,6 @@ export async function createOffers(flags: OffersArgs) { ); } - const usdcAddress = await usdc.getAddress(); - - // Multicall here is not working for some reason: - // Event 'MarketOfferRegistered' with hash '0x8090f06b11ff71e91580cf20918a29fefe5fcb76bc8819d550d1aef761382a99' not found in logs of the successful transaction. Try updating Fluence CLI to the latest version - - // const registerMarketOfferTxReceipts = await signBatch( - // offers.map( - // ({ - // computePeersToRegister, - // effectorPrefixesAndHash, - // minPricePerCuPerEpochBigInt, - // }) => { - // return [ - // market.registerMarketOffer, - // minPricePerCuPerEpochBigInt, - // usdcAddress, - // effectorPrefixesAndHash, - // computePeersToRegister, - // ]; - // }, - // ), - // ); - - // if (registerMarketOfferTxReceipts === undefined) { - // return commandObj.error("No offers to create"); - // } - - // const notValidatedOfferIds = getEventValueFromReceipts({ - // contract: market, - // eventName: MARKET_OFFER_REGISTERED_EVENT_NAME, - // txReceipts: registerMarketOfferTxReceipts, - // value: OFFER_ID_PROPERTY, - // }); - const offerRegisterResults: ( | { result: { offerId: string; offerName: string } } | { error: string } @@ -185,7 +148,7 @@ export async function createOffers(flags: OffersArgs) { getArgs(computePeersToRegister) { return [ minPricePerCuPerEpochBigInt, - usdcAddress, + contracts.deployment.usdc, effectorPrefixesAndHash, computePeersToRegister, minProtocolVersion, @@ -195,7 +158,7 @@ export async function createOffers(flags: OffersArgs) { getTitle() { return `Register offer: ${offerName}`; }, - method: market.registerMarketOffer, + method: contracts.diamond.registerMarketOffer, validateAddress: assertProviderIsRegistered, })); } catch (e) { @@ -210,7 +173,7 @@ export async function createOffers(flags: OffersArgs) { try { offerId = getEventValue({ - contract: market, + contract: contracts.diamond, eventName: MARKET_OFFER_REGISTERED_EVENT_NAME, txReceipt: offerRegisterTxReceipt, value: OFFER_ID_PROPERTY, @@ -245,8 +208,19 @@ export async function createOffers(flags: OffersArgs) { } try { - await addRemainingCUs({ allCPs, addedCPs, offerId, market, offerName }); - await addRemainingCPs({ allCPs, addedCPs, offerId, market, offerName }); + await addRemainingCUs({ + allCPs, + addedCPs, + offerId, + offerName, + }); + + await addRemainingCPs({ + allCPs, + addedCPs, + offerId, + offerName, + }); } catch (e) { pushOfferRegisterResult({ error: `Error when adding remaining CUs or CPs to the created offer ${color.yellow(offerName)} (${offerId}). You can try using ${color.yellow(`${CLI_NAME} provider offer-update --${OFFER_FLAG_NAME} ${offerName}`)} command to update on-chain offer to match your offer definition in ${providerConfigPath}. Error: ${stringifyUnknown(e)}`, @@ -323,7 +297,6 @@ type AddRemainingCPsOrCUsArgs = { allCPs: CPFromProviderConfig[]; addedCPs: CPFromProviderConfig[]; offerId: string; - market: IMarket; offerName: string; }; @@ -331,11 +304,11 @@ export async function addRemainingCPs({ allCPs, addedCPs = [], offerId, - market, offerName, }: Omit & { addedCPs?: CPFromProviderConfig[]; }) { + const { contracts } = await getContracts(); let totalAddedCPs = addedCPs.length; while (totalAddedCPs < allCPs.length) { @@ -358,14 +331,13 @@ export async function addRemainingCPs({ }, ).join("\n")}\n\nto offer ${offerName} (${offerId})`; }, - method: market.addComputePeers, + method: contracts.diamond.addComputePeers, }); await addRemainingCUs({ allCPs: remainingCPs, addedCPs, offerId, - market, offerName, }); @@ -377,9 +349,9 @@ async function addRemainingCUs({ allCPs, addedCPs, offerId, - market, offerName, }: AddRemainingCPsOrCUsArgs) { + const { contracts } = await getContracts(); const lastRegisteredCP = addedCPs[addedCPs.length - 1]; const lastRegisteredCPFromAllCPs = allCPs[addedCPs.length - 1]; @@ -411,7 +383,7 @@ async function addRemainingCUs({ getTitle({ sliceCount: numberOfCUsForAddCU }) { return `Add ${numToStr(numberOfCUsForAddCU)} compute units\nto compute peer ${cpName} (${peerIdBase58})\nfor offer ${offerName} (${offerId})`; }, - method: market.addComputeUnits, + method: contracts.diamond.addComputeUnits, }); totalRegisteredCUsCount = totalRegisteredCUsCount + registeredCUsCount; @@ -687,8 +659,7 @@ export type EnsureOfferConfig = Awaited< async function ensureOfferConfigs() { const providerConfig = await ensureReadonlyProviderConfig(); const providerArtifactsConfig = await initReadonlyProviderArtifactsConfig(); - - const { ethers } = await import("ethers"); + const { randomBytes } = await import("ethers"); const fluenceEnv = await ensureFluenceEnv(); return Promise.all( @@ -718,7 +689,7 @@ async function ensureOfferConfigs() { peerIdBase58: peerId, peerId: await peerIdBase58ToUint8Array(peerId), unitIds: times(computeUnits).map(() => { - return ethers.randomBytes(32); + return randomBytes(32); }), owner: walletAddress, }; diff --git a/cli/src/lib/chain/offer/updateOffers.ts b/cli/src/lib/chain/offer/updateOffers.ts index 4368f9d8f..2254047d8 100644 --- a/cli/src/lib/chain/offer/updateOffers.ts +++ b/cli/src/lib/chain/offer/updateOffers.ts @@ -25,7 +25,7 @@ import { CLI_NAME, PROVIDER_ARTIFACTS_CONFIG_FULL_FILE_NAME, } from "../../const.js"; -import { getDealClient, signBatch, populateTx } from "../../dealClient.js"; +import { getContracts, signBatch, populateTx } from "../../dealClient.js"; import { numToStr } from "../../helpers/typesafeStringify.js"; import { splitErrorsAndResults } from "../../helpers/utils.js"; import { confirm } from "../../prompt.js"; @@ -290,8 +290,7 @@ async function populatePeersToRemoveTxs( { computePeersFromProviderConfig }: OnChainOffer, peersOnChain: PeersOnChain, ) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); const computePeersToRemove = peersOnChain.filter(({ peerIdBase58 }) => { return !computePeersFromProviderConfig.some((p) => { @@ -309,10 +308,10 @@ async function populatePeersToRemoveTxs( description: `\nRemoving peer ${peerIdBase58} with ${numToStr(computeUnits.length)} compute units`, } : {}), - tx: populateTx(market.removeComputeUnit, computeUnit.id), + tx: populateTx(contracts.diamond.removeComputeUnit, computeUnit.id), }; }), - { tx: populateTx(market.removeComputePeer, hexPeerId) }, + { tx: populateTx(contracts.diamond.removeComputePeer, hexPeerId) }, ]; }, ); @@ -322,10 +321,8 @@ async function populatePaymentTokenTx({ offerIndexerInfo, offerId, }: OnChainOffer) { - const { dealClient } = await getDealClient(); - const usdc = dealClient.getUSDC(); - const market = dealClient.getMarket(); - const usdcAddress = await usdc.getAddress(); + const { contracts } = await getContracts(); + const usdcAddress = contracts.deployment.usdc; return offerIndexerInfo.paymentToken.address === usdcAddress.toLowerCase() ? [] : [ @@ -333,7 +330,11 @@ async function populatePaymentTokenTx({ description: `\nchanging payment token from ${color.yellow( offerIndexerInfo.paymentToken.address, )} to ${color.yellow(usdcAddress)}`, - tx: populateTx(market.changePaymentToken, offerId, usdcAddress), + tx: populateTx( + contracts.diamond.changePaymentToken, + offerId, + usdcAddress, + ), }, ]; } @@ -343,8 +344,7 @@ async function populateMinPricePerCuPerEpochTx({ minPricePerCuPerEpochBigInt, offerId, }: OnChainOffer) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); return offerIndexerInfo.pricePerEpoch === minPricePerCuPerEpochBigInt ? [] : [ @@ -355,7 +355,7 @@ async function populateMinPricePerCuPerEpochTx({ await ptFormatWithSymbol(minPricePerCuPerEpochBigInt), )}`, tx: populateTx( - market.changeMinPricePerCuPerEpoch, + contracts.diamond.changeMinPricePerCuPerEpoch, offerId, minPricePerCuPerEpochBigInt, ), @@ -367,8 +367,7 @@ async function populateEffectorsRemoveTx( { effectors, offerId }: OnChainOffer, effectorsOnChain: string[], ) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); const removedEffectors = effectorsOnChain.filter((cid) => { return effectors === undefined ? true : !effectors.includes(cid); @@ -380,7 +379,7 @@ async function populateEffectorsRemoveTx( { description: `\nRemoving effectors:\n${removedEffectors.join("\n")}`, tx: populateTx( - market.removeEffector, + contracts.diamond.removeEffector, offerId, await Promise.all( removedEffectors.map((cid) => { @@ -396,8 +395,7 @@ async function populateEffectorsAddTx( { effectors, offerId }: OnChainOffer, effectorsOnChain: string[], ) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); const addedEffectors = (effectors ?? []).filter((effector) => { return !effectorsOnChain.some((cid) => { @@ -411,7 +409,7 @@ async function populateEffectorsAddTx( { description: `\nAdding effectors:\n${addedEffectors.join("\n")}`, tx: populateTx( - market.addEffector, + contracts.diamond.addEffector, offerId, await Promise.all( addedEffectors.map((effector) => { @@ -427,8 +425,7 @@ async function populateCUToRemoveTxs( { computePeersFromProviderConfig }: OnChainOffer, peersOnChain: PeersOnChain, ) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); const computeUnitsToRemove = peersOnChain.flatMap( ({ peerIdBase58, computeUnits }) => { @@ -465,18 +462,17 @@ async function populateCUToRemoveTxs( description: `\nRemoving ${numToStr(computeUnits.length)} compute units from peer ${peerIdBase58}`, } : {}), - tx: populateTx(market.removeComputeUnit, computeUnit), + tx: populateTx(contracts.diamond.removeComputeUnit, computeUnit), }; }); }); } async function populateOfferRemoveTx({ offerId }: OnChainOffer) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); return { description: `\nRemoving offer: ${offerId}`, - tx: populateTx(market.removeOffer, offerId), + tx: populateTx(contracts.diamond.removeOffer, offerId), }; } @@ -484,8 +480,7 @@ async function populateCUToAddTxs( { computePeersFromProviderConfig }: OnChainOffer, peersOnChain: PeersOnChain, ) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); const computeUnitsToAdd = peersOnChain.flatMap( ({ peerIdBase58, hexPeerId, computeUnits }) => { @@ -520,7 +515,7 @@ async function populateCUToAddTxs( description: `\nAdding ${numToStr(unitIds.length)} compute units to peer ${peerIdBase58}`, } : {}), - tx: populateTx(market.addComputeUnits, hexPeerId, [CUId]), + tx: populateTx(contracts.diamond.addComputeUnits, hexPeerId, [CUId]), }; }); }); @@ -530,16 +525,13 @@ async function addMissingComputePeers( { computePeersFromProviderConfig, offerId, offerName }: OnChainOffer, peersOnChain: PeersOnChain, ) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); - const allCPs = computePeersFromProviderConfig.filter(({ peerIdBase58 }) => { return !peersOnChain.some((p) => { return p.peerIdBase58 === peerIdBase58; }); }); - return addRemainingCPs({ allCPs, offerId, market, offerName }); + return addRemainingCPs({ allCPs, offerId, offerName }); } function printOffersToUpdateInfo( diff --git a/cli/src/lib/chain/printDealInfo.ts b/cli/src/lib/chain/printDealInfo.ts index 11cea4db1..01d2bf176 100644 --- a/cli/src/lib/chain/printDealInfo.ts +++ b/cli/src/lib/chain/printDealInfo.ts @@ -17,26 +17,27 @@ import { color } from "@oclif/color"; -import { BLOCK_SCOUT_URLS } from "../../common.js"; import { commandObj } from "../commandObj.js"; import { type DealNameAndId } from "../deal.js"; -import { getReadonlyDealClient } from "../dealClient.js"; -import { ensureChainEnv } from "../ensureChainNetwork.js"; +import { getReadonlyContracts } from "../dealClient.js"; import { bigintToStr } from "../helpers/typesafeStringify.js"; +import { getBlockScoutUrl } from "./chainConfig.js"; import { peerIdHexStringToBase58String } from "./conversions.js"; import { ptFormatWithSymbol } from "./currencies.js"; export async function printDealInfo({ dealId, dealName }: DealNameAndId) { - const { readonlyDealClient } = await getReadonlyDealClient(); - const deal = readonlyDealClient.getDeal(dealId); + const { readonlyContracts } = await getReadonlyContracts(); + const deal = readonlyContracts.getDeal(dealId); commandObj.log(`\n${color.yellow(dealName)} info:`); const status = await deal.getStatus(); - const env = await ensureChainEnv(); const { DealStatus } = await import("@fluencelabs/deal-ts-clients"); + const blockScoutUrl = await getBlockScoutUrl(); - if (env !== "local") { - commandObj.log(`Deal: ${BLOCK_SCOUT_URLS[env]}address/${dealId}`); + if ("blockExplorers" in blockScoutUrl) { + commandObj.log( + `Deal: ${blockScoutUrl.blockExplorers.default.url}address/${dealId}`, + ); } commandObj.log(`DealID: "${dealId}"`); diff --git a/cli/src/lib/chain/providerInfo.ts b/cli/src/lib/chain/providerInfo.ts index 14c1041e2..1dfa1ef5c 100644 --- a/cli/src/lib/chain/providerInfo.ts +++ b/cli/src/lib/chain/providerInfo.ts @@ -18,7 +18,7 @@ import { commandObj } from "../commandObj.js"; import { ensureReadonlyProviderConfig } from "../configs/project/provider.js"; import { CLI_NAME } from "../const.js"; -import { getDealClient, sign, getSignerAddress } from "../dealClient.js"; +import { getContracts, sign, getSignerAddress } from "../dealClient.js"; import { cidStringToCIDV1Struct } from "./conversions.js"; @@ -27,8 +27,7 @@ const CURRENTLY_UNUSED_CID = export async function registerProvider() { const providerConfig = await ensureReadonlyProviderConfig(); - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); await sign({ async validateAddress(address: string) { @@ -41,7 +40,7 @@ export async function registerProvider() { } }, title: `Register provider with the name: ${providerConfig.providerName}`, - method: market.setProviderInfo, + method: contracts.diamond.setProviderInfo, args: [ providerConfig.providerName, await cidStringToCIDV1Struct(CURRENTLY_UNUSED_CID), @@ -69,8 +68,7 @@ Provider address: ${signerAddress} export async function updateProvider() { const providerConfig = await ensureReadonlyProviderConfig(); - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); await sign({ async validateAddress(address: string) { @@ -83,7 +81,7 @@ export async function updateProvider() { } }, title: `Update provider name to ${providerConfig.providerName}`, - method: market.setProviderInfo, + method: contracts.diamond.setProviderInfo, args: [ providerConfig.providerName, await cidStringToCIDV1Struct(CURRENTLY_UNUSED_CID), @@ -110,9 +108,8 @@ Provider address: ${signerAddress} } export async function getProviderInfoByAddress(address: string) { - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); - const { name } = await market.getProviderInfo(address); + const { contracts } = await getContracts(); + const { name } = await contracts.diamond.getProviderInfo(address); return { name: name === "" ? null : name, address }; } diff --git a/cli/src/lib/configs/initConfig.ts b/cli/src/lib/configs/initConfig.ts index 7d55b3515..37920773d 100644 --- a/cli/src/lib/configs/initConfig.ts +++ b/cli/src/lib/configs/initConfig.ts @@ -24,7 +24,7 @@ import type { AnySchema, JSONSchemaType, ValidateFunction } from "ajv"; import isInteger from "lodash-es/isInteger.js"; import { jsonStringify } from "../../common.js"; -import { validationErrorToString } from "../ajvInstance.js"; +import { validationErrorToString, getAjv } from "../ajvInstance.js"; import { commandObj } from "../commandObj.js"; import { FS_OPTIONS, @@ -304,15 +304,7 @@ export function getReadonlyConfigInitFunction< const { configDirPath } = getConfigPathResult; let { configPath } = getConfigPathResult; - - const Ajv = (await import("ajv")).default; - const addFormats = (await import("ajv-formats")).default.default; - - const validateLatestConfig = addFormats( - new Ajv.default({ - allowUnionTypes: true, - }), - ).compile(latestSchema); + const validateLatestConfig = getAjv().compile(latestSchema); const schemaPathCommentStart = "# yaml-language-server: $schema="; @@ -466,11 +458,8 @@ export function getReadonlyConfigInitFunction< ); } - const validateCurrentConfigVersion = addFormats( - new Ajv.default({ - allowUnionTypes: true, - }), - ).compile(currentSchema); + const validateCurrentConfigVersion = + getAjv().compile(currentSchema); if (!validateCurrentConfigVersion(config)) { await updateSchemaPathInConfigString( diff --git a/cli/src/lib/configs/project/dockerCompose.ts b/cli/src/lib/configs/project/dockerCompose.ts index 87153d057..d5e346094 100644 --- a/cli/src/lib/configs/project/dockerCompose.ts +++ b/cli/src/lib/configs/project/dockerCompose.ts @@ -253,7 +253,7 @@ async function genDockerCompose(): Promise { }, }, [GRAPH_NODE_CONTAINER_NAME]: { - image: "fluencelabs/graph-node:v0.34.1", + image: "fluencelabs/graph-node:v0.35.1", ports: [ "8000:8000", "8001:8001", diff --git a/cli/src/lib/configs/project/env.ts b/cli/src/lib/configs/project/env.ts index e49eadd36..de12dbbac 100644 --- a/cli/src/lib/configs/project/env.ts +++ b/cli/src/lib/configs/project/env.ts @@ -15,14 +15,14 @@ * along with this program. If not, see . */ +import type { Deployment } from "@fluencelabs/deal-ts-clients"; import type { JSONSchemaType } from "ajv"; -import { DEFAULT_PUBLIC_FLUENCE_ENV } from "../../../common.js"; +import { CHAIN_ENV, DEFAULT_PUBLIC_FLUENCE_ENV } from "../../../common.js"; import { ajv, validationErrorToString } from "../../ajvInstance.js"; import { ENV_CONFIG_FILE_NAME, ENV_CONFIG_FULL_FILE_NAME, - FLUENCE_ENVS, FLUENCE_ENVS_OLD, fluenceOldEnvToNewEnv, TOP_LEVEL_SCHEMA_ID, @@ -66,6 +66,12 @@ const configSchemaV0: JSONSchemaType = configSchemaV0Obj; type ConfigV1 = { fluenceEnv?: FluenceEnv; + relays?: Array; + subgraphUrl?: string; + rpcUrl?: string; + blockScoutUrl?: string; + chainId?: number; + deployment?: Partial; version: 1; }; @@ -76,9 +82,51 @@ const configSchemaV1Obj = { title: "Fluence environment", description: `Fluence environment to connect to`, type: "string", - enum: [...FLUENCE_ENVS], + enum: [...CHAIN_ENV], nullable: true, }, + relays: { + type: "array", + description: `List of custom relay multiaddresses to use when connecting to Fluence network`, + items: { type: "string" }, + minItems: 1, + nullable: true, + }, + subgraphUrl: { + type: "string", + description: `Subgraph URL to use`, + format: "uri", + nullable: true, + }, + rpcUrl: { + type: "string", + description: `RPC URL to use`, + format: "uri", + nullable: true, + }, + blockScoutUrl: { + type: "string", + description: `BlockScout URL to use`, + format: "uri", + nullable: true, + }, + chainId: { + type: "number", + description: `Chain ID to use`, + nullable: true, + }, + deployment: { + type: "object", + description: `Deployed contract address overrides`, + nullable: true, + required: [], + additionalProperties: false, + properties: { + usdc: { type: "string", nullable: true }, + multicall3: { type: "string", nullable: true }, + diamond: { type: "string", nullable: true }, + }, + }, version: { type: "integer", const: 1 }, }, required: ["version"], diff --git a/cli/src/lib/configs/project/fluence.ts b/cli/src/lib/configs/project/fluence.ts index 0b6734834..339f91d65 100644 --- a/cli/src/lib/configs/project/fluence.ts +++ b/cli/src/lib/configs/project/fluence.ts @@ -29,7 +29,6 @@ import { CHAIN_ENV_OLD, type ChainENV, type ChainENVOld, - chainEnvOldToNew, } from "../../../common.js"; import CLIPackageJSON from "../../../versions/cli.package.json" assert { type: "json" }; import { versions } from "../../../versions.js"; @@ -50,7 +49,6 @@ import { DOT_FLUENCE_DIR_NAME, FLUENCE_CONFIG_FILE_NAME, FLUENCE_CONFIG_FULL_FILE_NAME, - FLUENCE_ENVS, type FluenceEnv, GLOBAL_CONFIG_FULL_FILE_NAME, IPFS_ADDR_PROPERTY, @@ -64,6 +62,7 @@ import { type AquaLogLevel, PT_SYMBOL, COMPILE_AQUA_PROPERTY_NAME, + ENV_CONFIG_FULL_FILE_NAME, } from "../../const.js"; import { numToStr } from "../../helpers/typesafeStringify.js"; import { splitErrorsAndResults } from "../../helpers/utils.js"; @@ -73,7 +72,7 @@ import { validateBatchAsync, } from "../../helpers/validations.js"; import { writeSecretKey } from "../../keyPairs.js"; -import { resolveRelays } from "../../multiaddres.js"; +import { resolveDefaultRelays } from "../../multiaddres.js"; import { getFluenceDir, projectRootDir } from "../../paths.js"; import type { Mutable } from "../../typeHelpers.js"; import { @@ -86,6 +85,7 @@ import { type Migrations, } from "../initConfig.js"; +import { initNewEnvConfig } from "./env.js"; import { type OverridableModuleProperties, overridableModuleProperties, @@ -199,10 +199,10 @@ const configSchemaV1Obj = { }, relays: { title: "Relays", - description: `List of Fluence Peer multi addresses or a name of the network. This multi addresses are used for connecting to the Fluence network when deploying. Peer ids from these addresses are also used for deploying in case if you don't specify "peerId" or "peerIds" property in the deployment config. Default: ${FLUENCE_ENVS[0]}`, + description: `List of Fluence Peer multi addresses or a name of the network. This multi addresses are used for connecting to the Fluence network when deploying. Peer ids from these addresses are also used for deploying in case if you don't specify "peerId" or "peerIds" property in the deployment config. Default: ${CHAIN_ENV[0]}`, type: ["string", "array"], oneOf: [ - { type: "string", title: "Network name", enum: FLUENCE_ENVS }, + { type: "string", title: "Network name", enum: CHAIN_ENV }, { type: "array", title: "Multi addresses", @@ -1095,10 +1095,6 @@ ${yamlDiffPatch( # noEmptyResponse: false # # A list of custom relay multiaddresses to use when connecting to Fluence network -# customFluenceEnv: -# contractsEnv: local -# relays: -# - "/ip4/127.0.0.1/tcp/10010/ws/p2p/12D3KooWGpqaLpVUoLB5cJPLDS6CjBNZePBNTYPGpNPNZMDs6osY" # # A map with service names as keys and service configs as values. # # Service names must start with a lowercase letter and contain only letters numbers and underscores. # # You can use \`fluence service new\` or \`fluence service add\` command to add a service @@ -1302,7 +1298,7 @@ const migrations: Migrations = [ contractsEnv: chainNetwork ?? "dar", relays: relays === undefined || typeof relays === "string" - ? await resolveRelays() + ? await resolveDefaultRelays() : relays, }; } @@ -1498,18 +1494,23 @@ const migrations: Migrations = [ const { customFluenceEnv, ...rest } = config; - return { - ...rest, - version: 10, - ...(customFluenceEnv === undefined - ? {} - : { - customFluenceEnv: { - ...customFluenceEnv, - contractsEnv: chainEnvOldToNew(customFluenceEnv.contractsEnv), - }, - }), - }; + if (customFluenceEnv !== undefined) { + const envConfig = await initNewEnvConfig(); + envConfig.relays = customFluenceEnv.relays; + + envConfig.fluenceEnv = + customFluenceEnv.contractsEnv === "kras" + ? "mainnet" + : customFluenceEnv.contractsEnv === "dar" + ? "testnet" + : customFluenceEnv.contractsEnv; + + commandObj.warn( + `Custom fluence env migrated from ${FLUENCE_CONFIG_FULL_FILE_NAME} to ${DOT_FLUENCE_DIR_NAME}/${ENV_CONFIG_FULL_FILE_NAME}`, + ); + } + + return { ...rest, version: 10 }; }, ]; diff --git a/cli/src/lib/configs/project/provider.ts b/cli/src/lib/configs/project/provider.ts index 79f5a26a4..179afe9db 100644 --- a/cli/src/lib/configs/project/provider.ts +++ b/cli/src/lib/configs/project/provider.ts @@ -30,10 +30,14 @@ import mergeWith from "lodash-es/mergeWith.js"; import snakeCase from "lodash-es/snakeCase.js"; import times from "lodash-es/times.js"; -import { type ChainENV, jsonStringify } from "../../../common.js"; +import { + jsonStringify, + CHAIN_RPC_PORT, + type ChainENV, +} from "../../../common.js"; import { versions } from "../../../versions.js"; import { ajv, validationErrorToString } from "../../ajvInstance.js"; -import { getChainId } from "../../chain/chainId.js"; +import { getChainId } from "../../chain/chainConfig.js"; import { ccDurationValidator, validateAddress, @@ -63,11 +67,12 @@ import { WS_CHAIN_URLS, PT_SYMBOL, DEFAULT_CURL_EFFECTOR_CID, - CHAIN_URLS_FOR_CONTAINERS, + CHAIN_RPC_CONTAINER_NAME, CLI_NAME, DEFAULT_NUMBER_OF_LOCAL_NET_NOXES, DEFAULT_VM_EFFECTOR_CID, } from "../../const.js"; +import { resolveDeployment } from "../../dealClient.js"; import { ensureChainEnv } from "../../ensureChainNetwork.js"; import { type ProviderConfigArgs } from "../../generateUserProviderConfig.js"; import { getPeerIdFromSecretKey } from "../../helpers/getPeerIdFromSecretKey.js"; @@ -88,7 +93,7 @@ import { ensureFluenceCCPConfigsDir, } from "../../paths.js"; import { input, list } from "../../prompt.js"; -import { setEnvConfig } from "../globalConfigs.js"; +import { envConfig, setEnvConfig } from "../globalConfigs.js"; import { getReadonlyConfigInitFunction, type InitializedConfig, @@ -2150,11 +2155,12 @@ const LOCAL_API_MULTIADDRS: Record = { async function getDefaultNoxConfigYAML(): Promise { const env = await ensureChainEnv(); const networkId = await getChainId(); - const { DealClient } = await import("@fluencelabs/deal-ts-clients"); + const { RPC_URLS } = await import("@fluencelabs/deal-ts-clients"); - const contractAddresses = DealClient.getContractAddresses( - env === "testnet" ? "dar" : env, - ); + const CHAIN_URLS_FOR_CONTAINERS = { + ...RPC_URLS, + local: `http://${CHAIN_RPC_CONTAINER_NAME}:${CHAIN_RPC_PORT}`, + }; return { aquavmPoolSize: DEFAULT_AQUAVM_POOL_SIZE, @@ -2174,9 +2180,12 @@ async function getDefaultNoxConfigYAML(): Promise { }, }, chain: { - httpEndpoint: CHAIN_URLS_FOR_CONTAINERS[env], + httpEndpoint: + envConfig?.rpcUrl === undefined + ? CHAIN_URLS_FOR_CONTAINERS[env] + : envConfig.rpcUrl, wsEndpoint: WS_CHAIN_URLS[env], - diamondContract: contractAddresses.diamond, + diamondContract: (await resolveDeployment()).diamond, networkId, defaultPriorityFee: 0, }, @@ -2238,7 +2247,7 @@ export type EnsureComputerPeerConfig = Awaited< >[number]; export async function ensureComputerPeerConfigs(computePeerNames?: string[]) { - const { ethers } = await import("ethers"); + const { Wallet } = await import("ethers"); const providerConfig = await ensureReadonlyProviderConfig(); const providerSecretsConfig = @@ -2289,7 +2298,7 @@ export async function ensureComputerPeerConfigs(computePeerNames?: string[]) { .secretKey, computePeerName, computePeer, - signingWallet: ethers.Wallet.createRandom().privateKey, + signingWallet: Wallet.createRandom().privateKey, }; }), ); @@ -2422,7 +2431,7 @@ export async function ensureComputerPeerConfigs(computePeerNames?: string[]) { peerId: await getPeerIdFromSecretKey(secretKey), computeUnits: computePeer.computeUnits, walletKey: signingWallet, - walletAddress: await new ethers.Wallet(signingWallet).getAddress(), + walletAddress: await new Wallet(signingWallet).getAddress(), capacityCommitment, }; }, diff --git a/cli/src/lib/configs/project/providerSecrets.ts b/cli/src/lib/configs/project/providerSecrets.ts index fd8502664..ba5b19ab1 100644 --- a/cli/src/lib/configs/project/providerSecrets.ts +++ b/cli/src/lib/configs/project/providerSecrets.ts @@ -58,6 +58,7 @@ const secretesConfig = { }, signingWallet: { type: "string", + format: "hex", description: "Signing wallet for built-in decider system service in nox", }, }, @@ -129,7 +130,7 @@ export async function initNewProviderSecretsConfig( } async function getDefault(providerConfig: ProviderConfigReadonly) { - const { ethers } = await import("ethers"); + const { Wallet } = await import("ethers"); const noxes: Record = Object.fromEntries( await Promise.all( @@ -138,7 +139,7 @@ async function getDefault(providerConfig: ProviderConfigReadonly) { name, { networkKey: (await genSecretKeyOrReturnExisting(name)).secretKey, - signingWallet: ethers.Wallet.createRandom().privateKey, + signingWallet: Wallet.createRandom().privateKey, }, ] as const; }), diff --git a/cli/src/lib/configs/project/workers.ts b/cli/src/lib/configs/project/workers.ts index b6edbde75..33dbc0003 100644 --- a/cli/src/lib/configs/project/workers.ts +++ b/cli/src/lib/configs/project/workers.ts @@ -21,6 +21,7 @@ import type { JSONSchemaType } from "ajv"; import isEmpty from "lodash-es/isEmpty.js"; import { + CHAIN_ENV, CHAIN_ENV_OLD, type ChainENVOld, chainEnvOldToNew, @@ -35,7 +36,6 @@ import { CLI_NAME, DEFAULT_DEPLOYMENT_NAME, DEFAULT_WORKER_NAME, - FLUENCE_ENVS, type FluenceEnvOld, type FluenceEnv, } from "../../const.js"; @@ -426,7 +426,7 @@ const migrations: Migrations = [ for (const [workerName, host] of Object.entries(config.hosts ?? {})) { const env = await fluenceEnvOldPrompt( `Select the environment that you used for deploying worker ${workerName} with dummyDealId: ${host.dummyDealId} at ${configPath}`, - "custom", + "kras", ); let hostsForEnv = hosts[env]; @@ -525,7 +525,7 @@ version: ${numToStr(latestSchemaObj.properties.version.const)} # hosts: # # A map of directly deployed workers -# ${FLUENCE_ENVS[0]}: +# ${CHAIN_ENV[0]}: # ${DEFAULT_WORKER_NAME}: # # worker CID # definition: bafkreicoctafgctpxf7jk4nynpnma4wdxpcecjtspsjmuidmag6enctnqa diff --git a/cli/src/lib/const.ts b/cli/src/lib/const.ts index 1b8ff5078..33e4c7cea 100644 --- a/cli/src/lib/const.ts +++ b/cli/src/lib/const.ts @@ -31,7 +31,6 @@ import xbytes from "xbytes"; import { getIsUnion, CHAIN_ENV, - CHAIN_URLS_WITHOUT_LOCAL, type ChainENV, CHAIN_RPC_PORT, LOCAL_NET_DEFAULT_WALLET_KEY, @@ -116,16 +115,9 @@ export const WC_METADATA = { icons: [], }; -export const FLUENCE_ENVS = [...CHAIN_ENV, "custom"] as const; -export type FluenceEnv = (typeof FLUENCE_ENVS)[number]; -export const isFluenceEnv = getIsUnion(FLUENCE_ENVS); -export const FLUENCE_ENVS_OLD = [ - "stage", - "dar", - "kras", - "local", - "custom", -] as const; +export type FluenceEnv = (typeof CHAIN_ENV)[number]; +export const isFluenceEnv = getIsUnion(CHAIN_ENV); +export const FLUENCE_ENVS_OLD = ["stage", "dar", "kras", "local"] as const; export type FluenceEnvOld = (typeof FLUENCE_ENVS_OLD)[number]; export const isFluenceEnvOld = getIsUnion(FLUENCE_ENVS_OLD); @@ -136,7 +128,6 @@ export function fluenceOldEnvToNewEnv(env: FluenceEnvOld): FluenceEnv { dar: "testnet", kras: "mainnet", local: "local", - custom: "custom", } as const satisfies Record )[env]; } @@ -156,11 +147,6 @@ export const HTTP_PORT_START = 918; export const DEFAULT_AQUAVM_POOL_SIZE = 2; export const DEFAULT_NUMBER_OF_LOCAL_NET_NOXES = 3; -export const CHAIN_URLS_FOR_CONTAINERS: Record = { - ...CHAIN_URLS_WITHOUT_LOCAL, - local: `http://${CHAIN_RPC_CONTAINER_NAME}:${CHAIN_RPC_PORT}`, -}; - export const WS_CHAIN_URLS: Record = { mainnet: "wss://ws.mainnet.fluence.dev", testnet: "wss://ws.testnet.fluence.dev", @@ -278,7 +264,7 @@ export const NO_INPUT_FLAG = { const fluenceEnvFlagAndArg = { description: "Fluence Environment to use when running the command", - helpValue: `<${FLUENCE_ENVS.join(" | ")}>`, + helpValue: `<${CHAIN_ENV.join(" | ")}>`, }; export const ENV_FLAG_NAME = "env"; diff --git a/cli/src/lib/deal.ts b/cli/src/lib/deal.ts index b6d504be4..43993b53c 100644 --- a/cli/src/lib/deal.ts +++ b/cli/src/lib/deal.ts @@ -36,11 +36,12 @@ import { import { dbg } from "./dbg.js"; import { sign, - getDealClient, + getContracts, getDealMatcherClient, getEventValue, getEventValues, - getReadonlyDealClient, + getReadonlyContracts, + batchRead, } from "./dealClient.js"; import { ensureChainEnv } from "./ensureChainNetwork.js"; import { bigintToStr } from "./helpers/typesafeStringify.js"; @@ -82,12 +83,12 @@ export async function dealCreate({ protocolVersion, deploymentName, }: DealCreateArg) { - const { dealClient } = await getDealClient(); - const core = dealClient.getCore(); - const usdc = dealClient.getUSDC(); - + const { contracts } = await getContracts(); const pricePerCuPerEpochBigInt = await ptParse(pricePerCuPerEpoch); - const minDealDepositedEpochs = await core.minDealDepositedEpochs(); + + const minDealDepositedEpochs = + await contracts.diamond.minDealDepositedEpochs(); + const targetWorkersBigInt = BigInt(targetWorkers); const cuCountPerWorkerBigInt = BigInt(cuCountPerWorker); @@ -121,20 +122,18 @@ export async function dealCreate({ ); } - const dealFactory = dealClient.getDealFactory(); - await sign({ title: `Approve ${await ptFormatWithSymbol(initialBalanceBigInt)} to be deposited to the deal`, - method: usdc.approve, - args: [await dealFactory.getAddress(), initialBalanceBigInt], + method: contracts.usdc.approve, + args: [contracts.deployment.diamond, initialBalanceBigInt], }); const deployDealTxReceipt = await sign({ title: `Create deal with appCID: ${appCID}`, - method: dealFactory.deployDeal, + method: contracts.diamond.deployDeal, args: [ await cidStringToCIDV1Struct(appCID), - await usdc.getAddress(), + contracts.deployment.usdc, initialBalanceBigInt, minWorkers, targetWorkers, @@ -157,7 +156,7 @@ export async function dealCreate({ }); const dealId = getEventValue({ - contract: dealFactory, + contract: contracts.diamond, txReceipt: deployDealTxReceipt, eventName: "DealCreated", value: "deal", @@ -172,22 +171,22 @@ export async function createAndMatchDealsForPeerIds({ ...dealCreateArgs }: Parameters[0] & { peerIdsFromFlags: string }) { const peerIds = commaSepStrToArr(peerIdsFromFlags); - const { dealClient } = await getDealClient(); - const market = dealClient.getMarket(); + const { contracts } = await getContracts(); const { ZeroAddress } = await import("ethers"); const offersWithCUs = await Promise.all( peerIds.map(async (peerId) => { const peerIdUint8Array = await peerIdBase58ToUint8Array(peerId); + const ccIds = await contracts.diamond.getComputeUnitIds(peerIdUint8Array); const computeUnits = ( - await Promise.all( - [...(await market.getComputeUnitIds(peerIdUint8Array))].map( - async (unitId) => { - const info = await market.getComputeUnit(unitId); - return { unitId, deal: info.deal }; - }, - ), + await batchRead( + ccIds.map((unitId) => { + return async () => { + const { deal } = await contracts.diamond.getComputeUnit(unitId); + return { unitId, deal }; + }; + }), ) ) .filter(({ deal }) => { @@ -197,11 +196,10 @@ export async function createAndMatchDealsForPeerIds({ return unitId; }); - return { - computeUnits, - offerId: (await market.getComputePeer(peerIdUint8Array)).offerId, - peerId, - }; + const { offerId } = + await contracts.diamond.getComputePeer(peerIdUint8Array); + + return { computeUnits, offerId, peerId }; }), ); @@ -227,7 +225,7 @@ export async function createAndMatchDealsForPeerIds({ await sign({ title: `Match deal ${dealAddress} with compute units:\n\n${CUs.join("\n")}\n\nfrom offer ${offerId}`, - method: market.matchDeal, + method: contracts.diamond.matchDeal, args: [dealAddress, [offerId], [[CUs]]], }); @@ -249,12 +247,11 @@ async function getDefaultInitialBalance( cuCountPerWorker: bigint, ) { if ((await ensureChainEnv()) === "local") { - const { readonlyDealClient } = await getReadonlyDealClient(); - const core = readonlyDealClient.getCore(); + const { readonlyContracts } = await getReadonlyContracts(); const balance = (DEFAULT_DEAL_ACTIVE_DURATION_FOR_LOCAL_ENV / - (await core.epochDuration())) * + (await readonlyContracts.diamond.epochDuration())) * targetWorkersBigInt * pricePerCuPerEpochBigInt * cuCountPerWorker; @@ -273,8 +270,8 @@ type DealUpdateArg = { }; export async function dealUpdate({ dealAddress, appCID }: DealUpdateArg) { - const { dealClient } = await getDealClient(); - const deal = dealClient.getDeal(dealAddress); + const { contracts } = await getContracts(); + const deal = contracts.getDeal(dealAddress); await sign({ title: `Update deal with new appCID: ${appCID}`, @@ -284,15 +281,14 @@ export async function dealUpdate({ dealAddress, appCID }: DealUpdateArg) { } export async function match(dealAddress: string) { - const { dealClient } = await getDealClient(); + const { contracts } = await getContracts(); const dealMatcherClient = await getDealMatcherClient(); dbg(`running getMatchedOffersByDealId with dealAddress: ${dealAddress}`); - const core = dealClient.getCore(); dbg( `initTimestamp: ${bigintToStr( - await core.initTimestamp(), - )} Current epoch: ${bigintToStr(await core.currentEpoch())}`, + await contracts.diamond.initTimestamp(), + )} Current epoch: ${bigintToStr(await contracts.diamond.currentEpoch())}`, ); const matchedOffers = await setTryTimeout( @@ -314,16 +310,14 @@ export async function match(dealAddress: string) { dbg(`got matchedOffers: ${stringifyUnknown(matchedOffers)}`); - const market = dealClient.getMarket(); - const matchDealTxReceipt = await sign({ title: `Match deal ${dealAddress} with offers:\n\n${matchedOffers.offers.join("\n")}`, - method: market.matchDeal, + method: contracts.diamond.matchDeal, args: [dealAddress, matchedOffers.offers, matchedOffers.computeUnits], }); const pats = getEventValues({ - contract: market, + contract: contracts.diamond, txReceipt: matchDealTxReceipt, eventName: "ComputeUnitsMatched", value: "unitId", diff --git a/cli/src/lib/dealClient.ts b/cli/src/lib/dealClient.ts index 6db25ce2c..8976c8ff0 100644 --- a/cli/src/lib/dealClient.ts +++ b/cli/src/lib/dealClient.ts @@ -18,11 +18,12 @@ import assert from "node:assert"; import type { - DealClient, + Contracts, DealMatcherClient, DealExplorerClient, + DealCliClient, + Deployment, } from "@fluencelabs/deal-ts-clients"; -import type { DealCliClient } from "@fluencelabs/deal-ts-clients/dist/dealCliClient/dealCliClient.js"; import type { TypedContractMethod, StateMutability, @@ -41,13 +42,19 @@ import chunk from "lodash-es/chunk.js"; import stripAnsi from "strip-ansi"; import { - CHAIN_URLS, type TransactionPayload, LOCAL_NET_DEFAULT_WALLET_KEY, } from "../common.js"; +import { + getChainId, + getNetworkName, + getRpcUrl, + getSubgraphUrl, +} from "./chain/chainConfig.js"; import { chainFlags } from "./chainFlags.js"; import { commandObj, isInteractive } from "./commandObj.js"; +import { initEnvConfig } from "./configs/project/env.js"; import { CLI_NAME_FULL, PRIV_KEY_FLAG_NAME } from "./const.js"; import { dbg } from "./dbg.js"; import { ensureChainEnv } from "./ensureChainNetwork.js"; @@ -55,32 +62,25 @@ import { setTryTimeout, stringifyUnknown } from "./helpers/utils.js"; import { createTransaction, getAddressFromConnector } from "./server.js"; let provider: Provider | undefined = undefined; -let readonlyDealClient: DealClient | undefined = undefined; +let readonlyContracts: Contracts | undefined = undefined; -export async function getReadonlyDealClient() { +export async function getReadonlyContracts() { if (provider === undefined) { provider = await ensureProvider(); } - if (readonlyDealClient === undefined) { - readonlyDealClient = await createDealClient(provider); + if (readonlyContracts === undefined) { + readonlyContracts = await createContracts(provider); } - return { - readonlyDealClient, - provider, - }; + return { readonlyContracts, provider }; } let providerOrWallet: Provider | Wallet | undefined = undefined; -let dealClient: DealClient | undefined = undefined; - -// only needed for 'proof' command so it's possible to use multiple wallets during one command execution -// normally, each command will use only one wallet -let dealClientPrivKey: string | undefined = undefined; +let contracts: Contracts | undefined = undefined; -export async function getDealClient() { +export async function getContracts() { const privKey = chainFlags[PRIV_KEY_FLAG_NAME] === undefined && (await ensureChainEnv()) === "local" && @@ -88,25 +88,19 @@ export async function getDealClient() { ? LOCAL_NET_DEFAULT_WALLET_KEY : chainFlags[PRIV_KEY_FLAG_NAME]; - if ( - providerOrWallet === undefined || - dealClient === undefined || - dealClientPrivKey !== privKey - ) { - dealClientPrivKey = privKey; - + if (providerOrWallet === undefined || contracts === undefined) { providerOrWallet = await (privKey === undefined ? ensureProvider() : getWallet(privKey)); - dealClient = await createDealClient(providerOrWallet); + contracts = await createContracts(providerOrWallet); } - return { dealClient, providerOrWallet }; + return { contracts, providerOrWallet }; } export async function getSignerAddress() { - const { providerOrWallet } = await getDealClient(); + const { providerOrWallet } = await getContracts(); return ( "address" in providerOrWallet @@ -120,8 +114,7 @@ let dealMatcherClient: DealMatcherClient | undefined = undefined; export async function getDealMatcherClient() { if (dealMatcherClient === undefined) { const { DealMatcherClient } = await import("@fluencelabs/deal-ts-clients"); - const env = await ensureChainEnv(); - dealMatcherClient = new DealMatcherClient(env === "testnet" ? "dar" : env); + dealMatcherClient = new DealMatcherClient(await getSubgraphUrl()); } return dealMatcherClient; @@ -130,18 +123,13 @@ export async function getDealMatcherClient() { let dealExplorerClient: DealExplorerClient | undefined = undefined; export async function getDealExplorerClient() { - if (provider === undefined) { - provider = await ensureProvider(); - } - if (dealExplorerClient === undefined) { const { DealExplorerClient } = await import("@fluencelabs/deal-ts-clients"); - const env = await ensureChainEnv(); + const { readonlyContracts } = await getReadonlyContracts(); dealExplorerClient = await DealExplorerClient.create( - env === "testnet" ? "dar" : env, - undefined, - provider, + readonlyContracts, + await getSubgraphUrl(), ); } @@ -153,54 +141,77 @@ let dealCliClient: DealCliClient | undefined = undefined; export async function getDealCliClient() { if (dealCliClient === undefined) { const { DealCliClient } = await import("@fluencelabs/deal-ts-clients"); - const env = await ensureChainEnv(); - dealCliClient = new DealCliClient(env); + dealCliClient = new DealCliClient(await getSubgraphUrl()); } return dealCliClient; } -async function createDealClient(signerOrProvider: Provider | Signer) { - const { DealClient } = await import("@fluencelabs/deal-ts-clients"); - const env = await ensureChainEnv(); +let deployment: Promise | undefined = undefined; + +export async function resolveDeployment() { + if (deployment === undefined) { + deployment = (async () => { + const envConfig = await initEnvConfig(); + const { DEPLOYMENTS } = await import("@fluencelabs/deal-ts-clients"); + + if ( + envConfig !== null && + envConfig.deployment !== undefined && + Object.keys(envConfig.deployment).length > 0 + ) { + commandObj.logToStderr( + `Using custom contract addresses ${JSON.stringify(envConfig.deployment)} from ${envConfig.$getPath()}`, + ); + } - const client = new DealClient( - signerOrProvider, - env === "testnet" ? "dar" : env, - ); + return { + ...DEPLOYMENTS[await ensureChainEnv()], + ...envConfig?.deployment, + }; + })(); + } + + return deployment; +} + +async function createContracts(signerOrProvider: Provider | Signer) { + const { Contracts } = await import("@fluencelabs/deal-ts-clients"); + const contracts = new Contracts(signerOrProvider, await resolveDeployment()); await setTryTimeout( "check if blockchain client is connected", async () => { - const core = client.getCore(); // By calling this method we ensure that the blockchain client is connected - await core.minDealDepositedEpochs(); + await contracts.diamond.minDealDepositedEpochs(); }, (err) => { commandObj.error( - `Check if blockchain client is connected by running core.minDealDepositedEpochs() failed: ${stringifyUnknown(err)}`, + `Check if blockchain client is connected by running contracts.diamond.minDealDepositedEpochs() failed: ${stringifyUnknown(err)}`, ); }, 1000 * 5, // 5 seconds ); - return client; + return contracts; } export async function ensureProvider(): Promise { if (provider === undefined) { - const { ethers } = await import("ethers"); - const chainEnv = await ensureChainEnv(); - dbg(`Chain RPC ${CHAIN_URLS[chainEnv]}`); - provider = new ethers.JsonRpcProvider(CHAIN_URLS[chainEnv]); + const { JsonRpcProvider } = await import("ethers"); + + provider = new JsonRpcProvider(await getRpcUrl(), { + chainId: await getChainId(), + name: await getNetworkName(), + }); } return provider; } -async function getWallet(privKey: string): Promise { - const { ethers } = await import("ethers"); - return new ethers.Wallet(privKey, await ensureProvider()); +export async function getWallet(privKey: string): Promise { + const { Wallet } = await import("ethers"); + return new Wallet(privKey, await ensureProvider()); } const DEFAULT_OVERRIDES: TransactionRequest = { @@ -210,6 +221,7 @@ const DEFAULT_OVERRIDES: TransactionRequest = { export async function sendRawTransaction( title: string, transactionRequest: TransactionRequest, + providerOrWallet?: Provider | Wallet, ) { const debugInfo = methodCallToString([ { name: "sendTransaction" }, @@ -218,16 +230,18 @@ export async function sendRawTransaction( dbg(`sending raw transaction: ${debugInfo}`); - const { providerOrWallet } = await getDealClient(); + const providerOrWalletToUse = + providerOrWallet ?? (await getContracts()).providerOrWallet; let txHash: string; let txReceipt: TransactionReceipt | null; - if (providerOrWallet.sendTransaction !== undefined) { + if (providerOrWalletToUse.sendTransaction !== undefined) { const { tx, res } = await setTryTimeout( - `executing ${color.yellow(title)}`, + `execute ${color.yellow(title)}`, async function executingContractMethod() { - const tx = await providerOrWallet.sendTransaction?.(transactionRequest); + const tx = + await providerOrWalletToUse.sendTransaction?.(transactionRequest); assert( tx !== undefined, @@ -275,8 +289,7 @@ export async function sendRawTransaction( }); })); - const { providerOrWallet } = await getDealClient(); - const provider = providerOrWallet.provider; + const provider = providerOrWalletToUse.provider; assert(provider !== null, "Unreachable. Provider is null"); txReceipt = await provider.getTransactionReceipt(txHash); } @@ -339,14 +352,14 @@ async function doSign< : `calling contract method: ${debugInfo}`, ); - const { providerOrWallet } = await getDealClient(); + const { providerOrWallet } = await getContracts(); let txHash: string; let txReceipt: TransactionReceipt | null; if (providerOrWallet.sendTransaction !== undefined) { const { tx, res } = await setTryTimeout( - `executing ${color.yellow(title)} contract method`, + `execute ${color.yellow(title)} contract function`, async function executingContractMethod() { const tx = await method(...args); const res = await tx.wait(); @@ -403,7 +416,7 @@ async function doSign< validateAddress, )); - const { providerOrWallet } = await getDealClient(); + const { providerOrWallet } = await getContracts(); const provider = providerOrWallet.provider; assert(provider !== null, "Unreachable. Provider is null"); txReceipt = await provider.getTransactionReceipt(txHash); @@ -505,14 +518,8 @@ export async function signBatch( throw new Error("All transactions must be to the same address"); } - const { IMulticall__factory } = await import("@fluencelabs/deal-ts-clients"); - const { providerOrWallet } = await getDealClient(); - - const { multicall } = IMulticall__factory.connect( - firstAddr, - providerOrWallet, - ); - + const { contracts } = await getContracts(); + const { multicall } = contracts.getMulticall(firstAddr); const receipts = []; let sliceIndexStart = 0; @@ -722,7 +729,7 @@ export async function guessTxSizeAndSign< let valuesToRegister; let sliceIndex = sliceIndexArg; let isValidTx = false; - const { providerOrWallet } = await getDealClient(); + const { providerOrWallet } = await getContracts(); const address = await getSignerAddress(); do { diff --git a/cli/src/lib/deploy.ts b/cli/src/lib/deploy.ts index 71dde8047..bf014a4b3 100644 --- a/cli/src/lib/deploy.ts +++ b/cli/src/lib/deploy.ts @@ -24,7 +24,7 @@ import { Flags } from "@oclif/core"; import { baseFlags } from "../baseCommand.js"; import type Deploy from "../commands/deploy.js"; -import { getChainId } from "./chain/chainId.js"; +import { getChainId } from "./chain/chainConfig.js"; import { printDealInfo } from "./chain/printDealInfo.js"; import { commandObj } from "./commandObj.js"; import type { Upload_deployArgConfig } from "./compiled-aqua/installation-spell/cli.js"; @@ -49,7 +49,7 @@ import { import { dbg } from "./dbg.js"; import { dealCreate, dealUpdate, match } from "./deal.js"; import { createAndMatchDealsForPeerIds } from "./deal.js"; -import { getReadonlyDealClient } from "./dealClient.js"; +import { getReadonlyContracts } from "./dealClient.js"; import { numToStr } from "./helpers/typesafeStringify.js"; import { stringifyUnknown } from "./helpers/utils.js"; import { disconnectFluenceClient } from "./jsClient.js"; @@ -347,8 +347,8 @@ export async function deployImpl(this: Deploy, cl: typeof Deploy) { async function getDealStatus(dealId: string) { const { DealStatus } = await import("@fluencelabs/deal-ts-clients"); - const { readonlyDealClient } = await getReadonlyDealClient(); - const deal = readonlyDealClient.getDeal(dealId); + const { readonlyContracts } = await getReadonlyContracts(); + const deal = readonlyContracts.getDeal(dealId); const status = Number(await deal.getStatus()); function isDealStatus(status: number): status is DealStatus { diff --git a/cli/src/lib/ensureChainNetwork.ts b/cli/src/lib/ensureChainNetwork.ts index 233c5f7f7..aec12dc42 100644 --- a/cli/src/lib/ensureChainNetwork.ts +++ b/cli/src/lib/ensureChainNetwork.ts @@ -20,8 +20,6 @@ import { color } from "@oclif/color"; import type { ChainENV } from "../common.js"; import { commandObj } from "./commandObj.js"; -import { initReadonlyFluenceConfig } from "./configs/project/fluence.js"; -import { CLI_NAME, ENV_FLAG_NAME } from "./const.js"; import { ensureFluenceEnv } from "./resolveFluenceEnv.js"; let env: ChainENV | undefined = undefined; @@ -36,35 +34,5 @@ function setEnv(e: ChainENV): ChainENV { } export async function ensureChainEnv(): Promise { - if (env !== undefined) { - return env; - } - - const fluenceEnv = await ensureFluenceEnv(); - - if (fluenceEnv !== "custom") { - return setEnv(fluenceEnv); - } - - const fluenceConfig = await initReadonlyFluenceConfig(); - - if (fluenceConfig === null) { - commandObj.error( - `Fluence project is required to use custom env. Please make sure you're in the project directory or specify the environment using --${ENV_FLAG_NAME} flag`, - ); - } - - const customContractsEnv = fluenceConfig.customFluenceEnv?.contractsEnv; - - if (customContractsEnv === undefined) { - commandObj.error( - `${color.yellow("customFluenceEnv")} is not defined in ${color.yellow( - fluenceConfig.$getPath(), - )}. Please make sure it's there or choose some other fluence environment using ${color.yellow( - `${CLI_NAME} default env`, - )}`, - ); - } - - return setEnv(customContractsEnv); + return env === undefined ? setEnv(await ensureFluenceEnv()) : env; } diff --git a/cli/src/lib/multiaddres.ts b/cli/src/lib/multiaddres.ts index 7fe629732..7c3d54ff7 100644 --- a/cli/src/lib/multiaddres.ts +++ b/cli/src/lib/multiaddres.ts @@ -23,17 +23,17 @@ import { type Node as AddrAndPeerId } from "@fluencelabs/fluence-network-environ import { color } from "@oclif/color"; import sample from "lodash-es/sample.js"; -import { jsonStringify } from "../common.js"; +import { CHAIN_ENV, jsonStringify } from "../common.js"; import { commandObj } from "./commandObj.js"; import { envConfig } from "./configs/globalConfigs.js"; import { initFluenceConfig } from "./configs/project/fluence.js"; import { ensureComputerPeerConfigs } from "./configs/project/provider.js"; -import { FLUENCE_ENVS, type FluenceEnv } from "./const.js"; +import type { FluenceEnv } from "./const.js"; import { numToStr } from "./helpers/typesafeStringify.js"; import { splitErrorsAndResults } from "./helpers/utils.js"; import { - getPeerId, + resolveCustomAddrsAndPeerIds, resolveAddrsAndPeerIdsWithoutLocal, } from "./multiaddresWithoutLocal.js"; import { projectRootDir } from "./paths.js"; @@ -50,17 +50,27 @@ async function ensureLocalAddrsAndPeerIds() { ); } -export async function resolveAddrsAndPeerIds(): Promise { - const fluenceEnv = await ensureFluenceEnv(); +async function resolveDefaultAddrsAndPeerIds(): Promise { + const env = await ensureFluenceEnv(); + return env === "local" + ? ensureLocalAddrsAndPeerIds() + : resolveAddrsAndPeerIdsWithoutLocal(env); +} - if (fluenceEnv === "local") { - return ensureLocalAddrsAndPeerIds(); - } +export async function resolveDefaultRelays(): Promise> { + return (await resolveDefaultAddrsAndPeerIds()).map((node) => { + return node.multiaddr; + }); +} - return resolveAddrsAndPeerIdsWithoutLocal(fluenceEnv); +async function resolveAddrsAndPeerIds(): Promise { + return ( + (await resolveCustomAddrsAndPeerIds()) ?? + (await resolveDefaultAddrsAndPeerIds()) + ); } -export async function resolveRelays(): Promise> { +async function resolveRelays(): Promise> { return (await resolveAddrsAndPeerIds()).map((node) => { return node.multiaddr; }); @@ -77,7 +87,7 @@ async function getMaybeNamedAddrAndPeerId( return undefined; } - const fluenceEnv = FLUENCE_ENVS.find((networkName) => { + const fluenceEnv = CHAIN_ENV.find((networkName) => { return maybeRelayName.startsWith(networkName); }); @@ -180,10 +190,6 @@ export async function resolvePeerId(peerIdOrNamedNode: string) { ); } -export async function getRandomPeerId(): Promise { - return getPeerId(await getRandomRelayAddr()); -} - export async function updateRelaysJSON() { const fluenceConfig = await initFluenceConfig(); diff --git a/cli/src/lib/multiaddresWithoutLocal.ts b/cli/src/lib/multiaddresWithoutLocal.ts index e5e9ebe41..41ddee3a6 100644 --- a/cli/src/lib/multiaddresWithoutLocal.ts +++ b/cli/src/lib/multiaddresWithoutLocal.ts @@ -24,13 +24,11 @@ import { import { multiaddr } from "@multiformats/multiaddr"; import { color } from "@oclif/color"; -import { CHAIN_ENV, type PublicFluenceEnv } from "../common.js"; +import { type PublicFluenceEnv } from "../common.js"; import { commandObj } from "./commandObj.js"; -import { initFluenceConfig } from "./configs/project/fluence.js"; +import { initEnvConfig } from "./configs/project/env.js"; import type { FluenceEnv } from "./const.js"; -import { commaSepStrToArr, stringifyUnknown } from "./helpers/utils.js"; -import { input, list } from "./prompt.js"; export function getPeerId(addr: string): string { const id = multiaddr(addr).getPeerId(); @@ -53,82 +51,36 @@ export function addrsToNodes(multiaddrs: string[]): AddrAndPeerId[] { }); } -export async function ensureCustomAddrsAndPeerIds() { - const fluenceConfig = await initFluenceConfig(); +const ADDR_MAP: Record> = { + mainnet: kras, + testnet: testNet, + stage, +}; - if (fluenceConfig === null) { - commandObj.error( - `You must init fluence project if you want to use ${color.yellow( - "custom", - )} fluence env`, - ); - } +let loggedAboutCustomAddrs = false; - if (fluenceConfig.customFluenceEnv?.relays !== undefined) { - let res; +export async function resolveCustomAddrsAndPeerIds() { + const envConfig = await initEnvConfig(); - try { - res = addrsToNodes(fluenceConfig.customFluenceEnv.relays); - } catch (e) { - commandObj.error( - `${fluenceConfig.$getPath()} at ${color.yellow( - "customFluenceEnv.relays", - )}: ${stringifyUnknown(e)}`, + if (envConfig !== null && envConfig.relays !== undefined) { + if (!loggedAboutCustomAddrs) { + commandObj.log( + `Using custom relays from ${color.yellow(envConfig.$getPath())}`, ); + + loggedAboutCustomAddrs = true; } - return res; + return addrsToNodes(envConfig.relays); } - const contractsEnv = await list({ - message: "Select contracts environment for your custom network", - options: [...CHAIN_ENV], - oneChoiceMessage: (): never => { - throw new Error("Unreachable: only one contracts env"); - }, - onNoChoices: (): never => { - throw new Error("Unreachable: no contracts envs"); - }, - }); - - const fluenceEnvOrCustomRelays = commaSepStrToArr( - await input({ - message: "Enter comma-separated list of relays", - validate: (input: string) => { - const relays = commaSepStrToArr(input); - - if (relays.length === 0) { - return "You must specify at least one relay"; - } - - return true; - }, - }), - ); - - fluenceConfig.customFluenceEnv = { - contractsEnv, - relays: fluenceEnvOrCustomRelays, - }; - - await fluenceConfig.$commit(); - return addrsToNodes(fluenceEnvOrCustomRelays); + return null; } -const ADDR_MAP: Record> = { - mainnet: kras, - testnet: testNet, - stage, -}; - export async function resolveAddrsAndPeerIdsWithoutLocal( env: Exclude, ): Promise { - if (env === "custom") { - return ensureCustomAddrsAndPeerIds(); - } - - return ADDR_MAP[env]; + return (await resolveCustomAddrsAndPeerIds()) ?? ADDR_MAP[env]; } export async function resolveRelaysWithoutLocal( diff --git a/cli/src/lib/resolveFluenceEnv.ts b/cli/src/lib/resolveFluenceEnv.ts index 73b030731..d67bf47bb 100644 --- a/cli/src/lib/resolveFluenceEnv.ts +++ b/cli/src/lib/resolveFluenceEnv.ts @@ -17,14 +17,13 @@ import { color } from "@oclif/color"; -import { DEFAULT_PUBLIC_FLUENCE_ENV } from "../common.js"; +import { CHAIN_ENV, DEFAULT_PUBLIC_FLUENCE_ENV } from "../common.js"; import { chainFlags } from "./chainFlags.js"; import { commandObj } from "./commandObj.js"; import { envConfig } from "./configs/globalConfigs.js"; import { ENV_FLAG_NAME, - FLUENCE_ENVS, FLUENCE_ENVS_OLD, isFluenceEnv, type FluenceEnv, @@ -70,7 +69,7 @@ export async function fluenceEnvPrompt( ): Promise { return list({ message, - options: [...FLUENCE_ENVS], + options: [...CHAIN_ENV], oneChoiceMessage() { throw new Error("Unreachable. There are multiple envs"); }, diff --git a/cli/src/lib/server.ts b/cli/src/lib/server.ts index 504b2bda0..b2ca11f41 100644 --- a/cli/src/lib/server.ts +++ b/cli/src/lib/server.ts @@ -32,7 +32,12 @@ import { type ConnectorToCLIMessage, } from "../common.js"; -import { getChainId } from "./chain/chainId.js"; +import { + getBlockScoutUrl, + getChainId, + getRpcUrl, + getNetworkName, +} from "./chain/chainConfig.js"; import { commandObj, isInteractive } from "./commandObj.js"; import { CLI_CONNECTOR_DIR_NAME, @@ -163,8 +168,15 @@ async function sendEvent(msg: CLIToConnectorMsg) { isServerInitialized = true; } - const chainId = await getChainId(); - const cliToConnectorFullMsg: CLIToConnectorFullMsg = { chainId, msg }; + const cliToConnectorFullMsg: CLIToConnectorFullMsg = { + chain: { + id: await getChainId(), + name: await getNetworkName(), + rpcUrls: { default: { http: [await getRpcUrl()] } }, + ...(await getBlockScoutUrl()), + }, + msg, + }; clientEventResponse?.write( `data: ${jsonStringify(cliToConnectorFullMsg, true)}\n\n`, diff --git a/cli/src/versions.json b/cli/src/versions.json index f1f7ee3aa..82148b4a5 100644 --- a/cli/src/versions.json +++ b/cli/src/versions.json @@ -1,9 +1,9 @@ { "protocolVersion": 1, "nox": "fluencelabs/nox:0.26.1", - "chain-rpc": "fluencelabs/chain-rpc:0.20.0", - "chain-deploy-script": "fluencelabs/chain-deploy-script:0.20.0", - "subgraph-deploy-script": "fluencelabs/subgraph-deploy-script:0.20.0", + "chain-rpc": "fluencelabs/chain-rpc:0.22.0", + "chain-deploy-script": "fluencelabs/chain-deploy-script:0.22.0", + "subgraph-deploy-script": "fluencelabs/subgraph-deploy-script:0.22.0", "rust-toolchain": "nightly-2024-06-10", "npm": { "@fluencelabs/aqua-lib": "0.12.1", diff --git a/cli/yarn.lock b/cli/yarn.lock index 053e00f6b..d5d469b36 100644 --- a/cli/yarn.lock +++ b/cli/yarn.lock @@ -436,7 +436,7 @@ __metadata: "@fluencelabs/air-beautify-wasm": "npm:0.3.9" "@fluencelabs/aqua-api": "npm:0.14.10" "@fluencelabs/aqua-to-js": "npm:0.3.13" - "@fluencelabs/deal-ts-clients": "npm:0.20.0" + "@fluencelabs/deal-ts-clients": "npm:0.22.0" "@fluencelabs/fluence-network-environment": "npm:1.2.3" "@fluencelabs/js-client": "npm:0.9.0" "@fluencelabs/npm-aqua-compiler": "npm:0.0.3" @@ -510,9 +510,9 @@ __metadata: languageName: unknown linkType: soft -"@fluencelabs/deal-ts-clients@npm:0.20.0": - version: 0.20.0 - resolution: "@fluencelabs/deal-ts-clients@npm:0.20.0" +"@fluencelabs/deal-ts-clients@npm:0.22.0": + version: 0.22.0 + resolution: "@fluencelabs/deal-ts-clients@npm:0.22.0" dependencies: "@graphql-typed-document-node/core": "npm:^3.2.0" debug: "npm:^4.3.4" @@ -524,7 +524,7 @@ __metadata: graphql-tag: "npm:^2.12.6" ipfs-http-client: "npm:^60.0.1" multiformats: "npm:^13.0.1" - checksum: 10c0/a652bd87b0508d8b7a7282938c1b441ebfc27be11b05f6079d3f80f607ff5ade769ee8713a88b573f8a9884393b2ce25f1e7fb3429c5aabfd4351dcf981d8d61 + checksum: 10c0/1765abc283a6e58d6b4b8c7197b08e3d7e63fe3ae5b76449e0b9be1eaa16f76f1a90996a64962548f0f7d5678cd5f15ac38343906359870fe4ce1c0eb2a6be1d languageName: node linkType: hard diff --git a/packages/cli-connector/src/App.tsx b/packages/cli-connector/src/App.tsx index d91631461..a79cd10b5 100644 --- a/packages/cli-connector/src/App.tsx +++ b/packages/cli-connector/src/App.tsx @@ -24,8 +24,6 @@ import { type ConnectorToCLIMessage, jsonStringify, LOCAL_NET_WALLET_KEYS, - CHAIN_IDS, - ChainId, } from "@repo/common"; import { useEffect, useMemo, useRef, useState } from "react"; import * as v from "valibot"; @@ -47,13 +45,7 @@ const TransactionError = v.object({ }), }); -export function App({ - chainId, - setChainId, -}: { - chainId: ChainId; - setChainId: (chainId: ChainId) => void; -}) { +export function App({ chain }: { chain: CLIToConnectorFullMsg["chain"] }) { const { isConnected, address, chainId: accountChainId } = useAccount(); const [addressUsedByCLI, setAddressUsedByCLI] = useState(null); const client = useClient(); @@ -94,7 +86,7 @@ export function App({ const [trySwitchChainFlag, setTrySwitchChainFlag] = useState(false); const isCorrectChainIdSet = - chainId === client?.chain.id && chainId === accountChainId; + chain.id === client?.chain.id && chain.id === accountChainId; useEffect(() => { if (isCorrectChainIdSet) { @@ -108,14 +100,14 @@ export function App({ // For some reason switchChain does not work if called immediately // So we try until user switches the chain cause we can't proceed until he does setTimeout(() => { - switchChain({ chainId }); + switchChain({ chainId: chain.id }); setTrySwitchChainFlag((prev) => { return !prev; }); }, 2000); }, [ - chainId, + chain, switchChain, trySwitchChainFlag, wasSwitchChainDialogShown, @@ -132,15 +124,11 @@ export function App({ events.onmessage = ({ data }) => { // We are sure CLI returns what we expect so there is no need to validate // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - const { chainId: chainIdFromCLI, msg } = JSON.parse( + const { msg } = JSON.parse( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions data as string, ) as CLIToConnectorFullMsg; - if (chainId !== chainIdFromCLI) { - setChainId(chainIdFromCLI); - } - if (msg.tag !== "ping") { reset(); setIsReturnToCLI(false); @@ -187,7 +175,7 @@ export function App({ ); } }; - }, [chainId, reset, sendTransaction, setChainId]); + }, [chain, reset, sendTransaction]); const { data: txReceipt, @@ -230,7 +218,7 @@ export function App({ return ( <> {isConnected &&

Chain: {client?.chain.name}

} - {client?.chain.id === CHAIN_IDS.local && ( + {client?.chain.name === "Fluence Local" && (
How to work with local chain
    diff --git a/packages/cli-connector/src/main.tsx b/packages/cli-connector/src/main.tsx index 6bde8b68e..972fb442c 100644 --- a/packages/cli-connector/src/main.tsx +++ b/packages/cli-connector/src/main.tsx @@ -19,16 +19,15 @@ import "@rainbow-me/rainbowkit/styles.css"; import { Buffer } from "buffer"; -import { RainbowKitProvider } from "@rainbow-me/rainbowkit"; -import { ChainId, CLIToConnectorFullMsg } from "@repo/common"; +import { RainbowKitProvider, getDefaultConfig } from "@rainbow-me/rainbowkit"; +import { CLIToConnectorFullMsg } from "@repo/common"; import { QueryClientProvider, QueryClient } from "@tanstack/react-query"; import React from "react"; import { useState, useEffect } from "react"; import ReactDOM from "react-dom/client"; -import { WagmiProvider } from "wagmi"; +import { WagmiProvider, deepEqual } from "wagmi"; import { App } from "./App.jsx"; -import { config } from "./wagmi.js"; import "@total-typescript/ts-reset"; import "./index.css"; @@ -42,10 +41,12 @@ if (root === null) { } export function AppWrapper() { - const [chainId, setChainId] = useState(undefined); + const [chain, setChain] = useState< + CLIToConnectorFullMsg["chain"] | undefined + >(undefined); useEffect(() => { - if (chainId !== undefined) { + if (chain !== undefined) { return; } @@ -54,25 +55,42 @@ export function AppWrapper() { eventSource.onmessage = ({ data }) => { // We are sure CLI returns what we expect so there is no need to validate // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - const { chainId: chainIdFromCLI } = JSON.parse( + const { chain: chainFromCLI } = JSON.parse( // eslint-disable-next-line @typescript-eslint/consistent-type-assertions data as string, ) as CLIToConnectorFullMsg; - setChainId(chainIdFromCLI); - eventSource.close(); + if (!deepEqual(chain, chainFromCLI)) { + setChain(chainFromCLI); + } }; - }, [chainId, setChainId]); + }, [chain, setChain]); - if (chainId === undefined) { + if (chain === undefined) { return; } + const config = getDefaultConfig({ + appName: "Fluence CLI Connector", + projectId: "YOUR_PROJECT_ID", + chains: [ + { + ...chain, + nativeCurrency: { + decimals: 18, + name: "Fluence", + symbol: chain.name === "Fluence Mainnet" ? "FLT" : "tFLT", + }, + testnet: chain.name !== "Fluence Mainnet", + }, + ], + }); + return ( - - + + diff --git a/packages/cli-connector/src/wagmi.ts b/packages/cli-connector/src/wagmi.ts deleted file mode 100644 index 6638dd294..000000000 --- a/packages/cli-connector/src/wagmi.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Fluence CLI - * Copyright (C) 2024 Fluence DAO - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import { getDefaultConfig } from "@rainbow-me/rainbowkit"; -import { CHAIN_IDS, CHAIN_URLS } from "@repo/common"; -import { fluence, fluenceStage, fluenceTestnet } from "viem/chains"; - -export const config = getDefaultConfig({ - appName: "Fluence CLI Connector", - projectId: "YOUR_PROJECT_ID", - chains: [ - fluenceStage, - fluenceTestnet, - fluence, - { - id: CHAIN_IDS.local, - name: "local", - nativeCurrency: { - decimals: 18, - name: "Fluence", - symbol: "tFLT", - }, - rpcUrls: { - default: { http: [CHAIN_URLS.local] }, - }, - testnet: true, - }, - ], -}); diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index e51d2e25b..8e444d897 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -18,16 +18,6 @@ import "@total-typescript/ts-reset"; import type { TransactionRequest } from "ethers"; -export const CHAIN_IDS = { - testnet: 52164803, - stage: 123420000220, - mainnet: 9999999, - local: 31337, -} as const satisfies Record; - -export type ChainId = (typeof CHAIN_IDS)[ChainENV]; -export const isChainId = getIsUnion(Object.values(CHAIN_IDS)); - export const CHAIN_RPC_PORT = "8545"; export const DEFAULT_PUBLIC_FLUENCE_ENV = "testnet"; @@ -62,23 +52,6 @@ export function chainEnvOldToNew(env: ChainENVOld): ChainENV { )[env]; } -export const CHAIN_URLS_WITHOUT_LOCAL = { - mainnet: "https://rpc.mainnet.fluence.dev", - testnet: "https://rpc.testnet.fluence.dev", - stage: "https://rpc.stage.fluence.dev", -} as const satisfies Record, string>; - -export const CHAIN_URLS = { - ...CHAIN_URLS_WITHOUT_LOCAL, - local: `http://127.0.0.1:${CHAIN_RPC_PORT}`, -} as const satisfies Record; - -export const BLOCK_SCOUT_URLS = { - mainnet: "https://blockscout.mainnet.fluence.dev/", - testnet: "https://blockscout.testnet.fluence.dev/", - stage: "https://blockscout.stage.fluence.dev/", -} as const satisfies Record, string>; - export type TransactionPayload = { title: string; name: string; @@ -108,7 +81,12 @@ export type CLIToConnectorMsg = }; export type CLIToConnectorFullMsg = { - chainId: ChainId; + chain: { + id: number; + name: string; + rpcUrls: { default: { http: [string] } }; + blockExplorers?: { default: { name: string; url: string; apiUrl: string } }; + }; msg: CLIToConnectorMsg; };