npm package: @skate-org/skate-app-amm
Description: Core SDK for Skate's cross-chain Automated Market Maker (AMM) with NFT-based position management.
Latest version: 3.4.0

# @skate-org/skate-app-amm

Core SDK for Skate's cross-chain Automated Market Maker (AMM) with NFT-based position management.

## Installation

```bash
npm install @skate-org/skate-app-amm
```

## Quick Start

```typescript
import { SkateAmmCoreSDK } from "@skate-org/skate-app-amm";

const sdk = new SkateAmmCoreSDK("PRODUCTION"); // or "STAGING"
```

## Package Structure

```
src/
├── abi/                          # Smart contract ABIs
│   ├── skate-amm/               # V2 contract ABIs (unified)
│   │   ├── KernelManager.ts     # Core kernel contract
│   │   ├── KernelPool.ts        # Pool contract
│   │   └── PeripheryPool.ts     # Cross-chain periphery
│   └── uniswap/                 # Uniswap V3 compatibility
├── action/                       # Core AMM operations
│   └── kernel.ts                # Position management functions
├── adapter/                      # Protocol adapters
│   ├── kernelManager.ts         # Kernel contract adapter
│   └── peripheryPool.ts         # Periphery contract adapter
├── api/                         # REST API functions
├── deployment/                   # Contract addresses & config
├── types/                       # TypeScript definitions
└── classWrapper.ts              # Main SDK class
```

## Core Actions

### Position Management

#### Get NFT Positions (V2)

```typescript
import { SkateAmmCoreSDK } from "@skate-org/skate-app-amm";
import { createPublicClient, http } from "viem";
import { base } from "viem/chains";

const sdk = new SkateAmmCoreSDK("PRODUCTION");
const client = createPublicClient({
  chain: base,
  transport: http()
});

// Get all NFT positions for a user
const positions = await sdk.getNFTPositions(client, {
  user: "0x742d35Cc6639C0532fEb96A35d15b3DF1c99dd5F"
});

console.log(positions);
// [{ tokenId: 123n, pool: "0x...", tickLower: -100, tickUpper: 100, liquidity: 1000n }]
```

#### Get Pool Information

```typescript
// Get all available pools
const pools = sdk.getAllPoolInfo();

// Get specific pool by tokens
const pool = sdk.getPoolInfoByTokens(CHAIN.BASE, {
  tokenA: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
  tokenB: "0x4200000000000000000000000000000000000006"  // WETH
});
```

### Simulation & Quotes

#### Swap Simulation

```typescript
const swapResult = await sdk.simulateSwap(client, {
  kernelPool: "0x...",
  recipient: "0x..." // bytes32 format
  zeroForOne: true,
  amountSpecified: 1000000n, // 1 USDC (6 decimals)
  sqrtPriceLimitX96: 0n
});

console.log(`Amount out: ${swapResult.amount1}`);
```

#### Get Swap Quote

```typescript
const quote = await sdk.getSwapQuote(CHAIN.BASE, {
  tokenA: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
  tokenB: "0x4200000000000000000000000000000000000006", // WETH
  amount: 1000000n,
  slippageLimit: 0.01 // 1%
});

if (quote.success) {
  console.log(`Expected output: ${quote.expectedAmountOut}`);
}
```

### Contract Interactions

#### Generate Transaction Calldata

```typescript
// Swap calldata for KernelManager
const swapCalldata = sdk.getSwapCalldata({
  kernelPool: "0x...",
  bytes32Recipient: "0x...",
  bytes32User: "0x...",
  actionId: "0x...",
  srcChainId: 8453, // Base
  srcVmType: 1,     // EVM
  destChainId: 42161, // Arbitrum
  destVmType: 1,      // EVM
  zeroForOne: true,
  amount: 1000000n,
  sqrtPriceLimitX96: 0n
});

// Periphery swap calldata
const peripherySwapCalldata = sdk.getPeripherySwapCalldata({
  recipient: "0x...", // bytes32
  destChainId: 42161,
  destVmType: 1,
  zeroForOne: true,
  amount: 1000000n,
  sqrtPriceLimitX96: 0n,
  minAmountOut: 900000n,
  deadline: BigInt(Math.floor(Date.now() / 1000) + 3600) // 1 hour
});
```

#### Mint Position Calldata

```typescript
const mintCalldata = sdk.getPeripheryMintCalldata({
  recipient: "0x...", // bytes32
  tickLower: -200,
  tickUpper: 200,
  amount0: 1000000n, // USDC
  amount1: 500000000000000000n, // 0.5 WETH
  amount0Min: 950000n,
  amount1Min: 475000000000000000n,
  deadline: BigInt(Math.floor(Date.now() / 1000) + 3600)
});
```

### API Integration

```typescript
// Get swap quote via API (includes transaction instructions)
const apiQuote = await sdk.apiGetSwapQuote({
  amount: 1000000n,
  srcChainId: CHAIN.BASE,
  tokenA: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
  tokenB: "0x4200000000000000000000000000000000000006", // WETH
  user: "0x742d35Cc6639C0532fEb96A35d15b3DF1c99dd5F",
  recipient: "0x742d35Cc6639C0532fEb96A35d15b3DF1c99dd5F",
  slippageLimit: 0.01
});

// Returns transaction calldata for the specific chain
console.log(apiQuote.payload.calldata);
```

## Chain Support

```typescript
import { CHAIN, VM } from "@skate-org/skate-app-amm";

// Supported chains
CHAIN.ETHEREUM    // 1
CHAIN.ARBITRUM    // 42161
CHAIN.BASE        // 8453
CHAIN.SOLANA      // 901
CHAIN.ECLIPSE     // 902
CHAIN.SUI         // 1001

// VM Types
VM.EVM  // 1 - Ethereum Virtual Machine
VM.SVM  // 3 - Solana Virtual Machine
VM.SuiVM // 4 - Sui Virtual Machine
```

## Environment Configuration

```typescript
// Production (mainnet)
const mainnetSDK = new SkateAmmCoreSDK("PRODUCTION");

// Staging (testnet)
const testnetSDK = new SkateAmmCoreSDK("STAGING");
```

## Advanced Usage

See [CHANGELOG.md](./CHANGELOG.md) for detailed migration guide.