Search code examples
solanaanchor-solana

What's "ATA" mean in Solana/Anchor?


Noticed this code comment in an Anchor test:

enter image description here

What's the ATA stand for there and why does it matter for DAO controlled authorities?


Solution

  • ATA is an associated token address.

    Associated token addresses can be derived from another public key using findProgramAddress.

    function getAssociatedTokenAddress(
        mint: PublicKey,
        owner: PublicKey,
        allowOwnerOffCurve = false,
        programId = TOKEN_PROGRAM_ID,
        associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
    ): Promise<PublicKey> {
        if (!allowOwnerOffCurve && !PublicKey.isOnCurve(owner.toBuffer())) throw new TokenOwnerOffCurveError();
    
        const [address] = await PublicKey.findProgramAddress(
            [owner.toBuffer(), programId.toBuffer(), mint.toBuffer()],
            associatedTokenProgramId
        );
    
        return address;
    }
    

    There is another type of token account that predates the associated token account, an ancillary token account. These legacy accounts still exist and can be created today.

    The reason that the code says it can be either ATA or something else is because it is validating that the account is a token account that it expects.