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

Feat: Avail support #2538

Merged
merged 6 commits into from
Oct 29, 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 eslint-local-rules/rules/no-relative-import-from-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
return {
ImportDeclaration(node) {
const { source } = node;
if (!isLiteral(source.type)) {
if (!isLiteral(source)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion eslint-local-rules/rules/no-self-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
}

const { source } = node;
if (!isLiteral(source.type)) {
if (!isLiteral(source)) {
return;
}

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
"dependencies": {
"@apollo/client": "3.11.8",
"@headlessui/react": "^1.7.17",
"@polkadot/api": "12.4.2",
"@polkadot/keyring": "13.0.2",
"@polkadot/api": "13.1.1",
"@polkadot/keyring": "13.1.1",
"@polkadot/react-identicon": "3.9.1",
"@polkadot/rpc-provider": "12.4.2",
"@polkadot/types": "12.4.2",
"@polkadot/util": "13.0.2",
"@polkadot/util-crypto": "13.0.2",
"@polkadot/rpc-provider": "14.1.1",
"@polkadot/types": "13.1.1",
"@polkadot/util": "13.1.1",
"@polkadot/util-crypto": "13.1.1",
"@radix-ui/react-checkbox": "^1.1.2",
"@radix-ui/react-dialog": "1.1.2",
"@radix-ui/react-dropdown-menu": "2.1.2",
Expand All @@ -85,8 +85,8 @@
"@react-spring/web": "9.7.5",
"@remote-ui/rpc": "^1.4.4",
"@substrate/connect": "^1.1.0",
"@substrate/txwrapper-orml": "7.5.1",
"@substrate/txwrapper-polkadot": "7.5.1",
"@substrate/txwrapper-orml": "7.5.2",
"@substrate/txwrapper-polkadot": "7.5.2",
"@walletconnect/sign-client": "2.16.1",
"@walletconnect/types": "2.16.1",
"@walletconnect/utils": "2.16.1",
Expand Down
1,108 changes: 523 additions & 585 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/renderer/entities/network/model/network-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ const createApiFx = createEffect(async ({ chainId, providers, apis }: CreateApiP
await api.connect();

return api;
} else {
return networkService.createApi(providers[chainId]);
}

return networkService.createApi(chainId, providers[chainId]);
});

const disconnectApiFx = createEffect(async (api: ApiPromise): Promise<ChainId> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiPromise } from '@polkadot/api';
import { MockProvider } from '@polkadot/rpc-provider/mock';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';

import { TEST_ADDRESS } from '@/shared/lib/utils';
import { useCallDataDecoder } from '../callDataDecoder';
Expand All @@ -15,6 +15,8 @@ describe('entities/transaction/lib/callDataDecoder', () => {
let api: ApiPromise;

beforeEach(async (): Promise<void> => {
// @ts-expect-error In polkadot.js tests the also use TypeRegistry
// https://github.com/polkadot-js/api/blob/master/packages/rpc-core/src/index.spec.ts
provider = new MockProvider(registry);
const genesisHash = registry.createType('Hash', await provider.send('chain_getBlockHash', [])).toHex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('entities/transaction/lib/extrinsicService', () => {
let api: ApiPromise;

beforeEach(async (): Promise<void> => {
// @ts-expect-error In polkadot.js tests the also use TypeRegistry
// https://github.com/polkadot-js/api/blob/master/packages/rpc-core/src/index.spec.ts
provider = new MockProvider(registry);

const genesisHash = registry.createType('Hash', await provider.send('chain_getBlockHash', [])).toHex();
Expand Down
21 changes: 1 addition & 20 deletions src/renderer/entities/transaction/lib/extrinsicService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,8 @@ import { getMaxWeight, hasDestWeight, isControllerMissing, isOldMultisigPallet }
import * as xcmMethods from './common/xcmMethods';
import { convictionVotingMethods } from './wrappers/convictionVoting';

type BalancesTransferArgs = Parameters<typeof methods.balances.transfer>[0];
type BondWithoutContollerArgs = Omit<Parameters<typeof methods.staking.bond>[0], 'controller'>;

// TODO: change to substrate txwrapper method when it'll update
const transferKeepAlive = (
args: BalancesTransferArgs,
info: BaseTxInfo,
options: OptionsWithMeta,
): UnsignedTransaction =>
defineMethod(
{
method: {
args,
name: 'transferKeepAlive',
pallet: 'balances',
},
...info,
},
options,
);

const bondWithoutController = (
args: BondWithoutContollerArgs,
info: BaseTxInfo,
Expand All @@ -63,7 +44,7 @@ export const getUnsignedTransaction: Record<
[TransactionType.TRANSFER]: (transaction, info, options, api) => {
// @ts-expect-error TODO fix
return api.tx.balances.transferKeepAlive
? transferKeepAlive(
? methods.balances.transferKeepAlive(
{
dest: transaction.args.dest,
value: transaction.args.value,
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/entities/transaction/lib/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ type TxWrappersParams = {
account: Account;
signatories?: Account[];
};

/**
* Get array of transaction wrappers (proxy/multisig) Every wrapper recursively
* calls getTxWrappers until it finds regular account
Expand Down Expand Up @@ -260,6 +261,7 @@ export type WrappedTransactions = {
coreTx: Transaction;
multisigTx?: Transaction;
};

function getWrappedTransaction({ api, addressPrefix, transaction, txWrappers }: WrapperParams): WrappedTransactions {
return txWrappers.reduce<WrappedTransactions>(
(acc, txWrapper) => {
Expand Down
13 changes: 11 additions & 2 deletions src/renderer/shared/api/network/service/networkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiPromise, ScProvider, WsProvider } from '@polkadot/api';
import { type ProviderInterface } from '@polkadot/rpc-provider/types';
import * as Sc from '@substrate/connect';

import { EXTENSIONS } from '@/shared/config/extensions';
import { type ChainId, type HexString } from '@/shared/core';
import { getKnownChain } from '@/shared/lib/utils';
import { ProviderType, type ProviderWithMetadata } from '../lib/types';
Expand All @@ -12,8 +13,16 @@ export const networkService = {
createApi,
};

function createApi(provider: ProviderInterface): Promise<ApiPromise> {
return ApiPromise.create({ provider, throwOnConnect: true, noInitWarn: true, throwOnUnknown: true });
function createApi(chainId: ChainId, provider: ProviderInterface): Promise<ApiPromise> {
const api = new ApiPromise({
provider,
noInitWarn: true,
throwOnConnect: true,
throwOnUnknown: true,
...EXTENSIONS[chainId].provider,
});

return api.isReady;
}

type ProviderParams = {
Expand Down
16 changes: 16 additions & 0 deletions src/renderer/shared/config/extensions/avail/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { rpc } from './rpc';
import { signedExtensions } from './signed-extensions';
import { types } from './types';

export const AVAIL_PROVIDER = {
rpc,
types,
signedExtensions,
};

export const AVAIL_TXWRAPPER = {
additionalTypes: {
AppId: types['AppId'],
},
userExtensions: signedExtensions,
};
62 changes: 62 additions & 0 deletions src/renderer/shared/config/extensions/avail/rpc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { type DefinitionRpc, type DefinitionRpcSub } from '@polkadot/types/types/definitions';

export const rpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>> = {
kate: {
blockLength: {
description: 'Get Block Length',
params: [
{
name: 'at',
type: 'Hash',
isOptional: true,
},
],
type: 'BlockLength',
},
queryProof: {
description: 'Generate the kate proof for the given `cells`',
params: [
{
name: 'cells',
type: 'Vec<Cell>',
},
{
name: 'at',
type: 'Hash',
isOptional: true,
},
],
type: 'Vec<(U256, [u8; 48])>',
},
queryDataProof: {
description: 'Generate the data proof for the given `transaction_index`',
params: [
{
name: 'transaction_index',
type: 'u32',
},
{
name: 'at',
type: 'Hash',
isOptional: true,
},
],
type: 'ProofResponse',
},
queryRows: {
description: 'Query rows based on their indices',
params: [
{
name: 'rows',
type: 'Vec<u32>',
},
{
name: 'at',
type: 'Hash',
isOptional: true,
},
],
type: 'Vec<Vec<U256>>',
},
},
};
10 changes: 10 additions & 0 deletions src/renderer/shared/config/extensions/avail/signed-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { type ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';

export const signedExtensions: ExtDef = {
CheckAppId: {
payload: {},
extrinsic: {
appId: 'AppId',
},
},
};
103 changes: 103 additions & 0 deletions src/renderer/shared/config/extensions/avail/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { type RegistryTypes } from '@polkadot/types/types';

export const types: RegistryTypes = {
AppId: 'Compact<u32>',
DataLookupItem: {
appId: 'AppId',
start: 'Compact<u32>',
},
CompactDataLookup: {
size: 'Compact<u32>',
index: 'Vec<DataLookupItem>',
},
KateCommitment: {
rows: 'Compact<u16>',
cols: 'Compact<u16>',
commitment: 'Vec<u8>',
dataRoot: 'H256',
},
V3HeaderExtension: {
appLookup: 'CompactDataLookup',
commitment: 'KateCommitment',
},
HeaderExtension: {
_enum: {
V1: 'V3HeaderExtension',
V2: 'V3HeaderExtension',
V3: 'V3HeaderExtension',
},
},
DaHeader: {
parentHash: 'Hash',
number: 'Compact<BlockNumber>',
stateRoot: 'Hash',
extrinsicsRoot: 'Hash',
digest: 'Digest',
extension: 'HeaderExtension',
},
Header: 'DaHeader',
CheckAppIdExtra: {
appId: 'AppId',
},
CheckAppIdTypes: {},
CheckAppId: {
extra: 'CheckAppIdExtra',
types: 'CheckAppIdTypes',
},
BlockLengthColumns: 'Compact<u32>',
BlockLengthRows: 'Compact<u32>',
BlockLength: {
max: 'PerDispatchClass',
cols: 'BlockLengthColumns',
rows: 'BlockLengthRows',
chunkSize: 'Compact<u32>',
},
PerDispatchClass: {
normal: 'u32',
operational: 'u32',
mandatory: 'u32',
},
DataProof: {
roots: 'TxDataRoots',
proof: 'Vec<H256>',
numberOfLeaves: 'Compact<u32>',
leafIndex: 'Compact<u32>',
leaf: 'H256',
},
TxDataRoots: {
dataRoot: 'H256',
blobRoot: 'H256',
bridgeRoot: 'H256',
},
ProofResponse: {
dataProof: 'DataProof',
message: 'Option<AddressedMessage>',
},
AddressedMessage: {
message: 'Message',
from: 'H256',
to: 'H256',
originDomain: 'u32',
destinationDomain: 'u32',
id: 'u64',
},
Message: {
_enum: {
ArbitraryMessage: 'ArbitraryMessage',
FungibleToken: 'FungibleToken',
},
},
MessageType: {
_enum: ['ArbitraryMessage', 'FungibleToken'],
},
FungibleToken: {
assetId: 'H256',
amount: 'String',
},
BoundedData: 'Vec<u8>',
ArbitraryMessage: 'BoundedData',
Cell: {
row: 'BlockLengthRows',
col: 'BlockLengthColumns',
},
};
24 changes: 24 additions & 0 deletions src/renderer/shared/config/extensions/index.ts
tuul-wq marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { type ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import { type DefinitionRpc, type DefinitionRpcSub, type RegistryTypes } from '@polkadot/types/types';

import { type ChainId } from '@/shared/core';

import { AVAIL_PROVIDER, AVAIL_TXWRAPPER } from './avail';

type Extension = {
rpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
types: RegistryTypes;
signedExtensions: ExtDef;
};

type TxWrapper = {
additionalTypes: RegistryTypes;
userExtensions: ExtDef;
};

export const EXTENSIONS: Record<ChainId, { provider: Extension; txwrapper: TxWrapper }> = {
'0xb91746b45e0346cc2f815a520b9c6cb4d5c0902af848db0a80f85932d2e8276a': {
provider: AVAIL_PROVIDER,
txwrapper: AVAIL_TXWRAPPER,
},
};
Loading
Loading