Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[framework] Release Framework v13 #2716

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ jobs:
chmod 600 private_key.pem
sudo apt update
sudo apt install -y --no-install-recommends openssh-server
ssh -o StrictHostKeyChecking=no -i private_key.pem $USER@$HOST bash -c "'sleep 30' && docker image prune -a -f && docker ps | grep main_debug | awk '{print \$1}' | xargs -r docker stop && docker ps -a | grep main_debug | awk '{print \$1}' | xargs -r docker rm -f && docker pull 'ghcr.io/rooch-network/rooch:main_debug' && docker run --rm -v /root:/root ghcr.io/rooch-network/rooch:main_debug server clean -n dev -f && docker run -d -v /root:/root -p 6767:6767 -p 9184:9184 'ghcr.io/rooch-network/rooch:main_debug' server start -n dev --btc-rpc-url '${{secrets.BTC_REGTEST_RPC_URL}}' --btc-rpc-username rooch-regtest --btc-rpc-password '${{secrets.BTC_REGTEST_RPC_PWD}}' --da '{\"internal-da-server\": {\"servers\": [{\"open-da\": {\"scheme\": \"fs\"}}]}}'"
ssh -o StrictHostKeyChecking=no -i private_key.pem $USER@$HOST bash -c "'sleep 30' && docker image prune -a -f && docker ps | grep main_debug | awk '{print \$1}' | xargs -r docker stop && docker ps -a | grep main_debug | awk '{print \$1}' | xargs -r docker rm -f && docker pull 'ghcr.io/rooch-network/rooch:main_debug' && docker run --rm -v /root:/root ghcr.io/rooch-network/rooch:main_debug server clean -n dev -f && docker run -d -v /root:/root -p 6767:6767 -p 9184:9184 'ghcr.io/rooch-network/rooch:main_debug' server start -n dev --btc-rpc-url '${{secrets.BTC_REGTEST_RPC_URL}}' --btc-rpc-username rooch-regtest --btc-rpc-password '${{secrets.BTC_REGTEST_RPC_PWD}}' --da '{\"internal-da-server\": {\"servers\": [{\"open-da\": {\"scheme\": \"fs\"}}]}}' --traffic-burst-size 100000 --traffic-per-second 10000"
ssh -o StrictHostKeyChecking=no -i private_key.pem $USER@$HOST "cd /root/rooch && git pull origin main && bash scripts/check_dev_deploy_status.sh main_debug '${{ secrets.TESTNET_MNEMONIC_PHRASE }}'"
26 changes: 22 additions & 4 deletions crates/rooch-oracle/src/aggregator_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ impl AggregateStrategy {
sum += d.value;
}
let avg = sum / U256::from(data.len() as u64);
let last_data = data.last().unwrap();
OracleDecimalData {
value: avg,
decimal: data[0].decimal,
decimal: last_data.decimal,
timestamp: last_data.timestamp,
}
}
AggregateStrategy::Median => {
Expand All @@ -70,9 +72,11 @@ impl AggregateStrategy {
} else {
sorted_data[mid].value
};
let last_data = data.last().unwrap();
OracleDecimalData {
value: median,
decimal: data[0].decimal,
decimal: last_data.decimal,
timestamp: last_data.timestamp,
}
}
AggregateStrategy::Mode => {
Expand All @@ -81,9 +85,11 @@ impl AggregateStrategy {
*freq_map.entry(d.value).or_insert(0) += 1;
}
let mode = freq_map.iter().max_by_key(|&(_, count)| count).unwrap().0;
let last_data = data.last().unwrap();
OracleDecimalData {
value: *mode,
decimal: data[0].decimal,
decimal: last_data.decimal,
timestamp: last_data.timestamp,
}
}
}
Expand Down Expand Up @@ -151,26 +157,32 @@ mod tests {
OracleDecimalData {
value: U256::from(100u64),
decimal: 2,
timestamp: 0,
},
OracleDecimalData {
value: U256::from(200u64),
decimal: 2,
timestamp: 0,
},
OracleDecimalData {
value: U256::from(300u64),
decimal: 2,
timestamp: 0,
},
OracleDecimalData {
value: U256::from(400u64),
decimal: 2,
timestamp: 0,
},
OracleDecimalData {
value: U256::from(500u64),
decimal: 2,
timestamp: 0,
},
OracleDecimalData {
value: U256::from(100u64),
decimal: 2,
timestamp: 0,
}, //two 100s
];

Expand All @@ -193,22 +205,27 @@ mod tests {
Ok(OracleDecimalData {
value: U256::from(100u64),
decimal: 2,
timestamp: 0,
}),
Ok(OracleDecimalData {
value: U256::from(200u64),
decimal: 2,
timestamp: 0,
}),
Ok(OracleDecimalData {
value: U256::from(300u64),
decimal: 2,
timestamp: 0,
}),
Ok(OracleDecimalData {
value: U256::from(400u64),
decimal: 2,
timestamp: 0,
}),
Ok(OracleDecimalData {
value: U256::from(500u64),
decimal: 2,
timestamp: 0,
}),
]);
let mut agg_stream = AggregatorStream::new(data_stream, AggregateStrategy::Average);
Expand All @@ -218,7 +235,8 @@ mod tests {
result,
Some(OracleDecimalData {
value: U256::from(300u64),
decimal: 2
decimal: 2,
timestamp: 0,
})
);
}
Expand Down
9 changes: 7 additions & 2 deletions crates/rooch-oracle/src/data_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub fn subscribe_websocket(
while let Some(message) = read.next().await {
match message {
Ok(Message::Text(text)) => {
info!("Received message: {}", text);
if let Err(e) =
tx.try_send(serde_json::from_str(&text).map_err(|e| anyhow::anyhow!(e)))
{
Expand Down Expand Up @@ -198,6 +199,7 @@ pub async fn execute_submit_data_tx(
data.value,
data.decimal,
identifier,
data.timestamp,
admin_obj,
);
let tx_data = wallet_context.build_tx_data(sender, action, None).await?;
Expand All @@ -206,8 +208,11 @@ pub async fn execute_submit_data_tx(
Ok(tx) => match tx.execution_info.status {
KeptVMStatusView::Executed => {
info!(
"Submit data success, value: {}, tx_hash: {}, gas_used:{}",
data.value, tx.execution_info.tx_hash, tx.execution_info.gas_used
"Submit data value: {}, timestamp:{}, tx_hash: {}, gas_used:{}",
data.value,
data.timestamp,
tx.execution_info.tx_hash,
tx.execution_info.gas_used
);
}
_ => {
Expand Down
4 changes: 4 additions & 0 deletions crates/rooch-oracle/src/datasource/binance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ fn parse_data(response: Value) -> Result<OracleDecimalData> {
.ok_or_else(|| anyhow!("c field not found in response: {}", response))?
.parse::<f64>()?
* 10f64.powi(8);
let e = response["E"]
.as_u64()
.ok_or_else(|| anyhow!("E field not found in response: {}", response))?;
Ok(OracleDecimalData {
value: U256::from(c as u64),
decimal: 8,
timestamp: e,
})
}
1 change: 1 addition & 0 deletions crates/rooch-oracle/src/datasource/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl Display for Ticker {
pub struct OracleDecimalData {
pub value: U256,
pub decimal: u8,
pub timestamp: u64,
}

#[async_trait]
Expand Down
5 changes: 5 additions & 0 deletions crates/rooch-oracle/src/datasource/okx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ fn parse_data(response: Value) -> Result<OracleDecimalData> {
.ok_or_else(|| anyhow!("last field not found in response: {}", response))?
.parse::<f64>()?
* 10f64.powi(8);
let ts = response["data"][0]["ts"]
.as_str()
.ok_or_else(|| anyhow!("ts field not found in response: {}", response))?
.parse::<u64>()?;
Ok(OracleDecimalData {
value: U256::from(last as u64),
decimal: 8,
timestamp: ts,
})
}
4 changes: 4 additions & 0 deletions crates/rooch-oracle/src/datasource/pyth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ fn parse_data(response: Value) -> Result<OracleDecimalData> {
.as_str()
.ok_or_else(|| anyhow!("price field not found in response: {}", response))?
.parse::<U256>()?;
let publish_time = response["parsed"][0]["ema_price"]["publish_time"]
.as_u64()
.ok_or_else(|| anyhow!("publish_time field not found in response: {}", response))?;
Ok(OracleDecimalData {
value: price,
decimal: 8,
timestamp: publish_time * 1000,
})
}
2 changes: 2 additions & 0 deletions crates/rooch-types/src/framework/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl OracleModule {
value: U256,
decimal: u8,
identifier: String,
timestamp: u64,
admin_obj: ObjectID,
) -> MoveAction {
Self::create_move_action(
Expand All @@ -76,6 +77,7 @@ impl OracleModule {
MoveValue::U256(value),
MoveValue::U8(decimal),
MoveString::from(identifier).to_move_value(),
MoveValue::U64(timestamp),
admin_obj.to_move_value(),
],
)
Expand Down
13 changes: 7 additions & 6 deletions crates/testsuite/features/portal.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,35 @@ Feature: Rooch Portal contract tests
Then cmd: "object -t default::gas_market::RGasMarket"
Then cmd: "object -t default::gas_faucet::RGasFaucet"
Then cmd: "object -t default::admin::AdminCap"
Then cmd: "object -t moveos_std::timestamp::Timestamp"

# submit the oracle price, require at least two record
Then cmd: "move run --function rooch_framework::oracle::create_entry --args string:oracle1 --args string:oracle1_url --args string:oracle1_desc --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "event get-events-by-event-handle -t rooch_framework::oracle::NewOracleEvent --limit 1 -d true"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:1 --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:1 --args u64:{{$.object[3].data[0].updated_at}} --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:1 --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:1 --args u64:{{$.object[3].data[0].updated_at}} --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function default::trusted_oracle::add_trusted_oracle --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args object:{{$.object[2].data[0].id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

Then cmd: "move run --function rooch_framework::oracle::create_entry --args string:oracle2 --args string:oracle2_url --args string:oracle2_desc --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "event get-events-by-event-handle -t rooch_framework::oracle::NewOracleEvent --limit 1 -d true"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:2 --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:2 --args u64:{{$.object[3].data[0].updated_at}} --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:2 --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:2 --args u64:{{$.object[3].data[0].updated_at}} --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function default::trusted_oracle::add_trusted_oracle --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args object:{{$.object[2].data[0].id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"

Then cmd: "move run --function rooch_framework::oracle::create_entry --args string:oracle3 --args string:oracle3_url --args string:oracle3_desc --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "event get-events-by-event-handle -t rooch_framework::oracle::NewOracleEvent --limit 1 -d true"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:3 --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:3 --args u64:{{$.object[3].data[0].updated_at}} --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:3 --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then cmd: "move run --function rooch_framework::oracle::submit_decimal_data --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args string:BTCUSD --args u256:5805106000000 --args u8:8 --args string:3 --args u64:{{$.object[3].data[0].updated_at}} --args object:{{$.event[-1].data[0].decoded_event_data.value.admin_id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Then cmd: "move run --function default::trusted_oracle::add_trusted_oracle --args object:{{$.event[-1].data[0].decoded_event_data.value.oracle_id}} --args object:{{$.object[2].data[0].id}} --json"
Then assert: "{{$.move[-1].execution_info.status.type}} == executed"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions frameworks/framework-release/released/13/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Rooch Move Framework v13

* [moveos_std] Implement base64 encode and decode in base64 module.
* [moveos_std] Enhancement json support.
* [rooch_nursery] Cosmwasm support Poc implementation.
* [rooch_framework] Add entry function and NewOracleEvent for oracle module.
Binary file not shown.
18 changes: 17 additions & 1 deletion frameworks/rooch-framework/doc/oracle.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- [Function `create_entry`](#0x3_oracle_create_entry)
- [Function `create`](#0x3_oracle_create)
- [Function `submit_data`](#0x3_oracle_submit_data)
- [Function `submit_data_with_timestamp`](#0x3_oracle_submit_data_with_timestamp)
- [Function `submit_decimal_data`](#0x3_oracle_submit_decimal_data)
- [Function `archive_data`](#0x3_oracle_archive_data)

Expand Down Expand Up @@ -168,13 +169,28 @@ Create a new SimpleOracle object for publishing data.



<a name="0x3_oracle_submit_data_with_timestamp"></a>

## Function `submit_data_with_timestamp`

Submit data with timestamp.
This function is used to submit data with a specific timestamp.
The timestamp is the time from the oracle's data source.
The timestamp is measured in milliseconds.


<pre><code><b>public</b> <b>fun</b> <a href="oracle.md#0x3_oracle_submit_data_with_timestamp">submit_data_with_timestamp</a>&lt;T: <b>copy</b>, drop, store&gt;(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, value: T, identifier: <a href="_String">string::String</a>, <a href="">timestamp</a>: u64, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_OracleAdminCap">oracle::OracleAdminCap</a>&gt;)
</code></pre>



<a name="0x3_oracle_submit_decimal_data"></a>

## Function `submit_decimal_data`



<pre><code><b>public</b> entry <b>fun</b> <a href="oracle.md#0x3_oracle_submit_decimal_data">submit_decimal_data</a>(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, value: <a href="">u256</a>, decimal: u8, identifier: <a href="_String">string::String</a>, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_OracleAdminCap">oracle::OracleAdminCap</a>&gt;)
<pre><code><b>public</b> entry <b>fun</b> <a href="oracle.md#0x3_oracle_submit_decimal_data">submit_decimal_data</a>(oracle_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_SimpleOracle">oracle::SimpleOracle</a>&gt;, ticker: <a href="_String">string::String</a>, value: <a href="">u256</a>, decimal: u8, identifier: <a href="_String">string::String</a>, <a href="">timestamp</a>: u64, admin_obj: &<b>mut</b> <a href="_Object">object::Object</a>&lt;<a href="oracle.md#0x3_oracle_OracleAdminCap">oracle::OracleAdminCap</a>&gt;)
</code></pre>


Expand Down
Loading
Loading