Skip to content

Commit

Permalink
Ed 3835 lookback (#27)
Browse files Browse the repository at this point in the history
* adding chain sync service

* adding ws transport to viem
commenting out alchemy and sign module co-dependencies
commenting out atomic nonces
moving BalanceService token loading to onApplicationBootstrap

* getting the ChainSync service to work
refactored websocket inetent service to use viem subscription on websocket connection instead of the ethers alchemy ws
adding provers array to the sourceIntents config
modifying everywhere we handle addresses to use viems getAddress instead of toLowercase

* adding tests for chain sync service
updating the abi contracts

* add prover to intent
  • Loading branch information
StoyanD authored Sep 19, 2024
1 parent a06abc8 commit 665a5fb
Show file tree
Hide file tree
Showing 29 changed files with 677 additions and 384 deletions.
1 change: 1 addition & 0 deletions config/development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default {
'0xd3F4Bef596a04e2be4fbeB17Dd70f02F717c5a6c',
'0x93551e3F61F8E3EE73DDc096BddbC1ADc52f5A3a',
],
provers: ['0x99b07fF401E2c73826f3043AdaB2ef37e53d4f23'],
},
],
solvers: {
Expand Down
6 changes: 3 additions & 3 deletions src/alchemy/aa-smart-multichain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
SmartAccountClient,
SmartAccountClientConfig,
} from '@alchemy/aa-core'
import { extractChain, http } from 'viem'
import { extractChain } from 'viem'
import { EcoError } from '../common/errors/eco-error'
import { ChainsSupported } from '../common/utils/chains'
import { createMultiOwnerModularAccount } from '@alchemy/aa-accounts'
import { getAchemyRPCUrl } from '../common/utils/strings'
import { AAMultiChainConfig } from './aa-smart-multichain.service'
import { getTransport } from './utils'

export class AASmartMultichainClient {
readonly configs: AAMultiChainConfig
Expand Down Expand Up @@ -42,7 +42,7 @@ export class AASmartMultichainClient {

// const c = Object.values(aaChains)[0]
if (this.configs && this.configs.ids.includes(chainID) && chain) {
const rpcTransport = http(getAchemyRPCUrl(chain, this.configs.apiKey))
const rpcTransport = getTransport(chain, this.configs.apiKey, true)
return {
transport: rpcTransport as any,
chain: chain,
Expand Down
4 changes: 2 additions & 2 deletions src/alchemy/alchemy.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { forwardRef, Module } from '@nestjs/common'
import { Module } from '@nestjs/common'
import { EcoConfigModule } from '../eco-configs/eco-config.module'
import { AlchemyService } from './alchemy.service'
import { SignModule } from '../sign/sign.module'
import { MultichainSmartAccountService } from './multichain_smart_account.service'
import { MultichainPublicClientService } from './multichain-public-client.service'

@Module({
imports: [EcoConfigModule, forwardRef(() => SignModule)],
imports: [EcoConfigModule, SignModule],

providers: [
AlchemyService,
Expand Down
5 changes: 2 additions & 3 deletions src/alchemy/multichain-atomic-smart-account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
SmartAccountClientConfig,
} from '@alchemy/aa-core'
import { ViemMultichainClientService } from './viem_multichain_client.service'
import { http } from 'viem'
import { getAchemyRPCUrl } from '../common/utils/strings'
import { createMultiOwnerModularAccount } from '@alchemy/aa-accounts'
import { EcoConfigService } from '../eco-configs/eco-config.service'
import { AtomicSignerService } from '../sign/atomic-signer.service'
import { getTransport } from './utils'

@Injectable()
export class MultichainAtomicSmartAccountService extends ViemMultichainClientService<
Expand All @@ -34,7 +33,7 @@ export class MultichainAtomicSmartAccountService extends ViemMultichainClientSer
protected override async buildChainConfig(
chain: chains.Chain,
): Promise<SmartAccountClientConfig> {
const rpcTransport = http(getAchemyRPCUrl(chain, this.apiKey))
const rpcTransport = getTransport(chain, this.apiKey, true)
return {
transport: rpcTransport as any,
chain: chain,
Expand Down
5 changes: 2 additions & 3 deletions src/alchemy/multichain_smart_account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
SmartAccountClientConfig,
} from '@alchemy/aa-core'
import { ViemMultichainClientService } from './viem_multichain_client.service'
import { http } from 'viem'
import { getAchemyRPCUrl } from '../common/utils/strings'
import { createMultiOwnerModularAccount } from '@alchemy/aa-accounts'
import { EcoConfigService } from '../eco-configs/eco-config.service'
import { SignerService } from '../sign/signer.service'
import { getTransport } from './utils'

@Injectable()
export class MultichainSmartAccountService extends ViemMultichainClientService<
Expand All @@ -38,7 +37,7 @@ export class MultichainSmartAccountService extends ViemMultichainClientService<
protected override async buildChainConfig(
chain: chains.Chain,
): Promise<SmartAccountClientConfig> {
const rpcTransport = http(getAchemyRPCUrl(chain, this.apiKey))
const rpcTransport = getTransport(chain, this.apiKey, true)
return {
transport: rpcTransport as any,
chain: chain,
Expand Down
37 changes: 37 additions & 0 deletions src/alchemy/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { chains } from '@alchemy/aa-core'
import { http, HttpTransport, webSocket, WebSocketTransport } from 'viem'

/**
* Merges the two strings into a valid api url
* @param rpc the rpc endpoint
* @param apiKey the alchemy api key
* @returns
*/
export function getAchemyRPCUrl(
chain: chains.Chain,
apiKey: string,
websocketEnabled: boolean = true,
): string {
const url =
websocketEnabled && chain.rpcUrls.alchemy.webSocket
? chain.rpcUrls.alchemy.webSocket[0]
: chain.rpcUrls.alchemy.http[0]
return url + '/' + apiKey
}

/**
* Returns a transport for the chain with the given api key
*
* @param chain the chain to get the transport for
* @param apiKey the alchemy api key
* @param websocketEnabled whether to use websocket or not, defaults to true
* @returns the websocket or http transport
*/
export function getTransport(
chain: chains.Chain,
apiKey: string,
websocketEnabled: boolean = true,
): WebSocketTransport | HttpTransport {
const url = getAchemyRPCUrl(chain, apiKey, websocketEnabled)
return websocketEnabled ? webSocket(url) : http(url)
}
6 changes: 3 additions & 3 deletions src/alchemy/viem_multichain_client.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable, OnModuleInit } from '@nestjs/common'
import { EcoConfigService } from '../eco-configs/eco-config.service'
import { chains } from '@alchemy/aa-core'
import { createClient, extractChain, http } from 'viem'
import { createClient, extractChain } from 'viem'
import { EcoError } from '../common/errors/eco-error'
import { ChainsSupported } from '../common/utils/chains'
import { getAchemyRPCUrl } from '../common/utils/strings'
import { getTransport } from './utils'

@Injectable()
export class ViemMultichainClientService<T, V> implements OnModuleInit {
Expand Down Expand Up @@ -70,7 +70,7 @@ export class ViemMultichainClientService<T, V> implements OnModuleInit {
}

protected async buildChainConfig(chain: chains.Chain): Promise<V> {
const rpcTransport = http(getAchemyRPCUrl(chain, this.apiKey))
const rpcTransport = getTransport(chain, this.apiKey, true)
return {
transport: rpcTransport,
chain: chain,
Expand Down
43 changes: 23 additions & 20 deletions src/assets/abis/IntentSource.json

Large diffs are not rendered by default.

Loading

0 comments on commit 665a5fb

Please sign in to comment.