Skip to content

Commit

Permalink
Add payments config and charge according to configured rates (#395)
Browse files Browse the repository at this point in the history
* Track amount paid on payment channels and charge as per query cost

* Add payments manager config

* Fix received payment checks

* Separate out payment not received and amount insufficient errors

* Serve a query for free if its rate is not configured

* Load open payment channels from the stored state

* Take list of free queries from config

* Take mutation rates from config

* Rename query rates config fields

* Take cache settings and request timeout from config

* Upgrade ts-nitro packages

* Upgrade package versions
  • Loading branch information
prathamesh0 authored Jul 27, 2023
1 parent aa10a2d commit 198d3e6
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 109 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.2.49",
"version": "0.2.50",
"npmClient": "yarn",
"useWorkspaces": true,
"command": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/cache",
"version": "0.2.49",
"version": "0.2.50",
"description": "Generic object cache",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/cli",
"version": "0.2.49",
"version": "0.2.50",
"main": "dist/index.js",
"license": "AGPL-3.0",
"scripts": {
Expand All @@ -11,8 +11,8 @@
"chat": "DEBUG='vulcanize:*, laconic:*' node dist/chat.js"
},
"dependencies": {
"@cerc-io/peer": "^0.2.49",
"@cerc-io/util": "^0.2.49",
"@cerc-io/peer": "^0.2.50",
"@cerc-io/util": "^0.2.50",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/utils": "^9.1.1",
"@ipld/dag-cbor": "^8.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/codegen",
"version": "0.2.49",
"version": "0.2.50",
"description": "Code generator",
"private": true,
"main": "index.js",
Expand All @@ -20,7 +20,7 @@
},
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@cerc-io/util": "^0.2.49",
"@cerc-io/util": "^0.2.50",
"@graphql-tools/load-files": "^6.5.2",
"@poanet/solidity-flattener": "https://github.com/vulcanize/solidity-flattener.git",
"@solidity-parser/parser": "^0.13.2",
Expand Down
10 changes: 5 additions & 5 deletions packages/codegen/src/templates/package-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/cli": "^0.2.49",
"@cerc-io/ipld-eth-client": "^0.2.49",
"@cerc-io/solidity-mapper": "^0.2.49",
"@cerc-io/util": "^0.2.49",
"@cerc-io/cli": "^0.2.50",
"@cerc-io/ipld-eth-client": "^0.2.50",
"@cerc-io/solidity-mapper": "^0.2.50",
"@cerc-io/util": "^0.2.50",
{{#if (subgraphPath)}}
"@cerc-io/graph-node": "^0.2.49",
"@cerc-io/graph-node": "^0.2.50",
{{/if}}
"@ethersproject/providers": "^5.4.4",
"apollo-type-bigint": "^0.1.3",
Expand Down
10 changes: 5 additions & 5 deletions packages/graph-node/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@cerc-io/graph-node",
"version": "0.2.49",
"version": "0.2.50",
"main": "dist/index.js",
"license": "AGPL-3.0",
"devDependencies": {
"@cerc-io/solidity-mapper": "^0.2.49",
"@cerc-io/solidity-mapper": "^0.2.50",
"@ethersproject/providers": "^5.4.4",
"@graphprotocol/graph-ts": "^0.22.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
Expand Down Expand Up @@ -51,9 +51,9 @@
"dependencies": {
"@apollo/client": "^3.3.19",
"@cerc-io/assemblyscript": "0.19.10-watcher-ts-0.1.2",
"@cerc-io/cache": "^0.2.49",
"@cerc-io/ipld-eth-client": "^0.2.49",
"@cerc-io/util": "^0.2.49",
"@cerc-io/cache": "^0.2.50",
"@cerc-io/ipld-eth-client": "^0.2.50",
"@cerc-io/util": "^0.2.50",
"@types/json-diff": "^0.5.2",
"@types/yargs": "^17.0.0",
"bn.js": "^4.11.9",
Expand Down
4 changes: 2 additions & 2 deletions packages/ipld-eth-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/ipld-eth-client",
"version": "0.2.49",
"version": "0.2.50",
"description": "IPLD ETH Client",
"main": "dist/index.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"homepage": "https://github.com/cerc-io/watcher-ts#readme",
"dependencies": {
"@apollo/client": "^3.7.1",
"@cerc-io/cache": "^0.2.49",
"@cerc-io/cache": "^0.2.50",
"cross-fetch": "^3.1.4",
"debug": "^4.3.1",
"ethers": "^5.4.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/peer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/peer",
"version": "0.2.49",
"version": "0.2.50",
"description": "libp2p module",
"main": "dist/index.js",
"exports": "./dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/solidity-mapper/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@cerc-io/solidity-mapper",
"version": "0.2.49",
"version": "0.2.50",
"main": "dist/index.js",
"license": "AGPL-3.0",
"devDependencies": {
"@cerc-io/ipld-eth-client": "^0.2.49",
"@cerc-io/ipld-eth-client": "^0.2.50",
"@ethersproject/abi": "^5.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/test",
"version": "0.2.49",
"version": "0.2.50",
"main": "dist/index.js",
"license": "AGPL-3.0",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/tracing-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/tracing-client",
"version": "0.2.49",
"version": "0.2.50",
"description": "ETH VM tracing client",
"main": "dist/index.js",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions packages/util/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@cerc-io/util",
"version": "0.2.49",
"version": "0.2.50",
"main": "dist/index.js",
"license": "AGPL-3.0",
"dependencies": {
"@apollo/utils.keyvaluecache": "^1.0.1",
"@cerc-io/nitro-client": "^0.1.4",
"@cerc-io/solidity-mapper": "^0.2.49",
"@cerc-io/nitro-client": "^0.1.5",
"@cerc-io/solidity-mapper": "^0.2.50",
"@cerc-io/ts-channel": "1.0.3-ts-nitro-0.1.1",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/schema": "^9.0.10",
Expand Down Expand Up @@ -40,8 +40,8 @@
"yargs": "^17.0.1"
},
"devDependencies": {
"@cerc-io/cache": "^0.2.49",
"@cerc-io/ipld-eth-client": "^0.2.49",
"@cerc-io/cache": "^0.2.50",
"@cerc-io/ipld-eth-client": "^0.2.50",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@types/express": "^4.17.14",
"@types/fs-extra": "^9.0.11",
Expand Down
36 changes: 31 additions & 5 deletions packages/util/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ interface L2TxsConfig {
privateKey: string;

// Gas limit for tx
gasLimit?: number
gasLimit?: number;
}

// Peer config
Expand Down Expand Up @@ -126,11 +126,37 @@ export interface PeerConfig {
l2TxsConfig?: L2TxsConfig;
}

export interface BaseRatesConfig {
freeQueriesLimit: number;
freeQueriesList: string[];
queries: { [key: string]: string };
mutations: { [key: string]: string };
}

export interface PaymentsCacheConfig {
maxAccounts: number;
accountTTLInSecs: number;
maxVouchersPerAccount: number;
voucherTTLInSecs: number;
maxPaymentChannels: number;
paymentChannelTTLInSecs: number;
}

// Payments manager config
export interface PaymentsConfig {
ratesFile: string;
requestTimeoutInSecs: number;
cache: PaymentsCacheConfig;
}

// ts-nitro config
export interface NitroConfig {
store: string
privateKey: string
chainPrivateKey: string
store: string;

privateKey: string;
chainPrivateKey: string;

payments: PaymentsConfig;
}

// P2P config
Expand Down Expand Up @@ -179,7 +205,7 @@ export interface ServerConfig {

// Flag to specify whether RPC endpoint supports block hash as block tag parameter
// https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block
rpcSupportsBlockHashParam: boolean
rpcSupportsBlockHashParam: boolean;
}

export interface UpstreamConfig {
Expand Down
Loading

0 comments on commit 198d3e6

Please sign in to comment.