Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing tool #6

Merged
merged 21 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
39cc831
[Publishing Tool]: Introduce the executors
0xOmarA Mar 2, 2024
8ea84bc
[Publishing Tool]: Create the execution service.
0xOmarA Mar 2, 2024
a36666d
[Publishing Tool]: Add a publishing tool
0xOmarA Mar 4, 2024
1870bb0
[Publishing Tool]: Misc changes.
0xOmarA Mar 5, 2024
fd26ddf
[Ociswap v2 Adapter v1]: Add the global id of the underlying LP.
0xOmarA Mar 5, 2024
e150d04
[Publishing Tool]: Allow the publishing tool to run against stokenet
0xOmarA Mar 5, 2024
1269283
[Ociswap v2 Adapter v1]: Add non-fungible data to adapter specific data.
0xOmarA Mar 5, 2024
d774a4b
Merge branch 'feature/lp-nft-in-ociswap-adapter-data' into feature/pu…
0xOmarA Mar 5, 2024
0842a6b
[Publishing Tool]: Have a lib and bin in same crate
0xOmarA Mar 5, 2024
c7d82e5
Merge pull request #8 from radixdlt/feature/publishing-tool-stokenet
0xOmarA Mar 5, 2024
d938aa6
Merge pull request #7 from radixdlt/feature/lp-nft-in-ociswap-adapter…
0xOmarA Mar 5, 2024
cc5b086
[Defiplaza v2 Adapter v1]: Some cleanups and tests
0xOmarA Mar 5, 2024
c4910fc
[Misc]: Fix cargo.lock issue
0xOmarA Mar 11, 2024
ae47f63
[Defiplaza v2 Adapter v1]: Small correction
0xOmarA Mar 5, 2024
20faa96
[Defiplaza v2 Adapter v1]: Rename `add_pair_config` to plural
0xOmarA Mar 6, 2024
731c951
[Defiplaza v2 Adapter v1]: Rename first and second to shortage and
0xOmarA Mar 6, 2024
14c3cfe
[Caviarnine v1 Adapter v1]: Optimize fees for opening positions.
0xOmarA Mar 6, 2024
7160d6d
[Tests]: Add basis for defiplaza v2 fee tests
0xOmarA Mar 7, 2024
ed3d11c
[Tests]: Fix tests
0xOmarA Mar 7, 2024
1424189
[Defiplaza v2 Adapter v1]: Update the fee calculation and add tests
0xOmarA Mar 11, 2024
316b55a
Merge remote-tracking branch 'origin/feature/defiplaza-support' into …
0xOmarA Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading