Skip to content

Commit 534fe43

Browse files
committed
feat: added getChallengeValue method
1 parent fe1dd7c commit 534fe43

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

contracts/standard/arbitration/Linguo.sol

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @authors: [@unknownunknown1]
2+
* @authors: [@unknownunknown1*]
33
* @reviewers: [@ferittuncer*, @clesaege*, @satello*, @hbarcelos]
44
* @auditors: []
55
* @bounties: []
@@ -578,6 +578,20 @@ contract Linguo is Arbitrable {
578578
}
579579
}
580580

581+
/** @dev Gets the deposit required for challenging the translation.
582+
* @param _taskID The ID of the task.
583+
* @return deposit The challengers's deposit.
584+
*/
585+
function getChallengeValue(uint _taskID) public view returns (uint deposit) {
586+
Task storage task = tasks[_taskID];
587+
if (now - task.lastInteraction > reviewTimeout || task.status != Status.AwaitingReview) {
588+
deposit = NOT_PAYABLE_VALUE;
589+
} else {
590+
uint arbitrationCost = arbitrator.arbitrationCost(arbitratorExtraData);
591+
deposit = arbitrationCost.addCap((challengeMultiplier.mulCap(task.requesterDeposit)) / MULTIPLIER_DIVISOR);
592+
}
593+
}
594+
581595
/** @dev Gets the current price of a specified task.
582596
* @param _taskID The ID of the task.
583597
* @return price The price of the task.

test/linguo.js

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,9 @@ contract('Linguo', function(accounts) {
412412
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
413413
await expectThrow(linguo.acceptTranslation(0))
414414

415-
const task = await linguo.tasks(0)
416-
const price = task[6].toNumber()
417415
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
418416
const challengerDeposit =
419-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
417+
(await linguo.getChallengeValue(0)).toNumber() + 1000
420418
await linguo.challengeTranslation(0, {
421419
from: challenger,
422420
value: challengerDeposit
@@ -436,10 +434,9 @@ contract('Linguo', function(accounts) {
436434
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
437435

438436
task = await linguo.tasks(0)
439-
const price = task[6].toNumber()
440437
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
441438
const challengerDeposit =
442-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
439+
(await linguo.getChallengeValue(0)).toNumber() + 1000
443440
const challengeTx = await linguo.challengeTranslation(0, {
444441
from: challenger,
445442
value: challengerDeposit
@@ -516,10 +513,9 @@ contract('Linguo', function(accounts) {
516513
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
517514

518515
task = await linguo.tasks(0)
519-
const price = task[6].toNumber()
520516
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
521517
const challengerDeposit =
522-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
518+
(await linguo.getChallengeValue(0)).toNumber() + 1000
523519
await linguo.challengeTranslation(0, {
524520
from: challenger,
525521
value: challengerDeposit
@@ -574,11 +570,9 @@ contract('Linguo', function(accounts) {
574570
})
575571
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
576572

577-
task = await linguo.tasks(0)
578-
const price = task[6].toNumber()
579573
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
580574
const challengerDeposit =
581-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
575+
(await linguo.getChallengeValue(0)).toNumber() + 1000
582576
await linguo.challengeTranslation(0, {
583577
from: challenger,
584578
value: challengerDeposit
@@ -633,10 +627,9 @@ contract('Linguo', function(accounts) {
633627
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
634628

635629
task = await linguo.tasks(0)
636-
const price = task[6].toNumber()
637630
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
638631
const challengerDeposit =
639-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
632+
(await linguo.getChallengeValue(0)).toNumber() + 1000
640633
await linguo.challengeTranslation(0, {
641634
from: challenger,
642635
value: challengerDeposit
@@ -687,11 +680,9 @@ contract('Linguo', function(accounts) {
687680
})
688681
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
689682

690-
const task = await linguo.tasks(0)
691-
const price = task[6].toNumber()
692683
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
693684
const challengerDeposit =
694-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
685+
(await linguo.getChallengeValue(0)).toNumber() + 1000
695686
await linguo.challengeTranslation(0, {
696687
from: challenger,
697688
value: challengerDeposit
@@ -805,11 +796,10 @@ contract('Linguo', function(accounts) {
805796
})
806797
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
807798

808-
const task = await linguo.tasks(0)
809-
const price = task[6].toNumber()
799+
// DEL: const task = await linguo.tasks(0)
810800
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
811801
const challengerDeposit =
812-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
802+
(await linguo.getChallengeValue(0)).toNumber() + 1000
813803
await linguo.challengeTranslation(0, {
814804
from: challenger,
815805
value: challengerDeposit
@@ -832,11 +822,10 @@ contract('Linguo', function(accounts) {
832822
})
833823
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
834824

835-
const task = await linguo.tasks(0)
836-
const price = task[6].toNumber()
825+
// DEL: const task = await linguo.tasks(0)
837826
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
838827
const challengerDeposit =
839-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
828+
(await linguo.getChallengeValue(0)).toNumber() + 1000
840829
await linguo.challengeTranslation(0, {
841830
from: challenger,
842831
value: challengerDeposit
@@ -862,10 +851,9 @@ contract('Linguo', function(accounts) {
862851
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
863852

864853
task = await linguo.tasks(0)
865-
const price = task[6].toNumber()
866854
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
867855
const challengerDeposit =
868-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
856+
(await linguo.getChallengeValue(0)).toNumber() + 1000
869857
await linguo.challengeTranslation(0, {
870858
from: challenger,
871859
value: challengerDeposit
@@ -926,12 +914,11 @@ contract('Linguo', function(accounts) {
926914
})
927915
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
928916

929-
const task = await linguo.tasks(0)
930-
const price = task[6].toNumber()
917+
// DEL: const task = await linguo.tasks(0)
931918

932919
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
933920
const challengerDeposit =
934-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
921+
(await linguo.getChallengeValue(0)).toNumber() + 1000
935922
await linguo.challengeTranslation(0, {
936923
from: challenger,
937924
value: challengerDeposit
@@ -1029,11 +1016,10 @@ contract('Linguo', function(accounts) {
10291016
})
10301017
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
10311018

1032-
const task = await linguo.tasks(0)
1033-
const price = task[6].toNumber()
1019+
// DEL: const task = await linguo.tasks(0)
10341020
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
10351021
const challengerDeposit =
1036-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
1022+
(await linguo.getChallengeValue(0)).toNumber() + 1000
10371023
await linguo.challengeTranslation(0, {
10381024
from: challenger,
10391025
value: challengerDeposit
@@ -1113,11 +1099,10 @@ contract('Linguo', function(accounts) {
11131099
})
11141100
await linguo.submitTranslation(0, 'ipfs:/X', { from: translator })
11151101

1116-
const task = await linguo.tasks(0)
1117-
const price = task[6].toNumber()
1102+
// DEL: const task = await linguo.tasks(0)
11181103
// add a small amount because javascript can have small deviations up to several hundreds when operating with large numbers
11191104
const challengerDeposit =
1120-
arbitrationFee + (challengeMultiplier * price) / MULTIPLIER_DIVISOR + 1000
1105+
(await linguo.getChallengeValue(0)).toNumber() + 1000
11211106
await linguo.challengeTranslation(0, {
11221107
from: challenger,
11231108
value: challengerDeposit

0 commit comments

Comments
 (0)