Skip to content

Commit

Permalink
pool resumption
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Apr 8, 2024
1 parent 0e307d2 commit f48b10c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ride/factory_v2.ride
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func activateNewPool(poolAddress: String, amountAssetStr: String, priceAssetStr:
# return:
@Callable(i)
func managePool(poolAddress: String, newStatus: Int) = {
strict checkCaller = i.mustManager()
strict checkCaller = i.mustAdmin()

let poolConfig = getPoolConfig(poolAddress)

Expand Down
62 changes: 62 additions & 0 deletions ride/voting_emission.ride
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ let poolWeightMult = 100_000_000
let maxDepthDefault = 10
let finalizationStageTotal = 0
let finalizationStageShares = 1
let resumptionFeeDefault = 5000_00000000

let keyEpochLength = ["%s", "epochLength"].makeString(separator)
let keyEpochLengthNew = ["%s%s", "epochLength__new"].makeString(separator)
func keyEpochLengthByEpoch(epoch: Int) = ["%s%d", "epochLength", epoch.toString()].makeString(separator)

let keyCurrentEpoch = ["%s", "currentEpoch"].makeString(separator)
let keyMaxDepth = ["%s", "maxDepth"].makeString(separator)
let keyResumptionFee = ["%s", "resumptionFee"].makeString(separator)
let keyVotingEmissionCandidateContract = ["%s", "votingEmissionCandidateContract"].makeString(separator)
let keyVotingEmissionRateContract = ["%s", "votingEmissionRateContract"].makeString(separator)
let keyFactoryContract = ["%s", "factoryContract"].makeString(separator)
Expand Down Expand Up @@ -97,6 +99,17 @@ func keyFactoryCfg() = "%s__factoryConfig"
func readFactoryCfgOrFail(factory: Address) = factory.getStrOrFail(keyFactoryCfg()).split(separator)
func getGwxRewardAddressOrFail(factoryCfg: List[String]) = factoryCfg[IdxFactoryCfgGwxRewardDapp].addressFromStringValue()

# returns (poolAddress: Address, lpAssetId: ByteVector)
func getPoolInfo(amountAssetId: String, priceAssetId: String) = {
let poolInfoOption = factoryContract.invoke(
"poolInfoREADONLY",
[amountAssetId, priceAssetId],
[]
).as[(Address, ByteVector)]

poolInfoOption
}

func getLpAssetByPoolAssets(amountAssetId: String, priceAssetId: String) = {
func keyMappingsBaseAsset2internalId(baseAssetStr: String) = {
"%s%s%s__mappings__baseAsset2internalId__" + baseAssetStr
Expand Down Expand Up @@ -789,6 +802,55 @@ func deletePool(amountAssetId: String, priceAssetId: String) = {
] ++ actions
}

# statuses are returned within 3 days
@Callable(i)
func resume(amountAssetId: String, priceAssetId: String) = {
let lpAssetId = getLpAssetByPoolAssets(amountAssetId, priceAssetId)
let balanceIsOk = factoryContract.invoke("checkBalance", [lpAssetId], []).exactAs[Boolean]

let payment = i.payments[0]

let assetsStoreContract = this.getStringValue(
keyAssetsStoreContract
).addressFromStringValue()

let kBoostingConfig = "%s__config"
let idxCfgAssetId = 1
let boostingContract = this.getStrOrFail(keyBoostingContract).addressFromStringValue()
let wxAssetId = boostingContract.getStringValue(kBoostingConfig).split(separator)[idxCfgAssetId].fromBase58String()

let amountAssetVerified = assetsStoreContract.invoke("isVerifiedREADONLY", [amountAssetId], []).exactAs[Boolean]
let priceAssetVerified = assetsStoreContract.invoke("isVerifiedREADONLY", [priceAssetId], []).exactAs[Boolean]

let resumptionFee = this.getInteger(
keyResumptionFee
).valueOrElse(resumptionFeeDefault)

strict checks = [
balanceIsOk || throwErr("insufficient balances"),
i.payments.size() == 1 || throwErr("1 payment is required"),
payment.assetId == wxAssetId || throwErr("invalid payment asset id"),
payment.amount == resumptionFee || throwErr("invalid payment amount"),
amountAssetVerified && priceAssetVerified || throwErr("both assets should be verified")
]

# strict setWxEmissionInv = factoryContract.invoke("setWxEmissionPoolLabel", [amountAssetId, priceAssetId], [])

# let poolAddress = getPoolInfo(
# amountAssetId,
# priceAssetId
# ).valueOrErrorMessage(wrapErr("invalid assets"))._1
# let newStatus = 1
# strict setPoolStatusInv = factoryContract.invoke("managePool", [poolAddress.toString(), newStatus], [])

let pool = (amountAssetId, priceAssetId)
let inListActions = [
BooleanEntry(pool.keyInList(), true)
] ++ poolsListName.insertNodeActions(pool.poolToString())

(inListActions, unit)
}

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

0 comments on commit f48b10c

Please sign in to comment.