-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Gearbox-protocol/lmrewardsv3
Lmrewardsv3
- Loading branch information
Showing
33 changed files
with
992 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
delete from farm_V3; | ||
delete from user_lmdetails_v3 ; | ||
delete from sync_adapters where type='LMRewardsv3'; | ||
|
||
WITH data as (select * from sync_adapters where type = 'AddressProvider') | ||
insert into sync_adapters(address, type, last_sync, firstlog_at, version, discovered_at, disabled) values ( | ||
'0x00000000000000000000000000000000000beef3', | ||
'LMRewardsv3', | ||
(SELECT firstlog_at-1 from data), | ||
(SELECT firstlog_at from data), | ||
'300', | ||
(SELECT firstlog_at from data), | ||
'f' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
delete from diesel_balances; delete from diesel_transfers; delete from lm_rewards; | ||
update sync_adapters set details='{}'::jsonb, last_sync=(SELECT firstlog_at-1 FROM sync_adapters WHERE type='AddressProvider') WHERE type='PoolLMRewards'; | ||
update sync_adapters set details='{}'::jsonb, last_sync=(SELECT firstlog_at-1 FROM sync_adapters WHERE type='AddressProvider') WHERE type='LMRewardsv2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
create table farm_v3 ( | ||
pool varchar(42), | ||
farm varchar(42), | ||
-- | ||
checkpoint integer, | ||
farmed_per_token varchar(80), | ||
-- | ||
reward varchar(80), | ||
period integer, | ||
end_ts integer, | ||
-- | ||
total_supply varchar(80), | ||
diesel_token varchar(42), | ||
PRIMARY KEY (farm) | ||
); | ||
|
||
create table user_lmdetails_v3 ( | ||
balances_bi varchar(80), | ||
balances double precision, | ||
correction varchar(80), | ||
account varchar(42), | ||
farm varchar(42), | ||
diesel_sym varchar(42), | ||
PRIMARY KEY(farm, account) | ||
); | ||
|
||
-- 1inch lm rewards are stored with gear. | ||
|
||
update sync_adapters set type='LMRewardsv2', address='0x00000000000000000000000000000000000beef2' where type = 'PoolLMRewards'; | ||
-- | ||
WITH data as (select * from sync_adapters where type = 'AddressProvider') | ||
insert into sync_adapters(address, type, last_sync, firstlog_at, version, discovered_at, disabled) values ( | ||
'0x00000000000000000000000000000000000beef3', | ||
'LMRewardsv3', | ||
(SELECT firstlog_at-1 from data), | ||
(SELECT firstlog_at from data), | ||
'300', | ||
(SELECT firstlog_at from data), | ||
'f' | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package pool_v3 | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/Gearbox-protocol/sdk-go/core" | ||
"github.com/Gearbox-protocol/sdk-go/core/schemas" | ||
"github.com/Gearbox-protocol/sdk-go/log" | ||
"github.com/Gearbox-protocol/sdk-go/utils" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type UpdatePoolLedger struct { | ||
Zapper string | ||
Pool string | ||
User string | ||
BlockNum int64 | ||
TxHash string | ||
Shares *big.Int | ||
Type string | ||
} | ||
|
||
func (mdl *Poolv3) updateFarmedv3(txLog types.Log) { | ||
from := common.BytesToAddress(txLog.Topics[1][:]).Hex() | ||
to := common.BytesToAddress(txLog.Topics[2][:]).Hex() | ||
shares := new(big.Int).SetBytes(txLog.Data[:]) | ||
txHash := txLog.TxHash.Hex() | ||
blockNum := int64(txLog.BlockNumber) | ||
|
||
if from == core.NULL_ADDR.Hex() || to == core.NULL_ADDR.Hex() { | ||
return | ||
} | ||
|
||
if from == mdl.getZapPoolv2() { | ||
mdl.updatesForPoolv2 = append(mdl.updatesForPoolv2, UpdatePoolLedger{ | ||
Zapper: from, | ||
User: to, | ||
Pool: mdl.getPoolv2(), | ||
BlockNum: blockNum, | ||
TxHash: txHash, | ||
Type: "RemoveLiquidity", | ||
}) | ||
} | ||
if from == mdl.getZapUnderlying() || from == mdl.getZapPoolv2() { // usdc-farmedUSDCv3, dUSDC-farmedUSDCv3 | ||
if txHash != mdl.addLiquidityEvent.TxHash || | ||
blockNum != mdl.addLiquidityEvent.BlockNumber || | ||
shares.Cmp(mdl.addLiquidityEvent.SharesBI.Convert()) != 0 || | ||
from != mdl.addLiquidityEvent.User { | ||
log.Fatal(utils.ToJson(mdl.addLiquidityEvent), "addLiquidityEvent", "txHash", txHash, "blockNum", blockNum, "shares", shares) | ||
} | ||
mdl.addLiquidityEvent.User = to | ||
mdl.Repo.AddPoolLedger(mdl.addLiquidityEvent) | ||
mdl.addLiquidityEvent = nil | ||
} | ||
|
||
if to == mdl.getZapUnderlying() || to == mdl.getZapPoolv2() { | ||
mdl.removeLiqUpdate = &UpdatePoolLedger{ | ||
Zapper: to, | ||
User: from, | ||
Pool: mdl.Address, | ||
BlockNum: blockNum, | ||
TxHash: txHash, | ||
Shares: shares, | ||
} | ||
} | ||
if to == mdl.getZapPoolv2() { | ||
mdl.updatesForPoolv2 = append(mdl.updatesForPoolv2, UpdatePoolLedger{ | ||
Zapper: to, | ||
User: from, | ||
Pool: mdl.getPoolv2(), | ||
BlockNum: blockNum, | ||
TxHash: txHash, | ||
Type: "AddLiquidity", | ||
}) | ||
} | ||
} | ||
|
||
func (mdl *Poolv3) changeAddressOnAddLiq(event *schemas.PoolLedger) { | ||
if mdl.removeLiqUpdate != nil { | ||
log.Fatal(utils.ToJson(mdl.removeLiqUpdate), "removeLiqUpdate is not nil on add Liq", utils.ToJson(event)) | ||
} | ||
if mdl.addLiquidityEvent != nil { | ||
log.Fatal(utils.ToJson(mdl.addLiquidityEvent), "addLiquidityEvent is not nil", "pool", mdl.Address, "event", event) | ||
} | ||
mdl.addLiquidityEvent = event | ||
} | ||
func (mdl *Poolv3) changeAddressOnRemoveLiq(event *schemas.PoolLedger) { | ||
if mdl.removeLiqUpdate == nil { | ||
log.Fatal(utils.ToJson(event)) | ||
} | ||
txHash := mdl.removeLiqUpdate.TxHash | ||
blockNum := mdl.removeLiqUpdate.BlockNum | ||
shares := mdl.removeLiqUpdate.Shares | ||
if txHash != event.TxHash || | ||
blockNum != event.BlockNumber || | ||
shares.Cmp(event.SharesBI.Convert()) != 0 || | ||
mdl.removeLiqUpdate.Zapper != event.User { | ||
log.Fatal(utils.ToJson(mdl.removeLiqUpdate), "removeLiqUpdate", "txHash", event.TxHash, "blockNum", event.BlockNumber, "shares", event.SharesBI, "user", event.User) | ||
} | ||
if mdl.addLiquidityEvent != nil { | ||
log.Fatal(utils.ToJson(mdl.addLiquidityEvent), "addLiquidityEvent is not nil", "pool", mdl.Address, "event", event) | ||
} | ||
// | ||
// | ||
event.User = mdl.removeLiqUpdate.User | ||
mdl.Repo.AddPoolLedger(event) | ||
mdl.removeLiqUpdate = nil | ||
} | ||
|
||
func (mdl *Poolv3) UpdatePoolv2Ledger(tx *gorm.DB) { | ||
for _, update := range mdl.updatesForPoolv2 { | ||
if update.Type == "" { | ||
continue | ||
} | ||
x := tx.Exec(`UPDATE pool_ledger set user_address=? WHERE block_num=? AND event = ? AND tx_hash=? AND user_address in (?, ?)`, | ||
update.User, update.BlockNum, update.Type, update.TxHash, update.User, update.Zapper) | ||
log.CheckFatal(x.Error) | ||
// | ||
|
||
if x.RowsAffected != 1 { | ||
log.Infof("SEELCT * from pool_ledger WHERE block_num=%d AND event = '%s' AND tx_hash='%s' AND user_address in ('%s', '%s')", update.BlockNum, update.Type, update.TxHash, update.User, update.Zapper) | ||
log.Fatal("Can't update for", utils.ToJson(update)) | ||
} | ||
} | ||
} |
Oops, something went wrong.