@gearbox-protocol/sdk 0.0.102 → 0.0.105
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/.eslintignore +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -2
- package/lib/index.js +8 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +18 -15
- package/lib/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +4 -4
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +27 -17
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +7 -3
- package/src/core/strategy.ts +27 -23
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +361 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +9 -5
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {NetworkType} from "../core/constants";
|
|
1
|
+
import { NetworkType } from "../core/constants";
|
|
2
2
|
|
|
3
3
|
export type PathFinderContracts = "PATH_FINDER" | "CONVEX_PATH_FINDER";
|
|
4
4
|
|
|
5
|
-
export const pathFindersByNetwork: Record<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
export const pathFindersByNetwork: Record<
|
|
6
|
+
NetworkType,
|
|
7
|
+
Record<PathFinderContracts, string>
|
|
8
|
+
> = {
|
|
9
|
+
Mainnet: {
|
|
10
|
+
// PATH_FINDER
|
|
11
|
+
PATH_FINDER: "",
|
|
12
|
+
CONVEX_PATH_FINDER: ""
|
|
13
|
+
},
|
|
14
|
+
Kovan: {
|
|
15
|
+
// PATH_FINDER
|
|
16
|
+
PATH_FINDER: "",
|
|
17
|
+
CONVEX_PATH_FINDER: ""
|
|
18
|
+
}
|
|
17
19
|
};
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { convexTokens } from "../tokens/convex";
|
|
2
|
+
import { objectEntries } from "../utils/mappers";
|
|
3
|
+
import type { LPWithdrawPathFinder, Path } from "./path";
|
|
3
4
|
|
|
4
5
|
export class ConvexLPPathFinder implements LPWithdrawPathFinder {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
6
|
+
// eslint-disable-next-line class-methods-use-this
|
|
7
|
+
async findWithdrawPaths(p: Path): Promise<Array<Path>> {
|
|
8
|
+
const pids = objectEntries(convexTokens).reduce(
|
|
9
|
+
(acc, [cvxToken, tokenData]) => {
|
|
10
|
+
const currentBalance = p.popBalance(cvxToken);
|
|
11
|
+
if (currentBalance.gt(1)) {
|
|
12
|
+
pids.add(tokenData.pid);
|
|
13
13
|
}
|
|
14
|
+
return acc;
|
|
15
|
+
},
|
|
16
|
+
new Set<number>()
|
|
17
|
+
);
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
// const convexPathFinder = ConvexPathFinder__factory.connect(
|
|
20
|
+
// pathFindersByNetwork[p.networkType].CONVEX_PATH_FINDER,
|
|
21
|
+
// p.provider
|
|
22
|
+
// );
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
// const tokenBalances = await convexPathFinder.calcRewards(
|
|
25
|
+
// p.creditAccount.addr,
|
|
26
|
+
// Array.from(pids)
|
|
27
|
+
// );
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// for (let balance of tokenBalances) {
|
|
30
|
+
// p.balances[balance.token] = p.balances[balance.token].add(
|
|
31
|
+
// balance.balance
|
|
32
|
+
// );
|
|
33
|
+
// }
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
return p.withdrawTokens();
|
|
36
|
+
}
|
|
33
37
|
}
|
|
@@ -1,71 +1,75 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import type { LPWithdrawPathFinder, Path } from "./path";
|
|
3
|
+
import { CurveLPToken, curveTokens } from "../tokens/curveLP";
|
|
4
|
+
import {
|
|
5
|
+
contractParams,
|
|
6
|
+
contractsByAddress,
|
|
7
|
+
CurveParams,
|
|
8
|
+
CurvePoolContract
|
|
9
|
+
} from "../contracts/contracts";
|
|
10
|
+
import { TradeType } from "./tradeTypes";
|
|
11
|
+
import { CallData, MultiCallContract } from "../utils/multicall";
|
|
12
|
+
import { ICurvePool__factory } from "../types";
|
|
13
|
+
import { ICurvePoolInterface } from "../types/contracts/integrations/curve/ICurvePool";
|
|
9
14
|
|
|
10
15
|
export class CurvePathFinder implements LPWithdrawPathFinder {
|
|
11
|
-
|
|
12
|
-
contract: CurvePoolContract;
|
|
16
|
+
lpToken: CurveLPToken;
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
this.lpToken = token;
|
|
16
|
-
const curvePools = curveTokens[this.lpToken].lpActions.filter(
|
|
17
|
-
a => a.type == TradeType.CurveWithdrawLP
|
|
18
|
-
);
|
|
18
|
+
contract: CurvePoolContract;
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
constructor(token: CurveLPToken) {
|
|
21
|
+
this.lpToken = token;
|
|
22
|
+
const curvePools = curveTokens[this.lpToken].lpActions.filter(
|
|
23
|
+
a => a.type === TradeType.CurveWithdrawLP
|
|
24
|
+
);
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
if (curvePools.length !== 1) throw new Error("Cant find Withdrawer");
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
.wrapper;
|
|
28
|
+
this.contract = curvePools[0].contract as CurvePoolContract;
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
this.contract = wrapper;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
30
|
+
const { wrapper } = contractParams[curvePools[0].contract] as CurveParams;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
if (wrapper) {
|
|
33
|
+
this.contract = wrapper;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
async findWithdrawPaths(p: Path): Promise<Array<Path>> {
|
|
38
|
+
const coins = (contractParams[this.contract] as CurveParams).tokens;
|
|
39
|
+
const nCoins = coins.length;
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
contractsByAddress[this.contract],
|
|
40
|
-
ICurvePool__factory.createInterface(),
|
|
41
|
-
p.provider
|
|
42
|
-
);
|
|
41
|
+
const lpBalance = p.popBalance(this.lpToken);
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
const multiCallContract = new MultiCallContract(
|
|
44
|
+
contractsByAddress[this.contract],
|
|
45
|
+
ICurvePool__factory.createInterface(),
|
|
46
|
+
p.provider
|
|
47
|
+
);
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
data.push({
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
method: "calc_withdraw_one_coin(uint256,int128)",
|
|
50
|
-
params: [lpBalance, i]
|
|
51
|
-
});
|
|
52
|
-
}
|
|
49
|
+
const data: Array<CallData<ICurvePoolInterface>> = [];
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
for (let i = 0; i < nCoins; i += 1) {
|
|
52
|
+
data.push({
|
|
53
|
+
method: "calc_withdraw_one_coin(uint256,int128)",
|
|
54
|
+
params: [lpBalance, i]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
const balances = await multiCallContract.call<Array<BigNumber>>(data);
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
for (let i = 0; i < nCoins; i++) {
|
|
60
|
-
const newPath = p.clone();
|
|
61
|
-
// newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
|
|
62
|
-
// newPath.calls.push({
|
|
63
|
-
// targetContract: contractsByNetwork[p.networkType][this.contract],
|
|
64
|
-
// callData: ICurveV1Adapter__factory.createInterface().encodeFunctionData("remove_all_liquidity_one_coin", [i])
|
|
65
|
-
// })
|
|
66
|
-
paths.push(newPath);
|
|
67
|
-
}
|
|
60
|
+
console.debug(balances);
|
|
68
61
|
|
|
69
|
-
|
|
62
|
+
const paths: Array<Path> = [];
|
|
63
|
+
for (let i = 0; i < nCoins; i += 1) {
|
|
64
|
+
const newPath = p.clone();
|
|
65
|
+
// newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
|
|
66
|
+
// newPath.calls.push({
|
|
67
|
+
// targetContract: contractsByNetwork[p.networkType][this.contract],
|
|
68
|
+
// callData: ICurveV1Adapter__factory.createInterface().encodeFunctionData("remove_all_liquidity_one_coin", [i])
|
|
69
|
+
// })
|
|
70
|
+
paths.push(newPath);
|
|
70
71
|
}
|
|
72
|
+
|
|
73
|
+
return paths;
|
|
74
|
+
}
|
|
71
75
|
}
|
package/src/pathfinder/path.ts
CHANGED
|
@@ -23,12 +23,19 @@ import { TokenType } from "../tokens/tokenType";
|
|
|
23
23
|
|
|
24
24
|
export class Path {
|
|
25
25
|
public readonly calls: Array<MultiCall> = [];
|
|
26
|
+
|
|
26
27
|
public readonly balances: PartialRecord<SupportedToken, BigNumber>;
|
|
28
|
+
|
|
27
29
|
public readonly underlying: SupportedToken;
|
|
30
|
+
|
|
28
31
|
public readonly creditManager: CreditManagerData;
|
|
32
|
+
|
|
29
33
|
public readonly creditAccount: CreditAccountData;
|
|
34
|
+
|
|
30
35
|
public readonly networkType: NetworkType;
|
|
36
|
+
|
|
31
37
|
public readonly provider: ethers.providers.Provider;
|
|
38
|
+
|
|
32
39
|
public totalGasLimit: number;
|
|
33
40
|
|
|
34
41
|
constructor(opts: {
|
|
@@ -59,9 +66,9 @@ export class Path {
|
|
|
59
66
|
return currentBalance.sub(1);
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
private comparedByPriority(
|
|
63
|
-
[tokenA
|
|
64
|
-
[tokenB
|
|
69
|
+
private static comparedByPriority(
|
|
70
|
+
[tokenA]: [string, BigNumber],
|
|
71
|
+
[tokenB]: [string, BigNumber]
|
|
65
72
|
): number {
|
|
66
73
|
const priorityTokenA =
|
|
67
74
|
priority[supportedTokens[tokenA as SupportedToken].type];
|
|
@@ -70,7 +77,8 @@ export class Path {
|
|
|
70
77
|
|
|
71
78
|
if (priorityTokenA > priorityTokenB) {
|
|
72
79
|
return -1;
|
|
73
|
-
}
|
|
80
|
+
}
|
|
81
|
+
if (priorityTokenA < priorityTokenB) {
|
|
74
82
|
return 1;
|
|
75
83
|
}
|
|
76
84
|
return 0;
|
|
@@ -110,15 +118,15 @@ export class Path {
|
|
|
110
118
|
provider
|
|
111
119
|
);
|
|
112
120
|
|
|
113
|
-
console.
|
|
114
|
-
console.
|
|
121
|
+
console.debug(lpPaths);
|
|
122
|
+
console.debug(pathFinder);
|
|
115
123
|
// const bestPath = await pathFinder.bestPath();
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
async withdrawTokens(): Promise<Array<Path>> {
|
|
119
127
|
const existingTokens = Object.entries(this.balances)
|
|
120
|
-
.filter(([
|
|
121
|
-
.sort(
|
|
128
|
+
.filter(([, balance]) => balance.gt(1))
|
|
129
|
+
.sort(Path.comparedByPriority);
|
|
122
130
|
|
|
123
131
|
// TODO: Add checks for lenght
|
|
124
132
|
if (existingTokens.length === 0)
|
|
@@ -153,7 +161,7 @@ export class Path {
|
|
|
153
161
|
throw new Error("Token type not supported yet");
|
|
154
162
|
}
|
|
155
163
|
|
|
156
|
-
return
|
|
164
|
+
return lpPathFinder.findWithdrawPaths(this);
|
|
157
165
|
}
|
|
158
166
|
|
|
159
167
|
clone(): Path {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {TokenType} from "../tokens/tokenType";
|
|
1
|
+
import { TokenType } from "../tokens/tokenType";
|
|
2
2
|
|
|
3
3
|
export const priority: Record<TokenType, number> = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
[TokenType.CONNECTOR]: 1,
|
|
5
|
+
[TokenType.NORMAL_TOKEN]: 2,
|
|
6
|
+
[TokenType.CURVE_LP]: 3,
|
|
7
|
+
[TokenType.YEARN_VAULT]: 3,
|
|
8
|
+
[TokenType.META_CURVE_LP]: 4,
|
|
9
|
+
[TokenType.YEARN_VAULT_OF_CURVE_LP]: 4,
|
|
10
|
+
[TokenType.CONVEX_LP_TOKEN]: 5,
|
|
11
|
+
[TokenType.YEARN_VAULT_OF_META_CURVE_LP]: 5,
|
|
12
|
+
[TokenType.CONVEX_STAKED_PHANTOM_TOKEN]: 5,
|
|
13
|
+
[TokenType.DIESEL_LP_TOKEN]: 6
|
|
14
14
|
};
|
package/src/pathfinder/trade.ts
CHANGED
|
@@ -1,83 +1,90 @@
|
|
|
1
|
-
import {BigNumber} from "ethers";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {SwapType} from "./tradeTypes";
|
|
1
|
+
import { BigNumber, BytesLike } from "ethers";
|
|
2
|
+
import { PERCENTAGE_FACTOR, WAD } from "../core/constants";
|
|
3
|
+
import { SwapType } from "./tradeTypes";
|
|
5
4
|
|
|
6
5
|
export interface CloseTradePath {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
path: Array<string>;
|
|
7
|
+
amountOutMin: BigNumber;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export class TradePath {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
11
|
+
public readonly swapType: SwapType;
|
|
12
|
+
|
|
13
|
+
public readonly amount: BigNumber;
|
|
14
|
+
|
|
15
|
+
public readonly rate: BigNumber;
|
|
16
|
+
|
|
17
|
+
public readonly path: Array<string>;
|
|
18
|
+
|
|
19
|
+
public readonly expectedAmount: BigNumber;
|
|
20
|
+
|
|
21
|
+
public readonly pathUniV3: BytesLike | undefined;
|
|
22
|
+
|
|
23
|
+
public readonly i: number | undefined;
|
|
24
|
+
|
|
25
|
+
public readonly j: number | undefined;
|
|
26
|
+
|
|
27
|
+
public readonly operationName: string | undefined;
|
|
28
|
+
|
|
29
|
+
constructor(params: {
|
|
30
|
+
swapType: SwapType;
|
|
31
|
+
amount: BigNumber;
|
|
32
|
+
path: Array<string>;
|
|
33
|
+
expectedAmount: BigNumber;
|
|
34
|
+
pathUniV3?: BytesLike;
|
|
35
|
+
i?: number;
|
|
36
|
+
j?: number;
|
|
37
|
+
operationName?: string;
|
|
38
|
+
}) {
|
|
39
|
+
this.swapType = params.swapType;
|
|
40
|
+
this.amount = params.amount;
|
|
41
|
+
this.path = params.path;
|
|
42
|
+
this.expectedAmount = params.expectedAmount;
|
|
43
|
+
this.pathUniV3 = params.pathUniV3;
|
|
44
|
+
this.rate =
|
|
45
|
+
params.swapType !== SwapType.ExactInput
|
|
46
|
+
? params.expectedAmount.mul(WAD).div(params.amount)
|
|
47
|
+
: WAD.mul(params.amount).div(params.expectedAmount);
|
|
48
|
+
this.i = params.i;
|
|
49
|
+
this.j = params.j;
|
|
50
|
+
this.operationName = params.operationName;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getExpectedAmountWithSlippage(slippage: number): BigNumber {
|
|
54
|
+
return this.swapType === SwapType.ExactInput
|
|
55
|
+
? this.getAmountOutMin(slippage)
|
|
56
|
+
: this.getAmountInMax(slippage);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getAmountInMax(slippage: number): BigNumber {
|
|
60
|
+
return this.expectedAmount
|
|
61
|
+
.mul(PERCENTAGE_FACTOR + slippage)
|
|
62
|
+
.div(PERCENTAGE_FACTOR);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getAmountOutMin(slippage: number): BigNumber {
|
|
66
|
+
return this.expectedAmount
|
|
67
|
+
.mul(PERCENTAGE_FACTOR)
|
|
68
|
+
.div(PERCENTAGE_FACTOR + slippage);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public get from(): string {
|
|
72
|
+
return this.path[0];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public get to(): string {
|
|
76
|
+
return this.path[this.path.length - 1];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getFromAmount(slippage: number): BigNumber {
|
|
80
|
+
return this.swapType === SwapType.ExactInput
|
|
81
|
+
? this.amount
|
|
82
|
+
: this.getExpectedAmountWithSlippage(slippage);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getToAmount(slippage: number): BigNumber {
|
|
86
|
+
return this.swapType === SwapType.ExactOutput
|
|
87
|
+
? this.amount
|
|
88
|
+
: this.getExpectedAmountWithSlippage(slippage);
|
|
89
|
+
}
|
|
83
90
|
}
|