Fetch and query a delegates for user accounts on Drift v2 Program .
A Delegate is an address that can control an account on the user's behalf. The delegated user (public key) although has limited power, can perform most operations on the account except for withdrawals. To find delegated users on Drift Protocol, we need to query the delegate field in the drift_User account.
You can directly copy paste this code on replit and see it in action.
The response contains authority and delegate which indicates the account owner and the delegated account, more fields can also be cherrypicked as per your requirement.
You can also query the delegate account for a particular user account or authority, using the following query
query MyQuery { drift_User( where: {authority: {_eq:"AUYs3A9gMLn5tqySAQ4Sqea8PB5sWAXmgZGz8GBerYE3"}} ) { //replace with the user/authority wallet which you want to query status pubkey authority delegate }}