Skip to content
Open

Vault #155

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
2 changes: 2 additions & 0 deletions packages/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod structs {
pub mod tongo {
pub mod ITongo;
pub mod Tongo;
pub mod IVault;
pub mod Vault;
}

//OZ interface
Expand Down
17 changes: 17 additions & 0 deletions packages/contracts/src/structs/common/state.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use starknet::{ContractAddress, ClassHash};
use crate::structs::aecipher::AEBalance;
use crate::structs::common::cipherbalance::CipherBalance;

Expand All @@ -18,3 +19,19 @@ pub struct State {
pub ae_balance: Option<AEBalance>,
pub ae_audit_balance: Option<AEBalance>,
}

/// Represent the setup of the Vaul
///
/// - vault_address: The contract address of the Vault.
/// - tongo_class_hash: The class hash of the Tongo this contract will work with.
/// - ERC20: The contract address of the ERC20 that Tongo will wrap.
/// - rate: The rate of conversion between the wrapped ERC20 and Tongo
/// - bit_size: The bit size Tongo will work it.
#[derive(Serde, Drop, starknet::Store)]
pub struct GlobalSetup {
pub vault_address: ContractAddress,
pub tongo_class_hash: ClassHash,
pub ERC20: ContractAddress,
pub rate: u256,
pub bit_size: u32,
}
47 changes: 35 additions & 12 deletions packages/contracts/src/structs/events.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use starknet::ContractAddress;
use crate::structs::aecipher::AEBalance;
use crate::structs::common::cipherbalance::CipherBalance;
use crate::structs::common::pubkey::PubKey;
use crate::structs::{
aecipher::AEBalance,
common::{
cipherbalance::CipherBalance,
pubkey::PubKey,
},
};

/// Event emited in a Fund operation.
/// Event emitted in a Fund operation.
///
/// - to: The Tongo account to fund.
/// - nonce: The nonce of the Tongo account.
Expand All @@ -20,7 +24,7 @@ pub struct FundEvent {
pub amount: u128,
}

/// Event emited in a OutsideFund operation
/// Event emitted in a OutsideFund operation
///
/// - to: The Tongo account to fund.
/// - from: The contract address is funding the account.
Expand All @@ -34,7 +38,7 @@ pub struct OutsideFundEvent {
pub amount: u128,
}

/// Event emited in a Rollover operation.
/// Event emitted in a Rollover operation.
///
/// - to: The Tongo account to rollover.
/// - nonce: The nonce of the Tongo account.
Expand All @@ -49,7 +53,7 @@ pub struct RolloverEvent {
}


/// Event emited in a Withdraw operation.
/// Event emitted in a Withdraw operation.
///
/// - from: The Tongo account to withdraw from.
/// - nonce: The nonce of the Tongo account.
Expand All @@ -66,7 +70,7 @@ pub struct WithdrawEvent {
}


/// Event emited in a Transfer operation.
/// Event emitted in a Transfer operation.
///
/// - to: The Tongo account to send tongos to.
/// - from: The Tongo account to take tongos from.
Expand All @@ -90,7 +94,7 @@ pub struct TransferEvent {
}


/// Event emited in a Ragequit operation.
/// Event emitted in a Ragequit operation.
///
/// - from: The Tongo account to withdraw from.
/// - nonce: The nonce of the Tongo account.
Expand All @@ -106,7 +110,7 @@ pub struct RagequitEvent {
pub to: ContractAddress,
}

/// Event emited when users declare their balances to the auditor.
/// Event emitted when users declare their balances to the auditor.
///
/// - from: The Tongo account that is declaring its balance.
/// - nonce: The nonce of the Tongo accout.
Expand All @@ -125,7 +129,7 @@ pub struct BalanceDeclared {
}


/// Event emited when users declare a transfer to the auditor.
/// Event emitted when users declare a transfer to the auditor.
///
/// - from: The Tongo account that is executing the transfer.
/// - to: The Tongo account that is receiving the transfer.
Expand All @@ -146,7 +150,7 @@ pub struct TransferDeclared {
pub hint: AEBalance,
}

/// Event emited when the owner sets a public key for the auditor.
/// Event emitted when the owner sets a public key for the auditor.
///
/// - keyNumber: An increasing number that identifies the public key
/// - AuditorPubKey: The newly set auditor public key.
Expand All @@ -156,3 +160,22 @@ pub struct AuditorPubKeySet {
pub keyNumber: u128,
pub AuditorPubKey: PubKey,
}

/// Event emitted when a Tongo contract is deployed by the Vault
///
/// - tag: The chosen tag for the contract
/// - address: The contract address of the Tongo instance
/// - ERC20: The erc20 is being wrapped
/// - rate: The conversion rage between the wrapped ERC20 and Tongo
/// - bit_size: The bit size the contract will work with
/// - AuditorPubKey: The auditor public key
#[derive(Drop, starknet::Event)]
pub struct TongoDeployed {
#[key]
pub tag: felt252,
pub address: ContractAddress,
pub ERC20: ContractAddress,
pub rate: u256,
pub bit_size: u32,
pub AuditorPubKey: Option<PubKey>,
}
28 changes: 17 additions & 11 deletions packages/contracts/src/tongo/ITongo.cairo
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
use starknet::ContractAddress;
use crate::structs::common::cipherbalance::CipherBalance;
use crate::structs::common::pubkey::PubKey;
use crate::structs::common::state::State;
use crate::structs::operations::fund::{Fund, OutsideFund};
use crate::structs::operations::ragequit::Ragequit;
use crate::structs::operations::rollover::Rollover;
use crate::structs::operations::transfer::Transfer;
use crate::structs::operations::withdraw::Withdraw;
use crate::structs::common::{
cipherbalance::CipherBalance,
pubkey::PubKey,
state::State,
};
use crate::structs::operations::{
fund::{Fund, OutsideFund},
ragequit::Ragequit,
rollover::Rollover,
transfer::Transfer,
withdraw::Withdraw,
};

#[starknet::interface]
pub trait ITongo<TContractState> {
// Tongo general setup:
/// Returns the contract address that Tongo is wraping.
/// Returns the Tag this contract is registered with.
fn get_tag(self: @TContractState) -> felt252;

/// Returns the contract address of the ERC20 that is wrapped
fn ERC20(self: @TContractState) -> ContractAddress;

/// Returns the rate of conversion between the wrapped ERC20 a tongo:
/// Returns the rate of conversion between the wrapped ERC20 and tongo:
///
/// ERC20_amount = Tongo_amount*rate
///
Expand Down
45 changes: 45 additions & 0 deletions packages/contracts/src/tongo/IVault.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use starknet::{ContractAddress, ClassHash};
use crate::structs::common::{
pubkey::PubKey,
state::GlobalSetup,
};

#[starknet::interface]
pub trait IVault<TContractState> {
/// Returns the global setup of the Vaul.
fn get_vault_setup(self: @TContractState) -> GlobalSetup;

/// Returns the class hash of the Tongo this contract will work with.
fn get_tongo_class_hash(self: @TContractState) -> ClassHash;

/// Returns the contract address of the ERC20 that Tongo will wrap.
fn ERC20(self: @TContractState) -> ContractAddress;

/// Returns the rate of conversion between the wrapped ERC20 and Tongo:
///
/// ERC20_amount = Tongo_amount*rate
///
/// The amount variable in all operation refers to the amount of Tongos.
fn get_rate(self: @TContractState) -> u256;

/// Returns the bit size Tongo will work it.
fn get_bit_size(self: @TContractState) -> u32;

/// Returns true if the contract address is a Tongo contract deployed by this Vault.
/// The Vault will only work with these contracts.
fn is_known_tongo(self: @TContractState, address: ContractAddress) -> bool;

/// Returns the address of a given tag if a Tongo contract was deployed with that particular tag.
fn tag_to_address(self: @TContractState, tag: felt252) -> ContractAddress;

/// Deploys a Tongo instance for the given owner and tag with the given auditor.
///
/// Emits TongoDeployed event.
fn deploy_tongo(ref self: TContractState, owner: ContractAddress, tag: felt252, auditorKey: Option<PubKey>) -> ContractAddress;

/// Pulls ERC20 from the caller. The caller can only be a Tongo instance deployed by this Vault.
fn deposit(ref self: TContractState, amount: u256);

/// Sends ERC20 to the caller. The caller can only be a Tongo instance deployed by this Vault.
fn withdraw(ref self: TContractState, amount: u256);
}
Loading
Loading