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

Existential Amount for Cross Chain transfer #267

Merged
merged 4 commits into from
May 27, 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
6 changes: 6 additions & 0 deletions .changeset/great-kings-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@polkadex/thea": minor
"@polkadex/ux": minor
---

Added a new enum for ChainType and minor UI fix
2 changes: 1 addition & 1 deletion packages/thea/src/config/substrate/config/polkadex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const toAstar: AssetConfig[] = [
balance: BalanceBuilder().substrate().assets().account(),
destination: astar,
destinationFee: {
amount: 0, // TODO: Change it later
amount: 0.05,
asset: astr,
balance: BalanceBuilder().substrate().system().account(),
},
Expand Down
11 changes: 9 additions & 2 deletions packages/thea/src/config/substrate/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { AnyChain, ChainAssetsData } from "@moonbeam-network/xcm-types";
import {
AnyChain,
ChainAssetsData,
ChainType as MoonbeamChainType,
} from "@moonbeam-network/xcm-types";

import { Asset, ChainType, Chain } from "../types";

Expand All @@ -8,7 +12,10 @@ export const changeSubstrateToBaseChain = (chain: AnyChain): Chain => ({
genesis: chain.genesisHash,
logo: chain.name,
name: chain.name,
type: ChainType.Substrate,
type:
chain.type === MoonbeamChainType.EvmParachain
? ChainType.EvmSubstrate
: ChainType.Substrate,
isTestnet: chain.isTestChain,
});

Expand Down
1 change: 1 addition & 0 deletions packages/thea/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum ChainType {
Substrate,
EvmSubstrate,
Evm,
}

Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/assetHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class AssetHub implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class AssetHub implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/astar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Astar implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Astar implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/bifrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Bifrost implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Bifrost implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Interlay implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Interlay implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Moonbeam implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Moonbeam implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/phala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Phala implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Phala implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/polkadex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Polkadex implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Polkadex implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Polkadot implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Polkadot implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
9 changes: 9 additions & 0 deletions packages/thea/src/sdk/substrate/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ export class Unique implements BaseChainAdapter {
),
};

const sourceFeeExistential: AssetAmount = {
ticker: transferConfig.source.existentialDeposit.originSymbol,
amount: +Utils.formatUnits(
transferConfig.source.existentialDeposit.amount,
transferConfig.source.existentialDeposit.decimals
),
};

const destinationFee: AssetAmount = {
ticker: transferConfig.destination.fee.originSymbol,
amount: +Utils.formatUnits(
Expand All @@ -157,6 +165,7 @@ export class Unique implements BaseChainAdapter {
destinationFee,
sourceFeeBalance,
destinationFeeBalance,
sourceFeeExistential,

transfer: async <T>(amount: number): Promise<T> => {
const api = await getPolkadotApi(this.chain.ws);
Expand Down
3 changes: 2 additions & 1 deletion packages/thea/src/sdk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export type TransferConfig = {
min: AssetAmount;
max: AssetAmount;
sourceFee: AssetAmount;
destinationFee: AssetAmount;
sourceFeeBalance: AssetAmount;
sourceFeeExistential: AssetAmount;
destinationFee: AssetAmount;
destinationFeeBalance: AssetAmount;

// Do the actual transfer
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Primary = forwardRef<ElementRef<"input">, InputWithContainerProps>(
{...containerProps}
>
<div className="flex flex-1 items-center justify-between gap-2 pl-3 pr-2">
<div className="flex items-center gap-2">
<div className="flex flex-1 items-center gap-2">
{LabelComponent}
<Base
ref={ref}
Expand Down
Loading