Skip to content

Instantly share code, notes, and snippets.

View gorgos's full-sized avatar

Markus Waas gorgos

View GitHub Profile
fn instantiate2_address_impl(
checksum: &[u8],
creator: &CanonicalAddr,
salt: &[u8],
msg: &[u8],
) -> Result<CanonicalAddr, Instantiate2AddressError> {
if checksum.len() != 32 {
return Err(Instantiate2AddressError::InvalidChecksumLength);
}
@gorgos
gorgos / ERC20.sol
Created November 28, 2021 01:18
Solana ERC20.sol: Token contract for use with solang compiler
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
contract ERC20 {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
@gorgos
gorgos / MultiSwap.sol
Created August 22, 2021 11:04
Example for how to swap multiple tokens in one on Ropsten
// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;
import "https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/interfaces/ISwapRouter.sol";
import "https://github.com/Uniswap/uniswap-v3-periphery/blob/main/contracts/interfaces/IQuoter.sol";
import {IERC20, SafeERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v3.4-solc-0.7/contracts/token/ERC20/SafeERC20.sol";
interface IUniswapRouter is ISwapRouter {
@gorgos
gorgos / High-Stakes Roulette Example
Last active July 17, 2023 03:07
Example for a contract for playing high-stakes Roulette on the blockchain
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BankOwned {
address public bankAddress;
constructor() {
bankAddress = msg.sender;
}
@gorgos
gorgos / ExampleSlidingWindowOracleDaiWethKovan.sol
Created January 9, 2021 20:16
ExampleSlidingWindowOracle with DAI + WETH for Kovan.
pragma solidity 0.6.6;
pragma experimental ABIEncoderV2;
import "https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/interfaces/IUniswapV2Pair.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/FixedPoint.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/FullMath.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/Babylonian.sol";
import "https://github.com/Uniswap/uniswap-lib/blob/master/contracts/libraries/BitMath.sol";
library SafeMath {
@gorgos
gorgos / TokenSwapWith0x.sol
Last active January 28, 2024 03:42
0x API Integration Example
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.4;
interface IERC20 {
function balanceOf(address owner) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
@gorgos
gorgos / BalancerExample.sol
Last active October 31, 2021 01:37
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.7.2+commit.51b20bc0.js&optimize=true&gist=
// SPDX-License-Identifier: MIT
pragma solidity 0.7.2;
interface PoolInterface {
function swapExactAmountIn(address, uint, address, uint, uint) external returns (uint, uint);
function swapExactAmountOut(address, uint, address, uint, uint) external returns (uint, uint);
}
interface TokenInterface {
function balanceOf(address) external returns (uint);
@gorgos
gorgos / ExtCodeHashExample.sol
Created June 21, 2020 00:26
ExtCodeHashExample
// SPDX-License-Identifier: MIT
pragma solidity 0.6.10;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
interface ExternalContractInterface {
function game() external returns(ExtCodeHashExample);
function payoutToWinner(address winner) external;
function withdrawTo(uint roundId, address receiver) external;
receive() external payable;
mapping (address => uint256) gameWeiValues;
mapping (address => uint256) blockHashesToBeUsed;
function playGame() public {
if (!blockHashesToBeUsed[msg.sender]) {
// first run, determine block hash to be used
blockHashesToBeUsed[msg.sender] = block.number + 2; // use 2 or more
gameWeiValues[msg.sender] = msg.value;
return;
}