Skip to content

Commit

Permalink
Add Gen K staking contract adapter
Browse files Browse the repository at this point in the history
Signed-off-by: 0xwalde <0xwalde@proton.me>
  • Loading branch information
0xwalde authored and raymondfeng committed Aug 31, 2023
1 parent 41da332 commit 11d37fd
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/adapters/genk-staking.adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {BindingScope, extensionFor, injectable} from '@loopback/core';
import {BigNumber} from 'ethers';
import {STAKING_ADAPTERS_EXTENSION_POINT} from '../keys';
import {BaseStakingContractAdapter, StakingAsset} from '../staking';
import {GenkStaking__factory} from '../types/factories/GenkStaking__factory';

@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 GenKStakingContractAdapter extends BaseStakingContractAdapter {
contractAddress = '0x027FC636E944A7a28D58E2d80e5241df546fD9a7';
chainId = 137;
supportedAssets: StakingAsset[] = [
{
asset: 'ERC721:0xf8b06f92f147adf01da319304a9d18a2b1b8c9e8',
},
];

/**
* Get staked token ids for the given owner
* @param owner - Owner address
* @returns
*/
async getStakedTokenIds(owner: string): Promise<BigNumber[]> {
const contract = GenkStaking__factory.connect(
this.contractAddress,
this.provider,
);
return contract.getStakedTokens(owner);
}

/**
* Get staked token balance for the given owner
* @param owner - Owner address
* @returns
*/
async getStakedTokenBalance(owner: string): Promise<BigNumber> {
const contract = GenkStaking__factory.connect(
this.contractAddress,
this.provider,
);
return BigNumber.from((await contract.getStakedTokens(owner))?.length ?? 0);
}
}
2 changes: 2 additions & 0 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {Meltdown03ContractAdapter} from './adapters/meltdown.adapter';
import {AngelBlockStakingContractAdapter} from './adapters/ab.adapter';
import {BapeliensStakingContractAdapter} from './adapters/bapeliens-staking.adapter';
import {CbzGrowStakingContractAdapter} from './adapters/cbzgrow.adapter';
import {GenKStakingContractAdapter} from './adapters/genk-staking.adapter';
import {MoonrunnersStakingContractAdapter} from './adapters/moonrunners.adapter';
import {MtgStakingContractAdapter} from './adapters/mtg.adapter';
import {OmniguardEternalsStakingContractAdapter} from './adapters/omniguard-eternals.adapter';
Expand Down Expand Up @@ -80,6 +81,7 @@ export class StakingContractsComponent implements Component {
ReNFTPolygonSylvesterV1StakingContractAdapter,
ReplicantXStakingContractAdapter,
CbzGrowStakingContractAdapter,
GenKStakingContractAdapter,
MeltdownContractAdapter,
AngelBlockStakingContractAdapter,
BapeliensStakingContractAdapter,
Expand Down
21 changes: 21 additions & 0 deletions src/contracts/genk-staking.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_user",
"type": "address"
}
],
"name": "getStakedTokens",
"outputs": [
{
"internalType": "uint256[]",
"name": "",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
}
]

0 comments on commit 11d37fd

Please sign in to comment.