@defisaver/positions-sdk 2.1.22-dev-savings-1 → 2.1.22-dev-savings-2
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/cjs/savings/index.d.ts +1 -1
- package/cjs/savings/index.js +3 -3
- package/cjs/savings/morphoVaults/index.d.ts +2 -2
- package/cjs/savings/morphoVaults/index.js +16 -8
- package/cjs/savings/yearnVaults/index.d.ts +2 -2
- package/cjs/savings/yearnVaults/index.js +16 -8
- package/cjs/types/savings/index.d.ts +2 -1
- package/esm/savings/index.d.ts +1 -1
- package/esm/savings/index.js +3 -3
- package/esm/savings/morphoVaults/index.d.ts +2 -2
- package/esm/savings/morphoVaults/index.js +16 -8
- package/esm/savings/yearnVaults/index.d.ts +2 -2
- package/esm/savings/yearnVaults/index.js +16 -8
- package/esm/types/savings/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/savings/index.ts +3 -3
- package/src/savings/morphoVaults/index.ts +19 -9
- package/src/savings/yearnVaults/index.ts +18 -8
- package/src/types/savings/index.ts +2 -1
package/cjs/savings/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
|
3
3
|
import * as morphoVaults from './morphoVaults';
|
|
4
4
|
import * as yearnVaults from './yearnVaults';
|
|
5
5
|
export { morphoVaults, yearnVaults, };
|
|
6
|
-
export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber,
|
|
6
|
+
export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]) => Promise<SavingsData>;
|
package/cjs/savings/index.js
CHANGED
|
@@ -47,7 +47,7 @@ const morphoVaults = __importStar(require("./morphoVaults"));
|
|
|
47
47
|
exports.morphoVaults = morphoVaults;
|
|
48
48
|
const yearnVaults = __importStar(require("./yearnVaults"));
|
|
49
49
|
exports.yearnVaults = yearnVaults;
|
|
50
|
-
const getSavingsData = (provider, network,
|
|
50
|
+
const getSavingsData = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
const morphoVaultsList = Object.keys(morphoVaults.morphoVaultsOptions.MORPHO_VAULTS);
|
|
52
52
|
const yearnVaultsList = Object.keys(yearnVaults.yearnVaultsOptions.YEARN_VAULTS);
|
|
53
53
|
const savingsData = {
|
|
@@ -57,12 +57,12 @@ const getSavingsData = (provider, network, account) => __awaiter(void 0, void 0,
|
|
|
57
57
|
yield Promise.all([
|
|
58
58
|
...morphoVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
59
|
const vault = morphoVaults.morphoVaultsOptions.getMorphoVault(vaultKey);
|
|
60
|
-
const data = yield morphoVaults.getMorphoVaultData(provider, network, vault,
|
|
60
|
+
const data = yield morphoVaults.getMorphoVaultData(provider, network, vault, accounts);
|
|
61
61
|
savingsData.morphoVaults[vaultKey] = data;
|
|
62
62
|
})),
|
|
63
63
|
...yearnVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
64
|
const vault = yearnVaults.yearnVaultsOptions.getYearnVault(vaultKey);
|
|
65
|
-
const data = yield yearnVaults.getYearnVaultData(provider, network, vault,
|
|
65
|
+
const data = yield yearnVaults.getYearnVaultData(provider, network, vault, accounts);
|
|
66
66
|
savingsData.yearnVaults[vaultKey] = data;
|
|
67
67
|
})),
|
|
68
68
|
]);
|
|
@@ -3,5 +3,5 @@ import * as morphoVaultsOptions from './options';
|
|
|
3
3
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
4
4
|
import { MorphoVault, SavingsVaultData } from '../../types';
|
|
5
5
|
export { morphoVaultsOptions, };
|
|
6
|
-
export declare const _getMorphoVaultData: (provider: Client, network: NetworkNumber, morphoVault: MorphoVault,
|
|
7
|
-
export declare function getMorphoVaultData(provider: EthereumProvider, network: NetworkNumber, morphoVault: MorphoVault,
|
|
6
|
+
export declare const _getMorphoVaultData: (provider: Client, network: NetworkNumber, morphoVault: MorphoVault, accounts: EthAddress[]) => Promise<SavingsVaultData>;
|
|
7
|
+
export declare function getMorphoVaultData(provider: EthereumProvider, network: NetworkNumber, morphoVault: MorphoVault, accounts: EthAddress[]): Promise<SavingsVaultData>;
|
|
@@ -73,21 +73,29 @@ vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
|
73
73
|
}
|
|
74
74
|
}`;
|
|
75
75
|
const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
|
|
76
|
-
const _getMorphoVaultData = (provider, network, morphoVault,
|
|
76
|
+
const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
77
|
const morphoVaultContract = (0, contracts_1.getMorphoVaultContractViem)(provider, morphoVault.address);
|
|
78
|
-
const
|
|
78
|
+
const shares = {};
|
|
79
|
+
const [totalAssets, totalSupply, decimals, decimalsOffset, vaultData] = yield Promise.all([
|
|
79
80
|
morphoVaultContract.read.totalAssets(),
|
|
80
|
-
morphoVaultContract.read.balanceOf([account]),
|
|
81
81
|
morphoVaultContract.read.totalSupply(),
|
|
82
82
|
morphoVaultContract.read.decimals(),
|
|
83
83
|
morphoVaultContract.read.DECIMALS_OFFSET(),
|
|
84
84
|
(0, graphql_request_1.request)(MORPHO_BLUE_API, vaultDataQuery(morphoVault.address)),
|
|
85
|
+
...accounts.map((account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
86
|
+
const share = yield morphoVaultContract.read.balanceOf([account]);
|
|
87
|
+
shares[account] = share;
|
|
88
|
+
})),
|
|
85
89
|
]);
|
|
86
|
-
const supplied = new decimal_js_1.default(new decimal_js_1.default(shares.toString()).mul(new decimal_js_1.default(totalAssets.toString()).add(1)).div(new decimal_js_1.default(totalSupply.toString()).add(Math.pow(10, decimalsOffset))).div(Math.pow(10, 18))
|
|
87
|
-
.toFixed(decimals)).mul(Math.pow(10, decimalsOffset))
|
|
88
|
-
.toString();
|
|
89
90
|
const poolSize = (0, tokens_1.assetAmountInEth)(totalAssets.toString(), morphoVault.asset);
|
|
90
91
|
const liquidity = (0, tokens_1.assetAmountInEth)(vaultData.vaultByAddress.liquidity.underlying, morphoVault.asset);
|
|
92
|
+
const supplied = {};
|
|
93
|
+
accounts.forEach((account) => {
|
|
94
|
+
const share = shares[account] || BigInt(0);
|
|
95
|
+
supplied[account.toLowerCase()] = new decimal_js_1.default(new decimal_js_1.default(share.toString()).mul(new decimal_js_1.default(totalAssets.toString()).add(1)).div(new decimal_js_1.default(totalSupply.toString()).add(Math.pow(10, decimalsOffset))).div(Math.pow(10, 18))
|
|
96
|
+
.toFixed(decimals)).mul(Math.pow(10, decimalsOffset))
|
|
97
|
+
.toString();
|
|
98
|
+
});
|
|
91
99
|
return {
|
|
92
100
|
poolSize,
|
|
93
101
|
supplied,
|
|
@@ -95,7 +103,7 @@ const _getMorphoVaultData = (provider, network, morphoVault, account) => __await
|
|
|
95
103
|
};
|
|
96
104
|
});
|
|
97
105
|
exports._getMorphoVaultData = _getMorphoVaultData;
|
|
98
|
-
function getMorphoVaultData(provider, network, morphoVault,
|
|
106
|
+
function getMorphoVaultData(provider, network, morphoVault, accounts) {
|
|
99
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
108
|
return (0, exports._getMorphoVaultData)((0, viem_1.getViemProvider)(provider, network, {
|
|
101
109
|
batch: {
|
|
@@ -103,6 +111,6 @@ function getMorphoVaultData(provider, network, morphoVault, account) {
|
|
|
103
111
|
batchSize: 2500000,
|
|
104
112
|
},
|
|
105
113
|
},
|
|
106
|
-
}), network, morphoVault,
|
|
114
|
+
}), network, morphoVault, accounts);
|
|
107
115
|
});
|
|
108
116
|
}
|
|
@@ -3,5 +3,5 @@ import { SavingsVaultData, YearnVault } from '../../types';
|
|
|
3
3
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
4
4
|
import * as yearnVaultsOptions from './options';
|
|
5
5
|
export { yearnVaultsOptions, };
|
|
6
|
-
export declare const _getYearnVaultData: (provider: Client, network: NetworkNumber, yearnVault: YearnVault,
|
|
7
|
-
export declare function getYearnVaultData(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault,
|
|
6
|
+
export declare const _getYearnVaultData: (provider: Client, network: NetworkNumber, yearnVault: YearnVault, accounts: EthAddress[]) => Promise<SavingsVaultData>;
|
|
7
|
+
export declare function getYearnVaultData(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault, accounts: EthAddress[]): Promise<SavingsVaultData>;
|
|
@@ -53,28 +53,36 @@ const viem_1 = require("../../services/viem");
|
|
|
53
53
|
const yearnVaultsOptions = __importStar(require("./options"));
|
|
54
54
|
exports.yearnVaultsOptions = yearnVaultsOptions;
|
|
55
55
|
const contracts_1 = require("../../contracts");
|
|
56
|
-
const _getYearnVaultData = (provider, network, yearnVault,
|
|
56
|
+
const _getYearnVaultData = (provider, network, yearnVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
57
|
const yearnVaultContract = (0, contracts_1.getYearnVaultContractViem)(provider, yearnVault.address);
|
|
58
58
|
const viewContract = (0, contracts_1.YearnViewContractViem)(provider, network);
|
|
59
|
-
const
|
|
59
|
+
const yvAmountsWei = {};
|
|
60
|
+
const [tokenSupply, underlyingSupply, poolLiquidity] = yield Promise.all([
|
|
60
61
|
yearnVaultContract.read.totalSupply(),
|
|
61
62
|
yearnVaultContract.read.totalAssets(),
|
|
62
|
-
yearnVaultContract.read.balanceOf([account]),
|
|
63
63
|
viewContract.read.getPoolLiquidity([yearnVault.address]),
|
|
64
|
+
...accounts.map((account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
const yvAmount = yield yearnVaultContract.read.balanceOf([account]);
|
|
66
|
+
yvAmountsWei[account] = yvAmount;
|
|
67
|
+
})),
|
|
64
68
|
]);
|
|
65
69
|
const exchangeRate = new decimal_js_1.default(underlyingSupply).div(tokenSupply).toString();
|
|
66
|
-
const underlyingAmountWei = new decimal_js_1.default(yvAmountWei).mul(exchangeRate).toString();
|
|
67
|
-
const supplied = (0, tokens_1.assetAmountInEth)(underlyingAmountWei, yearnVault.asset);
|
|
68
70
|
const poolSize = (0, tokens_1.assetAmountInEth)(underlyingSupply.toString(), yearnVault.asset);
|
|
69
71
|
const liquidity = (0, tokens_1.assetAmountInEth)(poolLiquidity.toString(), yearnVault.asset);
|
|
72
|
+
const supplied = {};
|
|
73
|
+
accounts.forEach((account) => {
|
|
74
|
+
const yvAmountWei = yvAmountsWei[account] || BigInt(0);
|
|
75
|
+
const underlyingAmountWei = new decimal_js_1.default(yvAmountWei).mul(exchangeRate).toString();
|
|
76
|
+
supplied[account.toLowerCase()] = (0, tokens_1.assetAmountInEth)(underlyingAmountWei, yearnVault.asset);
|
|
77
|
+
});
|
|
70
78
|
return {
|
|
71
79
|
poolSize,
|
|
72
|
-
supplied,
|
|
73
80
|
liquidity,
|
|
81
|
+
supplied,
|
|
74
82
|
};
|
|
75
83
|
});
|
|
76
84
|
exports._getYearnVaultData = _getYearnVaultData;
|
|
77
|
-
function getYearnVaultData(provider, network, yearnVault,
|
|
85
|
+
function getYearnVaultData(provider, network, yearnVault, accounts) {
|
|
78
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
87
|
return (0, exports._getYearnVaultData)((0, viem_1.getViemProvider)(provider, network, {
|
|
80
88
|
batch: {
|
|
@@ -82,6 +90,6 @@ function getYearnVaultData(provider, network, yearnVault, account) {
|
|
|
82
90
|
batchSize: 2500000,
|
|
83
91
|
},
|
|
84
92
|
},
|
|
85
|
-
}), network, yearnVault,
|
|
93
|
+
}), network, yearnVault, accounts);
|
|
86
94
|
});
|
|
87
95
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { EthAddress } from '../common';
|
|
1
2
|
import { MorphoVaultType } from './morphoVaults';
|
|
2
3
|
import { YearnVaultType } from './yearnVaults';
|
|
3
4
|
export * from './morphoVaults';
|
|
4
5
|
export * from './yearnVaults';
|
|
5
6
|
export interface SavingsVaultData {
|
|
6
7
|
poolSize: string;
|
|
7
|
-
supplied: string;
|
|
8
8
|
liquidity: string;
|
|
9
|
+
supplied: Record<EthAddress, string>;
|
|
9
10
|
}
|
|
10
11
|
export interface SavingsData {
|
|
11
12
|
morphoVaults: {
|
package/esm/savings/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
|
3
3
|
import * as morphoVaults from './morphoVaults';
|
|
4
4
|
import * as yearnVaults from './yearnVaults';
|
|
5
5
|
export { morphoVaults, yearnVaults, };
|
|
6
|
-
export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber,
|
|
6
|
+
export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]) => Promise<SavingsData>;
|
package/esm/savings/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import * as morphoVaults from './morphoVaults';
|
|
11
11
|
import * as yearnVaults from './yearnVaults';
|
|
12
12
|
export { morphoVaults, yearnVaults, };
|
|
13
|
-
export const getSavingsData = (provider, network,
|
|
13
|
+
export const getSavingsData = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
14
|
const morphoVaultsList = Object.keys(morphoVaults.morphoVaultsOptions.MORPHO_VAULTS);
|
|
15
15
|
const yearnVaultsList = Object.keys(yearnVaults.yearnVaultsOptions.YEARN_VAULTS);
|
|
16
16
|
const savingsData = {
|
|
@@ -20,12 +20,12 @@ export const getSavingsData = (provider, network, account) => __awaiter(void 0,
|
|
|
20
20
|
yield Promise.all([
|
|
21
21
|
...morphoVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
22
|
const vault = morphoVaults.morphoVaultsOptions.getMorphoVault(vaultKey);
|
|
23
|
-
const data = yield morphoVaults.getMorphoVaultData(provider, network, vault,
|
|
23
|
+
const data = yield morphoVaults.getMorphoVaultData(provider, network, vault, accounts);
|
|
24
24
|
savingsData.morphoVaults[vaultKey] = data;
|
|
25
25
|
})),
|
|
26
26
|
...yearnVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
27
|
const vault = yearnVaults.yearnVaultsOptions.getYearnVault(vaultKey);
|
|
28
|
-
const data = yield yearnVaults.getYearnVaultData(provider, network, vault,
|
|
28
|
+
const data = yield yearnVaults.getYearnVaultData(provider, network, vault, accounts);
|
|
29
29
|
savingsData.yearnVaults[vaultKey] = data;
|
|
30
30
|
})),
|
|
31
31
|
]);
|
|
@@ -3,5 +3,5 @@ import * as morphoVaultsOptions from './options';
|
|
|
3
3
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
4
4
|
import { MorphoVault, SavingsVaultData } from '../../types';
|
|
5
5
|
export { morphoVaultsOptions, };
|
|
6
|
-
export declare const _getMorphoVaultData: (provider: Client, network: NetworkNumber, morphoVault: MorphoVault,
|
|
7
|
-
export declare function getMorphoVaultData(provider: EthereumProvider, network: NetworkNumber, morphoVault: MorphoVault,
|
|
6
|
+
export declare const _getMorphoVaultData: (provider: Client, network: NetworkNumber, morphoVault: MorphoVault, accounts: EthAddress[]) => Promise<SavingsVaultData>;
|
|
7
|
+
export declare function getMorphoVaultData(provider: EthereumProvider, network: NetworkNumber, morphoVault: MorphoVault, accounts: EthAddress[]): Promise<SavingsVaultData>;
|
|
@@ -33,28 +33,36 @@ vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
|
33
33
|
}
|
|
34
34
|
}`;
|
|
35
35
|
const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
|
|
36
|
-
export const _getMorphoVaultData = (provider, network, morphoVault,
|
|
36
|
+
export const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
37
|
const morphoVaultContract = getMorphoVaultContractViem(provider, morphoVault.address);
|
|
38
|
-
const
|
|
38
|
+
const shares = {};
|
|
39
|
+
const [totalAssets, totalSupply, decimals, decimalsOffset, vaultData] = yield Promise.all([
|
|
39
40
|
morphoVaultContract.read.totalAssets(),
|
|
40
|
-
morphoVaultContract.read.balanceOf([account]),
|
|
41
41
|
morphoVaultContract.read.totalSupply(),
|
|
42
42
|
morphoVaultContract.read.decimals(),
|
|
43
43
|
morphoVaultContract.read.DECIMALS_OFFSET(),
|
|
44
44
|
graphqlRequest(MORPHO_BLUE_API, vaultDataQuery(morphoVault.address)),
|
|
45
|
+
...accounts.map((account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const share = yield morphoVaultContract.read.balanceOf([account]);
|
|
47
|
+
shares[account] = share;
|
|
48
|
+
})),
|
|
45
49
|
]);
|
|
46
|
-
const supplied = new Dec(new Dec(shares.toString()).mul(new Dec(totalAssets.toString()).add(1)).div(new Dec(totalSupply.toString()).add(Math.pow(10, decimalsOffset))).div(Math.pow(10, 18))
|
|
47
|
-
.toFixed(decimals)).mul(Math.pow(10, decimalsOffset))
|
|
48
|
-
.toString();
|
|
49
50
|
const poolSize = assetAmountInEth(totalAssets.toString(), morphoVault.asset);
|
|
50
51
|
const liquidity = assetAmountInEth(vaultData.vaultByAddress.liquidity.underlying, morphoVault.asset);
|
|
52
|
+
const supplied = {};
|
|
53
|
+
accounts.forEach((account) => {
|
|
54
|
+
const share = shares[account] || BigInt(0);
|
|
55
|
+
supplied[account.toLowerCase()] = new Dec(new Dec(share.toString()).mul(new Dec(totalAssets.toString()).add(1)).div(new Dec(totalSupply.toString()).add(Math.pow(10, decimalsOffset))).div(Math.pow(10, 18))
|
|
56
|
+
.toFixed(decimals)).mul(Math.pow(10, decimalsOffset))
|
|
57
|
+
.toString();
|
|
58
|
+
});
|
|
51
59
|
return {
|
|
52
60
|
poolSize,
|
|
53
61
|
supplied,
|
|
54
62
|
liquidity,
|
|
55
63
|
};
|
|
56
64
|
});
|
|
57
|
-
export function getMorphoVaultData(provider, network, morphoVault,
|
|
65
|
+
export function getMorphoVaultData(provider, network, morphoVault, accounts) {
|
|
58
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
67
|
return _getMorphoVaultData(getViemProvider(provider, network, {
|
|
60
68
|
batch: {
|
|
@@ -62,6 +70,6 @@ export function getMorphoVaultData(provider, network, morphoVault, account) {
|
|
|
62
70
|
batchSize: 2500000,
|
|
63
71
|
},
|
|
64
72
|
},
|
|
65
|
-
}), network, morphoVault,
|
|
73
|
+
}), network, morphoVault, accounts);
|
|
66
74
|
});
|
|
67
75
|
}
|
|
@@ -3,5 +3,5 @@ import { SavingsVaultData, YearnVault } from '../../types';
|
|
|
3
3
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
|
|
4
4
|
import * as yearnVaultsOptions from './options';
|
|
5
5
|
export { yearnVaultsOptions, };
|
|
6
|
-
export declare const _getYearnVaultData: (provider: Client, network: NetworkNumber, yearnVault: YearnVault,
|
|
7
|
-
export declare function getYearnVaultData(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault,
|
|
6
|
+
export declare const _getYearnVaultData: (provider: Client, network: NetworkNumber, yearnVault: YearnVault, accounts: EthAddress[]) => Promise<SavingsVaultData>;
|
|
7
|
+
export declare function getYearnVaultData(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault, accounts: EthAddress[]): Promise<SavingsVaultData>;
|
|
@@ -13,27 +13,35 @@ import { getViemProvider } from '../../services/viem';
|
|
|
13
13
|
import * as yearnVaultsOptions from './options';
|
|
14
14
|
import { getYearnVaultContractViem, YearnViewContractViem } from '../../contracts';
|
|
15
15
|
export { yearnVaultsOptions, };
|
|
16
|
-
export const _getYearnVaultData = (provider, network, yearnVault,
|
|
16
|
+
export const _getYearnVaultData = (provider, network, yearnVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
17
|
const yearnVaultContract = getYearnVaultContractViem(provider, yearnVault.address);
|
|
18
18
|
const viewContract = YearnViewContractViem(provider, network);
|
|
19
|
-
const
|
|
19
|
+
const yvAmountsWei = {};
|
|
20
|
+
const [tokenSupply, underlyingSupply, poolLiquidity] = yield Promise.all([
|
|
20
21
|
yearnVaultContract.read.totalSupply(),
|
|
21
22
|
yearnVaultContract.read.totalAssets(),
|
|
22
|
-
yearnVaultContract.read.balanceOf([account]),
|
|
23
23
|
viewContract.read.getPoolLiquidity([yearnVault.address]),
|
|
24
|
+
...accounts.map((account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const yvAmount = yield yearnVaultContract.read.balanceOf([account]);
|
|
26
|
+
yvAmountsWei[account] = yvAmount;
|
|
27
|
+
})),
|
|
24
28
|
]);
|
|
25
29
|
const exchangeRate = new Dec(underlyingSupply).div(tokenSupply).toString();
|
|
26
|
-
const underlyingAmountWei = new Dec(yvAmountWei).mul(exchangeRate).toString();
|
|
27
|
-
const supplied = assetAmountInEth(underlyingAmountWei, yearnVault.asset);
|
|
28
30
|
const poolSize = assetAmountInEth(underlyingSupply.toString(), yearnVault.asset);
|
|
29
31
|
const liquidity = assetAmountInEth(poolLiquidity.toString(), yearnVault.asset);
|
|
32
|
+
const supplied = {};
|
|
33
|
+
accounts.forEach((account) => {
|
|
34
|
+
const yvAmountWei = yvAmountsWei[account] || BigInt(0);
|
|
35
|
+
const underlyingAmountWei = new Dec(yvAmountWei).mul(exchangeRate).toString();
|
|
36
|
+
supplied[account.toLowerCase()] = assetAmountInEth(underlyingAmountWei, yearnVault.asset);
|
|
37
|
+
});
|
|
30
38
|
return {
|
|
31
39
|
poolSize,
|
|
32
|
-
supplied,
|
|
33
40
|
liquidity,
|
|
41
|
+
supplied,
|
|
34
42
|
};
|
|
35
43
|
});
|
|
36
|
-
export function getYearnVaultData(provider, network, yearnVault,
|
|
44
|
+
export function getYearnVaultData(provider, network, yearnVault, accounts) {
|
|
37
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
46
|
return _getYearnVaultData(getViemProvider(provider, network, {
|
|
39
47
|
batch: {
|
|
@@ -41,6 +49,6 @@ export function getYearnVaultData(provider, network, yearnVault, account) {
|
|
|
41
49
|
batchSize: 2500000,
|
|
42
50
|
},
|
|
43
51
|
},
|
|
44
|
-
}), network, yearnVault,
|
|
52
|
+
}), network, yearnVault, accounts);
|
|
45
53
|
});
|
|
46
54
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { EthAddress } from '../common';
|
|
1
2
|
import { MorphoVaultType } from './morphoVaults';
|
|
2
3
|
import { YearnVaultType } from './yearnVaults';
|
|
3
4
|
export * from './morphoVaults';
|
|
4
5
|
export * from './yearnVaults';
|
|
5
6
|
export interface SavingsVaultData {
|
|
6
7
|
poolSize: string;
|
|
7
|
-
supplied: string;
|
|
8
8
|
liquidity: string;
|
|
9
|
+
supplied: Record<EthAddress, string>;
|
|
9
10
|
}
|
|
10
11
|
export interface SavingsData {
|
|
11
12
|
morphoVaults: {
|
package/package.json
CHANGED
package/src/savings/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ export {
|
|
|
11
11
|
export const getSavingsData = async (
|
|
12
12
|
provider: EthereumProvider,
|
|
13
13
|
network: NetworkNumber,
|
|
14
|
-
|
|
14
|
+
accounts: EthAddress[],
|
|
15
15
|
) => {
|
|
16
16
|
const morphoVaultsList = Object.keys(morphoVaults.morphoVaultsOptions.MORPHO_VAULTS) as MorphoVaultType[];
|
|
17
17
|
const yearnVaultsList = Object.keys(yearnVaults.yearnVaultsOptions.YEARN_VAULTS) as YearnVaultType[];
|
|
@@ -24,12 +24,12 @@ export const getSavingsData = async (
|
|
|
24
24
|
await Promise.all([
|
|
25
25
|
...morphoVaultsList.map(async (vaultKey) => {
|
|
26
26
|
const vault = morphoVaults.morphoVaultsOptions.getMorphoVault(vaultKey);
|
|
27
|
-
const data = await morphoVaults.getMorphoVaultData(provider, network, vault,
|
|
27
|
+
const data = await morphoVaults.getMorphoVaultData(provider, network, vault, accounts);
|
|
28
28
|
savingsData.morphoVaults[vaultKey] = data;
|
|
29
29
|
}),
|
|
30
30
|
...yearnVaultsList.map(async (vaultKey) => {
|
|
31
31
|
const vault = yearnVaults.yearnVaultsOptions.getYearnVault(vaultKey);
|
|
32
|
-
const data = await yearnVaults.getYearnVaultData(provider, network, vault,
|
|
32
|
+
const data = await yearnVaults.getYearnVaultData(provider, network, vault, accounts);
|
|
33
33
|
savingsData.yearnVaults[vaultKey] = data;
|
|
34
34
|
}),
|
|
35
35
|
]);
|
|
@@ -33,24 +33,34 @@ vaultByAddress(chainId: 1, address: "${vaultAddress}") {
|
|
|
33
33
|
|
|
34
34
|
const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
|
|
35
35
|
|
|
36
|
-
export const _getMorphoVaultData = async (provider: Client, network: NetworkNumber, morphoVault: MorphoVault,
|
|
36
|
+
export const _getMorphoVaultData = async (provider: Client, network: NetworkNumber, morphoVault: MorphoVault, accounts: EthAddress[]): Promise<SavingsVaultData> => {
|
|
37
37
|
const morphoVaultContract = getMorphoVaultContractViem(provider, morphoVault.address);
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
const shares: Record<EthAddress, bigint> = {};
|
|
40
|
+
|
|
41
|
+
const [totalAssets, totalSupply, decimals, decimalsOffset, vaultData] = await Promise.all([
|
|
39
42
|
morphoVaultContract.read.totalAssets(),
|
|
40
|
-
morphoVaultContract.read.balanceOf([account]),
|
|
41
43
|
morphoVaultContract.read.totalSupply(),
|
|
42
44
|
morphoVaultContract.read.decimals(),
|
|
43
45
|
morphoVaultContract.read.DECIMALS_OFFSET(),
|
|
44
46
|
graphqlRequest(MORPHO_BLUE_API, vaultDataQuery(morphoVault.address)),
|
|
47
|
+
...accounts.map(async (account) => {
|
|
48
|
+
const share = await morphoVaultContract.read.balanceOf([account]);
|
|
49
|
+
shares[account] = share;
|
|
50
|
+
}),
|
|
45
51
|
]);
|
|
46
52
|
|
|
47
|
-
const supplied = new Dec(new Dec(shares.toString()).mul(new Dec(totalAssets.toString()).add(1)).div(new Dec(totalSupply.toString()).add(10 ** decimalsOffset)).div(10 ** 18)
|
|
48
|
-
.toFixed(decimals)).mul(10 ** decimalsOffset)
|
|
49
|
-
.toString();
|
|
50
|
-
|
|
51
53
|
const poolSize = assetAmountInEth(totalAssets.toString(), morphoVault.asset);
|
|
52
54
|
const liquidity = assetAmountInEth((vaultData as any).vaultByAddress.liquidity.underlying, morphoVault.asset);
|
|
53
55
|
|
|
56
|
+
const supplied: Record<EthAddress, string> = {};
|
|
57
|
+
accounts.forEach((account) => {
|
|
58
|
+
const share = shares[account] || BigInt(0);
|
|
59
|
+
supplied[account.toLowerCase() as EthAddress] = new Dec(new Dec(share.toString()).mul(new Dec(totalAssets.toString()).add(1)).div(new Dec(totalSupply.toString()).add(10 ** decimalsOffset)).div(10 ** 18)
|
|
60
|
+
.toFixed(decimals)).mul(10 ** decimalsOffset)
|
|
61
|
+
.toString();
|
|
62
|
+
});
|
|
63
|
+
|
|
54
64
|
return {
|
|
55
65
|
poolSize,
|
|
56
66
|
supplied,
|
|
@@ -58,12 +68,12 @@ export const _getMorphoVaultData = async (provider: Client, network: NetworkNumb
|
|
|
58
68
|
};
|
|
59
69
|
};
|
|
60
70
|
|
|
61
|
-
export async function getMorphoVaultData(provider: EthereumProvider, network: NetworkNumber, morphoVault: MorphoVault,
|
|
71
|
+
export async function getMorphoVaultData(provider: EthereumProvider, network: NetworkNumber, morphoVault: MorphoVault, accounts: EthAddress[]): Promise<SavingsVaultData> {
|
|
62
72
|
return _getMorphoVaultData(getViemProvider(provider, network, {
|
|
63
73
|
batch: {
|
|
64
74
|
multicall: {
|
|
65
75
|
batchSize: 2500000,
|
|
66
76
|
},
|
|
67
77
|
},
|
|
68
|
-
}), network, morphoVault,
|
|
78
|
+
}), network, morphoVault, accounts);
|
|
69
79
|
}
|
|
@@ -11,36 +11,46 @@ export {
|
|
|
11
11
|
yearnVaultsOptions,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export const _getYearnVaultData = async (provider: Client, network: NetworkNumber, yearnVault: YearnVault,
|
|
14
|
+
export const _getYearnVaultData = async (provider: Client, network: NetworkNumber, yearnVault: YearnVault, accounts: EthAddress[]): Promise<SavingsVaultData> => {
|
|
15
15
|
const yearnVaultContract = getYearnVaultContractViem(provider, yearnVault.address);
|
|
16
16
|
const viewContract = YearnViewContractViem(provider, network);
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const yvAmountsWei: Record<EthAddress, bigint> = {};
|
|
19
|
+
|
|
20
|
+
const [tokenSupply, underlyingSupply, poolLiquidity] = await Promise.all([
|
|
19
21
|
yearnVaultContract.read.totalSupply(),
|
|
20
22
|
yearnVaultContract.read.totalAssets(),
|
|
21
|
-
yearnVaultContract.read.balanceOf([account]),
|
|
22
23
|
viewContract.read.getPoolLiquidity([yearnVault.address]),
|
|
24
|
+
...accounts.map(async (account) => {
|
|
25
|
+
const yvAmount = await yearnVaultContract.read.balanceOf([account]);
|
|
26
|
+
yvAmountsWei[account] = yvAmount;
|
|
27
|
+
}),
|
|
23
28
|
]);
|
|
24
29
|
|
|
25
30
|
const exchangeRate = new Dec(underlyingSupply).div(tokenSupply).toString();
|
|
26
|
-
const underlyingAmountWei = new Dec(yvAmountWei).mul(exchangeRate).toString();
|
|
27
|
-
const supplied = assetAmountInEth(underlyingAmountWei, yearnVault.asset);
|
|
28
31
|
const poolSize = assetAmountInEth(underlyingSupply.toString(), yearnVault.asset);
|
|
29
32
|
const liquidity = assetAmountInEth(poolLiquidity.toString(), yearnVault.asset);
|
|
30
33
|
|
|
34
|
+
const supplied: Record<EthAddress, string> = {};
|
|
35
|
+
accounts.forEach((account) => {
|
|
36
|
+
const yvAmountWei = yvAmountsWei[account] || BigInt(0);
|
|
37
|
+
const underlyingAmountWei = new Dec(yvAmountWei).mul(exchangeRate).toString();
|
|
38
|
+
supplied[account.toLowerCase() as EthAddress] = assetAmountInEth(underlyingAmountWei, yearnVault.asset);
|
|
39
|
+
});
|
|
40
|
+
|
|
31
41
|
return {
|
|
32
42
|
poolSize,
|
|
33
|
-
supplied,
|
|
34
43
|
liquidity,
|
|
44
|
+
supplied,
|
|
35
45
|
};
|
|
36
46
|
};
|
|
37
47
|
|
|
38
|
-
export async function getYearnVaultData(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault,
|
|
48
|
+
export async function getYearnVaultData(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault, accounts: EthAddress[]): Promise<SavingsVaultData> {
|
|
39
49
|
return _getYearnVaultData(getViemProvider(provider, network, {
|
|
40
50
|
batch: {
|
|
41
51
|
multicall: {
|
|
42
52
|
batchSize: 2500000,
|
|
43
53
|
},
|
|
44
54
|
},
|
|
45
|
-
}), network, yearnVault,
|
|
55
|
+
}), network, yearnVault, accounts);
|
|
46
56
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EthAddress } from '../common';
|
|
1
2
|
import { MorphoVaultType } from './morphoVaults';
|
|
2
3
|
import { YearnVaultType } from './yearnVaults';
|
|
3
4
|
|
|
@@ -6,8 +7,8 @@ export * from './yearnVaults';
|
|
|
6
7
|
|
|
7
8
|
export interface SavingsVaultData {
|
|
8
9
|
poolSize: string,
|
|
9
|
-
supplied: string,
|
|
10
10
|
liquidity: string,
|
|
11
|
+
supplied: Record<EthAddress, string>,
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export interface SavingsData {
|