Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocp/worker/geyser/external_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

Expand Down
23 changes: 19 additions & 4 deletions ocp/worker/swap/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down