@huma-finance/sdk 0.0.37 → 0.0.38-beta.0

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