Skip to content

Commit

Permalink
Merge branch 'master' into add-sol-to-moonnbeam
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav authored Feb 3, 2025
2 parents 8349d50 + 304c9a8 commit 0736deb
Show file tree
Hide file tree
Showing 77 changed files with 1,097 additions and 382 deletions.
4 changes: 2 additions & 2 deletions examples/sdk-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@galacticcouncil/sdk": "^5.3.0",
"@galacticcouncil/xcm-sdk": "^8.0.1",
"@galacticcouncil/xcm-cfg": "^7.0.0"
"@galacticcouncil/xcm-sdk": "^8.1.0",
"@galacticcouncil/xcm-cfg": "^7.1.1"
}
}
4 changes: 2 additions & 2 deletions examples/xcm-transfer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
},
"dependencies": {
"@galacticcouncil/sdk": "^5.3.0",
"@galacticcouncil/xcm-cfg": "^7.0.0",
"@galacticcouncil/xcm-sdk": "^8.0.1",
"@galacticcouncil/xcm-cfg": "^7.1.1",
"@galacticcouncil/xcm-sdk": "^8.1.0",
"@polkadot-api/descriptors": "file:.papi/descriptors",
"@talismn/connect-wallets": "^1.2.8",
"polkadot-api": "^1.8.2"
Expand Down
46 changes: 22 additions & 24 deletions examples/xcm-transfer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetAmount, ConfigBuilder } from '@galacticcouncil/xcm-core';
import { Call } from '@galacticcouncil/xcm-sdk';
import { Call, SubstrateCall } from '@galacticcouncil/xcm-sdk';

import {
getWormholeChainById,
Expand Down Expand Up @@ -74,33 +74,31 @@ balanceSubscription.unsubscribe();
/***************************/

/**
* Sign transaction with Papi
*
* @param address - signer address
*/
async function signV2(address: string) {
substrateV2.signAndSend(address, call, srcChain, (event) => {
console.log(event);
});
}

/**
* Sign transaction with Pjs
* Sign substrate transaction
*
* @param address - signer address
*/
async function sign(address: string) {
substrate.signAndSend(
address,
call,
srcChain,
({ status }) => {
console.log(status.toHuman());
},
(error) => {
console.error(error);
}
);
const { txOptions } = call as SubstrateCall;

// Using papi signer as txOptions not working in 14.x pjs
if (txOptions) {
substrateV2.signAndSend(address, call, srcChain, (event) => {
console.log(event);
});
} else {
substrate.signAndSend(
address,
call,
srcChain,
({ status }) => {
console.log(status.toHuman());
},
(error) => {
console.error(error);
}
);
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion examples/xcm-transfer/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ configService.registerExternal(externals);
// Register dex-es
const hydration = configService.getChain('hydration');
const assethub = configService.getChain('assethub');
const assethubCex = configService.getChain('assethub_cex');

wallet.registerDex(
new dex.HydrationDex(hydration),
new dex.AssethubDex(assethub)
new dex.AssethubDex(assethub),
new dex.AssethubDex(assethubCex)
);
13 changes: 13 additions & 0 deletions examples/xcm-transfer/src/signers/substrate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { AnyChain, AnyParachain } from '@galacticcouncil/xcm-core';
import type { Call } from '@galacticcouncil/xcm-sdk';

import type { ApiPromise } from '@polkadot/api';
import type { ISubmittableResult } from '@polkadot/types/types';
import { getWalletBySource } from '@talismn/connect-wallets';

/**
* Doesn't work in 14.x pjs !!!
*/
const feeAsset = (api: ApiPromise, assetId: number) =>
api.createType('MultiLocation', {
parents: 0,
interior: {
x2: [{ palletInstance: 50 }, { generalIndex: assetId }],
},
});

export async function signAndSend(
address: string,
call: Call,
Expand Down
25 changes: 17 additions & 8 deletions examples/xcm-transfer/src/signers/substrateV2.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Binary, TxEvent } from 'polkadot-api';

import { AnyChain, AnyParachain } from '@galacticcouncil/xcm-core';
import type { Call } from '@galacticcouncil/xcm-sdk';

import { assethub } from '@polkadot-api/descriptors';

import { getSignerBySource, getWs, asset } from './v2';
import type { AnyChain, AnyParachain } from '@galacticcouncil/xcm-core';
import type { Call, SubstrateCall } from '@galacticcouncil/xcm-sdk';

import { getSignerBySource, getWs, getFeeAsset } from './v2';

export async function signAndSend(
address: string,
Expand All @@ -16,16 +16,25 @@ export async function signAndSend(
const ctx = chain as AnyParachain;
const signer = await getSignerBySource('polkadot-js', address);

const { data, txOptions } = call as SubstrateCall;

const apiPjs = await ctx.api;
const extrinsic = apiPjs.tx(call.data);
const extrinsic = apiPjs.tx(data);

const client = await getWs(ctx.ws);
const api = client.getTypedApi(assethub);

const callData = Binary.fromHex(extrinsic.inner.toHex());

let opts = {};
if (txOptions && txOptions.asset) {
const feeAsset = getFeeAsset(ctx, txOptions.asset);
opts = {
...opts,
asset: feeAsset,
};
}

const tx = await api.txFromCallData(callData);
tx.signSubmitAndWatch(signer, {
asset: asset.usdc,
}).subscribe(observer);
tx.signSubmitAndWatch(signer, opts).subscribe(observer);
}
3 changes: 2 additions & 1 deletion examples/xcm-transfer/src/signers/v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './extension';
export * from './provider';
export * as asset from './types';
export * from './utils';
export * from './types';
7 changes: 0 additions & 7 deletions examples/xcm-transfer/src/signers/v2/provider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createClient, PolkadotClient } from 'polkadot-api';
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';

import { XcmV3Junctions } from '@polkadot-api/descriptors';

export const getWs = async (
wsUrl: string | string[]
): Promise<PolkadotClient> => {
Expand All @@ -15,8 +13,3 @@ export const getWs = async (
const wsProvider = getWsProvider(endpoints);
return createClient(withPolkadotSdkCompat(wsProvider));
};

export type XcmV3Multilocation = {
parents: number;
interior: XcmV3Junctions;
};
20 changes: 2 additions & 18 deletions examples/xcm-transfer/src/signers/v2/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import { XcmV3Junctions, XcmV3Junction } from '@polkadot-api/descriptors';
import { XcmV3Junctions } from '@polkadot-api/descriptors';

type XcmV3Multilocation = {
export type XcmV3Multilocation = {
parents: number;
interior: XcmV3Junctions;
};

export const usdt = {
parents: 0,
interior: XcmV3Junctions.X2([
XcmV3Junction.PalletInstance(50),
XcmV3Junction.GeneralIndex(BigInt(1984)),
]),
} as XcmV3Multilocation;

export const usdc = {
parents: 0,
interior: XcmV3Junctions.X2([
XcmV3Junction.PalletInstance(50),
XcmV3Junction.GeneralIndex(BigInt(1337)),
]),
} as XcmV3Multilocation;
22 changes: 22 additions & 0 deletions examples/xcm-transfer/src/signers/v2/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { XcmV3Junctions, XcmV3Junction } from '@polkadot-api/descriptors';

import { AnyParachain, Asset, multiloc } from '@galacticcouncil/xcm-core';

import { XcmV3Multilocation } from './types';

export const getFeeAsset = (chain: AnyParachain, asset: Asset) => {
const location = chain.getAssetXcmLocation(asset);
if (location) {
const pallet = multiloc.findPalletInstance(location);
const index = multiloc.findGeneralIndex(location);

return {
parents: 0,
interior: XcmV3Junctions.X2([
XcmV3Junction.PalletInstance(Number(pallet)),
XcmV3Junction.GeneralIndex(BigInt(index)),
]),
} as XcmV3Multilocation;
}
throw new Error('Asset locations not found');
};
5 changes: 5 additions & 0 deletions integration-tests/xcm-test/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ process.env.LOG_COMPACT = 'false';
*/
process.env.VERBOSE_LOG = 'false';

process.env.ASSETHUBPOLKADOT_BLOCK_NUMBER = 8112196;
process.env.HYDRATION_BLOCK_NUMBER = 6875392;
process.env.MOONBEAM_BLOCK_NUMBER = 9418127;
process.env.POLKADOT_BLOCK_NUMBER = 24527644;

export default config;
4 changes: 2 additions & 2 deletions integration-tests/xcm-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@acala-network/chopsticks-testing": "1.0.1"
},
"dependencies": {
"@galacticcouncil/xcm-cfg": "^7.0.0",
"@galacticcouncil/xcm-sdk": "^8.0.1"
"@galacticcouncil/xcm-cfg": "^7.1.1",
"@galacticcouncil/xcm-sdk": "^8.1.0"
}
}
24 changes: 24 additions & 0 deletions integration-tests/xcm-test/src/__db__/metadata.db.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,5 +910,29 @@
"feeAsset": "PHA",
"feeNative": "64296000000"
}
},
"hydration-assethub_cex-usdt": {
"updated": 1738523661393,
"destination": {
"fee": "1.055453",
"feeAsset": "USDT",
"feeNative": "1055453"
}
},
"hydration-assethub_cex-usdc": {
"updated": 1738493249475,
"destination": {
"fee": "1.184201",
"feeAsset": "USDC",
"feeNative": "1184201"
}
},
"hydration-polkadot_cex-dot": {
"updated": 1738579585913,
"destination": {
"fee": "10",
"feeAsset": "DOT",
"feeNative": "100000000000"
}
}
}
21 changes: 21 additions & 0 deletions integration-tests/xcm-test/src/__snapshots__/call.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,20 @@ exports[`Wallet with XCM config should return valid Polkadot calldata for Hydrat
]
`;

exports[`Wallet with XCM config should return valid Polkadot calldata for Hydration -> AssetHub (CEX) USDC [usdc] transfer 1`] = `
[
"hydration-assethub_cex-usdc",
"0x5503040d02086b0d04010100a10f0404010300a10f043205e5140002093d000204010300a10f043205e5140204040d010000010100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741006b0004010100a10f041400040002043205e5140082380100130002043205e51400823801000004040002043205e5140022cf040000010100d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d140d01020400010100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741",
]
`;

exports[`Wallet with XCM config should return valid Polkadot calldata for Hydration -> AssetHub (CEX) USDT [usdt] transfer 1`] = `
[
"hydration-assethub_cex-usdt",
"0x5503040d02086b0d04010100a10f0404010300a10f043205011f0002093d000204010300a10f043205011f0204040d010000010100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741006b0004010100a10f041400040002043205011f0082380100130002043205011f0082380100000601c2e6e0810161a43208011f00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27dca1c0500140d01020400010100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741",
]
`;

exports[`Wallet with XCM config should return valid Polkadot calldata for Hydration -> AssetHub DED [ded] transfer 1`] = `
[
"hydration-assethub-ded",
Expand Down Expand Up @@ -903,6 +917,13 @@ exports[`Wallet with XCM config should return valid Polkadot calldata for Hydrat
]
`;

exports[`Wallet with XCM config should return valid Polkadot calldata for Hydration -> Polkadot (CEX) DOT [dot] transfer 1`] = `
[
"hydration-polkadot_cex-dot",
"0xc502040d020889000500000000e40b5402000000000000000000000004010200000100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741006b00040100041400040000000208af2f130000000208af2f000601027c3125253890050400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01140d01020400010100f959d131179b0264f98ac96d2c9c13c403129f5de93e52f3a611ccd4294d1741",
]
`;

exports[`Wallet with XCM config should return valid Polkadot calldata for Hydration -> Polkadot DOT [dot] transfer 1`] = `
[
"hydration-polkadot-dot",
Expand Down
21 changes: 21 additions & 0 deletions integration-tests/xcm-test/src/__snapshots__/e2e.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,20 @@ exports[`Wallet with XCM config should result in valid Polkadot transfer for Hyd
]
`;

exports[`Wallet with XCM config should result in valid Polkadot transfer for Hydration -> AssetHub (CEX) USDC [usdc] transfer 1`] = `
[
"hydration-assethub_cex-usdc",
"0x5503040d02086b0d04010100a10f0404010300a10f043205e51400025a62020204010300a10f043205e5140204040d0100000101007632da7afff71e425b32cd610f55c7fdd45a90c3bcbd1679e825c3139bdbea13006b0004010100a10f041400040002043205e5140082380100130002043205e51400823801000004040002043205e51400ce131a020001010088dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee140d010204000101007632da7afff71e425b32cd610f55c7fdd45a90c3bcbd1679e825c3139bdbea13",
]
`;

exports[`Wallet with XCM config should result in valid Polkadot transfer for Hydration -> AssetHub (CEX) USDT [usdt] transfer 1`] = `
[
"hydration-assethub_cex-usdt",
"0x5503040d02086b0d04010100a10f0404010300a10f043205011f00025a62020204010300a10f043205011f0204040d0100000101007632da7afff71e425b32cd610f55c7fdd45a90c3bcbd1679e825c3139bdbea13006b0004010100a10f041400040002043205011f0082380100130002043205011f00823801000004040002043205011f0046e419020001010088dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee140d010204000101007632da7afff71e425b32cd610f55c7fdd45a90c3bcbd1679e825c3139bdbea13",
]
`;

exports[`Wallet with XCM config should result in valid Polkadot transfer for Hydration -> AssetHub DED [ded] transfer 1`] = `
[
"hydration-assethub-ded",
Expand Down Expand Up @@ -630,6 +644,13 @@ exports[`Wallet with XCM config should result in valid Polkadot transfer for Hyd
]
`;

exports[`Wallet with XCM config should result in valid Polkadot transfer for Hydration -> Polkadot (CEX) DOT [dot] transfer 1`] = `
[
"hydration-polkadot_cex-dot",
"0xfc0489000500000000e87648170000000000000000000000040102000001007632da7afff71e425b32cd610f55c7fdd45a90c3bcbd1679e825c3139bdbea1300",
]
`;

exports[`Wallet with XCM config should result in valid Polkadot transfer for Hydration -> Polkadot DOT [dot] transfer 1`] = `
[
"hydration-polkadot-dot",
Expand Down
Loading

0 comments on commit 0736deb

Please sign in to comment.