@huma-finance/sdk 0.0.42-beta.99 → 0.0.42

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.
@@ -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 {};
@@ -1,4 +1,4 @@
1
- import { CreditEvent, PoolContractMap, requestPost, } from '@huma-finance/shared';
1
+ import { CreditEvent, PoolContractMap, requestPost, PoolSubgraphMap, } from '@huma-finance/shared';
2
2
  /**
3
3
  * Returns the subgraph URL for a given chain ID.
4
4
  *
@@ -7,16 +7,8 @@ import { CreditEvent, PoolContractMap, requestPost, } from '@huma-finance/shared
7
7
  * @returns {string} The subgraph URL for the given chain ID.
8
8
  */
9
9
  function getSubgraphUrlForChainId(chainId) {
10
- switch (chainId) {
11
- case 5:
12
- return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
13
- case 137:
14
- return 'https://api.thegraph.com/subgraphs/name/00labs/huma-polygon';
15
- case 80001:
16
- return 'https://api.thegraph.com/subgraphs/name/00labs/huma-mumbai';
17
- default:
18
- return '';
19
- }
10
+ var _a, _b;
11
+ return (_b = (_a = PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.subgraph) !== null && _b !== void 0 ? _b : '';
20
12
  }
21
13
  /**
22
14
  * Returns the credit events for a given user.
@@ -79,6 +71,68 @@ function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolTyp
79
71
  CreditEvent.DrawdownMadeWithReceivable,
80
72
  ]).then((events) => Number(events[0].amount));
81
73
  }
74
+ /**
75
+ * Returns the paginated real world receivables' info.
76
+ *
77
+ * @memberof SubgraphService
78
+ * @param {string} userAddress - The address of the user.
79
+ * @param {number} chainId - The ID of the chain.
80
+ * @param {POOL_NAME} poolName - The name of the pool.
81
+ * @param {POOL_TYPE} poolType - The type of the pool.
82
+ * @param {Pagination} pagination - The pagination option.
83
+ * @returns {Promise<RealWorldReceivableInfoBase>} The paginated real world receivables' info.
84
+ */
85
+ function getRWReceivableInfo(userAddress, chainId, poolName, poolType, pagination = {
86
+ first: null,
87
+ skip: null,
88
+ orderBy: 'tokenId',
89
+ orderDirection: 'desc',
90
+ }) {
91
+ var _a, _b, _c, _d;
92
+ const url = (_a = PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.receivablesSubgraph;
93
+ if (!url) {
94
+ return Promise.resolve([]);
95
+ }
96
+ const poolAddress = (_d = (_c = (_b = 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;
97
+ const RWReceivablesQuery = `
98
+ query {
99
+ rwreceivables(
100
+ where: {
101
+ owner: "${userAddress}",
102
+ pool: "${poolAddress}",
103
+ }
104
+ first: ${pagination.first}
105
+ skip: ${pagination.skip}
106
+ orderBy: "${pagination.orderBy}"
107
+ orderDirection: "${pagination.orderDirection}"
108
+ ) {
109
+ id
110
+ tokenId
111
+ receivableAmount
112
+ paidAmount
113
+ owner
114
+ pool
115
+ maturityDate
116
+ currencyCode
117
+ tokenUri
118
+ status
119
+ }
120
+ }
121
+ `;
122
+ return requestPost(url, JSON.stringify({ query: RWReceivablesQuery }), {
123
+ withCredentials: false,
124
+ }).then((res) => {
125
+ if (res.errors) {
126
+ console.error(res.errors);
127
+ return [];
128
+ }
129
+ return res.data.rwreceivables.map((item) => {
130
+ item.poolAddress = item.pool;
131
+ item.tokenURI = item.tokenUri;
132
+ return item;
133
+ });
134
+ });
135
+ }
82
136
  /**
83
137
  * An object that contains functions to interact with Huma's Subgraph storage.
84
138
  * @namespace SubgraphService
@@ -87,5 +141,6 @@ export const SubgraphService = {
87
141
  getSubgraphUrlForChainId,
88
142
  getCreditEventsForUser,
89
143
  getLastFactorizedAmountFromPool,
144
+ getRWReceivableInfo,
90
145
  };
91
146
  //# sourceMappingURL=SubgraphService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SubgraphService.js","sourceRoot":"","sources":["../../src/services/SubgraphService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EAGf,WAAW,GACZ,MAAM,sBAAsB,CAAA;AAE7B;;;;;;GAMG;AACH,SAAS,wBAAwB,CAAC,OAAe;IAC/C,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC;YACJ,OAAO,4DAA4D,CAAA;QACrE,KAAK,GAAG;YACN,OAAO,6DAA6D,CAAA;QACtE,KAAK,KAAK;YACR,OAAO,4DAA4D,CAAA;QACrE;YACE,OAAO,EAAE,CAAA;KACZ;AACH,CAAC;AAcD;;;;;;;;;;GAUG;AACH,SAAS,sBAAsB,CAC7B,WAAmB,EACnB,OAAe,EACf,QAAmB,EACnB,QAAmB,EACnB,KAAe;;IAEf,MAAM,GAAG,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IAC7C,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;KAC3B;IAED,MAAM,WAAW,GAAG,MAAA,MAAA,MAAA,eAAe,CAAC,OAAO,CAAC,0CAAG,QAAQ,CAAC,0CAAG,QAAQ,CAAC,0CAAE,IAAI,CAAA;IAE1E,MAAM,KAAK,GAAG;;;;oBAII,WAAW;mBACZ,WAAW;uBACP,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC;;;;;;;;;;;;GAYnC,CAAA;IAED,8DAA8D;IAC9D,OAAO,WAAW,CAAC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