diff --git a/Cargo.lock b/Cargo.lock index e85462d5..977beb98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1054,7 +1054,7 @@ dependencies = [ [[package]] name = "skip" -version = "0.2.1" +version = "0.3.0" dependencies = [ "astroport", "cosmos-sdk-proto 0.19.0", @@ -1070,12 +1070,13 @@ dependencies = [ [[package]] name = "skip-api-entry-point" -version = "0.2.1" +version = "0.3.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", "cw-utils 1.0.1", + "cw2 1.1.0", "cw20 1.1.0", "skip", "test-case", @@ -1084,11 +1085,12 @@ dependencies = [ [[package]] name = "skip-api-ibc-adapter-ibc-hooks" -version = "0.2.1" +version = "0.3.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", + "cw2 1.1.0", "ibc-proto", "prost", "serde-cw-value", @@ -1100,12 +1102,13 @@ dependencies = [ [[package]] name = "skip-api-ibc-adapter-neutron-transfer" -version = "0.2.1" +version = "0.3.0" dependencies = [ "cosmos-sdk-proto 0.19.0", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", + "cw2 1.1.0", "neutron-proto", "neutron-sdk 0.5.0", "prost", @@ -1116,13 +1119,14 @@ dependencies = [ [[package]] name = "skip-api-swap-adapter-astroport" -version = "0.2.1" +version = "0.3.0" dependencies = [ "astroport", "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", "cw-utils 1.0.1", + "cw2 1.1.0", "cw20 1.1.0", "skip", "test-case", @@ -1131,12 +1135,13 @@ dependencies = [ [[package]] name = "skip-api-swap-adapter-lido-satellite" -version = "0.2.1" +version = "0.3.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", "cw-utils 1.0.1", + "cw2 1.1.0", "lido-satellite", "skip", "test-case", @@ -1145,12 +1150,13 @@ dependencies = [ [[package]] name = "skip-api-swap-adapter-osmosis-poolmanager" -version = "0.2.1" +version = "0.3.0" dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus 1.1.0", "cw-utils 1.0.1", + "cw2 1.1.0", "osmosis-std", "skip", "test-case", diff --git a/Cargo.toml b/Cargo.toml index 74396f14..fd4c1e87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ ] [workspace.package] -version = "0.2.1" +version = "0.3.0" authors = ["Skip"] edition = "2021" rust-version = "1.71.0" @@ -35,7 +35,7 @@ osmosis-std = "0.15.3" prost = "0.11" serde-cw-value = "0.7.0" serde-json-wasm = "0.5.1" -skip = { version = "0.2.0", path = "./packages/skip" } +skip = { version = "0.3.0", path = "./packages/skip" } test-case = "3.1.0" thiserror = "1" diff --git a/contracts/adapters/ibc/ibc-hooks/Cargo.toml b/contracts/adapters/ibc/ibc-hooks/Cargo.toml index 9072bbc4..89d55608 100644 --- a/contracts/adapters/ibc/ibc-hooks/Cargo.toml +++ b/contracts/adapters/ibc/ibc-hooks/Cargo.toml @@ -22,6 +22,7 @@ library = [] [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw2 = { workspace = true } cw-storage-plus = { workspace = true } ibc-proto = { workspace = true } prost = { workspace = true } diff --git a/contracts/adapters/ibc/ibc-hooks/src/contract.rs b/contracts/adapters/ibc/ibc-hooks/src/contract.rs index 82e29c86..fe34f646 100644 --- a/contracts/adapters/ibc/ibc-hooks/src/contract.rs +++ b/contracts/adapters/ibc/ibc-hooks/src/contract.rs @@ -9,11 +9,12 @@ use cosmwasm_std::{ entry_point, to_binary, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response, SubMsg, SubMsgResult, }; +use cw2::set_contract_version; use ibc_proto::ibc::applications::transfer::v1::{MsgTransfer, MsgTransferResponse}; use prost::Message; use serde_cw_value::Value; use skip::{ - ibc::{AckID, ExecuteMsg, IbcInfo, IbcLifecycleComplete, InstantiateMsg, QueryMsg}, + ibc::{AckID, ExecuteMsg, IbcInfo, IbcLifecycleComplete, InstantiateMsg, MigrateMsg, QueryMsg}, proto_coin::ProtoCoin, sudo::{OsmosisSudoMsg as SudoMsg, SudoType}, }; @@ -21,10 +22,23 @@ use skip::{ const IBC_MSG_TRANSFER_TYPE_URL: &str = "/ibc.applications.transfer.v1.MsgTransfer"; const REPLY_ID: u64 = 1; +/////////////// +/// MIGRATE /// +/////////////// + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { + unimplemented!() +} + /////////////////// /// INSTANTIATE /// /////////////////// +// Contract name and version used for migration. +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -32,6 +46,9 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> ContractResult { + // Set contract version + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // Validate entry point contract address let checked_entry_point_contract_address = deps.api.addr_validate(&msg.entry_point_contract_address)?; diff --git a/contracts/adapters/ibc/neutron-transfer/Cargo.toml b/contracts/adapters/ibc/neutron-transfer/Cargo.toml index ae5ad3ce..90c3d3f7 100644 --- a/contracts/adapters/ibc/neutron-transfer/Cargo.toml +++ b/contracts/adapters/ibc/neutron-transfer/Cargo.toml @@ -22,6 +22,7 @@ library = [] [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw2 = { workspace = true } cw-storage-plus = { workspace = true } neutron-proto = { workspace = true } neutron-sdk = { workspace = true } diff --git a/contracts/adapters/ibc/neutron-transfer/src/contract.rs b/contracts/adapters/ibc/neutron-transfer/src/contract.rs index 716f5b25..6601cfd7 100644 --- a/contracts/adapters/ibc/neutron-transfer/src/contract.rs +++ b/contracts/adapters/ibc/neutron-transfer/src/contract.rs @@ -6,21 +6,35 @@ use cosmwasm_std::{ entry_point, to_binary, BankMsg, Binary, Coin, Deps, DepsMut, Env, MessageInfo, Reply, Response, SubMsg, SubMsgResult, }; +use cw2::set_contract_version; use neutron_proto::neutron::transfer::{MsgTransfer, MsgTransferResponse}; use neutron_sdk::sudo::msg::{RequestPacket, TransferSudoMsg}; use prost::Message; use skip::{ - ibc::{AckID, ExecuteMsg, IbcInfo, InstantiateMsg, QueryMsg}, + ibc::{AckID, ExecuteMsg, IbcInfo, InstantiateMsg, MigrateMsg, QueryMsg}, proto_coin::ProtoCoin, sudo::SudoType, }; const REPLY_ID: u64 = 1; +/////////////// +/// MIGRATE /// +/////////////// + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { + unimplemented!() +} + /////////////////// /// INSTANTIATE /// /////////////////// +// Contract name and version used for migration. +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -28,6 +42,9 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> ContractResult { + // Set contract version + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // Validate entry point contract address let checked_entry_point_contract_address = deps.api.addr_validate(&msg.entry_point_contract_address)?; diff --git a/contracts/adapters/swap/astroport/Cargo.toml b/contracts/adapters/swap/astroport/Cargo.toml index 5f65f54b..46ee290b 100644 --- a/contracts/adapters/swap/astroport/Cargo.toml +++ b/contracts/adapters/swap/astroport/Cargo.toml @@ -23,6 +23,7 @@ library = [] astroport = { workspace = true } cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw2 = { workspace = true } cw20 = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } diff --git a/contracts/adapters/swap/astroport/src/contract.rs b/contracts/adapters/swap/astroport/src/contract.rs index e1199d09..cc2a803b 100644 --- a/contracts/adapters/swap/astroport/src/contract.rs +++ b/contracts/adapters/swap/astroport/src/contract.rs @@ -13,21 +13,35 @@ use cosmwasm_std::{ entry_point, from_binary, to_binary, Addr, Api, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Response, Uint128, WasmMsg, }; +use cw2::set_contract_version; use cw20::{Cw20Coin, Cw20ReceiveMsg}; use cw_utils::one_coin; use skip::{ asset::Asset, swap::{ execute_transfer_funds_back, AstroportInstantiateMsg as InstantiateMsg, Cw20HookMsg, - ExecuteMsg, QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse, - SwapOperation, + ExecuteMsg, MigrateMsg, QueryMsg, SimulateSwapExactAssetInResponse, + SimulateSwapExactAssetOutResponse, SwapOperation, }, }; +/////////////// +/// MIGRATE /// +/////////////// + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { + unimplemented!() +} + /////////////////// /// INSTANTIATE /// /////////////////// +// Contract name and version used for migration. +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -35,6 +49,9 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> ContractResult { + // Set contract version + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // Validate entry point contract address let checked_entry_point_contract_address = deps.api.addr_validate(&msg.entry_point_contract_address)?; diff --git a/contracts/adapters/swap/lido-satellite/Cargo.toml b/contracts/adapters/swap/lido-satellite/Cargo.toml index 1880abe6..f08e2e1f 100644 --- a/contracts/adapters/swap/lido-satellite/Cargo.toml +++ b/contracts/adapters/swap/lido-satellite/Cargo.toml @@ -22,6 +22,7 @@ library = [] [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw2 = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } lido-satellite = { workspace = true } diff --git a/contracts/adapters/swap/lido-satellite/src/contract.rs b/contracts/adapters/swap/lido-satellite/src/contract.rs index 87c93f4f..a47aa06f 100644 --- a/contracts/adapters/swap/lido-satellite/src/contract.rs +++ b/contracts/adapters/swap/lido-satellite/src/contract.rs @@ -9,20 +9,34 @@ use cosmwasm_std::{ entry_point, to_binary, Binary, Coin, Decimal, Deps, DepsMut, Env, MessageInfo, Response, WasmMsg, }; +use cw2::set_contract_version; use cw_utils::one_coin; use skip::{ asset::Asset, swap::{ execute_transfer_funds_back, ExecuteMsg, LidoSatelliteInstantiateMsg as InstantiateMsg, - QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse, + MigrateMsg, QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse, SwapOperation, }, }; +/////////////// +/// MIGRATE /// +/////////////// + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { + unimplemented!() +} + /////////////////// /// INSTANTIATE /// /////////////////// +// Contract name and version used for migration. +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -30,6 +44,9 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> ContractResult { + // Set contract version + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // Validate entry point contract address let checked_entry_point_contract_address = deps.api.addr_validate(&msg.entry_point_contract_address)?; diff --git a/contracts/adapters/swap/osmosis-poolmanager/Cargo.toml b/contracts/adapters/swap/osmosis-poolmanager/Cargo.toml index e4cdf8e1..a3aea215 100644 --- a/contracts/adapters/swap/osmosis-poolmanager/Cargo.toml +++ b/contracts/adapters/swap/osmosis-poolmanager/Cargo.toml @@ -22,6 +22,7 @@ library = [] [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw2 = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } osmosis-std = { workspace = true } diff --git a/contracts/adapters/swap/osmosis-poolmanager/src/contract.rs b/contracts/adapters/swap/osmosis-poolmanager/src/contract.rs index c9fbbbd9..2a40dbf8 100644 --- a/contracts/adapters/swap/osmosis-poolmanager/src/contract.rs +++ b/contracts/adapters/swap/osmosis-poolmanager/src/contract.rs @@ -6,6 +6,7 @@ use cosmwasm_std::{ entry_point, to_binary, Binary, Coin, CosmosMsg, Decimal, Deps, DepsMut, Empty, Env, MessageInfo, Response, Uint128, WasmMsg, }; +use cw2::set_contract_version; use cw_utils::one_coin; use osmosis_std::types::osmosis::poolmanager::v1beta1::{ EstimateSwapExactAmountInResponse, EstimateSwapExactAmountOutResponse, MsgSwapExactAmountIn, @@ -15,17 +16,30 @@ use skip::{ asset::Asset, proto_coin::ProtoCoin, swap::{ - convert_swap_operations, execute_transfer_funds_back, ExecuteMsg, + convert_swap_operations, execute_transfer_funds_back, ExecuteMsg, MigrateMsg, OsmosisInstantiateMsg as InstantiateMsg, QueryMsg, SimulateSwapExactAssetInResponse, SimulateSwapExactAssetOutResponse, SwapOperation, }, }; use std::str::FromStr; +/////////////// +/// MIGRATE /// +/////////////// + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { + unimplemented!() +} + /////////////////// /// INSTANTIATE /// /////////////////// +// Contract name and version used for migration. +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -33,6 +47,9 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> ContractResult { + // Set contract version + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // Validate entry point contract address let checked_entry_point_contract_address = deps.api.addr_validate(&msg.entry_point_contract_address)?; diff --git a/contracts/entry-point/Cargo.toml b/contracts/entry-point/Cargo.toml index a07ff677..cbc82f61 100644 --- a/contracts/entry-point/Cargo.toml +++ b/contracts/entry-point/Cargo.toml @@ -22,6 +22,7 @@ library = [] [dependencies] cosmwasm-schema = { workspace = true } cosmwasm-std = { workspace = true } +cw2 = { workspace = true } cw20 = { workspace = true } cw-storage-plus = { workspace = true } cw-utils = { workspace = true } diff --git a/contracts/entry-point/src/contract.rs b/contracts/entry-point/src/contract.rs index 4550b432..0e53a09a 100644 --- a/contracts/entry-point/src/contract.rs +++ b/contracts/entry-point/src/contract.rs @@ -11,12 +11,26 @@ use crate::{ use cosmwasm_std::{ entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, }; -use skip::entry_point::{ExecuteMsg, InstantiateMsg, QueryMsg}; +use cw2::set_contract_version; +use skip::entry_point::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; + +/////////////// +/// MIGRATE /// +/////////////// + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> ContractResult { + unimplemented!() +} /////////////////// /// INSTANTIATE /// /////////////////// +// Contract name and version used for migration. +const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( deps: DepsMut, @@ -24,6 +38,9 @@ pub fn instantiate( _info: MessageInfo, msg: InstantiateMsg, ) -> ContractResult { + // Set contract version + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + // Create response object to return let mut response: Response = Response::new().add_attribute("action", "instantiate"); diff --git a/packages/skip/src/entry_point.rs b/packages/skip/src/entry_point.rs index 1c97fc50..21e42c28 100644 --- a/packages/skip/src/entry_point.rs +++ b/packages/skip/src/entry_point.rs @@ -8,6 +8,14 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Addr, Binary, Uint128}; use cw20::Cw20ReceiveMsg; +/////////////// +/// MIGRATE /// +/////////////// + +// The MigrateMsg struct defines the migration parameters for the entry point contract. +#[cw_serde] +pub struct MigrateMsg {} + /////////////////// /// INSTANTIATE /// /////////////////// diff --git a/packages/skip/src/ibc.rs b/packages/skip/src/ibc.rs index 358dfa02..3a191bd6 100644 --- a/packages/skip/src/ibc.rs +++ b/packages/skip/src/ibc.rs @@ -6,6 +6,14 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{Coin, Coins, StdError}; use neutron_proto::neutron::feerefunder::Fee as NeutronFee; +/////////////// +/// MIGRATE /// +/////////////// + +// The MigrateMsg struct defines the migration parameters for the entry point contract. +#[cw_serde] +pub struct MigrateMsg {} + /////////////////// /// INSTANTIATE /// /////////////////// diff --git a/packages/skip/src/swap.rs b/packages/skip/src/swap.rs index 20a236cf..70d71e80 100644 --- a/packages/skip/src/swap.rs +++ b/packages/skip/src/swap.rs @@ -11,6 +11,14 @@ use osmosis_std::types::osmosis::poolmanager::v1beta1::{ SwapAmountInRoute as OsmosisSwapAmountInRoute, SwapAmountOutRoute as OsmosisSwapAmountOutRoute, }; +/////////////// +/// MIGRATE /// +/////////////// + +// The MigrateMsg struct defines the migration parameters for the entry point contract. +#[cw_serde] +pub struct MigrateMsg {} + /////////////////// /// INSTANTIATE /// /////////////////// diff --git a/schema/skip-api-entry-point.json b/schema/skip-api-entry-point.json index 86d80f60..ef2282b9 100644 --- a/schema/skip-api-entry-point.json +++ b/schema/skip-api-entry-point.json @@ -1,6 +1,6 @@ { "contract_name": "skip-api-entry-point", - "contract_version": "0.2.1", + "contract_version": "0.3.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/scripts/configs/neutron.toml b/scripts/configs/neutron.toml index 9ca9fa04..adbca842 100644 --- a/scripts/configs/neutron.toml +++ b/scripts/configs/neutron.toml @@ -1,9 +1,12 @@ # Enter your mnemonic here MNEMONIC = "" -# Commut Hash +# Commit Hash of the commit used to build the contracts COMMIT_HASH = "" +# Admin address to execute migrations from +ADMIN_ADDRESS = "" + MAINNET_REST_URL = "https://rest-kralum.neutron-1.neutron.org" MAINNET_RPC_URL = "https://rpc-kralum.neutron-1.neutron.org" MAINNET_CHAIN_ID = "neutron-1" diff --git a/scripts/configs/osmosis.toml b/scripts/configs/osmosis.toml index e83ca3c8..def00313 100644 --- a/scripts/configs/osmosis.toml +++ b/scripts/configs/osmosis.toml @@ -1,9 +1,12 @@ # Enter your mnemonic here MNEMONIC = "" -# Commut Hash +# Commit Hash of the commit used to build the contracts COMMIT_HASH = "" +# Admin address to execute migrations from +ADMIN_ADDRESS = "" + MAINNET_REST_URL = "https://osmosis-api.polkachu.com" MAINNET_RPC_URL = "https://osmosis-rpc.polkachu.com/" MAINNET_CHAIN_ID = "osmosis-1" diff --git a/scripts/configs/terra.toml b/scripts/configs/terra.toml index 07336a58..f1e5d314 100644 --- a/scripts/configs/terra.toml +++ b/scripts/configs/terra.toml @@ -1,9 +1,12 @@ # Enter your mnemonic here MNEMONIC = "" -# Commut Hash +# Commit Hash of the commit used to build the contracts COMMIT_HASH = "" +# Admin address to execute migrations from +ADMIN_ADDRESS = "" + MAINNET_REST_URL = "https://phoenix-lcd.terra.dev" MAINNET_RPC_URL = "https://terra-rpc.polkachu.com/" MAINNET_CHAIN_ID = "phoenix-1" diff --git a/scripts/deploy.py b/scripts/deploy.py index 47627825..50870b82 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -4,17 +4,15 @@ import httpx import time from hashlib import sha256 -from base64 import b64encode, b64decode +from base64 import b64encode from datetime import datetime from bip_utils import Bip39SeedGenerator, Bip44, Bip44Coins from google.protobuf import any_pb2 from cosmpy.aerial.client import LedgerClient, NetworkConfig -from cosmpy.aerial.contract import create_cosmwasm_execute_msg from cosmpy.aerial.tx import Transaction, SigningCfg from cosmpy.aerial.wallet import LocalWallet from cosmpy.crypto.keypairs import PrivateKey -from cosmpy.protos.cosmos.base.v1beta1.coin_pb2 import Coin from cosmpy.protos.cosmwasm.wasm.v1.tx_pb2 import ( MsgStoreCode, MsgInstantiateContract, @@ -39,7 +37,9 @@ # Raise exception if config not found if not found_config: - raise Exception(f"Could not find config for chain {CHAIN}; Must enter a chain as 1st command line argument.") + raise Exception( + f"Could not find config for chain {CHAIN}; Must enter a chain as 1st cli arg." + ) # Create deployed-contracts folder if it doesn't exist if not os.path.exists("../deployed-contracts"): @@ -65,7 +65,9 @@ CHAIN_ID = config["TESTNET_CHAIN_ID"] SWAP_VENUES = config["testnet_swap_venues"] else: - raise Exception("Must specify either 'mainnet' or 'testnet' for 2nd command line argument.") + raise Exception( + "Must specify either 'mainnet' or 'testnet' for 2nd cli arg." + ) ADDRESS_PREFIX = config["ADDRESS_PREFIX"] DENOM = config["DENOM"] @@ -81,6 +83,9 @@ # Pregenerated Contract Addresses ENTRY_POINT_PRE_GENERATED_ADDRESS = config["ENTRY_POINT_PRE_GENERATED_ADDRESS"] +# Admin address for future migrations +ADMIN_ADDRESS = config["ADMIN_ADDRESS"] + MNEMONIC = config["MNEMONIC"] del config["MNEMONIC"] @@ -114,7 +119,12 @@ def main(): toml.dump(DEPLOYED_CONTRACTS_INFO, f) # IBC Contracts - ibc_transfer_adapter_contract_code_id = store_contract(client, wallet, IBC_TRANSFER_ADAPTER_PATH, "ibc_transfer_adapter", PERMISSIONED_UPLOADER_ADDRESS) + ibc_transfer_adapter_contract_code_id = store_contract( + client, wallet, + IBC_TRANSFER_ADAPTER_PATH, + "ibc_transfer_adapter", + PERMISSIONED_UPLOADER_ADDRESS + ) ibc_transfer_adapter_contract_address = instantiate_contract( client, wallet, @@ -131,8 +141,13 @@ def main(): # Swap Contracts for venue in SWAP_VENUES: - swap_adapter_contract_code_id = store_contract(client, wallet, venue["swap_adapter_path"], f"swap_adapter_{venue['name']}", PERMISSIONED_UPLOADER_ADDRESS) - + swap_adapter_contract_code_id = store_contract( + client, + wallet, + venue["swap_adapter_path"], + f"swap_adapter_{venue['name']}", + PERMISSIONED_UPLOADER_ADDRESS + ) swap_adapter_instantiate_args = { "entry_point_contract_address": ENTRY_POINT_PRE_GENERATED_ADDRESS } @@ -158,7 +173,13 @@ def main(): ) # Entry Point Contract - entry_point_contract_code_id = store_contract(client, wallet, ENTRY_POINT_CONTRACT_PATH, "entry_point", PERMISSIONED_UPLOADER_ADDRESS) + entry_point_contract_code_id = store_contract( + client, + wallet, + ENTRY_POINT_CONTRACT_PATH, + "entry_point", + PERMISSIONED_UPLOADER_ADDRESS + ) instantiate2_contract( client=client, wallet=wallet, @@ -169,6 +190,7 @@ def main(): pre_gen_address=ENTRY_POINT_PRE_GENERATED_ADDRESS ) + def create_tx(msg, client, wallet, @@ -183,116 +205,17 @@ def create_tx(msg, account = client.query_account(str(wallet.address())) # Seal, Sign, and Complete Tx - tx.seal(signing_cfgs=[SigningCfg.direct(wallet.public_key(), account.sequence)], fee = fee, gas_limit=gas_limit) + tx.seal( + signing_cfgs=[SigningCfg.direct(wallet.public_key(), account.sequence)], + fee=fee, + gas_limit=gas_limit + ) tx.sign(wallet.signer(), client.network_config.chain_id, account.number) tx.complete() return tx - -def create_wasm_store_tx(client, - wallet, - address: str, - gas_fee: str, - gas_limit: int, - file: str, - permissioned_uploader_address: str | None = None - ) -> tuple[bytes, str]: - if permissioned_uploader_address is not None: - msg_store_code = MsgStoreCode( - sender=permissioned_uploader_address, - wasm_byte_code=open(file, "rb").read(), - instantiate_permission=None - ) - msg = create_exec_msg(msg=msg_store_code, grantee_address=address) - else: - msg = MsgStoreCode( - sender=address, - wasm_byte_code=open(file, "rb").read(), - instantiate_permission=None - ) - - return create_tx(msg=msg, - client=client, - wallet=wallet, - gas_limit=gas_limit, - fee=gas_fee) - -def create_wasm_instantiate_tx( - client, - wallet, - address: str, - gas_fee: str, - gas_limit: int, - code_id: int, - args: dict, - label: str, - ) -> tuple[bytes, str]: - - msg = MsgInstantiateContract( - sender=str(address), - code_id=code_id, - msg=json_encode(args).encode("UTF8"), - label=label, - ) - - return create_tx(msg=msg, - client=client, - wallet=wallet, - gas_limit=gas_limit, - fee=gas_fee) -def create_wasm_instantiate2_tx( - client, - wallet, - address: str, - gas_fee: str, - gas_limit: int, - code_id: int, - args: dict, - label: str, - ) -> tuple[bytes, str]: - - msg = MsgInstantiateContract2( - sender=address, - code_id=code_id, - msg=json_encode(args).encode("UTF8"), - label=label, - salt=SALT, - fix_msg=False, - ) - - return create_tx(msg=msg, - client=client, - wallet=wallet, - gas_limit=gas_limit, - fee=gas_fee) - - -def create_wasm_execute_tx( - client, - wallet, - contract_address: str, - args: dict, - address: str, - gas_fee: str, - gas_limit: int, - funds_coin: Coin | None, - ) -> tuple[bytes, str]: - msg = create_cosmwasm_execute_msg( - contract_address=contract_address, - args=args, - sender_address=address - ) - if funds_coin: - msg.funds.append(funds_coin) - return create_tx(msg=msg, - client=client, - wallet=wallet, - gas_limit=gas_limit, - fee=gas_fee) - - def create_wallet(client) -> LocalWallet: """ Create a wallet from a mnemonic and return it""" if CHAIN == "terra": @@ -305,7 +228,10 @@ def create_wallet(client) -> LocalWallet: else: seed_bytes = Bip39SeedGenerator(MNEMONIC).Generate() bip44_def_ctx = Bip44.FromSeed(seed_bytes, Bip44Coins.COSMOS).DeriveDefaultPath() - wallet = LocalWallet(PrivateKey(bip44_def_ctx.PrivateKey().Raw().ToBytes()), prefix=ADDRESS_PREFIX) + wallet = LocalWallet( + PrivateKey(bip44_def_ctx.PrivateKey().Raw().ToBytes()), + prefix=ADDRESS_PREFIX + ) balance = client.query_bank_balance(str(wallet.address()), DENOM) print("Wallet Address: ", wallet.address(), " with account balance: ", balance) return wallet @@ -326,16 +252,33 @@ def init_deployed_contracts_info(): toml.dump(DEPLOYED_CONTRACTS_INFO, f) -def store_contract(client, wallet, file_path, name, permissioned_uploader_address) -> int: +def store_contract( + client, + wallet, + file_path, + name, + permissioned_uploader_address +) -> int: gas_limit = 5000000 - store_tx = create_wasm_store_tx( - client=client, - wallet=wallet, - address=str(wallet.address()), - gas_fee=f"{int(GAS_PRICE*gas_limit)}{DENOM}", + if permissioned_uploader_address is not None: + msg_store_code = MsgStoreCode( + sender=permissioned_uploader_address, + wasm_byte_code=open(file_path, "rb").read(), + instantiate_permission=None + ) + msg = create_exec_msg(msg=msg_store_code, grantee_address=str(wallet.address())) + else: + msg = MsgStoreCode( + sender=str(wallet.address()), + wasm_byte_code=open(file_path, "rb").read(), + instantiate_permission=None + ) + store_tx = create_tx( + msg=msg, + client=client, + wallet=wallet, gas_limit=gas_limit, - file=file_path, - permissioned_uploader_address=permissioned_uploader_address + fee=f"{int(GAS_PRICE*gas_limit)}{DENOM}" ) tx_hash = sha256(store_tx.tx.SerializeToString()).hexdigest() print("Tx hash: ", tx_hash) @@ -351,15 +294,19 @@ def store_contract(client, wallet, file_path, name, permissioned_uploader_addres def instantiate_contract(client, wallet, code_id, args, label, name) -> str: gas_limit = 300000 - instantiate_tx = create_wasm_instantiate_tx( - client=client, - wallet=wallet, - address=str(wallet.address()), - gas_fee=f"{int(GAS_PRICE*gas_limit)}{DENOM}", - gas_limit=gas_limit, + msg = MsgInstantiateContract( + sender=str(wallet.address()), + admin=ADMIN_ADDRESS, code_id=code_id, - args=args, - label=label + msg=json_encode(args).encode("UTF8"), + label=label, + ) + instantiate_tx = create_tx( + msg=msg, + client=client, + wallet=wallet, + gas_limit=gas_limit, + fee=f"{int(GAS_PRICE*gas_limit)}{DENOM}" ) tx_hash = sha256(instantiate_tx.tx.SerializeToString()).hexdigest() print("Tx hash: ", tx_hash) @@ -373,17 +320,31 @@ def instantiate_contract(client, wallet, code_id, args, label, name) -> str: return contract_address -def instantiate2_contract(client, wallet, code_id, args, label, name, pre_gen_address) -> str: +def instantiate2_contract( + client, + wallet, + code_id, + args, + label, + name, + pre_gen_address +) -> str: gas_limit = 300000 - instantiate_2_tx = create_wasm_instantiate2_tx( - client=client, - wallet=wallet, - address=str(wallet.address()), - gas_fee=f"{int(GAS_PRICE*gas_limit)}{DENOM}", - gas_limit=gas_limit, + msg = MsgInstantiateContract2( + sender=str(wallet.address()), + admin=ADMIN_ADDRESS, code_id=code_id, - args=args, - label=label + msg=json_encode(args).encode("UTF8"), + label=label, + salt=SALT, + fix_msg=False, + ) + instantiate_2_tx = create_tx( + msg=msg, + client=client, + wallet=wallet, + gas_limit=gas_limit, + fee=f"{int(GAS_PRICE*gas_limit)}{DENOM}" ) tx_hash = sha256(instantiate_2_tx.tx.SerializeToString()).hexdigest() print("Tx hash: ", tx_hash) @@ -421,7 +382,10 @@ def broadcast_tx(tx) -> httpx.Response: httpx.post(RPC_URL, json=data, timeout=60) print("Sleeping for 20 seconds...") time.sleep(20) - resp = httpx.get(REST_URL + f"/cosmos/tx/v1beta1/txs/{sha256(tx_bytes).hexdigest()}", timeout=60) + resp = httpx.get( + REST_URL + f"/cosmos/tx/v1beta1/txs/{sha256(tx_bytes).hexdigest()}", + timeout=60 + ) return resp