Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define contract from two files #1267

Closed
friedger opened this issue Nov 30, 2023 · 8 comments
Closed

Define contract from two files #1267

friedger opened this issue Nov 30, 2023 · 8 comments
Assignees
Milestone

Comments

@friedger
Copy link
Contributor

Is your feature request related to a problem? Please describe.
pox-4 contract is the concatenation of pox-4.clar and pox-mainnet.clar or pox-testnet.clar
There is currently no way to define this in Clarinet.toml

Describe the solution you'd like
It would be nice to use a list of path and the resulting contract code consists of the concatenation of the listed files.

Describe alternatives you've considered
Currently, we duplicate the code and add unit tests to ensure the the two copies stay in sync

Additional context
stacks-network/stacks-core#4094 (comment)

@hugocaillard
Copy link
Collaborator

@friedger Since it's an edge case that will only be used for pox contracts (and maybe other boot contracts), are we sure that pox-4 will be tested with clarinet?

Also, since this is only for boot contracts, I wonder if we want to hard code this logic for boot contracts or if we want to let anyone do it in the Clarinet.toml, which might a bit weird I guess 🤔

@friedger
Copy link
Contributor Author

friedger commented Dec 1, 2023

@hugocaillard I have seen different cases where changes needs to be made between testnet and mainnet. For example, all contract that reference a SIP trait or when mock/debug functions are used.

It can help improve the process of testnet mainnet switching in general.

@hugocaillard
Copy link
Collaborator

@friedger Ok I see.
When referencing a trait, I think that using clarinet requirement is the best solution. Unless if the referenced contract is different on testnet and mainnet but I don't think it can really be the case.

So the need for pox-4 is not just to concat two files, but to do it conditionally depending on the env?
Leading to something like that:

[contracts.pox-4]
[mainnet] 
paths = ['contracts/pox-mainnet.clar', 'contracts/pox-4.clar']
[testnet] 
paths = ['contracts/pox-testnet.clar', 'contracts/pox-4.clar']
[devnet] 
paths = ['contracts/pox-testnet.clar', 'contracts/pox-4.clar']
clarity_version = 2
epoch = 2.4

@friedger
Copy link
Contributor Author

friedger commented Dec 1, 2023

For traits, the referenced contracts are different like SP123.sip-10-trait vs ST987.trait-sip10

The deployed code will be different.

Your suggestion would be a great solution.

@hugocaillard
Copy link
Collaborator

@friedger The recommended way is to handle it with clarinet is to add SP123.sip-10-trait as a requirements.
When deploying on testnet, a sip-10-trait will be deployed for you. And when deploying on mainnet, it will use SP123.sip-10-trait

@hugocaillard
Copy link
Collaborator

@friedger While we work on a standard to "embed" or "concatenate" contracts – at the Clarity or Clarinet level – do you think we could get pox-4.clar to avoid the issue completely and leverage is-in-mainnet instead?

It could define the constants like so in pox-4.clar directly instead of having pox-<network>.clar files.

(define-constant PREPARE_CYCLE_LENGTH (if is-in-mainnet u100 u50))

@friedger
Copy link
Contributor Author

friedger commented Dec 1, 2023

I'll try to push for that solution

@hugocaillard
Copy link
Collaborator

Hey @friedger. I'm closing for now feel free to re-open at any point if needed

@smcclellan smcclellan added this to the Q1-2024 milestone Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants