@gearbox-protocol/sdk 3.0.0-next.101 → 3.0.0-next.103
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/lib/apy/index.d.ts +1 -0
- package/lib/apy/index.js +1 -0
- package/lib/apy/maker.d.ts +39 -0
- package/lib/apy/maker.js +65 -0
- package/lib/core/strategy.d.ts +5 -7
- package/lib/core/strategy.js +4 -6
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +2 -2
- package/package.json +1 -1
package/lib/apy/index.d.ts
CHANGED
package/lib/apy/index.js
CHANGED
|
@@ -26,4 +26,5 @@ exports.isTokenWithAPY = isTokenWithAPY;
|
|
|
26
26
|
__exportStar(require("./convexAPY"), exports);
|
|
27
27
|
__exportStar(require("./curveAPY"), exports);
|
|
28
28
|
__exportStar(require("./lidoAPY"), exports);
|
|
29
|
+
__exportStar(require("./maker"), exports);
|
|
29
30
|
__exportStar(require("./yearnAPY"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ERC4626Params, ERC4626VaultContract, NetworkType } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
import { BigNumber } from "ethers";
|
|
3
|
+
import { Interface } from "ethers/lib/utils";
|
|
4
|
+
export declare const MAKER_VAULT_ABI: {
|
|
5
|
+
inputs: never[];
|
|
6
|
+
name: string;
|
|
7
|
+
outputs: {
|
|
8
|
+
internalType: string;
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}[];
|
|
12
|
+
stateMutability: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const MAKER_VAULT_INTERFACE: Interface;
|
|
16
|
+
export type MakerPoolContract = Extract<ERC4626VaultContract, "MAKER_DSR_VAULT">;
|
|
17
|
+
interface PoolInfo {
|
|
18
|
+
pool: ERC4626Params;
|
|
19
|
+
poolAddress: string;
|
|
20
|
+
}
|
|
21
|
+
export interface GetMakerAPYBulkCallsProps {
|
|
22
|
+
pools: Array<MakerPoolContract>;
|
|
23
|
+
networkType: NetworkType;
|
|
24
|
+
}
|
|
25
|
+
export declare function getMakerAPYBulkCalls({ pools, networkType, }: GetMakerAPYBulkCallsProps): {
|
|
26
|
+
poolsInfo: PoolInfo[];
|
|
27
|
+
calls: {
|
|
28
|
+
address: string;
|
|
29
|
+
interface: Interface;
|
|
30
|
+
method: string;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
type GetMakerAPYBulkCallsReturns = ReturnType<typeof getMakerAPYBulkCalls>;
|
|
34
|
+
export interface GetMakerAPYBulkProps {
|
|
35
|
+
generated: GetMakerAPYBulkCallsReturns;
|
|
36
|
+
response: Array<BigNumber>;
|
|
37
|
+
}
|
|
38
|
+
export declare function getMakerAPYBulk(props: GetMakerAPYBulkProps): bigint[];
|
|
39
|
+
export {};
|
package/lib/apy/maker.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMakerAPYBulk = exports.getMakerAPYBulkCalls = exports.MAKER_VAULT_INTERFACE = exports.MAKER_VAULT_ABI = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const utils_1 = require("ethers/lib/utils");
|
|
6
|
+
const formatter_1 = require("../utils/formatter");
|
|
7
|
+
exports.MAKER_VAULT_ABI = [
|
|
8
|
+
{
|
|
9
|
+
inputs: [],
|
|
10
|
+
name: "dsr",
|
|
11
|
+
outputs: [
|
|
12
|
+
{
|
|
13
|
+
internalType: "uint256",
|
|
14
|
+
name: "",
|
|
15
|
+
type: "uint256",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
stateMutability: "view",
|
|
19
|
+
type: "function",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
exports.MAKER_VAULT_INTERFACE = new utils_1.Interface(exports.MAKER_VAULT_ABI);
|
|
23
|
+
const MAKER_BY_NETWORK = {
|
|
24
|
+
Mainnet: {
|
|
25
|
+
MAKER_DSR_VAULT: "0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7",
|
|
26
|
+
},
|
|
27
|
+
Arbitrum: {
|
|
28
|
+
MAKER_DSR_VAULT: "",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
function getMakerAPYBulkCalls({ pools, networkType, }) {
|
|
32
|
+
const poolsInfo = pools.map((pool) => {
|
|
33
|
+
const poolParams = sdk_gov_1.contractParams[pool];
|
|
34
|
+
const basePoolAddress = MAKER_BY_NETWORK[networkType][pool];
|
|
35
|
+
return {
|
|
36
|
+
pool: poolParams,
|
|
37
|
+
poolAddress: basePoolAddress,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
const calls = poolsInfo.map(info => ({
|
|
41
|
+
address: info.poolAddress,
|
|
42
|
+
interface: exports.MAKER_VAULT_INTERFACE,
|
|
43
|
+
method: "dsr()",
|
|
44
|
+
}));
|
|
45
|
+
return { poolsInfo, calls };
|
|
46
|
+
}
|
|
47
|
+
exports.getMakerAPYBulkCalls = getMakerAPYBulkCalls;
|
|
48
|
+
function getMakerAPYBulk(props) {
|
|
49
|
+
const { poolsInfo } = props.generated;
|
|
50
|
+
const apyList = props.response.map((baseApy, i) => {
|
|
51
|
+
const apy = calculateMakerAPY({
|
|
52
|
+
baseApy: (0, sdk_gov_1.toBigInt)(baseApy),
|
|
53
|
+
poolInfo: poolsInfo[i],
|
|
54
|
+
});
|
|
55
|
+
return apy;
|
|
56
|
+
});
|
|
57
|
+
return apyList;
|
|
58
|
+
}
|
|
59
|
+
exports.getMakerAPYBulk = getMakerAPYBulk;
|
|
60
|
+
const POW = 3600 * 24 * 365;
|
|
61
|
+
function calculateMakerAPY(props) {
|
|
62
|
+
const rateFloat = Number((0, formatter_1.toSignificant)(props.baseApy, 27, 27));
|
|
63
|
+
const rate = Math.max(0, rateFloat ** POW - 1);
|
|
64
|
+
return (0, formatter_1.toBN)(rate.toString(), sdk_gov_1.WAD_DECIMALS_POW);
|
|
65
|
+
}
|
package/lib/core/strategy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Protocols } from "@gearbox-protocol/sdk-gov";
|
|
1
|
+
import { Protocols, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { CreditManagerData } from "./creditManager";
|
|
3
3
|
export interface StrategyPayload {
|
|
4
4
|
apy?: number;
|
|
@@ -6,9 +6,8 @@ export interface StrategyPayload {
|
|
|
6
6
|
lpToken: string;
|
|
7
7
|
protocol: Protocols;
|
|
8
8
|
creditManagers: Array<string>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
leveragableCollateral: Array<string>;
|
|
9
|
+
collateralTokens: Array<SupportedToken>;
|
|
10
|
+
liquidationTokens: Array<SupportedToken>;
|
|
12
11
|
}
|
|
13
12
|
interface CalculateMaxAPYProps {
|
|
14
13
|
apy: number;
|
|
@@ -21,9 +20,8 @@ export declare class Strategy {
|
|
|
21
20
|
readonly name: string;
|
|
22
21
|
readonly lpToken: string;
|
|
23
22
|
readonly protocol: Protocols;
|
|
24
|
-
readonly
|
|
25
|
-
readonly
|
|
26
|
-
readonly leveragableCollateral: Array<string>;
|
|
23
|
+
readonly collateralTokens: Array<SupportedToken>;
|
|
24
|
+
readonly liquidationTokens: Array<SupportedToken>;
|
|
27
25
|
readonly creditManagers: Array<string>;
|
|
28
26
|
constructor(payload: StrategyPayload);
|
|
29
27
|
static maxLeverage(lpToken: string, cms: Array<PartialCM>): number;
|
package/lib/core/strategy.js
CHANGED
|
@@ -7,9 +7,8 @@ class Strategy {
|
|
|
7
7
|
name;
|
|
8
8
|
lpToken;
|
|
9
9
|
protocol;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
leveragableCollateral;
|
|
10
|
+
collateralTokens;
|
|
11
|
+
liquidationTokens;
|
|
13
12
|
creditManagers;
|
|
14
13
|
constructor(payload) {
|
|
15
14
|
this.apy = payload.apy;
|
|
@@ -17,9 +16,8 @@ class Strategy {
|
|
|
17
16
|
this.lpToken = payload.lpToken.toLowerCase();
|
|
18
17
|
this.protocol = payload.protocol;
|
|
19
18
|
this.creditManagers = payload.creditManagers.map(addr => addr.toLowerCase());
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.leveragableCollateral = payload.leveragableCollateral.map(addr => addr.toLowerCase());
|
|
19
|
+
this.collateralTokens = payload.collateralTokens;
|
|
20
|
+
this.liquidationTokens = payload.liquidationTokens;
|
|
23
21
|
}
|
|
24
22
|
static maxLeverage(lpToken, cms) {
|
|
25
23
|
const [maxThreshold] = Strategy.maxLeverageThreshold(lpToken, cms);
|
package/lib/utils/formatter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
2
|
export declare function rayToNumber(num: BigNumberish): number;
|
|
3
3
|
export declare function formatRAY(num?: bigint): string;
|
|
4
|
-
export declare function toSignificant(num: bigint, decimals: number): string;
|
|
4
|
+
export declare function toSignificant(num: bigint, decimals: number, precision?: number): string;
|
|
5
5
|
export declare function toBN(num: string, decimals: number): bigint;
|
|
6
6
|
export declare function shortAddress(address?: string): string;
|
|
7
7
|
export declare function shortHash(address?: string): string;
|
package/lib/utils/formatter.js
CHANGED
|
@@ -12,12 +12,12 @@ function formatRAY(num = 0n) {
|
|
|
12
12
|
return toSignificant(num, 27);
|
|
13
13
|
}
|
|
14
14
|
exports.formatRAY = formatRAY;
|
|
15
|
-
function toSignificant(num, decimals) {
|
|
15
|
+
function toSignificant(num, decimals, precision = 6) {
|
|
16
16
|
if (num === 1n)
|
|
17
17
|
return "0";
|
|
18
18
|
const divider = new decimal_js_light_1.Decimal(10).toPower(decimals);
|
|
19
19
|
const number = new decimal_js_light_1.Decimal(num.toString()).div(divider);
|
|
20
|
-
return number.toSignificantDigits(
|
|
20
|
+
return number.toSignificantDigits(precision, 4).toString();
|
|
21
21
|
}
|
|
22
22
|
exports.toSignificant = toSignificant;
|
|
23
23
|
function toBN(num, decimals) {
|