-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): add OpenAllowList as zero config extension of SimpleDenyList
- Loading branch information
Showing
7 changed files
with
140 additions
and
13 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,40 @@ | ||
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { isAddress, zeroAddress } from 'viem'; | ||
import { beforeAll, describe, expect, test } from 'vitest'; | ||
import { accounts } from '../../test/accounts'; | ||
import { | ||
type Fixtures, | ||
defaultOptions, | ||
deployFixtures, | ||
} from '../../test/helpers'; | ||
import { OpenAllowList } from './OpenAllowList'; | ||
|
||
let fixtures: Fixtures; | ||
|
||
beforeAll(async () => { | ||
fixtures = await loadFixture(deployFixtures); | ||
}); | ||
|
||
function freshOpenAllowList(fixtures: Fixtures) { | ||
return function freshOpenAllowList() { | ||
return fixtures.registry.clone( | ||
crypto.randomUUID(), | ||
new fixtures.bases.OpenAllowList(defaultOptions), | ||
); | ||
}; | ||
} | ||
|
||
describe('OpenAllowList', () => { | ||
test('can successfully be deployed', async () => { | ||
const denyList = new OpenAllowList(defaultOptions); | ||
await denyList.deploy(); | ||
expect(isAddress(denyList.assertValidAddress())).toBe(true); | ||
}); | ||
|
||
test('allows anyone', async () => { | ||
const denyList = await loadFixture(freshOpenAllowList(fixtures)); | ||
expect(await denyList.isAllowed(defaultOptions.account.address)).toBe(true); | ||
expect(await denyList.isAllowed(zeroAddress)).toBe(true); | ||
expect(await denyList.isAllowed(accounts.at(1)!.account)).toBe(true); | ||
}); | ||
}); |
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,65 @@ | ||
import { simpleDenyListAbi } from '@boostxyz/evm'; | ||
import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleDenyList.sol/SimpleDenyList.json'; | ||
import { type Address, type Hex, zeroAddress } from 'viem'; | ||
import type { | ||
DeployableOptions, | ||
GenericDeployableParams, | ||
} from '../Deployable/Deployable'; | ||
import { RegistryType } from '../utils'; | ||
import { | ||
SimpleDenyList, | ||
type SimpleDenyListPayload, | ||
prepareSimpleDenyListPayload, | ||
} from './SimpleDenyList'; | ||
|
||
export const openAllowListAbi = simpleDenyListAbi; | ||
|
||
/** | ||
* A simple AllowList, extending {@link DenyList}, that is ownerless and allows anyone to claim. | ||
* | ||
* @export | ||
* @class OpenAllowList | ||
* @typedef {OpenAllowList} | ||
* @extends {DeployableTarget<OpenAllowListPayload>} | ||
*/ | ||
export class OpenAllowList extends SimpleDenyList<undefined> { | ||
public override readonly abi = openAllowListAbi; | ||
/** | ||
* @inheritdoc | ||
* | ||
* @public | ||
* @static | ||
* @type {Address} | ||
*/ | ||
public static override base: Address = import.meta.env | ||
.VITE_SIMPLE_DENYLIST_BASE; | ||
/** | ||
* @inheritdoc | ||
* | ||
* @public | ||
* @static | ||
* @type {RegistryType} | ||
*/ | ||
public static override registryType: RegistryType = RegistryType.ALLOW_LIST; | ||
|
||
/** | ||
* @inheritdoc | ||
* | ||
* @public | ||
* @param {?SimpleDenyListPayload} [_payload] | ||
* @param {?DeployableOptions} [_options] | ||
* @returns {GenericDeployableParams} | ||
*/ | ||
public override buildParameters( | ||
_payload?: SimpleDenyListPayload, | ||
_options?: DeployableOptions, | ||
): GenericDeployableParams { | ||
const [_, options] = this.validateDeploymentConfig({}, _options); | ||
return { | ||
abi: openAllowListAbi, | ||
bytecode: bytecode as Hex, | ||
args: [prepareSimpleDenyListPayload({ owner: zeroAddress, denied: [] })], | ||
...this.optionallyAttachAccount(options.account), | ||
}; | ||
} | ||
} |
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
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