@eth-optimism/actions-sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +9 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +12 -1
- package/dist/actions.js.map +1 -1
- package/dist/ens/EnsNamespace.d.ts +57 -0
- package/dist/ens/EnsNamespace.d.ts.map +1 -0
- package/dist/ens/EnsNamespace.js +158 -0
- package/dist/ens/EnsNamespace.js.map +1 -0
- package/dist/ens/EnsNamespace.spec.d.ts +2 -0
- package/dist/ens/EnsNamespace.spec.d.ts.map +1 -0
- package/dist/ens/EnsNamespace.spec.js +144 -0
- package/dist/ens/EnsNamespace.spec.js.map +1 -0
- package/dist/ens/errors.d.ts +24 -0
- package/dist/ens/errors.d.ts.map +1 -0
- package/dist/ens/errors.js +35 -0
- package/dist/ens/errors.js.map +1 -0
- package/dist/ens/index.d.ts +4 -0
- package/dist/ens/index.d.ts.map +1 -0
- package/dist/ens/index.js +4 -0
- package/dist/ens/index.js.map +1 -0
- package/dist/ens/types.d.ts +63 -0
- package/dist/ens/types.d.ts.map +1 -0
- package/dist/ens/types.js +14 -0
- package/dist/ens/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/services/ChainManager.d.ts +7 -0
- package/dist/services/ChainManager.d.ts.map +1 -1
- package/dist/services/ChainManager.js +9 -0
- package/dist/services/ChainManager.js.map +1 -1
- package/dist/services/__mocks__/MockChainManager.d.ts +1 -0
- package/dist/services/__mocks__/MockChainManager.d.ts.map +1 -1
- package/dist/services/__mocks__/MockChainManager.js +5 -0
- package/dist/services/__mocks__/MockChainManager.js.map +1 -1
- package/dist/swap/core/SwapProvider.d.ts +6 -6
- package/dist/swap/core/SwapProvider.d.ts.map +1 -1
- package/dist/swap/core/SwapProvider.js +4 -8
- package/dist/swap/core/SwapProvider.js.map +1 -1
- package/dist/swap/namespaces/BaseSwapNamespace.d.ts +3 -1
- package/dist/swap/namespaces/BaseSwapNamespace.d.ts.map +1 -1
- package/dist/swap/namespaces/BaseSwapNamespace.js +16 -11
- package/dist/swap/namespaces/BaseSwapNamespace.js.map +1 -1
- package/dist/swap/namespaces/WalletSwapNamespace.d.ts +2 -1
- package/dist/swap/namespaces/WalletSwapNamespace.d.ts.map +1 -1
- package/dist/swap/namespaces/WalletSwapNamespace.js +9 -4
- package/dist/swap/namespaces/WalletSwapNamespace.js.map +1 -1
- package/dist/swap/namespaces/__tests__/BaseSwapNamespace.spec.js +4 -4
- package/dist/swap/namespaces/__tests__/BaseSwapNamespace.spec.js.map +1 -1
- package/dist/swap/providers/uniswap/UniswapSwapProvider.d.ts +3 -2
- package/dist/swap/providers/uniswap/UniswapSwapProvider.d.ts.map +1 -1
- package/dist/swap/providers/uniswap/UniswapSwapProvider.js.map +1 -1
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.d.ts +3 -2
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.d.ts.map +1 -1
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.js.map +1 -1
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.js +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.js.map +1 -1
- package/dist/types/swap/base.d.ts +5 -4
- package/dist/types/swap/base.d.ts.map +1 -1
- package/dist/types/swap/base.js.map +1 -1
- package/dist/utils/ens.d.ts +25 -0
- package/dist/utils/ens.d.ts.map +1 -0
- package/dist/utils/ens.js +53 -0
- package/dist/utils/ens.js.map +1 -0
- package/dist/utils/ens.test.d.ts +2 -0
- package/dist/utils/ens.test.d.ts.map +1 -0
- package/dist/utils/ens.test.js +75 -0
- package/dist/utils/ens.test.js.map +1 -0
- package/dist/utils/validation.d.ts +5 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +10 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/wallet/core/wallets/abstract/Wallet.d.ts.map +1 -1
- package/dist/wallet/core/wallets/abstract/Wallet.js +3 -1
- package/dist/wallet/core/wallets/abstract/Wallet.js.map +1 -1
- package/package.json +1 -1
- package/src/actions.ts +15 -0
- package/src/ens/EnsNamespace.spec.ts +171 -0
- package/src/ens/EnsNamespace.ts +210 -0
- package/src/ens/errors.ts +45 -0
- package/src/ens/index.ts +12 -0
- package/src/ens/types.ts +76 -0
- package/src/index.ts +9 -0
- package/src/services/ChainManager.ts +10 -0
- package/src/services/__mocks__/MockChainManager.ts +8 -0
- package/src/swap/core/SwapProvider.ts +16 -15
- package/src/swap/namespaces/BaseSwapNamespace.ts +43 -27
- package/src/swap/namespaces/WalletSwapNamespace.ts +12 -4
- package/src/swap/namespaces/__tests__/BaseSwapNamespace.spec.ts +4 -0
- package/src/swap/providers/uniswap/UniswapSwapProvider.ts +4 -2
- package/src/swap/providers/velodrome/VelodromeSwapProvider.ts +4 -2
- package/src/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.ts +1 -0
- package/src/types/swap/base.ts +5 -4
- package/src/utils/ens.test.ts +104 -0
- package/src/utils/ens.ts +85 -0
- package/src/utils/validation.ts +11 -0
- package/src/wallet/core/wallets/abstract/Wallet.ts +3 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EnsNamespace } from '../../../../ens/index.js';
|
|
1
2
|
import { WalletLendNamespace } from '../../../../lend/namespaces/WalletLendNamespace.js';
|
|
2
3
|
import { fetchERC20Balance, fetchETHBalance } from '../../../../services/tokenBalance.js';
|
|
3
4
|
import { WalletSwapNamespace } from '../../../../swap/namespaces/WalletSwapNamespace.js';
|
|
@@ -23,7 +24,8 @@ export class Wallet {
|
|
|
23
24
|
this.lend = new WalletLendNamespace(this.lendProviders, this);
|
|
24
25
|
}
|
|
25
26
|
if (Object.values(this.swapProviders).some(Boolean)) {
|
|
26
|
-
|
|
27
|
+
const ens = new EnsNamespace(this.chainManager);
|
|
28
|
+
this.swap = new WalletSwapNamespace(this.swapProviders, this, (r) => (r ? ens.getAddress(r) : Promise.resolve(undefined)), swapSettings);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Wallet.js","sourceRoot":"","sources":["../../../../../src/wallet/core/wallets/abstract/Wallet.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAE9E,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAU9E;;;;GAIG;AACH,MAAM,OAAgB,MAAM;IA+B1B;;;;;;OAMG;IACH,YACE,YAA0B,EAC1B,aAA6B,EAC7B,aAA6B,EAC7B,eAAyB,EACzB,YAA2B;QAE3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,EAAE,CAAA;QAC5C,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YACzD,IAAI,CAAC,IAAI,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;QAC/D,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACpD,IAAI,CAAC,IAAI,GAAG,IAAI,mBAAmB,CACjC,IAAI,CAAC,aAAa,EAClB,IAAI,EACJ,YAAY,CACb,CAAA;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,oBAAoB,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACpE,OAAO,iBAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAClE,CAAC,CAAC,CAAA;QACF,MAAM,iBAAiB,GAAG,eAAe,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QAE1E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,GAAG,oBAAoB,CAAC,CAAC,CAAA;IAClE,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACO,KAAK,CAAC,qBAAqB,KAAmB,CAAC;IAEzD;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,UAAU;QACxB,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAA;QAC7C,IAAI,CAAC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;YAC7B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAA;YACpC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,sDAAsD;gBACtD,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;gBAC5B,MAAM,IAAI,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YAClE,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;CAyBF"}
|
|
1
|
+
{"version":3,"file":"Wallet.js","sourceRoot":"","sources":["../../../../../src/wallet/core/wallets/abstract/Wallet.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAE9E,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAU9E;;;;GAIG;AACH,MAAM,OAAgB,MAAM;IA+B1B;;;;;;OAMG;IACH,YACE,YAA0B,EAC1B,aAA6B,EAC7B,aAA6B,EAC7B,eAAyB,EACzB,YAA2B;QAE3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,EAAE,CAAA;QACxC,IAAI,CAAC,eAAe,GAAG,eAAe,IAAI,EAAE,CAAA;QAC5C,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YACzD,IAAI,CAAC,IAAI,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;QAC/D,CAAC;QACD,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACpD,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,mBAAmB,CACjC,IAAI,CAAC,aAAa,EAClB,IAAI,EACJ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAC3D,YAAY,CACb,CAAA;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,oBAAoB,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACpE,OAAO,iBAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAClE,CAAC,CAAC,CAAA;QACF,MAAM,iBAAiB,GAAG,eAAe,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QAE1E,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAE,GAAG,oBAAoB,CAAC,CAAC,CAAA;IAClE,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACO,KAAK,CAAC,qBAAqB,KAAmB,CAAC;IAEzD;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,UAAU;QACxB,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAA;QAC7C,IAAI,CAAC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;YAC7B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAA;YACpC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,sDAAsD;gBACtD,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;gBAC5B,MAAM,IAAI,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YAClE,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;CAyBF"}
|
package/package.json
CHANGED
package/src/actions.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EnsNamespace } from '@/ens/index.js'
|
|
1
2
|
import { AaveLendProvider, MorphoLendProvider } from '@/lend/index.js'
|
|
2
3
|
import { ActionsLendNamespace } from '@/lend/namespaces/ActionsLendNamespace.js'
|
|
3
4
|
import { ChainManager } from '@/services/ChainManager.js'
|
|
@@ -47,6 +48,7 @@ export class Actions<
|
|
|
47
48
|
SmartWalletProvider
|
|
48
49
|
>
|
|
49
50
|
private chainManager: ChainManager
|
|
51
|
+
private _ens: EnsNamespace
|
|
50
52
|
private _lend?: ActionsLendNamespace
|
|
51
53
|
private _lendProviders: LendProviders = {}
|
|
52
54
|
private _swap?: ActionsSwapNamespace
|
|
@@ -76,6 +78,8 @@ export class Actions<
|
|
|
76
78
|
this._assetsConfig = config.assets
|
|
77
79
|
validateConfigAddresses(config)
|
|
78
80
|
|
|
81
|
+
this._ens = new EnsNamespace(this.chainManager)
|
|
82
|
+
|
|
79
83
|
if (config.lend?.morpho) {
|
|
80
84
|
this._lendProviders.morpho = new MorphoLendProvider(
|
|
81
85
|
config.lend.morpho,
|
|
@@ -111,6 +115,7 @@ export class Actions<
|
|
|
111
115
|
if (Object.values(this._swapProviders).some(Boolean)) {
|
|
112
116
|
this._swap = new ActionsSwapNamespace(
|
|
113
117
|
this._swapProviders,
|
|
118
|
+
(r) => (r ? this._ens.getAddress(r) : Promise.resolve(undefined)),
|
|
114
119
|
this._swapSettings,
|
|
115
120
|
)
|
|
116
121
|
}
|
|
@@ -142,6 +147,16 @@ export class Actions<
|
|
|
142
147
|
return this._lendProviders
|
|
143
148
|
}
|
|
144
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Get ENS operations interface
|
|
152
|
+
* @description Access to Ethereum Name Service operations: resolve, reverseResolve, lookupText.
|
|
153
|
+
* Requires Ethereum mainnet (chain ID 1) to be included in your chain configuration.
|
|
154
|
+
* @returns EnsNamespace for ENS operations
|
|
155
|
+
*/
|
|
156
|
+
get ens(): EnsNamespace {
|
|
157
|
+
return this._ens
|
|
158
|
+
}
|
|
159
|
+
|
|
145
160
|
/**
|
|
146
161
|
* Get swap operations interface
|
|
147
162
|
* @description Access to swap operations like price quotes and markets.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { Address, PublicClient } from 'viem'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
import type { ChainManager } from '@/services/ChainManager.js'
|
|
5
|
+
|
|
6
|
+
import { EnsNamespace } from './EnsNamespace.js'
|
|
7
|
+
import { EnsResolutionError, EnsRpcError } from './errors.js'
|
|
8
|
+
import type { EnsName } from './types.js'
|
|
9
|
+
|
|
10
|
+
const REAL_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' as Address
|
|
11
|
+
const ENS_NAME = 'vitalik.eth' as EnsName
|
|
12
|
+
|
|
13
|
+
function mockChainManager(client?: Partial<PublicClient>): ChainManager {
|
|
14
|
+
const tryGetPublicClient = client
|
|
15
|
+
? vi.fn().mockReturnValue(client)
|
|
16
|
+
: vi.fn().mockReturnValue(undefined)
|
|
17
|
+
return { tryGetPublicClient } as unknown as ChainManager
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function mockClient(
|
|
21
|
+
overrides: Partial<PublicClient> = {},
|
|
22
|
+
): Partial<PublicClient> {
|
|
23
|
+
return {
|
|
24
|
+
getEnsAddress: vi.fn().mockResolvedValue(REAL_ADDRESS),
|
|
25
|
+
getEnsName: vi.fn().mockResolvedValue(ENS_NAME),
|
|
26
|
+
getEnsText: vi.fn().mockResolvedValue(null),
|
|
27
|
+
...overrides,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('EnsNamespace', () => {
|
|
32
|
+
describe('getAddress', () => {
|
|
33
|
+
it('resolves a hex address directly', async () => {
|
|
34
|
+
const ens = new EnsNamespace(mockChainManager())
|
|
35
|
+
expect(await ens.getAddress(REAL_ADDRESS)).toBe(REAL_ADDRESS)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('resolves an ENS name via mainnet client', async () => {
|
|
39
|
+
const client = mockClient()
|
|
40
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
41
|
+
expect(await ens.getAddress(ENS_NAME)).toBe(REAL_ADDRESS)
|
|
42
|
+
expect(client.getEnsAddress).toHaveBeenCalledWith({ name: ENS_NAME })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('caches resolved addresses on subsequent calls', async () => {
|
|
46
|
+
const client = mockClient()
|
|
47
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
48
|
+
await ens.getAddress(ENS_NAME)
|
|
49
|
+
await ens.getAddress(ENS_NAME)
|
|
50
|
+
expect(client.getEnsAddress).toHaveBeenCalledTimes(1)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('getName', () => {
|
|
55
|
+
it('returns ENS name for a known address', async () => {
|
|
56
|
+
const client = mockClient()
|
|
57
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
58
|
+
expect(await ens.getName(REAL_ADDRESS)).toBe(ENS_NAME)
|
|
59
|
+
expect(client.getEnsName).toHaveBeenCalledWith({ address: REAL_ADDRESS })
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('returns null when no primary name is set', async () => {
|
|
63
|
+
const client = mockClient({ getEnsName: vi.fn().mockResolvedValue(null) })
|
|
64
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
65
|
+
expect(await ens.getName(REAL_ADDRESS)).toBeNull()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('throws EnsRpcError on RPC failure', async () => {
|
|
69
|
+
const client = mockClient({
|
|
70
|
+
getEnsName: vi.fn().mockRejectedValue(new Error('rpc down')),
|
|
71
|
+
})
|
|
72
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
73
|
+
await expect(ens.getName(REAL_ADDRESS)).rejects.toThrow(EnsRpcError)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('caches results on subsequent calls', async () => {
|
|
77
|
+
const client = mockClient()
|
|
78
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
79
|
+
await ens.getName(REAL_ADDRESS)
|
|
80
|
+
await ens.getName(REAL_ADDRESS)
|
|
81
|
+
expect(client.getEnsName).toHaveBeenCalledTimes(1)
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('caches null results', async () => {
|
|
85
|
+
const client = mockClient({ getEnsName: vi.fn().mockResolvedValue(null) })
|
|
86
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
87
|
+
await ens.getName(REAL_ADDRESS)
|
|
88
|
+
await ens.getName(REAL_ADDRESS)
|
|
89
|
+
expect(client.getEnsName).toHaveBeenCalledTimes(1)
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('getInfo', () => {
|
|
94
|
+
it('returns all-null EnsInfo when address has no primary name', async () => {
|
|
95
|
+
const client = mockClient({ getEnsName: vi.fn().mockResolvedValue(null) })
|
|
96
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
97
|
+
const info = await ens.getInfo(REAL_ADDRESS)
|
|
98
|
+
expect(info).toEqual({
|
|
99
|
+
avatar: null,
|
|
100
|
+
display: null,
|
|
101
|
+
description: null,
|
|
102
|
+
url: null,
|
|
103
|
+
email: null,
|
|
104
|
+
keywords: null,
|
|
105
|
+
twitter: null,
|
|
106
|
+
github: null,
|
|
107
|
+
discord: null,
|
|
108
|
+
reddit: null,
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('returns all text record fields when name is given', async () => {
|
|
113
|
+
const client = mockClient({
|
|
114
|
+
getEnsText: vi.fn().mockResolvedValue('test-value'),
|
|
115
|
+
})
|
|
116
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
117
|
+
const info = await ens.getInfo(ENS_NAME)
|
|
118
|
+
expect(info.avatar).toBe('test-value')
|
|
119
|
+
expect(info.twitter).toBe('test-value')
|
|
120
|
+
expect(info.github).toBe('test-value')
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('returns null fields when text records are not set', async () => {
|
|
124
|
+
const client = mockClient({ getEnsText: vi.fn().mockResolvedValue(null) })
|
|
125
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
126
|
+
const info = await ens.getInfo(ENS_NAME)
|
|
127
|
+
expect(info.avatar).toBeNull()
|
|
128
|
+
expect(info.twitter).toBeNull()
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('fetches all 10 standard keys in parallel', async () => {
|
|
132
|
+
const client = mockClient({ getEnsText: vi.fn().mockResolvedValue(null) })
|
|
133
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
134
|
+
await ens.getInfo(ENS_NAME)
|
|
135
|
+
expect(client.getEnsText).toHaveBeenCalledTimes(10)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('throws EnsRpcError on text lookup RPC failure', async () => {
|
|
139
|
+
const client = mockClient({
|
|
140
|
+
getEnsText: vi.fn().mockRejectedValue(new Error('rpc down')),
|
|
141
|
+
})
|
|
142
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
143
|
+
await expect(ens.getInfo(ENS_NAME)).rejects.toThrow(EnsRpcError)
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('throws EnsResolutionError when the resolved name fails normalization', async () => {
|
|
147
|
+
const client = mockClient({
|
|
148
|
+
getEnsName: vi.fn().mockResolvedValue('not!valid.eth'),
|
|
149
|
+
})
|
|
150
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
151
|
+
await expect(ens.getInfo(REAL_ADDRESS)).rejects.toThrow(
|
|
152
|
+
EnsResolutionError,
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('skips reverse resolution when input is already an EnsName', async () => {
|
|
157
|
+
const client = mockClient({ getEnsText: vi.fn().mockResolvedValue(null) })
|
|
158
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
159
|
+
await ens.getInfo(ENS_NAME)
|
|
160
|
+
expect(client.getEnsName).not.toHaveBeenCalled()
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('caches results on subsequent calls', async () => {
|
|
164
|
+
const client = mockClient({ getEnsText: vi.fn().mockResolvedValue(null) })
|
|
165
|
+
const ens = new EnsNamespace(mockChainManager(client))
|
|
166
|
+
await ens.getInfo(ENS_NAME)
|
|
167
|
+
await ens.getInfo(ENS_NAME)
|
|
168
|
+
expect(client.getEnsText).toHaveBeenCalledTimes(10)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
})
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { type Address, createPublicClient, http } from 'viem'
|
|
2
|
+
import { mainnet } from 'viem/chains'
|
|
3
|
+
import { normalize } from 'viem/ens'
|
|
4
|
+
|
|
5
|
+
import type { ChainManager } from '@/services/ChainManager.js'
|
|
6
|
+
import { resolveAddress } from '@/utils/ens.js'
|
|
7
|
+
|
|
8
|
+
import { EnsResolutionError, EnsRpcError } from './errors.js'
|
|
9
|
+
import {
|
|
10
|
+
type EnsInfo,
|
|
11
|
+
type EnsName,
|
|
12
|
+
isEnsName,
|
|
13
|
+
type NameServiceProvider,
|
|
14
|
+
} from './types.js'
|
|
15
|
+
|
|
16
|
+
/** Default TTL for cached ENS lookups — 5 minutes */
|
|
17
|
+
const DEFAULT_CACHE_TTL_MS = 5 * 60 * 1000
|
|
18
|
+
|
|
19
|
+
/** Public mainnet RPC used as fallback when mainnet is not in chain config */
|
|
20
|
+
const FALLBACK_MAINNET_RPC = 'https://cloudflare-eth.com'
|
|
21
|
+
|
|
22
|
+
/** ENSIP-5 / ENSIP-18 standard text record keys mapped to EnsInfo field names */
|
|
23
|
+
const ENS_TEXT_KEYS = {
|
|
24
|
+
avatar: 'avatar',
|
|
25
|
+
display: 'display',
|
|
26
|
+
description: 'description',
|
|
27
|
+
url: 'url',
|
|
28
|
+
email: 'email',
|
|
29
|
+
keywords: 'keywords',
|
|
30
|
+
twitter: 'com.twitter',
|
|
31
|
+
github: 'com.github',
|
|
32
|
+
discord: 'com.discord',
|
|
33
|
+
reddit: 'org.reddit',
|
|
34
|
+
} as const satisfies Record<keyof EnsInfo, string>
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Namespace for human-readable name resolution on Ethereum.
|
|
38
|
+
* Currently backed by ENS (Ethereum Name Service) on mainnet.
|
|
39
|
+
*
|
|
40
|
+
* Implements {@link NameServiceProvider} — designed to be extensible: future
|
|
41
|
+
* versions could support alternative name services alongside ENS (e.g. Basename,
|
|
42
|
+
* Unstoppable Domains, Lens handles). The natural evolution is additional
|
|
43
|
+
* NameServiceProvider implementations registered under their own namespace
|
|
44
|
+
* (e.g. `actions.basename`).
|
|
45
|
+
*
|
|
46
|
+
* Falls back to a public mainnet RPC automatically if mainnet is not included
|
|
47
|
+
* in your chain configuration, so ENS works even in L2-only setups.
|
|
48
|
+
*/
|
|
49
|
+
export class EnsNamespace implements NameServiceProvider {
|
|
50
|
+
private chainManager: ChainManager
|
|
51
|
+
private readonly cacheTtlMs: number
|
|
52
|
+
private addressCache = new Map<
|
|
53
|
+
string,
|
|
54
|
+
{ value: Address; expiresAt: number }
|
|
55
|
+
>()
|
|
56
|
+
private nameCache = new Map<
|
|
57
|
+
Address,
|
|
58
|
+
{ value: EnsName | null; expiresAt: number }
|
|
59
|
+
>()
|
|
60
|
+
private infoCache = new Map<string, { value: EnsInfo; expiresAt: number }>()
|
|
61
|
+
|
|
62
|
+
constructor(chainManager: ChainManager, cacheTtlMs = DEFAULT_CACHE_TTL_MS) {
|
|
63
|
+
this.chainManager = chainManager
|
|
64
|
+
this.cacheTtlMs = cacheTtlMs
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolve an ENS name or hex address to a checksummed hex address.
|
|
69
|
+
* Hex addresses are returned as-is after format validation.
|
|
70
|
+
*
|
|
71
|
+
* If you need to resolve outside of an {@link Actions} instance (e.g. in a
|
|
72
|
+
* provider or script), use the lower-level `resolveAddress` utility instead.
|
|
73
|
+
* @param input - Hex address (0x...) or ENS name (e.g. "vitalik.eth")
|
|
74
|
+
* @returns Resolved hex address
|
|
75
|
+
* @throws {EnsResolutionError} If the name cannot be resolved
|
|
76
|
+
* @throws {EnsRpcError} If the RPC call fails
|
|
77
|
+
*/
|
|
78
|
+
async getAddress(input: Address | EnsName): Promise<Address> {
|
|
79
|
+
const cached = this.addressCache.get(input)
|
|
80
|
+
if (cached && Date.now() < cached.expiresAt) return cached.value
|
|
81
|
+
const value = await resolveAddress(input, this.getMainnetClient())
|
|
82
|
+
this.addressCache.set(input, {
|
|
83
|
+
value,
|
|
84
|
+
expiresAt: Date.now() + this.cacheTtlMs,
|
|
85
|
+
})
|
|
86
|
+
return value
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Reverse-resolve an address to its primary ENS name.
|
|
91
|
+
* @param address - Hex address to look up
|
|
92
|
+
* @returns ENS name, or null if none is set
|
|
93
|
+
* @throws {EnsRpcError} If the RPC call fails
|
|
94
|
+
*/
|
|
95
|
+
async getName(address: Address): Promise<EnsName | null> {
|
|
96
|
+
const cached = this.nameCache.get(address)
|
|
97
|
+
if (cached && Date.now() < cached.expiresAt) return cached.value
|
|
98
|
+
const name = await this.getMainnetClient()
|
|
99
|
+
.getEnsName({ address })
|
|
100
|
+
.catch((cause: unknown) => {
|
|
101
|
+
throw new EnsRpcError(
|
|
102
|
+
`ENS reverse resolution failed for "${address}": RPC error`,
|
|
103
|
+
address,
|
|
104
|
+
{ cause },
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
const value = name && isEnsName(name) ? name : null
|
|
108
|
+
this.nameCache.set(address, {
|
|
109
|
+
value,
|
|
110
|
+
expiresAt: Date.now() + this.cacheTtlMs,
|
|
111
|
+
})
|
|
112
|
+
return value
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Fetch all standard ENS profile text record fields (ENSIP-5 / ENSIP-18)
|
|
117
|
+
* for an ENS name or address in a single batched call.
|
|
118
|
+
*
|
|
119
|
+
* All fields are null when not set. Returns all-null if the address has
|
|
120
|
+
* no primary ENS name.
|
|
121
|
+
* @param input - Hex address (0x...) or ENS name
|
|
122
|
+
* @returns EnsInfo object with all standard text record fields
|
|
123
|
+
* @throws {EnsResolutionError} If the name cannot be normalized
|
|
124
|
+
* @throws {EnsRpcError} If the RPC call fails
|
|
125
|
+
*/
|
|
126
|
+
async getInfo(input: Address | EnsName): Promise<EnsInfo> {
|
|
127
|
+
const name = isEnsName(input) ? input : await this.getName(input)
|
|
128
|
+
if (!name) return nullInfo()
|
|
129
|
+
|
|
130
|
+
const cached = this.infoCache.get(name)
|
|
131
|
+
if (cached && Date.now() < cached.expiresAt) return cached.value
|
|
132
|
+
|
|
133
|
+
const normalized = (() => {
|
|
134
|
+
try {
|
|
135
|
+
return normalize(name)
|
|
136
|
+
} catch (cause) {
|
|
137
|
+
throw new EnsResolutionError(
|
|
138
|
+
`ENS name "${name}" is invalid and cannot be normalized`,
|
|
139
|
+
name,
|
|
140
|
+
{ cause },
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
})()
|
|
144
|
+
|
|
145
|
+
const client = this.getMainnetClient()
|
|
146
|
+
const fetchKey = (key: string) =>
|
|
147
|
+
client.getEnsText({ name: normalized, key }).catch((cause: unknown) => {
|
|
148
|
+
throw new EnsRpcError(
|
|
149
|
+
`ENS text record lookup failed for "${name}" key "${key}": RPC error`,
|
|
150
|
+
name,
|
|
151
|
+
{ cause },
|
|
152
|
+
)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
const [
|
|
156
|
+
avatar,
|
|
157
|
+
display,
|
|
158
|
+
description,
|
|
159
|
+
url,
|
|
160
|
+
email,
|
|
161
|
+
keywords,
|
|
162
|
+
twitter,
|
|
163
|
+
github,
|
|
164
|
+
discord,
|
|
165
|
+
reddit,
|
|
166
|
+
] = await Promise.all(Object.values(ENS_TEXT_KEYS).map(fetchKey))
|
|
167
|
+
|
|
168
|
+
const value: EnsInfo = {
|
|
169
|
+
avatar: avatar ?? null,
|
|
170
|
+
display: display ?? null,
|
|
171
|
+
description: description ?? null,
|
|
172
|
+
url: url ?? null,
|
|
173
|
+
email: email ?? null,
|
|
174
|
+
keywords: keywords ?? null,
|
|
175
|
+
twitter: twitter ?? null,
|
|
176
|
+
github: github ?? null,
|
|
177
|
+
discord: discord ?? null,
|
|
178
|
+
reddit: reddit ?? null,
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this.infoCache.set(name, { value, expiresAt: Date.now() + this.cacheTtlMs })
|
|
182
|
+
return value
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private getMainnetClient() {
|
|
186
|
+
return (
|
|
187
|
+
this.chainManager.tryGetPublicClient(mainnet.id) ??
|
|
188
|
+
createPublicClient({
|
|
189
|
+
chain: mainnet,
|
|
190
|
+
transport: http(FALLBACK_MAINNET_RPC),
|
|
191
|
+
batch: { multicall: true },
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function nullInfo(): EnsInfo {
|
|
198
|
+
return {
|
|
199
|
+
avatar: null,
|
|
200
|
+
display: null,
|
|
201
|
+
description: null,
|
|
202
|
+
url: null,
|
|
203
|
+
email: null,
|
|
204
|
+
keywords: null,
|
|
205
|
+
twitter: null,
|
|
206
|
+
github: null,
|
|
207
|
+
discord: null,
|
|
208
|
+
reddit: null,
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mainnet } from 'viem/chains'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when an ENS operation is attempted but the required chain is not
|
|
5
|
+
* included in the Actions chain configuration.
|
|
6
|
+
*/
|
|
7
|
+
export class EnsNotConfiguredError extends Error {
|
|
8
|
+
chainId: number
|
|
9
|
+
|
|
10
|
+
constructor(chainId = mainnet.id) {
|
|
11
|
+
super(
|
|
12
|
+
`ENS operations require Ethereum mainnet. ` +
|
|
13
|
+
`Add chain ID ${chainId} to your chain configuration.`,
|
|
14
|
+
)
|
|
15
|
+
this.name = 'EnsNotConfiguredError'
|
|
16
|
+
this.chainId = chainId
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Thrown when an ENS name cannot be resolved to an address — e.g. the name
|
|
22
|
+
* is unregistered, resolves to the zero address, or fails normalization.
|
|
23
|
+
*/
|
|
24
|
+
export class EnsResolutionError extends Error {
|
|
25
|
+
input: string
|
|
26
|
+
|
|
27
|
+
constructor(message: string, input: string, options?: ErrorOptions) {
|
|
28
|
+
super(message, options)
|
|
29
|
+
this.name = 'EnsResolutionError'
|
|
30
|
+
this.input = input
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Thrown when an ENS RPC call fails due to a network or provider error.
|
|
36
|
+
*/
|
|
37
|
+
export class EnsRpcError extends Error {
|
|
38
|
+
input: string
|
|
39
|
+
|
|
40
|
+
constructor(message: string, input: string, options?: ErrorOptions) {
|
|
41
|
+
super(message, options)
|
|
42
|
+
this.name = 'EnsRpcError'
|
|
43
|
+
this.input = input
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/ens/index.ts
ADDED
package/src/ens/types.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Address } from 'viem'
|
|
2
|
+
|
|
3
|
+
import type { SwapExecuteParams, SwapQuoteParams } from '@/types/swap/base.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A dot-separated ENS name (e.g. `vitalik.eth`, `sub.vitalik.eth`, `example.com`).
|
|
7
|
+
*
|
|
8
|
+
* ENS is not limited to `.eth` — it supports any DNSSEC-enabled DNS TLD as well
|
|
9
|
+
* as ENS-native TLDs (`.eth`, `.test`). Subdomains of arbitrary depth are valid.
|
|
10
|
+
*
|
|
11
|
+
* This type is a structural constraint (at least one dot) mirroring viem's Address type.
|
|
12
|
+
* True validity is determined at runtime by `normalize()` (ENSIP-15): a name is valid
|
|
13
|
+
* if and only if it does not throw during normalization.
|
|
14
|
+
*/
|
|
15
|
+
export type EnsName = `${string}.${string}`
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Type guard for EnsName. Mirrors the pattern of viem's isAddress.
|
|
19
|
+
* Rejects obviously invalid forms (leading/trailing dots, consecutive dots)
|
|
20
|
+
* but does not run full ENSIP-15 normalization — use normalize() for that.
|
|
21
|
+
* @param value - String to check
|
|
22
|
+
* @returns True if the value satisfies the EnsName structural constraint
|
|
23
|
+
*/
|
|
24
|
+
export function isEnsName(value: string): value is EnsName {
|
|
25
|
+
return (
|
|
26
|
+
value.includes('.') &&
|
|
27
|
+
!value.startsWith('.') &&
|
|
28
|
+
!value.endsWith('.') &&
|
|
29
|
+
!value.includes('..')
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Standard ENS profile text record fields as defined by ENSIP-5 and ENSIP-18.
|
|
35
|
+
* All fields are null when not set on the resolver.
|
|
36
|
+
*/
|
|
37
|
+
export interface EnsInfo {
|
|
38
|
+
avatar: string | null
|
|
39
|
+
display: string | null
|
|
40
|
+
description: string | null
|
|
41
|
+
url: string | null
|
|
42
|
+
email: string | null
|
|
43
|
+
keywords: string | null
|
|
44
|
+
/** com.twitter */
|
|
45
|
+
twitter: string | null
|
|
46
|
+
/** com.github */
|
|
47
|
+
github: string | null
|
|
48
|
+
/** com.discord */
|
|
49
|
+
discord: string | null
|
|
50
|
+
/** org.reddit */
|
|
51
|
+
reddit: string | null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** SwapExecuteParams with recipient narrowed to Address after ENS resolution */
|
|
55
|
+
export type SwapExecuteParamsResolved = Omit<SwapExecuteParams, 'recipient'> & {
|
|
56
|
+
recipient?: Address
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** SwapQuoteParams with recipient narrowed to Address after ENS resolution */
|
|
60
|
+
export type SwapQuoteParamsResolved = Omit<SwapQuoteParams, 'recipient'> & {
|
|
61
|
+
recipient?: Address
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Common interface for human-readable name service providers.
|
|
66
|
+
* Implemented by {@link EnsNamespace}; designed to support future providers
|
|
67
|
+
* such as Basename, Lens, Unstoppable Domains, etc.
|
|
68
|
+
*/
|
|
69
|
+
export interface NameServiceProvider {
|
|
70
|
+
/** Resolve a name or address to a checksummed hex address. */
|
|
71
|
+
getAddress(input: Address | EnsName): Promise<Address>
|
|
72
|
+
/** Reverse-resolve an address to its primary name, or null if not set. */
|
|
73
|
+
getName(address: Address): Promise<EnsName | null>
|
|
74
|
+
/** Fetch all standard profile text record fields in a single batched call. */
|
|
75
|
+
getInfo(input: Address | EnsName): Promise<EnsInfo>
|
|
76
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,14 @@ export {
|
|
|
52
52
|
type SupportedChainId,
|
|
53
53
|
} from '@/constants/supportedChains.js'
|
|
54
54
|
export * from '@/core/error/errors.js'
|
|
55
|
+
export {
|
|
56
|
+
type EnsInfo,
|
|
57
|
+
EnsNamespace,
|
|
58
|
+
EnsNotConfiguredError,
|
|
59
|
+
EnsResolutionError,
|
|
60
|
+
EnsRpcError,
|
|
61
|
+
type NameServiceProvider,
|
|
62
|
+
} from '@/ens/index.js'
|
|
55
63
|
export { LendProvider, MorphoLendProvider } from '@/lend/index.js'
|
|
56
64
|
export {
|
|
57
65
|
SwapProvider,
|
|
@@ -100,5 +108,6 @@ export type {
|
|
|
100
108
|
WalletSwapParams,
|
|
101
109
|
} from '@/types/index.js'
|
|
102
110
|
export { getAssetAddress, isAssetSupportedOnChain } from '@/utils/assets.js'
|
|
111
|
+
export { type EnsName, isEnsName, resolveAddress } from '@/utils/ens.js'
|
|
103
112
|
export { Wallet } from '@/wallet/core/wallets/abstract/Wallet.js'
|
|
104
113
|
export { SmartWallet } from '@/wallet/core/wallets/smart/abstract/SmartWallet.js'
|
|
@@ -49,6 +49,16 @@ export class ChainManager {
|
|
|
49
49
|
return client
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Get public client for a specific chain, or undefined if not configured.
|
|
54
|
+
* Use this when the chain is optional (e.g. mainnet for ENS resolution).
|
|
55
|
+
* @param chainId - The chain ID to retrieve the public client for
|
|
56
|
+
* @returns PublicClient instance, or undefined if not configured
|
|
57
|
+
*/
|
|
58
|
+
tryGetPublicClient(chainId: SupportedChainId): PublicClient | undefined {
|
|
59
|
+
return this.publicClients.get(chainId)
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
/**
|
|
53
63
|
* Get bundler client for a specific chain
|
|
54
64
|
* @param chainId - The chain ID to retrieve the bundler client for
|
|
@@ -21,6 +21,9 @@ export class MockChainManager {
|
|
|
21
21
|
public getPublicClient: MockedFunction<
|
|
22
22
|
(chainId: SupportedChainId) => PublicClient
|
|
23
23
|
>
|
|
24
|
+
public tryGetPublicClient: MockedFunction<
|
|
25
|
+
(chainId: SupportedChainId) => PublicClient | undefined
|
|
26
|
+
>
|
|
24
27
|
public getBundlerClient: MockedFunction<
|
|
25
28
|
(chainId: SupportedChainId, account: SmartAccount) => BundlerClient
|
|
26
29
|
>
|
|
@@ -54,6 +57,11 @@ export class MockChainManager {
|
|
|
54
57
|
}
|
|
55
58
|
return client
|
|
56
59
|
})
|
|
60
|
+
this.tryGetPublicClient = vi
|
|
61
|
+
.fn()
|
|
62
|
+
.mockImplementation((chainId: SupportedChainId) => {
|
|
63
|
+
return this.publicClients.get(chainId)
|
|
64
|
+
})
|
|
57
65
|
this.getBundlerClient = vi
|
|
58
66
|
.fn()
|
|
59
67
|
.mockImplementation((chainId: SupportedChainId) => {
|