Skip to content

Commit

Permalink
Allow l2NetworkId to be undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
chrstph-dvx committed Feb 6, 2024
1 parent 23f4664 commit d9f4d8e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 44 deletions.
19 changes: 12 additions & 7 deletions src/commands/allTokensList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ export const command = Action.AllTokensList;

export const describe = 'All tokens list';

export const handler = async (argvs: Args) => {
let tokenList: ArbTokenList = await generateFullListFormatted(
argvs.l2NetworkID,
);
if (argvs.includePermitTags) {
tokenList = await addPermitTags(tokenList, argvs.l2NetworkID);
export const handler = async ({
includePermitTags,
l2NetworkID,
newArbifiedList,
}: Args) => {
if (!l2NetworkID) {
throw new Error('l2NetworkID is required');
}
writeToFile(tokenList, argvs.newArbifiedList);
let tokenList: ArbTokenList = await generateFullListFormatted(l2NetworkID);
if (includePermitTags) {
tokenList = await addPermitTags(tokenList, l2NetworkID);
}
writeToFile(tokenList, newArbifiedList);
return tokenList;
};
19 changes: 13 additions & 6 deletions src/commands/full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ export const command = Action.Full;

export const describe = 'Full';

export const handler = async (argvs: Args) => {
if (argvs.tokenList !== 'full')
throw new Error("expected --tokenList 'full'");
if (argvs.includePermitTags)
export const handler = async ({
includePermitTags,
l2NetworkID,
newArbifiedList,
tokenList: tokenListPath,
}: Args) => {
if (tokenListPath !== 'full') throw new Error("expected --tokenList 'full'");
if (includePermitTags)
throw new Error('full list mode does not support permit tagging');
const tokenList = await generateFullList(argvs.l2NetworkID);
writeToFile(tokenList, argvs.newArbifiedList);
if (!l2NetworkID) {
throw new Error('l2NetworkID is required');
}
const tokenList = await generateFullList(l2NetworkID);
writeToFile(tokenList, newArbifiedList);
return tokenList;
};
34 changes: 20 additions & 14 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@ export const command = Action.Update;

export const describe = 'Update';

export const handler = async (argvs: Args) => {
const includeOldDataFields = !!argvs.includeOldDataFields;
const { newList } = await updateArbifiedList(
argvs.tokenList,
argvs.l2NetworkID,
{
includeOldDataFields,
ignorePreviousList: argvs.ignorePreviousList,
prevArbifiedList: argvs.prevArbifiedList,
},
);
export const handler = async ({
ignorePreviousList,
includeOldDataFields,
includePermitTags,
l2NetworkID,
newArbifiedList,
prevArbifiedList,
tokenList: tokenListPath,
}: Args) => {
if (!l2NetworkID) {
throw new Error('l2NetworkID is required');
}
const { newList } = await updateArbifiedList(tokenListPath, l2NetworkID, {
includeOldDataFields: !!includeOldDataFields,
ignorePreviousList,
prevArbifiedList,
});
let tokenList: ArbTokenList = newList;

if (argvs.includePermitTags) {
tokenList = await addPermitTags(tokenList, argvs.l2NetworkID);
if (includePermitTags) {
tokenList = await addPermitTags(tokenList, l2NetworkID);
}
writeToFile(tokenList, argvs.newArbifiedList);
writeToFile(tokenList, newArbifiedList);
return tokenList;
};
18 changes: 17 additions & 1 deletion src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ enum Action {
Full = 'full',
Permit = 'permit',
Update = 'update',
CrossChain = 'crosschain',
}
const options = {
l2NetworkID: {
type: 'number',
demandOption: true,
demandOption: false, // Only optional for cross-chain lists
},
crossChain: {
type: 'boolean',
demandOption: false,
},
tokenList: {
type: 'string',
Expand Down Expand Up @@ -69,6 +74,17 @@ const yargsInstance = yargs(hideBin(process.argv))
return true;
}

return false;
})
.check(({ l2NetworkID, crossChain }) => {
if (l2NetworkID && !crossChain) {
return true;
}

if (!l2NetworkID && crossChain) {
return true;
}

return false;
});

Expand Down
34 changes: 18 additions & 16 deletions src/lib/token_list_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,25 @@ export interface ArbificationOptions {
overwriteCurrentList: boolean;
}

type GenerateTokenListOptions = {
/**
* Append all tokens from the original l1TokenList to the output list.
*/
includeAllL1Tokens?: boolean;
/**
* Append all unbridged tokens from original l1TokenList to the output list.
*/
includeUnbridgedL1Tokens?: boolean;
getAllTokensInNetwork?: boolean;
includeOldDataFields?: boolean;
sourceListURL?: string;
preserveListName?: boolean;
};
export const generateTokenList = async (
l1TokenList: TokenList,
l2ChainId: number,
prevArbTokenList?: ArbTokenList | null,
options?: {
/**
* Append all tokens from the original l1TokenList to the output list.
*/
includeAllL1Tokens?: boolean;
/**
* Append all unbridged tokens from original l1TokenList to the output list.
*/
includeUnbridgedL1Tokens?: boolean;
getAllTokensInNetwork?: boolean;
includeOldDataFields?: boolean;
sourceListURL?: string;
preserveListName?: boolean;
},
options?: GenerateTokenListOptions,
) => {
if (options?.includeAllL1Tokens && options.includeUnbridgedL1Tokens) {
throw new Error(
Expand Down Expand Up @@ -366,8 +367,8 @@ export const arbifyL1List = async (
includeOldDataFields,
ignorePreviousList,
prevArbifiedList,
}: {
includeOldDataFields: boolean;
...options
}: GenerateTokenListOptions & {
ignorePreviousList: boolean;
prevArbifiedList: string | undefined;
},
Expand All @@ -383,6 +384,7 @@ export const arbifyL1List = async (
includeAllL1Tokens: false,
includeOldDataFields,
sourceListURL: isValidHttpUrl(pathOrUrl) ? pathOrUrl : undefined,
...options,
},
);

Expand Down

0 comments on commit d9f4d8e

Please sign in to comment.