diff --git a/packages/contract/script/pay/DeployDaimoPayAxelarBridger.s.sol b/packages/contract/script/pay/DeployDaimoPayAxelarBridger.s.sol index d0b40bda1..75b5cbd84 100644 --- a/packages/contract/script/pay/DeployDaimoPayAxelarBridger.s.sol +++ b/packages/contract/script/pay/DeployDaimoPayAxelarBridger.s.sol @@ -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) { @@ -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 { @@ -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 {} } diff --git a/packages/contract/src/pay/DaimoPayAxelarBridger.sol b/packages/contract/src/pay/DaimoPayAxelarBridger.sol index 91fb7ec69..9e56bb666 100644 --- a/packages/contract/src/pay/DaimoPayAxelarBridger.sol +++ b/packages/contract/src/pay/DaimoPayAxelarBridger.sol @@ -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", @@ -271,7 +270,7 @@ contract DaimoPayAxelarBridger is axelarGasService.payNativeGasForExpressCallWithToken{value: fee}( address(this), destChainName, - receiverContract.toHexString(), + Strings.toHexString(receiverContract), abi.encode(toAddress), outTokenSymbol, outAmount, @@ -281,7 +280,7 @@ contract DaimoPayAxelarBridger is axelarGasService.payNativeGasForContractCallWithToken{value: fee}( address(this), destChainName, - receiverContract.toHexString(), + Strings.toHexString(receiverContract), abi.encode(toAddress), outTokenSymbol, outAmount, @@ -298,7 +297,7 @@ contract DaimoPayAxelarBridger is }); axelarGateway.callContractWithToken( destChainName, - receiverContract.toHexString(), + Strings.toHexString(receiverContract), abi.encode(toAddress), outTokenSymbol, outAmount diff --git a/packages/daimo-common/src/daimoPay.ts b/packages/daimo-common/src/daimoPay.ts index 3ca5d35f9..c4b94033e 100644 --- a/packages/daimo-common/src/daimoPay.ts +++ b/packages/daimo-common/src/daimoPay.ts @@ -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 { @@ -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); @@ -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;