Skip to content

feat: AuthorizationLock implementation#35

Open
tracy-codes wants to merge 15 commits intomainfrom
tracy/auth-lock
Open

feat: AuthorizationLock implementation#35
tracy-codes wants to merge 15 commits intomainfrom
tracy/auth-lock

Conversation

@tracy-codes
Copy link
Contributor

@tracy-codes tracy-codes commented Jun 7, 2025

More optimal implementation of AuthorizationLock concept.

  • Adds AuthorizationLock which is stored at the end of a swig's account data always
  • ManageAuthorizationLock and All permissions can add AuthorizationLocks on an account
  • Roles can only remove AuthorizationLocks they added manually
  • AuthorizationLocks are automatically removed once expired
  • AuthorizationLock holds a specific mint and amount in the wallet until it expires or the role is ready to spend the authorized amount
  • AuthorizationLocks are additive if there are multiple for a single mint
  • AuthorizationLocks respect all TokenLimit, RecurringTokenLimit, SolLimit, RecurringSolLimit on the role that is adding the AuthorizationLock. Meaning, a role can't lock up more tokens than what they're allowed access to.
  • Incorporates latest changes pushed to main since feat: AuthorizationLock #30

@tracy-codes tracy-codes requested a review from austbot June 7, 2025 03:04
@tracy-codes tracy-codes changed the title Tracy/auth lock feat: AuthorizationLock implementation Jun 7, 2025
// cursor positions
msg!("role: {:?}", role.unwrap().get_all_actions());
let (swig_header, swig_roles) = unsafe { swig_account_data.split_at_mut_unchecked(Swig::LEN) };
let swig = unsafe { Swig::load_mut_unchecked(swig_header)? };
Copy link
Contributor

Choose a reason for hiding this comment

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

you are doing double work, loading with roles and also doing the load_mut, you can consolidate to one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're so right here thank you for this callout

}

// Authentication and permission checking
let swig_with_roles = SwigWithRoles::from_bytes(&swig_account_data).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

SwigWithRoles is meant to be a helper for off chain usage, its slow on chain remove please see next comments


// Get existing authorization locks for this role using a smaller array to avoid
// stack overflow
const MAX_LOCKS: usize = 10; // Smaller bound to prevent stack overflow
Copy link
Contributor

Choose a reason for hiding this comment

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

man I would love to be able to increase this. do we have any data to suggest a user may only need 10 concurrent locks. looking at my credit card statement it would be very rare, but imagining businesses would need more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I just set it arbitrarily here. We can crank this up, maybe even not have a limit? I think it's more sensible to have a limit but can also experiment to see what seems better

)?;

// Re-borrow data after authentication
let swig_account_data = unsafe { ctx.accounts.swig.borrow_mut_data_unchecked() };
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like its following the SwigBuilder pattern like in add authority

let lock_slice = &mut swig_account_data[new_lock_offset..new_lock_offset + new_lock_size];
let new_lock = unsafe { &mut *(lock_slice.as_mut_ptr() as *mut AuthorizationLock) };

// Initialize the lock fields directly in memory
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can encapsulate this in swig builder

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