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

fix: support the new xtokens interface on interlay/kintsugi #28

Merged
merged 1 commit into from
Mar 10, 2023
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
19 changes: 17 additions & 2 deletions src/adapters/interlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { ISubmittableResult } from "@polkadot/types/types";
import { BalanceAdapter, BalanceAdapterConfigs } from "../balance-adapter";
import { BaseCrossChainAdapter } from "../base-chain-adapter";
import { ChainName, chains } from "../configs";
import { ApiNotFound, CurrencyNotFound } from "../errors";
import {
ApiNotFound,
CurrencyNotFound,
DestinationWeightNotFound,
} from "../errors";
import {
BalanceData,
BasicToken,
Expand Down Expand Up @@ -216,6 +220,17 @@ class BaseInterlayAdapter extends BaseCrossChainAdapter {
throw new CurrencyNotFound(token);
}

// use "Unlimited" if the xToken.transfer's fourth parameter version supports it
const destWeight =
this.api.tx.xTokens.transfer.meta.args[3].type.toString() ===
"XcmV2WeightLimit"
? "Unlimited"
: this.getDestWeight(token, to);

if (destWeight === undefined) {
throw new DestinationWeightNotFound(this.chain.id, to, token);
}

return this.api.tx.xTokens.transfer(
tokenId,
amount.toChainData(),
Expand All @@ -231,7 +246,7 @@ class BaseInterlayAdapter extends BaseCrossChainAdapter {
},
},
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.getDestWeight(token, to)!.toString()
destWeight
);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ export class NoCrossChainAdapterFound extends Error {
this.name = "NoCrossChainAdapterFound";
}
}

export class DestinationWeightNotFound extends Error {
constructor(source: string, destination: string, token: string) {
super();

this.message = `Can't find ${source} addapter's destination weight for ${destination} destination sending ${token} token.`;
this.name = "DestinationWeightNotFound";
}
}