Skip to content

Commit

Permalink
[Ociswap v2 Adapter v1]: Add non-fungible data to adapter specific data.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Mar 5, 2024
1 parent fd26ddf commit 1269283
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/ociswap-v2-adapter-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ pub mod adapter {
let (receipt, change_x, change_y) =
pool.add_liquidity(lower_tick, upper_tick, bucket_x, bucket_y);

let non_fungible_global_id = NonFungibleGlobalId::new(
receipt.as_non_fungible().resource_address(),
receipt.as_non_fungible().non_fungible_local_id(),
);
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),
Expand All @@ -183,7 +184,8 @@ pub mod adapter {
adapter_specific_information: AnyValue::from_typed(
&OciswapV2AdapterSpecificInformation {
liquidity_receipt_non_fungible_global_id:
non_fungible_global_id.clone(),
non_fungible_global_id,
liquidity_receipt_data: non_fungible_data,
},
)
.expect(UNEXPECTED_ERROR),
Expand Down Expand Up @@ -259,10 +261,25 @@ pub mod adapter {
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,
}

0 comments on commit 1269283

Please sign in to comment.