Skip to content

Commit

Permalink
[Publishing Tool]: Allow the publishing tool to run against stokenet
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Mar 5, 2024
1 parent fd26ddf commit e150d04
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions tools/publishing-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ hex-literal = "0.4.1"
itertools = "0.12.1"
serde_json = "1.0.114"
clap = { version = "4.5.1", features = ["derive"] }
bitflags = "2.4.2"

[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ pub fn mainnet_testing(
additional_information: AdditionalInformation {
ociswap_v2_registry_component: None,
},
additional_operation_flags: AdditionalOperationFlags::empty()
// cSpell:enable
}
}
7 changes: 7 additions & 0 deletions tools/publishing-tool/src/cli/default_configurations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::*;
use clap::*;
mod mainnet_testing;
mod stokenet_testing;

#[derive(ValueEnum, Clone, Copy, Debug)]
pub enum ConfigurationSelector {
MainnetTesting,
StokenetTesting,
}

impl ConfigurationSelector {
Expand All @@ -16,18 +18,23 @@ impl ConfigurationSelector {
Self::MainnetTesting => {
mainnet_testing::mainnet_testing(notary_private_key)
}
Self::StokenetTesting => {
stokenet_testing::stokenet_testing(notary_private_key)
}
}
}

pub fn gateway_base_url(self) -> String {
match self {
Self::MainnetTesting => "https://mainnet.radixdlt.com".to_owned(),
Self::StokenetTesting => "https://stokenet.radixdlt.com".to_owned(),
}
}

pub fn network_definition(self) -> NetworkDefinition {
match self {
Self::MainnetTesting => NetworkDefinition::mainnet(),
Self::StokenetTesting => NetworkDefinition::stokenet(),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
use common::prelude::*;

use self::utils::*;
use crate::*;

pub fn stokenet_testing(
notary_private_key: &PrivateKey,
) -> PublishingConfiguration {
let notary_account_address =
ComponentAddress::virtual_account_from_public_key(
&notary_private_key.public_key(),
);

// cSpell:disable
PublishingConfiguration {
protocol_configuration: ProtocolConfiguration {
protocol_resource: XRD,
user_resource_volatility: UserResourceIndexedData {
bitcoin: Volatility::Volatile,
ethereum: Volatility::Volatile,
usdc: Volatility::NonVolatile,
usdt: Volatility::NonVolatile,
},
reward_rates: indexmap! {
LockupPeriod::from_minutes(0).unwrap() => dec!(0.125), // 12.5%
LockupPeriod::from_minutes(1).unwrap() => dec!(0.15), // 15.0%
},
allow_opening_liquidity_positions: true,
allow_closing_liquidity_positions: true,
maximum_allowed_price_staleness: i64::MAX,
maximum_allowed_price_difference_percentage: Decimal::MAX,
entities_metadata: Entities {
protocol_entities: ProtocolIndexedData {
ignition: metadata_init! {
"name" => "Ignition", updatable;
"description" => "The main entrypoint into the Ignition liquidity incentive program.", updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
simple_oracle: metadata_init! {
"name" => "Ignition Oracle", updatable;
"description" => "The oracle used by the Ignition protocol.", updatable;
"tags" => vec!["oracle"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
},
exchange_adapter_entities: ExchangeIndexedData {
ociswap_v2: metadata_init! {
"name" => "Ignition Ociswap v2 Adapter", updatable;
"description" => "An adapter used by the Ignition protocol to communicate with Ociswap v2 pools.", updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
defiplaza_v2: metadata_init! {
"name" => "Ignition DefiPlaza v2 Adapter", updatable;
"description" => "An adapter used by the Ignition protocol to communicate with DefiPlaza v2 pools.", updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
caviarnine_v1: metadata_init! {
"name" => "Ignition Caviarnine v1 Adapter", updatable;
"description" => "An adapter used by the Ignition protocol to communicate with Caviarnine v1 pools.", updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
},
},
},
dapp_definition_metadata: indexmap! {
"name".to_owned() => MetadataValue::String("Project Ignition".to_owned()),
"description".to_owned() => MetadataValue::String("A Radix liquidity incentives program, offered in partnership with select decentralized exchange dApps in the Radix ecosystem.".to_owned()),
"icon_url".to_owned() => MetadataValue::Url(UncheckedUrl::of("https://assets.radixdlt.com/icons/icon-Ignition-LP.png"))
},
transaction_configuration: TransactionConfiguration {
notary: clone_private_key(notary_private_key),
fee_payer_information: AccountAndControllingKey::new_virtual_account(
clone_private_key(notary_private_key),
),
},
// TODO: Determine where they should be sent to.
badges: BadgeIndexedData {
oracle_manager_badge: BadgeHandling::CreateAndSend {
account_address: notary_account_address,
metadata_init: metadata_init! {
"name" => "Ignition Oracle Manager", updatable;
"symbol" => "IGNOM", updatable;
"description" => "A badge with the authority to update the Oracle prices of the Ignition oracle.", updatable;
"tags" => vec!["badge"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
},
protocol_manager_badge: BadgeHandling::CreateAndSend {
account_address: notary_account_address,
metadata_init: metadata_init! {
"name" => "Ignition Protocol Manager", updatable;
"symbol" => "IGNPM", updatable;
"description" => "A badge with the authority to manage the Ignition protocol.", updatable;
"tags" => vec!["badge"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
},
protocol_owner_badge: BadgeHandling::CreateAndSend {
account_address: notary_account_address,
metadata_init: metadata_init! {
"name" => "Ignition Protocol Owner", updatable;
"symbol" => "IGNPO", updatable;
"description" => "A badge with owner authority over the Ignition protocol.", updatable;
"tags" => vec!["badge"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
},
},
// TODO: Not real resources, just the notXYZ resources.
user_resources: UserResourceIndexedData {
bitcoin: UserResourceHandling::UseExisting {
resource_address: resource_address!(
"resource_tdx_2_1thltk578jr4v7axqpu5ceznhlha6ca2qtzcflqdmytgtf37xncu7l9"
),
},
ethereum: UserResourceHandling::UseExisting {
resource_address: resource_address!(
"resource_tdx_2_1t59gx963vzd6u6fz63h5de2zh9nmgwxc8y832edmr6pxvz98wg6zu3"
),
},
usdc: UserResourceHandling::UseExisting {
resource_address: resource_address!(
"resource_tdx_2_1thfv477eqwlh8x4wt6xsc62myt4z0zxmdpr4ea74fa8jnxh243y60r"
),
},
usdt: UserResourceHandling::UseExisting {
resource_address: resource_address!(
"resource_tdx_2_1t4p3ytx933n576pdps4ua7jkjh36zrh36a543u0tfcsu2vthavlqg8"
),
},
},
packages: Entities {
protocol_entities: ProtocolIndexedData {
ignition: PackageHandling::LoadAndPublish {
crate_package_name: "ignition".to_owned(),
metadata: metadata_init! {
"name" => "Ignition Package", updatable;
"description" => "The implementation of the Ignition protocol.", updatable;
"tags" => Vec::<String>::new(), updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
blueprint_name: "Ignition".to_owned(),
},
simple_oracle: PackageHandling::LoadAndPublish {
crate_package_name: "simple-oracle".to_owned(),
metadata: metadata_init! {
"name" => "Ignition Simple Oracle Package", updatable;
"description" => "The implementation of the Oracle used by the Ignition protocol.", updatable;
"tags" => vec!["oracle"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
blueprint_name: "SimpleOracle".to_owned(),
},
},
exchange_adapter_entities: ExchangeIndexedData {
ociswap_v2: PackageHandling::LoadAndPublish {
crate_package_name: "ociswap-v2-adapter-v1".to_owned(),
metadata: metadata_init! {
"name" => "Ignition Ociswap v2 Adapter Package", updatable;
"description" => "The implementation of an adapter for Ociswap v2 for the Ignition protocol.", updatable;
"tags" => vec!["adapter"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
blueprint_name: "OciswapV2Adapter".to_owned(),
},
defiplaza_v2: PackageHandling::LoadAndPublish {
crate_package_name: "defiplaza-v2-adapter-v1".to_owned(),
metadata: metadata_init! {
"name" => "Ignition DefiPlaza v2 Adapter Package", updatable;
"description" => "The implementation of an adapter for DefiPlaza v1 for the Ignition protocol.", updatable;
"tags" => vec!["adapter"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
blueprint_name: "DefiPlazaV2Adapter".to_owned(),
},
caviarnine_v1: PackageHandling::LoadAndPublish {
crate_package_name: "caviarnine-v1-adapter-v1".to_owned(),
metadata: metadata_init! {
"name" => "Ignition Caviarnine v1 Adapter Package", updatable;
"description" => "The implementation of an adapter for Caviarnine v1 for the Ignition protocol.", updatable;
"tags" => vec!["adapter"], updatable;
// Dapp definition will be automatically added by the
// publisher accordingly.
},
blueprint_name: "CaviarnineV1Adapter".to_owned(),
},
},
},
exchange_information: ExchangeIndexedData {
// No ociswap v2 currently on mainnet.
ociswap_v2: Some(ExchangeInformation {
blueprint_id: BlueprintId {
package_address: package_address!(
"package_tdx_2_1phgf5er6zx60wu4jjhtps97akqjpv787f6k7rjqkxgdpacng89a4uz"
),
blueprint_name: "LiquidityPool".to_owned(),
},
pools: UserResourceIndexedData {
bitcoin: PoolHandling::Create,
ethereum: PoolHandling::Create,
usdc: PoolHandling::Create,
usdt: PoolHandling::Create,
},
liquidity_receipt: LiquidityReceiptHandling::CreateNew {
non_fungible_schema:
NonFungibleDataSchema::new_local_without_self_package_replacement::<
LiquidityReceipt<AnyValue>,
>(),
metadata: metadata_init! {
"name" => "Ignition LP: Ociswap", updatable;
"description" => "Represents a particular contribution of liquidity to Ociswap through the Ignition liquidity incentives program. See the redeem_url metadata for where to redeem these NFTs.", updatable;
"tags" => vec!["lp token"], updatable;
"icon_url" => UncheckedUrl::of("https://assets.radixdlt.com/icons/icon-Ignition-LP.png"), updatable;
"DEX" => "Ociswap", updatable;
// TODO: Must get this from the DEX
"redeem_url" => UncheckedUrl::of("https://www.google.com"), updatable;
},
},
}),
caviarnine_v1: None,
defiplaza_v2: None,
},
additional_information: AdditionalInformation {
ociswap_v2_registry_component: Some(component_address!(
"component_tdx_2_1cpwm3sjxr48gmsnh7lgmh5de3eqqzthqkazztc4qv6n3fvedgjepwk"
)),
},
additional_operation_flags: AdditionalOperationFlags::SUBMIT_ORACLE_PRICES_OF_ONE
// cSpell:enable
}
}
53 changes: 31 additions & 22 deletions tools/publishing-tool/src/cli/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ pub struct Publish {
/// The configuration that the user wants to use when publishing.
configuration_selector: ConfigurationSelector,

/// The path to the state manager database.
state_manager_database_path: PathBuf,

/// The hex-encoded private key of the notary.
notary_ed25519_private_key_hex: String,

/// The path to the state manager database. If no path is provided for the
/// state manager database then it will be assumed that the user does not
/// wish to do a simulation before publishing and is comfortable doing an
/// actual run straightaway.
#[clap(short, long)]
state_manager_database_path: Option<PathBuf>,
}

impl Publish {
Expand All @@ -33,18 +37,31 @@ impl Publish {
let configuration = self
.configuration_selector
.configuration(&notary_private_key);

// Creating the network connection providers to use for the deployments
let network_definition =
self.configuration_selector.network_definition();

// Creating the network connection providers to use for the deployments
if let Some(state_manager_database_path) =
self.state_manager_database_path
{
let database =
RocksDBStore::new_read_only(state_manager_database_path)
.map_err(Error::RocksDbOpenError)?;

let mut simulator_network_provider = SimulatorNetworkConnector::new(
&database,
network_definition.clone(),
);

// Running a dry run of the publishing process against the simulator
// network provider.
log::info!("Publishing against the simulator");
publish(&configuration, &mut simulator_network_provider)?;
}

// Running the transactions against the network.
log::info!("Publishing against the gateway");
let gateway_base_url = self.configuration_selector.gateway_base_url();
let database =
RocksDBStore::new_read_only(self.state_manager_database_path)
.unwrap();
let mut simulator_network_provider = SimulatorNetworkConnector::new(
&database,
network_definition.clone(),
);
let mut gateway_network_provider = GatewayNetworkConnector::new(
gateway_base_url,
network_definition.clone(),
Expand All @@ -53,16 +70,8 @@ impl Publish {
retries: 10,
},
);

// Running a dry run of the publishing process against the simulator
// network provider.
log::info!("Publishing against the simulator");
publish(&configuration, &mut simulator_network_provider)?;

// Running the transactions against the network.
log::info!("Publishing against the gateway");
let receipt = publish(&configuration, &mut gateway_network_provider)?;
writeln!(f, "{}", to_json(&receipt, &network_definition)).unwrap();
Ok(())
writeln!(f, "{}", to_json(&receipt, &network_definition))
.map_err(Error::IoError)
}
}
3 changes: 3 additions & 0 deletions tools/publishing-tool/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::*;
use state_manager::traits::*;

#[derive(Debug)]
pub enum Error {
PrivateKeyError,
GatewayExecutorError(PublishingError<GatewayExecutorError>),
SimulatorExecutorError(PublishingError<MainnetSimulatorError>),
IoError(std::io::Error),
RocksDbOpenError(DatabaseConfigValidationError),
}

impl From<PublishingError<GatewayExecutorError>> for Error {
Expand Down
Loading

0 comments on commit e150d04

Please sign in to comment.