Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

Commit 3b09a6b

Browse files
committed
updated-minium-amount
1 parent 774de35 commit 3b09a6b

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

app/services/integrations/webhooks/chainhook/handlers/airdrop_stx_handler.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class AirdropSTXHandler(ChainhookEventHandler):
3232
TARGET_CONTRACT = "SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.send-many"
3333

3434
# Business rule constants for basic transaction validation
35-
MIN_TOTAL_STX = 5_000_000 # 5 STX in microSTX (1 STX = 1,000,000 microSTX)
35+
MIN_AMOUNT_PER_RECIPIENT = (
36+
100_000 # 0.1 STX in microSTX (1 STX = 1,000,000 microSTX)
37+
)
3638
MIN_RECIPIENTS = 5
3739
# Note: Expiry and cooldown validations are now handled at API level during proposal creation
3840

@@ -143,9 +145,10 @@ def _parse_stx_transfer_events(self, events: List[Event]) -> Dict[str, any]:
143145
events: List of events from the transaction
144146
145147
Returns:
146-
Dict containing parsed airdrop data
148+
Dict containing parsed airdrop data with individual recipient amounts
147149
"""
148150
recipients = []
151+
recipient_amounts = {} # Track individual amounts per recipient
149152
total_amount = 0
150153
sender = None
151154

@@ -162,7 +165,13 @@ def _parse_stx_transfer_events(self, events: List[Event]) -> Dict[str, any]:
162165
if recipient:
163166
recipients.append(recipient)
164167
try:
165-
total_amount += int(amount_str)
168+
amount = int(amount_str)
169+
total_amount += amount
170+
# Track individual recipient amounts (handle multiple transfers to same recipient)
171+
if recipient in recipient_amounts:
172+
recipient_amounts[recipient] += amount
173+
else:
174+
recipient_amounts[recipient] = amount
166175
except (ValueError, TypeError):
167176
self.logger.warning(
168177
f"Invalid amount in STX transfer: {amount_str}"
@@ -174,6 +183,7 @@ def _parse_stx_transfer_events(self, events: List[Event]) -> Dict[str, any]:
174183

175184
return {
176185
"recipients": recipients,
186+
"recipient_amounts": recipient_amounts,
177187
"total_amount": str(total_amount),
178188
"token_identifier": "STX", # STX transfers
179189
"sender": sender,
@@ -195,23 +205,30 @@ async def _validate_recipients_against_wallets(
195205
return await validate_wallet_recipients(recipients)
196206

197207
def _validate_minimum_requirements(
198-
self, total_amount: int, recipient_count: int
208+
self, recipient_amounts: Dict[str, int], recipient_count: int
199209
) -> Dict[str, str]:
200-
"""Validate minimum STX amount and recipient count.
210+
"""Validate minimum STX amount per recipient and recipient count.
201211
202212
Args:
203-
total_amount: Total amount to be airdropped in microSTX
213+
recipient_amounts: Dict mapping recipient addresses to amounts in microSTX
204214
recipient_count: Number of recipients
205215
206216
Returns:
207217
Dict with validation errors, empty if all validations pass
208218
"""
209219
errors = {}
210220

211-
if total_amount < self.MIN_TOTAL_STX:
212-
errors["total_amount"] = (
213-
f"Total amount {total_amount / 1_000_000:.6f} STX is below minimum "
214-
f"{self.MIN_TOTAL_STX / 1_000_000:.6f} STX"
221+
# Check minimum amount per recipient
222+
insufficient_recipients = []
223+
for recipient, amount in recipient_amounts.items():
224+
if amount < self.MIN_AMOUNT_PER_RECIPIENT:
225+
insufficient_recipients.append(
226+
f"{recipient}: {amount / 1_000_000:.6f} STX (min: {self.MIN_AMOUNT_PER_RECIPIENT / 1_000_000:.1f} STX)"
227+
)
228+
229+
if insufficient_recipients:
230+
errors["recipient_amounts"] = (
231+
f"Recipients with insufficient amounts: {', '.join(insufficient_recipients)}"
215232
)
216233

217234
if recipient_count < self.MIN_RECIPIENTS:
@@ -266,6 +283,7 @@ async def handle_transaction(self, transaction: TransactionWithReceipt) -> None:
266283
return
267284

268285
recipients = airdrop_data["recipients"]
286+
recipient_amounts = airdrop_data["recipient_amounts"]
269287
total_amount = int(airdrop_data["total_amount"])
270288
sender = airdrop_data["sender"]
271289

@@ -322,7 +340,7 @@ async def handle_transaction(self, transaction: TransactionWithReceipt) -> None:
322340

323341
# Validate minimum requirements
324342
requirement_errors = self._validate_minimum_requirements(
325-
total_amount, len(recipients)
343+
recipient_amounts, len(recipients)
326344
)
327345
if requirement_errors:
328346
self.logger.error(

0 commit comments

Comments
 (0)