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

feat: contract hooks #11121

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
260 changes: 260 additions & 0 deletions apps/web/src/config/abi/ido.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
export const idoABI = [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{ inputs: [], name: 'AddressesLengthNotCorrect', type: 'error' },
{ inputs: [], name: 'AlreadyHarvested', type: 'error' },
{ inputs: [], name: 'AlreadyInitialized', type: 'error' },
{ inputs: [], name: 'AmountMustBeZero', type: 'error' },
{ inputs: [], name: 'AmountMustExceedZero', type: 'error' },
{ inputs: [], name: 'CanNotBeLPToken', type: 'error' },
{ inputs: [], name: 'CanNotBeOfferingToken', type: 'error' },
{ inputs: [], name: 'DidNotParticipate', type: 'error' },
{ inputs: [], name: 'EmptyUserAddress', type: 'error' },
{ inputs: [], name: 'EndTimeTooFar', type: 'error' },
{ inputs: [], name: 'FlatTaxRateMustBe0WhenHasTaxIsFalse', type: 'error' },
{ inputs: [], name: 'FlatTaxRateMustBeLessThan1e12', type: 'error' },
{ inputs: [], name: 'IDOHasEnded', type: 'error' },
{ inputs: [], name: 'IDOHasStarted', type: 'error' },
{ inputs: [], name: 'NewAmountAboveUserCap', type: 'error' },
{ inputs: [], name: 'NotEnoughLPTokens', type: 'error' },
{ inputs: [], name: 'NotEnoughOfferingTokens', type: 'error' },
{ inputs: [], name: 'NotFactory', type: 'error' },
{ inputs: [], name: 'NotMeetAnyoneOfRequiredConditions', type: 'error' },
{ inputs: [], name: 'PoolNotSet', type: 'error' },
{ inputs: [], name: 'StartAndEndTimestampsLengthNotCorrect', type: 'error' },
{ inputs: [], name: 'StartTimeMustGreaterThanCurrentBlockTime', type: 'error' },
{ inputs: [], name: 'StartTimeMustInferiorToEndTime', type: 'error' },
{ inputs: [], name: 'TokensNotDepositedProperly', type: 'error' },
{ inputs: [], name: 'TooEarly', type: 'error' },
{ inputs: [], name: 'TooLate', type: 'error' },
{
anonymous: false,
inputs: [
{ indexed: false, internalType: 'address', name: 'tokenAddress', type: 'address' },
{ indexed: false, internalType: 'uint256', name: 'amountTokens', type: 'uint256' },
],
name: 'AdminTokenRecovery',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: false, internalType: 'uint256', name: 'amountLP', type: 'uint256' },
{ indexed: false, internalType: 'uint256', name: 'amountOfferingToken', type: 'uint256' },
],
name: 'AdminWithdraw',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: 'address', name: 'user', type: 'address' },
{ indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' },
],
name: 'Deposit',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: 'address', name: 'user', type: 'address' },
{ indexed: false, internalType: 'uint256', name: 'offeringAmount', type: 'uint256' },
{ indexed: false, internalType: 'uint256', name: 'excessAmount', type: 'uint256' },
],
name: 'Harvest',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: false, internalType: 'uint256', name: 'startTimestamp', type: 'uint256' },
{ indexed: false, internalType: 'uint256', name: 'endTimestamp', type: 'uint256' },
],
name: 'NewStartAndEndTimestamps',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: 'address', name: 'previousOwner', type: 'address' },
{ indexed: true, internalType: 'address', name: 'newOwner', type: 'address' },
],
name: 'OwnershipTransferred',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: false, internalType: 'uint256', name: 'offeringAmountPool', type: 'uint256' },
{ indexed: false, internalType: 'uint256', name: 'raisingAmountPool', type: 'uint256' },
],
name: 'PoolParametersSet',
type: 'event',
},
{
inputs: [],
name: 'MAX_BUFFER_SECONDS',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: '_poolInformation',
outputs: [
{ internalType: 'uint256', name: 'raisingAmountPool', type: 'uint256' },
{ internalType: 'uint256', name: 'offeringAmountPool', type: 'uint256' },
{ internalType: 'uint256', name: 'capPerUserInLP', type: 'uint256' },
{ internalType: 'bool', name: 'hasTax', type: 'bool' },
{ internalType: 'uint256', name: 'flatTaxRate', type: 'uint256' },
{ internalType: 'uint256', name: 'totalAmountPool', type: 'uint256' },
{ internalType: 'uint256', name: 'sumTaxesOverflow', type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
name: 'addresses',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
name: 'depositPool',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
{
inputs: [],
name: 'endTimestamp',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'uint256', name: '_lpAmount', type: 'uint256' },
{ internalType: 'uint256', name: '_offerAmount', type: 'uint256' },
],
name: 'finalWithdraw',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{ inputs: [], name: 'harvestPool', outputs: [], stateMutability: 'nonpayable', type: 'function' },
{
inputs: [
{ internalType: 'address[]', name: '_addresses', type: 'address[]' },
{ internalType: 'uint256[]', name: '_startAndEndTimestamps', type: 'uint256[]' },
{ internalType: 'uint256', name: '_maxBufferSeconds', type: 'uint256' },
],
name: 'initialize',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'owner',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{ internalType: 'address', name: '_tokenAddress', type: 'address' },
{ internalType: 'uint256', name: '_tokenAmount', type: 'uint256' },
],
name: 'recoverWrongTokens',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{ inputs: [], name: 'renounceOwnership', outputs: [], stateMutability: 'nonpayable', type: 'function' },
{
inputs: [
{ internalType: 'uint256', name: '_offeringAmountPool', type: 'uint256' },
{ internalType: 'uint256', name: '_raisingAmountPool', type: 'uint256' },
{ internalType: 'uint256', name: '_limitPerUserInLP', type: 'uint256' },
{ internalType: 'bool', name: '_hasTax', type: 'bool' },
{ internalType: 'uint256', name: '_flatTaxRate', type: 'uint256' },
],
name: 'setPool',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'startTimestamp',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: 'newOwner', type: 'address' }],
name: 'transferOwnership',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [{ internalType: 'uint256[]', name: '_startAndEndTimestamps', type: 'uint256[]' }],
name: 'updateStartAndEndTimestamps',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [],
name: 'viewPoolInformation',
outputs: [
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'bool', name: '', type: 'bool' },
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'viewPoolTaxRateOverflow',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
name: 'viewUserAllocation',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
name: 'viewUserInfo',
outputs: [
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'bool', name: '', type: 'bool' },
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: '_user', type: 'address' }],
name: 'viewUserOfferingAndRefundingAmounts',
outputs: [
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
{ internalType: 'uint256', name: '', type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
] as const
3 changes: 3 additions & 0 deletions apps/web/src/config/constants/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,7 @@ export default {
[ChainId.ZKSYNC_TESTNET]: '0xbfcCF87Ee5cd03d4550Cc1526Bf152cc2EE1C7AB',
[ChainId.ZKSYNC]: '0xB774c13bA5a665713037c42A12f0ED9De70585cB',
},
ido: {
[ChainId.BSC_TESTNET]: '0xCd2358dd6FD92447ACAdB9f1A437A658151a2C25',
},
} as const satisfies Record<string, Record<number, `0x${string}`>>
8 changes: 8 additions & 0 deletions apps/web/src/hooks/useContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getFarmAuctionContract,
getFixedStakingContract,
getGaugesVotingContract,
getIDOContract,
getIfoCreditAddressContract,
getLotteryV2Contract,
getMasterChefContract,
Expand Down Expand Up @@ -587,3 +588,10 @@ export const useRevenueSharingPoolGatewayContract = () => {

return useMemo(() => getRevenueSharingPoolGatewayContract(signer ?? undefined, chainId), [signer, chainId])
}

export const useIDOContract = () => {
const { chainId } = useActiveChainId()
const { data: signer } = useWalletClient()

return useMemo(() => getIDOContract(signer ?? undefined, chainId), [chainId, signer])
}
4 changes: 4 additions & 0 deletions apps/web/src/utils/addressHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,7 @@ export const getRevenueSharingVeCakeAddressNoFallback = (chainId?: number) => {
export const getRevenueSharingPoolGatewayAddress = (chainId?: number) => {
return getAddressFromMap(addresses.revenueSharingPoolGateway, chainId)
}

export const getIDOAddress = (chainId?: number) => {
return getAddressFromMap(addresses.ido, chainId)
}
15 changes: 13 additions & 2 deletions apps/web/src/utils/contractHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import {
getCalcGaugesVotingAddress,
getCrossFarmingReceiverAddress,
getCrossFarmingSenderAddress,
getCrossFarmingVaultAddress,
getFarmAuctionAddress,
getFixedStakingAddress,
getGaugesVotingAddress,
getIDOAddress,
getLotteryV2Address,
getMasterChefV2Address,
getMasterChefV3Address,
getNftMarketAddress,
getNftSaleAddress,
getCrossFarmingVaultAddress,
getPancakeProfileAddress,
getPancakeSquadAddress,
getPancakeVeSenderV2Address,
Expand Down Expand Up @@ -53,8 +54,8 @@ import {
import { predictionsV1ABI, predictionsV2ABI, predictionsV3ABI } from '@pancakeswap/prediction'
import { crossFarmingProxyABI } from 'config/abi/crossFarmingProxy'
import { crossFarmingSenderABI } from 'config/abi/crossFarmingSender'
import { nftSaleABI } from 'config/abi/nftSale'
import { crossFarmingVaultABI } from 'config/abi/crossFarmingVault'
import { nftSaleABI } from 'config/abi/nftSale'
import { pointCenterIfoABI } from 'config/abi/pointCenterIfo'
import { stableSwapNativeHelperABI } from 'config/abi/stableSwapNativeHelper'

Expand Down Expand Up @@ -82,6 +83,7 @@ import { chainlinkOracleABI } from 'config/abi/chainlinkOracle'
import { crossFarmingReceiverABI } from 'config/abi/crossFarmingReceiver'
import { farmAuctionABI } from 'config/abi/farmAuction'
import { fixedStakingABI } from 'config/abi/fixedStaking'
import { idoABI } from 'config/abi/ido'
import { lotteryV2ABI } from 'config/abi/lotteryV2'
import { lpTokenABI } from 'config/abi/lpTokenAbi'
import { masterChefV2ABI } from 'config/abi/masterchefV2'
Expand Down Expand Up @@ -592,3 +594,12 @@ export const getRevenueSharingPoolGatewayContract = (signer?: WalletClient, chai
chainId,
})
}

export const getIDOContract = (signer?: WalletClient, chainId?: number) => {
return getContract({
abi: idoABI,
address: getIDOAddress(chainId) ?? getIDOAddress(ChainId.BSC),
signer,
chainId,
})
}
29 changes: 29 additions & 0 deletions apps/web/src/views/Idos/hooks/ido/usdIDOStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type Currency, CurrencyAmount, Percent } from '@pancakeswap/swap-sdk-core'
import { useMemo } from 'react'
import { useIDOCurrencies } from './useIDOCurrencies'
import { useIDOPoolInfo } from './useIDOPoolInfo'

export type IDOStatus = {
progress: Percent
currentStakedAmount: CurrencyAmount<Currency>
}

export const useIDOStatus = () => {
const { stakeCurrency } = useIDOCurrencies()
const { data: poolInfo } = useIDOPoolInfo()

const progress = useMemo(() => {
if (!poolInfo) return new Percent(0, 100)
return new Percent(poolInfo.totalAmountPool, poolInfo.raisingAmountPool)
}, [poolInfo])

const currentStakedAmount = useMemo(() => {
if (!stakeCurrency || !poolInfo) return undefined
return CurrencyAmount.fromRawAmount(stakeCurrency, poolInfo.totalAmountPool)
}, [poolInfo, stakeCurrency])

return {
progress,
currentStakedAmount,
}
}
Loading
Loading