@huma-finance/sdk 0.0.39 → 0.0.42-beta.100

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 (135) hide show
  1. package/API.md +45 -9
  2. package/dist/cjs/graphql/generatedTypes.d.ts +40 -0
  3. package/dist/cjs/graphql/generatedTypes.js +9 -0
  4. package/dist/cjs/graphql/generatedTypes.js.map +1 -0
  5. package/dist/cjs/graphql/index.d.ts +1 -0
  6. package/dist/cjs/graphql/index.js +5 -0
  7. package/dist/cjs/graphql/index.js.map +1 -0
  8. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
  9. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +22 -0
  10. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
  11. package/dist/cjs/helpers/PoolContractHelper.d.ts +119 -0
  12. package/dist/cjs/helpers/PoolContractHelper.js +144 -0
  13. package/dist/cjs/helpers/PoolContractHelper.js.map +1 -0
  14. package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
  15. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +22 -0
  16. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js.map +1 -0
  17. package/dist/cjs/helpers/index.d.ts +3 -0
  18. package/dist/cjs/helpers/index.js +7 -0
  19. package/dist/cjs/helpers/index.js.map +1 -0
  20. package/dist/cjs/hooks/index.d.ts +4 -0
  21. package/dist/cjs/hooks/index.js +8 -0
  22. package/dist/cjs/hooks/index.js.map +1 -0
  23. package/dist/cjs/hooks/useContract.d.ts +13 -0
  24. package/dist/cjs/hooks/useContract.js +31 -0
  25. package/dist/cjs/hooks/useContract.js.map +1 -0
  26. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  27. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +21 -0
  28. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  29. package/dist/cjs/hooks/usePoolContract.d.ts +60 -0
  30. package/dist/cjs/hooks/usePoolContract.js +54 -0
  31. package/dist/cjs/hooks/usePoolContract.js.map +1 -0
  32. package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -0
  33. package/dist/cjs/hooks/useRealWorldReceivableContract.js +20 -0
  34. package/dist/cjs/hooks/useRealWorldReceivableContract.js.map +1 -0
  35. package/dist/cjs/index.d.ts +4 -0
  36. package/dist/cjs/index.js +8 -0
  37. package/dist/cjs/index.js.map +1 -0
  38. package/dist/cjs/services/ARWeaveService.d.ts +117 -0
  39. package/dist/cjs/services/ARWeaveService.js +204 -0
  40. package/dist/cjs/services/ARWeaveService.js.map +1 -0
  41. package/dist/cjs/services/EAService.d.ts +20 -0
  42. package/dist/cjs/services/EAService.js +34 -0
  43. package/dist/cjs/services/EAService.js.map +1 -0
  44. package/dist/cjs/services/ReceivableService.d.ts +158 -0
  45. package/dist/cjs/services/ReceivableService.js +325 -0
  46. package/dist/cjs/services/ReceivableService.js.map +1 -0
  47. package/dist/cjs/services/SubgraphService.d.ts +76 -0
  48. package/dist/cjs/services/SubgraphService.js +149 -0
  49. package/dist/cjs/services/SubgraphService.js.map +1 -0
  50. package/dist/cjs/services/index.d.ts +4 -0
  51. package/dist/cjs/services/index.js +8 -0
  52. package/dist/cjs/services/index.js.map +1 -0
  53. package/dist/cjs/utils/chain.d.ts +15 -0
  54. package/dist/cjs/utils/chain.js +38 -0
  55. package/dist/cjs/utils/chain.js.map +1 -0
  56. package/dist/cjs/utils/index.d.ts +4 -0
  57. package/dist/cjs/utils/index.js +8 -0
  58. package/dist/cjs/utils/index.js.map +1 -0
  59. package/dist/cjs/utils/maticGasStation.d.ts +3 -0
  60. package/dist/cjs/utils/maticGasStation.js +39 -0
  61. package/dist/cjs/utils/maticGasStation.js.map +1 -0
  62. package/dist/cjs/utils/poolInfo.d.ts +8 -0
  63. package/dist/cjs/utils/poolInfo.js +13 -0
  64. package/dist/cjs/utils/poolInfo.js.map +1 -0
  65. package/dist/cjs/utils/web3.d.ts +5 -0
  66. package/dist/cjs/utils/web3.js +34 -0
  67. package/dist/cjs/utils/web3.js.map +1 -0
  68. package/dist/graphql/generatedTypes.d.ts +40 -0
  69. package/dist/graphql/generatedTypes.js +5 -0
  70. package/dist/graphql/generatedTypes.js.map +1 -0
  71. package/dist/graphql/index.d.ts +1 -0
  72. package/dist/graphql/index.js +2 -0
  73. package/dist/graphql/index.js.map +1 -0
  74. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
  75. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +18 -0
  76. package/dist/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
  77. package/dist/helpers/PoolContractHelper.d.ts +119 -0
  78. package/dist/helpers/PoolContractHelper.js +135 -0
  79. package/dist/helpers/PoolContractHelper.js.map +1 -0
  80. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
  81. package/dist/helpers/RealWorldReceivableContractHelper.js +18 -0
  82. package/dist/helpers/RealWorldReceivableContractHelper.js.map +1 -0
  83. package/dist/helpers/index.d.ts +3 -0
  84. package/dist/helpers/index.js +4 -0
  85. package/dist/helpers/index.js.map +1 -0
  86. package/dist/hooks/index.d.ts +4 -0
  87. package/dist/hooks/index.js +5 -0
  88. package/dist/hooks/index.js.map +1 -0
  89. package/dist/hooks/useContract.d.ts +13 -0
  90. package/dist/hooks/useContract.js +27 -0
  91. package/dist/hooks/useContract.js.map +1 -0
  92. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  93. package/dist/hooks/useERC20TransferableReceivableContract.js +17 -0
  94. package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  95. package/dist/hooks/usePoolContract.d.ts +60 -0
  96. package/dist/hooks/usePoolContract.js +49 -0
  97. package/dist/hooks/usePoolContract.js.map +1 -0
  98. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -0
  99. package/dist/hooks/useRealWorldReceivableContract.js +16 -0
  100. package/dist/hooks/useRealWorldReceivableContract.js.map +1 -0
  101. package/dist/index.d.ts +4 -0
  102. package/dist/index.js +5 -0
  103. package/dist/index.js.map +1 -0
  104. package/dist/services/ARWeaveService.d.ts +117 -0
  105. package/dist/services/ARWeaveService.js +199 -0
  106. package/dist/services/ARWeaveService.js.map +1 -0
  107. package/dist/services/EAService.d.ts +20 -0
  108. package/dist/services/EAService.js +31 -0
  109. package/dist/services/EAService.js.map +1 -0
  110. package/dist/services/ReceivableService.d.ts +158 -0
  111. package/dist/services/ReceivableService.js +322 -0
  112. package/dist/services/ReceivableService.js.map +1 -0
  113. package/dist/services/SubgraphService.d.ts +76 -0
  114. package/dist/services/SubgraphService.js +146 -0
  115. package/dist/services/SubgraphService.js.map +1 -0
  116. package/dist/services/index.d.ts +4 -0
  117. package/dist/services/index.js +5 -0
  118. package/dist/services/index.js.map +1 -0
  119. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  120. package/dist/utils/chain.d.ts +15 -0
  121. package/dist/utils/chain.js +32 -0
  122. package/dist/utils/chain.js.map +1 -0
  123. package/dist/utils/index.d.ts +4 -0
  124. package/dist/utils/index.js +5 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/utils/maticGasStation.d.ts +3 -0
  127. package/dist/utils/maticGasStation.js +34 -0
  128. package/dist/utils/maticGasStation.js.map +1 -0
  129. package/dist/utils/poolInfo.d.ts +8 -0
  130. package/dist/utils/poolInfo.js +9 -0
  131. package/dist/utils/poolInfo.js.map +1 -0
  132. package/dist/utils/web3.d.ts +5 -0
  133. package/dist/utils/web3.js +28 -0
  134. package/dist/utils/web3.js.map +1 -0
  135. package/package.json +3 -3
@@ -0,0 +1,158 @@
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
+ import { Pagination } from './SubgraphService';
5
+ /**
6
+ * Fetches the tokenId of a RealWorldReceivable, or null if it doesn't exist, given a metadata URI
7
+ *
8
+ * @async
9
+ * @function
10
+ * @memberof ReceivableService
11
+ * @param {ethers.Signer} signer - The signer used to lookup metadata uploads for
12
+ * @param {string} arweaveId - The internal ARWeave identifier to lookup a token by
13
+ * @returns {Promise<string | null | undefined>} - Either the token Id or null if no token was found.
14
+ */
15
+ declare function getTokenIdByURI(signer: ethers.Signer, uri: string | null): Promise<string | null | undefined>;
16
+ /**
17
+ * Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
18
+ *
19
+ * @async
20
+ * @function
21
+ * @memberof ReceivableService
22
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
23
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave
24
+ * @param {number} paymentAmount - The amount to declare paid to the receivable.
25
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
26
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
27
+ */
28
+ declare function declareReceivablePaymentByReferenceId(signer: ethers.Signer, referenceId: string, paymentAmount: number, gasOpts?: Overrides): Promise<TransactionResponse>;
29
+ /**
30
+ * Declares a payment on a RealWorldReceivable given a tokenId of the receivable.
31
+ *
32
+ * @async
33
+ * @function
34
+ * @memberof ReceivableService
35
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
36
+ * @param {BigNumberish} receivableTokenId - The Id of the receivable token to pay.
37
+ * @param {number} paymentAmount - The amount to pay the receivable.
38
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
39
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
40
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
41
+ */
42
+ declare function declareReceivablePaymentByTokenId(signer: ethers.Signer, receivableTokenId: BigNumberish, paymentAmount: number, gasOpts?: Overrides): Promise<TransactionResponse>;
43
+ /**
44
+ * Creates a new RealWorldReceivable token on the given chain of the signer
45
+ *
46
+ * @async
47
+ * @function
48
+ * @memberof ReceivableService
49
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
50
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
51
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
52
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
53
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
54
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
55
+ * @param {string} uri - The URI of the receivable token metadata.
56
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
57
+ * @returns {Promise<TransactionResponse | null>} - A Promise of the transaction response.
58
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network, or if a token already exists with the same metadata URI.
59
+ */
60
+ declare function createReceivable(signer: ethers.Signer, poolName: POOL_NAME, poolType: POOL_TYPE, currencyCode: number, receivableAmount: number, maturityDate: number, uri: string, gasOpts?: Overrides): Promise<TransactionResponse>;
61
+ /**
62
+ * Uploads metadata onto ARWeave (or fetches the existing metadata with the same reference Id) and returns the ARWeave URL
63
+ *
64
+ * @async
65
+ * @function
66
+ * @memberof ReceivableService
67
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
68
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
69
+ * from server calls.
70
+ * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
71
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
72
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
73
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
74
+ * @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
75
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
76
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
77
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
78
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
79
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
80
+ * @returns {Promise<string>} - The ARWeave metadata URI.
81
+ */
82
+ declare function uploadOrFetchMetadataURI(signerOrProvider: Web3Provider | ethers.Signer, privateKey: string | null, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, metadata: Record<string, unknown>, referenceId: string, extraTags: {
83
+ name: string;
84
+ value: string;
85
+ }[], lazyFund?: boolean): Promise<string>;
86
+ /**
87
+ * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
88
+ *
89
+ * @async
90
+ * @function
91
+ * @memberof ReceivableService
92
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
93
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
94
+ * from server calls.
95
+ * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
96
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
97
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
98
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
99
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
100
+ * @param {number} receivableAmount - The receivable amount.
101
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
102
+ * @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
103
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
104
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
105
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
106
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
107
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
108
+ * @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
109
+ * @returns {Promise<TransactionResponse>} - The transaction receipt.
110
+ */
111
+ 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: {
112
+ name: string;
113
+ value: string;
114
+ }[], lazyFund?: boolean, gasOpts?: Overrides): Promise<TransactionResponse>;
115
+ /**
116
+ * Loads all RWRs belonging to the specified owner, including the RWR metadata
117
+ *
118
+ * @async
119
+ * @function
120
+ * @memberof ReceivableService
121
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
122
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
123
+ * from server calls.
124
+ * @param {string} owner - The receivable token owner to query from.
125
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
126
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
127
+ * @param {Pagination} pagination - The pagination option.
128
+ * @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
129
+ */
130
+ declare function loadReceivablesOfOwnerWithMetadata<T>(signerOrProvider: Web3Provider | ethers.Signer, owner: string, poolName: POOL_NAME, poolType: POOL_TYPE, pagination?: Pagination): Promise<RealWorldReceivableInfo<T>[]>;
131
+ /**
132
+ * Get the total count of all RWRs belonging to the specified owner
133
+ *
134
+ * @async
135
+ * @function
136
+ * @memberof ReceivableService
137
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
138
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
139
+ * from server calls.
140
+ * @param {string} owner - The receivable token owner to query from.
141
+ * @returns {Promise<number>} - Total count of receivables owned by the owner for the pool.
142
+ */
143
+ declare function getTotalCountOfReceivables(signerOrProvider: Web3Provider | ethers.Signer, owner: string): Promise<number>;
144
+ /**
145
+ * An object that contains functions to interact with Huma's receivables.
146
+ * @namespace ReceivableService
147
+ */
148
+ export declare const ReceivableService: {
149
+ createReceivableWithMetadata: typeof createReceivableWithMetadata;
150
+ createReceivable: typeof createReceivable;
151
+ declareReceivablePaymentByTokenId: typeof declareReceivablePaymentByTokenId;
152
+ declareReceivablePaymentByReferenceId: typeof declareReceivablePaymentByReferenceId;
153
+ loadReceivablesOfOwnerWithMetadata: typeof loadReceivablesOfOwnerWithMetadata;
154
+ getTotalCountOfReceivables: typeof getTotalCountOfReceivables;
155
+ uploadOrFetchMetadataURI: typeof uploadOrFetchMetadataURI;
156
+ getTokenIdByURI: typeof getTokenIdByURI;
157
+ };
158
+ export {};
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReceivableService = void 0;
4
+ const providers_1 = require("@ethersproject/providers");
5
+ const ethers_1 = require("ethers");
6
+ const shared_1 = require("@huma-finance/shared");
7
+ const graphql_request_1 = require("graphql-request");
8
+ const ARWeaveService_1 = require("./ARWeaveService");
9
+ const helpers_1 = require("../helpers");
10
+ const utils_1 = require("../utils");
11
+ const SubgraphService_1 = require("./SubgraphService");
12
+ /**
13
+ * Fetches the tokenId of a RealWorldReceivable, or null if it doesn't exist, given a metadata URI
14
+ *
15
+ * @async
16
+ * @function
17
+ * @memberof ReceivableService
18
+ * @param {ethers.Signer} signer - The signer used to lookup metadata uploads for
19
+ * @param {string} arweaveId - The internal ARWeave identifier to lookup a token by
20
+ * @returns {Promise<string | null | undefined>} - Either the token Id or null if no token was found.
21
+ */
22
+ async function getTokenIdByURI(signer, uri) {
23
+ var _a, _b, _c, _d;
24
+ if (uri === null) {
25
+ return null;
26
+ }
27
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
28
+ const signerAddress = await signer.getAddress();
29
+ if (!chainId) {
30
+ throw new Error('No Chain Id found');
31
+ }
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
+ const receivableSubgraph = (_a = shared_1.PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.receivablesSubgraph;
45
+ if (!receivableSubgraph) {
46
+ throw new Error('No receivable subgraph exists for this chain');
47
+ }
48
+ const receivablesData = await (0, graphql_request_1.request)(receivableSubgraph, receivablesQuery, {
49
+ owner: signerAddress,
50
+ uri,
51
+ });
52
+ if (!((_b = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _b === void 0 ? void 0 : _b.length)) {
53
+ console.log('No receivables found with this URI.');
54
+ return null;
55
+ }
56
+ if (((_c = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables) === null || _c === void 0 ? void 0 : _c.length) > 1) {
57
+ throw new Error(`This owner has multiple receivables with the same URI, so we don't know which to use. Please burn
58
+ unnecessary receivables. If paying, you can pay the correct token manually using declareReceivablePaymentByTokenId`);
59
+ }
60
+ return (_d = receivablesData === null || receivablesData === void 0 ? void 0 : receivablesData.receivables[0]) === null || _d === void 0 ? void 0 : _d.tokenId;
61
+ }
62
+ /**
63
+ * Declares a payment on a RealWorldReceivable given a reference Id of the receivable, which was used as an index for ARWeave data.
64
+ *
65
+ * @async
66
+ * @function
67
+ * @memberof ReceivableService
68
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
69
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave
70
+ * @param {number} paymentAmount - The amount to declare paid to the receivable.
71
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
72
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
73
+ */
74
+ async function declareReceivablePaymentByReferenceId(signer, referenceId, paymentAmount, gasOpts = {}) {
75
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
76
+ const signerAddress = await signer.getAddress();
77
+ if (!chainId) {
78
+ throw new Error('No Chain Id found');
79
+ }
80
+ // Get ARWeave Id
81
+ const dataId = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
82
+ // Fetch receivables with the same ARWeave Id
83
+ const tokenId = await getTokenIdByURI(signer, dataId);
84
+ if (tokenId == null) {
85
+ throw new Error('Could not find tokenId for this ARWeave Id. Please check your logs for more details.');
86
+ }
87
+ const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
88
+ if (!contract) {
89
+ throw new Error('Could not find RealWorldReceivable contract');
90
+ }
91
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
92
+ return contract.declarePayment(tokenId, paymentAmount, gasOpts);
93
+ }
94
+ /**
95
+ * Declares a payment on a RealWorldReceivable given a tokenId of the receivable.
96
+ *
97
+ * @async
98
+ * @function
99
+ * @memberof ReceivableService
100
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
101
+ * @param {BigNumberish} receivableTokenId - The Id of the receivable token to pay.
102
+ * @param {number} paymentAmount - The amount to pay the receivable.
103
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
104
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction receipt.
105
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network.
106
+ */
107
+ async function declareReceivablePaymentByTokenId(signer, receivableTokenId, paymentAmount, gasOpts = {}) {
108
+ var _a;
109
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
110
+ if (!chainId) {
111
+ throw new Error('No Chain Id found');
112
+ }
113
+ const realWorldReceivable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.RealWorldReceivable];
114
+ if (!realWorldReceivable) {
115
+ throw new Error('RealWorldReceivable is not available on this network');
116
+ }
117
+ const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
118
+ if (!contract) {
119
+ throw new Error('Could not find RealWorldReceivable contract');
120
+ }
121
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
122
+ return contract.declarePayment(receivableTokenId, paymentAmount, gasOpts);
123
+ }
124
+ /**
125
+ * Creates a new RealWorldReceivable token on the given chain of the signer
126
+ *
127
+ * @async
128
+ * @function
129
+ * @memberof ReceivableService
130
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
131
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
132
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
133
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
134
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
135
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
136
+ * @param {string} uri - The URI of the receivable token metadata.
137
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
138
+ * @returns {Promise<TransactionResponse | null>} - A Promise of the transaction response.
139
+ * @throws {Error} - Throws an error if the RealWorldReceivable contract is not available on the network, or if a token already exists with the same metadata URI.
140
+ */
141
+ async function createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, uri, gasOpts = {}) {
142
+ var _a, _b;
143
+ const tokenId = await getTokenIdByURI(signer, uri);
144
+ if (tokenId != null) {
145
+ throw new Error('A token already exists with this metadata, canceling mint');
146
+ }
147
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signer);
148
+ if (!chainId) {
149
+ throw new Error('No Chain Id found');
150
+ }
151
+ const poolInfo = chainId
152
+ ? (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]
153
+ : undefined;
154
+ if (!poolInfo) {
155
+ throw new Error('RealWorldReceivable is not available on this network');
156
+ }
157
+ const contract = (0, helpers_1.getRealWorldReceivableContract)(signer, chainId);
158
+ if (!contract) {
159
+ throw new Error('Could not find RealWorldReceivable contract');
160
+ }
161
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
162
+ return contract.createRealWorldReceivable(poolInfo.pool, currencyCode, receivableAmount, maturityDate, uri, gasOpts);
163
+ }
164
+ /**
165
+ * Uploads metadata onto ARWeave (or fetches the existing metadata with the same reference Id) and returns the ARWeave URL
166
+ *
167
+ * @async
168
+ * @function
169
+ * @memberof ReceivableService
170
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
171
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
172
+ * from server calls.
173
+ * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
174
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
175
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
176
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
177
+ * @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
178
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
179
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
180
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
181
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
182
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
183
+ * @returns {Promise<string>} - The ARWeave metadata URI.
184
+ */
185
+ async function uploadOrFetchMetadataURI(signerOrProvider, privateKey, chainId, poolName, poolType, metadata, referenceId, extraTags, lazyFund = true) {
186
+ if (typeof metadata !== 'object' || Array.isArray(metadata)) {
187
+ throw new Error('Input must be a JSON object.');
188
+ }
189
+ // Check to see if metadata with referenceId has already been minted
190
+ const signer = signerOrProvider instanceof providers_1.Web3Provider
191
+ ? signerOrProvider.getSigner()
192
+ : signerOrProvider;
193
+ const signerAddress = await signer.getAddress();
194
+ const dataId = await ARWeaveService_1.ARWeaveService.queryForMetadata(chainId, signerAddress, referenceId);
195
+ const config = ARWeaveService_1.ARWeaveService.getBundlrNetworkConfig(chainId);
196
+ let arweaveId;
197
+ if (dataId != null) {
198
+ console.log(`Metadata already exists with this reference Id, returning existing data ==> ${ARWeaveService_1.ARWeaveService.getURIFromARWeaveId(dataId)}`);
199
+ arweaveId = dataId;
200
+ }
201
+ else {
202
+ const tags = [
203
+ { name: 'Content-Type', value: 'application/json' },
204
+ { name: 'appName', value: 'HumaFinance' },
205
+ { name: 'poolName', value: poolName },
206
+ { name: 'poolType', value: poolType },
207
+ { name: 'referenceId', value: referenceId },
208
+ ...extraTags,
209
+ ];
210
+ // Append referenceId to metadata (if it's not already there)
211
+ if (!Object.prototype.hasOwnProperty.call(metadata, 'referenceId')) {
212
+ metadata.referenceId = referenceId;
213
+ }
214
+ const response = await ARWeaveService_1.ARWeaveService.storeData(config, signerOrProvider instanceof providers_1.Web3Provider ? signerOrProvider : privateKey, metadata, tags, lazyFund);
215
+ arweaveId = response.id;
216
+ console.log(`Data uploaded ==> ${ARWeaveService_1.ARWeaveService.getURIFromARWeaveId(arweaveId)}`);
217
+ }
218
+ return ARWeaveService_1.ARWeaveService.getURIFromARWeaveId(arweaveId);
219
+ }
220
+ /**
221
+ * Creates a RealWorldReceivable token with metadata uploaded onto ARWeave
222
+ *
223
+ * @async
224
+ * @function
225
+ * @memberof ReceivableService
226
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
227
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
228
+ * from server calls.
229
+ * @param {string | null} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
230
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
231
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
232
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
233
+ * @param {number} currencyCode - The ISO 4217 currency code that the receivable is denominated in
234
+ * @param {number} receivableAmount - The receivable amount.
235
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
236
+ * @param {Record<string, any>} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
237
+ * @param {string} referenceId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
238
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
239
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
240
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
241
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
242
+ * @param {Overrides} [gasOpts] - Optional gas overrides for the transaction.
243
+ * @returns {Promise<TransactionResponse>} - The transaction receipt.
244
+ */
245
+ async function createReceivableWithMetadata(signerOrProvider, privateKey, chainId, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadata, referenceId, extraTags, lazyFund = true, gasOpts) {
246
+ if (typeof metadata !== 'object' || Array.isArray(metadata)) {
247
+ throw new Error('Input must be a JSON object.');
248
+ }
249
+ // Check to see if metadata with referenceId has already been minted
250
+ const signer = signerOrProvider instanceof providers_1.Web3Provider
251
+ ? signerOrProvider.getSigner()
252
+ : signerOrProvider;
253
+ const metadataURI = await uploadOrFetchMetadataURI(signerOrProvider, privateKey, chainId, poolName, poolType, metadata, referenceId, extraTags, lazyFund);
254
+ return createReceivable(signer, poolName, poolType, currencyCode, receivableAmount, maturityDate, metadataURI, gasOpts);
255
+ }
256
+ /**
257
+ * Loads all RWRs belonging to the specified owner, including the RWR metadata
258
+ *
259
+ * @async
260
+ * @function
261
+ * @memberof ReceivableService
262
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
263
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
264
+ * from server calls.
265
+ * @param {string} owner - The receivable token owner to query from.
266
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
267
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
268
+ * @param {Pagination} pagination - The pagination option.
269
+ * @returns {Promise<RealWorldReceivableInfo[]>} - An array of receivables owned by the owner for the pool.
270
+ */
271
+ async function loadReceivablesOfOwnerWithMetadata(signerOrProvider, owner, poolName, poolType, pagination) {
272
+ if (!ethers_1.ethers.utils.isAddress(owner)) {
273
+ throw new Error('Invalid owner address');
274
+ }
275
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signerOrProvider);
276
+ if (!chainId) {
277
+ throw new Error('No Chain Id found');
278
+ }
279
+ const rwReceivablesBase = await SubgraphService_1.SubgraphService.getRWReceivableInfo(owner, chainId, poolName, poolType, pagination);
280
+ const fetchMetadata = async (rwrInfoBase) => ARWeaveService_1.ARWeaveService.fetchMetadataFromUrl(rwrInfoBase.tokenURI);
281
+ const metadatas = await Promise.all(rwReceivablesBase.map(fetchMetadata));
282
+ return rwReceivablesBase.map((rwrInfoBase, index) => (Object.assign(Object.assign({}, rwrInfoBase), { metadata: metadatas[index] })));
283
+ }
284
+ /**
285
+ * Get the total count of all RWRs belonging to the specified owner
286
+ *
287
+ * @async
288
+ * @function
289
+ * @memberof ReceivableService
290
+ * @param {Web3Provider | ethers.Signer} signerOrProvider - If calling this function from a browser, this function expects a Web3Provider.
291
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
292
+ * from server calls.
293
+ * @param {string} owner - The receivable token owner to query from.
294
+ * @returns {Promise<number>} - Total count of receivables owned by the owner for the pool.
295
+ */
296
+ async function getTotalCountOfReceivables(signerOrProvider, owner) {
297
+ if (!ethers_1.ethers.utils.isAddress(owner)) {
298
+ throw new Error('Invalid owner address');
299
+ }
300
+ const chainId = await (0, utils_1.getChainIdFromSignerOrProvider)(signerOrProvider);
301
+ if (!chainId) {
302
+ throw new Error('No Chain Id found');
303
+ }
304
+ const rwrContract = (0, helpers_1.getRealWorldReceivableContract)(signerOrProvider, chainId);
305
+ if (!rwrContract) {
306
+ throw new Error('Could not find RealWorldReceivable contract');
307
+ }
308
+ const balance = await rwrContract.balanceOf(owner);
309
+ return balance.toNumber();
310
+ }
311
+ /**
312
+ * An object that contains functions to interact with Huma's receivables.
313
+ * @namespace ReceivableService
314
+ */
315
+ exports.ReceivableService = {
316
+ createReceivableWithMetadata,
317
+ createReceivable,
318
+ declareReceivablePaymentByTokenId,
319
+ declareReceivablePaymentByReferenceId,
320
+ loadReceivablesOfOwnerWithMetadata,
321
+ getTotalCountOfReceivables,
322
+ uploadOrFetchMetadataURI,
323
+ getTokenIdByURI,
324
+ };
325
+ //# sourceMappingURL=ReceivableService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;AAAA,wDAA4E;AAC5E,mCAAwD;AACxD,iDAS6B;AAC7B,qDAA8C;AAE9C,qDAAiD;AACjD,wCAA2D;AAC3D,oCAA+E;AAE/E,uDAA+D;AAE/D;;;;;;;;;GASG;AACH,KAAK,UAAU,eAAe,CAC5B,MAAqB,EACrB,GAAkB;;IAElB,IAAI,GAAG,KAAK,IAAI,EAAE;QAChB,OAAO,IAAI,CAAA;KACZ;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAC5D,MAAM,aAAa,GAAG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,0BAA0B,CACvC,gBAA8C,EAC9C,KAAa;IAEb,IAAI,CAAC,eAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;KACzC;IAED,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,gBAAgB,CAAC,CAAA;IACtE,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACrC;IAED,MAAM,WAAW,GAAG,IAAA,wCAA8B,EAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;IAC7E,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;KAC/D;IAED,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAClD,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAA;AAC3B,CAAC;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG;IAC/B,4BAA4B;IAC5B,gBAAgB;IAChB,iCAAiC;IACjC,qCAAqC;IACrC,kCAAkC;IAClC,0BAA0B;IAC1B,wBAAwB;IACxB,eAAe;CAChB,CAAA"}
@@ -0,0 +1,76 @@
1
+ import { POOL_NAME, POOL_TYPE, RealWorldReceivableInfoBase } from '@huma-finance/shared';
2
+ /**
3
+ * Represents the payload of a credit event.
4
+ * @typedef {Object} CreditEventPayload
5
+ */
6
+ export type CreditEventPayload = {
7
+ amount?: string;
8
+ timestamp?: string;
9
+ owner?: string;
10
+ pool?: string;
11
+ event?: string;
12
+ };
13
+ /**
14
+ * Represents the pagination options for a query.
15
+ * @typedef {Object} Pagination
16
+ */
17
+ export type Pagination = {
18
+ first: number | null;
19
+ skip: number | null;
20
+ orderBy: string;
21
+ orderDirection: 'desc' | 'asc';
22
+ };
23
+ /**
24
+ * Returns the subgraph URL for a given chain ID.
25
+ *
26
+ * @memberof SubgraphService
27
+ * @param {number} chainId - The ID of the chain.
28
+ * @returns {string} The subgraph URL for the given chain ID.
29
+ */
30
+ declare function getSubgraphUrlForChainId(chainId: number): string;
31
+ /**
32
+ * Returns the credit events for a given user.
33
+ *
34
+ * @memberof SubgraphService
35
+ * @param {string} userAddress - The address of the user.
36
+ * @param {number} chainId - The ID of the chain.
37
+ * @param {POOL_NAME} poolName - The name of the pool.
38
+ * @param {POOL_TYPE} poolType - The type of the pool.
39
+ * @param {number[]} event - The event types to filter by.
40
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
41
+ */
42
+ declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: number[]): Promise<CreditEventPayload[]>;
43
+ /**
44
+ * Returns the last factorized amount for a given user and pool.
45
+ *
46
+ * @memberof SubgraphService
47
+ * @param {string} userAddress - The address of the user.
48
+ * @param {number} chainId - The ID of the chain.
49
+ * @param {POOL_NAME} poolName - The name of the pool.
50
+ * @param {POOL_TYPE} poolType - The type of the pool.
51
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
52
+ */
53
+ declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
54
+ /**
55
+ * Returns the paginated real world receivables' info.
56
+ *
57
+ * @memberof SubgraphService
58
+ * @param {string} userAddress - The address of the user.
59
+ * @param {number} chainId - The ID of the chain.
60
+ * @param {POOL_NAME} poolName - The name of the pool.
61
+ * @param {POOL_TYPE} poolType - The type of the pool.
62
+ * @param {Pagination} pagination - The pagination option.
63
+ * @returns {Promise<RealWorldReceivableInfoBase>} The paginated real world receivables' info.
64
+ */
65
+ declare function getRWReceivableInfo(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, pagination?: Pagination): Promise<RealWorldReceivableInfoBase[]>;
66
+ /**
67
+ * An object that contains functions to interact with Huma's Subgraph storage.
68
+ * @namespace SubgraphService
69
+ */
70
+ export declare const SubgraphService: {
71
+ getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
72
+ getCreditEventsForUser: typeof getCreditEventsForUser;
73
+ getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
74
+ getRWReceivableInfo: typeof getRWReceivableInfo;
75
+ };
76
+ export {};