Commit 7668a5a2 authored by XFT-dev's avatar XFT-dev
Browse files

added bsc code

parent 855c2207
# Offshift BSC-ETHEREUM bridge
\ No newline at end of file
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
contract bsc_bridge{
IERC20 token;
bool pause;
address connector;
address owner;
constructor(address _token, address _bridge) {
token = IERC20(_token);
pause = false;
connector = _bridge;
owner = msg.sender;
}
event bridged(address recv, uint256 amount);
function move(uint256 amount) public{
require(amount <= token.allowance(msg.sender, address(this)), "approve the contract");
require(!pause, "bridge is paused");
token.transferFrom(msg.sender, connector, amount);
emit bridged(msg.sender, amount);
}
function stop() public {
require(msg.sender == owner, "only owner");
pause = !pause;
}
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Offshift Bridge</title>
<script src="./web3.min.js"></script>
<link href="./styles.css" rel="stylesheet">
</head>
<body>
<div id="main" class="dark">
<div
class="min-h-screen bg-gradient-to-r from-purple-400 via-pink-500 to-red-500 py-6 flex flex-col justify-center sm:py-12 text-white dark:bg-gradient-to-r dark:from-gray-800 dark:to-gray-900">
<div class="dark:bg-gray-800 dark:text-white w-full mx-auto rounded-3xl shadow-lg bg-white px-10 pt-16 pb-10 text-gray-600"
style="max-width: 400px">
<div class="overflow-hidden relative mb-10">
<div class="font-semibold text-center text-2xl mb-4 text-gray-900 dark:text-white">Offshift Bridge
</div>
<div class="container mx-auto mb-1 pt-8 justify-center">
<p class="mx-auto mb-3 dark:text-purple-500 text-center font-bold pb-3" id="net">Non Web3
enabled browser detected</p>
<p class="mx-auto mb-3 dark:text-purple-500 text-center font-bold pb-3">Amount</p>
<input id="tokenAmount" type="number"
class="dark:border-gray-800 focus:ring-2 dark:bg-gray-600 shadow appearance-none border rounded py-2 px-20 text-grey-darker">
</div>
<div class="container w-full pt-10 text-center">
<button id="btttn" onclick="handle()"
class="dark:bg-gradient-to-r dark:from-purple-800 px-7 py-3 shadow-md no-underline rounded-full bg-gradient-to-r from-green-400 to-blue-500 hover:from-pink-500 hover:to-yellow-500 text-white font-sans font-semibold text-xl border-blue btn-primary hover:text-white hover:bg-blue-light focus:outline-none active:shadow-none justify-center">Approve</button>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
if (typeof ethereum != "undefined") {
ethereum.request({ method: 'eth_requestAccounts' }).catch((err) => alert("Please connect metamask to the site"));
} else {
alert("None ethereum browser detected, Please install metmask !!!");
}
web3 = new Web3(window.ethereum);
web3.eth.getAccounts(async function (error, accounts) {
web3.eth.accounts = accounts;
web3.eth.defaultAccount = accounts[0];
});
let network = "";
async function setup() {
let netId = await web3.eth.net.getId();
if (netId == 1) {
network = "ethereum";
} else if (netId == 56) {
network = "binance";
} else {
alert("please switch to a supported network")
}
net.innerText = `Using ${network} network`;
}
let state = "Approve";
function handle() {
if (state == "Approve") {
approve();
} else {
bridge();
}
}
async function bridge() {
let bridge_contract;
let token = "";
if (network == "ethereum") {
bridge_contract = new web3.eth.Contract(bridge_abi, "0xe138c66982Fd5c890c60b94FDBa1747faF092c20");
token = "0xABe580E7ee158dA464b51ee1a83Ac0289622e6be";
} else if (network == "binance") {
bridge_contract = new web3.eth.Contract(bridge_abi, "0xcDC5DeeFa9F540bAC261829B6c64163E2CfF92Ca");
token = "0xe138c66982Fd5c890c60b94FDBa1747faF092c20";
}
let amount = web3.utils.toWei(parseFloat(tokenAmount.value).toString(), 'ether');
btttn.classList.add("opacity-40");
btttn.disabled = true;
if (network == "ethereum") {
let gas = (await bridge_contract.methods.move(amount).estimateGas({ from: ethereum.selectedAddress, value: 2 })) * await web3.eth.getGasPrice();
await bridge_contract.methods.move(amount).send({ from: ethereum.selectedAddress, value: gas });
} else {
await bridge_contract.methods.move(amount).send({ from: ethereum.selectedAddress});
}
state = "Approve";
btttn.innerText = state;
btttn.classList.remove("opacity-40");
btttn.disabled = false;
//addToken(token);
alert("Tokens moved, transcation may take up to 30 minutes in order to complete");
}
async function approve() {
let token = "";
let bridge_address = "";
if (network == "ethereum") {
token = new web3.eth.Contract(token_abi, "0xABe580E7ee158dA464b51ee1a83Ac0289622e6be");
bridge_address = "0xe138c66982Fd5c890c60b94FDBa1747faF092c20";
} else if (network == "binance") {
token = new web3.eth.Contract(token_abi, "0xe138c66982Fd5c890c60b94FDBa1747faF092c20");
bridge_address = "0xcDC5DeeFa9F540bAC261829B6c64163E2CfF92Ca";
}
btttn.classList.add("opacity-40");
btttn.disabled = true;
let amount = web3.utils.toWei(parseFloat(tokenAmount.value).toString(), 'ether');
if (await token.methods.allowance(ethereum.selectedAddress, bridge_address).call() >= amount) {
state = "MOVE";
btttn.innerText = state;
btttn.classList.remove("opacity-40");
btttn.disabled = false;
return 1;
}
await token.methods.approve(bridge_address, amount).send({ from: ethereum.selectedAddress });
state = "MOVE";
btttn.innerText = state;
btttn.classList.remove("opacity-40");
btttn.disabled = false;
}
async function addToken(addy) {
const tokenAddress = addy;
const tokenSymbol = 'XFT';
const tokenDecimals = 18;
const tokenImage = 'https://assets.coingecko.com/coins/images/11977/small/CsBrPiA.png?1614570441';
try {
// wasAdded is a boolean. Like any RPC method, an error may be thrown.
const wasAdded = await ethereum.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC20', // Initially only supports ERC20, but eventually more!
options: {
address: tokenAddress, // The address that the token is at.
symbol: tokenSymbol, // A ticker symbol or shorthand, up to 5 chars.
decimals: tokenDecimals, // The number of decimals in the token
image: tokenImage, // A string url of the token logo
},
},
});
if (wasAdded) {
console.log('!!!!');
} else {
console.log('Your loss!');
}
} catch (error) {
console.log(error);
}
}
let token_abi = [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"internalType": "address",
"name": "spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "recipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
}
]
let bridge_abi = [
{
"inputs": [
{
"internalType": "address",
"name": "_token",
"type": "address"
},
{
"internalType": "address",
"name": "_bridge",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "recv",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "bridged",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "move",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "stop",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
];
setup();
ethereum.on('chainChanged', (_chainId) => window.location.reload());
</script>
\ No newline at end of file
# Offshift pancakeswap farm
# <img src="logo.svg" alt="OpenZeppelin" height="40px">
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/contracts)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/contracts.svg)](https://www.npmjs.org/package/@openzeppelin/contracts)
[![Coverage Status](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts/graph/badge.svg)](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts)
**A library for secure smart contract development.** Build on a solid foundation of community-vetted code.
* Implementations of standards like [ERC20](https://docs.openzeppelin.com/contracts/erc20) and [ERC721](https://docs.openzeppelin.com/contracts/erc721).
* Flexible [role-based permissioning](https://docs.openzeppelin.com/contracts/access-control) scheme.
* Reusable [Solidity components](https://docs.openzeppelin.com/contracts/utilities) to build custom contracts and complex decentralized systems.
* First-class integration with the [Gas Station Network](https://docs.openzeppelin.com/contracts/gsn) for systems with no gas fees!
* [Audited](https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/audit) by leading security firms (_last full audit on v2.0.0_).
## Overview
### Installation
```console
$ npm install @openzeppelin/contracts
```
OpenZeppelin Contracts features a [stable API](https://docs.openzeppelin.com/contracts/releases-stability#api-stability), which means your contracts won't break unexpectedly when upgrading to a newer minor version.
### Usage
Once installed, you can use the contracts in the library by importing them:
```solidity
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
contract MyCollectible is ERC721 {
constructor() ERC721("MyCollectible", "MCO") {
}
}
```
_If you're new to smart contract development, head to [Developing Smart Contracts](https://docs.openzeppelin.com/learn/developing-smart-contracts) to learn about creating a new project and compiling your contracts._
To keep your system secure, you should **always** use the installed code as-is, and neither copy-paste it from online sources, nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.
## Learn More
The guides in the [docs site](https://docs.openzeppelin.com/contracts) will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:
* [Access Control](https://docs.openzeppelin.com/contracts/access-control): decide who can perform each of the actions on your system.
* [Tokens](https://docs.openzeppelin.com/contracts/tokens): create tradeable assets or collectives, and distribute them via [Crowdsales](https://docs.openzeppelin.com/contracts/crowdsales).
* [Gas Station Network](https://docs.openzeppelin.com/contracts/gsn): let your users interact with your contracts without having to pay for gas themselves.
* [Utilities](https://docs.openzeppelin.com/contracts/utilities): generic useful tools, including non-overflowing math, signature verification, and trustless paying systems.
The [full API](https://docs.openzeppelin.com/contracts/api/token/ERC20) is also thoroughly documented, and serves as a great reference when developing your smart contract application. You can also ask for help or follow Contracts's development in the [community forum](https://forum.openzeppelin.com).
Finally, you may want to take a look at the [guides on our blog](https://blog.openzeppelin.com/guides), which cover several common use cases and good practices.. The following articles provide great background reading, though please note, some of the referenced tools have changed as the tooling in the ecosystem continues to rapidly evolve.
* [The Hitchhiker’s Guide to Smart Contracts in Ethereum](https://blog.openzeppelin.com/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05) will help you get an overview of the various tools available for smart contract development, and help you set up your environment.
* [A Gentle Introduction to Ethereum Programming, Part 1](https://blog.openzeppelin.com/a-gentle-introduction-to-ethereum-programming-part-1-783cc7796094) provides very useful information on an introductory level, including many basic concepts from the Ethereum platform.
* For a more in-depth dive, you may read the guide [Designing the Architecture for Your Ethereum Application](https://blog.openzeppelin.com/designing-the-architecture-for-your-ethereum-application-9cec086f8317), which discusses how to better structure your application and its relationship to the real world.
## Security
This project is maintained by [OpenZeppelin](https://openzeppelin.com), and developed following our high standards for code quality and security. OpenZeppelin is meant to provide tested and community-audited code, but please use common sense when doing anything that deals with real money! We take no responsibility for your implementation decisions and any security problems you might experience.
The core development principles and strategies that OpenZeppelin is based on include: security in depth, simple and modular code, clarity-driven naming conventions, comprehensive unit testing, pre-and-post-condition sanity checks, code consistency, and regular audits.
The latest audit was done on October 2018 on version 2.0.0.
Please report any security issues you find to [email protected]
## Contribute
OpenZeppelin exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the [contribution guide](CONTRIBUTING.md)!
## License
OpenZeppelin is released under the [MIT License](LICENSE).
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping (address => bool) members;
bytes32 adminRole;
}
mapping (bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite