Skip to content

Commit

Permalink
2.0.3 further tweaked precision
Browse files Browse the repository at this point in the history
  • Loading branch information
boyuanx committed Nov 28, 2023
1 parent 47e9b03 commit 810e7c9
Show file tree
Hide file tree
Showing 9 changed files with 840 additions and 70 deletions.
8 changes: 3 additions & 5 deletions contracts/core/TokenTableUnlockerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ contract TokenTableUnlockerV2 is
override
returns (uint256 deltaAmountClaimable, uint256 updatedAmountClaimed)
{
uint256 precisionDecimals = 10 ** 10;
uint256 precisionDecimals = 10 ** 5;
UnlockingScheduleActual memory actual = unlockingScheduleActuals[
actualId
];
Expand Down Expand Up @@ -555,15 +555,13 @@ contract TokenTableUnlockerV2 is
preset.linearStartTimestampsRelative[
latestIncompleteLinearIndex
];
uint256 numOfClaimableUnlocksInIncompleteLinear = (latestIncompleteLinearClaimableTimestampRelative *
precisionDecimals) /
uint256 numOfClaimableUnlocksInIncompleteLinear = latestIncompleteLinearClaimableTimestampRelative /
latestIncompleteLinearIntervalForEachUnlock;
updatedAmountClaimed +=
(preset.linearBips[latestIncompleteLinearIndex] *
precisionDecimals *
numOfClaimableUnlocksInIncompleteLinear) /
preset.numOfUnlocksForEachLinear[latestIncompleteLinearIndex] /
precisionDecimals;
preset.numOfUnlocksForEachLinear[latestIncompleteLinearIndex];
updatedAmountClaimed =
(updatedAmountClaimed * actual.totalAmount) /
BIPS_PRECISION /
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

142 changes: 85 additions & 57 deletions deployments/zkSyncEra/TokenTableUnlockerV2.json

Large diffs are not rendered by default.

198 changes: 198 additions & 0 deletions deployments/zkSyncEra/solcInputs/2f2c481e30ec55c0f8ffc0acb17729d6.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export default {
polygonMumbai: process.env.POLYGONSCAN_KEY,
mantaPacific: process.env.MANTAPACIFIC_KEY,
mantaPacificTestnet: process.env.MANTAPACIFIC_TEST_KEY,
avaxC: process.env.SNOWTRACE_KEY
avaxC: process.env.SNOWTRACE_KEY,
sepolia: process.env.ETHERSCAN_KEY,
mainnet: process.env.ETHERSCAN_KEY
},
customChains: [
{
Expand Down
5 changes: 2 additions & 3 deletions test/TokenTableUnlockerV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ const calculateAmountOfTokensToClaimAtTimestamp = (
claimTimestampRelative -
linearStartTimestampsRelative[latestIncompleteLinearIndex]
const numOfClaimableUnlocksInIncompleteLinear =
(latestIncompleteLinearClaimableTimestampRelative * precisionDecimals) /
latestIncompleteLinearClaimableTimestampRelative /
latestIncompleteLinearIntervalForEachUnlock

const latestIncompleteLinearClaimableBips =
(linearBips[latestIncompleteLinearIndex] *
precisionDecimals *
numOfClaimableUnlocksInIncompleteLinear) /
numOfUnlocksForEachLinear[latestIncompleteLinearIndex] /
precisionDecimals
numOfUnlocksForEachLinear[latestIncompleteLinearIndex]

claimableBips += latestIncompleteLinearClaimableBips
if (claimableBips > bipsPrecision * precisionDecimals) {
Expand Down
7 changes: 3 additions & 4 deletions test/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const calculateAmountOfTokensToClaimAtTimestamp = (
bipsPrecision: bigint,
totalAmount: bigint
): bigint => {
const precisionDecimals = 10n ** 10n
const precisionDecimals = 10n ** 5n
let claimableBips = 0n
const claimTimestampRelative =
claimTimestampAbsolute - startTimestampAbsolute
Expand Down Expand Up @@ -51,15 +51,14 @@ const calculateAmountOfTokensToClaimAtTimestamp = (
claimTimestampRelative -
linearStartTimestampsRelative[latestIncompleteLinearIndex]
const numOfClaimableUnlocksInIncompleteLinear =
(latestIncompleteLinearClaimableTimestampRelative * precisionDecimals) /
latestIncompleteLinearClaimableTimestampRelative /
latestIncompleteLinearIntervalForEachUnlock

const latestIncompleteLinearClaimableBips =
(linearBips[latestIncompleteLinearIndex] *
precisionDecimals *
numOfClaimableUnlocksInIncompleteLinear) /
numOfUnlocksForEachLinear[latestIncompleteLinearIndex] /
precisionDecimals
numOfUnlocksForEachLinear[latestIncompleteLinearIndex]

claimableBips += latestIncompleteLinearClaimableBips
if (claimableBips > bipsPrecision * precisionDecimals) {
Expand Down

0 comments on commit 810e7c9

Please sign in to comment.