diff --git a/apps/dapp/README.md b/apps/dapp/README.md index fd34362..20c56d6 100644 --- a/apps/dapp/README.md +++ b/apps/dapp/README.md @@ -10,6 +10,8 @@ Copy the .env.example file to .env and fill in the values. cp env.example .env ``` +>[!NOTE] +> If you want to use your own deployment of the smart contract, you can set the .env property `NEXT_PUBLIC_IS_LOCAL` to true and uncomment the lines 11-13 of the file `src/helpers/getRemoteConfig.ts` and do not commit this changes. ## Running the app Run the development server: diff --git a/apps/dapp/env.example b/apps/dapp/env.example index 06c166d..e49a5d9 100644 --- a/apps/dapp/env.example +++ b/apps/dapp/env.example @@ -1 +1,2 @@ -NEXT_PUBLIC_TEST_TOKENS_ADMIN= # Test tokens admin address \ No newline at end of file +NEXT_PUBLIC_TEST_TOKENS_ADMIN= # Test tokens admin address +NEXT_PUBLIC_IS_LOCAL= # Defines the environment config \ No newline at end of file diff --git a/apps/dapp/src/constants/constants.ts b/apps/dapp/src/constants/constants.ts index 4162867..4c76ae8 100644 --- a/apps/dapp/src/constants/constants.ts +++ b/apps/dapp/src/constants/constants.ts @@ -1,10 +1,29 @@ import axios from 'axios' -const baseURL = 'https://raw.githubusercontent.com/paltalabs/defindex/refs/heads/main/public/' -const suffix = '.contracts.json' + + +const contract_addresses = { + testnet: { + defindex_factory: "CAJJAIJT6E7GMJKFA66RRI7KUNNR22TPNLNUFCNANGCFXJ54RYPVPPJT", + hodl_strategy: "CDTSVTAI4BXYIEZ66F2TLZ337OLW5R5P4ONWMHQY5XTOTBZURZEDZ64N", + fixed_apr_strategy: "CDR6K2L2UN3SZLBOUCJCVNKKKGC4F5DHGQ6QIPVBXU3UTXTTGWWEZ2H3", + blend_strategy: "CCFT4EVTUSYUNO7CYJHC3R2F5ZBTXW7CMJW5Z2PGVYCHWNDG4RS35YZ5" + }, + mainnet: { + defindex_factory: undefined, + hodl_strategy: undefined, + fixed_apr_strategy: undefined, + blend_strategy: undefined + } +} export const configFile = async (network:string)=>{ - if(network != 'testnet' && network != 'mainnet' && network!= 'standalone') throw new Error(`Invalid network: ${network}. It should be testnet, mainnet or standalone`) - const url = baseURL + network + suffix + /* if(network != 'testnet' && network != 'mainnet' && network!= 'standalone') throw new Error(`Invalid network: ${network}. It should be testnet, mainnet or standalone`) + const url = `https://raw.githubusercontent.com/paltalabs/defindex/refs/heads/main/public/${network}.contracts.json` const data = await axios.get(url) if(data.status === 200) return data.data - if(data.status === 404) throw new Error(`Deployment not found for network: ${network}`) + if(data.status === 404) throw new Error(`Deployment not found for network: ${network}`) */ + if(network != 'testnet' && network != 'mainnet' && network != 'standalone') throw new Error(`Invalid network: ${network}.`) + if(network === 'testnet') return contract_addresses.testnet + if(network === 'mainnet') return contract_addresses.mainnet + if(network === 'standalone') return contract_addresses.testnet + return {} } \ No newline at end of file diff --git a/apps/dapp/src/helpers/getRemoteConfig.ts b/apps/dapp/src/helpers/getRemoteConfig.ts index cc9de08..c90acfe 100644 --- a/apps/dapp/src/helpers/getRemoteConfig.ts +++ b/apps/dapp/src/helpers/getRemoteConfig.ts @@ -1,11 +1,14 @@ import { configFile } from '@/constants/constants'; +import localDeployment from '../../../contracts/.soroban/testnet.contracts.json' + const isLocal = process.env.NEXT_PUBLIC_IS_LOCAL + export const getRemoteConfig = async (network: string) => { if (isLocal === 'false') { const deployments = await configFile(network) return deployments - } else if(isLocal === 'true') { - const localDeployment = require(`../../../contracts/.soroban/${network}.contracts.json`) - return localDeployment - } + } + /* else if(isLocal === 'true') { + return localDeployment.ids + } */ } \ No newline at end of file diff --git a/apps/dapp/src/store/lib/features/vaultStore.ts b/apps/dapp/src/store/lib/features/vaultStore.ts index 5a2a916..009cc51 100644 --- a/apps/dapp/src/store/lib/features/vaultStore.ts +++ b/apps/dapp/src/store/lib/features/vaultStore.ts @@ -18,15 +18,15 @@ const initialState: NewVaultState = { //Filtrar Strategies por network y retornar array de Strategies export const getDefaultStrategies = async (network: string) => { try { - const remoteStrategies = await getRemoteConfig(network) + const remoteStrategies: any = await getRemoteConfig(network) const strategies: Strategy[] = [] - for (let strategy in remoteStrategies.ids) { + for (let strategy in remoteStrategies) { if (strategy.includes('strategy')) { const parsedName = strategy.split('_')[0] if (!parsedName) continue const prettierName = parsedName.charAt(0).toUpperCase() + parsedName.slice(1) strategies.push({ - address: remoteStrategies.ids[strategy], + address: remoteStrategies[strategy], name: parsedName ? prettierName : '', paused: false, tempAmount: 0 diff --git a/apps/dapp/src/utils/factory.ts b/apps/dapp/src/utils/factory.ts index f94a5b6..55da4a6 100644 --- a/apps/dapp/src/utils/factory.ts +++ b/apps/dapp/src/utils/factory.ts @@ -7,7 +7,7 @@ export async function fetchFactoryAddress(network: string): Promise { const remoteConfig: any = await getRemoteConfig(network); try { - const factoryAddress = remoteConfig.ids.defindex_factory; + const factoryAddress = remoteConfig.defindex_factory; return factoryAddress; } catch (error) {