diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index 27066b9237b..57dc6ec2bc0 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -188,6 +188,15 @@ export function getCompletionSnippets(range: monacoTypes.IRange, monaco): monaco insertText: '// SPDX-License-Identifier: MIT', insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, range + }, + { + label: 'erc20', + kind: monaco.languages.CompletionItemKind.Snippet, + insertText: '\/\/ https:\/\/eips.ethereum.org\/EIPS\/eip-20\r\n\/\/ SPDX-License-Identifier: MIT\r\npragma solidity >=0.5.0 <0.8.0;\r\n\r\ninterface Token {\r\n\r\n \/\/\/ @param _owner The address from which the balance will be retrieved\r\n \/\/\/ @return balance the balance\r\n function balanceOf(address _owner) external view returns (uint256 balance);\r\n\r\n \/\/\/ @notice send `_value` token to `_to` from `msg.sender`\r\n \/\/\/ @param _to The address of the recipient\r\n \/\/\/ @param _value The amount of token to be transferred\r\n \/\/\/ @return success Whether the transfer was successful or not\r\n function transfer(address _to, uint256 _value) external returns (bool success);\r\n\r\n \/\/\/ @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`\r\n \/\/\/ @param _from The address of the sender\r\n \/\/\/ @param _to The address of the recipient\r\n \/\/\/ @param _value The amount of token to be transferred\r\n \/\/\/ @return success Whether the transfer was successful or not\r\n function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);\r\n\r\n \/\/\/ @notice `msg.sender` approves `_addr` to spend `_value` tokens\r\n \/\/\/ @param _spender The address of the account able to transfer the tokens\r\n \/\/\/ @param _value The amount of wei to be approved for transfer\r\n \/\/\/ @return success Whether the approval was successful or not\r\n function approve(address _spender , uint256 _value) external returns (bool success);\r\n\r\n \/\/\/ @param _owner The address of the account owning tokens\r\n \/\/\/ @param _spender The address of the account able to transfer the tokens\r\n \/\/\/ @return remaining Amount of remaining tokens allowed to spent\r\n function allowance(address _owner, address _spender) external view returns (uint256 remaining);\r\n\r\n event Transfer(address indexed _from, address indexed _to, uint256 _value);\r\n event Approval(address indexed _owner, address indexed _spender, uint256 _value);\r\n}\r\n\r\ncontract Standard_Token is Token {\r\n uint256 constant private MAX_UINT256 = 2**256 - 1;\r\n mapping (address => uint256) public balances;\r\n mapping (address => mapping (address => uint256)) public allowed;\r\n uint256 public totalSupply;\r\n \/*\r\n NOTE:\r\n The following variables are OPTIONAL vanities. One does not have to include them.\r\n They allow one to customise the token contract & in no way influences the core functionality.\r\n Some wallets\/interfaces might not even bother to look at this information.\r\n *\/\r\n string public name; \/\/fancy name: eg Simon Bucks\r\n uint8 public decimals; \/\/How many decimals to show.\r\n string public symbol; \/\/An identifier: eg SBX\r\n\r\n constructor(uint256 _initialAmount, string memory _tokenName, uint8 _decimalUnits, string memory _tokenSymbol) {\r\n balances[msg.sender] = _initialAmount; \/\/ Give the creator all initial tokens\r\n totalSupply = _initialAmount; \/\/ Update total supply\r\n name = _tokenName; \/\/ Set the name for display purposes\r\n decimals = _decimalUnits; \/\/ Amount of decimals for display purposes\r\n symbol = _tokenSymbol; \/\/ Set the symbol for display purposes\r\n }\r\n\r\n function transfer(address _to, uint256 _value) public override returns (bool success) {\r\n require(balances[msg.sender] >= _value, \"token balance is lower than the value requested\");\r\n balances[msg.sender] -= _value;\r\n balances[_to] += _value;\r\n emit Transfer(msg.sender, _to, _value); \/\/solhint-disable-line indent, no-unused-vars\r\n return true;\r\n }\r\n\r\n function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {\r\n uint256 allowance = allowed[_from][msg.sender];\r\n require(balances[_from] >= _value && allowance >= _value, \"token balance or allowance is lower than amount requested\");\r\n balances[_to] += _value;\r\n balances[_from] -= _value;\r\n if (allowance < MAX_UINT256) {\r\n allowed[_from][msg.sender] -= _value;\r\n }\r\n emit Transfer(_from, _to, _value); \/\/solhint-disable-line indent, no-unused-vars\r\n return true;\r\n }\r\n\r\n function balanceOf(address _owner) public override view returns (uint256 balance) {\r\n return balances[_owner];\r\n }\r\n\r\n function approve(address _spender, uint256 _value) public override returns (bool success) {\r\n allowed[msg.sender][_spender] = _value;\r\n emit Approval(msg.sender, _spender, _value); \/\/solhint-disable-line indent, no-unused-vars\r\n return true;\r\n }\r\n\r\n function allowance(address _owner, address _spender) public override view returns (uint256 remaining) {\r\n return allowed[_owner][_spender];\r\n }\r\n}', + documentation: 'ERC20 example implementation\n\n \/\/ https:\/\/eips.ethereum.org\/EIPS\/eip-20\r\n\/\/ SPDX-License-Identifier: MIT\r\npragma solidity >=0.5.0 <0.8.0;\r\n\r\ninterface Token {\r\n\r\n \/\/\/ @param _owner The address from which the balance will be retrieved\r\n \/\/\/ @return balance the balance\r\n function balanceOf(address _owner) external view returns (uint256 balance);\r\n\r\n \/\/\/ @notice send `_value` token to `_to` from `msg.sender`\r\n \/\/\/ @param _to The address of the recipient\r\n \/\/\/ @param _value The amount of token to be transferred\r\n \/\/\/ @return success Whether the transfer was successful or not\r\n function transfer(address _to, uint256 _value) external returns (bool success);\r\n\r\n \/\/\/ @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`\r\n \/\/\/ @param _from The address of the sender\r\n \/\/\/ @param _to The address of the recipient\r\n \/\/\/ @param _value The amount of token to be transferred\r\n \/\/\/ @return success Whether the transfer was successful or not\r\n function transferFrom(address _from, address _to, uint256 _value) external returns (bool success);\r\n\r\n \/\/\/ @notice `msg.sender` approves `_addr` to spend `_value` tokens\r\n \/\/\/ @param _spender The address of the account able to transfer the tokens\r\n \/\/\/ @param _value The amount of wei to be approved for transfer\r\n \/\/\/ @return success Whether the approval was successful or not\r\n function approve(address _spender , uint256 _value) external returns (bool success);\r\n\r\n \/\/\/ @param _owner The address of the account owning tokens\r\n \/\/\/ @param _spender The address of the account able to transfer the tokens\r\n \/\/\/ @return remaining Amount of remaining tokens allowed to spent\r\n function allowance(address _owner, address _spender) external view returns (uint256 remaining);\r\n\r\n event Transfer(address indexed _from, address indexed _to, uint256 _value);\r\n event Approval(address indexed _owner, address indexed _spender, uint256 _value);\r\n}\r\n\r\ncontract Standard_Token is Token {\r\n uint256 constant private MAX_UINT256 = 2**256 - 1;\r\n mapping (address => uint256) public balances;\r\n mapping (address => mapping (address => uint256)) public allowed;\r\n uint256 public totalSupply;\r\n \/*\r\n NOTE:\r\n The following variables are OPTIONAL vanities. One does not have to include them.\r\n They allow one to customise the token contract & in no way influences the core functionality.\r\n Some wallets\/interfaces might not even bother to look at this information.\r\n *\/\r\n string public name; \/\/fancy name: eg Simon Bucks\r\n uint8 public decimals; \/\/How many decimals to show.\r\n string public symbol; \/\/An identifier: eg SBX\r\n\r\n constructor(uint256 _initialAmount, string memory _tokenName, uint8 _decimalUnits, string memory _tokenSymbol) {\r\n balances[msg.sender] = _initialAmount; \/\/ Give the creator all initial tokens\r\n totalSupply = _initialAmount; \/\/ Update total supply\r\n name = _tokenName; \/\/ Set the name for display purposes\r\n decimals = _decimalUnits; \/\/ Amount of decimals for display purposes\r\n symbol = _tokenSymbol; \/\/ Set the symbol for display purposes\r\n }\r\n\r\n function transfer(address _to, uint256 _value) public override returns (bool success) {\r\n require(balances[msg.sender] >= _value, \"token balance is lower than the value requested\");\r\n balances[msg.sender] -= _value;\r\n balances[_to] += _value;\r\n emit Transfer(msg.sender, _to, _value); \/\/solhint-disable-line indent, no-unused-vars\r\n return true;\r\n }\r\n\r\n function transferFrom(address _from, address _to, uint256 _value) public override returns (bool success) {\r\n uint256 allowance = allowed[_from][msg.sender];\r\n require(balances[_from] >= _value && allowance >= _value, \"token balance or allowance is lower than amount requested\");\r\n balances[_to] += _value;\r\n balances[_from] -= _value;\r\n if (allowance < MAX_UINT256) {\r\n allowed[_from][msg.sender] -= _value;\r\n }\r\n emit Transfer(_from, _to, _value); \/\/solhint-disable-line indent, no-unused-vars\r\n return true;\r\n }\r\n\r\n function balanceOf(address _owner) public override view returns (uint256 balance) {\r\n return balances[_owner];\r\n }\r\n\r\n function approve(address _spender, uint256 _value) public override returns (bool success) {\r\n allowed[msg.sender][_spender] = _value;\r\n emit Approval(msg.sender, _spender, _value); \/\/solhint-disable-line indent, no-unused-vars\r\n return true;\r\n }\r\n\r\n function allowance(address _owner, address _spender) public override view returns (uint256 remaining) {\r\n return allowed[_owner][_spender];\r\n }\r\n}', + detail: 'erc20 example', + insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, + range } ] }