Skip to content

Commit

Permalink
pool swap disable
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Aug 17, 2023
1 parent da04606 commit aa5225d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ride/factory_v2.ride
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ func keyPoolOneTokenOperationsDisabled(assetsInternal: (Int, Int)) = {
func keyAllPoolsOneTokenOperationsDisabled() = {
["%s", "oneTokenOperationsDisabled"].makeString(SEP)
}


func keyPoolSwapDisabled(assetsInternal: (Int, Int)) = {
let (amountAssetInternal, priceAssetInternal) = assetsInternal
["%d%d%s", amountAssetInternal.toString(), priceAssetInternal.toString(), "swapDisabled"].makeString(SEP)
}
func keyAllPoolsSwapDisabled() = {
["%s", "swapDisabled"].makeString(SEP)
}

func keyMappingLpAssetToPoolAssets(lpAssetStr: String)
= "%s%s%s__" + lpAssetStr + "__mappings__lpAsset2Pool"
func keyMappingPoolAssetsToLpasset(internalAmountAssetIdStr: String, internalPriceAssetIdStr: String)
Expand Down Expand Up @@ -862,6 +872,16 @@ func isPoolOneTokenOperationsDisabledREADONLY(poolAddress: String) = {
([], allPoolsOneTokenOperationsDisabled || poolOneTokenOperationsDisabled)
}

@Callable(i)
func isPoolSwapDisabledREADONLY(poolAddress: String) = {
let poolConfig = poolAddress.getPoolConfig()
let assetsInternal = (poolConfig[idxIAmtAssetId].parseIntValue(), poolConfig[idxIPriceAssetId].parseIntValue())
let poolSwapDisabled = assetsInternal.keyPoolSwapDisabled().getBoolean().valueOrElse(false)
let allPoolsSwapDisabled = keyAllPoolsSwapDisabled().getBoolean().valueOrElse(false)

([], allPoolsSwapDisabled || poolSwapDisabled)
}

@Callable(i)
func getInFeeREADONLY(poolAddress: String) = {
let fee = intOrDefaultOrFallback(keyInFee(poolAddress), keyInFeeDefault(), 0)
Expand Down
9 changes: 9 additions & 0 deletions ride/lp.ride
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,16 @@ func calculateAmountOutForSwapAndSendTokens(cleanAmountIn: Int, isReverse: Boole
[],
[]
).exactAs[String]

let isPoolSwapDisabled = factoryContract.invoke(
"isPoolSwapDisabledREADONLY",
[this.toString()],
[]
).exactAs[Boolean]
let isSwapDisabled = isGlobalShutdown() || cfgPoolStatus == PoolShutdown || isPoolSwapDisabled

strict checks = [
!isSwapDisabled || i.isManager() || "swap operation is blocked by admin".throwErr(),
i.payments[0].value().amount >= cleanAmountIn || "Wrong amount".throwErr(),
i.caller == addressFromStringValue(swapContact) || "Permission denied".throwErr()
]
Expand Down
9 changes: 9 additions & 0 deletions ride/lp_stable.ride
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,16 @@ func calculateAmountOutForSwapAndSendTokens(cleanAmountIn: Int, isReverse: Boole
[],
[]
).exactAs[String]

let isPoolSwapDisabled = fca.invoke(
"isPoolSwapDisabledREADONLY",
[this.toString()],
[]
).exactAs[Boolean]
let isSwapDisabled = igs() || cfgPoolStatus == PoolShutdown || isPoolSwapDisabled

strict checks = [
!isSwapDisabled || i.isManager() || "swap operation is blocked by admin".throwErr(),
i.payments[0].value().amount >= cleanAmountIn || "Wrong amount".throwErr(),
i.caller == addressFromStringValue(swapContact) || "Permission denied".throwErr()
]
Expand Down
5 changes: 4 additions & 1 deletion ride/rest.ride
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ func poolStatsREADONLY(lpAsset: String) = {

let poolOneTokenOperationsDisabled = factoryDapp.invoke("isPoolOneTokenOperationsDisabledREADONLY", [poolAddress.toString()], []).exactAs[Boolean]
let poolOneTokenOperationsEnabled = !poolOneTokenOperationsDisabled

let poolSwapEnabled = !factoryDapp.invoke("isPoolSwapDisabledREADONLY", [poolAddress.toString()], []).exactAs[Boolean]
(
[],
makeString([
Expand All @@ -425,7 +427,8 @@ func poolStatsREADONLY(lpAsset: String) = {
poolWeight.toString(),
inFee.toString(),
outFee.toString(),
poolOneTokenOperationsEnabled.toString()
poolOneTokenOperationsEnabled.toString(),
poolSwapEnabled.toString()
],
SEP)
)
Expand Down

0 comments on commit aa5225d

Please sign in to comment.