GithubHelp home page GithubHelp logo

otc-coupon-trader's Introduction

Warning

This is unaudited and untested code. Please exercise caution and do not use it with more than you are comfortable losing.

Also, DO NOT send any tokens or ETH to this contract. Any tokens or ETH sent here will be stuck forever. Only interact with the contract via its functions.

What

This is a smart contract intended to allow untrusted parties to buy/sell ESD coupons in an OTC fashion. An instance of this contract can be found on mainnet here.

There are no order books or AMMs here. Any negotiations over price, quantity, epochs, etc takes place off-chain. This is just a way for two people who have already come to an agreement to execute that agreement without a trusted intermediary.

How

Step 1: Sellers approve this contract

The seller of coupons must approve the CouponTrader contract to move their coupons via the approveCoupons function on the ESD DAO contract. This only has to be done once.

Step 2: Sellers create an offer

Once the seller has approved the CouponTrader contract, they can create an offer by calling the setOffer function on the CouponTrader contract. They can specify a specific _buyer that is allowed to take their offer, or they can set the buyer as address 0x0000000000000000000000000000000000000001 to indicate that the offer is open for anyone to take.

Remember that USDC uses 6 decimal places, not 18 like most other coins, so be careful when setting the _totalUSDCRequiredFromSeller parameter to use the correct number of "decimals".

A seller can update their off by calling the setOffer function again, and they can revoke their offer altogether by calling the revokeOffer function.

Step 3: Buyers approve this contract

The buyer of coupons must approve the CouponTrader contract to move their USDC via the approve function of the USDC contract. This only has to be done once.

Step 4: Buyer takes the offer

Once the buyer has approved the CouponTrader contract, they can take an offer by calling the takeOffer function and passing in the details of the trade. The details must match the seller's current offer or else the transaction will revert (this is for the buyer's safety, as it prevents them from getting frontrun by a malicious seller).

The CouponTrader contract will take 1% of the _totalUSDCRequiredFromSeller a fee -- so the buyer will have _totalUSDCRequiredFromSeller pulled from their account and the seller will receive 99% of that. The coupons will be transferred from the seller to the buyer.

At no time does this contract take possession of the coupons or the USDC.

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.