Skip to content

Commit

Permalink
Merge pull request #157 from makerdao/staging
Browse files Browse the repository at this point in the history
staging -> master
  • Loading branch information
tyler17 authored Sep 12, 2023
2 parents 85855f7 + d8b766c commit a024031
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 62 deletions.
34 changes: 34 additions & 0 deletions insert_poll_creators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require('dotenv').config();

const pgp = require('pg-promise')();

const db = pgp({
host: process.env.VL_DB_HOST,
port: process.env.VL_DB_PORT,
database: process.env.VL_DB_DATABASE,
user: process.env.VL_DB_USER,
password: process.env.VL_DB_PASSWORD
});

const authorizedCreatorsArray = (process.env.AUTHORIZED_CREATORS || '').split(',').map(creator => creator.toLowerCase());

const deleteQuery = 'DELETE FROM polling.creators';
const insertQuery = 'INSERT INTO polling.creators (address) VALUES ($1)';

async function executeQueries() {
try {
await db.none(deleteQuery);
console.log('All previous creators deleted.');

for (const creator of authorizedCreatorsArray) {
await db.none(insertQuery, creator);
console.log(`Creator ${creator} added successfully.`);
}

console.log('All authorized creators added successfully.');
} catch (err) {
console.error('Error: ', err);
}
}

executeQueries().catch(err => console.error('Error: ', err));
50 changes: 50 additions & 0 deletions migrations/072-polls-vote-breakdown.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
create or replace function api.polls_vote_breakdown(param_poll_ids integer[])
returns table (
poll_id INTEGER,
option_id CHARACTER,
mkr_support NUMERIC
) as $$
with merged_votes as (
SELECT DISTINCT (poll_id) poll_id, voter, option_id_raw, timestamp
FROM (
SELECT voter, option_id_raw, poll_id, b.timestamp
FROM polling.voted_event ve
JOIN vulcan2x.block b ON ve.block_id = b.id
UNION
SELECT voter, option_id_raw, poll_id, ba.timestamp
FROM polling.voted_event_arbitrum vea
JOIN vulcan2xarbitrum.block ba ON vea.block_id = ba.id
) sub1
),
votes_with_end_date as (
select voter, v.poll_id, option_id_raw, v.timestamp as vote_time, p.end_date, (
select id from vulcan2x.block where timestamp <= to_timestamp(end_date)
order by timestamp desc limit 1
) as end_block
from merged_votes v left join api.active_polls() p
on v.poll_id = p.poll_id
where p.poll_id is not null
),
unique_votes_with_mkr as (
select voter, poll_id, option_id_raw, polling.reverse_voter_weight(voter, end_block) mkr_balance
from (
select
polling.unique_voter_address(voter, end_block) voter,
poll_id,
(array_agg(option_id_raw ORDER BY vote_time DESC))[1] AS option_id_raw,
end_block
from votes_with_end_date
where vote_time <= to_timestamp(end_date)
group by poll_id, voter, end_block
order by poll_id, voter
) vwed
)
select
poll_id,
option_id_raw,
sum(mkr_balance) as mkr_support
from unique_votes_with_mkr
where poll_id = ANY (param_poll_ids)
group by poll_id, option_id_raw
order by poll_id, option_id_raw
$$ language sql stable strict;
9 changes: 9 additions & 0 deletions migrations/073-poll-creators.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
create table polling.creators (
address character varying(66) not null
);

create or replace function api.poll_creators()
returns setof polling.creators as $$
select *
from polling.creators;
$$ language sql stable strict;
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"scripts": {
"start-etl": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-etl/dist/bin/etl ./config.js",
"start-sync": "yarn migrate",
"migrate": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-etl/dist/bin/migrate ./config.js",
"migrate:only": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-etl/dist/bin/migrate ./config.js",
"migrate": "yarn migrate:only && yarn insert-poll-creators",
"start-api": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-graphql-api/dist/index.js ./config.js",
"test": "jest",
"test:ci": "./tests/run-tests.sh",
"repl": "node --experimental-repl-await -r ./loadenv.js ./repl"
"repl": "node --experimental-repl-await -r ./loadenv.js ./repl",
"insert-poll-creators": "node insert_poll_creators.js"
},
"dependencies": {
"@makerdao-dux/spock-etl": "^0.2.0",
Expand All @@ -20,13 +22,13 @@
"bignumber.js": "^9.0.2",
"consola": "^2.15.3",
"dotenv-flow": "^2.0.0",
"ethers": "krzkaczor/ethers.js#kk/get-logs-multiple-address-build"
"ethers": "krzkaczor/ethers.js#kk/get-logs-multiple-address-build",
"pg-promise": "10.11.1"
},
"devDependencies": {
"eslint": "^8.23.1",
"eslint-plugin-prettier": "^4.2.1",
"graphql-request": "^1.8.2",
"jest": "^24.8.0",
"pg-promise": "^8.7.2"
"jest": "^24.8.0"
}
}
7 changes: 7 additions & 0 deletions queries/pollCreators.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query pollCreators {
pollCreators {
nodes {
address
}
}
}
9 changes: 9 additions & 0 deletions queries/pollsVoteBreakdown.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query pollsVoteBreakdown($paramPollIds: [Int]!) {
pollsVoteBreakdown(paramPollIds: $paramPollIds) {
nodes {
pollId
optionId
mkrSupport
}
}
}
59 changes: 2 additions & 57 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -938,11 +938,6 @@ asn1@~0.2.3:
dependencies:
safer-buffer "~2.1.0"

assert-options@0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/assert-options/-/assert-options-0.1.3.tgz#ea56c6a67a558eefb9db52c394f2fa92b94bfcde"
integrity sha512-DXrZ5WkCv/igD+H8OmeUTl9k0pBhYSTdyA7DRZoSJERCzQ8Z2v85yDjkhYVnHUOeCXGfCNKaogRbLWQsIQbtpg==

assert-options@0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/assert-options/-/assert-options-0.7.0.tgz#82c27618d9c0baa5e9da8ef607ee261a44ed6e5e"
Expand Down Expand Up @@ -3704,11 +3699,6 @@ makeerror@1.0.12:
dependencies:
tmpl "1.0.5"

manakin@0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/manakin/-/manakin-0.5.2.tgz#abe3df430ca6085f6983f6e4cf5af0298f4d30cc"
integrity sha512-pfDSB7QYoVg0Io4KMV9hhPoXpj6p0uBscgtyUSKCOFZe8bqgbpStfgnKIbF/ulnr6U3ICu4OqdyxAqBgOhZwBQ==

map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
Expand Down Expand Up @@ -4232,11 +4222,6 @@ pg-int8@1.0.1:
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==

pg-minify@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/pg-minify/-/pg-minify-1.4.1.tgz#ff9a9febefa6cec53055e2fd24e3115a275e2a08"
integrity sha512-8aZ9xdx7Pe/ppFYVOqvU5KgmM6ttXjaBlsl9Y8yzrUH4xSNVucJKKOwm4Y4H+LCvzZGjZIm4Rkf2Ajt5ixtkBQ==

pg-minify@1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/pg-minify/-/pg-minify-1.6.2.tgz#055acfe862cfca3ca0a529020846b0f308d68e70"
Expand All @@ -4247,7 +4232,7 @@ pg-packet-stream@^1.1.0:
resolved "https://registry.yarnpkg.com/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz#e45c3ae678b901a2873af1e17b92d787962ef914"
integrity sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg==

pg-pool@^2.0.10, pg-pool@^2.0.4:
pg-pool@^2.0.10:
version "2.0.10"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.10.tgz#842ee23b04e86824ce9d786430f8365082d81c4a"
integrity sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg==
Expand All @@ -4257,7 +4242,7 @@ pg-pool@^3.4.1, pg-pool@^3.5.1:
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.5.1.tgz#f499ce76f9bf5097488b3b83b19861f28e4ed905"
integrity sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==

pg-promise@^10.4.4:
pg-promise@10.11.1, pg-promise@^10.4.4:
version "10.11.1"
resolved "https://registry.yarnpkg.com/pg-promise/-/pg-promise-10.11.1.tgz#62348927da636aa74d2c20510cfbd12e85f104ae"
integrity sha512-HAv32WSKf2m2RqHerW5RmANn/mcXIwWXbg/gOfGQcoS0SE+8iBi3Jj4JmoR4PNzSEozo/y/npy4e6F16psOItw==
Expand All @@ -4267,17 +4252,6 @@ pg-promise@^10.4.4:
pg-minify "1.6.2"
spex "3.2.0"

pg-promise@^8.7.2:
version "8.7.5"
resolved "https://registry.yarnpkg.com/pg-promise/-/pg-promise-8.7.5.tgz#d66beb86b041ae6e9dc66c4b5c7fb04dafcd18bb"
integrity sha512-r/OmS1b1i0nA0KHqlbcAoMLoNo3EGUdcZxaseyXnHrzepcS8ciK516Lw6/lIb6AeWI85ZOBSNdiPlw22xoFx3A==
dependencies:
assert-options "0.1.3"
manakin "0.5.2"
pg "7.11.0"
pg-minify "1.4.1"
spex "2.2.0"

pg-protocol@*, pg-protocol@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.5.0.tgz#b5dd452257314565e2d54ab3c132adc46565a6a0"
Expand All @@ -4304,30 +4278,6 @@ pg-types@^2.1.0, pg-types@^2.2.0:
postgres-date "~1.0.4"
postgres-interval "^1.1.0"

pg-types@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.0.1.tgz#b8585a37f2a9c7b386747e44574799549e5f4933"
integrity sha512-b7y6QM1VF5nOeX9ukMQ0h8a9z89mojrBHXfJeSug4mhL0YpxNBm83ot2TROyoAmX/ZOX3UbwVO4EbH7i1ZZNiw==
dependencies:
pg-int8 "1.0.1"
postgres-array "~2.0.0"
postgres-bytea "~1.0.0"
postgres-date "~1.0.4"
postgres-interval "^1.1.0"

pg@7.11.0:
version "7.11.0"
resolved "https://registry.yarnpkg.com/pg/-/pg-7.11.0.tgz#a8b9ae9cf19199b7952b72957573d0a9c5e67c0c"
integrity sha512-YO4V7vCmEMGoF390LJaFaohWNKaA2ayoQOEZmiHVcAUF+YsRThpf/TaKCgSvsSE7cDm37Q/Cy3Gz41xiX/XjTw==
dependencies:
buffer-writer "2.0.0"
packet-reader "1.0.0"
pg-connection-string "0.1.3"
pg-pool "^2.0.4"
pg-types "~2.0.0"
pgpass "1.x"
semver "4.3.2"

pg@8.7.1:
version "8.7.1"
resolved "https://registry.yarnpkg.com/pg/-/pg-8.7.1.tgz#9ea9d1ec225980c36f94e181d009ab9f4ce4c471"
Expand Down Expand Up @@ -5120,11 +5070,6 @@ spdx-license-ids@^3.0.0:
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz#50c0d8c40a14ec1bf449bae69a0ea4685a9d9f95"
integrity sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g==

spex@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/spex/-/spex-2.2.0.tgz#b0d825f43ca3c88a35bda79553296c83c07b4d63"
integrity sha512-iwBxqKe4ZKD+P/i/WdzWw5qxmerHvzVb29wQm4zwYaDPuwsTKjS7nbqt8OyBSLAi2q0ZFUN3F2b4erX0UwF0fA==

spex@3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/spex/-/spex-3.2.0.tgz#fa4a21922407e112624977b445a6d634578a1127"
Expand Down

0 comments on commit a024031

Please sign in to comment.