Skip to content

Commit

Permalink
Merge pull request #81 from argentlabs/main_cherry_pick
Browse files Browse the repository at this point in the history
Adding method descriptions and increasing test coverage
  • Loading branch information
juniset authored Dec 6, 2022
2 parents 597e6b2 + 3a7544c commit 470b150
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 58 deletions.
58 changes: 57 additions & 1 deletion contracts/account/ArgentAccount.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ from contracts.account.library import (
assert_initialized,
assert_no_self_call,
)

//
// @title ArgentAccount
// @author Argent Labs
// @notice Main account for Argent on StarkNet
//

/////////////////////
// CONSTANTS
Expand Down Expand Up @@ -196,6 +202,10 @@ func supportsInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_che
// EXTERNAL FUNCTIONS
/////////////////////

// @dev Initialises the account with the signer and an optional guardian.
// Must be called immediately after the account is deployed.
// @param signer The signer public key
// @param guardian The guardian public key
@external
func initialize{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
signer: felt, guardian: felt
Expand All @@ -206,6 +216,11 @@ func initialize{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}
return ();
}

// @dev Upgrades the implementation of the account and delegate calls {execute_after_upgrade} if additional data is provided.
// Must be called via {__execute__} and authorised by the signer and a guardian.
// @param implementation The class hash of the new implementation
// @param calldata The calldata to pass to {execute_after_upgrade}
// @return retdata The return of the library call to {execute_after_upgrade}
@external
func upgrade{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
implementation: felt, calldata_len: felt, calldata: felt*
Expand All @@ -226,6 +241,11 @@ func upgrade{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
}
}

// @dev Logic or multicall to execute after an upgrade.
// Can only be called by the account after a call to {upgrade}.
// @param call_array The multicall to execute
// @param calldata The calldata associated to the multicall
// @return retdata An array containing the output of the calls
@external
func execute_after_upgrade{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
call_array_len: felt, call_array: CallArray*, calldata_len: felt, calldata: felt*
Expand All @@ -241,6 +261,9 @@ func execute_after_upgrade{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range
return (retdata_len=retdata_len, retdata=retdata);
}

// @dev Changes the signer.
// Must be called via {__execute__} and authorised by the signer and a guardian.
// @param newSigner The public key of the new signer
@external
func changeSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newSigner: felt
Expand All @@ -249,6 +272,9 @@ func changeSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_pt
return ();
}

// @dev Changes the guardian.
// Must be called via {__execute__} and authorised by the signer and a guardian.
// @param newGuardian The public key of the new guardian
@external
func changeGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newGuardian: felt
Expand All @@ -257,6 +283,9 @@ func changeGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_
return ();
}

// @dev Changes the guardian backup.
// Must be called via {__execute__} and authorised by the signer and a guardian.
// @param newGuardian The public key of the new guardian backup
@external
func changeGuardianBackup{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newGuardian: felt
Expand All @@ -265,24 +294,35 @@ func changeGuardianBackup{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_
return ();
}

// @dev Triggers the escape of the guardian when it is lost or compromised.
// Must be called via {__execute__} and authorised by the signer alone.
// Can override an ongoing escape of the signer.
@external
func triggerEscapeGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
ArgentModel.trigger_escape_guardian();
return ();
}

// @dev Triggers the escape of the signer when it is lost or compromised.
// Must be called via {__execute__} and authorised by a guardian alone.
// Cannot override an ongoing escape of the guardian.
@external
func triggerEscapeSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
ArgentModel.trigger_escape_signer();
return ();
}

// @dev Cancels an ongoing escape if any.
// Must be called via {__execute__} and authorised by the signer and a guardian.
@external
func cancelEscape{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() {
ArgentModel.cancel_escape();
return ();
}

// @dev Escapes the guardian after the escape period of 7 days.
// Must be called via {__execute__} and authorised by the signer alone.
// @param newGuardian The public key of the new guardian
@external
func escapeGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newGuardian: felt
Expand All @@ -291,6 +331,9 @@ func escapeGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_
return ();
}

// @dev Escapes the signer after the escape period of 7 days.
// Must be called via {__execute__} and authorised by a guardian alone.
// @param newSigner The public key of the new signer
@external
func escapeSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
newSigner: felt
Expand All @@ -303,6 +346,8 @@ func escapeSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_pt
// VIEW FUNCTIONS
/////////////////////

// @dev Gets the current signer
// @return signer The public key of the signer
@view
func getSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
signer: felt
Expand All @@ -311,6 +356,8 @@ func getSigner{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
return (signer=res);
}

// @dev Gets the current guardian
// @return guardian The public key of the guardian
@view
func getGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
guardian: felt
Expand All @@ -319,6 +366,8 @@ func getGuardian{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
return (guardian=res);
}

// @dev Gets the current guardian backup
// @return guardianBackup The public key of the guardian backup
@view
func getGuardianBackup{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
guardianBackup: felt
Expand All @@ -327,6 +376,9 @@ func getGuardianBackup{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_che
return (guardianBackup=res);
}

// @dev Gets the details of the ongoing escape
// @return activeAt The timestamp at which the escape can be executed
// @return type The type of the ongoing escape: 0=no escape, 1=guardian escape, 2=signer escape
@view
func getEscape{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (
activeAt: felt, type: felt
Expand All @@ -335,17 +387,21 @@ func getEscape{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
return (activeAt=activeAt, type=type);
}

// @dev Gets the version of the account implementation
// @return version The current version as a short string
@view
func getVersion() -> (version: felt) {
return (version=VERSION);
}

// @dev Gets the name of the account implementation
// @return name The name as a short string
@view
func getName() -> (name: felt) {
return (name=NAME);
}

// TMP: Remove when isValidSignature() is widely used
// @dev DEPRECATED: Remove when isValidSignature() is widely used
@view
func is_valid_signature{
syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, ecdsa_ptr: SignatureBuiltin*, range_check_ptr
Expand Down
Loading

0 comments on commit 470b150

Please sign in to comment.