Skip to content

Commit

Permalink
Merge pull request #223 from OriginTrail/chiado-contracts-redeployment
Browse files Browse the repository at this point in the history
Chiado contracts redeployment
  • Loading branch information
br41nl3t authored Feb 7, 2024
2 parents 097a197 + a02629c commit b27fff2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
11 changes: 7 additions & 4 deletions contracts/v2/scoring/LinearSum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ contract LinearSum is IProximityScoreFunctionsPair, Indexable, Named, HubDepende

if (1e18 >= normalizedDistance) {
return
ScaleDownLib.toUint40((1e18 - normalizedDistance) * w1 + normalizeStake(stake) * w2, (w1 + w2) * 1e18);
ScaleDownLib.toUint40(
uint216(1e18 - normalizedDistance) * w1 + uint216(normalizeStake(stake)) * w2,
uint216(w1 + w2) * 1e18
);
} else {
uint64 proximityScore = (normalizedDistance - 1e18) * w1;
uint64 stakeScore = normalizeStake(stake) * w2;
uint216 proximityScore = uint216(normalizedDistance - 1e18) * w1;
uint216 stakeScore = uint216(normalizeStake(stake)) * w2;
if (stakeScore <= proximityScore) {
return 0;
}
return ScaleDownLib.toUint40(stakeScore - proximityScore, (w1 + w2) * 1e18);
return ScaleDownLib.toUint40(stakeScore - proximityScore, uint216(w1 + w2) * 1e18);
}
}

Expand Down
8 changes: 4 additions & 4 deletions deployments/gnosis_chiado_dev_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@
"deployed": true
},
"LinearSum": {
"evmAddress": "0x50c8Bcea7935242b991934Eb0251ff0CdAD4ED7f",
"evmAddress": "0x5dA70b2fF6aAc33EE21350df19183173F72E01dF",
"version": null,
"gitBranch": "release/delegations",
"gitCommitHash": "3170df6307d65977d66d8bc22134ecaf5fef8fe5",
"deploymentTimestamp": 1706896901040,
"gitBranch": "chiado-contracts-redeployment",
"gitCommitHash": "bfc4be6d0239de8b3c1e6a2017c4e71d3c9c2e50",
"deploymentTimestamp": 1707235148480,
"deployed": true
},
"Log2PLDSF": {
Expand Down
8 changes: 4 additions & 4 deletions deployments/gnosis_chiado_test_contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@
"version": "1.0.0"
},
"LinearSum": {
"evmAddress": "0x669C7e51EbBdA5C57503Ff19feb463109874C2D5",
"evmAddress": "0xEad3f049298d483aAf2C1341EE8E84237f0853cB",
"version": null,
"gitBranch": "release/delegations",
"gitCommitHash": "3170df6307d65977d66d8bc22134ecaf5fef8fe5",
"deploymentTimestamp": 1706896932563,
"gitBranch": "chiado-contracts-redeployment",
"gitCommitHash": "bfc4be6d0239de8b3c1e6a2017c4e71d3c9c2e50",
"deploymentTimestamp": 1707235181232,
"deployed": true
},
"NodeOperatorFeeChangesStorage": {
Expand Down
8 changes: 4 additions & 4 deletions deployments/parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"LinearSum": {
"w1": "1",
"w2": "1",
"w2": "100",
"distanceScaleFactor": "1000000000000000000",
"stakeScaleFactor": "1000000000000000000"
},
Expand Down Expand Up @@ -232,7 +232,7 @@
},
"LinearSum": {
"w1": "1",
"w2": "1",
"w2": "100",
"distanceScaleFactor": "1000000000000000000",
"stakeScaleFactor": "1000000000000000000"
},
Expand Down Expand Up @@ -394,7 +394,7 @@
},
"LinearSum": {
"w1": "1",
"w2": "1",
"w2": "100",
"distanceScaleFactor": "1000000000000000000",
"stakeScaleFactor": "1000000000000000000"
},
Expand Down Expand Up @@ -556,7 +556,7 @@
},
"LinearSum": {
"w1": "1",
"w2": "1",
"w2": "100",
"distanceScaleFactor": "1000000000000000000",
"stakeScaleFactor": "1000000000000000000"
},
Expand Down
14 changes: 6 additions & 8 deletions test/v2/unit/LinearSum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ describe('@v2 @unit LinearSum', function () {
const linearSumParams = await LinearSum.getParameters();
const [, stakeScaleFactor, , w2] = linearSumParams;

let normalizedStake = stakeScaleFactor.mul(stake.sub(minStake)).div(maxStake.sub(minStake));
if (normalizedStake.gt(UINT64_MAX_BN)) {
normalizedStake = normalizedStake.mod(UINT64_MAX_BN.add(1));
}
const normalizedStake = stakeScaleFactor.mul(stake.sub(minStake)).div(maxStake.sub(minStake));
const stakeScore = normalizedStake.mul(w2);

return stakeScore;
Expand Down Expand Up @@ -227,7 +224,7 @@ describe('@v2 @unit LinearSum', function () {
BigNumber.from('1000000000000000000'),
BigNumber.from('1000000000000000000'),
1,
1,
100,
]);
});

Expand Down Expand Up @@ -295,6 +292,7 @@ describe('@v2 @unit LinearSum', function () {
});

it('Manual verification of score function', async function () {
const w2 = await LinearSum.w2();
const minStake = await ParametersStorage.minimumStake();
const maxStake = await ParametersStorage.maximumStake();
const peerHash = ZERO_BYTES32;
Expand All @@ -310,7 +308,7 @@ describe('@v2 @unit LinearSum', function () {

const stakeScore = await calculateStakeScore(distance, stake, maxDistance, 1, 1, minStake, maxStake);
// 50k / 1950k = 0.0256410256410256410256410256410256410256410256410256410256410256
expect(stakeScore).to.be.equal(BigNumber.from('25641025641025641'));
expect(stakeScore).to.be.equal(BigNumber.from('25641025641025641').mul(w2));

const scoreBeforeScaling = await calculateScoreBeforeScaling(
distance,
Expand All @@ -321,9 +319,9 @@ describe('@v2 @unit LinearSum', function () {
minStake,
maxStake,
);
expect(scoreBeforeScaling).to.be.equal(BigNumber.from('525641025641025641'));
expect(scoreBeforeScaling).to.be.equal(BigNumber.from('3064102564102564100'));

const score = await calculateScore(distance, stake, maxDistance, 1, 1, minStake, maxStake);
expect(score).to.be.equal(BigNumber.from('288974209863'));
expect(score).to.be.equal(BigNumber.from('33356597999'));
});
});

0 comments on commit b27fff2

Please sign in to comment.