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

feat: add multiversx example #169

Merged
merged 20 commits into from
Mar 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Try to get interchain transfer from mvx to evm working.
  • Loading branch information
raress96 committed Feb 14, 2024
commit 085a7a7f9026be6ed4ab1f56a3028c120e8246ff
60 changes: 36 additions & 24 deletions examples/multiversx/its-interchain-token/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,34 @@ async function execute(evmChain, wallet, options) {

const tokenId = await evmItsFactory.interchainTokenId(wallet.address, salt);

console.log(`Deploying interchain token [${name}, ${symbol}, ${decimals}] at ${evmChain.name}`);
await (await evmItsFactory.deployInterchainToken(
salt,
name,
symbol,
decimals,
amount,
wallet.address,
)).wait();

console.log(`Deploying remote interchain token from ${evmChain.name} to multiversx`);
await (await evmItsFactory.deployRemoteInterchainToken(
'',
salt,
wallet.address,
'multiversx',
fee,
{value: fee},
)).wait();

console.log('Token id', tokenId);

const evmTokenAddress = await evmIts.interchainTokenAddress(tokenId);

if (await evmChain.provider.getCode(evmTokenAddress) === '0x') {
console.log(`Deploying interchain token [${name}, ${symbol}, ${decimals}] at ${evmChain.name}`);
await (await evmItsFactory.deployInterchainToken(
salt,
name,
symbol,
decimals,
amount,
wallet.address,
)).wait();
}

if (!await client.its.getValidTokenIdentifier(tokenId)) {
console.log(`Deploying remote interchain token from ${evmChain.name} to multiversx`);
await (await evmItsFactory.deployRemoteInterchainToken(
'',
salt,
wallet.address,
'multiversx',
fee,
{ value: fee },
)).wait();
}

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
while (await evmChain.provider.getCode(evmTokenAddress) === '0x') {
await sleep(1000);
Expand All @@ -81,7 +85,8 @@ async function execute(evmChain, wallet, options) {

await interchainTransferEvmToMultiversX(evmChain, client, wallet, evmTokenAddress, tokenIdentifier, tokenId, amount, fee);

await interchainTransferMultiversXToEvm(client, evmChain, wallet, evmTokenAddress, tokenIdentifier, tokenId, amount);
// TODO: The EVM execute call fails here for some reason
// await interchainTransferMultiversXToEvm(client, evmChain, wallet, evmTokenAddress, tokenIdentifier, tokenId, amount);
}

async function interchainTransferEvmToMultiversX(evmChain, client, wallet, evmTokenAddress, tokenIdentifier, tokenId, amount, fee) {
Expand Down Expand Up @@ -132,15 +137,22 @@ async function interchainTransferMultiversXToEvm(client, evmChain, wallet, evmTo

console.log(`Sending ${amount} of token ${tokenIdentifier} from MultiversX to ${evmChain.name}`);

const success = await client.its.interchainTransfer(tokenId, evmChain.name, wallet.address, tokenIdentifier, amount);
// Gas value is not known for MultiversX, so we use 5 instead (will be multiplied by 100000000 in the MultiversXRelayer)
const success = await client.its.interchainTransfer(tokenId, evmChain.name, wallet.address, tokenIdentifier, amount, '5');
if (!success) {
throw new Error(`Could not send token from MultiversX to ${evmChain.name}...`);
}

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

while (Number(balance) == Number(await destinationToken.balanceOf(wallet.address))) {
await sleep(1000);
let retries = 0;
while (Number(balance) === Number(await destinationToken.balanceOf(wallet.address))) {
if (retries >= 5) {
throw new Error(`Did not receive ERC20 transfer on ${evmChain.name}`);
}

await sleep(6000);
retries++;
}

console.log('--- After ---');
Expand Down