From 87f6a1aa57a10991038bdbb59dc5d7be9c3708fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20L=C3=B3pez?= <50665615+flopez7@users.noreply.github.com> Date: Fri, 7 Jun 2024 07:48:17 +0200 Subject: [PATCH 1/5] [SDK] Transactions module (#2101) * Add transactions module in SDK * Clean tests and generate docs * fix transaction path in subgraph * remove print option for python SDK tests --- docs/sdk/python/human_protocol_sdk.filter.md | 21 + docs/sdk/python/human_protocol_sdk.md | 2 + docs/sdk/python/index.md | 1 + docs/sdk/typescript/.nojekyll | 1 - docs/sdk/typescript/README.md | 4 +- docs/sdk/typescript/base/README.md | 13 + .../base/classes/BaseEthersClient.md | 63 ++ .../classes/base.BaseEthersClient.md | 76 --- .../classes/operator.OperatorUtils.md | 163 ----- docs/sdk/typescript/encryption/README.md | 14 + .../classes/Encryption.md} | 126 ++-- .../classes/EncryptionUtils.md} | 124 ++-- docs/sdk/typescript/escrow/README.md | 14 + .../classes/EscrowClient.md} | 603 +++++++++--------- .../classes/EscrowUtils.md} | 60 +- docs/sdk/typescript/kvstore/README.md | 13 + .../classes/KVStoreClient.md} | 239 +++---- docs/sdk/typescript/modules.md | 24 +- docs/sdk/typescript/modules/base.md | 9 - docs/sdk/typescript/modules/encryption.md | 10 - docs/sdk/typescript/modules/escrow.md | 10 - docs/sdk/typescript/modules/kvstore.md | 9 - docs/sdk/typescript/modules/operator.md | 9 - docs/sdk/typescript/modules/staking.md | 9 - docs/sdk/typescript/modules/statistics.md | 9 - docs/sdk/typescript/modules/storage.md | 9 - docs/sdk/typescript/operator/README.md | 13 + .../operator/classes/OperatorUtils.md | 158 +++++ docs/sdk/typescript/staking/README.md | 13 + .../classes/StakingClient.md} | 349 +++++----- docs/sdk/typescript/statistics/README.md | 13 + .../classes/StatisticsClient.md} | 109 ++-- docs/sdk/typescript/storage/README.md | 13 + .../classes/StorageClient.md} | 156 +++-- .../human_protocol_sdk/filter.py | 63 ++ .../human_protocol_sdk/gql/transaction.py | 65 ++ .../transaction/__init__.py | 11 + .../transaction/transaction_utils.py | 200 ++++++ .../scripts/run-unit-test.sh | 2 +- .../transaction/test_transaction_utils.py | 187 ++++++ .../human-protocol-sdk/src/error.ts | 12 + .../src/graphql/queries/transaction.ts | 59 ++ .../human-protocol-sdk/src/interfaces.ts | 20 + .../human-protocol-sdk/src/transaction.ts | 146 +++++ .../test/transaction.test.ts | 188 ++++++ .../sdk/typescript/subgraph/schema.graphql | 11 + .../typescript/subgraph/src/mapping/Escrow.ts | 6 + .../subgraph/src/mapping/EscrowFactory.ts | 3 + .../subgraph/src/mapping/HMToken.ts | 13 + .../subgraph/src/mapping/KVStore.ts | 2 + .../subgraph/src/mapping/RewardPool.ts | 2 + .../subgraph/src/mapping/Staking.ts | 27 + .../subgraph/src/mapping/legacy/Escrow.ts | 4 + .../src/mapping/legacy/EscrowFactory.ts | 2 + .../subgraph/src/mapping/utils/transaction.ts | 21 + .../escrow-factory/escrow-factory.test.ts | 50 ++ .../subgraph/tests/escrow/escrow.test.ts | 210 ++++++ .../typescript/subgraph/tests/hmt/hmt.test.ts | 156 +++++ .../subgraph/tests/kvstore/kvstore.test.ts | 67 ++ .../escrow-factory/escrow-factory.test.ts | 50 ++ .../tests/legacy/escrow/escrow.test.ts | 120 ++++ .../tests/reward-pool/reward-pool.test.ts | 48 ++ .../subgraph/tests/staking/staking.test.ts | 192 ++++++ 63 files changed, 3186 insertions(+), 1210 deletions(-) delete mode 100644 docs/sdk/typescript/.nojekyll create mode 100644 docs/sdk/typescript/base/README.md create mode 100644 docs/sdk/typescript/base/classes/BaseEthersClient.md delete mode 100644 docs/sdk/typescript/classes/base.BaseEthersClient.md delete mode 100644 docs/sdk/typescript/classes/operator.OperatorUtils.md create mode 100644 docs/sdk/typescript/encryption/README.md rename docs/sdk/typescript/{classes/encryption.Encryption.md => encryption/classes/Encryption.md} (70%) rename docs/sdk/typescript/{classes/encryption.EncryptionUtils.md => encryption/classes/EncryptionUtils.md} (71%) create mode 100644 docs/sdk/typescript/escrow/README.md rename docs/sdk/typescript/{classes/escrow.EscrowClient.md => escrow/classes/EscrowClient.md} (62%) rename docs/sdk/typescript/{classes/escrow.EscrowUtils.md => escrow/classes/EscrowUtils.md} (77%) create mode 100644 docs/sdk/typescript/kvstore/README.md rename docs/sdk/typescript/{classes/kvstore.KVStoreClient.md => kvstore/classes/KVStoreClient.md} (60%) delete mode 100644 docs/sdk/typescript/modules/base.md delete mode 100644 docs/sdk/typescript/modules/encryption.md delete mode 100644 docs/sdk/typescript/modules/escrow.md delete mode 100644 docs/sdk/typescript/modules/kvstore.md delete mode 100644 docs/sdk/typescript/modules/operator.md delete mode 100644 docs/sdk/typescript/modules/staking.md delete mode 100644 docs/sdk/typescript/modules/statistics.md delete mode 100644 docs/sdk/typescript/modules/storage.md create mode 100644 docs/sdk/typescript/operator/README.md create mode 100644 docs/sdk/typescript/operator/classes/OperatorUtils.md create mode 100644 docs/sdk/typescript/staking/README.md rename docs/sdk/typescript/{classes/staking.StakingClient.md => staking/classes/StakingClient.md} (60%) create mode 100644 docs/sdk/typescript/statistics/README.md rename docs/sdk/typescript/{classes/statistics.StatisticsClient.md => statistics/classes/StatisticsClient.md} (73%) create mode 100644 docs/sdk/typescript/storage/README.md rename docs/sdk/typescript/{classes/storage.StorageClient.md => storage/classes/StorageClient.md} (62%) create mode 100644 packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/transaction.py create mode 100644 packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/__init__.py create mode 100644 packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py create mode 100644 packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py create mode 100644 packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/transaction.ts create mode 100644 packages/sdk/typescript/human-protocol-sdk/src/transaction.ts create mode 100644 packages/sdk/typescript/human-protocol-sdk/test/transaction.test.ts create mode 100644 packages/sdk/typescript/subgraph/src/mapping/utils/transaction.ts diff --git a/docs/sdk/python/human_protocol_sdk.filter.md b/docs/sdk/python/human_protocol_sdk.filter.md index ac0a3c76d6..c5e7fadf1c 100644 --- a/docs/sdk/python/human_protocol_sdk.filter.md +++ b/docs/sdk/python/human_protocol_sdk.filter.md @@ -42,3 +42,24 @@ Initializes a PayoutFilter instance. * **recipient** (`Optional`[`str`]) – Recipient address * **date_from** (`Optional`[`datetime`]) – Created from date * **date_to** (`Optional`[`datetime`]) – Created to date + +### *class* human_protocol_sdk.filter.TransactionFilter(networks, from_address=None, to_address=None, start_date=None, end_date=None, start_block=None, end_block=None) + +Bases: `object` + +A class used to filter transactions. + +#### \_\_init_\_(networks, from_address=None, to_address=None, start_date=None, end_date=None, start_block=None, end_block=None) + +Initializes a TransactionsFilter instance. + +* **Parameters:** + * **networks** (`List`[[`ChainId`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.ChainId)]) – List of chain IDs to filter transactions from + * **from_address** (`Optional`[`str`]) – Sender address + * **to_address** (`Optional`[`str`]) – Receiver address + * **start_date** (`Optional`[`datetime`]) – Start date for filtering transactions + * **end_date** (`Optional`[`datetime`]) – End date for filtering transactions + * **start_block** (`Optional`[`int`]) – Start block number for filtering transactions + * **end_block** (`Optional`[`int`]) – End block number for filtering transactions +* **Raises:** + **ValueError** – If start_date is after end_date diff --git a/docs/sdk/python/human_protocol_sdk.md b/docs/sdk/python/human_protocol_sdk.md index a21347b75a..b779d78361 100644 --- a/docs/sdk/python/human_protocol_sdk.md +++ b/docs/sdk/python/human_protocol_sdk.md @@ -148,6 +148,8 @@ * [`FilterError`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.FilterError) * [`PayoutFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.PayoutFilter) * [`PayoutFilter.__init__()`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.PayoutFilter.__init__) + * [`TransactionFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.TransactionFilter) + * [`TransactionFilter.__init__()`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.TransactionFilter.__init__) * [human_protocol_sdk.legacy_encryption module](human_protocol_sdk.legacy_encryption.md) * [`DecryptionError`](human_protocol_sdk.legacy_encryption.md#human_protocol_sdk.legacy_encryption.DecryptionError) * [`Encryption`](human_protocol_sdk.legacy_encryption.md#human_protocol_sdk.legacy_encryption.Encryption) diff --git a/docs/sdk/python/index.md b/docs/sdk/python/index.md index 1c04f2f29d..ca5e5e0ea0 100644 --- a/docs/sdk/python/index.md +++ b/docs/sdk/python/index.md @@ -50,6 +50,7 @@ pip install human-protocol-sdk[agreement] * [`EscrowFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.EscrowFilter) * [`FilterError`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.FilterError) * [`PayoutFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.PayoutFilter) + * [`TransactionFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.TransactionFilter) * [human_protocol_sdk.legacy_encryption module](human_protocol_sdk.legacy_encryption.md) * [`DecryptionError`](human_protocol_sdk.legacy_encryption.md#human_protocol_sdk.legacy_encryption.DecryptionError) * [`Encryption`](human_protocol_sdk.legacy_encryption.md#human_protocol_sdk.legacy_encryption.Encryption) diff --git a/docs/sdk/typescript/.nojekyll b/docs/sdk/typescript/.nojekyll deleted file mode 100644 index e2ac6616ad..0000000000 --- a/docs/sdk/typescript/.nojekyll +++ /dev/null @@ -1 +0,0 @@ -TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/sdk/typescript/README.md b/docs/sdk/typescript/README.md index f0aaf7a38c..6140b1dd9e 100644 --- a/docs/sdk/typescript/README.md +++ b/docs/sdk/typescript/README.md @@ -1,4 +1,6 @@ -@human-protocol/sdk / [Modules](modules.md) +**@human-protocol/sdk** • [**Docs**](modules.md) + +*** # Human Protocol Node.js SDK diff --git a/docs/sdk/typescript/base/README.md b/docs/sdk/typescript/base/README.md new file mode 100644 index 0000000000..2eab692472 --- /dev/null +++ b/docs/sdk/typescript/base/README.md @@ -0,0 +1,13 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / base + +# base + +## Index + +### Classes + +- [BaseEthersClient](classes/BaseEthersClient.md) diff --git a/docs/sdk/typescript/base/classes/BaseEthersClient.md b/docs/sdk/typescript/base/classes/BaseEthersClient.md new file mode 100644 index 0000000000..21deb7e0ca --- /dev/null +++ b/docs/sdk/typescript/base/classes/BaseEthersClient.md @@ -0,0 +1,63 @@ +[**@human-protocol/sdk**](../../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../../modules.md) / [base](../README.md) / BaseEthersClient + +# Class: `abstract` BaseEthersClient + +## Introduction + +This class is used as a base class for other clients making on-chain calls. + +## Extended by + +- [`EscrowClient`](../../escrow/classes/EscrowClient.md) +- [`KVStoreClient`](../../kvstore/classes/KVStoreClient.md) +- [`StakingClient`](../../staking/classes/StakingClient.md) + +## Constructors + +### new BaseEthersClient() + +> **new BaseEthersClient**(`runner`, `networkData`): [`BaseEthersClient`](BaseEthersClient.md) + +**BaseClient constructor** + +#### Parameters + +• **runner**: `ContractRunner` + +The Signer or Provider object to interact with the Ethereum network + +• **networkData**: `NetworkData` + +The network information required to connect to the contracts + +#### Returns + +[`BaseEthersClient`](BaseEthersClient.md) + +#### Source + +[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) + +## Properties + +### networkData + +> **networkData**: `NetworkData` + +#### Source + +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) + +*** + +### runner + +> `protected` **runner**: `ContractRunner` + +#### Source + +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) diff --git a/docs/sdk/typescript/classes/base.BaseEthersClient.md b/docs/sdk/typescript/classes/base.BaseEthersClient.md deleted file mode 100644 index 3bbf22c90a..0000000000 --- a/docs/sdk/typescript/classes/base.BaseEthersClient.md +++ /dev/null @@ -1,76 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [base](../modules/base.md) / BaseEthersClient - -# Class: BaseEthersClient - -[base](../modules/base.md).BaseEthersClient - -## Introduction - -This class is used as a base class for other clients making on-chain calls. - -## Hierarchy - -- **`BaseEthersClient`** - - ↳ [`EscrowClient`](escrow.EscrowClient.md) - - ↳ [`KVStoreClient`](kvstore.KVStoreClient.md) - - ↳ [`StakingClient`](staking.StakingClient.md) - -## Table of contents - -### Constructors - -- [constructor](base.BaseEthersClient.md#constructor) - -### Properties - -- [networkData](base.BaseEthersClient.md#networkdata) -- [runner](base.BaseEthersClient.md#runner) - -## Constructors - -### constructor - -• **new BaseEthersClient**(`runner`, `networkData`): [`BaseEthersClient`](base.BaseEthersClient.md) - -**BaseClient constructor** - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Signer or Provider object to interact with the Ethereum network | -| `networkData` | `NetworkData` | The network information required to connect to the contracts | - -#### Returns - -[`BaseEthersClient`](base.BaseEthersClient.md) - -#### Defined in - -[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/c5bdba8d09572dcd1b7eef0032edf59f6f0b1b0f/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) -[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) - -## Properties - -### networkData - -• **networkData**: `NetworkData` - -#### Defined in - -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c5bdba8d09572dcd1b7eef0032edf59f6f0b1b0f/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) - -___ - -### runner - -• `Protected` **runner**: `ContractRunner` - -#### Defined in - -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c5bdba8d09572dcd1b7eef0032edf59f6f0b1b0f/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) diff --git a/docs/sdk/typescript/classes/operator.OperatorUtils.md b/docs/sdk/typescript/classes/operator.OperatorUtils.md deleted file mode 100644 index fe0b3cd1b8..0000000000 --- a/docs/sdk/typescript/classes/operator.OperatorUtils.md +++ /dev/null @@ -1,163 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [operator](../modules/operator.md) / OperatorUtils - -# Class: OperatorUtils - -[operator](../modules/operator.md).OperatorUtils - -## Table of contents - -### Constructors - -- [constructor](operator.OperatorUtils.md#constructor) - -### Methods - -- [getLeader](operator.OperatorUtils.md#getleader) -- [getLeaders](operator.OperatorUtils.md#getleaders) -- [getReputationNetworkOperators](operator.OperatorUtils.md#getreputationnetworkoperators) -- [getRewards](operator.OperatorUtils.md#getrewards) - -## Constructors - -### constructor - -• **new OperatorUtils**(): [`OperatorUtils`](operator.OperatorUtils.md) - -#### Returns - -[`OperatorUtils`](operator.OperatorUtils.md) - -## Methods - -### getLeader - -▸ **getLeader**(`chainId`, `address`): `Promise`\<`ILeader`\> - -This function returns the leader data for the given address. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `chainId` | `ChainId` | - | -| `address` | `string` | Leader address. | - -#### Returns - -`Promise`\<`ILeader`\> - -Returns the leader details. - -**Code example** - -```ts -import { OperatorUtils, ChainId } from '@human-protocol/sdk'; - -const leader = await OperatorUtils.getLeader(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); -``` - -#### Defined in - -[operator.ts:44](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L44) - -___ - -### getLeaders - -▸ **getLeaders**(`filter`): `Promise`\<`ILeader`[]\> - -This function returns all the leader details of the protocol. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `filter` | `ILeadersFilter` | Filter for the leaders. | - -#### Returns - -`Promise`\<`ILeader`[]\> - -Returns an array with all the leader details. - -**Code example** - -```ts -import { OperatorUtils } from '@human-protocol/sdk'; - -const filter: ILeadersFilter = { - chainId: ChainId.POLYGON -}; -const leaders = await OperatorUtils.getLeaders(filter); -``` - -#### Defined in - -[operator.ts:88](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L88) - -___ - -### getReputationNetworkOperators - -▸ **getReputationNetworkOperators**(`chainId`, `address`, `role?`): `Promise`\<`IOperator`[]\> - -Retrieves the reputation network operators of the specified address. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `chainId` | `ChainId` | - | -| `address` | `string` | Address of the reputation oracle. | -| `role?` | `string` | (Optional) Role of the operator. | - -#### Returns - -`Promise`\<`IOperator`[]\> - -- Returns an array of operator details. - -**`Example`** - -```typescript -import { OperatorUtils, ChainId } from '@human-protocol/sdk'; - -const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); -``` - -#### Defined in - -[operator.ts:132](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L132) - -___ - -### getRewards - -▸ **getRewards**(`chainId`, `slasherAddress`): `Promise`\<`IReward`[]\> - -This function returns information about the rewards for a given slasher address. - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `chainId` | `ChainId` | - | -| `slasherAddress` | `string` | Slasher address. | - -#### Returns - -`Promise`\<`IReward`[]\> - -Returns an array of Reward objects that contain the rewards earned by the user through slashing other users. - -**Code example** - -```ts -import { OperatorUtils, ChainId } from '@human-protocol/sdk'; - -const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); -``` - -#### Defined in - -[operator.ts:174](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L174) diff --git a/docs/sdk/typescript/encryption/README.md b/docs/sdk/typescript/encryption/README.md new file mode 100644 index 0000000000..cd0a892bdb --- /dev/null +++ b/docs/sdk/typescript/encryption/README.md @@ -0,0 +1,14 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / encryption + +# encryption + +## Index + +### Classes + +- [Encryption](classes/Encryption.md) +- [EncryptionUtils](classes/EncryptionUtils.md) diff --git a/docs/sdk/typescript/classes/encryption.Encryption.md b/docs/sdk/typescript/encryption/classes/Encryption.md similarity index 70% rename from docs/sdk/typescript/classes/encryption.Encryption.md rename to docs/sdk/typescript/encryption/classes/Encryption.md index 6d0c2daf4d..4e5c85e07c 100644 --- a/docs/sdk/typescript/classes/encryption.Encryption.md +++ b/docs/sdk/typescript/encryption/classes/Encryption.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [encryption](../modules/encryption.md) / Encryption +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: Encryption +*** + +[@human-protocol/sdk](../../modules.md) / [encryption](../README.md) / Encryption -[encryption](../modules/encryption.md).Encryption +# Class: Encryption ## Introduction @@ -44,69 +46,55 @@ const passphrase = 'example_passphrase'; const encription = await Encryption.build(privateKey, passphrase); ``` -## Table of contents - -### Constructors - -- [constructor](encryption.Encryption.md#constructor) - -### Properties - -- [privateKey](encryption.Encryption.md#privatekey) - -### Methods - -- [decrypt](encryption.Encryption.md#decrypt) -- [sign](encryption.Encryption.md#sign) -- [signAndEncrypt](encryption.Encryption.md#signandencrypt) -- [build](encryption.Encryption.md#build) - ## Constructors -### constructor +### new Encryption() -• **new Encryption**(`privateKey`): [`Encryption`](encryption.Encryption.md) +> **new Encryption**(`privateKey`): [`Encryption`](Encryption.md) Constructor for the Encryption class. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `privateKey` | `PrivateKey` | The private key. | +• **privateKey**: `PrivateKey` + +The private key. #### Returns -[`Encryption`](encryption.Encryption.md) +[`Encryption`](Encryption.md) -#### Defined in +#### Source -[encryption.ts:53](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L53) +[encryption.ts:53](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L53) ## Properties ### privateKey -• `Private` **privateKey**: `PrivateKey` +> `private` **privateKey**: `PrivateKey` -#### Defined in +#### Source -[encryption.ts:46](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L46) +[encryption.ts:46](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L46) ## Methods -### decrypt +### decrypt() -▸ **decrypt**(`message`, `publicKey?`): `Promise`\<`string`\> +> **decrypt**(`message`, `publicKey`?): `Promise`\<`string`\> This function decrypt message message using the private key. In addition, the public key can be added for signature verification. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message to decrypt. | -| `publicKey?` | `string` | Public key used to verify signature if needed. Optional. | +• **message**: `string` + +Message to decrypt. + +• **publicKey?**: `string` + +Public key used to verify signature if needed. Optional. #### Returns @@ -138,23 +126,23 @@ UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv const resultMessage = await encription.decrypt('message'); ``` -#### Defined in +#### Source -[encryption.ts:180](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L180) +[encryption.ts:180](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L180) -___ +*** -### sign +### sign() -▸ **sign**(`message`): `Promise`\<`string`\> +> **sign**(`message`): `Promise`\<`string`\> This function signs a message using the private key used to initialize the client. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message to sign. | +• **message**: `string` + +Message to sign. #### Returns @@ -174,24 +162,27 @@ const encription = await Encryption.build(privateKey, passphrase); const resultMessage = await encription.sign('message'); ``` -#### Defined in +#### Source -[encryption.ts:217](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L217) +[encryption.ts:217](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L217) -___ +*** -### signAndEncrypt +### signAndEncrypt() -▸ **signAndEncrypt**(`message`, `publicKeys`): `Promise`\<`string`\> +> **signAndEncrypt**(`message`, `publicKeys`): `Promise`\<`string`\> This function signs and encrypts a message using the private key used to initialize the client and the specified public keys. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message to sign and encrypt. | -| `publicKeys` | `string`[] | Array of public keys to use for encryption. | +• **message**: `string` + +Message to sign and encrypt. + +• **publicKeys**: `string`[] + +Array of public keys to use for encryption. #### Returns @@ -236,31 +227,34 @@ const publicKeys = [publicKey1, publicKey2]; const resultMessage = await encription.signAndEncrypt('message', publicKeys); ``` -#### Defined in +#### Source -[encryption.ts:129](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L129) +[encryption.ts:129](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L129) -___ +*** -### build +### build() -▸ **build**(`privateKeyArmored`, `passphrase?`): `Promise`\<[`Encryption`](encryption.Encryption.md)\> +> `static` **build**(`privateKeyArmored`, `passphrase`?): `Promise`\<[`Encryption`](Encryption.md)\> Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `privateKeyArmored` | `string` | The encrypted private key in armored format. | -| `passphrase?` | `string` | Optional: The passphrase for the private key. | +• **privateKeyArmored**: `string` + +The encrypted private key in armored format. + +• **passphrase?**: `string` + +Optional: The passphrase for the private key. #### Returns -`Promise`\<[`Encryption`](encryption.Encryption.md)\> +`Promise`\<[`Encryption`](Encryption.md)\> - The Encryption instance. -#### Defined in +#### Source -[encryption.ts:64](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L64) +[encryption.ts:64](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L64) diff --git a/docs/sdk/typescript/classes/encryption.EncryptionUtils.md b/docs/sdk/typescript/encryption/classes/EncryptionUtils.md similarity index 71% rename from docs/sdk/typescript/classes/encryption.EncryptionUtils.md rename to docs/sdk/typescript/encryption/classes/EncryptionUtils.md index ed8fe8d98b..3e4975a765 100644 --- a/docs/sdk/typescript/classes/encryption.EncryptionUtils.md +++ b/docs/sdk/typescript/encryption/classes/EncryptionUtils.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [encryption](../modules/encryption.md) / EncryptionUtils +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: EncryptionUtils +*** + +[@human-protocol/sdk](../../modules.md) / [encryption](../README.md) / EncryptionUtils -[encryption](../modules/encryption.md).EncryptionUtils +# Class: EncryptionUtils ## Introduction @@ -28,44 +30,31 @@ import { EncryptionUtils } from '@human-protocol/sdk'; const keyPair = await EncryptionUtils.generateKeyPair('Human', 'human@hmt.ai'); ``` -## Table of contents - -### Constructors - -- [constructor](encryption.EncryptionUtils.md#constructor) - -### Methods - -- [encrypt](encryption.EncryptionUtils.md#encrypt) -- [generateKeyPair](encryption.EncryptionUtils.md#generatekeypair) -- [getSignedData](encryption.EncryptionUtils.md#getsigneddata) -- [isEncrypted](encryption.EncryptionUtils.md#isencrypted) -- [verify](encryption.EncryptionUtils.md#verify) - ## Constructors -### constructor +### new EncryptionUtils() -• **new EncryptionUtils**(): [`EncryptionUtils`](encryption.EncryptionUtils.md) +> **new EncryptionUtils**(): [`EncryptionUtils`](EncryptionUtils.md) #### Returns -[`EncryptionUtils`](encryption.EncryptionUtils.md) +[`EncryptionUtils`](EncryptionUtils.md) ## Methods -### encrypt +### encrypt() -▸ **encrypt**(`message`, `publicKeys`): `Promise`\<`string`\> +> `static` **encrypt**(`message`, `publicKeys`): `Promise`\<`string`\> This function encrypts a message using the specified public keys. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message to encrypt. | -| `publicKeys` | `string`[] | - | +• **message**: `string` + +Message to encrypt. + +• **publicKeys**: `string`[] #### Returns @@ -106,25 +95,31 @@ const publicKeys = [publicKey1, publicKey2] const result = await EncriptionUtils.encrypt('message', publicKeys); ``` -#### Defined in +#### Source -[encryption.ts:422](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L422) +[encryption.ts:422](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L422) -___ +*** -### generateKeyPair +### generateKeyPair() -▸ **generateKeyPair**(`name`, `email`, `passphrase?`): `Promise`\<`IKeyPair`\> +> `static` **generateKeyPair**(`name`, `email`, `passphrase`): `Promise`\<`IKeyPair`\> This function generates a key pair for encryption and decryption. #### Parameters -| Name | Type | Default value | Description | -| :------ | :------ | :------ | :------ | -| `name` | `string` | `undefined` | Name for the key pair. | -| `email` | `string` | `undefined` | Email for the key pair. | -| `passphrase` | `string` | `''` | Passphrase to encrypt the private key. Optional. | +• **name**: `string` + +Name for the key pair. + +• **email**: `string` + +Email for the key pair. + +• **passphrase**: `string`= `''` + +Passphrase to encrypt the private key. Optional. #### Returns @@ -155,23 +150,23 @@ const passphrase = 'YOUR_PASSPHRASE'; const result = await EncriptionUtils.generateKeyPair(name, email, passphrase); ``` -#### Defined in +#### Source -[encryption.ts:360](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L360) +[encryption.ts:360](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L360) -___ +*** -### getSignedData +### getSignedData() -▸ **getSignedData**(`message`): `Promise`\<`string`\> +> `static` **getSignedData**(`message`): `Promise`\<`string`\> This function gets signed data from a signed message. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message. | +• **message**: `string` + +Message. #### Returns @@ -187,23 +182,23 @@ import { EncryptionUtils } from '@human-protocol/sdk'; const signedData = await EncriptionUtils.getSignedData('message'); ``` -#### Defined in +#### Source -[encryption.ts:317](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L317) +[encryption.ts:317](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L317) -___ +*** -### isEncrypted +### isEncrypted() -▸ **isEncrypted**(`message`): `boolean` +> `static` **isEncrypted**(`message`): `boolean` Verifies if a message appears to be encrypted with OpenPGP. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message to verify. | +• **message**: `string` + +Message to verify. #### Returns @@ -235,24 +230,27 @@ if (isEncrypted) { } ``` -#### Defined in +#### Source -[encryption.ts:471](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L471) +[encryption.ts:471](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L471) -___ +*** -### verify +### verify() -▸ **verify**(`message`, `publicKey`): `Promise`\<`boolean`\> +> `static` **verify**(`message`, `publicKey`): `Promise`\<`boolean`\> This function verifies the signature of a signed message using the public key. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `message` | `string` | Message to verify. | -| `publicKey` | `string` | Public key to verify that the message was sign by a specific source. | +• **message**: `string` + +Message to verify. + +• **publicKey**: `string` + +Public key to verify that the message was sign by a specific source. #### Returns @@ -280,6 +278,6 @@ UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv const result = await EncriptionUtils.verify('message', publicKey); ``` -#### Defined in +#### Source -[encryption.ts:284](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L284) +[encryption.ts:284](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L284) diff --git a/docs/sdk/typescript/escrow/README.md b/docs/sdk/typescript/escrow/README.md new file mode 100644 index 0000000000..b22561f928 --- /dev/null +++ b/docs/sdk/typescript/escrow/README.md @@ -0,0 +1,14 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / escrow + +# escrow + +## Index + +### Classes + +- [EscrowClient](classes/EscrowClient.md) +- [EscrowUtils](classes/EscrowUtils.md) diff --git a/docs/sdk/typescript/classes/escrow.EscrowClient.md b/docs/sdk/typescript/escrow/classes/EscrowClient.md similarity index 62% rename from docs/sdk/typescript/classes/escrow.EscrowClient.md rename to docs/sdk/typescript/escrow/classes/EscrowClient.md index 931d680ead..8d33261f4c 100644 --- a/docs/sdk/typescript/classes/escrow.EscrowClient.md +++ b/docs/sdk/typescript/escrow/classes/EscrowClient.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [escrow](../modules/escrow.md) / EscrowClient +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: EscrowClient +*** + +[@human-protocol/sdk](../../modules.md) / [escrow](../README.md) / EscrowClient -[escrow](../modules/escrow.md).EscrowClient +# Class: EscrowClient ## Introduction @@ -72,130 +74,93 @@ const provider = new providers.JsonRpcProvider(rpcUrl); const escrowClient = await EscrowClient.build(provider); ``` -## Hierarchy - -- [`BaseEthersClient`](base.BaseEthersClient.md) - - ↳ **`EscrowClient`** - -## Table of contents - -### Constructors - -- [constructor](escrow.EscrowClient.md#constructor) - -### Properties - -- [escrowFactoryContract](escrow.EscrowClient.md#escrowfactorycontract) -- [networkData](escrow.EscrowClient.md#networkdata) -- [runner](escrow.EscrowClient.md#runner) - -### Methods +## Extends -- [abort](escrow.EscrowClient.md#abort) -- [addTrustedHandlers](escrow.EscrowClient.md#addtrustedhandlers) -- [bulkPayOut](escrow.EscrowClient.md#bulkpayout) -- [cancel](escrow.EscrowClient.md#cancel) -- [complete](escrow.EscrowClient.md#complete) -- [createAndSetupEscrow](escrow.EscrowClient.md#createandsetupescrow) -- [createEscrow](escrow.EscrowClient.md#createescrow) -- [fund](escrow.EscrowClient.md#fund) -- [getBalance](escrow.EscrowClient.md#getbalance) -- [getEscrowContract](escrow.EscrowClient.md#getescrowcontract) -- [getExchangeOracleAddress](escrow.EscrowClient.md#getexchangeoracleaddress) -- [getFactoryAddress](escrow.EscrowClient.md#getfactoryaddress) -- [getIntermediateResultsUrl](escrow.EscrowClient.md#getintermediateresultsurl) -- [getJobLauncherAddress](escrow.EscrowClient.md#getjoblauncheraddress) -- [getManifestHash](escrow.EscrowClient.md#getmanifesthash) -- [getManifestUrl](escrow.EscrowClient.md#getmanifesturl) -- [getRecordingOracleAddress](escrow.EscrowClient.md#getrecordingoracleaddress) -- [getReputationOracleAddress](escrow.EscrowClient.md#getreputationoracleaddress) -- [getResultsUrl](escrow.EscrowClient.md#getresultsurl) -- [getStatus](escrow.EscrowClient.md#getstatus) -- [getTokenAddress](escrow.EscrowClient.md#gettokenaddress) -- [setup](escrow.EscrowClient.md#setup) -- [storeResults](escrow.EscrowClient.md#storeresults) -- [build](escrow.EscrowClient.md#build) +- [`BaseEthersClient`](../../base/classes/BaseEthersClient.md) ## Constructors -### constructor +### new EscrowClient() -• **new EscrowClient**(`runner`, `networkData`): [`EscrowClient`](escrow.EscrowClient.md) +> **new EscrowClient**(`runner`, `networkData`): [`EscrowClient`](EscrowClient.md) **EscrowClient constructor** #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Runner object to interact with the Ethereum network | -| `networkData` | `NetworkData` | - | +• **runner**: `ContractRunner` + +The Runner object to interact with the Ethereum network + +• **networkData**: `NetworkData` #### Returns -[`EscrowClient`](escrow.EscrowClient.md) +[`EscrowClient`](EscrowClient.md) #### Overrides -[BaseEthersClient](base.BaseEthersClient.md).[constructor](base.BaseEthersClient.md#constructor) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`constructor`](../../base/classes/BaseEthersClient.md#constructors) -#### Defined in +#### Source -[escrow.ts:127](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L127) +[escrow.ts:127](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L127) ## Properties ### escrowFactoryContract -• `Private` **escrowFactoryContract**: `EscrowFactory` +> `private` **escrowFactoryContract**: `EscrowFactory` -#### Defined in +#### Source -[escrow.ts:119](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L119) +[escrow.ts:119](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L119) -___ +*** ### networkData -• **networkData**: `NetworkData` +> **networkData**: `NetworkData` #### Inherited from -[BaseEthersClient](base.BaseEthersClient.md).[networkData](base.BaseEthersClient.md#networkdata) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`networkData`](../../base/classes/BaseEthersClient.md#networkdata) -#### Defined in +#### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) -___ +*** ### runner -• `Protected` **runner**: `ContractRunner` +> `protected` **runner**: `ContractRunner` #### Inherited from -[BaseEthersClient](base.BaseEthersClient.md).[runner](base.BaseEthersClient.md#runner) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`runner`](../../base/classes/BaseEthersClient.md#runner) -#### Defined in +#### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) ## Methods -### abort +### abort() -▸ **abort**(`escrowAddress`, `txOptions?`): `Promise`\<`void`\> +> **abort**(`escrowAddress`, `txOptions`?): `Promise`\<`void`\> This function cancels the specified escrow, sends the balance to the canceler and selfdestructs the escrow contract. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -221,25 +186,31 @@ const escrowClient = await EscrowClient.build(signer); await escrowClient.abort('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:835](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L835) +[escrow.ts:835](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L835) -___ +*** -### addTrustedHandlers +### addTrustedHandlers() -▸ **addTrustedHandlers**(`escrowAddress`, `trustedHandlers`, `txOptions?`): `Promise`\<`void`\> +> **addTrustedHandlers**(`escrowAddress`, `trustedHandlers`, `txOptions`?): `Promise`\<`void`\> This function sets the status of an escrow to completed. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | -| `trustedHandlers` | `string`[] | Array of addresses of trusted handlers to add. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow. + +• **trustedHandlers**: `string`[] + +Array of addresses of trusted handlers to add. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -266,28 +237,43 @@ const trustedHandlers = ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6 await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309f', trustedHandlers); ``` -#### Defined in +#### Source -[escrow.ts:883](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L883) +[escrow.ts:883](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L883) -___ +*** -### bulkPayOut +### bulkPayOut() -▸ **bulkPayOut**(`escrowAddress`, `recipients`, `amounts`, `finalResultsUrl`, `finalResultsHash`, `txOptions?`): `Promise`\<`void`\> +> **bulkPayOut**(`escrowAddress`, `recipients`, `amounts`, `finalResultsUrl`, `finalResultsHash`, `txOptions`?): `Promise`\<`void`\> This function pays out the amounts specified to the workers and sets the URL of the final results file. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Escrow address to payout. | -| `recipients` | `string`[] | Array of recipient addresses. | -| `amounts` | `bigint`[] | Array of amounts the recipients will receive. | -| `finalResultsUrl` | `string` | Final results file url. | -| `finalResultsHash` | `string` | Final results file hash. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Escrow address to payout. + +• **recipients**: `string`[] + +Array of recipient addresses. + +• **amounts**: `bigint`[] + +Array of amounts the recipients will receive. + +• **finalResultsUrl**: `string` + +Final results file url. + +• **finalResultsHash**: `string` + +Final results file hash. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -318,24 +304,27 @@ const resultsHash'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079'; await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', recipients, amounts, resultsUrl, resultsHash); ``` -#### Defined in +#### Source -[escrow.ts:648](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L648) +[escrow.ts:648](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L648) -___ +*** -### cancel +### cancel() -▸ **cancel**(`escrowAddress`, `txOptions?`): `Promise`\<`EscrowCancel`\> +> **cancel**(`escrowAddress`, `txOptions`?): `Promise`\<`EscrowCancel`\> This function cancels the specified escrow and sends the balance to the canceler. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow to cancel. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow to cancel. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -361,24 +350,27 @@ const escrowClient = await EscrowClient.build(signer); await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:751](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L751) +[escrow.ts:751](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L751) -___ +*** -### complete +### complete() -▸ **complete**(`escrowAddress`, `txOptions?`): `Promise`\<`void`\> +> **complete**(`escrowAddress`, `txOptions`?): `Promise`\<`void`\> This function sets the status of an escrow to completed. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -404,26 +396,35 @@ const escrowClient = await EscrowClient.build(signer); await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:590](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L590) +[escrow.ts:590](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L590) -___ +*** -### createAndSetupEscrow +### createAndSetupEscrow() -▸ **createAndSetupEscrow**(`tokenAddress`, `trustedHandlers`, `jobRequesterId`, `escrowConfig`): `Promise`\<`string`\> +> **createAndSetupEscrow**(`tokenAddress`, `trustedHandlers`, `jobRequesterId`, `escrowConfig`): `Promise`\<`string`\> This function creates and sets up an escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `tokenAddress` | `string` | Token address to use for pay outs. | -| `trustedHandlers` | `string`[] | Array of addresses that can perform actions on the contract. | -| `jobRequesterId` | `string` | Job Requester Id | -| `escrowConfig` | `IEscrowConfig` | Configuration object with escrow settings. | +• **tokenAddress**: `string` + +Token address to use for pay outs. + +• **trustedHandlers**: `string`[] + +Array of addresses that can perform actions on the contract. + +• **jobRequesterId**: `string` + +Job Requester Id + +• **escrowConfig**: `IEscrowConfig` + +Configuration object with escrow settings. #### Returns @@ -462,26 +463,35 @@ const escrowConfig = { const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trustedHandlers, jobRequesterId, escrowConfig); ``` -#### Defined in +#### Source -[escrow.ts:413](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L413) +[escrow.ts:413](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L413) -___ +*** -### createEscrow +### createEscrow() -▸ **createEscrow**(`tokenAddress`, `trustedHandlers`, `jobRequesterId`, `txOptions?`): `Promise`\<`string`\> +> **createEscrow**(`tokenAddress`, `trustedHandlers`, `jobRequesterId`, `txOptions`?): `Promise`\<`string`\> This function creates an escrow contract that uses the token passed to pay oracle fees and reward workers. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `tokenAddress` | `string` | Token address to use for pay outs. | -| `trustedHandlers` | `string`[] | Array of addresses that can perform actions on the contract. | -| `jobRequesterId` | `string` | Job Requester Id | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **tokenAddress**: `string` + +Token address to use for pay outs. + +• **trustedHandlers**: `string`[] + +Array of addresses that can perform actions on the contract. + +• **jobRequesterId**: `string` + +Job Requester Id + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -510,25 +520,31 @@ const jobRequesterId = "job-requester-id"; const escrowAddress = await escrowClient.createEscrow(tokenAddress, trustedHandlers, jobRequesterId); ``` -#### Defined in +#### Source -[escrow.ts:207](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L207) +[escrow.ts:207](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L207) -___ +*** -### fund +### fund() -▸ **fund**(`escrowAddress`, `amount`, `txOptions?`): `Promise`\<`void`\> +> **fund**(`escrowAddress`, `amount`, `txOptions`?): `Promise`\<`void`\> This function adds funds of the chosen token to the escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow to fund. | -| `amount` | `bigint` | Amount to be added as funds. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow to fund. + +• **amount**: `bigint` + +Amount to be added as funds. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -553,23 +569,23 @@ const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount); ``` -#### Defined in +#### Source -[escrow.ts:461](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L461) +[escrow.ts:461](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L461) -___ +*** -### getBalance +### getBalance() -▸ **getBalance**(`escrowAddress`): `Promise`\<`bigint`\> +> **getBalance**(`escrowAddress`): `Promise`\<`bigint`\> This function returns the balance for a specified escrow address. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -591,45 +607,45 @@ const escrowClient = await EscrowClient.build(signer); const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:938](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L938) +[escrow.ts:938](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L938) -___ +*** -### getEscrowContract +### getEscrowContract() -▸ **getEscrowContract**(`escrowAddress`): `Escrow` +> `private` **getEscrowContract**(`escrowAddress`): `Escrow` Connects to the escrow contract #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Escrow address to connect to | +• **escrowAddress**: `string` + +Escrow address to connect to #### Returns `Escrow` -#### Defined in +#### Source -[escrow.ts:167](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L167) +[escrow.ts:167](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L167) -___ +*** -### getExchangeOracleAddress +### getExchangeOracleAddress() -▸ **getExchangeOracleAddress**(`escrowAddress`): `Promise`\<`string`\> +> **getExchangeOracleAddress**(`escrowAddress`): `Promise`\<`string`\> This function returns the exchange oracle address for a given escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -651,23 +667,23 @@ const escrowClient = await EscrowClient.build(signer); const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1318](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1318) +[escrow.ts:1318](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1318) -___ +*** -### getFactoryAddress +### getFactoryAddress() -▸ **getFactoryAddress**(`escrowAddress`): `Promise`\<`string`\> +> **getFactoryAddress**(`escrowAddress`): `Promise`\<`string`\> This function returns the escrow factory address for a given escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -689,23 +705,23 @@ const escrowClient = await EscrowClient.build(signer); const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1356](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1356) +[escrow.ts:1356](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1356) -___ +*** -### getIntermediateResultsUrl +### getIntermediateResultsUrl() -▸ **getIntermediateResultsUrl**(`escrowAddress`): `Promise`\<`string`\> +> **getIntermediateResultsUrl**(`escrowAddress`): `Promise`\<`string`\> This function returns the intermediate results file URL. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -727,23 +743,23 @@ const escrowClient = await EscrowClient.build(signer); const intemediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1090](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1090) +[escrow.ts:1090](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1090) -___ +*** -### getJobLauncherAddress +### getJobLauncherAddress() -▸ **getJobLauncherAddress**(`escrowAddress`): `Promise`\<`string`\> +> **getJobLauncherAddress**(`escrowAddress`): `Promise`\<`string`\> This function returns the job launcher address for a given escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -765,23 +781,23 @@ const escrowClient = await EscrowClient.build(signer); const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1242](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1242) +[escrow.ts:1242](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1242) -___ +*** -### getManifestHash +### getManifestHash() -▸ **getManifestHash**(`escrowAddress`): `Promise`\<`string`\> +> **getManifestHash**(`escrowAddress`): `Promise`\<`string`\> This function returns the manifest file hash. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -803,23 +819,23 @@ const escrowClient = await EscrowClient.build(signer); const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:976](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L976) +[escrow.ts:976](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L976) -___ +*** -### getManifestUrl +### getManifestUrl() -▸ **getManifestUrl**(`escrowAddress`): `Promise`\<`string`\> +> **getManifestUrl**(`escrowAddress`): `Promise`\<`string`\> This function returns the manifest file URL. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -841,23 +857,23 @@ const escrowClient = await EscrowClient.build(signer); const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1014](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1014) +[escrow.ts:1014](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1014) -___ +*** -### getRecordingOracleAddress +### getRecordingOracleAddress() -▸ **getRecordingOracleAddress**(`escrowAddress`): `Promise`\<`string`\> +> **getRecordingOracleAddress**(`escrowAddress`): `Promise`\<`string`\> This function returns the recording oracle address for a given escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -879,23 +895,23 @@ const escrowClient = await EscrowClient.build(signer); const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1204](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1204) +[escrow.ts:1204](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1204) -___ +*** -### getReputationOracleAddress +### getReputationOracleAddress() -▸ **getReputationOracleAddress**(`escrowAddress`): `Promise`\<`string`\> +> **getReputationOracleAddress**(`escrowAddress`): `Promise`\<`string`\> This function returns the reputation oracle address for a given escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -917,23 +933,23 @@ const escrowClient = await EscrowClient.build(signer); const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1280](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1280) +[escrow.ts:1280](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1280) -___ +*** -### getResultsUrl +### getResultsUrl() -▸ **getResultsUrl**(`escrowAddress`): `Promise`\<`string`\> +> **getResultsUrl**(`escrowAddress`): `Promise`\<`string`\> This function returns the results file URL. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -955,23 +971,23 @@ const escrowClient = await EscrowClient.build(signer); const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1052](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1052) +[escrow.ts:1052](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1052) -___ +*** -### getStatus +### getStatus() -▸ **getStatus**(`escrowAddress`): `Promise`\<`EscrowStatus`\> +> **getStatus**(`escrowAddress`): `Promise`\<`EscrowStatus`\> This function returns the current status of the escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -993,23 +1009,23 @@ const escrowClient = await EscrowClient.build(signer); const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1166](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1166) +[escrow.ts:1166](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1166) -___ +*** -### getTokenAddress +### getTokenAddress() -▸ **getTokenAddress**(`escrowAddress`): `Promise`\<`string`\> +> **getTokenAddress**(`escrowAddress`): `Promise`\<`string`\> This function returns the token address used for funding the escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | +• **escrowAddress**: `string` + +Address of the escrow. #### Returns @@ -1031,25 +1047,31 @@ const escrowClient = await EscrowClient.build(signer); const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[escrow.ts:1128](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1128) +[escrow.ts:1128](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1128) -___ +*** -### setup +### setup() -▸ **setup**(`escrowAddress`, `escrowConfig`, `txOptions?`): `Promise`\<`void`\> +> **setup**(`escrowAddress`, `escrowConfig`, `txOptions`?): `Promise`\<`void`\> This function sets up the parameters of the escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow to set up. | -| `escrowConfig` | `IEscrowConfig` | Escrow configuration parameters. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow to set up. + +• **escrowConfig**: `IEscrowConfig` + +Escrow configuration parameters. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -1086,26 +1108,35 @@ const escrowConfig = { await escrowClient.setup(escrowAddress, escrowConfig); ``` -#### Defined in +#### Source -[escrow.ts:288](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L288) +[escrow.ts:288](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L288) -___ +*** -### storeResults +### storeResults() -▸ **storeResults**(`escrowAddress`, `url`, `hash`, `txOptions?`): `Promise`\<`void`\> +> **storeResults**(`escrowAddress`, `url`, `hash`, `txOptions`?): `Promise`\<`void`\> This function stores the results url and hash. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow. | -| `url` | `string` | Results file url. | -| `hash` | `string` | Results file hash. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow. + +• **url**: `string` + +Results file url. + +• **hash**: `string` + +Results file hash. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -1131,38 +1162,38 @@ const escrowClient = await EscrowClient.build(signer); await storeResults.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'http://localhost/results.json', 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079'); ``` -#### Defined in +#### Source -[escrow.ts:526](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L526) +[escrow.ts:526](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L526) -___ +*** -### build +### build() -▸ **build**(`runner`): `Promise`\<[`EscrowClient`](escrow.EscrowClient.md)\> +> `static` **build**(`runner`): `Promise`\<[`EscrowClient`](EscrowClient.md)\> Creates an instance of EscrowClient from a Runner. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Runner object to interact with the Ethereum network | +• **runner**: `ContractRunner` + +The Runner object to interact with the Ethereum network #### Returns -`Promise`\<[`EscrowClient`](escrow.EscrowClient.md)\> +`Promise`\<[`EscrowClient`](EscrowClient.md)\> An instance of EscrowClient -**`Throws`** +#### Throws Thrown if the provider does not exist for the provided Signer -**`Throws`** +#### Throws Thrown if the network's chainId is not supported -#### Defined in +#### Source -[escrow.ts:145](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L145) +[escrow.ts:145](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L145) diff --git a/docs/sdk/typescript/classes/escrow.EscrowUtils.md b/docs/sdk/typescript/escrow/classes/EscrowUtils.md similarity index 77% rename from docs/sdk/typescript/classes/escrow.EscrowUtils.md rename to docs/sdk/typescript/escrow/classes/EscrowUtils.md index 00259f6744..5ade7ff16f 100644 --- a/docs/sdk/typescript/classes/escrow.EscrowUtils.md +++ b/docs/sdk/typescript/escrow/classes/EscrowUtils.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [escrow](../modules/escrow.md) / EscrowUtils +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: EscrowUtils +*** + +[@human-protocol/sdk](../../modules.md) / [escrow](../README.md) / EscrowUtils -[escrow](../modules/escrow.md).EscrowUtils +# Class: EscrowUtils ## Introduction @@ -34,32 +36,21 @@ const escrowAddresses = new EscrowUtils.getEscrows({ }); ``` -## Table of contents - -### Constructors - -- [constructor](escrow.EscrowUtils.md#constructor) - -### Methods - -- [getEscrow](escrow.EscrowUtils.md#getescrow) -- [getEscrows](escrow.EscrowUtils.md#getescrows) - ## Constructors -### constructor +### new EscrowUtils() -• **new EscrowUtils**(): [`EscrowUtils`](escrow.EscrowUtils.md) +> **new EscrowUtils**(): [`EscrowUtils`](EscrowUtils.md) #### Returns -[`EscrowUtils`](escrow.EscrowUtils.md) +[`EscrowUtils`](EscrowUtils.md) ## Methods -### getEscrow +### getEscrow() -▸ **getEscrow**(`chainId`, `escrowAddress`): `Promise`\<`EscrowData`\> +> `static` **getEscrow**(`chainId`, `escrowAddress`): `Promise`\<`EscrowData`\> This function returns the escrow data for a given address. @@ -117,10 +108,13 @@ type EscrowData = { #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `chainId` | `ChainId` | Network in which the escrow has been deployed | -| `escrowAddress` | `string` | Address of the escrow | +• **chainId**: `ChainId` + +Network in which the escrow has been deployed + +• **escrowAddress**: `string` + +Address of the escrow #### Returns @@ -136,15 +130,15 @@ import { ChainId, EscrowUtils } from '@human-protocol/sdk'; const escrowData = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890"); ``` -#### Defined in +#### Source -[escrow.ts:1633](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1633) +[escrow.ts:1633](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1633) -___ +*** -### getEscrows +### getEscrows() -▸ **getEscrows**(`filter`): `Promise`\<`EscrowData`[]\> +> `static` **getEscrows**(`filter`): `Promise`\<`EscrowData`[]\> This function returns an array of escrows based on the specified filter parameters. @@ -226,9 +220,9 @@ type EscrowData = { #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `filter` | `IEscrowsFilter` | Filter parameters. | +• **filter**: `IEscrowsFilter` + +Filter parameters. #### Returns @@ -250,6 +244,6 @@ const filters: IEscrowsFilter = { const escrowDatas = await EscrowUtils.getEscrows(filters); ``` -#### Defined in +#### Source -[escrow.ts:1505](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1505) +[escrow.ts:1505](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1505) diff --git a/docs/sdk/typescript/kvstore/README.md b/docs/sdk/typescript/kvstore/README.md new file mode 100644 index 0000000000..aa3066f2ed --- /dev/null +++ b/docs/sdk/typescript/kvstore/README.md @@ -0,0 +1,13 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / kvstore + +# kvstore + +## Index + +### Classes + +- [KVStoreClient](classes/KVStoreClient.md) diff --git a/docs/sdk/typescript/classes/kvstore.KVStoreClient.md b/docs/sdk/typescript/kvstore/classes/KVStoreClient.md similarity index 60% rename from docs/sdk/typescript/classes/kvstore.KVStoreClient.md rename to docs/sdk/typescript/kvstore/classes/KVStoreClient.md index a62972e610..f84d084807 100644 --- a/docs/sdk/typescript/classes/kvstore.KVStoreClient.md +++ b/docs/sdk/typescript/kvstore/classes/KVStoreClient.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [kvstore](../modules/kvstore.md) / KVStoreClient +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: KVStoreClient +*** + +[@human-protocol/sdk](../../modules.md) / [kvstore](../README.md) / KVStoreClient -[kvstore](../modules/kvstore.md).KVStoreClient +# Class: KVStoreClient ## Introduction @@ -72,113 +74,93 @@ const provider = new providers.JsonRpcProvider(rpcUrl); const kvstoreClient = await KVStoreClient.build(signer); ``` -## Hierarchy - -- [`BaseEthersClient`](base.BaseEthersClient.md) - - ↳ **`KVStoreClient`** - -## Table of contents - -### Constructors - -- [constructor](kvstore.KVStoreClient.md#constructor) - -### Properties - -- [contract](kvstore.KVStoreClient.md#contract) -- [networkData](kvstore.KVStoreClient.md#networkdata) -- [runner](kvstore.KVStoreClient.md#runner) +## Extends -### Methods - -- [get](kvstore.KVStoreClient.md#get) -- [getFileUrlAndVerifyHash](kvstore.KVStoreClient.md#getfileurlandverifyhash) -- [getPublicKey](kvstore.KVStoreClient.md#getpublickey) -- [set](kvstore.KVStoreClient.md#set) -- [setBulk](kvstore.KVStoreClient.md#setbulk) -- [setFileUrlAndHash](kvstore.KVStoreClient.md#setfileurlandhash) -- [build](kvstore.KVStoreClient.md#build) +- [`BaseEthersClient`](../../base/classes/BaseEthersClient.md) ## Constructors -### constructor +### new KVStoreClient() -• **new KVStoreClient**(`runner`, `networkData`): [`KVStoreClient`](kvstore.KVStoreClient.md) +> **new KVStoreClient**(`runner`, `networkData`): [`KVStoreClient`](KVStoreClient.md) **KVStoreClient constructor** #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Runner object to interact with the Ethereum network | -| `networkData` | `NetworkData` | - | +• **runner**: `ContractRunner` + +The Runner object to interact with the Ethereum network + +• **networkData**: `NetworkData` #### Returns -[`KVStoreClient`](kvstore.KVStoreClient.md) +[`KVStoreClient`](KVStoreClient.md) #### Overrides -[BaseEthersClient](base.BaseEthersClient.md).[constructor](base.BaseEthersClient.md#constructor) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`constructor`](../../base/classes/BaseEthersClient.md#constructors) -#### Defined in +#### Source -[kvstore.ts:100](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L100) +[kvstore.ts:100](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L100) ## Properties ### contract -• `Private` **contract**: `KVStore` +> `private` **contract**: `KVStore` -#### Defined in +#### Source -[kvstore.ts:92](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L92) +[kvstore.ts:92](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L92) -___ +*** ### networkData -• **networkData**: `NetworkData` +> **networkData**: `NetworkData` #### Inherited from -[BaseEthersClient](base.BaseEthersClient.md).[networkData](base.BaseEthersClient.md#networkdata) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`networkData`](../../base/classes/BaseEthersClient.md#networkdata) -#### Defined in +#### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) -___ +*** ### runner -• `Protected` **runner**: `ContractRunner` +> `protected` **runner**: `ContractRunner` #### Inherited from -[BaseEthersClient](base.BaseEthersClient.md).[runner](base.BaseEthersClient.md#runner) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`runner`](../../base/classes/BaseEthersClient.md#runner) -#### Defined in +#### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) ## Methods -### get +### get() -▸ **get**(`address`, `key`): `Promise`\<`string`\> +> **get**(`address`, `key`): `Promise`\<`string`\> Gets the value of a key-value pair in the contract. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `address` | `string` | Address from which to get the key value. | -| `key` | `string` | Key to obtain the value. | +• **address**: `string` + +Address from which to get the key value. + +• **key**: `string` + +Key to obtain the value. #### Returns @@ -202,24 +184,27 @@ const kvstoreClient = await KVStoreClient.build(provider); const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role'); ``` -#### Defined in +#### Source -[kvstore.ts:301](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L301) +[kvstore.ts:301](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L301) -___ +*** -### getFileUrlAndVerifyHash +### getFileUrlAndVerifyHash() -▸ **getFileUrlAndVerifyHash**(`address`, `urlKey?`): `Promise`\<`string`\> +> **getFileUrlAndVerifyHash**(`address`, `urlKey`): `Promise`\<`string`\> Gets the URL value of the given entity, and verify its hash. #### Parameters -| Name | Type | Default value | Description | -| :------ | :------ | :------ | :------ | -| `address` | `string` | `undefined` | Address from which to get the URL value. | -| `urlKey` | `string` | `'url'` | Configurable URL key. `url` by default. | +• **address**: `string` + +Address from which to get the URL value. + +• **urlKey**: `string`= `'url'` + +Configurable URL key. `url` by default. #### Returns @@ -245,23 +230,23 @@ const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash( ); ``` -#### Defined in +#### Source -[kvstore.ts:340](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L340) +[kvstore.ts:340](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L340) -___ +*** -### getPublicKey +### getPublicKey() -▸ **getPublicKey**(`address`): `Promise`\<`string`\> +> **getPublicKey**(`address`): `Promise`\<`string`\> Gets the public key of the given entity, and verify its hash. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `address` | `string` | Address from which to get the public key. | +• **address**: `string` + +Address from which to get the public key. #### Returns @@ -283,25 +268,31 @@ const kvstoreClient = await KVStoreClient.build(provider); const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'); ``` -#### Defined in +#### Source -[kvstore.ts:398](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L398) +[kvstore.ts:398](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L398) -___ +*** -### set +### set() -▸ **set**(`key`, `value`, `txOptions?`): `Promise`\<`void`\> +> **set**(`key`, `value`, `txOptions`?): `Promise`\<`void`\> This function sets a key-value pair associated with the address that submits the transaction. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `key` | `string` | Key of the key-value pair | -| `value` | `string` | Value of the key-value pair | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **key**: `string` + +Key of the key-value pair + +• **value**: `string` + +Value of the key-value pair + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -327,25 +318,31 @@ const kvstoreClient = await KVStoreClient.build(signer); await kvstoreClient.set('Role', 'RecordingOracle'); ``` -#### Defined in +#### Source -[kvstore.ts:163](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L163) +[kvstore.ts:163](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L163) -___ +*** -### setBulk +### setBulk() -▸ **setBulk**(`keys`, `values`, `txOptions?`): `Promise`\<`void`\> +> **setBulk**(`keys`, `values`, `txOptions`?): `Promise`\<`void`\> This function sets key-value pairs in bulk associated with the address that submits the transaction. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `keys` | `string`[] | Array of keys (keys and value must have the same order) | -| `values` | `string`[] | Array of values | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **keys**: `string`[] + +Array of keys (keys and value must have the same order) + +• **values**: `string`[] + +Array of values + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -373,25 +370,31 @@ const values = ['RecordingOracle', 'http://localhost']; await kvstoreClient.set(keys, values); ``` -#### Defined in +#### Source -[kvstore.ts:206](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L206) +[kvstore.ts:206](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L206) -___ +*** -### setFileUrlAndHash +### setFileUrlAndHash() -▸ **setFileUrlAndHash**(`url`, `urlKey?`, `txOptions?`): `Promise`\<`void`\> +> **setFileUrlAndHash**(`url`, `urlKey`, `txOptions`?): `Promise`\<`void`\> Sets a URL value for the address that submits the transaction, and its hash. #### Parameters -| Name | Type | Default value | Description | -| :------ | :------ | :------ | :------ | -| `url` | `string` | `undefined` | URL to set | -| `urlKey` | `string` | `'url'` | Configurable URL key. `url` by default. | -| `txOptions?` | `Overrides` | `{}` | Additional transaction parameters (optional, defaults to an empty object). | +• **url**: `string` + +URL to set + +• **urlKey**: `string`= `'url'` + +Configurable URL key. `url` by default. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -416,38 +419,38 @@ await kvstoreClient.setFileUrlAndHash('example.com'); await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url); ``` -#### Defined in +#### Source -[kvstore.ts:249](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L249) +[kvstore.ts:249](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L249) -___ +*** -### build +### build() -▸ **build**(`runner`): `Promise`\<[`KVStoreClient`](kvstore.KVStoreClient.md)\> +> `static` **build**(`runner`): `Promise`\<[`KVStoreClient`](KVStoreClient.md)\> Creates an instance of KVStoreClient from a runner. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Runner object to interact with the Ethereum network | +• **runner**: `ContractRunner` + +The Runner object to interact with the Ethereum network #### Returns -`Promise`\<[`KVStoreClient`](kvstore.KVStoreClient.md)\> +`Promise`\<[`KVStoreClient`](KVStoreClient.md)\> - An instance of KVStoreClient -**`Throws`** +#### Throws - Thrown if the provider does not exist for the provided Signer -**`Throws`** +#### Throws - Thrown if the network's chainId is not supported -#### Defined in +#### Source -[kvstore.ts:118](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L118) +[kvstore.ts:118](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L118) diff --git a/docs/sdk/typescript/modules.md b/docs/sdk/typescript/modules.md index 20a36584ad..acfa859a25 100644 --- a/docs/sdk/typescript/modules.md +++ b/docs/sdk/typescript/modules.md @@ -1,16 +1,16 @@ -[@human-protocol/sdk](README.md) / Modules +[**@human-protocol/sdk**](README.md) • **Docs** -# @human-protocol/sdk +*** -## Table of contents +# @human-protocol/sdk -### Modules +## Modules -- [base](modules/base.md) -- [encryption](modules/encryption.md) -- [escrow](modules/escrow.md) -- [kvstore](modules/kvstore.md) -- [operator](modules/operator.md) -- [staking](modules/staking.md) -- [statistics](modules/statistics.md) -- [storage](modules/storage.md) +- [base](base/README.md) +- [encryption](encryption/README.md) +- [escrow](escrow/README.md) +- [kvstore](kvstore/README.md) +- [operator](operator/README.md) +- [staking](staking/README.md) +- [statistics](statistics/README.md) +- [storage](storage/README.md) diff --git a/docs/sdk/typescript/modules/base.md b/docs/sdk/typescript/modules/base.md deleted file mode 100644 index b5c39bcd06..0000000000 --- a/docs/sdk/typescript/modules/base.md +++ /dev/null @@ -1,9 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / base - -# Module: base - -## Table of contents - -### Classes - -- [BaseEthersClient](../classes/base.BaseEthersClient.md) diff --git a/docs/sdk/typescript/modules/encryption.md b/docs/sdk/typescript/modules/encryption.md deleted file mode 100644 index df3b0376b8..0000000000 --- a/docs/sdk/typescript/modules/encryption.md +++ /dev/null @@ -1,10 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / encryption - -# Module: encryption - -## Table of contents - -### Classes - -- [Encryption](../classes/encryption.Encryption.md) -- [EncryptionUtils](../classes/encryption.EncryptionUtils.md) diff --git a/docs/sdk/typescript/modules/escrow.md b/docs/sdk/typescript/modules/escrow.md deleted file mode 100644 index c6c2b293e7..0000000000 --- a/docs/sdk/typescript/modules/escrow.md +++ /dev/null @@ -1,10 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / escrow - -# Module: escrow - -## Table of contents - -### Classes - -- [EscrowClient](../classes/escrow.EscrowClient.md) -- [EscrowUtils](../classes/escrow.EscrowUtils.md) diff --git a/docs/sdk/typescript/modules/kvstore.md b/docs/sdk/typescript/modules/kvstore.md deleted file mode 100644 index 5a551b3bc9..0000000000 --- a/docs/sdk/typescript/modules/kvstore.md +++ /dev/null @@ -1,9 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / kvstore - -# Module: kvstore - -## Table of contents - -### Classes - -- [KVStoreClient](../classes/kvstore.KVStoreClient.md) diff --git a/docs/sdk/typescript/modules/operator.md b/docs/sdk/typescript/modules/operator.md deleted file mode 100644 index 711d7da936..0000000000 --- a/docs/sdk/typescript/modules/operator.md +++ /dev/null @@ -1,9 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / operator - -# Module: operator - -## Table of contents - -### Classes - -- [OperatorUtils](../classes/operator.OperatorUtils.md) diff --git a/docs/sdk/typescript/modules/staking.md b/docs/sdk/typescript/modules/staking.md deleted file mode 100644 index f9dffc58aa..0000000000 --- a/docs/sdk/typescript/modules/staking.md +++ /dev/null @@ -1,9 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / staking - -# Module: staking - -## Table of contents - -### Classes - -- [StakingClient](../classes/staking.StakingClient.md) diff --git a/docs/sdk/typescript/modules/statistics.md b/docs/sdk/typescript/modules/statistics.md deleted file mode 100644 index e32abbb74f..0000000000 --- a/docs/sdk/typescript/modules/statistics.md +++ /dev/null @@ -1,9 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / statistics - -# Module: statistics - -## Table of contents - -### Classes - -- [StatisticsClient](../classes/statistics.StatisticsClient.md) diff --git a/docs/sdk/typescript/modules/storage.md b/docs/sdk/typescript/modules/storage.md deleted file mode 100644 index 39a127fbc7..0000000000 --- a/docs/sdk/typescript/modules/storage.md +++ /dev/null @@ -1,9 +0,0 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / storage - -# Module: storage - -## Table of contents - -### Classes - -- [StorageClient](../classes/storage.StorageClient.md) diff --git a/docs/sdk/typescript/operator/README.md b/docs/sdk/typescript/operator/README.md new file mode 100644 index 0000000000..2e8bce74ed --- /dev/null +++ b/docs/sdk/typescript/operator/README.md @@ -0,0 +1,13 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / operator + +# operator + +## Index + +### Classes + +- [OperatorUtils](classes/OperatorUtils.md) diff --git a/docs/sdk/typescript/operator/classes/OperatorUtils.md b/docs/sdk/typescript/operator/classes/OperatorUtils.md new file mode 100644 index 0000000000..d8caea3f1f --- /dev/null +++ b/docs/sdk/typescript/operator/classes/OperatorUtils.md @@ -0,0 +1,158 @@ +[**@human-protocol/sdk**](../../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../../modules.md) / [operator](../README.md) / OperatorUtils + +# Class: OperatorUtils + +## Constructors + +### new OperatorUtils() + +> **new OperatorUtils**(): [`OperatorUtils`](OperatorUtils.md) + +#### Returns + +[`OperatorUtils`](OperatorUtils.md) + +## Methods + +### getLeader() + +> `static` **getLeader**(`chainId`, `address`): `Promise`\<`ILeader`\> + +This function returns the leader data for the given address. + +#### Parameters + +• **chainId**: `ChainId` + +• **address**: `string` + +Leader address. + +#### Returns + +`Promise`\<`ILeader`\> + +Returns the leader details. + +**Code example** + +```ts +import { OperatorUtils, ChainId } from '@human-protocol/sdk'; + +const leader = await OperatorUtils.getLeader(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); +``` + +#### Source + +[operator.ts:44](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L44) + +*** + +### getLeaders() + +> `static` **getLeaders**(`filter`): `Promise`\<`ILeader`[]\> + +This function returns all the leader details of the protocol. + +#### Parameters + +• **filter**: `ILeadersFilter` + +Filter for the leaders. + +#### Returns + +`Promise`\<`ILeader`[]\> + +Returns an array with all the leader details. + +**Code example** + +```ts +import { OperatorUtils } from '@human-protocol/sdk'; + +const filter: ILeadersFilter = { + chainId: ChainId.POLYGON +}; +const leaders = await OperatorUtils.getLeaders(filter); +``` + +#### Source + +[operator.ts:99](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L99) + +*** + +### getReputationNetworkOperators() + +> `static` **getReputationNetworkOperators**(`chainId`, `address`, `role`?): `Promise`\<`IOperator`[]\> + +Retrieves the reputation network operators of the specified address. + +#### Parameters + +• **chainId**: `ChainId` + +• **address**: `string` + +Address of the reputation oracle. + +• **role?**: `string` + +(Optional) Role of the operator. + +#### Returns + +`Promise`\<`IOperator`[]\> + +- Returns an array of operator details. + +#### Example + +```typescript +import { OperatorUtils, ChainId } from '@human-protocol/sdk'; + +const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); +``` + +#### Source + +[operator.ts:159](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L159) + +*** + +### getRewards() + +> `static` **getRewards**(`chainId`, `slasherAddress`): `Promise`\<`IReward`[]\> + +This function returns information about the rewards for a given slasher address. + +#### Parameters + +• **chainId**: `ChainId` + +• **slasherAddress**: `string` + +Slasher address. + +#### Returns + +`Promise`\<`IReward`[]\> + +Returns an array of Reward objects that contain the rewards earned by the user through slashing other users. + +**Code example** + +```ts +import { OperatorUtils, ChainId } from '@human-protocol/sdk'; + +const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); +``` + +#### Source + +[operator.ts:211](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L211) diff --git a/docs/sdk/typescript/staking/README.md b/docs/sdk/typescript/staking/README.md new file mode 100644 index 0000000000..b32a13ff45 --- /dev/null +++ b/docs/sdk/typescript/staking/README.md @@ -0,0 +1,13 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / staking + +# staking + +## Index + +### Classes + +- [StakingClient](classes/StakingClient.md) diff --git a/docs/sdk/typescript/classes/staking.StakingClient.md b/docs/sdk/typescript/staking/classes/StakingClient.md similarity index 60% rename from docs/sdk/typescript/classes/staking.StakingClient.md rename to docs/sdk/typescript/staking/classes/StakingClient.md index 8223477c8e..b41bfdd2dd 100644 --- a/docs/sdk/typescript/classes/staking.StakingClient.md +++ b/docs/sdk/typescript/staking/classes/StakingClient.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [staking](../modules/staking.md) / StakingClient +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: StakingClient +*** + +[@human-protocol/sdk](../../modules.md) / [staking](../README.md) / StakingClient -[staking](../modules/staking.md).StakingClient +# Class: StakingClient ## Introduction @@ -72,141 +74,111 @@ const provider = new providers.JsonRpcProvider(rpcUrl); const stakingClient = await StakingClient.build(provider); ``` -## Hierarchy - -- [`BaseEthersClient`](base.BaseEthersClient.md) - - ↳ **`StakingClient`** - -## Table of contents +## Extends -### Constructors - -- [constructor](staking.StakingClient.md#constructor) - -### Properties - -- [escrowFactoryContract](staking.StakingClient.md#escrowfactorycontract) -- [networkData](staking.StakingClient.md#networkdata) -- [rewardPoolContract](staking.StakingClient.md#rewardpoolcontract) -- [runner](staking.StakingClient.md#runner) -- [stakingContract](staking.StakingClient.md#stakingcontract) -- [tokenContract](staking.StakingClient.md#tokencontract) - -### Methods - -- [allocate](staking.StakingClient.md#allocate) -- [approveStake](staking.StakingClient.md#approvestake) -- [checkValidEscrow](staking.StakingClient.md#checkvalidescrow) -- [closeAllocation](staking.StakingClient.md#closeallocation) -- [distributeReward](staking.StakingClient.md#distributereward) -- [getAllocation](staking.StakingClient.md#getallocation) -- [slash](staking.StakingClient.md#slash) -- [stake](staking.StakingClient.md#stake) -- [unstake](staking.StakingClient.md#unstake) -- [withdraw](staking.StakingClient.md#withdraw) -- [build](staking.StakingClient.md#build) +- [`BaseEthersClient`](../../base/classes/BaseEthersClient.md) ## Constructors -### constructor +### new StakingClient() -• **new StakingClient**(`runner`, `networkData`): [`StakingClient`](staking.StakingClient.md) +> **new StakingClient**(`runner`, `networkData`): [`StakingClient`](StakingClient.md) **StakingClient constructor** #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Runner object to interact with the Ethereum network | -| `networkData` | `NetworkData` | - | +• **runner**: `ContractRunner` + +The Runner object to interact with the Ethereum network + +• **networkData**: `NetworkData` #### Returns -[`StakingClient`](staking.StakingClient.md) +[`StakingClient`](StakingClient.md) #### Overrides -[BaseEthersClient](base.BaseEthersClient.md).[constructor](base.BaseEthersClient.md#constructor) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`constructor`](../../base/classes/BaseEthersClient.md#constructors) -#### Defined in +#### Source -[staking.ts:111](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L111) +[staking.ts:111](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L111) ## Properties ### escrowFactoryContract -• **escrowFactoryContract**: `EscrowFactory` +> **escrowFactoryContract**: `EscrowFactory` -#### Defined in +#### Source -[staking.ts:102](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L102) +[staking.ts:102](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L102) -___ +*** ### networkData -• **networkData**: `NetworkData` +> **networkData**: `NetworkData` #### Inherited from -[BaseEthersClient](base.BaseEthersClient.md).[networkData](base.BaseEthersClient.md#networkdata) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`networkData`](../../base/classes/BaseEthersClient.md#networkdata) -#### Defined in +#### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) -___ +*** ### rewardPoolContract -• **rewardPoolContract**: `RewardPool` +> **rewardPoolContract**: `RewardPool` -#### Defined in +#### Source -[staking.ts:103](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L103) +[staking.ts:103](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L103) -___ +*** ### runner -• `Protected` **runner**: `ContractRunner` +> `protected` **runner**: `ContractRunner` #### Inherited from -[BaseEthersClient](base.BaseEthersClient.md).[runner](base.BaseEthersClient.md#runner) +[`BaseEthersClient`](../../base/classes/BaseEthersClient.md).[`runner`](../../base/classes/BaseEthersClient.md#runner) -#### Defined in +#### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) -___ +*** ### stakingContract -• **stakingContract**: `Staking` +> **stakingContract**: `Staking` -#### Defined in +#### Source -[staking.ts:101](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L101) +[staking.ts:101](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L101) -___ +*** ### tokenContract -• **tokenContract**: `HMToken` +> **tokenContract**: `HMToken` -#### Defined in +#### Source -[staking.ts:100](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L100) +[staking.ts:100](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L100) ## Methods -### allocate +### allocate() -▸ **allocate**(`escrowAddress`, `amount`, `txOptions?`): `Promise`\<`void`\> +> **allocate**(`escrowAddress`, `amount`, `txOptions`?): `Promise`\<`void`\> This function allocates a portion of the staked tokens to a specific escrow. @@ -214,11 +186,17 @@ This function allocates a portion of the staked tokens to a specific escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow contract to allocate in. | -| `amount` | `bigint` | Amount in WEI of tokens to allocate. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow contract to allocate in. + +• **amount**: `bigint` + +Amount in WEI of tokens to allocate. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -243,24 +221,27 @@ const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount); ``` -#### Defined in +#### Source -[staking.ts:458](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L458) +[staking.ts:458](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L458) -___ +*** -### approveStake +### approveStake() -▸ **approveStake**(`amount`, `txOptions?`): `Promise`\<`void`\> +> **approveStake**(`amount`, `txOptions`?): `Promise`\<`void`\> This function approves the staking contract to transfer a specified amount of tokens when the user stakes. It increases the allowance for the staking contract. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `amount` | `bigint` | Amount in WEI of tokens to approve for stake. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **amount**: `bigint` + +Amount in WEI of tokens to approve for stake. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -285,37 +266,37 @@ const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI await stakingClient.approveStake(amount); ``` -#### Defined in +#### Source -[staking.ts:203](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L203) +[staking.ts:203](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L203) -___ +*** -### checkValidEscrow +### checkValidEscrow() -▸ **checkValidEscrow**(`escrowAddress`): `Promise`\<`void`\> +> `private` **checkValidEscrow**(`escrowAddress`): `Promise`\<`void`\> Check if escrow exists #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Escrow address to check against | +• **escrowAddress**: `string` + +Escrow address to check against #### Returns `Promise`\<`void`\> -#### Defined in +#### Source -[staking.ts:167](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L167) +[staking.ts:167](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L167) -___ +*** -### closeAllocation +### closeAllocation() -▸ **closeAllocation**(`escrowAddress`, `txOptions?`): `Promise`\<`void`\> +> **closeAllocation**(`escrowAddress`, `txOptions`?): `Promise`\<`void`\> This function drops the allocation from a specific escrow. @@ -324,10 +305,13 @@ This function drops the allocation from a specific escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Address of the escrow contract to close allocation from. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Address of the escrow contract to close allocation from. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -351,15 +335,15 @@ const stakingClient = await StakingClient.build(signer); await stakingClient.closeAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[staking.ts:511](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L511) +[staking.ts:511](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L511) -___ +*** -### distributeReward +### distributeReward() -▸ **distributeReward**(`escrowAddress`, `txOptions?`): `Promise`\<`void`\> +> **distributeReward**(`escrowAddress`, `txOptions`?): `Promise`\<`void`\> This function drops the allocation from a specific escrow. @@ -367,10 +351,13 @@ This function drops the allocation from a specific escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Escrow address from which rewards are distributed. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **escrowAddress**: `string` + +Escrow address from which rewards are distributed. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -394,23 +381,23 @@ const stakingClient = await StakingClient.build(signer); await stakingClient.distributeReward('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[staking.ts:554](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L554) +[staking.ts:554](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L554) -___ +*** -### getAllocation +### getAllocation() -▸ **getAllocation**(`escrowAddress`): `Promise`\<`IAllocation`\> +> **getAllocation**(`escrowAddress`): `Promise`\<`IAllocation`\> This function returns information about the allocation of the specified escrow. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `escrowAddress` | `string` | Escrow address from which we want to get allocation information. | +• **escrowAddress**: `string` + +Escrow address from which we want to get allocation information. #### Returns @@ -432,27 +419,39 @@ const stakingClient = await StakingClient.build(provider); const allocationInfo = await stakingClient.getAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); ``` -#### Defined in +#### Source -[staking.ts:591](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L591) +[staking.ts:591](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L591) -___ +*** -### slash +### slash() -▸ **slash**(`slasher`, `staker`, `escrowAddress`, `amount`, `txOptions?`): `Promise`\<`void`\> +> **slash**(`slasher`, `staker`, `escrowAddress`, `amount`, `txOptions`?): `Promise`\<`void`\> This function reduces the allocated amount by an staker in an escrow and transfers those tokens to the reward pool. This allows the slasher to claim them later. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `slasher` | `string` | Wallet address from who requested the slash | -| `staker` | `string` | Wallet address from who is going to be slashed | -| `escrowAddress` | `string` | Address of the escrow which allocation will be slashed | -| `amount` | `bigint` | Amount in WEI of tokens to unstake. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **slasher**: `string` + +Wallet address from who requested the slash + +• **staker**: `string` + +Wallet address from who is going to be slashed + +• **escrowAddress**: `string` + +Address of the escrow which allocation will be slashed + +• **amount**: `bigint` + +Amount in WEI of tokens to unstake. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -477,15 +476,15 @@ const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount); ``` -#### Defined in +#### Source -[staking.ts:387](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L387) +[staking.ts:387](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L387) -___ +*** -### stake +### stake() -▸ **stake**(`amount`, `txOptions?`): `Promise`\<`void`\> +> **stake**(`amount`, `txOptions`?): `Promise`\<`void`\> This function stakes a specified amount of tokens on a specific network. @@ -493,10 +492,13 @@ This function stakes a specified amount of tokens on a specific network. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `amount` | `bigint` | Amount in WEI of tokens to stake. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **amount**: `bigint` + +Amount in WEI of tokens to stake. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -522,15 +524,15 @@ await stakingClient.approveStake(amount); // if it was already approved before, await stakingClient.approveStake(amount); ``` -#### Defined in +#### Source -[staking.ts:258](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L258) +[staking.ts:258](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L258) -___ +*** -### unstake +### unstake() -▸ **unstake**(`amount`, `txOptions?`): `Promise`\<`void`\> +> **unstake**(`amount`, `txOptions`?): `Promise`\<`void`\> This function unstakes tokens from staking contract. The unstaked tokens stay locked for a period of time. @@ -538,10 +540,13 @@ This function unstakes tokens from staking contract. The unstaked tokens stay lo #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `amount` | `bigint` | Amount in WEI of tokens to unstake. | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **amount**: `bigint` + +Amount in WEI of tokens to unstake. + +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -566,15 +571,15 @@ const amount = ethers.parseUnits(5, 'ether'); //convert from ETH to WEI await stakingClient.unstake(amount); ``` -#### Defined in +#### Source -[staking.ts:303](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L303) +[staking.ts:303](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L303) -___ +*** -### withdraw +### withdraw() -▸ **withdraw**(`txOptions?`): `Promise`\<`void`\> +> **withdraw**(`txOptions`?): `Promise`\<`void`\> This function withdraws unstaked and non locked tokens form staking contract to the user wallet. @@ -582,9 +587,9 @@ This function withdraws unstaked and non locked tokens form staking contract to #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `txOptions?` | `Overrides` | Additional transaction parameters (optional, defaults to an empty object). | +• **txOptions?**: `Overrides`= `{}` + +Additional transaction parameters (optional, defaults to an empty object). #### Returns @@ -608,38 +613,38 @@ const stakingClient = await StakingClient.build(signer); await stakingClient.withdraw(); ``` -#### Defined in +#### Source -[staking.ts:349](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L349) +[staking.ts:349](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L349) -___ +*** -### build +### build() -▸ **build**(`runner`): `Promise`\<[`StakingClient`](staking.StakingClient.md)\> +> `static` **build**(`runner`): `Promise`\<[`StakingClient`](StakingClient.md)\> Creates an instance of StakingClient from a Runner. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `runner` | `ContractRunner` | The Runner object to interact with the Ethereum network | +• **runner**: `ContractRunner` + +The Runner object to interact with the Ethereum network #### Returns -`Promise`\<[`StakingClient`](staking.StakingClient.md)\> +`Promise`\<[`StakingClient`](StakingClient.md)\> - An instance of StakingClient -**`Throws`** +#### Throws - Thrown if the provider does not exist for the provided Signer -**`Throws`** +#### Throws - Thrown if the network's chainId is not supported -#### Defined in +#### Source -[staking.ts:145](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L145) +[staking.ts:145](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L145) diff --git a/docs/sdk/typescript/statistics/README.md b/docs/sdk/typescript/statistics/README.md new file mode 100644 index 0000000000..d5cf580f8e --- /dev/null +++ b/docs/sdk/typescript/statistics/README.md @@ -0,0 +1,13 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / statistics + +# statistics + +## Index + +### Classes + +- [StatisticsClient](classes/StatisticsClient.md) diff --git a/docs/sdk/typescript/classes/statistics.StatisticsClient.md b/docs/sdk/typescript/statistics/classes/StatisticsClient.md similarity index 73% rename from docs/sdk/typescript/classes/statistics.StatisticsClient.md rename to docs/sdk/typescript/statistics/classes/StatisticsClient.md index b08fc01c08..8018c85400 100644 --- a/docs/sdk/typescript/classes/statistics.StatisticsClient.md +++ b/docs/sdk/typescript/statistics/classes/StatisticsClient.md @@ -1,8 +1,10 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [statistics](../modules/statistics.md) / StatisticsClient +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: StatisticsClient +*** + +[@human-protocol/sdk](../../modules.md) / [statistics](../README.md) / StatisticsClient -[statistics](../modules/statistics.md).StatisticsClient +# Class: StatisticsClient ## Introduction @@ -40,60 +42,43 @@ import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk'; const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]); ``` -## Table of contents - -### Constructors - -- [constructor](statistics.StatisticsClient.md#constructor) - -### Properties - -- [networkData](statistics.StatisticsClient.md#networkdata) - -### Methods - -- [getEscrowStatistics](statistics.StatisticsClient.md#getescrowstatistics) -- [getHMTStatistics](statistics.StatisticsClient.md#gethmtstatistics) -- [getPaymentStatistics](statistics.StatisticsClient.md#getpaymentstatistics) -- [getWorkerStatistics](statistics.StatisticsClient.md#getworkerstatistics) - ## Constructors -### constructor +### new StatisticsClient() -• **new StatisticsClient**(`networkData`): [`StatisticsClient`](statistics.StatisticsClient.md) +> **new StatisticsClient**(`networkData`): [`StatisticsClient`](StatisticsClient.md) **StatisticsClient constructor** #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `networkData` | `NetworkData` | The network information required to connect to the Statistics contract | +• **networkData**: `NetworkData` + +The network information required to connect to the Statistics contract #### Returns -[`StatisticsClient`](statistics.StatisticsClient.md) +[`StatisticsClient`](StatisticsClient.md) -#### Defined in +#### Source -[statistics.ts:68](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L68) +[statistics.ts:68](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L68) ## Properties ### networkData -• **networkData**: `NetworkData` +> **networkData**: `NetworkData` -#### Defined in +#### Source -[statistics.ts:61](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L61) +[statistics.ts:61](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L61) ## Methods -### getEscrowStatistics +### getEscrowStatistics() -▸ **getEscrowStatistics**(`params?`): `Promise`\<`EscrowStatistics`\> +> **getEscrowStatistics**(`params`): `Promise`\<`EscrowStatistics`\> This function returns the statistical data of escrows. @@ -125,9 +110,9 @@ type EscrowStatistics = { #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `params` | `IStatisticsParams` | Statistics params with duration data | +• **params**: `IStatisticsParams`= `{}` + +Statistics params with duration data #### Returns @@ -149,15 +134,15 @@ const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({ }); ``` -#### Defined in +#### Source -[statistics.ts:121](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L121) +[statistics.ts:121](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L121) -___ +*** -### getHMTStatistics +### getHMTStatistics() -▸ **getHMTStatistics**(`params?`): `Promise`\<`HMTStatistics`\> +> **getHMTStatistics**(`params`): `Promise`\<`HMTStatistics`\> This function returns the statistical data of HMToken. @@ -194,9 +179,9 @@ type HMTStatistics = { #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `params` | `IStatisticsParams` | Statistics params with duration data | +• **params**: `IStatisticsParams`= `{}` + +Statistics params with duration data #### Returns @@ -245,15 +230,15 @@ console.log('HMT statistics from 5/8 - 6/8:', { }); ``` -#### Defined in +#### Source -[statistics.ts:394](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L394) +[statistics.ts:394](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L394) -___ +*** -### getPaymentStatistics +### getPaymentStatistics() -▸ **getPaymentStatistics**(`params?`): `Promise`\<`PaymentStatistics`\> +> **getPaymentStatistics**(`params`): `Promise`\<`PaymentStatistics`\> This function returns the statistical data of payments. @@ -282,9 +267,9 @@ type PaymentStatistics = { #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `params` | `IStatisticsParams` | Statistics params with duration data | +• **params**: `IStatisticsParams`= `{}` + +Statistics params with duration data #### Returns @@ -327,15 +312,15 @@ console.log( ); ``` -#### Defined in +#### Source -[statistics.ts:285](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L285) +[statistics.ts:285](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L285) -___ +*** -### getWorkerStatistics +### getWorkerStatistics() -▸ **getWorkerStatistics**(`params?`): `Promise`\<`WorkerStatistics`\> +> **getWorkerStatistics**(`params`): `Promise`\<`WorkerStatistics`\> This function returns the statistical data of workers. @@ -362,9 +347,9 @@ type WorkerStatistics = { #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `params` | `IStatisticsParams` | Statistics params with duration data | +• **params**: `IStatisticsParams`= `{}` + +Statistics params with duration data #### Returns @@ -386,6 +371,6 @@ const workerStatisticsApril = await statisticsClient.getWorkerStatistics({ }); ``` -#### Defined in +#### Source -[statistics.ts:196](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L196) +[statistics.ts:196](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L196) diff --git a/docs/sdk/typescript/storage/README.md b/docs/sdk/typescript/storage/README.md new file mode 100644 index 0000000000..80e8da6d9f --- /dev/null +++ b/docs/sdk/typescript/storage/README.md @@ -0,0 +1,13 @@ +[**@human-protocol/sdk**](../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../modules.md) / storage + +# storage + +## Index + +### Classes + +- [StorageClient](classes/StorageClient.md) diff --git a/docs/sdk/typescript/classes/storage.StorageClient.md b/docs/sdk/typescript/storage/classes/StorageClient.md similarity index 62% rename from docs/sdk/typescript/classes/storage.StorageClient.md rename to docs/sdk/typescript/storage/classes/StorageClient.md index ee52d4bbd0..2250a251a2 100644 --- a/docs/sdk/typescript/classes/storage.StorageClient.md +++ b/docs/sdk/typescript/storage/classes/StorageClient.md @@ -1,10 +1,12 @@ -[@human-protocol/sdk](../README.md) / [Modules](../modules.md) / [storage](../modules/storage.md) / StorageClient +[**@human-protocol/sdk**](../../README.md) • **Docs** -# Class: StorageClient +*** -[storage](../modules/storage.md).StorageClient +[@human-protocol/sdk](../../modules.md) / [storage](../README.md) / StorageClient -**`Deprecated`** +# Class: ~~StorageClient~~ + +## Deprecated StorageClient is deprecated. Use Minio.Client directly. @@ -51,81 +53,65 @@ const params: StorageParams = { const storageClient = new StorageClient(params, credentials); ``` -## Table of contents - -### Constructors - -- [constructor](storage.StorageClient.md#constructor) - -### Properties - -- [client](storage.StorageClient.md#client) -- [clientParams](storage.StorageClient.md#clientparams) - -### Methods - -- [bucketExists](storage.StorageClient.md#bucketexists) -- [downloadFiles](storage.StorageClient.md#downloadfiles) -- [listObjects](storage.StorageClient.md#listobjects) -- [uploadFiles](storage.StorageClient.md#uploadfiles) -- [downloadFileFromUrl](storage.StorageClient.md#downloadfilefromurl) - ## Constructors -### constructor +### new StorageClient() -• **new StorageClient**(`params`, `credentials?`): [`StorageClient`](storage.StorageClient.md) +> **new StorageClient**(`params`, `credentials`?): [`StorageClient`](StorageClient.md) **Storage client constructor** #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `params` | `StorageParams` | Cloud storage params | -| `credentials?` | `StorageCredentials` | Optional. Cloud storage access data. If credentials is not provided - use an anonymous access to the bucket | +• **params**: `StorageParams` + +Cloud storage params + +• **credentials?**: `StorageCredentials` + +Optional. Cloud storage access data. If credentials is not provided - use an anonymous access to the bucket #### Returns -[`StorageClient`](storage.StorageClient.md) +[`StorageClient`](StorageClient.md) -#### Defined in +#### Source -[storage.ts:73](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L73) +[storage.ts:73](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L73) ## Properties -### client +### ~~client~~ -• `Private` **client**: `Client` +> `private` **client**: `Client` -#### Defined in +#### Source -[storage.ts:64](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L64) +[storage.ts:64](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L64) -___ +*** -### clientParams +### ~~clientParams~~ -• `Private` **clientParams**: `StorageParams` +> `private` **clientParams**: `StorageParams` -#### Defined in +#### Source -[storage.ts:65](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L65) +[storage.ts:65](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L65) ## Methods -### bucketExists +### ~~bucketExists()~~ -▸ **bucketExists**(`bucket`): `Promise`\<`boolean`\> +> **bucketExists**(`bucket`): `Promise`\<`boolean`\> This function checks if a bucket exists. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `bucket` | `string` | Bucket name. | +• **bucket**: `string` + +Bucket name. #### Returns @@ -153,24 +139,27 @@ const storageClient = new StorageClient(params, credentials); const exists = await storageClient.bucketExists('bucket-name'); ``` -#### Defined in +#### Source -[storage.ts:266](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L266) +[storage.ts:266](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L266) -___ +*** -### downloadFiles +### ~~downloadFiles()~~ -▸ **downloadFiles**(`keys`, `bucket`): `Promise`\<`any`[]\> +> **downloadFiles**(`keys`, `bucket`): `Promise`\<`any`[]\> This function downloads files from a bucket. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `keys` | `string`[] | Array of filenames to download. | -| `bucket` | `string` | Bucket name. | +• **keys**: `string`[] + +Array of filenames to download. + +• **bucket**: `string` + +Bucket name. #### Returns @@ -196,23 +185,23 @@ const keys = ['file1.json', 'file2.json']; const files = await storageClient.downloadFiles(keys, 'bucket-name'); ``` -#### Defined in +#### Source -[storage.ts:113](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L113) +[storage.ts:113](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L113) -___ +*** -### listObjects +### ~~listObjects()~~ -▸ **listObjects**(`bucket`): `Promise`\<`string`[]\> +> **listObjects**(`bucket`): `Promise`\<`string`[]\> This function list all file names contained in the bucket. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `bucket` | `string` | Bucket name. | +• **bucket**: `string` + +Bucket name. #### Returns @@ -240,24 +229,27 @@ const storageClient = new StorageClient(params, credentials); const fileNames = await storageClient.listObjects('bucket-name'); ``` -#### Defined in +#### Source -[storage.ts:297](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L297) +[storage.ts:297](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L297) -___ +*** -### uploadFiles +### ~~uploadFiles()~~ -▸ **uploadFiles**(`files`, `bucket`): `Promise`\<`UploadFile`[]\> +> **uploadFiles**(`files`, `bucket`): `Promise`\<`UploadFile`[]\> This function uploads files to a bucket. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `files` | `any`[] | Array of objects to upload serialized into json. | -| `bucket` | `string` | Bucket name. | +• **files**: `any`[] + +Array of objects to upload serialized into json. + +• **bucket**: `string` + +Bucket name. #### Returns @@ -288,23 +280,23 @@ const files = [file1, file2]; const uploadedFiles = await storageClient.uploadFiles(files, 'bucket-name'); ``` -#### Defined in +#### Source -[storage.ts:201](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L201) +[storage.ts:201](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L201) -___ +*** -### downloadFileFromUrl +### ~~downloadFileFromUrl()~~ -▸ **downloadFileFromUrl**(`url`): `Promise`\<`any`\> +> `static` **downloadFileFromUrl**(`url`): `Promise`\<`any`\> This function downloads files from a Url. #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `url` | `string` | Url of the file to download. | +• **url**: `string` + +Url of the file to download. #### Returns @@ -320,6 +312,6 @@ import { StorageClient } from '@human-protocol/sdk'; const file = await storageClient.downloadFileFromUrl('http://localhost/file.json'); ``` -#### Defined in +#### Source -[storage.ts:148](https://github.com/humanprotocol/human-protocol/blob/a1de62e8e746c43536740f191a75d8b701d507a9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L148) +[storage.ts:148](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L148) diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/filter.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/filter.py index 6c13f5109b..a4fe5416db 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/filter.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/filter.py @@ -118,3 +118,66 @@ def __init__( self.recipient = recipient self.date_from = date_from self.date_to = date_to + + +class TransactionFilter: + """ + A class used to filter transactions. + """ + + def __init__( + self, + networks: List[ChainId], + from_address: Optional[str] = None, + to_address: Optional[str] = None, + start_date: Optional[datetime] = None, + end_date: Optional[datetime] = None, + start_block: Optional[int] = None, + end_block: Optional[int] = None, + ): + """ + Initializes a TransactionsFilter instance. + + :param networks: List of chain IDs to filter transactions from + :param from_address: Sender address + :param to_address: Receiver address + :param start_date: Start date for filtering transactions + :param end_date: End date for filtering transactions + :param start_block: Start block number for filtering transactions + :param end_block: End block number for filtering transactions + + :raises ValueError: If start_date is after end_date + """ + + if from_address and not Web3.is_address(from_address): + raise ValueError(f"Invalid from_address: {from_address}") + + if to_address and not Web3.is_address(to_address): + raise ValueError(f"Invalid to_address: {to_address}") + + if start_date and end_date and start_date > end_date: + raise ValueError( + f"Invalid date range: start_date must be earlier than end_date" + ) + + if ( + start_block is not None + and end_block is not None + and start_block > end_block + ): + raise ValueError( + f"Invalid block range: start_block must be earlier than end_block" + ) + + if (start_date or end_date) and (start_block or end_block): + raise ValueError( + "Date and block filters cannot be used together in TransactionsFilter" + ) + + self.networks = networks + self.from_address = from_address + self.to_address = to_address + self.start_date = start_date + self.end_date = end_date + self.start_block = start_block + self.end_block = end_block diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/transaction.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/transaction.py new file mode 100644 index 0000000000..73966e3f7a --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/transaction.py @@ -0,0 +1,65 @@ +from human_protocol_sdk.filter import TransactionFilter + +transaction_fragment = """ +fragment TransactionFields on Transaction { + block + txHash + from + to + timestamp + value + method +} +""" + + +def get_transactions_query(filter: TransactionFilter) -> str: + return """ +query GetTransactions( + $fromAddress: String + $toAddress: String + $startDate: Int + $endDate: Int + $startBlock: Int + $endBlock: Int +) {{ + transactions( + where: {{ + {from_address_clause} + {to_address_clause} + {start_date_clause} + {end_date_clause} + {start_block_clause} + {end_block_clause} + }} + orderBy: timestamp, + orderDirection: asc, + ) {{ + ...TransactionFields + }} +}} +{transaction_fragment} +""".format( + transaction_fragment=transaction_fragment, + from_address_clause="from: $fromAddress" if filter.from_address else "", + to_address_clause="to: $toAddress" if filter.to_address else "", + start_date_clause="timestamp_gte: $startDate" if filter.start_date else "", + end_date_clause="timestamp_lte: $endDate" if filter.end_date else "", + start_block_clause="block_gte: $startBlock" if filter.start_block else "", + end_block_clause="block_lte: $endBlock" if filter.end_block else "", + ) + + +def get_transaction_query() -> str: + return """ +query GetTransaction( + $hash: String! +) {{ + transaction(id: $hash) {{ + ...TransactionFields + }} +}} +{transaction_fragment} +""".format( + transaction_fragment=transaction_fragment + ) diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/__init__.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/__init__.py new file mode 100644 index 0000000000..d8f90a53e8 --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/__init__.py @@ -0,0 +1,11 @@ +""" +This module enables to obtain transaction information from +both the contracts and subgraph. +""" + +from .transaction_utils import ( + TransactionUtils, + TransactionData, + TransactionFilter, + TransactionUtilsError, +) diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py new file mode 100644 index 0000000000..e232214358 --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py @@ -0,0 +1,200 @@ +""" +Utility class for transaction-related operations. + +Code Example +------------ + +.. code-block:: python + + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.transaction import TransactionUtils, TransactionFilter + + print( + TransactionUtils.get_transactions( + TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="0x1234567890123456789012345678901234567890", + to_address="0x0987654321098765432109876543210987654321", + start_date=datetime.datetime(2023, 5, 8), + end_date=datetime.datetime(2023, 6, 8), + ) + ) + ) + +Module +------ +""" + +from typing import List, Optional + +from human_protocol_sdk.constants import NETWORKS, ChainId +from web3 import Web3 +from human_protocol_sdk.filter import TransactionFilter +from human_protocol_sdk.utils import get_data_from_subgraph + + +class TransactionData: + def __init__( + self, + chain_id: ChainId, + block: int, + hash: str, + from_address: str, + to_address: str, + timestamp: int, + value: str, + method: str, + ): + self.chain_id = chain_id + self.block = block + self.hash = hash + self.from_address = from_address + self.to_address = to_address + self.timestamp = timestamp + self.value = value + self.method = method + + +class TransactionUtilsError(Exception): + """ + Raises when some error happens when getting data from subgraph. + """ + + pass + + +class TransactionUtils: + """ + A utility class that provides additional transaction-related functionalities. + """ + + @staticmethod + def get_transaction(chain_id: ChainId, hash: str) -> Optional[TransactionData]: + """Returns the transaction for a given hash. + + :param chain_id: Network in which the transaction was executed + :param hash: Hash of the transaction + + :return: Transaction data + + :example: + .. code-block:: python + + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.transaction import TransactionUtils + + print( + TransactionUtils.get_transaction( + ChainId.POLYGON_AMOY, + "0x1234567890123456789012345678901234567891" + ) + ) + """ + network = NETWORKS.get(chain_id) + if not network: + raise TransactionUtilsError("Unsupported Chain ID") + + from human_protocol_sdk.gql.transaction import get_transaction_query + + transaction_data = get_data_from_subgraph( + network["subgraph_url"], + query=get_transaction_query(), + params={"hash": hash.lower()}, + ) + transaction = transaction_data["data"]["transaction"] + + if not transaction: + return None + + return TransactionData( + chain_id=chain_id, + block=transaction.get("block", 0), + hash=transaction.get("txHash", ""), + from_address=transaction.get("from", ""), + to_address=transaction.get("to", ""), + timestamp=transaction.get("timestamp", 0), + value=transaction.get("value", ""), + method=transaction.get("method", ""), + ) + + @staticmethod + def get_transactions(filter: TransactionFilter) -> List[TransactionData]: + """Get an array of transactions based on the specified filter parameters. + + :param filter: Object containing all the necessary parameters to filter + + :return: List of transactions + + :example: + .. code-block:: python + + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.transaction import TransactionUtils, TransactionFilter + + print( + TransactionUtils.get_transactions( + TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="0x1234567890123456789012345678901234567890", + to_address="0x0987654321098765432109876543210987654321", + start_date=datetime.datetime(2023, 5, 8), + end_date=datetime.datetime(2023, 6, 8), + ) + ) + ) + """ + if not filter.networks: + raise TransactionUtilsError("Unsupported Chain ID") + + from human_protocol_sdk.gql.transaction import get_transactions_query + + transactions = [] + for chain_id in filter.networks: + network_data = NETWORKS.get(chain_id) + if not network_data: + raise TransactionUtilsError("Unsupported Chain ID") + + data = get_data_from_subgraph( + network_data["subgraph_url"], + query=get_transactions_query(filter), + params={ + "fromAddress": ( + filter.from_address.lower() if filter.from_address else None + ), + "toAddress": ( + filter.to_address.lower() if filter.to_address else None + ), + "startDate": ( + int(filter.start_date.timestamp()) + if filter.start_date + else None + ), + "endDate": ( + int(filter.end_date.timestamp()) if filter.end_date else None + ), + "startBlock": filter.start_block if filter.start_block else None, + "endBlock": filter.end_block if filter.end_block else None, + }, + ) + if not data or "data" not in data or "transactions" not in data["data"]: + continue + + transactions_raw = data["data"]["transactions"] + + transactions.extend( + [ + TransactionData( + chain_id=chain_id, + block=transaction.get("block", 0), + hash=transaction.get("txHash", ""), + from_address=transaction.get("from", ""), + to_address=transaction.get("to", ""), + timestamp=transaction.get("timestamp", 0), + value=transaction.get("value", ""), + method=transaction.get("method", ""), + ) + for transaction in transactions_raw + ] + ) + + return transactions diff --git a/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh b/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh index 28cc287db2..2a0c4c8015 100755 --- a/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh +++ b/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh @@ -2,4 +2,4 @@ set -eux # Run test -pipenv run pytest ./test/human_protocol_sdk +pipenv run pytest ./test/human_protocol_sdk/ \ No newline at end of file diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py new file mode 100644 index 0000000000..c2215bf71e --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py @@ -0,0 +1,187 @@ +import unittest +from datetime import datetime +from unittest.mock import ANY, patch + +from human_protocol_sdk.constants import NETWORKS, ChainId, Status +from human_protocol_sdk.gql.transaction import ( + get_transaction_query, + get_transactions_query, +) +from human_protocol_sdk.transaction import ( + TransactionUtils, +) +from human_protocol_sdk.filter import TransactionFilter + + +class TestTransactionUtils(unittest.TestCase): + def test_get_transactions(self): + with patch( + "human_protocol_sdk.transaction.transaction_utils.get_data_from_subgraph" + ) as mock_function: + mock_transaction_1 = { + "block": 123, + "txHash": "0x1234567890123456789012345678901234567890123456789012345678901234", + "from": "0x1234567890123456789012345678901234567890", + "to": "0x9876543210987654321098765432109876543210", + "timestamp": 1622700000, + "value": "1000000000000000000", + "method": "transfer", + } + mock_transaction_2 = { + "block": 456, + "txHash": "0x9876543210987654321098765432109876543210987654321098765432109876", + "from": "0x9876543210987654321098765432109876543210", + "to": "0x1234567890123456789012345678901234567890", + "timestamp": 1622800000, + "value": "2000000000000000000", + "method": "transfer", + } + + mock_function.return_value = { + "data": {"transactions": [mock_transaction_1, mock_transaction_2]} + } + + filter = TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="0x1234567890123456789012345678901234567890", + to_address="0x9876543210987654321098765432109876543210", + ) + + transactions = TransactionUtils.get_transactions(filter) + + mock_function.assert_called_once_with( + NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + query=get_transactions_query(filter), + params={ + "fromAddress": "0x1234567890123456789012345678901234567890", + "toAddress": "0x9876543210987654321098765432109876543210", + "startDate": None, + "endDate": None, + "startBlock": None, + "endBlock": None, + }, + ) + self.assertEqual(len(transactions), 2) + self.assertEqual(transactions[0].chain_id, ChainId.POLYGON_AMOY) + self.assertEqual(transactions[1].chain_id, ChainId.POLYGON_AMOY) + + def test_get_transactions_empty_response(self): + with patch( + "human_protocol_sdk.transaction.transaction_utils.get_data_from_subgraph" + ) as mock_function: + mock_function.return_value = {"data": {"transactions": []}} + + filter = TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="0x1234567890123456789012345678901234567890", + ) + + transactions = TransactionUtils.get_transactions(filter) + + mock_function.assert_called_once_with( + NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + query=get_transactions_query(filter), + params={ + "fromAddress": "0x1234567890123456789012345678901234567890", + "toAddress": None, + "startDate": None, + "endDate": None, + "startBlock": None, + "endBlock": None, + }, + ) + self.assertEqual(len(transactions), 0) + + def test_get_transactions_invalid_network(self): + with self.assertRaises(ValueError) as cm: + filter = TransactionFilter(networks=[ChainId(12345)]) + TransactionUtils.get_transactions(filter) + self.assertEqual("12345 is not a valid ChainId", str(cm.exception)) + + def test_get_transactions_invalid_from_address(self): + with self.assertRaises(ValueError) as cm: + TransactionUtils.get_transactions( + TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="invalid_address", + ) + ) + self.assertEqual("Invalid from_address: invalid_address", str(cm.exception)) + + def test_get_transactions_invalid_to_address(self): + with self.assertRaises(ValueError) as cm: + TransactionUtils.get_transactions( + TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + to_address="invalid_address", + ) + ) + self.assertEqual("Invalid to_address: invalid_address", str(cm.exception)) + + def test_get_transaction(self): + with patch( + "human_protocol_sdk.transaction.transaction_utils.get_data_from_subgraph" + ) as mock_function: + mock_transaction = { + "block": 123, + "txHash": "0x1234567890123456789012345678901234567890123456789012345678901234", + "from": "0x1234567890123456789012345678901234567890", + "to": "0x9876543210987654321098765432109876543210", + "timestamp": 1622700000, + "value": "1000000000000000000", + "method": "transfer", + } + + mock_function.return_value = {"data": {"transaction": mock_transaction}} + + transaction = TransactionUtils.get_transaction( + ChainId.POLYGON_AMOY, + "0x1234567890123456789012345678901234567890123456789012345678901234", + ) + + mock_function.assert_called_once_with( + NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + query=get_transaction_query(), + params={ + "hash": "0x1234567890123456789012345678901234567890123456789012345678901234" + }, + ) + self.assertIsNotNone(transaction) + self.assertEqual(transaction.chain_id, ChainId.POLYGON_AMOY) + self.assertEqual(transaction.block, mock_transaction["block"]) + self.assertEqual(transaction.hash, mock_transaction["txHash"]) + self.assertEqual(transaction.from_address, mock_transaction["from"]) + self.assertEqual(transaction.to_address, mock_transaction["to"]) + self.assertEqual(transaction.timestamp, mock_transaction["timestamp"]) + self.assertEqual(transaction.value, mock_transaction["value"]) + self.assertEqual(transaction.method, mock_transaction["method"]) + + def test_get_transaction_empty_data(self): + with patch( + "human_protocol_sdk.transaction.transaction_utils.get_data_from_subgraph" + ) as mock_function: + + mock_function.return_value = {"data": {"transaction": None}} + + transaction = TransactionUtils.get_transaction( + ChainId.POLYGON_AMOY, "transaction_hash" + ) + + mock_function.assert_called_once_with( + NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + query=ANY, + params={"hash": "transaction_hash"}, + ) + + self.assertIsNone(transaction) + + def test_get_transaction_invalid_chain_id(self): + with self.assertRaises(ValueError) as cm: + TransactionUtils.get_transaction( + ChainId(123), "0x1234567890123456789012345678901234567891" + ) + self.assertEqual("123 is not a valid ChainId", str(cm.exception)) + + +if __name__ == "__main__": + unittest.main(exit=True) diff --git a/packages/sdk/typescript/human-protocol-sdk/src/error.ts b/packages/sdk/typescript/human-protocol-sdk/src/error.ts index 8b14e80c79..73edc04578 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/error.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/error.ts @@ -117,6 +117,18 @@ export const ErrorInvalidStakerAddressProvided = new Error( 'Invalid staker address provided' ); +/** + * @constant {Error} - Invalid hash provided. + */ +export const ErrorInvalidHahsProvided = new Error('Invalid hash provided'); + +/** + * @constant {Error} - Cannot use both date and block filters simultaneously. + */ +export const ErrorCannotUseDateAndBlockSimultaneously = new Error( + 'Cannot use both date and block filters simultaneously' +); + /** * @constant {Error} - Invalid escrow address provided. */ diff --git a/packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/transaction.ts b/packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/transaction.ts new file mode 100644 index 0000000000..a616c65caa --- /dev/null +++ b/packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/transaction.ts @@ -0,0 +1,59 @@ +import gql from 'graphql-tag'; +import { ITransactionsFilter } from '../../../src/interfaces'; + +const TRANSACTION_FRAGMENT = gql` + fragment TransactionFields on Transaction { + block + txHash + from + to + timestamp + value + method + } +`; + +export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => { + const { startDate, endDate, startBlock, endBlock, fromAddress, toAddress } = + filter; + + const WHERE_CLAUSE = ` + where: { + ${fromAddress ? `from: $fromAddress` : ''} + ${toAddress ? `to: $toAddress` : ''} + ${startDate ? `timestamp_gte: $startDate` : ''} + ${endDate ? `timestamp_lte: $endDate` : ''} + ${startBlock ? `block_gte: $startBlock` : ''} + ${endBlock ? `block_lte: $endBlock` : ''} + } + `; + + return gql` + query getTransactions( + $fromAddress: String + $toAddress: String + $startDate: Int + $endDate: Int + $startBlock: Int + $endBlock: Int + ) { + transactions( + ${WHERE_CLAUSE} + orderBy: timestamp, + orderDirection: asc, + ) { + ...TransactionFields + } + } + ${TRANSACTION_FRAGMENT} + `; +}; + +export const GET_TRANSACTION_QUERY = gql` + query getTransaction($hash: String!) { + transaction(id: $hash) { + ...TransactionFields + } + } + ${TRANSACTION_FRAGMENT} +`; diff --git a/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts b/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts index 78a7ad961d..c5d869d4da 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts @@ -108,3 +108,23 @@ export interface IPayoutFilter { from?: Date; to?: Date; } + +export interface ITransaction { + block: bigint; + hash: string; + from: string; + to: string; + timestamp: bigint; + value: string; + method: string; +} + +export interface ITransactionsFilter { + networks: ChainId[]; + startBlock?: number; + endBlock?: number; + startDate?: Date; + endDate?: Date; + fromAddress?: string; + toAddress?: string; +} diff --git a/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts b/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts new file mode 100644 index 0000000000..c1497adb3a --- /dev/null +++ b/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts @@ -0,0 +1,146 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { ethers } from 'ethers'; +import gqlFetch from 'graphql-request'; +import { NETWORKS } from './constants'; +import { ChainId } from './enums'; +import { + ErrorCannotUseDateAndBlockSimultaneously, + ErrorInvalidHahsProvided, + ErrorUnsupportedChainID, +} from './error'; +import { + GET_TRANSACTIONS_QUERY, + GET_TRANSACTION_QUERY, +} from './graphql/queries/transaction'; +import { ITransaction, ITransactionsFilter } from './interfaces'; + +export class TransactionUtils { + /** + * This function returns the transaction data for the given hash. + * + * @param {ChainId} chainId The chain ID. + * @param {string} hash The transaction hash. + * @returns {Promise} Returns the transaction details. + * + * **Code example** + * + * ```ts + * import { TransactionUtils, ChainId } from '@human-protocol/sdk'; + * + * const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f'); + * ``` + */ + public static async getTransaction( + chainId: ChainId, + hash: string + ): Promise { + if (!ethers.isHexString(hash)) { + throw ErrorInvalidHahsProvided; + } + const networkData = NETWORKS[chainId]; + + if (!networkData) { + throw ErrorUnsupportedChainID; + } + + const { transaction } = await gqlFetch<{ + transaction: ITransaction; + }>(networkData.subgraphUrl, GET_TRANSACTION_QUERY, { + hash: hash.toLowerCase(), + }); + + return transaction; + } + + /** + * This function returns all transaction details based on the provided filter. + * + * > This uses Subgraph + * + * **Input parameters** + * + * ```ts + * interface ITransactionsFilter { + * networks: ChainId[]; // List of chain IDs to query. + * fromAddress?: string; // (Optional) The address from which transactions are sent. + * toAddress?: string; // (Optional) The address to which transactions are sent. + * startDate?: Date; // (Optional) The start date to filter transactions (inclusive). + * endDate?: Date; // (Optional) The end date to filter transactions (inclusive). + * startBlock?: number; // (Optional) The start block number to filter transactions (inclusive). + * endBlock?: number; // (Optional) The end block number to filter transactions (inclusive). + * } + * ``` + * + * ```ts + * type ITransaction = { + * block: number; + * txHash: string; + * from: string; + * to: string; + * timestamp: number; + * value: string; + * method: string; + * }; + * ``` + * + * @param {ITransactionsFilter} filter Filter for the transactions. + * @returns {Promise} Returns an array with all the transaction details. + * + * **Code example** + * + * ```ts + * import { TransactionUtils, ChainId } from '@human-protocol/sdk'; + * + * const filter: ITransactionsFilter = { + * networks: [ChainId.POLYGON], + * startDate: new Date('2022-01-01'), + * endDate: new Date('2022-12-31') + * }; + * const transactions = await TransactionUtils.getTransactions(filter); + * ``` + */ + public static async getTransactions( + filter: ITransactionsFilter + ): Promise { + if ( + (!!filter.startDate || !!filter.endDate) && + (!!filter.startBlock || !!filter.endBlock) + ) { + throw ErrorCannotUseDateAndBlockSimultaneously; + } + + const transactions_data: ITransaction[] = []; + for (const chainId of filter.networks) { + const networkData = NETWORKS[chainId]; + if (!networkData) { + throw ErrorUnsupportedChainID; + } + + if (!networkData.subgraphUrl) { + continue; + } + + const { transactions } = await gqlFetch<{ + transactions: ITransaction[]; + }>(networkData.subgraphUrl, GET_TRANSACTIONS_QUERY(filter), { + fromAddress: filter?.fromAddress, + toAddress: filter?.toAddress, + startDate: filter?.startDate + ? Math.floor(filter?.startDate.getTime() / 1000) + : undefined, + endDate: filter.endDate + ? Math.floor(filter.endDate.getTime() / 1000) + : undefined, + startBlock: filter.startBlock ? filter.startBlock : undefined, + endBlock: filter.endBlock ? filter.endBlock : undefined, + }); + + if (!transactions) { + continue; + } + + transactions_data.push(...transactions); + } + return transactions_data; + } +} diff --git a/packages/sdk/typescript/human-protocol-sdk/test/transaction.test.ts b/packages/sdk/typescript/human-protocol-sdk/test/transaction.test.ts new file mode 100644 index 0000000000..d2567f4b2e --- /dev/null +++ b/packages/sdk/typescript/human-protocol-sdk/test/transaction.test.ts @@ -0,0 +1,188 @@ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import * as gqlFetch from 'graphql-request'; +import { describe, expect, test, vi } from 'vitest'; +import { NETWORKS } from '../src/constants'; +import { ChainId } from '../src/enums'; +import { + ErrorCannotUseDateAndBlockSimultaneously, + ErrorInvalidHahsProvided, +} from '../src/error'; +import { GET_TRANSACTION_QUERY } from '../src/graphql/queries/transaction'; +import { ITransaction, ITransactionsFilter } from '../src/interfaces'; +import { TransactionUtils } from '../src/transaction'; + +vi.mock('graphql-request', () => { + return { + default: vi.fn(), + }; +}); + +describe('TransactionUtils', () => { + describe('getTransaction', () => { + const txHash = '0x62dD51230A30401C455c8398d06F85e4EaB6309f'; + const invalidHash = 'InvalidHash'; + + const mockTransaction: ITransaction = { + block: 12345n, + hash: txHash, + from: '0x1234567890123456789012345678901234567890', + to: '0x0987654321098765432109876543210987654321', + timestamp: 1625247600n, + value: '1000000000000000000', + method: 'transfer', + }; + + test('should return transaction information', async () => { + const gqlFetchSpy = vi.spyOn(gqlFetch, 'default').mockResolvedValueOnce({ + transaction: mockTransaction, + }); + + const result = await TransactionUtils.getTransaction( + ChainId.LOCALHOST, + txHash + ); + + expect(gqlFetchSpy).toHaveBeenCalledWith( + NETWORKS[ChainId.LOCALHOST]?.subgraphUrl, + GET_TRANSACTION_QUERY, + { + hash: txHash.toLowerCase(), + } + ); + expect(result).toEqual(mockTransaction); + }); + + test('should throw an error for an invalid transaction hash', async () => { + await expect( + TransactionUtils.getTransaction(ChainId.LOCALHOST, invalidHash) + ).rejects.toThrow(ErrorInvalidHahsProvided); + }); + + test('should throw an error if the gql fetch fails', async () => { + const gqlFetchSpy = vi + .spyOn(gqlFetch, 'default') + .mockRejectedValueOnce(new Error('Error')); + + await expect( + TransactionUtils.getTransaction(ChainId.LOCALHOST, txHash) + ).rejects.toThrow(); + expect(gqlFetchSpy).toHaveBeenCalledTimes(1); + }); + }); + + describe('getTransactions', () => { + const mockTransaction: ITransaction = { + block: 12345n, + hash: '0x62dD51230A30401C455c8398d06F85e4EaB6309f', + from: '0x1234567890123456789012345678901234567890', + to: '0x0987654321098765432109876543210987654321', + timestamp: 1625247600n, + value: '1000000000000000000', + method: 'transfer', + }; + + test('should return an array of transactions', async () => { + const gqlFetchSpy = vi.spyOn(gqlFetch, 'default').mockResolvedValueOnce({ + transactions: [mockTransaction, mockTransaction], + }); + const filter: ITransactionsFilter = { + networks: [ChainId.LOCALHOST], + }; + + const result = await TransactionUtils.getTransactions(filter); + + expect(gqlFetchSpy).toHaveBeenCalledWith( + NETWORKS[ChainId.LOCALHOST]?.subgraphUrl, + expect.anything(), + { + fromAddress: undefined, + toAddress: undefined, + startDate: undefined, + endDate: undefined, + startBlock: undefined, + endBlock: undefined, + } + ); + expect(result).toEqual([mockTransaction, mockTransaction]); + }); + + test('should return an array of transactions with date filter', async () => { + const gqlFetchSpy = vi.spyOn(gqlFetch, 'default').mockResolvedValueOnce({ + transactions: [mockTransaction, mockTransaction], + }); + const filter: ITransactionsFilter = { + networks: [ChainId.LOCALHOST], + startDate: new Date('2022-01-01'), + endDate: new Date('2022-12-31'), + }; + + const result = await TransactionUtils.getTransactions(filter); + + expect(gqlFetchSpy).toHaveBeenCalledWith( + NETWORKS[ChainId.LOCALHOST]?.subgraphUrl, + expect.anything(), + { + fromAddress: undefined, + toAddress: undefined, + startDate: Math.floor(filter.startDate!.getTime() / 1000), + endDate: Math.floor(filter.endDate!.getTime() / 1000), + startBlock: undefined, + endBlock: undefined, + } + ); + expect(result).toEqual([mockTransaction, mockTransaction]); + }); + + test('should return an array of transactions with address filter', async () => { + const gqlFetchSpy = vi.spyOn(gqlFetch, 'default').mockResolvedValueOnce({ + transactions: [mockTransaction, mockTransaction], + }); + const filter: ITransactionsFilter = { + networks: [ChainId.LOCALHOST], + fromAddress: '0x1234567890123456789012345678901234567890', + }; + + const result = await TransactionUtils.getTransactions(filter); + + expect(gqlFetchSpy).toHaveBeenCalledWith( + NETWORKS[ChainId.LOCALHOST]?.subgraphUrl, + expect.anything(), + { + fromAddress: filter.fromAddress, + toAddress: undefined, + startDate: undefined, + endDate: undefined, + startBlock: undefined, + endBlock: undefined, + } + ); + expect(result).toEqual([mockTransaction, mockTransaction]); + }); + + test('should throw an error if both date and block filters are used', async () => { + const filter: ITransactionsFilter = { + networks: [ChainId.LOCALHOST], + startDate: new Date('2022-01-01'), + endBlock: 100000, + }; + + await expect(TransactionUtils.getTransactions(filter)).rejects.toThrow( + ErrorCannotUseDateAndBlockSimultaneously + ); + }); + + test('should throw an error if the gql fetch fails', async () => { + const filter: ITransactionsFilter = { + networks: [ChainId.LOCALHOST], + }; + + const gqlFetchSpy = vi + .spyOn(gqlFetch, 'default') + .mockRejectedValueOnce(new Error('Error')); + + await expect(TransactionUtils.getTransactions(filter)).rejects.toThrow(); + expect(gqlFetchSpy).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/packages/sdk/typescript/subgraph/schema.graphql b/packages/sdk/typescript/subgraph/schema.graphql index 8630ef86bb..7e688bef2e 100644 --- a/packages/sdk/typescript/subgraph/schema.graphql +++ b/packages/sdk/typescript/subgraph/schema.graphql @@ -378,3 +378,14 @@ type LeaderStatistics @entity { id: ID! leaders: BigInt! } + +type Transaction @entity { + id: ID! + block: BigInt! + timestamp: BigInt! + txHash: Bytes! + from: Bytes! + to: Bytes + value: BigInt + method: String! +} diff --git a/packages/sdk/typescript/subgraph/src/mapping/Escrow.ts b/packages/sdk/typescript/subgraph/src/mapping/Escrow.ts index 9d28112450..ce080b14b5 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/Escrow.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/Escrow.ts @@ -24,6 +24,7 @@ import { Address, BigInt, dataSource } from '@graphprotocol/graph-ts'; import { ZERO_BI, ONE_BI } from './utils/number'; import { toEventId } from './utils/event'; import { getEventDayData } from './utils/dayUpdates'; +import { createTransaction } from './utils/transaction'; export const STATISTICS_ENTITY_ID = 'escrow-statistics-id'; @@ -69,6 +70,7 @@ export function createOrLoadWorker(address: Address): Worker { } export function handlePending(event: Pending): void { + createTransaction(event, 'setup'); // Create SetupEvent entity const setupEventEntity = new SetupEvent(toEventId(event)); setupEventEntity.block = event.block.number; @@ -172,6 +174,7 @@ export function handlePending(event: Pending): void { } export function handleIntermediateStorage(event: IntermediateStorage): void { + createTransaction(event, 'storeResults'); // Create StoreResultsEvent entity const eventEntity = new StoreResultsEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -206,6 +209,7 @@ export function handleIntermediateStorage(event: IntermediateStorage): void { } export function handleBulkTransfer(event: BulkTransfer): void { + createTransaction(event, 'bulkTransfer'); // Create BulkPayoutEvent entity const eventEntity = new BulkPayoutEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -287,6 +291,7 @@ export function handleBulkTransfer(event: BulkTransfer): void { } export function handleCancelled(event: Cancelled): void { + createTransaction(event, 'cancel'); // Create CancelledStatusEvent entity const eventEntity = new CancelledStatusEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -320,6 +325,7 @@ export function handleCancelled(event: Cancelled): void { } export function handleCompleted(event: Completed): void { + createTransaction(event, 'complete'); // Create CompletedStatusEvent entity const eventEntity = new CompletedStatusEvent(toEventId(event)); eventEntity.block = event.block.number; diff --git a/packages/sdk/typescript/subgraph/src/mapping/EscrowFactory.ts b/packages/sdk/typescript/subgraph/src/mapping/EscrowFactory.ts index 5d119b1b99..7691373439 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/EscrowFactory.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/EscrowFactory.ts @@ -6,10 +6,12 @@ import { Escrow } from '../../generated/schema'; import { Escrow as EscrowTemplate } from '../../generated/templates'; import { createOrLoadEscrowStatistics } from './Escrow'; import { createOrLoadLeader } from './Staking'; +import { createTransaction } from './utils/transaction'; import { getEventDayData } from './utils/dayUpdates'; import { ONE_BI, ZERO_BI } from './utils/number'; export function handleLaunched(event: Launched): void { + createTransaction(event, 'createEscrow'); // Create Escrow entity const entity = new Escrow(event.params.escrow.toHex()); @@ -48,6 +50,7 @@ export function handleLaunched(event: Launched): void { } export function handleLaunchedV2(event: LaunchedV2): void { + createTransaction(event, 'createEscrow'); // Create Escrow entity const entity = new Escrow(event.params.escrow.toHex()); diff --git a/packages/sdk/typescript/subgraph/src/mapping/HMToken.ts b/packages/sdk/typescript/subgraph/src/mapping/HMToken.ts index a1223a1c2d..4cc612dda0 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/HMToken.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/HMToken.ts @@ -22,6 +22,7 @@ import { toEventDayId, toEventId } from './utils/event'; import { ONE_BI, ZERO_BI } from './utils/number'; import { createOrLoadEscrowStatistics, createOrLoadWorker } from './Escrow'; import { getEventDayData } from './utils/dayUpdates'; +import { createTransaction } from './utils/transaction'; export const HMT_STATISTICS_ENTITY_ID = 'hmt-statistics-id'; @@ -132,6 +133,10 @@ export function handleTransfer(event: Transfer): void { event.params._value ); escrow.save(); + + createTransaction(event, 'fund', event.params._to, event.params._value); + } else { + createTransaction(event, 'transfer', event.params._to, event.params._value); } // Update holders @@ -197,6 +202,7 @@ export function handleTransfer(event: Transfer): void { } export function handleBulkTransfer(event: BulkTransfer): void { + createTransaction(event, 'transferBulk'); // Create HMTBulkTransferEvent entity const eventEntity = new HMTBulkTransferEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -214,6 +220,12 @@ export function handleBulkTransfer(event: BulkTransfer): void { } export function handleApproval(event: Approval): void { + createTransaction( + event, + 'approve', + event.params._spender, + event.params._value + ); // Create HMTApprovalEvent entity const eventEntity = new HMTApprovalEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -232,6 +244,7 @@ export function handleApproval(event: Approval): void { } export function handleBulkApproval(event: BulkApproval): void { + createTransaction(event, 'increaseApprovalBulk'); // Create HMTBulkApprovalEvent entity const eventEntity = new HMTBulkApprovalEvent(toEventId(event)); eventEntity.block = event.block.number; diff --git a/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts b/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts index 7b41de6dd7..f891e46dc0 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts @@ -9,6 +9,7 @@ import { createOrLoadLeader } from './Staking'; import { toEventId } from './utils/event'; import { isValidEthAddress } from './utils/ethAdrress'; import { Address, BigInt } from '@graphprotocol/graph-ts'; +import { createTransaction } from './utils/transaction'; export function createOrLoadLeaderURL(leader: Leader, key: string): LeaderURL { const entityId = `${leader.address.toHex()}-${key}`; @@ -39,6 +40,7 @@ export function createOrLoadReputationNetwork( } export function handleDataSaved(event: DataSaved): void { + createTransaction(event, 'set'); // Create KVStoreSetEvent entity const eventEntity = new KVStoreSetEvent(toEventId(event)); eventEntity.block = event.block.number; diff --git a/packages/sdk/typescript/subgraph/src/mapping/RewardPool.ts b/packages/sdk/typescript/subgraph/src/mapping/RewardPool.ts index f8ae230297..ce5bae0fcc 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/RewardPool.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/RewardPool.ts @@ -2,8 +2,10 @@ import { RewardAddedEvent } from '../../generated/schema'; import { RewardAdded } from '../../generated/RewardPool/RewardPool'; import { createOrLoadLeader } from './Staking'; import { toEventId } from './utils/event'; +import { createTransaction } from './utils/transaction'; export function handleRewardAdded(event: RewardAdded): void { + createTransaction(event, 'addReward'); // Create RewardAddedEvent entity const eventEntity = new RewardAddedEvent(toEventId(event)); eventEntity.block = event.block.number; diff --git a/packages/sdk/typescript/subgraph/src/mapping/Staking.ts b/packages/sdk/typescript/subgraph/src/mapping/Staking.ts index 951073c41a..0da74a8156 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/Staking.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/Staking.ts @@ -19,6 +19,7 @@ import { import { Address } from '@graphprotocol/graph-ts'; import { ONE_BI, ZERO_BI } from './utils/number'; import { toEventId } from './utils/event'; +import { createTransaction } from './utils/transaction'; export const STATISTICS_ENTITY_ID = 'leader-statistics-id'; @@ -62,6 +63,7 @@ export function createOrLoadLeader(address: Address): Leader { } export function handleStakeDeposited(event: StakeDeposited): void { + createTransaction(event, 'stake', event.transaction.to, event.params.tokens); // Create StakeDepostiedEvent entity const eventEntity = new StakeDepositedEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -91,6 +93,12 @@ export function handleStakeDeposited(event: StakeDeposited): void { } export function handleStakeLocked(event: StakeLocked): void { + createTransaction( + event, + 'unstake', + event.transaction.to, + event.params.tokens + ); // Create StakeLockedEvent entity const eventEntity = new StakeLockedEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -109,6 +117,12 @@ export function handleStakeLocked(event: StakeLocked): void { } export function handleStakeWithdrawn(event: StakeWithdrawn): void { + createTransaction( + event, + 'withdraw', + event.transaction.to, + event.params.tokens + ); // Create StakeWithdrawnEvent entity const eventEntity = new StakeWithdrawnEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -130,6 +144,12 @@ export function handleStakeWithdrawn(event: StakeWithdrawn): void { } export function handleStakeAllocated(event: StakeAllocated): void { + createTransaction( + event, + 'allocate', + event.params.escrowAddress, + event.params.tokens + ); // Create StakeAllocatedEvent entity const eventEntity = new StakeAllocatedEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -147,6 +167,12 @@ export function handleStakeAllocated(event: StakeAllocated): void { } export function handleAllocationClosed(event: AllocationClosed): void { + createTransaction( + event, + 'closeAllocation', + event.params.escrowAddress, + event.params.tokens + ); // Create AllocationClosedEvent entity const eventEntity = new AllocationClosedEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -164,6 +190,7 @@ export function handleAllocationClosed(event: AllocationClosed): void { } export function handleStakeSlashed(event: StakeSlashed): void { + createTransaction(event, 'slash', event.params.slasher, event.params.tokens); // Create StakeSlashedEvent entity const eventEntity = new StakeSlashedEvent(toEventId(event)); eventEntity.block = event.block.number; diff --git a/packages/sdk/typescript/subgraph/src/mapping/legacy/Escrow.ts b/packages/sdk/typescript/subgraph/src/mapping/legacy/Escrow.ts index e4c6a62bdd..d06dade9dc 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/legacy/Escrow.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/legacy/Escrow.ts @@ -19,6 +19,7 @@ import { createOrLoadEscrowStatistics } from '../Escrow'; import { ONE_BI } from '../utils/number'; import { toEventId } from '../utils/event'; import { getEventDayData } from '../utils/dayUpdates'; +import { createTransaction } from '../utils/transaction'; enum EscrowStatuses { Launched, @@ -30,6 +31,7 @@ enum EscrowStatuses { } export function handlePending(event: Pending): void { + createTransaction(event, 'setup'); // Create SetupEvent entity const setupEventEntity = new SetupEvent(toEventId(event)); setupEventEntity.block = event.block.number; @@ -101,6 +103,7 @@ export function handlePending(event: Pending): void { } export function handleIntermediateStorage(event: IntermediateStorage): void { + createTransaction(event, 'storeResults'); // Create StoreResultsEvent entity const eventEntity = new StoreResultsEvent(toEventId(event)); eventEntity.block = event.block.number; @@ -135,6 +138,7 @@ export function handleIntermediateStorage(event: IntermediateStorage): void { } export function handleBulkTransfer(event: BulkTransfer): void { + createTransaction(event, 'bulkTransfer'); // Create BulkPayoutEvent entity const eventEntity = new BulkPayoutEvent(toEventId(event)); eventEntity.block = event.block.number; diff --git a/packages/sdk/typescript/subgraph/src/mapping/legacy/EscrowFactory.ts b/packages/sdk/typescript/subgraph/src/mapping/legacy/EscrowFactory.ts index 5bee23b21f..a7737faa16 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/legacy/EscrowFactory.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/legacy/EscrowFactory.ts @@ -5,8 +5,10 @@ import { ONE_BI, ZERO_BI } from '../utils/number'; import { getEventDayData } from '../utils/dayUpdates'; import { createOrLoadEscrowStatistics } from '../Escrow'; import { createOrLoadLeader } from '../Staking'; +import { createTransaction } from '../utils/transaction'; export function handleLaunched(event: Launched): void { + createTransaction(event, 'createEscrow'); // Create Escrow entity const entity = new Escrow(event.params.escrow.toHex()); diff --git a/packages/sdk/typescript/subgraph/src/mapping/utils/transaction.ts b/packages/sdk/typescript/subgraph/src/mapping/utils/transaction.ts new file mode 100644 index 0000000000..a5c0f17692 --- /dev/null +++ b/packages/sdk/typescript/subgraph/src/mapping/utils/transaction.ts @@ -0,0 +1,21 @@ +import { Address, BigInt, ethereum } from '@graphprotocol/graph-ts'; +import { Transaction } from '../../../generated/schema'; + +export function createTransaction( + event: ethereum.Event, + method: string, + to: Address | null = null, + value: BigInt | null = null +): void { + const transaction = new Transaction(event.transaction.hash.toHex()); + + transaction.from = event.transaction.from; + transaction.to = to !== null ? to : event.transaction.to; + transaction.txHash = event.transaction.hash; + transaction.block = event.block.number; + transaction.timestamp = event.block.timestamp; + transaction.value = value !== null ? value : event.transaction.value; + transaction.method = method; + + transaction.save(); +} diff --git a/packages/sdk/typescript/subgraph/tests/escrow-factory/escrow-factory.test.ts b/packages/sdk/typescript/subgraph/tests/escrow-factory/escrow-factory.test.ts index 7ee2d99f58..5c45bfc169 100644 --- a/packages/sdk/typescript/subgraph/tests/escrow-factory/escrow-factory.test.ts +++ b/packages/sdk/typescript/subgraph/tests/escrow-factory/escrow-factory.test.ts @@ -133,5 +133,55 @@ describe('EscrowFactory', () => { 'amountJobsLaunched', '2' ); + + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'txHash', + data1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'method', + 'createEscrow' + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'block', + data1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'from', + data1.transaction.from.toHex() + ); + + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'createEscrow' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); }); }); diff --git a/packages/sdk/typescript/subgraph/tests/escrow/escrow.test.ts b/packages/sdk/typescript/subgraph/tests/escrow/escrow.test.ts index 8f131ffffb..58e7affb49 100644 --- a/packages/sdk/typescript/subgraph/tests/escrow/escrow.test.ts +++ b/packages/sdk/typescript/subgraph/tests/escrow/escrow.test.ts @@ -224,6 +224,36 @@ describe('Escrow', () => { 'recordingOracleFee', '20' ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'txHash', + newPending1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'method', + 'setup' + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'block', + newPending1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'from', + newPending1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle Pending event for new contract, without exchange oracle', () => { @@ -352,6 +382,36 @@ describe('Escrow', () => { 'recordingOracleFee', '20' ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'txHash', + newPending1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'method', + 'setup' + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'block', + newPending1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'from', + newPending1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle Pending event for new contract, with exchange oracle', () => { @@ -492,6 +552,36 @@ describe('Escrow', () => { 'exchangeOracleFee', '30' ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'txHash', + newPending1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'method', + 'setup' + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'block', + newPending1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'from', + newPending1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('should properly handle IntermediateStorage event', () => { @@ -530,6 +620,36 @@ describe('Escrow', () => { ); assert.fieldEquals('StoreResultsEvent', id, 'sender', workerAddressString); assert.fieldEquals('StoreResultsEvent', id, 'intermediateResultsUrl', URL); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'txHash', + newIS.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'method', + 'storeResults' + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'block', + newIS.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'from', + newIS.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle BulkTransfer events', () => { @@ -692,6 +812,36 @@ describe('Escrow', () => { 'finalResultsUrl', 'test.com' ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'txHash', + bulk1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'method', + 'bulkTransfer' + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'block', + bulk1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'from', + bulk1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle Cancelled event', () => { @@ -737,6 +887,36 @@ describe('Escrow', () => { // Escrow assert.fieldEquals('Escrow', escrowAddress.toHex(), 'status', 'Cancelled'); + assert.fieldEquals( + 'Transaction', + newCancelled.transaction.hash.toHex(), + 'txHash', + newCancelled.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newCancelled.transaction.hash.toHex(), + 'method', + 'cancel' + ); + assert.fieldEquals( + 'Transaction', + newCancelled.transaction.hash.toHex(), + 'block', + newCancelled.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newCancelled.transaction.hash.toHex(), + 'from', + newCancelled.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newCancelled.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle Completed event', () => { @@ -782,6 +962,36 @@ describe('Escrow', () => { // Escrow assert.fieldEquals('Escrow', escrowAddress.toHex(), 'status', 'Complete'); + assert.fieldEquals( + 'Transaction', + newCompleted.transaction.hash.toHex(), + 'txHash', + newCompleted.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newCompleted.transaction.hash.toHex(), + 'method', + 'complete' + ); + assert.fieldEquals( + 'Transaction', + newCompleted.transaction.hash.toHex(), + 'block', + newCompleted.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newCompleted.transaction.hash.toHex(), + 'from', + newCompleted.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newCompleted.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); describe('Statistics', () => { diff --git a/packages/sdk/typescript/subgraph/tests/hmt/hmt.test.ts b/packages/sdk/typescript/subgraph/tests/hmt/hmt.test.ts index 34173dae74..30b89c31ac 100644 --- a/packages/sdk/typescript/subgraph/tests/hmt/hmt.test.ts +++ b/packages/sdk/typescript/subgraph/tests/hmt/hmt.test.ts @@ -131,6 +131,42 @@ describe('HMToken', () => { 'totalFundedAmount', '101' ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'txHash', + transfer.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'method', + 'fund' + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'block', + transfer.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'from', + transfer.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'to', + escrowAddressString + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'value', + '1' + ); }); test('Should properly handle Transfer event to Holder', () => { @@ -248,6 +284,42 @@ describe('HMToken', () => { operatorAddressString ); assert.fieldEquals('Payout', payoutId, 'amount', '1'); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'txHash', + transfer.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'method', + 'transfer' + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'block', + transfer.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'from', + transfer.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'to', + operatorAddressString + ); + assert.fieldEquals( + 'Transaction', + transfer.transaction.hash.toHex(), + 'value', + '1' + ); }); }); @@ -281,6 +353,30 @@ describe('HMToken', () => { ); assert.fieldEquals('HMTBulkTransferEvent', id, 'txId', '1'); assert.fieldEquals('HMTBulkTransferEvent', id, 'bulkCount', '3'); + assert.fieldEquals( + 'Transaction', + bulkTransfer.transaction.hash.toHex(), + 'txHash', + bulkTransfer.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulkTransfer.transaction.hash.toHex(), + 'method', + 'transferBulk' + ); + assert.fieldEquals( + 'Transaction', + bulkTransfer.transaction.hash.toHex(), + 'block', + bulkTransfer.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + bulkTransfer.transaction.hash.toHex(), + 'from', + bulkTransfer.transaction.from.toHex() + ); }); test('Should properly handle Approval event', () => { @@ -324,6 +420,42 @@ describe('HMToken', () => { operatorAddressString ); assert.fieldEquals('HMTApprovalEvent', id, 'amount', '1'); + assert.fieldEquals( + 'Transaction', + approval.transaction.hash.toHex(), + 'txHash', + approval.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + approval.transaction.hash.toHex(), + 'method', + 'approve' + ); + assert.fieldEquals( + 'Transaction', + approval.transaction.hash.toHex(), + 'block', + approval.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + approval.transaction.hash.toHex(), + 'from', + approval.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + approval.transaction.hash.toHex(), + 'to', + operatorAddressString + ); + assert.fieldEquals( + 'Transaction', + approval.transaction.hash.toHex(), + 'value', + '1' + ); }); test('Should properly handle BulkApproval event', () => { @@ -356,6 +488,30 @@ describe('HMToken', () => { ); assert.fieldEquals('HMTBulkApprovalEvent', id, 'txId', '1'); assert.fieldEquals('HMTBulkApprovalEvent', id, 'bulkCount', '3'); + assert.fieldEquals( + 'Transaction', + bulkApproval.transaction.hash.toHex(), + 'txHash', + bulkApproval.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulkApproval.transaction.hash.toHex(), + 'method', + 'increaseApprovalBulk' + ); + assert.fieldEquals( + 'Transaction', + bulkApproval.transaction.hash.toHex(), + 'block', + bulkApproval.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + bulkApproval.transaction.hash.toHex(), + 'from', + bulkApproval.transaction.from.toHex() + ); }); describe('Statistics', () => { diff --git a/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts b/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts index 5bfc8cfdfb..61efa17df3 100644 --- a/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts +++ b/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts @@ -96,6 +96,73 @@ describe('KVStore', () => { assert.fieldEquals('KVStoreSetEvent', id2, 'value', 'Validator'); }); + test('Should properly create a transaction', () => { + const data1 = createDataSavedEvent( + '0xD979105297fB0eee83F7433fC09279cb5B94fFC6', + 'role', + 'Operator', + BigInt.fromI32(10) + ); + const data2 = createDataSavedEvent( + '0x92a2eEF7Ff696BCef98957a0189872680600a959', + 'role', + 'Validator', + BigInt.fromI32(11) + ); + + handleDataSaved(data1); + handleDataSaved(data2); + + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'txHash', + data1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'method', + 'set' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'set' + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'block', + data1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'from', + data1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + }); + test('Should properly update leader role', () => { const data1 = createDataSavedEvent( '0xD979105297fB0eee83F7433fC09279cb5B94fFC6', diff --git a/packages/sdk/typescript/subgraph/tests/legacy/escrow-factory/escrow-factory.test.ts b/packages/sdk/typescript/subgraph/tests/legacy/escrow-factory/escrow-factory.test.ts index 07b6822dc4..af165e660e 100644 --- a/packages/sdk/typescript/subgraph/tests/legacy/escrow-factory/escrow-factory.test.ts +++ b/packages/sdk/typescript/subgraph/tests/legacy/escrow-factory/escrow-factory.test.ts @@ -133,5 +133,55 @@ describe('EscrowFactory', () => { 'amountJobsLaunched', '2' ); + + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'txHash', + data1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'method', + 'createEscrow' + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'block', + data1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'from', + data1.transaction.from.toHex() + ); + + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'createEscrow' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); }); }); diff --git a/packages/sdk/typescript/subgraph/tests/legacy/escrow/escrow.test.ts b/packages/sdk/typescript/subgraph/tests/legacy/escrow/escrow.test.ts index 9f0b7146f9..dd8429dad6 100644 --- a/packages/sdk/typescript/subgraph/tests/legacy/escrow/escrow.test.ts +++ b/packages/sdk/typescript/subgraph/tests/legacy/escrow/escrow.test.ts @@ -182,6 +182,36 @@ describe('Escrow', () => { 'recordingOracle', recordingOracleAddressString ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'txHash', + newPending1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'method', + 'setup' + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'block', + newPending1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'from', + newPending1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newPending1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('should properly handle IntermediateStorage event', () => { @@ -220,6 +250,36 @@ describe('Escrow', () => { ); assert.fieldEquals('StoreResultsEvent', id, 'sender', workerAddressString); assert.fieldEquals('StoreResultsEvent', id, 'intermediateResultsUrl', URL); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'txHash', + newIS.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'method', + 'storeResults' + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'block', + newIS.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'from', + newIS.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + newIS.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle BulkTransfer events with partially paid status', () => { @@ -309,6 +369,36 @@ describe('Escrow', () => { 'status', 'Partially Paid' ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'txHash', + bulk1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'method', + 'bulkTransfer' + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'block', + bulk1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'from', + bulk1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); test('Should properly handle BulkTransfer events with fully paid status', () => { @@ -388,6 +478,36 @@ describe('Escrow', () => { // Escrow assert.fieldEquals('Escrow', escrowAddress.toHex(), 'status', 'Paid'); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'txHash', + bulk1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'method', + 'bulkTransfer' + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'block', + bulk1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'from', + bulk1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + bulk1.transaction.hash.toHex(), + 'to', + escrowAddressString + ); }); describe('Statistics', () => { diff --git a/packages/sdk/typescript/subgraph/tests/reward-pool/reward-pool.test.ts b/packages/sdk/typescript/subgraph/tests/reward-pool/reward-pool.test.ts index 5462e00adb..7fb025b002 100644 --- a/packages/sdk/typescript/subgraph/tests/reward-pool/reward-pool.test.ts +++ b/packages/sdk/typescript/subgraph/tests/reward-pool/reward-pool.test.ts @@ -123,5 +123,53 @@ describe('RewardPool', () => { assert.fieldEquals('Leader', data1.params.slasher.toHex(), 'reward', '30'); assert.fieldEquals('Leader', data2.params.slasher.toHex(), 'reward', '50'); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'txHash', + data1.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'method', + 'addReward' + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'block', + data1.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data1.transaction.hash.toHex(), + 'from', + data1.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'addReward' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); }); }); diff --git a/packages/sdk/typescript/subgraph/tests/staking/staking.test.ts b/packages/sdk/typescript/subgraph/tests/staking/staking.test.ts index 0cfe881428..af58fce820 100644 --- a/packages/sdk/typescript/subgraph/tests/staking/staking.test.ts +++ b/packages/sdk/typescript/subgraph/tests/staking/staking.test.ts @@ -163,6 +163,38 @@ describe('Staking', () => { 'amountStaked', '200' ); + + // Transaction + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'stake' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'value', + '200' + ); }); test('Should properly index StakeLocked events', () => { @@ -291,6 +323,38 @@ describe('Staking', () => { 'lockedUntilTimestamp', '31' ); + + // Transaction + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'unstake' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'value', + '100' + ); }); test('Should properly index StakeWithdrawn events', () => { @@ -427,6 +491,38 @@ describe('Staking', () => { 'amountWithdrawn', '100' ); + + // Transaction + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'withdraw' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'value', + '100' + ); }); test('Should properly index StakeAllocated events', () => { @@ -591,6 +687,38 @@ describe('Staking', () => { 'amountAllocated', '50' ); + + // Transaction + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'allocate' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'value', + '50' + ); }); test('Should properly index StakeSlashed events', () => { @@ -779,6 +907,38 @@ describe('Staking', () => { 'amountSlashed', '10' ); + + // Transaction + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'slash' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'value', + '10' + ); }); test('Should properly index AllocationClosed events', () => { @@ -956,5 +1116,37 @@ describe('Staking', () => { 'amountSlashed', '10' ); + + // Transaction + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'txHash', + data2.transaction.hash.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'method', + 'closeAllocation' + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'block', + data2.block.number.toString() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'from', + data2.transaction.from.toHex() + ); + assert.fieldEquals( + 'Transaction', + data2.transaction.hash.toHex(), + 'value', + '40' + ); }); }); From 1f067e5c764db7a140a52dc21a1a85e1c0ce3c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20L=C3=B3pez?= <50665615+flopez7@users.noreply.github.com> Date: Fri, 7 Jun 2024 08:19:55 +0200 Subject: [PATCH 2/5] Add a method in SDK to fetch current kvstore keys of an address (#2105) Co-authored-by: portuu3 --- ...uman_protocol_sdk.kvstore.kvstore_utils.md | 61 +++++++++ .../python/human_protocol_sdk.transaction.md | 16 +++ ...tocol_sdk.transaction.transaction_utils.md | 94 ++++++++++++++ .../base/classes/BaseEthersClient.md | 6 +- .../encryption/classes/Encryption.md | 12 +- .../encryption/classes/EncryptionUtils.md | 10 +- .../typescript/escrow/classes/EscrowClient.md | 56 ++++----- .../typescript/escrow/classes/EscrowUtils.md | 4 +- docs/sdk/typescript/kvstore/README.md | 1 + .../kvstore/classes/KVStoreClient.md | 22 ++-- .../kvstore/classes/KVStoreUtils.md | 116 ++++++++++++++++++ .../operator/classes/OperatorUtils.md | 8 +- .../staking/classes/StakingClient.md | 36 +++--- .../statistics/classes/StatisticsClient.md | 12 +- .../storage/classes/StorageClient.md | 16 +-- ...man_protocol_sdk.kvstore.kvstore_utils.rst | 7 ++ .../docs/human_protocol_sdk.transaction.rst | 15 +++ ...ocol_sdk.transaction.transaction_utils.rst | 7 ++ .../human_protocol_sdk/constants.py | 2 - .../human_protocol_sdk/escrow/escrow_utils.py | 20 ++- .../human_protocol_sdk/gql/kvstore.py | 25 ++++ .../human_protocol_sdk/kvstore/__init__.py | 1 + .../kvstore/kvstore_utils.py | 110 +++++++++++++++++ .../operator/operator_utils.py | 2 - .../staking/staking_client.py | 2 - .../kvstore/test_kvstore_utils.py | 91 ++++++++++++++ .../src/graphql/queries/kvstore.ts | 23 ++++ .../human-protocol-sdk/src/graphql/types.ts | 9 ++ .../human-protocol-sdk/src/interfaces.ts | 5 + .../human-protocol-sdk/src/kvstore.ts | 113 +++++++++++++++++ .../human-protocol-sdk/test/kvstore.test.ts | 76 +++++++++++- .../sdk/typescript/subgraph/schema.graphql | 9 ++ .../subgraph/src/mapping/KVStore.ts | 20 +++ .../subgraph/tests/kvstore/kvstore.test.ts | 44 +++++++ 34 files changed, 948 insertions(+), 103 deletions(-) create mode 100644 docs/sdk/python/human_protocol_sdk.kvstore.kvstore_utils.md create mode 100644 docs/sdk/python/human_protocol_sdk.transaction.md create mode 100644 docs/sdk/python/human_protocol_sdk.transaction.transaction_utils.md create mode 100644 docs/sdk/typescript/kvstore/classes/KVStoreUtils.md create mode 100644 packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.kvstore.kvstore_utils.rst create mode 100644 packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.rst create mode 100644 packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.transaction_utils.rst create mode 100644 packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/kvstore.py create mode 100644 packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py create mode 100644 packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py create mode 100644 packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/kvstore.ts diff --git a/docs/sdk/python/human_protocol_sdk.kvstore.kvstore_utils.md b/docs/sdk/python/human_protocol_sdk.kvstore.kvstore_utils.md new file mode 100644 index 0000000000..dda731ad85 --- /dev/null +++ b/docs/sdk/python/human_protocol_sdk.kvstore.kvstore_utils.md @@ -0,0 +1,61 @@ +# human_protocol_sdk.kvstore.kvstore_utils module + +Utility class for KVStore-related operations. + +## Code Example + +```python +from human_protocol_sdk.constants import ChainId +from human_protocol_sdk.kvstore import KVStoreUtils + +print( + KVStoreUtils.get_data( + ChainId.POLYGON_AMOY, + "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65" + ) +) +``` + +## Module + +### *class* human_protocol_sdk.kvstore.kvstore_utils.KVStoreData(key, value) + +Bases: `object` + +#### \_\_init_\_(key, value) + +Initializes a KVStoreData instance. + +* **Parameters:** + * **key** (`str`) – Key + * **value** (`str`) – Value + +### *class* human_protocol_sdk.kvstore.kvstore_utils.KVStoreUtils + +Bases: `object` + +A utility class that provides additional KVStore-related functionalities. + +#### *static* get_kvstore_data(chain_id, address) + +Returns the KVStore data for a given address. + +* **Parameters:** + * **chain_id** ([`ChainId`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.ChainId)) – Network in which the KVStore data has been deployed + * **address** (`str`) – Address of the KVStore +* **Return type:** + `Optional`[`List`[[`KVStoreData`](#human_protocol_sdk.kvstore.kvstore_utils.KVStoreData)]] +* **Returns:** + List of KVStore data +* **Example:** + ```python + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.kvstore import KVStoreUtils + + print( + KVStoreUtils.get_kvstore_data( + ChainId.POLYGON_AMOY, + "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65" + ) + ) + ``` diff --git a/docs/sdk/python/human_protocol_sdk.transaction.md b/docs/sdk/python/human_protocol_sdk.transaction.md new file mode 100644 index 0000000000..58fb7d7b25 --- /dev/null +++ b/docs/sdk/python/human_protocol_sdk.transaction.md @@ -0,0 +1,16 @@ +# human_protocol_sdk.transaction package + +This module enables to obtain transaction information from +both the contracts and subgraph. + +## Submodules + +* [human_protocol_sdk.transaction.transaction_utils module](human_protocol_sdk.transaction.transaction_utils.md) + * [Code Example](human_protocol_sdk.transaction.transaction_utils.md#code-example) + * [Module](human_protocol_sdk.transaction.transaction_utils.md#module) + * [`TransactionData`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionData) + * [`TransactionData.__init__()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionData.__init__) + * [`TransactionUtils`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils) + * [`TransactionUtils.get_transaction()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils.get_transaction) + * [`TransactionUtils.get_transactions()`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtils.get_transactions) + * [`TransactionUtilsError`](human_protocol_sdk.transaction.transaction_utils.md#human_protocol_sdk.transaction.transaction_utils.TransactionUtilsError) diff --git a/docs/sdk/python/human_protocol_sdk.transaction.transaction_utils.md b/docs/sdk/python/human_protocol_sdk.transaction.transaction_utils.md new file mode 100644 index 0000000000..f2f50bc9f3 --- /dev/null +++ b/docs/sdk/python/human_protocol_sdk.transaction.transaction_utils.md @@ -0,0 +1,94 @@ +# human_protocol_sdk.transaction.transaction_utils module + +Utility class for transaction-related operations. + +## Code Example + +```python +from human_protocol_sdk.constants import ChainId +from human_protocol_sdk.transaction import TransactionUtils, TransactionFilter + +print( + TransactionUtils.get_transactions( + TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="0x1234567890123456789012345678901234567890", + to_address="0x0987654321098765432109876543210987654321", + start_date=datetime.datetime(2023, 5, 8), + end_date=datetime.datetime(2023, 6, 8), + ) + ) +) +``` + +## Module + +### *class* human_protocol_sdk.transaction.transaction_utils.TransactionData(chain_id, block, hash, from_address, to_address, timestamp, value, method) + +Bases: `object` + +#### \_\_init_\_(chain_id, block, hash, from_address, to_address, timestamp, value, method) + +### *class* human_protocol_sdk.transaction.transaction_utils.TransactionUtils + +Bases: `object` + +A utility class that provides additional transaction-related functionalities. + +#### *static* get_transaction(chain_id, hash) + +Returns the transaction for a given hash. + +* **Parameters:** + * **chain_id** ([`ChainId`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.ChainId)) – Network in which the transaction was executed + * **hash** (`str`) – Hash of the transaction +* **Return type:** + `Optional`[[`TransactionData`](#human_protocol_sdk.transaction.transaction_utils.TransactionData)] +* **Returns:** + Transaction data +* **Example:** + ```python + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.transaction import TransactionUtils + + print( + TransactionUtils.get_transaction( + ChainId.POLYGON_AMOY, + "0x1234567890123456789012345678901234567891" + ) + ) + ``` + +#### *static* get_transactions(filter) + +Get an array of transactions based on the specified filter parameters. + +* **Parameters:** + **filter** ([`TransactionFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.TransactionFilter)) – Object containing all the necessary parameters to filter +* **Return type:** + `List`[[`TransactionData`](#human_protocol_sdk.transaction.transaction_utils.TransactionData)] +* **Returns:** + List of transactions +* **Example:** + ```python + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.transaction import TransactionUtils, TransactionFilter + + print( + TransactionUtils.get_transactions( + TransactionFilter( + networks=[ChainId.POLYGON_AMOY], + from_address="0x1234567890123456789012345678901234567890", + to_address="0x0987654321098765432109876543210987654321", + start_date=datetime.datetime(2023, 5, 8), + end_date=datetime.datetime(2023, 6, 8), + ) + ) + ) + ``` + +### *exception* human_protocol_sdk.transaction.transaction_utils.TransactionUtilsError + +Bases: `Exception` + +Raises when some error happens when getting data from subgraph. diff --git a/docs/sdk/typescript/base/classes/BaseEthersClient.md b/docs/sdk/typescript/base/classes/BaseEthersClient.md index 21deb7e0ca..412b52034b 100644 --- a/docs/sdk/typescript/base/classes/BaseEthersClient.md +++ b/docs/sdk/typescript/base/classes/BaseEthersClient.md @@ -40,7 +40,7 @@ The network information required to connect to the contracts #### Source -[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) +[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) ## Properties @@ -50,7 +50,7 @@ The network information required to connect to the contracts #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -60,4 +60,4 @@ The network information required to connect to the contracts #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) diff --git a/docs/sdk/typescript/encryption/classes/Encryption.md b/docs/sdk/typescript/encryption/classes/Encryption.md index 4e5c85e07c..5389527457 100644 --- a/docs/sdk/typescript/encryption/classes/Encryption.md +++ b/docs/sdk/typescript/encryption/classes/Encryption.md @@ -66,7 +66,7 @@ The private key. #### Source -[encryption.ts:53](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L53) +[encryption.ts:53](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L53) ## Properties @@ -76,7 +76,7 @@ The private key. #### Source -[encryption.ts:46](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L46) +[encryption.ts:46](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L46) ## Methods @@ -128,7 +128,7 @@ const resultMessage = await encription.decrypt('message'); #### Source -[encryption.ts:180](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L180) +[encryption.ts:180](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L180) *** @@ -164,7 +164,7 @@ const resultMessage = await encription.sign('message'); #### Source -[encryption.ts:217](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L217) +[encryption.ts:217](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L217) *** @@ -229,7 +229,7 @@ const resultMessage = await encription.signAndEncrypt('message', publicKeys); #### Source -[encryption.ts:129](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L129) +[encryption.ts:129](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L129) *** @@ -257,4 +257,4 @@ Optional: The passphrase for the private key. #### Source -[encryption.ts:64](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L64) +[encryption.ts:64](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L64) diff --git a/docs/sdk/typescript/encryption/classes/EncryptionUtils.md b/docs/sdk/typescript/encryption/classes/EncryptionUtils.md index 3e4975a765..b94b0c34fe 100644 --- a/docs/sdk/typescript/encryption/classes/EncryptionUtils.md +++ b/docs/sdk/typescript/encryption/classes/EncryptionUtils.md @@ -97,7 +97,7 @@ const result = await EncriptionUtils.encrypt('message', publicKeys); #### Source -[encryption.ts:422](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L422) +[encryption.ts:422](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L422) *** @@ -152,7 +152,7 @@ const result = await EncriptionUtils.generateKeyPair(name, email, passphrase); #### Source -[encryption.ts:360](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L360) +[encryption.ts:360](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L360) *** @@ -184,7 +184,7 @@ const signedData = await EncriptionUtils.getSignedData('message'); #### Source -[encryption.ts:317](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L317) +[encryption.ts:317](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L317) *** @@ -232,7 +232,7 @@ if (isEncrypted) { #### Source -[encryption.ts:471](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L471) +[encryption.ts:471](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L471) *** @@ -280,4 +280,4 @@ const result = await EncriptionUtils.verify('message', publicKey); #### Source -[encryption.ts:284](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L284) +[encryption.ts:284](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L284) diff --git a/docs/sdk/typescript/escrow/classes/EscrowClient.md b/docs/sdk/typescript/escrow/classes/EscrowClient.md index 8d33261f4c..d8dc3d6f80 100644 --- a/docs/sdk/typescript/escrow/classes/EscrowClient.md +++ b/docs/sdk/typescript/escrow/classes/EscrowClient.md @@ -104,7 +104,7 @@ The Runner object to interact with the Ethereum network #### Source -[escrow.ts:127](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L127) +[escrow.ts:127](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L127) ## Properties @@ -114,7 +114,7 @@ The Runner object to interact with the Ethereum network #### Source -[escrow.ts:119](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L119) +[escrow.ts:119](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L119) *** @@ -128,7 +128,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -142,7 +142,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) ## Methods @@ -188,7 +188,7 @@ await escrowClient.abort('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); #### Source -[escrow.ts:835](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L835) +[escrow.ts:835](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L835) *** @@ -239,7 +239,7 @@ await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309 #### Source -[escrow.ts:883](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L883) +[escrow.ts:883](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L883) *** @@ -306,7 +306,7 @@ await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', reci #### Source -[escrow.ts:648](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L648) +[escrow.ts:648](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L648) *** @@ -352,7 +352,7 @@ await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); #### Source -[escrow.ts:751](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L751) +[escrow.ts:751](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L751) *** @@ -398,7 +398,7 @@ await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); #### Source -[escrow.ts:590](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L590) +[escrow.ts:590](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L590) *** @@ -465,7 +465,7 @@ const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trus #### Source -[escrow.ts:413](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L413) +[escrow.ts:413](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L413) *** @@ -522,7 +522,7 @@ const escrowAddress = await escrowClient.createEscrow(tokenAddress, trustedHandl #### Source -[escrow.ts:207](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L207) +[escrow.ts:207](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L207) *** @@ -571,7 +571,7 @@ await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount); #### Source -[escrow.ts:461](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L461) +[escrow.ts:461](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L461) *** @@ -609,7 +609,7 @@ const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e #### Source -[escrow.ts:938](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L938) +[escrow.ts:938](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L938) *** @@ -631,7 +631,7 @@ Escrow address to connect to #### Source -[escrow.ts:167](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L167) +[escrow.ts:167](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L167) *** @@ -669,7 +669,7 @@ const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A3 #### Source -[escrow.ts:1318](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1318) +[escrow.ts:1318](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1318) *** @@ -707,7 +707,7 @@ const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C4 #### Source -[escrow.ts:1356](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1356) +[escrow.ts:1356](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1356) *** @@ -745,7 +745,7 @@ const intemediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62 #### Source -[escrow.ts:1090](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1090) +[escrow.ts:1090](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1090) *** @@ -783,7 +783,7 @@ const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230 #### Source -[escrow.ts:1242](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1242) +[escrow.ts:1242](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1242) *** @@ -821,7 +821,7 @@ const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8 #### Source -[escrow.ts:976](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L976) +[escrow.ts:976](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L976) *** @@ -859,7 +859,7 @@ const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c839 #### Source -[escrow.ts:1014](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1014) +[escrow.ts:1014](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1014) *** @@ -897,7 +897,7 @@ const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A #### Source -[escrow.ts:1204](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1204) +[escrow.ts:1204](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1204) *** @@ -935,7 +935,7 @@ const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230 #### Source -[escrow.ts:1280](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1280) +[escrow.ts:1280](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1280) *** @@ -973,7 +973,7 @@ const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d #### Source -[escrow.ts:1052](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1052) +[escrow.ts:1052](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1052) *** @@ -1011,7 +1011,7 @@ const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4E #### Source -[escrow.ts:1166](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1166) +[escrow.ts:1166](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1166) *** @@ -1049,7 +1049,7 @@ const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8 #### Source -[escrow.ts:1128](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1128) +[escrow.ts:1128](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1128) *** @@ -1110,7 +1110,7 @@ await escrowClient.setup(escrowAddress, escrowConfig); #### Source -[escrow.ts:288](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L288) +[escrow.ts:288](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L288) *** @@ -1164,7 +1164,7 @@ await storeResults.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'h #### Source -[escrow.ts:526](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L526) +[escrow.ts:526](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L526) *** @@ -1196,4 +1196,4 @@ Thrown if the network's chainId is not supported #### Source -[escrow.ts:145](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L145) +[escrow.ts:145](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L145) diff --git a/docs/sdk/typescript/escrow/classes/EscrowUtils.md b/docs/sdk/typescript/escrow/classes/EscrowUtils.md index 5ade7ff16f..a32960395c 100644 --- a/docs/sdk/typescript/escrow/classes/EscrowUtils.md +++ b/docs/sdk/typescript/escrow/classes/EscrowUtils.md @@ -132,7 +132,7 @@ const escrowData = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890 #### Source -[escrow.ts:1633](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1633) +[escrow.ts:1633](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1633) *** @@ -246,4 +246,4 @@ const escrowDatas = await EscrowUtils.getEscrows(filters); #### Source -[escrow.ts:1505](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1505) +[escrow.ts:1505](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1505) diff --git a/docs/sdk/typescript/kvstore/README.md b/docs/sdk/typescript/kvstore/README.md index aa3066f2ed..1436bd8549 100644 --- a/docs/sdk/typescript/kvstore/README.md +++ b/docs/sdk/typescript/kvstore/README.md @@ -11,3 +11,4 @@ ### Classes - [KVStoreClient](classes/KVStoreClient.md) +- [KVStoreUtils](classes/KVStoreUtils.md) diff --git a/docs/sdk/typescript/kvstore/classes/KVStoreClient.md b/docs/sdk/typescript/kvstore/classes/KVStoreClient.md index f84d084807..a6967b4578 100644 --- a/docs/sdk/typescript/kvstore/classes/KVStoreClient.md +++ b/docs/sdk/typescript/kvstore/classes/KVStoreClient.md @@ -104,7 +104,7 @@ The Runner object to interact with the Ethereum network #### Source -[kvstore.ts:100](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L100) +[kvstore.ts:104](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L104) ## Properties @@ -114,7 +114,7 @@ The Runner object to interact with the Ethereum network #### Source -[kvstore.ts:92](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L92) +[kvstore.ts:96](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L96) *** @@ -128,7 +128,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -142,7 +142,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) ## Methods @@ -186,7 +186,7 @@ const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb9226 #### Source -[kvstore.ts:301](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L301) +[kvstore.ts:305](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L305) *** @@ -232,7 +232,7 @@ const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash( #### Source -[kvstore.ts:340](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L340) +[kvstore.ts:344](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L344) *** @@ -270,7 +270,7 @@ const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB882 #### Source -[kvstore.ts:398](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L398) +[kvstore.ts:402](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L402) *** @@ -320,7 +320,7 @@ await kvstoreClient.set('Role', 'RecordingOracle'); #### Source -[kvstore.ts:163](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L163) +[kvstore.ts:167](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L167) *** @@ -372,7 +372,7 @@ await kvstoreClient.set(keys, values); #### Source -[kvstore.ts:206](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L206) +[kvstore.ts:210](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L210) *** @@ -421,7 +421,7 @@ await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url); #### Source -[kvstore.ts:249](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L249) +[kvstore.ts:253](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L253) *** @@ -453,4 +453,4 @@ The Runner object to interact with the Ethereum network #### Source -[kvstore.ts:118](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L118) +[kvstore.ts:122](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L122) diff --git a/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md b/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md new file mode 100644 index 0000000000..20268fc078 --- /dev/null +++ b/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md @@ -0,0 +1,116 @@ +[**@human-protocol/sdk**](../../README.md) • **Docs** + +*** + +[@human-protocol/sdk](../../modules.md) / [kvstore](../README.md) / KVStoreUtils + +# Class: KVStoreUtils + +## Introduction + +Utility class for KVStore-related operations. + +## Installation + +### npm +```bash +npm install @human-protocol/sdk +``` + +### yarn +```bash +yarn install @human-protocol/sdk +``` + +## Code example + +### Signer + +**Using private key (backend)** + +```ts +import { ChainId, KVStoreUtils } from '@human-protocol/sdk'; + +const KVStoreAddresses = new KVStoreUtils.getData({ + networks: [ChainId.POLYGON_AMOY] +}); +``` + +## Constructors + +### new KVStoreUtils() + +> **new KVStoreUtils**(): [`KVStoreUtils`](KVStoreUtils.md) + +#### Returns + +[`KVStoreUtils`](KVStoreUtils.md) + +## Methods + +### getKVStoreData() + +> `static` **getKVStoreData**(`chainId`, `address`): `Promise`\<`IKVStore`[]\> + +This function returns the KVStore data for a given address. + +> This uses Subgraph + +**Input parameters** + +```ts +enum ChainId { + ALL = -1, + MAINNET = 1, + RINKEBY = 4, + GOERLI = 5, + BSC_MAINNET = 56, + BSC_TESTNET = 97, + POLYGON = 137, + POLYGON_MUMBAI = 80001, + POLYGON_AMOY = 80002, + MOONBEAM = 1284, + MOONBASE_ALPHA = 1287, + AVALANCHE = 43114, + AVALANCHE_TESTNET = 43113, + CELO = 42220, + CELO_ALFAJORES = 44787, + LOCALHOST = 1338, +} +``` + +```ts +interface IKVStore { + key: string; + value: string; +} +``` + +#### Parameters + +• **chainId**: `ChainId` + +Network in which the KVStore is deployed + +• **address**: `string` + +Address of the KVStore + +#### Returns + +`Promise`\<`IKVStore`[]\> + +KVStore data + +**Code example** + +```ts +import { ChainId, KVStoreUtils } from '@human-protocol/sdk'; + +const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890"); +console.log(kvStoreData); +``` + +#### Source + +[kvstore.ts:498](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L498) diff --git a/docs/sdk/typescript/operator/classes/OperatorUtils.md b/docs/sdk/typescript/operator/classes/OperatorUtils.md index d8caea3f1f..2e5281cb84 100644 --- a/docs/sdk/typescript/operator/classes/OperatorUtils.md +++ b/docs/sdk/typescript/operator/classes/OperatorUtils.md @@ -48,7 +48,7 @@ const leader = await OperatorUtils.getLeader(ChainId.POLYGON_AMOY, '0x62dD51230A #### Source -[operator.ts:44](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L44) +[operator.ts:44](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L44) *** @@ -83,7 +83,7 @@ const leaders = await OperatorUtils.getLeaders(filter); #### Source -[operator.ts:99](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L99) +[operator.ts:99](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L99) *** @@ -121,7 +121,7 @@ const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLY #### Source -[operator.ts:159](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L159) +[operator.ts:159](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L159) *** @@ -155,4 +155,4 @@ const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_AMOY, '0x62dD5123 #### Source -[operator.ts:211](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L211) +[operator.ts:211](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L211) diff --git a/docs/sdk/typescript/staking/classes/StakingClient.md b/docs/sdk/typescript/staking/classes/StakingClient.md index b41bfdd2dd..87de3db484 100644 --- a/docs/sdk/typescript/staking/classes/StakingClient.md +++ b/docs/sdk/typescript/staking/classes/StakingClient.md @@ -104,7 +104,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:111](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L111) +[staking.ts:111](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L111) ## Properties @@ -114,7 +114,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:102](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L102) +[staking.ts:102](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L102) *** @@ -128,7 +128,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -138,7 +138,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:103](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L103) +[staking.ts:103](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L103) *** @@ -152,7 +152,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) *** @@ -162,7 +162,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:101](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L101) +[staking.ts:101](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L101) *** @@ -172,7 +172,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:100](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L100) +[staking.ts:100](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L100) ## Methods @@ -223,7 +223,7 @@ await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amoun #### Source -[staking.ts:458](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L458) +[staking.ts:458](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L458) *** @@ -268,7 +268,7 @@ await stakingClient.approveStake(amount); #### Source -[staking.ts:203](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L203) +[staking.ts:203](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L203) *** @@ -290,7 +290,7 @@ Escrow address to check against #### Source -[staking.ts:167](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L167) +[staking.ts:167](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L167) *** @@ -337,7 +337,7 @@ await stakingClient.closeAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f' #### Source -[staking.ts:511](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L511) +[staking.ts:511](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L511) *** @@ -383,7 +383,7 @@ await stakingClient.distributeReward('0x62dD51230A30401C455c8398d06F85e4EaB6309f #### Source -[staking.ts:554](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L554) +[staking.ts:554](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L554) *** @@ -421,7 +421,7 @@ const allocationInfo = await stakingClient.getAllocation('0x62dD51230A30401C455c #### Source -[staking.ts:591](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L591) +[staking.ts:591](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L591) *** @@ -478,7 +478,7 @@ await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd #### Source -[staking.ts:387](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L387) +[staking.ts:387](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L387) *** @@ -526,7 +526,7 @@ await stakingClient.approveStake(amount); #### Source -[staking.ts:258](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L258) +[staking.ts:258](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L258) *** @@ -573,7 +573,7 @@ await stakingClient.unstake(amount); #### Source -[staking.ts:303](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L303) +[staking.ts:303](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L303) *** @@ -615,7 +615,7 @@ await stakingClient.withdraw(); #### Source -[staking.ts:349](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L349) +[staking.ts:349](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L349) *** @@ -647,4 +647,4 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:145](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L145) +[staking.ts:145](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L145) diff --git a/docs/sdk/typescript/statistics/classes/StatisticsClient.md b/docs/sdk/typescript/statistics/classes/StatisticsClient.md index 8018c85400..474dbba7f6 100644 --- a/docs/sdk/typescript/statistics/classes/StatisticsClient.md +++ b/docs/sdk/typescript/statistics/classes/StatisticsClient.md @@ -62,7 +62,7 @@ The network information required to connect to the Statistics contract #### Source -[statistics.ts:68](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L68) +[statistics.ts:68](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L68) ## Properties @@ -72,7 +72,7 @@ The network information required to connect to the Statistics contract #### Source -[statistics.ts:61](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L61) +[statistics.ts:61](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L61) ## Methods @@ -136,7 +136,7 @@ const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({ #### Source -[statistics.ts:121](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L121) +[statistics.ts:121](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L121) *** @@ -232,7 +232,7 @@ console.log('HMT statistics from 5/8 - 6/8:', { #### Source -[statistics.ts:394](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L394) +[statistics.ts:394](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L394) *** @@ -314,7 +314,7 @@ console.log( #### Source -[statistics.ts:285](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L285) +[statistics.ts:285](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L285) *** @@ -373,4 +373,4 @@ const workerStatisticsApril = await statisticsClient.getWorkerStatistics({ #### Source -[statistics.ts:196](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L196) +[statistics.ts:196](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L196) diff --git a/docs/sdk/typescript/storage/classes/StorageClient.md b/docs/sdk/typescript/storage/classes/StorageClient.md index 2250a251a2..a63dd5cba0 100644 --- a/docs/sdk/typescript/storage/classes/StorageClient.md +++ b/docs/sdk/typescript/storage/classes/StorageClient.md @@ -77,7 +77,7 @@ Optional. Cloud storage access data. If credentials is not provided - use an ano #### Source -[storage.ts:73](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L73) +[storage.ts:73](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L73) ## Properties @@ -87,7 +87,7 @@ Optional. Cloud storage access data. If credentials is not provided - use an ano #### Source -[storage.ts:64](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L64) +[storage.ts:64](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L64) *** @@ -97,7 +97,7 @@ Optional. Cloud storage access data. If credentials is not provided - use an ano #### Source -[storage.ts:65](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L65) +[storage.ts:65](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L65) ## Methods @@ -141,7 +141,7 @@ const exists = await storageClient.bucketExists('bucket-name'); #### Source -[storage.ts:266](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L266) +[storage.ts:266](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L266) *** @@ -187,7 +187,7 @@ const files = await storageClient.downloadFiles(keys, 'bucket-name'); #### Source -[storage.ts:113](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L113) +[storage.ts:113](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L113) *** @@ -231,7 +231,7 @@ const fileNames = await storageClient.listObjects('bucket-name'); #### Source -[storage.ts:297](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L297) +[storage.ts:297](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L297) *** @@ -282,7 +282,7 @@ const uploadedFiles = await storageClient.uploadFiles(files, 'bucket-name'); #### Source -[storage.ts:201](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L201) +[storage.ts:201](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L201) *** @@ -314,4 +314,4 @@ const file = await storageClient.downloadFileFromUrl('http://localhost/file.json #### Source -[storage.ts:148](https://github.com/humanprotocol/human-protocol/blob/4fdfdddcf617469b657582a44683ec62e5f33c71/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L148) +[storage.ts:148](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L148) diff --git a/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.kvstore.kvstore_utils.rst b/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.kvstore.kvstore_utils.rst new file mode 100644 index 0000000000..f03e99b689 --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.kvstore.kvstore_utils.rst @@ -0,0 +1,7 @@ +human\_protocol\_sdk.kvstore.kvstore\_utils module +================================================== + +.. automodule:: human_protocol_sdk.kvstore.kvstore_utils + :members: + :undoc-members: + :show-inheritance: diff --git a/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.rst b/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.rst new file mode 100644 index 0000000000..cffcd0c213 --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.rst @@ -0,0 +1,15 @@ +human\_protocol\_sdk.transaction package +======================================== + +.. automodule:: human_protocol_sdk.transaction + :members: + :undoc-members: + :show-inheritance: + +Submodules +---------- + +.. toctree:: + :maxdepth: 4 + + human_protocol_sdk.transaction.transaction_utils diff --git a/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.transaction_utils.rst b/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.transaction_utils.rst new file mode 100644 index 0000000000..9c71eeff3f --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/docs/human_protocol_sdk.transaction.transaction_utils.rst @@ -0,0 +1,7 @@ +human\_protocol\_sdk.transaction.transaction\_utils module +========================================================== + +.. automodule:: human_protocol_sdk.transaction.transaction_utils + :members: + :undoc-members: + :show-inheritance: diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py index cbb2f96ff1..0285025e85 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py @@ -296,8 +296,6 @@ class Role(Enum): ARTIFACTS_FOLDER = os.path.join(os.path.dirname(os.path.dirname(__file__)), "artifacts") -GAS_LIMIT = int(os.getenv("GAS_LIMIT", 4712388)) - class KVStoreKeys(Enum): """Enum for KVStore keys""" diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py index 8c113862df..275abfef45 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py @@ -39,8 +39,6 @@ from human_protocol_sdk.escrow.escrow_client import EscrowClientError -GAS_LIMIT = int(os.getenv("GAS_LIMIT", 4712388)) - LOG = logging.getLogger("human_protocol_sdk.escrow") @@ -188,6 +186,13 @@ def get_escrows( "to": int(filter.date_to.timestamp()) if filter.date_to else None, }, ) + + if ( + not escrows_data + or "data" not in escrows_data + or "escrows" not in escrows_data["data"] + ): + return [] escrows_raw = escrows_data["data"]["escrows"] escrows.extend( @@ -283,11 +288,16 @@ def get_escrow( }, ) - escrow = escrow_data["data"]["escrow"] - - if not escrow: + if ( + not escrow_data + or "data" not in escrow_data + or "escrow" not in escrow_data["data"] + or not escrow_data["data"]["escrow"] + ): return None + escrow = escrow_data["data"]["escrow"] + return EscrowData( chain_id=chain_id, id=escrow.get("id", ""), diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/kvstore.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/kvstore.py new file mode 100644 index 0000000000..d4e47f8878 --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/gql/kvstore.py @@ -0,0 +1,25 @@ +kvstore_fragment = """ +fragment KVStoreFields on KVStore { + id + block + timestamp + address + key + value +} +""" + + +def get_kvstore_by_address_query() -> str: + return f""" +query getKVStoreData($address: String!) {{ + kvstores( + where: {{ + address: $address + }} + ) {{ + ...KVStoreFields + }} +}} +{kvstore_fragment} +""" diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/__init__.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/__init__.py index 96b0d8a8bd..4a145ec7bd 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/__init__.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/__init__.py @@ -3,3 +3,4 @@ """ from .kvstore_client import KVStoreClient, KVStoreClientError +from .kvstore_utils import KVStoreUtils, KVStoreData diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py new file mode 100644 index 0000000000..ec31ede449 --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py @@ -0,0 +1,110 @@ +""" +Utility class for KVStore-related operations. + +Code Example +------------ + +.. code-block:: python + + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.kvstore import KVStoreUtils + + print( + KVStoreUtils.get_data( + ChainId.POLYGON_AMOY, + "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65" + ) + ) + +Module +------ +""" + +from datetime import datetime +import logging +import os +from typing import List, Optional, Dict + +from web3 import Web3 + +from human_protocol_sdk.constants import NETWORKS, ChainId +from human_protocol_sdk.utils import get_data_from_subgraph + +from human_protocol_sdk.kvstore.kvstore_client import KVStoreClientError + +LOG = logging.getLogger("human_protocol_sdk.kvstore") + + +class KVStoreData: + def __init__(self, key: str, value: str): + """ + Initializes a KVStoreData instance. + + :param key: Key + :param value: Value + """ + self.key = key + self.value = value + + +class KVStoreUtils: + """ + A utility class that provides additional KVStore-related functionalities. + """ + + @staticmethod + def get_kvstore_data( + chain_id: ChainId, + address: str, + ) -> Optional[List[KVStoreData]]: + """Returns the KVStore data for a given address. + + :param chain_id: Network in which the KVStore data has been deployed + :param address: Address of the KVStore + + :return: List of KVStore data + + :example: + .. code-block:: python + + from human_protocol_sdk.constants import ChainId + from human_protocol_sdk.kvstore import KVStoreUtils + + print( + KVStoreUtils.get_kvstore_data( + ChainId.POLYGON_AMOY, + "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65" + ) + ) + """ + from human_protocol_sdk.gql.kvstore import get_kvstore_by_address_query + + if chain_id.value not in set(chain_id.value for chain_id in ChainId): + raise KVStoreClientError(f"Invalid ChainId") + + if not Web3.is_address(address): + raise KVStoreClientError(f"Invalid KVStore address: {address}") + + network = NETWORKS[ChainId(chain_id)] + + kvstore_data = get_data_from_subgraph( + network["subgraph_url"], + query=get_kvstore_by_address_query(), + params={ + "address": address.lower(), + }, + ) + + if ( + not kvstore_data + or "data" not in kvstore_data + or "kvstores" not in kvstore_data["data"] + ): + return [] + + kvstores = kvstore_data["data"]["kvstores"] + + return [ + KVStoreData(key=kvstore.get("key", ""), value=kvstore.get("value", "")) + for kvstore in kvstores + ] diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py index 97c7f7cf04..0b7264d5a9 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py @@ -28,8 +28,6 @@ from human_protocol_sdk.utils import get_data_from_subgraph from web3 import Web3 -GAS_LIMIT = int(os.getenv("GAS_LIMIT", 4712388)) - LOG = logging.getLogger("human_protocol_sdk.operator") diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py index d501f5c9af..be399fbb38 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/staking/staking_client.py @@ -70,8 +70,6 @@ def get_w3_with_priv_key(priv_key: str): handle_transaction, ) -GAS_LIMIT = int(os.getenv("GAS_LIMIT", 4712388)) - LOG = logging.getLogger("human_protocol_sdk.staking") diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py new file mode 100644 index 0000000000..602745018c --- /dev/null +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py @@ -0,0 +1,91 @@ +import unittest +from unittest.mock import patch +from human_protocol_sdk.constants import NETWORKS, ChainId +from human_protocol_sdk.kvstore import KVStoreUtils, KVStoreClientError +from human_protocol_sdk.gql.kvstore import get_kvstore_by_address_query + + +class TestKVStoreUtils(unittest.TestCase): + def test_get_kvstore_data(self): + with patch( + "human_protocol_sdk.kvstore.kvstore_utils.get_data_from_subgraph" + ) as mock_function: + mock_kvstore_data = [ + { + "id": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65-fee", + "block": "31", + "timestamp": "1717510736", + "address": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", + "key": "fee", + "value": "1", + }, + { + "id": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65-jwt_public_key", + "block": "33", + "timestamp": "1717510740", + "address": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", + "key": "jwt_public_key", + "value": "http://localhost:9000/bucket/public-key.txt", + }, + ] + + mock_function.return_value = { + "data": { + "kvstores": mock_kvstore_data, + } + } + + kvstores = KVStoreUtils.get_kvstore_data( + ChainId.POLYGON_AMOY, + "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", + ) + + mock_function.assert_called_once_with( + NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + query=get_kvstore_by_address_query(), + params={ + "address": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", + }, + ) + self.assertEqual(len(kvstores), 2) + self.assertEqual(kvstores[0].key, "fee") + self.assertEqual(kvstores[0].value, "1") + + def test_get_kvstore_data_empty_data(self): + with patch( + "human_protocol_sdk.kvstore.kvstore_utils.get_data_from_subgraph" + ) as mock_function: + mock_function.return_value = { + "data": { + "kvstores": [], + } + } + + kvstores = KVStoreUtils.get_kvstore_data( + ChainId.POLYGON_AMOY, + "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", + ) + mock_function.assert_called_once_with( + NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + query=get_kvstore_by_address_query(), + params={ + "address": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", + }, + ) + self.assertEqual(kvstores, []) + + def test_get_kvstore_data_invalid_chain_id(self): + with self.assertRaises(ValueError) as cm: + KVStoreUtils.get_kvstore_data( + ChainId(123), "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65" + ) + self.assertEqual("123 is not a valid ChainId", str(cm.exception)) + + def test_get_kvstore_data_invalid_address(self): + with self.assertRaises(KVStoreClientError) as cm: + KVStoreUtils.get_kvstore_data(ChainId.LOCALHOST, "invalid_address") + self.assertEqual("Invalid KVStore address: invalid_address", str(cm.exception)) + + +if __name__ == "__main__": + unittest.main(exit=True) diff --git a/packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/kvstore.ts b/packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/kvstore.ts new file mode 100644 index 0000000000..6af715ef0a --- /dev/null +++ b/packages/sdk/typescript/human-protocol-sdk/src/graphql/queries/kvstore.ts @@ -0,0 +1,23 @@ +import gql from 'graphql-tag'; + +const KVSTORE_FRAGMENT = gql` + fragment KVStoreFields on KVStore { + id + block + timestamp + address + key + value + } +`; + +export const GET_KVSTORE_BY_ADDRESS_QUERY = () => { + return gql` + query getKVStoreData($address: String!) { + kvstores(where: { address: $address }) { + ...KVStoreFields + } + } + ${KVSTORE_FRAGMENT} + `; +}; diff --git a/packages/sdk/typescript/human-protocol-sdk/src/graphql/types.ts b/packages/sdk/typescript/human-protocol-sdk/src/graphql/types.ts index 251c86a467..5ef3cd5be6 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/graphql/types.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/graphql/types.ts @@ -155,3 +155,12 @@ export type DailyTaskData = { export type TaskStatistics = { dailyTasksData: DailyTaskData[]; }; + +export type KVStoreData = { + id: string; + address: string; + key: string; + value: string; + timestamp: Date; + block: number; +}; diff --git a/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts b/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts index c5d869d4da..2f27484419 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/interfaces.ts @@ -109,6 +109,11 @@ export interface IPayoutFilter { to?: Date; } +export interface IKVStore { + key: string; + value: string; +} + export interface ITransaction { block: bigint; hash: string; diff --git a/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts b/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts index f32d8713ae..2a413eb3f4 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts @@ -16,8 +16,12 @@ import { ErrorProviderDoesNotExist, ErrorUnsupportedChainID, } from './error'; +import gqlFetch from 'graphql-request'; import { NetworkData } from './types'; import { isValidUrl } from './utils'; +import { GET_KVSTORE_BY_ADDRESS_QUERY } from './graphql/queries/kvstore'; +import { KVStoreData } from './graphql'; +import { IKVStore } from './interfaces'; /** * ## Introduction * @@ -410,3 +414,112 @@ export class KVStoreClient extends BaseEthersClient { return publicKey; } } + +/** + * ## Introduction + * + * Utility class for KVStore-related operations. + * + * ## Installation + * + * ### npm + * ```bash + * npm install @human-protocol/sdk + * ``` + * + * ### yarn + * ```bash + * yarn install @human-protocol/sdk + * ``` + * + * ## Code example + * + * ### Signer + * + * **Using private key (backend)** + * + * ```ts + * import { ChainId, KVStoreUtils } from '@human-protocol/sdk'; + * + * const KVStoreAddresses = new KVStoreUtils.getData({ + * networks: [ChainId.POLYGON_AMOY] + * }); + * ``` + */ +export class KVStoreUtils { + /** + * This function returns the KVStore data for a given address. + * + * > This uses Subgraph + * + * **Input parameters** + * + * ```ts + * enum ChainId { + * ALL = -1, + * MAINNET = 1, + * RINKEBY = 4, + * GOERLI = 5, + * BSC_MAINNET = 56, + * BSC_TESTNET = 97, + * POLYGON = 137, + * POLYGON_MUMBAI = 80001, + * POLYGON_AMOY = 80002, + * MOONBEAM = 1284, + * MOONBASE_ALPHA = 1287, + * AVALANCHE = 43114, + * AVALANCHE_TESTNET = 43113, + * CELO = 42220, + * CELO_ALFAJORES = 44787, + * LOCALHOST = 1338, + * } + * ``` + * + * ```ts + * interface IKVStore { + * key: string; + * value: string; + * } + * ``` + * + * @param {ChainId} chainId Network in which the KVStore is deployed + * @param {string} address Address of the KVStore + * @returns {Promise} KVStore data + * + * **Code example** + * + * ```ts + * import { ChainId, KVStoreUtils } from '@human-protocol/sdk'; + * + * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890"); + * console.log(kvStoreData); + * ``` + */ + public static async getKVStoreData( + chainId: ChainId, + address: string + ): Promise { + const networkData = NETWORKS[chainId]; + + if (!networkData) { + throw ErrorUnsupportedChainID; + } + + if (address && !ethers.isAddress(address)) { + throw ErrorInvalidAddress; + } + + const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>( + networkData.subgraphUrl, + GET_KVSTORE_BY_ADDRESS_QUERY(), + { address: address.toLowerCase() } + ); + + const kvStoreData = kvstores.map((item) => ({ + key: item.key, + value: item.value, + })); + + return kvStoreData || []; + } +} diff --git a/packages/sdk/typescript/human-protocol-sdk/test/kvstore.test.ts b/packages/sdk/typescript/human-protocol-sdk/test/kvstore.test.ts index 1ffd7f51b2..a76a68d294 100644 --- a/packages/sdk/typescript/human-protocol-sdk/test/kvstore.test.ts +++ b/packages/sdk/typescript/human-protocol-sdk/test/kvstore.test.ts @@ -13,14 +13,22 @@ import { ErrorSigner, ErrorUnsupportedChainID, } from '../src/error'; -import { KVStoreClient } from '../src/kvstore'; +import { KVStoreClient, KVStoreUtils } from '../src/kvstore'; import { NetworkData } from '../src/types'; import { DEFAULT_GAS_PAYER_PRIVKEY } from './utils/constants'; +import * as gqlFetch from 'graphql-request'; +import { GET_KVSTORE_BY_ADDRESS_QUERY } from '../src/graphql/queries/kvstore'; global.fetch = vi.fn().mockResolvedValue({ text: () => Promise.resolve('example'), }); +vi.mock('graphql-request', () => { + return { + default: vi.fn(), + }; +}); + describe('KVStoreClient', () => { let mockProvider: any, mockSigner: any, @@ -587,3 +595,69 @@ describe('KVStoreClient', () => { }); }); }); + +describe('KVStoreUtils', () => { + describe('getKVStoreData', () => { + test('should throw an error if chain id is an unsupported id', async () => { + const chainId = -1; + const address = ethers.ZeroAddress; + + await expect( + KVStoreUtils.getKVStoreData(chainId, address) + ).rejects.toThrow(ErrorUnsupportedChainID); + }); + + test('should throw an error if escrow address is an invalid address', async () => { + const chainId = ChainId.LOCALHOST; + const address = '0x0'; + + await expect( + KVStoreUtils.getKVStoreData(chainId, address) + ).rejects.toThrow(ErrorInvalidAddress); + }); + + test('should successfully get all data for the filter', async () => { + const chainId = ChainId.LOCALHOST; + + const kvstores = [ + { + id: ethers.ZeroAddress + '-fee', + block: '31', + timestamp: '1717510736', + address: ethers.ZeroAddress, + key: 'fee', + value: '1', + }, + { + id: ethers.ZeroAddress + '-jwt_public_key', + block: '33', + timestamp: '1717510740', + address: ethers.ZeroAddress, + key: 'jwt_public_key', + value: 'http://localhost:9000/bucket/public-key.txt', + }, + ]; + + const gqlFetchSpy = vi + .spyOn(gqlFetch, 'default') + .mockResolvedValue({ kvstores }); + + const result = await KVStoreUtils.getKVStoreData( + chainId, + ethers.ZeroAddress + ); + + expect(result).toEqual( + kvstores.map((item) => ({ + key: item.key, + value: item.value, + })) + ); + expect(gqlFetchSpy).toHaveBeenCalledWith( + NETWORKS[ChainId.LOCALHOST]?.subgraphUrl, + GET_KVSTORE_BY_ADDRESS_QUERY(), + { address: ethers.ZeroAddress } + ); + }); + }); +}); diff --git a/packages/sdk/typescript/subgraph/schema.graphql b/packages/sdk/typescript/subgraph/schema.graphql index 7e688bef2e..dbcf938b11 100644 --- a/packages/sdk/typescript/subgraph/schema.graphql +++ b/packages/sdk/typescript/subgraph/schema.graphql @@ -245,6 +245,15 @@ type KVStoreSetEvent @entity { value: String! } +type KVStore @entity { + id: ID! + block: BigInt! + timestamp: BigInt! + address: Bytes! + key: String! + value: String! +} + # Staking type StakeDepositedEvent @entity { id: ID! diff --git a/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts b/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts index f891e46dc0..da20ec6a88 100644 --- a/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts +++ b/packages/sdk/typescript/subgraph/src/mapping/KVStore.ts @@ -1,4 +1,5 @@ import { + KVStore, KVStoreSetEvent, Leader, LeaderURL, @@ -39,6 +40,22 @@ export function createOrLoadReputationNetwork( return reputationNetwork; } +export function createOrUpdateKVStore(event: DataSaved): void { + const kvstoreId = `${event.params.sender.toHex()}-${event.params.key.toString()}`; + let kvstore = KVStore.load(kvstoreId); + + if (!kvstore) { + kvstore = new KVStore(kvstoreId); + kvstore.address = event.params.sender; + kvstore.key = event.params.key; + } + kvstore.block = event.block.number; + kvstore.timestamp = event.block.timestamp; + kvstore.value = event.params.value; + + kvstore.save(); +} + export function handleDataSaved(event: DataSaved): void { createTransaction(event, 'set'); // Create KVStoreSetEvent entity @@ -51,6 +68,9 @@ export function handleDataSaved(event: DataSaved): void { eventEntity.value = event.params.value; eventEntity.save(); + // Update KVStore entity + createOrUpdateKVStore(event); + // Update leader attribute, if necessary const leader = createOrLoadLeader(event.params.sender); diff --git a/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts b/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts index 61efa17df3..d33e102832 100644 --- a/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts +++ b/packages/sdk/typescript/subgraph/tests/kvstore/kvstore.test.ts @@ -430,4 +430,48 @@ describe('KVStore', () => { data1.params.sender.toHexString() ); }); + + test('Should properly update KVStore entity', () => { + const data1 = createDataSavedEvent( + '0xD979105297fB0eee83F7433fC09279cb5B94fFC6', + 'role', + 'Reputation Oracle', + BigInt.fromI32(10) + ); + const data2 = createDataSavedEvent( + '0xD979105297fB0eee83F7433fC09279cb5B94fFC6', + 'role', + 'Job Launcher', + BigInt.fromI32(11) + ); + handleDataSaved(data1); + + assert.fieldEquals( + 'KVStore', + `${data1.params.sender.toHexString()}-${data1.params.key}`, + 'key', + 'role' + ); + assert.fieldEquals( + 'KVStore', + `${data1.params.sender.toHexString()}-${data1.params.key}`, + 'value', + 'Reputation Oracle' + ); + + handleDataSaved(data2); + + assert.fieldEquals( + 'KVStore', + `${data1.params.sender.toHexString()}-${data1.params.key}`, + 'key', + 'role' + ); + assert.fieldEquals( + 'KVStore', + `${data1.params.sender.toHexString()}-${data1.params.key}`, + 'value', + 'Job Launcher' + ); + }); }); From d2f1b0dc33f93dd6396b450d02a885e304f6f146 Mon Sep 17 00:00:00 2001 From: portuu3 <61605646+portuu3@users.noreply.github.com> Date: Fri, 7 Jun 2024 17:39:19 +0200 Subject: [PATCH 3/5] [SDK] Changes to use the graph decentralized network (#2117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * rename subgraph configs * add subgraph api key use * get api key by env variable * fix example * update subgraph urls * fix tests * fix tests * fix sdk docs * fix subgraph tests * Add subgraph api key to python SDK * Make subgraph api key compatible with python-dotenv * update python docs --------- Co-authored-by: Francisco López --- docs/sdk/SUMMARY.md | 32 ++++---- docs/sdk/python/human_protocol_sdk.utils.md | 2 +- .../base/classes/BaseEthersClient.md | 6 +- .../encryption/classes/Encryption.md | 12 +-- .../encryption/classes/EncryptionUtils.md | 10 +-- .../typescript/escrow/classes/EscrowClient.md | 56 ++++++------- .../typescript/escrow/classes/EscrowUtils.md | 4 +- .../kvstore/classes/KVStoreClient.md | 22 ++--- .../kvstore/classes/KVStoreUtils.md | 2 +- .../operator/classes/OperatorUtils.md | 8 +- .../staking/classes/StakingClient.md | 36 ++++---- .../statistics/classes/StatisticsClient.md | 22 +++-- .../storage/classes/StorageClient.md | 16 ++-- .../human_protocol_sdk/constants.py | 82 +++++++++++++++---- .../human_protocol_sdk/escrow/escrow_utils.py | 4 +- .../kvstore/kvstore_utils.py | 2 +- .../operator/operator_utils.py | 8 +- .../statistics/statistics_client.py | 14 ++-- .../transaction/transaction_utils.py | 4 +- .../human_protocol_sdk/utils.py | 25 +++++- .../scripts/run-unit-test.sh | 2 +- .../escrow/test_escrow_utils.py | 10 +-- .../kvstore/test_kvstore_utils.py | 4 +- .../operator/test_operator_utils.py | 31 +++---- .../statistics/test_statistics_client.py | 14 ++-- .../transaction/__init__.py | 0 .../transaction/test_transaction_utils.py | 8 +- .../example/transactions.ts | 21 +++++ .../human-protocol-sdk/src/constants.ts | 64 +++++++++++---- .../human-protocol-sdk/src/error.ts | 3 + .../human-protocol-sdk/src/escrow.ts | 6 +- .../human-protocol-sdk/src/kvstore.ts | 4 +- .../human-protocol-sdk/src/operator.ts | 14 ++-- .../human-protocol-sdk/src/statistics.ts | 18 ++-- .../human-protocol-sdk/src/transaction.ts | 10 +-- .../human-protocol-sdk/src/types.ts | 4 + .../human-protocol-sdk/src/utils.ts | 25 ++++++ .../human-protocol-sdk/test/escrow.test.ts | 2 +- .../test/statistics.test.ts | 10 +-- .../{avalanche-v2.json => avalanche.json} | 0 .../{bsctest-v2.json => bsc-testnet.json} | 0 .../subgraph/config/{bsc-v2.json => bsc.json} | 0 .../config/{mainnet-v2.json => ethereum.json} | 0 .../config/{fuji-v2.json => fuji.json} | 0 .../typescript/subgraph/config/goerli-v2.json | 40 --------- ...base-alpha-v2.json => moonbase-alpha.json} | 0 .../{moonbeam-v2.json => moonbeam.json} | 0 .../typescript/subgraph/config/mumbai-v2.json | 40 --------- .../config/{polygon-v2.json => polygon.json} | 0 .../{xlayer-mainnet.json => xlayer.json} | 0 packages/sdk/typescript/subgraph/package.json | 2 +- 51 files changed, 393 insertions(+), 306 deletions(-) create mode 100644 packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/__init__.py create mode 100644 packages/sdk/typescript/human-protocol-sdk/example/transactions.ts rename packages/sdk/typescript/subgraph/config/{avalanche-v2.json => avalanche.json} (100%) rename packages/sdk/typescript/subgraph/config/{bsctest-v2.json => bsc-testnet.json} (100%) rename packages/sdk/typescript/subgraph/config/{bsc-v2.json => bsc.json} (100%) rename packages/sdk/typescript/subgraph/config/{mainnet-v2.json => ethereum.json} (100%) rename packages/sdk/typescript/subgraph/config/{fuji-v2.json => fuji.json} (100%) delete mode 100644 packages/sdk/typescript/subgraph/config/goerli-v2.json rename packages/sdk/typescript/subgraph/config/{moonbase-alpha-v2.json => moonbase-alpha.json} (100%) rename packages/sdk/typescript/subgraph/config/{moonbeam-v2.json => moonbeam.json} (100%) delete mode 100644 packages/sdk/typescript/subgraph/config/mumbai-v2.json rename packages/sdk/typescript/subgraph/config/{polygon-v2.json => polygon.json} (100%) rename packages/sdk/typescript/subgraph/config/{xlayer-mainnet.json => xlayer.json} (100%) diff --git a/docs/sdk/SUMMARY.md b/docs/sdk/SUMMARY.md index 9e8caeae52..b46d6d3409 100644 --- a/docs/sdk/SUMMARY.md +++ b/docs/sdk/SUMMARY.md @@ -2,22 +2,22 @@ ## Typescript SDK​ -- [Encryption](typescript/modules/encryption.md) - - [Encryption](typescript/classes/encryption.Encryption.md) - - [EncryptionUtils](typescript/classes/encryption.EncryptionUtils.md) -- [Escrow](typescript/modules/escrow.md) - - [EscrowClient](typescript/classes/escrow.EscrowClient.md) - - [EscrowUtils](typescript/classes/escrow.EscrowUtils.md) -- [KVStore](typescript/modules/kvstore.md) - - [KVStoreClient](typescript/classes/kvstore.KVStoreClient.md) -- [Staking](typescript/modules/staking.md) - - [StakingClient](typescript/classes/staking.StakingClient.md) -- [Operator](typescript/modules/operator.md) - - [OperatorUtils](typescript/classes/operator.OperatorUtils.md) -- [Storage](typescript/modules/storage.md) - - [StorageClient](typescript/classes/storage.StorageClient.md) -- [Statistics](typescript/modules/statistics.md) - - [StatisticsClient](typescript/classes/statistics.StatisticsClient.md) +- [Encryption](typescript/encryption/README.md) + - [Encryption](typescript/encryption/classes/Encryption.md) + - [EncryptionUtils](typescript/encryption/classes/EncryptionUtils.md) +- [Escrow](typescript/escrow/escrow.md) + - [EscrowClient](typescript/escrow/classes/EscrowClient.md) + - [EscrowUtils](typescript/escrow/classes/EscrowUtils.md) +- [KVStore](typescript/kvstore/kvstore.md) + - [KVStoreClient](typescript/kvstore/classes/KVStoreClient.md) +- [Staking](typescript/staking/staking.md) + - [StakingClient](typescript/staking/classes/StakingClient.md) +- [Operator](typescript/operator/operator.md) + - [OperatorUtils](typescript/operator/classes/OperatorUtils.md) +- [Storage](typescript/storage/storage.md) + - [StorageClient](typescript/storage/classes/StorageClient.md) +- [Statistics](typescript/statistics/statistics.md) + - [StatisticsClient](typescript/statistics/classes/StatisticsClient.md) ## Python SDK diff --git a/docs/sdk/python/human_protocol_sdk.utils.md b/docs/sdk/python/human_protocol_sdk.utils.md index c959c0dd44..adc9d4cc71 100644 --- a/docs/sdk/python/human_protocol_sdk.utils.md +++ b/docs/sdk/python/human_protocol_sdk.utils.md @@ -9,7 +9,7 @@ Retrieve the contract interface of a given contract. * **Returns:** The contract interface containing the contract abi. -### human_protocol_sdk.utils.get_data_from_subgraph(url, query, params=None) +### human_protocol_sdk.utils.get_data_from_subgraph(network, query, params=None) ### human_protocol_sdk.utils.get_erc20_interface() diff --git a/docs/sdk/typescript/base/classes/BaseEthersClient.md b/docs/sdk/typescript/base/classes/BaseEthersClient.md index 412b52034b..a5d42896c8 100644 --- a/docs/sdk/typescript/base/classes/BaseEthersClient.md +++ b/docs/sdk/typescript/base/classes/BaseEthersClient.md @@ -40,7 +40,7 @@ The network information required to connect to the contracts #### Source -[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) +[base.ts:20](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L20) ## Properties @@ -50,7 +50,7 @@ The network information required to connect to the contracts #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -60,4 +60,4 @@ The network information required to connect to the contracts #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) diff --git a/docs/sdk/typescript/encryption/classes/Encryption.md b/docs/sdk/typescript/encryption/classes/Encryption.md index 5389527457..907bc36e16 100644 --- a/docs/sdk/typescript/encryption/classes/Encryption.md +++ b/docs/sdk/typescript/encryption/classes/Encryption.md @@ -66,7 +66,7 @@ The private key. #### Source -[encryption.ts:53](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L53) +[encryption.ts:53](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L53) ## Properties @@ -76,7 +76,7 @@ The private key. #### Source -[encryption.ts:46](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L46) +[encryption.ts:46](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L46) ## Methods @@ -128,7 +128,7 @@ const resultMessage = await encription.decrypt('message'); #### Source -[encryption.ts:180](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L180) +[encryption.ts:180](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L180) *** @@ -164,7 +164,7 @@ const resultMessage = await encription.sign('message'); #### Source -[encryption.ts:217](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L217) +[encryption.ts:217](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L217) *** @@ -229,7 +229,7 @@ const resultMessage = await encription.signAndEncrypt('message', publicKeys); #### Source -[encryption.ts:129](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L129) +[encryption.ts:129](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L129) *** @@ -257,4 +257,4 @@ Optional: The passphrase for the private key. #### Source -[encryption.ts:64](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L64) +[encryption.ts:64](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L64) diff --git a/docs/sdk/typescript/encryption/classes/EncryptionUtils.md b/docs/sdk/typescript/encryption/classes/EncryptionUtils.md index b94b0c34fe..25fc193056 100644 --- a/docs/sdk/typescript/encryption/classes/EncryptionUtils.md +++ b/docs/sdk/typescript/encryption/classes/EncryptionUtils.md @@ -97,7 +97,7 @@ const result = await EncriptionUtils.encrypt('message', publicKeys); #### Source -[encryption.ts:422](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L422) +[encryption.ts:422](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L422) *** @@ -152,7 +152,7 @@ const result = await EncriptionUtils.generateKeyPair(name, email, passphrase); #### Source -[encryption.ts:360](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L360) +[encryption.ts:360](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L360) *** @@ -184,7 +184,7 @@ const signedData = await EncriptionUtils.getSignedData('message'); #### Source -[encryption.ts:317](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L317) +[encryption.ts:317](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L317) *** @@ -232,7 +232,7 @@ if (isEncrypted) { #### Source -[encryption.ts:471](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L471) +[encryption.ts:471](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L471) *** @@ -280,4 +280,4 @@ const result = await EncriptionUtils.verify('message', publicKey); #### Source -[encryption.ts:284](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L284) +[encryption.ts:284](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/encryption.ts#L284) diff --git a/docs/sdk/typescript/escrow/classes/EscrowClient.md b/docs/sdk/typescript/escrow/classes/EscrowClient.md index d8dc3d6f80..5f333c73a6 100644 --- a/docs/sdk/typescript/escrow/classes/EscrowClient.md +++ b/docs/sdk/typescript/escrow/classes/EscrowClient.md @@ -104,7 +104,7 @@ The Runner object to interact with the Ethereum network #### Source -[escrow.ts:127](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L127) +[escrow.ts:127](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L127) ## Properties @@ -114,7 +114,7 @@ The Runner object to interact with the Ethereum network #### Source -[escrow.ts:119](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L119) +[escrow.ts:119](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L119) *** @@ -128,7 +128,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -142,7 +142,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) ## Methods @@ -188,7 +188,7 @@ await escrowClient.abort('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); #### Source -[escrow.ts:835](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L835) +[escrow.ts:835](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L835) *** @@ -239,7 +239,7 @@ await escrowClient.addTrustedHandlers('0x62dD51230A30401C455c8398d06F85e4EaB6309 #### Source -[escrow.ts:883](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L883) +[escrow.ts:883](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L883) *** @@ -306,7 +306,7 @@ await escrowClient.bulkPayOut('0x62dD51230A30401C455c8398d06F85e4EaB6309f', reci #### Source -[escrow.ts:648](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L648) +[escrow.ts:648](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L648) *** @@ -352,7 +352,7 @@ await escrowClient.cancel('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); #### Source -[escrow.ts:751](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L751) +[escrow.ts:751](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L751) *** @@ -398,7 +398,7 @@ await escrowClient.complete('0x62dD51230A30401C455c8398d06F85e4EaB6309f'); #### Source -[escrow.ts:590](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L590) +[escrow.ts:590](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L590) *** @@ -465,7 +465,7 @@ const escrowAddress = await escrowClient.createAndSetupEscrow(tokenAddress, trus #### Source -[escrow.ts:413](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L413) +[escrow.ts:413](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L413) *** @@ -522,7 +522,7 @@ const escrowAddress = await escrowClient.createEscrow(tokenAddress, trustedHandl #### Source -[escrow.ts:207](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L207) +[escrow.ts:207](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L207) *** @@ -571,7 +571,7 @@ await escrowClient.fund('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amount); #### Source -[escrow.ts:461](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L461) +[escrow.ts:461](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L461) *** @@ -609,7 +609,7 @@ const balance = await escrowClient.getBalance('0x62dD51230A30401C455c8398d06F85e #### Source -[escrow.ts:938](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L938) +[escrow.ts:938](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L938) *** @@ -631,7 +631,7 @@ Escrow address to connect to #### Source -[escrow.ts:167](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L167) +[escrow.ts:167](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L167) *** @@ -669,7 +669,7 @@ const oracleAddress = await escrowClient.getExchangeOracleAddress('0x62dD51230A3 #### Source -[escrow.ts:1318](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1318) +[escrow.ts:1318](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1318) *** @@ -707,7 +707,7 @@ const factoryAddress = await escrowClient.getFactoryAddress('0x62dD51230A30401C4 #### Source -[escrow.ts:1356](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1356) +[escrow.ts:1356](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1356) *** @@ -745,7 +745,7 @@ const intemediateResultsUrl = await escrowClient.getIntermediateResultsUrl('0x62 #### Source -[escrow.ts:1090](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1090) +[escrow.ts:1090](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1090) *** @@ -783,7 +783,7 @@ const jobLauncherAddress = await escrowClient.getJobLauncherAddress('0x62dD51230 #### Source -[escrow.ts:1242](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1242) +[escrow.ts:1242](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1242) *** @@ -821,7 +821,7 @@ const manifestHash = await escrowClient.getManifestHash('0x62dD51230A30401C455c8 #### Source -[escrow.ts:976](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L976) +[escrow.ts:976](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L976) *** @@ -859,7 +859,7 @@ const manifestUrl = await escrowClient.getManifestUrl('0x62dD51230A30401C455c839 #### Source -[escrow.ts:1014](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1014) +[escrow.ts:1014](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1014) *** @@ -897,7 +897,7 @@ const oracleAddress = await escrowClient.getRecordingOracleAddress('0x62dD51230A #### Source -[escrow.ts:1204](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1204) +[escrow.ts:1204](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1204) *** @@ -935,7 +935,7 @@ const oracleAddress = await escrowClient.getReputationOracleAddress('0x62dD51230 #### Source -[escrow.ts:1280](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1280) +[escrow.ts:1280](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1280) *** @@ -973,7 +973,7 @@ const resultsUrl = await escrowClient.getResultsUrl('0x62dD51230A30401C455c8398d #### Source -[escrow.ts:1052](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1052) +[escrow.ts:1052](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1052) *** @@ -1011,7 +1011,7 @@ const status = await escrowClient.getStatus('0x62dD51230A30401C455c8398d06F85e4E #### Source -[escrow.ts:1166](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1166) +[escrow.ts:1166](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1166) *** @@ -1049,7 +1049,7 @@ const tokenAddress = await escrowClient.getTokenAddress('0x62dD51230A30401C455c8 #### Source -[escrow.ts:1128](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1128) +[escrow.ts:1128](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1128) *** @@ -1110,7 +1110,7 @@ await escrowClient.setup(escrowAddress, escrowConfig); #### Source -[escrow.ts:288](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L288) +[escrow.ts:288](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L288) *** @@ -1164,7 +1164,7 @@ await storeResults.storeResults('0x62dD51230A30401C455c8398d06F85e4EaB6309f', 'h #### Source -[escrow.ts:526](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L526) +[escrow.ts:526](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L526) *** @@ -1196,4 +1196,4 @@ Thrown if the network's chainId is not supported #### Source -[escrow.ts:145](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L145) +[escrow.ts:145](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L145) diff --git a/docs/sdk/typescript/escrow/classes/EscrowUtils.md b/docs/sdk/typescript/escrow/classes/EscrowUtils.md index a32960395c..4ed3dbc551 100644 --- a/docs/sdk/typescript/escrow/classes/EscrowUtils.md +++ b/docs/sdk/typescript/escrow/classes/EscrowUtils.md @@ -132,7 +132,7 @@ const escrowData = new EscrowUtils.getEscrow(ChainId.POLYGON_AMOY, "0x1234567890 #### Source -[escrow.ts:1633](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1633) +[escrow.ts:1633](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1633) *** @@ -246,4 +246,4 @@ const escrowDatas = await EscrowUtils.getEscrows(filters); #### Source -[escrow.ts:1505](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1505) +[escrow.ts:1505](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts#L1505) diff --git a/docs/sdk/typescript/kvstore/classes/KVStoreClient.md b/docs/sdk/typescript/kvstore/classes/KVStoreClient.md index a6967b4578..545f6a00f9 100644 --- a/docs/sdk/typescript/kvstore/classes/KVStoreClient.md +++ b/docs/sdk/typescript/kvstore/classes/KVStoreClient.md @@ -104,7 +104,7 @@ The Runner object to interact with the Ethereum network #### Source -[kvstore.ts:104](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L104) +[kvstore.ts:104](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L104) ## Properties @@ -114,7 +114,7 @@ The Runner object to interact with the Ethereum network #### Source -[kvstore.ts:96](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L96) +[kvstore.ts:96](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L96) *** @@ -128,7 +128,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -142,7 +142,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) ## Methods @@ -186,7 +186,7 @@ const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb9226 #### Source -[kvstore.ts:305](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L305) +[kvstore.ts:305](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L305) *** @@ -232,7 +232,7 @@ const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash( #### Source -[kvstore.ts:344](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L344) +[kvstore.ts:344](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L344) *** @@ -270,7 +270,7 @@ const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB882 #### Source -[kvstore.ts:402](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L402) +[kvstore.ts:402](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L402) *** @@ -320,7 +320,7 @@ await kvstoreClient.set('Role', 'RecordingOracle'); #### Source -[kvstore.ts:167](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L167) +[kvstore.ts:167](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L167) *** @@ -372,7 +372,7 @@ await kvstoreClient.set(keys, values); #### Source -[kvstore.ts:210](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L210) +[kvstore.ts:210](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L210) *** @@ -421,7 +421,7 @@ await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url); #### Source -[kvstore.ts:253](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L253) +[kvstore.ts:253](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L253) *** @@ -453,4 +453,4 @@ The Runner object to interact with the Ethereum network #### Source -[kvstore.ts:122](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L122) +[kvstore.ts:122](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L122) diff --git a/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md b/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md index 20268fc078..934e8ac9b1 100644 --- a/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md +++ b/docs/sdk/typescript/kvstore/classes/KVStoreUtils.md @@ -113,4 +113,4 @@ console.log(kvStoreData); #### Source -[kvstore.ts:498](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L498) +[kvstore.ts:498](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts#L498) diff --git a/docs/sdk/typescript/operator/classes/OperatorUtils.md b/docs/sdk/typescript/operator/classes/OperatorUtils.md index 2e5281cb84..ddd7608e5d 100644 --- a/docs/sdk/typescript/operator/classes/OperatorUtils.md +++ b/docs/sdk/typescript/operator/classes/OperatorUtils.md @@ -48,7 +48,7 @@ const leader = await OperatorUtils.getLeader(ChainId.POLYGON_AMOY, '0x62dD51230A #### Source -[operator.ts:44](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L44) +[operator.ts:44](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L44) *** @@ -83,7 +83,7 @@ const leaders = await OperatorUtils.getLeaders(filter); #### Source -[operator.ts:99](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L99) +[operator.ts:99](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L99) *** @@ -121,7 +121,7 @@ const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLY #### Source -[operator.ts:159](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L159) +[operator.ts:155](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L155) *** @@ -155,4 +155,4 @@ const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_AMOY, '0x62dD5123 #### Source -[operator.ts:211](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L211) +[operator.ts:207](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/operator.ts#L207) diff --git a/docs/sdk/typescript/staking/classes/StakingClient.md b/docs/sdk/typescript/staking/classes/StakingClient.md index 87de3db484..9ea7dab7a2 100644 --- a/docs/sdk/typescript/staking/classes/StakingClient.md +++ b/docs/sdk/typescript/staking/classes/StakingClient.md @@ -104,7 +104,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:111](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L111) +[staking.ts:111](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L111) ## Properties @@ -114,7 +114,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:102](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L102) +[staking.ts:102](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L102) *** @@ -128,7 +128,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) +[base.ts:12](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L12) *** @@ -138,7 +138,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:103](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L103) +[staking.ts:103](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L103) *** @@ -152,7 +152,7 @@ The Runner object to interact with the Ethereum network #### Source -[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) +[base.ts:11](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/base.ts#L11) *** @@ -162,7 +162,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:101](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L101) +[staking.ts:101](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L101) *** @@ -172,7 +172,7 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:100](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L100) +[staking.ts:100](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L100) ## Methods @@ -223,7 +223,7 @@ await stakingClient.allocate('0x62dD51230A30401C455c8398d06F85e4EaB6309f', amoun #### Source -[staking.ts:458](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L458) +[staking.ts:458](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L458) *** @@ -268,7 +268,7 @@ await stakingClient.approveStake(amount); #### Source -[staking.ts:203](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L203) +[staking.ts:203](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L203) *** @@ -290,7 +290,7 @@ Escrow address to check against #### Source -[staking.ts:167](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L167) +[staking.ts:167](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L167) *** @@ -337,7 +337,7 @@ await stakingClient.closeAllocation('0x62dD51230A30401C455c8398d06F85e4EaB6309f' #### Source -[staking.ts:511](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L511) +[staking.ts:511](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L511) *** @@ -383,7 +383,7 @@ await stakingClient.distributeReward('0x62dD51230A30401C455c8398d06F85e4EaB6309f #### Source -[staking.ts:554](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L554) +[staking.ts:554](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L554) *** @@ -421,7 +421,7 @@ const allocationInfo = await stakingClient.getAllocation('0x62dD51230A30401C455c #### Source -[staking.ts:591](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L591) +[staking.ts:591](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L591) *** @@ -478,7 +478,7 @@ await stakingClient.slash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', '0xf39Fd #### Source -[staking.ts:387](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L387) +[staking.ts:387](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L387) *** @@ -526,7 +526,7 @@ await stakingClient.approveStake(amount); #### Source -[staking.ts:258](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L258) +[staking.ts:258](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L258) *** @@ -573,7 +573,7 @@ await stakingClient.unstake(amount); #### Source -[staking.ts:303](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L303) +[staking.ts:303](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L303) *** @@ -615,7 +615,7 @@ await stakingClient.withdraw(); #### Source -[staking.ts:349](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L349) +[staking.ts:349](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L349) *** @@ -647,4 +647,4 @@ The Runner object to interact with the Ethereum network #### Source -[staking.ts:145](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L145) +[staking.ts:145](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/staking.ts#L145) diff --git a/docs/sdk/typescript/statistics/classes/StatisticsClient.md b/docs/sdk/typescript/statistics/classes/StatisticsClient.md index 474dbba7f6..c1192d912a 100644 --- a/docs/sdk/typescript/statistics/classes/StatisticsClient.md +++ b/docs/sdk/typescript/statistics/classes/StatisticsClient.md @@ -62,7 +62,7 @@ The network information required to connect to the Statistics contract #### Source -[statistics.ts:68](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L68) +[statistics.ts:69](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L69) ## Properties @@ -72,7 +72,17 @@ The network information required to connect to the Statistics contract #### Source -[statistics.ts:61](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L61) +[statistics.ts:61](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L61) + +*** + +### subgraphUrl + +> **subgraphUrl**: `string` + +#### Source + +[statistics.ts:62](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L62) ## Methods @@ -136,7 +146,7 @@ const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({ #### Source -[statistics.ts:121](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L121) +[statistics.ts:123](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L123) *** @@ -232,7 +242,7 @@ console.log('HMT statistics from 5/8 - 6/8:', { #### Source -[statistics.ts:394](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L394) +[statistics.ts:396](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L396) *** @@ -314,7 +324,7 @@ console.log( #### Source -[statistics.ts:285](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L285) +[statistics.ts:287](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L287) *** @@ -373,4 +383,4 @@ const workerStatisticsApril = await statisticsClient.getWorkerStatistics({ #### Source -[statistics.ts:196](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L196) +[statistics.ts:198](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts#L198) diff --git a/docs/sdk/typescript/storage/classes/StorageClient.md b/docs/sdk/typescript/storage/classes/StorageClient.md index a63dd5cba0..0b9d647b7f 100644 --- a/docs/sdk/typescript/storage/classes/StorageClient.md +++ b/docs/sdk/typescript/storage/classes/StorageClient.md @@ -77,7 +77,7 @@ Optional. Cloud storage access data. If credentials is not provided - use an ano #### Source -[storage.ts:73](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L73) +[storage.ts:73](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L73) ## Properties @@ -87,7 +87,7 @@ Optional. Cloud storage access data. If credentials is not provided - use an ano #### Source -[storage.ts:64](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L64) +[storage.ts:64](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L64) *** @@ -97,7 +97,7 @@ Optional. Cloud storage access data. If credentials is not provided - use an ano #### Source -[storage.ts:65](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L65) +[storage.ts:65](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L65) ## Methods @@ -141,7 +141,7 @@ const exists = await storageClient.bucketExists('bucket-name'); #### Source -[storage.ts:266](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L266) +[storage.ts:266](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L266) *** @@ -187,7 +187,7 @@ const files = await storageClient.downloadFiles(keys, 'bucket-name'); #### Source -[storage.ts:113](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L113) +[storage.ts:113](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L113) *** @@ -231,7 +231,7 @@ const fileNames = await storageClient.listObjects('bucket-name'); #### Source -[storage.ts:297](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L297) +[storage.ts:297](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L297) *** @@ -282,7 +282,7 @@ const uploadedFiles = await storageClient.uploadFiles(files, 'bucket-name'); #### Source -[storage.ts:201](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L201) +[storage.ts:201](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L201) *** @@ -314,4 +314,4 @@ const file = await storageClient.downloadFileFromUrl('http://localhost/file.json #### Source -[storage.ts:148](https://github.com/humanprotocol/human-protocol/blob/c31b0fe05d1fe8709b826dd2d3d55568a13b7bf9/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L148) +[storage.ts:148](https://github.com/humanprotocol/human-protocol/blob/5c3ff98d933709d76ff6e1e712664f4ec3029081/packages/sdk/typescript/human-protocol-sdk/src/storage.ts#L148) diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py index 0285025e85..c6ffb97e5a 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/constants.py @@ -30,7 +30,10 @@ class ChainId(Enum): "title": "Ethereum", "scan_url": "https://etherscan.io", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v2" + "https://api.studio.thegraph.com/query/74256/ethereum/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BtC96WCK6ZpZ35v94MK6rZNiBzDEZYHFzDmhMYyZ369D" ), "hmt_address": "0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867", "factory_address": "0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a", @@ -46,6 +49,7 @@ class ChainId(Enum): "subgraph_url": ( "https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v2" ), + "subgraph_url_api_key": "", "hmt_address": "0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317", "factory_address": "0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c", "staking_address": "0xf46B45Df3d956369726d8Bd93Ba33963Ab692920", @@ -60,7 +64,10 @@ class ChainId(Enum): "title": "Sepolia", "scan_url": "https://sepolia.etherscan.io", "subgraph_url": ( - "https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-sepolia/api" + "https://api.studio.thegraph.com/query/74256/sepolia/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/UMLaZHtLE9LxzDyvBLBgfWj4erzYzYMeGUbQtxtyMaE" ), "hmt_address": "0x792abbcC99c01dbDec49c9fa9A828a186Da45C33", "factory_address": "0xD6D347ba6987519B4e42EcED43dF98eFf5465a23", @@ -73,7 +80,12 @@ class ChainId(Enum): ChainId.BSC_MAINNET: { "title": "Binance Smart Chain", "scan_url": "https://bscscan.com", - "subgraph_url": "https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v2", + "subgraph_url": ( + "https://api.studio.thegraph.com/query/74256/bsc/version/latest" + ), + "subgraph_url_api_key": ( + "hthttps://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/JBJPC3YmRSNjyjRTTpazhhSX5CCZ4CeBx6ptRsM8PCBb" + ), "hmt_address": "0x711Fd6ab6d65A98904522d4e3586F492B989c527", "factory_address": "0x92FD968AcBd521c232f5fB8c33b342923cC72714", "staking_address": "0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C", @@ -86,7 +98,10 @@ class ChainId(Enum): "title": "Binance Smart Chain (Testnet)", "scan_url": "https://testnet.bscscan.com", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v2" + "https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BnaC4CDqgdbGvcgM7KoZ6d7Yeebsm7NvLFrr61Lxg6Ao" ), "hmt_address": "0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d", "factory_address": "0x2bfA592DBDaF434DDcbb893B1916120d181DAD18", @@ -102,7 +117,10 @@ class ChainId(Enum): "title": "Polygon", "scan_url": "https://polygonscan.com", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2" + "https://api.studio.thegraph.com/query/74256/polygon/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/HHYwCHBvDrjckpNB4jbB8k63pSot6rGtBYLBygGji3vD" ), "hmt_address": "0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF", "factory_address": "0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB", @@ -120,6 +138,7 @@ class ChainId(Enum): "subgraph_url": ( "https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v2" ), + "subgraph_url_api_key": "", "hmt_address": "0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4", "factory_address": "0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d", "staking_address": "0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac", @@ -134,7 +153,10 @@ class ChainId(Enum): "title": "Polygon Amoy", "scan_url": "https://www.oklink.com/amoy", "subgraph_url": ( - "https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-amoy/api" + "https://api.studio.thegraph.com/query/74256/amoy/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/FmdCVzHV3bB4abPVYtBALtBHr7ZRZmZ67m5c432S7GZH" ), "hmt_address": "0x792abbcC99c01dbDec49c9fa9A828a186Da45C33", "factory_address": "0xAFf5a986A530ff839d49325A5dF69F96627E8D29", @@ -148,7 +170,10 @@ class ChainId(Enum): "title": "Moonbeam", "scan_url": "https://moonbeam.moonscan.io", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v2" + "https://api.studio.thegraph.com/query/74256/moonbeam/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BH5Sm6exn76o5frV5VeCufChB43DCfMXCQsdtWt4AuQP" ), "hmt_address": "0x3b25BC1dC591D24d60560d0135D6750A561D4764", "factory_address": "0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a", @@ -164,7 +189,10 @@ class ChainId(Enum): "title": "Moonbase Alpha", "scan_url": "https://moonbase.moonscan.io/", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v2" + "https://api.studio.thegraph.com/query/74256/moonbase-alpha/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/AmmRkJszUbjfUwHubcRkU6CfG1Q9psRWRbbHADVmsLjE" ), "hmt_address": "0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3", "factory_address": "0x5e622FF522D81aa426f082bDD95210BC25fCA7Ed", @@ -178,7 +206,10 @@ class ChainId(Enum): "title": "Avalanche C-Chain Mainnet", "scan_url": "https://snowtrace.io", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche-v2" + "https://api.studio.thegraph.com/query/74256/avalanche/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/FweDaDWZ6ZDcsA63wsjnWgdgw4aCbkiVQYMYvtcP5p2u" ), "hmt_address": "0x12365293cb6477d4fc2686e46BB97E3Fb64f1550", "factory_address": "0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a", @@ -193,7 +224,12 @@ class ChainId(Enum): ChainId.AVALANCHE_TESTNET: { "title": "Fuji C-Chain", "scan_url": "https://testnet.snowtrace.io", - "subgraph_url": "https://api.thegraph.com/subgraphs/name/humanprotocol/fuji-v2", + "subgraph_url": ( + "https://api.studio.thegraph.com/query/74256/fuji/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/CnZCDsWziQF3jNoqgQMkmJbF9frof5osM3hN5eUgyL5u" + ), "hmt_address": "0x9406d5c635AD22b0d76c75E52De57A2177919ca3", "factory_address": "0x56C2ba540726ED4f46E7a134b6b9Ee9C867FcF92", "staking_address": "0x9890473B0b93E24d6D1a8Dfb739D577C6f25FFd3", @@ -207,7 +243,12 @@ class ChainId(Enum): ChainId.CELO: { "title": "Celo", "scan_url": "https://celoscan.io/", - "subgraph_url": "https://api.thegraph.com/subgraphs/name/humanprotocol/celo", + "subgraph_url": ( + "https://api.studio.thegraph.com/query/74256/celo/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/HTgMnYWGsdsw41o8dyph1bwhotuXh6va3L8r8DGgLjsA" + ), "hmt_address": "0x19Ead835951493A763c96910255d5eeF147E914F", "factory_address": "0xc90B43a5d576D9d8026c48904dfbaED50C15Fa08", "staking_address": "0x34cD3Bd6B16c559f321799b516dE61E12017fFd1", @@ -220,7 +261,10 @@ class ChainId(Enum): "title": "Celo", "scan_url": "https://alfajores.celoscan.io/", "subgraph_url": ( - "https://api.thegraph.com/subgraphs/name/humanprotocol/celo-alfajores" + "https://api.studio.thegraph.com/query/74256/celo-alfajores/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/EGWCWuzBNkbypW8ipRKuyGwq8azoCy6LKKosGgSPMGRD" ), "hmt_address": "0x2736B33455A872dC478E1E004106D04c35472468", "factory_address": "0x86Af9f6Cd34B69Db1B202223C6d6D109f2491569", @@ -234,7 +278,10 @@ class ChainId(Enum): "title": "XLayer", "scan_url": "https://www.oklink.com/xlayer", "subgraph_url": ( - "https://gateway-arbitrum.network.thegraph.com/api/b376e45c321d3fcd7d659f9532f0a464/subgraphs/id/CrratkbjCraj1BZLgJmck1GGxbMb2Y2iPZiW4Lh5DdcX" + "https://api.studio.thegraph.com/query/74256/xlayer/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/CrratkbjCraj1BZLgJmck1GGxbMb2Y2iPZiW4Lh5DdcX" ), "hmt_address": "0x10acbe3b9e6a2ff7f341e5cbf4b6617741ff44aa", "factory_address": "0x4949C9DFFD83F0D5Ab0AB24C57C4D403D5c20C15", @@ -248,7 +295,10 @@ class ChainId(Enum): "title": "X Layer Testnet", "scan_url": "https://www.oklink.com/oktc-test", "subgraph_url": ( - "https://gateway-arbitrum.network.thegraph.com/api/b376e45c321d3fcd7d659f9532f0a464/subgraphs/id/EX5DU7VEVmkfNCzUG1gRRy8hBKtknA868NR2kSTF4D93" + "https://api.studio.thegraph.com/query/74256/xlayer-testnet/version/latest" + ), + "subgraph_url_api_key": ( + "https://gateway-testnet-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/9zd1LcywWjuSUtde4ofC8oyyzpawPwGUiPsvqTq247xk" ), "hmt_address": "0x792abbcC99c01dbDec49c9fa9A828a186Da45C33", "factory_address": "0x6Cd3ecAD36ee88E9ef3665CF381D9dAE0FE0a32e", @@ -262,6 +312,7 @@ class ChainId(Enum): "title": "Localhost", "scan_url": "", "subgraph_url": "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + "subgraph_url_api_key": "", "hmt_address": "0x5FbDB2315678afecb367f032d93F642f64180aa3", "factory_address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", "staking_address": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", @@ -273,6 +324,9 @@ class ChainId(Enum): } +SUBGRAPH_API_KEY_PLACEHOLDER = "[SUBGRAPH_API_KEY]" + + class Status(Enum): """Enum for escrow statuses.""" diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py index 275abfef45..960aab4261 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/escrow/escrow_utils.py @@ -159,7 +159,7 @@ def get_escrows( for chain_id in filter.networks: network = NETWORKS[chain_id] escrows_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_escrows_query(filter), params={ "launcher": filter.launcher.lower() if filter.launcher else None, @@ -281,7 +281,7 @@ def get_escrow( network = NETWORKS[ChainId(chain_id)] escrow_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_escrow_query(), params={ "escrowAddress": escrow_address.lower(), diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py index ec31ede449..1c6a42a9dd 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/kvstore/kvstore_utils.py @@ -88,7 +88,7 @@ def get_kvstore_data( network = NETWORKS[ChainId(chain_id)] kvstore_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_kvstore_by_address_query(), params={ "address": address.lower(), diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py index 0b7264d5a9..d2fac07aa0 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/operator/operator_utils.py @@ -193,7 +193,7 @@ def get_leaders(filter: LeaderFilter) -> List[LeaderData]: return [] leaders_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_leaders_query(filter), params={"role": filter.role}, ) @@ -279,7 +279,7 @@ def get_leader( network = NETWORKS[chain_id] leader_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_leader_query, params={"address": leader_address.lower()}, ) @@ -355,7 +355,7 @@ def get_reputation_network_operators( network = NETWORKS[chain_id] reputation_network_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_reputation_network_query(role), params={"address": address.lower(), "role": role}, ) @@ -413,7 +413,7 @@ def get_rewards_info(chain_id: ChainId, slasher: str) -> List[RewardData]: network = NETWORKS[chain_id] reward_added_events_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_reward_added_events_query, params={"slasherAddress": slasher.lower()}, ) diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/statistics/statistics_client.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/statistics/statistics_client.py index bcf539a26e..92f6abc2a0 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/statistics/statistics_client.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/statistics/statistics_client.py @@ -327,13 +327,13 @@ def get_escrow_statistics( ) escrow_statistics_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_escrow_statistics_query, ) escrow_statistics = escrow_statistics_data["data"]["escrowStatistics"] event_day_datas_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_event_day_data_query(param), params={ "from": int(param.date_from.timestamp()) if param.date_from else None, @@ -399,7 +399,7 @@ def get_worker_statistics( ) event_day_datas_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_event_day_data_query(param), params={ "from": int(param.date_from.timestamp()) if param.date_from else None, @@ -453,7 +453,7 @@ def get_payment_statistics( ) event_day_datas_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_event_day_data_query(param), params={ "from": int(param.date_from.timestamp()) if param.date_from else None, @@ -514,19 +514,19 @@ def get_hmt_statistics( ) hmtoken_statistics_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_hmtoken_statistics_query, ) hmtoken_statistics = hmtoken_statistics_data["data"]["hmtokenStatistics"] holders_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_holders_query, ) holders = holders_data["data"]["holders"] event_day_datas_data = get_data_from_subgraph( - self.network["subgraph_url"], + self.network, query=get_event_day_data_query(param), params={ "from": int(param.date_from.timestamp()) if param.date_from else None, diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py index e232214358..da72981b96 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/transaction/transaction_utils.py @@ -97,7 +97,7 @@ def get_transaction(chain_id: ChainId, hash: str) -> Optional[TransactionData]: from human_protocol_sdk.gql.transaction import get_transaction_query transaction_data = get_data_from_subgraph( - network["subgraph_url"], + network, query=get_transaction_query(), params={"hash": hash.lower()}, ) @@ -155,7 +155,7 @@ def get_transactions(filter: TransactionFilter) -> List[TransactionData]: raise TransactionUtilsError("Unsupported Chain ID") data = get_data_from_subgraph( - network_data["subgraph_url"], + network_data, query=get_transactions_query(filter), params={ "fromAddress": ( diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py index efb9e2fed7..748ea35507 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py @@ -1,5 +1,6 @@ import json import logging +import os import time import re from typing import Tuple, Optional @@ -12,10 +13,19 @@ from web3.exceptions import ContractLogicError from web3.types import TxParams -from human_protocol_sdk.constants import ARTIFACTS_FOLDER +from human_protocol_sdk.constants import ARTIFACTS_FOLDER, SUBGRAPH_API_KEY_PLACEHOLDER logger = logging.getLogger("human_protocol_sdk.utils") +# Try to load environment variables from the .env file if python-dotenv is available +try: + from dotenv import load_dotenv + + load_dotenv() +except ImportError: + print("python-dotenv is not installed, skipping .env file loading") + pass + def with_retry(fn, retries=3, delay=5, backoff=2): """Retry a function @@ -182,8 +192,17 @@ def get_kvstore_interface(): ) -def get_data_from_subgraph(url: str, query: str, params: dict = None): - request = requests.post(url, json={"query": query, "variables": params}) +def get_data_from_subgraph(network: dict, query: str, params: dict = None): + subgraph_api_key = os.getenv("SUBGRAPH_API_KEY", "") + if subgraph_api_key: + subgraph_url = network["subgraph_url_api_key"].replace( + SUBGRAPH_API_KEY_PLACEHOLDER, subgraph_api_key + ) + else: + logger.warning("Warning: SUBGRAPH_API_KEY is not provided") + subgraph_url = network["subgraph_url"] + + request = requests.post(subgraph_url, json={"query": query, "variables": params}) if request.status_code == 200: return request.json() else: diff --git a/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh b/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh index 2a0c4c8015..0eb9707e0e 100755 --- a/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh +++ b/packages/sdk/python/human-protocol-sdk/scripts/run-unit-test.sh @@ -2,4 +2,4 @@ set -eux # Run test -pipenv run pytest ./test/human_protocol_sdk/ \ No newline at end of file +pipenv run pytest -s ./test/human_protocol_sdk/ \ No newline at end of file diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/escrow/test_escrow_utils.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/escrow/test_escrow_utils.py index bb0a2588ff..81a33e824f 100644 --- a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/escrow/test_escrow_utils.py +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/escrow/test_escrow_utils.py @@ -65,7 +65,7 @@ def test_get_escrows(self): } def side_effect(subgraph_url, query, params): - if subgraph_url == NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"]: + if subgraph_url == NETWORKS[ChainId.POLYGON_AMOY]: return {"data": {"escrows": [mock_escrow_1]}} else: return {"data": {"escrows": [mock_escrow_2]}} @@ -83,7 +83,7 @@ def side_effect(subgraph_url, query, params): filtered = EscrowUtils.get_escrows(filter) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_escrows_query(filter), params={ "launcher": "0x1234567890123456789012345678901234567891", @@ -104,7 +104,7 @@ def side_effect(subgraph_url, query, params): filtered = EscrowUtils.get_escrows(filter) mock_function.assert_called_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_escrows_query(filter), params={ "launcher": None, @@ -160,7 +160,7 @@ def test_get_escrow(self): ) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_escrow_query(), params={ "escrowAddress": "0x1234567890123456789012345678901234567890", @@ -185,7 +185,7 @@ def test_get_escrow_empty_data(self): "0x1234567890123456789012345678901234567890", ) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_escrow_query(), params={ "escrowAddress": "0x1234567890123456789012345678901234567890", diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py index 602745018c..175ba8c9c7 100644 --- a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/kvstore/test_kvstore_utils.py @@ -41,7 +41,7 @@ def test_get_kvstore_data(self): ) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_kvstore_by_address_query(), params={ "address": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", @@ -66,7 +66,7 @@ def test_get_kvstore_data_empty_data(self): "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", ) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_kvstore_by_address_query(), params={ "address": "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/operator/test_operator_utils.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/operator/test_operator_utils.py index 969de8de9c..c3170171bb 100644 --- a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/operator/test_operator_utils.py +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/operator/test_operator_utils.py @@ -51,7 +51,7 @@ def test_get_leaders(self): leaders = OperatorUtils.get_leaders(filter) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leaders_query(filter), params={"role": filter.role}, ) @@ -113,7 +113,7 @@ def test_get_leaders_when_job_types_is_none(self): leaders = OperatorUtils.get_leaders(filter) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leaders_query(filter), params={"role": filter.role}, ) @@ -135,7 +135,8 @@ def test_get_leaders_when_job_types_is_none(self): self.assertEqual(leaders[0].public_key, None) self.assertEqual(leaders[0].webhook_url, None) self.assertEqual(leaders[0].url, None) - self.assertEqual(leaders[0].job_types, []) # Should rerutn empty array + # Should rerutn empty array + self.assertEqual(leaders[0].job_types, []) def test_get_leaders_when_job_types_is_array(self): filter = LeaderFilter(chain_id=ChainId.POLYGON, role="role") @@ -175,7 +176,7 @@ def test_get_leaders_when_job_types_is_array(self): leaders = OperatorUtils.get_leaders(filter) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leaders_query(filter), params={"role": filter.role}, ) @@ -219,7 +220,7 @@ def test_get_leaders_empty_data(self): leaders = OperatorUtils.get_leaders(filter) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leaders_query(filter), params={"role": filter.role}, ) @@ -263,7 +264,7 @@ def test_get_leader(self): leader = OperatorUtils.get_leader(ChainId.POLYGON, staker_address) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leader_query, params={"address": staker_address}, ) @@ -324,7 +325,7 @@ def test_get_leader_when_job_types_is_none(self): leader = OperatorUtils.get_leader(ChainId.POLYGON, staker_address) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leader_query, params={"address": staker_address}, ) @@ -385,7 +386,7 @@ def test_get_leader_when_job_types_is_array(self): leader = OperatorUtils.get_leader(ChainId.POLYGON, staker_address) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leader_query, params={"address": staker_address}, ) @@ -422,7 +423,7 @@ def test_get_leader_empty_data(self): leader = OperatorUtils.get_leader(ChainId.POLYGON, staker_address) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_leader_query, params={"address": staker_address}, ) @@ -465,7 +466,7 @@ def test_get_reputation_network_operators(self): ) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_reputation_network_query(None), params={"address": reputation_address, "role": None}, ) @@ -512,7 +513,7 @@ def test_get_reputation_network_operators_when_job_types_is_none(self): ) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_reputation_network_query(None), params={"address": reputation_address, "role": None}, ) @@ -559,7 +560,7 @@ def test_get_reputation_network_operators_when_job_types_is_array(self): ) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_reputation_network_query(None), params={"address": reputation_address, "role": None}, ) @@ -585,7 +586,7 @@ def test_get_reputation_network_operators_empty_data(self): ) mock_function.assert_any_call( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_reputation_network_query(None), params={"address": reputation_address, "role": None}, ) @@ -616,7 +617,7 @@ def test_get_rewards_info(self): rewards_info = OperatorUtils.get_rewards_info(ChainId.POLYGON, slasher) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_reward_added_events_query, params={"slasherAddress": slasher}, ) @@ -638,7 +639,7 @@ def test_get_rewards_info_empty_data(self): rewards_info = OperatorUtils.get_rewards_info(ChainId.POLYGON, slasher) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON]["subgraph_url"], + NETWORKS[ChainId.POLYGON], query=get_reward_added_events_query, params={"slasherAddress": slasher}, ) diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/statistics/test_statistics_client.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/statistics/test_statistics_client.py index 889657115c..164e8e0573 100644 --- a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/statistics/test_statistics_client.py +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/statistics/test_statistics_client.py @@ -62,12 +62,12 @@ def test_get_escrow_statistics(self): escrow_statistics = self.statistics.get_escrow_statistics(param) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_escrow_statistics_query, ) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_event_day_data_query(param), params={ "from": 1683811973, @@ -115,7 +115,7 @@ def test_get_worker_statistics(self): payment_statistics = self.statistics.get_worker_statistics(param) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_event_day_data_query(param), params={ "from": 1683811973, @@ -157,7 +157,7 @@ def test_get_payment_statistics(self): payment_statistics = self.statistics.get_payment_statistics(param) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_event_day_data_query(param), params={ "from": 1683811973, @@ -224,17 +224,17 @@ def test_get_hmt_statistics(self): hmt_statistics = self.statistics.get_hmt_statistics(param) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_hmtoken_statistics_query, ) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_holders_query, ) mock_function.assert_any_call( - "http://localhost:8000/subgraphs/name/humanprotocol/localhost", + NETWORKS[ChainId.LOCALHOST], query=get_event_day_data_query(param), params={ "from": 1683811973, diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/__init__.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py index c2215bf71e..fc9b159157 100644 --- a/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py +++ b/packages/sdk/python/human-protocol-sdk/test/human_protocol_sdk/transaction/test_transaction_utils.py @@ -50,7 +50,7 @@ def test_get_transactions(self): transactions = TransactionUtils.get_transactions(filter) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_transactions_query(filter), params={ "fromAddress": "0x1234567890123456789012345678901234567890", @@ -79,7 +79,7 @@ def test_get_transactions_empty_response(self): transactions = TransactionUtils.get_transactions(filter) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_transactions_query(filter), params={ "fromAddress": "0x1234567890123456789012345678901234567890", @@ -140,7 +140,7 @@ def test_get_transaction(self): ) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=get_transaction_query(), params={ "hash": "0x1234567890123456789012345678901234567890123456789012345678901234" @@ -168,7 +168,7 @@ def test_get_transaction_empty_data(self): ) mock_function.assert_called_once_with( - NETWORKS[ChainId.POLYGON_AMOY]["subgraph_url"], + NETWORKS[ChainId.POLYGON_AMOY], query=ANY, params={"hash": "transaction_hash"}, ) diff --git a/packages/sdk/typescript/human-protocol-sdk/example/transactions.ts b/packages/sdk/typescript/human-protocol-sdk/example/transactions.ts new file mode 100644 index 0000000000..ee42f5ae5d --- /dev/null +++ b/packages/sdk/typescript/human-protocol-sdk/example/transactions.ts @@ -0,0 +1,21 @@ +import { ChainId } from '../src/enums'; +import { TransactionUtils } from '../src/transaction'; +import * as dotenv from 'dotenv'; + +dotenv.config({ + path: '.env', +}); + +export const getTransactions = async () => { + const response = await TransactionUtils.getTransactions({ + networks: [ChainId.POLYGON_AMOY], + fromAddress: '0xF3D9a0ba9FA14273C515e519DFD0826Ff87d5164', + startBlock: 6282708, + }); + + console.log(response); +}; + +(async () => { + await getTransactions(); +})(); diff --git a/packages/sdk/typescript/human-protocol-sdk/src/constants.ts b/packages/sdk/typescript/human-protocol-sdk/src/constants.ts index 39edc017d3..8a3cda6cdc 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/constants.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/constants.ts @@ -61,7 +61,9 @@ export const NETWORKS: { rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a', kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v2', + 'https://api.studio.thegraph.com/query/74256/ethereum/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BtC96WCK6ZpZ35v94MK6rZNiBzDEZYHFzDmhMYyZ369D', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -75,6 +77,7 @@ export const NETWORKS: { rewardPoolAddress: '', kvstoreAddress: '', subgraphUrl: '', + subgraphUrlApiKey: '', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -89,6 +92,7 @@ export const NETWORKS: { kvstoreAddress: '0x19Fc3e859C1813ac9427a7a78BeB9ae102CE96d3', subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v2', + subgraphUrlApiKey: '', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli', oldFactoryAddress: '0xaAe6a2646C1F88763E62e0cD08aD050Ea66AC46F', @@ -103,7 +107,9 @@ export const NETWORKS: { rewardPoolAddress: '0xAFf5a986A530ff839d49325A5dF69F96627E8D29', kvstoreAddress: '0xCc0AF0635aa19fE799B6aFDBe28fcFAeA7f00a60', subgraphUrl: - 'https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-sepolia/api', + 'https://api.studio.thegraph.com/query/74256/sepolia/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/UMLaZHtLE9LxzDyvBLBgfWj4erzYzYMeGUbQtxtyMaE', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -116,7 +122,10 @@ export const NETWORKS: { stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C', rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e', kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1', - subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v2', + subgraphUrl: + 'https://api.studio.thegraph.com/query/74256/bsc/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/JBJPC3YmRSNjyjRTTpazhhSX5CCZ4CeBx6ptRsM8PCBb', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc', oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4', }, @@ -130,7 +139,9 @@ export const NETWORKS: { rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29', kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v2', + 'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BnaC4CDqgdbGvcgM7KoZ6d7Yeebsm7NvLFrr61Lxg6Ao', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest', oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f', @@ -145,7 +156,9 @@ export const NETWORKS: { rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3', kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2', + 'https://api.studio.thegraph.com/query/74256/polygon/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/HHYwCHBvDrjckpNB4jbB8k63pSot6rGtBYLBygGji3vD', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon', oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794', @@ -161,6 +174,7 @@ export const NETWORKS: { kvstoreAddress: '0xD96158c7267Ea658a4688F4aEf1c85659851625d', subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v2', + subgraphUrlApiKey: '', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai', oldFactoryAddress: '0x558cd800f9F0B02f3B149667bDe003284c867E94', @@ -175,7 +189,9 @@ export const NETWORKS: { rewardPoolAddress: '0xd866bCEFf6D0F77E1c3EAE28230AE6C79b03fDa7', kvstoreAddress: '0x724AeFC243EdacCA27EAB86D3ec5a76Af4436Fc7', subgraphUrl: - 'https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-amoy/api', + 'https://api.studio.thegraph.com/query/74256/amoy/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/FmdCVzHV3bB4abPVYtBALtBHr7ZRZmZ67m5c432S7GZH', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -189,7 +205,9 @@ export const NETWORKS: { rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a', kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v2', + 'https://api.studio.thegraph.com/query/74256/moonbeam/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/BH5Sm6exn76o5frV5VeCufChB43DCfMXCQsdtWt4AuQP', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam', oldFactoryAddress: '0x98108c28B7767a52BE38B4860832dd4e11A7ecad', @@ -204,7 +222,9 @@ export const NETWORKS: { rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920', kvstoreAddress: '0xcC561f4482f4Ff051D2Dcc65c2cE1A0f291bbA46', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v2', + 'https://api.studio.thegraph.com/query/74256/moonbase-alpha/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/AmmRkJszUbjfUwHubcRkU6CfG1Q9psRWRbbHADVmsLjE', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -218,7 +238,9 @@ export const NETWORKS: { rewardPoolAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18', kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji-v2', + 'https://api.studio.thegraph.com/query/74256/fuji/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/CnZCDsWziQF3jNoqgQMkmJbF9frof5osM3hN5eUgyL5u', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji', oldFactoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88', @@ -233,7 +255,9 @@ export const NETWORKS: { rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a', kvstoreAddress: '0x9Bc7bff35B2Be2413708d48c3B0aEF5c43646728', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche-v2', + 'https://api.studio.thegraph.com/query/74256/avalanche/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/FweDaDWZ6ZDcsA63wsjnWgdgw4aCbkiVQYMYvtcP5p2u', oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche', oldFactoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4', @@ -248,7 +272,9 @@ export const NETWORKS: { rewardPoolAddress: '0xA9545C2530BD5bdb464d5E274F59ACceAa73eD86', kvstoreAddress: '0x938335006ea6F9Eb0e8020969cFF94404425e298', subgraphUrl: - 'https://api.thegraph.com/subgraphs/name/humanprotocol/celo-alfajores', + 'https://api.studio.thegraph.com/query/74256/celo-alfajores/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/EGWCWuzBNkbypW8ipRKuyGwq8azoCy6LKKosGgSPMGRD', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -261,7 +287,10 @@ export const NETWORKS: { stakingAddress: '0x34cD3Bd6B16c559f321799b516dE61E12017fFd1', rewardPoolAddress: '0xb9344bAD98E3d26a4d83900922baf395a2Ec154c', kvstoreAddress: '0x86Af9f6Cd34B69Db1B202223C6d6D109f2491569', - subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/celo', + subgraphUrl: + 'https://api.studio.thegraph.com/query/74256/celo/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/HTgMnYWGsdsw41o8dyph1bwhotuXh6va3L8r8DGgLjsA', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -275,7 +304,9 @@ export const NETWORKS: { rewardPoolAddress: '0x7ABa5F75b2b530cB0c8927C86591c21dF44f06b6', kvstoreAddress: '0x6512d894cc3d3FE93Da9d0420430136fA889FaB9', subgraphUrl: - 'https://gateway-arbitrum.network.thegraph.com/api/b376e45c321d3fcd7d659f9532f0a464/subgraphs/id/CrratkbjCraj1BZLgJmck1GGxbMb2Y2iPZiW4Lh5DdcX', + 'https://api.studio.thegraph.com/query/74256/xlayer/version/latest', + subgraphUrlApiKey: + 'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/CrratkbjCraj1BZLgJmck1GGxbMb2Y2iPZiW4Lh5DdcX', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -289,7 +320,9 @@ export const NETWORKS: { rewardPoolAddress: '0x6daccd1f3a68945f8a7ac6d20260953f7a97fae4', kvstoreAddress: '0xdE8BE9E3C12E9F546309A429cd88d026a25EaF8C', subgraphUrl: - 'https://gateway-arbitrum.network.thegraph.com/api/b376e45c321d3fcd7d659f9532f0a464/subgraphs/id/EX5DU7VEVmkfNCzUG1gRRy8hBKtknA868NR2kSTF4D93', + 'https://api.studio.thegraph.com/query/74256/xlayer-testnet/version/latest', + subgraphUrlApiKey: + 'https://gateway-testnet-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/subgraphs/id/9zd1LcywWjuSUtde4ofC8oyyzpawPwGUiPsvqTq247xk', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -303,6 +336,7 @@ export const NETWORKS: { rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853', kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707', subgraphUrl: 'http://localhost:8000/subgraphs/name/humanprotocol/localhost', + subgraphUrlApiKey: '', oldSubgraphUrl: '', oldFactoryAddress: '', }, @@ -323,3 +357,5 @@ export const Role = { ReputationOracle: 'Reputation Oracle', RecordingOracle: 'Recording Oracle', }; + +export const SUBGRAPH_API_KEY_PLACEHOLDER = '[SUBGRAPH_API_KEY]'; diff --git a/packages/sdk/typescript/human-protocol-sdk/src/error.ts b/packages/sdk/typescript/human-protocol-sdk/src/error.ts index 73edc04578..173c563d02 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/error.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/error.ts @@ -334,3 +334,6 @@ export class InvalidEthereumAddressError extends Error { * @constant {Error} - The Hash does not match */ export const ErrorInvalidHash = new Error('Invalid hash'); + +export const WarnSubgraphApiKeyNotProvided = + '"subgraphApiKey" is not being provided. It might cause issues with the subgraph.'; diff --git a/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts b/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts index b61687370c..7250f8cb70 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/escrow.ts @@ -44,7 +44,7 @@ import { } from './graphql'; import { IEscrowConfig, IEscrowsFilter } from './interfaces'; import { EscrowCancel, EscrowStatus, NetworkData } from './types'; -import { isValidUrl, throwError } from './utils'; +import { getSubgraphUrl, isValidUrl, throwError } from './utils'; /** * ## Introduction @@ -1534,7 +1534,7 @@ export class EscrowUtils { } const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>( - networkData.subgraphUrl, + getSubgraphUrl(networkData), GET_ESCROWS_QUERY(filter), { ...filter, @@ -1646,7 +1646,7 @@ export class EscrowUtils { try { const { escrow } = await gqlFetch<{ escrow: EscrowData }>( - networkData.subgraphUrl, + getSubgraphUrl(networkData), GET_ESCROW_BY_ADDRESS_QUERY(), { escrowAddress: escrowAddress.toLowerCase() } ); diff --git a/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts b/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts index 2a413eb3f4..df93ff467f 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/kvstore.ts @@ -18,7 +18,7 @@ import { } from './error'; import gqlFetch from 'graphql-request'; import { NetworkData } from './types'; -import { isValidUrl } from './utils'; +import { getSubgraphUrl, isValidUrl } from './utils'; import { GET_KVSTORE_BY_ADDRESS_QUERY } from './graphql/queries/kvstore'; import { KVStoreData } from './graphql'; import { IKVStore } from './interfaces'; @@ -510,7 +510,7 @@ export class KVStoreUtils { } const { kvstores } = await gqlFetch<{ kvstores: KVStoreData[] }>( - networkData.subgraphUrl, + getSubgraphUrl(networkData), GET_KVSTORE_BY_ADDRESS_QUERY(), { address: address.toLowerCase() } ); diff --git a/packages/sdk/typescript/human-protocol-sdk/src/operator.ts b/packages/sdk/typescript/human-protocol-sdk/src/operator.ts index 76dc969080..ef53922467 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/operator.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/operator.ts @@ -21,7 +21,7 @@ import { ErrorInvalidStakerAddressProvided, ErrorUnsupportedChainID, } from './error'; -import { throwError } from './utils'; +import { getSubgraphUrl, throwError } from './utils'; import { ChainId } from './enums'; import { NETWORKS } from './constants'; @@ -57,7 +57,7 @@ export class OperatorUtils { try { const { leader } = await gqlFetch<{ leader: ILeaderSubgraph; - }>(networkData.subgraphUrl, GET_LEADER_QUERY, { + }>(getSubgraphUrl(networkData), GET_LEADER_QUERY, { address: address.toLowerCase(), }); @@ -106,13 +106,9 @@ export class OperatorUtils { throw ErrorUnsupportedChainID; } - if (!networkData.subgraphUrl) { - return []; - } - const { leaders } = await gqlFetch<{ leaders: ILeaderSubgraph[]; - }>(networkData.subgraphUrl, GET_LEADERS_QUERY(filter), { + }>(getSubgraphUrl(networkData), GET_LEADERS_QUERY(filter), { role: filter?.role, }); @@ -169,7 +165,7 @@ export class OperatorUtils { try { const { reputationNetwork } = await gqlFetch<{ reputationNetwork: IReputationNetworkSubgraph; - }>(networkData.subgraphUrl, GET_REPUTATION_NETWORK_QUERY(role), { + }>(getSubgraphUrl(networkData), GET_REPUTATION_NETWORK_QUERY(role), { address: address.toLowerCase(), role: role, }); @@ -224,7 +220,7 @@ export class OperatorUtils { try { const { rewardAddedEvents } = await gqlFetch<{ rewardAddedEvents: RewardAddedEventData[]; - }>(networkData.subgraphUrl, GET_REWARD_ADDED_EVENTS_QUERY, { + }>(getSubgraphUrl(networkData), GET_REWARD_ADDED_EVENTS_QUERY, { slasherAddress: slasherAddress.toLowerCase(), }); diff --git a/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts b/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts index 75bbf7eaf0..4449b7e12e 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/statistics.ts @@ -18,7 +18,7 @@ import { } from './graphql'; import { IStatisticsParams } from './interfaces'; import { NetworkData } from './types'; -import { throwError } from './utils'; +import { getSubgraphUrl, throwError } from './utils'; /** * ## Introduction @@ -59,6 +59,7 @@ import { throwError } from './utils'; */ export class StatisticsClient { public networkData: NetworkData; + public subgraphUrl: string; /** * **StatisticsClient constructor** @@ -67,6 +68,7 @@ export class StatisticsClient { */ constructor(networkData: NetworkData) { this.networkData = networkData; + this.subgraphUrl = getSubgraphUrl(networkData); } /** @@ -124,11 +126,11 @@ export class StatisticsClient { try { const { escrowStatistics } = await gqlFetch<{ escrowStatistics: EscrowStatisticsData; - }>(this.networkData.subgraphUrl, GET_ESCROW_STATISTICS_QUERY); + }>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY); const { eventDayDatas } = await gqlFetch<{ eventDayDatas: EventDayData[]; - }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { + }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { from: params.from ? params.from.getTime() / 1000 : undefined, to: params.to ? params.to.getTime() / 1000 : undefined, }); @@ -199,7 +201,7 @@ export class StatisticsClient { try { const { eventDayDatas } = await gqlFetch<{ eventDayDatas: EventDayData[]; - }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { + }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { from: params.from ? params.from.getTime() / 1000 : undefined, to: params.to ? params.to.getTime() / 1000 : undefined, }); @@ -288,7 +290,7 @@ export class StatisticsClient { try { const { eventDayDatas } = await gqlFetch<{ eventDayDatas: EventDayData[]; - }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { + }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { from: params.from ? params.from.getTime() / 1000 : undefined, to: params.to ? params.to.getTime() / 1000 : undefined, }); @@ -397,15 +399,15 @@ export class StatisticsClient { try { const { hmtokenStatistics } = await gqlFetch<{ hmtokenStatistics: HMTStatisticsData; - }>(this.networkData.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY); + }>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY); const { holders } = await gqlFetch<{ holders: HMTHolderData[]; - }>(this.networkData.subgraphUrl, GET_HOLDERS_QUERY); + }>(this.subgraphUrl, GET_HOLDERS_QUERY); const { eventDayDatas } = await gqlFetch<{ eventDayDatas: EventDayData[]; - }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { + }>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), { from: params.from ? params.from.getTime() / 1000 : undefined, to: params.to ? params.to.getTime() / 1000 : undefined, }); diff --git a/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts b/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts index c1497adb3a..aa1e1325d1 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/transaction.ts @@ -13,6 +13,7 @@ import { GET_TRANSACTION_QUERY, } from './graphql/queries/transaction'; import { ITransaction, ITransactionsFilter } from './interfaces'; +import { getSubgraphUrl } from './utils'; export class TransactionUtils { /** @@ -45,7 +46,7 @@ export class TransactionUtils { const { transaction } = await gqlFetch<{ transaction: ITransaction; - }>(networkData.subgraphUrl, GET_TRANSACTION_QUERY, { + }>(getSubgraphUrl(networkData), GET_TRANSACTION_QUERY, { hash: hash.toLowerCase(), }); @@ -115,14 +116,9 @@ export class TransactionUtils { if (!networkData) { throw ErrorUnsupportedChainID; } - - if (!networkData.subgraphUrl) { - continue; - } - const { transactions } = await gqlFetch<{ transactions: ITransaction[]; - }>(networkData.subgraphUrl, GET_TRANSACTIONS_QUERY(filter), { + }>(getSubgraphUrl(networkData), GET_TRANSACTIONS_QUERY(filter), { fromAddress: filter?.fromAddress, toAddress: filter?.toAddress, startDate: filter?.startDate diff --git a/packages/sdk/typescript/human-protocol-sdk/src/types.ts b/packages/sdk/typescript/human-protocol-sdk/src/types.ts index 05dc8d5658..b47a5a27c1 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/types.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/types.ts @@ -127,6 +127,10 @@ export type NetworkData = { * Subgraph URL */ subgraphUrl: string; + /** + * Subgraph URL + */ + subgraphUrlApiKey: string; /** * Old subgraph URL */ diff --git a/packages/sdk/typescript/human-protocol-sdk/src/utils.ts b/packages/sdk/typescript/human-protocol-sdk/src/utils.ts index b1ade8a602..fb6dd0b52b 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/utils.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/utils.ts @@ -9,7 +9,10 @@ import { NumericFault, ReplacementUnderpriced, TransactionReplaced, + WarnSubgraphApiKeyNotProvided, } from './error'; +import { NetworkData } from './types'; +import { SUBGRAPH_API_KEY_PLACEHOLDER } from './constants'; /** * **Handle and throw the error.* @@ -49,3 +52,25 @@ export const isValidUrl = (url: string) => { return false; } }; + +/** + * **Get the subgraph URL.* + * + * @param {NetworkData} networkData + * @param {string} apiKey + * @returns + */ +export const getSubgraphUrl = (networkData: NetworkData) => { + let subgraphUrl = networkData.subgraphUrl; + if (process.env.SUBGRAPH_API_KEY) { + subgraphUrl = networkData.subgraphUrlApiKey.replace( + SUBGRAPH_API_KEY_PLACEHOLDER, + process.env.SUBGRAPH_API_KEY + ); + } else { + // eslint-disable-next-line no-console + console.warn(WarnSubgraphApiKeyNotProvided); + } + + return subgraphUrl; +}; diff --git a/packages/sdk/typescript/human-protocol-sdk/test/escrow.test.ts b/packages/sdk/typescript/human-protocol-sdk/test/escrow.test.ts index 90b664218b..9bfdd7b8df 100644 --- a/packages/sdk/typescript/human-protocol-sdk/test/escrow.test.ts +++ b/packages/sdk/typescript/human-protocol-sdk/test/escrow.test.ts @@ -2228,7 +2228,7 @@ describe('EscrowUtils', () => { const result = await EscrowUtils.getEscrows(filter); expect(result).toEqual(escrows); expect(gqlFetchSpy).toHaveBeenCalledWith( - 'https://subgraph.satsuma-prod.com/8d51f9873a51/team--2543/humanprotocol-amoy/api', + 'https://api.studio.thegraph.com/query/74256/amoy/version/latest', GET_ESCROWS_QUERY(filter), filter ); diff --git a/packages/sdk/typescript/human-protocol-sdk/test/statistics.test.ts b/packages/sdk/typescript/human-protocol-sdk/test/statistics.test.ts index 1a15f73c60..f68d2b2b58 100644 --- a/packages/sdk/typescript/human-protocol-sdk/test/statistics.test.ts +++ b/packages/sdk/typescript/human-protocol-sdk/test/statistics.test.ts @@ -61,11 +61,11 @@ describe('StatisticsClient', () => { }); expect(gqlFetchSpy).toHaveBeenCalledWith( - 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2', + 'https://api.studio.thegraph.com/query/74256/polygon/version/latest', GET_ESCROW_STATISTICS_QUERY ); expect(gqlFetchSpy).toHaveBeenCalledWith( - 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2', + 'https://api.studio.thegraph.com/query/74256/polygon/version/latest', GET_EVENT_DAY_DATA_QUERY({ from, to }), { from: from.getTime() / 1000, @@ -124,7 +124,7 @@ describe('StatisticsClient', () => { }); expect(gqlFetchSpy).toHaveBeenCalledWith( - 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2', + 'https://api.studio.thegraph.com/query/74256/polygon/version/latest', GET_EVENT_DAY_DATA_QUERY({ from, to }), { from: from.getTime() / 1000, @@ -180,7 +180,7 @@ describe('StatisticsClient', () => { }); expect(gqlFetchSpy).toHaveBeenCalledWith( - 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2', + 'https://api.studio.thegraph.com/query/74256/polygon/version/latest', GET_EVENT_DAY_DATA_QUERY({ from, to }), { from: from.getTime() / 1000, @@ -254,7 +254,7 @@ describe('StatisticsClient', () => { }); expect(gqlFetchSpy).toHaveBeenCalledWith( - 'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2', + 'https://api.studio.thegraph.com/query/74256/polygon/version/latest', GET_EVENT_DAY_DATA_QUERY({ from, to }), { from: from.getTime() / 1000, diff --git a/packages/sdk/typescript/subgraph/config/avalanche-v2.json b/packages/sdk/typescript/subgraph/config/avalanche.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/avalanche-v2.json rename to packages/sdk/typescript/subgraph/config/avalanche.json diff --git a/packages/sdk/typescript/subgraph/config/bsctest-v2.json b/packages/sdk/typescript/subgraph/config/bsc-testnet.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/bsctest-v2.json rename to packages/sdk/typescript/subgraph/config/bsc-testnet.json diff --git a/packages/sdk/typescript/subgraph/config/bsc-v2.json b/packages/sdk/typescript/subgraph/config/bsc.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/bsc-v2.json rename to packages/sdk/typescript/subgraph/config/bsc.json diff --git a/packages/sdk/typescript/subgraph/config/mainnet-v2.json b/packages/sdk/typescript/subgraph/config/ethereum.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/mainnet-v2.json rename to packages/sdk/typescript/subgraph/config/ethereum.json diff --git a/packages/sdk/typescript/subgraph/config/fuji-v2.json b/packages/sdk/typescript/subgraph/config/fuji.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/fuji-v2.json rename to packages/sdk/typescript/subgraph/config/fuji.json diff --git a/packages/sdk/typescript/subgraph/config/goerli-v2.json b/packages/sdk/typescript/subgraph/config/goerli-v2.json deleted file mode 100644 index 3058c1637c..0000000000 --- a/packages/sdk/typescript/subgraph/config/goerli-v2.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "network": "goerli", - "description": "Human subgraph on Ethereum Goerli testnet", - "EscrowFactory": { - "address": "0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c", - "startBlock": 8985991, - "abi": "../../../../node_modules/@human-protocol/core/abis/EscrowFactory.json" - }, - "HMToken": { - "address": "0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317", - "startBlock": 7755449, - "abi": "../../../../node_modules/@human-protocol/core/abis/HMToken.json" - }, - "Escrow": { - "abi": "../../../../node_modules/@human-protocol/core/abis/Escrow.json" - }, - "Staking": { - "address": "0xf46B45Df3d956369726d8Bd93Ba33963Ab692920", - "startBlock": 8985993, - "abi": "../../../../node_modules/@human-protocol/core/abis/Staking.json" - }, - "KVStore": { - "address": "0x19Fc3e859C1813ac9427a7a78BeB9ae102CE96d3", - "startBlock": 10001191, - "abi": "../../../../node_modules/@human-protocol/core/abis/KVStore.json" - }, - "RewardPool": { - "address": "0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4", - "startBlock": 8403042, - "abi": "../../../../node_modules/@human-protocol/core/abis/RewardPool.json" - }, - "LegacyEscrowFactory": { - "address": "0xaAe6a2646C1F88763E62e0cD08aD050Ea66AC46F", - "startBlock": 7755458, - "abi": "../../../../node_modules/@human-protocol/core/abis/legacy/EscrowFactory.json" - }, - "LegacyEscrow": { - "abi": "../../../../node_modules/@human-protocol/core/abis/legacy/Escrow.json" - } -} diff --git a/packages/sdk/typescript/subgraph/config/moonbase-alpha-v2.json b/packages/sdk/typescript/subgraph/config/moonbase-alpha.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/moonbase-alpha-v2.json rename to packages/sdk/typescript/subgraph/config/moonbase-alpha.json diff --git a/packages/sdk/typescript/subgraph/config/moonbeam-v2.json b/packages/sdk/typescript/subgraph/config/moonbeam.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/moonbeam-v2.json rename to packages/sdk/typescript/subgraph/config/moonbeam.json diff --git a/packages/sdk/typescript/subgraph/config/mumbai-v2.json b/packages/sdk/typescript/subgraph/config/mumbai-v2.json deleted file mode 100644 index 804257486d..0000000000 --- a/packages/sdk/typescript/subgraph/config/mumbai-v2.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "network": "mumbai", - "description": "Human subgraph on Polygon Mumbai testnet", - "EscrowFactory": { - "address": "0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d", - "startBlock": 31433945, - "abi": "../../../../node_modules/@human-protocol/core/abis/EscrowFactory.json" - }, - "HMToken": { - "address": "0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4", - "startBlock": 26086128, - "abi": "../../../../node_modules/@human-protocol/core/abis/HMToken.json" - }, - "Escrow": { - "abi": "../../../../node_modules/@human-protocol/core/abis/Escrow.json" - }, - "Staking": { - "address": "0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac", - "startBlock": 31433938, - "abi": "../../../../node_modules/@human-protocol/core/abis/Staking.json" - }, - "KVStore": { - "address": "0xD96158c7267Ea658a4688F4aEf1c85659851625d", - "startBlock": 42107536, - "abi": "../../../../node_modules/@human-protocol/core/abis/KVStore.json" - }, - "RewardPool": { - "address": "0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE", - "startBlock": 31433950, - "abi": "../../../../node_modules/@human-protocol/core/abis/RewardPool.json" - }, - "LegacyEscrowFactory": { - "address": "0x558cd800f9F0B02f3B149667bDe003284c867E94", - "startBlock": 26086172, - "abi": "../../../../node_modules/@human-protocol/core/abis/legacy/EscrowFactory.json" - }, - "LegacyEscrow": { - "abi": "../../../../node_modules/@human-protocol/core/abis/legacy/Escrow.json" - } -} diff --git a/packages/sdk/typescript/subgraph/config/polygon-v2.json b/packages/sdk/typescript/subgraph/config/polygon.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/polygon-v2.json rename to packages/sdk/typescript/subgraph/config/polygon.json diff --git a/packages/sdk/typescript/subgraph/config/xlayer-mainnet.json b/packages/sdk/typescript/subgraph/config/xlayer.json similarity index 100% rename from packages/sdk/typescript/subgraph/config/xlayer-mainnet.json rename to packages/sdk/typescript/subgraph/config/xlayer.json diff --git a/packages/sdk/typescript/subgraph/package.json b/packages/sdk/typescript/subgraph/package.json index bc92b33f8c..24683e2357 100644 --- a/packages/sdk/typescript/subgraph/package.json +++ b/packages/sdk/typescript/subgraph/package.json @@ -9,7 +9,7 @@ "generate": "mustache ./config/$NETWORK.json template.yaml > subgraph.yaml && graph codegen", "codegen": "graph codegen", "build": "graph build", - "pretest": "NETWORK=mumbai-v2 yarn generate", + "pretest": "NETWORK=polygon yarn generate", "test": "graph test ", "create-local": "graph create --node http://localhost:8020/ humanprotocol/localhost", "remove-local": "graph remove --node http://localhost:8020/ humanprotocol/localhost", From 5ba1aebf70fbd93a5eddbd06a78a29b2276d8309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20L=C3=B3pez?= <50665615+flopez7@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:12:10 +0200 Subject: [PATCH 4/5] Fix api key injection in user module (#2121) --- .../apps/job-launcher/server/src/modules/user/user.module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/apps/job-launcher/server/src/modules/user/user.module.ts b/packages/apps/job-launcher/server/src/modules/user/user.module.ts index a40c7d637d..1cc8237828 100644 --- a/packages/apps/job-launcher/server/src/modules/user/user.module.ts +++ b/packages/apps/job-launcher/server/src/modules/user/user.module.ts @@ -1,4 +1,4 @@ -import { Logger, Module } from '@nestjs/common'; +import { Logger, Module, forwardRef } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ConfigModule } from '@nestjs/config'; @@ -14,6 +14,7 @@ import { AuthModule } from '../auth/auth.module'; TypeOrmModule.forFeature([UserEntity]), ConfigModule, PaymentModule, + forwardRef(() => AuthModule), ], controllers: [UserController], providers: [Logger, UserService, UserRepository], From 13ee19fe4d0f80f76bcbeb92a0bed3f617c0df35 Mon Sep 17 00:00:00 2001 From: portuu3 <61605646+portuu3@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:59:03 +0200 Subject: [PATCH 5/5] fix warning messages (#2128) --- .../sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py | 4 +++- packages/sdk/typescript/human-protocol-sdk/src/error.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py index 748ea35507..161b0539fb 100644 --- a/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py +++ b/packages/sdk/python/human-protocol-sdk/human_protocol_sdk/utils.py @@ -199,7 +199,9 @@ def get_data_from_subgraph(network: dict, query: str, params: dict = None): SUBGRAPH_API_KEY_PLACEHOLDER, subgraph_api_key ) else: - logger.warning("Warning: SUBGRAPH_API_KEY is not provided") + logger.warning( + "Warning: SUBGRAPH_API_KEY is not provided. It might cause issues with the subgraph." + ) subgraph_url = network["subgraph_url"] request = requests.post(subgraph_url, json={"query": query, "variables": params}) diff --git a/packages/sdk/typescript/human-protocol-sdk/src/error.ts b/packages/sdk/typescript/human-protocol-sdk/src/error.ts index 173c563d02..4df55cd485 100644 --- a/packages/sdk/typescript/human-protocol-sdk/src/error.ts +++ b/packages/sdk/typescript/human-protocol-sdk/src/error.ts @@ -336,4 +336,4 @@ export class InvalidEthereumAddressError extends Error { export const ErrorInvalidHash = new Error('Invalid hash'); export const WarnSubgraphApiKeyNotProvided = - '"subgraphApiKey" is not being provided. It might cause issues with the subgraph.'; + '"SUBGRAPH_API_KEY" is not being provided. It might cause issues with the subgraph.';