From b9066d9939f6f0e2de7965ea3a4c87d9ab1de86f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 4 Jul 2024 04:15:28 +0800 Subject: [PATCH] 1 --- bin/backtask/config/bc_currency.json | 6 +++++- server/backtask/mtb/mtb.auto_gen.go | 10 ++++++++++ server/backtask/proto/mt.proto | 1 + server/backtask/service/bc_currency.go | 15 +++++++++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bin/backtask/config/bc_currency.json b/bin/backtask/config/bc_currency.json index 7c229924..0f1ac8ea 100644 --- a/bin/backtask/config/bc_currency.json +++ b/bin/backtask/config/bc_currency.json @@ -2,21 +2,25 @@ { "name": "Ethereum", "contract_address": "0xe9E96d1aad82562b7588F03f49aD34186f996478", + "decimals": 18, "current_price": 3371.1 }, { "name": "USDC", "contract_address": "0x3b2d8a1931736fc321c24864bceee981b11c3c57", + "decimals": 6, "current_price": 0.999334 }, { "name": "Immutable", "contract_address": "0x1ccca691501174b4a623ceda58cc8f1a76dc3439", + "decimals": 18, "current_price": 1.54 }, { "name": "NATIVE", "contract_address": "0xFd42bfb03212dA7e1A4608a44d7658641D99CF34", - "current_price": 1.54 + "decimals": 18, + "current_price": 3371.1 } ] diff --git a/server/backtask/mtb/mtb.auto_gen.go b/server/backtask/mtb/mtb.auto_gen.go index 51bf145a..e20a8de9 100644 --- a/server/backtask/mtb/mtb.auto_gen.go +++ b/server/backtask/mtb/mtb.auto_gen.go @@ -99,6 +99,7 @@ type BcCurrency struct { name string contract_address string current_price float64 + decimals int32 _flags1_ uint64 _flags2_ uint64 @@ -492,6 +493,14 @@ func (this *BcCurrency) HasCurrentPrice() bool { return (this._flags1_ & (uint64(1) << 4)) > 0 } +func (this *BcCurrency) GetDecimals() int32 { + return this.decimals +} + +func (this *BcCurrency) HasDecimals() bool { + return (this._flags1_ & (uint64(1) << 5)) > 0 +} + func (this *RankSeason) GetId() int32 { return this.id } @@ -628,6 +637,7 @@ func (this *BcCurrency) LoadFromKv(kv map[string]interface{}) { f5.ReadMetaTableField(&this.name, "name", &this._flags1_, 1, kv) f5.ReadMetaTableField(&this.contract_address, "contract_address", &this._flags1_, 3, kv) f5.ReadMetaTableField(&this.current_price, "current_price", &this._flags1_, 4, kv) + f5.ReadMetaTableField(&this.decimals, "decimals", &this._flags1_, 5, kv) } func (this *RankSeason) LoadFromKv(kv map[string]interface{}) { diff --git a/server/backtask/proto/mt.proto b/server/backtask/proto/mt.proto index bdb87948..b1a2774c 100644 --- a/server/backtask/proto/mt.proto +++ b/server/backtask/proto/mt.proto @@ -82,6 +82,7 @@ message BcCurrency optional string name = 1; optional string contract_address = 3; optional double current_price = 4; + optional int32 decimals = 5; } message RankSeason diff --git a/server/backtask/service/bc_currency.go b/server/backtask/service/bc_currency.go index 3fa80a6d..1c6cd34c 100644 --- a/server/backtask/service/bc_currency.go +++ b/server/backtask/service/bc_currency.go @@ -53,11 +53,22 @@ func (this *bcCurrency) ExchangeUSD(amount string, itemType string, contractAddr if !ok { return 0, "0" } - bnDecimal := big.NewInt(DECIMALS) + //bnDecimal := big.NewInt(DECIMALS) + bnDecimalEx := big.NewInt(100000000000000000) + { + usdcMeta := mt.Table.BcCurrency.GetByName(jccommon.BC_CURRENCY_NAME_USDC) + if usdcMeta != nil && strings.ToLower(usdcMeta.GetContractAddress()) == contractAddress { + bnDecimalEx = big.NewInt(100000) + } + } + //if itemType == jccommon.BC_CURRENCY_NAME_USDC { + //bnDecimalEx = big.NewInt(100000) + //} bnPrice := big.NewInt(0) bnRate := big.NewInt(rate) bnPrice.Mul(bnAmount, bnRate) - bnPrice.Div(bnPrice, bnDecimal) + //bnPrice.Mul(bnPrice, bnDecimal) + bnPrice.Div(bnPrice, bnDecimalEx) return rate, bnPrice.String() }