Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Coreum native staking #4704

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"hdkey": "1.1.1",
"inherits": "2.0.4",
"long": "4.0.0",
"msw": "1.3.2",
"process-nextick-args": "2.0.0",
"randombytes": "2.1.0",
"regenerator-runtime": "0.13.2",
Expand Down Expand Up @@ -220,6 +221,7 @@
"@babel/runtime": "^7.20.0",
"@bugsnag/source-maps": "^2.3.1",
"@rollup/plugin-babel": "^6.0.3",
"@stakekit/api-hooks": "^0.0.52",
"@sucrase/webpack-loader": "^2.0.0",
"@tsconfig/react-native": "^2.0.2",
"@typechain/ethers-v5": "^11.1.2",
Expand Down
6 changes: 4 additions & 2 deletions src/components/scenes/Staking/StakeOverviewScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const StakeOverviewSceneComponent = (props: Props) => {
// Hooks
const [stakeAllocations, setStakeAllocations] = React.useState<PositionAllocation[]>([])
const [rewardAllocations, setRewardAllocations] = React.useState<PositionAllocation[]>([])
const [unstakedAllocations, setUnstakedAllocations] = React.useState<PositionAllocation[]>([])
const [stakePosition, setStakePosition] = React.useState<StakePosition | undefined>(startingStakePosition)

// Background loop to force fetchStakePosition updates
Expand All @@ -80,6 +81,7 @@ const StakeOverviewSceneComponent = (props: Props) => {
const guiAllocations = getPositionAllocations(stakePosition)
setStakeAllocations(guiAllocations.staked)
setRewardAllocations(guiAllocations.earned)
setUnstakedAllocations(guiAllocations.unstaked)
setStakePosition(stakePosition)
}
} catch (err) {
Expand Down Expand Up @@ -121,7 +123,7 @@ const StakeOverviewSceneComponent = (props: Props) => {
// Renderers
const renderCFAT = ({ item }: { item: PositionAllocation }) => {
const { allocationType, currencyCode, nativeAmount } = item
const titleBase = allocationType === 'staked' ? lstrings.stake_s_staked : lstrings.stake_s_earned
const titleBase = allocationType === 'staked' ? lstrings.stake_s_staked : allocationType === 'earned' ? lstrings.stake_s_earned : lstrings.stake_s_unstaked
const title = `${sprintf(titleBase, currencyCode)} ${getAllocationLocktimeMessage(item)}`
const denomination = displayDenomMap[currencyCode]

Expand Down Expand Up @@ -162,7 +164,7 @@ const StakeOverviewSceneComponent = (props: Props) => {
</>
) : null}
<FlatList
data={[...stakeAllocations, ...rewardAllocations]}
data={[...stakeAllocations, ...rewardAllocations, ...unstakedAllocations]}
renderItem={renderCFAT}
keyExtractor={(allocation: PositionAllocation) =>
`${allocation.allocationType}${allocation.currencyCode}${allocation.nativeAmount}${getAllocationLocktimeMessage(allocation)}`
Expand Down
1 change: 1 addition & 0 deletions src/constants/WalletAndCurrencyConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export const SPECIAL_CURRENCY_INFO: {
initWalletName: lstrings.string_first_coreum_wallet_name,
chainCode: 'CORE',
dummyPublicAddress: 'core18rv2a6cjkk3lnayy29hez6s2ftpe9llqnce2vu',
isStakingSupported: true,
isImportKeySupported: true
},
osmosis: {
Expand Down
1 change: 1 addition & 0 deletions src/envConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const asEnvConfig = asObject({
})
),
AZTECO_API_KEY: asNullable(asString),
STAKEKIT_API_KEY: asNullable(asString),

// Core plugin options:
AVALANCHE_INIT: asCorePluginInit(asEvmApiKeys),
Expand Down
1 change: 1 addition & 0 deletions src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,7 @@ const strings = {
stake_estimated_return: 'Estimated Return: %s',
stake_s_staked: '%s Staked',
stake_s_earned: '%s Earned',
stake_s_unstaked: '%s Unstaked',
stake_lock_message: 'locked until %s',
stake_select_options: 'Select staking options:',
stake_stake_more_funds: 'Stake More Funds',
Expand Down
1 change: 1 addition & 0 deletions src/locales/strings/enUS.json
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@
"stake_estimated_return": "Estimated Return: %s",
"stake_s_staked": "%s Staked",
"stake_s_earned": "%s Earned",
"stake_s_unstaked": "%s Unstaked",
"stake_lock_message": "locked until %s",
"stake_select_options": "Select staking options:",
"stake_stake_more_funds": "Stake More Funds",
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/stake-plugins/generic/GenericStakePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChangeQuote, ChangeQuoteRequest, StakePlugin, StakePluginFactory, StakePolicy, StakePolicyFilter, StakePosition, StakePositionRequest } from '../types'
import { CoreumNativeSkateKitAdapterConfig, makeSkateKitAdapter } from './policyAdapters/CoreumStakeKitAdaptor'
import { GlifInfinityPoolAdapterConfig, makeGlifInfinityPoolAdapter } from './policyAdapters/GlifInfinityPoolAdapter'
import { makeTarotPoolAdapter, TarotPoolAdapterConfig } from './policyAdapters/TarotPoolAdaptor'
import { StakeAdapterConfig, StakePolicyAdapter } from './policyAdapters/types'
Expand Down Expand Up @@ -73,12 +74,17 @@ function isPolicyInfoForGlifInfinityPool(policyInfo: StakePolicyConfig<StakeAdap
function isPolicyInfoForTarotPool(policyInfo: StakePolicyConfig<StakeAdapterConfig>): policyInfo is StakePolicyConfig<TarotPoolAdapterConfig> {
return policyInfo.adapterConfig.type === 'tarot-velodrome-pool'
}
function isPolicyInfoForCoreumStakeKit(policyInfo: StakePolicyConfig<StakeAdapterConfig>): policyInfo is StakePolicyConfig<CoreumNativeSkateKitAdapterConfig> {
return policyInfo.adapterConfig.type === 'coreum-native-stake-kit'
}

const makePolicyAdapter = (policyInfo: StakePolicyConfig<StakeAdapterConfig>): StakePolicyAdapter => {
if (isPolicyInfoForGlifInfinityPool(policyInfo)) {
return makeGlifInfinityPoolAdapter(policyInfo)
} else if (isPolicyInfoForTarotPool(policyInfo)) {
return makeTarotPoolAdapter(policyInfo)
} else if (isPolicyInfoForCoreumStakeKit(policyInfo)) {
return makeSkateKitAdapter(policyInfo)
} else {
throw new Error('Unknown policyInfo')
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/stake-plugins/generic/pluginInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { coreumnative } from './pluginInfo/coreumNativeStaking'
import { glifpoolCalibration } from './pluginInfo/filecoinCalibrationGlifpool'
import { glifpool } from './pluginInfo/filecoinGlifpool'
import { tarotpool } from './pluginInfo/optimismTarotPool'

export const genericPlugins = [glifpool, glifpoolCalibration, tarotpool]
export const genericPlugins = [glifpool, glifpoolCalibration, tarotpool, coreumnative]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { StakeProviderInfo } from '../../types'
import { StakePluginInfo, StakePolicyConfig } from '../types'

interface CoreumNativeSkateKitAdapterConfig {
type: string
integrationId: string
preferredValidatorAddress: string
preferredValidatorName: string
}

const stakeProviderInfo: StakeProviderInfo = {
displayName: 'Coreum Native Staking',
pluginId: 'coreum',
stakeProviderId: 'coreum_native'
}

const commonAdaptorConfig = {
type: 'coreum-native-stake-kit',
integrationId: 'coreum-core-native-staking'
}

const adaptors: CoreumNativeSkateKitAdapterConfig[] = [
{
...commonAdaptorConfig,
preferredValidatorAddress: 'corevaloper1k0rllvenwr02gvm52fh5056g5m3hly2lpf63z5', // StakeLab
preferredValidatorName: 'StakeLab'
},

{
...commonAdaptorConfig,
preferredValidatorAddress: 'corevaloper1puge9crcxvq02jguql4vp2dhglvjll3wzdcggq', // Bware Labs
preferredValidatorName: 'Bware Labs'
}
]

const makePolicyConfig = (adapterConfig: CoreumNativeSkateKitAdapterConfig) => {
return {
stakePolicyId: `coreum_native_${adapterConfig.preferredValidatorAddress}`,
stakeProviderInfo: { ...stakeProviderInfo, displayName: `Coreum Native Staking - ${adapterConfig.preferredValidatorName}` },
parentPluginId: 'coreum',
parentCurrencyCode: 'COREUM',
hideUnstakeAction: true,
adapterConfig,
stakeAssets: [{ pluginId: 'coreum', currencyCode: 'COREUM' }],
rewardAssets: [{ pluginId: 'coreum', currencyCode: 'COREUM' }]
}
}

const coreumPolicyConfig: Array<StakePolicyConfig<any>> = adaptors.map(adaptor => makePolicyConfig(adaptor))

export const coreumnative: StakePluginInfo = {
pluginId: 'stake:coreum:native',
policyConfigs: [...coreumPolicyConfig]
}
Loading
Loading