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

@airswap/peer

v0.3.0

Published

Manages delegated trading rules for use in the Swap Protocol

Downloads

7

Readme

Peer

: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 basic Peer contract that can be deployed with trading rules. In addition, there is a PeerFactory contract that deploys Peer contracts as well.

:bulb: Note: solidity-coverage does not cooperate with view functions. To run test coverage, remove the view keywords from functions in Peer.sol, IPeer.sol, and PeerFactory.sol.

Discord License

Peer

Features

Limit Orders

Set rules to only take trades at specific prices.

Partial Fills

Send up to a maximum amount of a token.

Definitions

| Term | Definition | | :---------------- | :------------------------------------------------------------------------- | | Peer | Smart contract that trades based on rules. Acts as taker. | | Consumer | A party that gets quotes from and sends orders to the peer. Acts as maker. | | Rule | An amount of tokens to trade at a specific price. | | Price Coefficient | The significant digits of the price. | | Price Exponent | The location of the decimal on the price. |

Constructor

Create a new Peer contract.

constructor(
  address _swapContract,
  address _peerContractOwner
) public

Params

| Name | Type | Description | | :------------------- | :-------- | :---------------------------------------------------- | | _swapContract | address | Address of the swap contract used to settle trades. | | _peerContractOwner | address | Address of the owner of the peer for rule management. |

Price Calculations

All amounts are in the smallest unit (e.g. wei), so all calculations based on price result in a whole number. For calculations that would result in a decimal, the amount is automatically floored by dropping the decimal. For example, a price of 5.25 and takerParam of 2 results in makerParam of 10 rather than 10.5. Tokens have many decimal places so these differences are very small.

Set a Rule

Set a trading rule on the peer.

function setRule(
  address _takerToken,
  address _makerToken,
  uint256 _maxTakerAmount,
  uint256 _priceCoef,
  uint256 _priceExp
) external onlyOwner

Params

| Name | Type | Description | | :---------------- | :-------- | :------------------------------------------------------------- | | _takerToken | address | The token the peer would send. | | _makerToken | address | The token the consumer would send. | | _maxTakerAmount | uint256 | The maximum amount of token the peer would send. | | _priceCoef | uint256 | The coefficient of the price to indicate the whole number. | | _priceExp | uint256 | The exponent of the price to indicate location of the decimal. |

Example

Set a rule to send up to 100,000 DAI for WETH at 0.0032 WETH/DAI

setRule(<WETHAddress>, <DAIAddress>, 100000, 32, 4)

Set a rule to send up to 100,000 DAI for WETH at 312.50 WETH/DAI

setRule(<WETHAddress>, <DAIAddress>, 100000, 32150, 2)

Set a rule to send up to 100,000 DAI for WETH at 312 WETH/DAI

setRule(<WETHAddress>, <DAIAddress>, 100000, 312, 0)

Unset a Rule

Unset a trading rule for the peer.

function unsetRule(
  address _takerToken,
  address _makerToken
) external onlyOwner

Params

| Name | Type | Description | | :------------ | :-------- | :--------------------------------- | | _takerToken | address | The token the peer would send. | | _makerToken | address | The token the consumer would send. |

Get a Maker-Side Quote

Get a quote for the maker (consumer) side. Often used to get a buy price for _quoteTakerToken.

function getMakerSideQuote(
  uint256 _quoteTakerParam,
  address _quoteTakerToken,
  address _quoteMakerToken
) external view returns (
  uint256 quoteMakerParam
)

Params

| Name | Type | Description | | :----------------- | :-------- | :------------------------------------------------------ | | _quoteTakerParam | uint256 | The amount of ERC-20 token the peer would send. | | _quoteTakerToken | address | The address of an ERC-20 token the peer would send. | | _quoteMakerToken | address | The address of an ERC-20 token the consumer would send. |

Reverts

| Reason | Scenario | | :-------------------- | :----------------------------------------------- | | TOKEN_PAIR_INACTIVE | There is no rule set for this token pair. | | AMOUNT_EXCEEDS_MAX | The quote would exceed the maximum for the rule. |

Get a Taker-Side Quote

Get a quote for the taker (peer) side. Often used to get a sell price for _quoteMakerToken.

function getTakerSideQuote(
  uint256 _quoteMakerParam,
  address _quoteMakerToken,
  address _quoteTakerToken
) external view returns (
  uint256 quoteTakerParam
)

Params

| Name | Type | Description | | :----------------- | :-------- | :------------------------------------------------------ | | _quoteMakerParam | uint256 | The amount of ERC-20 token the consumer would send. | | _quoteMakerToken | address | The address of an ERC-20 token the consumer would send. | | _quoteTakerToken | address | The address of an ERC-20 token the peer would send. |

Reverts

| Reason | Scenario | | :-------------------- | :----------------------------------------------- | | TOKEN_PAIR_INACTIVE | There is no rule set for this token pair. | | AMOUNT_EXCEEDS_MAX | The quote would exceed the maximum for the rule. |

Get a Max Quote

Get the maximum quote from the peer.

function getMaxQuote(
  address _quoteTakerToken,
  address _quoteMakerToken
) external view returns (
  uint256 quoteTakerParam,
  uint256 quoteMakerParam
)

Params

| Name | Type | Description | | :----------------- | :-------- | :------------------------------------------------------ | | _quoteTakerToken | address | The address of an ERC-20 token the peer would send. | | _quoteMakerToken | address | The address of an ERC-20 token the consumer would send. |

Reverts

| Reason | Scenario | | :-------------------- | :---------------------------------------- | | TOKEN_PAIR_INACTIVE | There is no rule set for this token pair. |

Provide an Order

Provide an order to the peer for taking.

function provideOrder(
  Types.Order memory _order
) public

Params

| Name | Type | Description | | :------ | :------ | :--------------------------------------------------------- | | order | Order | Order struct as specified in the @airswap/types package. |

Reverts

| Reason | Scenario | | :-------------------- | :------------------------------------------------------------- | | TOKEN_PAIR_INACTIVE | There is no rule set for this token pair. | | AMOUNT_EXCEEDS_MAX | The amount of the trade would exceed the maximum for the rule. | | PRICE_INCORRECT | The order is priced incorrectly for the rule. |

Peer Factory

Features

Deploys Peer Contracts

Creates peers with a trusted interface

Has lookup to find peer contracts it has deployed

Definitions

| Term | Definition | | :--- | :-------------------------------------------------------- | | Peer | Smart contract that trades based on rules. Acts as taker. |

Constructor

Create a new Peer contract.

constructor(
  address _swapContract,
  address _peerContractOwner
) public

Create a new Peer contract.

createPeer(
  address _swapContract,
  address _peerContractOwner
) external returns
  (address peerContractAddress)

Params

| Name | Type | Description | | :------------------- | :-------- | :---------------------------------------------------- | | _swapContract | address | Address of the swap contract used to settle trades. | | _peerContractOwner | address | Address of the owner of the peer for rule management. |

Lookup for deployed peers

To check whether a locator was deployed

function has(
  bytes32 _locator
) external returns (bool)

Params

| Name | Type | Description | | :--------- | :-------- | :----------------------------------------------- | | _locator | bytes32 | locator of the peer in question, ex an address |