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 interface EscrowAccountFields { mint: PublicKey tokenAcct: PublicKey locator: types.XTokenLocatorFields tokenReturnStrategy: types.TokenReturnStrategyKind hasReturned: types.HasReturnedKind tokens: BN } export interface EscrowAccountJSON { mint: string tokenAcct: string locator: types.XTokenLocatorJSON tokenReturnStrategy: types.TokenReturnStrategyJSON hasReturned: types.HasReturnedJSON tokens: string } export class EscrowAccount { readonly mint: PublicKey readonly tokenAcct: PublicKey readonly locator: types.XTokenLocator readonly tokenReturnStrategy: types.TokenReturnStrategyKind readonly hasReturned: types.HasReturnedKind readonly tokens: BN constructor(fields: EscrowAccountFields) { this.mint = fields.mint this.tokenAcct = fields.tokenAcct this.locator = new types.XTokenLocator({ ...fields.locator }) this.tokenReturnStrategy = fields.tokenReturnStrategy this.hasReturned = fields.hasReturned this.tokens = fields.tokens } static layout(property?: string) { return borsh.struct( [ borsh.publicKey("mint"), borsh.publicKey("tokenAcct"), types.XTokenLocator.layout("locator"), types.TokenReturnStrategy.layout("tokenReturnStrategy"), types.HasReturned.layout("hasReturned"), borsh.u64("tokens"), ], property ) } // eslint-disable-next-line @typescript-eslint/no-explicit-any static fromDecoded(obj: any) { return new EscrowAccount({ mint: obj.mint, tokenAcct: obj.tokenAcct, locator: types.XTokenLocator.fromDecoded(obj.locator), tokenReturnStrategy: types.TokenReturnStrategy.fromDecoded( obj.tokenReturnStrategy ), hasReturned: types.HasReturned.fromDecoded(obj.hasReturned), tokens: obj.tokens, }) } static toEncodable(fields: EscrowAccountFields) { return { mint: fields.mint, tokenAcct: fields.tokenAcct, locator: types.XTokenLocator.toEncodable(fields.locator), tokenReturnStrategy: fields.tokenReturnStrategy.toEncodable(), hasReturned: fields.hasReturned.toEncodable(), tokens: fields.tokens, } } toJSON(): EscrowAccountJSON { return { mint: this.mint.toString(), tokenAcct: this.tokenAcct.toString(), locator: this.locator.toJSON(), tokenReturnStrategy: this.tokenReturnStrategy.toJSON(), hasReturned: this.hasReturned.toJSON(), tokens: this.tokens.toString(), } } static fromJSON(obj: EscrowAccountJSON): EscrowAccount { return new EscrowAccount({ mint: new PublicKey(obj.mint), tokenAcct: new PublicKey(obj.tokenAcct), locator: types.XTokenLocator.fromJSON(obj.locator), tokenReturnStrategy: types.TokenReturnStrategy.fromJSON( obj.tokenReturnStrategy ), hasReturned: types.HasReturned.fromJSON(obj.hasReturned), tokens: new BN(obj.tokens), }) } toEncodable() { return EscrowAccount.toEncodable(this) } }