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
5 changes: 3 additions & 2 deletions ocp/antispam/guard.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"github.com/code-payments/ocp-server/metrics"
"github.com/code-payments/ocp-server/ocp/common"
"github.com/code-payments/ocp-server/ocp/data/swap"
"github.com/code-payments/ocp-server/ocp/integration"
)

type Guard struct {
integration Integration
integration integration.Antispam
}

func NewGuard(integration Integration) *Guard {
func NewGuard(integration integration.Antispam) *Guard {
return &Guard{integration: integration}
}

Expand Down
58 changes: 0 additions & 58 deletions ocp/antispam/integration.go

This file was deleted.

58 changes: 58 additions & 0 deletions ocp/integration/antispam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package integration

import (
"context"

transactionpb "github.com/code-payments/ocp-protobuf-api/generated/go/transaction/v1"

"github.com/code-payments/ocp-server/ocp/common"
"github.com/code-payments/ocp-server/ocp/data/swap"
)

// Antispam is an antispam guard integration that apps can implement to check
// whether operations of interest are allowed to be performed.
type Antispam interface {
AllowOpenAccounts(ctx context.Context, owner *common.Account, accountSet transactionpb.OpenAccountsMetadata_AccountSet) (bool, string, error)

AllowSendPayment(ctx context.Context, owner, destination *common.Account, isPublic bool) (bool, string, error)

AllowReceivePayments(ctx context.Context, owner *common.Account, isPublic bool) (bool, string, error)

AllowDistribution(ctx context.Context, owner *common.Account, isPublic bool) (bool, string, error)

AllowSwap(ctx context.Context, fundingSource swap.FundingSource, owner, fromMint, toMint *common.Account, amount uint64, initializesMint bool) (bool, string, error)

AllowCurrencyLaunch(ctx context.Context, owner *common.Account, name, symbol string) (bool, string, error)
}

type allowEverythingAntispamIntegration struct {
}

// NewAllowEverythingAntispamIntegration returns a default antispam integration that allows everything
func NewAllowEverythingAntispamIntegration() Antispam {
return &allowEverythingAntispamIntegration{}
}

func (i *allowEverythingAntispamIntegration) AllowOpenAccounts(ctx context.Context, owner *common.Account, accountSet transactionpb.OpenAccountsMetadata_AccountSet) (bool, string, error) {
return true, "", nil
}

func (i *allowEverythingAntispamIntegration) AllowSendPayment(ctx context.Context, owner, destination *common.Account, isPublic bool) (bool, string, error) {
return true, "", nil
}

func (i *allowEverythingAntispamIntegration) AllowReceivePayments(ctx context.Context, owner *common.Account, isPublic bool) (bool, string, error) {
return true, "", nil
}

func (i *allowEverythingAntispamIntegration) AllowDistribution(ctx context.Context, owner *common.Account, isPublic bool) (bool, string, error) {
return true, "", nil
}

func (i *allowEverythingAntispamIntegration) AllowSwap(ctx context.Context, fundingSource swap.FundingSource, owner, fromMint, toMint *common.Account, amount uint64, initializesMint bool) (bool, string, error) {
return true, "", nil
}

func (i *allowEverythingAntispamIntegration) AllowCurrencyLaunch(ctx context.Context, owner *common.Account, name, symbol string) (bool, string, error) {
return true, "", nil
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package geyser
package integration

import (
"context"

"github.com/code-payments/ocp-server/ocp/common"
)

// Integration allows for notifications based on events processed by Geyser
type Integration interface {
// Swap is an integration that hooks into the Geyser worker
type Geyser interface {
// OnDepositReceived allows for notifications for external deposits processed by Geyser
OnDepositReceived(ctx context.Context, owner, mint *common.Account, currencyName string, usdMarketValue float64) error
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package transaction
package integration

import (
"context"
Expand All @@ -8,7 +8,8 @@ import (
"github.com/code-payments/ocp-server/ocp/data/intent"
)

type SubmitIntentIntegration interface {
// SubmitIntent is an integration that hooks into SubmitIntent
type SubmitIntent interface {
// AllowCreation determines whether the new intent creation should be allowed
// with app-specific validation rules
AllowCreation(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata, actions []*transactionpb.Action) error
Expand All @@ -22,7 +23,7 @@ type defaultSubmitIntentIntegration struct {
}

// NewDefaultSubmitIntentIntegration retuns a SubmitIntentIntegration that allows everything
func NewDefaultSubmitIntentIntegration() SubmitIntentIntegration {
func NewDefaultSubmitIntentIntegration() SubmitIntent {
return &defaultSubmitIntentIntegration{}
}

Expand Down
7 changes: 4 additions & 3 deletions ocp/worker/swap/integration.go → ocp/integration/swap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package swap
package integration

import (
"context"
Expand All @@ -7,7 +7,8 @@ import (
"github.com/code-payments/ocp-server/ocp/common"
)

// Integration allows for notifications based on events processed by the swap worker
type Integration interface {
// Swap is an integration that hooks into the swap worker
type Swap interface {
// OnSwapFinalized allows for notifications based on events processed by the swap worker
OnSwapFinalized(ctx context.Context, owner *common.Account, isBuy bool, mint *common.Account, currencyName string, region currency.Code, valueReceived float64, isMintInit bool) error
}
5 changes: 3 additions & 2 deletions ocp/rpc/transaction/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
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/integration"
"github.com/code-payments/ocp-server/ocp/transaction"
)

Expand All @@ -29,7 +30,7 @@ type transactionServer struct {

auth *auth_util.RPCSignatureVerifier

submitIntentIntegration SubmitIntentIntegration
submitIntentIntegration integration.SubmitIntent

antispamGuard *antispam.Guard
amlGuard *aml.Guard
Expand All @@ -49,7 +50,7 @@ func NewTransactionServer(
log *zap.Logger,
data ocp_data.Provider,
mintDataProvider *currency_util.MintDataProvider,
submitIntentIntegration SubmitIntentIntegration,
submitIntentIntegration integration.SubmitIntent,
antispamGuard *antispam.Guard,
amlGuard *aml.Guard,
nodeID string,
Expand Down
5 changes: 3 additions & 2 deletions ocp/worker/geyser/external_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/code-payments/ocp-server/ocp/data/intent"
"github.com/code-payments/ocp-server/ocp/data/swap"
"github.com/code-payments/ocp-server/ocp/data/transaction"
"github.com/code-payments/ocp-server/ocp/integration"
transaction_util "github.com/code-payments/ocp-server/ocp/transaction"
vm_util "github.com/code-payments/ocp-server/ocp/vm"
"github.com/code-payments/ocp-server/retry"
Expand All @@ -43,7 +44,7 @@ var (
syncedDepositCache = cache.NewCache(1_000_000)
)

func fixMissingExternalDeposits(ctx context.Context, data ocp_data.Provider, integration Integration, userAuthority, mint *common.Account) error {
func fixMissingExternalDeposits(ctx context.Context, data ocp_data.Provider, integration integration.Geyser, userAuthority, mint *common.Account) error {
err := maybeInitiateExternalDepositIntoVm(ctx, data, userAuthority, mint)
if err != nil {
return errors.Wrap(err, "error depositing into the vm")
Expand Down Expand Up @@ -227,7 +228,7 @@ func findPotentialExternalDepositsIntoVm(ctx context.Context, data ocp_data.Prov
}
}

func processPotentialExternalDepositIntoVm(ctx context.Context, data ocp_data.Provider, integration Integration, signature string, userAuthority, mint *common.Account) error {
func processPotentialExternalDepositIntoVm(ctx context.Context, data ocp_data.Provider, integration integration.Geyser, signature string, userAuthority, mint *common.Account) error {
vmConfig, err := common.GetVmConfigForMint(ctx, data, mint)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions ocp/worker/geyser/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/mr-tron/base58"
"github.com/pkg/errors"

"github.com/code-payments/ocp-server/ocp/integration"
geyserpb "github.com/code-payments/ocp-server/ocp/worker/geyser/api/gen"

"github.com/code-payments/ocp-server/ocp/common"
Expand All @@ -29,10 +30,10 @@ type ProgramAccountUpdateHandler interface {
type TokenProgramAccountHandler struct {
conf *conf
data ocp_data.Provider
integration Integration
integration integration.Geyser
}

func NewTokenProgramAccountHandler(conf *conf, data ocp_data.Provider, integration Integration) ProgramAccountUpdateHandler {
func NewTokenProgramAccountHandler(conf *conf, data ocp_data.Provider, integration integration.Geyser) ProgramAccountUpdateHandler {
return &TokenProgramAccountHandler{
conf: conf,
data: data,
Expand Down Expand Up @@ -120,7 +121,7 @@ func (h *TokenProgramAccountHandler) Handle(ctx context.Context, update *geyserp
return nil
}

func initializeProgramAccountUpdateHandlers(conf *conf, data ocp_data.Provider, integration Integration) map[string]ProgramAccountUpdateHandler {
func initializeProgramAccountUpdateHandlers(conf *conf, data ocp_data.Provider, integration integration.Geyser) map[string]ProgramAccountUpdateHandler {
return map[string]ProgramAccountUpdateHandler{
base58.Encode(token.ProgramKey): NewTokenProgramAccountHandler(conf, data, integration),
}
Expand Down
5 changes: 3 additions & 2 deletions ocp/worker/geyser/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"go.uber.org/zap"

"github.com/code-payments/ocp-server/ocp/integration"
"github.com/code-payments/ocp-server/ocp/worker"
geyserpb "github.com/code-payments/ocp-server/ocp/worker/geyser/api/gen"
timelock_token "github.com/code-payments/ocp-server/solana/timelock/v1"
Expand All @@ -25,7 +26,7 @@ type runtime struct {
data ocp_data.Provider
conf *conf

integration Integration
integration integration.Geyser

programUpdatesChan chan *geyserpb.SubscribeUpdateAccount
programUpdateHandlers map[string]ProgramAccountUpdateHandler
Expand All @@ -45,7 +46,7 @@ type runtime struct {
backupExternalDepositWorkerStatus bool
}

func New(log *zap.Logger, data ocp_data.Provider, integration Integration, configProvider ConfigProvider) worker.Runtime {
func New(log *zap.Logger, data ocp_data.Provider, integration integration.Geyser, configProvider ConfigProvider) worker.Runtime {
conf := configProvider()
return &runtime{
log: log,
Expand Down
5 changes: 3 additions & 2 deletions ocp/worker/swap/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

ocp_data "github.com/code-payments/ocp-server/ocp/data"
"github.com/code-payments/ocp-server/ocp/data/swap"
"github.com/code-payments/ocp-server/ocp/integration"
"github.com/code-payments/ocp-server/ocp/worker"
)

Expand All @@ -19,10 +20,10 @@ type runtime struct {
conf *conf
data ocp_data.Provider
vmIndexerClient indexerpb.IndexerClient
integration Integration
integration integration.Swap
}

func New(log *zap.Logger, data ocp_data.Provider, vmIndexerClient indexerpb.IndexerClient, integration Integration, configProvider ConfigProvider) worker.Runtime {
func New(log *zap.Logger, data ocp_data.Provider, vmIndexerClient indexerpb.IndexerClient, integration integration.Swap, configProvider ConfigProvider) worker.Runtime {
return &runtime{
log: log,
conf: configProvider(),
Expand Down
Loading