0.3.0 • Published 11 days ago

@fluencelabs/deal-ts-clients v0.3.0

Weekly downloads
-
License
-
Repository
-
Last release
11 days 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.13.11

11 days ago

0.13.10

24 days ago

0.13.9

1 month ago

0.13.8

1 month ago

0.13.7

2 months ago

0.13.6

2 months ago

0.13.4

2 months ago

0.13.5

2 months ago

0.13.3

2 months ago

0.13.2

2 months ago

0.13.1

2 months ago

0.13.0

2 months ago

0.12.0

2 months ago

0.12.1

2 months ago

0.12.2

2 months ago

0.11.0

2 months ago

0.11.1

2 months ago

0.11.2

2 months ago

0.11.3

2 months ago

0.11.4

2 months ago

0.10.1

2 months ago

0.10.0

2 months ago

0.9.0

2 months ago

0.8.0

2 months ago

0.7.2

3 months ago

0.7.3

3 months ago

0.7.1

3 months ago

0.7.0

3 months ago

0.6.7

3 months ago

0.6.6

3 months ago

0.6.3

3 months ago

0.6.5

3 months ago

0.6.4

3 months ago

0.6.1

3 months ago

0.6.0

3 months ago

0.5.2

3 months ago

0.5.1

3 months ago

0.5.0

3 months ago

0.4.0

4 months ago

0.3.0

4 months ago