@huma-finance/sdk 0.0.41 → 0.0.42-beta.100
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/dist/cjs/services/ReceivableService.d.ts +17 -1
- package/dist/cjs/services/ReceivableService.js +29 -34
- package/dist/cjs/services/ReceivableService.js.map +1 -1
- package/dist/cjs/services/SubgraphService.d.ts +32 -9
- package/dist/cjs/services/SubgraphService.js +65 -10
- package/dist/cjs/services/SubgraphService.js.map +1 -1
- package/dist/services/ReceivableService.d.ts +17 -1
- package/dist/services/ReceivableService.js +29 -34
- package/dist/services/ReceivableService.js.map +1 -1
- package/dist/services/SubgraphService.d.ts +32 -9
- package/dist/services/SubgraphService.js +66 -11
- package/dist/services/SubgraphService.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TransactionResponse, Web3Provider } from '@ethersproject/providers';
|
|
2
2
|
import { BigNumberish, ethers, Overrides } from 'ethers';
|
|
3
3
|
import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfo } from '@huma-finance/shared';
|
|
4
|
+
import { Pagination } from './SubgraphService';
|
|
4
5
|
/**
|
|
5
6
|
* Fetches the tokenId of a RealWorldReceivable, or null if it doesn't exist, given a metadata URI
|
|
6
7
|
*
|
|
@@ -123,9 +124,23 @@ declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | e
|
|
|
123
124
|
* @param {string} owner - The receivable token owner to query from.
|
|
124
125
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
125
126
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
127
|
+
* @param {Pagination} pagination - The pagination option.
|
|
126
128
|
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
127
129
|
*/
|
|
128
|
-
declare function loadReceivablesOfOwnerWithMetadata<T>(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<RealWorldReceivableInfo<T>[]>;
|
|
130
|
+
declare function loadReceivablesOfOwnerWithMetadata<T>(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE, pagination?: Pagination): Promise<RealWorldReceivableInfo<T>[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the total count of all RWRs belonging to the specified owner
|
|
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} owner - The receivable token owner to query from.
|
|
141
|
+
* @returns {Promise<number>} - Total count of receivables owned by the owner for the pool.
|
|
142
|
+
*/
|
|
143
|
+
declare function getTotalCountOfReceivables(signerOrProvider: Web3Provider | ethers.Signer, owner: string): Promise<number>;
|
|
129
144
|
/**
|
|
130
145
|
* An object that contains functions to interact with Huma's receivables.
|
|
131
146
|
* @namespace ReceivableService
|
|
@@ -136,6 +151,7 @@ export declare const ReceivableService: {
|
|
|
136
151
|
declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
|
|
137
152
|
declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
|
|
138
153
|
loadReceivablesOfOwnerWithMetadata: typeof loadReceivablesOfOwnerWithMetadata;
|
|
154
|
+
getTotalCountOfReceivables: typeof getTotalCountOfReceivables;
|
|
139
155
|
uploadOrFetchMetadataURI: typeof uploadOrFetchMetadataURI;
|
|
140
156
|
getTokenIdByURI: typeof getTokenIdByURI;
|
|
141
157
|
};
|
|
@@ -8,6 +8,7 @@ const graphql_request_1 = require("graphql-request");
|
|
|
8
8
|
const ARWeaveService_1 = require("./ARWeaveService");
|
|
9
9
|
const helpers_1 = require("../helpers");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
|
+
const SubgraphService_1 = require("./SubgraphService");
|
|
11
12
|
/**
|
|
12
13
|
* Fetches the tokenId of a RealWorldReceivable, or null if it doesn't exist, given a metadata URI
|
|
13
14
|
*
|
|
@@ -264,10 +265,10 @@ async function createReceivableWithMetadata(signerOrProvider, privateKey, chainI
|
|
|
264
265
|
* @param {string} owner - The receivable token owner to query from.
|
|
265
266
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
266
267
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
268
|
+
* @param {Pagination} pagination - The pagination option.
|
|
267
269
|
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
268
270
|
*/
|
|
269
|
-
async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType) {
|
|
270
|
-
var _a, _b;
|
|
271
|
+
async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType, pagination) {
|
|
271
272
|
if (!ethers_1.ethers.utils.isAddress(owner)) {
|
|
272
273
|
throw new Error('Invalid owner address');
|
|
273
274
|
}
|
|
@@ -275,44 +276,37 @@ async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolN
|
|
|
275
276
|
if (!chainId) {
|
|
276
277
|
throw new Error('No Chain Id found');
|
|
277
278
|
}
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
279
|
+
const rwReceivablesBase = await SubgraphService_1.SubgraphService.getRWReceivableInfo(owner, chainId, poolName, poolType, pagination);
|
|
280
|
+
const fetchMetadata = async (rwrInfoBase) => ARWeaveService_1.ARWeaveService.fetchMetadataFromUrl(rwrInfoBase.tokenURI);
|
|
281
|
+
const metadatas = await Promise.all(rwReceivablesBase.map(fetchMetadata));
|
|
282
|
+
return rwReceivablesBase.map((rwrInfoBase, index) => (Object.assign(Object.assign({}, rwrInfoBase), { metadata: metadatas[index] })));
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get the total count of all RWRs belonging to the specified owner
|
|
286
|
+
*
|
|
287
|
+
* @async
|
|
288
|
+
* @function
|
|
289
|
+
* @memberof ReceivableService
|
|
290
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
291
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
292
|
+
* from server calls.
|
|
293
|
+
* @param {string} owner - The receivable token owner to query from.
|
|
294
|
+
* @returns {Promise<number>} - Total count of receivables owned by the owner for the pool.
|
|
295
|
+
*/
|
|
296
|
+
async function getTotalCountOfReceivables(signerOrProvider, owner) {
|
|
297
|
+
if (!ethers_1.ethers.utils.isAddress(owner)) {
|
|
298
|
+
throw new Error('Invalid owner address');
|
|
299
|
+
}
|
|
300
|
+
const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signerOrProvider);
|
|
301
|
+
if (!chainId) {
|
|
302
|
+
throw new Error('No Chain Id found');
|
|
283
303
|
}
|
|
284
304
|
const rwrContract = (0, helpers_1.getRealWorldReceivableContract)(signerOrProvider, chainId);
|
|
285
305
|
if (!rwrContract) {
|
|
286
306
|
throw new Error('Could not find RealWorldReceivable contract');
|
|
287
307
|
}
|
|
288
|
-
// Load all receivables of owner
|
|
289
308
|
const balance = await rwrContract.balanceOf(owner);
|
|
290
|
-
|
|
291
|
-
const tokens = Array.from(Array(balance.toNumber()));
|
|
292
|
-
const fetchPromises = tokens.map(async (_, tokenIndex) => {
|
|
293
|
-
const tokenId = await rwrContract.tokenOfOwnerByIndex(owner, tokenIndex);
|
|
294
|
-
const rwrInfo = await rwrContract.rwrInfoMapping(tokenId);
|
|
295
|
-
// If a RWR uploaded by an owner is not for this specific pool, skip it
|
|
296
|
-
if (rwrInfo.poolAddress.toLowerCase() !== poolInfo.pool.toLowerCase()) {
|
|
297
|
-
return undefined;
|
|
298
|
-
}
|
|
299
|
-
const tokenURI = await rwrContract.tokenURI(tokenId);
|
|
300
|
-
const metadata = await ARWeaveService_1.ARWeaveService.fetchMetadataFromUrl(tokenURI);
|
|
301
|
-
return {
|
|
302
|
-
tokenId,
|
|
303
|
-
poolAddress: rwrInfo.poolAddress,
|
|
304
|
-
receivableAmount: rwrInfo.receivableAmount,
|
|
305
|
-
paidAmount: rwrInfo.paidAmount,
|
|
306
|
-
creationDate: rwrInfo.creationDate,
|
|
307
|
-
maturityDate: rwrInfo.maturityDate,
|
|
308
|
-
currencyCode: rwrInfo.currencyCode,
|
|
309
|
-
tokenURI,
|
|
310
|
-
metadata,
|
|
311
|
-
};
|
|
312
|
-
});
|
|
313
|
-
const tokenData = await Promise.all(fetchPromises);
|
|
314
|
-
// Filter undefined
|
|
315
|
-
return tokenData.filter((token) => token !== undefined);
|
|
309
|
+
return balance.toNumber();
|
|
316
310
|
}
|
|
317
311
|
/**
|
|
318
312
|
* An object that contains functions to interact with Huma's receivables.
|
|
@@ -324,6 +318,7 @@ exports.ReceivableService = {
|
|
|
324
318
|
declareReceivablePaymentByTokenId,
|
|
325
319
|
declareReceivablePaymentByReferenceId,
|
|
326
320
|
loadReceivablesOfOwnerWithMetadata,
|
|
321
|
+
getTotalCountOfReceivables,
|
|
327
322
|
uploadOrFetchMetadataURI,
|
|
328
323
|
getTokenIdByURI,
|
|
329
324
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;AAAA,wDAA4E;AAC5E,mCAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;AAAA,wDAA4E;AAC5E,mCAAwD;AACxD,iDAS6B;AAC7B,qDAA8C;AAE9C,qDAAiD;AACjD,wCAA2D;AAC3D,oCAA+E;AAE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AC,aAAa,CAAC,CAAC,CAAA;IAEzE,OAAO,iBAAiB,CAAC,GAAG,CAC1B,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,CACrB,CAAC,gCACI,WAAW,KACd,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,GACI,CAAA,CACnC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,0BAA0B,CACvC,gBAA8C,EAC9C,KAAa;IAEb,IAAI,CAAC,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,gBAAgB,CAAC,CAAA;IACtE,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,MAAM,WAAW,GAAG,IAAA,wCAA8B,EAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;IAC7E,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;KAC/D;IAED,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAClD,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAA;AAC3B,CAAC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG;IAC/B,4BAA4B;IAC5B,gBAAgB;IAChB,iCAAiC;IACjC,qCAAqC;IACrC,kCAAkC;IAClC,0BAA0B;IAC1B,wBAAwB;IACxB,eAAe;CAChB,CAAA"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { POOL_NAME, 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;
|
|
1
|
+
import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfoBase } from '@huma-finance/shared';
|
|
10
2
|
/**
|
|
11
3
|
* Represents the payload of a credit event.
|
|
12
4
|
* @typedef {Object} CreditEventPayload
|
|
@@ -18,6 +10,24 @@ export type CreditEventPayload = {
|
|
|
18
10
|
pool?: string;
|
|
19
11
|
event?: string;
|
|
20
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the pagination options for a query.
|
|
15
|
+
* @typedef {Object} Pagination
|
|
16
|
+
*/
|
|
17
|
+
export type Pagination = {
|
|
18
|
+
first: number | null;
|
|
19
|
+
skip: number | null;
|
|
20
|
+
orderBy: string;
|
|
21
|
+
orderDirection: 'desc' | 'asc';
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Returns the subgraph URL for a given chain ID.
|
|
25
|
+
*
|
|
26
|
+
* @memberof SubgraphService
|
|
27
|
+
* @param {number} chainId - The ID of the chain.
|
|
28
|
+
* @returns {string} The subgraph URL for the given chain ID.
|
|
29
|
+
*/
|
|
30
|
+
declare function getSubgraphUrlForChainId(chainId: number): string;
|
|
21
31
|
/**
|
|
22
32
|
* Returns the credit events for a given user.
|
|
23
33
|
*
|
|
@@ -41,6 +51,18 @@ declare function getCreditEventsForUser(userAddress: string, chainId: number, po
|
|
|
41
51
|
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
42
52
|
*/
|
|
43
53
|
declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the paginated real world receivables' info.
|
|
56
|
+
*
|
|
57
|
+
* @memberof SubgraphService
|
|
58
|
+
* @param {string} userAddress - The address of the user.
|
|
59
|
+
* @param {number} chainId - The ID of the chain.
|
|
60
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
61
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
62
|
+
* @param {Pagination} pagination - The pagination option.
|
|
63
|
+
* @returns {Promise<RealWorldReceivableInfoBase>} The paginated real world receivables' info.
|
|
64
|
+
*/
|
|
65
|
+
declare function getRWReceivableInfo(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, pagination?: Pagination): Promise<RealWorldReceivableInfoBase[]>;
|
|
44
66
|
/**
|
|
45
67
|
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
46
68
|
* @namespace SubgraphService
|
|
@@ -49,5 +71,6 @@ export declare const SubgraphService: {
|
|
|
49
71
|
getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
|
|
50
72
|
getCreditEventsForUser: typeof getCreditEventsForUser;
|
|
51
73
|
getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
|
|
74
|
+
getRWReceivableInfo: typeof getRWReceivableInfo;
|
|
52
75
|
};
|
|
53
76
|
export {};
|
|
@@ -10,16 +10,8 @@ const shared_1 = require("@huma-finance/shared");
|
|
|
10
10
|
* @returns {string} The subgraph URL for the given chain ID.
|
|
11
11
|
*/
|
|
12
12
|
function getSubgraphUrlForChainId(chainId) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
|
|
16
|
-
case 137:
|
|
17
|
-
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-polygon';
|
|
18
|
-
case 80001:
|
|
19
|
-
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-mumbai';
|
|
20
|
-
default:
|
|
21
|
-
return '';
|
|
22
|
-
}
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return (_b = (_a = shared_1.PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.subgraph) !== null && _b !== void 0 ? _b : '';
|
|
23
15
|
}
|
|
24
16
|
/**
|
|
25
17
|
* Returns the credit events for a given user.
|
|
@@ -82,6 +74,68 @@ function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolTyp
|
|
|
82
74
|
shared_1.CreditEvent.DrawdownMadeWithReceivable,
|
|
83
75
|
]).then((events) => Number(events[0].amount));
|
|
84
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the paginated real world receivables' info.
|
|
79
|
+
*
|
|
80
|
+
* @memberof SubgraphService
|
|
81
|
+
* @param {string} userAddress - The address of the user.
|
|
82
|
+
* @param {number} chainId - The ID of the chain.
|
|
83
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
84
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
85
|
+
* @param {Pagination} pagination - The pagination option.
|
|
86
|
+
* @returns {Promise<RealWorldReceivableInfoBase>} The paginated real world receivables' info.
|
|
87
|
+
*/
|
|
88
|
+
function getRWReceivableInfo(userAddress, chainId, poolName, poolType, pagination = {
|
|
89
|
+
first: null,
|
|
90
|
+
skip: null,
|
|
91
|
+
orderBy: 'tokenId',
|
|
92
|
+
orderDirection: 'desc',
|
|
93
|
+
}) {
|
|
94
|
+
var _a, _b, _c, _d;
|
|
95
|
+
const url = (_a = shared_1.PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.receivablesSubgraph;
|
|
96
|
+
if (!url) {
|
|
97
|
+
return Promise.resolve([]);
|
|
98
|
+
}
|
|
99
|
+
const poolAddress = (_d = (_c = (_b = shared_1.PoolContractMap[chainId]) === null || _b === void 0 ? void 0 : _b[poolType]) === null || _c === void 0 ? void 0 : _c[poolName]) === null || _d === void 0 ? void 0 : _d.pool;
|
|
100
|
+
const RWReceivablesQuery = `
|
|
101
|
+
query {
|
|
102
|
+
rwreceivables(
|
|
103
|
+
where: {
|
|
104
|
+
owner: "${userAddress}",
|
|
105
|
+
pool: "${poolAddress}",
|
|
106
|
+
}
|
|
107
|
+
first: ${pagination.first}
|
|
108
|
+
skip: ${pagination.skip}
|
|
109
|
+
orderBy: "${pagination.orderBy}"
|
|
110
|
+
orderDirection: "${pagination.orderDirection}"
|
|
111
|
+
) {
|
|
112
|
+
id
|
|
113
|
+
tokenId
|
|
114
|
+
receivableAmount
|
|
115
|
+
paidAmount
|
|
116
|
+
owner
|
|
117
|
+
pool
|
|
118
|
+
maturityDate
|
|
119
|
+
currencyCode
|
|
120
|
+
tokenUri
|
|
121
|
+
status
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
return (0, shared_1.requestPost)(url, JSON.stringify({ query: RWReceivablesQuery }), {
|
|
126
|
+
withCredentials: false,
|
|
127
|
+
}).then((res) => {
|
|
128
|
+
if (res.errors) {
|
|
129
|
+
console.error(res.errors);
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
return res.data.rwreceivables.map((item) => {
|
|
133
|
+
item.poolAddress = item.pool;
|
|
134
|
+
item.tokenURI = item.tokenUri;
|
|
135
|
+
return item;
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
85
139
|
/**
|
|
86
140
|
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
87
141
|
* @namespace SubgraphService
|
|
@@ -90,5 +144,6 @@ exports.SubgraphService = {
|
|
|
90
144
|
getSubgraphUrlForChainId,
|
|
91
145
|
getCreditEventsForUser,
|
|
92
146
|
getLastFactorizedAmountFromPool,
|
|
147
|
+
getRWReceivableInfo,
|
|
93
148
|
};
|
|
94
149
|
//# sourceMappingURL=SubgraphService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubgraphService.js","sourceRoot":"","sources":["../../../src/services/SubgraphService.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"SubgraphService.js","sourceRoot":"","sources":["../../../src/services/SubgraphService.ts"],"names":[],"mappings":";;;AAAA,iDAQ6B;AAyB7B;;;;;;GAMG;AACH,SAAS,wBAAwB,CAAC,OAAe;;IAC/C,OAAO,MAAA,MAAA,wBAAe,CAAC,OA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I,CAAA;QACb,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACU,QAAA,eAAe,GAAG;IAC7B,wBAAwB;IACxB,sBAAsB;IACtB,+BAA+B;IAC/B,mBAAmB;CACpB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TransactionResponse, Web3Provider } from '@ethersproject/providers';
|
|
2
2
|
import { BigNumberish, ethers, Overrides } from 'ethers';
|
|
3
3
|
import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfo } from '@huma-finance/shared';
|
|
4
|
+
import { Pagination } from './SubgraphService';
|
|
4
5
|
/**
|
|
5
6
|
* Fetches the tokenId of a RealWorldReceivable, or null if it doesn't exist, given a metadata URI
|
|
6
7
|
*
|
|
@@ -123,9 +124,23 @@ declare function createReceivableWithMetadata(signerOrProvider: Web3Provider | e
|
|
|
123
124
|
* @param {string} owner - The receivable token owner to query from.
|
|
124
125
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
125
126
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
127
|
+
* @param {Pagination} pagination - The pagination option.
|
|
126
128
|
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
127
129
|
*/
|
|
128
|
-
declare function loadReceivablesOfOwnerWithMetadata<T>(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<RealWorldReceivableInfo<T>[]>;
|
|
130
|
+
declare function loadReceivablesOfOwnerWithMetadata<T>(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE, pagination?: Pagination): Promise<RealWorldReceivableInfo<T>[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the total count of all RWRs belonging to the specified owner
|
|
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} owner - The receivable token owner to query from.
|
|
141
|
+
* @returns {Promise<number>} - Total count of receivables owned by the owner for the pool.
|
|
142
|
+
*/
|
|
143
|
+
declare function getTotalCountOfReceivables(signerOrProvider: Web3Provider | ethers.Signer, owner: string): Promise<number>;
|
|
129
144
|
/**
|
|
130
145
|
* An object that contains functions to interact with Huma's receivables.
|
|
131
146
|
* @namespace ReceivableService
|
|
@@ -136,6 +151,7 @@ export declare const ReceivableService: {
|
|
|
136
151
|
declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
|
|
137
152
|
declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
|
|
138
153
|
loadReceivablesOfOwnerWithMetadata: typeof loadReceivablesOfOwnerWithMetadata;
|
|
154
|
+
getTotalCountOfReceivables: typeof getTotalCountOfReceivables;
|
|
139
155
|
uploadOrFetchMetadataURI: typeof uploadOrFetchMetadataURI;
|
|
140
156
|
getTokenIdByURI: typeof getTokenIdByURI;
|
|
141
157
|
};
|
|
@@ -5,6 +5,7 @@ import { request, gql } from 'graphql-request';
|
|
|
5
5
|
import { ARWeaveService } from './ARWeaveService';
|
|
6
6
|
import { getRealWorldReceivableContract } from '../helpers';
|
|
7
7
|
import { getDefaultGasOptions, getChainIdFromSignerOrProvider } from '../utils';
|
|
8
|
+
import { SubgraphService } from './SubgraphService';
|
|
8
9
|
/**
|
|
9
10
|
* Fetches the tokenId of a RealWorldReceivable, or null if it doesn't exist, given a metadata URI
|
|
10
11
|
*
|
|
@@ -261,10 +262,10 @@ async function createReceivableWithMetadata(signerOrProvider, privateKey, chainI
|
|
|
261
262
|
* @param {string} owner - The receivable token owner to query from.
|
|
262
263
|
* @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
|
|
263
264
|
* @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
|
|
265
|
+
* @param {Pagination} pagination - The pagination option.
|
|
264
266
|
* @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
|
|
265
267
|
*/
|
|
266
|
-
async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType) {
|
|
267
|
-
var _a, _b;
|
|
268
|
+
async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType, pagination) {
|
|
268
269
|
if (!ethers.utils.isAddress(owner)) {
|
|
269
270
|
throw new Error('Invalid owner address');
|
|
270
271
|
}
|
|
@@ -272,44 +273,37 @@ async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolN
|
|
|
272
273
|
if (!chainId) {
|
|
273
274
|
throw new Error('No Chain Id found');
|
|
274
275
|
}
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
276
|
+
const rwReceivablesBase = await SubgraphService.getRWReceivableInfo(owner, chainId, poolName, poolType, pagination);
|
|
277
|
+
const fetchMetadata = async (rwrInfoBase) => ARWeaveService.fetchMetadataFromUrl(rwrInfoBase.tokenURI);
|
|
278
|
+
const metadatas = await Promise.all(rwReceivablesBase.map(fetchMetadata));
|
|
279
|
+
return rwReceivablesBase.map((rwrInfoBase, index) => (Object.assign(Object.assign({}, rwrInfoBase), { metadata: metadatas[index] })));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Get the total count of all RWRs belonging to the specified owner
|
|
283
|
+
*
|
|
284
|
+
* @async
|
|
285
|
+
* @function
|
|
286
|
+
* @memberof ReceivableService
|
|
287
|
+
* @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
|
|
288
|
+
* If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
|
|
289
|
+
* from server calls.
|
|
290
|
+
* @param {string} owner - The receivable token owner to query from.
|
|
291
|
+
* @returns {Promise<number>} - Total count of receivables owned by the owner for the pool.
|
|
292
|
+
*/
|
|
293
|
+
async function getTotalCountOfReceivables(signerOrProvider, owner) {
|
|
294
|
+
if (!ethers.utils.isAddress(owner)) {
|
|
295
|
+
throw new Error('Invalid owner address');
|
|
296
|
+
}
|
|
297
|
+
const chainId = await getChainIdFromSignerOrProvider(signerOrProvider);
|
|
298
|
+
if (!chainId) {
|
|
299
|
+
throw new Error('No Chain Id found');
|
|
280
300
|
}
|
|
281
301
|
const rwrContract = getRealWorldReceivableContract(signerOrProvider, chainId);
|
|
282
302
|
if (!rwrContract) {
|
|
283
303
|
throw new Error('Could not find RealWorldReceivable contract');
|
|
284
304
|
}
|
|
285
|
-
// Load all receivables of owner
|
|
286
305
|
const balance = await rwrContract.balanceOf(owner);
|
|
287
|
-
|
|
288
|
-
const tokens = Array.from(Array(balance.toNumber()));
|
|
289
|
-
const fetchPromises = tokens.map(async (_, tokenIndex) => {
|
|
290
|
-
const tokenId = await rwrContract.tokenOfOwnerByIndex(owner, tokenIndex);
|
|
291
|
-
const rwrInfo = await rwrContract.rwrInfoMapping(tokenId);
|
|
292
|
-
// If a RWR uploaded by an owner is not for this specific pool, skip it
|
|
293
|
-
if (rwrInfo.poolAddress.toLowerCase() !== poolInfo.pool.toLowerCase()) {
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
const tokenURI = await rwrContract.tokenURI(tokenId);
|
|
297
|
-
const metadata = await ARWeaveService.fetchMetadataFromUrl(tokenURI);
|
|
298
|
-
return {
|
|
299
|
-
tokenId,
|
|
300
|
-
poolAddress: rwrInfo.poolAddress,
|
|
301
|
-
receivableAmount: rwrInfo.receivableAmount,
|
|
302
|
-
paidAmount: rwrInfo.paidAmount,
|
|
303
|
-
creationDate: rwrInfo.creationDate,
|
|
304
|
-
maturityDate: rwrInfo.maturityDate,
|
|
305
|
-
currencyCode: rwrInfo.currencyCode,
|
|
306
|
-
tokenURI,
|
|
307
|
-
metadata,
|
|
308
|
-
};
|
|
309
|
-
});
|
|
310
|
-
const tokenData = await Promise.all(fetchPromises);
|
|
311
|
-
// Filter undefined
|
|
312
|
-
return tokenData.filter((token) => token !== undefined);
|
|
306
|
+
return balance.toNumber();
|
|
313
307
|
}
|
|
314
308
|
/**
|
|
315
309
|
* An object that contains functions to interact with Huma's receivables.
|
|
@@ -321,6 +315,7 @@ export const ReceivableService = {
|
|
|
321
315
|
declareReceivablePaymentByTokenId,
|
|
322
316
|
declareReceivablePaymentByReferenceId,
|
|
323
317
|
loadReceivablesOfOwnerWithMetadata,
|
|
318
|
+
getTotalCountOfReceivables,
|
|
324
319
|
uploadOrFetchMetadataURI,
|
|
325
320
|
getTokenIdByURI,
|
|
326
321
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../src/services/ReceivableService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5E,OAAO,EAAgB,MAAM,EAAa,MAAM,QAAQ,CAAA;AACxD,OAAO,EAGL,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../src/services/ReceivableService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5E,OAAO,EAAgB,MAAM,EAAa,MAAM,QAAQ,CAAA;AACxD,OAAO,EAGL,eAAe,EACf,eAAe,EAGf,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,8BAA8B,EAAE,MAAM,UAAU,C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C,GAAG,CAC1B,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE,CACrB,CAAC,gCACI,WAAW,KACd,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,GACI,CAAA,CACnC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,0BAA0B,CACvC,gBAA8C,EAC9C,KAAa;IAEb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,OAAO,GAAG,MAAM,8BAA8B,CAAC,gBAAgB,CAAC,CAAA;IACtE,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,MAAM,WAAW,GAAG,8BAA8B,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;IAC7E,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;KAC/D;IAED,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAClD,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAA;AAC3B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,4BAA4B;IAC5B,gBAAgB;IAChB,iCAAiC;IACjC,qCAAqC;IACrC,kCAAkC;IAClC,0BAA0B;IAC1B,wBAAwB;IACxB,eAAe;CAChB,CAAA"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { POOL_NAME, 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;
|
|
1
|
+
import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfoBase } from '@huma-finance/shared';
|
|
10
2
|
/**
|
|
11
3
|
* Represents the payload of a credit event.
|
|
12
4
|
* @typedef {Object} CreditEventPayload
|
|
@@ -18,6 +10,24 @@ export type CreditEventPayload = {
|
|
|
18
10
|
pool?: string;
|
|
19
11
|
event?: string;
|
|
20
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Represents the pagination options for a query.
|
|
15
|
+
* @typedef {Object} Pagination
|
|
16
|
+
*/
|
|
17
|
+
export type Pagination = {
|
|
18
|
+
first: number | null;
|
|
19
|
+
skip: number | null;
|
|
20
|
+
orderBy: string;
|
|
21
|
+
orderDirection: 'desc' | 'asc';
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Returns the subgraph URL for a given chain ID.
|
|
25
|
+
*
|
|
26
|
+
* @memberof SubgraphService
|
|
27
|
+
* @param {number} chainId - The ID of the chain.
|
|
28
|
+
* @returns {string} The subgraph URL for the given chain ID.
|
|
29
|
+
*/
|
|
30
|
+
declare function getSubgraphUrlForChainId(chainId: number): string;
|
|
21
31
|
/**
|
|
22
32
|
* Returns the credit events for a given user.
|
|
23
33
|
*
|
|
@@ -41,6 +51,18 @@ declare function getCreditEventsForUser(userAddress: string, chainId: number, po
|
|
|
41
51
|
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
42
52
|
*/
|
|
43
53
|
declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the paginated real world receivables' info.
|
|
56
|
+
*
|
|
57
|
+
* @memberof SubgraphService
|
|
58
|
+
* @param {string} userAddress - The address of the user.
|
|
59
|
+
* @param {number} chainId - The ID of the chain.
|
|
60
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
61
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
62
|
+
* @param {Pagination} pagination - The pagination option.
|
|
63
|
+
* @returns {Promise<RealWorldReceivableInfoBase>} The paginated real world receivables' info.
|
|
64
|
+
*/
|
|
65
|
+
declare function getRWReceivableInfo(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, pagination?: Pagination): Promise<RealWorldReceivableInfoBase[]>;
|
|
44
66
|
/**
|
|
45
67
|
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
46
68
|
* @namespace SubgraphService
|
|
@@ -49,5 +71,6 @@ export declare const SubgraphService: {
|
|
|
49
71
|
getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
|
|
50
72
|
getCreditEventsForUser: typeof getCreditEventsForUser;
|
|
51
73
|
getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
|
|
74
|
+
getRWReceivableInfo: typeof getRWReceivableInfo;
|
|
52
75
|
};
|
|
53
76
|
export {};
|