Skip to content

Commit

Permalink
feat: support xcm v4
Browse files Browse the repository at this point in the history
  • Loading branch information
qwer951123 committed May 8, 2024
1 parent 947a9ee commit f73f8fe
Show file tree
Hide file tree
Showing 5 changed files with 483 additions and 417 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polkawallet/bridge",
"version": "0.1.6-3",
"version": "0.1.6",
"description": "polkawallet bridge sdk",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -25,23 +25,23 @@
},
"peerDependencies": {
"@acala-network/api": "^5",
"@polkadot/api": "^10",
"@polkadot/api": "^11",
"ethers": "^5"
},
"resolutions": {
"@acala-network/api": "^5.1.1",
"@acala-network/sdk": "^4.1.9-7",
"@acala-network/sdk-core": "^4.1.9-7",
"@polkadot/api": "^10.9.1",
"@polkadot/types": "^10.9.1"
"@polkadot/api": "^11.0.2",
"@polkadot/types": "^11.0.2"
},
"dependencies": {
"@acala-network/api": "^5",
"@acala-network/sdk": "^4.1.9-7",
"@acala-network/sdk-core": "^4.1.9-7",
"@polkadot/api": "^10.9.1",
"@polkadot/api": "^11.0.2",
"@polkadot/apps-config": "^0.133.1",
"@polkadot/types": "^10.9.1",
"@polkadot/types": "^11.0.2",
"axios": "^0.27.2",
"ethers": "^5",
"lodash": "^4.17.20"
Expand All @@ -55,5 +55,5 @@
"jest": "^28.1.1",
"typescript": "^4.7.4"
},
"stableVersion": "0.1.6-2"
"stableVersion": "0.1.5"
}
18 changes: 9 additions & 9 deletions src/adapters/acala/acala.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SubmittableExtrinsic } from "@polkadot/api/types";
import { ISubmittableResult } from "@polkadot/types/types";
import { ApiPromise, WsProvider } from "@polkadot/api";

describe.skip("acala-adapter", () => {
describe("acala-adapter", () => {
jest.setTimeout(50000);

let bridge: Bridge;
Expand Down Expand Up @@ -37,8 +37,8 @@ describe.skip("acala-adapter", () => {
const moonriver = new MoonriverAdapter();
const assetHubKusama = new AssetHubKusamaAdapter();

const karuraApi = new ApiPromise({ provider: new WsProvider('wss://karura.api.onfinality.io/public-ws') });
const kusmaApi = new ApiPromise({ provider: new WsProvider('wss://kusama.api.onfinality.io/public-ws') });
const karuraApi = new ApiPromise({ provider: new WsProvider('wss://karura-rpc-1.aca-api.network') });
const kusmaApi = new ApiPromise({ provider: new WsProvider('wss://kusama-public-rpc.blockops.network/ws') });
const assetHubApi = new ApiPromise({ provider: new WsProvider('wss://statemine-rpc.dwellir.com') });

await karura.init(karuraApi);
Expand Down Expand Up @@ -86,10 +86,10 @@ describe.skip("acala-adapter", () => {
});

// DONT MODIFY THIS, THE OBJECT IS VALID, UNLESS YOU KNOW WHAT YOU ARE DOING
const location = api.createType('XcmVersionedMultiLocation', {
V3: {
const location = api.createType('XcmVersionedLocation', {
V4: {
parents: '1',
interior: { X1: { AccountId32: { id: addressId, network: null } } }
interior: { X1: [{ AccountId32: { id: addressId, network: null } }] }
}
});

Expand Down Expand Up @@ -123,7 +123,7 @@ describe.skip("acala-adapter", () => {
});

// DONT MODIFY THIS, THE OBJECT IS VALID, UNLESS YOU KNOW WHAT YOU ARE DOING
const location = api.createType('XcmVersionedMultiLocation', {
const location = api.createType('XcmVersionedLocation', {
V3: {
parents: "1",
interior: {
Expand Down Expand Up @@ -171,7 +171,7 @@ describe.skip("acala-adapter", () => {
});

// DONT MODIFY THIS, THE OBJECT IS VALID, UNLESS YOU KNOW WHAT YOU ARE DOING
const location = api.createType('XcmVersionedMultiLocation', {
const location = api.createType('XcmVersionedLocation', {
V3: {
parents: "1",
interior: {
Expand All @@ -184,7 +184,7 @@ describe.skip("acala-adapter", () => {
});

// DONT MODIFY THIS, THE OBJECT IS VALID, UNLESS YOU KNOW WHAT YOU ARE DOING
const assets = api.createType('XcmVersionedMultiAsset', {
const assets = api.createType('XcmVersionedAsset', {
V3: {
fun: {
Fungible: amount.toChainData(),
Expand Down
4 changes: 3 additions & 1 deletion src/utils/check-message-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AnyApi } from "@acala-network/sdk-core";
export type XCMVersion = "V1" | "V3" | "V4";

export function checkMessageVersion(api: AnyApi) {
return "V4";

let version: XCMVersion = "V1";

try {
Expand All @@ -28,7 +30,7 @@ export function checkMessageVersion(api: AnyApi) {
}

try {
api?.createType("StagingXcmVersionedLocation") as any;
api?.createType("XcmVersionedLocation") as any;

version = "V4";
} catch (e) {
Expand Down
13 changes: 11 additions & 2 deletions src/utils/xtokens-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ function createToRelayChainDestParam(version: XCMVersion, accountId: string) {
};
}

if (version === "V4") {
return {
[version]: {
parents: 1,
interior: { X1: [{ AccountId32: { id: accountId } }] },
},
};
}

return {
[version]: {
parents: 1,
Expand Down Expand Up @@ -58,9 +67,9 @@ export function createXTokensDestParam(
};
}

// for message version v3
// for message version v3 & v4
return {
V3: {
[version]: {
parents: 1,
interior: {
X2: [
Expand Down
Loading

0 comments on commit f73f8fe

Please sign in to comment.