diff --git a/ride/boosting.ride b/ride/boosting.ride index d9e6921b..7c78d315 100644 --- a/ride/boosting.ride +++ b/ride/boosting.ride @@ -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() @@ -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 { @@ -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], []) @@ -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) @@ -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() @@ -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() } @@ -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) @@ -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() { diff --git a/ride/gwx_reward.ride b/ride/gwx_reward.ride index d7ee6175..10ea787a 100644 --- a/ride/gwx_reward.ride +++ b/ride/gwx_reward.ride @@ -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 @@ -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) @@ -324,6 +329,7 @@ func tradeRewardInternal( rewards: List[Int], currentIter: Int ) = { + strict suspensionCheck = throwIfSuspended() if (currentIter == userAddresses.size()) then ([]) else strict checks = [ @@ -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], []) @@ -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() @@ -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] @@ -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() @@ -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() {