Skip to main content

46 docs tagged with "nevm"

View all tags

API Overview

This section explains the Pegasys Subgraph and how to interact with it. The Pegasys subgraph indexes data from the Pegasys contracts over time. It organizes data about pairs, tokens, Pegasys as a whole, and more. The subgraph updates any time a transaction is made on Pegasys. The subgraph runs on The Graph protocol's hosted service and can be openly queried.

Common Errors

This document covers a few error codes frequently encountered while building on Pegasys.

Custom Linking

The Pegasys front-end supports URL query parameters to allow for custom linking to the Pegasys frontend. Users and developers can use these query parameters to link to the Pegasys

Ecosystem Participants

The Pegasys ecosystem is primarily comprised of three types of users: liquidity providers, traders, and developers. Liquidity providers are incentivized to contribute ERC-20 tokens to common liquidity pools. Traders can swap these tokens for one another for a fixed 0.25% fee (which goes to liquidity providers). Developers can integrate directly with Pegasys smart contracts to power new and exciting interactions with tokens, trading interfaces, retail experiences, and more.

Entities

Entities define the schema of the subgraph, and represent the data that can be queried. Within each entity are sets of fields that store useful information related to the entity. Below is a list of the available entities within the Pegasys Subgraph, and descriptions for the available fields.

Fees

Liquidity provider fees

Fetcher

The data fetching logic is split from the rest of the code for better tree-shaking,

Flash Swaps

Pegasys flash swaps allow you to withdraw up to the full reserves of any ERC20 token on Pegasys and execute arbitrary logic at no upfront cost, provided that by the end of the transaction you either:

Flash Swaps

Flash swaps are an integral feature of Pegasys. In fact, under the hood, all swaps are actually flash swaps! This simply means that pair contracts send output tokens to the recipient before enforcing that enough input tokens have been received. This is slightly atypical, as one might expect a pair to ensure it's received payment before delivery. However, because Syscoin transactions are atomic, we can roll back the entire swap if it turns out that the contract hasn't received enough tokens to make itself whole by the end of the transaction.

Fractions

The base class which all subsequent fraction classes extend. Not meant to be used directly.

Getting Started

The pages that follow contain technical reference information on the Pegasys SDK.

How Pegasys works

Pegasys is an automated liquidity protocol powered by a constant product formula and implemented in a system of non-upgradeable smart contracts on the Syscoin blockchain.

Iframe Integration

Pegasys can be used within other sites as an iframe. An iframe shows an exact version of the Pegasys frontend site and can have custom prefilled settings.

Implement a Swap

When trading from a smart contract, the most important thing to keep in mind is that access to an external price source is required. Without this, trades can be frontrun for considerable loss.

Math

This section will be expanded in the future. In the mean time, the Uniswap V2 whitepaper has most relevant math for Pegasys.

Oracles

A price oracle is any tool used to view price information about a given asset. When you look at stock prices on your phone, you are using your phone as a price oracle. Similarly, the app on your phone relies on devices to retrieve price information - likely several, which are aggregated and then displayed to you, the end-user. These are price oracles as well.

Overview

0xE18c200A70908c89fFA18C628fE1B83aC0065EA4

Pair

The Pair entity represents a Pegasys pair with a balance of each of its pair tokens.

Pair

This documentation covers Pegasys-specific functionality. For ERC-20 functionality, see Pair (ERC-20).

Pair (ERC-20)

This documentation covers ERC-20 functionality for denominating pool tokens. For Pegasys-specific functionality, see Pair.

Pegasys API

API for querying key values for Pegasys and the PSYS token

Pools

Each Pegasys liquidity pool is a trading venue for a pair of ERC20 tokens. When a pool contract is created, its balances of each token are 0; in order for the pool to begin facilitating trades, someone must seed it with an initial deposit of each token. This first liquidity provider is the one who sets the initial price of the pool. They are incentivized to deposit an equal value of both tokens into the pool. To see why, consider the case where the first liquidity provider deposits tokens at a ratio different from the current market rate. This immediately creates a profitable arbitrage opportunity, which is likely to be taken by an external party.

Pricing

As we learned in Protocol Overview, each pair on Pegasys is actually underpinned by a liquidity pool. Liquidity pools are smart contracts that hold balances of two unique tokens and enforces rules around depositing and withdrawing them. The primary rule is the constant product formula. When a token is withdrawn (bought), a proportional amount must be deposited (sold) to maintain the constant. The ratio of tokens in the pool, in combination with the constant product formula, ultimately determine the price that a swap executes at.

Process

This document is a living document which represents the current process guidelines for developing and advancing Pegasys Governance Proposals.

Queries

The subgraph can be queried to retrieve important information about Pegasys, pairs, tokens, transactions, users, and more. This page will provide examples for common queries.

Research

The automated market maker is a new concept, and as such, new research comes out frequently. We've selected some of the most thoughtful here.

Route

The Route entity represents one or more ordered Pegasys pairs with a fully specified path from input token to output token.

Router

Because routers are stateless and do not hold token balances, they can be replaced safely and trustlessly, if necessary. This may happen if more efficient smart contract patterns are discovered, or if additional functionality is desired.

SDK Quick start

The Pegasys SDK exists to help developers build on top of Pegasys. It's designed to run in any environment that can execute JavaScript (think websites, node scripts, etc.). While simple enough to use in a hackathon project, it's also robust enough to power production applications.

Security

Between January 8 and April 30, a team of six engineers reviewed and formally verified crucial components of the smart contracts for Uniswap V2.

Smart Contract Quick start

Developing smart contracts for Syscoin involves a bevy of off-chain tools used for producing and testing bytecode

Smart contracts

Pegasys is a binary smart contract system. Core contracts provide fundamental safety guarantees for all parties interacting with Pegasys. Periphery contracts interact with one or more core contracts but are not themselves part of the core.

Swaps

Token swaps in Pegasys are a simple way to trade one ERC-20 token for another.

Token

The Token entity represents an ERC-20 token at a specific address on a specific chain.

Trade

The Trade entity represents a fully specified trade along a route. This entity supplies all the information necessary to craft a router transaction.

Understanding Returns

Pegasys incentivizes users to add liquidity to trading pools by rewarding providers with the fees generated when other users trade with those pools. Market making, in general, is a complex activity. There is a risk of losing money during large and sustained movement in the underlying asset price compared to simply holding an asset.

Using the API

In this guide we will create a web interface that consumes and displays data from the Pegasys Subgraph. The goal is to provide a quick overview of a setup that you can extend to create your own UIs and analytics around Pegasys data.