Skip to content

Commit

Permalink
Fix/weth insufficient gas (#194)
Browse files Browse the repository at this point in the history
* fix

* tests

* comments

* removed unused deps

* network addresses

* removed mumbai
  • Loading branch information
todesstille authored May 1, 2024
1 parent 3a5856e commit 91e9218
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ COINMARKETCAP_KEY = "COINMARKETCAP API KEY"
TYPECHAIN_TARGET = "TYPECHAIN TARGET"

# Environment
ENVIRONMENT = "PROD|STAGE|DEV|DEV_SEPOLIA|DEV_MUMBAI"
ENVIRONMENT = "PROD|STAGE|DEV|DEV_SEPOLIA"
26 changes: 25 additions & 1 deletion contracts/core/network-properties/BSCProperties.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import "@solarity/solidity-lib/access-control/MultiOwnable.sol";

import "@uniswap/v2-periphery/contracts/interfaces/IWETH.sol";

import "../../interfaces/core/INetworkProperties.sol";

contract BSCProperties is INetworkProperties {
contract BSCProperties is INetworkProperties, MultiOwnable, UUPSUpgradeable {
uint256 private constant BNB_SUPPLY = 150_000_000 * 10 ** 18;

IWETH public weth;

function __NetworkProperties_init(address weth_) external initializer {
__MultiOwnable_init();

weth = IWETH(weth_);
}

function unwrapWeth(uint256 amount) external override {
weth.withdraw(amount);

(bool ok, ) = payable(msg.sender).call{value: amount}("");
assert(ok);
}

receive() external payable {}

function getNativeSupply() external view override returns (uint256) {
return BNB_SUPPLY;
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}
3 changes: 2 additions & 1 deletion contracts/gov/user-keeper/GovUserKeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ contract GovUserKeeper is IGovUserKeeper, OwnableUpgradeable, ERC721HolderUpgrad
if (wrapping) {
IWETH(wethAddress).deposit{value: value}();
} else {
IWETH(wethAddress).withdraw(value);
IWETH(wethAddress).transfer(networkPropertiesAddress, value);
INetworkProperties(networkPropertiesAddress).unwrapWeth(value);
}
}

Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/core/INetworkProperties.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
pragma solidity ^0.8.20;

interface INetworkProperties {
/// @notice Used to unwrap WEth out of SphereX-controlled beacon and return to the sender
/// @param amount The amount to unwrap
function unwrapWeth(uint256 amount) external;

/// @notice Used in native coin governance mechanism
/// @return The current full supply of native coin
function getNativeSupply() external view returns (uint256);
Expand Down
10 changes: 10 additions & 0 deletions contracts/mock/gov/NetworkPropertiesMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "../../core/network-properties/BSCProperties.sol";

contract NetworkPropertiesMock is BSCProperties {
function changeWeth(address newAddress) external {
weth = IWETH(newAddress);
}
}
193 changes: 0 additions & 193 deletions deploy/config/configs/dev-mumbai.conf.js

This file was deleted.

2 changes: 1 addition & 1 deletion deploy/config/configs/dev-sepolia.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const uniswap = {
quoter: "0xed1f6473345f45b75f8179591dd5ba1888cf2fb3",
};

const NETWORK_PROPERTIES = "0x7Dc3f3bEAeC9dAbC1Ae17508d96335E228a3c2a8";
const NETWORK_PROPERTIES = "0xeEf4962269b8c8693e910D1e5B3BCf52bA4Ca80A";

const DEXE_DAO_NAME = "DeXe Protocol";

Expand Down
2 changes: 1 addition & 1 deletion deploy/config/configs/dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const uniswap = {
quoter: "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2",
};

const NETWORK_PROPERTIES = "0x35b3978fa2fA3cCC754e47cbD1D9956485A83736";
const NETWORK_PROPERTIES = "0xfC0b23b0F841Ce81eC8Fa7Ba80A1096f05cDD7Eb";

const DEXE_DAO_NAME = "DeXe Protocol";

Expand Down
2 changes: 1 addition & 1 deletion deploy/config/configs/prod.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const uniswap = {
quoter: "0xb048bbc1ee6b733fffcfb9e9cef7375518e25997",
};

const NETWORK_PROPERTIES = "0x9a1AF9996458FDe28dD33EDC199f707ca9Ec2bA6";
const NETWORK_PROPERTIES = "";

const DEXE_DAO_NAME = "DeXe Protocol";

Expand Down
2 changes: 1 addition & 1 deletion deploy/config/configs/stage.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const uniswap = {
quoter: "0xbC203d7f83677c7ed3F7acEc959963E7F4ECC5C2",
};

const NETWORK_PROPERTIES = "0x35b3978fa2fA3cCC754e47cbD1D9956485A83736";
const NETWORK_PROPERTIES = "";

const DEXE_DAO_NAME = "DeXe Protocol";

Expand Down
21 changes: 17 additions & 4 deletions deploy/config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ const getConfig = () => {
return require("./configs/dev-sepolia.conf.js");
}

if (process.env.ENVIRONMENT == "DEV_MUMBAI") {
return require("./configs/dev-mumbai.conf.js");
}

throw Error("No environment config specified");
};

Expand Down Expand Up @@ -77,9 +73,26 @@ const getBytesDexeMultiplierInit = (multiplierName, multiplierSymbol) => {
);
};

const getBytesNetworkPropertiesInit = (wethAddress) => {
return web3.eth.abi.encodeFunctionCall(
{
name: "__NetworkProperties_init",
type: "function",
inputs: [
{
type: "address",
name: "weth_",
},
],
},
[wethAddress],
);
};

module.exports = {
getConfig,
getBytesPolynomialPowerInit,
getBytesContractsRegistryInit,
getBytesDexeMultiplierInit,
getBytesNetworkPropertiesInit,
};
7 changes: 0 additions & 7 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ module.exports = {
accounts: privateKey(),
gasMultiplier: 1.2,
},
mumbai: {
url: `https://polygon-testnet.public.blastapi.io`,
accounts: privateKey(),
gasPrice: 2000000000,
gasMultiplier: 1.2,
},
chapel: {
url: "https://data-seed-prebsc-1-s1.binance.org:8545",
accounts: privateKey(),
Expand Down Expand Up @@ -79,7 +73,6 @@ module.exports = {
mainnet: `${process.env.ETHERSCAN_KEY}`,
goerli: `${process.env.ETHERSCAN_KEY}`,
sepolia: `${process.env.ETHERSCAN_KEY}`,
polygonMumbai: `${process.env.POLYGONSCAN_KEY}`,
bsc: `${process.env.BSCSCAN_KEY}`,
bscTestnet: `${process.env.BSCSCAN_KEY}`,
},
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"private-network-fork": "npx hardhat node --fork https://mainnet.infura.io/v3/$(grep INFURA_KEY .env | cut -d '\"' -f2)",
"deploy-dev": "npx hardhat migrate --network localhost",
"deploy-sepolia": "npx hardhat migrate --network sepolia --verify",
"deploy-mumbai": "npx hardhat migrate --network mumbai --verify",
"deploy-chapel": "npx hardhat migrate --network chapel --verify",
"deploy-eth": "npx hardhat migrate --network ethereum --verify",
"deploy-bsc": "npx hardhat migrate --network bsc --verify",
Expand Down
Loading

0 comments on commit 91e9218

Please sign in to comment.