Skip to content

Commit

Permalink
pay: use zBigIntStr, revise axelar fees, use Strings.toHexString
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewliu08 committed Nov 4, 2024
1 parent fe746d7 commit f6abfe0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
24 changes: 18 additions & 6 deletions packages/contract/script/pay/DeployDaimoPayAxelarBridger.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,13 @@ contract DeployDaimoPayAxelarBridger is Script {
chainIds[0] = BSC_MAINNET;

for (uint32 i = 0; i < chainIds.length; ++i) {
uint256 fee = block.chainid == POLYGON_MAINNET
? 3000000000000000000 // 3.0 POLYGON
: 300000000000000; // 0.0003 ETH

bridgeRoutes[i] = DaimoPayAxelarBridger.AxelarBridgeRoute({
destChainName: _getAxelarChainName(chainIds[i]),
bridgeTokenIn: _getAxlUsdcAddress(block.chainid),
bridgeTokenOut: _getAxlUsdcAddress(chainIds[i]),
bridgeTokenOutSymbol: "axlUSDC",
receiverContract: axelarReceiver,
fee: fee
fee: _getAxelarFeeByChain(block.chainid)
});
}
} else if (block.chainid == BSC_MAINNET) {
Expand All @@ -108,7 +104,7 @@ contract DeployDaimoPayAxelarBridger is Script {
bridgeTokenOut: _getAxlUsdcAddress(chainIds[i]),
bridgeTokenOutSymbol: "axlUSDC",
receiverContract: axelarReceiver,
fee: 2_000_000_000_000_000 // 2 * 10^15 = 0.002 BNB
fee: _getAxelarFeeByChain(block.chainid)
});
}
} else {
Expand All @@ -130,6 +126,22 @@ contract DeployDaimoPayAxelarBridger is Script {
}
}

/**
* Get the Axelar bridging gas fee for a given chain. The fee should be
* approximately worth $1 USD.
*/
function _getAxelarFeeByChain(
uint256 chainId
) private pure returns (uint256) {
if (chainId == POLYGON_MAINNET) {
return 4_000_000_000_000_000_000; // 4 * 10^18 = 4 POL
} else if (chainId == BSC_MAINNET) {
return 2_000_000_000_000_000; // 2 * 10^15 = 0.002 BNB
} else {
return 500_000_000_000_000; // 5 * 10^14 = 0.0005 ETH
}
}

// Exclude from forge coverage
function test() public {}
}
7 changes: 3 additions & 4 deletions packages/contract/src/pay/DaimoPayAxelarBridger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ contract DaimoPayAxelarBridger is
Ownable2Step
{
using SafeERC20 for IERC20;
using Strings for address;

struct AxelarBridgeRoute {
// Axelar requires the name of the destination chain, e.g. "base",
Expand Down Expand Up @@ -271,7 +270,7 @@ contract DaimoPayAxelarBridger is
axelarGasService.payNativeGasForExpressCallWithToken{value: fee}(
address(this),
destChainName,
receiverContract.toHexString(),
Strings.toHexString(receiverContract),
abi.encode(toAddress),
outTokenSymbol,
outAmount,
Expand All @@ -281,7 +280,7 @@ contract DaimoPayAxelarBridger is
axelarGasService.payNativeGasForContractCallWithToken{value: fee}(
address(this),
destChainName,
receiverContract.toHexString(),
Strings.toHexString(receiverContract),
abi.encode(toAddress),
outTokenSymbol,
outAmount,
Expand All @@ -298,7 +297,7 @@ contract DaimoPayAxelarBridger is
});
axelarGateway.callContractWithToken(
destChainName,
receiverContract.toHexString(),
Strings.toHexString(receiverContract),
abi.encode(toAddress),
outTokenSymbol,
outAmount
Expand Down
8 changes: 4 additions & 4 deletions packages/daimo-common/src/daimoPay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "viem";
import z from "zod";

import { BigIntStr, zAddress } from "./model";
import { BigIntStr, zAddress, zBigIntStr } from "./model";

// lifecycle: waiting payment -> pending processing -> start submitted -> processed (onchain tx was successful)
export enum DaimoPayOrderStatusSource {
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface DaimoPayOrderItem {

export const zBridgeTokenOutOption = z.object({
token: zAddress.transform((a) => getAddress(a)),
amount: z.string().transform((a) => BigInt(a)),
amount: zBigIntStr.transform((a) => BigInt(a)),
});

export const zBridgeTokenOutOptions = z.array(zBridgeTokenOutOption);
Expand Down Expand Up @@ -135,8 +135,8 @@ export type DaimoPayHydratedOrder = {
id: bigint;
intentAddr: Address;
bridgeTokenOutOptions: DaimoPayTokenAmount[];
bridgeTokenOutAddr: Address | null;
bridgeTokenOutAmount: bigint | null;
selectedBridgeTokenOutAddr: Address | null;
selectedBridgeTokenOutAmount: bigint | null;
destFinalCallTokenAmount: DaimoPayTokenAmount;
destFinalCall: OnChainCall;
destRefundAddr: Address;
Expand Down

0 comments on commit f6abfe0

Please sign in to comment.