Skip to content

Commit

Permalink
xcm config adjustments and not throw error when amount is 0 in networ…
Browse files Browse the repository at this point in the history
…k fee and relayer fee
  • Loading branch information
mmaurello committed Dec 20, 2024
1 parent 58e31f3 commit 9f06304
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/config/src/xcm-configs/moonriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const moonriverRoutes = new ChainRoutes({
destination: {
asset: movr,
chain: calamari,
balance: BalanceBuilder().substrate().system().account(),
balance: BalanceBuilder().substrate().assets().account(),
fee: {
amount: 0.001,
asset: movr,
Expand Down Expand Up @@ -144,7 +144,7 @@ export const moonriverRoutes = new ChainRoutes({
chain: khala,
balance: BalanceBuilder().substrate().assets().account(),
fee: {
amount: 0.0002,
amount: 0.001,
asset: movr,
},
},
Expand Down Expand Up @@ -683,7 +683,7 @@ export const moonriverRoutes = new ChainRoutes({
chain: bifrostKusama,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
amount: 0.0001,
amount: 0.1,
asset: vbnc,
},
min: AssetMinBuilder().assetRegistry().currencyMetadatas(),
Expand All @@ -707,7 +707,7 @@ export const moonriverRoutes = new ChainRoutes({
chain: bifrostKusama,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
amount: 0.0001,
amount: 0.001,
asset: vksm,
},
min: AssetMinBuilder().assetRegistry().currencyMetadatas(),
Expand All @@ -731,7 +731,7 @@ export const moonriverRoutes = new ChainRoutes({
chain: bifrostKusama,
balance: BalanceBuilder().substrate().tokens().accounts(),
fee: {
amount: 0.00000001,
amount: 0.1,
asset: vmovr,
},
min: AssetMinBuilder().assetRegistry().currencyMetadatas(),
Expand Down
5 changes: 4 additions & 1 deletion packages/mrl/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export async function getSourceData({
builder: route.source.balance,
chain: source,
});

const feeBalance = route.source.fee
? await getBalance({
address: sourceAddress,
Expand All @@ -87,6 +88,7 @@ export async function getSourceData({
});

const existentialDeposit = await getExistentialDeposit(source);

const min = await getAssetMin({
asset,
builder: route.source.min,
Expand Down Expand Up @@ -185,6 +187,7 @@ async function getFee({
if (ContractConfig.is(transfer)) {
return getContractFee({
address: sourceAddress,
balance,
chain: chain as EvmChain | EvmParachain,
contract: transfer,
destinationFee,
Expand Down Expand Up @@ -248,7 +251,7 @@ async function getWormholeFee({
const fee = await wh.getFee(config);

return AssetAmount.fromChainAsset(chain.getChainAsset(asset), {
amount: fee.relayFee ? fee.relayFee.amount + safetyAmount : 0n,
amount: fee?.relayFee ? fee.relayFee.amount + safetyAmount : 0n,
});
}

Expand Down
7 changes: 6 additions & 1 deletion packages/mrl/src/services/wormhole/WormholeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export class WormholeService {
this.#wh = wormholeFactory(chain);
}

async getFee(transfer: WormholeConfig): Promise<TransferQuote> {
async getFee(transfer: WormholeConfig): Promise<TransferQuote | undefined> {
const amount = transfer.args[1];
if (amount === 0n) {
return undefined;
}

const xfer = await this.#wh[transfer.func](...transfer.args);

return TokenTransfer.quoteTransfer(
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export async function getFee({
if (contract) {
return getContractFee({
address: sourceAddress,
balance,
chain: chain as EvmChain | EvmParachain,
contract,
destinationFee,
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/src/getTransferData/getTransferData.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export async function getExtrinsicFee({

export interface GetContractFeeParams {
address: string;
balance: AssetAmount;
chain: EvmChain | EvmParachain;
contract: ContractConfig;
destinationFee: AssetAmount;
Expand All @@ -316,13 +317,17 @@ export interface GetContractFeeParams {

export async function getContractFee({
address,
balance,
chain,
contract,
destinationFee,
feeBalance,
feeConfig,
}: GetContractFeeParams): Promise<AssetAmount> {
try {
if (balance.amount === 0n) {
return feeBalance.copyWith({ amount: 0n });
}
const evm = EvmService.create(chain);
const fee = await evm.getFee(address, contract);
const extra = feeConfig?.extra
Expand Down

0 comments on commit 9f06304

Please sign in to comment.