Skip to content

Commit 555c687

Browse files
committed
feat: add /contract/implementation
1 parent 7d4e336 commit 555c687

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/routes/contract/controller.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,17 @@ async function getAbi(
264264
return abi;
265265
}
266266

267+
async function getImplementationAddress(
268+
chain: ChainId,
269+
address: Address,
270+
): Promise<Address | null> {
271+
const contract = await getSource(chain, address);
272+
if (!contract) {
273+
return null;
274+
}
275+
return contract.implementation?.address ?? null;
276+
}
277+
267278
async function getDeployment(
268279
chain: ChainId,
269280
address: Address,
@@ -415,4 +426,4 @@ async function fetchDeployment(
415426
};
416427
}
417428

418-
export { getAll, getSource, getAbi, getDeployment };
429+
export { getAll, getSource, getAbi, getImplementationAddress, getDeployment };

src/routes/contract/router.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Address } from 'viem';
55

66
import { chainSchema, parseChainId } from '@/utils/chains';
77

8-
import { getAll, getAbi, getSource, getDeployment } from './controller';
8+
import { getAll, getAbi, getSource, getDeployment, getImplementationAddress } from './controller';
99

1010
const router = new Hono()
1111
.get(
@@ -71,6 +71,27 @@ const router = new Hono()
7171
return c.json(abi);
7272
},
7373
)
74+
.get(
75+
'/implementation',
76+
vValidator(
77+
'query',
78+
v.object({
79+
address: v.string(),
80+
chain: chainSchema,
81+
}),
82+
),
83+
async (c) => {
84+
const { address, chain } = c.req.valid('query');
85+
const chainId = parseChainId(chain);
86+
const implementationAddress = await getImplementationAddress(
87+
chainId,
88+
address.toLowerCase() as Address,
89+
);
90+
return c.json({
91+
address: implementationAddress,
92+
});
93+
},
94+
)
7495
.get(
7596
'/deployment',
7697
vValidator(

0 commit comments

Comments
 (0)