# WarpGate SDK

<figure><img src="https://710732935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4oWnUjLPtiTi3oUs8LGy%2Fuploads%2FGPPnH5m7bZ6biDZlaQcl%2FWarpgate-SDK.jpg?alt=media&#x26;token=51ad4f1e-b30c-4b36-bb01-733eee913d18" alt=""><figcaption></figcaption></figure>

## WarpGate Swap SDK

[![npm version](https://camo.githubusercontent.com/adfcf990ec0cd85f79863365a220a1e67b9b236ba7d2dacc96b54a4cec002ba6/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f77617270676174652d737761702d73646b2e737667)](https://www.npmjs.com/package/warpgate-swap-sdk) [![License: MIT](https://camo.githubusercontent.com/6cd0120cc4c5ac11d28b2c60f76033b52db98dac641de3b2644bb054b449d60c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT) [![TypeScript](https://camo.githubusercontent.com/a11f926d30e57a454c6b5953bbec77329106b507bc39dffbbf13f1c150108925/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f547970655363726970742d342e392532422d626c7565)](https://www.typescriptlang.org/)

TypeScript SDK for interacting with WarpGate Swap on Movement blockchain. This SDK provides a simple and intuitive way to integrate WarpGate Swap functionality into your applications.

### Features

* Token Swapping with Best Price Routing
* Liquidity Pool Management
* Price Calculations and Pool Information
* Type-safe with TypeScript
* Comprehensive Documentation
* Full Test Coverage

### Installation

```
npm install warpgate-swap-sdk @aptos-labs/ts-sdk
```

### Core Operations

#### 1. Initialize Client

```
import { Aptos, AptosConfig, Network } from '@aptos-labs/ts-sdk'

// Initialize Aptos client
const config = new AptosConfig({ network: Network.MAINNET })
const client = new Aptos(config)

// For testnet
const testnetConfig = new AptosConfig({ network: Network.TESTNET })
const testnetClient = new Aptos(testnetConfig)

// For custom node
const customConfig = new AptosConfig({ 
  fullnode: "https://your-node-url",
  // Optional: Include if you need to submit transactions
  faucet: "https://your-faucet-url"  
})
const customClient = new Aptos(customConfig)
```

#### 2. Token Swap

```
import { 
  Coin,
  ChainId,
  Pair,
  Route,
  Trade,
  TradeType,
  Percent,
  Router,
  CurrencyAmount
} from 'warpgate-swap-sdk'

// Initialize tokens
const USDC = new Coin(
  ChainId.MAINNET,
  "0x1::coin::USDC",
  6,
  "USDC",
  "USD Coin"
)

const MOVE = new Coin(
  ChainId.MAINNET,
  "0x1::coin::MOVE",
  8,
  "MOVE",
  "Movement Token"
)

// Create a pair and route
const pair = new Pair(USDC, MOVE)
const route = new Route([pair], USDC, MOVE)

// Create a trade with 1 USDC
const trade = Trade.exactIn(
  route,
  CurrencyAmount.fromRawAmount(USDC, "1000000"), // 1 USDC (6 decimals)
  9975 // 0.25% fee
)

// Execute the swap with 0.5% slippage tolerance
const router = new Router()
const swapParams = router.swapCallParameters(trade, {
  allowedSlippage: new Percent('50', '10000') // 0.5%
})

// Submit transaction
const transaction = await client.generateTransaction(account.address, swapParams)
const pendingTx = await client.signAndSubmitTransaction(account, transaction)
const txResult = await client.waitForTransaction(pendingTx.hash)
```

#### 3. Add Liquidity

```
import { Router } from 'warpgate-swap-sdk'

const router = new Router()

// Add liquidity parameters
const addLiquidityParams = router.addLiquidityParameters(
  "1000000",      // Amount of token X (e.g., 1 USDC with 6 decimals)
  "100000000",    // Amount of token Y (e.g., 1 MOVE with 8 decimals)
  "995000",       // Minimum amount of token X (0.5% slippage)
  "99500000",     // Minimum amount of token Y (0.5% slippage)
  "0x1::coin::USDC",  // Token X address
  "0x1::coin::MOVE",  // Token Y address
  "30"           // Fee in basis points (0.3%)
)

// Submit transaction
const transaction = await client.generateTransaction(account.address, addLiquidityParams)
const pendingTx = await client.signAndSubmitTransaction(account, transaction)
const txResult = await client.waitForTransaction(pendingTx.hash)
```

#### 4. Remove Liquidity

```
import { Router } from 'warpgate-swap-sdk'

const router = new Router()

// Remove liquidity parameters
const removeLiquidityParams = router.removeLiquidityParameters(
  "1000000",      // LP token amount to remove
  "995000",       // Minimum amount of token X to receive (0.5% slippage)
  "99500000",     // Minimum amount of token Y to receive (0.5% slippage)
  "0x1::coin::USDC",  // Token X address
  "0x1::coin::MOVE"   // Token Y address
)

// Submit transaction
const transaction = await client.generateTransaction(account.address, removeLiquidityParams)
const pendingTx = await client.signAndSubmitTransaction(account, removeLiquidityParams)
const txResult = await client.waitForTransaction(pendingTx.hash)
```

#### 5. Advanced Swap Operations

```
import { Router, Trade, TradeType } from 'warpgate-swap-sdk'

// For exact input swaps (you specify exact input amount)
const exactInputTrade = Trade.exactIn(route, inputAmount, 9975) // 0.25% fee
const exactInputParams = router.swapCallParameters(exactInputTrade, {
  allowedSlippage: new Percent('50', '10000') // 0.5%
})

// For exact output swaps (you specify exact output amount)
const exactOutputTrade = Trade.exactOut(route, outputAmount, 9975) // 0.25% fee
const exactOutputParams = router.swapCallParameters(exactOutputTrade, {
  allowedSlippage: new Percent('50', '10000') // 0.5%
})
```

### Development

#### Setup

```
# Clone the repository
git clone https://github.com/hatchy-fun/warpgate-swap-sdk.git
cd warpgate-swap-sdk

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test
```

#### Scripts

* `npm run build` - Build the SDK
* `npm test` - Run tests
* `npm run lint` - Lint the code
* `npm run format` - Format the code

### Contributing

We welcome contributions! Please see our [Contributing Guide](https://github.com/hatchy-fun/warpgate-swap-sdk/blob/main/CONTRIBUTING.md) for details.

#### Development Process

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

### Security

For security concerns, please open a security advisory on GitHub.

### License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/hatchy-fun/warpgate-swap-sdk/blob/main/LICENSE) file for details.

### Support

* [GitHub Issues](https://github.com/hatchy-fun/warpgate-swap-sdk/issues)
* [Documentation](https://github.com/hatchy-fun/warpgate-swap-sdk#readme)
