diff --git a/server/light_backtask/service/vip.go b/server/light_backtask/service/vip.go index 69350092..5efc8000 100644 --- a/server/light_backtask/service/vip.go +++ b/server/light_backtask/service/vip.go @@ -6,6 +6,7 @@ import ( "sync" "strings" "main/constant" + "math/big" ) type vip struct { @@ -84,6 +85,15 @@ func (this *vip) AddEx(accountAddress string, val string, idx int64, valField st return true } +/* +Deposit amount his_amount 衰减,最后的存覆盖之前的 +Withdraw 所有 + +按时间排序处理事件的先后顺序 + +通过Vester.sol的remainingEsToken方法获取, 如果要本地计算的话, 那就取每次Deposit事件的时间和amount, 加上先前的转换的余额, 再按total * (now - deposit_time) / (365 * 24 * 2600) +*/ + func (this *vip) RecalcEsCecConvert(accountAddress string) error { accountAddress = strings.ToLower(accountAddress) err , ds := f5.GetGoStyleDb().NewOrmSelect( @@ -124,5 +134,21 @@ func (this *vip) RecalcEsCecConvert(accountAddress string) error { q5.Sort(matchDeposits, func (a *vesterDepositWithdrawPo, b *vesterDepositWithdrawPo) bool { return a.chainTimestamp < b.chainTimestamp }) + var lastDeposit *vesterDepositWithdrawPo + nowTime := q5.ToInt32(f5.GetApp().GetRealSeconds()) + bnTotal := new(big.Int) + for _, val := range matchDeposits { + if lastDeposit != nil { + if nowTime > lastDeposit.chainTimestamp { + bnPassTime := new(big.Int).SetInt64(int64(nowTime - lastDeposit.chainTimestamp)) + bnTotalTime := new(big.Int).SetInt64(int64(365 * 24 * 2600)) + bnRate := bnPassTime.Div(bnPassTime, bnTotalTime) + bnTotal.Mul(bnTotal, bnRate) + } + } + bnAmount, _ := new(big.Int).SetString(val.depositAmount, 10) + bnTotal = bnAmount.Add(bnAmount, bnTotal) + lastDeposit = val + } return nil } diff --git a/server/light_backtask/task/vester.go b/server/light_backtask/task/vester.go index 0afc3a68..35954b2f 100644 --- a/server/light_backtask/task/vester.go +++ b/server/light_backtask/task/vester.go @@ -11,14 +11,6 @@ import ( "strings" ) -/* -Deposit amount his_amount 衰减,最后的存覆盖之前的 -Withdraw 所有 - -按时间排序处理事件的先后顺序 - -通过Vester.sol的remainingEsToken方法获取, 如果要本地计算的话, 那就取每次Deposit事件的时间和amount, 加上先前的转换的余额, 再按total * (now - deposit_time) / (365 * 24 * 2600) -*/ type vester struct { }