From 74580dba5037512450ba049a64be36a787e6343a Mon Sep 17 00:00:00 2001 From: William Poulin Date: Mon, 11 Dec 2023 14:06:28 -0500 Subject: [PATCH] feat(dhedge-v2): Add staking position (#3125) --- ...ge-v2.staking.contract-position-fetcher.ts | 142 ++ .../contracts/abis/dhedge-v-2-staking.json | 718 +++++++ .../contracts/viem.contract-factory.ts | 5 +- .../contracts/viem/DhedgeV2Staking.ts | 1678 +++++++++++++++++ src/apps/dhedge-v2/contracts/viem/index.ts | 2 + src/apps/dhedge-v2/dhedge-v2.module.ts | 8 +- ...ge-v2.staking.contract-position-fetcher.ts | 10 + 7 files changed, 2561 insertions(+), 2 deletions(-) create mode 100644 src/apps/dhedge-v2/common/dhedge-v2.staking.contract-position-fetcher.ts create mode 100644 src/apps/dhedge-v2/contracts/abis/dhedge-v-2-staking.json create mode 100644 src/apps/dhedge-v2/contracts/viem/DhedgeV2Staking.ts create mode 100644 src/apps/dhedge-v2/optimism/dhedge-v2.staking.contract-position-fetcher.ts diff --git a/src/apps/dhedge-v2/common/dhedge-v2.staking.contract-position-fetcher.ts b/src/apps/dhedge-v2/common/dhedge-v2.staking.contract-position-fetcher.ts new file mode 100644 index 000000000..af031847c --- /dev/null +++ b/src/apps/dhedge-v2/common/dhedge-v2.staking.contract-position-fetcher.ts @@ -0,0 +1,142 @@ +import { Inject, NotImplementedException } from '@nestjs/common'; +import _, { range } from 'lodash'; + +import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { drillBalance } from '~app-toolkit/helpers/drill-balance.helper'; +import { getLabelFromToken } from '~app-toolkit/helpers/presentation/image.present'; +import { DefaultDataProps } from '~position/display.interface'; +import { ContractPositionBalance } from '~position/position-balance.interface'; +import { MetaType } from '~position/position.interface'; +import { + GetDefinitionsParams, + GetDisplayPropsParams, + GetTokenDefinitionsParams, +} from '~position/template/contract-position.template.types'; +import { CustomContractPositionTemplatePositionFetcher } from '~position/template/custom-contract-position.template.position-fetcher'; + +import { DhedgeV2ViemContractFactory } from '../contracts'; +import { DhedgeV2Staking } from '../contracts/viem'; + +export type DhedgeStakingV2ContractPositionDefinition = { + address: string; + stakingTokenAddress: string; +}; + +export abstract class DhedgeV2StakingContractPositionFetcher extends CustomContractPositionTemplatePositionFetcher< + DhedgeV2Staking, + DefaultDataProps, + DhedgeStakingV2ContractPositionDefinition +> { + abstract stakingV2ContractAddress: string; + + constructor( + @Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit, + @Inject(DhedgeV2ViemContractFactory) protected readonly contractFactory: DhedgeV2ViemContractFactory, + ) { + super(appToolkit); + } + + getContract(address: string) { + return this.contractFactory.dhedgeV2Staking({ network: this.network, address }); + } + + async getDefinitions({ multicall }: GetDefinitionsParams): Promise { + const stakingV2Contract = this.contractFactory.dhedgeV2Staking({ + address: this.stakingV2ContractAddress, + network: this.network, + }); + const numStakingPosition = await multicall.wrap(stakingV2Contract).read.numberOfPoolsConfigured(); + const stakingTokenAddresses = await Promise.all( + range(Number(numStakingPosition)).map(async n => { + const suppliedTokenAddressRaw = await multicall.wrap(stakingV2Contract).read.poolConfiguredByIndex([BigInt(n)]); + return suppliedTokenAddressRaw.toLowerCase(); + }), + ); + + return stakingTokenAddresses.map(stakingTokenAddress => { + return { + address: this.stakingV2ContractAddress, + stakingTokenAddress, + }; + }); + } + + async getTokenDefinitions({ + contract, + definition, + }: GetTokenDefinitionsParams) { + const dhtTokenAddress = await contract.read.dhtAddress(); + return [ + { + metaType: MetaType.SUPPLIED, + address: dhtTokenAddress, + network: this.network, + }, + { + metaType: MetaType.SUPPLIED, + address: definition.stakingTokenAddress, + network: this.network, + }, + { + metaType: MetaType.CLAIMABLE, + address: dhtTokenAddress, + network: this.network, + }, + ]; + } + + async getLabel({ contractPosition }: GetDisplayPropsParams): Promise { + return getLabelFromToken(contractPosition.tokens[1]); + } + + getTokenBalancesPerPosition(): never { + throw new NotImplementedException(); + } + + async getBalances(address: string): Promise[]> { + const multicall = this.appToolkit.getViemMulticall(this.network); + const stakingV2Contract = this.contractFactory.dhedgeV2Staking({ + address: this.stakingV2ContractAddress, + network: this.network, + }); + + const contractPositions = await this.appToolkit.getAppContractPositions({ + appId: this.appId, + network: this.network, + groupIds: [this.groupId], + }); + + const numPositionsRaw = await multicall.wrap(stakingV2Contract).read.balanceOf([address]); + + const balances = await Promise.all( + range(0, Number(numPositionsRaw)).map(async index => { + const tokenId = await multicall.wrap(stakingV2Contract).read.tokenOfOwnerByIndex([address, BigInt(index)]); + + const [suppliedBalances, claimableAmountRaw] = await Promise.all([ + multicall.wrap(stakingV2Contract).read.stakes([tokenId]), + multicall.wrap(stakingV2Contract).read.currentRewardsForStake([tokenId]), + ]); + const lpTokenAddress = suppliedBalances[2]; + const matchingPosition = contractPositions.find(x => + x.tokens.find(x => x.address == lpTokenAddress.toLowerCase()), + ); + if (!matchingPosition) return null; + + const suppliedDht = suppliedBalances[0]; + const suppliedLp = suppliedBalances[3]; + + const depositDhtAmount = drillBalance(matchingPosition.tokens[0], suppliedDht.toString()); + const depositLpAmount = drillBalance(matchingPosition.tokens[1], suppliedLp.toString()); + const claimableBalance = drillBalance(matchingPosition.tokens[2], claimableAmountRaw.toString()); + + return { + ...matchingPosition, + tokens: [depositDhtAmount, depositLpAmount, claimableBalance], + balanceUSD: depositDhtAmount.balanceUSD + depositLpAmount.balanceUSD + claimableBalance.balanceUSD, + }; + }), + ); + + return _.compact(balances); + } +} diff --git a/src/apps/dhedge-v2/contracts/abis/dhedge-v-2-staking.json b/src/apps/dhedge-v2/contracts/abis/dhedge-v-2-staking.json new file mode 100644 index 000000000..2925b60ca --- /dev/null +++ b/src/apps/dhedge-v2/contracts/abis/dhedge-v-2-staking.json @@ -0,0 +1,718 @@ +[ + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "dhtAmount", "type": "uint256" } + ], + "name": "AddDHTToStake", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "approved", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "owner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "operator", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "ApprovalForAll", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "claimAmount", "type": "uint256" } + ], + "name": "Claim", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "dhtAmount", "type": "uint256" } + ], + "name": "NewStake", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "string", "name": "operation", "type": "string" }], + "name": "OwnerOperation", + "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": "address", "name": "account", "type": "address" }], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "address", "name": "dhedgePoolAddress", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "poolTokenAmount", "type": "uint256" } + ], + "name": "StakePoolTokens", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": true, "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "address", "name": "account", "type": "address" }], + "name": "Unpaused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "UnstakeDHT", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "newTokedId", "type": "uint256" } + ], + "name": "UnstakePoolTokens", + "type": "event" + }, + { + "inputs": [], + "name": "POOL_TOKEN_UNIT", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "UNIT", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint256", "name": "dhtAmount", "type": "uint256" } + ], + "name": "addDhtToStake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "aggregateStakeStartTime", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "owner", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "baseURI", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "vDHTAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "poolTokensStaked", "type": "uint256" }, + { "internalType": "uint256", "name": "tokenPriceStart", "type": "uint256" }, + { "internalType": "uint256", "name": "tokenPriceFinish", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeStartTime", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeFinishTime", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeEmissionsRate", "type": "uint256" }, + { + "components": [ + { "internalType": "uint256", "name": "stakeDurationDelaySeconds", "type": "uint256" }, + { "internalType": "uint256", "name": "maxDurationBoostSeconds", "type": "uint256" }, + { "internalType": "uint256", "name": "maxPerformanceBoostNumerator", "type": "uint256" }, + { "internalType": "uint256", "name": "maxPerformanceBoostDenominator", "type": "uint256" }, + { "internalType": "uint256", "name": "stakingRatio", "type": "uint256" }, + { "internalType": "uint256", "name": "emissionsRate", "type": "uint256" }, + { "internalType": "uint256", "name": "emissionsRateDenominator", "type": "uint256" } + ], + "internalType": "struct IDhedgeStakingV2Storage.RewardParams", + "name": "rewardParams", + "type": "tuple" + } + ], + "name": "calculateDhtRewardAmount", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "vDHTAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "totalValue", "type": "uint256" }, + { "internalType": "uint256", "name": "stakingRatio", "type": "uint256" } + ], + "name": "calculateMaxVDHTAllowed", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenPriceStart", "type": "uint256" }, + { "internalType": "uint256", "name": "tokenPriceFinish", "type": "uint256" }, + { "internalType": "uint256", "name": "maxPerformanceBoostNumerator", "type": "uint256" }, + { "internalType": "uint256", "name": "maxPerformanceBoostDenominator", "type": "uint256" } + ], + "name": "calculatePerformanceFactor", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "stakeStartTime", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeFinishTime", "type": "uint256" }, + { "internalType": "uint256", "name": "maxDurationBoostSeconds", "type": "uint256" } + ], + "name": "calculateStakeDurationFactor", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "stakeStartTime", "type": "uint256" }, + { "internalType": "uint256", "name": "dhtAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeFinishTime", "type": "uint256" }, + { "internalType": "uint256", "name": "maxVDurationTime", "type": "uint256" } + ], + "name": "calculateVDHT", + "outputs": [{ "internalType": "uint256", "name": "vDHT", "type": "uint256" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "canClaimAmount", + "outputs": [{ "internalType": "uint256", "name": "claimAmount", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "claimAmount", "type": "uint256" }], + "name": "checkEnoughDht", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "claim", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "uint256", "name": "cap", "type": "uint256" } + ], + "name": "configurePool", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "currentRewardsForStake", + "outputs": [{ "internalType": "uint256", "name": "rewardsDHT", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "dhtAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "staker", "type": "address" }], + "name": "dhtBalanceOf", + "outputs": [{ "internalType": "uint256", "name": "dht", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "dhtCap", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "dhtRewarded", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "dhtStaked", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "getApproved", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "dhedgePoolAddress", "type": "address" }], + "name": "getPoolConfiguration", + "outputs": [ + { + "components": [ + { "internalType": "bool", "name": "configured", "type": "bool" }, + { "internalType": "uint256", "name": "stakeCap", "type": "uint256" }, + { "internalType": "uint256", "name": "stakedSoFar", "type": "uint256" } + ], + "internalType": "struct IDhedgeStakingV2Storage.PoolConfiguration", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "getStake", + "outputs": [ + { + "components": [ + { "internalType": "uint256", "name": "dhtAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "dhtStakeStartTime", "type": "uint256" }, + { "internalType": "address", "name": "dhedgePoolAddress", "type": "address" }, + { "internalType": "uint256", "name": "dhedgePoolAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "dhedgePoolStakeStartTime", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeStartTokenPrice", "type": "uint256" }, + { "internalType": "bool", "name": "unstaked", "type": "bool" }, + { "internalType": "uint256", "name": "unstakeTime", "type": "uint256" }, + { "internalType": "uint256", "name": "reward", "type": "uint256" }, + { "internalType": "uint256", "name": "claimedReward", "type": "uint256" }, + { "internalType": "uint256", "name": "rewardParamsEmissionsRate", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeFinishTokenPrice", "type": "uint256" }, + { "internalType": "uint256", "name": "vdhtAccruedAtUnstake", "type": "uint256" }, + { "internalType": "uint256", "name": "dhedgePoolRemainingExitCooldownAtStakeTime", "type": "uint256" } + ], + "internalType": "struct IDhedgeStakingV2Storage.Stake", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "globalVDHT", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "implInitializer", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [{ "internalType": "address", "name": "_dhtAddress", "type": "address" }], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "operator", "type": "address" } + ], + "name": "isApprovedForAll", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxStakingValue", + "outputs": [{ "internalType": "uint256", "name": "maximumStakingValue", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxVDurationTimeSeconds", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "dhtAmount", "type": "uint256" }], + "name": "newStake", + "outputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "numberOfPoolsConfigured", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "ownerOf", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "poolConfiguredByIndex", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "rewardParams", + "outputs": [ + { "internalType": "uint256", "name": "stakeDurationDelaySeconds", "type": "uint256" }, + { "internalType": "uint256", "name": "maxDurationBoostSeconds", "type": "uint256" }, + { "internalType": "uint256", "name": "maxPerformanceBoostNumerator", "type": "uint256" }, + { "internalType": "uint256", "name": "maxPerformanceBoostDenominator", "type": "uint256" }, + { "internalType": "uint256", "name": "stakingRatio", "type": "uint256" }, + { "internalType": "uint256", "name": "emissionsRate", "type": "uint256" }, + { "internalType": "uint256", "name": "emissionsRateDenominator", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardStreamingTime", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "bytes", "name": "_data", "type": "bytes" } + ], + "name": "safeTransferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "operator", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "setApprovalForAll", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newDHTCap", "type": "uint256" }], + "name": "setDHTCap", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newEmissionsRate", "type": "uint256" }], + "name": "setEmissionsRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newMaxDurationBoostSeconds", "type": "uint256" }], + "name": "setMaxDurationBoostSeconds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newMaxPerformanceBoostNumerator", "type": "uint256" }], + "name": "setMaxPerformanceBoostNumerator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newMaxVDurationTimeSeconds", "type": "uint256" }], + "name": "setMaxVDurationTimeSeconds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newRewardStreamingTime", "type": "uint256" }], + "name": "setRewardStreamingTime", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newStakeDurationDelaySeconds", "type": "uint256" }], + "name": "setStakeDurationDelaySeconds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "newStakingRatio", "type": "uint256" }], + "name": "setStakingRatio", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IDhedgeStakingV2NFTJson", "name": "newTokenUriGenerator", "type": "address" } + ], + "name": "setTokenUriGenerator", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "address", "name": "dhedgePoolAddress", "type": "address" }, + { "internalType": "uint256", "name": "dhedgePoolAmount", "type": "uint256" } + ], + "name": "stakePoolTokens", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "name": "stakes", + "outputs": [ + { "internalType": "uint256", "name": "dhtAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "dhtStakeStartTime", "type": "uint256" }, + { "internalType": "address", "name": "dhedgePoolAddress", "type": "address" }, + { "internalType": "uint256", "name": "dhedgePoolAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "dhedgePoolStakeStartTime", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeStartTokenPrice", "type": "uint256" }, + { "internalType": "bool", "name": "unstaked", "type": "bool" }, + { "internalType": "uint256", "name": "unstakeTime", "type": "uint256" }, + { "internalType": "uint256", "name": "reward", "type": "uint256" }, + { "internalType": "uint256", "name": "claimedReward", "type": "uint256" }, + { "internalType": "uint256", "name": "rewardParamsEmissionsRate", "type": "uint256" }, + { "internalType": "uint256", "name": "stakeFinishTokenPrice", "type": "uint256" }, + { "internalType": "uint256", "name": "vdhtAccruedAtUnstake", "type": "uint256" }, + { "internalType": "uint256", "name": "dhedgePoolRemainingExitCooldownAtStakeTime", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }], + "name": "supportsInterface", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "index", "type": "uint256" }], + "name": "tokenByIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "uint256", "name": "index", "type": "uint256" } + ], + "name": "tokenOfOwnerByIndex", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "tokenURI", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "tokenUriGenerator", + "outputs": [{ "internalType": "contract IDhedgeStakingV2NFTJson", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalStakingValue", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "tokenId", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "tokenId", "type": "uint256" }, + { "internalType": "uint256", "name": "dhtAmount", "type": "uint256" } + ], + "name": "unstakeDHT", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "unstakePoolTokens", + "outputs": [{ "internalType": "uint256", "name": "newTokenId", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "staker", "type": "address" }], + "name": "vDHTBalanceOf", + "outputs": [{ "internalType": "uint256", "name": "vDHT", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }], + "name": "vDHTBalanceOfStake", + "outputs": [{ "internalType": "uint256", "name": "vDHT", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/apps/dhedge-v2/contracts/viem.contract-factory.ts b/src/apps/dhedge-v2/contracts/viem.contract-factory.ts index 3f4be203a..6b9f94578 100644 --- a/src/apps/dhedge-v2/contracts/viem.contract-factory.ts +++ b/src/apps/dhedge-v2/contracts/viem.contract-factory.ts @@ -3,7 +3,7 @@ import { Injectable, Inject } from '@nestjs/common'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; import { Network } from '~types/network.interface'; -import { DhedgeV2Factory__factory, DhedgeV2Token__factory } from './viem'; +import { DhedgeV2Factory__factory, DhedgeV2Staking__factory, DhedgeV2Token__factory } from './viem'; type ContractOpts = { address: string; network: Network }; @@ -14,6 +14,9 @@ export class DhedgeV2ViemContractFactory { dhedgeV2Factory({ address, network }: ContractOpts) { return DhedgeV2Factory__factory.connect(address, this.appToolkit.getViemNetworkProvider(network)); } + dhedgeV2Staking({ address, network }: ContractOpts) { + return DhedgeV2Staking__factory.connect(address, this.appToolkit.getViemNetworkProvider(network)); + } dhedgeV2Token({ address, network }: ContractOpts) { return DhedgeV2Token__factory.connect(address, this.appToolkit.getViemNetworkProvider(network)); } diff --git a/src/apps/dhedge-v2/contracts/viem/DhedgeV2Staking.ts b/src/apps/dhedge-v2/contracts/viem/DhedgeV2Staking.ts new file mode 100644 index 000000000..84b38bffa --- /dev/null +++ b/src/apps/dhedge-v2/contracts/viem/DhedgeV2Staking.ts @@ -0,0 +1,1678 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { getContract, GetContractReturnType, PublicClient } from 'viem'; + +export const dhedgeV2StakingAbi = [ + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + ], + name: 'AddDHTToStake', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'approved', + type: 'address', + }, + { + indexed: true, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'Approval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'ApprovalForAll', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'claimAmount', + type: 'uint256', + }, + ], + name: 'Claim', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + ], + name: 'NewStake', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'string', + name: 'operation', + type: 'string', + }, + ], + name: 'OwnerOperation', + 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: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'Paused', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'address', + name: 'dhedgePoolAddress', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'poolTokenAmount', + type: 'uint256', + }, + ], + name: 'StakePoolTokens', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: true, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'Transfer', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'address', + name: 'account', + type: 'address', + }, + ], + name: 'Unpaused', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'UnstakeDHT', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'newTokedId', + type: 'uint256', + }, + ], + name: 'UnstakePoolTokens', + type: 'event', + }, + { + inputs: [], + name: 'POOL_TOKEN_UNIT', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'UNIT', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + ], + name: 'addDhtToStake', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'aggregateStakeStartTime', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'approve', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'baseURI', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'vDHTAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'poolTokensStaked', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'tokenPriceStart', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'tokenPriceFinish', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeStartTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeFinishTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeEmissionsRate', + type: 'uint256', + }, + { + components: [ + { + internalType: 'uint256', + name: 'stakeDurationDelaySeconds', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxDurationBoostSeconds', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxPerformanceBoostNumerator', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxPerformanceBoostDenominator', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakingRatio', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'emissionsRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'emissionsRateDenominator', + type: 'uint256', + }, + ], + internalType: 'struct IDhedgeStakingV2Storage.RewardParams', + name: 'rewardParams', + type: 'tuple', + }, + ], + name: 'calculateDhtRewardAmount', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'vDHTAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'totalValue', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakingRatio', + type: 'uint256', + }, + ], + name: 'calculateMaxVDHTAllowed', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenPriceStart', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'tokenPriceFinish', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxPerformanceBoostNumerator', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxPerformanceBoostDenominator', + type: 'uint256', + }, + ], + name: 'calculatePerformanceFactor', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'stakeStartTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeFinishTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxDurationBoostSeconds', + type: 'uint256', + }, + ], + name: 'calculateStakeDurationFactor', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'stakeStartTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeFinishTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxVDurationTime', + type: 'uint256', + }, + ], + name: 'calculateVDHT', + outputs: [ + { + internalType: 'uint256', + name: 'vDHT', + type: 'uint256', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'canClaimAmount', + outputs: [ + { + internalType: 'uint256', + name: 'claimAmount', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'claimAmount', + type: 'uint256', + }, + ], + name: 'checkEnoughDht', + outputs: [], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'claim', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'pool', + type: 'address', + }, + { + internalType: 'uint256', + name: 'cap', + type: 'uint256', + }, + ], + name: 'configurePool', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'currentRewardsForStake', + outputs: [ + { + internalType: 'uint256', + name: 'rewardsDHT', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'dhtAddress', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'staker', + type: 'address', + }, + ], + name: 'dhtBalanceOf', + outputs: [ + { + internalType: 'uint256', + name: 'dht', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'dhtCap', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'dhtRewarded', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'dhtStaked', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'getApproved', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'dhedgePoolAddress', + type: 'address', + }, + ], + name: 'getPoolConfiguration', + outputs: [ + { + components: [ + { + internalType: 'bool', + name: 'configured', + type: 'bool', + }, + { + internalType: 'uint256', + name: 'stakeCap', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakedSoFar', + type: 'uint256', + }, + ], + internalType: 'struct IDhedgeStakingV2Storage.PoolConfiguration', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'getStake', + outputs: [ + { + components: [ + { + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhtStakeStartTime', + type: 'uint256', + }, + { + internalType: 'address', + name: 'dhedgePoolAddress', + type: 'address', + }, + { + internalType: 'uint256', + name: 'dhedgePoolAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhedgePoolStakeStartTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeStartTokenPrice', + type: 'uint256', + }, + { + internalType: 'bool', + name: 'unstaked', + type: 'bool', + }, + { + internalType: 'uint256', + name: 'unstakeTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'reward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'claimedReward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'rewardParamsEmissionsRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeFinishTokenPrice', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'vdhtAccruedAtUnstake', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhedgePoolRemainingExitCooldownAtStakeTime', + type: 'uint256', + }, + ], + internalType: 'struct IDhedgeStakingV2Storage.Stake', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'globalVDHT', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'implInitializer', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_dhtAddress', + type: 'address', + }, + ], + name: 'initialize', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + ], + name: 'isApprovedForAll', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'maxStakingValue', + outputs: [ + { + internalType: 'uint256', + name: 'maximumStakingValue', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'maxVDurationTimeSeconds', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'name', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + ], + name: 'newStake', + outputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'numberOfPoolsConfigured', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'ownerOf', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'paused', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + name: 'poolConfiguredByIndex', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'rewardParams', + outputs: [ + { + internalType: 'uint256', + name: 'stakeDurationDelaySeconds', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxDurationBoostSeconds', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxPerformanceBoostNumerator', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxPerformanceBoostDenominator', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakingRatio', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'emissionsRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'emissionsRateDenominator', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'rewardStreamingTime', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'safeTransferFrom', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + internalType: 'bytes', + name: '_data', + type: 'bytes', + }, + ], + name: 'safeTransferFrom', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'operator', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'setApprovalForAll', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newDHTCap', + type: 'uint256', + }, + ], + name: 'setDHTCap', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newEmissionsRate', + type: 'uint256', + }, + ], + name: 'setEmissionsRate', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newMaxDurationBoostSeconds', + type: 'uint256', + }, + ], + name: 'setMaxDurationBoostSeconds', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newMaxPerformanceBoostNumerator', + type: 'uint256', + }, + ], + name: 'setMaxPerformanceBoostNumerator', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newMaxVDurationTimeSeconds', + type: 'uint256', + }, + ], + name: 'setMaxVDurationTimeSeconds', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newRewardStreamingTime', + type: 'uint256', + }, + ], + name: 'setRewardStreamingTime', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newStakeDurationDelaySeconds', + type: 'uint256', + }, + ], + name: 'setStakeDurationDelaySeconds', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'newStakingRatio', + type: 'uint256', + }, + ], + name: 'setStakingRatio', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IDhedgeStakingV2NFTJson', + name: 'newTokenUriGenerator', + type: 'address', + }, + ], + name: 'setTokenUriGenerator', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + internalType: 'address', + name: 'dhedgePoolAddress', + type: 'address', + }, + { + internalType: 'uint256', + name: 'dhedgePoolAmount', + type: 'uint256', + }, + ], + name: 'stakePoolTokens', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + name: 'stakes', + outputs: [ + { + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhtStakeStartTime', + type: 'uint256', + }, + { + internalType: 'address', + name: 'dhedgePoolAddress', + type: 'address', + }, + { + internalType: 'uint256', + name: 'dhedgePoolAmount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhedgePoolStakeStartTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeStartTokenPrice', + type: 'uint256', + }, + { + internalType: 'bool', + name: 'unstaked', + type: 'bool', + }, + { + internalType: 'uint256', + name: 'unstakeTime', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'reward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'claimedReward', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'rewardParamsEmissionsRate', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'stakeFinishTokenPrice', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'vdhtAccruedAtUnstake', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhedgePoolRemainingExitCooldownAtStakeTime', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4', + }, + ], + name: 'supportsInterface', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'symbol', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'index', + type: 'uint256', + }, + ], + name: 'tokenByIndex', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'owner', + type: 'address', + }, + { + internalType: 'uint256', + name: 'index', + type: 'uint256', + }, + ], + name: 'tokenOfOwnerByIndex', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'tokenURI', + outputs: [ + { + internalType: 'string', + name: '', + type: 'string', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'tokenUriGenerator', + outputs: [ + { + internalType: 'contract IDhedgeStakingV2NFTJson', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalStakingValue', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'totalSupply', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'transferFrom', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'dhtAmount', + type: 'uint256', + }, + ], + name: 'unstakeDHT', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'unstakePoolTokens', + outputs: [ + { + internalType: 'uint256', + name: 'newTokenId', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'staker', + type: 'address', + }, + ], + name: 'vDHTBalanceOf', + outputs: [ + { + internalType: 'uint256', + name: 'vDHT', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'tokenId', + type: 'uint256', + }, + ], + name: 'vDHTBalanceOfStake', + outputs: [ + { + internalType: 'uint256', + name: 'vDHT', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, +] as const; + +export type DhedgeV2Staking = typeof dhedgeV2StakingAbi; +export type DhedgeV2StakingContract = GetContractReturnType; + +export class DhedgeV2Staking__factory { + static connect(address: string, client: PublicClient) { + return getContract({ address, abi: dhedgeV2StakingAbi, publicClient: client }); + } +} diff --git a/src/apps/dhedge-v2/contracts/viem/index.ts b/src/apps/dhedge-v2/contracts/viem/index.ts index eb1d3b9cd..747840135 100644 --- a/src/apps/dhedge-v2/contracts/viem/index.ts +++ b/src/apps/dhedge-v2/contracts/viem/index.ts @@ -3,7 +3,9 @@ /* eslint-disable */ export type { DhedgeV2Factory } from './DhedgeV2Factory'; +export type { DhedgeV2Staking } from './DhedgeV2Staking'; export type { DhedgeV2Token } from './DhedgeV2Token'; export { DhedgeV2Factory__factory } from './DhedgeV2Factory'; +export { DhedgeV2Staking__factory } from './DhedgeV2Staking'; export { DhedgeV2Token__factory } from './DhedgeV2Token'; diff --git a/src/apps/dhedge-v2/dhedge-v2.module.ts b/src/apps/dhedge-v2/dhedge-v2.module.ts index f81c9805c..d10511a15 100644 --- a/src/apps/dhedge-v2/dhedge-v2.module.ts +++ b/src/apps/dhedge-v2/dhedge-v2.module.ts @@ -4,9 +4,15 @@ import { AbstractApp } from '~app/app.dynamic-module'; import { DhedgeV2ViemContractFactory } from './contracts'; import { OptimismDhedgeV2PoolTokenFetcher } from './optimism/dhedge-v2.pool.token-fetcher'; +import { OptimismDhedgeV2StakingContractPositionFetcher } from './optimism/dhedge-v2.staking.contract-position-fetcher'; import { PolygonDhedgeV2PoolTokenFetcher } from './polygon/dhedge-v2.pool.token-fetcher'; @Module({ - providers: [DhedgeV2ViemContractFactory, OptimismDhedgeV2PoolTokenFetcher, PolygonDhedgeV2PoolTokenFetcher], + providers: [ + DhedgeV2ViemContractFactory, + OptimismDhedgeV2PoolTokenFetcher, + OptimismDhedgeV2StakingContractPositionFetcher, + PolygonDhedgeV2PoolTokenFetcher, + ], }) export class DhedgeV2AppModule extends AbstractApp() {} diff --git a/src/apps/dhedge-v2/optimism/dhedge-v2.staking.contract-position-fetcher.ts b/src/apps/dhedge-v2/optimism/dhedge-v2.staking.contract-position-fetcher.ts new file mode 100644 index 000000000..858ab3b34 --- /dev/null +++ b/src/apps/dhedge-v2/optimism/dhedge-v2.staking.contract-position-fetcher.ts @@ -0,0 +1,10 @@ +import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator'; + +import { DhedgeV2StakingContractPositionFetcher } from '../common/dhedge-v2.staking.contract-position-fetcher'; + +@PositionTemplate() +export class OptimismDhedgeV2StakingContractPositionFetcher extends DhedgeV2StakingContractPositionFetcher { + groupLabel = ' Staking'; + + stakingV2ContractAddress = '0xf165ca3d75120d817b7428eef8c39ea5cb33b612'; +}