Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions src/contracts/core.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ mod Core {
/// - If the payout is attempted before the scheduled start time or after the end time.
/// - If the payout is attempted before the required interval has passed since the last
/// execution.
fn schedule_payout(ref self: ContractState) {
fn schedule_payout(ref self: ContractState, token: ContractAddress) {
let caller = get_caller_address();
let members = self.member.get_members();
let no_of_members = members.len();
Expand All @@ -243,8 +243,8 @@ mod Core {
let vault_address = org_info.vault_address;

let vault_dispatcher = IVaultDispatcher { contract_address: vault_address };
let total_bonus = vault_dispatcher.get_bonus_allocation();
let total_funds = vault_dispatcher.get_balance();
let total_bonus = vault_dispatcher.get_bonus_allocation(token);
let total_funds = vault_dispatcher.get_token_balance(token);

let current_schedule = self.disbursement.get_current_schedule();
assert(current_schedule.status == ScheduleStatus::ACTIVE, 'Schedule not active');
Expand Down Expand Up @@ -282,7 +282,7 @@ mod Core {
.disbursement
.compute_renumeration(current_member_response, total_bonus, total_weight);
let timestamp = get_block_timestamp();
vault_dispatcher.pay_member(current_member_response.address, amount);
vault_dispatcher.pay_member(token, current_member_response.address, amount);
// self.member.record_member_payment(current_member_response.id, amount, timestamp)
}

Expand Down
3 changes: 2 additions & 1 deletion src/contracts/factory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ pub mod Factory {
let vault_count = self.vaults_count.read();
let vault_id: u256 = vault_count.into();
let mut constructor_calldata = array![];
token.serialize(ref constructor_calldata);
let tokens = array![token];
// available_funds.serialize(ref constructor_calldata);
// starting_bonus_allocation.serialize(ref constructor_calldata);
owner.serialize(ref constructor_calldata);
tokens.serialize(ref constructor_calldata);

// Deploy the Vault
let processed_class_hash: ClassHash = self.vault_class_hash.read();
Expand Down
404 changes: 247 additions & 157 deletions src/contracts/vault.cairo

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/interfaces/icore.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use starknet::ContractAddress;

/// # ICore
///
/// This trait defines the public interface for the central core contract of an organization.
Expand All @@ -18,7 +20,7 @@ pub trait ICore<T> {
/// ## Parameters
///
/// - `ref self: T`: The current state of the contract.
fn schedule_payout(ref self: T);
fn schedule_payout(ref self: T, token: ContractAddress);

/// # initialize_disbursement_schedule
///
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/ifactory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ pub trait IFactory<T> {
// fn get_vault_org_pairs(self: @T) -> Array<(ContractAddress, ContractAddress)>;

// in the future, you can upgrade a deployed org core from here
// fn initialize_upgrade(ref self: T, vaults: Array<ContractAddress>, cores:
// Array<ContractAddress>);
// this function would pick the updated class hash from the storage, if the class hash has been
// updated at present, it can only pick the latest...
// in the future, it can pick a specific class hash version
// fn initialize_upgrade(ref self: T, vaults: Array<ContractAddress>, cores:
// Array<ContractAddress>);
// this function would pick the updated class hash from the storage, if the class hash has been
// updated at present, it can only pick the latest...
// in the future, it can pick a specific class hash version
}
135 changes: 85 additions & 50 deletions src/interfaces/ivault.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,153 +3,188 @@ use starknet::ContractAddress;

/// # IVault
///
/// This trait defines the public interface for a vault component. It outlines the core
/// functionalities for managing an organization's funds, including deposits, withdrawals,
/// member payments, and security measures like emergency freezes. The interface is designed
/// to be implemented by a Starknet component responsible for the secure handling and
/// tracking of financial assets.
/// This trait defines the public interface for a multi-token vault component. It outlines the core
/// functionalities for managing an organization's funds across various ERC20 tokens, including
/// deposits, withdrawals, member payments, and security measures.
#[starknet::interface]
pub trait IVault<TContractState> {
/// # deposit_funds
///
/// Deposits a specified amount of a given token into the vault.
/// Deposits a specified amount of an accepted token into the vault.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
/// - `token`: The `ContractAddress` of the token being deposited.
/// - `amount`: The amount of funds to deposit as a `u256`.
/// - `address`: The `ContractAddress` of the token being deposited.
fn deposit_funds(ref self: TContractState, amount: u256, address: ContractAddress);
/// - `from_address`: The `ContractAddress` from which the funds are being sent.
fn deposit_funds(
ref self: TContractState,
token: ContractAddress,
amount: u256,
from_address: ContractAddress,
);

/// # withdraw_funds
///
/// Withdraws a specified amount of a given token from the vault. This is a privileged action.
/// Withdraws a specified amount of an accepted token from the vault.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
/// - `token`: The `ContractAddress` of the token being withdrawn.
/// - `amount`: The amount of funds to withdraw as a `u256`.
/// - `address`: The `ContractAddress` of the token being withdrawn.
fn withdraw_funds(ref self: TContractState, amount: u256, address: ContractAddress);
/// - `to_address`: The `ContractAddress` to receive the funds.
fn withdraw_funds(
ref self: TContractState, token: ContractAddress, amount: u256, to_address: ContractAddress,
);

/// # emergency_freeze
///
/// Halts all outbound transactions from the vault. This function serves as a security
/// measure to prevent unauthorized fund movements in case of a compromise.
/// Halts all outbound transactions from the vault as a global security measure.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
fn emergency_freeze(ref self: TContractState);

/// # unfreeze_vault
///
/// Lifts the emergency freeze, restoring normal vault operations. This is a privileged action.
/// Lifts the emergency freeze, restoring normal vault operations.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
fn unfreeze_vault(ref self: TContractState);

// fn bulk_transfer(ref self: TContractState, recipients: Span<ContractAddress>);

/// # pay_member
///
/// Executes a payment from the vault to a specific member's address.
/// Executes a payment from the vault to a specific member's address using a specified token.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
/// - `token`: The `ContractAddress` of the token for the payment.
/// - `recipient`: The `ContractAddress` of the member to receive the payment.
/// - `amount`: The payment amount as a `u256`.
fn pay_member(ref self: TContractState, recipient: ContractAddress, amount: u256);
fn pay_member(
ref self: TContractState, token: ContractAddress, recipient: ContractAddress, amount: u256,
);

/// # add_to_bonus_allocation
///
/// Allocates a certain amount of funds for bonus payments. These funds are tracked
/// separately from the main available balance.
/// Allocates funds of a specific token for bonus payments.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
/// - `token`: The `ContractAddress` of the token for the bonus allocation.
/// - `amount`: The amount to allocate for bonuses.
/// - `address`: The `ContractAddress` of the token for the bonus allocation.
fn add_to_bonus_allocation(ref self: TContractState, amount: u256, address: ContractAddress);
/// - `address`: The address initiating the allocation.
fn add_to_bonus_allocation(
ref self: TContractState, token: ContractAddress, amount: u256, address: ContractAddress,
);

/// # add_accepted_token
///
/// Adds a new ERC20 token to the list of accepted tokens for the vault. (Owner only)
///
/// ## Parameters
/// - `ref self: TContractState`: The current state of the contract.
/// - `token`: The `ContractAddress` of the token to be accepted.
fn add_accepted_token(ref self: TContractState, token: ContractAddress);

/// # get_balance
/// # remove_accepted_token
///
/// Retrieves the total balance of the vault for all managed assets.
/// Removes an ERC20 token from the list of accepted tokens for the vault. (Owner only)
///
/// ## Parameters
/// - `ref self: TContractState`: The current state of the contract.
/// - `token`: The `ContractAddress` of the token to be removed.
fn remove_accepted_token(ref self: TContractState, token: ContractAddress);

/// # get_token_balance
///
/// Retrieves the total balance of a specific token held by the vault.
///
/// ## Parameters
/// - `self: @TContractState`: A snapshot of the contract's state.
/// - `token`: The `ContractAddress` of the token to query.
///
/// ## Returns
///
/// The total balance as a `u256`.
fn get_balance(self: @TContractState) -> u256;
/// The total balance of the specified token as a `u256`.
fn get_token_balance(self: @TContractState, token: ContractAddress) -> u256;

/// # get_available_funds
/// # get_all_token_balances
///
/// Retrieves the amount of funds available for general use, excluding any earmarked
/// allocations like bonuses.
/// Retrieves the vault's balance for every accepted token.
///
/// ## Parameters
///
/// - `self: @TContractState`: A snapshot of the contract's state.
///
/// ## Returns
/// An `Array` of (`ContractAddress`, `u256`) tuples representing each token and its balance.
fn get_all_token_balances(self: @TContractState) -> Array<(ContractAddress, u256)>;


/// # get_accepted_tokens
///
/// Retrieves a list of all tokens the vault is authorized to manage.
///
/// ## Parameters
/// - `self: @TContractState`: A snapshot of the contract's state.
///
/// The available funds as a `u256`.
fn get_available_funds(self: @TContractState) -> u256;
/// ## Returns
/// An `Array<ContractAddress>` of accepted tokens.
fn get_accepted_tokens(self: @TContractState) -> Array<ContractAddress>;

/// # get_vault_status
///
/// Returns the current operational status of the vault (e.g., Active, Frozen).
///
/// ## Parameters
///
/// - `self: @TContractState`: A snapshot of the contract's state.
///
/// ## Returns
///
/// The current `VaultStatus` enum.
fn get_vault_status(self: @TContractState) -> VaultStatus;

/// # get_bonus_allocation
///
/// Retrieves the current total amount allocated for bonuses.
/// Retrieves the current total amount allocated for bonuses for a specific token.
///
/// ## Parameters
///
/// - `self: @TContractState`: A snapshot of the contract's state.
/// - `token`: The `ContractAddress` of the token to query.
///
/// ## Returns
/// The bonus allocation for the specified token as a `u256`.
fn get_bonus_allocation(self: @TContractState, token: ContractAddress) -> u256;

/// # is_token_acceptable
///
/// Checks whether a specific token is accepted by the vault for transactions.
///
/// ## Parameters
/// - `self: @TContractState`: A snapshot of the contract's state.
/// - `token`: The `ContractAddress` of the token to check.
///
/// The total bonus allocation as a `u256`.
fn get_bonus_allocation(self: @TContractState) -> u256;
/// ## Returns
/// A boolean value: `true` if the token is accepted, `false` otherwise.
fn is_token_acceptable(self: @TContractState, token: ContractAddress) -> bool;

/// # get_transaction_history
///
/// Retrieves a log of all transactions processed by the vault.
///
/// ## Parameters
///
/// - `self: @TContractState`: A snapshot of the contract's state.
///
/// ## Returns
///
/// An `Array<Transaction>` containing the vault's transaction history.
fn get_transaction_history(self: @TContractState) -> Array<Transaction>;

/// # allow_org_core_address
///
/// Grants permission to a core organization contract to interact with the vault.
/// This is necessary for enabling automated payments and other coordinated actions.
/// Grants permission to a contract to interact with the vault.
///
/// ## Parameters
///
/// - `ref self: TContractState`: The current state of the contract.
/// - `org_address`: The `ContractAddress` of the core organization contract to authorize.
/// - `org_address`: The `ContractAddress` of the contract to authorize.
fn allow_org_core_address(ref self: TContractState, org_address: ContractAddress);
}
Loading
Loading