@huma-finance/sdk 0.0.51-beta.225 → 0.0.51-beta.346

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 (79) hide show
  1. package/API.md +151 -0
  2. package/dist/cjs/helpers/ERC20ContractHelper.d.ts +16 -0
  3. package/dist/cjs/helpers/ERC20ContractHelper.js +33 -0
  4. package/dist/cjs/helpers/ERC20ContractHelper.js.map +1 -0
  5. package/dist/cjs/helpers/PoolContractHelper.d.ts +3 -3
  6. package/dist/cjs/helpers/PoolContractHelper.js +3 -6
  7. package/dist/cjs/helpers/PoolContractHelper.js.map +1 -1
  8. package/dist/cjs/helpers/index.d.ts +2 -0
  9. package/dist/cjs/helpers/index.js +2 -0
  10. package/dist/cjs/helpers/index.js.map +1 -1
  11. package/dist/cjs/helpers/v2/ReceivableBackedCreditLineContractHelper.d.ts +64 -0
  12. package/dist/cjs/helpers/v2/ReceivableBackedCreditLineContractHelper.js +135 -0
  13. package/dist/cjs/helpers/v2/ReceivableBackedCreditLineContractHelper.js.map +1 -0
  14. package/dist/cjs/helpers/v2/ReceivableContractHelper.d.ts +15 -0
  15. package/dist/cjs/helpers/v2/ReceivableContractHelper.js +64 -0
  16. package/dist/cjs/helpers/v2/ReceivableContractHelper.js.map +1 -0
  17. package/dist/cjs/services/ReceivableService.js +6 -2
  18. package/dist/cjs/services/ReceivableService.js.map +1 -1
  19. package/dist/cjs/services/SubgraphService.d.ts +14 -0
  20. package/dist/cjs/services/SubgraphService.js +79 -2
  21. package/dist/cjs/services/SubgraphService.js.map +1 -1
  22. package/dist/cjs/services/index.d.ts +3 -0
  23. package/dist/cjs/services/index.js +3 -0
  24. package/dist/cjs/services/index.js.map +1 -1
  25. package/dist/cjs/services/v2/HumaContext.d.ts +23 -0
  26. package/dist/cjs/services/v2/HumaContext.js +55 -0
  27. package/dist/cjs/services/v2/HumaContext.js.map +1 -0
  28. package/dist/cjs/services/v2/HumaReceivableFactory.d.ts +22 -0
  29. package/dist/cjs/services/v2/HumaReceivableFactory.js +89 -0
  30. package/dist/cjs/services/v2/HumaReceivableFactory.js.map +1 -0
  31. package/dist/cjs/services/v2/HumaReceivableHandler.d.ts +10 -0
  32. package/dist/cjs/services/v2/HumaReceivableHandler.js +32 -0
  33. package/dist/cjs/services/v2/HumaReceivableHandler.js.map +1 -0
  34. package/dist/cjs/utils/chain.js +2 -10
  35. package/dist/cjs/utils/chain.js.map +1 -1
  36. package/dist/cjs/utils/poolInfo.js +1 -1
  37. package/dist/cjs/utils/poolInfo.js.map +1 -1
  38. package/dist/cjs/utils/web3.d.ts +3 -2
  39. package/dist/cjs/utils/web3.js.map +1 -1
  40. package/dist/helpers/ERC20ContractHelper.d.ts +16 -0
  41. package/dist/helpers/ERC20ContractHelper.js +29 -0
  42. package/dist/helpers/ERC20ContractHelper.js.map +1 -0
  43. package/dist/helpers/PoolContractHelper.d.ts +3 -3
  44. package/dist/helpers/PoolContractHelper.js +3 -6
  45. package/dist/helpers/PoolContractHelper.js.map +1 -1
  46. package/dist/helpers/index.d.ts +2 -0
  47. package/dist/helpers/index.js +2 -0
  48. package/dist/helpers/index.js.map +1 -1
  49. package/dist/helpers/v2/ReceivableBackedCreditLineContractHelper.d.ts +64 -0
  50. package/dist/helpers/v2/ReceivableBackedCreditLineContractHelper.js +127 -0
  51. package/dist/helpers/v2/ReceivableBackedCreditLineContractHelper.js.map +1 -0
  52. package/dist/helpers/v2/ReceivableContractHelper.d.ts +15 -0
  53. package/dist/helpers/v2/ReceivableContractHelper.js +57 -0
  54. package/dist/helpers/v2/ReceivableContractHelper.js.map +1 -0
  55. package/dist/services/ReceivableService.js +6 -2
  56. package/dist/services/ReceivableService.js.map +1 -1
  57. package/dist/services/SubgraphService.d.ts +14 -0
  58. package/dist/services/SubgraphService.js +80 -3
  59. package/dist/services/SubgraphService.js.map +1 -1
  60. package/dist/services/index.d.ts +3 -0
  61. package/dist/services/index.js +3 -0
  62. package/dist/services/index.js.map +1 -1
  63. package/dist/services/v2/HumaContext.d.ts +23 -0
  64. package/dist/services/v2/HumaContext.js +51 -0
  65. package/dist/services/v2/HumaContext.js.map +1 -0
  66. package/dist/services/v2/HumaReceivableFactory.d.ts +22 -0
  67. package/dist/services/v2/HumaReceivableFactory.js +85 -0
  68. package/dist/services/v2/HumaReceivableFactory.js.map +1 -0
  69. package/dist/services/v2/HumaReceivableHandler.d.ts +10 -0
  70. package/dist/services/v2/HumaReceivableHandler.js +28 -0
  71. package/dist/services/v2/HumaReceivableHandler.js.map +1 -0
  72. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  73. package/dist/utils/chain.js +2 -10
  74. package/dist/utils/chain.js.map +1 -1
  75. package/dist/utils/poolInfo.js +2 -2
  76. package/dist/utils/poolInfo.js.map +1 -1
  77. package/dist/utils/web3.d.ts +3 -2
  78. package/dist/utils/web3.js.map +1 -1
  79. package/package.json +4 -4
package/API.md CHANGED
@@ -18,6 +18,9 @@
18
18
  <dl>
19
19
  <dt><a href="#defaultWrapper">defaultWrapper()</a></dt>
20
20
  <dd><p>All built-in and custom scalars, mapped to their actual values</p></dd>
21
+ <dt><a href="#approveERC20AllowanceIfInsufficient">approveERC20AllowanceIfInsufficient(signer, tokenAddress, spenderAddress, allowanceAmount, [gasOpts])</a> ⇒ <code>Promise.&lt;(TransactionResponse|null)&gt;</code></dt>
22
+ <dd><p>Approves an ERC20 allowance for a spender address, if the current allowance is insufficient.
23
+ Allowance is required to do certain actions on the Huma protocol (e.g. makePayment)</p></dd>
21
24
  <dt><a href="#getERC20TransferableReceivableContract">getERC20TransferableReceivableContract(signerOrProvider, chainId)</a> ⇒ <code>Contract</code> | <code>null</code></dt>
22
25
  <dd><p>Returns an ethers contract instance for the ERC20TransferableReceivable contract
23
26
  associated with the given pool name on the current chain.</p></dd>
@@ -37,6 +40,21 @@ attempt to first increase the allowance of the pool.</p></dd>
37
40
  <dt><a href="#getRealWorldReceivableContract">getRealWorldReceivableContract(signerOrProvider, chainId)</a> ⇒ <code>Contract</code> | <code>null</code></dt>
38
41
  <dd><p>Returns an ethers contract instance for the RealWorldReceivable contract
39
42
  associated with the given pool name on the current chain.</p></dd>
43
+ <dt><a href="#getReceivableBackedCreditLineContractV2">getReceivableBackedCreditLineContractV2(signerOrProvider, poolName)</a> ⇒ <code>ReceivableBackedCreditLine</code> | <code>null</code></dt>
44
+ <dd><p>Returns an ethers contract instance for the V2 Receivable contract
45
+ associated with the given pool name on the current chain.</p></dd>
46
+ <dt><a href="#getTotalDueV2">getTotalDueV2(provider, poolName)</a> ⇒ <code>BigNumber</code> | <code>null</code></dt>
47
+ <dd><p>Returns account's total due amount in BigNumber format
48
+ associated with the given pool name on the current chain.</p></dd>
49
+ <dt><a href="#drawdownWithReceivable">drawdownWithReceivable(signer, poolName, receivableId, drawdownAmount, [gasOpts])</a> ⇒ <code>Promise.&lt;TransactionResponse&gt;</code></dt>
50
+ <dd><p>Draws down from a pool using a receivable.</p></dd>
51
+ <dt><a href="#makePaymentWithReceivable">makePaymentWithReceivable(signer, poolName, receivableId, paymentAmount, principalOnly, [gasOpts])</a> ⇒ <code>Promise.&lt;TransactionResponse&gt;</code></dt>
52
+ <dd><p>Makes a payment with a receivable.</p></dd>
53
+ <dt><a href="#makePrincipalPaymentAndDrawdownWithReceivable">makePrincipalPaymentAndDrawdownWithReceivable(signer, poolName, paymentReceivableId, paymentAmount, drawdownReceivableId, drawdownAmount, [gasOpts])</a> ⇒ <code>Promise.&lt;TransactionResponse&gt;</code></dt>
54
+ <dd><p>Makes a principal payment and drawdown with receivables.</p></dd>
55
+ <dt><a href="#getReceivableContractV2">getReceivableContractV2(signerOrProvider, chainId)</a> ⇒ <code>Contract</code> | <code>null</code></dt>
56
+ <dd><p>Returns an ethers contract instance for the V2 Receivable contract
57
+ associated with the given pool name on the current chain.</p></dd>
40
58
  <dt><a href="#useContract">useContract(address, ABI, signerOrProvider)</a> ⇒ <code>T</code> | <code>null</code></dt>
41
59
  <dd><p>Custom hook for creating an ethers instance of a smart contract.</p></dd>
42
60
  <dt><a href="#useERC20TransferableReceivableContract">useERC20TransferableReceivableContract(signerOrProvider, chainId, poolName)</a> ⇒ <code>Contract</code> | <code>null</code></dt>
@@ -475,6 +493,7 @@ in Huma's pools that can be drawn down by the borrower.</p>
475
493
  * [.getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType)](#SubgraphService.getLastFactorizedAmountFromPool) ⇒ <code>Promise.&lt;number&gt;</code>
476
494
  * [.getRWReceivableInfo(userAddress, chainId, poolName, poolType, pagination)](#SubgraphService.getRWReceivableInfo) ⇒ <code>Promise.&lt;RealWorldReceivableInfoBase&gt;</code>
477
495
  * [.getPoolStats(chainId, pool)](#SubgraphService.getPoolStats) ⇒ <code>Promise.&lt;{PoolStats}&gt;</code>
496
+ * [.checkBorrowAndLendHistory(chainId, pool, userAddress)](#SubgraphService.checkBorrowAndLendHistory) ⇒ <code>Promise.&lt;{hasBorrowHistory: boolean, hasLendHistory: boolean}&gt;</code>
478
497
 
479
498
  <a name="SubgraphService.getSubgraphUrlForChainId"></a>
480
499
 
@@ -548,12 +567,45 @@ in Huma's pools that can be drawn down by the borrower.</p>
548
567
  | chainId | <code>number</code> | <p>The ID of the chain.</p> |
549
568
  | pool | <code>string</code> | <p>The address of the pool.</p> |
550
569
 
570
+ <a name="SubgraphService.checkBorrowAndLendHistory"></a>
571
+
572
+ ### SubgraphService.checkBorrowAndLendHistory(chainId, pool, userAddress) ⇒ <code>Promise.&lt;{hasBorrowHistory: boolean, hasLendHistory: boolean}&gt;</code>
573
+ <p>Returns if user has borrow or lend history.</p>
574
+
575
+ **Kind**: static method of [<code>SubgraphService</code>](#SubgraphService)
576
+ **Returns**: <code>Promise.&lt;{hasBorrowHistory: boolean, hasLendHistory: boolean}&gt;</code> - <p>If user has borrow or lend history.</p>
577
+
578
+ | Param | Type | Description |
579
+ | --- | --- | --- |
580
+ | chainId | <code>number</code> | <p>The ID of the chain.</p> |
581
+ | pool | <code>string</code> | <p>The address of the pool.</p> |
582
+ | userAddress | <code>string</code> | <p>The address of the user.</p> |
583
+
551
584
  <a name="defaultWrapper"></a>
552
585
 
553
586
  ## defaultWrapper()
554
587
  <p>All built-in and custom scalars, mapped to their actual values</p>
555
588
 
556
589
  **Kind**: global function
590
+ <a name="approveERC20AllowanceIfInsufficient"></a>
591
+
592
+ ## approveERC20AllowanceIfInsufficient(signer, tokenAddress, spenderAddress, allowanceAmount, [gasOpts]) ⇒ <code>Promise.&lt;(TransactionResponse\|null)&gt;</code>
593
+ <p>Approves an ERC20 allowance for a spender address, if the current allowance is insufficient.
594
+ Allowance is required to do certain actions on the Huma protocol (e.g. makePayment)</p>
595
+
596
+ **Kind**: global function
597
+ **Returns**: <code>Promise.&lt;(TransactionResponse\|null)&gt;</code> - <ul>
598
+ <li>A Promise of the transaction response, or null if the allowance was already sufficient.</li>
599
+ </ul>
600
+
601
+ | Param | Type | Description |
602
+ | --- | --- | --- |
603
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
604
+ | tokenAddress | <code>string</code> | <p>The address of the ERC20 token to approve.</p> |
605
+ | spenderAddress | <code>string</code> | <p>The address of the spender to approve an allowance for.</p> |
606
+ | allowanceAmount | <code>BigNumber</code> | <p>The amount of tokens to approve, if applicable. Denominated in the ERC20 tokens.</p> |
607
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
608
+
557
609
  <a name="getERC20TransferableReceivableContract"></a>
558
610
 
559
611
  ## getERC20TransferableReceivableContract(signerOrProvider, chainId) ⇒ <code>Contract</code> \| <code>null</code>
@@ -710,6 +762,105 @@ associated with the given pool name on the current chain.</p>
710
762
  | signerOrProvider | <code>ethers.providers.Provider</code> \| <code>ethers.Signer</code> | <p>The provider or signer instance to use for the contract.</p> |
711
763
  | chainId | <code>number</code> | <p>The chain id where the contract instance exists</p> |
712
764
 
765
+ <a name="getReceivableBackedCreditLineContractV2"></a>
766
+
767
+ ## getReceivableBackedCreditLineContractV2(signerOrProvider, poolName) ⇒ <code>ReceivableBackedCreditLine</code> \| <code>null</code>
768
+ <p>Returns an ethers contract instance for the V2 Receivable contract
769
+ associated with the given pool name on the current chain.</p>
770
+
771
+ **Kind**: global function
772
+ **Returns**: <code>ReceivableBackedCreditLine</code> \| <code>null</code> - <p>A contract instance for the ReceivableBackedCreditLine contract or null if it could not be found.</p>
773
+
774
+ | Param | Type | Description |
775
+ | --- | --- | --- |
776
+ | signerOrProvider | <code>ethers.providers.Provider</code> \| <code>ethers.Signer</code> | <p>The provider or signer instance to use for the contract.</p> |
777
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to get the contract instance for.</p> |
778
+
779
+ <a name="getTotalDueV2"></a>
780
+
781
+ ## getTotalDueV2(provider, poolName) ⇒ <code>BigNumber</code> \| <code>null</code>
782
+ <p>Returns account's total due amount in BigNumber format
783
+ associated with the given pool name on the current chain.</p>
784
+
785
+ **Kind**: global function
786
+ **Returns**: <code>BigNumber</code> \| <code>null</code> - <p>The account's total due amount in BigNumber format</p>
787
+
788
+ | Param | Type | Description |
789
+ | --- | --- | --- |
790
+ | provider | <code>JsonRpcProvider</code> \| <code>Web3Provider</code> | <p>The provider instance to use for the contract.</p> |
791
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to get the contract instance for.</p> |
792
+
793
+ <a name="drawdownWithReceivable"></a>
794
+
795
+ ## drawdownWithReceivable(signer, poolName, receivableId, drawdownAmount, [gasOpts]) ⇒ <code>Promise.&lt;TransactionResponse&gt;</code>
796
+ <p>Draws down from a pool using a receivable.</p>
797
+
798
+ **Kind**: global function
799
+ **Returns**: <code>Promise.&lt;TransactionResponse&gt;</code> - <ul>
800
+ <li>A Promise of the transaction response.</li>
801
+ </ul>
802
+
803
+ | Param | Type | Description |
804
+ | --- | --- | --- |
805
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
806
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to drawdown from.</p> |
807
+ | receivableId | <code>BigNumberish</code> | <p>The ID of the receivable.</p> |
808
+ | drawdownAmount | <code>BigNumberish</code> | <p>The amount to drawdown.</p> |
809
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
810
+
811
+ <a name="makePaymentWithReceivable"></a>
812
+
813
+ ## makePaymentWithReceivable(signer, poolName, receivableId, paymentAmount, principalOnly, [gasOpts]) ⇒ <code>Promise.&lt;TransactionResponse&gt;</code>
814
+ <p>Makes a payment with a receivable.</p>
815
+
816
+ **Kind**: global function
817
+ **Returns**: <code>Promise.&lt;TransactionResponse&gt;</code> - <ul>
818
+ <li>A Promise of the transaction response.</li>
819
+ </ul>
820
+
821
+ | Param | Type | Description |
822
+ | --- | --- | --- |
823
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
824
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the pool to interact with.</p> |
825
+ | receivableId | <code>BigNumberish</code> | <p>The ID of the receivable.</p> |
826
+ | paymentAmount | <code>BigNumberish</code> | <p>The amount to payback.</p> |
827
+ | principalOnly | <code>boolean</code> | <p>Whether this payment should ONLY apply to the principal</p> |
828
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
829
+
830
+ <a name="makePrincipalPaymentAndDrawdownWithReceivable"></a>
831
+
832
+ ## makePrincipalPaymentAndDrawdownWithReceivable(signer, poolName, paymentReceivableId, paymentAmount, drawdownReceivableId, drawdownAmount, [gasOpts]) ⇒ <code>Promise.&lt;TransactionResponse&gt;</code>
833
+ <p>Makes a principal payment and drawdown with receivables.</p>
834
+
835
+ **Kind**: global function
836
+ **Returns**: <code>Promise.&lt;TransactionResponse&gt;</code> - <ul>
837
+ <li>A Promise of the transaction response.</li>
838
+ </ul>
839
+
840
+ | Param | Type | Description |
841
+ | --- | --- | --- |
842
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
843
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the pool to interact with.</p> |
844
+ | paymentReceivableId | <code>BigNumberish</code> | <p>The ID of the receivable for payment.</p> |
845
+ | paymentAmount | <code>BigNumberish</code> | <p>The amount to payback.</p> |
846
+ | drawdownReceivableId | <code>BigNumberish</code> | <p>The ID of the drawdown receivable.</p> |
847
+ | drawdownAmount | <code>BigNumberish</code> | <p>The amount to drawdown.</p> |
848
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
849
+
850
+ <a name="getReceivableContractV2"></a>
851
+
852
+ ## getReceivableContractV2(signerOrProvider, chainId) ⇒ <code>Contract</code> \| <code>null</code>
853
+ <p>Returns an ethers contract instance for the V2 Receivable contract
854
+ associated with the given pool name on the current chain.</p>
855
+
856
+ **Kind**: global function
857
+ **Returns**: <code>Contract</code> \| <code>null</code> - <p>A contract instance for the Receivable contract or null if it could not be found.</p>
858
+
859
+ | Param | Type | Description |
860
+ | --- | --- | --- |
861
+ | signerOrProvider | <code>ethers.providers.Provider</code> \| <code>ethers.Signer</code> | <p>The provider or signer instance to use for the contract.</p> |
862
+ | chainId | <code>number</code> | <p>The chain id where the contract instance exists</p> |
863
+
713
864
  <a name="useContract"></a>
714
865
 
715
866
  ## useContract(address, ABI, signerOrProvider) ⇒ <code>T</code> \| <code>null</code>
@@ -0,0 +1,16 @@
1
+ import { BigNumberish, Overrides, ethers } from 'ethers';
2
+ import { TransactionResponse } from '@ethersproject/providers';
3
+ /**
4
+ * Approves an ERC20 allowance for a spender address, if the current allowance is insufficient.
5
+ * Allowance is required to do certain actions on the Huma protocol (e.g. makePayment)
6
+ *
7
+ * @async
8
+ * @function
9
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
10
+ * @param {string} tokenAddress - The address of the ERC20 token to approve.
11
+ * @param {string} spenderAddress - The address of the spender to approve an allowance for.
12
+ * @param {BigNumber} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the ERC20 tokens.
13
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
14
+ * @returns {Promise<TransactionResponse | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
15
+ */
16
+ export declare function approveERC20AllowanceIfInsufficient(signer: ethers.Signer, tokenAddress: string, spenderAddress: string, allowanceAmount: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse | null>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.approveERC20AllowanceIfInsufficient = void 0;
4
+ const shared_1 = require("@huma-finance/shared");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * Approves an ERC20 allowance for a spender address, if the current allowance is insufficient.
8
+ * Allowance is required to do certain actions on the Huma protocol (e.g. makePayment)
9
+ *
10
+ * @async
11
+ * @function
12
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
13
+ * @param {string} tokenAddress - The address of the ERC20 token to approve.
14
+ * @param {string} spenderAddress - The address of the spender to approve an allowance for.
15
+ * @param {BigNumber} allowanceAmount - The amount of tokens to approve, if applicable. Denominated in the ERC20 tokens.
16
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
17
+ * @returns {Promise<TransactionResponse | null>} - A Promise of the transaction response, or null if the allowance was already sufficient.
18
+ */
19
+ async function approveERC20AllowanceIfInsufficient(signer, tokenAddress, spenderAddress, allowanceAmount, gasOpts = {}) {
20
+ const chainId = await (0, shared_1.getChainIdFromSignerOrProvider)(signer);
21
+ if (!chainId) {
22
+ throw new Error('Could not find chain ID');
23
+ }
24
+ const tokenContract = (0, utils_1.getERC20Contract)(tokenAddress, signer);
25
+ const allowance = await tokenContract.allowance(await signer.getAddress(), spenderAddress);
26
+ if (allowance.lt(allowanceAmount)) {
27
+ gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
28
+ return tokenContract.approve(spenderAddress, allowanceAmount, gasOpts);
29
+ }
30
+ return null;
31
+ }
32
+ exports.approveERC20AllowanceIfInsufficient = approveERC20AllowanceIfInsufficient;
33
+ //# sourceMappingURL=ERC20ContractHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ERC20ContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/ERC20ContractHelper.ts"],"names":[],"mappings":";;;AACA,iDAAqE;AAErE,oCAAiE;AAEjE;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,mCAAmC,CACvD,MAAqB,EACrB,YAAoB,EACpB,cAAsB,EACtB,eAA6B,EAC7B,UAAqB,EAAE;IAEvB,MAAM,OAAO,GAAG,MAAM,IAAA,uCAA8B,EAAC,MAAM,CAAC,CAAA;IAE5D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;KAC3C;IAED,MAAM,aAAa,GAAG,IAAA,wBAAgB,EAAC,YAAY,EAAE,MAAM,CAAC,CAAA;IAE5D,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,SAAS,CAC7C,MAAM,MAAM,CAAC,UAAU,EAAE,EACzB,cAAc,CACf,CAAA;IACD,IAAI,SAAS,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE;QACjC,OAAO,GAAG,MAAM,IAAA,4BAAoB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACtD,OAAO,aAAa,CAAC,OAAO,CAAC,cAAc,EAAE,eAAe,EAAE,OAAO,CAAC,CAAA;KACvE;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAzBD,kFAyBC"}
@@ -1,6 +1,6 @@
1
1
  import { BigNumber } from '@ethersproject/bignumber';
2
- import { BigNumberish, Contract, Overrides, ethers } from 'ethers';
3
- import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
2
+ import { BigNumberish, Overrides, ethers } from 'ethers';
3
+ import { BaseCreditPool, POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
4
4
  import { TransactionResponse } from '@ethersproject/providers';
5
5
  /**
6
6
  * Returns an ethers contract instance for a Huma pool contract
@@ -11,7 +11,7 @@ import { TransactionResponse } from '@ethersproject/providers';
11
11
  * @param {POOL_TYPE} poolType The type of the pool contract to get.
12
12
  * @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
13
13
  */
14
- export declare function getPoolContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Contract | null;
14
+ export declare function getPoolContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): BaseCreditPool | null;
15
15
  /**
16
16
  * Return type of getCreditRecord
17
17
  *
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.approvePoolAllowance = exports.makePaymentToPool = exports.drawdownFromPool = exports.getTotalDue = exports.getCreditRecord = exports.getPoolContract = void 0;
4
4
  const utils_1 = require("../utils");
5
+ const ERC20ContractHelper_1 = require("./ERC20ContractHelper");
5
6
  /**
6
7
  * Returns an ethers contract instance for a Huma pool contract
7
8
  *
@@ -75,7 +76,6 @@ async function drawdownFromPool(signer, chainId, poolName, poolType, drawdownAmo
75
76
  throw new Error('Could not find pool contract');
76
77
  }
77
78
  gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
78
- // TODO: Generate typechain for pool contract
79
79
  return poolContract.drawdown(drawdownAmount, gasOpts);
80
80
  }
81
81
  exports.drawdownFromPool = drawdownFromPool;
@@ -98,19 +98,16 @@ async function makePaymentToPool(signer, chainId, poolName, poolType, paymentAmo
98
98
  if (!(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address)) {
99
99
  throw new Error('Could not find pool underlying token address');
100
100
  }
101
- const poolTokenContract = (0, utils_1.getERC20Contract)(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address, signer);
102
101
  const poolContract = getPoolContract(signer, chainId, poolName, poolType);
103
102
  if (!poolContract) {
104
103
  throw new Error('Could not find pool contract');
105
104
  }
106
105
  gasOpts = await (0, utils_1.getDefaultGasOptions)(gasOpts, chainId);
107
- const allowance = await poolTokenContract.allowance(await signer.getAddress(), poolContract.address);
108
- if (allowance.lt(paymentAmount)) {
109
- const approvalTx = await poolTokenContract.approve(poolContract.address, paymentAmount, gasOpts);
106
+ const approvalTx = await (0, ERC20ContractHelper_1.approveERC20AllowanceIfInsufficient)(signer, poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address, poolContract.address, paymentAmount, gasOpts);
107
+ if (approvalTx) {
110
108
  // Wait for 5 block confirmations since this is required for makePayment
111
109
  await approvalTx.wait(5);
112
110
  }
113
- // TODO: Generate typechain for pool contract
114
111
  return poolContract.makePayment(await signer.getAddress(), paymentAmount, gasOpts);
115
112
  }
116
113
  exports.makePaymentToPool = makePaymentToPool;
@@ -1 +1 @@
1
- {"version":3,"file":"PoolContractHelper.js","sourceRoot":"","sources":["../../../src/helpers/PoolContractHelper.ts"],"names":[],"mappings":";;;AAKA,oCAKiB;AAEjB;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,gBAA2D,EAC3D,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAEzD,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAE1B,OAAO,IAAA,mBAAW,EAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;AACvE,CAAC;AAXD,0CAWC;AAsCD;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,eAAe,CACnC,OAAe,EACf,gBAA2D,EAC3D,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,MAAM,YAAY,GAAG,eAAe,CAClC,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,QAAQ,CACT,CAAA;IAED,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,OAAO,YAAY,CAAC,mBAAmB,CAAC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Y,GAAG,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAEzE,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;KAChD;IAED,OAAO,GAAG,MAAM,IAAA,4BAAoB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAEtD,OAAO,iBAAiB,CAAC,OAAO,CAC9B,YAAY,CAAC,OAAO,EACpB,eAAe,EACf,OAAO,CACR,CAAA;AACH,CAAC;AA7BD,oDA6BC"}
@@ -1,3 +1,5 @@
1
1
  export * from './RealWorldReceivableContractHelper';
2
2
  export * from './ERC20TransferableReceivableContractHelper';
3
3
  export * from './PoolContractHelper';
4
+ export * from './v2/ReceivableContractHelper';
5
+ export * from './v2/ReceivableBackedCreditLineContractHelper';
@@ -4,4 +4,6 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./RealWorldReceivableContractHelper"), exports);
5
5
  tslib_1.__exportStar(require("./ERC20TransferableReceivableContractHelper"), exports);
6
6
  tslib_1.__exportStar(require("./PoolContractHelper"), exports);
7
+ tslib_1.__exportStar(require("./v2/ReceivableContractHelper"), exports);
8
+ tslib_1.__exportStar(require("./v2/ReceivableBackedCreditLineContractHelper"), exports);
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,8EAAmD;AACnD,sFAA2D;AAC3D,+DAAoC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,8EAAmD;AACnD,sFAA2D;AAC3D,+DAAoC;AACpC,wEAA6C;AAC7C,wFAA6D"}
@@ -0,0 +1,64 @@
1
+ import { JsonRpcProvider, TransactionResponse, Web3Provider } from '@ethersproject/providers';
2
+ import { POOL_NAME } from '@huma-finance/shared';
3
+ import { ReceivableBackedCreditLine } from '@huma-finance/shared/src/v2/abis/types';
4
+ import { BigNumber, BigNumberish, ethers, Overrides } from 'ethers';
5
+ /**
6
+ * Returns an ethers contract instance for the V2 Receivable contract
7
+ * associated with the given pool name on the current chain.
8
+ *
9
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
10
+ * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
11
+ * @returns {ReceivableBackedCreditLine | null} A contract instance for the ReceivableBackedCreditLine contract or null if it could not be found.
12
+ */
13
+ export declare function getReceivableBackedCreditLineContractV2(poolName: POOL_NAME, signerOrProvider: JsonRpcProvider | Web3Provider | ethers.Signer): Promise<ReceivableBackedCreditLine | null>;
14
+ /**
15
+ * Returns account's total due amount in BigNumber format
16
+ * associated with the given pool name on the current chain.
17
+ *
18
+ * @param {JsonRpcProvider | Web3Provider} provider The provider instance to use for the contract.
19
+ * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
20
+ * @returns {BigNumber | null} The account's total due amount in BigNumber format
21
+ */
22
+ export declare function getTotalDueV2(poolName: POOL_NAME, account: string, provider: JsonRpcProvider | Web3Provider): Promise<BigNumber | null>;
23
+ /**
24
+ * Draws down from a pool using a receivable.
25
+ *
26
+ * @async
27
+ * @function
28
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
29
+ * @param {POOL_NAME} poolName - The name of the credit pool to drawdown from.
30
+ * @param {BigNumberish} receivableId - The ID of the receivable.
31
+ * @param {BigNumberish} drawdownAmount - The amount to drawdown.
32
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
33
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
34
+ */
35
+ export declare function drawdownWithReceivable(signer: ethers.Signer, poolName: POOL_NAME, receivableId: BigNumberish, drawdownAmount: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse>;
36
+ /**
37
+ * Makes a payment with a receivable.
38
+ *
39
+ * @async
40
+ * @function
41
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
42
+ * @param {POOL_NAME} poolName - The name of the pool to interact with.
43
+ * @param {BigNumberish} receivableId - The ID of the receivable.
44
+ * @param {BigNumberish} paymentAmount - The amount to payback.
45
+ * @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
46
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
47
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
48
+ */
49
+ export declare function makePaymentWithReceivable(signer: ethers.Signer, poolName: POOL_NAME, receivableId: BigNumberish, paymentAmount: BigNumberish, principalOnly: boolean, gasOpts?: Overrides): Promise<TransactionResponse>;
50
+ /**
51
+ * Makes a principal payment and drawdown with receivables.
52
+ *
53
+ * @async
54
+ * @function
55
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
56
+ * @param {POOL_NAME} poolName - The name of the pool to interact with.
57
+ * @param {BigNumberish} paymentReceivableId - The ID of the receivable for payment.
58
+ * @param {BigNumberish} paymentAmount - The amount to payback.
59
+ * @param {BigNumberish} drawdownReceivableId - The ID of the drawdown receivable.
60
+ * @param {BigNumberish} drawdownAmount - The amount to drawdown.
61
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
62
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
63
+ */
64
+ export declare function makePrincipalPaymentAndDrawdownWithReceivable(signer: ethers.Signer, poolName: POOL_NAME, paymentReceivableId: BigNumberish, paymentAmount: BigNumberish, drawdownReceivableId: BigNumberish, drawdownAmount: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse>;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makePrincipalPaymentAndDrawdownWithReceivable = exports.makePaymentWithReceivable = exports.drawdownWithReceivable = exports.getTotalDueV2 = exports.getReceivableBackedCreditLineContractV2 = void 0;
4
+ const shared_1 = require("@huma-finance/shared");
5
+ const utils_1 = require("../../utils");
6
+ const ERC20ContractHelper_1 = require("../ERC20ContractHelper");
7
+ const ReceivableContractHelper_1 = require("./ReceivableContractHelper");
8
+ /**
9
+ * Returns an ethers contract instance for the V2 Receivable contract
10
+ * associated with the given pool name on the current chain.
11
+ *
12
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
13
+ * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
14
+ * @returns {ReceivableBackedCreditLine | null} A contract instance for the ReceivableBackedCreditLine contract or null if it could not be found.
15
+ */
16
+ async function getReceivableBackedCreditLineContractV2(poolName, signerOrProvider) {
17
+ const chainId = await (0, shared_1.getChainIdFromSignerOrProvider)(signerOrProvider);
18
+ const poolInfo = (0, shared_1.getPoolInfoV2)(poolName, chainId);
19
+ if (!poolInfo || poolInfo.poolType !== shared_1.POOL_TYPE.ReceivableBackedCreditLine) {
20
+ return null;
21
+ }
22
+ return (0, utils_1.getContract)(poolInfo.poolCredit, shared_1.RECEIVABLE_BACKED_CREDIT_LINE_V2_ABI, signerOrProvider);
23
+ }
24
+ exports.getReceivableBackedCreditLineContractV2 = getReceivableBackedCreditLineContractV2;
25
+ /**
26
+ * Returns account's total due amount in BigNumber format
27
+ * associated with the given pool name on the current chain.
28
+ *
29
+ * @param {JsonRpcProvider | Web3Provider} provider The provider instance to use for the contract.
30
+ * @param {POOL_NAME} poolName - The name of the credit pool to get the contract instance for.
31
+ * @returns {BigNumber | null} The account's total due amount in BigNumber format
32
+ */
33
+ async function getTotalDueV2(poolName, account, provider) {
34
+ const creditRecord = await (0, shared_1.getCreditRecordV2)(poolName, account, provider);
35
+ if (!creditRecord) {
36
+ return null;
37
+ }
38
+ return creditRecord.nextDue.add(creditRecord.totalPastDue);
39
+ }
40
+ exports.getTotalDueV2 = getTotalDueV2;
41
+ /**
42
+ * Draws down from a pool using a receivable.
43
+ *
44
+ * @async
45
+ * @function
46
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
47
+ * @param {POOL_NAME} poolName - The name of the credit pool to drawdown from.
48
+ * @param {BigNumberish} receivableId - The ID of the receivable.
49
+ * @param {BigNumberish} drawdownAmount - The amount to drawdown.
50
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
51
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
52
+ */
53
+ async function drawdownWithReceivable(signer, poolName, receivableId, drawdownAmount, gasOpts = {}) {
54
+ const creditContract = await getReceivableBackedCreditLineContractV2(poolName, signer);
55
+ if (!creditContract) {
56
+ throw new Error('Could not find credit contract');
57
+ }
58
+ const approveTx = await (0, ReceivableContractHelper_1.approveReceivableTransferIfNeeded)(signer, poolName, receivableId);
59
+ await (approveTx === null || approveTx === void 0 ? void 0 : approveTx.wait(5));
60
+ return creditContract.drawdownWithReceivable(receivableId, drawdownAmount, gasOpts);
61
+ }
62
+ exports.drawdownWithReceivable = drawdownWithReceivable;
63
+ /**
64
+ * Makes a payment with a receivable.
65
+ *
66
+ * @async
67
+ * @function
68
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
69
+ * @param {POOL_NAME} poolName - The name of the pool to interact with.
70
+ * @param {BigNumberish} receivableId - The ID of the receivable.
71
+ * @param {BigNumberish} paymentAmount - The amount to payback.
72
+ * @param {boolean} principalOnly - Whether this payment should ONLY apply to the principal
73
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
74
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
75
+ */
76
+ async function makePaymentWithReceivable(signer, poolName, receivableId, paymentAmount, principalOnly, gasOpts = {}) {
77
+ const creditContract = await getReceivableBackedCreditLineContractV2(poolName, signer);
78
+ if (!creditContract) {
79
+ throw new Error('Could not find credit contract');
80
+ }
81
+ const poolSafeContract = await (0, shared_1.getPoolSafeContractV2)(poolName, signer.provider);
82
+ if (!poolSafeContract) {
83
+ throw new Error('Could not find pool safe contract');
84
+ }
85
+ const underlyingToken = await (0, shared_1.getPoolUnderlyingTokenContractV2)(poolName, signer.provider);
86
+ if (!underlyingToken) {
87
+ throw new Error('Could not find underlying token contract');
88
+ }
89
+ const approveERC20Tx = await (0, ERC20ContractHelper_1.approveERC20AllowanceIfInsufficient)(signer, underlyingToken.address, poolSafeContract.address, paymentAmount, gasOpts);
90
+ await (approveERC20Tx === null || approveERC20Tx === void 0 ? void 0 : approveERC20Tx.wait(5));
91
+ let paymentTx;
92
+ if (principalOnly) {
93
+ paymentTx = await creditContract.makePrincipalPaymentWithReceivable(receivableId, paymentAmount, gasOpts);
94
+ }
95
+ else {
96
+ paymentTx = await creditContract.makePaymentWithReceivable(await signer.getAddress(), receivableId, paymentAmount, gasOpts);
97
+ }
98
+ return paymentTx;
99
+ }
100
+ exports.makePaymentWithReceivable = makePaymentWithReceivable;
101
+ /**
102
+ * Makes a principal payment and drawdown with receivables.
103
+ *
104
+ * @async
105
+ * @function
106
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
107
+ * @param {POOL_NAME} poolName - The name of the pool to interact with.
108
+ * @param {BigNumberish} paymentReceivableId - The ID of the receivable for payment.
109
+ * @param {BigNumberish} paymentAmount - The amount to payback.
110
+ * @param {BigNumberish} drawdownReceivableId - The ID of the drawdown receivable.
111
+ * @param {BigNumberish} drawdownAmount - The amount to drawdown.
112
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
113
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
114
+ */
115
+ async function makePrincipalPaymentAndDrawdownWithReceivable(signer, poolName, paymentReceivableId, paymentAmount, drawdownReceivableId, drawdownAmount, gasOpts = {}) {
116
+ const creditContract = await getReceivableBackedCreditLineContractV2(poolName, signer);
117
+ if (!creditContract) {
118
+ throw new Error('Could not find credit contract');
119
+ }
120
+ const underlyingToken = await (0, shared_1.getPoolUnderlyingTokenContractV2)(poolName, signer.provider);
121
+ const poolSafeContract = await (0, shared_1.getPoolSafeContractV2)(poolName, signer.provider);
122
+ if (!poolSafeContract) {
123
+ throw new Error('Could not find pool safe contract');
124
+ }
125
+ if (!underlyingToken) {
126
+ throw new Error('Could not find underlying token contract');
127
+ }
128
+ const approveERC20Tx = await (0, ERC20ContractHelper_1.approveERC20AllowanceIfInsufficient)(signer, underlyingToken.address, poolSafeContract.address, paymentAmount, gasOpts);
129
+ await (approveERC20Tx === null || approveERC20Tx === void 0 ? void 0 : approveERC20Tx.wait(5));
130
+ const approveTx = await (0, ReceivableContractHelper_1.approveReceivableTransferIfNeeded)(signer, poolName, drawdownReceivableId);
131
+ await (approveTx === null || approveTx === void 0 ? void 0 : approveTx.wait(5));
132
+ return creditContract.makePrincipalPaymentAndDrawdownWithReceivable(paymentReceivableId, paymentAmount, drawdownReceivableId, drawdownAmount, gasOpts);
133
+ }
134
+ exports.makePrincipalPaymentAndDrawdownWithReceivable = makePrincipalPaymentAndDrawdownWithReceivable;
135
+ //# sourceMappingURL=ReceivableBackedCreditLineContractHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReceivableBackedCreditLineContractHelper.js","sourceRoot":"","sources":["../../../../src/helpers/v2/ReceivableBackedCreditLineContractHelper.ts"],"names":[],"mappings":";;;AAKA,iDAS6B;AAG7B,uCAAyC;AACzC,gEAA4E;AAC5E,yEAA8E;AAE9E;;;;;;;GAOG;AACI,KAAK,UAAU,uCAAuC,CAC3D,QAAmB,EACnB,gBAAgE;IAEhE,MAAM,OAAO,GAAG,MAAM,IAAA,uCAA8B,EAAC,gBAAgB,CAAC,CAAA;IACtE,MAAM,QAAQ,GAAG,IAAA,sBAAa,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACjD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,KAAK,kBAAS,CAAC,0BAA0B,EAAE;QAC3E,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAA,mBAAW,EAChB,QAAQ,CAAC,UAAU,EACnB,6CAAoC,EACpC,gBAAgB,CACjB,CAAA;AACH,CAAC;AAfD,0FAeC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,aAAa,CACjC,QAAmB,EACnB,OAAe,EACf,QAAwC;IAExC,MAAM,YAAY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AAG,MAAM,IAAA,8BAAqB,EAClD,QAAQ,EACR,MAAM,CAAC,QAAsD,CAC9D,CAAA;IAED,IAAI,CAAC,gBAAgB,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;KAC5D;IAED,MAAM,cAAc,GAAG,MAAM,IAAA,yDAAmC,EAC9D,MAAM,EACN,eAAe,CAAC,OAAO,EACvB,gBAAgB,CAAC,OAAO,EACxB,aAAa,EACb,OAAO,CACR,CAAA;IACD,MAAM,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,CAAC,CAAC,CAAA,CAAA;IAE7B,MAAM,SAAS,GAAG,MAAM,IAAA,4DAAiC,EACvD,MAAM,EACN,QAAQ,EACR,oBAAoB,CACrB,CAAA;IACD,MAAM,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,CAAC,CAAC,CAAC,CAAA,CAAA;IAExB,OAAO,cAAc,CAAC,6CAA6C,CACjE,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,OAAO,CACR,CAAA;AACH,CAAC;AA3DD,sGA2DC"}
@@ -0,0 +1,15 @@
1
+ import { BigNumber, BigNumberish, Overrides, ethers } from 'ethers';
2
+ import { POOL_NAME, v2Contracts } from '@huma-finance/shared';
3
+ import { JsonRpcProvider, TransactionResponse, Web3Provider } from '@ethersproject/providers';
4
+ /**
5
+ * Returns an ethers contract instance for the V2 Receivable contract
6
+ * associated with the given pool name on the current chain.
7
+ *
8
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
9
+ * @param {number} chainId The chain id where the contract instance exists
10
+ * @returns {Contract | null} A contract instance for the Receivable contract or null if it could not be found.
11
+ */
12
+ export declare function getReceivableContractV2(poolName: POOL_NAME, signerOrProvider: JsonRpcProvider | Web3Provider | ethers.Signer): Promise<v2Contracts.Receivable | null>;
13
+ export declare function getReceivableTokenIdFromReferenceId(referenceId: string, creator: string, poolName: POOL_NAME, provider: JsonRpcProvider | Web3Provider): Promise<BigNumber>;
14
+ export declare function getReceivableReferenceAlreadyExists(referenceId: string, signerAddress: string, poolName: POOL_NAME, provider: JsonRpcProvider | Web3Provider): Promise<boolean>;
15
+ export declare function approveReceivableTransferIfNeeded(signer: ethers.Signer, poolName: POOL_NAME, receivableId: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse | null>;