Last active
June 12, 2023 10:47
-
-
Save codeWhizperer/e185e82911322e921434f4ddc88146e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[abi] | |
| trait IERC20 { | |
| #[view] | |
| fn get_name() -> felt252; | |
| #[view] | |
| fn get_symbol() -> felt252; | |
| #[view] | |
| fn total_supply() -> felt252; | |
| #[view] | |
| fn balance_of(account: ContractAddress) -> u256; | |
| #[view] | |
| fn allowance(owner: ContractAddress, spender: ContractAddress) -> u256; | |
| #[external] | |
| fn transfer(recipient: ContractAddress, amount: u256); | |
| #[external] | |
| fn transfer_from(sender: ContractAddress, recipient: ContractAddress, amount: u256); | |
| #[external] | |
| fn approve(spender: ContractAddress, amount: u256); | |
| } | |
| ////////////Contract Dispatcher | |
| #[contract] | |
| mod Dispatcher { | |
| use super::IERC20DispatcherTrait; | |
| use super::IERC20Dispatcher; | |
| use starknet::ContractAddress; | |
| #[view] | |
| fn token_supply( | |
| _contract_address: ContractAddress | |
| ) -> felt252 { | |
| IERC20Dispatcher {contract_address: _contract_address }.total_supply() | |
| } | |
| #[external] | |
| fn transfer_token( | |
| _contract_address: ContractAddress, recipient: ContractAddress, amount: u256 | |
| ) -> bool { | |
| IERC20Dispatcher {contract_address: _contract_address }.transfer(recipient, amount) | |
| } | |
| } | |
| /////////////////Library Dispatcher | |
| //**** Specify interface here ****// | |
| use super::IERC20DispatcherTrait; | |
| use super::IERC20LibraryDispatcher; | |
| use starknet::ContractAddress; | |
| #[view] | |
| fn token_supply() -> felt252 { | |
| IERC20LibraryDispatcher { class_hash: starknet::class_hash_const::<0x1234>() }.total_supply() | |
| } | |
| #[external] | |
| fn transfer_token( | |
| recipient: ContractAddress, amount: u256 | |
| ) -> bool { | |
| IERC20LibraryDispatcher { class_hash: starknet::class_hash_const::<0x1234>() }.transfer(recipient, amount) | |
| } | |
| /////////starknet::call_contract_syscall | |
| #[external] | |
| fn transfer_token( | |
| address: starknet::ContractAddress, selector: felt252, calldata: Array<felt252> | |
| ) -> Span::<felt252> { | |
| starknet::call_contract_syscall(address, selector, calldata.span()).unwrap_syscall() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment