Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

fix: remove remaining deps to ah data #439

Merged
merged 1 commit into from
Jul 18, 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
118 changes: 38 additions & 80 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
profile: minimal
toolchain: stable
- name: Build
- name: Build
run: |
cargo build --verbose
working-directory: .
Expand All @@ -29,15 +29,15 @@ jobs:
with:
profile: minimal
toolchain: stable
- name: test
- name: test
run: |
cargo test --verbose
working-directory: .
devnet:
#needs: test
name: deploy on devnet
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main'
environment: devnet
steps:
- uses: actions/checkout@v4
Expand All @@ -53,55 +53,52 @@ jobs:
toolchain: stable
- name: Compile
run: |
getNewVersionBYContract(){
getNewVersionBYContract(){

local contractAddress=$1
local contractAddress=$1

ELYSD=./elysd
local json=$($ELYSD q --output json --node "${{vars.NODE}}" wasm contract-state smart "$contractAddress" '{ "version": {} }')
local VERSION=$(echo $json | jq -r ".data.version")
# Extract the major, minor, and patch versions
local version_parts=(${VERSION//./ })
local major=${version_parts[0]}
local minor=${version_parts[1]}
local patch=${version_parts[2]}
ELYSD=./elysd
local json=$($ELYSD q --output json --node "${{vars.NODE}}" wasm contract-state smart "$contractAddress" '{ "version": {} }')
local VERSION=$(echo $json | jq -r ".data.version")

# Extract the major, minor, and patch versions
local version_parts=(${VERSION//./ })
local major=${version_parts[0]}
local minor=${version_parts[1]}
local patch=${version_parts[2]}

# Increment the minor version
local minor=$((minor + 1))
# Increment the minor version
local minor=$((minor + 1))

# Update the version string
VERSION="$major.$minor.$patch"
# Update the version string
VERSION="$major.$minor.$patch"

echo $VERSION
}
echo $VERSION
}

accountHistoryContractVersion=$(getNewVersionBYContract ${{vars.AH_CONTRACT_ADDRESS}})
tradeShieldContractVersion=$(getNewVersionBYContract ${{vars.TS_CONTRACT_ADDRESS}})
financialSnapshotContractVersion=$(getNewVersionBYContract ${{vars.FS_CONTRACT_ADDRESS}})
tradeShieldContractVersion=$(getNewVersionBYContract ${{vars.TS_CONTRACT_ADDRESS}})
financialSnapshotContractVersion=$(getNewVersionBYContract ${{vars.FS_CONTRACT_ADDRESS}})

echo "new accountHistoryContractVersion: $accountHistoryContractVersion"
echo "new tradeShieldContractVersion: $tradeShieldContractVersion"
echo "new financialSnapshotContractVersion: $financialSnapshotContractVersion"
echo "new tradeShieldContractVersion: $tradeShieldContractVersion"
echo "new financialSnapshotContractVersion: $financialSnapshotContractVersion"

sed -i "s/^version = .*/version = \"$accountHistoryContractVersion\"/" contracts/account-history-contract/Cargo.toml
sed -i "s/^version = .*/version = \"$tradeShieldContractVersion\"/" contracts/trade-shield-contract/Cargo.toml
sed -i "s/^version = .*/version = \"$financialSnapshotContractVersion\"/" contracts/financial-snapshot-contract/Cargo.toml
cargo update

docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.14.0
sed -i "s/^version = .*/version = \"$tradeShieldContractVersion\"/" contracts/trade-shield-contract/Cargo.toml
sed -i "s/^version = .*/version = \"$financialSnapshotContractVersion\"/" contracts/financial-snapshot-contract/Cargo.toml
cargo update

docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.14.0
- name: Deploy
run: |
run: |
# helper functions
extract_txhash() { awk -F 'txhash: ' '/txhash:/{print $2; exit}'; }
extract_code_id() { awk -F 'key: code_id|value: ' '/key: code_id/ { getline; gsub(/"/, "", $2); print $2; exit }'; }
extract_contract_address() { awk -F 'key: _contract_address|value: ' '/key: _contract_address/ { getline; gsub(/"/, "", $2); print $2; exit }'; }
extract_account_number() { awk -F 'account_number: ' '/account_number:/ { gsub(/"/, "", $2); print $2 + 0; exit; }'; }
extract_sequence() { awk -F 'sequence: ' '/sequence:/ { gsub(/"/, "", $2); print $2 + 0; exit; }'; }

ELYSD=./elysd

wait_for_tx() {
Expand All @@ -127,7 +124,7 @@ jobs:

# contract addresses enviroment variables


# set elysd config
$ELYSD config keyring-backend test
$ELYSD config node $NODE
Expand Down Expand Up @@ -156,11 +153,9 @@ jobs:
##contracts
FS_CONTRACT_ADDRESS=${{vars.FS_CONTRACT_ADDRESS}}
TS_CONTRACT_ADDRESS=${{vars.TS_CONTRACT_ADDRESS}}
AH_CONTRACT_ADDRESS=${{vars.AH_CONTRACT_ADDRESS}}

printf "FS_CONTRACT_ADDRESS=%s\n" "$FS_CONTRACT_ADDRESS"
printf "TS_CONTRACT_ADDRESS=%s\n" "$TS_CONTRACT_ADDRESS"
printf "AH_CONTRACT_ADDRESS=%s\n" "$AH_CONTRACT_ADDRESS"

# store and init/migrate financial snapshot contract
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm store $OPTIONS --sequence $(($sequence + 1)) artifacts/financial_snapshot_contract.wasm | extract_txhash)
Expand All @@ -169,7 +164,7 @@ jobs:
wait_for_tx $txhash
codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id)
echo "fs code id: $codeid"

if [ "$FS_CONTRACT_ADDRESS" != "empty" ]; then
txhash=$( echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 2)) $FS_CONTRACT_ADDRESS $codeid '{}' | extract_txhash)
echo "fs migrate txhash: $txhash"
Expand All @@ -192,58 +187,21 @@ jobs:
echo "ts code id: $codeid"

if [ "$TS_CONTRACT_ADDRESS" != "empty" ]; then
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 4)) $TS_CONTRACT_ADDRESS $codeid '{
"account_history_address": "'"$AH_CONTRACT_ADDRESS"'"
}' | extract_txhash)
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 4)) $TS_CONTRACT_ADDRESS $codeid '{}' | extract_txhash)
echo "ts migrate txhash: $txhash"
else
# set localnet AH deterministic address as param
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 4)) --label "ts" --admin $NAME $codeid '{
"account_history_address": "elys17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgs98tvuy"
}' | extract_txhash)
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 4)) --label "ts" --admin $NAME $codeid '{}' | extract_txhash)
echo "ts init txhash: $txhash"
fi
exit_if_tx_is_empty $txhash
wait_for_tx $txhash
export ts_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address)
echo "ts_contract_address: $ts_contract_address"

# store and init/migrate account history contract
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm store artifacts/account_history_contract.wasm $OPTIONS --sequence $(($sequence + 5)) | extract_txhash)

echo "ah store txhash: $txhash"
exit_if_tx_is_empty $txhash
wait_for_tx $txhash

codeid=$($ELYSD q tx $txhash --node $NODE | extract_code_id)
echo "ah code id: $codeid"

if [ "$AH_CONTRACT_ADDRESS" != "empty" ]; then
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm migrate $OPTIONS --sequence $(($sequence + 6)) $AH_CONTRACT_ADDRESS $codeid '{
"trade_shield_address": "'"$TS_CONTRACT_ADDRESS"'",
"limit": 1
}' | extract_txhash)
echo "ah migrate txhash: $txhash"
else
txhash=$(echo "${{ secrets.PASSPHRASE_MALLORCA }}" | $ELYSD tx wasm init $OPTIONS --sequence $(($sequence + 6)) --label "ah" --admin $NAME $codeid '{
"limit": 300,
"expiration": {
"at_time": "604800000000000"
},
"trade_shield_address": "'"$ts_contract_address"'"
}' | extract_txhash)
echo "ah init txhash: $txhash"
fi

exit_if_tx_is_empty $txhash
wait_for_tx $txhash
ah_contract_address=$($ELYSD q tx $txhash --node $NODE | extract_contract_address)
echo "ah_contract_address: $ah_contract_address"

# print environment variables to set
printf "\nset those environment variables to use the contracts:\n\n"
printf "export NODE=%s\n" "$NODE"
printf "export NAME=%s\n" "$NAME"
printf "export FS_CONTRACT_ADDRESS=%s\n" "$fs_contract_address"
printf "export TS_CONTRACT_ADDRESS=%s\n" "$ts_contract_address"
printf "export AH_CONTRACT_ADDRESS=%s\n" "$ah_contract_address"
4 changes: 1 addition & 3 deletions bindings/src/trade_shield/msg/instantiate_msg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cosmwasm_schema::cw_serde;

#[cw_serde]
pub struct InstantiateMsg {
pub account_history_address: Option<String>,
}
pub struct InstantiateMsg {}
4 changes: 1 addition & 3 deletions bindings/src/trade_shield/msg/migrate_msg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use cosmwasm_schema::cw_serde;

#[cw_serde]
pub struct MigrateMsg {
pub account_history_address: Option<String>,
}
pub struct MigrateMsg {}
3 changes: 0 additions & 3 deletions bindings/src/trade_shield/states/account_history_address.rs

This file was deleted.

2 changes: 0 additions & 2 deletions bindings/src/trade_shield/states/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
mod account_history_address;
mod limit_order;
mod number_of_order;
mod params;
mod perpetual_order;
mod reply_info;
mod spot_order;

pub use account_history_address::ACCOUNT_HISTORY_ADDRESS;
pub use limit_order::LIMIT_PROCESS_ORDER;
pub use number_of_order::{NUMBER_OF_EXECUTED_ORDER, NUMBER_OF_PENDING_ORDER};
pub use params::{
Expand Down
4 changes: 2 additions & 2 deletions contracts/trade-shield-contract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Optionally, use `-v` to display the node logs.
Run the following command to store the contract on the chain:

```sh
elysd tx wasm store path/to/account_history_contract.wasm --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --gas=auto --gas-adjustment=1.3 -y -b=sync
elysd tx wasm store path/to/trade_shield_contract.wasm --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --gas=auto --gas-adjustment=1.3 -y -b=sync
```

Ensure to replace `path/to/account_history_contract.wasm` with the actual path to the downloaded contract.
Ensure to replace `path/to/trade_shield_contract.wasm` with the actual path to the downloaded contract.

7. Instantiate Contract
Execute the command below to instantiate the contract on the Elys network:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub fn instantiate(
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
MAX_REPLY_ID.save(deps.storage, &0)?;
SPOT_ORDER_MAX_ID.save(deps.storage, &0)?;
ACCOUNT_HISTORY_ADDRESS.save(deps.storage, &msg.account_history_address)?;

let admin = "elys16xffmfa6k45j340cx5zyp66lqvuw62a0neaa7w".to_string();
PARAMS_ADMIN.save(deps.storage, &admin)?;
Expand Down
9 changes: 2 additions & 7 deletions contracts/trade-shield-contract/src/entry_point/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use cw2::set_contract_version;
use elys_bindings::trade_shield::{
msg::MigrateMsg,
states::{
ACCOUNT_HISTORY_ADDRESS, LEVERAGE_ENABLED, LIMIT_PROCESS_ORDER, MARKET_ORDER_ENABLED,
PARAMS_ADMIN, PERPETUAL_ENABLED, PROCESS_ORDERS_ENABLED, REWARD_ENABLED, STAKE_ENABLED,
SWAP_ENABLED,
LEVERAGE_ENABLED, LIMIT_PROCESS_ORDER, MARKET_ORDER_ENABLED, PARAMS_ADMIN,
PERPETUAL_ENABLED, PROCESS_ORDERS_ENABLED, REWARD_ENABLED, STAKE_ENABLED, SWAP_ENABLED,
},
};
use semver::Version;
Expand All @@ -19,10 +18,6 @@ pub fn migrate(
_env: Env,
msg: MigrateMsg,
) -> StdResult<Response<ElysMsg>> {
if msg.account_history_address.is_some() {
ACCOUNT_HISTORY_ADDRESS.save(deps.storage, &msg.account_history_address)?;
}

let admin = "elys16xffmfa6k45j340cx5zyp66lqvuw62a0neaa7w".to_string();
PARAMS_ADMIN.save(deps.storage, &admin)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fn not_found() {

// Create a mock message to instantiate the contract with no initial orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn succesful_cancel_an_order() {

// Create a mock message to instantiate the contract with no initial orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![PerpetualOrder::new_open(
"user",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ fn unauthorize() {

// Create a mock message to instantiate the contract with no initial orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![PerpetualOrder::new_open(
"user",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ fn not_found() {

// Create a mock message to instantiate the contract with an empty list of orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn process_spot_order_processing() {

// Create a mock message to instantiate the contract with the dummy order.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![dummy_order.clone()],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ fn successful_cancel_order_with_created_order() {

// Create a mock message to instantiate the contract with no initial orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ fn successful_cancel_order_with_dummy_order() {

// Create a mock message to instantiate the contract with the dummy order.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![dummy_order.clone()],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fn unauthorized() {

// Create a mock message to instantiate the contract with an order owned by the "user"
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![SpotOrder::new_dummy()],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ fn successfully_cancel_orders() {

// Create a mock message to instantiate the contract with an empty list of orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: spot_orders.clone(),
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ fn successfully_cancel_orders_ids() {

// Create a mock message to instantiate the contract with an empty list of orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: spot_orders.clone(),
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ fn successfully_cancel_orders_type() {

// Create a mock message to instantiate the contract with an empty list of orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: spot_orders.clone(),
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ fn unauthorize() {

// Create a mock message to instantiate the contract with an empty list of orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![SpotOrder {
order_type: SpotOrderType::LimitBuy,
order_id: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ fn claim_rewards_request() {
let code_id = app.store_code(Box::new(code));

let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ fn closing_perpetualg_position() {

// Create a mock message to instantiate the contract with no initial orders.
let instantiate_msg = InstantiateMockMsg {
account_history_address: None,
spot_orders: vec![],
perpetual_orders: vec![],
};
Expand Down
Loading
Loading