private BigInteger CalculateEntryVotingPower(VotingLogEntry entry, Timestamp currentTime) { BigInteger baseMultiplier = 100; BigInteger votingMultiplier = baseMultiplier; var diff = (currentTime - entry.timestamp) / 86400; var votingBonus = diff < MaxVotingPowerBonus ? diff : MaxVotingPowerBonus; votingMultiplier += DailyVotingBonus * votingBonus; var votingPower = (entry.amount * votingMultiplier) / 100; return(votingPower); }
public void Stake(Address from, BigInteger stakeAmount) { Runtime.Expect(stakeAmount >= MinimumValidStake, "invalid amount"); Runtime.Expect(Runtime.IsWitness(from), "witness failed"); var balance = Runtime.GetBalance(DomainSettings.StakingTokenSymbol, from); if (stakeAmount > balance) { var diff = stakeAmount - balance; throw new BalanceException("SOUL", from, diff); balance = stakeAmount; // debug mode only, otherwise a exception will prevent it from reaching here } Runtime.Expect(balance >= stakeAmount, $"balance: {balance} stake: {stakeAmount} not enough balance to stake at " + from); Runtime.TransferTokens(DomainSettings.StakingTokenSymbol, from, this.Address, stakeAmount); EnergyStake stake; if (_stakeMap.ContainsKey <Address>(from)) { stake = _stakeMap.Get <Address, EnergyStake>(from); } else { stake = new EnergyStake() { stakeTime = new Timestamp(0), stakeAmount = 0, }; } stake.stakeTime = Runtime.Time; stake.stakeAmount += stakeAmount; _stakeMap.Set <Address, EnergyStake>(from, stake); Runtime.AddMember(DomainSettings.StakersOrganizationName, this.Address, from); var claimList = _claimMap.Get <Address, StorageList>(from); var claimEntry = new EnergyClaim() { stakeAmount = stakeAmount, claimDate = this.Runtime.Time, isNew = true, }; claimList.Add(claimEntry); var logEntry = new VotingLogEntry() { timestamp = this.Runtime.Time, amount = stakeAmount }; var votingLogbook = _voteHistory.Get <Address, StorageList>(from); votingLogbook.Add(logEntry); // masters membership var masterAccountThreshold = GetMasterThreshold(); if (stake.stakeAmount >= masterAccountThreshold && !IsMaster(from)) { var nextClaim = GetMasterClaimDate(2); Runtime.AddMember(DomainSettings.MastersOrganizationName, this.Address, from); _masterClaims.Set <Address, Timestamp>(from, nextClaim); _masterAgeMap.Set <Address, Timestamp>(from, Runtime.Time); } }