Skip to content

Commit

Permalink
Merge pull request #6 from radixdlt/feature/publishing-tool
Browse files Browse the repository at this point in the history
Publishing tool
  • Loading branch information
0xOmarA authored Mar 11, 2024
2 parents 42cd445 + 316b55a commit b4e1a87
Show file tree
Hide file tree
Showing 48 changed files with 5,289 additions and 2,083 deletions.
906 changes: 840 additions & 66 deletions Cargo.lock

Large diffs are not rendered by default.

48 changes: 32 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = [
"libraries/ports-interface",
"libraries/scrypto-math",
# Tools
"tools/bootstrap",
"tools/publishing-tool",
# Tests
"tests"
]
Expand All @@ -27,21 +27,21 @@ edition = "2021"
description = "The implementation of project Ignition in Scrypto for the Radix Ledger"

[workspace.dependencies]
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
native-sdk = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine-stores = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine-derive = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
utils = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
native-sdk = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-stores = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-derive = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }

scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
scrypto-test = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "ef169b1e1348b8dbad977ba81d086ee1e80d6ff8" }
scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
scrypto-test = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }

[profile.release]
opt-level = 'z'
Expand All @@ -52,4 +52,20 @@ strip = true
overflow-checks = true

[workspace.lints.clippy]
arithmetic_side_effects = "warn"
arithmetic_side_effects = "warn"

[patch.'https://github.com/radixdlt/radixdlt-scrypto']
sbor = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
utils = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
scrypto = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
native-sdk = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
transaction = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-common = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-stores = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-derive = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-queries = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-interface = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
radix-engine-store-interface = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
scrypto-unit = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
scrypto-test = { git = "https://www.github.com/radixdlt/radixdlt-scrypto.git", rev = "4887c5e4be2603433592ed290b70b1a0c03cced3" }
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct NonFungibleResourcesCollectionItemVaultAggregatedVault {

#[serde(rename = "total_count", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "total_count",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub total_count: Option<Option<i64>>,

#[serde(rename = "next_cursor", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "next_cursor",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub next_cursor: Option<Option<String>>,
#[serde(rename = "items")]
pub items: Vec<crate::models::NonFungibleResourcesCollectionItemVaultAggregatedVaultItem>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub struct StateEntityDetailsResponseItem {
)]
pub explicit_metadata: Option<Box<crate::models::EntityMetadataCollection>>,
#[serde(rename = "details", skip_serializing_if = "Option::is_none")]
pub details:
Option<Box<crate::models::StateEntityDetailsResponseItemDetails>>,
pub details: Option<serde_json::Value>,
}

impl StateEntityDetailsResponseItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ pub struct StateEntityDetailsResponsePackageDetails {
#[serde(rename = "code_hex")]
pub code_hex: String,

#[serde(rename = "royalty_vault_balance", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "royalty_vault_balance",
skip_serializing_if = "Option::is_none"
)]
pub royalty_vault_balance: Option<String>,
#[serde(rename = "blueprints", skip_serializing_if = "Option::is_none")]
pub blueprints: Option<Box<crate::models::StateEntityDetailsResponsePackageDetailsBlueprintCollection>>,
pub blueprints:
Option<Box<crate::models::StateEntityDetailsResponsePackageDetailsBlueprintCollection>>,
#[serde(rename = "schemas", skip_serializing_if = "Option::is_none")]
pub schemas: Option<Box<crate::models::StateEntityDetailsResponsePackageDetailsSchemaCollection>>,
pub schemas:
Option<Box<crate::models::StateEntityDetailsResponsePackageDetailsSchemaCollection>>,
}

impl StateEntityDetailsResponsePackageDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ pub struct StateEntityNonFungibleResourceVaultsPageResponse {
#[serde(rename = "ledger_state")]
pub ledger_state: Box<crate::models::LedgerState>,

#[serde(rename = "total_count", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "total_count",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub total_count: Option<Option<i64>>,

#[serde(rename = "next_cursor", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
#[serde(
rename = "next_cursor",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub next_cursor: Option<Option<String>>,
#[serde(rename = "items")]
pub items: Vec<crate::models::NonFungibleResourcesCollectionItemVaultAggregatedVaultItem>,
Expand Down
39 changes: 16 additions & 23 deletions libraries/scrypto-interface/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ fn generate_scrypto_stub(
let mut arguments = arguments.clone();
if arguments.is_function() {
arguments.add_argument_to_end(
Ident::new("blueprint_package_address", ident.span()),
parse_quote!(::radix_engine_interface::prelude::PackageAddress)
Ident::new("blueprint_package_address", ident.span()),
parse_quote!(::radix_engine_interface::prelude::PackageAddress),
);
}

Expand Down Expand Up @@ -296,14 +296,12 @@ fn generate_scrypto_test_stub(
let mut arguments = arguments.clone();
if arguments.is_function() {
arguments.add_argument_to_end(
Ident::new("blueprint_package_address", ident.span()),
parse_quote!(::radix_engine_interface::prelude::PackageAddress)
Ident::new("blueprint_package_address", ident.span()),
parse_quote!(::radix_engine_interface::prelude::PackageAddress),
);
}
arguments.add_argument_to_end(
Ident::new("env", ident.span()),
parse_quote!(&mut Y)
);
arguments
.add_argument_to_end(Ident::new("env", ident.span()), parse_quote!(&mut Y));

let inner = if arguments.is_function() {
quote! {
Expand Down Expand Up @@ -421,29 +419,24 @@ fn generate_manifest_builder_stub(
if arguments.is_function() {
arguments.add_argument_to_beginning(
Ident::new("blueprint_package_address", ident.span()),
parse_quote!(
::radix_engine_interface::prelude::PackageAddress
),
parse_quote!(::radix_engine_interface::prelude::PackageAddress),
);
} else {
arguments.add_argument_to_beginning(
Ident::new("component_address", ident.span()),
parse_quote!(
impl ::transaction::builder::ResolvableGlobalAddress
),
parse_quote!(impl ::transaction::builder::ResolvableGlobalAddress),
);
}

let fn_ident = format_ident!(
"{}_{}",
struct_ident.to_string().to_snake_case(),
ident
);
let fn_ident =
format_ident!("{}_{}", struct_ident.to_string().to_snake_case(), ident);

arguments.manifest_arguments().map(|arguments| quote! {
#(#attrs)*
#[allow(clippy::too_many_arguments)]
#token_fn #fn_ident ( self, #arguments ) -> Self #semi_colon
arguments.manifest_arguments().map(|arguments| {
quote! {
#(#attrs)*
#[allow(clippy::too_many_arguments)]
#token_fn #fn_ident ( self, #arguments ) -> Self #semi_colon
}
})
},
)
Expand Down
23 changes: 23 additions & 0 deletions packages/defiplaza-v2-adapter-v1/src/blueprint_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,26 @@ impl From<Shortage> for ShortageState {
}
}
}

#[derive(
ScryptoSbor,
ManifestSbor,
Copy,
Clone,
Debug,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
)]
pub struct PlazaPair {
pub config: PairConfig,
pub state: PairState,
pub base_address: ResourceAddress,
pub quote_address: ResourceAddress,
pub base_divisibility: u8,
pub quote_divisibility: u8,
pub base_pool: ComponentAddress,
pub quote_pool: ComponentAddress,
}
8 changes: 5 additions & 3 deletions packages/ignition/src/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,10 +1483,12 @@ mod ignition {
}
} else {
drop(entry);
self.pool_units
.insert(global_id, indexmap! {
self.pool_units.insert(
global_id,
indexmap! {
pool_units_resource_address => Vault::with_bucket(pool_units)
})
},
)
}
}

Expand Down
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,
}
1 change: 0 additions & 1 deletion tests/example

This file was deleted.

3 changes: 1 addition & 2 deletions tests/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,7 @@ impl ScryptoTestEnv {
let resource_y =
ResourceManager(XRD).mint_fungible(dec!(100_000_000), &mut env)?;

let (_, change1) =
defiplaza_pool.add_liquidity(resource_x, None, &mut env)?;
let (_, change1) = defiplaza_pool.add_liquidity(resource_x, None, &mut env)?;
let (_, change2) = defiplaza_pool.add_liquidity(resource_y, None, &mut env)?;
let change_amount1 = change1
.map(|bucket| bucket.amount(&mut env).unwrap())
Expand Down
15 changes: 8 additions & 7 deletions tests/tests/caviarnine_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ fn can_close_a_liquidity_position_in_caviarnine_that_fits_into_fee_limits() {
ModuleId::Main,
ConsensusManagerField::ProposerMilliTimestamp.field_index(),
ConsensusManagerProposerMilliTimestampFieldPayload::from_content_source(
ProposerMilliTimestampSubstate { epoch_milli: maturity_instant.seconds_since_unix_epoch * 1000 }
ProposerMilliTimestampSubstate {
epoch_milli: maturity_instant.seconds_since_unix_epoch * 1000,
},
),
)
.unwrap();
Expand All @@ -260,8 +262,9 @@ fn can_close_a_liquidity_position_in_caviarnine_that_fits_into_fee_limits() {
ConsensusManagerField::ProposerMinuteTimestamp.field_index(),
ConsensusManagerProposerMinuteTimestampFieldPayload::from_content_source(
ProposerMinuteTimestampSubstate {
epoch_minute: i32::try_from(maturity_instant.seconds_since_unix_epoch / 60).unwrap(),
}
epoch_minute: i32::try_from(maturity_instant.seconds_since_unix_epoch / 60)
.unwrap(),
},
),
)
.unwrap();
Expand Down Expand Up @@ -1097,10 +1100,8 @@ fn test_effect_of_price_action_on_fees(multiplier: i32, bin_span: u32) {
ConsensusManagerField::ProposerMinuteTimestamp.field_index(),
ConsensusManagerProposerMinuteTimestampFieldPayload::from_content_source(
ProposerMinuteTimestampSubstate {
epoch_minute: i32::try_from(
maturity_instant.seconds_since_unix_epoch / 60,
)
.unwrap(),
epoch_minute: i32::try_from(maturity_instant.seconds_since_unix_epoch / 60)
.unwrap(),
},
),
)
Expand Down
6 changes: 2 additions & 4 deletions tests/tests/caviarnine_v1_simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,10 +1042,8 @@ fn test_effect_of_price_action_on_fees(
ConsensusManagerField::ProposerMinuteTimestamp.field_index(),
ConsensusManagerProposerMinuteTimestampFieldPayload::from_content_source(
ProposerMinuteTimestampSubstate {
epoch_minute: i32::try_from(
maturity_instant.seconds_since_unix_epoch / 60,
)
.unwrap(),
epoch_minute: i32::try_from(maturity_instant.seconds_since_unix_epoch / 60)
.unwrap(),
},
),
)
Expand Down
Loading

0 comments on commit b4e1a87

Please sign in to comment.