# @exoda-app/tokens

> `@exoda-app/tokens` is a TypeScript library that provides a simple and convenient way to instantiate `ERC20` and `Uniswap V2 Pair` tokens.

Latest version **0.0.22** (published 2023-07-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install @exoda-app/tokens
pnpm add @exoda-app/tokens
yarn add @exoda-app/tokens
bun add @exoda-app/tokens
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.22 |
| Published | 2023-07-17 |
| First published | 2023-03-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 334.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ian Guimaraes |
| Maintainers | iankressin |

## Links

- npm: https://www.npmjs.com/package/@exoda-app/tokens
- npm.io page: https://npm.io/package/@exoda-app/tokens

## Dependencies (3)

- [ethers](https://npm.io/package/ethers.md) ^5.1.3
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.1.1
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.7.2

## Recent versions

- 0.0.22 (latest) — 2023-07-17
- 0.0.21 — 2023-07-17
- 0.0.20 — 2023-07-17
- 0.0.18 — 2023-04-17
- 0.0.17 — 2023-04-04
- 0.0.16 — 2023-04-04
- 0.0.15 — 2023-04-04
- 0.0.14 — 2023-04-03
- 0.0.13 — 2023-03-29
- 0.0.12 — 2023-03-28
- 0.0.11 — 2023-03-28
- 0.0.10 — 2023-03-28
- 0.0.9 — 2023-03-28
- 0.0.8 — 2023-03-26
- 0.0.7 — 2023-03-26
- … 5 more at https://npm.io/package/@exoda-app/tokens/versions

## README

# 🪙 @exoda-app/tokens
`@exoda-app/tokens` is a TypeScript library that provides a simple and convenient way to instantiate `ERC20` and `Uniswap V2 Pair` tokens.

## ⚙ Install
```bash
npm install @exoda-app/tokens
```

## 💻 Usage
```ts
import { Token, TokenPool, Chain } from '@exoda-app/tokens'

const token = await Token.init({ address: '0x...', chain: Chains.ETH })

// You can optionally pass a custom rpc for both Token and TokenPool initializers
const poolToken = await TokenPool.init({ address: '0x...', chain: Chains.ETH, rpc: 'https://rpc.ankr.com/eth' })
```

## 👥 Models

### BaseToken
Both `Token` and `TokenPool` extends `BaseToken`, therefore the methods and instance variables of this class can invoken from these two classes.

#### Fields
- `chain: Chain` - Blockchain network id where the token resides.
- `address: string` - Token's contract address.
- `name: string` - Name of the token.
- `decimals: number` - Number of decimal places used by the token.
- `totalSupply: string` - Total supply of the token.
- `allowance: number | undefined` - Amount of tokens that another address is allowed to spend on behalf of the token owner.
- `balance: number | undefined` - Balance of the token held by the user.
- `rawBalance: string | undefined` - Balance of the token in raw, token base points format.
- `rawAllowance: string | undefined` - Allowance of the token in raw, token base points format.
- `symbol: string` - Token's symbol.
- `price: number | null`- Token's current price, if available.

#### Methods
- `setBalance(rawBalance: string)`: receives a balance in token basis points, sets `rawBalance`, converts to base 10 and sets `balance`
- `setAllowance(rawAllowance: string)`: receives a allowance in token basis points, sets `rawAllowance`, converts to base 10 and sets `allowance`
___

### Token
Represents an `ERC20` token. Extends `BaseToken`

#### Methods
- `updateBalance(user: string)`: fetches user's balance from contract and call `BaseToken.setBalance` with the value received
- `updateAllowance(user: string)`: fetches user's allowance from contract and call `BaseToken.setAllowance` with the value received
___

### TokenPool
Represents an `Uniswap V2 Pair` token. Extends `BaseToken`

#### Fields
- `token0: Token`: First token in the pool
- `token1: Token` Second token in the pool
- reserves:  The reserves of each tokens in the pool

#### Methods
- `updateBalance(user: string)`: fetches user balance from contract and call `BaseToken.setBalance` with the value received
- `updateAllowance(user: string)`: fetches user allowance from contract and call `BaseToken.setAllowance` with the value received
____

## 🔗 Supported chains for token prices
- `ETH`
- `POLYGON`
- `BSC`
- `OPTIMISM`
- `ARBITRUM`

---
_Source: https://npm.io/package/@exoda-app/tokens · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
