Skip to content

Commit 3a5b857

Browse files
committed
upd: market reserves -> multicall + core instance -> og + stability lib + pvpFee
1 parent 7bfd5c6 commit 3a5b857

File tree

8 files changed

+93
-64
lines changed

8 files changed

+93
-64
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "stability-ui",
33
"type": "module",
4-
"version": "0.11.44-alpha",
4+
"version": "0.11.45-alpha",
55
"scripts": {
66
"dev": "astro dev",
77
"start": "astro dev",
@@ -18,7 +18,7 @@
1818
"@astrojs/tailwind": "6.0.2",
1919
"@astrojs/vercel": "8.2.10",
2020
"@nanostores/react": "^0.7.1",
21-
"@stabilitydao/stability": "=0.57.2",
21+
"@stabilitydao/stability": "=0.58.1",
2222
"@tanstack/query-sync-storage-persister": "^5.22.2",
2323
"@tanstack/react-query": "^5.22.2",
2424
"@tanstack/react-query-persist-client": "^5.22.2",
114 KB
Loading

src/modules/DAO/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ import { useVestingData } from "./hooks";
1818

1919
import { getInitialStateFromUrl } from "./functions";
2020

21+
import { daos } from "@stabilitydao/stability";
22+
2123
import { DAOSectionTypes } from "@types";
2224

2325
const DAO = (): JSX.Element => {
2426
const { data: vestingData, isLoading } = useVestingData("146");
2527

28+
const stabilityDAO = daos?.find(({ name }) => name === "Stability");
29+
2630
const { section } = getInitialStateFromUrl();
2731

2832
const [activeSection, setActiveSection] = useState(section);
@@ -72,7 +76,9 @@ const DAO = (): JSX.Element => {
7276
<span className="text-[#97979A] text-[16px] leading-5 font-medium">
7377
xSTBL instant exit fee
7478
</span>
75-
<span className="font-semibold">80%</span>
79+
<span className="font-semibold">
80+
{stabilityDAO?.params?.pvpFee}%
81+
</span>
7682
</div>
7783
<div className="flex items-center justify-between">
7884
<span className="text-[#97979A] text-[16px] leading-5 font-medium">

src/modules/Market/hooks/useUserReservesData.ts

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { useEffect } from "react";
22

33
import { useStore } from "@nanostores/react";
44

5-
import { formatUnits } from "viem";
5+
import { formatUnits, erc20Abi, Abi } from "viem";
66

7-
import { getBalance, getAllowance, getTokenData } from "@utils";
7+
import { getTokenData } from "@utils";
88

99
import { web3clients, AaveProtocolDataProviderABI, AavePoolABI } from "@web3";
1010

@@ -76,22 +76,65 @@ export const useUserReservesData = (market: TMarket): TResult => {
7676
availableBorrowsBase = Number(formatUnits(userData[2], 8));
7777
liquidationThreshold = Number(userData[3]) / 10000;
7878
} catch (err) {
79-
console.warn("Failed to get availableBorrowsBase:", err);
79+
console.warn("Failed to get user account data:", err);
8080
}
8181

82+
const contracts = market.reserves.flatMap((asset) => {
83+
const address = asset.address as TAddress;
84+
const aToken = asset.aToken as TAddress;
85+
86+
const calls = [
87+
{
88+
address: aToken,
89+
abi: erc20Abi,
90+
functionName: "balanceOf",
91+
args: [$account],
92+
},
93+
{
94+
address,
95+
abi: erc20Abi,
96+
functionName: "balanceOf",
97+
args: [$account],
98+
},
99+
{
100+
address,
101+
abi: erc20Abi,
102+
functionName: "allowance",
103+
args: [$account, pool],
104+
},
105+
];
106+
107+
if (asset.isBorrowable) {
108+
calls.push({
109+
address: provider,
110+
abi: AaveProtocolDataProviderABI as Abi,
111+
functionName: "getUserReserveData",
112+
args: [address, $account],
113+
});
114+
}
115+
116+
return calls;
117+
});
118+
119+
const results = await client.multicall({
120+
contracts,
121+
allowFailure: false,
122+
});
123+
124+
let index = 0;
125+
82126
for (const asset of market.reserves) {
83127
const address = asset.address as TAddress;
84-
const aTokenAddress = asset.aToken as TAddress;
85-
const priceUSD = Number(asset.price);
86128
const decimals = getTokenData(address)?.decimals ?? 18;
129+
const priceUSD = Number(asset.price);
87130

88-
const rawATokenBalance = await getBalance(
89-
client,
90-
aTokenAddress,
91-
$account
92-
);
131+
const rawATokenBalance = results[index++] as bigint;
132+
const rawBalance = results[index++] as bigint;
133+
const rawAllowance = results[index++] as bigint;
93134

94135
const withdraw = formatUnits(rawATokenBalance, decimals);
136+
const balance = formatUnits(rawBalance, decimals);
137+
const allowance = formatUnits(rawAllowance, decimals);
95138

96139
let maxWithdraw = "0";
97140

@@ -114,7 +157,7 @@ export const useUserReservesData = (market: TMarket): TResult => {
114157
let _maxWithdraw = withdraw;
115158

116159
if (maxWithdrawTokens < Number(withdraw)) {
117-
maxWithdrawTokens *= 0.998999; // * for safe amount
160+
maxWithdrawTokens *= 0.998999;
118161
_maxWithdraw = maxWithdrawTokens.toString();
119162
}
120163

@@ -124,68 +167,38 @@ export const useUserReservesData = (market: TMarket): TResult => {
124167
}
125168
}
126169

127-
const [rawBalance, rawAllowance] = await Promise.all([
128-
getBalance(client, address, $account),
129-
getAllowance(client, address, $account, pool),
130-
]);
131-
132-
const balance = formatUnits(rawBalance, decimals);
133-
const allowance = formatUnits(rawAllowance, decimals);
134-
135170
const reserveData: any = {
136171
supply: { balance, allowance },
137172
withdraw: { balance: withdraw, maxWithdraw },
138173
};
139174

140175
if (asset.isBorrowable) {
141-
const tokenPrice = Number(asset.price);
176+
const userReserveData = results[index++] as bigint[];
177+
const rawVariableDebt = userReserveData[2];
178+
179+
const repayBalance = formatUnits(rawVariableDebt, decimals);
180+
142181
let borrow = { balance: "0", maxBorrow: "0" };
143182

144-
if (availableBorrowsBase > 0 && tokenPrice > 0) {
183+
if (availableBorrowsBase > 0 && priceUSD > 0) {
145184
const rawAmount =
146-
(availableBorrowsBase / tokenPrice) * 10 ** decimals;
185+
(availableBorrowsBase / priceUSD) * 10 ** decimals;
147186

148187
const safeAmount = BigInt(Math.floor(rawAmount * 0.999999));
149-
150188
const maxBorrow = formatUnits(safeAmount, decimals);
151189

152-
const availableToBorrow = Number(asset?.availableToBorrow) ?? 0;
153-
154-
const canBorrow = String(
155-
Math.min(availableToBorrow, Number(maxBorrow))
156-
);
190+
const availableToBorrow = Number(asset.availableToBorrow) || 0;
157191

158192
borrow = {
159-
balance: canBorrow,
193+
balance: String(Math.min(availableToBorrow, Number(maxBorrow))),
160194
maxBorrow,
161195
};
162196
}
163197

164198
reserveData.borrow = borrow;
165-
166-
const userReserveData = (await client.readContract({
167-
address: provider,
168-
abi: AaveProtocolDataProviderABI,
169-
functionName: "getUserReserveData",
170-
args: [address, $account],
171-
})) as bigint[];
172-
173-
const rawVariableDebt = userReserveData[2];
174-
175-
const repayBalance = formatUnits(rawVariableDebt, decimals);
176-
177-
const rawRepayAllowance = await getAllowance(
178-
client,
179-
address,
180-
$account,
181-
pool
182-
);
183-
184-
const repayAllowance = formatUnits(rawRepayAllowance, decimals);
185-
186199
reserveData.repay = {
187200
balance: repayBalance,
188-
allowance: repayAllowance,
201+
allowance,
189202
};
190203
}
191204

src/modules/Staking/components/ExitForms/InstantExit.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ import { sonicClient, ERC20ABI, IXSTBLABI, wagmiConfig } from "@web3";
1616

1717
import { STABILITY_TOKENS } from "@constants";
1818

19+
import { daos } from "@stabilitydao/stability";
20+
1921
import type { TAddress } from "@types";
2022

2123
const InstantExit: React.FC = () => {
2224
const $connected = useStore(connected);
2325
const $account = useStore(account);
2426
const $lastTx = useStore(lastTx);
2527

28+
const stabilityDAO = daos?.find(({ name }) => name === "Stability");
29+
2630
const input = useRef<HTMLInputElement>(null);
2731

2832
const [balance, setBalance] = useState("0");
@@ -126,8 +130,9 @@ const InstantExit: React.FC = () => {
126130
Instant Exit
127131
</span>
128132
<span className="text-[16px] leafing-6 font-medium text-[#97979A]">
129-
Instantly exit to STBL, incurring a 80% penalty. This process cannot
130-
be reverted, all forfeited STBL is streamed back to stakers.
133+
Instantly exit to STBL, incurring a {stabilityDAO?.params?.pvpFee}%
134+
penalty. This process cannot be reverted, all forfeited STBL is
135+
streamed back to stakers.
131136
</span>
132137
</div>
133138
<div className="flex flex-col justify-between gap-4">

src/modules/Staking/components/ExitForms/VestedExit.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ import { account, connected, lastTx } from "@store";
1818

1919
import { STABILITY_TOKENS } from "@constants";
2020

21+
import { daos } from "@stabilitydao/stability";
22+
2123
import type { TAddress, TVestPeriod } from "@types";
2224

2325
const VestedExit: React.FC = () => {
2426
const $connected = useStore(connected);
2527
const $account = useStore(account);
2628
const $lastTx = useStore(lastTx);
2729

30+
const stabilityDAO = daos?.find(({ name }) => name === "Stability");
31+
32+
const ratio = (100 - Number(stabilityDAO?.params?.pvpFee)) / 100;
33+
2834
const input = useRef<HTMLInputElement>(null);
2935
const dropDownRef = useRef<HTMLDivElement>(null);
3036

@@ -280,8 +286,8 @@ const VestedExit: React.FC = () => {
280286

281287
<span className="text-[16px] leafing-6 font-medium text-[#97979A]">
282288
Redeem xSTBL over a vesting period. Choose a minimum vest of 15 days
283-
(1:0.5 ratio) to maximum vest of 6 months (1:1 ratio). You can cancel
284-
the vest in the first 14 days.
289+
(1:{ratio} ratio) to maximum vest of 6 months (1:1 ratio). You can
290+
cancel the vest in the first 14 days.
285291
</span>
286292
</div>
287293
<div>

src/pages/lending/1/Core-Instance.astro

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import Layout from '@layouts/Layout.astro';
44
import { Market } from "@modules"
55
---
66

7-
<!-- todo: change img -->
87
<Layout
98
title="Core Instance Market"
10-
img="/ogs/markets/Brunch_gen2.png"
9+
img="/ogs/markets/Core_Instance.png"
1110
metaTitle="Core Instance Market"
1211
metaUrl="https://stability.farm/lending/1/Core-Instance"
1312
metaDescription="Non-custodial liquidity market"

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,10 +2013,10 @@
20132013
resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz#821f8442f4175d8f0467b9daf26e3a18e2d02af2"
20142014
integrity sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==
20152015

2016-
"@stabilitydao/stability@=0.57.2":
2017-
version "0.57.2"
2018-
resolved "https://registry.yarnpkg.com/@stabilitydao/stability/-/stability-0.57.2.tgz#436a5bf99326c591ab29e36096d559e72f6f31f9"
2019-
integrity sha512-XxgNt9Vhviggmaeg1vlCtJ54HueheTUNgvB9pf4vbzUpij5SBCCHyQAGZ4M27mttfXtwClJ01ueJc1Skm5JSyA==
2016+
"@stabilitydao/stability@=0.58.1":
2017+
version "0.58.1"
2018+
resolved "https://registry.yarnpkg.com/@stabilitydao/stability/-/stability-0.58.1.tgz#2e15a8ae244538c84364af4a774308ad8ae96c11"
2019+
integrity sha512-uEQhaA8VpT5j2oK0lVjrwAY6UYPf137fTnH7c9gf9Pm7s9+J4/ye00BNBH5V0wL9noj2DAraNHgaSB2AIGZYyQ==
20202020

20212021
"@stablelib/aead@^1.0.1":
20222022
version "1.0.1"

0 commit comments

Comments
 (0)