-
Notifications
You must be signed in to change notification settings - Fork 151
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
feat: sol!
contracts
#77
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
935e318
feat: `sol!` contracts
DaniPopes 3e01468
chore: clippy
DaniPopes 30d2201
docs: add note about parser design, leniency
DaniPopes 9b60af4
test: bless tests after updating to syn 2.0.19
DaniPopes a58dba1
typo
DaniPopes 5d0f420
test: bless new test
DaniPopes 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use syn::Attribute; | ||
|
||
pub(crate) fn docs(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> { | ||
attrs.iter().filter(|attr| attr.path().is_ident("doc")) | ||
} | ||
|
||
pub(crate) fn derives(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> { | ||
attrs.iter().filter(|attr| attr.path().is_ident("derive")) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,42 @@ | ||
use alloy_primitives::{Address, U256}; | ||
use alloy_sol_types::{sol, SolCall}; | ||
use hex_literal::hex; | ||
|
||
sol! { | ||
/// Interface of the ERC20 standard as defined in [the EIP]. | ||
/// | ||
/// [the EIP]: https://eips.ethereum.org/EIPS/eip-20 | ||
#[derive(Debug, PartialEq)] | ||
interface IERC20 { | ||
// TODO: Events | ||
// event Transfer(address indexed from, address indexed to, uint256 value); | ||
// event Approval(address indexed owner, address indexed spender, uint256 value); | ||
|
||
function totalSupply() external view returns (uint256); | ||
function balanceOf(address account) external view returns (uint256); | ||
function transfer(address to, uint256 amount) external returns (bool); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
function approve(address spender, uint256 amount) external returns (bool); | ||
function transferFrom(address from, address to, uint256 amount) external returns (bool); | ||
} | ||
} | ||
|
||
#[test] | ||
fn contracts() { | ||
// TODO | ||
// random mainnet ERC20 transfer | ||
// https://etherscan.io/tx/0x947332ff624b5092fb92e8f02cdbb8a50314e861a4b39c29a286b3b75432165e | ||
let data = hex!( | ||
"a9059cbb" | ||
"0000000000000000000000008bc47be1e3abbaba182069c89d08a61fa6c2b292" | ||
"0000000000000000000000000000000000000000000000000000000253c51700" | ||
); | ||
let expected = IERC20::transferCall { | ||
to: Address::from(hex!("8bc47be1e3abbaba182069c89d08a61fa6c2b292")), | ||
amount: U256::from(9995360000_u64), | ||
}; | ||
|
||
assert_eq!(data[..4], IERC20::transferCall::SELECTOR); | ||
let decoded = IERC20::IERC20Calls::decode(&data, true).unwrap(); | ||
assert_eq!(decoded, IERC20::IERC20Calls::transfer(expected)); | ||
assert_eq!(decoded.encode(), data); | ||
} |
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,21 @@ | ||
use alloy_sol_types::sol; | ||
|
||
sol! { | ||
contract C { | ||
contract Nested {} | ||
} | ||
} | ||
|
||
sol! { | ||
interface C { | ||
library Nested {} | ||
} | ||
} | ||
|
||
sol! { | ||
abstract contract C { | ||
interface Nested {} | ||
} | ||
} | ||
|
||
fn main() {} |
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.
this is very cool