Skip to content

Commit 3063134

Browse files
portuu3flopez7dnechay
authored
Escrow contract upgrades (#3482)
Co-authored-by: Francisco López <[email protected]> Co-authored-by: Francisco López <[email protected]> Co-authored-by: Dmitry Nechay <[email protected]>
1 parent d5f21bd commit 3063134

File tree

279 files changed

+22369
-13029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+22369
-13029
lines changed

.changeset/early-words-arrive.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@human-protocol/core": major
3+
---
4+
5+
- Add new cancellation flow
6+
- Introduce admin role
7+
- Add the ability to create, fund and setup an escrow with only one transaction
8+
- Store intermediateResultsHash

.changeset/rich-kids-rush.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@human-protocol/sdk": major
3+
---
4+
5+
### Changed
6+
7+
- Created proper Subgraph types and cast values to the interfaces we have for SDK
8+
- Refactor EscrowUtils, TransactionUtils, OperatorUtils and WorkerUtils methods to fix mismatch types with Subgraph
9+
- Created some mappings to remove duplicated code
10+
- Add the ability to create, fund and setup an escrow with only one transaction

.github/workflows/cd-gitbook-sdk-docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Publish SDK Docs to GitBook
33
on:
44
push:
55
tags:
6-
- "sdk@*"
6+
- "js/sdk@*"
77

88
permissions:
99
contents: read

docs/sdk/python/human_protocol_sdk.constants.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,5 @@ Enum for escrow statuses.
103103
#### Partial *= 2*
104104

105105
#### Pending *= 1*
106+
107+
#### ToCancel *= 6*

docs/sdk/python/human_protocol_sdk.escrow.escrow_client.md

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,23 @@ Initializes a Escrow instance.
7474
* **Parameters:**
7575
**web3** (`Web3`) – The Web3 object
7676

77-
#### add_trusted_handlers(\*args, \*\*kwargs)
78-
7977
#### bulk_payout(\*args, \*\*kwargs)
8078

8179
#### cancel(\*args, \*\*kwargs)
8280

8381
#### complete(\*args, \*\*kwargs)
8482

85-
#### create_bulk_payout_transaction(escrow_address, recipients, amounts, final_results_url, final_results_hash, txId, force_complete=False, tx_options=None)
83+
#### create_bulk_payout_transaction(escrow_address, recipients, amounts, final_results_url, final_results_hash, payoutId, force_complete=False, tx_options=None)
8684

8785
Creates a prepared transaction for bulk payout without signing or sending it.
8886

8987
* **Parameters:**
9088
* **escrow_address** (`str`) – Address of the escrow
9189
* **recipients** (`List`[`str`]) – Array of recipient addresses
92-
* **amounts** (`List`[`Decimal`]) – Array of amounts the recipients will receive
90+
* **amounts** (`List`[`int`]) – Array of amounts the recipients will receive
9391
* **final_results_url** (`str`) – Final results file URL
9492
* **final_results_hash** (`str`) – Final results file hash
95-
* **txId** (`Decimal`) – Serial number of the bulks
93+
* **payoutId** (`str`) – Unique identifier for the payout
9694
* **tx_options** (`Optional`[`TxParams`]) – (Optional) Additional transaction parameters
9795
* **Return type:**
9896
`TxParams`
@@ -159,14 +157,16 @@ Creates a prepared transaction for bulk payout without signing or sending it.
159157

160158
#### create_escrow(\*args, \*\*kwargs)
161159

160+
#### create_fund_and_setup_escrow(\*args, \*\*kwargs)
161+
162162
#### ensure_correct_bulk_payout_input(escrow_address, recipients, amounts, final_results_url, final_results_hash)
163163

164164
Validates input parameters for bulk payout operations.
165165

166166
* **Parameters:**
167167
* **escrow_address** (`str`) – Address of the escrow
168168
* **recipients** (`List`[`str`]) – Array of recipient addresses
169-
* **amounts** (`List`[`Decimal`]) – Array of amounts the recipients will receive
169+
* **amounts** (`List`[`int`]) – Array of amounts the recipients will receive
170170
* **final_results_url** (`str`) – Final results file URL
171171
* **final_results_hash** (`str`) – Final results file hash
172172
* **Return type:**
@@ -185,7 +185,7 @@ Gets the balance for a specified escrow address.
185185
* **Parameters:**
186186
**escrow_address** (`str`) – Address of the escrow
187187
* **Return type:**
188-
`Decimal`
188+
`int`
189189
* **Returns:**
190190
Value of the balance
191191
* **Raises:**
@@ -262,6 +262,34 @@ Gets the escrow factory address of the escrow.
262262
)
263263
```
264264

265+
#### get_intermediate_results_hash(escrow_address)
266+
267+
Gets the intermediate results file hash.
268+
269+
* **Parameters:**
270+
**escrow_address** (`str`) – Address of the escrow
271+
* **Return type:**
272+
`str`
273+
* **Returns:**
274+
Intermediate results file hash
275+
* **Raises:**
276+
[**EscrowClientError**](#human_protocol_sdk.escrow.escrow_client.EscrowClientError) – If an error occurs while checking the parameters
277+
* **Example:**
278+
```python
279+
from eth_typing import URI
280+
from web3 import Web3
281+
from web3.providers.auto import load_provider_from_uri
282+
283+
from human_protocol_sdk.escrow import EscrowClient
284+
285+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
286+
escrow_client = EscrowClient(w3)
287+
288+
hash = escrow_client.get_intermediate_results_hash(
289+
"0x62dD51230A30401C455c8398d06F85e4EaB6309f"
290+
)
291+
```
292+
265293
#### get_intermediate_results_url(escrow_address)
266294

267295
Gets the intermediate results file URL.
@@ -430,6 +458,34 @@ Gets the reputation oracle address of the escrow.
430458
)
431459
```
432460

461+
#### get_reserved_funds(escrow_address)
462+
463+
Gets the reserved funds for a specified escrow address.
464+
465+
* **Parameters:**
466+
**escrow_address** (`str`) – Address of the escrow
467+
* **Return type:**
468+
`int`
469+
* **Returns:**
470+
Value of the reserved funds
471+
* **Raises:**
472+
[**EscrowClientError**](#human_protocol_sdk.escrow.escrow_client.EscrowClientError) – If an error occurs while checking the parameters
473+
* **Example:**
474+
```python
475+
from eth_typing import URI
476+
from web3 import Web3
477+
from web3.providers.auto import load_provider_from_uri
478+
479+
from human_protocol_sdk.escrow import EscrowClient
480+
481+
w3 = Web3(load_provider_from_uri(URI("http://localhost:8545")))
482+
escrow_client = EscrowClient(w3)
483+
484+
reserved_funds = escrow_client.get_reserved_funds(
485+
"0x62dD51230A30401C455c8398d06F85e4EaB6309f"
486+
)
487+
```
488+
433489
#### get_results_url(escrow_address)
434490

435491
Gets the results file URL.
@@ -514,6 +570,8 @@ Gets the address of the token used to fund the escrow.
514570
)
515571
```
516572

573+
#### request_cancellation(\*args, \*\*kwargs)
574+
517575
#### setup(\*args, \*\*kwargs)
518576

519577
#### store_results(\*args, \*\*kwargs)
@@ -539,20 +597,20 @@ Initializes a Escrow instance.
539597
* **Parameters:**
540598
* **recording_oracle_address** (`str`) – Address of the Recording Oracle
541599
* **reputation_oracle_address** (`str`) – Address of the Reputation Oracle
542-
* **recording_oracle_fee** (`Decimal`) – Fee percentage of the Recording Oracle
543-
* **reputation_oracle_fee** (`Decimal`) – Fee percentage of the Reputation Oracle
600+
* **recording_oracle_fee** (`int`) – Fee percentage of the Recording Oracle
601+
* **reputation_oracle_fee** (`int`) – Fee percentage of the Reputation Oracle
544602
* **manifest** (`str`) – Manifest data (can be a URL or JSON string)
545603
* **hash** (`str`) – Manifest file hash
546604

547-
### *class* human_protocol_sdk.escrow.escrow_client.EscrowWithdraw(tx_hash, token_address, amount_withdrawn)
605+
### *class* human_protocol_sdk.escrow.escrow_client.EscrowWithdraw(tx_hash, token_address, withdrawn_amount)
548606

549607
Bases: `object`
550608

551-
#### \_\_init_\_(tx_hash, token_address, amount_withdrawn)
609+
#### \_\_init_\_(tx_hash, token_address, withdrawn_amount)
552610

553611
Represents the result of an escrow cancellation transaction.
554612

555613
* **Parameters:**
556614
* **tx_hash** (`str`) – The hash of the transaction associated with the escrow withdrawal.
557615
* **token_address** (`str`) – The address of the token used for the withdrawal.
558-
* **amount_withdrawn** (`any`) – The amount withdrawn from the escrow.
616+
* **withdrawn_amount** (`any`) – The amount withdrawn from the escrow.

docs/sdk/python/human_protocol_sdk.escrow.escrow_utils.md

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,101 @@ print(
2222

2323
## Module
2424

25-
### *class* human_protocol_sdk.escrow.escrow_utils.EscrowData(chain_id, id, address, amount_paid, balance, count, factory_address, launcher, status, token, total_funded_amount, created_at, final_results_url=None, intermediate_results_url=None, manifest_hash=None, manifest=None, recording_oracle=None, reputation_oracle=None, exchange_oracle=None)
25+
### *class* human_protocol_sdk.escrow.escrow_utils.CancellationRefund(id, escrow_address, receiver, amount, block, timestamp, tx_hash)
2626

2727
Bases: `object`
2828

29-
#### \_\_init_\_(chain_id, id, address, amount_paid, balance, count, factory_address, launcher, status, token, total_funded_amount, created_at, final_results_url=None, intermediate_results_url=None, manifest_hash=None, manifest=None, recording_oracle=None, reputation_oracle=None, exchange_oracle=None)
29+
Represents a cancellation refund event.
30+
31+
* **Parameters:**
32+
* **id** (`str`) – The unique identifier for the cancellation refund event.
33+
* **escrow_address** (`str`) – The address of the escrow associated with the refund.
34+
* **receiver** (`str`) – The address of the recipient receiving the refund.
35+
* **amount** (`str`) – The amount being refunded.
36+
* **block** (`str`) – The block number in which the refund was processed.
37+
* **timestamp** (`str`) – The timestamp of the refund event in milliseconds.
38+
* **tx_hash** (`str`) – The transaction hash of the refund event.
39+
40+
#### \_\_init_\_(id, escrow_address, receiver, amount, block, timestamp, tx_hash)
41+
42+
### *class* human_protocol_sdk.escrow.escrow_utils.EscrowData(chain_id, id, address, amount_paid, balance, count, factory_address, launcher, job_requester_id, status, token, total_funded_amount, created_at, final_results_url=None, final_results_hash=None, intermediate_results_url=None, intermediate_results_hash=None, manifest_hash=None, manifest=None, recording_oracle=None, reputation_oracle=None, exchange_oracle=None, recording_oracle_fee=None, reputation_oracle_fee=None, exchange_oracle_fee=None)
43+
44+
Bases: `object`
45+
46+
#### \_\_init_\_(chain_id, id, address, amount_paid, balance, count, factory_address, launcher, job_requester_id, status, token, total_funded_amount, created_at, final_results_url=None, final_results_hash=None, intermediate_results_url=None, intermediate_results_hash=None, manifest_hash=None, manifest=None, recording_oracle=None, reputation_oracle=None, exchange_oracle=None, recording_oracle_fee=None, reputation_oracle_fee=None, exchange_oracle_fee=None)
3047

3148
Initializes an EscrowData instance.
3249

3350
* **Parameters:**
3451
* **chain_id** ([`ChainId`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.ChainId)) – Chain identifier
3552
* **id** (`str`) – Identifier
3653
* **address** (`str`) – Address
37-
* **amount_paid** (`int`) – Amount paid
38-
* **balance** (`int`) – Balance
39-
* **count** (`int`) – Count
54+
* **amount_paid** (`str`) – Amount paid
55+
* **balance** (`str`) – Balance
56+
* **count** (`str`) – Count
4057
* **factory_address** (`str`) – Factory address
4158
* **launcher** (`str`) – Launcher
59+
* **job_requester_id** (`Optional`[`str`]) – Job requester identifier
4260
* **status** (`str`) – Status
4361
* **token** (`str`) – Token
44-
* **total_funded_amount** (`int`) – Total funded amount
45-
* **created_at** (`datetime`) – Creation date
62+
* **total_funded_amount** (`str`) – Total funded amount
63+
* **created_at** (`str`) – Creation timestamp in milliseconds
4664
* **final_results_url** (`Optional`[`str`]) – URL for final results.
65+
* **final_results_hash** (`Optional`[`str`]) – Hash for final results.
4766
* **intermediate_results_url** (`Optional`[`str`]) – URL for intermediate results.
67+
* **intermediate_results_hash** (`Optional`[`str`]) – Hash for intermediate results.
4868
* **manifest_hash** (`Optional`[`str`]) – Manifest hash.
4969
* **manifest** (`Optional`[`str`]) – Manifest data (JSON/URL).
5070
* **recording_oracle** (`Optional`[`str`]) – Recording Oracle address.
5171
* **reputation_oracle** (`Optional`[`str`]) – Reputation Oracle address.
5272
* **exchange_oracle** (`Optional`[`str`]) – Exchange Oracle address.
73+
* **recording_oracle_fee** (`Optional`[`str`]) – Fee for the Recording Oracle.
74+
* **reputation_oracle_fee** (`Optional`[`str`]) – Fee for the Reputation Oracle.
75+
* **exchange_oracle_fee** (`Optional`[`str`]) – Fee for the Exchange Oracle.
5376

5477
### *class* human_protocol_sdk.escrow.escrow_utils.EscrowUtils
5578

5679
Bases: `object`
5780

5881
A utility class that provides additional escrow-related functionalities.
5982

83+
#### *static* get_cancellation_refund(chain_id, escrow_address)
84+
85+
Returns the cancellation refund for a given escrow address.
86+
87+
* **Parameters:**
88+
* **chain_id** ([`ChainId`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.ChainId)) – Network in which the escrow has been deployed
89+
* **escrow_address** (`str`) – Address of the escrow
90+
* **Return type:**
91+
[`CancellationRefund`](#human_protocol_sdk.escrow.escrow_utils.CancellationRefund)
92+
* **Returns:**
93+
CancellationRefund data or None
94+
* **Raises:**
95+
[**EscrowClientError**](human_protocol_sdk.escrow.escrow_client.md#human_protocol_sdk.escrow.escrow_client.EscrowClientError) – If an unsupported chain ID or invalid address is provided.
96+
* **Example:**
97+
```python
98+
from human_protocol_sdk.constants import ChainId
99+
from human_protocol_sdk.escrow import EscrowUtils
100+
101+
refund = EscrowUtils.get_cancellation_refund(
102+
ChainId.POLYGON_AMOY,
103+
"0x1234567890123456789012345678901234567890"
104+
)
105+
```
106+
107+
#### *static* get_cancellation_refunds(filter)
108+
109+
Fetch cancellation refunds from the subgraph based on the provided filter.
110+
111+
* **Parameters:**
112+
**filter** ([`CancellationRefundFilter`](human_protocol_sdk.filter.md#human_protocol_sdk.filter.CancellationRefundFilter)) – Object containing all the necessary parameters to filter cancellation refunds.
113+
* **Return List[CancellationRefund]:**
114+
List of cancellation refunds matching the query parameters.
115+
* **Raises:**
116+
[**EscrowClientError**](human_protocol_sdk.escrow.escrow_client.md#human_protocol_sdk.escrow.escrow_client.EscrowClientError) – If an unsupported chain ID or invalid addresses are provided.
117+
* **Return type:**
118+
`List`[[`CancellationRefund`](#human_protocol_sdk.escrow.escrow_utils.CancellationRefund)]
119+
60120
#### *static* get_escrow(chain_id, escrow_address)
61121

62122
Returns the escrow for a given address.
@@ -145,8 +205,8 @@ Initializes a Payout instance.
145205
* **chain_id** – The chain identifier where the payout occurred.
146206
* **escrow_address** (`str`) – The address of the escrow that executed the payout.
147207
* **recipient** (`str`) – The address of the recipient.
148-
* **amount** (`int`) – The amount of the payout.
149-
* **created_at** (`int`) – The time of creation of the payout.
208+
* **amount** (`str`) – The amount of the payout.
209+
* **created_at** (`str`) – The time of creation of the payout in milliseconds.
150210

151211
#### \_\_init_\_(id, escrow_address, recipient, amount, created_at)
152212

@@ -157,7 +217,7 @@ Bases: `object`
157217
Initializes a StatusEvent instance.
158218

159219
* **Parameters:**
160-
* **timestamp** (`int`) – The timestamp of the event.
220+
* **timestamp** (`int`) – The timestamp of the event in milliseconds.
161221
* **status** (`str`) – The status of the escrow.
162222
* **chain_id** ([`ChainId`](human_protocol_sdk.constants.md#human_protocol_sdk.constants.ChainId)) – The chain identifier where the event occurred.
163223
* **escrow_address** (`str`) – The address of the escrow.

0 commit comments

Comments
 (0)