Skip to content

Commit

Permalink
[Publishing Tool]: Have a lib and bin in same crate
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Mar 5, 2024
1 parent d774a4b commit 0842a6b
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 63 deletions.
7 changes: 7 additions & 0 deletions tools/publishing-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ bitflags = "2.4.2"

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "lib"]

[[bin]]
name = "publishing-tool"
path = "src/cli/bin.rs"
29 changes: 29 additions & 0 deletions tools/publishing-tool/src/cli/bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![allow(dead_code, clippy::enum_variant_names, clippy::wrong_self_convention)]

mod default_configurations;
mod publish;

use clap::Parser;
use publishing_tool::error::*;
use radix_engine_common::prelude::*;
use transaction::prelude::*;

fn main() -> Result<(), Error> {
env_logger::init();
let mut out = std::io::stdout();
let cli = <Cli as clap::Parser>::parse();
cli.run(&mut out)
}

#[derive(Parser, Debug)]
pub enum Cli {
Publish(publish::Publish),
}

impl Cli {
pub fn run<O: std::io::Write>(self, out: &mut O) -> Result<(), Error> {
match self {
Self::Publish(cmd) => cmd.run(out),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use common::prelude::*;

use self::utils::*;
use crate::*;
use publishing_tool::publishing::*;
use publishing_tool::utils::*;
use publishing_tool::*;
use radix_engine_interface::prelude::*;
use transaction::prelude::*;

pub fn mainnet_testing(
notary_private_key: &PrivateKey,
Expand Down Expand Up @@ -297,9 +299,8 @@ pub fn mainnet_testing(
}),
},
additional_information: AdditionalInformation {
ociswap_v2_registry_component: None,
ociswap_v2_registry_component_and_dapp_definition: None,
},
additional_operation_flags: AdditionalOperationFlags::empty()
// cSpell:enable
additional_operation_flags: AdditionalOperationFlags::empty(), // cSpell:enable
}
}
6 changes: 4 additions & 2 deletions tools/publishing-tool/src/cli/default_configurations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::*;
use clap::*;
mod mainnet_testing;
mod stokenet_testing;

use clap::*;
use publishing_tool::publishing::*;
use transaction::prelude::*;

#[derive(ValueEnum, Clone, Copy, Debug)]
pub enum ConfigurationSelector {
MainnetTesting,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use common::prelude::*;

use self::utils::*;
use crate::*;
use publishing_tool::publishing::*;
use publishing_tool::utils::*;
use publishing_tool::*;
use radix_engine_interface::prelude::*;
use transaction::prelude::*;

pub fn stokenet_testing(
notary_private_key: &PrivateKey,
Expand Down Expand Up @@ -233,11 +235,21 @@ pub fn stokenet_testing(
defiplaza_v2: None,
},
additional_information: AdditionalInformation {
ociswap_v2_registry_component: Some(component_address!(
"component_tdx_2_1cpwm3sjxr48gmsnh7lgmh5de3eqqzthqkazztc4qv6n3fvedgjepwk"
ociswap_v2_registry_component_and_dapp_definition: Some((
component_address!(
"component_tdx_2_1cpwm3sjxr48gmsnh7lgmh5de3eqqzthqkazztc4qv6n3fvedgjepwk"
),
component_address!(
"account_tdx_2_12yhfrtak5j0pmaju5l3p752wpye4z4nzua679ypns0094hmu66p2yk"
),
)),
},
additional_operation_flags: AdditionalOperationFlags::SUBMIT_ORACLE_PRICES_OF_ONE
// cSpell:enable
additional_operation_flags:
AdditionalOperationFlags::SUBMIT_ORACLE_PRICES_OF_ONE
.union(AdditionalOperationFlags::PROVIDE_INITIAL_IGNITION_LIQUIDITY)
.union(
AdditionalOperationFlags::PROVIDE_INITIAL_LIQUIDITY_TO_OCISWAP_BY_MINTING_USER_RESOURCE
)
}
// cSpell:enable
}
18 changes: 0 additions & 18 deletions tools/publishing-tool/src/cli/mod.rs

This file was deleted.

6 changes: 4 additions & 2 deletions tools/publishing-tool/src/cli/publish.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::default_configurations::*;
use crate::utils::*;
use crate::default_configurations::*;
use crate::*;
use clap::Parser;
use publishing_tool::network_connection_provider::*;
use publishing_tool::publishing::*;
use publishing_tool::utils::*;
use radix_engine_common::prelude::*;
use state_manager::RocksDBStore;
use std::path::*;
Expand Down
3 changes: 2 additions & 1 deletion tools/publishing-tool/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::*;
use crate::network_connection_provider::*;
use crate::publishing::*;
use state_manager::traits::*;

#[derive(Debug)]
Expand Down
6 changes: 6 additions & 0 deletions tools/publishing-tool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod database_overlay;
pub mod error;
pub mod macros;
pub mod network_connection_provider;
pub mod publishing;
pub mod utils;
23 changes: 0 additions & 23 deletions tools/publishing-tool/src/main.rs

This file was deleted.

8 changes: 7 additions & 1 deletion tools/publishing-tool/src/publishing/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ bitflags::bitflags! {
/// attempt to get the XRD from the faucet. If otherwise then it will
/// attempt to mint it.
const PROVIDE_INITIAL_IGNITION_LIQUIDITY = 0b00000010;

/// Provides initial liquidity to ociswap v2 pools by minting the user
/// asset. If the protocol asset is mintable then it mints them in the
/// process and if they're not then it gets them from the faucet.
const PROVIDE_INITIAL_LIQUIDITY_TO_OCISWAP_BY_MINTING_USER_RESOURCE = 0b00000100;
}
}

Expand All @@ -94,7 +99,8 @@ pub struct ProtocolConfigurationReceipt {
}

pub struct AdditionalInformation {
pub ociswap_v2_registry_component: Option<ComponentAddress>,
pub ociswap_v2_registry_component_and_dapp_definition:
Option<(ComponentAddress, ComponentAddress)>,
}

pub struct ProtocolConfiguration {
Expand Down
123 changes: 120 additions & 3 deletions tools/publishing-tool/src/publishing/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use defiplaza_v2_adapter_v1::*;
use ignition::{InitializationParametersManifest, PoolBlueprintInformation};
use itertools::*;
use ociswap_v2_adapter_v1::OciswapV2PoolInterfaceManifestBuilderExtensionTrait;
use package_loader::*;
use radix_engine::blueprints::package::*;
use radix_engine::types::node_modules::*;
Expand Down Expand Up @@ -974,6 +975,119 @@ pub fn publish<N: NetworkConnectionProvider>(
.build();
execution_service.execute_manifest(manifest)?;
}

// Seeding Ignition with the initial set of XRD if requested.
if configuration.additional_operation_flags.contains(
AdditionalOperationFlags::PROVIDE_INITIAL_IGNITION_LIQUIDITY,
) {
let total_amount_of_protocol_resource = dec!(10_000);
let mut manifest_builder = ManifestBuilder::new()
.create_proof_from_account_of_amount(
resolved_badges.protocol_owner_badge.0,
resolved_badges.protocol_owner_badge.1,
dec!(1),
);
if configuration.protocol_configuration.protocol_resource == XRD {
manifest_builder = manifest_builder.get_free_xrd_from_faucet()
} else {
manifest_builder = manifest_builder.mint_fungible(
configuration.protocol_configuration.protocol_resource,
total_amount_of_protocol_resource,
)
}

let manifest = manifest_builder
.take_from_worktop(
XRD,
total_amount_of_protocol_resource / 2,
"volatile",
)
.take_from_worktop(
XRD,
total_amount_of_protocol_resource / 2,
"non_volatile",
)
.with_name_lookup(|builder, _| {
let volatile = builder.bucket("volatile");
let non_volatile = builder.bucket("non_volatile");

builder
.call_method(
resolved_entity_component_addresses
.protocol_entities
.ignition,
"deposit_protocol_resources",
(volatile, common::prelude::Volatility::Volatile),
)
.call_method(
resolved_entity_component_addresses
.protocol_entities
.ignition,
"deposit_protocol_resources",
(
non_volatile,
common::prelude::Volatility::NonVolatile,
),
)
})
.build();
execution_service.execute_manifest(manifest)?;
}

// Contributing initial liquidity to Ociswap if requested
if configuration.additional_operation_flags.contains(
AdditionalOperationFlags::PROVIDE_INITIAL_LIQUIDITY_TO_OCISWAP_BY_MINTING_USER_RESOURCE,
) {
if let Some(ExchangeInformation { pools, .. }) = resolved_exchange_data.ociswap_v2 {
for (pool_address, user_resource_address) in
pools.zip_borrowed(&resolved_user_resources).iter()
{
let (pool_address, user_resource_address) =
(*pool_address, **user_resource_address);

let mut manifest_builder = ManifestBuilder::new();
if configuration.protocol_configuration.protocol_resource == XRD {
manifest_builder = manifest_builder.get_free_xrd_from_faucet()
} else {
manifest_builder = manifest_builder.mint_fungible(
configuration.protocol_configuration.protocol_resource,
dec!(10_000),
)
}
let manifest = manifest_builder
.mint_fungible(user_resource_address, dec!(10_000))
.take_all_from_worktop(
configuration.protocol_configuration.protocol_resource,
"protocol",
)
.take_all_from_worktop(user_resource_address, "user")
.then(|builder| {
let protocol_resource = builder.bucket("protocol");
let user_resource = builder.bucket("user");

let (x_bucket, y_bucket) =
if configuration.protocol_configuration.protocol_resource
< user_resource_address
{
(protocol_resource, user_resource)
} else {
(user_resource, protocol_resource)
};

builder.ociswap_v2_pool_add_liquidity(
pool_address,
-3921i32,
9942i32,
x_bucket,
y_bucket,
)
})
.try_deposit_entire_worktop_or_abort(ephemeral_account, None)
.build();
execution_service.execute_manifest(manifest)?;
}
}
}
}

// Depositing the created badges into their accounts.
Expand Down Expand Up @@ -1063,7 +1177,11 @@ fn handle_ociswap_v2_exchange_information<N: NetworkConnectionProvider>(
> {
// No ociswap registry component is passed even through it is needed.
let AdditionalInformation {
ociswap_v2_registry_component: Some(ociswap_v2_registry_component),
ociswap_v2_registry_component_and_dapp_definition:
Some((
ociswap_v2_registry_component,
ociswap_v2_dapp_definition_account,
)),
} = additional_information
else {
return Ok(None);
Expand Down Expand Up @@ -1130,8 +1248,7 @@ fn handle_ociswap_v2_exchange_information<N: NetworkConnectionProvider>(
ManifestBucket,
)>::new(
),
// TODO: Specify their dapp definition?
FAUCET,
ociswap_v2_dapp_definition_account,
),
)
.build();
Expand Down

0 comments on commit 0842a6b

Please sign in to comment.