Skip to content

Commit a8dbabc

Browse files
authored
feat(target_chains/starknet): add fee configuration (#1525)
1 parent cae194e commit a8dbabc

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

target_chains/starknet/contracts/deploy/local_deploy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ wormhole_hash=$(starkli declare target/dev/pyth_wormhole.contract_class.json)
2222
# prefunded katana account
2323
owner=0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb46e03
2424

25+
fee_token_address=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
26+
2527
# deploying wormhole with mainnet guardians
2628

2729
${sleep}
@@ -117,6 +119,8 @@ ${sleep}
117119
pyth_address=$(starkli deploy "${pyth_hash}" \
118120
"${owner}" \
119121
"${wormhole_address}" \
122+
"${fee_token_address}" \
123+
1000 0 `# fee amount` \
120124
1 `# num_data_sources` \
121125
26 `# emitter_chain_id` \
122126
58051393581875729396504816158954007153 299086580781278228892874716333010393740 `# emitter_address` \

target_chains/starknet/contracts/src/pyth.cairo

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub use pyth::{Event, PriceFeedUpdateEvent};
99
pub trait IPyth<T> {
1010
fn get_price_unsafe(self: @T, price_id: u256) -> Result<Price, GetPriceUnsafeError>;
1111
fn get_ema_price_unsafe(self: @T, price_id: u256) -> Result<Price, GetPriceUnsafeError>;
12-
fn set_data_sources(ref self: T, sources: Array<DataSource>) -> Result<(), SetDataSourcesError>;
12+
fn set_data_sources(
13+
ref self: T, sources: Array<DataSource>
14+
) -> Result<(), GovernanceActionError>;
15+
fn set_fee(ref self: T, single_update_fee: u256) -> Result<(), GovernanceActionError>;
1316
fn update_price_feeds(ref self: T, data: ByteArray) -> Result<(), UpdatePriceFeedsError>;
1417
}
1518

@@ -35,25 +38,24 @@ impl GetPriceUnsafeErrorIntoFelt252 of Into<GetPriceUnsafeError, felt252> {
3538
}
3639
}
3740

38-
3941
#[derive(Copy, Drop, Debug, Serde, PartialEq)]
40-
pub enum SetDataSourcesError {
42+
pub enum GovernanceActionError {
4143
AccessDenied,
4244
}
4345

44-
pub impl SetDataSourcesErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, SetDataSourcesError> {
45-
fn unwrap_with_felt252(self: Result<T, SetDataSourcesError>) -> T {
46+
pub impl GovernanceActionErrorUnwrapWithFelt252<T> of UnwrapWithFelt252<T, GovernanceActionError> {
47+
fn unwrap_with_felt252(self: Result<T, GovernanceActionError>) -> T {
4648
match self {
4749
Result::Ok(v) => v,
4850
Result::Err(err) => core::panic_with_felt252(err.into()),
4951
}
5052
}
5153
}
5254

53-
impl SetDataSourcesErrorIntoFelt252 of Into<SetDataSourcesError, felt252> {
54-
fn into(self: SetDataSourcesError) -> felt252 {
55+
impl GovernanceActionErrorIntoFelt252 of Into<GovernanceActionError, felt252> {
56+
fn into(self: GovernanceActionError) -> felt252 {
5557
match self {
56-
SetDataSourcesError::AccessDenied => 'access denied',
58+
GovernanceActionError::AccessDenied => 'access denied',
5759
}
5860
}
5961
}
@@ -116,10 +118,10 @@ mod pyth {
116118
use pyth::reader::{Reader, ReaderImpl};
117119
use pyth::byte_array::{ByteArray, ByteArrayImpl};
118120
use core::panic_with_felt252;
119-
use core::starknet::{ContractAddress, get_caller_address};
121+
use core::starknet::{ContractAddress, get_caller_address, get_execution_info};
120122
use pyth::wormhole::{IWormholeDispatcher, IWormholeDispatcherTrait};
121123
use super::{
122-
DataSource, UpdatePriceFeedsError, PriceInfo, SetDataSourcesError, Price,
124+
DataSource, UpdatePriceFeedsError, PriceInfo, GovernanceActionError, Price,
123125
GetPriceUnsafeError
124126
};
125127
use pyth::merkle_tree::{read_and_verify_proof, MerkleVerificationError};
@@ -220,6 +222,8 @@ mod pyth {
220222
#[storage]
221223
struct Storage {
222224
wormhole_address: ContractAddress,
225+
fee_contract_address: ContractAddress,
226+
single_update_fee: u256,
223227
owner: ContractAddress,
224228
data_sources: LegacyMap<usize, DataSource>,
225229
num_data_sources: usize,
@@ -233,10 +237,14 @@ mod pyth {
233237
ref self: ContractState,
234238
owner: ContractAddress,
235239
wormhole_address: ContractAddress,
240+
fee_contract_address: ContractAddress,
241+
single_update_fee: u256,
236242
data_sources: Array<DataSource>
237243
) {
238244
self.owner.write(wormhole_address);
239245
self.wormhole_address.write(wormhole_address);
246+
self.fee_contract_address.write(fee_contract_address);
247+
self.single_update_fee.write(single_update_fee);
240248
write_data_sources(ref self, data_sources);
241249
}
242250

@@ -308,14 +316,24 @@ mod pyth {
308316

309317
fn set_data_sources(
310318
ref self: ContractState, sources: Array<DataSource>
311-
) -> Result<(), SetDataSourcesError> {
319+
) -> Result<(), GovernanceActionError> {
312320
if self.owner.read() != get_caller_address() {
313-
return Result::Err(SetDataSourcesError::AccessDenied);
321+
return Result::Err(GovernanceActionError::AccessDenied);
314322
}
315323
write_data_sources(ref self, sources);
316324
Result::Ok(())
317325
}
318326

327+
fn set_fee(
328+
ref self: ContractState, single_update_fee: u256
329+
) -> Result<(), GovernanceActionError> {
330+
if self.owner.read() != get_caller_address() {
331+
return Result::Err(GovernanceActionError::AccessDenied);
332+
}
333+
self.single_update_fee.write(single_update_fee);
334+
Result::Ok(())
335+
}
336+
319337
fn update_price_feeds(
320338
ref self: ContractState, data: ByteArray
321339
) -> Result<(), UpdatePriceFeedsError> {

target_chains/starknet/contracts/tests/pyth.cairo

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ fn update_price_feeds_works() {
3535
let pyth = deploy(
3636
owner,
3737
wormhole.contract_address,
38+
0x42.try_into().unwrap(),
39+
1000,
3840
array![
3941
DataSource {
4042
emitter_chain_id: 26,
@@ -78,10 +80,15 @@ fn update_price_feeds_works() {
7880
}
7981

8082
fn deploy(
81-
owner: ContractAddress, wormhole_address: ContractAddress, data_sources: Array<DataSource>
83+
owner: ContractAddress,
84+
wormhole_address: ContractAddress,
85+
fee_contract_address: ContractAddress,
86+
single_update_fee: u256,
87+
data_sources: Array<DataSource>
8288
) -> IPythDispatcher {
8389
let mut args = array![];
84-
(owner, wormhole_address, data_sources).serialize(ref args);
90+
(owner, wormhole_address, fee_contract_address, single_update_fee).serialize(ref args);
91+
data_sources.serialize(ref args);
8592
let contract = declare("pyth");
8693
let contract_address = match contract.deploy(@args) {
8794
Result::Ok(v) => { v },

0 commit comments

Comments
 (0)