Skip to content

Commit a179986

Browse files
committed
fix: adding multiple dcs
1 parent 2780dda commit a179986

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

ds/dc_wrapper/wrapper.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,31 +181,39 @@ func (dcw *DataCompressorWrapper) LoadMultipleDC(multiDCs interface{}) {
181181
log.Fatalf("Converting address provider() details for dc to map failed %v", multiDCs)
182182
}
183183

184-
var blockNums []int64
185-
for k := range dcMap {
186-
blockNum, err := strconv.ParseInt(k, 10, 64)
187-
if err != nil {
188-
log.Fatal(err)
184+
blockNums := []int64{}
185+
{
186+
blockMap := map[int64]struct{}{}
187+
for k := range dcMap {
188+
splits := strings.Split(k, "_")
189+
blockNum, err := strconv.ParseInt(splits[0], 10, 64)
190+
if err != nil {
191+
log.Fatal(err)
192+
}
193+
blockMap[blockNum] = struct{}{}
194+
}
195+
for blockNum := range blockMap {
196+
blockNums = append(blockNums, blockNum)
189197
}
190-
blockNums = append(blockNums, blockNum)
198+
sort.Slice(blockNums, func(i, j int) bool { return blockNums[i] < blockNums[j] })
191199
}
192-
sort.Slice(blockNums, func(i, j int) bool { return blockNums[i] < blockNums[j] })
193200
for _, blockNum := range blockNums {
194-
k := fmt.Sprintf("%d", blockNum)
195-
dcAddr := dcMap[k].(string)
196-
//
197-
if strings.Contains(dcAddr, "_") {
198-
addrs := strings.Split(dcAddr, "_")
199-
if addrs[1] == "300" {
200-
version, err := strconv.ParseInt(addrs[1], 10, 64)
201-
log.CheckFatal(err)
202-
dcw.addDataCompressorv300(core.NewVersion(int16(version)), addrs[0], blockNum)
203-
} else {
204-
dcw.AddCompressorType(common.HexToAddress(addrs[0]), CompressorType(addrs[1]), blockNum)
201+
for _, suffix := range []CompressorType{CompressorType(""), CompressorType("300"), MARKET_COMPRESSOR, POOL_COMPRESSOR, CREDIT_ACCOUNT_COMPRESSOR} {
202+
key := fmt.Sprintf("%d", blockNum)
203+
if suffix != "" {
204+
key = fmt.Sprintf("%d_%s", blockNum, suffix)
205+
}
206+
if dcAddr, ok := dcMap[key].(string); ok {
207+
if suffix == "" {
208+
dcw.addDataCompressorv1v2(blockNum, dcAddr)
209+
} else if suffix == "300" {
210+
dcw.addDataCompressorv300(core.NewVersion(300), dcAddr, blockNum)
211+
} else {
212+
dcw.AddCompressorType(common.HexToAddress(dcAddr), suffix, blockNum)
213+
}
205214
}
206-
} else {
207-
dcw.addDataCompressorv1v2(blockNum, dcAddr)
208215
}
216+
//
209217
}
210218
}
211219

migrations/000056_v310.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CREATE TABLE relations (
3030
);
3131

3232
-- UPDATE
33-
update pools p set price_oracle=sa.address from sync_adapters sa where type='PriceOracle' and p._version=sa.version;
33+
update pools p set price_oracle=sa.address from sync_adapters sa where type='PriceOracle' and (case when p._version=1 then 2 else p._version end)=sa.version;
3434

3535
update token_oracle set disabled_at=19752044 where version=2; -- don't disable for v1
3636
update token_oracle set disabled_at=13856183 where feed='0xc170DC3C2e8809AC6197D56b86bF421c8a7f8c67'; -- all for v1

models/address_provider/on_log.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (mdl *AddressProvider) OnLog(txLog types.Log) {
124124
switch txLog.Topics[0] {
125125
case core.Topic("AddressSet(bytes32,address)"):
126126
mdl.v2LogParse(txLog)
127-
case core.Topic("SetAddress(bytes32,address,uint256)"): // can be used for version 310 address provider too. set PriceOracle acl contractregister are not emitted thought
127+
case core.Topic("SetAddress(bytes32,address,uint256)"):
128128
contract := strings.Trim(string(txLog.Topics[1][:]), "\x00")
129129
address := common.BytesToAddress(txLog.Topics[2][:])
130130
mdl.v3LogParse(txLog, contract, address.Hex(), getRealVersion(txLog.Topics[3]))
@@ -166,10 +166,10 @@ func (mdl *AddressProvider) v310LogParse(txLog types.Log, contract string, addre
166166
"POOL_COMPRESSOR": dc_wrapper.POOL_COMPRESSOR,
167167
}
168168
cType := m[contract]
169-
newValue := fmt.Sprintf("%s_%s", txLog.Address.Hex(), cType)
169+
newValue := address
170170
//
171171
dcObj, fn := mdl.updateDetailsField_dc()
172-
dcObj[fmt.Sprintf("%d", blockNum)] = newValue
172+
dcObj[fmt.Sprintf("%d_%s", blockNum, cType)] = newValue
173173
fn(dcObj)
174174
mdl.Repo.GetDCWrapper().AddCompressorType(common.HexToAddress(address), cType, int64(txLog.BlockNumber))
175175
}
@@ -188,10 +188,10 @@ func (mdl *AddressProvider) v3LogParse(txLog types.Log, contract string, address
188188
log.Infof("Don't add %s version %d", address, realversion)
189189
return
190190
}
191-
dcObj[fmt.Sprintf("%d", blockNum)] = fmt.Sprintf("%s_%d", address, realversion)
191+
dcObj[fmt.Sprintf("%d_300", blockNum)] = address
192192
fn(dcObj)
193193
// v3
194-
mdl.Repo.GetDCWrapper().AddDataCompressorv300(core.NewVersion(realversion), address, blockNum)
194+
mdl.Repo.GetDCWrapper().AddDataCompressorv300(core.NewVersion(300), address, blockNum)
195195
case "PRICE_ORACLE":
196196
if realversion < 300 { // don't except v2,v2.10 or v1 priceOracle , why are already know from v1 addressProvider
197197
return

0 commit comments

Comments
 (0)