Skip to content

Commit

Permalink
feat: add Dot Joystream chain
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 committed Dec 5, 2023
1 parent 2e90b2a commit 6e02a14
Show file tree
Hide file tree
Showing 8 changed files with 424 additions and 553 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,19 @@
"@metamask/eth-sig-util@^4.0.1": "patch:@metamask/eth-sig-util@npm%3A4.0.1#./.yarn/patches/@metamask-eth-sig-util-npm-4.0.1-27d55ec43e.patch",
"cross-fetch": "patch:cross-fetch@npm%3A3.1.5#./.yarn/patches/cross-fetch-npm-3.1.5-e414995db9.patch",
"protobufjs": "patch:protobufjs@npm%3A6.11.3#./.yarn/patches/protobufjs-npm-6.11.3-566fb31188.patch",
"@polkadot/extension-inject": "0.46.3",
"@polkadot/rpc-provider": "^10.7.1",
"@polkadot/rpc-core": "^10.7.1",
"@polkadot/rpc-augment": "^10.7.1",
"@polkadot/types": "^10.7.1",
"@polkadot/types-support": "^10.7.1",
"@polkadot/types-known": "^10.7.1",
"@polkadot/types-create": "^10.7.1",
"@polkadot/types-codec": "^10.7.1",
"@polkadot/types-augment": "^10.7.1",
"@polkadot/util": "^12.2.1",
"@polkadot/util-crypto": "^12.2.1",
"@polkadot/x-global": "^12.2.1",
"@polkadot/extension-inject": "0.46.6",
"@polkadot/rpc-provider": "^10.11.1",
"@polkadot/rpc-core": "^10.11.1",
"@polkadot/rpc-augment": "^10.11.1",
"@polkadot/types": "^10.11.1",
"@polkadot/types-support": "^10.11.1",
"@polkadot/types-known": "^10.11.1",
"@polkadot/types-create": "^10.11.1",
"@polkadot/types-codec": "^10.11.1",
"@polkadot/types-augment": "^10.11.1",
"@polkadot/util": "^12.6.1",
"@polkadot/util-crypto": "^12.6.1",
"@polkadot/x-global": "^12.6.1",
"react": "18.2.0",
"jsc-android": "294992.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
"@noble/secp256k1": "^1.7.1",
"@onekeyfe/cardano-coin-selection": "1.0.0",
"@onekeyfe/cardano-coin-selection-asmjs": "^1.1.0",
"@polkadot/api": "10.7.1",
"@polkadot/extension-inject": "0.46.3",
"@polkadot/api": "10.11.1",
"@polkadot/extension-inject": "0.46.6",
"@solana/spl-token": "^0.3.0",
"@solana/web3.js": "^1.75.0",
"@substrate/txwrapper-polkadot": "6.0.0",
"@substrate/txwrapper-polkadot": "7.1.1",
"@zondax/izari-filecoin": "^1.0.1",
"algosdk": "^1.21.0",
"aptos": "^1.3.17",
Expand Down
38 changes: 29 additions & 9 deletions packages/engine/src/vaults/impl/dot/Vault.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/require-await */
import { bytesToHex } from '@noble/hashes/utils';
import {
construct,
createMetadata,
Expand Down Expand Up @@ -61,7 +62,6 @@ import { KeyringHardware } from './KeyringHardware';
import { KeyringHd } from './KeyringHd';
import { KeyringImported } from './KeyringImported';
import { KeyringWatching } from './KeyringWatching';
import { accountIdToAddress } from './sdk/address';
import polkadotSdk from './sdk/polkadotSdk';
import { EXTRINSIC_VERSION } from './sdk/polkadotSdkTypes';
import settings from './settings';
Expand All @@ -79,6 +79,8 @@ import type { DotImplOptions, IEncodedTxDot } from './types';
import type { BaseTxInfo, TypeRegistry } from '@substrate/txwrapper-polkadot';

const {
encodeAddress,
decodeAddress,
ApiPromise,
HttpProvider,
WsProvider,
Expand Down Expand Up @@ -286,11 +288,10 @@ export default class Vault extends VaultBase {
}

const implOptions = await this.getChainInfoImplOptions();
const address = accountIdToAddress(
accountId,
return encodeAddress(
addHexPrefix(accountId),
implOptions?.addressPrefix ?? 0,
).getValue();
return address;
);
}

override async addressFromBase(account: DBAccount) {
Expand Down Expand Up @@ -430,8 +431,23 @@ export default class Vault extends VaultBase {
if (!transferInfo.to) {
throw new Error('Invalid transferInfo.to params');
}
const implOptions = await this.getChainInfoImplOptions();

const { to, amount, token: tokenAddress } = transferInfo;
const { address: from } = await this.getDbAccount();
const toAccountId = decodeAddress(
to,
true,
implOptions?.addressPrefix ?? 0,
);

const chainId = await this.getNetworkChainId();
let toAccount = { id: to };
// pending txwapper-polkadot support JoyStream
if (chainId === 'joystream') {
// @ts-expect-error
toAccount = `0x${bytesToHex(toAccountId)}`;
}

let amountValue;
const client = await this.getClient();
Expand Down Expand Up @@ -513,7 +529,7 @@ export default class Vault extends VaultBase {
unsigned = methods.balances.transferKeepAlive(
{
value: amountValue,
dest: { id: to },
dest: toAccount,
},
info,
option,
Expand All @@ -522,7 +538,7 @@ export default class Vault extends VaultBase {
unsigned = methods.balances.transfer(
{
value: amountValue,
dest: { id: to },
dest: toAccount,
},
info,
option,
Expand Down Expand Up @@ -848,10 +864,14 @@ export default class Vault extends VaultBase {
if (type === IDecodedTxActionType.NATIVE_TRANSFER) {
debugLogger.sendTx.debug('updateEncodedTx', 'send max amount');

const {
const chainId = await this.getNetworkChainId();
let {
// @ts-expect-error
dest: { id: toAddress },
} = decodeUnsignedTx.method.args;
if (chainId === 'joystream') {
toAddress = decodeUnsignedTx.method.args.dest;
}

const chainVault = await this.getChainVault();
const registry = await chainVault.getRegistryCache(encodedTx);
Expand All @@ -861,7 +881,7 @@ export default class Vault extends VaultBase {
blockHash: encodedTx.blockHash,
blockNumber: hexToNumber(addHexPrefix(encodedTx.blockNumber)),
eraPeriod: 64,
genesisHash: encodedTx.genesisHash as `0x${string}`,
genesisHash: encodedTx.genesisHash,
metadataRpc: encodedTx.metadataRpc,
nonce: hexToNumber(addHexPrefix(encodedTx.nonce)),
specVersion: hexToNumber(addHexPrefix(encodedTx.specVersion)),
Expand Down
26 changes: 0 additions & 26 deletions packages/engine/src/vaults/impl/dot/sdk/address.ts

This file was deleted.

141 changes: 0 additions & 141 deletions packages/engine/src/vaults/impl/dot/substrate/SubstrateAddress.ts

This file was deleted.

This file was deleted.

43 changes: 43 additions & 0 deletions packages/shared/src/config/presetNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,49 @@ const serverPresetNetworks = [
'createdAt': '2023-05-31T00:29:24.951Z',
'updatedAt': '2023-05-31T00:29:24.951Z',
},
{
'balance2FeeDecimals': 10,
'chainId': 'joystream',
'code': 'dot-joystream',
'decimals': 10,
'extensions': {
'providerOptions': {
'addressPrefix': 126,
'addressRegex': '^j4[R-X][a-km-zA-HJ-NP-Z1-9]+$',
},
},
'id': 'dot--joystream',
'impl': 'dot',
'isTestnet': false,
'logoURI': 'https://onekey-asset.com/assets/joystream/joystream.png',
'name': 'Joystream',
'rpcURLs': [
{
'url': 'wss://rpc.joystream.org',
},
],
'shortcode': 'joy',
'shortname': 'JOY',
'symbol': 'JOY',
'feeMeta': {
'code': 'joy',
'decimals': 10,
'symbol': 'JOY',
},
'defaultEnabled': true,
'priceConfigs': [],
'explorers': [
{
'address': 'https://joystream.subscan.io/account/{address}',
'block': 'https://joystream.subscan.io/block/{block}',
'name': 'https://joystream.subscan.io/',
'transaction': 'https://joystream.subscan.io/extrinsic/{transaction}',
},
],
'status': 'LISTED',
'createdAt': '2023-05-31T00:29:24.951Z',
'updatedAt': '2023-05-31T00:29:24.951Z',
},
{
'balance2FeeDecimals': 9,
'chainId': '1',
Expand Down
Loading

0 comments on commit 6e02a14

Please sign in to comment.