Skip to content

Instantly share code, notes, and snippets.

View erc20.js
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address who) external view returns (uint256);
function allowance(address owner, address spender)
external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
View deploy.ts
import dotenv from "dotenv";
import { getDefaultProvider, Wallet } from "ethers";
import { deployContract } from "ethereum-waffle";
import SKETokenArtifact from "../build/SKEToken.json";
import { SKEToken } from "../types/ethers-contracts/SKEToken";
dotenv.config();
async function deploy() {
const mnemonic = process.env["MNEMONIC"] || "";
View waffle.test.js
import { use, expect } from "chai";
import { solidity, MockProvider, deployContract } from "ethereum-waffle";
import SKETokenArtifact from "../build/SKEToken.json";
import { SKEToken } from "../types/ethers-contracts/SKEToken";
use(solidity);
describe("Counter smart contract", () => {
const provider = new MockProvider();
const [wallet] = provider.getWallets();
View truffle.test.js
const SKEToken = artifacts.require("SKEToken");
contract("2nd SKEToken test", async ([deployer, user1]) => {
it("should put 10000 SKEToken in the first account", async () => {
const token = await SKEToken.new(10000, { from: deployer });
let balance = await token.balanceOf(deployer);
assert.equal(balance.valueOf(), 10000);
});
});
View truffle.js
ropsten: {
provider: () =>
new HDWalletProvider(
process.env["MNEMONIC"],
`https://ropsten.infura.io/v3/939fb730f6cd4449aeb9f101cca7277e`
),
network_id: 3, // Ropsten's id
gas: 5500000, // Ropsten has a lower block limit than mainnet
confirmations: 2, // # of confs to wait between deployments. (default: 0)
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
View waffle.test.js
import { use, expect } from "chai";
import { solidity, createMockProvider, getWallets, deployContract } from 'ethereum-waffle'
import * as ERC20TokenJSON from '../build/ERC20Token.json'
import { ERC20Token } from '../typed-contracts/ERC20Token'
use(solidity);
describe('Counter smart contract', () => {
const provider = createMockProvider();
const [wallet] = getWallets(provider);
View uniswap-main.py
if __name__ == '__main__':
num_traders = 100
num_arbitrageurs = 10
trader_dai = 10000
trader_eth = 1000
uniswap_dai = 1000000
uniswap_eth = 10000
model = UniswapModel(num_traders, num_arbitrageurs, trader_dai, trader_eth, uniswap_dai, uniswap_eth)
for i in range(100):
View uniswap-model.py
class UniswapModel(Model):
def __init__(self, num_traders, num_arbitrageurs, trader_dai, trader_eth, uniswap_dai, uniswap_eth):
super().__init__()
self.num_traders = num_traders
self.schedule = RandomActivation(self)
self.uniswap = Uniswap(1, self, uniswap_dai, uniswap_eth)
for i in range(num_traders):
trader = Trader(i, self, trader_eth, trader_dai, i < num_arbitrageurs)
self.schedule.add(trader)
View uniswap-agent.py
def transfer(from_agent, to_agent, currency, amount):
from_amount = getattr(from_agent, currency, 0)
to_amount = getattr(to_agent, currency, 0)
setattr(from_agent, currency, from_amount - amount)
setattr(to_agent, currency, to_amount + amount)
class Uniswap(Agent):
def __init__(self, unique_id, model, dai, eth):
super().__init__(unique_id, model)
self.dai = dai
View trader.py
class Trader(Agent):
def __init__(self, unique_id, model, eth, dai, is_arbitrageur):
super().__init__(unique_id, model)
self.eth = eth
self.dai = dai
self.is_arbitrageur = is_arbitrageur
def buy_eth(self):
amount = min(random.random() * 1000, self.dai)
self.model.uniswap.trade(self, "eth", amount)