├── docs ├── static │ ├── .nojekyll │ ├── img │ │ └── favicon.ico │ └── fonts │ │ ├── sometype-mono.bold.ttf │ │ ├── sometype-mono.medium.ttf │ │ ├── sometype-mono.regular.ttf │ │ ├── sometype-mono.bold-italic.ttf │ │ ├── sometype-mono.medium-italic.ttf │ │ └── sometype-mono.regular-italic.ttf ├── babel.config.js ├── docs │ ├── how_it_works │ │ ├── _category_.json │ │ ├── parsing.md │ │ ├── parsing_interface.md │ │ ├── parsing_library.md │ │ ├── parsing_contract.md │ │ ├── parsing_expressions.md │ │ └── assembler.md │ ├── tutorial │ │ ├── _category_.json │ │ └── preparation.md │ ├── how-to-use.md │ ├── intro.md │ ├── issues.md │ └── capabilities.md ├── src │ └── css │ │ ├── code.scss │ │ ├── themes.scss │ │ ├── layout.scss │ │ ├── fonts.scss │ │ ├── navbar.scss │ │ └── custom.scss ├── .gitignore ├── sidebars.js ├── README.md ├── package.json └── docusaurus.config.js ├── tests ├── generated │ ├── src │ │ ├── libs │ │ │ ├── mod.rs │ │ │ └── math.rs │ │ ├── lib.rs │ │ ├── impls │ │ │ ├── mod.rs │ │ │ ├── flipper.rs │ │ │ ├── comment_contract.rs │ │ │ └── struct_contract.rs │ │ ├── Cargo.toml │ │ └── traits │ │ │ ├── flipper.rs │ │ │ ├── array_contract.rs │ │ │ ├── mod.rs │ │ │ ├── ierc_20.rs │ │ │ ├── struct_contract.rs │ │ │ ├── primitives.rs │ │ │ ├── comment_contract.rs │ │ │ ├── function_contract.rs │ │ │ ├── stable_swap.rs │ │ │ ├── erc_1155.rs │ │ │ ├── access_control.rs │ │ │ └── erc_721.rs │ └── contracts │ │ ├── primitives │ │ ├── lib.rs │ │ └── Cargo.toml │ │ ├── erc_20 │ │ └── Cargo.toml │ │ ├── erc_721 │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── example │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── flipper │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── erc_1155 │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── stable_swap │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── access_control │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── array_contract │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── comment_contract │ │ ├── Cargo.toml │ │ └── lib.rs │ │ ├── struct_contract │ │ ├── Cargo.toml │ │ └── lib.rs │ │ └── function_contract │ │ ├── Cargo.toml │ │ └── lib.rs └── file_change_tests.rs ├── uniwap_v2 ├── solidity │ ├── periphery │ │ ├── interfaces │ │ │ ├── V1 │ │ │ │ ├── IUniswapV1Factory.sol │ │ │ │ └── IUniswapV1Exchange.sol │ │ │ ├── IUniswapV2Migrator.sol │ │ │ ├── IWETH.sol │ │ │ ├── IERC20.sol │ │ │ └── IUniswapV2Router02.sol │ │ ├── examples │ │ │ ├── README.md │ │ │ └── ExampleComputeLiquidityValue.sol │ │ ├── libraries │ │ │ ├── SafeMath.sol │ │ │ └── UniswapV2OracleLibrary.sol │ │ └── UniswapV2Migrator.sol │ └── core │ │ ├── interfaces │ │ ├── IUniswapV2Callee.sol │ │ ├── IUniswapV2Factory.sol │ │ ├── IERC20.sol │ │ ├── IUniswapV2ERC20.sol │ │ └── IUniswapV2Pair.sol │ │ ├── test │ │ └── ERC20.sol │ │ ├── libraries │ │ ├── SafeMath.sol │ │ ├── UQ112x112.sol │ │ └── Math.sol │ │ └── UniswapV2Factory.sol └── generated │ ├── src │ ├── lib.rs │ ├── traits │ │ ├── i_uniswap_v_1_factory.rs │ │ ├── iweth.rs │ │ ├── i_uniswap_v_2_callee.rs │ │ ├── i_uniswap_v_2_migrator.rs │ │ ├── uniswap_v_2_migrator.rs │ │ ├── example_flash_swap.rs │ │ ├── i_uniswap_v_1_exchange.rs │ │ ├── example_swap_to_price.rs │ │ ├── uniswap_v_2_factory.rs │ │ ├── weth_9.rs │ │ ├── erc_20.rs │ │ ├── example_oracle_simple.rs │ │ ├── i_uniswap_v_2_factory.rs │ │ ├── deflating_erc_20.rs │ │ ├── uniswap_v_2_erc_20.rs │ │ ├── ierc_20.rs │ │ ├── example_sliding_window_oracle.rs │ │ ├── i_uniswap_v_2_router_02.rs │ │ ├── mod.rs │ │ ├── example_compute_liquidity_value.rs │ │ ├── i_uniswap_v_2_erc_20.rs │ │ ├── router_event_emitter.rs │ │ └── uniswap_v_2_pair.rs │ ├── libs │ │ ├── mod.rs │ │ ├── uq_112_x_112.rs │ │ ├── math.rs │ │ ├── safe_math.rs │ │ └── uniswap_v_2_oracle_library.rs │ ├── Cargo.toml │ └── impls │ │ ├── mod.rs │ │ └── uniswap_v_2_migrator.rs │ └── contracts │ ├── erc_20 │ ├── Cargo.toml │ └── lib.rs │ ├── weth_9 │ └── Cargo.toml │ ├── deflating_erc_20 │ ├── Cargo.toml │ └── lib.rs │ ├── uniswap_v_2_pair │ └── Cargo.toml │ ├── example_flash_swap │ ├── Cargo.toml │ └── lib.rs │ ├── uniswap_v_2_erc_20 │ ├── Cargo.toml │ └── lib.rs │ ├── uniswap_v_2_factory │ ├── Cargo.toml │ └── lib.rs │ ├── example_oracle_simple │ ├── Cargo.toml │ └── lib.rs │ ├── example_swap_to_price │ ├── Cargo.toml │ └── lib.rs │ ├── router_event_emitter │ ├── Cargo.toml │ └── lib.rs │ ├── uniswap_v_2_migrator │ ├── Cargo.toml │ └── lib.rs │ ├── uniswap_v_2_router_01 │ ├── Cargo.toml │ └── lib.rs │ ├── uniswap_v_2_router_02 │ ├── Cargo.toml │ └── lib.rs │ ├── example_sliding_window_oracle │ ├── Cargo.toml │ └── lib.rs │ └── example_compute_liquidity_value │ ├── Cargo.toml │ └── lib.rs ├── .gitignore ├── Cargo.toml ├── examples ├── flipper.sol ├── StructContract.sol ├── IERC20.sol └── CommentContract.sol ├── .github └── workflows │ ├── ci.yml │ └── deploy.yml ├── LICENSE ├── .rustfmt.toml └── src └── cli.rs /docs/static/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/img/favicon.ico -------------------------------------------------------------------------------- /docs/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/docs/how_it_works/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "How it works", 3 | "position": 4, 4 | "collapsed": false 5 | } -------------------------------------------------------------------------------- /docs/docs/tutorial/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "ERC-20 Tutorial", 3 | "position": 3, 4 | "collapsed": false 5 | } -------------------------------------------------------------------------------- /docs/static/fonts/sometype-mono.bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/fonts/sometype-mono.bold.ttf -------------------------------------------------------------------------------- /tests/generated/src/libs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod safe_math; 2 | pub use safe_math::*; 3 | 4 | pub mod math; 5 | pub use math::*; 6 | 7 | -------------------------------------------------------------------------------- /docs/static/fonts/sometype-mono.medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/fonts/sometype-mono.medium.ttf -------------------------------------------------------------------------------- /docs/static/fonts/sometype-mono.regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/fonts/sometype-mono.regular.ttf -------------------------------------------------------------------------------- /docs/static/fonts/sometype-mono.bold-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/fonts/sometype-mono.bold-italic.ttf -------------------------------------------------------------------------------- /docs/static/fonts/sometype-mono.medium-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/fonts/sometype-mono.medium-italic.ttf -------------------------------------------------------------------------------- /docs/static/fonts/sometype-mono.regular-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Brushfam/sol2ink/HEAD/docs/static/fonts/sometype-mono.regular-italic.ttf -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/interfaces/V1/IUniswapV1Factory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV1Factory { 4 | function getExchange(address) external view returns (address); 5 | } 6 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/interfaces/IUniswapV2Callee.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Callee { 4 | function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external; 5 | } 6 | -------------------------------------------------------------------------------- /tests/generated/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | pub mod impls; 5 | pub mod libs; 6 | pub mod traits; 7 | pub use impls::*; 8 | pub use libs::*; 9 | pub use traits::*; 10 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | pub mod impls; 5 | pub mod libs; 6 | pub mod traits; 7 | pub use impls::*; 8 | pub use libs::*; 9 | pub use traits::*; 10 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/interfaces/IUniswapV2Migrator.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Migrator { 4 | function migrate(address token, uint amountTokenMin, uint amountETHMin, address to, uint deadline) external; 5 | } 6 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/test/ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.16; 2 | 3 | import '../UniswapV2ERC20.sol'; 4 | 5 | contract ERC20 is UniswapV2ERC20 { 6 | constructor(uint _totalSupply) public { 7 | _mint(msg.sender, _totalSupply); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/interfaces/IWETH.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IWETH { 4 | function deposit() external payable; 5 | function transfer(address to, uint value) external returns (bool); 6 | function withdraw(uint) external; 7 | } 8 | -------------------------------------------------------------------------------- /docs/src/css/code.scss: -------------------------------------------------------------------------------- 1 | .docusaurus-highlight-code-line { 2 | background-color: rgba(0, 0, 0, 0.1); 3 | display: block; 4 | margin: 0 calc(-1 * var(--ifm-pre-padding)); 5 | padding: 0 var(--ifm-pre-padding); 6 | } 7 | 8 | html { 9 | [class^='codeBlockContainer'] { 10 | border-radius: 0; 11 | } 12 | } -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_1_factory.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | #[openbrush::wrapper] 7 | pub type IUniswapV1FactoryRef = dyn IUniswapV1Factory; 8 | 9 | #[openbrush::trait_definition] 10 | pub trait IUniswapV1Factory { 11 | #[ink(message)] 12 | fn get_exchange(&self, _: AccountId) -> Result; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/libs/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod safe_math; 2 | pub use safe_math::*; 3 | 4 | pub mod uq_112_x_112; 5 | pub use uq_112_x_112::*; 6 | 7 | pub mod math; 8 | pub use math::*; 9 | 10 | pub mod uniswap_v_2_oracle_library; 11 | pub use uniswap_v_2_oracle_library::*; 12 | 13 | pub mod uniswap_v_2_library; 14 | pub use uniswap_v_2_library::*; 15 | 16 | pub mod safe_math; 17 | pub use safe_math::*; 18 | 19 | pub mod uniswap_v_2_liquidity_math_library; 20 | pub use uniswap_v_2_liquidity_math_library::*; 21 | 22 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/interfaces/V1/IUniswapV1Exchange.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV1Exchange { 4 | function balanceOf(address owner) external view returns (uint); 5 | function transferFrom(address from, address to, uint value) external returns (bool); 6 | function removeLiquidity(uint, uint, uint, uint) external returns (uint, uint); 7 | function tokenToEthSwapInput(uint, uint, uint) external returns (uint); 8 | function ethToTokenSwapInput(uint, uint) external payable returns (uint); 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .idea 3 | 4 | # Ignore build artifacts from the local tests sub-crate. 5 | target 6 | artifacts 7 | 8 | # Ignore backup files creates by cargo fmt. 9 | **/*.rs.bk 10 | 11 | # Remove Cargo.lock when creating an executable, leave it for libraries 12 | # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock 13 | Cargo.lock 14 | 15 | # Dependency directory 16 | node_modules 17 | 18 | package-lock.json 19 | 20 | # macOS 21 | .DS_Store 22 | 23 | yarn.lock 24 | .cargo/config.toml 25 | examples/generated/* 26 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sol2ink" 3 | version = "2.1.0" 4 | edition = "2021" 5 | license = "MIT" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | convert_case = "0.6.0" 11 | substring = "1.4.5" 12 | rust-format = { version = "0.3.4", features = ["token_stream", "post_process"] } 13 | proc-macro2 = "1.0.47" 14 | quote = "1.0.21" 15 | lazy_static = "1.4.0" 16 | clap = { version = "4.0.32", features = ["derive"] } 17 | solang-parser = "=0.2.1" 18 | rbtree = "0.1.5" 19 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/iweth.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | #[openbrush::wrapper] 7 | pub type IWETHRef = dyn IWETH; 8 | 9 | #[openbrush::trait_definition] 10 | pub trait IWETH { 11 | #[ink(message, payable)] 12 | fn deposit(&mut self) -> Result<(), Error>; 13 | 14 | #[ink(message)] 15 | fn transfer(&mut self, to: AccountId, value: u128) -> Result; 16 | 17 | #[ink(message)] 18 | fn withdraw(&mut self, _: u128) -> Result<(), Error>; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /examples/flipper.sol: -------------------------------------------------------------------------------- 1 | 2 | contract flipper { 3 | bool private value; 4 | 5 | /// Constructor that initializes the `bool` value to the given `init_value`. 6 | constructor(bool initvalue) { 7 | value = initvalue; 8 | } 9 | 10 | /// A message that can be called on instantiated contracts. 11 | /// This one flips the value of the stored `bool` from `true` 12 | /// to `false` and vice versa. 13 | function flip() public { 14 | value = !value; 15 | } 16 | 17 | /// Simply returns the current value of our `bool`. 18 | function get() public view returns (bool) { 19 | return value; 20 | } 21 | } -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_2_callee.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::traits::AccountId; 6 | 7 | #[openbrush::wrapper] 8 | pub type IUniswapV2CalleeRef = dyn IUniswapV2Callee; 9 | 10 | #[openbrush::trait_definition] 11 | pub trait IUniswapV2Callee { 12 | #[ink(message)] 13 | fn uniswap_v_2_call( 14 | &mut self, 15 | sender: AccountId, 16 | amount_0: u128, 17 | amount_1: u128, 18 | data: Vec, 19 | ) -> Result<(), Error>; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_2_migrator.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | #[openbrush::wrapper] 7 | pub type IUniswapV2MigratorRef = dyn IUniswapV2Migrator; 8 | 9 | #[openbrush::trait_definition] 10 | pub trait IUniswapV2Migrator { 11 | #[ink(message)] 12 | fn migrate( 13 | &mut self, 14 | token: AccountId, 15 | amount_token_min: u128, 16 | amount_eth_min: u128, 17 | to: AccountId, 18 | deadline: u128, 19 | ) -> Result<(), Error>; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | ## Disclaimer 4 | 5 | These contracts are for demonstrative purposes only. 6 | While these contracts have unit tests, and we generally expect them to be 7 | correct, there are no guarantees about the correctness or security of 8 | these contracts. We hold these contracts to a different standard of 9 | correctness and security than other contracts in this repository. 10 | E.g., we have explicitly excluded these contracts from the 11 | [bug bounty](https://uniswap.org/bug-bounty/#scope). 12 | 13 | You must do your own due diligence if you wish to use code 14 | from these examples in your project. 15 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/libraries/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.16; 2 | 3 | // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math) 4 | 5 | library SafeMath { 6 | function add(uint x, uint y) internal pure returns (uint z) { 7 | require((z = x + y) >= x, 'ds-math-add-overflow'); 8 | } 9 | 10 | function sub(uint x, uint y) internal pure returns (uint z) { 11 | require((z = x - y) <= x, 'ds-math-sub-underflow'); 12 | } 13 | 14 | function mul(uint x, uint y) internal pure returns (uint z) { 15 | require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/libraries/SafeMath.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.6; 2 | 3 | // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math) 4 | 5 | library SafeMath { 6 | function add(uint x, uint y) internal pure returns (uint z) { 7 | require((z = x + y) >= x, 'ds-math-add-overflow'); 8 | } 9 | 10 | function sub(uint x, uint y) internal pure returns (uint z) { 11 | require((z = x - y) <= x, 'ds-math-sub-underflow'); 12 | } 13 | 14 | function mul(uint x, uint y) internal pure returns (uint z) { 15 | require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/libraries/UQ112x112.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.16; 2 | 3 | // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) 4 | 5 | // range: [0, 2**112 - 1] 6 | // resolution: 1 / 2**112 7 | 8 | library UQ112x112 { 9 | uint224 constant Q112 = 2**112; 10 | 11 | // encode a uint112 as a UQ112x112 12 | function encode(uint112 y) internal pure returns (uint224 z) { 13 | z = uint224(y) * Q112; // never overflows 14 | } 15 | 16 | // divide a UQ112x112 by a uint112, returning a UQ112x112 17 | function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) { 18 | z = x / uint224(y); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/libraries/Math.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.16; 2 | 3 | // a library for performing various math operations 4 | 5 | library Math { 6 | function min(uint x, uint y) internal pure returns (uint z) { 7 | z = x < y ? x : y; 8 | } 9 | 10 | // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) 11 | function sqrt(uint y) internal pure returns (uint z) { 12 | if (y > 3) { 13 | z = y; 14 | uint x = y / 2 + 1; 15 | while (x < z) { 16 | z = x; 17 | x = (y / x + x) / 2; 18 | } 19 | } else if (y != 0) { 20 | z = 1; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/generated/src/impls/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod erc_1155; 2 | pub use erc_1155::*; 3 | 4 | pub mod comment_contract; 5 | pub use comment_contract::*; 6 | 7 | pub mod erc_20; 8 | pub use erc_20::*; 9 | 10 | pub mod function_contract; 11 | pub use function_contract::*; 12 | 13 | pub mod flipper; 14 | pub use flipper::*; 15 | 16 | pub mod primitives; 17 | pub use primitives::*; 18 | 19 | pub mod erc_721; 20 | pub use erc_721::*; 21 | 22 | pub mod array_contract; 23 | pub use array_contract::*; 24 | 25 | pub mod example; 26 | pub use example::*; 27 | 28 | pub mod stable_swap; 29 | pub use stable_swap::*; 30 | 31 | pub mod struct_contract; 32 | pub use struct_contract::*; 33 | 34 | pub mod access_control; 35 | pub use access_control::*; 36 | 37 | -------------------------------------------------------------------------------- /tests/generated/src/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "generated" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | 14 | [lib] 15 | name = "generated" 16 | path = "lib.rs" 17 | 18 | [features] 19 | default = ["std"] 20 | std = [ 21 | "ink/std", 22 | "scale/std", 23 | "scale-info/std", 24 | "openbrush/std", 25 | ] 26 | 27 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "generated" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | 14 | [lib] 15 | name = "generated" 16 | path = "lib.rs" 17 | 18 | [features] 19 | default = ["std"] 20 | std = [ 21 | "ink/std", 22 | "scale/std", 23 | "scale-info/std", 24 | "openbrush/std", 25 | ] 26 | 27 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/interfaces/IUniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Factory { 4 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 5 | 6 | function feeTo() external view returns (address); 7 | function feeToSetter() external view returns (address); 8 | 9 | function getPair(address tokenA, address tokenB) external view returns (address pair); 10 | function allPairs(uint) external view returns (address pair); 11 | function allPairsLength() external view returns (uint); 12 | 13 | function createPair(address tokenA, address tokenB) external returns (address pair); 14 | 15 | function setFeeTo(address) external; 16 | function setFeeToSetter(address) external; 17 | } 18 | -------------------------------------------------------------------------------- /docs/docs/how_it_works/parsing.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | title: Parsing 4 | --- 5 | 6 | This section will look at how Sol2Ink works under the hood. 7 | 8 | ### Parsing 9 | 10 | After running it, the program will first parse the original file. The parser we use is [Solang parser](https://github.com/hyperledger/solang/tree/main/solang-parser), so we don't have to reinvent the wheel. Sol2Ink will then take the output of Solang parser (parsed token tree and comments) and convert the Solang structures to Sol2Ink structures, which will be then tossed to assembler to assemble the output ink! contract with a comprehensive file structure. We leverage the power of Rust at its fullest! 11 | 12 | ### Note the following 13 | - if there is some code outside of `Contract`, `Interface`, or `Library` definition, Sol2Ink will not parse it. -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/uniswap_v_2_migrator.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | 17 | 18 | #[openbrush::wrapper] 19 | pub type UniswapV2MigratorRef = dyn UniswapV2Migrator; 20 | 21 | #[openbrush::trait_definition] 22 | pub trait UniswapV2Migrator { 23 | #[ink(message)] 24 | fn migrate( 25 | &mut self, 26 | token: AccountId, 27 | amount_token_min: u128, 28 | amount_eth_min: u128, 29 | to: AccountId, 30 | deadline: u128, 31 | ) -> Result<(), Error>; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /docs/sidebars.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creating a sidebar enables you to: 3 | - create an ordered group of docs 4 | - render a sidebar for each doc of that group 5 | - provide next/previous navigation 6 | 7 | The sidebars can be generated from the filesystem, or explicitly defined here. 8 | 9 | Create as many sidebars as you want. 10 | */ 11 | 12 | // @ts-check 13 | 14 | /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ 15 | const sidebars = { 16 | // By default, Docusaurus generates a sidebar from the docs folder structure 17 | tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], 18 | 19 | // But you can create a sidebar manually 20 | /* 21 | tutorialSidebar: [ 22 | { 23 | type: 'category', 24 | label: 'Tutorial', 25 | items: ['hello'], 26 | }, 27 | ], 28 | */ 29 | }; 30 | 31 | module.exports = sidebars; 32 | -------------------------------------------------------------------------------- /tests/generated/contracts/primitives/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod primitives { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct primitivesContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl primitives for primitivesContract {} 25 | 26 | impl primitivesContract { 27 | #[ink(constructor)] 28 | pub fn new() -> Self { 29 | let mut instance = Self::default(); 30 | instance 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/generated/contracts/erc_20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "erc_20" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "erc_20" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/src/traits/flipper.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | use scale::{ 5 | Decode, 6 | Encode, 7 | }; 8 | 9 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 10 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 11 | pub enum Error { 12 | Custom(String), 13 | } 14 | 15 | 16 | 17 | #[openbrush::wrapper] 18 | pub type flipperRef = dyn flipper; 19 | 20 | #[openbrush::trait_definition] 21 | pub trait flipper { 22 | ///A message that can be called on instantiated contracts. 23 | ///This one flips the value of the stored `bool` from `true` 24 | ///to `false` and vice versa. 25 | #[ink(message)] 26 | fn flip(&mut self) -> Result<(), Error>; 27 | 28 | ///Simply returns the current value of our `bool`. 29 | #[ink(message)] 30 | fn get(&self) -> Result; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /tests/generated/contracts/erc_721/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "erc_721" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "erc_721" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/example/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "example" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/flipper/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flipper" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "flipper" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/erc_20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "erc_20" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "erc_20" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/weth_9/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "weth_9" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "weth_9" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/erc_1155/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "erc_1155" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "erc_1155" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/primitives/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "primitives" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "primitives" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/stable_swap/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "stable_swap" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "stable_swap" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/access_control/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "access_control" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "access_control" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/array_contract/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "array_contract" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "array_contract" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/comment_contract/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "comment_contract" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "comment_contract" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/struct_contract/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "struct_contract" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "struct_contract" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /tests/generated/contracts/function_contract/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "function_contract" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "function_contract" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/deflating_erc_20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "deflating_erc_20" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "deflating_erc_20" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_pair/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uniswap_v_2_pair" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "uniswap_v_2_pair" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_flash_swap/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example_flash_swap" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "example_flash_swap" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_erc_20/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uniswap_v_2_erc_20" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "uniswap_v_2_erc_20" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IERC20 { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external view returns (string memory); 8 | function symbol() external view returns (string memory); 9 | function decimals() external view returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | } 18 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_factory/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uniswap_v_2_factory" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "uniswap_v_2_factory" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IERC20 { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external view returns (string memory); 8 | function symbol() external view returns (string memory); 9 | function decimals() external view returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | } 18 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_oracle_simple/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example_oracle_simple" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "example_oracle_simple" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_swap_to_price/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example_swap_to_price" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "example_swap_to_price" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/router_event_emitter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "router_event_emitter" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "router_event_emitter" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_migrator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uniswap_v_2_migrator" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "uniswap_v_2_migrator" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_router_01/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uniswap_v_2_router_01" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "uniswap_v_2_router_01" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_router_02/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "uniswap_v_2_router_02" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "uniswap_v_2_router_02" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ### Build 20 | 21 | ``` 22 | $ yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ### Deployment 28 | 29 | Using SSH: 30 | 31 | ``` 32 | $ USE_SSH=true yarn deploy 33 | ``` 34 | 35 | Not using SSH: 36 | 37 | ``` 38 | $ GIT_USER= yarn deploy 39 | ``` 40 | 41 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 42 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_sliding_window_oracle/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example_sliding_window_oracle" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "example_sliding_window_oracle" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/example_flash_swap.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::traits::AccountId; 6 | use scale::{ 7 | Decode, 8 | Encode, 9 | }; 10 | 11 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 12 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 13 | pub enum Error { 14 | Custom(String), 15 | } 16 | 17 | 18 | 19 | #[openbrush::wrapper] 20 | pub type ExampleFlashSwapRef = dyn ExampleFlashSwap; 21 | 22 | #[openbrush::trait_definition] 23 | pub trait ExampleFlashSwap { 24 | /// gets tokens/WETH via a V2 flash swap, swaps for the ETH/tokens on V1, repays V2, and keeps the rest! 25 | #[ink(message)] 26 | fn uniswap_v_2_call( 27 | &mut self, 28 | sender: AccountId, 29 | amount_0: u128, 30 | amount_1: u128, 31 | data: Vec, 32 | ) -> Result<(), Error>; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_compute_liquidity_value/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "example_compute_liquidity_value" 3 | version = "2.1.0" 4 | edition = "2021" 5 | authors = ["Sol2Ink"] 6 | 7 | [dependencies] 8 | ink = { version = "~4.1.0", default-features = false } 9 | scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true } 11 | openbrush = { git = "https://github.com/Brushfam/openbrush-contracts", tag = "3.1.0", default-features = false, features = [] } 12 | 13 | generated = { path = "../../src", default-features = false } 14 | 15 | [lib] 16 | name = "example_compute_liquidity_value" 17 | path = "lib.rs" 18 | crate-type = ["cdylib"] 19 | 20 | [features] 21 | default = ["std"] 22 | std = [ 23 | "ink/std", 24 | "scale/std", 25 | "scale-info/std", 26 | "openbrush/std", 27 | "generated/std" 28 | ] 29 | 30 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/libs/uq_112_x_112.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | 5 | // Generated with Sol2Ink v2.1.0 6 | // https://github.com/Brushfam/sol2ink 7 | 8 | /// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) 9 | /// range: [0, 2**112 - 1] 10 | /// resolution: 1 / 2**112 11 | 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | pub const Q_112: u128 = 2.pow(112); 17 | 18 | /// encode a uint112 as a UQ112x112 19 | pub fn encode(&self, y: u128) -> Result { 20 | let mut z = Default::default(); 21 | z = ::from(y) * self.data().q_112; 22 | Ok(z) 23 | } 24 | 25 | /// never overflows 26 | /// divide a UQ112x112 by a uint112, returning a UQ112x112 27 | pub fn uqdiv(&self, x: u128, y: u128) -> Result { 28 | let mut z = Default::default(); 29 | z = x / ::from(y); 30 | Ok(z) 31 | } 32 | 33 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/libs/math.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | 5 | // Generated with Sol2Ink v2.1.0 6 | // https://github.com/Brushfam/sol2ink 7 | 8 | /// a library for performing various math operations 9 | 10 | pub enum Error { 11 | Custom(String), 12 | } 13 | 14 | 15 | pub fn min(&self, x: u128, y: u128) -> Result { 16 | let mut z = Default::default(); 17 | z = if x < y { x } else { y }; 18 | Ok(z) 19 | } 20 | 21 | /// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) 22 | pub fn sqrt(&self, y: u128) -> Result { 23 | let mut z = Default::default(); 24 | if y > 3 { 25 | z = y; 26 | let mut x: u128 = y / 2 + 1; 27 | while x < z { 28 | z = x; 29 | x = (y / x + x) / 2; 30 | } 31 | } else if y != 0 { 32 | z = 1; 33 | } 34 | Ok(z) 35 | } 36 | 37 | -------------------------------------------------------------------------------- /tests/generated/contracts/flipper/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod flipper { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct flipperContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl flipper for flipperContract {} 25 | 26 | impl flipperContract { 27 | ///Constructor that initializes the `bool` value to the given `init_value`. 28 | #[ink(constructor)] 29 | pub fn new(initvalue: bool) -> Self { 30 | let mut instance = Self::default(); 31 | instance.data.value = initvalue; 32 | instance 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/generated/contracts/function_contract/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod function_contract { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct FunctionContractContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl FunctionContract for FunctionContractContract {} 25 | 26 | impl FunctionContractContract { 27 | #[ink(constructor)] 28 | pub fn new() -> Self { 29 | let mut instance = Self::default(); 30 | instance.data.owner = instance.env().caller(); 31 | self.x = 10; 32 | instance 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/generated/contracts/array_contract/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// SPDX-License-Identifier: MIT 8 | /// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/ERC1155.sol) 9 | #[openbrush::contract] 10 | pub mod array_contract { 11 | use generated::*; 12 | use ink::lang::codegen::{ 13 | EmitEvent, 14 | Env, 15 | }; 16 | use openbrush::traits::Storage; 17 | 18 | 19 | #[ink(storage)] 20 | #[derive(Default, Storage)] 21 | pub struct ArrayContractContract { 22 | #[storage_field] 23 | data: impls::Data, 24 | } 25 | 26 | impl ArrayContract for ArrayContractContract {} 27 | 28 | impl ArrayContractContract { 29 | #[ink(constructor)] 30 | pub fn new() -> Self { 31 | let mut instance = Self::default(); 32 | instance 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/generated/src/traits/array_contract.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::storage::Mapping; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | 17 | #[derive(Default, Encode, Decode)] 18 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 19 | pub struct TestStruct { 20 | struct_mapping: Mapping, 21 | struct_f_array: [u8; 32], 22 | struct_d_array: Vec, 23 | } 24 | 25 | #[derive(Default, Encode, Decode)] 26 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 27 | pub struct NestedTestStruct { 28 | test_struct: TestStruct, 29 | uint_field: u8, 30 | } 31 | 32 | 33 | #[openbrush::wrapper] 34 | pub type ArrayContractRef = dyn ArrayContract; 35 | 36 | #[openbrush::trait_definition] 37 | pub trait ArrayContract {} 38 | -------------------------------------------------------------------------------- /tests/generated/src/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod erc_1155; 2 | pub use erc_1155::*; 3 | 4 | pub mod comment_contract; 5 | pub use comment_contract::*; 6 | 7 | pub mod ierc_20; 8 | pub use ierc_20::*; 9 | 10 | pub mod erc_20; 11 | pub use erc_20::*; 12 | 13 | pub mod function_contract; 14 | pub use function_contract::*; 15 | 16 | pub mod ierc_1155; 17 | pub use ierc_1155::*; 18 | 19 | pub mod flipper; 20 | pub use flipper::*; 21 | 22 | pub mod primitives; 23 | pub use primitives::*; 24 | 25 | pub mod erc_721; 26 | pub use erc_721::*; 27 | 28 | pub mod ierc_721; 29 | pub use ierc_721::*; 30 | 31 | pub mod i_access_control; 32 | pub use i_access_control::*; 33 | 34 | pub mod array_contract; 35 | pub use array_contract::*; 36 | 37 | pub mod example; 38 | pub use example::*; 39 | 40 | pub mod stable_swap; 41 | pub use stable_swap::*; 42 | 43 | pub mod ierc_20; 44 | pub use ierc_20::*; 45 | 46 | pub mod struct_contract; 47 | pub use struct_contract::*; 48 | 49 | pub mod access_control; 50 | pub use access_control::*; 51 | 52 | -------------------------------------------------------------------------------- /docs/docs/how_it_works/parsing_interface.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | title: Parsing an interface 4 | --- 5 | 6 | When parsing an interface, Sol2Ink will create an ink! trait definition from the parsed interface. This trait definition may include the following: 7 | 8 | - event definitions 9 | - struct definitions 10 | - enum definitions 11 | - function definitions 12 | - documentation comments 13 | 14 | After Sol2Ink parses an interface, it will move on to the assemble part, where it assembles the ink! trait from the parsed structures. The output file will contain the trait definition and will be saved in `generated/src/traits/trait_name.rs`, where `trait_name` is the name of the parsed interface. This trait definition will be also exposed in `generated/src/traits/mod.rs` for the project to use. Note that all functions return `Result` by default, but we will discuss this later when describing contract parsing. 15 | 16 | We can then later create another file where we implement this trait and then implement it for our contract. -------------------------------------------------------------------------------- /tests/generated/src/libs/math.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | 5 | // Generated with Sol2Ink v2.1.0 6 | // https://github.com/Brushfam/sol2ink 7 | 8 | /// SPDX-License-Identifier: MIT 9 | /// Simplified version of Curve's stable swap AMM 10 | ///Invariant - price of trade and amount of liquidity are determined by this equation 11 | /// 12 | ///An^n sum(x_i) + D = ADn^n + D^(n + 1) / (n^n prod(x_i)) 13 | /// 14 | ///Topics 15 | ///0. Newton's method x_(n + 1) = x_n - f(x_n) / f'(x_n) 16 | ///1. Invariant 17 | ///2. Swap 18 | /// - Calculate Y 19 | /// - Calculate D 20 | ///3. Get virtual price 21 | ///4. Add liquidity 22 | /// - Imbalance fee 23 | ///5. Remove liquidity 24 | ///6. Remove liquidity one token 25 | /// - Calculate withdraw one token 26 | /// - getYD 27 | 28 | pub enum Error { 29 | Custom(String), 30 | } 31 | 32 | 33 | pub fn abs(&self, x: u128, y: u128) -> Result { 34 | return Ok(if x >= y { x - y } else { y - x }) 35 | } 36 | 37 | -------------------------------------------------------------------------------- /docs/docs/how-to-use.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | title: How to use 4 | --- 5 | 6 | You can use Sol2Ink either with cargo run or by running the binary of Sol2Ink. 7 | 8 | - ### Using `cargo run` 9 | 10 | 1. Sol2Ink runs on the nightly toolchain of Rust, so you will need that installed 11 | 2. Clone the Sol2Ink repository with `git clone https://github.com/Brushfam/sol2ink` 12 | 3. Copy the path to your Solidity files. It can be either a single .sol file or a folder with multiple .sol files. Navigate to the cloned repo and run `cargo +nightly run path_to_files` substituting `path_to_files` with the actual name of the file or folder. 13 | 4. The output will be saved in the folder of the original file under `generated` 14 | 15 | - ### Using Sol2Ink binary 16 | 17 | 1. Download Sol2Ink from the release page 18 | 2. Navigate to the folder where you saved the binary 19 | 3. Run `./sol2ink path_to_files` substituting `path_to_files` with the actual name of the file or folder. 20 | 4. The output will be saved in the folder of the original file under `generated` -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_compute_liquidity_value/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod example_compute_liquidity_value { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct ExampleComputeLiquidityValueContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl ExampleComputeLiquidityValue for ExampleComputeLiquidityValueContract {} 25 | 26 | impl ExampleComputeLiquidityValueContract { 27 | #[ink(constructor)] 28 | pub fn new(factory: AccountId) -> Self { 29 | let mut instance = Self::default(); 30 | instance.data.factory = factory; 31 | instance 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /docs/docs/how_it_works/parsing_library.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | title: Parsing a library 4 | --- 5 | 6 | When parsing a libraray, Sol2Ink will create a plain Rust file, making all functions public so they can be used in the parsed contract. This file definition may include the following: 7 | 8 | - struct definitions 9 | - enum definitions 10 | - function definitions 11 | - documentation comments 12 | - state variables (only constants) 13 | 14 | After Sol2Ink parses a library, it will move on to the assemble part, where it assembles a Rust file for our library (of course using ink! and OpenBrush where possible) from the parsed structures. The output file will contain the parsed library and include all parsed constant members, and will be saved in `generated/src/libs/lib_name.rs`, where `lib_name` is the name of the parsed library. This library will be also exposed in `generated/src/libs/mod.rs` for the project to use. Note that all functions return `Result` by default. 15 | 16 | To use our library, we can simply import it in our contract, and use its functions. -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_1_exchange.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | #[openbrush::wrapper] 7 | pub type IUniswapV1ExchangeRef = dyn IUniswapV1Exchange; 8 | 9 | #[openbrush::trait_definition] 10 | pub trait IUniswapV1Exchange { 11 | #[ink(message)] 12 | fn balance_of(&self, owner: AccountId) -> Result; 13 | 14 | #[ink(message)] 15 | fn transfer_from(&mut self, from: AccountId, to: AccountId, value: u128) 16 | -> Result; 17 | 18 | #[ink(message)] 19 | fn remove_liquidity( 20 | &mut self, 21 | _: u128, 22 | _: u128, 23 | _: u128, 24 | _: u128, 25 | ) -> Result<(u128, u128), Error>; 26 | 27 | #[ink(message)] 28 | fn token_to_eth_swap_input(&mut self, _: u128, _: u128, _: u128) -> Result; 29 | 30 | #[ink(message, payable)] 31 | fn eth_to_token_swap_input(&mut self, _: u128, _: u128) -> Result; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_swap_to_price/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod example_swap_to_price { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct ExampleSwapToPriceContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl ExampleSwapToPrice for ExampleSwapToPriceContract {} 25 | 26 | impl ExampleSwapToPriceContract { 27 | #[ink(constructor)] 28 | pub fn new(factory: AccountId, router: IUniswapV2Router01) -> Self { 29 | let mut instance = Self::default(); 30 | instance.data.factory = factory; 31 | instance.data.router = router; 32 | instance 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/generated/src/impls/flipper.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use crate::{ 5 | impls, 6 | traits::*, 7 | }; 8 | use openbrush::traits::Storage; 9 | 10 | pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); 11 | 12 | #[derive(Default, Debug)] 13 | #[openbrush::upgradeable_storage(STORAGE_KEY)] 14 | pub struct Data { 15 | pub value: bool, 16 | pub _reserved: Option<()>, 17 | } 18 | 19 | 20 | impl> flipper for T { 21 | ///A message that can be called on instantiated contracts. 22 | ///This one flips the value of the stored `bool` from `true` 23 | ///to `false` and vice versa. 24 | fn flip(&mut self) -> Result<(), Error> { 25 | self.data().value = !self.data().value; 26 | Ok(()) 27 | } 28 | 29 | ///Simply returns the current value of our `bool`. 30 | fn get(&self) -> Result { 31 | return Ok(self.data().value) 32 | } 33 | 34 | } 35 | 36 | pub trait Internal {} 37 | 38 | impl> Internal for T {} 39 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI/CD 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | - develop 8 | 9 | jobs: 10 | rustfmt: 11 | concurrency: 12 | group: rustfmt-${{ github.ref }} 13 | cancel-in-progress: true 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Install latest nightly 18 | uses: actions-rs/toolchain@v1 19 | with: 20 | toolchain: nightly 21 | override: true 22 | components: rustfmt 23 | 24 | - name: Cargo fmt check 25 | run: cargo +nightly fmt --all -- --check 26 | unit-test: 27 | concurrency: 28 | group: unit-test-${{ github.ref }} 29 | cancel-in-progress: true 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: actions/checkout@v3 33 | - name: Install latest nightly 34 | uses: actions-rs/toolchain@v1 35 | with: 36 | toolchain: nightly 37 | override: true 38 | components: rustfmt, clippy 39 | 40 | - name: Run all unit tests 41 | run: cargo +nightly test -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_router_01/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod uniswap_v_2_router_01 { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct UniswapV2Router01Contract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl UniswapV2Router01 for UniswapV2Router01Contract {} 25 | 26 | impl IUniswapV2Router01 for UniswapV2Router01Contract {} 27 | 28 | impl UniswapV2Router01Contract { 29 | #[ink(constructor)] 30 | pub fn new(factory: AccountId, weth: AccountId) -> Self { 31 | let mut instance = Self::default(); 32 | instance.data.factory = factory; 33 | instance.data.weth = weth; 34 | instance 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_router_02/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod uniswap_v_2_router_02 { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct UniswapV2Router02Contract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl UniswapV2Router02 for UniswapV2Router02Contract {} 25 | 26 | impl IUniswapV2Router02 for UniswapV2Router02Contract {} 27 | 28 | impl UniswapV2Router02Contract { 29 | #[ink(constructor)] 30 | pub fn new(factory: AccountId, weth: AccountId) -> Self { 31 | let mut instance = Self::default(); 32 | instance.data.factory = factory; 33 | instance.data.weth = weth; 34 | instance 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /docs/docs/how_it_works/parsing_contract.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 4 3 | title: Parsing a contract 4 | --- 5 | 6 | When parsing a contract, Sol2Ink will create an ink! trait definition, implementation of this trait, and a contract file from the parsed contract. This contract may include the following: 7 | 8 | - event definitions 9 | - struct definitions 10 | - enum definitions 11 | - function definitions 12 | - documentation comments 13 | - state variables 14 | - constructor 15 | - modifiers 16 | 17 | ### Parsing a function or a modifier 18 | 19 | While parsing a contract, Sol2Ink will also parse all of the mentioned above. We will describe how parsing functions work later. For now we just need to know, that all of these functions will be added to an ink! trait definition of the contract saved in `src/traits/contract_name.rs` and exposed in `src/traits/mod.rs`, then will this trait be implemented in `src/impls/contract_name.rs` and the implementation file will be exposed in `src/impls/mod.rs` and finally it will generate a contract in `contracts/contract_name/lib.rs` and the dependencies file in `contracts/contract_name/Cargo.toml`. 20 | -------------------------------------------------------------------------------- /docs/docs/tutorial/preparation.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | title: Preparation 4 | --- 5 | 6 | In this tutorial, we will transpile the [ERC-20 contract](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol) from OpenZeppelin. 7 | 8 | #### Preparation 9 | 10 | Before we run the program, we will make some adjustments to the ERC-20 file. We will add the events from the [IERC-20 interface](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol) to our contract. We do this because later in the contract, we want to emit these events. Another thing we will change is to rewrite all functions `_msgSender()` to `msg.sender`. We do this because we want to demonstrate how to call `msg.sender` in ink!. 11 | 12 | #### Running Sol2Ink 13 | 14 | Running Sol2Ink is easy. First we need to navigate to the folder where we saved `sol2ink` and we will call `./sol2ink path`, where `path` is the path to our `ERC20` file. The output file will be stored in the newly created folder `generated`, containing all of the files of the contract. Now we will try to build it! 15 | -------------------------------------------------------------------------------- /docs/src/css/themes.scss: -------------------------------------------------------------------------------- 1 | html[data-theme='light'] { 2 | .pagination-nav__link { 3 | background: white; 4 | } 5 | 6 | .main-wrapper { 7 | background: #fafafa; 8 | } 9 | [class^='codeBlockContainer'] { 10 | box-shadow: none; 11 | border: 1px solid #ebeef1; 12 | } 13 | 14 | .footer { 15 | border: 2px solid var(--ifm-toc-border-color); 16 | } 17 | 18 | .navbar__items { 19 | &:first-child { 20 | background: #fafafa; 21 | 22 | &:before { 23 | content: ''; 24 | width: 0; 25 | position: absolute; 26 | right: -76px; 27 | height: 0; 28 | border-bottom: 56px solid #fafafa; 29 | border-right: 76px solid transparent; 30 | } 31 | } 32 | } 33 | } 34 | 35 | html[data-theme='dark'] { 36 | .docusaurus-highlight-code-line { 37 | background-color: rgba(0, 0, 0, 0.3); 38 | } 39 | 40 | [class^='codeBlockContainer'] { 41 | box-shadow: none; 42 | } 43 | 44 | .footer { 45 | border: 2px solid var(--ifm-toc-border-color); 46 | } 47 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Supercolony 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/libs/safe_math.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | 5 | // Generated with Sol2Ink v2.1.0 6 | // https://github.com/Brushfam/sol2ink 7 | 8 | /// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math) 9 | 10 | pub enum Error { 11 | Custom(String), 12 | } 13 | 14 | 15 | pub fn add(&self, x: u128, y: u128) -> Result { 16 | let mut z = Default::default(); 17 | if !((z = x + y) >= x) { 18 | return Err(Error::Custom(String::from("ds-math-add-overflow"))) 19 | }; 20 | Ok(z) 21 | } 22 | 23 | pub fn sub(&self, x: u128, y: u128) -> Result { 24 | let mut z = Default::default(); 25 | if !((z = x - y) <= x) { 26 | return Err(Error::Custom(String::from("ds-math-sub-underflow"))) 27 | }; 28 | Ok(z) 29 | } 30 | 31 | pub fn mul(&self, x: u128, y: u128) -> Result { 32 | let mut z = Default::default(); 33 | if !(y == 0 || (z = x * y) / y == x) { 34 | return Err(Error::Custom(String::from("ds-math-mul-overflow"))) 35 | }; 36 | Ok(z) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_migrator/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod uniswap_v_2_migrator { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct UniswapV2MigratorContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl UniswapV2Migrator for UniswapV2MigratorContract {} 25 | 26 | impl IUniswapV2Migrator for UniswapV2MigratorContract {} 27 | 28 | impl UniswapV2MigratorContract { 29 | #[ink(constructor)] 30 | pub fn new(factory_v_1: AccountId, router: AccountId) -> Self { 31 | let mut instance = Self::default(); 32 | instance.data.factory_v_1 = i_uniswap_v_1_factory(factory_v_1)?; 33 | instance.data.router = i_uniswap_v_2_router_01(router)?; 34 | instance 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/impls/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod uniswap_v_2_factory; 2 | pub use uniswap_v_2_factory::*; 3 | 4 | pub mod uniswap_v_2_erc_20; 5 | pub use uniswap_v_2_erc_20::*; 6 | 7 | pub mod erc_20; 8 | pub use erc_20::*; 9 | 10 | pub mod uniswap_v_2_pair; 11 | pub use uniswap_v_2_pair::*; 12 | 13 | pub mod uniswap_v_2_migrator; 14 | pub use uniswap_v_2_migrator::*; 15 | 16 | pub mod weth_9; 17 | pub use weth_9::*; 18 | 19 | pub mod erc_20; 20 | pub use erc_20::*; 21 | 22 | pub mod deflating_erc_20; 23 | pub use deflating_erc_20::*; 24 | 25 | pub mod router_event_emitter; 26 | pub use router_event_emitter::*; 27 | 28 | pub mod uniswap_v_2_router_01; 29 | pub use uniswap_v_2_router_01::*; 30 | 31 | pub mod example_compute_liquidity_value; 32 | pub use example_compute_liquidity_value::*; 33 | 34 | pub mod example_flash_swap; 35 | pub use example_flash_swap::*; 36 | 37 | pub mod example_oracle_simple; 38 | pub use example_oracle_simple::*; 39 | 40 | pub mod example_swap_to_price; 41 | pub use example_swap_to_price::*; 42 | 43 | pub mod example_sliding_window_oracle; 44 | pub use example_sliding_window_oracle::*; 45 | 46 | pub mod uniswap_v_2_router_02; 47 | pub use uniswap_v_2_router_02::*; 48 | 49 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/example_swap_to_price.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | 17 | 18 | #[openbrush::wrapper] 19 | pub type ExampleSwapToPriceRef = dyn ExampleSwapToPrice; 20 | 21 | #[openbrush::trait_definition] 22 | pub trait ExampleSwapToPrice { 23 | /// swaps an amount of either token such that the trade is profit-maximizing, given an external true price 24 | /// true price is expressed in the ratio of token A to token B 25 | /// caller must approve this contract to spend whichever token is intended to be swapped 26 | #[ink(message)] 27 | fn swap_to_price( 28 | &mut self, 29 | token_a: AccountId, 30 | token_b: AccountId, 31 | true_price_token_a: u128, 32 | true_price_token_b: u128, 33 | max_spend_token_a: u128, 34 | max_spend_token_b: u128, 35 | to: AccountId, 36 | deadline: u128, 37 | ) -> Result<(), Error>; 38 | 39 | } 40 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_flash_swap/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod example_flash_swap { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(storage)] 18 | #[derive(Default, Storage)] 19 | pub struct ExampleFlashSwapContract { 20 | #[storage_field] 21 | data: impls::Data, 22 | } 23 | 24 | impl ExampleFlashSwap for ExampleFlashSwapContract {} 25 | 26 | impl IUniswapV2Callee for ExampleFlashSwapContract {} 27 | 28 | impl ExampleFlashSwapContract { 29 | #[ink(constructor)] 30 | pub fn new(factory: AccountId, factory_v_1: AccountId, router: AccountId) -> Self { 31 | let mut instance = Self::default(); 32 | instance.data.factory_v_1 = i_uniswap_v_1_factory(factory_v_1)?; 33 | instance.data.factory = factory; 34 | instance.data.weth = iweth(i_uniswap_v_2_router_01(router)?.weth()?)?; 35 | instance 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/uniswap_v_2_factory.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::{ 6 | storage::Mapping, 7 | traits::{ 8 | AccountId, 9 | AccountIdExt, 10 | ZERO_ADDRESS, 11 | }, 12 | }; 13 | use scale::{ 14 | Decode, 15 | Encode, 16 | }; 17 | 18 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 19 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 20 | pub enum Error { 21 | Custom(String), 22 | } 23 | 24 | 25 | 26 | #[openbrush::wrapper] 27 | pub type UniswapV2FactoryRef = dyn UniswapV2Factory; 28 | 29 | #[openbrush::trait_definition] 30 | pub trait UniswapV2Factory { 31 | #[ink(message)] 32 | fn all_pairs_length(&self) -> Result; 33 | 34 | #[ink(message)] 35 | fn create_pair(&mut self, token_a: AccountId, token_b: AccountId) -> Result; 36 | 37 | /// single check is sufficient 38 | /// populate mapping in the reverse direction 39 | #[ink(message)] 40 | fn set_fee_to(&mut self, fee_to: AccountId) -> Result<(), Error>; 41 | 42 | #[ink(message)] 43 | fn set_fee_to_setter(&mut self, fee_to_setter: AccountId) -> Result<(), Error>; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/interfaces/IUniswapV2ERC20.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2ERC20 { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external pure returns (string memory); 8 | function symbol() external pure returns (string memory); 9 | function decimals() external pure returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | 18 | function DOMAIN_SEPARATOR() external view returns (bytes32); 19 | function PERMIT_TYPEHASH() external pure returns (bytes32); 20 | function nonces(address owner) external view returns (uint); 21 | 22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 23 | } 24 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/router_event_emitter/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod router_event_emitter { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(event)] 18 | pub struct Amounts { 19 | amounts: Vec, 20 | } 21 | 22 | #[ink(storage)] 23 | #[derive(Default, Storage)] 24 | pub struct RouterEventEmitterContract { 25 | #[storage_field] 26 | data: impls::Data, 27 | } 28 | 29 | impl RouterEventEmitter for RouterEventEmitterContract {} 30 | impl generated::impls::router_event_emitter::Internal for RouterEventEmitterContract { 31 | 32 | fn _emit_amounts(&self, amounts: Vec) { 33 | self.env().emit_event(Amounts { amounts }); 34 | } 35 | 36 | } 37 | 38 | impl RouterEventEmitterContract { 39 | #[ink(constructor)] 40 | pub fn new() -> Self { 41 | let mut instance = Self::default(); 42 | instance 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/docs/how_it_works/parsing_expressions.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 6 3 | title: Parsing expressions 4 | --- 5 | 6 | Another step of parsing a statement is parsing each expression. Here the program will decide how to parse each expression inside a statement. 7 | 8 | ### Basics 9 | 10 | - Literals are parsed without any modifications 11 | - Specific expressions like `address(0)`, `msg.sender` or `msg.value` are parsed in their ink! form 12 | - Solidity types are converted to Rust/ink! types 13 | 14 | ### Hex values 15 | 16 | Expressions like `hex"0000_0000_0000_0000"` are converted to a call of `&hex::decode` function. 17 | 18 | ### type(T).f / type(T) 19 | 20 | These expressions are parsed as expected, except `type` is changed to `type_of` since `type` is a keyword in rust. This can produce uncompilable code, since `type(uint256).max` will be parsed as `type_of(u128).max` instead of `u128::MAX`, and the developer needs to change this call. We plan on better support for such functions in the future version of Sol2Ink. 21 | 22 | All other expressions are parsed as expected: 23 | 24 | - struct initializations 25 | - function calls 26 | - arithmetic operations 27 | - logical operations 28 | - parentheses 29 | 30 | After Sol2Ink parses everything, it will assemble the final ink! contract. -------------------------------------------------------------------------------- /tests/generated/contracts/example/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// example.sol 8 | #[openbrush::contract] 9 | pub mod example { 10 | use generated::*; 11 | use ink::lang::codegen::{ 12 | EmitEvent, 13 | Env, 14 | }; 15 | use openbrush::traits::Storage; 16 | 17 | /// Constants 18 | pub const BAD_STATE: State = state.zombie; 19 | pub const FIRST_PID: i32 = 1; 20 | 21 | #[ink(storage)] 22 | #[derive(Default, Storage)] 23 | pub struct exampleContract { 24 | #[storage_field] 25 | data: impls::Data, 26 | } 27 | 28 | impl example for exampleContract {} 29 | 30 | impl exampleContract { 31 | /// Our constructors 32 | #[ink(constructor)] 33 | pub fn new(pid: i32) -> Self { 34 | let mut instance = Self::default(); 35 | instance.data.pid = pid; 36 | self.reaped = 3; 37 | self.card_1 = card(value.two, suit.club)?; 38 | self.card_2 = card { 39 | s: suit.club, 40 | v: value.two, 41 | }; 42 | instance 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/src/css/layout.scss: -------------------------------------------------------------------------------- 1 | html { 2 | font-weight: 500; 3 | } 4 | 5 | body { 6 | padding: 0; 7 | } 8 | 9 | .main-wrapper { 10 | border-left: 2px solid var(--ifm-toc-border-color); 11 | border-right: 2px solid var(--ifm-toc-border-color); 12 | } 13 | 14 | main > .container { 15 | padding-top: 0 !important; 16 | } 17 | 18 | .markdown { 19 | h1:first-child { 20 | --ifm-h1-font-size: 2.6rem; 21 | } 22 | } 23 | 24 | .markdown > h2 { 25 | --ifm-h2-font-size: 1.8rem; 26 | } 27 | 28 | @media (max-width: 767px) { 29 | .markdown { 30 | h1, 31 | h2, 32 | h3, 33 | h4, 34 | h5, 35 | h6 { 36 | --ifm-h1-font-size: 2rem !important; 37 | --ifm-h2-font-size: 1.5rem; 38 | --ifm-h3-font-size: 1.25rem; 39 | --ifm-h4-font-size: 1rem; 40 | --ifm-h5-font-size: 0.875rem; 41 | --ifm-h6-font-size: 0.85rem; 42 | } 43 | } 44 | } 45 | 46 | @media (min-width: 768px) { 47 | html[data-theme='dark'], 48 | html[data-theme='light'] { 49 | --ifm-navbar-height: 85px; 50 | } 51 | 52 | body { 53 | padding: 0 25px; 54 | } 55 | 56 | .footer { 57 | margin-bottom: 25px; 58 | } 59 | 60 | .navbar__inner { 61 | padding-top: 25px; 62 | } 63 | } -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/weth_9.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::{ 7 | AccountId, 8 | String, 9 | }, 10 | }; 11 | use scale::{ 12 | Decode, 13 | Encode, 14 | }; 15 | 16 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 17 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 18 | pub enum Error { 19 | Custom(String), 20 | } 21 | 22 | 23 | 24 | #[openbrush::wrapper] 25 | pub type WETH9Ref = dyn WETH9; 26 | 27 | #[openbrush::trait_definition] 28 | pub trait WETH9 { 29 | /// function() public payable { 30 | /// deposit(); 31 | /// } 32 | #[ink(message, payable)] 33 | fn deposit(&mut self) -> Result<(), Error>; 34 | 35 | #[ink(message)] 36 | fn withdraw(&mut self, wad: u128) -> Result<(), Error>; 37 | 38 | #[ink(message)] 39 | fn total_supply(&self) -> Result; 40 | 41 | #[ink(message)] 42 | fn approve(&mut self, guy: AccountId, wad: u128) -> Result; 43 | 44 | #[ink(message)] 45 | fn transfer(&mut self, dst: AccountId, wad: u128) -> Result; 46 | 47 | #[ink(message)] 48 | fn transfer_from(&mut self, src: AccountId, dst: AccountId, wad: u128) -> Result; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/erc_20.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::{ 7 | AccountId, 8 | AccountIdExt, 9 | String, 10 | ZERO_ADDRESS, 11 | }, 12 | }; 13 | use scale::{ 14 | Decode, 15 | Encode, 16 | }; 17 | 18 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 19 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 20 | pub enum Error { 21 | Custom(String), 22 | } 23 | 24 | 25 | 26 | #[openbrush::wrapper] 27 | pub type ERC20Ref = dyn ERC20; 28 | 29 | #[openbrush::trait_definition] 30 | pub trait ERC20 { 31 | #[ink(message)] 32 | fn approve(&mut self, spender: AccountId, value: u128) -> Result; 33 | 34 | #[ink(message)] 35 | fn transfer(&mut self, to: AccountId, value: u128) -> Result; 36 | 37 | #[ink(message)] 38 | fn transfer_from(&mut self, from: AccountId, to: AccountId, value: u128) 39 | -> Result; 40 | 41 | #[ink(message)] 42 | fn permit( 43 | &mut self, 44 | owner: AccountId, 45 | spender: AccountId, 46 | value: u128, 47 | deadline: u128, 48 | v: u8, 49 | r: [u8; 32], 50 | s: [u8; 32], 51 | ) -> Result<(), Error>; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/example_oracle_simple.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | 17 | 18 | #[openbrush::wrapper] 19 | pub type ExampleOracleSimpleRef = dyn ExampleOracleSimple; 20 | 21 | #[openbrush::trait_definition] 22 | pub trait ExampleOracleSimple { 23 | /// fetch the current accumulated price value (1 / 0) 24 | /// fetch the current accumulated price value (0 / 1) 25 | /// ensure that there's liquidity in the pair 26 | #[ink(message)] 27 | fn update(&mut self) -> Result<(), Error>; 28 | 29 | /// overflow is desired 30 | /// ensure that at least one full period has passed since the last update 31 | /// overflow is desired, casting never truncates 32 | /// cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed 33 | /// note this will always return 0 before update has been called successfully for the first time. 34 | #[ink(message)] 35 | fn consult(&self, token: AccountId, amount_in: u128) -> Result; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_2_factory.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | #[ink(event)] 7 | pub struct PairCreated { 8 | #[ink(topic)] 9 | token_0: AccountId, 10 | #[ink(topic)] 11 | token_1: AccountId, 12 | pair: AccountId, 13 | anonymous: u128, 14 | } 15 | 16 | #[openbrush::wrapper] 17 | pub type IUniswapV2FactoryRef = dyn IUniswapV2Factory; 18 | 19 | #[openbrush::trait_definition] 20 | pub trait IUniswapV2Factory { 21 | #[ink(message)] 22 | fn fee_to(&self) -> Result; 23 | 24 | #[ink(message)] 25 | fn fee_to_setter(&self) -> Result; 26 | 27 | #[ink(message)] 28 | fn get_pair(&self, token_a: AccountId, token_b: AccountId) -> Result; 29 | 30 | #[ink(message)] 31 | fn all_pairs(&self, _: u128) -> Result; 32 | 33 | #[ink(message)] 34 | fn all_pairs_length(&self) -> Result; 35 | 36 | #[ink(message)] 37 | fn create_pair(&mut self, token_a: AccountId, token_b: AccountId) -> Result; 38 | 39 | #[ink(message)] 40 | fn set_fee_to(&mut self, _: AccountId) -> Result<(), Error>; 41 | 42 | #[ink(message)] 43 | fn set_fee_to_setter(&mut self, _: AccountId) -> Result<(), Error>; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/deflating_erc_20.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::{ 7 | AccountId, 8 | AccountIdExt, 9 | String, 10 | ZERO_ADDRESS, 11 | }, 12 | }; 13 | use scale::{ 14 | Decode, 15 | Encode, 16 | }; 17 | 18 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 19 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 20 | pub enum Error { 21 | Custom(String), 22 | } 23 | 24 | 25 | 26 | #[openbrush::wrapper] 27 | pub type DeflatingERC20Ref = dyn DeflatingERC20; 28 | 29 | #[openbrush::trait_definition] 30 | pub trait DeflatingERC20 { 31 | #[ink(message)] 32 | fn approve(&mut self, spender: AccountId, value: u128) -> Result; 33 | 34 | #[ink(message)] 35 | fn transfer(&mut self, to: AccountId, value: u128) -> Result; 36 | 37 | #[ink(message)] 38 | fn transfer_from(&mut self, from: AccountId, to: AccountId, value: u128) 39 | -> Result; 40 | 41 | #[ink(message)] 42 | fn permit( 43 | &mut self, 44 | owner: AccountId, 45 | spender: AccountId, 46 | value: u128, 47 | deadline: u128, 48 | v: u8, 49 | r: [u8; 32], 50 | s: [u8; 32], 51 | ) -> Result<(), Error>; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/uniswap_v_2_erc_20.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::{ 7 | AccountId, 8 | AccountIdExt, 9 | String, 10 | ZERO_ADDRESS, 11 | }, 12 | }; 13 | use scale::{ 14 | Decode, 15 | Encode, 16 | }; 17 | 18 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 19 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 20 | pub enum Error { 21 | Custom(String), 22 | } 23 | 24 | 25 | 26 | #[openbrush::wrapper] 27 | pub type UniswapV2ERC20Ref = dyn UniswapV2ERC20; 28 | 29 | #[openbrush::trait_definition] 30 | pub trait UniswapV2ERC20 { 31 | #[ink(message)] 32 | fn approve(&mut self, spender: AccountId, value: u128) -> Result; 33 | 34 | #[ink(message)] 35 | fn transfer(&mut self, to: AccountId, value: u128) -> Result; 36 | 37 | #[ink(message)] 38 | fn transfer_from(&mut self, from: AccountId, to: AccountId, value: u128) 39 | -> Result; 40 | 41 | #[ink(message)] 42 | fn permit( 43 | &mut self, 44 | owner: AccountId, 45 | spender: AccountId, 46 | value: u128, 47 | deadline: u128, 48 | v: u8, 49 | r: [u8; 32], 50 | s: [u8; 32], 51 | ) -> Result<(), Error>; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /docs/src/css/fonts.scss: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Sometype Mono'; 3 | src: url('/static/fonts/sometype-mono.regular.ttf') format('truetype'); 4 | font-weight: 400; 5 | font-style: normal; 6 | font-display: swap; 7 | } 8 | 9 | @font-face { 10 | font-family: 'Sometype Mono'; 11 | src: url('/static/fonts/sometype-mono.regular-italic.ttf') format('truetype'); 12 | font-weight: 400; 13 | font-style: italic; 14 | font-display: swap; 15 | } 16 | 17 | @font-face { 18 | font-family: 'Sometype Mono'; 19 | src: url('/static/fonts/sometype-mono.medium.ttf') format('truetype'); 20 | font-weight: 500; 21 | font-style: normal; 22 | font-display: swap; 23 | } 24 | 25 | @font-face { 26 | font-family: 'Sometype Mono'; 27 | src: url('/static/fonts/sometype-mono.medium-italic.ttf') format('truetype'); 28 | font-weight: 500; 29 | font-style: italic; 30 | font-display: swap; 31 | } 32 | 33 | @font-face { 34 | font-family: 'Sometype Mono'; 35 | src: url('/static/fonts/sometype-mono.bold.ttf') format('truetype'); 36 | font-weight: bold; 37 | font-style: normal; 38 | font-display: swap; 39 | } 40 | 41 | @font-face { 42 | font-family: 'Sometype Mono'; 43 | src: url('/static/fonts/sometype-mono.bold-italic.ttf') format('truetype'); 44 | font-weight: bold; 45 | font-style: italic; 46 | font-display: swap; 47 | } -------------------------------------------------------------------------------- /tests/generated/src/traits/ierc_20.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::AccountId, 7 | }; 8 | 9 | #[ink(event)] 10 | pub struct Transfer { 11 | #[ink(topic)] 12 | from: AccountId, 13 | #[ink(topic)] 14 | to: AccountId, 15 | amount: u128, 16 | } 17 | 18 | #[ink(event)] 19 | pub struct Approval { 20 | #[ink(topic)] 21 | owner: AccountId, 22 | #[ink(topic)] 23 | spender: AccountId, 24 | amount: u128, 25 | } 26 | 27 | #[openbrush::wrapper] 28 | pub type IERC20Ref = dyn IERC20; 29 | 30 | #[openbrush::trait_definition] 31 | pub trait IERC20 { 32 | #[ink(message)] 33 | fn total_supply(&self) -> Result; 34 | 35 | #[ink(message)] 36 | fn balance_of(&self, account: AccountId) -> Result; 37 | 38 | #[ink(message)] 39 | fn transfer(&mut self, recipient: AccountId, amount: u128) -> Result; 40 | 41 | #[ink(message)] 42 | fn allowance(&self, owner: AccountId, spender: AccountId) -> Result; 43 | 44 | #[ink(message)] 45 | fn approve(&mut self, spender: AccountId, amount: u128) -> Result; 46 | 47 | #[ink(message)] 48 | fn transfer_from( 49 | &mut self, 50 | sender: AccountId, 51 | recipient: AccountId, 52 | amount: u128, 53 | ) -> Result; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /docs/docs/intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | slug: / 4 | title: Sol2Ink Documentation 5 | sidebar_label: Getting started 6 | --- 7 | 8 | # Sol2Ink Documentation 9 | 10 | Welcome to Sol2Ink documentation. In this documentation, we will describe the capabilities of Sol2Ink, how the process works under the hood, 11 | what issues you may face while using Sol2Ink, and you will see some examples of usage of Sol2Ink. 12 | 13 | ## What is Sol2Ink 14 | 15 | Sol2Ink is a tool developed to ease the developers' transition from Solidity to ink!. Since we are the builders in the Dotsama ecosystem, we recognized a problem when some team wanted to develop their existing Solidity dapp in ink! smart contract language, the most annoying and time-consuming part of the development will be rewriting the Solidity code into Rust and ink!. Sol2Ink aims to decrease this time by transpiling the existing Solidity code into Rust and ink! code. So the dirty part of the job is automated, and now it is up to the developers to fix some language-specific issues while learning how things works in ink!. Sol2Ink will save time! 16 | 17 | ### What you'll need 18 | 19 | Sol2Ink is written in Rust, so you will need Rust installed with the nightly toolchain. If this is satisfied, you will also need Sol2Ink, which you can get [here](https://github.com/Supercolony-net/sol2ink/releases/tag/v1.0.0). Another thing you will need is the Solidity file you want to transpile. And that's it! We can start transpiling now! 20 | -------------------------------------------------------------------------------- /tests/generated/contracts/erc_1155/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// SPDX-License-Identifier: MIT 8 | /// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC1155/ERC1155.sol) 9 | /// @dev Implementation of the basic standard multi-token. 10 | /// See https://eips.ethereum.org/EIPS/eip-1155 11 | /// Originally based on code by Enjin: https://github.com/enjin/erc-1155 12 | /// 13 | /// _Available since v3.1._ 14 | #[openbrush::contract] 15 | pub mod erc_1155 { 16 | use generated::*; 17 | use ink::lang::codegen::{ 18 | EmitEvent, 19 | Env, 20 | }; 21 | use openbrush::traits::Storage; 22 | 23 | 24 | #[ink(storage)] 25 | #[derive(Default, Storage)] 26 | pub struct ERC1155Contract { 27 | #[storage_field] 28 | data: impls::Data, 29 | } 30 | 31 | impl ERC1155 for ERC1155Contract {} 32 | 33 | impl Context for ERC1155Contract {} 34 | 35 | impl ERC165 for ERC1155Contract {} 36 | 37 | impl IERC1155 for ERC1155Contract {} 38 | 39 | impl IERC1155MetadataURI for ERC1155Contract {} 40 | 41 | impl ERC1155Contract { 42 | /// @dev See {_setURI}. 43 | #[ink(constructor)] 44 | pub fn new(uri: String) -> Self { 45 | let mut instance = Self::default(); 46 | instance._set_uri(uri)?; 47 | instance 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/generated/src/traits/struct_contract.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::{ 5 | AccountId, 6 | String, 7 | }; 8 | use scale::{ 9 | Decode, 10 | Encode, 11 | }; 12 | 13 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 14 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 15 | pub enum Error { 16 | Custom(String), 17 | } 18 | 19 | pub enum Status { 20 | Pending, 21 | Shipped, 22 | Accepted, 23 | Rejected, 24 | Canceled, 25 | } 26 | 27 | 28 | #[derive(Default, Encode, Decode)] 29 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 30 | pub struct Todo { 31 | text: String, 32 | completed: bool, 33 | priority: u8, 34 | comment: String, 35 | } 36 | 37 | 38 | #[openbrush::wrapper] 39 | pub type StructContractRef = dyn StructContract; 40 | 41 | #[openbrush::trait_definition] 42 | pub trait StructContract { 43 | #[ink(message)] 44 | fn get(&self) -> Result; 45 | 46 | #[ink(message)] 47 | fn set(&mut self, status: Status) -> Result<(), Error>; 48 | 49 | #[ink(message)] 50 | fn cancel(&mut self) -> Result<(), Error>; 51 | 52 | #[ink(message)] 53 | fn reset(&mut self) -> Result<(), Error>; 54 | 55 | #[ink(message)] 56 | fn create_events(&mut self) -> Result<(), Error>; 57 | 58 | #[ink(message)] 59 | fn create_todo(&mut self, text: String, priority: u8, comment: String) -> Result<(), Error>; 60 | 61 | } 62 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/interfaces/IUniswapV2Router02.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.6.2; 2 | 3 | import './IUniswapV2Router01.sol'; 4 | 5 | interface IUniswapV2Router02 is IUniswapV2Router01 { 6 | function removeLiquidityETHSupportingFeeOnTransferTokens( 7 | address token, 8 | uint liquidity, 9 | uint amountTokenMin, 10 | uint amountETHMin, 11 | address to, 12 | uint deadline 13 | ) external returns (uint amountETH); 14 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 15 | address token, 16 | uint liquidity, 17 | uint amountTokenMin, 18 | uint amountETHMin, 19 | address to, 20 | uint deadline, 21 | bool approveMax, uint8 v, bytes32 r, bytes32 s 22 | ) external returns (uint amountETH); 23 | 24 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 25 | uint amountIn, 26 | uint amountOutMin, 27 | address[] calldata path, 28 | address to, 29 | uint deadline 30 | ) external; 31 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 32 | uint amountOutMin, 33 | address[] calldata path, 34 | address to, 35 | uint deadline 36 | ) external payable; 37 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 38 | uint amountIn, 39 | uint amountOutMin, 40 | address[] calldata path, 41 | address to, 42 | uint deadline 43 | ) external; 44 | } 45 | -------------------------------------------------------------------------------- /docs/src/css/navbar.scss: -------------------------------------------------------------------------------- 1 | .navbar__brand { 2 | height: 2.9rem; 3 | margin-left: 15px; 4 | } 5 | 6 | .navbar__toggle { 7 | margin-left: 20px; 8 | margin-right: 0; 9 | } 10 | 11 | .navbar--fixed-top { 12 | border-bottom: 2px solid var(--ifm-toc-border-color); 13 | padding: 0; 14 | } 15 | 16 | .navbar__items { 17 | flex: initial; 18 | } 19 | 20 | .navbar__items:first-child:after { 21 | content: ''; 22 | position: absolute; 23 | width: 97px; 24 | height: 2px; 25 | right: -97px; 26 | background: var(--ifm-toc-border-color); 27 | -webkit-transform: rotate(37.28deg) translateX(-1px); 28 | -moz-transform: rotate(37.28deg) translateX(-1px); 29 | transform: rotate(37.28deg) translateX(-1px); 30 | -webkit-transform-origin: left bottom; 31 | -moz-transform-origin: left bottom; 32 | transform-origin: left bottom; 33 | top: -2px; 34 | } 35 | 36 | .navbar__items:first-child { 37 | border-left: 2px solid var(--ifm-toc-border-color); 38 | border-top: 2px solid var(--ifm-toc-border-color); 39 | width: calc(var(--doc-sidebar-width) - 75px); 40 | position: relative; 41 | } 42 | 43 | @media (max-width: 997px) { 44 | .navbar__inner .navbar__items:first-child { 45 | width: calc(100% - 77px); 46 | } 47 | } 48 | 49 | @media (min-width: 997px) { 50 | aside[class^='docSidebarContainer'] { 51 | border-right-width: 2px; 52 | } 53 | 54 | html [class^='tableOfContents'] { 55 | top: var(--ifm-navbar-height); 56 | } 57 | } -------------------------------------------------------------------------------- /docs/docs/issues.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 5 3 | title: Known issues 4 | --- 5 | 6 | Here is a list of known issues which you may face using Sol2Ink: 7 | 8 | ### Added or fixed in v 2.0.0 9 | 10 | - ~~inability to parse libraries~~ 11 | - ~~inability to parse uncompilable contracts~~ (since 2.0.0 most cases can be parsed, otherwise Sol2Ink will throw a comprehesive error) 12 | - ~~calling functions with a value~~ 13 | - ~~occasional incorrect parsing of selectors within brackets~~ 14 | - ~~incorrect rewriting of fields inside structs extracted from a mapping~~ 15 | - ~~incorrectly allowing modifiers to take functions as parameters~~ 16 | - ~~inability to parse inheritation~~ 17 | - ~~inability to parse multi-file projects~~ 18 | - ~~binary operation in a function only performs the reading of the value, not the updating~~ 19 | 20 | ### To be fixed 21 | - output contracts can be incompilable and need some fixing from the developer (our long-term goal is to make all contracts compilable) 22 | - Solidity abi functions (encode, decode) 23 | - Overloading functions is supported in Solidity but not in Rust 24 | - Functions as parameters 25 | 26 | Sol2Ink still needs to walk some path. Every time you use Sol2Ink to transpile your contracts from Solidity to ink!, run the generated code by a human brain to get the best results! If you find any issue, let us know in our [Element chat](https://matrix.to/#/!utTuYglskDvqRRMQta:matrix.org?via=matrix.org&via=t2bot.io&via=web3.foundation), [Discord](https://discord.gg/6TXE7n7Ptc) or simply open an issue in our [GitHub repo](https://github.com/Brushfam/sol2ink) 27 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/ierc_20.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::{ 5 | AccountId, 6 | String, 7 | }; 8 | 9 | #[ink(event)] 10 | pub struct Approval { 11 | #[ink(topic)] 12 | owner: AccountId, 13 | #[ink(topic)] 14 | spender: AccountId, 15 | value: u128, 16 | } 17 | 18 | #[ink(event)] 19 | pub struct Transfer { 20 | #[ink(topic)] 21 | from: AccountId, 22 | #[ink(topic)] 23 | to: AccountId, 24 | value: u128, 25 | } 26 | 27 | #[openbrush::wrapper] 28 | pub type IERC20Ref = dyn IERC20; 29 | 30 | #[openbrush::trait_definition] 31 | pub trait IERC20 { 32 | #[ink(message)] 33 | fn name(&self) -> Result; 34 | 35 | #[ink(message)] 36 | fn symbol(&self) -> Result; 37 | 38 | #[ink(message)] 39 | fn decimals(&self) -> Result; 40 | 41 | #[ink(message)] 42 | fn total_supply(&self) -> Result; 43 | 44 | #[ink(message)] 45 | fn balance_of(&self, owner: AccountId) -> Result; 46 | 47 | #[ink(message)] 48 | fn allowance(&self, owner: AccountId, spender: AccountId) -> Result; 49 | 50 | #[ink(message)] 51 | fn approve(&mut self, spender: AccountId, value: u128) -> Result; 52 | 53 | #[ink(message)] 54 | fn transfer(&mut self, to: AccountId, value: u128) -> Result; 55 | 56 | #[ink(message)] 57 | fn transfer_from(&mut self, from: AccountId, to: AccountId, value: u128) 58 | -> Result; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Documentation 2 | 3 | on: 4 | pull_request: 5 | branches: [main] 6 | push: 7 | branches: [main] 8 | 9 | jobs: 10 | checks: 11 | if: github.event_name != 'push' 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v1 15 | - uses: actions/setup-node@v1 16 | with: 17 | node-version: '16.x' 18 | - name: Test Build 19 | run: | 20 | cd docs 21 | if [ -e yarn.lock ]; then 22 | yarn install --frozen-lockfile 23 | elif [ -e package-lock.json ]; then 24 | npm ci 25 | else 26 | npm i 27 | fi 28 | npm run build 29 | gh-release: 30 | if: github.event_name != 'pull_request' 31 | runs-on: ubuntu-latest 32 | steps: 33 | - uses: actions/checkout@v1 34 | - uses: actions/setup-node@v1 35 | with: 36 | node-version: '16.x' 37 | - uses: webfactory/ssh-agent@v0.5.4 38 | with: 39 | ssh-private-key: ${{ secrets.GH_PAGES_DEPLOY }} 40 | - name: Release to GitHub Pages 41 | env: 42 | USE_SSH: true 43 | GIT_USER: git 44 | run: | 45 | cd docs 46 | git config --global user.email "actions@github.com" 47 | git config --global user.name "gh-actions" 48 | if [ -e yarn.lock ]; then 49 | yarn install --frozen-lockfile 50 | elif [ -e package-lock.json ]; then 51 | npm ci 52 | else 53 | npm i 54 | fi 55 | npm run deploy 56 | -------------------------------------------------------------------------------- /tests/generated/contracts/comment_contract/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod comment_contract { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | ///sender comment 18 | /// message comment 19 | ///priority comment1 20 | ///priority comment2 21 | #[ink(event)] 22 | pub struct Log { 23 | #[ink(topic)] 24 | sender: AccountId, 25 | message: String, 26 | priority: u8, 27 | status: Status, 28 | } 29 | 30 | #[ink(storage)] 31 | #[derive(Default, Storage)] 32 | pub struct CommentContractContract { 33 | #[storage_field] 34 | data: impls::Data, 35 | } 36 | 37 | impl CommentContract for CommentContractContract {} 38 | impl generated::impls::comment_contract::Internal for CommentContractContract { 39 | 40 | fn _emit_log(&self, sender: AccountId, message: String, priority: u8, status: Status) { 41 | self.env().emit_event(Log { 42 | sender, 43 | message, 44 | priority, 45 | status, 46 | }); 47 | } 48 | 49 | } 50 | 51 | impl CommentContractContract { 52 | #[ink(constructor)] 53 | pub fn new() -> Self { 54 | let mut instance = Self::default(); 55 | instance 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/generated/contracts/erc_721/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// SPDX-License-Identifier: MIT 8 | /// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/ERC721.sol) 9 | /// @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including 10 | /// the Metadata extension, but not including the Enumerable extension, which is available separately as 11 | /// {ERC721Enumerable}. 12 | #[openbrush::contract] 13 | pub mod erc_721 { 14 | use generated::*; 15 | use ink::lang::codegen::{ 16 | EmitEvent, 17 | Env, 18 | }; 19 | use openbrush::traits::Storage; 20 | 21 | 22 | #[ink(storage)] 23 | #[derive(Default, Storage)] 24 | pub struct ERC721Contract { 25 | #[storage_field] 26 | data: impls::Data, 27 | } 28 | 29 | impl ERC721 for ERC721Contract {} 30 | 31 | impl Context for ERC721Contract {} 32 | 33 | impl ERC165 for ERC721Contract {} 34 | 35 | impl IERC721 for ERC721Contract {} 36 | 37 | impl IERC721Metadata for ERC721Contract {} 38 | 39 | impl ERC721Contract { 40 | /// @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. 41 | #[ink(constructor)] 42 | pub fn new(name: String, symbol: String) -> Self { 43 | let mut instance = Self::default(); 44 | instance.data.name = name; 45 | instance.data.symbol = symbol; 46 | instance 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sol-2-ink", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve", 13 | "write-translations": "docusaurus write-translations", 14 | "write-heading-ids": "docusaurus write-heading-ids" 15 | }, 16 | "dependencies": { 17 | "@docusaurus/core": "2.0.0-beta.21", 18 | "@docusaurus/preset-classic": "2.0.0-beta.21", 19 | "@docusaurus/theme-search-algolia": "^2.0.0-beta.21", 20 | "@mdx-js/react": "^1.6.21", 21 | "@svgr/webpack": "^5.5.0", 22 | "clsx": "^1.1.1", 23 | "docusaurus-plugin-sass": "^0.2.1", 24 | "file-loader": "^6.2.0", 25 | "prism-react-renderer": "^1.2.1", 26 | "react": "^17.0.1", 27 | "react-dom": "^17.0.1", 28 | "sass": "^1.39.0", 29 | "url-loader": "^4.1.1" 30 | }, 31 | "devDependencies": { 32 | "@docusaurus/module-type-aliases": "2.0.0-beta.21", 33 | "@tsconfig/docusaurus": "^1.0.3", 34 | "@types/react": "^17.0.14", 35 | "@types/react-helmet": "^6.1.2", 36 | "@types/react-router-dom": "^5.1.8", 37 | "typescript": "^4.3.5" 38 | }, 39 | "browserslist": { 40 | "production": [ 41 | ">0.5%", 42 | "not dead", 43 | "not op_mini all" 44 | ], 45 | "development": [ 46 | "last 1 chrome version", 47 | "last 1 firefox version", 48 | "last 1 safari version" 49 | ] 50 | }, 51 | "engines": { 52 | "node": ">=16.14" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/generated/contracts/struct_contract/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod struct_contract { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(event)] 18 | pub struct Log { 19 | #[ink(topic)] 20 | sender: AccountId, 21 | message: String, 22 | priority: u8, 23 | status: Status, 24 | } 25 | 26 | #[ink(event)] 27 | pub struct AnotherLog {} 28 | 29 | #[ink(storage)] 30 | #[derive(Default, Storage)] 31 | pub struct StructContractContract { 32 | #[storage_field] 33 | data: impls::Data, 34 | } 35 | 36 | impl StructContract for StructContractContract {} 37 | impl generated::impls::struct_contract::Internal for StructContractContract { 38 | 39 | fn _emit_log(&self, sender: AccountId, message: String, priority: u8, status: Status) { 40 | self.env().emit_event(Log { 41 | sender, 42 | message, 43 | priority, 44 | status, 45 | }); 46 | } 47 | 48 | fn _emit_another_log(&self) { 49 | self.env().emit_event(AnotherLog {}); 50 | } 51 | 52 | } 53 | 54 | impl StructContractContract { 55 | #[ink(constructor)] 56 | pub fn new() -> Self { 57 | let mut instance = Self::default(); 58 | instance 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/StructContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.0; 2 | 3 | contract StructContract { 4 | enum Status { 5 | Pending, 6 | Shipped, 7 | Accepted, 8 | Rejected, 9 | Canceled 10 | } 11 | 12 | Status public status; 13 | 14 | event Log(address indexed sender, string message, uint8 priority, Status status); 15 | event AnotherLog(); 16 | 17 | struct Todo { 18 | string text; 19 | bool completed; 20 | uint8 priority; 21 | string comment; 22 | } 23 | 24 | Todo[] public todos; 25 | 26 | function get() public view returns (Status) { 27 | return status; 28 | } 29 | 30 | function set(Status _status) public { 31 | status = _status; 32 | } 33 | 34 | function cancel() public { 35 | status = Status.Canceled; 36 | } 37 | 38 | function reset() public { 39 | delete status; 40 | } 41 | 42 | function create_events() public { 43 | emit Log(msg.sender, "log event", 9, Accepted); 44 | emit AnotherLog(); 45 | } 46 | 47 | function create_todo(string calldata _text, uint8 _priority, string calldata _comment) public { 48 | // 3 ways to initialize a struct 49 | // - calling it like a function 50 | todos.push(Todo(_text, false, _priority, _comment)); 51 | 52 | // key value mapping 53 | todos.push(Todo({text: _text, completed: false, priority: _priority, _comment: _comment})); 54 | 55 | // initialize an empty struct and then update it 56 | Todo memory todo; 57 | todo.text = _text; 58 | // completed initialized to false 59 | todo.priority = _priority; 60 | todo.comment = _comment; 61 | 62 | todos.push(todo); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/generated/contracts/stable_swap/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod stable_swap { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | /// Number of tokens 17 | pub const N: u128 = 3; 18 | /// Amplification coefficient multiplied by N^(N - 1) 19 | /// Higher value makes the curve more flat 20 | /// Lower value makes the curve more like constant product AMM 21 | pub const A: u128 = 1000 * (N.pow((N - 1))); 22 | /// 0.03% 23 | pub const SWAP_FEE: u128 = 300; 24 | /// Liquidity fee is derived from 2 constraints 25 | /// 1. Fee is 0 for adding / removing liquidity that results in a balanced pool 26 | /// 2. Swapping in a balanced pool is like adding and then removing liquidity 27 | /// from a balanced pool 28 | /// swap fee = add liquidity fee + remove liquidity fee 29 | pub const LIQUIDITY_FEE: u128 = (SWAP_FEE * N) / (4 * (N - 1)); 30 | pub const FEE_DENOMINATOR: u128 = 1000000; 31 | /// 1 share = 1e18, 18 decimals 32 | pub const DECIMALS: u128 = 18; 33 | 34 | #[ink(storage)] 35 | #[derive(Default, Storage)] 36 | pub struct StableSwapContract { 37 | #[storage_field] 38 | data: impls::Data, 39 | } 40 | 41 | impl StableSwap for StableSwapContract {} 42 | 43 | impl StableSwapContract { 44 | #[ink(constructor)] 45 | pub fn new() -> Self { 46 | let mut instance = Self::default(); 47 | self.multipliers = vec![1, 1000000000000, 1000000000000]; 48 | instance 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_factory/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod uniswap_v_2_factory { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | 17 | #[ink(event)] 18 | pub struct PairCreated { 19 | #[ink(topic)] 20 | token_0: AccountId, 21 | #[ink(topic)] 22 | token_1: AccountId, 23 | pair: AccountId, 24 | anonymous: u128, 25 | } 26 | 27 | #[ink(storage)] 28 | #[derive(Default, Storage)] 29 | pub struct UniswapV2FactoryContract { 30 | #[storage_field] 31 | data: impls::Data, 32 | } 33 | 34 | impl UniswapV2Factory for UniswapV2FactoryContract {} 35 | impl generated::impls::uniswap_v_2_factory::Internal for UniswapV2FactoryContract { 36 | 37 | fn _emit_pair_created( 38 | &self, 39 | token_0: AccountId, 40 | token_1: AccountId, 41 | pair: AccountId, 42 | anonymous: u128, 43 | ) { 44 | self.env().emit_event(PairCreated { 45 | token_0, 46 | token_1, 47 | pair, 48 | anonymous, 49 | }); 50 | } 51 | 52 | } 53 | 54 | impl IUniswapV2Factory for UniswapV2FactoryContract {} 55 | 56 | impl UniswapV2FactoryContract { 57 | #[ink(constructor)] 58 | pub fn new(fee_to_setter: AccountId) -> Self { 59 | let mut instance = Self::default(); 60 | instance.data.fee_to_setter = fee_to_setter; 61 | instance 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/libs/uniswap_v_2_oracle_library.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | // Generated with Sol2Ink v2.1.0 7 | // https://github.com/Brushfam/sol2ink 8 | 9 | /// library with helper methods for oracles that are concerned with computing average prices 10 | 11 | pub enum Error { 12 | Custom(String), 13 | } 14 | 15 | 16 | /// helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] 17 | pub fn current_block_timestamp(&self) -> Result { 18 | return Ok(::from(Self::env().block_timestamp() % 2.pow(32))) 19 | } 20 | 21 | /// produces the cumulative price using counterfactuals to save gas and avoid a call to sync. 22 | pub fn current_cumulative_prices(&self, pair: AccountId) -> Result<(u128, u128, u32), Error> { 23 | let mut price_0_cumulative = Default::default(); 24 | let mut price_1_cumulative = Default::default(); 25 | let mut block_timestamp = Default::default(); 26 | block_timestamp = self._current_block_timestamp()?; 27 | price_0_cumulative = i_uniswap_v_2_pair(pair)?.price_0_cumulative_last()?; 28 | price_1_cumulative = i_uniswap_v_2_pair(pair)?.price_1_cumulative_last()?; 29 | (reserve_0, reserve_1, block_timestamp_last) = i_uniswap_v_2_pair(pair)?.get_reserves()?; 30 | if block_timestamp_last != block_timestamp { 31 | let mut time_elapsed: u32 = block_timestamp - block_timestamp_last; 32 | price_0_cumulative += 33 | ::from(fixed_point.fraction(reserve_1, reserve_0)?.x) * time_elapsed; 34 | price_1_cumulative += 35 | ::from(fixed_point.fraction(reserve_0, reserve_1)?.x) * time_elapsed; 36 | } 37 | Ok((price_0_cumulative, price_1_cumulative, block_timestamp)) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/libraries/UniswapV2OracleLibrary.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol'; 4 | import '@uniswap/lib/contracts/libraries/FixedPoint.sol'; 5 | 6 | // library with helper methods for oracles that are concerned with computing average prices 7 | library UniswapV2OracleLibrary { 8 | using FixedPoint for *; 9 | 10 | // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] 11 | function currentBlockTimestamp() internal view returns (uint32) { 12 | return uint32(block.timestamp % 2 ** 32); 13 | } 14 | 15 | // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. 16 | function currentCumulativePrices( 17 | address pair 18 | ) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) { 19 | blockTimestamp = currentBlockTimestamp(); 20 | price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast(); 21 | price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast(); 22 | 23 | // if time has elapsed since the last update on the pair, mock the accumulated price values 24 | (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves(); 25 | if (blockTimestampLast != blockTimestamp) { 26 | // subtraction overflow is desired 27 | uint32 timeElapsed = blockTimestamp - blockTimestampLast; 28 | // addition overflow is desired 29 | // counterfactual 30 | price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; 31 | // counterfactual 32 | price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/example_sliding_window_oracle.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::AccountId, 7 | }; 8 | use scale::{ 9 | Decode, 10 | Encode, 11 | }; 12 | 13 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 14 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 15 | pub enum Error { 16 | Custom(String), 17 | } 18 | 19 | 20 | #[derive(Default, Encode, Decode)] 21 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 22 | pub struct Observation { 23 | timestamp: u128, 24 | price_0_cumulative: u128, 25 | price_1_cumulative: u128, 26 | } 27 | 28 | 29 | #[openbrush::wrapper] 30 | pub type ExampleSlidingWindowOracleRef = dyn ExampleSlidingWindowOracle; 31 | 32 | #[openbrush::trait_definition] 33 | pub trait ExampleSlidingWindowOracle { 34 | /// returns the index of the observation corresponding to the given timestamp 35 | #[ink(message)] 36 | fn observation_index_of(&self, timestamp: u128) -> Result; 37 | 38 | /// no overflow issue. if observationIndex + 1 overflows, result is still zero. 39 | /// update the cumulative price for the observation at the current timestamp. each observation is updated at most 40 | /// once per epoch period. 41 | #[ink(message)] 42 | fn update(&mut self, token_a: AccountId, token_b: AccountId) -> Result<(), Error>; 43 | 44 | /// overflow is desired. 45 | /// returns the amount out corresponding to the amount in for a given token using the moving average over the time 46 | /// range [now - [windowSize, windowSize - periodSize * 2], now] 47 | /// update must have been called for the bucket corresponding to timestamp `now - windowSize` 48 | #[ink(message)] 49 | fn consult( 50 | &self, 51 | token_in: AccountId, 52 | amount_in: u128, 53 | token_out: AccountId, 54 | ) -> Result; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_oracle_simple/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// fixed window oracle that recomputes the average price for the entire period once every period 8 | /// note that the price average is only guaranteed to be over at least 1 period, but may be over a longer period 9 | #[openbrush::contract] 10 | pub mod example_oracle_simple { 11 | use generated::*; 12 | use ink::lang::codegen::{ 13 | EmitEvent, 14 | Env, 15 | }; 16 | use openbrush::traits::Storage; 17 | 18 | pub const PERIOD: u128 = 24 * 3600i128; 19 | 20 | #[ink(storage)] 21 | #[derive(Default, Storage)] 22 | pub struct ExampleOracleSimpleContract { 23 | #[storage_field] 24 | data: impls::Data, 25 | } 26 | 27 | impl ExampleOracleSimple for ExampleOracleSimpleContract {} 28 | 29 | impl ExampleOracleSimpleContract { 30 | #[ink(constructor)] 31 | pub fn new(factory: AccountId, token_a: AccountId, token_b: AccountId) -> Self { 32 | let mut instance = Self::default(); 33 | let mut pair: IUniswapV2Pair = 34 | i_uniswap_v_2_pair(uniswap_v_2_library.pair_for(factory, token_a, token_b)?)?; 35 | instance.data.pair = pair; 36 | instance.data.token_0 = pair.token_0()?; 37 | instance.data.token_1 = pair.token_1()?; 38 | instance.data.price_0_cumulative_last = pair.price_0_cumulative_last()?; 39 | instance.data.price_1_cumulative_last = pair.price_1_cumulative_last()?; 40 | (_, _, _) = pair.get_reserves()?; 41 | if !(reserve_0 != 0 && reserve_1 != 0) { 42 | return Err(Error::Custom(String::from( 43 | "ExampleOracleSimple: NO_RESERVES", 44 | ))) 45 | }; 46 | instance 47 | } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/generated/src/traits/primitives.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | pub enum Oper { 17 | Add, 18 | Sub, 19 | Mul, 20 | Div, 21 | Modulo, 22 | Pow, 23 | Shl, 24 | Shr, 25 | Or, 26 | And, 27 | Xor, 28 | } 29 | 30 | 31 | 32 | #[openbrush::wrapper] 33 | pub type primitivesRef = dyn primitives; 34 | 35 | #[openbrush::trait_definition] 36 | pub trait primitives { 37 | #[ink(message)] 38 | fn is_mul(&self, op: Oper) -> Result; 39 | 40 | #[ink(message)] 41 | fn return_div(&self) -> Result; 42 | 43 | #[ink(message)] 44 | fn op_i_64(&self, op: Oper, a: i64, b: i64) -> Result; 45 | 46 | #[ink(message)] 47 | fn op_u_64(&self, op: Oper, a: u64, b: u64) -> Result; 48 | 49 | #[ink(message)] 50 | fn op_u_256(&self, op: Oper, a: u128, b: u128) -> Result; 51 | 52 | #[ink(message)] 53 | fn op_i_256(&self, op: Oper, a: i128, b: i128) -> Result; 54 | 55 | #[ink(message)] 56 | fn return_u_8_6(&self) -> Result<[u8; 6], Error>; 57 | 58 | #[ink(message)] 59 | fn op_u_8_5_shift(&self, op: Oper, a: [u8; 5], r: u64) -> Result<[u8; 5], Error>; 60 | 61 | #[ink(message)] 62 | fn op_u_8_5(&self, op: Oper, a: [u8; 5], b: [u8; 5]) -> Result<[u8; 5], Error>; 63 | 64 | #[ink(message)] 65 | fn op_u_8_14_shift(&self, op: Oper, a: [u8; 14], r: u64) -> Result<[u8; 14], Error>; 66 | 67 | #[ink(message)] 68 | fn op_u_8_14(&self, op: Oper, a: [u8; 14], b: [u8; 14]) -> Result<[u8; 14], Error>; 69 | 70 | #[ink(message)] 71 | fn address_passthrough(&self, a: AccountId) -> Result; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | max_width = 100 # changed 2 | hard_tabs = false 3 | tab_spaces = 4 4 | newline_style = "Auto" 5 | use_small_heuristics = "Default" 6 | indent_style = "Block" 7 | wrap_comments = false 8 | format_code_in_doc_comments = false 9 | comment_width = 80 10 | normalize_comments = true # changed 11 | normalize_doc_attributes = false 12 | license_template_path = "LICENSE" # changed 13 | format_strings = false 14 | format_macro_matchers = false 15 | format_macro_bodies = true 16 | empty_item_single_line = true 17 | struct_lit_single_line = true 18 | fn_single_line = false 19 | where_single_line = false 20 | imports_indent = "Block" 21 | imports_layout = "Vertical" # changed 22 | imports_granularity = "Crate" # changed 23 | reorder_imports = true 24 | reorder_modules = true 25 | reorder_impl_items = false 26 | type_punctuation_density = "Wide" 27 | space_before_colon = false 28 | space_after_colon = true 29 | spaces_around_ranges = false 30 | binop_separator = "Front" 31 | remove_nested_parens = true 32 | combine_control_expr = false # changed 33 | overflow_delimited_expr = false 34 | struct_field_align_threshold = 0 35 | enum_discrim_align_threshold = 0 36 | match_arm_blocks = true 37 | force_multiline_blocks = true # changed 38 | fn_args_layout = "Tall" 39 | brace_style = "SameLineWhere" 40 | control_brace_style = "AlwaysSameLine" 41 | trailing_semicolon = false # changed 42 | trailing_comma = "Vertical" 43 | match_block_trailing_comma = false 44 | blank_lines_upper_bound = 1 45 | blank_lines_lower_bound = 0 46 | edition = "2021" # changed 47 | version = "One" 48 | merge_derives = true 49 | use_try_shorthand = true # changed 50 | use_field_init_shorthand = true # changed 51 | force_explicit_abi = true 52 | condense_wildcard_suffixes = false 53 | color = "Auto" 54 | unstable_features = true # changed 55 | disable_all_formatting = false 56 | skip_children = false 57 | hide_parse_errors = false 58 | error_on_line_overflow = false 59 | error_on_unformatted = false 60 | report_todo = "Never" 61 | report_fixme = "Always" 62 | ignore = [] -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_2_router_02.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | 6 | #[openbrush::wrapper] 7 | pub type IUniswapV2Router02Ref = dyn IUniswapV2Router02; 8 | 9 | #[openbrush::trait_definition] 10 | pub trait IUniswapV2Router02 { 11 | #[ink(message)] 12 | fn remove_liquidity_eth_supporting_fee_on_transfer_tokens( 13 | &mut self, 14 | token: AccountId, 15 | liquidity: u128, 16 | amount_token_min: u128, 17 | amount_eth_min: u128, 18 | to: AccountId, 19 | deadline: u128, 20 | ) -> Result; 21 | 22 | #[ink(message)] 23 | fn remove_liquidity_eth_with_permit_supporting_fee_on_transfer_tokens( 24 | &mut self, 25 | token: AccountId, 26 | liquidity: u128, 27 | amount_token_min: u128, 28 | amount_eth_min: u128, 29 | to: AccountId, 30 | deadline: u128, 31 | approve_max: bool, 32 | v: u8, 33 | r: [u8; 32], 34 | s: [u8; 32], 35 | ) -> Result; 36 | 37 | #[ink(message)] 38 | fn swap_exact_tokens_for_tokens_supporting_fee_on_transfer_tokens( 39 | &mut self, 40 | amount_in: u128, 41 | amount_out_min: u128, 42 | path: Vec, 43 | to: AccountId, 44 | deadline: u128, 45 | ) -> Result<(), Error>; 46 | 47 | #[ink(message, payable)] 48 | fn swap_exact_eth_for_tokens_supporting_fee_on_transfer_tokens( 49 | &mut self, 50 | amount_out_min: u128, 51 | path: Vec, 52 | to: AccountId, 53 | deadline: u128, 54 | ) -> Result<(), Error>; 55 | 56 | #[ink(message)] 57 | fn swap_exact_tokens_for_eth_supporting_fee_on_transfer_tokens( 58 | &mut self, 59 | amount_in: u128, 60 | amount_out_min: u128, 61 | path: Vec, 62 | to: AccountId, 63 | deadline: u128, 64 | ) -> Result<(), Error>; 65 | 66 | } 67 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod uniswap_v_2_factory; 2 | pub use uniswap_v_2_factory::*; 3 | 4 | pub mod uniswap_v_2_erc_20; 5 | pub use uniswap_v_2_erc_20::*; 6 | 7 | pub mod erc_20; 8 | pub use erc_20::*; 9 | 10 | pub mod uniswap_v_2_pair; 11 | pub use uniswap_v_2_pair::*; 12 | 13 | pub mod ierc_20; 14 | pub use ierc_20::*; 15 | 16 | pub mod i_uniswap_v_2_erc_20; 17 | pub use i_uniswap_v_2_erc_20::*; 18 | 19 | pub mod i_uniswap_v_2_factory; 20 | pub use i_uniswap_v_2_factory::*; 21 | 22 | pub mod i_uniswap_v_2_pair; 23 | pub use i_uniswap_v_2_pair::*; 24 | 25 | pub mod i_uniswap_v_2_callee; 26 | pub use i_uniswap_v_2_callee::*; 27 | 28 | pub mod uniswap_v_2_migrator; 29 | pub use uniswap_v_2_migrator::*; 30 | 31 | pub mod weth_9; 32 | pub use weth_9::*; 33 | 34 | pub mod erc_20; 35 | pub use erc_20::*; 36 | 37 | pub mod deflating_erc_20; 38 | pub use deflating_erc_20::*; 39 | 40 | pub mod router_event_emitter; 41 | pub use router_event_emitter::*; 42 | 43 | pub mod uniswap_v_2_router_01; 44 | pub use uniswap_v_2_router_01::*; 45 | 46 | pub mod example_compute_liquidity_value; 47 | pub use example_compute_liquidity_value::*; 48 | 49 | pub mod example_flash_swap; 50 | pub use example_flash_swap::*; 51 | 52 | pub mod example_oracle_simple; 53 | pub use example_oracle_simple::*; 54 | 55 | pub mod example_swap_to_price; 56 | pub use example_swap_to_price::*; 57 | 58 | pub mod example_sliding_window_oracle; 59 | pub use example_sliding_window_oracle::*; 60 | 61 | pub mod uniswap_v_2_router_02; 62 | pub use uniswap_v_2_router_02::*; 63 | 64 | pub mod i_uniswap_v_1_factory; 65 | pub use i_uniswap_v_1_factory::*; 66 | 67 | pub mod i_uniswap_v_1_exchange; 68 | pub use i_uniswap_v_1_exchange::*; 69 | 70 | pub mod ierc_20; 71 | pub use ierc_20::*; 72 | 73 | pub mod i_uniswap_v_2_router_01; 74 | pub use i_uniswap_v_2_router_01::*; 75 | 76 | pub mod i_uniswap_v_2_router_02; 77 | pub use i_uniswap_v_2_router_02::*; 78 | 79 | pub mod iweth; 80 | pub use iweth::*; 81 | 82 | pub mod i_uniswap_v_2_migrator; 83 | pub use i_uniswap_v_2_migrator::*; 84 | 85 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/example_compute_liquidity_value.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | 17 | 18 | #[openbrush::wrapper] 19 | pub type ExampleComputeLiquidityValueRef = dyn ExampleComputeLiquidityValue; 20 | 21 | #[openbrush::trait_definition] 22 | pub trait ExampleComputeLiquidityValue { 23 | /// see UniswapV2LiquidityMathLibrary#getReservesAfterArbitrage 24 | #[ink(message)] 25 | fn get_reserves_after_arbitrage( 26 | &self, 27 | token_a: AccountId, 28 | token_b: AccountId, 29 | true_price_token_a: u128, 30 | true_price_token_b: u128, 31 | ) -> Result<(u128, u128), Error>; 32 | 33 | /// see UniswapV2LiquidityMathLibrary#getLiquidityValue 34 | #[ink(message)] 35 | fn get_liquidity_value( 36 | &self, 37 | token_a: AccountId, 38 | token_b: AccountId, 39 | liquidity_amount: u128, 40 | ) -> Result<(u128, u128), Error>; 41 | 42 | /// see UniswapV2LiquidityMathLibrary#getLiquidityValueAfterArbitrageToPrice 43 | #[ink(message)] 44 | fn get_liquidity_value_after_arbitrage_to_price( 45 | &self, 46 | token_a: AccountId, 47 | token_b: AccountId, 48 | true_price_token_a: u128, 49 | true_price_token_b: u128, 50 | liquidity_amount: u128, 51 | ) -> Result<(u128, u128), Error>; 52 | 53 | /// test function to measure the gas cost of the above function 54 | #[ink(message)] 55 | fn get_gas_cost_of_get_liquidity_value_after_arbitrage_to_price( 56 | &self, 57 | token_a: AccountId, 58 | token_b: AccountId, 59 | true_price_token_a: u128, 60 | true_price_token_b: u128, 61 | liquidity_amount: u128, 62 | ) -> Result; 63 | 64 | } 65 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/example_sliding_window_oracle/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// sliding window oracle that uses observations collected over a window to provide moving price averages in the past 8 | /// `windowSize` with a precision of `windowSize / granularity` 9 | /// note this is a singleton oracle and only needs to be deployed once per desired parameters, which 10 | /// differs from the simple oracle which must be deployed once per pair. 11 | #[openbrush::contract] 12 | pub mod example_sliding_window_oracle { 13 | use generated::*; 14 | use ink::lang::codegen::{ 15 | EmitEvent, 16 | Env, 17 | }; 18 | use openbrush::traits::Storage; 19 | 20 | 21 | #[ink(storage)] 22 | #[derive(Default, Storage)] 23 | pub struct ExampleSlidingWindowOracleContract { 24 | #[storage_field] 25 | data: impls::Data, 26 | } 27 | 28 | impl ExampleSlidingWindowOracle for ExampleSlidingWindowOracleContract {} 29 | 30 | impl ExampleSlidingWindowOracleContract { 31 | #[ink(constructor)] 32 | pub fn new(factory: AccountId, window_size: u128, granularity: u8) -> Self { 33 | let mut instance = Self::default(); 34 | if !(granularity > 1) { 35 | return Err(Error::Custom(String::from( 36 | "SlidingWindowOracle: GRANULARITY", 37 | ))) 38 | }; 39 | if !((instance.data.period_size = window_size / granularity) * granularity 40 | == window_size) 41 | { 42 | return Err(Error::Custom(String::from( 43 | "SlidingWindowOracle: WINDOW_NOT_EVENLY_DIVISIBLE", 44 | ))) 45 | }; 46 | instance.data.factory = factory; 47 | instance.data.window_size = window_size; 48 | instance.data.granularity = granularity; 49 | instance 50 | } 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /docs/docusaurus.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Note: type annotations allow type checking and IDEs autocompletion 3 | 4 | const lightCodeTheme = require('prism-react-renderer/themes/github'); 5 | const darkCodeTheme = require('prism-react-renderer/themes/dracula'); 6 | 7 | /** @type {import('@docusaurus/types').Config} */ 8 | const config = { 9 | title: 'Sol2Ink', 10 | tagline: 'Sol2Ink documentation', 11 | url: 'https://Brushfam.github.io/sol2ink/', 12 | baseUrl: '/sol2ink/', 13 | onBrokenLinks: 'throw', 14 | onBrokenMarkdownLinks: 'warn', 15 | favicon: 'img/favicon.ico', 16 | organizationName: 'Brushfam', 17 | projectName: 'sol2ink', 18 | deploymentBranch: 'gh-pages', 19 | 20 | themeConfig: { 21 | colorMode: { 22 | defaultMode: 'dark' 23 | }, 24 | navbar: { 25 | logo: { 26 | alt: 'Sol2Ink', 27 | src: 'img/logo.svg', 28 | srcDark: 'img/logo-dark.svg' 29 | }, 30 | items: [ 31 | { 32 | href: 'https://twitter.com/727_ventures', 33 | className: 'header-twitter-link', 34 | position: 'right' 35 | }, 36 | { 37 | href: 'https://github.com/Brushfam/sol2ink', 38 | className: 'header-github-link', 39 | position: 'right' 40 | } 41 | ] 42 | }, 43 | footer: { 44 | copyright: `Copyright © ${new Date().getFullYear()} Sol2Ink, Supercolony.net.` 45 | }, 46 | prism: { 47 | theme: lightCodeTheme, 48 | darkTheme: darkCodeTheme, 49 | additionalLanguages: ['toml', 'rust'] 50 | } 51 | }, 52 | plugins: ['docusaurus-plugin-sass'], 53 | presets: [ 54 | [ 55 | '@docusaurus/preset-classic', 56 | { 57 | docs: { 58 | routeBasePath: '/', 59 | sidebarPath: require.resolve('./sidebars.js'), 60 | editUrl: 'https://github.com/Brushfam/sol2ink/tree/main/docs' 61 | }, 62 | theme: { 63 | customCss: [require.resolve('./src/css/custom.scss')] 64 | } 65 | } 66 | ] 67 | ] 68 | }; 69 | 70 | module.exports = config; 71 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/UniswapV2Factory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.5.16; 2 | 3 | import './interfaces/IUniswapV2Factory.sol'; 4 | import './UniswapV2Pair.sol'; 5 | 6 | contract UniswapV2Factory is IUniswapV2Factory { 7 | address public feeTo; 8 | address public feeToSetter; 9 | 10 | mapping(address => mapping(address => address)) public getPair; 11 | address[] public allPairs; 12 | 13 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 14 | 15 | constructor(address _feeToSetter) public { 16 | feeToSetter = _feeToSetter; 17 | } 18 | 19 | function allPairsLength() external view returns (uint) { 20 | return allPairs.length; 21 | } 22 | 23 | function createPair(address tokenA, address tokenB) external returns (address pair) { 24 | require(tokenA != tokenB, 'UniswapV2: IDENTICAL_ADDRESSES'); 25 | (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); 26 | require(token0 != address(0), 'UniswapV2: ZERO_ADDRESS'); 27 | require(getPair[token0][token1] == address(0), 'UniswapV2: PAIR_EXISTS'); // single check is sufficient 28 | bytes memory bytecode = type(UniswapV2Pair).creationCode; 29 | bytes32 salt = keccak256(abi.encodePacked(token0, token1)); 30 | assembly { 31 | pair := create2(0, add(bytecode, 32), mload(bytecode), salt) 32 | } 33 | IUniswapV2Pair(pair).initialize(token0, token1); 34 | getPair[token0][token1] = pair; 35 | getPair[token1][token0] = pair; // populate mapping in the reverse direction 36 | allPairs.push(pair); 37 | emit PairCreated(token0, token1, pair, allPairs.length); 38 | } 39 | 40 | function setFeeTo(address _feeTo) external { 41 | require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN'); 42 | feeTo = _feeTo; 43 | } 44 | 45 | function setFeeToSetter(address _feeToSetter) external { 46 | require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN'); 47 | feeToSetter = _feeToSetter; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/generated/src/impls/comment_contract.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use crate::{ 5 | impls, 6 | traits::*, 7 | }; 8 | pub use ink::prelude::vec::*; 9 | use openbrush::traits::Storage; 10 | pub use openbrush::{ 11 | storage::Mapping, 12 | traits::{ 13 | AccountId, 14 | String, 15 | }, 16 | }; 17 | 18 | pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); 19 | 20 | #[derive(Default, Debug)] 21 | #[openbrush::upgradeable_storage(STORAGE_KEY)] 22 | pub struct Data { 23 | pub status: Status, 24 | pub _reserved: Option<()>, 25 | } 26 | 27 | 28 | impl> CommentContract for T { 29 | fn status(&self) -> Status { 30 | self.data().status 31 | } 32 | 33 | } 34 | 35 | pub trait Internal { 36 | fn _do_safe_batch_transfer_acceptance_check( 37 | &mut self, 38 | operator: AccountId, 39 | from: AccountId, 40 | to: AccountId, 41 | ids: Vec, 42 | amounts: Vec, 43 | data: Vec, 44 | ) -> Result<(), Error>; 45 | 46 | fn _emit_log(&self, sender: AccountId, message: String, priority: u8, status: Status); 47 | 48 | } 49 | 50 | impl> Internal for T { 51 | default fn _do_safe_batch_transfer_acceptance_check( 52 | &mut self, 53 | operator: AccountId, 54 | from: AccountId, 55 | to: AccountId, 56 | ids: Vec, 57 | amounts: Vec, 58 | data: Vec, 59 | ) -> Result<(), Error> { 60 | ids = 5; 61 | if ids < 4 { 62 | ids = 5; 63 | } else if ids == 0 { 64 | ids = 4; 65 | } else { 66 | ids = 0; 67 | } 68 | if to.is_contract()? { 69 | if ierc_1155_receiver(to)? 70 | .on_erc_1155_batch_received(operator, from, ids, amounts, data)? 71 | .is_err() 72 | { 73 | return Err(Error::Custom("Try failed")) 74 | } 75 | } 76 | Ok(()) 77 | } 78 | 79 | default fn _emit_log(&self, _: AccountId, _: String, _: u8, _: Status) {} 80 | 81 | } 82 | -------------------------------------------------------------------------------- /docs/docs/capabilities.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | title: Capabilities 4 | --- 5 | 6 | Sol2Ink can parse Solidity files into ink! project while leveraging the power of [OpenBrush](https://github.com/Brushfam/openbrush-contracts). You can either parse a single file by providing the path to the file, or a whole folder by providing the path to teh folder. In the latter case, Sol2Ink will parse all Solidity files in the selected folder file tree and add them to one big ink! project. The output of Sol2Ink is a folder called `generated` with the following file structure: 7 | 8 | ```shell 9 | ├── contracts 10 | │ └── contract 11 | │ ├── contract.rs 12 | │ └── Cargo.toml 13 | └── src 14 | ├── impls 15 | │ ├── contract.rs 16 | │ └── mod.rs 17 | ├── libs 18 | │ ├── library.rs 19 | │ └── mod.rs 20 | ├── traits 21 | │ ├── contract.rs 22 | │ └── mod.rs 23 | │── lib.rs 24 | └── Cargo.toml 25 | ``` 26 | 27 | In this structure, we suppose we were parsing a directory which contains a contract called `Contract.sol` and a library called `Library.sol`. Sol2Ink will produce a lib file called `library.rs` in the folder `src/libs` and expose it in the `src/libs/mod.rs` file. Parsing the `Contract.sol` file produces a trait which serves as a public API for our contract in `src/traits/contract.rs`, expose it in `src/traits/mod.rs`, the trait implementation file in `src/impls/contract.rs` and expose it in `src/impls/mod.rs`, a contract implementation file in `contracts/contract/contract.rs`, where the genrated trait will be implemented for the contract and a `contracts/contract/Cargo.toml` file, where will be the dependencies of our contract. Additionaly, it will expose the folders `src/impls`, `src/libs` and `src/traits` in `src/lib.rs` file, and add the dependencies file `src/Cargo.toml` file. 28 | 29 | This version of Sol2Ink is able to parse any contract, however, it may produce some compile-time issues. These will need to be fixed by the developer and future versions of Sol2Ink will aim to produce fully compilable code. The point of Sol2Ink currently is to save time on re-writing the code and makes the developer go over the generated code and fix it to make it work. -------------------------------------------------------------------------------- /docs/docs/how_it_works/assembler.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 7 3 | title: Assembling a contract 4 | --- 5 | 6 | Sol2Ink has everything it needs; now, it needs to mix it. Here we will clarify what may not be obvious. 7 | 8 | ### Error 9 | 10 | Each contract and library will contain the following error definition: 11 | ```rust 12 | #[derive(Debug, Encode, Decode, PartialEq)] 13 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 14 | pub enum Error { 15 | Custom(String), 16 | } 17 | ``` 18 | This error will be used as the error type when returning results from the contract functions. In the future versions, we plan on creating an Error enum variant for each error a contract can produce. So instead of `Err(Error::Custom(String::from("No allowance")))` Sol2Ink will produce `Err(Error::NoAllowance)`. 19 | 20 | ### Storage 21 | 22 | Openbrush simplifies the work with storage and allows the upgradeability of the storage; that is why we use the following approach. This approach will also streamline our future development when our contract uses multiple traits, etc. For now, we define a storage key inside the contract, the state variables in a struct which will use this storage key, and this struct itself is the member of the contract storage. The whole storage will look something like this: 23 | 24 | ```rust 25 | pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); 26 | 27 | #[derive(Default, Debug)] 28 | #[openbrush::upgradeable_storage(STORAGE_KEY)] 29 | pub struct Data { 30 | pub value: u128, 31 | } 32 | 33 | #[ink(storage)] 34 | #[derive(Default, SpreadAllocate, Storage)] 35 | pub struct Contract { 36 | #[storage_field] 37 | data: Data, 38 | } 39 | ``` 40 | Accessing the `value` state variables inside the contract looks like `self.data.value`. 41 | 42 | Sol2Ink will generate the functions of the contract inside the impl section. Note the following: 43 | 44 | - the constructor will be called new and will have the `#[ink(constructor)]` attribute 45 | - the constructor will be generated even if it is empty or does not exist in the original contract 46 | - public/external messages will have the `#[ink(message)]` attribute 47 | - private/internal functions will be prefixed with `_` 48 | -------------------------------------------------------------------------------- /tests/generated/src/traits/comment_contract.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::{ 6 | storage::Mapping, 7 | traits::{ 8 | AccountId, 9 | String, 10 | }, 11 | }; 12 | use scale::{ 13 | Decode, 14 | Encode, 15 | }; 16 | 17 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 18 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 19 | pub enum Error { 20 | Custom(String), 21 | } 22 | 23 | /// pending comment1 24 | /// pending comment2 25 | ///shipped comment1 26 | /// shipped comment2 27 | ///rejected comment 28 | ///canceled comment1 29 | /// canceled comment2 30 | pub enum Status { 31 | Pending, 32 | Shipped, 33 | Accepted, 34 | Rejected, 35 | Canceled, 36 | } 37 | 38 | 39 | /// MULTILINE_COMMENT::members 40 | /// COMMENT::members 41 | ///COMMENT::adminRole 42 | /// MULTILINE_COMMENT::adminRole 43 | #[derive(Default, Encode, Decode)] 44 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 45 | pub struct RoleData1 { 46 | members: Mapping, 47 | admin_role: [u8; 32], 48 | } 49 | 50 | /// 51 | ///ULTILINE_COMMENT::members 52 | /// COMMENT::members 53 | /// COMMENT::adminRole 54 | #[derive(Default, Encode, Decode)] 55 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 56 | pub struct RoleData2 { 57 | members: Mapping, 58 | admin_role: [u8; 32], 59 | } 60 | 61 | /// COMMENT::members 62 | /// COMMENT::adminRole 63 | #[derive(Default, Encode, Decode)] 64 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 65 | pub struct RoleData3 { 66 | members: Mapping, 67 | admin_role: [u8; 32], 68 | } 69 | 70 | /// MULTILINE_COMMENT::members 71 | /// MULTILINE_COMMENT::adminRole 72 | #[derive(Default, Encode, Decode)] 73 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 74 | pub struct RoleData4 { 75 | members: Mapping, 76 | admin_role: [u8; 32], 77 | } 78 | 79 | 80 | #[openbrush::wrapper] 81 | pub type CommentContractRef = dyn CommentContract; 82 | 83 | #[openbrush::trait_definition] 84 | pub trait CommentContract {} 85 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/i_uniswap_v_2_erc_20.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::{ 5 | AccountId, 6 | String, 7 | }; 8 | 9 | #[ink(event)] 10 | pub struct Approval { 11 | #[ink(topic)] 12 | owner: AccountId, 13 | #[ink(topic)] 14 | spender: AccountId, 15 | value: u128, 16 | } 17 | 18 | #[ink(event)] 19 | pub struct Transfer { 20 | #[ink(topic)] 21 | from: AccountId, 22 | #[ink(topic)] 23 | to: AccountId, 24 | value: u128, 25 | } 26 | 27 | #[openbrush::wrapper] 28 | pub type IUniswapV2ERC20Ref = dyn IUniswapV2ERC20; 29 | 30 | #[openbrush::trait_definition] 31 | pub trait IUniswapV2ERC20 { 32 | #[ink(message)] 33 | fn name(&self) -> Result; 34 | 35 | #[ink(message)] 36 | fn symbol(&self) -> Result; 37 | 38 | #[ink(message)] 39 | fn decimals(&self) -> Result; 40 | 41 | #[ink(message)] 42 | fn total_supply(&self) -> Result; 43 | 44 | #[ink(message)] 45 | fn balance_of(&self, owner: AccountId) -> Result; 46 | 47 | #[ink(message)] 48 | fn allowance(&self, owner: AccountId, spender: AccountId) -> Result; 49 | 50 | #[ink(message)] 51 | fn approve(&mut self, spender: AccountId, value: u128) -> Result; 52 | 53 | #[ink(message)] 54 | fn transfer(&mut self, to: AccountId, value: u128) -> Result; 55 | 56 | #[ink(message)] 57 | fn transfer_from(&mut self, from: AccountId, to: AccountId, value: u128) 58 | -> Result; 59 | 60 | #[ink(message)] 61 | fn domain_separator(&self) -> Result<[u8; 32], Error>; 62 | 63 | #[ink(message)] 64 | fn permit_typehash(&self) -> Result<[u8; 32], Error>; 65 | 66 | #[ink(message)] 67 | fn nonces(&self, owner: AccountId) -> Result; 68 | 69 | #[ink(message)] 70 | fn permit( 71 | &mut self, 72 | owner: AccountId, 73 | spender: AccountId, 74 | value: u128, 75 | deadline: u128, 76 | v: u8, 77 | r: [u8; 32], 78 | s: [u8; 32], 79 | ) -> Result<(), Error>; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/cli.rs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | 3 | // Copyright (c) 2022 Supercolony 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | use clap::{ 24 | command, 25 | Parser, 26 | }; 27 | use std::path::Path; 28 | 29 | #[derive(Debug, Clone)] 30 | pub enum CliInput { 31 | SolidityFile(String), 32 | Directory(String), 33 | } 34 | 35 | /// Sol2Ink - tool to convert Solidity smart contracts to Ink! smart contracts 36 | #[derive(Parser, Debug)] 37 | #[command(author, version, about, long_about = None)] 38 | pub struct Args { 39 | /// Path to files or directories 40 | #[arg(value_parser = sol_file_parser)] 41 | pub(crate) files: Option>, 42 | } 43 | 44 | fn sol_file_parser(s: &str) -> Result { 45 | let result = s.to_string(); 46 | 47 | if !Path::new(&result).exists() { 48 | return Err(format!("{result} does not exist")) 49 | } 50 | 51 | if result.ends_with(".sol") { 52 | Ok(CliInput::SolidityFile(result)) 53 | } else if Path::new(&result).is_dir() { 54 | Ok(CliInput::Directory(result)) 55 | } else { 56 | Err(format!("{result} is not a solidity file or directory")) 57 | } 58 | } 59 | 60 | pub fn cli() -> Args { 61 | Args::parse() 62 | } 63 | -------------------------------------------------------------------------------- /tests/generated/src/traits/function_contract.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::{ 5 | AccountId, 6 | AccountIdExt, 7 | String, 8 | ZERO_ADDRESS, 9 | }; 10 | use scale::{ 11 | Decode, 12 | Encode, 13 | }; 14 | 15 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 16 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 17 | pub enum Error { 18 | Custom(String), 19 | } 20 | 21 | 22 | 23 | #[openbrush::wrapper] 24 | pub type FunctionContractRef = dyn FunctionContract; 25 | 26 | #[openbrush::trait_definition] 27 | pub trait FunctionContract { 28 | #[ink(message)] 29 | fn change_owner(&mut self, new_owner: AccountId) -> Result<(), Error>; 30 | 31 | #[ink(message)] 32 | fn decrement(&mut self, i: u128) -> Result<(), Error>; 33 | 34 | /// Functions can return multiple values. 35 | #[ink(message)] 36 | fn return_many(&self) -> Result<(u128, bool, u128), Error>; 37 | 38 | /// Return values can be named. 39 | #[ink(message)] 40 | fn named(&self) -> Result<(u128, bool, u128), Error>; 41 | 42 | /// Return values can be assigned to their name. 43 | /// In this case the return statement can be omitted. 44 | #[ink(message)] 45 | fn assigned(&self) -> Result<(u128, bool, u128), Error>; 46 | 47 | /// Use destructuring assignment when calling another 48 | /// function that returns multiple values. 49 | #[ink(message)] 50 | fn destructuring_assignments(&self) -> Result<(u128, bool, u128, u128, u128), Error>; 51 | 52 | /// Values can be left out. 53 | /// Cannot use map for either input or output 54 | /// Can use array for input 55 | #[ink(message)] 56 | fn array_input(&mut self, arr: Vec) -> Result<(), Error>; 57 | 58 | #[ink(message)] 59 | fn array_output(&self) -> Result, Error>; 60 | 61 | /// Call function with key-value inputs 62 | #[ink(message)] 63 | fn some_func_with_many_inputs( 64 | &self, 65 | x: u128, 66 | y: u128, 67 | z: u128, 68 | a: AccountId, 69 | b: bool, 70 | c: String, 71 | ) -> Result; 72 | 73 | #[ink(message)] 74 | fn call_func(&self) -> Result; 75 | 76 | #[ink(message)] 77 | fn call_func_with_key_value(&self) -> Result; 78 | 79 | } 80 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/router_event_emitter.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::traits::AccountId; 5 | use scale::{ 6 | Decode, 7 | Encode, 8 | }; 9 | 10 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 11 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 12 | pub enum Error { 13 | Custom(String), 14 | } 15 | 16 | 17 | 18 | #[openbrush::wrapper] 19 | pub type RouterEventEmitterRef = dyn RouterEventEmitter; 20 | 21 | #[openbrush::trait_definition] 22 | pub trait RouterEventEmitter { 23 | #[ink(message)] 24 | fn swap_exact_tokens_for_tokens( 25 | &mut self, 26 | router: AccountId, 27 | amount_in: u128, 28 | amount_out_min: u128, 29 | path: Vec, 30 | to: AccountId, 31 | deadline: u128, 32 | ) -> Result<(), Error>; 33 | 34 | #[ink(message)] 35 | fn swap_tokens_for_exact_tokens( 36 | &mut self, 37 | router: AccountId, 38 | amount_out: u128, 39 | amount_in_max: u128, 40 | path: Vec, 41 | to: AccountId, 42 | deadline: u128, 43 | ) -> Result<(), Error>; 44 | 45 | #[ink(message, payable)] 46 | fn swap_exact_eth_for_tokens( 47 | &mut self, 48 | router: AccountId, 49 | amount_out_min: u128, 50 | path: Vec, 51 | to: AccountId, 52 | deadline: u128, 53 | ) -> Result<(), Error>; 54 | 55 | #[ink(message)] 56 | fn swap_tokens_for_exact_eth( 57 | &mut self, 58 | router: AccountId, 59 | amount_out: u128, 60 | amount_in_max: u128, 61 | path: Vec, 62 | to: AccountId, 63 | deadline: u128, 64 | ) -> Result<(), Error>; 65 | 66 | #[ink(message)] 67 | fn swap_exact_tokens_for_eth( 68 | &mut self, 69 | router: AccountId, 70 | amount_in: u128, 71 | amount_out_min: u128, 72 | path: Vec, 73 | to: AccountId, 74 | deadline: u128, 75 | ) -> Result<(), Error>; 76 | 77 | #[ink(message, payable)] 78 | fn swap_eth_for_exact_tokens( 79 | &mut self, 80 | router: AccountId, 81 | amount_out: u128, 82 | path: Vec, 83 | to: AccountId, 84 | deadline: u128, 85 | ) -> Result<(), Error>; 86 | 87 | } 88 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/UniswapV2Migrator.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.6; 2 | 3 | import '@uniswap/lib/contracts/libraries/TransferHelper.sol'; 4 | 5 | import './interfaces/IUniswapV2Migrator.sol'; 6 | import './interfaces/V1/IUniswapV1Factory.sol'; 7 | import './interfaces/V1/IUniswapV1Exchange.sol'; 8 | import './interfaces/IUniswapV2Router01.sol'; 9 | import './interfaces/IERC20.sol'; 10 | 11 | contract UniswapV2Migrator is IUniswapV2Migrator { 12 | IUniswapV1Factory immutable factoryV1; 13 | IUniswapV2Router01 immutable router; 14 | 15 | constructor(address _factoryV1, address _router) public { 16 | factoryV1 = IUniswapV1Factory(_factoryV1); 17 | router = IUniswapV2Router01(_router); 18 | } 19 | 20 | // needs to accept ETH from any v1 exchange and the router. ideally this could be enforced, as in the router, 21 | // but it's not possible because it requires a call to the v1 factory, which takes too much gas 22 | receive() external payable {} 23 | 24 | function migrate(address token, uint amountTokenMin, uint amountETHMin, address to, uint deadline) 25 | external 26 | override 27 | { 28 | IUniswapV1Exchange exchangeV1 = IUniswapV1Exchange(factoryV1.getExchange(token)); 29 | uint liquidityV1 = exchangeV1.balanceOf(msg.sender); 30 | require(exchangeV1.transferFrom(msg.sender, address(this), liquidityV1), 'TRANSFER_FROM_FAILED'); 31 | (uint amountETHV1, uint amountTokenV1) = exchangeV1.removeLiquidity(liquidityV1, 1, 1, uint(-1)); 32 | TransferHelper.safeApprove(token, address(router), amountTokenV1); 33 | (uint amountTokenV2, uint amountETHV2,) = router.addLiquidityETH{value: amountETHV1}( 34 | token, 35 | amountTokenV1, 36 | amountTokenMin, 37 | amountETHMin, 38 | to, 39 | deadline 40 | ); 41 | if (amountTokenV1 > amountTokenV2) { 42 | TransferHelper.safeApprove(token, address(router), 0); // be a good blockchain citizen, reset allowance to 0 43 | TransferHelper.safeTransfer(token, msg.sender, amountTokenV1 - amountTokenV2); 44 | } else if (amountETHV1 > amountETHV2) { 45 | // addLiquidityETH guarantees that all of amountETHV1 or amountTokenV1 will be used, hence this else is safe 46 | TransferHelper.safeTransferETH(msg.sender, amountETHV1 - amountETHV2); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/generated/src/impls/struct_contract.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use crate::{ 5 | impls, 6 | traits::*, 7 | }; 8 | use openbrush::traits::Storage; 9 | pub use openbrush::traits::{ 10 | AccountId, 11 | String, 12 | }; 13 | 14 | pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); 15 | 16 | #[derive(Default, Debug)] 17 | #[openbrush::upgradeable_storage(STORAGE_KEY)] 18 | pub struct Data { 19 | pub status: Status, 20 | pub todos: Vec, 21 | pub _reserved: Option<()>, 22 | } 23 | 24 | 25 | impl> StructContract for T { 26 | fn get(&self) -> Result { 27 | return Ok(self.data().status) 28 | } 29 | 30 | fn set(&mut self, status: Status) -> Result<(), Error> { 31 | self.data().status = status; 32 | Ok(()) 33 | } 34 | 35 | fn cancel(&mut self) -> Result<(), Error> { 36 | self.data().status = status.canceled; 37 | Ok(()) 38 | } 39 | 40 | fn reset(&mut self) -> Result<(), Error> { 41 | // Deletion of storage member 42 | Ok(()) 43 | } 44 | 45 | fn create_events(&mut self) -> Result<(), Error> { 46 | self._emit_log(Self::env().caller(), "log event", 9, accepted); 47 | self._emit_another_log(); 48 | Ok(()) 49 | } 50 | 51 | fn create_todo(&mut self, text: String, priority: u8, comment: String) -> Result<(), Error> { 52 | self.data() 53 | .todos 54 | .push(todo(text, false, priority, comment)?)?; 55 | self.data().todos.push(todo { 56 | text, 57 | completed: false, 58 | priority, 59 | comment, 60 | })?; 61 | todo.text = text; 62 | todo.priority = priority; 63 | todo.comment = comment; 64 | self.data().todos.push(todo)?; 65 | Ok(()) 66 | } 67 | 68 | fn status(&self) -> Status { 69 | self.data().status 70 | } 71 | 72 | fn todos(&self) -> Vec { 73 | self.data().todos 74 | } 75 | 76 | } 77 | 78 | pub trait Internal { 79 | fn _emit_log(&self, sender: AccountId, message: String, priority: u8, status: Status); 80 | 81 | fn _emit_another_log(&self); 82 | 83 | } 84 | 85 | impl> Internal for T { 86 | default fn _emit_log(&self, _: AccountId, _: String, _: u8, _: Status) {} 87 | 88 | default fn _emit_another_log(&self) {} 89 | 90 | } 91 | -------------------------------------------------------------------------------- /docs/src/css/custom.scss: -------------------------------------------------------------------------------- 1 | @import 'fonts'; 2 | @import 'icons'; 3 | @import 'layout'; 4 | @import 'code'; 5 | @import 'navbar'; 6 | @import 'themes'; 7 | 8 | :root { 9 | --ifm-code-border-radius: 0; 10 | --ifm-color-primary: #8c9640; 11 | --ifm-color-primary-dark: #b4be68; 12 | --ifm-color-primary-darker: #8c9640; 13 | --ifm-color-primary-darkest: #5a5f34; 14 | --ifm-color-primary-light: #c3cb86; 15 | --ifm-color-primary-lighter: #d2d8a4; 16 | --ifm-color-primary-lightest: #dadfb4; 17 | --ifm-code-font-size: 85%; 18 | --ifm-spacing-horizontal: 25px; 19 | --ifm-font-family-monospace: 'Sometype Mono'; 20 | --ifm-font-family-base: 'Sometype Mono'; 21 | --ifm-navbar-height: 60px; 22 | --ifm-menu-link-padding-horizontal: 20px; 23 | --ifm-font-size-base: 95%; 24 | --ifm-navbar-shadow: none; 25 | } 26 | 27 | html[data-theme='light'] { 28 | --ifm-font-color-base: #333; 29 | } 30 | 31 | html[data-theme='dark'] { 32 | --ifm-background-color: #121516; 33 | --ifm-toc-border-color: #43494d; 34 | --ifm-navbar-background-color: #121516; 35 | --ifm-footer-background-color: #121516; 36 | --ifm-color-primary: #d2d8a4; 37 | --ifm-link-color: #d2d8a4; 38 | --ifm-menu-color-active: #dadfb4; 39 | --ifm-navbar-link-hover-color: #d2d8a4; 40 | } 41 | 42 | html[data-theme='light'] { 43 | --ifm-color-primary: var(--ifm-color-primary-darker); 44 | --ifm-footer-background-color: #fafafa; 45 | } 46 | 47 | .table-of-contents li { 48 | position: relative; 49 | } 50 | 51 | .table-of-contents__link--active { 52 | font-weight: 500; 53 | } 54 | 55 | .table-of-contents__left-border { 56 | border-left-width: 2px; 57 | } 58 | 59 | .pagination-nav__link { 60 | border-radius: 0; 61 | border-width: 2px; 62 | } 63 | 64 | [class^='docItemContainer'] { 65 | padding-top: 2rem; 66 | } 67 | 68 | .menu.thin-scrollbar { 69 | padding-bottom: 20px; 70 | } 71 | 72 | a.menu__link { 73 | position: relative 74 | } 75 | 76 | a.menu__link.menu__link--active:before { 77 | content: ''; 78 | display: block; 79 | background: var(--ifm-color-primary); 80 | width: 6px; 81 | height: 6px; 82 | border-radius: 50%; 83 | position: absolute; 84 | transform: translateY(-50%); 85 | top: 50%; 86 | left: 6px; 87 | } 88 | 89 | .table-of-contents { 90 | font-size: 0.85rem; 91 | position: relative; 92 | } 93 | 94 | html button { 95 | font-family: inherit; 96 | } 97 | 98 | [class*='backToTopButton'] { 99 | display: none !important; 100 | } -------------------------------------------------------------------------------- /tests/file_change_tests.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fs, 3 | process::Command, 4 | }; 5 | 6 | macro_rules! contract_file { 7 | ($origin:expr,$mod_name:expr,$file_name:expr) => { 8 | fs::read_to_string(format!( 9 | "{}/generated/contracts/{}/{}", 10 | $origin, $mod_name, $file_name 11 | )) 12 | .unwrap_or_else(|err| panic!("{err:?}")) 13 | }; 14 | } 15 | 16 | macro_rules! test_file { 17 | ($origin:expr,$mod_name:expr,$file_name:expr) => { 18 | fs::read_to_string(format!( 19 | "{}/generated/src/{}/{}", 20 | $origin, $mod_name, $file_name 21 | )) 22 | .unwrap_or_else(|err| panic!("{err:?}")) 23 | }; 24 | } 25 | 26 | macro_rules! test_case_contract { 27 | ($folder_name:expr,$mod_name:expr) => { 28 | let contract_cargo = contract_file!("tests", $mod_name, "Cargo.toml"); 29 | let contract_lib = contract_file!("tests", $mod_name, "lib.rs"); 30 | 31 | let impl_file = test_file!("tests", "impls", format!("{}.rs", $mod_name)); 32 | let trait_file = test_file!("tests", "traits", format!("{}.rs", $mod_name)); 33 | 34 | assert_eq!( 35 | contract_cargo, 36 | contract_file!("examples", $mod_name, "Cargo.toml") 37 | ); 38 | assert_eq!( 39 | contract_lib, 40 | contract_file!("examples", $mod_name, "lib.rs") 41 | ); 42 | 43 | assert_eq!( 44 | impl_file, 45 | test_file!("examples", "impls", format!("{}.rs", $mod_name)) 46 | ); 47 | assert_eq!( 48 | trait_file, 49 | test_file!("examples", "traits", format!("{}.rs", $mod_name)) 50 | ); 51 | }; 52 | } 53 | 54 | #[test] 55 | fn examples_not_changed() { 56 | Command::new("cargo") 57 | .args(["+nightly", "run", "examples"]) 58 | .output() 59 | .expect("failed to execute process"); 60 | 61 | test_case_contract!("ERC20", "erc_20"); 62 | test_case_contract!("ERC721", "erc_721"); 63 | test_case_contract!("ERC1155", "erc_1155"); 64 | test_case_contract!("AccessControl", "access_control"); 65 | test_case_contract!("example", "example"); 66 | test_case_contract!("flipper", "flipper"); 67 | test_case_contract!("Primitives", "primitives"); 68 | test_case_contract!("ArrayContract", "array_contract"); 69 | test_case_contract!("CommentContract", "comment_contract"); 70 | test_case_contract!("FunctionContract", "function_contract"); 71 | test_case_contract!("StructContract", "struct_contract"); 72 | } 73 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/erc_20/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod erc_20 { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | pub const NAME: String = "Test Token"; 17 | pub const SYMBOL: String = "TT"; 18 | pub const DECIMALS: u8 = 18; 19 | /// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); 20 | pub const PERMIT_TYPEHASH: [u8; 32] = 21 | &hex::decode("0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9"); 22 | 23 | #[ink(event)] 24 | pub struct Approval { 25 | #[ink(topic)] 26 | owner: AccountId, 27 | #[ink(topic)] 28 | spender: AccountId, 29 | value: u128, 30 | } 31 | 32 | #[ink(event)] 33 | pub struct Transfer { 34 | #[ink(topic)] 35 | from: AccountId, 36 | #[ink(topic)] 37 | to: AccountId, 38 | value: u128, 39 | } 40 | 41 | #[ink(storage)] 42 | #[derive(Default, Storage)] 43 | pub struct ERC20Contract { 44 | #[storage_field] 45 | data: impls::Data, 46 | } 47 | 48 | impl ERC20 for ERC20Contract {} 49 | impl generated::impls::erc_20::Internal for ERC20Contract { 50 | 51 | fn _emit_approval(&self, owner: AccountId, spender: AccountId, value: u128) { 52 | self.env().emit_event(Approval { 53 | owner, 54 | spender, 55 | value, 56 | }); 57 | } 58 | 59 | fn _emit_transfer(&self, from: AccountId, to: AccountId, value: u128) { 60 | self.env().emit_event(Transfer { from, to, value }); 61 | } 62 | 63 | } 64 | 65 | impl ERC20Contract { 66 | #[ink(constructor)] 67 | pub fn new(total_supply: u128) -> Self { 68 | let mut instance = Self::default(); 69 | __comment__!("Assembly block here. Parsing assembly is not implemented yet"); 70 | instance . data . domain_separator = keccak_256 (abi . encode (keccak_256 ("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)") ? , keccak_256 (Vec :: < u8 > :: from (NAME)) ? , keccak_256 (Vec :: < u8 > :: from ("1")) ? , chain_id , instance . env () . account_id ()) ?) ? ; 71 | instance._mint(instance.env().caller(), total_supply)?; 72 | instance 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/core/interfaces/IUniswapV2Pair.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Pair { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external pure returns (string memory); 8 | function symbol() external pure returns (string memory); 9 | function decimals() external pure returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | 18 | function DOMAIN_SEPARATOR() external view returns (bytes32); 19 | function PERMIT_TYPEHASH() external pure returns (bytes32); 20 | function nonces(address owner) external view returns (uint); 21 | 22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 23 | 24 | event Mint(address indexed sender, uint amount0, uint amount1); 25 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 26 | event Swap( 27 | address indexed sender, 28 | uint amount0In, 29 | uint amount1In, 30 | uint amount0Out, 31 | uint amount1Out, 32 | address indexed to 33 | ); 34 | event Sync(uint112 reserve0, uint112 reserve1); 35 | 36 | function MINIMUM_LIQUIDITY() external pure returns (uint); 37 | function factory() external view returns (address); 38 | function token0() external view returns (address); 39 | function token1() external view returns (address); 40 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 41 | function price0CumulativeLast() external view returns (uint); 42 | function price1CumulativeLast() external view returns (uint); 43 | function kLast() external view returns (uint); 44 | 45 | function mint(address to) external returns (uint liquidity); 46 | function burn(address to) external returns (uint amount0, uint amount1); 47 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 48 | function skim(address to) external; 49 | function sync() external; 50 | 51 | function initialize(address, address) external; 52 | } 53 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/uniswap_v_2_erc_20/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod uniswap_v_2_erc_20 { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | pub const NAME: String = "Uniswap V2"; 17 | pub const SYMBOL: String = "UNI-V2"; 18 | pub const DECIMALS: u8 = 18; 19 | /// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); 20 | pub const PERMIT_TYPEHASH: [u8; 32] = 21 | &hex::decode("0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9"); 22 | 23 | #[ink(event)] 24 | pub struct Approval { 25 | #[ink(topic)] 26 | owner: AccountId, 27 | #[ink(topic)] 28 | spender: AccountId, 29 | value: u128, 30 | } 31 | 32 | #[ink(event)] 33 | pub struct Transfer { 34 | #[ink(topic)] 35 | from: AccountId, 36 | #[ink(topic)] 37 | to: AccountId, 38 | value: u128, 39 | } 40 | 41 | #[ink(storage)] 42 | #[derive(Default, Storage)] 43 | pub struct UniswapV2ERC20Contract { 44 | #[storage_field] 45 | data: impls::Data, 46 | } 47 | 48 | impl UniswapV2ERC20 for UniswapV2ERC20Contract {} 49 | impl generated::impls::uniswap_v_2_erc_20::Internal for UniswapV2ERC20Contract { 50 | 51 | fn _emit_approval(&self, owner: AccountId, spender: AccountId, value: u128) { 52 | self.env().emit_event(Approval { 53 | owner, 54 | spender, 55 | value, 56 | }); 57 | } 58 | 59 | fn _emit_transfer(&self, from: AccountId, to: AccountId, value: u128) { 60 | self.env().emit_event(Transfer { from, to, value }); 61 | } 62 | 63 | } 64 | 65 | impl IUniswapV2ERC20 for UniswapV2ERC20Contract {} 66 | 67 | impl UniswapV2ERC20Contract { 68 | #[ink(constructor)] 69 | pub fn new() -> Self { 70 | let mut instance = Self::default(); 71 | __comment__!("Assembly block here. Parsing assembly is not implemented yet"); 72 | instance . data . domain_separator = keccak_256 (abi . encode (keccak_256 ("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)") ? , keccak_256 (Vec :: < u8 > :: from (NAME)) ? , keccak_256 (Vec :: < u8 > :: from ("1")) ? , chain_id , instance . env () . account_id ()) ?) ? ; 73 | instance 74 | } 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /uniwap_v2/generated/contracts/deflating_erc_20/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | #[openbrush::contract] 8 | pub mod deflating_erc_20 { 9 | use generated::*; 10 | use ink::lang::codegen::{ 11 | EmitEvent, 12 | Env, 13 | }; 14 | use openbrush::traits::Storage; 15 | 16 | pub const NAME: String = "Deflating Test Token"; 17 | pub const SYMBOL: String = "DTT"; 18 | pub const DECIMALS: u8 = 18; 19 | /// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); 20 | pub const PERMIT_TYPEHASH: [u8; 32] = 21 | &hex::decode("0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9"); 22 | 23 | #[ink(event)] 24 | pub struct Approval { 25 | #[ink(topic)] 26 | owner: AccountId, 27 | #[ink(topic)] 28 | spender: AccountId, 29 | value: u128, 30 | } 31 | 32 | #[ink(event)] 33 | pub struct Transfer { 34 | #[ink(topic)] 35 | from: AccountId, 36 | #[ink(topic)] 37 | to: AccountId, 38 | value: u128, 39 | } 40 | 41 | #[ink(storage)] 42 | #[derive(Default, Storage)] 43 | pub struct DeflatingERC20Contract { 44 | #[storage_field] 45 | data: impls::Data, 46 | } 47 | 48 | impl DeflatingERC20 for DeflatingERC20Contract {} 49 | impl generated::impls::deflating_erc_20::Internal for DeflatingERC20Contract { 50 | 51 | fn _emit_approval(&self, owner: AccountId, spender: AccountId, value: u128) { 52 | self.env().emit_event(Approval { 53 | owner, 54 | spender, 55 | value, 56 | }); 57 | } 58 | 59 | fn _emit_transfer(&self, from: AccountId, to: AccountId, value: u128) { 60 | self.env().emit_event(Transfer { from, to, value }); 61 | } 62 | 63 | } 64 | 65 | impl DeflatingERC20Contract { 66 | #[ink(constructor)] 67 | pub fn new(total_supply: u128) -> Self { 68 | let mut instance = Self::default(); 69 | __comment__!("Assembly block here. Parsing assembly is not implemented yet"); 70 | instance . data . domain_separator = keccak_256 (abi . encode (keccak_256 ("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)") ? , keccak_256 (Vec :: < u8 > :: from (NAME)) ? , keccak_256 (Vec :: < u8 > :: from ("1")) ? , chain_id , instance . env () . account_id ()) ?) ? ; 71 | instance._mint(instance.env().caller(), total_supply)?; 72 | instance 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/impls/uniswap_v_2_migrator.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use crate::{ 5 | impls, 6 | traits::*, 7 | }; 8 | pub use openbrush::traits::AccountId; 9 | use openbrush::traits::Storage; 10 | 11 | pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); 12 | 13 | #[derive(Default, Debug)] 14 | #[openbrush::upgradeable_storage(STORAGE_KEY)] 15 | pub struct Data { 16 | pub factory_v_1: IUniswapV1Factory, 17 | pub router: IUniswapV2Router01, 18 | pub _reserved: Option<()>, 19 | } 20 | 21 | 22 | impl> UniswapV2Migrator for T { 23 | fn migrate( 24 | &mut self, 25 | token: AccountId, 26 | amount_token_min: u128, 27 | amount_eth_min: u128, 28 | to: AccountId, 29 | deadline: u128, 30 | ) -> Result<(), Error> { 31 | let mut exchange_v_1: IUniswapV1Exchange = 32 | i_uniswap_v_1_exchange(self.data().factory_v_1.get_exchange(token)?)?; 33 | let mut liquidity_v_1: u128 = exchange_v_1.balance_of(Self::env().caller())?; 34 | if !(exchange_v_1.transfer_from( 35 | Self::env().caller(), 36 | Self::env().account_id(), 37 | liquidity_v_1, 38 | )?) { 39 | return Err(Error::Custom(String::from("TRANSFER_FROM_FAILED"))) 40 | }; 41 | (amount_ethv_1, amount_token_v_1) = 42 | exchange_v_1.remove_liquidity(liquidity_v_1, 1, 1, ::from(-1))?; 43 | transfer_helper.safe_approve( 44 | token, 45 | AccountId::from(self.data().router), 46 | amount_token_v_1, 47 | )?; 48 | (amount_token_v_2, amount_ethv_2, _) = self 49 | .data() 50 | .router 51 | .add_liquidity_eth( 52 | token, 53 | amount_token_v_1, 54 | amount_token_min, 55 | amount_eth_min, 56 | to, 57 | deadline, 58 | ) 59 | .transferred_value(amount_ethv_1)?; 60 | if amount_token_v_1 > amount_token_v_2 { 61 | transfer_helper.safe_approve(token, AccountId::from(self.data().router), 0)?; 62 | transfer_helper.safe_transfer( 63 | token, 64 | Self::env().caller(), 65 | amount_token_v_1 - amount_token_v_2, 66 | )?; 67 | } else if amount_ethv_1 > amount_ethv_2 { 68 | transfer_helper 69 | .safe_transfer_eth(Self::env().caller(), amount_ethv_1 - amount_ethv_2)?; 70 | } 71 | Ok(()) 72 | } 73 | 74 | } 75 | 76 | pub trait Internal {} 77 | 78 | impl> Internal for T {} 79 | -------------------------------------------------------------------------------- /tests/generated/src/traits/stable_swap.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::AccountId, 7 | }; 8 | use scale::{ 9 | Decode, 10 | Encode, 11 | }; 12 | 13 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 14 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 15 | pub enum Error { 16 | Custom(String), 17 | } 18 | 19 | 20 | 21 | #[openbrush::wrapper] 22 | pub type StableSwapRef = dyn StableSwap; 23 | 24 | #[openbrush::trait_definition] 25 | pub trait StableSwap { 26 | /// Newton's method 27 | /// Initial guess, y <= d 28 | /// Estimate value of 1 share 29 | /// How many tokens is one share worth? 30 | #[ink(message)] 31 | fn get_virtual_price(&self) -> Result; 32 | 33 | /// @notice Swap dx amount of token i for token j 34 | /// @param i Index of token in 35 | /// @param j Index of token out 36 | /// @param dx Token in amount 37 | /// @param minDy Minimum token out 38 | #[ink(message)] 39 | fn swap(&mut self, i: u128, j: u128, dx: u128, min_dy: u128) -> Result; 40 | 41 | /// Calculate dy 42 | /// y0 must be >= y1, since x has increased 43 | /// -1 to round down 44 | /// Subtract fee from dy 45 | #[ink(message)] 46 | fn add_liquidity(&mut self, amounts: Vec, min_shares: u128) -> Result; 47 | 48 | /// calculate current liquidity d0 49 | /// Transfer tokens in 50 | /// Calculate new liquidity d1 51 | /// Reccalcuate D accounting for fee on imbalance 52 | /// why old_xs[i] * d1 / d0? why not d1 / N? 53 | /// Update balances 54 | /// Shares to mint = (d2 - d0) / d0 * total supply 55 | /// d1 >= d2 >= d0 56 | #[ink(message)] 57 | fn remove_liquidity( 58 | &mut self, 59 | shares: u128, 60 | min_amounts_out: Vec, 61 | ) -> Result, Error>; 62 | 63 | /// Calculate d0 and d1 64 | /// Calculate reduction in y if D = d1 65 | /// d1 <= d0 so y must be <= xp[i] 66 | /// Calculate imbalance fee, update xp with fees 67 | /// d1 / d0 <= 1 68 | /// Recalculate y with xp including imbalance fees 69 | /// - 1 to round down 70 | #[ink(message)] 71 | fn calc_withdraw_one_token(&self, shares: u128, i: u128) -> Result<(u128, u128), Error>; 72 | 73 | /// @notice Withdraw liquidity in token i 74 | /// @param shares Shares to burn 75 | /// @param i Token to withdraw 76 | /// @param minAmountOut Minimum amount of token i that must be withdrawn 77 | #[ink(message)] 78 | fn remove_liquidity_one_token( 79 | &mut self, 80 | shares: u128, 81 | i: u128, 82 | min_amount_out: u128, 83 | ) -> Result; 84 | 85 | } 86 | -------------------------------------------------------------------------------- /uniwap_v2/generated/src/traits/uniswap_v_2_pair.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::traits::{ 6 | AccountId, 7 | AccountIdExt, 8 | ZERO_ADDRESS, 9 | }; 10 | use scale::{ 11 | Decode, 12 | Encode, 13 | }; 14 | 15 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 16 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 17 | pub enum Error { 18 | Custom(String), 19 | } 20 | 21 | 22 | 23 | #[openbrush::wrapper] 24 | pub type UniswapV2PairRef = dyn UniswapV2Pair; 25 | 26 | #[openbrush::trait_definition] 27 | pub trait UniswapV2Pair { 28 | #[ink(message)] 29 | fn get_reserves(&self) -> Result<(u128, u128, u32), Error>; 30 | 31 | /// called once by the factory at time of deployment 32 | #[ink(message)] 33 | fn initialize(&mut self, token_0: AccountId, token_1: AccountId) -> Result<(), Error>; 34 | 35 | /// gas savings 36 | /// this low-level function should be called from a contract which performs important safety checks 37 | #[ink(message)] 38 | fn mint(&mut self, to: AccountId) -> Result; 39 | 40 | /// gas savings 41 | /// gas savings, must be defined here since totalSupply can update in _mintFee 42 | /// permanently lock the first MINIMUM_LIQUIDITY tokens 43 | /// reserve0 and reserve1 are up-to-date 44 | /// this low-level function should be called from a contract which performs important safety checks 45 | #[ink(message)] 46 | fn burn(&mut self, to: AccountId) -> Result<(u128, u128), Error>; 47 | 48 | /// gas savings 49 | /// gas savings 50 | /// gas savings 51 | /// gas savings, must be defined here since totalSupply can update in _mintFee 52 | /// using balances ensures pro-rata distribution 53 | /// using balances ensures pro-rata distribution 54 | /// reserve0 and reserve1 are up-to-date 55 | /// this low-level function should be called from a contract which performs important safety checks 56 | #[ink(message)] 57 | fn swap( 58 | &mut self, 59 | amount_0_out: u128, 60 | amount_1_out: u128, 61 | to: AccountId, 62 | data: Vec, 63 | ) -> Result<(), Error>; 64 | 65 | /// gas savings 66 | /// scope for _token{0,1}, avoids stack too deep errors 67 | /// optimistically transfer tokens 68 | /// optimistically transfer tokens 69 | /// scope for reserve{0,1}Adjusted, avoids stack too deep errors 70 | /// force balances to match reserves 71 | #[ink(message)] 72 | fn skim(&mut self, to: AccountId) -> Result<(), Error>; 73 | 74 | /// gas savings 75 | /// gas savings 76 | /// force reserves to match balances 77 | #[ink(message)] 78 | fn sync(&mut self) -> Result<(), Error>; 79 | 80 | } 81 | -------------------------------------------------------------------------------- /uniwap_v2/solidity/periphery/examples/ExampleComputeLiquidityValue.sol: -------------------------------------------------------------------------------- 1 | pragma solidity =0.6.6; 2 | 3 | import '../libraries/UniswapV2LiquidityMathLibrary.sol'; 4 | 5 | contract ExampleComputeLiquidityValue { 6 | using SafeMath for uint256; 7 | 8 | address public immutable factory; 9 | 10 | constructor(address factory_) public { 11 | factory = factory_; 12 | } 13 | 14 | // see UniswapV2LiquidityMathLibrary#getReservesAfterArbitrage 15 | function getReservesAfterArbitrage( 16 | address tokenA, 17 | address tokenB, 18 | uint256 truePriceTokenA, 19 | uint256 truePriceTokenB 20 | ) external view returns (uint256 reserveA, uint256 reserveB) { 21 | return UniswapV2LiquidityMathLibrary.getReservesAfterArbitrage( 22 | factory, 23 | tokenA, 24 | tokenB, 25 | truePriceTokenA, 26 | truePriceTokenB 27 | ); 28 | } 29 | 30 | // see UniswapV2LiquidityMathLibrary#getLiquidityValue 31 | function getLiquidityValue( 32 | address tokenA, 33 | address tokenB, 34 | uint256 liquidityAmount 35 | ) external view returns ( 36 | uint256 tokenAAmount, 37 | uint256 tokenBAmount 38 | ) { 39 | return UniswapV2LiquidityMathLibrary.getLiquidityValue( 40 | factory, 41 | tokenA, 42 | tokenB, 43 | liquidityAmount 44 | ); 45 | } 46 | 47 | // see UniswapV2LiquidityMathLibrary#getLiquidityValueAfterArbitrageToPrice 48 | function getLiquidityValueAfterArbitrageToPrice( 49 | address tokenA, 50 | address tokenB, 51 | uint256 truePriceTokenA, 52 | uint256 truePriceTokenB, 53 | uint256 liquidityAmount 54 | ) external view returns ( 55 | uint256 tokenAAmount, 56 | uint256 tokenBAmount 57 | ) { 58 | return UniswapV2LiquidityMathLibrary.getLiquidityValueAfterArbitrageToPrice( 59 | factory, 60 | tokenA, 61 | tokenB, 62 | truePriceTokenA, 63 | truePriceTokenB, 64 | liquidityAmount 65 | ); 66 | } 67 | 68 | // test function to measure the gas cost of the above function 69 | function getGasCostOfGetLiquidityValueAfterArbitrageToPrice( 70 | address tokenA, 71 | address tokenB, 72 | uint256 truePriceTokenA, 73 | uint256 truePriceTokenB, 74 | uint256 liquidityAmount 75 | ) external view returns ( 76 | uint256 77 | ) { 78 | uint gasBefore = gasleft(); 79 | UniswapV2LiquidityMathLibrary.getLiquidityValueAfterArbitrageToPrice( 80 | factory, 81 | tokenA, 82 | tokenB, 83 | truePriceTokenA, 84 | truePriceTokenB, 85 | liquidityAmount 86 | ); 87 | uint gasAfter = gasleft(); 88 | return gasBefore - gasAfter; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/generated/contracts/access_control/lib.rs: -------------------------------------------------------------------------------- 1 | #![cfg_attr(not(feature = "std"), no_std)] 2 | #![feature(min_specialization)] 3 | 4 | // Generated with Sol2Ink v2.1.0 5 | // https://github.com/Brushfam/sol2ink 6 | 7 | /// SPDX-License-Identifier: MIT 8 | /// OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) 9 | /// @dev Contract module that allows children to implement role-based access 10 | /// control mechanisms. This is a lightweight version that doesn't allow enumerating role 11 | /// members except through off-chain means by accessing the contract event logs. Some 12 | /// applications may benefit from on-chain enumerability, for those cases see 13 | /// {AccessControlEnumerable}. 14 | /// 15 | /// Roles are referred to by their `bytes32` identifier. These should be exposed 16 | /// in the external API and be unique. The best way to achieve this is by 17 | /// using `public constant` hash digests: 18 | /// 19 | /// ```solidity 20 | /// bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); 21 | /// ``` 22 | /// 23 | /// Roles can be used to represent a set of permissions. To restrict access to a 24 | /// function call, use {hasRole}: 25 | /// 26 | /// ```solidity 27 | /// function foo() public { 28 | /// require(hasRole(MY_ROLE, msg.sender)); 29 | /// ... 30 | /// } 31 | /// ``` 32 | /// 33 | /// Roles can be granted and revoked dynamically via the {grantRole} and 34 | /// {revokeRole} functions. Each role has an associated admin role, and only 35 | /// accounts that have a role's admin role can call {grantRole} and {revokeRole}. 36 | /// 37 | /// By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means 38 | /// that only accounts with this role will be able to grant or revoke other 39 | /// roles. More complex role relationships can be created by using 40 | /// {_setRoleAdmin}. 41 | /// 42 | /// WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to 43 | /// grant and revoke this role. Extra precautions should be taken to secure 44 | /// accounts that have been granted it. 45 | #[openbrush::contract] 46 | pub mod access_control { 47 | use generated::*; 48 | use ink::lang::codegen::{ 49 | EmitEvent, 50 | Env, 51 | }; 52 | use openbrush::traits::Storage; 53 | 54 | pub const DEFAULT_ADMIN_ROLE: [u8; 32] = &hex::decode("0x00"); 55 | 56 | #[ink(storage)] 57 | #[derive(Default, Storage)] 58 | pub struct AccessControlContract { 59 | #[storage_field] 60 | data: impls::Data, 61 | } 62 | 63 | impl AccessControl for AccessControlContract {} 64 | 65 | impl Context for AccessControlContract {} 66 | 67 | impl IAccessControl for AccessControlContract {} 68 | 69 | impl ERC165 for AccessControlContract {} 70 | 71 | impl AccessControlContract { 72 | #[ink(constructor)] 73 | pub fn new() -> Self { 74 | let mut instance = Self::default(); 75 | instance 76 | } 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /tests/generated/src/traits/erc_1155.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::{ 6 | storage::Mapping, 7 | traits::{ 8 | AccountId, 9 | AccountIdExt, 10 | String, 11 | ZERO_ADDRESS, 12 | }, 13 | }; 14 | use scale::{ 15 | Decode, 16 | Encode, 17 | }; 18 | 19 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 20 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 21 | pub enum Error { 22 | Custom(String), 23 | } 24 | 25 | 26 | 27 | #[openbrush::wrapper] 28 | pub type ERC1155Ref = dyn ERC1155; 29 | 30 | #[openbrush::trait_definition] 31 | pub trait ERC1155 { 32 | /// @dev See {IERC165-supportsInterface}. 33 | #[ink(message)] 34 | fn supports_interface(&self, interface_id: [u8; 4]) -> Result; 35 | 36 | /// @dev See {IERC1155MetadataURI-uri}. 37 | /// 38 | /// This implementation returns the same URI for *all* token types. It relies 39 | /// on the token type ID substitution mechanism 40 | /// https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. 41 | /// 42 | /// Clients calling this function must replace the `\{id\}` substring with the 43 | /// actual token type ID. 44 | #[ink(message)] 45 | fn uri(&self, _: u128) -> Result; 46 | 47 | /// @dev See {IERC1155-balanceOf}. 48 | /// 49 | /// Requirements: 50 | /// 51 | /// - `account` cannot be the zero address. 52 | #[ink(message)] 53 | fn balance_of(&self, account: AccountId, id: u128) -> Result; 54 | 55 | /// @dev See {IERC1155-balanceOfBatch}. 56 | /// 57 | /// Requirements: 58 | /// 59 | /// - `accounts` and `ids` must have the same length. 60 | #[ink(message)] 61 | fn balance_of_batch( 62 | &self, 63 | accounts: Vec, 64 | ids: Vec, 65 | ) -> Result, Error>; 66 | 67 | /// @dev See {IERC1155-setApprovalForAll}. 68 | #[ink(message)] 69 | fn set_approval_for_all(&mut self, operator: AccountId, approved: bool) -> Result<(), Error>; 70 | 71 | /// @dev See {IERC1155-isApprovedForAll}. 72 | #[ink(message)] 73 | fn is_approved_for_all(&self, account: AccountId, operator: AccountId) -> Result; 74 | 75 | /// @dev See {IERC1155-safeTransferFrom}. 76 | #[ink(message)] 77 | fn safe_transfer_from( 78 | &mut self, 79 | from: AccountId, 80 | to: AccountId, 81 | id: u128, 82 | amount: u128, 83 | data: Vec, 84 | ) -> Result<(), Error>; 85 | 86 | /// @dev See {IERC1155-safeBatchTransferFrom}. 87 | #[ink(message)] 88 | fn safe_batch_transfer_from( 89 | &mut self, 90 | from: AccountId, 91 | to: AccountId, 92 | ids: Vec, 93 | amounts: Vec, 94 | data: Vec, 95 | ) -> Result<(), Error>; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /tests/generated/src/traits/access_control.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use openbrush::{ 5 | storage::Mapping, 6 | traits::AccountId, 7 | }; 8 | use scale::{ 9 | Decode, 10 | Encode, 11 | }; 12 | 13 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 14 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 15 | pub enum Error { 16 | Custom(String), 17 | } 18 | 19 | 20 | #[derive(Default, Encode, Decode)] 21 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 22 | pub struct RoleData { 23 | members: Mapping, 24 | admin_role: [u8; 32], 25 | } 26 | 27 | 28 | #[openbrush::wrapper] 29 | pub type AccessControlRef = dyn AccessControl; 30 | 31 | #[openbrush::trait_definition] 32 | pub trait AccessControl { 33 | /// @dev See {IERC165-supportsInterface}. 34 | #[ink(message)] 35 | fn supports_interface(&self, interface_id: [u8; 4]) -> Result; 36 | 37 | /// @dev Returns `true` if `account` has been granted `role`. 38 | #[ink(message)] 39 | fn has_role(&self, role: [u8; 32], account: AccountId) -> Result; 40 | 41 | /// @dev Returns the admin role that controls `role`. See {grantRole} and 42 | /// {revokeRole}. 43 | /// 44 | /// To change a role's admin, use {_setRoleAdmin}. 45 | #[ink(message)] 46 | fn get_role_admin(&self, role: [u8; 32]) -> Result<[u8; 32], Error>; 47 | 48 | /// @dev Grants `role` to `account`. 49 | /// 50 | /// If `account` had not been already granted `role`, emits a {RoleGranted} 51 | /// event. 52 | /// 53 | /// Requirements: 54 | /// 55 | /// - the caller must have ``role``'s admin role. 56 | /// 57 | /// May emit a {RoleGranted} event. 58 | #[ink(message)] 59 | fn grant_role(&mut self, role: [u8; 32], account: AccountId) -> Result<(), Error>; 60 | 61 | /// @dev Revokes `role` from `account`. 62 | /// 63 | /// If `account` had been granted `role`, emits a {RoleRevoked} event. 64 | /// 65 | /// Requirements: 66 | /// 67 | /// - the caller must have ``role``'s admin role. 68 | /// 69 | /// May emit a {RoleRevoked} event. 70 | #[ink(message)] 71 | fn revoke_role(&mut self, role: [u8; 32], account: AccountId) -> Result<(), Error>; 72 | 73 | /// @dev Revokes `role` from the calling account. 74 | /// 75 | /// Roles are often managed via {grantRole} and {revokeRole}: this function's 76 | /// purpose is to provide a mechanism for accounts to lose their privileges 77 | /// if they are compromised (such as when a trusted device is misplaced). 78 | /// 79 | /// If the calling account had been revoked `role`, emits a {RoleRevoked} 80 | /// event. 81 | /// 82 | /// Requirements: 83 | /// 84 | /// - the caller must be `account`. 85 | /// 86 | /// May emit a {RoleRevoked} event. 87 | #[ink(message)] 88 | fn renounce_role(&mut self, role: [u8; 32], account: AccountId) -> Result<(), Error>; 89 | 90 | } 91 | -------------------------------------------------------------------------------- /examples/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) 3 | 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev Interface of the ERC20 standard as defined in the EIP. 8 | */ 9 | interface IERC20 { 10 | /** 11 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 12 | * another (`to`). 13 | * 14 | * Note that `value` may be zero. 15 | */ 16 | event Transfer(address indexed from, address indexed to, uint256 value); 17 | 18 | /** 19 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 20 | * a call to {approve}. `value` is the new allowance. 21 | */ 22 | event Approval(address indexed owner, address indexed spender, uint256 value); 23 | 24 | /** 25 | * @dev Returns the amount of tokens in existence. 26 | */ 27 | function totalSupply() external view returns (uint256); 28 | 29 | /** 30 | * @dev Returns the amount of tokens owned by `account`. 31 | */ 32 | function balanceOf(address account) external view returns (uint256); 33 | 34 | /** 35 | * @dev Moves `amount` tokens from the caller's account to `to`. 36 | * 37 | * Returns a boolean value indicating whether the operation succeeded. 38 | * 39 | * Emits a {Transfer} event. 40 | */ 41 | function transfer(address to, uint256 amount) external returns (bool); 42 | 43 | /** 44 | * @dev Returns the remaining number of tokens that `spender` will be 45 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 46 | * zero by default. 47 | * 48 | * This value changes when {approve} or {transferFrom} are called. 49 | */ 50 | function allowance(address owner, address spender) external view returns (uint256); 51 | 52 | /** 53 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 54 | * 55 | * Returns a boolean value indicating whether the operation succeeded. 56 | * 57 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 58 | * that someone may use both the old and the new allowance by unfortunate 59 | * transaction ordering. One possible solution to mitigate this race 60 | * condition is to first reduce the spender's allowance to 0 and set the 61 | * desired value afterwards: 62 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 63 | * 64 | * Emits an {Approval} event. 65 | */ 66 | function approve(address spender, uint256 amount) external returns (bool); 67 | 68 | /** 69 | * @dev Moves `amount` tokens from `from` to `to` using the 70 | * allowance mechanism. `amount` is then deducted from the caller's 71 | * allowance. 72 | * 73 | * Returns a boolean value indicating whether the operation succeeded. 74 | * 75 | * Emits a {Transfer} event. 76 | */ 77 | function transferFrom(address from, address to, uint256 amount) external returns (bool); 78 | } -------------------------------------------------------------------------------- /examples/CommentContract.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.8.0; 2 | 3 | contract CommentContract { 4 | enum Status { 5 | // pending comment1 6 | // pending comment2 7 | Pending, 8 | Shipped, /* shipped comment1 9 | shipped comment2 10 | */ 11 | Accepted, 12 | Rejected, /* rejected comment */ 13 | /* canceled comment1 */ 14 | Canceled // canceled comment2 15 | } 16 | 17 | Status public status; 18 | 19 | event Log(address indexed sender, /* sender comment */ string message, // message comment 20 | /* priority comment1 */ uint8 priority, /* priority comment2 */ Status status); 21 | 22 | struct RoleData1 { 23 | /** 24 | * MULTILINE_COMMENT::members 25 | */ 26 | mapping(address => bool) members; // COMMENT::members 27 | //COMMENT::adminRole 28 | bytes32 adminRole; /** 29 | 30 | * MULTILINE_COMMENT::adminRole 31 | */ 32 | } 33 | 34 | struct RoleData2 { 35 | /** 36 | * 37 | MULTILINE_COMMENT::members */ 38 | mapping(address => bool) members; // COMMENT::members 39 | bytes32 adminRole; 40 | // COMMENT::adminRole 41 | } 42 | 43 | struct RoleData3 { 44 | // COMMENT::members 45 | mapping(address => bool) members; 46 | bytes32 adminRole; // COMMENT::adminRole 47 | } 48 | 49 | struct RoleData4 { 50 | mapping(address => bool) members; /** 51 | * MULTILINE_COMMENT::members 52 | */ 53 | bytes32 adminRole; /** 54 | * MULTILINE_COMMENT::adminRole 55 | */ 56 | } 57 | 58 | function _doSafeBatchTransferAcceptanceCheck( 59 | address operator, 60 | address from, 61 | address to, 62 | uint256[] memory ids, 63 | uint256[] memory amounts, 64 | bytes memory data 65 | ) private { 66 | ids = 5; 67 | if (ids < 4) { 68 | ids = 5; 69 | } /* 70 | COMMENT1 71 | COMMENT2 72 | 73 | COMMENT3 74 | */ 75 | else if (ids == 0){ 76 | ids = 4; 77 | } // COMMENT4 78 | else { 79 | ids = 0; 80 | } 81 | 82 | if (to.isContract()) { 83 | try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns ( 84 | bytes4 response 85 | ) { 86 | if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { 87 | revert("ERC1155: ERC1155Receiver rejected tokens"); 88 | } 89 | } // COMMENT5 90 | catch Error(string memory reason) { 91 | revert(reason); 92 | } /* 93 | COMMENT6 94 | 95 | */ 96 | catch { 97 | revert("ERC1155: transfer to non-ERC1155Receiver implementer"); 98 | } 99 | } 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /tests/generated/src/traits/erc_721.rs: -------------------------------------------------------------------------------- 1 | // Generated with Sol2Ink v2.1.0 2 | // https://github.com/Brushfam/sol2ink 3 | 4 | pub use ink::prelude::vec::*; 5 | pub use openbrush::{ 6 | storage::Mapping, 7 | traits::{ 8 | AccountId, 9 | AccountIdExt, 10 | String, 11 | ZERO_ADDRESS, 12 | }, 13 | }; 14 | use scale::{ 15 | Decode, 16 | Encode, 17 | }; 18 | 19 | #[derive(Debug, Encode, Decode, PartialEq, Eq)] 20 | #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] 21 | pub enum Error { 22 | Custom(String), 23 | } 24 | 25 | 26 | 27 | #[openbrush::wrapper] 28 | pub type ERC721Ref = dyn ERC721; 29 | 30 | #[openbrush::trait_definition] 31 | pub trait ERC721 { 32 | /// @dev See {IERC165-supportsInterface}. 33 | #[ink(message)] 34 | fn supports_interface(&self, interface_id: [u8; 4]) -> Result; 35 | 36 | /// @dev See {IERC721-balanceOf}. 37 | #[ink(message)] 38 | fn balance_of(&self, owner: AccountId) -> Result; 39 | 40 | /// @dev See {IERC721-ownerOf}. 41 | #[ink(message)] 42 | fn owner_of(&self, token_id: u128) -> Result; 43 | 44 | /// @dev See {IERC721Metadata-name}. 45 | #[ink(message)] 46 | fn name(&self) -> Result; 47 | 48 | /// @dev See {IERC721Metadata-symbol}. 49 | #[ink(message)] 50 | fn symbol(&self) -> Result; 51 | 52 | /// @dev See {IERC721Metadata-tokenURI}. 53 | #[ink(message)] 54 | fn token_uri(&self, token_id: u128) -> Result; 55 | 56 | /// @dev See {IERC721-approve}. 57 | #[ink(message)] 58 | fn approve(&mut self, to: AccountId, token_id: u128) -> Result<(), Error>; 59 | 60 | /// @dev See {IERC721-getApproved}. 61 | #[ink(message)] 62 | fn get_approved(&self, token_id: u128) -> Result; 63 | 64 | /// @dev See {IERC721-setApprovalForAll}. 65 | #[ink(message)] 66 | fn set_approval_for_all(&mut self, operator: AccountId, approved: bool) -> Result<(), Error>; 67 | 68 | /// @dev See {IERC721-isApprovedForAll}. 69 | #[ink(message)] 70 | fn is_approved_for_all(&self, owner: AccountId, operator: AccountId) -> Result; 71 | 72 | /// @dev See {IERC721-transferFrom}. 73 | #[ink(message)] 74 | fn transfer_from( 75 | &mut self, 76 | from: AccountId, 77 | to: AccountId, 78 | token_id: u128, 79 | ) -> Result<(), Error>; 80 | 81 | ///solhint-disable-next-line max-line-length 82 | /// @dev See {IERC721-safeTransferFrom}. 83 | #[ink(message)] 84 | fn safe_transfer_from( 85 | &mut self, 86 | from: AccountId, 87 | to: AccountId, 88 | token_id: u128, 89 | ) -> Result<(), Error>; 90 | 91 | /// @dev See {IERC721-safeTransferFrom}. 92 | #[ink(message)] 93 | fn safe_transfer_from( 94 | &mut self, 95 | from: AccountId, 96 | to: AccountId, 97 | token_id: u128, 98 | data: Vec, 99 | ) -> Result<(), Error>; 100 | 101 | } 102 | --------------------------------------------------------------------------------