rosud 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rosud-0.1.0/.gitignore +42 -0
- rosud-0.1.0/PKG-INFO +104 -0
- rosud-0.1.0/README.md +70 -0
- rosud-0.1.0/examples/async_example.py +105 -0
- rosud-0.1.0/examples/autogen_agent.py +197 -0
- rosud-0.1.0/examples/basic_payment.py +108 -0
- rosud-0.1.0/examples/langchain_agent.py +191 -0
- rosud-0.1.0/pyproject.toml +55 -0
- rosud-0.1.0/rosud/__init__.py +67 -0
- rosud-0.1.0/rosud/_http.py +222 -0
- rosud-0.1.0/rosud/client.py +155 -0
- rosud-0.1.0/rosud/exceptions.py +139 -0
- rosud-0.1.0/rosud/models.py +153 -0
- rosud-0.1.0/rosud/resources/__init__.py +16 -0
- rosud-0.1.0/rosud/resources/agents.py +144 -0
- rosud-0.1.0/rosud/resources/payments.py +168 -0
- rosud-0.1.0/rosud/resources/wallets.py +51 -0
- rosud-0.1.0/rosud/resources/webhooks.py +151 -0
- rosud-0.1.0/tests/__init__.py +0 -0
- rosud-0.1.0/tests/test_client.py +197 -0
rosud-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Dependencies - NEVER commit these
|
|
2
|
+
node_modules/
|
|
3
|
+
.pnp/
|
|
4
|
+
.pnp.js
|
|
5
|
+
|
|
6
|
+
# Next.js build
|
|
7
|
+
.next/
|
|
8
|
+
out/
|
|
9
|
+
dist/
|
|
10
|
+
build/
|
|
11
|
+
|
|
12
|
+
# Python
|
|
13
|
+
__pycache__/
|
|
14
|
+
*.pyc
|
|
15
|
+
*.pyo
|
|
16
|
+
.pytest_cache/
|
|
17
|
+
*.egg-info/
|
|
18
|
+
.venv/
|
|
19
|
+
venv/
|
|
20
|
+
env/
|
|
21
|
+
|
|
22
|
+
# Environment variables
|
|
23
|
+
.env
|
|
24
|
+
.env.local
|
|
25
|
+
.env.*.local
|
|
26
|
+
!*.example
|
|
27
|
+
|
|
28
|
+
# Logs
|
|
29
|
+
*.log
|
|
30
|
+
npm-debug.log*
|
|
31
|
+
|
|
32
|
+
# OS
|
|
33
|
+
.DS_Store
|
|
34
|
+
Thumbs.db
|
|
35
|
+
|
|
36
|
+
# IDE
|
|
37
|
+
.vscode/
|
|
38
|
+
.idea/
|
|
39
|
+
|
|
40
|
+
__pycache__/
|
|
41
|
+
*.pyc
|
|
42
|
+
.pytest_cache/
|
rosud-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rosud
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Rosud Python SDK - AI 에이전트 자율 USDC 결제 인프라
|
|
5
|
+
Project-URL: Homepage, https://rosud.com
|
|
6
|
+
Project-URL: Documentation, https://docs.rosud.com
|
|
7
|
+
Project-URL: Repository, https://github.com/rosud-com/rosud-python
|
|
8
|
+
Project-URL: Issues, https://github.com/rosud-com/rosud-python/issues
|
|
9
|
+
Author-email: Rosud Team <team@rosud.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: agents,ai,payments,stablecoin,usdc,web3
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: httpx>=0.25.0
|
|
23
|
+
Requires-Dist: pydantic>=2.0.0
|
|
24
|
+
Provides-Extra: autogen
|
|
25
|
+
Requires-Dist: pyautogen>=0.2.0; extra == 'autogen'
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-httpx>=0.21.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: respx>=0.20.0; extra == 'dev'
|
|
31
|
+
Provides-Extra: langchain
|
|
32
|
+
Requires-Dist: langchain>=0.1.0; extra == 'langchain'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# rosud · Python SDK
|
|
36
|
+
|
|
37
|
+
> AI agent USDC payment infrastructure — Official Python SDK
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install rosud
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Quick Start
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import rosud
|
|
47
|
+
|
|
48
|
+
client = rosud.Rosud(api_key="rosud_live_xxx")
|
|
49
|
+
# or set ROSUD_API_KEY environment variable
|
|
50
|
+
|
|
51
|
+
# Create a payment
|
|
52
|
+
payment = client.payments.create(
|
|
53
|
+
amount=5.00,
|
|
54
|
+
to="0x742d35Cc6634C0532925a3b8D4C9E3Ff9C4A6bB",
|
|
55
|
+
memo="api_call_fee",
|
|
56
|
+
)
|
|
57
|
+
print(payment.status) # "confirmed"
|
|
58
|
+
print(payment.tx_hash) # "0x..."
|
|
59
|
+
|
|
60
|
+
# Check balance
|
|
61
|
+
balance = client.wallets.balance()
|
|
62
|
+
print(f"Balance: {balance.usdc} USDC")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Async
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import asyncio
|
|
69
|
+
import rosud
|
|
70
|
+
|
|
71
|
+
async def main():
|
|
72
|
+
client = rosud.AsyncRosud(api_key="rosud_live_xxx")
|
|
73
|
+
payment = await client.payments.create(amount=1.00, to="0x...")
|
|
74
|
+
await client.close()
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Resources
|
|
80
|
+
|
|
81
|
+
- **Payments** — `client.payments.create()`, `.list()`, `.get()`
|
|
82
|
+
- **Agents** — `client.agents.create()`, `.list()`, `.get()`, `.delete()`
|
|
83
|
+
- **Wallets** — `client.wallets.balance()`
|
|
84
|
+
- **Webhooks** — `client.webhooks.create()`, `.list()`, `.delete()`
|
|
85
|
+
|
|
86
|
+
## Error Handling
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from rosud.exceptions import RosudAPIError, RosudAuthError
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
payment = client.payments.create(amount=5.00, to="0x...")
|
|
93
|
+
except RosudAuthError:
|
|
94
|
+
print("Invalid API key")
|
|
95
|
+
except RosudAPIError as e:
|
|
96
|
+
print(e.status_code, e.message)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Links
|
|
100
|
+
|
|
101
|
+
- [Dashboard](https://rosud.com/dashboard)
|
|
102
|
+
- [API Docs](https://rosud.com/docs)
|
|
103
|
+
- [TypeScript SDK](https://www.npmjs.com/package/rosud)
|
|
104
|
+
- [MCP Server](https://pypi.org/project/rosud-mcp)
|
rosud-0.1.0/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# rosud · Python SDK
|
|
2
|
+
|
|
3
|
+
> AI agent USDC payment infrastructure — Official Python SDK
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install rosud
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import rosud
|
|
13
|
+
|
|
14
|
+
client = rosud.Rosud(api_key="rosud_live_xxx")
|
|
15
|
+
# or set ROSUD_API_KEY environment variable
|
|
16
|
+
|
|
17
|
+
# Create a payment
|
|
18
|
+
payment = client.payments.create(
|
|
19
|
+
amount=5.00,
|
|
20
|
+
to="0x742d35Cc6634C0532925a3b8D4C9E3Ff9C4A6bB",
|
|
21
|
+
memo="api_call_fee",
|
|
22
|
+
)
|
|
23
|
+
print(payment.status) # "confirmed"
|
|
24
|
+
print(payment.tx_hash) # "0x..."
|
|
25
|
+
|
|
26
|
+
# Check balance
|
|
27
|
+
balance = client.wallets.balance()
|
|
28
|
+
print(f"Balance: {balance.usdc} USDC")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Async
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import asyncio
|
|
35
|
+
import rosud
|
|
36
|
+
|
|
37
|
+
async def main():
|
|
38
|
+
client = rosud.AsyncRosud(api_key="rosud_live_xxx")
|
|
39
|
+
payment = await client.payments.create(amount=1.00, to="0x...")
|
|
40
|
+
await client.close()
|
|
41
|
+
|
|
42
|
+
asyncio.run(main())
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Resources
|
|
46
|
+
|
|
47
|
+
- **Payments** — `client.payments.create()`, `.list()`, `.get()`
|
|
48
|
+
- **Agents** — `client.agents.create()`, `.list()`, `.get()`, `.delete()`
|
|
49
|
+
- **Wallets** — `client.wallets.balance()`
|
|
50
|
+
- **Webhooks** — `client.webhooks.create()`, `.list()`, `.delete()`
|
|
51
|
+
|
|
52
|
+
## Error Handling
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from rosud.exceptions import RosudAPIError, RosudAuthError
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
payment = client.payments.create(amount=5.00, to="0x...")
|
|
59
|
+
except RosudAuthError:
|
|
60
|
+
print("Invalid API key")
|
|
61
|
+
except RosudAPIError as e:
|
|
62
|
+
print(e.status_code, e.message)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Links
|
|
66
|
+
|
|
67
|
+
- [Dashboard](https://rosud.com/dashboard)
|
|
68
|
+
- [API Docs](https://rosud.com/docs)
|
|
69
|
+
- [TypeScript SDK](https://www.npmjs.com/package/rosud)
|
|
70
|
+
- [MCP Server](https://pypi.org/project/rosud-mcp)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""
|
|
2
|
+
비동기 사용 예시 - Rosud Python SDK
|
|
3
|
+
|
|
4
|
+
asyncio 또는 비동기 프레임워크(FastAPI, aiohttp 등)와 함께 사용하는 예시
|
|
5
|
+
"""
|
|
6
|
+
import asyncio
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
import rosud
|
|
10
|
+
from rosud.exceptions import RosudError
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def single_payment_example() -> None:
|
|
14
|
+
"""단순 비동기 결제 예시"""
|
|
15
|
+
client = rosud.AsyncRosud(api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_xxx"))
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
payment = await client.payments.create(
|
|
19
|
+
amount=1.00,
|
|
20
|
+
to="0xRecipientAddress",
|
|
21
|
+
memo="async_payment",
|
|
22
|
+
)
|
|
23
|
+
print(f"결제 완료: {payment.id} ({payment.status})")
|
|
24
|
+
except RosudError as e:
|
|
25
|
+
print(f"결제 오류: {e.message}")
|
|
26
|
+
finally:
|
|
27
|
+
await client.aclose()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async def concurrent_payments_example() -> None:
|
|
31
|
+
"""여러 결제를 동시에 처리하는 예시 (고성능)"""
|
|
32
|
+
async with rosud.AsyncRosud(api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_xxx")) as client:
|
|
33
|
+
# 병렬로 여러 작업 실행
|
|
34
|
+
balance_task = client.wallets.get_balance()
|
|
35
|
+
payments_task = client.payments.list(limit=5)
|
|
36
|
+
|
|
37
|
+
balance, payments = await asyncio.gather(balance_task, payments_task)
|
|
38
|
+
|
|
39
|
+
print(f"현재 잔액: {balance.amount} USDC")
|
|
40
|
+
print(f"최근 결제 {len(payments)}건:")
|
|
41
|
+
for p in payments:
|
|
42
|
+
print(f" - {p.id}: {p.amount} USDC ({p.status})")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def batch_payments_example() -> None:
|
|
46
|
+
"""배치 결제 처리 예시"""
|
|
47
|
+
recipients = [
|
|
48
|
+
{"to": "0xRecipient1", "amount": 1.00, "memo": "service_fee_1"},
|
|
49
|
+
{"to": "0xRecipient2", "amount": 2.50, "memo": "service_fee_2"},
|
|
50
|
+
{"to": "0xRecipient3", "amount": 0.50, "memo": "service_fee_3"},
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
async with rosud.AsyncRosud(api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_xxx")) as client:
|
|
54
|
+
# 모든 결제를 동시에 처리
|
|
55
|
+
tasks = [
|
|
56
|
+
client.payments.create(
|
|
57
|
+
amount=r["amount"],
|
|
58
|
+
to=r["to"],
|
|
59
|
+
memo=r["memo"],
|
|
60
|
+
idempotency_key=f"batch-{i}", # 중복 방지
|
|
61
|
+
)
|
|
62
|
+
for i, r in enumerate(recipients)
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
results = await asyncio.gather(*tasks, return_exceptions=True)
|
|
66
|
+
|
|
67
|
+
for i, result in enumerate(results):
|
|
68
|
+
if isinstance(result, Exception):
|
|
69
|
+
print(f"결제 {i+1} 실패: {result}")
|
|
70
|
+
else:
|
|
71
|
+
print(f"결제 {i+1} 성공: {result.id} ({result.status})")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
async def webhook_setup_example() -> None:
|
|
75
|
+
"""웹훅 설정 예시"""
|
|
76
|
+
async with rosud.AsyncRosud(api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_xxx")) as client:
|
|
77
|
+
try:
|
|
78
|
+
webhook = await client.webhooks.create(
|
|
79
|
+
url="https://myapp.com/webhooks/rosud",
|
|
80
|
+
events=["payment.confirmed", "payment.failed"],
|
|
81
|
+
secret="my-super-secret-hmac-key",
|
|
82
|
+
)
|
|
83
|
+
print(f"웹훅 등록 완료: {webhook.id}")
|
|
84
|
+
print(f"URL: {webhook.url}")
|
|
85
|
+
print(f"구독 이벤트: {webhook.events}")
|
|
86
|
+
except RosudError as e:
|
|
87
|
+
print(f"웹훅 등록 실패: {e.message}")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
async def main() -> None:
|
|
91
|
+
print("=== 단순 결제 ===")
|
|
92
|
+
await single_payment_example()
|
|
93
|
+
|
|
94
|
+
print("\n=== 병렬 처리 ===")
|
|
95
|
+
await concurrent_payments_example()
|
|
96
|
+
|
|
97
|
+
print("\n=== 배치 결제 ===")
|
|
98
|
+
await batch_payments_example()
|
|
99
|
+
|
|
100
|
+
print("\n=== 웹훅 설정 ===")
|
|
101
|
+
await webhook_setup_example()
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__ == "__main__":
|
|
105
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AutoGen 통합 예시 - Rosud Python SDK
|
|
3
|
+
|
|
4
|
+
Microsoft AutoGen 프레임워크와 Rosud를 통합하여
|
|
5
|
+
AI 에이전트가 자율적으로 USDC 결제를 처리하는 예시.
|
|
6
|
+
|
|
7
|
+
설치:
|
|
8
|
+
pip install rosud-python pyautogen
|
|
9
|
+
"""
|
|
10
|
+
import os
|
|
11
|
+
from typing import Annotated, Optional
|
|
12
|
+
|
|
13
|
+
import rosud
|
|
14
|
+
from rosud.exceptions import PaymentError, RosudError
|
|
15
|
+
|
|
16
|
+
# Rosud 클라이언트 초기화
|
|
17
|
+
client = rosud.Rosud(api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_xxx"))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ──────────────────────────────────────────────────────────
|
|
21
|
+
# AutoGen 함수 정의 (에이전트가 호출할 함수들)
|
|
22
|
+
# ──────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
def make_payment(
|
|
25
|
+
amount: Annotated[float, "Payment amount in USDC"],
|
|
26
|
+
recipient: Annotated[str, "Recipient wallet address (0x...)"],
|
|
27
|
+
memo: Annotated[str, "Payment memo or description"] = "",
|
|
28
|
+
) -> str:
|
|
29
|
+
"""Make a USDC payment via Rosud.
|
|
30
|
+
|
|
31
|
+
This function allows an AI agent to make cryptocurrency payments
|
|
32
|
+
in USDC on the Base L2 network.
|
|
33
|
+
"""
|
|
34
|
+
try:
|
|
35
|
+
payment = client.payments.create(
|
|
36
|
+
amount=amount,
|
|
37
|
+
to=recipient,
|
|
38
|
+
memo=memo or "autogen_payment",
|
|
39
|
+
)
|
|
40
|
+
return (
|
|
41
|
+
f"Payment successful!\n"
|
|
42
|
+
f" ID: {payment.id}\n"
|
|
43
|
+
f" Amount: {payment.amount} USDC\n"
|
|
44
|
+
f" Recipient: {payment.to_wallet}\n"
|
|
45
|
+
f" Status: {payment.status}\n"
|
|
46
|
+
f" TX Hash: {payment.tx_hash or 'pending'}"
|
|
47
|
+
)
|
|
48
|
+
except PaymentError as e:
|
|
49
|
+
return f"Payment failed: {e.message} (code: {e.error_code})"
|
|
50
|
+
except RosudError as e:
|
|
51
|
+
return f"Error: {e.message}"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_balance() -> str:
|
|
55
|
+
"""Get current USDC wallet balance."""
|
|
56
|
+
try:
|
|
57
|
+
balance = client.wallets.get_balance()
|
|
58
|
+
return (
|
|
59
|
+
f"Wallet Balance:\n"
|
|
60
|
+
f" Amount: {balance.amount} {balance.currency}\n"
|
|
61
|
+
f" Network: {balance.network}\n"
|
|
62
|
+
f" Address: {balance.address}"
|
|
63
|
+
)
|
|
64
|
+
except RosudError as e:
|
|
65
|
+
return f"Error getting balance: {e.message}"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_payment_history(limit: Annotated[int, "Number of payments to retrieve"] = 5) -> str:
|
|
69
|
+
"""Get recent payment history."""
|
|
70
|
+
try:
|
|
71
|
+
payments = client.payments.list(limit=limit)
|
|
72
|
+
if not payments.items:
|
|
73
|
+
return "No payments found."
|
|
74
|
+
|
|
75
|
+
lines = [f"Recent {len(payments)} payment(s) (total: {payments.total}):"]
|
|
76
|
+
for p in payments:
|
|
77
|
+
lines.append(
|
|
78
|
+
f" [{p.status.upper()}] {p.amount} USDC → "
|
|
79
|
+
f"{p.to_wallet[:12]}... | {p.created_at:%Y-%m-%d %H:%M}"
|
|
80
|
+
)
|
|
81
|
+
return "\n".join(lines)
|
|
82
|
+
except RosudError as e:
|
|
83
|
+
return f"Error: {e.message}"
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# ──────────────────────────────────────────────────────────
|
|
87
|
+
# AutoGen 에이전트 실행 예시
|
|
88
|
+
# ──────────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
def run_autogen_example() -> None:
|
|
91
|
+
"""AutoGen ConversableAgent 예시"""
|
|
92
|
+
try:
|
|
93
|
+
import autogen
|
|
94
|
+
from autogen import ConversableAgent, UserProxyAgent
|
|
95
|
+
|
|
96
|
+
# LLM 설정
|
|
97
|
+
llm_config = {
|
|
98
|
+
"config_list": [
|
|
99
|
+
{
|
|
100
|
+
"model": "gpt-4",
|
|
101
|
+
"api_key": os.environ.get("OPENAI_API_KEY"),
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
"temperature": 0,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# AI 에이전트 (결제 처리 담당)
|
|
108
|
+
payment_agent = ConversableAgent(
|
|
109
|
+
name="PaymentAgent",
|
|
110
|
+
system_message=(
|
|
111
|
+
"You are a payment processing agent. "
|
|
112
|
+
"You can check wallet balances and make USDC payments. "
|
|
113
|
+
"Always check the balance before making payments. "
|
|
114
|
+
"Be careful and confirm the recipient address before paying."
|
|
115
|
+
),
|
|
116
|
+
llm_config=llm_config,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Function 등록
|
|
120
|
+
payment_agent.register_for_llm(name="make_payment", description="Make a USDC payment")(make_payment)
|
|
121
|
+
payment_agent.register_for_llm(name="get_balance", description="Check wallet balance")(get_balance)
|
|
122
|
+
payment_agent.register_for_llm(name="get_payment_history", description="Get payment history")(get_payment_history)
|
|
123
|
+
|
|
124
|
+
# UserProxy (함수 실행자)
|
|
125
|
+
user_proxy = UserProxyAgent(
|
|
126
|
+
name="UserProxy",
|
|
127
|
+
human_input_mode="NEVER",
|
|
128
|
+
max_consecutive_auto_reply=5,
|
|
129
|
+
is_termination_msg=lambda x: "TERMINATE" in x.get("content", ""),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
user_proxy.register_for_execution(name="make_payment")(make_payment)
|
|
133
|
+
user_proxy.register_for_execution(name="get_balance")(get_balance)
|
|
134
|
+
user_proxy.register_for_execution(name="get_payment_history")(get_payment_history)
|
|
135
|
+
|
|
136
|
+
# 대화 시작
|
|
137
|
+
user_proxy.initiate_chat(
|
|
138
|
+
payment_agent,
|
|
139
|
+
message=(
|
|
140
|
+
"Please check my wallet balance and show me the last 3 payments. "
|
|
141
|
+
"If my balance is over 10 USDC, pay 1.50 USDC to "
|
|
142
|
+
"0xServiceProvider123 with memo 'autogen_test'. "
|
|
143
|
+
"Reply TERMINATE when done."
|
|
144
|
+
),
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
except ImportError:
|
|
148
|
+
print("AutoGen이 설치되지 않았습니다. pip install pyautogen 을 실행하세요.")
|
|
149
|
+
print("\n직접 함수 테스트:")
|
|
150
|
+
print(get_balance())
|
|
151
|
+
print("\n" + get_payment_history(3))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# ──────────────────────────────────────────────────────────
|
|
155
|
+
# AutoGen v0.4+ (새 API) 예시
|
|
156
|
+
# ──────────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
def run_autogen_v04_example() -> None:
|
|
159
|
+
"""AutoGen v0.4+ AssistantAgent 예시"""
|
|
160
|
+
try:
|
|
161
|
+
from autogen_agentchat.agents import AssistantAgent
|
|
162
|
+
from autogen_agentchat.ui import Console
|
|
163
|
+
from autogen_ext.models.openai import OpenAIChatCompletionClient
|
|
164
|
+
|
|
165
|
+
# 도구 함수들
|
|
166
|
+
async def async_get_balance() -> str:
|
|
167
|
+
async with rosud.AsyncRosud(api_key=os.environ.get("ROSUD_API_KEY")) as c:
|
|
168
|
+
balance = await c.wallets.get_balance()
|
|
169
|
+
return f"{balance.amount} {balance.currency} on {balance.network}"
|
|
170
|
+
|
|
171
|
+
async def async_make_payment(amount: float, to: str, memo: str = "") -> str:
|
|
172
|
+
async with rosud.AsyncRosud(api_key=os.environ.get("ROSUD_API_KEY")) as c:
|
|
173
|
+
payment = await c.payments.create(amount=amount, to=to, memo=memo)
|
|
174
|
+
return f"Payment {payment.id}: {payment.status} ({payment.amount} USDC)"
|
|
175
|
+
|
|
176
|
+
model_client = OpenAIChatCompletionClient(model="gpt-4o")
|
|
177
|
+
|
|
178
|
+
agent = AssistantAgent(
|
|
179
|
+
"payment_agent",
|
|
180
|
+
model_client=model_client,
|
|
181
|
+
tools=[async_get_balance, async_make_payment],
|
|
182
|
+
system_message=(
|
|
183
|
+
"You are a payment agent. "
|
|
184
|
+
"Use the available tools to check balance and make payments."
|
|
185
|
+
),
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
import asyncio
|
|
189
|
+
asyncio.run(Console(agent.run_stream(task="Check my USDC balance")))
|
|
190
|
+
|
|
191
|
+
except ImportError:
|
|
192
|
+
print("autogen-agentchat이 설치되지 않았습니다.")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
if __name__ == "__main__":
|
|
196
|
+
print("=== AutoGen + Rosud 통합 예시 ===\n")
|
|
197
|
+
run_autogen_example()
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""
|
|
2
|
+
기본 결제 예시 - Rosud Python SDK
|
|
3
|
+
|
|
4
|
+
이 예시는 Rosud SDK의 기본 사용법을 보여줍니다:
|
|
5
|
+
- 결제 생성
|
|
6
|
+
- 결제 목록 조회
|
|
7
|
+
- 지갑 잔액 조회
|
|
8
|
+
- 에이전트 생성
|
|
9
|
+
"""
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import rosud
|
|
13
|
+
from rosud.exceptions import InsufficientFundsError, PaymentError, RosudError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main() -> None:
|
|
17
|
+
# API 키 설정 (환경변수 또는 직접 전달)
|
|
18
|
+
client = rosud.Rosud(
|
|
19
|
+
api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_your_key_here"),
|
|
20
|
+
base_url=os.environ.get("ROSUD_BASE_URL", "https://api.rosud.com"),
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# ──────────────────────────────────────────────
|
|
24
|
+
# 1. 지갑 잔액 확인
|
|
25
|
+
# ──────────────────────────────────────────────
|
|
26
|
+
print("=== 지갑 잔액 ===")
|
|
27
|
+
try:
|
|
28
|
+
balance = client.wallets.get_balance()
|
|
29
|
+
print(f"잔액: {balance.amount} {balance.currency}")
|
|
30
|
+
print(f"주소: {balance.address}")
|
|
31
|
+
print(f"네트워크: {balance.network}")
|
|
32
|
+
except RosudError as e:
|
|
33
|
+
print(f"잔액 조회 실패: {e.message}")
|
|
34
|
+
|
|
35
|
+
# ──────────────────────────────────────────────
|
|
36
|
+
# 2. 결제 생성
|
|
37
|
+
# ──────────────────────────────────────────────
|
|
38
|
+
print("\n=== 결제 생성 ===")
|
|
39
|
+
try:
|
|
40
|
+
payment = client.payments.create(
|
|
41
|
+
amount=5.00,
|
|
42
|
+
currency="USDC",
|
|
43
|
+
to="0xRecipientWalletAddress123456789012345678",
|
|
44
|
+
memo="api_call_fee",
|
|
45
|
+
idempotency_key="unique-payment-key-001", # 중복 방지
|
|
46
|
+
)
|
|
47
|
+
print(f"결제 ID: {payment.id}")
|
|
48
|
+
print(f"상태: {payment.status}")
|
|
49
|
+
print(f"금액: {payment.amount} {payment.currency}")
|
|
50
|
+
print(f"수신자: {payment.to_wallet}")
|
|
51
|
+
print(f"TX Hash: {payment.tx_hash or '(pending)'}")
|
|
52
|
+
except InsufficientFundsError:
|
|
53
|
+
print("잔액이 부족합니다.")
|
|
54
|
+
except PaymentError as e:
|
|
55
|
+
print(f"결제 오류 [{e.error_code}]: {e.message}")
|
|
56
|
+
except RosudError as e:
|
|
57
|
+
print(f"오류: {e.message}")
|
|
58
|
+
|
|
59
|
+
# ──────────────────────────────────────────────
|
|
60
|
+
# 3. 결제 목록 조회
|
|
61
|
+
# ──────────────────────────────────────────────
|
|
62
|
+
print("\n=== 최근 결제 목록 ===")
|
|
63
|
+
try:
|
|
64
|
+
payments = client.payments.list(limit=10)
|
|
65
|
+
print(f"총 {payments.total}건 중 {len(payments)}건 조회")
|
|
66
|
+
for p in payments:
|
|
67
|
+
print(f" - {p.id} | {p.amount} USDC | {p.status} | {p.created_at:%Y-%m-%d %H:%M}")
|
|
68
|
+
except RosudError as e:
|
|
69
|
+
print(f"결제 목록 조회 실패: {e.message}")
|
|
70
|
+
|
|
71
|
+
# ──────────────────────────────────────────────
|
|
72
|
+
# 4. 에이전트 생성 (AI 에이전트용 서브계정)
|
|
73
|
+
# ──────────────────────────────────────────────
|
|
74
|
+
print("\n=== 에이전트 생성 ===")
|
|
75
|
+
try:
|
|
76
|
+
agent = client.agents.create(
|
|
77
|
+
name="Payment Bot v1",
|
|
78
|
+
spending_limit_daily=100.00, # 일 100 USDC 한도
|
|
79
|
+
spending_limit_per_tx=10.00, # 건당 10 USDC 한도
|
|
80
|
+
allowed_recipients=[ # 화이트리스트 (보안)
|
|
81
|
+
"0xApprovedRecipient1",
|
|
82
|
+
"0xApprovedRecipient2",
|
|
83
|
+
],
|
|
84
|
+
)
|
|
85
|
+
print(f"에이전트 ID: {agent.id}")
|
|
86
|
+
print(f"에이전트 이름: {agent.name}")
|
|
87
|
+
print(f"API 키: {agent.api_key}") # 최초 1회만 반환!
|
|
88
|
+
print("⚠️ API 키를 안전하게 보관하세요. 다시 조회할 수 없습니다.")
|
|
89
|
+
except RosudError as e:
|
|
90
|
+
print(f"에이전트 생성 실패: {e.message}")
|
|
91
|
+
|
|
92
|
+
# ──────────────────────────────────────────────
|
|
93
|
+
# 5. context manager 사용법
|
|
94
|
+
# ──────────────────────────────────────────────
|
|
95
|
+
print("\n=== Context Manager 사용 ===")
|
|
96
|
+
with rosud.Rosud(api_key=os.environ.get("ROSUD_API_KEY", "rosud_live_key")) as c:
|
|
97
|
+
try:
|
|
98
|
+
balance = c.wallets.get_balance()
|
|
99
|
+
print(f"잔액: {balance.amount} USDC")
|
|
100
|
+
except RosudError as e:
|
|
101
|
+
print(f"오류: {e}")
|
|
102
|
+
|
|
103
|
+
client.close()
|
|
104
|
+
print("\n완료!")
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if __name__ == "__main__":
|
|
108
|
+
main()
|