From b55e964b3f516d66ed44a417b6afbdfb531bdff8 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 25 Apr 2024 15:57:50 -0700 Subject: [PATCH] fix: fix superverse adapter Signed-off-by: Raymond Feng --- src/adapters/superverse-staking.adapter.ts | 40 ++++++---------------- src/component.ts | 6 +--- src/services/staking-contracts.service.ts | 11 +++--- 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/src/adapters/superverse-staking.adapter.ts b/src/adapters/superverse-staking.adapter.ts index 1dc60ec..d838e66 100644 --- a/src/adapters/superverse-staking.adapter.ts +++ b/src/adapters/superverse-staking.adapter.ts @@ -23,37 +23,11 @@ export class SuperverseStakingContractAdapter extends BaseStakingContractAdapter */ supportedAssets: StakingAsset[] = [ { + name: 'SuperVerse', asset: 'ERC20:0xe53EC727dbDEB9E2d5456c3be40cFF031AB40A55', }, - ]; - - /** - * Get staked token ids for the given owner - * @param owner - Owner address - * @returns - */ - async getStakedTokenBalance(owner: string): Promise { - const contract = SuperverseStaking__factory.connect( - this.contractAddress, - this.provider, - ); - - const stakerInfo = await contract.stakerInfo(owner); - return stakerInfo.stakedTokens; - } -} - -export class SuperverseStakingPowerContractAdapter extends BaseStakingContractAdapter { - /** - * The contract address - */ - contractAddress = '0x8C96EdC82d111E3c5686F5ABE738A82d54d0b887'; - - /** - * Assets that can be staked to this contract: SuperVerse ERC20 - */ - supportedAssets: StakingAsset[] = [ { + name: 'SuperVersePower', asset: 'ERC20:0xe53EC727dbDEB9E2d5456c3be40cFF031AB40A55', }, ]; @@ -63,13 +37,19 @@ export class SuperverseStakingPowerContractAdapter extends BaseStakingContractAd * @param owner - Owner address * @returns */ - async getStakedTokenBalance(owner: string): Promise { + async getStakedTokenBalance( + owner: string, + name = 'SuperVerse', + ): Promise { + name = name.toLowerCase(); const contract = SuperverseStaking__factory.connect( this.contractAddress, this.provider, ); const stakerInfo = await contract.stakerInfo(owner); - return stakerInfo.stakerPower; + return name === 'superverse' + ? stakerInfo.stakedTokens + : stakerInfo.stakerPower; } } diff --git a/src/component.ts b/src/component.ts index e119a59..61976fb 100644 --- a/src/component.ts +++ b/src/component.ts @@ -69,10 +69,7 @@ import {SkyFarmStakingContractAdapter} from './adapters/sky-farm.adapter.js'; import {SpitYardContractAdapter} from './adapters/spit-yard.adapter.js'; import {StartStakingContractAdapter} from './adapters/start.adapter.js'; import {SugartownStakingContractAdapter} from './adapters/sugartown.adapter.js'; -import { - SuperverseStakingContractAdapter, - SuperverseStakingPowerContractAdapter, -} from './adapters/superverse-staking.adapter.js'; +import {SuperverseStakingContractAdapter} from './adapters/superverse-staking.adapter.js'; import {SupremeKong2StakingContractAdapter} from './adapters/supreme-kong-2-staking.adapter.js'; import {SupremeKongStakingContractAdapter} from './adapters/supreme-kong-staking.adapter.js'; import {TtooStakingContractAdapter} from './adapters/ttoo-staking.adapter.js'; @@ -142,7 +139,6 @@ export class StakingContractsComponent implements Component { DwebUniV2EthereumStakingContractAdapter, DwebUniV2PolygonStakingContractAdapter, SuperverseStakingContractAdapter, - SuperverseStakingPowerContractAdapter, StartStakingContractAdapter, BlastminersStakingContractAdapter, RailgunBinanceGovernanceAdapter, diff --git a/src/services/staking-contracts.service.ts b/src/services/staking-contracts.service.ts index f93e4d3..811a07b 100644 --- a/src/services/staking-contracts.service.ts +++ b/src/services/staking-contracts.service.ts @@ -77,10 +77,13 @@ export class StakingContractsService { utils.getAddress(a.contractAddress) === contractAddress, ); if (adapters.length === 0) return []; - const types = adapters[0].supportedAssets.map(a => - new AssetName(a.asset).namespace.toUpperCase(), + + const types = adapters.map(adapter => + adapter.supportedAssets.map(a => + new AssetName(a.asset).namespace.toUpperCase(), + ), ); - return Array.from(new Set(types)); + return Array.from(new Set(types.flat())); } /** @@ -96,7 +99,7 @@ export class StakingContractsService { }); } - private getAdapter(address: string, chainId = 1) { + private getAdapter(address: string, chainId = 1, name?: string) { address = utils.getAddress(address); const adapter = this.adapters.find( a =>