Skip to content

Commit

Permalink
create new position views to include isVested in leo in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-d committed Sep 10, 2024
1 parent c3eff8a commit 57e4796
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/faucet.superposition/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions cmd/graphql.ethereum/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions cmd/graphql.ethereum/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions cmd/graphql.ethereum/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@ type SeawaterPosition {
"""
upper: Int!

"""
True if this position is currently vested in Leo, false otherwise.
"""
isVested: Boolean!

"""
Liquidity available in this specific position.
"""
Expand Down
54 changes: 54 additions & 0 deletions db/migrations/1725866798-seawater_positions_vested.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- migrate:up

-- seawater_positions_vested to determine whether positions are vested
-- in Leo by looking at their most recent vest/divest event
CREATE VIEW seawater_positions_vested AS SELECT DISTINCT ON (position_id)
is_vested,
position_id,
created_by
FROM (
SELECT
TRUE AS is_vested,
position_id,
created_by
FROM
events_leo_positionvested
UNION
SELECT
FALSE AS is_vested,
position_id,
created_by
FROM
events_leo_positiondivested
ORDER BY
created_by DESC) a;

CREATE VIEW seawater_positions_2 AS
SELECT
events_seawater_mintPosition.created_by AS created_by,
events_seawater_mintPosition.block_hash AS block_hash,
events_seawater_mintPosition.transaction_hash AS transaction_hash,
events_seawater_mintPosition.block_number AS created_block_number,
events_seawater_mintPosition.pos_id AS pos_id,
COALESCE(transfers.to_, events_seawater_mintPosition.owner) AS owner,
pool,
lower,
upper,
is_vested
FROM events_seawater_mintPosition
LEFT JOIN events_seawater_transferPosition AS transfers
ON transfers.pos_id = events_seawater_mintPosition.pos_id
LEFT JOIN seawater_positions_vested AS vested
ON vested.position_id = events_seawater_mintPosition.pos_id
;

CREATE VIEW seawater_active_positions_3 AS
SELECT
seawater_active_positions_2.*,
COALESCE(is_vested, FALSE) AS is_vested
FROM
seawater_active_positions_2
LEFT JOIN seawater_positions_vested ON seawater_active_positions_2.pos_id = seawater_positions_vested.position_id
;

-- migrate:down
1 change: 1 addition & 0 deletions lib/types/seawater/seawater.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Position struct {
Pool types.Address `json:"pool"`
Lower types.Number `json:"lower"`
Upper types.Number `json:"upper"`
IsVested bool `json:"is_vested"`
}

// PositionSnapshot taken from snapshot_positions_log_1. Used to service
Expand Down

0 comments on commit 57e4796

Please sign in to comment.