diff --git a/adapters/adapters.go b/adapters/adapters.go index 9f63928..bede93d 100644 --- a/adapters/adapters.go +++ b/adapters/adapters.go @@ -48,7 +48,8 @@ type Lock struct { TokenAmount *big.Int TokenDecimals uint8 Token common.Address - Time uint64 + Duration uint64 + BlockTime uint64 BlockNumber uint64 TxHash common.Hash } diff --git a/adapters/projects/drips/lock.go b/adapters/projects/drips/lock.go index 1ab0ea7..309c519 100644 --- a/adapters/projects/drips/lock.go +++ b/adapters/projects/drips/lock.go @@ -18,7 +18,7 @@ const ( // https://taikoscan.io/address/0x46f0a2e45bee8e9ebfdb278ce06caa6af294c349 LockAddress string = "0x46f0a2e45bee8e9ebfdb278ce06caa6af294c349" - logDepositSignature string = "Deposit(address,uint256)" + logDepositWithDurationSignature string = "DepositWithDuration(address,uint256,uint256,uint256)" ) type LockIndexer struct { @@ -43,12 +43,14 @@ func (indexer *LockIndexer) Index(ctx context.Context, logs ...types.Log) ([]ada var locks []adapters.Lock for _, l := range logs { - if !indexer.isDeposit(l) { + if !indexer.isDepositWithDuration(l) { continue } - var depositEvent struct { - Assets *big.Int + var depositWithDurationEvent struct { + LockStart *big.Int + Amount *big.Int + Duration *big.Int } user := common.BytesToAddress(l.Topics[1].Bytes()[12:]) @@ -58,7 +60,7 @@ func (indexer *LockIndexer) Index(ctx context.Context, logs ...types.Log) ([]ada return nil, err } - err = dripsABI.UnpackIntoInterface(&depositEvent, "Deposit", l.Data) + err = dripsABI.UnpackIntoInterface(&depositWithDurationEvent, "DepositWithDuration", l.Data) if err != nil { return nil, err } @@ -70,10 +72,11 @@ func (indexer *LockIndexer) Index(ctx context.Context, logs ...types.Log) ([]ada lock := &adapters.Lock{ User: user, - TokenAmount: depositEvent.Assets, + TokenAmount: depositWithDurationEvent.Amount, TokenDecimals: adapters.TaikoTokenDecimals, Token: common.HexToAddress(adapters.TaikoTokenAddress), - Time: block.Time(), + Duration: depositWithDurationEvent.Duration.Uint64(), + BlockTime: block.Time(), BlockNumber: block.NumberU64(), TxHash: l.TxHash, } @@ -84,6 +87,6 @@ func (indexer *LockIndexer) Index(ctx context.Context, logs ...types.Log) ([]ada return locks, nil } -func (indexer *LockIndexer) isDeposit(l types.Log) bool { - return l.Topics[0].Hex() == crypto.Keccak256Hash([]byte(logDepositSignature)).Hex() +func (indexer *LockIndexer) isDepositWithDuration(l types.Log) bool { + return l.Topics[0].Hex() == crypto.Keccak256Hash([]byte(logDepositWithDurationSignature)).Hex() } diff --git a/adapters/projects/drips/lock_test.go b/adapters/projects/drips/lock_test.go index cf7bb23..e27d03f 100644 --- a/adapters/projects/drips/lock_test.go +++ b/adapters/projects/drips/lock_test.go @@ -34,7 +34,8 @@ func TestLockIndexer(t *testing.T) { assert.Equal(t, big.NewInt(2000000000000000000), locks[0].TokenAmount) assert.Equal(t, adapters.TaikoTokenDecimals, locks[0].TokenDecimals) assert.Equal(t, common.HexToAddress(adapters.TaikoTokenAddress), locks[0].Token) - assert.Equal(t, uint64(1728390191), locks[0].Time) + assert.Equal(t, uint64(1728390191), locks[0].BlockTime) + assert.Equal(t, uint64(86400), locks[0].Duration) assert.Equal(t, uint64(blocknumber), locks[0].BlockNumber) assert.Equal(t, common.HexToHash("0x95f528b52f0a75176543f516014bbba26e003f1c17c9b9413e936240e3f44650"), locks[0].TxHash) } diff --git a/adapters/projects/symmetric/lock.go b/adapters/projects/symmetric/lock.go index 659e10b..22124c5 100644 --- a/adapters/projects/symmetric/lock.go +++ b/adapters/projects/symmetric/lock.go @@ -67,6 +67,8 @@ func (indexer *LockIndexer) processDepositLog(ctx context.Context, l types.Log) } user := common.BytesToAddress(l.Topics[1].Bytes()[12:]) + lockEndTime := l.Topics[2].Big() + duration := new(big.Int).Sub(lockEndTime, depositEvent.Ts) block, err := indexer.client.BlockByNumber(ctx, big.NewInt(int64(l.BlockNumber))) if err != nil { @@ -103,7 +105,7 @@ func (indexer *LockIndexer) processDepositLog(ctx context.Context, l types.Log) return nil, errors.Join(err, errors.New("fetching pool tokens")) } - return indexer.createLocks(user, depositEvent.Value, totalSupply, poolTokens, block, l.TxHash), nil + return indexer.createLocks(user, duration, depositEvent.Value, totalSupply, poolTokens, block, l.TxHash), nil } func (indexer *LockIndexer) parseDepositEvent(l types.Log) (*struct { @@ -151,7 +153,7 @@ func (indexer *LockIndexer) fetchBalancerTokenInfo(balancerToken *balancer_token return totalSupply, poolId, vault, nil } -func (indexer *LockIndexer) createLocks(user common.Address, depositValue *big.Int, totalSupply *big.Int, poolTokens struct { +func (indexer *LockIndexer) createLocks(user common.Address, duration, depositValue *big.Int, totalSupply *big.Int, poolTokens struct { Tokens []common.Address Balances []*big.Int LastChangeBlock *big.Int @@ -168,7 +170,8 @@ func (indexer *LockIndexer) createLocks(user common.Address, depositValue *big.I TokenAmount: userAmount, TokenDecimals: adapters.TaikoTokenDecimals, Token: token, - Time: block.Time(), + Duration: duration.Uint64(), + BlockTime: block.Time(), BlockNumber: block.NumberU64(), TxHash: txHash, } diff --git a/adapters/projects/symmetric/lock_test.go b/adapters/projects/symmetric/lock_test.go index 372359c..a2cb29e 100644 --- a/adapters/projects/symmetric/lock_test.go +++ b/adapters/projects/symmetric/lock_test.go @@ -33,13 +33,15 @@ func TestLockIndexer(t *testing.T) { txHash := common.HexToHash("0x27058b3cfbd15e3466cdd1b86ab387a473f2ca01c0697eb6b47ae7b33fdf97b0") user := common.HexToAddress("0x7255Db0d1C1B93Fb756157074fa0613Aa6878F31") time := 1728397319 + duration := 4959481 expectedLocks := []adapters.Lock{ { User: user, TokenAmount: big.NewInt(45884668717994), TokenDecimals: adapters.TaikoTokenDecimals, Token: common.HexToAddress(adapters.WETHAddress), - Time: uint64(time), + Duration: uint64(duration), + BlockTime: uint64(time), BlockNumber: uint64(blocknumber), TxHash: txHash, }, @@ -48,7 +50,8 @@ func TestLockIndexer(t *testing.T) { TokenAmount: big.NewInt(287649277362130342), TokenDecimals: adapters.TaikoTokenDecimals, Token: common.HexToAddress(adapters.TaikoTokenAddress), - Time: uint64(time), + Duration: uint64(duration), + BlockTime: uint64(time), BlockNumber: uint64(blocknumber), TxHash: txHash, }, @@ -58,8 +61,9 @@ func TestLockIndexer(t *testing.T) { assert.Equal(t, expectedLocks[i].User, lock.User) assert.Equal(t, expectedLocks[i].TokenAmount, lock.TokenAmount) assert.Equal(t, expectedLocks[i].TokenDecimals, lock.TokenDecimals) + assert.Equal(t, expectedLocks[i].Duration, lock.Duration) assert.Equal(t, expectedLocks[i].Token, lock.Token) - assert.Equal(t, expectedLocks[i].Time, lock.Time) + assert.Equal(t, expectedLocks[i].BlockTime, lock.BlockTime) assert.Equal(t, expectedLocks[i].BlockNumber, lock.BlockNumber) assert.Equal(t, expectedLocks[i].TxHash, lock.TxHash) }