-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
335 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
package coindistribution | ||
|
||
import ( | ||
stdlibtime "time" | ||
|
||
"github.com/ice-blockchain/eskimo/users" | ||
"github.com/ice-blockchain/freezer/model" | ||
"github.com/ice-blockchain/wintr/time" | ||
) | ||
|
||
const ( | ||
miningSessionSoloEndedAtNetworkDelayAdjustment = 20 * stdlibtime.Second | ||
) | ||
|
||
func CalculateEthereumDistributionICEBalance( | ||
standardBalance float64, | ||
ethereumDistributionFrequencyMin, ethereumDistributionFrequencyMax stdlibtime.Duration, | ||
now, ethereumDistributionEndDate *time.Time, | ||
) float64 { | ||
delta := ethereumDistributionEndDate.Truncate(ethereumDistributionFrequencyMin).Sub(now.Truncate(ethereumDistributionFrequencyMin)) | ||
if delta <= ethereumDistributionFrequencyMax { | ||
return standardBalance | ||
} | ||
|
||
//TODO: should this be fractional or natural? | ||
return standardBalance / (float64(delta.Nanoseconds()) / float64(ethereumDistributionFrequencyMax.Nanoseconds())) | ||
} | ||
|
||
func IsEligibleForEthereumDistribution( | ||
minMiningStreaksRequired uint64, | ||
standardBalance, minEthereumDistributionICEBalanceRequired float64, | ||
ethAddress, country string, | ||
distributionDeniedCountries map[string]struct{}, | ||
now, miningSessionSoloStartedAt, miningSessionSoloEndedAt, ethereumDistributionEndDate *time.Time, | ||
kycState model.KYCState, | ||
miningSessionDuration, ethereumDistributionFrequencyMin, ethereumDistributionFrequencyMax stdlibtime.Duration) bool { | ||
var countryAllowed bool | ||
if _, countryDenied := distributionDeniedCountries[country]; country != "" && !countryDenied { | ||
countryAllowed = true | ||
} | ||
|
||
return countryAllowed && | ||
!miningSessionSoloEndedAt.IsNil() && miningSessionSoloEndedAt.After(now.Add(miningSessionSoloEndedAtNetworkDelayAdjustment)) && | ||
isEthereumAddressValid(ethAddress) && | ||
CalculateEthereumDistributionICEBalance(standardBalance, ethereumDistributionFrequencyMin, ethereumDistributionFrequencyMax, now, ethereumDistributionEndDate) >= minEthereumDistributionICEBalanceRequired && //nolint:lll // . | ||
model.CalculateMiningStreak(now, miningSessionSoloStartedAt, miningSessionSoloEndedAt, miningSessionDuration) >= minMiningStreaksRequired && | ||
kycState.KYCStepPassedCorrectly(users.QuizKYCStep) | ||
} | ||
|
||
func isEthereumAddressValid(ethAddress string) bool { | ||
if ethAddress == "" { | ||
return false | ||
} | ||
if ethAddress == "skip" { | ||
return true | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.