-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plugingen to generate plugin contract abi and get contract help…
…er method
- Loading branch information
Showing
13 changed files
with
1,988 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import dedent from "dedent"; | ||
import type { Phase } from "../types"; | ||
|
||
export const ContractAbiGenPhase: Phase = async (input) => { | ||
const { contract, content } = input; | ||
content.push(dedent` | ||
export const ${contract.name}Abi = ${JSON.stringify(contract.abi)} as const; | ||
`); | ||
return input; | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/accounts/plugingen/phases/contract-addresses-gen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import dedent from "dedent"; | ||
import type { Address } from "viem"; | ||
import type { Phase } from "../types"; | ||
|
||
export const ContractAddressesGenPhase: Phase = async (input) => { | ||
const { contract, content, addImport } = input; | ||
|
||
addImport("viem", { name: "Address", isType: true }); | ||
content.push(dedent` | ||
const addresses = {${Object.entries( | ||
contract.address as Record<number, Address> | ||
).reduce( | ||
(prev, [chainId, addr]) => (prev += `${chainId}: "${addr}" as Address, `), | ||
"" | ||
)}} as Record<number, Address>; | ||
`); | ||
return input; | ||
}; |
20 changes: 20 additions & 0 deletions
20
packages/accounts/plugingen/phases/plugin-generator/get-contract-gen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import dedent from "dedent"; | ||
import type { Phase } from "../../types"; | ||
|
||
export const GetContractGenPhase: Phase = async (input) => { | ||
const { content, contract, addImport } = input; | ||
|
||
addImport("viem", { name: "getContract", isType: false }); | ||
addImport("viem", { name: "GetContractReturnType", isType: true }); | ||
addImport("viem", { name: "Address", isType: true }); | ||
content.push(dedent` | ||
getContract: (provider: ISmartAccountProvider): GetContractReturnType<typeof ${contract.name}Abi, typeof provider.rpcClient, undefined, Address> => | ||
getContract({ | ||
address: addresses[provider.rpcClient.chain.id], | ||
abi: ${contract.name}Abi, | ||
publicClient: provider.rpcClient, | ||
}) | ||
`); | ||
|
||
return input; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
packages/accounts/plugingen/phases/plugin-generator/meta-gen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.