Skip to content

Commit 7eff3e5

Browse files
committed
chore: add bos as collateral for borrowing
1 parent 92ecfe9 commit 7eff3e5

8 files changed

Lines changed: 54 additions & 57 deletions

File tree

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
3+
}

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true,
5+
"editor.codeActionsOnSave": {
6+
"source.organizeImports": "explicit",
7+
"source.sortImports": "explicit"
8+
},
9+
"cSpell.words": ["sovryn"]
310
}

apps/frontend/src/app/5_pages/BorrowPage/components/OpenLoansTable/hooks/useGetOpenLoans.ts

Lines changed: 21 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useMemo, useState } from 'react';
1+
import { keepPreviousData, useQuery } from '@tanstack/react-query';
22

33
import dayjs from 'dayjs';
44

@@ -12,7 +12,6 @@ import { useAccount } from '../../../../../../hooks/useAccount';
1212
import { useBlockNumber } from '../../../../../../hooks/useBlockNumber';
1313
import { useLoadContract } from '../../../../../../hooks/useLoadContract';
1414
import { queryRate } from '../../../../../../utils/calls';
15-
import { useGetActiveLoansQuery } from '../../../../../../utils/graphql/rsk/generated';
1615
import { decimalic } from '../../../../../../utils/math';
1716
import {
1817
calculateApr,
@@ -30,35 +29,19 @@ const unsafeOnly = false;
3029

3130
export const useGetOpenLoans = () => {
3231
const { account } = useAccount();
33-
const { value: blockNumber } = useBlockNumber();
34-
const [processedBlock, setProcessedBlock] = useState<number | undefined>();
32+
const blockNumber = useBlockNumber();
3533
const contract = useLoadContract('protocol', 'protocol', RSK_CHAIN_ID);
36-
const [loadingLoans, setLoadingLoans] = useState(false);
37-
const [loanItemsSmartContract, setLoanItemsSmartContract] = useState<
38-
LoanItem[]
39-
>([]);
4034

4135
const {
42-
data,
43-
loading: loadingSubgraph,
44-
refetch,
45-
} = useGetActiveLoansQuery({
46-
variables: { user: account },
47-
});
48-
49-
const loading = useMemo(
50-
() => loadingLoans || loadingSubgraph,
51-
[loadingLoans, loadingSubgraph],
52-
);
53-
54-
const getUserLoans = useCallback(async () => {
55-
if (!account || !contract) {
56-
setLoadingLoans(false);
57-
return;
58-
}
59-
60-
try {
61-
setLoadingLoans(true);
36+
data: loanItemsSmartContract,
37+
isPending,
38+
error,
39+
} = useQuery({
40+
queryKey: ['userLoans', { account, blockNumber }],
41+
queryFn: async () => {
42+
if (!account || !contract) {
43+
return [];
44+
}
6245
const loans = await contract.getUserLoans(
6346
account,
6447
start,
@@ -69,7 +52,7 @@ export const useGetOpenLoans = () => {
6952
);
7053

7154
if (!loans) {
72-
return;
55+
return [];
7356
}
7457

7558
const rates = await mapRates(loans);
@@ -125,29 +108,17 @@ export const useGetOpenLoans = () => {
125108
.filter(Boolean)
126109
.filter(item => isSupportedPool(item.debtAsset, item.collateralAsset));
127110

128-
setLoanItemsSmartContract(result);
129-
setProcessedBlock(blockNumber);
130-
} catch (error) {
131-
console.error(`Error while fetching loans: ${error}`);
132-
} finally {
133-
setLoadingLoans(false);
134-
}
135-
}, [account, blockNumber, contract]);
136-
137-
useEffect(() => {
138-
if (blockNumber !== processedBlock) {
139-
refetch();
140-
getUserLoans();
141-
}
142-
}, [blockNumber, getUserLoans, processedBlock, refetch]);
143-
144-
if (!data?.loans || !contract || !loanItemsSmartContract) {
145-
return { data: [], loading };
146-
}
111+
return result as LoanItem[];
112+
},
113+
enabled: !!account && !!contract,
114+
placeholderData: keepPreviousData,
115+
throwOnError: true,
116+
});
147117

148118
return {
149-
data: loanItemsSmartContract,
150-
loading,
119+
data: loanItemsSmartContract ?? [],
120+
loading: isPending,
121+
error,
151122
};
152123
};
153124

apps/frontend/src/constants/infrastructure/bsc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Environments } from '../../types/global';
22

33
const rpc = {
4-
[Environments.Mainnet]: 'wss://bsc.sovryn.app/mainnet/websocket',
5-
[Environments.Testnet]: 'wss://bsc.sovryn.app/testnet/websocket',
4+
[Environments.Mainnet]: 'https://bsc.sovryn.app/mainnet',
5+
[Environments.Testnet]: 'https://bsc.sovryn.app/testnet',
66
};
77

88
export const BSC = {

apps/frontend/src/utils/LendingPoolDictionary.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class LendingPoolDictionary {
77
COMMON_SYMBOLS.DLLR,
88
new LendingPool(
99
COMMON_SYMBOLS.DLLR,
10-
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV],
10+
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV, COMMON_SYMBOLS.BOS],
1111
false,
1212
false,
1313
),
@@ -22,6 +22,7 @@ export class LendingPoolDictionary {
2222
COMMON_SYMBOLS.SOV,
2323
'BPRO',
2424
COMMON_SYMBOLS.DOC,
25+
COMMON_SYMBOLS.BOS,
2526
],
2627
false,
2728
false,
@@ -31,7 +32,7 @@ export class LendingPoolDictionary {
3132
COMMON_SYMBOLS.XUSD,
3233
new LendingPool(
3334
COMMON_SYMBOLS.XUSD,
34-
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV],
35+
[COMMON_SYMBOLS.BTC, 'BPRO', COMMON_SYMBOLS.SOV, COMMON_SYMBOLS.BOS],
3536
true,
3637
false,
3738
),
@@ -40,7 +41,13 @@ export class LendingPoolDictionary {
4041
COMMON_SYMBOLS.DOC,
4142
new LendingPool(
4243
COMMON_SYMBOLS.DOC,
43-
[COMMON_SYMBOLS.BTC, COMMON_SYMBOLS.XUSD, 'BPRO', COMMON_SYMBOLS.SOV],
44+
[
45+
COMMON_SYMBOLS.BTC,
46+
COMMON_SYMBOLS.XUSD,
47+
'BPRO',
48+
COMMON_SYMBOLS.SOV,
49+
COMMON_SYMBOLS.BOS,
50+
],
4451
false,
4552
false,
4653
),
@@ -59,6 +66,7 @@ export class LendingPoolDictionary {
5966
COMMON_SYMBOLS.XUSD,
6067
COMMON_SYMBOLS.DOC,
6168
COMMON_SYMBOLS.SOV,
69+
COMMON_SYMBOLS.BOS,
6270
],
6371
false,
6472
false,

apps/frontend/src/utils/asset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const COMMON_SYMBOLS = {
3737
ETH: 'ETH',
3838
WBTC_OLD: 'WBTC.OLD',
3939
USDT: 'USDT',
40+
BOS: 'BOS',
4041
};
4142

4243
export const compareAssets = (asset1?: string | null, asset2?: string | null) =>

packages/contracts/src/contracts/assets/rsk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const rsk: Array<AssetDetails> = [
127127
},
128128
{
129129
symbol: 'BOS',
130-
address: '0x3E3006896458F0ACfE79b57A1A0fe067B3a1ce6f',
130+
address: '0x3e3006896458f0acfe79b57a1a0fe067b3a1ce6f',
131131
name: 'BitcoinOS Token',
132132
decimals: 18,
133133
getIcon: async () => (await import('./icons/rsk/bos')).default,

packages/contracts/src/contracts/assets/rskTestnet.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,11 @@ export const rskTestnet: Array<AssetDetails> = [
125125
decimals: 18,
126126
getIcon: async () => (await import('./icons/rsk/powa')).default,
127127
},
128+
{
129+
symbol: 'BOS',
130+
address: '0x0000000000000000000000000000000000000000',
131+
name: 'BitcoinOS Token',
132+
decimals: 18,
133+
getIcon: async () => (await import('./icons/rsk/bos')).default,
134+
},
128135
];

0 commit comments

Comments
 (0)