@defisaver/positions-sdk 2.1.26 → 2.1.27-dev-savings-1

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 (79) hide show
  1. package/cjs/config/contracts.d.ts +173 -0
  2. package/cjs/config/contracts.js +23 -1
  3. package/cjs/contracts.d.ts +1650 -0
  4. package/cjs/contracts.js +22 -1
  5. package/cjs/fluid/index.js +16 -4
  6. package/cjs/index.d.ts +2 -1
  7. package/cjs/index.js +3 -1
  8. package/cjs/savings/index.d.ts +7 -0
  9. package/cjs/savings/index.js +75 -0
  10. package/cjs/savings/makerDSR/index.d.ts +7 -0
  11. package/cjs/savings/makerDSR/index.js +94 -0
  12. package/cjs/savings/makerDSR/options.d.ts +2 -0
  13. package/cjs/savings/makerDSR/options.js +11 -0
  14. package/cjs/savings/morphoVaults/index.d.ts +7 -0
  15. package/cjs/savings/morphoVaults/index.js +118 -0
  16. package/cjs/savings/morphoVaults/options.d.ts +16 -0
  17. package/cjs/savings/morphoVaults/options.js +112 -0
  18. package/cjs/savings/yearnVaults/index.d.ts +9 -0
  19. package/cjs/savings/yearnVaults/index.js +113 -0
  20. package/cjs/savings/yearnVaults/options.d.ts +6 -0
  21. package/cjs/savings/yearnVaults/options.js +29 -0
  22. package/cjs/types/index.d.ts +1 -0
  23. package/cjs/types/index.js +1 -0
  24. package/cjs/types/savings/index.d.ts +15 -0
  25. package/cjs/types/savings/index.js +19 -0
  26. package/cjs/types/savings/makerDsr.d.ts +11 -0
  27. package/cjs/types/savings/makerDsr.js +7 -0
  28. package/cjs/types/savings/morphoVaults.d.ts +23 -0
  29. package/cjs/types/savings/morphoVaults.js +19 -0
  30. package/cjs/types/savings/yearnVaults.d.ts +12 -0
  31. package/cjs/types/savings/yearnVaults.js +9 -0
  32. package/esm/config/contracts.d.ts +173 -0
  33. package/esm/config/contracts.js +22 -0
  34. package/esm/contracts.d.ts +1650 -0
  35. package/esm/contracts.js +18 -0
  36. package/esm/fluid/index.js +16 -4
  37. package/esm/index.d.ts +2 -1
  38. package/esm/index.js +2 -1
  39. package/esm/savings/index.d.ts +7 -0
  40. package/esm/savings/index.js +36 -0
  41. package/esm/savings/makerDSR/index.d.ts +7 -0
  42. package/esm/savings/makerDSR/index.js +53 -0
  43. package/esm/savings/makerDSR/options.d.ts +2 -0
  44. package/esm/savings/makerDSR/options.js +8 -0
  45. package/esm/savings/morphoVaults/index.d.ts +7 -0
  46. package/esm/savings/morphoVaults/index.js +77 -0
  47. package/esm/savings/morphoVaults/options.d.ts +16 -0
  48. package/esm/savings/morphoVaults/options.js +108 -0
  49. package/esm/savings/yearnVaults/index.d.ts +9 -0
  50. package/esm/savings/yearnVaults/index.js +70 -0
  51. package/esm/savings/yearnVaults/options.d.ts +6 -0
  52. package/esm/savings/yearnVaults/options.js +25 -0
  53. package/esm/types/index.d.ts +1 -0
  54. package/esm/types/index.js +1 -0
  55. package/esm/types/savings/index.d.ts +15 -0
  56. package/esm/types/savings/index.js +3 -0
  57. package/esm/types/savings/makerDsr.d.ts +11 -0
  58. package/esm/types/savings/makerDsr.js +4 -0
  59. package/esm/types/savings/morphoVaults.d.ts +23 -0
  60. package/esm/types/savings/morphoVaults.js +16 -0
  61. package/esm/types/savings/yearnVaults.d.ts +12 -0
  62. package/esm/types/savings/yearnVaults.js +6 -0
  63. package/package.json +3 -2
  64. package/src/config/contracts.ts +23 -1
  65. package/src/contracts.ts +23 -1
  66. package/src/fluid/index.ts +17 -4
  67. package/src/index.ts +2 -0
  68. package/src/savings/index.ts +43 -0
  69. package/src/savings/makerDsr/index.ts +54 -0
  70. package/src/savings/makerDsr/options.ts +9 -0
  71. package/src/savings/morphoVaults/index.ts +81 -0
  72. package/src/savings/morphoVaults/options.ts +123 -0
  73. package/src/savings/yearnVaults/index.ts +74 -0
  74. package/src/savings/yearnVaults/options.ts +30 -0
  75. package/src/types/index.ts +2 -1
  76. package/src/types/savings/index.ts +18 -0
  77. package/src/types/savings/makerDsr.ts +13 -0
  78. package/src/types/savings/morphoVaults.ts +25 -0
  79. package/src/types/savings/yearnVaults.ts +14 -0
package/esm/contracts.js CHANGED
@@ -45,6 +45,22 @@ export const createViemContractFromConfigFunc = (name, _address) => (client, net
45
45
  client,
46
46
  });
47
47
  };
48
+ export const getMorphoVaultContractViem = (client, address) => {
49
+ const abi = getConfigContractAbi('MorphoVault');
50
+ return getContract({
51
+ address,
52
+ abi,
53
+ client,
54
+ });
55
+ };
56
+ export const getYearnVaultContractViem = (client, address) => {
57
+ const abi = getConfigContractAbi('YearnVault');
58
+ return getContract({
59
+ address,
60
+ abi,
61
+ client,
62
+ });
63
+ };
48
64
  export const MorphoBlueViewContractViem = createViemContractFromConfigFunc('MorphoBlueView');
49
65
  export const AaveLoanInfoV2ContractViem = createViemContractFromConfigFunc('AaveLoanInfoV2');
50
66
  export const AaveV3ViewContractViem = createViemContractFromConfigFunc('AaveV3View');
@@ -89,3 +105,5 @@ export const SparkRewardsControllerViem = createViemContractFromConfigFunc('Spar
89
105
  export const AaveRewardsControllerViem = createViemContractFromConfigFunc('AaveRewardsController');
90
106
  export const LiquityV2sBoldVaultViem = createViemContractFromConfigFunc('LiquityV2sBoldVault');
91
107
  export const StkAAVEViem = createViemContractFromConfigFunc('StkAAVE');
108
+ export const YearnViewContractViem = createViemContractFromConfigFunc('YearnView');
109
+ export const MakerDsrContractViem = createViemContractFromConfigFunc('MakerDsr');
@@ -1138,11 +1138,23 @@ export const _getAllFluidMarketDataChunked = (network, provider) => __awaiter(vo
1138
1138
  });
1139
1139
  export const getAllFluidMarketDataChunked = (network, provider) => __awaiter(void 0, void 0, void 0, function* () { return _getAllFluidMarketDataChunked(network, getViemProvider(provider, network, { batch: { multicall: true } })); });
1140
1140
  export const _getFluidTokenData = (provider, network, token) => __awaiter(void 0, void 0, void 0, function* () {
1141
+ var _a, _b;
1141
1142
  const view = FluidViewContractViem(provider, network);
1142
1143
  const fTokenAddress = getFTokenAddress(token, network);
1143
- const data = yield view.read.getFTokenData([fTokenAddress]);
1144
- const supplyRate = new Dec(data.supplyRate).div(100).toString();
1145
- const rewardsRate = new Dec(data.rewardsRate).div(1e12).toString();
1144
+ const [data, rewardsApiResponse,] = yield Promise.all([
1145
+ yield view.read.getFTokenData([fTokenAddress]),
1146
+ fetch(`https://api.fluid.instadapp.io/v2/lending/${network}/tokens/${fTokenAddress}`),
1147
+ ]);
1148
+ let rewardsData = { rewards: [] };
1149
+ if (!rewardsApiResponse.ok) {
1150
+ console.log('External API Failure: Failed to fetch fluid rewards APY');
1151
+ }
1152
+ else {
1153
+ rewardsData = yield rewardsApiResponse.json();
1154
+ }
1155
+ const supplyRate = new Dec((rewardsData === null || rewardsData === void 0 ? void 0 : rewardsData.supplyRate) || '0').div(100).toString();
1156
+ const rewardRates = ((_a = rewardsData === null || rewardsData === void 0 ? void 0 : rewardsData.rewards) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => acc.add(new Dec(item.rate || '0').div(100)), new Dec(0))) || '0';
1157
+ const stakeRate = new Dec(((_b = rewardsData === null || rewardsData === void 0 ? void 0 : rewardsData.asset) === null || _b === void 0 ? void 0 : _b.stakingApr) || '0').div(100).toString();
1146
1158
  const decimals = data.decimals.toString();
1147
1159
  const depositRate = new Dec(getEthAmountForDecimals(data.convertToShares.toString(), decimals)).toString();
1148
1160
  const withdrawRate = new Dec(getEthAmountForDecimals(data.convertToAssets.toString(), decimals)).toString();
@@ -1152,7 +1164,7 @@ export const _getFluidTokenData = (provider, network, token) => __awaiter(void 0
1152
1164
  decimals,
1153
1165
  totalDeposited: getEthAmountForDecimals(data.totalAssets.toString(), decimals),
1154
1166
  withdrawable: getEthAmountForDecimals(data.withdrawable.toString(), decimals),
1155
- apy: new Dec(supplyRate).add(rewardsRate).toString(),
1167
+ apy: new Dec(supplyRate).plus(rewardRates).plus(stakeRate).toString(),
1156
1168
  depositRate,
1157
1169
  withdrawRate,
1158
1170
  };
package/esm/index.d.ts CHANGED
@@ -19,5 +19,6 @@ import * as llamaLend from './llamaLend';
19
19
  import * as eulerV2 from './eulerV2';
20
20
  import * as portfolio from './portfolio';
21
21
  import * as claiming from './claiming';
22
+ import * as savings from './savings';
22
23
  export * from './types';
23
- export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, };
24
+ export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
package/esm/index.js CHANGED
@@ -19,5 +19,6 @@ import * as llamaLend from './llamaLend';
19
19
  import * as eulerV2 from './eulerV2';
20
20
  import * as portfolio from './portfolio';
21
21
  import * as claiming from './claiming';
22
+ import * as savings from './savings';
22
23
  export * from './types';
23
- export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, };
24
+ export { aaveV2, aaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, liquityV2, maker, exchange, staking, moneymarket, markets, helpers, morphoBlue, llamaLend, eulerV2, fluid, portfolio, claiming, savings, };
@@ -0,0 +1,7 @@
1
+ import { MakerDsrType, MorphoVaultType, YearnVaultType } from '../types';
2
+ import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
3
+ import * as morphoVaults from './morphoVaults';
4
+ import * as yearnVaults from './yearnVaults';
5
+ import * as makerDsr from './makerDSR';
6
+ export { morphoVaults, yearnVaults, makerDsr, };
7
+ export declare const getSavingsData: (provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]) => Promise<Partial<Record<MakerDsrType | MorphoVaultType | YearnVaultType, import("../types").SavingsVaultData>>>;
@@ -0,0 +1,36 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { MakerDsrType, } from '../types';
11
+ import * as morphoVaults from './morphoVaults';
12
+ import * as yearnVaults from './yearnVaults';
13
+ import * as makerDsr from './makerDSR';
14
+ export { morphoVaults, yearnVaults, makerDsr, };
15
+ export const getSavingsData = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const morphoVaultsList = Object.keys(morphoVaults.morphoVaultsOptions.MORPHO_VAULTS);
17
+ const yearnVaultsList = Object.keys(yearnVaults.yearnVaultsOptions.YEARN_VAULTS);
18
+ const savingsData = {};
19
+ yield Promise.all([
20
+ ...morphoVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const vault = morphoVaults.morphoVaultsOptions.getMorphoVault(vaultKey);
22
+ const data = yield morphoVaults.getMorphoVaultData(provider, network, vault, accounts);
23
+ savingsData[vaultKey] = data;
24
+ })),
25
+ ...yearnVaultsList.map((vaultKey) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const vault = yearnVaults.yearnVaultsOptions.getYearnVault(vaultKey);
27
+ const data = yield yearnVaults.getYearnVaultData(provider, network, vault, accounts);
28
+ savingsData[vaultKey] = data;
29
+ })),
30
+ (() => __awaiter(void 0, void 0, void 0, function* () {
31
+ const data = yield makerDsr.getMakerDsrData(provider, network, accounts);
32
+ savingsData[MakerDsrType.MakerDsrVault] = data;
33
+ }))(),
34
+ ]);
35
+ return savingsData;
36
+ });
@@ -0,0 +1,7 @@
1
+ import { Client } from 'viem';
2
+ import { SavingsVaultData } from '../../types';
3
+ import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
4
+ import * as makerDsrOptions from './options';
5
+ export { makerDsrOptions, };
6
+ export declare const _getMakerDsrData: (provider: Client, network: NetworkNumber, accounts: EthAddress[]) => Promise<SavingsVaultData>;
7
+ export declare function getMakerDsrData(provider: EthereumProvider, network: NetworkNumber, accounts: EthAddress[]): Promise<SavingsVaultData>;
@@ -0,0 +1,53 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { getViemProvider } from '../../services/viem';
12
+ import { MakerDsrType } from '../../types';
13
+ import * as makerDsrOptions from './options';
14
+ import { MakerDsrContractViem } from '../../contracts';
15
+ export { makerDsrOptions, };
16
+ export const _getMakerDsrData = (provider, network, accounts) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const contract = MakerDsrContractViem(provider, network);
18
+ const pieAmounts = {};
19
+ const [Pie, chi] = yield Promise.all([
20
+ contract.read.Pie(),
21
+ contract.read.chi(),
22
+ ...accounts.map((account) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const pieAmount = yield contract.read.pie([account]);
24
+ pieAmounts[account] = pieAmount;
25
+ })),
26
+ ]);
27
+ const totalSupplyRad = new Dec(Pie).mul(chi).toString();
28
+ const poolSize = new Dec(totalSupplyRad).div(1e45).toString();
29
+ const supplied = {};
30
+ accounts.forEach((account) => {
31
+ const pie = pieAmounts[account] || BigInt(0);
32
+ const radAmount = new Dec(pie).mul(chi).toString();
33
+ supplied[account.toLowerCase()] = new Dec(radAmount).div(1e45).toString();
34
+ });
35
+ return {
36
+ poolSize,
37
+ liquidity: poolSize,
38
+ supplied,
39
+ asset: 'DAI',
40
+ optionType: MakerDsrType.MakerDsrVault,
41
+ };
42
+ });
43
+ export function getMakerDsrData(provider, network, accounts) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ return _getMakerDsrData(getViemProvider(provider, network, {
46
+ batch: {
47
+ multicall: {
48
+ batchSize: 2500000,
49
+ },
50
+ },
51
+ }), network, accounts);
52
+ });
53
+ }
@@ -0,0 +1,2 @@
1
+ import { MakerDsrVault } from '../../types';
2
+ export declare const MAKER_DSR_VAULT: MakerDsrVault;
@@ -0,0 +1,8 @@
1
+ import { MakerDsrType } from '../../types';
2
+ export const MAKER_DSR_VAULT = {
3
+ type: MakerDsrType.MakerDsrVault,
4
+ name: 'Maker DSR',
5
+ address: '0x197e90f9fad81970ba7976f33cbd77088e5d7cf7',
6
+ asset: 'DAI',
7
+ deploymentBlock: 8928160,
8
+ };
@@ -0,0 +1,7 @@
1
+ import { Client } from 'viem';
2
+ import * as morphoVaultsOptions from './options';
3
+ import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
4
+ import { MorphoVault, SavingsVaultData } from '../../types';
5
+ export { morphoVaultsOptions, };
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>;
@@ -0,0 +1,77 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { request as graphqlRequest } from 'graphql-request';
12
+ import { assetAmountInEth } from '@defisaver/tokens';
13
+ import * as morphoVaultsOptions from './options';
14
+ import { getViemProvider } from '../../services/viem';
15
+ import { getMorphoVaultContractViem } from '../../contracts';
16
+ export { morphoVaultsOptions, };
17
+ const vaultDataQuery = (vaultAddress) => `query vaultByAddress {
18
+ vaultByAddress(chainId: 1, address: "${vaultAddress}") {
19
+ id,
20
+ dailyApy,
21
+ dailyApys {
22
+ apy, netApy
23
+ },
24
+ monthlyApys {
25
+ apy, netApy
26
+ },
27
+ liquidity {
28
+ underlying, usd,
29
+ },
30
+ asset {
31
+ priceUsd
32
+ }
33
+ }
34
+ }`;
35
+ const MORPHO_BLUE_API = 'https://blue-api.morpho.org/graphql';
36
+ export const _getMorphoVaultData = (provider, network, morphoVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const morphoVaultContract = getMorphoVaultContractViem(provider, morphoVault.address);
38
+ const shares = {};
39
+ const [totalAssets, totalSupply, decimals, decimalsOffset, vaultData] = yield Promise.all([
40
+ morphoVaultContract.read.totalAssets(),
41
+ morphoVaultContract.read.totalSupply(),
42
+ morphoVaultContract.read.decimals(),
43
+ morphoVaultContract.read.DECIMALS_OFFSET(),
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
+ })),
49
+ ]);
50
+ const poolSize = assetAmountInEth(totalAssets.toString(), morphoVault.asset);
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
+ });
59
+ return {
60
+ poolSize,
61
+ supplied,
62
+ liquidity,
63
+ asset: morphoVault.asset,
64
+ optionType: morphoVault.type,
65
+ };
66
+ });
67
+ export function getMorphoVaultData(provider, network, morphoVault, accounts) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return _getMorphoVaultData(getViemProvider(provider, network, {
70
+ batch: {
71
+ multicall: {
72
+ batchSize: 2500000,
73
+ },
74
+ },
75
+ }), network, morphoVault, accounts);
76
+ });
77
+ }
@@ -0,0 +1,16 @@
1
+ import { MorphoVault, MorphoVaultType } from '../../types';
2
+ export declare const MORPHO_VAULT_FLAGSHIP_ETH: MorphoVault;
3
+ export declare const MORPHO_VAULT_GAUNTLET_USDC_CORE: MorphoVault;
4
+ export declare const MORPHO_VAULT_GAUNTLET_USDC_PRIME: MorphoVault;
5
+ export declare const MORPHO_VAULT_RE7_WETH: MorphoVault;
6
+ export declare const MORPHO_VAULT_GAUNTLET_WETH_CORE: MorphoVault;
7
+ export declare const MORPHO_VAULT_GAUNTLET_WETH_PRIME: MorphoVault;
8
+ export declare const MORPHO_VAULT_BOOSTED_USDC: MorphoVault;
9
+ export declare const MORPHO_VAULT_STEAKHOUSE_PYUSD: MorphoVault;
10
+ export declare const MORPHO_VAULT_FLAGSHIP_USDT: MorphoVault;
11
+ export declare const MORPHO_VAULT_STEAKHOUSE_USDT: MorphoVault;
12
+ export declare const MORPHO_VAULT_GAUNTLET_USDA_CORE: MorphoVault;
13
+ export declare const MORPHO_VAULT_GAUNTLET_USDT_PRIME: MorphoVault;
14
+ export declare const MORPHO_VAULT_GAUNTLET_RESOLV_USDC: MorphoVault;
15
+ export declare const MORPHO_VAULTS: Record<MorphoVaultType, MorphoVault>;
16
+ export declare const getMorphoVault: (type: MorphoVaultType) => MorphoVault;
@@ -0,0 +1,108 @@
1
+ import { MorphoVaultType } from '../../types';
2
+ export const MORPHO_VAULT_FLAGSHIP_ETH = {
3
+ type: MorphoVaultType.MorphoVaultFlagshipEth,
4
+ name: 'Flagship ETH',
5
+ address: '0x38989BBA00BDF8181F4082995b3DEAe96163aC5D',
6
+ asset: 'WETH',
7
+ deploymentBlock: 18927491,
8
+ };
9
+ export const MORPHO_VAULT_GAUNTLET_USDC_CORE = {
10
+ type: MorphoVaultType.MorphoVaultGauntletUSDCCore,
11
+ name: 'Gauntlet USDC Core',
12
+ address: '0x8eB67A509616cd6A7c1B3c8C21D48FF57df3d458',
13
+ asset: 'USDC',
14
+ deploymentBlock: 19777569,
15
+ };
16
+ export const MORPHO_VAULT_GAUNTLET_USDC_PRIME = {
17
+ type: MorphoVaultType.MorphoVaultGauntletUSDCPrime,
18
+ name: 'Gauntlet USDC Prime',
19
+ address: '0xdd0f28e19C1780eb6396170735D45153D261490d',
20
+ asset: 'USDC',
21
+ deploymentBlock: 19777569,
22
+ };
23
+ export const MORPHO_VAULT_RE7_WETH = {
24
+ type: MorphoVaultType.MorphoVaultRe7Weth,
25
+ name: 'RE7 WETH',
26
+ address: '0x78Fc2c2eD1A4cDb5402365934aE5648aDAd094d0',
27
+ asset: 'WETH',
28
+ deploymentBlock: 19121118,
29
+ };
30
+ export const MORPHO_VAULT_GAUNTLET_WETH_CORE = {
31
+ type: MorphoVaultType.MorphoVaultGauntletWETHCore,
32
+ name: 'Gauntlet WETH Core',
33
+ address: '0x4881Ef0BF6d2365D3dd6499ccd7532bcdBCE0658',
34
+ asset: 'WETH',
35
+ deploymentBlock: 19541126,
36
+ };
37
+ export const MORPHO_VAULT_GAUNTLET_WETH_PRIME = {
38
+ type: MorphoVaultType.MorphoVaultGauntletWETHPrime,
39
+ name: 'Gauntlet WETH Prime',
40
+ address: '0x2371e134e3455e0593363cBF89d3b6cf53740618',
41
+ asset: 'WETH',
42
+ deploymentBlock: 19372149,
43
+ };
44
+ export const MORPHO_VAULT_BOOSTED_USDC = {
45
+ type: MorphoVaultType.MorphoVaultBoostedUSDC,
46
+ name: 'Boosted USDC',
47
+ address: '0xd63070114470f685b75B74D60EEc7c1113d33a3D',
48
+ asset: 'USDC',
49
+ deploymentBlock: 20377233,
50
+ };
51
+ export const MORPHO_VAULT_STEAKHOUSE_PYUSD = {
52
+ type: MorphoVaultType.MorphoVaultSteakhousePYUSD,
53
+ name: 'Steakhouse PYUSD',
54
+ address: '0xbEEF02e5E13584ab96848af90261f0C8Ee04722a',
55
+ asset: 'PYUSD',
56
+ deploymentBlock: 19043398,
57
+ };
58
+ export const MORPHO_VAULT_FLAGSHIP_USDT = {
59
+ type: MorphoVaultType.MorphoVaultFlagshipUSDT,
60
+ name: 'Flagship USDT',
61
+ address: '0x2C25f6C25770fFEC5959D34B94Bf898865e5D6b1',
62
+ asset: 'USDT',
63
+ deploymentBlock: 19127039,
64
+ };
65
+ export const MORPHO_VAULT_STEAKHOUSE_USDT = {
66
+ type: MorphoVaultType.MorphoVaultSteakhouseUSDT,
67
+ name: 'Steakhouse USDT',
68
+ address: '0xbEef047a543E45807105E51A8BBEFCc5950fcfBa',
69
+ asset: 'USDT',
70
+ deploymentBlock: 19043398,
71
+ };
72
+ export const MORPHO_VAULT_GAUNTLET_USDA_CORE = {
73
+ type: MorphoVaultType.MorphoVaultGauntletUSDACore,
74
+ name: 'Gauntlet USDA Core',
75
+ address: '0x125D41A6e5dbf455cD9Df8F80BCC6fd172D52Cc6',
76
+ asset: 'USDA',
77
+ deploymentBlock: 19633608,
78
+ };
79
+ export const MORPHO_VAULT_GAUNTLET_USDT_PRIME = {
80
+ type: MorphoVaultType.MorphoVaultGauntletUSDTPrime,
81
+ name: 'Gauntlet USDT Prime',
82
+ address: '0x8CB3649114051cA5119141a34C200D65dc0Faa73',
83
+ asset: 'USDT',
84
+ deploymentBlock: 19486541,
85
+ };
86
+ export const MORPHO_VAULT_GAUNTLET_RESOLV_USDC = {
87
+ type: MorphoVaultType.MorphoVaultGauntletResolvUSDC,
88
+ name: 'Gauntlet Resolv USDC',
89
+ address: '0x132E6C9C33A62D7727cd359b1f51e5B566E485Eb',
90
+ asset: 'USDC',
91
+ deploymentBlock: 21487882,
92
+ };
93
+ export const MORPHO_VAULTS = {
94
+ [MorphoVaultType.MorphoVaultFlagshipEth]: MORPHO_VAULT_FLAGSHIP_ETH,
95
+ [MorphoVaultType.MorphoVaultGauntletUSDCCore]: MORPHO_VAULT_GAUNTLET_USDC_CORE,
96
+ [MorphoVaultType.MorphoVaultGauntletUSDCPrime]: MORPHO_VAULT_GAUNTLET_USDC_PRIME,
97
+ [MorphoVaultType.MorphoVaultRe7Weth]: MORPHO_VAULT_RE7_WETH,
98
+ [MorphoVaultType.MorphoVaultGauntletWETHCore]: MORPHO_VAULT_GAUNTLET_WETH_CORE,
99
+ [MorphoVaultType.MorphoVaultGauntletWETHPrime]: MORPHO_VAULT_GAUNTLET_WETH_PRIME,
100
+ [MorphoVaultType.MorphoVaultBoostedUSDC]: MORPHO_VAULT_BOOSTED_USDC,
101
+ [MorphoVaultType.MorphoVaultSteakhousePYUSD]: MORPHO_VAULT_STEAKHOUSE_PYUSD,
102
+ [MorphoVaultType.MorphoVaultFlagshipUSDT]: MORPHO_VAULT_FLAGSHIP_USDT,
103
+ [MorphoVaultType.MorphoVaultSteakhouseUSDT]: MORPHO_VAULT_STEAKHOUSE_USDT,
104
+ [MorphoVaultType.MorphoVaultGauntletUSDACore]: MORPHO_VAULT_GAUNTLET_USDA_CORE,
105
+ [MorphoVaultType.MorphoVaultGauntletUSDTPrime]: MORPHO_VAULT_GAUNTLET_USDT_PRIME,
106
+ [MorphoVaultType.MorphoVaultGauntletResolvUSDC]: MORPHO_VAULT_GAUNTLET_RESOLV_USDC,
107
+ };
108
+ export const getMorphoVault = (type) => MORPHO_VAULTS[type];
@@ -0,0 +1,9 @@
1
+ import { Client } from 'viem';
2
+ import { SavingsVaultData, YearnVault } from '../../types';
3
+ import { EthAddress, EthereumProvider, NetworkNumber } from '../../types/common';
4
+ import * as yearnVaultsOptions from './options';
5
+ export { yearnVaultsOptions, };
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>;
8
+ export declare const _getYearnVaultExchangeRate: (provider: Client, yearnVault: YearnVault) => Promise<string>;
9
+ export declare function getYearnVaultExchangeRate(provider: EthereumProvider, network: NetworkNumber, yearnVault: YearnVault): Promise<string>;
@@ -0,0 +1,70 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { assetAmountInEth } from '@defisaver/tokens';
12
+ import { getViemProvider } from '../../services/viem';
13
+ import * as yearnVaultsOptions from './options';
14
+ import { getYearnVaultContractViem, YearnViewContractViem } from '../../contracts';
15
+ export { yearnVaultsOptions, };
16
+ export const _getYearnVaultData = (provider, network, yearnVault, accounts) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const yearnVaultContract = getYearnVaultContractViem(provider, yearnVault.address);
18
+ const viewContract = YearnViewContractViem(provider, network);
19
+ const yvAmountsWei = {};
20
+ const [tokenSupply, underlyingSupply, poolLiquidity] = yield Promise.all([
21
+ yearnVaultContract.read.totalSupply(),
22
+ yearnVaultContract.read.totalAssets(),
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
+ })),
28
+ ]);
29
+ const exchangeRate = new Dec(underlyingSupply).div(tokenSupply).toString();
30
+ const poolSize = assetAmountInEth(underlyingSupply.toString(), yearnVault.asset);
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
+ });
38
+ return {
39
+ poolSize,
40
+ liquidity,
41
+ supplied,
42
+ asset: yearnVault.asset,
43
+ optionType: yearnVault.type,
44
+ };
45
+ });
46
+ export function getYearnVaultData(provider, network, yearnVault, accounts) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return _getYearnVaultData(getViemProvider(provider, network, {
49
+ batch: {
50
+ multicall: {
51
+ batchSize: 2500000,
52
+ },
53
+ },
54
+ }), network, yearnVault, accounts);
55
+ });
56
+ }
57
+ export const _getYearnVaultExchangeRate = (provider, yearnVault) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const yearnVaultContract = getYearnVaultContractViem(provider, yearnVault.address);
59
+ const [tokenSupply, underlyingSupply] = yield Promise.all([
60
+ yearnVaultContract.read.totalSupply(),
61
+ yearnVaultContract.read.totalAssets(),
62
+ ]);
63
+ const exchangeRate = new Dec(underlyingSupply).div(tokenSupply).toString();
64
+ return exchangeRate;
65
+ });
66
+ export function getYearnVaultExchangeRate(provider, network, yearnVault) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ return _getYearnVaultExchangeRate(getViemProvider(provider, network), yearnVault);
69
+ });
70
+ }
@@ -0,0 +1,6 @@
1
+ import { YearnVault, YearnVaultType } from '../../types/savings/yearnVaults';
2
+ export declare const YEARN_VAULT_DAI: YearnVault;
3
+ export declare const YEARN_VAULT_USDC: YearnVault;
4
+ export declare const YEARN_VAULT_USDT: YearnVault;
5
+ export declare const YEARN_VAULTS: Record<YearnVaultType, YearnVault>;
6
+ export declare const getYearnVault: (type: YearnVaultType) => YearnVault;
@@ -0,0 +1,25 @@
1
+ import { YearnVaultType } from '../../types/savings/yearnVaults';
2
+ export const YEARN_VAULT_DAI = {
3
+ type: YearnVaultType.YearnVaultDAI,
4
+ address: '0xdA816459F1AB5631232FE5e97a05BBBb94970c95',
5
+ asset: 'DAI',
6
+ deploymentBlock: 12796965,
7
+ };
8
+ export const YEARN_VAULT_USDC = {
9
+ type: YearnVaultType.YearnVaultUSDC,
10
+ address: '0xa354F35829Ae975e850e23e9615b11Da1B3dC4DE',
11
+ asset: 'USDC',
12
+ deploymentBlock: 13513457,
13
+ };
14
+ export const YEARN_VAULT_USDT = {
15
+ type: YearnVaultType.YearnVaultUSDT,
16
+ address: '0x3B27F92C0e212C671EA351827EDF93DB27cc0c65',
17
+ asset: 'USDT',
18
+ deploymentBlock: 14980240,
19
+ };
20
+ export const YEARN_VAULTS = {
21
+ [YearnVaultType.YearnVaultDAI]: YEARN_VAULT_DAI,
22
+ [YearnVaultType.YearnVaultUSDC]: YEARN_VAULT_USDC,
23
+ [YearnVaultType.YearnVaultUSDT]: YEARN_VAULT_USDT,
24
+ };
25
+ export const getYearnVault = (type) => YEARN_VAULTS[type];
@@ -12,3 +12,4 @@ export * from './fluid';
12
12
  export * from './portfolio';
13
13
  export * from './merit';
14
14
  export * from './merkl';
15
+ export * from './savings';
@@ -12,3 +12,4 @@ export * from './fluid';
12
12
  export * from './portfolio';
13
13
  export * from './merit';
14
14
  export * from './merkl';
15
+ export * from './savings';
@@ -0,0 +1,15 @@
1
+ import { EthAddress } from '../common';
2
+ import { MakerDsrType } from './makerDsr';
3
+ import { MorphoVaultType } from './morphoVaults';
4
+ import { YearnVaultType } from './yearnVaults';
5
+ export * from './morphoVaults';
6
+ export * from './yearnVaults';
7
+ export * from './makerDsr';
8
+ export interface SavingsVaultData {
9
+ poolSize: string;
10
+ liquidity: string;
11
+ supplied: Record<EthAddress, string>;
12
+ asset: string;
13
+ optionType: string;
14
+ }
15
+ export type SavingsData = Partial<Record<MorphoVaultType | YearnVaultType | MakerDsrType, SavingsVaultData>>;
@@ -0,0 +1,3 @@
1
+ export * from './morphoVaults';
2
+ export * from './yearnVaults';
3
+ export * from './makerDsr';
@@ -0,0 +1,11 @@
1
+ import { EthAddress } from '../common';
2
+ export declare enum MakerDsrType {
3
+ MakerDsrVault = "maker_dsr"
4
+ }
5
+ export interface MakerDsrVault {
6
+ type: MakerDsrType;
7
+ name: string;
8
+ address: EthAddress;
9
+ asset: string;
10
+ deploymentBlock: number;
11
+ }
@@ -0,0 +1,4 @@
1
+ export var MakerDsrType;
2
+ (function (MakerDsrType) {
3
+ MakerDsrType["MakerDsrVault"] = "maker_dsr";
4
+ })(MakerDsrType || (MakerDsrType = {}));
@@ -0,0 +1,23 @@
1
+ import { EthAddress } from '../common';
2
+ export declare enum MorphoVaultType {
3
+ MorphoVaultFlagshipEth = "morpho_vault_flagship_eth",
4
+ MorphoVaultGauntletUSDCCore = "morpho_vault_gauntlet_usdc_core",
5
+ MorphoVaultGauntletUSDCPrime = "morpho_vault_gauntlet_usdc_prime",
6
+ MorphoVaultRe7Weth = "morpho_vault_re7_weth",
7
+ MorphoVaultGauntletWETHCore = "morpho_vault_gauntlet_weth_core",
8
+ MorphoVaultGauntletWETHPrime = "morpho_vault_gauntlet_weth_prime",
9
+ MorphoVaultBoostedUSDC = "morpho_vault_usual_boosted_usdc",
10
+ MorphoVaultSteakhousePYUSD = "morpho_vault_steakhouse_pyusd",
11
+ MorphoVaultFlagshipUSDT = "morpho_vault_flagship_usdt",
12
+ MorphoVaultSteakhouseUSDT = "morpho_vault_steakhouse_usdt",
13
+ MorphoVaultGauntletUSDACore = "morpho_vault_gauntlet_usda_core",
14
+ MorphoVaultGauntletUSDTPrime = "morpho_vault_gauntlet_usdt_prime",
15
+ MorphoVaultGauntletResolvUSDC = "morpho_vault_gauntlet_resolv_usdc"
16
+ }
17
+ export interface MorphoVault {
18
+ type: MorphoVaultType;
19
+ name: string;
20
+ address: EthAddress;
21
+ asset: string;
22
+ deploymentBlock: number;
23
+ }
@@ -0,0 +1,16 @@
1
+ export var MorphoVaultType;
2
+ (function (MorphoVaultType) {
3
+ MorphoVaultType["MorphoVaultFlagshipEth"] = "morpho_vault_flagship_eth";
4
+ MorphoVaultType["MorphoVaultGauntletUSDCCore"] = "morpho_vault_gauntlet_usdc_core";
5
+ MorphoVaultType["MorphoVaultGauntletUSDCPrime"] = "morpho_vault_gauntlet_usdc_prime";
6
+ MorphoVaultType["MorphoVaultRe7Weth"] = "morpho_vault_re7_weth";
7
+ MorphoVaultType["MorphoVaultGauntletWETHCore"] = "morpho_vault_gauntlet_weth_core";
8
+ MorphoVaultType["MorphoVaultGauntletWETHPrime"] = "morpho_vault_gauntlet_weth_prime";
9
+ MorphoVaultType["MorphoVaultBoostedUSDC"] = "morpho_vault_usual_boosted_usdc";
10
+ MorphoVaultType["MorphoVaultSteakhousePYUSD"] = "morpho_vault_steakhouse_pyusd";
11
+ MorphoVaultType["MorphoVaultFlagshipUSDT"] = "morpho_vault_flagship_usdt";
12
+ MorphoVaultType["MorphoVaultSteakhouseUSDT"] = "morpho_vault_steakhouse_usdt";
13
+ MorphoVaultType["MorphoVaultGauntletUSDACore"] = "morpho_vault_gauntlet_usda_core";
14
+ MorphoVaultType["MorphoVaultGauntletUSDTPrime"] = "morpho_vault_gauntlet_usdt_prime";
15
+ MorphoVaultType["MorphoVaultGauntletResolvUSDC"] = "morpho_vault_gauntlet_resolv_usdc";
16
+ })(MorphoVaultType || (MorphoVaultType = {}));
@@ -0,0 +1,12 @@
1
+ import { EthAddress } from '../common';
2
+ export declare enum YearnVaultType {
3
+ YearnVaultDAI = "yearn_vault_dai",
4
+ YearnVaultUSDC = "yearn_vault_usdc",
5
+ YearnVaultUSDT = "yearn_vault_usdt"
6
+ }
7
+ export interface YearnVault {
8
+ type: YearnVaultType;
9
+ address: EthAddress;
10
+ asset: string;
11
+ deploymentBlock: number;
12
+ }