Skip to content

Commit

Permalink
added registry component (keep-starknet-strange#77)
Browse files Browse the repository at this point in the history
* added registry component

* fix registry integration

---------

Co-authored-by: Ikem Peter <[email protected]>
Co-authored-by: Chqrles <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent 41ce6df commit 7c9a046
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions contracts/src/contracts/ramps/revolut/revolut.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ pub mod RevolutRamp {
use openzeppelin::access::ownable::OwnableComponent;
use starknet::storage::Map;
use starknet::{ContractAddress, get_caller_address};
use zkramp::components::registry::interface::OffchainId;
use zkramp::components::registry::interface::{OffchainId, IRegistry};
use zkramp::components::registry::registry::RegistryComponent;
use zkramp::contracts::ramps::revolut::interface::{LiquidityKey, IZKRampLiquidity};

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: RegistryComponent, storage: registry, event: RegistryEvent);

// Ownable
#[abi(embed_v0)]
impl OwnableMixinImpl = OwnableComponent::OwnableMixinImpl<ContractState>;
impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;

// Registry
#[abi(embed_v0)]
impl RegistryImpl = RegistryComponent::RegistryImpl<ContractState>;

//
// Storage
//
Expand All @@ -22,6 +28,8 @@ pub mod RevolutRamp {
struct Storage {
#[substorage(v0)]
ownable: OwnableComponent::Storage,
#[substorage(v0)]
registry: RegistryComponent::Storage,
token: ContractAddress,
// liquidity_key -> amount
liquidity: Map::<LiquidityKey, u256>,
Expand Down Expand Up @@ -55,6 +63,8 @@ pub mod RevolutRamp {
enum Event {
#[flat]
OwnableEvent: OwnableComponent::Event,
#[flat]
RegistryEvent: RegistryComponent::Event,
LiquidityAdded: LiquidityAdded,
}

Expand All @@ -70,15 +80,6 @@ pub mod RevolutRamp {
self.token.write(token);
}


#[generate_trait]
impl Private of PrivateTrait {
// just a mock
fn is_registered(self: @ContractState, contract_address: ContractAddress, offchain_id: OffchainId) -> bool {
true
}
}

#[abi(embed_v0)]
impl ZKRampLiquidityImpl of IZKRampLiquidity<ContractState> {
/// Create a liquidity position by locking an amonunt and asking for
Expand All @@ -90,7 +91,7 @@ pub mod RevolutRamp {
let caller = get_caller_address();

// assert caller registered the offchain ID
assert(self.is_registered(contract_address: caller, :offchain_id), Errors::NOT_REGISTERED);
assert(self.registry.is_registered(contract_address: caller, :offchain_id), Errors::NOT_REGISTERED);
assert(amount.is_non_zero(), Errors::INVALID_AMOUNT);

// get liquidity key
Expand Down

0 comments on commit 7c9a046

Please sign in to comment.