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 Enhancements - I #231

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
db2dae1
feat: polkadex to assethub DOT transfer
ap211unitech Apr 30, 2024
bd256a3
feat: assethub to assethub DOT transfer (not tested yet)
ap211unitech May 1, 2024
aead323
feat: interlay to polkadex for DOT
ap211unitech May 1, 2024
d6bc81d
fix: balance fetching for interlay
ap211unitech May 1, 2024
5144267
feat: interlay to polkadex for USDT
ap211unitech May 1, 2024
1791d0f
chore: minor change
ap211unitech May 1, 2024
7a073e3
chore: changeset added
ap211unitech May 1, 2024
b5a8c5e
Merge branch 'feat/thea-withdrawals' into feat/thea-enhancements-i
ap211unitech May 1, 2024
10e25ca
chore: added USDC and GLMR token for interlay
ap211unitech May 1, 2024
3f063a8
feat: interlay to polkadex for USDC
ap211unitech May 1, 2024
0b4026f
feat: interlay to polkadex for GLMR
ap211unitech May 1, 2024
8b0854b
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech May 1, 2024
c1093b9
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech May 15, 2024
3121b8e
Merge branch 'main' into feat/thea-enhancements-i
nuel77 May 27, 2024
e29f862
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech Jun 3, 2024
2b0045b
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech Jun 3, 2024
7973f8b
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech Jun 3, 2024
5ab8340
chore: tested GLMR transfer
ap211unitech Jun 4, 2024
2f3b5a9
feat: added BNC token for interlay
ap211unitech Jun 4, 2024
6a54ca6
feat: added vDOT token for interlay
ap211unitech Jun 4, 2024
3266dd0
chore: minor change
ap211unitech Jun 4, 2024
130880f
chore: removed DOT support for AssetHub to Polkadex
ap211unitech Jun 4, 2024
a5561b8
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech Jun 5, 2024
b05624a
chore: removed support for usdt & usdc
ap211unitech Jun 5, 2024
dcd4d42
Merge branch 'main' into feat/thea-enhancements-i
ap211unitech Jun 5, 2024
c10656b
feat: DOT transfer working
ap211unitech Jun 5, 2024
5ab8ea1
feat: GLMR transfer from Polkadex to Interlay
ap211unitech Jun 6, 2024
662db21
feat: BNC transfer from Polkadex to Interlay
ap211unitech Jun 6, 2024
0b64367
feat: DOT transfer from Polkadex to Interlay
ap211unitech Jun 6, 2024
f570877
feat: vDOT transfer from Polkadex to Interlay
ap211unitech Jun 6, 2024
915a540
chore: minor change
ap211unitech Jun 6, 2024
8f44c82
chore: files cleanup
ap211unitech Jun 6, 2024
c2197fd
chore: updated changeset
ap211unitech Jun 6, 2024
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
5 changes: 5 additions & 0 deletions .changeset/tall-schools-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@polkadex/thea": minor
---

In this PR, we will be allowing DOT transfer from AssetHub to Polkadex and DOT, USDT transfer from Interlay to Polkadex network.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const limitedReserveTransferAssets = () => {
const func = "limitedReserveTransferAssets";
return {
X1: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, asset, destination, palletInstance }) =>
build: ({ address, amount, destination }) =>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The build function with the old parameters { address, amount, asset, destination, palletInstance } is still present in packages/thea/src/config/substrate/builders/pallets/xTokens.ts. This indicates that the removal of these parameters in polkadotXcm.ts might not be consistent across the codebase.

  • packages/thea/src/config/substrate/builders/pallets/xTokens.ts:
    • Line(s) containing the old parameters:
      • build: ({ address, amount, asset, destination, palletInstance }) =>

Please review and update the xTokens.ts file to ensure consistency.

Analysis chain

Verify the removal of asset and palletInstance parameters in the build function of X1.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the removal of parameters in other parts of the codebase.

# Test: Search for the usage of `build` function of `X1` with old parameters. Expect: No occurrences.
rg --type typescript $'build: \({ address, amount, asset, destination, palletInstance }\)'

Length of output: 251



Script:

#!/bin/bash
# Description: Verify the removal of parameters in other parts of the codebase.

# Test: Search for the usage of `build` function of `X1` with old parameters. Expect: No occurrences.
rg --type typescript 'build: \(\{ address, amount, asset, destination, palletInstance \}\)'

Length of output: 128



Script:

#!/bin/bash
# Description: Verify the removal of parameters in other parts of the codebase.

# Test: Search for the usage of `build` function of `X1` with old parameters. Expect: No occurrences.
rg --type ts 'build: \(\{ address, amount, asset, destination, palletInstance \}\)'

Length of output: 359


Tip

Codebase Verification

The here method in reserveTransferAssets appears to be duplicated across multiple files:

  • packages/thea/src/config/substrate/builders/pallets/xTokens.ts
  • packages/thea/src/config/substrate/builders/pallets/polkadotXcm.ts
  • packages/thea/src/config/substrate/builders/pallets/xTransfer.ts
  • packages/thea/src/config/substrate/builders/pallets/xcmPallet.ts

Please review these instances to ensure there is no unnecessary duplication and consider refactoring if needed.

Analysis chain

Review the addition of the new here method in reserveTransferAssets for potential duplication with existing methods.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for potential duplication of the `here` method in `reserveTransferAssets`.

# Test: Search for similar methods in the codebase. Expect: No similar methods.
rg --type typescript $'here: \(\) => ExtrinsicConfigBuilder'

Length of output: 96



Script:

#!/bin/bash
# Description: Check for potential duplication of the `here` method in `reserveTransferAssets`.

# Test: Search for similar methods in the codebase. Expect: No similar methods.
rg --type ts $'here: \(\) => ExtrinsicConfigBuilder'

Length of output: 53



Script:

#!/bin/bash
# Description: Check for potential duplication of the `here` method in `reserveTransferAssets`.

# Test: Search for similar methods in the codebase. Expect: No similar methods.
rg --type ts 'here: \(\) =>'

Length of output: 30



Script:

#!/bin/bash
# Description: Check for potential duplication of the `here` method in `reserveTransferAssets`.

# Test: Search for similar methods in the codebase. Expect: No similar methods.
rg --type ts 'here:'

Length of output: 778

new ExtrinsicConfig({
module: pallet,
func,
Expand Down
18 changes: 18 additions & 0 deletions packages/thea/src/config/substrate/builders/pallets/xTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ const evmTransfer = (): ExtrinsicConfigBuilder => ({

const transferMultiasset = (originParachainId?: number) => {
return {
X2: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, destination }) =>
new ExtrinsicConfig({
module: pallet,
func: "transferMultiasset",
getArgs: () => {
const version = XcmVersion.v2;
const account = getExtrinsicAccount(address);
return [
{
[version]: toAsset("Here", amount),
},
toDest(version, destination, account),
"Unlimited",
];
},
}),
}),
X3: (): ExtrinsicConfigBuilder => ({
build: ({ address, amount, asset, destination, palletInstance }) =>
new ExtrinsicConfig({
Expand Down
34 changes: 34 additions & 0 deletions packages/thea/src/config/substrate/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,46 @@ export const interlay = new Parachain({
id: { Token: intr.originSymbol },
metadataId: 0,
},
{
asset: dot,
decimals: 10,
id: { Token: dot.originSymbol },
metadataId: 0,
},
{
asset: usdt,
decimals: 6,
id: { ForeignAsset: 2 },
metadataId: 0,
},
{
asset: usdc,
decimals: 6,
id: { ForeignAsset: 12 },
metadataId: 0,
},
{
asset: glmr,
decimals: 18,
id: { ForeignAsset: 10 },
metadataId: 0,
},
{
asset: ibtc,
decimals: 8,
id: { Token: ibtc.originSymbol },
metadataId: 0,
},
{
asset: bnc,
decimals: 12,
id: { ForeignAsset: 11 },
},
{
asset: vdot,
decimals: 10,
id: { ForeignAsset: 3 },
},
],
ecosystem: Ecosystem.Polkadot,
genesisHash: INTERLAY_GENESIS,
Expand Down
70 changes: 69 additions & 1 deletion packages/thea/src/config/substrate/config/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BalanceBuilder } from "@moonbeam-network/xcm-builder";

import { ExtrinsicBuilderV2 } from "../builders";
import { interlay, polkadex } from "../chains";
import { ibtc, intr } from "../assets";
import { ibtc, intr, dot, glmr, bnc, vdot } from "../assets";

const toPolkadex: AssetConfig[] = [
new AssetConfig({
Expand All @@ -21,6 +21,74 @@ const toPolkadex: AssetConfig[] = [
balance: BalanceBuilder().substrate().tokens().accounts(),
},
}),

// Tested & working
new AssetConfig({
asset: dot,
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: polkadex,
destinationFee: {
amount: 0.06,
asset: dot,
balance: BalanceBuilder().substrate().assets().account(),
},
extrinsic: ExtrinsicBuilderV2().xTokens().transferMultiasset().X2(),
fee: {
asset: intr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
}),

// Tested & working
new AssetConfig({
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: polkadex,
destinationFee: {
amount: 0.0035,
asset: glmr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
extrinsic: ExtrinsicBuilderV2().xTokens().transfer().X2(),
fee: {
asset: intr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
}),

// Tested & working
new AssetConfig({
asset: bnc,
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: polkadex,
destinationFee: {
amount: 0.00055,
asset: bnc,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
extrinsic: ExtrinsicBuilderV2().xTokens().transfer().X2(),
fee: {
asset: intr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
}),

// Tested & working
new AssetConfig({
asset: vdot,
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: polkadex,
destinationFee: {
amount: 0.00000007,
asset: vdot,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
extrinsic: ExtrinsicBuilderV2().xTokens().transfer().X3(),
fee: {
asset: intr,
balance: BalanceBuilder().substrate().tokens().accounts(),
},
}),
];

export const interlayConfig = new ChainConfig({
Expand Down
91 changes: 91 additions & 0 deletions packages/thea/src/config/substrate/config/polkadex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,97 @@ const toInterlay: AssetConfig[] = [
xcmDeliveryFeeAmount,
},
}),

// Tested & Working
new AssetConfig({
asset: dot,
balance: BalanceBuilder().substrate().assets().account(),
destination: interlay,
destinationFee: {
amount: 0.05,
asset: dot,
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilderV2()
.theaExecuter()
.parachainWithdraw()
.X2()
.sufficient(),
min: AssetMinBuilder().assets().asset(),
fee: {
asset: pdex,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount,
},
}),

// Tested & Working
new AssetConfig({
asset: glmr,
balance: BalanceBuilder().substrate().assets().account(),
destination: interlay,
destinationFee: {
amount: 0.045,
asset: glmr,
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilderV2()
.theaExecuter()
.parachainWithdraw()
.X2()
.sufficient(),
min: AssetMinBuilder().assets().asset(),
fee: {
asset: pdex,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount,
},
}),

// Tested & Working
new AssetConfig({
asset: bnc,
balance: BalanceBuilder().substrate().assets().account(),
destination: interlay,
destinationFee: {
amount: 0.05,
asset: bnc,
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilderV2()
.theaExecuter()
.parachainWithdraw()
.X2()
.sufficient(),
min: AssetMinBuilder().assets().asset(),
fee: {
asset: pdex,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount,
},
}),

new AssetConfig({
asset: vdot,
balance: BalanceBuilder().substrate().assets().account(),
destination: interlay,
destinationFee: {
amount: 0.00000007,
asset: vdot,
balance: BalanceBuilder().substrate().system().account(),
},
extrinsic: ExtrinsicBuilderV2()
.theaExecuter()
.parachainWithdraw()
.X2()
.sufficient(),
min: AssetMinBuilder().assets().asset(),
fee: {
asset: pdex,
balance: BalanceBuilder().substrate().system().account(),
xcmDeliveryFeeAmount,
},
}),
];

const toBifrost: AssetConfig[] = [
Expand Down
4 changes: 1 addition & 3 deletions packages/thea/src/sdk/substrate/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ export class Interlay implements BaseChainAdapter {
const api = await getPolkadotApi(this.chain.ws);

const balances = assets.map(async (a): Promise<AssetAmount> => {
const b = await api.query.tokens.accounts(address, {
Token: a.ticker,
});
const b = await api.query.tokens.accounts(address, a.id);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down