Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dinos problems #9

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions problemVersion1/1/problem1.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// Declare public state variables as command, then assign the default value of that type.
// Declare public state variables, then assign the default value of that type.
// In fact you do not to assign the default value cuz it's "default"
contract answer1 {
// TODO: declare a uint variable named myUint
// TODO: declare a uint256 variable named myUint

// TODO: declare a boolean variable named myBool

Expand All @@ -12,7 +13,11 @@ contract answer1 {
// TODO: declare a string variable named myString


function getUint() public view returns (uint) {


// --------------Below are judging functions-------------------

function getUint() public view returns (uint256) {
return myUint;
}
function getBool() public view returns (bool) {
Expand Down
12 changes: 10 additions & 2 deletions problemVersion1/10/problem10.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;


// The system will deploy `Called` for you
// The interface you are going to write will be use to call contract `Called`.
contract Called {
bool public called = false;

Expand All @@ -13,7 +15,9 @@ contract Called {
}
}

// TODO: write an interface named `ICalled`, implement the two functions in contract `Called`.
// TODO 1: write an interface named `ICalled`, implement the two functions which is in contract `Called`.




contract answer10 {
Expand All @@ -24,10 +28,14 @@ contract answer10 {
}

function setCalled() external {
// TODO: finish this function by using `ICalled` to call `setCalled()` in contract `Called`.
// TODO 2: Finish this function by using `ICalled` to call `setCalled()` in contract `Called`.


}


// --------------Below are judging functions-------------------

function checkAns() external view returns (bool) {
return ICalled(address(calledContract)).getCalled();
}
Expand Down
6 changes: 5 additions & 1 deletion problemVersion1/11/problem11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ contract answer11 {
called = new Called();
}

// TODO: Declare a function named `sendETHtoCalled`.
// TODO 1: Declare a function named `sendETHtoCalled`.


// This function should send 50000 wei to the contract `called` using method `call`
// Assign the first return value to `success`.
// Notice that there are multiple return values of method call.


// --------------Below are judging functions-------------------

function checkAns() external view returns(uint256) {
require(success, "transfer not success");
return called.getBalance();
Expand Down
19 changes: 13 additions & 6 deletions problemVersion1/12/problem12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ contract answer12 {
Called public called;
bool public success;



// TODO: write a function named `callSetGreet()`, take a string as a param.



// This function should call function `setGreet()` in contract `called` and a string as param.
// You can, but not required, send some ETH with this call .



// --------------Below are judging functions-------------------

receive() external payable {}

function deployContract() external {
called = new Called();
}

// TODO: write a function named `callSetGreet()`, taking a string as a parameter.
// This function should call function `setGreet()` in contract `called` and input the param string.
// You can, but not required, send some ETH with this call .


function getGreet() external view returns (string memory) {
return called.getGreet();
}
Expand Down
15 changes: 10 additions & 5 deletions problemVersion1/13/problem13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
pragma solidity ^0.8.17;

contract answer13 {
// TODO: Define a struct named `Food`,
// The first variable is a string named `name`, and the second is a uint256 named `price`.
// TODO 1: Define a struct named `Food`,
// This struct includes a string named `name`, and a uint256 named `price`.

// TODO: Declare a Food array named `foods`

// TODO: Declare a function named `createFood()`, it should let user createNewFood.
// That is, it should take a string and a uint256 as param, create a `Food`, and push it into the array `foods`.
// TODO 2: Declare a Food array named `foods`


// TODO 3: Declare a function named `createFood()`
// It should take a string and a uint256 as param, create a `Food`, and push it into the array `foods`.



// --------------Below are judging functions-------------------

function checkAns() external view returns (string memory, uint256) {
return (foods[0].name, foods[0].price);
}
Expand Down
9 changes: 7 additions & 2 deletions problemVersion1/16/problem16.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// In this problem, we are going to write our ERC20 contract !

interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);

Expand All @@ -12,15 +14,15 @@ interface IERC20 {

function transfer(address to, uint256 amount) external returns (bool);

// The functions below are commented for judging/compiling reasons.
// ---------functions below are commented for compiling reasons.--------
// function allowance(address owner, address spender) external view returns (uint256);

// function approve(address spender, uint256 amount) external returns (bool);

// function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

// Finish the functions below, you can have a peek to the interface if you feel it difficult.
// Finish the functions below, you can take a look at the interface if you find it difficult.
contract answer16 is IERC20 {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
Expand All @@ -34,10 +36,13 @@ contract answer16 is IERC20 {

// Finish the `totalSupply` function, it should return the totalSupply of this ERC20 token.


// Finish the `balanceOf` function, it should return the balance of an input address.


// Finish the `transfer` function, it should transfer specific amount of ETH from the function called to another address and return true.


}


16 changes: 10 additions & 6 deletions problemVersion1/17/problem17.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pragma solidity ^0.8.17;

// Cont'd
// Finish the ERC20
// If you haven't done the part 1, it is recommended first
// Finish the ERC20 contract
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);

Expand Down Expand Up @@ -49,7 +50,8 @@ contract answer17 is IERC20 {

//========= All the Todos are below here ==========

// TODO: Finish the function `allowance`, it should return the allowance from owner to spender.
// TODO 1: Finish the function `allowance`, it should return the allowance from owner to spender.




Expand All @@ -63,19 +65,21 @@ contract answer17 is IERC20 {
require(_owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");

// TODO: set the allowance from `owner` to `sender` to be `amount`
// TODO 2: set the allowance from `owner` to `sender` to be `amount`

// TODO: fire the event `Approval`
// TODO 3: fire the event `Approval`


}

// TODO: Finish function `transferFrom`
// TODO 4: Finish function `transferFrom`
// It should call `_spendAllowance()` and `_transfer()`, try to pass in the correct param !



// ========== All todos are done ! Good job =======


// --------------Below are judging functions-------------------

function _spendAllowance(address _owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = _allowances[owner][spender];
Expand Down
4 changes: 0 additions & 4 deletions problemVersion1/18/answer18.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ contract answer18 is IERC165, IAnother {

function aFunction() external returns (bool) {}
function bFunction() external returns (bool) {}

function getIAnotherId() external pure returns(bytes4) {
return this.aFunction.selector ^ this.bFunction.selector;
}
}


11 changes: 6 additions & 5 deletions problemVersion1/18/problem18.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ interface IERC165 {
}

interface IAnother {
function aFunction() external returns (bool);
function bFunction() external returns (bool);
function aFunction() external returns (bool);
function bFunction() external returns (bool);
}


contract answer18 is IERC165, IAnother {

// TODO: write a function named `supportsInterface` which takes a bytes4 as an input.
// This function check if the input interfaceID is supported by this contract.
// Note that `answer18` contract supports two interface: IERC165 and IAnother.
// TODO: write a function named `supportsInterface` which takes a bytes4 as an input.
// This function check if the input interfaceID is supported by this contract.
// Note that `answer18` contract supports two interface: IERC165 and IAnother.




function aFunction() external returns (bool) {}
function bFunction() external returns (bool) {}
}
Expand Down
9 changes: 5 additions & 4 deletions problemVersion1/19/problem19.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// ERC721! We are going to write our own ERC721 contract.
interface IERC165 {
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
Expand All @@ -26,17 +27,17 @@ contract ERC721 is IERC721 {
interfaceId == type(IERC165).interfaceId;
}

// TODO: write a `_mint` internal function taking an address and an id
// TODO 1: write a `_mint` internal function taking an address and an id
// It should revert with "mint to zero address" message if so
// It should revert with "already minted" message if so
// it should emit Transfer


// TODO: write an `ownerOf` external function.
// TODO 2: write a `ownerOf` external function.
// It should revert with "token doesn't exist" if so


// TODO: write an `balanceOf` external function.
// TODO 3: write a `balanceOf` external function.
// It should revert with "owner = zero address" if someone query for zero address


Expand All @@ -48,6 +49,6 @@ contract answer19 is ERC721 {
function mint(address to, uint256 id) external {
_mint(to, id);
}

}

2 changes: 1 addition & 1 deletion problemVersion1/2/problem2.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
// Below you have to declare public functions, remember to assign the type of functions( pure or view )
// Declare public functions, remember to assign the type of functions, that is, pure or view.
contract answer2 {
uint public x = 1;

Expand Down
8 changes: 6 additions & 2 deletions problemVersion1/20/problem20.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// Cont'd
// If you haven't done part 1, it is recommended to do it first.
interface IERC165 {
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
Expand Down Expand Up @@ -88,19 +90,21 @@ contract ERC721 is IERC721 {
spender == _approvals[id]);
}

// write a function named `transferFrom`
// TODO 1: write a function named `transferFrom`
// it should transfer token if all requirement are satisfied
// it should revert with "transfer to zero address" message if so
// it should fire event `Transfer`



// write a function named `_burn` taking one uint256 as param
// TODO 2: write a function named `_burn` taking one uint256 as param
// It should burn token
// it should revert with "not minted" if so
// it should emit `Transfer` as it transfer token to zero address




}

contract answer20 is ERC721 {
Expand Down
4 changes: 2 additions & 2 deletions problemVersion1/3/problem3.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

// complete the function below
// Complete the function below.
contract answer3 {
function biggerThanTen(uint256 num) public pure returns (bool) {
// if the input is bigger than ten, return true, else return false
// If the input is bigger than ten, return true, else return false

}
}
6 changes: 3 additions & 3 deletions problemVersion1/4/answer4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
pragma solidity ^0.8.17;
contract answer4 {
mapping(address => uint256) balanceOf;
mapping(address => mapping(uint256 => bool)) AddressOwnNum;
mapping(address => mapping(uint256 => bool)) addressOwnNum;

function setBalanceOf(address _user, uint256 _balance) public {
balanceOf[_user] = _balance;
}

function setAddressOwnNFT(address _user, uint256 _num) public {
AddressOwnNum[_user][_num] = true;
addressOwnNum[_user][_num] = true;
}

function getBalanceOf(address _user) public view returns (uint256) {
return balanceOf[_user];
}

function getAddressOwnNum(address _user, uint256 _num) public view returns (bool) {
return AddressOwnNum[_user][_num];
return addressOwnNum[_user][_num];
}
}
Loading