Skip to content

Commit

Permalink
Track more info about position vesting/divesting
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk committed Aug 28, 2024
1 parent 4aa5146 commit 46587b4
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 7 deletions.
14 changes: 14 additions & 0 deletions cmd/ingestor.logs.ethereum/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
25 changes: 25 additions & 0 deletions db/migrations/1724812411-events_leo_positions.sql
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions lib/events/leo/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
26 changes: 20 additions & 6 deletions lib/events/leo/leo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package leo
import (
"bytes"
_ "embed"
"time"
"fmt"
"math/big"
"time"

"github.com/fluidity-money/long.so/lib/types"

Expand All @@ -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
Expand Down Expand Up @@ -80,14 +82,26 @@ 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),
Ending: time.Unix(int64(ending), 0),
}, 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)
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/events/leo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
)
16 changes: 15 additions & 1 deletion pkg/leo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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<u8>> {
Expand Down
4 changes: 4 additions & 0 deletions pkg/sol/ILeoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 46587b4

Please sign in to comment.