Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit 08026e6

Browse files
authored
Fix an edge case in the attribution resolver (#466)
* Fix edge case in attribution resolver * Remove redundant starbit taker * Remove additional taker reference
1 parent 3e55629 commit 08026e6

5 files changed

Lines changed: 46 additions & 18 deletions

File tree

src/attributions/definitions/star-bit.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
{
1313
"type": "relayer",
1414
"feeRecipientAddress": "0xc370d2a5920344aa6b7d8d11250e3e861434cbdd"
15-
},
16-
{
17-
"type": "relayer",
18-
"takerAddress": "0x0681e844593a051e2882ec897ecd5444efe19ff2"
1915
}
2016
],
2117
"categories": []

src/attributions/resolve-attributions.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,30 @@ const resolveAttributions = metadata => {
4444
mapping.senderAddress === undefined),
4545
);
4646

47+
const attributions = _.uniqWith(
48+
matches.map(match => {
49+
const definition = entityDefinitions.find(d =>
50+
d.mappings.includes(match),
51+
);
52+
53+
return {
54+
id: definition.id,
55+
type: match.type,
56+
};
57+
}),
58+
_.isEqual,
59+
);
60+
4761
// TODO: Make this guard dynamic based on types constant
48-
if (matches.filter(m => m.type === 'relayer').length > 1) {
62+
if (attributions.filter(a => a.type === 'relayer').length > 1) {
4963
throw getErrorForDuplicate('relayer', metadata);
5064
}
5165

52-
if (matches.filter(m => m.type === 'consumer').length > 1) {
66+
if (attributions.filter(a => a.type === 'consumer').length > 1) {
5367
throw getErrorForDuplicate('consumer', metadata);
5468
}
5569

56-
return matches.map(match => {
57-
const definition = entityDefinitions.find(d => d.mappings.includes(match));
58-
59-
return {
60-
id: definition.id,
61-
type: match.type,
62-
};
63-
});
70+
return attributions;
6471
};
6572

6673
module.exports = resolveAttributions;

src/attributions/resolve-attributions.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ describe('attributions/resolveAttributions', () => {
7878
},
7979
],
8080
},
81+
{
82+
id: 'a5808078-d297-4fbd-a818-dccd8a5438ed',
83+
name: 'STAR BIT',
84+
mappings: [
85+
{
86+
type: 'relayer',
87+
feeRecipientAddress: '0x8124071f810d533ff63de61d0c98db99eeb99d64',
88+
},
89+
{
90+
type: 'relayer',
91+
feeRecipientAddress: '0xc370d2a5920344aa6b7d8d11250e3e861434cbdd',
92+
},
93+
{
94+
type: 'relayer',
95+
takerAddress: '0x0681e844593a051e2882ec897ecd5444efe19ff2',
96+
},
97+
],
98+
},
8199
]);
82100
});
83101

@@ -161,6 +179,17 @@ describe('attributions/resolveAttributions', () => {
161179
]);
162180
});
163181

182+
it('should resolve relayer when multiple matches exist', () => {
183+
const attributions = resolveAttributions({
184+
feeRecipientAddress: '0x8124071f810d533ff63de61d0c98db99eeb99d64',
185+
takerAddress: '0x0681e844593a051e2882ec897ecd5444efe19ff2',
186+
});
187+
188+
expect(attributions).toEqual([
189+
{ id: 'a5808078-d297-4fbd-a818-dccd8a5438ed', type: 'relayer' },
190+
]);
191+
});
192+
164193
it('should throw an error when multiple matching relayers found', () => {
165194
expect(() =>
166195
resolveAttributions({

src/relayers/__snapshots__/get-all-relayers.test.js.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,6 @@ Object {
301301
"name": "STAR BIT",
302302
"orderMatcher": true,
303303
"slug": "star-bit",
304-
"takerAddresses": Array [
305-
"0x0681e844593a051e2882ec897ecd5444efe19ff2",
306-
],
307304
"url": "https://www.starbitex.com",
308305
},
309306
"switchDex": Object {

src/relayers/relayer-registry.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ module.exports = {
8181
name: 'STAR BIT',
8282
orderMatcher: true,
8383
slug: 'star-bit',
84-
takerAddresses: ['0x0681e844593a051e2882ec897ecd5444efe19ff2'],
8584
url: 'https://www.starbitex.com',
8685
},
8786
tokenJar: {

0 commit comments

Comments
 (0)