@human-protocol/sdk 1.0.0
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/package.json +47 -0
- package/src/constants.ts +9 -0
- package/src/error.ts +38 -0
- package/src/index.ts +4 -0
- package/src/job.ts +797 -0
- package/src/logger.ts +29 -0
- package/src/storage.ts +134 -0
- package/src/types.ts +663 -0
- package/src/utils.ts +98 -0
package/src/utils.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { BigNumber, ethers } from 'ethers';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Escrow,
|
|
5
|
+
Escrow__factory,
|
|
6
|
+
EscrowFactory,
|
|
7
|
+
EscrowFactory__factory,
|
|
8
|
+
HMToken,
|
|
9
|
+
HMToken__factory,
|
|
10
|
+
} from '@human-protocol/core/typechain-types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* **Get HMToken contract instance at given address**
|
|
14
|
+
*
|
|
15
|
+
* @param {string} hmTokenAddr HMToken contract address
|
|
16
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
17
|
+
* @returns {Promise<HMToken>} Attached contract instance
|
|
18
|
+
*/
|
|
19
|
+
export const getHmToken = async (
|
|
20
|
+
hmTokenAddr: string,
|
|
21
|
+
signer?: ethers.Signer
|
|
22
|
+
): Promise<HMToken> => {
|
|
23
|
+
const factory = new HMToken__factory(signer);
|
|
24
|
+
|
|
25
|
+
const contract = await factory.attach(hmTokenAddr);
|
|
26
|
+
|
|
27
|
+
return contract;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* **Deploy EscrowFactory contract**
|
|
32
|
+
*
|
|
33
|
+
* @param {string} hmTokenAddr HMToken address
|
|
34
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
35
|
+
* @returns {Promise<EscrowFactory>} Deployed contract instance
|
|
36
|
+
*/
|
|
37
|
+
export const deployEscrowFactory = async (
|
|
38
|
+
hmTokenAddr: string,
|
|
39
|
+
signer?: ethers.Signer
|
|
40
|
+
): Promise<EscrowFactory> => {
|
|
41
|
+
const factory = new EscrowFactory__factory(signer);
|
|
42
|
+
|
|
43
|
+
const contract = await factory.deploy(hmTokenAddr);
|
|
44
|
+
|
|
45
|
+
return contract;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* **Get EscrowFactory contract instance at given address**
|
|
50
|
+
*
|
|
51
|
+
* @param {string} factoryAddr EscrowFactory contract address
|
|
52
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
53
|
+
* @returns {Promise<EscrowFactory>} Attached contract instance
|
|
54
|
+
*/
|
|
55
|
+
export const getEscrowFactory = async (
|
|
56
|
+
factoryAddr: string,
|
|
57
|
+
signer?: ethers.Signer
|
|
58
|
+
): Promise<EscrowFactory> => {
|
|
59
|
+
const factory = new EscrowFactory__factory(signer);
|
|
60
|
+
|
|
61
|
+
const contract = await factory.attach(factoryAddr);
|
|
62
|
+
|
|
63
|
+
return contract;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* **Get Escrow contract instance at given address**
|
|
68
|
+
*
|
|
69
|
+
* @param {string} escrowAddr Escrow contract address
|
|
70
|
+
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
71
|
+
* @returns {Promise<Escrow>} Attached contract instance
|
|
72
|
+
*/
|
|
73
|
+
export const getEscrow = async (
|
|
74
|
+
escrowAddr: string,
|
|
75
|
+
signer?: ethers.Signer
|
|
76
|
+
): Promise<Escrow> => {
|
|
77
|
+
const factory = new Escrow__factory(signer);
|
|
78
|
+
|
|
79
|
+
const contract = await factory.attach(escrowAddr);
|
|
80
|
+
|
|
81
|
+
return contract;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* **Get specific amount representation in given decimals**
|
|
86
|
+
*
|
|
87
|
+
* Apply given decimals to the specified amount.
|
|
88
|
+
*
|
|
89
|
+
* @param {string | number} amount - Amount to convert
|
|
90
|
+
* @param {number} decimals - Decimal to convert
|
|
91
|
+
* @returns {BigNumber} Converted amount
|
|
92
|
+
*/
|
|
93
|
+
export const toFullDigit = (
|
|
94
|
+
amount: number | string,
|
|
95
|
+
decimals = 18
|
|
96
|
+
): BigNumber => {
|
|
97
|
+
return BigNumber.from(amount).mul(BigNumber.from(10).pow(decimals));
|
|
98
|
+
};
|