@gearbox-protocol/sdk 2.1.5 → 2.1.7

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.
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ // Gearbox. Generalized leverage protocol that allows to take leverage and then use it across other DeFi protocols and platforms in a composable way.
3
+ // (c) Gearbox Foundation, 2023
4
+ pragma solidity ^0.8.17;
5
+
6
+ import {Test} from "forge-std/Test.sol";
7
+
8
+ interface IERC20Check {
9
+ function totalSupply() external view returns (uint256);
10
+ }
11
+
12
+ contract NetworkDetector is Test {
13
+ mapping(uint256 => address) usdcByNetwork;
14
+
15
+ uint16[] public connectedNetworks;
16
+
17
+ uint256 public immutable chainId;
18
+
19
+ constructor() {
20
+ // ---------------- Networks ---------------------
21
+ connectedNetworks.push(1);
22
+ connectedNetworks.push(42161);
23
+ usdcByNetwork[1] = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
24
+ usdcByNetwork[42161] = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831;
25
+
26
+ chainId = getNetworkId();
27
+ }
28
+
29
+ function getNetworkId() internal view returns (uint256) {
30
+ if (block.chainid == 1337 || block.chainid == 31337) {
31
+ uint256 len = connectedNetworks.length;
32
+ for (uint256 i = 0; i < len; i++) {
33
+ if (checkNetworkId(connectedNetworks[i])) {
34
+ return connectedNetworks[i];
35
+ }
36
+ }
37
+ }
38
+ return block.chainid;
39
+ }
40
+
41
+ function checkNetworkId(uint16 _networkId) internal view returns (bool) {
42
+ address tokenToCheck = usdcByNetwork[_networkId];
43
+
44
+ if (!isContract(tokenToCheck)) {
45
+ return false;
46
+ }
47
+
48
+ try IERC20Check(tokenToCheck).totalSupply() returns (uint256) {
49
+ return true;
50
+ } catch {
51
+ return false;
52
+ }
53
+ }
54
+
55
+ // This method relies on extcodesize/address.code.length, which returns 0
56
+ // for contracts in construction, since the code is only stored at the end
57
+ // of the constructor execution.
58
+ function isContract(address account) internal view returns (bool) {
59
+ return account.code.length > 0;
60
+ }
61
+ }
@@ -54,8 +54,6 @@ struct RedStonePriceFeedData {
54
54
  }
55
55
 
56
56
  contract PriceFeedDataLive {
57
- uint256 networkId;
58
-
59
57
  mapping(uint256 => ChainlinkPriceFeedData[]) chainlinkPriceFeedsByNetwork;
60
58
  mapping(uint256 => SingeTokenPriceFeedData[]) zeroPriceFeedsByNetwork;
61
59
  mapping(uint256 => CurvePriceFeedData[]) curvePriceFeedsByNetwork;
@@ -70,8 +68,7 @@ contract PriceFeedDataLive {
70
68
  mapping(uint256 => GenericLPPriceFeedData[]) erc4626PriceFeedsByNetwork;
71
69
  mapping(uint256 => RedStonePriceFeedData[]) redStonePriceFeedsByNetwork;
72
70
 
73
- constructor(uint256 _networkId) {
74
- networkId = _networkId;
71
+ constructor() {
75
72
  // ------------------------ 1INCH ------------------------
76
73
  chainlinkPriceFeedsByNetwork[1].push(
77
74
  ChainlinkPriceFeedData({token: Tokens._1INCH, priceFeed: 0xc929ad75B72593967DE83E7F7Cda0493458261D9})
@@ -908,6 +905,6 @@ contract PriceFeedDataLive {
908
905
  }
909
906
 
910
907
  function chainlinkPriceFeeds(uint256 index) external view returns (ChainlinkPriceFeedData memory) {
911
- return chainlinkPriceFeedsByNetwork[networkId][index];
908
+ return chainlinkPriceFeedsByNetwork[block.chainid][index];
912
909
  }
913
910
  }
@@ -26,14 +26,11 @@ contract SupportedContracts is Test, ISupportedContracts {
26
26
  mapping(Contracts => address) public override addressOf;
27
27
  mapping(Contracts => string) public override nameOf;
28
28
  mapping(address => Contracts) public override contractIndex;
29
- mapping(uint16 => ContractData[]) public contractDataByNetwork;
29
+ mapping(uint256 => ContractData[]) public contractDataByNetwork;
30
30
 
31
31
  uint256 public override contractCount;
32
32
 
33
- uint16 immutable networkId;
34
-
35
- constructor(uint16 _networkId) {
36
- networkId = _networkId;
33
+ constructor() {
37
34
  contractDataByNetwork[1].push(
38
35
  ContractData({
39
36
  id: Contracts.UNISWAP_V2_ROUTER,
@@ -352,7 +349,7 @@ contract SupportedContracts is Test, ISupportedContracts {
352
349
  })
353
350
  );
354
351
 
355
- ContractData[] storage cd = contractDataByNetwork[networkId];
352
+ ContractData[] storage cd = contractDataByNetwork[block.chainid];
356
353
 
357
354
  uint256 len = cd.length;
358
355
  contractCount = len;
@@ -18,16 +18,8 @@ struct TokenData {
18
18
 
19
19
  contract TokensDataLive {
20
20
  mapping(uint256 => TokenData[]) tokenDataByNetwork;
21
- mapping(uint256 => address) usdcByNetwork;
22
-
23
- uint16[] public connectedNetworks;
24
21
 
25
22
  constructor() {
26
- // ---------------- Networks ---------------------
27
- connectedNetworks.push(1);
28
- connectedNetworks.push(42161);
29
-
30
- // ---------------- TokensData ---------------------
31
23
  tokenDataByNetwork[1].push(
32
24
  TokenData({
33
25
  id: Tokens._1INCH,
@@ -108,7 +100,6 @@ contract TokensDataLive {
108
100
  tokenType: TokenType.NORMAL_TOKEN
109
101
  })
110
102
  );
111
- usdcByNetwork[1] = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
112
103
  tokenDataByNetwork[1].push(
113
104
  TokenData({
114
105
  id: Tokens.USDC,
@@ -809,7 +800,6 @@ contract TokensDataLive {
809
800
  tokenType: TokenType.NORMAL_TOKEN
810
801
  })
811
802
  );
812
- usdcByNetwork[42161] = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831;
813
803
  tokenDataByNetwork[42161].push(
814
804
  TokenData({
815
805
  id: Tokens.USDC,
@@ -1016,40 +1006,7 @@ contract TokensDataLive {
1016
1006
  );
1017
1007
  }
1018
1008
 
1019
- function getTokenData() external view returns (TokenData[] memory) {
1020
- return tokenDataByNetwork[block.chainid];
1021
- }
1022
-
1023
- function getNetworkId() external view returns (uint256) {
1024
- if (block.chainid == 1337 || block.chainid == 31337) {
1025
- uint256 len = connectedNetworks.length;
1026
- for (uint256 i = 0; i < len; i++) {
1027
- if (checkNetworkId(connectedNetworks[i])) {
1028
- return connectedNetworks[i];
1029
- }
1030
- }
1031
- }
1032
- return block.chainid;
1033
- }
1034
-
1035
- function checkNetworkId(uint16 _networkId) internal view returns (bool) {
1036
- address tokenToCheck = usdcByNetwork[_networkId];
1037
-
1038
- if (!isContract(tokenToCheck)) {
1039
- return false;
1040
- }
1041
-
1042
- try IERC20Check(tokenToCheck).totalSupply() returns (uint256) {
1043
- return true;
1044
- } catch {
1045
- return false;
1046
- }
1047
- }
1048
-
1049
- // This method relies on extcodesize/address.code.length, which returns 0
1050
- // for contracts in construction, since the code is only stored at the end
1051
- // of the constructor execution.
1052
- function isContract(address account) internal view returns (bool) {
1053
- return account.code.length > 0;
1009
+ function getTokenData(uint256 chainId) external view returns (TokenData[] memory) {
1010
+ return tokenDataByNetwork[chainId];
1054
1011
  }
1055
1012
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",