@huma-finance/sdk 0.0.10 → 0.0.12
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 +432 -0
- package/LICENSE +660 -660
- package/README.md +35 -31
- package/dist/cjs/graphql/generatedTypes.d.ts +40 -0
- package/dist/cjs/graphql/generatedTypes.js +9 -0
- package/dist/cjs/graphql/generatedTypes.js.map +1 -0
- package/dist/cjs/graphql/index.d.ts +1 -0
- package/dist/cjs/graphql/index.js +5 -0
- package/dist/cjs/graphql/index.js.map +1 -0
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +10 -0
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +22 -0
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +22 -0
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
- package/dist/cjs/helpers/PoolContractHelper.d.ts +15 -0
- package/dist/cjs/helpers/PoolContractHelper.js +39 -0
- package/dist/cjs/helpers/PoolContractHelper.js.map +1 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +22 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js.map +1 -0
- package/dist/cjs/helpers/index.d.ts +3 -0
- package/dist/cjs/helpers/index.js +7 -0
- package/dist/cjs/helpers/index.js.map +1 -0
- package/dist/cjs/hooks/index.d.ts +4 -0
- package/dist/cjs/hooks/index.js +8 -0
- package/dist/cjs/hooks/index.js.map +1 -0
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +10 -0
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +20 -0
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
- package/dist/cjs/hooks/useContract.d.ts +13 -0
- package/dist/cjs/hooks/useContract.js +31 -0
- package/dist/cjs/hooks/useContract.js.map +1 -0
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +21 -0
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -0
- package/dist/cjs/hooks/usePoolContract.d.ts +60 -0
- package/dist/cjs/hooks/usePoolContract.js +54 -0
- package/dist/cjs/hooks/usePoolContract.js.map +1 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.js +20 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.js.map +1 -0
- package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
- package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +17 -0
- package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/ARWeaveService.d.ts +81 -0
- package/dist/cjs/services/ARWeaveService.js +141 -0
- package/dist/cjs/services/ARWeaveService.js.map +1 -0
- package/dist/cjs/services/EAService.d.ts +18 -0
- package/dist/cjs/services/EAService.js +13 -0
- package/dist/cjs/services/EAService.js.map +1 -0
- package/dist/cjs/services/ReceivableService.d.ts +87 -0
- package/dist/cjs/services/ReceivableService.js +189 -0
- package/dist/cjs/services/ReceivableService.js.map +1 -0
- package/dist/cjs/services/SubgraphService.d.ts +53 -0
- package/dist/cjs/services/SubgraphService.js +101 -0
- package/dist/cjs/services/SubgraphService.js.map +1 -0
- package/dist/cjs/services/index.d.ts +4 -0
- package/dist/cjs/services/index.js +8 -0
- package/dist/cjs/services/index.js.map +1 -0
- package/dist/cjs/utils/chain.d.ts +14 -0
- package/dist/cjs/utils/chain.js +34 -0
- package/dist/cjs/utils/chain.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +3 -0
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/poolInfo.d.ts +9 -0
- package/dist/cjs/utils/poolInfo.js +14 -0
- package/dist/cjs/utils/poolInfo.js.map +1 -0
- package/dist/cjs/utils/web3.d.ts +4 -0
- package/dist/cjs/utils/web3.js +29 -0
- package/dist/cjs/utils/web3.js.map +1 -0
- package/dist/graphql/generatedTypes.d.ts +40 -0
- package/dist/graphql/generatedTypes.js +5 -0
- package/dist/graphql/generatedTypes.js.map +1 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.js +2 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +10 -0
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +18 -0
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
- package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js +18 -0
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
- package/dist/helpers/PoolContractHelper.d.ts +15 -0
- package/dist/helpers/PoolContractHelper.js +33 -0
- package/dist/helpers/PoolContractHelper.js.map +1 -0
- package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
- package/dist/helpers/RealWorldReceivableContractHelper.js +18 -0
- package/dist/helpers/RealWorldReceivableContractHelper.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +10 -0
- package/dist/hooks/useBaseCreditPoolReceivableContract.js +16 -0
- package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
- package/dist/hooks/useContract.d.ts +13 -0
- package/dist/hooks/useContract.js +27 -0
- package/dist/hooks/useContract.js.map +1 -0
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
- package/dist/hooks/useERC20TransferableReceivableContract.js +17 -0
- package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -0
- package/dist/hooks/usePool.d.ts +0 -0
- package/dist/hooks/usePool.js +2 -0
- package/dist/hooks/usePool.js.map +1 -0
- package/dist/hooks/usePoolContract.d.ts +60 -0
- package/dist/hooks/usePoolContract.js +49 -0
- package/dist/hooks/usePoolContract.js.map +1 -0
- package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -0
- package/dist/hooks/useRealWorldReceivableContract.js +16 -0
- package/dist/hooks/useRealWorldReceivableContract.js.map +1 -0
- package/dist/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
- package/dist/hooks/useReceivableFactoringPoolContract.js +13 -0
- package/dist/hooks/useReceivableFactoringPoolContract.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/services/ARWeaveService.d.ts +81 -0
- package/dist/services/ARWeaveService.js +136 -0
- package/dist/services/ARWeaveService.js.map +1 -0
- package/dist/services/EAService.d.ts +18 -0
- package/dist/services/EAService.js +10 -0
- package/dist/services/EAService.js.map +1 -0
- package/dist/services/ReceivableService.d.ts +87 -0
- package/dist/services/ReceivableService.js +185 -0
- package/dist/services/ReceivableService.js.map +1 -0
- package/dist/services/SubgraphService.d.ts +53 -0
- package/dist/services/SubgraphService.js +98 -0
- package/dist/services/SubgraphService.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +5 -0
- package/dist/services/index.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/utils/chain.d.ts +14 -0
- package/dist/utils/chain.js +29 -0
- package/dist/utils/chain.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/poolInfo.d.ts +9 -0
- package/dist/utils/poolInfo.js +10 -0
- package/dist/utils/poolInfo.js.map +1 -0
- package/dist/utils/web3.d.ts +4 -0
- package/dist/utils/web3.js +24 -0
- package/dist/utils/web3.js.map +1 -0
- package/getting-started.md +191 -0
- package/package.json +11 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRealWorldReceivableContract = void 0;
|
|
4
|
+
const shared_1 = require("@huma-finance/shared");
|
|
5
|
+
const useContract_1 = require("./useContract");
|
|
6
|
+
/**
|
|
7
|
+
* A react hook that returns an ethers contract instance for the RealWorldReceivable 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 RealWorldReceivable contract or null if it could not be found.
|
|
13
|
+
*/
|
|
14
|
+
function useRealWorldReceivableContract(signerOrProvider, chainId) {
|
|
15
|
+
var _a;
|
|
16
|
+
const realWorldReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable];
|
|
17
|
+
return (0, useContract_1.useContract)(realWorldReceivable, shared_1.REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
|
|
18
|
+
}
|
|
19
|
+
exports.useRealWorldReceivableContract = useRealWorldReceivableContract;
|
|
20
|
+
//# sourceMappingURL=useRealWorldReceivableContract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRealWorldReceivableContract.js","sourceRoot":"","sources":["../../../src/hooks/useRealWorldReceivableContract.ts"],"names":[],"mappings":";;;AACA,iDAK6B;AAE7B,+CAA2C;AAE3C;;;;;;;GAOG;AACH,SAAgB,8BAA8B,CAC5C,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,mBAAmB,GACvB,MAAA,kCAAyB,CAAC,OAAO,CAAC,0CAChC,+BAAsB,CAAC,mBAAmB,CAC3C,CAAA;IAEH,OAAO,IAAA,yBAAW,EAChB,mBAAmB,EACnB,kCAAyB,EACzB,gBAAgB,CACjB,CAAA;AACH,CAAC;AAdD,wEAcC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,kDAAuB;AACvB,qDAA0B;AAC1B,kDAAuB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { FundResponse, UploadResponse } from '@bundlr-network/client/build/common/types';
|
|
2
|
+
import { Web3Provider } from '@ethersproject/providers';
|
|
3
|
+
/**
|
|
4
|
+
* The configuration for Bundlr network instances
|
|
5
|
+
*
|
|
6
|
+
* @typedef {Object} BundlrConfig
|
|
7
|
+
* @memberof ArweaveService
|
|
8
|
+
* @property {string} nodeUrl - The Bundlr node URL to use.
|
|
9
|
+
* @property {string} currency - The currency to pay for uploads with.
|
|
10
|
+
* Please see https://docs.bundlr.network/sdk/using-other-currencies for all the supported currencies
|
|
11
|
+
* @property {string} [providerUrl] - The provider URL, required for devnets.
|
|
12
|
+
*/
|
|
13
|
+
export type BundlrConfig = {
|
|
14
|
+
nodeUrl: string;
|
|
15
|
+
currency: string;
|
|
16
|
+
providerUrl?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get the configuration for Bundlr network given a chain ID
|
|
20
|
+
*
|
|
21
|
+
* @function
|
|
22
|
+
* @memberof ArweaveService
|
|
23
|
+
* @param {number} chainId - The chain ID.
|
|
24
|
+
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getBundlrNetworkConfig(chainId: number): BundlrConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Prefund the Bundlr network with the specified amount. Required if not lazy funding.
|
|
29
|
+
*
|
|
30
|
+
* @async
|
|
31
|
+
* @function
|
|
32
|
+
* @memberof ArweaveService
|
|
33
|
+
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
34
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
35
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
36
|
+
* @returns {Promise<FundResponse>} - The fund response.
|
|
37
|
+
*/
|
|
38
|
+
declare function prefundBundlr(config: BundlrConfig, signer: any, amount: number): Promise<FundResponse>;
|
|
39
|
+
/**
|
|
40
|
+
* Store data on ARWeave using the Bundlr Network.
|
|
41
|
+
*
|
|
42
|
+
* @async
|
|
43
|
+
* @function
|
|
44
|
+
* @memberof ArweaveService
|
|
45
|
+
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
46
|
+
* @param {Web3Provider | string} signerOrPrivateKey - Wallet object used for interacting with the Bundlr instance.
|
|
47
|
+
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
48
|
+
* environment, this should be a private key string.
|
|
49
|
+
* @param {JSON} data - The data to store in the Bundlr instance.
|
|
50
|
+
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
51
|
+
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
52
|
+
* Bundlr node should already be funded or else uploads will fail.
|
|
53
|
+
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
54
|
+
*/
|
|
55
|
+
declare function storeData(config: BundlrConfig, signerOrPrivateKey: Web3Provider | string, data: JSON, tags: {
|
|
56
|
+
name: string;
|
|
57
|
+
value: string;
|
|
58
|
+
}[], lazyFund?: boolean): Promise<UploadResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
61
|
+
*
|
|
62
|
+
* @async
|
|
63
|
+
* @function
|
|
64
|
+
* @memberof ArweaveService
|
|
65
|
+
* @param {number} chainId - The chain ID.
|
|
66
|
+
* @param {string} sender - The sender tag to query.
|
|
67
|
+
* @param {string} referenceId - The referenceId tag to query, whatever was used when uploading the metadata.
|
|
68
|
+
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
69
|
+
*/
|
|
70
|
+
declare function queryForMetadata(chainId: number, sender: string, referenceId: string): Promise<string | null>;
|
|
71
|
+
/**
|
|
72
|
+
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
73
|
+
* @namespace ARWeaveService
|
|
74
|
+
*/
|
|
75
|
+
export declare const ARWeaveService: {
|
|
76
|
+
queryForMetadata: typeof queryForMetadata;
|
|
77
|
+
storeData: typeof storeData;
|
|
78
|
+
prefundBundlr: typeof prefundBundlr;
|
|
79
|
+
getBundlrNetworkConfig: typeof getBundlrNetworkConfig;
|
|
80
|
+
};
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ARWeaveService = 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
|
+
* @memberof ArweaveService
|
|
12
|
+
* @param {number} chainId - The chain ID.
|
|
13
|
+
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
14
|
+
*/
|
|
15
|
+
function getBundlrNetworkConfig(chainId) {
|
|
16
|
+
switch (chainId) {
|
|
17
|
+
case 5:
|
|
18
|
+
return {
|
|
19
|
+
nodeUrl: 'https://devnet.bundlr.network',
|
|
20
|
+
currency: 'ethereum',
|
|
21
|
+
providerUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
|
22
|
+
};
|
|
23
|
+
case 80001:
|
|
24
|
+
return {
|
|
25
|
+
nodeUrl: 'https://devnet.bundlr.network',
|
|
26
|
+
currency: 'matic',
|
|
27
|
+
providerUrl: 'https://rpc-mumbai.matic.today',
|
|
28
|
+
};
|
|
29
|
+
default:
|
|
30
|
+
return {
|
|
31
|
+
nodeUrl: '',
|
|
32
|
+
currency: '',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.getBundlrNetworkConfig = getBundlrNetworkConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Prefund the Bundlr network with the specified amount. Required if not lazy funding.
|
|
39
|
+
*
|
|
40
|
+
* @async
|
|
41
|
+
* @function
|
|
42
|
+
* @memberof ArweaveService
|
|
43
|
+
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
44
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
45
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
46
|
+
* @returns {Promise<FundResponse>} - The fund response.
|
|
47
|
+
*/
|
|
48
|
+
async function prefundBundlr(config,
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
signer, amount) {
|
|
51
|
+
const bundlr = new client_1.default(config.nodeUrl, config.currency, signer, config.providerUrl
|
|
52
|
+
? {
|
|
53
|
+
providerUrl: config.providerUrl,
|
|
54
|
+
}
|
|
55
|
+
: undefined);
|
|
56
|
+
await bundlr.ready();
|
|
57
|
+
return bundlr.fund(amount);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Store data on ARWeave using the Bundlr Network.
|
|
61
|
+
*
|
|
62
|
+
* @async
|
|
63
|
+
* @function
|
|
64
|
+
* @memberof ArweaveService
|
|
65
|
+
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
66
|
+
* @param {Web3Provider | string} signerOrPrivateKey - 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 a private key string.
|
|
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, signerOrPrivateKey, data, tags, lazyFund = true) {
|
|
76
|
+
const bundlr = new client_1.default(config.nodeUrl, config.currency, signerOrPrivateKey, 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
|
+
/**
|
|
94
|
+
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
95
|
+
*
|
|
96
|
+
* @async
|
|
97
|
+
* @function
|
|
98
|
+
* @memberof ArweaveService
|
|
99
|
+
* @param {number} chainId - The chain ID.
|
|
100
|
+
* @param {string} sender - The sender tag to query.
|
|
101
|
+
* @param {string} referenceId - The referenceId 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, sender, referenceId) {
|
|
105
|
+
var _a, _b, _c, _d;
|
|
106
|
+
const config = getBundlrNetworkConfig(chainId);
|
|
107
|
+
const query = (0, graphql_request_1.gql) `
|
|
108
|
+
query ArweaveHumaMetadataQuery($sender: String!, $referenceId: String!) {
|
|
109
|
+
transactions(
|
|
110
|
+
owners: [$sender]
|
|
111
|
+
tags: [
|
|
112
|
+
{ name: "appName", values: ["HumaFinance"] }
|
|
113
|
+
{ name: "referenceId", values: [$referenceId] }
|
|
114
|
+
]
|
|
115
|
+
) {
|
|
116
|
+
edges {
|
|
117
|
+
node {
|
|
118
|
+
id
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
+
const data = await (0, graphql_request_1.default)(`${config.nodeUrl}/graphql`, query, {
|
|
126
|
+
sender,
|
|
127
|
+
referenceId,
|
|
128
|
+
});
|
|
129
|
+
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;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
133
|
+
* @namespace ARWeaveService
|
|
134
|
+
*/
|
|
135
|
+
exports.ARWeaveService = {
|
|
136
|
+
queryForMetadata,
|
|
137
|
+
storeData,
|
|
138
|
+
prefundBundlr,
|
|
139
|
+
getBundlrNetworkConfig,
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=ARWeaveService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../../src/services/ARWeaveService.ts"],"names":[],"mappings":";;;;AAAA,4EAA2C;AAM3C,2EAA8C;AAkB9C;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IACpD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC;YACJ,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,UAAU;gBACpB,WAAW,EACT,8DAA8D;aACjE,CAAA;QACH,KAAK,KAAK;YACR,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE,OAAO;gBACjB,WAAW,EAAE,gCAAgC;aAC9C,CAAA;QACH;YACE,OAAO;gBACL,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;aACb,CAAA;KACJ;AACH,CAAC;AArBD,wDAqBC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,aAAa,CAC1B,MAAo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,EAAE,IAAI,EAAE,CAAC,CAAA;AACzC,CAAC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,gBAAgB,CAC7B,OAAe,EACf,MAAc,EACd,WAAmB;;IAEnB,MAAM,MAAM,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;GAgBhB,CAAA;IAED,8DAA8D;IAC9D,MAAM,IAAI,GAAQ,MAAM,IAAA,yBAAO,EAAC,GAAG,MAAM,CAAC,OAAO,UAAU,EAAE,KAAK,EAAE;QAClE,MAAM;QACN,WAAW;KACZ,CAAC,CAAA;IAEF,OAAO,MAAA,MAAA,MAAA,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,YAAY,0CAAE,KAAK,0CAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,EAAE,CAAA;AACjD,CAAC;AAED;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,gBAAgB;IAChB,SAAS;IACT,aAAa;IACb,sBAAsB;CACvB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Object representing the response to the underwriting approval request.
|
|
3
|
+
* @typedef {Object} ApprovalResult
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Object representing an invoice payload for underwriting approval.
|
|
7
|
+
*
|
|
8
|
+
* @typedef {Object} EAPayload
|
|
9
|
+
*/
|
|
10
|
+
export type { ApprovalResult, EAPayload } from '@huma-finance/shared';
|
|
11
|
+
/**
|
|
12
|
+
* An object that contains functions to interact with Huma's EAVerse service.
|
|
13
|
+
*
|
|
14
|
+
* @namespace EAService
|
|
15
|
+
*/
|
|
16
|
+
export declare const EAService: {
|
|
17
|
+
approve: (payload: import("@huma-finance/shared").EAPayload, chainId: number, isDev?: boolean | undefined) => Promise<import("@huma-finance/shared").Approval>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EAService = void 0;
|
|
4
|
+
const shared_1 = require("@huma-finance/shared");
|
|
5
|
+
/**
|
|
6
|
+
* An object that contains functions to interact with Huma's EAVerse service.
|
|
7
|
+
*
|
|
8
|
+
* @namespace EAService
|
|
9
|
+
*/
|
|
10
|
+
exports.EAService = {
|
|
11
|
+
approve: shared_1.EAService.approve,
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=EAService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EAService.js","sourceRoot":"","sources":["../../../src/services/EAService.ts"],"names":[],"mappings":";;;AAAA,iDAAqE;AAarE;;;;GAIG;AACU,QAAA,SAAS,GAAG;IACvB,OAAO,EAAE,kBAAiB,CAAC,OAAO;CACnC,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TransactionResponse, Web3Provider } from '@ethersproject/providers';
|
|
2
|
+
import { BigNumberish, ethers, Overrides } from 'ethers';
|
|
3
|
+
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
4
|
+
/**
|
|
5
|
+
* Declares a payment on a RealWorldReceivable given a reference ID of the receivable, which was used as an index for ARWeave data.
|
|
6
|
+
*
|
|
7
|
+
* @async
|
|
8
|
+
* @function
|
|
9
|
+
* @memberof ReceivableService
|
|
10
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
11
|
+
* @param {string} referenceId - An internal identifier value added as a tag on ARWeave
|
|
12
|
+
* @param {number} paymentAmount - The amount to declare paid to the receivable.
|
|
13
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
14
|
+
*/
|
|
15
|
+
declare function declareReceivablePaymentByReferenceId(signer: ethers.Signer, referenceId: string, paymentAmount: number): Promise<TransactionResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
|
|
18
|
+
*
|
|
19
|
+
* @async
|
|
20
|
+
* @function
|
|
21
|
+
* @memberof ReceivableService
|
|
22
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
23
|
+
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
24
|
+
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
25
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
26
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
27
|
+
*/
|
|
28
|
+
declare function declareReceivablePaymentByTokenId(signer: ethers.Signer, receivableTokenId: BigNumberish, paymentAmount: number): Promise<TransactionResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new RealWorldReceivable token on the given chain of the signer
|
|
31
|
+
*
|
|
32
|
+
* @async
|
|
33
|
+
* @function
|
|
34
|
+
* @memberof ReceivableService
|
|
35
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
36
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
37
|
+
* @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
38
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
39
|
+
* @param {number} receivableAmount - The amount of the receivable token to mint.
|
|
40
|
+
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
41
|
+
* @param {string} uri - The URI of the receivable token metadata.
|
|
42
|
+
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
43
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
44
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
45
|
+
*/
|
|
46
|
+
declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, uri: string, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
49
|
+
*
|
|
50
|
+
* @async
|
|
51
|
+
* @function
|
|
52
|
+
* @memberof ReceivableService
|
|
53
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
54
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
55
|
+
* from server calls.
|
|
56
|
+
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
57
|
+
* @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
|
|
58
|
+
* @param {string} recipient - The receivable token recipient.
|
|
59
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
60
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
61
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
62
|
+
* @param {number} receivableAmount - The receivable amount.
|
|
63
|
+
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
64
|
+
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
65
|
+
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
66
|
+
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
67
|
+
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
68
|
+
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
69
|
+
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
70
|
+
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
71
|
+
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
72
|
+
*/
|
|
73
|
+
declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, metadata: JSON, referenceId: string, extraTags: {
|
|
74
|
+
name: string;
|
|
75
|
+
value: string;
|
|
76
|
+
}[], lazyFund?: boolean, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* An object that contains functions to interact with Huma's receivables.
|
|
79
|
+
* @namespace ReceivableService
|
|
80
|
+
*/
|
|
81
|
+
export declare const ReceivableService: {
|
|
82
|
+
createReceivableWithMetadata: typeof createReceivableWithMetadata;
|
|
83
|
+
createReceivable: typeof createReceivable;
|
|
84
|
+
declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
|
|
85
|
+
declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
|
|
86
|
+
};
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReceivableService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const providers_1 = require("@ethersproject/providers");
|
|
6
|
+
const shared_1 = require("@huma-finance/shared");
|
|
7
|
+
const graphql_request_1 = tslib_1.__importStar(require("graphql-request"));
|
|
8
|
+
const ARWeaveService_1 = require("./ARWeaveService");
|
|
9
|
+
const helpers_1 = require("../helpers");
|
|
10
|
+
const chain_1 = require("../utils/chain");
|
|
11
|
+
/**
|
|
12
|
+
* Declares a payment on a RealWorldReceivable given a reference ID of the receivable, which was used as an index for ARWeave data.
|
|
13
|
+
*
|
|
14
|
+
* @async
|
|
15
|
+
* @function
|
|
16
|
+
* @memberof ReceivableService
|
|
17
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
18
|
+
* @param {string} referenceId - An internal identifier value added as a tag on ARWeave
|
|
19
|
+
* @param {number} paymentAmount - The amount to declare paid to the receivable.
|
|
20
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
21
|
+
*/
|
|
22
|
+
async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
25
|
+
const signerAddress = await signer.getAddress();
|
|
26
|
+
if (!chainId) {
|
|
27
|
+
throw new Error('No Chain ID found');
|
|
28
|
+
}
|
|
29
|
+
// Get ARWeave ID
|
|
30
|
+
const dataID = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
|
|
31
|
+
// Fetch receivables with the same ARWeave ID
|
|
32
|
+
const receivablesQuery = (0, graphql_request_1.gql) `
|
|
33
|
+
query ReceivablesByURIQuery($owner: String!, $uri: String!) {
|
|
34
|
+
receivables(where: { owner: $owner, uri: $uri }) {
|
|
35
|
+
...ReceivableFields
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fragment ReceivableFields on Receivable {
|
|
40
|
+
tokenId
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
let receivableSubgraph;
|
|
44
|
+
switch (chainId) {
|
|
45
|
+
case shared_1.ChainEnum.Goerli:
|
|
46
|
+
receivableSubgraph = `https://api.thegraph.com/subgraphs/name/00labs/huma-receivables-goerli`;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
throw new Error('No receivable subgraph exists for this chain');
|
|
50
|
+
}
|
|
51
|
+
const receivablesData = await (0, graphql_request_1.default)(receivableSubgraph, receivablesQuery, {
|
|
52
|
+
owner: signerAddress,
|
|
53
|
+
uri: `https://arweave.net/${dataID}`,
|
|
54
|
+
});
|
|
55
|
+
if (!(receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) || !((_a = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
56
|
+
throw new Error('No receivables found with this ARWeave ID.');
|
|
57
|
+
}
|
|
58
|
+
else if (((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length) > 1) {
|
|
59
|
+
throw new Error(`This owner has multiple receivables with the same URI. Please burn
|
|
60
|
+
unnecessary receivables or pay the correct token manually using declareReceivablePaymentByTokenId`);
|
|
61
|
+
}
|
|
62
|
+
const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
|
|
63
|
+
if (!contract) {
|
|
64
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
65
|
+
}
|
|
66
|
+
return contract.declarePayment((_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _c === void 0 ? void 0 : _c.tokenId, paymentAmount);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
|
|
70
|
+
*
|
|
71
|
+
* @async
|
|
72
|
+
* @function
|
|
73
|
+
* @memberof ReceivableService
|
|
74
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
75
|
+
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
76
|
+
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
77
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
78
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
79
|
+
*/
|
|
80
|
+
async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount) {
|
|
81
|
+
var _a;
|
|
82
|
+
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
83
|
+
if (!chainId) {
|
|
84
|
+
throw new Error('No Chain ID found');
|
|
85
|
+
}
|
|
86
|
+
const realWorldReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable];
|
|
87
|
+
if (!realWorldReceivable) {
|
|
88
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
89
|
+
}
|
|
90
|
+
const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
|
|
91
|
+
if (!contract) {
|
|
92
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
93
|
+
}
|
|
94
|
+
return contract.declarePayment(receivableTokenId, paymentAmount);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new RealWorldReceivable token on the given chain of the signer
|
|
98
|
+
*
|
|
99
|
+
* @async
|
|
100
|
+
* @function
|
|
101
|
+
* @memberof ReceivableService
|
|
102
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
103
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
104
|
+
* @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
105
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
106
|
+
* @param {number} receivableAmount - The amount of the receivable token to mint.
|
|
107
|
+
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
108
|
+
* @param {string} uri - The URI of the receivable token metadata.
|
|
109
|
+
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
110
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
111
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
112
|
+
*/
|
|
113
|
+
async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
116
|
+
if (!chainId) {
|
|
117
|
+
throw new Error('No Chain ID found');
|
|
118
|
+
}
|
|
119
|
+
const poolInfo = chainId
|
|
120
|
+
? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
|
|
121
|
+
: undefined;
|
|
122
|
+
if (!poolInfo) {
|
|
123
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
124
|
+
}
|
|
125
|
+
const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
|
|
126
|
+
if (!contract) {
|
|
127
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
128
|
+
}
|
|
129
|
+
return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
133
|
+
*
|
|
134
|
+
* @async
|
|
135
|
+
* @function
|
|
136
|
+
* @memberof ReceivableService
|
|
137
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
138
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
139
|
+
* from server calls.
|
|
140
|
+
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
141
|
+
* @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
|
|
142
|
+
* @param {string} recipient - The receivable token recipient.
|
|
143
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
144
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
145
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
146
|
+
* @param {number} receivableAmount - The receivable amount.
|
|
147
|
+
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
148
|
+
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
149
|
+
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
150
|
+
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
151
|
+
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
152
|
+
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
153
|
+
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
154
|
+
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
155
|
+
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
156
|
+
*/
|
|
157
|
+
async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
|
|
158
|
+
const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
|
|
159
|
+
try {
|
|
160
|
+
const tags = [
|
|
161
|
+
{ name: 'Content-Type', value: 'application/json' },
|
|
162
|
+
{ name: 'appName', value: 'HumaFinance' },
|
|
163
|
+
{ name: 'poolName', value: poolName },
|
|
164
|
+
{ name: 'poolType', value: poolType },
|
|
165
|
+
{ name: 'referenceId', value: referenceId },
|
|
166
|
+
...extraTags,
|
|
167
|
+
];
|
|
168
|
+
const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
|
|
169
|
+
console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
|
|
170
|
+
return await createReceivable(signerOrProvider instanceof providers_1.Web3Provider
|
|
171
|
+
? signerOrProvider.getSigner()
|
|
172
|
+
: signerOrProvider, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${response.id}`, gasOpts);
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
console.error(e);
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* An object that contains functions to interact with Huma's receivables.
|
|
181
|
+
* @namespace ReceivableService
|
|
182
|
+
*/
|
|
183
|
+
exports.ReceivableService = {
|
|
184
|
+
createReceivableWithMetadata,
|
|
185
|
+
createReceivable,
|
|
186
|
+
declareReceivablePaymentByTokenId,
|
|
187
|
+
declareReceivablePaymentByReferenceId,
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=ReceivableService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;;AAAA,wDAA4E;AAE5E,iDAO6B;AAC7B,2EAA8C;AAE9C,qDAAiD;AACjD,wCAA2D;AAC3D,0CAA+D;AAG/D;;;;;;;;;;GAUG;AACH,KAAK,UAAU,qCAAqC,CAClD,MAAqB,EACrB,WAAmB,EACnB,aAAqB;;IAErB,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;IAE/C,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,iBAAiB;IACjB,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,gBAAgB,CAClD,OAAO,EACP,aAAa,EACb,WAAW,CACZ,CAAA;IAED,6CAA6C;IAC7C,MAAM,gBAAgB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;GAU3B,CAAA;IAED,IAAI,kBAAkB,CAAA;IACtB,QAAQ,OAAO,EAAE;QACf,KAAK,kBAAS,CAAC,MAAM;YACnB,kBAAkB,GAAG,wEAAwE,CAAA;YAC7F,MAAK;QACP;YACE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;KAClE;IAED,MAAM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