@huma-finance/sdk 0.0.31 → 0.0.32

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 +1041 -977
  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/BaseCreditPoolReceivableContractHelper.d.ts +10 -0
  9. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +22 -0
  10. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
  11. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  12. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +21 -21
  13. package/dist/cjs/helpers/PoolContractHelper.d.ts +119 -119
  14. package/dist/cjs/helpers/PoolContractHelper.js +142 -142
  15. package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  16. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +21 -21
  17. package/dist/cjs/helpers/index.d.ts +3 -3
  18. package/dist/cjs/helpers/index.js +6 -6
  19. package/dist/cjs/hooks/index.d.ts +4 -4
  20. package/dist/cjs/hooks/index.js +7 -7
  21. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +10 -0
  22. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +20 -0
  23. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
  24. package/dist/cjs/hooks/useContract.d.ts +13 -13
  25. package/dist/cjs/hooks/useContract.js +30 -30
  26. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  27. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +20 -20
  28. package/dist/cjs/hooks/usePoolContract.d.ts +60 -60
  29. package/dist/cjs/hooks/usePoolContract.js +53 -53
  30. package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -10
  31. package/dist/cjs/hooks/useRealWorldReceivableContract.js +19 -19
  32. package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
  33. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +17 -0
  34. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +1 -0
  35. package/dist/cjs/index.d.ts +4 -4
  36. package/dist/cjs/index.js +7 -7
  37. package/dist/cjs/services/ARWeaveService.d.ts +106 -106
  38. package/dist/cjs/services/ARWeaveService.js +190 -190
  39. package/dist/cjs/services/ARWeaveService.js.map +1 -1
  40. package/dist/cjs/services/EAService.d.ts +20 -20
  41. package/dist/cjs/services/EAService.js +33 -33
  42. package/dist/cjs/services/ReceivableService.d.ts +105 -105
  43. package/dist/cjs/services/ReceivableService.js +310 -253
  44. package/dist/cjs/services/ReceivableService.js.map +1 -1
  45. package/dist/cjs/services/SubgraphService.d.ts +53 -53
  46. package/dist/cjs/services/SubgraphService.js +93 -93
  47. package/dist/cjs/services/index.d.ts +4 -4
  48. package/dist/cjs/services/index.js +7 -7
  49. package/dist/cjs/utils/chain.d.ts +15 -15
  50. package/dist/cjs/utils/chain.js +37 -37
  51. package/dist/cjs/utils/index.d.ts +4 -4
  52. package/dist/cjs/utils/index.js +7 -7
  53. package/dist/cjs/utils/maticGasStation.d.ts +3 -3
  54. package/dist/cjs/utils/maticGasStation.js +38 -38
  55. package/dist/cjs/utils/poolInfo.d.ts +8 -8
  56. package/dist/cjs/utils/poolInfo.js +12 -12
  57. package/dist/cjs/utils/web3.d.ts +5 -5
  58. package/dist/cjs/utils/web3.js +33 -33
  59. package/dist/graphql/generatedTypes.d.ts +40 -40
  60. package/dist/graphql/generatedTypes.js +4 -4
  61. package/dist/graphql/index.d.ts +1 -1
  62. package/dist/graphql/index.js +1 -1
  63. package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +10 -0
  64. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +18 -0
  65. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
  66. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  67. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
  68. package/dist/helpers/PoolContractHelper.d.ts +119 -119
  69. package/dist/helpers/PoolContractHelper.js +133 -133
  70. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  71. package/dist/helpers/RealWorldReceivableContractHelper.js +17 -17
  72. package/dist/helpers/index.d.ts +3 -3
  73. package/dist/helpers/index.js +3 -3
  74. package/dist/hooks/index.d.ts +4 -4
  75. package/dist/hooks/index.js +4 -4
  76. package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +10 -0
  77. package/dist/hooks/useBaseCreditPoolReceivableContract.js +16 -0
  78. package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
  79. package/dist/hooks/useContract.d.ts +13 -13
  80. package/dist/hooks/useContract.js +26 -26
  81. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  82. package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
  83. package/dist/hooks/usePool.d.ts +0 -0
  84. package/dist/hooks/usePool.js +2 -0
  85. package/dist/hooks/usePool.js.map +1 -0
  86. package/dist/hooks/usePoolContract.d.ts +60 -60
  87. package/dist/hooks/usePoolContract.js +48 -48
  88. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -10
  89. package/dist/hooks/useRealWorldReceivableContract.js +15 -15
  90. package/dist/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
  91. package/dist/hooks/useReceivableFactoringPoolContract.js +13 -0
  92. package/dist/hooks/useReceivableFactoringPoolContract.js.map +1 -0
  93. package/dist/index.d.ts +4 -4
  94. package/dist/index.js +4 -4
  95. package/dist/services/ARWeaveService.d.ts +106 -106
  96. package/dist/services/ARWeaveService.js +185 -185
  97. package/dist/services/ARWeaveService.js.map +1 -1
  98. package/dist/services/EAService.d.ts +20 -20
  99. package/dist/services/EAService.js +30 -30
  100. package/dist/services/ReceivableService.d.ts +105 -105
  101. package/dist/services/ReceivableService.js +306 -249
  102. package/dist/services/ReceivableService.js.map +1 -1
  103. package/dist/services/SubgraphService.d.ts +53 -53
  104. package/dist/services/SubgraphService.js +90 -90
  105. package/dist/services/index.d.ts +4 -4
  106. package/dist/services/index.js +4 -4
  107. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  108. package/dist/utils/chain.d.ts +15 -15
  109. package/dist/utils/chain.js +31 -31
  110. package/dist/utils/index.d.ts +4 -4
  111. package/dist/utils/index.js +4 -4
  112. package/dist/utils/maticGasStation.d.ts +3 -3
  113. package/dist/utils/maticGasStation.js +33 -33
  114. package/dist/utils/poolInfo.d.ts +8 -8
  115. package/dist/utils/poolInfo.js +8 -8
  116. package/dist/utils/web3.d.ts +5 -5
  117. package/dist/utils/web3.js +27 -27
  118. package/getting-started.md +190 -190
  119. package/package.json +3 -3
@@ -1,250 +1,307 @@
1
- import { Web3Provider } from '@ethersproject/providers';
2
- import { ethers } from 'ethers';
3
- import { PoolContractMap, PoolSubgraphMap, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
4
- import request, { gql } from 'graphql-request';
5
- import { ARWeaveService } from './ARWeaveService';
6
- import { getRealWorldReceivableContract } from '../helpers';
7
- import { getDefaultGasOptions, getChainIdFromSignerOrProvider } from '../utils';
8
- /**
9
- * Declares a payment on a RealWorldReceivable given a reference ID of the receivable, which was used as an index for ARWeave data.
10
- *
11
- * @async
12
- * @function
13
- * @memberof ReceivableService
14
- * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
15
- * @param {string} referenceId - An internal identifier value added as a tag on ARWeave
16
- * @param {number} paymentAmount - The amount to declare paid to the receivable.
17
- * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
18
- * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
19
- */
20
- async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount, gasOpts = {}) {
21
- var _a, _b, _c;
22
- const chainId = await getChainIdFromSignerOrProvider(signer);
23
- const signerAddress = await signer.getAddress();
24
- if (!chainId) {
25
- throw new Error('No Chain ID found');
26
- }
27
- // Get ARWeave ID
28
- const dataID = await ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
29
- // Fetch receivables with the same ARWeave ID
30
- const receivablesQuery = gql `
31
- query ReceivablesByURIQuery($owner: String!, $uri: String!) {
32
- receivables(where: { owner: $owner, uri: $uri }) {
33
- ...ReceivableFields
34
- }
35
- }
36
-
37
- fragment ReceivableFields on Receivable {
38
- tokenId
39
- }
40
- `;
41
- const receivableSubgraph = PoolSubgraphMap[chainId].receivablesSubgraph;
42
- if (!receivableSubgraph) {
43
- throw new Error('No receivable subgraph exists for this chain');
44
- }
45
- const receivablesData = await request(receivableSubgraph, receivablesQuery, {
46
- owner: signerAddress,
47
- uri: `https://arweave.net/${dataID}`,
48
- });
49
- 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)) {
50
- throw new Error('No receivables found with this ARWeave ID.');
51
- }
52
- else if (((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length) > 1) {
53
- throw new Error(`This owner has multiple receivables with the same URI. Please burn
54
- unnecessary receivables or pay the correct token manually using declareReceivablePaymentByTokenId`);
55
- }
56
- const contract = getRealWorldReceivableContract(signer, chainId);
57
- if (!contract) {
58
- throw new Error('Could not find RealWorldReceivable contract');
59
- }
60
- gasOpts = await getDefaultGasOptions(gasOpts, chainId);
61
- return contract.declarePayment((_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _c === void 0 ? void 0 : _c.tokenId, paymentAmount, gasOpts);
62
- }
63
- /**
64
- * Declares a payment on a RealWorldReceivable given a tokenID of the receivable.
65
- *
66
- * @async
67
- * @function
68
- * @memberof ReceivableService
69
- * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
70
- * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
71
- * @param {number} paymentAmount - The amount to pay the receivable.
72
- * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
73
- * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
74
- * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
75
- */
76
- async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount, gasOpts = {}) {
77
- var _a;
78
- const chainId = await getChainIdFromSignerOrProvider(signer);
79
- if (!chainId) {
80
- throw new Error('No Chain ID found');
81
- }
82
- const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
83
- if (!realWorldReceivable) {
84
- throw new Error('RealWorldReceivable is not available on this network');
85
- }
86
- const contract = getRealWorldReceivableContract(signer, chainId);
87
- if (!contract) {
88
- throw new Error('Could not find RealWorldReceivable contract');
89
- }
90
- gasOpts = await getDefaultGasOptions(gasOpts, chainId);
91
- return contract.declarePayment(receivableTokenId, paymentAmount, gasOpts);
92
- }
93
- /**
94
- * Creates a new RealWorldReceivable token on the given chain of the signer
95
- *
96
- * @async
97
- * @function
98
- * @memberof ReceivableService
99
- * @param {ethers.Signer} signer - The signer used to send the transaction.
100
- * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
101
- * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
102
- * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
103
- * @param {number} receivableAmount - The amount of the receivable token to mint.
104
- * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
105
- * @param {string} uri - The URI of the receivable token metadata.
106
- * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
107
- * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
108
- * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
109
- */
110
- async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
111
- var _a, _b;
112
- const chainId = await getChainIdFromSignerOrProvider(signer);
113
- if (!chainId) {
114
- throw new Error('No Chain ID found');
115
- }
116
- const poolInfo = chainId
117
- ? (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
118
- : undefined;
119
- if (!poolInfo) {
120
- throw new Error('RealWorldReceivable is not available on this network');
121
- }
122
- const contract = getRealWorldReceivableContract(signer, chainId);
123
- if (!contract) {
124
- throw new Error('Could not find RealWorldReceivable contract');
125
- }
126
- gasOpts = await getDefaultGasOptions(gasOpts, chainId);
127
- return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
128
- }
129
- /**
130
- * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
131
- *
132
- * @async
133
- * @function
134
- * @memberof ReceivableService
135
- * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
136
- * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
137
- * from server calls.
138
- * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
139
- * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
140
- * @param {string} recipient - The receivable token recipient.
141
- * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
142
- * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
143
- * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
144
- * @param {number} receivableAmount - The receivable amount.
145
- * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
146
- * @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
147
- * @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
148
- * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
149
- * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
150
- * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
151
- * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
152
- * @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
153
- * @returns {Promise<TransactionResponse>} - The transaction receipt.
154
- */
155
- async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
156
- const config = ARWeaveService.getBundlrNetworkConfig(chainId);
157
- try {
158
- const tags = [
159
- { name: 'Content-Type', value: 'application/json' },
160
- { name: 'appName', value: 'HumaFinance' },
161
- { name: 'poolName', value: poolName },
162
- { name: 'poolType', value: poolType },
163
- { name: 'referenceId', value: referenceId },
164
- ...extraTags,
165
- ];
166
- const response = await ARWeaveService.storeData(config, signerOrProvider instanceof Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
167
- console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
168
- return await createReceivable(signerOrProvider instanceof Web3Provider
169
- ? signerOrProvider.getSigner()
170
- : signerOrProvider, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${response.id}`, gasOpts);
171
- }
172
- catch (e) {
173
- console.error(e);
174
- throw e;
175
- }
176
- }
177
- /**
178
- * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
179
- *
180
- * @async
181
- * @function
182
- * @memberof ReceivableService
183
- * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
184
- * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
185
- * from server calls.
186
- * @param {string} owner - The receivable token owner to query from.
187
- * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
188
- * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
189
- * @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
190
- */
191
- async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType) {
192
- var _a, _b;
193
- if (!ethers.utils.isAddress(owner)) {
194
- throw new Error('Invalid owner address');
195
- }
196
- const chainId = await getChainIdFromSignerOrProvider(signerOrProvider);
197
- if (!chainId) {
198
- throw new Error('No Chain ID found');
199
- }
200
- const poolInfo = chainId
201
- ? (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
202
- : undefined;
203
- if (!poolInfo) {
204
- throw new Error('RealWorldReceivable is not available on this network');
205
- }
206
- const rwrContract = getRealWorldReceivableContract(signerOrProvider, chainId);
207
- if (!rwrContract) {
208
- throw new Error('Could not find RealWorldReceivable contract');
209
- }
210
- // Load all receivables of owner
211
- const balance = await rwrContract.balanceOf(owner);
212
- // Create empty array with length of balance
213
- const tokens = Array.from(Array(balance.toNumber()));
214
- const fetchPromises = tokens.map(async (_, tokenIndex) => {
215
- const tokenId = await rwrContract.tokenOfOwnerByIndex(owner, tokenIndex);
216
- const rwrInfo = await rwrContract.rwrInfoMapping(tokenId);
217
- // If a RWR uploaded by an owner is not for this specific pool, skip it
218
- if (rwrInfo.poolAddress.toLowerCase() !== poolInfo.pool.toLowerCase()) {
219
- return undefined;
220
- }
221
- const tokenURI = await rwrContract.tokenURI(tokenId);
222
- const metadata = await ARWeaveService.fetchMetadataFromUrl(tokenURI);
223
- return {
224
- tokenId,
225
- poolAddress: rwrInfo.poolAddress,
226
- receivableAmount: rwrInfo.receivableAmount,
227
- paidAmount: rwrInfo.paidAmount,
228
- creationDate: rwrInfo.creationDate,
229
- maturityDate: rwrInfo.maturityDate,
230
- currencyCode: rwrInfo.currencyCode,
231
- tokenURI,
232
- metadata,
233
- };
234
- });
235
- const tokenData = await Promise.all(fetchPromises);
236
- // Filter undefined
237
- return tokenData.filter((token) => token !== undefined);
238
- }
239
- /**
240
- * An object that contains functions to interact with Huma's receivables.
241
- * @namespace ReceivableService
242
- */
243
- export const ReceivableService = {
244
- createReceivableWithMetadata,
245
- createReceivable,
246
- declareReceivablePaymentByTokenId,
247
- declareReceivablePaymentByReferenceId,
248
- loadReceivablesOfOwnerWithMetadata,
249
- };
1
+ import { Web3Provider } from '@ethersproject/providers';
2
+ import { ethers } from 'ethers';
3
+ import { PoolContractMap, PoolSubgraphMap, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
4
+ import request, { gql } from 'graphql-request';
5
+ import { ARWeaveService } from './ARWeaveService';
6
+ import { getRealWorldReceivableContract } from '../helpers';
7
+ import { getDefaultGasOptions, getChainIdFromSignerOrProvider } from '../utils';
8
+ /**
9
+ * Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
10
+ *
11
+ * @async
12
+ * @function
13
+ * @memberof ReceivableService
14
+ * @param {ethers.Signer} signer - The signer used to lookup metadata uploads for
15
+ * @param {string} arweaveId - The internal ARWeave identifier to lookup a token by
16
+ * @returns {Promise<string | null | undefined>} - Either the token Id or null if no token was found.
17
+ */
18
+ async function getTokenIdByARWeaveId(signer, arweaveId) {
19
+ var _a, _b, _c;
20
+ if (arweaveId === null) {
21
+ return null;
22
+ }
23
+ const chainId = await getChainIdFromSignerOrProvider(signer);
24
+ const signerAddress = await signer.getAddress();
25
+ if (!chainId) {
26
+ throw new Error('No Chain Id found');
27
+ }
28
+ // Fetch receivables with the same ARWeave Id
29
+ const receivablesQuery = gql `
30
+ query ReceivablesByURIQuery($owner: String!, $uri: String!) {
31
+ receivables(where: { owner: $owner, uri: $uri }) {
32
+ ...ReceivableFields
33
+ }
34
+ }
35
+
36
+ fragment ReceivableFields on Receivable {
37
+ tokenId
38
+ }
39
+ `;
40
+ const receivableSubgraph = PoolSubgraphMap[chainId].receivablesSubgraph;
41
+ if (!receivableSubgraph) {
42
+ throw new Error('No receivable subgraph exists for this chain');
43
+ }
44
+ const receivablesData = await request(receivableSubgraph, receivablesQuery, {
45
+ owner: signerAddress,
46
+ uri: `https://arweave.net/${arweaveId}`,
47
+ });
48
+ if (!((_a = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _a === void 0 ? void 0 : _a.length)) {
49
+ console.log('No receivables found with this ARWeave Id.');
50
+ return null;
51
+ }
52
+ if (((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length) > 1) {
53
+ console.log(`This owner has multiple receivables with the same ARWeave URI, so we don't know which to use. Please burn
54
+ unnecessary receivables or pay the correct token manually using declareReceivablePaymentByTokenId`);
55
+ return null;
56
+ }
57
+ return (_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _c === void 0 ? void 0 : _c.tokenId;
58
+ }
59
+ /**
60
+ * Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
61
+ *
62
+ * @async
63
+ * @function
64
+ * @memberof ReceivableService
65
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
66
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave
67
+ * @param {number} paymentAmount - The amount to declare paid to the receivable.
68
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
69
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
70
+ */
71
+ async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount, gasOpts = {}) {
72
+ const chainId = await getChainIdFromSignerOrProvider(signer);
73
+ const signerAddress = await signer.getAddress();
74
+ if (!chainId) {
75
+ throw new Error('No Chain Id found');
76
+ }
77
+ // Get ARWeave Id
78
+ const dataId = await ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
79
+ // Fetch receivables with the same ARWeave Id
80
+ const tokenId = await getTokenIdByARWeaveId(signer, dataId);
81
+ if (tokenId == null) {
82
+ throw new Error('Could not find tokenId for this ARWeave Id. Please check your logs for more details.');
83
+ }
84
+ const contract = getRealWorldReceivableContract(signer, chainId);
85
+ if (!contract) {
86
+ throw new Error('Could not find RealWorldReceivable contract');
87
+ }
88
+ gasOpts = await getDefaultGasOptions(gasOpts, chainId);
89
+ return contract.declarePayment(tokenId, paymentAmount, gasOpts);
90
+ }
91
+ /**
92
+ * Declares a payment on a RealWorldReceivable given a tokenId of the receivable.
93
+ *
94
+ * @async
95
+ * @function
96
+ * @memberof ReceivableService
97
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
98
+ * @param {BigNumberish} receivableTokenId - The Id of the receivable token to pay.
99
+ * @param {number} paymentAmount - The amount to pay the receivable.
100
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
101
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
102
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
103
+ */
104
+ async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount, gasOpts = {}) {
105
+ var _a;
106
+ const chainId = await getChainIdFromSignerOrProvider(signer);
107
+ if (!chainId) {
108
+ throw new Error('No Chain Id found');
109
+ }
110
+ const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
111
+ if (!realWorldReceivable) {
112
+ throw new Error('RealWorldReceivable is not available on this network');
113
+ }
114
+ const contract = getRealWorldReceivableContract(signer, chainId);
115
+ if (!contract) {
116
+ throw new Error('Could not find RealWorldReceivable contract');
117
+ }
118
+ gasOpts = await getDefaultGasOptions(gasOpts, chainId);
119
+ return contract.declarePayment(receivableTokenId, paymentAmount, gasOpts);
120
+ }
121
+ /**
122
+ * Creates a new RealWorldReceivable token on the given chain of the signer
123
+ *
124
+ * @async
125
+ * @function
126
+ * @memberof ReceivableService
127
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
128
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
129
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
130
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
131
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
132
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
133
+ * @param {string} uri - The URI of the receivable token metadata.
134
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
135
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
136
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
137
+ */
138
+ async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
139
+ var _a, _b;
140
+ const chainId = await getChainIdFromSignerOrProvider(signer);
141
+ if (!chainId) {
142
+ throw new Error('No Chain Id found');
143
+ }
144
+ const poolInfo = chainId
145
+ ? (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
146
+ : undefined;
147
+ if (!poolInfo) {
148
+ throw new Error('RealWorldReceivable is not available on this network');
149
+ }
150
+ const contract = getRealWorldReceivableContract(signer, chainId);
151
+ if (!contract) {
152
+ throw new Error('Could not find RealWorldReceivable contract');
153
+ }
154
+ gasOpts = await getDefaultGasOptions(gasOpts, chainId);
155
+ return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
156
+ }
157
+ /**
158
+ * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
159
+ *
160
+ * @async
161
+ * @function
162
+ * @memberof ReceivableService
163
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
164
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
165
+ * from server calls.
166
+ * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
167
+ * @param {number} chainId - The chain Id to mint the receivable token on and pay ARWeave funds from.
168
+ * @param {string} recipient - The receivable token recipient.
169
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
170
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
171
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
172
+ * @param {number} receivableAmount - The receivable amount.
173
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
174
+ * @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
175
+ * @param {number} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
176
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
177
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
178
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
179
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
180
+ * @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
181
+ * @returns {Promise<TransactionResponse>} - The transaction receipt.
182
+ */
183
+ async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
184
+ if (typeof metadata !== 'object' || Array.isArray(metadata)) {
185
+ throw new Error('Input must be a JSON object.');
186
+ }
187
+ const config = ARWeaveService.getBundlrNetworkConfig(chainId);
188
+ try {
189
+ // Check to see if metadata with referenceId has already been minted
190
+ const signer = signerOrProvider instanceof Web3Provider
191
+ ? signerOrProvider.getSigner()
192
+ : signerOrProvider;
193
+ const signerAddress = await signer.getAddress();
194
+ const dataId = await ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
195
+ let arweaveId;
196
+ if (dataId != null) {
197
+ // If there already exists metadata with this reference Id, check if there exists
198
+ // a token with that ARWeave Id as metadata.
199
+ const tokenId = await getTokenIdByARWeaveId(signer, dataId);
200
+ if (tokenId == null) {
201
+ console.log(`Reusing existing metadata ${dataId} to mint new receivable`);
202
+ arweaveId = dataId;
203
+ }
204
+ else {
205
+ throw new Error('A token already exists with this reference Id, canceling mint');
206
+ }
207
+ }
208
+ else {
209
+ const tags = [
210
+ { name: 'Content-Type', value: 'application/json' },
211
+ { name: 'appName', value: 'HumaFinance' },
212
+ { name: 'poolName', value: poolName },
213
+ { name: 'poolType', value: poolType },
214
+ { name: 'referenceId', value: referenceId },
215
+ ...extraTags,
216
+ ];
217
+ // Append referenceId to metadata (if it's not already there)
218
+ if (!Object.prototype.hasOwnProperty.call(metadata, 'referenceId')) {
219
+ metadata.referenceId = referenceId;
220
+ }
221
+ const response = await ARWeaveService.storeData(config, signerOrProvider instanceof Web3Provider
222
+ ? signerOrProvider
223
+ : privateKey, metadata, tags, lazyFund);
224
+ arweaveId = response.id;
225
+ console.log(`Data uploaded ==> https://arweave.net/${arweaveId}`);
226
+ }
227
+ return await createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, `https://arweave.net/${arweaveId}`, gasOpts);
228
+ }
229
+ catch (e) {
230
+ console.error(e);
231
+ throw e;
232
+ }
233
+ }
234
+ /**
235
+ * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
236
+ *
237
+ * @async
238
+ * @function
239
+ * @memberof ReceivableService
240
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
241
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
242
+ * from server calls.
243
+ * @param {string} owner - The receivable token owner to query from.
244
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
245
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
246
+ * @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
247
+ */
248
+ async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType) {
249
+ var _a, _b;
250
+ if (!ethers.utils.isAddress(owner)) {
251
+ throw new Error('Invalid owner address');
252
+ }
253
+ const chainId = await getChainIdFromSignerOrProvider(signerOrProvider);
254
+ if (!chainId) {
255
+ throw new Error('No Chain Id found');
256
+ }
257
+ const poolInfo = chainId
258
+ ? (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
259
+ : undefined;
260
+ if (!poolInfo) {
261
+ throw new Error('RealWorldReceivable is not available on this network');
262
+ }
263
+ const rwrContract = getRealWorldReceivableContract(signerOrProvider, chainId);
264
+ if (!rwrContract) {
265
+ throw new Error('Could not find RealWorldReceivable contract');
266
+ }
267
+ // Load all receivables of owner
268
+ const balance = await rwrContract.balanceOf(owner);
269
+ // Create empty array with length of balance
270
+ const tokens = Array.from(Array(balance.toNumber()));
271
+ const fetchPromises = tokens.map(async (_, tokenIndex) => {
272
+ const tokenId = await rwrContract.tokenOfOwnerByIndex(owner, tokenIndex);
273
+ const rwrInfo = await rwrContract.rwrInfoMapping(tokenId);
274
+ // If a RWR uploaded by an owner is not for this specific pool, skip it
275
+ if (rwrInfo.poolAddress.toLowerCase() !== poolInfo.pool.toLowerCase()) {
276
+ return undefined;
277
+ }
278
+ const tokenURI = await rwrContract.tokenURI(tokenId);
279
+ const metadata = await ARWeaveService.fetchMetadataFromUrl(tokenURI);
280
+ return {
281
+ tokenId,
282
+ poolAddress: rwrInfo.poolAddress,
283
+ receivableAmount: rwrInfo.receivableAmount,
284
+ paidAmount: rwrInfo.paidAmount,
285
+ creationDate: rwrInfo.creationDate,
286
+ maturityDate: rwrInfo.maturityDate,
287
+ currencyCode: rwrInfo.currencyCode,
288
+ tokenURI,
289
+ metadata,
290
+ };
291
+ });
292
+ const tokenData = await Promise.all(fetchPromises);
293
+ // Filter undefined
294
+ return tokenData.filter((token) => token !== undefined);
295
+ }
296
+ /**
297
+ * An object that contains functions to interact with Huma's receivables.
298
+ * @namespace ReceivableService
299
+ */
300
+ export const ReceivableService = {
301
+ createReceivableWithMetadata,
302
+ createReceivable,
303
+ declareReceivablePaymentByTokenId,
304
+ declareReceivablePaymentByReferenceId,
305
+ loadReceivablesOfOwnerWithMetadata,
306
+ };
250
307
  //# sourceMappingURL=ReceivableService.js.map
@@ -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,EAEf,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,OAAO,EAAE,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,CAAA;AAG/E;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,qCAAqC,CAClD,MAAqB,EACrB,WAAmB,EACnB,aAAqB,EACrB,UAAqB,EAAE;;IAEvB,MAAM,OAAO,GAAG,MAAM,8BAA8B,CAAC,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,cAAc,CAAC,gBAAgB,CAClD,OAAO,EACP,aAAa,EACb,WAAW,C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