Skip to content

Commit

Permalink
Add Coreum native staking via StakeKit
Browse files Browse the repository at this point in the history
  • Loading branch information
peachbits committed Jan 22, 2024
1 parent dfcf672 commit 6755620
Show file tree
Hide file tree
Showing 10 changed files with 751 additions and 16 deletions.
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
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
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

0 comments on commit 6755620

Please sign in to comment.