Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/usdc_migration/src/errors.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod Errors {
pub const THRESHOLD_TOO_SMALL: felt252 = 'Threshold is too small';
pub const L1_RECIPIENT_NOT_VERIFIED: felt252 = 'L1 recipient not verified.';
}
8 changes: 7 additions & 1 deletion packages/usdc_migration/src/events.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod USDCMigrationEvents {
use starknet::ContractAddress;
use starknet::{ContractAddress, EthAddress};

#[derive(Drop, starknet::Event, Debug, PartialEq)]
pub struct USDCMigrated {
Expand All @@ -11,4 +11,10 @@ pub mod USDCMigrationEvents {
pub to_token: ContractAddress,
pub amount: u256,
}

#[derive(Drop, starknet::Event, Debug, PartialEq)]
pub struct L1RecipientVerified {
#[key]
pub l1_recipient: EthAddress,
}
}
19 changes: 18 additions & 1 deletion packages/usdc_migration/src/usdc_migration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod USDCMigration {
use starkware_utils::constants::MAX_U256;
use starkware_utils::erc20::erc20_utils::CheckedIERC20DispatcherTrait;
use usdc_migration::errors::Errors;
use usdc_migration::events::USDCMigrationEvents::USDCMigrated;
use usdc_migration::events::USDCMigrationEvents::{L1RecipientVerified, USDCMigrated};
use usdc_migration::interface::{IUSDCMigration, IUSDCMigrationAdmin};

pub(crate) const SMALL_BATCH_SIZE: u256 = 10_000_000_000_u256;
Expand Down Expand Up @@ -43,6 +43,8 @@ pub mod USDCMigration {
/// The exact amount of legacy token sent to L1 in a single withdraw action.
/// Must be a value from FIXED_BATCH_SIZES.
batch_size: u256,
/// Indicates if L1 recipient address was verified.
l1_recipient_verified: bool,
}

#[event]
Expand All @@ -51,6 +53,7 @@ pub mod USDCMigration {
OwnableEvent: OwnableComponent::Event,
UpgradeableEvent: UpgradeableComponent::Event,
USDCMigrated: USDCMigrated,
L1RecipientVerified: L1RecipientVerified,
}

#[constructor]
Expand Down Expand Up @@ -143,6 +146,18 @@ pub mod USDCMigration {
}
}

/// Verify the L1 recipient address is a reachable address.
// TODO: Test.
#[l1_handler]
fn verify_l1_recipient(ref self: ContractState, from_address: felt252) {
// TODO: If not verified here?
let l1_recipient = self.l1_recipient.read();
if from_address == l1_recipient.into() {
self.l1_recipient_verified.write(true);
self.emit(L1RecipientVerified { l1_recipient });
}
}

#[generate_trait]
impl USDCMigrationInternalImpl of USDCMigrationInternalTrait {
fn _swap(
Expand All @@ -167,7 +182,9 @@ pub mod USDCMigration {
);
}

// TODO: Catch error in tests in every function that calls this.
fn _send_legacy_to_l1(self: @ContractState, amount: u256) {
assert(self.l1_recipient_verified.read(), Errors::L1_RECIPIENT_NOT_VERIFIED);
// TODO: implement this.
// TODO: Event.
return;
Expand Down