@defisaver/positions-sdk 2.1.159 → 2.1.160

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.
@@ -10,3 +10,4 @@ export declare const ZERO_BYTES32 = "0x00000000000000000000000000000000000000000
10
10
  export declare const WAD = 1000000000000000000;
11
11
  export declare const USD_QUOTE = "0x0000000000000000000000000000000000000348";
12
12
  export declare const borrowOperations: string[];
13
+ export declare const MORPHO_API_URL = "https://fe.defisaver.com/api/morpho/graphql";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.borrowOperations = exports.USD_QUOTE = exports.WAD = exports.ZERO_BYTES32 = exports.ZERO_ADDRESS = exports.BLOCKS_IN_A_YEAR = exports.AVG_BLOCK_TIME = exports.SECONDS_PER_WEEK = exports.SECONDS_PER_YEAR = exports.SECONDS_PER_DAY = exports.SECONDS_PER_HOUR = exports.SECONDS_PER_MINUTE = void 0;
3
+ exports.MORPHO_API_URL = exports.borrowOperations = exports.USD_QUOTE = exports.WAD = exports.ZERO_BYTES32 = exports.ZERO_ADDRESS = exports.BLOCKS_IN_A_YEAR = exports.AVG_BLOCK_TIME = exports.SECONDS_PER_WEEK = exports.SECONDS_PER_YEAR = exports.SECONDS_PER_DAY = exports.SECONDS_PER_HOUR = exports.SECONDS_PER_MINUTE = void 0;
4
4
  exports.SECONDS_PER_MINUTE = 60;
5
5
  exports.SECONDS_PER_HOUR = 60 * exports.SECONDS_PER_MINUTE;
6
6
  exports.SECONDS_PER_DAY = 24 * exports.SECONDS_PER_HOUR;
@@ -13,3 +13,6 @@ exports.ZERO_BYTES32 = '0x000000000000000000000000000000000000000000000000000000
13
13
  exports.WAD = 1e18;
14
14
  exports.USD_QUOTE = '0x0000000000000000000000000000000000000348';
15
15
  exports.borrowOperations = ['borrow', 'payback'];
16
+ // Proxies Morpho's GraphQL API through the DFS backend, which attaches the private API key
17
+ // for better rate limits (DEV-13673)
18
+ exports.MORPHO_API_URL = 'https://fe.defisaver.com/api/morpho/graphql';
@@ -139,7 +139,6 @@ const getApyAfterValuesEstimation = (selectedMarket, actions, provider, network)
139
139
  return { borrowRate, supplyRate };
140
140
  });
141
141
  exports.getApyAfterValuesEstimation = getApyAfterValuesEstimation;
142
- const API_URL = 'https://api.morpho.org/graphql';
143
142
  // Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
144
143
  const ACRM_TARGET_UTILIZATION = '900000000000000000';
145
144
  const MARKET_QUERY = `
@@ -216,7 +215,7 @@ const REWARDS_QUERY = `
216
215
  const getReallocatableLiquidity = (marketId_1, ...args_1) => __awaiter(void 0, [marketId_1, ...args_1], void 0, function* (marketId, network = common_1.NetworkNumber.Eth) {
217
216
  var _a;
218
217
  try {
219
- const response = yield fetch(API_URL, {
218
+ const response = yield fetch(constants_1.MORPHO_API_URL, {
220
219
  method: 'POST',
221
220
  headers: { 'Content-Type': 'application/json' },
222
221
  body: JSON.stringify({
@@ -280,7 +279,7 @@ const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...args_1) =>
280
279
  var _a, _b, _c;
281
280
  try {
282
281
  const { marketId, loanToken } = market;
283
- const response = yield fetch(API_URL, {
282
+ const response = yield fetch(constants_1.MORPHO_API_URL, {
284
283
  method: 'POST',
285
284
  headers: { 'Content-Type': 'application/json' },
286
285
  body: JSON.stringify({
@@ -354,7 +353,7 @@ const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...args_1) =>
354
353
  exports.getReallocation = getReallocation;
355
354
  const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0, [marketId_1, ...args_1], void 0, function* (marketId, network = common_1.NetworkNumber.Eth) {
356
355
  var _a;
357
- const response = yield fetch(API_URL, {
356
+ const response = yield fetch(constants_1.MORPHO_API_URL, {
358
357
  method: 'POST',
359
358
  headers: { 'Content-Type': 'application/json' },
360
359
  body: JSON.stringify({
@@ -55,7 +55,7 @@ const morphoVaultsOptions = __importStar(require("./options"));
55
55
  exports.morphoVaultsOptions = morphoVaultsOptions;
56
56
  const viem_1 = require("../../services/viem");
57
57
  const contracts_1 = require("../../contracts");
58
- const MORPHO_BLUE_API = 'https://api.morpho.org/graphql';
58
+ const constants_1 = require("../../constants");
59
59
  // Morpho API caps list page size at 100 items
60
60
  const MORPHO_API_PAGE_SIZE = 100;
61
61
  const vaultsLiquidityQuery = `
@@ -80,7 +80,7 @@ const fetchMorphoVaultsLiquidity = (network, vaults) => __awaiter(void 0, void 0
80
80
  chunks.push(vaults.slice(i, i + MORPHO_API_PAGE_SIZE));
81
81
  const liquidityByAddress = {};
82
82
  yield Promise.all(chunks.map((chunk) => __awaiter(void 0, void 0, void 0, function* () {
83
- const data = yield (0, graphql_request_1.request)(MORPHO_BLUE_API, vaultsLiquidityQuery, {
83
+ const data = yield (0, graphql_request_1.request)(constants_1.MORPHO_API_URL, vaultsLiquidityQuery, {
84
84
  addresses: chunk.map((vault) => vault.address),
85
85
  chainIds: [network],
86
86
  // the BigInt scalar serializes as a JSON number when it fits in Number.MAX_SAFE_INTEGER, a string otherwise
@@ -10,3 +10,4 @@ export declare const ZERO_BYTES32 = "0x00000000000000000000000000000000000000000
10
10
  export declare const WAD = 1000000000000000000;
11
11
  export declare const USD_QUOTE = "0x0000000000000000000000000000000000000348";
12
12
  export declare const borrowOperations: string[];
13
+ export declare const MORPHO_API_URL = "https://fe.defisaver.com/api/morpho/graphql";
@@ -10,3 +10,6 @@ export const ZERO_BYTES32 = '0x0000000000000000000000000000000000000000000000000
10
10
  export const WAD = 1e18;
11
11
  export const USD_QUOTE = '0x0000000000000000000000000000000000000348';
12
12
  export const borrowOperations = ['borrow', 'payback'];
13
+ // Proxies Morpho's GraphQL API through the DFS backend, which attaches the private API key
14
+ // for better rate limits (DEV-13673)
15
+ export const MORPHO_API_URL = 'https://fe.defisaver.com/api/morpho/graphql';
@@ -12,7 +12,7 @@ import { assetAmountInWei, getAssetInfo, getAssetInfoByAddress } from '@defisave
12
12
  import { aprToApy, calcLeverageLiqPrice, getAssetsTotal, getExposure, isLeveragedPos, } from '../../moneymarket';
13
13
  import { calculateNetApy } from '../../staking';
14
14
  import { LeverageType, NetworkNumber, } from '../../types/common';
15
- import { borrowOperations, SECONDS_PER_YEAR, WAD } from '../../constants';
15
+ import { borrowOperations, MORPHO_API_URL, SECONDS_PER_YEAR, WAD, } from '../../constants';
16
16
  import { MorphoBlueViewContractViem } from '../../contracts';
17
17
  import { compareAddresses, LONGER_TIMEOUT } from '../../services/utils';
18
18
  import { getViemProvider } from '../../services/viem';
@@ -129,7 +129,6 @@ export const getApyAfterValuesEstimation = (selectedMarket, actions, provider, n
129
129
  const supplyRate = getSupplyRate(data[1].totalSupplyAssets.toString(), data[1].totalBorrowAssets.toString(), data[0].toString(), data[1].fee.toString());
130
130
  return { borrowRate, supplyRate };
131
131
  });
132
- const API_URL = 'https://api.morpho.org/graphql';
133
132
  // Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
134
133
  const ACRM_TARGET_UTILIZATION = '900000000000000000';
135
134
  const MARKET_QUERY = `
@@ -206,7 +205,7 @@ const REWARDS_QUERY = `
206
205
  export const getReallocatableLiquidity = (marketId_1, ...args_1) => __awaiter(void 0, [marketId_1, ...args_1], void 0, function* (marketId, network = NetworkNumber.Eth) {
207
206
  var _a;
208
207
  try {
209
- const response = yield fetch(API_URL, {
208
+ const response = yield fetch(MORPHO_API_URL, {
210
209
  method: 'POST',
211
210
  headers: { 'Content-Type': 'application/json' },
212
211
  body: JSON.stringify({
@@ -268,7 +267,7 @@ export const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...arg
268
267
  var _a, _b, _c;
269
268
  try {
270
269
  const { marketId, loanToken } = market;
271
- const response = yield fetch(API_URL, {
270
+ const response = yield fetch(MORPHO_API_URL, {
272
271
  method: 'POST',
273
272
  headers: { 'Content-Type': 'application/json' },
274
273
  body: JSON.stringify({
@@ -341,7 +340,7 @@ export const getReallocation = (market_1, assetsData_1, amountToBorrow_1, ...arg
341
340
  });
342
341
  export const getRewardsForMarket = (marketId_1, ...args_1) => __awaiter(void 0, [marketId_1, ...args_1], void 0, function* (marketId, network = NetworkNumber.Eth) {
343
342
  var _a;
344
- const response = yield fetch(API_URL, {
343
+ const response = yield fetch(MORPHO_API_URL, {
345
344
  method: 'POST',
346
345
  headers: { 'Content-Type': 'application/json' },
347
346
  body: JSON.stringify({
@@ -13,8 +13,8 @@ import { assetAmountInEth } from '@defisaver/tokens';
13
13
  import * as morphoVaultsOptions from './options';
14
14
  import { getViemProvider } from '../../services/viem';
15
15
  import { getMorphoVaultContractViem } from '../../contracts';
16
+ import { MORPHO_API_URL } from '../../constants';
16
17
  export { morphoVaultsOptions, };
17
- const MORPHO_BLUE_API = 'https://api.morpho.org/graphql';
18
18
  // Morpho API caps list page size at 100 items
19
19
  const MORPHO_API_PAGE_SIZE = 100;
20
20
  const vaultsLiquidityQuery = `
@@ -39,7 +39,7 @@ export const fetchMorphoVaultsLiquidity = (network, vaults) => __awaiter(void 0,
39
39
  chunks.push(vaults.slice(i, i + MORPHO_API_PAGE_SIZE));
40
40
  const liquidityByAddress = {};
41
41
  yield Promise.all(chunks.map((chunk) => __awaiter(void 0, void 0, void 0, function* () {
42
- const data = yield graphqlRequest(MORPHO_BLUE_API, vaultsLiquidityQuery, {
42
+ const data = yield graphqlRequest(MORPHO_API_URL, vaultsLiquidityQuery, {
43
43
  addresses: chunk.map((vault) => vault.address),
44
44
  chainIds: [network],
45
45
  // the BigInt scalar serializes as a JSON number when it fits in Number.MAX_SAFE_INTEGER, a string otherwise
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "2.1.159",
3
+ "version": "2.1.160",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -9,4 +9,8 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
9
9
  export const ZERO_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
10
10
  export const WAD = 1e18;
11
11
  export const USD_QUOTE = '0x0000000000000000000000000000000000000348';
12
- export const borrowOperations = ['borrow', 'payback'];
12
+ export const borrowOperations = ['borrow', 'payback'];
13
+
14
+ // Proxies Morpho's GraphQL API through the DFS backend, which attaches the private API key
15
+ // for better rate limits (DEV-13673)
16
+ export const MORPHO_API_URL = 'https://fe.defisaver.com/api/morpho/graphql';
@@ -12,7 +12,9 @@ import {
12
12
  MorphoBluePublicAllocatorItem,
13
13
  MorphoBlueRealloactionMarketData,
14
14
  } from '../../types';
15
- import { borrowOperations, SECONDS_PER_YEAR, WAD } from '../../constants';
15
+ import {
16
+ borrowOperations, MORPHO_API_URL, SECONDS_PER_YEAR, WAD,
17
+ } from '../../constants';
16
18
  import { MorphoBlueViewContractViem } from '../../contracts';
17
19
  import { compareAddresses, LONGER_TIMEOUT, wethToEth } from '../../services/utils';
18
20
  import { getViemProvider } from '../../services/viem';
@@ -147,7 +149,6 @@ export const getApyAfterValuesEstimation = async (selectedMarket: MorphoBlueMark
147
149
  return { borrowRate, supplyRate };
148
150
  };
149
151
 
150
- const API_URL = 'https://api.morpho.org/graphql';
151
152
  // Morpho Blue ACRM (Adaptive Curve IRM) always targets 90% utilization — protocol constant
152
153
  const ACRM_TARGET_UTILIZATION = '900000000000000000';
153
154
 
@@ -226,7 +227,7 @@ const REWARDS_QUERY = `
226
227
  */
227
228
  export const getReallocatableLiquidity = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth): Promise<{ reallocatableLiquidity: string, targetBorrowUtilization: string }> => {
228
229
  try {
229
- const response = await fetch(API_URL, {
230
+ const response = await fetch(MORPHO_API_URL, {
230
231
  method: 'POST',
231
232
  headers: { 'Content-Type': 'application/json' },
232
233
  body: JSON.stringify({
@@ -291,7 +292,7 @@ export const getLiquidityToAllocate = (amountToBorrow: string, totalBorrow: stri
291
292
  export const getReallocation = async (market: MorphoBlueMarketData, assetsData: MorphoBlueAssetsData, amountToBorrow: string, network: NetworkNumber = NetworkNumber.Eth): Promise<{ vaults: string[], withdrawals: (string | string[])[][][] }> => {
292
293
  try {
293
294
  const { marketId, loanToken } = market;
294
- const response = await fetch(API_URL, {
295
+ const response = await fetch(MORPHO_API_URL, {
295
296
  method: 'POST',
296
297
  headers: { 'Content-Type': 'application/json' },
297
298
  body: JSON.stringify({
@@ -382,7 +383,7 @@ export const getReallocation = async (market: MorphoBlueMarketData, assetsData:
382
383
  };
383
384
 
384
385
  export const getRewardsForMarket = async (marketId: string, network: NetworkNumber = NetworkNumber.Eth) => {
385
- const response = await fetch(API_URL, {
386
+ const response = await fetch(MORPHO_API_URL, {
386
387
  method: 'POST',
387
388
  headers: { 'Content-Type': 'application/json' },
388
389
  body: JSON.stringify({
@@ -8,13 +8,12 @@ import {
8
8
  } from '../../types';
9
9
  import { getViemProvider } from '../../services/viem';
10
10
  import { getMorphoVaultContractViem } from '../../contracts';
11
+ import { MORPHO_API_URL } from '../../constants';
11
12
 
12
13
  export {
13
14
  morphoVaultsOptions,
14
15
  };
15
16
 
16
- const MORPHO_BLUE_API = 'https://api.morpho.org/graphql';
17
-
18
17
  // Morpho API caps list page size at 100 items
19
18
  const MORPHO_API_PAGE_SIZE = 100;
20
19
 
@@ -41,7 +40,7 @@ export const fetchMorphoVaultsLiquidity = async (network: NetworkNumber, vaults:
41
40
 
42
41
  const liquidityByAddress: Record<string, string> = {};
43
42
  await Promise.all(chunks.map(async (chunk) => {
44
- const data = await graphqlRequest(MORPHO_BLUE_API, vaultsLiquidityQuery, {
43
+ const data = await graphqlRequest(MORPHO_API_URL, vaultsLiquidityQuery, {
45
44
  addresses: chunk.map((vault) => vault.address),
46
45
  chainIds: [network],
47
46
  // the BigInt scalar serializes as a JSON number when it fits in Number.MAX_SAFE_INTEGER, a string otherwise