@defisaver/positions-sdk 2.1.71-aave-v4-2-dev → 2.1.71-aave-v4-lend

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.
@@ -1,6 +1,7 @@
1
1
  import { Client } from 'viem';
2
2
  import { AaveV4AccountData, AaveV4SpokeData, AaveV4SpokeInfo } from '../types';
3
3
  import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
4
+ export * as lend from './lend';
4
5
  export declare function _getAaveV4SpokeData(provider: Client, network: NetworkNumber, market: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
5
6
  export declare function getAaveV4SpokeData(provider: EthereumProvider, network: NetworkNumber, spoke: AaveV4SpokeInfo, blockNumber?: 'latest' | number): Promise<AaveV4SpokeData>;
6
7
  export declare function _getAaveV4AccountData(provider: Client, network: NetworkNumber, spokeData: AaveV4SpokeData, address: EthAddress, blockNumber?: 'latest' | number): Promise<AaveV4AccountData>;
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -12,6 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
45
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
46
  };
14
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.lend = void 0;
15
49
  exports._getAaveV4SpokeData = _getAaveV4SpokeData;
16
50
  exports.getAaveV4SpokeData = getAaveV4SpokeData;
17
51
  exports._getAaveV4AccountData = _getAaveV4AccountData;
@@ -25,6 +59,7 @@ const staking_1 = require("../staking");
25
59
  const utils_1 = require("../services/utils");
26
60
  const aaveV4Helpers_1 = require("../helpers/aaveV4Helpers");
27
61
  const aaveV4_1 = require("../markets/aaveV4");
62
+ exports.lend = __importStar(require("./lend"));
28
63
  const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, void 0, function* () {
29
64
  const hubData = yield viewContract.read.getHubAllAssetsData([hubAddress]);
30
65
  return {
@@ -38,6 +73,7 @@ const fetchHubData = (viewContract, hubAddress) => __awaiter(void 0, void 0, voi
38
73
  };
39
74
  });
40
75
  const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, network) => __awaiter(void 0, void 0, void 0, function* () {
76
+ var _a, _b, _c, _d, _e, _f;
41
77
  const assetInfo = (0, tokens_1.getAssetInfoByAddress)(reserveAsset.underlying, network);
42
78
  const symbol = (0, utils_1.wethToEth)(assetInfo.symbol);
43
79
  const hubInfo = (0, aaveV4_1.getAaveV4HubByAddress)(network, reserveAsset.hub);
@@ -65,6 +101,12 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
65
101
  });
66
102
  }
67
103
  }
104
+ const totalSuppliedRaw = (_a = reserveAsset.totalSupplied) !== null && _a !== void 0 ? _a : 0;
105
+ const totalDrawnRaw = (_b = reserveAsset.totalDrawn) !== null && _b !== void 0 ? _b : 0;
106
+ const totalPremiumRaw = (_c = reserveAsset.totalPremium) !== null && _c !== void 0 ? _c : 0;
107
+ const totalDebtRaw = (_d = reserveAsset.totalDebt) !== null && _d !== void 0 ? _d : 0;
108
+ const supplyCapRaw = (_e = reserveAsset.supplyCap) !== null && _e !== void 0 ? _e : 0;
109
+ const borrowCapRaw = (_f = reserveAsset.borrowCap) !== null && _f !== void 0 ? _f : 0;
68
110
  return ({
69
111
  symbol,
70
112
  underlying: reserveAsset.underlying,
@@ -79,12 +121,12 @@ const formatReserveAsset = (reserveAsset, hubAsset, reserveId, oracleDecimals, n
79
121
  collateralFactor: new decimal_js_1.default(reserveAsset.collateralFactor).div(10000).toNumber(),
80
122
  liquidationFee: new decimal_js_1.default(reserveAsset.liquidationFee).div(10000).toNumber(),
81
123
  price: new decimal_js_1.default(reserveAsset.price).div(new decimal_js_1.default(10).pow(oracleDecimals)).toString(),
82
- totalSupplied: (0, tokens_1.assetAmountInEth)(reserveAsset.totalSupplied.toString(), symbol),
83
- totalDrawn: (0, tokens_1.assetAmountInEth)(reserveAsset.totalDrawn.toString(), symbol),
84
- totalPremium: (0, tokens_1.assetAmountInEth)(reserveAsset.totalPremium.toString(), symbol),
85
- totalDebt: (0, tokens_1.assetAmountInEth)(reserveAsset.totalDebt.toString(), symbol),
86
- supplyCap: (0, tokens_1.assetAmountInEth)(reserveAsset.supplyCap.toString(), symbol),
87
- borrowCap: (0, tokens_1.assetAmountInEth)(reserveAsset.borrowCap.toString(), symbol),
124
+ totalSupplied: (0, tokens_1.assetAmountInEth)(totalSuppliedRaw.toString(), symbol),
125
+ totalDrawn: (0, tokens_1.assetAmountInEth)(totalDrawnRaw.toString(), symbol),
126
+ totalPremium: (0, tokens_1.assetAmountInEth)(totalPremiumRaw.toString(), symbol),
127
+ totalDebt: (0, tokens_1.assetAmountInEth)(totalDebtRaw.toString(), symbol),
128
+ supplyCap: (0, tokens_1.assetAmountInEth)(supplyCapRaw.toString(), symbol),
129
+ borrowCap: (0, tokens_1.assetAmountInEth)(borrowCapRaw.toString(), symbol),
88
130
  spokeActive: reserveAsset.spokeActive,
89
131
  spokeHalted: reserveAsset.spokeHalted,
90
132
  drawnRate: new decimal_js_1.default(hubAsset.drawnRate).div(new decimal_js_1.default(10).pow(27)).toString(),
@@ -0,0 +1,45 @@
1
+ import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
2
+ export interface AaveV4TokenizationSpokeData {
3
+ underlyingAsset: EthAddress;
4
+ assetId: string;
5
+ decimals: number;
6
+ spoke: EthAddress;
7
+ spokeActive: boolean;
8
+ spokeHalted: boolean;
9
+ spokeDepositCap: string;
10
+ spokeTotalAssets: string;
11
+ spokeTotalShares: string;
12
+ hub: EthAddress;
13
+ hubLiquidity: string;
14
+ hubDrawnRate: string;
15
+ convertToShares: string;
16
+ convertToAssets: string;
17
+ user: EthAddress;
18
+ userSuppliedAssets: string;
19
+ userSuppliedShares: string;
20
+ }
21
+ export declare const AAVE_V4_TOKENIZED_SPOKES: Record<string, EthAddress>;
22
+ export declare const AAVE_V4_TOKENIZED_SPOKE_ADDRESSES: Partial<Record<NetworkNumber, EthAddress[]>>;
23
+ export type AaveV4TokenizedHubKey = 'CORE' | 'PLUS' | 'PRIME';
24
+ export declare const aaveV4GetTokenizedHubKey: (hubNameOrKey?: string | null) => AaveV4TokenizedHubKey | null;
25
+ export declare const aaveV4GetTokenizedVaultKey: (symbol: string, hubNameOrKey?: string | null) => string | null;
26
+ export declare const aaveV4GetTokenizedVaultAddress: (network: NetworkNumber, symbol: string, hubNameOrKey?: string | null) => EthAddress | undefined;
27
+ /** Parsed tokenization spoke data with human-readable supplied amounts for display */
28
+ export interface AaveV4TokenizationSpokeDataParsed {
29
+ vaultAddress: EthAddress;
30
+ key: string | null;
31
+ symbol: string;
32
+ hubKey: string;
33
+ userSuppliedAssetsEth: string;
34
+ userSuppliedSharesEth: string;
35
+ userSuppliedAssets: string;
36
+ userSuppliedShares: string;
37
+ underlyingAsset: EthAddress;
38
+ spoke: EthAddress;
39
+ decimals: number;
40
+ }
41
+ /**
42
+ * Fetches tokenization vault data for the given user via getTokenizationSpokesData.
43
+ * Returns parsed data including userSuppliedAssets in human-readable form for each vault.
44
+ */
45
+ export declare function getAaveV4TokenizationSpokesData(provider: EthereumProvider, network: NetworkNumber, userAddress: EthAddress): Promise<AaveV4TokenizationSpokeDataParsed[]>;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.aaveV4GetTokenizedVaultAddress = exports.aaveV4GetTokenizedVaultKey = exports.aaveV4GetTokenizedHubKey = exports.AAVE_V4_TOKENIZED_SPOKE_ADDRESSES = exports.AAVE_V4_TOKENIZED_SPOKES = void 0;
13
+ exports.getAaveV4TokenizationSpokesData = getAaveV4TokenizationSpokesData;
14
+ const tokens_1 = require("@defisaver/tokens");
15
+ const contracts_1 = require("../contracts");
16
+ const viem_1 = require("../services/viem");
17
+ const utils_1 = require("../services/utils");
18
+ const common_1 = require("../types/common");
19
+ exports.AAVE_V4_TOKENIZED_SPOKES = {
20
+ AAVE_CORE: '0x08309234884cF7E015b07Bf22569017Aa035cdeF',
21
+ EURC_CORE: '0x73596dED4B2Eb0aC85e477b3c8dB56FC427E6774',
22
+ GHO_CORE: '0xf7E1f1b43922527e5054bD77E7f863Cf182b194D',
23
+ GHO_PRIME: '0xeF1cAd5c6a2C9cb83c952b4B96bbD35b3F61F18f',
24
+ LBTC_CORE: '0x8f4D423590F22833131e3493bf67A27213398f8e',
25
+ LINK_CORE: '0xBE1197750b423e30137E97d9183065d33E903BE6',
26
+ PT_USDe_PLUS: '0x8cA27Ab284F2aA2BcF33D9129e11c101aD2d16de',
27
+ PT_sUSDe_PLUS: '0xb8A464EC56071a98c854f30fE19CfeCc41FA6233',
28
+ PYUSD_CORE: '0x203FB463087005698d50768FcA837047f738632d',
29
+ RLUSD_CORE: '0xa9afdd0c54fb153CaE39cE86E49626B5e9d15513',
30
+ USDC_CORE: '0xa2e476f4cbB06C7bFA8Ad51bCcbF198cd32CfD35',
31
+ USDC_PLUS: '0x320Bec4fB7a25e64c003A007D0AeF7AB3D6C30d7',
32
+ USDC_PRIME: '0x0A0507F7A1129892b5cf74b8B4e911442c466b87',
33
+ USDG_CORE: '0x87c224256f09a014C1BC3e9FbB094C3AdD8fBaCC',
34
+ USDT_CORE: '0x3f12BD5999b9172550893FF52691c980676f9E73',
35
+ USDT_PLUS: '0xa4E74a78bED2d3ab8971e8AB26fb39f26DD8eEd9',
36
+ USDT_PRIME: '0xF565fB55bc96d65561887898bfeb25C1dE7e06d2',
37
+ USDe_PLUS: '0xA0d346ab2699B689AC67aba5174164A84206BB73',
38
+ WBTC_CORE: '0x837Ab872A665e0CF467d41cF56a054031b4A38bc',
39
+ WBTC_PRIME: '0xeae98b8a1798738182B2123DF1eB93d97BD29F34',
40
+ WETH_CORE: '0x3961a75099E986F59a1a31c6f945061641dFD2b2',
41
+ WETH_PRIME: '0xa411826a6ef5d289c0FAa7d5B45FE8aAB52257F6',
42
+ XAUt_CORE: '0x470341bC0e2B833C54D0120642713BdF762A494F',
43
+ cbBTC_CORE: '0xe8D5E595d5b6b5EFf84B7064765fd0e8DfD214C9',
44
+ cbBTC_PRIME: '0x0E986545150DcDDe46Ea9df355D0fD2af33bd75D',
45
+ frxUSD_CORE: '0x00C8A6a42947Cc4E7B6f27963Cab0143ccaaD2B5',
46
+ frxUSD_PLUS: '0xCAB288d37CAb5a9db7b503F086455276Dcde61F1',
47
+ rsETH_CORE: '0x6eEce89caE2163584bA7Ff9743861B9633c245E0',
48
+ sUSDe_PLUS: '0xdf47fc43c88B06edC47753b7d647ff18037D2F3d',
49
+ weETH_CORE: '0xB67F20bFF413C8E5d633B54BD28899c4c9e33ed0',
50
+ wstETH_CORE: '0x474602394d0B02F43AC3D7C8c5cFc0814b03fd40',
51
+ wstETH_PRIME: '0xAcCdAb49ECB9A801CfF62a92fc80D52339b33770',
52
+ };
53
+ exports.AAVE_V4_TOKENIZED_SPOKE_ADDRESSES = {
54
+ [common_1.NetworkNumber.Eth]: Object.values(exports.AAVE_V4_TOKENIZED_SPOKES),
55
+ };
56
+ const aaveV4GetTokenizedHubKey = (hubNameOrKey) => {
57
+ if (!hubNameOrKey)
58
+ return null;
59
+ const normalized = hubNameOrKey.trim().toUpperCase();
60
+ if (normalized === 'CORE' || normalized === 'CORE HUB')
61
+ return 'CORE';
62
+ if (normalized === 'PLUS' || normalized === 'PLUS HUB')
63
+ return 'PLUS';
64
+ if (normalized === 'PRIME' || normalized === 'PRIME HUB')
65
+ return 'PRIME';
66
+ if (normalized.includes('CORE'))
67
+ return 'CORE';
68
+ if (normalized.includes('PLUS'))
69
+ return 'PLUS';
70
+ if (normalized.includes('PRIME'))
71
+ return 'PRIME';
72
+ return null;
73
+ };
74
+ exports.aaveV4GetTokenizedHubKey = aaveV4GetTokenizedHubKey;
75
+ const aaveV4GetTokenizedVaultKey = (symbol, hubNameOrKey) => {
76
+ if (!symbol)
77
+ return null;
78
+ const hubKey = (0, exports.aaveV4GetTokenizedHubKey)(hubNameOrKey);
79
+ if (!hubKey)
80
+ return null;
81
+ const normalizedSymbol = symbol
82
+ .trim()
83
+ .replace(/-/g, '_');
84
+ return `${normalizedSymbol}_${hubKey}`;
85
+ };
86
+ exports.aaveV4GetTokenizedVaultKey = aaveV4GetTokenizedVaultKey;
87
+ const aaveV4GetTokenizedVaultAddress = (network, symbol, hubNameOrKey) => {
88
+ if (network !== common_1.NetworkNumber.Eth)
89
+ return undefined;
90
+ const key = (0, exports.aaveV4GetTokenizedVaultKey)(symbol, hubNameOrKey);
91
+ if (!key)
92
+ return undefined;
93
+ return exports.AAVE_V4_TOKENIZED_SPOKES[key];
94
+ };
95
+ exports.aaveV4GetTokenizedVaultAddress = aaveV4GetTokenizedVaultAddress;
96
+ const AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY = Object.entries(exports.AAVE_V4_TOKENIZED_SPOKES).reduce((acc, [k, v]) => {
97
+ acc[v.toLowerCase()] = k;
98
+ return acc;
99
+ }, {});
100
+ /**
101
+ * Fetches tokenization vault data for the given user via getTokenizationSpokesData.
102
+ * Returns parsed data including userSuppliedAssets in human-readable form for each vault.
103
+ */
104
+ function getAaveV4TokenizationSpokesData(provider, network, userAddress) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ var _a;
107
+ const spokes = (_a = exports.AAVE_V4_TOKENIZED_SPOKE_ADDRESSES[network]) !== null && _a !== void 0 ? _a : [];
108
+ if (spokes.length === 0)
109
+ return [];
110
+ const client = (0, viem_1.getViemProvider)(provider, network);
111
+ const viewContract = (0, contracts_1.AaveV4ViewContractViem)(client, network);
112
+ const raw = yield viewContract.read.getTokenizationSpokesData([spokes, userAddress]);
113
+ console.log(raw);
114
+ return raw.map((r, i) => {
115
+ var _a, _b, _c, _d, _e;
116
+ const vaultAddress = spokes[i];
117
+ const key = (_a = AAVE_V4_TOKENIZED_SPOKE_ADDRESS_TO_KEY[vaultAddress.toLowerCase()]) !== null && _a !== void 0 ? _a : null;
118
+ const symbol = (0, utils_1.wethToEth)((0, tokens_1.getAssetInfoByAddress)(r.underlyingAsset, network).symbol);
119
+ if (symbol === '?') { // unsupported asset
120
+ return null;
121
+ }
122
+ const hubKey = key ? (_b = key.split('_').pop()) !== null && _b !== void 0 ? _b : '' : '';
123
+ const decimals = Number((_c = r.decimals) !== null && _c !== void 0 ? _c : 18);
124
+ const userSuppliedAssetsRaw = (_d = r.userSuppliedAssets) !== null && _d !== void 0 ? _d : 0;
125
+ const userSuppliedSharesRaw = (_e = r.userSuppliedShares) !== null && _e !== void 0 ? _e : 0;
126
+ const userSuppliedAssetsEth = (0, tokens_1.assetAmountInEth)(userSuppliedAssetsRaw.toString(), symbol);
127
+ const userSuppliedSharesEth = (0, tokens_1.assetAmountInEth)(userSuppliedSharesRaw.toString(), symbol);
128
+ return {
129
+ vaultAddress,
130
+ key,
131
+ symbol,
132
+ hubKey,
133
+ userSuppliedAssetsEth,
134
+ userSuppliedSharesEth,
135
+ userSuppliedAssets: userSuppliedAssetsRaw.toString(),
136
+ userSuppliedShares: userSuppliedSharesRaw.toString(),
137
+ underlyingAsset: r.underlyingAsset,
138
+ spoke: r.spoke,
139
+ decimals,
140
+ };
141
+ }).filter(item => item != null);
142
+ });
143
+ }
@@ -92043,6 +92043,14 @@ export declare const AaveV4View: {
92043
92043
  readonly internalType: "uint256";
92044
92044
  readonly name: "totalDebt";
92045
92045
  readonly type: "uint256";
92046
+ }, {
92047
+ readonly internalType: "uint256";
92048
+ readonly name: "totalDrawnShares";
92049
+ readonly type: "uint256";
92050
+ }, {
92051
+ readonly internalType: "uint256";
92052
+ readonly name: "totalPremiumShares";
92053
+ readonly type: "uint256";
92046
92054
  }, {
92047
92055
  readonly internalType: "uint256";
92048
92056
  readonly name: "swept";
@@ -92130,6 +92138,14 @@ export declare const AaveV4View: {
92130
92138
  readonly internalType: "uint256";
92131
92139
  readonly name: "totalDebt";
92132
92140
  readonly type: "uint256";
92141
+ }, {
92142
+ readonly internalType: "uint256";
92143
+ readonly name: "totalDrawnShares";
92144
+ readonly type: "uint256";
92145
+ }, {
92146
+ readonly internalType: "uint256";
92147
+ readonly name: "totalPremiumShares";
92148
+ readonly type: "uint256";
92133
92149
  }, {
92134
92150
  readonly internalType: "uint256";
92135
92151
  readonly name: "swept";
@@ -93431,7 +93447,7 @@ export declare const AaveV4View: {
93431
93447
  }];
93432
93448
  readonly networks: {
93433
93449
  readonly "1": {
93434
- readonly address: "0x10B748Dc504C2515Bb6A9e23CB2F686090b6c584";
93450
+ readonly address: "0x34b6B5A3e8fB9135EbB47ACE4242b47E51064f5D";
93435
93451
  };
93436
93452
  };
93437
93453
  };