@huma-finance/sdk 0.0.11 → 0.0.13

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 (67) hide show
  1. package/API.md +482 -0
  2. package/README.md +9 -5
  3. package/dist/cjs/graphql/generatedTypes.d.ts +40 -0
  4. package/dist/cjs/graphql/generatedTypes.js +9 -0
  5. package/dist/cjs/graphql/generatedTypes.js.map +1 -0
  6. package/dist/cjs/graphql/index.d.ts +1 -0
  7. package/dist/cjs/graphql/index.js +5 -0
  8. package/dist/cjs/graphql/index.js.map +1 -0
  9. package/dist/cjs/helpers/PoolContractHelper.d.ts +30 -1
  10. package/dist/cjs/helpers/PoolContractHelper.js +45 -1
  11. package/dist/cjs/helpers/PoolContractHelper.js.map +1 -1
  12. package/dist/cjs/services/ARWeaveService.d.ts +1 -18
  13. package/dist/cjs/services/ARWeaveService.js +17 -51
  14. package/dist/cjs/services/ARWeaveService.js.map +1 -1
  15. package/dist/cjs/services/ReceivableService.d.ts +11 -0
  16. package/dist/cjs/services/ReceivableService.js +71 -20
  17. package/dist/cjs/services/ReceivableService.js.map +1 -1
  18. package/dist/graphql/generatedTypes.d.ts +40 -0
  19. package/dist/graphql/generatedTypes.js +5 -0
  20. package/dist/graphql/generatedTypes.js.map +1 -0
  21. package/dist/graphql/index.d.ts +1 -0
  22. package/dist/graphql/index.js +2 -0
  23. package/dist/graphql/index.js.map +1 -0
  24. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -10
  25. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
  26. package/dist/helpers/PoolContractHelper.d.ts +41 -12
  27. package/dist/helpers/PoolContractHelper.js +58 -16
  28. package/dist/helpers/PoolContractHelper.js.map +1 -1
  29. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
  30. package/dist/helpers/RealWorldReceivableContractHelper.js +17 -17
  31. package/dist/helpers/index.d.ts +3 -3
  32. package/dist/helpers/index.js +3 -3
  33. package/dist/hooks/index.d.ts +4 -4
  34. package/dist/hooks/index.js +4 -4
  35. package/dist/hooks/useContract.d.ts +13 -13
  36. package/dist/hooks/useContract.js +26 -26
  37. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
  38. package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
  39. package/dist/hooks/usePoolContract.d.ts +60 -60
  40. package/dist/hooks/usePoolContract.js +48 -48
  41. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -10
  42. package/dist/hooks/useRealWorldReceivableContract.js +15 -15
  43. package/dist/index.d.ts +4 -4
  44. package/dist/index.js +4 -4
  45. package/dist/services/ARWeaveService.d.ts +81 -84
  46. package/dist/services/ARWeaveService.js +133 -144
  47. package/dist/services/ARWeaveService.js.map +1 -1
  48. package/dist/services/EAService.d.ts +18 -18
  49. package/dist/services/EAService.js +9 -9
  50. package/dist/services/ReceivableService.d.ts +87 -76
  51. package/dist/services/ReceivableService.js +182 -132
  52. package/dist/services/ReceivableService.js.map +1 -1
  53. package/dist/services/SubgraphService.d.ts +53 -53
  54. package/dist/services/SubgraphService.js +79 -79
  55. package/dist/services/index.d.ts +4 -4
  56. package/dist/services/index.js +4 -4
  57. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  58. package/dist/utils/chain.d.ts +14 -14
  59. package/dist/utils/chain.js +28 -28
  60. package/dist/utils/index.d.ts +3 -3
  61. package/dist/utils/index.js +3 -3
  62. package/dist/utils/poolInfo.d.ts +9 -9
  63. package/dist/utils/poolInfo.js +9 -9
  64. package/dist/utils/web3.d.ts +4 -4
  65. package/dist/utils/web3.js +23 -23
  66. package/getting-started.md +191 -0
  67. package/package.json +13 -6
@@ -1,17 +1,59 @@
1
- import { getContract, getPoolInfo } from '../utils';
2
- /**
3
- * Returns an ethers contract instance for a Huma pool contract
4
- *
5
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
6
- * @param {number} chainId The chain id where the contract instance exists
7
- * @param {POOL_NAME} poolName The name of the pool contract to get.
8
- * @param {POOL_TYPE} poolType The type of the pool contract to get.
9
- * @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
10
- */
11
- export function getPoolContract(signerOrProvider, chainId, poolName, poolType) {
12
- const poolInfo = getPoolInfo(chainId, poolName, poolType);
13
- if (!poolInfo)
14
- return null;
15
- return getContract(poolInfo.pool, poolInfo.poolAbi, signerOrProvider);
16
- }
1
+ import { getContract, getPoolInfo } from '../utils';
2
+ /**
3
+ * Returns an ethers contract instance for a Huma pool contract
4
+ *
5
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
6
+ * @param {number} chainId The chain id where the contract instance exists
7
+ * @param {POOL_NAME} poolName The name of the pool contract to get.
8
+ * @param {POOL_TYPE} poolType The type of the pool contract to get.
9
+ * @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
10
+ */
11
+ export function getPoolContract(signerOrProvider, chainId, poolName, poolType) {
12
+ const poolInfo = getPoolInfo(chainId, poolName, poolType);
13
+ if (!poolInfo)
14
+ return null;
15
+ return getContract(poolInfo.pool, poolInfo.poolAbi, signerOrProvider);
16
+ }
17
+ /**
18
+ * Calls drawdown on a Huma pool contract
19
+ *
20
+ * @async
21
+ * @function
22
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
23
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
24
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
25
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
26
+ * @param {BigNumberish} drawdownAmount - The amount of tokens to withdraw, denominated in the ERC20 tokens of the pool.
27
+ * @param {Overrides} gasOpts - The gas options to use for the transaction.
28
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
29
+ */
30
+ export function drawdownFromPool(signer, chainId, poolName, poolType, drawdownAmount, gasOpts = {}) {
31
+ const poolContract = getPoolContract(signer, chainId, poolName, poolType);
32
+ if (!poolContract) {
33
+ throw new Error('Could not find pool contract');
34
+ }
35
+ // TODO: Generate typechain for pool contract
36
+ return poolContract.drawdown(drawdownAmount, gasOpts);
37
+ }
38
+ /**
39
+ * Calls drawdown on a Huma pool contract
40
+ *
41
+ * @async
42
+ * @function
43
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
44
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
45
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
46
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
47
+ * @param {BigNumberish} paymentAmount - The amount of tokens to payback, denominated in the ERC20 tokens of the pool.
48
+ * @param {Overrides} gasOpts - The gas options to use for the transaction.
49
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
50
+ */
51
+ export async function makePaymentToPool(signer, chainId, poolName, poolType, paymentAmount, gasOpts = {}) {
52
+ const poolContract = getPoolContract(signer, chainId, poolName, poolType);
53
+ if (!poolContract) {
54
+ throw new Error('Could not find pool contract');
55
+ }
56
+ // TODO: Generate typechain for pool contract
57
+ return poolContract.makePayment(await signer.getAddress(), paymentAmount, gasOpts);
58
+ }
17
59
  //# sourceMappingURL=PoolContractHelper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PoolContractHelper.js","sourceRoot":"","sources":["../../src/helpers/PoolContractHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEnD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,gBAA2D,EAC3D,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAEzD,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAE1B,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;AACvE,CAAC"}
1
+ {"version":3,"file":"PoolContractHelper.js","sourceRoot":"","sources":["../../src/helpers/PoolContractHelper.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEnD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,gBAA2D,EAC3D,OAAe,EACf,QAAmB,EACnB,QAAmB;IAEnB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAEzD,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAE1B,OAAO,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;AACvE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAqB,EACrB,OAAe,EACf,QAAmB,EACnB,QAAmB,EACnB,cAA4B,EAC5B,UAAqB,EAAE;IAEvB,MAAM,YAAY,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,6CAA6C;IAC7C,OAAO,YAAY,CAAC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AACvD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAqB,EACrB,OAAe,EACf,QAAmB,EACnB,QAAmB,EACnB,aAA2B,EAC3B,UAAqB,EAAE;IAEvB,MAAM,YAAY,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,6CAA6C;IAC7C,OAAO,YAAY,CAAC,WAAW,CAC7B,MAAM,MAAM,CAAC,UAAU,EAAE,EACzB,aAAa,EACb,OAAO,CACR,CAAA;AACH,CAAC"}
@@ -1,10 +1,10 @@
1
- import { Contract, ethers } from 'ethers';
2
- /**
3
- * Returns an ethers contract instance for the RealWorldReceivable 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 RealWorldReceivable contract or null if it could not be found.
9
- */
10
- export declare function getRealWorldReceivableContract(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 RealWorldReceivable 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 RealWorldReceivable contract or null if it could not be found.
9
+ */
10
+ export declare function getRealWorldReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
@@ -1,18 +1,18 @@
1
- import { REAL_WORLD_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
2
- import { getContract } from '../utils';
3
- /**
4
- * Returns an ethers contract instance for the RealWorldReceivable contract
5
- * associated with the given pool name on the current chain.
6
- *
7
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
- * @param {number} chainId The chain id where the contract instance exists
9
- * @returns {Contract | null} A contract instance for the RealWorldReceivable contract or null if it could not be found.
10
- */
11
- export function getRealWorldReceivableContract(signerOrProvider, chainId) {
12
- var _a;
13
- const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
14
- if (!realWorldReceivable)
15
- return null;
16
- return getContract(realWorldReceivable, REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
17
- }
1
+ import { REAL_WORLD_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
2
+ import { getContract } from '../utils';
3
+ /**
4
+ * Returns an ethers contract instance for the RealWorldReceivable contract
5
+ * associated with the given pool name on the current chain.
6
+ *
7
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
+ * @param {number} chainId The chain id where the contract instance exists
9
+ * @returns {Contract | null} A contract instance for the RealWorldReceivable contract or null if it could not be found.
10
+ */
11
+ export function getRealWorldReceivableContract(signerOrProvider, chainId) {
12
+ var _a;
13
+ const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
14
+ if (!realWorldReceivable)
15
+ return null;
16
+ return getContract(realWorldReceivable, REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
17
+ }
18
18
  //# sourceMappingURL=RealWorldReceivableContractHelper.js.map
@@ -1,3 +1,3 @@
1
- export * from './RealWorldReceivableContractHelper';
2
- export * from './ERC20TransferableReceivableContractHelper';
3
- export * from './PoolContractHelper';
1
+ export * from './RealWorldReceivableContractHelper';
2
+ export * from './ERC20TransferableReceivableContractHelper';
3
+ export * from './PoolContractHelper';
@@ -1,4 +1,4 @@
1
- export * from './RealWorldReceivableContractHelper';
2
- export * from './ERC20TransferableReceivableContractHelper';
3
- export * from './PoolContractHelper';
1
+ export * from './RealWorldReceivableContractHelper';
2
+ export * from './ERC20TransferableReceivableContractHelper';
3
+ export * from './PoolContractHelper';
4
4
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- export * from './useContract';
2
- export * from './useRealWorldReceivableContract';
3
- export * from './useERC20TransferableReceivableContract';
4
- export * from './usePoolContract';
1
+ export * from './useContract';
2
+ export * from './useRealWorldReceivableContract';
3
+ export * from './useERC20TransferableReceivableContract';
4
+ export * from './usePoolContract';
@@ -1,5 +1,5 @@
1
- export * from './useContract';
2
- export * from './useRealWorldReceivableContract';
3
- export * from './useERC20TransferableReceivableContract';
4
- export * from './usePoolContract';
1
+ export * from './useContract';
2
+ export * from './useRealWorldReceivableContract';
3
+ export * from './useERC20TransferableReceivableContract';
4
+ export * from './usePoolContract';
5
5
  //# sourceMappingURL=index.js.map
@@ -1,13 +1,13 @@
1
- import { Contract } from '@ethersproject/contracts';
2
- import { ethers } from 'ethers';
3
- /**
4
- * Custom hook for creating an ethers instance of a smart contract.
5
- *
6
- * @template T - The type of the contract.
7
- * @param {string | null | undefined} address - The address of the smart contract instance.
8
- * @param {any} ABI - The ABI of the smart contract.
9
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
10
- * Note that this signerOrProvider must be connected to the same network as the smart contract in question.
11
- * @returns {T | null} An instance of the smart contract, or null if an error occurs.
12
- */
13
- export declare function useContract<T extends Contract = Contract>(address: string | null | undefined, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): T | null;
1
+ import { Contract } from '@ethersproject/contracts';
2
+ import { ethers } from 'ethers';
3
+ /**
4
+ * Custom hook for creating an ethers instance of a smart contract.
5
+ *
6
+ * @template T - The type of the contract.
7
+ * @param {string | null | undefined} address - The address of the smart contract instance.
8
+ * @param {any} ABI - The ABI of the smart contract.
9
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
10
+ * Note that this signerOrProvider must be connected to the same network as the smart contract in question.
11
+ * @returns {T | null} An instance of the smart contract, or null if an error occurs.
12
+ */
13
+ export declare function useContract<T extends Contract = Contract>(address: string | null | undefined, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): T | null;
@@ -1,27 +1,27 @@
1
- import { useMemo } from 'react';
2
- import { getContract } from '../utils/web3';
3
- /**
4
- * Custom hook for creating an ethers instance of a smart contract.
5
- *
6
- * @template T - The type of the contract.
7
- * @param {string | null | undefined} address - The address of the smart contract instance.
8
- * @param {any} ABI - The ABI of the smart contract.
9
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
10
- * Note that this signerOrProvider must be connected to the same network as the smart contract in question.
11
- * @returns {T | null} An instance of the smart contract, or null if an error occurs.
12
- */
13
- export function useContract(address,
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- ABI, signerOrProvider) {
16
- return useMemo(() => {
17
- if (!address || !ABI || !signerOrProvider)
18
- return null;
19
- try {
20
- return getContract(address, ABI, signerOrProvider);
21
- }
22
- catch (error) {
23
- return null;
24
- }
25
- }, [address, ABI, signerOrProvider]);
26
- }
1
+ import { useMemo } from 'react';
2
+ import { getContract } from '../utils/web3';
3
+ /**
4
+ * Custom hook for creating an ethers instance of a smart contract.
5
+ *
6
+ * @template T - The type of the contract.
7
+ * @param {string | null | undefined} address - The address of the smart contract instance.
8
+ * @param {any} ABI - The ABI of the smart contract.
9
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to sign transactions or retrieve blockchain data.
10
+ * Note that this signerOrProvider must be connected to the same network as the smart contract in question.
11
+ * @returns {T | null} An instance of the smart contract, or null if an error occurs.
12
+ */
13
+ export function useContract(address,
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ ABI, signerOrProvider) {
16
+ return useMemo(() => {
17
+ if (!address || !ABI || !signerOrProvider)
18
+ return null;
19
+ try {
20
+ return getContract(address, ABI, signerOrProvider);
21
+ }
22
+ catch (error) {
23
+ return null;
24
+ }
25
+ }, [address, ABI, signerOrProvider]);
26
+ }
27
27
  //# sourceMappingURL=useContract.js.map
@@ -1,12 +1,12 @@
1
- import { Contract, ethers } from 'ethers';
2
- import { POOL_NAME } from '@huma-finance/shared';
3
- /**
4
- * A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
5
- * associated with the given pool name on the current chain.
6
- *
7
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
- * @param {number} chainId The chain id where the contract instance exists
9
- * @param {POOL_NAME} poolName The name of the pool to get the contract for.
10
- * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
11
- */
12
- export declare function useERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME): Contract | null;
1
+ import { Contract, ethers } from 'ethers';
2
+ import { POOL_NAME } from '@huma-finance/shared';
3
+ /**
4
+ * A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
5
+ * associated with the given pool name on the current chain.
6
+ *
7
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
+ * @param {number} chainId The chain id where the contract instance exists
9
+ * @param {POOL_NAME} poolName The name of the pool to get the contract for.
10
+ * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
11
+ */
12
+ export declare function useERC20TransferableReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME): Contract | null;
@@ -1,17 +1,17 @@
1
- import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, POOL_TYPE, PoolContractMap, } from '@huma-finance/shared';
2
- import { useContract } from './useContract';
3
- /**
4
- * A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
5
- * associated with the given pool name on the current chain.
6
- *
7
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
- * @param {number} chainId The chain id where the contract instance exists
9
- * @param {POOL_NAME} poolName The name of the pool to get the contract for.
10
- * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
11
- */
12
- export function useERC20TransferableReceivableContract(signerOrProvider, chainId, poolName) {
13
- var _a, _b, _c;
14
- const TransferableReceivableAddress = (_c = (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[POOL_TYPE.Invoice]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.assetAddress;
15
- return useContract(TransferableReceivableAddress, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
16
- }
1
+ import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, POOL_TYPE, PoolContractMap, } from '@huma-finance/shared';
2
+ import { useContract } from './useContract';
3
+ /**
4
+ * A react hook that returns an ethers contract instance for the ERC20TransferableReceivable contract
5
+ * associated with the given pool name on the current chain.
6
+ *
7
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
+ * @param {number} chainId The chain id where the contract instance exists
9
+ * @param {POOL_NAME} poolName The name of the pool to get the contract for.
10
+ * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
11
+ */
12
+ export function useERC20TransferableReceivableContract(signerOrProvider, chainId, poolName) {
13
+ var _a, _b, _c;
14
+ const TransferableReceivableAddress = (_c = (_b = (_a = PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[POOL_TYPE.Invoice]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.assetAddress;
15
+ return useContract(TransferableReceivableAddress, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
16
+ }
17
17
  //# sourceMappingURL=useERC20TransferableReceivableContract.js.map
@@ -1,60 +1,60 @@
1
- import { BigNumber } from '@ethersproject/bignumber';
2
- import { Contract, ethers } from 'ethers';
3
- import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
4
- /**
5
- * A react hook that returns a contract instance of a specific pool using an ethers provider or signer
6
- *
7
- * @namespace usePoolContract
8
- * @template T - The type of the contract.
9
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - An ethers signer or provider instance.
10
- * @param {number} chainId The chain id where the contract instance exists
11
- * @param {POOL_NAME} poolName - The name of the pool.
12
- * @param {POOL_TYPE} poolType - The type of the pool.
13
- * @returns {T} A contract instance of the specific pool.
14
- */
15
- export declare function usePoolContract<T extends Contract>(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): T | null;
16
- /**
17
- * CreditRecordDetails type object representing the details of a credit line.
18
- *
19
- * @memberof usePoolContract
20
- * @typedef {Object} CreditRecordDetails
21
- * @property {number} aprInBps - The APR (annual percentage rate) in basis points.
22
- * @property {BigNumber} correction - adjustment of interest over or under-counted because of drawdown
23
- * or principal payment in the middle of a billing period
24
- * @property {BigNumber} creditLimit - The credit limit in the pools base currency.
25
- * @property {BigNumber} defaultAmount - The amount of the default, if any.
26
- * @property {BigNumber} dueDate - The due date of the next payment.
27
- * @property {BigNumber} feesAndInterestDue - The fees and interest due.
28
- * @property {number} intervalInDays - The interval in days between payment periods.
29
- * @property {number} missedPeriods - The number of missed periods.
30
- * @property {number} remainingPeriods - The number of remaining periods before this credit line is considered paid off.
31
- * @property {number} state - The state of the factorization. Please see the CreditState in huma-contracts for more details.
32
- * @property {BigNumber} totalDue - The total due amount of this credit line.
33
- * @property {BigNumber} unbilledPrincipal - The unbilled principal of the next payment.
34
- */
35
- export type CreditRecordDetails = {
36
- aprInBps: number;
37
- correction: BigNumber;
38
- creditLimit: BigNumber;
39
- defaultAmount: BigNumber;
40
- dueDate: BigNumber;
41
- feesAndInterestDue: BigNumber;
42
- intervalInDays: number;
43
- missedPeriods: number;
44
- remainingPeriods: number;
45
- state: number;
46
- totalDue: BigNumber;
47
- unbilledPrincipal: BigNumber;
48
- };
49
- /**
50
- * A react hook that returns the credit record details for a user in a given pool, as well as a function to refresh the data.
51
- *
52
- * @memberof usePoolContract
53
- * @param {string} userAddress - The address of the user to get the credit record details for.
54
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider object to use for the contract.
55
- * @param {number} chainId The chain id where the contract instance exists
56
- * @param {POOL_NAME} poolName - The name of the pool to get the credit record details for.
57
- * @param {POOL_TYPE} poolType - The type of the pool.
58
- * @returns {Array<CreditRecordDetails | undefined, function():void>} An array containing the credit record details and a function to refresh the data.
59
- */
60
- export declare function useCreditRecordDetails(userAddress: string, signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): [CreditRecordDetails | undefined, () => void];
1
+ import { BigNumber } from '@ethersproject/bignumber';
2
+ import { Contract, ethers } from 'ethers';
3
+ import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
4
+ /**
5
+ * A react hook that returns a contract instance of a specific pool using an ethers provider or signer
6
+ *
7
+ * @namespace usePoolContract
8
+ * @template T - The type of the contract.
9
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - An ethers signer or provider instance.
10
+ * @param {number} chainId The chain id where the contract instance exists
11
+ * @param {POOL_NAME} poolName - The name of the pool.
12
+ * @param {POOL_TYPE} poolType - The type of the pool.
13
+ * @returns {T} A contract instance of the specific pool.
14
+ */
15
+ export declare function usePoolContract<T extends Contract>(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): T | null;
16
+ /**
17
+ * CreditRecordDetails type object representing the details of a credit line.
18
+ *
19
+ * @memberof usePoolContract
20
+ * @typedef {Object} CreditRecordDetails
21
+ * @property {number} aprInBps - The APR (annual percentage rate) in basis points.
22
+ * @property {BigNumber} correction - adjustment of interest over or under-counted because of drawdown
23
+ * or principal payment in the middle of a billing period
24
+ * @property {BigNumber} creditLimit - The credit limit in the pools base currency.
25
+ * @property {BigNumber} defaultAmount - The amount of the default, if any.
26
+ * @property {BigNumber} dueDate - The due date of the next payment.
27
+ * @property {BigNumber} feesAndInterestDue - The fees and interest due.
28
+ * @property {number} intervalInDays - The interval in days between payment periods.
29
+ * @property {number} missedPeriods - The number of missed periods.
30
+ * @property {number} remainingPeriods - The number of remaining periods before this credit line is considered paid off.
31
+ * @property {number} state - The state of the factorization. Please see the CreditState in huma-contracts for more details.
32
+ * @property {BigNumber} totalDue - The total due amount of this credit line.
33
+ * @property {BigNumber} unbilledPrincipal - The unbilled principal of the next payment.
34
+ */
35
+ export type CreditRecordDetails = {
36
+ aprInBps: number;
37
+ correction: BigNumber;
38
+ creditLimit: BigNumber;
39
+ defaultAmount: BigNumber;
40
+ dueDate: BigNumber;
41
+ feesAndInterestDue: BigNumber;
42
+ intervalInDays: number;
43
+ missedPeriods: number;
44
+ remainingPeriods: number;
45
+ state: number;
46
+ totalDue: BigNumber;
47
+ unbilledPrincipal: BigNumber;
48
+ };
49
+ /**
50
+ * A react hook that returns the credit record details for a user in a given pool, as well as a function to refresh the data.
51
+ *
52
+ * @memberof usePoolContract
53
+ * @param {string} userAddress - The address of the user to get the credit record details for.
54
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider object to use for the contract.
55
+ * @param {number} chainId The chain id where the contract instance exists
56
+ * @param {POOL_NAME} poolName - The name of the pool to get the credit record details for.
57
+ * @param {POOL_TYPE} poolType - The type of the pool.
58
+ * @returns {Array<CreditRecordDetails | undefined, function():void>} An array containing the credit record details and a function to refresh the data.
59
+ */
60
+ export declare function useCreditRecordDetails(userAddress: string, signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): [CreditRecordDetails | undefined, () => void];
@@ -1,49 +1,49 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { useContract } from './useContract';
3
- import { getPoolInfo } from '../utils/poolInfo';
4
- /**
5
- * A react hook that returns a contract instance of a specific pool using an ethers provider or signer
6
- *
7
- * @namespace usePoolContract
8
- * @template T - The type of the contract.
9
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - An ethers signer or provider instance.
10
- * @param {number} chainId The chain id where the contract instance exists
11
- * @param {POOL_NAME} poolName - The name of the pool.
12
- * @param {POOL_TYPE} poolType - The type of the pool.
13
- * @returns {T} A contract instance of the specific pool.
14
- */
15
- export function usePoolContract(signerOrProvider, chainId, poolName, poolType) {
16
- const poolInfo = getPoolInfo(chainId, poolName, poolType);
17
- return useContract(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.pool, poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolAbi, signerOrProvider);
18
- }
19
- /**
20
- * A react hook that returns the credit record details for a user in a given pool, as well as a function to refresh the data.
21
- *
22
- * @memberof usePoolContract
23
- * @param {string} userAddress - The address of the user to get the credit record details for.
24
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider object to use for the contract.
25
- * @param {number} chainId The chain id where the contract instance exists
26
- * @param {POOL_NAME} poolName - The name of the pool to get the credit record details for.
27
- * @param {POOL_TYPE} poolType - The type of the pool.
28
- * @returns {Array<CreditRecordDetails | undefined, function():void>} An array containing the credit record details and a function to refresh the data.
29
- */
30
- export function useCreditRecordDetails(userAddress, signerOrProvider, chainId, poolName, poolType) {
31
- const poolContract = usePoolContract(signerOrProvider, chainId, poolName, poolType);
32
- const [creditRecordDetails, setCreditRecordDetails] = useState();
33
- const [refreshCount, setRefreshCount] = useState(0);
34
- useEffect(() => {
35
- const fetchData = async () => {
36
- if (poolContract && userAddress) {
37
- const creditRecordMapping = await poolContract.creditRecordMapping(userAddress);
38
- const creditRecordStaticMapping = await poolContract.creditRecordStaticMapping(userAddress);
39
- setCreditRecordDetails(Object.assign(Object.assign({}, creditRecordMapping), creditRecordStaticMapping));
40
- }
41
- };
42
- fetchData();
43
- }, [userAddress, poolContract, refreshCount]);
44
- const refresh = useCallback(() => {
45
- setRefreshCount((pre) => pre + 1);
46
- }, []);
47
- return [creditRecordDetails, refresh];
48
- }
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { useContract } from './useContract';
3
+ import { getPoolInfo } from '../utils/poolInfo';
4
+ /**
5
+ * A react hook that returns a contract instance of a specific pool using an ethers provider or signer
6
+ *
7
+ * @namespace usePoolContract
8
+ * @template T - The type of the contract.
9
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - An ethers signer or provider instance.
10
+ * @param {number} chainId The chain id where the contract instance exists
11
+ * @param {POOL_NAME} poolName - The name of the pool.
12
+ * @param {POOL_TYPE} poolType - The type of the pool.
13
+ * @returns {T} A contract instance of the specific pool.
14
+ */
15
+ export function usePoolContract(signerOrProvider, chainId, poolName, poolType) {
16
+ const poolInfo = getPoolInfo(chainId, poolName, poolType);
17
+ return useContract(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.pool, poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolAbi, signerOrProvider);
18
+ }
19
+ /**
20
+ * A react hook that returns the credit record details for a user in a given pool, as well as a function to refresh the data.
21
+ *
22
+ * @memberof usePoolContract
23
+ * @param {string} userAddress - The address of the user to get the credit record details for.
24
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider object to use for the contract.
25
+ * @param {number} chainId The chain id where the contract instance exists
26
+ * @param {POOL_NAME} poolName - The name of the pool to get the credit record details for.
27
+ * @param {POOL_TYPE} poolType - The type of the pool.
28
+ * @returns {Array<CreditRecordDetails | undefined, function():void>} An array containing the credit record details and a function to refresh the data.
29
+ */
30
+ export function useCreditRecordDetails(userAddress, signerOrProvider, chainId, poolName, poolType) {
31
+ const poolContract = usePoolContract(signerOrProvider, chainId, poolName, poolType);
32
+ const [creditRecordDetails, setCreditRecordDetails] = useState();
33
+ const [refreshCount, setRefreshCount] = useState(0);
34
+ useEffect(() => {
35
+ const fetchData = async () => {
36
+ if (poolContract && userAddress) {
37
+ const creditRecordMapping = await poolContract.creditRecordMapping(userAddress);
38
+ const creditRecordStaticMapping = await poolContract.creditRecordStaticMapping(userAddress);
39
+ setCreditRecordDetails(Object.assign(Object.assign({}, creditRecordMapping), creditRecordStaticMapping));
40
+ }
41
+ };
42
+ fetchData();
43
+ }, [userAddress, poolContract, refreshCount]);
44
+ const refresh = useCallback(() => {
45
+ setRefreshCount((pre) => pre + 1);
46
+ }, []);
47
+ return [creditRecordDetails, refresh];
48
+ }
49
49
  //# sourceMappingURL=usePoolContract.js.map
@@ -1,10 +1,10 @@
1
- import { Contract, ethers } from 'ethers';
2
- /**
3
- * A react hook that returns an ethers contract instance for the RealWorldReceivable 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 RealWorldReceivable contract or null if it could not be found.
9
- */
10
- export declare function useRealWorldReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
1
+ import { Contract, ethers } from 'ethers';
2
+ /**
3
+ * A react hook that returns an ethers contract instance for the RealWorldReceivable 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 RealWorldReceivable contract or null if it could not be found.
9
+ */
10
+ export declare function useRealWorldReceivableContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number): Contract | null;
@@ -1,16 +1,16 @@
1
- import { REAL_WORLD_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
2
- import { useContract } from './useContract';
3
- /**
4
- * A react hook that returns an ethers contract instance for the RealWorldReceivable contract
5
- * associated with the given pool name on the current chain.
6
- *
7
- * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
- * @param {number} chainId The chain id where the contract instance exists
9
- * @returns {Contract | null} A contract instance for the RealWorldReceivable contract or null if it could not be found.
10
- */
11
- export function useRealWorldReceivableContract(signerOrProvider, chainId) {
12
- var _a;
13
- const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
14
- return useContract(realWorldReceivable, REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
15
- }
1
+ import { REAL_WORLD_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
2
+ import { useContract } from './useContract';
3
+ /**
4
+ * A react hook that returns an ethers contract instance for the RealWorldReceivable contract
5
+ * associated with the given pool name on the current chain.
6
+ *
7
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider The provider or signer instance to use for the contract.
8
+ * @param {number} chainId The chain id where the contract instance exists
9
+ * @returns {Contract | null} A contract instance for the RealWorldReceivable contract or null if it could not be found.
10
+ */
11
+ export function useRealWorldReceivableContract(signerOrProvider, chainId) {
12
+ var _a;
13
+ const realWorldReceivable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
14
+ return useContract(realWorldReceivable, REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
15
+ }
16
16
  //# sourceMappingURL=useRealWorldReceivableContract.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './helpers';
2
- export * from './hooks';
3
- export * from './services';
4
- export * from './utils';
1
+ export * from './helpers';
2
+ export * from './hooks';
3
+ export * from './services';
4
+ export * from './utils';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from './helpers';
2
- export * from './hooks';
3
- export * from './services';
4
- export * from './utils';
1
+ export * from './helpers';
2
+ export * from './hooks';
3
+ export * from './services';
4
+ export * from './utils';
5
5
  //# sourceMappingURL=index.js.map