@huma-finance/sdk 0.0.6-alpha.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 (115) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.d.ts +9 -0
  4. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js +21 -0
  5. package/dist/cjs/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
  6. package/dist/cjs/helpers/index.d.ts +1 -0
  7. package/dist/cjs/helpers/index.js +5 -0
  8. package/dist/cjs/helpers/index.js.map +1 -0
  9. package/dist/cjs/hooks/index.d.ts +5 -0
  10. package/dist/cjs/hooks/index.js +9 -0
  11. package/dist/cjs/hooks/index.js.map +1 -0
  12. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.d.ts +9 -0
  13. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js +19 -0
  14. package/dist/cjs/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
  15. package/dist/cjs/hooks/useContract.d.ts +11 -0
  16. package/dist/cjs/hooks/useContract.js +29 -0
  17. package/dist/cjs/hooks/useContract.js.map +1 -0
  18. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  19. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +24 -0
  20. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  21. package/dist/cjs/hooks/usePoolContract.d.ts +53 -0
  22. package/dist/cjs/hooks/usePoolContract.js +49 -0
  23. package/dist/cjs/hooks/usePoolContract.js.map +1 -0
  24. package/dist/cjs/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
  25. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js +17 -0
  26. package/dist/cjs/hooks/useReceivableFactoringPoolContract.js.map +1 -0
  27. package/dist/cjs/index.d.ts +4 -0
  28. package/dist/cjs/index.js +8 -0
  29. package/dist/cjs/index.js.map +1 -0
  30. package/dist/cjs/services/ARWeaveService.d.ts +62 -0
  31. package/dist/cjs/services/ARWeaveService.js +141 -0
  32. package/dist/cjs/services/ARWeaveService.js.map +1 -0
  33. package/dist/cjs/services/EAService.d.ts +13 -0
  34. package/dist/cjs/services/EAService.js +17 -0
  35. package/dist/cjs/services/EAService.js.map +1 -0
  36. package/dist/cjs/services/ReceivableService.d.ts +76 -0
  37. package/dist/cjs/services/ReceivableService.js +156 -0
  38. package/dist/cjs/services/ReceivableService.js.map +1 -0
  39. package/dist/cjs/services/SubgraphService.d.ts +39 -0
  40. package/dist/cjs/services/SubgraphService.js +92 -0
  41. package/dist/cjs/services/SubgraphService.js.map +1 -0
  42. package/dist/cjs/services/index.d.ts +4 -0
  43. package/dist/cjs/services/index.js +8 -0
  44. package/dist/cjs/services/index.js.map +1 -0
  45. package/dist/cjs/utils/chain.d.ts +14 -0
  46. package/dist/cjs/utils/chain.js +34 -0
  47. package/dist/cjs/utils/chain.js.map +1 -0
  48. package/dist/cjs/utils/index.d.ts +3 -0
  49. package/dist/cjs/utils/index.js +7 -0
  50. package/dist/cjs/utils/index.js.map +1 -0
  51. package/dist/cjs/utils/poolInfo.d.ts +9 -0
  52. package/dist/cjs/utils/poolInfo.js +14 -0
  53. package/dist/cjs/utils/poolInfo.js.map +1 -0
  54. package/dist/cjs/utils/web3.d.ts +4 -0
  55. package/dist/cjs/utils/web3.js +29 -0
  56. package/dist/cjs/utils/web3.js.map +1 -0
  57. package/dist/helpers/BaseCreditPoolReceivableContractHelper.d.ts +9 -0
  58. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js +17 -0
  59. package/dist/helpers/BaseCreditPoolReceivableContractHelper.js.map +1 -0
  60. package/dist/helpers/index.d.ts +1 -0
  61. package/dist/helpers/index.js +2 -0
  62. package/dist/helpers/index.js.map +1 -0
  63. package/dist/hooks/index.d.ts +5 -0
  64. package/dist/hooks/index.js +6 -0
  65. package/dist/hooks/index.js.map +1 -0
  66. package/dist/hooks/useBaseCreditPoolReceivableContract.d.ts +9 -0
  67. package/dist/hooks/useBaseCreditPoolReceivableContract.js +15 -0
  68. package/dist/hooks/useBaseCreditPoolReceivableContract.js.map +1 -0
  69. package/dist/hooks/useContract.d.ts +11 -0
  70. package/dist/hooks/useContract.js +25 -0
  71. package/dist/hooks/useContract.js.map +1 -0
  72. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  73. package/dist/hooks/useERC20TransferableReceivableContract.js +20 -0
  74. package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  75. package/dist/hooks/usePool.d.ts +0 -0
  76. package/dist/hooks/usePool.js +2 -0
  77. package/dist/hooks/usePool.js.map +1 -0
  78. package/dist/hooks/usePoolContract.d.ts +53 -0
  79. package/dist/hooks/usePoolContract.js +44 -0
  80. package/dist/hooks/usePoolContract.js.map +1 -0
  81. package/dist/hooks/useReceivableFactoringPoolContract.d.ts +10 -0
  82. package/dist/hooks/useReceivableFactoringPoolContract.js +13 -0
  83. package/dist/hooks/useReceivableFactoringPoolContract.js.map +1 -0
  84. package/dist/index.d.ts +4 -0
  85. package/dist/index.js +5 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/services/ARWeaveService.d.ts +62 -0
  88. package/dist/services/ARWeaveService.js +133 -0
  89. package/dist/services/ARWeaveService.js.map +1 -0
  90. package/dist/services/EAService.d.ts +13 -0
  91. package/dist/services/EAService.js +14 -0
  92. package/dist/services/EAService.js.map +1 -0
  93. package/dist/services/ReceivableService.d.ts +76 -0
  94. package/dist/services/ReceivableService.js +149 -0
  95. package/dist/services/ReceivableService.js.map +1 -0
  96. package/dist/services/SubgraphService.d.ts +39 -0
  97. package/dist/services/SubgraphService.js +86 -0
  98. package/dist/services/SubgraphService.js.map +1 -0
  99. package/dist/services/index.d.ts +4 -0
  100. package/dist/services/index.js +5 -0
  101. package/dist/services/index.js.map +1 -0
  102. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  103. package/dist/utils/chain.d.ts +14 -0
  104. package/dist/utils/chain.js +29 -0
  105. package/dist/utils/chain.js.map +1 -0
  106. package/dist/utils/index.d.ts +3 -0
  107. package/dist/utils/index.js +4 -0
  108. package/dist/utils/index.js.map +1 -0
  109. package/dist/utils/poolInfo.d.ts +9 -0
  110. package/dist/utils/poolInfo.js +10 -0
  111. package/dist/utils/poolInfo.js.map +1 -0
  112. package/dist/utils/web3.d.ts +4 -0
  113. package/dist/utils/web3.js +24 -0
  114. package/dist/utils/web3.js.map +1 -0
  115. package/package.json +86 -0
@@ -0,0 +1,76 @@
1
+ import { TransactionReceipt, TransactionResponse, Web3Provider } from '@ethersproject/providers';
2
+ import { BigNumberish, ethers } from 'ethers';
3
+ import { POOL_NAME, POOL_TYPE } from '@00labs/huma-shared';
4
+ /**
5
+ * Enumeration of payment methods. Maps to the PaymentMethod enum in the BaseCreditPoolReceivable contract.
6
+ * Declarative payment methods are those that do not actually send ERC20 funds. Payable payment methods are those that
7
+ * do by calling makePayment on the BaseCreditPool contract.
8
+ * @enum {number}
9
+ */
10
+ export declare enum PaymentMethod {
11
+ Declarative = 0,
12
+ Payable = 1
13
+ }
14
+ /**
15
+ * Pays a BaseCreditPoolReceivable using the specified payment method, given an internalId mapping to the receivable's metadata
16
+ *
17
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
18
+ * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
19
+ * @param {number} paymentAmount - The amount to pay the receivable.
20
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
21
+ * @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
22
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
23
+ */
24
+ export declare function payReceivableByInternalId(signer: ethers.Signer, internalId: string, paymentAmount: number, paymentMethod: PaymentMethod): Promise<TransactionReceipt>;
25
+ /**
26
+ * Pays a BaseCreditPoolReceivable using the specified payment method, given a tokenID of the receivable.
27
+ *
28
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
29
+ * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
30
+ * @param {number} paymentAmount - The amount to pay the receivable.
31
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
32
+ * @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
33
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
34
+ */
35
+ export declare function payReceivableByTokenId(signer: ethers.Signer, receivableTokenId: BigNumberish, paymentAmount: number, paymentMethod: PaymentMethod): Promise<TransactionReceipt>;
36
+ /**
37
+ * Mints a new BaseCreditPoolReceivable token on the given chain of the signer
38
+ *
39
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
40
+ * @param {string} recipient - The address of the recipient of the receivable token.
41
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
42
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
43
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
44
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
45
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
46
+ * @param {string} uri - The URI of the receivable token metadata.
47
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
48
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
49
+ */
50
+ export declare function mintReceivable(signer: ethers.Signer, recipient: string, poolName: POOL_NAME, poolType: POOL_TYPE, receivableAmount: number, maturityDate: number, paymentMethod: PaymentMethod, uri: string): Promise<TransactionResponse>;
51
+ /**
52
+ * Mints a BaseCreditPoolReceivable token with metadata uploaded onto ARWeave
53
+ *
54
+ * @param {Web3Provider | ethers.Signer} wallet - If calling this function from a browser, this function expects a Web3Provider.
55
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
56
+ * from server calls.
57
+ * @param {string} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
58
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
59
+ * @param {string} recipient - The receivable token recipient.
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} receivableAmount - The receivable amount.
63
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
64
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
65
+ * @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
66
+ * @param {number} internalId - 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
+ * @returns {Promise<TransactionReceipt>} - The transaction receipt.
72
+ */
73
+ export declare function mintReceivableWithMetadata(wallet: Web3Provider | ethers.Signer, privateKey: string, chainId: number, recipient: string, poolName: POOL_NAME, poolType: POOL_TYPE, receivableAmount: number, maturityDate: number, paymentMethod: PaymentMethod, metadata: JSON, internalId: string, extraTags: {
74
+ name: string;
75
+ value: string;
76
+ }[], lazyFund?: boolean): Promise<TransactionReceipt>;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mintReceivableWithMetadata = exports.mintReceivable = exports.payReceivableByTokenId = exports.payReceivableByInternalId = exports.PaymentMethod = void 0;
4
+ const providers_1 = require("@ethersproject/providers");
5
+ const huma_shared_1 = require("@00labs/huma-shared");
6
+ const utils_1 = require("../utils");
7
+ const ARWeaveService_1 = require("./ARWeaveService");
8
+ const chain_1 = require("../utils/chain");
9
+ /**
10
+ * Enumeration of payment methods. Maps to the PaymentMethod enum in the BaseCreditPoolReceivable contract.
11
+ * Declarative payment methods are those that do not actually send ERC20 funds. Payable payment methods are those that
12
+ * do by calling makePayment on the BaseCreditPool contract.
13
+ * @enum {number}
14
+ */
15
+ var PaymentMethod;
16
+ (function (PaymentMethod) {
17
+ PaymentMethod[PaymentMethod["Declarative"] = 0] = "Declarative";
18
+ PaymentMethod[PaymentMethod["Payable"] = 1] = "Payable";
19
+ })(PaymentMethod = exports.PaymentMethod || (exports.PaymentMethod = {}));
20
+ /**
21
+ * Pays a BaseCreditPoolReceivable using the specified payment method, given an internalId mapping to the receivable's metadata
22
+ *
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 {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
27
+ * @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
28
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
29
+ */
30
+ async function payReceivableByInternalId(
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ signer,
33
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
34
+ internalId,
35
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
+ paymentAmount,
37
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ paymentMethod) {
39
+ throw new Error('Not implemented');
40
+ }
41
+ exports.payReceivableByInternalId = payReceivableByInternalId;
42
+ /**
43
+ * Pays a BaseCreditPoolReceivable using the specified payment method, given a tokenID of the receivable.
44
+ *
45
+ * @param {ethers.Signer} signer - The signer used to send the transaction. Note only the receivable owner can pay the receivable.
46
+ * @param {BigNumberish} receivableTokenId - The ID of the receivable token to pay.
47
+ * @param {number} paymentAmount - The amount to pay the receivable.
48
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
49
+ * @returns {Promise<TransactionReceipt>} - A Promise of the transaction receipt.
50
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
51
+ */
52
+ async function payReceivableByTokenId(signer, receivableTokenId, paymentAmount, paymentMethod) {
53
+ var _a;
54
+ const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
55
+ const baseCreditPoolReceivable = chainId
56
+ ? (_a = huma_shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[huma_shared_1.SupplementaryContracts.BaseCreditPoolReceivable]
57
+ : null;
58
+ if (!baseCreditPoolReceivable) {
59
+ throw new Error('BaseCreditPoolReceivable is not available on this network');
60
+ }
61
+ const contract = (0, utils_1.getContract)(baseCreditPoolReceivable, huma_shared_1.BASE_CREDIT_POOL_RECEIVABLE_ABI, signer);
62
+ if (!contract) {
63
+ throw new Error('Could not find BaseCreditPoolReceivable contract');
64
+ }
65
+ let tx;
66
+ switch (paymentMethod) {
67
+ case PaymentMethod.Declarative:
68
+ tx = await contract.declarePayment(receivableTokenId, paymentAmount);
69
+ break;
70
+ case PaymentMethod.Payable:
71
+ tx = await contract.makePayment(receivableTokenId, paymentAmount);
72
+ break;
73
+ default:
74
+ throw new Error('Invalid payment method');
75
+ }
76
+ return tx.wait();
77
+ }
78
+ exports.payReceivableByTokenId = payReceivableByTokenId;
79
+ /**
80
+ * Mints a new BaseCreditPoolReceivable token on the given chain of the signer
81
+ *
82
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
83
+ * @param {string} recipient - The address of the recipient of the receivable token.
84
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
85
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
86
+ * @param {number} receivableAmount - The amount of the receivable token to mint.
87
+ * @param {number} maturityDate - The maturity date of the receivable token, in UNIX timestamp format.
88
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
89
+ * @param {string} uri - The URI of the receivable token metadata.
90
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
91
+ * @throws {Error} - Throws an error if the BaseCreditPoolReceivable contract is not available on the network.
92
+ */
93
+ async function mintReceivable(signer, recipient, poolName, poolType, receivableAmount, maturityDate, paymentMethod, uri) {
94
+ var _a, _b, _c;
95
+ const chainId = await (0, chain_1.getChainIdFromSignerOrProvider)(signer);
96
+ const baseCreditPoolReceivable = chainId
97
+ ? (_a = huma_shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[huma_shared_1.SupplementaryContracts.BaseCreditPoolReceivable]
98
+ : null;
99
+ const poolInfo = chainId
100
+ ? (_c = (_b = huma_shared_1.PoolContractMap[chainId]) === null || _b === void 0 ? void 0 : _b[poolType]) === null || _c === void 0 ? void 0 : _c[poolName]
101
+ : undefined;
102
+ if (!baseCreditPoolReceivable || !poolInfo) {
103
+ throw new Error('BaseCreditPoolReceivable is not available on this network');
104
+ }
105
+ const contract = (0, utils_1.getContract)(baseCreditPoolReceivable, huma_shared_1.BASE_CREDIT_POOL_RECEIVABLE_ABI, signer);
106
+ if (!contract) {
107
+ throw new Error('Could not find BaseCreditPoolReceivable contract');
108
+ }
109
+ return contract.safeMint(recipient, poolInfo.pool, poolInfo.poolUnderlyingToken.address, receivableAmount, maturityDate, paymentMethod, uri);
110
+ }
111
+ exports.mintReceivable = mintReceivable;
112
+ /**
113
+ * Mints a BaseCreditPoolReceivable token with metadata uploaded onto ARWeave
114
+ *
115
+ * @param {Web3Provider | ethers.Signer} wallet - If calling this function from a browser, this function expects a Web3Provider.
116
+ * If calling this function from a server, this function expects an ethers Signer. Note that privateKey only needs to be included
117
+ * from server calls.
118
+ * @param {string} privateKey - Private key of the wallet used to upload metadata to ARWeave. Only required if calling this function from a server.
119
+ * @param {number} chainId - The chain ID to mint the receivable token on and pay ARWeave funds from.
120
+ * @param {string} recipient - The receivable token recipient.
121
+ * @param {POOL_NAME} poolName - The pool name. Used to lookup the pool address to pay to.
122
+ * @param {POOL_TYPE} poolType - The pool type. Used to lookup the pool address to pay to.
123
+ * @param {number} receivableAmount - The receivable amount.
124
+ * @param {number} maturityDate - The maturity date of the receivable, in UNIX timestamp format.
125
+ * @param {PaymentMethod} paymentMethod - The payment method to use. See PaymentMethod for more details.
126
+ * @param {JSON} metadata - The metadata in JSON format. This will be uploaded onto ARWeave
127
+ * @param {number} internalId - An internal identifier value added as a tag on ARWeave, for easily querying the metadata later.
128
+ * @param {Array<{ name: string, value: string }>} extraTags - Any extraTags you'd like to tag your metadata with. Note that metadata on
129
+ * ARWeave is indexed by these tags, so make sure to include any tags that you'd like to be able to query by.
130
+ * @param {boolean} [lazyFund=true] - Whether to lazy fund the ARWeave uploads. If true, the ARWeave uploads will be paid for by the
131
+ * metadata uploader immediately before uploading. If false, the ARWeave node must be pre-funded before calling this function.
132
+ * @returns {Promise<TransactionReceipt>} - The transaction receipt.
133
+ */
134
+ async function mintReceivableWithMetadata(wallet, privateKey, chainId, recipient, poolName, poolType, receivableAmount, maturityDate, paymentMethod, metadata, internalId, extraTags, lazyFund = true) {
135
+ const config = (0, ARWeaveService_1.getBundlrNetworkConfig)(chainId);
136
+ try {
137
+ const tags = [
138
+ { name: 'Content-Type', value: 'application/json' },
139
+ { name: 'appName', value: 'HumaFinance' },
140
+ { name: 'poolName', value: poolName },
141
+ { name: 'poolType', value: poolType },
142
+ { name: 'internalId', value: internalId },
143
+ ...extraTags,
144
+ ];
145
+ const response = await (0, ARWeaveService_1.storeData)(config, wallet instanceof providers_1.Web3Provider ? wallet : privateKey, metadata, tags, lazyFund);
146
+ console.log(`Data uploaded ==> https://arweave.net/${response.id}`);
147
+ const tx = await mintReceivable(wallet instanceof providers_1.Web3Provider ? wallet.getSigner() : wallet, recipient, poolName, poolType, receivableAmount, maturityDate, paymentMethod, `https://arweave.net/${response.id}`);
148
+ return await tx.wait();
149
+ }
150
+ catch (e) {
151
+ console.error(e);
152
+ throw e;
153
+ }
154
+ }
155
+ exports.mintReceivableWithMetadata = mintReceivableWithMetadata;
156
+ //# sourceMappingURL=ReceivableService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReceivableService.js","sourceRoot":"","sources":["../../../src/services/ReceivableService.ts"],"names":[],"mappings":";;;AAAA,wDAIiC;AAEjC,qDAO4B;AAE5B,oCAAsC;AACtC,qDAAoE;AACpE,0CAA+D;AAE/D;;;;;GAKG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,+DAAe,CAAA;IACf,uDAAW,CAAA;AACb,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,yBAAyB;AAC7C,6DAA6D;AAC7D,MAAqB;AACrB,6DAA6D;AAC7D,UAAkB;AAClB,6DAA6D;AAC7D,aAAqB;AACrB,6DAA6D;AAC7D,aAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;AACpC,CAAC;AAXD,8DAWC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,sBAAsB,CAC1C,MAAqB,EACrB,iBAA+B,EAC/B,aAAqB,EACrB,aAA4B;;IAE5B,MAAM,OAAO,GAAG,MAAM,IAAA,sCAA8B,EAAC,MAAM,CAAC,CAAA;IAE5D,MAAM,wBAAwB,GAAG,OAAO;QACtC,CAAC,CAAC,MAAA,uCAAyB,CAAC,OAAO,CAAC,0CAChC,oCAAsB,CAAC,wBAAwB,CAChD;QACH,CAAC,CAAC,IAAI,CAAA;IAER,IAAI,CAAC,wBAAwB,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;KAC7E;IAED,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAC1B,wBAAwB,EACxB,6CAA+B,EAC/B,MAAM,CACP,CAAA;IAED,IAAI,CAAC,QAAQ,EAAE;QACb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AY,wBAAY,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,MAAM,EAC5D,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,uBAAuB,QAAQ,CAAC,EAAE,EAAE,CACrC,CAAA;QAED,OAAO,MAAM,EAAE,CAAC,IAAI,EAAE,CAAA;KACvB;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QAChB,MAAM,CAAC,CAAA;KACR;AACH,CAAC;AApDD,gEAoDC"}
@@ -0,0 +1,39 @@
1
+ import { POOL_NAME, POOL_TYPE } from '@00labs/huma-shared';
2
+ /**
3
+ * Returns the subgraph URL for a given chain ID.
4
+ *
5
+ * @param {number} chainId - The ID of the chain.
6
+ * @returns {string} The subgraph URL for the given chain ID.
7
+ */
8
+ export declare function getSubgraphUrlForChainId(chainId: number): string;
9
+ /**
10
+ * Represents the payload of a credit event.
11
+ */
12
+ export type CreditEventPayload = {
13
+ amount?: string;
14
+ timestamp?: string;
15
+ owner?: string;
16
+ pool?: string;
17
+ event?: string;
18
+ };
19
+ /**
20
+ * Returns the credit events for a given user.
21
+ *
22
+ * @param {string} userAddress - The address of the user.
23
+ * @param {number} chainId - The ID of the chain.
24
+ * @param {POOL_NAME} poolName - The name of the pool.
25
+ * @param {POOL_TYPE} poolType - The type of the pool.
26
+ * @param {string[]} event - The event types to filter by.
27
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
28
+ */
29
+ export declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: string[]): Promise<CreditEventPayload[]>;
30
+ /**
31
+ * Returns the last factorized amount for a given user and pool.
32
+ *
33
+ * @param {string} userAddress - The address of the user.
34
+ * @param {number} chainId - The ID of the chain.
35
+ * @param {POOL_NAME} poolName - The name of the pool.
36
+ * @param {POOL_TYPE} poolType - The type of the pool.
37
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
38
+ */
39
+ export declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLastFactorizedAmountFromPool = exports.getCreditEventsForUser = exports.getSubgraphUrlForChainId = void 0;
4
+ const huma_shared_1 = require("@00labs/huma-shared");
5
+ /**
6
+ * Returns the subgraph URL for a given chain ID.
7
+ *
8
+ * @param {number} chainId - The ID of the chain.
9
+ * @returns {string} The subgraph URL for the given chain ID.
10
+ */
11
+ function getSubgraphUrlForChainId(chainId) {
12
+ switch (chainId) {
13
+ case 5:
14
+ return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
15
+ case 137:
16
+ return 'https://api.thegraph.com/subgraphs/name/00labs/huma-polygon';
17
+ case 80001:
18
+ return 'https://api.thegraph.com/subgraphs/name/00labs/huma-mumbai';
19
+ default:
20
+ return '';
21
+ }
22
+ }
23
+ exports.getSubgraphUrlForChainId = getSubgraphUrlForChainId;
24
+ /**
25
+ * Returns the credit events for a given user.
26
+ *
27
+ * @param {string} userAddress - The address of the user.
28
+ * @param {number} chainId - The ID of the chain.
29
+ * @param {POOL_NAME} poolName - The name of the pool.
30
+ * @param {POOL_TYPE} poolType - The type of the pool.
31
+ * @param {string[]} event - The event types to filter by.
32
+ * @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
33
+ */
34
+ function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
35
+ var _a, _b, _c;
36
+ const url = getSubgraphUrlForChainId(chainId);
37
+ if (!url) {
38
+ return Promise.resolve([]);
39
+ }
40
+ const poolAddress = (_c = (_b = (_a = huma_shared_1.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;
41
+ const query = `
42
+ query {
43
+ creditEvents(
44
+ where: {
45
+ owner: "${userAddress}",
46
+ pool: "${poolAddress}",
47
+ event_in: "[${event.join('", "')}]"
48
+ }
49
+ orderBy: timestamp
50
+ orderDirection: desc
51
+ ) {
52
+ amount
53
+ timestamp
54
+ owner
55
+ pool
56
+ event
57
+ }
58
+ }
59
+ `;
60
+ return fetch(url, {
61
+ method: 'POST',
62
+ headers: {
63
+ 'Content-Type': 'application/json',
64
+ },
65
+ body: JSON.stringify({ query }),
66
+ })
67
+ .then((res) => res.json())
68
+ .then((res) => {
69
+ if (res.errors) {
70
+ console.error(res.errors);
71
+ return [];
72
+ }
73
+ return res.data.creditEvents;
74
+ });
75
+ }
76
+ exports.getCreditEventsForUser = getCreditEventsForUser;
77
+ /**
78
+ * Returns the last factorized amount for a given user and pool.
79
+ *
80
+ * @param {string} userAddress - The address of the user.
81
+ * @param {number} chainId - The ID of the chain.
82
+ * @param {POOL_NAME} poolName - The name of the pool.
83
+ * @param {POOL_TYPE} poolType - The type of the pool.
84
+ * @returns {Promise<number>} The last factorized amount for the given user and pool.
85
+ */
86
+ function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
87
+ return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
88
+ huma_shared_1.CreditEvent.DrawdownMadeWithReceivable.toString(),
89
+ ]).then((events) => Number(events[0].amount));
90
+ }
91
+ exports.getLastFactorizedAmountFromPool = getLastFactorizedAmountFromPool;
92
+ //# sourceMappingURL=SubgraphService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SubgraphService.js","sourceRoot":"","sources":["../../../src/services/SubgraphService.ts"],"names":[],"mappings":";;;AAAA,qDAK4B;AAE5B;;;;;GAKG;AACH,SAAgB,wBAAwB,CAAC,OAAe;IACtD,QAAQ,OAAO,EAAE;QACf,KAAK,CAAC;YACJ,OAAO,4DAA4D,CAAA;QACrE,KAAK,GAAG;YACN,OAAO,6DAA6D,CAAA;QACtE,KAAK,KAAK;YACR,OAAO,4DAA4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EAAE,QAAQ,EAAE,QAAQ,EAAE;QACtE,yBAAW,CAAC,0BAA0B,CAAC,QAAQ,EAAE;KAClD,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;AAC/C,CAAC;AATD,0EASC"}
@@ -0,0 +1,4 @@
1
+ export * from './ARWeaveService';
2
+ export * from './EAService';
3
+ export * from './SubgraphService';
4
+ export * from './ReceivableService';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./ARWeaveService"), exports);
5
+ tslib_1.__exportStar(require("./EAService"), exports);
6
+ tslib_1.__exportStar(require("./SubgraphService"), exports);
7
+ tslib_1.__exportStar(require("./ReceivableService"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgC;AAChC,sDAA2B;AAC3B,4DAAiC;AACjC,8DAAmC"}
@@ -0,0 +1,14 @@
1
+ import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers';
2
+ import { ethers } from 'ethers';
3
+ /**
4
+ * Get the chain ID from a signer or provider object.
5
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to get the chain ID from.
6
+ * @returns {number} - The chain ID.
7
+ */
8
+ export declare function getChainIdFromJsonSignerOrProvider(signerOrProvider: JsonRpcProvider | JsonRpcSigner): number;
9
+ /**
10
+ * Get the chain ID from a signer or provider object.
11
+ * @param {ethers.provider.Provider | ethers.Signer} signerOrProvider - The signer or provider object to get the chain ID from.
12
+ * @returns {number} - The chain ID.
13
+ */
14
+ export declare function getChainIdFromSignerOrProvider(signerOrProvider: ethers.providers.Provider | ethers.Signer): Promise<number | undefined>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChainIdFromSignerOrProvider = exports.getChainIdFromJsonSignerOrProvider = void 0;
4
+ const providers_1 = require("@ethersproject/providers");
5
+ const ethers_1 = require("ethers");
6
+ /**
7
+ * Get the chain ID from a signer or provider object.
8
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to get the chain ID from.
9
+ * @returns {number} - The chain ID.
10
+ */
11
+ function getChainIdFromJsonSignerOrProvider(signerOrProvider) {
12
+ return signerOrProvider instanceof providers_1.JsonRpcProvider
13
+ ? signerOrProvider.network.chainId
14
+ : signerOrProvider.provider.network.chainId;
15
+ }
16
+ exports.getChainIdFromJsonSignerOrProvider = getChainIdFromJsonSignerOrProvider;
17
+ /**
18
+ * Get the chain ID from a signer or provider object.
19
+ * @param {ethers.provider.Provider | ethers.Signer} signerOrProvider - The signer or provider object to get the chain ID from.
20
+ * @returns {number} - The chain ID.
21
+ */
22
+ async function getChainIdFromSignerOrProvider(signerOrProvider) {
23
+ var _a;
24
+ let network;
25
+ if (signerOrProvider instanceof ethers_1.ethers.providers.Provider) {
26
+ network = await signerOrProvider.getNetwork();
27
+ }
28
+ else {
29
+ network = await ((_a = signerOrProvider === null || signerOrProvider === void 0 ? void 0 : signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork());
30
+ }
31
+ return network === null || network === void 0 ? void 0 : network.chainId;
32
+ }
33
+ exports.getChainIdFromSignerOrProvider = getChainIdFromSignerOrProvider;
34
+ //# sourceMappingURL=chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/utils/chain.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;AACzE,mCAA+B;AAE/B;;;;GAIG;AACH,SAAgB,kCAAkC,CAChD,gBAAiD;IAEjD,OAAO,gBAAgB,YAAY,2BAAe;QAChD,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO;QAClC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAA;AAC/C,CAAC;AAND,gFAMC;AAED;;;;GAIG;AACI,KAAK,UAAU,8BAA8B,CAClD,gBAA2D;;IAE3D,IAAI,OAAO,CAAA;IACX,IAAI,gBAAgB,YAAY,eAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;QACzD,OAAO,GAAG,MAAM,gBAAgB,CAAC,UAAU,EAAE,CAAA;KAC9C;SAAM;QACL,OAAO,GAAG,MAAM,CAAA,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,QAAQ,0CAAE,UAAU,EAAE,CAAA,CAAA;KACzD;IAED,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAA;AACzB,CAAC;AAXD,wEAWC"}
@@ -0,0 +1,3 @@
1
+ export * from './chain';
2
+ export * from './web3';
3
+ export * from './poolInfo';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./chain"), exports);
5
+ tslib_1.__exportStar(require("./web3"), exports);
6
+ tslib_1.__exportStar(require("./poolInfo"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB;AACvB,iDAAsB;AACtB,qDAA0B"}
@@ -0,0 +1,9 @@
1
+ import { POOL_NAME, POOL_TYPE, PoolInfoType } from '@00labs/huma-shared';
2
+ /**
3
+ * Returns the pool info based on the provided pool name and type, using the same chain ID as the provider/signer given
4
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The Web3 provider or signer.
5
+ * @param {POOL_NAME} poolName - The name of the pool.
6
+ * @param {POOL_TYPE} poolType - The type of the pool.
7
+ * @returns {PoolInfoType|undefined} - The pool info or undefined if the chain ID is not supported.
8
+ */
9
+ export declare const getPoolInfo: (chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE) => PoolInfoType | undefined;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPoolInfo = void 0;
4
+ const huma_shared_1 = require("@00labs/huma-shared");
5
+ /**
6
+ * Returns the pool info based on the provided pool name and type, using the same chain ID as the provider/signer given
7
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The Web3 provider or signer.
8
+ * @param {POOL_NAME} poolName - The name of the pool.
9
+ * @param {POOL_TYPE} poolType - The type of the pool.
10
+ * @returns {PoolInfoType|undefined} - The pool info or undefined if the chain ID is not supported.
11
+ */
12
+ const getPoolInfo = (chainId, poolName, poolType) => { var _a, _b; return (_b = (_a = huma_shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]; };
13
+ exports.getPoolInfo = getPoolInfo;
14
+ //# sourceMappingURL=poolInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poolInfo.js","sourceRoot":"","sources":["../../../src/utils/poolInfo.ts"],"names":[],"mappings":";;;AAAA,qDAK4B;AAE5B;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,CACzB,OAAe,EACf,QAAmB,EACnB,QAAmB,EACO,EAAE,eAAC,OAAA,MAAA,MAAA,6BAAe,CAAC,OAAO,CAAC,0CAAG,QAAQ,CAAC,0CAAG,QAAQ,CAAC,CAAA,EAAA,CAAA;AAJlE,QAAA,WAAW,eAIuD"}
@@ -0,0 +1,4 @@
1
+ import { Contract } from '@ethersproject/contracts';
2
+ import { ethers } from 'ethers';
3
+ export declare function isAddress(value: any): string | false;
4
+ export declare function getContract(address: string, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): Contract;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContract = exports.isAddress = void 0;
4
+ const contracts_1 = require("@ethersproject/contracts");
5
+ const constants_1 = require("@ethersproject/constants");
6
+ const address_1 = require("@ethersproject/address");
7
+ // returns the checksummed address if the address is valid, otherwise returns false
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ function isAddress(value) {
10
+ try {
11
+ // Alphabetical letters must be made lowercase for getAddress to work.
12
+ // See documentation here: https://docs.ethers.io/v5/api/utils/address/
13
+ return (0, address_1.getAddress)(value.toLowerCase());
14
+ }
15
+ catch (_a) {
16
+ return false;
17
+ }
18
+ }
19
+ exports.isAddress = isAddress;
20
+ function getContract(address,
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ ABI, signerOrProvider) {
23
+ if (!isAddress(address) || address === constants_1.AddressZero) {
24
+ throw Error(`Invalid 'address' parameter '${address}'.`);
25
+ }
26
+ return new contracts_1.Contract(address, ABI, signerOrProvider);
27
+ }
28
+ exports.getContract = getContract;
29
+ //# sourceMappingURL=web3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3.js","sourceRoot":"","sources":["../../../src/utils/web3.ts"],"names":[],"mappings":";;;AAAA,wDAAmD;AACnD,wDAAsD;AACtD,oDAAmD;AAGnD,mFAAmF;AACnF,8DAA8D;AAC9D,SAAgB,SAAS,CAAC,KAAU;IAClC,IAAI;QACF,sEAAsE;QACtE,uEAAuE;QACvE,OAAO,IAAA,oBAAU,EAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;KACvC;IAAC,WAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AARD,8BAQC;AAED,SAAgB,WAAW,CACzB,OAAe;AACf,8DAA8D;AAC9D,GAAQ,EACR,gBAA2D;IAE3D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,uBAAW,EAAE;QAClD,MAAM,KAAK,CAAC,gCAAgC,OAAO,IAAI,CAAC,CAAA;KACzD;IAED,OAAO,IAAI,oBAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAA;AACrD,CAAC;AAXD,kCAWC"}
@@ -0,0 +1,9 @@
1
+ import { Contract, ethers } from 'ethers';
2
+ /**
3
+ * Returns an ethers contract instance for the BaseCreditPoolReceivable contract
4
+ * associated with the given pool name on the current chain.
5
+ *
6
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
7
+ * @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
8
+ */
9
+ export declare function getBaseCreditPoolReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
@@ -0,0 +1,17 @@
1
+ import { BASE_CREDIT_POOL_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@00labs/huma-shared';
2
+ import { getContract } from '../utils';
3
+ /**
4
+ * Returns an ethers contract instance for the BaseCreditPoolReceivable contract
5
+ * associated with the given pool name on the current chain.
6
+ *
7
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
8
+ * @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
9
+ */
10
+ export function getBaseCreditPoolReceivableContract(signerOrProvider, chainId) {
11
+ var _a;
12
+ const baseCreditPoolReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.BaseCreditPoolReceivable];
13
+ if (!baseCreditPoolReceivable)
14
+ return null;
15
+ return getContract(baseCreditPoolReceivable, BASE_CREDIT_POOL_RECEIVABLE_ABI, signerOrProvider);
16
+ }
17
+ //# sourceMappingURL=BaseCreditPoolReceivableContractHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseCreditPoolReceivableContractHelper.js","sourceRoot":"","sources":["../../src/helpers/BaseCreditPoolReceivableContractHelper.ts"],"names":[],"mappings":"AACA,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC;;;;;;GAMG;AACH,MAAM,UAAU,mCAAmC,CACjD,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,wBAAwB,GAC5B,MAAA,yBAAyB,CAAC,OAAO,CAAC,0CAChC,sBAAsB,CAAC,wBAAwB,CAChD,CAAA;IAEH,IAAI,CAAC,wBAAwB;QAAE,OAAO,IAAI,CAAA;IAE1C,OAAO,WAAW,CAChB,wBAAwB,EACxB,+BAA+B,EAC/B,gBAAgB,CACjB,CAAA;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './BaseCreditPoolReceivableContractHelper';
@@ -0,0 +1,2 @@
1
+ export * from './BaseCreditPoolReceivableContractHelper';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,0CAA0C,CAAA"}
@@ -0,0 +1,5 @@
1
+ export * from './useContract';
2
+ export * from './useBaseCreditPoolReceivableContract';
3
+ export * from './useERC20TransferableReceivableContract';
4
+ export * from './usePoolContract';
5
+ export * from './useReceivableFactoringPoolContract';
@@ -0,0 +1,6 @@
1
+ export * from './useContract';
2
+ export * from './useBaseCreditPoolReceivableContract';
3
+ export * from './useERC20TransferableReceivableContract';
4
+ export * from './usePoolContract';
5
+ export * from './useReceivableFactoringPoolContract';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,uCAAuC,CAAA;AACrD,cAAc,0CAA0C,CAAA;AACxD,cAAc,mBAAmB,CAAA;AACjC,cAAc,sCAAsC,CAAA"}
@@ -0,0 +1,9 @@
1
+ import { Contract, ethers } from 'ethers';
2
+ /**
3
+ * A react hook that returns an ethers contract instance for the BaseCreditPoolReceivable contract
4
+ * associated with the given pool name on the current chain.
5
+ *
6
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider The provider or signer instance to use for the contract.
7
+ * @returns {Contract | null} A contract instance for the BaseCreditPoolReceivable contract or null if it could not be found.
8
+ */
9
+ export declare function useBaseCreditPoolReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;