0.3.0 • Published 8 months ago

@fluencelabs/deal-ts-clients v0.3.0

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

ts-clients

Requirements

  • node version: v18.16.1

client

To load contract deployments and interfaces for different stands: kras/testnet/stage/etc.

TODO: rename, because client says nothing.

deal-mather-client

To find preferable compute units for the deal and its configuration via Subgraph (indexer). The main user of the client is https://github.com/fluencelabs/cli (fCli).

Context Diagram

sequenceDiagram

    box integration of DealMatcherClient into fCli
        participant fCli
        participant newClient as DealMatcherClient (deal-ts-clients package)
    end
    participant indexer as Subgraph Node
    box Blockchain
        participant Other Contracts
        participant matcher as Matcher Contract
    end

    Note over indexer,Other Contracts: ...pulling data...
    Note over fCli,Other Contracts: ...already acknowledged about "DealId"...
    Note over fCli,Other Contracts: ...at least 1 epoch (core.epochDuration()) passed after capacity.createCommitment()...
    
    fCli -->> newClient: getMatchedOffersByDealId
    newClient -) indexer: fetch deal configuration
    newClient -) indexer: fetch matched offers
    newClient -->> fCli: data structure that should match Matcher contract matchDeal()
    Note right of fCli: ...logging, showing, salting, other business logic...
    fCli -) matcher: send data structure to matchDeal()

Example Local Package Use

From here I suppose you want to develop locally with this package. Thus, you need to prepare all package dependencies to run locally.

Thus, we suppose you use:

  • local network
  • node version v18.16.1 (example below is checked with this version)
  • TS with installed package TODO: name.

Check completed instruction on how to boot local deal infra: #Develop with Deal Infrastructure

main.js (to run with e.g. via node --loader ts-node/esm main.ts) with random dealId:

import { DealMatcherClient } from "@fluencelabs/deal-aurora";

type asyncRuntimeDecoratorType = (func: Function) => void;

const asyncRuntimeDecorator: asyncRuntimeDecoratorType = (func) => {
    func()
        .then(() => process.exit(0))
        .catch((error: unknown) => {
            console.error(error);
            process.exit(1);
        });
};

async function main() {
    const stand = "local"
    // TODO: place your dealID below.
    const dealId = "0x00...0"

    // General typed class to use.
    const client = new DealMatcherClient(
        stand,
    );

    console.log(await client.getMatchedOffersByDealId(dealId))
}

asyncRuntimeDecorator(main);

deal-explorer-client

This client delivers data for the Explorer Frontend Application. The client consists of 3 ones:

  • DealContractsClient - to load env {kras, testnet, stage} and deployed contracts
  • DealRpcClient - with built-in multicall3 contract feature (1 JSON RPC request per several view calls on different Fluence contracts)
  • IndexerClient - to fetch built GraphQL models from the indexer (i.e. The Graph/Subgraph)

Install

npm i @fluencelabs/deal-aurora

Example UseCase

  • node version v18.16.1
  • TS

tsconfig.js for reactApp example:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "module": "esnext",
    "moduleResolution": "bundler",
    "target": "es2015",

    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react-jsx",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true
  }
}

ready to use main.js (to run with e.g. via node --loader ts-node/esm main.ts)

import { DealExplorerClient } from "@fluencelabs/deal-ts-clients";

type asyncRuntimeDecoratorType = (func: Function) => void;

const asyncRuntimeDecorator: asyncRuntimeDecoratorType = (func) => {
    func()
        .then(() => process.exit(0))
        .catch((error: unknown) => {
            console.error(error);
            process.exit(1);
        });
};

async function main() {
    // For local uncomment below:
    // const rpcUrl = "http://localhost:8545"
    // const stand = "local"

    // For Mumbai uncomment below:
    const rpcUrl = "https://rpc.ankr.com/polygon_mumbai"
    const stand = "testnet"

    // General typed class to use.
    const client = new DealExplorerClient(
        stand,
        rpcUrl,
        undefined,  // TODO: demonstrate on ready.
    );

    // With filter example.
    // await client.getProviders({ effectorIds: ["1241"] });

    // No filters example.
    const res = await client.getOffers();
    for (const offer of res.data) {
        console.log(offer.effectors)
    }
}

asyncRuntimeDecorator(main);

Develop

GraphQL Scheme Generation

It generates typescripts for the graphQl schemes declared in src/indexerClient/queries via fetched graphql schemes. Instruction rules are defined in codegen-deal-explorer-indexer.ts.

Thus, TS files with generated key word you should not rewrite manually.

Those generated files are under git commit because it is a part of the source code, e.g. dealExplorerClient.ts & indexerClient.ts.

ToDo

  • rename to deal-explorer-client
  • use deal package instead of import from ../src
  • commit to the special repo
  • after merge with foundry -> to different npm packages refactor work with several packages
  • add ulr links to fetch filters...
  • TODO: search fields: by client or dealId?
  • resolve registered workers! (separate class?)
  • page counter (thanks to graphQL for no paginators)?
  • optional filtering in .graphql schemes (discord solution processing...) currently unsolved
  • convert values: timestamps, eths
  • move to simple client
  • codegen - get url from env
0.22.3

8 months ago

0.22.2

8 months ago

0.22.1

9 months ago

0.22.0

9 months ago

0.21.0

9 months ago

0.20.0

9 months ago

0.19.8

10 months ago

0.19.4

10 months ago

0.19.5

10 months ago

0.19.6

10 months ago

0.19.7

10 months ago

0.19.1

10 months ago

0.19.2

10 months ago

0.19.3

10 months ago

0.19.0

10 months ago

0.18.7

10 months ago

0.18.6

10 months ago

0.18.5

10 months ago

0.18.4

10 months ago

0.18.3

10 months ago

0.18.2

10 months ago

0.15.4

11 months ago

0.15.0

11 months ago

0.15.1

11 months ago

0.17.0

11 months ago

0.15.2

11 months ago

0.15.3

11 months ago

0.13.13

1 year ago

0.18.1

10 months ago

0.14.0

1 year ago

0.16.0

11 months ago

0.14.2

12 months ago

0.16.1

11 months ago

0.14.3

12 months ago

0.18.0

11 months ago

0.13.12

1 year ago

0.13.11

1 year ago

0.13.10

1 year ago

0.13.9

1 year ago

0.13.8

1 year ago

0.13.7

1 year ago

0.13.6

1 year ago

0.13.4

1 year ago

0.13.5

1 year ago

0.13.3

1 year ago

0.13.2

1 year ago

0.13.1

1 year ago

0.13.0

1 year ago

0.12.0

1 year ago

0.12.1

1 year ago

0.12.2

1 year ago

0.11.0

1 year ago

0.11.1

1 year ago

0.11.2

1 year ago

0.11.3

1 year ago

0.11.4

1 year ago

0.10.1

1 year ago

0.10.0

1 year ago

0.9.0

1 year ago

0.8.0

1 year ago

0.7.2

1 year ago

0.7.3

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.3

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago