-
-
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
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ation/pi_network/pi-network-interoperability/bridge-contracts/sidra-chain/SidraBridge.sol
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,44 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "./Pausable.sol"; | ||
import "./Owner.sol"; | ||
import "./WalletAccessControl.sol"; | ||
import "./SidraToken.sol"; | ||
|
||
contract SidraBridge is Pausable, Owner, WalletAccessControl { | ||
SidraToken public sidraToken; | ||
address public foreignChainAddress; | ||
uint256 public bridgeFee; | ||
|
||
event BridgeTransfer(address indexed from, address indexed to, uint256 value); | ||
event BridgeReceived(address indexed from, address indexed to, uint256 value); | ||
|
||
constructor() public { | ||
sidraToken = SidraToken(address(new SidraToken())); | ||
foreignChainAddress = address(0); | ||
bridgeFee = 0.1 * (10**18); // 0.1 ST | ||
} | ||
|
||
function setForeignChainAddress(address _foreignChainAddress) public onlyOwner { | ||
foreignChainAddress = _foreignChainAddress; | ||
} | ||
|
||
function setBridgeFee(uint256 _bridgeFee) public onlyOwner { | ||
bridgeFee = _bridgeFee; | ||
} | ||
|
||
function transferToForeignChain(address _to, uint256 _value) public whenNotPaused { | ||
require(isWalletAllowed(msg.sender), "Wallet not allowed"); | ||
require(_value > 0, "Invalid value"); | ||
require(sidraToken.balanceOf(msg.sender) >= _value, "Insufficient balance"); | ||
sidraToken.transferFrom(msg.sender, address(this), _value); | ||
emit BridgeTransfer(msg.sender, _to, _value); | ||
} | ||
|
||
function receiveFromForeignChain(address _from, address _to, uint256 _value) public whenNotPaused { | ||
require(foreignChainAddress == msg.sender, "Invalid foreign chain address"); | ||
require(_value > 0, "Invalid value"); | ||
sidraToken.transfer(_to, _value); | ||
emit BridgeReceived(_from, _to, _value); | ||
} | ||
} |