-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add whbar contract Signed-off-by: nikolay <[email protected]> * chore: add whbar contract Signed-off-by: nikolay <[email protected]> * chore: edit readme Signed-off-by: nikolay <[email protected]> * chore: fix readme Signed-off-by: nikolay <[email protected]> * chore: fix readme Signed-off-by: nikolay <[email protected]> * chore: fix readme Signed-off-by: nikolay <[email protected]> * chore: add tests for receive and fallback methods Signed-off-by: nikolay <[email protected]> --------- Signed-off-by: nikolay <[email protected]>
- Loading branch information
Showing
4 changed files
with
548 additions
and
0 deletions.
There are no files selected for viewing
290 changes: 290 additions & 0 deletions
290
contracts-abi/contracts/wrapped-tokens/WHBAR.sol/WHBAR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "src", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "guy", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Approval", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "dst", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Deposit", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "src", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "dst", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "src", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Withdrawal", | ||
"type": "event" | ||
}, | ||
{ | ||
"stateMutability": "payable", | ||
"type": "fallback" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"name": "allowance", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "guy", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "approve", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"name": "balanceOf", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "decimals", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint8", | ||
"name": "", | ||
"type": "uint8" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "deposit", | ||
"outputs": [], | ||
"stateMutability": "payable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "symbol", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "totalSupply", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "dst", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transfer", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "src", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "dst", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "transferFrom", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "wad", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "withdraw", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"stateMutability": "payable", | ||
"type": "receive" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
:warning: :bangbang: ***All examples under this folder are exploration code and have NOT been audited. Use them at your own risk!*** :bangbang: :warning: | ||
|
||
--- | ||
|
||
### WHBAR | ||
|
||
The WHBAR contract for Wrapped HBAR to help transactions that use native token payments. | ||
|
||
##### Properties: | ||
- name - ```string``` "Wrapped HBAR" | ||
- symbol - ```string``` "WHBAR"decimals | ||
- decimals - ```uint8``` 8 | ||
- balanceOf - ``` mapping(address => uint256) balanceOf``` | ||
- allowance - ```mapping(address => mapping(address => uint256)) allowance``` | ||
|
||
##### Events: | ||
- Approval - ```event Approval(address src, address guy, uint256 wad)``` | ||
- Transfer - ``` event Transfer(address src, address dst, uint256 wad)``` | ||
- Deposit - ``` event Deposit(address dst, uint256 wad)``` | ||
- Withdrawal - ``` event Withdrawal(address src, uint256 wad)``` | ||
|
||
##### Methods: | ||
- receive - ```receive() external payable``` | ||
- fallback - ```fallback() external payable``` | ||
- deposit - ```function deposit() external payable``` | ||
- withdraw - ```function withdraw(uint256 wad) external``` | ||
- totalSupply - ```function totalSupply() public view returns (uint256)``` | ||
- approve - ```function approve(address guy, uint256 wad) public returns (bool)``` | ||
- transfer - ```function transfer(address dst, uint256 wad) public returns (bool)``` | ||
- transferFrom - ```function transferFrom(address src, address dst, uint256 wad) public returns (bool)``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.22; | ||
|
||
contract WHBAR { | ||
string public name = "Wrapped HBAR"; | ||
string public symbol = "WHBAR"; | ||
uint8 public decimals = 8; | ||
|
||
event Approval(address indexed src, address indexed guy, uint wad); | ||
event Transfer(address indexed src, address indexed dst, uint wad); | ||
event Deposit(address indexed dst, uint wad); | ||
event Withdrawal(address indexed src, uint wad); | ||
|
||
mapping(address => uint) public balanceOf; | ||
mapping(address => mapping(address => uint)) public allowance; | ||
|
||
fallback() external payable { | ||
deposit(); | ||
} | ||
|
||
receive() external payable { | ||
deposit(); | ||
} | ||
|
||
function deposit() public payable { | ||
balanceOf[msg.sender] += msg.value; | ||
|
||
emit Deposit(msg.sender, msg.value); | ||
} | ||
|
||
function withdraw(uint wad) public { | ||
require(balanceOf[msg.sender] >= wad); | ||
|
||
balanceOf[msg.sender] -= wad; | ||
payable(msg.sender).transfer(wad); | ||
|
||
emit Withdrawal(msg.sender, wad); | ||
} | ||
|
||
function totalSupply() public view returns (uint) { | ||
return address(this).balance; | ||
} | ||
|
||
function approve(address guy, uint wad) public returns (bool) { | ||
allowance[msg.sender][guy] = wad; | ||
|
||
emit Approval(msg.sender, guy, wad); | ||
|
||
return true; | ||
} | ||
|
||
function transfer(address dst, uint wad) public returns (bool) { | ||
return transferFrom(msg.sender, dst, wad); | ||
} | ||
|
||
function transferFrom(address src, address dst, uint wad) public returns (bool) { | ||
require(balanceOf[src] >= wad); | ||
|
||
if (src != msg.sender && allowance[src][msg.sender] != | ||
type(uint256).max) { | ||
require(allowance[src][msg.sender] >= wad); | ||
allowance[src][msg.sender] -= wad; | ||
} | ||
|
||
balanceOf[src] -= wad; | ||
balanceOf[dst] += wad; | ||
|
||
emit Transfer(src, dst, wad); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.