@gearbox-protocol/sdk 2.1.1 → 2.1.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.
@@ -1024,21 +1024,38 @@ contract TokensDataLive {
1024
1024
  }
1025
1025
 
1026
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];
1027
+ if (block.chainid == 1337 || block.chainid == 31337) {
1028
+ uint256 len = connectedNetworks.length;
1029
+ for (uint256 i = 0; i < len; i++) {
1030
+ if (checkNetworkId(connectedNetworks[i])) {
1031
+ return connectedNetworks[i];
1032
+ }
1031
1033
  }
1032
- }
1033
1034
 
1034
- revert("No network found");
1035
+ revert("No network found");
1036
+ } else {
1037
+ return uint16(block.chainid);
1038
+ }
1035
1039
  }
1036
1040
 
1037
1041
  function checkNetworkId(uint16 _networkId) internal view returns (bool) {
1038
- try IERC20Check(usdcByNetwork[_networkId]).totalSupply() returns (uint256) {
1042
+ address tokenToCheck = usdcByNetwork[_networkId];
1043
+
1044
+ if (!isContract(tokenToCheck)) {
1045
+ return false;
1046
+ }
1047
+
1048
+ try IERC20Check(tokenToCheck).totalSupply() returns (uint256) {
1039
1049
  return true;
1040
1050
  } catch {
1041
1051
  return false;
1042
1052
  }
1043
1053
  }
1054
+
1055
+ // This method relies on extcodesize/address.code.length, which returns 0
1056
+ // for contracts in construction, since the code is only stored at the end
1057
+ // of the constructor execution.
1058
+ function isContract(address account) internal view returns (bool) {
1059
+ return account.code.length > 0;
1060
+ }
1044
1061
  }
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.2",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",