diff --git a/.changeset/eager-planets-jam.md b/.changeset/eager-planets-jam.md new file mode 100644 index 00000000..8a976754 --- /dev/null +++ b/.changeset/eager-planets-jam.md @@ -0,0 +1,6 @@ +--- +"@macalinao/clients-orca-whirlpools": minor +"@macalinao/create-coda": minor +--- + +Add create-coda package diff --git a/.changeset/eight-animals-win.md b/.changeset/eight-animals-win.md new file mode 100644 index 00000000..da3b75d2 --- /dev/null +++ b/.changeset/eight-animals-win.md @@ -0,0 +1,8 @@ +--- +"@macalinao/clients-orca-whirlpools": patch +"@macalinao/clients-kamino-lending": patch +"@macalinao/create-coda": patch +"coda-docs": patch +--- + +Docs diff --git a/apps/docs/content/docs/meta.json b/apps/docs/content/docs/meta.json index 98942d13..f1158d8a 100644 --- a/apps/docs/content/docs/meta.json +++ b/apps/docs/content/docs/meta.json @@ -1,12 +1,12 @@ { - "title": "Documentation", + "title": "Coda Documentation", "pages": [ - "---Introduction---", "index", "why-coda", "installation", "quick-start", "---Using Coda---", + "create-coda", "configuration", "generating-clients", "generating-docs", diff --git a/apps/docs/content/docs/packages/create-coda.mdx b/apps/docs/content/docs/packages/create-coda.mdx new file mode 100644 index 00000000..0401b281 --- /dev/null +++ b/apps/docs/content/docs/packages/create-coda.mdx @@ -0,0 +1,244 @@ +--- +title: "@macalinao/create-coda" +description: Project scaffolding tool for Coda client projects +--- + +## Overview + +`@macalinao/create-coda` is a project scaffolding tool that helps you bootstrap new TypeScript clients for Solana programs. It sets up a complete project structure with TypeScript, ESLint, and Coda pre-configured, allowing you to start generating clients immediately. + +## Installation + +The package is designed to be used with create commands from any package manager: + +```bash +# Using npm +npm create @macalinao/create-coda@latest my-project + +# Using bun +bun create @macalinao/create-coda my-project +``` + +## Usage + +### Basic Usage + +Create a new Coda client project: + +```bash +# Using npm +npm create @macalinao/create-coda@latest my-client + +# Using bun +bun create @macalinao/create-coda my-client +``` + +This will create a new directory called `my-client` with a complete project setup. + +### Custom Directory Name + +You can specify any name for your project: + +```bash +# Using npm +npm create @macalinao/create-coda@latest my-awesome-dex +npm create @macalinao/create-coda@latest lending-protocol +npm create @macalinao/create-coda@latest nft-marketplace + +# Using bun +bun create @macalinao/create-coda my-awesome-dex +bun create @macalinao/create-coda lending-protocol +bun create @macalinao/create-coda nft-marketplace +``` + +## What's Included + +The scaffolded project includes: + +### Project Structure + +``` +my-client/ +├── idls/ # Anchor IDL files +│ └── example.json # Example IDL to demonstrate usage +├── src/ +│ ├── generated/ # Generated client code (after codegen) +│ └── index.ts # Main entry point +├── coda.config.mjs # Coda configuration +├── tsconfig.json # TypeScript configuration +├── eslint.config.js # ESLint configuration +├── package.json # Dependencies and scripts +├── README.md # Project documentation +└── .gitignore # Git ignore patterns +``` + +### Pre-configured Dependencies + +- **@macalinao/coda** - The Coda CLI for generating clients +- **@macalinao/eslint-config** - Consistent ESLint configuration +- **@macalinao/tsconfig** - Shared TypeScript configuration +- **@solana/kit** - Solana development kit +- **TypeScript** - For type-safe development +- **ESLint** - For code quality + +### NPM Scripts + +```json +{ + "scripts": { + "build": "tsc", + "clean": "rm -fr dist/ tsconfig.tsbuildinfo", + "codegen": "rm -fr src/generated/ && coda generate", + "lint": "eslint . --cache" + } +} +``` + +### TypeScript Configuration + +Extends `@macalinao/tsconfig` with: + +- ES modules with `.js` extensions +- Strict type checking +- Modern ES2024 target +- Source maps and declarations +- Incremental compilation + +### ESLint Configuration + +Extends `@macalinao/eslint-config` with: + +- TypeScript-specific rules +- Import organization +- Special handling for generated code +- Automatic formatting fixes + +### Coda Configuration + +Pre-configured `coda.config.mjs` with: + +- Automatic IDL discovery from `./idls/*.json` +- Output to `./src/generated` +- Ready for custom visitors and PDAs + +## Template Customization + +The template is designed to be flexible: + +### Single IDL Projects + +Default configuration works out of the box: + +```javascript +// coda.config.mjs +export default defineConfig({ + // Automatically finds IDLs in ./idls/*.json + outputDir: "./src/generated", +}); +``` + +### Multiple IDL Projects + +Configure for multiple programs: + +```javascript +// coda.config.mjs +export default defineConfig({ + idlPath: "./idls/*.json", // Process all IDLs + outputDir: "./src/generated", +}); +``` + +### Custom Visitors + +Add Codama visitors for enhanced functionality: + +```javascript +// coda.config.mjs +import { addPdasVisitor } from "codama"; + +export default defineConfig({ + outputDir: "./src/generated", + visitors: [ + addPdasVisitor({ + // Custom PDA definitions + }), + ], +}); +``` + +## Development Workflow + +After creating a project with create-coda: + +### 1. Install Dependencies + +```bash +cd my-client +bun install +``` + +### 2. Add Your IDL + +Replace the example IDL with your program's IDL: + +```bash +rm idls/example.json +cp path/to/your/target/idl/program.json idls/ +``` + +### 3. Generate Client + +```bash +bun run codegen +``` + +### 4. Build Project + +```bash +bun run build +``` + +### 5. Use the Client + +```typescript +import { createInitializeInstruction } from "./dist/index.js"; + +const ix = createInitializeInstruction({ + // ... parameters +}); +``` + +## Package Development + +To work on the create-coda package itself: + +### Building + +```bash +cd packages/create-coda +bun run build +``` + +### Testing Locally + +```bash +node ./dist/bin.js test-project +``` + +### Template Files + +The template files are located in `packages/create-coda/template/` and are copied when creating new projects. + +## Source Code + +The create-coda package is part of the Coda monorepo: + +- [GitHub Repository](https://github.com/macalinao/coda/tree/master/packages/create-coda) +- [NPM Package](https://www.npmjs.com/package/@macalinao/create-coda) + +## Related Packages + +- [**@macalinao/coda**](/docs/packages/coda) - The main Coda CLI +- [**@macalinao/codama-renderers-js-esm**](/docs/packages/codama-renderers-js-esm) - ESM renderer for Codama +- [**@macalinao/codama-instruction-accounts-dedupe-visitor**](/docs/packages/codama-instruction-accounts-dedupe-visitor) - Account deduplication visitor diff --git a/apps/docs/content/docs/packages/index.mdx b/apps/docs/content/docs/packages/index.mdx index c5c715d2..5a041753 100644 --- a/apps/docs/content/docs/packages/index.mdx +++ b/apps/docs/content/docs/packages/index.mdx @@ -5,30 +5,40 @@ description: Core packages that power Coda's client generation capabilities Coda is built as a modular system of packages that work together to generate high-quality TypeScript clients from Solana IDLs. Each package serves a specific purpose in the generation pipeline. -## Core Package +## Core Packages ### [@macalinao/coda](/docs/packages/coda) + The main CLI tool for generating TypeScript clients from Anchor IDLs. Works out of the box with sensible defaults and extensible configuration. +### [@macalinao/create-coda](/docs/packages/create-coda) + +Project scaffolding tool that bootstraps new Coda client projects with TypeScript, ESLint, and all configurations pre-set. + ## Parsers ### [@macalinao/codama-nodes-from-anchor-x](/docs/packages/codama-nodes-from-anchor-x) + Creates Codama root nodes from multiple Anchor IDLs with enhanced support for various IDL versions. ## Visitors ### [@macalinao/codama-instruction-accounts-dedupe-visitor](/docs/packages/codama-instruction-accounts-dedupe-visitor) + Flattens nested account structures from Anchor IDLs while preserving relationships through naming conventions. ### [@macalinao/codama-rename-visitor](/docs/packages/codama-rename-visitor) + Renames accounts, instructions, and defined types in the Codama AST to avoid conflicts and customize naming. ## Renderers ### [@macalinao/codama-renderers-js-esm](/docs/packages/codama-renderers-js-esm) + ESM-native TypeScript renderer that generates modern JavaScript modules with proper `.js` extensions. ### [@macalinao/codama-renderers-markdown](/docs/packages/codama-renderers-markdown) + Generates comprehensive Markdown documentation from Codama AST nodes, perfect for API documentation. ## Package Architecture @@ -44,18 +54,56 @@ Each package in the Coda ecosystem follows a consistent structure: Each package can be installed individually based on your needs: +### Create a New Project (Recommended) + +```bash +# Using npm +npm create @macalinao/create-coda@latest my-client + +# Using bun +bun create @macalinao/create-coda my-client +``` + +### Install the Main CLI + ```bash -# Install the main CLI +# Using npm +npm install -D @macalinao/coda + +# Using bun bun add -D @macalinao/coda +``` -# Install parsers +### Install Parsers + +```bash +# Using npm +npm install @macalinao/codama-nodes-from-anchor-x + +# Using bun bun add @macalinao/codama-nodes-from-anchor-x +``` + +### Install Visitors -# Install visitors +```bash +# Using npm +npm install @macalinao/codama-instruction-accounts-dedupe-visitor +npm install @macalinao/codama-rename-visitor + +# Using bun bun add @macalinao/codama-instruction-accounts-dedupe-visitor bun add @macalinao/codama-rename-visitor +``` + +### Install Renderers -# Install renderers +```bash +# Using npm +npm install @macalinao/codama-renderers-js-esm +npm install @macalinao/codama-renderers-markdown + +# Using bun bun add @macalinao/codama-renderers-js-esm bun add @macalinao/codama-renderers-markdown ``` @@ -73,4 +121,4 @@ bun test # Fix linting issues bun run lint:fix -``` \ No newline at end of file +``` diff --git a/apps/docs/content/docs/packages/meta.json b/apps/docs/content/docs/packages/meta.json index 500a40b0..88e06a29 100644 --- a/apps/docs/content/docs/packages/meta.json +++ b/apps/docs/content/docs/packages/meta.json @@ -2,8 +2,9 @@ "title": "Packages", "pages": [ "index", - "---Core Package---", + "---Core Packages---", "coda", + "create-coda", "---Parsers---", "codama-nodes-from-anchor-x", "---Visitors---", diff --git a/apps/docs/content/docs/quick-start.mdx b/apps/docs/content/docs/quick-start.mdx index ee876b10..418ca8bf 100644 --- a/apps/docs/content/docs/quick-start.mdx +++ b/apps/docs/content/docs/quick-start.mdx @@ -3,28 +3,71 @@ title: Quick Start description: Generate your first TypeScript client with Coda --- -This guide walks you through generating your first TypeScript client from an Anchor IDL. +Get started with Coda in seconds using our project scaffolding tool. -## Step 1: Build Your Program +## Option 1: Create a New Project (Recommended) -First, ensure you have an Anchor IDL by building your program: +The fastest way to start is with `create-coda`: ```bash -anchor build +# Using npm +npm create @macalinao/create-coda@latest my-client +cd my-client +npm install + +# Using bun +bun create @macalinao/create-coda my-client +cd my-client +bun install ``` -This creates your IDL file at `./target/idl/your_program.json`. +This creates a complete project with: -## Step 2: Generate the Client +- TypeScript and ESLint pre-configured +- Coda configuration ready to use +- Example IDL to get started +- All necessary build scripts -Run Coda to generate your TypeScript client: +Then add your IDL and generate: ```bash -bunx @macalinao/coda generate +# Replace example.json with your Anchor IDL +cp path/to/your/program/target/idl/your_program.json idls/ + +# Generate the TypeScript client +bun run codegen + +# Build the project +bun run build +``` + +## Option 2: Add to Existing Project + +If you have an existing project with an Anchor IDL: + +### Step 1: Install Coda + +```bash +# Using npm +npm install -D @macalinao/coda + +# Using bun +bun add -D @macalinao/coda +``` + +### Step 2: Generate the Client + +```bash +# Using npm +npx coda generate + +# Using bun +bunx coda generate ``` Coda will: -- Locate your IDL (defaults to `./target/idl/`) + +- Locate your IDL (defaults to `./idls/*.json` or `./target/idl/`) - Generate a complete TypeScript client - Output files to `./src/generated/` @@ -35,10 +78,10 @@ No configuration required for standard Anchor projects. Import and use the generated functions in your application: ```typescript -import { +import { createTransferInstruction, fetchTokenAccount, - findVaultPda + findVaultPda, } from "./src/generated"; // Create instructions with full type safety @@ -46,7 +89,7 @@ const instruction = createTransferInstruction({ source: sourceAccount, destination: destAccount, authority: signer, - amount: 1000n + amount: 1000n, }); // Fetch and decode accounts @@ -56,7 +99,7 @@ console.log(account.balance); // Fully typed // Find program-derived addresses const [vault] = await findVaultPda({ user: userPubkey, - seed: "vault" + seed: "vault", }); ``` @@ -65,18 +108,23 @@ const [vault] = await findVaultPda({ Coda generates a comprehensive TypeScript client including: ### **Instructions** + Typed builders for every program instruction with full IntelliSense support. ### **Accounts** + Fetchers and decoders for all account types with automatic deserialization. ### **Types** + All custom types from your IDL including enums, structs, and unions. ### **PDAs** + Helper functions for program-derived address calculation. ### **Errors** + Typed error definitions for proper error handling. ## File Structure @@ -108,4 +156,4 @@ src/generated/ **Type errors**: Run `tsc --noEmit` to check TypeScript compilation -For additional help, please [open an issue](https://github.com/macalinao/coda/issues) on GitHub. \ No newline at end of file +For additional help, please [open an issue](https://github.com/macalinao/coda/issues) on GitHub. diff --git a/bun.lock b/bun.lock index 1ac780e3..36ec9e5e 100644 --- a/bun.lock +++ b/bun.lock @@ -54,6 +54,21 @@ "@solana/kit": "*", }, }, + "clients/orca-whirlpools": { + "name": "@macalinao/clients-orca-whirlpools", + "version": "0.1.0", + "devDependencies": { + "@macalinao/coda": "workspace:*", + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@solana/kit": "*", + "eslint": "catalog:", + "typescript": "catalog:", + }, + "peerDependencies": { + "@solana/kit": "*", + }, + }, "clients/quarry": { "name": "@macalinao/clients-quarry", "version": "0.1.3", @@ -184,6 +199,20 @@ "typescript": "catalog:", }, }, + "packages/create-coda": { + "name": "@macalinao/create-coda", + "version": "0.0.0", + "bin": { + "create-coda": "./dist/bin.js", + }, + "devDependencies": { + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@types/node": "^22.0.0", + "eslint": "catalog:", + "typescript": "catalog:", + }, + }, }, "overrides": { "react": "^19.1.1", @@ -458,6 +487,8 @@ "@macalinao/clients-kamino-lending": ["@macalinao/clients-kamino-lending@workspace:clients/kamino-lending"], + "@macalinao/clients-orca-whirlpools": ["@macalinao/clients-orca-whirlpools@workspace:clients/orca-whirlpools"], + "@macalinao/clients-quarry": ["@macalinao/clients-quarry@workspace:clients/quarry"], "@macalinao/clients-token-metadata": ["@macalinao/clients-token-metadata@workspace:clients/token-metadata"], @@ -474,6 +505,8 @@ "@macalinao/codama-renderers-markdown": ["@macalinao/codama-renderers-markdown@workspace:packages/codama-renderers-markdown"], + "@macalinao/create-coda": ["@macalinao/create-coda@workspace:packages/create-coda"], + "@macalinao/eslint-config": ["@macalinao/eslint-config@5.0.1", "", { "dependencies": { "@eslint/js": "^9.33.0", "@typescript-eslint/parser": "^8.39.1", "@typescript-eslint/utils": "^8.39.1", "eslint-config-prettier": "^10.1.8", "eslint-config-turbo": "^2.5.6", "eslint-import-resolver-typescript": "^4.4.4", "eslint-plugin-import-x": "^4.16.1", "eslint-plugin-prettier": "^5.5.4", "eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-unused-imports": "^4.1.4", "globals": "^16.3.0", "typescript-eslint": "^8.39.1" }, "peerDependencies": { "eslint": "^9.33.0" } }, "sha512-y2irsItbTh2+qk5ICCGiNozKEcDJzZZjZ6ohRBbwNPWnl/X5hzS/pmeFvQzcw/USM4/eWbynsayobZMCIOWjAg=="], "@macalinao/tsconfig": ["@macalinao/tsconfig@3.2.3", "", {}, "sha512-PH6UvudxPrxYg+2BZyPUx2/U2jCOlJYz+2cGLvIX3Ybtz3GNGxjounb4sceZmR9QmquZlxuP0o5Zz3Y8VATbdA=="], @@ -1912,6 +1945,8 @@ "@isaacs/cliui/wrap-ansi": ["wrap-ansi@8.1.0", "", { "dependencies": { "ansi-styles": "^6.1.0", "string-width": "^5.0.1", "strip-ansi": "^7.0.1" } }, "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ=="], + "@macalinao/create-coda/@types/node": ["@types/node@22.17.2", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-gL6z5N9Jm9mhY+U2KXZpteb+09zyffliRkZyZOHODGATyC5B1Jt/7TzuuiLkFsSUMLbS1OLmlj/E+/3KF4Q/4w=="], + "@manypkg/find-root/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], "@manypkg/find-root/find-up": ["find-up@4.1.0", "", { "dependencies": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" } }, "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw=="], @@ -2020,6 +2055,8 @@ "@isaacs/cliui/wrap-ansi/ansi-styles": ["ansi-styles@6.2.1", "", {}, "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug=="], + "@macalinao/create-coda/@types/node/undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="], + "@manypkg/find-root/find-up/locate-path": ["locate-path@5.0.0", "", { "dependencies": { "p-locate": "^4.1.0" } }, "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g=="], "@typescript-eslint/typescript-estree/fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], diff --git a/clients/kamino-lending/README.md b/clients/kamino-lending/README.md index cba48cd4..5997bb12 100644 --- a/clients/kamino-lending/README.md +++ b/clients/kamino-lending/README.md @@ -3,7 +3,7 @@ [![npm version](https://img.shields.io/npm/v/@macalinao/clients-kamino-lending.svg)](https://www.npmjs.com/package/@macalinao/clients-kamino-lending) [![npm downloads](https://img.shields.io/npm/dm/@macalinao/clients-kamino-lending.svg)](https://www.npmjs.com/package/@macalinao/clients-kamino-lending) -TypeScript client for the Kamino Lending program on Solana. +Low-level TypeScript client for the Kamino Lending and Farms programs on Solana. ## Installation diff --git a/clients/orca-whirlpools/.gitignore b/clients/orca-whirlpools/.gitignore new file mode 100644 index 00000000..24943919 --- /dev/null +++ b/clients/orca-whirlpools/.gitignore @@ -0,0 +1,31 @@ +# Dependencies +node_modules/ +.pnp +.pnp.js + +# Build output +dist/ +*.tsbuildinfo + +# Debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* +bun.lockb + +# Environment +.env +.env.local +.env.*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store + +# Cache +.turbo/ +.eslintcache \ No newline at end of file diff --git a/clients/orca-whirlpools/README.md b/clients/orca-whirlpools/README.md new file mode 100644 index 00000000..978156cc --- /dev/null +++ b/clients/orca-whirlpools/README.md @@ -0,0 +1,45 @@ +# @macalinao/clients-orca-whirlpools + +[![npm version](https://img.shields.io/npm/v/@macalinao/clients-orca-whirlpools.svg)](https://www.npmjs.com/package/@macalinao/clients-orca-whirlpools) + +TypeScript client for the Orca Whirlpools program, generated using Coda CLI with full ESM support. + +## Installation + +```bash +bun add @macalinao/clients-orca-whirlpools +``` + +## About Orca Whirlpools + +Orca Whirlpools is a concentrated liquidity AMM (CLMM) protocol on Solana that enables efficient token swaps with capital-efficient liquidity provision. The protocol allows liquidity providers to concentrate their capital within custom price ranges. + +## Development + +This client is generated from the Orca Whirlpools IDL using Coda CLI: + +```bash +# Generate the client from idls/ +bun run codegen + +# Build the TypeScript +bun run build +``` + +### Configuration + +The `coda.config.mjs` file can be customized to add PDAs and other Codama visitors for enhanced client functionality. + +## Usage + +```typescript +import {} from /* generated exports */ "@macalinao/clients-orca-whirlpools"; + +// Use the generated client functions +``` + +## License + +Copyright © 2025 Ian Macalinao + +Licensed under the Apache License, Version 2.0 diff --git a/clients/orca-whirlpools/coda.config.mjs b/clients/orca-whirlpools/coda.config.mjs new file mode 100644 index 00000000..e2a16661 --- /dev/null +++ b/clients/orca-whirlpools/coda.config.mjs @@ -0,0 +1,21 @@ +import { defineConfig } from "@macalinao/coda"; + +export default defineConfig({ + // Coda will automatically discover IDLs from ./idls/*.json + // You can override this by specifying a custom path: + // idlPath: "./idls/my_program.json", + + // For multiple IDLs, use a glob pattern or array: + // idlPath: "./idls/*.json", + // idlPath: ["./idls/program1.json", "./idls/program2.json"], + + // Output directory for generated code (default: "./src/generated") + outputDir: "./src/generated", + + // Optional: Add custom Codama visitors for advanced customization + // visitors: [ + // addPdasVisitor({ + // // Define custom PDAs here + // }) + // ] +}); diff --git a/clients/orca-whirlpools/docs/whirlpool.md b/clients/orca-whirlpools/docs/whirlpool.md new file mode 100644 index 00000000..614403dc --- /dev/null +++ b/clients/orca-whirlpools/docs/whirlpool.md @@ -0,0 +1,1506 @@ +# Whirlpool Program + +- Program ID: `whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc` + +## Table of Contents + +- [Accounts](#accounts) + - [whirlpoolsConfig](#whirlpoolsConfig) + - [whirlpoolsConfigExtension](#whirlpoolsConfigExtension) + - [feeTier](#feeTier) + - [lockConfig](#lockConfig) + - [position](#position) + - [positionBundle](#positionBundle) + - [tickArray](#tickArray) + - [tokenBadge](#tokenBadge) + - [whirlpool](#whirlpool) +- [Instructions](#instructions) + - [initializeConfig](#initializeConfig) + - [initializePool](#initializePool) + - [initializeTickArray](#initializeTickArray) + - [initializeFeeTier](#initializeFeeTier) + - [initializeReward](#initializeReward) + - [setRewardEmissions](#setRewardEmissions) + - [openPosition](#openPosition) + - [openPositionWithMetadata](#openPositionWithMetadata) + - [increaseLiquidity](#increaseLiquidity) + - [decreaseLiquidity](#decreaseLiquidity) + - [updateFeesAndRewards](#updateFeesAndRewards) + - [collectFees](#collectFees) + - [collectReward](#collectReward) + - [collectProtocolFees](#collectProtocolFees) + - [swap](#swap) + - [closePosition](#closePosition) + - [setDefaultFeeRate](#setDefaultFeeRate) + - [setDefaultProtocolFeeRate](#setDefaultProtocolFeeRate) + - [setFeeRate](#setFeeRate) + - [setProtocolFeeRate](#setProtocolFeeRate) + - [setFeeAuthority](#setFeeAuthority) + - [setCollectProtocolFeesAuthority](#setCollectProtocolFeesAuthority) + - [setRewardAuthority](#setRewardAuthority) + - [setRewardAuthorityBySuperAuthority](#setRewardAuthorityBySuperAuthority) + - [setRewardEmissionsSuperAuthority](#setRewardEmissionsSuperAuthority) + - [twoHopSwap](#twoHopSwap) + - [initializePositionBundle](#initializePositionBundle) + - [initializePositionBundleWithMetadata](#initializePositionBundleWithMetadata) + - [deletePositionBundle](#deletePositionBundle) + - [openBundledPosition](#openBundledPosition) + - [closeBundledPosition](#closeBundledPosition) + - [openPositionWithTokenExtensions](#openPositionWithTokenExtensions) + - [closePositionWithTokenExtensions](#closePositionWithTokenExtensions) + - [lockPosition](#lockPosition) + - [collectFeesV2](#collectFeesV2) + - [collectProtocolFeesV2](#collectProtocolFeesV2) + - [collectRewardV2](#collectRewardV2) + - [decreaseLiquidityV2](#decreaseLiquidityV2) + - [increaseLiquidityV2](#increaseLiquidityV2) + - [initializePoolV2](#initializePoolV2) + - [initializeRewardV2](#initializeRewardV2) + - [setRewardEmissionsV2](#setRewardEmissionsV2) + - [swapV2](#swapV2) + - [twoHopSwapV2](#twoHopSwapV2) + - [initializeConfigExtension](#initializeConfigExtension) + - [setConfigExtensionAuthority](#setConfigExtensionAuthority) + - [setTokenBadgeAuthority](#setTokenBadgeAuthority) + - [initializeTokenBadge](#initializeTokenBadge) + - [deleteTokenBadge](#deleteTokenBadge) +- [Types](#types) + - [lockType](#lockType) + - [lockTypeLabel](#lockTypeLabel) + - [openPositionBumps](#openPositionBumps) + - [openPositionWithMetadataBumps](#openPositionWithMetadataBumps) + - [positionRewardInfo](#positionRewardInfo) + - [tick](#tick) + - [whirlpoolBumps](#whirlpoolBumps) + - [whirlpoolRewardInfo](#whirlpoolRewardInfo) + - [accountsType](#accountsType) + - [remainingAccountsInfo](#remainingAccountsInfo) + - [remainingAccountsSlice](#remainingAccountsSlice) +- [Errors](#errors) + +## Accounts + +### whirlpoolsConfig + +**Fields:** + +| Field | Type | Description | +| ------------------------------- | ----------- | ----------- | +| `discriminator` | `unknown` | | +| `feeAuthority` | `PublicKey` | | +| `collectProtocolFeesAuthority` | `PublicKey` | | +| `rewardEmissionsSuperAuthority` | `PublicKey` | | +| `defaultProtocolFeeRate` | `u16` | | + +### whirlpoolsConfigExtension + +**Fields:** + +| Field | Type | Description | +| -------------------------- | ----------- | ----------- | +| `discriminator` | `unknown` | | +| `whirlpoolsConfig` | `PublicKey` | | +| `configExtensionAuthority` | `PublicKey` | | +| `tokenBadgeAuthority` | `PublicKey` | | + +### feeTier + +**Fields:** + +| Field | Type | Description | +| ------------------ | ----------- | ----------- | +| `discriminator` | `unknown` | | +| `whirlpoolsConfig` | `PublicKey` | | +| `tickSpacing` | `u16` | | +| `defaultFeeRate` | `u16` | | + +### lockConfig + +**Fields:** + +| Field | Type | Description | +| ----------------- | --------------------------------- | ----------- | +| `discriminator` | `unknown` | | +| `position` | `PublicKey` | | +| `positionOwner` | `PublicKey` | | +| `whirlpool` | `PublicKey` | | +| `lockedTimestamp` | `u64` | | +| `lockType` | [lockTypeLabel](#lockTypeLabel-3) | | + +### position + +**Fields:** + +| Field | Type | Description | +| ---------------------- | ---------------------------------------------- | ----------- | +| `discriminator` | `unknown` | | +| `whirlpool` | `PublicKey` | | +| `positionMint` | `PublicKey` | | +| `liquidity` | `u128` | | +| `tickLowerIndex` | `i32` | | +| `tickUpperIndex` | `i32` | | +| `feeGrowthCheckpointA` | `u128` | | +| `feeOwedA` | `u64` | | +| `feeGrowthCheckpointB` | `u128` | | +| `feeOwedB` | `u64` | | +| `rewardInfos` | [positionRewardInfo](#positionRewardInfo-3)[3] | | + +### positionBundle + +**Fields:** + +| Field | Type | Description | +| -------------------- | ----------- | ----------- | +| `discriminator` | `unknown` | | +| `positionBundleMint` | `PublicKey` | | +| `positionBitmap` | `u8`[32] | | + +### tickArray + +**Fields:** + +| Field | Type | Description | +| ---------------- | ------------------- | ----------- | +| `discriminator` | `unknown` | | +| `startTickIndex` | `i32` | | +| `ticks` | [tick](#tick-3)[88] | | +| `whirlpool` | `PublicKey` | | + +### tokenBadge + +**Fields:** + +| Field | Type | Description | +| ------------------ | ----------- | ----------- | +| `discriminator` | `unknown` | | +| `whirlpoolsConfig` | `PublicKey` | | +| `tokenMint` | `PublicKey` | | + +### whirlpool + +**Fields:** + +| Field | Type | Description | +| ---------------------------- | ------------------------------------------------ | ----------- | +| `discriminator` | `unknown` | | +| `whirlpoolsConfig` | `PublicKey` | | +| `whirlpoolBump` | `u8`[1] | | +| `tickSpacing` | `u16` | | +| `tickSpacingSeed` | `u8`[2] | | +| `feeRate` | `u16` | | +| `protocolFeeRate` | `u16` | | +| `liquidity` | `u128` | | +| `sqrtPrice` | `u128` | | +| `tickCurrentIndex` | `i32` | | +| `protocolFeeOwedA` | `u64` | | +| `protocolFeeOwedB` | `u64` | | +| `tokenMintA` | `PublicKey` | | +| `tokenVaultA` | `PublicKey` | | +| `feeGrowthGlobalA` | `u128` | | +| `tokenMintB` | `PublicKey` | | +| `tokenVaultB` | `PublicKey` | | +| `feeGrowthGlobalB` | `u128` | | +| `rewardLastUpdatedTimestamp` | `u64` | | +| `rewardInfos` | [whirlpoolRewardInfo](#whirlpoolRewardInfo-3)[3] | | + +## Instructions + +### initializeConfig + +**Accounts:** + +| Account | Type | Description | +| --------------- | ---------------- | ----------- | +| `config` | signer, writable | | +| `funder` | signer, writable | | +| `systemProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------------------- | ----------- | ----------- | +| `discriminator` | `unknown` | | +| `feeAuthority` | `PublicKey` | | +| `collectProtocolFeesAuthority` | `PublicKey` | | +| `rewardEmissionsSuperAuthority` | `PublicKey` | | +| `defaultProtocolFeeRate` | `u16` | | + +### initializePool + +**Accounts:** + +| Account | Type | Description | +| ------------------ | ---------------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `funder` | signer, writable | | +| `whirlpool` | writable | | +| `tokenVaultA` | signer, writable | | +| `tokenVaultB` | signer, writable | | +| `feeTier` | readonly | | +| `tokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------ | ----------------------------------- | ----------- | +| `discriminator` | `unknown` | | +| `bumps` | [whirlpoolBumps](#whirlpoolBumps-3) | | +| `tickSpacing` | `u16` | | +| `initialSqrtPrice` | `u128` | | + +### initializeTickArray + +**Accounts:** + +| Account | Type | Description | +| --------------- | ---------------- | ----------- | +| `whirlpool` | readonly | | +| `funder` | signer, writable | | +| `tickArray` | writable | | +| `systemProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `startTickIndex` | `i32` | | + +### initializeFeeTier + +**Accounts:** + +| Account | Type | Description | +| --------------- | ---------------- | ----------- | +| `config` | readonly | | +| `feeTier` | writable | | +| `funder` | signer, writable | | +| `feeAuthority` | signer | | +| `systemProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `tickSpacing` | `u16` | | +| `defaultFeeRate` | `u16` | | + +### initializeReward + +**Accounts:** + +| Account | Type | Description | +| ----------------- | ---------------- | ----------- | +| `rewardAuthority` | signer | | +| `funder` | signer, writable | | +| `whirlpool` | writable | | +| `rewardMint` | readonly | | +| `rewardVault` | signer, writable | | +| `tokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | + +### setRewardEmissions + +**Accounts:** + +| Account | Type | Description | +| ----------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `rewardAuthority` | signer | | +| `rewardVault` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | +| `emissionsPerSecondX64` | `u128` | | + +### openPosition + +**Accounts:** + +| Account | Type | Description | +| ------------------------ | ---------------- | ----------- | +| `funder` | signer, writable | | +| `owner` | readonly | | +| `position` | writable | | +| `positionMint` | signer, writable | | +| `positionTokenAccount` | writable | | +| `whirlpool` | readonly | | +| `tokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | +| `associatedTokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------- | ----------------------------------------- | ----------- | +| `discriminator` | `unknown` | | +| `bumps` | [openPositionBumps](#openPositionBumps-3) | | +| `tickLowerIndex` | `i32` | | +| `tickUpperIndex` | `i32` | | + +### openPositionWithMetadata + +**Accounts:** + +| Account | Type | Description | +| ------------------------- | ---------------- | ----------- | +| `funder` | signer, writable | | +| `owner` | readonly | | +| `position` | writable | | +| `positionMint` | signer, writable | | +| `positionMetadataAccount` | writable | | +| `positionTokenAccount` | writable | | +| `whirlpool` | readonly | | +| `tokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | +| `associatedTokenProgram` | readonly | | +| `metadataProgram` | readonly | | +| `metadataUpdateAuth` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------- | ----------------------------------------------------------------- | ----------- | +| `discriminator` | `unknown` | | +| `bumps` | [openPositionWithMetadataBumps](#openPositionWithMetadataBumps-3) | | +| `tickLowerIndex` | `i32` | | +| `tickUpperIndex` | `i32` | | + +### increaseLiquidity + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `tokenProgram` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultA` | writable | | +| `tokenVaultB` | writable | | +| `tickArrayLower` | writable | | +| `tickArrayUpper` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `liquidityAmount` | `u128` | | +| `tokenMaxA` | `u64` | | +| `tokenMaxB` | `u64` | | + +### decreaseLiquidity + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `tokenProgram` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultA` | writable | | +| `tokenVaultB` | writable | | +| `tickArrayLower` | writable | | +| `tickArrayUpper` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `liquidityAmount` | `u128` | | +| `tokenMinA` | `u64` | | +| `tokenMinB` | `u64` | | + +### updateFeesAndRewards + +**Accounts:** + +| Account | Type | Description | +| ---------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `position` | writable | | +| `tickArrayLower` | readonly | | +| `tickArrayUpper` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### collectFees + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenVaultA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultB` | writable | | +| `tokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### collectReward + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `rewardOwnerAccount` | writable | | +| `rewardVault` | writable | | +| `tokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | + +### collectProtocolFees + +**Accounts:** + +| Account | Type | Description | +| ------------------------------ | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpool` | writable | | +| `collectProtocolFeesAuthority` | signer | | +| `tokenVaultA` | writable | | +| `tokenVaultB` | writable | | +| `tokenDestinationA` | writable | | +| `tokenDestinationB` | writable | | +| `tokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### swap + +**Accounts:** + +| Account | Type | Description | +| -------------------- | -------- | ----------- | +| `tokenProgram` | readonly | | +| `tokenAuthority` | signer | | +| `whirlpool` | writable | | +| `tokenOwnerAccountA` | writable | | +| `tokenVaultA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultB` | writable | | +| `tickArray0` | writable | | +| `tickArray1` | writable | | +| `tickArray2` | writable | | +| `oracle` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------------ | --------- | ----------- | +| `discriminator` | `unknown` | | +| `amount` | `u64` | | +| `otherAmountThreshold` | `u64` | | +| `sqrtPriceLimit` | `u128` | | +| `amountSpecifiedIsInput` | `boolean` | | +| `aToB` | `boolean` | | + +### closePosition + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `positionAuthority` | signer | | +| `receiver` | writable | | +| `position` | writable | | +| `positionMint` | writable | | +| `positionTokenAccount` | writable | | +| `tokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### setDefaultFeeRate + +**Accounts:** + +| Account | Type | Description | +| ------------------ | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `feeTier` | writable | | +| `feeAuthority` | signer | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `defaultFeeRate` | `u16` | | + +### setDefaultProtocolFeeRate + +**Accounts:** + +| Account | Type | Description | +| ------------------ | -------- | ----------- | +| `whirlpoolsConfig` | writable | | +| `feeAuthority` | signer | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------------ | --------- | ----------- | +| `discriminator` | `unknown` | | +| `defaultProtocolFeeRate` | `u16` | | + +### setFeeRate + +**Accounts:** + +| Account | Type | Description | +| ------------------ | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpool` | writable | | +| `feeAuthority` | signer | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `feeRate` | `u16` | | + +### setProtocolFeeRate + +**Accounts:** + +| Account | Type | Description | +| ------------------ | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpool` | writable | | +| `feeAuthority` | signer | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `protocolFeeRate` | `u16` | | + +### setFeeAuthority + +**Accounts:** + +| Account | Type | Description | +| ------------------ | -------- | ----------- | +| `whirlpoolsConfig` | writable | | +| `feeAuthority` | signer | | +| `newFeeAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### setCollectProtocolFeesAuthority + +**Accounts:** + +| Account | Type | Description | +| --------------------------------- | -------- | ----------- | +| `whirlpoolsConfig` | writable | | +| `collectProtocolFeesAuthority` | signer | | +| `newCollectProtocolFeesAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### setRewardAuthority + +**Accounts:** + +| Account | Type | Description | +| -------------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `rewardAuthority` | signer | | +| `newRewardAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | + +### setRewardAuthorityBySuperAuthority + +**Accounts:** + +| Account | Type | Description | +| ------------------------------- | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpool` | writable | | +| `rewardEmissionsSuperAuthority` | signer | | +| `newRewardAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | + +### setRewardEmissionsSuperAuthority + +**Accounts:** + +| Account | Type | Description | +| ---------------------------------- | -------- | ----------- | +| `whirlpoolsConfig` | writable | | +| `rewardEmissionsSuperAuthority` | signer | | +| `newRewardEmissionsSuperAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### twoHopSwap + +**Accounts:** + +| Account | Type | Description | +| ----------------------- | -------- | ----------- | +| `tokenProgram` | readonly | | +| `tokenAuthority` | signer | | +| `whirlpoolOne` | writable | | +| `whirlpoolTwo` | writable | | +| `tokenOwnerAccountOneA` | writable | | +| `tokenVaultOneA` | writable | | +| `tokenOwnerAccountOneB` | writable | | +| `tokenVaultOneB` | writable | | +| `tokenOwnerAccountTwoA` | writable | | +| `tokenVaultTwoA` | writable | | +| `tokenOwnerAccountTwoB` | writable | | +| `tokenVaultTwoB` | writable | | +| `tickArrayOne0` | writable | | +| `tickArrayOne1` | writable | | +| `tickArrayOne2` | writable | | +| `tickArrayTwo0` | writable | | +| `tickArrayTwo1` | writable | | +| `tickArrayTwo2` | writable | | +| `oracleOne` | readonly | | +| `oracleTwo` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------------ | --------- | ----------- | +| `discriminator` | `unknown` | | +| `amount` | `u64` | | +| `otherAmountThreshold` | `u64` | | +| `amountSpecifiedIsInput` | `boolean` | | +| `aToBOne` | `boolean` | | +| `aToBTwo` | `boolean` | | +| `sqrtPriceLimitOne` | `u128` | | +| `sqrtPriceLimitTwo` | `u128` | | + +### initializePositionBundle + +**Accounts:** + +| Account | Type | Description | +| ---------------------------- | ---------------- | ----------- | +| `positionBundle` | writable | | +| `positionBundleMint` | signer, writable | | +| `positionBundleTokenAccount` | writable | | +| `positionBundleOwner` | readonly | | +| `funder` | signer, writable | | +| `tokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | +| `associatedTokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### initializePositionBundleWithMetadata + +**Accounts:** + +| Account | Type | Description | +| ---------------------------- | ---------------- | ----------- | +| `positionBundle` | writable | | +| `positionBundleMint` | signer, writable | | +| `positionBundleMetadata` | writable | | +| `positionBundleTokenAccount` | writable | | +| `positionBundleOwner` | readonly | | +| `funder` | signer, writable | | +| `metadataUpdateAuth` | readonly | | +| `tokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | +| `associatedTokenProgram` | readonly | | +| `metadataProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### deletePositionBundle + +**Accounts:** + +| Account | Type | Description | +| ---------------------------- | -------- | ----------- | +| `positionBundle` | writable | | +| `positionBundleMint` | writable | | +| `positionBundleTokenAccount` | writable | | +| `positionBundleOwner` | signer | | +| `receiver` | writable | | +| `tokenProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### openBundledPosition + +**Accounts:** + +| Account | Type | Description | +| ---------------------------- | ---------------- | ----------- | +| `bundledPosition` | writable | | +| `positionBundle` | writable | | +| `positionBundleTokenAccount` | readonly | | +| `positionBundleAuthority` | signer | | +| `whirlpool` | readonly | | +| `funder` | signer, writable | | +| `systemProgram` | readonly | | +| `rent` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `bundleIndex` | `u16` | | +| `tickLowerIndex` | `i32` | | +| `tickUpperIndex` | `i32` | | + +### closeBundledPosition + +**Accounts:** + +| Account | Type | Description | +| ---------------------------- | -------- | ----------- | +| `bundledPosition` | writable | | +| `positionBundle` | writable | | +| `positionBundleTokenAccount` | readonly | | +| `positionBundleAuthority` | signer | | +| `receiver` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `bundleIndex` | `u16` | | + +### openPositionWithTokenExtensions + +**Accounts:** + +| Account | Type | Description | +| ------------------------ | ---------------- | ----------- | +| `funder` | signer, writable | | +| `owner` | readonly | | +| `position` | writable | | +| `positionMint` | signer, writable | | +| `positionTokenAccount` | writable | | +| `whirlpool` | readonly | | +| `token2022Program` | readonly | | +| `systemProgram` | readonly | | +| `associatedTokenProgram` | readonly | | +| `metadataUpdateAuth` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ---------------------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `tickLowerIndex` | `i32` | | +| `tickUpperIndex` | `i32` | | +| `withTokenMetadataExtension` | `boolean` | | + +### closePositionWithTokenExtensions + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `positionAuthority` | signer | | +| `receiver` | writable | | +| `position` | writable | | +| `positionMint` | writable | | +| `positionTokenAccount` | writable | | +| `token2022Program` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### lockPosition + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | ---------------- | ----------- | +| `funder` | signer, writable | | +| `positionAuthority` | signer | | +| `position` | readonly | | +| `positionMint` | readonly | | +| `positionTokenAccount` | writable | | +| `lockConfig` | writable | | +| `whirlpool` | readonly | | +| `token2022Program` | readonly | | +| `systemProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | ----------------------- | ----------- | +| `discriminator` | `unknown` | | +| `lockType` | [lockType](#lockType-3) | | + +### collectFeesV2 + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenVaultA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultB` | writable | | +| `tokenProgramA` | readonly | | +| `tokenProgramB` | readonly | | +| `memoProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### collectProtocolFeesV2 + +**Accounts:** + +| Account | Type | Description | +| ------------------------------ | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpool` | writable | | +| `collectProtocolFeesAuthority` | signer | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `tokenVaultA` | writable | | +| `tokenVaultB` | writable | | +| `tokenDestinationA` | writable | | +| `tokenDestinationB` | writable | | +| `tokenProgramA` | readonly | | +| `tokenProgramB` | readonly | | +| `memoProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### collectRewardV2 + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `rewardOwnerAccount` | writable | | +| `rewardMint` | readonly | | +| `rewardVault` | writable | | +| `rewardTokenProgram` | readonly | | +| `memoProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### decreaseLiquidityV2 + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `tokenProgramA` | readonly | | +| `tokenProgramB` | readonly | | +| `memoProgram` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultA` | writable | | +| `tokenVaultB` | writable | | +| `tickArrayLower` | writable | | +| `tickArrayUpper` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `liquidityAmount` | `u128` | | +| `tokenMinA` | `u64` | | +| `tokenMinB` | `u64` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### increaseLiquidityV2 + +**Accounts:** + +| Account | Type | Description | +| ---------------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `tokenProgramA` | readonly | | +| `tokenProgramB` | readonly | | +| `memoProgram` | readonly | | +| `positionAuthority` | signer | | +| `position` | writable | | +| `positionTokenAccount` | readonly | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultA` | writable | | +| `tokenVaultB` | writable | | +| `tickArrayLower` | writable | | +| `tickArrayUpper` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `liquidityAmount` | `u128` | | +| `tokenMaxA` | `u64` | | +| `tokenMaxB` | `u64` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### initializePoolV2 + +**Accounts:** + +| Account | Type | Description | +| ------------------ | ---------------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `tokenBadgeA` | readonly | | +| `tokenBadgeB` | readonly | | +| `funder` | signer, writable | | +| `whirlpool` | writable | | +| `tokenVaultA` | signer, writable | | +| `tokenVaultB` | signer, writable | | +| `feeTier` | readonly | | +| `tokenProgramA` | readonly | | +| `tokenProgramB` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------ | --------- | ----------- | +| `discriminator` | `unknown` | | +| `tickSpacing` | `u16` | | +| `initialSqrtPrice` | `u128` | | + +### initializeRewardV2 + +**Accounts:** + +| Account | Type | Description | +| -------------------- | ---------------- | ----------- | +| `rewardAuthority` | signer | | +| `funder` | signer, writable | | +| `whirlpool` | writable | | +| `rewardMint` | readonly | | +| `rewardTokenBadge` | readonly | | +| `rewardVault` | signer, writable | | +| `rewardTokenProgram` | readonly | | +| `systemProgram` | readonly | | +| `rent` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | + +### setRewardEmissionsV2 + +**Accounts:** + +| Account | Type | Description | +| ----------------- | -------- | ----------- | +| `whirlpool` | writable | | +| `rewardAuthority` | signer | | +| `rewardVault` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ----------------------- | --------- | ----------- | +| `discriminator` | `unknown` | | +| `rewardIndex` | `u8` | | +| `emissionsPerSecondX64` | `u128` | | + +### swapV2 + +**Accounts:** + +| Account | Type | Description | +| -------------------- | -------- | ----------- | +| `tokenProgramA` | readonly | | +| `tokenProgramB` | readonly | | +| `memoProgram` | readonly | | +| `tokenAuthority` | signer | | +| `whirlpool` | writable | | +| `tokenMintA` | readonly | | +| `tokenMintB` | readonly | | +| `tokenOwnerAccountA` | writable | | +| `tokenVaultA` | writable | | +| `tokenOwnerAccountB` | writable | | +| `tokenVaultB` | writable | | +| `tickArray0` | writable | | +| `tickArray1` | writable | | +| `tickArray2` | writable | | +| `oracle` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------------ | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `amount` | `u64` | | +| `otherAmountThreshold` | `u64` | | +| `sqrtPriceLimit` | `u128` | | +| `amountSpecifiedIsInput` | `boolean` | | +| `aToB` | `boolean` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### twoHopSwapV2 + +**Accounts:** + +| Account | Type | Description | +| --------------------------- | -------- | ----------- | +| `whirlpoolOne` | writable | | +| `whirlpoolTwo` | writable | | +| `tokenMintInput` | readonly | | +| `tokenMintIntermediate` | readonly | | +| `tokenMintOutput` | readonly | | +| `tokenProgramInput` | readonly | | +| `tokenProgramIntermediate` | readonly | | +| `tokenProgramOutput` | readonly | | +| `tokenOwnerAccountInput` | writable | | +| `tokenVaultOneInput` | writable | | +| `tokenVaultOneIntermediate` | writable | | +| `tokenVaultTwoIntermediate` | writable | | +| `tokenVaultTwoOutput` | writable | | +| `tokenOwnerAccountOutput` | writable | | +| `tokenAuthority` | signer | | +| `tickArrayOne0` | writable | | +| `tickArrayOne1` | writable | | +| `tickArrayOne2` | writable | | +| `tickArrayTwo0` | writable | | +| `tickArrayTwo1` | writable | | +| `tickArrayTwo2` | writable | | +| `oracleOne` | writable | | +| `oracleTwo` | writable | | +| `memoProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| ------------------------ | ------------------------------------------------- | ----------- | --- | +| `discriminator` | `unknown` | | +| `amount` | `u64` | | +| `otherAmountThreshold` | `u64` | | +| `amountSpecifiedIsInput` | `boolean` | | +| `aToBOne` | `boolean` | | +| `aToBTwo` | `boolean` | | +| `sqrtPriceLimitOne` | `u128` | | +| `sqrtPriceLimitTwo` | `u128` | | +| `remainingAccountsInfo` | [remainingAccountsInfo](#remainingAccountsInfo-3) | null | | + +### initializeConfigExtension + +**Accounts:** + +| Account | Type | Description | +| ----------------- | ---------------- | ----------- | +| `config` | readonly | | +| `configExtension` | writable | | +| `funder` | signer, writable | | +| `feeAuthority` | signer | | +| `systemProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### setConfigExtensionAuthority + +**Accounts:** + +| Account | Type | Description | +| ----------------------------- | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpoolsConfigExtension` | writable | | +| `configExtensionAuthority` | signer | | +| `newConfigExtensionAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### setTokenBadgeAuthority + +**Accounts:** + +| Account | Type | Description | +| --------------------------- | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpoolsConfigExtension` | writable | | +| `configExtensionAuthority` | signer | | +| `newTokenBadgeAuthority` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### initializeTokenBadge + +**Accounts:** + +| Account | Type | Description | +| --------------------------- | ---------------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpoolsConfigExtension` | readonly | | +| `tokenBadgeAuthority` | signer | | +| `tokenMint` | readonly | | +| `tokenBadge` | writable | | +| `funder` | signer, writable | | +| `systemProgram` | readonly | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +### deleteTokenBadge + +**Accounts:** + +| Account | Type | Description | +| --------------------------- | -------- | ----------- | +| `whirlpoolsConfig` | readonly | | +| `whirlpoolsConfigExtension` | readonly | | +| `tokenBadgeAuthority` | signer | | +| `tokenMint` | readonly | | +| `tokenBadge` | writable | | +| `receiver` | writable | | + +**Arguments:** + +| Argument | Type | Description | +| --------------- | --------- | ----------- | +| `discriminator` | `unknown` | | + +## Types + +### lockType + +**Definition:** + +```typescript +| { kind: "permanent" } +``` + +### lockTypeLabel + +**Definition:** + +```typescript +| { kind: "permanent" } +``` + +### openPositionBumps + +**Definition:** + +```typescript +{ + positionBump: bigint; +} +``` + +### openPositionWithMetadataBumps + +**Definition:** + +```typescript +{ + positionBump: bigint; + metadataBump: bigint; +} +``` + +### positionRewardInfo + +**Definition:** + +```typescript +{ + growthInsideCheckpoint: bigint; + amountOwed: bigint; +} +``` + +### tick + +**Definition:** + +```typescript +{ + initialized: boolean; + liquidityNet: bigint; + liquidityGross: bigint; + feeGrowthOutsideA: bigint; + feeGrowthOutsideB: bigint; + rewardGrowthsOutside: bigint[3]; +} +``` + +### whirlpoolBumps + +**Definition:** + +```typescript +{ + whirlpoolBump: bigint; +} +``` + +### whirlpoolRewardInfo + +**Definition:** + +```typescript +{ + mint: PublicKey; + vault: PublicKey; + authority: PublicKey; + emissionsPerSecondX64: bigint; + growthGlobalX64: bigint; +} +``` + +### accountsType + +**Definition:** + +```typescript +| { kind: "transferHookA" } + | { kind: "transferHookB" } + | { kind: "transferHookReward" } + | { kind: "transferHookInput" } + | { kind: "transferHookIntermediate" } + | { kind: "transferHookOutput" } + | { kind: "supplementalTickArrays" } + | { kind: "supplementalTickArraysOne" } + | { kind: "supplementalTickArraysTwo" } +``` + +### remainingAccountsInfo + +**Definition:** + +```typescript +{ + slices: remainingAccountsSlice[]; +} +``` + +### remainingAccountsSlice + +**Definition:** + +```typescript +{ + accountsType: accountsType; + length: bigint; +} +``` + +## Errors + +- **6000 - InvalidEnum**: Enum value could not be converted _(Hex: `0x1770`)_ +- **6001 - InvalidStartTick**: Invalid start tick index provided. _(Hex: `0x1771`)_ +- **6002 - TickArrayExistInPool**: Tick-array already exists in this whirlpool _(Hex: `0x1772`)_ +- **6003 - TickArrayIndexOutofBounds**: Attempt to search for a tick-array failed _(Hex: `0x1773`)_ +- **6004 - InvalidTickSpacing**: Tick-spacing is not supported _(Hex: `0x1774`)_ +- **6005 - ClosePositionNotEmpty**: Position is not empty It cannot be closed _(Hex: `0x1775`)_ +- **6006 - DivideByZero**: Unable to divide by zero _(Hex: `0x1776`)_ +- **6007 - NumberCastError**: Unable to cast number into BigInt _(Hex: `0x1777`)_ +- **6008 - NumberDownCastError**: Unable to down cast number _(Hex: `0x1778`)_ +- **6009 - TickNotFound**: Tick not found within tick array _(Hex: `0x1779`)_ +- **6010 - InvalidTickIndex**: Provided tick index is either out of bounds or uninitializable _(Hex: `0x177a`)_ +- **6011 - SqrtPriceOutOfBounds**: Provided sqrt price out of bounds _(Hex: `0x177b`)_ +- **6012 - LiquidityZero**: Liquidity amount must be greater than zero _(Hex: `0x177c`)_ +- **6013 - LiquidityTooHigh**: Liquidity amount must be less than i64::MAX _(Hex: `0x177d`)_ +- **6014 - LiquidityOverflow**: Liquidity overflow _(Hex: `0x177e`)_ +- **6015 - LiquidityUnderflow**: Liquidity underflow _(Hex: `0x177f`)_ +- **6016 - LiquidityNetError**: Tick liquidity net underflowed or overflowed _(Hex: `0x1780`)_ +- **6017 - TokenMaxExceeded**: Exceeded token max _(Hex: `0x1781`)_ +- **6018 - TokenMinSubceeded**: Did not meet token min _(Hex: `0x1782`)_ +- **6019 - MissingOrInvalidDelegate**: Position token account has a missing or invalid delegate _(Hex: `0x1783`)_ +- **6020 - InvalidPositionTokenAmount**: Position token amount must be 1 _(Hex: `0x1784`)_ +- **6021 - InvalidTimestampConversion**: Timestamp should be convertible from i64 to u64 _(Hex: `0x1785`)_ +- **6022 - InvalidTimestamp**: Timestamp should be greater than the last updated timestamp _(Hex: `0x1786`)_ +- **6023 - InvalidTickArraySequence**: Invalid tick array sequence provided for instruction. _(Hex: `0x1787`)_ +- **6024 - InvalidTokenMintOrder**: Token Mint in wrong order _(Hex: `0x1788`)_ +- **6025 - RewardNotInitialized**: Reward not initialized _(Hex: `0x1789`)_ +- **6026 - InvalidRewardIndex**: Invalid reward index _(Hex: `0x178a`)_ +- **6027 - RewardVaultAmountInsufficient**: Reward vault requires amount to support emissions for at least one day _(Hex: `0x178b`)_ +- **6028 - FeeRateMaxExceeded**: Exceeded max fee rate _(Hex: `0x178c`)_ +- **6029 - ProtocolFeeRateMaxExceeded**: Exceeded max protocol fee rate _(Hex: `0x178d`)_ +- **6030 - MultiplicationShiftRightOverflow**: Multiplication with shift right overflow _(Hex: `0x178e`)_ +- **6031 - MulDivOverflow**: Muldiv overflow _(Hex: `0x178f`)_ +- **6032 - MulDivInvalidInput**: Invalid div_u256 input _(Hex: `0x1790`)_ +- **6033 - MultiplicationOverflow**: Multiplication overflow _(Hex: `0x1791`)_ +- **6034 - InvalidSqrtPriceLimitDirection**: Provided SqrtPriceLimit not in the same direction as the swap. _(Hex: `0x1792`)_ +- **6035 - ZeroTradableAmount**: There are no tradable amount to swap. _(Hex: `0x1793`)_ +- **6036 - AmountOutBelowMinimum**: Amount out below minimum threshold _(Hex: `0x1794`)_ +- **6037 - AmountInAboveMaximum**: Amount in above maximum threshold _(Hex: `0x1795`)_ +- **6038 - TickArraySequenceInvalidIndex**: Invalid index for tick array sequence _(Hex: `0x1796`)_ +- **6039 - AmountCalcOverflow**: Amount calculated overflows _(Hex: `0x1797`)_ +- **6040 - AmountRemainingOverflow**: Amount remaining overflows _(Hex: `0x1798`)_ +- **6041 - InvalidIntermediaryMint**: Invalid intermediary mint _(Hex: `0x1799`)_ +- **6042 - DuplicateTwoHopPool**: Duplicate two hop pool _(Hex: `0x179a`)_ +- **6043 - InvalidBundleIndex**: Bundle index is out of bounds _(Hex: `0x179b`)_ +- **6044 - BundledPositionAlreadyOpened**: Position has already been opened _(Hex: `0x179c`)_ +- **6045 - BundledPositionAlreadyClosed**: Position has already been closed _(Hex: `0x179d`)_ +- **6046 - PositionBundleNotDeletable**: Unable to delete PositionBundle with open positions _(Hex: `0x179e`)_ +- **6047 - UnsupportedTokenMint**: Token mint has unsupported attributes _(Hex: `0x179f`)_ +- **6048 - RemainingAccountsInvalidSlice**: Invalid remaining accounts _(Hex: `0x17a0`)_ +- **6049 - RemainingAccountsInsufficient**: Insufficient remaining accounts _(Hex: `0x17a1`)_ +- **6050 - NoExtraAccountsForTransferHook**: Unable to call transfer hook without extra accounts _(Hex: `0x17a2`)_ +- **6051 - IntermediateTokenAmountMismatch**: Output and input amount mismatch _(Hex: `0x17a3`)_ +- **6052 - TransferFeeCalculationError**: Transfer fee calculation failed _(Hex: `0x17a4`)_ +- **6053 - RemainingAccountsDuplicatedAccountsType**: Same accounts type is provided more than once _(Hex: `0x17a5`)_ +- **6054 - FullRangeOnlyPool**: This whirlpool only supports full-range positions _(Hex: `0x17a6`)_ +- **6055 - TooManySupplementalTickArrays**: Too many supplemental tick arrays provided _(Hex: `0x17a7`)_ +- **6056 - DifferentWhirlpoolTickArrayAccount**: TickArray account for different whirlpool provided _(Hex: `0x17a8`)_ +- **6057 - PartialFillError**: Trade resulted in partial fill _(Hex: `0x17a9`)_ +- **6058 - PositionNotLockable**: Position is not lockable _(Hex: `0x17aa`)_ +- **6059 - OperationNotAllowedOnLockedPosition**: Operation not allowed on locked position _(Hex: `0x17ab`)_ diff --git a/clients/orca-whirlpools/eslint.config.js b/clients/orca-whirlpools/eslint.config.js new file mode 100644 index 00000000..f157753e --- /dev/null +++ b/clients/orca-whirlpools/eslint.config.js @@ -0,0 +1,31 @@ +import { configs } from "@macalinao/eslint-config"; + +export default [ + ...configs.fast, + { + languageOptions: { + parserOptions: { + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + files: ["src/generated/**/*.ts"], + rules: { + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/prefer-nullish-coalescing": "off", + }, + }, + { + files: [ + "src/generated/instructions/*.ts", + "src/generated/types/*.ts", + "src/generated/errors/*.ts", + ], + rules: { + "@typescript-eslint/no-unnecessary-condition": "off", + "no-constant-condition": "off", + "@typescript-eslint/no-empty-object-type": "off", + }, + }, +]; diff --git a/clients/orca-whirlpools/idls/whirlpool.json b/clients/orca-whirlpools/idls/whirlpool.json new file mode 100644 index 00000000..6526de4a --- /dev/null +++ b/clients/orca-whirlpools/idls/whirlpool.json @@ -0,0 +1,1485 @@ +{ + "version": "0.3.4", + "name": "whirlpool", + "metadata": { + "address": "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc" + }, + "instructions": [ + { + "name": "initializeConfig", + "accounts": [ + { "name": "config", "isMut": true, "isSigner": true }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "systemProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "feeAuthority", "type": "publicKey" }, + { "name": "collectProtocolFeesAuthority", "type": "publicKey" }, + { "name": "rewardEmissionsSuperAuthority", "type": "publicKey" }, + { "name": "defaultProtocolFeeRate", "type": "u16" } + ] + }, + { + "name": "initializePool", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": true }, + { "name": "tokenVaultB", "isMut": true, "isSigner": true }, + { "name": "feeTier", "isMut": false, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "bumps", "type": { "defined": "WhirlpoolBumps" } }, + { "name": "tickSpacing", "type": "u16" }, + { "name": "initialSqrtPrice", "type": "u128" } + ] + }, + { + "name": "initializeTickArray", + "accounts": [ + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "tickArray", "isMut": true, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "startTickIndex", "type": "i32" }] + }, + { + "name": "initializeFeeTier", + "accounts": [ + { "name": "config", "isMut": false, "isSigner": false }, + { "name": "feeTier", "isMut": true, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "feeAuthority", "isMut": false, "isSigner": true }, + { "name": "systemProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "tickSpacing", "type": "u16" }, + { "name": "defaultFeeRate", "type": "u16" } + ] + }, + { + "name": "initializeReward", + "accounts": [ + { "name": "rewardAuthority", "isMut": false, "isSigner": true }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "rewardMint", "isMut": false, "isSigner": false }, + { "name": "rewardVault", "isMut": true, "isSigner": true }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "rewardIndex", "type": "u8" }] + }, + { + "name": "setRewardEmissions", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "rewardAuthority", "isMut": false, "isSigner": true }, + { "name": "rewardVault", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "rewardIndex", "type": "u8" }, + { "name": "emissionsPerSecondX64", "type": "u128" } + ] + }, + { + "name": "openPosition", + "accounts": [ + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "owner", "isMut": false, "isSigner": false }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionMint", "isMut": true, "isSigner": true }, + { "name": "positionTokenAccount", "isMut": true, "isSigner": false }, + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false }, + { "name": "associatedTokenProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "bumps", "type": { "defined": "OpenPositionBumps" } }, + { "name": "tickLowerIndex", "type": "i32" }, + { "name": "tickUpperIndex", "type": "i32" } + ] + }, + { + "name": "openPositionWithMetadata", + "accounts": [ + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "owner", "isMut": false, "isSigner": false }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionMint", "isMut": true, "isSigner": true }, + { "name": "positionMetadataAccount", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": true, "isSigner": false }, + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false }, + { "name": "associatedTokenProgram", "isMut": false, "isSigner": false }, + { "name": "metadataProgram", "isMut": false, "isSigner": false }, + { "name": "metadataUpdateAuth", "isMut": false, "isSigner": false } + ], + "args": [ + { + "name": "bumps", + "type": { "defined": "OpenPositionWithMetadataBumps" } + }, + { "name": "tickLowerIndex", "type": "i32" }, + { "name": "tickUpperIndex", "type": "i32" } + ] + }, + { + "name": "increaseLiquidity", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tickArrayLower", "isMut": true, "isSigner": false }, + { "name": "tickArrayUpper", "isMut": true, "isSigner": false } + ], + "args": [ + { "name": "liquidityAmount", "type": "u128" }, + { "name": "tokenMaxA", "type": "u64" }, + { "name": "tokenMaxB", "type": "u64" } + ] + }, + { + "name": "decreaseLiquidity", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tickArrayLower", "isMut": true, "isSigner": false }, + { "name": "tickArrayUpper", "isMut": true, "isSigner": false } + ], + "args": [ + { "name": "liquidityAmount", "type": "u128" }, + { "name": "tokenMinA", "type": "u64" }, + { "name": "tokenMinB", "type": "u64" } + ] + }, + { + "name": "updateFeesAndRewards", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "tickArrayLower", "isMut": false, "isSigner": false }, + { "name": "tickArrayUpper", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "collectFees", + "accounts": [ + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "collectReward", + "accounts": [ + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "rewardOwnerAccount", "isMut": true, "isSigner": false }, + { "name": "rewardVault", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "rewardIndex", "type": "u8" }] + }, + { + "name": "collectProtocolFees", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { + "name": "collectProtocolFeesAuthority", + "isMut": false, + "isSigner": true + }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tokenDestinationA", "isMut": true, "isSigner": false }, + { "name": "tokenDestinationB", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "swap", + "accounts": [ + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "tokenAuthority", "isMut": false, "isSigner": true }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tickArray0", "isMut": true, "isSigner": false }, + { "name": "tickArray1", "isMut": true, "isSigner": false }, + { "name": "tickArray2", "isMut": true, "isSigner": false }, + { "name": "oracle", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "amount", "type": "u64" }, + { "name": "otherAmountThreshold", "type": "u64" }, + { "name": "sqrtPriceLimit", "type": "u128" }, + { "name": "amountSpecifiedIsInput", "type": "bool" }, + { "name": "aToB", "type": "bool" } + ] + }, + { + "name": "closePosition", + "accounts": [ + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "receiver", "isMut": true, "isSigner": false }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionMint", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "setDefaultFeeRate", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "feeTier", "isMut": true, "isSigner": false }, + { "name": "feeAuthority", "isMut": false, "isSigner": true } + ], + "args": [{ "name": "defaultFeeRate", "type": "u16" }] + }, + { + "name": "setDefaultProtocolFeeRate", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": true, "isSigner": false }, + { "name": "feeAuthority", "isMut": false, "isSigner": true } + ], + "args": [{ "name": "defaultProtocolFeeRate", "type": "u16" }] + }, + { + "name": "setFeeRate", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "feeAuthority", "isMut": false, "isSigner": true } + ], + "args": [{ "name": "feeRate", "type": "u16" }] + }, + { + "name": "setProtocolFeeRate", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "feeAuthority", "isMut": false, "isSigner": true } + ], + "args": [{ "name": "protocolFeeRate", "type": "u16" }] + }, + { + "name": "setFeeAuthority", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": true, "isSigner": false }, + { "name": "feeAuthority", "isMut": false, "isSigner": true }, + { "name": "newFeeAuthority", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "setCollectProtocolFeesAuthority", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": true, "isSigner": false }, + { + "name": "collectProtocolFeesAuthority", + "isMut": false, + "isSigner": true + }, + { + "name": "newCollectProtocolFeesAuthority", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "setRewardAuthority", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "rewardAuthority", "isMut": false, "isSigner": true }, + { "name": "newRewardAuthority", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "rewardIndex", "type": "u8" }] + }, + { + "name": "setRewardAuthorityBySuperAuthority", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { + "name": "rewardEmissionsSuperAuthority", + "isMut": false, + "isSigner": true + }, + { "name": "newRewardAuthority", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "rewardIndex", "type": "u8" }] + }, + { + "name": "setRewardEmissionsSuperAuthority", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": true, "isSigner": false }, + { + "name": "rewardEmissionsSuperAuthority", + "isMut": false, + "isSigner": true + }, + { + "name": "newRewardEmissionsSuperAuthority", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "twoHopSwap", + "accounts": [ + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "tokenAuthority", "isMut": false, "isSigner": true }, + { "name": "whirlpoolOne", "isMut": true, "isSigner": false }, + { "name": "whirlpoolTwo", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountOneA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultOneA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountOneB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultOneB", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountTwoA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultTwoA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountTwoB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultTwoB", "isMut": true, "isSigner": false }, + { "name": "tickArrayOne0", "isMut": true, "isSigner": false }, + { "name": "tickArrayOne1", "isMut": true, "isSigner": false }, + { "name": "tickArrayOne2", "isMut": true, "isSigner": false }, + { "name": "tickArrayTwo0", "isMut": true, "isSigner": false }, + { "name": "tickArrayTwo1", "isMut": true, "isSigner": false }, + { "name": "tickArrayTwo2", "isMut": true, "isSigner": false }, + { "name": "oracleOne", "isMut": false, "isSigner": false }, + { "name": "oracleTwo", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "amount", "type": "u64" }, + { "name": "otherAmountThreshold", "type": "u64" }, + { "name": "amountSpecifiedIsInput", "type": "bool" }, + { "name": "aToBOne", "type": "bool" }, + { "name": "aToBTwo", "type": "bool" }, + { "name": "sqrtPriceLimitOne", "type": "u128" }, + { "name": "sqrtPriceLimitTwo", "type": "u128" } + ] + }, + { + "name": "initializePositionBundle", + "accounts": [ + { "name": "positionBundle", "isMut": true, "isSigner": false }, + { "name": "positionBundleMint", "isMut": true, "isSigner": true }, + { + "name": "positionBundleTokenAccount", + "isMut": true, + "isSigner": false + }, + { "name": "positionBundleOwner", "isMut": false, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false }, + { "name": "associatedTokenProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "initializePositionBundleWithMetadata", + "accounts": [ + { "name": "positionBundle", "isMut": true, "isSigner": false }, + { "name": "positionBundleMint", "isMut": true, "isSigner": true }, + { "name": "positionBundleMetadata", "isMut": true, "isSigner": false }, + { + "name": "positionBundleTokenAccount", + "isMut": true, + "isSigner": false + }, + { "name": "positionBundleOwner", "isMut": false, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "metadataUpdateAuth", "isMut": false, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false }, + { "name": "associatedTokenProgram", "isMut": false, "isSigner": false }, + { "name": "metadataProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "deletePositionBundle", + "accounts": [ + { "name": "positionBundle", "isMut": true, "isSigner": false }, + { "name": "positionBundleMint", "isMut": true, "isSigner": false }, + { + "name": "positionBundleTokenAccount", + "isMut": true, + "isSigner": false + }, + { "name": "positionBundleOwner", "isMut": false, "isSigner": true }, + { "name": "receiver", "isMut": true, "isSigner": false }, + { "name": "tokenProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "openBundledPosition", + "accounts": [ + { "name": "bundledPosition", "isMut": true, "isSigner": false }, + { "name": "positionBundle", "isMut": true, "isSigner": false }, + { + "name": "positionBundleTokenAccount", + "isMut": false, + "isSigner": false + }, + { "name": "positionBundleAuthority", "isMut": false, "isSigner": true }, + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "bundleIndex", "type": "u16" }, + { "name": "tickLowerIndex", "type": "i32" }, + { "name": "tickUpperIndex", "type": "i32" } + ] + }, + { + "name": "closeBundledPosition", + "accounts": [ + { "name": "bundledPosition", "isMut": true, "isSigner": false }, + { "name": "positionBundle", "isMut": true, "isSigner": false }, + { + "name": "positionBundleTokenAccount", + "isMut": false, + "isSigner": false + }, + { "name": "positionBundleAuthority", "isMut": false, "isSigner": true }, + { "name": "receiver", "isMut": true, "isSigner": false } + ], + "args": [{ "name": "bundleIndex", "type": "u16" }] + }, + { + "name": "openPositionWithTokenExtensions", + "accounts": [ + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "owner", "isMut": false, "isSigner": false }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionMint", "isMut": true, "isSigner": true }, + { "name": "positionTokenAccount", "isMut": true, "isSigner": false }, + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "token2022Program", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "associatedTokenProgram", "isMut": false, "isSigner": false }, + { "name": "metadataUpdateAuth", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "tickLowerIndex", "type": "i32" }, + { "name": "tickUpperIndex", "type": "i32" }, + { "name": "withTokenMetadataExtension", "type": "bool" } + ] + }, + { + "name": "closePositionWithTokenExtensions", + "accounts": [ + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "receiver", "isMut": true, "isSigner": false }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionMint", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": true, "isSigner": false }, + { "name": "token2022Program", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "lockPosition", + "accounts": [ + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": false, "isSigner": false }, + { "name": "positionMint", "isMut": false, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": true, "isSigner": false }, + { "name": "lockConfig", "isMut": true, "isSigner": false }, + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "token2022Program", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "lockType", "type": { "defined": "LockType" } }] + }, + { + "name": "collectFeesV2", + "accounts": [ + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tokenProgramA", "isMut": false, "isSigner": false }, + { "name": "tokenProgramB", "isMut": false, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "collectProtocolFeesV2", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { + "name": "collectProtocolFeesAuthority", + "isMut": false, + "isSigner": true + }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tokenDestinationA", "isMut": true, "isSigner": false }, + { "name": "tokenDestinationB", "isMut": true, "isSigner": false }, + { "name": "tokenProgramA", "isMut": false, "isSigner": false }, + { "name": "tokenProgramB", "isMut": false, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "collectRewardV2", + "accounts": [ + { "name": "whirlpool", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "rewardOwnerAccount", "isMut": true, "isSigner": false }, + { "name": "rewardMint", "isMut": false, "isSigner": false }, + { "name": "rewardVault", "isMut": true, "isSigner": false }, + { "name": "rewardTokenProgram", "isMut": false, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "rewardIndex", "type": "u8" }, + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "decreaseLiquidityV2", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenProgramA", "isMut": false, "isSigner": false }, + { "name": "tokenProgramB", "isMut": false, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tickArrayLower", "isMut": true, "isSigner": false }, + { "name": "tickArrayUpper", "isMut": true, "isSigner": false } + ], + "args": [ + { "name": "liquidityAmount", "type": "u128" }, + { "name": "tokenMinA", "type": "u64" }, + { "name": "tokenMinB", "type": "u64" }, + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "increaseLiquidityV2", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenProgramA", "isMut": false, "isSigner": false }, + { "name": "tokenProgramB", "isMut": false, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false }, + { "name": "positionAuthority", "isMut": false, "isSigner": true }, + { "name": "position", "isMut": true, "isSigner": false }, + { "name": "positionTokenAccount", "isMut": false, "isSigner": false }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tickArrayLower", "isMut": true, "isSigner": false }, + { "name": "tickArrayUpper", "isMut": true, "isSigner": false } + ], + "args": [ + { "name": "liquidityAmount", "type": "u128" }, + { "name": "tokenMaxA", "type": "u64" }, + { "name": "tokenMaxB", "type": "u64" }, + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "initializePoolV2", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "tokenBadgeA", "isMut": false, "isSigner": false }, + { "name": "tokenBadgeB", "isMut": false, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": true }, + { "name": "tokenVaultB", "isMut": true, "isSigner": true }, + { "name": "feeTier", "isMut": false, "isSigner": false }, + { "name": "tokenProgramA", "isMut": false, "isSigner": false }, + { "name": "tokenProgramB", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "tickSpacing", "type": "u16" }, + { "name": "initialSqrtPrice", "type": "u128" } + ] + }, + { + "name": "initializeRewardV2", + "accounts": [ + { "name": "rewardAuthority", "isMut": false, "isSigner": true }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "rewardMint", "isMut": false, "isSigner": false }, + { "name": "rewardTokenBadge", "isMut": false, "isSigner": false }, + { "name": "rewardVault", "isMut": true, "isSigner": true }, + { "name": "rewardTokenProgram", "isMut": false, "isSigner": false }, + { "name": "systemProgram", "isMut": false, "isSigner": false }, + { "name": "rent", "isMut": false, "isSigner": false } + ], + "args": [{ "name": "rewardIndex", "type": "u8" }] + }, + { + "name": "setRewardEmissionsV2", + "accounts": [ + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "rewardAuthority", "isMut": false, "isSigner": true }, + { "name": "rewardVault", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "rewardIndex", "type": "u8" }, + { "name": "emissionsPerSecondX64", "type": "u128" } + ] + }, + { + "name": "swapV2", + "accounts": [ + { "name": "tokenProgramA", "isMut": false, "isSigner": false }, + { "name": "tokenProgramB", "isMut": false, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false }, + { "name": "tokenAuthority", "isMut": false, "isSigner": true }, + { "name": "whirlpool", "isMut": true, "isSigner": false }, + { "name": "tokenMintA", "isMut": false, "isSigner": false }, + { "name": "tokenMintB", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountA", "isMut": true, "isSigner": false }, + { "name": "tokenVaultA", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountB", "isMut": true, "isSigner": false }, + { "name": "tokenVaultB", "isMut": true, "isSigner": false }, + { "name": "tickArray0", "isMut": true, "isSigner": false }, + { "name": "tickArray1", "isMut": true, "isSigner": false }, + { "name": "tickArray2", "isMut": true, "isSigner": false }, + { "name": "oracle", "isMut": true, "isSigner": false } + ], + "args": [ + { "name": "amount", "type": "u64" }, + { "name": "otherAmountThreshold", "type": "u64" }, + { "name": "sqrtPriceLimit", "type": "u128" }, + { "name": "amountSpecifiedIsInput", "type": "bool" }, + { "name": "aToB", "type": "bool" }, + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "twoHopSwapV2", + "accounts": [ + { "name": "whirlpoolOne", "isMut": true, "isSigner": false }, + { "name": "whirlpoolTwo", "isMut": true, "isSigner": false }, + { "name": "tokenMintInput", "isMut": false, "isSigner": false }, + { "name": "tokenMintIntermediate", "isMut": false, "isSigner": false }, + { "name": "tokenMintOutput", "isMut": false, "isSigner": false }, + { "name": "tokenProgramInput", "isMut": false, "isSigner": false }, + { + "name": "tokenProgramIntermediate", + "isMut": false, + "isSigner": false + }, + { "name": "tokenProgramOutput", "isMut": false, "isSigner": false }, + { "name": "tokenOwnerAccountInput", "isMut": true, "isSigner": false }, + { "name": "tokenVaultOneInput", "isMut": true, "isSigner": false }, + { + "name": "tokenVaultOneIntermediate", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenVaultTwoIntermediate", + "isMut": true, + "isSigner": false + }, + { "name": "tokenVaultTwoOutput", "isMut": true, "isSigner": false }, + { "name": "tokenOwnerAccountOutput", "isMut": true, "isSigner": false }, + { "name": "tokenAuthority", "isMut": false, "isSigner": true }, + { "name": "tickArrayOne0", "isMut": true, "isSigner": false }, + { "name": "tickArrayOne1", "isMut": true, "isSigner": false }, + { "name": "tickArrayOne2", "isMut": true, "isSigner": false }, + { "name": "tickArrayTwo0", "isMut": true, "isSigner": false }, + { "name": "tickArrayTwo1", "isMut": true, "isSigner": false }, + { "name": "tickArrayTwo2", "isMut": true, "isSigner": false }, + { "name": "oracleOne", "isMut": true, "isSigner": false }, + { "name": "oracleTwo", "isMut": true, "isSigner": false }, + { "name": "memoProgram", "isMut": false, "isSigner": false } + ], + "args": [ + { "name": "amount", "type": "u64" }, + { "name": "otherAmountThreshold", "type": "u64" }, + { "name": "amountSpecifiedIsInput", "type": "bool" }, + { "name": "aToBOne", "type": "bool" }, + { "name": "aToBTwo", "type": "bool" }, + { "name": "sqrtPriceLimitOne", "type": "u128" }, + { "name": "sqrtPriceLimitTwo", "type": "u128" }, + { + "name": "remainingAccountsInfo", + "type": { "option": { "defined": "RemainingAccountsInfo" } } + } + ] + }, + { + "name": "initializeConfigExtension", + "accounts": [ + { "name": "config", "isMut": false, "isSigner": false }, + { "name": "configExtension", "isMut": true, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "feeAuthority", "isMut": false, "isSigner": true }, + { "name": "systemProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "setConfigExtensionAuthority", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { + "name": "whirlpoolsConfigExtension", + "isMut": true, + "isSigner": false + }, + { + "name": "configExtensionAuthority", + "isMut": false, + "isSigner": true + }, + { + "name": "newConfigExtensionAuthority", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "setTokenBadgeAuthority", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { + "name": "whirlpoolsConfigExtension", + "isMut": true, + "isSigner": false + }, + { + "name": "configExtensionAuthority", + "isMut": false, + "isSigner": true + }, + { "name": "newTokenBadgeAuthority", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "initializeTokenBadge", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { + "name": "whirlpoolsConfigExtension", + "isMut": false, + "isSigner": false + }, + { "name": "tokenBadgeAuthority", "isMut": false, "isSigner": true }, + { "name": "tokenMint", "isMut": false, "isSigner": false }, + { "name": "tokenBadge", "isMut": true, "isSigner": false }, + { "name": "funder", "isMut": true, "isSigner": true }, + { "name": "systemProgram", "isMut": false, "isSigner": false } + ], + "args": [] + }, + { + "name": "deleteTokenBadge", + "accounts": [ + { "name": "whirlpoolsConfig", "isMut": false, "isSigner": false }, + { + "name": "whirlpoolsConfigExtension", + "isMut": false, + "isSigner": false + }, + { "name": "tokenBadgeAuthority", "isMut": false, "isSigner": true }, + { "name": "tokenMint", "isMut": false, "isSigner": false }, + { "name": "tokenBadge", "isMut": true, "isSigner": false }, + { "name": "receiver", "isMut": true, "isSigner": false } + ], + "args": [] + } + ], + "accounts": [ + { + "name": "WhirlpoolsConfig", + "type": { + "kind": "struct", + "fields": [ + { "name": "feeAuthority", "type": "publicKey" }, + { "name": "collectProtocolFeesAuthority", "type": "publicKey" }, + { "name": "rewardEmissionsSuperAuthority", "type": "publicKey" }, + { "name": "defaultProtocolFeeRate", "type": "u16" } + ] + } + }, + { + "name": "WhirlpoolsConfigExtension", + "type": { + "kind": "struct", + "fields": [ + { "name": "whirlpoolsConfig", "type": "publicKey" }, + { "name": "configExtensionAuthority", "type": "publicKey" }, + { "name": "tokenBadgeAuthority", "type": "publicKey" } + ] + } + }, + { + "name": "FeeTier", + "type": { + "kind": "struct", + "fields": [ + { "name": "whirlpoolsConfig", "type": "publicKey" }, + { "name": "tickSpacing", "type": "u16" }, + { "name": "defaultFeeRate", "type": "u16" } + ] + } + }, + { + "name": "LockConfig", + "type": { + "kind": "struct", + "fields": [ + { "name": "position", "type": "publicKey" }, + { "name": "positionOwner", "type": "publicKey" }, + { "name": "whirlpool", "type": "publicKey" }, + { "name": "lockedTimestamp", "type": "u64" }, + { "name": "lockType", "type": { "defined": "LockTypeLabel" } } + ] + } + }, + { + "name": "Position", + "type": { + "kind": "struct", + "fields": [ + { "name": "whirlpool", "type": "publicKey" }, + { "name": "positionMint", "type": "publicKey" }, + { "name": "liquidity", "type": "u128" }, + { "name": "tickLowerIndex", "type": "i32" }, + { "name": "tickUpperIndex", "type": "i32" }, + { "name": "feeGrowthCheckpointA", "type": "u128" }, + { "name": "feeOwedA", "type": "u64" }, + { "name": "feeGrowthCheckpointB", "type": "u128" }, + { "name": "feeOwedB", "type": "u64" }, + { + "name": "rewardInfos", + "type": { "array": [{ "defined": "PositionRewardInfo" }, 3] } + } + ] + } + }, + { + "name": "PositionBundle", + "type": { + "kind": "struct", + "fields": [ + { "name": "positionBundleMint", "type": "publicKey" }, + { "name": "positionBitmap", "type": { "array": ["u8", 32] } } + ] + } + }, + { + "name": "TickArray", + "type": { + "kind": "struct", + "fields": [ + { "name": "startTickIndex", "type": "i32" }, + { "name": "ticks", "type": { "array": [{ "defined": "Tick" }, 88] } }, + { "name": "whirlpool", "type": "publicKey" } + ] + } + }, + { + "name": "TokenBadge", + "type": { + "kind": "struct", + "fields": [ + { "name": "whirlpoolsConfig", "type": "publicKey" }, + { "name": "tokenMint", "type": "publicKey" } + ] + } + }, + { + "name": "Whirlpool", + "type": { + "kind": "struct", + "fields": [ + { "name": "whirlpoolsConfig", "type": "publicKey" }, + { "name": "whirlpoolBump", "type": { "array": ["u8", 1] } }, + { "name": "tickSpacing", "type": "u16" }, + { "name": "tickSpacingSeed", "type": { "array": ["u8", 2] } }, + { "name": "feeRate", "type": "u16" }, + { "name": "protocolFeeRate", "type": "u16" }, + { "name": "liquidity", "type": "u128" }, + { "name": "sqrtPrice", "type": "u128" }, + { "name": "tickCurrentIndex", "type": "i32" }, + { "name": "protocolFeeOwedA", "type": "u64" }, + { "name": "protocolFeeOwedB", "type": "u64" }, + { "name": "tokenMintA", "type": "publicKey" }, + { "name": "tokenVaultA", "type": "publicKey" }, + { "name": "feeGrowthGlobalA", "type": "u128" }, + { "name": "tokenMintB", "type": "publicKey" }, + { "name": "tokenVaultB", "type": "publicKey" }, + { "name": "feeGrowthGlobalB", "type": "u128" }, + { "name": "rewardLastUpdatedTimestamp", "type": "u64" }, + { + "name": "rewardInfos", + "type": { "array": [{ "defined": "WhirlpoolRewardInfo" }, 3] } + } + ] + } + } + ], + "types": [ + { + "name": "LockType", + "type": { "kind": "enum", "variants": [{ "name": "Permanent" }] } + }, + { + "name": "LockTypeLabel", + "type": { "kind": "enum", "variants": [{ "name": "Permanent" }] } + }, + { + "name": "OpenPositionBumps", + "type": { + "kind": "struct", + "fields": [{ "name": "positionBump", "type": "u8" }] + } + }, + { + "name": "OpenPositionWithMetadataBumps", + "type": { + "kind": "struct", + "fields": [ + { "name": "positionBump", "type": "u8" }, + { "name": "metadataBump", "type": "u8" } + ] + } + }, + { + "name": "PositionRewardInfo", + "type": { + "kind": "struct", + "fields": [ + { "name": "growthInsideCheckpoint", "type": "u128" }, + { "name": "amountOwed", "type": "u64" } + ] + } + }, + { + "name": "Tick", + "type": { + "kind": "struct", + "fields": [ + { "name": "initialized", "type": "bool" }, + { "name": "liquidityNet", "type": "i128" }, + { "name": "liquidityGross", "type": "u128" }, + { "name": "feeGrowthOutsideA", "type": "u128" }, + { "name": "feeGrowthOutsideB", "type": "u128" }, + { "name": "rewardGrowthsOutside", "type": { "array": ["u128", 3] } } + ] + } + }, + { + "name": "WhirlpoolBumps", + "type": { + "kind": "struct", + "fields": [{ "name": "whirlpoolBump", "type": "u8" }] + } + }, + { + "name": "WhirlpoolRewardInfo", + "type": { + "kind": "struct", + "fields": [ + { "name": "mint", "type": "publicKey" }, + { "name": "vault", "type": "publicKey" }, + { "name": "authority", "type": "publicKey" }, + { "name": "emissionsPerSecondX64", "type": "u128" }, + { "name": "growthGlobalX64", "type": "u128" } + ] + } + }, + { + "name": "AccountsType", + "type": { + "kind": "enum", + "variants": [ + { "name": "TransferHookA" }, + { "name": "TransferHookB" }, + { "name": "TransferHookReward" }, + { "name": "TransferHookInput" }, + { "name": "TransferHookIntermediate" }, + { "name": "TransferHookOutput" }, + { "name": "SupplementalTickArrays" }, + { "name": "SupplementalTickArraysOne" }, + { "name": "SupplementalTickArraysTwo" } + ] + } + }, + { + "name": "RemainingAccountsInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "slices", + "type": { "vec": { "defined": "RemainingAccountsSlice" } } + } + ] + } + }, + { + "name": "RemainingAccountsSlice", + "type": { + "kind": "struct", + "fields": [ + { "name": "accountsType", "type": { "defined": "AccountsType" } }, + { "name": "length", "type": "u8" } + ] + } + } + ], + "events": [ + { + "name": "LiquidityDecreased", + "fields": [ + { "name": "whirlpool", "type": "publicKey", "index": false }, + { "name": "position", "type": "publicKey", "index": false }, + { "name": "tickLowerIndex", "type": "i32", "index": false }, + { "name": "tickUpperIndex", "type": "i32", "index": false }, + { "name": "liquidity", "type": "u128", "index": false }, + { "name": "tokenAAmount", "type": "u64", "index": false }, + { "name": "tokenBAmount", "type": "u64", "index": false }, + { "name": "tokenATransferFee", "type": "u64", "index": false }, + { "name": "tokenBTransferFee", "type": "u64", "index": false } + ] + }, + { + "name": "LiquidityIncreased", + "fields": [ + { "name": "whirlpool", "type": "publicKey", "index": false }, + { "name": "position", "type": "publicKey", "index": false }, + { "name": "tickLowerIndex", "type": "i32", "index": false }, + { "name": "tickUpperIndex", "type": "i32", "index": false }, + { "name": "liquidity", "type": "u128", "index": false }, + { "name": "tokenAAmount", "type": "u64", "index": false }, + { "name": "tokenBAmount", "type": "u64", "index": false }, + { "name": "tokenATransferFee", "type": "u64", "index": false }, + { "name": "tokenBTransferFee", "type": "u64", "index": false } + ] + }, + { + "name": "PoolInitialized", + "fields": [ + { "name": "whirlpool", "type": "publicKey", "index": false }, + { "name": "whirlpoolsConfig", "type": "publicKey", "index": false }, + { "name": "tokenMintA", "type": "publicKey", "index": false }, + { "name": "tokenMintB", "type": "publicKey", "index": false }, + { "name": "tickSpacing", "type": "u16", "index": false }, + { "name": "tokenProgramA", "type": "publicKey", "index": false }, + { "name": "tokenProgramB", "type": "publicKey", "index": false }, + { "name": "decimalsA", "type": "u8", "index": false }, + { "name": "decimalsB", "type": "u8", "index": false }, + { "name": "initialSqrtPrice", "type": "u128", "index": false } + ] + }, + { + "name": "Traded", + "fields": [ + { "name": "whirlpool", "type": "publicKey", "index": false }, + { "name": "aToB", "type": "bool", "index": false }, + { "name": "preSqrtPrice", "type": "u128", "index": false }, + { "name": "postSqrtPrice", "type": "u128", "index": false }, + { "name": "inputAmount", "type": "u64", "index": false }, + { "name": "outputAmount", "type": "u64", "index": false }, + { "name": "inputTransferFee", "type": "u64", "index": false }, + { "name": "outputTransferFee", "type": "u64", "index": false }, + { "name": "lpFee", "type": "u64", "index": false }, + { "name": "protocolFee", "type": "u64", "index": false } + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "InvalidEnum", + "msg": "Enum value could not be converted" + }, + { + "code": 6001, + "name": "InvalidStartTick", + "msg": "Invalid start tick index provided." + }, + { + "code": 6002, + "name": "TickArrayExistInPool", + "msg": "Tick-array already exists in this whirlpool" + }, + { + "code": 6003, + "name": "TickArrayIndexOutofBounds", + "msg": "Attempt to search for a tick-array failed" + }, + { + "code": 6004, + "name": "InvalidTickSpacing", + "msg": "Tick-spacing is not supported" + }, + { + "code": 6005, + "name": "ClosePositionNotEmpty", + "msg": "Position is not empty It cannot be closed" + }, + { "code": 6006, "name": "DivideByZero", "msg": "Unable to divide by zero" }, + { + "code": 6007, + "name": "NumberCastError", + "msg": "Unable to cast number into BigInt" + }, + { + "code": 6008, + "name": "NumberDownCastError", + "msg": "Unable to down cast number" + }, + { + "code": 6009, + "name": "TickNotFound", + "msg": "Tick not found within tick array" + }, + { + "code": 6010, + "name": "InvalidTickIndex", + "msg": "Provided tick index is either out of bounds or uninitializable" + }, + { + "code": 6011, + "name": "SqrtPriceOutOfBounds", + "msg": "Provided sqrt price out of bounds" + }, + { + "code": 6012, + "name": "LiquidityZero", + "msg": "Liquidity amount must be greater than zero" + }, + { + "code": 6013, + "name": "LiquidityTooHigh", + "msg": "Liquidity amount must be less than i64::MAX" + }, + { "code": 6014, "name": "LiquidityOverflow", "msg": "Liquidity overflow" }, + { + "code": 6015, + "name": "LiquidityUnderflow", + "msg": "Liquidity underflow" + }, + { + "code": 6016, + "name": "LiquidityNetError", + "msg": "Tick liquidity net underflowed or overflowed" + }, + { "code": 6017, "name": "TokenMaxExceeded", "msg": "Exceeded token max" }, + { + "code": 6018, + "name": "TokenMinSubceeded", + "msg": "Did not meet token min" + }, + { + "code": 6019, + "name": "MissingOrInvalidDelegate", + "msg": "Position token account has a missing or invalid delegate" + }, + { + "code": 6020, + "name": "InvalidPositionTokenAmount", + "msg": "Position token amount must be 1" + }, + { + "code": 6021, + "name": "InvalidTimestampConversion", + "msg": "Timestamp should be convertible from i64 to u64" + }, + { + "code": 6022, + "name": "InvalidTimestamp", + "msg": "Timestamp should be greater than the last updated timestamp" + }, + { + "code": 6023, + "name": "InvalidTickArraySequence", + "msg": "Invalid tick array sequence provided for instruction." + }, + { + "code": 6024, + "name": "InvalidTokenMintOrder", + "msg": "Token Mint in wrong order" + }, + { + "code": 6025, + "name": "RewardNotInitialized", + "msg": "Reward not initialized" + }, + { + "code": 6026, + "name": "InvalidRewardIndex", + "msg": "Invalid reward index" + }, + { + "code": 6027, + "name": "RewardVaultAmountInsufficient", + "msg": "Reward vault requires amount to support emissions for at least one day" + }, + { + "code": 6028, + "name": "FeeRateMaxExceeded", + "msg": "Exceeded max fee rate" + }, + { + "code": 6029, + "name": "ProtocolFeeRateMaxExceeded", + "msg": "Exceeded max protocol fee rate" + }, + { + "code": 6030, + "name": "MultiplicationShiftRightOverflow", + "msg": "Multiplication with shift right overflow" + }, + { "code": 6031, "name": "MulDivOverflow", "msg": "Muldiv overflow" }, + { + "code": 6032, + "name": "MulDivInvalidInput", + "msg": "Invalid div_u256 input" + }, + { + "code": 6033, + "name": "MultiplicationOverflow", + "msg": "Multiplication overflow" + }, + { + "code": 6034, + "name": "InvalidSqrtPriceLimitDirection", + "msg": "Provided SqrtPriceLimit not in the same direction as the swap." + }, + { + "code": 6035, + "name": "ZeroTradableAmount", + "msg": "There are no tradable amount to swap." + }, + { + "code": 6036, + "name": "AmountOutBelowMinimum", + "msg": "Amount out below minimum threshold" + }, + { + "code": 6037, + "name": "AmountInAboveMaximum", + "msg": "Amount in above maximum threshold" + }, + { + "code": 6038, + "name": "TickArraySequenceInvalidIndex", + "msg": "Invalid index for tick array sequence" + }, + { + "code": 6039, + "name": "AmountCalcOverflow", + "msg": "Amount calculated overflows" + }, + { + "code": 6040, + "name": "AmountRemainingOverflow", + "msg": "Amount remaining overflows" + }, + { + "code": 6041, + "name": "InvalidIntermediaryMint", + "msg": "Invalid intermediary mint" + }, + { + "code": 6042, + "name": "DuplicateTwoHopPool", + "msg": "Duplicate two hop pool" + }, + { + "code": 6043, + "name": "InvalidBundleIndex", + "msg": "Bundle index is out of bounds" + }, + { + "code": 6044, + "name": "BundledPositionAlreadyOpened", + "msg": "Position has already been opened" + }, + { + "code": 6045, + "name": "BundledPositionAlreadyClosed", + "msg": "Position has already been closed" + }, + { + "code": 6046, + "name": "PositionBundleNotDeletable", + "msg": "Unable to delete PositionBundle with open positions" + }, + { + "code": 6047, + "name": "UnsupportedTokenMint", + "msg": "Token mint has unsupported attributes" + }, + { + "code": 6048, + "name": "RemainingAccountsInvalidSlice", + "msg": "Invalid remaining accounts" + }, + { + "code": 6049, + "name": "RemainingAccountsInsufficient", + "msg": "Insufficient remaining accounts" + }, + { + "code": 6050, + "name": "NoExtraAccountsForTransferHook", + "msg": "Unable to call transfer hook without extra accounts" + }, + { + "code": 6051, + "name": "IntermediateTokenAmountMismatch", + "msg": "Output and input amount mismatch" + }, + { + "code": 6052, + "name": "TransferFeeCalculationError", + "msg": "Transfer fee calculation failed" + }, + { + "code": 6053, + "name": "RemainingAccountsDuplicatedAccountsType", + "msg": "Same accounts type is provided more than once" + }, + { + "code": 6054, + "name": "FullRangeOnlyPool", + "msg": "This whirlpool only supports full-range positions" + }, + { + "code": 6055, + "name": "TooManySupplementalTickArrays", + "msg": "Too many supplemental tick arrays provided" + }, + { + "code": 6056, + "name": "DifferentWhirlpoolTickArrayAccount", + "msg": "TickArray account for different whirlpool provided" + }, + { + "code": 6057, + "name": "PartialFillError", + "msg": "Trade resulted in partial fill" + }, + { + "code": 6058, + "name": "PositionNotLockable", + "msg": "Position is not lockable" + }, + { + "code": 6059, + "name": "OperationNotAllowedOnLockedPosition", + "msg": "Operation not allowed on locked position" + } + ] +} diff --git a/clients/orca-whirlpools/package.json b/clients/orca-whirlpools/package.json new file mode 100644 index 00000000..a68e32f6 --- /dev/null +++ b/clients/orca-whirlpools/package.json @@ -0,0 +1,55 @@ +{ + "name": "@macalinao/clients-orca-whirlpools", + "version": "0.1.0", + "description": "TypeScript client for Orca Whirlpools program", + "type": "module", + "sideEffects": false, + "license": "Apache-2.0", + "keywords": [ + "coda", + "solana", + "orca", + "whirlpools", + "dex", + "amm", + "client", + "typescript" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, + "files": [ + "dist/", + "src/" + ], + "scripts": { + "build": "tsc", + "clean": "rm -fr dist/ tsconfig.tsbuildinfo", + "codegen": "rm -fr src/generated/ && coda generate", + "lint": "eslint . --cache" + }, + "peerDependencies": { + "@solana/kit": "*" + }, + "devDependencies": { + "@macalinao/coda": "workspace:*", + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@solana/kit": "*", + "eslint": "catalog:", + "typescript": "catalog:" + }, + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/macalinao/coda.git", + "directory": "clients/orca-whirlpools" + } +} diff --git a/clients/orca-whirlpools/src/generated/accounts/feeTier.ts b/clients/orca-whirlpools/src/generated/accounts/feeTier.ts new file mode 100644 index 00000000..08d04854 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/feeTier.ts @@ -0,0 +1,139 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; + +export const FEE_TIER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 56, 75, 159, 76, 142, 68, 190, 105, +]); + +export function getFeeTierDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(FEE_TIER_DISCRIMINATOR); +} + +export interface FeeTier { + discriminator: ReadonlyUint8Array; + whirlpoolsConfig: Address; + tickSpacing: number; + defaultFeeRate: number; +} + +export interface FeeTierArgs { + whirlpoolsConfig: Address; + tickSpacing: number; + defaultFeeRate: number; +} + +export function getFeeTierEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["whirlpoolsConfig", getAddressEncoder()], + ["tickSpacing", getU16Encoder()], + ["defaultFeeRate", getU16Encoder()], + ]), + (value) => ({ ...value, discriminator: FEE_TIER_DISCRIMINATOR }), + ); +} + +export function getFeeTierDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["whirlpoolsConfig", getAddressDecoder()], + ["tickSpacing", getU16Decoder()], + ["defaultFeeRate", getU16Decoder()], + ]); +} + +export function getFeeTierCodec(): FixedSizeCodec { + return combineCodec(getFeeTierEncoder(), getFeeTierDecoder()); +} + +export function decodeFeeTier( + encodedAccount: EncodedAccount, +): Account; +export function decodeFeeTier( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeFeeTier( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getFeeTierDecoder(), + ); +} + +export async function fetchFeeTier( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeFeeTier(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeFeeTier( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeFeeTier(maybeAccount); +} + +export async function fetchAllFeeTier( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeFeeTier(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeFeeTier( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeFeeTier(maybeAccount)); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/index.ts b/clients/orca-whirlpools/src/generated/accounts/index.ts new file mode 100644 index 00000000..76a801cb --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/index.ts @@ -0,0 +1,17 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./feeTier.js"; +export * from "./lockConfig.js"; +export * from "./position.js"; +export * from "./positionBundle.js"; +export * from "./tickArray.js"; +export * from "./tokenBadge.js"; +export * from "./whirlpool.js"; +export * from "./whirlpoolsConfig.js"; +export * from "./whirlpoolsConfigExtension.js"; diff --git a/clients/orca-whirlpools/src/generated/accounts/lockConfig.ts b/clients/orca-whirlpools/src/generated/accounts/lockConfig.ts new file mode 100644 index 00000000..95e03eaf --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/lockConfig.ts @@ -0,0 +1,155 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import type { LockTypeLabel, LockTypeLabelArgs } from "../types/index.js"; +import { + getLockTypeLabelDecoder, + getLockTypeLabelEncoder, +} from "../types/index.js"; + +export const LOCK_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 106, 47, 238, 159, 124, 12, 160, 192, +]); + +export function getLockConfigDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(LOCK_CONFIG_DISCRIMINATOR); +} + +export interface LockConfig { + discriminator: ReadonlyUint8Array; + position: Address; + positionOwner: Address; + whirlpool: Address; + lockedTimestamp: bigint; + lockType: LockTypeLabel; +} + +export interface LockConfigArgs { + position: Address; + positionOwner: Address; + whirlpool: Address; + lockedTimestamp: number | bigint; + lockType: LockTypeLabelArgs; +} + +export function getLockConfigEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["position", getAddressEncoder()], + ["positionOwner", getAddressEncoder()], + ["whirlpool", getAddressEncoder()], + ["lockedTimestamp", getU64Encoder()], + ["lockType", getLockTypeLabelEncoder()], + ]), + (value) => ({ ...value, discriminator: LOCK_CONFIG_DISCRIMINATOR }), + ); +} + +export function getLockConfigDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["position", getAddressDecoder()], + ["positionOwner", getAddressDecoder()], + ["whirlpool", getAddressDecoder()], + ["lockedTimestamp", getU64Decoder()], + ["lockType", getLockTypeLabelDecoder()], + ]); +} + +export function getLockConfigCodec(): FixedSizeCodec< + LockConfigArgs, + LockConfig +> { + return combineCodec(getLockConfigEncoder(), getLockConfigDecoder()); +} + +export function decodeLockConfig( + encodedAccount: EncodedAccount, +): Account; +export function decodeLockConfig( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeLockConfig( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getLockConfigDecoder(), + ); +} + +export async function fetchLockConfig( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeLockConfig(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLockConfig( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeLockConfig(maybeAccount); +} + +export async function fetchAllLockConfig( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeLockConfig(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeLockConfig( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeLockConfig(maybeAccount)); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/position.ts b/clients/orca-whirlpools/src/generated/accounts/position.ts new file mode 100644 index 00000000..9c00926a --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/position.ts @@ -0,0 +1,187 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import type { + PositionRewardInfo, + PositionRewardInfoArgs, +} from "../types/index.js"; +import { + getPositionRewardInfoDecoder, + getPositionRewardInfoEncoder, +} from "../types/index.js"; + +export const POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 170, 188, 143, 228, 122, 64, 247, 208, +]); + +export function getPositionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(POSITION_DISCRIMINATOR); +} + +export interface Position { + discriminator: ReadonlyUint8Array; + whirlpool: Address; + positionMint: Address; + liquidity: bigint; + tickLowerIndex: number; + tickUpperIndex: number; + feeGrowthCheckpointA: bigint; + feeOwedA: bigint; + feeGrowthCheckpointB: bigint; + feeOwedB: bigint; + rewardInfos: PositionRewardInfo[]; +} + +export interface PositionArgs { + whirlpool: Address; + positionMint: Address; + liquidity: number | bigint; + tickLowerIndex: number; + tickUpperIndex: number; + feeGrowthCheckpointA: number | bigint; + feeOwedA: number | bigint; + feeGrowthCheckpointB: number | bigint; + feeOwedB: number | bigint; + rewardInfos: PositionRewardInfoArgs[]; +} + +export function getPositionEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["whirlpool", getAddressEncoder()], + ["positionMint", getAddressEncoder()], + ["liquidity", getU128Encoder()], + ["tickLowerIndex", getI32Encoder()], + ["tickUpperIndex", getI32Encoder()], + ["feeGrowthCheckpointA", getU128Encoder()], + ["feeOwedA", getU64Encoder()], + ["feeGrowthCheckpointB", getU128Encoder()], + ["feeOwedB", getU64Encoder()], + [ + "rewardInfos", + getArrayEncoder(getPositionRewardInfoEncoder(), { size: 3 }), + ], + ]), + (value) => ({ ...value, discriminator: POSITION_DISCRIMINATOR }), + ); +} + +export function getPositionDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["whirlpool", getAddressDecoder()], + ["positionMint", getAddressDecoder()], + ["liquidity", getU128Decoder()], + ["tickLowerIndex", getI32Decoder()], + ["tickUpperIndex", getI32Decoder()], + ["feeGrowthCheckpointA", getU128Decoder()], + ["feeOwedA", getU64Decoder()], + ["feeGrowthCheckpointB", getU128Decoder()], + ["feeOwedB", getU64Decoder()], + [ + "rewardInfos", + getArrayDecoder(getPositionRewardInfoDecoder(), { size: 3 }), + ], + ]); +} + +export function getPositionCodec(): FixedSizeCodec { + return combineCodec(getPositionEncoder(), getPositionDecoder()); +} + +export function decodePosition( + encodedAccount: EncodedAccount, +): Account; +export function decodePosition( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodePosition( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getPositionDecoder(), + ); +} + +export async function fetchPosition( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybePosition(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybePosition( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodePosition(maybeAccount); +} + +export async function fetchAllPosition( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybePosition(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybePosition( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodePosition(maybeAccount)); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/positionBundle.ts b/clients/orca-whirlpools/src/generated/accounts/positionBundle.ts new file mode 100644 index 00000000..4d3292a8 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/positionBundle.ts @@ -0,0 +1,150 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; + +export const POSITION_BUNDLE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [129, 169, 175, 65, 185, 95, 32, 100], +); + +export function getPositionBundleDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + POSITION_BUNDLE_DISCRIMINATOR, + ); +} + +export interface PositionBundle { + discriminator: ReadonlyUint8Array; + positionBundleMint: Address; + positionBitmap: number[]; +} + +export interface PositionBundleArgs { + positionBundleMint: Address; + positionBitmap: number[]; +} + +export function getPositionBundleEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["positionBundleMint", getAddressEncoder()], + ["positionBitmap", getArrayEncoder(getU8Encoder(), { size: 32 })], + ]), + (value) => ({ ...value, discriminator: POSITION_BUNDLE_DISCRIMINATOR }), + ); +} + +export function getPositionBundleDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["positionBundleMint", getAddressDecoder()], + ["positionBitmap", getArrayDecoder(getU8Decoder(), { size: 32 })], + ]); +} + +export function getPositionBundleCodec(): FixedSizeCodec< + PositionBundleArgs, + PositionBundle +> { + return combineCodec(getPositionBundleEncoder(), getPositionBundleDecoder()); +} + +export function decodePositionBundle( + encodedAccount: EncodedAccount, +): Account; +export function decodePositionBundle( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodePositionBundle( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getPositionBundleDecoder(), + ); +} + +export async function fetchPositionBundle( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybePositionBundle(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybePositionBundle< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodePositionBundle(maybeAccount); +} + +export async function fetchAllPositionBundle( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybePositionBundle( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybePositionBundle( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodePositionBundle(maybeAccount), + ); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/tickArray.ts b/clients/orca-whirlpools/src/generated/accounts/tickArray.ts new file mode 100644 index 00000000..38a77023 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/tickArray.ts @@ -0,0 +1,143 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import type { Tick, TickArgs } from "../types/index.js"; +import { getTickDecoder, getTickEncoder } from "../types/index.js"; + +export const TICK_ARRAY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 69, 97, 189, 190, 110, 7, 66, 187, +]); + +export function getTickArrayDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(TICK_ARRAY_DISCRIMINATOR); +} + +export interface TickArray { + discriminator: ReadonlyUint8Array; + startTickIndex: number; + ticks: Tick[]; + whirlpool: Address; +} + +export interface TickArrayArgs { + startTickIndex: number; + ticks: TickArgs[]; + whirlpool: Address; +} + +export function getTickArrayEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["startTickIndex", getI32Encoder()], + ["ticks", getArrayEncoder(getTickEncoder(), { size: 88 })], + ["whirlpool", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: TICK_ARRAY_DISCRIMINATOR }), + ); +} + +export function getTickArrayDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["startTickIndex", getI32Decoder()], + ["ticks", getArrayDecoder(getTickDecoder(), { size: 88 })], + ["whirlpool", getAddressDecoder()], + ]); +} + +export function getTickArrayCodec(): FixedSizeCodec { + return combineCodec(getTickArrayEncoder(), getTickArrayDecoder()); +} + +export function decodeTickArray( + encodedAccount: EncodedAccount, +): Account; +export function decodeTickArray( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeTickArray( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getTickArrayDecoder(), + ); +} + +export async function fetchTickArray( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeTickArray(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeTickArray( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeTickArray(maybeAccount); +} + +export async function fetchAllTickArray( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeTickArray(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeTickArray( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeTickArray(maybeAccount)); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/tokenBadge.ts b/clients/orca-whirlpools/src/generated/accounts/tokenBadge.ts new file mode 100644 index 00000000..02330c60 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/tokenBadge.ts @@ -0,0 +1,136 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; + +export const TOKEN_BADGE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 116, 219, 204, 229, 249, 116, 255, 150, +]); + +export function getTokenBadgeDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(TOKEN_BADGE_DISCRIMINATOR); +} + +export interface TokenBadge { + discriminator: ReadonlyUint8Array; + whirlpoolsConfig: Address; + tokenMint: Address; +} + +export interface TokenBadgeArgs { + whirlpoolsConfig: Address; + tokenMint: Address; +} + +export function getTokenBadgeEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["whirlpoolsConfig", getAddressEncoder()], + ["tokenMint", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: TOKEN_BADGE_DISCRIMINATOR }), + ); +} + +export function getTokenBadgeDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["whirlpoolsConfig", getAddressDecoder()], + ["tokenMint", getAddressDecoder()], + ]); +} + +export function getTokenBadgeCodec(): FixedSizeCodec< + TokenBadgeArgs, + TokenBadge +> { + return combineCodec(getTokenBadgeEncoder(), getTokenBadgeDecoder()); +} + +export function decodeTokenBadge( + encodedAccount: EncodedAccount, +): Account; +export function decodeTokenBadge( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeTokenBadge( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getTokenBadgeDecoder(), + ); +} + +export async function fetchTokenBadge( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeTokenBadge(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeTokenBadge( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeTokenBadge(maybeAccount); +} + +export async function fetchAllTokenBadge( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeTokenBadge(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeTokenBadge( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeTokenBadge(maybeAccount)); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/whirlpool.ts b/clients/orca-whirlpools/src/generated/accounts/whirlpool.ts new file mode 100644 index 00000000..93cc2c04 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/whirlpool.ts @@ -0,0 +1,227 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU16Decoder, + getU16Encoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import type { + WhirlpoolRewardInfo, + WhirlpoolRewardInfoArgs, +} from "../types/index.js"; +import { + getWhirlpoolRewardInfoDecoder, + getWhirlpoolRewardInfoEncoder, +} from "../types/index.js"; + +export const WHIRLPOOL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 63, 149, 209, 12, 225, 128, 99, 9, +]); + +export function getWhirlpoolDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(WHIRLPOOL_DISCRIMINATOR); +} + +export interface Whirlpool { + discriminator: ReadonlyUint8Array; + whirlpoolsConfig: Address; + whirlpoolBump: number[]; + tickSpacing: number; + tickSpacingSeed: number[]; + feeRate: number; + protocolFeeRate: number; + liquidity: bigint; + sqrtPrice: bigint; + tickCurrentIndex: number; + protocolFeeOwedA: bigint; + protocolFeeOwedB: bigint; + tokenMintA: Address; + tokenVaultA: Address; + feeGrowthGlobalA: bigint; + tokenMintB: Address; + tokenVaultB: Address; + feeGrowthGlobalB: bigint; + rewardLastUpdatedTimestamp: bigint; + rewardInfos: WhirlpoolRewardInfo[]; +} + +export interface WhirlpoolArgs { + whirlpoolsConfig: Address; + whirlpoolBump: number[]; + tickSpacing: number; + tickSpacingSeed: number[]; + feeRate: number; + protocolFeeRate: number; + liquidity: number | bigint; + sqrtPrice: number | bigint; + tickCurrentIndex: number; + protocolFeeOwedA: number | bigint; + protocolFeeOwedB: number | bigint; + tokenMintA: Address; + tokenVaultA: Address; + feeGrowthGlobalA: number | bigint; + tokenMintB: Address; + tokenVaultB: Address; + feeGrowthGlobalB: number | bigint; + rewardLastUpdatedTimestamp: number | bigint; + rewardInfos: WhirlpoolRewardInfoArgs[]; +} + +export function getWhirlpoolEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["whirlpoolsConfig", getAddressEncoder()], + ["whirlpoolBump", getArrayEncoder(getU8Encoder(), { size: 1 })], + ["tickSpacing", getU16Encoder()], + ["tickSpacingSeed", getArrayEncoder(getU8Encoder(), { size: 2 })], + ["feeRate", getU16Encoder()], + ["protocolFeeRate", getU16Encoder()], + ["liquidity", getU128Encoder()], + ["sqrtPrice", getU128Encoder()], + ["tickCurrentIndex", getI32Encoder()], + ["protocolFeeOwedA", getU64Encoder()], + ["protocolFeeOwedB", getU64Encoder()], + ["tokenMintA", getAddressEncoder()], + ["tokenVaultA", getAddressEncoder()], + ["feeGrowthGlobalA", getU128Encoder()], + ["tokenMintB", getAddressEncoder()], + ["tokenVaultB", getAddressEncoder()], + ["feeGrowthGlobalB", getU128Encoder()], + ["rewardLastUpdatedTimestamp", getU64Encoder()], + [ + "rewardInfos", + getArrayEncoder(getWhirlpoolRewardInfoEncoder(), { size: 3 }), + ], + ]), + (value) => ({ ...value, discriminator: WHIRLPOOL_DISCRIMINATOR }), + ); +} + +export function getWhirlpoolDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["whirlpoolsConfig", getAddressDecoder()], + ["whirlpoolBump", getArrayDecoder(getU8Decoder(), { size: 1 })], + ["tickSpacing", getU16Decoder()], + ["tickSpacingSeed", getArrayDecoder(getU8Decoder(), { size: 2 })], + ["feeRate", getU16Decoder()], + ["protocolFeeRate", getU16Decoder()], + ["liquidity", getU128Decoder()], + ["sqrtPrice", getU128Decoder()], + ["tickCurrentIndex", getI32Decoder()], + ["protocolFeeOwedA", getU64Decoder()], + ["protocolFeeOwedB", getU64Decoder()], + ["tokenMintA", getAddressDecoder()], + ["tokenVaultA", getAddressDecoder()], + ["feeGrowthGlobalA", getU128Decoder()], + ["tokenMintB", getAddressDecoder()], + ["tokenVaultB", getAddressDecoder()], + ["feeGrowthGlobalB", getU128Decoder()], + ["rewardLastUpdatedTimestamp", getU64Decoder()], + [ + "rewardInfos", + getArrayDecoder(getWhirlpoolRewardInfoDecoder(), { size: 3 }), + ], + ]); +} + +export function getWhirlpoolCodec(): FixedSizeCodec { + return combineCodec(getWhirlpoolEncoder(), getWhirlpoolDecoder()); +} + +export function decodeWhirlpool( + encodedAccount: EncodedAccount, +): Account; +export function decodeWhirlpool( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeWhirlpool( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getWhirlpoolDecoder(), + ); +} + +export async function fetchWhirlpool( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeWhirlpool(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeWhirlpool( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeWhirlpool(maybeAccount); +} + +export async function fetchAllWhirlpool( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeWhirlpool(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeWhirlpool( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeWhirlpool(maybeAccount)); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/whirlpoolsConfig.ts b/clients/orca-whirlpools/src/generated/accounts/whirlpoolsConfig.ts new file mode 100644 index 00000000..fe3134ff --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/whirlpoolsConfig.ts @@ -0,0 +1,160 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; + +export const WHIRLPOOLS_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([157, 20, 49, 224, 217, 87, 193, 254]); + +export function getWhirlpoolsConfigDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + WHIRLPOOLS_CONFIG_DISCRIMINATOR, + ); +} + +export interface WhirlpoolsConfig { + discriminator: ReadonlyUint8Array; + feeAuthority: Address; + collectProtocolFeesAuthority: Address; + rewardEmissionsSuperAuthority: Address; + defaultProtocolFeeRate: number; +} + +export interface WhirlpoolsConfigArgs { + feeAuthority: Address; + collectProtocolFeesAuthority: Address; + rewardEmissionsSuperAuthority: Address; + defaultProtocolFeeRate: number; +} + +export function getWhirlpoolsConfigEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["feeAuthority", getAddressEncoder()], + ["collectProtocolFeesAuthority", getAddressEncoder()], + ["rewardEmissionsSuperAuthority", getAddressEncoder()], + ["defaultProtocolFeeRate", getU16Encoder()], + ]), + (value) => ({ ...value, discriminator: WHIRLPOOLS_CONFIG_DISCRIMINATOR }), + ); +} + +export function getWhirlpoolsConfigDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["feeAuthority", getAddressDecoder()], + ["collectProtocolFeesAuthority", getAddressDecoder()], + ["rewardEmissionsSuperAuthority", getAddressDecoder()], + ["defaultProtocolFeeRate", getU16Decoder()], + ]); +} + +export function getWhirlpoolsConfigCodec(): FixedSizeCodec< + WhirlpoolsConfigArgs, + WhirlpoolsConfig +> { + return combineCodec( + getWhirlpoolsConfigEncoder(), + getWhirlpoolsConfigDecoder(), + ); +} + +export function decodeWhirlpoolsConfig( + encodedAccount: EncodedAccount, +): Account; +export function decodeWhirlpoolsConfig( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeWhirlpoolsConfig( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getWhirlpoolsConfigDecoder(), + ); +} + +export async function fetchWhirlpoolsConfig( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeWhirlpoolsConfig(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeWhirlpoolsConfig< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeWhirlpoolsConfig(maybeAccount); +} + +export async function fetchAllWhirlpoolsConfig( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeWhirlpoolsConfig( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeWhirlpoolsConfig( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeWhirlpoolsConfig(maybeAccount), + ); +} diff --git a/clients/orca-whirlpools/src/generated/accounts/whirlpoolsConfigExtension.ts b/clients/orca-whirlpools/src/generated/accounts/whirlpoolsConfigExtension.ts new file mode 100644 index 00000000..211402d2 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/accounts/whirlpoolsConfigExtension.ts @@ -0,0 +1,169 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; + +export const WHIRLPOOLS_CONFIG_EXTENSION_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([2, 99, 215, 163, 240, 26, 153, 58]); + +export function getWhirlpoolsConfigExtensionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + WHIRLPOOLS_CONFIG_EXTENSION_DISCRIMINATOR, + ); +} + +export interface WhirlpoolsConfigExtension { + discriminator: ReadonlyUint8Array; + whirlpoolsConfig: Address; + configExtensionAuthority: Address; + tokenBadgeAuthority: Address; +} + +export interface WhirlpoolsConfigExtensionArgs { + whirlpoolsConfig: Address; + configExtensionAuthority: Address; + tokenBadgeAuthority: Address; +} + +export function getWhirlpoolsConfigExtensionEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["whirlpoolsConfig", getAddressEncoder()], + ["configExtensionAuthority", getAddressEncoder()], + ["tokenBadgeAuthority", getAddressEncoder()], + ]), + (value) => ({ + ...value, + discriminator: WHIRLPOOLS_CONFIG_EXTENSION_DISCRIMINATOR, + }), + ); +} + +export function getWhirlpoolsConfigExtensionDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["whirlpoolsConfig", getAddressDecoder()], + ["configExtensionAuthority", getAddressDecoder()], + ["tokenBadgeAuthority", getAddressDecoder()], + ]); +} + +export function getWhirlpoolsConfigExtensionCodec(): FixedSizeCodec< + WhirlpoolsConfigExtensionArgs, + WhirlpoolsConfigExtension +> { + return combineCodec( + getWhirlpoolsConfigExtensionEncoder(), + getWhirlpoolsConfigExtensionDecoder(), + ); +} + +export function decodeWhirlpoolsConfigExtension< + TAddress extends string = string, +>( + encodedAccount: EncodedAccount, +): Account; +export function decodeWhirlpoolsConfigExtension< + TAddress extends string = string, +>( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeWhirlpoolsConfigExtension< + TAddress extends string = string, +>( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getWhirlpoolsConfigExtensionDecoder(), + ); +} + +export async function fetchWhirlpoolsConfigExtension< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeWhirlpoolsConfigExtension( + rpc, + address, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeWhirlpoolsConfigExtension< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeWhirlpoolsConfigExtension(maybeAccount); +} + +export async function fetchAllWhirlpoolsConfigExtension( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeWhirlpoolsConfigExtension( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeWhirlpoolsConfigExtension( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeWhirlpoolsConfigExtension(maybeAccount), + ); +} diff --git a/clients/orca-whirlpools/src/generated/errors/index.ts b/clients/orca-whirlpools/src/generated/errors/index.ts new file mode 100644 index 00000000..b7ceb61b --- /dev/null +++ b/clients/orca-whirlpools/src/generated/errors/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./whirlpool.js"; diff --git a/clients/orca-whirlpools/src/generated/errors/whirlpool.ts b/clients/orca-whirlpools/src/generated/errors/whirlpool.ts new file mode 100644 index 00000000..6fbff18f --- /dev/null +++ b/clients/orca-whirlpools/src/generated/errors/whirlpool.ts @@ -0,0 +1,323 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + SolanaError, +} from "@solana/kit"; +import { isProgramError } from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; + +/** InvalidEnum: Enum value could not be converted */ +export const WHIRLPOOL_ERROR__INVALID_ENUM = 0x1770; // 6000 +/** InvalidStartTick: Invalid start tick index provided. */ +export const WHIRLPOOL_ERROR__INVALID_START_TICK = 0x1771; // 6001 +/** TickArrayExistInPool: Tick-array already exists in this whirlpool */ +export const WHIRLPOOL_ERROR__TICK_ARRAY_EXIST_IN_POOL = 0x1772; // 6002 +/** TickArrayIndexOutofBounds: Attempt to search for a tick-array failed */ +export const WHIRLPOOL_ERROR__TICK_ARRAY_INDEX_OUTOF_BOUNDS = 0x1773; // 6003 +/** InvalidTickSpacing: Tick-spacing is not supported */ +export const WHIRLPOOL_ERROR__INVALID_TICK_SPACING = 0x1774; // 6004 +/** ClosePositionNotEmpty: Position is not empty It cannot be closed */ +export const WHIRLPOOL_ERROR__CLOSE_POSITION_NOT_EMPTY = 0x1775; // 6005 +/** DivideByZero: Unable to divide by zero */ +export const WHIRLPOOL_ERROR__DIVIDE_BY_ZERO = 0x1776; // 6006 +/** NumberCastError: Unable to cast number into BigInt */ +export const WHIRLPOOL_ERROR__NUMBER_CAST_ERROR = 0x1777; // 6007 +/** NumberDownCastError: Unable to down cast number */ +export const WHIRLPOOL_ERROR__NUMBER_DOWN_CAST_ERROR = 0x1778; // 6008 +/** TickNotFound: Tick not found within tick array */ +export const WHIRLPOOL_ERROR__TICK_NOT_FOUND = 0x1779; // 6009 +/** InvalidTickIndex: Provided tick index is either out of bounds or uninitializable */ +export const WHIRLPOOL_ERROR__INVALID_TICK_INDEX = 0x177a; // 6010 +/** SqrtPriceOutOfBounds: Provided sqrt price out of bounds */ +export const WHIRLPOOL_ERROR__SQRT_PRICE_OUT_OF_BOUNDS = 0x177b; // 6011 +/** LiquidityZero: Liquidity amount must be greater than zero */ +export const WHIRLPOOL_ERROR__LIQUIDITY_ZERO = 0x177c; // 6012 +/** LiquidityTooHigh: Liquidity amount must be less than i64::MAX */ +export const WHIRLPOOL_ERROR__LIQUIDITY_TOO_HIGH = 0x177d; // 6013 +/** LiquidityOverflow: Liquidity overflow */ +export const WHIRLPOOL_ERROR__LIQUIDITY_OVERFLOW = 0x177e; // 6014 +/** LiquidityUnderflow: Liquidity underflow */ +export const WHIRLPOOL_ERROR__LIQUIDITY_UNDERFLOW = 0x177f; // 6015 +/** LiquidityNetError: Tick liquidity net underflowed or overflowed */ +export const WHIRLPOOL_ERROR__LIQUIDITY_NET_ERROR = 0x1780; // 6016 +/** TokenMaxExceeded: Exceeded token max */ +export const WHIRLPOOL_ERROR__TOKEN_MAX_EXCEEDED = 0x1781; // 6017 +/** TokenMinSubceeded: Did not meet token min */ +export const WHIRLPOOL_ERROR__TOKEN_MIN_SUBCEEDED = 0x1782; // 6018 +/** MissingOrInvalidDelegate: Position token account has a missing or invalid delegate */ +export const WHIRLPOOL_ERROR__MISSING_OR_INVALID_DELEGATE = 0x1783; // 6019 +/** InvalidPositionTokenAmount: Position token amount must be 1 */ +export const WHIRLPOOL_ERROR__INVALID_POSITION_TOKEN_AMOUNT = 0x1784; // 6020 +/** InvalidTimestampConversion: Timestamp should be convertible from i64 to u64 */ +export const WHIRLPOOL_ERROR__INVALID_TIMESTAMP_CONVERSION = 0x1785; // 6021 +/** InvalidTimestamp: Timestamp should be greater than the last updated timestamp */ +export const WHIRLPOOL_ERROR__INVALID_TIMESTAMP = 0x1786; // 6022 +/** InvalidTickArraySequence: Invalid tick array sequence provided for instruction. */ +export const WHIRLPOOL_ERROR__INVALID_TICK_ARRAY_SEQUENCE = 0x1787; // 6023 +/** InvalidTokenMintOrder: Token Mint in wrong order */ +export const WHIRLPOOL_ERROR__INVALID_TOKEN_MINT_ORDER = 0x1788; // 6024 +/** RewardNotInitialized: Reward not initialized */ +export const WHIRLPOOL_ERROR__REWARD_NOT_INITIALIZED = 0x1789; // 6025 +/** InvalidRewardIndex: Invalid reward index */ +export const WHIRLPOOL_ERROR__INVALID_REWARD_INDEX = 0x178a; // 6026 +/** RewardVaultAmountInsufficient: Reward vault requires amount to support emissions for at least one day */ +export const WHIRLPOOL_ERROR__REWARD_VAULT_AMOUNT_INSUFFICIENT = 0x178b; // 6027 +/** FeeRateMaxExceeded: Exceeded max fee rate */ +export const WHIRLPOOL_ERROR__FEE_RATE_MAX_EXCEEDED = 0x178c; // 6028 +/** ProtocolFeeRateMaxExceeded: Exceeded max protocol fee rate */ +export const WHIRLPOOL_ERROR__PROTOCOL_FEE_RATE_MAX_EXCEEDED = 0x178d; // 6029 +/** MultiplicationShiftRightOverflow: Multiplication with shift right overflow */ +export const WHIRLPOOL_ERROR__MULTIPLICATION_SHIFT_RIGHT_OVERFLOW = 0x178e; // 6030 +/** MulDivOverflow: Muldiv overflow */ +export const WHIRLPOOL_ERROR__MUL_DIV_OVERFLOW = 0x178f; // 6031 +/** MulDivInvalidInput: Invalid div_u256 input */ +export const WHIRLPOOL_ERROR__MUL_DIV_INVALID_INPUT = 0x1790; // 6032 +/** MultiplicationOverflow: Multiplication overflow */ +export const WHIRLPOOL_ERROR__MULTIPLICATION_OVERFLOW = 0x1791; // 6033 +/** InvalidSqrtPriceLimitDirection: Provided SqrtPriceLimit not in the same direction as the swap. */ +export const WHIRLPOOL_ERROR__INVALID_SQRT_PRICE_LIMIT_DIRECTION = 0x1792; // 6034 +/** ZeroTradableAmount: There are no tradable amount to swap. */ +export const WHIRLPOOL_ERROR__ZERO_TRADABLE_AMOUNT = 0x1793; // 6035 +/** AmountOutBelowMinimum: Amount out below minimum threshold */ +export const WHIRLPOOL_ERROR__AMOUNT_OUT_BELOW_MINIMUM = 0x1794; // 6036 +/** AmountInAboveMaximum: Amount in above maximum threshold */ +export const WHIRLPOOL_ERROR__AMOUNT_IN_ABOVE_MAXIMUM = 0x1795; // 6037 +/** TickArraySequenceInvalidIndex: Invalid index for tick array sequence */ +export const WHIRLPOOL_ERROR__TICK_ARRAY_SEQUENCE_INVALID_INDEX = 0x1796; // 6038 +/** AmountCalcOverflow: Amount calculated overflows */ +export const WHIRLPOOL_ERROR__AMOUNT_CALC_OVERFLOW = 0x1797; // 6039 +/** AmountRemainingOverflow: Amount remaining overflows */ +export const WHIRLPOOL_ERROR__AMOUNT_REMAINING_OVERFLOW = 0x1798; // 6040 +/** InvalidIntermediaryMint: Invalid intermediary mint */ +export const WHIRLPOOL_ERROR__INVALID_INTERMEDIARY_MINT = 0x1799; // 6041 +/** DuplicateTwoHopPool: Duplicate two hop pool */ +export const WHIRLPOOL_ERROR__DUPLICATE_TWO_HOP_POOL = 0x179a; // 6042 +/** InvalidBundleIndex: Bundle index is out of bounds */ +export const WHIRLPOOL_ERROR__INVALID_BUNDLE_INDEX = 0x179b; // 6043 +/** BundledPositionAlreadyOpened: Position has already been opened */ +export const WHIRLPOOL_ERROR__BUNDLED_POSITION_ALREADY_OPENED = 0x179c; // 6044 +/** BundledPositionAlreadyClosed: Position has already been closed */ +export const WHIRLPOOL_ERROR__BUNDLED_POSITION_ALREADY_CLOSED = 0x179d; // 6045 +/** PositionBundleNotDeletable: Unable to delete PositionBundle with open positions */ +export const WHIRLPOOL_ERROR__POSITION_BUNDLE_NOT_DELETABLE = 0x179e; // 6046 +/** UnsupportedTokenMint: Token mint has unsupported attributes */ +export const WHIRLPOOL_ERROR__UNSUPPORTED_TOKEN_MINT = 0x179f; // 6047 +/** RemainingAccountsInvalidSlice: Invalid remaining accounts */ +export const WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_INVALID_SLICE = 0x17a0; // 6048 +/** RemainingAccountsInsufficient: Insufficient remaining accounts */ +export const WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT = 0x17a1; // 6049 +/** NoExtraAccountsForTransferHook: Unable to call transfer hook without extra accounts */ +export const WHIRLPOOL_ERROR__NO_EXTRA_ACCOUNTS_FOR_TRANSFER_HOOK = 0x17a2; // 6050 +/** IntermediateTokenAmountMismatch: Output and input amount mismatch */ +export const WHIRLPOOL_ERROR__INTERMEDIATE_TOKEN_AMOUNT_MISMATCH = 0x17a3; // 6051 +/** TransferFeeCalculationError: Transfer fee calculation failed */ +export const WHIRLPOOL_ERROR__TRANSFER_FEE_CALCULATION_ERROR = 0x17a4; // 6052 +/** RemainingAccountsDuplicatedAccountsType: Same accounts type is provided more than once */ +export const WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE = 0x17a5; // 6053 +/** FullRangeOnlyPool: This whirlpool only supports full-range positions */ +export const WHIRLPOOL_ERROR__FULL_RANGE_ONLY_POOL = 0x17a6; // 6054 +/** TooManySupplementalTickArrays: Too many supplemental tick arrays provided */ +export const WHIRLPOOL_ERROR__TOO_MANY_SUPPLEMENTAL_TICK_ARRAYS = 0x17a7; // 6055 +/** DifferentWhirlpoolTickArrayAccount: TickArray account for different whirlpool provided */ +export const WHIRLPOOL_ERROR__DIFFERENT_WHIRLPOOL_TICK_ARRAY_ACCOUNT = 0x17a8; // 6056 +/** PartialFillError: Trade resulted in partial fill */ +export const WHIRLPOOL_ERROR__PARTIAL_FILL_ERROR = 0x17a9; // 6057 +/** PositionNotLockable: Position is not lockable */ +export const WHIRLPOOL_ERROR__POSITION_NOT_LOCKABLE = 0x17aa; // 6058 +/** OperationNotAllowedOnLockedPosition: Operation not allowed on locked position */ +export const WHIRLPOOL_ERROR__OPERATION_NOT_ALLOWED_ON_LOCKED_POSITION = 0x17ab; // 6059 + +export type WhirlpoolError = + | typeof WHIRLPOOL_ERROR__AMOUNT_CALC_OVERFLOW + | typeof WHIRLPOOL_ERROR__AMOUNT_IN_ABOVE_MAXIMUM + | typeof WHIRLPOOL_ERROR__AMOUNT_OUT_BELOW_MINIMUM + | typeof WHIRLPOOL_ERROR__AMOUNT_REMAINING_OVERFLOW + | typeof WHIRLPOOL_ERROR__BUNDLED_POSITION_ALREADY_CLOSED + | typeof WHIRLPOOL_ERROR__BUNDLED_POSITION_ALREADY_OPENED + | typeof WHIRLPOOL_ERROR__CLOSE_POSITION_NOT_EMPTY + | typeof WHIRLPOOL_ERROR__DIFFERENT_WHIRLPOOL_TICK_ARRAY_ACCOUNT + | typeof WHIRLPOOL_ERROR__DIVIDE_BY_ZERO + | typeof WHIRLPOOL_ERROR__DUPLICATE_TWO_HOP_POOL + | typeof WHIRLPOOL_ERROR__FEE_RATE_MAX_EXCEEDED + | typeof WHIRLPOOL_ERROR__FULL_RANGE_ONLY_POOL + | typeof WHIRLPOOL_ERROR__INTERMEDIATE_TOKEN_AMOUNT_MISMATCH + | typeof WHIRLPOOL_ERROR__INVALID_BUNDLE_INDEX + | typeof WHIRLPOOL_ERROR__INVALID_ENUM + | typeof WHIRLPOOL_ERROR__INVALID_INTERMEDIARY_MINT + | typeof WHIRLPOOL_ERROR__INVALID_POSITION_TOKEN_AMOUNT + | typeof WHIRLPOOL_ERROR__INVALID_REWARD_INDEX + | typeof WHIRLPOOL_ERROR__INVALID_SQRT_PRICE_LIMIT_DIRECTION + | typeof WHIRLPOOL_ERROR__INVALID_START_TICK + | typeof WHIRLPOOL_ERROR__INVALID_TICK_ARRAY_SEQUENCE + | typeof WHIRLPOOL_ERROR__INVALID_TICK_INDEX + | typeof WHIRLPOOL_ERROR__INVALID_TICK_SPACING + | typeof WHIRLPOOL_ERROR__INVALID_TIMESTAMP + | typeof WHIRLPOOL_ERROR__INVALID_TIMESTAMP_CONVERSION + | typeof WHIRLPOOL_ERROR__INVALID_TOKEN_MINT_ORDER + | typeof WHIRLPOOL_ERROR__LIQUIDITY_NET_ERROR + | typeof WHIRLPOOL_ERROR__LIQUIDITY_OVERFLOW + | typeof WHIRLPOOL_ERROR__LIQUIDITY_TOO_HIGH + | typeof WHIRLPOOL_ERROR__LIQUIDITY_UNDERFLOW + | typeof WHIRLPOOL_ERROR__LIQUIDITY_ZERO + | typeof WHIRLPOOL_ERROR__MISSING_OR_INVALID_DELEGATE + | typeof WHIRLPOOL_ERROR__MUL_DIV_INVALID_INPUT + | typeof WHIRLPOOL_ERROR__MUL_DIV_OVERFLOW + | typeof WHIRLPOOL_ERROR__MULTIPLICATION_OVERFLOW + | typeof WHIRLPOOL_ERROR__MULTIPLICATION_SHIFT_RIGHT_OVERFLOW + | typeof WHIRLPOOL_ERROR__NO_EXTRA_ACCOUNTS_FOR_TRANSFER_HOOK + | typeof WHIRLPOOL_ERROR__NUMBER_CAST_ERROR + | typeof WHIRLPOOL_ERROR__NUMBER_DOWN_CAST_ERROR + | typeof WHIRLPOOL_ERROR__OPERATION_NOT_ALLOWED_ON_LOCKED_POSITION + | typeof WHIRLPOOL_ERROR__PARTIAL_FILL_ERROR + | typeof WHIRLPOOL_ERROR__POSITION_BUNDLE_NOT_DELETABLE + | typeof WHIRLPOOL_ERROR__POSITION_NOT_LOCKABLE + | typeof WHIRLPOOL_ERROR__PROTOCOL_FEE_RATE_MAX_EXCEEDED + | typeof WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE + | typeof WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT + | typeof WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_INVALID_SLICE + | typeof WHIRLPOOL_ERROR__REWARD_NOT_INITIALIZED + | typeof WHIRLPOOL_ERROR__REWARD_VAULT_AMOUNT_INSUFFICIENT + | typeof WHIRLPOOL_ERROR__SQRT_PRICE_OUT_OF_BOUNDS + | typeof WHIRLPOOL_ERROR__TICK_ARRAY_EXIST_IN_POOL + | typeof WHIRLPOOL_ERROR__TICK_ARRAY_INDEX_OUTOF_BOUNDS + | typeof WHIRLPOOL_ERROR__TICK_ARRAY_SEQUENCE_INVALID_INDEX + | typeof WHIRLPOOL_ERROR__TICK_NOT_FOUND + | typeof WHIRLPOOL_ERROR__TOKEN_MAX_EXCEEDED + | typeof WHIRLPOOL_ERROR__TOKEN_MIN_SUBCEEDED + | typeof WHIRLPOOL_ERROR__TOO_MANY_SUPPLEMENTAL_TICK_ARRAYS + | typeof WHIRLPOOL_ERROR__TRANSFER_FEE_CALCULATION_ERROR + | typeof WHIRLPOOL_ERROR__UNSUPPORTED_TOKEN_MINT + | typeof WHIRLPOOL_ERROR__ZERO_TRADABLE_AMOUNT; + +let whirlpoolErrorMessages: Record | undefined; +if (true) { + whirlpoolErrorMessages = { + [WHIRLPOOL_ERROR__AMOUNT_CALC_OVERFLOW]: "Amount calculated overflows", + [WHIRLPOOL_ERROR__AMOUNT_IN_ABOVE_MAXIMUM]: + "Amount in above maximum threshold", + [WHIRLPOOL_ERROR__AMOUNT_OUT_BELOW_MINIMUM]: + "Amount out below minimum threshold", + [WHIRLPOOL_ERROR__AMOUNT_REMAINING_OVERFLOW]: "Amount remaining overflows", + [WHIRLPOOL_ERROR__BUNDLED_POSITION_ALREADY_CLOSED]: + "Position has already been closed", + [WHIRLPOOL_ERROR__BUNDLED_POSITION_ALREADY_OPENED]: + "Position has already been opened", + [WHIRLPOOL_ERROR__CLOSE_POSITION_NOT_EMPTY]: + "Position is not empty It cannot be closed", + [WHIRLPOOL_ERROR__DIFFERENT_WHIRLPOOL_TICK_ARRAY_ACCOUNT]: + "TickArray account for different whirlpool provided", + [WHIRLPOOL_ERROR__DIVIDE_BY_ZERO]: "Unable to divide by zero", + [WHIRLPOOL_ERROR__DUPLICATE_TWO_HOP_POOL]: "Duplicate two hop pool", + [WHIRLPOOL_ERROR__FEE_RATE_MAX_EXCEEDED]: "Exceeded max fee rate", + [WHIRLPOOL_ERROR__FULL_RANGE_ONLY_POOL]: + "This whirlpool only supports full-range positions", + [WHIRLPOOL_ERROR__INTERMEDIATE_TOKEN_AMOUNT_MISMATCH]: + "Output and input amount mismatch", + [WHIRLPOOL_ERROR__INVALID_BUNDLE_INDEX]: "Bundle index is out of bounds", + [WHIRLPOOL_ERROR__INVALID_ENUM]: "Enum value could not be converted", + [WHIRLPOOL_ERROR__INVALID_INTERMEDIARY_MINT]: "Invalid intermediary mint", + [WHIRLPOOL_ERROR__INVALID_POSITION_TOKEN_AMOUNT]: + "Position token amount must be 1", + [WHIRLPOOL_ERROR__INVALID_REWARD_INDEX]: "Invalid reward index", + [WHIRLPOOL_ERROR__INVALID_SQRT_PRICE_LIMIT_DIRECTION]: + "Provided SqrtPriceLimit not in the same direction as the swap.", + [WHIRLPOOL_ERROR__INVALID_START_TICK]: "Invalid start tick index provided.", + [WHIRLPOOL_ERROR__INVALID_TICK_ARRAY_SEQUENCE]: + "Invalid tick array sequence provided for instruction.", + [WHIRLPOOL_ERROR__INVALID_TICK_INDEX]: + "Provided tick index is either out of bounds or uninitializable", + [WHIRLPOOL_ERROR__INVALID_TICK_SPACING]: "Tick-spacing is not supported", + [WHIRLPOOL_ERROR__INVALID_TIMESTAMP]: + "Timestamp should be greater than the last updated timestamp", + [WHIRLPOOL_ERROR__INVALID_TIMESTAMP_CONVERSION]: + "Timestamp should be convertible from i64 to u64", + [WHIRLPOOL_ERROR__INVALID_TOKEN_MINT_ORDER]: "Token Mint in wrong order", + [WHIRLPOOL_ERROR__LIQUIDITY_NET_ERROR]: + "Tick liquidity net underflowed or overflowed", + [WHIRLPOOL_ERROR__LIQUIDITY_OVERFLOW]: "Liquidity overflow", + [WHIRLPOOL_ERROR__LIQUIDITY_TOO_HIGH]: + "Liquidity amount must be less than i64::MAX", + [WHIRLPOOL_ERROR__LIQUIDITY_UNDERFLOW]: "Liquidity underflow", + [WHIRLPOOL_ERROR__LIQUIDITY_ZERO]: + "Liquidity amount must be greater than zero", + [WHIRLPOOL_ERROR__MISSING_OR_INVALID_DELEGATE]: + "Position token account has a missing or invalid delegate", + [WHIRLPOOL_ERROR__MUL_DIV_INVALID_INPUT]: "Invalid div_u256 input", + [WHIRLPOOL_ERROR__MUL_DIV_OVERFLOW]: "Muldiv overflow", + [WHIRLPOOL_ERROR__MULTIPLICATION_OVERFLOW]: "Multiplication overflow", + [WHIRLPOOL_ERROR__MULTIPLICATION_SHIFT_RIGHT_OVERFLOW]: + "Multiplication with shift right overflow", + [WHIRLPOOL_ERROR__NO_EXTRA_ACCOUNTS_FOR_TRANSFER_HOOK]: + "Unable to call transfer hook without extra accounts", + [WHIRLPOOL_ERROR__NUMBER_CAST_ERROR]: "Unable to cast number into BigInt", + [WHIRLPOOL_ERROR__NUMBER_DOWN_CAST_ERROR]: "Unable to down cast number", + [WHIRLPOOL_ERROR__OPERATION_NOT_ALLOWED_ON_LOCKED_POSITION]: + "Operation not allowed on locked position", + [WHIRLPOOL_ERROR__PARTIAL_FILL_ERROR]: "Trade resulted in partial fill", + [WHIRLPOOL_ERROR__POSITION_BUNDLE_NOT_DELETABLE]: + "Unable to delete PositionBundle with open positions", + [WHIRLPOOL_ERROR__POSITION_NOT_LOCKABLE]: "Position is not lockable", + [WHIRLPOOL_ERROR__PROTOCOL_FEE_RATE_MAX_EXCEEDED]: + "Exceeded max protocol fee rate", + [WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_DUPLICATED_ACCOUNTS_TYPE]: + "Same accounts type is provided more than once", + [WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_INSUFFICIENT]: + "Insufficient remaining accounts", + [WHIRLPOOL_ERROR__REMAINING_ACCOUNTS_INVALID_SLICE]: + "Invalid remaining accounts", + [WHIRLPOOL_ERROR__REWARD_NOT_INITIALIZED]: "Reward not initialized", + [WHIRLPOOL_ERROR__REWARD_VAULT_AMOUNT_INSUFFICIENT]: + "Reward vault requires amount to support emissions for at least one day", + [WHIRLPOOL_ERROR__SQRT_PRICE_OUT_OF_BOUNDS]: + "Provided sqrt price out of bounds", + [WHIRLPOOL_ERROR__TICK_ARRAY_EXIST_IN_POOL]: + "Tick-array already exists in this whirlpool", + [WHIRLPOOL_ERROR__TICK_ARRAY_INDEX_OUTOF_BOUNDS]: + "Attempt to search for a tick-array failed", + [WHIRLPOOL_ERROR__TICK_ARRAY_SEQUENCE_INVALID_INDEX]: + "Invalid index for tick array sequence", + [WHIRLPOOL_ERROR__TICK_NOT_FOUND]: "Tick not found within tick array", + [WHIRLPOOL_ERROR__TOKEN_MAX_EXCEEDED]: "Exceeded token max", + [WHIRLPOOL_ERROR__TOKEN_MIN_SUBCEEDED]: "Did not meet token min", + [WHIRLPOOL_ERROR__TOO_MANY_SUPPLEMENTAL_TICK_ARRAYS]: + "Too many supplemental tick arrays provided", + [WHIRLPOOL_ERROR__TRANSFER_FEE_CALCULATION_ERROR]: + "Transfer fee calculation failed", + [WHIRLPOOL_ERROR__UNSUPPORTED_TOKEN_MINT]: + "Token mint has unsupported attributes", + [WHIRLPOOL_ERROR__ZERO_TRADABLE_AMOUNT]: + "There are no tradable amount to swap.", + }; +} + +export function getWhirlpoolErrorMessage(code: WhirlpoolError): string { + if (true) { + return whirlpoolErrorMessages![code]; + } + + return "Error message not available in production bundles."; +} + +export function isWhirlpoolError( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode, +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + WHIRLPOOL_PROGRAM_ADDRESS, + code, + ); +} diff --git a/clients/orca-whirlpools/src/generated/index.ts b/clients/orca-whirlpools/src/generated/index.ts new file mode 100644 index 00000000..57d7322d --- /dev/null +++ b/clients/orca-whirlpools/src/generated/index.ts @@ -0,0 +1,13 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./accounts/index.js"; +export * from "./errors/index.js"; +export * from "./instructions/index.js"; +export * from "./programs/index.js"; +export * from "./types/index.js"; diff --git a/clients/orca-whirlpools/src/generated/instructions/closeBundledPosition.ts b/clients/orca-whirlpools/src/generated/instructions/closeBundledPosition.ts new file mode 100644 index 00000000..18fec2f5 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/closeBundledPosition.ts @@ -0,0 +1,256 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CLOSE_BUNDLED_POSITION_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([41, 36, 216, 245, 27, 85, 103, 67]); + +export function getCloseBundledPositionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CLOSE_BUNDLED_POSITION_DISCRIMINATOR, + ); +} + +export type CloseBundledPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountBundledPosition extends string | AccountMeta = string, + TAccountPositionBundle extends string | AccountMeta = string, + TAccountPositionBundleTokenAccount extends string | AccountMeta = string, + TAccountPositionBundleAuthority extends string | AccountMeta = string, + TAccountReceiver extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBundledPosition extends string + ? WritableAccount + : TAccountBundledPosition, + TAccountPositionBundle extends string + ? WritableAccount + : TAccountPositionBundle, + TAccountPositionBundleTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionBundleAuthority, + TAccountReceiver extends string + ? WritableAccount + : TAccountReceiver, + ...TRemainingAccounts, + ] + >; + +export interface CloseBundledPositionInstructionData { + discriminator: ReadonlyUint8Array; + bundleIndex: number; +} + +export interface CloseBundledPositionInstructionDataArgs { + bundleIndex: number; +} + +export function getCloseBundledPositionInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bundleIndex", getU16Encoder()], + ]), + (value) => ({ + ...value, + discriminator: CLOSE_BUNDLED_POSITION_DISCRIMINATOR, + }), + ); +} + +export function getCloseBundledPositionInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bundleIndex", getU16Decoder()], + ]); +} + +export function getCloseBundledPositionInstructionDataCodec(): FixedSizeCodec< + CloseBundledPositionInstructionDataArgs, + CloseBundledPositionInstructionData +> { + return combineCodec( + getCloseBundledPositionInstructionDataEncoder(), + getCloseBundledPositionInstructionDataDecoder(), + ); +} + +export interface CloseBundledPositionInput< + TAccountBundledPosition extends string = string, + TAccountPositionBundle extends string = string, + TAccountPositionBundleTokenAccount extends string = string, + TAccountPositionBundleAuthority extends string = string, + TAccountReceiver extends string = string, +> { + bundledPosition: Address; + positionBundle: Address; + positionBundleTokenAccount: Address; + positionBundleAuthority: TransactionSigner; + receiver: Address; + bundleIndex: CloseBundledPositionInstructionDataArgs["bundleIndex"]; +} + +export function getCloseBundledPositionInstruction< + TAccountBundledPosition extends string, + TAccountPositionBundle extends string, + TAccountPositionBundleTokenAccount extends string, + TAccountPositionBundleAuthority extends string, + TAccountReceiver extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CloseBundledPositionInput< + TAccountBundledPosition, + TAccountPositionBundle, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority, + TAccountReceiver + >, + config?: { programAddress?: TProgramAddress }, +): CloseBundledPositionInstruction< + TProgramAddress, + TAccountBundledPosition, + TAccountPositionBundle, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority, + TAccountReceiver +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + bundledPosition: { value: input.bundledPosition ?? null, isWritable: true }, + positionBundle: { value: input.positionBundle ?? null, isWritable: true }, + positionBundleTokenAccount: { + value: input.positionBundleTokenAccount ?? null, + isWritable: false, + }, + positionBundleAuthority: { + value: input.positionBundleAuthority ?? null, + isWritable: false, + }, + receiver: { value: input.receiver ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.bundledPosition), + getAccountMeta(accounts.positionBundle), + getAccountMeta(accounts.positionBundleTokenAccount), + getAccountMeta(accounts.positionBundleAuthority), + getAccountMeta(accounts.receiver), + ], + programAddress, + data: getCloseBundledPositionInstructionDataEncoder().encode( + args as CloseBundledPositionInstructionDataArgs, + ), + } as CloseBundledPositionInstruction< + TProgramAddress, + TAccountBundledPosition, + TAccountPositionBundle, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority, + TAccountReceiver + >; + + return instruction; +} + +export interface ParsedCloseBundledPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + bundledPosition: TAccountMetas[0]; + positionBundle: TAccountMetas[1]; + positionBundleTokenAccount: TAccountMetas[2]; + positionBundleAuthority: TAccountMetas[3]; + receiver: TAccountMetas[4]; + }; + data: CloseBundledPositionInstructionData; +} + +export function parseCloseBundledPositionInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCloseBundledPositionInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + bundledPosition: getNextAccount(), + positionBundle: getNextAccount(), + positionBundleTokenAccount: getNextAccount(), + positionBundleAuthority: getNextAccount(), + receiver: getNextAccount(), + }, + data: getCloseBundledPositionInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/closePosition.ts b/clients/orca-whirlpools/src/generated/instructions/closePosition.ts new file mode 100644 index 00000000..149079c5 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/closePosition.ts @@ -0,0 +1,251 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CLOSE_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 123, 134, 81, 0, 49, 68, 98, 98, +]); + +export function getClosePositionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CLOSE_POSITION_DISCRIMINATOR, + ); +} + +export type ClosePositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountReceiver extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionMint extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountReceiver extends string + ? WritableAccount + : TAccountReceiver, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionMint extends string + ? WritableAccount + : TAccountPositionMint, + TAccountPositionTokenAccount extends string + ? WritableAccount + : TAccountPositionTokenAccount, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface ClosePositionInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface ClosePositionInstructionDataArgs {} + +export function getClosePositionInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: CLOSE_POSITION_DISCRIMINATOR }), + ); +} + +export function getClosePositionInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getClosePositionInstructionDataCodec(): FixedSizeCodec< + ClosePositionInstructionDataArgs, + ClosePositionInstructionData +> { + return combineCodec( + getClosePositionInstructionDataEncoder(), + getClosePositionInstructionDataDecoder(), + ); +} + +export interface ClosePositionInput< + TAccountPositionAuthority extends string = string, + TAccountReceiver extends string = string, + TAccountPosition extends string = string, + TAccountPositionMint extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenProgram extends string = string, +> { + positionAuthority: TransactionSigner; + receiver: Address; + position: Address; + positionMint: Address; + positionTokenAccount: Address; + tokenProgram: Address; +} + +export function getClosePositionInstruction< + TAccountPositionAuthority extends string, + TAccountReceiver extends string, + TAccountPosition extends string, + TAccountPositionMint extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: ClosePositionInput< + TAccountPositionAuthority, + TAccountReceiver, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): ClosePositionInstruction< + TProgramAddress, + TAccountPositionAuthority, + TAccountReceiver, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + receiver: { value: input.receiver ?? null, isWritable: true }, + position: { value: input.position ?? null, isWritable: true }, + positionMint: { value: input.positionMint ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.receiver), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionMint), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenProgram), + ], + programAddress, + data: getClosePositionInstructionDataEncoder().encode({}), + } as ClosePositionInstruction< + TProgramAddress, + TAccountPositionAuthority, + TAccountReceiver, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountTokenProgram + >; + + return instruction; +} + +export interface ParsedClosePositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + positionAuthority: TAccountMetas[0]; + receiver: TAccountMetas[1]; + position: TAccountMetas[2]; + positionMint: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + }; + data: ClosePositionInstructionData; +} + +export function parseClosePositionInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedClosePositionInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + positionAuthority: getNextAccount(), + receiver: getNextAccount(), + position: getNextAccount(), + positionMint: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getClosePositionInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/closePositionWithTokenExtensions.ts b/clients/orca-whirlpools/src/generated/instructions/closePositionWithTokenExtensions.ts new file mode 100644 index 00000000..da755b00 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/closePositionWithTokenExtensions.ts @@ -0,0 +1,260 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CLOSE_POSITION_WITH_TOKEN_EXTENSIONS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([1, 182, 135, 59, 155, 25, 99, 223]); + +export function getClosePositionWithTokenExtensionsDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CLOSE_POSITION_WITH_TOKEN_EXTENSIONS_DISCRIMINATOR, + ); +} + +export type ClosePositionWithTokenExtensionsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountReceiver extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionMint extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountToken2022Program extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountReceiver extends string + ? WritableAccount + : TAccountReceiver, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionMint extends string + ? WritableAccount + : TAccountPositionMint, + TAccountPositionTokenAccount extends string + ? WritableAccount + : TAccountPositionTokenAccount, + TAccountToken2022Program extends string + ? ReadonlyAccount + : TAccountToken2022Program, + ...TRemainingAccounts, + ] + >; + +export interface ClosePositionWithTokenExtensionsInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface ClosePositionWithTokenExtensionsInstructionDataArgs {} + +export function getClosePositionWithTokenExtensionsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: CLOSE_POSITION_WITH_TOKEN_EXTENSIONS_DISCRIMINATOR, + }), + ); +} + +export function getClosePositionWithTokenExtensionsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getClosePositionWithTokenExtensionsInstructionDataCodec(): FixedSizeCodec< + ClosePositionWithTokenExtensionsInstructionDataArgs, + ClosePositionWithTokenExtensionsInstructionData +> { + return combineCodec( + getClosePositionWithTokenExtensionsInstructionDataEncoder(), + getClosePositionWithTokenExtensionsInstructionDataDecoder(), + ); +} + +export interface ClosePositionWithTokenExtensionsInput< + TAccountPositionAuthority extends string = string, + TAccountReceiver extends string = string, + TAccountPosition extends string = string, + TAccountPositionMint extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountToken2022Program extends string = string, +> { + positionAuthority: TransactionSigner; + receiver: Address; + position: Address; + positionMint: Address; + positionTokenAccount: Address; + token2022Program: Address; +} + +export function getClosePositionWithTokenExtensionsInstruction< + TAccountPositionAuthority extends string, + TAccountReceiver extends string, + TAccountPosition extends string, + TAccountPositionMint extends string, + TAccountPositionTokenAccount extends string, + TAccountToken2022Program extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: ClosePositionWithTokenExtensionsInput< + TAccountPositionAuthority, + TAccountReceiver, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountToken2022Program + >, + config?: { programAddress?: TProgramAddress }, +): ClosePositionWithTokenExtensionsInstruction< + TProgramAddress, + TAccountPositionAuthority, + TAccountReceiver, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountToken2022Program +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + receiver: { value: input.receiver ?? null, isWritable: true }, + position: { value: input.position ?? null, isWritable: true }, + positionMint: { value: input.positionMint ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: true, + }, + token2022Program: { + value: input.token2022Program ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.receiver), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionMint), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.token2022Program), + ], + programAddress, + data: getClosePositionWithTokenExtensionsInstructionDataEncoder().encode( + {}, + ), + } as ClosePositionWithTokenExtensionsInstruction< + TProgramAddress, + TAccountPositionAuthority, + TAccountReceiver, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountToken2022Program + >; + + return instruction; +} + +export interface ParsedClosePositionWithTokenExtensionsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + positionAuthority: TAccountMetas[0]; + receiver: TAccountMetas[1]; + position: TAccountMetas[2]; + positionMint: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + token2022Program: TAccountMetas[5]; + }; + data: ClosePositionWithTokenExtensionsInstructionData; +} + +export function parseClosePositionWithTokenExtensionsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedClosePositionWithTokenExtensionsInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + positionAuthority: getNextAccount(), + receiver: getNextAccount(), + position: getNextAccount(), + positionMint: getNextAccount(), + positionTokenAccount: getNextAccount(), + token2022Program: getNextAccount(), + }, + data: getClosePositionWithTokenExtensionsInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/collectFees.ts b/clients/orca-whirlpools/src/generated/instructions/collectFees.ts new file mode 100644 index 00000000..2c0bdc9a --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/collectFees.ts @@ -0,0 +1,299 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const COLLECT_FEES_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 164, 152, 207, 99, 30, 186, 19, 182, +]); + +export function getCollectFeesDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + COLLECT_FEES_DISCRIMINATOR, + ); +} + +export type CollectFeesInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface CollectFeesInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface CollectFeesInstructionDataArgs {} + +export function getCollectFeesInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: COLLECT_FEES_DISCRIMINATOR }), + ); +} + +export function getCollectFeesInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getCollectFeesInstructionDataCodec(): FixedSizeCodec< + CollectFeesInstructionDataArgs, + CollectFeesInstructionData +> { + return combineCodec( + getCollectFeesInstructionDataEncoder(), + getCollectFeesInstructionDataDecoder(), + ); +} + +export interface CollectFeesInput< + TAccountWhirlpool extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTokenProgram extends string = string, +> { + whirlpool: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + tokenOwnerAccountA: Address; + tokenVaultA: Address; + tokenOwnerAccountB: Address; + tokenVaultB: Address; + tokenProgram: Address; +} + +export function getCollectFeesInstruction< + TAccountWhirlpool extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenVaultA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultB extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CollectFeesInput< + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): CollectFeesInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tokenProgram), + ], + programAddress, + data: getCollectFeesInstructionDataEncoder().encode({}), + } as CollectFeesInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTokenProgram + >; + + return instruction; +} + +export interface ParsedCollectFeesInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + positionAuthority: TAccountMetas[1]; + position: TAccountMetas[2]; + positionTokenAccount: TAccountMetas[3]; + tokenOwnerAccountA: TAccountMetas[4]; + tokenVaultA: TAccountMetas[5]; + tokenOwnerAccountB: TAccountMetas[6]; + tokenVaultB: TAccountMetas[7]; + tokenProgram: TAccountMetas[8]; + }; + data: CollectFeesInstructionData; +} + +export function parseCollectFeesInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCollectFeesInstruction { + if (instruction.accounts.length < 9) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultB: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getCollectFeesInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/collectFeesV2.ts b/clients/orca-whirlpools/src/generated/instructions/collectFeesV2.ts new file mode 100644 index 00000000..38ab5c8f --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/collectFeesV2.ts @@ -0,0 +1,386 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const COLLECT_FEES_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [207, 117, 95, 191, 229, 180, 226, 15], +); + +export function getCollectFeesV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + COLLECT_FEES_V2_DISCRIMINATOR, + ); +} + +export type CollectFeesV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTokenProgramA extends string | AccountMeta = string, + TAccountTokenProgramB extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTokenProgramA extends string + ? ReadonlyAccount + : TAccountTokenProgramA, + TAccountTokenProgramB extends string + ? ReadonlyAccount + : TAccountTokenProgramB, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + ...TRemainingAccounts, + ] + >; + +export interface CollectFeesV2InstructionData { + discriminator: ReadonlyUint8Array; + remainingAccountsInfo: Option; +} + +export interface CollectFeesV2InstructionDataArgs { + remainingAccountsInfo: OptionOrNullable; +} + +export function getCollectFeesV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ ...value, discriminator: COLLECT_FEES_V2_DISCRIMINATOR }), + ); +} + +export function getCollectFeesV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getCollectFeesV2InstructionDataCodec(): Codec< + CollectFeesV2InstructionDataArgs, + CollectFeesV2InstructionData +> { + return combineCodec( + getCollectFeesV2InstructionDataEncoder(), + getCollectFeesV2InstructionDataDecoder(), + ); +} + +export interface CollectFeesV2Input< + TAccountWhirlpool extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTokenProgramA extends string = string, + TAccountTokenProgramB extends string = string, + TAccountMemoProgram extends string = string, +> { + whirlpool: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + tokenMintA: Address; + tokenMintB: Address; + tokenOwnerAccountA: Address; + tokenVaultA: Address; + tokenOwnerAccountB: Address; + tokenVaultB: Address; + tokenProgramA: Address; + tokenProgramB: Address; + memoProgram: Address; + remainingAccountsInfo: CollectFeesV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getCollectFeesV2Instruction< + TAccountWhirlpool extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenVaultA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultB extends string, + TAccountTokenProgramA extends string, + TAccountTokenProgramB extends string, + TAccountMemoProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CollectFeesV2Input< + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram + >, + config?: { programAddress?: TProgramAddress }, +): CollectFeesV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, + tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tokenProgramA), + getAccountMeta(accounts.tokenProgramB), + getAccountMeta(accounts.memoProgram), + ], + programAddress, + data: getCollectFeesV2InstructionDataEncoder().encode( + args as CollectFeesV2InstructionDataArgs, + ), + } as CollectFeesV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram + >; + + return instruction; +} + +export interface ParsedCollectFeesV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + positionAuthority: TAccountMetas[1]; + position: TAccountMetas[2]; + positionTokenAccount: TAccountMetas[3]; + tokenMintA: TAccountMetas[4]; + tokenMintB: TAccountMetas[5]; + tokenOwnerAccountA: TAccountMetas[6]; + tokenVaultA: TAccountMetas[7]; + tokenOwnerAccountB: TAccountMetas[8]; + tokenVaultB: TAccountMetas[9]; + tokenProgramA: TAccountMetas[10]; + tokenProgramB: TAccountMetas[11]; + memoProgram: TAccountMetas[12]; + }; + data: CollectFeesV2InstructionData; +} + +export function parseCollectFeesV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCollectFeesV2Instruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultB: getNextAccount(), + tokenProgramA: getNextAccount(), + tokenProgramB: getNextAccount(), + memoProgram: getNextAccount(), + }, + data: getCollectFeesV2InstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/collectProtocolFees.ts b/clients/orca-whirlpools/src/generated/instructions/collectProtocolFees.ts new file mode 100644 index 00000000..be9f1612 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/collectProtocolFees.ts @@ -0,0 +1,289 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const COLLECT_PROTOCOL_FEES_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([22, 67, 23, 98, 150, 178, 70, 220]); + +export function getCollectProtocolFeesDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + COLLECT_PROTOCOL_FEES_DISCRIMINATOR, + ); +} + +export type CollectProtocolFeesInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountCollectProtocolFeesAuthority extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTokenDestinationA extends string | AccountMeta = string, + TAccountTokenDestinationB extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountCollectProtocolFeesAuthority, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTokenDestinationA extends string + ? WritableAccount + : TAccountTokenDestinationA, + TAccountTokenDestinationB extends string + ? WritableAccount + : TAccountTokenDestinationB, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface CollectProtocolFeesInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface CollectProtocolFeesInstructionDataArgs {} + +export function getCollectProtocolFeesInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: COLLECT_PROTOCOL_FEES_DISCRIMINATOR, + }), + ); +} + +export function getCollectProtocolFeesInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getCollectProtocolFeesInstructionDataCodec(): FixedSizeCodec< + CollectProtocolFeesInstructionDataArgs, + CollectProtocolFeesInstructionData +> { + return combineCodec( + getCollectProtocolFeesInstructionDataEncoder(), + getCollectProtocolFeesInstructionDataDecoder(), + ); +} + +export interface CollectProtocolFeesInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpool extends string = string, + TAccountCollectProtocolFeesAuthority extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTokenDestinationA extends string = string, + TAccountTokenDestinationB extends string = string, + TAccountTokenProgram extends string = string, +> { + whirlpoolsConfig: Address; + whirlpool: Address; + collectProtocolFeesAuthority: TransactionSigner; + tokenVaultA: Address; + tokenVaultB: Address; + tokenDestinationA: Address; + tokenDestinationB: Address; + tokenProgram: Address; +} + +export function getCollectProtocolFeesInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpool extends string, + TAccountCollectProtocolFeesAuthority extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountTokenDestinationA extends string, + TAccountTokenDestinationB extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CollectProtocolFeesInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTokenDestinationA, + TAccountTokenDestinationB, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): CollectProtocolFeesInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTokenDestinationA, + TAccountTokenDestinationB, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + collectProtocolFeesAuthority: { + value: input.collectProtocolFeesAuthority ?? null, + isWritable: false, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tokenDestinationA: { + value: input.tokenDestinationA ?? null, + isWritable: true, + }, + tokenDestinationB: { + value: input.tokenDestinationB ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.collectProtocolFeesAuthority), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tokenDestinationA), + getAccountMeta(accounts.tokenDestinationB), + getAccountMeta(accounts.tokenProgram), + ], + programAddress, + data: getCollectProtocolFeesInstructionDataEncoder().encode({}), + } as CollectProtocolFeesInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTokenDestinationA, + TAccountTokenDestinationB, + TAccountTokenProgram + >; + + return instruction; +} + +export interface ParsedCollectProtocolFeesInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpool: TAccountMetas[1]; + collectProtocolFeesAuthority: TAccountMetas[2]; + tokenVaultA: TAccountMetas[3]; + tokenVaultB: TAccountMetas[4]; + tokenDestinationA: TAccountMetas[5]; + tokenDestinationB: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + }; + data: CollectProtocolFeesInstructionData; +} + +export function parseCollectProtocolFeesInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCollectProtocolFeesInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpool: getNextAccount(), + collectProtocolFeesAuthority: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + tokenDestinationA: getNextAccount(), + tokenDestinationB: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getCollectProtocolFeesInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/collectProtocolFeesV2.ts b/clients/orca-whirlpools/src/generated/instructions/collectProtocolFeesV2.ts new file mode 100644 index 00000000..89592183 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/collectProtocolFeesV2.ts @@ -0,0 +1,376 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const COLLECT_PROTOCOL_FEES_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([103, 128, 222, 134, 114, 200, 22, 200]); + +export function getCollectProtocolFeesV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + COLLECT_PROTOCOL_FEES_V2_DISCRIMINATOR, + ); +} + +export type CollectProtocolFeesV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountCollectProtocolFeesAuthority extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTokenDestinationA extends string | AccountMeta = string, + TAccountTokenDestinationB extends string | AccountMeta = string, + TAccountTokenProgramA extends string | AccountMeta = string, + TAccountTokenProgramB extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountCollectProtocolFeesAuthority, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTokenDestinationA extends string + ? WritableAccount + : TAccountTokenDestinationA, + TAccountTokenDestinationB extends string + ? WritableAccount + : TAccountTokenDestinationB, + TAccountTokenProgramA extends string + ? ReadonlyAccount + : TAccountTokenProgramA, + TAccountTokenProgramB extends string + ? ReadonlyAccount + : TAccountTokenProgramB, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + ...TRemainingAccounts, + ] + >; + +export interface CollectProtocolFeesV2InstructionData { + discriminator: ReadonlyUint8Array; + remainingAccountsInfo: Option; +} + +export interface CollectProtocolFeesV2InstructionDataArgs { + remainingAccountsInfo: OptionOrNullable; +} + +export function getCollectProtocolFeesV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ + ...value, + discriminator: COLLECT_PROTOCOL_FEES_V2_DISCRIMINATOR, + }), + ); +} + +export function getCollectProtocolFeesV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getCollectProtocolFeesV2InstructionDataCodec(): Codec< + CollectProtocolFeesV2InstructionDataArgs, + CollectProtocolFeesV2InstructionData +> { + return combineCodec( + getCollectProtocolFeesV2InstructionDataEncoder(), + getCollectProtocolFeesV2InstructionDataDecoder(), + ); +} + +export interface CollectProtocolFeesV2Input< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpool extends string = string, + TAccountCollectProtocolFeesAuthority extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTokenDestinationA extends string = string, + TAccountTokenDestinationB extends string = string, + TAccountTokenProgramA extends string = string, + TAccountTokenProgramB extends string = string, + TAccountMemoProgram extends string = string, +> { + whirlpoolsConfig: Address; + whirlpool: Address; + collectProtocolFeesAuthority: TransactionSigner; + tokenMintA: Address; + tokenMintB: Address; + tokenVaultA: Address; + tokenVaultB: Address; + tokenDestinationA: Address; + tokenDestinationB: Address; + tokenProgramA: Address; + tokenProgramB: Address; + memoProgram: Address; + remainingAccountsInfo: CollectProtocolFeesV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getCollectProtocolFeesV2Instruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpool extends string, + TAccountCollectProtocolFeesAuthority extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountTokenDestinationA extends string, + TAccountTokenDestinationB extends string, + TAccountTokenProgramA extends string, + TAccountTokenProgramB extends string, + TAccountMemoProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CollectProtocolFeesV2Input< + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTokenDestinationA, + TAccountTokenDestinationB, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram + >, + config?: { programAddress?: TProgramAddress }, +): CollectProtocolFeesV2Instruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTokenDestinationA, + TAccountTokenDestinationB, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + collectProtocolFeesAuthority: { + value: input.collectProtocolFeesAuthority ?? null, + isWritable: false, + }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tokenDestinationA: { + value: input.tokenDestinationA ?? null, + isWritable: true, + }, + tokenDestinationB: { + value: input.tokenDestinationB ?? null, + isWritable: true, + }, + tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, + tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.collectProtocolFeesAuthority), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tokenDestinationA), + getAccountMeta(accounts.tokenDestinationB), + getAccountMeta(accounts.tokenProgramA), + getAccountMeta(accounts.tokenProgramB), + getAccountMeta(accounts.memoProgram), + ], + programAddress, + data: getCollectProtocolFeesV2InstructionDataEncoder().encode( + args as CollectProtocolFeesV2InstructionDataArgs, + ), + } as CollectProtocolFeesV2Instruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountCollectProtocolFeesAuthority, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTokenDestinationA, + TAccountTokenDestinationB, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram + >; + + return instruction; +} + +export interface ParsedCollectProtocolFeesV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpool: TAccountMetas[1]; + collectProtocolFeesAuthority: TAccountMetas[2]; + tokenMintA: TAccountMetas[3]; + tokenMintB: TAccountMetas[4]; + tokenVaultA: TAccountMetas[5]; + tokenVaultB: TAccountMetas[6]; + tokenDestinationA: TAccountMetas[7]; + tokenDestinationB: TAccountMetas[8]; + tokenProgramA: TAccountMetas[9]; + tokenProgramB: TAccountMetas[10]; + memoProgram: TAccountMetas[11]; + }; + data: CollectProtocolFeesV2InstructionData; +} + +export function parseCollectProtocolFeesV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCollectProtocolFeesV2Instruction { + if (instruction.accounts.length < 12) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpool: getNextAccount(), + collectProtocolFeesAuthority: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + tokenDestinationA: getNextAccount(), + tokenDestinationB: getNextAccount(), + tokenProgramA: getNextAccount(), + tokenProgramB: getNextAccount(), + memoProgram: getNextAccount(), + }, + data: getCollectProtocolFeesV2InstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/collectReward.ts b/clients/orca-whirlpools/src/generated/instructions/collectReward.ts new file mode 100644 index 00000000..55c5a867 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/collectReward.ts @@ -0,0 +1,283 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const COLLECT_REWARD_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 70, 5, 132, 87, 86, 235, 177, 34, +]); + +export function getCollectRewardDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + COLLECT_REWARD_DISCRIMINATOR, + ); +} + +export type CollectRewardInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountRewardOwnerAccount extends string | AccountMeta = string, + TAccountRewardVault extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountRewardOwnerAccount extends string + ? WritableAccount + : TAccountRewardOwnerAccount, + TAccountRewardVault extends string + ? WritableAccount + : TAccountRewardVault, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface CollectRewardInstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; +} + +export interface CollectRewardInstructionDataArgs { + rewardIndex: number; +} + +export function getCollectRewardInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: COLLECT_REWARD_DISCRIMINATOR }), + ); +} + +export function getCollectRewardInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ]); +} + +export function getCollectRewardInstructionDataCodec(): FixedSizeCodec< + CollectRewardInstructionDataArgs, + CollectRewardInstructionData +> { + return combineCodec( + getCollectRewardInstructionDataEncoder(), + getCollectRewardInstructionDataDecoder(), + ); +} + +export interface CollectRewardInput< + TAccountWhirlpool extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountRewardOwnerAccount extends string = string, + TAccountRewardVault extends string = string, + TAccountTokenProgram extends string = string, +> { + whirlpool: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + rewardOwnerAccount: Address; + rewardVault: Address; + tokenProgram: Address; + rewardIndex: CollectRewardInstructionDataArgs["rewardIndex"]; +} + +export function getCollectRewardInstruction< + TAccountWhirlpool extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountRewardOwnerAccount extends string, + TAccountRewardVault extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CollectRewardInput< + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountRewardOwnerAccount, + TAccountRewardVault, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): CollectRewardInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountRewardOwnerAccount, + TAccountRewardVault, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + rewardOwnerAccount: { + value: input.rewardOwnerAccount ?? null, + isWritable: true, + }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.rewardOwnerAccount), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.tokenProgram), + ], + programAddress, + data: getCollectRewardInstructionDataEncoder().encode( + args as CollectRewardInstructionDataArgs, + ), + } as CollectRewardInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountRewardOwnerAccount, + TAccountRewardVault, + TAccountTokenProgram + >; + + return instruction; +} + +export interface ParsedCollectRewardInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + positionAuthority: TAccountMetas[1]; + position: TAccountMetas[2]; + positionTokenAccount: TAccountMetas[3]; + rewardOwnerAccount: TAccountMetas[4]; + rewardVault: TAccountMetas[5]; + tokenProgram: TAccountMetas[6]; + }; + data: CollectRewardInstructionData; +} + +export function parseCollectRewardInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCollectRewardInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + rewardOwnerAccount: getNextAccount(), + rewardVault: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getCollectRewardInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/collectRewardV2.ts b/clients/orca-whirlpools/src/generated/instructions/collectRewardV2.ts new file mode 100644 index 00000000..f4618a18 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/collectRewardV2.ts @@ -0,0 +1,336 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const COLLECT_REWARD_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([177, 107, 37, 180, 160, 19, 49, 209]); + +export function getCollectRewardV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + COLLECT_REWARD_V2_DISCRIMINATOR, + ); +} + +export type CollectRewardV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountRewardOwnerAccount extends string | AccountMeta = string, + TAccountRewardMint extends string | AccountMeta = string, + TAccountRewardVault extends string | AccountMeta = string, + TAccountRewardTokenProgram extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountRewardOwnerAccount extends string + ? WritableAccount + : TAccountRewardOwnerAccount, + TAccountRewardMint extends string + ? ReadonlyAccount + : TAccountRewardMint, + TAccountRewardVault extends string + ? WritableAccount + : TAccountRewardVault, + TAccountRewardTokenProgram extends string + ? ReadonlyAccount + : TAccountRewardTokenProgram, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + ...TRemainingAccounts, + ] + >; + +export interface CollectRewardV2InstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; + remainingAccountsInfo: Option; +} + +export interface CollectRewardV2InstructionDataArgs { + rewardIndex: number; + remainingAccountsInfo: OptionOrNullable; +} + +export function getCollectRewardV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ ...value, discriminator: COLLECT_REWARD_V2_DISCRIMINATOR }), + ); +} + +export function getCollectRewardV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getCollectRewardV2InstructionDataCodec(): Codec< + CollectRewardV2InstructionDataArgs, + CollectRewardV2InstructionData +> { + return combineCodec( + getCollectRewardV2InstructionDataEncoder(), + getCollectRewardV2InstructionDataDecoder(), + ); +} + +export interface CollectRewardV2Input< + TAccountWhirlpool extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountRewardOwnerAccount extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardVault extends string = string, + TAccountRewardTokenProgram extends string = string, + TAccountMemoProgram extends string = string, +> { + whirlpool: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + rewardOwnerAccount: Address; + rewardMint: Address; + rewardVault: Address; + rewardTokenProgram: Address; + memoProgram: Address; + rewardIndex: CollectRewardV2InstructionDataArgs["rewardIndex"]; + remainingAccountsInfo: CollectRewardV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getCollectRewardV2Instruction< + TAccountWhirlpool extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountRewardOwnerAccount extends string, + TAccountRewardMint extends string, + TAccountRewardVault extends string, + TAccountRewardTokenProgram extends string, + TAccountMemoProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: CollectRewardV2Input< + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountRewardOwnerAccount, + TAccountRewardMint, + TAccountRewardVault, + TAccountRewardTokenProgram, + TAccountMemoProgram + >, + config?: { programAddress?: TProgramAddress }, +): CollectRewardV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountRewardOwnerAccount, + TAccountRewardMint, + TAccountRewardVault, + TAccountRewardTokenProgram, + TAccountMemoProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + rewardOwnerAccount: { + value: input.rewardOwnerAccount ?? null, + isWritable: true, + }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + rewardTokenProgram: { + value: input.rewardTokenProgram ?? null, + isWritable: false, + }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.rewardOwnerAccount), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.rewardTokenProgram), + getAccountMeta(accounts.memoProgram), + ], + programAddress, + data: getCollectRewardV2InstructionDataEncoder().encode( + args as CollectRewardV2InstructionDataArgs, + ), + } as CollectRewardV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountRewardOwnerAccount, + TAccountRewardMint, + TAccountRewardVault, + TAccountRewardTokenProgram, + TAccountMemoProgram + >; + + return instruction; +} + +export interface ParsedCollectRewardV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + positionAuthority: TAccountMetas[1]; + position: TAccountMetas[2]; + positionTokenAccount: TAccountMetas[3]; + rewardOwnerAccount: TAccountMetas[4]; + rewardMint: TAccountMetas[5]; + rewardVault: TAccountMetas[6]; + rewardTokenProgram: TAccountMetas[7]; + memoProgram: TAccountMetas[8]; + }; + data: CollectRewardV2InstructionData; +} + +export function parseCollectRewardV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCollectRewardV2Instruction { + if (instruction.accounts.length < 9) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + rewardOwnerAccount: getNextAccount(), + rewardMint: getNextAccount(), + rewardVault: getNextAccount(), + rewardTokenProgram: getNextAccount(), + memoProgram: getNextAccount(), + }, + data: getCollectRewardV2InstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/decreaseLiquidity.ts b/clients/orca-whirlpools/src/generated/instructions/decreaseLiquidity.ts new file mode 100644 index 00000000..9eabde0b --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/decreaseLiquidity.ts @@ -0,0 +1,353 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const DECREASE_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([160, 38, 208, 111, 104, 91, 44, 1]); + +export function getDecreaseLiquidityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + DECREASE_LIQUIDITY_DISCRIMINATOR, + ); +} + +export type DecreaseLiquidityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTickArrayLower extends string | AccountMeta = string, + TAccountTickArrayUpper extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTickArrayLower extends string + ? WritableAccount + : TAccountTickArrayLower, + TAccountTickArrayUpper extends string + ? WritableAccount + : TAccountTickArrayUpper, + ...TRemainingAccounts, + ] + >; + +export interface DecreaseLiquidityInstructionData { + discriminator: ReadonlyUint8Array; + liquidityAmount: bigint; + tokenMinA: bigint; + tokenMinB: bigint; +} + +export interface DecreaseLiquidityInstructionDataArgs { + liquidityAmount: number | bigint; + tokenMinA: number | bigint; + tokenMinB: number | bigint; +} + +export function getDecreaseLiquidityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["liquidityAmount", getU128Encoder()], + ["tokenMinA", getU64Encoder()], + ["tokenMinB", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: DECREASE_LIQUIDITY_DISCRIMINATOR }), + ); +} + +export function getDecreaseLiquidityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["liquidityAmount", getU128Decoder()], + ["tokenMinA", getU64Decoder()], + ["tokenMinB", getU64Decoder()], + ]); +} + +export function getDecreaseLiquidityInstructionDataCodec(): FixedSizeCodec< + DecreaseLiquidityInstructionDataArgs, + DecreaseLiquidityInstructionData +> { + return combineCodec( + getDecreaseLiquidityInstructionDataEncoder(), + getDecreaseLiquidityInstructionDataDecoder(), + ); +} + +export interface DecreaseLiquidityInput< + TAccountWhirlpool extends string = string, + TAccountTokenProgram extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTickArrayLower extends string = string, + TAccountTickArrayUpper extends string = string, +> { + whirlpool: Address; + tokenProgram: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + tokenOwnerAccountA: Address; + tokenOwnerAccountB: Address; + tokenVaultA: Address; + tokenVaultB: Address; + tickArrayLower: Address; + tickArrayUpper: Address; + liquidityAmount: DecreaseLiquidityInstructionDataArgs["liquidityAmount"]; + tokenMinA: DecreaseLiquidityInstructionDataArgs["tokenMinA"]; + tokenMinB: DecreaseLiquidityInstructionDataArgs["tokenMinB"]; +} + +export function getDecreaseLiquidityInstruction< + TAccountWhirlpool extends string, + TAccountTokenProgram extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountTickArrayLower extends string, + TAccountTickArrayUpper extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: DecreaseLiquidityInput< + TAccountWhirlpool, + TAccountTokenProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >, + config?: { programAddress?: TProgramAddress }, +): DecreaseLiquidityInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, + tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tickArrayLower), + getAccountMeta(accounts.tickArrayUpper), + ], + programAddress, + data: getDecreaseLiquidityInstructionDataEncoder().encode( + args as DecreaseLiquidityInstructionDataArgs, + ), + } as DecreaseLiquidityInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >; + + return instruction; +} + +export interface ParsedDecreaseLiquidityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + tokenProgram: TAccountMetas[1]; + positionAuthority: TAccountMetas[2]; + position: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + tokenOwnerAccountA: TAccountMetas[5]; + tokenOwnerAccountB: TAccountMetas[6]; + tokenVaultA: TAccountMetas[7]; + tokenVaultB: TAccountMetas[8]; + tickArrayLower: TAccountMetas[9]; + tickArrayUpper: TAccountMetas[10]; + }; + data: DecreaseLiquidityInstructionData; +} + +export function parseDecreaseLiquidityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDecreaseLiquidityInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + tokenProgram: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + tickArrayLower: getNextAccount(), + tickArrayUpper: getNextAccount(), + }, + data: getDecreaseLiquidityInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/decreaseLiquidityV2.ts b/clients/orca-whirlpools/src/generated/instructions/decreaseLiquidityV2.ts new file mode 100644 index 00000000..c6c1b61d --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/decreaseLiquidityV2.ts @@ -0,0 +1,437 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const DECREASE_LIQUIDITY_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([58, 127, 188, 62, 79, 82, 196, 96]); + +export function getDecreaseLiquidityV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + DECREASE_LIQUIDITY_V2_DISCRIMINATOR, + ); +} + +export type DecreaseLiquidityV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenProgramA extends string | AccountMeta = string, + TAccountTokenProgramB extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTickArrayLower extends string | AccountMeta = string, + TAccountTickArrayUpper extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenProgramA extends string + ? ReadonlyAccount + : TAccountTokenProgramA, + TAccountTokenProgramB extends string + ? ReadonlyAccount + : TAccountTokenProgramB, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTickArrayLower extends string + ? WritableAccount + : TAccountTickArrayLower, + TAccountTickArrayUpper extends string + ? WritableAccount + : TAccountTickArrayUpper, + ...TRemainingAccounts, + ] + >; + +export interface DecreaseLiquidityV2InstructionData { + discriminator: ReadonlyUint8Array; + liquidityAmount: bigint; + tokenMinA: bigint; + tokenMinB: bigint; + remainingAccountsInfo: Option; +} + +export interface DecreaseLiquidityV2InstructionDataArgs { + liquidityAmount: number | bigint; + tokenMinA: number | bigint; + tokenMinB: number | bigint; + remainingAccountsInfo: OptionOrNullable; +} + +export function getDecreaseLiquidityV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["liquidityAmount", getU128Encoder()], + ["tokenMinA", getU64Encoder()], + ["tokenMinB", getU64Encoder()], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ + ...value, + discriminator: DECREASE_LIQUIDITY_V2_DISCRIMINATOR, + }), + ); +} + +export function getDecreaseLiquidityV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["liquidityAmount", getU128Decoder()], + ["tokenMinA", getU64Decoder()], + ["tokenMinB", getU64Decoder()], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getDecreaseLiquidityV2InstructionDataCodec(): Codec< + DecreaseLiquidityV2InstructionDataArgs, + DecreaseLiquidityV2InstructionData +> { + return combineCodec( + getDecreaseLiquidityV2InstructionDataEncoder(), + getDecreaseLiquidityV2InstructionDataDecoder(), + ); +} + +export interface DecreaseLiquidityV2Input< + TAccountWhirlpool extends string = string, + TAccountTokenProgramA extends string = string, + TAccountTokenProgramB extends string = string, + TAccountMemoProgram extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTickArrayLower extends string = string, + TAccountTickArrayUpper extends string = string, +> { + whirlpool: Address; + tokenProgramA: Address; + tokenProgramB: Address; + memoProgram: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + tokenMintA: Address; + tokenMintB: Address; + tokenOwnerAccountA: Address; + tokenOwnerAccountB: Address; + tokenVaultA: Address; + tokenVaultB: Address; + tickArrayLower: Address; + tickArrayUpper: Address; + liquidityAmount: DecreaseLiquidityV2InstructionDataArgs["liquidityAmount"]; + tokenMinA: DecreaseLiquidityV2InstructionDataArgs["tokenMinA"]; + tokenMinB: DecreaseLiquidityV2InstructionDataArgs["tokenMinB"]; + remainingAccountsInfo: DecreaseLiquidityV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getDecreaseLiquidityV2Instruction< + TAccountWhirlpool extends string, + TAccountTokenProgramA extends string, + TAccountTokenProgramB extends string, + TAccountMemoProgram extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountTickArrayLower extends string, + TAccountTickArrayUpper extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: DecreaseLiquidityV2Input< + TAccountWhirlpool, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >, + config?: { programAddress?: TProgramAddress }, +): DecreaseLiquidityV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, + tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, + tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenProgramA), + getAccountMeta(accounts.tokenProgramB), + getAccountMeta(accounts.memoProgram), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tickArrayLower), + getAccountMeta(accounts.tickArrayUpper), + ], + programAddress, + data: getDecreaseLiquidityV2InstructionDataEncoder().encode( + args as DecreaseLiquidityV2InstructionDataArgs, + ), + } as DecreaseLiquidityV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >; + + return instruction; +} + +export interface ParsedDecreaseLiquidityV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + tokenProgramA: TAccountMetas[1]; + tokenProgramB: TAccountMetas[2]; + memoProgram: TAccountMetas[3]; + positionAuthority: TAccountMetas[4]; + position: TAccountMetas[5]; + positionTokenAccount: TAccountMetas[6]; + tokenMintA: TAccountMetas[7]; + tokenMintB: TAccountMetas[8]; + tokenOwnerAccountA: TAccountMetas[9]; + tokenOwnerAccountB: TAccountMetas[10]; + tokenVaultA: TAccountMetas[11]; + tokenVaultB: TAccountMetas[12]; + tickArrayLower: TAccountMetas[13]; + tickArrayUpper: TAccountMetas[14]; + }; + data: DecreaseLiquidityV2InstructionData; +} + +export function parseDecreaseLiquidityV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDecreaseLiquidityV2Instruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + tokenProgramA: getNextAccount(), + tokenProgramB: getNextAccount(), + memoProgram: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + tickArrayLower: getNextAccount(), + tickArrayUpper: getNextAccount(), + }, + data: getDecreaseLiquidityV2InstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/deletePositionBundle.ts b/clients/orca-whirlpools/src/generated/instructions/deletePositionBundle.ts new file mode 100644 index 00000000..e71b8bde --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/deletePositionBundle.ts @@ -0,0 +1,258 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const DELETE_POSITION_BUNDLE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([100, 25, 99, 2, 217, 239, 124, 173]); + +export function getDeletePositionBundleDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + DELETE_POSITION_BUNDLE_DISCRIMINATOR, + ); +} + +export type DeletePositionBundleInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountPositionBundle extends string | AccountMeta = string, + TAccountPositionBundleMint extends string | AccountMeta = string, + TAccountPositionBundleTokenAccount extends string | AccountMeta = string, + TAccountPositionBundleOwner extends string | AccountMeta = string, + TAccountReceiver extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPositionBundle extends string + ? WritableAccount + : TAccountPositionBundle, + TAccountPositionBundleMint extends string + ? WritableAccount + : TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount extends string + ? WritableAccount + : TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionBundleOwner, + TAccountReceiver extends string + ? WritableAccount + : TAccountReceiver, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface DeletePositionBundleInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface DeletePositionBundleInstructionDataArgs {} + +export function getDeletePositionBundleInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: DELETE_POSITION_BUNDLE_DISCRIMINATOR, + }), + ); +} + +export function getDeletePositionBundleInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getDeletePositionBundleInstructionDataCodec(): FixedSizeCodec< + DeletePositionBundleInstructionDataArgs, + DeletePositionBundleInstructionData +> { + return combineCodec( + getDeletePositionBundleInstructionDataEncoder(), + getDeletePositionBundleInstructionDataDecoder(), + ); +} + +export interface DeletePositionBundleInput< + TAccountPositionBundle extends string = string, + TAccountPositionBundleMint extends string = string, + TAccountPositionBundleTokenAccount extends string = string, + TAccountPositionBundleOwner extends string = string, + TAccountReceiver extends string = string, + TAccountTokenProgram extends string = string, +> { + positionBundle: Address; + positionBundleMint: Address; + positionBundleTokenAccount: Address; + positionBundleOwner: TransactionSigner; + receiver: Address; + tokenProgram: Address; +} + +export function getDeletePositionBundleInstruction< + TAccountPositionBundle extends string, + TAccountPositionBundleMint extends string, + TAccountPositionBundleTokenAccount extends string, + TAccountPositionBundleOwner extends string, + TAccountReceiver extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: DeletePositionBundleInput< + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountReceiver, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): DeletePositionBundleInstruction< + TProgramAddress, + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountReceiver, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + positionBundle: { value: input.positionBundle ?? null, isWritable: true }, + positionBundleMint: { + value: input.positionBundleMint ?? null, + isWritable: true, + }, + positionBundleTokenAccount: { + value: input.positionBundleTokenAccount ?? null, + isWritable: true, + }, + positionBundleOwner: { + value: input.positionBundleOwner ?? null, + isWritable: false, + }, + receiver: { value: input.receiver ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.positionBundle), + getAccountMeta(accounts.positionBundleMint), + getAccountMeta(accounts.positionBundleTokenAccount), + getAccountMeta(accounts.positionBundleOwner), + getAccountMeta(accounts.receiver), + getAccountMeta(accounts.tokenProgram), + ], + programAddress, + data: getDeletePositionBundleInstructionDataEncoder().encode({}), + } as DeletePositionBundleInstruction< + TProgramAddress, + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountReceiver, + TAccountTokenProgram + >; + + return instruction; +} + +export interface ParsedDeletePositionBundleInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + positionBundle: TAccountMetas[0]; + positionBundleMint: TAccountMetas[1]; + positionBundleTokenAccount: TAccountMetas[2]; + positionBundleOwner: TAccountMetas[3]; + receiver: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + }; + data: DeletePositionBundleInstructionData; +} + +export function parseDeletePositionBundleInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDeletePositionBundleInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + positionBundle: getNextAccount(), + positionBundleMint: getNextAccount(), + positionBundleTokenAccount: getNextAccount(), + positionBundleOwner: getNextAccount(), + receiver: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getDeletePositionBundleInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/deleteTokenBadge.ts b/clients/orca-whirlpools/src/generated/instructions/deleteTokenBadge.ts new file mode 100644 index 00000000..cf957f93 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/deleteTokenBadge.ts @@ -0,0 +1,253 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const DELETE_TOKEN_BADGE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([53, 146, 68, 8, 18, 117, 17, 185]); + +export function getDeleteTokenBadgeDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + DELETE_TOKEN_BADGE_DISCRIMINATOR, + ); +} + +export type DeleteTokenBadgeInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpoolsConfigExtension extends string | AccountMeta = string, + TAccountTokenBadgeAuthority extends string | AccountMeta = string, + TAccountTokenMint extends string | AccountMeta = string, + TAccountTokenBadge extends string | AccountMeta = string, + TAccountReceiver extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountTokenBadgeAuthority, + TAccountTokenMint extends string + ? ReadonlyAccount + : TAccountTokenMint, + TAccountTokenBadge extends string + ? WritableAccount + : TAccountTokenBadge, + TAccountReceiver extends string + ? WritableAccount + : TAccountReceiver, + ...TRemainingAccounts, + ] + >; + +export interface DeleteTokenBadgeInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface DeleteTokenBadgeInstructionDataArgs {} + +export function getDeleteTokenBadgeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: DELETE_TOKEN_BADGE_DISCRIMINATOR }), + ); +} + +export function getDeleteTokenBadgeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getDeleteTokenBadgeInstructionDataCodec(): FixedSizeCodec< + DeleteTokenBadgeInstructionDataArgs, + DeleteTokenBadgeInstructionData +> { + return combineCodec( + getDeleteTokenBadgeInstructionDataEncoder(), + getDeleteTokenBadgeInstructionDataDecoder(), + ); +} + +export interface DeleteTokenBadgeInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpoolsConfigExtension extends string = string, + TAccountTokenBadgeAuthority extends string = string, + TAccountTokenMint extends string = string, + TAccountTokenBadge extends string = string, + TAccountReceiver extends string = string, +> { + whirlpoolsConfig: Address; + whirlpoolsConfigExtension: Address; + tokenBadgeAuthority: TransactionSigner; + tokenMint: Address; + tokenBadge: Address; + receiver: Address; +} + +export function getDeleteTokenBadgeInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpoolsConfigExtension extends string, + TAccountTokenBadgeAuthority extends string, + TAccountTokenMint extends string, + TAccountTokenBadge extends string, + TAccountReceiver extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: DeleteTokenBadgeInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority, + TAccountTokenMint, + TAccountTokenBadge, + TAccountReceiver + >, + config?: { programAddress?: TProgramAddress }, +): DeleteTokenBadgeInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority, + TAccountTokenMint, + TAccountTokenBadge, + TAccountReceiver +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpoolsConfigExtension: { + value: input.whirlpoolsConfigExtension ?? null, + isWritable: false, + }, + tokenBadgeAuthority: { + value: input.tokenBadgeAuthority ?? null, + isWritable: false, + }, + tokenMint: { value: input.tokenMint ?? null, isWritable: false }, + tokenBadge: { value: input.tokenBadge ?? null, isWritable: true }, + receiver: { value: input.receiver ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpoolsConfigExtension), + getAccountMeta(accounts.tokenBadgeAuthority), + getAccountMeta(accounts.tokenMint), + getAccountMeta(accounts.tokenBadge), + getAccountMeta(accounts.receiver), + ], + programAddress, + data: getDeleteTokenBadgeInstructionDataEncoder().encode({}), + } as DeleteTokenBadgeInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority, + TAccountTokenMint, + TAccountTokenBadge, + TAccountReceiver + >; + + return instruction; +} + +export interface ParsedDeleteTokenBadgeInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpoolsConfigExtension: TAccountMetas[1]; + tokenBadgeAuthority: TAccountMetas[2]; + tokenMint: TAccountMetas[3]; + tokenBadge: TAccountMetas[4]; + receiver: TAccountMetas[5]; + }; + data: DeleteTokenBadgeInstructionData; +} + +export function parseDeleteTokenBadgeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedDeleteTokenBadgeInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpoolsConfigExtension: getNextAccount(), + tokenBadgeAuthority: getNextAccount(), + tokenMint: getNextAccount(), + tokenBadge: getNextAccount(), + receiver: getNextAccount(), + }, + data: getDeleteTokenBadgeInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/increaseLiquidity.ts b/clients/orca-whirlpools/src/generated/instructions/increaseLiquidity.ts new file mode 100644 index 00000000..153a50c6 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/increaseLiquidity.ts @@ -0,0 +1,353 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INCREASE_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([46, 156, 243, 118, 13, 205, 251, 178]); + +export function getIncreaseLiquidityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INCREASE_LIQUIDITY_DISCRIMINATOR, + ); +} + +export type IncreaseLiquidityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTickArrayLower extends string | AccountMeta = string, + TAccountTickArrayUpper extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTickArrayLower extends string + ? WritableAccount + : TAccountTickArrayLower, + TAccountTickArrayUpper extends string + ? WritableAccount + : TAccountTickArrayUpper, + ...TRemainingAccounts, + ] + >; + +export interface IncreaseLiquidityInstructionData { + discriminator: ReadonlyUint8Array; + liquidityAmount: bigint; + tokenMaxA: bigint; + tokenMaxB: bigint; +} + +export interface IncreaseLiquidityInstructionDataArgs { + liquidityAmount: number | bigint; + tokenMaxA: number | bigint; + tokenMaxB: number | bigint; +} + +export function getIncreaseLiquidityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["liquidityAmount", getU128Encoder()], + ["tokenMaxA", getU64Encoder()], + ["tokenMaxB", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: INCREASE_LIQUIDITY_DISCRIMINATOR }), + ); +} + +export function getIncreaseLiquidityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["liquidityAmount", getU128Decoder()], + ["tokenMaxA", getU64Decoder()], + ["tokenMaxB", getU64Decoder()], + ]); +} + +export function getIncreaseLiquidityInstructionDataCodec(): FixedSizeCodec< + IncreaseLiquidityInstructionDataArgs, + IncreaseLiquidityInstructionData +> { + return combineCodec( + getIncreaseLiquidityInstructionDataEncoder(), + getIncreaseLiquidityInstructionDataDecoder(), + ); +} + +export interface IncreaseLiquidityInput< + TAccountWhirlpool extends string = string, + TAccountTokenProgram extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTickArrayLower extends string = string, + TAccountTickArrayUpper extends string = string, +> { + whirlpool: Address; + tokenProgram: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + tokenOwnerAccountA: Address; + tokenOwnerAccountB: Address; + tokenVaultA: Address; + tokenVaultB: Address; + tickArrayLower: Address; + tickArrayUpper: Address; + liquidityAmount: IncreaseLiquidityInstructionDataArgs["liquidityAmount"]; + tokenMaxA: IncreaseLiquidityInstructionDataArgs["tokenMaxA"]; + tokenMaxB: IncreaseLiquidityInstructionDataArgs["tokenMaxB"]; +} + +export function getIncreaseLiquidityInstruction< + TAccountWhirlpool extends string, + TAccountTokenProgram extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountTickArrayLower extends string, + TAccountTickArrayUpper extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: IncreaseLiquidityInput< + TAccountWhirlpool, + TAccountTokenProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >, + config?: { programAddress?: TProgramAddress }, +): IncreaseLiquidityInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, + tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tickArrayLower), + getAccountMeta(accounts.tickArrayUpper), + ], + programAddress, + data: getIncreaseLiquidityInstructionDataEncoder().encode( + args as IncreaseLiquidityInstructionDataArgs, + ), + } as IncreaseLiquidityInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >; + + return instruction; +} + +export interface ParsedIncreaseLiquidityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + tokenProgram: TAccountMetas[1]; + positionAuthority: TAccountMetas[2]; + position: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + tokenOwnerAccountA: TAccountMetas[5]; + tokenOwnerAccountB: TAccountMetas[6]; + tokenVaultA: TAccountMetas[7]; + tokenVaultB: TAccountMetas[8]; + tickArrayLower: TAccountMetas[9]; + tickArrayUpper: TAccountMetas[10]; + }; + data: IncreaseLiquidityInstructionData; +} + +export function parseIncreaseLiquidityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedIncreaseLiquidityInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + tokenProgram: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + tickArrayLower: getNextAccount(), + tickArrayUpper: getNextAccount(), + }, + data: getIncreaseLiquidityInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/increaseLiquidityV2.ts b/clients/orca-whirlpools/src/generated/instructions/increaseLiquidityV2.ts new file mode 100644 index 00000000..4e649e90 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/increaseLiquidityV2.ts @@ -0,0 +1,437 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const INCREASE_LIQUIDITY_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([133, 29, 89, 223, 69, 238, 176, 10]); + +export function getIncreaseLiquidityV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INCREASE_LIQUIDITY_V2_DISCRIMINATOR, + ); +} + +export type IncreaseLiquidityV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenProgramA extends string | AccountMeta = string, + TAccountTokenProgramB extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTickArrayLower extends string | AccountMeta = string, + TAccountTickArrayUpper extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenProgramA extends string + ? ReadonlyAccount + : TAccountTokenProgramA, + TAccountTokenProgramB extends string + ? ReadonlyAccount + : TAccountTokenProgramB, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionTokenAccount, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTickArrayLower extends string + ? WritableAccount + : TAccountTickArrayLower, + TAccountTickArrayUpper extends string + ? WritableAccount + : TAccountTickArrayUpper, + ...TRemainingAccounts, + ] + >; + +export interface IncreaseLiquidityV2InstructionData { + discriminator: ReadonlyUint8Array; + liquidityAmount: bigint; + tokenMaxA: bigint; + tokenMaxB: bigint; + remainingAccountsInfo: Option; +} + +export interface IncreaseLiquidityV2InstructionDataArgs { + liquidityAmount: number | bigint; + tokenMaxA: number | bigint; + tokenMaxB: number | bigint; + remainingAccountsInfo: OptionOrNullable; +} + +export function getIncreaseLiquidityV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["liquidityAmount", getU128Encoder()], + ["tokenMaxA", getU64Encoder()], + ["tokenMaxB", getU64Encoder()], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ + ...value, + discriminator: INCREASE_LIQUIDITY_V2_DISCRIMINATOR, + }), + ); +} + +export function getIncreaseLiquidityV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["liquidityAmount", getU128Decoder()], + ["tokenMaxA", getU64Decoder()], + ["tokenMaxB", getU64Decoder()], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getIncreaseLiquidityV2InstructionDataCodec(): Codec< + IncreaseLiquidityV2InstructionDataArgs, + IncreaseLiquidityV2InstructionData +> { + return combineCodec( + getIncreaseLiquidityV2InstructionDataEncoder(), + getIncreaseLiquidityV2InstructionDataDecoder(), + ); +} + +export interface IncreaseLiquidityV2Input< + TAccountWhirlpool extends string = string, + TAccountTokenProgramA extends string = string, + TAccountTokenProgramB extends string = string, + TAccountMemoProgram extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTickArrayLower extends string = string, + TAccountTickArrayUpper extends string = string, +> { + whirlpool: Address; + tokenProgramA: Address; + tokenProgramB: Address; + memoProgram: Address; + positionAuthority: TransactionSigner; + position: Address; + positionTokenAccount: Address; + tokenMintA: Address; + tokenMintB: Address; + tokenOwnerAccountA: Address; + tokenOwnerAccountB: Address; + tokenVaultA: Address; + tokenVaultB: Address; + tickArrayLower: Address; + tickArrayUpper: Address; + liquidityAmount: IncreaseLiquidityV2InstructionDataArgs["liquidityAmount"]; + tokenMaxA: IncreaseLiquidityV2InstructionDataArgs["tokenMaxA"]; + tokenMaxB: IncreaseLiquidityV2InstructionDataArgs["tokenMaxB"]; + remainingAccountsInfo: IncreaseLiquidityV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getIncreaseLiquidityV2Instruction< + TAccountWhirlpool extends string, + TAccountTokenProgramA extends string, + TAccountTokenProgramB extends string, + TAccountMemoProgram extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionTokenAccount extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountTickArrayLower extends string, + TAccountTickArrayUpper extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: IncreaseLiquidityV2Input< + TAccountWhirlpool, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >, + config?: { programAddress?: TProgramAddress }, +): IncreaseLiquidityV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, + tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: false, + }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: true }, + tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenProgramA), + getAccountMeta(accounts.tokenProgramB), + getAccountMeta(accounts.memoProgram), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tickArrayLower), + getAccountMeta(accounts.tickArrayUpper), + ], + programAddress, + data: getIncreaseLiquidityV2InstructionDataEncoder().encode( + args as IncreaseLiquidityV2InstructionDataArgs, + ), + } as IncreaseLiquidityV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionTokenAccount, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountTickArrayLower, + TAccountTickArrayUpper + >; + + return instruction; +} + +export interface ParsedIncreaseLiquidityV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + tokenProgramA: TAccountMetas[1]; + tokenProgramB: TAccountMetas[2]; + memoProgram: TAccountMetas[3]; + positionAuthority: TAccountMetas[4]; + position: TAccountMetas[5]; + positionTokenAccount: TAccountMetas[6]; + tokenMintA: TAccountMetas[7]; + tokenMintB: TAccountMetas[8]; + tokenOwnerAccountA: TAccountMetas[9]; + tokenOwnerAccountB: TAccountMetas[10]; + tokenVaultA: TAccountMetas[11]; + tokenVaultB: TAccountMetas[12]; + tickArrayLower: TAccountMetas[13]; + tickArrayUpper: TAccountMetas[14]; + }; + data: IncreaseLiquidityV2InstructionData; +} + +export function parseIncreaseLiquidityV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedIncreaseLiquidityV2Instruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + tokenProgramA: getNextAccount(), + tokenProgramB: getNextAccount(), + memoProgram: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionTokenAccount: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + tickArrayLower: getNextAccount(), + tickArrayUpper: getNextAccount(), + }, + data: getIncreaseLiquidityV2InstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/index.ts b/clients/orca-whirlpools/src/generated/instructions/index.ts new file mode 100644 index 00000000..88f7d90e --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/index.ts @@ -0,0 +1,57 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./closeBundledPosition.js"; +export * from "./closePosition.js"; +export * from "./closePositionWithTokenExtensions.js"; +export * from "./collectFees.js"; +export * from "./collectFeesV2.js"; +export * from "./collectProtocolFees.js"; +export * from "./collectProtocolFeesV2.js"; +export * from "./collectReward.js"; +export * from "./collectRewardV2.js"; +export * from "./decreaseLiquidity.js"; +export * from "./decreaseLiquidityV2.js"; +export * from "./deletePositionBundle.js"; +export * from "./deleteTokenBadge.js"; +export * from "./increaseLiquidity.js"; +export * from "./increaseLiquidityV2.js"; +export * from "./initializeConfig.js"; +export * from "./initializeConfigExtension.js"; +export * from "./initializeFeeTier.js"; +export * from "./initializePool.js"; +export * from "./initializePoolV2.js"; +export * from "./initializePositionBundle.js"; +export * from "./initializePositionBundleWithMetadata.js"; +export * from "./initializeReward.js"; +export * from "./initializeRewardV2.js"; +export * from "./initializeTickArray.js"; +export * from "./initializeTokenBadge.js"; +export * from "./lockPosition.js"; +export * from "./openBundledPosition.js"; +export * from "./openPosition.js"; +export * from "./openPositionWithMetadata.js"; +export * from "./openPositionWithTokenExtensions.js"; +export * from "./setCollectProtocolFeesAuthority.js"; +export * from "./setConfigExtensionAuthority.js"; +export * from "./setDefaultFeeRate.js"; +export * from "./setDefaultProtocolFeeRate.js"; +export * from "./setFeeAuthority.js"; +export * from "./setFeeRate.js"; +export * from "./setProtocolFeeRate.js"; +export * from "./setRewardAuthority.js"; +export * from "./setRewardAuthorityBySuperAuthority.js"; +export * from "./setRewardEmissions.js"; +export * from "./setRewardEmissionsSuperAuthority.js"; +export * from "./setRewardEmissionsV2.js"; +export * from "./setTokenBadgeAuthority.js"; +export * from "./swap.js"; +export * from "./swapV2.js"; +export * from "./twoHopSwap.js"; +export * from "./twoHopSwapV2.js"; +export * from "./updateFeesAndRewards.js"; diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeConfig.ts b/clients/orca-whirlpools/src/generated/instructions/initializeConfig.ts new file mode 100644 index 00000000..4588ccbf --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeConfig.ts @@ -0,0 +1,234 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([208, 127, 21, 1, 194, 190, 196, 70]); + +export function getInitializeConfigDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_CONFIG_DISCRIMINATOR, + ); +} + +export type InitializeConfigInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountConfig extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountConfig extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountConfig, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializeConfigInstructionData { + discriminator: ReadonlyUint8Array; + feeAuthority: Address; + collectProtocolFeesAuthority: Address; + rewardEmissionsSuperAuthority: Address; + defaultProtocolFeeRate: number; +} + +export interface InitializeConfigInstructionDataArgs { + feeAuthority: Address; + collectProtocolFeesAuthority: Address; + rewardEmissionsSuperAuthority: Address; + defaultProtocolFeeRate: number; +} + +export function getInitializeConfigInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["feeAuthority", getAddressEncoder()], + ["collectProtocolFeesAuthority", getAddressEncoder()], + ["rewardEmissionsSuperAuthority", getAddressEncoder()], + ["defaultProtocolFeeRate", getU16Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_CONFIG_DISCRIMINATOR }), + ); +} + +export function getInitializeConfigInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["feeAuthority", getAddressDecoder()], + ["collectProtocolFeesAuthority", getAddressDecoder()], + ["rewardEmissionsSuperAuthority", getAddressDecoder()], + ["defaultProtocolFeeRate", getU16Decoder()], + ]); +} + +export function getInitializeConfigInstructionDataCodec(): FixedSizeCodec< + InitializeConfigInstructionDataArgs, + InitializeConfigInstructionData +> { + return combineCodec( + getInitializeConfigInstructionDataEncoder(), + getInitializeConfigInstructionDataDecoder(), + ); +} + +export interface InitializeConfigInput< + TAccountConfig extends string = string, + TAccountFunder extends string = string, + TAccountSystemProgram extends string = string, +> { + config: TransactionSigner; + funder: TransactionSigner; + systemProgram: Address; + feeAuthority: InitializeConfigInstructionDataArgs["feeAuthority"]; + collectProtocolFeesAuthority: InitializeConfigInstructionDataArgs["collectProtocolFeesAuthority"]; + rewardEmissionsSuperAuthority: InitializeConfigInstructionDataArgs["rewardEmissionsSuperAuthority"]; + defaultProtocolFeeRate: InitializeConfigInstructionDataArgs["defaultProtocolFeeRate"]; +} + +export function getInitializeConfigInstruction< + TAccountConfig extends string, + TAccountFunder extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeConfigInput< + TAccountConfig, + TAccountFunder, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializeConfigInstruction< + TProgramAddress, + TAccountConfig, + TAccountFunder, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + config: { value: input.config ?? null, isWritable: true }, + funder: { value: input.funder ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.config), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeConfigInstructionDataEncoder().encode( + args as InitializeConfigInstructionDataArgs, + ), + } as InitializeConfigInstruction< + TProgramAddress, + TAccountConfig, + TAccountFunder, + TAccountSystemProgram + >; + + return instruction; +} + +export interface ParsedInitializeConfigInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + config: TAccountMetas[0]; + funder: TAccountMetas[1]; + systemProgram: TAccountMetas[2]; + }; + data: InitializeConfigInstructionData; +} + +export function parseInitializeConfigInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeConfigInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + config: getNextAccount(), + funder: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeConfigInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeConfigExtension.ts b/clients/orca-whirlpools/src/generated/instructions/initializeConfigExtension.ts new file mode 100644 index 00000000..7a137aaa --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeConfigExtension.ts @@ -0,0 +1,237 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_CONFIG_EXTENSION_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([55, 9, 53, 9, 114, 57, 209, 52]); + +export function getInitializeConfigExtensionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_CONFIG_EXTENSION_DISCRIMINATOR, + ); +} + +export type InitializeConfigExtensionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountConfig extends string | AccountMeta = string, + TAccountConfigExtension extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountConfig extends string + ? ReadonlyAccount + : TAccountConfig, + TAccountConfigExtension extends string + ? WritableAccount + : TAccountConfigExtension, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializeConfigExtensionInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface InitializeConfigExtensionInstructionDataArgs {} + +export function getInitializeConfigExtensionInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: INITIALIZE_CONFIG_EXTENSION_DISCRIMINATOR, + }), + ); +} + +export function getInitializeConfigExtensionInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getInitializeConfigExtensionInstructionDataCodec(): FixedSizeCodec< + InitializeConfigExtensionInstructionDataArgs, + InitializeConfigExtensionInstructionData +> { + return combineCodec( + getInitializeConfigExtensionInstructionDataEncoder(), + getInitializeConfigExtensionInstructionDataDecoder(), + ); +} + +export interface InitializeConfigExtensionInput< + TAccountConfig extends string = string, + TAccountConfigExtension extends string = string, + TAccountFunder extends string = string, + TAccountFeeAuthority extends string = string, + TAccountSystemProgram extends string = string, +> { + config: Address; + configExtension: Address; + funder: TransactionSigner; + feeAuthority: TransactionSigner; + systemProgram: Address; +} + +export function getInitializeConfigExtensionInstruction< + TAccountConfig extends string, + TAccountConfigExtension extends string, + TAccountFunder extends string, + TAccountFeeAuthority extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeConfigExtensionInput< + TAccountConfig, + TAccountConfigExtension, + TAccountFunder, + TAccountFeeAuthority, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializeConfigExtensionInstruction< + TProgramAddress, + TAccountConfig, + TAccountConfigExtension, + TAccountFunder, + TAccountFeeAuthority, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + config: { value: input.config ?? null, isWritable: false }, + configExtension: { value: input.configExtension ?? null, isWritable: true }, + funder: { value: input.funder ?? null, isWritable: true }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.config), + getAccountMeta(accounts.configExtension), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.feeAuthority), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeConfigExtensionInstructionDataEncoder().encode({}), + } as InitializeConfigExtensionInstruction< + TProgramAddress, + TAccountConfig, + TAccountConfigExtension, + TAccountFunder, + TAccountFeeAuthority, + TAccountSystemProgram + >; + + return instruction; +} + +export interface ParsedInitializeConfigExtensionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + config: TAccountMetas[0]; + configExtension: TAccountMetas[1]; + funder: TAccountMetas[2]; + feeAuthority: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: InitializeConfigExtensionInstructionData; +} + +export function parseInitializeConfigExtensionInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeConfigExtensionInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + config: getNextAccount(), + configExtension: getNextAccount(), + funder: getNextAccount(), + feeAuthority: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeConfigExtensionInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeFeeTier.ts b/clients/orca-whirlpools/src/generated/instructions/initializeFeeTier.ts new file mode 100644 index 00000000..5ff81ade --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeFeeTier.ts @@ -0,0 +1,252 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_FEE_TIER_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([183, 74, 156, 160, 112, 2, 42, 30]); + +export function getInitializeFeeTierDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_FEE_TIER_DISCRIMINATOR, + ); +} + +export type InitializeFeeTierInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountConfig extends string | AccountMeta = string, + TAccountFeeTier extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountConfig extends string + ? ReadonlyAccount + : TAccountConfig, + TAccountFeeTier extends string + ? WritableAccount + : TAccountFeeTier, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializeFeeTierInstructionData { + discriminator: ReadonlyUint8Array; + tickSpacing: number; + defaultFeeRate: number; +} + +export interface InitializeFeeTierInstructionDataArgs { + tickSpacing: number; + defaultFeeRate: number; +} + +export function getInitializeFeeTierInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["tickSpacing", getU16Encoder()], + ["defaultFeeRate", getU16Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_FEE_TIER_DISCRIMINATOR }), + ); +} + +export function getInitializeFeeTierInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["tickSpacing", getU16Decoder()], + ["defaultFeeRate", getU16Decoder()], + ]); +} + +export function getInitializeFeeTierInstructionDataCodec(): FixedSizeCodec< + InitializeFeeTierInstructionDataArgs, + InitializeFeeTierInstructionData +> { + return combineCodec( + getInitializeFeeTierInstructionDataEncoder(), + getInitializeFeeTierInstructionDataDecoder(), + ); +} + +export interface InitializeFeeTierInput< + TAccountConfig extends string = string, + TAccountFeeTier extends string = string, + TAccountFunder extends string = string, + TAccountFeeAuthority extends string = string, + TAccountSystemProgram extends string = string, +> { + config: Address; + feeTier: Address; + funder: TransactionSigner; + feeAuthority: TransactionSigner; + systemProgram: Address; + tickSpacing: InitializeFeeTierInstructionDataArgs["tickSpacing"]; + defaultFeeRate: InitializeFeeTierInstructionDataArgs["defaultFeeRate"]; +} + +export function getInitializeFeeTierInstruction< + TAccountConfig extends string, + TAccountFeeTier extends string, + TAccountFunder extends string, + TAccountFeeAuthority extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeFeeTierInput< + TAccountConfig, + TAccountFeeTier, + TAccountFunder, + TAccountFeeAuthority, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializeFeeTierInstruction< + TProgramAddress, + TAccountConfig, + TAccountFeeTier, + TAccountFunder, + TAccountFeeAuthority, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + config: { value: input.config ?? null, isWritable: false }, + feeTier: { value: input.feeTier ?? null, isWritable: true }, + funder: { value: input.funder ?? null, isWritable: true }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.config), + getAccountMeta(accounts.feeTier), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.feeAuthority), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeFeeTierInstructionDataEncoder().encode( + args as InitializeFeeTierInstructionDataArgs, + ), + } as InitializeFeeTierInstruction< + TProgramAddress, + TAccountConfig, + TAccountFeeTier, + TAccountFunder, + TAccountFeeAuthority, + TAccountSystemProgram + >; + + return instruction; +} + +export interface ParsedInitializeFeeTierInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + config: TAccountMetas[0]; + feeTier: TAccountMetas[1]; + funder: TAccountMetas[2]; + feeAuthority: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: InitializeFeeTierInstructionData; +} + +export function parseInitializeFeeTierInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeFeeTierInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + config: getNextAccount(), + feeTier: getNextAccount(), + funder: getNextAccount(), + feeAuthority: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeFeeTierInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializePool.ts b/clients/orca-whirlpools/src/generated/instructions/initializePool.ts new file mode 100644 index 00000000..d347b9e0 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializePool.ts @@ -0,0 +1,352 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { WhirlpoolBumps, WhirlpoolBumpsArgs } from "../types/index.js"; +import { + getWhirlpoolBumpsDecoder, + getWhirlpoolBumpsEncoder, +} from "../types/index.js"; + +export const INITIALIZE_POOL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [95, 180, 10, 172, 84, 174, 232, 40], +); + +export function getInitializePoolDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_POOL_DISCRIMINATOR, + ); +} + +export type InitializePoolInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountFeeTier extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenVaultA extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountTokenVaultB, + TAccountFeeTier extends string + ? ReadonlyAccount + : TAccountFeeTier, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + ...TRemainingAccounts, + ] + >; + +export interface InitializePoolInstructionData { + discriminator: ReadonlyUint8Array; + bumps: WhirlpoolBumps; + tickSpacing: number; + initialSqrtPrice: bigint; +} + +export interface InitializePoolInstructionDataArgs { + bumps: WhirlpoolBumpsArgs; + tickSpacing: number; + initialSqrtPrice: number | bigint; +} + +export function getInitializePoolInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bumps", getWhirlpoolBumpsEncoder()], + ["tickSpacing", getU16Encoder()], + ["initialSqrtPrice", getU128Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_POOL_DISCRIMINATOR }), + ); +} + +export function getInitializePoolInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bumps", getWhirlpoolBumpsDecoder()], + ["tickSpacing", getU16Decoder()], + ["initialSqrtPrice", getU128Decoder()], + ]); +} + +export function getInitializePoolInstructionDataCodec(): FixedSizeCodec< + InitializePoolInstructionDataArgs, + InitializePoolInstructionData +> { + return combineCodec( + getInitializePoolInstructionDataEncoder(), + getInitializePoolInstructionDataDecoder(), + ); +} + +export interface InitializePoolInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountFunder extends string = string, + TAccountWhirlpool extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountFeeTier extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + whirlpoolsConfig: Address; + tokenMintA: Address; + tokenMintB: Address; + funder: TransactionSigner; + whirlpool: Address; + tokenVaultA: TransactionSigner; + tokenVaultB: TransactionSigner; + feeTier: Address; + tokenProgram: Address; + systemProgram: Address; + rent: Address; + bumps: InitializePoolInstructionDataArgs["bumps"]; + tickSpacing: InitializePoolInstructionDataArgs["tickSpacing"]; + initialSqrtPrice: InitializePoolInstructionDataArgs["initialSqrtPrice"]; +} + +export function getInitializePoolInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountFunder extends string, + TAccountWhirlpool extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountFeeTier extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializePoolInput< + TAccountWhirlpoolsConfig, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountFunder, + TAccountWhirlpool, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountFeeTier, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): InitializePoolInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountFunder, + TAccountWhirlpool, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountFeeTier, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + funder: { value: input.funder ?? null, isWritable: true }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + feeTier: { value: input.feeTier ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.feeTier), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getInitializePoolInstructionDataEncoder().encode( + args as InitializePoolInstructionDataArgs, + ), + } as InitializePoolInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountFunder, + TAccountWhirlpool, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountFeeTier, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >; + + return instruction; +} + +export interface ParsedInitializePoolInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + tokenMintA: TAccountMetas[1]; + tokenMintB: TAccountMetas[2]; + funder: TAccountMetas[3]; + whirlpool: TAccountMetas[4]; + tokenVaultA: TAccountMetas[5]; + tokenVaultB: TAccountMetas[6]; + feeTier: TAccountMetas[7]; + tokenProgram: TAccountMetas[8]; + systemProgram: TAccountMetas[9]; + rent: TAccountMetas[10]; + }; + data: InitializePoolInstructionData; +} + +export function parseInitializePoolInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializePoolInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + funder: getNextAccount(), + whirlpool: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + feeTier: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + }, + data: getInitializePoolInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializePoolV2.ts b/clients/orca-whirlpools/src/generated/instructions/initializePoolV2.ts new file mode 100644 index 00000000..9b3c1653 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializePoolV2.ts @@ -0,0 +1,383 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_POOL_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([207, 45, 87, 242, 27, 63, 204, 67]); + +export function getInitializePoolV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_POOL_V2_DISCRIMINATOR, + ); +} + +export type InitializePoolV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountTokenBadgeA extends string | AccountMeta = string, + TAccountTokenBadgeB extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountFeeTier extends string | AccountMeta = string, + TAccountTokenProgramA extends string | AccountMeta = string, + TAccountTokenProgramB extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountTokenBadgeA extends string + ? ReadonlyAccount + : TAccountTokenBadgeA, + TAccountTokenBadgeB extends string + ? ReadonlyAccount + : TAccountTokenBadgeB, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenVaultA extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountTokenVaultA, + TAccountTokenVaultB extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountTokenVaultB, + TAccountFeeTier extends string + ? ReadonlyAccount + : TAccountFeeTier, + TAccountTokenProgramA extends string + ? ReadonlyAccount + : TAccountTokenProgramA, + TAccountTokenProgramB extends string + ? ReadonlyAccount + : TAccountTokenProgramB, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + ...TRemainingAccounts, + ] + >; + +export interface InitializePoolV2InstructionData { + discriminator: ReadonlyUint8Array; + tickSpacing: number; + initialSqrtPrice: bigint; +} + +export interface InitializePoolV2InstructionDataArgs { + tickSpacing: number; + initialSqrtPrice: number | bigint; +} + +export function getInitializePoolV2InstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["tickSpacing", getU16Encoder()], + ["initialSqrtPrice", getU128Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_POOL_V2_DISCRIMINATOR }), + ); +} + +export function getInitializePoolV2InstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["tickSpacing", getU16Decoder()], + ["initialSqrtPrice", getU128Decoder()], + ]); +} + +export function getInitializePoolV2InstructionDataCodec(): FixedSizeCodec< + InitializePoolV2InstructionDataArgs, + InitializePoolV2InstructionData +> { + return combineCodec( + getInitializePoolV2InstructionDataEncoder(), + getInitializePoolV2InstructionDataDecoder(), + ); +} + +export interface InitializePoolV2Input< + TAccountWhirlpoolsConfig extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountTokenBadgeA extends string = string, + TAccountTokenBadgeB extends string = string, + TAccountFunder extends string = string, + TAccountWhirlpool extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenVaultB extends string = string, + TAccountFeeTier extends string = string, + TAccountTokenProgramA extends string = string, + TAccountTokenProgramB extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + whirlpoolsConfig: Address; + tokenMintA: Address; + tokenMintB: Address; + tokenBadgeA: Address; + tokenBadgeB: Address; + funder: TransactionSigner; + whirlpool: Address; + tokenVaultA: TransactionSigner; + tokenVaultB: TransactionSigner; + feeTier: Address; + tokenProgramA: Address; + tokenProgramB: Address; + systemProgram: Address; + rent: Address; + tickSpacing: InitializePoolV2InstructionDataArgs["tickSpacing"]; + initialSqrtPrice: InitializePoolV2InstructionDataArgs["initialSqrtPrice"]; +} + +export function getInitializePoolV2Instruction< + TAccountWhirlpoolsConfig extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountTokenBadgeA extends string, + TAccountTokenBadgeB extends string, + TAccountFunder extends string, + TAccountWhirlpool extends string, + TAccountTokenVaultA extends string, + TAccountTokenVaultB extends string, + TAccountFeeTier extends string, + TAccountTokenProgramA extends string, + TAccountTokenProgramB extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializePoolV2Input< + TAccountWhirlpoolsConfig, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenBadgeA, + TAccountTokenBadgeB, + TAccountFunder, + TAccountWhirlpool, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountFeeTier, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): InitializePoolV2Instruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenBadgeA, + TAccountTokenBadgeB, + TAccountFunder, + TAccountWhirlpool, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountFeeTier, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountSystemProgram, + TAccountRent +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + tokenBadgeA: { value: input.tokenBadgeA ?? null, isWritable: false }, + tokenBadgeB: { value: input.tokenBadgeB ?? null, isWritable: false }, + funder: { value: input.funder ?? null, isWritable: true }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + feeTier: { value: input.feeTier ?? null, isWritable: false }, + tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, + tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.tokenBadgeA), + getAccountMeta(accounts.tokenBadgeB), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.feeTier), + getAccountMeta(accounts.tokenProgramA), + getAccountMeta(accounts.tokenProgramB), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getInitializePoolV2InstructionDataEncoder().encode( + args as InitializePoolV2InstructionDataArgs, + ), + } as InitializePoolV2Instruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenBadgeA, + TAccountTokenBadgeB, + TAccountFunder, + TAccountWhirlpool, + TAccountTokenVaultA, + TAccountTokenVaultB, + TAccountFeeTier, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountSystemProgram, + TAccountRent + >; + + return instruction; +} + +export interface ParsedInitializePoolV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + tokenMintA: TAccountMetas[1]; + tokenMintB: TAccountMetas[2]; + tokenBadgeA: TAccountMetas[3]; + tokenBadgeB: TAccountMetas[4]; + funder: TAccountMetas[5]; + whirlpool: TAccountMetas[6]; + tokenVaultA: TAccountMetas[7]; + tokenVaultB: TAccountMetas[8]; + feeTier: TAccountMetas[9]; + tokenProgramA: TAccountMetas[10]; + tokenProgramB: TAccountMetas[11]; + systemProgram: TAccountMetas[12]; + rent: TAccountMetas[13]; + }; + data: InitializePoolV2InstructionData; +} + +export function parseInitializePoolV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializePoolV2Instruction { + if (instruction.accounts.length < 14) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + tokenBadgeA: getNextAccount(), + tokenBadgeB: getNextAccount(), + funder: getNextAccount(), + whirlpool: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenVaultB: getNextAccount(), + feeTier: getNextAccount(), + tokenProgramA: getNextAccount(), + tokenProgramB: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + }, + data: getInitializePoolV2InstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializePositionBundle.ts b/clients/orca-whirlpools/src/generated/instructions/initializePositionBundle.ts new file mode 100644 index 00000000..16451a4a --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializePositionBundle.ts @@ -0,0 +1,304 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_POSITION_BUNDLE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([117, 45, 241, 149, 24, 18, 194, 65]); + +export function getInitializePositionBundleDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_POSITION_BUNDLE_DISCRIMINATOR, + ); +} + +export type InitializePositionBundleInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountPositionBundle extends string | AccountMeta = string, + TAccountPositionBundleMint extends string | AccountMeta = string, + TAccountPositionBundleTokenAccount extends string | AccountMeta = string, + TAccountPositionBundleOwner extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPositionBundle extends string + ? WritableAccount + : TAccountPositionBundle, + TAccountPositionBundleMint extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount extends string + ? WritableAccount + : TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner extends string + ? ReadonlyAccount + : TAccountPositionBundleOwner, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializePositionBundleInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface InitializePositionBundleInstructionDataArgs {} + +export function getInitializePositionBundleInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: INITIALIZE_POSITION_BUNDLE_DISCRIMINATOR, + }), + ); +} + +export function getInitializePositionBundleInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getInitializePositionBundleInstructionDataCodec(): FixedSizeCodec< + InitializePositionBundleInstructionDataArgs, + InitializePositionBundleInstructionData +> { + return combineCodec( + getInitializePositionBundleInstructionDataEncoder(), + getInitializePositionBundleInstructionDataDecoder(), + ); +} + +export interface InitializePositionBundleInput< + TAccountPositionBundle extends string = string, + TAccountPositionBundleMint extends string = string, + TAccountPositionBundleTokenAccount extends string = string, + TAccountPositionBundleOwner extends string = string, + TAccountFunder extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> { + positionBundle: Address; + positionBundleMint: TransactionSigner; + positionBundleTokenAccount: Address; + positionBundleOwner: Address; + funder: TransactionSigner; + tokenProgram: Address; + systemProgram: Address; + rent: Address; + associatedTokenProgram: Address; +} + +export function getInitializePositionBundleInstruction< + TAccountPositionBundle extends string, + TAccountPositionBundleMint extends string, + TAccountPositionBundleTokenAccount extends string, + TAccountPositionBundleOwner extends string, + TAccountFunder extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializePositionBundleInput< + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountFunder, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializePositionBundleInstruction< + TProgramAddress, + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountFunder, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + positionBundle: { value: input.positionBundle ?? null, isWritable: true }, + positionBundleMint: { + value: input.positionBundleMint ?? null, + isWritable: true, + }, + positionBundleTokenAccount: { + value: input.positionBundleTokenAccount ?? null, + isWritable: true, + }, + positionBundleOwner: { + value: input.positionBundleOwner ?? null, + isWritable: false, + }, + funder: { value: input.funder ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.positionBundle), + getAccountMeta(accounts.positionBundleMint), + getAccountMeta(accounts.positionBundleTokenAccount), + getAccountMeta(accounts.positionBundleOwner), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.associatedTokenProgram), + ], + programAddress, + data: getInitializePositionBundleInstructionDataEncoder().encode({}), + } as InitializePositionBundleInstruction< + TProgramAddress, + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountFunder, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram + >; + + return instruction; +} + +export interface ParsedInitializePositionBundleInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + positionBundle: TAccountMetas[0]; + positionBundleMint: TAccountMetas[1]; + positionBundleTokenAccount: TAccountMetas[2]; + positionBundleOwner: TAccountMetas[3]; + funder: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + rent: TAccountMetas[7]; + associatedTokenProgram: TAccountMetas[8]; + }; + data: InitializePositionBundleInstructionData; +} + +export function parseInitializePositionBundleInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializePositionBundleInstruction { + if (instruction.accounts.length < 9) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + positionBundle: getNextAccount(), + positionBundleMint: getNextAccount(), + positionBundleTokenAccount: getNextAccount(), + positionBundleOwner: getNextAccount(), + funder: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getInitializePositionBundleInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializePositionBundleWithMetadata.ts b/clients/orca-whirlpools/src/generated/instructions/initializePositionBundleWithMetadata.ts new file mode 100644 index 00000000..7754c8b2 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializePositionBundleWithMetadata.ts @@ -0,0 +1,360 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_POSITION_BUNDLE_WITH_METADATA_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([93, 124, 16, 179, 249, 131, 115, 245]); + +export function getInitializePositionBundleWithMetadataDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_POSITION_BUNDLE_WITH_METADATA_DISCRIMINATOR, + ); +} + +export type InitializePositionBundleWithMetadataInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountPositionBundle extends string | AccountMeta = string, + TAccountPositionBundleMint extends string | AccountMeta = string, + TAccountPositionBundleMetadata extends string | AccountMeta = string, + TAccountPositionBundleTokenAccount extends string | AccountMeta = string, + TAccountPositionBundleOwner extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountMetadataUpdateAuth extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountMetadataProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPositionBundle extends string + ? WritableAccount + : TAccountPositionBundle, + TAccountPositionBundleMint extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPositionBundleMint, + TAccountPositionBundleMetadata extends string + ? WritableAccount + : TAccountPositionBundleMetadata, + TAccountPositionBundleTokenAccount extends string + ? WritableAccount + : TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner extends string + ? ReadonlyAccount + : TAccountPositionBundleOwner, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountMetadataUpdateAuth extends string + ? ReadonlyAccount + : TAccountMetadataUpdateAuth, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountMetadataProgram extends string + ? ReadonlyAccount + : TAccountMetadataProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializePositionBundleWithMetadataInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface InitializePositionBundleWithMetadataInstructionDataArgs {} + +export function getInitializePositionBundleWithMetadataInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: INITIALIZE_POSITION_BUNDLE_WITH_METADATA_DISCRIMINATOR, + }), + ); +} + +export function getInitializePositionBundleWithMetadataInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getInitializePositionBundleWithMetadataInstructionDataCodec(): FixedSizeCodec< + InitializePositionBundleWithMetadataInstructionDataArgs, + InitializePositionBundleWithMetadataInstructionData +> { + return combineCodec( + getInitializePositionBundleWithMetadataInstructionDataEncoder(), + getInitializePositionBundleWithMetadataInstructionDataDecoder(), + ); +} + +export interface InitializePositionBundleWithMetadataInput< + TAccountPositionBundle extends string = string, + TAccountPositionBundleMint extends string = string, + TAccountPositionBundleMetadata extends string = string, + TAccountPositionBundleTokenAccount extends string = string, + TAccountPositionBundleOwner extends string = string, + TAccountFunder extends string = string, + TAccountMetadataUpdateAuth extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountMetadataProgram extends string = string, +> { + positionBundle: Address; + positionBundleMint: TransactionSigner; + positionBundleMetadata: Address; + positionBundleTokenAccount: Address; + positionBundleOwner: Address; + funder: TransactionSigner; + metadataUpdateAuth: Address; + tokenProgram: Address; + systemProgram: Address; + rent: Address; + associatedTokenProgram: Address; + metadataProgram: Address; +} + +export function getInitializePositionBundleWithMetadataInstruction< + TAccountPositionBundle extends string, + TAccountPositionBundleMint extends string, + TAccountPositionBundleMetadata extends string, + TAccountPositionBundleTokenAccount extends string, + TAccountPositionBundleOwner extends string, + TAccountFunder extends string, + TAccountMetadataUpdateAuth extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TAccountAssociatedTokenProgram extends string, + TAccountMetadataProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializePositionBundleWithMetadataInput< + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleMetadata, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountFunder, + TAccountMetadataUpdateAuth, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializePositionBundleWithMetadataInstruction< + TProgramAddress, + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleMetadata, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountFunder, + TAccountMetadataUpdateAuth, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + positionBundle: { value: input.positionBundle ?? null, isWritable: true }, + positionBundleMint: { + value: input.positionBundleMint ?? null, + isWritable: true, + }, + positionBundleMetadata: { + value: input.positionBundleMetadata ?? null, + isWritable: true, + }, + positionBundleTokenAccount: { + value: input.positionBundleTokenAccount ?? null, + isWritable: true, + }, + positionBundleOwner: { + value: input.positionBundleOwner ?? null, + isWritable: false, + }, + funder: { value: input.funder ?? null, isWritable: true }, + metadataUpdateAuth: { + value: input.metadataUpdateAuth ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.positionBundle), + getAccountMeta(accounts.positionBundleMint), + getAccountMeta(accounts.positionBundleMetadata), + getAccountMeta(accounts.positionBundleTokenAccount), + getAccountMeta(accounts.positionBundleOwner), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.metadataUpdateAuth), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.metadataProgram), + ], + programAddress, + data: getInitializePositionBundleWithMetadataInstructionDataEncoder().encode( + {}, + ), + } as InitializePositionBundleWithMetadataInstruction< + TProgramAddress, + TAccountPositionBundle, + TAccountPositionBundleMint, + TAccountPositionBundleMetadata, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleOwner, + TAccountFunder, + TAccountMetadataUpdateAuth, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram + >; + + return instruction; +} + +export interface ParsedInitializePositionBundleWithMetadataInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + positionBundle: TAccountMetas[0]; + positionBundleMint: TAccountMetas[1]; + positionBundleMetadata: TAccountMetas[2]; + positionBundleTokenAccount: TAccountMetas[3]; + positionBundleOwner: TAccountMetas[4]; + funder: TAccountMetas[5]; + metadataUpdateAuth: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + systemProgram: TAccountMetas[8]; + rent: TAccountMetas[9]; + associatedTokenProgram: TAccountMetas[10]; + metadataProgram: TAccountMetas[11]; + }; + data: InitializePositionBundleWithMetadataInstructionData; +} + +export function parseInitializePositionBundleWithMetadataInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializePositionBundleWithMetadataInstruction< + TProgram, + TAccountMetas +> { + if (instruction.accounts.length < 12) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + positionBundle: getNextAccount(), + positionBundleMint: getNextAccount(), + positionBundleMetadata: getNextAccount(), + positionBundleTokenAccount: getNextAccount(), + positionBundleOwner: getNextAccount(), + funder: getNextAccount(), + metadataUpdateAuth: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + associatedTokenProgram: getNextAccount(), + metadataProgram: getNextAccount(), + }, + data: getInitializePositionBundleWithMetadataInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeReward.ts b/clients/orca-whirlpools/src/generated/instructions/initializeReward.ts new file mode 100644 index 00000000..81698bd1 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeReward.ts @@ -0,0 +1,293 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_REWARD_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([95, 135, 192, 196, 242, 129, 230, 68]); + +export function getInitializeRewardDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_REWARD_DISCRIMINATOR, + ); +} + +export type InitializeRewardInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountRewardAuthority extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountRewardMint extends string | AccountMeta = string, + TAccountRewardVault extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountRewardAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardAuthority, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountRewardMint extends string + ? ReadonlyAccount + : TAccountRewardMint, + TAccountRewardVault extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountRewardVault, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + ...TRemainingAccounts, + ] + >; + +export interface InitializeRewardInstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; +} + +export interface InitializeRewardInstructionDataArgs { + rewardIndex: number; +} + +export function getInitializeRewardInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: INITIALIZE_REWARD_DISCRIMINATOR }), + ); +} + +export function getInitializeRewardInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ]); +} + +export function getInitializeRewardInstructionDataCodec(): FixedSizeCodec< + InitializeRewardInstructionDataArgs, + InitializeRewardInstructionData +> { + return combineCodec( + getInitializeRewardInstructionDataEncoder(), + getInitializeRewardInstructionDataDecoder(), + ); +} + +export interface InitializeRewardInput< + TAccountRewardAuthority extends string = string, + TAccountFunder extends string = string, + TAccountWhirlpool extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardVault extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + rewardAuthority: TransactionSigner; + funder: TransactionSigner; + whirlpool: Address; + rewardMint: Address; + rewardVault: TransactionSigner; + tokenProgram: Address; + systemProgram: Address; + rent: Address; + rewardIndex: InitializeRewardInstructionDataArgs["rewardIndex"]; +} + +export function getInitializeRewardInstruction< + TAccountRewardAuthority extends string, + TAccountFunder extends string, + TAccountWhirlpool extends string, + TAccountRewardMint extends string, + TAccountRewardVault extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeRewardInput< + TAccountRewardAuthority, + TAccountFunder, + TAccountWhirlpool, + TAccountRewardMint, + TAccountRewardVault, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): InitializeRewardInstruction< + TProgramAddress, + TAccountRewardAuthority, + TAccountFunder, + TAccountWhirlpool, + TAccountRewardMint, + TAccountRewardVault, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + rewardAuthority: { + value: input.rewardAuthority ?? null, + isWritable: false, + }, + funder: { value: input.funder ?? null, isWritable: true }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.rewardAuthority), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getInitializeRewardInstructionDataEncoder().encode( + args as InitializeRewardInstructionDataArgs, + ), + } as InitializeRewardInstruction< + TProgramAddress, + TAccountRewardAuthority, + TAccountFunder, + TAccountWhirlpool, + TAccountRewardMint, + TAccountRewardVault, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >; + + return instruction; +} + +export interface ParsedInitializeRewardInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + rewardAuthority: TAccountMetas[0]; + funder: TAccountMetas[1]; + whirlpool: TAccountMetas[2]; + rewardMint: TAccountMetas[3]; + rewardVault: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + rent: TAccountMetas[7]; + }; + data: InitializeRewardInstructionData; +} + +export function parseInitializeRewardInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeRewardInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + rewardAuthority: getNextAccount(), + funder: getNextAccount(), + whirlpool: getNextAccount(), + rewardMint: getNextAccount(), + rewardVault: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + }, + data: getInitializeRewardInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeRewardV2.ts b/clients/orca-whirlpools/src/generated/instructions/initializeRewardV2.ts new file mode 100644 index 00000000..fd5f8fcc --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeRewardV2.ts @@ -0,0 +1,318 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_REWARD_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([91, 1, 77, 50, 235, 229, 133, 49]); + +export function getInitializeRewardV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_REWARD_V2_DISCRIMINATOR, + ); +} + +export type InitializeRewardV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountRewardAuthority extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountRewardMint extends string | AccountMeta = string, + TAccountRewardTokenBadge extends string | AccountMeta = string, + TAccountRewardVault extends string | AccountMeta = string, + TAccountRewardTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountRewardAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardAuthority, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountRewardMint extends string + ? ReadonlyAccount + : TAccountRewardMint, + TAccountRewardTokenBadge extends string + ? ReadonlyAccount + : TAccountRewardTokenBadge, + TAccountRewardVault extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountRewardVault, + TAccountRewardTokenProgram extends string + ? ReadonlyAccount + : TAccountRewardTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + ...TRemainingAccounts, + ] + >; + +export interface InitializeRewardV2InstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; +} + +export interface InitializeRewardV2InstructionDataArgs { + rewardIndex: number; +} + +export function getInitializeRewardV2InstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_REWARD_V2_DISCRIMINATOR, + }), + ); +} + +export function getInitializeRewardV2InstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ]); +} + +export function getInitializeRewardV2InstructionDataCodec(): FixedSizeCodec< + InitializeRewardV2InstructionDataArgs, + InitializeRewardV2InstructionData +> { + return combineCodec( + getInitializeRewardV2InstructionDataEncoder(), + getInitializeRewardV2InstructionDataDecoder(), + ); +} + +export interface InitializeRewardV2Input< + TAccountRewardAuthority extends string = string, + TAccountFunder extends string = string, + TAccountWhirlpool extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardTokenBadge extends string = string, + TAccountRewardVault extends string = string, + TAccountRewardTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + rewardAuthority: TransactionSigner; + funder: TransactionSigner; + whirlpool: Address; + rewardMint: Address; + rewardTokenBadge: Address; + rewardVault: TransactionSigner; + rewardTokenProgram: Address; + systemProgram: Address; + rent: Address; + rewardIndex: InitializeRewardV2InstructionDataArgs["rewardIndex"]; +} + +export function getInitializeRewardV2Instruction< + TAccountRewardAuthority extends string, + TAccountFunder extends string, + TAccountWhirlpool extends string, + TAccountRewardMint extends string, + TAccountRewardTokenBadge extends string, + TAccountRewardVault extends string, + TAccountRewardTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeRewardV2Input< + TAccountRewardAuthority, + TAccountFunder, + TAccountWhirlpool, + TAccountRewardMint, + TAccountRewardTokenBadge, + TAccountRewardVault, + TAccountRewardTokenProgram, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): InitializeRewardV2Instruction< + TProgramAddress, + TAccountRewardAuthority, + TAccountFunder, + TAccountWhirlpool, + TAccountRewardMint, + TAccountRewardTokenBadge, + TAccountRewardVault, + TAccountRewardTokenProgram, + TAccountSystemProgram, + TAccountRent +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + rewardAuthority: { + value: input.rewardAuthority ?? null, + isWritable: false, + }, + funder: { value: input.funder ?? null, isWritable: true }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardTokenBadge: { + value: input.rewardTokenBadge ?? null, + isWritable: false, + }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + rewardTokenProgram: { + value: input.rewardTokenProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.rewardAuthority), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardTokenBadge), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.rewardTokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getInitializeRewardV2InstructionDataEncoder().encode( + args as InitializeRewardV2InstructionDataArgs, + ), + } as InitializeRewardV2Instruction< + TProgramAddress, + TAccountRewardAuthority, + TAccountFunder, + TAccountWhirlpool, + TAccountRewardMint, + TAccountRewardTokenBadge, + TAccountRewardVault, + TAccountRewardTokenProgram, + TAccountSystemProgram, + TAccountRent + >; + + return instruction; +} + +export interface ParsedInitializeRewardV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + rewardAuthority: TAccountMetas[0]; + funder: TAccountMetas[1]; + whirlpool: TAccountMetas[2]; + rewardMint: TAccountMetas[3]; + rewardTokenBadge: TAccountMetas[4]; + rewardVault: TAccountMetas[5]; + rewardTokenProgram: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + rent: TAccountMetas[8]; + }; + data: InitializeRewardV2InstructionData; +} + +export function parseInitializeRewardV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeRewardV2Instruction { + if (instruction.accounts.length < 9) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + rewardAuthority: getNextAccount(), + funder: getNextAccount(), + whirlpool: getNextAccount(), + rewardMint: getNextAccount(), + rewardTokenBadge: getNextAccount(), + rewardVault: getNextAccount(), + rewardTokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + }, + data: getInitializeRewardV2InstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeTickArray.ts b/clients/orca-whirlpools/src/generated/instructions/initializeTickArray.ts new file mode 100644 index 00000000..3c1cfcdc --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeTickArray.ts @@ -0,0 +1,236 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_TICK_ARRAY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([11, 188, 193, 214, 141, 91, 149, 184]); + +export function getInitializeTickArrayDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_TICK_ARRAY_DISCRIMINATOR, + ); +} + +export type InitializeTickArrayInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountTickArray extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountTickArray extends string + ? WritableAccount + : TAccountTickArray, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializeTickArrayInstructionData { + discriminator: ReadonlyUint8Array; + startTickIndex: number; +} + +export interface InitializeTickArrayInstructionDataArgs { + startTickIndex: number; +} + +export function getInitializeTickArrayInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["startTickIndex", getI32Encoder()], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_TICK_ARRAY_DISCRIMINATOR, + }), + ); +} + +export function getInitializeTickArrayInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["startTickIndex", getI32Decoder()], + ]); +} + +export function getInitializeTickArrayInstructionDataCodec(): FixedSizeCodec< + InitializeTickArrayInstructionDataArgs, + InitializeTickArrayInstructionData +> { + return combineCodec( + getInitializeTickArrayInstructionDataEncoder(), + getInitializeTickArrayInstructionDataDecoder(), + ); +} + +export interface InitializeTickArrayInput< + TAccountWhirlpool extends string = string, + TAccountFunder extends string = string, + TAccountTickArray extends string = string, + TAccountSystemProgram extends string = string, +> { + whirlpool: Address; + funder: TransactionSigner; + tickArray: Address; + systemProgram: Address; + startTickIndex: InitializeTickArrayInstructionDataArgs["startTickIndex"]; +} + +export function getInitializeTickArrayInstruction< + TAccountWhirlpool extends string, + TAccountFunder extends string, + TAccountTickArray extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeTickArrayInput< + TAccountWhirlpool, + TAccountFunder, + TAccountTickArray, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializeTickArrayInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountFunder, + TAccountTickArray, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + funder: { value: input.funder ?? null, isWritable: true }, + tickArray: { value: input.tickArray ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.tickArray), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeTickArrayInstructionDataEncoder().encode( + args as InitializeTickArrayInstructionDataArgs, + ), + } as InitializeTickArrayInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountFunder, + TAccountTickArray, + TAccountSystemProgram + >; + + return instruction; +} + +export interface ParsedInitializeTickArrayInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + funder: TAccountMetas[1]; + tickArray: TAccountMetas[2]; + systemProgram: TAccountMetas[3]; + }; + data: InitializeTickArrayInstructionData; +} + +export function parseInitializeTickArrayInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeTickArrayInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + funder: getNextAccount(), + tickArray: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeTickArrayInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/initializeTokenBadge.ts b/clients/orca-whirlpools/src/generated/instructions/initializeTokenBadge.ts new file mode 100644 index 00000000..a329fed2 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/initializeTokenBadge.ts @@ -0,0 +1,274 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INITIALIZE_TOKEN_BADGE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([253, 77, 205, 95, 27, 224, 89, 223]); + +export function getInitializeTokenBadgeDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INITIALIZE_TOKEN_BADGE_DISCRIMINATOR, + ); +} + +export type InitializeTokenBadgeInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpoolsConfigExtension extends string | AccountMeta = string, + TAccountTokenBadgeAuthority extends string | AccountMeta = string, + TAccountTokenMint extends string | AccountMeta = string, + TAccountTokenBadge extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountTokenBadgeAuthority, + TAccountTokenMint extends string + ? ReadonlyAccount + : TAccountTokenMint, + TAccountTokenBadge extends string + ? WritableAccount + : TAccountTokenBadge, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface InitializeTokenBadgeInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface InitializeTokenBadgeInstructionDataArgs {} + +export function getInitializeTokenBadgeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: INITIALIZE_TOKEN_BADGE_DISCRIMINATOR, + }), + ); +} + +export function getInitializeTokenBadgeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getInitializeTokenBadgeInstructionDataCodec(): FixedSizeCodec< + InitializeTokenBadgeInstructionDataArgs, + InitializeTokenBadgeInstructionData +> { + return combineCodec( + getInitializeTokenBadgeInstructionDataEncoder(), + getInitializeTokenBadgeInstructionDataDecoder(), + ); +} + +export interface InitializeTokenBadgeInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpoolsConfigExtension extends string = string, + TAccountTokenBadgeAuthority extends string = string, + TAccountTokenMint extends string = string, + TAccountTokenBadge extends string = string, + TAccountFunder extends string = string, + TAccountSystemProgram extends string = string, +> { + whirlpoolsConfig: Address; + whirlpoolsConfigExtension: Address; + tokenBadgeAuthority: TransactionSigner; + tokenMint: Address; + tokenBadge: Address; + funder: TransactionSigner; + systemProgram: Address; +} + +export function getInitializeTokenBadgeInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpoolsConfigExtension extends string, + TAccountTokenBadgeAuthority extends string, + TAccountTokenMint extends string, + TAccountTokenBadge extends string, + TAccountFunder extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: InitializeTokenBadgeInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority, + TAccountTokenMint, + TAccountTokenBadge, + TAccountFunder, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): InitializeTokenBadgeInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority, + TAccountTokenMint, + TAccountTokenBadge, + TAccountFunder, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpoolsConfigExtension: { + value: input.whirlpoolsConfigExtension ?? null, + isWritable: false, + }, + tokenBadgeAuthority: { + value: input.tokenBadgeAuthority ?? null, + isWritable: false, + }, + tokenMint: { value: input.tokenMint ?? null, isWritable: false }, + tokenBadge: { value: input.tokenBadge ?? null, isWritable: true }, + funder: { value: input.funder ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpoolsConfigExtension), + getAccountMeta(accounts.tokenBadgeAuthority), + getAccountMeta(accounts.tokenMint), + getAccountMeta(accounts.tokenBadge), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getInitializeTokenBadgeInstructionDataEncoder().encode({}), + } as InitializeTokenBadgeInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountTokenBadgeAuthority, + TAccountTokenMint, + TAccountTokenBadge, + TAccountFunder, + TAccountSystemProgram + >; + + return instruction; +} + +export interface ParsedInitializeTokenBadgeInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpoolsConfigExtension: TAccountMetas[1]; + tokenBadgeAuthority: TAccountMetas[2]; + tokenMint: TAccountMetas[3]; + tokenBadge: TAccountMetas[4]; + funder: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + }; + data: InitializeTokenBadgeInstructionData; +} + +export function parseInitializeTokenBadgeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitializeTokenBadgeInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpoolsConfigExtension: getNextAccount(), + tokenBadgeAuthority: getNextAccount(), + tokenMint: getNextAccount(), + tokenBadge: getNextAccount(), + funder: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getInitializeTokenBadgeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/lockPosition.ts b/clients/orca-whirlpools/src/generated/instructions/lockPosition.ts new file mode 100644 index 00000000..3e32ab74 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/lockPosition.ts @@ -0,0 +1,313 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { LockType, LockTypeArgs } from "../types/index.js"; +import { getLockTypeDecoder, getLockTypeEncoder } from "../types/index.js"; + +export const LOCK_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 227, 62, 2, 252, 247, 10, 171, 185, +]); + +export function getLockPositionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + LOCK_POSITION_DISCRIMINATOR, + ); +} + +export type LockPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountFunder extends string | AccountMeta = string, + TAccountPositionAuthority extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionMint extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountLockConfig extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountToken2022Program extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountPositionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionAuthority, + TAccountPosition extends string + ? ReadonlyAccount + : TAccountPosition, + TAccountPositionMint extends string + ? ReadonlyAccount + : TAccountPositionMint, + TAccountPositionTokenAccount extends string + ? WritableAccount + : TAccountPositionTokenAccount, + TAccountLockConfig extends string + ? WritableAccount + : TAccountLockConfig, + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountToken2022Program extends string + ? ReadonlyAccount + : TAccountToken2022Program, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface LockPositionInstructionData { + discriminator: ReadonlyUint8Array; + lockType: LockType; +} + +export interface LockPositionInstructionDataArgs { + lockType: LockTypeArgs; +} + +export function getLockPositionInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["lockType", getLockTypeEncoder()], + ]), + (value) => ({ ...value, discriminator: LOCK_POSITION_DISCRIMINATOR }), + ); +} + +export function getLockPositionInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["lockType", getLockTypeDecoder()], + ]); +} + +export function getLockPositionInstructionDataCodec(): FixedSizeCodec< + LockPositionInstructionDataArgs, + LockPositionInstructionData +> { + return combineCodec( + getLockPositionInstructionDataEncoder(), + getLockPositionInstructionDataDecoder(), + ); +} + +export interface LockPositionInput< + TAccountFunder extends string = string, + TAccountPositionAuthority extends string = string, + TAccountPosition extends string = string, + TAccountPositionMint extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountLockConfig extends string = string, + TAccountWhirlpool extends string = string, + TAccountToken2022Program extends string = string, + TAccountSystemProgram extends string = string, +> { + funder: TransactionSigner; + positionAuthority: TransactionSigner; + position: Address; + positionMint: Address; + positionTokenAccount: Address; + lockConfig: Address; + whirlpool: Address; + token2022Program: Address; + systemProgram: Address; + lockType: LockPositionInstructionDataArgs["lockType"]; +} + +export function getLockPositionInstruction< + TAccountFunder extends string, + TAccountPositionAuthority extends string, + TAccountPosition extends string, + TAccountPositionMint extends string, + TAccountPositionTokenAccount extends string, + TAccountLockConfig extends string, + TAccountWhirlpool extends string, + TAccountToken2022Program extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: LockPositionInput< + TAccountFunder, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountLockConfig, + TAccountWhirlpool, + TAccountToken2022Program, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): LockPositionInstruction< + TProgramAddress, + TAccountFunder, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountLockConfig, + TAccountWhirlpool, + TAccountToken2022Program, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + funder: { value: input.funder ?? null, isWritable: true }, + positionAuthority: { + value: input.positionAuthority ?? null, + isWritable: false, + }, + position: { value: input.position ?? null, isWritable: false }, + positionMint: { value: input.positionMint ?? null, isWritable: false }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: true, + }, + lockConfig: { value: input.lockConfig ?? null, isWritable: true }, + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + token2022Program: { + value: input.token2022Program ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.funder), + getAccountMeta(accounts.positionAuthority), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionMint), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.lockConfig), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.token2022Program), + getAccountMeta(accounts.systemProgram), + ], + programAddress, + data: getLockPositionInstructionDataEncoder().encode( + args as LockPositionInstructionDataArgs, + ), + } as LockPositionInstruction< + TProgramAddress, + TAccountFunder, + TAccountPositionAuthority, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountLockConfig, + TAccountWhirlpool, + TAccountToken2022Program, + TAccountSystemProgram + >; + + return instruction; +} + +export interface ParsedLockPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + funder: TAccountMetas[0]; + positionAuthority: TAccountMetas[1]; + position: TAccountMetas[2]; + positionMint: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + lockConfig: TAccountMetas[5]; + whirlpool: TAccountMetas[6]; + token2022Program: TAccountMetas[7]; + systemProgram: TAccountMetas[8]; + }; + data: LockPositionInstructionData; +} + +export function parseLockPositionInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedLockPositionInstruction { + if (instruction.accounts.length < 9) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + funder: getNextAccount(), + positionAuthority: getNextAccount(), + position: getNextAccount(), + positionMint: getNextAccount(), + positionTokenAccount: getNextAccount(), + lockConfig: getNextAccount(), + whirlpool: getNextAccount(), + token2022Program: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getLockPositionInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/openBundledPosition.ts b/clients/orca-whirlpools/src/generated/instructions/openBundledPosition.ts new file mode 100644 index 00000000..ebe043c4 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/openBundledPosition.ts @@ -0,0 +1,312 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const OPEN_BUNDLED_POSITION_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([169, 113, 126, 171, 213, 172, 212, 49]); + +export function getOpenBundledPositionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + OPEN_BUNDLED_POSITION_DISCRIMINATOR, + ); +} + +export type OpenBundledPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountBundledPosition extends string | AccountMeta = string, + TAccountPositionBundle extends string | AccountMeta = string, + TAccountPositionBundleTokenAccount extends string | AccountMeta = string, + TAccountPositionBundleAuthority extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountFunder extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBundledPosition extends string + ? WritableAccount + : TAccountBundledPosition, + TAccountPositionBundle extends string + ? WritableAccount + : TAccountPositionBundle, + TAccountPositionBundleTokenAccount extends string + ? ReadonlyAccount + : TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPositionBundleAuthority, + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + ...TRemainingAccounts, + ] + >; + +export interface OpenBundledPositionInstructionData { + discriminator: ReadonlyUint8Array; + bundleIndex: number; + tickLowerIndex: number; + tickUpperIndex: number; +} + +export interface OpenBundledPositionInstructionDataArgs { + bundleIndex: number; + tickLowerIndex: number; + tickUpperIndex: number; +} + +export function getOpenBundledPositionInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bundleIndex", getU16Encoder()], + ["tickLowerIndex", getI32Encoder()], + ["tickUpperIndex", getI32Encoder()], + ]), + (value) => ({ + ...value, + discriminator: OPEN_BUNDLED_POSITION_DISCRIMINATOR, + }), + ); +} + +export function getOpenBundledPositionInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bundleIndex", getU16Decoder()], + ["tickLowerIndex", getI32Decoder()], + ["tickUpperIndex", getI32Decoder()], + ]); +} + +export function getOpenBundledPositionInstructionDataCodec(): FixedSizeCodec< + OpenBundledPositionInstructionDataArgs, + OpenBundledPositionInstructionData +> { + return combineCodec( + getOpenBundledPositionInstructionDataEncoder(), + getOpenBundledPositionInstructionDataDecoder(), + ); +} + +export interface OpenBundledPositionInput< + TAccountBundledPosition extends string = string, + TAccountPositionBundle extends string = string, + TAccountPositionBundleTokenAccount extends string = string, + TAccountPositionBundleAuthority extends string = string, + TAccountWhirlpool extends string = string, + TAccountFunder extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + bundledPosition: Address; + positionBundle: Address; + positionBundleTokenAccount: Address; + positionBundleAuthority: TransactionSigner; + whirlpool: Address; + funder: TransactionSigner; + systemProgram: Address; + rent: Address; + bundleIndex: OpenBundledPositionInstructionDataArgs["bundleIndex"]; + tickLowerIndex: OpenBundledPositionInstructionDataArgs["tickLowerIndex"]; + tickUpperIndex: OpenBundledPositionInstructionDataArgs["tickUpperIndex"]; +} + +export function getOpenBundledPositionInstruction< + TAccountBundledPosition extends string, + TAccountPositionBundle extends string, + TAccountPositionBundleTokenAccount extends string, + TAccountPositionBundleAuthority extends string, + TAccountWhirlpool extends string, + TAccountFunder extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: OpenBundledPositionInput< + TAccountBundledPosition, + TAccountPositionBundle, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority, + TAccountWhirlpool, + TAccountFunder, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): OpenBundledPositionInstruction< + TProgramAddress, + TAccountBundledPosition, + TAccountPositionBundle, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority, + TAccountWhirlpool, + TAccountFunder, + TAccountSystemProgram, + TAccountRent +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + bundledPosition: { value: input.bundledPosition ?? null, isWritable: true }, + positionBundle: { value: input.positionBundle ?? null, isWritable: true }, + positionBundleTokenAccount: { + value: input.positionBundleTokenAccount ?? null, + isWritable: false, + }, + positionBundleAuthority: { + value: input.positionBundleAuthority ?? null, + isWritable: false, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + funder: { value: input.funder ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.bundledPosition), + getAccountMeta(accounts.positionBundle), + getAccountMeta(accounts.positionBundleTokenAccount), + getAccountMeta(accounts.positionBundleAuthority), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.funder), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + programAddress, + data: getOpenBundledPositionInstructionDataEncoder().encode( + args as OpenBundledPositionInstructionDataArgs, + ), + } as OpenBundledPositionInstruction< + TProgramAddress, + TAccountBundledPosition, + TAccountPositionBundle, + TAccountPositionBundleTokenAccount, + TAccountPositionBundleAuthority, + TAccountWhirlpool, + TAccountFunder, + TAccountSystemProgram, + TAccountRent + >; + + return instruction; +} + +export interface ParsedOpenBundledPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + bundledPosition: TAccountMetas[0]; + positionBundle: TAccountMetas[1]; + positionBundleTokenAccount: TAccountMetas[2]; + positionBundleAuthority: TAccountMetas[3]; + whirlpool: TAccountMetas[4]; + funder: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + rent: TAccountMetas[7]; + }; + data: OpenBundledPositionInstructionData; +} + +export function parseOpenBundledPositionInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedOpenBundledPositionInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + bundledPosition: getNextAccount(), + positionBundle: getNextAccount(), + positionBundleTokenAccount: getNextAccount(), + positionBundleAuthority: getNextAccount(), + whirlpool: getNextAccount(), + funder: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + }, + data: getOpenBundledPositionInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/openPosition.ts b/clients/orca-whirlpools/src/generated/instructions/openPosition.ts new file mode 100644 index 00000000..3b2388d6 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/openPosition.ts @@ -0,0 +1,341 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + OpenPositionBumps, + OpenPositionBumpsArgs, +} from "../types/index.js"; +import { + getOpenPositionBumpsDecoder, + getOpenPositionBumpsEncoder, +} from "../types/index.js"; + +export const OPEN_POSITION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 135, 128, 47, 77, 15, 152, 240, 49, +]); + +export function getOpenPositionDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + OPEN_POSITION_DISCRIMINATOR, + ); +} + +export type OpenPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountFunder extends string | AccountMeta = string, + TAccountOwner extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionMint extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountOwner extends string + ? ReadonlyAccount + : TAccountOwner, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionMint extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPositionMint, + TAccountPositionTokenAccount extends string + ? WritableAccount + : TAccountPositionTokenAccount, + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface OpenPositionInstructionData { + discriminator: ReadonlyUint8Array; + bumps: OpenPositionBumps; + tickLowerIndex: number; + tickUpperIndex: number; +} + +export interface OpenPositionInstructionDataArgs { + bumps: OpenPositionBumpsArgs; + tickLowerIndex: number; + tickUpperIndex: number; +} + +export function getOpenPositionInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bumps", getOpenPositionBumpsEncoder()], + ["tickLowerIndex", getI32Encoder()], + ["tickUpperIndex", getI32Encoder()], + ]), + (value) => ({ ...value, discriminator: OPEN_POSITION_DISCRIMINATOR }), + ); +} + +export function getOpenPositionInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bumps", getOpenPositionBumpsDecoder()], + ["tickLowerIndex", getI32Decoder()], + ["tickUpperIndex", getI32Decoder()], + ]); +} + +export function getOpenPositionInstructionDataCodec(): FixedSizeCodec< + OpenPositionInstructionDataArgs, + OpenPositionInstructionData +> { + return combineCodec( + getOpenPositionInstructionDataEncoder(), + getOpenPositionInstructionDataDecoder(), + ); +} + +export interface OpenPositionInput< + TAccountFunder extends string = string, + TAccountOwner extends string = string, + TAccountPosition extends string = string, + TAccountPositionMint extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountWhirlpool extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountAssociatedTokenProgram extends string = string, +> { + funder: TransactionSigner; + owner: Address; + position: Address; + positionMint: TransactionSigner; + positionTokenAccount: Address; + whirlpool: Address; + tokenProgram: Address; + systemProgram: Address; + rent: Address; + associatedTokenProgram: Address; + bumps: OpenPositionInstructionDataArgs["bumps"]; + tickLowerIndex: OpenPositionInstructionDataArgs["tickLowerIndex"]; + tickUpperIndex: OpenPositionInstructionDataArgs["tickUpperIndex"]; +} + +export function getOpenPositionInstruction< + TAccountFunder extends string, + TAccountOwner extends string, + TAccountPosition extends string, + TAccountPositionMint extends string, + TAccountPositionTokenAccount extends string, + TAccountWhirlpool extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TAccountAssociatedTokenProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: OpenPositionInput< + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): OpenPositionInstruction< + TProgramAddress, + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + funder: { value: input.funder ?? null, isWritable: true }, + owner: { value: input.owner ?? null, isWritable: false }, + position: { value: input.position ?? null, isWritable: true }, + positionMint: { value: input.positionMint ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: true, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.funder), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionMint), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.associatedTokenProgram), + ], + programAddress, + data: getOpenPositionInstructionDataEncoder().encode( + args as OpenPositionInstructionDataArgs, + ), + } as OpenPositionInstruction< + TProgramAddress, + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram + >; + + return instruction; +} + +export interface ParsedOpenPositionInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + funder: TAccountMetas[0]; + owner: TAccountMetas[1]; + position: TAccountMetas[2]; + positionMint: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + whirlpool: TAccountMetas[5]; + tokenProgram: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + rent: TAccountMetas[8]; + associatedTokenProgram: TAccountMetas[9]; + }; + data: OpenPositionInstructionData; +} + +export function parseOpenPositionInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedOpenPositionInstruction { + if (instruction.accounts.length < 10) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + funder: getNextAccount(), + owner: getNextAccount(), + position: getNextAccount(), + positionMint: getNextAccount(), + positionTokenAccount: getNextAccount(), + whirlpool: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + associatedTokenProgram: getNextAccount(), + }, + data: getOpenPositionInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/openPositionWithMetadata.ts b/clients/orca-whirlpools/src/generated/instructions/openPositionWithMetadata.ts new file mode 100644 index 00000000..9c357d7c --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/openPositionWithMetadata.ts @@ -0,0 +1,396 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + OpenPositionWithMetadataBumps, + OpenPositionWithMetadataBumpsArgs, +} from "../types/index.js"; +import { + getOpenPositionWithMetadataBumpsDecoder, + getOpenPositionWithMetadataBumpsEncoder, +} from "../types/index.js"; + +export const OPEN_POSITION_WITH_METADATA_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([242, 29, 134, 48, 58, 110, 14, 60]); + +export function getOpenPositionWithMetadataDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + OPEN_POSITION_WITH_METADATA_DISCRIMINATOR, + ); +} + +export type OpenPositionWithMetadataInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountFunder extends string | AccountMeta = string, + TAccountOwner extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionMint extends string | AccountMeta = string, + TAccountPositionMetadataAccount extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountRent extends string | AccountMeta = string, + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountMetadataProgram extends string | AccountMeta = string, + TAccountMetadataUpdateAuth extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountOwner extends string + ? ReadonlyAccount + : TAccountOwner, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionMint extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPositionMint, + TAccountPositionMetadataAccount extends string + ? WritableAccount + : TAccountPositionMetadataAccount, + TAccountPositionTokenAccount extends string + ? WritableAccount + : TAccountPositionTokenAccount, + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountMetadataProgram extends string + ? ReadonlyAccount + : TAccountMetadataProgram, + TAccountMetadataUpdateAuth extends string + ? ReadonlyAccount + : TAccountMetadataUpdateAuth, + ...TRemainingAccounts, + ] + >; + +export interface OpenPositionWithMetadataInstructionData { + discriminator: ReadonlyUint8Array; + bumps: OpenPositionWithMetadataBumps; + tickLowerIndex: number; + tickUpperIndex: number; +} + +export interface OpenPositionWithMetadataInstructionDataArgs { + bumps: OpenPositionWithMetadataBumpsArgs; + tickLowerIndex: number; + tickUpperIndex: number; +} + +export function getOpenPositionWithMetadataInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bumps", getOpenPositionWithMetadataBumpsEncoder()], + ["tickLowerIndex", getI32Encoder()], + ["tickUpperIndex", getI32Encoder()], + ]), + (value) => ({ + ...value, + discriminator: OPEN_POSITION_WITH_METADATA_DISCRIMINATOR, + }), + ); +} + +export function getOpenPositionWithMetadataInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bumps", getOpenPositionWithMetadataBumpsDecoder()], + ["tickLowerIndex", getI32Decoder()], + ["tickUpperIndex", getI32Decoder()], + ]); +} + +export function getOpenPositionWithMetadataInstructionDataCodec(): FixedSizeCodec< + OpenPositionWithMetadataInstructionDataArgs, + OpenPositionWithMetadataInstructionData +> { + return combineCodec( + getOpenPositionWithMetadataInstructionDataEncoder(), + getOpenPositionWithMetadataInstructionDataDecoder(), + ); +} + +export interface OpenPositionWithMetadataInput< + TAccountFunder extends string = string, + TAccountOwner extends string = string, + TAccountPosition extends string = string, + TAccountPositionMint extends string = string, + TAccountPositionMetadataAccount extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountWhirlpool extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountMetadataProgram extends string = string, + TAccountMetadataUpdateAuth extends string = string, +> { + funder: TransactionSigner; + owner: Address; + position: Address; + positionMint: TransactionSigner; + positionMetadataAccount: Address; + positionTokenAccount: Address; + whirlpool: Address; + tokenProgram: Address; + systemProgram: Address; + rent: Address; + associatedTokenProgram: Address; + metadataProgram: Address; + metadataUpdateAuth: Address; + bumps: OpenPositionWithMetadataInstructionDataArgs["bumps"]; + tickLowerIndex: OpenPositionWithMetadataInstructionDataArgs["tickLowerIndex"]; + tickUpperIndex: OpenPositionWithMetadataInstructionDataArgs["tickUpperIndex"]; +} + +export function getOpenPositionWithMetadataInstruction< + TAccountFunder extends string, + TAccountOwner extends string, + TAccountPosition extends string, + TAccountPositionMint extends string, + TAccountPositionMetadataAccount extends string, + TAccountPositionTokenAccount extends string, + TAccountWhirlpool extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TAccountAssociatedTokenProgram extends string, + TAccountMetadataProgram extends string, + TAccountMetadataUpdateAuth extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: OpenPositionWithMetadataInput< + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionMetadataAccount, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram, + TAccountMetadataUpdateAuth + >, + config?: { programAddress?: TProgramAddress }, +): OpenPositionWithMetadataInstruction< + TProgramAddress, + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionMetadataAccount, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram, + TAccountMetadataUpdateAuth +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + funder: { value: input.funder ?? null, isWritable: true }, + owner: { value: input.owner ?? null, isWritable: false }, + position: { value: input.position ?? null, isWritable: true }, + positionMint: { value: input.positionMint ?? null, isWritable: true }, + positionMetadataAccount: { + value: input.positionMetadataAccount ?? null, + isWritable: true, + }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: true, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + metadataProgram: { + value: input.metadataProgram ?? null, + isWritable: false, + }, + metadataUpdateAuth: { + value: input.metadataUpdateAuth ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.funder), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionMint), + getAccountMeta(accounts.positionMetadataAccount), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.metadataProgram), + getAccountMeta(accounts.metadataUpdateAuth), + ], + programAddress, + data: getOpenPositionWithMetadataInstructionDataEncoder().encode( + args as OpenPositionWithMetadataInstructionDataArgs, + ), + } as OpenPositionWithMetadataInstruction< + TProgramAddress, + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionMetadataAccount, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent, + TAccountAssociatedTokenProgram, + TAccountMetadataProgram, + TAccountMetadataUpdateAuth + >; + + return instruction; +} + +export interface ParsedOpenPositionWithMetadataInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + funder: TAccountMetas[0]; + owner: TAccountMetas[1]; + position: TAccountMetas[2]; + positionMint: TAccountMetas[3]; + positionMetadataAccount: TAccountMetas[4]; + positionTokenAccount: TAccountMetas[5]; + whirlpool: TAccountMetas[6]; + tokenProgram: TAccountMetas[7]; + systemProgram: TAccountMetas[8]; + rent: TAccountMetas[9]; + associatedTokenProgram: TAccountMetas[10]; + metadataProgram: TAccountMetas[11]; + metadataUpdateAuth: TAccountMetas[12]; + }; + data: OpenPositionWithMetadataInstructionData; +} + +export function parseOpenPositionWithMetadataInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedOpenPositionWithMetadataInstruction { + if (instruction.accounts.length < 13) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + funder: getNextAccount(), + owner: getNextAccount(), + position: getNextAccount(), + positionMint: getNextAccount(), + positionMetadataAccount: getNextAccount(), + positionTokenAccount: getNextAccount(), + whirlpool: getNextAccount(), + tokenProgram: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + associatedTokenProgram: getNextAccount(), + metadataProgram: getNextAccount(), + metadataUpdateAuth: getNextAccount(), + }, + data: getOpenPositionWithMetadataInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/openPositionWithTokenExtensions.ts b/clients/orca-whirlpools/src/generated/instructions/openPositionWithTokenExtensions.ts new file mode 100644 index 00000000..93f24808 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/openPositionWithTokenExtensions.ts @@ -0,0 +1,345 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBooleanDecoder, + getBooleanEncoder, + getBytesDecoder, + getBytesEncoder, + getI32Decoder, + getI32Encoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const OPEN_POSITION_WITH_TOKEN_EXTENSIONS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([212, 47, 95, 92, 114, 102, 131, 250]); + +export function getOpenPositionWithTokenExtensionsDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + OPEN_POSITION_WITH_TOKEN_EXTENSIONS_DISCRIMINATOR, + ); +} + +export type OpenPositionWithTokenExtensionsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountFunder extends string | AccountMeta = string, + TAccountOwner extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountPositionMint extends string | AccountMeta = string, + TAccountPositionTokenAccount extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountToken2022Program extends string | AccountMeta = string, + TAccountSystemProgram extends string | AccountMeta = string, + TAccountAssociatedTokenProgram extends string | AccountMeta = string, + TAccountMetadataUpdateAuth extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountFunder extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountFunder, + TAccountOwner extends string + ? ReadonlyAccount + : TAccountOwner, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountPositionMint extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPositionMint, + TAccountPositionTokenAccount extends string + ? WritableAccount + : TAccountPositionTokenAccount, + TAccountWhirlpool extends string + ? ReadonlyAccount + : TAccountWhirlpool, + TAccountToken2022Program extends string + ? ReadonlyAccount + : TAccountToken2022Program, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountAssociatedTokenProgram extends string + ? ReadonlyAccount + : TAccountAssociatedTokenProgram, + TAccountMetadataUpdateAuth extends string + ? ReadonlyAccount + : TAccountMetadataUpdateAuth, + ...TRemainingAccounts, + ] + >; + +export interface OpenPositionWithTokenExtensionsInstructionData { + discriminator: ReadonlyUint8Array; + tickLowerIndex: number; + tickUpperIndex: number; + withTokenMetadataExtension: boolean; +} + +export interface OpenPositionWithTokenExtensionsInstructionDataArgs { + tickLowerIndex: number; + tickUpperIndex: number; + withTokenMetadataExtension: boolean; +} + +export function getOpenPositionWithTokenExtensionsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["tickLowerIndex", getI32Encoder()], + ["tickUpperIndex", getI32Encoder()], + ["withTokenMetadataExtension", getBooleanEncoder()], + ]), + (value) => ({ + ...value, + discriminator: OPEN_POSITION_WITH_TOKEN_EXTENSIONS_DISCRIMINATOR, + }), + ); +} + +export function getOpenPositionWithTokenExtensionsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["tickLowerIndex", getI32Decoder()], + ["tickUpperIndex", getI32Decoder()], + ["withTokenMetadataExtension", getBooleanDecoder()], + ]); +} + +export function getOpenPositionWithTokenExtensionsInstructionDataCodec(): FixedSizeCodec< + OpenPositionWithTokenExtensionsInstructionDataArgs, + OpenPositionWithTokenExtensionsInstructionData +> { + return combineCodec( + getOpenPositionWithTokenExtensionsInstructionDataEncoder(), + getOpenPositionWithTokenExtensionsInstructionDataDecoder(), + ); +} + +export interface OpenPositionWithTokenExtensionsInput< + TAccountFunder extends string = string, + TAccountOwner extends string = string, + TAccountPosition extends string = string, + TAccountPositionMint extends string = string, + TAccountPositionTokenAccount extends string = string, + TAccountWhirlpool extends string = string, + TAccountToken2022Program extends string = string, + TAccountSystemProgram extends string = string, + TAccountAssociatedTokenProgram extends string = string, + TAccountMetadataUpdateAuth extends string = string, +> { + funder: TransactionSigner; + owner: Address; + position: Address; + positionMint: TransactionSigner; + positionTokenAccount: Address; + whirlpool: Address; + token2022Program: Address; + systemProgram: Address; + associatedTokenProgram: Address; + metadataUpdateAuth: Address; + tickLowerIndex: OpenPositionWithTokenExtensionsInstructionDataArgs["tickLowerIndex"]; + tickUpperIndex: OpenPositionWithTokenExtensionsInstructionDataArgs["tickUpperIndex"]; + withTokenMetadataExtension: OpenPositionWithTokenExtensionsInstructionDataArgs["withTokenMetadataExtension"]; +} + +export function getOpenPositionWithTokenExtensionsInstruction< + TAccountFunder extends string, + TAccountOwner extends string, + TAccountPosition extends string, + TAccountPositionMint extends string, + TAccountPositionTokenAccount extends string, + TAccountWhirlpool extends string, + TAccountToken2022Program extends string, + TAccountSystemProgram extends string, + TAccountAssociatedTokenProgram extends string, + TAccountMetadataUpdateAuth extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: OpenPositionWithTokenExtensionsInput< + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountToken2022Program, + TAccountSystemProgram, + TAccountAssociatedTokenProgram, + TAccountMetadataUpdateAuth + >, + config?: { programAddress?: TProgramAddress }, +): OpenPositionWithTokenExtensionsInstruction< + TProgramAddress, + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountToken2022Program, + TAccountSystemProgram, + TAccountAssociatedTokenProgram, + TAccountMetadataUpdateAuth +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + funder: { value: input.funder ?? null, isWritable: true }, + owner: { value: input.owner ?? null, isWritable: false }, + position: { value: input.position ?? null, isWritable: true }, + positionMint: { value: input.positionMint ?? null, isWritable: true }, + positionTokenAccount: { + value: input.positionTokenAccount ?? null, + isWritable: true, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: false }, + token2022Program: { + value: input.token2022Program ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + associatedTokenProgram: { + value: input.associatedTokenProgram ?? null, + isWritable: false, + }, + metadataUpdateAuth: { + value: input.metadataUpdateAuth ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.funder), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.position), + getAccountMeta(accounts.positionMint), + getAccountMeta(accounts.positionTokenAccount), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.token2022Program), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.associatedTokenProgram), + getAccountMeta(accounts.metadataUpdateAuth), + ], + programAddress, + data: getOpenPositionWithTokenExtensionsInstructionDataEncoder().encode( + args as OpenPositionWithTokenExtensionsInstructionDataArgs, + ), + } as OpenPositionWithTokenExtensionsInstruction< + TProgramAddress, + TAccountFunder, + TAccountOwner, + TAccountPosition, + TAccountPositionMint, + TAccountPositionTokenAccount, + TAccountWhirlpool, + TAccountToken2022Program, + TAccountSystemProgram, + TAccountAssociatedTokenProgram, + TAccountMetadataUpdateAuth + >; + + return instruction; +} + +export interface ParsedOpenPositionWithTokenExtensionsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + funder: TAccountMetas[0]; + owner: TAccountMetas[1]; + position: TAccountMetas[2]; + positionMint: TAccountMetas[3]; + positionTokenAccount: TAccountMetas[4]; + whirlpool: TAccountMetas[5]; + token2022Program: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + associatedTokenProgram: TAccountMetas[8]; + metadataUpdateAuth: TAccountMetas[9]; + }; + data: OpenPositionWithTokenExtensionsInstructionData; +} + +export function parseOpenPositionWithTokenExtensionsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedOpenPositionWithTokenExtensionsInstruction { + if (instruction.accounts.length < 10) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + funder: getNextAccount(), + owner: getNextAccount(), + position: getNextAccount(), + positionMint: getNextAccount(), + positionTokenAccount: getNextAccount(), + whirlpool: getNextAccount(), + token2022Program: getNextAccount(), + systemProgram: getNextAccount(), + associatedTokenProgram: getNextAccount(), + metadataUpdateAuth: getNextAccount(), + }, + data: getOpenPositionWithTokenExtensionsInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setCollectProtocolFeesAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setCollectProtocolFeesAuthority.ts new file mode 100644 index 00000000..c9f50a51 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setCollectProtocolFeesAuthority.ts @@ -0,0 +1,216 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_COLLECT_PROTOCOL_FEES_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([34, 150, 93, 244, 139, 225, 233, 67]); + +export function getSetCollectProtocolFeesAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_COLLECT_PROTOCOL_FEES_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetCollectProtocolFeesAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountCollectProtocolFeesAuthority extends string | AccountMeta = string, + TAccountNewCollectProtocolFeesAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? WritableAccount + : TAccountWhirlpoolsConfig, + TAccountCollectProtocolFeesAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountCollectProtocolFeesAuthority, + TAccountNewCollectProtocolFeesAuthority extends string + ? ReadonlyAccount + : TAccountNewCollectProtocolFeesAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetCollectProtocolFeesAuthorityInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface SetCollectProtocolFeesAuthorityInstructionDataArgs {} + +export function getSetCollectProtocolFeesAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: SET_COLLECT_PROTOCOL_FEES_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetCollectProtocolFeesAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getSetCollectProtocolFeesAuthorityInstructionDataCodec(): FixedSizeCodec< + SetCollectProtocolFeesAuthorityInstructionDataArgs, + SetCollectProtocolFeesAuthorityInstructionData +> { + return combineCodec( + getSetCollectProtocolFeesAuthorityInstructionDataEncoder(), + getSetCollectProtocolFeesAuthorityInstructionDataDecoder(), + ); +} + +export interface SetCollectProtocolFeesAuthorityInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountCollectProtocolFeesAuthority extends string = string, + TAccountNewCollectProtocolFeesAuthority extends string = string, +> { + whirlpoolsConfig: Address; + collectProtocolFeesAuthority: TransactionSigner; + newCollectProtocolFeesAuthority: Address; +} + +export function getSetCollectProtocolFeesAuthorityInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountCollectProtocolFeesAuthority extends string, + TAccountNewCollectProtocolFeesAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetCollectProtocolFeesAuthorityInput< + TAccountWhirlpoolsConfig, + TAccountCollectProtocolFeesAuthority, + TAccountNewCollectProtocolFeesAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetCollectProtocolFeesAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountCollectProtocolFeesAuthority, + TAccountNewCollectProtocolFeesAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: true, + }, + collectProtocolFeesAuthority: { + value: input.collectProtocolFeesAuthority ?? null, + isWritable: false, + }, + newCollectProtocolFeesAuthority: { + value: input.newCollectProtocolFeesAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.collectProtocolFeesAuthority), + getAccountMeta(accounts.newCollectProtocolFeesAuthority), + ], + programAddress, + data: getSetCollectProtocolFeesAuthorityInstructionDataEncoder().encode({}), + } as SetCollectProtocolFeesAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountCollectProtocolFeesAuthority, + TAccountNewCollectProtocolFeesAuthority + >; + + return instruction; +} + +export interface ParsedSetCollectProtocolFeesAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + collectProtocolFeesAuthority: TAccountMetas[1]; + newCollectProtocolFeesAuthority: TAccountMetas[2]; + }; + data: SetCollectProtocolFeesAuthorityInstructionData; +} + +export function parseSetCollectProtocolFeesAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetCollectProtocolFeesAuthorityInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + collectProtocolFeesAuthority: getNextAccount(), + newCollectProtocolFeesAuthority: getNextAccount(), + }, + data: getSetCollectProtocolFeesAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setConfigExtensionAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setConfigExtensionAuthority.ts new file mode 100644 index 00000000..eab9e7cb --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setConfigExtensionAuthority.ts @@ -0,0 +1,233 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_CONFIG_EXTENSION_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([44, 94, 241, 116, 24, 188, 60, 143]); + +export function getSetConfigExtensionAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_CONFIG_EXTENSION_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetConfigExtensionAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpoolsConfigExtension extends string | AccountMeta = string, + TAccountConfigExtensionAuthority extends string | AccountMeta = string, + TAccountNewConfigExtensionAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension extends string + ? WritableAccount + : TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountConfigExtensionAuthority, + TAccountNewConfigExtensionAuthority extends string + ? ReadonlyAccount + : TAccountNewConfigExtensionAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetConfigExtensionAuthorityInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface SetConfigExtensionAuthorityInstructionDataArgs {} + +export function getSetConfigExtensionAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: SET_CONFIG_EXTENSION_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetConfigExtensionAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getSetConfigExtensionAuthorityInstructionDataCodec(): FixedSizeCodec< + SetConfigExtensionAuthorityInstructionDataArgs, + SetConfigExtensionAuthorityInstructionData +> { + return combineCodec( + getSetConfigExtensionAuthorityInstructionDataEncoder(), + getSetConfigExtensionAuthorityInstructionDataDecoder(), + ); +} + +export interface SetConfigExtensionAuthorityInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpoolsConfigExtension extends string = string, + TAccountConfigExtensionAuthority extends string = string, + TAccountNewConfigExtensionAuthority extends string = string, +> { + whirlpoolsConfig: Address; + whirlpoolsConfigExtension: Address; + configExtensionAuthority: TransactionSigner; + newConfigExtensionAuthority: Address; +} + +export function getSetConfigExtensionAuthorityInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpoolsConfigExtension extends string, + TAccountConfigExtensionAuthority extends string, + TAccountNewConfigExtensionAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetConfigExtensionAuthorityInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority, + TAccountNewConfigExtensionAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetConfigExtensionAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority, + TAccountNewConfigExtensionAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpoolsConfigExtension: { + value: input.whirlpoolsConfigExtension ?? null, + isWritable: true, + }, + configExtensionAuthority: { + value: input.configExtensionAuthority ?? null, + isWritable: false, + }, + newConfigExtensionAuthority: { + value: input.newConfigExtensionAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpoolsConfigExtension), + getAccountMeta(accounts.configExtensionAuthority), + getAccountMeta(accounts.newConfigExtensionAuthority), + ], + programAddress, + data: getSetConfigExtensionAuthorityInstructionDataEncoder().encode({}), + } as SetConfigExtensionAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority, + TAccountNewConfigExtensionAuthority + >; + + return instruction; +} + +export interface ParsedSetConfigExtensionAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpoolsConfigExtension: TAccountMetas[1]; + configExtensionAuthority: TAccountMetas[2]; + newConfigExtensionAuthority: TAccountMetas[3]; + }; + data: SetConfigExtensionAuthorityInstructionData; +} + +export function parseSetConfigExtensionAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetConfigExtensionAuthorityInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpoolsConfigExtension: getNextAccount(), + configExtensionAuthority: getNextAccount(), + newConfigExtensionAuthority: getNextAccount(), + }, + data: getSetConfigExtensionAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setDefaultFeeRate.ts b/clients/orca-whirlpools/src/generated/instructions/setDefaultFeeRate.ts new file mode 100644 index 00000000..e59f4548 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setDefaultFeeRate.ts @@ -0,0 +1,223 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_DEFAULT_FEE_RATE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([118, 215, 214, 157, 182, 229, 208, 228]); + +export function getSetDefaultFeeRateDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_DEFAULT_FEE_RATE_DISCRIMINATOR, + ); +} + +export type SetDefaultFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountFeeTier extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountFeeTier extends string + ? WritableAccount + : TAccountFeeTier, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetDefaultFeeRateInstructionData { + discriminator: ReadonlyUint8Array; + defaultFeeRate: number; +} + +export interface SetDefaultFeeRateInstructionDataArgs { + defaultFeeRate: number; +} + +export function getSetDefaultFeeRateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["defaultFeeRate", getU16Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_DEFAULT_FEE_RATE_DISCRIMINATOR, + }), + ); +} + +export function getSetDefaultFeeRateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["defaultFeeRate", getU16Decoder()], + ]); +} + +export function getSetDefaultFeeRateInstructionDataCodec(): FixedSizeCodec< + SetDefaultFeeRateInstructionDataArgs, + SetDefaultFeeRateInstructionData +> { + return combineCodec( + getSetDefaultFeeRateInstructionDataEncoder(), + getSetDefaultFeeRateInstructionDataDecoder(), + ); +} + +export interface SetDefaultFeeRateInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountFeeTier extends string = string, + TAccountFeeAuthority extends string = string, +> { + whirlpoolsConfig: Address; + feeTier: Address; + feeAuthority: TransactionSigner; + defaultFeeRate: SetDefaultFeeRateInstructionDataArgs["defaultFeeRate"]; +} + +export function getSetDefaultFeeRateInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountFeeTier extends string, + TAccountFeeAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetDefaultFeeRateInput< + TAccountWhirlpoolsConfig, + TAccountFeeTier, + TAccountFeeAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetDefaultFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountFeeTier, + TAccountFeeAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + feeTier: { value: input.feeTier ?? null, isWritable: true }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.feeTier), + getAccountMeta(accounts.feeAuthority), + ], + programAddress, + data: getSetDefaultFeeRateInstructionDataEncoder().encode( + args as SetDefaultFeeRateInstructionDataArgs, + ), + } as SetDefaultFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountFeeTier, + TAccountFeeAuthority + >; + + return instruction; +} + +export interface ParsedSetDefaultFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + feeTier: TAccountMetas[1]; + feeAuthority: TAccountMetas[2]; + }; + data: SetDefaultFeeRateInstructionData; +} + +export function parseSetDefaultFeeRateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetDefaultFeeRateInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + feeTier: getNextAccount(), + feeAuthority: getNextAccount(), + }, + data: getSetDefaultFeeRateInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setDefaultProtocolFeeRate.ts b/clients/orca-whirlpools/src/generated/instructions/setDefaultProtocolFeeRate.ts new file mode 100644 index 00000000..b18e0e03 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setDefaultProtocolFeeRate.ts @@ -0,0 +1,210 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_DEFAULT_PROTOCOL_FEE_RATE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([107, 205, 249, 226, 151, 35, 86, 0]); + +export function getSetDefaultProtocolFeeRateDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_DEFAULT_PROTOCOL_FEE_RATE_DISCRIMINATOR, + ); +} + +export type SetDefaultProtocolFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? WritableAccount + : TAccountWhirlpoolsConfig, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetDefaultProtocolFeeRateInstructionData { + discriminator: ReadonlyUint8Array; + defaultProtocolFeeRate: number; +} + +export interface SetDefaultProtocolFeeRateInstructionDataArgs { + defaultProtocolFeeRate: number; +} + +export function getSetDefaultProtocolFeeRateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["defaultProtocolFeeRate", getU16Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_DEFAULT_PROTOCOL_FEE_RATE_DISCRIMINATOR, + }), + ); +} + +export function getSetDefaultProtocolFeeRateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["defaultProtocolFeeRate", getU16Decoder()], + ]); +} + +export function getSetDefaultProtocolFeeRateInstructionDataCodec(): FixedSizeCodec< + SetDefaultProtocolFeeRateInstructionDataArgs, + SetDefaultProtocolFeeRateInstructionData +> { + return combineCodec( + getSetDefaultProtocolFeeRateInstructionDataEncoder(), + getSetDefaultProtocolFeeRateInstructionDataDecoder(), + ); +} + +export interface SetDefaultProtocolFeeRateInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountFeeAuthority extends string = string, +> { + whirlpoolsConfig: Address; + feeAuthority: TransactionSigner; + defaultProtocolFeeRate: SetDefaultProtocolFeeRateInstructionDataArgs["defaultProtocolFeeRate"]; +} + +export function getSetDefaultProtocolFeeRateInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountFeeAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetDefaultProtocolFeeRateInput< + TAccountWhirlpoolsConfig, + TAccountFeeAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetDefaultProtocolFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountFeeAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: true, + }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.feeAuthority), + ], + programAddress, + data: getSetDefaultProtocolFeeRateInstructionDataEncoder().encode( + args as SetDefaultProtocolFeeRateInstructionDataArgs, + ), + } as SetDefaultProtocolFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountFeeAuthority + >; + + return instruction; +} + +export interface ParsedSetDefaultProtocolFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + feeAuthority: TAccountMetas[1]; + }; + data: SetDefaultProtocolFeeRateInstructionData; +} + +export function parseSetDefaultProtocolFeeRateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetDefaultProtocolFeeRateInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + feeAuthority: getNextAccount(), + }, + data: getSetDefaultProtocolFeeRateInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setFeeAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setFeeAuthority.ts new file mode 100644 index 00000000..6d05f431 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setFeeAuthority.ts @@ -0,0 +1,208 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_FEE_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([31, 1, 50, 87, 237, 101, 97, 132]); + +export function getSetFeeAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_FEE_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetFeeAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TAccountNewFeeAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? WritableAccount + : TAccountWhirlpoolsConfig, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + TAccountNewFeeAuthority extends string + ? ReadonlyAccount + : TAccountNewFeeAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetFeeAuthorityInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface SetFeeAuthorityInstructionDataArgs {} + +export function getSetFeeAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: SET_FEE_AUTHORITY_DISCRIMINATOR }), + ); +} + +export function getSetFeeAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getSetFeeAuthorityInstructionDataCodec(): FixedSizeCodec< + SetFeeAuthorityInstructionDataArgs, + SetFeeAuthorityInstructionData +> { + return combineCodec( + getSetFeeAuthorityInstructionDataEncoder(), + getSetFeeAuthorityInstructionDataDecoder(), + ); +} + +export interface SetFeeAuthorityInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountFeeAuthority extends string = string, + TAccountNewFeeAuthority extends string = string, +> { + whirlpoolsConfig: Address; + feeAuthority: TransactionSigner; + newFeeAuthority: Address; +} + +export function getSetFeeAuthorityInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountFeeAuthority extends string, + TAccountNewFeeAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetFeeAuthorityInput< + TAccountWhirlpoolsConfig, + TAccountFeeAuthority, + TAccountNewFeeAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetFeeAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountFeeAuthority, + TAccountNewFeeAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: true, + }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + newFeeAuthority: { + value: input.newFeeAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.feeAuthority), + getAccountMeta(accounts.newFeeAuthority), + ], + programAddress, + data: getSetFeeAuthorityInstructionDataEncoder().encode({}), + } as SetFeeAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountFeeAuthority, + TAccountNewFeeAuthority + >; + + return instruction; +} + +export interface ParsedSetFeeAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + feeAuthority: TAccountMetas[1]; + newFeeAuthority: TAccountMetas[2]; + }; + data: SetFeeAuthorityInstructionData; +} + +export function parseSetFeeAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetFeeAuthorityInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + feeAuthority: getNextAccount(), + newFeeAuthority: getNextAccount(), + }, + data: getSetFeeAuthorityInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setFeeRate.ts b/clients/orca-whirlpools/src/generated/instructions/setFeeRate.ts new file mode 100644 index 00000000..d28fdfad --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setFeeRate.ts @@ -0,0 +1,221 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_FEE_RATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 53, 243, 137, 65, 8, 140, 158, 6, +]); + +export function getSetFeeRateDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_FEE_RATE_DISCRIMINATOR, + ); +} + +export type SetFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetFeeRateInstructionData { + discriminator: ReadonlyUint8Array; + feeRate: number; +} + +export interface SetFeeRateInstructionDataArgs { + feeRate: number; +} + +export function getSetFeeRateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["feeRate", getU16Encoder()], + ]), + (value) => ({ ...value, discriminator: SET_FEE_RATE_DISCRIMINATOR }), + ); +} + +export function getSetFeeRateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["feeRate", getU16Decoder()], + ]); +} + +export function getSetFeeRateInstructionDataCodec(): FixedSizeCodec< + SetFeeRateInstructionDataArgs, + SetFeeRateInstructionData +> { + return combineCodec( + getSetFeeRateInstructionDataEncoder(), + getSetFeeRateInstructionDataDecoder(), + ); +} + +export interface SetFeeRateInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpool extends string = string, + TAccountFeeAuthority extends string = string, +> { + whirlpoolsConfig: Address; + whirlpool: Address; + feeAuthority: TransactionSigner; + feeRate: SetFeeRateInstructionDataArgs["feeRate"]; +} + +export function getSetFeeRateInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpool extends string, + TAccountFeeAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetFeeRateInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountFeeAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountFeeAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.feeAuthority), + ], + programAddress, + data: getSetFeeRateInstructionDataEncoder().encode( + args as SetFeeRateInstructionDataArgs, + ), + } as SetFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountFeeAuthority + >; + + return instruction; +} + +export interface ParsedSetFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpool: TAccountMetas[1]; + feeAuthority: TAccountMetas[2]; + }; + data: SetFeeRateInstructionData; +} + +export function parseSetFeeRateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetFeeRateInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpool: getNextAccount(), + feeAuthority: getNextAccount(), + }, + data: getSetFeeRateInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setProtocolFeeRate.ts b/clients/orca-whirlpools/src/generated/instructions/setProtocolFeeRate.ts new file mode 100644 index 00000000..28da7f27 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setProtocolFeeRate.ts @@ -0,0 +1,225 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU16Decoder, + getU16Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_PROTOCOL_FEE_RATE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([95, 7, 4, 50, 154, 79, 156, 131]); + +export function getSetProtocolFeeRateDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_PROTOCOL_FEE_RATE_DISCRIMINATOR, + ); +} + +export type SetProtocolFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountFeeAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountFeeAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountFeeAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetProtocolFeeRateInstructionData { + discriminator: ReadonlyUint8Array; + protocolFeeRate: number; +} + +export interface SetProtocolFeeRateInstructionDataArgs { + protocolFeeRate: number; +} + +export function getSetProtocolFeeRateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["protocolFeeRate", getU16Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_PROTOCOL_FEE_RATE_DISCRIMINATOR, + }), + ); +} + +export function getSetProtocolFeeRateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["protocolFeeRate", getU16Decoder()], + ]); +} + +export function getSetProtocolFeeRateInstructionDataCodec(): FixedSizeCodec< + SetProtocolFeeRateInstructionDataArgs, + SetProtocolFeeRateInstructionData +> { + return combineCodec( + getSetProtocolFeeRateInstructionDataEncoder(), + getSetProtocolFeeRateInstructionDataDecoder(), + ); +} + +export interface SetProtocolFeeRateInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpool extends string = string, + TAccountFeeAuthority extends string = string, +> { + whirlpoolsConfig: Address; + whirlpool: Address; + feeAuthority: TransactionSigner; + protocolFeeRate: SetProtocolFeeRateInstructionDataArgs["protocolFeeRate"]; +} + +export function getSetProtocolFeeRateInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpool extends string, + TAccountFeeAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetProtocolFeeRateInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountFeeAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetProtocolFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountFeeAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + feeAuthority: { value: input.feeAuthority ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.feeAuthority), + ], + programAddress, + data: getSetProtocolFeeRateInstructionDataEncoder().encode( + args as SetProtocolFeeRateInstructionDataArgs, + ), + } as SetProtocolFeeRateInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountFeeAuthority + >; + + return instruction; +} + +export interface ParsedSetProtocolFeeRateInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpool: TAccountMetas[1]; + feeAuthority: TAccountMetas[2]; + }; + data: SetProtocolFeeRateInstructionData; +} + +export function parseSetProtocolFeeRateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetProtocolFeeRateInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpool: getNextAccount(), + feeAuthority: getNextAccount(), + }, + data: getSetProtocolFeeRateInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setRewardAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setRewardAuthority.ts new file mode 100644 index 00000000..19af92c8 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setRewardAuthority.ts @@ -0,0 +1,228 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_REWARD_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([34, 39, 183, 252, 83, 28, 85, 127]); + +export function getSetRewardAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_REWARD_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetRewardAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountRewardAuthority extends string | AccountMeta = string, + TAccountNewRewardAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountRewardAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardAuthority, + TAccountNewRewardAuthority extends string + ? ReadonlyAccount + : TAccountNewRewardAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetRewardAuthorityInstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; +} + +export interface SetRewardAuthorityInstructionDataArgs { + rewardIndex: number; +} + +export function getSetRewardAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_REWARD_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetRewardAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ]); +} + +export function getSetRewardAuthorityInstructionDataCodec(): FixedSizeCodec< + SetRewardAuthorityInstructionDataArgs, + SetRewardAuthorityInstructionData +> { + return combineCodec( + getSetRewardAuthorityInstructionDataEncoder(), + getSetRewardAuthorityInstructionDataDecoder(), + ); +} + +export interface SetRewardAuthorityInput< + TAccountWhirlpool extends string = string, + TAccountRewardAuthority extends string = string, + TAccountNewRewardAuthority extends string = string, +> { + whirlpool: Address; + rewardAuthority: TransactionSigner; + newRewardAuthority: Address; + rewardIndex: SetRewardAuthorityInstructionDataArgs["rewardIndex"]; +} + +export function getSetRewardAuthorityInstruction< + TAccountWhirlpool extends string, + TAccountRewardAuthority extends string, + TAccountNewRewardAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetRewardAuthorityInput< + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountNewRewardAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetRewardAuthorityInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountNewRewardAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + rewardAuthority: { + value: input.rewardAuthority ?? null, + isWritable: false, + }, + newRewardAuthority: { + value: input.newRewardAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.rewardAuthority), + getAccountMeta(accounts.newRewardAuthority), + ], + programAddress, + data: getSetRewardAuthorityInstructionDataEncoder().encode( + args as SetRewardAuthorityInstructionDataArgs, + ), + } as SetRewardAuthorityInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountNewRewardAuthority + >; + + return instruction; +} + +export interface ParsedSetRewardAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + rewardAuthority: TAccountMetas[1]; + newRewardAuthority: TAccountMetas[2]; + }; + data: SetRewardAuthorityInstructionData; +} + +export function parseSetRewardAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetRewardAuthorityInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + rewardAuthority: getNextAccount(), + newRewardAuthority: getNextAccount(), + }, + data: getSetRewardAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setRewardAuthorityBySuperAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setRewardAuthorityBySuperAuthority.ts new file mode 100644 index 00000000..8cb84bed --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setRewardAuthorityBySuperAuthority.ts @@ -0,0 +1,248 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_REWARD_AUTHORITY_BY_SUPER_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([240, 154, 201, 198, 148, 93, 56, 25]); + +export function getSetRewardAuthorityBySuperAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_REWARD_AUTHORITY_BY_SUPER_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetRewardAuthorityBySuperAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountRewardEmissionsSuperAuthority extends string | AccountMeta = string, + TAccountNewRewardAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountRewardEmissionsSuperAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardAuthority extends string + ? ReadonlyAccount + : TAccountNewRewardAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetRewardAuthorityBySuperAuthorityInstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; +} + +export interface SetRewardAuthorityBySuperAuthorityInstructionDataArgs { + rewardIndex: number; +} + +export function getSetRewardAuthorityBySuperAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_REWARD_AUTHORITY_BY_SUPER_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetRewardAuthorityBySuperAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ]); +} + +export function getSetRewardAuthorityBySuperAuthorityInstructionDataCodec(): FixedSizeCodec< + SetRewardAuthorityBySuperAuthorityInstructionDataArgs, + SetRewardAuthorityBySuperAuthorityInstructionData +> { + return combineCodec( + getSetRewardAuthorityBySuperAuthorityInstructionDataEncoder(), + getSetRewardAuthorityBySuperAuthorityInstructionDataDecoder(), + ); +} + +export interface SetRewardAuthorityBySuperAuthorityInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpool extends string = string, + TAccountRewardEmissionsSuperAuthority extends string = string, + TAccountNewRewardAuthority extends string = string, +> { + whirlpoolsConfig: Address; + whirlpool: Address; + rewardEmissionsSuperAuthority: TransactionSigner; + newRewardAuthority: Address; + rewardIndex: SetRewardAuthorityBySuperAuthorityInstructionDataArgs["rewardIndex"]; +} + +export function getSetRewardAuthorityBySuperAuthorityInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpool extends string, + TAccountRewardEmissionsSuperAuthority extends string, + TAccountNewRewardAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetRewardAuthorityBySuperAuthorityInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetRewardAuthorityBySuperAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + rewardEmissionsSuperAuthority: { + value: input.rewardEmissionsSuperAuthority ?? null, + isWritable: false, + }, + newRewardAuthority: { + value: input.newRewardAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.rewardEmissionsSuperAuthority), + getAccountMeta(accounts.newRewardAuthority), + ], + programAddress, + data: getSetRewardAuthorityBySuperAuthorityInstructionDataEncoder().encode( + args as SetRewardAuthorityBySuperAuthorityInstructionDataArgs, + ), + } as SetRewardAuthorityBySuperAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpool, + TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardAuthority + >; + + return instruction; +} + +export interface ParsedSetRewardAuthorityBySuperAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpool: TAccountMetas[1]; + rewardEmissionsSuperAuthority: TAccountMetas[2]; + newRewardAuthority: TAccountMetas[3]; + }; + data: SetRewardAuthorityBySuperAuthorityInstructionData; +} + +export function parseSetRewardAuthorityBySuperAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetRewardAuthorityBySuperAuthorityInstruction< + TProgram, + TAccountMetas +> { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpool: getNextAccount(), + rewardEmissionsSuperAuthority: getNextAccount(), + newRewardAuthority: getNextAccount(), + }, + data: getSetRewardAuthorityBySuperAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setRewardEmissions.ts b/clients/orca-whirlpools/src/generated/instructions/setRewardEmissions.ts new file mode 100644 index 00000000..7f80019a --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setRewardEmissions.ts @@ -0,0 +1,232 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_REWARD_EMISSIONS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([13, 197, 86, 168, 109, 176, 27, 244]); + +export function getSetRewardEmissionsDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_REWARD_EMISSIONS_DISCRIMINATOR, + ); +} + +export type SetRewardEmissionsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountRewardAuthority extends string | AccountMeta = string, + TAccountRewardVault extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountRewardAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardAuthority, + TAccountRewardVault extends string + ? ReadonlyAccount + : TAccountRewardVault, + ...TRemainingAccounts, + ] + >; + +export interface SetRewardEmissionsInstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; + emissionsPerSecondX64: bigint; +} + +export interface SetRewardEmissionsInstructionDataArgs { + rewardIndex: number; + emissionsPerSecondX64: number | bigint; +} + +export function getSetRewardEmissionsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ["emissionsPerSecondX64", getU128Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_REWARD_EMISSIONS_DISCRIMINATOR, + }), + ); +} + +export function getSetRewardEmissionsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ["emissionsPerSecondX64", getU128Decoder()], + ]); +} + +export function getSetRewardEmissionsInstructionDataCodec(): FixedSizeCodec< + SetRewardEmissionsInstructionDataArgs, + SetRewardEmissionsInstructionData +> { + return combineCodec( + getSetRewardEmissionsInstructionDataEncoder(), + getSetRewardEmissionsInstructionDataDecoder(), + ); +} + +export interface SetRewardEmissionsInput< + TAccountWhirlpool extends string = string, + TAccountRewardAuthority extends string = string, + TAccountRewardVault extends string = string, +> { + whirlpool: Address; + rewardAuthority: TransactionSigner; + rewardVault: Address; + rewardIndex: SetRewardEmissionsInstructionDataArgs["rewardIndex"]; + emissionsPerSecondX64: SetRewardEmissionsInstructionDataArgs["emissionsPerSecondX64"]; +} + +export function getSetRewardEmissionsInstruction< + TAccountWhirlpool extends string, + TAccountRewardAuthority extends string, + TAccountRewardVault extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetRewardEmissionsInput< + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountRewardVault + >, + config?: { programAddress?: TProgramAddress }, +): SetRewardEmissionsInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountRewardVault +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + rewardAuthority: { + value: input.rewardAuthority ?? null, + isWritable: false, + }, + rewardVault: { value: input.rewardVault ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.rewardAuthority), + getAccountMeta(accounts.rewardVault), + ], + programAddress, + data: getSetRewardEmissionsInstructionDataEncoder().encode( + args as SetRewardEmissionsInstructionDataArgs, + ), + } as SetRewardEmissionsInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountRewardVault + >; + + return instruction; +} + +export interface ParsedSetRewardEmissionsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + rewardAuthority: TAccountMetas[1]; + rewardVault: TAccountMetas[2]; + }; + data: SetRewardEmissionsInstructionData; +} + +export function parseSetRewardEmissionsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetRewardEmissionsInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + rewardAuthority: getNextAccount(), + rewardVault: getNextAccount(), + }, + data: getSetRewardEmissionsInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setRewardEmissionsSuperAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setRewardEmissionsSuperAuthority.ts new file mode 100644 index 00000000..0347e417 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setRewardEmissionsSuperAuthority.ts @@ -0,0 +1,220 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_REWARD_EMISSIONS_SUPER_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([207, 5, 200, 209, 122, 56, 82, 183]); + +export function getSetRewardEmissionsSuperAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_REWARD_EMISSIONS_SUPER_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetRewardEmissionsSuperAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountRewardEmissionsSuperAuthority extends string | AccountMeta = string, + TAccountNewRewardEmissionsSuperAuthority extends + | string + | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? WritableAccount + : TAccountWhirlpoolsConfig, + TAccountRewardEmissionsSuperAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardEmissionsSuperAuthority extends string + ? ReadonlyAccount + : TAccountNewRewardEmissionsSuperAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetRewardEmissionsSuperAuthorityInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface SetRewardEmissionsSuperAuthorityInstructionDataArgs {} + +export function getSetRewardEmissionsSuperAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: SET_REWARD_EMISSIONS_SUPER_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetRewardEmissionsSuperAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getSetRewardEmissionsSuperAuthorityInstructionDataCodec(): FixedSizeCodec< + SetRewardEmissionsSuperAuthorityInstructionDataArgs, + SetRewardEmissionsSuperAuthorityInstructionData +> { + return combineCodec( + getSetRewardEmissionsSuperAuthorityInstructionDataEncoder(), + getSetRewardEmissionsSuperAuthorityInstructionDataDecoder(), + ); +} + +export interface SetRewardEmissionsSuperAuthorityInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountRewardEmissionsSuperAuthority extends string = string, + TAccountNewRewardEmissionsSuperAuthority extends string = string, +> { + whirlpoolsConfig: Address; + rewardEmissionsSuperAuthority: TransactionSigner; + newRewardEmissionsSuperAuthority: Address; +} + +export function getSetRewardEmissionsSuperAuthorityInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountRewardEmissionsSuperAuthority extends string, + TAccountNewRewardEmissionsSuperAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetRewardEmissionsSuperAuthorityInput< + TAccountWhirlpoolsConfig, + TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardEmissionsSuperAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetRewardEmissionsSuperAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardEmissionsSuperAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: true, + }, + rewardEmissionsSuperAuthority: { + value: input.rewardEmissionsSuperAuthority ?? null, + isWritable: false, + }, + newRewardEmissionsSuperAuthority: { + value: input.newRewardEmissionsSuperAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.rewardEmissionsSuperAuthority), + getAccountMeta(accounts.newRewardEmissionsSuperAuthority), + ], + programAddress, + data: getSetRewardEmissionsSuperAuthorityInstructionDataEncoder().encode( + {}, + ), + } as SetRewardEmissionsSuperAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountRewardEmissionsSuperAuthority, + TAccountNewRewardEmissionsSuperAuthority + >; + + return instruction; +} + +export interface ParsedSetRewardEmissionsSuperAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + rewardEmissionsSuperAuthority: TAccountMetas[1]; + newRewardEmissionsSuperAuthority: TAccountMetas[2]; + }; + data: SetRewardEmissionsSuperAuthorityInstructionData; +} + +export function parseSetRewardEmissionsSuperAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetRewardEmissionsSuperAuthorityInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + rewardEmissionsSuperAuthority: getNextAccount(), + newRewardEmissionsSuperAuthority: getNextAccount(), + }, + data: getSetRewardEmissionsSuperAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setRewardEmissionsV2.ts b/clients/orca-whirlpools/src/generated/instructions/setRewardEmissionsV2.ts new file mode 100644 index 00000000..e476365e --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setRewardEmissionsV2.ts @@ -0,0 +1,232 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_REWARD_EMISSIONS_V2_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([114, 228, 72, 32, 193, 48, 160, 102]); + +export function getSetRewardEmissionsV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_REWARD_EMISSIONS_V2_DISCRIMINATOR, + ); +} + +export type SetRewardEmissionsV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountRewardAuthority extends string | AccountMeta = string, + TAccountRewardVault extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountRewardAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountRewardAuthority, + TAccountRewardVault extends string + ? ReadonlyAccount + : TAccountRewardVault, + ...TRemainingAccounts, + ] + >; + +export interface SetRewardEmissionsV2InstructionData { + discriminator: ReadonlyUint8Array; + rewardIndex: number; + emissionsPerSecondX64: bigint; +} + +export interface SetRewardEmissionsV2InstructionDataArgs { + rewardIndex: number; + emissionsPerSecondX64: number | bigint; +} + +export function getSetRewardEmissionsV2InstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["rewardIndex", getU8Encoder()], + ["emissionsPerSecondX64", getU128Encoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_REWARD_EMISSIONS_V2_DISCRIMINATOR, + }), + ); +} + +export function getSetRewardEmissionsV2InstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["rewardIndex", getU8Decoder()], + ["emissionsPerSecondX64", getU128Decoder()], + ]); +} + +export function getSetRewardEmissionsV2InstructionDataCodec(): FixedSizeCodec< + SetRewardEmissionsV2InstructionDataArgs, + SetRewardEmissionsV2InstructionData +> { + return combineCodec( + getSetRewardEmissionsV2InstructionDataEncoder(), + getSetRewardEmissionsV2InstructionDataDecoder(), + ); +} + +export interface SetRewardEmissionsV2Input< + TAccountWhirlpool extends string = string, + TAccountRewardAuthority extends string = string, + TAccountRewardVault extends string = string, +> { + whirlpool: Address; + rewardAuthority: TransactionSigner; + rewardVault: Address; + rewardIndex: SetRewardEmissionsV2InstructionDataArgs["rewardIndex"]; + emissionsPerSecondX64: SetRewardEmissionsV2InstructionDataArgs["emissionsPerSecondX64"]; +} + +export function getSetRewardEmissionsV2Instruction< + TAccountWhirlpool extends string, + TAccountRewardAuthority extends string, + TAccountRewardVault extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetRewardEmissionsV2Input< + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountRewardVault + >, + config?: { programAddress?: TProgramAddress }, +): SetRewardEmissionsV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountRewardVault +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + rewardAuthority: { + value: input.rewardAuthority ?? null, + isWritable: false, + }, + rewardVault: { value: input.rewardVault ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.rewardAuthority), + getAccountMeta(accounts.rewardVault), + ], + programAddress, + data: getSetRewardEmissionsV2InstructionDataEncoder().encode( + args as SetRewardEmissionsV2InstructionDataArgs, + ), + } as SetRewardEmissionsV2Instruction< + TProgramAddress, + TAccountWhirlpool, + TAccountRewardAuthority, + TAccountRewardVault + >; + + return instruction; +} + +export interface ParsedSetRewardEmissionsV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + rewardAuthority: TAccountMetas[1]; + rewardVault: TAccountMetas[2]; + }; + data: SetRewardEmissionsV2InstructionData; +} + +export function parseSetRewardEmissionsV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetRewardEmissionsV2Instruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + rewardAuthority: getNextAccount(), + rewardVault: getNextAccount(), + }, + data: getSetRewardEmissionsV2InstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/setTokenBadgeAuthority.ts b/clients/orca-whirlpools/src/generated/instructions/setTokenBadgeAuthority.ts new file mode 100644 index 00000000..576750da --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/setTokenBadgeAuthority.ts @@ -0,0 +1,233 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_TOKEN_BADGE_AUTHORITY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([207, 202, 4, 32, 205, 79, 13, 178]); + +export function getSetTokenBadgeAuthorityDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_TOKEN_BADGE_AUTHORITY_DISCRIMINATOR, + ); +} + +export type SetTokenBadgeAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolsConfig extends string | AccountMeta = string, + TAccountWhirlpoolsConfigExtension extends string | AccountMeta = string, + TAccountConfigExtensionAuthority extends string | AccountMeta = string, + TAccountNewTokenBadgeAuthority extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolsConfig extends string + ? ReadonlyAccount + : TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension extends string + ? WritableAccount + : TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountConfigExtensionAuthority, + TAccountNewTokenBadgeAuthority extends string + ? ReadonlyAccount + : TAccountNewTokenBadgeAuthority, + ...TRemainingAccounts, + ] + >; + +export interface SetTokenBadgeAuthorityInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface SetTokenBadgeAuthorityInstructionDataArgs {} + +export function getSetTokenBadgeAuthorityInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: SET_TOKEN_BADGE_AUTHORITY_DISCRIMINATOR, + }), + ); +} + +export function getSetTokenBadgeAuthorityInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getSetTokenBadgeAuthorityInstructionDataCodec(): FixedSizeCodec< + SetTokenBadgeAuthorityInstructionDataArgs, + SetTokenBadgeAuthorityInstructionData +> { + return combineCodec( + getSetTokenBadgeAuthorityInstructionDataEncoder(), + getSetTokenBadgeAuthorityInstructionDataDecoder(), + ); +} + +export interface SetTokenBadgeAuthorityInput< + TAccountWhirlpoolsConfig extends string = string, + TAccountWhirlpoolsConfigExtension extends string = string, + TAccountConfigExtensionAuthority extends string = string, + TAccountNewTokenBadgeAuthority extends string = string, +> { + whirlpoolsConfig: Address; + whirlpoolsConfigExtension: Address; + configExtensionAuthority: TransactionSigner; + newTokenBadgeAuthority: Address; +} + +export function getSetTokenBadgeAuthorityInstruction< + TAccountWhirlpoolsConfig extends string, + TAccountWhirlpoolsConfigExtension extends string, + TAccountConfigExtensionAuthority extends string, + TAccountNewTokenBadgeAuthority extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SetTokenBadgeAuthorityInput< + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority, + TAccountNewTokenBadgeAuthority + >, + config?: { programAddress?: TProgramAddress }, +): SetTokenBadgeAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority, + TAccountNewTokenBadgeAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolsConfig: { + value: input.whirlpoolsConfig ?? null, + isWritable: false, + }, + whirlpoolsConfigExtension: { + value: input.whirlpoolsConfigExtension ?? null, + isWritable: true, + }, + configExtensionAuthority: { + value: input.configExtensionAuthority ?? null, + isWritable: false, + }, + newTokenBadgeAuthority: { + value: input.newTokenBadgeAuthority ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolsConfig), + getAccountMeta(accounts.whirlpoolsConfigExtension), + getAccountMeta(accounts.configExtensionAuthority), + getAccountMeta(accounts.newTokenBadgeAuthority), + ], + programAddress, + data: getSetTokenBadgeAuthorityInstructionDataEncoder().encode({}), + } as SetTokenBadgeAuthorityInstruction< + TProgramAddress, + TAccountWhirlpoolsConfig, + TAccountWhirlpoolsConfigExtension, + TAccountConfigExtensionAuthority, + TAccountNewTokenBadgeAuthority + >; + + return instruction; +} + +export interface ParsedSetTokenBadgeAuthorityInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolsConfig: TAccountMetas[0]; + whirlpoolsConfigExtension: TAccountMetas[1]; + configExtensionAuthority: TAccountMetas[2]; + newTokenBadgeAuthority: TAccountMetas[3]; + }; + data: SetTokenBadgeAuthorityInstructionData; +} + +export function parseSetTokenBadgeAuthorityInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetTokenBadgeAuthorityInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolsConfig: getNextAccount(), + whirlpoolsConfigExtension: getNextAccount(), + configExtensionAuthority: getNextAccount(), + newTokenBadgeAuthority: getNextAccount(), + }, + data: getSetTokenBadgeAuthorityInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/swap.ts b/clients/orca-whirlpools/src/generated/instructions/swap.ts new file mode 100644 index 00000000..5da7ee1a --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/swap.ts @@ -0,0 +1,358 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBooleanDecoder, + getBooleanEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SWAP_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 248, 198, 158, 145, 225, 117, 135, 200, +]); + +export function getSwapDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(SWAP_DISCRIMINATOR); +} + +export type SwapInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountTokenAuthority extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTickArray0 extends string | AccountMeta = string, + TAccountTickArray1 extends string | AccountMeta = string, + TAccountTickArray2 extends string | AccountMeta = string, + TAccountOracle extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountTokenAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountTokenAuthority, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTickArray0 extends string + ? WritableAccount + : TAccountTickArray0, + TAccountTickArray1 extends string + ? WritableAccount + : TAccountTickArray1, + TAccountTickArray2 extends string + ? WritableAccount + : TAccountTickArray2, + TAccountOracle extends string + ? ReadonlyAccount + : TAccountOracle, + ...TRemainingAccounts, + ] + >; + +export interface SwapInstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + otherAmountThreshold: bigint; + sqrtPriceLimit: bigint; + amountSpecifiedIsInput: boolean; + aToB: boolean; +} + +export interface SwapInstructionDataArgs { + amount: number | bigint; + otherAmountThreshold: number | bigint; + sqrtPriceLimit: number | bigint; + amountSpecifiedIsInput: boolean; + aToB: boolean; +} + +export function getSwapInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["otherAmountThreshold", getU64Encoder()], + ["sqrtPriceLimit", getU128Encoder()], + ["amountSpecifiedIsInput", getBooleanEncoder()], + ["aToB", getBooleanEncoder()], + ]), + (value) => ({ ...value, discriminator: SWAP_DISCRIMINATOR }), + ); +} + +export function getSwapInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["otherAmountThreshold", getU64Decoder()], + ["sqrtPriceLimit", getU128Decoder()], + ["amountSpecifiedIsInput", getBooleanDecoder()], + ["aToB", getBooleanDecoder()], + ]); +} + +export function getSwapInstructionDataCodec(): FixedSizeCodec< + SwapInstructionDataArgs, + SwapInstructionData +> { + return combineCodec( + getSwapInstructionDataEncoder(), + getSwapInstructionDataDecoder(), + ); +} + +export interface SwapInput< + TAccountTokenProgram extends string = string, + TAccountTokenAuthority extends string = string, + TAccountWhirlpool extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTickArray0 extends string = string, + TAccountTickArray1 extends string = string, + TAccountTickArray2 extends string = string, + TAccountOracle extends string = string, +> { + tokenProgram: Address; + tokenAuthority: TransactionSigner; + whirlpool: Address; + tokenOwnerAccountA: Address; + tokenVaultA: Address; + tokenOwnerAccountB: Address; + tokenVaultB: Address; + tickArray0: Address; + tickArray1: Address; + tickArray2: Address; + oracle: Address; + amount: SwapInstructionDataArgs["amount"]; + otherAmountThreshold: SwapInstructionDataArgs["otherAmountThreshold"]; + sqrtPriceLimit: SwapInstructionDataArgs["sqrtPriceLimit"]; + amountSpecifiedIsInput: SwapInstructionDataArgs["amountSpecifiedIsInput"]; + aToB: SwapInstructionDataArgs["aToB"]; +} + +export function getSwapInstruction< + TAccountTokenProgram extends string, + TAccountTokenAuthority extends string, + TAccountWhirlpool extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenVaultA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultB extends string, + TAccountTickArray0 extends string, + TAccountTickArray1 extends string, + TAccountTickArray2 extends string, + TAccountOracle extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SwapInput< + TAccountTokenProgram, + TAccountTokenAuthority, + TAccountWhirlpool, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTickArray0, + TAccountTickArray1, + TAccountTickArray2, + TAccountOracle + >, + config?: { programAddress?: TProgramAddress }, +): SwapInstruction< + TProgramAddress, + TAccountTokenProgram, + TAccountTokenAuthority, + TAccountWhirlpool, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTickArray0, + TAccountTickArray1, + TAccountTickArray2, + TAccountOracle +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tickArray0: { value: input.tickArray0 ?? null, isWritable: true }, + tickArray1: { value: input.tickArray1 ?? null, isWritable: true }, + tickArray2: { value: input.tickArray2 ?? null, isWritable: true }, + oracle: { value: input.oracle ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.tokenAuthority), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tickArray0), + getAccountMeta(accounts.tickArray1), + getAccountMeta(accounts.tickArray2), + getAccountMeta(accounts.oracle), + ], + programAddress, + data: getSwapInstructionDataEncoder().encode( + args as SwapInstructionDataArgs, + ), + } as SwapInstruction< + TProgramAddress, + TAccountTokenProgram, + TAccountTokenAuthority, + TAccountWhirlpool, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTickArray0, + TAccountTickArray1, + TAccountTickArray2, + TAccountOracle + >; + + return instruction; +} + +export interface ParsedSwapInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + tokenProgram: TAccountMetas[0]; + tokenAuthority: TAccountMetas[1]; + whirlpool: TAccountMetas[2]; + tokenOwnerAccountA: TAccountMetas[3]; + tokenVaultA: TAccountMetas[4]; + tokenOwnerAccountB: TAccountMetas[5]; + tokenVaultB: TAccountMetas[6]; + tickArray0: TAccountMetas[7]; + tickArray1: TAccountMetas[8]; + tickArray2: TAccountMetas[9]; + oracle: TAccountMetas[10]; + }; + data: SwapInstructionData; +} + +export function parseSwapInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSwapInstruction { + if (instruction.accounts.length < 11) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + tokenProgram: getNextAccount(), + tokenAuthority: getNextAccount(), + whirlpool: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultB: getNextAccount(), + tickArray0: getNextAccount(), + tickArray1: getNextAccount(), + tickArray2: getNextAccount(), + oracle: getNextAccount(), + }, + data: getSwapInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/swapV2.ts b/clients/orca-whirlpools/src/generated/instructions/swapV2.ts new file mode 100644 index 00000000..79067702 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/swapV2.ts @@ -0,0 +1,437 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBooleanDecoder, + getBooleanEncoder, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const SWAP_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 43, 4, 237, 11, 26, 201, 30, 98, +]); + +export function getSwapV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(SWAP_V2_DISCRIMINATOR); +} + +export type SwapV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountTokenProgramA extends string | AccountMeta = string, + TAccountTokenProgramB extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TAccountTokenAuthority extends string | AccountMeta = string, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountTokenMintA extends string | AccountMeta = string, + TAccountTokenMintB extends string | AccountMeta = string, + TAccountTokenOwnerAccountA extends string | AccountMeta = string, + TAccountTokenVaultA extends string | AccountMeta = string, + TAccountTokenOwnerAccountB extends string | AccountMeta = string, + TAccountTokenVaultB extends string | AccountMeta = string, + TAccountTickArray0 extends string | AccountMeta = string, + TAccountTickArray1 extends string | AccountMeta = string, + TAccountTickArray2 extends string | AccountMeta = string, + TAccountOracle extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountTokenProgramA extends string + ? ReadonlyAccount + : TAccountTokenProgramA, + TAccountTokenProgramB extends string + ? ReadonlyAccount + : TAccountTokenProgramB, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + TAccountTokenAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountTokenAuthority, + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountTokenMintA extends string + ? ReadonlyAccount + : TAccountTokenMintA, + TAccountTokenMintB extends string + ? ReadonlyAccount + : TAccountTokenMintB, + TAccountTokenOwnerAccountA extends string + ? WritableAccount + : TAccountTokenOwnerAccountA, + TAccountTokenVaultA extends string + ? WritableAccount + : TAccountTokenVaultA, + TAccountTokenOwnerAccountB extends string + ? WritableAccount + : TAccountTokenOwnerAccountB, + TAccountTokenVaultB extends string + ? WritableAccount + : TAccountTokenVaultB, + TAccountTickArray0 extends string + ? WritableAccount + : TAccountTickArray0, + TAccountTickArray1 extends string + ? WritableAccount + : TAccountTickArray1, + TAccountTickArray2 extends string + ? WritableAccount + : TAccountTickArray2, + TAccountOracle extends string + ? WritableAccount + : TAccountOracle, + ...TRemainingAccounts, + ] + >; + +export interface SwapV2InstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + otherAmountThreshold: bigint; + sqrtPriceLimit: bigint; + amountSpecifiedIsInput: boolean; + aToB: boolean; + remainingAccountsInfo: Option; +} + +export interface SwapV2InstructionDataArgs { + amount: number | bigint; + otherAmountThreshold: number | bigint; + sqrtPriceLimit: number | bigint; + amountSpecifiedIsInput: boolean; + aToB: boolean; + remainingAccountsInfo: OptionOrNullable; +} + +export function getSwapV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["otherAmountThreshold", getU64Encoder()], + ["sqrtPriceLimit", getU128Encoder()], + ["amountSpecifiedIsInput", getBooleanEncoder()], + ["aToB", getBooleanEncoder()], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ ...value, discriminator: SWAP_V2_DISCRIMINATOR }), + ); +} + +export function getSwapV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["otherAmountThreshold", getU64Decoder()], + ["sqrtPriceLimit", getU128Decoder()], + ["amountSpecifiedIsInput", getBooleanDecoder()], + ["aToB", getBooleanDecoder()], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getSwapV2InstructionDataCodec(): Codec< + SwapV2InstructionDataArgs, + SwapV2InstructionData +> { + return combineCodec( + getSwapV2InstructionDataEncoder(), + getSwapV2InstructionDataDecoder(), + ); +} + +export interface SwapV2Input< + TAccountTokenProgramA extends string = string, + TAccountTokenProgramB extends string = string, + TAccountMemoProgram extends string = string, + TAccountTokenAuthority extends string = string, + TAccountWhirlpool extends string = string, + TAccountTokenMintA extends string = string, + TAccountTokenMintB extends string = string, + TAccountTokenOwnerAccountA extends string = string, + TAccountTokenVaultA extends string = string, + TAccountTokenOwnerAccountB extends string = string, + TAccountTokenVaultB extends string = string, + TAccountTickArray0 extends string = string, + TAccountTickArray1 extends string = string, + TAccountTickArray2 extends string = string, + TAccountOracle extends string = string, +> { + tokenProgramA: Address; + tokenProgramB: Address; + memoProgram: Address; + tokenAuthority: TransactionSigner; + whirlpool: Address; + tokenMintA: Address; + tokenMintB: Address; + tokenOwnerAccountA: Address; + tokenVaultA: Address; + tokenOwnerAccountB: Address; + tokenVaultB: Address; + tickArray0: Address; + tickArray1: Address; + tickArray2: Address; + oracle: Address; + amount: SwapV2InstructionDataArgs["amount"]; + otherAmountThreshold: SwapV2InstructionDataArgs["otherAmountThreshold"]; + sqrtPriceLimit: SwapV2InstructionDataArgs["sqrtPriceLimit"]; + amountSpecifiedIsInput: SwapV2InstructionDataArgs["amountSpecifiedIsInput"]; + aToB: SwapV2InstructionDataArgs["aToB"]; + remainingAccountsInfo: SwapV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getSwapV2Instruction< + TAccountTokenProgramA extends string, + TAccountTokenProgramB extends string, + TAccountMemoProgram extends string, + TAccountTokenAuthority extends string, + TAccountWhirlpool extends string, + TAccountTokenMintA extends string, + TAccountTokenMintB extends string, + TAccountTokenOwnerAccountA extends string, + TAccountTokenVaultA extends string, + TAccountTokenOwnerAccountB extends string, + TAccountTokenVaultB extends string, + TAccountTickArray0 extends string, + TAccountTickArray1 extends string, + TAccountTickArray2 extends string, + TAccountOracle extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: SwapV2Input< + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountTokenAuthority, + TAccountWhirlpool, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTickArray0, + TAccountTickArray1, + TAccountTickArray2, + TAccountOracle + >, + config?: { programAddress?: TProgramAddress }, +): SwapV2Instruction< + TProgramAddress, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountTokenAuthority, + TAccountWhirlpool, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTickArray0, + TAccountTickArray1, + TAccountTickArray2, + TAccountOracle +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + tokenProgramA: { value: input.tokenProgramA ?? null, isWritable: false }, + tokenProgramB: { value: input.tokenProgramB ?? null, isWritable: false }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + tokenMintA: { value: input.tokenMintA ?? null, isWritable: false }, + tokenMintB: { value: input.tokenMintB ?? null, isWritable: false }, + tokenOwnerAccountA: { + value: input.tokenOwnerAccountA ?? null, + isWritable: true, + }, + tokenVaultA: { value: input.tokenVaultA ?? null, isWritable: true }, + tokenOwnerAccountB: { + value: input.tokenOwnerAccountB ?? null, + isWritable: true, + }, + tokenVaultB: { value: input.tokenVaultB ?? null, isWritable: true }, + tickArray0: { value: input.tickArray0 ?? null, isWritable: true }, + tickArray1: { value: input.tickArray1 ?? null, isWritable: true }, + tickArray2: { value: input.tickArray2 ?? null, isWritable: true }, + oracle: { value: input.oracle ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.tokenProgramA), + getAccountMeta(accounts.tokenProgramB), + getAccountMeta(accounts.memoProgram), + getAccountMeta(accounts.tokenAuthority), + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.tokenMintA), + getAccountMeta(accounts.tokenMintB), + getAccountMeta(accounts.tokenOwnerAccountA), + getAccountMeta(accounts.tokenVaultA), + getAccountMeta(accounts.tokenOwnerAccountB), + getAccountMeta(accounts.tokenVaultB), + getAccountMeta(accounts.tickArray0), + getAccountMeta(accounts.tickArray1), + getAccountMeta(accounts.tickArray2), + getAccountMeta(accounts.oracle), + ], + programAddress, + data: getSwapV2InstructionDataEncoder().encode( + args as SwapV2InstructionDataArgs, + ), + } as SwapV2Instruction< + TProgramAddress, + TAccountTokenProgramA, + TAccountTokenProgramB, + TAccountMemoProgram, + TAccountTokenAuthority, + TAccountWhirlpool, + TAccountTokenMintA, + TAccountTokenMintB, + TAccountTokenOwnerAccountA, + TAccountTokenVaultA, + TAccountTokenOwnerAccountB, + TAccountTokenVaultB, + TAccountTickArray0, + TAccountTickArray1, + TAccountTickArray2, + TAccountOracle + >; + + return instruction; +} + +export interface ParsedSwapV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + tokenProgramA: TAccountMetas[0]; + tokenProgramB: TAccountMetas[1]; + memoProgram: TAccountMetas[2]; + tokenAuthority: TAccountMetas[3]; + whirlpool: TAccountMetas[4]; + tokenMintA: TAccountMetas[5]; + tokenMintB: TAccountMetas[6]; + tokenOwnerAccountA: TAccountMetas[7]; + tokenVaultA: TAccountMetas[8]; + tokenOwnerAccountB: TAccountMetas[9]; + tokenVaultB: TAccountMetas[10]; + tickArray0: TAccountMetas[11]; + tickArray1: TAccountMetas[12]; + tickArray2: TAccountMetas[13]; + oracle: TAccountMetas[14]; + }; + data: SwapV2InstructionData; +} + +export function parseSwapV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSwapV2Instruction { + if (instruction.accounts.length < 15) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + tokenProgramA: getNextAccount(), + tokenProgramB: getNextAccount(), + memoProgram: getNextAccount(), + tokenAuthority: getNextAccount(), + whirlpool: getNextAccount(), + tokenMintA: getNextAccount(), + tokenMintB: getNextAccount(), + tokenOwnerAccountA: getNextAccount(), + tokenVaultA: getNextAccount(), + tokenOwnerAccountB: getNextAccount(), + tokenVaultB: getNextAccount(), + tickArray0: getNextAccount(), + tickArray1: getNextAccount(), + tickArray2: getNextAccount(), + oracle: getNextAccount(), + }, + data: getSwapV2InstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/twoHopSwap.ts b/clients/orca-whirlpools/src/generated/instructions/twoHopSwap.ts new file mode 100644 index 00000000..61545172 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/twoHopSwap.ts @@ -0,0 +1,502 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBooleanDecoder, + getBooleanEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const TWO_HOP_SWAP_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 195, 96, 237, 108, 68, 162, 219, 230, +]); + +export function getTwoHopSwapDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + TWO_HOP_SWAP_DISCRIMINATOR, + ); +} + +export type TwoHopSwapInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountTokenProgram extends string | AccountMeta = string, + TAccountTokenAuthority extends string | AccountMeta = string, + TAccountWhirlpoolOne extends string | AccountMeta = string, + TAccountWhirlpoolTwo extends string | AccountMeta = string, + TAccountTokenOwnerAccountOneA extends string | AccountMeta = string, + TAccountTokenVaultOneA extends string | AccountMeta = string, + TAccountTokenOwnerAccountOneB extends string | AccountMeta = string, + TAccountTokenVaultOneB extends string | AccountMeta = string, + TAccountTokenOwnerAccountTwoA extends string | AccountMeta = string, + TAccountTokenVaultTwoA extends string | AccountMeta = string, + TAccountTokenOwnerAccountTwoB extends string | AccountMeta = string, + TAccountTokenVaultTwoB extends string | AccountMeta = string, + TAccountTickArrayOne0 extends string | AccountMeta = string, + TAccountTickArrayOne1 extends string | AccountMeta = string, + TAccountTickArrayOne2 extends string | AccountMeta = string, + TAccountTickArrayTwo0 extends string | AccountMeta = string, + TAccountTickArrayTwo1 extends string | AccountMeta = string, + TAccountTickArrayTwo2 extends string | AccountMeta = string, + TAccountOracleOne extends string | AccountMeta = string, + TAccountOracleTwo extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountTokenAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountTokenAuthority, + TAccountWhirlpoolOne extends string + ? WritableAccount + : TAccountWhirlpoolOne, + TAccountWhirlpoolTwo extends string + ? WritableAccount + : TAccountWhirlpoolTwo, + TAccountTokenOwnerAccountOneA extends string + ? WritableAccount + : TAccountTokenOwnerAccountOneA, + TAccountTokenVaultOneA extends string + ? WritableAccount + : TAccountTokenVaultOneA, + TAccountTokenOwnerAccountOneB extends string + ? WritableAccount + : TAccountTokenOwnerAccountOneB, + TAccountTokenVaultOneB extends string + ? WritableAccount + : TAccountTokenVaultOneB, + TAccountTokenOwnerAccountTwoA extends string + ? WritableAccount + : TAccountTokenOwnerAccountTwoA, + TAccountTokenVaultTwoA extends string + ? WritableAccount + : TAccountTokenVaultTwoA, + TAccountTokenOwnerAccountTwoB extends string + ? WritableAccount + : TAccountTokenOwnerAccountTwoB, + TAccountTokenVaultTwoB extends string + ? WritableAccount + : TAccountTokenVaultTwoB, + TAccountTickArrayOne0 extends string + ? WritableAccount + : TAccountTickArrayOne0, + TAccountTickArrayOne1 extends string + ? WritableAccount + : TAccountTickArrayOne1, + TAccountTickArrayOne2 extends string + ? WritableAccount + : TAccountTickArrayOne2, + TAccountTickArrayTwo0 extends string + ? WritableAccount + : TAccountTickArrayTwo0, + TAccountTickArrayTwo1 extends string + ? WritableAccount + : TAccountTickArrayTwo1, + TAccountTickArrayTwo2 extends string + ? WritableAccount + : TAccountTickArrayTwo2, + TAccountOracleOne extends string + ? ReadonlyAccount + : TAccountOracleOne, + TAccountOracleTwo extends string + ? ReadonlyAccount + : TAccountOracleTwo, + ...TRemainingAccounts, + ] + >; + +export interface TwoHopSwapInstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + otherAmountThreshold: bigint; + amountSpecifiedIsInput: boolean; + aToBOne: boolean; + aToBTwo: boolean; + sqrtPriceLimitOne: bigint; + sqrtPriceLimitTwo: bigint; +} + +export interface TwoHopSwapInstructionDataArgs { + amount: number | bigint; + otherAmountThreshold: number | bigint; + amountSpecifiedIsInput: boolean; + aToBOne: boolean; + aToBTwo: boolean; + sqrtPriceLimitOne: number | bigint; + sqrtPriceLimitTwo: number | bigint; +} + +export function getTwoHopSwapInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["otherAmountThreshold", getU64Encoder()], + ["amountSpecifiedIsInput", getBooleanEncoder()], + ["aToBOne", getBooleanEncoder()], + ["aToBTwo", getBooleanEncoder()], + ["sqrtPriceLimitOne", getU128Encoder()], + ["sqrtPriceLimitTwo", getU128Encoder()], + ]), + (value) => ({ ...value, discriminator: TWO_HOP_SWAP_DISCRIMINATOR }), + ); +} + +export function getTwoHopSwapInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["otherAmountThreshold", getU64Decoder()], + ["amountSpecifiedIsInput", getBooleanDecoder()], + ["aToBOne", getBooleanDecoder()], + ["aToBTwo", getBooleanDecoder()], + ["sqrtPriceLimitOne", getU128Decoder()], + ["sqrtPriceLimitTwo", getU128Decoder()], + ]); +} + +export function getTwoHopSwapInstructionDataCodec(): FixedSizeCodec< + TwoHopSwapInstructionDataArgs, + TwoHopSwapInstructionData +> { + return combineCodec( + getTwoHopSwapInstructionDataEncoder(), + getTwoHopSwapInstructionDataDecoder(), + ); +} + +export interface TwoHopSwapInput< + TAccountTokenProgram extends string = string, + TAccountTokenAuthority extends string = string, + TAccountWhirlpoolOne extends string = string, + TAccountWhirlpoolTwo extends string = string, + TAccountTokenOwnerAccountOneA extends string = string, + TAccountTokenVaultOneA extends string = string, + TAccountTokenOwnerAccountOneB extends string = string, + TAccountTokenVaultOneB extends string = string, + TAccountTokenOwnerAccountTwoA extends string = string, + TAccountTokenVaultTwoA extends string = string, + TAccountTokenOwnerAccountTwoB extends string = string, + TAccountTokenVaultTwoB extends string = string, + TAccountTickArrayOne0 extends string = string, + TAccountTickArrayOne1 extends string = string, + TAccountTickArrayOne2 extends string = string, + TAccountTickArrayTwo0 extends string = string, + TAccountTickArrayTwo1 extends string = string, + TAccountTickArrayTwo2 extends string = string, + TAccountOracleOne extends string = string, + TAccountOracleTwo extends string = string, +> { + tokenProgram: Address; + tokenAuthority: TransactionSigner; + whirlpoolOne: Address; + whirlpoolTwo: Address; + tokenOwnerAccountOneA: Address; + tokenVaultOneA: Address; + tokenOwnerAccountOneB: Address; + tokenVaultOneB: Address; + tokenOwnerAccountTwoA: Address; + tokenVaultTwoA: Address; + tokenOwnerAccountTwoB: Address; + tokenVaultTwoB: Address; + tickArrayOne0: Address; + tickArrayOne1: Address; + tickArrayOne2: Address; + tickArrayTwo0: Address; + tickArrayTwo1: Address; + tickArrayTwo2: Address; + oracleOne: Address; + oracleTwo: Address; + amount: TwoHopSwapInstructionDataArgs["amount"]; + otherAmountThreshold: TwoHopSwapInstructionDataArgs["otherAmountThreshold"]; + amountSpecifiedIsInput: TwoHopSwapInstructionDataArgs["amountSpecifiedIsInput"]; + aToBOne: TwoHopSwapInstructionDataArgs["aToBOne"]; + aToBTwo: TwoHopSwapInstructionDataArgs["aToBTwo"]; + sqrtPriceLimitOne: TwoHopSwapInstructionDataArgs["sqrtPriceLimitOne"]; + sqrtPriceLimitTwo: TwoHopSwapInstructionDataArgs["sqrtPriceLimitTwo"]; +} + +export function getTwoHopSwapInstruction< + TAccountTokenProgram extends string, + TAccountTokenAuthority extends string, + TAccountWhirlpoolOne extends string, + TAccountWhirlpoolTwo extends string, + TAccountTokenOwnerAccountOneA extends string, + TAccountTokenVaultOneA extends string, + TAccountTokenOwnerAccountOneB extends string, + TAccountTokenVaultOneB extends string, + TAccountTokenOwnerAccountTwoA extends string, + TAccountTokenVaultTwoA extends string, + TAccountTokenOwnerAccountTwoB extends string, + TAccountTokenVaultTwoB extends string, + TAccountTickArrayOne0 extends string, + TAccountTickArrayOne1 extends string, + TAccountTickArrayOne2 extends string, + TAccountTickArrayTwo0 extends string, + TAccountTickArrayTwo1 extends string, + TAccountTickArrayTwo2 extends string, + TAccountOracleOne extends string, + TAccountOracleTwo extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: TwoHopSwapInput< + TAccountTokenProgram, + TAccountTokenAuthority, + TAccountWhirlpoolOne, + TAccountWhirlpoolTwo, + TAccountTokenOwnerAccountOneA, + TAccountTokenVaultOneA, + TAccountTokenOwnerAccountOneB, + TAccountTokenVaultOneB, + TAccountTokenOwnerAccountTwoA, + TAccountTokenVaultTwoA, + TAccountTokenOwnerAccountTwoB, + TAccountTokenVaultTwoB, + TAccountTickArrayOne0, + TAccountTickArrayOne1, + TAccountTickArrayOne2, + TAccountTickArrayTwo0, + TAccountTickArrayTwo1, + TAccountTickArrayTwo2, + TAccountOracleOne, + TAccountOracleTwo + >, + config?: { programAddress?: TProgramAddress }, +): TwoHopSwapInstruction< + TProgramAddress, + TAccountTokenProgram, + TAccountTokenAuthority, + TAccountWhirlpoolOne, + TAccountWhirlpoolTwo, + TAccountTokenOwnerAccountOneA, + TAccountTokenVaultOneA, + TAccountTokenOwnerAccountOneB, + TAccountTokenVaultOneB, + TAccountTokenOwnerAccountTwoA, + TAccountTokenVaultTwoA, + TAccountTokenOwnerAccountTwoB, + TAccountTokenVaultTwoB, + TAccountTickArrayOne0, + TAccountTickArrayOne1, + TAccountTickArrayOne2, + TAccountTickArrayTwo0, + TAccountTickArrayTwo1, + TAccountTickArrayTwo2, + TAccountOracleOne, + TAccountOracleTwo +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, + whirlpoolOne: { value: input.whirlpoolOne ?? null, isWritable: true }, + whirlpoolTwo: { value: input.whirlpoolTwo ?? null, isWritable: true }, + tokenOwnerAccountOneA: { + value: input.tokenOwnerAccountOneA ?? null, + isWritable: true, + }, + tokenVaultOneA: { value: input.tokenVaultOneA ?? null, isWritable: true }, + tokenOwnerAccountOneB: { + value: input.tokenOwnerAccountOneB ?? null, + isWritable: true, + }, + tokenVaultOneB: { value: input.tokenVaultOneB ?? null, isWritable: true }, + tokenOwnerAccountTwoA: { + value: input.tokenOwnerAccountTwoA ?? null, + isWritable: true, + }, + tokenVaultTwoA: { value: input.tokenVaultTwoA ?? null, isWritable: true }, + tokenOwnerAccountTwoB: { + value: input.tokenOwnerAccountTwoB ?? null, + isWritable: true, + }, + tokenVaultTwoB: { value: input.tokenVaultTwoB ?? null, isWritable: true }, + tickArrayOne0: { value: input.tickArrayOne0 ?? null, isWritable: true }, + tickArrayOne1: { value: input.tickArrayOne1 ?? null, isWritable: true }, + tickArrayOne2: { value: input.tickArrayOne2 ?? null, isWritable: true }, + tickArrayTwo0: { value: input.tickArrayTwo0 ?? null, isWritable: true }, + tickArrayTwo1: { value: input.tickArrayTwo1 ?? null, isWritable: true }, + tickArrayTwo2: { value: input.tickArrayTwo2 ?? null, isWritable: true }, + oracleOne: { value: input.oracleOne ?? null, isWritable: false }, + oracleTwo: { value: input.oracleTwo ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.tokenAuthority), + getAccountMeta(accounts.whirlpoolOne), + getAccountMeta(accounts.whirlpoolTwo), + getAccountMeta(accounts.tokenOwnerAccountOneA), + getAccountMeta(accounts.tokenVaultOneA), + getAccountMeta(accounts.tokenOwnerAccountOneB), + getAccountMeta(accounts.tokenVaultOneB), + getAccountMeta(accounts.tokenOwnerAccountTwoA), + getAccountMeta(accounts.tokenVaultTwoA), + getAccountMeta(accounts.tokenOwnerAccountTwoB), + getAccountMeta(accounts.tokenVaultTwoB), + getAccountMeta(accounts.tickArrayOne0), + getAccountMeta(accounts.tickArrayOne1), + getAccountMeta(accounts.tickArrayOne2), + getAccountMeta(accounts.tickArrayTwo0), + getAccountMeta(accounts.tickArrayTwo1), + getAccountMeta(accounts.tickArrayTwo2), + getAccountMeta(accounts.oracleOne), + getAccountMeta(accounts.oracleTwo), + ], + programAddress, + data: getTwoHopSwapInstructionDataEncoder().encode( + args as TwoHopSwapInstructionDataArgs, + ), + } as TwoHopSwapInstruction< + TProgramAddress, + TAccountTokenProgram, + TAccountTokenAuthority, + TAccountWhirlpoolOne, + TAccountWhirlpoolTwo, + TAccountTokenOwnerAccountOneA, + TAccountTokenVaultOneA, + TAccountTokenOwnerAccountOneB, + TAccountTokenVaultOneB, + TAccountTokenOwnerAccountTwoA, + TAccountTokenVaultTwoA, + TAccountTokenOwnerAccountTwoB, + TAccountTokenVaultTwoB, + TAccountTickArrayOne0, + TAccountTickArrayOne1, + TAccountTickArrayOne2, + TAccountTickArrayTwo0, + TAccountTickArrayTwo1, + TAccountTickArrayTwo2, + TAccountOracleOne, + TAccountOracleTwo + >; + + return instruction; +} + +export interface ParsedTwoHopSwapInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + tokenProgram: TAccountMetas[0]; + tokenAuthority: TAccountMetas[1]; + whirlpoolOne: TAccountMetas[2]; + whirlpoolTwo: TAccountMetas[3]; + tokenOwnerAccountOneA: TAccountMetas[4]; + tokenVaultOneA: TAccountMetas[5]; + tokenOwnerAccountOneB: TAccountMetas[6]; + tokenVaultOneB: TAccountMetas[7]; + tokenOwnerAccountTwoA: TAccountMetas[8]; + tokenVaultTwoA: TAccountMetas[9]; + tokenOwnerAccountTwoB: TAccountMetas[10]; + tokenVaultTwoB: TAccountMetas[11]; + tickArrayOne0: TAccountMetas[12]; + tickArrayOne1: TAccountMetas[13]; + tickArrayOne2: TAccountMetas[14]; + tickArrayTwo0: TAccountMetas[15]; + tickArrayTwo1: TAccountMetas[16]; + tickArrayTwo2: TAccountMetas[17]; + oracleOne: TAccountMetas[18]; + oracleTwo: TAccountMetas[19]; + }; + data: TwoHopSwapInstructionData; +} + +export function parseTwoHopSwapInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedTwoHopSwapInstruction { + if (instruction.accounts.length < 20) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + tokenProgram: getNextAccount(), + tokenAuthority: getNextAccount(), + whirlpoolOne: getNextAccount(), + whirlpoolTwo: getNextAccount(), + tokenOwnerAccountOneA: getNextAccount(), + tokenVaultOneA: getNextAccount(), + tokenOwnerAccountOneB: getNextAccount(), + tokenVaultOneB: getNextAccount(), + tokenOwnerAccountTwoA: getNextAccount(), + tokenVaultTwoA: getNextAccount(), + tokenOwnerAccountTwoB: getNextAccount(), + tokenVaultTwoB: getNextAccount(), + tickArrayOne0: getNextAccount(), + tickArrayOne1: getNextAccount(), + tickArrayOne2: getNextAccount(), + tickArrayTwo0: getNextAccount(), + tickArrayTwo1: getNextAccount(), + tickArrayTwo2: getNextAccount(), + oracleOne: getNextAccount(), + oracleTwo: getNextAccount(), + }, + data: getTwoHopSwapInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/twoHopSwapV2.ts b/clients/orca-whirlpools/src/generated/instructions/twoHopSwapV2.ts new file mode 100644 index 00000000..5b0f26b2 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/twoHopSwapV2.ts @@ -0,0 +1,602 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + Option, + OptionOrNullable, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBooleanDecoder, + getBooleanEncoder, + getBytesDecoder, + getBytesEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import type { + RemainingAccountsInfo, + RemainingAccountsInfoArgs, +} from "../types/index.js"; +import { + getRemainingAccountsInfoDecoder, + getRemainingAccountsInfoEncoder, +} from "../types/index.js"; + +export const TWO_HOP_SWAP_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [186, 143, 209, 29, 254, 2, 194, 117], +); + +export function getTwoHopSwapV2DiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + TWO_HOP_SWAP_V2_DISCRIMINATOR, + ); +} + +export type TwoHopSwapV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpoolOne extends string | AccountMeta = string, + TAccountWhirlpoolTwo extends string | AccountMeta = string, + TAccountTokenMintInput extends string | AccountMeta = string, + TAccountTokenMintIntermediate extends string | AccountMeta = string, + TAccountTokenMintOutput extends string | AccountMeta = string, + TAccountTokenProgramInput extends string | AccountMeta = string, + TAccountTokenProgramIntermediate extends string | AccountMeta = string, + TAccountTokenProgramOutput extends string | AccountMeta = string, + TAccountTokenOwnerAccountInput extends string | AccountMeta = string, + TAccountTokenVaultOneInput extends string | AccountMeta = string, + TAccountTokenVaultOneIntermediate extends string | AccountMeta = string, + TAccountTokenVaultTwoIntermediate extends string | AccountMeta = string, + TAccountTokenVaultTwoOutput extends string | AccountMeta = string, + TAccountTokenOwnerAccountOutput extends string | AccountMeta = string, + TAccountTokenAuthority extends string | AccountMeta = string, + TAccountTickArrayOne0 extends string | AccountMeta = string, + TAccountTickArrayOne1 extends string | AccountMeta = string, + TAccountTickArrayOne2 extends string | AccountMeta = string, + TAccountTickArrayTwo0 extends string | AccountMeta = string, + TAccountTickArrayTwo1 extends string | AccountMeta = string, + TAccountTickArrayTwo2 extends string | AccountMeta = string, + TAccountOracleOne extends string | AccountMeta = string, + TAccountOracleTwo extends string | AccountMeta = string, + TAccountMemoProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpoolOne extends string + ? WritableAccount + : TAccountWhirlpoolOne, + TAccountWhirlpoolTwo extends string + ? WritableAccount + : TAccountWhirlpoolTwo, + TAccountTokenMintInput extends string + ? ReadonlyAccount + : TAccountTokenMintInput, + TAccountTokenMintIntermediate extends string + ? ReadonlyAccount + : TAccountTokenMintIntermediate, + TAccountTokenMintOutput extends string + ? ReadonlyAccount + : TAccountTokenMintOutput, + TAccountTokenProgramInput extends string + ? ReadonlyAccount + : TAccountTokenProgramInput, + TAccountTokenProgramIntermediate extends string + ? ReadonlyAccount + : TAccountTokenProgramIntermediate, + TAccountTokenProgramOutput extends string + ? ReadonlyAccount + : TAccountTokenProgramOutput, + TAccountTokenOwnerAccountInput extends string + ? WritableAccount + : TAccountTokenOwnerAccountInput, + TAccountTokenVaultOneInput extends string + ? WritableAccount + : TAccountTokenVaultOneInput, + TAccountTokenVaultOneIntermediate extends string + ? WritableAccount + : TAccountTokenVaultOneIntermediate, + TAccountTokenVaultTwoIntermediate extends string + ? WritableAccount + : TAccountTokenVaultTwoIntermediate, + TAccountTokenVaultTwoOutput extends string + ? WritableAccount + : TAccountTokenVaultTwoOutput, + TAccountTokenOwnerAccountOutput extends string + ? WritableAccount + : TAccountTokenOwnerAccountOutput, + TAccountTokenAuthority extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountTokenAuthority, + TAccountTickArrayOne0 extends string + ? WritableAccount + : TAccountTickArrayOne0, + TAccountTickArrayOne1 extends string + ? WritableAccount + : TAccountTickArrayOne1, + TAccountTickArrayOne2 extends string + ? WritableAccount + : TAccountTickArrayOne2, + TAccountTickArrayTwo0 extends string + ? WritableAccount + : TAccountTickArrayTwo0, + TAccountTickArrayTwo1 extends string + ? WritableAccount + : TAccountTickArrayTwo1, + TAccountTickArrayTwo2 extends string + ? WritableAccount + : TAccountTickArrayTwo2, + TAccountOracleOne extends string + ? WritableAccount + : TAccountOracleOne, + TAccountOracleTwo extends string + ? WritableAccount + : TAccountOracleTwo, + TAccountMemoProgram extends string + ? ReadonlyAccount + : TAccountMemoProgram, + ...TRemainingAccounts, + ] + >; + +export interface TwoHopSwapV2InstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + otherAmountThreshold: bigint; + amountSpecifiedIsInput: boolean; + aToBOne: boolean; + aToBTwo: boolean; + sqrtPriceLimitOne: bigint; + sqrtPriceLimitTwo: bigint; + remainingAccountsInfo: Option; +} + +export interface TwoHopSwapV2InstructionDataArgs { + amount: number | bigint; + otherAmountThreshold: number | bigint; + amountSpecifiedIsInput: boolean; + aToBOne: boolean; + aToBTwo: boolean; + sqrtPriceLimitOne: number | bigint; + sqrtPriceLimitTwo: number | bigint; + remainingAccountsInfo: OptionOrNullable; +} + +export function getTwoHopSwapV2InstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["otherAmountThreshold", getU64Encoder()], + ["amountSpecifiedIsInput", getBooleanEncoder()], + ["aToBOne", getBooleanEncoder()], + ["aToBTwo", getBooleanEncoder()], + ["sqrtPriceLimitOne", getU128Encoder()], + ["sqrtPriceLimitTwo", getU128Encoder()], + [ + "remainingAccountsInfo", + getOptionEncoder(getRemainingAccountsInfoEncoder()), + ], + ]), + (value) => ({ ...value, discriminator: TWO_HOP_SWAP_V2_DISCRIMINATOR }), + ); +} + +export function getTwoHopSwapV2InstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["otherAmountThreshold", getU64Decoder()], + ["amountSpecifiedIsInput", getBooleanDecoder()], + ["aToBOne", getBooleanDecoder()], + ["aToBTwo", getBooleanDecoder()], + ["sqrtPriceLimitOne", getU128Decoder()], + ["sqrtPriceLimitTwo", getU128Decoder()], + [ + "remainingAccountsInfo", + getOptionDecoder(getRemainingAccountsInfoDecoder()), + ], + ]); +} + +export function getTwoHopSwapV2InstructionDataCodec(): Codec< + TwoHopSwapV2InstructionDataArgs, + TwoHopSwapV2InstructionData +> { + return combineCodec( + getTwoHopSwapV2InstructionDataEncoder(), + getTwoHopSwapV2InstructionDataDecoder(), + ); +} + +export interface TwoHopSwapV2Input< + TAccountWhirlpoolOne extends string = string, + TAccountWhirlpoolTwo extends string = string, + TAccountTokenMintInput extends string = string, + TAccountTokenMintIntermediate extends string = string, + TAccountTokenMintOutput extends string = string, + TAccountTokenProgramInput extends string = string, + TAccountTokenProgramIntermediate extends string = string, + TAccountTokenProgramOutput extends string = string, + TAccountTokenOwnerAccountInput extends string = string, + TAccountTokenVaultOneInput extends string = string, + TAccountTokenVaultOneIntermediate extends string = string, + TAccountTokenVaultTwoIntermediate extends string = string, + TAccountTokenVaultTwoOutput extends string = string, + TAccountTokenOwnerAccountOutput extends string = string, + TAccountTokenAuthority extends string = string, + TAccountTickArrayOne0 extends string = string, + TAccountTickArrayOne1 extends string = string, + TAccountTickArrayOne2 extends string = string, + TAccountTickArrayTwo0 extends string = string, + TAccountTickArrayTwo1 extends string = string, + TAccountTickArrayTwo2 extends string = string, + TAccountOracleOne extends string = string, + TAccountOracleTwo extends string = string, + TAccountMemoProgram extends string = string, +> { + whirlpoolOne: Address; + whirlpoolTwo: Address; + tokenMintInput: Address; + tokenMintIntermediate: Address; + tokenMintOutput: Address; + tokenProgramInput: Address; + tokenProgramIntermediate: Address; + tokenProgramOutput: Address; + tokenOwnerAccountInput: Address; + tokenVaultOneInput: Address; + tokenVaultOneIntermediate: Address; + tokenVaultTwoIntermediate: Address; + tokenVaultTwoOutput: Address; + tokenOwnerAccountOutput: Address; + tokenAuthority: TransactionSigner; + tickArrayOne0: Address; + tickArrayOne1: Address; + tickArrayOne2: Address; + tickArrayTwo0: Address; + tickArrayTwo1: Address; + tickArrayTwo2: Address; + oracleOne: Address; + oracleTwo: Address; + memoProgram: Address; + amount: TwoHopSwapV2InstructionDataArgs["amount"]; + otherAmountThreshold: TwoHopSwapV2InstructionDataArgs["otherAmountThreshold"]; + amountSpecifiedIsInput: TwoHopSwapV2InstructionDataArgs["amountSpecifiedIsInput"]; + aToBOne: TwoHopSwapV2InstructionDataArgs["aToBOne"]; + aToBTwo: TwoHopSwapV2InstructionDataArgs["aToBTwo"]; + sqrtPriceLimitOne: TwoHopSwapV2InstructionDataArgs["sqrtPriceLimitOne"]; + sqrtPriceLimitTwo: TwoHopSwapV2InstructionDataArgs["sqrtPriceLimitTwo"]; + remainingAccountsInfo: TwoHopSwapV2InstructionDataArgs["remainingAccountsInfo"]; +} + +export function getTwoHopSwapV2Instruction< + TAccountWhirlpoolOne extends string, + TAccountWhirlpoolTwo extends string, + TAccountTokenMintInput extends string, + TAccountTokenMintIntermediate extends string, + TAccountTokenMintOutput extends string, + TAccountTokenProgramInput extends string, + TAccountTokenProgramIntermediate extends string, + TAccountTokenProgramOutput extends string, + TAccountTokenOwnerAccountInput extends string, + TAccountTokenVaultOneInput extends string, + TAccountTokenVaultOneIntermediate extends string, + TAccountTokenVaultTwoIntermediate extends string, + TAccountTokenVaultTwoOutput extends string, + TAccountTokenOwnerAccountOutput extends string, + TAccountTokenAuthority extends string, + TAccountTickArrayOne0 extends string, + TAccountTickArrayOne1 extends string, + TAccountTickArrayOne2 extends string, + TAccountTickArrayTwo0 extends string, + TAccountTickArrayTwo1 extends string, + TAccountTickArrayTwo2 extends string, + TAccountOracleOne extends string, + TAccountOracleTwo extends string, + TAccountMemoProgram extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: TwoHopSwapV2Input< + TAccountWhirlpoolOne, + TAccountWhirlpoolTwo, + TAccountTokenMintInput, + TAccountTokenMintIntermediate, + TAccountTokenMintOutput, + TAccountTokenProgramInput, + TAccountTokenProgramIntermediate, + TAccountTokenProgramOutput, + TAccountTokenOwnerAccountInput, + TAccountTokenVaultOneInput, + TAccountTokenVaultOneIntermediate, + TAccountTokenVaultTwoIntermediate, + TAccountTokenVaultTwoOutput, + TAccountTokenOwnerAccountOutput, + TAccountTokenAuthority, + TAccountTickArrayOne0, + TAccountTickArrayOne1, + TAccountTickArrayOne2, + TAccountTickArrayTwo0, + TAccountTickArrayTwo1, + TAccountTickArrayTwo2, + TAccountOracleOne, + TAccountOracleTwo, + TAccountMemoProgram + >, + config?: { programAddress?: TProgramAddress }, +): TwoHopSwapV2Instruction< + TProgramAddress, + TAccountWhirlpoolOne, + TAccountWhirlpoolTwo, + TAccountTokenMintInput, + TAccountTokenMintIntermediate, + TAccountTokenMintOutput, + TAccountTokenProgramInput, + TAccountTokenProgramIntermediate, + TAccountTokenProgramOutput, + TAccountTokenOwnerAccountInput, + TAccountTokenVaultOneInput, + TAccountTokenVaultOneIntermediate, + TAccountTokenVaultTwoIntermediate, + TAccountTokenVaultTwoOutput, + TAccountTokenOwnerAccountOutput, + TAccountTokenAuthority, + TAccountTickArrayOne0, + TAccountTickArrayOne1, + TAccountTickArrayOne2, + TAccountTickArrayTwo0, + TAccountTickArrayTwo1, + TAccountTickArrayTwo2, + TAccountOracleOne, + TAccountOracleTwo, + TAccountMemoProgram +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpoolOne: { value: input.whirlpoolOne ?? null, isWritable: true }, + whirlpoolTwo: { value: input.whirlpoolTwo ?? null, isWritable: true }, + tokenMintInput: { value: input.tokenMintInput ?? null, isWritable: false }, + tokenMintIntermediate: { + value: input.tokenMintIntermediate ?? null, + isWritable: false, + }, + tokenMintOutput: { + value: input.tokenMintOutput ?? null, + isWritable: false, + }, + tokenProgramInput: { + value: input.tokenProgramInput ?? null, + isWritable: false, + }, + tokenProgramIntermediate: { + value: input.tokenProgramIntermediate ?? null, + isWritable: false, + }, + tokenProgramOutput: { + value: input.tokenProgramOutput ?? null, + isWritable: false, + }, + tokenOwnerAccountInput: { + value: input.tokenOwnerAccountInput ?? null, + isWritable: true, + }, + tokenVaultOneInput: { + value: input.tokenVaultOneInput ?? null, + isWritable: true, + }, + tokenVaultOneIntermediate: { + value: input.tokenVaultOneIntermediate ?? null, + isWritable: true, + }, + tokenVaultTwoIntermediate: { + value: input.tokenVaultTwoIntermediate ?? null, + isWritable: true, + }, + tokenVaultTwoOutput: { + value: input.tokenVaultTwoOutput ?? null, + isWritable: true, + }, + tokenOwnerAccountOutput: { + value: input.tokenOwnerAccountOutput ?? null, + isWritable: true, + }, + tokenAuthority: { value: input.tokenAuthority ?? null, isWritable: false }, + tickArrayOne0: { value: input.tickArrayOne0 ?? null, isWritable: true }, + tickArrayOne1: { value: input.tickArrayOne1 ?? null, isWritable: true }, + tickArrayOne2: { value: input.tickArrayOne2 ?? null, isWritable: true }, + tickArrayTwo0: { value: input.tickArrayTwo0 ?? null, isWritable: true }, + tickArrayTwo1: { value: input.tickArrayTwo1 ?? null, isWritable: true }, + tickArrayTwo2: { value: input.tickArrayTwo2 ?? null, isWritable: true }, + oracleOne: { value: input.oracleOne ?? null, isWritable: true }, + oracleTwo: { value: input.oracleTwo ?? null, isWritable: true }, + memoProgram: { value: input.memoProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpoolOne), + getAccountMeta(accounts.whirlpoolTwo), + getAccountMeta(accounts.tokenMintInput), + getAccountMeta(accounts.tokenMintIntermediate), + getAccountMeta(accounts.tokenMintOutput), + getAccountMeta(accounts.tokenProgramInput), + getAccountMeta(accounts.tokenProgramIntermediate), + getAccountMeta(accounts.tokenProgramOutput), + getAccountMeta(accounts.tokenOwnerAccountInput), + getAccountMeta(accounts.tokenVaultOneInput), + getAccountMeta(accounts.tokenVaultOneIntermediate), + getAccountMeta(accounts.tokenVaultTwoIntermediate), + getAccountMeta(accounts.tokenVaultTwoOutput), + getAccountMeta(accounts.tokenOwnerAccountOutput), + getAccountMeta(accounts.tokenAuthority), + getAccountMeta(accounts.tickArrayOne0), + getAccountMeta(accounts.tickArrayOne1), + getAccountMeta(accounts.tickArrayOne2), + getAccountMeta(accounts.tickArrayTwo0), + getAccountMeta(accounts.tickArrayTwo1), + getAccountMeta(accounts.tickArrayTwo2), + getAccountMeta(accounts.oracleOne), + getAccountMeta(accounts.oracleTwo), + getAccountMeta(accounts.memoProgram), + ], + programAddress, + data: getTwoHopSwapV2InstructionDataEncoder().encode( + args as TwoHopSwapV2InstructionDataArgs, + ), + } as TwoHopSwapV2Instruction< + TProgramAddress, + TAccountWhirlpoolOne, + TAccountWhirlpoolTwo, + TAccountTokenMintInput, + TAccountTokenMintIntermediate, + TAccountTokenMintOutput, + TAccountTokenProgramInput, + TAccountTokenProgramIntermediate, + TAccountTokenProgramOutput, + TAccountTokenOwnerAccountInput, + TAccountTokenVaultOneInput, + TAccountTokenVaultOneIntermediate, + TAccountTokenVaultTwoIntermediate, + TAccountTokenVaultTwoOutput, + TAccountTokenOwnerAccountOutput, + TAccountTokenAuthority, + TAccountTickArrayOne0, + TAccountTickArrayOne1, + TAccountTickArrayOne2, + TAccountTickArrayTwo0, + TAccountTickArrayTwo1, + TAccountTickArrayTwo2, + TAccountOracleOne, + TAccountOracleTwo, + TAccountMemoProgram + >; + + return instruction; +} + +export interface ParsedTwoHopSwapV2Instruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpoolOne: TAccountMetas[0]; + whirlpoolTwo: TAccountMetas[1]; + tokenMintInput: TAccountMetas[2]; + tokenMintIntermediate: TAccountMetas[3]; + tokenMintOutput: TAccountMetas[4]; + tokenProgramInput: TAccountMetas[5]; + tokenProgramIntermediate: TAccountMetas[6]; + tokenProgramOutput: TAccountMetas[7]; + tokenOwnerAccountInput: TAccountMetas[8]; + tokenVaultOneInput: TAccountMetas[9]; + tokenVaultOneIntermediate: TAccountMetas[10]; + tokenVaultTwoIntermediate: TAccountMetas[11]; + tokenVaultTwoOutput: TAccountMetas[12]; + tokenOwnerAccountOutput: TAccountMetas[13]; + tokenAuthority: TAccountMetas[14]; + tickArrayOne0: TAccountMetas[15]; + tickArrayOne1: TAccountMetas[16]; + tickArrayOne2: TAccountMetas[17]; + tickArrayTwo0: TAccountMetas[18]; + tickArrayTwo1: TAccountMetas[19]; + tickArrayTwo2: TAccountMetas[20]; + oracleOne: TAccountMetas[21]; + oracleTwo: TAccountMetas[22]; + memoProgram: TAccountMetas[23]; + }; + data: TwoHopSwapV2InstructionData; +} + +export function parseTwoHopSwapV2Instruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedTwoHopSwapV2Instruction { + if (instruction.accounts.length < 24) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpoolOne: getNextAccount(), + whirlpoolTwo: getNextAccount(), + tokenMintInput: getNextAccount(), + tokenMintIntermediate: getNextAccount(), + tokenMintOutput: getNextAccount(), + tokenProgramInput: getNextAccount(), + tokenProgramIntermediate: getNextAccount(), + tokenProgramOutput: getNextAccount(), + tokenOwnerAccountInput: getNextAccount(), + tokenVaultOneInput: getNextAccount(), + tokenVaultOneIntermediate: getNextAccount(), + tokenVaultTwoIntermediate: getNextAccount(), + tokenVaultTwoOutput: getNextAccount(), + tokenOwnerAccountOutput: getNextAccount(), + tokenAuthority: getNextAccount(), + tickArrayOne0: getNextAccount(), + tickArrayOne1: getNextAccount(), + tickArrayOne2: getNextAccount(), + tickArrayTwo0: getNextAccount(), + tickArrayTwo1: getNextAccount(), + tickArrayTwo2: getNextAccount(), + oracleOne: getNextAccount(), + oracleTwo: getNextAccount(), + memoProgram: getNextAccount(), + }, + data: getTwoHopSwapV2InstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/orca-whirlpools/src/generated/instructions/updateFeesAndRewards.ts b/clients/orca-whirlpools/src/generated/instructions/updateFeesAndRewards.ts new file mode 100644 index 00000000..9f7cfdd9 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/instructions/updateFeesAndRewards.ts @@ -0,0 +1,217 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + WritableAccount, +} from "@solana/kit"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { WHIRLPOOL_PROGRAM_ADDRESS } from "../programs/index.js"; +import type { ResolvedAccount } from "../shared/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const UPDATE_FEES_AND_REWARDS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([154, 230, 250, 13, 236, 209, 75, 223]); + +export function getUpdateFeesAndRewardsDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + UPDATE_FEES_AND_REWARDS_DISCRIMINATOR, + ); +} + +export type UpdateFeesAndRewardsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountWhirlpool extends string | AccountMeta = string, + TAccountPosition extends string | AccountMeta = string, + TAccountTickArrayLower extends string | AccountMeta = string, + TAccountTickArrayUpper extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountWhirlpool extends string + ? WritableAccount + : TAccountWhirlpool, + TAccountPosition extends string + ? WritableAccount + : TAccountPosition, + TAccountTickArrayLower extends string + ? ReadonlyAccount + : TAccountTickArrayLower, + TAccountTickArrayUpper extends string + ? ReadonlyAccount + : TAccountTickArrayUpper, + ...TRemainingAccounts, + ] + >; + +export interface UpdateFeesAndRewardsInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface UpdateFeesAndRewardsInstructionDataArgs {} + +export function getUpdateFeesAndRewardsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: UPDATE_FEES_AND_REWARDS_DISCRIMINATOR, + }), + ); +} + +export function getUpdateFeesAndRewardsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getUpdateFeesAndRewardsInstructionDataCodec(): FixedSizeCodec< + UpdateFeesAndRewardsInstructionDataArgs, + UpdateFeesAndRewardsInstructionData +> { + return combineCodec( + getUpdateFeesAndRewardsInstructionDataEncoder(), + getUpdateFeesAndRewardsInstructionDataDecoder(), + ); +} + +export interface UpdateFeesAndRewardsInput< + TAccountWhirlpool extends string = string, + TAccountPosition extends string = string, + TAccountTickArrayLower extends string = string, + TAccountTickArrayUpper extends string = string, +> { + whirlpool: Address; + position: Address; + tickArrayLower: Address; + tickArrayUpper: Address; +} + +export function getUpdateFeesAndRewardsInstruction< + TAccountWhirlpool extends string, + TAccountPosition extends string, + TAccountTickArrayLower extends string, + TAccountTickArrayUpper extends string, + TProgramAddress extends Address = typeof WHIRLPOOL_PROGRAM_ADDRESS, +>( + input: UpdateFeesAndRewardsInput< + TAccountWhirlpool, + TAccountPosition, + TAccountTickArrayLower, + TAccountTickArrayUpper + >, + config?: { programAddress?: TProgramAddress }, +): UpdateFeesAndRewardsInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPosition, + TAccountTickArrayLower, + TAccountTickArrayUpper +> { + // Program address. + const programAddress = config?.programAddress ?? WHIRLPOOL_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + whirlpool: { value: input.whirlpool ?? null, isWritable: true }, + position: { value: input.position ?? null, isWritable: true }, + tickArrayLower: { value: input.tickArrayLower ?? null, isWritable: false }, + tickArrayUpper: { value: input.tickArrayUpper ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + const instruction = { + accounts: [ + getAccountMeta(accounts.whirlpool), + getAccountMeta(accounts.position), + getAccountMeta(accounts.tickArrayLower), + getAccountMeta(accounts.tickArrayUpper), + ], + programAddress, + data: getUpdateFeesAndRewardsInstructionDataEncoder().encode({}), + } as UpdateFeesAndRewardsInstruction< + TProgramAddress, + TAccountWhirlpool, + TAccountPosition, + TAccountTickArrayLower, + TAccountTickArrayUpper + >; + + return instruction; +} + +export interface ParsedUpdateFeesAndRewardsInstruction< + TProgram extends string = typeof WHIRLPOOL_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + whirlpool: TAccountMetas[0]; + position: TAccountMetas[1]; + tickArrayLower: TAccountMetas[2]; + tickArrayUpper: TAccountMetas[3]; + }; + data: UpdateFeesAndRewardsInstructionData; +} + +export function parseUpdateFeesAndRewardsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedUpdateFeesAndRewardsInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + whirlpool: getNextAccount(), + position: getNextAccount(), + tickArrayLower: getNextAccount(), + tickArrayUpper: getNextAccount(), + }, + data: getUpdateFeesAndRewardsInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/orca-whirlpools/src/generated/programs/index.ts b/clients/orca-whirlpools/src/generated/programs/index.ts new file mode 100644 index 00000000..b7ceb61b --- /dev/null +++ b/clients/orca-whirlpools/src/generated/programs/index.ts @@ -0,0 +1,9 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./whirlpool.js"; diff --git a/clients/orca-whirlpools/src/generated/programs/whirlpool.ts b/clients/orca-whirlpools/src/generated/programs/whirlpool.ts new file mode 100644 index 00000000..9300b661 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/programs/whirlpool.ts @@ -0,0 +1,935 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ReadonlyUint8Array } from "@solana/kit"; +import { containsBytes, fixEncoderSize, getBytesEncoder } from "@solana/kit"; +import type { + ParsedCloseBundledPositionInstruction, + ParsedClosePositionInstruction, + ParsedClosePositionWithTokenExtensionsInstruction, + ParsedCollectFeesInstruction, + ParsedCollectFeesV2Instruction, + ParsedCollectProtocolFeesInstruction, + ParsedCollectProtocolFeesV2Instruction, + ParsedCollectRewardInstruction, + ParsedCollectRewardV2Instruction, + ParsedDecreaseLiquidityInstruction, + ParsedDecreaseLiquidityV2Instruction, + ParsedDeletePositionBundleInstruction, + ParsedDeleteTokenBadgeInstruction, + ParsedIncreaseLiquidityInstruction, + ParsedIncreaseLiquidityV2Instruction, + ParsedInitializeConfigExtensionInstruction, + ParsedInitializeConfigInstruction, + ParsedInitializeFeeTierInstruction, + ParsedInitializePoolInstruction, + ParsedInitializePoolV2Instruction, + ParsedInitializePositionBundleInstruction, + ParsedInitializePositionBundleWithMetadataInstruction, + ParsedInitializeRewardInstruction, + ParsedInitializeRewardV2Instruction, + ParsedInitializeTickArrayInstruction, + ParsedInitializeTokenBadgeInstruction, + ParsedLockPositionInstruction, + ParsedOpenBundledPositionInstruction, + ParsedOpenPositionInstruction, + ParsedOpenPositionWithMetadataInstruction, + ParsedOpenPositionWithTokenExtensionsInstruction, + ParsedSetCollectProtocolFeesAuthorityInstruction, + ParsedSetConfigExtensionAuthorityInstruction, + ParsedSetDefaultFeeRateInstruction, + ParsedSetDefaultProtocolFeeRateInstruction, + ParsedSetFeeAuthorityInstruction, + ParsedSetFeeRateInstruction, + ParsedSetProtocolFeeRateInstruction, + ParsedSetRewardAuthorityBySuperAuthorityInstruction, + ParsedSetRewardAuthorityInstruction, + ParsedSetRewardEmissionsInstruction, + ParsedSetRewardEmissionsSuperAuthorityInstruction, + ParsedSetRewardEmissionsV2Instruction, + ParsedSetTokenBadgeAuthorityInstruction, + ParsedSwapInstruction, + ParsedSwapV2Instruction, + ParsedTwoHopSwapInstruction, + ParsedTwoHopSwapV2Instruction, + ParsedUpdateFeesAndRewardsInstruction, +} from "../instructions/index.js"; + +export const WHIRLPOOL_PROGRAM_ADDRESS = + "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc" as Address<"whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc">; + +export enum WhirlpoolAccount { + WhirlpoolsConfig = 0, + WhirlpoolsConfigExtension = 1, + FeeTier = 2, + LockConfig = 3, + Position = 4, + PositionBundle = 5, + TickArray = 6, + TokenBadge = 7, + Whirlpool = 8, +} + +export function identifyWhirlpoolAccount( + account: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): WhirlpoolAccount { + const data = "data" in account ? account.data : account; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([157, 20, 49, 224, 217, 87, 193, 254]), + ), + 0, + ) + ) { + return WhirlpoolAccount.WhirlpoolsConfig; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([2, 99, 215, 163, 240, 26, 153, 58]), + ), + 0, + ) + ) { + return WhirlpoolAccount.WhirlpoolsConfigExtension; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([56, 75, 159, 76, 142, 68, 190, 105]), + ), + 0, + ) + ) { + return WhirlpoolAccount.FeeTier; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([106, 47, 238, 159, 124, 12, 160, 192]), + ), + 0, + ) + ) { + return WhirlpoolAccount.LockConfig; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([170, 188, 143, 228, 122, 64, 247, 208]), + ), + 0, + ) + ) { + return WhirlpoolAccount.Position; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([129, 169, 175, 65, 185, 95, 32, 100]), + ), + 0, + ) + ) { + return WhirlpoolAccount.PositionBundle; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([69, 97, 189, 190, 110, 7, 66, 187]), + ), + 0, + ) + ) { + return WhirlpoolAccount.TickArray; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([116, 219, 204, 229, 249, 116, 255, 150]), + ), + 0, + ) + ) { + return WhirlpoolAccount.TokenBadge; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([63, 149, 209, 12, 225, 128, 99, 9]), + ), + 0, + ) + ) { + return WhirlpoolAccount.Whirlpool; + } + throw new Error( + "The provided account could not be identified as a whirlpool account.", + ); +} + +export enum WhirlpoolInstruction { + InitializeConfig = 0, + InitializePool = 1, + InitializeTickArray = 2, + InitializeFeeTier = 3, + InitializeReward = 4, + SetRewardEmissions = 5, + OpenPosition = 6, + OpenPositionWithMetadata = 7, + IncreaseLiquidity = 8, + DecreaseLiquidity = 9, + UpdateFeesAndRewards = 10, + CollectFees = 11, + CollectReward = 12, + CollectProtocolFees = 13, + Swap = 14, + ClosePosition = 15, + SetDefaultFeeRate = 16, + SetDefaultProtocolFeeRate = 17, + SetFeeRate = 18, + SetProtocolFeeRate = 19, + SetFeeAuthority = 20, + SetCollectProtocolFeesAuthority = 21, + SetRewardAuthority = 22, + SetRewardAuthorityBySuperAuthority = 23, + SetRewardEmissionsSuperAuthority = 24, + TwoHopSwap = 25, + InitializePositionBundle = 26, + InitializePositionBundleWithMetadata = 27, + DeletePositionBundle = 28, + OpenBundledPosition = 29, + CloseBundledPosition = 30, + OpenPositionWithTokenExtensions = 31, + ClosePositionWithTokenExtensions = 32, + LockPosition = 33, + CollectFeesV2 = 34, + CollectProtocolFeesV2 = 35, + CollectRewardV2 = 36, + DecreaseLiquidityV2 = 37, + IncreaseLiquidityV2 = 38, + InitializePoolV2 = 39, + InitializeRewardV2 = 40, + SetRewardEmissionsV2 = 41, + SwapV2 = 42, + TwoHopSwapV2 = 43, + InitializeConfigExtension = 44, + SetConfigExtensionAuthority = 45, + SetTokenBadgeAuthority = 46, + InitializeTokenBadge = 47, + DeleteTokenBadge = 48, +} + +export function identifyWhirlpoolInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): WhirlpoolInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([208, 127, 21, 1, 194, 190, 196, 70]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeConfig; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([95, 180, 10, 172, 84, 174, 232, 40]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializePool; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([11, 188, 193, 214, 141, 91, 149, 184]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeTickArray; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([183, 74, 156, 160, 112, 2, 42, 30]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeFeeTier; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([95, 135, 192, 196, 242, 129, 230, 68]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeReward; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([13, 197, 86, 168, 109, 176, 27, 244]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetRewardEmissions; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([135, 128, 47, 77, 15, 152, 240, 49]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.OpenPosition; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([242, 29, 134, 48, 58, 110, 14, 60]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.OpenPositionWithMetadata; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([46, 156, 243, 118, 13, 205, 251, 178]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.IncreaseLiquidity; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([160, 38, 208, 111, 104, 91, 44, 1]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.DecreaseLiquidity; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([154, 230, 250, 13, 236, 209, 75, 223]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.UpdateFeesAndRewards; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([164, 152, 207, 99, 30, 186, 19, 182]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CollectFees; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([70, 5, 132, 87, 86, 235, 177, 34]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CollectReward; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([22, 67, 23, 98, 150, 178, 70, 220]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CollectProtocolFees; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([248, 198, 158, 145, 225, 117, 135, 200]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.Swap; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([123, 134, 81, 0, 49, 68, 98, 98]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.ClosePosition; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([118, 215, 214, 157, 182, 229, 208, 228]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetDefaultFeeRate; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([107, 205, 249, 226, 151, 35, 86, 0]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetDefaultProtocolFeeRate; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([53, 243, 137, 65, 8, 140, 158, 6]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetFeeRate; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([95, 7, 4, 50, 154, 79, 156, 131]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetProtocolFeeRate; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([31, 1, 50, 87, 237, 101, 97, 132]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetFeeAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([34, 150, 93, 244, 139, 225, 233, 67]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetCollectProtocolFeesAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([34, 39, 183, 252, 83, 28, 85, 127]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetRewardAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([240, 154, 201, 198, 148, 93, 56, 25]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetRewardAuthorityBySuperAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([207, 5, 200, 209, 122, 56, 82, 183]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetRewardEmissionsSuperAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([195, 96, 237, 108, 68, 162, 219, 230]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.TwoHopSwap; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([117, 45, 241, 149, 24, 18, 194, 65]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializePositionBundle; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([93, 124, 16, 179, 249, 131, 115, 245]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializePositionBundleWithMetadata; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([100, 25, 99, 2, 217, 239, 124, 173]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.DeletePositionBundle; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([169, 113, 126, 171, 213, 172, 212, 49]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.OpenBundledPosition; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([41, 36, 216, 245, 27, 85, 103, 67]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CloseBundledPosition; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([212, 47, 95, 92, 114, 102, 131, 250]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.OpenPositionWithTokenExtensions; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([1, 182, 135, 59, 155, 25, 99, 223]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.ClosePositionWithTokenExtensions; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([227, 62, 2, 252, 247, 10, 171, 185]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.LockPosition; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([207, 117, 95, 191, 229, 180, 226, 15]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CollectFeesV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([103, 128, 222, 134, 114, 200, 22, 200]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CollectProtocolFeesV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([177, 107, 37, 180, 160, 19, 49, 209]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.CollectRewardV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([58, 127, 188, 62, 79, 82, 196, 96]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.DecreaseLiquidityV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([133, 29, 89, 223, 69, 238, 176, 10]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.IncreaseLiquidityV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([207, 45, 87, 242, 27, 63, 204, 67]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializePoolV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([91, 1, 77, 50, 235, 229, 133, 49]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeRewardV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([114, 228, 72, 32, 193, 48, 160, 102]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetRewardEmissionsV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([43, 4, 237, 11, 26, 201, 30, 98]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SwapV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([186, 143, 209, 29, 254, 2, 194, 117]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.TwoHopSwapV2; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([55, 9, 53, 9, 114, 57, 209, 52]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeConfigExtension; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([44, 94, 241, 116, 24, 188, 60, 143]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetConfigExtensionAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([207, 202, 4, 32, 205, 79, 13, 178]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.SetTokenBadgeAuthority; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([253, 77, 205, 95, 27, 224, 89, 223]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.InitializeTokenBadge; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([53, 146, 68, 8, 18, 117, 17, 185]), + ), + 0, + ) + ) { + return WhirlpoolInstruction.DeleteTokenBadge; + } + throw new Error( + "The provided instruction could not be identified as a whirlpool instruction.", + ); +} + +export type ParsedWhirlpoolInstruction< + TProgram extends string = "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc", +> = + | ({ + instructionType: WhirlpoolInstruction.InitializeConfig; + } & ParsedInitializeConfigInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializePool; + } & ParsedInitializePoolInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializeTickArray; + } & ParsedInitializeTickArrayInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializeFeeTier; + } & ParsedInitializeFeeTierInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializeReward; + } & ParsedInitializeRewardInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetRewardEmissions; + } & ParsedSetRewardEmissionsInstruction) + | ({ + instructionType: WhirlpoolInstruction.OpenPosition; + } & ParsedOpenPositionInstruction) + | ({ + instructionType: WhirlpoolInstruction.OpenPositionWithMetadata; + } & ParsedOpenPositionWithMetadataInstruction) + | ({ + instructionType: WhirlpoolInstruction.IncreaseLiquidity; + } & ParsedIncreaseLiquidityInstruction) + | ({ + instructionType: WhirlpoolInstruction.DecreaseLiquidity; + } & ParsedDecreaseLiquidityInstruction) + | ({ + instructionType: WhirlpoolInstruction.UpdateFeesAndRewards; + } & ParsedUpdateFeesAndRewardsInstruction) + | ({ + instructionType: WhirlpoolInstruction.CollectFees; + } & ParsedCollectFeesInstruction) + | ({ + instructionType: WhirlpoolInstruction.CollectReward; + } & ParsedCollectRewardInstruction) + | ({ + instructionType: WhirlpoolInstruction.CollectProtocolFees; + } & ParsedCollectProtocolFeesInstruction) + | ({ + instructionType: WhirlpoolInstruction.Swap; + } & ParsedSwapInstruction) + | ({ + instructionType: WhirlpoolInstruction.ClosePosition; + } & ParsedClosePositionInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetDefaultFeeRate; + } & ParsedSetDefaultFeeRateInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetDefaultProtocolFeeRate; + } & ParsedSetDefaultProtocolFeeRateInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetFeeRate; + } & ParsedSetFeeRateInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetProtocolFeeRate; + } & ParsedSetProtocolFeeRateInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetFeeAuthority; + } & ParsedSetFeeAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetCollectProtocolFeesAuthority; + } & ParsedSetCollectProtocolFeesAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetRewardAuthority; + } & ParsedSetRewardAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetRewardAuthorityBySuperAuthority; + } & ParsedSetRewardAuthorityBySuperAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetRewardEmissionsSuperAuthority; + } & ParsedSetRewardEmissionsSuperAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.TwoHopSwap; + } & ParsedTwoHopSwapInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializePositionBundle; + } & ParsedInitializePositionBundleInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializePositionBundleWithMetadata; + } & ParsedInitializePositionBundleWithMetadataInstruction) + | ({ + instructionType: WhirlpoolInstruction.DeletePositionBundle; + } & ParsedDeletePositionBundleInstruction) + | ({ + instructionType: WhirlpoolInstruction.OpenBundledPosition; + } & ParsedOpenBundledPositionInstruction) + | ({ + instructionType: WhirlpoolInstruction.CloseBundledPosition; + } & ParsedCloseBundledPositionInstruction) + | ({ + instructionType: WhirlpoolInstruction.OpenPositionWithTokenExtensions; + } & ParsedOpenPositionWithTokenExtensionsInstruction) + | ({ + instructionType: WhirlpoolInstruction.ClosePositionWithTokenExtensions; + } & ParsedClosePositionWithTokenExtensionsInstruction) + | ({ + instructionType: WhirlpoolInstruction.LockPosition; + } & ParsedLockPositionInstruction) + | ({ + instructionType: WhirlpoolInstruction.CollectFeesV2; + } & ParsedCollectFeesV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.CollectProtocolFeesV2; + } & ParsedCollectProtocolFeesV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.CollectRewardV2; + } & ParsedCollectRewardV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.DecreaseLiquidityV2; + } & ParsedDecreaseLiquidityV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.IncreaseLiquidityV2; + } & ParsedIncreaseLiquidityV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.InitializePoolV2; + } & ParsedInitializePoolV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.InitializeRewardV2; + } & ParsedInitializeRewardV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.SetRewardEmissionsV2; + } & ParsedSetRewardEmissionsV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.SwapV2; + } & ParsedSwapV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.TwoHopSwapV2; + } & ParsedTwoHopSwapV2Instruction) + | ({ + instructionType: WhirlpoolInstruction.InitializeConfigExtension; + } & ParsedInitializeConfigExtensionInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetConfigExtensionAuthority; + } & ParsedSetConfigExtensionAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.SetTokenBadgeAuthority; + } & ParsedSetTokenBadgeAuthorityInstruction) + | ({ + instructionType: WhirlpoolInstruction.InitializeTokenBadge; + } & ParsedInitializeTokenBadgeInstruction) + | ({ + instructionType: WhirlpoolInstruction.DeleteTokenBadge; + } & ParsedDeleteTokenBadgeInstruction); diff --git a/clients/orca-whirlpools/src/generated/shared/index.ts b/clients/orca-whirlpools/src/generated/shared/index.ts new file mode 100644 index 00000000..7d911d4a --- /dev/null +++ b/clients/orca-whirlpools/src/generated/shared/index.ts @@ -0,0 +1,168 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + ProgramDerivedAddress, + TransactionSigner, +} from "@solana/kit"; +import { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + upgradeRoleToSigner, +} from "@solana/kit"; + +/** + * Asserts that the given value is not null or undefined. + * @internal + */ +export function expectSome(value: T | null | undefined): T { + if (value === null || value === undefined) { + throw new Error("Expected a value but received null or undefined."); + } + return value; +} + +/** + * Asserts that the given value is a PublicKey. + * @internal + */ +export function expectAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): Address { + if (!value) { + throw new Error("Expected a Address."); + } + if (typeof value === "object" && "address" in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; +} + +/** + * Asserts that the given value is a PDA. + * @internal + */ +export function expectProgramDerivedAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): ProgramDerivedAddress { + if (!(value && Array.isArray(value) && isProgramDerivedAddress(value))) { + throw new Error("Expected a ProgramDerivedAddress."); + } + return value; +} + +/** + * Asserts that the given value is a TransactionSigner. + * @internal + */ +export function expectTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): TransactionSigner { + if (!(value && isTransactionSigner(value))) { + throw new Error("Expected a TransactionSigner."); + } + return value; +} + +/** + * Defines an instruction account to resolve. + * @internal + */ +export interface ResolvedAccount< + T extends string = string, + U extends + | Address + | ProgramDerivedAddress + | TransactionSigner + | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, +> { + isWritable: boolean; + value: U; +} + +/** + * Defines an instruction that stores additional bytes on-chain. + * @internal + */ +export interface InstructionWithByteDelta { + byteDelta: number; +} + +/** + * Get account metas and signers from resolved accounts. + * @internal + */ +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: "omitted" | "programId", +) { + return ( + account: ResolvedAccount, + ): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === "omitted") { + return; + } + return Object.freeze({ + address: programAddress, + role: AccountRole.READONLY, + }); + } + + const writableRole = account.isWritable + ? AccountRole.WRITABLE + : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) + ? upgradeRoleToSigner(writableRole) + : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; +} + +export function isTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner, +): value is TransactionSigner { + return ( + !!value && + typeof value === "object" && + "address" in value && + kitIsTransactionSigner(value) + ); +} diff --git a/clients/orca-whirlpools/src/generated/types/accountsType.ts b/clients/orca-whirlpools/src/generated/types/accountsType.ts new file mode 100644 index 00000000..2ae48228 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/accountsType.ts @@ -0,0 +1,43 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +export enum AccountsType { + TransferHookA = 0, + TransferHookB = 1, + TransferHookReward = 2, + TransferHookInput = 3, + TransferHookIntermediate = 4, + TransferHookOutput = 5, + SupplementalTickArrays = 6, + SupplementalTickArraysOne = 7, + SupplementalTickArraysTwo = 8, +} + +export type AccountsTypeArgs = AccountsType; + +export function getAccountsTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(AccountsType); +} + +export function getAccountsTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(AccountsType); +} + +export function getAccountsTypeCodec(): FixedSizeCodec< + AccountsTypeArgs, + AccountsType +> { + return combineCodec(getAccountsTypeEncoder(), getAccountsTypeDecoder()); +} diff --git a/clients/orca-whirlpools/src/generated/types/index.ts b/clients/orca-whirlpools/src/generated/types/index.ts new file mode 100644 index 00000000..c6fe95ba --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/index.ts @@ -0,0 +1,19 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./accountsType.js"; +export * from "./lockType.js"; +export * from "./lockTypeLabel.js"; +export * from "./openPositionBumps.js"; +export * from "./openPositionWithMetadataBumps.js"; +export * from "./positionRewardInfo.js"; +export * from "./remainingAccountsInfo.js"; +export * from "./remainingAccountsSlice.js"; +export * from "./tick.js"; +export * from "./whirlpoolBumps.js"; +export * from "./whirlpoolRewardInfo.js"; diff --git a/clients/orca-whirlpools/src/generated/types/lockType.ts b/clients/orca-whirlpools/src/generated/types/lockType.ts new file mode 100644 index 00000000..496c6cad --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/lockType.ts @@ -0,0 +1,32 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +export enum LockType { + Permanent = 0, +} + +export type LockTypeArgs = LockType; + +export function getLockTypeEncoder(): FixedSizeEncoder { + return getEnumEncoder(LockType); +} + +export function getLockTypeDecoder(): FixedSizeDecoder { + return getEnumDecoder(LockType); +} + +export function getLockTypeCodec(): FixedSizeCodec { + return combineCodec(getLockTypeEncoder(), getLockTypeDecoder()); +} diff --git a/clients/orca-whirlpools/src/generated/types/lockTypeLabel.ts b/clients/orca-whirlpools/src/generated/types/lockTypeLabel.ts new file mode 100644 index 00000000..87ad320d --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/lockTypeLabel.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +export enum LockTypeLabel { + Permanent = 0, +} + +export type LockTypeLabelArgs = LockTypeLabel; + +export function getLockTypeLabelEncoder(): FixedSizeEncoder { + return getEnumEncoder(LockTypeLabel); +} + +export function getLockTypeLabelDecoder(): FixedSizeDecoder { + return getEnumDecoder(LockTypeLabel); +} + +export function getLockTypeLabelCodec(): FixedSizeCodec< + LockTypeLabelArgs, + LockTypeLabel +> { + return combineCodec(getLockTypeLabelEncoder(), getLockTypeLabelDecoder()); +} diff --git a/clients/orca-whirlpools/src/generated/types/openPositionBumps.ts b/clients/orca-whirlpools/src/generated/types/openPositionBumps.ts new file mode 100644 index 00000000..46f66f91 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/openPositionBumps.ts @@ -0,0 +1,44 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; + +export interface OpenPositionBumps { + positionBump: number; +} + +export type OpenPositionBumpsArgs = OpenPositionBumps; + +export function getOpenPositionBumpsEncoder(): FixedSizeEncoder { + return getStructEncoder([["positionBump", getU8Encoder()]]); +} + +export function getOpenPositionBumpsDecoder(): FixedSizeDecoder { + return getStructDecoder([["positionBump", getU8Decoder()]]); +} + +export function getOpenPositionBumpsCodec(): FixedSizeCodec< + OpenPositionBumpsArgs, + OpenPositionBumps +> { + return combineCodec( + getOpenPositionBumpsEncoder(), + getOpenPositionBumpsDecoder(), + ); +} diff --git a/clients/orca-whirlpools/src/generated/types/openPositionWithMetadataBumps.ts b/clients/orca-whirlpools/src/generated/types/openPositionWithMetadataBumps.ts new file mode 100644 index 00000000..0ba3b40b --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/openPositionWithMetadataBumps.ts @@ -0,0 +1,51 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; + +export interface OpenPositionWithMetadataBumps { + positionBump: number; + metadataBump: number; +} + +export type OpenPositionWithMetadataBumpsArgs = OpenPositionWithMetadataBumps; + +export function getOpenPositionWithMetadataBumpsEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["positionBump", getU8Encoder()], + ["metadataBump", getU8Encoder()], + ]); +} + +export function getOpenPositionWithMetadataBumpsDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["positionBump", getU8Decoder()], + ["metadataBump", getU8Decoder()], + ]); +} + +export function getOpenPositionWithMetadataBumpsCodec(): FixedSizeCodec< + OpenPositionWithMetadataBumpsArgs, + OpenPositionWithMetadataBumps +> { + return combineCodec( + getOpenPositionWithMetadataBumpsEncoder(), + getOpenPositionWithMetadataBumpsDecoder(), + ); +} diff --git a/clients/orca-whirlpools/src/generated/types/positionRewardInfo.ts b/clients/orca-whirlpools/src/generated/types/positionRewardInfo.ts new file mode 100644 index 00000000..d8130322 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/positionRewardInfo.ts @@ -0,0 +1,56 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + getU128Decoder, + getU128Encoder, +} from "@solana/kit"; + +export interface PositionRewardInfo { + growthInsideCheckpoint: bigint; + amountOwed: bigint; +} + +export interface PositionRewardInfoArgs { + growthInsideCheckpoint: number | bigint; + amountOwed: number | bigint; +} + +export function getPositionRewardInfoEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["growthInsideCheckpoint", getU128Encoder()], + ["amountOwed", getU64Encoder()], + ]); +} + +export function getPositionRewardInfoDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["growthInsideCheckpoint", getU128Decoder()], + ["amountOwed", getU64Decoder()], + ]); +} + +export function getPositionRewardInfoCodec(): FixedSizeCodec< + PositionRewardInfoArgs, + PositionRewardInfo +> { + return combineCodec( + getPositionRewardInfoEncoder(), + getPositionRewardInfoDecoder(), + ); +} diff --git a/clients/orca-whirlpools/src/generated/types/remainingAccountsInfo.ts b/clients/orca-whirlpools/src/generated/types/remainingAccountsInfo.ts new file mode 100644 index 00000000..f2075fa0 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/remainingAccountsInfo.ts @@ -0,0 +1,54 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Codec, Decoder, Encoder } from "@solana/kit"; +import { + combineCodec, + getArrayDecoder, + getArrayEncoder, + getStructDecoder, + getStructEncoder, +} from "@solana/kit"; +import type { + RemainingAccountsSlice, + RemainingAccountsSliceArgs, +} from "./index.js"; +import { + getRemainingAccountsSliceDecoder, + getRemainingAccountsSliceEncoder, +} from "./index.js"; + +export interface RemainingAccountsInfo { + slices: RemainingAccountsSlice[]; +} + +export interface RemainingAccountsInfoArgs { + slices: RemainingAccountsSliceArgs[]; +} + +export function getRemainingAccountsInfoEncoder(): Encoder { + return getStructEncoder([ + ["slices", getArrayEncoder(getRemainingAccountsSliceEncoder())], + ]); +} + +export function getRemainingAccountsInfoDecoder(): Decoder { + return getStructDecoder([ + ["slices", getArrayDecoder(getRemainingAccountsSliceDecoder())], + ]); +} + +export function getRemainingAccountsInfoCodec(): Codec< + RemainingAccountsInfoArgs, + RemainingAccountsInfo +> { + return combineCodec( + getRemainingAccountsInfoEncoder(), + getRemainingAccountsInfoDecoder(), + ); +} diff --git a/clients/orca-whirlpools/src/generated/types/remainingAccountsSlice.ts b/clients/orca-whirlpools/src/generated/types/remainingAccountsSlice.ts new file mode 100644 index 00000000..ba160348 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/remainingAccountsSlice.ts @@ -0,0 +1,56 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; +import type { AccountsType, AccountsTypeArgs } from "./index.js"; +import { getAccountsTypeDecoder, getAccountsTypeEncoder } from "./index.js"; + +export interface RemainingAccountsSlice { + accountsType: AccountsType; + length: number; +} + +export interface RemainingAccountsSliceArgs { + accountsType: AccountsTypeArgs; + length: number; +} + +export function getRemainingAccountsSliceEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["accountsType", getAccountsTypeEncoder()], + ["length", getU8Encoder()], + ]); +} + +export function getRemainingAccountsSliceDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["accountsType", getAccountsTypeDecoder()], + ["length", getU8Decoder()], + ]); +} + +export function getRemainingAccountsSliceCodec(): FixedSizeCodec< + RemainingAccountsSliceArgs, + RemainingAccountsSlice +> { + return combineCodec( + getRemainingAccountsSliceEncoder(), + getRemainingAccountsSliceDecoder(), + ); +} diff --git a/clients/orca-whirlpools/src/generated/types/tick.ts b/clients/orca-whirlpools/src/generated/types/tick.ts new file mode 100644 index 00000000..f4460ffb --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/tick.ts @@ -0,0 +1,70 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getArrayDecoder, + getArrayEncoder, + getBooleanDecoder, + getBooleanEncoder, + getI128Decoder, + getI128Encoder, + getStructDecoder, + getStructEncoder, + getU128Decoder, + getU128Encoder, +} from "@solana/kit"; + +export interface Tick { + initialized: boolean; + liquidityNet: bigint; + liquidityGross: bigint; + feeGrowthOutsideA: bigint; + feeGrowthOutsideB: bigint; + rewardGrowthsOutside: bigint[]; +} + +export interface TickArgs { + initialized: boolean; + liquidityNet: number | bigint; + liquidityGross: number | bigint; + feeGrowthOutsideA: number | bigint; + feeGrowthOutsideB: number | bigint; + rewardGrowthsOutside: (number | bigint)[]; +} + +export function getTickEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["initialized", getBooleanEncoder()], + ["liquidityNet", getI128Encoder()], + ["liquidityGross", getU128Encoder()], + ["feeGrowthOutsideA", getU128Encoder()], + ["feeGrowthOutsideB", getU128Encoder()], + ["rewardGrowthsOutside", getArrayEncoder(getU128Encoder(), { size: 3 })], + ]); +} + +export function getTickDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["initialized", getBooleanDecoder()], + ["liquidityNet", getI128Decoder()], + ["liquidityGross", getU128Decoder()], + ["feeGrowthOutsideA", getU128Decoder()], + ["feeGrowthOutsideB", getU128Decoder()], + ["rewardGrowthsOutside", getArrayDecoder(getU128Decoder(), { size: 3 })], + ]); +} + +export function getTickCodec(): FixedSizeCodec { + return combineCodec(getTickEncoder(), getTickDecoder()); +} diff --git a/clients/orca-whirlpools/src/generated/types/whirlpoolBumps.ts b/clients/orca-whirlpools/src/generated/types/whirlpoolBumps.ts new file mode 100644 index 00000000..27c840ed --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/whirlpoolBumps.ts @@ -0,0 +1,41 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, +} from "@solana/kit"; + +export interface WhirlpoolBumps { + whirlpoolBump: number; +} + +export type WhirlpoolBumpsArgs = WhirlpoolBumps; + +export function getWhirlpoolBumpsEncoder(): FixedSizeEncoder { + return getStructEncoder([["whirlpoolBump", getU8Encoder()]]); +} + +export function getWhirlpoolBumpsDecoder(): FixedSizeDecoder { + return getStructDecoder([["whirlpoolBump", getU8Decoder()]]); +} + +export function getWhirlpoolBumpsCodec(): FixedSizeCodec< + WhirlpoolBumpsArgs, + WhirlpoolBumps +> { + return combineCodec(getWhirlpoolBumpsEncoder(), getWhirlpoolBumpsDecoder()); +} diff --git a/clients/orca-whirlpools/src/generated/types/whirlpoolRewardInfo.ts b/clients/orca-whirlpools/src/generated/types/whirlpoolRewardInfo.ts new file mode 100644 index 00000000..9fa63cc0 --- /dev/null +++ b/clients/orca-whirlpools/src/generated/types/whirlpoolRewardInfo.ts @@ -0,0 +1,69 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getStructDecoder, + getStructEncoder, + getU128Decoder, + getU128Encoder, +} from "@solana/kit"; + +export interface WhirlpoolRewardInfo { + mint: Address; + vault: Address; + authority: Address; + emissionsPerSecondX64: bigint; + growthGlobalX64: bigint; +} + +export interface WhirlpoolRewardInfoArgs { + mint: Address; + vault: Address; + authority: Address; + emissionsPerSecondX64: number | bigint; + growthGlobalX64: number | bigint; +} + +export function getWhirlpoolRewardInfoEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["mint", getAddressEncoder()], + ["vault", getAddressEncoder()], + ["authority", getAddressEncoder()], + ["emissionsPerSecondX64", getU128Encoder()], + ["growthGlobalX64", getU128Encoder()], + ]); +} + +export function getWhirlpoolRewardInfoDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["mint", getAddressDecoder()], + ["vault", getAddressDecoder()], + ["authority", getAddressDecoder()], + ["emissionsPerSecondX64", getU128Decoder()], + ["growthGlobalX64", getU128Decoder()], + ]); +} + +export function getWhirlpoolRewardInfoCodec(): FixedSizeCodec< + WhirlpoolRewardInfoArgs, + WhirlpoolRewardInfo +> { + return combineCodec( + getWhirlpoolRewardInfoEncoder(), + getWhirlpoolRewardInfoDecoder(), + ); +} diff --git a/clients/orca-whirlpools/src/index.ts b/clients/orca-whirlpools/src/index.ts new file mode 100644 index 00000000..ab03489a --- /dev/null +++ b/clients/orca-whirlpools/src/index.ts @@ -0,0 +1,2 @@ +// Re-export all generated code +export * from "./generated/index.js"; diff --git a/clients/orca-whirlpools/tsconfig.json b/clients/orca-whirlpools/tsconfig.json new file mode 100644 index 00000000..e528d933 --- /dev/null +++ b/clients/orca-whirlpools/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@macalinao/tsconfig/tsconfig.base.json" +} diff --git a/package.json b/package.json index 83df9fdf..800b8d53 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,8 @@ "ci:publish": "./scripts/ci-publish.sh", "prepare": "husky", "codegen": "turbo run codegen", - "docs:dev": "turbo dev --filter=@macalinao/coda-docs", - "docs:build": "turbo build --filter=@macalinao/coda-docs" + "docs:dev": "turbo dev --filter=coda-docs", + "docs:build": "turbo build --filter=coda-docs" }, "devDependencies": { "@biomejs/biome": "^2.2.0", diff --git a/packages/create-coda/.gitignore b/packages/create-coda/.gitignore new file mode 100644 index 00000000..a77089be --- /dev/null +++ b/packages/create-coda/.gitignore @@ -0,0 +1,6 @@ +# Build output +dist/ +*.tsbuildinfo + +# Cache +.eslintcache \ No newline at end of file diff --git a/packages/create-coda/eslint.config.js b/packages/create-coda/eslint.config.js new file mode 100644 index 00000000..e6553d2f --- /dev/null +++ b/packages/create-coda/eslint.config.js @@ -0,0 +1,15 @@ +import { configs } from "@macalinao/eslint-config"; + +export default [ + ...configs.fast, + { + languageOptions: { + parserOptions: { + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + ignores: ["template/**"], + }, +]; diff --git a/packages/create-coda/package.json b/packages/create-coda/package.json new file mode 100644 index 00000000..c904416b --- /dev/null +++ b/packages/create-coda/package.json @@ -0,0 +1,47 @@ +{ + "name": "@macalinao/create-coda", + "version": "0.0.0", + "description": "Create a new Coda client project", + "type": "module", + "bin": { + "create-coda": "./dist/bin.js" + }, + "main": "./dist/bin.js", + "files": [ + "dist/", + "template/" + ], + "scripts": { + "build": "tsc", + "clean": "rm -rf dist/ template/node_modules template/dist template/src/generated", + "lint": "eslint . --cache" + }, + "keywords": [ + "coda", + "solana", + "codama", + "client", + "generator", + "create", + "template" + ], + "license": "MIT", + "homepage": "https://github.com/macalinao/coda", + "repository": { + "type": "git", + "url": "https://github.com/macalinao/coda.git" + }, + "bugs": { + "url": "https://github.com/macalinao/coda/issues" + }, + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@types/node": "^22.0.0", + "eslint": "catalog:", + "typescript": "catalog:" + } +} diff --git a/packages/create-coda/src/bin.ts b/packages/create-coda/src/bin.ts new file mode 100644 index 00000000..406f85fe --- /dev/null +++ b/packages/create-coda/src/bin.ts @@ -0,0 +1,47 @@ +#!/usr/bin/env node + +import { existsSync } from "node:fs"; +import { cp, mkdir, readdir } from "node:fs/promises"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +async function main(): Promise { + const projectName = process.argv[2] ?? "my-coda-client"; + const targetDir = resolve(process.cwd(), projectName); + + // Check if directory already exists + if (existsSync(targetDir)) { + const files = await readdir(targetDir); + if (files.length > 0) { + console.error( + `Error: Directory ${projectName} already exists and is not empty.`, + ); + process.exit(1); + } + } + + // Create target directory + await mkdir(targetDir, { recursive: true }); + + // Copy template files (template is at the package root, not in dist) + const templateDir = join(__dirname, "..", "template"); + await cp(templateDir, targetDir, { recursive: true }); + + console.log(`✨ Created Coda client project at ${projectName}`); + console.log(""); + console.log("Next steps:"); + console.log(` cd ${projectName}`); + console.log(" bun install"); + console.log(" # Add your IDL file to idls/ directory"); + console.log(" bun run codegen"); + console.log(" bun run build"); + console.log(""); + console.log("Happy coding! 🚀"); +} + +main().catch((error: unknown) => { + console.error("Error creating project:", error); + process.exit(1); +}); diff --git a/packages/create-coda/template/.gitignore b/packages/create-coda/template/.gitignore new file mode 100644 index 00000000..24943919 --- /dev/null +++ b/packages/create-coda/template/.gitignore @@ -0,0 +1,31 @@ +# Dependencies +node_modules/ +.pnp +.pnp.js + +# Build output +dist/ +*.tsbuildinfo + +# Debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* +bun.lockb + +# Environment +.env +.env.local +.env.*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store + +# Cache +.turbo/ +.eslintcache \ No newline at end of file diff --git a/packages/create-coda/template/README.md b/packages/create-coda/template/README.md new file mode 100644 index 00000000..4bb4e49c --- /dev/null +++ b/packages/create-coda/template/README.md @@ -0,0 +1,63 @@ +# My Coda Client + +TypeScript client for Solana program generated with [Coda](https://github.com/macalinao/coda). + +## Getting Started + +1. **Add your IDL file(s)** + - Place your Anchor IDL JSON file(s) in the `idls/` directory + - Remove the example.json file + +2. **Generate the client code** + ```bash + bun run codegen + ``` + +3. **Build the project** + ```bash + bun run build + ``` + +## Project Structure + +``` +. +├── idls/ # Anchor IDL files +├── src/ +│ ├── generated/ # Generated client code (do not edit) +│ └── index.ts # Main entry point +├── coda.config.mjs # Coda configuration +└── package.json +``` + +## Available Scripts + +- `bun run codegen` - Generate TypeScript client from IDL +- `bun run build` - Build the TypeScript project +- `bun run clean` - Clean build artifacts +- `bun run lint` - Run ESLint +- `bun test` - Run tests + +## Configuration + +Edit `coda.config.mjs` to customize: +- IDL discovery patterns +- Output directory +- Custom PDAs and visitors + +## Usage + +```typescript +import { createInitializeInstruction } from "./dist/index.js"; + +// Use the generated client +const instruction = createInitializeInstruction({ + // ... instruction parameters +}); +``` + +## Learn More + +- [Coda Documentation](https://github.com/macalinao/coda) +- [Codama Documentation](https://github.com/codama-idl/codama) +- [Anchor Framework](https://www.anchor-lang.com/) \ No newline at end of file diff --git a/packages/create-coda/template/coda.config.mjs b/packages/create-coda/template/coda.config.mjs new file mode 100644 index 00000000..e2a16661 --- /dev/null +++ b/packages/create-coda/template/coda.config.mjs @@ -0,0 +1,21 @@ +import { defineConfig } from "@macalinao/coda"; + +export default defineConfig({ + // Coda will automatically discover IDLs from ./idls/*.json + // You can override this by specifying a custom path: + // idlPath: "./idls/my_program.json", + + // For multiple IDLs, use a glob pattern or array: + // idlPath: "./idls/*.json", + // idlPath: ["./idls/program1.json", "./idls/program2.json"], + + // Output directory for generated code (default: "./src/generated") + outputDir: "./src/generated", + + // Optional: Add custom Codama visitors for advanced customization + // visitors: [ + // addPdasVisitor({ + // // Define custom PDAs here + // }) + // ] +}); diff --git a/packages/create-coda/template/eslint.config.js b/packages/create-coda/template/eslint.config.js new file mode 100644 index 00000000..f157753e --- /dev/null +++ b/packages/create-coda/template/eslint.config.js @@ -0,0 +1,31 @@ +import { configs } from "@macalinao/eslint-config"; + +export default [ + ...configs.fast, + { + languageOptions: { + parserOptions: { + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + files: ["src/generated/**/*.ts"], + rules: { + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/prefer-nullish-coalescing": "off", + }, + }, + { + files: [ + "src/generated/instructions/*.ts", + "src/generated/types/*.ts", + "src/generated/errors/*.ts", + ], + rules: { + "@typescript-eslint/no-unnecessary-condition": "off", + "no-constant-condition": "off", + "@typescript-eslint/no-empty-object-type": "off", + }, + }, +]; diff --git a/packages/create-coda/template/idls/example.json b/packages/create-coda/template/idls/example.json new file mode 100644 index 00000000..b5fb1259 --- /dev/null +++ b/packages/create-coda/template/idls/example.json @@ -0,0 +1,79 @@ +{ + "version": "0.1.0", + "name": "example", + "instructions": [ + { + "name": "Initialize", + "accounts": [ + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "state", + "isMut": true, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "data", + "type": "u64" + } + ] + }, + { + "name": "Update", + "accounts": [ + { + "name": "authority", + "isMut": false, + "isSigner": true + }, + { + "name": "state", + "isMut": true, + "isSigner": false + } + ], + "args": [ + { + "name": "newData", + "type": "u64" + } + ] + } + ], + "accounts": [ + { + "name": "State", + "type": { + "kind": "struct", + "fields": [ + { + "name": "authority", + "type": "publicKey" + }, + { + "name": "data", + "type": "u64" + } + ] + } + } + ], + "types": [], + "errors": [ + { + "code": 6000, + "name": "Unauthorized", + "msg": "Unauthorized access" + } + ] +} diff --git a/packages/create-coda/template/package.json b/packages/create-coda/template/package.json new file mode 100644 index 00000000..678c9e39 --- /dev/null +++ b/packages/create-coda/template/package.json @@ -0,0 +1,44 @@ +{ + "name": "my-coda-client", + "version": "0.1.0", + "description": "TypeScript client for Solana program", + "type": "module", + "sideEffects": false, + "license": "Apache-2.0", + "keywords": [ + "coda", + "solana", + "client", + "typescript" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, + "files": [ + "dist/", + "src/" + ], + "scripts": { + "build": "tsc", + "clean": "rm -fr dist/ tsconfig.tsbuildinfo", + "codegen": "rm -fr src/generated/ && coda generate", + "lint": "eslint . --cache" + }, + "peerDependencies": { + "@solana/kit": "*" + }, + "devDependencies": { + "@macalinao/coda": "^0.2.3", + "@macalinao/eslint-config": "^5", + "@macalinao/tsconfig": "^3.2.3", + "@solana/kit": "*", + "@types/bun": "latest", + "eslint": "^9.0.0", + "typescript": "^5.0.0" + } +} diff --git a/packages/create-coda/template/src/index.ts b/packages/create-coda/template/src/index.ts new file mode 100644 index 00000000..ab03489a --- /dev/null +++ b/packages/create-coda/template/src/index.ts @@ -0,0 +1,2 @@ +// Re-export all generated code +export * from "./generated/index.js"; diff --git a/packages/create-coda/template/tsconfig.json b/packages/create-coda/template/tsconfig.json new file mode 100644 index 00000000..e528d933 --- /dev/null +++ b/packages/create-coda/template/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@macalinao/tsconfig/tsconfig.base.json" +} diff --git a/packages/create-coda/tsconfig.json b/packages/create-coda/tsconfig.json new file mode 100644 index 00000000..a6bfbbbf --- /dev/null +++ b/packages/create-coda/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "@macalinao/tsconfig/tsconfig.base.json", + "compilerOptions": { + "types": ["node"] + } +}