Skip to content

Commit 7ad9834

Browse files
committed
fix: get account data
1 parent 40bffe4 commit 7ad9834

File tree

13 files changed

+84
-33
lines changed

13 files changed

+84
-33
lines changed

ds/dc_wrapper/wrapper.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/Gearbox-protocol/sdk-go/artifacts/creditAccountCompressor"
1414
dcv2 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressor/dataCompressorv2"
1515
"github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressor/mainnet"
16+
"github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressorv3"
1617
dcv3 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressorv3"
1718
"github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
1819
"github.com/Gearbox-protocol/sdk-go/artifacts/poolCompressor"
@@ -264,6 +265,49 @@ func (dcw *DataCompressorWrapper) GetLatestv3DC() (common.Address, bool) {
264265
return dcs[len(dcs)-1].address, true
265266
}
266267

268+
func (dcw *DataCompressorWrapper) Retry(blockNum int64, account common.Address, v3Pods []dataCompressorv3.PriceOnDemand, v3PodCalls []multicall.Multicall2Call) (dc.CreditAccountCallData, error) {
269+
key, dcAddr := dcw.GetKeyAndAddress(core.NewVersion(300), blockNum, CREDIT_ACCOUNT_COMPRESSOR)
270+
opts := &bind.CallOpts{BlockNumber: big.NewInt(blockNum)}
271+
var newaccountData interface{}
272+
switch key {
273+
case NODC:
274+
return dc.CreditAccountCallData{}, NO_DC_FOUND_ERR
275+
case DCV3:
276+
con, err := dataCompressorv3.NewDataCompressorv3(dcAddr, dcw.client)
277+
log.CheckFatal(err)
278+
data, err := con.GetCreditAccountData(opts, account, v3Pods)
279+
if err != nil || !data.IsSuccessful {
280+
log.Warn("after retry, getCreditAccoutn data is still not successful", blockNum, account)
281+
return dc.CreditAccountCallData{}, err
282+
}
283+
case DCV310:
284+
callData, err := core.GetAbi("CreditAccountCompressor").Pack("getCreditAccountData", account)
285+
log.CheckFatal(err)
286+
v3PodCalls = append(v3PodCalls, multicall.Multicall2Call{
287+
Target: dcAddr,
288+
CallData: callData,
289+
})
290+
ans := core.MakeMultiCall(dcw.client, blockNum, false, v3PodCalls)
291+
data := ans[len(ans)-1]
292+
if !data.Success {
293+
log.Warn("after retry, getCreditAccoutn data is still not successful", blockNum, account)
294+
return dc.CreditAccountCallData{}, err
295+
}
296+
out, err := core.GetAbi("CreditAccountCompressor").Unpack("getCreditAccountData", data.ReturnData)
297+
if err != nil {
298+
return dc.CreditAccountCallData{}, err
299+
}
300+
accountData := *abi.ConvertType(out[0], new(creditAccountCompressor.CreditAccountData)).(*creditAccountCompressor.CreditAccountData)
301+
newaccountData = accountData
302+
log.Info(utils.ToJson(newaccountData))
303+
if !accountData.Success {
304+
log.Warn("after retry, getCreditAccoutn data is still not successful", blockNum, account)
305+
return dc.CreditAccountCallData{}, err
306+
}
307+
}
308+
return dc.GetAccountDataFromDCCall(dcw.client, core.NULL_ADDR, blockNum, newaccountData)
309+
}
310+
267311
// blockNum can't be zero
268312

269313
func (dcw *DataCompressorWrapper) GetCreditAccountData(version core.VersionType, blockNum int64, creditManager common.Address, borrower common.Address, account common.Address) (

go.mod

Lines changed: 2 additions & 2 deletions
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-20250408052012-1a750509b0a0
8+
github.com/Gearbox-protocol/sdk-go v0.0.0-20250412113852-53fe0875bc19
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
@@ -84,6 +84,6 @@ require (
8484

8585
replace github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.1
8686

87-
replace github.com/Gearbox-protocol/sdk-go v0.0.0-20250402073851-44589b7f10df => ../sdk-go
87+
replace github.com/Gearbox-protocol/sdk-go v0.0.0-20250408052012-1a750509b0a0 => ../sdk-go
8888

8989
replace github.com/ethereum/go-ethereum v1.13.14 => github.com/OffchainLabs/go-ethereum v1.13.4-0.20240313010929-e5d8587e7227

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
88
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
99
github.com/Gearbox-protocol/sdk-go v0.0.0-20250408052012-1a750509b0a0 h1:2xyatkhoaXBi/7/rXiZxUqR/1OJuGsVfH3xNzzuu6Fs=
1010
github.com/Gearbox-protocol/sdk-go v0.0.0-20250408052012-1a750509b0a0/go.mod h1:MZsiiSAwDdnHY6GEILYtHEqhb9wmbUUE34UBQgNlUyM=
11+
github.com/Gearbox-protocol/sdk-go v0.0.0-20250412113852-53fe0875bc19 h1:hGb50ChP/pcigoZvf8AXVRgpISyQAlTsxo++V1uYe7c=
12+
github.com/Gearbox-protocol/sdk-go v0.0.0-20250412113852-53fe0875bc19/go.mod h1:MZsiiSAwDdnHY6GEILYtHEqhb9wmbUUE34UBQgNlUyM=
1113
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
1214
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
1315
github.com/OffchainLabs/go-ethereum v1.13.4-0.20240313010929-e5d8587e7227 h1:+/3TrD+q+BP36jGj2Bycdmrc/joKLNbc5ImePQzKRLM=

jsonnet/mocks/aqf_multiple_adapters.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
dataId: 'BTC',
4141
signersThreshold: 5,
4242
token: '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
43+
feed: '#Redstone_1',
4344
},
4445
},
4546
},
@@ -58,6 +59,7 @@
5859
dataId: 'weETH_FUNDAMENTAL',
5960
signersThreshold: 5,
6061
token: '0x8C23b9E4CB9884e807294c4b4C33820333cC613c',
62+
feed: '#Redstone_1',
6163
},
6264
},
6365
},

models/aggregated_block_feed/base_price_feed/call_and_process.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func (mdl *BasePriceFeed) GetUnderlyingCalls(blockNum int64) (calls []multicall.
104104
DataId: dataId,
105105
SignersThreshold: signThreshold,
106106
UnderlyingToken: feedToken,
107+
Feed: common.HexToAddress(mdl.Address),
107108
}
108109
mdl.DetailsDS.Info[entry] = tokenDetails
109110
}

models/aggregated_block_feed/base_price_feed/token_ds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type DetailsDS struct {
1313
PFType string `json:"pfType"`
1414
Underlyings []string `json:"underlyings"`
1515
Info map[string]*core.RedStonePF `json:"info"`
16-
FetchedInfo bool `json:"fetchedInfo,omitempty"`
16+
FetchedInfo bool `json:"FetchedInfo,omitempty"`
1717
}
1818

1919
func (obj *DetailsDS) Load(in core.Json, version core.VersionType) {

models/aggregated_block_feed/composite_redstone_price_feed/model.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewRedstonePriceFeedFromAdapter(adapter *ds.SyncAdapter) *CompositeRedStone
4646
priceFeed1: common.BytesToAddress(pf1),
4747
Decimals: int8(new(big.Int).SetBytes(decimals).Int64()),
4848
}
49-
if obj.DetailsDS.Info[adapter.GetAddress()] == nil {
49+
if obj.DetailsDS.Info[adapter.GetAddress()] == nil || obj.DetailsDS.Info[adapter.GetAddress()].Feed == core.NULL_ADDR {
5050
_, signThreshold, dataId := priceFetcher.RedstoneDetails(obj.priceFeed0, adapter.Client)
5151
//
5252
if dataId == "beraETH_FUNDAMENTAL" {
@@ -62,6 +62,7 @@ func NewRedstonePriceFeedFromAdapter(adapter *ds.SyncAdapter) *CompositeRedStone
6262
DataId: dataId,
6363
SignersThreshold: signThreshold,
6464
UnderlyingToken: obj.Repo.GetFeedToTicker(obj.priceFeed0.Hex(), obj.Address),
65+
Feed: obj.priceFeed0,
6566
}
6667
obj.DetailsDS.Info[adapter.GetAddress()] = tokenDetails
6768
}

models/aggregated_block_feed/redstone_price_feed/model.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ func NewRedstonePriceFeedFromAdapter(adapter *ds.SyncAdapter) *RedstonePriceFeed
3535
obj := &RedstonePriceFeed{
3636
BasePriceFeed: base_price_feed.NewBasePriceFeedFromAdapter(adapter),
3737
}
38-
if obj.DetailsDS.Info[adapter.GetAddress()] == nil {
39-
feedToken, signThreshold, dataId := priceFetcher.RedstoneDetails(common.HexToAddress(adapter.GetAddress()), adapter.Client)
38+
if obj.DetailsDS.Info[adapter.GetAddress()] == nil || obj.DetailsDS.Info[adapter.GetAddress()].Feed == core.NULL_ADDR {
39+
feed := common.HexToAddress(adapter.GetAddress())
40+
feedToken, signThreshold, dataId := priceFetcher.RedstoneDetails(feed, adapter.Client)
4041
//
4142
tokenDetails := &core.RedStonePF{
4243
Type: 15,
4344
DataServiceId: "redstone-primary-prod",
4445
DataId: dataId,
4546
SignersThreshold: signThreshold,
4647
UnderlyingToken: feedToken,
48+
Feed: feed,
4749
}
4850
obj.DetailsDS.Info[adapter.GetAddress()] = tokenDetails
4951
}

models/credit_manager/cm_common/credit_session_state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ func (mdl *CommonCMAdapter) liqv3SessionCallAndResultFn(liquidatedAt int64, sess
105105
if err == nil && !dcAccountData.IsSuccessful && mdl.GetVersion() == core.NewVersion(300) {
106106
dcAccountData, err = mdl.retry(dcAccountData, liquidatedAt-1)
107107
}
108+
log.Info(utils.ToJson(dcAccountData))
108109
if err != nil {
109-
log.Fatalf("For blockNum %d CM:%s Borrower:%s %v", liquidatedAt, mdl.GetAddress(), session.Borrower, err)
110+
log.Fatalf("For blockNum %d Account:%s %v. txHash: %s", liquidatedAt, session.Account, err, liqv3Details.TxHash)
110111
}
111112
mdl.liqv3Session(liquidatedAt, session, dcAccountData, liqv3Details)
112113
}

models/credit_manager/cm_common/retry_redstone_get_account.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package cm_common
22

33
import (
4-
"math/big"
5-
6-
dcv3 "github.com/Gearbox-protocol/sdk-go/artifacts/dataCompressorv3"
74
"github.com/Gearbox-protocol/sdk-go/core"
85
"github.com/Gearbox-protocol/sdk-go/log"
96
"github.com/Gearbox-protocol/sdk-go/pkg/dc"
7+
"github.com/Gearbox-protocol/sdk-go/pkg/redstone"
108

119
"github.com/Gearbox-protocol/third-eye/ds"
12-
"github.com/Gearbox-protocol/third-eye/ds/dc_wrapper"
1310
"github.com/Gearbox-protocol/third-eye/models/pool/pool_v3"
14-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
11+
"github.com/ethereum/go-ethereum/common"
1512
)
1613

1714
func (mdl *CommonCMAdapter) priceFeedNeeded(balances core.DBBalanceFormat) (ans []core.RedStonePF) {
@@ -39,26 +36,16 @@ func (mdl *CommonCMAdapter) priceFeedNeeded(balances core.DBBalanceFormat) (ans
3936
return
4037
}
4138
func (mdl *CommonCMAdapter) retry(oldaccount dc.CreditAccountCallData, blockNum int64) (dc.CreditAccountCallData, error) {
42-
_, addr := mdl.Repo.GetDCWrapper().GetKeyAndAddress(core.NewVersion(300), blockNum, dc_wrapper.CREDIT_ACCOUNT_COMPRESSOR)
43-
dcw, err := dcv3.NewDataCompressorv3(addr, mdl.Client)
44-
log.CheckFatal(err)
4539
ts := mdl.Repo.SetAndGetBlock(blockNum).Timestamp
4640
bal := moreThan1Balance(oldaccount.Balances)
47-
pod := mdl.Repo.GetRedStonemgr().GetPodSign(int64(ts), mdl.priceFeedNeeded(bal))
48-
newaccountData, err := dcw.GetCreditAccountData(&bind.CallOpts{
49-
BlockNumber: big.NewInt(blockNum),
50-
},
51-
oldaccount.Addr,
52-
pod,
53-
)
54-
if err != nil {
55-
return dc.CreditAccountCallData{}, err
56-
}
57-
if !newaccountData.IsSuccessful {
58-
log.Warn("after retry, getCreditAccoutn data is still not successful", blockNum, oldaccount.Addr)
59-
}
60-
return dc.GetAccountDataFromDCCall(mdl.Client, core.NULL_ADDR, blockNum, newaccountData)
41+
redPFs := mdl.priceFeedNeeded(bal)
42+
v3Pods := mdl.Repo.GetRedStonemgr().GetPodSign(int64(ts), redPFs)
43+
v3PodsCalls := redstone.GetpodToCalls(300, common.HexToAddress(mdl.GetCreditFacadeAddr()), v3Pods, redPFs)
44+
log.Info("retrying to get credit account data", oldaccount.Addr, blockNum, "pods", len(v3Pods), "calls", len(v3PodsCalls))
45+
//
46+
return mdl.Repo.GetDCWrapper().Retry(blockNum, oldaccount.Addr, v3Pods, v3PodsCalls)
6147
}
48+
6249
func moreThan1Balance(oldBal []core.TokenBalanceCallData) core.DBBalanceFormat {
6350
dbFormat := core.DBBalanceFormat{}
6451
for _, balance := range oldBal {

0 commit comments

Comments
 (0)