@gearbox-protocol/sdk 3.0.0-next.57 → 3.0.0-next.58
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/core/trade.js
CHANGED
|
@@ -47,7 +47,11 @@ class Trade {
|
|
|
47
47
|
const callInfo = Trade.getCallInfo(calls, creditManager.address, currentContracts);
|
|
48
48
|
const trade = new Trade({
|
|
49
49
|
tradePath,
|
|
50
|
-
adapter: callInfo[0]
|
|
50
|
+
adapter: callInfo[0] || {
|
|
51
|
+
name: "unknown",
|
|
52
|
+
contractAddress: calls[0]?.target || "",
|
|
53
|
+
creditManager: creditManager.address,
|
|
54
|
+
},
|
|
51
55
|
swapOperation,
|
|
52
56
|
sourceAmount: amount,
|
|
53
57
|
minExpectedAmount: tradePath.minAmount,
|
|
@@ -64,8 +68,9 @@ class Trade {
|
|
|
64
68
|
static getCallInfo(calls, creditManager, currentContracts) {
|
|
65
69
|
const callAdapters = calls.reduce((acc, call) => {
|
|
66
70
|
const contractSymbol = this.getContractSymbol(call.target.toLowerCase());
|
|
67
|
-
if (!(0, sdk_gov_1.isSupportedContract)(contractSymbol))
|
|
71
|
+
if (!(0, sdk_gov_1.isSupportedContract)(contractSymbol)) {
|
|
68
72
|
return acc;
|
|
73
|
+
}
|
|
69
74
|
const { name } = sdk_gov_1.contractParams[contractSymbol];
|
|
70
75
|
const contractAddress = currentContracts[contractSymbol];
|
|
71
76
|
acc.push({
|
|
@@ -48,6 +48,10 @@ class CreditFacadeParser extends abstractParser_1.AbstractParser {
|
|
|
48
48
|
.join(", ");
|
|
49
49
|
return `${functionName}(${balancesStr})`;
|
|
50
50
|
}
|
|
51
|
+
case "withdrawCollateral": {
|
|
52
|
+
const [token, amount, to] = this.decodeFunctionData(functionFragment, calldata);
|
|
53
|
+
return `${functionName}(token: ${this.tokenSymbol(token)}, withdraw: ${this.formatAmount(amount)}, to: ${this.formatAmount(to)})`;
|
|
54
|
+
}
|
|
51
55
|
default:
|
|
52
56
|
return `${functionName}: Unknown operation ${functionFragment.name} with calldata ${calldata}`;
|
|
53
57
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NetworkType, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { providers, Signer } from "ethers";
|
|
3
|
+
import { Asset } from "../core/assets";
|
|
3
4
|
import { CreditAccountData } from "../core/creditAccount";
|
|
4
5
|
import { CreditManagerData } from "../core/creditManager";
|
|
5
6
|
import { IRouter } from "../types";
|
|
@@ -23,15 +24,15 @@ interface FindOneTokenPathProps {
|
|
|
23
24
|
interface FindBestClosePathProps {
|
|
24
25
|
creditAccount: CreditAccountData;
|
|
25
26
|
creditManager: CreditManagerData;
|
|
26
|
-
expectedBalances: Record<string,
|
|
27
|
-
leftoverBalances: Record<string,
|
|
27
|
+
expectedBalances: Record<string, Asset>;
|
|
28
|
+
leftoverBalances: Record<string, Asset>;
|
|
28
29
|
slippage: number;
|
|
29
30
|
noConcurrency?: boolean;
|
|
30
31
|
}
|
|
31
32
|
interface FindOpenStrategyPathProps {
|
|
32
33
|
creditManager: CreditManagerData;
|
|
33
|
-
expectedBalances: Record<string,
|
|
34
|
-
leftoverBalances: Record<string,
|
|
34
|
+
expectedBalances: Record<string, Asset>;
|
|
35
|
+
leftoverBalances: Record<string, Asset>;
|
|
35
36
|
target: string;
|
|
36
37
|
slippage: number;
|
|
37
38
|
}
|
|
@@ -77,11 +77,11 @@ class PathFinder {
|
|
|
77
77
|
async findOpenStrategyPath({ creditManager: cm, expectedBalances, leftoverBalances, target, slippage, }) {
|
|
78
78
|
const expected = cm.collateralTokens.map(token => ({
|
|
79
79
|
token,
|
|
80
|
-
balance: expectedBalances[token] ||
|
|
80
|
+
balance: expectedBalances[token]?.balance || 0n,
|
|
81
81
|
}));
|
|
82
82
|
const leftover = cm.collateralTokens.map(token => ({
|
|
83
83
|
token,
|
|
84
|
-
balance: leftoverBalances[token] ||
|
|
84
|
+
balance: leftoverBalances[token]?.balance || 1n,
|
|
85
85
|
}));
|
|
86
86
|
const connectors = this.getAvailableConnectors(cm.supportedTokens);
|
|
87
87
|
const [outBalances, result] = await this.pathFinder.callStatic.findOpenStrategyPath(cm.address, expected, leftover, target, connectors, slippage, {
|
|
@@ -114,11 +114,11 @@ class PathFinder {
|
|
|
114
114
|
const pathOptions = pathOptions_1.PathOptionFactory.generatePathOptions(creditAccount.allBalances, loopsPerTx);
|
|
115
115
|
const expected = cm.collateralTokens.map(token => ({
|
|
116
116
|
token,
|
|
117
|
-
balance: expectedBalances[token] ||
|
|
117
|
+
balance: expectedBalances[token]?.balance || 0n,
|
|
118
118
|
}));
|
|
119
119
|
const leftover = cm.collateralTokens.map(token => ({
|
|
120
120
|
token,
|
|
121
|
-
balance: leftoverBalances[token] ||
|
|
121
|
+
balance: leftoverBalances[token]?.balance || 1n,
|
|
122
122
|
}));
|
|
123
123
|
const connectors = this.getAvailableConnectors(creditAccount.balances);
|
|
124
124
|
let results = [];
|