Skip to content

feat: multiple subaccounts per role#124

Open
tracy-codes wants to merge 9 commits intomainfrom
tracy/multiple-subaccounts
Open

feat: multiple subaccounts per role#124
tracy-codes wants to merge 9 commits intomainfrom
tracy/multiple-subaccounts

Conversation

@tracy-codes
Copy link
Contributor

@tracy-codes tracy-codes commented Dec 11, 2025

problem

You can only have one SubAccount per role

solution

Use one byte of padding on the SubAccount to allow for setting a specific index that can be used as part of the PDA seed so one role can have multiple subaccounts.

Typescript sdk updates:anagrambuild/swig-ts#85
Docs updates: anagrambuild/swig-docs#16

Copy link
Contributor

@austbot austbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good just some questions on perf and reusability of code and some of the iterations you are doing

let mut cursor = 0;
let end_pos = role.actions.len();

while cursor < end_pos {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this while loop nonsense instead of Role get action or rolueMut::get_Action_mut

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally forgot about match_data / get_action_mut. updated here: 0d781c7#diff-271f9fd294483735c02257851e36ba7f48044df12711a853368a45838c332737R285

)?;

// Find the SubAccount action for this specific index
// We need custom logic to match by index since multiple SubAccount actions may
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this matter, does a sub account have permissions now?

I think as long as the role ha ssub account you can terminate at the first one.

Ah i see what you are doing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may behove us to make action interface also have a match fn so we can iterate with predicate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the match_data impl to allow for matching based on a specific index: 0d781c7#diff-51332229da15082ffb7cbdff13008826a473567758857466f5c4d53244a42e56R119

///
/// # Returns
/// * `Result<(), ProgramError>` - Ok if no duplicates, error otherwise
fn validate_no_duplicate_sub_account_indices(actions_data: &[u8]) -> Result<(), ProgramError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be used in create aswell?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -189,29 +200,97 @@ pub fn withdraw_from_sub_account_v1(
if !action.enabled {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we should be able to disable and then withdraw as the authority

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to allow for withdraw from subaccount when disabled: 0d781c7#diff-64d13480044b74ce5b687ca18234ae948b058d8ed1fc657f72bd8279c5b9410bR191-R195

);
return Err(SwigAuthenticateError::PermissionDeniedMissingPermission.into());
} else if all_action.is_some() {
// All permission: Search all roles to find which one has the SubAccount action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to iterate over all roles not just the current chekcing for subaccount and manage or all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to get the subaccount's index since it's part of the signer seeds, which is stored on the SubAccount action. We could add it as an optional arg where it defaults to 0 unless specified otherwise. let me know what you think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants