Skip to content

Commit

Permalink
Also pack campaign creation per second
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk committed Sep 3, 2024
1 parent 46454a7 commit 2668540
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/build.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

ORG_ROOT := fluidity
ORG_ROOT := superposition

INSTALL_DIR := $(or ${INSTALL_DIR},/usr/local/bin)

Expand Down
2 changes: 1 addition & 1 deletion cmd/graphql.ethereum/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

EXTRA_FILES := pools.toml
EXTRA_FILES := pools.toml bootstrap bootstrap.zip

include ../golang.mk

Expand Down
3 changes: 2 additions & 1 deletion db/migrations/1723693657-events_leo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ CREATE TABLE events_leo_campaigncreated (
tick_upper INTEGER NOT NULL,
owner ADDRESS NOT NULL,
starting TIMESTAMP WITHOUT TIME ZONE,
ending TIMESTAMP WITHOUT TIME ZONE
ending TIMESTAMP WITHOUT TIME ZONE,
per_second BIGINT NOT NULL
);

CREATE UNIQUE INDEX ON events_leo_campaigncreated (identifier, pool);
Expand Down
Empty file added lib/events/fluidity/abi.json
Empty file.
Empty file added lib/events/fluidity/fluidity.go
Empty file.
Empty file added lib/events/fluidity/types.go
Empty file.
10 changes: 6 additions & 4 deletions lib/events/leo/leo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func UnpackCampaignCreated(topic1, topic2, topic3 ethCommon.Hash, d []byte) (*Ca
return nil, fmt.Errorf("bad times: %T", i[1])
}
tickLower, tickUpper, owner := unpackDetails(details)
starting, ending := unpackTimes(times)
starting, ending, perSecond := unpackTimes(times)
return &CampaignCreated{
Identifier: hashToBytes8Data(topic1),
Pool: hashToAddr(topic2),
Expand All @@ -64,6 +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,
}, nil
}

Expand Down Expand Up @@ -123,9 +124,10 @@ func unpackDetails(i *big.Int) (tickLower int32, tickUpper int32, owner types.Ad
return
}

func unpackTimes(i *big.Int) (starting uint64, ending uint64) {
starting = new(big.Int).Rsh(i, 64).Uint64()
ending = i.Uint64()
func unpackTimes(i *big.Int) (starting uint64, ending uint64, perSecond uint64) {
starting = new(big.Int).Rsh(i, 64 * 2).Uint64()
ending = new(big.Int).Rsh(i, 64).Uint64()
perSecond = i.Uint64()
return
}

Expand Down
4 changes: 3 additions & 1 deletion lib/events/leo/leo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ func TestUnpackDetails(t *testing.T) {
}

func TestUnpackTimes(t *testing.T) {
starting, ending := unpackTimes(new(big.Int).SetBits([]big.Word{545464, 5000, 0, 0}))
//1701411834604692327378907846580747919949856
starting, ending, perSecond := unpackTimes(new(big.Int).SetBits([]big.Word{32, 545464, 5000, 0}))
assert.Equalf(t, uint64(5000), starting, "starting not equal")
assert.Equalf(t, uint64(545464), ending, "ending not equal")
assert.Equalf(t, uint64(32), perSecond, "per second not equal")
}

func TestUnpackExtras(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions lib/events/leo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type (
Owner types.Address `json:"owner"`
Starting time.Time `json:"starting"`
Ending time.Time `json:"ending"`
PerSecond uint64 `json:"perSecond"`
}

CampaignUpdated struct {
Expand Down
11 changes: 7 additions & 4 deletions pkg/leo/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ pub fn emit_campaign_created(
tick_upper: i32,
starting: u64,
ending: u64,
per_second: u64
) {
#[cfg(feature = "log-events")]
evm::log(CampaignCreated {
identifier: identifier.as_slice().try_into().unwrap(),
pool,
token,
details: pack_details(tick_lower, tick_upper, owner),
times: pack_times(starting, ending),
times: pack_times(starting, ending, per_second),
});
}

Expand All @@ -39,8 +40,10 @@ fn pack_details(tick_lower: i32, tick_upper: i32, owner: Address) -> U256 {
}

#[allow(dead_code)]
fn pack_times(starting: u64, ending: u64) -> U256 {
(U256::from(starting) << 64) | U256::from(ending)
fn pack_times(starting: u64, ending: u64, per_second: u64) -> U256 {
let mut packed = U256::from(starting) << 64 * 2;
packed |= U256::from(ending) << 64;
packed | U256::from(per_second)
}

#[allow(dead_code)]
Expand Down Expand Up @@ -83,7 +86,7 @@ fn test_pack_details() {

#[test]
fn test_pack_times() {
dbg!(pack_times(5000, 545464));
dbg!(pack_times(5000, 545464, 32));
}

#[test]
Expand Down

0 comments on commit 2668540

Please sign in to comment.