Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(bond & tokenomics) feat: bond migration final #75

Merged
merged 22 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f20fd6c
fix: update dispenser ABI
mohandast52 Aug 8, 2024
3149f9c
fix: update tokenomics ABI
mohandast52 Aug 8, 2024
e104e99
feat: update bonding products
mohandast52 Aug 8, 2024
8165e72
feat: update deposit component tag
mohandast52 Aug 9, 2024
eac13e4
chore: raw send transaction for deposit
mohandast52 Aug 9, 2024
f7da5b5
chore: minor updates to deposit
mohandast52 Aug 9, 2024
a1386c0
chore: remove logs
mohandast52 Aug 9, 2024
b3a13f0
refactor: Remove unused code and optimize useWhirlPoolInformation hook
mohandast52 Aug 9, 2024
af689c3
chore: address Tanya's review request
mohandast52 Aug 9, 2024
0097a42
chore: remove duplicate middleware
mohandast52 Aug 12, 2024
43dae31
chore: remvoe support for goerli
mohandast52 Aug 12, 2024
3afe314
chore: remove goerli and some CSS change
mohandast52 Aug 12, 2024
aad7b57
fix: bond error resolved
mohandast52 Aug 13, 2024
6226a88
chore: add logs for issue faced on Solana Liquidity
mohandast52 Aug 16, 2024
7db34fc
feat: calculation fix for deposit
mohandast52 Aug 16, 2024
3ff28ac
feat: calculate OLAS payout
mohandast52 Aug 16, 2024
6cf8d7d
feat: enhance error message in Solana liquidity management
mohandast52 Aug 22, 2024
b7ac697
feat: add tooltip to MyBonds - OLAS payout column
mohandast52 Aug 22, 2024
5c33ca9
fix: Add missing file to .gitleaksignore
mohandast52 Aug 22, 2024
501e504
fix: minor chnages
mohandast52 Aug 22, 2024
91701fc
feat: fix bonds-footer
mohandast52 Aug 22, 2024
04202e3
feat: add RPC endpoint to allowed origins in CSP header
mohandast52 Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NEXT_PUBLIC_GNOSIS_TEST_RPC=__URL__
NEXT_PUBLIC_POLYGON_TEST_RPC=__URL__
NEXT_PUBLIC_IS_CONNECTED_TO_TEST_NET=

# autonolas-registry-frontend
# registry
NEXT_PUBLIC_REGISTRY_URL=__value__
NEXT_PUBLIC_AUTONOLAS_URL=__value__
NEXT_PUBLIC_GNOSIS_SAFE_API_MAINNET=__value__
Expand All @@ -30,8 +30,13 @@ NEXT_PUBLIC_ETHERSCAN_API_KEY=__value__
NEXT_PUBLIC_SOLANA_MAINNET_BETA_URL=__value__
NEXT_PUBLIC_SVM_PUBLIC_KEY=__value__

# autonolas-tokenomics-frontend
# tokenomics
NEXT_PUBLIC_GRAPH_ENDPOINT_MAINNET=__URL__
NEXT_PUBLIC_SHYFT_API_KEY=__KEY__
NEXT_PUBLIC_IS_CONNECTED_TO_LOCAL=__TRUE_OR_FALSE__

# bond
NEXT_PUBLIC_MAINNET_BALANCER_URL=__URL__
NEXT_PUBLIC_OPTIMISM_BALANCER_URL=__URL__
NEXT_PUBLIC_GNOSIS_BALANCER_URL=__URL__
NEXT_PUBLIC_POLYGON_BALANCER_URL=__URL__
NEXT_PUBLIC_ARBITRUM_BALANCER_URL=__URL__
33 changes: 21 additions & 12 deletions apps/bond/common-util/graphql/clients.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { GraphQLClient } from 'graphql-request';
import {
arbitrum,
base,
gnosis,
goerli,
mainnet,
optimism,
polygon,
} from 'viem/chains';

const requestConfig = {
jsonSerializer: {
Expand All @@ -16,32 +25,32 @@ export const AUTONOLAS_GRAPH_CLIENTS = {

// https://docs.balancer.fi/reference/subgraph/ for future subgraph endpoints
export const BALANCER_GRAPH_CLIENTS = {
1: new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-v2',
[mainnet.id]: new GraphQLClient(
process.env.NEXT_PUBLIC_MAINNET_BALANCER_URL,
requestConfig,
),
5: new GraphQLClient(
[goerli.id]: new GraphQLClient(
mohandast52 marked this conversation as resolved.
Show resolved Hide resolved
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-goerli-v2',
requestConfig,
),
10: new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-optimism-v2',
[optimism.id]: new GraphQLClient(
process.env.NEXT_PUBLIC_OPTIMISM_BALANCER_URL,
requestConfig,
),
100: new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-gnosis-chain-v2',
[gnosis.id]: new GraphQLClient(
process.env.NEXT_PUBLIC_GNOSIS_BALANCER_URL,
requestConfig,
),
137: new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2',
[polygon.id]: new GraphQLClient(
process.env.NEXT_PUBLIC_POLYGON_BALANCER_URL,
requestConfig,
),
8453: new GraphQLClient(
[base.id]: new GraphQLClient(
'https://api.studio.thegraph.com/query/24660/balancer-base-v2/version/latest',
requestConfig,
),
42161: new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-arbitrum-v2',
[arbitrum.id]: new GraphQLClient(
Copy link
Collaborator

@77ph 77ph Aug 12, 2024

Choose a reason for hiding this comment

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

not config for CELO

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't support CELO in tokenomics, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

CELO bonding in tokenomics at stage of preparing voting. yes, not supported atm.

process.env.NEXT_PUBLIC_ARBITRUM_BALANCER_URL,
requestConfig,
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
QuestionCircleOutlined,
UnorderedListOutlined,
} from '@ant-design/icons';
import { Button, Empty, Popconfirm, Spin, Table, Tag, Tooltip, Typography } from 'antd';
import { Button, Empty, Popconfirm, Skeleton, Spin, Table, Tag, Tooltip, Typography } from 'antd';
import { isNaN, remove, round } from 'lodash';
import Link from 'next/link';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -33,6 +33,10 @@ const Container = styled.div`
}
`;

const Loader = () => <Skeleton.Button size="small" className="full-width" active block />;

const isCurrentPriceLpZero = (currentPrice) => Number(currentPrice) === 0;

const getTitle = (title, tooltipDesc) => (
<Tooltip title={tooltipDesc}>
<span>
Expand Down Expand Up @@ -86,11 +90,17 @@ const getColumns = (onClick, isActive, acc, depositoryAddress, hideEmptyProducts
dataIndex: 'fullCurrentPriceLp',
key: 'fullCurrentPriceLp',
width: 140,
render: (x, details) => (
<a href={details.currentPriceLpLink} rel="noopener noreferrer" target="_blank">
{x}
</a>
),
render: (currentPriceLp, details) => {
if (isCurrentPriceLpZero(currentPriceLp)) {
return <Loader />;
}

return (
<a href={details.currentPriceLpLink} rel="noopener noreferrer" target="_blank">
{currentPriceLp}
</a>
);
},
},
{
title: getTitle(
Expand Down Expand Up @@ -223,8 +233,16 @@ const getColumns = (onClick, isActive, acc, depositoryAddress, hideEmptyProducts
return columns;
};

const sortList = (list) =>
const sortProducts = (list) =>
list.sort((a, b) => {
// if the current price of the LP token is zero, then move it to the end of the list
// NOTE: It can be zero because
// - the API returns zero (shouldn't happen) OR
// - has error OR
// - not fetched yet
Comment on lines +241 to +242
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this our own API?
if so it should return some nullish reponse rather than 0, as this is an incorrect value..
no worries if not

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default value is 0, which is why this calculation exists and also, we need to move the 0s to the bottom.

const isSvm = a.lpChainId === VM_TYPE.SVM || b.lpChainId === VM_TYPE.SVM;
if (isSvm && isCurrentPriceLpZero(a.fullCurrentPriceLp)) return 1;

if (isNaN(a.projectedChange)) return 1;
if (isNaN(b.projectedChange)) return -1;
return b.projectedChange - a.projectedChange;
Expand Down Expand Up @@ -282,7 +300,7 @@ export const BondingList = ({ bondingProgramType, hideEmptyProducts }) => {
}, [handleProductDetails]);

const getProductsDataSource = useCallback(() => {
const sortedList = sortList(filteredProducts);
const sortedList = sortProducts(filteredProducts);
const processedList = hideEmptyProducts
? sortedList.filter((x) => x.supplyLeft > 0.00001)
: sortedList;
Expand All @@ -308,16 +326,17 @@ export const BondingList = ({ bondingProgramType, hideEmptyProducts }) => {
pagination={false}
scroll={{ x: 400 }}
className="mb-16"
rowHoverable={false}
/>

{!!productDetails && (
<Deposit
productId={productDetails?.id}
productToken={productDetails?.token}
productLpPriceInBg={getLpTokenWithDiscount(
productLpPriceAfterDiscount={getLpTokenWithDiscount(
productDetails?.priceLp,
productDetails?.discount,
)}
).toString()}
productSupply={productDetails?.supply}
getProducts={refetch}
closeModal={handleModalClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { usePublicClient } from 'wagmi';
import { VM_TYPE, areAddressesEqual } from '@autonolas/frontend-library';

import { DEPOSITORY } from 'libs/util-contracts/src/lib/abiAndAddresses';

import { ADDRESSES } from 'common-util/constants/addresses';
import { ADDRESS_ZERO, ONE_ETH } from 'common-util/constants/numbers';
import { DEX } from 'common-util/enums';
Expand Down
56 changes: 31 additions & 25 deletions apps/bond/components/BondingProducts/Bonding/Deposit/Deposit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { isNil } from 'lodash';
import PropTypes from 'prop-types';
import { useCallback, useEffect, useState } from 'react';

import {
COLOR,
getCommaSeparatedNumber,
notifyError,
notifySuccess,
} from '@autonolas/frontend-library';
import { getCommaSeparatedNumber } from '@autonolas/frontend-library';

import { COLOR } from 'libs/ui-theme/src';
import { notifyError, notifySuccess } from 'libs/util-functions/src';

import { ONE_ETH_IN_STRING } from 'common-util/constants/numbers';
import {
Expand All @@ -30,7 +28,7 @@ const fullWidth = { width: '100%' };
export const Deposit = ({
productId,
productToken,
productLpPriceInBg,
productLpPriceAfterDiscount,
productSupply,
getProducts,
closeModal,
Expand All @@ -43,6 +41,9 @@ export const Deposit = ({

const isSvmProduct = isSvmLpAddress(productToken);

// convert to BigNumber of bignumber.js and not ethers
const productLpPriceAfterDiscountInBg = new BigNumber(productLpPriceAfterDiscount);

const { getLpBalanceRequest, depositRequest, approveRequest, hasSufficientTokenRequest } =
useDeposit();

Expand Down Expand Up @@ -82,7 +83,7 @@ export const Deposit = ({
notifySuccess('Deposited successfully!', `Transaction Hash: ${txHash}`);

// fetch the products details again
getProducts();
await getProducts();

// close the modal after successful deposit
closeModal();
Expand Down Expand Up @@ -126,13 +127,14 @@ export const Deposit = ({
};

const getRemainingLpSupplyInEth = () => {
const supplyInWei = new BigNumber(productSupply || '0');
const productSupplyInWei = new BigNumber(productSupply || '0');
const lpBalanceInBg = new BigNumber(lpBalance);

const remainingSupply = supplyInWei
const remainingSupply = productSupplyInWei
.multipliedBy(ONE_ETH_IN_STRING)
.dividedBy(productLpPriceInBg);
.dividedBy(productLpPriceAfterDiscountInBg);

const remainingSupplyInWei = remainingSupply.lt(lpBalance) ? remainingSupply : lpBalance;
const remainingSupplyInWei = remainingSupply.lt(lpBalanceInBg) ? remainingSupply : lpBalance;
return parseToEth(remainingSupplyInWei);
};

Expand All @@ -147,8 +149,7 @@ export const Deposit = ({
? tokenAmountInputValue
: new BigNumber(parseToWei(tokenAmountInputValue));

const payoutInBg = new BigNumber(productLpPriceInBg.toString()).multipliedBy(tokenAmountValue);

const payoutInBg = productLpPriceAfterDiscountInBg.multipliedBy(tokenAmountValue);
const payout = isSvmProduct
? payoutInBg.dividedBy(BigNumber(`1${'0'.repeat(28)}`)).toFixed(2)
: Number(payoutInBg.dividedBy(ONE_ETH_IN_STRING).dividedBy(ONE_ETH_IN_STRING).toFixed(2));
Expand Down Expand Up @@ -178,8 +179,8 @@ export const Deposit = ({
autoComplete="off"
className="mt-16"
>
<Tag color={COLOR.PRIMARY} className="deposit-tag">
<Text>{`Bonding Product ID: ${productId}`}</Text>
<Tag color={COLOR.PRIMARY} className="deposit-tag mb-12">
{`Bonding Product ID: ${productId}`}
</Tag>

<Form.Item
Expand Down Expand Up @@ -222,7 +223,6 @@ export const Deposit = ({
form.setFieldsValue({ tokenAmount: remainingLpSupplyInEth });
form.validateFields(['tokenAmount']);
}}
className="pl-0"
>
Max
</Button>
Expand Down Expand Up @@ -255,12 +255,12 @@ export const Deposit = ({
htmlType="submit"
loading={isLoading}
onClick={async () => {
try {
if (!account) {
notifyError('Please connect your wallet');
return;
}
if (!account) {
notifyError('Please connect your wallet');
return;
}

try {
setIsLoading(true);
await approveRequest({
token: productToken,
Expand Down Expand Up @@ -291,16 +291,22 @@ export const Deposit = ({
Deposit.propTypes = {
productId: PropTypes.string,
productToken: PropTypes.string,
productSupply: PropTypes.string,
productLpPriceInBg: PropTypes.shape({}),
productSupply: PropTypes.oneOfType([
PropTypes.instanceOf(PropTypes.string),
PropTypes.instanceOf(BigInt),
]),
productLpPriceAfterDiscount: PropTypes.oneOfType([
PropTypes.instanceOf(PropTypes.string),
PropTypes.instanceOf(BigInt),
]),
closeModal: PropTypes.func,
getProducts: PropTypes.func,
};

Deposit.defaultProps = {
productId: undefined,
productToken: null,
productLpPriceInBg: null,
productLpPriceAfterDiscount: null,
productSupply: null,
closeModal: () => {},
getProducts: () => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export const useDeposit = () => {
const treasuryAddress = ADDRESSES[chainId].treasury;
const fnApprove = contract.methods.approve(treasuryAddress, amountToApprove);
const estimatedGas = await getEstimatedGasLimit(fnApprove, account);
const fn = await fnApprove.send({
from: account,
gasLimit: estimatedGas,
});
const fn = await fnApprove.send({ from: account, gasLimit: estimatedGas });

const response = await sendTransaction(fn, account);
return response;
Expand Down
Loading
Loading