Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am lukesaunders on github.
* I am lukedelphi (https://keybase.io/lukedelphi) on keybase.
* I have a public key ASAUhZZQElyWJtLmcUg6VOU-UBDn0_V8dp8FtGWm37H3GQo
To claim this, I am signing this object:

How to calculate depth from events

Keeping a running total of RUNE depth per pool requires the handling of several events: stakes, swaps, adds, rewards, errata, gas, emissions (?).

Here I will go through the events one by one and describe how to update the pool depths based on their values.

Stake event

Stake events are fired when an LP adds stake to a pool.

import knex from '../../../lib/database.js';
import sleep from '../../../lib/utils/sleep';
import { compareAsc, format, addDays, subDays, addYears, subMonths, subYears, parse } from 'date-fns';
import Web3 from 'web3';
import contractABI from './pooledStakingAbi.js';
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
process.on('unhandledRejection', up => { throw up });
const web3 = new Web3('http://localhost:9545');
specVersion: 0.0.2
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: Contract
network: mainnet
source:
address: "0x84edffa16bb0b9ab1163abb0a13ff0744c11272f"
abi: Contract
type Query {
pool(poolId: String!): Pool
pools(orderBy: PoolOrderAttribute, limit: Int): [Pool]
poolHistory(from: Int, until: Int, interval: Interval): PoolHistory
}
# A type representing the current state of a pool. To get historical data or averages use XXX
type Pool {
# the asset name in the format "CHAIN.TICKER-SYMBOL" e.g. "BNB.BTCB-101"
asset: String!
@lukesaunders
lukesaunders / event_job_collection.rb
Created January 30, 2012 01:39
Model for creating multiple model instances at once
class EventJobCollection
include ActiveModel::AttributeMethods
extend ActiveModel::Naming
include ActiveModel::Conversion
attr_accessor :event, :jobs
delegate :id, :to => :event, :prefix => :event
def initialize(event, event_params = nil)
@lukesaunders
lukesaunders / edit.html.erb
Created January 30, 2012 00:06
Create multiple models at once using fields_for
<h1>Editing event</h1>
<%= twitter_bootstrap_form_for(@event) do |f| %>
<%= f.inputs "General" do %>
<%= render :partial => 'form', :locals => { :f => f } %>
<% end %>
<%= f.inputs "Jobs" do %>
<%= f.fields_for(:jobs, @new_jobs) do |jf| %>
<%= jf.hidden_field :name %>
+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| count(question_id) | question |
+--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 3313 | In the <b>last 3 months</b>, approximately how often have you ridden a bike since the Challenge? |
| 3292 | Thinking about the <b>last 3 months</b>, did you ride your bike...? |
| 2392 | In the last <b>3 months</b>, approximately how ofte
sign_ups_referred_to_date = FlupTrackingEvent.find(:event_type => "sign_up", :inviter => {:$ne => ""}, :created_at => {:$lte => new_time}).to_a
invites_to_date = FlupTrackingEvent.find(:event_type => "external_invite", :created_at => {:$lte => new_time}).to_a
@days << {
:day => this_time,
:invites => FlupTrackingEvent.find(:event_type => "external_invite", :created_at => {:$gte => this_time, :$lte => new_time}).to_a,
:sign_ups_total => FlupTrackingEvent.find(:event_type => "sign_up", :created_at => {:$gte => this_time, :$lte => new_time}).to_a,
:sign_ups_reffered => FlupTrackingEvent.find(:event_type => "sign_up", :inviter => {:$ne => ""}, :created_at => {:$gte => this_time, :$lte => new_time}).to_a,
:sign_ups_reffered_to_date => sign_ups_referred_to_date,
:items => FlupTrackingEvent.find(:created_at => {:$gte => this_time, :$lte => new_time}).to_a,
REQUEST:
{:method=>"moo.pack.createTrialPartnerPack", :product=>"businesscard", :pack=>"{\"numCards\":50,\"productCode\":\"businesscard\",\"productVersion\":1,\"imageBasket\":{\"immutable\":false,\"items\":[{\"shouldEnhance\":false,\"copyrightOwner\":null,\"cacheId\":\"partner_interface_uploader:b9df2359-1018-558545d5-4e4a7003-aa04.pdf\",\"type\":\"front\",\"resourceUri\":\"filestore://image_original/b9df2359-1018-558545d5-4e4a7003-aa04.pdf\",\"removable\":true,\"croppable\":true,\"imageBox\":null,\"imageItems\":[{\"type\":\"print\",\"resourceUri\":\"https://secure.moo.com/is/o/b9df2359-1018-558545d5-4e4a7003-aa04.pdf\",\"width\":1500,\"height\":1007,\"rotation\":0},{\"type\":\"preview\",\"resourceUri\":\"https://secure.moo.com/is/r/1024/b9df2359-1018-558545d5-4e4a7003-aa04.png\",\"width\":1024,\"height\":687,\"rotation\":0},{\"type\":\"thumbnail\",\"resourceUri\":\"https://secure.moo.com/is/t/75/b9df2359-1018-558545d5-4e4a7003-aa04.png\",\"width\":75,\"height\":75,\"rotation\":0}]},{\"shouldEnhance\":false,\