0.2.0 • Published 5 years ago

@airswap/market v0.2.0

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

Market

:warning: This package is under active development. Do not use in production.

AirSwap is a peer-to-peer trading network for Ethereum tokens. This package contains source code and tests for a Market that represents a list of intents to trade.

Discord License

Features

Sorting

Intents are sorted by their amount, with the largest amount at the beginning of the list. Currently the staking amount is indicated by an Indexer that owns the Market.

Definitions

TermDefinition
IntentAn interest in trading a specific token pair without price information.
MarketA list of intents to trade for a token pair.
LocatorHow a peer can be reached to communicate pricing.

Intent Struct

An "intent to trade" is represented by the following Intent struct.

struct Intent {
  address staker;
  uint256 amount;
  address locator;
}

Constructor

Create a new Market contract. Usually called within the context of an Indexer contract.

constructor(
  address _makerToken,
  address _takerToken
) public

Params

NameTypeDescription
_makerTokenaddressAddress of the token that the Maker is intended to send.
_takerTokenaddressAddress of the token that the Taker is intended to send.

Set an Intent

Set an intent to trade in the Market.

function setIntent(
  address _staker,
  uint256 _amount,
  address _locator
) external onlyOwner

Params

NameTypeDescription
_stakeraddressAddress of the account that has staked for the intent.
_amountuint256Amount of token that the account has staked.
_locatoraddressLocator for the peer.

Unset an Intent

Unset an intent to trade in the Market.

function unsetIntent(
  address _staker
) public onlyOwner returns (bool)

Params

NameTypeDescription
_stakeraddressAddress of the account that will unstake its intent.

Get an Intent

Gets the intent for a given staker address.

function getIntent(
  address _staker
) public view returns (Intent memory)

Params

NameTypeDescription
_stakeraddressAddress of the account to fetch an intent

Has an Intent

Determines whether the Market has an intent for a staker address.

function hasIntent(
  address _staker
) internal view returns (bool)

Params

NameTypeDescription
_stakeraddressAddress of the account to check an intent

Fetch Intents

Fetch up to a number of intents from the list.

function fetchIntents(
  uint256 _count
) public view returns (address[] memory result)

Params

NameTypeDescription
_countuint256Number of intents to fetch.

Find an Intent (By Value)

Find an intent by value in the list.

function findPosition(
  uint256 amount
) internal view returns (Intent memory)

Params

NameTypeDescription
_countuint256Number of intents to fetch.

Insert an Intent

Insert an intent before an existing intent in the list.

function insertIntent(
  Intent memory _newIntent,
  Intent memory _nextIntent
) internal returns (bool)

Params

NameTypeDescription
_newIntentIntentIntent to insert.
_nextIntentIntentExisting intent to insert before.

Link Two Intents

Link two intents in the list.

function link(
  Intent memory _left,
  Intent memory _right
) internal

Params

NameTypeDescription
_leftIntentThe intent to link to the left (Higher value).
_rightIntentThe intent to link to the right (Lower value).