Skip to content

Commit

Permalink
Merge branch 'main' into peerUpgradable
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniko authored Dec 3, 2024
2 parents f6fc1ed + 5e7ceae commit c6527d6
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function select_branch {
branch=""
regex="refs/tags/v[0-9]*\.[0-9]*\.[0-9]*+cli"
if git ls-remote --tags "$REPO" | grep -q "$regex"; then
branch="$(git ls-remote --tags "$REPO" | grep "$regex" | sort -V | tail -n 1 | awk '{print $2}')"
branch="$(git ls-remote --tags "$REPO" | grep "$regex" | awk '{print $2}' | sort -V | tail -n 1)"
else
# otherwise error
echo "No tag of the form vX.Y.Z+cli found" >&2
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/ntt-cli",
"version": "0.5.0",
"version": "1.1.0",
"module": "src/index.ts",
"type": "module",
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,15 @@ async function deployEvm<N extends Network, C extends Chain>(
}

const rpc = ch.config.rpc;
const specialRelayer = "0x63BE47835c7D66c4aA5B2C688Dc6ed9771c94C74"; // TODO: how to configure this?
// TODO: how to make specialRelayer configurable??
let specialRelayer: string;
if (ch.chain === "Avalanche") {
specialRelayer = "0x1a19d8a194630642f750376Ae72b4eDF5aDFd25F";
} else if (ch.chain === "Bsc") {
specialRelayer = "0x8C56eE9cd232d23541a697C0eBd3cA597DE3c88D";
} else {
specialRelayer = "0x63BE47835c7D66c4aA5B2C688Dc6ed9771c94C74";
}

const provider = new ethers.JsonRpcProvider(rpc);
const abi = ["function decimals() external view returns (uint8)"];
Expand Down
10 changes: 7 additions & 3 deletions evm/src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,18 @@ contract WormholeTransceiver is
bytes32 refundRecipient = refundAddress;
uint16 destinationChain = recipientChain;

wormholeRelayer.sendPayloadToEvm{value: deliveryPayment}(
wormholeRelayer.sendToEvm{value: deliveryPayment}(
destinationChain,
fromWormholeFormat(getWormholePeer(destinationChain)),
encodedTransceiverPayload,
0,
0, // receiverValue
0, // paymentForExtraReceiverValue,
gasLimit,
destinationChain,
fromWormholeFormat(refundRecipient)
fromWormholeFormat(refundRecipient),
wormholeRelayer.getDefaultDeliveryProvider(),
new VaaKey[](0),
consistencyLevel
);

emit RelayingInfo(uint8(RelayingType.Standard), refundAddress, deliveryPayment);
Expand Down
20 changes: 13 additions & 7 deletions sdk/route/src/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ export class NttAutomaticRoute<N extends Network>
request.toChain.config.nativeTokenDecimals
);

const amt = amount.parse(params.amount, request.source.decimals);
const parsedAmount = amount.parse(params.amount, request.source.decimals);
// The trimmedAmount may differ from the parsedAmount if the parsedAmount includes dust
const trimmedAmount = NttRoute.trimAmount(
parsedAmount,
request.destination.decimals
);

const validatedParams: Vp = {
amount: params.amount,
normalizedParams: {
amount: amt,
amount: trimmedAmount,
sourceContracts: NttRoute.resolveNttContracts(
this.staticConfig,
request.source.id
Expand Down Expand Up @@ -160,6 +165,11 @@ export class NttAutomaticRoute<N extends Network>
params.normalizedParams.options
);

const dstAmount = amount.scale(
params.normalizedParams.amount,
request.destination.decimals
);

const result: QR = {
success: true,
params,
Expand All @@ -169,7 +179,7 @@ export class NttAutomaticRoute<N extends Network>
},
destinationToken: {
token: request.destination.id,
amount: amount.parse(params.amount, request.destination.decimals),
amount: dstAmount,
},
relayFee: {
token: Wormhole.tokenId(fromChain.chain, "native"),
Expand All @@ -190,10 +200,6 @@ export class NttAutomaticRoute<N extends Network>
const duration = await dstNtt.getRateLimitDuration();
if (duration > 0n) {
const capacity = await dstNtt.getCurrentInboundCapacity(fromChain.chain);
const dstAmount = amount.parse(
params.amount,
request.destination.decimals
);
if (
NttRoute.isCapacityThresholdExceeded(amount.units(dstAmount), capacity)
) {
Expand Down
21 changes: 14 additions & 7 deletions sdk/route/src/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ export class NttManualRoute<N extends Network>
): Promise<Vr> {
const options = params.options ?? this.getDefaultOptions();

const amt = amount.parse(params.amount, request.source.decimals);
const parsedAmount = amount.parse(params.amount, request.source.decimals);
// The trimmedAmount may differ from the parsedAmount if the parsedAmount includes dust
const trimmedAmount = NttRoute.trimAmount(
parsedAmount,
request.destination.decimals
);

const gasDropoff = amount.units(
amount.parse(
options.gasDropoff ?? "0.0",
Expand All @@ -113,7 +119,7 @@ export class NttManualRoute<N extends Network>
const validatedParams: Vp = {
amount: params.amount,
normalizedParams: {
amount: amt,
amount: trimmedAmount,
sourceContracts: NttRoute.resolveNttContracts(
this.staticConfig,
request.source.id
Expand All @@ -137,6 +143,11 @@ export class NttManualRoute<N extends Network>
request: routes.RouteTransferRequest<N>,
params: Vp
): Promise<QR> {
const dstAmount = amount.scale(
params.normalizedParams.amount,
request.destination.decimals
);

const result: QR = {
success: true,
params,
Expand All @@ -146,7 +157,7 @@ export class NttManualRoute<N extends Network>
},
destinationToken: {
token: request.destination.id,
amount: amount.parse(params.amount, request.destination.decimals),
amount: dstAmount,
},
eta: finality.estimateFinalityTime(request.fromChain.chain),
};
Expand All @@ -157,10 +168,6 @@ export class NttManualRoute<N extends Network>
const duration = await dstNtt.getRateLimitDuration();
if (duration > 0n) {
const capacity = await dstNtt.getCurrentInboundCapacity(fromChain.chain);
const dstAmount = amount.parse(
params.amount,
request.destination.decimals
);
if (
NttRoute.isCapacityThresholdExceeded(amount.units(dstAmount), capacity)
) {
Expand Down
14 changes: 14 additions & 0 deletions sdk/route/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export namespace NttRoute {
// Currently only wormhole attestations supported
export type TransceiverType = "wormhole";

export const TRIMMED_DECIMALS = 8;

export type TransceiverConfig = {
type: TransceiverType;
address: string;
Expand Down Expand Up @@ -212,4 +214,16 @@ export namespace NttRoute {
const threshold = (capacity * 95n) / 100n;
return amount > threshold;
}

export function trimAmount(
amt: amount.Amount,
dstTokenDecimals: number
): amount.Amount {
// remove dust to avoid `TransferAmountHasDust` revert reason
const truncatedAmount = amount.truncate(
amt,
Math.min(amt.decimals, dstTokenDecimals, NttRoute.TRIMMED_DECIMALS)
);
return truncatedAmount;
}
}

0 comments on commit c6527d6

Please sign in to comment.