Skip to content

Commit dd2e732

Browse files
v14.0.4 (#30)
1 parent 536713e commit dd2e732

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "sakit"
3-
version = "14.0.3"
3+
version = "14.0.4"
44
description = "Solana Agent Kit"
55
authors = ["Bevan Hunt <bevan@bevanhunt.com>"]
66
license = "MIT"

sakit/privy_trigger.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import base64
99
import logging
10+
import time
1011
from typing import Dict, Any, List, Optional
1112

1213
from solana_agent import AutoTool, ToolRegistry
@@ -401,6 +402,22 @@ async def _create_order(
401402
"message": "Missing required parameters: input_mint, output_mint, making_amount, taking_amount",
402403
}
403404

405+
# Validate expired_at is in the future if provided
406+
if expired_at:
407+
try:
408+
exp_timestamp = int(expired_at)
409+
current_timestamp = int(time.time())
410+
if exp_timestamp <= current_timestamp:
411+
return {
412+
"status": "error",
413+
"message": f"expired_at timestamp ({exp_timestamp}) must be in the future. Current time is {current_timestamp}.",
414+
}
415+
except (ValueError, TypeError):
416+
return {
417+
"status": "error",
418+
"message": f"Invalid expired_at value: {expired_at}. Must be a unix timestamp.",
419+
}
420+
404421
try:
405422
payer_pubkey = None
406423
if self._payer_private_key:

sakit/utils/trigger.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import logging
99
import base64
10+
import time
1011
from typing import Dict, Any, Optional, List
1112
from dataclasses import dataclass, field
1213
import httpx
@@ -115,6 +116,22 @@ async def create_order(
115116
Returns:
116117
TriggerOrderResponse with transaction to sign
117118
"""
119+
# Validate expired_at is in the future if provided
120+
if expired_at:
121+
try:
122+
exp_timestamp = int(expired_at)
123+
current_timestamp = int(time.time())
124+
if exp_timestamp <= current_timestamp:
125+
return TriggerOrderResponse(
126+
success=False,
127+
error=f"expired_at timestamp ({exp_timestamp}) must be in the future. Current time is {current_timestamp}.",
128+
)
129+
except (ValueError, TypeError):
130+
return TriggerOrderResponse(
131+
success=False,
132+
error=f"Invalid expired_at value: {expired_at}. Must be a unix timestamp.",
133+
)
134+
118135
body = {
119136
"inputMint": input_mint,
120137
"outputMint": output_mint,

tests/test_trigger_utils.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ async def test_create_order_with_expiry(self, trigger_client):
8787
"requestId": "req123",
8888
}
8989

90+
# Use a future timestamp (year 2030)
91+
future_timestamp = "1893456000"
92+
9093
with patch("httpx.AsyncClient") as MockClient:
9194
mock_instance = AsyncMock()
9295
mock_response_obj = MagicMock(status_code=200, json=lambda: mock_response)
@@ -101,13 +104,31 @@ async def test_create_order_with_expiry(self, trigger_client):
101104
maker="WalletPubkey123",
102105
making_amount="1000000",
103106
taking_amount="100000",
104-
expired_at="1700000000",
107+
expired_at=future_timestamp,
105108
)
106109

107110
# Verify the call was made with expiredAt in params
108111
call_args = mock_instance.post.call_args
109112
payload = call_args.kwargs.get("json") or call_args[1].get("json")
110-
assert payload.get("params", {}).get("expiredAt") == "1700000000"
113+
assert payload.get("params", {}).get("expiredAt") == future_timestamp
114+
115+
@pytest.mark.asyncio
116+
async def test_create_order_with_past_expiry_fails(self, trigger_client):
117+
"""Should return error when expired_at is in the past."""
118+
# Use a past timestamp (year 2020)
119+
past_timestamp = "1577836800"
120+
121+
result = await trigger_client.create_order(
122+
input_mint="So11111111111111111111111111111111111111112",
123+
output_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
124+
maker="WalletPubkey123",
125+
making_amount="1000000",
126+
taking_amount="100000",
127+
expired_at=past_timestamp,
128+
)
129+
130+
assert result.success is False
131+
assert "must be in the future" in result.error
111132

112133
@pytest.mark.asyncio
113134
async def test_create_order_with_payer(self, trigger_client):

0 commit comments

Comments
 (0)