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

feat: add deployment script #103

Closed
wants to merge 19 commits into from
Closed
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
12 changes: 6 additions & 6 deletions .github/workflows/Deploy-All.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.proxy_store_tx_hash }} --node ${nodeUrl} --output json)"
CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "Code ID is $CODE_ID"
echo "proxy_code_id=$CODE_ID" >> $GITHUB_ENV

Expand All @@ -133,7 +133,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.proxy_instantiate_tx_hash }} --node ${nodeUrl} --output json)"
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
echo "Contract address is $CONTRACT_ADDRESS"
echo "proxy_address=$CONTRACT_ADDRESS" >> $GITHUB_ENV

Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.dr_store_tx_hash }} --node ${nodeUrl} --output json)"
CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "Code ID is $CODE_ID"
echo "dr_code_id=$CODE_ID" >> $GITHUB_ENV

Expand All @@ -186,7 +186,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.dr_instantiate_tx_hash }} --node ${nodeUrl} --output json)"
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
echo "Contract address is $CONTRACT_ADDRESS"
echo "dr_address=$CONTRACT_ADDRESS" >> $GITHUB_ENV

Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.staking_store_tx_hash }} --node ${nodeUrl} --output json)"
CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "Code ID is $CODE_ID"
echo "staking_code_id=$CODE_ID" >> $GITHUB_ENV

Expand All @@ -239,7 +239,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.staking_instantiate_tx_hash }} --node ${nodeUrl} --output json)"
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
echo "Contract address is $CONTRACT_ADDRESS"
echo "staking_address=$CONTRACT_ADDRESS" >> $GITHUB_ENV

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.txhash }} --node ${nodeUrl} --output json)"
CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
CODE_ID=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "Code ID is $CODE_ID"
echo "code_id=$CODE_ID" >> $GITHUB_ENV

Expand Down Expand Up @@ -161,5 +161,5 @@ jobs:
run: |
nodeUrl=${{ env.NODE_URL }}
OUTPUT="$(./seda-chaind query tx ${{ env.txhash }} --node ${nodeUrl} --output json)"
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
echo "Contract address is $CONTRACT_ADDRESS"
27 changes: 21 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ overflow-checks = true
[workspace.dependencies]
anyhow = "1.0.75"
common = { path = "./packages/common" }
cosmwasm = "0.5"
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.4", features = ["staking"] }
cosmwasm-std = { version = "1.4", features = ["staking", "abort"] }
cosmwasm-storage = "1.1.3"
cosmwasm-vm = "1.5"
cw-storage-plus = "1.1"
cw2 = "1.1"
cw-utils = "1.0.1"
Expand Down
90 changes: 6 additions & 84 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUST_BACKTRACE=1 cargo unit-test

# auto-generate json schema
cargo schema -p data-requests
cargo schema -p proxy
cargo schema -p proxy-contract
cargo schema -p staking
```

Expand Down Expand Up @@ -87,91 +87,13 @@ Additionally, one may use [`cosmwasm-verify`](https://github.com/CosmWasm/cosmwa
## Uploading contracts and setting up cross-dependencies
To deploy and set up all contracts, the Proxy must first be instantiated followed by all of the other contracts, since the Proxy address is used as an argument when instantiating the other contracts. After all contracts are instantiated and to complete the circular dependency, the other contracts must then be set on the Proxy via Execute calls.

```bash
CHAIN_ID=seda-devnet | seda-testnet
```

Upload Proxy contract
```bash
OUTPUT="$(seda-chaind tx wasm store ./artifacts/proxy_contract.wasm --node $RPC_URL --from $DEV_ACCOUNT --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)"

TXHASH=$(echo $OUTPUT | jq -r '.txhash')

OUTPUT="$(seda-chaind query tx $TXHASH --node $RPC_URL --output json)"

PROXY_CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
```


Instantiate Proxy
```bash
OUTPUT=$(seda-chaind tx wasm instantiate $PROXY_CODE_ID '{"token":"aseda"}' --no-admin --from $DEV_ACCOUNT --node $RPC_URL --label proxy$PROXY_CODE_ID --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)

TXHASH=$(echo "$OUTPUT" | jq -r '.txhash')

OUTPUT="$(seda-chaind query tx $TXHASH --node $RPC_URL --output json)"

PROXY_CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
```

Upload DataRequests contract
```bash
OUTPUT="$(seda-chaind tx wasm store artifacts/data_requests.wasm --node $RPC_URL --from $DEV_ACCOUNT --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)"

TXHASH=$(echo $OUTPUT | jq -r '.txhash')

OUTPUT="$(seda-chaind query tx $dr_store_tx_hash --node $RPC_URL --output json)"

DRs_CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
```

Instantiate DataRequests

```bash
OUTPUT=$(seda-chaind tx wasm instantiate $DRs_CODE_ID '{"token":"aseda", "proxy": "'$PROXY_CONTRACT_ADDRESS'" }' --no-admin --from $DEV_ACCOUNT --node $RPC_URL --label dr$DRs_CODE_ID --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)

TXHASH=$(echo "$OUTPUT" | jq -r '.txhash')

OUTPUT="$(seda-chaind query tx $TXHASH --node $RPC_URL --output json)"

DRs_CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
```

Upload Staking contract
```bash
OUTPUT="$(seda-chaind tx wasm store artifacts/staking.wasm --node $RPC_URL --from $DEV_ACCOUNT --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)"

TXHASH=$(echo $OUTPUT | jq -r '.txhash')

OUTPUT="$(seda-chaind query tx $TXHASH --node $RPC_URL --output json)"

STAKING_CODE_ID=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
```

- Setup vars in `deploy.sh`, then run `bash deploy.sh`: <br>

Instantiate Staking
```bash
OUTPUT=$(seda-chaind tx wasm instantiate $STAKING_CODE_ID '{"token":"aseda", "proxy": "'$PROXY_CONTRACT_ADDRESS'" }' --no-admin --from $DEV_ACCOUNT --node $RPC_URL --label staking$staking_code_id --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)

TXHASH=$(echo "$OUTPUT" | jq -r '.txhash')

OUTPUT="$(seda-chaind query tx $TXHASH --node $RPC_URL --output json)"

STAKING_CONTRACT_ADDRESS=$(echo "$OUTPUT" | jq -r '.logs[].events[] | select(.type=="instantiate") | .attributes[] | select(.key=="_contract_address") | .value')
```

Set DataRequests on Proxy
```bash
OUTPUT="$(seda-chaind tx wasm execute $PROXY_CONTRACT_ADDRESS '{"set_data_requests":{"contract": "'$DRs_CONTRACT_ADDRESS'" }}' --from $DEV_ACCOUNT --node $RPC_URL --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)"

TXHASH=$(echo "$OUTPUT" | jq -r '.txhash')
```

Set Staking on Proxy
```bash
OUTPUT="$(seda-chaind tx wasm execute $PROXY_CONTRACT_ADDRESS '{"set_staking":{"contract": "'$STAKING_CONTRACT_ADDRESS'" }}' --from $DEV_ACCOUNT --node $RPC_URL --gas-prices 0.1aseda --gas auto --gas-adjustment 1.3 -y --output json --chain-id $CHAIN_ID)"

TXHASH=$(echo "$OUTPUT" | jq -r '.txhash')
CHAIN_ID="sedachain"|"seda-devnet"|"seda-testnet"
DEV_ACCOUNT="YOUR DEPLOYMENT ACCOUNT"
RPC_URL="CHAIN RPC URL"
KEYRING_BACKEND="KEYRING BACKEND PASS"
```


Expand Down
2 changes: 1 addition & 1 deletion packages/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cosmwasm-std = { workspace = true}
cw-utils = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod consts;
pub mod error;
pub mod msg;
pub mod querier;
pub mod state;
pub mod types;
28 changes: 27 additions & 1 deletion packages/common/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::state::{DataRequest, DataRequestExecutor, DataResult, Reveal, StakingConfig};
use crate::types::{Bytes, Commitment, Hash, Memo};
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Addr;
use cosmwasm_std::{Addr, CustomMsg, CustomQuery};
use std::collections::HashMap;

#[cw_serde]
Expand Down Expand Up @@ -78,6 +78,8 @@ pub enum DataRequestsQueryMsg {
GetRevealedDataResults { dr_id: Hash },
#[returns(GetResolvedDataResultResponse)]
GetResolvedDataResult { dr_id: Hash },
#[returns(QuerySeedResponse)]
QuerySeedRequest {},
}

#[cw_serde]
Expand Down Expand Up @@ -156,3 +158,27 @@ pub struct InstantiateMsg {
pub token: String,
pub proxy: String,
}

#[cw_serde]

pub enum SpecialQueryMsg {
QuerySeedRequest {},
}

#[cw_serde]

pub struct QuerySeedResponse {
pub block_height: u64,
pub seed: String,
}

/// SpecialQueryWrapper is an override of QueryRequest::Custom to access seda-specific modules
#[cw_serde]

pub struct SpecialQueryWrapper {
pub query_data: SpecialQueryMsg,
}

impl CustomQuery for SpecialQueryWrapper {}

impl CustomMsg for SpecialQueryMsg {}
32 changes: 32 additions & 0 deletions packages/common/src/querier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use cosmwasm_std::{
from_json, to_json_vec, ContractResult, QuerierWrapper, QueryRequest, StdError, StdResult,
SystemResult,
};

use crate::msg::SpecialQueryMsg::QuerySeedRequest;
use crate::msg::{QuerySeedResponse, SpecialQueryWrapper};
pub struct SpecialQuerier<'a> {
querier: &'a QuerierWrapper<'a, SpecialQueryWrapper>,
}

impl<'a> SpecialQuerier<'a> {
pub fn new(querier: &'a QuerierWrapper<'a, SpecialQueryWrapper>) -> Self {
SpecialQuerier { querier }
}

pub fn query_seed(&self) -> StdResult<QuerySeedResponse> {
let request = QueryRequest::Custom(QuerySeedRequest {});

let req_vec = to_json_vec(&request)?;

match self.querier.raw_query(&req_vec) {
SystemResult::Err(system_err) => Err(StdError::generic_err(format!(
"Querier system error: {system_err}"
))),
SystemResult::Ok(ContractResult::Err(contract_err)) => Err(StdError::generic_err(
format!("Querier contract error: {contract_err}"),
)),
SystemResult::Ok(ContractResult::Ok(value)) => Ok(from_json(value)?),
}
}
}
2 changes: 2 additions & 0 deletions packages/common/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct DataRequest {
pub commits: HashMap<String, Commitment>,
/// Reveals submitted by executors
pub reveals: HashMap<String, Reveal>,
/// hash(random seed fetched from chain, dr_id)
pub seed_hash: Hash,
}

/// Represents a resolved data result
Expand Down
Loading
Loading