Skip to content

Commit

Permalink
review fix : lock_from
Browse files Browse the repository at this point in the history
  • Loading branch information
chachaleo committed Sep 4, 2024
1 parent 2460ded commit a244047
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 0 additions & 1 deletion contracts/src/components/escrow.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod escrow;
pub mod interface;


21 changes: 19 additions & 2 deletions contracts/src/components/escrow/escrow.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub mod EscrowComponent {
struct Storage {
// (owner, token) -> amount
deposits: Map::<(ContractAddress, ContractAddress), u256>,
// token -> escrow address
escrow_contract_addresses: Map::<ContractAddress, ContractAddress>,
}

//
Expand All @@ -38,8 +40,20 @@ pub mod EscrowComponent {
token: ContractAddress,
amount: u256
) {
let erc20_dispatcher = IERC20Dispatcher { contract_address: token };

let balance = erc20_dispatcher.balance_of(from);

assert(balance >= amount, Errors::INSUFFICIENT_BALANCE);

let locked_amount = self.deposits.read((from, token));

// Retreives escrow address for the token `token``
let escrow_contract_address = self.escrow_contract_addresses.read(token);

// Transfers funds to escrow
transfer_erc20(from, escrow_contract_address, token, amount);

self.deposits.write((from, token), amount + locked_amount);
}

Expand All @@ -50,18 +64,21 @@ pub mod EscrowComponent {
token: ContractAddress,
amount: u256
) {
let escrow_contract_address = self.escrow_contract_addresses.read(token);

let locked_amount = self.deposits.read((from, token));

// TODO
// check for proof of deposit
assert(true, Errors::PROOF_OF_DEPOSIT_FAILED);

// check deposit balance
assert(locked_amount >= amount, Errors::INSUFFICIENT_BALANCE);

// transfert of the amount `amount` from `from` to `to`
transfer_erc20(from, to, token, amount);
transfer_erc20(escrow_contract_address, to, token, amount);

// update locked amount
// update locked amount
self.deposits.write((from, token), locked_amount - amount);
}
}
Expand Down

0 comments on commit a244047

Please sign in to comment.