@huma-finance/sdk 0.0.7 → 0.0.8
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/README.md +23 -7
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +2 -1
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +5 -4
- package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -1
- 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/index.d.ts +2 -0
- package/dist/cjs/helpers/index.js +2 -0
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/hooks/index.d.ts +0 -1
- package/dist/cjs/hooks/index.js +0 -1
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +2 -1
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +5 -4
- package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +1 -1
- package/dist/cjs/hooks/useContract.d.ts +6 -4
- package/dist/cjs/hooks/useContract.js +6 -4
- package/dist/cjs/hooks/useContract.js.map +1 -1
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +5 -5
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +6 -9
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -1
- package/dist/cjs/hooks/usePoolContract.d.ts +11 -4
- package/dist/cjs/hooks/usePoolContract.js +8 -3
- package/dist/cjs/hooks/usePoolContract.js.map +1 -1
- package/dist/cjs/services/ARWeaveService.d.ts +36 -14
- package/dist/cjs/services/ARWeaveService.js +33 -22
- package/dist/cjs/services/ARWeaveService.js.map +1 -1
- package/dist/cjs/services/EAService.d.ts +25 -2
- package/dist/cjs/services/EAService.js +4 -2
- package/dist/cjs/services/EAService.js.map +1 -1
- package/dist/cjs/services/ReceivableService.d.ts +30 -11
- package/dist/cjs/services/ReceivableService.js +40 -24
- package/dist/cjs/services/ReceivableService.js.map +1 -1
- package/dist/cjs/services/SubgraphService.d.ts +18 -4
- package/dist/cjs/services/SubgraphService.js +34 -25
- package/dist/cjs/services/SubgraphService.js.map +1 -1
- package/dist/cjs/utils/poolInfo.d.ts +1 -1
- package/dist/cjs/utils/poolInfo.js +2 -2
- package/dist/cjs/utils/poolInfo.js.map +1 -1
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +2 -1
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +3 -2
- package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -1
- 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/index.d.ts +2 -0
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.js +0 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +2 -1
- package/dist/hooks/useBaseCreditPoolReceivableContract.js +3 -2
- package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +1 -1
- package/dist/hooks/useContract.d.ts +6 -4
- package/dist/hooks/useContract.js +6 -4
- package/dist/hooks/useContract.js.map +1 -1
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +5 -5
- package/dist/hooks/useERC20TransferableReceivableContract.js +5 -8
- package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -1
- package/dist/hooks/usePoolContract.d.ts +11 -4
- package/dist/hooks/usePoolContract.js +8 -3
- package/dist/hooks/usePoolContract.js.map +1 -1
- package/dist/services/ARWeaveService.d.ts +36 -14
- package/dist/services/ARWeaveService.js +33 -19
- package/dist/services/ARWeaveService.js.map +1 -1
- package/dist/services/EAService.d.ts +25 -2
- package/dist/services/EAService.js +3 -1
- package/dist/services/EAService.js.map +1 -1
- package/dist/services/ReceivableService.d.ts +30 -11
- package/dist/services/ReceivableService.js +36 -16
- package/dist/services/ReceivableService.js.map +1 -1
- package/dist/services/SubgraphService.d.ts +18 -4
- package/dist/services/SubgraphService.js +34 -22
- package/dist/services/SubgraphService.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/poolInfo.d.ts +1 -1
- package/dist/utils/poolInfo.js +1 -1
- package/dist/utils/poolInfo.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import Bundlr from '@bundlr-network/client';
|
|
2
2
|
import request, { gql } from 'graphql-request';
|
|
3
3
|
/**
|
|
4
|
-
* Get the configuration for Bundlr network given a chain ID
|
|
4
|
+
* Get the configuration for Bundlr network given a chain ID
|
|
5
5
|
*
|
|
6
6
|
* @function
|
|
7
|
+
* @memberof ArweaveService
|
|
7
8
|
* @param {number} chainId - The chain ID.
|
|
8
9
|
* @returns {BundlrConfig} - The configuration for the Bundlr network.
|
|
9
|
-
* nodeUrl - The node URL of the Bundlr network to use.
|
|
10
|
-
* currency - The currency to pay for uploads with, if lazy funding.
|
|
11
|
-
* providerUrl - The provider URL, required for devnets.
|
|
12
10
|
*/
|
|
13
11
|
export function getBundlrNetworkConfig(chainId) {
|
|
14
12
|
switch (chainId) {
|
|
@@ -32,19 +30,20 @@ export function getBundlrNetworkConfig(chainId) {
|
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
32
|
/**
|
|
35
|
-
* Prefund the Bundlr network with the specified amount.
|
|
33
|
+
* Prefund the Bundlr network with the specified amount. Required if not lazy funding.
|
|
36
34
|
*
|
|
37
35
|
* @async
|
|
38
36
|
* @function
|
|
37
|
+
* @memberof ArweaveService
|
|
39
38
|
* @param {BundlrConfig} config - The configuration for the Bundlr network.
|
|
40
|
-
* @param {any}
|
|
41
|
-
* @param {number} amount - The amount to fund.
|
|
39
|
+
* @param {any} signer - The wallet to send funds from. This can be either a web3 signer or a private key string.
|
|
40
|
+
* @param {number} amount - The amount to fund, denoted in whatever currency specified by the config.
|
|
42
41
|
* @returns {Promise<FundResponse>} - The fund response.
|
|
43
42
|
*/
|
|
44
|
-
|
|
43
|
+
async function prefundBundlr(config,
|
|
45
44
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
-
|
|
47
|
-
const bundlr = new Bundlr(config.nodeUrl, config.currency,
|
|
45
|
+
signer, amount) {
|
|
46
|
+
const bundlr = new Bundlr(config.nodeUrl, config.currency, signer, config.providerUrl
|
|
48
47
|
? {
|
|
49
48
|
providerUrl: config.providerUrl,
|
|
50
49
|
}
|
|
@@ -54,20 +53,22 @@ wallet, amount) {
|
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
55
|
* Store data on ARWeave using the Bundlr Network.
|
|
56
|
+
*
|
|
57
57
|
* @async
|
|
58
58
|
* @function
|
|
59
|
+
* @memberof ArweaveService
|
|
59
60
|
* @param {BundlrConfig} config - Configuration object for the Bundlr instance.
|
|
60
|
-
* @param {Web3Provider |
|
|
61
|
+
* @param {Web3Provider | string} signerOrPrivateKey - Wallet object used for interacting with the Bundlr instance.
|
|
61
62
|
* If calling from a browser, this should be a `Web3Provider` instance. If calling from a Node.js
|
|
62
|
-
* environment, this should be
|
|
63
|
+
* environment, this should be a private key string.
|
|
63
64
|
* @param {JSON} data - The data to store in the Bundlr instance.
|
|
64
65
|
* @param {Array<{ name: string, value: string }>} tags - Array of tag objects with `name` and `value` properties.
|
|
65
66
|
* @param {boolean} [lazyFund=true] - Optional flag to fund the Bundlr instance lazily. If set to `false`, the
|
|
66
67
|
* Bundlr node should already be funded or else uploads will fail.
|
|
67
68
|
* @returns {Promise<UploadResponse>} Promise resolving with the upload response.
|
|
68
69
|
*/
|
|
69
|
-
|
|
70
|
-
const bundlr = new Bundlr(config.nodeUrl, config.currency,
|
|
70
|
+
async function storeData(config, signerOrPrivateKey, data, tags, lazyFund = true) {
|
|
71
|
+
const bundlr = new Bundlr(config.nodeUrl, config.currency, signerOrPrivateKey, config.providerUrl
|
|
71
72
|
? {
|
|
72
73
|
providerUrl: config.providerUrl,
|
|
73
74
|
}
|
|
@@ -86,15 +87,18 @@ export async function storeData(config, wallet, data, tags, lazyFund = true) {
|
|
|
86
87
|
}
|
|
87
88
|
/**
|
|
88
89
|
* Helper method to query the Arweave network for receivables metadata previously uploaded.
|
|
90
|
+
*
|
|
89
91
|
* @async
|
|
90
92
|
* @function
|
|
93
|
+
* @memberof ArweaveService
|
|
94
|
+
* @param {number} chainId - The chain ID.
|
|
91
95
|
* @param {POOL_NAME} poolName - The pool name tag to query.
|
|
92
96
|
* @param {POOL_TYPE} poolType - The pool type tag to query.
|
|
93
97
|
* @param {string} sender - The sender tag to query.
|
|
94
|
-
* @param {string}
|
|
98
|
+
* @param {string} referenceId - The referenceId tag to query, whatever was used when uploading the metadata.
|
|
95
99
|
* @returns {Promise<any>} Promise resolving with the queried data.
|
|
96
100
|
*/
|
|
97
|
-
|
|
101
|
+
async function queryForMetadata(chainId, poolName, poolType, sender, referenceId) {
|
|
98
102
|
var _a, _b, _c, _d;
|
|
99
103
|
const config = getBundlrNetworkConfig(chainId);
|
|
100
104
|
const query = gql `
|
|
@@ -102,7 +106,7 @@ export async function queryForMetadata(chainId, poolName, poolType, sender, inte
|
|
|
102
106
|
$poolName: String!
|
|
103
107
|
$poolType: String!
|
|
104
108
|
$sender: String!
|
|
105
|
-
$
|
|
109
|
+
$referenceId: String!
|
|
106
110
|
) {
|
|
107
111
|
transactions(
|
|
108
112
|
owners: [$sender]
|
|
@@ -110,7 +114,7 @@ export async function queryForMetadata(chainId, poolName, poolType, sender, inte
|
|
|
110
114
|
{ name: "appName", values: ["HumaFinance"] }
|
|
111
115
|
{ name: "poolName", values: [$poolName] }
|
|
112
116
|
{ name: "poolType", values: [$poolType] }
|
|
113
|
-
{ name: "
|
|
117
|
+
{ name: "referenceId", values: [$referenceId] }
|
|
114
118
|
]
|
|
115
119
|
) {
|
|
116
120
|
edges {
|
|
@@ -126,8 +130,18 @@ export async function queryForMetadata(chainId, poolName, poolType, sender, inte
|
|
|
126
130
|
poolName,
|
|
127
131
|
poolType,
|
|
128
132
|
sender,
|
|
129
|
-
|
|
133
|
+
referenceId,
|
|
130
134
|
});
|
|
131
135
|
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;
|
|
132
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* An object that contains functions to interact with Huma-related data stored on ARWeave
|
|
139
|
+
* @namespace ARWeaveService
|
|
140
|
+
*/
|
|
141
|
+
export const ARWeaveService = {
|
|
142
|
+
queryForMetadata,
|
|
143
|
+
storeData,
|
|
144
|
+
prefundBundlr,
|
|
145
|
+
getBundlrNetworkConfig,
|
|
146
|
+
};
|
|
133
147
|
//# sourceMappingURL=ARWeaveService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../src/services/ARWeaveService.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAM3C,OAAO,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"ARWeaveService.js","sourceRoot":"","sources":["../../src/services/ARWeaveService.ts"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AM,CAAC,MAAM,cAAc,GAAG;IAC5B,gBAAgB;IAChB,SAAS;IACT,aAAa;IACb,sBAAsB;CACvB,CAAA"}
|
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Object representing the information returned from a successful evaluation agent approve operation.
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Object} ApproveInfo
|
|
5
|
+
* @memberof EAService
|
|
6
|
+
* @property {number} aprInBps The annual percentage rate in basis points.
|
|
7
|
+
* @property {number|string} creditLimit The credit limit for the borrower in the pool's base currency.
|
|
8
|
+
* @property {number} intervalInDays The interval in days for credit line rebalancing.
|
|
9
|
+
* @property {number|string} receivableAmount The expected payment amount of the receivable asset.
|
|
10
|
+
* @property {string} receivableAsset The address of the receivable asset contract.
|
|
11
|
+
* @property {number|string} receivableParam The identifying parameter for the receivable asset, often the token ID of an ERC721.
|
|
12
|
+
* @property {number} remainingPeriods The number of remaining payback periods in the credit line.
|
|
13
|
+
* @property {number} tokenDecimal The number of decimals for the base token of the pool.
|
|
14
|
+
* @property {string} tokenName The name of the base token of the pool.
|
|
15
|
+
* @property {string} tokenSymbol The symbol of the base token of the pool.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Object representing an invoice payload for underwriting approval.
|
|
19
|
+
*
|
|
20
|
+
* @typedef {Object} EAPayload
|
|
21
|
+
*/
|
|
22
|
+
export type { ApproveInfo, EAPayload } from '@huma-finance/shared';
|
|
2
23
|
/**
|
|
3
24
|
* An object that contains functions to interact with Huma's EAVerse service.
|
|
4
25
|
*
|
|
26
|
+
* @namespace EAService
|
|
27
|
+
*
|
|
5
28
|
* approve: Submits a credit underwriting request to Huma's EAVerse.
|
|
6
29
|
* @param {EAPayload} payload The payload for the underwrite approval.
|
|
7
30
|
* @param {number} chainId The chain ID.
|
|
@@ -9,5 +32,5 @@ export type { ApproveInfo, EAPayload } from '@00labs/huma-shared';
|
|
|
9
32
|
* @throws {EARejectionError} If the underwrite approval is rejected.
|
|
10
33
|
*/
|
|
11
34
|
export declare const EAService: {
|
|
12
|
-
approve: (payload: import("@
|
|
35
|
+
approve: (payload: import("@huma-finance/shared").EAPayload, chainId: number, isDev?: boolean | undefined) => Promise<import("@huma-finance/shared").ApproveInfo>;
|
|
13
36
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { EAService as EAServiceInternal } from '@
|
|
1
|
+
import { EAService as EAServiceInternal } from '@huma-finance/shared';
|
|
2
2
|
/**
|
|
3
3
|
* An object that contains functions to interact with Huma's EAVerse service.
|
|
4
4
|
*
|
|
5
|
+
* @namespace EAService
|
|
6
|
+
*
|
|
5
7
|
* approve: Submits a credit underwriting request to Huma's EAVerse.
|
|
6
8
|
* @param {EAPayload} payload The payload for the underwrite approval.
|
|
7
9
|
* @param {number} chainId The chain ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EAService.js","sourceRoot":"","sources":["../../src/services/EAService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"EAService.js","sourceRoot":"","sources":["../../src/services/EAService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAyBrE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,iBAAiB,CAAC,OAAO;CACnC,CAAA"}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { TransactionReceipt, TransactionResponse, Web3Provider } from '@ethersproject/providers';
|
|
2
|
-
import { BigNumberish, ethers } from 'ethers';
|
|
3
|
-
import { POOL_NAME, POOL_TYPE } from '@
|
|
2
|
+
import { BigNumberish, ethers, Overrides } from 'ethers';
|
|
3
|
+
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
4
4
|
/**
|
|
5
5
|
* Enumeration of payment methods. Maps to the PaymentMethod enum in the BaseCreditPoolReceivable contract.
|
|
6
6
|
* Declarative payment methods are those that do not actually send ERC20 funds. Payable payment methods are those that
|
|
7
7
|
* do by calling makePayment on the BaseCreditPool contract.
|
|
8
|
+
*
|
|
8
9
|
* @enum {number}
|
|
10
|
+
* @memberof ReceivableService
|
|
9
11
|
*/
|
|
10
12
|
export declare enum PaymentMethod {
|
|
11
13
|
Declarative = 0,
|
|
12
14
|
Payable = 1
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
|
-
* Pays a BaseCreditPoolReceivable using the specified payment method, given an
|
|
17
|
+
* Pays a BaseCreditPoolReceivable using the specified payment method, given an referenceId mapping to the receivable's metadata
|
|
16
18
|
*
|
|
19
|
+
* @memberof ReceivableService
|
|
17
20
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
18
21
|
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
19
22
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
@@ -21,10 +24,11 @@ export declare enum PaymentMethod {
|
|
|
21
24
|
* @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
|
|
22
25
|
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
declare function payReceivableByReferenceId(signer: ethers.Signer, referenceId: string, paymentAmount: number, paymentMethod: PaymentMethod): Promise<TransactionReceipt>;
|
|
25
28
|
/**
|
|
26
29
|
* Pays a BaseCreditPoolReceivable using the specified payment method, given a tokenID of the receivable.
|
|
27
30
|
*
|
|
31
|
+
* @memberof ReceivableService
|
|
28
32
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
29
33
|
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
30
34
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
@@ -32,10 +36,11 @@ export declare function payReceivableByInternalId(signer: ethers.Signer, interna
|
|
|
32
36
|
* @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
|
|
33
37
|
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
34
38
|
*/
|
|
35
|
-
|
|
39
|
+
declare function payReceivableByTokenId(signer: ethers.Signer, receivableTokenId: BigNumberish, paymentAmount: number, paymentMethod: PaymentMethod): Promise<TransactionReceipt>;
|
|
36
40
|
/**
|
|
37
41
|
* Mints a new BaseCreditPoolReceivable token on the given chain of the signer
|
|
38
42
|
*
|
|
43
|
+
* @memberof ReceivableService
|
|
39
44
|
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
40
45
|
* @param {string} recipient - The address of the recipient of the receivable token.
|
|
41
46
|
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
@@ -44,17 +49,19 @@ export declare function payReceivableByTokenId(signer: ethers.Signer, receivable
|
|
|
44
49
|
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
45
50
|
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
46
51
|
* @param {string} uri - The URI of the receivable token metadata.
|
|
52
|
+
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
47
53
|
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
48
54
|
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
49
55
|
*/
|
|
50
|
-
|
|
56
|
+
declare function mintReceivable(signer: ethers.Signer, poolName: POOL_NAME, poolType: POOL_TYPE, receivableAmount: number, maturityDate: number, paymentMethod: PaymentMethod, uri: string, gasOpts?: Overrides): Promise<TransactionResponse>;
|
|
51
57
|
/**
|
|
52
58
|
* Mints a BaseCreditPoolReceivable token with metadata uploaded onto ARWeave
|
|
53
59
|
*
|
|
54
|
-
* @
|
|
60
|
+
* @memberof ReceivableService
|
|
61
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
55
62
|
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
56
63
|
* from server calls.
|
|
57
|
-
* @param {string} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
64
|
+
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
58
65
|
* @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
|
|
59
66
|
* @param {string} recipient - The receivable token recipient.
|
|
60
67
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
@@ -63,14 +70,26 @@ export declare function mintReceivable(signer: ethers.Signer, recipient: string,
|
|
|
63
70
|
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
64
71
|
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
65
72
|
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
66
|
-
* @param {number}
|
|
73
|
+
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
67
74
|
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
68
75
|
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
69
76
|
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
70
77
|
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
78
|
+
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
71
79
|
* @returns {Promise<TransactionReceipt>} - The transaction receipt.
|
|
72
80
|
*/
|
|
73
|
-
|
|
81
|
+
declare function mintReceivableWithMetadata(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, receivableAmount: number, maturityDate: number, paymentMethod: PaymentMethod, metadata: JSON, referenceId: string, extraTags: {
|
|
74
82
|
name: string;
|
|
75
83
|
value: string;
|
|
76
|
-
}[], lazyFund?: boolean): Promise<TransactionReceipt>;
|
|
84
|
+
}[], lazyFund?: boolean, gasOpts?: Overrides): Promise<TransactionReceipt>;
|
|
85
|
+
/**
|
|
86
|
+
* An object that contains functions to interact with Huma's receivables.
|
|
87
|
+
* @namespace ReceivableService
|
|
88
|
+
*/
|
|
89
|
+
export declare const ReceivableService: {
|
|
90
|
+
mintReceivableWithMetadata: typeof mintReceivableWithMetadata;
|
|
91
|
+
mintReceivable: typeof mintReceivable;
|
|
92
|
+
payReceivableByTokenId: typeof payReceivableByTokenId;
|
|
93
|
+
payReceivableByReferenceId: typeof payReceivableByReferenceId;
|
|
94
|
+
};
|
|
95
|
+
export {};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Web3Provider, } from '@ethersproject/providers';
|
|
2
|
-
import { BASE_CREDIT_POOL_RECEIVABLE_ABI, PoolContractMap, SupplementaryContracts, SupplementaryContractsMap, } from '@
|
|
2
|
+
import { BASE_CREDIT_POOL_RECEIVABLE_ABI, PoolContractMap, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
|
|
3
3
|
import { getContract } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { ARWeaveService } from './ARWeaveService';
|
|
5
5
|
import { getChainIdFromSignerOrProvider } from '../utils/chain';
|
|
6
6
|
/**
|
|
7
7
|
* Enumeration of payment methods. Maps to the PaymentMethod enum in the BaseCreditPoolReceivable contract.
|
|
8
8
|
* Declarative payment methods are those that do not actually send ERC20 funds. Payable payment methods are those that
|
|
9
9
|
* do by calling makePayment on the BaseCreditPool contract.
|
|
10
|
+
*
|
|
10
11
|
* @enum {number}
|
|
12
|
+
* @memberof ReceivableService
|
|
11
13
|
*/
|
|
12
14
|
export var PaymentMethod;
|
|
13
15
|
(function (PaymentMethod) {
|
|
@@ -15,8 +17,9 @@ export var PaymentMethod;
|
|
|
15
17
|
PaymentMethod[PaymentMethod["Payable"] = 1] = "Payable";
|
|
16
18
|
})(PaymentMethod || (PaymentMethod = {}));
|
|
17
19
|
/**
|
|
18
|
-
* Pays a BaseCreditPoolReceivable using the specified payment method, given an
|
|
20
|
+
* Pays a BaseCreditPoolReceivable using the specified payment method, given an referenceId mapping to the receivable's metadata
|
|
19
21
|
*
|
|
22
|
+
* @memberof ReceivableService
|
|
20
23
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
21
24
|
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
22
25
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
@@ -24,11 +27,11 @@ export var PaymentMethod;
|
|
|
24
27
|
* @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
|
|
25
28
|
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
async function payReceivableByReferenceId(
|
|
28
31
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
32
|
signer,
|
|
30
33
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
31
|
-
|
|
34
|
+
referenceId,
|
|
32
35
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
33
36
|
paymentAmount,
|
|
34
37
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -38,6 +41,7 @@ paymentMethod) {
|
|
|
38
41
|
/**
|
|
39
42
|
* Pays a BaseCreditPoolReceivable using the specified payment method, given a tokenID of the receivable.
|
|
40
43
|
*
|
|
44
|
+
* @memberof ReceivableService
|
|
41
45
|
* @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
|
|
42
46
|
* @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
|
|
43
47
|
* @param {number} paymentAmount - The amount to pay the receivable.
|
|
@@ -45,7 +49,7 @@ paymentMethod) {
|
|
|
45
49
|
* @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
|
|
46
50
|
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
47
51
|
*/
|
|
48
|
-
|
|
52
|
+
async function payReceivableByTokenId(signer, receivableTokenId, paymentAmount, paymentMethod) {
|
|
49
53
|
var _a;
|
|
50
54
|
const chainId = await getChainIdFromSignerOrProvider(signer);
|
|
51
55
|
const baseCreditPoolReceivable = chainId
|
|
@@ -74,6 +78,7 @@ export async function payReceivableByTokenId(signer, receivableTokenId, paymentA
|
|
|
74
78
|
/**
|
|
75
79
|
* Mints a new BaseCreditPoolReceivable token on the given chain of the signer
|
|
76
80
|
*
|
|
81
|
+
* @memberof ReceivableService
|
|
77
82
|
* @param {ethers.Signer} signer - The signer used to send the transaction.
|
|
78
83
|
* @param {string} recipient - The address of the recipient of the receivable token.
|
|
79
84
|
* @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
|
|
@@ -82,10 +87,11 @@ export async function payReceivableByTokenId(signer, receivableTokenId, paymentA
|
|
|
82
87
|
* @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
|
|
83
88
|
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
84
89
|
* @param {string} uri - The URI of the receivable token metadata.
|
|
90
|
+
* @param {Overrides} gasOpts - The gas options to use for the transaction.
|
|
85
91
|
* @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
|
|
86
92
|
* @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
|
|
87
93
|
*/
|
|
88
|
-
|
|
94
|
+
async function mintReceivable(signer, poolName, poolType, receivableAmount, maturityDate, paymentMethod, uri, gasOpts = {}) {
|
|
89
95
|
var _a, _b, _c;
|
|
90
96
|
const chainId = await getChainIdFromSignerOrProvider(signer);
|
|
91
97
|
const baseCreditPoolReceivable = chainId
|
|
@@ -101,15 +107,16 @@ export async function mintReceivable(signer, recipient, poolName, poolType, rece
|
|
|
101
107
|
if (!contract) {
|
|
102
108
|
throw new Error('Could not find BaseCreditPoolReceivable contract');
|
|
103
109
|
}
|
|
104
|
-
return contract.safeMint(
|
|
110
|
+
return contract.safeMint(await signer.getAddress(), poolInfo.pool, poolInfo.poolUnderlyingToken.address, receivableAmount, maturityDate, paymentMethod, uri, gasOpts);
|
|
105
111
|
}
|
|
106
112
|
/**
|
|
107
113
|
* Mints a BaseCreditPoolReceivable token with metadata uploaded onto ARWeave
|
|
108
114
|
*
|
|
109
|
-
* @
|
|
115
|
+
* @memberof ReceivableService
|
|
116
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
110
117
|
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
111
118
|
* from server calls.
|
|
112
|
-
* @param {string} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
119
|
+
* @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
|
|
113
120
|
* @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
|
|
114
121
|
* @param {string} recipient - The receivable token recipient.
|
|
115
122
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
@@ -118,27 +125,30 @@ export async function mintReceivable(signer, recipient, poolName, poolType, rece
|
|
|
118
125
|
* @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
|
|
119
126
|
* @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
|
|
120
127
|
* @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
|
|
121
|
-
* @param {number}
|
|
128
|
+
* @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
|
|
122
129
|
* @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
|
|
123
130
|
* ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
|
|
124
131
|
* @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
|
|
125
132
|
* metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
|
|
133
|
+
* @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
|
|
126
134
|
* @returns {Promise<TransactionReceipt>} - The transaction receipt.
|
|
127
135
|
*/
|
|
128
|
-
|
|
129
|
-
const config = getBundlrNetworkConfig(chainId);
|
|
136
|
+
async function mintReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, receivableAmount, maturityDate, paymentMethod, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
|
|
137
|
+
const config = ARWeaveService.getBundlrNetworkConfig(chainId);
|
|
130
138
|
try {
|
|
131
139
|
const tags = [
|
|
132
140
|
{ name: 'Content-Type', value: 'application/json' },
|
|
133
141
|
{ name: 'appName', value: 'HumaFinance' },
|
|
134
142
|
{ name: 'poolName', value: poolName },
|
|
135
143
|
{ name: 'poolType', value: poolType },
|
|
136
|
-
{ name: '
|
|
144
|
+
{ name: 'referenceId', value: referenceId },
|
|
137
145
|
...extraTags,
|
|
138
146
|
];
|
|
139
|
-
const response = await storeData(config,
|
|
147
|
+
const response = await ARWeaveService.storeData(config, signerOrProvider instanceof Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
|
|
140
148
|
console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
|
|
141
|
-
const tx = await mintReceivable(
|
|
149
|
+
const tx = await mintReceivable(signerOrProvider instanceof Web3Provider
|
|
150
|
+
? signerOrProvider.getSigner()
|
|
151
|
+
: signerOrProvider, poolName, poolType, receivableAmount, maturityDate, paymentMethod, `https://arweave.net/${response.id}`, gasOpts);
|
|
142
152
|
return await tx.wait();
|
|
143
153
|
}
|
|
144
154
|
catch (e) {
|
|
@@ -146,4 +156,14 @@ export async function mintReceivableWithMetadata(wallet, privateKey, chainId, re
|
|
|
146
156
|
throw e;
|
|
147
157
|
}
|
|
148
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* An object that contains functions to interact with Huma's receivables.
|
|
161
|
+
* @namespace ReceivableService
|
|
162
|
+
*/
|
|
163
|
+
export const ReceivableService = {
|
|
164
|
+
mintReceivableWithMetadata,
|
|
165
|
+
mintReceivable,
|
|
166
|
+
payReceivableByTokenId,
|
|
167
|
+
payReceivableByReferenceId,
|
|
168
|
+
};
|
|
149
169
|
//# sourceMappingURL=ReceivableService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../src/services/ReceivableService.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,GACb,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EACL,+BAA+B,EAG/B,eAAe,EACf,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,
|
|
1
|
+
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../src/services/ReceivableService.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,GACb,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EACL,+BAA+B,EAG/B,eAAe,EACf,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAA;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAN,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,+DAAe,CAAA;IACf,uDAAW,CAAA;AACb,CAAC,EAHW,aAAa,KAAb,aAAa,QAGxB;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,0BAA0B;AACvC,6DAA6D;AAC7D,MAAqB;AACrB,6DAA6D;AAC7D,WAAmB;AACnB,6DAA6D;AAC7D,aAAqB;AACrB,6DAA6D;AAC7D,aAA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|
/**
|
|
3
3
|
* Returns the subgraph URL for a given chain ID.
|
|
4
4
|
*
|
|
5
|
+
* @memberof SubgraphService
|
|
5
6
|
* @param {number} chainId - The ID of the chain.
|
|
6
7
|
* @returns {string} The subgraph URL for the given chain ID.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
declare function getSubgraphUrlForChainId(chainId: number): string;
|
|
9
10
|
/**
|
|
10
11
|
* Represents the payload of a credit event.
|
|
12
|
+
* @typedef {Object} CreditEventPayload
|
|
11
13
|
*/
|
|
12
14
|
export type CreditEventPayload = {
|
|
13
15
|
amount?: string;
|
|
@@ -19,6 +21,7 @@ export type CreditEventPayload = {
|
|
|
19
21
|
/**
|
|
20
22
|
* Returns the credit events for a given user.
|
|
21
23
|
*
|
|
24
|
+
* @memberof SubgraphService
|
|
22
25
|
* @param {string} userAddress - The address of the user.
|
|
23
26
|
* @param {number} chainId - The ID of the chain.
|
|
24
27
|
* @param {POOL_NAME} poolName - The name of the pool.
|
|
@@ -26,14 +29,25 @@ export type CreditEventPayload = {
|
|
|
26
29
|
* @param {string[]} event - The event types to filter by.
|
|
27
30
|
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
28
31
|
*/
|
|
29
|
-
|
|
32
|
+
declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: string[]): Promise<CreditEventPayload[]>;
|
|
30
33
|
/**
|
|
31
34
|
* Returns the last factorized amount for a given user and pool.
|
|
32
35
|
*
|
|
36
|
+
* @memberof SubgraphService
|
|
33
37
|
* @param {string} userAddress - The address of the user.
|
|
34
38
|
* @param {number} chainId - The ID of the chain.
|
|
35
39
|
* @param {POOL_NAME} poolName - The name of the pool.
|
|
36
40
|
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
37
41
|
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
38
42
|
*/
|
|
39
|
-
|
|
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 {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { CreditEvent, PoolContractMap, } from '@
|
|
1
|
+
import { CreditEvent, PoolContractMap, } from '@huma-finance/shared';
|
|
2
2
|
/**
|
|
3
3
|
* Returns the subgraph URL for a given chain ID.
|
|
4
4
|
*
|
|
5
|
+
* @memberof SubgraphService
|
|
5
6
|
* @param {number} chainId - The ID of the chain.
|
|
6
7
|
* @returns {string} The subgraph URL for the given chain ID.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
function getSubgraphUrlForChainId(chainId) {
|
|
9
10
|
switch (chainId) {
|
|
10
11
|
case 5:
|
|
11
12
|
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
|
|
@@ -20,6 +21,7 @@ export function getSubgraphUrlForChainId(chainId) {
|
|
|
20
21
|
/**
|
|
21
22
|
* Returns the credit events for a given user.
|
|
22
23
|
*
|
|
24
|
+
* @memberof SubgraphService
|
|
23
25
|
* @param {string} userAddress - The address of the user.
|
|
24
26
|
* @param {number} chainId - The ID of the chain.
|
|
25
27
|
* @param {POOL_NAME} poolName - The name of the pool.
|
|
@@ -27,31 +29,31 @@ export function getSubgraphUrlForChainId(chainId) {
|
|
|
27
29
|
* @param {string[]} event - The event types to filter by.
|
|
28
30
|
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
|
|
31
33
|
var _a, _b, _c;
|
|
32
34
|
const url = getSubgraphUrlForChainId(chainId);
|
|
33
35
|
if (!url) {
|
|
34
36
|
return Promise.resolve([]);
|
|
35
37
|
}
|
|
36
38
|
const poolAddress = (_c = (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.pool;
|
|
37
|
-
const query = `
|
|
38
|
-
query {
|
|
39
|
-
creditEvents(
|
|
40
|
-
where: {
|
|
41
|
-
owner: "${userAddress}",
|
|
42
|
-
pool: "${poolAddress}",
|
|
43
|
-
event_in: "[${event.join('", "')}]"
|
|
44
|
-
}
|
|
45
|
-
orderBy: timestamp
|
|
46
|
-
orderDirection: desc
|
|
47
|
-
) {
|
|
48
|
-
amount
|
|
49
|
-
timestamp
|
|
50
|
-
owner
|
|
51
|
-
pool
|
|
52
|
-
event
|
|
53
|
-
}
|
|
54
|
-
}
|
|
39
|
+
const query = `
|
|
40
|
+
query {
|
|
41
|
+
creditEvents(
|
|
42
|
+
where: {
|
|
43
|
+
owner: "${userAddress}",
|
|
44
|
+
pool: "${poolAddress}",
|
|
45
|
+
event_in: "[${event.join('", "')}]"
|
|
46
|
+
}
|
|
47
|
+
orderBy: timestamp
|
|
48
|
+
orderDirection: desc
|
|
49
|
+
) {
|
|
50
|
+
amount
|
|
51
|
+
timestamp
|
|
52
|
+
owner
|
|
53
|
+
pool
|
|
54
|
+
event
|
|
55
|
+
}
|
|
56
|
+
}
|
|
55
57
|
`;
|
|
56
58
|
return fetch(url, {
|
|
57
59
|
method: 'POST',
|
|
@@ -72,15 +74,25 @@ export function getCreditEventsForUser(userAddress, chainId, poolName, poolType,
|
|
|
72
74
|
/**
|
|
73
75
|
* Returns the last factorized amount for a given user and pool.
|
|
74
76
|
*
|
|
77
|
+
* @memberof SubgraphService
|
|
75
78
|
* @param {string} userAddress - The address of the user.
|
|
76
79
|
* @param {number} chainId - The ID of the chain.
|
|
77
80
|
* @param {POOL_NAME} poolName - The name of the pool.
|
|
78
81
|
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
79
82
|
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
80
83
|
*/
|
|
81
|
-
|
|
84
|
+
function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
|
|
82
85
|
return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
|
|
83
86
|
CreditEvent.DrawdownMadeWithReceivable.toString(),
|
|
84
87
|
]).then((events) => Number(events[0].amount));
|
|
85
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
91
|
+
* @namespace SubgraphService
|
|
92
|
+
*/
|
|
93
|
+
export const SubgraphService = {
|
|
94
|
+
getSubgraphUrlForChainId,
|
|
95
|
+
getCreditEventsForUser,
|
|
96
|
+
getLastFactorizedAmountFromPool,
|
|
97
|
+
};
|
|
86
98
|
//# sourceMappingURL=SubgraphService.js.map
|