-
Notifications
You must be signed in to change notification settings - Fork 66
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
[Epic] New Contract Dependency Manager #929
Comments
Note that some contracts are very unfriendly to deploy and install on emulator, if they have very many arguments to the initializer. FiatToken i am looking at you. We have solved this now by simple providing a shim for it that is a lot simpler. I would very much like the system to support shims for emulators that behave as the deployed version but it a lot easier to work with. |
Thanks @nvdtf this would be quite helpful for local development, and might also help improve contract deployment pipelines.
|
For GitHub import, can we introduce the concept of exporting contracts? Firstly, add an 'export' field in flow.json. {
"contracts": {
"MyContract": "./contracts/PathToFolder/MyContract.cdc", // local file location,
},
"exports": [
"MyContract"
]
} Then when using it, do as follows: {
"contracts": {
"MyContract": "github.com/username/reponame/MyContract", // GitHub, can only import contracts from exports, no worry about the path
},
} |
I think we need to use more advanced format, something like: {
"contracts": {
"MyContract": {
"type" : "local",
"localPath": "./contracts/MyContract.cdc"
},
"TopShot":{
"type": "flow",
"localPath": "./contracts/utility/TopShot.cdc",
"remotePath":{
"mainnet": "0123123123.TopShot",
"testnet": "042424242.TopShot"
}
},
"NonFungibleToken":{
"type": "github",
"localPath": "./contracts/utility/NonFungibleToken.cdc",
"remotePath":{
"mainnet": "github.com/onflow/flow-nft/NonFungibleToken.cdc",
"testnet": "github.com/onflow/flow-nft/NonFungibleToken.cdc"
},
"aliases":{
"mainnet": "0x0123123123",
"testnet": "0x0424242424"
}
},
"CoolNFT":{
"type": "nftcatalog",
"localPath": "./contracts/CoolNFT.cdc",
"remotePath":{
"mainnet": "mainnet/CoolNFT",
"testnet": "testnet/CoolNFT"
},
"aliases":{
"mainnet": "0x0123123123",
"testnet": "0x0424242424"
}
},
}
} also deploy shim idea is also great ( or some init args in flow.json ) |
@bjartek You're right. I created another issue for this, since it seems like there is no support for contract init params: #964
@jrkhan I re-used the simple syntax from
@btspoony The problem with supporting exports is that the original developer must be mindful of future reusability. I think we need to have
@bluesign Definitely looking to expand the simple syntax into advanced with more config options. I was also thinking of branch commit hash, content hash, ... |
The initial proposal is clean, but there seems to be a significant leap from that to the extended format, which appears necessary to convey sufficient information across networks. In a more comprehensive format, we can also embrace the existing terminology and structure familiar to developers, reducing the potential for confusion and difficulty. Consider the following structure:
In this format, dependencies from the contract manager that are not developed locally are segregated into a distinct
Executing |
There needs to be a mapping between networks for a contract somewhere. Personally i think the best place for this mapping is on chain. Could this be in pragmas in contracts? (all contracts must be updated for stable-cadence regardless) |
@chasefleming We can remove |
Yeah I agree
@bjartek I also agree a mapping would be nice, but I'm not sure we can rely on every contract having it so we'd need to have this working without that first and if there was a way to group down the road that could speed things up for a developer. |
One of the things I'm trying to wrap my head around is how to trust the
An answer to this is possibly to check for equivalence of all network deployments of a contract when installed and relying on the aliases from this point forward instead of the pragma. This puts a burden on the external developer to continuously keep their contracts in sync - which may or may not be an issue? Curious what thoughts are here. |
If you cant trust the author of a contract you should not use it. You have to trust somebody. And since this just populates local files and flow.json you can always validate right? |
Another option besides pragma is a resource you can store in your accoung. We talked about this in the flix wg yesterday, but not sure how well it would scale. @JeffreyDoyle |
I was thinking we only define dependencies so:
On the first point, if a given contract's mainnet/testnet code differs, we aren't impacted since we rely only on translated import addresses. The checked-out code is only useful for the second point, local deployment. This means that we're grabbing contracts from a source of truth (mainnet/testnet) and will run it in the emulator. We can argue at this point if we have a contract that has a different code on mainnet/testnet it won't probably work in emulator anyway since it's relying on network addresses in its code. Based on this point, we can have a rule like "always get the mainnet code" and simplify. Let me know what you think. |
Some projects that you might want to implement might not be on mainnet yet. We need to cover that case to. What to do with Fiat token for instance? Personally i think USDC should bust be on emulator like FlowToken. |
We need to support contract init args before we think about |
Personally i think flow init should have a flag to populate flow.json with all the aliases that are deployed when you start emulator. That makes bootstrapping way easier. |
But we are not now only talking about a dependenxcy manager for contracts. What about flix/tx/scripts to initialize an «addon». |
As I began coding and reached the step for deploying dependencies, I realized that instead of trying to integrate dependencies into commands like Initially, you would list dependencies in this format, which is easier to add (I will incorporate the
After running
Now, you can run |
This makes sense to me, have you considered using either identifiers for imports or replace the . With /? So either testnet://A.9a0766d93b6608b7.FungibleToken Or |
Overview
Following the declarative design principles of Flow CLI we want to build a simple dependency manager that enables developers to:
flow.json
Design
Each contract is identified in
flow.json
by a unique identifier. It can be imported into another contract, transaction, or script like this:The pre-processor will replace the imports with valid Cadence syntax and addresses based on
flow.json
:The simple syntax can be evolved in the future to support specific commit hashes or versions for GitHub, or block heights for addresses.
Flow CLI will support checking for missing dependencies and checking them out into a local
imports
folder. The folder can be added to.gitignore
so other developers always pull the dependencies from the original source-of-truth.flow contracts install
Flow CLI can check all dependencies and fetch missing ones into
imports
with this command:flow contracts add
A copy of the contract is fetched into the
imports
folder. For each import, a subfolder is created and the same operation is executed recursively. Analias
entry is also created inflow.json
to prevent re-deployments. Check outcadence-import to see this in action.
The contract address is resolved via NFT Catalog. The same steps as importing from networks are applied.
A copy of the contract is fetched into the
imports
folder from the latest commit. The name of the contract will be resolved from the contents. If the contract has imports, the repository’s rootflow.json
is checked to resolve them.Issues
References
The text was updated successfully, but these errors were encountered: