-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a41fb88
commit 0ae39ec
Showing
12 changed files
with
261 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { getSafeContract } from '~/common/getContracts'; | ||
|
||
import getTrustConnection from './getTrustConnection'; | ||
|
||
export default async function addTrust( | ||
{ account, safeAddress, safeAddressToTrust, limitPercentage }, | ||
core, | ||
) { | ||
const { | ||
contracts: { hub }, | ||
options: { hubAddress }, | ||
safe, | ||
utils, | ||
web3, | ||
} = core; | ||
// Retrieve safe | ||
const safeSdk = await safe.getSafeSdk(account, { safeAddress }); | ||
|
||
// Prepare transaction to trust a Safe | ||
return ( | ||
safeSdk | ||
.createTransaction({ | ||
safeTransactionData: { | ||
to: hubAddress, | ||
value: 0, | ||
data: hub.methods | ||
.trust(safeAddressToTrust, limitPercentage) | ||
.encodeABI(), | ||
}, | ||
}) | ||
.then((safeTx) => safeSdk.signTransaction(safeTx)) | ||
// Execute manually the transaction | ||
.then((signedSafeTx) => | ||
web3.eth.sendTransaction({ | ||
from: account.address, | ||
to: safeAddress, | ||
value: 0, | ||
data: getSafeContract(web3, safeAddress) | ||
.methods.execTransaction( | ||
signedSafeTx.data.to, | ||
signedSafeTx.data.value, | ||
signedSafeTx.data.data, | ||
signedSafeTx.data.operation, | ||
signedSafeTx.data.safeTxGas, | ||
signedSafeTx.data.baseGas, | ||
signedSafeTx.data.gasPrice, | ||
signedSafeTx.data.gasToken, | ||
signedSafeTx.data.refundReceiver, | ||
signedSafeTx.encodedSignatures(), | ||
) | ||
.encodeABI(), | ||
}), | ||
) | ||
.then(() => | ||
utils.loop( | ||
() => | ||
getTrustConnection(core, account, safeAddress, safeAddressToTrust), | ||
(isReady) => isReady, | ||
{ label: 'Wait for the graph to index newly added trust connection' }, | ||
), | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import privateKeys from './accounts.json'; | ||
|
||
const getAccounts = (web3) => | ||
privateKeys.map((key) => web3.eth.accounts.privateKeyToAccount(key)); | ||
|
||
export default getAccounts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { ZERO_ADDRESS } from '~/common/constants'; | ||
import { getSafeContract } from '~/common/getContracts'; | ||
|
||
// Set up manually a Safe for being fully usable in Circles | ||
export default async function setupAccount({ account, nonce }, core) { | ||
const { | ||
contracts: { safeMaster, hub, proxyFactory }, | ||
options: { | ||
fallbackHandlerAddress, | ||
hubAddress, | ||
proxyFactoryAddress, | ||
safeMasterAddress, | ||
}, | ||
safe, | ||
web3, | ||
} = core; | ||
const safeAddress = await safe.predictAddress(account, { nonce }); | ||
let safeSdk; | ||
|
||
return ( | ||
// Deploy manually a Safe | ||
web3.eth | ||
.sendTransaction({ | ||
from: account.address, | ||
to: proxyFactoryAddress, | ||
value: 0, | ||
data: proxyFactory.methods | ||
.createProxyWithNonce( | ||
safeMasterAddress, | ||
safeMaster.methods | ||
.setup( | ||
[account.address], | ||
1, | ||
ZERO_ADDRESS, | ||
'0x', | ||
fallbackHandlerAddress, | ||
ZERO_ADDRESS, | ||
0, | ||
ZERO_ADDRESS, | ||
) | ||
.encodeABI(), | ||
nonce, | ||
) | ||
.encodeABI(), | ||
}) | ||
// Instantiate deployed Safe | ||
.then(async () => { | ||
safeSdk = await safe.getSafeSdk(account, { safeAddress }); | ||
}) | ||
// Prepare transaction for Safe to be signed up | ||
.then(() => | ||
safeSdk.createTransaction({ | ||
safeTransactionData: { | ||
to: hubAddress, | ||
value: 0, | ||
data: hub.methods.signup().encodeABI(), | ||
}, | ||
}), | ||
) | ||
.then((safeTx) => safeSdk.signTransaction(safeTx)) | ||
// Execute manually the transaction | ||
.then((signedSafeTx) => | ||
web3.eth.sendTransaction({ | ||
from: account.address, | ||
to: safeAddress, | ||
value: 0, | ||
data: getSafeContract(web3, safeAddress) | ||
.methods.execTransaction( | ||
signedSafeTx.data.to, | ||
signedSafeTx.data.value, | ||
signedSafeTx.data.data, | ||
signedSafeTx.data.operation, | ||
signedSafeTx.data.safeTxGas, | ||
signedSafeTx.data.baseGas, | ||
signedSafeTx.data.gasPrice, | ||
signedSafeTx.data.gasToken, | ||
signedSafeTx.data.refundReceiver, | ||
signedSafeTx.encodedSignatures(), | ||
) | ||
.encodeABI(), | ||
}), | ||
) | ||
.then(() => safeAddress) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Web3 from 'web3'; | ||
import HDWalletProvider from '@truffle/hdwallet-provider'; | ||
|
||
import privateKeys from './accounts.json'; | ||
|
||
export default function setupWeb3() { | ||
const provider = new HDWalletProvider({ | ||
privateKeys, | ||
providerOrUrl: process.env.RPC_URL, | ||
}); | ||
const web3 = new Web3(provider); | ||
|
||
return { | ||
web3, | ||
provider, | ||
}; | ||
} |
Oops, something went wrong.