Closed MarcoMandar closed 4 months ago
Would need to see more of the code to say why this is happening
The complaint is coming from this section:
https://github.com/wormhole-foundation/wormhole-sdk-ts/blob/0.6.5/sdk/src/index.ts#L29-L38
likely that the platforms
var is not correct
Are you importing evm
as
import evm from '@wormhole-foundation/sdk/evm'
import { ethers } from 'ethers';
import evm from '@wormhole-foundation/sdk/evm';
import { getSigner, SignerStuff } from './helpers';
import { Chain, TokenTransfer, Network, TokenId, Wormhole, wormhole, } from '@wormhole-foundation/sdk';
const ETH_NETWORK_URL = process.env.HTTP_PROVIDER_MAINNET const PRIVATE_KEY = process.env.PRIVATE_KEY
const provider = new ethers.JsonRpcProvider(ETH_NETWORK_URL); const wallet = new ethers.Wallet(PRIVATE_KEY, provider); const providerOasis = new ethers.JsonRpcProvider('https://emerald.oasis.dev');
const USDT_OASIS_CONTRACT_ADDRESS = '0xdc19a122e268128b5ee20366299fc7b5b199c8e3';
export async function executeTransferUSDTfromEthToOasis(amount: string) { try { const wh = await wormhole('Mainnet', [evm]); const destinationchain = wh.getChain('Ethereum'); const sourcechain = wh.getChain('Oasis');
const leg1 = await getSigner(sourcechain);
const leg2 = await getSigner(destinationchain);
const token: TokenId = Wormhole.tokenId(
sourcechain.chain,
USDT_OASIS_CONTRACT_ADDRESS,
);
const amt = ethers.parseUnits(amount, 6);
try {
const route1 = await tokenTransfer(wh, {
token: token,
amount: amt,
source: leg1,
destination: leg2,
delivery: {
automatic: false,
},
});
console.log('Route 1 (External => Cosmos)', route1);
} catch (e) {
console.error('Route 1 Failed', e);
}
} catch (e) { console.error(e); } }
export async function tokenTransfer
const quote = await TokenTransfer.quoteTransfer( wh, route.source.chain, route.destination.chain, xfer.transfer, ); // console.log(quote);
if (xfer.transfer.automatic && quote.destinationToken.amount < 0) throw 'The amount requested is too low to cover the fee and any native gas requested.';
// 1) Submit the transactions to the source chain, passing a signer to sign any txns console.log('Starting transfer'); // const srcChain = wh.getChain(route.source.chain.chain); // console.log('srcChain', srcChain); // const tb = await srcChain.getTokenBridge(); // console.log('tb', tb);
// check gas limit
const balance = await xfer.fromChain.getBalance(
route.source.address.address.toString(),
route.token.address,
);
// console.log('balance', balance);
const srcTxids = await xfer.initiateTransfer(route.source.signer);
console.log(Started transfer:
, srcTxids);
// If automatic, we're done if (route.delivery?.automatic) return xfer;
// 2) Wait for the VAA to be signed and ready (not required for auto transfer)
console.log('Getting Attestation');
const attestIds = await xfer.fetchAttestation(60_000);
console.log(Got Attestation:
, attestIds);
// 3) Redeem the VAA on the dest chain
console.log('Completing Transfer');
const destTxids = await xfer.completeTransfer(route.destination.signer);
console.log(Completed Transfer:
, destTxids);
// EXAMPLE_TOKEN_TRANSFER
// If no need to send back, dip if (!roundTrip) return xfer;
const { destinationToken: token } = quote; return await tokenTransfer(wh, { ...route, token: token.token, amount: token.amount, source: route.destination, destination: route.source, }); } this is the code
This looks ok, might be related to the way nestjs handles dynamic imports
As an experiment, can you please bump to 0.6.6
and use the static imports?
eg
import evm from "@wormhole-foundation/sdk/platforms/evm"
//...
// This may be subject to the same issue as the dynamic loader for the platform but
// the error should be different, complaining about "No protocol registered..."
await loadProtocols(evm, ["TokenBridge", "WormholeCore"]);
const wh = new Wormhole("Mainnet", [evm.Platform]);
//...
Failed Error: Token Bridge not supported on Oasis at Function.validateTransferDetails the issue with the first error was fixed, I am getting this now from: (fromChain.supportsTokenBridge)
ah yes, seems like something related to the dynamic imports then
for now just add
import "@wormhole-foundation/sdk-evm-tokenbridge"
to the imports at the top which should register it unless there is another issue with tree shaking
if the above still doesnt work try:
import * as x from "@wormhole-foundation/sdk-evm-tokenbridge"
console.log(x)
to prevent it from getting tree-shaken out
hello, I keep getting this error on a fresh Nestjs project, and I am using the latest version ^0.6.5
Failed to load required packages TypeError: Cannot convert undefined or null to object at Function.values ()
at @wormhole-foundation/sdk/src/index.ts:36:36
at Array.map ()
for const wh = await wormhole('Mainnet', [evm]);