Skip to content

Instantly share code, notes, and snippets.

View ilblackdragon's full-sized avatar

Illia Polosukhin ilblackdragon

  • NEAR Protocol
  • San Francisco, CA
View GitHub Profile

Ethereum has a conflict between native token ETH and third-party tokens.

The first example of it is Maker. In case of Maker, the user locks ETH and gets PETH (Pooled ETH) token, which then gets locked into CDPs and that issues DAI (see whiteboard for more detail). At the same time DAI borrow rate accrues to MKR token holders (via burning MKR).

There is clearly in this model a way to remove MKR and just buy more ETH for the Pool, accruing value to all of Pool holders instead (also would incentivize holding CDPs longer as it now becomes a yield generating asset) Or even better, by buying and burning ETH - value would accrue to ALL ETH holders.

Similar story goes when a third-party token is used for transaction fees or as intermediate. There are no direct captures in such a token, and it can be removed by forking the contract. The most known example is Uniswap being a Bancor without their BNT token. Bancor is splitting value between liquidity providers and BNT vs in Uniswap the value only goes to liquidity

@ilblackdragon
ilblackdragon / truffle.js
Created February 14, 2020 06:33
Truffle example
const { NearProvider, nearlib } = require('near-web3-provider');
const web3 = require('web3');
ACCOUNT_ID = 'illia'
const fileKeyStore = new nearlib.keyStores.UnencryptedFileSystemKeyStore('neardev');
const networkId = 'default';
const defaultAccount = web3.utils.keccak256(ACCOUNT_ID).slice(26, 66);
module.exports = {
networks: {
@ilblackdragon
ilblackdragon / serialize.rs
Last active October 19, 2023 03:07
Protobuf vs Bincode vs CBOR
/*
test serialize_bincode_block ... bench: 2,187,247 ns/iter (+/- 305,944)
test serialize_bincode_block2 ... bench: 2,214,480 ns/iter (+/- 359,709)
test serialize_bincode_tx ... bench: 2,280 ns/iter (+/- 222)
test serialize_cbor_block ... bench: 1,950,128 ns/iter (+/- 188,149)
test serialize_cbor_tx ... bench: 2,182 ns/iter (+/- 334)
test serialize_proto_block ... bench: 3,688,611 ns/iter (+/- 541,517)
test serialize_proto_tx ... bench: 3,567 ns/iter (+/- 449)
@ilblackdragon
ilblackdragon / exception_hook.py
Last active December 11, 2017 23:50
Exception Hook for not print debugging
import sys
import traceback
def _format_value(key, value, first_n=20, last_n=20):
s = repr(value)
s = s.replace('\n', ' ').strip()
if len(s) > first_n + last_n + 3:
s = s[:first_n] + "..." + s[-last_n:]
return "%s: %s" % (key, s)
@ilblackdragon
ilblackdragon / tree_lstm_folded.py
Last active September 6, 2017 23:17
Tree LSTM folded
from pytorch_tools import torchfold
def encode_tree_fold(fold, tree):
def encode_node(node):
if node.is_leaf():
return fold.add('leaf', node.id).split(2)
else:
left_h, left_c = encode_node(node.left)
right_h, right_c = encode_node(node.right)
return fold.add('children', left_h, left_c, right_h, right_c).split(2)
@ilblackdragon
ilblackdragon / tree_lstm_regular.py
Last active September 6, 2017 23:16
TreeLSTM regular model
class TreeLSTM(nn.Module):
def __init__(self, num_units):
super(TreeLSTM, self).__init__()
self.num_units = num_units
self.left = nn.Linear(num_units, 5 * num_units)
self.right = nn.Linear(num_units, 5 * num_units)
def forward(self, left_in, right_in):
lstm_in = self.left(left_in[0])
lstm_in += self.right(right_in[0])
@ilblackdragon
ilblackdragon / torchfold_api.py
Created September 6, 2017 20:56
TorchFold API
class TorchFold(object):
def __init__(self, versatible=False, cuda=False):
...
def add(self, op, *args):
...
def apply(self, nn, return_values):
...
import collections
import torch
from torch.autograd import Variable
import torch.nn as nn
from torch import optim
import torch.nn.functional as F
import utils
@ilblackdragon
ilblackdragon / seq2seq.py
Last active May 22, 2022 21:42
Example of Seq2Seq with Attention using all the latest APIs
import logging
import numpy as np
import tensorflow as tf
from tensorflow.contrib import layers
GO_TOKEN = 0
END_TOKEN = 1
UNK_TOKEN = 2
import random
import pandas
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import LabelEncoder
from sklearn.utils import check_array
import tensorflow as tf
from tensorflow.contrib import layers