@gearbox-protocol/sdk 3.0.0-next.264 → 3.0.0-next.266

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.
Files changed (34) hide show
  1. package/contracts/index.sol +1 -0
  2. package/lib/apy/defiLamaAPY.js +1 -0
  3. package/lib/core/endpoint.d.ts +1 -0
  4. package/lib/core/endpoint.js +3 -0
  5. package/lib/pathfinder/pathfinder.d.ts +13 -1
  6. package/lib/pathfinder/pathfinder.js +74 -11
  7. package/lib/types/IPToken.d.ts +21 -0
  8. package/lib/types/{IPendleSY.js → IPToken.js} +11 -4
  9. package/lib/types/IPendleMarket.d.ts +3 -27
  10. package/lib/types/IPendleMarket.js +3 -19
  11. package/lib/types/IPendleRouter.d.ts +536 -0
  12. package/lib/types/IPendleRouter.js +370 -0
  13. package/lib/types/IPendleRouterAdapter.d.ts +831 -0
  14. package/lib/types/IPendleRouterAdapter.js +572 -0
  15. package/lib/types/IPendleRouterAdapterEvents.d.ts +26 -0
  16. package/lib/types/IPendleRouterAdapterEvents.js +39 -0
  17. package/lib/types/IPendleRouterAdapterExceptions.d.ts +9 -0
  18. package/lib/types/IPendleRouterAdapterExceptions.js +10 -0
  19. package/lib/types/{IPendleYT.d.ts → IRouterComponent.d.ts} +8 -8
  20. package/lib/types/{IPendleYT.js → IRouterComponent.js} +8 -8
  21. package/lib/types/IRouterStatic.d.ts +128 -0
  22. package/lib/types/IRouterStatic.js +68 -0
  23. package/lib/types/ISwapper.d.ts +100 -0
  24. package/lib/types/ISwapper.js +75 -0
  25. package/lib/types/IYToken.d.ts +21 -0
  26. package/lib/types/IYToken.js +22 -0
  27. package/lib/types/PendleSwapper.d.ts +182 -0
  28. package/lib/types/PendleSwapper.js +130 -0
  29. package/lib/types/RouterComponentConfigurator.d.ts +61 -0
  30. package/lib/types/RouterComponentConfigurator.js +48 -0
  31. package/lib/types/index.d.ts +11 -2
  32. package/lib/types/index.js +11 -2
  33. package/package.json +6 -6
  34. package/lib/types/IPendleSY.d.ts +0 -11
@@ -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
 
@@ -47,6 +47,7 @@ const NORMAL_TO_LAMA = {
47
47
  PT_corn_eBTC_27MAR2025: "eb7de368-b460-4638-bde1-50a129109b7b",
48
48
  PT_corn_pumpBTC_26DEC2024: "a23e2b97-ff92-4ebf-8c7d-171cad8431ad",
49
49
  PT_sUSDe_27MAR2025: "6b28892f-0909-418d-b4bb-3106fff72449",
50
+ scrvUSD: "5fd328af-4203-471b-bd16-1705c726d926",
50
51
  },
51
52
  Optimism: { rETH: "d4b3c522-6127-4b89-bedf-83641cdcd2eb" },
52
53
  Arbitrum: {
@@ -10,6 +10,7 @@ export declare class GearboxBackendApi {
10
10
  static getNFTMerkleUrl: (network: NetworkType, root: Address) => string;
11
11
  static getLeaderboardUrl: (url: string, chainId: number) => string;
12
12
  static getReferralUrl: () => string;
13
+ static apyServerAllRewards: (chainId: number) => string;
13
14
  }
14
15
  interface Options {
15
16
  params?: Record<string, string | number>;
@@ -62,6 +62,9 @@ class GearboxBackendApi {
62
62
  return `${LEADERBOARD_APIS[chainId]}${url}`;
63
63
  };
64
64
  static getReferralUrl = () => REFERRAL_API;
65
+ static apyServerAllRewards = (chainId) => URLApi.getRelativeUrl("https://testnet.gearbox.foundation/apy-server/api/rewards/all", {
66
+ params: { chain_id: chainId },
67
+ });
65
68
  }
66
69
  exports.GearboxBackendApi = GearboxBackendApi;
67
70
  class URLApi {
@@ -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({ creditAccount, tokenIn, tokenOut, amount, slippage, }: FindOneTokenPathProps): Promise<PathFinderResult>;
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({ creditAccount, tokenIn, tokenOut, amount, slippage, }) {
59
+ async findOneTokenPath(props) {
60
+ const { creditAccount, tokenIn, tokenOut, amount, slippage } = props;
51
61
  const connectors = this.getAvailableConnectors(creditAccount.balances);
52
- const { result } = await this.pathFinder.simulate.findOneTokenPath([
53
- tokenIn,
54
- amount,
55
- tokenOut,
56
- creditAccount.addr,
57
- connectors,
58
- BigInt(slippage),
59
- ], {
60
- gas: GAS_PER_BLOCK,
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
- // IPendleSY
3
+ // IPToken
4
4
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.iPendleSyAbi = void 0;
7
- exports.iPendleSyAbi = [
6
+ exports.ipTokenAbi = void 0;
7
+ exports.ipTokenAbi = [
8
8
  {
9
9
  type: "function",
10
10
  inputs: [],
11
- name: "exchangeRate",
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
  },