@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.
- package/API.md +482 -0
- package/README.md +9 -5
- 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/PoolContractHelper.d.ts +30 -1
- package/dist/cjs/helpers/PoolContractHelper.js +45 -1
- package/dist/cjs/helpers/PoolContractHelper.js.map +1 -1
- package/dist/cjs/services/ARWeaveService.d.ts +1 -18
- package/dist/cjs/services/ARWeaveService.js +17 -51
- package/dist/cjs/services/ARWeaveService.js.map +1 -1
- package/dist/cjs/services/ReceivableService.d.ts +11 -0
- package/dist/cjs/services/ReceivableService.js +71 -20
- package/dist/cjs/services/ReceivableService.js.map +1 -1
- 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 -10
- package/dist/helpers/ERC20TransferableReceivableContractHelper.js +17 -17
- package/dist/helpers/PoolContractHelper.d.ts +41 -12
- package/dist/helpers/PoolContractHelper.js +58 -16
- package/dist/helpers/PoolContractHelper.js.map +1 -1
- package/dist/helpers/RealWorldReceivableContractHelper.d.ts +10 -10
- package/dist/helpers/RealWorldReceivableContractHelper.js +17 -17
- package/dist/helpers/index.d.ts +3 -3
- package/dist/helpers/index.js +3 -3
- package/dist/hooks/index.d.ts +4 -4
- package/dist/hooks/index.js +4 -4
- package/dist/hooks/useContract.d.ts +13 -13
- package/dist/hooks/useContract.js +26 -26
- package/dist/hooks/useERC20TransferableReceivableContract.d.ts +12 -12
- package/dist/hooks/useERC20TransferableReceivableContract.js +16 -16
- package/dist/hooks/usePoolContract.d.ts +60 -60
- package/dist/hooks/usePoolContract.js +48 -48
- package/dist/hooks/useRealWorldReceivableContract.d.ts +10 -10
- package/dist/hooks/useRealWorldReceivableContract.js +15 -15
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/services/ARWeaveService.d.ts +81 -84
- package/dist/services/ARWeaveService.js +133 -144
- package/dist/services/ARWeaveService.js.map +1 -1
- package/dist/services/EAService.d.ts +18 -18
- package/dist/services/EAService.js +9 -9
- package/dist/services/ReceivableService.d.ts +87 -76
- package/dist/services/ReceivableService.js +182 -132
- package/dist/services/ReceivableService.js.map +1 -1
- package/dist/services/SubgraphService.d.ts +53 -53
- package/dist/services/SubgraphService.js +79 -79
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +4 -4
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/utils/chain.d.ts +14 -14
- package/dist/utils/chain.js +28 -28
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/utils/poolInfo.d.ts +9 -9
- package/dist/utils/poolInfo.js +9 -9
- package/dist/utils/web3.d.ts +4 -4
- package/dist/utils/web3.js +23 -23
- package/getting-started.md +191 -0
- package/package.json +13 -6
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the subgraph URL for a given chain ID.
|
|
4
|
-
*
|
|
5
|
-
* @memberof SubgraphService
|
|
6
|
-
* @param {number} chainId - The ID of the chain.
|
|
7
|
-
* @returns {string} The subgraph URL for the given chain ID.
|
|
8
|
-
*/
|
|
9
|
-
declare function getSubgraphUrlForChainId(chainId: number): string;
|
|
10
|
-
/**
|
|
11
|
-
* Represents the payload of a credit event.
|
|
12
|
-
* @typedef {Object} CreditEventPayload
|
|
13
|
-
*/
|
|
14
|
-
export type CreditEventPayload = {
|
|
15
|
-
amount?: string;
|
|
16
|
-
timestamp?: string;
|
|
17
|
-
owner?: string;
|
|
18
|
-
pool?: string;
|
|
19
|
-
event?: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Returns the credit events for a given user.
|
|
23
|
-
*
|
|
24
|
-
* @memberof SubgraphService
|
|
25
|
-
* @param {string} userAddress - The address of the user.
|
|
26
|
-
* @param {number} chainId - The ID of the chain.
|
|
27
|
-
* @param {POOL_NAME} poolName - The name of the pool.
|
|
28
|
-
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
29
|
-
* @param {string[]} event - The event types to filter by.
|
|
30
|
-
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
31
|
-
*/
|
|
32
|
-
declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: string[]): Promise<CreditEventPayload[]>;
|
|
33
|
-
/**
|
|
34
|
-
* Returns the last factorized amount for a given user and pool.
|
|
35
|
-
*
|
|
36
|
-
* @memberof SubgraphService
|
|
37
|
-
* @param {string} userAddress - The address of the user.
|
|
38
|
-
* @param {number} chainId - The ID of the chain.
|
|
39
|
-
* @param {POOL_NAME} poolName - The name of the pool.
|
|
40
|
-
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
41
|
-
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
42
|
-
*/
|
|
43
|
-
declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
|
|
44
|
-
/**
|
|
45
|
-
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
46
|
-
* @namespace SubgraphService
|
|
47
|
-
*/
|
|
48
|
-
export declare const SubgraphService: {
|
|
49
|
-
getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
|
|
50
|
-
getCreditEventsForUser: typeof getCreditEventsForUser;
|
|
51
|
-
getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
|
|
52
|
-
};
|
|
53
|
-
export {};
|
|
1
|
+
import { POOL_NAME, POOL_TYPE } from '@huma-finance/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the subgraph URL for a given chain ID.
|
|
4
|
+
*
|
|
5
|
+
* @memberof SubgraphService
|
|
6
|
+
* @param {number} chainId - The ID of the chain.
|
|
7
|
+
* @returns {string} The subgraph URL for the given chain ID.
|
|
8
|
+
*/
|
|
9
|
+
declare function getSubgraphUrlForChainId(chainId: number): string;
|
|
10
|
+
/**
|
|
11
|
+
* Represents the payload of a credit event.
|
|
12
|
+
* @typedef {Object} CreditEventPayload
|
|
13
|
+
*/
|
|
14
|
+
export type CreditEventPayload = {
|
|
15
|
+
amount?: string;
|
|
16
|
+
timestamp?: string;
|
|
17
|
+
owner?: string;
|
|
18
|
+
pool?: string;
|
|
19
|
+
event?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Returns the credit events for a given user.
|
|
23
|
+
*
|
|
24
|
+
* @memberof SubgraphService
|
|
25
|
+
* @param {string} userAddress - The address of the user.
|
|
26
|
+
* @param {number} chainId - The ID of the chain.
|
|
27
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
28
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
29
|
+
* @param {string[]} event - The event types to filter by.
|
|
30
|
+
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
31
|
+
*/
|
|
32
|
+
declare function getCreditEventsForUser(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE, event: string[]): Promise<CreditEventPayload[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the last factorized amount for a given user and pool.
|
|
35
|
+
*
|
|
36
|
+
* @memberof SubgraphService
|
|
37
|
+
* @param {string} userAddress - The address of the user.
|
|
38
|
+
* @param {number} chainId - The ID of the chain.
|
|
39
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
40
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
41
|
+
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
42
|
+
*/
|
|
43
|
+
declare function getLastFactorizedAmountFromPool(userAddress: string, chainId: number, poolName: POOL_NAME, poolType: POOL_TYPE): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
46
|
+
* @namespace SubgraphService
|
|
47
|
+
*/
|
|
48
|
+
export declare const SubgraphService: {
|
|
49
|
+
getSubgraphUrlForChainId: typeof getSubgraphUrlForChainId;
|
|
50
|
+
getCreditEventsForUser: typeof getCreditEventsForUser;
|
|
51
|
+
getLastFactorizedAmountFromPool: typeof getLastFactorizedAmountFromPool;
|
|
52
|
+
};
|
|
53
|
+
export {};
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { CreditEvent, PoolContractMap, } from '@huma-finance/shared';
|
|
2
|
-
/**
|
|
3
|
-
* Returns the subgraph URL for a given chain ID.
|
|
4
|
-
*
|
|
5
|
-
* @memberof SubgraphService
|
|
6
|
-
* @param {number} chainId - The ID of the chain.
|
|
7
|
-
* @returns {string} The subgraph URL for the given chain ID.
|
|
8
|
-
*/
|
|
9
|
-
function getSubgraphUrlForChainId(chainId) {
|
|
10
|
-
switch (chainId) {
|
|
11
|
-
case 5:
|
|
12
|
-
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
|
|
13
|
-
case 137:
|
|
14
|
-
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-polygon';
|
|
15
|
-
case 80001:
|
|
16
|
-
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-mumbai';
|
|
17
|
-
default:
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Returns the credit events for a given user.
|
|
23
|
-
*
|
|
24
|
-
* @memberof SubgraphService
|
|
25
|
-
* @param {string} userAddress - The address of the user.
|
|
26
|
-
* @param {number} chainId - The ID of the chain.
|
|
27
|
-
* @param {POOL_NAME} poolName - The name of the pool.
|
|
28
|
-
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
29
|
-
* @param {string[]} event - The event types to filter by.
|
|
30
|
-
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
31
|
-
*/
|
|
32
|
-
function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
|
|
33
|
-
var _a, _b, _c;
|
|
34
|
-
const url = getSubgraphUrlForChainId(chainId);
|
|
35
|
-
if (!url) {
|
|
36
|
-
return Promise.resolve([]);
|
|
37
|
-
}
|
|
38
|
-
const poolAddress = (_c = (_b = (_a = 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;
|
|
1
|
+
import { CreditEvent, PoolContractMap, } from '@huma-finance/shared';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the subgraph URL for a given chain ID.
|
|
4
|
+
*
|
|
5
|
+
* @memberof SubgraphService
|
|
6
|
+
* @param {number} chainId - The ID of the chain.
|
|
7
|
+
* @returns {string} The subgraph URL for the given chain ID.
|
|
8
|
+
*/
|
|
9
|
+
function getSubgraphUrlForChainId(chainId) {
|
|
10
|
+
switch (chainId) {
|
|
11
|
+
case 5:
|
|
12
|
+
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-goerli';
|
|
13
|
+
case 137:
|
|
14
|
+
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-polygon';
|
|
15
|
+
case 80001:
|
|
16
|
+
return 'https://api.thegraph.com/subgraphs/name/00labs/huma-mumbai';
|
|
17
|
+
default:
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the credit events for a given user.
|
|
23
|
+
*
|
|
24
|
+
* @memberof SubgraphService
|
|
25
|
+
* @param {string} userAddress - The address of the user.
|
|
26
|
+
* @param {number} chainId - The ID of the chain.
|
|
27
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
28
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
29
|
+
* @param {string[]} event - The event types to filter by.
|
|
30
|
+
* @returns {Promise<CreditEventPayload[]>} The credit events for the given user.
|
|
31
|
+
*/
|
|
32
|
+
function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event) {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
const url = getSubgraphUrlForChainId(chainId);
|
|
35
|
+
if (!url) {
|
|
36
|
+
return Promise.resolve([]);
|
|
37
|
+
}
|
|
38
|
+
const poolAddress = (_c = (_b = (_a = 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;
|
|
39
39
|
const query = `
|
|
40
40
|
query {
|
|
41
41
|
creditEvents(
|
|
@@ -54,45 +54,45 @@ function getCreditEventsForUser(userAddress, chainId, poolName, poolType, event)
|
|
|
54
54
|
event
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
`;
|
|
58
|
-
return fetch(url, {
|
|
59
|
-
method: 'POST',
|
|
60
|
-
headers: {
|
|
61
|
-
'Content-Type': 'application/json',
|
|
62
|
-
},
|
|
63
|
-
body: JSON.stringify({ query }),
|
|
64
|
-
})
|
|
65
|
-
.then((res) => res.json())
|
|
66
|
-
.then((res) => {
|
|
67
|
-
if (res.errors) {
|
|
68
|
-
console.error(res.errors);
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
return res.data.creditEvents;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Returns the last factorized amount for a given user and pool.
|
|
76
|
-
*
|
|
77
|
-
* @memberof SubgraphService
|
|
78
|
-
* @param {string} userAddress - The address of the user.
|
|
79
|
-
* @param {number} chainId - The ID of the chain.
|
|
80
|
-
* @param {POOL_NAME} poolName - The name of the pool.
|
|
81
|
-
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
82
|
-
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
83
|
-
*/
|
|
84
|
-
function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
|
|
85
|
-
return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
|
|
86
|
-
CreditEvent.DrawdownMadeWithReceivable.toString(),
|
|
87
|
-
]).then((events) => Number(events[0].amount));
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
91
|
-
* @namespace SubgraphService
|
|
92
|
-
*/
|
|
93
|
-
export const SubgraphService = {
|
|
94
|
-
getSubgraphUrlForChainId,
|
|
95
|
-
getCreditEventsForUser,
|
|
96
|
-
getLastFactorizedAmountFromPool,
|
|
97
|
-
};
|
|
57
|
+
`;
|
|
58
|
+
return fetch(url, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({ query }),
|
|
64
|
+
})
|
|
65
|
+
.then((res) => res.json())
|
|
66
|
+
.then((res) => {
|
|
67
|
+
if (res.errors) {
|
|
68
|
+
console.error(res.errors);
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
return res.data.creditEvents;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Returns the last factorized amount for a given user and pool.
|
|
76
|
+
*
|
|
77
|
+
* @memberof SubgraphService
|
|
78
|
+
* @param {string} userAddress - The address of the user.
|
|
79
|
+
* @param {number} chainId - The ID of the chain.
|
|
80
|
+
* @param {POOL_NAME} poolName - The name of the pool.
|
|
81
|
+
* @param {POOL_TYPE} poolType - The type of the pool.
|
|
82
|
+
* @returns {Promise<number>} The last factorized amount for the given user and pool.
|
|
83
|
+
*/
|
|
84
|
+
function getLastFactorizedAmountFromPool(userAddress, chainId, poolName, poolType) {
|
|
85
|
+
return getCreditEventsForUser(userAddress, chainId, poolName, poolType, [
|
|
86
|
+
CreditEvent.DrawdownMadeWithReceivable.toString(),
|
|
87
|
+
]).then((events) => Number(events[0].amount));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* An object that contains functions to interact with Huma's Subgraph storage.
|
|
91
|
+
* @namespace SubgraphService
|
|
92
|
+
*/
|
|
93
|
+
export const SubgraphService = {
|
|
94
|
+
getSubgraphUrlForChainId,
|
|
95
|
+
getCreditEventsForUser,
|
|
96
|
+
getLastFactorizedAmountFromPool,
|
|
97
|
+
};
|
|
98
98
|
//# sourceMappingURL=SubgraphService.js.map
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './ARWeaveService';
|
|
2
|
-
export * from './EAService';
|
|
3
|
-
export * from './SubgraphService';
|
|
4
|
-
export * from './ReceivableService';
|
|
1
|
+
export * from './ARWeaveService';
|
|
2
|
+
export * from './EAService';
|
|
3
|
+
export * from './SubgraphService';
|
|
4
|
+
export * from './ReceivableService';
|
package/dist/services/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './ARWeaveService';
|
|
2
|
-
export * from './EAService';
|
|
3
|
-
export * from './SubgraphService';
|
|
4
|
-
export * from './ReceivableService';
|
|
1
|
+
export * from './ARWeaveService';
|
|
2
|
+
export * from './EAService';
|
|
3
|
+
export * from './SubgraphService';
|
|
4
|
+
export * from './ReceivableService';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|