Skip to content

Commit

Permalink
pass isAutomatic as parameter to transfer function
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Oct 17, 2024
1 parent fccf158 commit b3dc342
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 24 deletions.
59 changes: 43 additions & 16 deletions examples/mrl-simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ main()
.finally(() => process.exit());

async function main() {
// await fromFantomToPeaq(ftm, 0.011);
// await fromFantomToMoonbase(ftm, 0.01);
// await fromMoonbaseToFantom(dev, 0.01);
// await fromPeaqToFantom(ftmwh, 0.1);
await fromPeaqEvmToFantom(ftmwh, 0.12);
const isAutomatic = true;
// await fromFantomToPeaq(ftm, 0.011, isAutomatic);
// await fromFantomToMoonbase(ftm, 0.01, isAutomatic);
// await fromMoonbaseToFantom(ftmwh, 0.01, isAutomatic);
await fromPeaqToFantom(agng, 20, isAutomatic);
// await fromPeaqEvmToFantom(ftmwh, 1.5, isAutomatic);
}

async function fromFantomToPeaq(asset: Asset, amount: number) {
async function fromFantomToPeaq(
asset: Asset,
amount: number,
isAutomatic: boolean,
) {
const walletClient = createWalletClient({
account,
chain: fantomTestnet.getViemChain(),
transport: http(),
});

const data = await Mrl()
.setSource(fantomTestnet)
.setDestination(peaqAlphanet)
Expand All @@ -73,13 +84,17 @@ async function fromFantomToPeaq(asset: Asset, amount: number) {

console.log(data);

await data.transfer(amount, {
await data.transfer(amount, isAutomatic, {
polkadotSigner: pair,
evmSigner: walletClient,
});
}

async function fromFantomToMoonbase(asset: Asset, amount: number) {
async function fromFantomToMoonbase(
asset: Asset,
amount: number,
isAutomatic: boolean,
) {
const walletClient = createWalletClient({
account,
chain: fantomTestnet.getViemChain(),
Expand All @@ -89,21 +104,25 @@ async function fromFantomToMoonbase(asset: Asset, amount: number) {
const data = await Mrl()
.setSource(fantomTestnet)
.setDestination(moonbaseAlpha)
.setAsset(dev)
.setAsset(asset)
.setAddresses({
sourceAddress: account.address,
destinationAddress: account.address,
});

console.log(data);

await data.transfer(0.5, {
await data.transfer(amount, isAutomatic, {
polkadotSigner: pair,
evmSigner: walletClient,
});
}

async function fromMoonbaseToFantom(asset: Asset, amount: number) {
async function fromMoonbaseToFantom(
asset: Asset,
amount: number,
isAutomatic: boolean,
) {
const walletClient = createWalletClient({
account,
chain: moonbaseAlphaViem,
Expand All @@ -120,13 +139,17 @@ async function fromMoonbaseToFantom(asset: Asset, amount: number) {

console.log(data);

await data.transfer(amount, {
await data.transfer(amount, isAutomatic, {
polkadotSigner: pair,
evmSigner: walletClient,
});
}

async function fromPeaqToFantom(asset: Asset, amount: number) {
async function fromPeaqToFantom(
asset: Asset,
amount: number,
isAutomatic: boolean,
) {
const data = await Mrl()
.setSource(peaqAlphanet)
.setDestination(fantomTestnet)
Expand All @@ -138,12 +161,16 @@ async function fromPeaqToFantom(asset: Asset, amount: number) {

console.log(data);

await data.transfer(amount, {
await data.transfer(amount, isAutomatic, {
polkadotSigner: pair,
});
}

async function fromPeaqEvmToFantom(asset: Asset, amount: number) {
async function fromPeaqEvmToFantom(
asset: Asset,
amount: number,
isAutomatic: boolean,
) {
const walletClient = createWalletClient({
account,
chain: peaqEvmAlphanet.getViemChain(),
Expand All @@ -161,5 +188,5 @@ async function fromPeaqEvmToFantom(asset: Asset, amount: number) {

console.log(data);

await data.transfer(amount, { evmSigner: walletClient });
await data.transfer(amount, isAutomatic, { evmSigner: walletClient });
}
2 changes: 1 addition & 1 deletion packages/config/src/mrl-configs/fantomTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const fantomTestnetRoutes = new MrlChainRoutes({
},
},
mrl: {
isAutomaticPossible: false, // TODO
isAutomaticPossible: true,
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChain: {
asset: ftmwh,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/mrl-configs/moonbaseAlpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const moonbaseAlphaRoutes = new MrlChainRoutes({
},
},
mrl: {
isAutomaticPossible: false, // TODO
isAutomaticPossible: true,
transfer: MrlBuilder().wormhole().wormhole().tokenTransfer(),
moonChain: {
asset: ftmwh,
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/mrl-configs/peaqEvmAlphanet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const peaqEvmAlphanetRoutes = new MrlChainRoutes({
},
},
mrl: {
isAutomaticPossible: false, // TODO
isAutomaticPossible: true,
transfer: MrlBuilder()
.wormhole()
.contract()
Expand Down
5 changes: 5 additions & 0 deletions packages/mrl/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export async function getSourceData({
asset: balance,
destinationAddress,
feeAsset: feeBalance,
isAutomatic: route.mrl.isAutomaticPossible,
route,
sourceAddress,
});
Expand All @@ -113,6 +114,7 @@ export async function getSourceData({
transfer,
asset: balance,
feeAsset: feeBalance,
isAutomatic: route.mrl.isAutomaticPossible,
destinationAddress,
route,
sourceAddress,
Expand All @@ -128,6 +130,7 @@ export async function getSourceData({
return {
balance,
chain: source,
destinationFee,
destinationFeeBalance,
moonChainFeeBalance,
existentialDeposit,
Expand Down Expand Up @@ -202,6 +205,7 @@ export async function getRelayerFee({
chain,
destinationAddress,
feeAsset,
isAutomatic,
route,
sourceAddress,
transfer,
Expand All @@ -215,6 +219,7 @@ export async function getRelayerFee({
asset,
destinationAddress,
feeAsset,
isAutomatic,
route,
sourceAddress,
});
Expand Down
2 changes: 2 additions & 0 deletions packages/mrl/src/getTransferData/getTransferData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export async function getTransferData({
source: sourceData,
async transfer(
amount,
isAutomatic,
{ evmSigner, polkadotSigner }: Partial<Signers>,
): Promise<string[]> {
const source = route.source.chain;
Expand All @@ -122,6 +123,7 @@ export async function getTransferData({
asset,
destinationAddress,
feeAsset,
isAutomatic,
route,
sourceAddress,
});
Expand Down
9 changes: 8 additions & 1 deletion packages/mrl/src/getTransferData/getTransferData.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface BuildTransferParams {
asset: AssetAmount;
destinationAddress: string;
feeAsset: AssetAmount;
isAutomatic: boolean;
route: AssetRoute;
sourceAddress: string;
}
Expand All @@ -111,6 +112,11 @@ export async function buildTransfer(params: BuildTransferParams) {
`MrlConfigBuilder is not defined for source chain ${route.source.chain.name} and asset ${route.source.asset.originSymbol}`,
);
}
if (params.isAutomatic && !route.mrl.isAutomaticPossible) {
throw new Error(
`Route from source chain ${route.source.chain.name} and asset ${route.source.asset.originSymbol} does not allow the automatic option`,
);
}
const builderParams = await getMrlBuilderParams(params);

return route.mrl.transfer.build({
Expand All @@ -125,6 +131,7 @@ export async function getMrlBuilderParams({
asset,
destinationAddress,
feeAsset,
isAutomatic,
route,
sourceAddress,
}: BuildTransferParams): Promise<MrlBuilderParams> {
Expand All @@ -151,7 +158,7 @@ export async function getMrlBuilderParams({
destinationAddress,
destinationApi,
fee: feeAsset,
isAutomatic: route.mrl.isAutomaticPossible,
isAutomatic,
moonApi,
moonAsset: moonChain.nativeAsset,
moonChain,
Expand Down
1 change: 1 addition & 0 deletions packages/mrl/src/mrl.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TransferData {
source: SourceTransferData;
transfer(
amount: bigint | number | string,
isAutomatic: boolean,
signers: Signers,
): Promise<string[]>;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/tests/acceptance/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const config: { chain: AnyParachain; address: string }[] = [
{ chain: centrifuge, address: substrateAddress },
{ chain: hydrationAlphanet, address: hydrationAddress },
{ chain: hydrationAlphanet, address: substrateAddress },
// {
// chain: moonbaseBeta,
// address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e84405e',
// },
{
chain: moonbaseBeta,
address: '0x4E82143Af671Cc8201Bc7efCBbCED3A69e84405e',
},
{ chain: moonbaseAlpha, address: moonEvmAddress },
{ chain: peaqEvmAlphanet, address: moonEvmAddress },
{ chain: peaqAlphanet, address: substrateAddress },
Expand Down

0 comments on commit b3dc342

Please sign in to comment.