func Swap(pair *Pair, payAssetID string, payAmount decimal.Decimal) (*Result, error) {
	m := swap.Imp(pair.SwapMethod)
	payAmount = payAmount.Truncate(8)
	r := &Result{
		PayAssetID: payAssetID,
		PayAmount:  payAmount,
		FeeAssetID: payAssetID,
		FeeAmount:  payAmount.Mul(pair.FeePercent).Truncate(8),
		RouteID:    pair.RouteID,
	}
	funds := payAmount.Sub(r.FeeAmount)
	if !funds.IsPositive() {
		return nil, errors.New("pay amount must be positive")
	}
	switch payAssetID {
	case pair.BaseAssetID:
		r.FillAssetID = pair.QuoteAssetID
		r.FillAmount = m.Swap(pair.BaseAmount, pair.QuoteAmount, funds).Truncate(8)
	case pair.QuoteAssetID:
		r.FillAssetID = pair.BaseAssetID
		r.FillAmount = m.Swap(pair.QuoteAmount, pair.BaseAmount, funds).Truncate(8)
	default:
		return nil, errors.New("invalid pay asset id")
	}
	return r, nil
}
Swap trade in a pair
package fswap
import (
	"errors"
	"github.com/fox-one/4swap-sdk-go/swap"
	"github.com/shopspring/decimal"
)
var (
	ErrInsufficientLiquiditySwapped = errors.New("insufficient liquidity swapped")
)
type Result struct {
	PayAssetID  string
	PayAmount   decimal.Decimal
	FillAssetID string
	FillAmount  decimal.Decimal
	FeeAssetID  string
	FeeAmount   decimal.Decimal
	RouteID     int64
}