Skip to content

Conversation

@arad-starkware
Copy link
Collaborator

@arad-starkware arad-starkware commented Oct 22, 2025

This change is Reviewable

Copy link
Collaborator Author

arad-starkware commented Oct 22, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 4 unresolved discussions (waiting on @arad-starkware)


packages/usdc_migration/src/usdc_migration.cairo line 31 at r1 (raw file):

        l1_transfer_unit: u256,
        /// L1 USDC token address.
        l1_usdc_token_address: EthAddress,

all should be initialized in constructor


packages/usdc_migration/src/usdc_migration.cairo line 83 at r1 (raw file):

            self.emit(USDCMigrationEvents::USDCMigratedEvent { amount, user: caller_address });
            self._recycle(:contract_address);

Why we need that as param?

Code quote:

contract_address

packages/usdc_migration/src/usdc_migration.cairo line 86 at r1 (raw file):

        }

        fn recycle(ref self: ContractState) {

Didnt we decide its not needed?


packages/usdc_migration/src/usdc_migration.cairo line 116 at r1 (raw file):

                starkgate_dispatcher
                    .initiate_token_withdraw(
                        l1_token: l1_usdc_token_address, :l1_recipient, :amount,

where is the unit size?

@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch from 41f2ef7 to efd71d4 Compare October 23, 2025 07:12
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch 2 times, most recently from 57f2b91 to 6d4edac Compare October 23, 2025 07:51
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch from efd71d4 to 97fbb47 Compare October 23, 2025 07:51
@arad-starkware arad-starkware changed the base branch from arad/feat_migrate_function_implementation to graphite-base/17 October 23, 2025 07:52
Copy link
Collaborator Author

@arad-starkware arad-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 4 unresolved discussions (waiting on @arad-starkware and @noa-starkware)


packages/usdc_migration/src/usdc_migration.cairo line 31 at r1 (raw file):

Previously, noa-starkware wrote…

all should be initialized in constructor

don't you do that in set_threshold?
I want to keep this as a draft until that one is merged (or the PRs below this one are so I can move it above set_threshold)


packages/usdc_migration/src/usdc_migration.cairo line 83 at r1 (raw file):

Previously, noa-starkware wrote…

Why we need that as param?

to avoid calling it again


packages/usdc_migration/src/usdc_migration.cairo line 86 at r1 (raw file):

Previously, noa-starkware wrote…

Didnt we decide its not needed?

depends, do we call recycle when setting the threshold?


packages/usdc_migration/src/usdc_migration.cairo line 116 at r1 (raw file):

Previously, noa-starkware wrote…

where is the unit size?

l1_transfer_unit? or do you mean the list?
This PR is not ready, which is why I left it as a draft, I wanted to wait until set_threshold is merged before going forward.

@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 6d4edac to 7a637de Compare October 23, 2025 08:10
@arad-starkware arad-starkware changed the base branch from graphite-base/17 to arad/feat_migrate_function_implementation October 23, 2025 08:10
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch 3 times, most recently from 036d42a to 564c045 Compare October 23, 2025 11:17
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch 2 times, most recently from 0979a5d to 56cad55 Compare October 23, 2025 11:27
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 564c045 to 56317f1 Compare October 23, 2025 11:27
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch from 56cad55 to f06c0f7 Compare October 23, 2025 13:07
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch 2 times, most recently from 308b694 to 9cc51f6 Compare October 23, 2025 13:28
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch from f06c0f7 to 8fc26fa Compare October 23, 2025 13:28
@remollemo remollemo changed the title feat: recycle implementation feat: send legacy balance to L1 Oct 23, 2025
Copy link
Collaborator

@remollemo remollemo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remollemo reviewed 1 of 3 files at r2.
Reviewable status: 1 of 6 files reviewed, 8 unresolved discussions (waiting on @arad-starkware and @noa-starkware)


packages/usdc_migration/src/starkgate_interface.cairo line 4 at r4 (raw file):

#[starknet::interface]
pub(crate) trait ITokenBridge<TContractState> {

does it have to be pub?

Code quote:

pub(crate) 

packages/usdc_migration/src/usdc_migration.cairo line 44 at r4 (raw file):

        l1_transfer_unit: u256,
        /// L1 USDC token address.
        l1_usdc_token_address: EthAddress,

Suggestion:

l1_token_address

packages/usdc_migration/src/interface.cairo line 5 at r4 (raw file):

    /// Exchange `amount` of legacy token for new token.
    /// Precondition: Caller has approved the contract to spend `amount` of legacy token.
    fn exchange_legacy_for_new(ref self: T, amount: u256);

Suggestion:

  fn exchange_legacy_for_new(ref self: T, amount: u256);
  fn exchange_legacy_for_new(ref self: T, amount: u256);

packages/usdc_migration/src/interface.cairo line 6 at r4 (raw file):

    /// Precondition: Caller has approved the contract to spend `amount` of legacy token.
    fn exchange_legacy_for_new(ref self: T, amount: u256);
    fn recycle(ref self: T);

we don't recycle, we send legacy tokens to L1.

Code quote:

    fn recycle(ref self: T);

Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 6 files reviewed, 7 unresolved discussions (waiting on @arad-starkware)


packages/usdc_migration/src/usdc_migration.cairo line 86 at r1 (raw file):

Previously, arad-starkware wrote…

depends, do we call recycle when setting the threshold?

We can do that if we want to

@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 40501c7 to 4f23fac Compare October 26, 2025 08:05
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch from bce1766 to 05c3064 Compare October 26, 2025 08:05
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 4f23fac to 77f1990 Compare October 26, 2025 08:40
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch 2 times, most recently from ac2c0c6 to eff588c Compare October 26, 2025 08:47
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 77f1990 to 6fe682a Compare October 26, 2025 08:47
@arad-starkware arad-starkware changed the base branch from arad/feat_migrate_function_implementation to graphite-base/17 October 26, 2025 11:02
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 6fe682a to 7428b19 Compare October 26, 2025 11:04
@arad-starkware arad-starkware changed the base branch from graphite-base/17 to arad/feat_migrate_function_implementation October 26, 2025 11:04
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 7428b19 to 15b7cf5 Compare October 26, 2025 11:05
@arad-starkware arad-starkware force-pushed the arad/feat_migrate_function_implementation branch from d1e5b6c to 2ff8f91 Compare October 26, 2025 11:05
@arad-starkware arad-starkware changed the base branch from arad/feat_migrate_function_implementation to graphite-base/17 October 26, 2025 12:04
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 15b7cf5 to f0a8f37 Compare October 26, 2025 12:22
@arad-starkware arad-starkware changed the base branch from graphite-base/17 to main October 26, 2025 12:22
@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch 4 times, most recently from e6610e2 to 151c2ba Compare October 26, 2025 14:28
Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 17 unresolved discussions (waiting on @arad-starkware and @remollemo)


packages/usdc_migration/src/usdc_migration.cairo line 86 at r1 (raw file):

Previously, noa-starkware wrote…

We can do that if we want to

Do we want to?


packages/usdc_migration/src/usdc_migration.cairo line 41 at r7 (raw file):

        l1_recipient: EthAddress,
        /// Address in L2 that gets the remaining USDC.
        owner_l2_address: ContractAddress,

revert

Code quote:

        /// Address in L2 that gets the remaining USDC.
        owner_l2_address: ContractAddress,

packages/usdc_migration/src/usdc_migration.cairo line 50 at r7 (raw file):

        batch_size: u256,
        /// L1 USDC token address.
        l1_token_address: EthAddress,

add it next to the other addresses in storage

Code quote:

        /// L1 USDC token address.
        l1_token_address: EthAddress,

packages/usdc_migration/src/usdc_migration.cairo line 71 at r7 (raw file):

        starkgate_address: ContractAddress,
        legacy_threshold: u256,
        l1_token_address: EthAddress,

Suggestion:

        ref self: ContractState,
        legacy_token: ContractAddress,
        new_token: ContractAddress,
        l1_token_address: EthAddress,
        l1_recipient: EthAddress,
        owner: ContractAddress,
        starkgate_address: ContractAddress,
        legacy_threshold: u256,

packages/usdc_migration/src/usdc_migration.cairo line 84 at r7 (raw file):

        self.batch_size.write(LARGE_BATCH_SIZE);
        self.ownable.initializer(:owner);
        self.l1_token_address.write(l1_token_address);

move


packages/usdc_migration/src/usdc_migration.cairo line 103 at r7 (raw file):

    pub impl USDCMigrationImpl of IUSDCMigration<ContractState> { //impl logic
        fn swap_to_new(ref self: ContractState, amount: u256) {
            let contract_address = get_contract_address();

What is the cost of this line? @remollemo


packages/usdc_migration/src/usdc_migration.cairo line 122 at r7 (raw file):

                    to_token: self.legacy_token_dispatcher.read(),
                    :amount,
                );

Suggestion:

self
                ._swap(
                    contract_address: get_contract_address(),
                    from_token: self.new_token_dispatcher.read(),
                    to_token: self.legacy_token_dispatcher.read(),
                    :amount,
                );

packages/usdc_migration/src/usdc_migration.cairo line 128 at r7 (raw file):

            let contract_address = get_contract_address();
            self._send_to_l1(:contract_address);
        }

IMO delete

Code quote:

        fn send_to_l1(ref self: ContractState) {
            let contract_address = get_contract_address();
            self._send_to_l1(:contract_address);
        }

packages/usdc_migration/src/usdc_migration.cairo line 174 at r7 (raw file):

    #[generate_trait]
    impl InternalUSDCMigration of InternalUSDCMigrationTrait {

why?


packages/usdc_migration/src/usdc_migration.cairo line 198 at r7 (raw file):

        fn _send_legacy_to_l1(self: @ContractState, amount: u256) {
            self.send_units_to_l1(batch_size: amount, batch_count: 1);

rename


packages/usdc_migration/src/usdc_migration.cairo line 201 at r7 (raw file):

        }

        fn _send_to_l1(ref self: ContractState, contract_address: ContractAddress) {

Why not do the for inside this function and calls _send_legacy_to_l1 just gets amount and invokes initiate_token_withdraw? Now there are too many functions that handle the same.


packages/usdc_migration/src/usdc_migration.cairo line 225 at r7 (raw file):

                starkgate_dispatcher
                    .initiate_token_withdraw(:l1_token, :l1_recipient, amount: batch_size);
            }

Or use while instead of calculate and then use for.
You can pass also l1_token, l1_recipient, starkgate_bridge to save readings.

Suggestion:

        fn _send_legacy_to_l1(self: @ContractState, amount: u256) {
            starkgate_dispatcher
                    .initiate_token_withdraw(l1_token, l1_recipient, amount);
        }

        fn _send_to_l1(ref self: ContractState, contract_address: ContractAddress) {
            let legacy_balance = self
                .legacy_token_dispatcher
                .read()
                .balance_of(account: contract_address);
            if legacy_balance < self.legacy_threshold.read() {
                return;
            }

            let batch_size = self.batch_size.read();
            let batch_count = legacy_balance / batch_size;
            for _ in 0..batch_count {
                self._send_legacy_to_l1(amount: batch_size)

            self.emit(SentToL1 { amount: batch_size * batch_count, batch_size, batch_count });
        }

packages/usdc_migration/src/interface.cairo line 10 at r7 (raw file):

    fn swap_to_legacy(ref self: T, amount: u256);
    /// Sends legacy tokens to L1 in batches of `l1_transfer_unit`.
    fn send_to_l1(ref self: T);

I think we dont need that function

@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 151c2ba to 6242309 Compare October 26, 2025 15:14
Copy link
Collaborator Author

@arad-starkware arad-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 17 unresolved discussions (waiting on @arad-starkware, @noa-starkware, and @remollemo)


packages/usdc_migration/src/interface.cairo line 6 at r4 (raw file):

Previously, remollemo wrote…

we don't recycle, we send legacy tokens to L1.

Done.


packages/usdc_migration/src/interface.cairo line 10 at r7 (raw file):

Previously, noa-starkware wrote…

I think we dont need that function

Done.


packages/usdc_migration/src/starkgate_interface.cairo line 4 at r4 (raw file):

Previously, remollemo wrote…

does it have to be pub?

so we use it in the impl yes, should i maybe duplicate this interface for the test so we don't have to do this?


packages/usdc_migration/src/usdc_migration.cairo line 86 at r1 (raw file):

Previously, noa-starkware wrote…

Do we want to?

yes


packages/usdc_migration/src/usdc_migration.cairo line 41 at r7 (raw file):

Previously, noa-starkware wrote…

revert

Done.


packages/usdc_migration/src/usdc_migration.cairo line 50 at r7 (raw file):

Previously, noa-starkware wrote…

add it next to the other addresses in storage

Done.


packages/usdc_migration/src/usdc_migration.cairo line 84 at r7 (raw file):

Previously, noa-starkware wrote…

move

Done.


packages/usdc_migration/src/usdc_migration.cairo line 103 at r7 (raw file):

Previously, noa-starkware wrote…

What is the cost of this line? @remollemo

I removed it... it's ridiculous...


packages/usdc_migration/src/usdc_migration.cairo line 128 at r7 (raw file):

Previously, noa-starkware wrote…

IMO delete

Done.


packages/usdc_migration/src/usdc_migration.cairo line 174 at r7 (raw file):

Previously, noa-starkware wrote…

why?

that's what i called it before your PRs were merged and I forgot to change it


packages/usdc_migration/src/usdc_migration.cairo line 198 at r7 (raw file):

Previously, noa-starkware wrote…

rename

Done.


packages/usdc_migration/src/usdc_migration.cairo line 201 at r7 (raw file):

Previously, noa-starkware wrote…

Why not do the for inside this function and calls _send_legacy_to_l1 just gets amount and invokes initiate_token_withdraw? Now there are too many functions that handle the same.

I'd rather split this since this way _send_legacy_batches_to_l1 is exactly the shared logic between send_legacy_balance_to_l1 and send_legacy_batches_to_l1


packages/usdc_migration/src/usdc_migration.cairo line 225 at r7 (raw file):

Previously, noa-starkware wrote…

Or use while instead of calculate and then use for.
You can pass also l1_token, l1_recipient, starkgate_bridge to save readings.

I want the calculation for the event anyway, and as I said above, this way I get to reuse logic between the functions that send to l1 without reading from storage in both.


packages/usdc_migration/src/usdc_migration.cairo line 71 at r7 (raw file):

        starkgate_address: ContractAddress,
        legacy_threshold: u256,
        l1_token_address: EthAddress,

Done.


packages/usdc_migration/src/usdc_migration.cairo line 122 at r7 (raw file):

                    to_token: self.legacy_token_dispatcher.read(),
                    :amount,
                );

Done.


packages/usdc_migration/src/usdc_migration.cairo line 44 at r4 (raw file):

        l1_transfer_unit: u256,
        /// L1 USDC token address.
        l1_usdc_token_address: EthAddress,

Done.

@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch 3 times, most recently from 7a4c970 to 2a6961c Compare October 26, 2025 15:24
Copy link
Collaborator

@remollemo remollemo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 13 files reviewed, 17 unresolved discussions (waiting on @arad-starkware and @noa-starkware)


packages/usdc_migration/src/usdc_migration.cairo line 67 at r9 (raw file):

        new_token: ContractAddress,
        l1_recipient: EthAddress,
        l1_token_address: EthAddress,

why should we get l1_token_address in constructor?
we need it only to push stuff thru SG to L1,
we can very well just use the ITokenBridge::get_l1_token(legacy_token) either every time or to store it in construction using this.
the only "agreeable" reason IMO to get it is to validate the wiring. but you have no wiring validatoin to begin with.

Code quote:

    l1_token_address: EthAddress,

packages/usdc_migration/src/usdc_migration.cairo line 186 at r9 (raw file):

        }

        fn send_legacy_batches_to_l1(ref self: ContractState) {

the batchkiada is internal. the highlevel action is sending them tokens to l1.

Suggestion:

send_legacy_tokens_to_l1

@arad-starkware arad-starkware force-pushed the arad/feat_recycle_implementation branch from 2a6961c to f8b16d5 Compare October 26, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants