0xSpaceShard / starknet-devnet-rs

A local testnet for Starknet... in Rust
https://0xspaceshard.github.io/starknet-devnet-rs/
MIT License
107 stars 62 forks source link

No easy way of importing the `StarknetMessaging` Interface #603

Open pscott opened 1 month ago

pscott commented 1 month ago

It's now easy to deploy a StarknetMessaging contract with .spawnVersion(). Great idea!

However, if one wants to interact with it in his own contract (example using sendMessageToL2), then one needs to import the MockStarknetMessaging.sol. But importing this one implies import a whole bunch of other dependencies.

I'm not sure exactly what is the strict minimum of function that are use from the MockStarknetMessaging.sol contract but it might bebeneficial to have a lean interface for it :)

FabijanC commented 1 month ago

This part is confusing me:

It's now easy to deploy a StarknetMessaging contract with .spawnVersion(). Great idea!

Are you referring to the spawnVersion method of Devnet from starknet-devnet-js? If so, that one is for spawning Devnet, not deploying a StarknetMessaging contract. ~Unless you are spawning a Devnet that loads a dumped instance with a previously deployed messaging contract.~

FabijanC commented 1 month ago

Contract dependency summary

Simplification proposal

Copied from Discord:

What I had in mind is replicated this cairo storage values into solidity for the mock messaging contract: https://github.com/keep-starknet-strange/piltover/blob/a9c015eada5082076185a7b1413163a3da247009/src/messaging/component.cairo#L58.

And here we extracted only the required interface traits to actually work: https://github.com/keep-starknet-strange/piltover/blob/a9c015eada5082076185a7b1413163a3da247009/src/messaging/interface.cairo#L10.

So mapping this to a solidity code should make the mock way simpler that using the actual inheritance of the Starknet contract.

marioiordanov commented 1 month ago

Hey @pscott I can't understand the following

However, if one wants to interact with it in his own contract

Do you mean that you have a solidity contract and you want to invoke methods of MockStarknetMessaging contract?

pscott commented 1 month ago

This part is confusing me:

It's now easy to deploy a StarknetMessaging contract with .spawnVersion(). Great idea!

Are you referring to the spawnVersion method of Devnet from starknet-devnet-js? If so, that one is for spawning Devnet, not deploying a StarknetMessaging contract. ~Unless you are spawning a Devnet that loads a dumped instance with a previously deployed messaging contract.~

My bad, I wanted to write .loadL1MessagingContract(network) function, not the spawnVersion.

pscott commented 1 month ago

Contract dependency summary

  • MockStarknetMessaging (defined in MockStarknetMessaging.sol) is an instance of StarknetMessaging (defined in StarknetMessaging.sol).
  • StarknetMessaging is IStarknetMessaging (defined in IStarknetMessaging.sol) and uses methods of NamedStorage (defined in NamedStorage.sol).
  • IStarknetMessaging is IStarknetMessagingEvents (defined in IStarknetMessagingEvents.sol)

Simplification proposal

Copied from Discord:

What I had in mind is replicated this cairo storage values into solidity for the mock messaging contract: https://github.com/keep-starknet-strange/piltover/blob/a9c015eada5082076185a7b1413163a3da247009/src/messaging/component.cairo#L58.

And here we extracted only the required interface traits to actually work: https://github.com/keep-starknet-strange/piltover/blob/a9c015eada5082076185a7b1413163a3da247009/src/messaging/interface.cairo#L10.

So mapping this to a solidity code should make the mock way simpler that using the actual inheritance of the Starknet contract.

This would work, or maybe just creating a single file that takes all the external function of:

By having everything in a single file, it would make interacting with the contract much easier (though I agree it would be a messy file ...)

pscott commented 1 month ago

Hey @pscott I can't understand the following

However, if one wants to interact with it in his own contract

Do you mean that you have a solidity contract and you want to invoke methods of MockStarknetMessaging contract?

Yes this is exactly what I was referring to. Interacting with the MockStarknetMessaging contract requires me to copy paste a whole bunch of other files.

marioiordanov commented 1 month ago

What I can suggest is using IStarknetMessaging interface. When you want to call methods of the messaging contract you can just do IStarknetMessaging(messaging_contract_address).sendMessageToL2

pscott commented 1 month ago

What I can suggest is using IStarknetMessaging interface. When you want to call methods of the messaging contract you can just do IStarknetMessaging(messaging_contract_address).sendMessageToL2

I believe the issue is if I wish to write IStarknetMessaging(messaging_contract_address), I need to first have imported the file. So I write import "./IStarknetMessaging.sol";.

But since this file starts with import "./IStarknetMessagingEvents.sol";, I also need to copy the file IStarknetMessagingEvents.sol. So I still need to copy two different files. This clobbers up my repo.

What would be nice is to have a simple, lean, interface file, that one can import and that has all the functions available to interact with the messaging contract

marioiordanov commented 1 month ago

Then you can omit IStarknetMessagingEvents.sol from IStarknetMessaging.sol and you will have 1 file.

pscott commented 1 month ago

In which case I also need to remove is IStarknetMessagingEvent. I feel like to a beginner, touching the code of a copied file might no be intuitive. I think providing the interface somewhere and say "hey, just copy this and you'll be fine" would be more convenient :D