Skip to content

Commit

Permalink
Pink registration (#1127)
Browse files Browse the repository at this point in the history
* Promotion Card for Lucky

* Promotion Card for Lucky

* Promotion Card for Lucky

* Promotion Card for Lucky

* Promotion Card for Lucky

* Add Pink in the assets

* Fix the origin asset id for PINK

* Manage another token to pay the fee for XCM transfers

* Manage another token to pay the fee for XCM transfers

* update pink image

* update the minimum for XCM transfers

* update the minimum for XCM transfers

* Revert "update the minimum for XCM transfers"

This reverts commit afc4fa3.

* Update src/v2/repositories/implementations/XcmRepository.ts

Co-authored-by: Roy <[email protected]>

* Add variables and add memo for 0.7 USDT

---------

Co-authored-by: Roy <[email protected]>
  • Loading branch information
GuiGou12358 and impelcrypto authored Mar 30, 2024
1 parent d2e320c commit ee08d58
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
Binary file added src/assets/img/token/pink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/modules/xcm/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ export const xcmToken = {
originChain: Chain.BIFROST_POLKADOT,
minBridgeAmount: '0.1',
},
{
symbol: 'PINK',
isNativeToken: false,
assetId: '18446744073709551633',
originAssetId: '23',
logo: require('/src/assets/img/token/pink.png'),
isXcmCompatible: true,
originChain: Chain.ASSET_HUB,
minBridgeAmount: '1',
},
],
[endpointKey.SHIDEN]: [
{
Expand Down
39 changes: 36 additions & 3 deletions src/v2/repositories/implementations/XcmRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,31 @@ export class XcmRepository implements IXcmRepository {
throw `Undefined extrinsic call ${extrinsic} with method ${method}`;
}

protected async fetchAssetConfig(
protected async fetchAssetConfigById(
source: XcmChain,
token: Asset,
tokenId: string,
endpoint: string
): Promise<{
parents: number;
interior: Interior;
}> {
const api = await this.apiFactory.get(endpoint);
const config = await api.query.xcAssetConfig.assetIdToLocation<Option<AssetConfig>>(token.id);
const config = await api.query.xcAssetConfig.assetIdToLocation<Option<AssetConfig>>(tokenId);
const formattedAssetConfig = JSON.parse(config.toString());
return formattedAssetConfig.v3;
}

protected async fetchAssetConfig(
source: XcmChain,
token: Asset,
endpoint: string
): Promise<{
parents: number;
interior: Interior;
}> {
return this.fetchAssetConfigById(source, token.id, endpoint);
}

protected isAstarNativeToken(token: Asset): boolean {
return !!this.astarTokens[token.metadata.symbol];
}
Expand Down Expand Up @@ -346,4 +357,26 @@ export class XcmRepository implements IXcmRepository {
return fixedAddress;
}
}

protected getFeeInformation(
token: Asset,
source: XcmChain,
destination: XcmChain
): {
feeAssetIsRequired: boolean;
feeAssetId: string;
feeAmount: number;
} {
if (token.metadata.name === 'PINK' && destination.name === Chain.ASSET_HUB) {
// Pink is not a sufficient token and cannot be used as gas fee in Asset Hub,
// it means we need to transfer another token to pay the fee and we will use USDT token.
const feeAssetIsRequired = true;
// 4294969280 is the USDT id
const feeAssetId = '4294969280';
// 700000 = 0.7 USDT
const feeAmount = 700000;
return { feeAssetIsRequired, feeAssetId, feeAmount };
}
return { feeAssetIsRequired: false, feeAssetId: '', feeAmount: 0 };
}
}
33 changes: 32 additions & 1 deletion src/v2/repositories/implementations/xcm/AstarXcmRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getPubkeyFromSS58Addr } from '@astar-network/astar-sdk-core';
import { XcmTokenInformation } from 'src/modules/xcm';
import { container } from 'src/v2/common';
import { ExtrinsicPayload, IApi, IApiFactory } from 'src/v2/integration';
import { Asset, ethWalletChains, XcmChain } from 'src/v2/models';
import { Asset, Chain, ethWalletChains, XcmChain } from 'src/v2/models';
import { Symbols } from 'src/v2/symbols';
import { XcmRepository } from '../XcmRepository';

Expand Down Expand Up @@ -92,6 +92,37 @@ export class AstarXcmRepository extends XcmRepository {
Unlimited: null,
};

const feeAssetInformation = this.getFeeInformation(token, from, to);

if (feeAssetInformation.feeAssetIsRequired) {
// we need to use another token for the fee
const fee = {
V3: {
fun: {
Fungible: new BN(feeAssetInformation.feeAmount),
},
id: {
Concrete: await this.fetchAssetConfigById(
from,
feeAssetInformation.feeAssetId,
endpoint
),
},
},
};

return await this.buildTxCall(
from,
endpoint,
'xTokens',
'transferMultiassetWithFee',
assets,
fee,
destination,
weightLimit
);
}

return await this.buildTxCall(
from,
endpoint,
Expand Down

0 comments on commit ee08d58

Please sign in to comment.