Set Agent Permissions
This guide walks you through the basic steps of using the Zodiac Roles SDK to define permissions for your Agent.
This guide has been imported from the Zodiac Roles Modifier Getting Started guide. For the most up-to-date documentation, please check out their documentation.
Installation
The Roles SDK relies on eth-sdk for generating type-safe APIs from automatically downloaded contract ABIs. To add it to your project, run one of the following commands.
With npm:
npm i --save @gnosis-guild/eth-sdk @gnosis-guild/eth-sdk-client zodiac-roles-sdk
With yarn:
yarn add @gnosis-guild/eth-sdk @gnosis-guild/eth-sdk-client zodiac-roles-sdk
With pnpm:
pnpm add @gnosis-guild/eth-sdk @gnosis-guild/eth-sdk-client zodiac-roles-sdk
Configuration
The next step is to create a config file that lists all the contracts we want to permit our Agent to calling.
Create a folder named eth-sdk
in your project root (where your package.json is located).
Inside this folder, create a config.ts
file with the following content structure:
import { defineConfig } from "@gnosis-guild/eth-sdk";
export default defineConfig({
contracts: {
mainnet: {
dai: "0x6b175474e89094c44da98b954eedeac495271d0f",
},
},
});
This example lists the DAI contract on Ethereum mainnet.
The object under the contracts
field should generally list the identifiers of all chains you plan to target.
For each chain entry, you can define arbitrary object structures with addresses stored at the leave values.
For custom chain configurations: refer to the eth-sdk docs for a complete overview of the available configuration options.
Generate allow kit
Now, and after any update to the eth-sdk/config.ts
file, make sure to run the following command:
yarn eth-sdk
This command will fetch the ABIs of the contracts listed in the config file and generate TypeScript types for them directly into your node_modules.
If the ABI of any listed contract cannot be fetched automatically, the command will return an error code.
In that case, you need to manually create a JSON file with the ABI at a location inside eth-sdk/abi
matching the path of the contract in the eth-sdk/config.ts
file.
The VSCode TypeScript server may not automatically pick up the type updates
generated by the yarn eth-sdk
command. To ensure the latest state is
reflected in your IDE, press CMD
+SHIFT
+P
and select "TypeScript: Restart
TS Server".
Define permissions
You now have a typed allow kit at your disposal.
Access it by importing from "zodiac-roles-sdk/kit"
:
import { allow } from "zodiac-roles-sdk/kit";
const CURVE_3POOL = "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7";
const permissions = [allow.mainnet.dai.approve(CURVE_3POOL)];
Generate permissions.json
Once your permissions have been defined, generate the permissions.json
like so:
const { targets } = processPermissions(permissions);
import { writeFileSync } from 'fs';
writeFileSync('permissions.json', JSON.stringify(targets, null, 2));
And you're done! Once you create your Agent from this strategy, you will be prompted to sign a transaction to apply these permissions to your wallet.