-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3055f3d
commit fa62f10
Showing
15 changed files
with
114 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
scarb 2.6.5 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "library_call" | ||
version = "0.1.0" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "library_call" | ||
version = "0.1.0" | ||
edition = "2023_11" | ||
|
||
[dependencies] | ||
starknet = "2.6.4" | ||
|
||
[[target.starknet-contract]] | ||
casm = true | ||
sierra = true | ||
casm-add-pythonic-hints = true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use core::starknet::{get_caller_address, ContractAddress}; | ||
|
||
|
||
#[starknet::interface] | ||
pub 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 allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; | ||
fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; | ||
fn transfer_from( | ||
ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 | ||
) -> bool; | ||
fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; | ||
} | ||
|
||
#[starknet::contract] | ||
pub mod BalanceSender { | ||
use core::starknet::{get_caller_address, ContractAddress, ClassHash, get_contract_address, SyscallResult}; | ||
use super::{IERC20Dispatcher, IERC20DispatcherTrait}; | ||
use core::starknet::syscalls::{replace_class_syscall}; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[external(v0)] | ||
fn send_balance(self: @ContractState, token_address: ContractAddress, recipient: ContractAddress) -> bool { | ||
let erc20_dispatcher = IERC20Dispatcher { contract_address: token_address }; | ||
let balance = erc20_dispatcher.balance_of(get_contract_address()); | ||
erc20_dispatcher.transfer(recipient, balance) | ||
} | ||
|
||
#[external(v0)] | ||
fn replace_class(ref self: ContractState, new_class: ClassHash) -> SyscallResult<()>{ | ||
replace_class_syscall(new_class) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod universal_library_caller; | ||
|
||
mod balance_sender; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use starknet::{ | ||
SyscallResult, storage_access::StorageAddress, class_hash::ClassHash, | ||
}; | ||
|
||
|
||
#[starknet::interface] | ||
pub trait IUniversalLibraryCaller<TContractState> { | ||
fn library_call(self: @TContractState, class_hash: ClassHash, function_selector: felt252, calldata: Span<felt252>) -> SyscallResult<Span<felt252>>; | ||
} | ||
|
||
#[starknet::contract] | ||
pub mod UniversalLibraryCaller { | ||
use starknet::syscalls::library_call_syscall; | ||
use starknet::{ | ||
SyscallResult, storage_access::StorageAddress, class_hash::ClassHash, | ||
}; | ||
|
||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[abi(embed_v0)] | ||
impl UniversalLibraryCallerImpl of super::IUniversalLibraryCaller<ContractState> { | ||
fn library_call(self: @ContractState, class_hash: ClassHash, function_selector: felt252, calldata: Span<felt252>) -> SyscallResult<Span<felt252>> { | ||
library_call_syscall(class_hash, function_selector, calldata) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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