Skip to content

Commit

Permalink
fix: fix superverse adapter
Browse files Browse the repository at this point in the history
Signed-off-by: Raymond Feng <[email protected]>
  • Loading branch information
raymondfeng committed Apr 25, 2024
1 parent d5724af commit b55e964
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 39 deletions.
40 changes: 10 additions & 30 deletions src/adapters/superverse-staking.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BigNumber> {
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',
},
];
Expand All @@ -63,13 +37,19 @@ export class SuperverseStakingPowerContractAdapter extends BaseStakingContractAd
* @param owner - Owner address
* @returns
*/
async getStakedTokenBalance(owner: string): Promise<BigNumber> {
async getStakedTokenBalance(
owner: string,
name = 'SuperVerse',
): Promise<BigNumber> {
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;
}
}
6 changes: 1 addition & 5 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -142,7 +139,6 @@ export class StakingContractsComponent implements Component {
DwebUniV2EthereumStakingContractAdapter,
DwebUniV2PolygonStakingContractAdapter,
SuperverseStakingContractAdapter,
SuperverseStakingPowerContractAdapter,
StartStakingContractAdapter,
BlastminersStakingContractAdapter,
RailgunBinanceGovernanceAdapter,
Expand Down
11 changes: 7 additions & 4 deletions src/services/staking-contracts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

/**
Expand All @@ -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 =>
Expand Down

0 comments on commit b55e964

Please sign in to comment.