@huma-finance/sdk 0.0.39 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/API.md +45 -9
  2. package/dist/cjs/graphql/generatedTypes.d.ts +40 -0
  3. package/dist/cjs/graphql/generatedTypes.js +9 -0
  4. package/dist/cjs/graphql/generatedTypes.js.map +1 -0
  5. package/dist/cjs/graphql/index.d.ts +1 -0
  6. package/dist/cjs/graphql/index.js +5 -0
  7. package/dist/cjs/graphql/index.js.map +1 -0
  8. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
  9. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +22 -0
  10. package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
  11. package/dist/cjs/helpers/PoolContractHelper.d.ts +119 -0
  12. package/dist/cjs/helpers/PoolContractHelper.js +144 -0
  13. package/dist/cjs/helpers/PoolContractHelper.js.map +1 -0
  14. package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
  15. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +22 -0
  16. package/dist/cjs/helpers/RealWorldReceivableContractHelper.js.map +1 -0
  17. package/dist/cjs/helpers/index.d.ts +3 -0
  18. package/dist/cjs/helpers/index.js +7 -0
  19. package/dist/cjs/helpers/index.js.map +1 -0
  20. package/dist/cjs/hooks/index.d.ts +4 -0
  21. package/dist/cjs/hooks/index.js +8 -0
  22. package/dist/cjs/hooks/index.js.map +1 -0
  23. package/dist/cjs/hooks/useContract.d.ts +13 -0
  24. package/dist/cjs/hooks/useContract.js +31 -0
  25. package/dist/cjs/hooks/useContract.js.map +1 -0
  26. package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  27. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +21 -0
  28. package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  29. package/dist/cjs/hooks/usePoolContract.d.ts +60 -0
  30. package/dist/cjs/hooks/usePoolContract.js +54 -0
  31. package/dist/cjs/hooks/usePoolContract.js.map +1 -0
  32. package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -0
  33. package/dist/cjs/hooks/useRealWorldReceivableContract.js +20 -0
  34. package/dist/cjs/hooks/useRealWorldReceivableContract.js.map +1 -0
  35. package/dist/cjs/index.d.ts +4 -0
  36. package/dist/cjs/index.js +8 -0
  37. package/dist/cjs/index.js.map +1 -0
  38. package/dist/cjs/services/ARWeaveService.d.ts +117 -0
  39. package/dist/cjs/services/ARWeaveService.js +204 -0
  40. package/dist/cjs/services/ARWeaveService.js.map +1 -0
  41. package/dist/cjs/services/EAService.d.ts +20 -0
  42. package/dist/cjs/services/EAService.js +34 -0
  43. package/dist/cjs/services/EAService.js.map +1 -0
  44. package/dist/cjs/services/ReceivableService.d.ts +142 -0
  45. package/dist/cjs/services/ReceivableService.js +330 -0
  46. package/dist/cjs/services/ReceivableService.js.map +1 -0
  47. package/dist/cjs/services/SubgraphService.d.ts +53 -0
  48. package/dist/cjs/services/SubgraphService.js +94 -0
  49. package/dist/cjs/services/SubgraphService.js.map +1 -0
  50. package/dist/cjs/services/index.d.ts +4 -0
  51. package/dist/cjs/services/index.js +8 -0
  52. package/dist/cjs/services/index.js.map +1 -0
  53. package/dist/cjs/utils/chain.d.ts +15 -0
  54. package/dist/cjs/utils/chain.js +38 -0
  55. package/dist/cjs/utils/chain.js.map +1 -0
  56. package/dist/cjs/utils/index.d.ts +4 -0
  57. package/dist/cjs/utils/index.js +8 -0
  58. package/dist/cjs/utils/index.js.map +1 -0
  59. package/dist/cjs/utils/maticGasStation.d.ts +3 -0
  60. package/dist/cjs/utils/maticGasStation.js +39 -0
  61. package/dist/cjs/utils/maticGasStation.js.map +1 -0
  62. package/dist/cjs/utils/poolInfo.d.ts +8 -0
  63. package/dist/cjs/utils/poolInfo.js +13 -0
  64. package/dist/cjs/utils/poolInfo.js.map +1 -0
  65. package/dist/cjs/utils/web3.d.ts +5 -0
  66. package/dist/cjs/utils/web3.js +34 -0
  67. package/dist/cjs/utils/web3.js.map +1 -0
  68. package/dist/graphql/generatedTypes.d.ts +40 -0
  69. package/dist/graphql/generatedTypes.js +5 -0
  70. package/dist/graphql/generatedTypes.js.map +1 -0
  71. package/dist/graphql/index.d.ts +1 -0
  72. package/dist/graphql/index.js +2 -0
  73. package/dist/graphql/index.js.map +1 -0
  74. package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
  75. package/dist/helpers/ERC20TransferableReceivableContractHelper.js +18 -0
  76. package/dist/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
  77. package/dist/helpers/PoolContractHelper.d.ts +119 -0
  78. package/dist/helpers/PoolContractHelper.js +135 -0
  79. package/dist/helpers/PoolContractHelper.js.map +1 -0
  80. package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
  81. package/dist/helpers/RealWorldReceivableContractHelper.js +18 -0
  82. package/dist/helpers/RealWorldReceivableContractHelper.js.map +1 -0
  83. package/dist/helpers/index.d.ts +3 -0
  84. package/dist/helpers/index.js +4 -0
  85. package/dist/helpers/index.js.map +1 -0
  86. package/dist/hooks/index.d.ts +4 -0
  87. package/dist/hooks/index.js +5 -0
  88. package/dist/hooks/index.js.map +1 -0
  89. package/dist/hooks/useContract.d.ts +13 -0
  90. package/dist/hooks/useContract.js +27 -0
  91. package/dist/hooks/useContract.js.map +1 -0
  92. package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
  93. package/dist/hooks/useERC20TransferableReceivableContract.js +17 -0
  94. package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -0
  95. package/dist/hooks/usePoolContract.d.ts +60 -0
  96. package/dist/hooks/usePoolContract.js +49 -0
  97. package/dist/hooks/usePoolContract.js.map +1 -0
  98. package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -0
  99. package/dist/hooks/useRealWorldReceivableContract.js +16 -0
  100. package/dist/hooks/useRealWorldReceivableContract.js.map +1 -0
  101. package/dist/index.d.ts +4 -0
  102. package/dist/index.js +5 -0
  103. package/dist/index.js.map +1 -0
  104. package/dist/services/ARWeaveService.d.ts +117 -0
  105. package/dist/services/ARWeaveService.js +199 -0
  106. package/dist/services/ARWeaveService.js.map +1 -0
  107. package/dist/services/EAService.d.ts +20 -0
  108. package/dist/services/EAService.js +31 -0
  109. package/dist/services/EAService.js.map +1 -0
  110. package/dist/services/ReceivableService.d.ts +142 -0
  111. package/dist/services/ReceivableService.js +327 -0
  112. package/dist/services/ReceivableService.js.map +1 -0
  113. package/dist/services/SubgraphService.d.ts +53 -0
  114. package/dist/services/SubgraphService.js +91 -0
  115. package/dist/services/SubgraphService.js.map +1 -0
  116. package/dist/services/index.d.ts +4 -0
  117. package/dist/services/index.js +5 -0
  118. package/dist/services/index.js.map +1 -0
  119. package/dist/tsconfig.cjs.tsbuildinfo +1 -0
  120. package/dist/utils/chain.d.ts +15 -0
  121. package/dist/utils/chain.js +32 -0
  122. package/dist/utils/chain.js.map +1 -0
  123. package/dist/utils/index.d.ts +4 -0
  124. package/dist/utils/index.js +5 -0
  125. package/dist/utils/index.js.map +1 -0
  126. package/dist/utils/maticGasStation.d.ts +3 -0
  127. package/dist/utils/maticGasStation.js +34 -0
  128. package/dist/utils/maticGasStation.js.map +1 -0
  129. package/dist/utils/poolInfo.d.ts +8 -0
  130. package/dist/utils/poolInfo.js +9 -0
  131. package/dist/utils/poolInfo.js.map +1 -0
  132. package/dist/utils/web3.d.ts +5 -0
  133. package/dist/utils/web3.js +28 -0
  134. package/dist/utils/web3.js.map +1 -0
  135. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgC;AAChC,sDAA2B;AAC3B,4DAAiC;AACjC,8DAAmC"}
@@ -0,0 +1,15 @@
1
+ import { JsonRpcProvider, JsonRpcSigner } from '@ethersproject/providers';
2
+ import { ethers } from 'ethers';
3
+ export declare function isPolygonNetwork(network: number): boolean;
4
+ /**
5
+ * Get the chain ID from a signer or provider object.
6
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to get the chain ID from.
7
+ * @returns {number} - The chain ID.
8
+ */
9
+ export declare function getChainIdFromJsonSignerOrProvider(signerOrProvider: JsonRpcProvider | JsonRpcSigner): number;
10
+ /**
11
+ * Get the chain ID from a signer or provider object.
12
+ * @param {ethers.provider.Provider | ethers.Signer} signerOrProvider - The signer or provider object to get the chain ID from.
13
+ * @returns {number} - The chain ID.
14
+ */
15
+ export declare function getChainIdFromSignerOrProvider(signerOrProvider: ethers.providers.Provider | ethers.Signer): Promise<number | undefined>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getChainIdFromSignerOrProvider = exports.getChainIdFromJsonSignerOrProvider = exports.isPolygonNetwork = void 0;
4
+ const providers_1 = require("@ethersproject/providers");
5
+ const ethers_1 = require("ethers");
6
+ function isPolygonNetwork(network) {
7
+ return network === 137 || network === 80001;
8
+ }
9
+ exports.isPolygonNetwork = isPolygonNetwork;
10
+ /**
11
+ * Get the chain ID from a signer or provider object.
12
+ * @param {JsonRpcProvider | JsonRpcSigner} signerOrProvider - The signer or provider object to get the chain ID from.
13
+ * @returns {number} - The chain ID.
14
+ */
15
+ function getChainIdFromJsonSignerOrProvider(signerOrProvider) {
16
+ return signerOrProvider instanceof providers_1.JsonRpcProvider
17
+ ? signerOrProvider.network.chainId
18
+ : signerOrProvider.provider.network.chainId;
19
+ }
20
+ exports.getChainIdFromJsonSignerOrProvider = getChainIdFromJsonSignerOrProvider;
21
+ /**
22
+ * Get the chain ID from a signer or provider object.
23
+ * @param {ethers.provider.Provider | ethers.Signer} signerOrProvider - The signer or provider object to get the chain ID from.
24
+ * @returns {number} - The chain ID.
25
+ */
26
+ async function getChainIdFromSignerOrProvider(signerOrProvider) {
27
+ var _a;
28
+ let network;
29
+ if (signerOrProvider instanceof ethers_1.ethers.providers.Provider) {
30
+ network = await signerOrProvider.getNetwork();
31
+ }
32
+ else {
33
+ network = await ((_a = signerOrProvider === null || signerOrProvider === void 0 ? void 0 : signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork());
34
+ }
35
+ return network === null || network === void 0 ? void 0 : network.chainId;
36
+ }
37
+ exports.getChainIdFromSignerOrProvider = getChainIdFromSignerOrProvider;
38
+ //# sourceMappingURL=chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/utils/chain.ts"],"names":[],"mappings":";;;AAAA,wDAAyE;AACzE,mCAA+B;AAE/B,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,OAAO,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,KAAK,CAAA;AAC7C,CAAC;AAFD,4CAEC;AAED;;;;GAIG;AACH,SAAgB,kCAAkC,CAChD,gBAAiD;IAEjD,OAAO,gBAAgB,YAAY,2BAAe;QAChD,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO;QAClC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAA;AAC/C,CAAC;AAND,gFAMC;AAED;;;;GAIG;AACI,KAAK,UAAU,8BAA8B,CAClD,gBAA2D;;IAE3D,IAAI,OAAO,CAAA;IACX,IAAI,gBAAgB,YAAY,eAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;QACzD,OAAO,GAAG,MAAM,gBAAgB,CAAC,UAAU,EAAE,CAAA;KAC9C;SAAM;QACL,OAAO,GAAG,MAAM,CAAA,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,QAAQ,0CAAE,UAAU,EAAE,CAAA,CAAA;KACzD;IAED,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAA;AACzB,CAAC;AAXD,wEAWC"}
@@ -0,0 +1,4 @@
1
+ export * from './chain';
2
+ export * from './web3';
3
+ export * from './poolInfo';
4
+ export * from './maticGasStation';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./chain"), exports);
5
+ tslib_1.__exportStar(require("./web3"), exports);
6
+ tslib_1.__exportStar(require("./poolInfo"), exports);
7
+ tslib_1.__exportStar(require("./maticGasStation"), exports);
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,kDAAuB;AACvB,iDAAsB;AACtB,qDAA0B;AAC1B,4DAAiC"}
@@ -0,0 +1,3 @@
1
+ import { Overrides } from 'ethers';
2
+ export declare function getPolygonGasOptions(network: number): Promise<Overrides>;
3
+ export declare function getDefaultGasOptions(gasOpts: Overrides, network: number): Promise<Overrides>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultGasOptions = exports.getPolygonGasOptions = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const shared_1 = require("@huma-finance/shared");
6
+ const chain_1 = require("./chain");
7
+ async function getPolygonGasOptions(network) {
8
+ let maxFeePerGas = ethers_1.ethers.BigNumber.from(40000000000); // fallback to 40 gwei
9
+ let maxPriorityFeePerGas = ethers_1.ethers.BigNumber.from(40000000000); // fallback to 40 gwei
10
+ try {
11
+ const url = network === shared_1.ChainEnum.Polygon
12
+ ? 'https://gasstation.polygon.technology/v2'
13
+ : 'https://gasstation-testnet.polygon.technology/v2';
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
+ const data = await (0, shared_1.requestGet)(url);
16
+ maxFeePerGas = ethers_1.ethers.utils.parseUnits(`${Math.ceil(data.fast.maxFee)}`, 'gwei');
17
+ maxPriorityFeePerGas = ethers_1.ethers.utils.parseUnits(`${Math.ceil(data.fast.maxPriorityFee)}`, 'gwei');
18
+ }
19
+ catch (_a) {
20
+ // ignore
21
+ }
22
+ return {
23
+ maxFeePerGas,
24
+ maxPriorityFeePerGas,
25
+ };
26
+ }
27
+ exports.getPolygonGasOptions = getPolygonGasOptions;
28
+ async function getDefaultGasOptions(gasOpts, network) {
29
+ // Return gasOpts if there are values already set
30
+ if (Object.keys(gasOpts).length > 0) {
31
+ return gasOpts;
32
+ }
33
+ if ((0, chain_1.isPolygonNetwork)(network)) {
34
+ gasOpts = await getPolygonGasOptions(network);
35
+ }
36
+ return gasOpts;
37
+ }
38
+ exports.getDefaultGasOptions = getDefaultGasOptions;
39
+ //# sourceMappingURL=maticGasStation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maticGasStation.js","sourceRoot":"","sources":["../../../src/utils/maticGasStation.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAC1C,iDAA4D;AAE5D,mCAA0C;AAEnC,KAAK,UAAU,oBAAoB,CACxC,OAAe;IAEf,IAAI,YAAY,GAAG,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC,sBAAsB;IAC5E,IAAI,oBAAoB,GAAG,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA,CAAC,sBAAsB;IACpF,IAAI;QACF,MAAM,GAAG,GACP,OAAO,KAAK,kBAAS,CAAC,OAAO;YAC3B,CAAC,CAAC,0CAA0C;YAC5C,CAAC,CAAC,kDAAkD,CAAA;QACxD,8DAA8D;QAC9D,MAAM,IAAI,GAAQ,MAAM,IAAA,mBAAU,EAAC,GAAG,CAAC,CAAA;QACvC,YAAY,GAAG,eAAM,CAAC,KAAK,CAAC,UAAU,CACpC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,EAChC,MAAM,CACP,CAAA;QACD,oBAAoB,GAAG,eAAM,CAAC,KAAK,CAAC,UAAU,CAC5C,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EACxC,MAAM,CACP,CAAA;KACF;IAAC,WAAM;QACN,SAAS;KACV;IAED,OAAO;QACL,YAAY;QACZ,oBAAoB;KACrB,CAAA;AACH,CAAC;AA5BD,oDA4BC;AAEM,KAAK,UAAU,oBAAoB,CACxC,OAAkB,EAClB,OAAe;IAEf,iDAAiD;IACjD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACnC,OAAO,OAAO,CAAA;KACf;IAED,IAAI,IAAA,wBAAgB,EAAC,OAAO,CAAC,EAAE;QAC7B,OAAO,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAA;KAC9C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAdD,oDAcC"}
@@ -0,0 +1,8 @@
1
+ import { POOL_NAME, POOL_TYPE, PoolInfoType } from '@huma-finance/shared';
2
+ /**
3
+ * Returns the pool info based on the provided pool name and type, using the same chain ID as the provider/signer given
4
+ * @param {POOL_NAME} poolName - The name of the pool.
5
+ * @param {POOL_TYPE} poolType - The type of the pool.
6
+ * @returns {PoolInfoType|undefined} - The pool info or undefined if the chain ID is not supported.
7
+ */
8
+ export declare const getPoolInfo: (chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE) => PoolInfoType | undefined;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPoolInfo = void 0;
4
+ const shared_1 = require("@huma-finance/shared");
5
+ /**
6
+ * Returns the pool info based on the provided pool name and type, using the same chain ID as the provider/signer given
7
+ * @param {POOL_NAME} poolName - The name of the pool.
8
+ * @param {POOL_TYPE} poolType - The type of the pool.
9
+ * @returns {PoolInfoType|undefined} - The pool info or undefined if the chain ID is not supported.
10
+ */
11
+ const getPoolInfo = (chainId, poolName, poolType) => { var _a, _b; return (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]; };
12
+ exports.getPoolInfo = getPoolInfo;
13
+ //# sourceMappingURL=poolInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"poolInfo.js","sourceRoot":"","sources":["../../../src/utils/poolInfo.ts"],"names":[],"mappings":";;;AAAA,iDAK6B;AAE7B;;;;;GAKG;AACI,MAAM,WAAW,GAAG,CACzB,OAAe,EACf,QAAmB,EACnB,QAAmB,EACO,EAAE,eAAC,OAAA,MAAA,MAAA,wBAAe,CAAC,OAAO,CAAC,0CAAG,QAAQ,CAAC,0CAAG,QAAQ,CAAC,CAAA,EAAA,CAAA;AAJlE,QAAA,WAAW,eAIuD"}
@@ -0,0 +1,5 @@
1
+ import { Contract } from '@ethersproject/contracts';
2
+ import { ethers } from 'ethers';
3
+ export declare function isAddress(value: any): string | false;
4
+ export declare function getContract(address: string, ABI: any, signerOrProvider: ethers.providers.Provider | ethers.Signer): Contract;
5
+ export declare function getERC20Contract(address: string, signerOrProvider: ethers.providers.Provider | ethers.Signer): Contract;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getERC20Contract = exports.getContract = exports.isAddress = void 0;
4
+ const contracts_1 = require("@ethersproject/contracts");
5
+ const constants_1 = require("@ethersproject/constants");
6
+ const address_1 = require("@ethersproject/address");
7
+ const shared_1 = require("@huma-finance/shared");
8
+ // returns the checksummed address if the address is valid, otherwise returns false
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ function isAddress(value) {
11
+ try {
12
+ // Alphabetical letters must be made lowercase for getAddress to work.
13
+ // See documentation here: https://docs.ethers.io/v5/api/utils/address/
14
+ return (0, address_1.getAddress)(value.toLowerCase());
15
+ }
16
+ catch (_a) {
17
+ return false;
18
+ }
19
+ }
20
+ exports.isAddress = isAddress;
21
+ function getContract(address,
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ ABI, signerOrProvider) {
24
+ if (!isAddress(address) || address === constants_1.AddressZero) {
25
+ throw Error(`Invalid 'address' parameter '${address}'.`);
26
+ }
27
+ return new contracts_1.Contract(address, ABI, signerOrProvider);
28
+ }
29
+ exports.getContract = getContract;
30
+ function getERC20Contract(address, signerOrProvider) {
31
+ return getContract(address, shared_1.ERC20_ABI, signerOrProvider);
32
+ }
33
+ exports.getERC20Contract = getERC20Contract;
34
+ //# sourceMappingURL=web3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3.js","sourceRoot":"","sources":["../../../src/utils/web3.ts"],"names":[],"mappings":";;;AAAA,wDAAmD;AACnD,wDAAsD;AACtD,oDAAmD;AAEnD,iDAAgD;AAEhD,mFAAmF;AACnF,8DAA8D;AAC9D,SAAgB,SAAS,CAAC,KAAU;IAClC,IAAI;QACF,sEAAsE;QACtE,uEAAuE;QACvE,OAAO,IAAA,oBAAU,EAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;KACvC;IAAC,WAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AARD,8BAQC;AAED,SAAgB,WAAW,CACzB,OAAe;AACf,8DAA8D;AAC9D,GAAQ,EACR,gBAA2D;IAE3D,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,KAAK,uBAAW,EAAE;QAClD,MAAM,KAAK,CAAC,gCAAgC,OAAO,IAAI,CAAC,CAAA;KACzD;IAED,OAAO,IAAI,oBAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAA;AACrD,CAAC;AAXD,kCAWC;AAED,SAAgB,gBAAgB,CAC9B,OAAe,EACf,gBAA2D;IAE3D,OAAO,WAAW,CAAC,OAAO,EAAE,kBAAS,EAAE,gBAAgB,CAAC,CAAA;AAC1D,CAAC;AALD,4CAKC"}
@@ -0,0 +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>;
@@ -0,0 +1,5 @@
1
+ const defaultWrapper = (action, _operationName, _operationType) => action();
2
+ export function getSdk(client, withWrapper = defaultWrapper) {
3
+ return {};
4
+ }
5
+ //# sourceMappingURL=generatedTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generatedTypes.js","sourceRoot":"","sources":["../../src/graphql/generatedTypes.ts"],"names":[],"mappings":"AA8CA,MAAM,cAAc,GAAuB,CACzC,MAAM,EACN,cAAc,EACd,cAAc,EACd,EAAE,CAAC,MAAM,EAAE,CAAA;AAEb,MAAM,UAAU,MAAM,CACpB,MAAqB,EACrB,cAAkC,cAAc;IAEhD,OAAO,EAAE,CAAA;AACX,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './generatedTypes';
@@ -0,0 +1,2 @@
1
+ export * from './generatedTypes';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graphql/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
@@ -0,0 +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;
@@ -0,0 +1,18 @@
1
+ import { ERC20_TRANSFERABLE_RECEIVABLE_ABI, SupplementaryContracts, SupplementaryContractsMap, } from '@huma-finance/shared';
2
+ import { getContract } from '../utils';
3
+ /**
4
+ * 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
+ * @returns {Contract | null} A contract instance for the ERC20TransferableReceivable contract or null if it could not be found.
10
+ */
11
+ export function getERC20TransferableReceivableContract(signerOrProvider, chainId) {
12
+ var _a;
13
+ const erc20TransferableReceiable = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.ERC20TransferableReceivable];
14
+ if (!erc20TransferableReceiable)
15
+ return null;
16
+ return getContract(erc20TransferableReceiable, ERC20_TRANSFERABLE_RECEIVABLE_ABI, signerOrProvider);
17
+ }
18
+ //# sourceMappingURL=ERC20TransferableReceivableContractHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ERC20TransferableReceivableContractHelper.js","sourceRoot":"","sources":["../../src/helpers/ERC20TransferableReceivableContractHelper.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC;;;;;;;GAOG;AACH,MAAM,UAAU,sCAAsC,CACpD,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,0BAA0B,GAC9B,MAAA,yBAAyB,CAAC,OAAO,CAAC,0CAChC,sBAAsB,CAAC,2BAA2B,CACnD,CAAA;IAEH,IAAI,CAAC,0BAA0B;QAAE,OAAO,IAAI,CAAA;IAE5C,OAAO,WAAW,CAChB,0BAA0B,EAC1B,iCAAiC,EACjC,gBAAgB,CACjB,CAAA;AACH,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { BigNumber } from '@ethersproject/bignumber';
2
+ import { BigNumberish, Contract, Overrides, ethers } from 'ethers';
3
+ import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
4
+ import { TransactionResponse } from '@ethersproject/providers';
5
+ /**
6
+ * Returns an ethers contract instance for a Huma pool contract
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
+ * @param {POOL_NAME} poolName The name of the pool contract to get.
11
+ * @param {POOL_TYPE} poolType The type of the pool contract to get.
12
+ * @returns {Contract | null} A contract instance for the Pool contract or null if it could not be found.
13
+ */
14
+ export declare function getPoolContract(signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Contract | null;
15
+ /**
16
+ * Return type of getCreditRecord
17
+ *
18
+ * @memberof getCreditRecord
19
+ * @typedef {Object} CreditRecord
20
+ * @property {BigNumber} unbilledPrincipal - The amount of principal not included in the bill
21
+ * @property {BigNumber} dueDate - Unix timestamp due date of the next payment
22
+ * @property {BigNumber} correction - the adjustment of interest over or under-counted because of drawdown
23
+ * or principal payment in the middle of a billing period
24
+ * @property {BigNumber} totalDue - The due amount of the next payment
25
+ * @property {BigNumber} feesAndInterestDue - Interest and fees due for the next payment
26
+ * @property {number} missedPeriods - # of consecutive missed payments, for default processing
27
+ * @property {number} remainingPeriods - # of payment periods until the maturity of the credit line
28
+ * @property {number} state - status of the credit line.
29
+ * For more info: https://github.com/00labs/huma-contracts/blob/b075a8f957de281e0885e37dbd72a422b6a54a38/contracts/libraries/BaseStructs.sol#L49
30
+ */
31
+ export type CreditRecord = [
32
+ BigNumber,
33
+ BigNumber,
34
+ BigNumber,
35
+ BigNumber,
36
+ BigNumber,
37
+ number,
38
+ number,
39
+ number
40
+ ] & {
41
+ unbilledPrincipal: BigNumber;
42
+ dueDate: BigNumber;
43
+ correction: BigNumber;
44
+ totalDue: BigNumber;
45
+ feesAndInterestDue: BigNumber;
46
+ missedPeriods: number;
47
+ remainingPeriods: number;
48
+ state: number;
49
+ };
50
+ /**
51
+ * Gets the credit record of a wallet in a Huma pool. Denominated in the ERC20 tokens of the pool.
52
+ *
53
+ * @namespace getCreditRecord
54
+ * @async
55
+ * @function
56
+ * @param {string} address - The address to lookup.
57
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to read data.
58
+ * @param {number} chainId - The chain ID of the pool. Used to lookup the pool address.
59
+ * @param {POOL_NAME} poolName - The name of the credit pool. Used to lookup the pool address.
60
+ * @param {POOL_TYPE} poolType - The type of the credit pool. Used to lookup the pool address.
61
+ * @returns {Promise<CreditRecord>} - A Promise of the transaction response.
62
+ */
63
+ export declare function getCreditRecord(address: string, signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<CreditRecord>;
64
+ /**
65
+ * Gets the total due for a Huma pool of the given wallet. Denominated in the ERC20 tokens of the pool.
66
+ *
67
+ * @async
68
+ * @function
69
+ * @param {string} address - The address to lookup.
70
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to read data.
71
+ * @param {number} chainId - The chain ID of the pool. Used to lookup the pool address.
72
+ * @param {POOL_NAME} poolName - The name of the credit pool. Used to lookup the pool address.
73
+ * @param {POOL_TYPE} poolType - The type of the credit pool. Used to lookup the pool address.
74
+ * @returns {Promise<BigNumber>} - A Promise of the transaction response.
75
+ */
76
+ export declare function getTotalDue(address: string, signerOrProvider: ethers.providers.Provider | ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<BigNumber>;
77
+ /**
78
+ * Calls drawdown on a Huma pool contract
79
+ *
80
+ * @async
81
+ * @function
82
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
83
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
84
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
85
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
86
+ * @param {BigNumberish} drawdownAmount - The amount of tokens to withdraw, denominated in the ERC20 tokens of the pool.
87
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
88
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
89
+ */
90
+ export declare function drawdownFromPool(signer: ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, drawdownAmount: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse>;
91
+ /**
92
+ * Calls makePayment on a Huma pool contract. If the pool does not have sufficient allowance to complete the operation,
93
+ * attempt to first increase the allowance of the pool.
94
+ *
95
+ * @async
96
+ * @function
97
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
98
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
99
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
100
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
101
+ * @param {BigNumberish} paymentAmount - The amount of tokens to payback, denominated in the ERC20 tokens of the pool.
102
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
103
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
104
+ */
105
+ export declare function makePaymentToPool(signer: ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, paymentAmount: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse>;
106
+ /**
107
+ * Approves an allowance for a Huma pool contract, which is required to do certain actions (e.g. makePayment)
108
+ *
109
+ * @async
110
+ * @function
111
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
112
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
113
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
114
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
115
+ * @param {BigNumberish} allowanceAmount - The amount of tokens to payback, denominated in the ERC20 tokens of the pool.
116
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
117
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
118
+ */
119
+ export declare function approvePoolAllowance(signer: ethers.Signer, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, allowanceAmount: BigNumberish, gasOpts?: Overrides): Promise<TransactionResponse>;
@@ -0,0 +1,135 @@
1
+ import { getContract, getPoolInfo, getDefaultGasOptions, getERC20Contract, } 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
+ * Gets the credit record of a wallet in a Huma pool. Denominated in the ERC20 tokens of the pool.
19
+ *
20
+ * @namespace getCreditRecord
21
+ * @async
22
+ * @function
23
+ * @param {string} address - The address to lookup.
24
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to read data.
25
+ * @param {number} chainId - The chain ID of the pool. Used to lookup the pool address.
26
+ * @param {POOL_NAME} poolName - The name of the credit pool. Used to lookup the pool address.
27
+ * @param {POOL_TYPE} poolType - The type of the credit pool. Used to lookup the pool address.
28
+ * @returns {Promise<CreditRecord>} - A Promise of the transaction response.
29
+ */
30
+ export async function getCreditRecord(address, signerOrProvider, chainId, poolName, poolType) {
31
+ const poolContract = getPoolContract(signerOrProvider, chainId, poolName, poolType);
32
+ if (!poolContract) {
33
+ throw new Error('Could not find pool contract');
34
+ }
35
+ return poolContract.creditRecordMapping(address);
36
+ }
37
+ /**
38
+ * Gets the total due for a Huma pool of the given wallet. Denominated in the ERC20 tokens of the pool.
39
+ *
40
+ * @async
41
+ * @function
42
+ * @param {string} address - The address to lookup.
43
+ * @param {ethers.providers.Provider | ethers.Signer} signerOrProvider - The signer or provider used to read data.
44
+ * @param {number} chainId - The chain ID of the pool. Used to lookup the pool address.
45
+ * @param {POOL_NAME} poolName - The name of the credit pool. Used to lookup the pool address.
46
+ * @param {POOL_TYPE} poolType - The type of the credit pool. Used to lookup the pool address.
47
+ * @returns {Promise<BigNumber>} - A Promise of the transaction response.
48
+ */
49
+ export async function getTotalDue(address, signerOrProvider, chainId, poolName, poolType) {
50
+ const creditRecord = await getCreditRecord(address, signerOrProvider, chainId, poolName, poolType);
51
+ return creditRecord.totalDue;
52
+ }
53
+ /**
54
+ * Calls drawdown on a Huma pool contract
55
+ *
56
+ * @async
57
+ * @function
58
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
59
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
60
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
61
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
62
+ * @param {BigNumberish} drawdownAmount - The amount of tokens to withdraw, denominated in the ERC20 tokens of the pool.
63
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
64
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
65
+ */
66
+ export async function drawdownFromPool(signer, chainId, poolName, poolType, drawdownAmount, gasOpts = {}) {
67
+ const poolContract = getPoolContract(signer, chainId, poolName, poolType);
68
+ if (!poolContract) {
69
+ throw new Error('Could not find pool contract');
70
+ }
71
+ gasOpts = await getDefaultGasOptions(gasOpts, chainId);
72
+ // TODO: Generate typechain for pool contract
73
+ return poolContract.drawdown(drawdownAmount, gasOpts);
74
+ }
75
+ /**
76
+ * Calls makePayment on a Huma pool contract. If the pool does not have sufficient allowance to complete the operation,
77
+ * attempt to first increase the allowance of the pool.
78
+ *
79
+ * @async
80
+ * @function
81
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
82
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
83
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
84
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
85
+ * @param {BigNumberish} paymentAmount - The amount of tokens to payback, denominated in the ERC20 tokens of the pool.
86
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
87
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
88
+ */
89
+ export async function makePaymentToPool(signer, chainId, poolName, poolType, paymentAmount, gasOpts = {}) {
90
+ const poolInfo = getPoolInfo(chainId, poolName, poolType);
91
+ if (!(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address)) {
92
+ throw new Error('Could not find pool underlying token address');
93
+ }
94
+ const poolTokenContract = getERC20Contract(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address, signer);
95
+ const poolContract = getPoolContract(signer, chainId, poolName, poolType);
96
+ if (!poolContract) {
97
+ throw new Error('Could not find pool contract');
98
+ }
99
+ gasOpts = await getDefaultGasOptions(gasOpts, chainId);
100
+ const allowance = await poolTokenContract.allowance(await signer.getAddress(), poolContract.address);
101
+ if (allowance.lt(paymentAmount)) {
102
+ const approvalTx = await poolTokenContract.approve(poolContract.address, paymentAmount, gasOpts);
103
+ // Wait for 5 block confirmations since this is required for makePayment
104
+ await approvalTx.wait(5);
105
+ }
106
+ // TODO: Generate typechain for pool contract
107
+ return poolContract.makePayment(await signer.getAddress(), paymentAmount, gasOpts);
108
+ }
109
+ /**
110
+ * Approves an allowance for a Huma pool contract, which is required to do certain actions (e.g. makePayment)
111
+ *
112
+ * @async
113
+ * @function
114
+ * @param {ethers.Signer} signer - The signer used to send the transaction.
115
+ * @param {number} chainId - The chain ID of the pool to call drawdown on. Used to lookup the pool address.
116
+ * @param {POOL_NAME} poolName - The name of the credit pool to mint the receivable token from. Used to lookup the pool address.
117
+ * @param {POOL_TYPE} poolType - The type of the credit pool to mint the receivable token from. Used to lookup the pool address.
118
+ * @param {BigNumberish} allowanceAmount - The amount of tokens to payback, denominated in the ERC20 tokens of the pool.
119
+ * @param {Overrides} [gasOpts] - The gas options to use for the transaction.
120
+ * @returns {Promise<TransactionResponse>} - A Promise of the transaction response.
121
+ */
122
+ export async function approvePoolAllowance(signer, chainId, poolName, poolType, allowanceAmount, gasOpts = {}) {
123
+ const poolInfo = getPoolInfo(chainId, poolName, poolType);
124
+ if (!(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address)) {
125
+ throw new Error('Could not find pool underlying token address');
126
+ }
127
+ const poolTokenContract = getERC20Contract(poolInfo === null || poolInfo === void 0 ? void 0 : poolInfo.poolUnderlyingToken.address, signer);
128
+ const poolContract = getPoolContract(signer, chainId, poolName, poolType);
129
+ if (!poolContract) {
130
+ throw new Error('Could not find pool contract');
131
+ }
132
+ gasOpts = await getDefaultGasOptions(gasOpts, chainId);
133
+ return poolTokenContract.approve(poolContract.address, allowanceAmount, gasOpts);
134
+ }
135
+ //# sourceMappingURL=PoolContractHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoolContractHelper.js","sourceRoot":"","sources":["../../src/helpers/PoolContractHelper.ts"],"names":[],"mappings":"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"}
@@ -0,0 +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;
@@ -0,0 +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 rwReceivableContract = (_a = SupplementaryContractsMap[chainId]) === null || _a === void 0 ? void 0 : _a[SupplementaryContracts.RealWorldReceivable];
14
+ if (!rwReceivableContract)
15
+ return null;
16
+ return getContract(rwReceivableContract, REAL_WORLD_RECEIVABLE_ABI, signerOrProvider);
17
+ }
18
+ //# sourceMappingURL=RealWorldReceivableContractHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RealWorldReceivableContractHelper.js","sourceRoot":"","sources":["../../src/helpers/RealWorldReceivableContractHelper.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEtC;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,gBAA2D,EAC3D,OAAe;;IAEf,MAAM,oBAAoB,GACxB,MAAA,yBAAyB,CAAC,OAAO,CAAC,0CAChC,sBAAsB,CAAC,mBAAmB,CAC3C,CAAA;IAEH,IAAI,CAAC,oBAAoB;QAAE,OAAO,IAAI,CAAA;IAEtC,OAAO,WAAW,CAChB,oBAAoB,EACpB,yBAAyB,EACzB,gBAAgB,CACjB,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './RealWorldReceivableContractHelper';
2
+ export * from './ERC20TransferableReceivableContractHelper';
3
+ export * from './PoolContractHelper';
@@ -0,0 +1,4 @@
1
+ export * from './RealWorldReceivableContractHelper';
2
+ export * from './ERC20TransferableReceivableContractHelper';
3
+ export * from './PoolContractHelper';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAA;AACnD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './useContract';
2
+ export * from './useRealWorldReceivableContract';
3
+ export * from './useERC20TransferableReceivableContract';
4
+ export * from './usePoolContract';