@defisaver/positions-sdk 2.1.13-dev-plasma-fluid5 → 2.1.13-dev-plasma-fluid7

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.
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getChainlinkAssetAddress = exports.getEthPriceForFluid = exports.getBTCPriceForFluid = exports.getWstETHPriceFluid = exports.parseWeETHPriceCalls = exports.parseWstETHPriceCalls = exports.getWeETHChainLinkPriceCalls = exports.getWstETHChainLinkPriceCalls = exports.getWeETHPrice = exports.getWstETHPrice = exports.getCompPrice = exports.getUSDCPrice = exports.getEthPrice = void 0;
15
+ exports.getChainlinkAssetAddress = exports.getEthPriceForFluid = exports.getBTCPriceForFluid = exports.getWstETHPriceFluid = exports.parseWeETHPriceCalls = exports.parseWstUSRPriceCalls = exports.parseSyrupUSDTPriceCalls = exports.parseWrsETHPriceCalls = exports.parseWstETHPriceCalls = exports.getWstUSRChainLinkPriceCalls = exports.getSyrupUSDTChainLinkPriceCalls = exports.getWsrETHChainLinkPriceCalls = exports.getWeETHChainLinkPriceCalls = exports.getWstETHChainLinkPriceCalls = exports.getWstUSRPrice = exports.getSyrupUSDTPrice = exports.getWsrETHPrice = exports.getWeETHPrice = exports.getWstETHPrice = exports.getCompPrice = exports.getUSDCPrice = exports.getEthPrice = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
18
  const contracts_1 = require("../contracts");
19
19
  const common_1 = require("../types/common");
20
20
  const utils_1 = require("./utils");
21
+ const constants_1 = require("../constants");
21
22
  const getEthPrice = (client) => __awaiter(void 0, void 0, void 0, function* () {
22
23
  const contract = (0, contracts_1.ETHPriceFeedContractViem)(client, common_1.NetworkNumber.Eth);
23
24
  const price = yield contract.read.latestAnswer();
@@ -62,6 +63,39 @@ const getWeETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...a
62
63
  return new decimal_js_1.default(ethPrice).mul(weETHRate).toString();
63
64
  });
64
65
  exports.getWeETHPrice = getWeETHPrice;
66
+ const getWsrETHPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
67
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
68
+ const [ethPriceWei, wrsETHRateWei] = yield Promise.all([
69
+ feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('WETH', network).address, constants_1.USD_QUOTE]),
70
+ feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('wrsETH', network).address, (0, tokens_1.getAssetInfo)('WETH', network).address]),
71
+ ]);
72
+ const ethPrice = new decimal_js_1.default(ethPriceWei[1].toString()).div(1e8);
73
+ const wrsETHRate = (0, utils_1.getEthAmountForDecimals)(wrsETHRateWei[1].toString(), 18);
74
+ return new decimal_js_1.default(ethPrice).mul(wrsETHRate).toString();
75
+ });
76
+ exports.getWsrETHPrice = getWsrETHPrice;
77
+ const getSyrupUSDTPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
78
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
79
+ const [usdtPriceWei, syrupUSDTRateWei] = yield Promise.all([
80
+ feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('USDT', network).address, constants_1.USD_QUOTE]),
81
+ feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('syrupUSDT', network).address, (0, tokens_1.getAssetInfo)('USDT', network).address]),
82
+ ]);
83
+ const usdtPrice = new decimal_js_1.default(usdtPriceWei[1].toString()).div(1e8);
84
+ const syrupUSDTPrice = (0, utils_1.getEthAmountForDecimals)(syrupUSDTRateWei[1].toString(), 18);
85
+ return new decimal_js_1.default(usdtPrice).mul(syrupUSDTPrice).toString();
86
+ });
87
+ exports.getSyrupUSDTPrice = getSyrupUSDTPrice;
88
+ const getWstUSRPrice = (client_1, ...args_1) => __awaiter(void 0, [client_1, ...args_1], void 0, function* (client, network = common_1.NetworkNumber.Eth) {
89
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
90
+ const [usrPriceWei, wstUSRRateWei] = yield Promise.all([
91
+ feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('USR', network).address, constants_1.USD_QUOTE]),
92
+ feedRegistryContract.read.latestRoundData([(0, tokens_1.getAssetInfo)('wstUSR', network).address, (0, tokens_1.getAssetInfo)('USR', network).address]),
93
+ ]);
94
+ const usrPrice = new decimal_js_1.default(usrPriceWei[1].toString()).div(1e8);
95
+ const wstUSRPrice = (0, utils_1.getEthAmountForDecimals)(wstUSRRateWei[1].toString(), 18);
96
+ return new decimal_js_1.default(usrPrice).mul(wstUSRPrice).toString();
97
+ });
98
+ exports.getWstUSRPrice = getWstUSRPrice;
65
99
  const getWstETHChainLinkPriceCalls = (client, network) => {
66
100
  const wstETHFeedContract = (0, contracts_1.WstETHPriceFeedContractViem)(client, network);
67
101
  const ethFeedContract = (0, contracts_1.ETHPriceFeedContractViem)(client, network);
@@ -114,12 +148,87 @@ const getWeETHChainLinkPriceCalls = (client, network) => {
114
148
  return calls;
115
149
  };
116
150
  exports.getWeETHChainLinkPriceCalls = getWeETHChainLinkPriceCalls;
151
+ const getWsrETHChainLinkPriceCalls = (client, network) => {
152
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
153
+ const calls = [
154
+ {
155
+ address: feedRegistryContract.address,
156
+ abi: feedRegistryContract.abi,
157
+ functionName: 'latestRoundData',
158
+ args: [(0, tokens_1.getAssetInfo)('WETH', network).address, constants_1.USD_QUOTE],
159
+ },
160
+ {
161
+ address: feedRegistryContract.address,
162
+ abi: feedRegistryContract.abi,
163
+ functionName: 'latestRoundData',
164
+ args: [(0, tokens_1.getAssetInfo)('wrsETH', network).address, (0, tokens_1.getAssetInfo)('WETH', network).address],
165
+ },
166
+ ];
167
+ return calls;
168
+ };
169
+ exports.getWsrETHChainLinkPriceCalls = getWsrETHChainLinkPriceCalls;
170
+ const getSyrupUSDTChainLinkPriceCalls = (client, network) => {
171
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
172
+ const calls = [
173
+ {
174
+ address: feedRegistryContract.address,
175
+ abi: feedRegistryContract.abi,
176
+ functionName: 'latestRoundData',
177
+ args: [(0, tokens_1.getAssetInfo)('USDT', network).address, constants_1.USD_QUOTE],
178
+ },
179
+ {
180
+ address: feedRegistryContract.address,
181
+ abi: feedRegistryContract.abi,
182
+ functionName: 'latestRoundData',
183
+ args: [(0, tokens_1.getAssetInfo)('syrupUSDT', network).address, (0, tokens_1.getAssetInfo)('USDT', network).address],
184
+ },
185
+ ];
186
+ return calls;
187
+ };
188
+ exports.getSyrupUSDTChainLinkPriceCalls = getSyrupUSDTChainLinkPriceCalls;
189
+ const getWstUSRChainLinkPriceCalls = (client, network) => {
190
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContractViem)(client, network);
191
+ const calls = [
192
+ {
193
+ address: feedRegistryContract.address,
194
+ abi: feedRegistryContract.abi,
195
+ functionName: 'latestRoundData',
196
+ args: [(0, tokens_1.getAssetInfo)('USR', network).address, constants_1.USD_QUOTE],
197
+ },
198
+ {
199
+ address: feedRegistryContract.address,
200
+ abi: feedRegistryContract.abi,
201
+ functionName: 'latestRoundData',
202
+ args: [(0, tokens_1.getAssetInfo)('wstUSR', network).address, (0, tokens_1.getAssetInfo)('USR', network).address],
203
+ },
204
+ ];
205
+ return calls;
206
+ };
207
+ exports.getWstUSRChainLinkPriceCalls = getWstUSRChainLinkPriceCalls;
117
208
  const parseWstETHPriceCalls = (_ethPrice, wstETHrateAnswer, decimals) => {
118
209
  const ethPrice = new decimal_js_1.default(_ethPrice).div(1e8);
119
210
  const wstETHRate = (0, utils_1.getEthAmountForDecimals)(wstETHrateAnswer, decimals);
120
211
  return { ethPrice, wstETHRate };
121
212
  };
122
213
  exports.parseWstETHPriceCalls = parseWstETHPriceCalls;
214
+ const parseWrsETHPriceCalls = (ethPriceAnswer, wrsETHrateAnswer) => {
215
+ const ethPrice = new decimal_js_1.default(ethPriceAnswer).div(1e8);
216
+ const wrsETHRate = new decimal_js_1.default(wrsETHrateAnswer).div(1e18);
217
+ return { ethPrice, wrsETHRate };
218
+ };
219
+ exports.parseWrsETHPriceCalls = parseWrsETHPriceCalls;
220
+ const parseSyrupUSDTPriceCalls = (usdtPriceAnswer, syrupUSDTRateAnswer) => {
221
+ const syrupUSDTRate = new decimal_js_1.default(syrupUSDTRateAnswer).div(1e8);
222
+ const USDTRate = new decimal_js_1.default(usdtPriceAnswer).div(1e18);
223
+ return { syrupUSDTRate, USDTRate };
224
+ };
225
+ exports.parseSyrupUSDTPriceCalls = parseSyrupUSDTPriceCalls;
226
+ const parseWstUSRPriceCalls = (usrPrice, _wstUSRRate) => {
227
+ const wstUSRRate = new decimal_js_1.default(_wstUSRRate).div(1e8);
228
+ const USRRate = new decimal_js_1.default(usrPrice).div(1e18);
229
+ return { wstUSRRate, USRRate };
230
+ };
231
+ exports.parseWstUSRPriceCalls = parseWstUSRPriceCalls;
123
232
  const parseWeETHPriceCalls = (_ethPrice, weETHrateAnswer, decimals) => {
124
233
  const ethPrice = new decimal_js_1.default(_ethPrice).div(1e8);
125
234
  const weETHRate = (0, utils_1.getEthAmountForDecimals)(weETHrateAnswer, decimals);
@@ -16,7 +16,7 @@ import { compareAddresses, DEFAULT_TIMEOUT, getEthAmountForDecimals, getNativeAs
16
16
  import { getFluidAggregatedData, mergeAssetData, mergeUsedAssets, parseDexBorrowData, parseDexSupplyData, } from '../helpers/fluidHelpers';
17
17
  import { getFluidMarketInfoById, getFluidVersionsDataForNetwork, getFTokenAddress } from '../markets';
18
18
  import { USD_QUOTE, ZERO_ADDRESS } from '../constants';
19
- import { getChainlinkAssetAddress, getWeETHChainLinkPriceCalls, getWeETHPrice, getWstETHChainLinkPriceCalls, getWstETHPrice, getWstETHPriceFluid, parseWeETHPriceCalls, parseWstETHPriceCalls, } from '../services/priceService';
19
+ import { getChainlinkAssetAddress, getSyrupUSDTChainLinkPriceCalls, getSyrupUSDTPrice, getWeETHChainLinkPriceCalls, getWeETHPrice, getWsrETHChainLinkPriceCalls, getWsrETHPrice, getWstETHChainLinkPriceCalls, getWstETHPrice, getWstETHPriceFluid, getWstUSRChainLinkPriceCalls, getWstUSRPrice, parseSyrupUSDTPriceCalls, parseWeETHPriceCalls, parseWrsETHPriceCalls, parseWstETHPriceCalls, parseWstUSRPriceCalls, } from '../services/priceService';
20
20
  import { getStakingApy, STAKING_ASSETS } from '../staking';
21
21
  import { getViemProvider } from '../services/viem';
22
22
  export const EMPTY_USED_ASSET = {
@@ -68,6 +68,12 @@ const getChainLinkPricesForTokens = (tokens, network, client) => __awaiter(void
68
68
  return getWstETHChainLinkPriceCalls(client, network);
69
69
  if (assetInfo.symbol === 'weETH' && network !== NetworkNumber.Plasma)
70
70
  return getWeETHChainLinkPriceCalls(client, network);
71
+ if (assetInfo.symbol === 'wrsETH' && network === NetworkNumber.Plasma)
72
+ return getWsrETHChainLinkPriceCalls(client, network);
73
+ if (assetInfo.symbol === 'syrupUSDT')
74
+ return getSyrupUSDTChainLinkPriceCalls(client, network);
75
+ if (assetInfo.symbol === 'wstUSR')
76
+ return getWstUSRChainLinkPriceCalls(client, network);
71
77
  if (isMainnet) {
72
78
  const feedRegistryContract = FeedRegistryContractViem(client, NetworkNumber.Eth);
73
79
  return ({
@@ -106,6 +112,36 @@ const getChainLinkPricesForTokens = (tokens, network, client) => __awaiter(void
106
112
  acc[token] = new Dec(ethPrice).mul(wstETHRate).toString();
107
113
  break;
108
114
  }
115
+ case 'wrsETH': {
116
+ const { ethPrice, wrsETHRate, } = parseWrsETHPriceCalls(
117
+ // @ts-ignore
118
+ results[i + offset].result[1].toString(),
119
+ // @ts-ignore
120
+ results[i + offset + 1].result[1].toString());
121
+ offset += 1;
122
+ acc[token] = new Dec(ethPrice).mul(wrsETHRate).toString();
123
+ break;
124
+ }
125
+ case 'syrupUSDT': {
126
+ const { syrupUSDTRate, USDTRate, } = parseSyrupUSDTPriceCalls(
127
+ // @ts-ignore
128
+ results[i + offset].result[1].toString(),
129
+ // @ts-ignore
130
+ results[i + offset + 1].result[1].toString());
131
+ offset += 1;
132
+ acc[token] = new Dec(syrupUSDTRate).mul(USDTRate).toString();
133
+ break;
134
+ }
135
+ case 'wstUSR': {
136
+ const { wstUSRRate, USRRate, } = parseWstUSRPriceCalls(
137
+ // @ts-ignore
138
+ results[i + offset].result[1].toString(),
139
+ // @ts-ignore
140
+ results[i + offset + 1].result[1].toString());
141
+ offset += 1;
142
+ acc[token] = new Dec(wstUSRRate).mul(USRRate).toString();
143
+ break;
144
+ }
109
145
  // TODO: These addresses do not have chainlink feeds, so we need to handle them separately, this is hotfix
110
146
  case 'ezETH': {
111
147
  acc[token] = new Dec(ethPriceChainlink).mul(1.049).toString();
@@ -1206,6 +1242,15 @@ const getTokenPricePortfolio = (token, provider, network) => __awaiter(void 0, v
1206
1242
  if (token === 'weETH' && network !== NetworkNumber.Plasma) {
1207
1243
  return getWeETHPrice(provider, network);
1208
1244
  }
1245
+ if (token === 'wrsETH') {
1246
+ return getWsrETHPrice(provider, network);
1247
+ }
1248
+ if (token === 'syrupUSDT') {
1249
+ return getSyrupUSDTPrice(provider, network);
1250
+ }
1251
+ if (token === 'wstUSR') {
1252
+ return getWstUSRPrice(provider, network);
1253
+ }
1209
1254
  const isMainnet = isMainnetNetwork(network);
1210
1255
  const chainLinkFeedAddress = getChainlinkAssetAddress(token, network);
1211
1256
  if (isMainnet) {