diff --git a/cmd/graphql.ethereum/graph/schema.resolvers.go b/cmd/graphql.ethereum/graph/schema.resolvers.go index fc24f756..5bc561cd 100644 --- a/cmd/graphql.ethereum/graph/schema.resolvers.go +++ b/cmd/graphql.ethereum/graph/schema.resolvers.go @@ -343,7 +343,7 @@ func (r *queryResolver) GetPoolPositions(ctx context.Context, pool string, first positions = model.SeawaterPositionsGlobal(MockGetPoolPositions(p)) return } - stmt := r.DB.Table("seawater_active_positions_4"). + stmt := r.DB.Table("seawater_active_positions_5"). Where("pool = ?", p). Limit(*first). Order("created_by desc") @@ -380,7 +380,7 @@ func (r *queryResolver) GetPosition(ctx context.Context, id int) (position *seaw position = MockGetPosition(id) return } - err = r.DB.Table("seawater_positions_3"). + err = r.DB.Table("seawater_positions_4"). Where("pos_id = ?", id). Scan(&position). Error @@ -405,7 +405,7 @@ func (r *queryResolver) GetPositions(ctx context.Context, wallet string, first * ) return } - stmt := r.DB.Table("seawater_active_positions_4"). + stmt := r.DB.Table("seawater_active_positions_5"). Where("owner = ?", w). Limit(*first). Order("created_by desc") @@ -1093,7 +1093,7 @@ func (r *seawaterPoolResolver) Positions(ctx context.Context, obj *seawater.Pool positions = model.SeawaterPositionsGlobal(MockGetPoolPositions(obj.Token)) return } - stmt := r.DB.Table("seawater_active_positions_4"). + stmt := r.DB.Table("seawater_active_positions_5"). Where("pool = ?", obj.Token). Limit(*first). Order("created_by desc") @@ -1130,7 +1130,7 @@ func (r *seawaterPoolResolver) PositionsForUser(ctx context.Context, obj *seawat positions = model.SeawaterPositionsUser(MockGetPoolPositions(w)) return } - err = r.DB.Table("seawater_active_positions_4"). + err = r.DB.Table("seawater_active_positions_5"). Where("pool = ? and owner = ?", obj.Token, wallet). Scan(&positions). Error @@ -1506,7 +1506,7 @@ func (r *seawaterPositionsGlobalResolver) Next(ctx context.Context, obj *model.S to := time.Unix(int64(*obj.To), 0) // Start to construct a statement based on whether internally a // wallet, or a pool, was used. - stmt := r.DB.Table("seawater_active_positions_4"). + stmt := r.DB.Table("seawater_active_positions_5"). Where("created_by < ?", to). Limit(*first). Order("created_by desc") @@ -1614,7 +1614,7 @@ func (r *seawaterPositionsUserResolver) Next(ctx context.Context, obj *model.Sea to := time.Unix(int64(*obj.To), 0) // Start to construct a statement based on whether internally a // wallet, or a pool, was used. - stmt := r.DB.Table("seawater_active_positions_4"). + stmt := r.DB.Table("seawater_active_positions_5"). Where("created_by < ?", to). Limit(*first). Order("created_by desc") @@ -1853,7 +1853,7 @@ func (r *walletResolver) Positions(ctx context.Context, obj *model.Wallet, first ) return } - stmt := r.DB.Table("seawater_active_positions_4"). + stmt := r.DB.Table("seawater_active_positions_5"). Where("owner = ?", obj.Address). Limit(*first). Order("created_by desc") diff --git a/db/migrations/1732505816-seawater_positions_vested_2.sql b/db/migrations/1732505816-seawater_positions_vested_2.sql new file mode 100644 index 00000000..986832db --- /dev/null +++ b/db/migrations/1732505816-seawater_positions_vested_2.sql @@ -0,0 +1,71 @@ +-- migrate:up + +-- seawater_positions_vested to determine whether positions are vested +-- in Leo by looking at their most recent vest/divest event +-- seawater_positions_vested_2 updates to use positionvested2 and positiondivested2 +CREATE VIEW seawater_positions_vested_2 AS SELECT DISTINCT ON (position_id) + is_vested, + position_id, + owner, + created_by +FROM ( + SELECT + TRUE AS is_vested, + position_id, + created_by, + owner + FROM + events_leo_positionvested2 + UNION + SELECT + FALSE AS is_vested, + position_id, + created_by, + recipient AS owner + FROM + events_leo_positiondivested2 + ORDER BY + created_by DESC) a; + +-- seawater_positions_4 includes owner updates from Leo's positionvested2 +-- and positiondivested2 to support use of the staking proxy contract. +CREATE VIEW seawater_positions_4 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(vested.owner, 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_2 AS vested + ON vested.position_id = events_seawater_mintPosition.pos_id +; + +-- seawater_active_positions_5 includes owner updates from Leo's positionvested2 +-- and positiondivested2 to support use of the staking proxy contract. +CREATE VIEW seawater_active_positions_5 AS +SELECT + seawater_active_positions_4.created_by, + seawater_active_positions_4.block_hash, + seawater_active_positions_4.transaction_hash, + seawater_active_positions_4.created_block_number, + seawater_active_positions_4.pos_id, + COALESCE(vested.owner, seawater_active_positions_4.owner) AS owner, + seawater_active_positions_4.pool, + seawater_active_positions_4.lower, + seawater_active_positions_4.upper, + COALESCE(vested.is_vested, FALSE) AS is_vested +FROM + seawater_active_positions_4 + LEFT JOIN seawater_positions_vested_2 AS vested + ON vested.position_id = seawater_active_positions_4.pos_id +; + +-- migrate:down