Skip to content

Commit

Permalink
suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Aug 31, 2023
1 parent c06125a commit 141c8d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ride/boosting.ride
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ let mathContract = cfgArray[IdxCfgMathContract].addressFromString().valueOrError
let blocksInPeriod = cfgArray[IdxCfgBlocksInPeriod].parseInt().valueOrErrorMessage(wrapErr("invalid blocks in period"))
let lockStepBlocks = cfgArray[IdxCfgLockStepBlocks].parseInt().valueOrErrorMessage(wrapErr("invalid lock step blocks"))

let keySuspension = "%s__suspension"
let isSuspended = this.getBoolean(keySuspension).valueOrElse(false)
func throwIfSuspended() = !isSuspended || throwErr("suspended")

func getManagerVaultAddressOrThis() = {
match keyManagerVaultAddress().getString() {
case s:String => s.addressFromStringValue()
Expand Down Expand Up @@ -640,6 +644,7 @@ func getWxWithdrawable(userAddress: Address, txIdOption: ByteVector|Unit) = {

@Callable(i)
func lockRef(duration: Int, referrerAddress: String, signature: ByteVector) = {
strict suspensionCheck = throwIfSuspended()
let (lockActionsResult, gWxAmountStart) = i.lockActions(duration)
let referralAddress = i.caller.toString()
strict refInv = if (referrerAddress == "" || signature == base58'') then unit else {
Expand All @@ -652,6 +657,7 @@ func lockRef(duration: Int, referrerAddress: String, signature: ByteVector) = {

@Callable(i)
func lock(duration: Int) = {
strict suspensionCheck = throwIfSuspended()
let (lockActionsResult, gWxAmountStart) = i.lockActions(duration)
strict updateRefActivity = mathContract.invoke("updateReferralActivity", [i.caller.toString(), gWxAmountStart], [])

Expand All @@ -660,6 +666,7 @@ func lock(duration: Int) = {

@Callable(i)
func claimWxBoost(lpAssetIdStr: String, userAddressStr: String) = {
strict suspensionCheck = throwIfSuspended()
if (stakingContract != i.caller) then throwErr("permissions denied") else
let (userBoostAvailable, dataState, debug) = internalClaimWxBoost(lpAssetIdStr, userAddressStr, false)

Expand All @@ -674,6 +681,7 @@ func claimWxBoostREADONLY(lpAssetIdStr: String, userAddressStr: String) = {

@Callable(i)
func unlock(txIdStr: String) = {
strict suspensionCheck = throwIfSuspended()
let userAddress = i.caller
let userAddressStr = userAddress.toString()
let txIdOption = if (txIdStr == "") then unit else txIdStr.fromBase58String()
Expand Down Expand Up @@ -770,6 +778,7 @@ func getGwxTotalREADONLY() = {
# call this function when wxEmissionRate or boostCoeff changes
@Callable(i)
func onBoostEmissionUpdate() = {
strict suspensionCheck = throwIfSuspended()
strict checkCaller = i.caller == emissionContract || i.mustManager()
refreshBoostEmissionIntegral()
}
Expand All @@ -786,6 +795,7 @@ func onBoostEmissionUpdate() = {
# ╰ edge = false (falling)
@Callable(i)
func onStakedVoteUpdate(lpAssetIdStr: String, userAddressStr: String, edge: Boolean) = {
strict suspensionCheck = throwIfSuspended()
strict checkCaller = i.caller == stakingContract || i.mustManager()
let actions = lpAssetIdStr.refreshVoteStakedIntegral(userAddressStr, edge)

Expand All @@ -812,6 +822,15 @@ func getUserVoteStakedIntegralREADONLY(lpAssetIdStr: String, userAddressStr: Str
([], lpAssetIdStr.getUserVoteStakedIntegral(userAddressStr))
}

@Callable(i)
func suspend(v: Boolean) = {
strict checkCaller = i.mustManager()

([
BooleanEntry(keySuspension, v)
], v)
}

@Verifier(tx)
func verify() = {
let targetPublicKey = match managerPublicKeyOrUnit() {
Expand Down
20 changes: 20 additions & 0 deletions ride/gwx_reward.ride
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func boostingContractOrFail() = {
# KEYS
# ***********************

let keySuspension = "%s__suspension"
let isSuspended = this.getBoolean(keySuspension).valueOrElse(false)
func throwIfSuspended() = !isSuspended || throwErr("suspended")

func keyGwxRewardEmissionStartHeight() = "%s%s__gwxRewardEmissionPart__startHeight"

# boosting contract state key, increments every lock() of unique user
Expand Down Expand Up @@ -308,6 +312,7 @@ func commonClaimReward(userAddressStr: String) = {

@Callable(i)
func refreshUserReward(userAddressBytes: ByteVector, userNum: Int) = {
strict suspensionCheck = throwIfSuspended()
strict checkCaller = i.caller == boostingContractOrFail() || throwErr("permission denied")

let (actions, reward) = _refreshUserReward(Address(userAddressBytes), userNum)
Expand All @@ -324,6 +329,7 @@ func tradeRewardInternal(
rewards: List[Int],
currentIter: Int
) = {
strict suspensionCheck = throwIfSuspended()
if (currentIter == userAddresses.size()) then ([]) else

strict checks = [
Expand Down Expand Up @@ -357,6 +363,7 @@ func tradeRewardInternal(

@Callable(i)
func updateReferralActivity(userAddress: String, gWxAmountStart: Int) = {
strict suspensionCheck = throwIfSuspended()
let referrer = referralsContractAddressOrFail.getString(userAddress.keyReferrer())
strict activeReferralInv = if (referrer == unit) then unit else {
referralsContractAddressOrFail.invoke("updateReferralActivity", [referralProgramName, userAddress, gWxAmountStart >= referralMinGWxAmount], [])
Expand All @@ -374,6 +381,7 @@ func processPendingPeriodsAndUsers() = {
# called by user
@Callable(i)
func claimReward() = {
strict suspensionCheck = throwIfSuspended()
let cfgArray = readConfigArrayOrFail()
let userAddress = i.caller
let userAddressStr = userAddress.toString()
Expand Down Expand Up @@ -417,12 +425,14 @@ func claimRewardREADONLY(address: String) = {
# save starting height of reward from emission 5%
@Callable(i)
func onEmissionForGwxStart() = {
strict suspensionCheck = throwIfSuspended()
if (i.caller != factoryContract) then throw("permissions denied") else
[IntegerEntry(keyGwxRewardEmissionStartHeight(), height)]
}

@Callable(i)
func tradeReward(userAddresses: List[String], rewards: List[Int]) = {
strict suspensionCheck = throwIfSuspended()
let argsComparison = userAddresses.size() == rewards.size()
let maxRecipients = keyMaxRecipients().getInteger().valueOrElse(0)
let payment = i.payments[0]
Expand Down Expand Up @@ -451,6 +461,7 @@ func tradeReward(userAddresses: List[String], rewards: List[Int]) = {

@Callable(i)
func claimTradingReward() = {
strict suspensionCheck = throwIfSuspended()
let userAddress = i.caller
let userAddressString = userAddress.toString()
let reward = userAddressString.getTradingReward()
Expand All @@ -467,6 +478,15 @@ func claimTradingRewardREADONLY(userAddress: String) = {
(nil, userAddress.getTradingReward())
}

@Callable(i)
func suspend(v: Boolean) = {
strict checkCaller = i.mustManager()

([
BooleanEntry(keySuspension, v)
], v)
}

@Verifier(tx)
func verify() = {
let targetPublicKey = match managerPublicKeyOrUnit() {
Expand Down

0 comments on commit 141c8d2

Please sign in to comment.