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
8 changes: 6 additions & 2 deletions ocp/rpc/transaction/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/code-payments/ocp-server/ocp/antispam"
auth_util "github.com/code-payments/ocp-server/ocp/auth"
"github.com/code-payments/ocp-server/ocp/common"
currency_util "github.com/code-payments/ocp-server/ocp/currency"
ocp_data "github.com/code-payments/ocp-server/ocp/data"
"github.com/code-payments/ocp-server/ocp/data/nonce"
"github.com/code-payments/ocp-server/ocp/transaction"
Expand All @@ -23,7 +24,8 @@ type transactionServer struct {

log *zap.Logger

data ocp_data.Provider
data ocp_data.Provider
mintDataProvider *currency_util.MintDataProvider

auth *auth_util.RPCSignatureVerifier

Expand All @@ -46,6 +48,7 @@ type transactionServer struct {
func NewTransactionServer(
log *zap.Logger,
data ocp_data.Provider,
mintDataProvider *currency_util.MintDataProvider,
submitIntentIntegration SubmitIntentIntegration,
antispamGuard *antispam.Guard,
amlGuard *aml.Guard,
Expand Down Expand Up @@ -86,7 +89,8 @@ func NewTransactionServer(

log: log,

data: data,
data: data,
mintDataProvider: mintDataProvider,

auth: auth_util.NewRPCSignatureVerifier(log, data),

Expand Down
19 changes: 19 additions & 0 deletions ocp/rpc/transaction/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/code-payments/ocp-server/ocp/vm"
"github.com/code-payments/ocp-server/protoutil"
"github.com/code-payments/ocp-server/solana"
"github.com/code-payments/ocp-server/solana/currencycreator"
)

func (s *transactionServer) StatefulSwap(streamer transactionpb.Transaction_StatefulSwapServer) error {
Expand Down Expand Up @@ -233,6 +234,24 @@ func (s *transactionServer) StatefulSwap(streamer transactionpb.Transaction_Stat
return handleStatefulSwapError(streamer, NewSwapDeniedError("mint is being initialized"))
}

if !initializesMint && !common.IsCoreMint(fromMint) {
liveReserveState, err := s.mintDataProvider.GetLiveReserveState(ctx, fromMint)
if err != nil {
log.With(zap.Error(err)).Warn("failure getting live reserve state")
return handleStatefulSwapError(streamer, err)
}

_, estimatedFees := currencycreator.EstimateSell(&currencycreator.EstimateSellArgs{
CurrentSupplyInQuarks: liveReserveState.SupplyFromBonding,
SellAmountInQuarks: initiateReserveSwapReq.Amount,
ValueMintDecimals: uint8(common.CoreMintDecimals),
SellFeeBps: currencyMetadataRecord.SellFeeBps,
})
if estimatedFees == 0 {
return handleStatefulSwapError(streamer, NewSwapDeniedError("swap would not generate a sell fee"))
}
}

var destinationVmAuthority *common.Account
if !initializesMint {
if owner.PublicKey().ToBase58() == swapAuthority.PublicKey().ToBase58() {
Expand Down
Loading