Skip to content

Commit 4b58e0e

Browse files
committed
fix: cm
1 parent e759d3b commit 4b58e0e

File tree

10 files changed

+59
-14
lines changed

10 files changed

+59
-14
lines changed

ds/dc_wrapper/wrapper.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ func isCType(c CompressorType) bool {
176176
}
177177
return false
178178
}
179-
179+
func compressors() []CompressorType {
180+
compressors := []CompressorType{}
181+
for _, v := range ContractNameToCompressortype {
182+
compressors = append(compressors, v)
183+
}
184+
return compressors
185+
}
180186
func (dcw *DataCompressorWrapper) AddCompressorType(addr common.Address, cType CompressorType, discoveredAt int64) {
181187
if !isCType(cType) {
182188
log.Fatal("ctype is wrong, ", cType)
@@ -218,7 +224,8 @@ func (dcw *DataCompressorWrapper) LoadMultipleDC(multiDCs interface{}) {
218224
sort.Slice(blockNums, func(i, j int) bool { return blockNums[i] < blockNums[j] })
219225
}
220226
for _, blockNum := range blockNums {
221-
for _, suffix := range []CompressorType{CompressorType(""), CompressorType("300"), MARKET_COMPRESSOR, POOL_COMPRESSOR, CREDIT_ACCOUNT_COMPRESSOR} {
227+
// TODO: NETWORK
228+
for _, suffix := range append(compressors(), "", "300") {
222229
key := fmt.Sprintf("%d", blockNum)
223230
if suffix != "" {
224231
key = fmt.Sprintf("%d_%s", blockNum, suffix)
@@ -240,6 +247,7 @@ func (dcw *DataCompressorWrapper) LoadMultipleDC(multiDCs interface{}) {
240247
type CompressorType string
241248

242249
const (
250+
// TODO : NETWORK
243251
MARKET_COMPRESSOR CompressorType = "MARKET"
244252
POOL_COMPRESSOR CompressorType = "POOL"
245253
CREDIT_ACCOUNT_COMPRESSOR CompressorType = "ACCOUNT"
@@ -416,7 +424,14 @@ func (dcw *DataCompressorWrapper) GetCreditAccountData(version core.VersionType,
416424
if err != nil {
417425
return dc.CreditAccountCallData{}, err
418426
}
419-
accountData := *abi.ConvertType(out[0], new(creditAccountCompressor.CreditAccountData)).(*creditAccountCompressor.CreditAccountData)
427+
var accountData creditAccountCompressor.CreditAccountData
428+
switch compressorType {
429+
case CREDIT_ACCOUNT_COMPRESSOR:
430+
accountData = *abi.ConvertType(out[0], new(creditAccountCompressor.CreditAccountData)).(*creditAccountCompressor.CreditAccountData)
431+
case GLOBAL_ACCOUNT_COMPRESSOR:
432+
x := abi.ConvertType(out[0], new(globalAccountCompressor.CreditAccountData)).(*globalAccountCompressor.CreditAccountData)
433+
accountData = dc.Convert(x)
434+
}
420435
return AddFieldsToAccountv310(dcw.client, blockNum, accountData)
421436
case DCV3:
422437
out, err := core.GetAbi("DataCompressorv3").Unpack("getCreditAccountData", bytes)
@@ -643,6 +658,7 @@ func (dcw *DataCompressorWrapper) GetPoolData(version core.VersionType, blockNum
643658
resultFn func([]byte) (dc.PoolCallData, error),
644659
errReturn error) {
645660
//
661+
// TODO : NETWORK
646662
key, dcAddr, compressorType := dcw.GetKeyAndAddress(version, blockNum, []CompressorType{POOL_COMPRESSOR, GLOBAL_MARKET_COMPRESSOR})
647663
switch key {
648664
case NODC:

ds/debt.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
dcv2 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressor/dataCompressorv2"
77
"github.com/Gearbox-protocol/sdk-go/core"
88
"github.com/Gearbox-protocol/sdk-go/core/schemas"
9+
"github.com/Gearbox-protocol/sdk-go/log"
910
"github.com/Gearbox-protocol/sdk-go/pkg/dc"
1011
"github.com/Gearbox-protocol/sdk-go/utils"
1112
)
@@ -51,5 +52,11 @@ func (profile *DebtProfile) String() string {
5152
}
5253

5354
func CallTraceAllowed(client core.ClientI) bool {
54-
return utils.Contains([]int64{1, 42161, 10, 7878, 1337}, core.GetChainId(client))
55+
network := log.TestNetOrMainnet()
56+
if network == "" { // testnet
57+
network = log.GetNetworkName(core.GetChainId(client))
58+
}
59+
chainid := log.GetNetworkToChainId(network)
60+
testnet := log.GetTestNet(chainid)
61+
return utils.Contains([]int64{7878, 1337}, core.GetChainId(client)) || (testnet != network)
5562
}

ds/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type RepositoryI interface {
7878
AddAllowedTokenV2(logID uint, txHash, creditFilter string, atoken *schemas.AllowedToken)
7979
UpdateLimits(logID uint, txHash, creditConfigurator string, params *schemas.Parameters)
8080
UpdateEmergencyLiqDiscount(logID uint, txHash, creditConfigurator string, params *schemas.Parameters)
81+
// saves in db and updates dao operations
8182
UpdateFees(logID uint, txHash, creditConfigurator string, params *schemas.Parameters)
8283
TransferAccountAllowed(*schemas.TransferAccountAllowed)
8384
GetPricesInUSD(blockNum int64, pool string, tokenAddrs []string) core.JsonFloatMap

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23
55
// toolchain go1.23.2
66

77
require (
8-
github.com/Gearbox-protocol/sdk-go v0.0.0-20250510115227-8bf87ea490e7
8+
github.com/Gearbox-protocol/sdk-go v0.0.0-20250515050146-74e6c8e5dfad
99
github.com/ethereum/go-ethereum v1.13.14
1010
github.com/go-playground/validator/v10 v10.4.1
1111
github.com/google/go-cmp v0.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
66
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
77
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
88
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
9-
github.com/Gearbox-protocol/sdk-go v0.0.0-20250510115227-8bf87ea490e7 h1:A/M+HDbHhyEQmr6/90/A94Dj/RfbovEwi9DY5xeEsAY=
10-
github.com/Gearbox-protocol/sdk-go v0.0.0-20250510115227-8bf87ea490e7/go.mod h1:MZsiiSAwDdnHY6GEILYtHEqhb9wmbUUE34UBQgNlUyM=
9+
github.com/Gearbox-protocol/sdk-go v0.0.0-20250515050146-74e6c8e5dfad h1:wRcGkN6RVzmxWD8lew22b4mjsddrWCCpmGGsy0xDZKQ=
10+
github.com/Gearbox-protocol/sdk-go v0.0.0-20250515050146-74e6c8e5dfad/go.mod h1:MZsiiSAwDdnHY6GEILYtHEqhb9wmbUUE34UBQgNlUyM=
1111
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
1212
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
1313
github.com/OffchainLabs/go-ethereum v1.13.4-0.20240313010929-e5d8587e7227 h1:+/3TrD+q+BP36jGj2Bycdmrc/joKLNbc5ImePQzKRLM=

migrations/000056_v310.up.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ alter table price_feeds add PRIMARY KEY (block_num, feed);
5555

5656
-- do after the legacy market configurator address is found.
5757
-- update legacy address in marketconfigurator.
58-
-- update tvl_snapshots market=? where market='0x0000000000000000000000000000000000000000';
58+
-- update tvl_snapshots market=? where market='0x0000000000000000000000000000000000000000';
59+
60+
insert into debt_sync values ('t', 0 ,0 );

models/credit_manager/cm_common/credit_session_state.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ func (mdl *CommonCMAdapter) updateSession(blockNum int64, session *schemas.Credi
314314
}
315315

316316
func (mdl *CommonCMAdapter) addFloatValue(account string, blockNum int64, dcv2Balances []core.TokenBalanceCallData) *core.DBBalanceFormat {
317+
var stETH string
317318
if log.GetBaseNet(core.GetBaseChainId(mdl.Client)) == log.MAINNET {
318-
return AddStETHBalance(account, blockNum, dcv2Balances, mdl.Client, mdl, core.GetToken(1, "stETH").Hex())
319+
stETH = core.GetToken(1, "stETH").Hex()
319320
}
320-
log.Fatal("AddStETHBalance is not supported other networks than mainnet")
321-
return nil
321+
return AddStETHBalance(account, blockNum, dcv2Balances, mdl.Client, mdl, stETH)
322322
}
323323

324324
func (mdl *CommonCMAdapter) GetDecimals(token string) int8 {

models/credit_manager/cm_v3/model.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"math/big"
55

66
"github.com/Gearbox-protocol/sdk-go/core"
7+
"github.com/Gearbox-protocol/sdk-go/core/schemas"
78
"github.com/Gearbox-protocol/sdk-go/log"
89
"github.com/Gearbox-protocol/third-eye/ds"
910
"github.com/ethereum/go-ethereum/common"
@@ -23,7 +24,19 @@ func NewCMv3(addr string, client core.ClientI, repo ds.RepositoryI, discoveredAt
2324
ds.NewSyncAdapter(addr, ds.CreditManager, discoveredAt, client, repo),
2425
)
2526
mdl.InitState()
27+
params := &schemas.Parameters{
28+
CreditManager: addr,
29+
BlockNum: discoveredAt,
30+
FeeInterest: 5000, // DEFAULT_FEE_INTEREST
31+
FeeLiquidation: 150, // DEFAULT_FEE_LIQUIDATION
32+
LiquidationDiscount: 100_00 - 4_00, // DEFAULT_LIQUIDATION_PREMIUM
33+
FeeLiquidationExpired: 1_00, // DEFAULT_FEE_LIQUIDATION_EXPIRED
34+
LiquidationDiscountExpired: 100_00 - 2_00, // DEFAULT_LIQUIDATION_PREMIUM_EXPIRED
35+
EmergencyLiqDiscount: 0,
36+
}
37+
mdl.SetParams(params)
2638
mdl.addCreditConfiguratorAdapter(mdl.GetDetailsByKey("configurator"))
39+
mdl.Repo.UpdateFees(0, "", mdl.GetDetailsByKey("configurator"), params)
2740
return mdl
2841
}
2942

models/credit_manager/cm_v3/on_change.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,22 @@ func (mdl *CMv3) OnLog(txLog types.Log) {
3939
case core.Topic("SetExpirationDate(uint40)"):
4040
mdl.expirationDate = uint64(new(big.Int).SetBytes(txLog.Data[:]).Int64())
4141
case core.Topic("UpdateFees(uint16,uint16,uint16,uint16,uint16)"):
42-
mdl.SetParams(&schemas.Parameters{
42+
// feeInterest,
43+
// uint16 feeLiquidation,
44+
// uint16 liquidationPremium,
45+
// uint16 feeLiquidationExpired,
46+
// uint16 liquidationPremiumExpired
47+
params := &schemas.Parameters{
4348
BlockNum: int64(txLog.BlockNumber),
4449
CreditManager: mdl.Address,
4550
FeeInterest: bytesToUInt16(txLog.Data[:32]),
4651
FeeLiquidation: bytesToUInt16(txLog.Data[32:64]),
4752
LiquidationDiscount: 10000 - bytesToUInt16(txLog.Data[64:96]), // 10000- liqPremium
4853
FeeLiquidationExpired: bytesToUInt16(txLog.Data[96:128]),
4954
LiquidationDiscountExpired: 10000 - bytesToUInt16(txLog.Data[128:160]), // 10000- liqPremiumExpired
50-
})
55+
}
56+
mdl.SetParams(params)
57+
mdl.Repo.UpdateFees(txLog.Index, txLog.TxHash.Hex(), mdl.GetAddress(), params)
5158
}
5259
return
5360
}

repository/save.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
func (repo *Repository) Flush(syncTill int64) error {
99
repo.mu.Lock()
1010
defer repo.mu.Unlock()
11-
// log.Fatal("")
1211
// time.Sleep(time.Hour)
1312
// preferred order (adapter | token) => pools => cm => credit session => blocks => allowedTokens
1413

0 commit comments

Comments
 (0)