diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..876b59e Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..3eaf746 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/Lingo-staking.json b/src/Lingo-staking.json new file mode 100644 index 0000000..3530aed --- /dev/null +++ b/src/Lingo-staking.json @@ -0,0 +1,367 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "_initialOwner", + "type": "address" + }, + { + "internalType": "contract ILingoToken", + "name": "_lingoToken", + "type": "address" + }, + { + "internalType": "uint256[]", + "name": "_lockDurations", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "InsufficientAmount", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidDuration", + "type": "error" + }, + { + "inputs": [], + "name": "MissingInternalRole", + "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": "StakeStillLocked", + "type": "error" + }, + { + "inputs": [], + "name": "UnauthorizedStakingOnBehalf", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256[]", + "name": "durations", + "type": "uint256[]" + } + ], + "name": "LockDurationsUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "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": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "duration", + "type": "uint256" + } + ], + "name": "Staked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "unlockBlock", + "type": "uint256" + } + ], + "name": "Unstaked", + "type": "event" + }, + { + "inputs": [], + "name": "LINGO_TOKEN", + "outputs": [ + { + "internalType": "contract ILingoToken", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "MIN_DEPOSIT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "getStakes", + "outputs": [ + { + "components": [ + { + "internalType": "uint128", + "name": "amount", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "unlockBlock", + "type": "uint128" + } + ], + "internalType": "struct TokenStaking.Position[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "lockDurations", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lockDurationsCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_durationIndex", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_expectedDuration", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "stake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_stakeIndex", + "type": "uint256" + } + ], + "name": "unstake", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "_durations", + "type": "uint256[]" + } + ], + "name": "updateLockDurations", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/adapters/lingo-staking.adapter.ts b/src/adapters/lingo-staking.adapter.ts new file mode 100644 index 0000000..add6b7a --- /dev/null +++ b/src/adapters/lingo-staking.adapter.ts @@ -0,0 +1,49 @@ +import {BindingScope, extensionFor, injectable} from '@loopback/core'; +import {BigNumber, ethers} 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 {LingoStaking__factory} from '../index.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 LingoStakingContractAdapter extends BaseStakingContractAdapter { + /** + * The contract address + */ + contractAddress = '0x9aF8C0dac726CcEE2BFd6c0f3E21f320d42398AC'; + + /** + * Assets that can be staked to this contract + */ + supportedAssets: StakingAsset[] = [ + { + asset: 'ERC20:0xfb42Da273158B0F642F59F2Ba7cc1d5457481677', + }, + ]; + + /** + * Get staked token ids for the given owner + * @param owner - Owner address + * @returns + */ + async getStakedTokenBalance(owner: string): Promise { + const contract = LingoStaking__factory.connect( + this.contractAddress, + this.provider, + ); + const positions = await contract.getStakes(owner); + + let total = ethers.BigNumber.from(0); + for (const pos of positions) { + total = total.add(pos.amount); + } + + return total; + } +} diff --git a/src/component.ts b/src/component.ts index 3dfcc23..f9e12c8 100644 --- a/src/component.ts +++ b/src/component.ts @@ -21,6 +21,7 @@ import { import {PerionCreditsStakingContractAdapter} from './adapters/erc20-staking.adapter.js'; import {IdolMarketplaceContractAdapter} from './adapters/idol-marketplace.adapter.js'; import {LifestoryPlanetStakingAdapter} from './adapters/lifestory-planet-staking.adapter.js'; +import {LingoStakingContractAdapter} from './adapters/lingo-staking.adapter.js'; import {LuckyNFTStakingContractAdapter} from './adapters/luckynft.adapter.js'; import {MeltdownContractAdapter} from './adapters/meltdown-1.adapter.js'; import {Meltdown03ContractAdapter} from './adapters/meltdown.adapter.js'; @@ -102,6 +103,7 @@ export class StakingContractsComponent implements Component { ChillRxStakingContractAdapter, CocoStakingContractAdapter, LuckyNFTStakingContractAdapter, + LingoStakingContractAdapter, MtgStakingContractAdapter, RirisuStakingContractAdapter, RoboStakingContractAdapter,