@gearbox-protocol/sdk 2.1.1 → 2.1.3

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.
@@ -54,23 +54,23 @@ struct RedStonePriceFeedData {
54
54
  }
55
55
 
56
56
  contract PriceFeedDataLive {
57
- uint16 networkId;
58
-
59
- mapping(uint16 => ChainlinkPriceFeedData[]) chainlinkPriceFeedsByNetwork;
60
- mapping(uint16 => SingeTokenPriceFeedData[]) zeroPriceFeedsByNetwork;
61
- mapping(uint16 => CurvePriceFeedData[]) curvePriceFeedsByNetwork;
62
- mapping(uint16 => CurvePriceFeedData[]) curveCryptoPriceFeedsByNetwork;
63
- mapping(uint16 => TheSamePriceFeedData[]) theSamePriceFeedsByNetwork;
64
- mapping(uint16 => SingeTokenPriceFeedData[]) yearnPriceFeedsByNetwork;
65
- mapping(uint16 => BoundedPriceFeedData[]) boundedPriceFeedsByNetwork;
66
- mapping(uint16 => CompositePriceFeedData[]) compositePriceFeedsByNetwork;
67
- mapping(uint16 => SingeTokenPriceFeedData) wstethPriceFeedByNetwork;
68
- mapping(uint16 => GenericLPPriceFeedData[]) wrappedAaveV2PriceFeedsByNetwork;
69
- mapping(uint16 => GenericLPPriceFeedData[]) compoundV2PriceFeedsByNetwork;
70
- mapping(uint16 => GenericLPPriceFeedData[]) erc4626PriceFeedsByNetwork;
71
- mapping(uint16 => RedStonePriceFeedData[]) redStonePriceFeedsByNetwork;
72
-
73
- constructor(uint16 _networkId) {
57
+ uint256 networkId;
58
+
59
+ mapping(uint256 => ChainlinkPriceFeedData[]) chainlinkPriceFeedsByNetwork;
60
+ mapping(uint256 => SingeTokenPriceFeedData[]) zeroPriceFeedsByNetwork;
61
+ mapping(uint256 => CurvePriceFeedData[]) curvePriceFeedsByNetwork;
62
+ mapping(uint256 => CurvePriceFeedData[]) curveCryptoPriceFeedsByNetwork;
63
+ mapping(uint256 => TheSamePriceFeedData[]) theSamePriceFeedsByNetwork;
64
+ mapping(uint256 => SingeTokenPriceFeedData[]) yearnPriceFeedsByNetwork;
65
+ mapping(uint256 => BoundedPriceFeedData[]) boundedPriceFeedsByNetwork;
66
+ mapping(uint256 => CompositePriceFeedData[]) compositePriceFeedsByNetwork;
67
+ mapping(uint256 => SingeTokenPriceFeedData) wstethPriceFeedByNetwork;
68
+ mapping(uint256 => GenericLPPriceFeedData[]) wrappedAaveV2PriceFeedsByNetwork;
69
+ mapping(uint256 => GenericLPPriceFeedData[]) compoundV2PriceFeedsByNetwork;
70
+ mapping(uint256 => GenericLPPriceFeedData[]) erc4626PriceFeedsByNetwork;
71
+ mapping(uint256 => RedStonePriceFeedData[]) redStonePriceFeedsByNetwork;
72
+
73
+ constructor(uint256 _networkId) {
74
74
  networkId = _networkId;
75
75
  // ------------------------ 1INCH ------------------------
76
76
  chainlinkPriceFeedsByNetwork[1].push(
@@ -17,9 +17,8 @@ struct TokenData {
17
17
  }
18
18
 
19
19
  contract TokensDataLive {
20
- uint16 public immutable networkId;
21
- mapping(uint16 => TokenData[]) tokenDataByNetwork;
22
- mapping(uint16 => address) usdcByNetwork;
20
+ mapping(uint256 => TokenData[]) tokenDataByNetwork;
21
+ mapping(uint256 => address) usdcByNetwork;
23
22
 
24
23
  uint16[] public connectedNetworks;
25
24
 
@@ -1015,30 +1014,42 @@ contract TokensDataLive {
1015
1014
  tokenType: TokenType.AAVE_V2_A_TOKEN
1016
1015
  })
1017
1016
  );
1018
-
1019
- networkId = getNetworkId();
1020
1017
  }
1021
1018
 
1022
1019
  function getTokenData() external view returns (TokenData[] memory) {
1023
- return tokenDataByNetwork[networkId];
1020
+ return tokenDataByNetwork[block.chainid];
1024
1021
  }
1025
1022
 
1026
- function getNetworkId() internal view returns (uint16) {
1027
- uint256 len = connectedNetworks.length;
1028
- for (uint256 i = 0; i < len; i++) {
1029
- if (checkNetworkId(connectedNetworks[i])) {
1030
- return connectedNetworks[i];
1023
+ function getNetworkId() internal 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
+ }
1031
1030
  }
1032
1031
  }
1033
-
1034
- revert("No network found");
1032
+ return block.chainid;
1035
1033
  }
1036
1034
 
1037
1035
  function checkNetworkId(uint16 _networkId) internal view returns (bool) {
1038
- try IERC20Check(usdcByNetwork[_networkId]).totalSupply() returns (uint256) {
1036
+ address tokenToCheck = usdcByNetwork[_networkId];
1037
+
1038
+ if (!isContract(tokenToCheck)) {
1039
+ return false;
1040
+ }
1041
+
1042
+ try IERC20Check(tokenToCheck).totalSupply() returns (uint256) {
1039
1043
  return true;
1040
1044
  } catch {
1041
1045
  return false;
1042
1046
  }
1043
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;
1054
+ }
1044
1055
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",