Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate interfaces ERC20 to CamelCase #6

Merged
merged 2 commits into from
Nov 9, 2023
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
6 changes: 3 additions & 3 deletions contracts/cairo/src/ERC20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ mod ERC20 {
18
}

fn total_supply(self: @ContractState) -> u256 {
fn totalSupply(self: @ContractState) -> u256 {
self.ERC20_total_supply.read()
}

fn balance_of(self: @ContractState, account: ContractAddress) -> u256 {
fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 {
self.ERC20_balances.read(account)
}

Expand All @@ -98,7 +98,7 @@ mod ERC20 {
true
}

fn transfer_from(
fn transferFrom(
ref self: ContractState,
sender: ContractAddress,
recipient: ContractAddress,
Expand Down
29 changes: 14 additions & 15 deletions contracts/cairo/src/escrow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ mod Escrow {
orders_used: LegacyMap::<u256, bool>,
herodotus_facts_registry_contract: ContractAddress,
eth_transfer_contract: EthAddress, // our transfer contract in L1
mm_ethereum_contract: EthAddress,
mm_starknet_contract: ContractAddress,
mm_ethereum_wallet: EthAddress,
mm_starknet_wallet: ContractAddress,
native_token_eth_starknet: ContractAddress
}

Expand All @@ -90,8 +90,8 @@ mod Escrow {
ref self: ContractState,
herodotus_facts_registry_contract: ContractAddress,
eth_transfer_contract: EthAddress,
mm_ethereum_contract: EthAddress,
mm_starknet_contract: ContractAddress,
mm_ethereum_wallet: EthAddress,
mm_starknet_wallet: ContractAddress,
native_token_eth_starknet: ContractAddress
) {
let mut unsafe_state = Ownable::unsafe_new_contract_state();
Expand All @@ -100,8 +100,8 @@ mod Escrow {
self.current_order_id.write(0);
self.herodotus_facts_registry_contract.write(herodotus_facts_registry_contract);
self.eth_transfer_contract.write(eth_transfer_contract);
self.mm_ethereum_contract.write(mm_ethereum_contract);
self.mm_starknet_contract.write(mm_starknet_contract);
self.mm_ethereum_wallet.write(mm_ethereum_wallet);
self.mm_starknet_wallet.write(mm_starknet_wallet);
self.native_token_eth_starknet.write(native_token_eth_starknet);
}

Expand All @@ -121,7 +121,7 @@ mod Escrow {
// TODO: add allowance ?

IERC20Dispatcher { contract_address: self.native_token_eth_starknet.read() }
.transfer_from(get_caller_address(), get_contract_address(), order.amount);
.transferFrom(get_caller_address(), get_contract_address(), order.amount);

self
.emit(
Expand All @@ -146,8 +146,7 @@ mod Escrow {

fn withdraw(ref self: ContractState, order_id: u256, block: u256, slot: u256,) {
assert(
self.mm_starknet_contract.read() == get_caller_address(),
'Only MM_STARKNET_CONTRACT'
self.mm_starknet_wallet.read() == get_caller_address(), 'Only MM_STARKNET_CONTRACT'
);
assert(!self.orders_used.read(order_id), 'Order already withdrawed');

Expand Down Expand Up @@ -196,9 +195,9 @@ mod Escrow {
// - add fee
// - confirm slot values against local order
IERC20Dispatcher { contract_address: self.native_token_eth_starknet.read() }
.transfer(self.mm_starknet_contract.read(), amount);
.transfer(self.mm_starknet_wallet.read(), amount);

self.emit(Withdraw { order_id, address: self.mm_starknet_contract.read(), amount });
self.emit(Withdraw { order_id, address: self.mm_starknet_wallet.read(), amount });
}

fn get_herodotus_facts_registry_contract(self: @ContractState) -> ContractAddress {
Expand All @@ -210,11 +209,11 @@ mod Escrow {
}

fn get_mm_ethereum_contract(self: @ContractState) -> EthAddress {
self.mm_ethereum_contract.read()
self.mm_ethereum_wallet.read()
}

fn get_mm_starknet_contract(self: @ContractState) -> ContractAddress {
self.mm_starknet_contract.read()
self.mm_starknet_wallet.read()
}

fn set_herodotus_facts_registry_contract(
Expand All @@ -234,13 +233,13 @@ mod Escrow {
fn set_mm_ethereum_contract(ref self: ContractState, new_contract: EthAddress) {
let unsafe_state = Ownable::unsafe_new_contract_state();
Ownable::InternalImpl::assert_only_owner(@unsafe_state);
self.mm_ethereum_contract.write(new_contract);
self.mm_ethereum_wallet.write(new_contract);
}

fn set_mm_starknet_contract(ref self: ContractState, new_contract: ContractAddress) {
let unsafe_state = Ownable::unsafe_new_contract_state();
Ownable::InternalImpl::assert_only_owner(@unsafe_state);
self.mm_starknet_contract.write(new_contract);
self.mm_starknet_wallet.write(new_contract);
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/cairo/src/interfaces/IERC20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ trait IERC20<TState> {
fn name(self: @TState) -> felt252;
fn symbol(self: @TState) -> felt252;
fn decimals(self: @TState) -> u8;
fn total_supply(self: @TState) -> u256;
fn balance_of(self: @TState, account: ContractAddress) -> u256;
fn totalSupply(self: @TState) -> u256;
fn balanceOf(self: @TState, account: ContractAddress) -> u256;
fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256;
fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool;
fn transfer_from(
fn transferFrom(
ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256
) -> bool;
fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool;
Expand Down
12 changes: 6 additions & 6 deletions contracts/cairo/src/tests/test_escrow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ mod Escrow {
let (escrow, eth_token) = setup();

// check balance
assert(eth_token.balance_of(escrow.contract_address) == 0, 'init: wrong balance');
assert(eth_token.balance_of(MM_STARKNET()) == 0, 'init: wrong balance');
assert(eth_token.balanceOf(escrow.contract_address) == 0, 'init: wrong balance');
assert(eth_token.balanceOf(MM_STARKNET()) == 0, 'init: wrong balance');

start_prank(escrow.contract_address, USER());
let order = Order { recipient_address: 12345.try_into().unwrap(), amount: 500 };
let order_id = escrow.set_order(order);
stop_prank(escrow.contract_address);

// check balance
assert(eth_token.balance_of(escrow.contract_address) == 500, 'set_order: wrong balance ');
assert(eth_token.balance_of(MM_STARKNET()) == 0, 'set_order: wrong balance');
assert(eth_token.balanceOf(escrow.contract_address) == 500, 'set_order: wrong balance ');
assert(eth_token.balanceOf(MM_STARKNET()) == 0, 'set_order: wrong balance');

// check Order
assert(order_id == 0, 'wrong order_id');
Expand All @@ -104,7 +104,7 @@ mod Escrow {
// check Order
assert(escrow.get_order_used(order_id), 'wrong order used');
// check balance
assert(eth_token.balance_of(escrow.contract_address) == 0, 'withdraw: wrong balance');
assert(eth_token.balance_of(MM_STARKNET()) == 500, 'withdraw: wrong balance');
assert(eth_token.balanceOf(escrow.contract_address) == 0, 'withdraw: wrong balance');
assert(eth_token.balanceOf(MM_STARKNET()) == 500, 'withdraw: wrong balance');
}
}
2 changes: 1 addition & 1 deletion contracts/solidity/src/YABTransfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.21;
contract YABTransfer {
struct TransferInfo {
uint256 destAddress;
uint128 amount;
uint256 amount;
bool isUsed;
}

Expand Down