@huma-finance/sdk 0.0.7 → 0.0.10
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/LICENSE +660 -660
- package/README.md +31 -15
- package/package.json +3 -3
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -9
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +0 -21
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
- package/dist/cjs/helpers/index.d.ts +0 -1
- package/dist/cjs/helpers/index.js +0 -5
- package/dist/cjs/helpers/index.js.map +0 -1
- package/dist/cjs/hooks/index.d.ts +0 -5
- package/dist/cjs/hooks/index.js +0 -9
- package/dist/cjs/hooks/index.js.map +0 -1
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -9
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +0 -19
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
- package/dist/cjs/hooks/useContract.d.ts +0 -11
- package/dist/cjs/hooks/useContract.js +0 -29
- 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 -24
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +0 -1
- package/dist/cjs/hooks/usePoolContract.d.ts +0 -53
- package/dist/cjs/hooks/usePoolContract.js +0 -49
- package/dist/cjs/hooks/usePoolContract.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 -62
- package/dist/cjs/services/ARWeaveService.js +0 -141
- package/dist/cjs/services/ARWeaveService.js.map +0 -1
- package/dist/cjs/services/EAService.d.ts +0 -13
- package/dist/cjs/services/EAService.js +0 -17
- package/dist/cjs/services/EAService.js.map +0 -1
- package/dist/cjs/services/ReceivableService.d.ts +0 -76
- package/dist/cjs/services/ReceivableService.js +0 -156
- package/dist/cjs/services/ReceivableService.js.map +0 -1
- package/dist/cjs/services/SubgraphService.d.ts +0 -39
- package/dist/cjs/services/SubgraphService.js +0 -92
- 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 -14
- package/dist/cjs/utils/chain.js +0 -34
- package/dist/cjs/utils/chain.js.map +0 -1
- package/dist/cjs/utils/index.d.ts +0 -3
- package/dist/cjs/utils/index.js +0 -7
- package/dist/cjs/utils/index.js.map +0 -1
- package/dist/cjs/utils/poolInfo.d.ts +0 -9
- package/dist/cjs/utils/poolInfo.js +0 -14
- package/dist/cjs/utils/poolInfo.js.map +0 -1
- package/dist/cjs/utils/web3.d.ts +0 -4
- package/dist/cjs/utils/web3.js +0 -29
- package/dist/cjs/utils/web3.js.map +0 -1
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -9
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +0 -17
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.js +0 -2
- package/dist/helpers/index.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -5
- package/dist/hooks/index.js +0 -6
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -9
- package/dist/hooks/useBaseCreditPoolReceivableContract.js +0 -15
- package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
- package/dist/hooks/useContract.d.ts +0 -11
- package/dist/hooks/useContract.js +0 -25
- package/dist/hooks/useContract.js.map +0 -1
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +0 -12
- package/dist/hooks/useERC20TransferableReceivableContract.js +0 -20
- 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 -53
- package/dist/hooks/usePoolContract.js +0 -44
- package/dist/hooks/usePoolContract.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 -62
- package/dist/services/ARWeaveService.js +0 -133
- package/dist/services/ARWeaveService.js.map +0 -1
- package/dist/services/EAService.d.ts +0 -13
- package/dist/services/EAService.js +0 -14
- package/dist/services/EAService.js.map +0 -1
- package/dist/services/ReceivableService.d.ts +0 -76
- package/dist/services/ReceivableService.js +0 -149
- package/dist/services/ReceivableService.js.map +0 -1
- package/dist/services/SubgraphService.d.ts +0 -39
- package/dist/services/SubgraphService.js +0 -86
- 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 -14
- package/dist/utils/chain.js +0 -29
- package/dist/utils/chain.js.map +0 -1
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +0 -4
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/poolInfo.d.ts +0 -9
- package/dist/utils/poolInfo.js +0 -10
- package/dist/utils/poolInfo.js.map +0 -1
- package/dist/utils/web3.d.ts +0 -4
- package/dist/utils/web3.js +0 -24
- package/dist/utils/web3.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
# Huma SDK
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
# Huma SDK
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
We recommend onboarding onto our SDK using the [Getting Started guide](getting-started.md)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
For extensive documentation on the different functions offered please refer to the [API documentation](API.md)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Services
|
|
16
|
+
- `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.
|
|
17
|
+
- `EAService` contains helper methods to request credit approvals from Huma's Evaluation Agent layer.
|
|
18
|
+
- `ReceivableService` contains helper methods to manage minting and paying Receivable tokens
|
|
19
|
+
- `SubgraphService` contains helper methods for querying Huma's subgraphs
|
|
20
|
+
- Hooks
|
|
21
|
+
- React hooks for fetching ethers.js Contract instances of Huma contracts
|
|
22
|
+
- Helpers
|
|
23
|
+
- Helper functions for fetching ethers.js Contract instances of Huma contracts
|
|
24
|
+
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
To see how the Huma SDK can be used, feel free to use our interactive example in the huma-widgets package.
|
|
28
|
+
|
|
29
|
+
1. Open up the huma-widgets package in your terminal
|
|
30
|
+
2. Run yarn cosmos
|
|
31
|
+
3. Open up localhost:8000 in your browser and navigate to the SDKTesting fixture
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@ethersproject/constants": "^5.7.0",
|
|
21
21
|
"@ethersproject/contracts": "^5.7.0",
|
|
22
22
|
"@ethersproject/providers": "^5.6.0",
|
|
23
|
-
"@huma-finance/shared": "^0.0.
|
|
23
|
+
"@huma-finance/shared": "^0.0.10",
|
|
24
24
|
"arweave": "^1.13.5",
|
|
25
25
|
"ethers": "^5.7.2",
|
|
26
26
|
"graphql-request": "^6.0.0",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"optionalDependencies": {
|
|
84
84
|
"encoding": "^0.1.13"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "61b1485097a4e7e6d2f1c2825454b9d2283c2a6c"
|
|
87
87
|
}
|
|
@@ -1,9 +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 {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
-
* @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getBaseCreditPoolReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBaseCreditPoolReceivableContract = void 0;
|
|
4
|
-
const huma_shared_1 = require("@00labs/huma-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 {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
|
|
11
|
-
* @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
|
|
12
|
-
*/
|
|
13
|
-
function getBaseCreditPoolReceivableContract(signerOrProvider, chainId) {
|
|
14
|
-
var _a;
|
|
15
|
-
const baseCreditPoolReceivable = (_a = huma_shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[huma_shared_1.SupplementaryContracts.BaseCreditPoolReceivable];
|
|
16
|
-
if (!baseCreditPoolReceivable)
|
|
17
|
-
return null;
|
|
18
|
-
return (0, utils_1.getContract)(baseCreditPoolReceivable, huma_shared_1.BASE_CREDIT_POOL_RECEIVABLE_ABI, signerOrProvider);
|
|
19
|
-
}
|
|
20
|
-
exports.getBaseCreditPoolReceivableContract = getBaseCreditPoolReceivableContract;
|
|
21
|
-
//# sourceMappingURL=BaseCreditPoolReceivableContractHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCreditPoolReceivableContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/BaseCreditPoolReceivableContractHelper.ts"],"names":[],"mappings":";;;AACA,qDAI4B;AAE5B,oCAAsC;AAEtC;;;;;;GAMG;AACH,SAAgB,mCAAmC,CACjD,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,wBAAwB,GAC5B,MAAA,uCAAyB,CAAC,OAAO,CAAC,0CAChC,oCAAsB,CAAC,wBAAwB,CAChD,CAAA;IAEH,IAAI,CAAC,wBAAwB;QAAE,OAAO,IAAI,CAAA;IAE1C,OAAO,IAAA,mBAAW,EAChB,wBAAwB,EACxB,6CAA+B,EAC/B,gBAAgB,CACjB,CAAA;AACH,CAAC;AAhBD,kFAgBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './BaseCreditPoolReceivableContractHelper';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,mFAAwD"}
|
package/dist/cjs/hooks/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./useContract"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./useBaseCreditPoolReceivableContract"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./useERC20TransferableReceivableContract"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./usePoolContract"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./useReceivableFactoringPoolContract"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,wDAA6B;AAC7B,gFAAqD;AACrD,mFAAwD;AACxD,4DAAiC;AACjC,+EAAoD"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Contract, ethers } from 'ethers';
|
|
2
|
-
/**
|
|
3
|
-
* A react hook that returns an ethers contract instance for the BaseCreditPoolReceivable contract
|
|
4
|
-
* associated with the given pool name on the current chain.
|
|
5
|
-
*
|
|
6
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
|
|
7
|
-
* @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
|
|
8
|
-
*/
|
|
9
|
-
export declare function useBaseCreditPoolReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useBaseCreditPoolReceivableContract = void 0;
|
|
4
|
-
const huma_shared_1 = require("@00labs/huma-shared");
|
|
5
|
-
const useContract_1 = require("./useContract");
|
|
6
|
-
/**
|
|
7
|
-
* A react hook that returns an ethers contract instance for the BaseCreditPoolReceivable contract
|
|
8
|
-
* associated with the given pool name on the current chain.
|
|
9
|
-
*
|
|
10
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
|
|
11
|
-
* @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
|
|
12
|
-
*/
|
|
13
|
-
function useBaseCreditPoolReceivableContract(signerOrProvider, chainId) {
|
|
14
|
-
var _a;
|
|
15
|
-
const baseCreditPoolReceivable = (_a = huma_shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[huma_shared_1.SupplementaryContracts.BaseCreditPoolReceivable];
|
|
16
|
-
return (0, useContract_1.useContract)(baseCreditPoolReceivable, huma_shared_1.BASE_CREDIT_POOL_RECEIVABLE_ABI, signerOrProvider);
|
|
17
|
-
}
|
|
18
|
-
exports.useBaseCreditPoolReceivableContract = useBaseCreditPoolReceivableContract;
|
|
19
|
-
//# sourceMappingURL=useBaseCreditPoolReceivableContract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseCreditPoolReceivableContract.js","sourceRoot":"","sources":["../../../src/hooks/useBaseCreditPoolReceivableContract.ts"],"names":[],"mappings":";;;AACA,qDAK4B;AAE5B,+CAA2C;AAE3C;;;;;;GAMG;AACH,SAAgB,mCAAmC,CACjD,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,wBAAwB,GAC5B,MAAA,uCAAyB,CAAC,OAAO,CAAC,0CAChC,oCAAsB,CAAC,wBAAwB,CAChD,CAAA;IAEH,OAAO,IAAA,yBAAW,EAChB,wBAAwB,EACxB,6CAA+B,EAC/B,gBAAgB,CACjB,CAAA;AACH,CAAC;AAdD,kFAcC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Contract } from '@ethersproject/contracts';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook for creating an ethers instance of a smart contract.
|
|
5
|
-
* @param address - The address of the smart contract instance.
|
|
6
|
-
* @param ABI - The ABI of the smart contract.
|
|
7
|
-
* @param signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
|
|
8
|
-
* Note that this signerOrProvider must be connected to the same network as the smart contract in question.
|
|
9
|
-
* @returns An instance of the smart contract, or null if an error occurs.
|
|
10
|
-
*/
|
|
11
|
-
export declare function useContract<T extends Contract = Contract>(address: string | null | undefined, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): T | null;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useContract = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const web3_1 = require("../utils/web3");
|
|
6
|
-
/**
|
|
7
|
-
* Custom hook for creating an ethers instance of a smart contract.
|
|
8
|
-
* @param address - The address of the smart contract instance.
|
|
9
|
-
* @param ABI - The ABI of the smart contract.
|
|
10
|
-
* @param signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
|
|
11
|
-
* Note that this signerOrProvider must be connected to the same network as the smart contract in question.
|
|
12
|
-
* @returns An instance of the smart contract, or null if an error occurs.
|
|
13
|
-
*/
|
|
14
|
-
function useContract(address,
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
ABI, signerOrProvider) {
|
|
17
|
-
return (0, react_1.useMemo)(() => {
|
|
18
|
-
if (!address || !ABI || !signerOrProvider)
|
|
19
|
-
return null;
|
|
20
|
-
try {
|
|
21
|
-
return (0, web3_1.getContract)(address, ABI, signerOrProvider);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}, [address, ABI, signerOrProvider]);
|
|
27
|
-
}
|
|
28
|
-
exports.useContract = useContract;
|
|
29
|
-
//# sourceMappingURL=useContract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useContract.js","sourceRoot":"","sources":["../../../src/hooks/useContract.ts"],"names":[],"mappings":";;;AACA,iCAA+B;AAG/B,wCAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,WAAW,CACzB,OAAkC;AAClC,8DAA8D;AAC9D,GAAQ,EACR,gBAA2D;IAE3D,OAAO,IAAA,eAAO,EAAC,GAAG,EAAE;QAClB,IAAI,CAAC,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,gBAAgB;YAAE,OAAO,IAAI,CAAA;QACtD,IAAI;YACF,OAAO,IAAA,kBAAW,EAAC,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAA;SACnD;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,IAAI,CAAA;SACZ;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAM,CAAA;AAC3C,CAAC;AAdD,kCAcC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers';
|
|
2
|
-
import { Contract } from 'ethers';
|
|
3
|
-
import { POOL_NAME } from '@00labs/huma-shared';
|
|
4
|
-
/**
|
|
5
|
-
* A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
6
|
-
* associated with the given pool name on the current chain.
|
|
7
|
-
*
|
|
8
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
|
|
9
|
-
* @param {POOL_NAME} poolName The name of the pool to get the contract for.
|
|
10
|
-
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
11
|
-
*/
|
|
12
|
-
export declare function useERC20TransferableReceivableContract(signerOrProvider: JsonRpcProvider | JsonRpcSigner, poolName: POOL_NAME): Contract | null;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useERC20TransferableReceivableContract = void 0;
|
|
4
|
-
const huma_shared_1 = require("@00labs/huma-shared");
|
|
5
|
-
const useContract_1 = require("./useContract");
|
|
6
|
-
const chain_1 = require("../utils/chain");
|
|
7
|
-
/**
|
|
8
|
-
* A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
|
|
9
|
-
* associated with the given pool name on the current chain.
|
|
10
|
-
*
|
|
11
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
|
|
12
|
-
* @param {POOL_NAME} poolName The name of the pool to get the contract for.
|
|
13
|
-
* @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
|
|
14
|
-
*/
|
|
15
|
-
function useERC20TransferableReceivableContract(signerOrProvider, poolName) {
|
|
16
|
-
var _a, _b, _c;
|
|
17
|
-
const chainId = (0, chain_1.getChainIdFromJsonSignerOrProvider)(signerOrProvider);
|
|
18
|
-
const TransferableReceivableAddress = chainId
|
|
19
|
-
? (_c = (_b = (_a = huma_shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[huma_shared_1.POOL_TYPE.Invoice]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.assetAddress
|
|
20
|
-
: null;
|
|
21
|
-
return (0, useContract_1.useContract)(TransferableReceivableAddress, huma_shared_1.ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
|
|
22
|
-
}
|
|
23
|
-
exports.useERC20TransferableReceivableContract = useERC20TransferableReceivableContract;
|
|
24
|
-
//# sourceMappingURL=useERC20TransferableReceivableContract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useERC20TransferableReceivableContract.js","sourceRoot":"","sources":["../../../src/hooks/useERC20TransferableReceivableContract.ts"],"names":[],"mappings":";;;AAEA,qDAM4B;AAE5B,+CAA2C;AAC3C,0CAAmE;AAEnE;;;;;;;GAOG;AACH,SAAgB,sCAAsC,CACpD,gBAAiD,EACjD,QAAmB;;IAEnB,MAAM,OAAO,GAAG,IAAA,0CAAkC,EAAC,gBAAgB,CAAC,CAAA;IAEpE,MAAM,6BAA6B,GAAG,OAAO;QAC3C,CAAC,CAAC,MAAA,MAAA,MAAA,6BAAe,CAAC,OAAO,CAAC,0CAAG,uBAAS,CAAC,OAAO,CAAC,0CAAG,QAAQ,CAAC,0CAAE,YAAY;QACzE,CAAC,CAAC,IAAI,CAAA;IAER,OAAO,IAAA,yBAAW,EAChB,6BAA6B,EAC7B,+CAAiC,EACjC,gBAAgB,CACjB,CAAA;AACH,CAAC;AAfD,wFAeC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from '@ethersproject/bignumber';
|
|
2
|
-
import { Contract, ethers } from 'ethers';
|
|
3
|
-
import { POOL_NAME, POOL_TYPE } from '@00labs/huma-shared';
|
|
4
|
-
/**
|
|
5
|
-
* A react hook that returns a contract instance of a specific pool using an ethers JsonRpcProvider or JsonRpcSigner.
|
|
6
|
-
*
|
|
7
|
-
* @template T - The type of the contract.
|
|
8
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - A JsonRpcProvider or JsonRpcSigner instance.
|
|
9
|
-
* @param {POOL_NAME} poolName - The name of the pool.
|
|
10
|
-
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
11
|
-
* @returns {T} A contract instance of the specific pool.
|
|
12
|
-
*/
|
|
13
|
-
export declare function usePoolContract<T extends Contract>(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): T | null;
|
|
14
|
-
/**
|
|
15
|
-
* CreditRecordDetails type object representing the details of a credit line.
|
|
16
|
-
* @typedef {Object} CreditRecordDetails
|
|
17
|
-
* @property {number} aprInBps - The APR (annual percentage rate) in basis points.
|
|
18
|
-
* @property {BigNumber} correction - adjustment of interest over or under-counted because of drawdown
|
|
19
|
-
* or principal payment in the middle of a billing period
|
|
20
|
-
* @property {BigNumber} creditLimit - The credit limit in the pools base currency.
|
|
21
|
-
* @property {BigNumber} defaultAmount - The amount of the default, if any.
|
|
22
|
-
* @property {BigNumber} dueDate - The due date of the next payment.
|
|
23
|
-
* @property {BigNumber} feesAndInterestDue - The fees and interest due.
|
|
24
|
-
* @property {number} intervalInDays - The interval in days between payment periods.
|
|
25
|
-
* @property {number} missedPeriods - The number of missed periods.
|
|
26
|
-
* @property {number} remainingPeriods - The number of remaining periods before this credit line is considered paid off.
|
|
27
|
-
* @property {number} state - The state of the factorization. Please see the CreditState in huma-contracts for more details.
|
|
28
|
-
* @property {BigNumber} totalDue - The total due amount of this credit line.
|
|
29
|
-
* @property {BigNumber} unbilledPrincipal - The unbilled principal of the next payment.
|
|
30
|
-
*/
|
|
31
|
-
export type CreditRecordDetails = {
|
|
32
|
-
aprInBps: number;
|
|
33
|
-
correction: BigNumber;
|
|
34
|
-
creditLimit: BigNumber;
|
|
35
|
-
defaultAmount: BigNumber;
|
|
36
|
-
dueDate: BigNumber;
|
|
37
|
-
feesAndInterestDue: BigNumber;
|
|
38
|
-
intervalInDays: number;
|
|
39
|
-
missedPeriods: number;
|
|
40
|
-
remainingPeriods: number;
|
|
41
|
-
state: number;
|
|
42
|
-
totalDue: BigNumber;
|
|
43
|
-
unbilledPrincipal: BigNumber;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* A react hook that returns the credit record details for a user in a given pool, as well as a function to refresh the data.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} userAddress - The address of the user to get the credit record details for.
|
|
49
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to use for the contract.
|
|
50
|
-
* @param {POOL_NAME} poolName - The name of the pool to get the credit record details for.
|
|
51
|
-
* @returns {Array<CreditRecordDetails | undefined, function():void>} An array containing the credit record details and a function to refresh the data.
|
|
52
|
-
*/
|
|
53
|
-
export declare function useCreditRecordDetails(userAddress: string, signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): [CreditRecordDetails | undefined, () => void];
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCreditRecordDetails = exports.usePoolContract = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const useContract_1 = require("./useContract");
|
|
6
|
-
const poolInfo_1 = require("../utils/poolInfo");
|
|
7
|
-
/**
|
|
8
|
-
* A react hook that returns a contract instance of a specific pool using an ethers JsonRpcProvider or JsonRpcSigner.
|
|
9
|
-
*
|
|
10
|
-
* @template T - The type of the contract.
|
|
11
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - A JsonRpcProvider or JsonRpcSigner instance.
|
|
12
|
-
* @param {POOL_NAME} poolName - The name of the pool.
|
|
13
|
-
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
14
|
-
* @returns {T} A contract instance of the specific pool.
|
|
15
|
-
*/
|
|
16
|
-
function usePoolContract(signerOrProvider, chainId, poolName, poolType) {
|
|
17
|
-
const poolInfo = (0, poolInfo_1.getPoolInfo)(chainId, poolName, poolType);
|
|
18
|
-
return (0, useContract_1.useContract)(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.pool, poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolAbi, signerOrProvider);
|
|
19
|
-
}
|
|
20
|
-
exports.usePoolContract = usePoolContract;
|
|
21
|
-
/**
|
|
22
|
-
* A react hook that returns the credit record details for a user in a given pool, as well as a function to refresh the data.
|
|
23
|
-
*
|
|
24
|
-
* @param {string} userAddress - The address of the user to get the credit record details for.
|
|
25
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to use for the contract.
|
|
26
|
-
* @param {POOL_NAME} poolName - The name of the pool to get the credit record details for.
|
|
27
|
-
* @returns {Array<CreditRecordDetails | undefined, function():void>} An array containing the credit record details and a function to refresh the data.
|
|
28
|
-
*/
|
|
29
|
-
function useCreditRecordDetails(userAddress, signerOrProvider, chainId, poolName, poolType) {
|
|
30
|
-
const poolContract = usePoolContract(signerOrProvider, chainId, poolName, poolType);
|
|
31
|
-
const [creditRecordDetails, setCreditRecordDetails] = (0, react_1.useState)();
|
|
32
|
-
const [refreshCount, setRefreshCount] = (0, react_1.useState)(0);
|
|
33
|
-
(0, react_1.useEffect)(() => {
|
|
34
|
-
const fetchData = async () => {
|
|
35
|
-
if (poolContract && userAddress) {
|
|
36
|
-
const creditRecordMapping = await poolContract.creditRecordMapping(userAddress);
|
|
37
|
-
const creditRecordStaticMapping = await poolContract.creditRecordStaticMapping(userAddress);
|
|
38
|
-
setCreditRecordDetails(Object.assign(Object.assign({}, creditRecordMapping), creditRecordStaticMapping));
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
fetchData();
|
|
42
|
-
}, [userAddress, poolContract, refreshCount]);
|
|
43
|
-
const refresh = (0, react_1.useCallback)(() => {
|
|
44
|
-
setRefreshCount((pre) => pre + 1);
|
|
45
|
-
}, []);
|
|
46
|
-
return [creditRecordDetails, refresh];
|
|
47
|
-
}
|
|
48
|
-
exports.useCreditRecordDetails = useCreditRecordDetails;
|
|
49
|
-
//# sourceMappingURL=usePoolContract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePoolContract.js","sourceRoot":"","sources":["../../../src/hooks/usePoolContract.ts"],"names":[],"mappings":";;;AAEA,iCAAwD;AAGxD,+CAA2C;AAC3C,gDAA+C;AAE/C;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,gBAA2D,EAC3D,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,MAAM,QAAQ,GAAG,IAAA,sBAAW,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IACzD,OAAO,IAAA,yBAAW,EAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,EAAE,gBAAgB,CAAC,CAAA;AAC5E,CAAC;AARD,0CAQC;AAkCD;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CACpC,WAAmB,EACnB,gBAA2D,EAC3D,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,MAAM,YAAY,GAAG,eAAe,CAClC,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAQ,CACT,CAAA;IACD,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GACjD,IAAA,gBAAQ,GAAuB,CAAA;IACjC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,EAAC,CAAC,CAAC,CAAA;IAEnD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;YAC3B,IAAI,YAAY,IAAI,WAAW,EAAE;gBAC/B,MAAM,mBAAmB,GAAG,MAAM,YAAY,CAAC,mBAAmB,CAChE,WAAW,CACZ,CAAA;gBACD,MAAM,yBAAyB,GAC7B,MAAM,YAAY,CAAC,yBAAyB,CAAC,WAAW,CAAC,CAAA;gBAC3D,sBAAsB,iCACjB,mBAAmB,GACnB,yBAAyB,EAC5B,CAAA;aACH;QACH,CAAC,CAAA;QACD,SAAS,EAAE,CAAA;IACb,CAAC,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAA;IAE7C,MAAM,OAAO,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC/B,eAAe,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACnC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC;AAvCD,wDAuCC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { POOL_NAME, ReceivableFactoringPool } from '@00labs/huma-shared';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
/**
|
|
4
|
-
* A react hook that returns the instance of the ReceivableFactoringPool contract for a given signer or provider and pool name.
|
|
5
|
-
*
|
|
6
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to use for the contract.
|
|
7
|
-
* @param {POOL_NAME} poolName - The name of the pool to get the contract for. Check the type for more details.
|
|
8
|
-
* @returns {ReceivableFactoringPool} An ethers instance of the ReceivableFactoringPool contract.
|
|
9
|
-
*/
|
|
10
|
-
export declare function useReceivableFactoringPoolContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME): ReceivableFactoringPool | null;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useReceivableFactoringPoolContract = void 0;
|
|
4
|
-
const huma_shared_1 = require("@00labs/huma-shared");
|
|
5
|
-
const usePoolContract_1 = require("./usePoolContract");
|
|
6
|
-
/**
|
|
7
|
-
* A react hook that returns the instance of the ReceivableFactoringPool contract for a given signer or provider and pool name.
|
|
8
|
-
*
|
|
9
|
-
* @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to use for the contract.
|
|
10
|
-
* @param {POOL_NAME} poolName - The name of the pool to get the contract for. Check the type for more details.
|
|
11
|
-
* @returns {ReceivableFactoringPool} An ethers instance of the ReceivableFactoringPool contract.
|
|
12
|
-
*/
|
|
13
|
-
function useReceivableFactoringPoolContract(signerOrProvider, chainId, poolName) {
|
|
14
|
-
return (0, usePoolContract_1.usePoolContract)(signerOrProvider, chainId, poolName, huma_shared_1.POOL_TYPE.Invoice);
|
|
15
|
-
}
|
|
16
|
-
exports.useReceivableFactoringPoolContract = useReceivableFactoringPoolContract;
|
|
17
|
-
//# sourceMappingURL=useReceivableFactoringPoolContract.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useReceivableFactoringPoolContract.js","sourceRoot":"","sources":["../../../src/hooks/useReceivableFactoringPoolContract.ts"],"names":[],"mappings":";;;AAAA,qDAI4B;AAG5B,uDAAmD;AAEnD;;;;;;GAMG;AACH,SAAgB,kCAAkC,CAChD,gBAA2D,EAC3D,OAAe,EACf,QAAmB;IAEnB,OAAO,IAAA,iCAAe,EACpB,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,uBAAS,CAAC,OAAO,CAClB,CAAA;AACH,CAAC;AAXD,gFAWC"}
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./helpers"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./hooks"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./services"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./utils"), exports);
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,kDAAuB;AACvB,qDAA0B;AAC1B,kDAAuB"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { FundResponse, UploadResponse } from '@bundlr-network/client/build/common/types';
|
|
2
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
3
|
-
import { POOL_NAME, POOL_TYPE } from '@00labs/huma-shared';
|
|
4
|
-
/**
|
|
5
|
-
* The configuration for Bundlr network instances
|
|
6
|
-
*/
|
|
7
|
-
export type BundlrConfig = {
|
|
8
|
-
nodeUrl: string;
|
|
9
|
-
currency: string;
|
|
10
|
-
providerUrl?: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Get the configuration for Bundlr network given a chain ID.
|
|
14
|
-
*
|
|
15
|
-
* @function
|
|
16
|
-
* @param {number} chainId - The chain ID.
|
|
17
|
-
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
18
|
-
* nodeUrl - The node URL of the Bundlr network to use.
|
|
19
|
-
* currency - The currency to pay for uploads with, if lazy funding.
|
|
20
|
-
* providerUrl - The provider URL, required for devnets.
|
|
21
|
-
*/
|
|
22
|
-
export declare function getBundlrNetworkConfig(chainId: number): BundlrConfig;
|
|
23
|
-
/**
|
|
24
|
-
* Prefund the Bundlr network with the specified amount. Useful if not lazy funding.
|
|
25
|
-
*
|
|
26
|
-
* @async
|
|
27
|
-
* @function
|
|
28
|
-
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
29
|
-
* @param {any} wallet - The wallet to send funds from
|
|
30
|
-
* @param {number} amount - The amount to fund.
|
|
31
|
-
* @returns {Promise<FundResponse>} - The fund response.
|
|
32
|
-
*/
|
|
33
|
-
export declare function prefundBundlr(config: BundlrConfig, wallet: any, amount: number): Promise<FundResponse>;
|
|
34
|
-
/**
|
|
35
|
-
* Store data on ARWeave using the Bundlr Network.
|
|
36
|
-
* @async
|
|
37
|
-
* @function
|
|
38
|
-
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
39
|
-
* @param {Web3Provider | ethers.Signer} wallet - Wallet object used for interacting with the Bundlr instance.
|
|
40
|
-
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
41
|
-
* environment, this should be an `ethers.Signer` instance.
|
|
42
|
-
* @param {JSON} data - The data to store in the Bundlr instance.
|
|
43
|
-
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
44
|
-
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
45
|
-
* Bundlr node should already be funded or else uploads will fail.
|
|
46
|
-
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
47
|
-
*/
|
|
48
|
-
export declare function storeData(config: BundlrConfig, wallet: Web3Provider | string, data: JSON, tags: {
|
|
49
|
-
name: string;
|
|
50
|
-
value: string;
|
|
51
|
-
}[], lazyFund?: boolean): Promise<UploadResponse>;
|
|
52
|
-
/**
|
|
53
|
-
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
54
|
-
* @async
|
|
55
|
-
* @function
|
|
56
|
-
* @param {POOL_NAME} poolName - The pool name tag to query.
|
|
57
|
-
* @param {POOL_TYPE} poolType - The pool type tag to query.
|
|
58
|
-
* @param {string} sender - The sender tag to query.
|
|
59
|
-
* @param {string} internalID - The internal ID tag to query, whatever was used when uploading the metadata.
|
|
60
|
-
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
61
|
-
*/
|
|
62
|
-
export declare function queryForMetadata(chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, sender: string, internalId: string): Promise<string | null>;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queryForMetadata = exports.storeData = exports.prefundBundlr = exports.getBundlrNetworkConfig = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const client_1 = tslib_1.__importDefault(require("@bundlr-network/client"));
|
|
6
|
-
const graphql_request_1 = tslib_1.__importStar(require("graphql-request"));
|
|
7
|
-
/**
|
|
8
|
-
* Get the configuration for Bundlr network given a chain ID.
|
|
9
|
-
*
|
|
10
|
-
* @function
|
|
11
|
-
* @param {number} chainId - The chain ID.
|
|
12
|
-
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
13
|
-
* nodeUrl - The node URL of the Bundlr network to use.
|
|
14
|
-
* currency - The currency to pay for uploads with, if lazy funding.
|
|
15
|
-
* providerUrl - The provider URL, required for devnets.
|
|
16
|
-
*/
|
|
17
|
-
function getBundlrNetworkConfig(chainId) {
|
|
18
|
-
switch (chainId) {
|
|
19
|
-
case 5:
|
|
20
|
-
return {
|
|
21
|
-
nodeUrl: 'https://devnet.bundlr.network',
|
|
22
|
-
currency: 'ethereum',
|
|
23
|
-
providerUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
|
24
|
-
};
|
|
25
|
-
case 80001:
|
|
26
|
-
return {
|
|
27
|
-
nodeUrl: 'https://devnet.bundlr.network',
|
|
28
|
-
currency: 'matic',
|
|
29
|
-
providerUrl: 'https://rpc-mumbai.matic.today',
|
|
30
|
-
};
|
|
31
|
-
default:
|
|
32
|
-
return {
|
|
33
|
-
nodeUrl: '',
|
|
34
|
-
currency: '',
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.getBundlrNetworkConfig = getBundlrNetworkConfig;
|
|
39
|
-
/**
|
|
40
|
-
* Prefund the Bundlr network with the specified amount. Useful if not lazy funding.
|
|
41
|
-
*
|
|
42
|
-
* @async
|
|
43
|
-
* @function
|
|
44
|
-
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
45
|
-
* @param {any} wallet - The wallet to send funds from
|
|
46
|
-
* @param {number} amount - The amount to fund.
|
|
47
|
-
* @returns {Promise<FundResponse>} - The fund response.
|
|
48
|
-
*/
|
|
49
|
-
async function prefundBundlr(config,
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
-
wallet, amount) {
|
|
52
|
-
const bundlr = new client_1.default(config.nodeUrl, config.currency, wallet, config.providerUrl
|
|
53
|
-
? {
|
|
54
|
-
providerUrl: config.providerUrl,
|
|
55
|
-
}
|
|
56
|
-
: undefined);
|
|
57
|
-
await bundlr.ready();
|
|
58
|
-
return bundlr.fund(amount);
|
|
59
|
-
}
|
|
60
|
-
exports.prefundBundlr = prefundBundlr;
|
|
61
|
-
/**
|
|
62
|
-
* Store data on ARWeave using the Bundlr Network.
|
|
63
|
-
* @async
|
|
64
|
-
* @function
|
|
65
|
-
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
66
|
-
* @param {Web3Provider | ethers.Signer} wallet - Wallet object used for interacting with the Bundlr instance.
|
|
67
|
-
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
68
|
-
* environment, this should be an `ethers.Signer` instance.
|
|
69
|
-
* @param {JSON} data - The data to store in the Bundlr instance.
|
|
70
|
-
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
71
|
-
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
72
|
-
* Bundlr node should already be funded or else uploads will fail.
|
|
73
|
-
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
74
|
-
*/
|
|
75
|
-
async function storeData(config, wallet, data, tags, lazyFund = true) {
|
|
76
|
-
const bundlr = new client_1.default(config.nodeUrl, config.currency, wallet, config.providerUrl
|
|
77
|
-
? {
|
|
78
|
-
providerUrl: config.providerUrl,
|
|
79
|
-
}
|
|
80
|
-
: undefined);
|
|
81
|
-
await bundlr.ready();
|
|
82
|
-
const dataStr = JSON.stringify(data);
|
|
83
|
-
if (lazyFund) {
|
|
84
|
-
const size = Buffer.byteLength(dataStr);
|
|
85
|
-
const price = await bundlr.getPrice(size);
|
|
86
|
-
// Add a buffer of 10% to account for fluctuations in the price
|
|
87
|
-
price.multipliedBy(1.1);
|
|
88
|
-
console.log(`Funding bundlr with ${price} ${config.currency} to upload data`);
|
|
89
|
-
await bundlr.fund(price);
|
|
90
|
-
}
|
|
91
|
-
return bundlr.upload(dataStr, { tags });
|
|
92
|
-
}
|
|
93
|
-
exports.storeData = storeData;
|
|
94
|
-
/**
|
|
95
|
-
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
96
|
-
* @async
|
|
97
|
-
* @function
|
|
98
|
-
* @param {POOL_NAME} poolName - The pool name tag to query.
|
|
99
|
-
* @param {POOL_TYPE} poolType - The pool type tag to query.
|
|
100
|
-
* @param {string} sender - The sender tag to query.
|
|
101
|
-
* @param {string} internalID - The internal ID tag to query, whatever was used when uploading the metadata.
|
|
102
|
-
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
103
|
-
*/
|
|
104
|
-
async function queryForMetadata(chainId, poolName, poolType, sender, internalId) {
|
|
105
|
-
var _a, _b, _c, _d;
|
|
106
|
-
const config = getBundlrNetworkConfig(chainId);
|
|
107
|
-
const query = (0, graphql_request_1.gql) `
|
|
108
|
-
query ArweaveHumaMetadataQuery(
|
|
109
|
-
$poolName: String!
|
|
110
|
-
$poolType: String!
|
|
111
|
-
$sender: String!
|
|
112
|
-
$internalId: String!
|
|
113
|
-
) {
|
|
114
|
-
transactions(
|
|
115
|
-
owners: [$sender]
|
|
116
|
-
tags: [
|
|
117
|
-
{ name: "appName", values: ["HumaFinance"] }
|
|
118
|
-
{ name: "poolName", values: [$poolName] }
|
|
119
|
-
{ name: "poolType", values: [$poolType] }
|
|
120
|
-
{ name: "internalId", values: [$internalId] }
|
|
121
|
-
]
|
|
122
|
-
) {
|
|
123
|
-
edges {
|
|
124
|
-
node {
|
|
125
|
-
id
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
`;
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
-
const data = await (0, graphql_request_1.default)(`${config.nodeUrl}/graphql`, query, {
|
|
133
|
-
poolName,
|
|
134
|
-
poolType,
|
|
135
|
-
sender,
|
|
136
|
-
internalId,
|
|
137
|
-
});
|
|
138
|
-
return (_d = (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.transactions) === null || _a === void 0 ? void 0 : _a.edges) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.node) === null || _d === void 0 ? void 0 : _d.id;
|
|
139
|
-
}
|
|
140
|
-
exports.queryForMetadata = queryForMetadata;
|
|
141
|
-
//# sourceMappingURL=ARWeaveService.js.map
|