@human-protocol/sdk 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/example/simple-existing-job.ts +86 -0
- package/example/simple-new-job-public.ts +74 -0
- package/example/simple-new-job.ts +72 -0
- package/package.json +9 -4
- package/src/error.ts +5 -0
- package/src/job.ts +215 -35
- package/src/storage.ts +5 -4
- package/src/types.ts +13 -0
- package/src/utils.ts +67 -1
- package/test/job.test.ts +716 -0
- package/test/utils/constants.ts +30 -0
- package/test/utils/manifest.ts +33 -0
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Escrow,
|
|
3
3
|
EscrowFactory,
|
|
4
4
|
HMToken,
|
|
5
|
+
Staking,
|
|
5
6
|
} from '@human-protocol/core/typechain-types';
|
|
6
7
|
import { ethers } from 'ethers';
|
|
7
8
|
|
|
@@ -567,6 +568,14 @@ export type ContractData = {
|
|
|
567
568
|
* HMToken contract instance
|
|
568
569
|
*/
|
|
569
570
|
hmToken?: HMToken;
|
|
571
|
+
/**
|
|
572
|
+
* Staking contract address
|
|
573
|
+
*/
|
|
574
|
+
stakingAddr?: string;
|
|
575
|
+
/**
|
|
576
|
+
* Staking contract instance
|
|
577
|
+
*/
|
|
578
|
+
staking?: Staking;
|
|
570
579
|
};
|
|
571
580
|
|
|
572
581
|
/**
|
|
@@ -627,6 +636,10 @@ export type JobArguments = {
|
|
|
627
636
|
/**
|
|
628
637
|
* Factory contract address
|
|
629
638
|
*/
|
|
639
|
+
stakingAddr?: string;
|
|
640
|
+
/**
|
|
641
|
+
* Staking contract address
|
|
642
|
+
*/
|
|
630
643
|
factoryAddr?: string;
|
|
631
644
|
/**
|
|
632
645
|
* Escrow contract address
|
package/src/utils.ts
CHANGED
|
@@ -7,6 +7,10 @@ import {
|
|
|
7
7
|
EscrowFactory__factory,
|
|
8
8
|
HMToken,
|
|
9
9
|
HMToken__factory,
|
|
10
|
+
Staking,
|
|
11
|
+
Staking__factory,
|
|
12
|
+
RewardPool,
|
|
13
|
+
RewardPool__factory,
|
|
10
14
|
} from '@human-protocol/core/typechain-types';
|
|
11
15
|
|
|
12
16
|
/**
|
|
@@ -31,16 +35,18 @@ export const getHmToken = async (
|
|
|
31
35
|
* **Deploy EscrowFactory contract**
|
|
32
36
|
*
|
|
33
37
|
* @param {string} hmTokenAddr HMToken address
|
|
38
|
+
* @param {string} stakingAddr Staking address
|
|
34
39
|
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
35
40
|
* @returns {Promise<EscrowFactory>} Deployed contract instance
|
|
36
41
|
*/
|
|
37
42
|
export const deployEscrowFactory = async (
|
|
38
43
|
hmTokenAddr: string,
|
|
44
|
+
stakingAddr: string,
|
|
39
45
|
signer?: ethers.Signer
|
|
40
46
|
): Promise<EscrowFactory> => {
|
|
41
47
|
const factory = new EscrowFactory__factory(signer);
|
|
42
48
|
|
|
43
|
-
const contract = await factory.deploy(hmTokenAddr);
|
|
49
|
+
const contract = await factory.deploy(hmTokenAddr, stakingAddr);
|
|
44
50
|
|
|
45
51
|
return contract;
|
|
46
52
|
};
|
|
@@ -81,6 +87,66 @@ export const getEscrow = async (
|
|
|
81
87
|
return contract;
|
|
82
88
|
};
|
|
83
89
|
|
|
90
|
+
/**
|
|
91
|
+
* **Deploy Staking contract**
|
|
92
|
+
*
|
|
93
|
+
* @param {string} hmTokenAddr HMToken address
|
|
94
|
+
* @param {number} minimumStake Minimum amount to stake
|
|
95
|
+
* @param {number} lockPeriod Lock period after unstake
|
|
96
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
97
|
+
* @returns {Promise<Staking>} Deployed contract instance
|
|
98
|
+
*/
|
|
99
|
+
export const deployStaking = async (
|
|
100
|
+
hmTokenAddr: string,
|
|
101
|
+
minimumStake: number,
|
|
102
|
+
lockPeriod: number,
|
|
103
|
+
signer?: ethers.Signer
|
|
104
|
+
): Promise<Staking> => {
|
|
105
|
+
const staking = new Staking__factory(signer);
|
|
106
|
+
const contract = await staking.deploy(hmTokenAddr, minimumStake, lockPeriod);
|
|
107
|
+
|
|
108
|
+
return contract;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* **Get Staking contract instance at given address**
|
|
113
|
+
*
|
|
114
|
+
* @param {string} stakingAddr Staking contract address
|
|
115
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
116
|
+
* @returns {Promise<Staking>} Attached contract instance
|
|
117
|
+
*/
|
|
118
|
+
export const getStaking = async (
|
|
119
|
+
stakingAddr: string,
|
|
120
|
+
signer?: ethers.Signer
|
|
121
|
+
): Promise<Staking> => {
|
|
122
|
+
const factory = new Staking__factory(signer);
|
|
123
|
+
|
|
124
|
+
const contract = await factory.attach(stakingAddr);
|
|
125
|
+
|
|
126
|
+
return contract;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* **Deploy RewardPool contract**
|
|
131
|
+
*
|
|
132
|
+
* @param {string} hmTokenAddr HMToken address
|
|
133
|
+
* @param {string} stakingAddr Staking address
|
|
134
|
+
* @param {number} fee Reward fee of the protocol
|
|
135
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
136
|
+
* @returns {Promise<Staking>} Deployed contract instance
|
|
137
|
+
*/
|
|
138
|
+
export const deployRewardPool = async (
|
|
139
|
+
hmTokenAddr: string,
|
|
140
|
+
stakingAddr: string,
|
|
141
|
+
fee: number,
|
|
142
|
+
signer?: ethers.Signer
|
|
143
|
+
): Promise<RewardPool> => {
|
|
144
|
+
const rewardPool = new RewardPool__factory(signer);
|
|
145
|
+
const contract = await rewardPool.deploy(hmTokenAddr, stakingAddr, fee);
|
|
146
|
+
|
|
147
|
+
return contract;
|
|
148
|
+
};
|
|
149
|
+
|
|
84
150
|
/**
|
|
85
151
|
* **Get specific amount representation in given decimals**
|
|
86
152
|
*
|