1.0.0 • Published 4 years ago

airswap-maker-kit v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

AirSwap Maker Kit

:warning: Maker Kit is in beta for use on Rinkeby only.

Maker Kit includes tools and examples to help you get started on the AirSwap Network.

Discord License Twitter Follow

Using This Package

AirSwap is a peer-to-peer trading network for Ethereum (ERC20, ERC721) tokens. Using an Indexer smart contract, peers can find each other based on their mutual intent to trade specific tokens. Once found, peers exchange pricing information and settle trades on a Swap contract.

This package includes a set of scripts/ and a file handlers.js that implements the latest AirSwap protocol, both as an example and a dependency of AirSwap Maker Kit Examples. Scripts available in this package include functionality to interact with peers, indexers, and tokens. See Commands below.

Concepts

  • Quotes are indicative prices and Orders are signed and executable for trading. Makers should be able to provide both.
  • Intent is an interest in trading including contact information, without pricing. Indexers help you manage intent.
  • Locators are public URLs shorter than 32 characters in length including URL scheme. This is where your maker runs.

Setup

Installation

Requires Node.js v8.10.0 or above and NPM or Yarn.

git clone https://github.com/airswap/airswap-maker-kit
cd airswap-maker-kit
yarn install

Environment variables are loaded from a .env file in the root directory. The following must be set:

  • ETHEREUM_ACCOUNT - The private key of an account to use for staking and trading.

There is an example .env-example that you can copy to .env to start with.

Ethereum Account

To use an existing Ethereum account, set the ETHEREUM_ACCOUNT in your .env file. Otherwise create a random account using the yarn utils:account script. Paste the generated private key into your .env file.

Contract Versions

The Swap and Indexer contracts used by Maker Kit are specified within their respective packages, @airswap/swap and @airswap/indexer in the AirSwap Protocols repository.

Commands

CommandDescription
yarnInstall dependencies
yarn peers:getGet quotes and orders from peers
yarn indexer:createCreate a new token pair index
yarn indexer:enableEnable staking on the indexer
yarn indexer:setSet an intent to trade
yarn indexer:unsetUnset an intent to trade
yarn indexer:getGet locators
yarn token:approveApprove a token for trading
yarn token:checkCheck a token approval
yarn utils:networkGet network addresses
yarn utils:accountCreate a random account

Helpful for Testing on Rinkeby

  • ETH to pay for transactions - Faucet
  • WETH for trading - 0xc778417e063141139fce010982780140aa0cd5ab Etherscan
  • DAI for trading - 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea Etherscan
  • AST for staking - 0xcc1cbd4f67cceb7c001bd4adf98451237a193ff8 Etherscan / Faucet

Quick Start: Quoting

AirSwap Maker Kit Examples has examples available to get started. For the following guide, start up the Express example for Node.js on your local machine.

Get a quote from your maker

In another shell, run the yarn peers:get script to test it out. Use the default values for everything but provide a locator value of http://0.0.0.0:8080/ to connect to your newly running maker.

$ yarn peers:get

AirSwap: Get Quotes and Orders
Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Rinkeby

Select a kind (quote, order):  (quote)
Select a side (buy, sell):  (buy)
Query a locator (optional):  http://0.0.0.0:8080/
Token to buy:  (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea)
Token to pay:  (0xc778417e063141139fce010982780140aa0cd5ab)
Amount to buy:  (100)

Got a Quote

buy: 100 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea
pay: 10 0xc778417e063141139fce010982780140aa0cd5ab
price: 0.1

This succeeds because we have a locator in hand, the URL of your local webserver. However, if we do no thave a locator in hand, we need to use an indexer to find other trading parties.

Set your intent to trade

By default, your maker is running in isolation. Run peers:get with default values, which will display No peers found..

$ yarn peers:get

To be found, announce your maker to the world by setting your "intent to trade" on the indexer.

$ yarn indexer:set

AirSwap: Set Intent to Trade
Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Rinkeby

Token address of signerToken (maker side):  (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea)
Token address of senderToken (taker side):  (0xc778417e063141139fce010982780140aa0cd5ab)
Web address of your server (URL):  (http://10.0.0.169:8080)
Amount of token to stake (AST):  (0)

Set an Intent

signerToken: 0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea
senderToken: 0xc778417e063141139fce010982780140aa0cd5ab
locator: http://10.0.0.169:8080
stakeAmount: 0
...

The transaction will be mined and your locator is now on the indexer.

$ yarn indexer:get

AirSwap: Get Locators
Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2 Rinkeby

Address of signerToken:  (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea)
Address of senderToken:  (0xc778417e063141139fce010982780140aa0cd5ab)
Number of locators to return:  (10)
1. http://10.0.0.169:8080
...

Get quotes from all makers (including yours)

Ensure your maker is still running.

Now run the same peers:get with default values, which will display your quote.

$ yarn peers:get

AirSwap: Get Quotes and Orders
Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2

Select a network (rinkeby, mainnet):  (rinkeby)
Select a kind (quote, order):  (quote)
Select a side (buy, sell):  (buy)
Query a locator (optional):
Token to buy:  (0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea)
Token to pay:  (0xc778417e063141139fce010982780140aa0cd5ab)
Amount to buy:  (100)

✓ Quote from http://10.0.0.169:8080 (cost: 10, price: 0.1)

Advanced: Staking and Trading

Indexer Staking

Run the yarn indexer:enable script to enable staking on an Indexer. You'll use AirSwap Tokens (AST) to stake an intent to trade. On Rinkeby, use the Rinkeby AST Faucet to pick up some AST for staking.

$ yarn indexer:enable

AirSwap: Enable Staking
Current account 0x1FF808E34E4DF60326a3fc4c2b0F80748A3D60c2

Select a network (rinkeby, mainnet):  (rinkeby)

This will approve the Indexer contract to stake your AST.
...

Token Approvals

Tokens must be approved for trading on the Swap contract. This is a one-time transaction for each token. To approve the Swap contract to transfer your tokens, use the yarn token:approve script for both WETH and DAI addresses above. You can check the approval status of any token with the yarn token:check script.

1.0.0

4 years ago