1 | | - | # no script |
---|
| 1 | + | {-# STDLIB_VERSION 6 #-} |
---|
| 2 | + | {-# SCRIPT_TYPE ACCOUNT #-} |
---|
| 3 | + | {-# CONTENT_TYPE DAPP #-} |
---|
| 4 | + | func getStringOrFail (key) = valueOrErrorMessage(getString(key), (("mandatory this." + key) + " is not defined")) |
---|
| 5 | + | |
---|
| 6 | + | |
---|
| 7 | + | let SEP = "__" |
---|
| 8 | + | |
---|
| 9 | + | let BUFSCALE = toBigInt(1000000000000000000) |
---|
| 10 | + | |
---|
| 11 | + | let scale8 = 100000000 |
---|
| 12 | + | |
---|
| 13 | + | func throwErr (msg) = throw(makeString(["ido.ride:", msg], " ")) |
---|
| 14 | + | |
---|
| 15 | + | |
---|
| 16 | + | func asString (val) = match val { |
---|
| 17 | + | case valStr: String => |
---|
| 18 | + | valStr |
---|
| 19 | + | case _ => |
---|
| 20 | + | throw("fail to cast into String") |
---|
| 21 | + | } |
---|
| 22 | + | |
---|
| 23 | + | |
---|
| 24 | + | func convertPriceAssetIntoIdoAsset (priceAssetAmount,priceAssetMULT,price,priceMULT,idoAssetMULT) = { |
---|
| 25 | + | let bPriceAssetMULT = toBigInt(priceAssetMULT) |
---|
| 26 | + | let bIdoAssetMULT = toBigInt(idoAssetMULT) |
---|
| 27 | + | let bPriceAssetBUF = fraction(toBigInt(priceAssetAmount), BUFSCALE, bPriceAssetMULT) |
---|
| 28 | + | let bAmountAssetBUF = fraction(bPriceAssetBUF, toBigInt(priceMULT), toBigInt(price)) |
---|
| 29 | + | toInt(fraction(bAmountAssetBUF, toBigInt(idoAssetMULT), BUFSCALE)) |
---|
| 30 | + | } |
---|
| 31 | + | |
---|
| 32 | + | |
---|
| 33 | + | let IdxCfgIdoStart = 1 |
---|
| 34 | + | |
---|
| 35 | + | let IdxCfgIdoDuration = 2 |
---|
| 36 | + | |
---|
| 37 | + | let IdxCfgClaimStart = 3 |
---|
| 38 | + | |
---|
| 39 | + | let IdxCfgClaimDuration = 4 |
---|
| 40 | + | |
---|
| 41 | + | let IdxCfgPrice = 5 |
---|
| 42 | + | |
---|
| 43 | + | let IdxCfgPriceMult = 6 |
---|
| 44 | + | |
---|
| 45 | + | let IdxCfgIdoAssetId = 7 |
---|
| 46 | + | |
---|
| 47 | + | let IdxCfgIdoAssetMult = 8 |
---|
| 48 | + | |
---|
| 49 | + | let IdxCfgPriceAssetId = 9 |
---|
| 50 | + | |
---|
| 51 | + | let IdxCfgPriceAssetMult = 10 |
---|
| 52 | + | |
---|
| 53 | + | let IdxCfgMinInvestAmount = 11 |
---|
| 54 | + | |
---|
| 55 | + | func fromatConfigS (idoStart,idoDuration,claimStart,claimDuration,price,priceMult,idoAssetId58,idoAssetMult,priceAssetId58,priceAssetMult,minInvestAmount,totalIdoAssetToSell) = makeString(["%d%d%d%d%d%d%s%d%s%d%d%d", idoStart, idoDuration, claimStart, claimDuration, price, priceMult, idoAssetId58, idoAssetMult, priceAssetId58, priceAssetMult, minInvestAmount, totalIdoAssetToSell], SEP) |
---|
| 56 | + | |
---|
| 57 | + | |
---|
| 58 | + | func fromatConfig (idoStart,idoDuration,claimStart,claimDuration,price,priceMult,idoAssetId58,idoAssetMult,priceAssetId58,priceAssetMult,minInvestAmount,totalIdoAssetToSell) = fromatConfigS(toString(idoStart), toString(idoDuration), toString(claimStart), toString(claimDuration), toString(price), toString(priceMult), idoAssetId58, toString(idoAssetMult), priceAssetId58, toString(priceAssetMult), toString(minInvestAmount), toString(totalIdoAssetToSell)) |
---|
| 59 | + | |
---|
| 60 | + | |
---|
| 61 | + | let IdxInvTotalAmount = 1 |
---|
| 62 | + | |
---|
| 63 | + | let IdxInvRemainingAmount = 2 |
---|
| 64 | + | |
---|
| 65 | + | let IdxInvClaimedPriceAssetAmount = 3 |
---|
| 66 | + | |
---|
| 67 | + | let IdxInvClaimedIdoAssetAmount = 4 |
---|
| 68 | + | |
---|
| 69 | + | let IdxInvLastClaimedHeight = 5 |
---|
| 70 | + | |
---|
| 71 | + | func formatInvestorS (totalAmount,remainingAmount,claimedPriceAssetAmount,claimedIdoAssetAmount,lastClaimedHeight) = makeString(["%d%d%d%d%d", totalAmount, remainingAmount, claimedPriceAssetAmount, claimedIdoAssetAmount, lastClaimedHeight], SEP) |
---|
| 72 | + | |
---|
| 73 | + | |
---|
| 74 | + | func formatInvestor (totalAmount,remainingAmount,claimedPriceAssetAmount,claimedIdoAssetAmount,lastClaimedHeight) = formatInvestorS(toString(totalAmount), toString(remainingAmount), toString(claimedPriceAssetAmount), toString(claimedIdoAssetAmount), toString(lastClaimedHeight)) |
---|
| 75 | + | |
---|
| 76 | + | |
---|
| 77 | + | func formatHistoryRecord (priceAssetAmount,idoAssetAmount) = makeString(["%d%d%d%d", toString(height), toString(lastBlock.timestamp), toString(priceAssetAmount), toString(idoAssetAmount)], SEP) |
---|
| 78 | + | |
---|
| 79 | + | |
---|
| 80 | + | func keyConfig () = "%s__config" |
---|
| 81 | + | |
---|
| 82 | + | |
---|
| 83 | + | func keyInvestor (userAddress) = ("%s__" + userAddress) |
---|
| 84 | + | |
---|
| 85 | + | |
---|
| 86 | + | func keyTotals () = "%s__totals" |
---|
| 87 | + | |
---|
| 88 | + | |
---|
| 89 | + | func keyOperationHistoryRecord (type,userAddress,txId58) = makeString(["%s%s%s%s__history", type, userAddress, txId58], SEP) |
---|
| 90 | + | |
---|
| 91 | + | |
---|
| 92 | + | func keyUSDNClaimDisabled () = "%s__usdnClaimDisabled" |
---|
| 93 | + | |
---|
| 94 | + | |
---|
| 95 | + | func keyUSDNClaimEndHeight () = "%s__usdnClaimEndHeight" |
---|
| 96 | + | |
---|
| 97 | + | |
---|
| 98 | + | func keyPeriodLength () = makeString(["%s", "periodLength"], SEP) |
---|
| 99 | + | |
---|
| 100 | + | |
---|
| 101 | + | func keyCurrentPeriod () = makeString(["%s", "currentPeriod"], SEP) |
---|
| 102 | + | |
---|
| 103 | + | |
---|
| 104 | + | func keyPeriodStartHeight (periodNum) = makeString(["%s%s", "periodStartHeight", toString(periodNum)], SEP) |
---|
| 105 | + | |
---|
| 106 | + | |
---|
| 107 | + | func keyPeriodEndHeight (periodNum) = makeString(["%s%s", "periodEndHeight", toString(periodNum)], SEP) |
---|
| 108 | + | |
---|
| 109 | + | |
---|
| 110 | + | func keyUsdtPriceAssetAllowableRatio () = makeString(["%s", "usdtPriceAssetAllowableRatio"], SEP) |
---|
| 111 | + | |
---|
| 112 | + | |
---|
| 113 | + | func keyTotalPeriodAllowance (assetId) = makeString(["%s%s", "totalPeriodAllowance", assetId], SEP) |
---|
| 114 | + | |
---|
| 115 | + | |
---|
| 116 | + | func keyUserPeriodAllowance (assetId) = makeString(["%s%s", "userPeriodAllowance", assetId], SEP) |
---|
| 117 | + | |
---|
| 118 | + | |
---|
| 119 | + | func keyPeriodTotalAvailableToClaim (assetId,periodNum) = makeString(["%s%s%s", "periodTotalAvailableToClaim", assetId, toString(periodNum)], SEP) |
---|
| 120 | + | |
---|
| 121 | + | |
---|
| 122 | + | func keyPeriodUserAvailableToClaim (assetId,periodNum,userAddress) = makeString(["%s%s%s%s", "periodUserAvailableToClaim", assetId, toString(periodNum), userAddress], SEP) |
---|
| 123 | + | |
---|
| 124 | + | |
---|
| 125 | + | func keyUsdtPriceAssetStablePool () = makeString(["%s", "usdtPriceAssetStablePool"], SEP) |
---|
| 126 | + | |
---|
| 127 | + | |
---|
| 128 | + | func keyUsdtAssetId () = makeString(["%s", "usdtAssetId"], SEP) |
---|
| 129 | + | |
---|
| 130 | + | |
---|
| 131 | + | func keyPriceAssetBalance (address) = makeString(["%s%s", "priceAssetBalance", address], SEP) |
---|
| 132 | + | |
---|
| 133 | + | |
---|
| 134 | + | func keyInvestorRemainingAmount (address) = makeString(["%s%s", "investorRemainingAmount", address], SEP) |
---|
| 135 | + | |
---|
| 136 | + | |
---|
| 137 | + | func keyTotalRemainingAmount () = makeString(["%s", "totalRemainingAmount"], SEP) |
---|
| 138 | + | |
---|
| 139 | + | |
---|
| 140 | + | func keyManagerPublicKey () = "%s__managerPublicKey" |
---|
| 141 | + | |
---|
| 142 | + | |
---|
| 143 | + | func keyManagerVaultAddress () = "%s__managerVaultAddress" |
---|
| 144 | + | |
---|
| 145 | + | |
---|
| 146 | + | func readConfigArray () = split(getStringOrFail(keyConfig()), SEP) |
---|
| 147 | + | |
---|
| 148 | + | |
---|
| 149 | + | func readTotalsArrayOrDefaultByCustomKey (customKey) = split(valueOrElse(getString(customKey), formatInvestorS("0", "0", "0", "0", "0")), SEP) |
---|
| 150 | + | |
---|
| 151 | + | |
---|
| 152 | + | func readTotalsArrayOrDefault () = readTotalsArrayOrDefaultByCustomKey(keyTotals()) |
---|
| 153 | + | |
---|
| 154 | + | |
---|
| 155 | + | func readInvestorArrayOrDefault (userAddress) = readTotalsArrayOrDefaultByCustomKey(keyInvestor(userAddress)) |
---|
| 156 | + | |
---|
| 157 | + | |
---|
| 158 | + | func readInvestorArrayOrFail (userAddress) = split(getStringOrFail(keyInvestor(userAddress)), SEP) |
---|
| 159 | + | |
---|
| 160 | + | |
---|
| 161 | + | func getManagerAddressOrFail () = addressFromStringValue(getStringValue(keyManagerVaultAddress())) |
---|
| 162 | + | |
---|
| 163 | + | |
---|
| 164 | + | let IdxDiffTotalIncrement = 0 |
---|
| 165 | + | |
---|
| 166 | + | let IdxDiffRemainingPriceAmountIncrement = 1 |
---|
| 167 | + | |
---|
| 168 | + | let IdxDiffClaimedPriceAmountIncrement = 2 |
---|
| 169 | + | |
---|
| 170 | + | let IdxDiffClaimedIdoAssetAmountIncrement = 3 |
---|
| 171 | + | |
---|
| 172 | + | func TotalsEntry (key,origArray,incrementDiff,newLastClaimedHeight,priceAssetBalance) = { |
---|
| 173 | + | let totalAmount = parseIntValue(origArray[IdxInvTotalAmount]) |
---|
| 174 | + | let remainingAmount = parseIntValue(origArray[IdxInvRemainingAmount]) |
---|
| 175 | + | let claimedPriceAssetAmount = parseIntValue(origArray[IdxInvClaimedPriceAssetAmount]) |
---|
| 176 | + | let claimedIdoAssetAmount = parseIntValue(origArray[IdxInvClaimedIdoAssetAmount]) |
---|
| 177 | + | let lastClaimedHeight = parseIntValue(origArray[IdxInvLastClaimedHeight]) |
---|
| 178 | + | let newTotalAmount = (totalAmount + incrementDiff[IdxDiffTotalIncrement]) |
---|
| 179 | + | let newRemainingAmount = (remainingAmount + incrementDiff[IdxDiffRemainingPriceAmountIncrement]) |
---|
| 180 | + | let cfgArray = readConfigArray() |
---|
| 181 | + | let priceAssetId58 = cfgArray[IdxCfgPriceAssetId] |
---|
| 182 | + | let priceAssetDecimals = value(assetInfo(fromBase58String(priceAssetId58))).decimals |
---|
| 183 | + | let priceAssetBalancePriceAssetDecimals = fraction(priceAssetBalance, scale8, pow(10, 0, priceAssetDecimals, 0, 0, DOWN)) |
---|
| 184 | + | let newClaimedPriceAssetAmount = ((claimedPriceAssetAmount + incrementDiff[IdxDiffClaimedPriceAmountIncrement]) - priceAssetBalance) |
---|
| 185 | + | let newClaimedIdoAssetAmount = ((claimedIdoAssetAmount + incrementDiff[IdxDiffClaimedIdoAssetAmountIncrement]) + priceAssetBalancePriceAssetDecimals) |
---|
| 186 | + | let entries = if ((0 > newRemainingAmount)) |
---|
| 187 | + | then { |
---|
| 188 | + | let diff = ((newTotalAmount - newClaimedPriceAssetAmount) - newClaimedIdoAssetAmount) |
---|
| 189 | + | let newLogicRemainingAmount = if ((0 > diff)) |
---|
| 190 | + | then 0 |
---|
| 191 | + | else diff |
---|
| 192 | + | StringEntry(key, formatInvestor(newTotalAmount, newLogicRemainingAmount, newClaimedPriceAssetAmount, newClaimedIdoAssetAmount, newLastClaimedHeight)) |
---|
| 193 | + | } |
---|
| 194 | + | else StringEntry(key, formatInvestor(newTotalAmount, newRemainingAmount, newClaimedPriceAssetAmount, newClaimedIdoAssetAmount, newLastClaimedHeight)) |
---|
| 195 | + | entries |
---|
| 196 | + | } |
---|
| 197 | + | |
---|
| 198 | + | |
---|
| 199 | + | func InvestOperationHistoryEntry (userAddress,priceAssetAmount,idoAssetAmount,txId) = StringEntry(keyOperationHistoryRecord("invest", userAddress, toBase58String(txId)), formatHistoryRecord(priceAssetAmount, idoAssetAmount)) |
---|
| 200 | + | |
---|
| 201 | + | |
---|
| 202 | + | func ClaimOperationHistoryEntry (userAddress,priceAssetAmount,idoAssetAmount,txId) = StringEntry(keyOperationHistoryRecord("claim", userAddress, toBase58String(txId)), formatHistoryRecord(priceAssetAmount, idoAssetAmount)) |
---|
| 203 | + | |
---|
| 204 | + | |
---|
| 205 | + | func internalClaim (claimedAssetId58,userAddress,txId) = { |
---|
| 206 | + | let cfgArray = readConfigArray() |
---|
| 207 | + | let claimStart = parseIntValue(cfgArray[IdxCfgClaimStart]) |
---|
| 208 | + | let claimDuration = parseIntValue(cfgArray[IdxCfgClaimDuration]) |
---|
| 209 | + | let claimEnd = (claimStart + claimDuration) |
---|
| 210 | + | let price = parseIntValue(cfgArray[IdxCfgPrice]) |
---|
| 211 | + | let priceMult = parseIntValue(cfgArray[IdxCfgPriceMult]) |
---|
| 212 | + | let idoAssetId58 = cfgArray[IdxCfgIdoAssetId] |
---|
| 213 | + | let idoAssetId = fromBase58String(idoAssetId58) |
---|
| 214 | + | let idoAssetMult = parseIntValue(cfgArray[IdxCfgIdoAssetMult]) |
---|
| 215 | + | let priceAssetId58 = cfgArray[IdxCfgPriceAssetId] |
---|
| 216 | + | let priceAssetId = fromBase58String(priceAssetId58) |
---|
| 217 | + | let priceAssetMult = parseIntValue(cfgArray[IdxCfgPriceAssetMult]) |
---|
| 218 | + | let userAddress58 = toString(userAddress) |
---|
| 219 | + | let origInvestArray = readInvestorArrayOrFail(userAddress58) |
---|
| 220 | + | let investTotalAmount = parseIntValue(origInvestArray[IdxInvTotalAmount]) |
---|
| 221 | + | let investLastClaimedHeightTMP = parseIntValue(origInvestArray[IdxInvLastClaimedHeight]) |
---|
| 222 | + | let investLastClaimedHeight = if ((claimStart >= investLastClaimedHeightTMP)) |
---|
| 223 | + | then claimStart |
---|
| 224 | + | else investLastClaimedHeightTMP |
---|
| 225 | + | let newClaimPeriodHeight = if ((height > claimEnd)) |
---|
| 226 | + | then claimEnd |
---|
| 227 | + | else if ((claimStart > height)) |
---|
| 228 | + | then claimStart |
---|
| 229 | + | else height |
---|
| 230 | + | let claimingBlocks = (newClaimPeriodHeight - investLastClaimedHeight) |
---|
| 231 | + | let claimingPriceAssetAmount = fraction(investTotalAmount, claimingBlocks, claimDuration) |
---|
| 232 | + | let claimingIdoAssetAmount = convertPriceAssetIntoIdoAsset(claimingPriceAssetAmount, priceAssetMult, price, priceMult, idoAssetMult) |
---|
| 233 | + | let isUSDN = (claimedAssetId58 == priceAssetId58) |
---|
| 234 | + | let isUSDNClaimDisabled = valueOrElse(getBoolean(keyUSDNClaimDisabled()), false) |
---|
| 235 | + | let checks = [if (!(if (isUSDN) |
---|
| 236 | + | then isUSDNClaimDisabled |
---|
| 237 | + | else false)) |
---|
| 238 | + | then true |
---|
| 239 | + | else throw("USDN claim is disabled")] |
---|
| 240 | + | if ((checks == checks)) |
---|
| 241 | + | then if ((claimedAssetId58 == priceAssetId58)) |
---|
| 242 | + | then $Tuple6([0, -(claimingPriceAssetAmount), claimingPriceAssetAmount, 0], claimingPriceAssetAmount, priceAssetId, origInvestArray, newClaimPeriodHeight, [claimingPriceAssetAmount, claimingIdoAssetAmount]) |
---|
| 243 | + | else if ((claimedAssetId58 == idoAssetId58)) |
---|
| 244 | + | then $Tuple6([0, -(claimingPriceAssetAmount), 0, claimingIdoAssetAmount], claimingIdoAssetAmount, idoAssetId, origInvestArray, newClaimPeriodHeight, [claimingPriceAssetAmount, claimingIdoAssetAmount]) |
---|
| 245 | + | else throw(("unsupported assetId: " + claimedAssetId58)) |
---|
| 246 | + | else throw("Strict value is not equal to itself.") |
---|
| 247 | + | } |
---|
| 248 | + | |
---|
| 249 | + | |
---|
| 250 | + | func internalClaimV2 (priceAssetId58,userAddress58,outAmount,totalUserAvailableToClaim) = { |
---|
| 251 | + | let totalPeriodPriceAssetAllowance = value(getInteger(keyTotalPeriodAllowance(priceAssetId58))) |
---|
| 252 | + | let userPeriodPriceAssetAllowance = value(getInteger(keyUserPeriodAllowance(priceAssetId58))) |
---|
| 253 | + | let periodLength = value(getInteger(keyPeriodLength())) |
---|
| 254 | + | let currentPeriod = valueOrElse(getInteger(keyCurrentPeriod()), 0) |
---|
| 255 | + | let zeroPeriodEndHeighIsDefined = isDefined(getInteger(keyPeriodEndHeight(0))) |
---|
| 256 | + | let $t01307714947 = if ((currentPeriod > 0)) |
---|
| 257 | + | then { |
---|
| 258 | + | let lastPeriodStartHeight = value(getInteger(keyPeriodStartHeight(currentPeriod))) |
---|
| 259 | + | let lastPeriodEndHeight = value(getInteger(keyPeriodEndHeight(currentPeriod))) |
---|
| 260 | + | let $t01333714042 = if ((height > lastPeriodEndHeight)) |
---|
| 261 | + | then { |
---|
| 262 | + | let updatedCurrentPeriod = (currentPeriod + 1) |
---|
| 263 | + | let periodStart = if ((height > (lastPeriodEndHeight + periodLength))) |
---|
| 264 | + | then { |
---|
| 265 | + | let blocksToLastPeriodStart = ((height - lastPeriodEndHeight) % periodLength) |
---|
| 266 | + | if ((blocksToLastPeriodStart == 0)) |
---|
| 267 | + | then ((height - periodLength) + 1) |
---|
| 268 | + | else (height - blocksToLastPeriodStart) |
---|
| 269 | + | } |
---|
| 270 | + | else (lastPeriodEndHeight + 1) |
---|
| 271 | + | let periodEnd = ((periodStart + periodLength) - 1) |
---|
| 272 | + | $Tuple3(updatedCurrentPeriod, periodStart, periodEnd) |
---|
| 273 | + | } |
---|
| 274 | + | else $Tuple3(currentPeriod, lastPeriodStartHeight, lastPeriodEndHeight) |
---|
| 275 | + | let updatedCurrentPeriod = $t01333714042._1 |
---|
| 276 | + | let periodStart = $t01333714042._2 |
---|
| 277 | + | let periodEnd = $t01333714042._3 |
---|
| 278 | + | $Tuple3(updatedCurrentPeriod, periodStart, periodEnd) |
---|
| 279 | + | } |
---|
| 280 | + | else if (zeroPeriodEndHeighIsDefined) |
---|
| 281 | + | then { |
---|
| 282 | + | let zeroPeriodStartHeight = value(getInteger(keyPeriodStartHeight(0))) |
---|
| 283 | + | let zeroPeriodEndHeight = value(getInteger(keyPeriodEndHeight(0))) |
---|
| 284 | + | let $t01429714679 = if ((height > zeroPeriodEndHeight)) |
---|
| 285 | + | then { |
---|
| 286 | + | let updatedCurrentPeriod = (currentPeriod + 1) |
---|
| 287 | + | let periodStart = (zeroPeriodEndHeight + 1) |
---|
| 288 | + | let periodEnd = ((periodStart + periodLength) - 1) |
---|
| 289 | + | $Tuple3(updatedCurrentPeriod, periodStart, periodEnd) |
---|
| 290 | + | } |
---|
| 291 | + | else $Tuple3(currentPeriod, zeroPeriodStartHeight, zeroPeriodEndHeight) |
---|
| 292 | + | let updatedCurrentPeriod = $t01429714679._1 |
---|
| 293 | + | let periodStart = $t01429714679._2 |
---|
| 294 | + | let periodEnd = $t01429714679._3 |
---|
| 295 | + | $Tuple3(updatedCurrentPeriod, periodStart, periodEnd) |
---|
| 296 | + | } |
---|
| 297 | + | else $Tuple3(currentPeriod, valueOrElse(getInteger(keyPeriodStartHeight(currentPeriod)), height), valueOrElse(getInteger(keyPeriodEndHeight(currentPeriod)), ((height + periodLength) - 1))) |
---|
| 298 | + | let updatedCurrentPeriod = $t01307714947._1 |
---|
| 299 | + | let periodStart = $t01307714947._2 |
---|
| 300 | + | let periodEnd = $t01307714947._3 |
---|
| 301 | + | let periodTotalAvailableToClaim = valueOrElse(getInteger(keyPeriodTotalAvailableToClaim(priceAssetId58, updatedCurrentPeriod)), totalPeriodPriceAssetAllowance) |
---|
| 302 | + | let periodUserAvailableToClaim = valueOrElse(getInteger(keyPeriodUserAvailableToClaim(priceAssetId58, updatedCurrentPeriod, userAddress58)), userPeriodPriceAssetAllowance) |
---|
| 303 | + | let priceAssetBalance = valueOrElse(getInteger(keyPriceAssetBalance(userAddress58)), 0) |
---|
| 304 | + | let periodMinAvailableToClaim = min([(outAmount + priceAssetBalance), periodTotalAvailableToClaim, periodUserAvailableToClaim]) |
---|
| 305 | + | let usdtPriceAssetAllowableRatio = value(getInteger(keyUsdtPriceAssetAllowableRatio())) |
---|
| 306 | + | let putOneTknV2PriceAssetAmount = scale8 |
---|
| 307 | + | let $t01570215955 = { |
---|
| 308 | + | let @ = invoke(addressFromStringValue(value(getString(keyUsdtPriceAssetStablePool()))), "putOneTknV2WithoutTakeFeeREADONLY", [putOneTknV2PriceAssetAmount, priceAssetId58], nil) |
---|
| 309 | + | if ($isInstanceOf(@, "(Int, Int, Int)")) |
---|
| 310 | + | then @ |
---|
| 311 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int, Int)")) |
---|
| 312 | + | } |
---|
| 313 | + | if (($t01570215955 == $t01570215955)) |
---|
| 314 | + | then { |
---|
| 315 | + | let bonus = $t01570215955._3 |
---|
| 316 | + | let feeAmount = $t01570215955._2 |
---|
| 317 | + | let lpAmount = $t01570215955._1 |
---|
| 318 | + | let usdtAssetId = value(getString(keyUsdtAssetId())) |
---|
| 319 | + | let $t01601716235 = { |
---|
| 320 | + | let @ = invoke(addressFromStringValue(value(getString(keyUsdtPriceAssetStablePool()))), "getOneTknV2READONLY", [usdtAssetId, lpAmount], nil) |
---|
| 321 | + | if ($isInstanceOf(@, "(Int, Int)")) |
---|
| 322 | + | then @ |
---|
| 323 | + | else throw(($getType(@) + " couldn't be cast to (Int, Int)")) |
---|
| 324 | + | } |
---|
| 325 | + | if (($t01601716235 == $t01601716235)) |
---|
| 326 | + | then { |
---|
| 327 | + | let getOneTknV2FeeAmount = $t01601716235._2 |
---|
| 328 | + | let usdtAmount = $t01601716235._1 |
---|
| 329 | + | let currentUsdtPriceAssetRatio = fraction(putOneTknV2PriceAssetAmount, scale8, usdtAmount) |
---|
| 330 | + | let endPeriodBlocksLeft = (periodEnd - height) |
---|
| 331 | + | $Tuple10(periodMinAvailableToClaim, periodTotalAvailableToClaim, periodUserAvailableToClaim, totalUserAvailableToClaim, usdtPriceAssetAllowableRatio, currentUsdtPriceAssetRatio, endPeriodBlocksLeft, updatedCurrentPeriod, periodStart, periodEnd) |
---|
| 332 | + | } |
---|
| 333 | + | else throw("Strict value is not equal to itself.") |
---|
| 334 | + | } |
---|
| 335 | + | else throw("Strict value is not equal to itself.") |
---|
| 336 | + | } |
---|
| 337 | + | |
---|
| 338 | + | |
---|
| 339 | + | func managerPublicKeyOrUnit () = { |
---|
| 340 | + | let managerVaultAddress = getManagerAddressOrFail() |
---|
| 341 | + | match getString(managerVaultAddress, keyManagerPublicKey()) { |
---|
| 342 | + | case s: String => |
---|
| 343 | + | fromBase58String(s) |
---|
| 344 | + | case _: Unit => |
---|
| 345 | + | unit |
---|
| 346 | + | case _ => |
---|
| 347 | + | throw("Match error") |
---|
| 348 | + | } |
---|
| 349 | + | } |
---|
| 350 | + | |
---|
| 351 | + | |
---|
| 352 | + | func mustManager (i) = { |
---|
| 353 | + | let pd = throw("Permission denied") |
---|
| 354 | + | match managerPublicKeyOrUnit() { |
---|
| 355 | + | case pk: ByteVector => |
---|
| 356 | + | if ((i.callerPublicKey == pk)) |
---|
| 357 | + | then true |
---|
| 358 | + | else pd |
---|
| 359 | + | case _: Unit => |
---|
| 360 | + | if ((i.caller == this)) |
---|
| 361 | + | then true |
---|
| 362 | + | else pd |
---|
| 363 | + | case _ => |
---|
| 364 | + | throw("Match error") |
---|
| 365 | + | } |
---|
| 366 | + | } |
---|
| 367 | + | |
---|
| 368 | + | |
---|
| 369 | + | @Callable(i) |
---|
| 370 | + | func constructor (idoStart,idoDuration,claimStart,claimDuration,price,priceAssetId58,minInvestAmount) = { |
---|
| 371 | + | let priceMult = ((100 * 1000) * 1000) |
---|
| 372 | + | let idoEnd = (idoStart + idoDuration) |
---|
| 373 | + | if (isDefined(getString(keyConfig()))) |
---|
| 374 | + | then throw("already initialized") |
---|
| 375 | + | else if (("3PMEHLx1j6zerarZTYfsGqDeeZqQoMpxq5S" != toString(i.caller))) |
---|
| 376 | + | then throw("not authorized") |
---|
| 377 | + | else if ((size(i.payments) != 1)) |
---|
| 378 | + | then throw("exactly 1 payment must be attached") |
---|
| 379 | + | else if ((idoEnd >= claimStart)) |
---|
| 380 | + | then throw("claimStart must be greater than idoEnd") |
---|
| 381 | + | else { |
---|
| 382 | + | let pmt = value(i.payments[0]) |
---|
| 383 | + | let idoAssetId = value(pmt.assetId) |
---|
| 384 | + | let idoAssetInfo = valueOrErrorMessage(assetInfo(idoAssetId), "fail to load ido asset info") |
---|
| 385 | + | let idoAssetId58 = toBase58String(idoAssetId) |
---|
| 386 | + | let idoAssetMult = pow(10, 0, idoAssetInfo.decimals, 0, 0, DOWN) |
---|
| 387 | + | let priceAssetId = fromBase58String(priceAssetId58) |
---|
| 388 | + | let priceAssetInfo = valueOrErrorMessage(assetInfo(priceAssetId), "fail to load price asset info") |
---|
| 389 | + | let priceAssetMult = pow(10, 0, priceAssetInfo.decimals, 0, 0, DOWN) |
---|
| 390 | + | let origTotalsArray = readTotalsArrayOrDefault() |
---|
| 391 | + | let totalsDiff = [0, 0, 0, 0] |
---|
| 392 | + | [StringEntry(keyConfig(), fromatConfig(idoStart, idoDuration, claimStart, claimDuration, price, priceMult, idoAssetId58, idoAssetMult, priceAssetId58, priceAssetMult, minInvestAmount, pmt.amount)), TotalsEntry(keyTotals(), origTotalsArray, totalsDiff, claimStart, 0)] |
---|
| 393 | + | } |
---|
| 394 | + | } |
---|
| 395 | + | |
---|
| 396 | + | |
---|
| 397 | + | |
---|
| 398 | + | @Callable(i) |
---|
| 399 | + | func invest () = { |
---|
| 400 | + | let cfgArray = readConfigArray() |
---|
| 401 | + | let idoStart = parseIntValue(cfgArray[IdxCfgIdoStart]) |
---|
| 402 | + | let idoDuration = parseIntValue(cfgArray[IdxCfgIdoDuration]) |
---|
| 403 | + | let idoEnd = (idoStart + idoDuration) |
---|
| 404 | + | let claimStart = parseIntValue(cfgArray[IdxCfgClaimStart]) |
---|
| 405 | + | let claimDuration = parseIntValue(cfgArray[IdxCfgClaimDuration]) |
---|
| 406 | + | let price = parseIntValue(cfgArray[IdxCfgPrice]) |
---|
| 407 | + | let priceMult = parseIntValue(cfgArray[IdxCfgPriceMult]) |
---|
| 408 | + | let idoAssetId58 = cfgArray[IdxCfgIdoAssetId] |
---|
| 409 | + | let idoAssetId = fromBase58String(idoAssetId58) |
---|
| 410 | + | let idoAssetMult = parseIntValue(cfgArray[IdxCfgIdoAssetMult]) |
---|
| 411 | + | let priceAssetId58 = cfgArray[IdxCfgPriceAssetId] |
---|
| 412 | + | let priceAssetId = fromBase58String(priceAssetId58) |
---|
| 413 | + | let priceAssetMult = parseIntValue(cfgArray[IdxCfgPriceAssetMult]) |
---|
| 414 | + | let minIvestAmount = parseIntValue(cfgArray[IdxCfgMinInvestAmount]) |
---|
| 415 | + | let userAddress = toString(i.caller) |
---|
| 416 | + | if ((idoStart > height)) |
---|
| 417 | + | then throw("ido has not been started yet") |
---|
| 418 | + | else if ((height > idoEnd)) |
---|
| 419 | + | then throw("ido has been already ended") |
---|
| 420 | + | else if ((size(i.payments) != 1)) |
---|
| 421 | + | then throw("exactly 1 payment is expected") |
---|
| 422 | + | else { |
---|
| 423 | + | let pmt = value(i.payments[0]) |
---|
| 424 | + | let pmtAssetId = value(pmt.assetId) |
---|
| 425 | + | let pmtAmount = pmt.amount |
---|
| 426 | + | if ((pmtAssetId != priceAssetId)) |
---|
| 427 | + | then throw((("invalid payment asset id: " + toBase58String(pmtAssetId)) + " is expected")) |
---|
| 428 | + | else { |
---|
| 429 | + | let origInvestorArray = readInvestorArrayOrDefault(userAddress) |
---|
| 430 | + | let origTotalsArray = readTotalsArrayOrDefault() |
---|
| 431 | + | let newPriceTotalAmount = (parseIntValue(origTotalsArray[IdxInvTotalAmount]) + pmtAmount) |
---|
| 432 | + | let requiredIdoAssetAmount = (newPriceTotalAmount * 100) |
---|
| 433 | + | if ((requiredIdoAssetAmount > assetBalance(this, idoAssetId))) |
---|
| 434 | + | then throw("IDO asset has been - sold consider to use smaller payment") |
---|
| 435 | + | else { |
---|
| 436 | + | let totalsDiff = [pmtAmount, pmtAmount, 0, 0] |
---|
| 437 | + | [TotalsEntry(keyInvestor(userAddress), origInvestorArray, totalsDiff, claimStart, 0), TotalsEntry(keyTotals(), origTotalsArray, totalsDiff, claimStart, 0), InvestOperationHistoryEntry(userAddress, pmtAmount, 0, i.transactionId)] |
---|
| 438 | + | } |
---|
| 439 | + | } |
---|
| 440 | + | } |
---|
| 441 | + | } |
---|
| 442 | + | |
---|
| 443 | + | |
---|
| 444 | + | |
---|
| 445 | + | @Callable(i) |
---|
| 446 | + | func claim (claimedAssetId58,userAddress58) = { |
---|
| 447 | + | let callerAddress58 = toString(i.caller) |
---|
| 448 | + | if ((userAddress58 != callerAddress58)) |
---|
| 449 | + | then throw("not authorized") |
---|
| 450 | + | else { |
---|
| 451 | + | let cfgArray = readConfigArray() |
---|
| 452 | + | let priceAssetId58 = cfgArray[IdxCfgPriceAssetId] |
---|
| 453 | + | let claimResultTuple = internalClaim(claimedAssetId58, i.caller, i.transactionId) |
---|
| 454 | + | let totalsDiff = claimResultTuple._1 |
---|
| 455 | + | let outAmount = claimResultTuple._2 |
---|
| 456 | + | let outAssetId = claimResultTuple._3 |
---|
| 457 | + | let origInvestArray = claimResultTuple._4 |
---|
| 458 | + | let newClaimPeriodHeight = claimResultTuple._5 |
---|
| 459 | + | let claimedPriceAmountFromDiff = totalsDiff[IdxDiffClaimedPriceAmountIncrement] |
---|
| 460 | + | let claimedIdoAssetAmountFromDiff = totalsDiff[IdxDiffClaimedIdoAssetAmountIncrement] |
---|
| 461 | + | let priceAssetBalance = valueOrElse(getInteger(keyPriceAssetBalance(userAddress58)), 0) |
---|
| 462 | + | let priceAssetDecimals = value(assetInfo(fromBase58String(priceAssetId58))).decimals |
---|
| 463 | + | let entries = if ((claimedAssetId58 == priceAssetId58)) |
---|
| 464 | + | then { |
---|
| 465 | + | let $t02207422518 = internalClaimV2(priceAssetId58, userAddress58, outAmount, totalsDiff[IdxDiffClaimedPriceAmountIncrement]) |
---|
| 466 | + | let periodMinAvailableToClaim = $t02207422518._1 |
---|
| 467 | + | let periodTotalAvailableToClaim = $t02207422518._2 |
---|
| 468 | + | let periodUserAvailableToClaim = $t02207422518._3 |
---|
| 469 | + | let totalUserAvailableToClaim = $t02207422518._4 |
---|
| 470 | + | let usdtPriceAssetAllowableRatio = $t02207422518._5 |
---|
| 471 | + | let currentUsdtPriceAssetRatio = $t02207422518._6 |
---|
| 472 | + | let endPeriodBlocksLeft = $t02207422518._7 |
---|
| 473 | + | let updatedCurrentPeriod = $t02207422518._8 |
---|
| 474 | + | let periodStart = $t02207422518._9 |
---|
| 475 | + | let periodEnd = $t02207422518._10 |
---|
| 476 | + | let checks = [if ((periodUserAvailableToClaim > 0)) |
---|
| 477 | + | then true |
---|
| 478 | + | else throwErr("unavailable to claim because user period allowance reached"), if ((periodTotalAvailableToClaim > 0)) |
---|
| 479 | + | then true |
---|
| 480 | + | else throwErr("unavailable to claim because total period allowance reached"), if ((periodMinAvailableToClaim > 0)) |
---|
| 481 | + | then true |
---|
| 482 | + | else throwErr("nothing to claim"), if ((usdtPriceAssetAllowableRatio > currentUsdtPriceAssetRatio)) |
---|
| 483 | + | then true |
---|
| 484 | + | else throwErr("unavailable to claim because usdn price lower than usdtPriceAssetAllowableRatio")] |
---|
| 485 | + | if ((checks == checks)) |
---|
| 486 | + | then { |
---|
| 487 | + | let updatedPeriodTotalAvailableToClaim = (periodTotalAvailableToClaim - periodMinAvailableToClaim) |
---|
| 488 | + | let updatedPeriodUserAvailableToClaim = (periodUserAvailableToClaim - periodMinAvailableToClaim) |
---|
| 489 | + | let entries = if ((priceAssetBalance > periodMinAvailableToClaim)) |
---|
| 490 | + | then [ScriptTransfer(i.caller, periodMinAvailableToClaim, outAssetId), IntegerEntry(keyPriceAssetBalance(userAddress58), (priceAssetBalance - periodMinAvailableToClaim))] |
---|
| 491 | + | else { |
---|
| 492 | + | let evaluateResult = split(asString(invoke(this, "claimREADONLY", [priceAssetId58, userAddress58], nil)), SEP) |
---|
| 493 | + | if ((evaluateResult == evaluateResult)) |
---|
| 494 | + | then { |
---|
| 495 | + | let availablePriceAmountToClaim = parseIntValue(evaluateResult[3]) |
---|
| 496 | + | let lastClaimEntries = if ((availablePriceAmountToClaim == periodMinAvailableToClaim)) |
---|
| 497 | + | then { |
---|
| 498 | + | let investorTotalAmount = parseIntValue(origInvestArray[IdxInvTotalAmount]) |
---|
| 499 | + | let investorRemainingAmount = parseIntValue(origInvestArray[IdxInvRemainingAmount]) |
---|
| 500 | + | let investorPriceAssetBalance = parseIntValue(origInvestArray[IdxInvClaimedPriceAssetAmount]) |
---|
| 501 | + | let investorIdoAssetBalance = parseIntValue(origInvestArray[IdxInvClaimedIdoAssetAmount]) |
---|
| 502 | + | let investorLastClaimedHeight = parseIntValue(origInvestArray[IdxInvLastClaimedHeight]) |
---|
| 503 | + | let newInvestArray = [toString(investorTotalAmount), "0", toString(investorPriceAssetBalance), toString(investorIdoAssetBalance), toString(investorLastClaimedHeight)] |
---|
| 504 | + | let totals = readTotalsArrayOrDefault() |
---|
| 505 | + | let totalsTotalAmount = parseIntValue(totals[IdxInvTotalAmount]) |
---|
| 506 | + | let totalsRemainingAmount = parseIntValue(totals[IdxInvRemainingAmount]) |
---|
| 507 | + | let totalsClaimedPriceAssetAmount = parseIntValue(totals[IdxInvClaimedPriceAssetAmount]) |
---|
| 508 | + | let totalsClaimedIdoAssetAmount = parseIntValue(totals[IdxInvClaimedIdoAssetAmount]) |
---|
| 509 | + | let totalsLastClaimedHeight = parseIntValue(totals[IdxInvLastClaimedHeight]) |
---|
| 510 | + | let newTotalsRemainingAmount = (totalsRemainingAmount - investorRemainingAmount) |
---|
| 511 | + | let newTotalArray = [toString(totalsTotalAmount), toString(newTotalsRemainingAmount), toString(totalsClaimedPriceAssetAmount), toString(totalsClaimedIdoAssetAmount), toString(totalsLastClaimedHeight)] |
---|
| 512 | + | let newTotalRemainingAmount = (valueOrElse(getInteger(keyTotalRemainingAmount()), 0) + investorRemainingAmount) |
---|
| 513 | + | [StringEntry(keyInvestorRemainingAmount(userAddress58), toString(investorRemainingAmount)), StringEntry(keyTotalRemainingAmount(), toString(newTotalRemainingAmount)), TotalsEntry(keyInvestor(userAddress58), newInvestArray, totalsDiff, newClaimPeriodHeight, 0), TotalsEntry(keyTotals(), newTotalArray, totalsDiff, newClaimPeriodHeight, 0)] |
---|
| 514 | + | } |
---|
| 515 | + | else [TotalsEntry(keyInvestor(userAddress58), origInvestArray, totalsDiff, newClaimPeriodHeight, 0), TotalsEntry(keyTotals(), readTotalsArrayOrDefault(), totalsDiff, newClaimPeriodHeight, 0)] |
---|
| 516 | + | let updatedPriceAssetBalance = ((priceAssetBalance + outAmount) - periodMinAvailableToClaim) |
---|
| 517 | + | ([ScriptTransfer(i.caller, periodMinAvailableToClaim, outAssetId), IntegerEntry(keyPriceAssetBalance(userAddress58), updatedPriceAssetBalance)] ++ lastClaimEntries) |
---|
| 518 | + | } |
---|
| 519 | + | else throw("Strict value is not equal to itself.") |
---|
| 520 | + | } |
---|
| 521 | + | $Tuple2(([IntegerEntry(keyCurrentPeriod(), updatedCurrentPeriod), IntegerEntry(keyPeriodStartHeight(updatedCurrentPeriod), periodStart), IntegerEntry(keyPeriodEndHeight(updatedCurrentPeriod), periodEnd), IntegerEntry(keyPeriodTotalAvailableToClaim(priceAssetId58, updatedCurrentPeriod), updatedPeriodTotalAvailableToClaim), IntegerEntry(keyPeriodUserAvailableToClaim(priceAssetId58, updatedCurrentPeriod, userAddress58), updatedPeriodUserAvailableToClaim), ClaimOperationHistoryEntry(userAddress58, periodMinAvailableToClaim, claimedIdoAssetAmountFromDiff, i.transactionId)] ++ entries), unit) |
---|
| 522 | + | } |
---|
| 523 | + | else throw("Strict value is not equal to itself.") |
---|
| 524 | + | } |
---|
| 525 | + | else { |
---|
| 526 | + | let priceAssetBalanceIdoDecimals = fraction(priceAssetBalance, scale8, pow(10, 0, priceAssetDecimals, 0, 0, DOWN)) |
---|
| 527 | + | $Tuple2([ScriptTransfer(i.caller, (outAmount + priceAssetBalanceIdoDecimals), outAssetId), IntegerEntry(keyPriceAssetBalance(userAddress58), 0), TotalsEntry(keyInvestor(userAddress58), origInvestArray, totalsDiff, newClaimPeriodHeight, priceAssetBalance), TotalsEntry(keyTotals(), readTotalsArrayOrDefault(), totalsDiff, newClaimPeriodHeight, priceAssetBalance), ClaimOperationHistoryEntry(userAddress58, claimedPriceAmountFromDiff, (claimedIdoAssetAmountFromDiff + priceAssetBalanceIdoDecimals), i.transactionId)], unit) |
---|
| 528 | + | } |
---|
| 529 | + | entries |
---|
| 530 | + | } |
---|
| 531 | + | } |
---|
| 532 | + | |
---|
| 533 | + | |
---|
| 534 | + | |
---|
| 535 | + | @Callable(i) |
---|
| 536 | + | func cleanRemaingAmount (userAddress58) = { |
---|
| 537 | + | let priceAssetId58 = readConfigArray()[IdxCfgPriceAssetId] |
---|
| 538 | + | let evaluateResult = split(asString(invoke(this, "claimREADONLY", [priceAssetId58, userAddress58], nil)), SEP) |
---|
| 539 | + | if ((evaluateResult == evaluateResult)) |
---|
| 540 | + | then { |
---|
| 541 | + | let availablePriceAmountToClaim = parseIntValue(evaluateResult[2]) |
---|
| 542 | + | let checkUnclaimedAssets = if ((availablePriceAmountToClaim == 0)) |
---|
| 543 | + | then true |
---|
| 544 | + | else throwErr("user have unclaimed assets") |
---|
| 545 | + | if ((checkUnclaimedAssets == checkUnclaimedAssets)) |
---|
| 546 | + | then { |
---|
| 547 | + | let investor = split(value(getString(keyInvestor(userAddress58))), SEP) |
---|
| 548 | + | let investorTotalAmount = parseIntValue(investor[IdxInvTotalAmount]) |
---|
| 549 | + | let investorRemainingAmount = parseIntValue(investor[IdxInvRemainingAmount]) |
---|
| 550 | + | let investorPriceAssetBalance = parseIntValue(investor[IdxInvClaimedPriceAssetAmount]) |
---|
| 551 | + | let investorIdoAssetBalance = parseIntValue(investor[IdxInvClaimedIdoAssetAmount]) |
---|
| 552 | + | let investorLastClaimedHeight = parseIntValue(investor[IdxInvLastClaimedHeight]) |
---|
| 553 | + | let investorRemainingAmountCheck = if ((investorRemainingAmount != 0)) |
---|
| 554 | + | then true |
---|
| 555 | + | else throwErr("investorRemainingAmount already zero") |
---|
| 556 | + | if ((investorRemainingAmountCheck == investorRemainingAmountCheck)) |
---|
| 557 | + | then { |
---|
| 558 | + | let newInvestor = makeString(["%d%d%d%d%d", toString(investorTotalAmount), "0", toString(investorPriceAssetBalance), toString(investorIdoAssetBalance), toString(investorLastClaimedHeight)], SEP) |
---|
| 559 | + | let totals = split(value(getString(keyTotals())), SEP) |
---|
| 560 | + | let totalsTotalAmount = parseIntValue(totals[IdxInvTotalAmount]) |
---|
| 561 | + | let totalsRemainingAmount = parseIntValue(totals[IdxInvRemainingAmount]) |
---|
| 562 | + | let totalsClaimedPriceAssetAmount = parseIntValue(totals[IdxInvClaimedPriceAssetAmount]) |
---|
| 563 | + | let totalsClaimedIdoAssetAmount = parseIntValue(totals[IdxInvClaimedIdoAssetAmount]) |
---|
| 564 | + | let totalsLastClaimedHeight = parseIntValue(totals[IdxInvLastClaimedHeight]) |
---|
| 565 | + | let newTotals = makeString(["%d%d%d%d%d", toString(totalsTotalAmount), toString((totalsRemainingAmount - investorRemainingAmount)), toString(totalsClaimedPriceAssetAmount), toString(totalsClaimedIdoAssetAmount), toString(totalsLastClaimedHeight)], SEP) |
---|
| 566 | + | let newTotalRemainingAmount = (valueOrElse(getInteger(keyTotalRemainingAmount()), 0) + investorRemainingAmount) |
---|
| 567 | + | [StringEntry(keyInvestorRemainingAmount(userAddress58), toString(investorRemainingAmount)), StringEntry(keyTotalRemainingAmount(), toString(newTotalRemainingAmount)), StringEntry(keyInvestor(userAddress58), newInvestor), StringEntry(keyTotals(), newTotals)] |
---|
| 568 | + | } |
---|
| 569 | + | else throw("Strict value is not equal to itself.") |
---|
| 570 | + | } |
---|
| 571 | + | else throw("Strict value is not equal to itself.") |
---|
| 572 | + | } |
---|
| 573 | + | else throw("Strict value is not equal to itself.") |
---|
| 574 | + | } |
---|
| 575 | + | |
---|
| 576 | + | |
---|
| 577 | + | |
---|
| 578 | + | @Callable(i) |
---|
| 579 | + | func claimREADONLY (claimedAssetId58,userAddress58) = { |
---|
| 580 | + | let claimResultTuple = internalClaim(claimedAssetId58, addressFromStringValue(userAddress58), fromBase58String("")) |
---|
| 581 | + | let totalsDiff = claimResultTuple._1 |
---|
| 582 | + | let outAmount = claimResultTuple._2 |
---|
| 583 | + | let outAssetId = claimResultTuple._3 |
---|
| 584 | + | let origInvestArray = claimResultTuple._4 |
---|
| 585 | + | let newClaimPeriodHeight = claimResultTuple._5 |
---|
| 586 | + | let availableToClaimArray = claimResultTuple._6 |
---|
| 587 | + | let availablePriceAmountToClaim = availableToClaimArray[0] |
---|
| 588 | + | let availableIdoAmountToClaim = availableToClaimArray[1] |
---|
| 589 | + | $Tuple2(nil, makeString(["%s%d%d", userAddress58, toString(availablePriceAmountToClaim), toString(availableIdoAmountToClaim)], SEP)) |
---|
| 590 | + | } |
---|
| 591 | + | |
---|
| 592 | + | |
---|
| 593 | + | |
---|
| 594 | + | @Callable(i) |
---|
| 595 | + | func claimV2READONLY (claimedAssetId58,userAddress58) = { |
---|
| 596 | + | let claimResultTuple = internalClaim(claimedAssetId58, addressFromStringValue(userAddress58), fromBase58String("")) |
---|
| 597 | + | let totalsDiff = claimResultTuple._1 |
---|
| 598 | + | let outAmount = claimResultTuple._2 |
---|
| 599 | + | let outAssetId = claimResultTuple._3 |
---|
| 600 | + | let origInvestArray = claimResultTuple._4 |
---|
| 601 | + | let newClaimPeriodHeight = claimResultTuple._5 |
---|
| 602 | + | let availableToClaimArray = claimResultTuple._6 |
---|
| 603 | + | let availablePriceAmountToClaim = availableToClaimArray[0] |
---|
| 604 | + | let availableIdoAmountToClaim = availableToClaimArray[1] |
---|
| 605 | + | let cfgArray = readConfigArray() |
---|
| 606 | + | let priceAssetId58 = cfgArray[IdxCfgPriceAssetId] |
---|
| 607 | + | let priceAssetBalance = valueOrElse(getInteger(keyPriceAssetBalance(userAddress58)), 0) |
---|
| 608 | + | let priceAssetBalanceIdoDecimals = (priceAssetBalance * 100) |
---|
| 609 | + | let availableIdoAmountToClaimWithPriceAssetBalance = (availableIdoAmountToClaim + priceAssetBalanceIdoDecimals) |
---|
| 610 | + | let $t03376934181 = internalClaimV2(priceAssetId58, userAddress58, outAmount, totalsDiff[IdxDiffClaimedPriceAmountIncrement]) |
---|
| 611 | + | let periodMinAvailableToClaim = $t03376934181._1 |
---|
| 612 | + | let periodTotalAvailableToClaim = $t03376934181._2 |
---|
| 613 | + | let periodUserAvailableToClaim = $t03376934181._3 |
---|
| 614 | + | let totalUserAvailableToClaim = $t03376934181._4 |
---|
| 615 | + | let usdtPriceAssetAllowableRatio = $t03376934181._5 |
---|
| 616 | + | let currentUsdtPriceAssetRatio = $t03376934181._6 |
---|
| 617 | + | let endPeriodBlocksLeft = $t03376934181._7 |
---|
| 618 | + | let updatedCurrentPeriod = $t03376934181._8 |
---|
| 619 | + | let periodStart = $t03376934181._9 |
---|
| 620 | + | let periodEnd = $t03376934181._10 |
---|
| 621 | + | let currentPeriodEndHeight = valueOrElse(getInteger(keyPeriodEndHeight(updatedCurrentPeriod)), 0) |
---|
| 622 | + | let userTotalPriceAssetClaimed = (parseIntValue(readInvestorArrayOrFail(userAddress58)[IdxInvClaimedPriceAssetAmount]) - priceAssetBalance) |
---|
| 623 | + | let resultString = if ((height > currentPeriodEndHeight)) |
---|
| 624 | + | then { |
---|
| 625 | + | let periodLenght = value(getInteger(keyPeriodLength())) |
---|
| 626 | + | let userPeriodAllowance = value(getInteger(keyUserPeriodAllowance(priceAssetId58))) |
---|
| 627 | + | let totalPeriodAllowance = value(getInteger(keyTotalPeriodAllowance(priceAssetId58))) |
---|
| 628 | + | makeString(["%d%d%d%d%d%d", toString(availableIdoAmountToClaimWithPriceAssetBalance), toString(userPeriodAllowance), toString(totalPeriodAllowance), toString(usdtPriceAssetAllowableRatio), toString(currentUsdtPriceAssetRatio), toString(periodLenght), toString(userTotalPriceAssetClaimed)], SEP) |
---|
| 629 | + | } |
---|
| 630 | + | else makeString(["%d%d%d%d%d%d", toString(availableIdoAmountToClaimWithPriceAssetBalance), toString(periodMinAvailableToClaim), toString(periodTotalAvailableToClaim), toString(usdtPriceAssetAllowableRatio), toString(currentUsdtPriceAssetRatio), toString(endPeriodBlocksLeft), toString(userTotalPriceAssetClaimed)], SEP) |
---|
| 631 | + | $Tuple2(nil, resultString) |
---|
| 632 | + | } |
---|
| 633 | + | |
---|
| 634 | + | |
---|
| 635 | + | @Verifier(tx) |
---|
| 636 | + | func verify () = { |
---|
| 637 | + | let targetPublicKey = match managerPublicKeyOrUnit() { |
---|
| 638 | + | case pk: ByteVector => |
---|
| 639 | + | pk |
---|
| 640 | + | case _: Unit => |
---|
| 641 | + | tx.senderPublicKey |
---|
| 642 | + | case _ => |
---|
| 643 | + | throw("Match error") |
---|
| 644 | + | } |
---|
| 645 | + | sigVerify(tx.bodyBytes, tx.proofs[0], targetPublicKey) |
---|
| 646 | + | } |
---|
| 647 | + | |
---|