Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
support engram v2
Browse files Browse the repository at this point in the history
  • Loading branch information
avenbreaks committed Jan 12, 2024
0 parents commit 7bf4f0d
Show file tree
Hide file tree
Showing 75 changed files with 13,289 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": [] // "transform-jsbi-to-bigint"
}
43 changes: 43 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI
env:
CI: true

on:
pull_request:
branches:
- v2
push:
branches:
- v2

jobs:
test:
strategy:
matrix:
node: ['10.x', '12.x']
os: [ubuntu-latest, macOS-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- run: npm install -g yarn

- id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-
- run: yarn

- run: yarn lint
- run: yarn build
- run: yarn test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

node_modules
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"solidity.compileUsingRemoteVersion": "v0.5.16+commit.9c3226ce"
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ignore-scripts true
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Noah Zinsmeister

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Uniswap SDK

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Actions Status](https://github.com/Uniswap/uniswap-sdk/workflows/CI/badge.svg)](https://github.com/Uniswap/uniswap-sdk)
[![npm version](https://img.shields.io/npm/v/@uniswap/sdk/latest.svg)](https://www.npmjs.com/package/@uniswap/sdk/v/latest)
[![npm bundle size (scoped version)](https://img.shields.io/bundlephobia/minzip/@uniswap/sdk/latest.svg)](https://bundlephobia.com/result?p=@uniswap/sdk@latest)

In-depth documentation on this SDK is available at [uniswap.org](https://uniswap.org/docs/v2/SDK/getting-started/).

## Running tests

To run the tests, follow these steps. You must have at least node v10 and [yarn](https://yarnpkg.com/) installed.

First clone the repository:

```sh
git clone https://github.com/Uniswap/uniswap-sdk.git
```

Move into the uniswap-sdk working directory

```sh
cd uniswap-sdk/
```

Install dependencies

```sh
yarn install
```

Run tests

```sh
yarn test
```

You should see output like the following:

```sh
yarn run v1.22.4
$ tsdx test
PASS test/constants.test.ts
PASS test/pair.test.ts
PASS test/fraction.test.ts
PASS test/miscellaneous.test.ts
PASS test/entities.test.ts
PASS test/trade.test.ts

Test Suites: 1 skipped, 6 passed, 6 of 7 total
Tests: 3 skipped, 82 passed, 85 total
Snapshots: 0 total
Time: 5.091s
Ran all test suites.
✨ Done in 6.61s.
```
40 changes: 40 additions & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import JSBI from 'jsbi';
export declare type BigintIsh = JSBI | bigint | string;
export declare enum ChainId {
ENGRAM = 131,
MAINNET = 1,
ROPSTEN = 3,
RINKEBY = 4,
GÖRLI = 5,
KOVAN = 42,
TECO = 188355
}
export declare enum TradeType {
EXACT_INPUT = 0,
EXACT_OUTPUT = 1
}
export declare enum Rounding {
ROUND_DOWN = 0,
ROUND_HALF_UP = 1,
ROUND_UP = 2
}
export declare const FACTORY_ADDRESS = "0x548C67Cbd80e8018b9792caeA0314569505F06B9";
export declare const INIT_CODE_HASH = "0x8ce6b67d11dffc78178e3df9094bcbef2889085d183a3076b2fdfd68db8aa2b4";
export declare const MINIMUM_LIQUIDITY: JSBI;
export declare const ZERO: JSBI;
export declare const ONE: JSBI;
export declare const TWO: JSBI;
export declare const THREE: JSBI;
export declare const FIVE: JSBI;
export declare const TEN: JSBI;
export declare const _100: JSBI;
export declare const _997: JSBI;
export declare const _1000: JSBI;
export declare enum SolidityType {
uint8 = "uint8",
uint256 = "uint256"
}
export declare const SOLIDITY_TYPE_MAXIMA: {
uint8: JSBI;
uint256: JSBI;
};
23 changes: 23 additions & 0 deletions dist/entities/currency.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.
*
* The only instance of the base class `Currency` is Ether.
*/
export declare class Currency {
readonly decimals: number;
readonly symbol?: string;
readonly name?: string;
/**
* The only instance of the base class `Currency`.
*/
static readonly ETHER: Currency;
/**
* Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
protected constructor(decimals: number, symbol?: string, name?: string);
}
declare const ETHER: Currency;
export { ETHER };
19 changes: 19 additions & 0 deletions dist/entities/fractions/currencyAmount.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Currency } from '../currency';
import JSBI from 'jsbi';
import { BigintIsh, Rounding } from '../../constants';
import { Fraction } from './fraction';
export declare class CurrencyAmount extends Fraction {
readonly currency: Currency;
/**
* Helper that calls the constructor with the ETHER currency
* @param amount ether amount in wei
*/
static ether(amount: BigintIsh): CurrencyAmount;
protected constructor(currency: Currency, amount: BigintIsh);
get raw(): JSBI;
add(other: CurrencyAmount): CurrencyAmount;
subtract(other: CurrencyAmount): CurrencyAmount;
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
toExact(format?: object): string;
}
19 changes: 19 additions & 0 deletions dist/entities/fractions/fraction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import JSBI from 'jsbi';
import { BigintIsh, Rounding } from '../../constants';
export declare class Fraction {
readonly numerator: JSBI;
readonly denominator: JSBI;
constructor(numerator: BigintIsh, denominator?: BigintIsh);
get quotient(): JSBI;
get remainder(): Fraction;
invert(): Fraction;
add(other: Fraction | BigintIsh): Fraction;
subtract(other: Fraction | BigintIsh): Fraction;
lessThan(other: Fraction | BigintIsh): boolean;
equalTo(other: Fraction | BigintIsh): boolean;
greaterThan(other: Fraction | BigintIsh): boolean;
multiply(other: Fraction | BigintIsh): Fraction;
divide(other: Fraction | BigintIsh): Fraction;
toSignificant(significantDigits: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces: number, format?: object, rounding?: Rounding): string;
}
5 changes: 5 additions & 0 deletions dist/entities/fractions/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './fraction';
export * from './percent';
export * from './tokenAmount';
export * from './currencyAmount';
export * from './price';
6 changes: 6 additions & 0 deletions dist/entities/fractions/percent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Rounding } from '../../constants';
import { Fraction } from './fraction';
export declare class Percent extends Fraction {
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
}
19 changes: 19 additions & 0 deletions dist/entities/fractions/price.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BigintIsh, Rounding } from '../../constants';
import { Currency } from '../currency';
import { Route } from '../route';
import { Fraction } from './fraction';
import { CurrencyAmount } from './currencyAmount';
export declare class Price extends Fraction {
readonly baseCurrency: Currency;
readonly quoteCurrency: Currency;
readonly scalar: Fraction;
static fromRoute(route: Route): Price;
constructor(baseCurrency: Currency, quoteCurrency: Currency, denominator: BigintIsh, numerator: BigintIsh);
get raw(): Fraction;
get adjusted(): Fraction;
invert(): Price;
multiply(other: Price): Price;
quote(currencyAmount: CurrencyAmount): CurrencyAmount;
toSignificant(significantDigits?: number, format?: object, rounding?: Rounding): string;
toFixed(decimalPlaces?: number, format?: object, rounding?: Rounding): string;
}
9 changes: 9 additions & 0 deletions dist/entities/fractions/tokenAmount.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CurrencyAmount } from './currencyAmount';
import { Token } from '../token';
import { BigintIsh } from '../../constants';
export declare class TokenAmount extends CurrencyAmount {
readonly token: Token;
constructor(token: Token, amount: BigintIsh);
add(other: TokenAmount): TokenAmount;
subtract(other: TokenAmount): TokenAmount;
}
6 changes: 6 additions & 0 deletions dist/entities/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from './token';
export * from './pair';
export * from './route';
export * from './trade';
export * from './currency';
export * from './fractions';
41 changes: 41 additions & 0 deletions dist/entities/pair.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Price } from './fractions/price';
import { TokenAmount } from './fractions/tokenAmount';
import { BigintIsh, ChainId } from '../constants';
import { Token } from './token';
export declare class Pair {
readonly liquidityToken: Token;
private readonly tokenAmounts;
static getAddress(tokenA: Token, tokenB: Token): string;
constructor(tokenAmountA: TokenAmount, tokenAmountB: TokenAmount);
/**
* Returns true if the token is either token0 or token1
* @param token to check
*/
involvesToken(token: Token): boolean;
/**
* Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0
*/
get token0Price(): Price;
/**
* Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1
*/
get token1Price(): Price;
/**
* Return the price of the given token in terms of the other token in the pair.
* @param token token to return price of
*/
priceOf(token: Token): Price;
/**
* Returns the chain ID of the tokens in the pair.
*/
get chainId(): ChainId;
get token0(): Token;
get token1(): Token;
get reserve0(): TokenAmount;
get reserve1(): TokenAmount;
reserveOf(token: Token): TokenAmount;
getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Pair];
getInputAmount(outputAmount: TokenAmount): [TokenAmount, Pair];
getLiquidityMinted(totalSupply: TokenAmount, tokenAmountA: TokenAmount, tokenAmountB: TokenAmount): TokenAmount;
getLiquidityValue(token: Token, totalSupply: TokenAmount, liquidity: TokenAmount, feeOn?: boolean, kLast?: BigintIsh): TokenAmount;
}
14 changes: 14 additions & 0 deletions dist/entities/route.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ChainId } from '../constants';
import { Currency } from './currency';
import { Token } from './token';
import { Pair } from './pair';
import { Price } from './fractions/price';
export declare class Route {
readonly pairs: Pair[];
readonly path: Token[];
readonly input: Currency;
readonly output: Currency;
readonly midPrice: Price;
constructor(pairs: Pair[], input: Currency, output?: Currency);
get chainId(): ChainId;
}
35 changes: 35 additions & 0 deletions dist/entities/token.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ChainId } from '../constants';
import { Currency } from './currency';
/**
* Represents an ERC20 token with a unique address and some metadata.
*/
export declare class Token extends Currency {
readonly chainId: ChainId;
readonly address: string;
constructor(chainId: ChainId, address: string, decimals: number, symbol?: string, name?: string);
/**
* Returns true if the two tokens are equivalent, i.e. have the same chainId and address.
* @param other other token to compare
*/
equals(other: Token): boolean;
/**
* Returns true if the address of this token sorts before the address of the other token
* @param other other token to compare
* @throws if the tokens have the same address
* @throws if the tokens are on different chains
*/
sortsBefore(other: Token): boolean;
}
/**
* Compares two currencies for equality
*/
export declare function currencyEquals(currencyA: Currency, currencyB: Currency): boolean;
export declare const WETH: {
1: Token;
3: Token;
4: Token;
5: Token;
42: Token;
188355: Token;
131: Token;
};
Loading

0 comments on commit 7bf4f0d

Please sign in to comment.