Skip to content

Commit

Permalink
Merge pull request #441 from prodesert22/feat/disable-rent
Browse files Browse the repository at this point in the history
feat: disable rent
  • Loading branch information
prodesert22 committed Jun 16, 2023
2 parents 8c14495 + 72bb9d3 commit 2e13bfa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
37 changes: 10 additions & 27 deletions src/state/psarstake/hooks/hedera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useHederaExchangeRate() {
* @param positionId The id of position
* Returns rent value in tiny bars
*/
function useHederaSarRent(position: Position | undefined | null) {
export function useHederaSarRent(position: Position | undefined | null) {
const chainId = useChainId();

const useGetBlockTimestamp = useLastBlockTimestampHook[chainId];
Expand Down Expand Up @@ -108,7 +108,6 @@ export function useDerivativeHederaSarStake(position?: Position | null) {
const sarNftContract = useHederaSarNFTContract();

const { data: exchangeRate, isLoading: isloadingExchangeRate } = useHederaExchangeRate();
const tinyRentAddMore = useHederaSarRent(position);

const { hederaAssociated: isAssociated } = useHederaTokenAssociated(sarNftContract?.address, 'Pangolin Sar NFT');

Expand All @@ -118,23 +117,15 @@ export function useDerivativeHederaSarStake(position?: Position | null) {
if (!sarStakingContract || !parsedAmount || !account || !exchangeRate || !isAssociated) {
return;
}
if (!!position && !tinyRentAddMore) {
return;
}
setAttempting(true);
try {
// we need to send 0.1$ in hbar amount to mint
const tinyCents = hederaFn.convertHBarToTinyBars('10'); // 10 cents = 0.1$
const tinyRent = hederaFn.tinyCentsToTinyBars(tinyCents, exchangeRate.current_rate);
const rent = !position ? tinyRent : tinyRentAddMore;

const response = await hederaFn.sarStake({
methodName: !position ? 'mint' : 'stake',
amount: parsedAmount.raw.toString(),
chainId: chainId,
account: account,
positionId: position?.id?.toString(),
rent: rent ?? '0',
rent: '0',
});

if (response) {
Expand Down Expand Up @@ -199,7 +190,6 @@ export function useDerivativeHederaSarStake(position?: Position | null) {
isAssociated,
exchangeRate,
isloadingExchangeRate,
tinyRentAddMore,
approveCallback,
onUserInput,
handleMax,
Expand Down Expand Up @@ -237,13 +227,11 @@ export function useDerivativeHederaSarUnstake(position: Position | null) {
wrappedOnDismiss,
} = useDefaultSarUnstake(position);

const tinyRent = useHederaSarRent(position);

const sarNftContract = useHederaSarNFTContract();
const queryClient = useQueryClient();

const onUnstake = async () => {
if (!sarStakingContract || !parsedAmount || !position || !account || !tinyRent) {
if (!sarStakingContract || !parsedAmount || !position || !account) {
return;
}
setAttempting(true);
Expand All @@ -253,7 +241,7 @@ export function useDerivativeHederaSarUnstake(position: Position | null) {
amount: parsedAmount.raw.toString(),
chainId: chainId,
account: account,
rent: tinyRent,
rent: '0',
positionId: position.id.toString(),
});
if (response) {
Expand Down Expand Up @@ -302,7 +290,6 @@ export function useDerivativeHederaSarUnstake(position: Position | null) {
error,
account,
sarStakingContract,
tinyRent,
onUserInput,
handleMax,
position,
Expand All @@ -327,12 +314,10 @@ export function useDerivativeHederaSarCompound(position: Position | null) {

const chainId = useChainId();

const rent = useHederaSarRent(position);

const sarNftContract = useHederaSarNFTContract();
const queryClient = useQueryClient();
const onCompound = async () => {
if (!sarStakingContract || !position || !account || !rent) {
if (!sarStakingContract || !position || !account) {
return;
}
setAttempting(true);
Expand All @@ -342,7 +327,7 @@ export function useDerivativeHederaSarCompound(position: Position | null) {
account: account,
chainId: chainId,
positionId: position.id.toString(),
rent: rent,
rent: '0',
},
'compound',
);
Expand Down Expand Up @@ -374,7 +359,7 @@ export function useDerivativeHederaSarCompound(position: Position | null) {
wrappedOnDismiss,
onCompound,
}),
[sarStakingContract, attempting, hash, account, rent, position],
[sarStakingContract, attempting, hash, account, position],
);
}

Expand All @@ -395,13 +380,11 @@ export function useDerivativeHederaSarClaim(position: Position | null) {

const chainId = useChainId();

const rent = useHederaSarRent(position);

const sarNftContract = useHederaSarNFTContract();
const queryClient = useQueryClient();

const onClaim = async () => {
if (!sarStakingContract || !position || !account || !rent) {
if (!sarStakingContract || !position || !account) {
return;
}
setAttempting(true);
Expand All @@ -411,7 +394,7 @@ export function useDerivativeHederaSarClaim(position: Position | null) {
account: account,
chainId: chainId,
positionId: position.id.toString(),
rent: rent,
rent: '0',
},
'harvest',
);
Expand Down Expand Up @@ -443,7 +426,7 @@ export function useDerivativeHederaSarClaim(position: Position | null) {
wrappedOnDismiss,
onClaim,
}),
[sarStakingContract, attempting, hash, account, rent, position],
[sarStakingContract, attempting, hash, account, position],
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/hedera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ class Hedera {

const error = new Error('Unpredictable HBAR amount to pay rent');
try {
if (Number(rent) === 0) {
if (Number(rent) < 0) {
throw error;
}
} catch {
Expand Down Expand Up @@ -913,7 +913,7 @@ class Hedera {

const error = new Error('Unpredictable HBAR amount to pay rent');
try {
if (Number(rent) === 0) {
if (Number(rent) < 0) {
throw error;
}
} catch {
Expand Down Expand Up @@ -947,7 +947,7 @@ class Hedera {

const error = new Error('Unpredictable HBAR amount to pay rent');
try {
if (Number(rent) === 0) {
if (Number(rent) < 0) {
throw error;
}
} catch {
Expand Down

1 comment on commit 2e13bfa

@vercel
Copy link

@vercel vercel bot commented on 2e13bfa Jun 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.