Skip to content

Commit

Permalink
Merge e44fc12 into c084f92
Browse files Browse the repository at this point in the history
  • Loading branch information
computerphysicslab committed Jun 10, 2021
2 parents c084f92 + e44fc12 commit 20803cb
Show file tree
Hide file tree
Showing 10 changed files with 622 additions and 1 deletion.
2 changes: 1 addition & 1 deletion brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ networks:
cmd_settings:
port: 443
gas_limit: 6800000
gas_price: 65000010 # 8000000000
gas_price: 20000000000 # 20 GWei
reverting_tx_gas_limit: false
default_contract_owner: false

Expand Down
96 changes: 96 additions & 0 deletions interfaces/IPancakeRouter01.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/// @dev https://github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/IPancakeRouter01.sol (pragma changed)
pragma solidity ^0.5.17;

interface IPancakeRouter01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);

function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);

function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
45 changes: 45 additions & 0 deletions interfaces/IPancakeRouter02.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/// @dev https://github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/interfaces/IPancakeRouter02.sol (with minor changes)
pragma solidity ^0.5.17;

import './IPancakeRouter01.sol';

contract IPancakeRouter02 is IPancakeRouter01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);

function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
123 changes: 123 additions & 0 deletions scripts/pancakeswap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# PancakeSwap Pool Creation

## Files:

### deploy_test_bSOV

Creates a sample SOV token in the network you choose with 100 Million tokens.

### deploy_multisig

Creates a sample multisig using [`MultisigWallet.sol`](../../contracts/multisig/MultiSigWallet.sol)

The multisig owners are taken from either [`bsc_testnet_contracts.json`](./bsc_testnet_contracts.json) or [`bsc_mainnet_contracts.json`](./bsc_mainnet_contracts.json) depending on the network.

In testnet, required confirmations from admins are 1 while in mainnet, it is 2.

### deploy_pool_user

Creates a pool from an EOA (Externally Owned Account) in PancakeSwap.

It assumes that you have enough BNB & token balance for the liquidity in the wallet calling this function.

It checks if the token is approved to be spent by the PancakeSwap, if not, it will do that.

It then creates the pool in PancakeSwap.

### deploy_pool

Creates a pool from a multisig in PancakeSwap.

It assumes either multisig or the user (EOA) calling it has enough BNB and Token in balance.

It checks if the multisig has enough BNB balance, if not it takes the required BNB from EOA.

It then checks if the multisig has enough Token balance, if not, it takes the required Token from EOA.

It then checks if the token is approved to be spent by the PancakeSwap, if not, it will do that.

It then creates a pool from multisig. (A transaction in multisig is created.)

If checking on testnet, these steps will create the pool. If on mainnet, another user has to call the confirm transaction.

## Steps to Create Pool:

NOTE: Dev experience advised to run the script and to make some edits suggested.


### Brownie Configuration for Binance Network

Add new BSC networks to brownie:

```
brownie networks add "BSC" "binance-mainnet" host="https://bsc​-dataseed1.defibit.io/" chainid=56
```

```
brownie networks add "BSC" "binance-testnet" host="https://data-seed-prebsc-1-s1.binance.org:8545/" chainid=97
```

### Mainnet

1. Go to [`bsc_mainnet_contracts.json`](./bsc_mainnet_contracts.json) and add the values for Multisig Admins. (NOTE: PancakeRouter02 is taken from [OpenZeppeling Forum](https://forum.openzeppelin.com/t/psa-regarding-safemoon-forks-on-pancakeswap-transfers-not-working-read-this/7692) and bSOV is taken from [Sovryn Wiki](https://wiki.sovryn.app/en/technical-documents/mainnet-contract-addresses). Please don't change it unless you know what you are doing.)

2. Go to [`brownie-config.yaml`](../../brownie-config.yaml) and edit the `gas_price` under `networks > live` to the current average or fast gas price for BSC network. Binance average is somewhere near [`20 Gwei`](https://bscscan.com/chart/gasprice).

3. (Optional) Deploying MultiSig: If you don't have a multisig yet, please use the [`deploy_multisig.py`](./deploy_multisig.py) to create a multisig with the parameters taken from [`bsc_mainnet_contracts.json`](./bsc_mainnet_contracts.json). To create, please run the following command:

```
brownie run scripts/pancakeswap/deploy_multisig.py --network binance-mainnet
```

4. Once multisig is deployed or known, please update [`bsc_mainnet_contracts.json`](./bsc_mainnet_contracts.json) to add the new multisig address.

5. Deploying Pool: Create a new pool using [`deploy_pool.py`](./deploy_pool.py). To create, please run the following command:

```
brownie run scripts/pancakeswap/deploy_pool.py --network binance-mainnet
```

### Testnet

1. Go to [`bsc_testnet_contracts.json`](./bsc_testnet_contracts.json) and add the values for Multisig Admins. (NOTE: PancakeRouter02 is taken from [PancakeSwap's Twitter Feed](https://twitter.com/pancakeswap/status/1369547285160370182?lang=en). Please don't change it unless you know what you are doing.)

2. Go to [`brownie-config.yaml`](../../brownie-config.yaml) and edit the `gas_price` under `networks > live` to the current average or fast gas price for BSC network.

3. (Optional) Deploying bSOV: If you don't have a bSOV Token yet, please use the [`deploy_test_bSOV.py`](./deploy_test_bSOV.py) to create a bSOV Token with 100 Million as Token Initial Supply. To create, please run the following command:

```
brownie run scripts/pancakeswap/deploy_test_bSOV.py --network binance-testnet
```

4. Once bSOV is deployed or known, please update [`bsc_testnet_contracts.json`](./bsc_testnet_contracts.json) to add the new bSOV Token address.

5. (Optional) Deploying MultiSig: If you don't have a multisig yet, please use the [`deploy_multisig.py`](./deploy_multisig.py) to create a multisig with the parameters taken from [`bsc_testnet_contracts.json`](./bsc_testnet_contracts.json). To create, please run the following command:

```
brownie run scripts/pancakeswap/deploy_multisig.py --network binance-testnet
```

6. Once multisig is deployed or known, please update [`bsc_testnet_contracts.json`](./bsc_testnet_contracts.json) to add the new multisig address.

7. Deploying Pool: Create a new pool using [`deploy_pool.py`](./deploy_pool.py). To create, please run the following command:

```
brownie run scripts/pancakeswap/deploy_pool.py --network binance-testnet
```

NOTE: If you want to create a pool with EOA, use [`deploy_pool_user.py`](./deploy_pool_user.py). This does not require multisig deployment.

## Possible Errors:

1. Please don't forget to set end points (RPC) for brownie networks (`binance-mainnet` and `binance-testnet`). Use your own full node, or any provider like [BSC RPC Endpoints](https://docs.binance.org/smart-chain/developer/rpc.html).

2. If the multisig does not have enough tokens or BNB to provide liquidity, it is taken from the account which is running it. Please make sure you have enough liquidity present in either your account or multisig.

The deploy script w/ no multisig (`deploy_pool_user.py`) and also the multisign script (`deploy_pool.py`) on line 12 has a default configuration values for the amount of BNB and bSOV to spend when deploying the pool:

```
# deployPool(10e18, 500e18) ## previous settings probably right for mainet, but too high for a regular faucet interaction on testnet.
deployPool(.1e18, 5e18)
```

So, be sure to set these values properly on mainnet before running the scripts.
6 changes: 6 additions & 0 deletions scripts/pancakeswap/bsc_mainnet_contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"multisigOwners": ["0x4C3d3505d34213751c4b4d621cB6bDe7E664E222", "0x9E0816a71B53ca67201a5088df960fE90910DE55", "0x27D55f5668eF4438635bdCE0aDCA083507E77752", "0x3Fa303A564645a36a8a92BBB5B7eAF1a899213F4", "0xDBE9fDECb4510ab20BB5A6D32C720f1048704A44"],
"bscMultisig": "",
"PancakeRouter02": "0x10ED43C718714eb63d5aA57B78B54704E256024E",
"bSOV": "0x8753ede1b3a36358e4d7780f384f3f7a2d9e4359"
}
6 changes: 6 additions & 0 deletions scripts/pancakeswap/bsc_testnet_contracts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"multisigOwners": ["0x4C3d3505d34213751c4b4d621cB6bDe7E664E222", "0x9E0816a71B53ca67201a5088df960fE90910DE55", "0x27D55f5668eF4438635bdCE0aDCA083507E77752", "0x3Fa303A564645a36a8a92BBB5B7eAF1a899213F4", "0xDBE9fDECb4510ab20BB5A6D32C720f1048704A44"],
"bscMultisig": "",
"PancakeRouter02": "0xD99D1c33F9fC3444f8101754aBC46c52416550D1",
"bSOV": ""
}
54 changes: 54 additions & 0 deletions scripts/pancakeswap/deploy_multisig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from brownie import *

import json

def main():
loadConfig()

balanceBefore = acct.balance()
# Function Call
deployMultisig()
balanceAfter = acct.balance()

print("=============================================================")
print("BNB Before Balance: ", balanceBefore)
print("BNB After Balance: ", balanceAfter)
print("Gas Used: ", balanceBefore - balanceAfter)
print("=============================================================")

def loadConfig():
global contracts, acct
thisNetwork = network.show_active()

# == Load config =======================================================================================================================
if thisNetwork == "binance-testnet":
acct = accounts.load("rskdeployer")
configFile = open('./scripts/pancakeswap/bsc_testnet_contracts.json')
elif thisNetwork == "binance-mainnet":
acct = accounts.load("rskdeployer")
configFile = open('./scripts/pancakeswap/bsc_mainnet_contracts.json')
else:
raise Exception("Network not supported.")

# Load deployed contracts addresses
contracts = json.load(configFile)

# == Multisig Deployment ======================================
def deployMultisig():
owners = contracts["multisigOwners"]
requiredConf = 1
if network.show_active() == "mainnet":
requiredConf = int(len(owners)/2 + 1)
print("=============================================================")
print("Deployment Parameters")
print("=============================================================")
print("Multisig Owners: ", owners)
print("Required Confirmations: ", requiredConf)
print("=============================================================")

multisig = acct.deploy(MultiSigWallet, owners, requiredConf)
print("=============================================================")
print("Deployed Details")
print("=============================================================")
print("Multisig Address: ", multisig)
print("=============================================================")
Loading

0 comments on commit 20803cb

Please sign in to comment.