-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(target_chains/starknet): pyth contract upgrade (#1592)
* feat(target_chains/starknet): pyth contract upgrade * doc(target_chains/starknet): add comment about class hash for contract upgrade
- Loading branch information
Showing
8 changed files
with
367 additions
and
11 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
105 changes: 105 additions & 0 deletions
105
target_chains/starknet/contracts/src/pyth/fake_upgrades.cairo
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,105 @@ | ||
// Only used for tests. | ||
|
||
#[starknet::contract] | ||
mod pyth_fake_upgrade1 { | ||
use pyth::pyth::{IPyth, GetPriceUnsafeError, DataSource, Price}; | ||
use pyth::byte_array::ByteArray; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) {} | ||
|
||
#[abi(embed_v0)] | ||
impl PythImpl of IPyth<ContractState> { | ||
fn get_price_unsafe( | ||
self: @ContractState, price_id: u256 | ||
) -> Result<Price, GetPriceUnsafeError> { | ||
let price = Price { price: 42, conf: 2, expo: -5, publish_time: 101, }; | ||
Result::Ok(price) | ||
} | ||
fn get_ema_price_unsafe( | ||
self: @ContractState, price_id: u256 | ||
) -> Result<Price, GetPriceUnsafeError> { | ||
panic!("unsupported") | ||
} | ||
fn set_data_sources(ref self: ContractState, sources: Array<DataSource>) { | ||
panic!("unsupported") | ||
} | ||
fn set_fee(ref self: ContractState, single_update_fee: u256) { | ||
panic!("unsupported") | ||
} | ||
fn update_price_feeds(ref self: ContractState, data: ByteArray) { | ||
panic!("unsupported") | ||
} | ||
fn execute_governance_instruction(ref self: ContractState, data: ByteArray) { | ||
panic!("unsupported") | ||
} | ||
fn pyth_upgradable_magic(self: @ContractState) -> u32 { | ||
0x97a6f304 | ||
} | ||
} | ||
} | ||
|
||
#[starknet::contract] | ||
mod pyth_fake_upgrade_wrong_magic { | ||
use pyth::pyth::{IPyth, GetPriceUnsafeError, DataSource, Price}; | ||
use pyth::byte_array::ByteArray; | ||
|
||
#[storage] | ||
struct Storage {} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) {} | ||
|
||
#[abi(embed_v0)] | ||
impl PythImpl of IPyth<ContractState> { | ||
fn get_price_unsafe( | ||
self: @ContractState, price_id: u256 | ||
) -> Result<Price, GetPriceUnsafeError> { | ||
panic!("unsupported") | ||
} | ||
fn get_ema_price_unsafe( | ||
self: @ContractState, price_id: u256 | ||
) -> Result<Price, GetPriceUnsafeError> { | ||
panic!("unsupported") | ||
} | ||
fn set_data_sources(ref self: ContractState, sources: Array<DataSource>) { | ||
panic!("unsupported") | ||
} | ||
fn set_fee(ref self: ContractState, single_update_fee: u256) { | ||
panic!("unsupported") | ||
} | ||
fn update_price_feeds(ref self: ContractState, data: ByteArray) { | ||
panic!("unsupported") | ||
} | ||
fn execute_governance_instruction(ref self: ContractState, data: ByteArray) { | ||
panic!("unsupported") | ||
} | ||
fn pyth_upgradable_magic(self: @ContractState) -> u32 { | ||
606 | ||
} | ||
} | ||
} | ||
|
||
#[starknet::interface] | ||
pub trait INotPyth<T> { | ||
fn test1(ref self: T) -> u32; | ||
} | ||
|
||
#[starknet::contract] | ||
mod pyth_fake_upgrade_not_pyth { | ||
#[storage] | ||
struct Storage {} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState) {} | ||
|
||
#[abi(embed_v0)] | ||
impl NotPythImpl of super::INotPyth<ContractState> { | ||
fn test1(ref self: ContractState) -> u32 { | ||
42 | ||
} | ||
} | ||
} |
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
Oops, something went wrong.