@gearbox-protocol/sdk 2.1.34 → 3.0.0-next.2
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/apy/convexAPY.d.ts +4 -6
- package/lib/apy/convexAPY.js +15 -16
- package/lib/apy/curveAPY.d.ts +2 -2
- package/lib/apy/curveAPY.js +3 -4
- package/lib/apy/index.d.ts +1 -1
- package/lib/apy/index.js +2 -2
- package/lib/apy/lidoAPY.js +2 -2
- package/lib/apy/yearnAPY.d.ts +1 -1
- package/lib/apy/yearnAPY.js +3 -5
- package/lib/contracts/contractsRegister.d.ts +1 -1
- package/lib/contracts/contractsRegister.js +6 -7
- package/lib/core/creditAccount.js +20 -22
- package/lib/core/creditAccount.spec.js +32 -34
- package/lib/core/creditManager.js +16 -17
- package/lib/core/creditSession.js +12 -13
- package/lib/core/events.js +34 -35
- package/lib/core/pool/data.js +22 -23
- package/lib/core/priceOracle.js +3 -3
- package/lib/core/rewardClaimer.d.ts +1 -3
- package/lib/core/rewardConvex.d.ts +1 -4
- package/lib/core/rewardConvex.js +7 -10
- package/lib/core/rewardConvex.spec.js +15 -16
- package/lib/core/strategy.js +14 -16
- package/lib/core/strategy.spec.js +20 -22
- package/lib/core/trade.d.ts +1 -1
- package/lib/core/trade.js +12 -15
- package/lib/core/transactions.d.ts +1 -1
- package/lib/core/transactions.js +18 -20
- package/lib/index.d.ts +2 -20
- package/lib/index.js +27 -24
- package/lib/parsers/ERC20Parser.d.ts +1 -1
- package/lib/parsers/abstractParser.d.ts +1 -1
- package/lib/parsers/abstractParser.js +3 -4
- package/lib/parsers/convexBaseRewardPoolAdapterParser.d.ts +1 -1
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +2 -2
- package/lib/parsers/convexBaseRewardPoolAdapterParser.spec.js +4 -4
- package/lib/parsers/convexBoosterAdapterParser.d.ts +1 -1
- package/lib/parsers/convexBoosterAdapterParser.js +3 -3
- package/lib/parsers/convexBoosterAdapterParser.spec.js +3 -3
- package/lib/parsers/convextRewardPoolParser.d.ts +1 -1
- package/lib/parsers/creditFacadeParser.d.ts +1 -1
- package/lib/parsers/creditFacadeParser.spec.js +8 -9
- package/lib/parsers/curveAdapterParser.d.ts +1 -2
- package/lib/parsers/curveAdapterParser.js +5 -5
- package/lib/parsers/curveAdapterParser.spec.js +13 -13
- package/lib/parsers/lidoAdapterParser.d.ts +1 -1
- package/lib/parsers/lidoAdapterParser.spec.js +2 -2
- package/lib/parsers/lidoSTETHParser.d.ts +1 -1
- package/lib/parsers/txParser.d.ts +1 -3
- package/lib/parsers/txParser.js +12 -15
- package/lib/parsers/uniV2AdapterParser.d.ts +1 -1
- package/lib/parsers/uniV2AdapterParser.spec.js +15 -16
- package/lib/parsers/uniV3AdapterParser.d.ts +1 -1
- package/lib/parsers/uniV3AdapterParser.spec.js +15 -16
- package/lib/parsers/wstETHAdapterParser.d.ts +1 -1
- package/lib/parsers/wstETHAdapterParser.spec.js +3 -3
- package/lib/parsers/yearnAdapterParser.spec.js +12 -12
- package/lib/parsers/yearnV2AdapterParser.d.ts +1 -1
- package/lib/parsers/yearnV2AdapterParser.js +2 -2
- package/lib/pathfinder/pathOptions.d.ts +1 -2
- package/lib/pathfinder/pathOptions.js +12 -16
- package/lib/pathfinder/pathOptions.spec.js +36 -36
- package/lib/pathfinder/pathfinder.d.ts +1 -2
- package/lib/pathfinder/pathfinder.js +9 -10
- package/lib/pathfinder/pathfinder.spec.js +11 -12
- package/lib/payload/creditAccount.d.ts +1 -1
- package/lib/payload/creditManager.d.ts +1 -1
- package/lib/payload/pool.d.ts +1 -1
- package/lib/tokens/tokenData.d.ts +0 -4
- package/lib/tokens/tokenData.js +1 -16
- package/lib/utils/formatter.js +3 -3
- package/lib/utils/math.js +5 -5
- package/lib/utils/price.js +4 -4
- package/lib/watchers/creditAccountWatcher.js +2 -2
- package/lib/watchers/creditAccountWatcher.spec.js +18 -18
- package/lib/watchers/creditManagerWatcher.spec.js +19 -19
- package/package.json +2 -1
- package/lib/contracts/adapters.d.ts +0 -24
- package/lib/contracts/adapters.js +0 -28
- package/lib/contracts/contracts.d.ts +0 -112
- package/lib/contracts/contracts.js +0 -654
- package/lib/contracts/protocols.d.ts +0 -12
- package/lib/contracts/protocols.js +0 -16
- package/lib/contracts/utilsContracts.d.ts +0 -7
- package/lib/contracts/utilsContracts.js +0 -28
- package/lib/core/chains.d.ts +0 -23
- package/lib/core/chains.js +0 -63
- package/lib/core/constants.d.ts +0 -21
- package/lib/core/constants.js +0 -31
- package/lib/tokens/aave.d.ts +0 -20
- package/lib/tokens/aave.js +0 -62
- package/lib/tokens/balancer.d.ts +0 -12
- package/lib/tokens/balancer.js +0 -36
- package/lib/tokens/compound.d.ts +0 -11
- package/lib/tokens/compound.js +0 -38
- package/lib/tokens/convex.d.ts +0 -30
- package/lib/tokens/convex.js +0 -262
- package/lib/tokens/curveLP.d.ts +0 -27
- package/lib/tokens/curveLP.js +0 -141
- package/lib/tokens/decimals.d.ts +0 -2
- package/lib/tokens/decimals.js +0 -115
- package/lib/tokens/gear.d.ts +0 -14
- package/lib/tokens/gear.js +0 -47
- package/lib/tokens/normal.d.ts +0 -9
- package/lib/tokens/normal.js +0 -194
- package/lib/tokens/quoted.d.ts +0 -3
- package/lib/tokens/quoted.js +0 -7
- package/lib/tokens/token.d.ts +0 -25
- package/lib/tokens/token.js +0 -305
- package/lib/tokens/tokenType.d.ts +0 -15
- package/lib/tokens/tokenType.js +0 -19
- package/lib/tokens/tokens.spec.d.ts +0 -1
- package/lib/tokens/tokens.spec.js +0 -151
- package/lib/tokens/yearn.d.ts +0 -26
- package/lib/tokens/yearn.js +0 -52
- package/lib/utils/mappers.d.ts +0 -8
- package/lib/utils/mappers.js +0 -13
- package/lib/utils/multicall.d.ts +0 -36
- package/lib/utils/multicall.js +0 -90
- package/lib/utils/safeEnum.d.ts +0 -1
- package/lib/utils/safeEnum.js +0 -10
- package/lib/utils/types.d.ts +0 -10
- package/lib/utils/types.js +0 -2
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
3
4
|
const chai_1 = require("chai");
|
|
4
|
-
const token_1 = require("../tokens/token");
|
|
5
5
|
const pathOptions_1 = require("./pathOptions");
|
|
6
6
|
describe("PathOptionFactory test", () => {
|
|
7
7
|
it("next works correctly", () => {
|
|
8
8
|
const serie = [
|
|
9
9
|
{
|
|
10
|
-
target:
|
|
10
|
+
target: sdk_gov_1.tokenDataByNetwork.Mainnet["3Crv"],
|
|
11
11
|
option: 0,
|
|
12
12
|
totalOptions: 3,
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
target:
|
|
15
|
+
target: sdk_gov_1.tokenDataByNetwork.Mainnet.FRAX3CRV,
|
|
16
16
|
option: 0,
|
|
17
17
|
totalOptions: 2,
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
target:
|
|
20
|
+
target: sdk_gov_1.tokenDataByNetwork.Mainnet.LUSD3CRV,
|
|
21
21
|
option: 0,
|
|
22
22
|
totalOptions: 2,
|
|
23
23
|
},
|
|
@@ -57,26 +57,26 @@ describe("PathOptionFactory test", () => {
|
|
|
57
57
|
});
|
|
58
58
|
it("generatePathOptions works correctly", () => {
|
|
59
59
|
const balances = {
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
64
|
-
[
|
|
60
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
61
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["3Crv"]]: 200,
|
|
62
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
63
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.FRAX3CRV]: 200,
|
|
64
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.LUSD3CRV]: 200,
|
|
65
65
|
};
|
|
66
66
|
const result = pathOptions_1.PathOptionFactory.generatePathOptions(balances, 4);
|
|
67
67
|
const expected = [
|
|
68
68
|
{
|
|
69
|
-
target:
|
|
69
|
+
target: sdk_gov_1.tokenDataByNetwork.Mainnet["3Crv"],
|
|
70
70
|
option: 0,
|
|
71
71
|
totalOptions: 3,
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
|
-
target:
|
|
74
|
+
target: sdk_gov_1.tokenDataByNetwork.Mainnet.FRAX3CRV,
|
|
75
75
|
option: 0,
|
|
76
76
|
totalOptions: 2,
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
|
-
target:
|
|
79
|
+
target: sdk_gov_1.tokenDataByNetwork.Mainnet.LUSD3CRV,
|
|
80
80
|
option: 0,
|
|
81
81
|
totalOptions: 2,
|
|
82
82
|
},
|
|
@@ -88,11 +88,11 @@ describe("PathOptionFactory test", () => {
|
|
|
88
88
|
});
|
|
89
89
|
it(" getCurvePools works correctly", () => {
|
|
90
90
|
let balances = {
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
91
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
92
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["3Crv"]]: 200,
|
|
93
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
94
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.FRAX3CRV]: 200,
|
|
95
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.LUSD3CRV]: 200,
|
|
96
96
|
};
|
|
97
97
|
let expectedCurvePools = [
|
|
98
98
|
"3Crv",
|
|
@@ -101,41 +101,41 @@ describe("PathOptionFactory test", () => {
|
|
|
101
101
|
];
|
|
102
102
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
103
103
|
balances = {
|
|
104
|
-
[
|
|
105
|
-
[
|
|
106
|
-
[
|
|
107
|
-
[
|
|
108
|
-
[
|
|
104
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
105
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["3Crv"]]: 200,
|
|
106
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
107
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.yvCurve_FRAX]: 200,
|
|
108
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.yvCurve_stETH]: 200,
|
|
109
109
|
};
|
|
110
110
|
expectedCurvePools = ["3Crv", "FRAX3CRV", "steCRV"];
|
|
111
111
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
112
112
|
balances = {
|
|
113
|
-
[
|
|
114
|
-
[
|
|
115
|
-
[
|
|
116
|
-
[
|
|
113
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
114
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
115
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.cvx3Crv]: 200,
|
|
116
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.cvxFRAX3CRV]: 200,
|
|
117
117
|
};
|
|
118
118
|
expectedCurvePools = ["3Crv", "FRAX3CRV"];
|
|
119
119
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
120
120
|
balances = {
|
|
121
|
-
[
|
|
122
|
-
[
|
|
123
|
-
[
|
|
124
|
-
[
|
|
121
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.wstETH]: 100,
|
|
122
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
123
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.stkcvx3Crv]: 200,
|
|
124
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.stkcvxFRAX3CRV]: 200,
|
|
125
125
|
};
|
|
126
126
|
expectedCurvePools = ["3Crv", "FRAX3CRV"];
|
|
127
127
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
128
128
|
balances = {
|
|
129
|
-
[
|
|
130
|
-
[
|
|
131
|
-
[
|
|
132
|
-
[
|
|
133
|
-
[
|
|
129
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet["3Crv"]]: 100,
|
|
130
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
131
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.stkcvx3Crv]: 200,
|
|
132
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.cvx3Crv]: 200,
|
|
133
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.yvCurve_stETH]: 200,
|
|
134
134
|
};
|
|
135
135
|
expectedCurvePools = ["3Crv", "steCRV"];
|
|
136
136
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
137
137
|
});
|
|
138
138
|
it("detectNetwork works correctly", () => {
|
|
139
|
-
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.detectNetwork(
|
|
139
|
+
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.detectNetwork(sdk_gov_1.tokenDataByNetwork.Mainnet["1INCH"])).to.be.eq("Mainnet");
|
|
140
140
|
});
|
|
141
141
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { NetworkType, SupportedToken } from "@gearbox-protocol/sdk-gov";
|
|
1
2
|
import { BigNumberish, providers, Signer } from "ethers";
|
|
2
|
-
import { NetworkType } from "../core/chains";
|
|
3
3
|
import { CreditAccountData } from "../core/creditAccount";
|
|
4
4
|
import { CreditManagerData } from "../core/creditManager";
|
|
5
|
-
import { SupportedToken } from "../tokens/token";
|
|
6
5
|
import { IRouter } from "../types/@gearbox-protocol/router/contracts/interfaces/IRouter";
|
|
7
6
|
import { MultiCall, PathFinderCloseResult, PathFinderOpenStrategyResult, PathFinderResult, SwapOperation } from "./core";
|
|
8
7
|
export interface CloseResult {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PathFinder = void 0;
|
|
4
|
-
const
|
|
5
|
-
const token_1 = require("../tokens/token");
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
6
5
|
const types_1 = require("../types");
|
|
7
6
|
const formatter_1 = require("../utils/formatter");
|
|
8
7
|
const pathOptions_1 = require("./pathOptions");
|
|
@@ -22,7 +21,7 @@ class PathFinder {
|
|
|
22
21
|
this.pathFinder = types_1.IRouter__factory.connect(address, provider);
|
|
23
22
|
this.network = network;
|
|
24
23
|
this._connectors = connectors
|
|
25
|
-
.map(c =>
|
|
24
|
+
.map(c => sdk_gov_1.tokenDataByNetwork[this.network][c]?.toLowerCase())
|
|
26
25
|
.filter(t => !!t);
|
|
27
26
|
}
|
|
28
27
|
async findAllSwaps(creditAccount, swapOperation, tokenIn, tokenOut, amount, slippage) {
|
|
@@ -30,8 +29,8 @@ class PathFinder {
|
|
|
30
29
|
const swapTask = {
|
|
31
30
|
swapOperation: swapOperation,
|
|
32
31
|
creditAccount: creditAccount.addr,
|
|
33
|
-
tokenIn:
|
|
34
|
-
tokenOut:
|
|
32
|
+
tokenIn: sdk_gov_1.tokenDataByNetwork[this.network][tokenIn] || tokenIn,
|
|
33
|
+
tokenOut: sdk_gov_1.tokenDataByNetwork[this.network][tokenOut] ||
|
|
35
34
|
tokenOut,
|
|
36
35
|
connectors,
|
|
37
36
|
amount: amount,
|
|
@@ -54,9 +53,9 @@ class PathFinder {
|
|
|
54
53
|
return Object.values(unique);
|
|
55
54
|
}
|
|
56
55
|
async findOneTokenPath(creditAccount, tokenIn, tokenOut, amount, slippage) {
|
|
57
|
-
const tokenInAddr =
|
|
56
|
+
const tokenInAddr = sdk_gov_1.tokenDataByNetwork[this.network][tokenIn] || tokenIn;
|
|
58
57
|
const connectors = this.getAvailableConnectors(creditAccount.balances);
|
|
59
|
-
const result = await this.pathFinder.callStatic.findOneTokenPath(tokenInAddr, amount,
|
|
58
|
+
const result = await this.pathFinder.callStatic.findOneTokenPath(tokenInAddr, amount, sdk_gov_1.tokenDataByNetwork[this.network][tokenOut] || tokenOut, creditAccount.addr, connectors, slippage, {
|
|
60
59
|
gasLimit: GAS_PER_BLOCK,
|
|
61
60
|
});
|
|
62
61
|
return {
|
|
@@ -76,9 +75,9 @@ class PathFinder {
|
|
|
76
75
|
* @returns PathFinderOpenStrategyResult which
|
|
77
76
|
*/
|
|
78
77
|
async findOpenStrategyPath(cm, expectedBalances, target, slippage) {
|
|
79
|
-
const targetAddr =
|
|
78
|
+
const targetAddr = sdk_gov_1.tokenDataByNetwork[this.network][target] || target;
|
|
80
79
|
const expectedBalancesAddr = Object.entries(expectedBalances).reduce((acc, [token, balance]) => {
|
|
81
|
-
const tokenAddr =
|
|
80
|
+
const tokenAddr = sdk_gov_1.tokenDataByNetwork[this.network][token] || token;
|
|
82
81
|
acc[tokenAddr.toLowerCase()] = balance;
|
|
83
82
|
return acc;
|
|
84
83
|
}, {});
|
|
@@ -142,7 +141,7 @@ class PathFinder {
|
|
|
142
141
|
};
|
|
143
142
|
}
|
|
144
143
|
static compare(r1, r2, gasPriceRAY) {
|
|
145
|
-
const comparator = ({ amount, gasUsage }, gasPrice) => amount - (gasUsage * gasPrice) /
|
|
144
|
+
const comparator = ({ amount, gasUsage }, gasPrice) => amount - (gasUsage * gasPrice) / sdk_gov_1.RAY;
|
|
146
145
|
return comparator(r1, gasPriceRAY) > comparator(r2, gasPriceRAY) ? r1 : r2;
|
|
147
146
|
}
|
|
148
147
|
getAvailableConnectors(availableList) {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
3
4
|
const chai_1 = require("chai");
|
|
4
5
|
const ethers_1 = require("ethers");
|
|
5
|
-
const constants_1 = require("../core/constants");
|
|
6
|
-
const token_1 = require("../tokens/token");
|
|
7
6
|
const pathfinder_1 = require("./pathfinder");
|
|
8
7
|
describe("PathFinder test", () => {
|
|
9
8
|
it("compare works correctly", () => {
|
|
@@ -17,24 +16,24 @@ describe("PathFinder test", () => {
|
|
|
17
16
|
gasUsage: 2000n,
|
|
18
17
|
calls: [],
|
|
19
18
|
};
|
|
20
|
-
let result = pathfinder_1.PathFinder.compare(r1, r2,
|
|
19
|
+
let result = pathfinder_1.PathFinder.compare(r1, r2, sdk_gov_1.RAY);
|
|
21
20
|
(0, chai_1.expect)(result).to.be.eql(r2);
|
|
22
|
-
result = pathfinder_1.PathFinder.compare(r1, r2,
|
|
21
|
+
result = pathfinder_1.PathFinder.compare(r1, r2, sdk_gov_1.RAY * 2n);
|
|
23
22
|
(0, chai_1.expect)(result).to.be.eql(r1);
|
|
24
23
|
});
|
|
25
24
|
it("has all expected connectors", () => {
|
|
26
25
|
const pf = new pathfinder_1.PathFinder("", new ethers_1.providers.JsonRpcProvider(), "Mainnet");
|
|
27
26
|
const allowedTokens = {
|
|
28
|
-
[
|
|
29
|
-
[
|
|
30
|
-
[
|
|
31
|
-
[
|
|
27
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.USDC.toLowerCase()]: true,
|
|
28
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: true,
|
|
29
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: true,
|
|
30
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.FRAX.toLowerCase()]: true,
|
|
32
31
|
};
|
|
33
32
|
(0, chai_1.expect)(pf.getAvailableConnectors(allowedTokens)).to.be.deep.equal([
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.USDC.toLowerCase(),
|
|
34
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase(),
|
|
35
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase(),
|
|
36
|
+
sdk_gov_1.tokenDataByNetwork.Mainnet.FRAX.toLowerCase(),
|
|
38
37
|
]);
|
|
39
38
|
});
|
|
40
39
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { ExcludeArrayProps } from "@gearbox-protocol/sdk-gov";
|
|
1
2
|
import { CreditAccountDataStruct, CreditAccountDataStructOutput } from "../types/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
|
-
import { ExcludeArrayProps } from "../utils/types";
|
|
3
3
|
export type TokenBalancePayload = CreditAccountDataStruct["balances"];
|
|
4
4
|
export type CreditAccountDataPayload = ExcludeArrayProps<CreditAccountDataStructOutput>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { ExcludeArrayProps } from "@gearbox-protocol/sdk-gov";
|
|
1
2
|
import { BigNumberish } from "ethers";
|
|
2
3
|
import { ICreditFacade } from "../types";
|
|
3
4
|
import { CreditManagerDataStructOutput } from "../types/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
4
|
-
import { ExcludeArrayProps } from "../utils/types";
|
|
5
5
|
export interface AdapterPayload {
|
|
6
6
|
allowedContract: string;
|
|
7
7
|
adapter: string;
|
package/lib/payload/pool.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ExcludeArrayProps } from "@gearbox-protocol/sdk-gov";
|
|
1
2
|
import { BigNumberish } from "ethers";
|
|
2
3
|
import { PoolDataStruct } from "../types/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
3
|
-
import { ExcludeArrayProps } from "../utils/types";
|
|
4
4
|
export type PoolDataPayload = ExcludeArrayProps<PoolDataStruct>;
|
|
5
5
|
export interface ChartsPoolDataPayload {
|
|
6
6
|
addr: string;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { NetworkType } from "../core/chains";
|
|
2
1
|
import { TokenDataPayload } from "../payload/token";
|
|
3
|
-
import { SupportedToken } from "./token";
|
|
4
2
|
export declare class TokenData {
|
|
5
3
|
readonly id: string;
|
|
6
4
|
readonly symbol: string;
|
|
@@ -10,5 +8,3 @@ export declare class TokenData {
|
|
|
10
8
|
constructor(payload: TokenDataPayload, symbolReplacements?: Record<string, string>);
|
|
11
9
|
compareBySymbol(b: TokenData): number;
|
|
12
10
|
}
|
|
13
|
-
export declare const connectors: Record<NetworkType, Array<SupportedToken>>;
|
|
14
|
-
export declare function getConnectors(networkType: NetworkType): string[];
|
package/lib/tokens/tokenData.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TokenData = void 0;
|
|
4
4
|
const config_1 = require("../config");
|
|
5
|
-
const token_1 = require("./token");
|
|
6
5
|
class TokenData {
|
|
7
6
|
id;
|
|
8
7
|
symbol;
|
|
@@ -21,17 +20,3 @@ class TokenData {
|
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
exports.TokenData = TokenData;
|
|
24
|
-
exports.connectors = {
|
|
25
|
-
Mainnet: ["WETH", "DAI", "USDC", "FRAX"],
|
|
26
|
-
Arbitrum: ["WETH", "DAI", "USDC", "WBTC"],
|
|
27
|
-
};
|
|
28
|
-
function getConnectors(networkType) {
|
|
29
|
-
return exports.connectors[networkType].map(e => {
|
|
30
|
-
const result = token_1.tokenDataByNetwork[networkType][e];
|
|
31
|
-
if (!result) {
|
|
32
|
-
throw new Error(`connector token ${e} not found`);
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
exports.getConnectors = getConnectors;
|
package/lib/utils/formatter.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatDateTime = exports.formatLeverage = exports.formatPercentage = exports.formatDate = exports.shortHash = exports.shortAddress = exports.toBN = exports.toBigInt = exports.toSignificant = exports.toHumanFormat = exports.formatBn4dig = exports.formatBN = exports.formatRAY = exports.rayToNumber = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
5
|
const decimal_js_light_1 = require("decimal.js-light");
|
|
5
6
|
const moment_1 = require("moment");
|
|
6
|
-
const constants_1 = require("../core/constants");
|
|
7
7
|
function rayToNumber(num) {
|
|
8
8
|
return Number((0, exports.toBigInt)(num) / 10n ** 21n) / 1000000;
|
|
9
9
|
}
|
|
@@ -124,11 +124,11 @@ function formatDate(date) {
|
|
|
124
124
|
}
|
|
125
125
|
exports.formatDate = formatDate;
|
|
126
126
|
function formatPercentage(healthFactor, decimals = 2) {
|
|
127
|
-
return (healthFactor / Number(
|
|
127
|
+
return (healthFactor / Number(sdk_gov_1.PERCENTAGE_FACTOR)).toFixed(decimals);
|
|
128
128
|
}
|
|
129
129
|
exports.formatPercentage = formatPercentage;
|
|
130
130
|
function formatLeverage(leverage, decimals = 2) {
|
|
131
|
-
return (leverage / Number(
|
|
131
|
+
return (leverage / Number(sdk_gov_1.LEVERAGE_DECIMALS)).toFixed(decimals);
|
|
132
132
|
}
|
|
133
133
|
exports.formatLeverage = formatLeverage;
|
|
134
134
|
function formatDateTime(timestamp) {
|
package/lib/utils/math.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BigIntMath = exports.nonNegativeBn = exports.sqrt = exports.percentMul = exports.rayDiv = exports.rayMul = exports.revertRay = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
5
|
const ethers_1 = require("ethers");
|
|
5
|
-
const constants_1 = require("../core/constants");
|
|
6
6
|
function revertRay(num) {
|
|
7
7
|
if (!num)
|
|
8
8
|
return undefined;
|
|
9
|
-
return (
|
|
9
|
+
return (sdk_gov_1.RAY * sdk_gov_1.RAY) / num;
|
|
10
10
|
}
|
|
11
11
|
exports.revertRay = revertRay;
|
|
12
12
|
function rayMul(a, b) {
|
|
13
13
|
if (a === 0n || b === 0n)
|
|
14
14
|
return 0n;
|
|
15
|
-
return (a * b +
|
|
15
|
+
return (a * b + sdk_gov_1.halfRAY) / sdk_gov_1.RAY;
|
|
16
16
|
}
|
|
17
17
|
exports.rayMul = rayMul;
|
|
18
18
|
function rayDiv(a, b) {
|
|
19
19
|
const halfB = b / 2n;
|
|
20
|
-
return (a *
|
|
20
|
+
return (a * sdk_gov_1.RAY + halfB) / b;
|
|
21
21
|
}
|
|
22
22
|
exports.rayDiv = rayDiv;
|
|
23
23
|
function percentMul(a, b) {
|
|
24
24
|
if (a === 0n || b === 0)
|
|
25
25
|
return 0n;
|
|
26
|
-
return (a * BigInt(b) +
|
|
26
|
+
return (a * BigInt(b) + sdk_gov_1.PERCENTAGE_FACTOR / 2n) / sdk_gov_1.PERCENTAGE_FACTOR;
|
|
27
27
|
}
|
|
28
28
|
exports.percentMul = percentMul;
|
|
29
29
|
function sqrt(x) {
|
package/lib/utils/price.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PriceUtils = void 0;
|
|
4
|
-
const
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
5
|
class PriceUtils {
|
|
6
|
-
static calcTotalPrice = (price, amount, decimals = 18) => (amount *
|
|
6
|
+
static calcTotalPrice = (price, amount, decimals = 18) => (amount * sdk_gov_1.WAD * price) / 10n ** BigInt(decimals) / sdk_gov_1.PRICE_DECIMALS;
|
|
7
7
|
static convertByPrice(totalMoney, { price: targetPrice, decimals: targetDecimals = 18 }) {
|
|
8
8
|
if (targetPrice <= 0n)
|
|
9
9
|
return 0n;
|
|
10
|
-
return ((totalMoney * 10n ** BigInt(targetDecimals) *
|
|
10
|
+
return ((totalMoney * 10n ** BigInt(targetDecimals) * sdk_gov_1.PRICE_DECIMALS) /
|
|
11
11
|
targetPrice /
|
|
12
|
-
|
|
12
|
+
sdk_gov_1.WAD);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.PriceUtils = PriceUtils;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreditAccountWatcher = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
4
5
|
const creditAccount_1 = require("../core/creditAccount");
|
|
5
6
|
const types_1 = require("../types");
|
|
6
|
-
const multicall_1 = require("../utils/multicall");
|
|
7
7
|
class CreditAccountWatcher {
|
|
8
8
|
static IERC20 = types_1.IERC20__factory.createInterface();
|
|
9
9
|
static creditManagerInterface = types_1.ICreditManagerV2__factory.createInterface();
|
|
@@ -93,7 +93,7 @@ class CreditAccountWatcher {
|
|
|
93
93
|
else {
|
|
94
94
|
atBlock = options;
|
|
95
95
|
}
|
|
96
|
-
const dcmc = new
|
|
96
|
+
const dcmc = new sdk_gov_1.MultiCallContract(dataCompressor, types_1.IDataCompressor__factory.createInterface(), signer);
|
|
97
97
|
const calls = [];
|
|
98
98
|
for (let i = 0; i < accs.length; i++) {
|
|
99
99
|
const chunk = accs.slice(i * chunkSize, (i + 1) * chunkSize);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
3
4
|
const chai_1 = require("chai");
|
|
4
5
|
const ethers_1 = require("ethers");
|
|
5
|
-
const constants_1 = require("../core/constants");
|
|
6
6
|
const types_1 = require("../types");
|
|
7
7
|
const creditAccountWatcher_1 = require("./creditAccountWatcher");
|
|
8
|
-
const CREDIT_MANAGER_ADDRESS =
|
|
8
|
+
const CREDIT_MANAGER_ADDRESS = sdk_gov_1.DUMB_ADDRESS;
|
|
9
9
|
const CREDIT_FACADE_ADDRESS = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252c48";
|
|
10
10
|
const CREDIT_FACADE_NEW = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252ccc";
|
|
11
11
|
const CREDIT_CONFIGURATOR_ADDRESS = "0xcb9a588a47dd0393af3d0d5f86e6f1c8fd252aaa";
|
|
@@ -21,7 +21,7 @@ const cmDumb = {
|
|
|
21
21
|
creditConfigurator: CREDIT_CONFIGURATOR_ADDRESS.toLowerCase(),
|
|
22
22
|
};
|
|
23
23
|
const encode = (abiType, value) => ethers_1.utils.defaultAbiCoder.encode([abiType], [value]);
|
|
24
|
-
const makeLog = (address, topics, data =
|
|
24
|
+
const makeLog = (address, topics, data = sdk_gov_1.ADDRESS_0X0) => {
|
|
25
25
|
return {
|
|
26
26
|
blockNumber: 0,
|
|
27
27
|
blockHash: "",
|
|
@@ -37,13 +37,13 @@ const makeLog = (address, topics, data = constants_1.ADDRESS_0X0) => {
|
|
|
37
37
|
const openLog = (facadeAddr = CREDIT_FACADE_ADDRESS) => makeLog(facadeAddr, [
|
|
38
38
|
creditFacadeInterface.getEventTopic("OpenCreditAccount"),
|
|
39
39
|
encode("address", BORROWER),
|
|
40
|
-
encode("address",
|
|
40
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
41
41
|
], ethers_1.utils.defaultAbiCoder.encode(["uint256", "uint16"], [10, 10]));
|
|
42
42
|
const closeLog = (facadeAddr = CREDIT_FACADE_ADDRESS) => makeLog(facadeAddr, [
|
|
43
43
|
creditFacadeInterface.getEventTopic("CloseCreditAccount"),
|
|
44
44
|
encode("address", BORROWER),
|
|
45
|
-
encode("address",
|
|
46
|
-
encode("address",
|
|
45
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
46
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
47
47
|
]);
|
|
48
48
|
const upgradeFacadeLog = (configuratorAddr = CREDIT_CONFIGURATOR_NEW, facadeAddr = CREDIT_FACADE_NEW) => makeLog(configuratorAddr, [
|
|
49
49
|
creditConfiguratorInterface.getEventTopic("CreditFacadeUpgraded"),
|
|
@@ -78,7 +78,7 @@ describe("CreditAccountTracker test", () => {
|
|
|
78
78
|
log = makeLog(CREDIT_FACADE_ADDRESS, [
|
|
79
79
|
creditFacadeInterface.getEventTopic("AddCollateral"),
|
|
80
80
|
encode("address", BORROWER),
|
|
81
|
-
encode("address",
|
|
81
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
82
82
|
], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
|
|
83
83
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
|
|
84
84
|
updated: [expectedHash],
|
|
@@ -95,7 +95,7 @@ describe("CreditAccountTracker test", () => {
|
|
|
95
95
|
log = makeLog(CREDIT_FACADE_ADDRESS, [
|
|
96
96
|
creditFacadeInterface.getEventTopic("TokenEnabled"),
|
|
97
97
|
encode("address", BORROWER),
|
|
98
|
-
encode("address",
|
|
98
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
99
99
|
]);
|
|
100
100
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
|
|
101
101
|
updated: [expectedHash],
|
|
@@ -104,7 +104,7 @@ describe("CreditAccountTracker test", () => {
|
|
|
104
104
|
log = makeLog(CREDIT_FACADE_ADDRESS, [
|
|
105
105
|
creditFacadeInterface.getEventTopic("TokenDisabled"),
|
|
106
106
|
encode("address", BORROWER),
|
|
107
|
-
encode("address",
|
|
107
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
108
108
|
]);
|
|
109
109
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
|
|
110
110
|
updated: [expectedHash],
|
|
@@ -113,7 +113,7 @@ describe("CreditAccountTracker test", () => {
|
|
|
113
113
|
log = makeLog(CREDIT_MANAGER_ADDRESS, [
|
|
114
114
|
creditManagerInterface.getEventTopic("ExecuteOrder"),
|
|
115
115
|
encode("address", BORROWER),
|
|
116
|
-
encode("address",
|
|
116
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
117
117
|
]);
|
|
118
118
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
|
|
119
119
|
updated: [expectedHash],
|
|
@@ -131,9 +131,9 @@ describe("CreditAccountTracker test", () => {
|
|
|
131
131
|
let log = makeLog(CREDIT_FACADE_ADDRESS, [
|
|
132
132
|
creditFacadeInterface.getEventTopic("LiquidateCreditAccount"),
|
|
133
133
|
encode("address", BORROWER),
|
|
134
|
-
encode("address",
|
|
135
|
-
encode("address",
|
|
136
|
-
encode("address",
|
|
134
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
135
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
136
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
137
137
|
], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
|
|
138
138
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
|
|
139
139
|
updated: [],
|
|
@@ -142,9 +142,9 @@ describe("CreditAccountTracker test", () => {
|
|
|
142
142
|
log = makeLog(CREDIT_FACADE_ADDRESS, [
|
|
143
143
|
creditFacadeInterface.getEventTopic("LiquidateExpiredCreditAccount"),
|
|
144
144
|
encode("address", BORROWER),
|
|
145
|
-
encode("address",
|
|
146
|
-
encode("address",
|
|
147
|
-
encode("address",
|
|
145
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
146
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
147
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
148
148
|
], ethers_1.utils.defaultAbiCoder.encode(["uint256"], [10]));
|
|
149
149
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([log], [cmDumb])).to.be.eql({
|
|
150
150
|
updated: [],
|
|
@@ -175,11 +175,11 @@ describe("CreditAccountTracker test", () => {
|
|
|
175
175
|
const transferLog = makeLog(CREDIT_FACADE_ADDRESS, [
|
|
176
176
|
creditFacadeInterface.getEventTopic("TransferAccount"),
|
|
177
177
|
encode("address", BORROWER),
|
|
178
|
-
encode("address",
|
|
178
|
+
encode("address", sdk_gov_1.DUMB_ADDRESS),
|
|
179
179
|
]);
|
|
180
180
|
(0, chai_1.expect)(creditAccountWatcher_1.CreditAccountWatcher.detectChanges([openLog(), transferLog], [cmDumb])).to.be.eql({
|
|
181
181
|
updated: [
|
|
182
|
-
`${CREDIT_MANAGER_ADDRESS.toLowerCase()}:${
|
|
182
|
+
`${CREDIT_MANAGER_ADDRESS.toLowerCase()}:${sdk_gov_1.DUMB_ADDRESS.toLowerCase()}`,
|
|
183
183
|
],
|
|
184
184
|
deleted: [expectedHash],
|
|
185
185
|
});
|