Skip to content

Commit 5078a07

Browse files
author
Jeff Yanta
committed
AML guard should limit AllowMoneyMovement by per-transaction send limits
1 parent 637b145 commit 5078a07

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

pkg/code/aml/guard.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ var (
1919
// so we can do better rounding on limits per currency.
2020
//
2121
// todo: configurable
22-
maxUsdTransactionValue = 2.0 * limit.SendLimits[currency_util.USD].PerTransaction
23-
maxDailyUsdLimit = 1.5 * limit.SendLimits[currency_util.USD].Daily
22+
maxDailyUsdLimit = 1.2 * limit.SendLimits[currency_util.USD].Daily
2423
)
2524

2625
// Guard gates money movement by applying rules on operations of interest to
@@ -43,11 +42,15 @@ func (g *Guard) AllowMoneyMovement(ctx context.Context, intentRecord *intent.Rec
4342
tracer := metrics.TraceMethodCall(ctx, metricsStructName, "AllowMoneyMovement")
4443
defer tracer.End()
4544

45+
var currency currency_util.Code
46+
var nativeAmount float64
4647
var usdMarketValue float64
4748
var consumptionCalculator func(ctx context.Context, owner string, since time.Time) (uint64, float64, error)
4849
switch intentRecord.IntentType {
4950
case intent.SendPublicPayment:
50-
// Public sends are subject to USD-based limits
51+
// Public sends are subject to limits
52+
currency = intentRecord.SendPublicPaymentMetadata.ExchangeCurrency
53+
nativeAmount = intentRecord.SendPublicPaymentMetadata.NativeAmount
5154
usdMarketValue = intentRecord.SendPublicPaymentMetadata.UsdMarketValue
5255
consumptionCalculator = g.data.GetTransactedAmountForAntiMoneyLaundering
5356
case intent.ReceivePaymentsPublicly:
@@ -60,15 +63,23 @@ func (g *Guard) AllowMoneyMovement(ctx context.Context, intentRecord *intent.Rec
6063
}
6164

6265
log := g.log.WithFields(logrus.Fields{
63-
"method": "AllowMoneyMovement",
64-
"owner": intentRecord.InitiatorOwnerAccount,
65-
"usd_value": usdMarketValue,
66+
"method": "AllowMoneyMovement",
67+
"owner": intentRecord.InitiatorOwnerAccount,
68+
"currency": string(currency),
69+
"native_amount": nativeAmount,
70+
"usd_value": usdMarketValue,
6671
})
6772

68-
// Bound the maximum dollar value of a payment
69-
if usdMarketValue > maxUsdTransactionValue {
70-
log.Info("denying intent that exceeds per-transaction usd value")
71-
recordDenialEvent(ctx, "exceeds per-transaction usd value")
73+
sendLimit, ok := limit.SendLimits[currency]
74+
if !ok {
75+
log.Info("denying intent with unsupported currency")
76+
recordDenialEvent(ctx, "unsupported currency")
77+
return false, nil
78+
}
79+
80+
if nativeAmount > sendLimit.PerTransaction {
81+
log.Info("denying intent that exceeds per-transaction value")
82+
recordDenialEvent(ctx, "exceeds per-transaction value")
7283
return false, nil
7384
}
7485

pkg/code/aml/guard_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ import (
1212
code_data "github.com/code-payments/code-server/pkg/code/data"
1313
"github.com/code-payments/code-server/pkg/code/data/currency"
1414
"github.com/code-payments/code-server/pkg/code/data/intent"
15+
"github.com/code-payments/code-server/pkg/code/limit"
1516
currency_lib "github.com/code-payments/code-server/pkg/currency"
1617
"github.com/code-payments/code-server/pkg/testutil"
1718
)
1819

19-
func TestGuard_SendPublicPayment_TransactionValue(t *testing.T) {
20+
func TestGuard_SendPublicPayment_PerTransactionValue(t *testing.T) {
2021
env := setupAmlTest(t)
2122

2223
owner := testutil.NewRandomAccount(t)
2324

2425
for _, acceptableValue := range []float64{
2526
1,
26-
maxUsdTransactionValue / 10,
27-
maxUsdTransactionValue - 1,
28-
maxUsdTransactionValue,
27+
limit.SendLimits[currency_lib.USD].PerTransaction / 10,
28+
limit.SendLimits[currency_lib.USD].PerTransaction - 1,
29+
limit.SendLimits[currency_lib.USD].PerTransaction,
2930
} {
3031
intentRecord := makeSendPublicPaymentIntent(t, owner, acceptableValue, time.Now())
3132

@@ -35,8 +36,8 @@ func TestGuard_SendPublicPayment_TransactionValue(t *testing.T) {
3536
}
3637

3738
for _, unacceptableValue := range []float64{
38-
maxUsdTransactionValue + 1,
39-
maxUsdTransactionValue * 10,
39+
limit.SendLimits[currency_lib.USD].PerTransaction + 1,
40+
limit.SendLimits[currency_lib.USD].PerTransaction * 10,
4041
} {
4142
intentRecord := makeSendPublicPaymentIntent(t, owner, unacceptableValue, time.Now())
4243

0 commit comments

Comments
 (0)