Skip to content

Commit

Permalink
feat: Add LRT pool filter (dm) (#5257)
Browse files Browse the repository at this point in the history
* feat: init

* chore: delete generated file

* chore: Update gitignore

* chore: Remove log

* fix: module import

* chore: Keep required folder

* chore: Update schema
  • Loading branch information
garethfuller authored Feb 13, 2024
1 parent b5115e0 commit 5fece57
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pnpm-debug.log*
# tokenlists
/src/assets/data/tokenlists.json
/src/assets/data/tokenlists/*.json
/src/assets/data/pools/**/*.json

#test coverage
/coverage
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
},
"scripts": {
"vite": "vite",
"dev": "npm run generate:tokenlists && vite",
"dev": "npm run generate:tokenlists && npm run generate:metadata && vite",
"serve": "npm run dev",
"build": "npm run generate:tokenlists && vite build",
"build": "npm run generate:tokenlists && npm run generate:metadata && vite build",
"build:witChunkSizeCheck": "node ./scripts/buildWithChunkSizeCheck.mjs",
"build:analyze": "BUILD_ANALIZE=true npm run build",
"build:docker": "export NODE_OPTIONS=--max-old-space-size=8192 && npm run build",
Expand All @@ -35,6 +35,7 @@
"tailwind:view": "tailwind-config-viewer -o",
"generate:contract-addresses": "NODE_ENV=development npx vite-node ./src/lib/scripts/contract-addresses.generator.ts",
"generate:tokenlists": "NODE_ENV=development npx vite-node --options.deps.inline=@ethersproject/basex --options.deps.inline=@ethersproject/signing-key --options.deps.inline=@balancer-labs/sdk ./src/lib/scripts/tokenlists.generator.ts",
"generate:metadata": "NODE_ENV=development npx vite-node ./src/lib/scripts/metadata.generator.ts",
"generate:api": "graphql-codegen --config codegen.yml -r dotenv/config",
"typecheck": "vue-tsc --noEmit"
},
Expand Down
Empty file added src/assets/data/pools/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions src/components/inputs/PoolFeatureSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const options = [
PoolTypeFilter.Stable,
PoolTypeFilter.CLP,
PoolTypeFilter.LBP,
PoolTypeFilter.LRT,
];
const attributeOptions = [PoolAttributeFilter.New];
Expand Down
23 changes: 23 additions & 0 deletions src/composables/usePoolGroups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ref, onBeforeMount } from 'vue';

const lrtPools = ref<string[]>([]);

const chainIdToNetworkFileMap = {
1: 'mainnet',
1101: 'zkevm',
};

export function usePoolGroups(chainId: string | number) {
const fileName = chainIdToNetworkFileMap[chainId] || 'mainnet';

onBeforeMount(async () => {
const module = await import(`@/assets/data/pools/${fileName}.json`);
const pools = module.default;

lrtPools.value = pools
.filter(pool => pool.categories.includes('lrt'))
.map(pool => pool.id);
});

return { lrtPools };
}
25 changes: 25 additions & 0 deletions src/lib/scripts/metadata.generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import axios from 'axios';

const fs = require('fs');

const baseUrl = 'https://raw.githubusercontent.com/balancer/metadata/main';
const filesToFetch = ['/pools/mainnet.json', '/pools/zkevm.json'];

async function generate() {
filesToFetch.forEach(async file => {
console.log(`Generating metadata for file ${file}...`);
const { data } = await axios(baseUrl + file);
fs.writeFileSync(`./src/assets/data${file}`, JSON.stringify(data, null, 2));
});
}

(async () => {
try {
console.log('⏳ Generating metadata...');
await generate();
console.log('✅ Generated metadata at /src/assets/data/*');
} catch (error) {
console.error('Failed to generate metadata:', error);
process.exit(1);
}
})();
6 changes: 6 additions & 0 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PoolFeatureSelect from '@/components/inputs/PoolFeatureSelect.vue';
import { useTokens } from '@/providers/tokens.provider';
import { PoolAttributeFilter, PoolTypeFilter } from '@/types/pools';
import UserInvestedInAffectedPoolAlert from '@/pages/recovery-exit/UserInvestedInAffectedPoolAlert.vue';
import { usePoolGroups } from '@/composables/usePoolGroups';
const featuredProtocolsSentinel = ref<HTMLDivElement | null>(null);
const isFeaturedProtocolsVisible = ref(false);
Expand Down Expand Up @@ -59,6 +60,7 @@ const { pools, isLoading, isFetchingNextPage, loadMorePools } = usePools({
const { upToSmallBreakpoint } = useBreakpoints();
const { networkSlug, networkConfig } = useNetwork();
const { lrtPools } = usePoolGroups(networkConfig.chainId);
const isPaginated = computed(() => pools.value.length >= 10);
Expand Down Expand Up @@ -97,6 +99,10 @@ function updatePoolFilters(feature: PoolTypeFilter | undefined) {
filterPoolIds.value = [];
filterPoolTypes.value = [PoolType.LiquidityBootstrapping];
break;
case PoolTypeFilter.LRT:
filterPoolIds.value = lrtPools.value;
filterPoolTypes.value = [];
break;
default:
filterPoolIds.value = [];
filterPoolTypes.value = [];
Expand Down
1 change: 1 addition & 0 deletions src/types/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum PoolTypeFilter {
Stable = 'Stable',
CLP = 'CLP',
LBP = 'LBP',
LRT = 'LRT',
}

export enum PoolAttributeFilter {
Expand Down

0 comments on commit 5fece57

Please sign in to comment.