Skip to content

Instantly share code, notes, and snippets.

View patitonar's full-sized avatar

Gerardo Nardelli patitonar

View GitHub Profile
@patitonar
patitonar / JavascriptPrototypeExample.js
Created November 22, 2018 00:15
An example of how javascript prototype works
// Create a Person function
function Person(first, last) {
this.firstName = first;
this.lastName = last;
}
// Function Person and Person.prototype are created
typeof Person // "function"
typeof Person.prototype // "object"
@patitonar
patitonar / ForeignBridgeNativeToErcFromv1toV220.sol
Last active February 7, 2019 19:00
Update POA Bridge from v1 to v2.2.0
pragma solidity 0.4.24;
// File: contracts/ERC677Receiver.sol
contract ERC677Receiver {
function onTokenTransfer(address _from, uint _value, bytes _data) external returns(bool);
}
// File: openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol
@patitonar
patitonar / HomeBridgeNativeToErcFromv1toV220
Created February 7, 2019 19:00
Update POA Bridge from v1 to v2.2.0
pragma solidity 0.4.24;
// File: contracts/IBridgeValidators.sol
interface IBridgeValidators {
function isValidator(address _validator) public view returns(bool);
function requiredSignatures() public view returns(uint256);
function owner() public view returns(address);
}
@patitonar
patitonar / HomeBridgeErcToNative.sol
Created April 3, 2019 19:13
HomeBridgeErcToNative.sol for xDai Bridge implementation that fixes zero value transfer from foreign
// File: contracts/libraries/SafeMath.sol
pragma solidity 0.4.24;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
@patitonar
patitonar / DepositsV1.sol
Created September 12, 2019 15:10
Deposit example in solidity. Get contract balance, anyone can deposit, anyone can withdraw all the balance
pragma solidity 0.5.11;
contract Deposits {
event Deposited(address indexed payee, uint256 weiAmount);
event Withdrawn(address indexed payee, uint256 weiAmount);
function deposit() public payable {
emit Deposited(msg.sender, msg.value);
}
@patitonar
patitonar / DepositsV2.sol
Created September 12, 2019 15:12
Deposit example in solidity. Get contract balance, get balance of an account, anyone can deposit, anyone can withdraw their own balance
pragma solidity 0.5.11;
contract DepositsV2 {
event Deposited(address indexed payee, uint256 weiAmount);
event Withdrawn(address indexed payee, uint256 weiAmount);
mapping(address => uint256) private _deposits;
function deposit() public payable {
[
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
@patitonar
patitonar / BasicAMBErc677ToErc677.test.js
Created October 30, 2019 13:59
Failing test that proves that setTotalSpentPerDay is called twice
it('should prevent emitting the event twice when ERC677 used by relayTokens and ERC677 is not owned by token manager', async function() {
// Given
const erc677Token = await ERC677BridgeToken.new('test', 'TST', 18)
await erc677Token.mint(user, twoEthers, { from: owner }).should.be.fulfilled
contract = this.bridge
await contract.initialize(
bridgeContract.address,
mediatorContract.address,
BRIDGE_MODE=ERC_TO_ERC
DEPLOYMENT_ACCOUNT_PRIVATE_KEY=01F903CE0C960FF3A9E68E80FF5FFC344358D80CE1C221C3F9711AF07F83A3BD
DEPLOYMENT_GAS_LIMIT_EXTRA=0.2
HOME_DEPLOYMENT_GAS_PRICE=1000000000
FOREIGN_DEPLOYMENT_GAS_PRICE=1000000000
GET_RECEIPT_INTERVAL_IN_MILLISECONDS=3000
HOME_RPC_URL=https://api.s0.b.hmny.io
@patitonar
patitonar / ForeignBridgeErcToNative.sol
Last active November 15, 2019 11:58
Simplified Foreign Bridge for xDai upgrade to only include migrateToMCD functionality. Took the following code as base to apply the changes https://etherscan.io/address/0x0d3726e5a9f37234d6b55216fc971d30f150a60f#code
/**
*Submitted for verification at Etherscan.io on 2018-12-19
*/
pragma solidity 0.4.24;
// File: contracts/ERC677Receiver.sol
contract ERC677Receiver {
function onTokenTransfer(address _from, uint _value, bytes _data) external returns(bool);