-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rewrite the entire project in Cairo (1) (#58)
Rewrites all the contracts and tests in Cairo, aka. Cairo 1.
- Loading branch information
1 parent
89d2fde
commit 482d14f
Showing
98 changed files
with
7,362 additions
and
7,262 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
.pytest_cache/ | ||
__pycache__/ | ||
/build/ |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1 @@ | ||
.pytest_cache/ | ||
__pycache__/ | ||
/build/ | ||
/dependencies/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[crate_roots] | ||
zklend = "src" | ||
tests = "tests" |
Submodule cairo-contracts
deleted from
70cbd0
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,10 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname "$0" )" &> /dev/null && pwd ) | ||
REPO_ROOT=$( cd -- "$( dirname $( dirname "$0" ) )" &> /dev/null && pwd ) | ||
|
||
docker run --rm \ | ||
-v "${REPO_ROOT}:/work" \ | ||
--entrypoint "cairo-format" \ | ||
starknet/cairo:2.1.0-rc2 \ | ||
-c -r /work |
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/// A central oracle hub for connecting to different upstream oracles and exposing a single getter | ||
/// to the core protocol. | ||
#[starknet::contract] | ||
mod DefaultPriceOracle { | ||
use starknet::ContractAddress; | ||
|
||
// Hack to simulate the `crate` keyword | ||
use super::super as crate; | ||
|
||
use crate::interfaces::{ | ||
IDefaultPriceOracle, IPriceOracle, IPriceOracleSourceDispatcher, | ||
IPriceOracleSourceDispatcherTrait, PriceWithUpdateTime | ||
}; | ||
use crate::libraries::ownable; | ||
|
||
#[storage] | ||
struct Storage { | ||
// token -> source | ||
sources: LegacyMap::<ContractAddress, ContractAddress>, | ||
// Unlike in `ZToken`, we don't need to maintain storage compatibility here as this | ||
// contract is not upgradeable. | ||
owner: ContractAddress | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
TokenSourceChanged: TokenSourceChanged, | ||
OwnershipTransferred: OwnershipTransferred, | ||
} | ||
|
||
#[derive(Drop, PartialEq, starknet::Event)] | ||
struct TokenSourceChanged { | ||
token: ContractAddress, | ||
source: ContractAddress | ||
} | ||
|
||
#[derive(Drop, PartialEq, starknet::Event)] | ||
struct OwnershipTransferred { | ||
previous_owner: ContractAddress, | ||
new_owner: ContractAddress, | ||
} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState, owner: ContractAddress) { | ||
ownable::initializer(ref self, owner); | ||
} | ||
|
||
#[external(v0)] | ||
impl IPriceOracleImpl of IPriceOracle<ContractState> { | ||
fn get_price(self: @ContractState, token: ContractAddress) -> felt252 { | ||
let source = self.sources.read(token); | ||
IPriceOracleSourceDispatcher { contract_address: source }.get_price() | ||
} | ||
|
||
fn get_price_with_time( | ||
self: @ContractState, token: ContractAddress | ||
) -> PriceWithUpdateTime { | ||
let source = self.sources.read(token); | ||
IPriceOracleSourceDispatcher { contract_address: source }.get_price_with_time() | ||
} | ||
} | ||
|
||
#[external(v0)] | ||
impl IDefaultPriceOracleImpl of IDefaultPriceOracle<ContractState> { | ||
fn set_token_source( | ||
ref self: ContractState, token: ContractAddress, source: ContractAddress | ||
) { | ||
ownable::assert_only_owner(@self); | ||
|
||
self.sources.write(token, source); | ||
|
||
self.emit(Event::TokenSourceChanged(TokenSourceChanged { token, source })); | ||
} | ||
} | ||
|
||
impl DefaultPriceOracleOwnable of ownable::Ownable<ContractState> { | ||
fn read_owner(self: @ContractState) -> ContractAddress { | ||
self.owner.read() | ||
} | ||
|
||
fn write_owner(ref self: ContractState, owner: ContractAddress) { | ||
self.owner.write(owner); | ||
} | ||
|
||
fn emit_ownership_transferred( | ||
ref self: ContractState, previous_owner: ContractAddress, new_owner: ContractAddress | ||
) { | ||
self | ||
.emit( | ||
Event::OwnershipTransferred(OwnershipTransferred { previous_owner, new_owner }) | ||
); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.