@huma-finance/sdk 0.0.37 → 0.0.38-beta.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/API.md +633 -650
- package/LICENSE +660 -660
- package/README.md +37 -37
- package/getting-started.md +190 -190
- package/package.json +3 -3
- package/dist/cjs/graphql/generatedTypes.d.ts +0 -40
- package/dist/cjs/graphql/generatedTypes.js +0 -9
- package/dist/cjs/graphql/generatedTypes.js.map +0 -1
- package/dist/cjs/graphql/index.d.ts +0 -1
- package/dist/cjs/graphql/index.js +0 -5
- package/dist/cjs/graphql/index.js.map +0 -1
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -10
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +0 -22
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +0 -10
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +0 -22
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js.map +0 -1
- package/dist/cjs/helpers/PoolContractHelper.d.ts +0 -119
- package/dist/cjs/helpers/PoolContractHelper.js +0 -144
- package/dist/cjs/helpers/PoolContractHelper.js.map +0 -1
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +0 -10
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +0 -22
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js.map +0 -1
- package/dist/cjs/helpers/index.d.ts +0 -3
- package/dist/cjs/helpers/index.js +0 -7
- package/dist/cjs/helpers/index.js.map +0 -1
- package/dist/cjs/hooks/index.d.ts +0 -4
- package/dist/cjs/hooks/index.js +0 -8
- package/dist/cjs/hooks/index.js.map +0 -1
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -10
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +0 -20
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
- package/dist/cjs/hooks/useContract.d.ts +0 -13
- package/dist/cjs/hooks/useContract.js +0 -31
- package/dist/cjs/hooks/useContract.js.map +0 -1
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +0 -12
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +0 -21
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +0 -1
- package/dist/cjs/hooks/usePoolContract.d.ts +0 -60
- package/dist/cjs/hooks/usePoolContract.js +0 -54
- package/dist/cjs/hooks/usePoolContract.js.map +0 -1
- package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +0 -10
- package/dist/cjs/hooks/useRealWorldReceivableContract.js +0 -20
- package/dist/cjs/hooks/useRealWorldReceivableContract.js.map +0 -1
- package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +0 -10
- package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +0 -17
- package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -4
- package/dist/cjs/index.js +0 -8
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/services/ARWeaveService.d.ts +0 -106
- package/dist/cjs/services/ARWeaveService.js +0 -191
- package/dist/cjs/services/ARWeaveService.js.map +0 -1
- package/dist/cjs/services/EAService.d.ts +0 -20
- package/dist/cjs/services/EAService.js +0 -34
- package/dist/cjs/services/EAService.js.map +0 -1
- package/dist/cjs/services/ReceivableService.d.ts +0 -104
- package/dist/cjs/services/ReceivableService.js +0 -309
- package/dist/cjs/services/ReceivableService.js.map +0 -1
- package/dist/cjs/services/SubgraphService.d.ts +0 -53
- package/dist/cjs/services/SubgraphService.js +0 -94
- package/dist/cjs/services/SubgraphService.js.map +0 -1
- package/dist/cjs/services/index.d.ts +0 -4
- package/dist/cjs/services/index.js +0 -8
- package/dist/cjs/services/index.js.map +0 -1
- package/dist/cjs/utils/chain.d.ts +0 -15
- package/dist/cjs/utils/chain.js +0 -38
- package/dist/cjs/utils/chain.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -4
- package/dist/cjs/utils/index.js +0 -8
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/maticGasStation.d.ts +0 -3
- package/dist/cjs/utils/maticGasStation.js +0 -39
- package/dist/cjs/utils/maticGasStation.js.map +0 -1
- package/dist/cjs/utils/poolInfo.d.ts +0 -8
- package/dist/cjs/utils/poolInfo.js +0 -13
- package/dist/cjs/utils/poolInfo.js.map +0 -1
- package/dist/cjs/utils/web3.d.ts +0 -5
- package/dist/cjs/utils/web3.js +0 -34
- package/dist/cjs/utils/web3.js.map +0 -1
- package/dist/graphql/generatedTypes.d.ts +0 -40
- package/dist/graphql/generatedTypes.js +0 -5
- package/dist/graphql/generatedTypes.js.map +0 -1
- package/dist/graphql/index.d.ts +0 -1
- package/dist/graphql/index.js +0 -2
- package/dist/graphql/index.js.map +0 -1
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -10
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +0 -18
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
- package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +0 -10
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js +0 -18
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js.map +0 -1
- package/dist/helpers/PoolContractHelper.d.ts +0 -119
- package/dist/helpers/PoolContractHelper.js +0 -135
- package/dist/helpers/PoolContractHelper.js.map +0 -1
- package/dist/helpers/RealWorldReceivableContractHelper.d.ts +0 -10
- package/dist/helpers/RealWorldReceivableContractHelper.js +0 -18
- package/dist/helpers/RealWorldReceivableContractHelper.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/index.js +0 -4
- package/dist/helpers/index.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.js +0 -5
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -10
- package/dist/hooks/useBaseCreditPoolReceivableContract.js +0 -16
- package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
- package/dist/hooks/useContract.d.ts +0 -13
- package/dist/hooks/useContract.js +0 -27
- package/dist/hooks/useContract.js.map +0 -1
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +0 -12
- package/dist/hooks/useERC20TransferableReceivableContract.js +0 -17
- package/dist/hooks/useERC20TransferableReceivableContract.js.map +0 -1
- package/dist/hooks/usePool.d.ts +0 -0
- package/dist/hooks/usePool.js +0 -2
- package/dist/hooks/usePool.js.map +0 -1
- package/dist/hooks/usePoolContract.d.ts +0 -60
- package/dist/hooks/usePoolContract.js +0 -49
- package/dist/hooks/usePoolContract.js.map +0 -1
- package/dist/hooks/useRealWorldReceivableContract.d.ts +0 -10
- package/dist/hooks/useRealWorldReceivableContract.js +0 -16
- package/dist/hooks/useRealWorldReceivableContract.js.map +0 -1
- package/dist/hooks/useReceivableFactoringPoolContract.d.ts +0 -10
- package/dist/hooks/useReceivableFactoringPoolContract.js +0 -13
- package/dist/hooks/useReceivableFactoringPoolContract.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/services/ARWeaveService.d.ts +0 -106
- package/dist/services/ARWeaveService.js +0 -186
- package/dist/services/ARWeaveService.js.map +0 -1
- package/dist/services/EAService.d.ts +0 -20
- package/dist/services/EAService.js +0 -31
- package/dist/services/EAService.js.map +0 -1
- package/dist/services/ReceivableService.d.ts +0 -104
- package/dist/services/ReceivableService.js +0 -306
- package/dist/services/ReceivableService.js.map +0 -1
- package/dist/services/SubgraphService.d.ts +0 -53
- package/dist/services/SubgraphService.js +0 -91
- package/dist/services/SubgraphService.js.map +0 -1
- package/dist/services/index.d.ts +0 -4
- package/dist/services/index.js +0 -5
- package/dist/services/index.js.map +0 -1
- package/dist/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist/utils/chain.d.ts +0 -15
- package/dist/utils/chain.js +0 -32
- package/dist/utils/chain.js.map +0 -1
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.js +0 -5
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/maticGasStation.d.ts +0 -3
- package/dist/utils/maticGasStation.js +0 -34
- package/dist/utils/maticGasStation.js.map +0 -1
- package/dist/utils/poolInfo.d.ts +0 -8
- package/dist/utils/poolInfo.js +0 -9
- package/dist/utils/poolInfo.js.map +0 -1
- package/dist/utils/web3.d.ts +0 -5
- package/dist/utils/web3.js +0 -28
- package/dist/utils/web3.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
# Huma SDK
|
|
2
|
-
|
|
3
|
-
 
|
|
4
|
-
|
|
5
|
-
The Huma SDK includes utilities and services for interacting with different layers of our protocol including contracts, our evaluation agent underwriting service, and data storage hosted on ARWeave, Subgraph, on-chain, etc. It's currently offered just as a Javascript NPM package at https://www.npmjs.com/package/@huma-finance/sdk.
|
|
6
|
-
|
|
7
|
-
## Getting Started
|
|
8
|
-
|
|
9
|
-
We recommend onboarding onto our SDK using the [Getting Started guide](getting-started.md)
|
|
10
|
-
|
|
11
|
-
## Documentation
|
|
12
|
-
|
|
13
|
-
For extensive documentation on the different functions offered please refer to the [API documentation](API.md)
|
|
14
|
-
|
|
15
|
-
## Features
|
|
16
|
-
|
|
17
|
-
- Services
|
|
18
|
-
- `ARWeaveService` contains helper methods for storing data on ARWeave conforming to Huma data standards, querying for metadata, and prefunding ARWeave nodes to pay for data uploading.
|
|
19
|
-
- `EAService` contains helper methods to request credit approvals from Huma's Evaluation Agent layer.
|
|
20
|
-
- `ReceivableService` contains helper methods to manage minting and paying Receivable tokens
|
|
21
|
-
- `SubgraphService` contains helper methods for querying Huma's subgraphs
|
|
22
|
-
- Hooks
|
|
23
|
-
- React hooks for fetching ethers.js Contract instances of Huma contracts
|
|
24
|
-
- Helpers
|
|
25
|
-
- `ERC20TransferableReceivableContractHelper` fetches ERC20TransferableReceivable contract instances, which Huma uses for its Request Network integration
|
|
26
|
-
- `RealWorldReceivableContractHelper` fetches RealWorldReceivable contract instances, which Huma uses to power pool loan tapes
|
|
27
|
-
- `PoolContractHelper` helper function for interacting with Huma's pool contracts, including drawdown and payback
|
|
28
|
-
|
|
29
|
-
## Examples
|
|
30
|
-
|
|
31
|
-
To see how the Huma SDK can be used, feel free to use our interactive example in the `huma-widgets` package.
|
|
32
|
-
|
|
33
|
-
1. Open up the `huma-widgets` package in your terminal
|
|
34
|
-
2. Run `yarn cosmos`
|
|
35
|
-
3. Open up localhost:8000 in your browser and navigate to the SDKTesting fixture
|
|
36
|
-
|
|
37
|
-
If you're looking for nodeJS script integrations, go to our `packages/examples` folder and view the examples scripts provided there.
|
|
1
|
+
# Huma SDK
|
|
2
|
+
|
|
3
|
+
 
|
|
4
|
+
|
|
5
|
+
The Huma SDK includes utilities and services for interacting with different layers of our protocol including contracts, our evaluation agent underwriting service, and data storage hosted on ARWeave, Subgraph, on-chain, etc. It's currently offered just as a Javascript NPM package at https://www.npmjs.com/package/@huma-finance/sdk.
|
|
6
|
+
|
|
7
|
+
## Getting Started
|
|
8
|
+
|
|
9
|
+
We recommend onboarding onto our SDK using the [Getting Started guide](getting-started.md)
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
For extensive documentation on the different functions offered please refer to the [API documentation](API.md)
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- Services
|
|
18
|
+
- `ARWeaveService` contains helper methods for storing data on ARWeave conforming to Huma data standards, querying for metadata, and prefunding ARWeave nodes to pay for data uploading.
|
|
19
|
+
- `EAService` contains helper methods to request credit approvals from Huma's Evaluation Agent layer.
|
|
20
|
+
- `ReceivableService` contains helper methods to manage minting and paying Receivable tokens
|
|
21
|
+
- `SubgraphService` contains helper methods for querying Huma's subgraphs
|
|
22
|
+
- Hooks
|
|
23
|
+
- React hooks for fetching ethers.js Contract instances of Huma contracts
|
|
24
|
+
- Helpers
|
|
25
|
+
- `ERC20TransferableReceivableContractHelper` fetches ERC20TransferableReceivable contract instances, which Huma uses for its Request Network integration
|
|
26
|
+
- `RealWorldReceivableContractHelper` fetches RealWorldReceivable contract instances, which Huma uses to power pool loan tapes
|
|
27
|
+
- `PoolContractHelper` helper function for interacting with Huma's pool contracts, including drawdown and payback
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
To see how the Huma SDK can be used, feel free to use our interactive example in the `huma-widgets` package.
|
|
32
|
+
|
|
33
|
+
1. Open up the `huma-widgets` package in your terminal
|
|
34
|
+
2. Run `yarn cosmos`
|
|
35
|
+
3. Open up localhost:8000 in your browser and navigate to the SDKTesting fixture
|
|
36
|
+
|
|
37
|
+
If you're looking for nodeJS script integrations, go to our `packages/examples` folder and view the examples scripts provided there.
|
package/getting-started.md
CHANGED
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
# Getting Started
|
|
2
|
-
|
|
3
|
-
In this guide we'll take a look at using Huma's SDK to mint and pay a receivable, call functions on our pool, and more.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Huma's SDK can be installed using npm or yarn.
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
npm install @huma-finance/sdk
|
|
11
|
-
yarn add @huma-finance/sdk
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
You'll also want to install Huma's shared utilities
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
npm install @huma-finance/shared
|
|
18
|
-
yarn add @huma-finance/shared
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Mint a Pool Receivable
|
|
22
|
-
|
|
23
|
-
Create a new file `index.js` and import services from `@huma-finance/sdk` and `@huma-finance/shared`
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
import { ReceivableService, PaymentMethod } from '@huma-finance/sdk'
|
|
27
|
-
import { POOL_NAME, POOL_TYPE } from "@huma-finance/shared";
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Set up your ethers Provider and import your private key
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
const TEST_PRIVATE_KEY = "YOUR_PRIVATE_KEY";
|
|
34
|
-
const provider = new ethers.providers.JsonRpcProvider(
|
|
35
|
-
`https://goerli.infura.io/v3/${INFURA_API_KEY}`,
|
|
36
|
-
{
|
|
37
|
-
name: "Goerli",
|
|
38
|
-
chainId: 5,
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
Call on the `mintReceivable` method with an ethers Wallet instance
|
|
44
|
-
|
|
45
|
-
> Note: Receivables support multiple payment methods. Declarative receivables
|
|
46
|
-
> don't actually transfer ERC20 tokens, they just update their balance on-chain.
|
|
47
|
-
> Payable receivables will actually call pool methods to transfer ERC20 tokens.
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
const wallet = new Wallet(TEST_PRIVATE_KEY, provider);
|
|
51
|
-
const tx = await ReceivableService.mintReceivable(
|
|
52
|
-
wallet,
|
|
53
|
-
POOL_NAME.HumaCreditLine,
|
|
54
|
-
POOL_TYPE.CreditLine,
|
|
55
|
-
1000, // receivableAmount
|
|
56
|
-
1684517656, // maturityDate
|
|
57
|
-
PaymentMethod.Declarative, // paymentMethod
|
|
58
|
-
""
|
|
59
|
-
);
|
|
60
|
-
const data = await tx.wait();
|
|
61
|
-
console.log(`Success. Tx hash: ${data.transactionHash}`);
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
Running this in the console, we should see the following result
|
|
65
|
-
|
|
66
|
-
```
|
|
67
|
-
$ node index.js
|
|
68
|
-
{}
|
|
69
|
-
Success. Tx hash: 0xb789af3611bc01b6a90f002327500421abf575660be1bbb30013d52518260e41
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
Congrats! You've successfully minted your own receivable token, which are used to borrow from Huma's pools.
|
|
73
|
-
|
|
74
|
-
If you're stuck or want to view a complete solution, check out our `examples` directory (here)[https://github.com/00labs/huma-dapp/blob/develop/packages/examples/src/]
|
|
75
|
-
|
|
76
|
-
## Call functions from Huma's pool
|
|
77
|
-
|
|
78
|
-
We can use the Huma SDK to easily obtain ethers Contract instances of any Huma pool.
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
import { getPoolContract } from "@huma-finance/sdk";
|
|
82
|
-
import { POOL_NAME, POOL_TYPE } from "@huma-finance/shared";
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
With a ethers provider, pass in some config options for which pool contract you'd like to fetch.
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
const poolContract = getPoolContract(
|
|
89
|
-
wallet,
|
|
90
|
-
5, // Goerli chain ID
|
|
91
|
-
POOL_NAME.HumaCreditLine,
|
|
92
|
-
POOL_TYPE.CreditLine
|
|
93
|
-
);
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Now you can call any functions you want on the pool as if it were any other ethers Contract. Let's try fetching credit record details of our current account:
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
const data = await poolContract.creditRecordMapping(wallet.address);
|
|
100
|
-
console.log(data);
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Running this in the console, you should see something like this
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
$ node index.js
|
|
107
|
-
[
|
|
108
|
-
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
109
|
-
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
110
|
-
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
111
|
-
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
112
|
-
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
113
|
-
0,
|
|
114
|
-
0,
|
|
115
|
-
0,
|
|
116
|
-
unbilledPrincipal: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
117
|
-
dueDate: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
118
|
-
correction: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
119
|
-
totalDue: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
120
|
-
feesAndInterestDue: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
121
|
-
missedPeriods: 0,
|
|
122
|
-
remainingPeriods: 0,
|
|
123
|
-
state: 0
|
|
124
|
-
]
|
|
125
|
-
Done in 4.90s.
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
# Other SDK examples
|
|
129
|
-
|
|
130
|
-
## Declare a receivable as paid
|
|
131
|
-
|
|
132
|
-
Once we've minted a receivable, we can use the `ReceivableService` to pay it off using multiple types of payment methods.
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
const wallet = new Wallet(TEST_PRIVATE_KEY, provider);
|
|
136
|
-
|
|
137
|
-
const data = await ReceivableService.payReceivableByTokenId(
|
|
138
|
-
wallet,
|
|
139
|
-
8, // receivableTokenId
|
|
140
|
-
10, // paymentAmount
|
|
141
|
-
PaymentMethod.Declarative // paymentMethod
|
|
142
|
-
);
|
|
143
|
-
console.log(`Success. Tx hash: ${data.transactionHash}`);
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Mint a receivable with metadata automatically uploaded to ARWeave
|
|
147
|
-
|
|
148
|
-
Huma supports both lazy funding and pre-funding the ARWeave network to pay for metadata uploads.
|
|
149
|
-
|
|
150
|
-
```
|
|
151
|
-
// Prefund...
|
|
152
|
-
await prefundBundlr(getBundlrNetworkConfig(5), signer, 1_000_000)
|
|
153
|
-
|
|
154
|
-
// Or pay as you go! (Note: it's recommended you still prefund with a small
|
|
155
|
-
// amount of currency to avoid slippage)
|
|
156
|
-
const data = await ReceivableService.mintReceivableWithMetadata(
|
|
157
|
-
signer,
|
|
158
|
-
TEST_PRIVATE_KEY,
|
|
159
|
-
chainId,
|
|
160
|
-
poolName,
|
|
161
|
-
poolType,
|
|
162
|
-
receivableAmount,
|
|
163
|
-
maturityDate,
|
|
164
|
-
paymentMethod,
|
|
165
|
-
JSON.parse(metadata),
|
|
166
|
-
internalID,
|
|
167
|
-
[],
|
|
168
|
-
)
|
|
169
|
-
setMintResult(`Success, Tx Hash: ${data.transactionHash}`)
|
|
170
|
-
console.log(data)
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Query for receivables uploaded to ARWeave
|
|
174
|
-
|
|
175
|
-
Once metadata is uploaded to ARWeave, you can query them by referenceId tags, which you can specify during upload.
|
|
176
|
-
|
|
177
|
-
```
|
|
178
|
-
const data = await ARWeaveService.queryForMetadata(
|
|
179
|
-
chainId,
|
|
180
|
-
poolName,
|
|
181
|
-
poolType,
|
|
182
|
-
address,
|
|
183
|
-
'12', // referenceId
|
|
184
|
-
)
|
|
185
|
-
setQueryResult(data)
|
|
186
|
-
console.log(data)
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## Next steps
|
|
190
|
-
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
In this guide we'll take a look at using Huma's SDK to mint and pay a receivable, call functions on our pool, and more.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Huma's SDK can be installed using npm or yarn.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm install @huma-finance/sdk
|
|
11
|
+
yarn add @huma-finance/sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
You'll also want to install Huma's shared utilities
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm install @huma-finance/shared
|
|
18
|
+
yarn add @huma-finance/shared
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Mint a Pool Receivable
|
|
22
|
+
|
|
23
|
+
Create a new file `index.js` and import services from `@huma-finance/sdk` and `@huma-finance/shared`
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
import { ReceivableService, PaymentMethod } from '@huma-finance/sdk'
|
|
27
|
+
import { POOL_NAME, POOL_TYPE } from "@huma-finance/shared";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Set up your ethers Provider and import your private key
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
const TEST_PRIVATE_KEY = "YOUR_PRIVATE_KEY";
|
|
34
|
+
const provider = new ethers.providers.JsonRpcProvider(
|
|
35
|
+
`https://goerli.infura.io/v3/${INFURA_API_KEY}`,
|
|
36
|
+
{
|
|
37
|
+
name: "Goerli",
|
|
38
|
+
chainId: 5,
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Call on the `mintReceivable` method with an ethers Wallet instance
|
|
44
|
+
|
|
45
|
+
> Note: Receivables support multiple payment methods. Declarative receivables
|
|
46
|
+
> don't actually transfer ERC20 tokens, they just update their balance on-chain.
|
|
47
|
+
> Payable receivables will actually call pool methods to transfer ERC20 tokens.
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
const wallet = new Wallet(TEST_PRIVATE_KEY, provider);
|
|
51
|
+
const tx = await ReceivableService.mintReceivable(
|
|
52
|
+
wallet,
|
|
53
|
+
POOL_NAME.HumaCreditLine,
|
|
54
|
+
POOL_TYPE.CreditLine,
|
|
55
|
+
1000, // receivableAmount
|
|
56
|
+
1684517656, // maturityDate
|
|
57
|
+
PaymentMethod.Declarative, // paymentMethod
|
|
58
|
+
""
|
|
59
|
+
);
|
|
60
|
+
const data = await tx.wait();
|
|
61
|
+
console.log(`Success. Tx hash: ${data.transactionHash}`);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Running this in the console, we should see the following result
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
$ node index.js
|
|
68
|
+
{}
|
|
69
|
+
Success. Tx hash: 0xb789af3611bc01b6a90f002327500421abf575660be1bbb30013d52518260e41
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Congrats! You've successfully minted your own receivable token, which are used to borrow from Huma's pools.
|
|
73
|
+
|
|
74
|
+
If you're stuck or want to view a complete solution, check out our `examples` directory (here)[https://github.com/00labs/huma-dapp/blob/develop/packages/examples/src/]
|
|
75
|
+
|
|
76
|
+
## Call functions from Huma's pool
|
|
77
|
+
|
|
78
|
+
We can use the Huma SDK to easily obtain ethers Contract instances of any Huma pool.
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
import { getPoolContract } from "@huma-finance/sdk";
|
|
82
|
+
import { POOL_NAME, POOL_TYPE } from "@huma-finance/shared";
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
With a ethers provider, pass in some config options for which pool contract you'd like to fetch.
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
const poolContract = getPoolContract(
|
|
89
|
+
wallet,
|
|
90
|
+
5, // Goerli chain ID
|
|
91
|
+
POOL_NAME.HumaCreditLine,
|
|
92
|
+
POOL_TYPE.CreditLine
|
|
93
|
+
);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Now you can call any functions you want on the pool as if it were any other ethers Contract. Let's try fetching credit record details of our current account:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
const data = await poolContract.creditRecordMapping(wallet.address);
|
|
100
|
+
console.log(data);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Running this in the console, you should see something like this
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
$ node index.js
|
|
107
|
+
[
|
|
108
|
+
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
109
|
+
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
110
|
+
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
111
|
+
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
112
|
+
BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
113
|
+
0,
|
|
114
|
+
0,
|
|
115
|
+
0,
|
|
116
|
+
unbilledPrincipal: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
117
|
+
dueDate: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
118
|
+
correction: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
119
|
+
totalDue: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
120
|
+
feesAndInterestDue: BigNumber { _hex: '0x00', _isBigNumber: true },
|
|
121
|
+
missedPeriods: 0,
|
|
122
|
+
remainingPeriods: 0,
|
|
123
|
+
state: 0
|
|
124
|
+
]
|
|
125
|
+
Done in 4.90s.
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
# Other SDK examples
|
|
129
|
+
|
|
130
|
+
## Declare a receivable as paid
|
|
131
|
+
|
|
132
|
+
Once we've minted a receivable, we can use the `ReceivableService` to pay it off using multiple types of payment methods.
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
const wallet = new Wallet(TEST_PRIVATE_KEY, provider);
|
|
136
|
+
|
|
137
|
+
const data = await ReceivableService.payReceivableByTokenId(
|
|
138
|
+
wallet,
|
|
139
|
+
8, // receivableTokenId
|
|
140
|
+
10, // paymentAmount
|
|
141
|
+
PaymentMethod.Declarative // paymentMethod
|
|
142
|
+
);
|
|
143
|
+
console.log(`Success. Tx hash: ${data.transactionHash}`);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Mint a receivable with metadata automatically uploaded to ARWeave
|
|
147
|
+
|
|
148
|
+
Huma supports both lazy funding and pre-funding the ARWeave network to pay for metadata uploads.
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
// Prefund...
|
|
152
|
+
await prefundBundlr(getBundlrNetworkConfig(5), signer, 1_000_000)
|
|
153
|
+
|
|
154
|
+
// Or pay as you go! (Note: it's recommended you still prefund with a small
|
|
155
|
+
// amount of currency to avoid slippage)
|
|
156
|
+
const data = await ReceivableService.mintReceivableWithMetadata(
|
|
157
|
+
signer,
|
|
158
|
+
TEST_PRIVATE_KEY,
|
|
159
|
+
chainId,
|
|
160
|
+
poolName,
|
|
161
|
+
poolType,
|
|
162
|
+
receivableAmount,
|
|
163
|
+
maturityDate,
|
|
164
|
+
paymentMethod,
|
|
165
|
+
JSON.parse(metadata),
|
|
166
|
+
internalID,
|
|
167
|
+
[],
|
|
168
|
+
)
|
|
169
|
+
setMintResult(`Success, Tx Hash: ${data.transactionHash}`)
|
|
170
|
+
console.log(data)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Query for receivables uploaded to ARWeave
|
|
174
|
+
|
|
175
|
+
Once metadata is uploaded to ARWeave, you can query them by referenceId tags, which you can specify during upload.
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
const data = await ARWeaveService.queryForMetadata(
|
|
179
|
+
chainId,
|
|
180
|
+
poolName,
|
|
181
|
+
poolType,
|
|
182
|
+
address,
|
|
183
|
+
'12', // referenceId
|
|
184
|
+
)
|
|
185
|
+
setQueryResult(data)
|
|
186
|
+
console.log(data)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Next steps
|
|
190
|
+
|
|
191
191
|
If you want to learn more about the different functions and helpers available in the Huma SDK, please check out our [API documentation](API.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38-beta.0+6ab0460",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@ethersproject/constants": "^5.7.0",
|
|
29
29
|
"@ethersproject/contracts": "^5.7.0",
|
|
30
30
|
"@ethersproject/providers": "^5.6.0",
|
|
31
|
-
"@huma-finance/shared": "^0.0.
|
|
31
|
+
"@huma-finance/shared": "^0.0.38-beta.0+6ab0460",
|
|
32
32
|
"arweave": "^1.13.5",
|
|
33
33
|
"axios": "^1.4.0",
|
|
34
34
|
"bignumber.js": "^9.1.1",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"optionalDependencies": {
|
|
111
111
|
"encoding": "^0.1.13"
|
|
112
112
|
},
|
|
113
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "6ab046042364e2516f1054e7e82c2811708b771d"
|
|
114
114
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { GraphQLClient } from 'graphql-request';
|
|
2
|
-
export type Maybe<T> = T | null;
|
|
3
|
-
export type InputMaybe<T> = Maybe<T>;
|
|
4
|
-
export type Exact<T extends {
|
|
5
|
-
[key: string]: unknown;
|
|
6
|
-
}> = {
|
|
7
|
-
[K in keyof T]: T[K];
|
|
8
|
-
};
|
|
9
|
-
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
10
|
-
[SubKey in K]?: Maybe<T[SubKey]>;
|
|
11
|
-
};
|
|
12
|
-
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
13
|
-
[SubKey in K]: Maybe<T[SubKey]>;
|
|
14
|
-
};
|
|
15
|
-
/** All built-in and custom scalars, mapped to their actual values */
|
|
16
|
-
export type Scalars = {
|
|
17
|
-
ID: string;
|
|
18
|
-
String: string;
|
|
19
|
-
Boolean: boolean;
|
|
20
|
-
Int: number;
|
|
21
|
-
Float: number;
|
|
22
|
-
};
|
|
23
|
-
export type Receivable = {
|
|
24
|
-
__typename?: 'Receivable';
|
|
25
|
-
creationDate?: Maybe<Scalars['String']>;
|
|
26
|
-
currencyCode?: Maybe<Scalars['String']>;
|
|
27
|
-
id?: Maybe<Scalars['String']>;
|
|
28
|
-
lastUpdate?: Maybe<Scalars['String']>;
|
|
29
|
-
maturityDate?: Maybe<Scalars['String']>;
|
|
30
|
-
owner?: Maybe<Scalars['String']>;
|
|
31
|
-
paidAmount?: Maybe<Scalars['String']>;
|
|
32
|
-
pool?: Maybe<Scalars['String']>;
|
|
33
|
-
receivableAmount?: Maybe<Scalars['String']>;
|
|
34
|
-
status?: Maybe<Scalars['String']>;
|
|
35
|
-
tokenId?: Maybe<Scalars['String']>;
|
|
36
|
-
uri?: Maybe<Scalars['String']>;
|
|
37
|
-
};
|
|
38
|
-
export type SdkFunctionWrapper = <T>(action: (requestHeaders?: Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
|
|
39
|
-
export declare function getSdk(client: GraphQLClient, withWrapper?: SdkFunctionWrapper): {};
|
|
40
|
-
export type Sdk = ReturnType<typeof getSdk>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSdk = void 0;
|
|
4
|
-
const defaultWrapper = (action, _operationName, _operationType) => action();
|
|
5
|
-
function getSdk(client, withWrapper = defaultWrapper) {
|
|
6
|
-
return {};
|
|
7
|
-
}
|
|
8
|
-
exports.getSdk = getSdk;
|
|
9
|
-
//# sourceMappingURL=generatedTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generatedTypes.js","sourceRoot":"","sources":["../../../src/graphql/generatedTypes.ts"],"names":[],"mappings":";;;AA8CA,MAAM,cAAc,GAAuB,CACzC,MAAM,EACN,cAAc,EACd,cAAc,EACd,EAAE,CAAC,MAAM,EAAE,CAAA;AAEb,SAAgB,MAAM,CACpB,MAAqB,EACrB,cAAkC,cAAc;IAEhD,OAAO,EAAE,CAAA;AACX,CAAC;AALD,wBAKC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './generatedTypes';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/graphql/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Contract, ethers } from 'ethers';
|
|
2
|
-
/**
|
|
3
|
-
* Returns an ethers contract instance for the BaseCreditPoolReceivable contract
|
|
4
|
-
* associated with the given pool name on the current chain.
|
|
5
|
-
*
|
|
6
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
-
* @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getBaseCreditPoolReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBaseCreditPoolReceivableContract = void 0;
|
|
4
|
-
const shared_1 = require("@huma-finance/shared");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
/**
|
|
7
|
-
* Returns an ethers contract instance for the BaseCreditPoolReceivable contract
|
|
8
|
-
* associated with the given pool name on the current chain.
|
|
9
|
-
*
|
|
10
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
11
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
12
|
-
* @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
|
|
13
|
-
*/
|
|
14
|
-
function getBaseCreditPoolReceivableContract(signerOrProvider, chainId) {
|
|
15
|
-
var _a;
|
|
16
|
-
const baseCreditPoolReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.BaseCreditPoolReceivable];
|
|
17
|
-
if (!baseCreditPoolReceivable)
|
|
18
|
-
return null;
|
|
19
|
-
return (0, utils_1.getContract)(baseCreditPoolReceivable, shared_1.BASE_CREDIT_POOL_RECEIVABLE_ABI, signerOrProvider);
|
|
20
|
-
}
|
|
21
|
-
exports.getBaseCreditPoolReceivableContract = getBaseCreditPoolReceivableContract;
|
|
22
|
-
//# sourceMappingURL=BaseCreditPoolReceivableContractHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCreditPoolReceivableContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/BaseCreditPoolReceivableContractHelper.ts"],"names":[],"mappings":";;;AACA,iDAI6B;AAE7B,oCAAsC;AAEtC;;;;;;;GAOG;AACH,SAAgB,mCAAmC,CACjD,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,wBAAwB,GAC5B,MAAA,kCAAyB,CAAC,OAAO,CAAC,0CAChC,+BAAsB,CAAC,wBAAwB,CAChD,CAAA;IAEH,IAAI,CAAC,wBAAwB;QAAE,OAAO,IAAI,CAAA;IAE1C,OAAO,IAAA,mBAAW,EAChB,wBAAwB,EACxB,wCAA+B,EAC/B,gBAAgB,CACjB,CAAA;AACH,CAAC;AAhBD,kFAgBC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Contract, ethers } from 'ethers';
|
|
2
|
-
/**
|
|
3
|
-
* Returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
4
|
-
* associated with the given pool name on the current chain.
|
|
5
|
-
*
|
|
6
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
8
|
-
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getERC20TransferableReceivableContract = void 0;
|
|
4
|
-
const shared_1 = require("@huma-finance/shared");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
/**
|
|
7
|
-
* Returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
8
|
-
* associated with the given pool name on the current chain.
|
|
9
|
-
*
|
|
10
|
-
* @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
|
|
11
|
-
* @param {number} chainId The chain id where the contract instance exists
|
|
12
|
-
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
13
|
-
*/
|
|
14
|
-
function getERC20TransferableReceivableContract(signerOrProvider, chainId) {
|
|
15
|
-
var _a;
|
|
16
|
-
const erc20TransferableReceiable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.ERC20TransferableReceivable];
|
|
17
|
-
if (!erc20TransferableReceiable)
|
|
18
|
-
return null;
|
|
19
|
-
return (0, utils_1.getContract)(erc20TransferableReceiable, shared_1.ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
|
|
20
|
-
}
|
|
21
|
-
exports.getERC20TransferableReceivableContract = getERC20TransferableReceivableContract;
|
|
22
|
-
//# sourceMappingURL=ERC20TransferableReceivableContractHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ERC20TransferableReceivableContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/ERC20TransferableReceivableContractHelper.ts"],"names":[],"mappings":";;;AACA,iDAI6B;AAE7B,oCAAsC;AAEtC;;;;;;;GAOG;AACH,SAAgB,sCAAsC,CACpD,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,0BAA0B,GAC9B,MAAA,kCAAyB,CAAC,OAAO,CAAC,0CAChC,+BAAsB,CAAC,2BAA2B,CACnD,CAAA;IAEH,IAAI,CAAC,0BAA0B;QAAE,OAAO,IAAI,CAAA;IAE5C,OAAO,IAAA,mBAAW,EAChB,0BAA0B,EAC1B,0CAAiC,EACjC,gBAAgB,CACjB,CAAA;AACH,CAAC;AAhBD,wFAgBC"}
|