@gearbox-protocol/sdk 13.0.0-beta.2 → 13.0.0-beta.3
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/dist/cjs/sdk/utils/creditAccount.js +2 -0
- package/dist/cjs/sdk/utils/endpoints.js +71 -0
- package/dist/cjs/sdk/utils/index.js +2 -0
- package/dist/esm/sdk/utils/creditAccount.js +2 -0
- package/dist/esm/sdk/utils/endpoints.js +46 -0
- package/dist/esm/sdk/utils/index.js +1 -0
- package/dist/types/sdk/utils/creditAccount.d.ts +3 -2
- package/dist/types/sdk/utils/endpoints.d.ts +19 -0
- package/dist/types/sdk/utils/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -24,6 +24,8 @@ module.exports = __toCommonJS(creditAccount_exports);
|
|
|
24
24
|
var import__ = require("../index.js");
|
|
25
25
|
const MAX_UINT16 = 65535;
|
|
26
26
|
class CreditAccountDataUtils {
|
|
27
|
+
constructor() {
|
|
28
|
+
}
|
|
27
29
|
static sortBalances(balances, prices, tokens) {
|
|
28
30
|
return Object.entries(balances).sort(
|
|
29
31
|
([addr1, amount1], [addr2, amount2]) => {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var endpoints_exports = {};
|
|
20
|
+
__export(endpoints_exports, {
|
|
21
|
+
GearboxBackendApi: () => GearboxBackendApi,
|
|
22
|
+
URLApi: () => URLApi
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(endpoints_exports);
|
|
25
|
+
var import__ = require("../index.js");
|
|
26
|
+
const CHARTS_BACKEND_ADDRESS = "https://charts-server.fly.dev";
|
|
27
|
+
const STATIC_TOKEN = "https://static.gearbox.finance/tokens/";
|
|
28
|
+
class GearboxBackendApi {
|
|
29
|
+
constructor() {
|
|
30
|
+
}
|
|
31
|
+
static getChartsUrl = (url, chainId, options = { params: {} }, priceSource) => {
|
|
32
|
+
const domain = CHARTS_BACKEND_ADDRESS;
|
|
33
|
+
const priceSourceArr = priceSource ? [priceSource] : [];
|
|
34
|
+
const isMain = (0, import__.isSupportedNetwork)(chainId);
|
|
35
|
+
const relativePath = URLApi.getRelativeUrl(
|
|
36
|
+
url,
|
|
37
|
+
isMain ? {
|
|
38
|
+
...options,
|
|
39
|
+
params: { ...options.params, chainId }
|
|
40
|
+
} : options
|
|
41
|
+
);
|
|
42
|
+
return [domain, "api", ...priceSourceArr, relativePath].join("/");
|
|
43
|
+
};
|
|
44
|
+
static getStaticTokenUrl = () => STATIC_TOKEN;
|
|
45
|
+
static getRewardsMerkleUrl = (network, root, account) => {
|
|
46
|
+
const path = `${network}_${root.slice(2)}/${account.slice(2, 4)}`;
|
|
47
|
+
const url = `https://am.gearbox.finance/${path.toLowerCase()}.json`;
|
|
48
|
+
return url;
|
|
49
|
+
};
|
|
50
|
+
static getNFTMerkleUrl = (network, root) => {
|
|
51
|
+
const url = `https://dm.gearbox.finance/${network.toLowerCase()}_${root}.json`;
|
|
52
|
+
return url;
|
|
53
|
+
};
|
|
54
|
+
static apyAllRewards = () => URLApi.getRelativeUrl(
|
|
55
|
+
"https://state-cache.gearbox.foundation/apy-server/latest.json"
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
class URLApi {
|
|
59
|
+
constructor() {
|
|
60
|
+
}
|
|
61
|
+
static getRelativeUrl = (url, options) => {
|
|
62
|
+
const { params = {} } = options || {};
|
|
63
|
+
const paramsString = Object.entries(params).map(([key, value]) => `${key}=${value}`).join("&");
|
|
64
|
+
return [url, ...paramsString ? [paramsString] : []].join("?");
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
GearboxBackendApi,
|
|
70
|
+
URLApi
|
|
71
|
+
});
|
|
@@ -24,6 +24,7 @@ __reExport(utils_exports, require("./bytes32ToString.js"), module.exports);
|
|
|
24
24
|
__reExport(utils_exports, require("./childLogger.js"), module.exports);
|
|
25
25
|
__reExport(utils_exports, require("./createRawTx.js"), module.exports);
|
|
26
26
|
__reExport(utils_exports, require("./creditAccount.js"), module.exports);
|
|
27
|
+
__reExport(utils_exports, require("./endpoints.js"), module.exports);
|
|
27
28
|
__reExport(utils_exports, require("./etherscan.js"), module.exports);
|
|
28
29
|
__reExport(utils_exports, require("./filterDust.js"), module.exports);
|
|
29
30
|
__reExport(utils_exports, require("./formatter.js"), module.exports);
|
|
@@ -47,6 +48,7 @@ __reExport(utils_exports, require("./zod.js"), module.exports);
|
|
|
47
48
|
...require("./childLogger.js"),
|
|
48
49
|
...require("./createRawTx.js"),
|
|
49
50
|
...require("./creditAccount.js"),
|
|
51
|
+
...require("./endpoints.js"),
|
|
50
52
|
...require("./etherscan.js"),
|
|
51
53
|
...require("./filterDust.js"),
|
|
52
54
|
...require("./formatter.js"),
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isSupportedNetwork } from "../index.js";
|
|
2
|
+
const CHARTS_BACKEND_ADDRESS = "https://charts-server.fly.dev";
|
|
3
|
+
const STATIC_TOKEN = "https://static.gearbox.finance/tokens/";
|
|
4
|
+
class GearboxBackendApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
}
|
|
7
|
+
static getChartsUrl = (url, chainId, options = { params: {} }, priceSource) => {
|
|
8
|
+
const domain = CHARTS_BACKEND_ADDRESS;
|
|
9
|
+
const priceSourceArr = priceSource ? [priceSource] : [];
|
|
10
|
+
const isMain = isSupportedNetwork(chainId);
|
|
11
|
+
const relativePath = URLApi.getRelativeUrl(
|
|
12
|
+
url,
|
|
13
|
+
isMain ? {
|
|
14
|
+
...options,
|
|
15
|
+
params: { ...options.params, chainId }
|
|
16
|
+
} : options
|
|
17
|
+
);
|
|
18
|
+
return [domain, "api", ...priceSourceArr, relativePath].join("/");
|
|
19
|
+
};
|
|
20
|
+
static getStaticTokenUrl = () => STATIC_TOKEN;
|
|
21
|
+
static getRewardsMerkleUrl = (network, root, account) => {
|
|
22
|
+
const path = `${network}_${root.slice(2)}/${account.slice(2, 4)}`;
|
|
23
|
+
const url = `https://am.gearbox.finance/${path.toLowerCase()}.json`;
|
|
24
|
+
return url;
|
|
25
|
+
};
|
|
26
|
+
static getNFTMerkleUrl = (network, root) => {
|
|
27
|
+
const url = `https://dm.gearbox.finance/${network.toLowerCase()}_${root}.json`;
|
|
28
|
+
return url;
|
|
29
|
+
};
|
|
30
|
+
static apyAllRewards = () => URLApi.getRelativeUrl(
|
|
31
|
+
"https://state-cache.gearbox.foundation/apy-server/latest.json"
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
class URLApi {
|
|
35
|
+
constructor() {
|
|
36
|
+
}
|
|
37
|
+
static getRelativeUrl = (url, options) => {
|
|
38
|
+
const { params = {} } = options || {};
|
|
39
|
+
const paramsString = Object.entries(params).map(([key, value]) => `${key}=${value}`).join("&");
|
|
40
|
+
return [url, ...paramsString ? [paramsString] : []].join("?");
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
GearboxBackendApi,
|
|
45
|
+
URLApi
|
|
46
|
+
};
|
|
@@ -7,6 +7,7 @@ export * from "./bytes32ToString.js";
|
|
|
7
7
|
export * from "./childLogger.js";
|
|
8
8
|
export * from "./createRawTx.js";
|
|
9
9
|
export * from "./creditAccount.js";
|
|
10
|
+
export * from "./endpoints.js";
|
|
10
11
|
export * from "./etherscan.js";
|
|
11
12
|
export * from "./filterDust.js";
|
|
12
13
|
export * from "./formatter.js";
|
|
@@ -70,8 +70,8 @@ export interface CalcQuotaUpdateProps {
|
|
|
70
70
|
type: "recommendedQuota";
|
|
71
71
|
debt: bigint;
|
|
72
72
|
};
|
|
73
|
-
allowedToSpend: Record<Address,
|
|
74
|
-
allowedToObtain: Record<Address,
|
|
73
|
+
allowedToSpend: Record<Address, object>;
|
|
74
|
+
allowedToObtain: Record<Address, object>;
|
|
75
75
|
quotaReserve: bigint;
|
|
76
76
|
}
|
|
77
77
|
interface CalcQuotaUpdateReturnType {
|
|
@@ -101,6 +101,7 @@ export interface TimeToLiquidationProps {
|
|
|
101
101
|
healthFactor: number;
|
|
102
102
|
}
|
|
103
103
|
export declare class CreditAccountDataUtils {
|
|
104
|
+
private constructor();
|
|
104
105
|
static sortBalances(balances: Record<Address, bigint>, prices: Record<Address, bigint>, tokens: Record<Address, TokenDataSlice>): Array<[Address, bigint]>;
|
|
105
106
|
static sortAssets<T extends Asset>(balances: Array<T>, prices: Record<Address, bigint>, tokens: Record<Address, TokenDataSlice>): T[];
|
|
106
107
|
static assetComparator<T extends Asset>(t1: T, t2: T, prices1: Record<Address, bigint> | undefined, prices2: Record<Address, bigint> | undefined, tokens1: Record<Address, TokenDataSlice> | undefined, tokens2: Record<Address, TokenDataSlice> | undefined): 1 | 0 | -1;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { type NetworkType } from "../index.js";
|
|
3
|
+
type ChartsPriceSource = "chainlink" | "spot";
|
|
4
|
+
export declare class GearboxBackendApi {
|
|
5
|
+
private constructor();
|
|
6
|
+
static getChartsUrl: (url: string, chainId: number, options?: Options, priceSource?: ChartsPriceSource) => string;
|
|
7
|
+
static getStaticTokenUrl: () => string;
|
|
8
|
+
static getRewardsMerkleUrl: (network: NetworkType, root: Address, account: Address) => string;
|
|
9
|
+
static getNFTMerkleUrl: (network: NetworkType, root: Address) => string;
|
|
10
|
+
static apyAllRewards: () => string;
|
|
11
|
+
}
|
|
12
|
+
interface Options {
|
|
13
|
+
params?: Record<string, string | number>;
|
|
14
|
+
}
|
|
15
|
+
export declare class URLApi {
|
|
16
|
+
private constructor();
|
|
17
|
+
static getRelativeUrl: (url: string, options?: Options) => string;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -7,6 +7,7 @@ export * from "./bytes32ToString.js";
|
|
|
7
7
|
export * from "./childLogger.js";
|
|
8
8
|
export * from "./createRawTx.js";
|
|
9
9
|
export * from "./creditAccount.js";
|
|
10
|
+
export * from "./endpoints.js";
|
|
10
11
|
export * from "./etherscan.js";
|
|
11
12
|
export * from "./filterDust.js";
|
|
12
13
|
export * from "./formatter.js";
|