@huma-finance/sdk 0.0.29 → 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 -482
  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 -81
  29. package/dist/cjs/services/ARWeaveService.js +190 -145
  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 -81
  75. package/dist/services/ARWeaveService.js +185 -140
  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 +6 -4
  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,194 +1,254 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReceivableService = void 0;
4
- const tslib_1 = require("tslib");
5
- const providers_1 = require("@ethersproject/providers");
6
- const shared_1 = require("@huma-finance/shared");
7
- const graphql_request_1 = tslib_1.__importStar(require("graphql-request"));
8
- const ARWeaveService_1 = require("./ARWeaveService");
9
- const helpers_1 = require("../helpers");
10
- const utils_1 = require("../utils");
11
- /**
12
- * Declares a payment on a RealWorldReceivable given a reference ID of the receivable, which was used as an index for ARWeave data.
13
- *
14
- * @async
15
- * @function
16
- * @memberof ReceivableService
17
- * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
18
- * @param {string} referenceId - An internal identifier value added as a tag on ARWeave
19
- * @param {number} paymentAmount - The amount to declare paid to the receivable.
20
- * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
21
- * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
22
- */
23
- async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount, gasOpts = {}) {
24
- var _a, _b, _c;
25
- const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
26
- const signerAddress = await signer.getAddress();
27
- if (!chainId) {
28
- throw new Error('No Chain ID found');
29
- }
30
- // Get ARWeave ID
31
- const dataID = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
32
- // Fetch receivables with the same ARWeave ID
33
- const receivablesQuery = (0, graphql_request_1.gql) `
34
- query ReceivablesByURIQuery($owner: String!, $uri: String!) {
35
- receivables(where: { owner: $owner, uri: $uri }) {
36
- ...ReceivableFields
37
- }
38
- }
39
-
40
- fragment ReceivableFields on Receivable {
41
- tokenId
42
- }
43
- `;
44
- let receivableSubgraph;
45
- switch (chainId) {
46
- case shared_1.ChainEnum.Goerli:
47
- receivableSubgraph = `https://api.thegraph.com/subgraphs/name/00labs/huma-receivables-goerli`;
48
- break;
49
- default:
50
- throw new Error('No receivable subgraph exists for this chain');
51
- }
52
- const receivablesData = await (0, graphql_request_1.default)(receivableSubgraph, receivablesQuery, {
53
- owner: signerAddress,
54
- uri: `https://arweave.net/${dataID}`,
55
- });
56
- if (!(receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) || !((_a = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _a === void 0 ? void 0 : _a.length)) {
57
- throw new Error('No receivables found with this ARWeave ID.');
58
- }
59
- else if (((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length) > 1) {
60
- throw new Error(`This owner has multiple receivables with the same URI. Please burn
61
- unnecessary receivables or pay the correct token manually using declareReceivablePaymentByTokenId`);
62
- }
63
- const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
64
- if (!contract) {
65
- throw new Error('Could not find RealWorldReceivable contract');
66
- }
67
- gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
68
- return contract.declarePayment((_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _c === void 0 ? void 0 : _c.tokenId, paymentAmount, gasOpts);
69
- }
70
- /**
71
- * Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
72
- *
73
- * @async
74
- * @function
75
- * @memberof ReceivableService
76
- * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
77
- * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
78
- * @param {number} paymentAmount - The amount to pay the receivable.
79
- * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
80
- * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
81
- * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
82
- */
83
- async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount, gasOpts = {}) {
84
- var _a;
85
- const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
86
- if (!chainId) {
87
- throw new Error('No Chain ID found');
88
- }
89
- const realWorldReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable];
90
- if (!realWorldReceivable) {
91
- throw new Error('RealWorldReceivable is not available on this network');
92
- }
93
- const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
94
- if (!contract) {
95
- throw new Error('Could not find RealWorldReceivable contract');
96
- }
97
- gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
98
- return contract.declarePayment(receivableTokenId, paymentAmount, gasOpts);
99
- }
100
- /**
101
- * Creates a new RealWorldReceivable token on the given chain of the signer
102
- *
103
- * @async
104
- * @function
105
- * @memberof ReceivableService
106
- * @param {ethers.Signer} signer - The signer used to send the transaction.
107
- * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
108
- * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
109
- * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
110
- * @param {number} receivableAmount - The amount of the receivable token to mint.
111
- * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
112
- * @param {string} uri - The URI of the receivable token metadata.
113
- * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
114
- * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
115
- * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
116
- */
117
- async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
118
- var _a, _b;
119
- const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
120
- if (!chainId) {
121
- throw new Error('No Chain ID found');
122
- }
123
- const poolInfo = chainId
124
- ? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
125
- : undefined;
126
- if (!poolInfo) {
127
- throw new Error('RealWorldReceivable is not available on this network');
128
- }
129
- const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
130
- if (!contract) {
131
- throw new Error('Could not find RealWorldReceivable contract');
132
- }
133
- gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
134
- return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
135
- }
136
- /**
137
- * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
138
- *
139
- * @async
140
- * @function
141
- * @memberof ReceivableService
142
- * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
143
- * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
144
- * from server calls.
145
- * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
146
- * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
147
- * @param {string} recipient - The receivable token recipient.
148
- * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
149
- * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
150
- * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
151
- * @param {number} receivableAmount - The receivable amount.
152
- * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
153
- * @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
154
- * @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
155
- * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
156
- * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
157
- * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
158
- * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
159
- * @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
160
- * @returns {Promise<TransactionResponse>} - The transaction receipt.
161
- */
162
- async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
163
- const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
164
- try {
165
- const tags = [
166
- { name: 'Content-Type', value: 'application/json' },
167
- { name: 'appName', value: 'HumaFinance' },
168
- { name: 'poolName', value: poolName },
169
- { name: 'poolType', value: poolType },
170
- { name: 'referenceId', value: referenceId },
171
- ...extraTags,
172
- ];
173
- const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
174
- console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
175
- return await createReceivable(signerOrProvider instanceof providers_1.Web3Provider
176
- ? signerOrProvider.getSigner()
177
- : signerOrProvider, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${response.id}`, gasOpts);
178
- }
179
- catch (e) {
180
- console.error(e);
181
- throw e;
182
- }
183
- }
184
- /**
185
- * An object that contains functions to interact with Huma's receivables.
186
- * @namespace ReceivableService
187
- */
188
- exports.ReceivableService = {
189
- createReceivableWithMetadata,
190
- createReceivable,
191
- declareReceivablePaymentByTokenId,
192
- declareReceivablePaymentByReferenceId,
193
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReceivableService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const providers_1 = require("@ethersproject/providers");
6
+ const ethers_1 = require("ethers");
7
+ const shared_1 = require("@huma-finance/shared");
8
+ const graphql_request_1 = tslib_1.__importStar(require("graphql-request"));
9
+ const ARWeaveService_1 = require("./ARWeaveService");
10
+ const helpers_1 = require("../helpers");
11
+ const utils_1 = require("../utils");
12
+ /**
13
+ * Declares a payment on a RealWorldReceivable given a reference ID of the receivable, which was used as an index for ARWeave data.
14
+ *
15
+ * @async
16
+ * @function
17
+ * @memberof ReceivableService
18
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
19
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave
20
+ * @param {number} paymentAmount - The amount to declare paid to the receivable.
21
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
22
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
23
+ */
24
+ async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount, gasOpts = {}) {
25
+ var _a, _b, _c;
26
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
27
+ const signerAddress = await signer.getAddress();
28
+ if (!chainId) {
29
+ throw new Error('No Chain ID found');
30
+ }
31
+ // Get ARWeave ID
32
+ const dataID = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
33
+ // Fetch receivables with the same ARWeave ID
34
+ const receivablesQuery = (0, graphql_request_1.gql) `
35
+ query ReceivablesByURIQuery($owner: String!, $uri: String!) {
36
+ receivables(where: { owner: $owner, uri: $uri }) {
37
+ ...ReceivableFields
38
+ }
39
+ }
40
+
41
+ fragment ReceivableFields on Receivable {
42
+ tokenId
43
+ }
44
+ `;
45
+ const receivableSubgraph = shared_1.PoolSubgraphMap[chainId].receivablesSubgraph;
46
+ if (!receivableSubgraph) {
47
+ throw new Error('No receivable subgraph exists for this chain');
48
+ }
49
+ const receivablesData = await (0, graphql_request_1.default)(receivableSubgraph, receivablesQuery, {
50
+ owner: signerAddress,
51
+ uri: `https://arweave.net/${dataID}`,
52
+ });
53
+ if (!(receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) || !((_a = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _a === void 0 ? void 0 : _a.length)) {
54
+ throw new Error('No receivables found with this ARWeave ID.');
55
+ }
56
+ else if (((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length) > 1) {
57
+ throw new Error(`This owner has multiple receivables with the same URI. Please burn
58
+ unnecessary receivables or pay the correct token manually using declareReceivablePaymentByTokenId`);
59
+ }
60
+ const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
61
+ if (!contract) {
62
+ throw new Error('Could not find RealWorldReceivable contract');
63
+ }
64
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
65
+ return contract.declarePayment((_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _c === void 0 ? void 0 : _c.tokenId, paymentAmount, gasOpts);
66
+ }
67
+ /**
68
+ * Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
69
+ *
70
+ * @async
71
+ * @function
72
+ * @memberof ReceivableService
73
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
74
+ * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
75
+ * @param {number} paymentAmount - The amount to pay the receivable.
76
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
77
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
78
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
79
+ */
80
+ async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount, gasOpts = {}) {
81
+ var _a;
82
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
83
+ if (!chainId) {
84
+ throw new Error('No Chain ID found');
85
+ }
86
+ const realWorldReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable];
87
+ if (!realWorldReceivable) {
88
+ throw new Error('RealWorldReceivable is not available on this network');
89
+ }
90
+ const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
91
+ if (!contract) {
92
+ throw new Error('Could not find RealWorldReceivable contract');
93
+ }
94
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
95
+ return contract.declarePayment(receivableTokenId, paymentAmount, gasOpts);
96
+ }
97
+ /**
98
+ * Creates a new RealWorldReceivable token on the given chain of the signer
99
+ *
100
+ * @async
101
+ * @function
102
+ * @memberof ReceivableService
103
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
104
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
105
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
106
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
107
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
108
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
109
+ * @param {string} uri - The URI of the receivable token metadata.
110
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
111
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
112
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
113
+ */
114
+ async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
115
+ var _a, _b;
116
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
117
+ if (!chainId) {
118
+ throw new Error('No Chain ID found');
119
+ }
120
+ const poolInfo = chainId
121
+ ? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
122
+ : undefined;
123
+ if (!poolInfo) {
124
+ throw new Error('RealWorldReceivable is not available on this network');
125
+ }
126
+ const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
127
+ if (!contract) {
128
+ throw new Error('Could not find RealWorldReceivable contract');
129
+ }
130
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
131
+ return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
132
+ }
133
+ /**
134
+ * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
135
+ *
136
+ * @async
137
+ * @function
138
+ * @memberof ReceivableService
139
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
140
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
141
+ * from server calls.
142
+ * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
143
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
144
+ * @param {string} recipient - The receivable token recipient.
145
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
146
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
147
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
148
+ * @param {number} receivableAmount - The receivable amount.
149
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
150
+ * @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
151
+ * @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
152
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
153
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
154
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
155
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
156
+ * @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
157
+ * @returns {Promise<TransactionResponse>} - The transaction receipt.
158
+ */
159
+ async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
160
+ const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
161
+ try {
162
+ const tags = [
163
+ { name: 'Content-Type', value: 'application/json' },
164
+ { name: 'appName', value: 'HumaFinance' },
165
+ { name: 'poolName', value: poolName },
166
+ { name: 'poolType', value: poolType },
167
+ { name: 'referenceId', value: referenceId },
168
+ ...extraTags,
169
+ ];
170
+ const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
171
+ console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
172
+ return await createReceivable(signerOrProvider instanceof providers_1.Web3Provider
173
+ ? signerOrProvider.getSigner()
174
+ : signerOrProvider, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${response.id}`, gasOpts);
175
+ }
176
+ catch (e) {
177
+ console.error(e);
178
+ throw e;
179
+ }
180
+ }
181
+ /**
182
+ * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
183
+ *
184
+ * @async
185
+ * @function
186
+ * @memberof ReceivableService
187
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
188
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
189
+ * from server calls.
190
+ * @param {string} owner - The receivable token owner to query from.
191
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
192
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
193
+ * @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
194
+ */
195
+ async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType) {
196
+ var _a, _b;
197
+ if (!ethers_1.ethers.utils.isAddress(owner)) {
198
+ throw new Error('Invalid owner address');
199
+ }
200
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signerOrProvider);
201
+ if (!chainId) {
202
+ throw new Error('No Chain ID found');
203
+ }
204
+ const poolInfo = chainId
205
+ ? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
206
+ : undefined;
207
+ if (!poolInfo) {
208
+ throw new Error('RealWorldReceivable is not available on this network');
209
+ }
210
+ const rwrContract = (0, helpers_1.getRealWorldReceivableContract)(signerOrProvider, chainId);
211
+ if (!rwrContract) {
212
+ throw new Error('Could not find RealWorldReceivable contract');
213
+ }
214
+ // Load all receivables of owner
215
+ const balance = await rwrContract.balanceOf(owner);
216
+ // Create empty array with length of balance
217
+ const tokens = Array.from(Array(balance.toNumber()));
218
+ const fetchPromises = tokens.map(async (_, tokenIndex) => {
219
+ const tokenId = await rwrContract.tokenOfOwnerByIndex(owner, tokenIndex);
220
+ const rwrInfo = await rwrContract.rwrInfoMapping(tokenId);
221
+ // If a RWR uploaded by an owner is not for this specific pool, skip it
222
+ if (rwrInfo.poolAddress.toLowerCase() !== poolInfo.pool.toLowerCase()) {
223
+ return undefined;
224
+ }
225
+ const tokenURI = await rwrContract.tokenURI(tokenId);
226
+ const metadata = await ARWeaveService_1.ARWeaveService.fetchMetadataFromUrl(tokenURI);
227
+ return {
228
+ tokenId,
229
+ poolAddress: rwrInfo.poolAddress,
230
+ receivableAmount: rwrInfo.receivableAmount,
231
+ paidAmount: rwrInfo.paidAmount,
232
+ creationDate: rwrInfo.creationDate,
233
+ maturityDate: rwrInfo.maturityDate,
234
+ currencyCode: rwrInfo.currencyCode,
235
+ tokenURI,
236
+ metadata,
237
+ };
238
+ });
239
+ const tokenData = await Promise.all(fetchPromises);
240
+ // Filter undefined
241
+ return tokenData.filter((token) => token !== undefined);
242
+ }
243
+ /**
244
+ * An object that contains functions to interact with Huma's receivables.
245
+ * @namespace ReceivableService
246
+ */
247
+ exports.ReceivableService = {
248
+ createReceivableWithMetadata,
249
+ createReceivable,
250
+ declareReceivablePaymentByTokenId,
251
+ declareReceivablePaymentByReferenceId,
252
+ loadReceivablesOfOwnerWithMetadata,
253
+ };
194
254
  //# sourceMappingURL=ReceivableService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;;AAAA,wDAA4E;AAE5E,iDAO6B;AAC7B,2EAA8C;AAE9C,qDAAiD;AACjD,wCAA2D;AAC3D,oCAA+E;AAG/E;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,qCAAqC,CAClD,MAAqB,EACrB,WAAmB,EACnB,aAAqB,EACrB,UAAqB,EAAE;;IAEvB,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;IAE/C,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,iBAAiB;IACjB,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,gBAAgB,CAClD,OAAO,EACP,aAAa,EACb,WAAW,CACZ,CAAA;IAED,6CAA6C;IAC7C,MAAM,gBAAgB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;GAU3B,CAAA;IAED,IAAI,kBAAkB,CAAA;IACtB,QA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,CAAA;QACD,OAAO,CAAC,GAAG,CAAC,yCAAyC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAA;QAEnE,OAAO,MAAM,gBAAgB,CAC3B,gBAAgB,YAAY,wBAAY;YACtC,CAAC,CAAC,gBAAgB,CAAC,SAAS,EAAE;YAC9B,CAAC,CAAC,gBAAgB,EACpB,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,QAAQ,CAAC,EAAE,EAAE,EACpC,OAAO,CACR,CAAA;KACF;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,MAAM,CAAC,CAAA;KACR;AACH,CAAC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG;IAC/B,4BAA4B;IAC5B,gBAAgB;IAChB,iCAAiC;IACjC,qCAAqC;CACtC,CAAA"}
1
+ {"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;;AAAA,wDAA4E;AAC5E,mCAAwD;AACxD,iDAQ6B;AAC7B,2EAA8C;AAE9C,qDAAiD;AACjD,wCAA2D;AAC3D,oCAA+E;AAG/E;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,qCAAqC,CAClD,MAAqB,EACrB,WAAmB,EACnB,aAAqB,EACrB,UAAqB,EAAE;;IAEvB,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAA;IAE/C,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,iBAAiB;IACjB,MAAM,MAAM,GAAG,MAAM,+BAAc,CAAC,gBAAgB,CAClD,OAAO,EACP,aAAa,EACb,WAAW,CACZ,CAAA;IAED,6CAA6C;IAC7C,MAAM,gBAAgB,GAA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AC,MAAM,CACrB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CACF,CAAA;AAChC,CAAC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG;IAC/B,4BAA4B;IAC5B,gBAAgB;IAChB,iCAAiC;IACjC,qCAAqC;IACrC,kCAAkC;CACnC,CAAA"}
@@ -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 {};