-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 0xwalde <0xwalde@proton.me>
- Loading branch information
1 parent
41da332
commit 11d37fd
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |