@huma-finance/sdk 0.0.39 → 0.0.42-beta.100
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.
- package/API.md +45 -9
- package/dist/cjs/graphql/generatedTypes.d.ts +40 -0
- package/dist/cjs/graphql/generatedTypes.js +9 -0
- package/dist/cjs/graphql/generatedTypes.js.map +1 -0
- package/dist/cjs/graphql/index.d.ts +1 -0
- package/dist/cjs/graphql/index.js +5 -0
- package/dist/cjs/graphql/index.js.map +1 -0
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js +22 -0
- package/dist/cjs/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
- package/dist/cjs/helpers/PoolContractHelper.d.ts +119 -0
- package/dist/cjs/helpers/PoolContractHelper.js +144 -0
- package/dist/cjs/helpers/PoolContractHelper.js.map +1 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js +22 -0
- package/dist/cjs/helpers/RealWorldReceivableContractHelper.js.map +1 -0
- package/dist/cjs/helpers/index.d.ts +3 -0
- package/dist/cjs/helpers/index.js +7 -0
- package/dist/cjs/helpers/index.js.map +1 -0
- package/dist/cjs/hooks/index.d.ts +4 -0
- package/dist/cjs/hooks/index.js +8 -0
- package/dist/cjs/hooks/index.js.map +1 -0
- package/dist/cjs/hooks/useContract.d.ts +13 -0
- package/dist/cjs/hooks/useContract.js +31 -0
- package/dist/cjs/hooks/useContract.js.map +1 -0
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js +21 -0
- package/dist/cjs/hooks/useERC20TransferableReceivableContract.js.map +1 -0
- package/dist/cjs/hooks/usePoolContract.d.ts +60 -0
- package/dist/cjs/hooks/usePoolContract.js +54 -0
- package/dist/cjs/hooks/usePoolContract.js.map +1 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.d.ts +10 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.js +20 -0
- package/dist/cjs/hooks/useRealWorldReceivableContract.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/services/ARWeaveService.d.ts +117 -0
- package/dist/cjs/services/ARWeaveService.js +204 -0
- package/dist/cjs/services/ARWeaveService.js.map +1 -0
- package/dist/cjs/services/EAService.d.ts +20 -0
- package/dist/cjs/services/EAService.js +34 -0
- package/dist/cjs/services/EAService.js.map +1 -0
- package/dist/cjs/services/ReceivableService.d.ts +158 -0
- package/dist/cjs/services/ReceivableService.js +325 -0
- package/dist/cjs/services/ReceivableService.js.map +1 -0
- package/dist/cjs/services/SubgraphService.d.ts +76 -0
- package/dist/cjs/services/SubgraphService.js +149 -0
- package/dist/cjs/services/SubgraphService.js.map +1 -0
- package/dist/cjs/services/index.d.ts +4 -0
- package/dist/cjs/services/index.js +8 -0
- package/dist/cjs/services/index.js.map +1 -0
- package/dist/cjs/utils/chain.d.ts +15 -0
- package/dist/cjs/utils/chain.js +38 -0
- package/dist/cjs/utils/chain.js.map +1 -0
- package/dist/cjs/utils/index.d.ts +4 -0
- package/dist/cjs/utils/index.js +8 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/maticGasStation.d.ts +3 -0
- package/dist/cjs/utils/maticGasStation.js +39 -0
- package/dist/cjs/utils/maticGasStation.js.map +1 -0
- package/dist/cjs/utils/poolInfo.d.ts +8 -0
- package/dist/cjs/utils/poolInfo.js +13 -0
- package/dist/cjs/utils/poolInfo.js.map +1 -0
- package/dist/cjs/utils/web3.d.ts +5 -0
- package/dist/cjs/utils/web3.js +34 -0
- package/dist/cjs/utils/web3.js.map +1 -0
- package/dist/graphql/generatedTypes.d.ts +40 -0
- package/dist/graphql/generatedTypes.js +5 -0
- package/dist/graphql/generatedTypes.js.map +1 -0
- package/dist/graphql/index.d.ts +1 -0
- package/dist/graphql/index.js +2 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/helpers/ERC20TransferableReceivableContractHelper.d.ts +10 -0
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js +18 -0
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js.map +1 -0
- package/dist/helpers/PoolContractHelper.d.ts +119 -0
- package/dist/helpers/PoolContractHelper.js +135 -0
- package/dist/helpers/PoolContractHelper.js.map +1 -0
- package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -0
- package/dist/helpers/RealWorldReceivableContractHelper.js +18 -0
- package/dist/helpers/RealWorldReceivableContractHelper.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +4 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useContract.d.ts +13 -0
- package/dist/hooks/useContract.js +27 -0
- package/dist/hooks/useContract.js.map +1 -0
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -0
- package/dist/hooks/useERC20TransferableReceivableContract.js +17 -0
- package/dist/hooks/useERC20TransferableReceivableContract.js.map +1 -0
- package/dist/hooks/usePoolContract.d.ts +60 -0
- package/dist/hooks/usePoolContract.js +49 -0
- package/dist/hooks/usePoolContract.js.map +1 -0
- package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -0
- package/dist/hooks/useRealWorldReceivableContract.js +16 -0
- package/dist/hooks/useRealWorldReceivableContract.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/services/ARWeaveService.d.ts +117 -0
- package/dist/services/ARWeaveService.js +199 -0
- package/dist/services/ARWeaveService.js.map +1 -0
- package/dist/services/EAService.d.ts +20 -0
- package/dist/services/EAService.js +31 -0
- package/dist/services/EAService.js.map +1 -0
- package/dist/services/ReceivableService.d.ts +158 -0
- package/dist/services/ReceivableService.js +322 -0
- package/dist/services/ReceivableService.js.map +1 -0
- package/dist/services/SubgraphService.d.ts +76 -0
- package/dist/services/SubgraphService.js +146 -0
- package/dist/services/SubgraphService.js.map +1 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.js +5 -0
- package/dist/services/index.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/utils/chain.d.ts +15 -0
- package/dist/utils/chain.js +32 -0
- package/dist/utils/chain.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/maticGasStation.d.ts +3 -0
- package/dist/utils/maticGasStation.js +34 -0
- package/dist/utils/maticGasStation.js.map +1 -0
- package/dist/utils/poolInfo.d.ts +8 -0
- package/dist/utils/poolInfo.js +9 -0
- package/dist/utils/poolInfo.js.map +1 -0
- package/dist/utils/web3.d.ts +5 -0
- package/dist/utils/web3.js +28 -0
- package/dist/utils/web3.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubgraphService = void 0;
|
|
4
|
+
const shared_1 = require("@huma-finance/shared");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the subgraph URL for a given chain ID.
|
|
7
|
+
*
|
|
8
|
+
* @memberof SubgraphService
|
|
9
|
+
* @param {number} chainId - The ID of the chain.
|
|
10
|
+
* @returns {string} The subgraph URL for the given chain ID.
|
|
11
|
+
*/
|
|
12
|
+
function getSubgraphUrlForChainId(chainId) {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
return (_b = (_a = shared_1.PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.subgraph) !== null && _b !== void 0 ? _b : '';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the credit events for a given user.
|
|
18
|
+
*
|
|
19
|
+
* @memberof SubgraphService
|
|
20
|
+
* @param {string} userAddress - The address of the user.
|
|
21
|
+
* @param {number} chainId - The ID of the chain.
|
|
22
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
23
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
24
|
+
* @param {number[]} event - The event types to filter by.
|
|
25
|
+
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
26
|
+
*/
|
|
27
|
+
function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
const url = getSubgraphUrlForChainId(chainId);
|
|
30
|
+
if (!url) {
|
|
31
|
+
return Promise.resolve([]);
|
|
32
|
+
}
|
|
33
|
+
const poolAddress = (_c = (_b = (_a = shared_1.PoolContractMap[chainId]) === null || _a === void 0 ? void 0 : _a[poolType]) === null || _b === void 0 ? void 0 : _b[poolName]) === null || _c === void 0 ? void 0 : _c.pool;
|
|
34
|
+
const query = `
|
|
35
|
+
query {
|
|
36
|
+
creditEvents(
|
|
37
|
+
where: {
|
|
38
|
+
owner: "${userAddress}",
|
|
39
|
+
pool: "${poolAddress}",
|
|
40
|
+
event_in: [${event.join(',')}]
|
|
41
|
+
}
|
|
42
|
+
orderBy: timestamp
|
|
43
|
+
orderDirection: desc
|
|
44
|
+
) {
|
|
45
|
+
amount
|
|
46
|
+
timestamp
|
|
47
|
+
owner
|
|
48
|
+
pool
|
|
49
|
+
event
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
return (0, shared_1.requestPost)(url, JSON.stringify({ query })).then((res) => {
|
|
55
|
+
if (res.errors) {
|
|
56
|
+
console.error(res.errors);
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return res.data.creditEvents;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Returns the last factorized amount for a given user and pool.
|
|
64
|
+
*
|
|
65
|
+
* @memberof SubgraphService
|
|
66
|
+
* @param {string} userAddress - The address of the user.
|
|
67
|
+
* @param {number} chainId - The ID of the chain.
|
|
68
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
69
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
70
|
+
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
71
|
+
*/
|
|
72
|
+
function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
|
|
73
|
+
return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
|
|
74
|
+
shared_1.CreditEvent.DrawdownMadeWithReceivable,
|
|
75
|
+
]).then((events) => Number(events[0].amount));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the paginated real world receivables' info.
|
|
79
|
+
*
|
|
80
|
+
* @memberof SubgraphService
|
|
81
|
+
* @param {string} userAddress - The address of the user.
|
|
82
|
+
* @param {number} chainId - The ID of the chain.
|
|
83
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
84
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
85
|
+
* @param {Pagination} pagination - The pagination option.
|
|
86
|
+
* @returns {Promise<RealWorldReceivableInfoBase>} The paginated real world receivables' info.
|
|
87
|
+
*/
|
|
88
|
+
function getRWReceivableInfo(userAddress, chainId, poolName, poolType, pagination = {
|
|
89
|
+
first: null,
|
|
90
|
+
skip: null,
|
|
91
|
+
orderBy: 'tokenId',
|
|
92
|
+
orderDirection: 'desc',
|
|
93
|
+
}) {
|
|
94
|
+
var _a, _b, _c, _d;
|
|
95
|
+
const url = (_a = shared_1.PoolSubgraphMap[chainId]) === null || _a === void 0 ? void 0 : _a.receivablesSubgraph;
|
|
96
|
+
if (!url) {
|
|
97
|
+
return Promise.resolve([]);
|
|
98
|
+
}
|
|
99
|
+
const poolAddress = (_d = (_c = (_b = shared_1.PoolContractMap[chainId]) === null || _b === void 0 ? void 0 : _b[poolType]) === null || _c === void 0 ? void 0 : _c[poolName]) === null || _d === void 0 ? void 0 : _d.pool;
|
|
100
|
+
const RWReceivablesQuery = `
|
|
101
|
+
query {
|
|
102
|
+
rwreceivables(
|
|
103
|
+
where: {
|
|
104
|
+
owner: "${userAddress}",
|
|
105
|
+
pool: "${poolAddress}",
|
|
106
|
+
}
|
|
107
|
+
first: ${pagination.first}
|
|
108
|
+
skip: ${pagination.skip}
|
|
109
|
+
orderBy: "${pagination.orderBy}"
|
|
110
|
+
orderDirection: "${pagination.orderDirection}"
|
|
111
|
+
) {
|
|
112
|
+
id
|
|
113
|
+
tokenId
|
|
114
|
+
receivableAmount
|
|
115
|
+
paidAmount
|
|
116
|
+
owner
|
|
117
|
+
pool
|
|
118
|
+
maturityDate
|
|
119
|
+
currencyCode
|
|
120
|
+
tokenUri
|
|
121
|
+
status
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
return (0, shared_1.requestPost)(url, JSON.stringify({ query: RWReceivablesQuery }), {
|
|
126
|
+
withCredentials: false,
|
|
127
|
+
}).then((res) => {
|
|
128
|
+
if (res.errors) {
|
|
129
|
+
console.error(res.errors);
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
return res.data.rwreceivables.map((item) => {
|
|
133
|
+
item.poolAddress = item.pool;
|
|
134
|
+
item.tokenURI = item.tokenUri;
|
|
135
|
+
return item;
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
141
|
+
* @namespace SubgraphService
|
|
142
|
+
*/
|
|
143
|
+
exports.SubgraphService = {
|
|
144
|
+
getSubgraphUrlForChainId,
|
|
145
|
+
getCreditEventsForUser,
|
|
146
|
+
getLastFactorizedAmountFromPool,
|
|
147
|
+
getRWReceivableInfo,
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=SubgraphService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubgraphService.js","sourceRoot":"","sources":["../../../src/services/SubgraphService.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./ARWeaveService"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./EAService"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./SubgraphService"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./ReceivableService"), exports);
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,2DAAgC;AAChC,sDAA2B;AAC3B,4DAAiC;AACjC,8DAAmC"}
|
|
@@ -0,0 +1,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,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,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 @@
|
|
|
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 @@
|
|
|
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>;
|