Skip to content

Commit 77bda68

Browse files
committed
fix: partial liq
1 parent d3b7a86 commit 77bda68

File tree

8 files changed

+34
-19
lines changed

8 files changed

+34
-19
lines changed

ds/execute_parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func NewFacadeCallNameWithMulticall(facade, name string, multicalls []multicall.
4242
facade: common.HexToAddress(facade).Hex(),
4343
}
4444
}
45+
func (obj *FacadeCallNameWithMulticall) AddMulticall(calls []multicall.Multicall2Call) {
46+
obj.multiCalls = append(obj.multiCalls, calls...)
47+
}
4548

4649
func (obj FacadeCallNameWithMulticall) String() string {
4750
str := ""

ds/multicall_processor/index.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/Gearbox-protocol/sdk-go/core/schemas"
55
"github.com/Gearbox-protocol/third-eye/ds"
66
"github.com/Gearbox-protocol/third-eye/models/pool/pool_v3"
7+
"github.com/ethereum/go-ethereum/common"
78
)
89

910
const (
@@ -50,6 +51,7 @@ type MulticallProcessorI interface {
5051
AddCloseEvent(event *schemas.AccountOperation)
5152
AddLiquidateEvent(event *schemas.AccountOperation)
5253
PopNonMulticallEvents() []*schemas.AccountOperation
53-
PopMainActions(txHash string, mgr *ds.AccountQuotaMgr) (facadeActions, openEventWithoutMulticall []*FacadeAccountAction)
54+
PopMainActions(txHash string, mgr *ds.AccountQuotaMgr) (facadeActions, openEventWithoutMulticall []*FacadeAccountAction, _ common.Address)
5455
End(logId uint, debts []pool_v3.ManageDebt, _, _ string)
56+
SetPartialLiq(account common.Address)
5557
}

ds/multicall_processor/multicall_processor_v2.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/Gearbox-protocol/sdk-go/utils"
77
"github.com/Gearbox-protocol/third-eye/ds"
88
"github.com/Gearbox-protocol/third-eye/models/pool/pool_v3"
9+
"github.com/ethereum/go-ethereum/common"
910
)
1011

1112
type MultiCallProcessorv2 struct {
@@ -102,7 +103,7 @@ func (p *MultiCallProcessorv2) End(logId uint, _ []pool_v3.ManageDebt, _ string,
102103
// - open call without multicalls
103104
// - open call have the multicalls in them
104105
// liquidated, closed and directly multicalls are separated entries
105-
func (p *MultiCallProcessorv2) PopMainActions(_ string, _ *ds.AccountQuotaMgr) (facadeActions, openEventWithoutMulticall []*FacadeAccountAction) {
106+
func (p *MultiCallProcessorv2) PopMainActions(_ string, _ *ds.AccountQuotaMgr) (facadeActions, openEventWithoutMulticall []*FacadeAccountAction, _ common.Address) {
106107
defer func() { p.facadeActions = nil }()
107108
p.noOfOpens = 0
108109
for _, entry := range p.facadeActions {
@@ -121,3 +122,5 @@ func (p *MultiCallProcessorv2) PopNonMulticallEvents() []*schemas.AccountOperati
121122
p.nonMultiCallEvents = nil
122123
return calls
123124
}
125+
func (p *MultiCallProcessorv2) SetPartialLiq(account common.Address) {
126+
}

ds/multicall_processor/multicall_processor_v3.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func addQuotasToFacade(action *FacadeAccountAction, quotaEvents []*ds.UpdateQuot
194194
type MultiCallProcessorv3 struct {
195195
units map[string]*MultiCallProcessorv3Unit
196196
facadeAddrToSession map[string]string
197+
PartialLiqAccount common.Address
197198
}
198199

199200
func NewMultiCallProcessorv3() *MultiCallProcessorv3 {
@@ -265,7 +266,7 @@ func (p *MultiCallProcessorv3) PopNonMulticallEvents() []*schemas.AccountOperati
265266
}
266267
return calls
267268
}
268-
func (p *MultiCallProcessorv3) PopMainActions(txHash string, mgr *ds.AccountQuotaMgr) (facadeActions, openEventWithoutMulticall []*FacadeAccountAction) {
269+
func (p *MultiCallProcessorv3) PopMainActions(txHash string, mgr *ds.AccountQuotaMgr) (facadeActions, openEventWithoutMulticall []*FacadeAccountAction, partialLiqAccount common.Address) {
269270
quotas := mgr.GetUpdateQuotaEventForAccount(common.HexToHash(txHash))
270271
for sessionId, unit := range p.units {
271272
facade, openWithoutMC := unit.popMainActions(txHash, quotas[common.HexToAddress(strings.Split(sessionId, "_")[0])], mgr)
@@ -276,6 +277,8 @@ func (p *MultiCallProcessorv3) PopMainActions(txHash string, mgr *ds.AccountQuot
276277
if len(p.facadeAddrToSession) != 0 {
277278
log.Fatal("facadeAddrToSession not empty after popping main actions", utils.ToJson(p.facadeAddrToSession))
278279
}
280+
partialLiqAccount = p.PartialLiqAccount
281+
p.PartialLiqAccount = core.NULL_ADDR
279282
return
280283

281284
}
@@ -292,3 +295,7 @@ func (p *MultiCallProcessorv3) End(logId uint, debts []pool_v3.ManageDebt, under
292295
}
293296
unit.End(logId, debts, underlyingtoken)
294297
}
298+
299+
func (p *MultiCallProcessorv3) SetPartialLiq(account common.Address) {
300+
p.PartialLiqAccount = account
301+
}

models/credit_manager/cm_common/facade_actions.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ import (
1919
// this function adds multicall to mainFacadeActions
2020
// if that is the correct structure of operation
2121
func (mdl *CommonCMAdapter) fixFacadeActionStructureViaTenderlyCalls(mainCalls []*ds.FacadeCallNameWithMulticall,
22-
facadeActions []*mpi.FacadeAccountAction) (result []*mpi.FacadeAccountAction) { // facadeEvents from rpc, mainCalls from tenderly
22+
facadeActions []*mpi.FacadeAccountAction, partialLiqAccount common.Address) (result []*mpi.FacadeAccountAction) { // facadeEvents from rpc, mainCalls from tenderly
2323
if len(mainCalls) > len(facadeActions) {
24-
25-
log.Warn(utils.ToJson(mainCalls), utils.ToJson(facadeActions))
2624
log.Warnf("Len of calls(%d) can't be more than separated close/liquidate and multicall(%d).",
2725
len(mainCalls), len(facadeActions),
2826
)
29-
if "0x6355aa8c94e2db37e99bb6702dd66ef189d1d356cc3149081be247f72f526c8d" == facadeActions[0].Data.TxHash {
30-
//mainCalls = []*ds.FacadeCallNameWithMulticall{mainCalls[1]}
27+
if len(facadeActions) == 1 && len(mainCalls) == 2 && partialLiqAccount != core.NULL_ADDR { // in the partial declaration in the open call, there is no instruction done, and there is another separate multi-call where all the instructions are done.
28+
if len(mainCalls[0].GetMulticalls()) != 0 || mainCalls[0].Name != ds.FacadeOpenMulticallCall {
29+
log.Fatal("first main call should be open with multicall and no multicalls inside")
30+
}
31+
mainCalls[0].AddMulticall(mainCalls[1].GetMulticalls())
32+
log.Warnf(" with partial liquidation for account %s, combining open with multicall", partialLiqAccount.Hex())
33+
mainCalls = mainCalls[:1] // skip the first main call which is open with partial liquidation
3134
}
3235
}
3336
//

models/credit_manager/cm_common/process_multicall.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
func (mdl CommonCMAdapter) ProcessRemainingMultiCalls(version core.VersionType, lastTxHash string, nonMultiCallExecuteEvents []ds.ExecuteParams) {
2525

2626
accountQuotaMgr := mdl.Repo.GetAccountQuotaMgr()
27-
facadeActions, openEventWithoutMulticall := mdl.MulticallMgr.PopMainActions(lastTxHash, accountQuotaMgr)
27+
facadeActions, openEventWithoutMulticall, partialLiqAccount := mdl.MulticallMgr.PopMainActions(lastTxHash, accountQuotaMgr)
2828

2929
// only for v2/v2.10
3030
for _, entry := range openEventWithoutMulticall {
@@ -40,7 +40,7 @@ func (mdl CommonCMAdapter) ProcessRemainingMultiCalls(version core.VersionType,
4040
}
4141
if len(facadeActions) > 0 { // account operation will only exist if there are one or more facade actions
4242
mainCalls := mdl.Repo.GetExecuteParser().GetMainCalls(lastTxHash, mdl.GetCreditFacadeAddr())
43-
fixedFacadeActions := mdl.fixFacadeActionStructureViaTenderlyCalls(mainCalls, facadeActions)
43+
fixedFacadeActions := mdl.fixFacadeActionStructureViaTenderlyCalls(mainCalls, facadeActions, partialLiqAccount)
4444
mdl.validateAndSaveFacadeActions(version, lastTxHash, fixedFacadeActions, mainCalls, nonMultiCallExecuteEvents)
4545
} else if len(nonMultiCallExecuteEvents) > 0 {
4646
mdl.SaveExecuteEvents(lastTxHash, nonMultiCallExecuteEvents)

models/credit_manager/cm_v3/v3.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func (mdl *CMv3) checkLogV3(txLog types.Log) {
128128
},
129129
Transfers: &core.Transfers{},
130130
}
131+
mdl.MulticallMgr.SetPartialLiq(creditAccount)
131132
poolv3 := mdl.Repo.GetAdapter(mdl.State.PoolAddress).(*pool_v3.Poolv3)
132133
debts := poolv3.GetDebt(txLog.TxHash, mdl.Address, txLog.Index)
133134
multicall_processor.AddManageDebtsToMain(accountOp, debts, mdl.GetUnderlyingToken())

services/call_with_multicall.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package services
33
import (
44
"encoding/hex"
55
"reflect"
6-
"strings"
6+
"strings"
7+
78
"github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
89
"github.com/Gearbox-protocol/sdk-go/core"
910
"github.com/Gearbox-protocol/sdk-go/log"
@@ -48,7 +49,7 @@ func (ep *ExecuteParser) getMainEvents(call *trace_service.Call, creditFacade co
4849
"e3f46b26", // liquidateCreditAccount (v3) // v310, v3
4950
"36b2ced3", // closeCreditAccount(creditAccount,to,skipTokenMask,convertToETH,calls) // v310, v3
5051
// "5d91a0e0", // liquidateCreditAccount
51-
// "85589e10", //Partial
52+
// "85589e10", //Partial
5253
"92beab1d": // openCreditAccount(onBehalfOf,calls,referralCode) // v310, v3
5354
// log.Info("v3 main event", call.Input[2:10])
5455
event, err := getCreditFacadeMainEvent(call.To, call.Input, creditFacadev3Parser)
@@ -79,8 +80,6 @@ func init() {
7980
creditFacadev2Parser = core.GetAbi("CreditFacade")
8081
creditFacadev3Parser = core.GetAbi("CreditFacadev3")
8182

82-
83-
8483
}
8584
func getABI(data string) *abi.ABI {
8685
abi, err := abi.JSON(strings.NewReader(data))
@@ -89,11 +88,8 @@ func getABI(data string) *abi.ABI {
8988
}
9089

9190
var pp = "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"creditAccount\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"token\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"repaidAmount\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"minSeizedAmount\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"to\",\"type\":\"address\"},{\"components\":[{\"internalType\":\"address\",\"name\":\"priceFeed\",\"type\":\"address\"},{\"internalType\":\"bytes\",\"name\":\"data\",\"type\":\"bytes\"}],\"internalType\":\"struct PriceUpdate[]\",\"name\":\"priceUpdates\",\"type\":\"tuple[]\"}],\"name\":\"partiallyLiquidateCreditAccount\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"seizedAmount\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
91+
9292
func getCreditFacadeMainEvent(contract string, input string, parser *abi.ABI) (*ds.FacadeCallNameWithMulticall, error) {
93-
a :=input[2:10] == "85589e10"
94-
if a {
95-
parser = getABI(pp)
96-
}
9793
hexData, err := hex.DecodeString(input[2:])
9894
if err != nil {
9995
return nil, err
@@ -112,7 +108,7 @@ parser = getABI(pp)
112108
Target common.Address `json:"target"`
113109
CallData []uint8 `json:"callData"`
114110
})
115-
if !ok && !a {
111+
if !ok {
116112
log.Fatal("calls type is different the creditFacade multicall: ", reflect.TypeOf(data["calls"]))
117113
}
118114
multicalls := []multicall.Multicall2Call{}

0 commit comments

Comments
 (0)