import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars import * as borsh from "@project-serum/borsh" export type SwapFields = { fields: types.SwapInfoFields } export type SwapValue = { fields: types.SwapInfo } export interface SwapJSON { kind: "Swap" value: { fields: types.SwapInfoJSON } } export class Swap { readonly discriminator = 0 readonly kind = "Swap" readonly value: SwapValue constructor(value: SwapFields) { this.value = { fields: new types.SwapInfo({ ...value.fields }), } } toJSON(): SwapJSON { return { kind: "Swap", value: { fields: this.value.fields.toJSON(), }, } } toEncodable() { return { Swap: { fields: types.SwapInfo.toEncodable(this.value.fields), }, } } } export interface AbortJSON { kind: "Abort" } export class Abort { readonly discriminator = 1 readonly kind = "Abort" toJSON(): AbortJSON { return { kind: "Abort", } } toEncodable() { return { Abort: {}, } } } // eslint-disable-next-line @typescript-eslint/no-explicit-any export function fromDecoded(obj: any): types.RaydiumOpCodeKind { if (typeof obj !== "object") { throw new Error("Invalid enum object") } if ("Swap" in obj) { const val = obj["Swap"] return new Swap({ fields: types.SwapInfo.fromDecoded(val["fields"]), }) } if ("Abort" in obj) { return new Abort() } throw new Error("Invalid enum object") } export function fromJSON( obj: types.RaydiumOpCodeJSON ): types.RaydiumOpCodeKind { switch (obj.kind) { case "Swap": { return new Swap({ fields: types.SwapInfo.fromJSON(obj.value.fields), }) } case "Abort": { return new Abort() } } } export function layout(property?: string) { const ret = borsh.rustEnum([ borsh.struct([types.SwapInfo.layout("fields")], "Swap"), borsh.struct([], "Abort"), ]) if (property !== undefined) { return ret.replicate(property) } return ret }