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

THEA Withdrawals #227

Merged
merged 13 commits into from
May 1, 2024
13 changes: 13 additions & 0 deletions .changeset/itchy-panthers-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@polkadex/thea": major
---

We have successfully added all the chains for cross chain transfer to Polkadex. In this task, we will be adding the withdraw logic for THEA so that user can withdraw thier assets from Polkadex network to other network.
ap211unitech marked this conversation as resolved.
Show resolved Hide resolved

1. Polkadex to AssetHub - USDT, DED, PINK, USDC
2. Polkadex to Astar - ASTR
3. Polkadex to Moonbeam - GLMR
4. Polkadex to Interlay - IBTC
5. Polkadex to Unique - UNQ
6. Polkadex to Polkadot - DOT
7. Polkadex to Phala - PHA
8 changes: 4 additions & 4 deletions apps/cross-chain/app/components/polkadotEco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { SubmittableExtrinsic } from "@polkadot/api/promise/types";
import { Signer } from "@polkadot/api/types";
import { getChainConnector, Thea } from "@polkadex/thea";

const SOURCE_CHAIN = "Polkadot";
const DESTINATION_CHAIN = "Polkadex";
const SELECTED_ASSET = "DOT";
const SOURCE_CHAIN = "Polkadex";
const DESTINATION_CHAIN = "AssetHub";
const SELECTED_ASSET = "USDT";

const fromAddress = "5GLFKUxSXTf8MDDKM1vqEFb5TuV1q642qpQT964mrmjeKz4w";
const toAddress = "5GLFKUxSXTf8MDDKM1vqEFb5TuV1q642qpQT964mrmjeKz4w";
const amount = 0.01;
const amount = 0.1;

export const PolkadotEco = () => {
const { getAllChains } = new Thea();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { polkadotXcm } from "./pallets/polkadotXcm";
import { xcmPallet } from "./pallets/xcmPallet";
import { xTokens } from "./pallets/xTokens";
import { xTransfer } from "./pallets/xTransfer";
import { theaExecuter } from "./pallets/theaExecuter";

export function ExtrinsicBuilderV2() {
return {
xTokens,
xTransfer,
xcmPallet,
polkadotXcm,
theaExecuter,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
XcmVersion,
ExtrinsicConfigBuilder,
ExtrinsicConfig,
} from "@moonbeam-network/xcm-builder";

import { getExtrinsicAccount } from "../ExtrinsicBuilder.utils";

import { toBeneficiary } from "./theaExecuter.utils";

const pallet = "theaExecutor";

const parachainWithdraw = () => {
const func = "parachainWithdraw";
return {
X2: () => ({
sufficient: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, asset, destination }) =>
new ExtrinsicConfig({
module: pallet,
func,
getArgs: () => {
const version = XcmVersion.v3;
const account = getExtrinsicAccount(address);
return [
asset,
amount,
toBeneficiary(version, destination, account),
null,
null,
true,
false,
];
},
}),
}),
insufficient: (
feeAssetId: string,
feeAmount: number
): ExtrinsicConfigBuilder => ({
build: ({ address, amount, asset, destination }) =>
new ExtrinsicConfig({
module: pallet,
func,
getArgs: () => {
const version = XcmVersion.v3;
const account = getExtrinsicAccount(address);
return [
asset,
amount,
toBeneficiary(version, destination, account),
feeAssetId,
feeAmount,
true,
false,
];
},
}),
}),
}),
};
};

export const theaExecuter = () => {
return {
parachainWithdraw,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { XcmVersion } from "@moonbeam-network/xcm-builder";
import { AnyChain } from "@moonbeam-network/xcm-types";

export const toBeneficiary = (
version: XcmVersion,
destination: AnyChain,
account: any
) => {
if (destination.key === "polkadot") {
return {
[version]: {
parents: 1,
interior: {
X1: account,
},
},
};
}

return {
[version]: {
parents: 1,
interior: {
X2: [
{
Parachain: destination.parachainId,
},
account,
],
},
},
};
ap211unitech marked this conversation as resolved.
Show resolved Hide resolved
};
Loading
Loading