@gearbox-protocol/sdk 3.0.0-next.56 → 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/creditManager.d.ts +1 -0
- package/lib/core/creditManager.js +6 -0
- package/lib/core/trade.js +7 -2
- package/lib/core/transactions.d.ts +16 -1
- package/lib/core/transactions.js +27 -1
- package/lib/parsers/creditFacadeParser.js +4 -0
- package/lib/pathfinder/pathfinder.d.ts +5 -4
- package/lib/pathfinder/pathfinder.js +4 -4
- package/package.json +1 -1
|
@@ -51,6 +51,7 @@ export declare class CreditManagerData {
|
|
|
51
51
|
encodeRevertIfReceivedLessThanV2(assets: Array<Asset>): MultiCall;
|
|
52
52
|
encodeRevertIfReceivedLessThanV3(assets: Array<Asset>): MultiCall;
|
|
53
53
|
encodeUpdateQuotaV3(token: string, quotaChange: bigint, minQuota: bigint): MultiCall;
|
|
54
|
+
encodeWithdrawCollateralV3(token: string, amount: bigint, to: string): MultiCall;
|
|
54
55
|
static withdrawAllAndUnwrap_Convex(address: string, claim: boolean): MultiCall;
|
|
55
56
|
}
|
|
56
57
|
export declare class ChartsCreditManagerData {
|
|
@@ -200,6 +200,12 @@ class CreditManagerData {
|
|
|
200
200
|
callData: types_1.ICreditFacadeV3Multicall__factory.createInterface().encodeFunctionData("updateQuota", [token, quotaChange, minQuota]),
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
|
+
encodeWithdrawCollateralV3(token, amount, to) {
|
|
204
|
+
return {
|
|
205
|
+
target: this.creditFacade,
|
|
206
|
+
callData: types_1.ICreditFacadeV3Multicall__factory.createInterface().encodeFunctionData("withdrawCollateral", [token, amount, to]),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
203
209
|
static withdrawAllAndUnwrap_Convex(address, claim) {
|
|
204
210
|
return {
|
|
205
211
|
target: address,
|
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({
|
|
@@ -2,7 +2,7 @@ import { SupportedContract } from "@gearbox-protocol/sdk-gov";
|
|
|
2
2
|
import { Asset } from "./assets";
|
|
3
3
|
import { EVMTx, EVMTxProps } from "./eventOrTx";
|
|
4
4
|
export interface TxSerialized {
|
|
5
|
-
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxDecreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimReward" | "TxClaimNFT" | "TxClaimGearRewards" | "TxEnableTokens" | "TxUpdateQuota" | "TxGaugeStake" | "TxGaugeUnstake" | "TxGaugeClaim" | "TxGaugeVote";
|
|
5
|
+
type: "TxAddLiquidity" | "TxRemoveLiquidity" | "TxSwap" | "TxAddCollateral" | "TxIncreaseBorrowAmount" | "TxDecreaseBorrowAmount" | "TxOpenAccount" | "TxRepayAccount" | "TxCloseAccount" | "TxApprove" | "TxOpenMultitokenAccount" | "TxClaimReward" | "TxClaimNFT" | "TxClaimGearRewards" | "TxEnableTokens" | "TxUpdateQuota" | "TxGaugeStake" | "TxGaugeUnstake" | "TxGaugeClaim" | "TxGaugeVote" | "TxWithdrawCollateral";
|
|
6
6
|
content: string;
|
|
7
7
|
}
|
|
8
8
|
export declare class TxSerializer {
|
|
@@ -237,4 +237,19 @@ export declare class TxGaugeVote extends EVMTx {
|
|
|
237
237
|
toString(): string;
|
|
238
238
|
serialize(): TxSerialized;
|
|
239
239
|
}
|
|
240
|
+
interface WithdrawCollateralProps extends EVMTxProps {
|
|
241
|
+
amount: bigint;
|
|
242
|
+
token: string;
|
|
243
|
+
to: string;
|
|
244
|
+
creditManager: string;
|
|
245
|
+
}
|
|
246
|
+
export declare class TxWithdrawCollateral extends EVMTx {
|
|
247
|
+
readonly amount: bigint;
|
|
248
|
+
readonly token: string;
|
|
249
|
+
readonly to: string;
|
|
250
|
+
readonly creditManager: string;
|
|
251
|
+
constructor(opts: WithdrawCollateralProps);
|
|
252
|
+
toString(): string;
|
|
253
|
+
serialize(): TxSerialized;
|
|
254
|
+
}
|
|
240
255
|
export {};
|
package/lib/core/transactions.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TxGaugeVote = exports.TxGaugeClaim = exports.TxGaugeUnstake = exports.TxGaugeStake = exports.TxUpdateQuota = exports.TxEnableTokens = exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = exports.TxClaimGearRewards = exports.TxClaimNFT = exports.TxClaimReward = exports.TxOpenMultitokenAccount = exports.TxOpenAccount = exports.TxDecreaseBorrowAmount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
|
|
3
|
+
exports.TxWithdrawCollateral = exports.TxGaugeVote = exports.TxGaugeClaim = exports.TxGaugeUnstake = exports.TxGaugeStake = exports.TxUpdateQuota = exports.TxEnableTokens = exports.TxApprove = exports.TxCloseAccount = exports.TxRepayAccount = exports.TxClaimGearRewards = exports.TxClaimNFT = exports.TxClaimReward = exports.TxOpenMultitokenAccount = exports.TxOpenAccount = exports.TxDecreaseBorrowAmount = exports.TxIncreaseBorrowAmount = exports.TxAddCollateral = exports.TXSwap = exports.TxRemoveLiquidity = exports.TxAddLiquidity = exports.TxSerializer = void 0;
|
|
4
4
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
5
|
const contractsRegister_1 = require("../contracts/contractsRegister");
|
|
6
6
|
const math_1 = require("../utils/math");
|
|
@@ -53,6 +53,8 @@ class TxSerializer {
|
|
|
53
53
|
return new TxGaugeClaim(params);
|
|
54
54
|
case "TxGaugeVote":
|
|
55
55
|
return new TxGaugeVote(params);
|
|
56
|
+
case "TxWithdrawCollateral":
|
|
57
|
+
return new TxWithdrawCollateral(params);
|
|
56
58
|
default:
|
|
57
59
|
throw new Error(`Unknown transaction for parsing: ${e.type}`);
|
|
58
60
|
}
|
|
@@ -501,3 +503,27 @@ class TxGaugeVote extends eventOrTx_1.EVMTx {
|
|
|
501
503
|
}
|
|
502
504
|
}
|
|
503
505
|
exports.TxGaugeVote = TxGaugeVote;
|
|
506
|
+
class TxWithdrawCollateral extends eventOrTx_1.EVMTx {
|
|
507
|
+
amount;
|
|
508
|
+
token;
|
|
509
|
+
to;
|
|
510
|
+
creditManager;
|
|
511
|
+
constructor(opts) {
|
|
512
|
+
super(opts);
|
|
513
|
+
this.amount = opts.amount;
|
|
514
|
+
this.token = opts.token;
|
|
515
|
+
this.to = opts.to;
|
|
516
|
+
this.creditManager = opts.creditManager;
|
|
517
|
+
}
|
|
518
|
+
toString() {
|
|
519
|
+
const [symbol, decimals] = (0, sdk_gov_1.extractTokenData)(this.token);
|
|
520
|
+
return `Credit account ${(0, contractsRegister_1.getContractName)(this.creditManager)}: withdrawn ${(0, sdk_gov_1.formatBN)(this.amount, decimals || 18)} ${symbol}`;
|
|
521
|
+
}
|
|
522
|
+
serialize() {
|
|
523
|
+
return {
|
|
524
|
+
type: "TxWithdrawCollateral",
|
|
525
|
+
content: JSON.stringify(this),
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
exports.TxWithdrawCollateral = TxWithdrawCollateral;
|
|
@@ -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 = [];
|