Skip to content

Commit

Permalink
цшз
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed Aug 18, 2023
1 parent 72625fe commit 32b0edb
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/abi/multicall2/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export function encodeTryAggregate(b: boolean, calls: [string, string][]) {
res += b ? trueEncoded : falseEncoded
res += encodeUint(dynamicOffset)

if (!res) {
throw new Error('Multicall2: failed to encode tryAggregate')
}

// encode dynamic array of calls
return encodeCalls(res, calls)
}
16 changes: 9 additions & 7 deletions packages/core/src/helpers/contract.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ContractFactory, ethers } from 'ethers'
import { BytesLike, Contract, ContractFactory, JsonRpcSigner, TransactionReceipt, ethers } from 'ethers'

interface ContractAbi {
abi: ethers.ContractInterface
bytecode: ethers.utils.BytesLike
abi: ethers.Interface | ethers.InterfaceAbi
bytecode: BytesLike
}

export async function deployContract(
contractAbi: ContractAbi,
signer: ethers.providers.JsonRpcSigner
): Promise<ethers.providers.TransactionReceipt> {
signer: JsonRpcSigner
): Promise<TransactionReceipt> {
const factory = new ContractFactory(contractAbi.abi, contractAbi.bytecode, signer)
const contract = await factory.deploy()
return await contract.deployTransaction.wait()
const contract = await factory.deploy() as Contract
const txReceipt = await contract.deploymentTransaction()?.wait()
if (!txReceipt) throw new Error('Contract deployment failed')
return txReceipt
}
3 changes: 2 additions & 1 deletion packages/core/src/helpers/gnosisSafeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TransactionResponse,
TransactionReceipt,
TransactionRequest,
EventLog,
} from 'ethers'
import { getChainById } from './chain'

Expand Down Expand Up @@ -123,7 +124,7 @@ export const waitForSafeTransaction = async (
}
})

const onExecutionSuccess = async (txHash: string, _payment: bigint, event: Event) => {
const onExecutionSuccess = async (txHash: string, _payment: bigint, event: EventLog) => {
if (txHash === safeTxHash) {
contract.removeListener('ExecutionSuccess', onExecutionSuccess)

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/helpers/injectedProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import detectEthereumProvider from '@metamask/detect-provider'
import { providers } from 'ethers'
import { isWebSocketProvider } from './isWebSocketProvider'
import { BrowserProvider } from 'ethers'

const GET_METAMASK_LINK = 'https://metamask.io/download.html'

Expand All @@ -21,7 +21,7 @@ export async function getInjectedProvider(getPollingInterval: (chaindId: number)
return undefined
}

const provider = new providers.Web3Provider(injectedProvider, 'any')
const provider = new BrowserProvider(injectedProvider, 'any')
const chainId = await provider.send('eth_chainId', [])
if (!isWebSocketProvider(provider)) {
provider.pollingInterval = getPollingInterval(chainId)
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/helpers/logs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai'
import { Contract, Filter, FilterByBlockHash, Log, ZeroAddress, ethers } from 'ethers'
import { Contract, Filter, FilterByBlockHash, Log, LogParams, ZeroAddress, ethers } from 'ethers'
import { TypedFilter } from '../hooks'
import { MockProvider, deployMockToken } from '../testing'
import { decodeLogs, encodeFilterData, LogsResult } from './logs'
Expand All @@ -26,7 +26,7 @@ describe('encodeFilterData', () => {

const encodedFilterData = encodeFilterData(filter, undefined, undefined, '0x0')

expect(encodedFilterData['blockHash']).to.not.be.undefined
expect((encodedFilterData as any)['blockHash']).to.not.be.undefined
})

it('Returns FilterByBlockHash when blockHash, toBlock, and fromBlock are valid', () => {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('decodeLogs', () => {
args: [],
}

const logs: Log[] = [
const logs: LogParams[] = [
{
address: await token.getAddress(),
topics: [
Expand All @@ -165,7 +165,7 @@ describe('decodeLogs', () => {
data: ethers.zeroPadValue(ZeroAddress, 32),
blockHash: '0x0',
blockNumber: 0,
logIndex: 0,
index: 0,
transactionIndex: 0,
transactionHash: '0x0',
removed: false,
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('decodeLogs', () => {
const removed = true
const transactionHash = '0x11'

const logs: Log[] = [
const logs: LogParams[] = [
{
address: await token.getAddress(),
topics: [
Expand All @@ -206,7 +206,7 @@ describe('decodeLogs', () => {
data: ethers.zeroPadValue(value, 32),
blockHash,
blockNumber,
logIndex,
index: logIndex,
transactionIndex,
transactionHash,
removed,
Expand All @@ -221,7 +221,7 @@ describe('decodeLogs', () => {
data: ethers.zeroPadValue(value, 32),
blockHash,
blockNumber,
logIndex,
index: logIndex,
transactionIndex,
transactionHash,
removed,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/helpers/logs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TypedFilter } from '../hooks/useLogs'
import { Awaited, ContractEventNames, DetailedEventRecord, EventRecord, Falsy, TypedContract } from '../model/types'
import { BlockTag, EventFragment, Filter, FilterByBlockHash, Log } from 'ethers'
import { BlockTag, EventFragment, Filter, FilterByBlockHash, LogParams } from 'ethers'

/**
* @internal Intended for internal use - use it on your own risk
Expand Down Expand Up @@ -92,7 +92,7 @@ export type LogsResult<T extends TypedContract, EN extends ContractEventNames<T>
*/
export function decodeLogs<T extends TypedContract, EN extends ContractEventNames<T>>(
filter: TypedFilter | Falsy,
result: Log[] | Falsy | Error
result: LogParams[] | Falsy | Error
): LogsResult<T, EN> {
if (!result || !filter) {
return undefined
Expand Down

0 comments on commit 32b0edb

Please sign in to comment.