Skip to content

Commit

Permalink
Add positionVested2
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk committed Nov 19, 2024
1 parent 44dcfad commit b913dca
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 50 deletions.
10 changes: 5 additions & 5 deletions cmd/ingestor.logs.ethereum/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var FilterTopics = []ethCommon.Hash{ // Matches any of these in the first topic
leo.TopicCampaignBalanceUpdated,
leo.TopicCampaignCreated,
leo.TopicCampaignUpdated,
leo.TopicPositionVested,
leo.TopicPositionVested2,
leo.TopicPositionDivested,
seawater.TopicMintPosition,
seawater.TopicBurnPosition,
Expand Down Expand Up @@ -242,10 +242,10 @@ 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"
case leo.TopicPositionVested2:
a, err = leo.UnpackPositionVested2(topic1, topic2, topic3, data)
logEvent("PositionVested2")
table = "events_leo_positionvested2"
isSeawater = false
isLeo = true

Expand Down
18 changes: 18 additions & 0 deletions db/migrations/1731986933-positionvested2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- migrate:up

CREATE TABLE events_leo_positionvested2 (
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,
owner ADDRESS NOT NULL
);

CREATE INDEX ON events_leo_positionvested2 (position_id);
CREATE INDEX ON events_leo_positionvested2 (owner);

-- migrate:down
19 changes: 19 additions & 0 deletions lib/events/leo/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,24 @@
}
],
"anonymous": false
},
{
"type": "event",
"name": "PositionVested2",
"inputs": [
{
"name": "positionId",
"type": "uint256",
"indexed": true,
"internalType": "uint256"
},
{
"name": "owner",
"type": "address",
"indexed": true,
"internalType": "address"
}
],
"anonymous": false
}
]
11 changes: 6 additions & 5 deletions lib/events/leo/leo.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
TopicCampaignBalanceUpdated = abi.Events["CampaignBalanceUpdated"].ID
TopicCampaignCreated = abi.Events["CampaignCreated"].ID
TopicCampaignUpdated = abi.Events["CampaignUpdated"].ID
TopicPositionVested = abi.Events["PositionVested"].ID
TopicPositionVested2 = abi.Events["PositionVested2"].ID
TopicPositionDivested = abi.Events["PositionDivested"].ID
)

Expand Down Expand Up @@ -64,7 +64,7 @@ func UnpackCampaignCreated(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*Ca
Owner: owner,
Starting: time.Unix(int64(starting), 0),
Ending: time.Unix(int64(ending), 0),
PerSecond: perSecond,
PerSecond: perSecond,
}, nil
}

Expand All @@ -91,9 +91,10 @@ func UnpackCampaignUpdated(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*Ca
}, nil
}

func UnpackPositionVested(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*PositionVested, error) {
return &PositionVested{
func UnpackPositionVested2(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*PositionVested2, error) {
return &PositionVested2{
PositionId: hashToNumber(topic1),
Owner: hashToAddr(topic2),
}, nil
}

Expand Down Expand Up @@ -125,7 +126,7 @@ func unpackDetails(i *big.Int) (tickLower int32, tickUpper int32, owner types.Ad
}

func unpackTimes(i *big.Int) (starting uint64, ending uint64, perSecond uint64) {
starting = new(big.Int).Rsh(i, 64 * 2).Uint64()
starting = new(big.Int).Rsh(i, 64*2).Uint64()
ending = new(big.Int).Rsh(i, 64).Uint64()
perSecond = i.Uint64()
return
Expand Down
3 changes: 2 additions & 1 deletion lib/events/leo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ type (
Ending time.Time `json:"ending"`
}

PositionVested struct {
PositionVested2 struct {
events.Event

PositionId types.Number `json:"positionId"`
Owner types.Address `json:"owner"`
}

PositionDivested struct {
Expand Down
44 changes: 14 additions & 30 deletions pkg/leo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ pub struct Leo {

emergency_council: StorageAddress,

// pool => campaign id => campaign[]
campaigns: StorageMap<Address, StorageCampaigns>,

// campaign id => campaign balance
campaign_balances: StorageMap<CampaignId, StorageCampaignBal>,
// pool => campaign id => campaign
campaigns: StorageMap<Address, StorageCampaign>,

// position id => position
positions: StorageMap<U256, StoragePosition>,
Expand All @@ -60,28 +57,6 @@ pub struct Leo {
liquidity: StorageMap<Address, StorageU256>,
}

#[storage]
pub struct StorageCampaigns {
// Ongoing campaigns. We don't use a map since the seconds will
// default to 0 so it'll return 0 for amounts calculated.
ongoing: StorageMap<CampaignId, StorageVec<StorageCampaign>>,
}

#[storage]
pub struct StorageCampaignBal {
// Owner of the campaign balance so we don't have any abuse.
owner: StorageAddress,

// Token being distributed.
token: StorageAddress,

// Amount that can be distributed.
maximum: StorageU256,

// Amount that was already distributed.
distributed: StorageU256,
}

#[storage]
pub struct StorageCampaign {
// The lower tick that the position should be LP'd in for them to be eligible.
Expand All @@ -99,6 +74,18 @@ pub struct StorageCampaign {
// The timestamp of when this campaign ended. May be modified
// if updates are made to the existing campaign.
ending: StorageU64,

// Owner of the campaign balance so we don't have any abuse.
owner: StorageAddress,

// Token being distributed.
token: StorageAddress,

// Amount that can be distributed.
maximum: StorageU256,

// Amount that was already distributed.
distributed: StorageU256,
}

#[storage]
Expand All @@ -114,9 +101,6 @@ pub struct StoragePosition {
tick_upper: StorageI32,

liquidity: StorageU256,

// Indexes of the position of the current status per campaign that's updated
offsets: StorageMap<CampaignId, StorageU256>,
}

#[public]
Expand Down
2 changes: 1 addition & 1 deletion pkg/seawater/tests/lib-end-to-end-proptest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn test_weird_behaviour() {
test_utils::with_storage::<_, Pools, _>(None, None, None, |c| {
let pool = Address::from([1_u8; 20]);
c.ctor(msg::sender(), Address::ZERO, Address::ZERO).unwrap();
c.create_pool_D650_E2_D0(
c.create_pool_653_F_395_E(
pool,
U256::from_limbs([9433916063688681729, 246222, 0, 0]), //4542003653232976906676481
3000,
Expand Down
14 changes: 7 additions & 7 deletions pkg/seawater/tests/lib-high-level-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn test_similar_to_ethers() -> Result<(), Vec<u8>> {
let token_addr = address!("97392C28f02AF38ac2aC41AF61297FA2b269C3DE");

// First, we set up the pool.
contract.create_pool_D650_E2_D0(
contract.create_pool_653_F_395_E(
token_addr,
test_utils::encode_sqrt_price(50, 1), // the price
0,
Expand Down Expand Up @@ -54,7 +54,7 @@ fn test_alex() -> Result<(), Vec<u8>> {
let token_addr = address!("97392C28f02AF38ac2aC41AF61297FA2b269C3DE");

// First, we set up the pool.
contract.create_pool_D650_E2_D0(
contract.create_pool_653_F_395_E(
token_addr,
test_utils::encode_sqrt_price(100, 1), // the price
0, // fee
Expand Down Expand Up @@ -87,7 +87,7 @@ fn ethers_suite_orchestrated_uniswap_single() {
test_utils::with_storage::<_, Pools, _>(None, None, None, |contract| -> Result<(), Vec<u8>> {
let token0 = address!("9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0");
contract.ctor(msg::sender(), Address::ZERO, Address::ZERO)?;
contract.create_pool_D650_E2_D0(
contract.create_pool_653_F_395_E(
token0,
U256::from_limbs([0, 42949672960, 0, 0]), //792281625142643375935439503360
500, // fee
Expand All @@ -112,7 +112,7 @@ fn ethers_suite_orchestrated_uniswap_single_version_2() {
test_utils::with_storage::<_, Pools, _>(None, None, None, |contract| -> Result<(), Vec<u8>> {
let token0 = address!("9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0");
contract.ctor(msg::sender(), Address::ZERO, Address::ZERO)?;
contract.create_pool_D650_E2_D0(
contract.create_pool_653_F_395_E(
token0,
U256::from_limbs([0, 42949672960, 0, 0]), //792281625142643375935439503360
500, // fee
Expand Down Expand Up @@ -147,14 +147,14 @@ fn ethers_suite_orchestrated_uniswap_two() {
.ctor(msg::sender(), Address::ZERO, Address::ZERO)
.unwrap();
contract
.create_pool_D650_E2_D0(
.create_pool_653_F_395_E(
token0,
U256::from_limbs([0, 42949672960, 0, 0]), //792281625142643375935439503360
500, // fee
)
.unwrap();
contract
.create_pool_D650_E2_D0(
.create_pool_653_F_395_E(
token1,
U256::from_limbs([0, 42949672960, 0, 0]), //792281625142643375935439503360
500, // fee
Expand Down Expand Up @@ -190,7 +190,7 @@ fn ethers_suite_swapping_with_permit2_blobs_no_permit2() {
.ctor(msg::sender(), Address::ZERO, Address::ZERO)
.unwrap();
contract
.create_pool_D650_E2_D0(
.create_pool_653_F_395_E(
token0,
U256::from_limbs([0, 42949672960, 0, 0]), //792281625142643375935439503360
500, // fee
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

export RUST_BACKTRACE=1

cargo test --features testing
cargo test --features testing -- leo

0 comments on commit b913dca

Please sign in to comment.