Skip to content

Instantly share code, notes, and snippets.

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
@yurenju
yurenju / trader.py
Last active December 15, 2019 03:56
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)
const ethers = require("ethers");
(async function() {
const address = "0x477b8D5eF7C2C42DB84deB555419cd817c336b6F";
const provider = ethers.getDefaultProvider();
const block1 = 8821739;
const block2 = 8821081;
let balance1 = ethers.utils.formatEther(await provider.getBalance(address, block1));
let balance2 = ethers.utils.formatEther(await provider.getBalance(address, block2));
console.log(`balance for block ${block1}: ${balance1}`);
async function withdraw() {
console.log(chalk.green("Executing withdraw"));
const withdrawValue = 10;
const [, noteB] = transferNotes;
const noteC = await note.create(alice.publicKey, splitValues[1] - withdrawValue);
const withdrawProof = new JoinSplitProof(
[noteB],
[noteC],
alice.address,
withdrawValue,
async function transferFromBobToAlice() {
const msg =
`Split note to note A with ${splitValues[0]} value for bob & ` +
`note B with ${splitValues[1]} value for alice`;
console.log(chalk.green(msg));
const noteA = await note.create(bob.publicKey, splitValues[0]);
const noteB = await note.create(alice.publicKey, splitValues[1]);
transferNotes = [noteA, noteB];
const transferProof = new JoinSplitProof(
async function deposit() {
const depositValue = 100;
console.log(chalk.green(`Deposit ${depositValue} from Bob's public erc20 to a aztec note`));
console.log(`- executing bob.signers.erc20.approve()`);
await (await bob.signers.erc20.approve(contractAddresses.ace, depositValue)).wait();
const depositNote = await note.create(bob.publicKey, depositValue);
depositNotes = [depositNote];
const proof = new JoinSplitProof([], depositNotes, bob.address, depositValue * -1, bob.address);
async function mint() {
const mintValue = 200;
console.log(chalk.green(`Minting ${mintValue} to Bob`));
const tx = await bob.signers.erc20.mint(bob.address, mintValue);
await tx.wait();
}
module.exports = ({ config, mode }) => {
// handle scss resource in vue file
const scssRule = {
test: /\.scss$/,
oneOf: [
{
resourceQuery: /\?vue/,
use: ["vue-style-loader", "css-loader", "postcss-loader", "sass-loader"]
}
]
// Register on client side
var verifier = srp.computeVerifier(params, salt, identity, password);
createAccount(identity, verifier);
// Login
// Generate A on client side
srp.genKey(function(secret1) {
var c = new srp.Client(params, salt, identity, password, secret1);
var srpA = c.computeA();
sendToServer(srpA);

Keybase proof

I hereby claim:

  • I am yurenju on github.
  • I am yurenju (https://keybase.io/yurenju) on keybase.
  • I have a public key ASAu_BLzXh8iYRCd1gXnZEFtsFWk-7ZfQGFy_NKU3K4QKgo

To claim this, I am signing this object: