I'm reading the source here:
https://github.com/solana-labs/solana-program-library/blob/master/token/program/src/processor.rs
But my Rust is not so fluent right now.
Right around here:
match source_account.delegate {
COption::Some(ref delegate) if Self::cmp_pubkeys(authority_info.key, delegate) {...}
_ => Self::validateOwner(...stuff...&source_account.owner)
}
I see the delegate consulted.
It looks like, if the "authority_info" arg is set to "owner", then even if a "delegate" has been set on the account, the program will run the "owner is signer" assertion rather than the "delegate is signer" assertion. Meaning, that it appears that, the owner is always authorized to transfer tokens in any amount no matter what is delegated.
But, I'm kind of hoping I'm wrong here. In my case, it'd be ideal for the delegate to have exclusive rights over their delegated amount.
As an alternative for my use case, or a fallback to the "Delegate" having "exclusive rights" over the delegated amount, if the delegate were to be mentioned when the total amount on the account drops below the delegate amount, that may suffice.
A follow up "Plan B" question is, if transfer rights are not exclusive, are the delegates cleared when their delegated amount is transferred?
Which I think is technically, no. Because I think what happens is the source account is just depleted of token quantity. The delegate remains set on the account, and so does their delegate amount. There is just less quantity in the account for the delegate to potentially be granted further authority over. Possibly there is zero "amount" on the account, despite the "delegate amount" being greater than zero.
Although actually, if the non delegate (i.e. the owner) is allowed to transfer a quantity over which the delegate has authority ( i.e. transfer in excess of non delegated quantity ), shouldn't that subtract from the delegate's holdings even if the delegate is not the signer?
Or is it possible for the delegate to hold authority over more tokens than what are held by the account?