@gearbox-protocol/sdk 0.0.100 → 0.0.103
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 +4 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.d.ts +8 -0
- package/lib/apy/convexAPY.js +200 -0
- package/lib/apy/lidoAPY.d.ts +4 -0
- package/lib/apy/lidoAPY.js +103 -0
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -1
- package/lib/contracts/contracts.d.ts +9 -4
- package/lib/contracts/contracts.js +52 -14
- package/lib/contracts/contractsRegister.js +16 -4
- package/lib/core/constants.d.ts +7 -1
- package/lib/core/constants.js +11 -5
- package/lib/core/creditAccount.d.ts +3 -1
- package/lib/core/creditAccount.js +33 -31
- package/lib/core/creditManager.d.ts +13 -2
- package/lib/core/creditManager.js +77 -33
- package/lib/core/creditSession.js +14 -3
- package/lib/core/errors.d.ts +10 -0
- package/lib/core/errors.js +16 -1
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +32 -30
- package/lib/core/multicall.d.ts +1 -1
- package/lib/core/pool.d.ts +2 -2
- package/lib/core/pool.js +8 -12
- package/lib/core/price.d.ts +2 -0
- package/lib/core/price.js +14 -0
- package/lib/core/strategy.d.ts +36 -0
- package/lib/core/strategy.js +57 -0
- 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 -3
- package/lib/index.js +9 -4
- 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 +22 -19
- package/lib/payload/creditAccount.d.ts +4 -26
- package/lib/payload/creditManager.d.ts +3 -25
- package/lib/payload/pool.d.ts +2 -17
- package/lib/payload/pool.js +0 -1
- package/lib/strategies/curve.d.ts +6 -60
- package/lib/strategies/curve.js +6 -0
- package/lib/strategies/uniswapV2.js +3 -19
- package/lib/strategies/uniswapV3.js +1 -1
- package/lib/strategies/yearn.js +15 -11
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +2 -2
- package/lib/tokens/curveLP.js +1 -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 +9 -9
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +3 -3
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +2 -1
- package/lib/utils/formatter.js +23 -15
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.d.ts +2 -1
- package/lib/utils/mappers.js +13 -5
- package/lib/utils/multicall.js +4 -3
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/types.d.ts +1 -0
- package/lib/utils/validate.js +1 -1
- package/package.json +26 -8
- package/src/apy/convexAPY.ts +250 -0
- package/src/apy/lidoAPY.ts +89 -0
- package/src/config.ts +2 -1
- package/src/contracts/contracts.ts +73 -19
- package/src/contracts/contractsRegister.ts +19 -4
- package/src/core/constants.ts +11 -4
- package/src/core/creditAccount.ts +69 -37
- package/src/core/creditManager.ts +256 -148
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +25 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +978 -911
- package/src/core/history.ts +46 -46
- package/src/core/multicall.ts +1 -1
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +75 -58
- package/src/core/price.ts +13 -0
- package/src/core/strategy.ts +134 -0
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +9 -4
- 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 +158 -150
- 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 +79 -63
- package/src/payload/creditAccount.ts +4 -26
- package/src/payload/creditManager.ts +4 -26
- package/src/payload/pool.ts +2 -19
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +217 -210
- package/src/strategies/creditFacade.ts +70 -53
- package/src/strategies/curve.ts +263 -194
- package/src/strategies/lido.ts +33 -37
- package/src/strategies/uniswapV2.ts +90 -112
- package/src/strategies/uniswapV3.ts +114 -91
- package/src/strategies/yearn.ts +58 -62
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +170 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +19 -10
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +126 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +26 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +15 -6
- package/src/utils/multicall.ts +6 -9
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/types.ts +6 -2
- package/src/utils/validate.ts +1 -1
- package/lib/core/adapters.d.ts +0 -15
- package/lib/core/adapters.js +0 -19
- package/lib/core/contracts.d.ts +0 -67
- package/lib/core/contracts.js +0 -254
- package/lib/core/contractsRegister.d.ts +0 -2
- package/lib/core/contractsRegister.js +0 -58
- package/lib/core/creditCard.d.ts +0 -13
- package/lib/core/creditCard.js +0 -2
- package/lib/core/oracles.d.ts +0 -38
- package/lib/core/oracles.js +0 -12
- package/lib/core/priceFeeds.d.ts +0 -3
- package/lib/core/priceFeeds.js +0 -492
- package/lib/core/protocols.d.ts +0 -13
- package/lib/core/protocols.js +0 -39
- package/lib/core/swap.d.ts +0 -4
- package/lib/core/swap.js +0 -8
- package/lib/core/trade.d.ts +0 -35
- package/lib/core/trade.js +0 -62
- package/lib/core/tradeTypes.d.ts +0 -79
- package/lib/core/tradeTypes.js +0 -21
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/core/history.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
|
|
3
3
|
export type BasicEvent = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
protocol: string; // address of creditManager. Address of target account for EXECUTE event
|
|
5
|
+
txHash: string;
|
|
6
|
+
timestamp: number; // timestamp in Unix format
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export type BasicSwapEvent = BasicEvent & {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
from: string; // address
|
|
11
|
+
fromAmount: BigNumber;
|
|
12
|
+
to: string; // address
|
|
13
|
+
toAmount: BigNumber;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type HistoryEvent =
|
|
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
|
-
});
|
|
17
|
+
| (BasicEvent & {
|
|
18
|
+
action: "OpenCreditAccount";
|
|
19
|
+
initialFunds: BigNumber;
|
|
20
|
+
leverage: number; // x100, so 420 => 4.2
|
|
21
|
+
})
|
|
22
|
+
| (BasicEvent & {
|
|
23
|
+
action: "CloseCreditAccount";
|
|
24
|
+
remainingFunds: BigNumber;
|
|
25
|
+
})
|
|
26
|
+
| (BasicEvent & {
|
|
27
|
+
action: "LiquidateCreditAccount";
|
|
28
|
+
remainingFunds: BigNumber;
|
|
29
|
+
})
|
|
30
|
+
| (BasicEvent & {
|
|
31
|
+
action: "IncreaseBorrowedAmount";
|
|
32
|
+
amount: BigNumber;
|
|
33
|
+
})
|
|
34
|
+
| (BasicEvent & {
|
|
35
|
+
action: "AddCollateral";
|
|
36
|
+
token: string; // token address
|
|
37
|
+
amount: BigNumber;
|
|
38
|
+
})
|
|
39
|
+
| (BasicEvent & {
|
|
40
|
+
action: "RepayCreditAccount";
|
|
41
|
+
repayAmount: BigNumber;
|
|
42
|
+
})
|
|
43
|
+
| (BasicEvent & {
|
|
44
|
+
action: "TransferAccount";
|
|
45
|
+
newAccount: string; // Address
|
|
46
|
+
})
|
|
47
|
+
| (BasicSwapEvent & {
|
|
48
|
+
action: "Swap";
|
|
49
|
+
})
|
|
50
|
+
| (BasicSwapEvent & {
|
|
51
|
+
action: "Deposit";
|
|
52
|
+
})
|
|
53
|
+
| (BasicSwapEvent & {
|
|
54
|
+
action: "Withdraw";
|
|
55
|
+
});
|
package/src/core/multicall.ts
CHANGED
package/src/core/operations.ts
CHANGED
|
@@ -2,11 +2,17 @@ import moment from "moment";
|
|
|
2
2
|
|
|
3
3
|
export class OperationData {
|
|
4
4
|
public readonly id: number;
|
|
5
|
+
|
|
5
6
|
public readonly address: string;
|
|
7
|
+
|
|
6
8
|
public readonly txHash: string;
|
|
9
|
+
|
|
7
10
|
public readonly blockNum: number;
|
|
11
|
+
|
|
8
12
|
public readonly operation: string;
|
|
13
|
+
|
|
9
14
|
public readonly timestamp: number;
|
|
15
|
+
|
|
10
16
|
public readonly date: string;
|
|
11
17
|
|
|
12
18
|
constructor(payload: OperationDataPayload) {
|
package/src/core/pool.ts
CHANGED
|
@@ -1,64 +1,81 @@
|
|
|
1
|
-
import {BigNumber, Signer} from "ethers";
|
|
2
|
-
|
|
3
|
-
import {PoolDataPayload} from "../payload/pool";
|
|
4
|
-
import {rayToNumber} from "../utils/formatter";
|
|
1
|
+
import { BigNumber, Signer } from "ethers";
|
|
2
|
+
|
|
3
|
+
import { PoolDataPayload } from "../payload/pool";
|
|
4
|
+
import { rayToNumber } from "../utils/formatter";
|
|
5
|
+
|
|
6
|
+
import { IPoolService, IPoolService__factory } from "../types";
|
|
7
|
+
|
|
8
|
+
import { PERCENTAGE_DECIMALS } from "./constants";
|
|
5
9
|
|
|
6
10
|
export class PoolData {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
11
|
+
public readonly id: string;
|
|
12
|
+
|
|
13
|
+
public readonly address: string;
|
|
14
|
+
|
|
15
|
+
public readonly underlyingToken: string;
|
|
16
|
+
|
|
17
|
+
public readonly dieselToken: string;
|
|
18
|
+
|
|
19
|
+
public readonly isWETH: boolean;
|
|
20
|
+
|
|
21
|
+
// Information
|
|
22
|
+
public readonly expectedLiquidity: BigNumber;
|
|
23
|
+
|
|
24
|
+
public readonly expectedLiquidityLimit: BigNumber;
|
|
25
|
+
|
|
26
|
+
public readonly availableLiquidity: BigNumber;
|
|
27
|
+
|
|
28
|
+
public readonly totalBorrowed: BigNumber;
|
|
29
|
+
|
|
30
|
+
public readonly depositAPY: number;
|
|
31
|
+
|
|
32
|
+
public readonly borrowAPY: number;
|
|
33
|
+
|
|
34
|
+
public readonly borrowAPYRay: BigNumber;
|
|
35
|
+
|
|
36
|
+
public readonly dieselRate: number;
|
|
37
|
+
|
|
38
|
+
public readonly dieselRateRay: BigNumber;
|
|
39
|
+
|
|
40
|
+
public readonly withdrawFee: number;
|
|
41
|
+
|
|
42
|
+
public readonly timestampLU: BigNumber;
|
|
43
|
+
|
|
44
|
+
public readonly cumulativeIndex_RAY: BigNumber;
|
|
45
|
+
|
|
46
|
+
public readonly isPaused: boolean = false;
|
|
47
|
+
|
|
48
|
+
constructor(payload: PoolDataPayload) {
|
|
49
|
+
this.id = payload.addr;
|
|
50
|
+
this.address = payload.addr;
|
|
51
|
+
this.underlyingToken = payload.underlying || "";
|
|
52
|
+
this.dieselToken = payload.dieselToken || "";
|
|
53
|
+
|
|
54
|
+
this.isWETH = payload.isWETH || false;
|
|
55
|
+
|
|
56
|
+
this.expectedLiquidity = BigNumber.from(payload.expectedLiquidity);
|
|
57
|
+
this.expectedLiquidityLimit = BigNumber.from(
|
|
58
|
+
payload.expectedLiquidityLimit || 0
|
|
59
|
+
);
|
|
60
|
+
this.availableLiquidity = BigNumber.from(payload.availableLiquidity);
|
|
61
|
+
this.totalBorrowed = BigNumber.from(payload.totalBorrowed);
|
|
62
|
+
this.depositAPY = rayToNumber(payload.depositAPY_RAY) * PERCENTAGE_DECIMALS;
|
|
63
|
+
this.borrowAPY = rayToNumber(payload.borrowAPY_RAY) * PERCENTAGE_DECIMALS;
|
|
64
|
+
this.borrowAPYRay = BigNumber.from(payload.borrowAPY_RAY);
|
|
65
|
+
this.dieselRate = rayToNumber(payload.dieselRate_RAY);
|
|
66
|
+
this.dieselRateRay = BigNumber.from(payload.dieselRate_RAY);
|
|
67
|
+
this.withdrawFee =
|
|
68
|
+
BigNumber.from(payload.withdrawFee).toNumber() / PERCENTAGE_DECIMALS;
|
|
69
|
+
this.timestampLU = BigNumber.from(payload.timestampLU || 0);
|
|
70
|
+
this.cumulativeIndex_RAY = BigNumber.from(payload.cumulativeIndex_RAY || 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
getContractETH(signer: Signer): IPoolService {
|
|
74
|
+
return IPoolService__factory.connect(this.address, signer);
|
|
75
|
+
}
|
|
59
76
|
}
|
|
60
77
|
|
|
61
78
|
export interface PoolsStat {
|
|
62
|
-
|
|
63
|
-
|
|
79
|
+
tvl: number;
|
|
80
|
+
totalBorrowed: number;
|
|
64
81
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { WAD, PRICE_DECIMALS } from "./constants";
|
|
3
|
+
|
|
4
|
+
export const calcTotalPrice = (
|
|
5
|
+
price: BigNumber,
|
|
6
|
+
amount: BigNumber,
|
|
7
|
+
decimals: number = 18
|
|
8
|
+
) =>
|
|
9
|
+
amount
|
|
10
|
+
.mul(WAD)
|
|
11
|
+
.mul(price)
|
|
12
|
+
.div(BigNumber.from(10).pow(decimals))
|
|
13
|
+
.div(PRICE_DECIMALS);
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "./constants";
|
|
3
|
+
import { calcTotalPrice } from "./price";
|
|
4
|
+
|
|
5
|
+
export interface StrategyPayload {
|
|
6
|
+
apy?: number;
|
|
7
|
+
|
|
8
|
+
name: string;
|
|
9
|
+
lpToken: string;
|
|
10
|
+
pools: Array<string>;
|
|
11
|
+
|
|
12
|
+
unleveragableCollateral: Array<string>;
|
|
13
|
+
leveragableCollateral: Array<string>;
|
|
14
|
+
|
|
15
|
+
baseAssets: Array<string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface PoolStats {
|
|
19
|
+
borrowRate: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type PoolList = Record<string, PoolStats>;
|
|
23
|
+
|
|
24
|
+
interface TokenDescription {
|
|
25
|
+
price: BigNumber;
|
|
26
|
+
amount: BigNumber;
|
|
27
|
+
decimals: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class Strategy {
|
|
31
|
+
apy: number | undefined;
|
|
32
|
+
|
|
33
|
+
name: string;
|
|
34
|
+
|
|
35
|
+
lpToken: string;
|
|
36
|
+
|
|
37
|
+
pools: Array<string>;
|
|
38
|
+
|
|
39
|
+
unleveragableCollateral: Array<string>;
|
|
40
|
+
|
|
41
|
+
leveragableCollateral: Array<string>;
|
|
42
|
+
|
|
43
|
+
baseAssets: Array<string>;
|
|
44
|
+
|
|
45
|
+
constructor(payload: StrategyPayload) {
|
|
46
|
+
this.apy = payload.apy;
|
|
47
|
+
|
|
48
|
+
this.name = payload.name;
|
|
49
|
+
this.lpToken = payload.lpToken;
|
|
50
|
+
this.pools = payload.pools;
|
|
51
|
+
this.unleveragableCollateral = payload.unleveragableCollateral;
|
|
52
|
+
this.leveragableCollateral = payload.leveragableCollateral;
|
|
53
|
+
this.baseAssets = payload.baseAssets;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public maxAPY(maxLeverage: number, poolApy: PoolList) {
|
|
57
|
+
const minApy = minBorrowApy(poolApy);
|
|
58
|
+
|
|
59
|
+
return roi(
|
|
60
|
+
this.apy || 0,
|
|
61
|
+
maxLeverage,
|
|
62
|
+
maxLeverage - LEVERAGE_DECIMALS,
|
|
63
|
+
minApy
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public overallAPY(
|
|
68
|
+
apy: number,
|
|
69
|
+
leverage: number,
|
|
70
|
+
depositCollateral: string,
|
|
71
|
+
borrowAPY: number
|
|
72
|
+
) {
|
|
73
|
+
const farmLev = this.farmLev(leverage, depositCollateral);
|
|
74
|
+
|
|
75
|
+
return roi(apy, farmLev, leverage - LEVERAGE_DECIMALS, borrowAPY);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// eslint-disable-next-line class-methods-use-this
|
|
79
|
+
public liquidationPrice(
|
|
80
|
+
borrowed: TokenDescription,
|
|
81
|
+
collateral: TokenDescription,
|
|
82
|
+
lp: TokenDescription,
|
|
83
|
+
ltCollateral: BigNumber
|
|
84
|
+
) {
|
|
85
|
+
const borrowedMoney = calcTotalPrice(
|
|
86
|
+
borrowed.price,
|
|
87
|
+
borrowed.amount,
|
|
88
|
+
borrowed.decimals
|
|
89
|
+
);
|
|
90
|
+
const collateralMoney = calcTotalPrice(
|
|
91
|
+
collateral.price,
|
|
92
|
+
collateral.amount,
|
|
93
|
+
collateral.decimals
|
|
94
|
+
)
|
|
95
|
+
.mul(ltCollateral)
|
|
96
|
+
.div(PERCENTAGE_FACTOR);
|
|
97
|
+
const lpMoney = calcTotalPrice(lp.price, lp.amount, lp.decimals);
|
|
98
|
+
|
|
99
|
+
return lpMoney.gt(0)
|
|
100
|
+
? borrowedMoney.sub(collateralMoney).mul(WAD).div(lpMoney)
|
|
101
|
+
: BigNumber.from(0);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private farmLev(leverage: number, depositCollateral: string) {
|
|
105
|
+
return this.inBaseAssets(depositCollateral) ||
|
|
106
|
+
this.inLeveragableAssets(depositCollateral)
|
|
107
|
+
? leverage
|
|
108
|
+
: leverage - LEVERAGE_DECIMALS;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private inBaseAssets(depositCollateral: string) {
|
|
112
|
+
return this.baseAssets.some(
|
|
113
|
+
c => c.toLowerCase() === depositCollateral.toLowerCase()
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private inLeveragableAssets(depositCollateral: string) {
|
|
118
|
+
return this.leveragableCollateral.some(
|
|
119
|
+
c => c.toLowerCase() === depositCollateral.toLowerCase()
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function roi(apy: number, farmLev: number, debtLev: number, borrowAPY: number) {
|
|
125
|
+
return (apy * farmLev - borrowAPY * debtLev) / LEVERAGE_DECIMALS;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function minBorrowApy(poolApy: PoolList) {
|
|
129
|
+
const apys = Object.values(poolApy).sort(
|
|
130
|
+
(a, b) => a.borrowRate - b.borrowRate
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
134
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BigNumber} from "ethers";
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
2
|
|
|
3
3
|
export interface TokenShare {
|
|
4
4
|
holder: string;
|
|
@@ -10,5 +10,5 @@ export interface TokenShare {
|
|
|
10
10
|
export enum VotingPower {
|
|
11
11
|
A, // A-type voting power & A-type vesting parameters
|
|
12
12
|
B, // B-type voting power & B-type vesting parameters
|
|
13
|
-
ZERO_VOTING_POWER
|
|
13
|
+
ZERO_VOTING_POWER // zero voting power & B-type vesting parameters
|
|
14
14
|
}
|