Skip to content

Commit

Permalink
Liquidity pool (#113)
Browse files Browse the repository at this point in the history
* Bootstrap AMM liquidity pool

* Adjust LP info

* Set links

* Add LP contract

* Show round 0 txs

* Adjust balances and allowance

* New LP contract

* Fix round end, change copy

* Add validation for staked Thales

* Adjust mobile, change labels

* All max allowance tooltip

* Remove filtering per round for Your transactions

* New LP contract

* New icon for LP

* Add copy

* Adjust external links

* Set height for buttons

* Add LP for OP mainnet

* Fix typo

* Update description

* Handle not connected wallet

* Set LP for Arbitrum

* Update text

* Set right formatting

* Fix approval logic on Arbitrum

* Remove console.log

* Update copy
  • Loading branch information
vladanthales authored Mar 15, 2023
1 parent 162dd67 commit 0dcb008
Show file tree
Hide file tree
Showing 41 changed files with 3,547 additions and 21 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"recharts": "^2.1.16",
"redux": "^4.1.2",
"styled-components": "^5.3.3",
"thales-data": "^1.2.11",
"thales-data": "^1.2.24",
"typescript": "^4.2.2",
"wagmi": "^0.6.4",
"web3": "^1.7.4"
Expand Down
9 changes: 7 additions & 2 deletions src/components/ApprovalModal/ApprovalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { RootState } from 'redux/rootReducer';
import { getIsWalletConnected } from 'redux/modules/wallet';
import { getIsWalletConnected, getNetworkId } from 'redux/modules/wallet';
import { BigNumber, ethers } from 'ethers';
import { bigNumberFormatter } from 'utils/formatters/ethers';
import styled from 'styled-components';
Expand Down Expand Up @@ -33,6 +33,7 @@ export const ApprovalModal: React.FC<ApprovalModalProps> = ({
}) => {
const { t } = useTranslation();
const isWalletConnected = useSelector((state: RootState) => getIsWalletConnected(state));
const networkId = useSelector((state: RootState) => getNetworkId(state));
const [amount, setAmount] = useState<number | string>(defaultAmount);
const [approveAll, setApproveAll] = useState<boolean>(true);
const [isAmountValid, setIsAmountValid] = useState<boolean>(true);
Expand All @@ -43,7 +44,11 @@ export const ApprovalModal: React.FC<ApprovalModalProps> = ({
const isAmountEntered = Number(amount) > 0;
const isButtonDisabled = !isWalletConnected || isAllowing || (!approveAll && (!isAmountEntered || !isAmountValid));

const amountConverted = getAmountForApproval(collateralIndex ? collateralIndex : 0, Number(amount).toString());
const amountConverted = getAmountForApproval(
collateralIndex ? collateralIndex : 0,
Number(amount).toString(),
networkId
);

const getSubmitButton = () => {
if (!isWalletConnected) {
Expand Down
7 changes: 5 additions & 2 deletions src/components/MintVoucherModal/MintVoucherModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export const MintVoucherModal: React.FC<MintVoucherModalProps> = ({ onClose }) =
const sUSDContractWithSigner = sUSDContract.connect(signer);
const getAllowance = async () => {
try {
const parsedAmount = ethers.utils.parseEther(Number(amount).toString());
const parsedAmount = ethers.utils.parseUnits(
Number(amount).toString(),
getDefaultDecimalsForNetwork(networkId)
);
const allowance = await checkAllowance(
parsedAmount,
sUSDContractWithSigner,
Expand All @@ -113,7 +116,7 @@ export const MintVoucherModal: React.FC<MintVoucherModalProps> = ({ onClose }) =
getAllowance();
}
}
}, [walletAddress, isWalletConnected, hasAllowance, amount, isAllowing]);
}, [walletAddress, isWalletConnected, hasAllowance, amount, isAllowing, networkId]);

const handleAllowance = async (approveAmount: BigNumber) => {
const { signer, sUSDContract, overtimeVoucherContract } = networkConnector;
Expand Down
6 changes: 6 additions & 0 deletions src/constants/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ export const LINKS = {
Medium:
'https://medium.com/@OvertimeMarkets.xyz/overtime-brings-the-bracket-to-the-blockchain-for-march-madness-66777956d87f',
},
UniswapBuyThalesOp:
'https://app.uniswap.org/#/swap?outputCurrency=0x217d47011b23bb961eb6d93ca9945b7501a5bb11&chain=optimism',
UniswapBuyThalesArbitrum:
'https://app.uniswap.org/#/swap?outputCurrency=0xE85B662Fe97e8562f4099d8A1d5A92D4B453bF30&chain=arbitrum',
ThalesStaking: 'https://thalesmarket.io/token',
ThalesTip99: 'https://github.com/thales-markets/thales-improvement-proposals/blob/main/TIPs/TIP-99.md',
};
14 changes: 14 additions & 0 deletions src/constants/liquidityPool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum LiquidityPoolTab {
DEPOSIT = 'deposit',
WITHDRAW = 'withdraw',
}

export enum LiquidityPoolTransaction {
USER_TRANSACTIONS = 'user-transactions',
YOUR_TRANSACTIONS = 'your-transactions',
}

export enum LiquidityPoolPnlType {
PNL_PER_ROUND = 'pnl-per-round',
CUMULATIVE_PNL = 'cumulative-pnl',
}
6 changes: 6 additions & 0 deletions src/constants/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export const QUERY_KEYS = {
networkId,
],
},
LiquidityPool: {
Data: (networkId: NetworkId) => ['liquidityPool', 'data', networkId],
UserData: (walletAddress: string, networkId: NetworkId) => ['liquidityPool', 'data', walletAddress, networkId],
PnL: (networkId: NetworkId) => ['liquidityPool', 'pnl', networkId],
UserTransactions: (networkId: NetworkId) => ['liquidityPool', 'userTransactions', networkId],
},
};

export default QUERY_KEYS;
1 change: 1 addition & 0 deletions src/constants/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const ROUTES = {
Vault: '/vaults/:vaultId',
Leaderboard: '/parlay-leaderboard',
MarchMadness: '/march-madness',
LiquidityPool: '/liquidity-pool',
};

export default ROUTES;
Expand Down
7 changes: 7 additions & 0 deletions src/constants/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export const NAV_MENU_SECOND_SECTION: NavMenuItem[] = [
route: ROUTES.Vaults,
supportedNetworks: [10, 420],
},
{
i18label: 'markets.nav-menu.items.liquidity-pool',
iconClass: 'icon icon--liquidity-pool',
name: 'liquidity-pool',
route: ROUTES.LiquidityPool,
supportedNetworks: [10, 420, 42161],
},
];

export const NAV_MENU_THIRD_SECTION: NavMenuItem[] = [
Expand Down
80 changes: 80 additions & 0 deletions src/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -935,5 +935,85 @@
"my-rewards": "我的奖励"
},
"test-info": "测试阶段现已开放样本团队,2023 年选择将于 3 月 12 日开放!"
},
"liquidity-pool": {
"title": "Provide Liquidity",
"description": "<h1>Description</h1><p>Liquidity providing involves users depositing stablecoin collateral into a smart contract-based liquidity pool for Overtime trading. The collateral deposited is used to facilitate trading on Overtime's AMM.</p><p>To be able to provide liquidity you'll need to be staking THALES. There's no maximum cap per wallet and you may deposit a maximum of 1 {{currency}} per {{thalesStakedAmount}} THALES staked until the liquidity pool is filled.</p><p>At the end of each round, the proportional share of that round's PnL will be added to your deposited balance.</p><p>If you wish to withdraw, you can signal that at any time during the ongoing round, and at the end of the round your balance (inclusive of that round's PnL) is sent to you. To withdraw, you need to have at least {{thalesStakedAmount}} THALES staked per each {{currency}} you are withdrawing.</p><p>If you decide to unstake THALES while providing liquidity, please be aware that you'll need to signal a withdrawal from the liquidity pool first.</p><p>Providing liquidity exposes you to various risks including potential losses due to users winning in trading as well as smart contract security risks. Please make sure you understand these risks before depositing.</p><p><tipLink>TIP-99</tipLink> has more details on the technical implementation of Overtime liquidity providing.</p>",
"variables": "<h1>Variables</h1><ul><li>Max total deposit: {{maxAllowedDeposit}}</li><li>Max users in the pool: {{maxAllowedUsers}}</li><li>Minimum deposit: {{minDepositAmount}}</li><li>Round duration: {{roundLength}} days</li></ul>",

"liquidity-pool-not-started-message": "The liquidity pool has not started",
"liquidity-pool-paused-message": "The liquidity pool is paused",
"round-end-label": "The round ends in",
"round-ended-label": "Round ended",

"total-info-label": "Total LP info",
"users-in-liquidity-pool-label": "Users in the liquidity pool: {{number}} / {{max}}",
"your-share-label": "Your share: {{percentage}} of LP",
"your-info-label": "Your LP info",
"current-balance-label": "Current balance",
"next-round-balance-label": "Next round balance",
"max-allowance-label": "Max allowance",
"your-thales-staked-label": "Your THALES staked",
"allowance-multiplier-label": "Allowance multiplier",
"withdrawal-request-label": "Withdrawal request: {{amount}}",
"estimated-amount-tooltip": "This is an estimated amount. The actual amount will be calculated upon closing the current round based on the round PnL.",

"deposit-amount-placeholder": "Enter amount",
"available-to-withdraw-label": "Available to withdraw: <bold>{{amount}}</bold>",
"nothing-to-withdraw-label": "Nothing to withdraw.",
"withdrawal-message": "You can request a withdrawal and your funds will be sent to you automatically at the end of the round when the round closes.",
"withdrawal-requested-message": "You requested to withdraw <bold>{{amount}}</bold><tooltip />. Your funds will be sent to you automatically at the end of the round when the round closes.",
"first-deposit-withdrawal-message": "You deposited for the next round and you can withdraw these funds at the end of the next round.",
"deposit-withdrawal-warning": "Withdrawal is requested, you cannot deposit.",
"deposit-max-amount-of-users-warning": "Maximum number of users in the liquidity pool is reached, you cannot deposit.",
"deposit-liquidity-pool-cap-reached-warning": "The liquidity pool cap is reached, you cannot deposit.",
"deposit-liquidity-pool-cap-error": "Deposit amount exceeds liquidity pool cap",
"deposit-staked-thales-error": "Deposit amount exceeds max allowance, stake more THALES to deposit",
"deposit-min-amount-error": "The minimum amount for the deposit is {{amount}}",
"withdrawal-deposit-warning": "You cannot withdraw as you already deposited for the next round.",
"withdrawal-staked-thales-warning": "You cannot withdraw as you need more staked THALES to withdraw. Stake {{amount}} THALES more to enable withdrawal.",

"tabs": {
"deposit": "Deposit",
"withdraw": "Withdraw"
},
"button": {
"deposit-label": "Deposit",
"deposit-progress-label": "Deposit in progress...",
"deposit-confirmation-message": "Deposit successfully placed",
"request-withdrawal-label": "Request withdrawal",
"request-withdrawal-progress-label": "Request in progress...",
"request-withdrawal-confirmation-message": "Withdrawal request successfully sent",
"withdraw-label": "Withdraw",
"withdraw-progress-label": "Withdrawal in progress...",
"withdraw-confirmation-message": "Funds successfully withdrawn",
"close-round-label": "Close round",
"close-round-progress-label": "Closing round in progress...",
"close-round-confirmation-message": "Round successfully closed",
"get-thales-label": "Get THALES",
"stake-thales-label": "Stake THALES"
},
"pnl": {
"pnl-per-round": {
"title": "PnL per round"
},
"cumulative-pnl": {
"title": "PnL over time"
},
"no-data": "No PnL data for previous rounds.",
"lifetime-pnl": "Lifetime PnL",
"ongoing-pnl": "Ongoing PnL"
},
"user-transactions": {
"title": "User transactions",
"your-transactions-title": "Your transactions",
"no-transactions": "No user transactions associated with this liquidity pool in the selected round.",
"round-label": "Round",
"type": {
"deposit": "Deposit",
"withdrawalRequest": "Withdrawal Request",
"claim": "Withdrawal Claim"
}
}
}
}
80 changes: 80 additions & 0 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -932,5 +932,85 @@
"my-rewards": "Meine Belohnungen"
},
"test-info": "Die Testphase mit den Musterteams ist jetzt eröffnet, die Auswahl 2023 öffnet am 12. März!"
},
"liquidity-pool": {
"title": "Provide Liquidity",
"description": "<h1>Description</h1><p>Liquidity providing involves users depositing stablecoin collateral into a smart contract-based liquidity pool for Overtime trading. The collateral deposited is used to facilitate trading on Overtime's AMM.</p><p>To be able to provide liquidity you'll need to be staking THALES. There's no maximum cap per wallet and you may deposit a maximum of 1 {{currency}} per {{thalesStakedAmount}} THALES staked until the liquidity pool is filled.</p><p>At the end of each round, the proportional share of that round's PnL will be added to your deposited balance.</p><p>If you wish to withdraw, you can signal that at any time during the ongoing round, and at the end of the round your balance (inclusive of that round's PnL) is sent to you. To withdraw, you need to have at least {{thalesStakedAmount}} THALES staked per each {{currency}} you are withdrawing.</p><p>If you decide to unstake THALES while providing liquidity, please be aware that you'll need to signal a withdrawal from the liquidity pool first.</p><p>Providing liquidity exposes you to various risks including potential losses due to users winning in trading as well as smart contract security risks. Please make sure you understand these risks before depositing.</p><p><tipLink>TIP-99</tipLink> has more details on the technical implementation of Overtime liquidity providing.</p>",
"variables": "<h1>Variables</h1><ul><li>Max total deposit: {{maxAllowedDeposit}}</li><li>Max users in the pool: {{maxAllowedUsers}}</li><li>Minimum deposit: {{minDepositAmount}}</li><li>Round duration: {{roundLength}} days</li></ul>",

"liquidity-pool-not-started-message": "The liquidity pool has not started",
"liquidity-pool-paused-message": "The liquidity pool is paused",
"round-end-label": "The round ends in",
"round-ended-label": "Round ended",

"total-info-label": "Total LP info",
"users-in-liquidity-pool-label": "Users in the liquidity pool: {{number}} / {{max}}",
"your-share-label": "Your share: {{percentage}} of LP",
"your-info-label": "Your LP info",
"current-balance-label": "Current balance",
"next-round-balance-label": "Next round balance",
"max-allowance-label": "Max allowance",
"your-thales-staked-label": "Your THALES staked",
"allowance-multiplier-label": "Allowance multiplier",
"withdrawal-request-label": "Withdrawal request: {{amount}}",
"estimated-amount-tooltip": "This is an estimated amount. The actual amount will be calculated upon closing the current round based on the round PnL.",

"deposit-amount-placeholder": "Enter amount",
"available-to-withdraw-label": "Available to withdraw: <bold>{{amount}}</bold>",
"nothing-to-withdraw-label": "Nothing to withdraw.",
"withdrawal-message": "You can request a withdrawal and your funds will be sent to you automatically at the end of the round when the round closes.",
"withdrawal-requested-message": "You requested to withdraw <bold>{{amount}}</bold><tooltip />. Your funds will be sent to you automatically at the end of the round when the round closes.",
"first-deposit-withdrawal-message": "You deposited for the next round and you can withdraw these funds at the end of the next round.",
"deposit-withdrawal-warning": "Withdrawal is requested, you cannot deposit.",
"deposit-max-amount-of-users-warning": "Maximum number of users in the liquidity pool is reached, you cannot deposit.",
"deposit-liquidity-pool-cap-reached-warning": "The liquidity pool cap is reached, you cannot deposit.",
"deposit-liquidity-pool-cap-error": "Deposit amount exceeds liquidity pool cap",
"deposit-staked-thales-error": "Deposit amount exceeds max allowance, stake more THALES to deposit",
"deposit-min-amount-error": "The minimum amount for the deposit is {{amount}}",
"withdrawal-deposit-warning": "You cannot withdraw as you already deposited for the next round.",
"withdrawal-staked-thales-warning": "You cannot withdraw as you need more staked THALES to withdraw. Stake {{amount}} THALES more to enable withdrawal.",

"tabs": {
"deposit": "Deposit",
"withdraw": "Withdraw"
},
"button": {
"deposit-label": "Deposit",
"deposit-progress-label": "Deposit in progress...",
"deposit-confirmation-message": "Deposit successfully placed",
"request-withdrawal-label": "Request withdrawal",
"request-withdrawal-progress-label": "Request in progress...",
"request-withdrawal-confirmation-message": "Withdrawal request successfully sent",
"withdraw-label": "Withdraw",
"withdraw-progress-label": "Withdrawal in progress...",
"withdraw-confirmation-message": "Funds successfully withdrawn",
"close-round-label": "Close round",
"close-round-progress-label": "Closing round in progress...",
"close-round-confirmation-message": "Round successfully closed",
"get-thales-label": "Get THALES",
"stake-thales-label": "Stake THALES"
},
"pnl": {
"pnl-per-round": {
"title": "PnL per round"
},
"cumulative-pnl": {
"title": "PnL over time"
},
"no-data": "No PnL data for previous rounds.",
"lifetime-pnl": "Lifetime PnL",
"ongoing-pnl": "Ongoing PnL"
},
"user-transactions": {
"title": "User transactions",
"your-transactions-title": "Your transactions",
"no-transactions": "No user transactions associated with this liquidity pool in the selected round.",
"round-label": "Round",
"type": {
"deposit": "Deposit",
"withdrawalRequest": "Withdrawal Request",
"claim": "Withdrawal Claim"
}
}
}
}
Loading

0 comments on commit 0dcb008

Please sign in to comment.