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

Fix transfers for all chains #164

Merged
merged 3 commits into from
Sep 13, 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: 1 addition & 1 deletion .github/workflows/check-build-front.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16-alpine3.16 as dependencies
FROM node:18-alpine3.19 as dependencies

ARG GH_BACKEND_URL
ARG GH_IPFS_URL
Expand All @@ -24,7 +24,7 @@ RUN set -x \
&& mv ci.env .env \
&& NODE_ENV=production yarn build

FROM gcr.io/distroless/nodejs:16 AS runner
FROM gcr.io/distroless/nodejs:18 AS runner

ARG GH_BACKEND_URL
ARG GH_IPFS_URL
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@
"typescript": "4.9.5"
},
"resolutions": {
"@types/react": "^17.x.x",
"@polkadot/types": "^10.9.1",
"@polkadot/api": "^10.9.1",
"@polkadot/util": "^12.5.1"
"@polkadot/types": "^13.0.1",
"@polkadot/api": "^13.0.1",
"@polkadot/util": "^13.0.2"
},
"dependencies": {
"@amplitude/analytics-browser": "^2.2.2",
Expand Down
210 changes: 195 additions & 15 deletions src/components/transfer/configs/same-chain.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,243 @@
import { useChainInfoByNetwork } from 'src/rtk/features/multiChainInfo/multiChainInfoHooks'
import { decodeExtrinsicString, getExtrinsicParams } from 'src/utils/extrinsicDecoder'
import {
decodeExtrinsicString,
getExtrinsicParams,
} from 'src/utils/extrinsicDecoder'

const getCustomTransferParamId = (token: string, network: string) => `${token}|${network}`
const getCustomTransferParamId = (token: string, network: string) =>
`${token}|${network}`
export type SameChainTransferParamData = {
amount: string
recipient: string
tokenId?: any
}

// balances.transfer - parallel, pioneer, romonomics, joystream, turing, parallel heiko, chainx
const customSameChainTransferConfig: {
[key: string]: {
getParams: (
data: SameChainTransferParamData,
) => any[]
getParams: (data: SameChainTransferParamData) => any[]
extrinsic: string
}
} = {
[getCustomTransferParamId('KSM', 'kusama')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [ data.recipient, data.amount ]
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('DOT', 'polkadot')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [ data.recipient, data.amount ]
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('ACA', 'acala')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('ASTR', 'astar')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('BNC', 'bifrostKusama')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('KSM', 'statemine')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('DOT', 'statemint')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('UNQ', 'unique')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('KAR', 'karura')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('PEN', 'pendulum')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('HDX', 'hydradx')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('SDN', 'shiden')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('PHA', 'khala')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('BNC', 'bifrostPolkadot')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('AIR', 'altair')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('BSX', 'basilisk')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('KMA', 'calamari')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('TEER', 'integritee')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('NUUM', 'continuum')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('CFG', 'centrifuge')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('NEURO', 'originTrail')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('MANTA', 'manta')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('PICA', 'picasso')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('PDEX', 'polkadex-polkadot')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('NODL', 'nodle')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('RING', 'darwinia')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('CRAB', 'darwinia-crab')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('TNKR', 'invArch')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('VARCH', 'invArch-polkadot')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('QTZ', 'quartz')]: {
extrinsic: 'balances.transferAllowDeath',
getParams: (data) => {
return [data.recipient, data.amount]
},
},
[getCustomTransferParamId('MGX', 'mangata')]: {
extrinsic: 'tokens.transfer',
getParams: (data) => {
return [ data.recipient, 0, data.amount ]
return [data.recipient, 0, data.amount]
},
},
[getCustomTransferParamId('KINT', 'kintsugi')]: {
extrinsic: 'tokens.transfer',
getParams: (data) => {
return [ data.recipient, { Token: 'KINT' }, data.amount ]
return [data.recipient, { Token: 'KINT' }, data.amount]
},
},
[getCustomTransferParamId('INTR', 'interlay')]: {
extrinsic: 'tokens.transfer',
getParams: (data) => {
return [ data.recipient, { Token: 'INTR' }, data.amount ]
return [data.recipient, { Token: 'INTR' }, data.amount]
},
},
}

export function useSameChainTransferExtrinsic (network: string, token: string, getTransferData: () => SameChainTransferParamData) {
export function useSameChainTransferExtrinsic(
network: string,
token: string,
getTransferData: () => SameChainTransferParamData
) {
const chainInfo = useChainInfoByNetwork(network)

const getExtrinsic = () => {
const { tokenId } = getTransferData()
const customConfig = customSameChainTransferConfig[getCustomTransferParamId(token, network)]
const customConfig =
customSameChainTransferConfig[getCustomTransferParamId(token, network)]
if (customConfig) {
return customConfig.extrinsic
} else if (!tokenId) {
return 'balances.transfer'
} else {
const { extrinsic } = decodeExtrinsicString(chainInfo?.tokenTransferMethod || '')
const { extrinsic } = decodeExtrinsicString(
chainInfo?.tokenTransferMethod || ''
)
return extrinsic
}
}
Expand All @@ -67,11 +246,12 @@ export function useSameChainTransferExtrinsic (network: string, token: string, g
const transferData = getTransferData()
const { amount, recipient, tokenId } = transferData

const customGetter = customSameChainTransferConfig[getCustomTransferParamId(token, network)]
const customGetter =
customSameChainTransferConfig[getCustomTransferParamId(token, network)]
if (customGetter) return customGetter.getParams({ ...transferData })

if (!tokenId) {
return [ recipient, amount ]
return [recipient, amount]
}

const method = chainInfo?.tokenTransferMethod
Expand Down
6 changes: 3 additions & 3 deletions src/rtk/features/prices/pricesHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const overriddenChainNames: Record<string, string> = {
continuum: 'mnet-continuum',
}

export const statemineAssets = ['rmrk']
const additionalTokens = ['zenlink-network-token', 'weth', 'wrapped-bitcoin']
export const statemineAssets = [ 'rmrk' ]
const additionalTokens = [ 'zenlink-network-token', 'weth', 'wrapped-bitcoin' ]

export const getChainsNamesForCoinGecko = (chainsInfo: MultiChainInfo) => {
let keys: string[] = []

if (chainsInfo && !isEmptyObj(chainsInfo)) {
keys = [...Object.keys(chainsInfo), ...statemineAssets, ...additionalTokens]
keys = [ ...Object.keys(chainsInfo), ...statemineAssets, ...additionalTokens ]
}

return keys
Expand Down
Loading
Loading