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

Stop using the relayer #131

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

// Maximum Wei value
export const MAX_WEI = '99999999999999999999999';

// txServiceUrl: 'https://safe-transaction.xdai.gnosis.io'

export const TX_SERVICE_URL = 'https://safe-transaction.xdai.gnosis.io';
39 changes: 39 additions & 0 deletions src/common/createContractsNetworks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getAbis } from '~/common/getContracts';

/**
* Create Contract Networks object
*
* @access private
*
* @param {string} chainId - Safe owner address
* @param {Object} options - contract addresses
*
* @return {Object} - Contract Network configuration
*/

export function getContractNetworks(chainId, options) {
const {
safeMasterAddress,
proxyFactoryAddress,
multiSendAddress,
multiSendCallAddress,
} = options;
const {
safeMasterCopyAbi,
safeProxyFactoryAbi,
multiSendAbi,
multiSendCallOnlyAbi,
} = getAbis();
return {
[chainId]: {
multiSendAddress: multiSendAddress,
multiSendAbi: multiSendAbi,
multiSendCallOnlyAddress: multiSendCallAddress,
multiSendCallOnlyAbi: multiSendCallOnlyAbi,
safeMasterCopyAddress: safeMasterAddress,
safeMasterCopyAbi: safeMasterCopyAbi,
safeProxyFactoryAddress: proxyFactoryAddress,
safeProxyFactoryAbi: safeProxyFactoryAbi,
},
};
}
28 changes: 26 additions & 2 deletions src/common/getContracts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import GnosisSafeContract from '@circles/safe-contracts/build/contracts/GnosisSafe.json';
import GnosisSafeContract from '@gnosis.pm/safe-contracts/build/artifacts/contracts/GnosisSafe.sol/GnosisSafe.json';
import ProxyFactoryContract from '@gnosis.pm/safe-contracts/build/artifacts/contracts/proxies/GnosisSafeProxyFactory.sol/GnosisSafeProxyFactory.json';
import MultiSendContract from '@gnosis.pm/safe-contracts/build/artifacts/contracts/libraries/MultiSend.sol/MultiSend.json';
import MultiSendCallOnlyContract from '@gnosis.pm/safe-contracts/build/artifacts/contracts/libraries/MultiSendCallOnly.sol/MultiSendCallOnly.json';
import HubContract from '@circles/circles-contracts/build/contracts/Hub.json';
import ProxyFactoryContract from '@circles/safe-contracts/build/contracts/ProxyFactory.json';
import TokenContract from '@circles/circles-contracts/build/contracts/Token.json';

/**
Expand Down Expand Up @@ -78,3 +80,25 @@ export default function getContracts(web3, options) {
safeMaster,
};
}

/**
* Helper method to get abis from deployed contracts
*
* @access private
*
* @return {Object} - contract instances
*/

export function getAbis() {
const safeMasterCopyAbi = GnosisSafeContract.abi;
const safeProxyFactoryAbi = ProxyFactoryContract.abi;
const multiSendAbi = MultiSendContract.abi;
const multiSendCallOnlyAbi = MultiSendCallOnlyContract.abi;

return {
safeMasterCopyAbi,
safeProxyFactoryAbi,
multiSendAbi,
multiSendCallOnlyAbi,
};
}
45 changes: 45 additions & 0 deletions src/common_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Web3 = require('web3');

// import Web3Adapter from '@gnosis.pm/safe-web3-lib';
const Web3Adapter = require('@gnosis.pm/safe-web3-lib').default;
const { SafeFactory } = require('@gnosis.pm/safe-core-sdk');
const { default: create } = require('keccak');

const web3 = new Web3.providers.HttpProvider('http://localhost:8545');
const safeOwner = '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB';

const owners = '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB';
const threshold = 1;
const saltNonce = '1';
const safeAccountConfig = {
owners,
threshold,
};
const safeDeploymentConfig = { saltNonce };
const ethAdapter = new Web3Adapter({
web3,
safeOwner,
});

// async function createFactory() {
// const safeFactory = await SafeFactory.create({ ethAdapter });
// console.log('safeFactory --- :' + safeFactory);
// const safeSdk = safeFactory.deploySafe({
// safeAccountConfig,
// safeDeploymentConfig,
// });
// const newSafeAddress = await safeSdk.getAddress();
// console.log(safeSdk);
// console.log(newSafeAddress);
// }
// createFactory();
const createSafe = async () => {
const safeFactory = await SafeFactory.create({ ethAdapter });
console.log(safeFactory);
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig });
console.log(safeSdk);
const newSafeAddress = await safeSdk.getAddress();
safeSdk();
console.log(newSafeAddress);
};
createSafe();
66 changes: 66 additions & 0 deletions src/deploySafe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import Web3 from 'web3';
import Web3Adapter from '@gnosis.pm/safe-web3-lib';
import { SafeFactory } from '@gnosis.pm/safe-core-sdk';
const PROXY_FACTORY_ADDRESS = '0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb';
import GnosisSafeContract from '@circles/safe-contracts/build/contracts/GnosisSafe.json';
import MultiSendContract from '@circles/safe-contracts/build/contracts/MultiSend.json';
import MasterCopyContract from '@circles/safe-contracts/build/contracts/MasterCopy.json';
import ProxyFactoryContract from '@circles/safe-contracts/build/contracts/ProxyFactory.json';

/**
* Transactions submodule execute tx with the Gnosis Safe.
*
* @access private
*
* @param {Web3} web3 - Web3 instance
* @param {Object} contracts - common contract instances
*
* @return {Object} - safe module instance
*/

const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
web3.eth.net
.isListening()
.then(() => console.log('is connected'))
.catch((e) => console.log('error ' + e));

const contractNetworks = {
1337: {
multiSendAddress: '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB',
multiSendAbi: MultiSendContract.abi,
safeMasterCopyAddress: '0xC89Ce4735882C9F0f0FE26686c53074E09B0D550',
safeMasterCopyAbi: MasterCopyContract.abi,
safeProxyFactoryAddress: PROXY_FACTORY_ADDRESS,
safeProxyFactoryAbi: ProxyFactoryContract.abi,
},
};
// const safeOwner = '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB';
const owners = '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB';
const threshold = 1;
const saltNonce = '1';
const safeAccountConfig = {
owners,
threshold,
};
const safeDeploymentConfig = { saltNonce };
const ethAdapter = new Web3Adapter.default({
web3,
owners,
});

async function createFactory() {
const safeFactory = await SafeFactory.create({
ethAdapter,
contractNetworks,
});
console.log('safeFactory --- ' + JSON.stringify(safeFactory));

const safeSdk = await safeFactory.deploySafe({
safeAccountConfig,
safeDeploymentConfig,
});
// const newSafeAddress = await safeSdk.getAddress();
console.log(safeSdk);
//console.log(newSafeAddress);
}
createFactory();
71 changes: 71 additions & 0 deletions src/eth-helper copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Web3 from 'web3';
import Web3Adapter from '@gnosis.pm/safe-web3-lib';
import { SafeFactory } from '@gnosis.pm/safe-core-sdk';
import GnosisSafeContract from '@circles/safe-contracts/build/contracts/GnosisSafe.json';
import MultiSendContract from '@circles/safe-contracts/build/contracts/MultiSend.json';
import MasterCopyContract from '@circles/safe-contracts/build/contracts/MasterCopy.json';
import ProxyFactoryContract from '@circles/safe-contracts/build/contracts/ProxyFactory.json';
import getContracts from './common/getContracts.js';

const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));

const PROXY_FACTORY_ADDRESS = '0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec';
const MULTISEND_ADDRESS = '0x67B5656d60a809915323Bf2C40A8bEF15A152e3e';
const MASTERCOPY_ADDRESS = '0x2612Af3A521c2df9EAF28422Ca335b04AdF3ac66';

async function getChainId() {
return web3.eth.getChainId();
}

let chainID = await getChainId();
//console.log(chainID);
const { proxyFactory, masterCopy } = getContracts(web3, {
proxyFactoryAddress: PROXY_FACTORY_ADDRESS,
multiSendAddress: MULTISEND_ADDRESS,
masterCopyAddress: MASTERCOPY_ADDRESS,
});

const contractNetworks = {
[chainID]: {
multiSendAddress: MULTISEND_ADDRESS,
multiSendAbi: MultiSendContract.abi,
safeMasterCopyAddress: MASTERCOPY_ADDRESS,
safeMasterCopyAbi: MasterCopyContract.abi,
safeProxyFactoryAddress: PROXY_FACTORY_ADDRESS,
safeProxyFactoryAbi: ProxyFactoryContract.abi,
},
};
// const safeOwner = '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB';
const owners = '0x9a0bbbbd3789f184CA88f2F6A40F42406cb842AB';
const threshold = 1;
const saltNonce = '1';
const safeAccountConfig = {
owners,
threshold,
};
const safeDeploymentConfig = { saltNonce };
const ethAdapter = new Web3Adapter.default({
web3,
owners,
});
console.log(ethAdapter.getChainId());
const predictSafeProps = { safeAccountConfig, safeDeploymentConfig };
async function createFactory() {
const safeFactory = await SafeFactory.create({
ethAdapter,
contractNetworks,
});
const predAddress = await safeFactory.predictSafeAddress(predictSafeProps);
console.log('predAddress' + predAddress);
const d = await safeFactory.getEthAdapter().getSignerAddress();
console.log('safeFactory --- ' + d);

const safeSdk = await safeFactory.deploySafe({
safeAccountConfig,
safeDeploymentConfig,
});
// const newSafeAddress = await safeSdk.getAddress();
console.log(safeSdk);
//console.log(newSafeAddress);
}
createFactory();
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import getContracts from '~/common/getContracts';

import createActivityModule from '~/activity';
import createOrganizationModule from '~/organization';
import createSafeModule from '~/safe';
import createSafeModule from '~/safe_v2';
import createTokenModule from '~/token';
import createTrustModule from '~/trust';
import createUserModule from '~/user';
import createUtilsModule from '~/utils';
//import createTransactionsModule from '~/transactions';

/**
* Base class of CirclesCore.
Expand All @@ -29,7 +30,9 @@ export default class CirclesCore {
* @param {string} options.graphNodeEndpoint - URL of the graph node
* @param {string} options.hubAddress - address of deployed Circles Hub contract
* @param {string} options.proxyFactoryAddress - address of deployed Gnosis ProxyFactory contract
* @param {string} options.relayServiceEndpoint - URL of the Relayer server
* @param {string} options.relayServiceEndpoint - address of deployed Gnosis ProxyFactory contract
* @param {string} options.multiSendAddress - address of deployed Gnosis Multisend contract
* @param {string} options.multiSendCallAddress - address of deployed Gnosis MultisendCall contract
* @param {string} options.safeMasterAddress - address of deployed Gnosis Safe master copy contract
*/
constructor(web3, options) {
Expand All @@ -53,6 +56,12 @@ export default class CirclesCore {
safeMasterAddress: {
type: web3.utils.checkAddressChecksum,
},
multiSendAddress: {
type: web3.utils.checkAddressChecksum,
},
multiSendCallAddress: {
type: web3.utils.checkAddressChecksum,
},
graphNodeEndpoint: {
type: 'string',
},
Expand Down Expand Up @@ -99,12 +108,14 @@ export default class CirclesCore {
this.utils,
);
/** @type {Object} - safe module */
this.safe = createSafeModule(web3, this.contracts, this.utils);
this.safe = createSafeModule(web3, this.options);
/** @type {Object} - token module */
this.token = createTokenModule(web3, this.contracts, this.utils);
/** @type {Object} - trust module */
this.trust = createTrustModule(web3, this.contracts, this.utils);
/** @type {Object} - user module */
this.user = createUserModule(web3, this.contracts, this.utils);
/** @type {Object} - transactions module */
// this.transactions = createTransactionsModule(web3, this.contracts);
}
}
17 changes: 17 additions & 0 deletions src/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import winston from 'winston';

const DEFAULT_LOG_LEVEL = 'info';

const { format } = winston;

export default winston.createLogger({
level: process.env.LOG_LEVEL || DEFAULT_LOG_LEVEL,
format: format.combine(
format.colorize(),
format.timestamp(),
format.printf((info) => {
return `${info.timestamp} [${info.level}]: ${info.message}`;
}),
),
transports: [new winston.transports.Console()],
});
Loading