Skip to content

Commit 23655c9

Browse files
committed
✨initial commit - minimal setup
1 parent 2898726 commit 23655c9

17 files changed

+1386
-0
lines changed

contracts/Token.sol

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// SPDX-License-Identifier: -- 🔮 --
2+
3+
pragma solidity ^0.8.0;
4+
5+
contract Token {
6+
7+
mapping (address => uint256) private _balances;
8+
mapping (address => mapping (address => uint256)) private _allowances;
9+
10+
uint256 private _totalSupply;
11+
12+
string private _name;
13+
string private _symbol;
14+
uint8 private _decimals;
15+
16+
event Transfer(address indexed from, address indexed to, uint256 value);
17+
event Approval(address indexed owner, address indexed spender, uint256 value);
18+
19+
constructor () {
20+
_name = "Token";
21+
_symbol = "TKN";
22+
_decimals = 18;
23+
24+
_totalSupply = 1000000000000000000000000;
25+
_balances[msg.sender] = _totalSupply;
26+
}
27+
28+
/**
29+
* @dev Returns the name of the token.
30+
*/
31+
function name() public view returns (string memory) {
32+
return _name;
33+
}
34+
35+
/**
36+
* @dev Returns the symbol of the token, usually a shorter version of the
37+
* name.
38+
*/
39+
function symbol() public view returns (string memory) {
40+
return _symbol;
41+
}
42+
43+
function decimals() public view returns (uint8) {
44+
return _decimals;
45+
}
46+
47+
function totalSupply() public view returns (uint256) {
48+
return _totalSupply;
49+
}
50+
51+
function balanceOf(address account) public view returns (uint256) {
52+
return _balances[account];
53+
}
54+
55+
function transfer(
56+
address recipient,
57+
uint256 amount
58+
) public returns (bool) {
59+
_transfer(_msgSender(), recipient, amount);
60+
return true;
61+
}
62+
63+
function allowance(
64+
address owner,
65+
address spender
66+
) public view returns (uint256) {
67+
return _allowances[owner][spender];
68+
}
69+
70+
function approve(
71+
address spender,
72+
uint256 amount
73+
) public returns (bool) {
74+
_approve(_msgSender(), spender, amount);
75+
return true;
76+
}
77+
78+
function transferFrom(
79+
address sender,
80+
address recipient,
81+
uint256 amount
82+
) public returns (bool) {
83+
_approve(
84+
sender,
85+
_msgSender(),
86+
_allowances[sender][_msgSender()] - amount
87+
);
88+
_transfer(sender, recipient, amount);
89+
return true;
90+
}
91+
92+
function increaseAllowance(
93+
address spender,
94+
uint256 addedValue
95+
) public virtual returns (bool) {
96+
_approve(
97+
_msgSender(),
98+
spender,
99+
_allowances[_msgSender()][spender] + addedValue
100+
);
101+
return true;
102+
}
103+
104+
function decreaseAllowance(
105+
address spender,
106+
uint256 subtractedValue
107+
) public virtual returns (bool) {
108+
_approve(
109+
_msgSender(), spender, _allowances[_msgSender()][spender] - subtractedValue
110+
);
111+
return true;
112+
}
113+
114+
function _transfer(
115+
address sender,
116+
address recipient,
117+
uint256 amount
118+
)
119+
internal
120+
virtual
121+
{
122+
require(
123+
sender != address(0),
124+
"ERC20: transfer from the zero address"
125+
);
126+
127+
require(
128+
recipient != address(0),
129+
"ERC20: transfer to the zero address"
130+
);
131+
132+
_balances[sender] =
133+
_balances[sender] - amount;
134+
135+
_balances[recipient] =
136+
_balances[recipient] + amount;
137+
138+
emit Transfer(sender, recipient, amount);
139+
}
140+
141+
function _approve(
142+
address owner,
143+
address spender,
144+
uint256 amount
145+
)
146+
internal
147+
virtual
148+
{
149+
require(
150+
owner != address(0x0),
151+
"ERC20: approve from the zero address"
152+
);
153+
154+
require(
155+
spender != address(0x0),
156+
"ERC20: approve to the zero address"
157+
);
158+
159+
_allowances[owner][spender] = amount;
160+
emit Approval(owner, spender, amount);
161+
}
162+
163+
function _msgSender() internal view virtual returns (address payable) {
164+
return payable(msg.sender);
165+
}
166+
167+
function _msgData() internal view virtual returns (bytes memory) {
168+
this;
169+
return msg.data;
170+
}
171+
}

deploy-factory.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const Web3 = require('web3');
2+
const web3 = new Web3('http://localhost:9545');
3+
4+
const UniswapV2FactoryBytecode = require('@uniswap/v2-core/build/UniswapV2Factory.json').bytecode
5+
const UniswapV2FactoryAbi = require('@uniswap/v2-core/build/UniswapV2Factory.json').abi
6+
7+
const Z = "0x0000000000000000000000000000000000000000";
8+
9+
async function a() {
10+
11+
const ganacheAccounts = await web3.eth.getAccounts();
12+
const contract = new web3.eth.Contract(UniswapV2FactoryAbi);
13+
14+
contract.deploy({
15+
arguments: [Z],
16+
data: UniswapV2FactoryBytecode
17+
}).send({
18+
from: ganacheAccounts[0],
19+
gas: 4712388,
20+
gasPrice: 100000000000
21+
}).then((deployment) => {
22+
console.log('Uniswap Factory was deployed at the following address:');
23+
console.log(deployment.options.address);
24+
}).catch((err) => {
25+
console.error(err);
26+
});
27+
}
28+
29+
a();

package.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "bitcoin-solidity-swap",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"repository": "https://github.com/bitcoin-portal/bitcoincom-solidity-swap",
6+
"description": "Bitcoin Swap",
7+
"scripts": {
8+
"chain": "ganache-cli --defaultBalanceEther 10000000 -i 5777 -p 9545 -l 12500000 -m \"urban prevent meadow draft involve security curtain robot brick question try scatter\"",
9+
"test-token": "npx truffle test test/token.test.js",
10+
"test-coverage": "npx truffle run coverage",
11+
"flat-file": "cd contracts && truffle-flattener fileName.sol > ../flats/fileName.sol",
12+
"compile": "npx truffle compile",
13+
"migrate": "npx truffle migrate --reset",
14+
"migrate-weth": "cd weth && truffle migrate",
15+
"migrate-uniswap-factory": "node deploy-factory.js",
16+
"migrate-uniswap-router": "cd uniswap && truffle migrate",
17+
"migrate-main": "truffle migrate",
18+
"bridge": "ethereum-bridge -H localhost:9545 -a 1 --dev",
19+
"migrate-all": "npm run migrate-weth && npm run migrate-uniswap-factory && npm run migrate-uniswap-router && npm run migrate-main"
20+
},
21+
"resolutions": {
22+
"serialize-javascript": "^3.1.0"
23+
},
24+
"dependencies": {
25+
"@babel/core": "*",
26+
"@uniswap/v2-core": "^1.0.1",
27+
"@uniswap/v2-periphery": "^1.1.0-beta.0",
28+
"sha3": "^2.1.2",
29+
"solc": "^0.6.12",
30+
"solium": "^1.0.0"
31+
},
32+
"devDependencies": {
33+
"@truffle/hdwallet-provider": "^1.2.6",
34+
"bignumber.js": "^8.0.2",
35+
"chai": "^4.2.0",
36+
"chai-bignumber": "^3.0.0",
37+
"coveralls": "^3.1.1",
38+
"eslint": "^5.13.0",
39+
"eth-gas-reporter": "^0.1.12",
40+
"ethereum-bridge": "^0.6.2",
41+
"ethlint": "1.2.3",
42+
"ganache-cli": "^6.9.1",
43+
"serialize-javascript": "^4.0.0",
44+
"solidity-coverage": "^0.7.16",
45+
"truffle": "^5.4.3",
46+
"web3": "^1.3.5"
47+
}
48+
}

test/exceptionsHelpers.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const errorString = "VM Exception while processing transaction: ";
2+
3+
async function tryCatch(promise, reason) {
4+
try {
5+
await promise;
6+
throw null;
7+
}
8+
catch (error) {
9+
assert(error, "Expected a VM exception but did not get one");
10+
assert(error.message.search(errorString + reason) >= 0, "Expected an error containing '" + errorString + reason + "' but got '" + error.message + "' instead");
11+
}
12+
};
13+
14+
module.exports = {
15+
catchRevert : async function(promise) {await tryCatch(promise, "revert" );},
16+
catchOutOfGas : async function(promise) {await tryCatch(promise, "out of gas" );},
17+
catchInvalidJump : async function(promise) {await tryCatch(promise, "invalid JUMP" );},
18+
catchInvalidOpcode : async function(promise) {await tryCatch(promise, "invalid opcode" );},
19+
catchStackOverflow : async function(promise) {await tryCatch(promise, "stack overflow" );},
20+
catchStackUnderflow : async function(promise) {await tryCatch(promise, "stack underflow" );},
21+
catchStaticStateChange : async function(promise) {await tryCatch(promise, "static state change");},
22+
};

test/token.test.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const Token = artifacts.require("Token");
2+
3+
const catchRevert = require("./exceptionsHelpers.js").catchRevert;
4+
5+
require("./utils");
6+
7+
const BN = web3.utils.BN;
8+
9+
// TESTING PARAMETERS
10+
const SECONDS_IN_DAY = 30;
11+
const FIVE_ETH = web3.utils.toWei("5");
12+
const STATIC_SUPPLY = web3.utils.toWei("5000000");
13+
14+
const getLastEvent = async (eventName, instance) => {
15+
const events = await instance.getPastEvents(eventName, {
16+
fromBlock: 0,
17+
toBlock: "latest",
18+
});
19+
return events.pop().returnValues;
20+
};
21+
22+
contract("Token", ([owner, user1, user2, random]) => {
23+
24+
let token;
25+
let launchTime;
26+
27+
before(async () => {
28+
token = await Token.new();
29+
});
30+
31+
describe.skip("Initial Variables", () => {
32+
33+
it("should have correct token name", async () => {
34+
const name = await token.name();
35+
assert.equal(
36+
name,
37+
"Token"
38+
);
39+
});
40+
41+
it("should have correct token symbol", async () => {
42+
const symbol = await token.symbol();
43+
assert.equal(
44+
symbol,
45+
"TKN"
46+
);
47+
});
48+
49+
it("should have correct token decimals", async () => {
50+
const decimals = await token.decimals();
51+
assert.equal(
52+
decimals,
53+
18
54+
);
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)