Feat: Implement tba acc contract #13
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Nonceto theDataKeyenum for transaction nonce storageget_nonce()andincrement_nonce()helper functionsnonce()getter function to query the current nonce2. Transaction Execution
execute()function that allows the TBA account to execute transactions on other contractsexecute(env: Env, to: Address, func: Symbol, args: Vec<Val>) -> Vec<Val>TransactionExecutedEventfor transaction tracking3. Event Emission
TransactionExecutedEventstruct with fields:to: Address- Target contract addressfunc: Symbol- Function name being callednonce: u64- Transaction nonce4. Authorization
__check_auth()implementation for CustomAccountInterfaceBytesN<64>for signatures)soroban_sdk::auth::ContextCode Quality
Fixes
Contextand signature typesinvoke_contractusage with proper type annotationsValconversion forrequire_auth_for_argstoken()function to handle chain_id (set to 0 as placeholder)Test Suite
contracts/tba_account/src/test.rsFiles Modified
contracts/tba_account/src/lib.rscontracts/tba_account/src/test.rs(new file)Technical Details
Storage
u64typeDataKeyenumAuthorization Flow
execute()verifies contract is initializedrequire_auth()Soroban-Specific Implementation
env.invoke_contract()for contract calls (not raw calls like Solidity)env.events().publish()for event emissionrequire_auth()for Stellar's native authorizationSymbolfor function namesVec<Val>for function arguments (Soroban's universal value type)Testing
cargo test --package tba_accountResults:
Compatibility
Next Steps
This implementation completes the core TBA Account contract. Future enhancements could include:
Notes
get_implementation_hash()andget_salt()functions are expected - these may be used by the Registry contract or future features