Safe Core SDK 🛠Managing modules and transaction guards - Germán MartÃnez
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Germán MartÃnez from Safe for a workshop titled "Managing modules and transaction guards". And that wraps up 2022! ETHIndia 2022⎯the biggest Ethereum hackathon to this date with over 459 projects built within 36 hours. 🫂 2000 attendees from 🌆 321 cities that were 🌱 44% new to web3... ...joined forces in Bengaluru to write history. Thank you for taking part in it 🫶🔥 ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com
Transcript
foreign [Applause] [Music] about the safe but specifically the safe core SDK and we're gonna mention uh what are the safe modules and safe transaction guards and also how to save car SDK can help us manage them so uh the content will be covering today is an overview of the safe architecture and we're gonna see uh the safe core SDK monoripo that is GitHub available how the transaction flow works on the safe where multiple signers must to have a um need to sign a transaction then we are going to talk about the safe modules and how they can expand the functionality of a safe also safe transaction guards how they can check or add some constraints to the transactions that are being executed and then we are gonna see what hackathon bounties we have and how to contact us and what resources we have to help you during the hackathon so first of all I would like to ask you uh if you please could raise your hand to see who knows about the safe what the safe is okay who's using the save who knows about uh transaction guards or modules okay pretty good so pretty good so let's start with the safe architecture a brief overview we have different layers the main one will be the contracts the more the most critical one and there we can find the save contract itself there are a couple of contracts that interact among each other then we have some libraries for example the multisend that allows to execute paths transactions we have also the save modules and safe transaction guards that will be see will be will see later we also have a layer of services that we run but you can also run by yourself being the most important one regarding this talk the safe transaction service because it will allow us to collect the transactions that are proposed by any of the signers and also the signatures from the other signers so somebody can execute a transaction finally and the last layer are the interfaces so we have different interfaces like the web interface mobile apps CLI and some sdks here we will covering uh in the sdks the safe core SDK so let's see how the SDK mono repo looks like and what it is the Safeguard SDK it is a software developer tools that facilitate the interaction with a smart contracts and also the services and because it is a mono repo there are some packages inside of it so let's see what I do quickly the first two the Safeguard CK types and Safeco SDK utils uh it's pretty easy to see what they do right the one of them exports types makes them available to the other packages and the utils has some utility functions then we have the next two the safe web3 library and the safe ethers Library these are two wrappers of the web 3.js and the ethers JS libraries and also uh allow to get instances of this of the safe smart contracts depending on the version you want to use and the network you have to provide it connected to after that we have the safe core CK this is the most important package in this mono repo it will need one of the previous packages like web3 or ethers that will provide a connection to the to the network and then you would need to provide a safe address in order to initialize these packets if you don't have a safe address you can also deploy one with it and this package is all about interacting with the smart contracts everything there happens on chain and you can get information from the safe like getting the owners the threshold the nouns whatever you can also create and prepare transactions you want to execute sign them and execute them and finally we have the safe service client uh as you if you remember before there was a one service the safe transaction service that allows to collect transactions that are proposed and its signatures and this safe service client consumes that API so you can also get information from the safe by consuming this this API but also have access to the history of transactions check the transactions that are that are pending and require your signature you can also propose a new transaction you can get the balances of the safe the usdc conversion uh Etc so uh in this Mana repo we have like these packages we also have a guide that will show you step by step how to use the SDK how to propose a transaction sign it execute it and we have a playground this playground ground is something new uh it is a a folder called playground where you already have a few scripts just have to modify a couple of configuration parameters like your safe the RPC you want to use Etc and then you will be able to deploy a safe to propose a transaction to sign it and to execute it so let's see how the transaction flow looks like and how it is different from the external own accounts for external Loan account the transaction flow is easy right you have just an account with a private key that gives you access to everything inside that account however the save because it is a smart contract where its main functionality is being a multi-signature wallet we need a couple of signatures so these signatures uh together can approve what the transactions we want to execute if they reach a threshold we can defined so for example two out of these three signers need to approve every transaction we can use the safe transaction service to collect the signatures of chain this is something optional but we will use it to afford some gas and as we saw before uh the the flow would be to initialize the core CK deploy as if we don't have it create propose confirm and execute so let's see how it looks uh the code we need to import the Safeguard SDK Library save ethers if we are using ethers and then the the safe service client we need to provide to Define our provider get the signer and then initialize is each of these packages uh by providing these parameters after that we can create a transaction object with the destination value data operation if it's a call or delegate Call Etc we can convert this object into a safe transaction object that will also be able to handle the signatures and then we need to use the service the method propose transaction to propose it and to send this transaction to the service then if we are running a client like this one using a different signer we have the service to get a transaction if we already know the safe transaction has we can use it to get the transaction completely otherwise we have a variety of methods you can we can use like get pending transactions for example and then from there we can get the transaction we want to execute finally we can call the service confirm transaction but before we need to sign it with the safe core SDK Colleen's signed transaction hash and once we call the service this signature will be submitted after that we just need to execute the transaction once we have enough signatures so uh before that before executing there's optionally a method that is called isvalid transaction that will check if this transaction will be will fail or not here if the transaction is executable then we can call the method save execute transaction passing this object so that's how the basic flow works now let's see what are the safe modules this is the main flow and the the save modules are very flexible and allowed to uh allowed to increment or to expand the functionality of the safe because they offer us another flow for these transactions that is more flexible that don't depend on designers so we need to deploy a safe safe module in the same network where we where our safe is and all the save module needs to do is just call the method exact transaction from module in the safe so the current flow when you want to execute a transaction you are calling the method in the safe exact transaction inside of that method there's contain all the logic that checks if the scene if the signers did sign the signature the the transaction but here this save module you can start with an empty one just calling exact transaction from module passing the transaction and it will have root access to execute the transaction this is very flexible because safe modules are like a white paper a white paper you can feel but also the responsibility of doing it well uh it's on you so all the logic not for checking the signers but for Designing how do you want to make a transaction valid or executable or not depends on you so multi-signature control is the basic functionality the safe has but safe modules also give us uh the opportunity to increase it for example assigning roles We could decide to assign admin rights or token voting or spending limits for example this would look like admin rights if you know zodiac which is a Dao tooling standard or they are building tools for those they have a module that is the role modifier and there you can Define okay for these you can Define different roles that and assign addresses to these roles meaning that some addresses will be able to execute or to call a specific uh to basically to execute transactions with uh where the parameters of these transactions are checked so somebody could execute a transaction that where the destination is one specific address but other addresses won't be able to do that but they will be able to do other things depending on the roles for token voting for example you can decide check to check if if the transaction like if the approvers of this transaction have some balance of a token or nft and if some of them approve a transaction then allow them to execute it or spend the limit you could Define that some account is able without anybody other or with any other confirmation they will be able to spend a certain amount of accept of a certain token in a certain period of time like weekly daily monthly this is for roles but also for Recovery mechanisms modules would allow at some point of time when a depending on on your logic the a safe is not used to trigger a transaction that or replace the current owners with the people who is activating this mechanism or just transferring the funds somewhere else and we could do that with social recovery by defining your friend your friend's addresses and giving them access later in time or a secret questions like if you remember long ago uh when you were logging into a web page there was did you remember your password do you remember your password and then uh it would ask you what was the name of your first teacher or whatever you could do something like that or custodial recovery or hybrid uh custody Etc and also modifiers modifiers are kind of modules that allow to be chained so each of them offers adds some constraints for example adding time logs to the transactions so you have a queue uh establishing cooldown periods or bonds where the people who confirms if a transaction can be executed or not have to deposit something Etc how the does the course Decay facilitates the interaction of or the management of the of safe modules there are a few methods that are available for example get modules when you where you can get a list of the modules you have enabled into your safe then is module enabled because I think I didn't say that in order to execute this uh the transactions from the module it is mandatory that the module is enabled in in the safe that means that at the beginning uh the signers need to create a transaction to enable that module it's not that anybody anybody can just deploy its own module and connect it to yourself so that's the basic thing so with the SDK you can enable a module disable a module check if enabled module is enabled or not and get the list so that's for modules and then we have the transaction guards safe transaction guards are also smart contracts that need to be deployed in the same network and they somehow are connected to the safe but they are not a starting point in the transaction flow but somehow they will take its place so here we see the the transaction flow designers the save the network and the safe transaction guards that are connected to the safe as as the same as before transaction guards need to be enabled or disabled by the by designers and once a transaction guard is enabled what they do is they have to implement an interface with two methods each of these methods will be run before and after the transaction does some State changes in the contract so we will have a method to do a pre-check and another method to do a post check and these methods will receive the transaction and will be able to parse it and act on it depending on the values of the parameters if the texts that are there pass the transaction will be successful otherwise the transaction will fail and you won't be able to execute it we saw the the advantages or how the functionality can be expanded with the modules what transaction got guards add is basically more protection you can define an allow list or deny list you could freeze an account Etc how this would look like for example for creating creating an allow or deny list you can deploy your or create your own transaction guard with these two methods and in the storage of the smart contract you could have a like a data storage structure to keep a track of a list of addresses and then in the first check for example you could check if the destination of the transaction that is going to be executed it is inside the list or not and act on that to freeze an account for example you could have a variable in the storage of the smart contract that is a switch a Boolean where you can say okay this account is freezed or is not do you see any problem with that it is very cool to be able to freeze an account but if you turn the switch off then the next transaction there won't be any more transactions right because there's no way to turn the switch on again so it's very important that all the that this kind of transaction guards parse a specific way of turning them on just um denying all the transaction except the one that where the date of the transaction or the encoding data allows to turn this switch on so it's very cool but also uh you have to know what you are doing now how the safe core SDK helps with safe transaction guards similar to what we have for modules we have the method get guard in this case safes can only have one transaction guard and you can enable them or disable them these methods return a transaction that is ready to be signed by designers okay so that was basically it we had the safe course Decay save modules save transaction guards and now what you are all expecting what are our bounties for this hackathon so the safe ecosystem Foundation has available 10 000 up or up for grabs and this will be given to the best projects that I'll be on top of the safe it is an open Bounty so uh everything that is built on top of it will apply but we have some suggestions or ideas you can you can use for example having a sub-dial management tool right now subdials or daos like to have sub-dials with different uh funds and would be cool to have a tool that allows to do all the accounting thing for all of them just an idea improving the security with transaction guards anything like the deny list or the allow allow list everything you can think of also working with modules thinking for example on our family that shares an account and the different people have different kind of access to the funds different rights also anything related with account abstractions that you can think of another thing for example to create a chart where designers of the safe can interact or can chat with among themselves also a tool that allows a safe to publish official messages so anybody can read them and whatever you want so last thing you can find us on Discord at chat nurses minusafe.io our forum uh and also on Twitter at safe now I will show a QR code if you want to get your phones ready with a safe hackathon successful guide success guide and then we have some Learning Materials past workshops we did also pass hackathon projects and the winners so we can have some idea of what others build and also some general ideas like the ones you see with the safe modules transaction guards and safe apps so now take your time to scan it or take a picture of it otherwise we will be all the weekend in our booth so feel free to come share your idea with us and we will try to help okay and now some links that are also included in the in the guide for our GitHub the Safeguard SDK repo also the safe contracts repo or the Zodiac if you want to check some modules and guards and then some documentation so that's it thank you very much and good luck with the hackathon
Automatic transcript — names and jargon may be misspelled.