diff --git a/ocp/worker/swap/integration.go b/ocp/worker/swap/integration.go index cdbe800..2b1a6b9 100644 --- a/ocp/worker/swap/integration.go +++ b/ocp/worker/swap/integration.go @@ -9,5 +9,5 @@ import ( // Integration allows for notifications based on events processed by the swap worker type Integration interface { - OnSwapFinalized(ctx context.Context, owner, fromMint, toMint *common.Account, currencyName string, region currency.Code, valueReceived float64) error + OnSwapFinalized(ctx context.Context, owner *common.Account, isBuy bool, currencyName string, region currency.Code, valueReceived float64) error } diff --git a/ocp/worker/swap/util.go b/ocp/worker/swap/util.go index 1be047f..82c85de 100644 --- a/ocp/worker/swap/util.go +++ b/ocp/worker/swap/util.go @@ -228,13 +228,16 @@ func (p *runtime) notifySwapFinalized(ctx context.Context, swapRecord *swap.Reco return err } - currencyName := common.CoreMintName - if !common.IsCoreMint(toMint) { - currencyMetadataRecord, err := p.data.GetCurrencyMetadata(ctx, toMint.PublicKey().ToBase58()) - if err != nil { - return nil - } - currencyName = currencyMetadataRecord.Name + isBuy := !common.IsCoreMint(toMint) + + targetMint := toMint + if !isBuy { + targetMint = fromMint + } + + targetCurrencyMetadataRecord, err := p.data.GetCurrencyMetadata(ctx, targetMint.PublicKey().ToBase58()) + if err != nil { + return nil } fundingIntentRecord, err := p.data.GetIntent(ctx, swapRecord.FundingId) @@ -243,10 +246,11 @@ func (p *runtime) notifySwapFinalized(ctx context.Context, swapRecord *swap.Reco } valueReceived := fundingIntentRecord.SendPublicPaymentMetadata.NativeAmount - if !common.IsCoreMint(fromMint) { + if !isBuy { valueReceived = 0.99 * valueReceived } - return p.integration.OnSwapFinalized(ctx, owner, fromMint, toMint, currencyName, fundingIntentRecord.SendPublicPaymentMetadata.ExchangeCurrency, valueReceived) + + return p.integration.OnSwapFinalized(ctx, owner, isBuy, targetCurrencyMetadataRecord.Name, fundingIntentRecord.SendPublicPaymentMetadata.ExchangeCurrency, valueReceived) } func (p *runtime) markNonceReleasedDueToSubmittedTransaction(ctx context.Context, record *swap.Record) error {