Skip to content

Commit 700ee77

Browse files
committed
Re-implement GetLimits
1 parent 3ae73a2 commit 700ee77

File tree

7 files changed

+25
-851
lines changed

7 files changed

+25
-851
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.0
55
require (
66
github.com/aws/aws-sdk-go-v2 v0.17.0
77
github.com/bits-and-blooms/bloom/v3 v3.1.0
8-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250402192552-177b85d5508d
8+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250409171630-fb01c98ecd86
99
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba
1010
github.com/emirpasic/gods v1.12.0
1111
github.com/envoyproxy/protoc-gen-validate v1.2.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht
7878
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
7979
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
8080
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
81-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250402192552-177b85d5508d h1:p0XvGezrScoG4CLGWbV702qK8MOwNSOPxfumVJ/kqBc=
82-
github.com/code-payments/code-protobuf-api v1.19.1-0.20250402192552-177b85d5508d/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
81+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250409171630-fb01c98ecd86 h1:Lv+DODC5j/zvzx+CfL8tlpw0GCHXpEwW/ICPXze3jTY=
82+
github.com/code-payments/code-protobuf-api v1.19.1-0.20250409171630-fb01c98ecd86/go.mod h1:ee6TzKbgMS42ZJgaFEMG3c4R3dGOiffHSu6MrY7WQvs=
8383
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba h1:Bkp+gmeb6Y2PWXfkSCTMBGWkb2P1BujRDSjWeI+0j5I=
8484
github.com/code-payments/code-vm-indexer v0.1.11-0.20241028132209-23031e814fba/go.mod h1:jSiifpiBpyBQ8q2R0MGEbkSgWC6sbdRTyDBntmW+j1E=
8585
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=

pkg/code/lawenforcement/anti_money_laundering.go

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ import (
1010
"github.com/code-payments/code-server/pkg/metrics"
1111
)
1212

13-
const (
14-
// These limits are intentionally higher than that enforced on clients,
15-
// so we can do better rounding on limits per currency.
16-
//
17-
// todo: configurable
18-
maxUsdPrivateBalance = 500.00 // 2x the 250 USD limit
19-
maxUsdTransactionValue = 500.00 // 2x the 250 USD limit
20-
maxDailyUsdLimit = 1500.00 // 1.5x the 1000 USD limit
21-
)
22-
2313
// AntiMoneyLaunderingGuard gates money movement by applying rules on operations
2414
// of interest to discourage money laundering through Code.
2515
type AntiMoneyLaunderingGuard struct {
@@ -40,97 +30,6 @@ func (g *AntiMoneyLaunderingGuard) AllowMoneyMovement(ctx context.Context, inten
4030
tracer := metrics.TraceMethodCall(ctx, metricsStructName, "AllowMoneyMovement")
4131
defer tracer.End()
4232

43-
/*
44-
var usdMarketValue float64
45-
var consumptionCalculator func(ctx context.Context, phoneNumber string, since time.Time) (uint64, float64, error)
46-
switch intentRecord.IntentType {
47-
case intent.SendPublicPayment, intent.ReceivePaymentsPublicly:
48-
// Public movements of money are not subject to AML rules. They are
49-
// done in the open.
50-
return true, nil
51-
case intent.SendPrivatePayment:
52-
usdMarketValue = intentRecord.SendPrivatePaymentMetadata.UsdMarketValue
53-
consumptionCalculator = g.data.GetTransactedAmountForAntiMoneyLaundering
54-
case intent.ReceivePaymentsPrivately:
55-
// Allow users to always receive in-app payments from their temporary incoming
56-
// accounts. The payment was already allowed when initiatied on the send side.
57-
if !intentRecord.ReceivePaymentsPrivatelyMetadata.IsDeposit {
58-
return true, nil
59-
}
60-
61-
owner, err := common.NewAccountFromPublicKeyString(intentRecord.InitiatorOwnerAccount)
62-
if err != nil {
63-
tracer.OnError(err)
64-
return false, err
65-
}
66-
67-
totalPrivateBalance, err := balance.GetPrivateBalance(ctx, g.data, owner)
68-
if err != nil {
69-
tracer.OnError(err)
70-
return false, err
71-
}
72-
73-
usdExchangeRecord, err := g.data.GetExchangeRate(ctx, currency_lib.USD, time.Now())
74-
if err != nil {
75-
tracer.OnError(err)
76-
return false, err
77-
}
78-
79-
// Do they need the deposit based on total private balance? Note: clients
80-
// always try to deposit the max as a mechanism of hiding in the crowd, so
81-
// we can only consider the current balance and whether it makes sense.
82-
if usdExchangeRecord.Rate*float64(kin.FromQuarks(totalPrivateBalance)) >= maxUsdPrivateBalance {
83-
recordDenialEvent(ctx, "private balance exceeds threshold")
84-
return false, nil
85-
}
86-
87-
// Otherwise, limit deposits in line with expectations for payments.
88-
usdMarketValue = intentRecord.ReceivePaymentsPrivatelyMetadata.UsdMarketValue
89-
consumptionCalculator = g.data.GetDepositedAmountForAntiMoneyLaundering
90-
default:
91-
err := errors.New("intent record must be a send or receive payment")
92-
tracer.OnError(err)
93-
return false, err
94-
}
95-
96-
if intentRecord.InitiatorPhoneNumber == nil {
97-
err := errors.New("anti-money laundering guard requires an identity")
98-
tracer.OnError(err)
99-
return false, err
100-
}
101-
102-
log := g.log.WithFields(logrus.Fields{
103-
"method": "AllowMoneyMovement",
104-
"owner": intentRecord.InitiatorOwnerAccount,
105-
"phone_number": *intentRecord.InitiatorPhoneNumber,
106-
"usd_value": usdMarketValue,
107-
})
108-
109-
phoneNumber := *intentRecord.InitiatorPhoneNumber
110-
111-
// Bound the maximum dollar value of a payment
112-
if usdMarketValue > maxUsdTransactionValue {
113-
log.Info("denying intent that exceeds per-transaction usd value")
114-
recordDenialEvent(ctx, "exceeds per-transaction usd value")
115-
return false, nil
116-
}
117-
118-
// Bound the maximum dollar value of payments in the last day
119-
_, usdInLastDay, err := consumptionCalculator(ctx, phoneNumber, time.Now().Add(-24*time.Hour))
120-
if err != nil {
121-
log.WithError(err).Warn("failure calculating previous day transaction amount")
122-
tracer.OnError(err)
123-
return false, err
124-
}
125-
126-
if usdInLastDay+usdMarketValue > maxDailyUsdLimit {
127-
log.Info("denying intent that exceeds daily usd limit")
128-
recordDenialEvent(ctx, "exceeds daily usd value")
129-
return false, nil
130-
}
131-
132-
return true, nil
133-
*/
134-
33+
// All movements of money are public, so no limits apply
13534
return true, nil
13635
}

0 commit comments

Comments
 (0)