Skip to content

Commit dccd39b

Browse files
Merge pull request #2 from vacuumlabs/autonom-integration
setup for autonom local testing
2 parents d19f879 + 18587b8 commit dccd39b

File tree

6 files changed

+266
-178
lines changed

6 files changed

+266
-178
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "rollup -c",
8-
"dev": "rollup -c -w",
8+
"dev": "node src/utils/autonom/fetchAddresses.js && rollup -c -w",
99
"start": "sirv build --single",
1010
"deploy-ipfs": "npm run build && npx ipfs-deploy build"
1111
},

src/lib/constants.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CONTRACT_ADDRESSES } from '../utils/autonom/output/l2'
2+
13
export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
24

35
export const HISTORY_COUNT = 10;
@@ -70,35 +72,37 @@ export const ABIS = {
7072
// Contract addresses are pulled from router contract
7173

7274
export const CHAINDATA = {
73-
31337: {
75+
31338: {
7476
label: 'localhost',
75-
router: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
76-
explorer: 'http://localhost:8545',
77+
router: CONTRACT_ADDRESSES.dexes.cap.router,
78+
explorer: 'http://localhost:8555',
7779
currencies: {
7880
weth: ADDRESS_ZERO,
79-
usdc: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707'
81+
usdc: CONTRACT_ADDRESSES.dexes.cap.token.usdc
8082
},
8183
poolInception: {
8284
weth: 1637154307000,
8385
usdc: 1637154307000,
8486
cap: 1637154307000
8587
},
86-
cap: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9'
87-
},
88-
42161: {
89-
label: 'Arbitrum',
90-
router: '0x5ABFF8F8D5b13253dCAB1e427Fdb3305cA620119',
91-
explorer: 'https://arbiscan.io',
92-
rpc: 'https://arb1.arbitrum.io/rpc', // for walletconnect
93-
currencies: {
94-
weth: ADDRESS_ZERO,
95-
usdc: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'
96-
},
97-
poolInception: {
98-
weth: 1637154307000,
99-
usdc: 1637154307000,
100-
cap: 1637154307000
101-
},
102-
cap: '0x031d35296154279DC1984dCD93E392b1f946737b'
88+
cap: CONTRACT_ADDRESSES.dexes.cap.token.cap
10389
}
104-
}
90+
// 42161: {
91+
// label: 'Arbitrum',
92+
// router: '0x5ABFF8F8D5b13253dCAB1e427Fdb3305cA620119',
93+
// explorer: 'https://arbiscan.io',
94+
// rpc: 'https://arb1.arbitrum.io/rpc', // for walletconnect
95+
// currencies: {
96+
// weth: ADDRESS_ZERO,
97+
// usdc: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'
98+
// },
99+
// poolInception: {
100+
// weth: 1637154307000,
101+
// usdc: 1637154307000,
102+
// cap: 1637154307000
103+
// },
104+
// cap: '0x031d35296154279DC1984dCD93E392b1f946737b'
105+
// }
106+
}
107+
108+
console.log('chain data: ', CHAINDATA);

src/lib/graph.js

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export async function getUserPositions() {
163163
const filter = contract.filters.PositionUpdated(null, _address);
164164
const _events = await contract.queryFilter(filter, -100);
165165

166-
// console.log('_events', _events);
166+
console.log('_events', _events);
167167

168168
let _details = {};
169169
for (const ev of _events) {
@@ -197,55 +197,55 @@ export async function getUserPositions() {
197197

198198
// graph
199199

200-
const response = await fetch(graph_url, {
201-
method: 'POST',
202-
headers: {
203-
'Content-Type': 'application/json',
204-
},
205-
body: JSON.stringify({
206-
query: `
207-
query {
208-
positions(
209-
orderBy: createdAtTimestamp,
210-
orderDirection: desc,
211-
first:50,
212-
where: {user: "${_address}"}
213-
) {
214-
id,
215-
productId,
216-
currency,
217-
margin,
218-
fee,
219-
size,
220-
leverage,
221-
price,
222-
isLong,
223-
createdAtTimestamp
224-
}
225-
}
226-
`
227-
})
228-
});
229-
230-
const json = await response.json();
231-
232-
let _positions = json.data && json.data.positions;
233-
234-
let _keys = _positions.map((e) => {return e.id;});
235-
236-
let _raw_positions = await getPositions(_keys);
237-
238-
// make sure graph positions actually exist in the contract for times the graph hasn't yet updated
239-
let actual_positions = [];
240-
let i = 0;
241-
for (const p of _positions) {
242-
if (_raw_positions[i] && _raw_positions[i].size && _raw_positions[i].size.toString() * 1 > 0) {
243-
actual_positions.push(p);
244-
}
245-
i++;
246-
}
247-
248-
let graph_positions = formatPositions(actual_positions);
200+
// const response = await fetch(graph_url, {
201+
// method: 'POST',
202+
// headers: {
203+
// 'Content-Type': 'application/json',
204+
// },
205+
// body: JSON.stringify({
206+
// query: `
207+
// query {
208+
// positions(
209+
// orderBy: createdAtTimestamp,
210+
// orderDirection: desc,
211+
// first:50,
212+
// where: {user: "${_address}"}
213+
// ) {
214+
// id,
215+
// productId,
216+
// currency,
217+
// margin,
218+
// fee,
219+
// size,
220+
// leverage,
221+
// price,
222+
// isLong,
223+
// createdAtTimestamp
224+
// }
225+
// }
226+
// `
227+
// })
228+
// });
229+
230+
// const json = await response.json();
231+
232+
// let _positions = json.data && json.data.positions;
233+
234+
// let _keys = _positions.map((e) => {return e.id;});
235+
236+
// let _raw_positions = await getPositions(_keys);
237+
238+
// // make sure graph positions actually exist in the contract for times the graph hasn't yet updated
239+
// let actual_positions = [];
240+
// let i = 0;
241+
// for (const p of _positions) {
242+
// if (_raw_positions[i] && _raw_positions[i].size && _raw_positions[i].size.toString() * 1 > 0) {
243+
// actual_positions.push(p);
244+
// }
245+
// i++;
246+
// }
247+
248+
// let graph_positions = formatPositions(actual_positions);
249249

250250
// console.log('graph_positions', graph_positions);
251251

@@ -257,12 +257,12 @@ export async function getUserPositions() {
257257
added_key[item.key] = true;
258258
}
259259
}
260-
for (const item of graph_positions) {
261-
if (!added_key[item.key]) {
262-
unique_positions.push(item);
263-
added_key[item.key] = true;
264-
}
265-
}
260+
// for (const item of graph_positions) {
261+
// if (!added_key[item.key]) {
262+
// unique_positions.push(item);
263+
// added_key[item.key] = true;
264+
// }
265+
// }
266266

267267
positions.set(unique_positions);
268268
setActiveProducts();

0 commit comments

Comments
 (0)