@@@@@@@@@@@@@@@ @@@@@@
@@@@@@@@@@@@@@@@@@@@ @@@@
@@@@@@,
@@@@@@ @@@ @@@ &@@% %@@@ @@@@ @@@@@@@
@@@@@ *@@@@ @@@@@( @@@@@ @@@@% @@@@@@@@@@@@@@@@%
@@@@@ @@@@@@@@@@ #@@@@ @@@@@@@ @@@@@ @@@@% @@@@@ @@@@@
@@@@@ @@@@@@@@@ &@@@@ @@@@ @@@@ %@@@@ @@@@% @@@@* #@@@@
@@@@@@ @@@@ @@@@@ @@@@ @@@@ *@@@@ @@@@% @@@@, #@@@@
@@@@@@ @@@@ @@@@@@@@@. @@@@ @@@@ @@@@% @@@@, #@@@@
@@@@@@@@@@&@@@@@@@@@ @@@@@@@% @@@@@@@ @@@@% @@@@, #@@@@
@@@@@@@@@@@@@@@@# @@@@@@ @@@@@ @@@@. @@@@ @@@@
Launch an endless variety of markets with just a price feed and an ETH deposit. Markets grow organically as interest grows, and the platform algorithmically ensures best performance available, even in markets with limited liquidity. This allows you to create and confidently trade longs, shorts, and stables in even the most obscure and growing markets, knowing that your transactions will be executed at their best potential. Gwin is designed so that you don't need to worry about exit liquidity or costly exposure in a lopsided trade. So get in, get out, and gwin!
Gwin has a great front-end that can be used along with this smart contract.
Check out a live deployment of the Gwin Dapp on the Goerli test net
Check out the full documentation.
Look through the FAQs
- Launch markets quickly with any price feed
- Trade efficiently in any market, even low-interest ones
- Act as a market maker and earn profits by maintaining balance in the protocol
- Avoid systemic risk with a unique approach to settlement and market making
- Connect to the platform via a simple front end and MetaMask
- Gwin Protocol
Please install or have the following installed:
- nodejs v16.15.0
- python
- Yarn
npm install --global yarn
python3 -m pip install --user pipx
python3 -m pipx ensurepath
# restart your terminal
pipx install eth-brownie
Or, if that doesn't work, try pip
pip install eth-brownie
Download the mix and install dependencies.
Use Git to clone the Gwin repository:
git clone https://github.com/coltonmilbrandt/gwin-protocol.git
cd gwin-protocol
For local testing install ganache-cli
npm install -g ganache-cli
or
yarn add global ganache-cli
All the scripts are designed to work locally or on a testnet.
This will deploy the Gwin smart contract to your local chain with ganache.
- Start ganache and take note of private keys as needed
ganache
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache. You can safely delete the build folder so that the proper contract is referenced.
- Run deploy script with ganache network flag
brownie run scripts/deploy.py --network ganache
This will deploy the Gwin smart contract with multiple pools to your local chain with ganache and then allow you to trade.
The deploy_pools.py script will repeatedly change the price feeds up in 1% increments to 10% higher than the original price and then down in 1% increments to 10% lower than the original price, changing multiple times per minute, so that you can experience price movements quickly and predictably. Eventually, the while loop doing this will terminate.
- Look over deploy_pools.py and optionally change any of the initially funded pools or the amount to fund them with.
# 'amount' determined by environment - i.e. the ETH you wish to distribute between all the pools
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
amount = 100 # Change this (optional)
# Change pools (optional)
#@@@@@@@@@@@@| Create 2x ETH/USD pool with stable parent |@@@@@@@@@@@@#
parent_id = 1 # parent ID: 1
pool_type = 0 # classic type pool
pool_h_rate = 100_0000000000 # 2x leverage
pool_c_rate = -100_0000000000 # stable
tx = gwin_protocol.initializePool(pool_type, parent_id, eth_usd_price_feed.address, "0x4554482f555344", "0x0000000000000000000000000000000000000000", "0x0", pool_c_rate, pool_h_rate, {"from": account, "value": Web3.toWei(amount, "ether")})
tx.wait(1)
pool_2x_id = 0
- Start ganache and take note of private keys
ganache
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache. You can safely delete the build folder so that the proper contract is referenced.
- Run deploy script with ganache network flag and copy contract address from logs
brownie run scripts/deploy_pools.py --network ganache
Copy the log output contract address for your newly deployed Gwin contract, for example...
gwin deployed to: 0xExAmpLe00c0nTr4ct00N0t00R34L00e3052d323a
Copy any price feed addresses you'd like to use to create pools, for example...
deploying: eth_usd_price_feed
# ...
Deployed mock price feed to 0xExAmpLe00c0nTr4ct00N0t00R34L00e3052d323a
-
Clone and launch front-end.
-
Insert contract address of your local Gwin smart contract on ganache (from step 3) into the code for the front-end. You can set this in the
contracts.js
file in theconstants
folder. If you've made changes to the contract, be sure to copy your new ABI over toGwin_abi.js
as well. -
Copy the private key for Account (1), and use it to 'Import Account' on MetaMask. Accounts (1-3) are generally your best choice as Account (0) initially funds the pools and Account (4) updates the price feeds.
-
Launch front-end with
yarn dev
and connect your MetaMask via Localhost 8545. -
Now you can Deposit and Withdraw to pools. To take advantage of the predictable price movement for testing, go long when ETH/USD is around $900 and withdraw, short, or go stable when ETH/USD is around $1,100 (see how trading works). Keep in mind that without market forces at work, it's easy to create interesting scenarios that otherwise wouldn't naturally arise with other traders participating and taking advantage of underweight (high health) pools. Read more about this in the documentation. Also note that you can create pools as well. Read about that right here, just make sure that you use price feed addresses from the logs in Step 3.
This will deploy the Gwin smart contract to Goerli.
- Get your keys set up and make sure your wallet is funded with test ETH.
Note: You may need to clear the build folder between deployments and testing, particulary when you change networks. You can safely delete the build folder so that the proper contract is referenced.
- Run deploy script with goerli network flag
brownie run scripts/deploy.py --network goerli
After this, if you set it up properly for Etherscan, you can interact with the verified contract via their interface.
This will deploy the Gwin smart contract with multiple pools to the Goerli Test Net and then allow you to trade. The deploy_pools.py script will create multiple pools to start you off.
-
Make sure you grab some test net ETH if you need it.
-
Look over deploy_pools.py and optionally change any of the initially funded pools or the amount to fund them with.
# 'amount' determined by environment - i.e. the ETH you wish to distribute between all the pools
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
amount = 100
else:
amount = 1.2 # change this (optional)
# Change pools (optional)
#@@@@@@@@@@@@| Create 2x ETH/USD pool with stable parent |@@@@@@@@@@@@#
parent_id = 1 # parent ID: 1
pool_type = 0 # classic type pool
pool_h_rate = 100_0000000000 # 2x leverage
pool_c_rate = -100_0000000000 # stable
tx = gwin_protocol.initializePool(pool_type, parent_id, eth_usd_price_feed.address, "0x4554482f555344", "0x0000000000000000000000000000000000000000", "0x0", pool_c_rate, pool_h_rate, {"from": account, "value": Web3.toWei(amount, "ether")})
tx.wait(1)
pool_2x_id = 0
- Responsibly set up your keys (use a test wallet!) and run deploy script with goerli network flag and copy contract address from logs.
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache or change networks. You can safely delete the build folder so that the proper contract is referenced.
Note: Make sure you have enough test ETH. Change the amount in the deploy_pools.py script if needed, and make sure you have enough left for gas.
brownie run scripts/deploy_pools.py --network goerli
Copy the log output contract address for your newly deployed Gwin contract, for example...
gwin deployed to: 0xExAmpLe00c0nTr4ct00N0t00R34L00e3052d323a
Price feeds will be determined by the established Goerli addresses, so no need to worry about copying them. However, you can get the price feeds you need for creating pools on Goerli here.
-
Clone and launch front-end.
-
Insert contract address of your Goerli Gwin smart contract on ganache (from step 3) into the code for the front-end. You can set this in the
contracts.js
file in theconstants
folder. If you've made changes to the contract, be sure to copy your new ABI over toGwin_abi.js
as well. -
Launch front-end with
yarn dev
and connect your MetaMask wallet with the same keys that you used to deploy the contract (that way you can get your test ETH back, if you want). -
Now you can Deposit and Withdraw to pools (see how trading works). Keep in mind that without market forces at work, it's easy to create interesting scenarios that otherwise wouldn't naturally arise with other traders participating and taking advantage of underweight (high health) pools. Read more about this in the documentation. Also note that you can create pools as well. Read about that right here.
Run every test in the tests folder and see the coverage report.
Run the test with:
brownie test --coverage --network ganache
GwinProtocol.abs - 100.0%
GwinProtocol.cEthNeededForPools - 100.0%
GwinProtocol.interactByPool - 100.0%
GwinProtocol.liquidateIfZero - 100.0%
GwinProtocol.reAdjust - 98.2%
GwinProtocol.withdrawFromTranche - 97.1%
GwinProtocol.reAdjustChildPools - 95.8%
GwinProtocol.trancheSpecificCalcs - 95.0%
GwinProtocol.depositToTranche - 91.1%
GwinProtocol.interact - 90.3%
GwinProtocol.bothPoolsHaveBalance - 87.5%
GwinProtocol.initializePool - 86.1%
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache or change networks. You can safely delete the build folder so that the proper contract is referenced.
Unit tests include tests for:
- Initializing a Pool
- Basic Deposit
- Basic Withdrawal
- Deposit Exploit Guard
- Liquidation
- Getting Accounts
- Balance Estimate Accuracy
- Zero Amount Deposits
- Withdrawal Greater than Balance
- And More...
Run these tests with:
brownie test tests/unit/gwin_unit.py --network ganache
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache or change networks. You can safely delete the build folder so that the proper contract is referenced.
This broad integration test includes a robust script that compares the underlying math model's expected values with what the protocol calculates, verifying accuracy with extensive testing of a wide range of accumulating activity:
- Initializing Pools
- Varying Types of Pools
- A Variety of Deposits
- A Variety of Withdrawals
Run this test with:
brownie test tests/integration/gwin_int.py --network ganache
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache or change networks. You can safely delete the build folder so that the proper contract is referenced.
Like the previous broad integration test, but this script tests parent pool type transactions to verify accuracy with extensive testing of a wide range of accumulating activity:
- Initializing Pools
- A Variety of Deposits
- A Variety of Withdrawals
Run this test with:
brownie test tests/integration/gwin_parent_int.py --network ganache
Note: You may need to clear the build folder between deployments and testing, particulary when you restart ganache or change networks. You can safely delete the build folder so that the proper contract is referenced.
Gwin is currently in alpha and is undergoing active development. While it is functional, there may be some bugs and issues that have not yet been addressed.
The smart contracts for Gwin have not yet been formally audited and should not be used for main net applications at this time.
If you encounter any issues or have any questions about Gwin, please don't hesitate to contact me.
We welcome contributions to Gwin! Here are a few ways you can help:
- Report bugs and suggest features by opening an issue on GitHub.
- Contribute code by opening a pull request on GitHub.
- Help to improve the documentation by submitting updates and corrections.
Gwin is licensed under the MIT License.
- Have questions?
- Need some help setting up?
- Want to contribute?
Email me at [email protected]!
Check out my website www.coltonmilbrandt.com
Read the full docs to learn more.