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

Commit 8aed71b

Browse files
authored
Introduce support for bridged assets (#323)
* Add asset bridging support to fills endpoints * Add bridge name to fill endpoint * Add bridge data to fills endpoint
1 parent 06c7da1 commit 8aed71b

File tree

9 files changed

+145
-2
lines changed

9 files changed

+145
-2
lines changed

src/app/routes/v1/fills.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,22 @@ const parseNumber = numberString => {
3030
return _.toNumber(numberString);
3131
};
3232

33+
const parseBoolean = booleanString => {
34+
if (booleanString === undefined) {
35+
return undefined;
36+
}
37+
38+
return booleanString === 'true';
39+
};
40+
3341
const createRouter = () => {
3442
const router = new Router({ prefix: '/fills' });
3543

3644
router.get(
3745
'/',
3846
pagination({ defaultLimit: 20, maxLimit: 50, maxPage: Infinity }),
3947
async ({ pagination: { limit, page }, request, response }, next) => {
40-
const { address, status, token } = request.query;
48+
const { address, bridgeAddress, status, token } = request.query;
4149
const relayerId = request.query.relayer;
4250
const query = request.query.q;
4351
const relayerLookupId = await getRelayerLookupId(relayerId);
@@ -49,6 +57,7 @@ const createRouter = () => {
4957
request.query.protocolVersion !== undefined
5058
? _.toNumber(request.query.protocolVersion)
5159
: undefined;
60+
const bridged = parseBoolean(request.query.bridged);
5261

5362
const minDate = moment().subtract(6, 'months');
5463

@@ -142,6 +151,8 @@ const createRouter = () => {
142151
const { docs, pages, total } = await searchFills(
143152
{
144153
address,
154+
bridgeAddress,
155+
bridged,
145156
dateFrom: dateFrom !== undefined ? dateFrom : minDate,
146157
dateTo,
147158
protocolVersion,

src/app/routes/v1/util/__snapshots__/transform-fill.test.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
exports[`transformFill should transform ERC20 asset 1`] = `
44
Object {
55
"amount": "0.275",
6+
"bridgeAddress": undefined,
7+
"bridgeName": undefined,
68
"price": Object {
79
"USD": 137.36999999999998,
810
},
@@ -18,6 +20,8 @@ Object {
1820
exports[`transformFill should transform ERC721 asset 1`] = `
1921
Object {
2022
"amount": "1",
23+
"bridgeAddress": undefined,
24+
"bridgeName": undefined,
2125
"price": Object {
2226
"USD": 37.77675,
2327
},
@@ -35,6 +39,8 @@ Object {
3539
"assets": Array [
3640
Object {
3741
"amount": "7.1373405",
42+
"bridgeAddress": undefined,
43+
"bridgeName": undefined,
3844
"price": Object {
3945
"USD": 224.42000000000002,
4046
},
@@ -47,6 +53,8 @@ Object {
4753
},
4854
Object {
4955
"amount": "300000",
56+
"bridgeAddress": undefined,
57+
"bridgeName": undefined,
5058
"price": Object {
5159
"USD": 0.0053392065167000005,
5260
},
@@ -96,6 +104,8 @@ Object {
96104
exports[`transformFill should transform V1 fill with unrecognised maker asset 1`] = `
97105
Object {
98106
"amount": undefined,
107+
"bridgeAddress": undefined,
108+
"bridgeName": undefined,
99109
"price": Object {
100110
"USD": 224.42000000000002,
101111
},
@@ -111,6 +121,8 @@ Object {
111121
exports[`transformFill should transform V1 fill with unrecognised taker asset 1`] = `
112122
Object {
113123
"amount": undefined,
124+
"bridgeAddress": undefined,
125+
"bridgeName": undefined,
114126
"price": Object {
115127
"USD": 0.0053392065167000005,
116128
},
@@ -128,6 +140,8 @@ Object {
128140
"assets": Array [
129141
Object {
130142
"amount": "1",
143+
"bridgeAddress": undefined,
144+
"bridgeName": undefined,
131145
"price": Object {
132146
"USD": 37.77675,
133147
},
@@ -140,6 +154,8 @@ Object {
140154
},
141155
Object {
142156
"amount": "0.275",
157+
"bridgeAddress": undefined,
158+
"bridgeName": undefined,
143159
"price": Object {
144160
"USD": 137.36999999999998,
145161
},

src/constants.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,44 @@ module.exports = {
103103
slug: 'veil',
104104
},
105105
},
106+
KNOWN_ASSET_BRIDGES: [
107+
{
108+
addresses: [
109+
'0x6a3b7c553d47c08651641ef00cb3befae97bf415', // V1
110+
'0x77c31eba23043b9a72d13470f3a3a311344d7438', // V2
111+
],
112+
name: 'Chai',
113+
},
114+
{
115+
addresses: [
116+
'0x96ddba19b69d6ea2549f6a12d005595167414744', // V1
117+
'0x55dc8f21d20d4c6ed3c82916a438a413ca68e335', // V2
118+
],
119+
name: 'dYdX',
120+
},
121+
{
122+
addresses: [
123+
'0x0ac2d6f5f5afc669d3ca38f830dad2b4f238ad3f', // V1
124+
'0x1c36b06fc0d9354a96cf155b861b141ed10c3312', // V2
125+
'0xe97ea901d034ba2e018155264f77c417ce7717f9', // V3
126+
],
127+
name: 'Eth2Dai',
128+
},
129+
{
130+
addresses: [
131+
'0xe64660275c40c16c491c2dabf50afaded20f858f', // V1
132+
'0x7253a80c1d3a3175283bad9ed04b2cecad0fe0d3', // V2
133+
'0xf342f3a80fdc9b48713d58fe97e17f5cc764ee62', // V3
134+
],
135+
name: 'Kyber',
136+
},
137+
{
138+
addresses: [
139+
'0xa6baaed2053058a3c8f11e0c7a9716304454b09e', // V1
140+
'0xb0dc61047847732a013ce27341228228a38655a0', // V2
141+
'0x533344cfdf2a3e911e2cf4c6f5ed08e791f5355f', // V3
142+
],
143+
name: 'Uniswap',
144+
},
145+
],
106146
};

src/constants.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const _ = require('lodash');
2+
const { KNOWN_ASSET_BRIDGES } = require('./constants');
3+
4+
it('KNOWN_ASSET_BRIDGES should not contain any duplicate addresses', () => {
5+
const addresses = _.flatMap(KNOWN_ASSET_BRIDGES, 'addresses');
6+
const uniqueAddresses = _.uniq(addresses);
7+
8+
expect(addresses).toEqual(uniqueAddresses);
9+
});

src/fills/get-asset-bridge-name.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { KNOWN_ASSET_BRIDGES } = require('../constants');
2+
3+
const getAssetBridgeName = address => {
4+
if (address === undefined) {
5+
return undefined;
6+
}
7+
8+
const matchingBridge = KNOWN_ASSET_BRIDGES.find(bridge =>
9+
bridge.addresses.includes(address),
10+
);
11+
12+
return matchingBridge === undefined ? undefined : matchingBridge.name;
13+
};
14+
15+
module.exports = getAssetBridgeName;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const getAssetBridgeName = require('./get-asset-bridge-name');
2+
3+
it('should return undefined when address is undefined', () => {
4+
const name = getAssetBridgeName();
5+
6+
expect(name).toBeUndefined();
7+
});
8+
9+
it('should return Eth2Dai when address is 0xe97ea901d034ba2e018155264f77c417ce7717f9', () => {
10+
const name = getAssetBridgeName('0xe97ea901d034ba2e018155264f77c417ce7717f9');
11+
12+
expect(name).toBe('Eth2Dai');
13+
});
14+
15+
it('should return Kyber when address is 0xf342f3a80fdc9b48713d58fe97e17f5cc764ee62', () => {
16+
const name = getAssetBridgeName('0xf342f3a80fdc9b48713d58fe97e17f5cc764ee62');
17+
18+
expect(name).toBe('Kyber');
19+
});
20+
21+
it('should return Kyber when address is 0x7253a80c1d3a3175283bad9ed04b2cecad0fe0d3', () => {
22+
const name = getAssetBridgeName('0x7253a80c1d3a3175283bad9ed04b2cecad0fe0d3');
23+
24+
expect(name).toBe('Kyber');
25+
});

src/fills/get-assets-for-fill.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ const _ = require('lodash');
33
const formatTokenAmount = require('../tokens/format-token-amount');
44
const formatTokenType = require('../tokens/format-token-type');
55
const formatTraderType = require('../traders/format-trader-type');
6+
const getAssetBridgeName = require('./get-asset-bridge-name');
67

78
const transformAsset = (tokens, asset) => {
89
const token = tokens[asset.tokenAddress];
910
const price = _.get(asset.price, 'USD');
1011

1112
return {
1213
amount: formatTokenAmount(asset.amount, token),
14+
bridgeAddress: asset.bridgeAddress,
15+
bridgeName: getAssetBridgeName(asset.bridgeAddress),
1316
price: _.isNumber(price) ? { USD: price } : undefined,
1417
tokenAddress: asset.tokenAddress,
1518
tokenId: asset.tokenId,

src/fills/search-fills.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const Fill = require('../model/fill');
55

66
const buildQuery = ({
77
address,
8+
bridgeAddress,
9+
bridged,
810
dateFrom,
911
dateTo,
1012
protocolVersion,
@@ -16,6 +18,7 @@ const buildQuery = ({
1618
valueTo,
1719
}) => {
1820
const filters = [];
21+
const exclusions = [];
1922

2023
if (dateFrom !== undefined || dateTo !== undefined) {
2124
filters.push({
@@ -82,10 +85,30 @@ const buildQuery = ({
8285
filters.push({ term: { status } });
8386
}
8487

88+
if (_.isString(bridgeAddress)) {
89+
filters.push({ match_phrase: { 'assets.bridgeAddress': bridgeAddress } });
90+
}
91+
92+
if (_.isBoolean(bridged)) {
93+
if (bridged) {
94+
filters.push({
95+
exists: {
96+
field: 'assets.bridgeAddress',
97+
},
98+
});
99+
} else {
100+
exclusions.push({
101+
exists: {
102+
field: 'assets.bridgeAddress',
103+
},
104+
});
105+
}
106+
}
107+
85108
return filters.length === 0
86109
? undefined
87110
: {
88-
bool: { filter: filters },
111+
bool: { filter: filters, must_not: exclusions },
89112
};
90113
};
91114

src/model/fill.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const schema = Schema({
99
{
1010
actor: Number,
1111
amount: Number,
12+
bridgeAddress: String,
1213
price: {
1314
USD: Number,
1415
},

0 commit comments

Comments
 (0)