Code Monkey home page Code Monkey logo

swaplace-contracts's Introduction

Swaplace

Tests Fuzz Testing

This repository contains the core smart contracts for the Swaplace Protocol; The lightest Swap protocol in the market.

TL;DR

  • Contracts cannot be upgraded.
  • Contracts have no ownership.
  • Contracts don't charge fees.
  • There are no external contract dependencies.
  • The protocol operates using available allowances.

Incentives

This repository is subjected to incentives for the community to contribute to the project. The incentive distribution and amount are being discussed but the eligibility has already started.

Features

  • Create Swaps: A Swap has an owner and an allowed address. The owner is the one that can cancel the swap while the allowed address is the one that can execute the swap but anyone can accept if it's set as the Zero Address. A Swap also has an expiry period in seconds. The Swap can only be executed before the expiry period is reached. The Asset type represents on one hand the bidding assets and on the other hand the asking assets.
    struct Swap {
        address owner;
        address allowed;
        uint256 expiry;
        Asset[] biding;
        Asset[] asking;
    }
  • Accept Swaps: You can accept swaps that have an allowed address equal to your or the Zero Address. As long as you provide the asked assets.

  • Cancel Swaps: You can cancel swaps that haven't been expired.

  • Swap Factory: Aids new swap creations to be used on Swaplace. Check contracts/SwapFactory.sol.

Setup

You should install the dependencies using Yarn (used in the project) or npm to deploy this code. The project uses Hardhat as a development environment. Which relies on Node.js (Recommended version v18.16.0).

To make sure that NodeJS is installed correctly, open the integrated terminal and run the following command:

node -v

Yarn:

Install Yarn globally and check if the version appears:

npm install --global yarn
yarn --version

Install the dependencies using Yarn:

yarn install

npm:

Install the dependencies using npm:

npm install

Environment Variables

The project comes with a .env.example file. You should rename it to .env and fill the variables with your values. Most RPC providers offer free testnet nodes. You can use Alchemy or Infura to get a free node.

WARNING: The private keys used in the .env file are from hardhat accounts. They are not meant to be used in production.

Testing and Deploying

Run the tests in localhost or try the contracts in a desired network by specifying the network name in hardhat.config.js.

yarn test
yarn testnet <network>

Deploy the contracts in the desired network according to the networks available in hardhat.config.js.

yarn deploy <network>

Contributing

swaplace-contracts's People

Contributors

0xjoaovpsantos avatar 0xneves avatar alextnetto avatar blackbeard002 avatar dipanshuhappy avatar heronlancellot avatar luislucena16 avatar mitish98 avatar rafadsan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swaplace-contracts's Issues

fix: error interface should not be nested in both father and child

The father already has access to the error interface and it should be removed from the main contract, it should be placed in the factory where all immutable features will take place.

  • Delete the IErrors import from Swaplace.sol
  • Remove the implementation of the contract header

feat: create event logs for each function

There are no event emissions in the Swaplace Contract, but that is about to change, the task is to implement the events while being cohesive on the log parameters. Don't forget to organize in the interface of Swaplace.

Proposal:

  • Add event emission for each function in Swaplace.sol
  • Add event interface in ISwaplace.sol
  • Comment the events using NatSpec

refactor: deployer as signer should be more elegant

Currently, there are two signers in the tests:

The owner and the accepted.

We should change in a way where:

  • A deployer signer is introduced
  • The owner remains the owner
  • The acceptee remains the acceptee

chore: enhance .gitignore

Enhance the current .gitignore by adding comments and separating categories to each blocked file or folder.

docs: enhance ITransfer.sol NatSpec comments

The current explanation is using wrong grammar and should point to the IERC-TransferFrom function.

Proposal:

  • Add a title to the interface contract ITransfer
  • Fix the grammar
  • Refer to IERC20 and IERC721

test: change the context of the tests to be individual and not linear nor correlated

The tests are built in a linear way using chai, they will fail depending on the order of the tests in the script.

This is not the behavior we are expecting and should be changed to an approach where each test is independent of its context.

The #15 provides a layer of usefulness to the current issue and more tools should be implemented to easily reutilize code and reduce the code base.

One thing noted is that we don't want to make it look too complicated but rather keep providing a familiar environment for newcomers who are learning about coding.

docs: swaplace factory should be explained in its interface instead of its contract

The descriptions of the SwaplaceFactory.sol do not follow the OpenZeppelin standard.

They should:

  • Refer to the interface in the main contract
  • Describe its features in the interface contract

This is because when using those features, the explanation is always supposed to be found in the interface to reduce the code size of the main contract and standardize the process of acknowledging what the contract do.

feat: call for contributors by introducing Ownership Wrapper

This card aims to find who is interested in pushing forward the development of Swaplace v2.

The architecture will be very different and security regarding allowances should be checked above all matters.

The core idea of Swaplace v2 is to sell tokenized executions on the blockchain.

You could sell ownership, stake, airdrop, claim functions and delegate to the buyer of said functions.

Please show interest by commenting on this card.

fix: wrong variable passed to custom error in createSwap

The swap.owner variable should not be passed in the InvalidAddress event as it is the msg.sender which is wrong in this scenario.

    if (swap.owner != msg.sender) {
        revert InvalidAddress(swap.owner);
    }

Must be done:

  • The parameter must be swapped with msg.sender instead

refactor: packages and hardhat environment

Proposal:

  • remove unnecessary packages from the package.json file
  • check for stable versions of the remaining packages
  • move all packages but hardhat to devDependencies
  • remove unwanted imports from hardhat.config.ts
  • generate a yarn.lock file to commit
  • prepare more scripts for running hardhat scripts:
    • npx hardhat clean
    • npx hardhat compile
    • npx hardhat run scripts/deploy
    • npx hardhat test
    • npx hardhat node

Run all tests to make sure its properly working

feat: better README.md for the project's repository

I think the bigger question here is:

  • What does a good README look like?
  • Should it have a short description of the project and long setups?

I've tried to explain a lot in the README but it is still not good enough, maybe needs some fluxes? Or more test commands? I'm getting negative feedback from someone, but is still hard to realize what is it lacking, every readme is different in its way, so I guess it is fine for me as it is. If we look at Uniswap README file, it is very simple and short.

Thus, we are accepting feedback and suggestions on what should be changed!

This issue will remain open until:

  • It is decided by the vast majority that it is viable.

feat: create cairo repo to introduce swaplace

We are expanding into the Cairo ecosystem of Starknet.

This card proposes to kickstart this development by introducing the repository at first.

Definition of done:

  • Running a contract on the localhost
  • Running a contract on the devnet

docs: create a title for ISwaplace.sol

Proposal:

  • Create a NatSpec title just like in ISwaplaceFactory.sol
  • Specify in ISwaplaceFactory.sol that the contract is Factory (place after the keywordSwaplace) and not regular Swaplace ie.:
/**
 * @dev Interface of the Swaplace implementation.
 */

chore: remove old branches

The following branches can be removed because they already served their purpose and are implemented in the remaining branches:

Remove:

  • develop/swaplace-architecture
  • ens/swaplaceV2
  • hidromel
  • review
  • selling-function-calls
  • swaplace-v1

Keep:

  • main
  • ens/prod/swaplace
  • prod/eth-version

chore: create milestone for Swaplace v.1.0.0

Milestones can be added to the pull request page of the repository where the milestone will be tracked:

blockful-io => swaplace-contracts => pull-requests => milestones

This issue will be the first in the Milestone here proposed as the one to be completed by 11/15/2023 when Swaplace v1.0.0 is fully operating

docs: add comment to variable

The main variables of the contract have no comments on them.

Proposal:

  • Comment what the variables do in a single line

refactor: change the way expiry is being set

We are setting an expiry time when we create a swap. We add the block timestamp on-chain. This will be more gas-consuming and the off-chain is more than willing to calculate the expiry for us.

Proposal:

  • Change the expiry to be checked summing to the current block.timestamp.
  • Remove the line where the swap.expiry is edited after the swap was stored.
  • Fix all the loose knots from the test file after applying this change as it will require the current timestamp to be added to the expiry.

feat: set default providers for EVM networks

This task consists of finding default providers specified by the mainnet itself for the following EVM networks:

-BNB
-MATIC
-ETH
-AVAX
-FTM
-ASTR

They should be set in '.env.sample' file that the task assignee should create as well.
They should be implemented in the hardhat config file.

feat: manually import the IERC165

Proposal:

  • Manually import the IERC165 into the interface folder of the Swaplace contracts
  • Point the import on Swaplace.sol to the recent added file

docs: enhance the natspec title of the SwapFactory contract

The current NatSpec of the SwapFactory isn't looking that create in terms of explaining the file itself and it is also not matching the changes from the issue #5

Must be done:

  • Make the same layout as the Swaplace contract
  • Remove the Blockful character image since it is an implementation that is not the main contract
  • Add a more readable and informative way to understand its underlying functions in the scope
  • Provide examples of usage in the title as well

docs: ISwap.sol needs NatSpec comments

Follow the same standard used in the rest of the contract (OpenZeppelin's) to describe the interface of ISwap.sol.

Proposal:

  • Implement the NatSpec interface for the ISwap.sol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.