forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e26a9f2
commit 945ab3f
Showing
3 changed files
with
412 additions
and
0 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,12 @@ | ||
CREATE TABLE IF NOT EXISTS lsd ( | ||
timestamp timestamp NOT NULL, | ||
name text NOT NULL, | ||
symbol text NOT NULL, | ||
address text NOT NULL, | ||
type text, | ||
"expectedRate" numeric, | ||
"marketRate" numeric, | ||
"ethPeg" numeric | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS lsd_address_timestamp_idx ON lsd (address, timestamp DESC); |
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,57 @@ | ||
const minify = require('pg-minify'); | ||
|
||
const { pgp, connect } = require('../utils/dbConnection'); | ||
|
||
const getLsd = async () => { | ||
const conn = await connect(); | ||
|
||
const query = minify( | ||
` | ||
SELECT | ||
DISTINCT ON (address) * | ||
FROM | ||
lsd | ||
ORDER BY | ||
address, | ||
timestamp DESC | ||
`, | ||
{ compress: true } | ||
); | ||
|
||
const response = await conn.query(query); | ||
|
||
if (!response) { | ||
return new AppError(`Couldn't get data`, 404); | ||
} | ||
|
||
return response; | ||
}; | ||
|
||
const insertLsd = async (payload) => { | ||
const conn = await connect(); | ||
|
||
const columns = [ | ||
'timestamp', | ||
'name', | ||
'symbol', | ||
'address', | ||
{ name: 'type', def: null }, | ||
{ name: 'expectedRate', def: null }, | ||
{ name: 'marketRate', def: null }, | ||
{ name: 'ethPeg', def: null }, | ||
]; | ||
const cs = new pgp.helpers.ColumnSet(columns, { table: 'lsd' }); | ||
const query = pgp.helpers.insert(payload, cs); | ||
const response = await conn.result(query); | ||
|
||
if (!response) { | ||
return new AppError(`Couldn't insert/update data`, 404); | ||
} | ||
|
||
return response; | ||
}; | ||
|
||
module.exports = { | ||
getLsd, | ||
insertLsd, | ||
}; |
Oops, something went wrong.