From 3c7a538a53e81994ed498931c5e7a0f74d264754 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Mon, 26 Jan 2026 14:16:17 -0500 Subject: [PATCH] Use finalized blockchain state for USD market value on sell from intent funding --- ocp/worker/geyser/external_deposit.go | 2 +- ocp/worker/swap/util.go | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ocp/worker/geyser/external_deposit.go b/ocp/worker/geyser/external_deposit.go index 25a61ed..caee4ed 100644 --- a/ocp/worker/geyser/external_deposit.go +++ b/ocp/worker/geyser/external_deposit.go @@ -333,8 +333,8 @@ func processPotentialExternalDepositIntoVm(ctx context.Context, data ocp_data.Pr DestinationTokenAccount: userVirtualTimelockVaultAccount.PublicKey().ToBase58(), Quantity: uint64(deltaQuarksIntoOmnibus), ExchangeCurrency: currency_lib.USD, - NativeAmount: usdMarketValue, ExchangeRate: currency_util.CalculateExchangeRate(mint, uint64(deltaQuarksIntoOmnibus), usdMarketValue), + NativeAmount: usdMarketValue, UsdMarketValue: usdMarketValue, }, diff --git a/ocp/worker/swap/util.go b/ocp/worker/swap/util.go index 83afe78..a117427 100644 --- a/ocp/worker/swap/util.go +++ b/ocp/worker/swap/util.go @@ -148,6 +148,13 @@ func (p *runtime) updateBalancesForFinalizedSwap(ctx context.Context, swapRecord return 0, err } + if !common.IsCoreMintUsdStableCoin() { + return 0, errors.New("core mint is not a usd stable coin") + } + if !common.IsCoreMint(fromMint) && !common.IsCoreMint(toMint) { + return 0, errors.New("core mint must be involved in swap") + } + destinationVmConfig, err := common.GetVmConfigForMint(ctx, p.data, toMint) if err != nil { return 0, err @@ -188,15 +195,23 @@ func (p *runtime) updateBalancesForFinalizedSwap(ctx context.Context, swapRecord exchangeCurrency = fundingIntentRecord.SendPublicPaymentMetadata.ExchangeCurrency nativeAmountWithoutFees = fundingIntentRecord.SendPublicPaymentMetadata.NativeAmount usdMarketValueWithoutFees = fundingIntentRecord.SendPublicPaymentMetadata.UsdMarketValue + + if common.IsCoreMint(toMint) { + usdMarketValue, err := currency_util.CalculateUsdMarketValueFromTokenAmount(ctx, p.data, common.CoreMintAccount, uint64(deltaQuarksIntoOmnibus), time.Now()) + if err != nil { + return 0, err + } + + usdMarketValueWithoutFees, _ = new(big.Float).Quo( + big.NewFloat(usdMarketValue).SetPrec(128), + big.NewFloat(0.99).SetPrec(128), + ).Float64() + } case swap.FundingSourceExternalWallet: if !common.IsCoreMint(fromMint) { return 0, errors.New("unexpected source mint") } - if !common.IsCoreMintUsdStableCoin() { - return 0, errors.New("core mint is not a usd stable coin") - } - exchangeCurrency = currency_lib.USD usdMarketValueWithoutFees, err = currency_util.CalculateUsdMarketValueFromTokenAmount(ctx, p.data, common.CoreMintAccount, swapRecord.Amount, time.Now()) if err != nil {