@gearbox-protocol/sdk 2.1.25 → 2.1.27
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/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/package.json +1 -1
- package/contracts/AdapterData.sol +0 -322
- package/contracts/AdapterType.sol +0 -29
- package/contracts/ContractType.sol +0 -68
- package/contracts/NetworkDetector.sol +0 -61
- package/contracts/PriceFeedDataLive.sol +0 -1227
- package/contracts/PriceFeedType.sol +0 -26
- package/contracts/SupportedContracts.sol +0 -423
- package/contracts/Tokens.sol +0 -135
- package/contracts/TokensData.sol +0 -1076
- package/contracts/TokensLib.sol +0 -34
- package/lib/oracles/priceFeeds.d.ts +0 -4
- package/lib/oracles/priceFeeds.js +0 -828
- package/lib/oracles/priceFeeds.spec.d.ts +0 -1
- package/lib/oracles/priceFeeds.spec.js +0 -134
- package/lib/oracles/pricefeedType.d.ts +0 -95
- package/lib/oracles/pricefeedType.js +0 -27
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const ethers_1 = require("ethers");
|
|
5
|
-
const chains_1 = require("../core/chains");
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
const formatter_1 = require("../utils/formatter");
|
|
8
|
-
const multicall_1 = require("../utils/multicall");
|
|
9
|
-
const priceFeeds_1 = require("./priceFeeds");
|
|
10
|
-
const pricefeedType_1 = require("./pricefeedType");
|
|
11
|
-
const iFeed = types_1.AggregatorV3Interface__factory.createInterface();
|
|
12
|
-
class PriceFeedsSuite {
|
|
13
|
-
networkTypes;
|
|
14
|
-
calls;
|
|
15
|
-
constructor(...networkTypes) {
|
|
16
|
-
this.networkTypes = networkTypes;
|
|
17
|
-
this.calls = networkTypes.map(c => this.collectCalls(c));
|
|
18
|
-
}
|
|
19
|
-
async getAnswers() {
|
|
20
|
-
const providers = this.networkTypes.map(c => {
|
|
21
|
-
const url = process.env[`${c.toUpperCase()}_TESTS_FORK`];
|
|
22
|
-
if (!url) {
|
|
23
|
-
throw new Error(`Provider for ${c} not found in env`);
|
|
24
|
-
}
|
|
25
|
-
return new ethers_1.ethers.providers.StaticJsonRpcProvider(url, chains_1.CHAINS[c]);
|
|
26
|
-
});
|
|
27
|
-
const resps = await Promise.all(this.networkTypes.map((_, i) => (0, multicall_1.safeMulticall)(this.calls[i], providers[i])));
|
|
28
|
-
return resps.map((_, i) => this.buildDict(this.calls[i], resps[i]));
|
|
29
|
-
}
|
|
30
|
-
collectCalls(c) {
|
|
31
|
-
const calls = [];
|
|
32
|
-
for (const [symb, data] of Object.entries(priceFeeds_1.priceFeedsByToken)) {
|
|
33
|
-
calls.push(...this.getCallsForToken(c, symb, data));
|
|
34
|
-
}
|
|
35
|
-
return calls;
|
|
36
|
-
}
|
|
37
|
-
getCallsForToken(network, token, data) {
|
|
38
|
-
const calls = [];
|
|
39
|
-
switch (data.type) {
|
|
40
|
-
case pricefeedType_1.PriceFeedType.NETWORK_DEPENDENT:
|
|
41
|
-
calls.push(...this.getCallsForToken(network, token, data.feeds[network]));
|
|
42
|
-
break;
|
|
43
|
-
case pricefeedType_1.PriceFeedType.CHAINLINK_ORACLE:
|
|
44
|
-
if (data.address.startsWith("0x")) {
|
|
45
|
-
calls.push({
|
|
46
|
-
address: data.address,
|
|
47
|
-
interface: iFeed,
|
|
48
|
-
method: "latestRoundData()",
|
|
49
|
-
key: token,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
break;
|
|
53
|
-
case pricefeedType_1.PriceFeedType.BOUNDED_ORACLE:
|
|
54
|
-
if (data.priceFeed.startsWith("0x")) {
|
|
55
|
-
calls.push({
|
|
56
|
-
address: data.priceFeed,
|
|
57
|
-
interface: iFeed,
|
|
58
|
-
method: "latestRoundData()",
|
|
59
|
-
key: token,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
break;
|
|
63
|
-
case pricefeedType_1.PriceFeedType.COMPOSITE_ORACLE:
|
|
64
|
-
if (data.baseToUsdPriceFeed.startsWith("0x")) {
|
|
65
|
-
calls.push({
|
|
66
|
-
address: data.baseToUsdPriceFeed,
|
|
67
|
-
interface: iFeed,
|
|
68
|
-
method: "latestRoundData()",
|
|
69
|
-
key: `${token}.baseToUsdPriceFeed`,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
if (data.targetToBasePriceFeed.startsWith("0x")) {
|
|
73
|
-
calls.push({
|
|
74
|
-
address: data.targetToBasePriceFeed,
|
|
75
|
-
interface: iFeed,
|
|
76
|
-
method: "latestRoundData()",
|
|
77
|
-
key: `${token}.targetToBasePriceFeed`,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
return calls;
|
|
83
|
-
}
|
|
84
|
-
buildDict(calls, responses) {
|
|
85
|
-
return calls.reduce((acc, call, i) => ({
|
|
86
|
-
...acc,
|
|
87
|
-
[call.key]: responses[i],
|
|
88
|
-
}), {});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
describe("Price feeds", () => {
|
|
92
|
-
const suite = new PriceFeedsSuite("Mainnet", "Arbitrum");
|
|
93
|
-
const PERCENTAGE_FACTOR = 1_00_00;
|
|
94
|
-
const THRESHOLD = 100; // 1%
|
|
95
|
-
let answers = [];
|
|
96
|
-
before(async function () {
|
|
97
|
-
this.timeout(10000);
|
|
98
|
-
answers = await suite.getAnswers();
|
|
99
|
-
});
|
|
100
|
-
describe(`should not deviate for more than ${(100 * THRESHOLD) / PERCENTAGE_FACTOR}% from mainnet`, () => {
|
|
101
|
-
// have to use suite.calls here, because answers are empty atm
|
|
102
|
-
// this is how mocha works, it builds test tree before execution
|
|
103
|
-
const [_, ...chainCalls] = suite.calls;
|
|
104
|
-
for (let i = 0; i < chainCalls.length; i++) {
|
|
105
|
-
const calls = chainCalls[i];
|
|
106
|
-
const chain = suite.networkTypes[i + 1];
|
|
107
|
-
for (const call of calls) {
|
|
108
|
-
it(`${chain}.${call.key} deviation`, () => {
|
|
109
|
-
const mainDict = answers[0];
|
|
110
|
-
const chainDict = answers[i + 1];
|
|
111
|
-
const chainPrice = chainDict[call.key].value?.answer;
|
|
112
|
-
const mainPrice = mainDict[call.key]?.value?.answer;
|
|
113
|
-
if (!mainPrice) {
|
|
114
|
-
// some tokens do not exist on mainnet
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
const deviation = chainPrice
|
|
118
|
-
?.sub(mainPrice)
|
|
119
|
-
.mul(PERCENTAGE_FACTOR)
|
|
120
|
-
.div(mainPrice)
|
|
121
|
-
.abs()
|
|
122
|
-
.toNumber();
|
|
123
|
-
// console.log(
|
|
124
|
-
// call.key,
|
|
125
|
-
// deviation,
|
|
126
|
-
// chainPrice?.toNumber(),
|
|
127
|
-
// mainPrice.toNumber(),
|
|
128
|
-
// );
|
|
129
|
-
(0, chai_1.expect)(deviation, `Mainnet price: ${(0, formatter_1.formatBN)(mainPrice, 8)}$, ${chain} price: ${(0, formatter_1.formatBN)(chainPrice, 8)}$ at ${call.address}`).to.be.below(THRESHOLD);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { CurvePoolContract } from "../contracts/contracts";
|
|
2
|
-
import { NetworkType } from "../core/chains";
|
|
3
|
-
import { AaveV2LPToken } from "../tokens/aave";
|
|
4
|
-
import { NormalToken } from "../tokens/normal";
|
|
5
|
-
import { SupportedToken } from "../tokens/token";
|
|
6
|
-
export interface PriceFeed {
|
|
7
|
-
token: string;
|
|
8
|
-
priceFeed: string;
|
|
9
|
-
}
|
|
10
|
-
export declare enum PriceFeedType {
|
|
11
|
-
CHAINLINK_ORACLE = 0,
|
|
12
|
-
YEARN_ORACLE = 1,
|
|
13
|
-
CURVE_2LP_ORACLE = 2,
|
|
14
|
-
CURVE_3LP_ORACLE = 3,
|
|
15
|
-
CURVE_4LP_ORACLE = 4,
|
|
16
|
-
ZERO_ORACLE = 5,
|
|
17
|
-
WSTETH_ORACLE = 6,
|
|
18
|
-
BOUNDED_ORACLE = 7,
|
|
19
|
-
COMPOSITE_ORACLE = 8,
|
|
20
|
-
WRAPPED_AAVE_V2_ORACLE = 9,
|
|
21
|
-
COMPOUND_V2_ORACLE = 10,
|
|
22
|
-
BALANCER_STABLE_LP_ORACLE = 11,
|
|
23
|
-
BALANCER_WEIGHTED_LP_ORACLE = 12,
|
|
24
|
-
CURVE_CRYPTO_ORACLE = 13,
|
|
25
|
-
THE_SAME_AS = 14,
|
|
26
|
-
REDSTONE_ORACLE = 15,
|
|
27
|
-
ERC4626_VAULT_ORACLE = 16,
|
|
28
|
-
NETWORK_DEPENDENT = 17,
|
|
29
|
-
CURVE_USD_ORACLE = 18
|
|
30
|
-
}
|
|
31
|
-
export declare const HOUR_1: number;
|
|
32
|
-
export declare const HOUR_24: number;
|
|
33
|
-
export type PriceFeedData = {
|
|
34
|
-
type: PriceFeedType.CHAINLINK_ORACLE;
|
|
35
|
-
address: string;
|
|
36
|
-
stalenessPeriod?: number;
|
|
37
|
-
} | {
|
|
38
|
-
type: PriceFeedType.YEARN_ORACLE;
|
|
39
|
-
token: SupportedToken;
|
|
40
|
-
} | {
|
|
41
|
-
type: PriceFeedType.CURVE_2LP_ORACLE;
|
|
42
|
-
assets: Array<SupportedToken>;
|
|
43
|
-
} | {
|
|
44
|
-
type: PriceFeedType.CURVE_3LP_ORACLE;
|
|
45
|
-
assets: Array<SupportedToken>;
|
|
46
|
-
} | {
|
|
47
|
-
type: PriceFeedType.CURVE_4LP_ORACLE;
|
|
48
|
-
assets: Array<SupportedToken>;
|
|
49
|
-
} | {
|
|
50
|
-
type: PriceFeedType.ZERO_ORACLE;
|
|
51
|
-
} | {
|
|
52
|
-
type: PriceFeedType.BOUNDED_ORACLE;
|
|
53
|
-
priceFeed: string;
|
|
54
|
-
stalenessPeriod?: number;
|
|
55
|
-
upperBound: bigint;
|
|
56
|
-
} | {
|
|
57
|
-
type: PriceFeedType.WSTETH_ORACLE;
|
|
58
|
-
token: SupportedToken;
|
|
59
|
-
} | {
|
|
60
|
-
type: PriceFeedType.COMPOSITE_ORACLE;
|
|
61
|
-
targetToBasePriceFeed: string;
|
|
62
|
-
targetStalenessPeriod?: number;
|
|
63
|
-
baseToUsdPriceFeed: string;
|
|
64
|
-
baseStalenessPeriod?: number;
|
|
65
|
-
} | {
|
|
66
|
-
type: PriceFeedType.CURVE_CRYPTO_ORACLE;
|
|
67
|
-
assets: Array<SupportedToken>;
|
|
68
|
-
} | {
|
|
69
|
-
type: PriceFeedType.BALANCER_WEIGHTED_LP_ORACLE;
|
|
70
|
-
assets: Array<SupportedToken>;
|
|
71
|
-
} | {
|
|
72
|
-
type: PriceFeedType.THE_SAME_AS;
|
|
73
|
-
token: SupportedToken;
|
|
74
|
-
} | {
|
|
75
|
-
type: PriceFeedType.WRAPPED_AAVE_V2_ORACLE;
|
|
76
|
-
underlying: AaveV2LPToken;
|
|
77
|
-
} | {
|
|
78
|
-
type: PriceFeedType.COMPOUND_V2_ORACLE;
|
|
79
|
-
underlying: NormalToken;
|
|
80
|
-
} | {
|
|
81
|
-
type: PriceFeedType.ERC4626_VAULT_ORACLE;
|
|
82
|
-
underlying: NormalToken;
|
|
83
|
-
} | {
|
|
84
|
-
type: PriceFeedType.REDSTONE_ORACLE;
|
|
85
|
-
dataId: string;
|
|
86
|
-
signers: Array<string>;
|
|
87
|
-
signersThreshold: number;
|
|
88
|
-
} | {
|
|
89
|
-
type: PriceFeedType.NETWORK_DEPENDENT;
|
|
90
|
-
feeds: Record<NetworkType, PriceFeedData>;
|
|
91
|
-
} | {
|
|
92
|
-
type: PriceFeedType.CURVE_USD_ORACLE;
|
|
93
|
-
pool: CurvePoolContract;
|
|
94
|
-
underlying: NormalToken;
|
|
95
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HOUR_24 = exports.HOUR_1 = exports.PriceFeedType = void 0;
|
|
4
|
-
var PriceFeedType;
|
|
5
|
-
(function (PriceFeedType) {
|
|
6
|
-
PriceFeedType[PriceFeedType["CHAINLINK_ORACLE"] = 0] = "CHAINLINK_ORACLE";
|
|
7
|
-
PriceFeedType[PriceFeedType["YEARN_ORACLE"] = 1] = "YEARN_ORACLE";
|
|
8
|
-
PriceFeedType[PriceFeedType["CURVE_2LP_ORACLE"] = 2] = "CURVE_2LP_ORACLE";
|
|
9
|
-
PriceFeedType[PriceFeedType["CURVE_3LP_ORACLE"] = 3] = "CURVE_3LP_ORACLE";
|
|
10
|
-
PriceFeedType[PriceFeedType["CURVE_4LP_ORACLE"] = 4] = "CURVE_4LP_ORACLE";
|
|
11
|
-
PriceFeedType[PriceFeedType["ZERO_ORACLE"] = 5] = "ZERO_ORACLE";
|
|
12
|
-
PriceFeedType[PriceFeedType["WSTETH_ORACLE"] = 6] = "WSTETH_ORACLE";
|
|
13
|
-
PriceFeedType[PriceFeedType["BOUNDED_ORACLE"] = 7] = "BOUNDED_ORACLE";
|
|
14
|
-
PriceFeedType[PriceFeedType["COMPOSITE_ORACLE"] = 8] = "COMPOSITE_ORACLE";
|
|
15
|
-
PriceFeedType[PriceFeedType["WRAPPED_AAVE_V2_ORACLE"] = 9] = "WRAPPED_AAVE_V2_ORACLE";
|
|
16
|
-
PriceFeedType[PriceFeedType["COMPOUND_V2_ORACLE"] = 10] = "COMPOUND_V2_ORACLE";
|
|
17
|
-
PriceFeedType[PriceFeedType["BALANCER_STABLE_LP_ORACLE"] = 11] = "BALANCER_STABLE_LP_ORACLE";
|
|
18
|
-
PriceFeedType[PriceFeedType["BALANCER_WEIGHTED_LP_ORACLE"] = 12] = "BALANCER_WEIGHTED_LP_ORACLE";
|
|
19
|
-
PriceFeedType[PriceFeedType["CURVE_CRYPTO_ORACLE"] = 13] = "CURVE_CRYPTO_ORACLE";
|
|
20
|
-
PriceFeedType[PriceFeedType["THE_SAME_AS"] = 14] = "THE_SAME_AS";
|
|
21
|
-
PriceFeedType[PriceFeedType["REDSTONE_ORACLE"] = 15] = "REDSTONE_ORACLE";
|
|
22
|
-
PriceFeedType[PriceFeedType["ERC4626_VAULT_ORACLE"] = 16] = "ERC4626_VAULT_ORACLE";
|
|
23
|
-
PriceFeedType[PriceFeedType["NETWORK_DEPENDENT"] = 17] = "NETWORK_DEPENDENT";
|
|
24
|
-
PriceFeedType[PriceFeedType["CURVE_USD_ORACLE"] = 18] = "CURVE_USD_ORACLE";
|
|
25
|
-
})(PriceFeedType = exports.PriceFeedType || (exports.PriceFeedType = {}));
|
|
26
|
-
exports.HOUR_1 = 60 * 60;
|
|
27
|
-
exports.HOUR_24 = 24 * exports.HOUR_1;
|