Skip to content
Merged
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
41 changes: 23 additions & 18 deletions ocp/rpc/transaction/intent_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ func (h *SendPublicPaymentIntentHandler) validateActions(

// Ensure the destination is the intent mint ATA for the client-provided owner,
// if provided. We'll check later if this is absolutely required.
var isVmSwapPda bool
var isDestinationOwnerVmSwapPda bool
if metadata.DestinationOwner != nil {
destinationOwner, err := common.NewAccountFromProto(metadata.DestinationOwner)
if err != nil {
Expand All @@ -797,7 +797,7 @@ func (h *SendPublicPaymentIntentHandler) validateActions(

_, err = h.data.GetTimelockBySwapPda(ctx, destinationOwner.PublicKey().ToBase58())
if err == nil {
isVmSwapPda = true
isDestinationOwnerVmSwapPda = true
} else if err != timelock.ErrTimelockNotFound {
return err
}
Expand All @@ -810,22 +810,27 @@ func (h *SendPublicPaymentIntentHandler) validateActions(
}

// Check whether the destination account is a token account of the same mint that's
// been created on the blockchain. If not, a fee is likely required
err = validateExternalTokenAccountWithinIntent(ctx, h.data, destination, intentMint)
switch err {
case nil:
default:
if !strings.Contains(strings.ToLower(err.Error()), "doesn't exist on the blockchain") {
return err
}

if metadata.DestinationOwner == nil {
return NewIntentValidationError("destination owner account is required to derive ata")
}

// Only VM swap PDAs are subsidized by server
if !simResult.HasAnyFeePayments() && !isVmSwapPda {
return NewIntentValidationErrorf("%s fee payment is required", transactionpb.FeePaymentAction_CREATE_ON_SEND_WITHDRAWAL.String())
// been created on the blockchain. If not, a fee is likely required.
//
// Note: We can skip these checks for VM swap ATAs because the account is already
// validated, and no fee payment is required.
if !isDestinationOwnerVmSwapPda {
err = validateExternalTokenAccountWithinIntent(ctx, h.data, destination, intentMint)
switch err {
case nil:
default:
if !strings.Contains(strings.ToLower(err.Error()), "doesn't exist on the blockchain") {
return err
}

if metadata.DestinationOwner == nil {
return NewIntentValidationError("destination owner account is required to derive ata")
}

// Only VM swap ATAs are subsidized by server
if !simResult.HasAnyFeePayments() && !isDestinationOwnerVmSwapPda {
return NewIntentValidationErrorf("%s fee payment is required", transactionpb.FeePaymentAction_CREATE_ON_SEND_WITHDRAWAL.String())
}
}
}

Expand Down
Loading