@huma-finance/sdk 0.0.35 → 0.0.36

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 (115) hide show
  1. package/API.md +822 -822
  2. package/LICENSE +660 -660
  3. package/README.md +37 -37
  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 +143 -143
  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 -106
  29. package/dist/cjs/services/ARWeaveService.js +190 -190
  30. package/dist/cjs/services/EAService.d.ts +20 -20
  31. package/dist/cjs/services/EAService.js +33 -33
  32. package/dist/cjs/services/ReceivableService.d.ts +104 -104
  33. package/dist/cjs/services/ReceivableService.js +308 -308
  34. package/dist/cjs/services/SubgraphService.d.ts +53 -53
  35. package/dist/cjs/services/SubgraphService.js +93 -93
  36. package/dist/cjs/services/index.d.ts +4 -4
  37. package/dist/cjs/services/index.js +7 -7
  38. package/dist/cjs/utils/chain.d.ts +15 -15
  39. package/dist/cjs/utils/chain.js +37 -37
  40. package/dist/cjs/utils/index.d.ts +4 -4
  41. package/dist/cjs/utils/index.js +7 -7
  42. package/dist/cjs/utils/maticGasStation.d.ts +3 -3
  43. package/dist/cjs/utils/maticGasStation.js +38 -38
  44. package/dist/cjs/utils/poolInfo.d.ts +8 -8
  45. package/dist/cjs/utils/poolInfo.js +12 -12
  46. package/dist/cjs/utils/web3.d.ts +5 -5
  47. package/dist/cjs/utils/web3.js +33 -33
  48. package/dist/graphql/generatedTypes.d.ts +40 -40
  49. package/dist/graphql/generatedTypes.js +4 -4
  50. package/dist/graphql/index.d.ts +1 -1
  51. package/dist/graphql/index.js +1 -1
  52. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  53. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
  54. package/dist/helpers/PoolContractHelper.d.ts +119 -119
  55. package/dist/helpers/PoolContractHelper.js +134 -134
  56. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  57. package/dist/helpers/RealWorldReceivableContractHelper.js +17 -17
  58. package/dist/helpers/index.d.ts +3 -3
  59. package/dist/helpers/index.js +3 -3
  60. package/dist/hooks/index.d.ts +4 -4
  61. package/dist/hooks/index.js +4 -4
  62. package/dist/hooks/useContract.d.ts +13 -13
  63. package/dist/hooks/useContract.js +26 -26
  64. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  65. package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
  66. package/dist/hooks/usePoolContract.d.ts +60 -60
  67. package/dist/hooks/usePoolContract.js +48 -48
  68. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -10
  69. package/dist/hooks/useRealWorldReceivableContract.js +15 -15
  70. package/dist/index.d.ts +4 -4
  71. package/dist/index.js +4 -4
  72. package/dist/services/ARWeaveService.d.ts +106 -106
  73. package/dist/services/ARWeaveService.js +185 -185
  74. package/dist/services/EAService.d.ts +20 -20
  75. package/dist/services/EAService.js +30 -30
  76. package/dist/services/ReceivableService.d.ts +104 -104
  77. package/dist/services/ReceivableService.js +305 -305
  78. package/dist/services/SubgraphService.d.ts +53 -53
  79. package/dist/services/SubgraphService.js +90 -90
  80. package/dist/services/index.d.ts +4 -4
  81. package/dist/services/index.js +4 -4
  82. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  83. package/dist/utils/chain.d.ts +15 -15
  84. package/dist/utils/chain.js +31 -31
  85. package/dist/utils/index.d.ts +4 -4
  86. package/dist/utils/index.js +4 -4
  87. package/dist/utils/maticGasStation.d.ts +3 -3
  88. package/dist/utils/maticGasStation.js +33 -33
  89. package/dist/utils/poolInfo.d.ts +8 -8
  90. package/dist/utils/poolInfo.js +8 -8
  91. package/dist/utils/web3.d.ts +5 -5
  92. package/dist/utils/web3.js +27 -27
  93. package/getting-started.md +190 -190
  94. package/package.json +4 -3
  95. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -10
  96. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +0 -22
  97. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
  98. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -10
  99. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +0 -20
  100. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
  101. package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +0 -10
  102. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +0 -17
  103. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +0 -1
  104. package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +0 -10
  105. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +0 -18
  106. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +0 -1
  107. package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +0 -10
  108. package/dist/hooks/useBaseCreditPoolReceivableContract.js +0 -16
  109. package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +0 -1
  110. package/dist/hooks/usePool.d.ts +0 -0
  111. package/dist/hooks/usePool.js +0 -2
  112. package/dist/hooks/usePool.js.map +0 -1
  113. package/dist/hooks/useReceivableFactoringPoolContract.d.ts +0 -10
  114. package/dist/hooks/useReceivableFactoringPoolContract.js +0 -13
  115. package/dist/hooks/useReceivableFactoringPoolContract.js.map +0 -1
@@ -1,53 +1,53 @@
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;
10
- /**
11
- * Represents the payload of a credit event.
12
- * @typedef {Object} CreditEventPayload
13
- */
14
- export type CreditEventPayload = {
15
- amount?: string;
16
- timestamp?: string;
17
- owner?: string;
18
- pool?: string;
19
- event?: string;
20
- };
21
- /**
22
- * Returns the credit events for a given user.
23
- *
24
- * @memberof SubgraphService
25
- * @param {string} userAddress - The address of the user.
26
- * @param {number} chainId - The ID of the chain.
27
- * @param {POOL_NAME} poolName - The name of the pool.
28
- * @param {POOL_TYPE} poolType - The type of the pool.
29
- * @param {number[]} event - The event types to filter by.
30
- * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
31
- */
32
- declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: number[]): Promise<CreditEventPayload[]>;
33
- /**
34
- * Returns the last factorized amount for a given user and pool.
35
- *
36
- * @memberof SubgraphService
37
- * @param {string} userAddress - The address of the user.
38
- * @param {number} chainId - The ID of the chain.
39
- * @param {POOL_NAME} poolName - The name of the pool.
40
- * @param {POOL_TYPE} poolType - The type of the pool.
41
- * @returns {Promise<number>} The last factorized amount for the given user and pool.
42
- */
43
- declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
44
- /**
45
- * An object that contains functions to interact with Huma's Subgraph storage.
46
- * @namespace SubgraphService
47
- */
48
- export declare const SubgraphService: {
49
- getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
50
- getCreditEventsForUser: typeof getCreditEventsForUser;
51
- getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
52
- };
53
- export {};
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;
10
+ /**
11
+ * Represents the payload of a credit event.
12
+ * @typedef {Object} CreditEventPayload
13
+ */
14
+ export type CreditEventPayload = {
15
+ amount?: string;
16
+ timestamp?: string;
17
+ owner?: string;
18
+ pool?: string;
19
+ event?: string;
20
+ };
21
+ /**
22
+ * Returns the credit events for a given user.
23
+ *
24
+ * @memberof SubgraphService
25
+ * @param {string} userAddress - The address of the user.
26
+ * @param {number} chainId - The ID of the chain.
27
+ * @param {POOL_NAME} poolName - The name of the pool.
28
+ * @param {POOL_TYPE} poolType - The type of the pool.
29
+ * @param {number[]} event - The event types to filter by.
30
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
31
+ */
32
+ declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: number[]): Promise<CreditEventPayload[]>;
33
+ /**
34
+ * Returns the last factorized amount for a given user and pool.
35
+ *
36
+ * @memberof SubgraphService
37
+ * @param {string} userAddress - The address of the user.
38
+ * @param {number} chainId - The ID of the chain.
39
+ * @param {POOL_NAME} poolName - The name of the pool.
40
+ * @param {POOL_TYPE} poolType - The type of the pool.
41
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
42
+ */
43
+ declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
44
+ /**
45
+ * An object that contains functions to interact with Huma's Subgraph storage.
46
+ * @namespace SubgraphService
47
+ */
48
+ export declare const SubgraphService: {
49
+ getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
50
+ getCreditEventsForUser: typeof getCreditEventsForUser;
51
+ getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
52
+ };
53
+ export {};
@@ -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