Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update circles-core dependency and use new pathfinder service #630

Merged
merged 14 commits into from
Apr 24, 2023
Merged
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ ETHEREUM_NODE_WS=ws://localhost:8545
# Service Endpoints
API_SERVICE_EXTERNAL=http://api.circles.local
GRAPH_NODE_EXTERNAL=http://graph.circles.local
PATHFINDER_SERVICE_ENDPOINT=http://localhost:8081
RELAY_SERVICE_EXTERNAL=http://relay.circles.local

# Database Endpoints
DATABASE_SOURCE=graph

# Pathfinder Type 'cli' or 'server'.
# The core library can get the transfer stpes from a pathfinder service ('server'), or from the circles-api that uses the cli tool ('cli')
llunaCreixent marked this conversation as resolved.
Show resolved Hide resolved
PATHFINDER_TYPE=server

# Smart Contract addresses of 1.3.0 version
HUB_ADDRESS=0xCfEB869F69431e42cdB54A4F4f105C19C080A601
PROXY_FACTORY_ADDRESS=0x9b1f7F645351AF3631a656421eD2e40f2802E6c0
Expand Down
2,233 changes: 1,336 additions & 897 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"test:watch": "npm run test -- --watch"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/eslint-parser": "^7.19.1",
"@babel/core": "^7.21.3",
"@babel/eslint-parser": "^7.21.3",
"@babel/node": "^7.20.7",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@svgr/webpack": "^5.5.0",
Expand All @@ -41,7 +41,7 @@
"css-loader": "^5.2.7",
"dotenv": "^10.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-prettier": "^8.8.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^3.4.1",
Expand All @@ -50,24 +50,24 @@
"file-loader": "^6.2.0",
"html-webpack-plugin": "^4.5.2",
"jest": "^27.5.1",
"prettier": "^2.8.3",
"prettier": "^2.8.7",
"rimraf": "^3.0.2",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^4.2.3",
"truffle": "^5.7.4",
"truffle": "^5.8.1",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.3"
},
"dependencies": {
"@circles/core": "^3.2.1",
"@circles/core": "^4.0.1",
"@circles/timecircles": "^1.0.6",
"@material-ui/core": "^4.12.4",
"@material-ui/lab": "^4.0.0-alpha.61",
"@sentry/browser": "^6.19.7",
"@sentry/tracing": "^6.19.7",
"@zxing/library": "^0.19.2",
"bip39": "^3.0.4",
"bip39": "^3.1.0",
"clipboard": "^2.0.11",
"clsx": "^1.2.1",
"compress.js": "^1.2.2",
Expand All @@ -79,7 +79,7 @@
"mime": "^2.6.0",
"notistack": "^1.0.10",
"qrcode": "^1.5.1",
"qs": "^6.11.0",
"qs": "^6.11.1",
"react": "^17.0.2",
"react-div-100vh": "^0.7.0",
"react-dom": "^17.0.2",
Expand All @@ -90,6 +90,6 @@
"redux-create-action-types": "^2.1.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.4.2",
"web3": "^1.8.2"
"web3": "^1.9.0"
}
}
8 changes: 2 additions & 6 deletions src/components/ButtonWobbly.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import clsx from 'clsx';
import PropTypes from 'prop-types';
import React from 'react';

import {
IconWobblyCircle,
iconSelector,
} from '~/styles/icons';
import { IconWobblyCircle, iconSelector } from '~/styles/icons';

const useStyles = makeStyles((theme) => ({
buttonWobbly: {
Expand Down Expand Up @@ -59,7 +56,6 @@ const ButtonWobbly = ({
isReady,
isPending,
onClick,
to,
}) => {
const classes = useStyles();
const IconElement = iconSelector(icon);
Expand Down Expand Up @@ -91,8 +87,8 @@ ButtonWobbly.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
icon: PropTypes.function,
isReady: PropTypes.bool,
isPending: PropTypes.bool,
isReady: PropTypes.bool,
onClick: PropTypes.function,
to: PropTypes.string,
};
Expand Down
2 changes: 2 additions & 0 deletions src/services/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const core = new CirclesCore(web3, {
fallbackHandlerAddress: process.env.SAFE_DEFAULT_CALLBACK_HANDLER,
graphNodeEndpoint: process.env.GRAPH_NODE_EXTERNAL,
hubAddress: process.env.HUB_ADDRESS,
pathfinderServiceEndpoint: process.env.PATHFINDER_SERVICE_ENDPOINT,
pathfinderType: process.env.PATHFINDER_TYPE,
proxyFactoryAddress: process.env.PROXY_FACTORY_ADDRESS,
relayServiceEndpoint: process.env.RELAY_SERVICE_EXTERNAL,
safeMasterAddress: process.env.SAFE_ADDRESS,
Expand Down
22 changes: 13 additions & 9 deletions src/store/token/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,19 @@ export function transfer(
const value = new web3.utils.BN(
core.utils.toFreckles(tcToCrc(Date.now(), Number(amount))),
);
const txHash = await loopTransfer(
from,
to,
value,
paymentNote,
hops,
attempts,
);

let txHash;
if (process.env.PATHFINDER_TYPE === 'cli') {
txHash = await loopTransfer(
from,
to,
value,
paymentNote,
hops,
attempts,
);
} else {
txHash = await core.token.transfer(from, to, value, paymentNote);
}
dispatch(
addPendingActivity({
txHash,
Expand Down
28 changes: 20 additions & 8 deletions src/utils/findPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LARGE_AMOUNT = new web3.utils.BN(
web3.utils.toWei('1000000000000000', 'ether'),
);

// Recursive helper function for findMaxFlow
// Recursive helper function for findMaxFlow recursively reducing number of hops
async function loopFindMaxFlow(
from,
to,
Expand Down Expand Up @@ -60,14 +60,26 @@ async function loopFindMaxFlow(
* @returns nothing. Updates MaxFlow state in Freckles.
*/
export async function findMaxFlow(from, to, setMaxFlow) {
// First attempting via API
// First attempting via API.
// The API parameters depends on the Pathfinder Type in use:
// The 'cli' uses hops, but this option is not available in the 'server'.
// Therefore we set the attemptsLeft and the hops option will be ignored.
try {
const response = await loopFindMaxFlow(
from,
to,
PATHFINDER_HOPS_DEFAULT,
PATHFINDER_HOPS_DEFAULT,
);
let response;
if (process.env.PATHFINDER_TYPE === 'cli') {
response = await loopFindMaxFlow(
from,
to,
PATHFINDER_HOPS_DEFAULT,
PATHFINDER_HOPS_DEFAULT,
);
} else {
response = await core.token.findTransitiveTransfer(
from,
to,
LARGE_AMOUNT,
);
}

// Throw an error when no path was found, we should try again with
// checking direct sends as the API might not be in sync yet
Expand Down
2 changes: 2 additions & 0 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const CONFIG_KEYS = [
'GRAPH_NODE_EXTERNAL',
'HUB_ADDRESS',
'NODE_ENV',
'PATHFINDER_SERVICE_ENDPOINT',
'PATHFINDER_TYPE',
'PROXY_FACTORY_ADDRESS',
'RELAY_SERVICE_EXTERNAL',
'SAFE_ADDRESS',
Expand Down