universalsettle-api 0.2.1

X402-inspired settlement program for any token on Solana
Documentation
use steel::*;

#[repr(u8)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
pub enum SettlementInstruction {
    // User (public — no authority required)
    Sweep = 0,       // Indirect/batch settlement sweep
    CreateVault = 1, // Setup SplitVault for a seller
    // 2–99 reserved for future public instructions

    // Admin (require Config authority signer)
    Initialize = 100,
    UpdateAuthority = 101,
    UpdateFeeRate = 102,
    UpdateFeeDestination = 103,
    UpdateMinFeeAmount = 104,
    UpdateMinFeeAmountSol = 105,
    UpdateProvisioningFee = 106,
    UpdateDiscountedFeeRate = 107,
    AcceptAuthority = 108, // Two-step: new authority accepts proposed transfer
    CancelAuthorityProposal = 109, // Two-step: current authority cancels pending proposal
    InitShard = 110,       // Initialize a fee shard
    CollectFromShard = 111, // Collect fees from a shard to the treasury
    UpdateShardConfig = 112, // Update shard flag and count
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CreateVault {
    pub seller: Pubkey, // 32 bytes - Resource owner wallet address
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Sweep {
    pub token_mint: Pubkey, // For SOL: Pubkey::default(), For SPL: the mint address
    pub amount: [u8; 8],    // Amount to sweep (0 = all available)
    pub is_sol: [u8; 1],    // 1 for native SOL, 0 for SPL token
    pub _padding: [u8; 7],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Initialize {
    pub fee_destination: Pubkey,       // 32
    pub min_fee_amount: [u8; 8],       // 8 (SPL)
    pub min_fee_amount_sol: [u8; 8],   // 8 (SOL)
    pub provisioning_fee_sol: [u8; 8], // 8
    pub provisioning_fee_spl: [u8; 8], // 8
    pub fee_bps: [u8; 2],              // 2
    pub discounted_fee_bps: [u8; 2],   // 2
    pub use_fee_shard: u8,             // 1
    pub shard_count: u8,               // 1
    pub _padding: [u8; 2],             // 2
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateAuthority {
    pub new_authority: Pubkey,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct AcceptAuthority {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CancelAuthorityProposal {}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateFeeRate {
    pub new_fee_bps: [u8; 2],
    pub _padding: [u8; 6], // 6 bytes padding
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateFeeDestination {
    pub new_fee_destination: Pubkey,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateMinFeeAmount {
    pub new_min_fee_amount: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateProvisioningFee {
    pub new_provisioning_fee_sol: [u8; 8],
    pub new_provisioning_fee_spl: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateDiscountedFeeRate {
    pub new_discounted_fee_bps: [u8; 2],
    pub _padding: [u8; 6],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateMinFeeAmountSol {
    pub new_min_fee_amount_sol: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct InitShard {
    pub index: [u8; 8],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct CollectFromShard {
    pub index: [u8; 8],
    pub amount: [u8; 8],
    pub is_sol: [u8; 1],
    pub _padding: [u8; 7],
}

#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct UpdateShardConfig {
    pub use_fee_shard: u8,
    pub shard_count: u8,
    pub _padding: [u8; 6],
}

instruction!(SettlementInstruction, Sweep);
instruction!(SettlementInstruction, CreateVault);
instruction!(SettlementInstruction, Initialize);
instruction!(SettlementInstruction, UpdateAuthority);
instruction!(SettlementInstruction, UpdateFeeRate);
instruction!(SettlementInstruction, UpdateFeeDestination);
instruction!(SettlementInstruction, UpdateMinFeeAmount);
instruction!(SettlementInstruction, UpdateMinFeeAmountSol);
instruction!(SettlementInstruction, UpdateProvisioningFee);
instruction!(SettlementInstruction, UpdateDiscountedFeeRate);
instruction!(SettlementInstruction, AcceptAuthority);
instruction!(SettlementInstruction, CancelAuthorityProposal);
instruction!(SettlementInstruction, InitShard);
instruction!(SettlementInstruction, CollectFromShard);
instruction!(SettlementInstruction, UpdateShardConfig);