-
Notifications
You must be signed in to change notification settings - Fork 7
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
Batch onboarding scripts & txns #35
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3f2ac27
add batch onboarding operations
sisyphusSmiling 0935750
update txn comments
sisyphusSmiling 87b2ca1
fix failing tests
sisyphusSmiling c7f5b95
add EVMUtils contract
sisyphusSmiling ef57cd6
move EVMAddress de/serialization to EVMUtils
sisyphusSmiling 9f18dc3
add reverse mapping to config & refactor evmAddressRequiresOnboarding…
sisyphusSmiling acb4c4e
add coverage for batch scripts & txns
sisyphusSmiling 428634e
add EVMUtils to coverage normalization script
sisyphusSmiling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import "EVM" | ||
|
||
/// Contract containing EVM-related utility methods | ||
/// | ||
access(all) contract EVMUtils { | ||
/// Returns an EVMAddress as a hex string without a 0x prefix | ||
/// | ||
/// @param address: The EVMAddress to convert to a hex string | ||
/// | ||
/// @return The hex string representation of the EVMAddress without 0x prefix | ||
/// | ||
// TODO: Remove once EVMAddress.toString() is available | ||
access(all) | ||
view fun getEVMAddressAsHexString(address: EVM.EVMAddress): String { | ||
let bytes = address.bytes | ||
// Iterating & appending to an array is not allowed in a `view` method and this method must be `view` for | ||
// certain use cases in the bridge contracts - namely for emitting values in pre- & post-conditions | ||
let addressBytes: [UInt8] = [ | ||
bytes[0], bytes[1], bytes[2], bytes[3], | ||
bytes[4], bytes[5], bytes[6], bytes[7], | ||
bytes[8], bytes[9], bytes[10], bytes[11], | ||
bytes[12], bytes[13], bytes[14], bytes[15], | ||
bytes[16], bytes[17], bytes[18], bytes[19] | ||
] | ||
return String.encodeHex(addressBytes) | ||
} | ||
|
||
/// Returns an EVMAddress as a hex string without a 0x prefix, truncating the string's last 20 bytes if exceeded | ||
/// | ||
/// @param address: The hex string to convert to an EVMAddress without the 0x prefix | ||
/// | ||
/// @return The EVMAddress representation of the hex string | ||
/// | ||
access(all) | ||
fun getEVMAddressFromHexString(address: String): EVM.EVMAddress? { | ||
if address.length != 40 { | ||
return nil | ||
} | ||
var addressBytes: [UInt8] = address.decodeHex() | ||
if addressBytes.length != 20 { | ||
return nil | ||
} | ||
return EVM.EVMAddress(bytes: [ | ||
addressBytes[0], addressBytes[1], addressBytes[2], addressBytes[3], | ||
addressBytes[4], addressBytes[5], addressBytes[6], addressBytes[7], | ||
addressBytes[8], addressBytes[9], addressBytes[10], addressBytes[11], | ||
addressBytes[12], addressBytes[13], addressBytes[14], addressBytes[15], | ||
addressBytes[16], addressBytes[17], addressBytes[18], addressBytes[19] | ||
]) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
cadence/scripts/bridge/batch_evm_address_requires_onboarding.cdc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import "EVMUtils" | ||
import "FlowEVMBridge" | ||
|
||
/// Returns whether a EVM contract needs to be onboarded to the FlowEVMBridge | ||
/// | ||
/// @param evmAddresses: Array of hex-encoded address of the EVM contract as a String without 0x prefix to check for | ||
/// onboarding status | ||
/// | ||
/// @return Whether the contract requires onboarding to the FlowEVMBridge if the type is bridgeable, otherwise nil | ||
/// indexed on the hex-encoded address of the EVM contract without 0x prefix | ||
/// | ||
access(all) fun main(evmAddresses: [String]): {String: Bool?} { | ||
let results: {String: Bool?} = {} | ||
for addressHex in evmAddresses { | ||
if results[addressHex] != nil { | ||
continue | ||
} | ||
if let address = EVMUtils.getEVMAddressFromHexString(address: addressHex) { | ||
let requiresOnboarding = FlowEVMBridge.evmAddressRequiresOnboarding(address) | ||
results.insert(key: addressHex, requiresOnboarding) | ||
} | ||
} | ||
return results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import "FlowEVMBridge" | ||
|
||
/// Returns whether a type needs to be onboarded to the FlowEVMBridge | ||
/// | ||
/// @param Types: The array of types to check for onboarding status | ||
/// | ||
/// @return Whether the type requires onboarding to the FlowEVMBridge if the type is bridgeable, otherwise nil indexed | ||
/// on the type | ||
/// | ||
access(all) fun main(types: [Type]): {Type: Bool?} { | ||
let results: {Type: Bool?} = {} | ||
for type in types { | ||
if results[type] != nil { | ||
continue | ||
} | ||
results.insert(key: type, FlowEVMBridge.typeRequiresOnboarding(type)) | ||
} | ||
return results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this ever be
true
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not, but covering a case where there are non-unique values in the provided array