-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathcreate_end_user_policy.py
More file actions
145 lines (136 loc) · 5.37 KB
/
create_end_user_policy.py
File metadata and controls
145 lines (136 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Usage: uv run python end_user/create_end_user_policy.py
import asyncio
from cdp import CdpClient
from cdp.policies.types import (
CreateEndUserEvmSwapRule,
CreatePolicyOptions,
EthValueCriterion,
EvmAddressCriterion,
EvmMessageCriterion,
EvmNetworkCriterion,
NetUSDChangeCriterion,
SendEndUserEvmTransactionRule,
SendEndUserSolTransactionRule,
SignEndUserEvmMessageRule,
SignEndUserEvmTransactionRule,
SignEndUserEvmTypedDataRule,
SignEndUserSolMessageRule,
SignEndUserSolTransactionRule,
SignEvmTypedDataVerifyingContractCriterion,
SolAddressCriterion,
SolMessageCriterion,
SolNetworkCriterion,
SolValueCriterion,
SplAddressCriterion,
)
from dotenv import load_dotenv
load_dotenv()
async def main():
async with CdpClient() as cdp:
policy_options = CreatePolicyOptions(
description="End User Policy Example",
scope="project",
rules=[
# Restrict end-user EVM transaction signing to a max value and allowlisted recipients
SignEndUserEvmTransactionRule(
action="accept",
criteria=[
EthValueCriterion(
ethValue="1000000000000000000", # 1 ETH in wei
operator="<=",
),
EvmAddressCriterion(
addresses=["0x000000000000000000000000000000000000dEaD"],
operator="in",
),
],
),
# Restrict end-user EVM transaction sending to a specific network and max USD exposure
SendEndUserEvmTransactionRule(
action="accept",
criteria=[
EvmNetworkCriterion(
networks=["base", "base-sepolia"],
operator="in",
),
NetUSDChangeCriterion(
changeCents=10000, # $100.00
operator="<=",
),
],
),
# Restrict end-user EVM swaps to a specific network and max USD exposure
CreateEndUserEvmSwapRule(
action="accept",
criteria=[
EvmNetworkCriterion(
networks=["base", "base-sepolia"],
operator="in",
),
NetUSDChangeCriterion(
changeCents=10000, # $100.00
operator="<=",
),
],
),
# Restrict end-user EVM message signing to messages matching a specific pattern
SignEndUserEvmMessageRule(
action="accept",
criteria=[
EvmMessageCriterion(
match="^Sign in to MyApp.*",
),
],
),
# Restrict end-user EVM typed data signing to a known verifying contract
SignEndUserEvmTypedDataRule(
action="accept",
criteria=[
SignEvmTypedDataVerifyingContractCriterion(
addresses=["0x000000000000000000000000000000000000dEaD"],
operator="in",
),
],
),
# Restrict end-user Solana transaction signing to allowlisted recipients under a SOL value threshold
SignEndUserSolTransactionRule(
action="accept",
criteria=[
SolAddressCriterion(
addresses=["11111111111111111111111111111111"],
operator="in",
),
SolValueCriterion(
solValue="1000000000", # 1 SOL in lamports
operator="<=",
),
],
),
# Restrict end-user Solana transaction sending to devnet with an SPL token allowlist
SendEndUserSolTransactionRule(
action="accept",
criteria=[
SolNetworkCriterion(
networks=["solana-devnet"],
operator="in",
),
SplAddressCriterion(
addresses=["11111111111111111111111111111111"],
operator="in",
),
],
),
# Restrict end-user Solana message signing to messages matching a specific pattern
SignEndUserSolMessageRule(
action="accept",
criteria=[
SolMessageCriterion(
match="^Sign in to MyApp.*",
),
],
),
],
)
policy = await cdp.policies.create_policy(policy=policy_options)
print("Created end user policy:", policy.id)
asyncio.run(main())