@huma-finance/sdk 0.0.48-beta.200 → 0.0.48-v2.278

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 (143) hide show
  1. package/API.md +134 -0
  2. package/dist/cjs/graphql/generatedTypes.d.ts +40 -40
  3. package/dist/cjs/graphql/generatedTypes.js +8 -8
  4. package/dist/cjs/graphql/index.d.ts +1 -1
  5. package/dist/cjs/graphql/index.js +4 -4
  6. package/dist/cjs/helpers/ERC20ContractHelper.d.ts +16 -0
  7. package/dist/cjs/helpers/ERC20ContractHelper.js +33 -0
  8. package/dist/cjs/helpers/ERC20ContractHelper.js.map +1 -0
  9. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  10. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +21 -21
  11. package/dist/cjs/helpers/PoolContractHelper.d.ts +119 -119
  12. package/dist/cjs/helpers/PoolContractHelper.js +140 -143
  13. package/dist/cjs/helpers/PoolContractHelper.js.map +1 -1
  14. package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  15. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +21 -21
  16. package/dist/cjs/helpers/index.d.ts +5 -3
  17. package/dist/cjs/helpers/index.js +8 -6
  18. package/dist/cjs/helpers/index.js.map +1 -1
  19. package/dist/cjs/helpers/v2/ReceivableBackedCreditLineContractHelper.d.ts +55 -0
  20. package/dist/cjs/helpers/v2/ReceivableBackedCreditLineContractHelper.js +102 -0
  21. package/dist/cjs/helpers/v2/ReceivableBackedCreditLineContractHelper.js.map +1 -0
  22. package/dist/cjs/helpers/v2/ReceivableContractHelper.d.ts +14 -0
  23. package/dist/cjs/helpers/v2/ReceivableContractHelper.js +45 -0
  24. package/dist/cjs/helpers/v2/ReceivableContractHelper.js.map +1 -0
  25. package/dist/cjs/hooks/index.d.ts +4 -4
  26. package/dist/cjs/hooks/index.js +7 -7
  27. package/dist/cjs/hooks/useContract.d.ts +13 -13
  28. package/dist/cjs/hooks/useContract.js +30 -30
  29. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  30. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +20 -20
  31. package/dist/cjs/hooks/usePoolContract.d.ts +60 -60
  32. package/dist/cjs/hooks/usePoolContract.js +53 -53
  33. package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -10
  34. package/dist/cjs/hooks/useRealWorldReceivableContract.js +19 -19
  35. package/dist/cjs/index.d.ts +4 -4
  36. package/dist/cjs/index.js +7 -7
  37. package/dist/cjs/services/ARWeaveService.d.ts +115 -115
  38. package/dist/cjs/services/ARWeaveService.js +196 -196
  39. package/dist/cjs/services/EAService.d.ts +20 -20
  40. package/dist/cjs/services/EAService.js +33 -33
  41. package/dist/cjs/services/ReceivableService.d.ts +150 -150
  42. package/dist/cjs/services/ReceivableService.js +300 -301
  43. package/dist/cjs/services/ReceivableService.js.map +1 -1
  44. package/dist/cjs/services/SubgraphService.d.ts +106 -93
  45. package/dist/cjs/services/SubgraphService.js +215 -138
  46. package/dist/cjs/services/SubgraphService.js.map +1 -1
  47. package/dist/cjs/services/index.d.ts +7 -4
  48. package/dist/cjs/services/index.js +10 -7
  49. package/dist/cjs/services/index.js.map +1 -1
  50. package/dist/cjs/services/v2/HumaContext.d.ts +23 -0
  51. package/dist/cjs/services/v2/HumaContext.js +55 -0
  52. package/dist/cjs/services/v2/HumaContext.js.map +1 -0
  53. package/dist/cjs/services/v2/HumaReceivableFactory.d.ts +21 -0
  54. package/dist/cjs/services/v2/HumaReceivableFactory.js +77 -0
  55. package/dist/cjs/services/v2/HumaReceivableFactory.js.map +1 -0
  56. package/dist/cjs/services/v2/HumaReceivableHandler.d.ts +10 -0
  57. package/dist/cjs/services/v2/HumaReceivableHandler.js +32 -0
  58. package/dist/cjs/services/v2/HumaReceivableHandler.js.map +1 -0
  59. package/dist/cjs/utils/chain.d.ts +15 -15
  60. package/dist/cjs/utils/chain.js +29 -37
  61. package/dist/cjs/utils/chain.js.map +1 -1
  62. package/dist/cjs/utils/index.d.ts +4 -4
  63. package/dist/cjs/utils/index.js +7 -7
  64. package/dist/cjs/utils/maticGasStation.d.ts +3 -3
  65. package/dist/cjs/utils/maticGasStation.js +38 -38
  66. package/dist/cjs/utils/poolInfo.d.ts +8 -8
  67. package/dist/cjs/utils/poolInfo.js +12 -12
  68. package/dist/cjs/utils/poolInfo.js.map +1 -1
  69. package/dist/cjs/utils/web3.d.ts +6 -5
  70. package/dist/cjs/utils/web3.js +33 -33
  71. package/dist/cjs/utils/web3.js.map +1 -1
  72. package/dist/graphql/generatedTypes.d.ts +40 -40
  73. package/dist/graphql/generatedTypes.js +4 -4
  74. package/dist/graphql/index.d.ts +1 -1
  75. package/dist/graphql/index.js +1 -1
  76. package/dist/helpers/ERC20ContractHelper.d.ts +16 -0
  77. package/dist/helpers/ERC20ContractHelper.js +29 -0
  78. package/dist/helpers/ERC20ContractHelper.js.map +1 -0
  79. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  80. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
  81. package/dist/helpers/PoolContractHelper.d.ts +119 -119
  82. package/dist/helpers/PoolContractHelper.js +131 -134
  83. package/dist/helpers/PoolContractHelper.js.map +1 -1
  84. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  85. package/dist/helpers/RealWorldReceivableContractHelper.js +17 -17
  86. package/dist/helpers/index.d.ts +5 -3
  87. package/dist/helpers/index.js +5 -3
  88. package/dist/helpers/index.js.map +1 -1
  89. package/dist/helpers/v2/ReceivableBackedCreditLineContractHelper.d.ts +55 -0
  90. package/dist/helpers/v2/ReceivableBackedCreditLineContractHelper.js +95 -0
  91. package/dist/helpers/v2/ReceivableBackedCreditLineContractHelper.js.map +1 -0
  92. package/dist/helpers/v2/ReceivableContractHelper.d.ts +14 -0
  93. package/dist/helpers/v2/ReceivableContractHelper.js +39 -0
  94. package/dist/helpers/v2/ReceivableContractHelper.js.map +1 -0
  95. package/dist/hooks/index.d.ts +4 -4
  96. package/dist/hooks/index.js +4 -4
  97. package/dist/hooks/useContract.d.ts +13 -13
  98. package/dist/hooks/useContract.js +26 -26
  99. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  100. package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
  101. package/dist/hooks/usePoolContract.d.ts +60 -60
  102. package/dist/hooks/usePoolContract.js +48 -48
  103. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -10
  104. package/dist/hooks/useRealWorldReceivableContract.js +15 -15
  105. package/dist/index.d.ts +4 -4
  106. package/dist/index.js +4 -4
  107. package/dist/services/ARWeaveService.d.ts +115 -115
  108. package/dist/services/ARWeaveService.js +191 -191
  109. package/dist/services/EAService.d.ts +20 -20
  110. package/dist/services/EAService.js +30 -30
  111. package/dist/services/ReceivableService.d.ts +150 -150
  112. package/dist/services/ReceivableService.js +297 -298
  113. package/dist/services/ReceivableService.js.map +1 -1
  114. package/dist/services/SubgraphService.d.ts +106 -93
  115. package/dist/services/SubgraphService.js +212 -135
  116. package/dist/services/SubgraphService.js.map +1 -1
  117. package/dist/services/index.d.ts +7 -4
  118. package/dist/services/index.js +7 -4
  119. package/dist/services/index.js.map +1 -1
  120. package/dist/services/v2/HumaContext.d.ts +23 -0
  121. package/dist/services/v2/HumaContext.js +51 -0
  122. package/dist/services/v2/HumaContext.js.map +1 -0
  123. package/dist/services/v2/HumaReceivableFactory.d.ts +21 -0
  124. package/dist/services/v2/HumaReceivableFactory.js +73 -0
  125. package/dist/services/v2/HumaReceivableFactory.js.map +1 -0
  126. package/dist/services/v2/HumaReceivableHandler.d.ts +10 -0
  127. package/dist/services/v2/HumaReceivableHandler.js +28 -0
  128. package/dist/services/v2/HumaReceivableHandler.js.map +1 -0
  129. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  130. package/dist/utils/chain.d.ts +15 -15
  131. package/dist/utils/chain.js +23 -31
  132. package/dist/utils/chain.js.map +1 -1
  133. package/dist/utils/index.d.ts +4 -4
  134. package/dist/utils/index.js +4 -4
  135. package/dist/utils/maticGasStation.d.ts +3 -3
  136. package/dist/utils/maticGasStation.js +33 -33
  137. package/dist/utils/poolInfo.d.ts +8 -8
  138. package/dist/utils/poolInfo.js +8 -8
  139. package/dist/utils/poolInfo.js.map +1 -1
  140. package/dist/utils/web3.d.ts +6 -5
  141. package/dist/utils/web3.js +27 -27
  142. package/dist/utils/web3.js.map +1 -1
  143. 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,18 @@ 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="#drawdownWithReceivable">drawdownWithReceivable(signer, poolName, receivableId, drawdownAmount, [gasOpts])</a> ⇒ <code>Promise.&lt;TransactionResponse&gt;</code></dt>
47
+ <dd><p>Draws down from a pool using a receivable.</p></dd>
48
+ <dt><a href="#makePaymentWithReceivable">makePaymentWithReceivable(signer, poolName, receivableId, paymentAmount, principalOnly, [gasOpts])</a> ⇒ <code>Promise.&lt;TransactionResponse&gt;</code></dt>
49
+ <dd><p>Makes a payment with a receivable.</p></dd>
50
+ <dt><a href="#makePrincipalPaymentAndDrawdownWithReceivable">makePrincipalPaymentAndDrawdownWithReceivable(signer, poolName, paymentReceivableId, paymentAmount, drawdownReceivableId, drawdownAmount, [gasOpts])</a> ⇒ <code>Promise.&lt;TransactionResponse&gt;</code></dt>
51
+ <dd><p>Makes a principal payment and drawdown with receivables.</p></dd>
52
+ <dt><a href="#getReceivableContractV2">getReceivableContractV2(signerOrProvider, chainId)</a> ⇒ <code>Contract</code> | <code>null</code></dt>
53
+ <dd><p>Returns an ethers contract instance for the V2 Receivable contract
54
+ associated with the given pool name on the current chain.</p></dd>
40
55
  <dt><a href="#useContract">useContract(address, ABI, signerOrProvider)</a> ⇒ <code>T</code> | <code>null</code></dt>
41
56
  <dd><p>Custom hook for creating an ethers instance of a smart contract.</p></dd>
42
57
  <dt><a href="#useERC20TransferableReceivableContract">useERC20TransferableReceivableContract(signerOrProvider, chainId, poolName)</a> ⇒ <code>Contract</code> | <code>null</code></dt>
@@ -475,6 +490,7 @@ in Huma's pools that can be drawn down by the borrower.</p>
475
490
  * [.getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType)](#SubgraphService.getLastFactorizedAmountFromPool) ⇒ <code>Promise.&lt;number&gt;</code>
476
491
  * [.getRWReceivableInfo(userAddress, chainId, poolName, poolType, pagination)](#SubgraphService.getRWReceivableInfo) ⇒ <code>Promise.&lt;RealWorldReceivableInfoBase&gt;</code>
477
492
  * [.getPoolStats(chainId, pool)](#SubgraphService.getPoolStats) ⇒ <code>Promise.&lt;{PoolStats}&gt;</code>
493
+ * [.checkBorrowAndLendHistory(chainId, pool, userAddress)](#SubgraphService.checkBorrowAndLendHistory) ⇒ <code>Promise.&lt;{hasBorrowHistory: boolean, hasLendHistory: boolean}&gt;</code>
478
494
 
479
495
  <a name="SubgraphService.getSubgraphUrlForChainId"></a>
480
496
 
@@ -548,12 +564,45 @@ in Huma's pools that can be drawn down by the borrower.</p>
548
564
  | chainId | <code>number</code> | <p>The ID of the chain.</p> |
549
565
  | pool | <code>string</code> | <p>The address of the pool.</p> |
550
566
 
567
+ <a name="SubgraphService.checkBorrowAndLendHistory"></a>
568
+
569
+ ### SubgraphService.checkBorrowAndLendHistory(chainId, pool, userAddress) ⇒ <code>Promise.&lt;{hasBorrowHistory: boolean, hasLendHistory: boolean}&gt;</code>
570
+ <p>Returns if user has borrow or lend history.</p>
571
+
572
+ **Kind**: static method of [<code>SubgraphService</code>](#SubgraphService)
573
+ **Returns**: <code>Promise.&lt;{hasBorrowHistory: boolean, hasLendHistory: boolean}&gt;</code> - <p>If user has borrow or lend history.</p>
574
+
575
+ | Param | Type | Description |
576
+ | --- | --- | --- |
577
+ | chainId | <code>number</code> | <p>The ID of the chain.</p> |
578
+ | pool | <code>string</code> | <p>The address of the pool.</p> |
579
+ | userAddress | <code>string</code> | <p>The address of the user.</p> |
580
+
551
581
  <a name="defaultWrapper"></a>
552
582
 
553
583
  ## defaultWrapper()
554
584
  <p>All built-in and custom scalars, mapped to their actual values</p>
555
585
 
556
586
  **Kind**: global function
587
+ <a name="approveERC20AllowanceIfInsufficient"></a>
588
+
589
+ ## approveERC20AllowanceIfInsufficient(signer, tokenAddress, spenderAddress, allowanceAmount, [gasOpts]) ⇒ <code>Promise.&lt;(TransactionResponse\|null)&gt;</code>
590
+ <p>Approves an ERC20 allowance for a spender address, if the current allowance is insufficient.
591
+ Allowance is required to do certain actions on the Huma protocol (e.g. makePayment)</p>
592
+
593
+ **Kind**: global function
594
+ **Returns**: <code>Promise.&lt;(TransactionResponse\|null)&gt;</code> - <ul>
595
+ <li>A Promise of the transaction response, or null if the allowance was already sufficient.</li>
596
+ </ul>
597
+
598
+ | Param | Type | Description |
599
+ | --- | --- | --- |
600
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
601
+ | tokenAddress | <code>string</code> | <p>The address of the ERC20 token to approve.</p> |
602
+ | spenderAddress | <code>string</code> | <p>The address of the spender to approve an allowance for.</p> |
603
+ | allowanceAmount | <code>BigNumber</code> | <p>The amount of tokens to approve, if applicable. Denominated in the ERC20 tokens.</p> |
604
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
605
+
557
606
  <a name="getERC20TransferableReceivableContract"></a>
558
607
 
559
608
  ## getERC20TransferableReceivableContract(signerOrProvider, chainId) ⇒ <code>Contract</code> \| <code>null</code>
@@ -710,6 +759,91 @@ associated with the given pool name on the current chain.</p>
710
759
  | signerOrProvider | <code>ethers.providers.Provider</code> \| <code>ethers.Signer</code> | <p>The provider or signer instance to use for the contract.</p> |
711
760
  | chainId | <code>number</code> | <p>The chain id where the contract instance exists</p> |
712
761
 
762
+ <a name="getReceivableBackedCreditLineContractV2"></a>
763
+
764
+ ## getReceivableBackedCreditLineContractV2(signerOrProvider, poolName) ⇒ <code>ReceivableBackedCreditLine</code> \| <code>null</code>
765
+ <p>Returns an ethers contract instance for the V2 Receivable contract
766
+ associated with the given pool name on the current chain.</p>
767
+
768
+ **Kind**: global function
769
+ **Returns**: <code>ReceivableBackedCreditLine</code> \| <code>null</code> - <p>A contract instance for the ReceivableBackedCreditLine contract or null if it could not be found.</p>
770
+
771
+ | Param | Type | Description |
772
+ | --- | --- | --- |
773
+ | signerOrProvider | <code>ethers.providers.Provider</code> \| <code>ethers.Signer</code> | <p>The provider or signer instance to use for the contract.</p> |
774
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to get the contract instance for.</p> |
775
+
776
+ <a name="drawdownWithReceivable"></a>
777
+
778
+ ## drawdownWithReceivable(signer, poolName, receivableId, drawdownAmount, [gasOpts]) ⇒ <code>Promise.&lt;TransactionResponse&gt;</code>
779
+ <p>Draws down from a pool using a receivable.</p>
780
+
781
+ **Kind**: global function
782
+ **Returns**: <code>Promise.&lt;TransactionResponse&gt;</code> - <ul>
783
+ <li>A Promise of the transaction response.</li>
784
+ </ul>
785
+
786
+ | Param | Type | Description |
787
+ | --- | --- | --- |
788
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
789
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the credit pool to drawdown from.</p> |
790
+ | receivableId | <code>BigNumberish</code> | <p>The ID of the receivable.</p> |
791
+ | drawdownAmount | <code>BigNumberish</code> | <p>The amount to drawdown.</p> |
792
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
793
+
794
+ <a name="makePaymentWithReceivable"></a>
795
+
796
+ ## makePaymentWithReceivable(signer, poolName, receivableId, paymentAmount, principalOnly, [gasOpts]) ⇒ <code>Promise.&lt;TransactionResponse&gt;</code>
797
+ <p>Makes a payment with a receivable.</p>
798
+
799
+ **Kind**: global function
800
+ **Returns**: <code>Promise.&lt;TransactionResponse&gt;</code> - <ul>
801
+ <li>A Promise of the transaction response.</li>
802
+ </ul>
803
+
804
+ | Param | Type | Description |
805
+ | --- | --- | --- |
806
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
807
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the pool to interact with.</p> |
808
+ | receivableId | <code>BigNumberish</code> | <p>The ID of the receivable.</p> |
809
+ | paymentAmount | <code>BigNumberish</code> | <p>The amount to payback.</p> |
810
+ | principalOnly | <code>boolean</code> | <p>Whether this payment should ONLY apply to the principal</p> |
811
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
812
+
813
+ <a name="makePrincipalPaymentAndDrawdownWithReceivable"></a>
814
+
815
+ ## makePrincipalPaymentAndDrawdownWithReceivable(signer, poolName, paymentReceivableId, paymentAmount, drawdownReceivableId, drawdownAmount, [gasOpts]) ⇒ <code>Promise.&lt;TransactionResponse&gt;</code>
816
+ <p>Makes a principal payment and drawdown with receivables.</p>
817
+
818
+ **Kind**: global function
819
+ **Returns**: <code>Promise.&lt;TransactionResponse&gt;</code> - <ul>
820
+ <li>A Promise of the transaction response.</li>
821
+ </ul>
822
+
823
+ | Param | Type | Description |
824
+ | --- | --- | --- |
825
+ | signer | <code>ethers.Signer</code> | <p>The signer used to send the transaction.</p> |
826
+ | poolName | <code>POOL\_NAME</code> | <p>The name of the pool to interact with.</p> |
827
+ | paymentReceivableId | <code>BigNumberish</code> | <p>The ID of the receivable for payment.</p> |
828
+ | paymentAmount | <code>BigNumberish</code> | <p>The amount to payback.</p> |
829
+ | drawdownReceivableId | <code>BigNumberish</code> | <p>The ID of the drawdown receivable.</p> |
830
+ | drawdownAmount | <code>BigNumberish</code> | <p>The amount to drawdown.</p> |
831
+ | [gasOpts] | <code>Overrides</code> | <p>The gas options to use for the transaction.</p> |
832
+
833
+ <a name="getReceivableContractV2"></a>
834
+
835
+ ## getReceivableContractV2(signerOrProvider, chainId) ⇒ <code>Contract</code> \| <code>null</code>
836
+ <p>Returns an ethers contract instance for the V2 Receivable contract
837
+ associated with the given pool name on the current chain.</p>
838
+
839
+ **Kind**: global function
840
+ **Returns**: <code>Contract</code> \| <code>null</code> - <p>A contract instance for the Receivable contract or null if it could not be found.</p>
841
+
842
+ | Param | Type | Description |
843
+ | --- | --- | --- |
844
+ | signerOrProvider | <code>ethers.providers.Provider</code> \| <code>ethers.Signer</code> | <p>The provider or signer instance to use for the contract.</p> |
845
+ | chainId | <code>number</code> | <p>The chain id where the contract instance exists</p> |
846
+
713
847
  <a name="useContract"></a>
714
848
 
715
849
  ## useContract(address, ABI, signerOrProvider) ⇒ <code>T</code> \| <code>null</code>
@@ -1,40 +1,40 @@
1
- import { GraphQLClient } from 'graphql-request';
2
- export type Maybe<T> = T | null;
3
- export type InputMaybe<T> = Maybe<T>;
4
- export type Exact<T extends {
5
- [key: string]: unknown;
6
- }> = {
7
- [K in keyof T]: T[K];
8
- };
9
- export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
10
- [SubKey in K]?: Maybe<T[SubKey]>;
11
- };
12
- export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
13
- [SubKey in K]: Maybe<T[SubKey]>;
14
- };
15
- /** All built-in and custom scalars, mapped to their actual values */
16
- export type Scalars = {
17
- ID: string;
18
- String: string;
19
- Boolean: boolean;
20
- Int: number;
21
- Float: number;
22
- };
23
- export type Receivable = {
24
- __typename?: 'Receivable';
25
- creationDate?: Maybe<Scalars['String']>;
26
- currencyCode?: Maybe<Scalars['String']>;
27
- id?: Maybe<Scalars['String']>;
28
- lastUpdate?: Maybe<Scalars['String']>;
29
- maturityDate?: Maybe<Scalars['String']>;
30
- owner?: Maybe<Scalars['String']>;
31
- paidAmount?: Maybe<Scalars['String']>;
32
- pool?: Maybe<Scalars['String']>;
33
- receivableAmount?: Maybe<Scalars['String']>;
34
- status?: Maybe<Scalars['String']>;
35
- tokenId?: Maybe<Scalars['String']>;
36
- uri?: Maybe<Scalars['String']>;
37
- };
38
- export type SdkFunctionWrapper = <T>(action: (requestHeaders?: Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
39
- export declare function getSdk(client: GraphQLClient, withWrapper?: SdkFunctionWrapper): {};
40
- export type Sdk = ReturnType<typeof getSdk>;
1
+ import { GraphQLClient } from 'graphql-request';
2
+ export type Maybe<T> = T | null;
3
+ export type InputMaybe<T> = Maybe<T>;
4
+ export type Exact<T extends {
5
+ [key: string]: unknown;
6
+ }> = {
7
+ [K in keyof T]: T[K];
8
+ };
9
+ export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
10
+ [SubKey in K]?: Maybe<T[SubKey]>;
11
+ };
12
+ export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
13
+ [SubKey in K]: Maybe<T[SubKey]>;
14
+ };
15
+ /** All built-in and custom scalars, mapped to their actual values */
16
+ export type Scalars = {
17
+ ID: string;
18
+ String: string;
19
+ Boolean: boolean;
20
+ Int: number;
21
+ Float: number;
22
+ };
23
+ export type Receivable = {
24
+ __typename?: 'Receivable';
25
+ creationDate?: Maybe<Scalars['String']>;
26
+ currencyCode?: Maybe<Scalars['String']>;
27
+ id?: Maybe<Scalars['String']>;
28
+ lastUpdate?: Maybe<Scalars['String']>;
29
+ maturityDate?: Maybe<Scalars['String']>;
30
+ owner?: Maybe<Scalars['String']>;
31
+ paidAmount?: Maybe<Scalars['String']>;
32
+ pool?: Maybe<Scalars['String']>;
33
+ receivableAmount?: Maybe<Scalars['String']>;
34
+ status?: Maybe<Scalars['String']>;
35
+ tokenId?: Maybe<Scalars['String']>;
36
+ uri?: Maybe<Scalars['String']>;
37
+ };
38
+ export type SdkFunctionWrapper = <T>(action: (requestHeaders?: Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
39
+ export declare function getSdk(client: GraphQLClient, withWrapper?: SdkFunctionWrapper): {};
40
+ export type Sdk = ReturnType<typeof getSdk>;
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSdk = void 0;
4
- const defaultWrapper = (action, _operationName, _operationType) => action();
5
- function getSdk(client, withWrapper = defaultWrapper) {
6
- return {};
7
- }
8
- exports.getSdk = getSdk;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSdk = void 0;
4
+ const defaultWrapper = (action, _operationName, _operationType) => action();
5
+ function getSdk(client, withWrapper = defaultWrapper) {
6
+ return {};
7
+ }
8
+ exports.getSdk = getSdk;
9
9
  //# sourceMappingURL=generatedTypes.js.map
@@ -1 +1 @@
1
- export * from './generatedTypes';
1
+ export * from './generatedTypes';
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./generatedTypes"), exports);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./generatedTypes"), exports);
5
5
  //# sourceMappingURL=index.js.map
@@ -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,10 +1,10 @@
1
- import { Contract, ethers } from 'ethers';
2
- /**
3
- * Returns an ethers contract instance for the ERC20TransferableReceivable contract
4
- * associated with the given pool name on the current chain.
5
- *
6
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
7
- * @param {number} chainId The chain id where the contract instance exists
8
- * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
9
- */
10
- export declare function getERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
1
+ import { Contract, ethers } from 'ethers';
2
+ /**
3
+ * Returns an ethers contract instance for the ERC20TransferableReceivable contract
4
+ * associated with the given pool name on the current chain.
5
+ *
6
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
7
+ * @param {number} chainId The chain id where the contract instance exists
8
+ * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
9
+ */
10
+ export declare function getERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getERC20TransferableReceivableContract = void 0;
4
- const shared_1 = require("@huma-finance/shared");
5
- const utils_1 = require("../utils");
6
- /**
7
- * Returns an ethers contract instance for the ERC20TransferableReceivable contract
8
- * associated with the given pool name on the current chain.
9
- *
10
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
11
- * @param {number} chainId The chain id where the contract instance exists
12
- * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
13
- */
14
- function getERC20TransferableReceivableContract(signerOrProvider, chainId) {
15
- var _a;
16
- const erc20TransferableReceiable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.ERC20TransferableReceivable];
17
- if (!erc20TransferableReceiable)
18
- return null;
19
- return (0, utils_1.getContract)(erc20TransferableReceiable, shared_1.ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
20
- }
21
- exports.getERC20TransferableReceivableContract = getERC20TransferableReceivableContract;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getERC20TransferableReceivableContract = void 0;
4
+ const shared_1 = require("@huma-finance/shared");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * Returns an ethers contract instance for the ERC20TransferableReceivable contract
8
+ * associated with the given pool name on the current chain.
9
+ *
10
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
11
+ * @param {number} chainId The chain id where the contract instance exists
12
+ * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
13
+ */
14
+ function getERC20TransferableReceivableContract(signerOrProvider, chainId) {
15
+ var _a;
16
+ const erc20TransferableReceiable = (_a = shared_1.SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[shared_1.SupplementaryContracts.ERC20TransferableReceivable];
17
+ if (!erc20TransferableReceiable)
18
+ return null;
19
+ return (0, utils_1.getContract)(erc20TransferableReceiable, shared_1.ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
20
+ }
21
+ exports.getERC20TransferableReceivableContract = getERC20TransferableReceivableContract;
22
22
  //# sourceMappingURL=ERC20TransferableReceivableContractHelper.js.map