<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yatharthsriv on Medium]]></title>
        <description><![CDATA[Stories by Yatharthsriv on Medium]]></description>
        <link>https://medium.com/@yatharthsriv18?source=rss-710670d729c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*i1eUzKKLcdbaVCa-</url>
            <title>Stories by Yatharthsriv on Medium</title>
            <link>https://medium.com/@yatharthsriv18?source=rss-710670d729c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:53:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yatharthsriv18/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring Squads v0.1 Program on Solana]]></title>
            <link>https://medium.com/@yatharthsriv18/exploring-squads-v0-1-program-on-solana-906fc9671d5b?source=rss-710670d729c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/906fc9671d5b</guid>
            <category><![CDATA[anchor]]></category>
            <category><![CDATA[multisig]]></category>
            <category><![CDATA[solanas]]></category>
            <dc:creator><![CDATA[Yatharthsriv]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 21:34:39 GMT</pubDate>
            <atom:updated>2026-08-07T21:34:39.071Z</atom:updated>
            <content:encoded><![CDATA[<p>I tried to understand the Squads Smart Account Program v0.1 in anchor currently on Mainnet and Devnet on Solana . This is a brief explanation of that contract and how to navigate through it which can act as helping guide for anyone to understand it .</p><p>Recommended Approach : Open the blog and the lib.rs file side by side</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xsVDRyWlvtSJcnr_A5STCA.png" /><figcaption>A basic Representation of States</figcaption></figure><blockquote><strong>Relevant Links :</strong></blockquote><ol><li>Github Repo : <a href="https://github.com/Squads-Protocol/smart-account-program/">https://github.com/Squads-Protocol/smart-account-program/</a></li><li>Mainnet Address : SMRTzfY6DfH5ik3TKiyLFfXexV8uSG3d2UksSCYdunG</li></ol><blockquote><strong>Overview and Core Concepts</strong></blockquote><p>The main idea behind this smart contract is to make multisig and smart accounts easily accessible and provide a secured way to manage your finance .</p><p>Smart Accounts : programmable accounts that allow customization for every user and use case</p><blockquote><strong>Lets’s try to understand the Most Important Two State variable </strong>:</blockquote><blockquote><strong>Settings</strong></blockquote><p>brain of this program as it has all the relevant details about controlling your smart accounts</p><p>important_fields :</p><ol><li>settings_authority</li></ol><p>Now thier are two types of smart accounts : controlled smart account and autonomus</p><p>if the settings_authority a pubkey is present then this address becomes the main authority controlling everything changing spending limits, thresholds, signers making it a controlled smart account</p><p>if it’s <strong>Pubkey::Default</strong> it becomes autonomus making all the changes to be aapproved by signers</p><p>2. threshold : basically how many voting-permission signers needed to approve a proposal or a transaction multisigs</p><p>3. transaction_index : every transaction which gets created has an attached index</p><p>4. stale_transaction_index : All transaction uptill this point are stale , gets updated when settings change</p><p>5. signers : Signers Attached to the smart account ( multisig )</p><p>6. account_utilization : Counter of sub accounts</p><p>7. policy_seed : for deterministic policy creation</p><blockquote><strong><em>Policy</em></strong></blockquote><p>settings : ( the settings it belongs to )</p><p>seed: seed of policy</p><p>bump , transaction_index , stale_transaction_index ,</p><p>signers : Signers attached to the policy with their permissions ( this can be different from the signers in the settings PDA )</p><p>threshold : threshold for apporvals</p><p>time_lock : seconds must pass between approval and execution</p><p>policy_state : PolicyState ( enum )</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong>PolicyState </strong>{</p><blockquote><strong>InternalFundTransfer</strong> ( <em>source_account_mask</em> , <em>destination_account_mask</em> , <em>allowed_mints</em> )</blockquote><p>allows transfer of SOL and SPL tokens( of allowed mints ) btw set of source and destination address</p><blockquote><strong>SpendingLimit</strong>( <em>source_account_index </em>: <strong>u8</strong> , <em>destinations </em>: <strong>vec&lt;Pubkey&gt; </strong>, <em>spending_limit</em> ( <strong>SpendingLimitV2</strong> {</blockquote><p><strong>mint</strong> ( token for which this is ) , <strong>time_constraints</strong> ( start , expiration , period , accumulate_unused ) , <strong>quantity_constraints</strong> , <strong>usage</strong> ( remaining_in_period , last_reset )</p><blockquote><strong>SettingsChange</strong></blockquote><blockquote>ProgramInteraction : Program Interaction Policy ( ProgramInteractionPolicy )</blockquote><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>start : Timestamp when the policy becomes active</p><p>expiration</p><p>rent_collector</p><blockquote><strong>Let’s Get Started With Instructions :</strong></blockquote><p>Well thier are total 36 pub fn ( or instructions ignoring the deprecated or left to be implemented ones ) but if you mostly understand few important ones others become much easier</p><blockquote><strong>1. initialize_program_config</strong></blockquote><p>Args : authority , smart_account_creation_fee , treasury</p><p>the authority pubkey controls program configs , account creation charge and treasury is where this fees go to</p><p><strong>Context :</strong></p><p>program_config ( init , type ProgramConfig )</p><p>initializer ( to initialise the config once ) , system_program</p><p><strong>ProgramConfig</strong></p><ul><li>smart_account_index : Counter for smart accounts created</li><li>authority : which can update config</li><li>smart_account_creation_fee</li><li>treasury : where creation fees go to</li></ul><p><strong>Args To Be Given By User :</strong></p><ul><li>authority</li><li>smart_account_creation_fee</li><li>treasury</li></ul><p><strong>Impls</strong> : fn init_program_config</p><p>pretty simple fill in details the program_config account</p><blockquote><strong>Updating The ProgramConfig</strong></blockquote><p>Context : program_config ( mut ) , authority</p><p><strong>2. fn set_program_config_authority</strong></p><p>args: ProgramConfigSetAuthorityArgs ( new_authority )</p><p>impls : fn set_authority</p><p>program_config.authority = newauthority</p><p><strong>3. fn set_program_config_smart_account_creation_fee</strong></p><p>args: new_smart_account_creation_fee</p><p>impls : fn set_smart_account_creation_fee</p><p><strong>4. fn set_program_config_treasury</strong></p><p>args: ProgramConfigSetTreasuryArgs</p><p>impls : fn set_treasury</p><p>We are done with Initialising ProgramConfig and the relevant instructions to change its details now we move to creating smart accounts</p><p>Before we move ahead ,</p><p>Here is a mental model i came up with to understand the whole Structure of the sqauds smart account program</p><p>let say Apple comes on the platform they create a Settings Account</p><h4><strong>Apple Settings Account now for different purposes they can create accounts like for eg marketing account pda ( account index 0) which controls all the payments , spending limits related to do marketing expenses similar for salaries account pda ( account index 1) ….</strong></h4><blockquote><strong>5. create_smart_account ( creating the Settings PDA )</strong></blockquote><p>We create a Settings Pda in this instruction</p><p>args: settings_authority (None for autonomus ) , threshold,signers, timelock , rent_collector</p><p>Context : program_config( mut ) , treasury ( mut ) , creator</p><p>impls: fn create_smart_account</p><p>program_config , signers : we sort it out as we test for duplicates later on , settings_seed : is basically program config account index + 1 , settings_pubkey , settings_bump with find_program_address</p><p>seeds = [ SEED_PREFIX , SEED_SETTINGS , settings_seed ]</p><p>settings_configuration with all relevant data</p><p>we create the settings account with all data with helper fn <strong>find_and_initialize_settings_account</strong></p><p>we get settings_account_info from remaining_accounts , and perfrom some checks : 1. owner is system_program 2. is empty with no data 3. is writable basically mutable</p><p>then <strong>create_account via CPI to system_program</strong></p><blockquote><strong>Updating the Settings PDA data ( only for controlled smart accounts )</strong></blockquote><p><strong>6. add_signer_as_authority ( add a new signer )</strong></p><p>args: AddSignerArgs { new_signer: SmartAccountSigner }</p><p>Context : Settings( mut ) , settings_authority , rent_payer,</p><p>impls : fn add_signer</p><p>get signer , settings , check if it already exists , add signer to array , make sure enough space and then we update stale index to current txn index so that previous are all stale .</p><p>Log The Event ,</p><p><strong>7. remove_signer_as_authority</strong></p><p>Context: Same as add_signer</p><p>impls : fn remove_signer — -&gt; remove the signer update stale index</p><p><strong>8. set_time_lock_as_authority</strong></p><p>Context : same , impls : fn set_time_lock → update time_lock in settings , update stale index</p><p><strong>9. change_threshold_as_authority</strong></p><p>Context : same , impls : fn change_threshold → update threshold in settings , update stale index</p><p><strong>10. set_new_settings_authority_as_authority</strong></p><p>Context : same , impls : fn set_new_settings_authority → update settings authority in settings , update stale index</p><h3><strong>Till this point we are done with creating Settings PDA and also all the instructions to update its data we move ahead to working with accounts index which we talked about earlier marketing , salaries ….</strong></h3><blockquote><strong>11. add_spending_limit_as_authority</strong></blockquote><p>args :</p><p><strong>seed</strong> ( spendinglimit PDA ) , <strong>account_index</strong> ( index of smart account spending limit is for ) ,</p><p><strong>mint</strong> ( token mint spending limit is for ) , <strong>amount</strong> ( which can be sent in a period we define later in decimals of mint ) , <strong>period</strong> ( Period enum values OneTime , Day , Week , Month ) , <strong>signers</strong> ( the signers for this can be different from the settings signers ) , <strong>destinations</strong> ( the address where money can be sent to if empty can be sent to anyone ) , <strong>expiration</strong> ( i64:Max for no expiration )</p><p><strong>Context</strong> : <strong>settings</strong> , <strong>settings_authority</strong>, <strong>spending_limit</strong> ( init , seeds = [ SEED_PREFIX , settings.key , SEED_SPENDING_LIMIT , args.seed ] ) , <strong>rent_payer</strong></p><p>impls : add_spending_limit</p><p>get settings , spending_limit accounts, sort signers , fill in spending_limit pda with all details</p><p>log event authority</p><p><strong>12 . remove_spending_limit_as_authority</strong></p><p>settings , authortiy ,</p><p>spending_limit #[account(mut, close = rent_collector)] this runs at the end of impls implementation leading to closing the account</p><p>and eventually logging event in the impls</p><h4><strong>we can create spending limits PDA for different account indexes and update its details but only for controlled ones now come the autonomus ones we create txn with changes to be implemented in it , then we create proposal signers vote , if accepted txn executes</strong></h4><blockquote><strong>13. create_settings_transaction <em>( From Here on it is all about autonomous )</em></strong></blockquote><p><strong>args </strong>: actions : Vec&lt;SettingsAction&gt;</p><p><strong>SettingsTransaction :</strong></p><p>settings , creator ( Signer on settings who submitted the transaction ) , rent_collector , index ( txn index in settings ) , bump , actions (vector of SettingsAction ) )</p><p><strong>Context</strong> : <strong>settings</strong> , <strong>transaction</strong> ( init , seeds = [ SEED_PREFIX , settings.key SEED_TRANSACTION, settings.txn_index + 1 ] , type <strong>SettingsTransaction</strong> )</p><p><strong>impls</strong> : fn create_settings_transaction</p><p>settings , transaction , creator , rent_payer , settings_key , transaction_index( + 1 to settings.index ) , fill in the transaction details , update the index in settings ,</p><p>event logging Done !</p><h4>We have a transaction ready with the actions to be done now before executing we have to create a proposal assocated to this transaction and wait for voting , before that we understand few stuff before creating proposal</h4><blockquote><strong>consensus_account</strong> <em>( this is an interface account which can be Settings and Policy )</em></blockquote><p>basically with this we can use same function for both settings and policy changes which has impls for space and account derivations</p><blockquote><strong>Proposal State</strong> :<em> settings , transaction_index, rent_collector , status ( ProposalStatus enum ) , approved , rejected , cancelled ( vec &lt;Pubkey&gt; )</em></blockquote><blockquote><strong>enum ProposalStatus</strong><em> ( stage with timestamp when it happend )</em></blockquote><p>Draft , Active , Rejected , Approved , Executed , Cancelled</p><blockquote><strong>cutoff <em>( Fn. in interface/consensus_trait.rs )</em></strong></blockquote><p>this is used to calculate the number of signers required to reject a proposal in such a way thier is no way for remaining voters to reach the approval threshold eg: total voters = 7, threshold = 3, cutoff = 5</p><blockquote><strong>14. create_proposal</strong></blockquote><p><strong>args</strong>: <strong>transaction_index</strong> ( index of smart account transaction this proposal belongs to ) , <strong>draft</strong> ( bool , if it should be initialised as Draft )</p><p><strong>Context</strong> : consensus_account , proposal ( init , type Proposal, seeds = [SEED_PREFIX, consensus_account.key , SEED_TRANSACTION , args.trx_index , SEED_PROPOSAL ] ), creator , rent_payer</p><p><strong>impls : fn create_proposal</strong></p><p>proposal , consensus_account , rent_payer , fill in proposal with details ,</p><p>log the event</p><p><strong>15 . activate_proposal </strong>( Update status of a smart account proposal from `Draft` to `Active` )</p><p><strong>Context</strong>: settings , signer , proposal</p><p><strong>impl</strong> : <strong>fn activate_proposal</strong> ( proposal.status se to Active with timestamp )</p><p><strong>16. approve_proposal</strong> ( The proposal must be Active for a member to approve )</p><p><strong>Context: </strong>consensus_account , signer , proposal</p><p>impls : fn approve_proposal ( consensus_account , proposal , signer )</p><p>then we go to .approve which gets the signer key and threshold from the consensus account in this fn basically in this first we remove any vote signer did previously , add it to approved array and then if</p><p>current number of approvals reahces threshold Proposal Status Approved with timestamp</p><p><strong>17 . reject_proposal </strong>( same the proposal should already be active )</p><p><strong>Context: same</strong></p><p>impls : consensus_account , signer , proposal and <strong>cutoff</strong></p><p>we go to .reject fn in which similarly we remove any previous vote and it to rejected array if the length reahces cutoff mark the Proposal as Rejected with timestamp</p><p><strong>18. cancel_proposal ( </strong>The proposal must be Approved )</p><p>Context : same</p><p>impls : consensus_account , signer , proposal</p><blockquote><em>then go to .cancel add it to .cancelled vector and if it reaches threshold mark it as Status:Cancelled with timestamp</em></blockquote><p>event and log</p><blockquote><strong>19. execute_settings_transaction ( the transaction should be approved )</strong></blockquote><p><strong>Context</strong> : <strong>settings</strong> , <strong>signer</strong> ( the signer on smart account executing txn ) , <strong>proposal</strong> , <strong>transaction</strong> , <strong>rent_payer</strong> ( now maybe we have to allocate more space to spendinglimit pda that is why we need this ) ,</p><p>now if it contains actions like add or remove spendinglimit user should provide spendinglimit account in remaining_accounts</p><p><strong>impls</strong> : <strong>execute_settings_transaction</strong></p><p>settings , settings_key , transaction , proposal , rent</p><p>Execute actions one by one they call <strong>fn modify_with_action</strong></p><blockquote><strong><em>SettingsAction::AddSigner</em></strong><em> : add signer , sort , stale index update</em></blockquote><blockquote><strong><em>SettingsAction::RemoveSigner</em></strong><em> : signer index , remove, stale index update</em></blockquote><blockquote><strong><em>SettingsAction::ChangeThreshold</em></strong><em>: update , stale index update</em></blockquote><blockquote><strong><em>SettingsAction::SetTimeLock</em></strong><em>: update , stale index update</em></blockquote><blockquote><strong><em>SettingsAction::AddSpendingLimit</em></strong><em> :</em></blockquote><blockquote><em>we find the key and bump of SpendingLimitPda , we get </em><strong><em>spending_limit_info , rent_payer , system_program</em></strong><em> all these come from </em><strong><em>remaining_accounts</em></strong><em> so they need to be given otherwise we report errors</em></blockquote><blockquote><em>then we use create_account to create account via CPI to systemprogram</em></blockquote><blockquote><em>Now we have the empty spendinglimit PDA we create the spendinglimit details and serialize it in the PDA</em></blockquote><blockquote><strong><em>SettingsAction::RemoveSpendingLimit</em></strong><em> :</em></blockquote><blockquote><strong><em>spending_limit_info , rent_payer </em></strong><em>all these come from </em><strong><em>remaining_accounts </em></strong><em>then we deserialise the spending_limit_info to SpendingLimit so that we can read the data if you do not do this it is still raw no access to data</em></blockquote><p>.close () fn coming ultimately from crate::common::close ( Transfer SOL from the account to the sol_destination ) we transfer the lamports and also make the owner of this account as system program</p><blockquote><strong><em>SettingsAction:: </em></strong>PolicyCreate :</blockquote><p>Before we understand this now we actually create Policies till now we just talked about Settings PDA and probably sometimes in the explaination of consensus account interface Policies came up but now we will create policies some relevant enums or structs :</p><p>— — — — — -</p><p>enum <strong>PolicyCreationPayload</strong> — →&gt; enum for all policy creation payloads to specify which policy to create</p><p>— — — — — -</p><p>Increment the ploicy seed , policy_pubkey , bump , policy_info ( from remaining_accounts ) , size ( for rellocation ) , create_account( simialr function ) , policy_state ( as per the enum matching ) , expiration , create policy state , serialize, log the event</p><blockquote><strong><em>SettingsAction:: </em></strong>PolicyUpdate:</blockquote><p>policy_info , policy_size , state , expiration , .update_state , allocate space accordingly , log the event</p><blockquote>SettingsAction::PolicyRemove ( pubkey of the policy ) :</blockquote><p>policy info from remaining_accounts , rent_collector , and again the same .close () fn to close the account transfer ownership and lamports</p><p>DONE phew !!</p><h4><strong>Now changes for autonomus accounts are also done</strong></h4><p>some structs before goingf further</p><blockquote><strong><em>Transaction</em></strong><em> ( </em><strong><em>consensus_account</em></strong><em> , </em><strong><em>creator</em></strong><em> ( signer of smart account submitted txn ) , </em><strong><em>rent_collector</em></strong><em> , </em><strong><em>index</em></strong><em> , </em><strong><em>payload ( struct TransactionPayload )</em></strong></blockquote><blockquote><strong><em>TransactionPayload</em></strong><em> ( account_index , ephemeral_signers , transaction_message )</em></blockquote><p><strong>TransactionMessage</strong></p><p><strong>num_signers</strong> ( no. of signer pubkeys in the account_keys vec ) , <strong>num_writable_signers</strong> ( number of writable signer pubkeys in the account_keys vec ) , <strong>num_writable_non_signers</strong> ( writable non signer ) , <strong>account_keys</strong> ( unique account keys and program ids used ) , <strong>instructions</strong> ( list of instructions to execute type <strong><em>CompiledInstruction</em></strong> ) , <strong>address_table_lookups</strong> ( type <strong><em>MessageAddressTableLookup</em></strong>)</p><blockquote><strong><em>CompiledInstruction</em></strong><em> ( </em><strong><em>program_id_index</em></strong><em> , </em><strong><em>account_indexes</em></strong><em> ( indexes in account_keys list which accounts to pass in this instru. ) , </em><strong><em>data</em></strong></blockquote><blockquote><strong><em>MessageAddressTableLookup</em></strong><em> ( </em><strong><em>account_key</em></strong><em> ( address table key ) , </em><strong><em>writable_indexes</em></strong><em> , </em><strong><em>readonly_indexes</em></strong><em> )</em></blockquote><blockquote><strong><em>SmartAccountTransactionMessage</em></strong><em> ( num_signers , num_writable_signers , num_writable_non_signers , </em><strong><em>account_keys </em></strong><em>, </em><strong><em>instructions</em></strong><em> , </em><strong><em>address_table_lookups</em></strong></blockquote><p><strong>account_keys</strong> : vector of Pubkeys in a particular order</p><blockquote><em>writeable signers — non writeable signers — — writeable non-signers — — non-writable non-signers</em></blockquote><p><strong>instructions</strong> : vector of struct <strong>SmartAccountCompiledInstruction</strong></p><blockquote><strong><em>SmartAccountCompiledInstruction { </em></strong><em>program_id_index , account_indexes ( accounts to pass indexes vec u8 ) , data ( instruction data vec u8 )</em></blockquote><p>address_table_lookups : vector of struct <strong>SmartAccountMessageAddressTableLookup</strong></p><blockquote><strong><em>SmartAccountMessageAddressTableLookup { </em></strong><em>account_key ( ALT key ) , writable_indexes ( list of indexes to load writable accounts ) , readonly_indexes ( list of indexes to load readonly accounts )</em></blockquote><blockquote><strong><em>20. create_transaction ( Create a new vault transaction )</em></strong></blockquote><p><strong>Context</strong> : consensus_account , transaction , creator , rent_payer</p><p><strong>impls : create_transaction</strong></p><p>consensus_account , transaction , creator , rent_payer , transaction_key , transaction_index <strong>( incremented by + 1 ) fill in the transaction fields ,</strong></p><p>now it can be <strong>Settings PDA + TransactionPayload</strong> or <strong>Policy PDA + PolicyPayload </strong>based on that matching happens</p><p>transaction_message_parsed from vec&lt;u8&gt; to struct of TransactionMessage then we store ephemeral_signer_bumps with seeds = [ SEED_PREFIX , transaction_key , SEED_EPHEMERAL_SIGNER , ephemeralsigner_index]</p><p>then we fill transaction.payload= account_index, ephermial_bumps, message</p><p>In a nutshell we create a transaction account ( struct Transaction ) with details about account_index to which it belongs Settings or Policy and payload ( what it is supposed to do , struct type accordingly )</p><p>update the transaction index in consensus account ,</p><p>log event</p><h4>Now we created this transaction next the proposal gets created like the settings changes we discussed about accepted rejected cancelled if accepted we move to executing transaction</h4><blockquote><strong><em>21</em></strong><em>. </em><strong><em>execute_transaction</em></strong><em> ( Execute a smart account transaction also it should be approved )</em></blockquote><p>Context : consensus_account , proposal ( assocaited with this transaction ) , transaction ( to execute which we created earlier ) , signer, program</p><p>remaining_accounts : ( required for execution ) in the order</p><p>For transaction :</p><p>1 . AddressLookupTable accounts in order of message.address_table_lookups</p><p>2. Accounts in order in as message.account_keys</p><p>3. Accounts in order in as message.address_table_lookups</p><p><strong>impls</strong> : fn <strong>execute_transaction</strong></p><p>consensus_account , proposal , transaction</p><p>match account_type , transaction_payload , smart_account_seeds = [ SEED_PREFIX , consensusaccount.key , SEED_SMART_ACCOUNT , transaction.payload.account_index ]</p><p>we get pubkey and bump of smart account , create array of smart_account_signer_seeds to sign .</p><p>num_lookups ( number of address lookup table ) , message_account_infos ( store accounts from num_lookups to end from remianing_accounts ) , address_lookup_table_account_infos ( store accounts from 0 to num_lookups from remianing_accounts )</p><p>then we derive the <strong>ephermal_keys</strong> and and <strong>seeds for signing </strong>derived tuple from the fn <strong>derive_ephemeral_signers </strong>takes t<strong>ransaction.key</strong> and the <strong>bumps array</strong> we created .</p><p>explanation : Vec&lt;Vec&lt;Vec&lt;u8&gt;&gt;&gt; means a list of signers each signer has seeds and each seeds is a byte</p><p>Now we create a executable message basically verify the transactionMessage signers non signer readable writable were sent correctly by client</p><p>struct <strong>ExecutableTransactionMessage</strong> { message , static_accounts ( account_keys of the message ) , loaded_writable_accounts ( resolved writable accounts from the indexes from ALT ) , loaded_readonly_accounts ( resolved readable accounts from the indexes from ALT )</p><p>then .executable_message() executes one by one</p><p>this fn recieves :</p><p>smart_account_seeds for main smart account PDA and signing</p><p>ephemeral_signer_seeds : Seeds for temporary PDA signers, if this transaction needs extra signer PDAs</p><p>protected_accounts : Accounts that must not be writable during inner calls. in this we protect accounts like the proposal one account from being modified by inner instructions.</p><p>then , change the seed format to send to invoke_signed , ix: is the actual instruction and account_infos : are the writable accounts making sure protected account are not given in to this</p><p>then we do do cpi call to run that transaction with invoke_signed</p><p>Done phew !</p><h4>Now For buffer the logic to make sure that all relevant buffer transactions are together for a particular transaction is to store the final hash ( fixed 32 byte size ) and then when the buffer after getting extended and then calculate the hash match it with final hash and boom verified execute</h4><p><strong>relevant</strong> <strong>state</strong> : <strong>TransactionBuffer</strong> { settings , creator , buffer_index , account_index , final_buffer_hash , final_buffer_size , buffer }</p><blockquote><strong>22. create_transaction_buffer ( when the create_transaction transaction bytes are too long for one go we can upload in parts )</strong></blockquote><p><strong>args</strong> : <strong>CreateTransactionBufferArgs</strong> { buffer_index ( index of buffer account ) , account_index ( to which it belongs ) , final_buffer_hash ( hash of final assembeld trxn message ) , final_buffer_size , buffer }</p><p>Context : CreateTransactionBuffer</p><p>consensus_account , transaction_buffer ( init , seeds = [ SEED_PREFIX , consensus_account.key , SEED_TRANSACTION_BUFFER , creator.key , args.buffer_index ] )</p><p><strong>impls</strong> : fn <strong>create_transaction_buffer</strong></p><p>get transaction_buffer , consensus_account , creator , buffer_index , fill in the details of transaction_buffer</p><blockquote><strong><em>23. extend_transaction_buffer ( </em></strong>Extend a transaction buffer account )</blockquote><p><strong>args</strong> : <strong>ExtendTransactionBufferArgs</strong> { buffer } the buffer to extend</p><p><strong>Context</strong> : <strong>ExtendTransactionBuffer</strong> { consensus_account , transaction_buffer ( only the creator can extend ) , creator }</p><p>impls : extend_transaction_buffer</p><p>transaction_buffer , buffer_slice_extension ( args.buffer ) , transaction_buffer.buffer.extend ..</p><blockquote><strong><em>24. close_transaction_buffer ( </em></strong>Close a transaction buffer account )</blockquote><p>Context : CloseTransactionBuffer { consensus_account , transaction_buffer ( close , only by creator who created it )</p><p>Now when we are done with creating buffers we can create a transaction with them to be further executed</p><blockquote><strong><em>25. create_transaction_from_buffer </em></strong>( new vault txn from a completed txn buffer ) ( This is only for Settings as policy changes are matched to give errors )</blockquote><p>args: Remain same as <strong><em>create_transaction ( 20 )</em></strong></p><p>Context : <strong>CreateTransactionFromBuffer { </strong>transaction_create ( <strong>CreateTransaction</strong> ) , transaction_buffer ( only the creator can create a vault txn from buffer ) , creator</p><p><strong>impls</strong> : <strong>validate</strong> ( in this we check that the final hash after extending the transaction_buffer is equivalent to the final hash we stored while creating the transaction buffer and also the size so that nothing remains incomplete )</p><p><strong>impls</strong> : <strong>create_transaction_from_buffer ( </strong>Create a new Transaction from a completed transaction buffer account )</p><p>transaction_account_info , rent_payer_account_info , transaction_buffer , calculate size as initally transaction account was empty , get the rent lamports , transfer the lamports required , space relocation ,</p><p>then we create args and context to call <strong>create_transaction</strong></p><p>Done !!</p><blockquote><strong><em>26. create_batch</em></strong></blockquote><p>struct Batch { settings , creator, rent_collector , index ( within smart account txns ) , bump , account_index , account_bump , size ( no. of txns in batch ) , executed_transaction_index ( 0 if none executed yet )</p><p>args : CreateBatchArgs{ account_index ( index of smart account this belongs to ) }</p><p>Context : CreateBatch { settings , batch ( init , seeds = [ SEED_PREFIX , settings.key , SEED_TRANSACTION , settings.txn_index + 1 ] ) , creator , rent_payer }</p><p>impls : fn create_batch</p><p>settings , creator , batch , rent_payer , settings_key , increment the txn index , get smart_account seeds publick key , bump , fill in details of batch , update settings.txn_index by 1</p><blockquote><strong><em>27. add_transaction_to_batch ( </em></strong>Add a transaction to the batch )</blockquote><p><strong>relevant</strong> <strong>state</strong> : <strong>BatchTransaction</strong> { bump , rent_collector , ephemeral_signer_bumps ( vector of bumps ) , message ( struct <strong>SmartAccountTransactionMessage</strong> )</p><p><strong>Context</strong> : AddTransactionToBatch</p><p>settings , proposal ( assocaited to the batch ) , batch , transaction ( BatchTransaction` account to initialize and add to the batch , init , seeds = [ SEED_PREFIX , settings.key , SEED_TRANSACTION , batch.index , SEED_BATCH_TRANSACTION , batch.size + 1 ]</p><p>impls : add_transaction_to_batch</p><p>batch , transaction , rent_payer , batch.key , transaction_message( struct TransactionMessage , ephemeral_signer_bumps ( vector of bumps from ephermal_signers ) , fill in transaction details , increase batch.size + 1</p><h4>Now we have batch , add #1 , add #2 create proposal( one whole proposal for the whole batch not for each batch txn ) , approve proposal , and then we move to executing #1 and then #2 one by one</h4><blockquote><strong><em>28. execute_batch_transaction</em></strong> <strong><em>( </em></strong>Execute a transaction from the batch)</blockquote><p><strong>Context</strong> : ExecuteBatchTransaction</p><p>settings , signer, proposal ( proposal account associated with the batch , If `<strong>transaction</strong>` is the last in the batch, the `<strong>proposal</strong>` status will be set to `<strong>Executed</strong> ) , batch , transaction ( Batch transaction to execute we use batch.executed_transaction_index.checked_add(1) this to make sure txn gets implemented in order )</p><p>remaining_accounts : order</p><p>AddressLookupTable accounts in the order they appear in `message.address_table_lookups` , Accounts in the order they appear in `message.account_keys` ,</p><p><strong>impls</strong> : fn <strong>execute_batch_transaction</strong></p><p>settings , proposal , batch , then we get transaction ( Batch Transaction but point to be noted here is with .take() the ctx.accounts.transaction data is now default data so we only use transaction from here on ) , settings_key , batch_key , smart_account_seeds ( for the smart account PDA ) , num_lookups , message_account_infos , address_lookup_table_account_infos , smart_account_pubkey</p><p>with derive_ephemeral_signers we get a tuple of ( ephemeral_signer_keys , ephemeral_signer_seeds ) , and then the similar process create a executable message , on this executable mesage we all</p><p><strong>execute_message</strong> : ephemeral_signer_seeds , signer_seeds with smart_Account_seeds as well</p><ol><li>convert PDA seed vectors into invoke_signed format<br>2. add smart account signer seeds<br>3. convert compiled instructions into real Solana Instructions<br>4. check protected accounts are not writable<br>5. block calls to Squads log_event<br>6. call each instruction with invoke_signed</li></ol><p>if the batch transaction message has 3 inner instructions all 3 are CPI-called , increase the index of executed ones in the batch .</p><p>And finally if the batch.executionindex= batch.size that means whole batch is implemented set proposal status to Executed</p><p>Done !! phew</p><blockquote><strong><em>29 . close_settings_transaction ( </em></strong>Closes a `SettingsTransaction` and the corresponding `Proposal )</blockquote><p>when it can be closed :</p><p>the `proposal` is stale</p><p>the proposal state is Executed , Cancelled , Rejected</p><p><strong>Context</strong> : <strong>CloseSettingsTransaction</strong> { settings , proposal , transaction ( corresponding to the proposal ) , transaction_rent_collector , proposal_rent_collector }</p><p><strong>impls</strong> : fn <strong>close_settings_transaction</strong></p><p>settings , transaction , proposal , proposal_Rent_collector , is_stale ( transaction.index is less or equal to settings.stale index ) , proposal_account ,</p><p>can_close : bool ( Draft Proposals , Active , Approved can be closed only if stale ) ( Rejected , Executed , Cancelled can be closed )</p><p>close Proposal impls fn close_if_exists ( with utils::close )</p><blockquote><strong><em>30 . close_transaction</em></strong> <strong><em>( </em></strong>Closes a `Transaction` and the corresponding `Proposal )</blockquote><p>when it can be closed :</p><p>the `proposal` is stale</p><p>the proposal state is Executed , Cancelled , Rejected</p><p>Context : CloseTransaction</p><p>consensus_account , proposal , transaction ( corresponding to proposal ) , proposal_rent_collector , transaction_rent_collector</p><p>impls : close_transaction { we check is_stale true or false , as per :</p><p>transaction.index &lt; = stale_index</p><p>now as per proposal_status ( if Draft , Active then it depends on is_stale if it is true we close otherwise if Approved then no we can’t close else Rejected Cancelled or Executed yes we can close )</p><p>Done !!</p><blockquote><strong><em>31 . close_empty_policy_transaction</em></strong> <strong><em>( </em></strong>Closes a `Transaction` and the corresponding `Proposal for empty/deleted policies )</blockquote><p>As policies can never be on same address ( seed stored in policy struct ) , we can safely remove txn or proposal linked to it</p><p>we mostly check is the policyaccount empty and is owned by system program if yes then we can safely close everything</p><blockquote><strong><em>32 . close_batch_transaction</em></strong> <strong><em>(</em></strong>Closes a `BatchTransaction` belonging to the `batch` and `proposal` )</blockquote><p>transaction can be closed : transaction must be the current last transaction in the batch, proposal must be terminal or stale-but-not-approved</p><p>make sure to decrease batch size as well as when batch size becomes zero we can close the batch as well</p><blockquote><strong><em>33 . close_batch</em></strong> <strong><em>( </em></strong>Closes Batch and the corresponding Proposal accounts for proposals)</blockquote><p>batch.size needs to be zero</p><p>batch.index &lt; = settings.stale_index</p><p>now as per proposal_status ( if Draft , Active then it depends on is_stale if it is true we close otherwise if Approved then no we can’t close else Rejected Cancelled or Executed yes we can close )</p><h4>Now if we do not want to go through the path of proposal creation approval wait and then excute and if we have enough signers we can execute transactions synchronously</h4><blockquote><strong><em>34. execute_transaction_sync_v2</em></strong></blockquote><p>sync execution requires time_lock == 0, and the first num_signers remaining accounts must actually sign and satisfy threshold/permissions.</p><p>args : SyncTransactionArgs { account_index , num_signers( required to reach threshold in reminaing accounts ) , payload ( SyncPayload { Transaction , Policy ) }</p><p>Context : consensus_account , program ,</p><p>remaining_accounts order : 1. exact amount of signers to reach threshold , 2. remaining accounts associated with the instructions 3. remaining accounts associated with the policy ( policy execution with settings_Account )</p><p>impls : sync_transaction {</p><p>consensus_account , remaining_accounts( slice with removed signers ) , matching account type</p><p>if ( Settings ) : payload , settings ( from consensus account ) , settings_key ,</p><p>CompiledInstrucitons ( Concise serialization schema for instructions that make up transaction : program_id_index, account_indexes ( indicating which accounts to pass to the instruction ) , data )</p><p>smart account seeds , smartaccount pubkey and bump derived ,</p><p>form the executable_message : SynchronousTransactionMessage { instructions and accounts }</p><p>run the executablemessage in the same way with .execute</p><p>creates each Solana instruction, calls invoke_signed</p><p>Log , event done</p><blockquote><strong><em>35. execute_settings_transaction_sync</em></strong><em> </em><strong><em>( </em></strong><em>Synchronously execute a config transaction )</em></blockquote><p>Sync settings transaction is only for autonomous smart accounts.</p><p>if enough valid signers with permissions are present right now in this same Solana transaction, apply the settings changes immediately</p><p>rahter than whole process of proposal creation ….</p><p>then we simply modify with actions with fn modify_with_action</p><p>as dicussed in the <strong>execute_settings_transaction allocate space</strong></p><p>log and event Done !!</p><blockquote><strong><em>36 . log_event</em></strong></blockquote><p>The logging of event we have doing it is mostly called by the instrucitons at the end of thier implementations</p><p>only allowed Squads-owned account types can act as log authority checked by their account discriminators as per ALLOWED_DISCRIMINATORS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*csimztmbddtXQMUebbLzDQ.png" /></figure><blockquote><strong>Constants</strong></blockquote><ol><li>SEED_PREFIX = b”smart_account”</li><li>SEED_PROGRAM_CONFIG = b“program_config”</li><li>SEED_SETTINGS = b”settings”</li><li>SEED_SPENDING_LIMIT = b“spending_limit”</li><li>SEED_PROPOSAL = b”proposal”</li><li>SEED_EPHEMERAL_SIGNER = b”ephemeral_signer”</li><li>SEED_SMART_ACCOUNT = b”smart_account”</li><li>SEED_TRANSACTION= b”transaction”</li><li>SEED_BATCH_TRANSACTION = b”batch_transaction”</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=906fc9671d5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>