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

Add Unizen staking contract #243

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
69 changes: 69 additions & 0 deletions src/adapters/unizen-staking.adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import {BindingScope, extensionFor, injectable} from '@loopback/core';
import {BigNumber} from 'ethers';
import {STAKING_ADAPTERS_EXTENSION_POINT} from '../keys.js';
import {BaseStakingContractAdapter, StakingAsset} from '../staking.js';
// Use the full path to import instead of `../types`
import {UnizenStaking__factory} from '../types/factories/UnizenStaking__factory.js';

@injectable(
{
scope: BindingScope.SINGLETON, // Mark the adapter as a singleton
},
// Mark it as an extension to staking contracts service
extensionFor(STAKING_ADAPTERS_EXTENSION_POINT),
)

export class UnizenStakingContractAdapter extends BaseStakingContractAdapter {
/**
* The contract address
*/
contractAddress = '0x5655B12f1e74D1D1fc3F1048a89850a0149Aa5d4';

PZCX_ADDRESS = '0xdd75542611d57c4b6e68168b14c3591c539022ed'
/**
* The chain the assets exist on
*/
chainId: number = 137;

/**
* Assets that can be staked to this contract
*/
supportedAssets: StakingAsset[] = [
{
name: 'pZCX',
asset: `ERC20:${this.PZCX_ADDRESS}`,
},
];

/**
* Get staked token ids for the given owner
* @param owner - Owner address
* @returns
*/
async getStakedTokenIds(owner: string): Promise<BigNumber[]> {
const contract = UnizenStaking__factory.connect(
this.contractAddress,
this.provider,
);
try {
const userStakes = await contract.callStatic['getUsersStakedAmountOfToken'](owner, this.PZCX_ADDRESS);
return [userStakes]
} catch (error) {
return [BigNumber.from(0)]
}
}

async getStakedTokenBalance(owner: string, assetName: string): Promise<BigNumber> {
const contract = UnizenStaking__factory.connect(
this.contractAddress,
this.provider,
);
try {
const userStakes = await contract.callStatic['getUsersStakedAmountOfToken'](owner, this.PZCX_ADDRESS);
return userStakes
} catch (error) {
return BigNumber.from(0)
}
}
}

2 changes: 2 additions & 0 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {SuperverseStakingContractAdapter} from './adapters/superverse-staking.ad
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';
import {UnizenStakingContractAdapter} from './adapters/unizen-staking.adapter.js';
import {UwULendStakingContractAdapter} from './adapters/uwulend-staking.adapter.js';
import {WarriorsofankhStakingContractAdapter} from './adapters/warriorsofankh-staking.adapter.js';
import {XenoStakingContractAdapter} from './adapters/xeno-mining.adapter.js';
Expand Down Expand Up @@ -145,6 +146,7 @@ export class StakingContractsComponent implements Component {
RailgunBinanceGovernanceAdapter,
RailgunEthereumGovernanceAdapter,
RailgunPolygonGovernanceAdapter,
UnizenStakingContractAdapter,
RevenueCoinStakingContractAdapter,
];
constructor() { }
Expand Down
Loading