-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from makerdao/staging
staging -> master
- Loading branch information
Showing
7 changed files
with
118 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query pollCreators { | ||
pollCreators { | ||
nodes { | ||
address | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters