-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allowlist module installation and uninstallation
- Loading branch information
Showing
3 changed files
with
182 additions
and
2 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
99 changes: 99 additions & 0 deletions
99
account-kit/smart-contracts/src/ma-v2/modules/allowlist-module/module.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,99 @@ | ||
import { encodeAbiParameters, type Address, type Hex } from "viem"; | ||
|
||
import { allowlistModuleAbi } from "./abis/allowlistModuleAbi.js"; | ||
|
||
const addresses: Record<number | "default", Address> = { | ||
default: "0xE46ca4a98c485caEE2Abb6ef5116292B8c78a868", | ||
}; | ||
|
||
const meta = { | ||
name: "AllowlistModule", | ||
version: "alpha.1", | ||
addresses, | ||
}; | ||
|
||
export const allowlistModule = { | ||
meta, | ||
abi: allowlistModuleAbi, | ||
encodeOnInstallData: (args: { | ||
entityId: number; | ||
inputs: Array<{ | ||
target: Address; | ||
hasSelectorAllowlist: boolean; | ||
hasERC20SpendLimit: boolean; | ||
erc20SpendLimit: bigint; | ||
selectors: Array<Hex>; | ||
}>; | ||
}): Hex => { | ||
const { entityId, inputs } = args; | ||
return encodeAbiParameters( | ||
[ | ||
{ type: "uint32" }, | ||
{ | ||
type: "tuple[]", | ||
components: [ | ||
{ type: "address" }, | ||
{ type: "bool" }, | ||
{ type: "bool" }, | ||
{ type: "uint256" }, | ||
{ type: "bytes4[]" }, | ||
], | ||
}, | ||
], | ||
[ | ||
entityId, | ||
inputs.map( | ||
(input) => | ||
[ | ||
input.target, | ||
input.hasSelectorAllowlist, | ||
input.hasERC20SpendLimit, | ||
input.erc20SpendLimit, | ||
input.selectors, | ||
] as const | ||
), | ||
] | ||
); | ||
}, | ||
|
||
encodeOnUninstallData: (args: { | ||
entityId: number; | ||
inputs: Array<{ | ||
target: Address; | ||
hasSelectorAllowlist: boolean; | ||
hasERC20SpendLimit: boolean; | ||
erc20SpendLimit: bigint; | ||
selectors: Array<Hex>; | ||
}>; | ||
}): Hex => { | ||
const { entityId, inputs } = args; | ||
return encodeAbiParameters( | ||
[ | ||
{ type: "uint32" }, | ||
{ | ||
type: "tuple[]", | ||
components: [ | ||
{ type: "address" }, | ||
{ type: "bool" }, | ||
{ type: "bool" }, | ||
{ type: "uint256" }, | ||
{ type: "bytes4[]" }, | ||
], | ||
}, | ||
], | ||
[ | ||
entityId, | ||
inputs.map( | ||
(input) => | ||
[ | ||
input.target, | ||
input.hasSelectorAllowlist, | ||
input.hasERC20SpendLimit, | ||
input.erc20SpendLimit, | ||
input.selectors, | ||
] as const | ||
), | ||
] | ||
); | ||
}, | ||
}; |