Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

A user revokes their subscription authority

Source: subscriptions/tests/test_revoke_subscription_authority.rs L92

  • When: the user initializes a subscription authority
  • Then: the ATA is delegated before revoke ✓
  • Then: the ATA is delegated for the full amount ✓
  • When: the user revokes the subscription authority
  • Then: Alice revokes her subscription authority ✓
  • Then: the delegate is cleared after revoke ✓
  • Then: the delegated amount is zeroed after revoke ✓

Result: ✓ success — 7978 CU · claims 5/5 ✓

sequenceDiagram
    participant p0 as alice
    participant p1 as Subscriptions
    participant p2 as token
    p0->>p1: revokeSubscriptionAuthority
    activate p1
    p1->>p2: revoke
    activate p2
    p2-->>p1: ✓ 108cu
    deactivate p2
    p1-->>p0: ✓ 7978cu
    deactivate p1

Authority

flowchart LR
    Subscriptions["Subscriptions"]:::program
    alice(["alice"]):::signer
    aliceATAMint[("alice/ATA(Mint)")]:::state
    SAaliceMint[("SA(alice, Mint)")]:::state
    token["token"]:::program
    alice -->|signs| Subscriptions
    Subscriptions -->|writes| aliceATAMint
    Subscriptions -->|writes| SAaliceMint
    token -->|writes| aliceATAMint
    alice -->|signs| token
    classDef program fill:#dae8fc,stroke:#6c8ebf;
    classDef signer fill:#d5e8d4,stroke:#82b366;
    classDef state fill:#ffe6cc,stroke:#d79b00;

Ownership

flowchart LR
    system["system"]:::program
    alice[("alice")]:::state
    token["token"]:::program
    aliceATAMint[("alice/ATA(Mint)")]:::state
    SAaliceMint[("SA(alice, Mint)")]:::state
    system -->|owns| alice
    token -->|owns| aliceATAMint
    system -->|owns| SAaliceMint
    classDef program fill:#dae8fc,stroke:#6c8ebf;
    classDef signer fill:#d5e8d4,stroke:#82b366;
    classDef state fill:#ffe6cc,stroke:#d79b00;

Accounts

AccountSignerWritableOwner
alicesystem
alice/ATA(Mint)·token
Mint··token
token··BPFL…
SA(alice, Mint)·system
Call tree and logs
A user revokes their subscription authority
alice (7978cu)
└─ Subscriptions::revokeSubscriptionAuthority ✓ 7978cu
   └─ token::revoke ✓ 108cu
Program De1egAFMkMWZSN5rYXRj9CAdheBamobVNubTsi9avR44 invoke [1]
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 108 of 193853 compute units
Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success
Program De1egAFMkMWZSN5rYXRj9CAdheBamobVNubTsi9avR44 consumed 7978 of 200000 compute units
Program De1egAFMkMWZSN5rYXRj9CAdheBamobVNubTsi9avR44 success

Integration

What an integrator writes: the derivations and the instruction, byte-identical to the transaction this page witnessed. Addresses are this scenario’s; supply your own.

#![allow(unused)]
fn main() {
use solana_instruction::{AccountMeta, Instruction};
use solana_pubkey::{pubkey, Pubkey};

// --- revokeSubscriptionAuthority ---
let program_id: Pubkey = pubkey!("De1egAFMkMWZSN5rYXRj9CAdheBamobVNubTsi9avR44");
let user: Pubkey = pubkey!("2rj1EEgg32bupe12mMYnPFaKQCPPyYBhKYmDFZ8cXxpT"); // alice: this scenario's value; supply your own
let user_ata: Pubkey = pubkey!("3fVRopUs1BsF6RqteSmcyctBCx2YQ6Zkv7prsUz95VHY"); // supply your own
let token_mint: Pubkey = pubkey!("HhbhtPWNt5Rd2gvrjhGCekommdNQwVLY6ZMp3aBv4xtG"); // Mint: this scenario's value; supply your own
let token_program: Pubkey = pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); // the token program
let subscription_authority: Pubkey = pubkey!("4RDKDQRnKtZC5ti4wunSAayArwxdZida5St595CiKJ7i"); // SA(alice, Mint): this scenario's value; supply your own
let ix = Instruction {
    program_id,
    accounts: vec![
        AccountMeta::new(user, true), // user
        AccountMeta::new(user_ata, false), // userAta
        AccountMeta::new_readonly(token_mint, false), // tokenMint
        AccountMeta::new_readonly(token_program, false), // tokenProgram
        AccountMeta::new(subscription_authority, false), // subscriptionAuthority
    ],
    // discriminator ++ borsh()
    data: vec![0x0e],
};
}

The same call through the Codama-generated TypeScript client (the async builder derives every PDA the resolver derived here, so only the free inputs appear):

import { address } from "@solana/kit";
import { getRevokeSubscriptionAuthorityInstructionAsync } from "your-generated-client";

const ix = await getRevokeSubscriptionAuthorityInstructionAsync({
  user: userSigner, // alice (a TransactionSigner)
  userAta: address("3fVRopUs1BsF6RqteSmcyctBCx2YQ6Zkv7prsUz95VHY"),
  tokenMint: address("HhbhtPWNt5Rd2gvrjhGCekommdNQwVLY6ZMp3aBv4xtG"), // Mint
  // tokenProgram defaults to the token program
  subscriptionAuthority: address("4RDKDQRnKtZC5ti4wunSAayArwxdZida5St595CiKJ7i"), // SA(alice, Mint)
});
How this page verifies itself: the test that ran it

The narrative above is this test; the page and the code cannot drift.

#![allow(unused)]
fn main() {
#[test]
fn revoke_subscription_authority_clears_delegate() {
    let mut story = Story::load(SO, IDL);
    let alice = story.cast("alice");
    let mint = story.mint(&alice, MINT_DECIMALS);
    story.fund(&alice, &[(mint, 1_000_000)]);
    let user_ata = story.ata(&alice.pubkey(), &mint);

    story
        .init_subscription_authority(InitAuthorityArgs {
            user: &alice,
            mint,
            sponsor: None,
            token_program: None,
        })
        .expect_success();
    story.then_holds(
        "the ATA is delegated before revoke",
        story.ata_delegate(&user_ata).is_some(),
    );
    story.then_holds(
        "the ATA is delegated for the full amount",
        story.ata_delegated_amount(&user_ata) == u64::MAX,
    );

    let outcome = story.revoke_subscription_authority(RevokeAuthorityArgs {
        user: &alice,
        mint,
        ata: None,
    });
    story.then_holds("Alice revokes her subscription authority", outcome.success);

    story.then_holds(
        "the delegate is cleared after revoke",
        story.ata_delegate(&user_ata).is_none(),
    );
    story.then_holds(
        "the delegated amount is zeroed after revoke",
        story.ata_delegated_amount(&user_ata) == 0,
    );
    emit_scenario(
        &story,
        &outcome,
        "A user revokes their subscription authority",
    );
}
}