-
Notifications
You must be signed in to change notification settings - Fork 3
Implement deposit_fiat and withdraw_fiat functions #7
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
Changes from all commits
f62dc1b
be5a87c
1580408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ mod Account { | |
| use starknet::{ClassHash, ContractAddress, get_caller_address}; | ||
| use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; | ||
|
|
||
|
|
||
| component!(path: AccountComponent, storage: account, event: AccountEvent); | ||
| component!(path: SRC5Component, storage: src5, event: SRC5Event); | ||
| component!(path: SRC9Component, storage: src9, event: SRC9Event); | ||
|
|
@@ -66,6 +65,8 @@ mod Account { | |
| #[flat] | ||
| UpgradeableEvent: UpgradeableComponent::Event, | ||
| TokenApproved: TokenApproved, | ||
| FiatDeposit: FiatDeposit, | ||
| FiatWithdrawal: FiatWithdrawal, | ||
| } | ||
|
|
||
| #[derive(Drop, starknet::Event)] | ||
|
|
@@ -76,6 +77,21 @@ mod Account { | |
| pub amount: u128, | ||
| } | ||
|
|
||
| #[derive(Drop, starknet::Event)] | ||
| pub struct FiatDeposit { | ||
| pub user: ContractAddress, | ||
| pub currency: felt252, | ||
| pub amount: u128, | ||
| } | ||
|
|
||
| #[derive(Drop, starknet::Event)] | ||
| pub struct FiatWithdrawal { | ||
| pub account_address: ContractAddress, | ||
| pub currency: felt252, | ||
| pub amount: u128, | ||
| pub recipient: ContractAddress, | ||
| } | ||
|
|
||
| #[constructor] | ||
| fn constructor(ref self: ContractState, public_key: felt252) { | ||
| self.account.initializer(public_key); | ||
|
|
@@ -94,7 +110,6 @@ mod Account { | |
| } | ||
| } | ||
|
|
||
|
|
||
| // contract impl | ||
| #[abi(embed_v0)] | ||
| impl AccountImpl of Iaccount<ContractState> { | ||
|
|
@@ -159,6 +174,24 @@ mod Account { | |
| fn get_initialized_status(self: @ContractState) -> bool { | ||
| self.initialized.read() | ||
| } | ||
|
|
||
| // -- New functions added here -- | ||
|
|
||
| fn deposit_fiat(ref self: ContractState, currency: felt252, amount: u128) { | ||
| assert(amount > 0, 'Amount must be > 0'); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| let caller = get_caller_address(); | ||
| let current_balance = self.fiat_balance.read((caller, currency)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to check if the user have sufficient balance
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I have sir |
||
| self.fiat_balance.write((caller, currency), current_balance + amount); | ||
| self.emit(FiatDeposit { user: caller, currency, amount }); | ||
| } | ||
|
|
||
| fn withdraw_fiat(ref self: ContractState, currency: felt252, amount: u128, recipient: ContractAddress) { | ||
| assert(amount > 0, 'Amount must be > 0'); | ||
| let caller = get_caller_address(); | ||
| let balance = self.fiat_balance.read((caller, currency)); | ||
| assert(balance >= amount, 'Insufficient balance'); | ||
| self.fiat_balance.write((caller, currency), balance - amount); | ||
| self.emit(FiatWithdrawal { account_address: caller, currency, amount, recipient }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert takes in felt252, therefore you should use single quotes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert that currency is provided