Skip to content

Commit

Permalink
Merge pull request #118 from Dhruv-Mishra/feature/overrideConstants
Browse files Browse the repository at this point in the history
feature: allow overriding module address
  • Loading branch information
kopy-kat authored Jan 21, 2025
2 parents e924fc4 + 95d9f3f commit 7bc8c43
Show file tree
Hide file tree
Showing 68 changed files with 619 additions and 418 deletions.
4 changes: 2 additions & 2 deletions src/common/queries/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, PublicClient } from 'viem'
import { INDEXER_URL } from '../constants'
import { Account } from '../../account'
import { GLOBAL_CONSTANTS } from '../../constants'

const query = `
query ($smartAccount: String, $chainId: Int) {
Expand All @@ -23,7 +23,7 @@ export const getInstalledModules = async ({
chainId: await client.getChainId(),
}

const response = await fetch(INDEXER_URL, {
const response = await fetch(GLOBAL_CONSTANTS.INDEXER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions src/common/queries/registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PublicClient } from 'viem'
import { INDEXER_URL } from '../constants'
import { GLOBAL_CONSTANTS } from '../../constants'

const query = `
query ($chainId: Int) {
Expand All @@ -19,7 +19,7 @@ export const getRegistryModules = async ({
chainId: await client.getChainId(),
}

const response = await fetch(INDEXER_URL, {
const response = await fetch(GLOBAL_CONSTANTS.INDEXER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
6 changes: 3 additions & 3 deletions src/common/queries/scheduledOrders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, PublicClient } from 'viem'
import { INDEXER_URL } from '../constants'
import { Account } from '../../account'
import { GLOBAL_CONSTANTS } from '../../constants'

const query = `
query ($smartAccount: String, $chainId: Int) {
Expand Down Expand Up @@ -29,7 +29,7 @@ export const getScheduledOrders = async ({
chainId: client.chain?.id,
}

const response = await fetch(INDEXER_URL, {
const response = await fetch(GLOBAL_CONSTANTS.INDEXER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -81,7 +81,7 @@ export const getScheduledOrderByJobId = async ({
chainId: await client.getChainId(),
}

const response = await fetch(INDEXER_URL, {
const response = await fetch(GLOBAL_CONSTANTS.INDEXER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
6 changes: 3 additions & 3 deletions src/common/queries/scheduledTransfers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, PublicClient } from 'viem'
import { INDEXER_URL } from '../constants'
import { Account } from '../../account'
import { GLOBAL_CONSTANTS } from '../../constants'

const query = `
query ($smartAccount: String, $chainId: Int) {
Expand Down Expand Up @@ -29,7 +29,7 @@ export const getScheduledTransfers = async ({
chainId: await client.getChainId(),
}

const response = await fetch(INDEXER_URL, {
const response = await fetch(GLOBAL_CONSTANTS.INDEXER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -81,7 +81,7 @@ export const getScheduledTransferByJobId = async ({
chainId: await client.getChainId(),
}

const response = await fetch(INDEXER_URL, {
const response = await fetch(GLOBAL_CONSTANTS.INDEXER_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
96 changes: 96 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Address } from 'viem'

export const ACCOUNT_LOCKER_HOOK = '0x97fbddd688327229eb193e824c8466d0c8c848fb'
export const ACCOUNT_LOCKER_SOURCE_EXECUTOR =
'0x868E00ae42214a5a1BB2d01aE1587c8814cF45BB'
export const ACCOUNT_LOCKER_TARGET_EXECUTOR =
'0xaffd5668449271Ce63B2a37fB0631f3B27F053b8'
export const AUTO_SAVINGS_ADDRESS: Address =
'0x6AE48bD83B6bdc8489584Ea0814086f963d1BD95'
export const COLD_STORAGE_FLASHLOAN_ADDRESS: Address =
'0x4422dbC3D055D59ee08F4A4D60E1046A9aFb287f'
export const COLD_STORAGE_HOOK_ADDRESS: Address =
'0x7E31543b269632ddc55a23553f902f84C9DD8454'
export const DEADMAN_SWITCH_ADDRESS: Address =
'0x8bAdE54bca47199B6732EB2F92318DD666bdE413'
export const HOOK_MULTI_PLEXER_ADDRESS: Address =
'0xF6782ed057F95f334D04F0Af1Af4D14fb84DE549'
export const INDEXER_URL =
'https://indexer.bigdevenergy.link/c03b38d/v1/graphql'
export const MULTI_FACTOR_VALIDATOR_ADDRESS: Address =
'0xf6bDf42c9BE18cEcA5C06c42A43DAf7FBbe7896b'
export const OWNABLE_EXECUTOR_ADDRESS: Address =
'0x4Fd8d57b94966982B62e9588C27B4171B55E8354'
export const OWNABLE_VALIDATOR_ADDRESS: Address =
'0x2483DA3A338895199E5e538530213157e931Bf06'
export const REGISTRY_ADDRESS: Address =
'0x000000000069E2a187AEFFb852bF3cCdC95151B2'
export const REGISTRY_HOOK_ADDRESS: Address =
'0x0ac6160DBA30d665cCA6e6b6a2CDf147DC3dED22'
export const SCHEDULED_ORDERS_EXECUTOR_ADDRESS: Address =
'0x40dc90D670C89F322fa8b9f685770296428DCb6b'
export const SCHEDULED_TRANSFERS_EXECUTOR_ADDRESS: Address =
'0xA8E374779aeE60413c974b484d6509c7E4DDb6bA'
export const SMART_SESSIONS_ADDRESS: Address =
'0x00000000002B0eCfbD0496EE71e01257dA0E37DE'
export const SMART_SESSIONS_COMPATIBILITY_FALLBACK_ADDRESS: Address =
'0xBad7E91C4F2803978cd6c7C3Fe80B5Fd7f7B0b50'
export const SOCIAL_RECOVERY_ADDRESS: Address =
'0xA04D053b3C8021e8D5bF641816c42dAA75D8b597'
export const UNIVERSAL_ACTION_POLICY_ADDRESS: Address =
'0x0000006DDA6c463511C4e9B05CFc34C1247fCF1F'
export const UNIVERSAL_EMAIL_RECOVERY_ADDRESS: Address =
'0x636632FA22052d2a4Fb6e3Bab84551B620b9C1F9'
export const UNIVERSAL_EMAIL_RECOVERY_ADDRESS__BASE: Address =
'0x36A470159F8170ad262B9518095a9FeD0824e7dD'
export const UNIVERSAL_EMAIL_RECOVERY_ADDRESS__ETH_SEPOLIA: Address =
'0x8ECcb707C4770239D7e95743cd01aaA72d6D313E'
export const WEBAUTHN_VALIDATOR_ADDRESS: Address =
'0xD990393C670dCcE8b4d8F858FB98c9912dBFAa06'

export const DEFAULT_CONSTANTS = {
ACCOUNT_LOCKER_HOOK,
ACCOUNT_LOCKER_SOURCE_EXECUTOR,
ACCOUNT_LOCKER_TARGET_EXECUTOR,
AUTO_SAVINGS_ADDRESS,
COLD_STORAGE_FLASHLOAN_ADDRESS,
COLD_STORAGE_HOOK_ADDRESS,
DEADMAN_SWITCH_ADDRESS,
HOOK_MULTI_PLEXER_ADDRESS,
INDEXER_URL,
MULTI_FACTOR_VALIDATOR_ADDRESS,
OWNABLE_EXECUTOR_ADDRESS,
OWNABLE_VALIDATOR_ADDRESS,
REGISTRY_ADDRESS,
REGISTRY_HOOK_ADDRESS,
SCHEDULED_ORDERS_EXECUTOR_ADDRESS,
SCHEDULED_TRANSFERS_EXECUTOR_ADDRESS,
SMART_SESSIONS_ADDRESS,
SMART_SESSIONS_COMPATIBILITY_FALLBACK_ADDRESS,
SOCIAL_RECOVERY_ADDRESS,
UNIVERSAL_ACTION_POLICY_ADDRESS,
UNIVERSAL_EMAIL_RECOVERY_ADDRESS,
UNIVERSAL_EMAIL_RECOVERY_ADDRESS__BASE,
UNIVERSAL_EMAIL_RECOVERY_ADDRESS__ETH_SEPOLIA,
WEBAUTHN_VALIDATOR_ADDRESS,
} as const

export let GLOBAL_CONSTANTS = {
...DEFAULT_CONSTANTS,
}

export type Constants = typeof GLOBAL_CONSTANTS

export const setGlobalConstants = (overrides: Partial<Constants>): void => {
GLOBAL_CONSTANTS = { ...GLOBAL_CONSTANTS, ...overrides }
}

export const getModifiedConstants = (
overrides?: Partial<Constants>,
): Constants => {
return { ...GLOBAL_CONSTANTS, ...overrides }
}

export const restoreGlobalConstants = (): void => {
GLOBAL_CONSTANTS = { ...DEFAULT_CONSTANTS }
}
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,11 @@ export {
getScheduledOrders,
getScheduledOrderByJobId,
} from './common'

export {
DEFAULT_CONSTANTS,
GLOBAL_CONSTANTS,
setGlobalConstants,
getModifiedConstants,
restoreGlobalConstants,
} from './constants'
6 changes: 3 additions & 3 deletions src/module/auto-savings/installation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, encodeAbiParameters } from 'viem'
import { Module } from '../types'
import { AUTO_SAVINGS_ADDRESS } from './constants'
import { swapRouterAddresses } from '../utils/uniswap'
import { GLOBAL_CONSTANTS } from '../../constants'

type Params = {
chainId: number
Expand All @@ -24,8 +24,8 @@ export const getAutoSavingsExecutor = ({
}

return {
address: AUTO_SAVINGS_ADDRESS,
module: AUTO_SAVINGS_ADDRESS,
address: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
module: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
initData: encodeAbiParameters(
[
{ internalType: 'address', name: 'swapRouter', type: 'address' },
Expand Down
18 changes: 9 additions & 9 deletions src/module/auto-savings/usage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Address, encodeFunctionData, getAddress, PublicClient } from 'viem'
import { AUTO_SAVINGS_ADDRESS } from './constants'
import { GLOBAL_CONSTANTS } from '../../constants'
import { abi } from './abi'
import { Execution } from '../../account'
import { SENTINEL_ADDRESS } from '../../common/constants'
Expand All @@ -25,8 +25,8 @@ export const getSetAutoSavingConfigAction = ({
})

return {
to: AUTO_SAVINGS_ADDRESS,
target: AUTO_SAVINGS_ADDRESS,
to: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
target: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
value: BigInt(0),
callData: data,
data,
Expand All @@ -42,7 +42,7 @@ export const getAutoSavingTokens = async ({
}): Promise<Address[]> => {
try {
const tokens = (await client.readContract({
address: AUTO_SAVINGS_ADDRESS,
address: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
abi,
functionName: 'getTokens',
args: [account.address],
Expand Down Expand Up @@ -86,8 +86,8 @@ export const getDeleteAutoSavingConfigAction = async ({
})

return {
to: AUTO_SAVINGS_ADDRESS,
target: AUTO_SAVINGS_ADDRESS,
to: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
target: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
value: BigInt(0),
callData: data,
data,
Expand Down Expand Up @@ -118,8 +118,8 @@ export const getAutoSaveAction = ({
})

return {
to: AUTO_SAVINGS_ADDRESS,
target: AUTO_SAVINGS_ADDRESS,
to: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
target: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
value: BigInt(0),
callData: data,
data,
Expand All @@ -139,7 +139,7 @@ export const getAutoSavingAccountTokenConfig = async ({
}): Promise<ConfigType> => {
try {
const config = (await client.readContract({
address: AUTO_SAVINGS_ADDRESS,
address: GLOBAL_CONSTANTS.AUTO_SAVINGS_ADDRESS,
abi,
functionName: 'config',
args: [account.address, token],
Expand Down
17 changes: 8 additions & 9 deletions src/module/cold-storage/installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import {
PublicClient,
} from 'viem'
import { Module } from '../types'
import {
COLD_STORAGE_HOOK_ADDRESS,
COLD_STORAGE_FLASHLOAN_ADDRESS,
} from './constants'
import { Account } from '../../account'
import { getInstalledModules } from '../../account'
import { CallType } from '../../module/types'
import { GLOBAL_CONSTANTS } from '../../constants'

type Params = {
account: Account
Expand All @@ -33,13 +30,15 @@ export const getColdStorageHook = async ({
}: Params): Promise<Module> => {
const installedModules = await getInstalledModules({ account, client })

const initData = installedModules.includes(COLD_STORAGE_HOOK_ADDRESS)
const initData = installedModules.includes(
GLOBAL_CONSTANTS.COLD_STORAGE_HOOK_ADDRESS,
)
? '0x'
: encodePacked(['uint128', 'address'], [BigInt(waitPeriod), owner])

return {
address: COLD_STORAGE_HOOK_ADDRESS,
module: COLD_STORAGE_HOOK_ADDRESS,
address: GLOBAL_CONSTANTS.COLD_STORAGE_HOOK_ADDRESS,
module: GLOBAL_CONSTANTS.COLD_STORAGE_HOOK_ADDRESS,
initData,
deInitData: '0x',
additionalContext: '0x',
Expand All @@ -64,8 +63,8 @@ export const getAllowedCallbackSenders = ({
hook,
}: FlashloanParams): Module => {
return {
address: COLD_STORAGE_FLASHLOAN_ADDRESS,
module: COLD_STORAGE_FLASHLOAN_ADDRESS,
address: GLOBAL_CONSTANTS.COLD_STORAGE_FLASHLOAN_ADDRESS,
module: GLOBAL_CONSTANTS.COLD_STORAGE_FLASHLOAN_ADDRESS,
initData: encodeAbiParameters(
[{ internalType: 'address[]', name: 'addresses', type: 'address[]' }],
[addresses],
Expand Down
Loading

0 comments on commit 7bc8c43

Please sign in to comment.