Skip to content

Commit

Permalink
Merge pull request #43 from ensdomains/burn-fuses-tweaks
Browse files Browse the repository at this point in the history
Tweaks
  • Loading branch information
LeonmanRolls authored Sep 1, 2022
2 parents 685428f + 9297f50 commit a19a7bd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"license": "MIT",
"scripts": {
"tenv": "ens-test-env -a",
"denv": "pnpm tenv start -ns -nb",
"generate-types": "ts-node scripts/runTypechain.ts",
"generate-abis": "hardhat export-abi",
"start": "ts-node --files src/index.test.ts",
Expand Down
23 changes: 12 additions & 11 deletions packages/ensjs/src/functions/burnFuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { namehash } from '../utils/normalise'
type FuseObj = typeof fuseEnum
type UnnamedFuseType = typeof unnamedFuses
type Fuse = keyof FuseObj
type NamedFuseValues = FuseObj[Fuse]
type UnnamedFuseValues = UnnamedFuseType[number]

// We need this type so that the following type isn't infinite. This type limits the max length of the fuse array to 7.
type FuseArrayPossibilities =
export type FuseArrayPossibilities =
| [Fuse]
| [Fuse, Fuse]
| [Fuse, Fuse, Fuse]
Expand Down Expand Up @@ -40,27 +39,29 @@ type FusesWithoutDuplicates<A, B = never> = A extends FuseArrayPossibilities
: // CLAUSE A > FALSE: Return an empty array as it isn't a fuse tuple.
[]

type FusePropsNamedArray<A extends FuseArrayPossibilities> = {
namedFusesToBurn: FusesWithoutDuplicates<A>
export type NamedFusesToBurn = FusesWithoutDuplicates<FuseArrayPossibilities>

export type FusePropsNamedArray = {
namedFusesToBurn: NamedFusesToBurn
}

type FusePropsUnnamedArray = {
export type FusePropsUnnamedArray = {
unnamedFusesToBurn: UnnamedFuseValues[]
}

type FusePropsNumber = {
export type FusePropsNumber = {
fuseNumberToBurn: number
}

type FuseProps<A extends FuseArrayPossibilities> =
| (Partial<FusePropsNamedArray<A>> & FusePropsUnnamedArray)
| (FusePropsNamedArray<A> & Partial<FusePropsUnnamedArray>)
export type FuseProps =
| (Partial<FusePropsNamedArray> & FusePropsUnnamedArray)
| (FusePropsNamedArray & Partial<FusePropsUnnamedArray>)
| FusePropsNumber

export default async function <A extends FuseArrayPossibilities>(
export default async function (
{ contracts, signer }: ENSArgs<'contracts' | 'signer'>,
name: string,
props: FuseProps<A>,
props: FuseProps,
) {
const isNumber = 'fuseNumberToBurn' in props
const hasNamedArray = 'namedFusesToBurn' in props
Expand Down
8 changes: 4 additions & 4 deletions packages/ensjs/src/functions/getFuses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const unwrappedNameDefault = {
CANNOT_TRANSFER: false,
CANNOT_UNWRAP: false,
PARENT_CANNOT_CONTROL: false,
canDoEverything: true,
CAN_DO_EVERYTHING: true,
},
owner: '0x0000000000000000000000000000000000000000',
rawFuses: BigNumber.from(0),
Expand Down Expand Up @@ -48,12 +48,12 @@ describe('getFuses', () => {
unwrappedNameDefault,
)
})
it('should return with canDoEverything set to true for a name with no fuses burned', async () => {
it('should return with CAN_DO_EVERYTHING set to true for a name with no fuses burned', async () => {
const nameWrapper = await ENSInstance.contracts!.getNameWrapper()!
const result = await ENSInstance.getFuses('test.wrapped-with-subnames.eth')
expect(result).toBeTruthy()
if (result) {
expect(result.fuseObj.canDoEverything).toBe(true)
expect(result.fuseObj.CAN_DO_EVERYTHING).toBe(true)
expect(
Object.values(result.fuseObj).reduce(
(prev, curr) => (curr ? prev + 1 : prev),
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('getFuses', () => {
CANNOT_SET_TTL: true,
CANNOT_CREATE_SUBDOMAIN: true,
PARENT_CANNOT_CONTROL: true,
canDoEverything: false,
CAN_DO_EVERYTHING: false,
})
expect(result.rawFuses.toHexString()).toBe('0x71')
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ensjs/src/functions/getFuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const decode = async (
)

if (fuses.eq(0)) {
fuseObj.canDoEverything = true
fuseObj.CAN_DO_EVERYTHING = true
} else {
fuseObj.canDoEverything = false
fuseObj.CAN_DO_EVERYTHING = false
}

const expiryDate = new Date(expiry * 1000)
Expand Down
3 changes: 3 additions & 0 deletions packages/ensjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import singleCall from './utils/singleCall'
import writeTx from './utils/writeTx'
import fuseEnum from './utils/fuses'

export type { FusePropsNamedArray, FusePropsUnnamedArray, FusePropsNumber, FuseProps, NamedFusesToBurn } from './functions/burnFuses'
export type FuseEnum = typeof fuseEnum

type ENSOptions = {
graphURI?: string | null
getContractAddress?: typeof _getContractAddress
Expand Down

0 comments on commit a19a7bd

Please sign in to comment.