@huma-finance/sdk 0.0.30 → 0.0.31

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.
Files changed (119) hide show
  1. package/API.md +977 -608
  2. package/LICENSE +660 -660
  3. package/README.md +34 -34
  4. package/dist/cjs/graphql/generatedTypes.d.ts +40 -40
  5. package/dist/cjs/graphql/generatedTypes.js +8 -8
  6. package/dist/cjs/graphql/index.d.ts +1 -1
  7. package/dist/cjs/graphql/index.js +4 -4
  8. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  9. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +21 -21
  10. package/dist/cjs/helpers/PoolContractHelper.d.ts +119 -119
  11. package/dist/cjs/helpers/PoolContractHelper.js +142 -142
  12. package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  13. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +21 -21
  14. package/dist/cjs/helpers/index.d.ts +3 -3
  15. package/dist/cjs/helpers/index.js +6 -6
  16. package/dist/cjs/hooks/index.d.ts +4 -4
  17. package/dist/cjs/hooks/index.js +7 -7
  18. package/dist/cjs/hooks/useContract.d.ts +13 -13
  19. package/dist/cjs/hooks/useContract.js +30 -30
  20. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  21. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +20 -20
  22. package/dist/cjs/hooks/usePoolContract.d.ts +60 -60
  23. package/dist/cjs/hooks/usePoolContract.js +53 -53
  24. package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -10
  25. package/dist/cjs/hooks/useRealWorldReceivableContract.js +19 -19
  26. package/dist/cjs/index.d.ts +4 -4
  27. package/dist/cjs/index.js +7 -7
  28. package/dist/cjs/services/ARWeaveService.d.ts +106 -95
  29. package/dist/cjs/services/ARWeaveService.js +190 -169
  30. package/dist/cjs/services/ARWeaveService.js.map +1 -1
  31. package/dist/cjs/services/EAService.d.ts +20 -20
  32. package/dist/cjs/services/EAService.js +33 -33
  33. package/dist/cjs/services/ReceivableService.d.ts +105 -89
  34. package/dist/cjs/services/ReceivableService.js +253 -193
  35. package/dist/cjs/services/ReceivableService.js.map +1 -1
  36. package/dist/cjs/services/SubgraphService.d.ts +53 -53
  37. package/dist/cjs/services/SubgraphService.js +93 -93
  38. package/dist/cjs/services/index.d.ts +4 -4
  39. package/dist/cjs/services/index.js +7 -7
  40. package/dist/cjs/utils/chain.d.ts +15 -15
  41. package/dist/cjs/utils/chain.js +37 -37
  42. package/dist/cjs/utils/index.d.ts +4 -4
  43. package/dist/cjs/utils/index.js +7 -7
  44. package/dist/cjs/utils/maticGasStation.d.ts +3 -3
  45. package/dist/cjs/utils/maticGasStation.js +38 -38
  46. package/dist/cjs/utils/poolInfo.d.ts +8 -8
  47. package/dist/cjs/utils/poolInfo.js +12 -12
  48. package/dist/cjs/utils/web3.d.ts +5 -5
  49. package/dist/cjs/utils/web3.js +33 -33
  50. package/dist/graphql/generatedTypes.d.ts +40 -40
  51. package/dist/graphql/generatedTypes.js +4 -4
  52. package/dist/graphql/index.d.ts +1 -1
  53. package/dist/graphql/index.js +1 -1
  54. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  55. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
  56. package/dist/helpers/PoolContractHelper.d.ts +119 -119
  57. package/dist/helpers/PoolContractHelper.js +133 -133
  58. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  59. package/dist/helpers/RealWorldReceivableContractHelper.js +17 -17
  60. package/dist/helpers/index.d.ts +3 -3
  61. package/dist/helpers/index.js +3 -3
  62. package/dist/hooks/index.d.ts +4 -4
  63. package/dist/hooks/index.js +4 -4
  64. package/dist/hooks/useContract.d.ts +13 -13
  65. package/dist/hooks/useContract.js +26 -26
  66. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  67. package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
  68. package/dist/hooks/usePoolContract.d.ts +60 -60
  69. package/dist/hooks/usePoolContract.js +48 -48
  70. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -10
  71. package/dist/hooks/useRealWorldReceivableContract.js +15 -15
  72. package/dist/index.d.ts +4 -4
  73. package/dist/index.js +4 -4
  74. package/dist/services/ARWeaveService.d.ts +106 -95
  75. package/dist/services/ARWeaveService.js +185 -164
  76. package/dist/services/ARWeaveService.js.map +1 -1
  77. package/dist/services/EAService.d.ts +20 -20
  78. package/dist/services/EAService.js +30 -30
  79. package/dist/services/ReceivableService.d.ts +105 -89
  80. package/dist/services/ReceivableService.js +249 -189
  81. package/dist/services/ReceivableService.js.map +1 -1
  82. package/dist/services/SubgraphService.d.ts +53 -53
  83. package/dist/services/SubgraphService.js +90 -90
  84. package/dist/services/index.d.ts +4 -4
  85. package/dist/services/index.js +4 -4
  86. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  87. package/dist/utils/chain.d.ts +15 -15
  88. package/dist/utils/chain.js +31 -31
  89. package/dist/utils/index.d.ts +4 -4
  90. package/dist/utils/index.js +4 -4
  91. package/dist/utils/maticGasStation.d.ts +3 -3
  92. package/dist/utils/maticGasStation.js +33 -33
  93. package/dist/utils/poolInfo.d.ts +8 -8
  94. package/dist/utils/poolInfo.js +8 -8
  95. package/dist/utils/web3.d.ts +5 -5
  96. package/dist/utils/web3.js +27 -27
  97. package/getting-started.md +190 -190
  98. package/package.json +3 -3
  99. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -10
  100. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +0 -22
  101. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
  102. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -10
  103. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +0 -20
  104. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
  105. package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +0 -10
  106. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +0 -17
  107. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +0 -1
  108. package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -10
  109. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +0 -18
  110. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
  111. package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -10
  112. package/dist/hooks/useBaseCreditPoolReceivableContract.js +0 -16
  113. package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
  114. package/dist/hooks/usePool.d.ts +0 -0
  115. package/dist/hooks/usePool.js +0 -2
  116. package/dist/hooks/usePool.js.map +0 -1
  117. package/dist/hooks/useReceivableFactoringPoolContract.d.ts +0 -10
  118. package/dist/hooks/useReceivableFactoringPoolContract.js +0 -13
  119. package/dist/hooks/useReceivableFactoringPoolContract.js.map +0 -1
@@ -1,91 +1,91 @@
1
- import { CreditEvent, PoolContractMap, requestPost, } 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
- 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
- }
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 {number[]} event - The event types to filter by.
30
- * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
31
- */
32
- function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
33
- var _a, _b, _c;
34
- const url = getSubgraphUrlForChainId(chainId);
35
- if (!url) {
36
- return Promise.resolve([]);
37
- }
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;
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
- }
57
- `;
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- return requestPost(url, JSON.stringify({ query })).then((res) => {
60
- if (res.errors) {
61
- console.error(res.errors);
62
- return [];
63
- }
64
- return res.data.creditEvents;
65
- });
66
- }
67
- /**
68
- * Returns the last factorized amount for a given user and pool.
69
- *
70
- * @memberof SubgraphService
71
- * @param {string} userAddress - The address of the user.
72
- * @param {number} chainId - The ID of the chain.
73
- * @param {POOL_NAME} poolName - The name of the pool.
74
- * @param {POOL_TYPE} poolType - The type of the pool.
75
- * @returns {Promise<number>} The last factorized amount for the given user and pool.
76
- */
77
- function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
78
- return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
79
- CreditEvent.DrawdownMadeWithReceivable,
80
- ]).then((events) => Number(events[0].amount));
81
- }
82
- /**
83
- * An object that contains functions to interact with Huma's Subgraph storage.
84
- * @namespace SubgraphService
85
- */
86
- export const SubgraphService = {
87
- getSubgraphUrlForChainId,
88
- getCreditEventsForUser,
89
- getLastFactorizedAmountFromPool,
90
- };
1
+ import { CreditEvent, PoolContractMap, requestPost, } 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
+ 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
+ }
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 {number[]} event - The event types to filter by.
30
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
31
+ */
32
+ function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
33
+ var _a, _b, _c;
34
+ const url = getSubgraphUrlForChainId(chainId);
35
+ if (!url) {
36
+ return Promise.resolve([]);
37
+ }
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;
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
+ }
57
+ `;
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ return requestPost(url, JSON.stringify({ query })).then((res) => {
60
+ if (res.errors) {
61
+ console.error(res.errors);
62
+ return [];
63
+ }
64
+ return res.data.creditEvents;
65
+ });
66
+ }
67
+ /**
68
+ * Returns the last factorized amount for a given user and pool.
69
+ *
70
+ * @memberof SubgraphService
71
+ * @param {string} userAddress - The address of the user.
72
+ * @param {number} chainId - The ID of the chain.
73
+ * @param {POOL_NAME} poolName - The name of the pool.
74
+ * @param {POOL_TYPE} poolType - The type of the pool.
75
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
76
+ */
77
+ function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
78
+ return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
79
+ CreditEvent.DrawdownMadeWithReceivable,
80
+ ]).then((events) => Number(events[0].amount));
81
+ }
82
+ /**
83
+ * An object that contains functions to interact with Huma's Subgraph storage.
84
+ * @namespace SubgraphService
85
+ */
86
+ export const SubgraphService = {
87
+ getSubgraphUrlForChainId,
88
+ getCreditEventsForUser,
89
+ getLastFactorizedAmountFromPool,
90
+ };
91
91
  //# sourceMappingURL=SubgraphService.js.map
@@ -1,4 +1,4 @@
1
- export * from './ARWeaveService';
2
- export * from './EAService';
3
- export * from './SubgraphService';
4
- export * from './ReceivableService';
1
+ export * from './ARWeaveService';
2
+ export * from './EAService';
3
+ export * from './SubgraphService';
4
+ export * from './ReceivableService';
@@ -1,5 +1,5 @@
1
- export * from './ARWeaveService';
2
- export * from './EAService';
3
- export * from './SubgraphService';
4
- export * from './ReceivableService';
1
+ export * from './ARWeaveService';
2
+ export * from './EAService';
3
+ export * from './SubgraphService';
4
+ export * from './ReceivableService';
5
5
  //# sourceMappingURL=index.js.map