@gearbox-protocol/sdk 3.0.0-next.7 → 3.0.0-next.9

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.
@@ -1,26 +1,12 @@
1
1
  import { SupportedContract } from "@gearbox-protocol/sdk-gov";
2
- import { Signer } from "ethers";
3
2
  import { MultiCall, PathFinderResult, SwapOperation } from "../pathfinder/core";
4
- import { ICreditFacadeV2 } from "../types";
5
3
  import { CreditManagerData } from "./creditManager";
6
- import { EVMTx } from "./eventOrTx";
7
4
  interface Info {
8
5
  name: string;
9
6
  contractAddress: string;
10
7
  creditManager: string;
11
8
  }
12
- export interface TradeProps {
13
- adapter: Info;
14
- tradePath: PathFinderResult;
15
- creditFacade: string;
16
- tokenFrom: string;
17
- tokenTo: string;
18
- sourceAmount: bigint;
19
- expectedAmount: bigint;
20
- swapType: SwapOperation;
21
- swapName: TradeOperations;
22
- }
23
- export type TradeOperations = "farmWithdraw" | "farmDeposit" | "swap" | "unknownOperation";
9
+ export type TradeOperations = "farmWithdraw" | "farmDeposit" | "swap";
24
10
  export interface GetTradesProps {
25
11
  from: string;
26
12
  to: string;
@@ -28,11 +14,12 @@ export interface GetTradesProps {
28
14
  results: Array<PathFinderResult>;
29
15
  creditManager: CreditManagerData;
30
16
  currentContracts: Record<SupportedContract, string>;
17
+ swapType: SwapOperation;
18
+ swapName: TradeOperations;
31
19
  }
32
20
  export declare class Trade {
33
21
  readonly helper: Info;
34
22
  readonly tradePath: PathFinderResult;
35
- readonly creditFacade: string;
36
23
  readonly swapType: SwapOperation;
37
24
  readonly sourceAmount: bigint;
38
25
  readonly expectedAmount: bigint;
@@ -40,17 +27,12 @@ export declare class Trade {
40
27
  readonly tokenFrom: string;
41
28
  readonly tokenTo: string;
42
29
  readonly operationName: TradeOperations;
43
- constructor(props: TradeProps);
30
+ private constructor();
44
31
  getName(): string;
45
- execute(signer: Signer): Promise<EVMTx>;
46
32
  toString(): string;
47
- static getTrades({ from, to, amount, results, creditManager, currentContracts, }: GetTradesProps): Trade[];
48
- static getOperationName(tokenInAddress: string, tokenOutAddress: string): TradeOperations;
33
+ static getTrades({ from, to, amount, results, creditManager, currentContracts, swapType, swapName, }: GetTradesProps): Trade[];
49
34
  static getCallInfo(calls: Array<MultiCall>, creditManager: string, currentContracts: Record<SupportedContract, string>): Info[];
50
35
  private static getContractSymbol;
51
- static getTradeId(trade: Trade): string;
52
36
  static sortTrades(trades: Array<Trade>, swapStrategy: string): Trade[];
53
- static executeMulticallPath(creditFacade: string | ICreditFacadeV2, signer: Signer, calls: Array<MultiCall>): Promise<import("ethers").ContractTransaction>;
54
- private static executeOnCreditFacade;
55
37
  }
56
38
  export {};
package/lib/core/trade.js CHANGED
@@ -4,19 +4,10 @@ exports.Trade = void 0;
4
4
  const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
5
5
  const txParser_1 = require("../parsers/txParser");
6
6
  const core_1 = require("../pathfinder/core");
7
- const types_1 = require("../types");
8
7
  const formatter_1 = require("../utils/formatter");
9
- const transactions_1 = require("./transactions");
10
- const OPERATION_NAMES = {
11
- farmWithdraw: "Farm withdraw",
12
- farmDeposit: "Farm deposit",
13
- swap: "Swap",
14
- unknownOperation: "Unknown operation",
15
- };
16
8
  class Trade {
17
9
  helper;
18
10
  tradePath;
19
- creditFacade;
20
11
  swapType;
21
12
  sourceAmount;
22
13
  expectedAmount;
@@ -27,7 +18,6 @@ class Trade {
27
18
  constructor(props) {
28
19
  this.helper = props.adapter;
29
20
  this.tradePath = props.tradePath;
30
- this.creditFacade = props.creditFacade;
31
21
  this.swapType = props.swapType;
32
22
  this.sourceAmount = props.sourceAmount;
33
23
  this.expectedAmount = props.expectedAmount;
@@ -39,20 +29,6 @@ class Trade {
39
29
  getName() {
40
30
  return this.helper.name;
41
31
  }
42
- async execute(signer) {
43
- const receipt = await Trade.executeMulticallPath(this.creditFacade, signer, this.tradePath.calls);
44
- return new transactions_1.TXSwap({
45
- txHash: receipt.hash,
46
- protocol: this.helper.contractAddress,
47
- operation: OPERATION_NAMES[this.operationName],
48
- amountFrom: this.sourceAmount,
49
- amountTo: this.expectedAmount,
50
- tokenFrom: this.tokenFrom,
51
- tokenTo: this.tokenTo,
52
- creditManager: this.helper.creditManager,
53
- timestamp: 0,
54
- });
55
- }
56
32
  toString() {
57
33
  const symbolFrom = sdk_gov_1.tokenSymbolByAddress[this.tokenFrom.toLowerCase()];
58
34
  const symbolTo = sdk_gov_1.tokenSymbolByAddress[this.tokenTo.toLowerCase()];
@@ -64,43 +40,25 @@ class Trade {
64
40
  const decimalsTo = sdk_gov_1.decimals[symbolTo];
65
41
  return `${this.operationName} ${(0, formatter_1.formatBN)(this.sourceAmount, decimalsFrom)} ${symbolFrom} ⇒ ${(0, formatter_1.formatBN)(this.expectedAmount, decimalsTo)} ${symbolTo} on ${this.helper.name}`;
66
42
  }
67
- static getTrades({ from, to, amount, results, creditManager, currentContracts, }) {
43
+ static getTrades({ from, to, amount, results, creditManager, currentContracts, swapType, swapName, }) {
68
44
  const trades = results.reduce((acc, tradePath) => {
69
45
  const { calls } = tradePath;
70
46
  const callInfo = Trade.getCallInfo(calls, creditManager.address, currentContracts);
71
47
  const trade = new Trade({
72
48
  tradePath,
73
- creditFacade: creditManager.creditFacade,
74
49
  adapter: callInfo[0],
75
- swapType: core_1.SwapOperation.EXACT_INPUT,
50
+ swapType,
76
51
  sourceAmount: amount,
77
52
  expectedAmount: tradePath.amount,
78
53
  tokenFrom: from,
79
54
  tokenTo: to,
80
- swapName: Trade.getOperationName(from, to),
55
+ swapName,
81
56
  });
82
57
  acc.push(trade);
83
58
  return acc;
84
59
  }, []);
85
60
  return trades;
86
61
  }
87
- static getOperationName(tokenInAddress, tokenOutAddress) {
88
- const tokenInSymbol = sdk_gov_1.tokenSymbolByAddress[tokenInAddress];
89
- const tokenOutSymbol = sdk_gov_1.tokenSymbolByAddress[tokenOutAddress];
90
- const tokenInIsLp = (0, sdk_gov_1.isLPToken)(tokenInSymbol);
91
- const tokenOutIsLp = (0, sdk_gov_1.isLPToken)(tokenOutSymbol);
92
- if (!tokenInSymbol)
93
- throw new Error(`Unknown token: ${tokenInAddress}`);
94
- if (!tokenOutSymbol)
95
- throw new Error(`Unknown token: ${tokenOutAddress}`);
96
- if (tokenInIsLp && !tokenOutIsLp)
97
- return "farmWithdraw";
98
- if (!tokenInIsLp && tokenOutIsLp)
99
- return "farmDeposit";
100
- if (!tokenInIsLp && !tokenOutIsLp)
101
- return "swap";
102
- return "unknownOperation";
103
- }
104
62
  static getCallInfo(calls, creditManager, currentContracts) {
105
63
  const callAdapters = calls.reduce((acc, call) => {
106
64
  const contractSymbol = this.getContractSymbol(call.target.toLowerCase());
@@ -126,9 +84,6 @@ class Trade {
126
84
  return undefined;
127
85
  }
128
86
  }
129
- static getTradeId(trade) {
130
- return `${trade.getName()}:${trade.expectedAmount.toString()}`;
131
- }
132
87
  static sortTrades(trades, swapStrategy) {
133
88
  if (trades.length === 0)
134
89
  return [];
@@ -144,16 +99,5 @@ class Trade {
144
99
  });
145
100
  return sorted;
146
101
  }
147
- static async executeMulticallPath(creditFacade, signer, calls) {
148
- if (calls.length < 1)
149
- throw new Error("No path to execute");
150
- const safeCreditFacade = typeof creditFacade === "string"
151
- ? types_1.ICreditFacadeV2__factory.connect(creditFacade, signer)
152
- : creditFacade;
153
- return this.executeOnCreditFacade(calls, safeCreditFacade);
154
- }
155
- static async executeOnCreditFacade(calls, creditFacade) {
156
- return creditFacade.multicall(calls);
157
- }
158
102
  }
159
103
  exports.Trade = Trade;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "3.0.0-next.7",
3
+ "version": "3.0.0-next.9",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -31,8 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@gearbox-protocol/integrations-v3": "^1.15.0",
34
- "@gearbox-protocol/sdk-gov": "^1.5.26",
35
- "@types/deep-eql": "^4.0.0",
34
+ "@gearbox-protocol/sdk-gov": "^1.5.27",
36
35
  "axios": "^1.2.6",
37
36
  "decimal.js-light": "^2.5.1",
38
37
  "deep-eql": "^4.1.0",
@@ -51,6 +50,7 @@
51
50
  "@openzeppelin/contracts": "4.8.3",
52
51
  "@typechain/ethers-v5": "^10.1.0",
53
52
  "@types/chai": "^4.3.3",
53
+ "@types/deep-eql": "^4.0.0",
54
54
  "@types/jest": "^28.1.7",
55
55
  "@types/mocha": "^10.0.1",
56
56
  "@types/node": "^18.7.6",