@@ -28,6 +28,7 @@ import (
2828 "github.com/code-payments/ocp-server/ocp/vm"
2929 "github.com/code-payments/ocp-server/protoutil"
3030 "github.com/code-payments/ocp-server/solana"
31+ "github.com/code-payments/ocp-server/solana/currencycreator"
3132)
3233
3334func (s * transactionServer ) StatefulSwap (streamer transactionpb.Transaction_StatefulSwapServer ) error {
@@ -233,6 +234,24 @@ func (s *transactionServer) StatefulSwap(streamer transactionpb.Transaction_Stat
233234 return handleStatefulSwapError (streamer , NewSwapDeniedError ("mint is being initialized" ))
234235 }
235236
237+ if ! initializesMint && ! common .IsCoreMint (fromMint ) {
238+ liveReserveState , err := s .mintDataProvider .GetLiveReserveState (ctx , fromMint )
239+ if err != nil {
240+ log .With (zap .Error (err )).Warn ("failure getting live reserve state" )
241+ return handleStatefulSwapError (streamer , err )
242+ }
243+
244+ _ , estimatedFees := currencycreator .EstimateSell (& currencycreator.EstimateSellArgs {
245+ CurrentSupplyInQuarks : liveReserveState .SupplyFromBonding ,
246+ SellAmountInQuarks : initiateReserveSwapReq .Amount ,
247+ ValueMintDecimals : uint8 (common .CoreMintDecimals ),
248+ SellFeeBps : currencyMetadataRecord .SellFeeBps ,
249+ })
250+ if estimatedFees == 0 {
251+ return handleStatefulSwapError (streamer , NewSwapDeniedError ("swap would not generate a sell fee" ))
252+ }
253+ }
254+
236255 var destinationVmAuthority * common.Account
237256 if ! initializesMint {
238257 if owner .PublicKey ().ToBase58 () == swapAuthority .PublicKey ().ToBase58 () {
0 commit comments