Skip to content

Commit aa4a195

Browse files
authored
Merge pull request #222 from rsksmart/2.0.0-rebased
Check if the address of the event is the original address
2 parents f7de821 + 3e04c14 commit aa4a195

File tree

7 files changed

+51
-24
lines changed

7 files changed

+51
-24
lines changed

bridge/migrations/21_deploy_allowTokens.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -52,49 +52,49 @@ module.exports = async (deployer, networkName, accounts) => {
5252
function tokensTypesMainnet() {
5353
return [
5454
{ description: 'BTC', limits: {
55-
min:toWei('0.001'),
55+
min:toWei('0.0001'),
5656
max:toWei('25'),
5757
daily:toWei('100'),
5858
mediumAmount:toWei('0.1'),
5959
largeAmount:toWei('1') }
6060
},
6161
{ description: 'ETH', limits: {
62-
min:toWei('0.05'),
62+
min:toWei('0.005'),
6363
max:toWei('750'),
6464
daily:toWei('3000'),
6565
mediumAmount:toWei('3'),
6666
largeAmount:toWei('30') }
6767
},
6868
{ description: '<1000usd', limits: {
69-
min:toWei('0.1'),
69+
min:toWei('0.01'),
7070
max:toWei('2500'),
7171
daily:toWei('5000'),
7272
mediumAmount:toWei('10'),
7373
largeAmount:toWei('100') }
7474
},
7575
{ description: '<100usd', limits: {
76-
min:toWei('1'),
76+
min:toWei('0.1'),
7777
max:toWei('25000'),
7878
daily:toWei('50000'),
7979
mediumAmount:toWei('100'),
8080
largeAmount:toWei('1000') }
8181
},
8282
{ description: '=1usd', limits: {
83-
min:toWei('100'),
83+
min:toWei('10'),
8484
max:toWei('2500000'),
8585
daily:toWei('5000000'),
8686
mediumAmount:toWei('10000'),
8787
largeAmount:toWei('100000') }
8888
},
8989
{ description: '<1usd', limits: {
90-
min:toWei('10000'),
90+
min:toWei('1000'),
9191
max:toWei('250000000'),
9292
daily:toWei('500000000'),
9393
mediumAmount:toWei('1000000'),
9494
largeAmount:toWei('10000000') }
9595
},
9696
{ description: '<1cent', limits: {
97-
min:toWei('1000000'),
97+
min:toWei('100000'),
9898
max:toWei('25000000000'),
9999
daily:toWei('50000000000'),
100100
mediumAmount:toWei('100000000'),

federator/integrationTest/integrationTest.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ async function transfer(originFederators, destinationFederators, config, origin,
508508
logger.info(`${destination} token balance`, balance);
509509
let destinationInitialUserBalance = balance;
510510

511-
// Cross AnotherToken (type id 0) Small Amount < toWei('0.1')
512-
const userSmallAmount = originWeb3.utils.toWei('0.0516');
513-
const userMediumAmount = originWeb3.utils.toWei('0.109');
511+
// Cross AnotherToken (type id 0) Small Amount < toWei('0.01')
512+
const userSmallAmount = originWeb3.utils.toWei('0.0056');
513+
const userMediumAmount = originWeb3.utils.toWei('0.019'); // < toWei('0.1')
514514
const userLargeAmount = originWeb3.utils.toWei('1.32');
515515
const userAppoveTotalAmount = originWeb3.utils.toWei('10');
516516

@@ -520,18 +520,18 @@ async function transfer(originFederators, destinationFederators, config, origin,
520520
await methodCall.call({from: userAddress});
521521
await transactionSender.sendTransaction(anotherTokenAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
522522

523-
// Cross AnotherToken (type id 0) Small Amount < toWei('0.1')
523+
// Cross AnotherToken (type id 0) Small Amount < toWei('0.01')
524524
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userSmallAmount);
525525
await methodCall.call({from: userAddress});
526526
const smallAmountReceipt = await transactionSender.sendTransaction(originBridgeAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
527527

528-
// Cross AnotherToken (type id 0) Medium Amount >= toWei('0.1') && < toWei('1')
528+
// Cross AnotherToken (type id 0) Medium Amount >= toWei('0.01') && < toWei('0.1')
529529
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userMediumAmount);
530530
await methodCall.call({from: userAddress});
531531
const mediumAmountReceipt = await transactionSender.sendTransaction(originBridgeAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
532532

533-
// Cross AnotherToken (type id 0) Large Amount >= toWei('1')
534-
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userLargeAmount)
533+
// Cross AnotherToken (type id 0) Large Amount >= toWei('0.1')
534+
methodCall = bridgeContract.methods.receiveTokensTo(anotherTokenAddress, userAddress, userLargeAmount)
535535
await methodCall.call({from: userAddress});
536536
const largeAmountReceipt = await transactionSender.sendTransaction(originBridgeAddress, methodCall.encodeABI(), 0, userPrivateKey, true);
537537

federator/src/contracts/AllowTokensFactory.js

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ module.exports = class AllowTokensFactory {
4040
try {
4141
const bridgeContract = new this.mainWeb3.eth.Contract(abiBridge, this.config.mainchain.bridge);
4242
const allowTokensAddress = await utils.retry3Times(bridgeContract.methods.allowTokens().call);
43-
4443
return await this.createInstance(
4544
this.mainWeb3,
4645
allowTokensAddress

federator/src/contracts/IAllowTokensV0.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = class IAllowTokensV0 {
3030

3131
async getLimits(tokenAddress) {
3232
return {
33+
allowed: true,
3334
mediumAmount: -1,
3435
largeAmount: 0,
3536
};

federator/src/contracts/IAllowTokensV1.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ module.exports = class IAllowTokensV1 {
5353
if(!result) {
5454
const infoAndLimits = await this.allowTokensContract.methods.getInfoAndLimits(tokenAddress).call();
5555
result = {
56+
allowed: infoAndLimits.info.allowed,
5657
mediumAmount: infoAndLimits.limit.mediumAmount,
5758
largeAmount: infoAndLimits.limit.largeAmount,
5859
};
59-
this.mapTokenInfoAndLimits[tokenAddress] = result;
60+
if (result.allowed) {
61+
this.mapTokenInfoAndLimits[tokenAddress] = result;
62+
}
6063
}
6164
return result;
6265
} catch(err) {

federator/src/contracts/IBridge.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ module.exports = class IBridge {
2929
getVersion() {
3030
return this.bridgeContract.methods.version();
3131
}
32+
33+
getMappedToken(originalTokenAddress) {
34+
return this.bridgeContract.methods.mappedTokens(originalTokenAddress);
35+
}
3236
}

federator/src/lib/Federator.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ module.exports = class Federator {
141141

142142
const isMember = await utils.retry3Times(fedContract.isMember(from).call);
143143
if (!isMember) throw new Error(`This Federator addr:${from} is not part of the federation`);
144-
144+
145145
const {
146146
mediumAmountConfirmations,
147147
largeAmountConfirmations
@@ -168,17 +168,37 @@ module.exports = class Federator {
168168
_typeId: typeId
169169
} = log.returnValues;
170170

171-
const {
171+
const mainBridge = await this.bridgeFactory.getMainBridgeContract();
172+
const sideTokenAddress = await utils.retry3Times(mainBridge.getMappedToken(tokenAddress).call);
173+
let allowed,
172174
mediumAmount,
173-
largeAmount
174-
} = await allowTokens.getLimits(tokenAddress);
175-
175+
largeAmount
176+
if (sideTokenAddress == utils.zeroAddress) {
177+
({
178+
allowed,
179+
mediumAmount,
180+
largeAmount
181+
} = await allowTokens.getLimits(tokenAddress));
182+
if (!allowed) {
183+
throw new Error(`Original Token not allowed nor side token Tx:${transactionHash} originalTokenAddress:${tokenAddress}`);
184+
}
185+
} else {
186+
({
187+
allowed,
188+
mediumAmount,
189+
largeAmount
190+
} = await allowTokens.getLimits(sideTokenAddress));
191+
if (!allowed) {
192+
this.logger.error(`Side token:${sideTokenAddress} needs to be allowed Tx:${transactionHash} originalTokenAddress:${tokenAddress}`);
193+
}
194+
}
195+
176196
const BN = this.mainWeb3.utils.BN;
177197
const mediumAmountBN = new BN(mediumAmount);
178198
const largeAmountBN = new BN(largeAmount);
179199
const amountBN = new BN(amount);
180200

181-
if(mediumAndSmall) {
201+
if (mediumAndSmall) {
182202
// At this point we're processing blocks newer than largeAmountConfirmations
183203
// and older than smallAmountConfirmations
184204
if(amountBN.gte(largeAmountBN)) {
@@ -214,7 +234,7 @@ module.exports = class Federator {
214234

215235
let wasProcessed = await utils.retry3Times(fedContract.transactionWasProcessed(transactionId).call);
216236
if (!wasProcessed) {
217-
let hasVoted = await utils.retry3Times(fedContract.hasVoted(transactionId).call);
237+
let hasVoted = await fedContract.hasVoted(transactionId).call({ from });
218238
if(!hasVoted) {
219239
this.logger.info(`Voting tx: ${log.transactionHash} block: ${log.blockHash} originalTokenAddress: ${tokenAddress}`);
220240
await this._voteTransaction(
@@ -292,7 +312,7 @@ module.exports = class Federator {
292312
}
293313

294314
const receipt = await this.transactionSender.sendTransaction(fedContract.getAddress(), txData, 0, this.config.privateKey);
295-
315+
296316
if(receipt.status == false) {
297317
fs.writeFileSync(
298318
this.revertedTxnsPath,

0 commit comments

Comments
 (0)