Skip to content

Commit

Permalink
Merge pull request #7 from radixdlt/feature/lp-nft-in-ociswap-adapter…
Browse files Browse the repository at this point in the history
…-data

Adding the global-id of the underlying NFT to ociswap adapter specific data.
  • Loading branch information
0xOmarA authored Mar 5, 2024
2 parents 1870bb0 + c7d82e5 commit d938aa6
Show file tree
Hide file tree
Showing 14 changed files with 590 additions and 80 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.

36 changes: 33 additions & 3 deletions packages/ociswap-v2-adapter-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,24 @@ pub mod adapter {
let (receipt, change_x, change_y) =
pool.add_liquidity(lower_tick, upper_tick, bucket_x, bucket_y);

let non_fungible = receipt
.as_non_fungible()
.non_fungible::<LiquidityPosition>();
let non_fungible_data = non_fungible.data();
let non_fungible_global_id = non_fungible.global_id().clone();

OpenLiquidityPositionOutput {
pool_units: IndexedBuckets::from_bucket(receipt),
change: IndexedBuckets::from_buckets([change_x, change_y]),
others: Default::default(),
adapter_specific_information: AnyValue::from_typed(&())
.expect(UNEXPECTED_ERROR),
adapter_specific_information: AnyValue::from_typed(
&OciswapV2AdapterSpecificInformation {
liquidity_receipt_non_fungible_global_id:
non_fungible_global_id,
liquidity_receipt_data: non_fungible_data,
},
)
.expect(UNEXPECTED_ERROR),
}
}

Expand Down Expand Up @@ -246,10 +258,28 @@ pub mod adapter {
}

#[derive(ScryptoSbor, Debug, Clone)]
pub struct OciswapV2AdapterSpecificInformation {}
pub struct OciswapV2AdapterSpecificInformation {
/// Stores the non-fungible global id of the liquidity receipt.
pub liquidity_receipt_non_fungible_global_id: NonFungibleGlobalId,

/// The data of the underlying liquidity receipt
pub liquidity_receipt_data: LiquidityPosition,
}

impl From<OciswapV2AdapterSpecificInformation> for AnyValue {
fn from(value: OciswapV2AdapterSpecificInformation) -> Self {
AnyValue::from_typed(&value).unwrap()
}
}

#[derive(NonFungibleData, ScryptoSbor, Debug, Clone)]
pub struct LiquidityPosition {
liquidity: PreciseDecimal,
left_bound: i32,
right_bound: i32,
shape_id: Option<NonFungibleLocalId>,
x_fee_checkpoint: PreciseDecimal,
y_fee_checkpoint: PreciseDecimal,
x_total_fee_checkpoint: PreciseDecimal,
y_total_fee_checkpoint: PreciseDecimal,
}
8 changes: 8 additions & 0 deletions tools/publishing-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ 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

[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,8 +299,8 @@ pub fn mainnet_testing(
}),
},
additional_information: AdditionalInformation {
ociswap_v2_registry_component: None,
ociswap_v2_registry_component_and_dapp_definition: None,
},
// cSpell:enable
additional_operation_flags: AdditionalOperationFlags::empty(), // cSpell:enable
}
}
13 changes: 11 additions & 2 deletions tools/publishing-tool/src/cli/default_configurations/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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,
StokenetTesting,
}

impl ConfigurationSelector {
Expand All @@ -16,18 +20,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(),
}
}
}
Loading

0 comments on commit d938aa6

Please sign in to comment.