Skip to content

Commit

Permalink
bet
Browse files Browse the repository at this point in the history
  • Loading branch information
dlaciport committed Feb 28, 2025
1 parent 80dd370 commit f60cb96
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions margin/.tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scarb 2.9.4
starknet-foundry 0.38.0
1 change: 1 addition & 0 deletions margin/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ assert_macros = "2.9.4"
[[target.starknet-contract]]
sierra = true


[scripts]
test = "snforge test"

Expand Down
7 changes: 7 additions & 0 deletions margin/src/interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ pub trait IMargin<TContractState> {

fn liquidate(ref self: TContractState, user: ContractAddress);
}

#[starknet::interface]
pub trait IERC20MetadataForPragma<TState> {
fn name(self: @TState) -> ByteArray;
fn symbol(self: @TState) -> felt252;
fn decimals(self: @TState) -> felt252;
}
4 changes: 0 additions & 4 deletions margin/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
pub mod margin;
pub mod types;
pub mod interface;

pub mod mocks {
pub mod erc20_mock;
}
5 changes: 4 additions & 1 deletion margin/tests/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#[cfg(test)]
mod test_deposit;

mod utils;

mod mocks {
pub mod erc20_mock;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
pub mod ERC20Mock {
use openzeppelin_token::erc20::{ERC20Component, ERC20HooksEmptyImpl};
use starknet::ContractAddress;
use margin::interface::IERC20MetadataForPragma;

component!(path: ERC20Component, storage: erc20, event: ERC20Event);

#[abi(embed_v0)]
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>;
#[abi(embed_v0)]
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>;
impl InternalImpl = ERC20Component::InternalImpl<ContractState>;

#[storage]
Expand All @@ -35,4 +34,22 @@ pub mod ERC20Mock {
self.erc20.initializer(name, symbol);
self.erc20.mint(recipient, initial_supply);
}

impl IERC20MetadataForPragmaImpl of IERC20MetadataForPragma<ContractState> {
fn name(self: @ContractState) -> ByteArray {
self.erc20.ERC20_name.read()
}

// Assume symbol is at most 31 bytes
fn symbol(self: @ContractState) -> felt252 {
let mut output = array![];
self.erc20.ERC20_symbol.read().serialize(ref output);

*output.at(0)
}

fn decimals(self: @ContractState) -> felt252 {
18
}
}
}
2 changes: 1 addition & 1 deletion margin/tests/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct MarginTestSuite {
}

pub fn ERC20_MOCK_CONTRACT() -> ContractAddress {
contract_address_const::<'erc20mock'>()
contract_address_const::<'ERC20Mock'>()
}

pub fn deploy_erc20_mock() -> ContractAddress {
Expand Down

0 comments on commit f60cb96

Please sign in to comment.