common: change type of variables for constants

This commit is contained in:
JukLee0ira 2025-02-17 10:52:19 +08:00
parent 0b40863458
commit 51dac59e92
15 changed files with 110 additions and 110 deletions

View file

@ -319,7 +319,7 @@ func IsValidRelayer(statedb *state.StateDB, address common.Address) bool {
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locRelayerState, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance := statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
if balance.Cmp(new(big.Int).Mul(common.BasePrice, common.RelayerLockedFund)) <= 0 {
log.Debug("Relayer is not in relayer list", "relayer", address.String(), "balance", balance)
return false

View file

@ -24,7 +24,7 @@ func GetExRelayerFee(relayer common.Address, statedb *state.StateDB) *big.Int {
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_fee"])
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Big()
return statedb.GetState(common.RelayerRegistrationSMC, locHash).Big()
}
func GetRelayerOwner(relayer common.Address, statedb *state.StateDB) common.Address {
@ -33,7 +33,7 @@ func GetRelayerOwner(relayer common.Address, statedb *state.StateDB) common.Addr
log.Debug("GetRelayerOwner", "relayer", relayer.Hex(), "slot", slot, "locBig", locBig)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_owner"])
locHash := common.BigToHash(locBig)
return common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Bytes())
return common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, locHash).Bytes())
}
// return true if relayer request to resign and have not withdraw locked fund
@ -41,7 +41,7 @@ func IsResignedRelayer(relayer common.Address, statedb *state.StateDB) bool {
slot := RelayerMappingSlot["RESIGN_REQUESTS"]
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash) != (common.Hash{})
return statedb.GetState(common.RelayerRegistrationSMC, locHash) != (common.Hash{})
}
func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
@ -49,7 +49,7 @@ func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_fromTokens"])
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Big().Uint64()
return statedb.GetState(common.RelayerRegistrationSMC, locHash).Big().Uint64()
}
func GetBaseTokenAtIndex(relayer common.Address, statedb *state.StateDB, index uint64) common.Address {
@ -58,7 +58,7 @@ func GetBaseTokenAtIndex(relayer common.Address, statedb *state.StateDB, index u
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_fromTokens"])
locHash := common.BigToHash(locBig)
loc := state.GetLocDynamicArrAtElement(locHash, index, 1)
return common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), loc).Bytes())
return common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, loc).Bytes())
}
func GetQuoteTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
@ -66,7 +66,7 @@ func GetQuoteTokenLength(relayer common.Address, statedb *state.StateDB) uint64
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_toTokens"])
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Big().Uint64()
return statedb.GetState(common.RelayerRegistrationSMC, locHash).Big().Uint64()
}
func GetQuoteTokenAtIndex(relayer common.Address, statedb *state.StateDB, index uint64) common.Address {
@ -75,13 +75,13 @@ func GetQuoteTokenAtIndex(relayer common.Address, statedb *state.StateDB, index
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_toTokens"])
locHash := common.BigToHash(locBig)
loc := state.GetLocDynamicArrAtElement(locHash, index, 1)
return common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), loc).Bytes())
return common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, loc).Bytes())
}
func GetRelayerCount(statedb *state.StateDB) uint64 {
slot := RelayerMappingSlot["RelayerCount"]
slotHash := common.BigToHash(new(big.Int).SetUint64(slot))
valueHash := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), slotHash)
valueHash := statedb.GetState(common.RelayerRegistrationSMC, slotHash)
return new(big.Int).SetBytes(valueHash.Bytes()).Uint64()
}
@ -90,7 +90,7 @@ func GetAllCoinbases(statedb *state.StateDB) []common.Address {
slot := RelayerMappingSlot["RELAYER_COINBASES"]
coinbases := []common.Address{}
for i := uint64(0); i < relayerCount; i++ {
valueHash := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), common.BytesToHash(state.GetLocMappingAtKey(common.BigToHash(big.NewInt(int64(i))), slot).Bytes()))
valueHash := statedb.GetState(common.RelayerRegistrationSMC, common.BytesToHash(state.GetLocMappingAtKey(common.BigToHash(big.NewInt(int64(i))), slot).Bytes()))
coinbases = append(coinbases, common.BytesToAddress(valueHash.Bytes()))
}
return coinbases
@ -102,21 +102,21 @@ func GetAllTradingPairs(statedb *state.StateDB) (map[common.Hash]bool, error) {
for _, coinbase := range coinbases {
locBig := GetLocMappingAtKey(coinbase.Hash(), slot)
fromTokenSlot := new(big.Int).Add(locBig, RelayerStructMappingSlot["_fromTokens"])
fromTokenLength := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), common.BigToHash(fromTokenSlot)).Big().Uint64()
fromTokenLength := statedb.GetState(common.RelayerRegistrationSMC, common.BigToHash(fromTokenSlot)).Big().Uint64()
toTokenSlot := new(big.Int).Add(locBig, RelayerStructMappingSlot["_toTokens"])
toTokenLength := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), common.BigToHash(toTokenSlot)).Big().Uint64()
toTokenLength := statedb.GetState(common.RelayerRegistrationSMC, common.BigToHash(toTokenSlot)).Big().Uint64()
if toTokenLength != fromTokenLength {
return map[common.Hash]bool{}, fmt.Errorf("invalid length from token & to token: from :%d , to :%d ", fromTokenLength, toTokenLength)
}
fromTokens := []common.Address{}
fromTokenSlotHash := common.BytesToHash(fromTokenSlot.Bytes())
for i := uint64(0); i < fromTokenLength; i++ {
fromToken := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), state.GetLocDynamicArrAtElement(fromTokenSlotHash, i, uint64(1))).Bytes())
fromToken := common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, state.GetLocDynamicArrAtElement(fromTokenSlotHash, i, uint64(1))).Bytes())
fromTokens = append(fromTokens, fromToken)
}
toTokenSlotHash := common.BytesToHash(toTokenSlot.Bytes())
for i := uint64(0); i < toTokenLength; i++ {
toToken := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), state.GetLocDynamicArrAtElement(toTokenSlotHash, i, uint64(1))).Bytes())
toToken := common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, state.GetLocDynamicArrAtElement(toTokenSlotHash, i, uint64(1))).Bytes())
log.Debug("GetAllTradingPairs all pair info", "from", fromTokens[i].Hex(), "toToken", toToken.Hex())
allPairs[GetTradingOrderBookHash(fromTokens[i], toToken)] = true
@ -132,14 +132,14 @@ func SubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateDB)
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance := statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
log.Debug("ApplyXDCXMatchedTransaction settle balance: SubRelayerFee BEFORE", "relayer", relayer.String(), "balance", balance)
if balance.Cmp(fee) < 0 {
return errors.Errorf("relayer %s isn't enough XDC fee", relayer.String())
} else {
balance = new(big.Int).Sub(balance, fee)
statedb.SetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.HexToAddress(common.RelayerRegistrationSMC), fee)
statedb.SetState(common.RelayerRegistrationSMC, locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.RelayerRegistrationSMC, fee)
log.Debug("ApplyXDCXMatchedTransaction settle balance: SubRelayerFee AFTER", "relayer", relayer.String(), "balance", balance)
return nil
}
@ -151,7 +151,7 @@ func CheckRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateD
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance := statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
if new(big.Int).Sub(balance, fee).Cmp(new(big.Int).Mul(common.BasePrice, common.RelayerLockedFund)) < 0 {
return errors.Errorf("relayer %s isn't enough XDC fee : balance %d , fee : %d ", relayer.Hex(), balance.Uint64(), fee.Uint64())
}
@ -295,7 +295,7 @@ func CheckSubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.Sta
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance = statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance = statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
}
log.Debug("CheckSubRelayerFee settle balance: SubRelayerFee ", "relayer", relayer.String(), "balance", balance, "fee", fee)
if balance.Cmp(fee) < 0 {
@ -343,6 +343,6 @@ func SetSubRelayerFee(relayer common.Address, balance *big.Int, fee *big.Int, st
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
statedb.SetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.HexToAddress(common.RelayerRegistrationSMC), fee)
statedb.SetState(common.RelayerRegistrationSMC, locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.RelayerRegistrationSMC, fee)
}

View file

@ -45,7 +45,7 @@ func IsValidRelayer(statedb *state.StateDB, coinbase common.Address) bool {
// a valid relayer must have baseToken
locBaseToken := state.GetLocOfStructElement(locRelayerState, LendingRelayerStructSlots["bases"])
if v := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), common.BytesToHash(locBaseToken.Bytes())); v != (common.Hash{}) {
if v := statedb.GetState(common.LendingRegistrationSMC, common.BytesToHash(locBaseToken.Bytes())); v != (common.Hash{}) {
if tradingstate.IsResignedRelayer(coinbase, statedb) {
return false
}
@ -54,7 +54,7 @@ func IsValidRelayer(statedb *state.StateDB, coinbase common.Address) bool {
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locRelayerStateTrading, tradingstate.RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance := statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
expectedFund := new(big.Int).Mul(common.BasePrice, common.RelayerLockedFund)
if balance.Cmp(expectedFund) <= 0 {
log.Debug("Relayer is not in relayer list", "relayer", coinbase.String(), "balance", balance, "expected", expectedFund)
@ -72,7 +72,7 @@ func IsValidRelayer(statedb *state.StateDB, coinbase common.Address) bool {
func GetFee(statedb *state.StateDB, coinbase common.Address) *big.Int {
locRelayerState := state.GetLocMappingAtKey(coinbase.Hash(), LendingRelayerListSlot)
locHash := common.BytesToHash(new(big.Int).Add(locRelayerState, LendingRelayerStructSlots["fee"]).Bytes())
return statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locHash).Big()
return statedb.GetState(common.LendingRegistrationSMC, locHash).Big()
}
// @function GetBaseList
@ -83,10 +83,10 @@ func GetBaseList(statedb *state.StateDB, coinbase common.Address) []common.Addre
baseList := []common.Address{}
locRelayerState := state.GetLocMappingAtKey(coinbase.Hash(), LendingRelayerListSlot)
locBaseHash := state.GetLocOfStructElement(locRelayerState, LendingRelayerStructSlots["bases"])
length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locBaseHash).Big().Uint64()
length := statedb.GetState(common.LendingRegistrationSMC, locBaseHash).Big().Uint64()
for i := uint64(0); i < length; i++ {
loc := state.GetLocDynamicArrAtElement(locBaseHash, i, 1)
addr := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Bytes())
addr := common.BytesToAddress(statedb.GetState(common.LendingRegistrationSMC, loc).Bytes())
if addr != (common.Address{}) {
baseList = append(baseList, addr)
}
@ -102,10 +102,10 @@ func GetTerms(statedb *state.StateDB, coinbase common.Address) []uint64 {
terms := []uint64{}
locRelayerState := state.GetLocMappingAtKey(coinbase.Hash(), LendingRelayerListSlot)
locTermHash := state.GetLocOfStructElement(locRelayerState, LendingRelayerStructSlots["terms"])
length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locTermHash).Big().Uint64()
length := statedb.GetState(common.LendingRegistrationSMC, locTermHash).Big().Uint64()
for i := uint64(0); i < length; i++ {
loc := state.GetLocDynamicArrAtElement(locTermHash, i, 1)
t := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Big().Uint64()
t := statedb.GetState(common.LendingRegistrationSMC, loc).Big().Uint64()
if t != uint64(0) {
terms = append(terms, t)
}
@ -153,20 +153,20 @@ func GetCollaterals(statedb *state.StateDB, coinbase common.Address, baseToken c
//TODO: ILO Collateral is not supported in release 2.2.0
//locRelayerState := state.GetLocMappingAtKey(coinbase.Hash(), LendingRelayerListSlot)
//locCollateralHash := state.GetLocOfStructElement(locRelayerState, LendingRelayerStructSlots["collaterals"])
//length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locCollateralHash).Big().Uint64()
//length := statedb.GetState(common.LendingRegistrationSMC, locCollateralHash).Big().Uint64()
//
//loc := state.GetLocDynamicArrAtElement(locCollateralHash, pairIndex, 1)
//collateralAddr := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Bytes())
//collateralAddr := common.BytesToAddress(statedb.GetState(common.LendingRegistrationSMC, loc).Bytes())
//if collateralAddr != (common.Address{}) && collateralAddr != (common.HexToAddress("0x0")) {
// return []common.Address{collateralAddr}, true
//}
// if collaterals is not defined for the relayer, return default collaterals
locDefaultCollateralHash := state.GetLocSimpleVariable(DefaultCollateralSlot)
length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locDefaultCollateralHash).Big().Uint64()
length := statedb.GetState(common.LendingRegistrationSMC, locDefaultCollateralHash).Big().Uint64()
for i := uint64(0); i < length; i++ {
loc := state.GetLocDynamicArrAtElement(locDefaultCollateralHash, i, 1)
addr := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Bytes())
addr := common.BytesToAddress(statedb.GetState(common.LendingRegistrationSMC, loc).Bytes())
if addr != (common.Address{}) {
collaterals = append(collaterals, addr)
}
@ -183,9 +183,9 @@ func GetCollateralDetail(statedb *state.StateDB, token common.Address) (depositR
locDepositRate := state.GetLocOfStructElement(collateralState, CollateralStructSlots["depositRate"])
locLiquidationRate := state.GetLocOfStructElement(collateralState, CollateralStructSlots["liquidationRate"])
locRecallRate := state.GetLocOfStructElement(collateralState, CollateralStructSlots["recallRate"])
depositRate = statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locDepositRate).Big()
liquidationRate = statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locLiquidationRate).Big()
recallRate = statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locRecallRate).Big()
depositRate = statedb.GetState(common.LendingRegistrationSMC, locDepositRate).Big()
liquidationRate = statedb.GetState(common.LendingRegistrationSMC, locLiquidationRate).Big()
recallRate = statedb.GetState(common.LendingRegistrationSMC, locRecallRate).Big()
return depositRate, liquidationRate, recallRate
}
@ -197,8 +197,8 @@ func GetCollateralPrice(statedb *state.StateDB, collateralToken common.Address,
locCollateralPrice := common.BigToHash(new(big.Int).Add(new(big.Int).SetBytes(locLendingTokenPriceByte), PriceStructSlots["price"]))
locBlockNumber := common.BigToHash(new(big.Int).Add(new(big.Int).SetBytes(locLendingTokenPriceByte), PriceStructSlots["blockNumber"]))
price = statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locCollateralPrice).Big()
blockNumber = statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locBlockNumber).Big()
price = statedb.GetState(common.LendingRegistrationSMC, locCollateralPrice).Big()
blockNumber = statedb.GetState(common.LendingRegistrationSMC, locBlockNumber).Big()
return price, blockNumber
}
@ -208,10 +208,10 @@ func GetCollateralPrice(statedb *state.StateDB, collateralToken common.Address,
func GetSupportedTerms(statedb *state.StateDB) []uint64 {
terms := []uint64{}
locSupportedTerm := state.GetLocSimpleVariable(SupportedTermSlot)
length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locSupportedTerm).Big().Uint64()
length := statedb.GetState(common.LendingRegistrationSMC, locSupportedTerm).Big().Uint64()
for i := uint64(0); i < length; i++ {
loc := state.GetLocDynamicArrAtElement(locSupportedTerm, i, 1)
t := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Big().Uint64()
t := statedb.GetState(common.LendingRegistrationSMC, loc).Big().Uint64()
if t != 0 {
terms = append(terms, t)
}
@ -225,10 +225,10 @@ func GetSupportedTerms(statedb *state.StateDB) []uint64 {
func GetSupportedBaseToken(statedb *state.StateDB) []common.Address {
baseTokens := []common.Address{}
locSupportedBaseToken := state.GetLocSimpleVariable(SupportedBaseSlot)
length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locSupportedBaseToken).Big().Uint64()
length := statedb.GetState(common.LendingRegistrationSMC, locSupportedBaseToken).Big().Uint64()
for i := uint64(0); i < length; i++ {
loc := state.GetLocDynamicArrAtElement(locSupportedBaseToken, i, 1)
addr := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Bytes())
addr := common.BytesToAddress(statedb.GetState(common.LendingRegistrationSMC, loc).Bytes())
if addr != (common.Address{}) {
baseTokens = append(baseTokens, addr)
}
@ -244,20 +244,20 @@ func GetAllCollateral(statedb *state.StateDB) []common.Address {
//TODO: ILO Collateral is not supported in release 2.2.0
//locILOCollateral := state.GetLocSimpleVariable(ILOCollateralSlot)
//length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locILOCollateral).Big().Uint64()
//length := statedb.GetState(common.LendingRegistrationSMC, locILOCollateral).Big().Uint64()
//for i := uint64(0); i < length; i++ {
// loc := state.GetLocDynamicArrAtElement(locILOCollateral, i, 1)
// addr := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Bytes())
// addr := common.BytesToAddress(statedb.GetState(common.LendingRegistrationSMC, loc).Bytes())
// if addr != (common.Address{}) {
// collaterals = append(collaterals, addr)
// }
//}
locDefaultCollateralHash := state.GetLocSimpleVariable(DefaultCollateralSlot)
length := statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), locDefaultCollateralHash).Big().Uint64()
length := statedb.GetState(common.LendingRegistrationSMC, locDefaultCollateralHash).Big().Uint64()
for i := uint64(0); i < length; i++ {
loc := state.GetLocDynamicArrAtElement(locDefaultCollateralHash, i, 1)
addr := common.BytesToAddress(statedb.GetState(common.HexToAddress(common.LendingRegistrationSMC), loc).Bytes())
addr := common.BytesToAddress(statedb.GetState(common.LendingRegistrationSMC, loc).Bytes())
if addr != (common.Address{}) {
collaterals = append(collaterals, addr)
}

View file

@ -160,7 +160,7 @@ func TestLendingItem_VerifyLendingStatus(t *testing.T) {
func SetFee(statedb *state.StateDB, coinbase common.Address, feeRate *big.Int) {
locRelayerState := state.GetLocMappingAtKey(coinbase.Hash(), LendingRelayerListSlot)
locHash := common.BytesToHash(new(big.Int).Add(locRelayerState, LendingRelayerStructSlots["fee"]).Bytes())
statedb.SetState(common.HexToAddress(common.LendingRegistrationSMC), locHash, common.BigToHash(feeRate))
statedb.SetState(common.LendingRegistrationSMC, locHash, common.BigToHash(feeRate))
}
func SetCollateralDetail(statedb *state.StateDB, token common.Address, depositRate *big.Int, liquidationRate *big.Int, price *big.Int) {
@ -168,9 +168,9 @@ func SetCollateralDetail(statedb *state.StateDB, token common.Address, depositRa
locDepositRate := state.GetLocOfStructElement(collateralState, CollateralStructSlots["depositRate"])
locLiquidationRate := state.GetLocOfStructElement(collateralState, CollateralStructSlots["liquidationRate"])
locCollateralPrice := state.GetLocOfStructElement(collateralState, CollateralStructSlots["price"])
statedb.SetState(common.HexToAddress(common.LendingRegistrationSMC), locDepositRate, common.BigToHash(depositRate))
statedb.SetState(common.HexToAddress(common.LendingRegistrationSMC), locLiquidationRate, common.BigToHash(liquidationRate))
statedb.SetState(common.HexToAddress(common.LendingRegistrationSMC), locCollateralPrice, common.BigToHash(price))
statedb.SetState(common.LendingRegistrationSMC, locDepositRate, common.BigToHash(depositRate))
statedb.SetState(common.LendingRegistrationSMC, locLiquidationRate, common.BigToHash(liquidationRate))
statedb.SetState(common.LendingRegistrationSMC, locCollateralPrice, common.BigToHash(price))
}
func TestVerifyBalance(t *testing.T) {

View file

@ -24,7 +24,7 @@ func GetExRelayerFee(relayer common.Address, statedb *state.StateDB) *big.Int {
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_fee"])
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Big()
return statedb.GetState(common.RelayerRegistrationSMC, locHash).Big()
}
func GetRelayerOwner(relayer common.Address, statedb *state.StateDB) common.Address {
@ -33,7 +33,7 @@ func GetRelayerOwner(relayer common.Address, statedb *state.StateDB) common.Addr
log.Debug("GetRelayerOwner", "relayer", relayer.Hex(), "slot", slot, "locBig", locBig)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_owner"])
locHash := common.BigToHash(locBig)
return common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Bytes())
return common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, locHash).Bytes())
}
// return true if relayer request to resign and have not withdraw locked fund
@ -41,7 +41,7 @@ func IsResignedRelayer(relayer common.Address, statedb *state.StateDB) bool {
slot := RelayerMappingSlot["RESIGN_REQUESTS"]
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash) != (common.Hash{})
return statedb.GetState(common.RelayerRegistrationSMC, locHash) != (common.Hash{})
}
func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
@ -49,7 +49,7 @@ func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_fromTokens"])
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Big().Uint64()
return statedb.GetState(common.RelayerRegistrationSMC, locHash).Big().Uint64()
}
func GetBaseTokenAtIndex(relayer common.Address, statedb *state.StateDB, index uint64) common.Address {
@ -58,7 +58,7 @@ func GetBaseTokenAtIndex(relayer common.Address, statedb *state.StateDB, index u
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_fromTokens"])
locHash := common.BigToHash(locBig)
loc := state.GetLocDynamicArrAtElement(locHash, index, 1)
return common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), loc).Bytes())
return common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, loc).Bytes())
}
func GetQuoteTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
@ -66,7 +66,7 @@ func GetQuoteTokenLength(relayer common.Address, statedb *state.StateDB) uint64
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_toTokens"])
locHash := common.BigToHash(locBig)
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash).Big().Uint64()
return statedb.GetState(common.RelayerRegistrationSMC, locHash).Big().Uint64()
}
func GetQuoteTokenAtIndex(relayer common.Address, statedb *state.StateDB, index uint64) common.Address {
@ -75,7 +75,7 @@ func GetQuoteTokenAtIndex(relayer common.Address, statedb *state.StateDB, index
locBig = new(big.Int).Add(locBig, RelayerStructMappingSlot["_toTokens"])
locHash := common.BigToHash(locBig)
loc := state.GetLocDynamicArrAtElement(locHash, index, 1)
return common.BytesToAddress(statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), loc).Bytes())
return common.BytesToAddress(statedb.GetState(common.RelayerRegistrationSMC, loc).Bytes())
}
func SubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateDB) error {
@ -84,14 +84,14 @@ func SubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateDB)
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance := statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
log.Debug("ApplyXDCXMatchedTransaction settle balance: SubRelayerFee BEFORE", "relayer", relayer.String(), "balance", balance)
if balance.Cmp(fee) < 0 {
return errors.Errorf("relayer %s isn't enough XDC fee", relayer.String())
} else {
balance = new(big.Int).Sub(balance, fee)
statedb.SetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.HexToAddress(common.RelayerRegistrationSMC), fee)
statedb.SetState(common.RelayerRegistrationSMC, locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.RelayerRegistrationSMC, fee)
log.Debug("ApplyXDCXMatchedTransaction settle balance: SubRelayerFee AFTER", "relayer", relayer.String(), "balance", balance)
return nil
}
@ -103,7 +103,7 @@ func CheckRelayerFee(relayer common.Address, fee *big.Int, statedb *state.StateD
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance := statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance := statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
if new(big.Int).Sub(balance, fee).Cmp(new(big.Int).Mul(common.BasePrice, common.RelayerLockedFund)) < 0 {
return errors.Errorf("relayer %s isn't enough XDC fee : balance %d , fee : %d ", relayer.Hex(), balance.Uint64(), fee.Uint64())
}
@ -248,7 +248,7 @@ func CheckSubRelayerFee(relayer common.Address, fee *big.Int, statedb *state.Sta
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
balance = statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit).Big()
balance = statedb.GetState(common.RelayerRegistrationSMC, locHashDeposit).Big()
}
log.Debug("CheckSubRelayerFee settle balance: SubRelayerFee ", "relayer", relayer.String(), "balance", balance, "fee", fee)
if balance.Cmp(fee) < 0 {
@ -296,6 +296,6 @@ func SetSubRelayerFee(relayer common.Address, balance *big.Int, fee *big.Int, st
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
locBigDeposit := new(big.Int).SetUint64(uint64(0)).Add(locBig, RelayerStructMappingSlot["_deposit"])
locHashDeposit := common.BigToHash(locBigDeposit)
statedb.SetState(common.HexToAddress(common.RelayerRegistrationSMC), locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.HexToAddress(common.RelayerRegistrationSMC), fee)
statedb.SetState(common.RelayerRegistrationSMC, locHashDeposit, common.BigToHash(balance))
statedb.SubBalance(common.RelayerRegistrationSMC, fee)
}

View file

@ -36,10 +36,10 @@ var DevnetConstant = constant{
xdcxListingSMC: HexToAddress("0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53"),
xdcxListingSMCTestNet: HexToAddress("0x14B2Bf043b9c31827A472CE4F94294fE9a6277e0"),
relayerRegistrationSMC: "0x16c63b79f9C8784168103C0b74E6A59EC2de4a02",
relayerRegistrationSMCTestnet: "0xA1996F69f47ba14Cb7f661010A7C31974277958c",
lendingRegistrationSMC: "0x7d761afd7ff65a79e4173897594a194e3c506e57",
lendingRegistrationSMCTestnet: "0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8",
relayerRegistrationSMC: HexToAddress("0x16c63b79f9C8784168103C0b74E6A59EC2de4a02"),
relayerRegistrationSMCTestnet: HexToAddress("0xA1996F69f47ba14Cb7f661010A7C31974277958c"),
lendingRegistrationSMC: HexToAddress("0x7d761afd7ff65a79e4173897594a194e3c506e57"),
lendingRegistrationSMCTestnet: HexToAddress("0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8"),
ignoreSignerCheckBlockArray: map[uint64]struct{}{
1032300: {},

View file

@ -97,10 +97,10 @@ type constant struct {
xdcxListingSMC Address
xdcxListingSMCTestNet Address
relayerRegistrationSMC string
relayerRegistrationSMCTestnet string
lendingRegistrationSMC string
lendingRegistrationSMCTestnet string
relayerRegistrationSMC Address
relayerRegistrationSMCTestnet Address
lendingRegistrationSMC Address
lendingRegistrationSMCTestnet Address
ignoreSignerCheckBlockArray map[uint64]struct{}

View file

@ -36,10 +36,10 @@ var localConstant = constant{
xdcxListingSMC: HexToAddress("0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53"),
xdcxListingSMCTestNet: HexToAddress("0x14B2Bf043b9c31827A472CE4F94294fE9a6277e0"),
relayerRegistrationSMC: "0x16c63b79f9C8784168103C0b74E6A59EC2de4a02",
relayerRegistrationSMCTestnet: "0xA1996F69f47ba14Cb7f661010A7C31974277958c",
lendingRegistrationSMC: "0x7d761afd7ff65a79e4173897594a194e3c506e57",
lendingRegistrationSMCTestnet: "0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8",
relayerRegistrationSMC: HexToAddress("0x16c63b79f9C8784168103C0b74E6A59EC2de4a02"),
relayerRegistrationSMCTestnet: HexToAddress("0xA1996F69f47ba14Cb7f661010A7C31974277958c"),
lendingRegistrationSMC: HexToAddress("0x7d761afd7ff65a79e4173897594a194e3c506e57"),
lendingRegistrationSMCTestnet: HexToAddress("0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8"),
ignoreSignerCheckBlockArray: map[uint64]struct{}{
1032300: {},

View file

@ -36,10 +36,10 @@ var MaintnetConstant = constant{
xdcxListingSMC: HexToAddress("0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53"),
xdcxListingSMCTestNet: HexToAddress("0x14B2Bf043b9c31827A472CE4F94294fE9a6277e0"),
relayerRegistrationSMC: "0x16c63b79f9C8784168103C0b74E6A59EC2de4a02",
relayerRegistrationSMCTestnet: "0xA1996F69f47ba14Cb7f661010A7C31974277958c",
lendingRegistrationSMC: "0x7d761afd7ff65a79e4173897594a194e3c506e57",
lendingRegistrationSMCTestnet: "0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8",
relayerRegistrationSMC: HexToAddress("0x16c63b79f9C8784168103C0b74E6A59EC2de4a02"),
relayerRegistrationSMCTestnet: HexToAddress("0xA1996F69f47ba14Cb7f661010A7C31974277958c"),
lendingRegistrationSMC: HexToAddress("0x7d761afd7ff65a79e4173897594a194e3c506e57"),
lendingRegistrationSMCTestnet: HexToAddress("0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8"),
ignoreSignerCheckBlockArray: map[uint64]struct{}{
1032300: {},

View file

@ -36,10 +36,10 @@ var TestnetConstant = constant{
xdcxListingSMC: HexToAddress("0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53"),
xdcxListingSMCTestNet: HexToAddress("0x14B2Bf043b9c31827A472CE4F94294fE9a6277e0"),
relayerRegistrationSMC: "0x16c63b79f9C8784168103C0b74E6A59EC2de4a02",
relayerRegistrationSMCTestnet: "0xA1996F69f47ba14Cb7f661010A7C31974277958c",
lendingRegistrationSMC: "0x7d761afd7ff65a79e4173897594a194e3c506e57",
lendingRegistrationSMCTestnet: "0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8",
relayerRegistrationSMC: HexToAddress("0x16c63b79f9C8784168103C0b74E6A59EC2de4a02"),
relayerRegistrationSMCTestnet: HexToAddress("0xA1996F69f47ba14Cb7f661010A7C31974277958c"),
lendingRegistrationSMC: HexToAddress("0x7d761afd7ff65a79e4173897594a194e3c506e57"),
lendingRegistrationSMCTestnet: HexToAddress("0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8"),
ignoreSignerCheckBlockArray: map[uint64]struct{}{
1032300: {},

View file

@ -97,10 +97,10 @@ type constant struct {
xdcxListingSMC Address
xdcxListingSMCTestNet Address
relayerRegistrationSMC string
relayerRegistrationSMCTestnet string
lendingRegistrationSMC string
lendingRegistrationSMCTestnet string
relayerRegistrationSMC Address
relayerRegistrationSMCTestnet Address
lendingRegistrationSMC Address
lendingRegistrationSMCTestnet Address
ignoreSignerCheckBlockArray map[uint64]struct{}

View file

@ -97,10 +97,10 @@ type constant struct {
xdcxListingSMC Address
xdcxListingSMCTestNet Address
relayerRegistrationSMC string
relayerRegistrationSMCTestnet string
lendingRegistrationSMC string
lendingRegistrationSMCTestnet string
relayerRegistrationSMC Address
relayerRegistrationSMCTestnet Address
lendingRegistrationSMC Address
lendingRegistrationSMCTestnet Address
ignoreSignerCheckBlockArray map[uint64]struct{}

View file

@ -97,10 +97,10 @@ type constant struct {
xdcxListingSMC Address
xdcxListingSMCTestNet Address
relayerRegistrationSMC string
relayerRegistrationSMCTestnet string
lendingRegistrationSMC string
lendingRegistrationSMCTestnet string
relayerRegistrationSMC Address
relayerRegistrationSMCTestnet Address
lendingRegistrationSMC Address
lendingRegistrationSMCTestnet Address
ignoreSignerCheckBlockArray map[uint64]struct{}

View file

@ -57,17 +57,17 @@ var (
// MaxHash represents the maximum possible hash value.
MaxHash = HexToHash("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
BlockSignersBinary = Address{19: 0x89} // xdc0000000000000000000000000000000000000089
MasternodeVotingSMCBinary = Address{19: 0x88} // xdc0000000000000000000000000000000000000088
RandomizeSMCBinary = Address{19: 0x90} // xdc0000000000000000000000000000000000000090
FoudationAddrBinary = Address{19: 0x68} // xdc0000000000000000000000000000000000000068
TeamAddrBinary = Address{19: 0x99} // xdc0000000000000000000000000000000000000099
XDCXAddrBinary = Address{19: 0x91} // xdc0000000000000000000000000000000000000091
TradingStateAddrBinary = Address{19: 0x92} // xdc0000000000000000000000000000000000000092
XDCXLendingAddressBinary = Address{19: 0x93} // xdc0000000000000000000000000000000000000093
XDCXLendingFinalizedTradeAddressBinary = Address{19: 0x94} // xdc0000000000000000000000000000000000000094
XDCNativeAddressBinary = Address{19: 0x01} // xdc0000000000000000000000000000000000000001
LendingLockAddressBinary = Address{19: 0x11} // xdc0000000000000000000000000000000000000011
BlockSignersBinary = HexToAddress("0x0000000000000000000000000000000000000089")
MasternodeVotingSMCBinary = HexToAddress("0x0000000000000000000000000000000000000088")
RandomizeSMCBinary = HexToAddress("0x0000000000000000000000000000000000000090")
FoudationAddrBinary = HexToAddress("0x0000000000000000000000000000000000000068")
TeamAddrBinary = HexToAddress("0x0000000000000000000000000000000000000099")
XDCXAddrBinary = HexToAddress("0x0000000000000000000000000000000000000091")
TradingStateAddrBinary = HexToAddress("0x0000000000000000000000000000000000000092")
XDCXLendingAddressBinary = HexToAddress("0x0000000000000000000000000000000000000093")
XDCXLendingFinalizedTradeAddressBinary = HexToAddress("0x0000000000000000000000000000000000000094")
XDCNativeAddressBinary = HexToAddress("0x0000000000000000000000000000000000000001")
LendingLockAddressBinary = HexToAddress("0x0000000000000000000000000000000000000011")
)
var (

View file

@ -262,13 +262,13 @@ func (api *API) NetworkInformation() NetworkInformation {
info.NetworkId = api.chain.Config().ChainId
info.XDCValidatorAddress = common.MasternodeVotingSMCBinary
if common.IsTestnet {
info.LendingAddress = common.HexToAddress(common.LendingRegistrationSMCTestnet)
info.RelayerRegistrationAddress = common.HexToAddress(common.RelayerRegistrationSMCTestnet)
info.LendingAddress = common.LendingRegistrationSMCTestnet
info.RelayerRegistrationAddress = common.RelayerRegistrationSMCTestnet
info.XDCXListingAddress = common.XDCXListingSMCTestNet
info.XDCZAddress = common.TRC21IssuerSMCTestNet
} else {
info.LendingAddress = common.HexToAddress(common.LendingRegistrationSMC)
info.RelayerRegistrationAddress = common.HexToAddress(common.RelayerRegistrationSMC)
info.LendingAddress = common.LendingRegistrationSMC
info.RelayerRegistrationAddress = common.RelayerRegistrationSMC
info.XDCXListingAddress = common.XDCXListingSMC
info.XDCZAddress = common.TRC21IssuerSMC
}