diff --git a/cmd/ingestor.logs.ethereum/func.go b/cmd/ingestor.logs.ethereum/func.go index c6ad3dcb..9548b70f 100644 --- a/cmd/ingestor.logs.ethereum/func.go +++ b/cmd/ingestor.logs.ethereum/func.go @@ -34,6 +34,8 @@ var FilterTopics = []ethCommon.Hash{ // Matches any of these in the first topic leo.TopicCampaignBalanceUpdated, leo.TopicCampaignCreated, leo.TopicCampaignUpdated, + leo.TopicPositionVested, + leo.TopicPositionDivested, seawater.TopicMintPosition, seawater.TopicBurnPosition, seawater.TopicTransferPosition, @@ -242,6 +244,18 @@ func handleLogCallback(seawaterAddr, thirdwebAddr, leoAddr ethCommon.Address, l isSeawater = false isLeo = true + case leo.TopicPositionVested: + a, err = leo.UnpackPositionVested(topic1, topic2, topic3, data) + logEvent("PositionVested") + table = "events_leo_positionvested" + isLeo = true + + case leo.TopicPositionDivested: + a, err = leo.UnpackPositionDivested(topic1, topic2, topic3, data) + logEvent("PositionDivested") + table = "events_leo_positiondivested" + isLeo = true + case seawater.TopicMintPosition: a, err = seawater.UnpackMintPosition(topic1, topic2, topic3, data) logEvent("MintPosition") diff --git a/db/migrations/1724812411-events_leo_positions.sql b/db/migrations/1724812411-events_leo_positions.sql new file mode 100644 index 00000000..b31ac545 --- /dev/null +++ b/db/migrations/1724812411-events_leo_positions.sql @@ -0,0 +1,25 @@ +-- migrate:up + +CREATE TABLE events_leo_positionvested ( + id SERIAL PRIMARY KEY, + created_by TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + block_hash HASH NOT NULL, + transaction_hash HASH NOT NULL, + block_number INTEGER NOT NULL, + emitter_addr ADDRESS NOT NULL, + + position_id HUGEINT NOT NULL, +); + +CREATE TABLE events_leo_positiondivested ( + id SERIAL PRIMARY KEY, + created_by TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP, + block_hash HASH NOT NULL, + transaction_hash HASH NOT NULL, + block_number INTEGER NOT NULL, + emitter_addr ADDRESS NOT NULL, + + position_id HUGEINT NOT NULL, +); + +-- migrate:down diff --git a/lib/events/leo/abi.json b/lib/events/leo/abi.json index ce928522..b1d395e9 100644 --- a/lib/events/leo/abi.json +++ b/lib/events/leo/abi.json @@ -85,5 +85,31 @@ } ], "anonymous": false + }, + { + "type": "event", + "name": "PositionDivested", + "inputs": [ + { + "name": "positionId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + } + ], + "anonymous": false + }, + { + "type": "event", + "name": "PositionVested", + "inputs": [ + { + "name": "positionId", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + } + ], + "anonymous": false } ] diff --git a/lib/events/leo/leo.go b/lib/events/leo/leo.go index 41439c95..b1fc250c 100644 --- a/lib/events/leo/leo.go +++ b/lib/events/leo/leo.go @@ -3,9 +3,9 @@ package leo import ( "bytes" _ "embed" - "time" "fmt" "math/big" + "time" "github.com/fluidity-money/long.so/lib/types" @@ -16,7 +16,9 @@ import ( var ( TopicCampaignBalanceUpdated = abi.Events["CampaignBalanceUpdated"].ID TopicCampaignCreated = abi.Events["CampaignCreated"].ID - TopicCampaignUpdated = abi.Events["CampaignUpdated"].ID + TopicCampaignUpdated = abi.Events["CampaignUpdated"].ID + TopicPositionVested = abi.Events["PositionVested"].ID + TopicPositionDivested = abi.Events["PositionDivested"].ID ) //go:embed abi.json @@ -80,7 +82,7 @@ func UnpackCampaignUpdated(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*Ca return &CampaignUpdated{ Identifier: hashToBytes8Data(topic1), Pool: hashToAddr(topic2), - PerSecond: hashToNumber(topic3), + PerSecond: hashToNumber(topic3), TickLower: tickLower, TickUpper: tickUpper, Starting: time.Unix(int64(starting), 0), @@ -88,6 +90,18 @@ func UnpackCampaignUpdated(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*Ca }, nil } +func UnpackPositionVested(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*PositionVested, error) { + return &PositionVested{ + PositionId: hashToNumber(topic1), + }, nil +} + +func UnpackPositionDivested(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*PositionDivested, error) { + return &PositionDivested{ + PositionId: hashToNumber(topic1), + }, nil +} + func hashToBytes8Data(t ethCommon.Hash) types.Data { b := t.Bytes()[:5] return types.DataFromBytes(b) @@ -103,7 +117,7 @@ func hashToNumber(h ethCommon.Hash) types.Number { } func unpackDetails(i *big.Int) (tickLower int32, tickUpper int32, owner types.Address) { - tickLower = int32(new(big.Int).Rsh(i, 32 + 160).Int64()) + tickLower = int32(new(big.Int).Rsh(i, 32+160).Int64()) tickUpper = int32(new(big.Int).Rsh(i, 160).Int64()) owner = types.AddressFromString(ethCommon.BigToAddress(i).String()) return @@ -116,8 +130,8 @@ func unpackTimes(i *big.Int) (starting uint64, ending uint64) { } func unpackExtras(i *big.Int) (tickLower int32, tickUpper int32, starting uint64, ending uint64) { - tickLower = int32(new(big.Int).Rsh(i, 32 + 64 + 64).Int64()) - tickUpper = int32(new(big.Int).Rsh(i, 64 + 64).Int64()) + tickLower = int32(new(big.Int).Rsh(i, 32+64+64).Int64()) + tickUpper = int32(new(big.Int).Rsh(i, 64+64).Int64()) starting = new(big.Int).Rsh(i, 64).Uint64() ending = i.Uint64() return diff --git a/lib/events/leo/types.go b/lib/events/leo/types.go index ad96bb65..17c5143c 100644 --- a/lib/events/leo/types.go +++ b/lib/events/leo/types.go @@ -42,4 +42,16 @@ type ( Starting time.Time `json:"starting"` Ending time.Time `json:"ending"` } + + PositionVested struct { + events.Event + + PositionId types.Number `json:"positionId"` + } + + PositionDivested struct { + events.Event + + PositionId types.Number `json:"positionId"` + } ) diff --git a/pkg/leo/src/lib.rs b/pkg/leo/src/lib.rs index 41a9ed3c..494a242c 100644 --- a/pkg/leo/src/lib.rs +++ b/pkg/leo/src/lib.rs @@ -170,6 +170,12 @@ impl Leo { self.liquidity .setter(pool) .set(existing_liq + U256::from(position_liq)); + + #[cfg(feature = "log-events")] + evm::log(events::PositionVested { + positionId: position_id, + }); + Ok(()) } @@ -569,7 +575,15 @@ impl Leo { self.liquidity .setter(pool) .set(existing_liq - self.positions.getter(position_id).liquidity.get()); - nft_manager::give_position(position_id) + + nft_manager::give_position(position_id)?; + + #[cfg(feature = "log-events")] + evm::log(events::PositionDivested { + positionId: position_id, + }); + + Ok(()) } pub fn admin_reduce_pos_time(&mut self, _id: U256, _secs: u64) -> Result<(), Vec> { diff --git a/pkg/sol/ILeoEvents.sol b/pkg/sol/ILeoEvents.sol index 69f607f0..7b7f7c7f 100644 --- a/pkg/sol/ILeoEvents.sol +++ b/pkg/sol/ILeoEvents.sol @@ -21,4 +21,8 @@ interface ILeoEvents { uint256 indexed perSecond, uint256 extras // [tick lower, tick upper, starting, ending] ); + + event PositionVested(uint256 indexed positionId); + + event PositionDivested(uint256 indexed positionId); }