Skip to content

Commit

Permalink
Add PlanetX Staking V1 (#234)
Browse files Browse the repository at this point in the history
* add PlanetX Staking V1

Signed-off-by: Dimitar Nikovski <[email protected]>

* add a signoff

Signed-off-by: Dimitar Nikovski <[email protected]>

* Sign off
:wq
Signed-off-by: D Nikovski \ <[email protected]>

Signed-off-by: Dimitar Nikovski <[email protected]>

* Commit with a signage

Signed-off-by: Dimitar Nikovski <[email protected]>
Signed-off-by: D Nikovski \ <[email protected]>
Signed-off-by: Dimitar Nikovski <[email protected]>

---------

Signed-off-by: Dimitar Nikovski <[email protected]>
Signed-off-by: D Nikovski \ <[email protected]>
  • Loading branch information
dimitar-nikovski authored Jul 30, 2024
1 parent bea80da commit 487e6a3
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/adapters/planetx.v1.adapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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 {PlanetxStakingV1} from '../types/PlanetxStakingV1.js';
import {PlanetxStakingV1__factory} from '../types/factories/PlanetxStakingV1__factory.js';

enum AssetNames {
X_DROIDS = 'X-Droids',
X_KEYS = 'X-Keys',
}

@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 PlanetXStakingV1ContractAdapter extends BaseStakingContractAdapter {
contractName = 'PlanetXStakingV1';
/**
* The contract address
*/
contractAddress = '0x8005e7626a079e07F16CC59c01e1Be6Cb54d1d24';

/**
* Assets that can be staked to this contract
*/
supportedAssets: StakingAsset[] = [
{
name: AssetNames.X_DROIDS,
asset: 'ERC721:0x72C916aA1d33aa2b9fCf7a7A146d22EFD22cdDE8',
},
{
asset: 'ERC721:0xbcbba981bff1e9530cbca0f40f67aa85f8944038',
name: AssetNames.X_KEYS,
},
];

private contract: PlanetxStakingV1;

constructor() {
super();
this.contract = PlanetxStakingV1__factory.connect(
this.contractAddress,
this.provider,
);
}

/**
* Get staked token ids for the given owner
* @param owner - Owner address
* @returns
*/
async getStakedTokenIds(
owner: string,
assetName?: string,
): Promise<BigNumber[]> {
assetName = assetName ?? AssetNames.X_DROIDS;

const tokenIds = await this.contract['getStakedTokens(address,address)'](
owner,
this.supportedAssets.find(a => a.name === assetName)!.asset.split(':')[1],
);

return tokenIds;
}

async getStakedTokenBalance(
owner: string,
assetName?: string,
): Promise<BigNumber> {
assetName = assetName ?? AssetNames.X_DROIDS;

const ids = await this.getStakedTokenIds(owner, assetName);

return BigNumber.from(ids.length);
}
}
4 changes: 3 additions & 1 deletion src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {JnglStakingContractAdapter} from './adapters/Jngl-staking.adapter.js';
import {MoonrunnersStakingContractAdapter} from './adapters/moonrunners.adapter.js';
import {MtgStakingContractAdapter} from './adapters/mtg.adapter.js';
import {OmniguardEternalsStakingContractAdapter} from './adapters/omniguard-eternals.adapter.js';
import {PlanetXStakingV1ContractAdapter} from './adapters/planetx.v1.adapter.js';
import {PlutoallianceStakingAdapter} from './adapters/plutoalliance.adapter.js';
import {PrimordiaStakingContractAdapter} from './adapters/primordia.adapter.js';
import {
Expand Down Expand Up @@ -145,7 +146,8 @@ export class StakingContractsComponent implements Component {
RailgunBinanceGovernanceAdapter,
RailgunEthereumGovernanceAdapter,
RailgunPolygonGovernanceAdapter,
PlanetXStakingV1ContractAdapter,
RevenueCoinStakingContractAdapter,
];
constructor() { }
constructor() {}
}
221 changes: 221 additions & 0 deletions src/contracts/planetx.staking.v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
[
{"inputs": [], "stateMutability": "nonpayable", "type": "constructor"},
{"inputs": [], "name": "NotTokenOwner", "type": "error"},
{
"inputs": [{"internalType": "address", "name": "owner", "type": "address"}],
"name": "OwnableInvalidOwner",
"type": "error"
},
{
"inputs": [
{"internalType": "address", "name": "account", "type": "address"}
],
"name": "OwnableUnauthorizedAccount",
"type": "error"
},
{"inputs": [], "name": "ReentrancyGuardReentrantCall", "type": "error"},
{"inputs": [], "name": "TokenAlreadyStaked", "type": "error"},
{"inputs": [], "name": "TokenNotStaked", "type": "error"},
{"inputs": [], "name": "UnsupportedStakingContract", "type": "error"},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "contractAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "tokenIds",
"type": "uint256[]"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
}
],
"name": "TokensStaked",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "contractAddress",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256[]",
"name": "tokenIds",
"type": "uint256[]"
},
{
"indexed": false,
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
}
],
"name": "TokensUnstaked",
"type": "event"
},
{
"inputs": [{"internalType": "address", "name": "user", "type": "address"}],
"name": "getStakedTokens",
"outputs": [
{"internalType": "address[]", "name": "contracts", "type": "address[]"},
{"internalType": "uint256[][]", "name": "tokenIds", "type": "uint256[][]"}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "user", "type": "address"},
{"internalType": "address", "name": "contractAddress", "type": "address"}
],
"name": "getStakedTokens",
"outputs": [
{"internalType": "uint256[]", "name": "tokenIds", "type": "uint256[]"}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "contractAddress", "type": "address"}
],
"name": "isContractSupported",
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "", "type": "address"},
{"internalType": "address", "name": "", "type": "address"},
{"internalType": "uint256", "name": "", "type": "uint256"},
{"internalType": "bytes", "name": "", "type": "bytes"}
],
"name": "onERC721Received",
"outputs": [{"internalType": "bytes4", "name": "", "type": "bytes4"}],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{"internalType": "address", "name": "", "type": "address"}],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "contractAddress", "type": "address"},
{"internalType": "bool", "name": "isSupported", "type": "bool"}
],
"name": "setSupportedContract",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "contractAddress", "type": "address"},
{"internalType": "uint256[]", "name": "tokenIds", "type": "uint256[]"}
],
"name": "stake",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "contractAddress", "type": "address"}
],
"name": "stakeCountsPerContract",
"outputs": [
{"internalType": "uint256", "name": "totalStaked", "type": "uint256"}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "newOwner", "type": "address"}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "contractAddress", "type": "address"},
{"internalType": "uint256[]", "name": "tokenIds", "type": "uint256[]"}
],
"name": "unstake",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{"internalType": "address", "name": "contractAddress", "type": "address"},
{"internalType": "uint256", "name": "tokenId", "type": "uint256"}
],
"name": "vaults",
"outputs": [
{"internalType": "address", "name": "owner", "type": "address"},
{"internalType": "uint64", "name": "stakedAt", "type": "uint64"}
],
"stateMutability": "view",
"type": "function"
}
]

0 comments on commit 487e6a3

Please sign in to comment.