-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...ion/pi_network/pi-network-interoperability/bridge-contracts/binance-smart-chain/Bridge.js
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,38 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol"; | ||
import "https://github.com/binance-chain/bsc-bridge/blob/master/contracts/BEP20.sol"; | ||
|
||
contract Bridge { | ||
address public owner; | ||
mapping(address => uint256) public balances; | ||
mapping(address => mapping(address => uint256)) public allowances; | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
function bridgeToken(address tokenAddress, address recipientAddress, uint256 amount) public { | ||
require(msg.sender == owner, "Only the owner can bridge tokens"); | ||
SafeERC20.safeTransfer(tokenAddress, recipientAddress, amount); | ||
balances[tokenAddress] -= amount; | ||
} | ||
|
||
function getBalance(address tokenAddress) public view returns (uint256) { | ||
return balances[tokenAddress]; | ||
} | ||
|
||
function approve(address spender, uint256 amount) public { | ||
allowances[msg.sender][spender] = amount; | ||
emit Approval(msg.sender, spender, amount); | ||
} | ||
|
||
function transferFrom(address sender, address recipient, uint256 amount) public { | ||
require(allowances[sender][msg.sender] >= amount, "Insufficient allowance"); | ||
SafeERC20.safeTransfer(sender, recipient, amount); | ||
allowances[sender][msg.sender] -= amount; | ||
} | ||
} |