Skip to content

Commit

Permalink
[Adapters Interface]: Use ScryptoValue for the AnyValue type.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Feb 8, 2024
1 parent 7c13c6b commit cf20c39
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 119 deletions.
13 changes: 9 additions & 4 deletions libraries/adapters-interface/src/any_value.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
use radix_engine_interface::prelude::*;

#[derive(Clone, Debug, Sbor, PartialEq, Eq)]
#[derive(Clone, Debug, ScryptoSbor, PartialEq, Eq)]
#[sbor(transparent)]
pub struct AnyValue(Vec<u8>);
pub struct AnyValue((ScryptoValue,));

impl AnyValue {
pub fn from_typed<T>(typed: &T) -> Result<Self, AnyValueError>
where
T: ScryptoEncode,
{
scrypto_encode(typed).map(Self).map_err(Into::into)
scrypto_encode(typed)
.map_err(Into::into)
.and_then(|value| scrypto_decode(&value).map_err(Into::into))
.map(|value| Self((value,)))
}

pub fn as_typed<T>(&self) -> Result<T, AnyValueError>
where
T: ScryptoDecode,
{
scrypto_decode(&self.0).map_err(Into::into)
scrypto_encode(&self.0 .0)
.map_err(Into::into)
.and_then(|value| scrypto_decode(&value).map_err(Into::into))
}
}

Expand Down
2 changes: 0 additions & 2 deletions libraries/adapters-interface/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ define_interface! {
ScryptoStub,
#[cfg(feature = "scrypto-test-stubs")]
ScryptoTestStub,
#[cfg(feature = "manifest-builder-stubs")]
ManifestBuilderStub
] {
/// Opens a liquidity position in the pool.
///
Expand Down
4 changes: 1 addition & 3 deletions packages/ignition/src/types/liquidity_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use adapters_interface::prelude::*;
use scrypto::prelude::*;

/// The data of the liquidity positions given to the users of Ignition.
#[derive(
ScryptoSbor, ManifestSbor, Clone, Debug, PartialEq, Eq, NonFungibleData,
)]
#[derive(ScryptoSbor, Clone, Debug, PartialEq, Eq, NonFungibleData)]
pub struct LiquidityReceipt {
/* Metadata/NonFungibleData standard */
pub name: String,
Expand Down
48 changes: 38 additions & 10 deletions tests/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,44 @@ impl ScryptoUnitEnv {
)
});

let [ociswap_liquidity_receipt_resource, caviarnine_liquidity_receipt_resource] =
[(), ()].map(|_| {
test_runner
.create_freely_mintable_and_burnable_non_fungible_resource(
OwnerRole::None,
NonFungibleIdType::RUID,
None::<Vec<(NonFungibleLocalId, LiquidityReceipt)>>,
account,
)
});
let [ociswap_liquidity_receipt_resource, caviarnine_liquidity_receipt_resource] = [(), ()].map(|_| {
test_runner
.execute_manifest(
ManifestBuilder::new()
.lock_fee_from_faucet()
.call_function(
RESOURCE_PACKAGE,
NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT,
NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_RUID_WITH_INITIAL_SUPPLY_IDENT,
NonFungibleResourceManagerCreateRuidWithInitialSupplyManifestInput {
owner_role: OwnerRole::None,
track_total_supply: true,
non_fungible_schema: NonFungibleDataSchema::new_local_without_self_package_replacement::<LiquidityReceipt>(),
entries: vec![],
resource_roles: NonFungibleResourceRoles {
mint_roles: mint_roles! {
minter => rule!(allow_all);
minter_updater => rule!(allow_all);
},
burn_roles: burn_roles! {
burner => rule!(allow_all);
burner_updater => rule!(allow_all);
},
..Default::default()
},
metadata: Default::default(),
address_reservation: Default::default(),
},
)
.build(),
vec![],
)
.expect_commit_success()
.new_resource_addresses()
.first()
.copied()
.unwrap()
});

let ociswap_pools = resource_addresses.map(|resource_address| {
let manifest = ManifestBuilder::new()
Expand Down
114 changes: 64 additions & 50 deletions tools/bootstrap/src/mainnet_testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,60 +357,74 @@ impl MainnetTesting {

let manifest = ManifestBuilder::new()
// Ociswap liquidity receipt
.create_ruid_non_fungible_resource::<_, LiquidityReceipt>(
owner_role.clone(),
true,
metadata! {
roles {
metadata_setter => protocol_owner_rule.clone();
metadata_setter_updater => protocol_owner_rule.clone();
metadata_locker => protocol_owner_rule.clone();
metadata_locker_updater => protocol_owner_rule.clone();
.call_function(
RESOURCE_PACKAGE,
NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT,
NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_RUID_WITH_INITIAL_SUPPLY_IDENT,
NonFungibleResourceManagerCreateRuidWithInitialSupplyManifestInput {
owner_role: owner_role.clone(),
track_total_supply: true,
non_fungible_schema: NonFungibleDataSchema::new_local_without_self_package_replacement::<LiquidityReceipt>(),
entries: Vec::new(),
resource_roles: roles.clone(),
metadata: metadata! {
roles {
metadata_setter => protocol_owner_rule.clone();
metadata_setter_updater => protocol_owner_rule.clone();
metadata_locker => protocol_owner_rule.clone();
metadata_locker_updater => protocol_owner_rule.clone();
},
init {
// TODO: Confirm with the exchanges what they want
// their name to be.
"name" => "Ignition LP: Ociswap", updatable;
"description" => "Represents a particular contribution of liquidity to Ociswap through the Ignition liquidity incentives program. See the redeem_url metadata for where to redeem these NFTs.", updatable;
"tags" => vec!["lp token"], updatable;
"dapp_definitions" => vec![dapp_definition_account], updatable;
// TODO: Must get this from our design team
"icon_url" => UncheckedUrl::of("https://www.google.com"), updatable;
"DEX" => "Ociswap", updatable;
// TODO: Must get this from Ociswap!
"redeem_url" => UncheckedUrl::of("https://www.google.com"), updatable;
}
},
init {
// TODO: Confirm with the exchanges what they want
// their name to be.
"name" => "Ignition LP: Ociswap", updatable;
"description" => "Represents a particular contribution of liquidity to Ociswap through the Ignition liquidity incentives program. See the redeem_url metadata for where to redeem these NFTs.", updatable;
"tags" => vec!["lp token"], updatable;
"dapp_definitions" => vec![dapp_definition_account], updatable;
// TODO: Must get this from our design team
"icon_url" => UncheckedUrl::of("https://www.google.com"), updatable;
"DEX" => "Ociswap", updatable;
// TODO: Must get this from Ociswap!
"redeem_url" => UncheckedUrl::of("https://www.google.com"), updatable;
}
},
roles.clone(),
Some(vec![]),
address_reservation: None
}
)
// Caviarnine liquidity receipt
.create_ruid_non_fungible_resource::<_, LiquidityReceipt>(
owner_role.clone(),
true,
metadata! {
roles {
metadata_setter => protocol_owner_rule.clone();
metadata_setter_updater => protocol_owner_rule.clone();
metadata_locker => protocol_owner_rule.clone();
metadata_locker_updater => protocol_owner_rule.clone();
.call_function(
RESOURCE_PACKAGE,
NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT,
NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_RUID_WITH_INITIAL_SUPPLY_IDENT,
NonFungibleResourceManagerCreateRuidWithInitialSupplyManifestInput {
owner_role: owner_role.clone(),
track_total_supply: true,
non_fungible_schema: NonFungibleDataSchema::new_local_without_self_package_replacement::<LiquidityReceipt>(),
entries: Vec::new(),
resource_roles: roles.clone(),
metadata: metadata! {
roles {
metadata_setter => protocol_owner_rule.clone();
metadata_setter_updater => protocol_owner_rule.clone();
metadata_locker => protocol_owner_rule.clone();
metadata_locker_updater => protocol_owner_rule.clone();
},
init {
// TODO: Confirm with the exchanges what they want
// their name to be.
"name" => "Ignition LP: Caviarnine", updatable;
"description" => "Represents a particular contribution of liquidity to Caviarnine through the Ignition liquidity incentives program. See the redeem_url metadata for where to redeem these NFTs.", updatable;
"tags" => vec!["lp token"], updatable;
"dapp_definitions" => vec![dapp_definition_account], updatable;
// TODO: Must get this from our design team
"icon_url" => UncheckedUrl::of("https://www.google.com"), updatable;
"DEX" => "Caviarnine", updatable;
// TODO: Must get this from Caviarnine!
"redeem_url" => UncheckedUrl::of("https://www.google.com"), updatable;
}
},
init {
// TODO: Confirm with the exchanges what they want
// their name to be.
"name" => "Ignition LP: Caviarnine", updatable;
"description" => "Represents a particular contribution of liquidity to Caviarnine through the Ignition liquidity incentives program. See the redeem_url metadata for where to redeem these NFTs.", updatable;
"tags" => vec!["lp token"], updatable;
"dapp_definitions" => vec![dapp_definition_account], updatable;
// TODO: Must get this from our design team
"icon_url" => UncheckedUrl::of("https://www.google.com"), updatable;
"DEX" => "Caviarnine", updatable;
// TODO: Must get this from Caviarnine!
"redeem_url" => UncheckedUrl::of("https://www.google.com"), updatable;
}
},
roles,
Some(vec![]),
address_reservation: None
}
)
.build();

Expand Down
Loading

0 comments on commit cf20c39

Please sign in to comment.