From 0caafaa30edde79dd2ae3db8ea499d5976083f70 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Thu, 12 Dec 2024 15:04:50 -0500 Subject: [PATCH 1/2] Create 20241212-import-aliasing.md --- cadence/20241212-import-aliasing.md | 78 +++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cadence/20241212-import-aliasing.md diff --git a/cadence/20241212-import-aliasing.md b/cadence/20241212-import-aliasing.md new file mode 100644 index 00000000..8fc2ce51 --- /dev/null +++ b/cadence/20241212-import-aliasing.md @@ -0,0 +1,78 @@ +--- +status: draft +flip: NNN (set to the issue number) +authors: My Name (me@example.org), AN Other (you@example.org) +sponsor: AN Expert (core-contributor@example.org) +updated: YYYY-MM-DD +--- + +# FLIP NNN: Import Aliasing + +## Objective + +The goal is to allow developers to import two contracts with the same name from different addresses (e.g. `FUSD` from `0x1` and `FUSD` from `0x2`). This would reduce code size as well as improve composibility in general. + +## Motivation + +From previous discussions: +- https://github.com/onflow/Flow-Working-Groups/blob/main/cadence_language_and_execution_working_group/meetings/2024-12-10.md#survey-feedback +- https://github.com/onflow/cadence/issues/1171 + +There can be two contracts operating on separate pools (e.g. `FlowUSDT` vs `FUSDUSDT`) which each expose a contract `UniswapPair`. In current contracts or transactions, developers cannot reference both these pools in the same code. There are workarounds, but these involve duplication of code. + +## User Benefit + +This will reduce code duplication and help developers avoid conflicts. + +## Design Proposal + +The proposed syntax is an `import ... as` alias. Consider the following example + +```cdc +import FUSD as FUSD1 from 0x02 +import FUSD as FUSD2 from 0x03 + +transaction { + prepare(acct: AuthAccount) { + let typeFUSD = Type() + let typeKibble = Type() + log(typeFUSD == typeKibble) + log(typeFUSD.identifier) + log(typeKibble.identifier) + } +} +``` + +### Drawbacks + +This could lead to more obfuscation, for example purposefully confusing aliases. + +### Performance Implications + +None. + +### Dependencies + +None. + +### Engineering Impact + +This change should be simple to implement. + +### Compatibility + +Feature addition, no impact. + +### User Impact + +Feature addition, no impact. + +## Related Issues + +Consider extension for type aliasing in the future. + +## Prior Art + +- [JS](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) +- [Python](https://docs.python.org/3/reference/simple_stmts.html#import) + From 085f3aca1439998036020fcc6f0ce6eba95bcbb1 Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Tue, 17 Dec 2024 13:50:17 -0500 Subject: [PATCH 2/2] Update 20241212-import-aliasing.md --- cadence/20241212-import-aliasing.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cadence/20241212-import-aliasing.md b/cadence/20241212-import-aliasing.md index 8fc2ce51..0c50d76b 100644 --- a/cadence/20241212-import-aliasing.md +++ b/cadence/20241212-import-aliasing.md @@ -1,12 +1,12 @@ --- status: draft -flip: NNN (set to the issue number) -authors: My Name (me@example.org), AN Other (you@example.org) -sponsor: AN Expert (core-contributor@example.org) -updated: YYYY-MM-DD +flip: 314 +authors: Raymond Zhang (raymond.zhang@flowfoundation.org) +sponsor: Supun Setunga (supun.setunga@flowfoundation.org) +updated: 2024-12-17 --- -# FLIP NNN: Import Aliasing +# FLIP 314: Import Aliasing ## Objective @@ -18,11 +18,11 @@ From previous discussions: - https://github.com/onflow/Flow-Working-Groups/blob/main/cadence_language_and_execution_working_group/meetings/2024-12-10.md#survey-feedback - https://github.com/onflow/cadence/issues/1171 -There can be two contracts operating on separate pools (e.g. `FlowUSDT` vs `FUSDUSDT`) which each expose a contract `UniswapPair`. In current contracts or transactions, developers cannot reference both these pools in the same code. There are workarounds, but these involve duplication of code. +There can be two contracts operating on separate pools (e.g. `FlowUSDT` vs `FUSDUSDT`) which each expose a contract `UniswapPair`. In current contracts or transactions, developers cannot reference both these pools in the same code. There are workarounds, but these involve duplication of code. An additional use case is to shorten the name of imported types. ## User Benefit -This will reduce code duplication and help developers avoid conflicts. +This will reduce code duplication, code size and help developers avoid conflicts. ## Design Proposal @@ -71,6 +71,9 @@ Feature addition, no impact. Consider extension for type aliasing in the future. +## Implementation +https://github.com/onflow/cadence/pull/3717 + ## Prior Art - [JS](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)