Skip to content
Open
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: 1 addition & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ require (
filippo.io/edwards25519 v1.1.0
github.com/anyproto/go-slip10 v1.0.1
github.com/aws/aws-sdk-go-v2 v1.42.0
github.com/aws/aws-sdk-go-v2/config v1.32.25
github.com/aws/aws-sdk-go-v2/credentials v1.19.24
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.59.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2
github.com/code-payments/code-vm-indexer v1.2.0
github.com/code-payments/ocp-protobuf-api v1.13.2-0.20260610171241-de46af911053
github.com/code-payments/ocp-protobuf-api v1.14.0
github.com/emirpasic/gods v1.12.0
github.com/envoyproxy/protoc-gen-validate v1.3.3
github.com/golang/protobuf v1.5.4
Expand Down Expand Up @@ -47,7 +46,6 @@ require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.11 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.29 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.30 // indirect
Expand All @@ -56,10 +54,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.12.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.29 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.25 // indirect
github.com/aws/aws-sdk-go-v2/service/signin v1.2.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.31.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.36.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.43.3 // indirect
github.com/aws/smithy-go v1.27.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.0 // indirect
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 // indirect
Expand Down
16 changes: 2 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ github.com/aws/aws-sdk-go-v2 v1.42.0 h1:XvXMJTkFQtpBKIWZnmr9ZEOc2InWM2yldjXEJ/by
github.com/aws/aws-sdk-go-v2 v1.42.0/go.mod h1:27+ACypSLljLAEKsCYOmrjKh83vuTRkuAe9Uv/3A4bg=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.11 h1:h5+3VT69KUBK24grGuuA5saDJTj2IIjLb9au668Fo5I=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.11/go.mod h1:dnakxebH6UwFvcvujL0LVggYQ8nEvBGjU4G/V79Nv94=
github.com/aws/aws-sdk-go-v2/config v1.32.25 h1:ACCejvStYoilgwrfegSt5ZntCbPrk52qfwyNcnl3omM=
github.com/aws/aws-sdk-go-v2/config v1.32.25/go.mod h1:LJyU8sDRbXUxFn8xMJIGP+v9QYYwveNLI8a/giAOiAs=
github.com/aws/aws-sdk-go-v2/credentials v1.19.24 h1:2hQqYCV9yqyePQ9o6dCrZc/zO8U3TwPr9mIKlZnPu/I=
github.com/aws/aws-sdk-go-v2/credentials v1.19.24/go.mod h1:IDwpACtwqHLISdzfwUUNq4P9DsB/h5BLg4FwJPNfqFY=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.29 h1:r6qZHbT+wxgWO/e9vYNUEtg7lv5+UN3pRqKhLXvnArg=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.29/go.mod h1:QRnaRcTVGKPGRy8w78HMQtKUGRYcnMZAANATkeVA6Mo=
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25 h1:EeK30mZmhopHcNmKykyGF0LwmFB1ZwQNr+FeyRjcN0U=
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.25/go.mod h1:tudVnwAJyXgCh4N6ABYdzUM+i+PXsx8700FOyhMn+4k=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.29 h1:f3vKqSo13fhTYb+JEcXwXefZQE26I1FB5eTSniU67ko=
Expand All @@ -65,14 +61,6 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.25 h1:2pQEbwf+/6EDb
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.25/go.mod h1:KvT6NCcQ0EZ+ZkVRrlBMt04Po3ok23YELEp7WimhLhM=
github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2 h1:ie4ElCmUKS26pzrZcIk/lmt4yWjAqLLcawstyQCh298=
github.com/aws/aws-sdk-go-v2/service/s3 v1.102.2/go.mod h1:zjsomFeX5duj+4PlMB+o4JoWTIx+G0XMyzjYrUbQkN0=
github.com/aws/aws-sdk-go-v2/service/signin v1.2.0 h1:3nXpRcFwRCW8n7HgO2QGy0Dc20eQNfBuUemGQhpF8m8=
github.com/aws/aws-sdk-go-v2/service/signin v1.2.0/go.mod h1:LxYujSTLPRlp2vTtcUO/+1ilrew8ytt6SvQyOgejzFQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.31.3 h1:ey1XLTYXb9PcLt4535632o5kCGXNXEhNb620Dqwuylo=
github.com/aws/aws-sdk-go-v2/service/sso v1.31.3/go.mod h1:Lk7PlmoTYryQmyBG0EXqj5BcUbj3whXdU2s3yGI3EAc=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.36.6 h1:yLr03zQE/5Eu5l3QU0Si+xMbLMbSDF2YXsigqXngs6g=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.36.6/go.mod h1:Q5N6icH+KJZDLh+ESNwzdv6cZ6vLFF/egy3IOxWhmz4=
github.com/aws/aws-sdk-go-v2/service/sts v1.43.3 h1:VrIhKRCSK1umelSgB9RghvA9RTUYeQffyAS5ApXehNI=
github.com/aws/aws-sdk-go-v2/service/sts v1.43.3/go.mod h1:r8wkDOuLaaMFqFiYAb8dGY2A3gJCOujMc6CFOVC4Zhc=
github.com/aws/smithy-go v1.27.1 h1:4T340VFndXtADGF52gYa1POyL7s9E4Z1OeZ1hCscIw8=
github.com/aws/smithy-go v1.27.1/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand All @@ -92,8 +80,8 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0=
github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8=
github.com/code-payments/ocp-protobuf-api v1.13.2-0.20260610171241-de46af911053 h1:0B96K7/z7TpFbAJeyzP43A0eM58Ie/KRuu5U6PUrses=
github.com/code-payments/ocp-protobuf-api v1.13.2-0.20260610171241-de46af911053/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/code-payments/ocp-protobuf-api v1.14.0 h1:Q0IqyF4q31Mf+wvOILz+BM6P+xOnrPVAm/85/YolKDk=
github.com/code-payments/ocp-protobuf-api v1.14.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
39 changes: 39 additions & 0 deletions ocp/currency/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"math/big"
"time"

"google.golang.org/protobuf/types/known/timestamppb"

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

Expand Down Expand Up @@ -154,6 +157,42 @@ func ValidateClientExchangeData(proto *transactionpb.VerifiedExchangeData) (bool
return validateLaunchpadCurrencyVerifiedExchangeData(proto)
}

// ValidateClientUsdFeeValue validates that a quark amount of a mint is valued
// at the expected USD amount for a fee.
func ValidateClientUsdFeeValue(
mint *common.Account,
quarks uint64,
expectedUsdValue float64,
clientReserveState *currencypb.VerifiedLaunchpadCurrencyReserveState,
) (bool, string) {
// Values are always in USD, and we assume a USD stablecoin for simplicity
if !common.IsCoreMintUsdStableCoin() {
return false, "usd value validation requires a usd stable coin core mint"
}

coreMintFiatExchangeRate := &currencypb.CoreMintFiatExchangeRate{
CurrencyCode: string(currency_lib.USD),
ExchangeRate: 1.0,
Timestamp: timestamppb.Now(),
}

marshalled, err := auth.ForceConsistentMarshal(coreMintFiatExchangeRate)
if err != nil {
return false, "failed to marshal exchange rate"
}

return ValidateClientExchangeData(&transactionpb.VerifiedExchangeData{
Mint: mint.ToProto(),
Quarks: quarks,
NativeAmount: expectedUsdValue,
CoreMintFiatExchangeRate: &currencypb.VerifiedCoreMintFiatExchangeRate{
ExchangeRate: coreMintFiatExchangeRate,
Signature: &commonpb.Signature{Value: ed25519.Sign(common.GetSubsidizer().PrivateKey().ToBytes(), marshalled)},
},
LaunchpadCurrencyReserveState: clientReserveState,
})
}

func validateCoreMintVerifiedExchangeData(proto *transactionpb.VerifiedExchangeData) (bool, string) {
coreMintQuarksPerUnit := common.GetMintQuarksPerUnit(common.CoreMintAccount)

Expand Down
2 changes: 1 addition & 1 deletion ocp/data/currency/metadata/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func testCountMetadataByState(t *testing.T, s metadata.Store) {
currency.MetadataStateUnknown,
currency.MetadataStateAvailable,
currency.MetadataStateWaitingForInitialPurchase,
currency.MetadataStateFundingAuthority,
currency.MetadataStatePrePurchaseSetup,
currency.MetadataStateExecutingInitialPurchase,
currency.MetadataStateCompletingInitialization,
currency.MetadataStateFinalValidation,
Expand Down
6 changes: 3 additions & 3 deletions ocp/data/currency/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
MetadataStateUnknown MetadataState = iota
MetadataStateAvailable
MetadataStateWaitingForInitialPurchase
MetadataStateFundingAuthority
MetadataStatePrePurchaseSetup
MetadataStateExecutingInitialPurchase
MetadataStateCompletingInitialization
MetadataStateFinalValidation
Expand Down Expand Up @@ -344,8 +344,8 @@ func (s MetadataState) String() string {
return "available"
case MetadataStateWaitingForInitialPurchase:
return "waiting_for_initial_purchase"
case MetadataStateFundingAuthority:
return "funding_authority"
case MetadataStatePrePurchaseSetup:
return "pre_purchase_setup"
case MetadataStateExecutingInitialPurchase:
return "executing_initial_purchase"
case MetadataStateCompletingInitialization:
Expand Down
2 changes: 1 addition & 1 deletion ocp/integration/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type Swap interface {
OnSwapSubmitted(ctx context.Context, owner *common.Account, fromMint, toMint *common.Account) error

// 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
OnSwapFinalized(ctx context.Context, owner *common.Account, isBuy bool, mint *common.Account, currencyName string, region currency.Code, valueReceived float64) error
}
40 changes: 32 additions & 8 deletions ocp/rpc/transaction/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/code-payments/ocp-server/config/env"
"github.com/code-payments/ocp-server/config/memory"
"github.com/code-payments/ocp-server/config/wrapper"
"github.com/code-payments/ocp-server/ocp/common"
)

const (
Expand All @@ -30,8 +31,21 @@ const (
FeeCollectorOwnerPublicKeyConfigEnvName = envConfigPrefix + "FEE_COLLECTOR_OWNER_PUBLIC_KEY"
defaultFeeCollectorPublicKey = "invalid" // Ensure something valid is set

CreateOnSendWithdrawalUsdFeeConfigEnvName = envConfigPrefix + "CREATE_ON_SEND_WITHDRAWAL_USD_FEE"
defaultCreateOnSendWithdrawalUsdFee = 0.50
CreateOnSendWithdrawalFeeQuarksConfigEnvName = envConfigPrefix + "CREATE_ON_SEND_WITHDRAWAL_FEE_QUARKS"

SwapTreasuryOwnerPublicKeyConfigEnvName = envConfigPrefix + "SWAP_TREASURY_OWNER_PUBLIC_KEY"
defaultSwapTreasuryOwnerPublicKey = "invalid" // Ensure something valid is set

NewCurrencyPurchaseQuarksConfigEnvName = envConfigPrefix + "NEW_CURRENCY_PURCHASE_QUARKS"

NewCurrencyFeeQuarksConfigEnvName = envConfigPrefix + "NEW_CURRENCY_FEE_QUARKS"
)

// Assumes a USD stable coin core mint
var (
defaultCreateOnSendWithdrawalFeeQuarks = common.CoreMintQuarksPerUnit / 2 // $0.50
defaultNewCurrencyPurchaseQuarks = 10 * common.CoreMintQuarksPerUnit
defaultNewCurrencyFeeQuarks = 10 * common.CoreMintQuarksPerUnit
)

type conf struct {
Expand All @@ -43,8 +57,11 @@ type conf struct {
submitIntentTimeout config.Duration
swapTimeout config.Duration
clientReceiveTimeout config.Duration
feeCollectorOwnerPublicKey config.String
createOnSendWithdrawalUsdFee config.Float64
feeCollectorOwnerPublicKey config.String
createOnSendWithdrawalFeeQuarks config.Uint64
swapTreasuryOwnerPublicKey config.String
newCurrencyPurchaseQuarks config.Uint64
newCurrencyFeeQuarks config.Uint64
}

// ConfigProvider defines how config values are pulled
Expand All @@ -62,8 +79,11 @@ func WithEnvConfigs() ConfigProvider {
submitIntentTimeout: env.NewDurationConfig(SubmitIntentTimeoutConfigEnvName, defaultSubmitIntentTimeout),
swapTimeout: env.NewDurationConfig(SwapTimeoutConfigEnvName, defaultSwapTimeout),
clientReceiveTimeout: env.NewDurationConfig(ClientReceiveTimeoutConfigEnvName, defaultClientReceiveTimeout),
feeCollectorOwnerPublicKey: env.NewStringConfig(FeeCollectorOwnerPublicKeyConfigEnvName, defaultFeeCollectorPublicKey),
createOnSendWithdrawalUsdFee: env.NewFloat64Config(CreateOnSendWithdrawalUsdFeeConfigEnvName, defaultCreateOnSendWithdrawalUsdFee),
feeCollectorOwnerPublicKey: env.NewStringConfig(FeeCollectorOwnerPublicKeyConfigEnvName, defaultFeeCollectorPublicKey),
createOnSendWithdrawalFeeQuarks: env.NewUint64Config(CreateOnSendWithdrawalFeeQuarksConfigEnvName, defaultCreateOnSendWithdrawalFeeQuarks),
swapTreasuryOwnerPublicKey: env.NewStringConfig(SwapTreasuryOwnerPublicKeyConfigEnvName, defaultSwapTreasuryOwnerPublicKey),
newCurrencyPurchaseQuarks: env.NewUint64Config(NewCurrencyPurchaseQuarksConfigEnvName, defaultNewCurrencyPurchaseQuarks),
newCurrencyFeeQuarks: env.NewUint64Config(NewCurrencyFeeQuarksConfigEnvName, defaultNewCurrencyFeeQuarks),
}
}
}
Expand All @@ -74,6 +94,7 @@ type testOverrides struct {
enableAmlChecks bool
clientReceiveTimeout time.Duration
feeCollectorOwnerPublicKey string
swapTreasuryOwnerPublicKey string
}

func withManualTestOverrides(overrides *testOverrides) ConfigProvider {
Expand All @@ -86,8 +107,11 @@ func withManualTestOverrides(overrides *testOverrides) ConfigProvider {
submitIntentTimeout: wrapper.NewDurationConfig(memory.NewConfig(defaultSubmitIntentTimeout), defaultSubmitIntentTimeout),
swapTimeout: wrapper.NewDurationConfig(memory.NewConfig(defaultSwapTimeout), defaultSwapTimeout),
clientReceiveTimeout: wrapper.NewDurationConfig(memory.NewConfig(overrides.clientReceiveTimeout), defaultClientReceiveTimeout),
feeCollectorOwnerPublicKey: wrapper.NewStringConfig(memory.NewConfig(overrides.feeCollectorOwnerPublicKey), defaultFeeCollectorPublicKey),
createOnSendWithdrawalUsdFee: wrapper.NewFloat64Config(memory.NewConfig(defaultCreateOnSendWithdrawalUsdFee), defaultCreateOnSendWithdrawalUsdFee),
feeCollectorOwnerPublicKey: wrapper.NewStringConfig(memory.NewConfig(overrides.feeCollectorOwnerPublicKey), defaultFeeCollectorPublicKey),
createOnSendWithdrawalFeeQuarks: wrapper.NewUint64Config(memory.NewConfig(defaultCreateOnSendWithdrawalFeeQuarks), defaultCreateOnSendWithdrawalFeeQuarks),
swapTreasuryOwnerPublicKey: wrapper.NewStringConfig(memory.NewConfig(overrides.swapTreasuryOwnerPublicKey), defaultSwapTreasuryOwnerPublicKey),
newCurrencyPurchaseQuarks: wrapper.NewUint64Config(memory.NewConfig(defaultNewCurrencyPurchaseQuarks), defaultNewCurrencyPurchaseQuarks),
newCurrencyFeeQuarks: wrapper.NewUint64Config(memory.NewConfig(defaultNewCurrencyFeeQuarks), defaultNewCurrencyFeeQuarks),
}
}
}
39 changes: 33 additions & 6 deletions ocp/rpc/transaction/intent_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
ocp_data "github.com/code-payments/ocp-server/ocp/data"
"github.com/code-payments/ocp-server/ocp/data/account"
"github.com/code-payments/ocp-server/ocp/data/action"
"github.com/code-payments/ocp-server/ocp/data/currency"
"github.com/code-payments/ocp-server/ocp/data/fulfillment"
"github.com/code-payments/ocp-server/ocp/data/intent"
"github.com/code-payments/ocp-server/ocp/data/swap"
Expand Down Expand Up @@ -250,7 +251,7 @@ func (h *OpenAccountsIntentHandler) AllowCreation(ctx context.Context, intentRec
// Part 5: Validate reserved intent IDs
//

_, err = validateSwapFunding(ctx, h.data, intentRecord)
_, err = validateSwapFunding(ctx, h.conf, h.data, intentRecord)
return err
}

Expand Down Expand Up @@ -670,7 +671,7 @@ func (h *SendPublicPaymentIntentHandler) AllowCreation(ctx context.Context, inte
// Part 7: Validate reserved intent IDs
//

h.cachedSwapRecord, err = validateSwapFunding(ctx, h.data, intentRecord)
h.cachedSwapRecord, err = validateSwapFunding(ctx, h.conf, h.data, intentRecord)
if err != nil {
return err
}
Expand Down Expand Up @@ -1218,7 +1219,7 @@ func (h *ReceivePaymentsPubliclyIntentHandler) AllowCreation(ctx context.Context
// Part 7: Validate reserved intent IDs
//

_, err = validateSwapFunding(ctx, h.data, intentRecord)
_, err = validateSwapFunding(ctx, h.conf, h.data, intentRecord)
if err != nil {
return err
}
Expand Down Expand Up @@ -1538,7 +1539,7 @@ func (h *PublicDistributionIntentHandler) AllowCreation(ctx context.Context, int
// Part 5: Validate reserved intent IDs
//

_, err = validateSwapFunding(ctx, h.data, intentRecord)
_, err = validateSwapFunding(ctx, h.conf, h.data, intentRecord)
if err != nil {
return err
}
Expand Down Expand Up @@ -2086,7 +2087,7 @@ func validateFeePayments(
var expectedUsdValue float64
switch expectedFeeType {
case transactionpb.FeePaymentAction_CREATE_ON_SEND_WITHDRAWAL:
expectedUsdValue = conf.createOnSendWithdrawalUsdFee.Get(ctx)
expectedUsdValue = float64(conf.createOnSendWithdrawalFeeQuarks.Get(ctx)) / float64(common.CoreMintQuarksPerUnit)
default:
return errors.New("unhandled fee type")
}
Expand Down Expand Up @@ -2257,7 +2258,7 @@ func validateDistributedPool(ctx context.Context, data ocp_data.Provider, poolVa
return nil
}

func validateSwapFunding(ctx context.Context, data ocp_data.Provider, intentRecord *intent.Record) (*swap.Record, error) {
func validateSwapFunding(ctx context.Context, conf *conf, data ocp_data.Provider, intentRecord *intent.Record) (*swap.Record, error) {
swapRecord, err := data.GetSwapByFundingId(ctx, intentRecord.IntentId)
if err != nil && err != swap.ErrNotFound {
return nil, err
Expand Down Expand Up @@ -2293,6 +2294,32 @@ func validateSwapFunding(ctx context.Context, data ocp_data.Provider, intentReco
if intentRecord.SendPublicPaymentMetadata.Quantity != swapRecord.SwapAmount+swapRecord.FeeAmount {
return nil, NewIntentValidationErrorf("must fund swap with %d quarks", swapRecord.SwapAmount+swapRecord.FeeAmount)
}

fromMintAccount, err := common.NewAccountFromPublicKeyString(swapRecord.FromMint)
if err != nil {
return nil, err
}
toMintAccount, err := common.NewAccountFromPublicKeyString(swapRecord.ToMint)
if err != nil {
return nil, err
}
if !common.IsCoreMint(fromMintAccount) && !common.IsCoreMint(toMintAccount) {
destinationCurrencyMetadataRecord, err := data.GetCurrencyMetadata(ctx, swapRecord.ToMint)
if err != nil {
return nil, err
}

initializesMint := destinationCurrencyMetadataRecord.State != currency.MetadataStateAvailable
if initializesMint {
expectedUsdValue := float64(conf.newCurrencyPurchaseQuarks.Get(ctx)+conf.newCurrencyFeeQuarks.Get(ctx)) / float64(common.CoreMintQuarksPerUnit)
if intentRecord.SendPublicPaymentMetadata.ExchangeCurrency != currency_lib.USD {
return nil, NewIntentValidationError("swap funding must be valued in usd")
}
if intentRecord.SendPublicPaymentMetadata.NativeAmount != expectedUsdValue {
return nil, NewIntentValidationErrorf("swap funding must be valued at %.2f usd", expectedUsdValue)
}
}
}
}
if !isIntentReservedForSwap && intentRecord.IntentType != intent.SendPublicPayment {
return nil, nil
Expand Down
10 changes: 10 additions & 0 deletions ocp/rpc/transaction/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type transactionServer struct {
localAccountLocks map[string]*sync.Mutex

feeCollector *common.Account
swapTreasury *common.Account

transactionpb.UnimplementedTransactionServer
}
Expand Down Expand Up @@ -127,5 +128,14 @@ func NewTransactionServer(
return nil, err
}

swapTreasuryVaultRecord, err := data.GetKey(ctx, s.conf.swapTreasuryOwnerPublicKey.Get(ctx))
if err != nil {
return nil, err
}
s.swapTreasury, err = common.NewAccountFromPrivateKeyString(swapTreasuryVaultRecord.PrivateKey)
if err != nil {
return nil, err
}

return s, nil
}
Loading
Loading