Architecture
The SDK is designed in three layers of abstraction:
Layer 1: Targets
This layer has diffing & patching functions on role configurations, operating on JSON objects matching the Role
type of the subgraph schema.
Example:
{
address: "0x182B723a58739a9c974cFDB385ceaDb237453c28",
clearance: Clearance.Function,
functions: [
{
selector: "0x84e9bd7e",
condition: {
paramType: ParameterType.Calldata,
operator: Operator.Matches,
children: [
{
paramType: ParameterType.Static,
operator: Operator.EqualTo,
compValue: defaultAbiCoder.encode(["address"], ["0x4F2083f5fBede34C2714aFfb3105539775f7FE64"]),
}
],
},
}
]
}
Functions implemented on this layer:
- fetch current role configurations
- compute contract calls required for patching an existing role configuration (targets and members) to a desired configuration
- integrity checks, minimizations, and normalizations for conditions
Layer 2: Permissions
For authoring purposes it is useful to capture permissions in a slightly different structure: Rather than the list of targets with nested functions as exposed by the subgraph, permissions are defined by a flat array of entries that grant call right to an address or a specific function at an address.
This layer also provides condition helper functions for a more convenient way of expressing conditions.
Example:
{
targetAddress: '0x182B723a58739a9c974cFDB385ceaDb237453c28',
signature: "claim_rewards(address)",
condition: c.calldataMatches([c.avatar], ["address"]),
}
Functions implemented on this layer:
- support for condition authoring
- joining permissions addressing the same function
Layer 3: Kits
On the highest layer of abstraction, users can generate kits for contracts they want to define permission for. A kit is a typed SDK tailored to a specific set of contracts that allows defining permissions on these in a convenient syntax and fully supported by the type system.
Users just provide the addresses of contracts. Powered by eth-sdk (opens in a new tab) and TypeChain (opens in a new tab), ABIs will be automatically downloaded from Etherscan to generate type-safe functions for granting permissions.
Example:
allow.curve.stETH_ETH_gauge["claim_rewards(address)"](c.avatar);
Functions implemented on this layer:
- type system support for conditions authoring