diff --git a/initialize.js b/initialize.js index c89b8f61..5728e4ba 100644 --- a/initialize.js +++ b/initialize.js @@ -160,7 +160,8 @@ function importContract(contract) { const importContent = `import * as Client from '${filenameNoExt}';\n` + `import { rpcUrl } from './util';\n\n` + - `export default new Client.Client({\n` + + `export const contractId = Client.networks.${process.env.SOROBAN_NETWORK}.contractId;\n\n` + + `export const contractClient = new Client.Client({\n` + ` ...Client.networks.${process.env.SOROBAN_NETWORK},\n` + ` rpcUrl,\n` + `${process.env.SOROBAN_NETWORK === 'local' || 'standalone' ? ` allowHttp: true,\n` : null}` + diff --git a/src/currencies.ts b/src/currencies.ts index ea3f6105..aa789f93 100644 --- a/src/currencies.ts +++ b/src/currencies.ts @@ -1,5 +1,5 @@ -import XLMPoolContract from '@contracts/loan_pool'; -import USDCPoolContract from '@contracts/usdc_pool'; +import * as XLMPoolContract from '@contracts/loan_pool'; +import * as USDCPoolContract from '@contracts/usdc_pool'; import StellarIcon from '@images/Stellar_Symbol.png'; import USDCIcon from '@images/usdc.svg'; import type { SupportedCurrency } from './stellar-wallet'; @@ -8,7 +8,8 @@ export type Currency = { name: string; symbol: SupportedCurrency; icon: string; - loanPoolContract: typeof XLMPoolContract; + loanPoolContract: typeof XLMPoolContract.contractClient; + contractId: string; }; export const CURRENCIES: Currency[] = [ @@ -16,12 +17,14 @@ export const CURRENCIES: Currency[] = [ name: 'Stellar Lumen', symbol: 'XLM', icon: StellarIcon.src, - loanPoolContract: XLMPoolContract, + loanPoolContract: XLMPoolContract.contractClient, + contractId: XLMPoolContract.contractId, }, { name: 'USD Coin', symbol: 'USDC', icon: USDCIcon.src, - loanPoolContract: USDCPoolContract, + loanPoolContract: USDCPoolContract.contractClient, + contractId: USDCPoolContract.contractId, }, ] as const; diff --git a/src/pages/_borrow/BorrowableAssetCard.tsx b/src/pages/_borrow/BorrowableAssetCard.tsx index 4e64b470..73c3fb15 100644 --- a/src/pages/_borrow/BorrowableAssetCard.tsx +++ b/src/pages/_borrow/BorrowableAssetCard.tsx @@ -1,18 +1,15 @@ import { Button } from '@components/Button'; import { Card } from '@components/Card'; -import loanManagerContract from '@contracts/loan_manager'; +import { contractClient } from '@contracts/loan_manager'; import type { Currency } from 'src/currencies'; import { useWallet } from 'src/stellar-wallet'; -// Temporary hack to use XLM pool for all loans and collaterals. -const XLM_LOAN_POOL_ID = 'CCRWVENKGBUX7EP273GOUMY542VWRFEEIHUICTTDDG5ESLSDNENCH6AT'; - interface BorrowableAssetCardProps { currency: Currency; } export const BorrowableAssetCard = ({ currency }: BorrowableAssetCardProps) => { - const { icon, name, symbol } = currency; + const { icon, name, symbol, contractId } = currency; const { wallet, signTransaction } = useWallet(); @@ -23,14 +20,14 @@ export const BorrowableAssetCard = ({ currency }: BorrowableAssetCardProps) => { } try { - loanManagerContract.options.publicKey = wallet.address; + contractClient.options.publicKey = wallet.address; - const tx = await loanManagerContract.initialize({ + const tx = await contractClient.initialize({ user: wallet.address, borrowed: BigInt(10), - borrowed_from: XLM_LOAN_POOL_ID, + borrowed_from: contractId, collateral: BigInt(1000), - collateral_from: XLM_LOAN_POOL_ID, + collateral_from: contractId, }); await tx.signAndSend({ signTransaction }); alert('Loan created succesfully!'); diff --git a/src/pages/_lend/LendableAssetCard.tsx b/src/pages/_lend/LendableAssetCard.tsx index 28765def..ebb26ea3 100644 --- a/src/pages/_lend/LendableAssetCard.tsx +++ b/src/pages/_lend/LendableAssetCard.tsx @@ -1,6 +1,6 @@ import { Button } from '@components/Button'; import { Card } from '@components/Card'; -import loanManager from '@contracts/loan_manager'; +import { contractClient } from '@contracts/loan_manager'; import type { xdr } from '@stellar/stellar-base'; import { Api as RpcApi } from '@stellar/stellar-sdk/rpc'; import { useCallback, useEffect, useState } from 'react'; @@ -63,10 +63,10 @@ export const LendableAssetCard = ({ currency }: LendableAssetCardProps) => { }, []); const fetchPriceData = useCallback(async () => { - if (!loanManager) return; + if (!contractClient) return; try { - const { simulation } = await loanManager.get_price({ token: currency.symbol }); + const { simulation } = await contractClient.get_price({ token: currency.symbol }); if (!simulation || !RpcApi.isSimulationSuccess(simulation)) { throw 'get_price simulation was unsuccessful.';