@gearbox-protocol/sdk 3.0.0-next.265 → 3.0.0-next.267
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/contracts/index.sol +1 -0
- package/lib/apy/index.d.ts +1 -6
- package/lib/apy/index.js +0 -20
- package/lib/core/creditAccount.d.ts +1 -1
- package/lib/core/endpoint.d.ts +1 -0
- package/lib/core/endpoint.js +4 -1
- package/lib/pathfinder/pathfinder.d.ts +13 -1
- package/lib/pathfinder/pathfinder.js +74 -11
- package/lib/types/IPToken.d.ts +21 -0
- package/lib/types/{IPendleSY.js → IPToken.js} +11 -4
- package/lib/types/IPendleMarket.d.ts +3 -27
- package/lib/types/IPendleMarket.js +3 -19
- package/lib/types/IPendleRouter.d.ts +536 -0
- package/lib/types/IPendleRouter.js +370 -0
- package/lib/types/IPendleRouterAdapter.d.ts +831 -0
- package/lib/types/IPendleRouterAdapter.js +572 -0
- package/lib/types/IPendleRouterAdapterEvents.d.ts +26 -0
- package/lib/types/IPendleRouterAdapterEvents.js +39 -0
- package/lib/types/IPendleRouterAdapterExceptions.d.ts +9 -0
- package/lib/types/IPendleRouterAdapterExceptions.js +10 -0
- package/lib/types/{IPendleYT.d.ts → IRouterComponent.d.ts} +8 -8
- package/lib/types/{IPendleYT.js → IRouterComponent.js} +8 -8
- package/lib/types/IRouterStatic.d.ts +128 -0
- package/lib/types/IRouterStatic.js +68 -0
- package/lib/types/ISwapper.d.ts +100 -0
- package/lib/types/ISwapper.js +75 -0
- package/lib/types/IYToken.d.ts +21 -0
- package/lib/types/IYToken.js +22 -0
- package/lib/types/PendleSwapper.d.ts +182 -0
- package/lib/types/PendleSwapper.js +130 -0
- package/lib/types/RouterComponentConfigurator.d.ts +61 -0
- package/lib/types/RouterComponentConfigurator.js +48 -0
- package/lib/types/index.d.ts +11 -2
- package/lib/types/index.js +11 -2
- package/package.json +5 -5
- package/lib/apy/curveAPY.d.ts +0 -61
- package/lib/apy/curveAPY.js +0 -143
- package/lib/apy/defiLamaAPY.d.ts +0 -3
- package/lib/apy/defiLamaAPY.js +0 -85
- package/lib/apy/lidoAPY.d.ts +0 -4
- package/lib/apy/lidoAPY.js +0 -19
- package/lib/apy/pendleAPY.d.ts +0 -5
- package/lib/apy/pendleAPY.js +0 -26
- package/lib/apy/skyAPY.d.ts +0 -5
- package/lib/apy/skyAPY.js +0 -28
- package/lib/apy/yearnAPY.d.ts +0 -3
- package/lib/apy/yearnAPY.js +0 -38
- package/lib/types/IPendleSY.d.ts +0 -11
package/contracts/index.sol
CHANGED
|
@@ -84,6 +84,7 @@ import {IStakingRewardsAdapter} from
|
|
|
84
84
|
import {IMulticall3} from "@gearbox-protocol/router-v3/lib/forge-std/src/interfaces/IMulticall3.sol";
|
|
85
85
|
import {IRouterV3} from "@gearbox-protocol/router-v3/contracts/interfaces/IRouterV3.sol";
|
|
86
86
|
import {IRouter} from "@gearbox-protocol/router/contracts/interfaces/IRouter.sol";
|
|
87
|
+
import {PendleSwapper} from "@gearbox-protocol/router-v3/contracts/workers/PendleSwapper.sol";
|
|
87
88
|
|
|
88
89
|
import {IFarmingPool} from "@1inch/farming/contracts/interfaces/IFarmingPool.sol";
|
|
89
90
|
|
package/lib/apy/index.d.ts
CHANGED
|
@@ -9,9 +9,4 @@ export type TokensWithApyRecord = PartialRecord<TokensWithAPY, number>;
|
|
|
9
9
|
export declare const isTokenWithAPY: (t: unknown) => t is TokensWithAPY;
|
|
10
10
|
export type AllLPTokens = LPTokens | ExtraFarmTokens;
|
|
11
11
|
export declare const isFarmToken: (t: unknown) => t is AllLPTokens;
|
|
12
|
-
export
|
|
13
|
-
export * from "./defiLamaAPY";
|
|
14
|
-
export * from "./lidoAPY";
|
|
15
|
-
export * from "./pendleAPY";
|
|
16
|
-
export * from "./skyAPY";
|
|
17
|
-
export * from "./yearnAPY";
|
|
12
|
+
export {};
|
package/lib/apy/index.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
3
|
exports.isFarmToken = exports.isTokenWithAPY = exports.isLRT_LSTToken = exports.isExtraFarmToken = void 0;
|
|
18
4
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
@@ -103,9 +89,3 @@ const isFarmToken = (t) => {
|
|
|
103
89
|
return (0, sdk_gov_1.isLPToken)(t) || (0, exports.isExtraFarmToken)(t);
|
|
104
90
|
};
|
|
105
91
|
exports.isFarmToken = isFarmToken;
|
|
106
|
-
__exportStar(require("./curveAPY"), exports);
|
|
107
|
-
__exportStar(require("./defiLamaAPY"), exports);
|
|
108
|
-
__exportStar(require("./lidoAPY"), exports);
|
|
109
|
-
__exportStar(require("./pendleAPY"), exports);
|
|
110
|
-
__exportStar(require("./skyAPY"), exports);
|
|
111
|
-
__exportStar(require("./yearnAPY"), exports);
|
|
@@ -124,7 +124,7 @@ export declare class CreditAccountData {
|
|
|
124
124
|
setDeleteInProgress(d: boolean): void;
|
|
125
125
|
static sortBalances(balances: Record<Address, bigint>, prices: Record<Address, bigint>, tokens: Record<Address, TokenData>): Array<[Address, bigint]>;
|
|
126
126
|
static sortAssets(balances: Array<Asset>, prices: Record<Address, bigint>, tokens: Record<Address, TokenData>): Asset[];
|
|
127
|
-
static tokensAbcComparator(t1?: TokenData, t2?: TokenData):
|
|
127
|
+
static tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1 | 0;
|
|
128
128
|
static amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
|
|
129
129
|
isForbidden(token: Address): boolean;
|
|
130
130
|
isQuoted(token: Address): boolean;
|
package/lib/core/endpoint.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class GearboxBackendApi {
|
|
|
11
11
|
static getLeaderboardUrl: (url: string, chainId: number) => string;
|
|
12
12
|
static getReferralUrl: () => string;
|
|
13
13
|
static apyServerAllRewards: (chainId: number) => string;
|
|
14
|
+
static apyServerGearAPY: (chainId: number) => string;
|
|
14
15
|
}
|
|
15
16
|
interface Options {
|
|
16
17
|
params?: Record<string, string | number>;
|
package/lib/core/endpoint.js
CHANGED
|
@@ -62,7 +62,10 @@ class GearboxBackendApi {
|
|
|
62
62
|
return `${LEADERBOARD_APIS[chainId]}${url}`;
|
|
63
63
|
};
|
|
64
64
|
static getReferralUrl = () => REFERRAL_API;
|
|
65
|
-
static apyServerAllRewards = (chainId) => URLApi.getRelativeUrl("https://
|
|
65
|
+
static apyServerAllRewards = (chainId) => URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/all", {
|
|
66
|
+
params: { chain_id: chainId },
|
|
67
|
+
});
|
|
68
|
+
static apyServerGearAPY = (chainId) => URLApi.getRelativeUrl("https://apy-server.fly.dev/api/rewards/gear-apy", {
|
|
66
69
|
params: { chain_id: chainId },
|
|
67
70
|
});
|
|
68
71
|
}
|
|
@@ -16,6 +16,7 @@ interface FindAllSwapsProps {
|
|
|
16
16
|
}
|
|
17
17
|
interface FindOneTokenPathProps {
|
|
18
18
|
creditAccount: CreditAccountData;
|
|
19
|
+
creditManager: CreditManagerData;
|
|
19
20
|
tokenIn: Address;
|
|
20
21
|
tokenOut: Address;
|
|
21
22
|
amount: bigint;
|
|
@@ -39,10 +40,21 @@ interface FindOpenStrategyPathProps {
|
|
|
39
40
|
export declare class PathFinder {
|
|
40
41
|
pathFinder: GetContractReturnType<typeof iRouterV3Abi, PublicClient>;
|
|
41
42
|
network: NetworkType;
|
|
43
|
+
protected readonly _client: PublicClient;
|
|
42
44
|
protected readonly _connectors: Array<Address>;
|
|
43
45
|
constructor(address: Address, provider: PublicClient, network?: NetworkType);
|
|
44
46
|
findAllSwaps({ creditAccount, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }: FindAllSwapsProps): Promise<Array<PathFinderResult>>;
|
|
45
|
-
findOneTokenPath(
|
|
47
|
+
findOneTokenPath(props: FindOneTokenPathProps): Promise<PathFinderResult>;
|
|
48
|
+
overridePTRedeem({ creditAccount, creditManager, tokenIn, tokenOut, amount, slippage, }: FindOneTokenPathProps): Promise<{
|
|
49
|
+
result: {
|
|
50
|
+
amount: bigint;
|
|
51
|
+
minAmount: bigint;
|
|
52
|
+
calls: {
|
|
53
|
+
target: `0x${string}`;
|
|
54
|
+
callData: `0x${string}`;
|
|
55
|
+
}[];
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
46
58
|
/**
|
|
47
59
|
* @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
48
60
|
* @param cm CreditManagerData which represents credit manager you want to use to open Credit Account
|
|
@@ -7,9 +7,17 @@ const types_1 = require("../types");
|
|
|
7
7
|
const pathOptions_1 = require("./pathOptions");
|
|
8
8
|
const MAX_GAS_PER_ROUTE = 200000000n;
|
|
9
9
|
const GAS_PER_BLOCK = 400000000n;
|
|
10
|
+
const PT_IN = {
|
|
11
|
+
["0xEe9085fC268F6727d5D4293dBABccF901ffDCC29".toLowerCase()]: "PT_sUSDe_26DEC2024",
|
|
12
|
+
["0xE00bd3Df25fb187d6ABBB620b3dfd19839947b81".toLowerCase()]: "PT_sUSDe_27MAR20251",
|
|
13
|
+
};
|
|
14
|
+
const OUT = {
|
|
15
|
+
["0x9D39A5DE30e57443BfF2A8307A4256c8797A3497".toLowerCase()]: "sUSDe",
|
|
16
|
+
};
|
|
10
17
|
class PathFinder {
|
|
11
18
|
pathFinder;
|
|
12
19
|
network;
|
|
20
|
+
_client;
|
|
13
21
|
_connectors;
|
|
14
22
|
constructor(address, provider, network = "Mainnet") {
|
|
15
23
|
this.pathFinder = (0, viem_1.getContract)({
|
|
@@ -19,6 +27,7 @@ class PathFinder {
|
|
|
19
27
|
});
|
|
20
28
|
this.network = network;
|
|
21
29
|
this._connectors = (0, sdk_gov_1.getConnectors)(network);
|
|
30
|
+
this._client = provider;
|
|
22
31
|
}
|
|
23
32
|
async findAllSwaps({ creditAccount, swapOperation, tokenIn, tokenOut, amount, leftoverAmount, slippage, }) {
|
|
24
33
|
const connectors = this.getAvailableConnectors(creditAccount.balances);
|
|
@@ -47,24 +56,78 @@ class PathFinder {
|
|
|
47
56
|
});
|
|
48
57
|
return Object.values(unique);
|
|
49
58
|
}
|
|
50
|
-
async findOneTokenPath(
|
|
59
|
+
async findOneTokenPath(props) {
|
|
60
|
+
const { creditAccount, tokenIn, tokenOut, amount, slippage } = props;
|
|
51
61
|
const connectors = this.getAvailableConnectors(creditAccount.balances);
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
const isPTOverrideRedeem = PT_IN[tokenIn.toLowerCase()] && OUT[tokenOut.toLowerCase()];
|
|
63
|
+
const { result } = await (isPTOverrideRedeem
|
|
64
|
+
? this.overridePTRedeem(props)
|
|
65
|
+
: this.pathFinder.simulate.findOneTokenPath([
|
|
66
|
+
tokenIn,
|
|
67
|
+
amount,
|
|
68
|
+
tokenOut,
|
|
69
|
+
creditAccount.addr,
|
|
70
|
+
connectors,
|
|
71
|
+
BigInt(slippage),
|
|
72
|
+
], {
|
|
73
|
+
gas: GAS_PER_BLOCK,
|
|
74
|
+
}));
|
|
62
75
|
return {
|
|
63
76
|
amount: result.amount,
|
|
64
77
|
minAmount: result.minAmount,
|
|
65
78
|
calls: result.calls,
|
|
66
79
|
};
|
|
67
80
|
}
|
|
81
|
+
async overridePTRedeem({ creditAccount, creditManager, tokenIn, tokenOut, amount, slippage, }) {
|
|
82
|
+
const pendleSwapperAddress = await this.pathFinder.read.componentAddressById([37]);
|
|
83
|
+
const adapterAddress = creditManager.adapters[sdk_gov_1.contractsByNetwork[this.network].PENDLE_ROUTER.toLowerCase()];
|
|
84
|
+
const pendleSwapper = (0, viem_1.getContract)({
|
|
85
|
+
address: pendleSwapperAddress,
|
|
86
|
+
abi: types_1.pendleSwapperAbi,
|
|
87
|
+
client: this._client,
|
|
88
|
+
});
|
|
89
|
+
const result = await pendleSwapper.simulate.getBestDirectPairSwap([
|
|
90
|
+
{
|
|
91
|
+
swapOperation: 1,
|
|
92
|
+
creditAccount: creditAccount.addr,
|
|
93
|
+
tokenIn: tokenIn,
|
|
94
|
+
tokenOut: tokenOut,
|
|
95
|
+
connectors: [],
|
|
96
|
+
amount,
|
|
97
|
+
leftoverAmount: 0n,
|
|
98
|
+
},
|
|
99
|
+
adapterAddress,
|
|
100
|
+
]);
|
|
101
|
+
const minAmount = (result.result.amount * (sdk_gov_1.PERCENTAGE_FACTOR - BigInt(slippage))) /
|
|
102
|
+
sdk_gov_1.PERCENTAGE_FACTOR;
|
|
103
|
+
const storeExpectedBalances = {
|
|
104
|
+
target: creditManager.creditFacade,
|
|
105
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
106
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
107
|
+
functionName: "storeExpectedBalances",
|
|
108
|
+
args: [[{ token: tokenOut, amount: minAmount }]],
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
const compareBalances = {
|
|
112
|
+
target: creditManager.creditFacade,
|
|
113
|
+
callData: (0, viem_1.encodeFunctionData)({
|
|
114
|
+
abi: types_1.iCreditFacadeV3MulticallAbi,
|
|
115
|
+
functionName: "compareBalances",
|
|
116
|
+
args: [],
|
|
117
|
+
}),
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
result: {
|
|
121
|
+
amount: result.result.amount,
|
|
122
|
+
minAmount,
|
|
123
|
+
calls: [
|
|
124
|
+
storeExpectedBalances,
|
|
125
|
+
result.result.multiCall,
|
|
126
|
+
compareBalances,
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
68
131
|
/**
|
|
69
132
|
* @dev Finds the best path for opening Credit Account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
70
133
|
* @param cm CreditManagerData which represents credit manager you want to use to open Credit Account
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const ipTokenAbi: readonly [{
|
|
2
|
+
readonly type: "function";
|
|
3
|
+
readonly inputs: readonly [];
|
|
4
|
+
readonly name: "YT";
|
|
5
|
+
readonly outputs: readonly [{
|
|
6
|
+
readonly name: "";
|
|
7
|
+
readonly internalType: "address";
|
|
8
|
+
readonly type: "address";
|
|
9
|
+
}];
|
|
10
|
+
readonly stateMutability: "view";
|
|
11
|
+
}, {
|
|
12
|
+
readonly type: "function";
|
|
13
|
+
readonly inputs: readonly [];
|
|
14
|
+
readonly name: "expiry";
|
|
15
|
+
readonly outputs: readonly [{
|
|
16
|
+
readonly name: "";
|
|
17
|
+
readonly internalType: "uint256";
|
|
18
|
+
readonly type: "uint256";
|
|
19
|
+
}];
|
|
20
|
+
readonly stateMutability: "view";
|
|
21
|
+
}];
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
3
|
-
//
|
|
3
|
+
// IPToken
|
|
4
4
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.ipTokenAbi = void 0;
|
|
7
|
+
exports.ipTokenAbi = [
|
|
8
8
|
{
|
|
9
9
|
type: "function",
|
|
10
10
|
inputs: [],
|
|
11
|
-
name: "
|
|
11
|
+
name: "YT",
|
|
12
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
13
|
+
stateMutability: "view",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: "function",
|
|
17
|
+
inputs: [],
|
|
18
|
+
name: "expiry",
|
|
12
19
|
outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
13
20
|
stateMutability: "view",
|
|
14
21
|
},
|
|
@@ -1,41 +1,17 @@
|
|
|
1
1
|
export declare const iPendleMarketAbi: readonly [{
|
|
2
|
-
readonly type: "function";
|
|
3
|
-
readonly inputs: readonly [];
|
|
4
|
-
readonly name: "expiry";
|
|
5
|
-
readonly outputs: readonly [{
|
|
6
|
-
readonly name: "";
|
|
7
|
-
readonly internalType: "uint256";
|
|
8
|
-
readonly type: "uint256";
|
|
9
|
-
}];
|
|
10
|
-
readonly stateMutability: "view";
|
|
11
|
-
}, {
|
|
12
|
-
readonly type: "function";
|
|
13
|
-
readonly inputs: readonly [{
|
|
14
|
-
readonly name: "secondsAgos";
|
|
15
|
-
readonly internalType: "uint32[]";
|
|
16
|
-
readonly type: "uint32[]";
|
|
17
|
-
}];
|
|
18
|
-
readonly name: "observe";
|
|
19
|
-
readonly outputs: readonly [{
|
|
20
|
-
readonly name: "";
|
|
21
|
-
readonly internalType: "uint216[]";
|
|
22
|
-
readonly type: "uint216[]";
|
|
23
|
-
}];
|
|
24
|
-
readonly stateMutability: "view";
|
|
25
|
-
}, {
|
|
26
2
|
readonly type: "function";
|
|
27
3
|
readonly inputs: readonly [];
|
|
28
4
|
readonly name: "readTokens";
|
|
29
5
|
readonly outputs: readonly [{
|
|
30
|
-
readonly name: "";
|
|
6
|
+
readonly name: "sy";
|
|
31
7
|
readonly internalType: "address";
|
|
32
8
|
readonly type: "address";
|
|
33
9
|
}, {
|
|
34
|
-
readonly name: "";
|
|
10
|
+
readonly name: "pt";
|
|
35
11
|
readonly internalType: "address";
|
|
36
12
|
readonly type: "address";
|
|
37
13
|
}, {
|
|
38
|
-
readonly name: "";
|
|
14
|
+
readonly name: "yt";
|
|
39
15
|
readonly internalType: "address";
|
|
40
16
|
readonly type: "address";
|
|
41
17
|
}];
|
|
@@ -5,30 +5,14 @@
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.iPendleMarketAbi = void 0;
|
|
7
7
|
exports.iPendleMarketAbi = [
|
|
8
|
-
{
|
|
9
|
-
type: "function",
|
|
10
|
-
inputs: [],
|
|
11
|
-
name: "expiry",
|
|
12
|
-
outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
13
|
-
stateMutability: "view",
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
type: "function",
|
|
17
|
-
inputs: [
|
|
18
|
-
{ name: "secondsAgos", internalType: "uint32[]", type: "uint32[]" },
|
|
19
|
-
],
|
|
20
|
-
name: "observe",
|
|
21
|
-
outputs: [{ name: "", internalType: "uint216[]", type: "uint216[]" }],
|
|
22
|
-
stateMutability: "view",
|
|
23
|
-
},
|
|
24
8
|
{
|
|
25
9
|
type: "function",
|
|
26
10
|
inputs: [],
|
|
27
11
|
name: "readTokens",
|
|
28
12
|
outputs: [
|
|
29
|
-
{ name: "", internalType: "address", type: "address" },
|
|
30
|
-
{ name: "", internalType: "address", type: "address" },
|
|
31
|
-
{ name: "", internalType: "address", type: "address" },
|
|
13
|
+
{ name: "sy", internalType: "address", type: "address" },
|
|
14
|
+
{ name: "pt", internalType: "address", type: "address" },
|
|
15
|
+
{ name: "yt", internalType: "address", type: "address" },
|
|
32
16
|
],
|
|
33
17
|
stateMutability: "view",
|
|
34
18
|
},
|