Skip to content

Commit

Permalink
fixup! 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 0b42ef9 commit e4858c5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 59 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"@react-navigation/native": "^6.1.3",
"@react-navigation/stack": "^6.3.12",
"@shopify/flash-list": "^1.6.3",
"@stakekit/api-hooks": "^0.0.50",
"@stakekit/api-hooks": "^0.0.52",
"@walletconnect/react-native-compat": "^2.9.0",
"@walletconnect/types": "^2.9.0",
"@walletconnect/utils": "^2.9.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import type { ActionRequestDto, TransactionDto } from '@stakekit/api-hooks'
import { add, div, eq, floor, gt, mul, sub } from 'biggystring'
import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'

import { AssetId, ChangeQuote, PositionAllocation, QuoteAllocation, StakePosition } from '../../types'
import { StakePolicyConfig } from '../types'
import {
actionEnter,
actionExit,
actionPending,
ActionRequestDto,
APIManager,
transactionConstruct,
TransactionDto,
transactionSubmitHash,
yieldGetSingleYieldBalances,
yieldYieldOpportunity
} from '@stakekit/api-hooks'
import { add, div, eq, floor, gt, mul, sub } from 'biggystring'
import { EdgeCurrencyWallet, EdgeTransaction } from 'edge-core-js'

import { ENV } from '../../../../env'
} from '../util/stakeKitUtils'
import { convertNativeToExchange, DECIMAL_PRECISION } from '../../../../util/utils'
import { AssetId, ChangeQuote, PositionAllocation, QuoteAllocation, StakePosition } from '../../types'
import { StakePolicyConfig } from '../types'
import { StakePolicyAdapter } from './types'

export interface CoreumNativeSkateKitAdapterConfig {
Expand All @@ -25,12 +22,6 @@ export interface CoreumNativeSkateKitAdapterConfig {
preferredValidatorAddress: string
preferredValidatorName: string
}
if (ENV.STAKEKIT_API_KEY != null) {
APIManager.configure({
apiKey: ENV.STAKEKIT_API_KEY,
baseURL: 'https://api.stakek.it'
})
}

export const makeSkateKitAdapter = (policyConfig: StakePolicyConfig<CoreumNativeSkateKitAdapterConfig>): StakePolicyAdapter => {
if (policyConfig.stakeAssets.length > 1) throw new Error(`Staking more than one assets is not supported for CoreumSkateKitAdapter`)
Expand Down
65 changes: 65 additions & 0 deletions src/plugins/stake-plugins/generic/util/stakeKitUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type {
ActionDto,
ActionRequestDto,
ConstructTransactionRequestDto,
PendingActionRequestDto,
SubmitHashRequestDto,
TransactionDto,
YieldBalanceDto,
YieldBalanceRequestDto,
YieldDto
} from '@stakekit/api-hooks'

import { ENV } from '../../../../env'

const baseUrl = 'https://api.stakek.it'
const headers = { 'Content-Type': 'application/json', 'X-API-KEY': ENV.STAKEKIT_API_KEY ?? '' }

const fetchGet = async <Res>(path: string): Promise<Res> => {
const response = await fetch(baseUrl + path, {
headers
})
return await response.json()
}
const fetchPatch = async <Body, Res>(path: string, body: Body): Promise<Res> => {
const response = await fetch(baseUrl + path, {
method: 'PATCH',
headers,
body: JSON.stringify(body)
})
return await response.json()
}
const fetchPost = async <Body, Res>(path: string, body: Body): Promise<Res> => {
const response = await fetch(baseUrl + path, {
method: 'POST',
headers,
body: JSON.stringify(body)
})
return await response.json()
}

export const actionEnter = async (actionRequestDto: ActionRequestDto): Promise<ActionDto> => {
return await fetchPost<ActionRequestDto, ActionDto>('/v1/actions/enter', actionRequestDto)
}
export const actionExit = async (actionRequestDto: ActionRequestDto): Promise<ActionDto> => {
return await fetchPost<ActionRequestDto, ActionDto>('/v1/actions/exit', actionRequestDto)
}
export const actionPending = async (pendingActionRequestDto: PendingActionRequestDto): Promise<ActionDto> => {
return await fetchPost<PendingActionRequestDto, ActionDto>('/v1/actions/pending', pendingActionRequestDto)
}
export const transactionConstruct = async (transactionId: string, constructTransactionRequestDto: ConstructTransactionRequestDto): Promise<TransactionDto> => {
return await fetchPatch<ConstructTransactionRequestDto, TransactionDto>(`/v1/transactions/${transactionId}`, constructTransactionRequestDto)
}
export const transactionSubmitHash = async (transactionId: string, submitHashRequestDto: SubmitHashRequestDto): Promise<void> => {
await fetch(baseUrl + `/v1/transactions/${transactionId}/submit_hash`, {
method: 'POST',
headers,
body: JSON.stringify(submitHashRequestDto)
})
}
export const yieldGetSingleYieldBalances = async (integrationId: string, yieldBalanceRequestDto: YieldBalanceRequestDto): Promise<YieldBalanceDto[]> => {
return await fetchPost<YieldBalanceRequestDto, YieldBalanceDto[]>(`/v1/yields/${integrationId}/balances`, yieldBalanceRequestDto)
}
export const yieldYieldOpportunity = async (integrationId: string): Promise<YieldDto> => {
return await fetchGet<YieldDto>(`/v1/yields/${integrationId}`)
}
89 changes: 47 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2951,7 +2951,7 @@
resolved "https://registry.yarnpkg.com/@mswjs/cookies/-/cookies-1.1.0.tgz#1528eb43630caf83a1d75d5332b30e75e9bb1b5b"
integrity sha512-0ZcCVQxifZmhwNBoQIrystCb+2sWBY2Zw8lpfJBPCHGCA/HWqehITeCRVIv4VMy8MPlaHo2w2pTHFV2pFfqKPw==

"@mswjs/interceptors@^0.25.13":
"@mswjs/interceptors@^0.25.14":
version "0.25.14"
resolved "https://registry.yarnpkg.com/@mswjs/interceptors/-/interceptors-0.25.14.tgz#70c1c9736b5c327337c0eb3da6d4895d7928049b"
integrity sha512-2dnIxl+obqIqjoPXTFldhe6pcdOrqiz+GcLaQQ6hmL02OldAF7nIC+rUgTWm+iF6lvmyCVhFFqbgbapNhR8eag==
Expand Down Expand Up @@ -4067,16 +4067,16 @@
"@stablelib/random" "^1.0.2"
"@stablelib/wipe" "^1.0.1"

"@stakekit/api-hooks@^0.0.50":
version "0.0.50"
resolved "https://registry.yarnpkg.com/@stakekit/api-hooks/-/api-hooks-0.0.50.tgz#c7a596885a4d552415d3f7b8d2fc312d228ea46b"
integrity sha512-eON0t3kEKkH/mht0Sk0YRCjdtpptcz+xrrH6qFt9yUmq2jGY5cwbCT1cCplvNKAeM6veSRSsywu3sZECd+j01Q==
"@stakekit/api-hooks@^0.0.52":
version "0.0.52"
resolved "https://registry.yarnpkg.com/@stakekit/api-hooks/-/api-hooks-0.0.52.tgz#25c3f67519a5be67b0d46e4c31f4e8d494238820"
integrity sha512-QF2l2y8fMRMg7ZH93I+YrERrLqsF60QZAjHzpihaAP64x/zjWU8PQ1oysKYynvFzIGpfh1fh/oW1d7KisqGUUw==
dependencies:
"@faker-js/faker" "^8.3.1"
"@tanstack/react-query" "^5.17.1"
axios "^1.6.4"
"@tanstack/react-query" "^5.17.9"
axios "^1.6.5"
lodash.merge "^4.6.2"
msw "^2.0.11"
msw "^2.0.13"

"@substrate/connect-extension-protocol@^1.0.1":
version "1.0.1"
Expand Down Expand Up @@ -4208,17 +4208,17 @@
dependencies:
defer-to-connect "^2.0.1"

"@tanstack/[email protected].9":
version "5.17.9"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.17.9.tgz#1dac85c7c674bdfd132fe7cd5cb898921000bdcf"
integrity sha512-8xcvpWIPaRMDNLMvG9ugcUJMgFK316ZsqkPPbsI+TMZsb10N9jk0B6XgPk4/kgWC2ziHyWR7n7wUhxmD0pChQw==
"@tanstack/[email protected].19":
version "5.17.19"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.17.19.tgz#212515ccc7a6b913afee6b71ce3e7df2c4d85f7d"
integrity sha512-Lzw8FUtnLCc9Jwz0sw9xOjZB+/mCCmJev38v2wHMUl/ioXNIhnNWeMxu0NKUjIhAd62IRB3eAtvxAGDJ55UkyA==

"@tanstack/react-query@^5.17.1":
version "5.17.9"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.17.9.tgz#74826465c1b2ecde17c6d2f1d03f10b611ac2363"
integrity sha512-M5E9gwUq1Stby/pdlYjBlL24euIVuGbWKIFCbtnQxSdXI4PgzjTSdXdV3QE6fc+itF+TUvX/JPTKIwq8yuBXcg==
"@tanstack/react-query@^5.17.9":
version "5.17.19"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.17.19.tgz#d6fc243faa469bb84952dd810faea47dabe389fc"
integrity sha512-qaQENB6/03Gj3dFZGvdmUoqeUGlGm7P1p0RmaR04Bf1Ib1T9lLGimcC9T3oCFbrx0b2ZF21ngjFZNjj9uPJMcg==
dependencies:
"@tanstack/query-core" "5.17.9"
"@tanstack/query-core" "5.17.19"

"@tokenizer/token@^0.3.0":
version "0.3.0"
Expand Down Expand Up @@ -4376,10 +4376,10 @@
dependencies:
"@types/node" "*"

"@types/cookie@^0.4.1":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.4.1.tgz#bfd02c1f2224567676c1545199f87c3a861d878d"
integrity sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==
"@types/cookie@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5"
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==

"@types/crypto-js@^3.1.43":
version "3.1.47"
Expand Down Expand Up @@ -4568,7 +4568,7 @@
expect "^29.0.0"
pretty-format "^29.0.0"

"@types/js-levenshtein@^1.1.1":
"@types/js-levenshtein@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/js-levenshtein/-/js-levenshtein-1.1.3.tgz#a6fd0bdc8255b274e5438e0bfb25f154492d1106"
integrity sha512-jd+Q+sD20Qfu9e2aEXogiO3vpOC1PYJOUdyN9gvs4Qrvkg4wF43L5OhqrPeokdv8TL0/mXoYfpkcoGZMNN2pkQ==
Expand Down Expand Up @@ -4838,7 +4838,7 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"
integrity sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw==

"@types/statuses@^2.0.1":
"@types/statuses@^2.0.4":
version "2.0.4"
resolved "https://registry.yarnpkg.com/@types/statuses/-/statuses-2.0.4.tgz#041143ba4a918e8f080f8b0ffbe3d4cb514e2315"
integrity sha512-eqNDvZsCNY49OAXB0Firg/Sc2BgoWsntsLUdybGFOhAfCD6QJ2n9HXUIHGqt5qjrxmMv4wS8WLAw43ZkKcJ8Pw==
Expand Down Expand Up @@ -5997,7 +5997,7 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

[email protected], [email protected], axios@^0.18.0, axios@^0.19.0, axios@^0.26.1, axios@^1.3.2, axios@^1.6.0, axios@^1.6.4:
[email protected], [email protected], axios@^0.18.0, axios@^0.19.0, axios@^0.26.1, axios@^1.3.2, axios@^1.6.0, axios@^1.6.5:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
Expand Down Expand Up @@ -10952,7 +10952,7 @@ [email protected], hdkey@^1.1.1:
safe-buffer "^5.1.1"
secp256k1 "^3.0.1"

headers-polyfill@^4.0.1:
headers-polyfill@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/headers-polyfill/-/headers-polyfill-4.0.2.tgz#9115a76eee3ce8fbf95b6e3c6bf82d936785b44a"
integrity sha512-EWGTfnTqAO2L/j5HZgoM/3z82L7necsJ0pO9Tp0X1wil3PDLrkypTBRgVO2ExehEEvUycejZD3FuRaXpZZc3kw==
Expand Down Expand Up @@ -13642,32 +13642,32 @@ [email protected], ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

msw@^2.0.11:
version "2.0.12"
resolved "https://registry.yarnpkg.com/msw/-/msw-2.0.12.tgz#1a1c4999988376df3975bfb3b382691f4b20c9e8"
integrity sha512-TN9HuRDRf8dA2tmIhc7xpX45A37zBMcjBBem490lBK+zz/eyveGoQZQTARAIiEHld6rz9bpzl1GSuxmy1mG87A==
msw@^2.0.13:
version "2.1.3"
resolved "https://registry.yarnpkg.com/msw/-/msw-2.1.3.tgz#56f233765739ffea0ca22b8c2144911305b6a58c"
integrity sha512-ZYOpBIxwnGkYKeGqkk9tI87OgOqYXeRpk5ZBTxJILOTyglVwzSde7E2TOoUlma4Kwu2cwgBEGlZnz0RbZPJuoA==
dependencies:
"@bundled-es-modules/cookie" "^2.0.0"
"@bundled-es-modules/js-levenshtein" "^2.0.1"
"@bundled-es-modules/statuses" "^1.0.1"
"@mswjs/cookies" "^1.1.0"
"@mswjs/interceptors" "^0.25.13"
"@mswjs/interceptors" "^0.25.14"
"@open-draft/until" "^2.1.0"
"@types/cookie" "^0.4.1"
"@types/js-levenshtein" "^1.1.1"
"@types/statuses" "^2.0.1"
"@types/cookie" "^0.6.0"
"@types/js-levenshtein" "^1.1.3"
"@types/statuses" "^2.0.4"
chalk "^4.1.2"
chokidar "^3.4.2"
graphql "^16.8.1"
headers-polyfill "^4.0.1"
headers-polyfill "^4.0.2"
inquirer "^8.2.0"
is-node-process "^1.2.0"
js-levenshtein "^1.1.6"
outvariant "^1.4.0"
outvariant "^1.4.2"
path-to-regexp "^6.2.0"
strict-event-emitter "^0.5.0"
type-fest "^2.19.0"
yargs "^17.3.1"
strict-event-emitter "^0.5.1"
type-fest "^4.9.0"
yargs "^17.7.2"

multibase@^0.7.0:
version "0.7.0"
Expand Down Expand Up @@ -14292,7 +14292,7 @@ osenv@^0.1.5:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

outvariant@^1.2.1, outvariant@^1.4.0:
outvariant@^1.2.1, outvariant@^1.4.0, outvariant@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/outvariant/-/outvariant-1.4.2.tgz#f54f19240eeb7f15b28263d5147405752d8e2066"
integrity sha512-Ou3dJ6bA/UJ5GVHxah4LnqDwZRwAmWxrG3wtrHrbGnP4RnLCtA64A4F+ae7Y8ww660JaddSoArUR5HjipWSHAQ==
Expand Down Expand Up @@ -16895,7 +16895,7 @@ stream-shift@^1.0.0:
resolved "https://registry.yarnpkg.com/stream-shift/-/stream-shift-1.0.0.tgz#d5c752825e5367e786f78e18e445ea223a155952"
integrity sha1-1cdSgl5TZ+eG944Y5EXqIjoVWVI=

strict-event-emitter@^0.5.0, strict-event-emitter@^0.5.1:
strict-event-emitter@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz#1602ece81c51574ca39c6815e09f1a3e8550bd93"
integrity sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==
Expand Down Expand Up @@ -17742,11 +17742,16 @@ type-fest@^1.0.1:
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1"
integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==

type-fest@^2.13.0, type-fest@^2.19.0:
type-fest@^2.13.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==

type-fest@^4.9.0:
version "4.10.0"
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-4.10.0.tgz#30e6d2648fecb67c296d0de31b32d156e501c38d"
integrity sha512-NPaKJsb4wyJ16qc8zBQrWswLKv/YirgBFykvUQ1Iajt2wd+twC8E4hFXdlIXqiMl6kWA0zY8tUJ9ELVAdu5h7w==

type-is@~1.6.18:
version "1.6.18"
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131"
Expand Down Expand Up @@ -19104,7 +19109,7 @@ yargs@^16.2.0:
y18n "^5.0.5"
yargs-parser "^20.2.2"

yargs@^17.3.1, yargs@^17.5.1:
yargs@^17.3.1, yargs@^17.5.1, yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
Expand Down

0 comments on commit e4858c5

Please sign in to comment.