@varla/sdk 2.13.1 → 2.15.0

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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  import type { Address, Hex } from "viem";
4
4
 
5
+ import { abis } from "../generated.js";
6
+
5
7
  // ---------------------------------------------------------------------------
6
8
  // Common signatures (DevEx)
7
9
  // ---------------------------------------------------------------------------
@@ -78,3 +80,111 @@ export async function assertCanCallImmediate(params: {
78
80
  throw new Error(`AccessManager.canCall denied or delayed (delay=${r.delay})`);
79
81
  }
80
82
  }
83
+
84
+ // ---------------------------------------------------------------------------
85
+ // VarlaAccessManager — mutating RBAC actions
86
+ // ---------------------------------------------------------------------------
87
+
88
+ /** Grant a role to an account. Requires ADMIN role (0). */
89
+ export async function prepareGrantRole(params: {
90
+ publicClient: { simulateContract: (args: any) => Promise<any> };
91
+ accessManagerAddress: Address;
92
+ account: Address;
93
+ roleId: bigint;
94
+ grantee: Address;
95
+ executionDelay: number;
96
+ }): Promise<any> {
97
+ return await params.publicClient.simulateContract({
98
+ address: params.accessManagerAddress,
99
+ abi: abis.VARLAACCESSMANAGER_ABI,
100
+ functionName: "grantRole",
101
+ args: [params.roleId, params.grantee, params.executionDelay],
102
+ account: params.account,
103
+ });
104
+ }
105
+
106
+ /** Revoke a role from an account. Requires ADMIN role (0). */
107
+ export async function prepareRevokeRole(params: {
108
+ publicClient: { simulateContract: (args: any) => Promise<any> };
109
+ accessManagerAddress: Address;
110
+ account: Address;
111
+ roleId: bigint;
112
+ target: Address;
113
+ }): Promise<any> {
114
+ return await params.publicClient.simulateContract({
115
+ address: params.accessManagerAddress,
116
+ abi: abis.VARLAACCESSMANAGER_ABI,
117
+ functionName: "revokeRole",
118
+ args: [params.roleId, params.target],
119
+ account: params.account,
120
+ });
121
+ }
122
+
123
+ /** Map function selectors on a target to a role. Requires ADMIN role (0). */
124
+ export async function prepareSetTargetFunctionRole(params: {
125
+ publicClient: { simulateContract: (args: any) => Promise<any> };
126
+ accessManagerAddress: Address;
127
+ account: Address;
128
+ target: Address;
129
+ selectors: readonly Hex[];
130
+ roleId: bigint;
131
+ }): Promise<any> {
132
+ return await params.publicClient.simulateContract({
133
+ address: params.accessManagerAddress,
134
+ abi: abis.VARLAACCESSMANAGER_ABI,
135
+ functionName: "setTargetFunctionRole",
136
+ args: [params.target, params.selectors, params.roleId],
137
+ account: params.account,
138
+ });
139
+ }
140
+
141
+ /** Close or open a target contract. When closed, all restricted calls revert. */
142
+ export async function prepareSetTargetClosed(params: {
143
+ publicClient: { simulateContract: (args: any) => Promise<any> };
144
+ accessManagerAddress: Address;
145
+ account: Address;
146
+ target: Address;
147
+ closed: boolean;
148
+ }): Promise<any> {
149
+ return await params.publicClient.simulateContract({
150
+ address: params.accessManagerAddress,
151
+ abi: abis.VARLAACCESSMANAGER_ABI,
152
+ functionName: "setTargetClosed",
153
+ args: [params.target, params.closed],
154
+ account: params.account,
155
+ });
156
+ }
157
+
158
+ /** Set the admin role for a given role (role hierarchy). */
159
+ export async function prepareSetRoleAdmin(params: {
160
+ publicClient: { simulateContract: (args: any) => Promise<any> };
161
+ accessManagerAddress: Address;
162
+ account: Address;
163
+ roleId: bigint;
164
+ adminRoleId: bigint;
165
+ }): Promise<any> {
166
+ return await params.publicClient.simulateContract({
167
+ address: params.accessManagerAddress,
168
+ abi: abis.VARLAACCESSMANAGER_ABI,
169
+ functionName: "setRoleAdmin",
170
+ args: [params.roleId, params.adminRoleId],
171
+ account: params.account,
172
+ });
173
+ }
174
+
175
+ /** Set the guardian role for a given role. */
176
+ export async function prepareSetRoleGuardian(params: {
177
+ publicClient: { simulateContract: (args: any) => Promise<any> };
178
+ accessManagerAddress: Address;
179
+ account: Address;
180
+ roleId: bigint;
181
+ guardianRoleId: bigint;
182
+ }): Promise<any> {
183
+ return await params.publicClient.simulateContract({
184
+ address: params.accessManagerAddress,
185
+ abi: abis.VARLAACCESSMANAGER_ABI,
186
+ functionName: "setRoleGuardian",
187
+ args: [params.roleId, params.guardianRoleId],
188
+ account: params.account,
189
+ });
190
+ }