Skip to content

Commit

Permalink
blocks in period variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ridev6 committed Aug 10, 2023
1 parent 40457b3 commit a8de7ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion migrations/wxdefi-435-release/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
MIN_LOCK_AMOUNT,
MIN_LOCK_DURATION,
MAX_LOCK_DURATION,
BLOCKS_IN_PERIOD,
} = process.env;
const api = create(NODE_URL);

Expand Down Expand Up @@ -141,12 +142,13 @@ txs.push({
key: '%s__config',
type: 'string',
value: [
'%s%d%d%d%s',
'%s%d%d%d%s%d',
WX_ASSET_ID,
MIN_LOCK_AMOUNT.toString(),
MIN_LOCK_DURATION.toString(),
MAX_LOCK_DURATION.toString(),
gwxRewardAddress,
BLOCKS_IN_PERIOD.toString(),
].join(separator),
}
],
Expand Down
12 changes: 7 additions & 5 deletions ride/boosting.ride
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# * "%s%s__config__referralsContractAddress": String
# * "%s__nextUserNum": Int
# * "%s%s__config__factoryAddress": String
# * "%s__config": String ("%s%d%d%d%s__<assetId>__<minLockAmount>__<minLockDuration>__<maxLockDuration>__<mathContract>")
# * "%s__config": String ("%s%d%d%d%s%d__<assetId>__<minLockAmount>__<minLockDuration>__<maxLockDuration>__<mathContract>__<blocksInPeriod>")
# * "%s__lpStakingPoolsContract": String

let SEP = "__"
Expand Down Expand Up @@ -94,6 +94,7 @@ let IdxCfgMinLockAmount = 2
let IdxCfgMinLockDuration = 3
let IdxCfgMaxLockDuration = 4
let IdxCfgMathContract = 5
let IdxCfgBlocksInPeriod = 6

func keyConfig() = {"%s__config"}
func readConfigArrayOrFail() = this.getStringOrFail(keyConfig()).split(SEP)
Expand All @@ -103,6 +104,7 @@ let minLockAmount = cfgArray[IdxCfgMinLockAmount].parseInt().valueOrErrorMessage
let minLockDuration = cfgArray[IdxCfgMinLockDuration].parseInt().valueOrErrorMessage(wrapErr("invalid min lock duration"))
let maxLockDuration = cfgArray[IdxCfgMaxLockDuration].parseInt().valueOrErrorMessage(wrapErr("invalid max lock duration"))
let mathContract = cfgArray[IdxCfgMathContract].addressFromString().valueOrErrorMessage(wrapErr("invalid math contract address"))
let blocksInPeriod = cfgArray[IdxCfgBlocksInPeriod].parseInt().valueOrErrorMessage(wrapErr("invalid blocks in period"))

func formatConfigS(assetId: String, minLockAmount: String, minLockDuration: String, maxLockDuration: String, mathContract: String) = {
makeString([
Expand Down Expand Up @@ -646,11 +648,11 @@ func getWxWithdrawable(userAddress: Address, txIdOption: ByteVector|Unit) = {
let wxClaimed = userRecordArray[IdxLockWxClaimed].parseIntValue()
let gwxAmount = userRecordArray[IdxLockGwxAmount].parseIntValue()

let t = (height - lockStart) / blocksInDay
let t = (height - lockStart) / blocksInPeriod

let exponent = fraction(
t.toBigInt(),
{ 8 * blocksInDay }.toBigInt() * MULT18BI,
{ 8 * blocksInPeriod }.toBigInt() * MULT18BI,
lockDuration.toBigInt()
)
let wxWithdrawable = if (height > lockEnd) then {
Expand Down Expand Up @@ -730,7 +732,7 @@ func unlock(txIdStr: String, amount: Int) = {
let wxClaimed = userRecordArray[IdxLockWxClaimed].parseIntValue()
let gwxAmount = userRecordArray[IdxLockGwxAmount].parseIntValue()

let t = (height - lockStart) / blocksInDay
let t = (height - lockStart) / blocksInPeriod

let wxWithdrawable = getWxWithdrawable(
userAddress,
Expand All @@ -743,7 +745,7 @@ func unlock(txIdStr: String, amount: Int) = {

let gwxBurned = max([
amount,
fraction(t * blocksInDay, userAmount, maxLockDuration)
fraction(t * blocksInPeriod, userAmount, maxLockDuration)
])
let gwxRemaining = ensurePositive(gwxAmount - gwxBurned, "gwxRemaining")
let lockedGwxAmount = getLockedGwxAmount(userAddress)
Expand Down

0 comments on commit a8de7ed

Please sign in to comment.