npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@energi/energiswap-contracts

v1.0.0

Published

Smart contracts for Energiswap

Downloads

15

Readme

Energiswap smart-contracts

Energiswap is a decentralized protocol for automated token exchange.

Prerequisites for deploying Energiswap smart-contracts locally

Make sure you are running Ganache CLI with the following command:

ganache-cli -a 12 -e 1000000 -l 10000000 -p 7545 -m "tackle crazy sibling hobby hurry cat donate abstract sword city 
enough crime"

Deploying Energiswap smart-contracts locally

  1. Git clone repo with git clone [email protected]:energi/defi/uniswap/energiswap-contracts.git
  2. Run yarn install to install the necessary dependencies for the project.
  3. Run truffle compile to compile the contracts inside the contracts folder.
  4. Run truffle migrate to deploy the contracts to the local ganache blockchain.

Testing

Test contracts are defined under the test directory. To run the tests run: truffle test

Architecture

See the architecture diagram in ./energiswap-contracts-architecture-diagram.png

Upgrades using Energi governance

The following Energiswap contracts are fully upgradeable using Energi governance:

EnergiswapRouter.sol EnergiswapFactory.sol EnergiswapPairsManager.sol

In order to upgrade EnergiswapPairsERC20.sol, one should deploy a new implementation for this contract, then deploy a new implementation for EnergiswapPairsManager.sol pointing to the new EnergiswapPairsERC20.sol implementation, and finally upgrade EnergiswapPairsManager.sol to the new implementation using Energi governance.

EnergiswapPairsManager.sol and EnergiswapPairsERC20.sol hold the logic for Energiswap pairs. Upgrading those contracts upgrades the logic for all Energiswap pairs.

Deploying Energiswap to Energi blockchain

WNRG.sol contract is a dependency to Energiswap smart contracts, it must be deployed for Energiswap to work.

Multicall.sol contract is a dependency to EnergiswapFactory and energiswap interface, it must be deployed for Energiswap to work.

Energi governance contracts must be deployed prior to deploying Energiswap Contracts.

Deploy EnergiswapFactory

factory = await EnergiswapFactory.new(feeToSetter, sporkProxy, '0x0000000000000000000000000000000000000000');

feeToSetter is the address of account which has permission to set the feeTo account which will receive trading fees.

sporkProxy is the address of the SporkProxy.sol smart contract which is part of Energi governance infrastructure.

Setting the last parameter to 0x0000000000000000000000000000000000000000 will result in EnergiswapFactoryGovernedProxy contract being deployed automatically. Alternatively, the address of an already deployed proxy contract can be passed.

The address of the deployed EnergiswapFactoryGovernedProxy will be used later in the deployment process. It is available via the proxy() function of EnergiswapFactory.

Deploy EnergiswapPairsERC20

pairsERC20 = await EnergiswapPairsERC20.new();

Deploy EnergiswapPairsManager

pairsManager = await EnergiswapPairsManager.new(factoryProxyAddress, pairsERC20.address, sporkProxy, '0x0000000000000000000000000000000000000000');

factoryProxyAddress is the address of the deployed EnergiswapFactoryGovernedProxy contract.

pairsERC20.address is the address of the deployed EnergiswapPairsERC20 contract.

sporkProxy is the address of the SporkProxy.sol smart contract which is part of Energi governance infrastructure.

Setting the last parameter to 0x0000000000000000000000000000000000000000 will result in EnergiswapPairsManagerGovernedProxy contract being deployed automatically. Alternatively, the address of an already deployed proxy contract can be passed.

The address of the deployed EnergiswapPairsManagerGovernedProxy will be used later in the deployment process. It is available via the proxy() function of EnergiswapPairsManager.

Initialize EnergiswapPairsERC20

await pairsERC20.initialize(pairsManager.address);

pairsManager.address is the address of the deployed EnergiswapPairsManager contract.

Deploy EnergiswapRouter

router = await EnergiswapRouter.new(factoryProxyAddress, wnrg.address, sporkProxy, '0x0000000000000000000000000000000000000000');

factoryProxyAddress is the address of the deployed EnergiswapFactoryGovernedProxy contract.

wnrg.address is the address of the deployed WNRG contract.

sporkProxy is the address of the SporkProxy.sol smart contract which is part of Energi governance infrastructure.

Setting the last parameter to 0x0000000000000000000000000000000000000000 will result in EnergiswapRouterGovernedProxy contract being deployed automatically. Alternatively, the address of an already deployed proxy contract can be passed.

The address of the deployed EnergiswapRouterGovernedProxy will be used later in the deployment process. It is available via the proxy() function of EnergiswapRouter.

Initialize EnergiswapFactory

await factory.initialize(multicall.address, routerProxyAddress, pairsManagerProxyAddress, pairsERC20.address);

multicall.address is the address of the deployed Multicall contract.

routerProxyAddress is the address of the deployed EnergiswapRouterGovernedProxy contract.

pairsManagerProxyAddress is the address of the deployed EnergiswapPairsManagerGovernedProxy contract.

pairsERC20.address is the address of the deployed EnergiswapPairsERC20 contract.

Energiswap Upgrades via Energi Governance

Start with deploying the desired upgrade implementation:

Deploying EnergiswapFactoryUpgrade

factoryUpgrade = await EnergiswapFactoryUpgrade.new(factoryStorageAddress, factoryProxyAddress);

factoryStorageAddress is the address of the existing EnergiswapFactoryStorage contract

factoryProxyAddress is the address of the existing EnergiswapFactoryGovernedProxy contract

Deploying EnergiswapPairsManagerUpgrade and EnergiswapPairsERC20Upgrade

pairsManagerUpgrade = await EnergiswapPairsManagerUpgrade.new(
      pairsManagerProxyAddress,
      pairsManagerStorageAddress,
      pairsERC20Upgrade.address
    );

pairsManagerProxyAddress is the address of the existing EnergiswapPairsManagerGovernedProxy contract

pairsManagerStorageAddress is the address of the existing energiswapPairsManagerStorage contract

pairsERC20Upgrade.address is the address of the deployed EnergiswapPairsERC20 contract. This could be either the former EnergiswapPairsERC20 contract, or a new EnergiswapPairsERC20Upgrade contract.

pairsERC20Upgrade.initialize(pairsManagerUpgrade.address);

Deploying EnergiswapRouterUpgrade

routerUpgrade = await EnergiswapRouterUpgrade.new(routerStorageAddress, routerProxyAddress);

routerStorageAddress is the address of the existing EnergiswapRouterStorage contract

routerProxyAddress is the address of the existing EnergiswapRouterGovernedProxy contract

Proposing a deployed upgrade

Once this is done, call the proposeUpgrade() function on the GovernedProxy contract of the contract being upgraded, with the address of the deployed upgrade implementation.

Masternodes voting and actual upgrade

Masternode owners can now vote to accept or reject the proposed upgrade. If quorum majority is reached, the upgrade proposal is accepted and anyone can now call the upgrade() function on the GovernedProxy contract of the contract being upgraded, with the address of the deployed upgrade proposal.