AccountV3

Opinionated Account implementation for tokenbound V3

This is an opinionated, flexible, and audited tokenbound account implementation.

The full contract code of the AccountV3 can be found here.

What's new?

The AccountV3 comes with breaking changes as we no longer maintain compatibility with SNIP-6.

It majorly focuses on flexibility and ease with integration, comprising of plug'n'play components which developers can utilize. More on this in the component section.

Functions

Constructor

The constructor function initializes certain parameters on deployment.

fn constructor(
    ref self: ContractState,
    token_contract: ContractAddress,
    token_id: u256,
    registry: ContractAddress,
    implementation_hash: felt252,
    salt: felt252
)

Parameters

ACCOUNTV3 IMPLEMENTATION

on_erc721_received

This function is called each time an NFT is received. Prevents ownership cycle.

fn on_erc721_received(
    self: @ContractState,
    operator: ContractAddress,
    from: ContractAddress,
    token_id: u256,
    data: Span<felt252>
) -> felt252;

context

Context gives deployment details of the TBA. Will be needed for cross-chain compatibility (v4?).

fn context(self: @ContractState) -> (ContractAddress, felt252, felt252)

SIGNATORY IMPLEMENTATION

is_valid_signer

Checks if the signer is the owner or a permissioned address.

fn is_valid_signer(self: @ContractState, signer: ContractAddress) -> bool;

is_valid_signature

Validates tokenbound account signatures.

fn is_valid_signature(
    self: @ContractState, hash: felt252, signature: Span<felt252>
) -> felt252;

EXECUTABLE IMPLEMENTATION

execute

Executes transactions on the TokenBound account. Checks caller is a valid signer and account is not locked.

fn execute(ref self: ContractState, mut calls: Array<Call>) -> Array<Span<felt252>>

UPGRADEABLE IMPLEMENTATION

upgrade

It upgrades the Token Bound Account by replacing with a new_class_hash . An account can only be upgraded by the owner and requires the account to be locked.

fn upgrade(ref self: ContractState, new_class_hash: ClassHash)

LOCKABLE IMPLEMENTATION

lock

Locks an account for a specified period of time which is measured in seconds. the function can only be called by a valid signer.

fn lock(ref self: ContractState, lock_until: u64)

is_locked

Checks if an account is locked and returns true if it is locked and false if it is not. If the account is locked, it also returns the time left until the account is unlocked.

fn is_locked(self: @ContractState) -> (bool, u64)

PERMISSIONABLE IMPLEMENTATION

set_permission

Gives a set of specified addresses permission to execute from a tokenbound account, lock it etc. (Think guardians). Can also remove permissions by setting permissions to false.

fn set_permission(
    ref self: ContractState,
    permissioned_addresses: Array<ContractAddress>,
    permissions: Array<bool>
)

has_permission

Checks if an address passed in is a permissioned_address. It returns true if permission has been set for the address, else it returns false.

fn has_permission(
    self: @ContractState, owner: ContractAddress, permissioned_address: ContractAddress
) -> bool; 

Last updated