From 0d01414866142c65f385f9f5ea291365e838af8f Mon Sep 17 00:00:00 2001 From: Nagaprasadvr Date: Mon, 11 Sep 2023 11:55:17 +0530 Subject: [PATCH 1/3] getMetaData --- .../js/src/plugins/instrumentModule/types.ts | 6 +++++ .../helpers.ts | 9 ++++++++ .../instrument.ts | 23 ++++++++++++++----- .../helpers.ts | 9 ++++++++ .../instrument.ts | 23 ++++++++++++++----- .../js/src/plugins/rfqModule/models/Rfq.ts | 14 ++++++++++- .../spotInstrumentModule/instruments.ts | 14 +++++++++-- .../integration/psyoptionsAmerican.spec.ts | 5 +++- .../integration/psyoptionsEuropean.spec.ts | 5 +++- packages/js/tests/unit/rfq.spec.ts | 5 ++++ 10 files changed, 96 insertions(+), 17 deletions(-) diff --git a/packages/js/src/plugins/instrumentModule/types.ts b/packages/js/src/plugins/instrumentModule/types.ts index 600ec3a28..5edee48d4 100644 --- a/packages/js/src/plugins/instrumentModule/types.ts +++ b/packages/js/src/plugins/instrumentModule/types.ts @@ -9,6 +9,11 @@ export interface LegInstrumentParser { parseFromLeg(convergence: Convergence, leg: Leg): LegInstrument; } +export type LegMetaData = { + legType: 'spot' | 'options' | 'futures'; + underlyingMint: PublicKey; +}; + export interface LegInstrument { getProgramId: () => PublicKey; getBaseAssetIndex: () => BaseAssetIndex; @@ -17,6 +22,7 @@ export interface LegInstrument { getSide: () => LegSide; serializeInstrumentData: () => Buffer; getValidationAccounts(): Promise; + getMetaData(): LegMetaData; } // TODO add registration of quote instruments diff --git a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts index 3e6499227..78ce6a0ba 100644 --- a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts +++ b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts @@ -2,6 +2,7 @@ import * as psyoptionsAmerican from '@mithraic-labs/psy-american'; import { BN } from 'bn.js'; import { PublicKey } from '@solana/web3.js'; +import { Leg } from '@convergence-rfq/rfq'; import { Convergence } from '../../Convergence'; import { ATAExistence, getOrCreateATA } from '../../utils/ata'; @@ -11,8 +12,10 @@ import { InstructionWithSigners, TransactionBuilder, } from '../../utils/TransactionBuilder'; +import { LegInstrument } from '../instrumentModule'; import { PsyoptionsAmericanInstrument } from './types'; import { createAmericanProgram } from './instrument'; +import { psyoptionsAmericanInstrumentProgram } from './programs'; export const mintAmericanOptions = async ( convergence: Convergence, @@ -185,3 +188,9 @@ export const getOrCreateAmericanOptionATAs = async ( } return ATAExistence.NOTEXISTS; }; + +export function hasPsyoptionsAmericanLeg(legs: Leg[]): boolean { + return legs.some((leg) => + leg.instrumentProgram.equals(psyoptionsAmericanInstrumentProgram.address) + ); +} diff --git a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts index ad226fc03..3ddd04076 100644 --- a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts +++ b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts @@ -8,7 +8,7 @@ import * as anchor from '@project-serum/anchor'; import * as psyoptionsAmerican from '@mithraic-labs/psy-american'; import BN from 'bn.js'; import { Mint } from '../tokenModule'; -import { LegInstrument } from '../instrumentModule'; +import { LegInstrument, LegMetaData } from '../instrumentModule'; import { addDecimals, removeDecimals } from '../../utils/conversions'; import { Convergence } from '../../Convergence'; import { createSerializerFromFixableBeetArgsStruct } from '../../types'; @@ -59,13 +59,20 @@ export class PsyoptionsAmericanInstrument implements LegInstrument { readonly baseAssetIndex: BaseAssetIndex, readonly amount: number, readonly side: LegSide, - private optionMeta?: OptionMarketWithKey + public optionMeta: OptionMarketWithKey ) {} getBaseAssetIndex = () => this.baseAssetIndex; getAmount = () => this.amount; getDecimals = () => PsyoptionsAmericanInstrument.decimals; getSide = () => this.side; + getMetaData() { + const legMetaData: LegMetaData = { + legType: 'options', + underlyingMint: this.optionMeta.underlyingAssetMint, + }; + return legMetaData; + } static async create( convergence: Convergence, @@ -196,10 +203,10 @@ export class PsyoptionsAmericanInstrument implements LegInstrument { } export const psyoptionsAmericanInstrumentParser = { - parseFromLeg( + async parseFromLeg( convergence: Convergence, leg: Leg - ): PsyoptionsAmericanInstrument { + ): Promise { const { side, instrumentAmount, instrumentData, baseAssetIndex } = leg; const [ { @@ -215,7 +222,10 @@ export const psyoptionsAmericanInstrumentParser = { ] = psyoptionsAmericanInstrumentDataSerializer.deserialize( Buffer.from(instrumentData) ); - + const optionMeta = await PsyoptionsAmericanInstrument.fetchMeta( + convergence, + metaKey + ); return new PsyoptionsAmericanInstrument( convergence, optionType, @@ -231,7 +241,8 @@ export const psyoptionsAmericanInstrumentParser = { metaKey, baseAssetIndex, removeDecimals(instrumentAmount, PsyoptionsAmericanInstrument.decimals), - fromSolitaLegSide(side) + fromSolitaLegSide(side), + optionMeta ); }, }; diff --git a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts index d3c021a2a..f735571dc 100644 --- a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts +++ b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts @@ -2,12 +2,15 @@ import * as psyoptionsEuropean from '@mithraic-labs/tokenized-euros'; import * as anchor from '@project-serum/anchor'; import { Keypair, PublicKey } from '@solana/web3.js'; import { BN } from 'bn.js'; +import { Leg } from '@convergence-rfq/rfq'; import { Mint } from '../tokenModule'; import { ATAExistence, getOrCreateATA } from '../../utils/ata'; import { addDecimals } from '../../utils/conversions'; import { TransactionBuilder } from '../../utils/TransactionBuilder'; import { Convergence } from '../../Convergence'; +import { LegInstrument } from '../instrumentModule'; import { PsyoptionsEuropeanInstrument } from './instrument'; +import { psyoptionsEuropeanInstrumentProgram } from './programs'; import { Pda } from '@/types/Pda'; import { makeConfirmOptionsFinalizedOnMainnet } from '@/types/Operation'; import { toBigNumber } from '@/types/BigNumber'; @@ -264,3 +267,9 @@ export const getOrCreateEuropeanOptionATAs = async ( } return ATAExistence.NOTEXISTS; }; + +export function hasPsyoptionsEuropeanLeg(legs: Leg[]): boolean { + return legs.some((leg) => + leg.instrumentProgram.equals(psyoptionsEuropeanInstrumentProgram.address) + ); +} diff --git a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts index 18ac0a928..dae578a5b 100644 --- a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts +++ b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts @@ -12,7 +12,7 @@ import { import { publicKey } from '@convergence-rfq/beet-solana'; import { Mint } from '../tokenModule'; -import { LegInstrument } from '../instrumentModule'; +import { LegInstrument, LegMetaData } from '../instrumentModule'; import { addDecimals, removeDecimals } from '../../utils/conversions'; import { assert } from '../../utils/assert'; import { Convergence } from '../../Convergence'; @@ -95,13 +95,20 @@ export class PsyoptionsEuropeanInstrument implements LegInstrument { readonly baseAssetIndex: BaseAssetIndex, readonly amount: number, readonly side: LegSide, - private optionMeta?: EuroMeta + public optionMeta: EuroMeta ) {} getBaseAssetIndex = () => this.baseAssetIndex; getAmount = () => this.amount; getDecimals = () => PsyoptionsEuropeanInstrument.decimals; getSide = () => this.side; + getMetaData() { + const legMetaData: LegMetaData = { + legType: 'options', + underlyingMint: this.optionMeta.underlyingMint, + }; + return legMetaData; + } static async create( convergence: Convergence, @@ -214,10 +221,10 @@ export class PsyoptionsEuropeanInstrument implements LegInstrument { } export const psyoptionsEuropeanInstrumentParser = { - parseFromLeg( + async parseFromLeg( convergence: Convergence, leg: Leg - ): PsyoptionsEuropeanInstrument { + ): Promise { const { side, instrumentAmount, instrumentData, baseAssetIndex } = leg; const [ { @@ -233,7 +240,10 @@ export const psyoptionsEuropeanInstrumentParser = { ] = psyoptionsEuropeanInstrumentDataSerializer.deserialize( Buffer.from(instrumentData) ); - + const optionMeta = await PsyoptionsEuropeanInstrument.fetchMeta( + convergence, + metaKey + ); return new PsyoptionsEuropeanInstrument( convergence, optionType, @@ -249,7 +259,8 @@ export const psyoptionsEuropeanInstrumentParser = { metaKey, baseAssetIndex, removeDecimals(instrumentAmount, PsyoptionsEuropeanInstrument.decimals), - fromSolitaLegSide(side) + fromSolitaLegSide(side), + optionMeta ); }, }; diff --git a/packages/js/src/plugins/rfqModule/models/Rfq.ts b/packages/js/src/plugins/rfqModule/models/Rfq.ts index d53e04e06..eda93a24e 100644 --- a/packages/js/src/plugins/rfqModule/models/Rfq.ts +++ b/packages/js/src/plugins/rfqModule/models/Rfq.ts @@ -15,6 +15,8 @@ import { collateralMintCache } from '../../../plugins/collateralModule'; import { FixedSize, fromSolitaFixedSize } from './FixedSize'; import { OrderType, fromSolitaOrderType } from './OrderType'; import { StoredRfqState, fromSolitaStoredRfqState } from './StoredRfqState'; +import { hasPsyoptionsAmericanLeg } from '@/plugins/psyoptionsAmericanInstrumentModule'; +import { hasPsyoptionsEuropeanLeg } from '@/plugins/psyoptionsEuropeanInstrumentModule'; /** * This model captures all the relevant information about an RFQ @@ -104,6 +106,16 @@ export const toRfq = async ( ); const collateralMint = await collateralMintCache.get(convergence); const collateralDecimals = collateralMint.decimals; + const { legs } = account.data; + let parsedLegs: LegInstrument[]; + if (hasPsyoptionsAmericanLeg(legs) || hasPsyoptionsEuropeanLeg(legs)) { + parsedLegs = await Promise.all( + legs.map((leg) => convergence.parseLegInstrument(leg)) + ); + } else { + parsedLegs = legs.map((leg) => convergence.parseLegInstrument(leg)); + } + return { model: 'rfq', address: account.publicKey, @@ -130,6 +142,6 @@ export const toRfq = async ( totalResponses: account.data.totalResponses, clearedResponses: account.data.clearedResponses, confirmedResponses: account.data.confirmedResponses, - legs: account.data.legs.map((leg) => convergence.parseLegInstrument(leg)), + legs: parsedLegs, }; }; diff --git a/packages/js/src/plugins/spotInstrumentModule/instruments.ts b/packages/js/src/plugins/spotInstrumentModule/instruments.ts index b4f0070ad..e287c3f2a 100644 --- a/packages/js/src/plugins/spotInstrumentModule/instruments.ts +++ b/packages/js/src/plugins/spotInstrumentModule/instruments.ts @@ -4,7 +4,11 @@ import { FixableBeetArgsStruct } from '@convergence-rfq/beet'; import { publicKey } from '@convergence-rfq/beet-solana'; import { Mint } from '../tokenModule'; -import { LegInstrument, QuoteInstrument } from '../instrumentModule'; +import { + LegInstrument, + LegMetaData, + QuoteInstrument, +} from '../instrumentModule'; import { Convergence } from '../../Convergence'; import { createSerializerFromFixableBeetArgsStruct } from '../../types'; import { removeDecimals } from '../../utils/conversions'; @@ -42,7 +46,13 @@ export class SpotLegInstrument implements LegInstrument { getDecimals = () => this.decimals; getAmount = () => this.amount; getBaseAssetIndex = () => this.baseAssetIndex; - + getMetaData() { + const legMetaData: LegMetaData = { + legType: 'spot', + underlyingMint: this.mintAddress, + }; + return legMetaData; + } static async create( convergence: Convergence, mint: Mint, diff --git a/packages/js/tests/integration/psyoptionsAmerican.spec.ts b/packages/js/tests/integration/psyoptionsAmerican.spec.ts index 0e32836a9..8a8a2dab8 100644 --- a/packages/js/tests/integration/psyoptionsAmerican.spec.ts +++ b/packages/js/tests/integration/psyoptionsAmerican.spec.ts @@ -36,7 +36,10 @@ describe('integration.psyoptionsAmerican', () => { quoteMint ); expect(rfq).toHaveProperty('address'); - + console.log( + 'rfq.optionMeta', + rfq.legs[1].getMetaData().underlyingMint.toBase58() + ); const { rfqResponse } = await respondToRfq(makerCvg, rfq, 12.1); expect(rfqResponse).toHaveProperty('address'); diff --git a/packages/js/tests/integration/psyoptionsEuropean.spec.ts b/packages/js/tests/integration/psyoptionsEuropean.spec.ts index 54ee6ea70..a3df0647b 100644 --- a/packages/js/tests/integration/psyoptionsEuropean.spec.ts +++ b/packages/js/tests/integration/psyoptionsEuropean.spec.ts @@ -35,7 +35,10 @@ describe('integration.psyoptionsEuropean', () => { baseMint, quoteMint ); - + console.log( + 'rfq.optionMeta', + rfq.legs[1].getMetaData().underlyingMint.toBase58() + ); expect(rfq).toHaveProperty('address'); expect(response.signature).toBeDefined(); diff --git a/packages/js/tests/unit/rfq.spec.ts b/packages/js/tests/unit/rfq.spec.ts index 9fd4b571f..d44018f31 100644 --- a/packages/js/tests/unit/rfq.spec.ts +++ b/packages/js/tests/unit/rfq.spec.ts @@ -37,7 +37,12 @@ describe('unit.rfq', () => { quoteAsset: await SpotQuoteInstrument.create(takerCvg, quoteMint), fixedSize, }); + console.log( + 'rfq.optionMeta', + rfq.legs[1].getMetaData().underlyingMint.toBase58() + ); // @ts-ignore + expect(fixedSize.amount).toBeCloseTo(rfq.size.amount); }); From 7d9d4f7e1c1697322058d95c802b1852c059886e Mon Sep 17 00:00:00 2001 From: Nagaprasadvr Date: Mon, 11 Sep 2023 15:23:55 +0530 Subject: [PATCH 2/3] getBaseAssetMint method to legInstruments --- packages/js/src/plugins/instrumentModule/types.ts | 7 +------ .../instrument.ts | 10 ++-------- .../instrument.ts | 10 ++-------- .../plugins/spotInstrumentModule/instruments.ts | 14 ++------------ .../tests/integration/psyoptionsAmerican.spec.ts | 4 ---- .../tests/integration/psyoptionsEuropean.spec.ts | 4 ---- packages/js/tests/unit/rfq.spec.ts | 6 +----- 7 files changed, 8 insertions(+), 47 deletions(-) diff --git a/packages/js/src/plugins/instrumentModule/types.ts b/packages/js/src/plugins/instrumentModule/types.ts index 5edee48d4..11e6b8dd2 100644 --- a/packages/js/src/plugins/instrumentModule/types.ts +++ b/packages/js/src/plugins/instrumentModule/types.ts @@ -9,11 +9,6 @@ export interface LegInstrumentParser { parseFromLeg(convergence: Convergence, leg: Leg): LegInstrument; } -export type LegMetaData = { - legType: 'spot' | 'options' | 'futures'; - underlyingMint: PublicKey; -}; - export interface LegInstrument { getProgramId: () => PublicKey; getBaseAssetIndex: () => BaseAssetIndex; @@ -22,7 +17,7 @@ export interface LegInstrument { getSide: () => LegSide; serializeInstrumentData: () => Buffer; getValidationAccounts(): Promise; - getMetaData(): LegMetaData; + getBaseAssetMint(): PublicKey; } // TODO add registration of quote instruments diff --git a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts index 3ddd04076..a988fb285 100644 --- a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts +++ b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/instrument.ts @@ -8,7 +8,7 @@ import * as anchor from '@project-serum/anchor'; import * as psyoptionsAmerican from '@mithraic-labs/psy-american'; import BN from 'bn.js'; import { Mint } from '../tokenModule'; -import { LegInstrument, LegMetaData } from '../instrumentModule'; +import { LegInstrument } from '../instrumentModule'; import { addDecimals, removeDecimals } from '../../utils/conversions'; import { Convergence } from '../../Convergence'; import { createSerializerFromFixableBeetArgsStruct } from '../../types'; @@ -66,13 +66,7 @@ export class PsyoptionsAmericanInstrument implements LegInstrument { getAmount = () => this.amount; getDecimals = () => PsyoptionsAmericanInstrument.decimals; getSide = () => this.side; - getMetaData() { - const legMetaData: LegMetaData = { - legType: 'options', - underlyingMint: this.optionMeta.underlyingAssetMint, - }; - return legMetaData; - } + getBaseAssetMint = () => this.optionMeta.underlyingAssetMint; static async create( convergence: Convergence, diff --git a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts index dae578a5b..d331660ec 100644 --- a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts +++ b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/instrument.ts @@ -12,7 +12,7 @@ import { import { publicKey } from '@convergence-rfq/beet-solana'; import { Mint } from '../tokenModule'; -import { LegInstrument, LegMetaData } from '../instrumentModule'; +import { LegInstrument } from '../instrumentModule'; import { addDecimals, removeDecimals } from '../../utils/conversions'; import { assert } from '../../utils/assert'; import { Convergence } from '../../Convergence'; @@ -102,13 +102,7 @@ export class PsyoptionsEuropeanInstrument implements LegInstrument { getAmount = () => this.amount; getDecimals = () => PsyoptionsEuropeanInstrument.decimals; getSide = () => this.side; - getMetaData() { - const legMetaData: LegMetaData = { - legType: 'options', - underlyingMint: this.optionMeta.underlyingMint, - }; - return legMetaData; - } + getBaseAssetMint = () => this.optionMeta.underlyingMint; static async create( convergence: Convergence, diff --git a/packages/js/src/plugins/spotInstrumentModule/instruments.ts b/packages/js/src/plugins/spotInstrumentModule/instruments.ts index e287c3f2a..96e3a38dd 100644 --- a/packages/js/src/plugins/spotInstrumentModule/instruments.ts +++ b/packages/js/src/plugins/spotInstrumentModule/instruments.ts @@ -4,11 +4,7 @@ import { FixableBeetArgsStruct } from '@convergence-rfq/beet'; import { publicKey } from '@convergence-rfq/beet-solana'; import { Mint } from '../tokenModule'; -import { - LegInstrument, - LegMetaData, - QuoteInstrument, -} from '../instrumentModule'; +import { LegInstrument, QuoteInstrument } from '../instrumentModule'; import { Convergence } from '../../Convergence'; import { createSerializerFromFixableBeetArgsStruct } from '../../types'; import { removeDecimals } from '../../utils/conversions'; @@ -46,13 +42,7 @@ export class SpotLegInstrument implements LegInstrument { getDecimals = () => this.decimals; getAmount = () => this.amount; getBaseAssetIndex = () => this.baseAssetIndex; - getMetaData() { - const legMetaData: LegMetaData = { - legType: 'spot', - underlyingMint: this.mintAddress, - }; - return legMetaData; - } + getBaseAssetMint = () => this.mintAddress; static async create( convergence: Convergence, mint: Mint, diff --git a/packages/js/tests/integration/psyoptionsAmerican.spec.ts b/packages/js/tests/integration/psyoptionsAmerican.spec.ts index 8a8a2dab8..7037c1a72 100644 --- a/packages/js/tests/integration/psyoptionsAmerican.spec.ts +++ b/packages/js/tests/integration/psyoptionsAmerican.spec.ts @@ -36,10 +36,6 @@ describe('integration.psyoptionsAmerican', () => { quoteMint ); expect(rfq).toHaveProperty('address'); - console.log( - 'rfq.optionMeta', - rfq.legs[1].getMetaData().underlyingMint.toBase58() - ); const { rfqResponse } = await respondToRfq(makerCvg, rfq, 12.1); expect(rfqResponse).toHaveProperty('address'); diff --git a/packages/js/tests/integration/psyoptionsEuropean.spec.ts b/packages/js/tests/integration/psyoptionsEuropean.spec.ts index a3df0647b..56be54a9b 100644 --- a/packages/js/tests/integration/psyoptionsEuropean.spec.ts +++ b/packages/js/tests/integration/psyoptionsEuropean.spec.ts @@ -35,10 +35,6 @@ describe('integration.psyoptionsEuropean', () => { baseMint, quoteMint ); - console.log( - 'rfq.optionMeta', - rfq.legs[1].getMetaData().underlyingMint.toBase58() - ); expect(rfq).toHaveProperty('address'); expect(response.signature).toBeDefined(); diff --git a/packages/js/tests/unit/rfq.spec.ts b/packages/js/tests/unit/rfq.spec.ts index d44018f31..ae04508d6 100644 --- a/packages/js/tests/unit/rfq.spec.ts +++ b/packages/js/tests/unit/rfq.spec.ts @@ -37,12 +37,8 @@ describe('unit.rfq', () => { quoteAsset: await SpotQuoteInstrument.create(takerCvg, quoteMint), fixedSize, }); - console.log( - 'rfq.optionMeta', - rfq.legs[1].getMetaData().underlyingMint.toBase58() - ); - // @ts-ignore + // @ts-ignore expect(fixedSize.amount).toBeCloseTo(rfq.size.amount); }); From 50548deb2bdf559bb6f8c2f49223784cf2e85719 Mon Sep 17 00:00:00 2001 From: Nagaprasadvr Date: Mon, 11 Sep 2023 15:34:46 +0530 Subject: [PATCH 3/3] cleanup --- packages/js/src/plugins/instrumentModule/plugin.ts | 2 +- packages/js/src/plugins/instrumentModule/types.ts | 2 +- .../psyoptionsAmericanInstrumentModule/helpers.ts | 1 - .../psyoptionsEuropeanInstrumentModule/helpers.ts | 1 - packages/js/src/plugins/rfqModule/models/Rfq.ts | 13 +++---------- .../src/plugins/spotInstrumentModule/instruments.ts | 5 ++++- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/packages/js/src/plugins/instrumentModule/plugin.ts b/packages/js/src/plugins/instrumentModule/plugin.ts index 23c3a7f6a..8073daead 100644 --- a/packages/js/src/plugins/instrumentModule/plugin.ts +++ b/packages/js/src/plugins/instrumentModule/plugin.ts @@ -48,7 +48,7 @@ declare module '../../Convergence' { programAddress: PublicKey, factory: LegInstrumentParser ): void; - parseLegInstrument(leg: SolitaLeg): LegInstrument; + parseLegInstrument(leg: SolitaLeg): Promise; } } diff --git a/packages/js/src/plugins/instrumentModule/types.ts b/packages/js/src/plugins/instrumentModule/types.ts index 11e6b8dd2..648e8a872 100644 --- a/packages/js/src/plugins/instrumentModule/types.ts +++ b/packages/js/src/plugins/instrumentModule/types.ts @@ -6,7 +6,7 @@ import { Convergence } from '../../Convergence'; import { LegSide } from '../rfqModule/models/LegSide'; export interface LegInstrumentParser { - parseFromLeg(convergence: Convergence, leg: Leg): LegInstrument; + parseFromLeg(convergence: Convergence, leg: Leg): Promise; } export interface LegInstrument { diff --git a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts index 78ce6a0ba..82030b985 100644 --- a/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts +++ b/packages/js/src/plugins/psyoptionsAmericanInstrumentModule/helpers.ts @@ -12,7 +12,6 @@ import { InstructionWithSigners, TransactionBuilder, } from '../../utils/TransactionBuilder'; -import { LegInstrument } from '../instrumentModule'; import { PsyoptionsAmericanInstrument } from './types'; import { createAmericanProgram } from './instrument'; import { psyoptionsAmericanInstrumentProgram } from './programs'; diff --git a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts index f735571dc..5b6649a4d 100644 --- a/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts +++ b/packages/js/src/plugins/psyoptionsEuropeanInstrumentModule/helpers.ts @@ -8,7 +8,6 @@ import { ATAExistence, getOrCreateATA } from '../../utils/ata'; import { addDecimals } from '../../utils/conversions'; import { TransactionBuilder } from '../../utils/TransactionBuilder'; import { Convergence } from '../../Convergence'; -import { LegInstrument } from '../instrumentModule'; import { PsyoptionsEuropeanInstrument } from './instrument'; import { psyoptionsEuropeanInstrumentProgram } from './programs'; import { Pda } from '@/types/Pda'; diff --git a/packages/js/src/plugins/rfqModule/models/Rfq.ts b/packages/js/src/plugins/rfqModule/models/Rfq.ts index eda93a24e..23f5cda19 100644 --- a/packages/js/src/plugins/rfqModule/models/Rfq.ts +++ b/packages/js/src/plugins/rfqModule/models/Rfq.ts @@ -15,8 +15,6 @@ import { collateralMintCache } from '../../../plugins/collateralModule'; import { FixedSize, fromSolitaFixedSize } from './FixedSize'; import { OrderType, fromSolitaOrderType } from './OrderType'; import { StoredRfqState, fromSolitaStoredRfqState } from './StoredRfqState'; -import { hasPsyoptionsAmericanLeg } from '@/plugins/psyoptionsAmericanInstrumentModule'; -import { hasPsyoptionsEuropeanLeg } from '@/plugins/psyoptionsEuropeanInstrumentModule'; /** * This model captures all the relevant information about an RFQ @@ -107,14 +105,9 @@ export const toRfq = async ( const collateralMint = await collateralMintCache.get(convergence); const collateralDecimals = collateralMint.decimals; const { legs } = account.data; - let parsedLegs: LegInstrument[]; - if (hasPsyoptionsAmericanLeg(legs) || hasPsyoptionsEuropeanLeg(legs)) { - parsedLegs = await Promise.all( - legs.map((leg) => convergence.parseLegInstrument(leg)) - ); - } else { - parsedLegs = legs.map((leg) => convergence.parseLegInstrument(leg)); - } + const parsedLegs = await Promise.all( + legs.map((leg) => convergence.parseLegInstrument(leg)) + ); return { model: 'rfq', diff --git a/packages/js/src/plugins/spotInstrumentModule/instruments.ts b/packages/js/src/plugins/spotInstrumentModule/instruments.ts index 96e3a38dd..76b69ba8a 100644 --- a/packages/js/src/plugins/spotInstrumentModule/instruments.ts +++ b/packages/js/src/plugins/spotInstrumentModule/instruments.ts @@ -92,7 +92,10 @@ export class SpotLegInstrument implements LegInstrument { } export const spotLegInstrumentParser = { - parseFromLeg(convergence: Convergence, leg: Leg): SpotLegInstrument { + async parseFromLeg( + convergence: Convergence, + leg: Leg + ): Promise { const { side, instrumentAmount,