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

feat: add option to submit safe tx #207

Draft
wants to merge 4 commits into
base: dev
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
2 changes: 2 additions & 0 deletions contracts/interfaces/IAccountGuard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface IAccountGuard {

function setWhitelist(address target, bool status) external;

function setWhitelistSend(address target, bool status) external;

function canCall(address proxy, address operator) external view returns (bool);

function permit(address caller, address target, bool allowance) external;
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
"@nomiclabs/hardhat-etherscan": "^2.1.7",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@oasisdex/multiply": "^0.2.10",
"@safe-global/safe-core-sdk": "^3.3.5",
"@safe-global/safe-core-sdk-types": "^2.3.0",
"@safe-global/safe-ethers-lib": "^1.9.4",
"@safe-global/safe-service-client": "^2.0.3",
"@tenderly/hardhat-tenderly": "^1.1.6",
"@typechain/ethers-v5": "^7.2.0",
"@typechain/hardhat": "^2.3.1",
Expand Down Expand Up @@ -84,7 +88,7 @@
},
"dependencies": {
"@nomicfoundation/hardhat-network-helpers": "^1.0.7",
"@oasisdex/automation": "^1.5.2",
"@oasisdex/automation": "^1.5.8",
"@openzeppelin/contracts": "^4.8.3",
"@uniswap/swap-router-contracts": "1.3.0",
"@uniswap/v3-core": "1.0.2-solc-0.8-simulate",
Expand Down
4 changes: 3 additions & 1 deletion scripts/common/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const addresses = {
AUTOMATION_DPM_ADAPTER: '0xBf2ecA15bff7d9c52e19b5c34EcbD03Bb2fc9CF7', //TODO: add address after deployment
AUTOMATION_AAVE_STOPLOSS_COMMAND: '0xDC1c84Aac43F21f103e9bD0B091a1B5cc6433554',
AUTOMATION_DUMMY_AAVE: '0x0000000000000000000000000000000000000000',
AUTOMATION_AAVE_PROXY_ACTIONS: '0x0000000000000000000000000000000000000000',
AUTOMATION_AAVE_PROXY_ACTIONS: '0xE6738B3B0214d6042FdFc9a0F0F92b63F459D983',
AUTOMATION_BOT_AGGREGATOR: '0x5f1d184204775fBB351C4b2C61a2fD4aAbd3fB76',
CONSTANT_MULTIPLE_VALIDATOR: '0x75d956f875e2714bc37Bae38890Fa159eaB661Aa',
UNISWAP_V2_ROUTER: '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D',
Expand All @@ -68,6 +68,7 @@ const addresses = {
DPM_GUARD: '0xCe91349d2A4577BBd0fC91Fe6019600e047f2847',
MAKER_SECURITY_ADAPTER: '',
MAKER_EXECUTABLE_ADAPTER: '',
GNOSIS_SAFE: '0x85f9b7408afE6CEb5E46223451f5d4b832B522dc',
SIGNERS: [
'0x8ff028d1248e9ae2e904603057981c9957f5f963',
'0x9bbb1c0a21b834e370c3ea268b2c1c53061470e7',
Expand Down Expand Up @@ -133,6 +134,7 @@ const addresses = {
MAKER_EXECUTABLE_ADAPTER: '',
DPM_FACTORY: '0x53958191c3077eDe3Ca90Eb840283df063FC1be3',
DPM_GUARD: '0x9319710C25cdaDDD1766F0bDE40F1A4034C17c7e',
GNOSIS_SAFE: '0x0000000000000000000000000000000000000000',
SIGNERS: [
'0x909187e0f7340014f89cc35fb045515dc080b3e6',
'0xa7063656a171cfdb05f3db28762e7c42429f3d06',
Expand Down
2 changes: 2 additions & 0 deletions scripts/common/deploy-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MakerAutoTakeProfitCommandV2,
AaveV3ProxyActions,
AaveV3StopLossCommandV2,
IAccountGuard,
} from '../../typechain'
import { AAVEAdapter } from '../../typechain/AAVEAdapter'
import { DPMAdapter } from '../../typechain/DPMAdapter'
Expand Down Expand Up @@ -47,6 +48,7 @@ export interface DeployedSystem {
aaveAdapter?: AAVEAdapter
dpmAdapter?: DPMAdapter
aaveProxyActions?: AaveV3ProxyActions
dpmGuard?: IAccountGuard
}

export interface DeploySystemArgs {
Expand Down
18 changes: 4 additions & 14 deletions scripts/common/hardhat.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import NodeCache from 'node-cache'
import BigNumber from 'bignumber.js'
import { coalesceNetwork, ETH_ADDRESS, getAddressesFor } from './addresses'
import { AutomationServiceName, EtherscanGasPrice, Network } from './types'

Check warning on line 9 in scripts/common/hardhat.utils.ts

View workflow job for this annotation

GitHub Actions / build

'AutomationServiceName' is defined but never used
import { DeployedSystem } from './deploy-system'
import { isLocalNetwork } from './utils'
import { setCode } from '@nomicfoundation/hardhat-network-helpers'
Expand All @@ -26,11 +26,6 @@
}

public async getDefaultSystem(): Promise<DeployedSystem> {
const serviceRegistry = await this.hre.ethers.getContractAt(
'ServiceRegistry',
this.addresses.AUTOMATION_SERVICE_REGISTRY,
)

return {
serviceRegistry: await this.hre.ethers.getContractAt(
'ServiceRegistry',
Expand Down Expand Up @@ -67,18 +62,13 @@
'MakerBasicSellCommandV2',
this.addresses.AUTOMATION_BASIC_SELL_COMMAND,
),
aaveAdapter: await this.hre.ethers.getContractAt(
'AAVEAdapter',
await serviceRegistry.getRegisteredService(AutomationServiceName.AAVE_ADAPTER),
),
dpmAdapter: await this.hre.ethers.getContractAt(
'DPMAdapter',
await serviceRegistry.getRegisteredService(AutomationServiceName.DPM_ADAPTER),
),
aaveAdapter: await this.hre.ethers.getContractAt('AAVEAdapter', this.addresses.AUTOMATION_AAVE_ADAPTER),
dpmAdapter: await this.hre.ethers.getContractAt('DPMAdapter', this.addresses.AUTOMATION_DPM_ADAPTER),
aaveProxyActions: await this.hre.ethers.getContractAt(
'AaveV3ProxyActions',
await serviceRegistry.getRegisteredService(AutomationServiceName.AAVE_PROXY_ACTIONS),
this.addresses.AUTOMATION_AAVE_PROXY_ACTIONS,
),
dpmGuard: await this.hre.ethers.getContractAt('IAccountGuard', this.addresses.DPM_GUARD),
}
}

Expand Down
102 changes: 102 additions & 0 deletions scripts/common/safe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import Safe from '@safe-global/safe-core-sdk'
import { SafeTransactionDataPartial, MetaTransactionData } from '@safe-global/safe-core-sdk-types'
import hre, { ethers } from 'hardhat'
import EthersAdapter from '@safe-global/safe-ethers-lib'
import { HardhatUtils, Network } from './'
import SafeServiceClient from '@safe-global/safe-service-client'
import { DeployedSystem } from './deploy-system'
import chalk from 'chalk'

/**
* Adds a registry entry using multisig.
* @param safeTransactionData - The transaction data to be executed on the safe.
* @param network - The network on which the transaction will be executed.
*/
export const addRegistryEntryMultisig = async (
safeTransactionData: SafeTransactionDataPartial | MetaTransactionData[],
network: Network,
) => {
const utils = new HardhatUtils(hre)
const safeOwner = hre.ethers.provider.getSigner(0)
const safeAddress = utils.addresses.GNOSIS_SAFE
const ethAdapter = new EthersAdapter({
ethers,
signerOrProvider: safeOwner,
})
const safe: Safe = await Safe.create({
ethAdapter,
safeAddress,
})
const service = new SafeServiceClient({
txServiceUrl: `https://safe-transaction-${network}.safe.global`,
ethAdapter,
})
const safeTx = await safe.createTransaction({ safeTransactionData })
const safeTxHash = await safe.getTransactionHash(safeTx)
const senderAddress = await safeOwner.getAddress()
const signature = await safe.signTransactionHash(safeTxHash)
await service.proposeTransaction({
safeAddress,
safeTransactionData: safeTx.data,
safeTxHash,
senderAddress,
senderSignature: signature.data,
})
}

export enum SafeTxType {
addNamedService,
setWhitelist,
}

/**
* Returns an array of partial transaction data based on the provided parameters.
* @param system - The deployed system object.
* @param type - The type of safe transaction.
* @param address - The address to be added to the service registry or whitelist.
* @param hash - The hash of the named service to be added to the service registry.
* @param nameOrTriggerId - The name of service or trigger ID of the named service to be added to the service registry.
* @returns An array of partial transaction data.
*/
export function getSafePartialTransactionData(
system: DeployedSystem,
type: SafeTxType,
address: string,
hash?: string,
nameOrTriggerId?: string,
) {
switch (type) {
case SafeTxType.addNamedService: {
console.info(
`Adding ${chalk.bold(address)} to the service registry as ${chalk.bold(
nameOrTriggerId,
)} (hash: ${chalk.bold(hash)})`,
)
return [
{
to: system.serviceRegistry.address,
value: '0',
data: system.serviceRegistry.interface.encodeFunctionData('addNamedService', [
hash as string,
address,
]),
},
]
}
case SafeTxType.setWhitelist: {
console.info(`Adding ${chalk.bold(address)} to the whitelist`)
return [
{
to: system.dpmGuard!.address,
value: '0',
data: system.dpmGuard!.interface.encodeFunctionData('setWhitelist', [address, true]),
},
{
to: system.dpmGuard!.address,
value: '0',
data: system.dpmGuard!.interface.encodeFunctionData('setWhitelistSend', [address, true]),
},
]
}
}
}
1 change: 1 addition & 0 deletions scripts/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum AutomationServiceName {
UNISWAP_FACTORY = 'UNISWAP_FACTORY',
DPM_ADAPTER = 'DPM_ADAPTER',
AAVE_ADAPTER = 'AAVE_ADAPTER',
DPM_GUARD = 'DPM_GUARD',
}

export interface OneInchQuoteResponse {
Expand Down
Loading
Loading