Skip to content

Commit 0e3f7eb

Browse files
committed
Remove redundant NarrowAbiToFunction utility type
1 parent fb2b61d commit 0e3f7eb

File tree

7 files changed

+7
-56
lines changed

7 files changed

+7
-56
lines changed

packages/smart-accounts-kit/src/DelegationFramework/DeleGatorCore/methods/disableDelegation.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { simulateContract, writeContract } from 'viem/actions';
66
import { toDelegationStruct } from '../../../delegation';
77
import type { Delegation } from '../../../types';
88
import type { InitializedClient } from '../../types';
9-
import type { NarrowAbiToFunction } from '../../utils';
109

1110
export type SimulateDisableDelegationParameters = {
1211
client: Client;
@@ -29,16 +28,11 @@ export const simulate = async ({
2928
delegationManagerAddress,
3029
delegation,
3130
}: SimulateDisableDelegationParameters) => {
32-
const abi = DeleGatorCore as any as NarrowAbiToFunction<
33-
typeof DeleGatorCore,
34-
'disableDelegation'
35-
>;
36-
3731
const delegationStruct = toDelegationStruct(delegation);
3832

3933
return simulateContract(client, {
4034
address: delegationManagerAddress,
41-
abi,
35+
abi: DeleGatorCore,
4236
functionName: 'disableDelegation',
4337
args: [delegationStruct],
4438
});

packages/smart-accounts-kit/src/DelegationFramework/DeleGatorCore/methods/enableDelegation.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { simulateContract, writeContract } from 'viem/actions';
66
import { toDelegationStruct } from '../../../delegation';
77
import type { Delegation } from '../../../types';
88
import type { InitializedClient } from '../../types';
9-
import type { NarrowAbiToFunction } from '../../utils';
109

1110
export type SimulateEnableDelegationParameters = {
1211
client: Client;
@@ -29,16 +28,11 @@ export const simulate = async ({
2928
delegationManagerAddress,
3029
delegation,
3130
}: SimulateEnableDelegationParameters) => {
32-
const abi = DeleGatorCore as any as NarrowAbiToFunction<
33-
typeof DeleGatorCore,
34-
'enableDelegation'
35-
>;
36-
3731
const delegationStruct = toDelegationStruct(delegation);
3832

3933
return simulateContract(client, {
4034
address: delegationManagerAddress,
41-
abi,
35+
abi: DeleGatorCore,
4236
functionName: 'enableDelegation',
4337
args: [delegationStruct],
4438
});

packages/smart-accounts-kit/src/DelegationFramework/DelegationManager/methods/disableDelegation.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { simulateContract, writeContract } from 'viem/actions';
66
import { toDelegationStruct } from '../../../delegation';
77
import type { Delegation } from '../../../types';
88
import type { InitializedClient } from '../../types';
9-
import type { NarrowAbiToFunction } from '../../utils';
109

1110
export type EncodeDisableDelegationParameters = {
1211
delegation: Delegation;
@@ -27,16 +26,11 @@ export const simulate = async ({
2726
delegationManagerAddress,
2827
delegation,
2928
}: SimulateDisableDelegationParameters) => {
30-
const abi = DelegationManager as any as NarrowAbiToFunction<
31-
typeof DelegationManager,
32-
'disableDelegation'
33-
>;
34-
3529
const delegationStruct = toDelegationStruct(delegation);
3630

3731
return simulateContract(client, {
3832
address: delegationManagerAddress,
39-
abi,
33+
abi: DelegationManager,
4034
functionName: 'disableDelegation',
4135
args: [delegationStruct],
4236
});

packages/smart-accounts-kit/src/DelegationFramework/DelegationManager/methods/enableDelegation.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { simulateContract, writeContract } from 'viem/actions';
66
import { toDelegationStruct } from '../../../delegation';
77
import type { Delegation } from '../../../types';
88
import type { InitializedClient } from '../../types';
9-
import type { NarrowAbiToFunction } from '../../utils';
109

1110
export type EncodeEnableDelegationParameters = {
1211
delegation: Delegation;
@@ -27,16 +26,11 @@ export const simulate = async ({
2726
delegationManagerAddress,
2827
delegation,
2928
}: SimulateEnableDelegationParameters) => {
30-
const abi = DelegationManager as any as NarrowAbiToFunction<
31-
typeof DelegationManager,
32-
'enableDelegation'
33-
>;
34-
3529
const delegationStruct = toDelegationStruct(delegation);
3630

3731
return simulateContract(client, {
3832
address: delegationManagerAddress,
39-
abi,
33+
abi: DelegationManager,
4034
functionName: 'enableDelegation',
4135
args: [delegationStruct],
4236
});

packages/smart-accounts-kit/src/DelegationFramework/DelegationManager/methods/redeemDelegations.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { encodeExecutionCalldatas } from '../../../executions';
88
import type { ExecutionMode, ExecutionStruct } from '../../../executions';
99
import type { Delegation } from '../../../types';
1010
import type { InitializedClient } from '../../types';
11-
import type { NarrowAbiToFunction } from '../../utils';
1211

1312
export type EncodeRedeemDelegationsParameters = {
1413
delegations: Delegation[][];
@@ -33,14 +32,9 @@ export const simulate = async ({
3332
modes,
3433
executions,
3534
}: SimulateRedeemDelegationsParameters) => {
36-
const abi = DelegationManager as any as NarrowAbiToFunction<
37-
typeof DelegationManager,
38-
'redeemDelegations'
39-
>;
40-
4135
return simulateContract(client, {
4236
address: delegationManagerAddress,
43-
abi,
37+
abi: DelegationManager,
4438
functionName: 'redeemDelegations',
4539
args: [
4640
encodePermissionContexts(delegations),

packages/smart-accounts-kit/src/DelegationFramework/utils.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
import { ERC1967Proxy } from '@metamask/delegation-abis';
22
import { ERC1967Proxy as ERC1967ProxyBytecode } from '@metamask/delegation-abis/bytecode';
3-
import type { Abi, Address, Client, Hex } from 'viem';
3+
import type { Address, Client, Hex } from 'viem';
44
import { encodeDeployData } from 'viem';
55
import { getCode } from 'viem/actions';
66

77
import { getProxyImplementation } from './DeleGatorCore/read';
88

9-
// Where a function signature is duplicated across contracts, we need to narrow
10-
// the ABI type passed as the `simulateContract` generic argument. Without this,
11-
// the `simulate()` return type would not match, despite being functionally
12-
// identical.
13-
export type NarrowAbiToFunction<
14-
TAbi extends Abi,
15-
FunctionName extends string,
16-
> = [
17-
Extract<
18-
TAbi[number],
19-
{
20-
type: 'function';
21-
name: FunctionName;
22-
}
23-
>[],
24-
];
25-
269
/**
2710
* Checks if a contract is deployed at the given address.
2811
*
@@ -95,5 +78,5 @@ export const encodeProxyCreationCode = ({
9578
encodeDeployData({
9679
abi: ERC1967Proxy,
9780
args: [implementationAddress, initcode],
98-
bytecode: ERC1967ProxyBytecode as Hex,
81+
bytecode: ERC1967ProxyBytecode,
9982
});

packages/smart-accounts-kit/src/contracts/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export {
2525
encodeProxyCreationCode,
2626
} from '../DelegationFramework/utils';
2727

28-
export type { NarrowAbiToFunction } from '../DelegationFramework/utils';
29-
3028
export {
3129
DelegationManager,
3230
DeleGatorCore,

0 commit comments

Comments
 (0)