Skip to content

Commit

Permalink
build: add init script for data_feed
Browse files Browse the repository at this point in the history
  • Loading branch information
chadoh committed Jul 22, 2024
1 parent ef3551b commit f2b619e
Show file tree
Hide file tree
Showing 3 changed files with 3,128 additions and 3,118 deletions.
63 changes: 32 additions & 31 deletions contracts/data-feed/src/data_feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,38 @@ impl IsSep40Admin for DataFeed {

fn set_price(&mut self, updates: Vec<i128>, timestamp: u64) {
Contract::require_auth();
let updates_len = updates.len();
if updates_len == 0 || updates_len >= 256 {
panic!("The assets update length or prices update length is invalid");
}
let timeframe: u64 = self.resolution.into();
let ledger_timestamp = now();
if timestamp == 0
|| !timestamp.is_valid_timestamp(timeframe)
|| timestamp > ledger_timestamp
{
panic!("The prices timestamp is invalid");
}

// from reflector implementation
// let retention_period = e.get_retention_period();

// let ledgers_to_live: u32 = ((retention_period / 1000 / 5) + 1) as u32;

//iterate over the updates
for (i, price) in updates.iter().enumerate() {
//don't store zero prices
if price == 0 {
continue;
}
let asset = i as u8;
//store the new price
e.set_price(asset, price, timestamp, ledgers_to_live);
}
if timestamp > self.last_timestamp {
self.last_timestamp = timestamp;
}
todo!();
// let updates_len = updates.len();
// if updates_len == 0 || updates_len >= 256 {
// panic!("The assets update length or prices update length is invalid");
// }
// let timeframe: u64 = self.resolution.into();
// let ledger_timestamp = now();
// if timestamp == 0
// || !timestamp.is_valid_timestamp(timeframe)
// || timestamp > ledger_timestamp
// {
// panic!("The prices timestamp is invalid");
// }
//
// // from reflector implementation
// // let retention_period = e.get_retention_period();
//
// // let ledgers_to_live: u32 = ((retention_period / 1000 / 5) + 1) as u32;
//
// //iterate over the updates
// for (i, price) in updates.iter().enumerate() {
// //don't store zero prices
// if price == 0 {
// continue;
// }
// let asset = i as u8;
// //store the new price
// e.set_price(asset, price, timestamp, ledgers_to_live);
// }
// if timestamp > self.last_timestamp {
// self.last_timestamp = timestamp;
// }
}
}

Expand Down
9 changes: 5 additions & 4 deletions environments.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ default = true
# You only need to specify the slop (everything after the `--`) for calls to
# `soroban contract invoke` for the given contract. Uses `default-account`
# by default; to use another, prefix with `SOROBAN_ACCOUNT=other-account`.
# init = """
# initialize --symbol ABND --decimal 7 --name abundance --admin me
# mint --amount 2000000 --to me"
# """
[development.contracts.data_feed]
init = """
admin_set --new-admin me
sep40_init --resolution 300000 --assets "[{\"Stellar\": \"$(stellar contract id asset --asset native)\"} ]" --decimals 14 --base "{\"Stellar"\:"\$(stellar contract id asset --asset native)"\}"
"""

# Coming Soon: Specify live contracts to bind & import in this project using the given name.
# During initialization, these contracts will also be "spooned" into the development network,
Expand Down
Loading

0 comments on commit f2b619e

Please sign in to comment.