Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add existing ticker check #7

Merged
merged 12 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -188079,6 +188079,7 @@ const robot = (app) => {
// since the token owner can be changed at protocol level at any time, it's enough to check the ownership of the token,
// without checking any previous owners
const apiUrl = getApiUrl();
await checkIfTickerAlreadyExists(token);
const tokenOwner = await getTokenOwnerFromApi(token, apiUrl);
if (new out_1.Address(tokenOwner).isContractAddress()) {
return await fetchStringValueFromApi(apiUrl, "accounts", tokenOwner, "ownerAddress");
Expand All @@ -188099,7 +188100,7 @@ const robot = (app) => {
return response.data;
}
catch (error) {
console.error(`Cannot query API at ${requestUrl}: ${error}`);
console.error(`Cannot query API at ${requestUrl} : ${error}`);
return '';
}
}
Expand Down Expand Up @@ -188154,6 +188155,23 @@ const robot = (app) => {
.filter(x => x);
return [...new Set(tokens)];
}
async function checkIfTickerAlreadyExists(tokenName) {
const tokensDirPath = (network === "mainnet") ? "/tokens" : `/${network}/tokens`;
const response = await context.octokit.repos.getContent({
owner: context.repo().owner,
repo: context.repo().repo,
path: tokensDirPath,
});
const tokenTicker = tokenName.split("-")[0];
if (!tokenTicker) {
return;
}
const tokensDirectories = (response.data && response.data.length) ? response.data : [];
const subdirectories = tokensDirectories.filter((content) => content?.type === "dir" && content?.name?.startsWith(tokenTicker));
if (subdirectories.length) {
await fail(`Token with ticker ${tokenTicker} already exists!`);
}
}
async function fail(reason) {
await createComment(reason);
console.error(reason);
Expand Down
26 changes: 25 additions & 1 deletion src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export const robot = (app: Probot) => {
// without checking any previous owners
const apiUrl = getApiUrl();

await checkIfTickerAlreadyExists(token);

const tokenOwner = await getTokenOwnerFromApi(token, apiUrl);
if (new Address(tokenOwner).isContractAddress()) {
return await fetchStringValueFromApi(apiUrl, "accounts", tokenOwner, "ownerAddress");
Expand All @@ -149,7 +151,7 @@ export const robot = (app: Probot) => {
const response = await axios.get(requestUrl);
return response.data;
} catch (error) {
console.error(`Cannot query API at ${requestUrl}: ${error}`);
console.error(`Cannot query API at ${requestUrl} : ${error}`);
return '';
}
}
Expand Down Expand Up @@ -224,6 +226,28 @@ export const robot = (app: Probot) => {
return [...new Set(tokens)];
}

async function checkIfTickerAlreadyExists(tokenName: string) {
const tokensDirPath = (network === "mainnet") ? "/tokens" : `/${network}/tokens`;
const response = await context.octokit.repos.getContent({
owner: context.repo().owner,
repo: context.repo().repo,
path: tokensDirPath,
});

const tokenTicker = tokenName.split("-")[0];
if (!tokenTicker) {
return;
}
const tokensDirectories = (response.data && (response.data as any[]).length) ? response.data as any[] : [];
const subdirectories = tokensDirectories.filter(
(content) => content?.type === "dir" && content?.name?.startsWith(tokenTicker),
);

if (subdirectories.length) {
await fail(`Token with ticker ${tokenTicker} already exists!`);
}
}

async function fail(reason: string) {
await createComment(reason);
console.error(reason);
Expand Down