@huma-finance/sdk 0.0.10 → 0.0.11
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 +30 -30
- 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 +12 -0
- package/dist/cjs/helpers/PoolContractHelper.js +21 -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 +98 -0
- package/dist/cjs/services/ARWeaveService.js +175 -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 +76 -0
- package/dist/cjs/services/ReceivableService.js +138 -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/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 +12 -0
- package/dist/helpers/PoolContractHelper.js +17 -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 +84 -0
- package/dist/services/ARWeaveService.js +147 -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 +76 -0
- package/dist/services/ReceivableService.js +135 -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/package.json +3 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { FundResponse, UploadResponse } from '@bundlr-network/client/build/common/types';
|
|
2
|
+
import { Web3Provider } from '@ethersproject/providers';
|
|
3
|
+
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
4
|
+
import { BigNumber } from 'ethers';
|
|
5
|
+
/**
|
|
6
|
+
* The configuration for Bundlr network instances
|
|
7
|
+
*
|
|
8
|
+
* @typedef {Object} BundlrConfig
|
|
9
|
+
* @memberof ArweaveService
|
|
10
|
+
* @property {string} nodeUrl - The Bundlr node URL to use.
|
|
11
|
+
* @property {string} currency - The currency to pay for uploads with.
|
|
12
|
+
* Please see https://docs.bundlr.network/sdk/using-other-currencies for all the supported currencies
|
|
13
|
+
* @property {string} [providerUrl] - The provider URL, required for devnets.
|
|
14
|
+
*/
|
|
15
|
+
export type BundlrConfig = {
|
|
16
|
+
nodeUrl: string;
|
|
17
|
+
currency: string;
|
|
18
|
+
providerUrl?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Get the configuration for Bundlr network given a chain ID
|
|
22
|
+
*
|
|
23
|
+
* @function
|
|
24
|
+
* @memberof ArweaveService
|
|
25
|
+
* @param {number} chainId - The chain ID.
|
|
26
|
+
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getBundlrNetworkConfig(chainId: number): BundlrConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Prefund the Bundlr network with the specified amount. Required if not lazy funding.
|
|
31
|
+
*
|
|
32
|
+
* @async
|
|
33
|
+
* @function
|
|
34
|
+
* @memberof ArweaveService
|
|
35
|
+
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
36
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
37
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
38
|
+
* @returns {Promise<FundResponse>} - The fund response.
|
|
39
|
+
*/
|
|
40
|
+
declare function prefundBundlr(config: BundlrConfig, signer: any, amount: number): Promise<FundResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Get the running balance on Bundlr network, in atomic units (the smallest unit of a given currency)
|
|
43
|
+
*
|
|
44
|
+
* @async
|
|
45
|
+
* @function
|
|
46
|
+
* @memberof ArweaveService
|
|
47
|
+
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
48
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
49
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
50
|
+
* @returns {Promise<FundResponse>} - The fund response.
|
|
51
|
+
*/
|
|
52
|
+
declare function getBundlrBalance(config: BundlrConfig, signer: any): Promise<BigNumber>;
|
|
53
|
+
/**
|
|
54
|
+
* Store data on ARWeave using the Bundlr Network.
|
|
55
|
+
*
|
|
56
|
+
* @async
|
|
57
|
+
* @function
|
|
58
|
+
* @memberof ArweaveService
|
|
59
|
+
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
60
|
+
* @param {Web3Provider | string} signerOrPrivateKey - Wallet object used for interacting with the Bundlr instance.
|
|
61
|
+
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
62
|
+
* environment, this should be a private key string.
|
|
63
|
+
* @param {JSON} data - The data to store in the Bundlr instance.
|
|
64
|
+
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
65
|
+
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
66
|
+
* Bundlr node should already be funded or else uploads will fail.
|
|
67
|
+
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
68
|
+
*/
|
|
69
|
+
declare function storeData(config: BundlrConfig, signerOrPrivateKey: Web3Provider | string, data: JSON, tags: {
|
|
70
|
+
name: string;
|
|
71
|
+
value: string;
|
|
72
|
+
}[], lazyFund?: boolean): Promise<UploadResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
75
|
+
*
|
|
76
|
+
* @async
|
|
77
|
+
* @function
|
|
78
|
+
* @memberof ArweaveService
|
|
79
|
+
* @param {number} chainId - The chain ID.
|
|
80
|
+
* @param {POOL_NAME} poolName - The pool name tag to query.
|
|
81
|
+
* @param {POOL_TYPE} poolType - The pool type tag to query.
|
|
82
|
+
* @param {string} sender - The sender tag to query.
|
|
83
|
+
* @param {string} referenceId - The referenceId tag to query, whatever was used when uploading the metadata.
|
|
84
|
+
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
85
|
+
*/
|
|
86
|
+
declare function queryForMetadata(chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, sender: string, referenceId: string): Promise<string | null>;
|
|
87
|
+
/**
|
|
88
|
+
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
89
|
+
* @namespace ARWeaveService
|
|
90
|
+
*/
|
|
91
|
+
export declare const ARWeaveService: {
|
|
92
|
+
getBundlrBalance: typeof getBundlrBalance;
|
|
93
|
+
queryForMetadata: typeof queryForMetadata;
|
|
94
|
+
storeData: typeof storeData;
|
|
95
|
+
prefundBundlr: typeof prefundBundlr;
|
|
96
|
+
getBundlrNetworkConfig: typeof getBundlrNetworkConfig;
|
|
97
|
+
};
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
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
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
/**
|
|
9
|
+
* Get the configuration for Bundlr network given a chain ID
|
|
10
|
+
*
|
|
11
|
+
* @function
|
|
12
|
+
* @memberof ArweaveService
|
|
13
|
+
* @param {number} chainId - The chain ID.
|
|
14
|
+
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
15
|
+
*/
|
|
16
|
+
function getBundlrNetworkConfig(chainId) {
|
|
17
|
+
switch (chainId) {
|
|
18
|
+
case 5:
|
|
19
|
+
return {
|
|
20
|
+
nodeUrl: 'https://devnet.bundlr.network',
|
|
21
|
+
currency: 'ethereum',
|
|
22
|
+
providerUrl: 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
|
|
23
|
+
};
|
|
24
|
+
case 80001:
|
|
25
|
+
return {
|
|
26
|
+
nodeUrl: 'https://devnet.bundlr.network',
|
|
27
|
+
currency: 'matic',
|
|
28
|
+
providerUrl: 'https://rpc-mumbai.matic.today',
|
|
29
|
+
};
|
|
30
|
+
default:
|
|
31
|
+
return {
|
|
32
|
+
nodeUrl: '',
|
|
33
|
+
currency: '',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.getBundlrNetworkConfig = getBundlrNetworkConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Prefund the Bundlr network with the specified amount. Required if not lazy funding.
|
|
40
|
+
*
|
|
41
|
+
* @async
|
|
42
|
+
* @function
|
|
43
|
+
* @memberof ArweaveService
|
|
44
|
+
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
45
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
46
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
47
|
+
* @returns {Promise<FundResponse>} - The fund response.
|
|
48
|
+
*/
|
|
49
|
+
async function prefundBundlr(config,
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
signer, amount) {
|
|
52
|
+
const bundlr = new client_1.default(config.nodeUrl, config.currency, signer, config.providerUrl
|
|
53
|
+
? {
|
|
54
|
+
providerUrl: config.providerUrl,
|
|
55
|
+
}
|
|
56
|
+
: undefined);
|
|
57
|
+
await bundlr.ready();
|
|
58
|
+
return bundlr.fund(amount);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the running balance on Bundlr network, in atomic units (the smallest unit of a given currency)
|
|
62
|
+
*
|
|
63
|
+
* @async
|
|
64
|
+
* @function
|
|
65
|
+
* @memberof ArweaveService
|
|
66
|
+
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
67
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
68
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
69
|
+
* @returns {Promise<FundResponse>} - The fund response.
|
|
70
|
+
*/
|
|
71
|
+
async function getBundlrBalance(config,
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
+
signer) {
|
|
74
|
+
const bundlr = new client_1.default(config.nodeUrl, config.currency, signer, config.providerUrl
|
|
75
|
+
? {
|
|
76
|
+
providerUrl: config.providerUrl,
|
|
77
|
+
}
|
|
78
|
+
: undefined);
|
|
79
|
+
return ethers_1.BigNumber.from(await bundlr.getLoadedBalance());
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Store data on ARWeave using the Bundlr Network.
|
|
83
|
+
*
|
|
84
|
+
* @async
|
|
85
|
+
* @function
|
|
86
|
+
* @memberof ArweaveService
|
|
87
|
+
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
88
|
+
* @param {Web3Provider | string} signerOrPrivateKey - Wallet object used for interacting with the Bundlr instance.
|
|
89
|
+
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
90
|
+
* environment, this should be a private key string.
|
|
91
|
+
* @param {JSON} data - The data to store in the Bundlr instance.
|
|
92
|
+
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
93
|
+
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
94
|
+
* Bundlr node should already be funded or else uploads will fail.
|
|
95
|
+
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
96
|
+
*/
|
|
97
|
+
async function storeData(config, signerOrPrivateKey, data, tags, lazyFund = true) {
|
|
98
|
+
const bundlr = new client_1.default(config.nodeUrl, config.currency, signerOrPrivateKey, config.providerUrl
|
|
99
|
+
? {
|
|
100
|
+
providerUrl: config.providerUrl,
|
|
101
|
+
}
|
|
102
|
+
: undefined);
|
|
103
|
+
await bundlr.ready();
|
|
104
|
+
const dataStr = JSON.stringify(data);
|
|
105
|
+
if (lazyFund) {
|
|
106
|
+
const size = Buffer.byteLength(dataStr);
|
|
107
|
+
const price = await bundlr.getPrice(size);
|
|
108
|
+
// Add a buffer of 10% to account for fluctuations in the price
|
|
109
|
+
price.multipliedBy(1.1);
|
|
110
|
+
console.log(`Funding bundlr with ${price} ${config.currency} to upload data`);
|
|
111
|
+
await bundlr.fund(price);
|
|
112
|
+
}
|
|
113
|
+
return bundlr.upload(dataStr, { tags });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
117
|
+
*
|
|
118
|
+
* @async
|
|
119
|
+
* @function
|
|
120
|
+
* @memberof ArweaveService
|
|
121
|
+
* @param {number} chainId - The chain ID.
|
|
122
|
+
* @param {POOL_NAME} poolName - The pool name tag to query.
|
|
123
|
+
* @param {POOL_TYPE} poolType - The pool type tag to query.
|
|
124
|
+
* @param {string} sender - The sender tag to query.
|
|
125
|
+
* @param {string} referenceId - The referenceId tag to query, whatever was used when uploading the metadata.
|
|
126
|
+
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
127
|
+
*/
|
|
128
|
+
async function queryForMetadata(chainId, poolName, poolType, sender, referenceId) {
|
|
129
|
+
var _a, _b, _c, _d;
|
|
130
|
+
const config = getBundlrNetworkConfig(chainId);
|
|
131
|
+
const query = (0, graphql_request_1.gql) `
|
|
132
|
+
query ArweaveHumaMetadataQuery(
|
|
133
|
+
$poolName: String!
|
|
134
|
+
$poolType: String!
|
|
135
|
+
$sender: String!
|
|
136
|
+
$referenceId: String!
|
|
137
|
+
) {
|
|
138
|
+
transactions(
|
|
139
|
+
owners: [$sender]
|
|
140
|
+
tags: [
|
|
141
|
+
{ name: "appName", values: ["HumaFinance"] }
|
|
142
|
+
{ name: "poolName", values: [$poolName] }
|
|
143
|
+
{ name: "poolType", values: [$poolType] }
|
|
144
|
+
{ name: "referenceId", values: [$referenceId] }
|
|
145
|
+
]
|
|
146
|
+
) {
|
|
147
|
+
edges {
|
|
148
|
+
node {
|
|
149
|
+
id
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
`;
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
+
const data = await (0, graphql_request_1.default)(`${config.nodeUrl}/graphql`, query, {
|
|
157
|
+
poolName,
|
|
158
|
+
poolType,
|
|
159
|
+
sender,
|
|
160
|
+
referenceId,
|
|
161
|
+
});
|
|
162
|
+
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;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
166
|
+
* @namespace ARWeaveService
|
|
167
|
+
*/
|
|
168
|
+
exports.ARWeaveService = {
|
|
169
|
+
getBundlrBalance,
|
|
170
|
+
queryForMetadata,
|
|
171
|
+
storeData,
|
|
172
|
+
prefundBundlr,
|
|
173
|
+
getBundlrNetworkConfig,
|
|
174
|
+
};
|
|
175
|
+
//# 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;AAE9C,mCAAkC;AAkBlC;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IACpD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC;YACJ,OAAO;gBACL,OAAO,EAAE,+BAA+B;gBACxC,QAAQ,EAAE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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,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,76 @@
|
|
|
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
|
+
declare function declareReceivablePaymentByReferenceId(signer: ethers.Signer, referenceId: string, paymentAmount: number): Promise<TransactionResponse>;
|
|
5
|
+
/**
|
|
6
|
+
* Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
|
|
7
|
+
*
|
|
8
|
+
* @async
|
|
9
|
+
* @function
|
|
10
|
+
* @memberof ReceivableService
|
|
11
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
12
|
+
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
13
|
+
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
14
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
15
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
16
|
+
*/
|
|
17
|
+
declare function declareReceivablePaymentByTokenId(signer: ethers.Signer, receivableTokenId: BigNumberish, paymentAmount: number): Promise<TransactionResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new RealWorldReceivable token on the given chain of the signer
|
|
20
|
+
*
|
|
21
|
+
* @async
|
|
22
|
+
* @function
|
|
23
|
+
* @memberof ReceivableService
|
|
24
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
25
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
26
|
+
* @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
27
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
28
|
+
* @param {number} receivableAmount - The amount of the receivable token to mint.
|
|
29
|
+
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
30
|
+
* @param {string} uri - The URI of the receivable token metadata.
|
|
31
|
+
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
32
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
33
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
34
|
+
*/
|
|
35
|
+
declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, uri: string, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
38
|
+
*
|
|
39
|
+
* @async
|
|
40
|
+
* @function
|
|
41
|
+
* @memberof ReceivableService
|
|
42
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
43
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
44
|
+
* from server calls.
|
|
45
|
+
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
46
|
+
* @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
|
|
47
|
+
* @param {string} recipient - The receivable token recipient.
|
|
48
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
49
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
50
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
51
|
+
* @param {number} receivableAmount - The receivable amount.
|
|
52
|
+
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
53
|
+
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
54
|
+
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
55
|
+
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
56
|
+
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
57
|
+
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
58
|
+
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
59
|
+
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
60
|
+
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
61
|
+
*/
|
|
62
|
+
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: {
|
|
63
|
+
name: string;
|
|
64
|
+
value: string;
|
|
65
|
+
}[], lazyFund?: boolean, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* An object that contains functions to interact with Huma's receivables.
|
|
68
|
+
* @namespace ReceivableService
|
|
69
|
+
*/
|
|
70
|
+
export declare const ReceivableService: {
|
|
71
|
+
createReceivableWithMetadata: typeof createReceivableWithMetadata;
|
|
72
|
+
createReceivable: typeof createReceivable;
|
|
73
|
+
declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
|
|
74
|
+
declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
|
|
75
|
+
};
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReceivableService = void 0;
|
|
4
|
+
const providers_1 = require("@ethersproject/providers");
|
|
5
|
+
const shared_1 = require("@huma-finance/shared");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const ARWeaveService_1 = require("./ARWeaveService");
|
|
8
|
+
const chain_1 = require("../utils/chain");
|
|
9
|
+
async function declareReceivablePaymentByReferenceId(
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
signer,
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
+
referenceId,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
+
paymentAmount) {
|
|
16
|
+
throw new Error('Not implemented');
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
|
|
20
|
+
*
|
|
21
|
+
* @async
|
|
22
|
+
* @function
|
|
23
|
+
* @memberof ReceivableService
|
|
24
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
25
|
+
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
26
|
+
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
27
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
|
|
28
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
29
|
+
*/
|
|
30
|
+
async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount) {
|
|
31
|
+
var _a;
|
|
32
|
+
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
33
|
+
const realWorldReceivable = chainId
|
|
34
|
+
? (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable]
|
|
35
|
+
: null;
|
|
36
|
+
if (!realWorldReceivable) {
|
|
37
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
38
|
+
}
|
|
39
|
+
const contract = (0, utils_1.getContract)(realWorldReceivable, shared_1.REAL_WORLD_RECEIVABLE_ABI, signer);
|
|
40
|
+
if (!contract) {
|
|
41
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
42
|
+
}
|
|
43
|
+
return contract.declarePayment(receivableTokenId, paymentAmount);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new RealWorldReceivable token on the given chain of the signer
|
|
47
|
+
*
|
|
48
|
+
* @async
|
|
49
|
+
* @function
|
|
50
|
+
* @memberof ReceivableService
|
|
51
|
+
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
52
|
+
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
53
|
+
* @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
54
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
55
|
+
* @param {number} receivableAmount - The amount of the receivable token to mint.
|
|
56
|
+
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
57
|
+
* @param {string} uri - The URI of the receivable token metadata.
|
|
58
|
+
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
59
|
+
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
60
|
+
* @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
|
|
61
|
+
*/
|
|
62
|
+
async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
|
|
65
|
+
const realWorldReceivable = chainId
|
|
66
|
+
? (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable]
|
|
67
|
+
: null;
|
|
68
|
+
const poolInfo = chainId
|
|
69
|
+
? (_c = (_b = shared_1.PoolContractMap[chainId]) === null || _b === void 0 ? void 0 : _b[poolType]) === null || _c === void 0 ? void 0 : _c[poolName]
|
|
70
|
+
: undefined;
|
|
71
|
+
if (!realWorldReceivable || !poolInfo) {
|
|
72
|
+
throw new Error('RealWorldReceivable is not available on this network');
|
|
73
|
+
}
|
|
74
|
+
const contract = (0, utils_1.getContract)(realWorldReceivable, shared_1.REAL_WORLD_RECEIVABLE_ABI, signer);
|
|
75
|
+
if (!contract) {
|
|
76
|
+
throw new Error('Could not find RealWorldReceivable contract');
|
|
77
|
+
}
|
|
78
|
+
return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
|
|
82
|
+
*
|
|
83
|
+
* @async
|
|
84
|
+
* @function
|
|
85
|
+
* @memberof ReceivableService
|
|
86
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
87
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
88
|
+
* from server calls.
|
|
89
|
+
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
90
|
+
* @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
|
|
91
|
+
* @param {string} recipient - The receivable token recipient.
|
|
92
|
+
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
93
|
+
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
94
|
+
* @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
|
|
95
|
+
* @param {number} receivableAmount - The receivable amount.
|
|
96
|
+
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
97
|
+
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
98
|
+
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
99
|
+
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
100
|
+
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
101
|
+
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
102
|
+
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
103
|
+
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
104
|
+
* @returns {Promise<TransactionResponse>} - The transaction receipt.
|
|
105
|
+
*/
|
|
106
|
+
async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
|
|
107
|
+
const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
|
|
108
|
+
try {
|
|
109
|
+
const tags = [
|
|
110
|
+
{ name: 'Content-Type', value: 'application/json' },
|
|
111
|
+
{ name: 'appName', value: 'HumaFinance' },
|
|
112
|
+
{ name: 'poolName', value: poolName },
|
|
113
|
+
{ name: 'poolType', value: poolType },
|
|
114
|
+
{ name: 'referenceId', value: referenceId },
|
|
115
|
+
...extraTags,
|
|
116
|
+
];
|
|
117
|
+
const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
|
|
118
|
+
console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
|
|
119
|
+
return await createReceivable(signerOrProvider instanceof providers_1.Web3Provider
|
|
120
|
+
? signerOrProvider.getSigner()
|
|
121
|
+
: signerOrProvider, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${response.id}`, gasOpts);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
console.error(e);
|
|
125
|
+
throw e;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* An object that contains functions to interact with Huma's receivables.
|
|
130
|
+
* @namespace ReceivableService
|
|
131
|
+
*/
|
|
132
|
+
exports.ReceivableService = {
|
|
133
|
+
createReceivableWithMetadata,
|
|
134
|
+
createReceivable,
|
|
135
|
+
declareReceivablePaymentByTokenId,
|
|
136
|
+
declareReceivablePaymentByReferenceId,
|
|
137
|
+
};
|
|
138
|
+
//# 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;AAE7B,oCAAsC;AACtC,qDAAiD;AACjD,0CAA+D;AAE/D,KAAK,UAAU,qCAAqC;AAClD,6DAA6D;AAC7D,MAAqB;AACrB,6DAA6D;AAC7D,WAAmB;AACnB,6DAA6D;AAC7D,aAAqB;IAErB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,iCAAiC,CAC9C,MAAqB,EACrB,iBAA+B,EAC/B,aAAqB;;IAErB,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAE5D,MAAM,mBAAmB,GAAG,OAAO;QACjC,CAAC,CAAC,MAAA,kCAAyB,CAAC,OAAO,CAAC,0CAChC,+BAAsB,CAAC,mBAAmB,CAC3C;QACH,CAAC,CAAC,IAAI,CAAA;IAER,IAAI,CAAC,mBAAmB,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;KACxE;IAED,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAC1B,mBAAmB,EACnB,kCAAyB,EACzB,MAAM,CACP,CAAA;IAED,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;KAC/D;IAED,OAAO,QAAQ,CAAC,cAAc,CAAC,iBAAiB,EAAE,aAAa,CAAC,C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AME, POOL_TYPE } from '@huma-finance/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the subgraph URL for a given chain ID.
|
|
4
|
+
*
|
|
5
|
+
* @memberof SubgraphService
|
|
6
|
+
* @param {number} chainId - The ID of the chain.
|
|
7
|
+
* @returns {string} The subgraph URL for the given chain ID.
|
|
8
|
+
*/
|
|
9
|
+
declare function getSubgraphUrlForChainId(chainId: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* Represents the payload of a credit event.
|
|
12
|
+
* @typedef {Object} CreditEventPayload
|
|
13
|
+
*/
|
|
14
|
+
export type CreditEventPayload = {
|
|
15
|
+
amount?: string;
|
|
16
|
+
timestamp?: string;
|
|
17
|
+
owner?: string;
|
|
18
|
+
pool?: string;
|
|
19
|
+
event?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Returns the credit events for a given user.
|
|
23
|
+
*
|
|
24
|
+
* @memberof SubgraphService
|
|
25
|
+
* @param {string} userAddress - The address of the user.
|
|
26
|
+
* @param {number} chainId - The ID of the chain.
|
|
27
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
28
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
29
|
+
* @param {string[]} event - The event types to filter by.
|
|
30
|
+
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
31
|
+
*/
|
|
32
|
+
declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: string[]): Promise<CreditEventPayload[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the last factorized amount for a given user and pool.
|
|
35
|
+
*
|
|
36
|
+
* @memberof SubgraphService
|
|
37
|
+
* @param {string} userAddress - The address of the user.
|
|
38
|
+
* @param {number} chainId - The ID of the chain.
|
|
39
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
40
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
41
|
+
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
42
|
+
*/
|
|
43
|
+
declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
46
|
+
* @namespace SubgraphService
|
|
47
|
+
*/
|
|
48
|
+
export declare const SubgraphService: {
|
|
49
|
+
getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
|
|
50
|
+
getCreditEventsForUser: typeof getCreditEventsForUser;
|
|
51
|
+
getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
|
|
52
|
+
};
|
|
53
|
+
export {};
|