-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
bea80da
commit 487e6a3
Showing
3 changed files
with
305 additions
and
1 deletion.
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,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); | ||
} | ||
} |
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,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" | ||
} | ||
] |