Skip to content

Conversation

@Otaiki1
Copy link
Contributor

@Otaiki1 Otaiki1 commented Jan 22, 2026

TBA Account Contract Implementation

This PR closes #1

Summary

This PR implements the core TBA (Token Bound Account) Account contract, completing the foundational infrastructure for the Token Bound Account system on Stellar/Soroban. The contract enables NFTs to have their own smart accounts that can hold assets and execute transactions.

Changes

Core Functionality

1. Nonce Tracking

  • Added Nonce to the DataKey enum for transaction nonce storage
  • Implemented get_nonce() and increment_nonce() helper functions
  • Added public nonce() getter function to query the current nonce
  • Nonce starts at 0 and increments with each transaction execution

2. Transaction Execution

  • Implemented execute() function that allows the TBA account to execute transactions on other contracts
  • Function signature: execute(env: Env, to: Address, func: Symbol, args: Vec<Val>) -> Vec<Val>
  • Includes proper authorization checks (only NFT owner can execute)
  • Automatically increments nonce on each execution
  • Emits TransactionExecutedEvent for transaction tracking

3. Event Emission

  • Added TransactionExecutedEvent struct with fields:
    • to: Address - Target contract address
    • func: Symbol - Function name being called
    • nonce: u64 - Transaction nonce
  • Events are emitted via Soroban's native event system

4. Authorization

  • Maintained existing __check_auth() implementation for CustomAccountInterface
  • Updated to use correct Soroban SDK types (BytesN<64> for signatures)
  • Fixed imports to use soroban_sdk::auth::Context
  • Proper authorization flow ensures only NFT owner can control the account

Code Quality

Fixes

  • Fixed import statements for Context and signature types
  • Corrected invoke_contract usage with proper type annotations
  • Fixed Val conversion for require_auth_for_args
  • Updated token() function to handle chain_id (set to 0 as placeholder)

Test Suite

  • Created comprehensive test suite in contracts/tba_account/src/test.rs
  • Tests cover:
    • ✅ Initialization (success case)
    • ✅ Re-initialization prevention (panic test)
    • ✅ Getter functions (token_contract, token_id, token, nonce)
    • ✅ Nonce initial value verification
    • ✅ Execute before initialization (panic test)
  • All 5 tests passing

Files Modified

  • contracts/tba_account/src/lib.rs

    • Added Nonce storage and helper functions
    • Added TransactionExecutedEvent struct
    • Implemented execute() function
    • Fixed imports and type conversions
    • Added nonce() getter function
  • contracts/tba_account/src/test.rs (new file)

    • Comprehensive test suite with 5 test cases
    • Mock NFT contract for testing
    • Tests for initialization, getters, and error cases

Technical Details

Storage

  • Uses instance storage for all data (nonce, token contract, token ID, etc.)
  • Nonce stored as u64 type
  • All storage keys defined in DataKey enum

Authorization Flow

  1. execute() verifies contract is initialized
  2. Queries NFT contract for current owner
  3. Requires authorization from NFT owner via require_auth()
  4. Increments nonce
  5. Emits event
  6. Executes target contract call

Soroban-Specific Implementation

  • Uses env.invoke_contract() for contract calls (not raw calls like Solidity)
  • Uses env.events().publish() for event emission
  • Uses require_auth() for Stellar's native authorization
  • Uses Symbol for function names
  • Uses Vec<Val> for function arguments (Soroban's universal value type)

Testing

cargo test --package tba_account

Results:

  • ✅ 5 tests passing
  • ✅ 0 tests failing
  • ✅ Contract compiles without errors
  • ✅ No linter errors

Compatibility

  • Compatible with ERC-6551 pattern (token() returns chain_id, contract, token_id tuple)
  • Follows Soroban best practices
  • Integrates with CustomAccountInterface for native Stellar account abstraction

Next Steps

This implementation completes the core TBA Account contract. Future enhancements could include:

  • Support for batch transactions
  • Delegate functionality
  • Enhanced event tracking
  • Integration with TBA Registry contract

Notes

  • Warnings about unused get_implementation_hash() and get_salt() functions are expected - these may be used by the Registry contract or future features
  • Chain ID is currently set to 0 as a placeholder (Soroban doesn't expose chain_id in the same way as Ethereum)

@manoahLinks
Copy link
Contributor

Thanks for your contribution @Otaiki1

@manoahLinks manoahLinks merged commit c4f0cb3 into crowdpass-live:main Jan 24, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Contract] TBA Account Contract - Basic Structure

2 participants