Skip to content

Commit

Permalink
Prover dis (#45)
Browse files Browse the repository at this point in the history
* adding the balance into the target

* disable prover indexing for watch intent
enable valid smart wallet check

* fixing tests
  • Loading branch information
StoyanD authored Oct 15, 2024
1 parent 12980ff commit fe9e841
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/contracts/IntentSource.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const IntentSourceAbi = [
type: 'uint256[]',
},
{
indexed: false,
indexed: true,
internalType: 'uint256',
name: '_expiryTime',
type: 'uint256',
Expand All @@ -115,7 +115,7 @@ export const IntentSourceAbi = [
type: 'bytes32',
},
{
indexed: true,
indexed: false,
internalType: 'address',
name: '_prover',
type: 'address',
Expand Down
28 changes: 17 additions & 11 deletions src/intent/tests/watch-intent.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('WatchIntentService', () => {
it('should subscribe to all source intents', async () => {
const mockWatch = jest.fn()
publicClientService.getClient.mockResolvedValue({
watchContractEvent: mockWatch
watchContractEvent: mockWatch,
} as any)
ecoConfigService.getSourceIntents.mockReturnValue(sources)
ecoConfigService.getSolvers.mockReturnValue(sources)
Expand All @@ -78,9 +78,11 @@ describe('WatchIntentService', () => {
for (const [index, s] of sources.entries()) {
const { address, eventName, args } = mockWatch.mock.calls[index][0]
const partial = { address, eventName, args }
expect(partial).toEqual(
{ address: s.sourceAddress, eventName: 'IntentCreated', args: { _destinationChain: supportedChains, _prover: s.provers } }
)
expect(partial).toEqual({
address: s.sourceAddress,
eventName: 'IntentCreated',
args: { _destinationChain: supportedChains}// TODO include in next release of contracts , _prover: s.provers },
})
}
})
})
Expand All @@ -95,7 +97,7 @@ describe('WatchIntentService', () => {
it('should unsubscribe to all source intents', async () => {
const mockUnwatch = jest.fn()
publicClientService.getClient.mockResolvedValue({
watchContractEvent: () => mockUnwatch
watchContractEvent: () => mockUnwatch,
} as any)
ecoConfigService.getSourceIntents.mockReturnValue(sources)
ecoConfigService.getSolvers.mockReturnValue(sources)
Expand All @@ -119,23 +121,27 @@ describe('WatchIntentService', () => {
it('should convert all bigints to strings', async () => {
expect(mockLogDebug.mock.calls[0][0].createIntent).toEqual(
expect.objectContaining({
args: { _hash: '1', logIndex: '2' }
})
args: { _hash: '1', logIndex: '2' },
}),
)

})

it('should should attach source chainID and network', async () => {
expect(mockLogDebug.mock.calls[0][0].createIntent).toEqual(
expect.objectContaining({
sourceChainID: s.chainID, sourceNetwork: s.network
})
sourceChainID: s.chainID,
sourceNetwork: s.network,
}),
)
})

it('should should enque a job for every intent', async () => {
expect(mockQueueAdd).toHaveBeenCalledTimes(1)
expect(mockQueueAdd).toHaveBeenCalledWith(QUEUES.SOURCE_INTENT.jobs.create_intent, expect.any(Object), { "jobId": "watch-1-0" })
expect(mockQueueAdd).toHaveBeenCalledWith(
QUEUES.SOURCE_INTENT.jobs.create_intent,
expect.any(Object),
{ jobId: 'watch-1-0' },
)
})
})
})
4 changes: 2 additions & 2 deletions src/intent/watch-intent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export class WatchIntentService implements OnApplicationBootstrap, OnModuleDestr
args: {
// restrict by acceptable chains, chain ids must be bigints
_destinationChain: solverSupportedChains,
// restrict by acceptable prover
_prover: source.provers,
// TODO redeploy once we are using the new contract addressess with the new abi restrict by acceptable prover
// _prover: source.provers,
},
onLogs: this.addJob(source),
})
Expand Down
8 changes: 2 additions & 6 deletions src/solver/filters/tests/valid-smart-wallet.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ describe('ValidSmartWalletService Tests', () => {
}
})
const result = await validWalletService.validateSmartWallet('0x789', 1n)
//todo restore this
// expect(result).toEqual(false)
expect(result).toEqual(true)
expect(result).toEqual(false)
})

it('should return false if the SA address is from another factory', async () => {
Expand All @@ -73,9 +71,7 @@ describe('ValidSmartWalletService Tests', () => {
}
})
const result = await validWalletService.validateSmartWallet('0x789', 1n)
//todo restore this
// expect(result).toEqual(false)
expect(result).toEqual(true)
expect(result).toEqual(false)
})

it('should return true if the SA is from our factory', async () => {
Expand Down
45 changes: 30 additions & 15 deletions src/solver/filters/valid-smart-wallet.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Injectable, OnModuleInit } from '@nestjs/common'
import { Injectable, Logger, OnModuleInit } from '@nestjs/common'
import { MultichainPublicClientService } from '../../transaction/multichain-public-client.service'
import { EcoConfigService } from '../../eco-configs/eco-config.service'
import { Hex } from 'viem'
import { EntryPointAbi_v6 } from '../../contracts/EntryPoint.V6.contract'
import { EcoLogMessage } from '../../common/logging/eco-log-message'

@Injectable()
export class ValidSmartWalletService implements OnModuleInit {
private logger = new Logger(ValidSmartWalletService.name)

private entryPointAddress: Hex
private factoryAddress: Hex
constructor(
Expand All @@ -27,19 +30,31 @@ export class ValidSmartWalletService implements OnModuleInit {
*/
async validateSmartWallet(smartWalletAddress: Hex, chainID: bigint): Promise<boolean> {
//TODO fix this
return true
// const client = await this.publicClient.getClient(chainID)
// const deployedEvents = await client.getContractEvents({
// address: this.entryPointAddress,
// abi: EntryPointAbi_v6,
// eventName: 'AccountDeployed',
// args: { sender: smartWalletAddress },
// fromBlock: 0n,
// toBlock: 'latest',
// })
// //should be only one event, but comes as an array
// return (
// deployedEvents && deployedEvents.some((event) => event.args.factory === this.factoryAddress)
// )
// return true
const client = await this.publicClient.getClient(Number(chainID))
try {
const deployedEvents = await client.getContractEvents({
address: this.entryPointAddress,
abi: EntryPointAbi_v6,
eventName: 'AccountDeployed',
args: { sender: smartWalletAddress },
fromBlock: 0n,
toBlock: 'latest',
})
//should be only one event, but comes as an array
return (
deployedEvents && deployedEvents.some((event) => event.args.factory === this.factoryAddress)
)
} catch (error) {
this.logger.error(
EcoLogMessage.fromDefault({
message: `RPC: getContractEvents error`,
properties: {
error,
},
}),
)
return false
}
}
}

0 comments on commit fe9e841

Please sign in to comment.