Skip to content

Commit

Permalink
Merge pull request #732 from liquity/fix-app-env
Browse files Browse the repository at this point in the history
fix: V1 staking rewards missing
  • Loading branch information
danielattilasimon authored Jan 22, 2025
2 parents b613f2e + 44b5c60 commit 7fa7ba6
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 28 deletions.
7 changes: 5 additions & 2 deletions contracts/utils/deployment-manifest-to-app-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const ZDeploymentManifest = z.object({
exchangeHelpers: ZAddress,

governance: z.object({
LUSDToken: ZAddress,
LQTYToken: ZAddress,
LQTYStaking: ZAddress.default(ZERO_ADDRESS),
stakingV1: ZAddress,
governance: ZAddress,
}),

Expand Down Expand Up @@ -212,9 +213,11 @@ function contractNameToAppEnvVariable(contractName: string, prefix: string = "")
return `${prefix}_TROVE_NFT`;

// governance contracts
case "LUSDToken":
return `${prefix}_LUSD_TOKEN`;
case "LQTYToken":
return `${prefix}_LQTY_TOKEN`;
case "LQTYStaking":
case "stakingV1":
return `${prefix}_LQTY_STAKING`;
case "governance":
return `${prefix}_GOVERNANCE`;
Expand Down
35 changes: 27 additions & 8 deletions frontend/app/src/abi/LqtyStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ export const LqtyStaking = [{
"type": "event",
}, {
"anonymous": false,
"inputs": [{
"indexed": false,
"internalType": "address",
"name": "_borrowerOperationsAddress",
"type": "address",
}],
"inputs": [{ "indexed": false, "internalType": "address", "name": "_borrowerOperationsAddress", "type": "address" }],
"name": "BorrowerOperationsAddressSet",
"type": "event",
}, {
Expand Down Expand Up @@ -129,6 +124,18 @@ export const LqtyStaking = [{
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function",
}, {
"inputs": [{ "internalType": "address", "name": "_user", "type": "address" }],
"name": "getPendingETHGain",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function",
}, {
"inputs": [{ "internalType": "address", "name": "_user", "type": "address" }],
"name": "getPendingLUSDGain",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function",
}, {
"inputs": [{ "internalType": "uint256", "name": "_ETHFee", "type": "uint256" }],
"name": "increaseF_ETH",
Expand All @@ -150,7 +157,13 @@ export const LqtyStaking = [{
}, {
"inputs": [],
"name": "lqtyToken",
"outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }],
"outputs": [{ "internalType": "contract ILQTYToken", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function",
}, {
"inputs": [],
"name": "lusdToken",
"outputs": [{ "internalType": "contract ILUSDToken", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function",
}, {
Expand All @@ -160,7 +173,13 @@ export const LqtyStaking = [{
"stateMutability": "view",
"type": "function",
}, {
"inputs": [{ "internalType": "address", "name": "_lqtyTokenAddress", "type": "address" }],
"inputs": [
{ "internalType": "address", "name": "_lqtyTokenAddress", "type": "address" },
{ "internalType": "address", "name": "_lusdTokenAddress", "type": "address" },
{ "internalType": "address", "name": "_troveManagerAddress", "type": "address" },
{ "internalType": "address", "name": "_borrowerOperationsAddress", "type": "address" },
{ "internalType": "address", "name": "_activePoolAddress", "type": "address" },
],
"name": "setAddresses",
"outputs": [],
"stateMutability": "nonpayable",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
CONTRACT_HINT_HELPERS,
CONTRACT_LQTY_STAKING,
CONTRACT_LQTY_TOKEN,
CONTRACT_LUSD_TOKEN,
CONTRACT_MULTI_TROVE_GETTER,
CONTRACT_WETH,
} from "@/src/env";
Expand All @@ -41,6 +42,7 @@ const protocolAbis = {
HintHelpers,
LqtyStaking,
LqtyToken,
LusdToken: erc20Abi,
MultiTroveGetter,
WETH: erc20Abi,
} as const;
Expand Down Expand Up @@ -111,6 +113,7 @@ const CONTRACTS: Contracts = {
HintHelpers: { abi: abis.HintHelpers, address: CONTRACT_HINT_HELPERS },
LqtyStaking: { abi: abis.LqtyStaking, address: CONTRACT_LQTY_STAKING },
LqtyToken: { abi: abis.LqtyToken, address: CONTRACT_LQTY_TOKEN },
LusdToken: { abi: abis.LusdToken, address: CONTRACT_LUSD_TOKEN },
MultiTroveGetter: { abi: abis.MultiTroveGetter, address: CONTRACT_MULTI_TROVE_GETTER },
WETH: { abi: abis.WETH, address: CONTRACT_WETH },

Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const EnvSchema = v.pipe(
v.optional(v.string(), ""),
v.transform((value) => value.trim()),
),
INITIATIVE_UNI_V4_DONATIONS: vAddress(),
KNOWN_INITIATIVES_URL: v.optional(v.pipe(v.string(), v.url())),
LIQUITY_STATS_URL: v.pipe(v.string(), v.url()),
SAFE_API_URL: v.optional(v.pipe(v.string(), v.url())),
Expand All @@ -97,6 +96,7 @@ export const EnvSchema = v.pipe(
CONTRACT_HINT_HELPERS: vAddress(),
CONTRACT_LQTY_STAKING: vAddress(),
CONTRACT_LQTY_TOKEN: vAddress(),
CONTRACT_LUSD_TOKEN: vAddress(),
CONTRACT_MULTI_TROVE_GETTER: vAddress(),
CONTRACT_WETH: vAddress(),

Expand Down Expand Up @@ -234,7 +234,6 @@ const parsedEnv = v.safeParse(EnvSchema, {
DELEGATE_AUTO: process.env.NEXT_PUBLIC_DELEGATE_AUTO,
DEMO_MODE: process.env.NEXT_PUBLIC_DEMO_MODE,
DEPLOYMENT_FLAVOR: process.env.NEXT_PUBLIC_DEPLOYMENT_FLAVOR,
INITIATIVE_UNI_V4_DONATIONS: process.env.NEXT_PUBLIC_INITIATIVE_UNI_V4_DONATIONS,
KNOWN_INITIATIVES_URL: process.env.NEXT_PUBLIC_KNOWN_INITIATIVES_URL,
LIQUITY_STATS_URL: process.env.NEXT_PUBLIC_LIQUITY_STATS_URL,
SAFE_API_URL: process.env.NEXT_PUBLIC_SAFE_API_URL,
Expand All @@ -249,6 +248,7 @@ const parsedEnv = v.safeParse(EnvSchema, {
CONTRACT_HINT_HELPERS: process.env.NEXT_PUBLIC_CONTRACT_HINT_HELPERS,
CONTRACT_LQTY_STAKING: process.env.NEXT_PUBLIC_CONTRACT_LQTY_STAKING,
CONTRACT_LQTY_TOKEN: process.env.NEXT_PUBLIC_CONTRACT_LQTY_TOKEN,
CONTRACT_LUSD_TOKEN: process.env.NEXT_PUBLIC_CONTRACT_LUSD_TOKEN,
CONTRACT_MULTI_TROVE_GETTER: process.env.NEXT_PUBLIC_CONTRACT_MULTI_TROVE_GETTER,
CONTRACT_WETH: process.env.NEXT_PUBLIC_CONTRACT_WETH,

Expand Down Expand Up @@ -324,12 +324,12 @@ export const {
CONTRACT_HINT_HELPERS,
CONTRACT_LQTY_STAKING,
CONTRACT_LQTY_TOKEN,
CONTRACT_LUSD_TOKEN,
CONTRACT_MULTI_TROVE_GETTER,
CONTRACT_WETH,
DELEGATE_AUTO,
DEMO_MODE,
DEPLOYMENT_FLAVOR,
INITIATIVE_UNI_V4_DONATIONS,
KNOWN_INITIATIVES_URL,
LIQUITY_STATS_URL,
SAFE_API_URL,
Expand Down
39 changes: 33 additions & 6 deletions frontend/app/src/liquity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useQuery } from "@tanstack/react-query";
import * as dn from "dnum";
import { useMemo } from "react";
import { encodeAbiParameters, keccak256, parseAbiParameters } from "viem";
import { useReadContract, useReadContracts } from "wagmi";
import { useBalance, useReadContract, useReadContracts } from "wagmi";

export function shortenTroveId(troveId: TroveId, chars = 8) {
return troveId.length < chars * 2 + 2
Expand Down Expand Up @@ -181,6 +181,7 @@ function earnPositionFromGraph(

export function useStakePosition(address: null | Address) {
const LqtyStaking = getProtocolContract("LqtyStaking");
const LusdToken = getProtocolContract("LusdToken");
const Governance = getProtocolContract("Governance");

const userProxyAddress = useReadContract({
Expand All @@ -190,6 +191,11 @@ export function useStakePosition(address: null | Address) {
query: { enabled: Boolean(address) },
});

const userProxyBalance = useBalance({
address: userProxyAddress.data ?? "0x",
query: { enabled: Boolean(address) && userProxyAddress.isSuccess },
});

return useReadContracts({
contracts: [
{
Expand All @@ -201,12 +207,33 @@ export function useStakePosition(address: null | Address) {
...LqtyStaking,
functionName: "totalLQTYStaked",
},
{
...LqtyStaking,
functionName: "getPendingETHGain",
args: [userProxyAddress.data ?? "0x"],
},
{
...LqtyStaking,
functionName: "getPendingLUSDGain",
args: [userProxyAddress.data ?? "0x"],
},
{
...LusdToken,
functionName: "balanceOf",
args: [userProxyAddress.data ?? "0x"],
},
],
query: {
enabled: Boolean(address) && userProxyAddress.isSuccess,
enabled: Boolean(address) && userProxyAddress.isSuccess && userProxyBalance.isSuccess,
refetchInterval: DATA_REFRESH_INTERVAL,
select: ([depositResult, totalStakedResult]): PositionStake | null => {
if (depositResult.status === "failure" || totalStakedResult.status === "failure") {
select: (
[depositResult, totalStakedResult, pendingEthGainResult, pendingLusdGainResult, lusdBalanceResult],
): PositionStake | null => {
if (
depositResult.status === "failure" || totalStakedResult.status === "failure"
|| pendingEthGainResult.status === "failure" || pendingLusdGainResult.status === "failure"
|| lusdBalanceResult.status === "failure"
) {
return null;
}
const deposit = dnum18(depositResult.result);
Expand All @@ -217,8 +244,8 @@ export function useStakePosition(address: null | Address) {
owner: address ?? "0x",
totalStaked,
rewards: {
eth: dnum18(0),
lusd: dnum18(0),
eth: dnum18(pendingEthGainResult.result + (userProxyBalance.data?.value ?? 0n)),
lusd: dnum18(pendingLusdGainResult.result + lusdBalanceResult.result),
},
share: dn.gt(totalStaked, 0) ? dn.div(deposit, totalStaked) : dnum18(0),
};
Expand Down
8 changes: 1 addition & 7 deletions frontend/app/src/screens/StakeScreen/PanelRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ export function PanelRewards() {
successLink: ["/", "Go to the Dashboard"],
successMessage: "The rewards have been claimed successfully.",

stakePosition: {
...stakePosition.data,
rewards: {
eth: dn.from(0, 18),
lusd: dn.from(0, 18),
},
},
stakePosition: stakePosition.data,
prevStakePosition: stakePosition.data,
});
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/screens/StakeScreen/PanelStaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export function PanelStaking() {
&& !insufficientBalance,
);

const rewardsLusd = dn.from(0, 18);
const rewardsEth = dn.from(0, 18);
const rewardsLusd = stakePosition.data?.rewards.lusd ?? dn.from(0, 18);
const rewardsEth = stakePosition.data?.rewards.eth ?? dn.from(0, 18);

return (
<>
Expand Down

0 comments on commit 7fa7ba6

Please sign in to comment.