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

fix ethers event decoding #512

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BigNumber } from '@ethersproject/bignumber'
import { Event } from '@ethersproject/contracts'
import { ethers } from 'ethers'
import { EthersTransactionOptions } from '@safe-global/protocol-kit/adapters/ethers/types'
import { Proxy_factory as SafeProxyFactory_V1_0_0 } from '@safe-global/protocol-kit/typechain/src/ethers-v5/v1.0.0/Proxy_factory'
import { Proxy_factory as SafeProxyFactory_V1_1_1 } from '@safe-global/protocol-kit/typechain/src/ethers-v5/v1.1.1/Proxy_factory'
Expand Down Expand Up @@ -49,21 +50,47 @@ class SafeProxyFactoryEthersContract implements SafeProxyFactoryContract {
...options
}
)
}
}
const proxyAddress = this.contract
.createProxyWithNonce(safeMasterCopyAddress, initializer, saltNonce, options)
.then(async (txResponse) => {
if (callback) {
callback(txResponse.hash)
}
const txReceipt = await txResponse.wait()
const proxyCreationEvent = txReceipt?.events?.find(
({ event }: Event) => event === 'ProxyCreation'
)
if (!proxyCreationEvent || !proxyCreationEvent.args) {
const proxyCreationLog = txReceipt?.events?.find(
({ topics }: Event) =>
topics[0] === '0x4f51faf6c4561ff95f067657e43439f0f856d97c04d9ec9070a6199ad418e235'
) as Event | undefined

let proxyCreationEventArgs: { 0: string; 1: string; proxy: string; singleton: string }
| undefined
if (proxyCreationLog) {
if (proxyCreationLog.topics.length == 1) {
const ifaceNonIndexedProxyAddress = new ethers.utils.Interface([
'event ProxyCreation(address proxy, address singleton)'
])
proxyCreationEventArgs = ifaceNonIndexedProxyAddress.decodeEventLog(
'ProxyCreation',
proxyCreationLog.data,
proxyCreationLog.topics
) as unknown as typeof proxyCreationEventArgs
} else if (proxyCreationLog.topics.length == 2) {
const ifaceIndexedProxyAddress = new ethers.utils.Interface([
'event ProxyCreation(address indexed proxy, address singleton)'
])
proxyCreationEventArgs = ifaceIndexedProxyAddress.decodeEventLog(
'ProxyCreation',
proxyCreationLog.data,
proxyCreationLog.topics
) as unknown as typeof proxyCreationEventArgs
}
}

if (!proxyCreationEventArgs?.proxy) {
throw new Error('SafeProxy was not deployed correctly')
}
const proxyAddress: string = proxyCreationEvent.args[0]
const proxyAddress: string = proxyCreationEventArgs.proxy
return proxyAddress
})
return proxyAddress
Expand Down