diff --git a/packages/sdk-bridge/src/abi/lnaccess-controller.ts b/packages/sdk-bridge/src/abi/lnaccess-controller.ts new file mode 100644 index 00000000..54243041 --- /dev/null +++ b/packages/sdk-bridge/src/abi/lnaccess-controller.ts @@ -0,0 +1,182 @@ +const abi = [ + { + inputs: [ + { internalType: "address", name: "_dao", type: "address" }, + { internalType: "address", name: "_endpoint", type: "address" }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint16", name: "lzRemoteChainId", type: "uint16" }, + { indexed: false, internalType: "bytes", name: "srcAddress", type: "bytes" }, + { indexed: false, internalType: "bool", name: "successed", type: "bool" }, + ], + name: "CallResult", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint16", name: "lzRemoteChainId", type: "uint16" }, + { indexed: false, internalType: "bytes", name: "srcAddress", type: "bytes" }, + { indexed: false, internalType: "address", name: "remoteAppAddress", type: "address" }, + ], + name: "CallerUnMatched", + type: "event", + }, + { + inputs: [ + { internalType: "address", name: "appAddress", type: "address" }, + { internalType: "bool", name: "enable", type: "bool" }, + ], + name: "authoriseAppCaller", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "", type: "address" }], + name: "callerWhiteList", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "dao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "endpoint", + outputs: [{ internalType: "contract ILayerZeroEndpoint", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes", name: "_message", type: "bytes" }, + ], + name: "fee", + outputs: [ + { internalType: "uint256", name: "nativeFee", type: "uint256" }, + { internalType: "uint256", name: "zroFee", type: "uint256" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint16", name: "_srcChainId", type: "uint16" }, + { internalType: "bytes", name: "_srcAddress", type: "bytes" }, + { internalType: "uint64", name: "", type: "uint64" }, + { internalType: "bytes", name: "_payload", type: "bytes" }, + ], + name: "lzReceive", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "operator", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + ], + name: "registerRemoteReceiver", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + ], + name: "registerRemoteSender", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "remoteAppReceivers", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "remoteAppSenders", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "uint256", name: "", type: "uint256" }], + name: "remoteMessagers", + outputs: [ + { internalType: "uint16", name: "lzRemoteChainId", type: "uint16" }, + { internalType: "address", name: "messager", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes", name: "_message", type: "bytes" }, + { internalType: "bytes", name: "_params", type: "bytes" }, + ], + name: "sendMessage", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_operator", type: "address" }], + name: "setOperator", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_appRemoteChainId", type: "uint256" }, + { internalType: "uint16", name: "_lzRemoteChainId", type: "uint16" }, + { internalType: "address", name: "_remoteMessager", type: "address" }, + ], + name: "setRemoteMessager", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_dao", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "uint16", name: "", type: "uint16" }], + name: "trustedRemotes", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, +] as const; + +export default abi; diff --git a/packages/sdk-bridge/src/abi/lnbridge-v3.ts b/packages/sdk-bridge/src/abi/lnbridge-v3.ts new file mode 100644 index 00000000..c12a74fc --- /dev/null +++ b/packages/sdk-bridge/src/abi/lnbridge-v3.ts @@ -0,0 +1,673 @@ +import { Abi } from "viem"; + +const abi = [ + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "tokenInfoKey", type: "bytes32" }, + { indexed: false, internalType: "uint256", name: "amount", type: "uint256" }, + { indexed: false, internalType: "address", name: "receiver", type: "address" }, + ], + name: "FeeIncomeClaimed", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "uint8", name: "version", type: "uint8" }], + name: "Initialized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32[]", name: "transferIds", type: "bytes32[]" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "uint256", name: "amount", type: "uint256" }, + ], + name: "LiquidityWithdrawn", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "bool", name: "paused", type: "bool" }, + ], + name: "LnProviderPaused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "baseFee", type: "uint112" }, + { indexed: false, internalType: "uint16", name: "liquidityfeeRate", type: "uint16" }, + { indexed: false, internalType: "uint112", name: "transferLimit", type: "uint112" }, + ], + name: "LnProviderUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }], + name: "Paused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "uint256", name: "updatedPanaltyReserve", type: "uint256" }, + ], + name: "PenaltyReserveUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "address", name: "slasher", type: "address" }, + ], + name: "SlashRequest", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "tokenInfoKey", type: "bytes32" }, + { indexed: false, internalType: "uint112", name: "protocolFee", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "penalty", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "sourceDecimals", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "targetDecimals", type: "uint112" }, + ], + name: "TokenInfoUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "totalFee", type: "uint112" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "address", name: "receiver", type: "address" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + ], + indexed: false, + internalType: "struct LnBridgeSourceV3.TransferParams", + name: "params", + type: "tuple", + }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "uint112", name: "targetAmount", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "fee", type: "uint112" }, + ], + name: "TokenLocked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "key", type: "bytes32" }, + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "protocolFee", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "penalty", type: "uint112" }, + { indexed: false, internalType: "uint32", name: "index", type: "uint32" }, + ], + name: "TokenRegistered", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + ], + name: "TransferFilled", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "slasher", type: "address" }, + { indexed: false, internalType: "uint112", name: "slashAmount", type: "uint112" }, + ], + name: "TransferSlashed", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }], + name: "Unpaused", + type: "event", + }, + { + inputs: [], + name: "LIQUIDITY_FEE_RATE_BASE", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK_STATUS_LOCKED", + outputs: [{ internalType: "uint8", name: "", type: "uint8" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK_STATUS_SLASHED", + outputs: [{ internalType: "uint8", name: "", type: "uint8" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK_STATUS_WITHDRAWN", + outputs: [{ internalType: "uint8", name: "", type: "uint8" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "LOCK_TIME_DISTANCE", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "MAX_TRANSFER_AMOUNT", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "SLASH_EXPIRE_TIME", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { inputs: [], name: "acceptOwnership", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [ + { internalType: "bytes32", name: "_tokenInfoKey", type: "bytes32" }, + { internalType: "uint256", name: "_amount", type: "uint256" }, + { internalType: "address", name: "_receiver", type: "address" }, + ], + name: "claimProtocolFeeIncome", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "dao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "key", type: "bytes32" }], + name: "deleteTokenInfo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "uint256", name: "_amount", type: "uint256" }, + ], + name: "depositPenaltyReserve", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "fillTransfers", + outputs: [ + { internalType: "uint64", name: "timestamp", type: "uint64" }, + { internalType: "address", name: "provider", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "getProviderKey", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "provider", type: "address" }, + ], + name: "getProviderStateKey", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "getTokenKey", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "totalFee", type: "uint112" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "address", name: "receiver", type: "address" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + ], + internalType: "struct LnBridgeSourceV3.TransferParams", + name: "_params", + type: "tuple", + }, + { internalType: "uint112", name: "_remoteAmount", type: "uint112" }, + ], + name: "getTransferId", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "dao", type: "address" }], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "totalFee", type: "uint112" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "address", name: "receiver", type: "address" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + ], + internalType: "struct LnBridgeSourceV3.TransferParams", + name: "_params", + type: "tuple", + }, + ], + name: "lockAndRemoteRelease", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "lockInfos", + outputs: [ + { internalType: "uint112", name: "amountWithFeeAndPenalty", type: "uint112" }, + { internalType: "uint32", name: "tokenIndex", type: "uint32" }, + { internalType: "uint8", name: "status", type: "uint8" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "uint256", name: "", type: "uint256" }], + name: "messagers", + outputs: [ + { internalType: "address", name: "sendService", type: "address" }, + { internalType: "address", name: "receiveService", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "operator", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { inputs: [], name: "pause", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [], + name: "paused", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "penaltyReserves", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "pendingDao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "providerPause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "providerUnpause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_baseFee", type: "uint112" }, + { internalType: "uint16", name: "_liquidityFeeRate", type: "uint16" }, + { internalType: "uint112", name: "_transferLimit", type: "uint112" }, + ], + name: "registerLnProvider", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_protocolFee", type: "uint112" }, + { internalType: "uint112", name: "_penalty", type: "uint112" }, + { internalType: "uint8", name: "_sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "_targetDecimals", type: "uint8" }, + { internalType: "uint32", name: "_index", type: "uint32" }, + ], + name: "registerTokenInfo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "sourceAmount", type: "uint112" }, + { internalType: "uint112", name: "targetAmount", type: "uint112" }, + { internalType: "address", name: "receiver", type: "address" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + ], + internalType: "struct LnBridgeTargetV3.RelayParams", + name: "_params", + type: "tuple", + }, + { internalType: "bytes32", name: "_expectedTransferId", type: "bytes32" }, + { internalType: "bool", name: "_relayBySelf", type: "bool" }, + ], + name: "relay", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "sourceAmount", type: "uint112" }, + { internalType: "uint112", name: "targetAmount", type: "uint112" }, + { internalType: "address", name: "receiver", type: "address" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + ], + internalType: "struct LnBridgeTargetV3.RelayParams", + name: "_params", + type: "tuple", + }, + { internalType: "bytes32", name: "_expectedTransferId", type: "bytes32" }, + { internalType: "uint256", name: "_feePrepaid", type: "uint256" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestSlashAndRemoteRelease", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32[]", name: "_transferIds", type: "bytes32[]" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestWithdrawLiquidity", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { internalType: "bytes32", name: "transferId", type: "bytes32" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "retrySlash", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_operator", type: "address" }], + name: "setOperator", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + { internalType: "address", name: "_service", type: "address" }, + ], + name: "setReceiveService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + { internalType: "address", name: "_service", type: "address" }, + ], + name: "setSendService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_transferId", type: "bytes32" }, + { internalType: "address", name: "_lnProvider", type: "address" }, + { internalType: "address", name: "_slasher", type: "address" }, + ], + name: "slash", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "slashInfos", + outputs: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "slasher", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "srcProviders", + outputs: [ + { internalType: "uint112", name: "baseFee", type: "uint112" }, + { internalType: "uint16", name: "liquidityFeeRate", type: "uint16" }, + { internalType: "uint112", name: "transferLimit", type: "uint112" }, + { internalType: "bool", name: "pause", type: "bool" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "uint32", name: "", type: "uint32" }], + name: "tokenIndexer", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "tokenInfos", + outputs: [ + { + components: [ + { internalType: "uint112", name: "protocolFee", type: "uint112" }, + { internalType: "uint112", name: "penalty", type: "uint112" }, + { internalType: "uint8", name: "sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "targetDecimals", type: "uint8" }, + ], + internalType: "struct LnBridgeSourceV3.TokenConfigure", + name: "config", + type: "tuple", + }, + { internalType: "uint32", name: "index", type: "uint32" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint256", name: "protocolFeeIncome", type: "uint256" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + ], + name: "totalFee", + outputs: [{ internalType: "uint112", name: "", type: "uint112" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_dao", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { inputs: [], name: "unpause", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_protocolFee", type: "uint112" }, + { internalType: "uint112", name: "_penalty", type: "uint112" }, + { internalType: "uint8", name: "_sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "_targetDecimals", type: "uint8" }, + ], + name: "updateTokenInfo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "bytes32[]", name: "_transferIds", type: "bytes32[]" }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_provider", type: "address" }, + ], + name: "withdrawLiquidity", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "uint256", name: "_amount", type: "uint256" }, + ], + name: "withdrawPenaltyReserve", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { stateMutability: "payable", type: "receive" }, +] as const satisfies Abi; + +export default abi; diff --git a/packages/sdk-bridge/src/abi/lnv2-default.ts b/packages/sdk-bridge/src/abi/lnv2-default.ts new file mode 100644 index 00000000..1bc5142e --- /dev/null +++ b/packages/sdk-bridge/src/abi/lnv2-default.ts @@ -0,0 +1,545 @@ +import { Abi } from "viem"; + +const abi = [ + { + anonymous: false, + inputs: [{ indexed: false, internalType: "uint8", name: "version", type: "uint8" }], + name: "Initialized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "baseFee", type: "uint112" }, + { indexed: false, internalType: "uint8", name: "liquidityfeeRate", type: "uint8" }, + ], + name: "LnProviderUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint256", name: "amount", type: "uint256" }, + { indexed: false, internalType: "uint64", name: "withdrawNonce", type: "uint64" }, + ], + name: "MarginUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }], + name: "Paused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint256", name: "margin", type: "uint256" }, + { indexed: false, internalType: "address", name: "slasher", type: "address" }, + ], + name: "Slash", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "bytes32", name: "expectedTransferId", type: "bytes32" }, + ], + name: "SlashRequest", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint256", name: "amount", type: "uint256" }, + ], + name: "SlashReserveUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "amount", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "fee", type: "uint112" }, + { indexed: false, internalType: "uint64", name: "timestamp", type: "uint64" }, + { indexed: false, internalType: "address", name: "receiver", type: "address" }, + ], + name: "TokenLocked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + ], + name: "TransferFilled", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }], + name: "Unpaused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "amount", type: "uint112" }, + ], + name: "WithdrawMarginRequest", + type: "event", + }, + { + inputs: [], + name: "dao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint256", name: "_margin", type: "uint256" }, + ], + name: "depositProviderMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint256", name: "_amount", type: "uint256" }, + ], + name: "depositSlashFundReserve", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "bytes32", name: "previousTransferId", type: "bytes32" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + { internalType: "address", name: "receiver", type: "address" }, + ], + internalType: "struct LnBridgeHelper.TransferParameter", + name: "_params", + type: "tuple", + }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_slasher", type: "address" }, + { internalType: "uint112", name: "_fee", type: "uint112" }, + { internalType: "uint112", name: "_penalty", type: "uint112" }, + ], + name: "encodeSlashCall", + outputs: [{ internalType: "bytes", name: "message", type: "bytes" }], + stateMutability: "pure", + type: "function", + }, + { + inputs: [ + { internalType: "bytes32", name: "_lastTransferId", type: "bytes32" }, + { internalType: "uint64", name: "_withdrawNonce", type: "uint64" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + ], + name: "encodeWithdrawCall", + outputs: [{ internalType: "bytes", name: "message", type: "bytes" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "fillTransfers", + outputs: [ + { internalType: "uint64", name: "timestamp", type: "uint64" }, + { internalType: "address", name: "slasher", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "dao", type: "address" }], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "lockInfos", + outputs: [ + { internalType: "uint112", name: "fee", type: "uint112" }, + { internalType: "uint112", name: "penalty", type: "uint112" }, + { internalType: "uint32", name: "timestamp", type: "uint32" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "uint256", name: "", type: "uint256" }], + name: "messagers", + outputs: [ + { internalType: "address", name: "sendService", type: "address" }, + { internalType: "address", name: "receiveService", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "operator", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { inputs: [], name: "pause", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [], + name: "paused", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "protocolFeeReceiver", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "providerPause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "providerUnpause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "bytes32", name: "previousTransferId", type: "bytes32" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + { internalType: "address", name: "receiver", type: "address" }, + ], + internalType: "struct LnBridgeHelper.TransferParameter", + name: "_params", + type: "tuple", + }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_expectedTransferId", type: "bytes32" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestSlashAndRemoteRelease", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestWithdrawMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_operator", type: "address" }], + name: "setOperator", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_baseFee", type: "uint112" }, + { internalType: "uint8", name: "_liquidityFeeRate", type: "uint8" }, + ], + name: "setProviderFee", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + { internalType: "address", name: "_service", type: "address" }, + ], + name: "setReceiveService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + { internalType: "address", name: "_service", type: "address" }, + ], + name: "setSendService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_protocolFee", type: "uint112" }, + { internalType: "uint112", name: "_penaltyLnCollateral", type: "uint112" }, + { internalType: "uint8", name: "_sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "_targetDecimals", type: "uint8" }, + ], + name: "setTokenInfo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "bytes32", name: "previousTransferId", type: "bytes32" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + { internalType: "address", name: "receiver", type: "address" }, + ], + internalType: "struct LnBridgeHelper.TransferParameter", + name: "_params", + type: "tuple", + }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_slasher", type: "address" }, + { internalType: "uint112", name: "_fee", type: "uint112" }, + { internalType: "uint112", name: "_penalty", type: "uint112" }, + ], + name: "slash", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "srcProviders", + outputs: [ + { + components: [ + { internalType: "uint112", name: "baseFee", type: "uint112" }, + { internalType: "uint16", name: "liquidityFeeRate", type: "uint16" }, + { internalType: "uint64", name: "withdrawNonce", type: "uint64" }, + { internalType: "bool", name: "pause", type: "bool" }, + ], + internalType: "struct LnDefaultBridgeSource.SourceProviderConfigure", + name: "config", + type: "tuple", + }, + { internalType: "bytes32", name: "lastTransferId", type: "bytes32" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "tgtProviders", + outputs: [ + { internalType: "uint256", name: "margin", type: "uint256" }, + { internalType: "uint256", name: "slashReserveFund", type: "uint256" }, + { internalType: "uint64", name: "lastExpireFillTime", type: "uint64" }, + { internalType: "uint64", name: "withdrawNonce", type: "uint64" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "tokenInfos", + outputs: [ + { internalType: "uint112", name: "protocolFee", type: "uint112" }, + { internalType: "uint112", name: "penaltyLnCollateral", type: "uint112" }, + { internalType: "uint8", name: "sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "targetDecimals", type: "uint8" }, + { internalType: "bool", name: "isRegistered", type: "bool" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + ], + name: "totalFee", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "bytes32", name: "transferId", type: "bytes32" }, + { internalType: "uint112", name: "totalFee", type: "uint112" }, + { internalType: "uint64", name: "withdrawNonce", type: "uint64" }, + ], + internalType: "struct LnDefaultBridgeSource.Snapshot", + name: "_snapshot", + type: "tuple", + }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + { internalType: "address", name: "_receiver", type: "address" }, + ], + name: "transferAndLockMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "bytes32", name: "previousTransferId", type: "bytes32" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + { internalType: "address", name: "receiver", type: "address" }, + ], + internalType: "struct LnBridgeHelper.TransferParameter", + name: "_params", + type: "tuple", + }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_expectedTransferId", type: "bytes32" }, + ], + name: "transferAndReleaseMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_dao", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { inputs: [], name: "unpause", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [{ internalType: "address", name: "_receiver", type: "address" }], + name: "updateFeeReceiver", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_lastTransferId", type: "bytes32" }, + { internalType: "uint64", name: "_withdrawNonce", type: "uint64" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + ], + name: "withdraw", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint256", name: "_amount", type: "uint256" }, + ], + name: "withdrawSlashFundReserve", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { stateMutability: "payable", type: "receive" }, +] as const satisfies Abi; + +export default abi; diff --git a/packages/sdk-bridge/src/abi/lnv2-opposite.ts b/packages/sdk-bridge/src/abi/lnv2-opposite.ts new file mode 100644 index 00000000..087e03b4 --- /dev/null +++ b/packages/sdk-bridge/src/abi/lnv2-opposite.ts @@ -0,0 +1,449 @@ +import { Abi } from "viem"; + +const abi = [ + { + anonymous: false, + inputs: [{ indexed: false, internalType: "uint8", name: "version", type: "uint8" }], + name: "Initialized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "amount", type: "uint112" }, + ], + name: "LiquidityWithdrawn", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "margin", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "baseFee", type: "uint112" }, + { indexed: false, internalType: "uint16", name: "liquidityfeeRate", type: "uint16" }, + ], + name: "LnProviderUpdated", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }], + name: "Paused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "margin", type: "uint112" }, + { indexed: false, internalType: "address", name: "slasher", type: "address" }, + ], + name: "Slash", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + ], + name: "SlashRequest", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "provider", type: "address" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "amount", type: "uint112" }, + { indexed: false, internalType: "uint112", name: "fee", type: "uint112" }, + { indexed: false, internalType: "uint64", name: "timestamp", type: "uint64" }, + { indexed: false, internalType: "address", name: "receiver", type: "address" }, + ], + name: "TokenLocked", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "slasher", type: "address" }, + ], + name: "TransferFilled", + type: "event", + }, + { + anonymous: false, + inputs: [{ indexed: false, internalType: "address", name: "account", type: "address" }], + name: "Unpaused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { indexed: false, internalType: "address", name: "sourceToken", type: "address" }, + { indexed: false, internalType: "address", name: "targetToken", type: "address" }, + { indexed: false, internalType: "uint112", name: "amount", type: "uint112" }, + ], + name: "WithdrawMarginRequest", + type: "event", + }, + { + inputs: [], + name: "dao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "fillTransfers", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_dao", type: "address" }], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "lockInfos", + outputs: [ + { internalType: "uint112", name: "amountWithFeeAndPenalty", type: "uint112" }, + { internalType: "uint32", name: "timestamp", type: "uint32" }, + { internalType: "bool", name: "hasSlashed", type: "bool" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "operator", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { inputs: [], name: "pause", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [], + name: "paused", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "protocolFeeReceiver", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "providerPause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + ], + name: "providerUnpause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_transferId", type: "bytes32" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestRetrySlashAndRemoteRelease", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "bytes32", name: "previousTransferId", type: "bytes32" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + { internalType: "address", name: "receiver", type: "address" }, + ], + internalType: "struct LnBridgeHelper.TransferParameter", + name: "_params", + type: "tuple", + }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_expectedTransferId", type: "bytes32" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestSlashAndRemoteRelease", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_lastTransferId", type: "bytes32" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + { internalType: "bytes", name: "_extParams", type: "bytes" }, + ], + name: "requestWithdrawMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_operator", type: "address" }], + name: "setOperator", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + { internalType: "address", name: "_service", type: "address" }, + ], + name: "setReceiveService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + { internalType: "address", name: "_service", type: "address" }, + ], + name: "setSendService", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_protocolFee", type: "uint112" }, + { internalType: "uint112", name: "_penaltyLnCollateral", type: "uint112" }, + { internalType: "uint8", name: "_sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "_targetDecimals", type: "uint8" }, + ], + name: "setTokenInfo", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "bytes32", name: "_latestSlashTransferId", type: "bytes32" }, + { internalType: "bytes32", name: "_transferId", type: "bytes32" }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "uint256", name: "_timestamp", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_slasher", type: "address" }, + ], + name: "slash", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "slashInfos", + outputs: [ + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "address", name: "slasher", type: "address" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "srcProviders", + outputs: [ + { + components: [ + { internalType: "uint112", name: "margin", type: "uint112" }, + { internalType: "uint112", name: "baseFee", type: "uint112" }, + { internalType: "uint16", name: "liquidityFeeRate", type: "uint16" }, + { internalType: "bool", name: "pause", type: "bool" }, + ], + internalType: "struct LnOppositeBridgeSource.SourceProviderConfigure", + name: "config", + type: "tuple", + }, + { internalType: "bytes32", name: "lastTransferId", type: "bytes32" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "tokenInfos", + outputs: [ + { internalType: "uint112", name: "protocolFee", type: "uint112" }, + { internalType: "uint112", name: "penaltyLnCollateral", type: "uint112" }, + { internalType: "uint8", name: "sourceDecimals", type: "uint8" }, + { internalType: "uint8", name: "targetDecimals", type: "uint8" }, + { internalType: "bool", name: "isRegistered", type: "bool" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + ], + name: "totalFee", + outputs: [{ internalType: "uint256", name: "", type: "uint256" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "uint256", name: "remoteChainId", type: "uint256" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "bytes32", name: "transferId", type: "bytes32" }, + { internalType: "uint112", name: "totalFee", type: "uint112" }, + { internalType: "uint112", name: "depositedMargin", type: "uint112" }, + ], + internalType: "struct LnOppositeBridgeSource.Snapshot", + name: "_snapshot", + type: "tuple", + }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + { internalType: "address", name: "_receiver", type: "address" }, + ], + name: "transferAndLockMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + components: [ + { internalType: "bytes32", name: "previousTransferId", type: "bytes32" }, + { internalType: "address", name: "provider", type: "address" }, + { internalType: "address", name: "sourceToken", type: "address" }, + { internalType: "address", name: "targetToken", type: "address" }, + { internalType: "uint112", name: "amount", type: "uint112" }, + { internalType: "uint256", name: "timestamp", type: "uint256" }, + { internalType: "address", name: "receiver", type: "address" }, + ], + internalType: "struct LnBridgeHelper.TransferParameter", + name: "_params", + type: "tuple", + }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes32", name: "_expectedTransferId", type: "bytes32" }, + ], + name: "transferAndReleaseMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_dao", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { inputs: [], name: "unpause", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [{ internalType: "address", name: "_receiver", type: "address" }], + name: "updateFeeReceiver", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_margin", type: "uint112" }, + { internalType: "uint112", name: "_baseFee", type: "uint112" }, + { internalType: "uint16", name: "_liquidityFeeRate", type: "uint16" }, + ], + name: "updateProviderFeeAndMargin", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { internalType: "bytes32", name: "_latestSlashTransferId", type: "bytes32" }, + { internalType: "bytes32", name: "_lastTransferId", type: "bytes32" }, + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_provider", type: "address" }, + { internalType: "address", name: "_sourceToken", type: "address" }, + { internalType: "address", name: "_targetToken", type: "address" }, + { internalType: "uint112", name: "_amount", type: "uint112" }, + ], + name: "withdrawMargin", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { stateMutability: "payable", type: "receive" }, +] as const satisfies Abi; + +export default abi; diff --git a/packages/sdk-bridge/src/abi/msgline-messager.ts b/packages/sdk-bridge/src/abi/msgline-messager.ts new file mode 100644 index 00000000..20dfee58 --- /dev/null +++ b/packages/sdk-bridge/src/abi/msgline-messager.ts @@ -0,0 +1,202 @@ +const abi = [ + { + inputs: [ + { internalType: "address", name: "_dao", type: "address" }, + { internalType: "address", name: "_msgline", type: "address" }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "srcAppChainId", type: "uint256" }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "bool", name: "result", type: "bool" }, + ], + name: "CallResult", + type: "event", + }, + { + anonymous: false, + inputs: [ + { indexed: false, internalType: "uint256", name: "srcAppChainId", type: "uint256" }, + { indexed: false, internalType: "bytes32", name: "transferId", type: "bytes32" }, + { indexed: false, internalType: "address", name: "srcAppAddress", type: "address" }, + ], + name: "CallerUnMatched", + type: "event", + }, + { inputs: [], name: "acceptOwnership", outputs: [], stateMutability: "nonpayable", type: "function" }, + { + inputs: [], + name: "dao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "latestRecvMessageId", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "latestSentMessageId", + outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "messageId", type: "bytes32" }], + name: "messageDelivered", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "_from", type: "address" }, + { internalType: "address", name: "_to", type: "address" }, + { internalType: "bytes", name: "_message", type: "bytes" }, + ], + name: "messagePayload", + outputs: [{ internalType: "bytes", name: "", type: "bytes" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "msgline", + outputs: [{ internalType: "contract IMessageLine", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "operator", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "pendingDao", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_srcAppChainId", type: "uint256" }, + { internalType: "address", name: "_remoteAppAddress", type: "address" }, + { internalType: "address", name: "_localAppAddress", type: "address" }, + { internalType: "bytes", name: "_message", type: "bytes" }, + ], + name: "receiveMessage", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + ], + name: "registerRemoteReceiver", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteBridge", type: "address" }, + ], + name: "registerRemoteSender", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "remoteAppReceivers", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "bytes32", name: "", type: "bytes32" }], + name: "remoteAppSenders", + outputs: [{ internalType: "address", name: "", type: "address" }], + stateMutability: "view", + type: "function", + }, + { + inputs: [{ internalType: "uint256", name: "", type: "uint256" }], + name: "remoteMessagers", + outputs: [ + { internalType: "uint256", name: "msglineRemoteChainId", type: "uint256" }, + { internalType: "address", name: "messager", type: "address" }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_remoteChainId", type: "uint256" }, + { internalType: "bytes", name: "_message", type: "bytes" }, + { internalType: "bytes", name: "_params", type: "bytes" }, + ], + name: "sendMessage", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_operator", type: "address" }], + name: "setOperator", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "uint256", name: "_appRemoteChainId", type: "uint256" }, + { internalType: "uint256", name: "_msglineRemoteChainId", type: "uint256" }, + { internalType: "address", name: "_remoteMessager", type: "address" }, + ], + name: "setRemoteMessager", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { internalType: "address", name: "_caller", type: "address" }, + { internalType: "bool", name: "_enable", type: "bool" }, + ], + name: "setWhiteList", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "_dao", type: "address" }], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [{ internalType: "address", name: "", type: "address" }], + name: "whiteList", + outputs: [{ internalType: "bool", name: "", type: "bool" }], + stateMutability: "view", + type: "function", + }, +] as const; + +export default abi; diff --git a/packages/sdk-bridge/src/ln-bridge.ts b/packages/sdk-bridge/src/ln-bridge.ts index 651f1082..263b483f 100644 --- a/packages/sdk-bridge/src/ln-bridge.ts +++ b/packages/sdk-bridge/src/ln-bridge.ts @@ -1,14 +1,26 @@ -import { Address, Chain, createPublicClient, http, PublicClient, WalletClient } from "viem"; +import { + Address, + bytesToHex, + Chain, + createPublicClient, + encodeFunctionData, + Hash, + http, + PublicClient, + WalletClient, +} from "viem"; import { HelixChain, HelixProtocolName } from "@helixbridge/helixconf"; import assert from "assert"; import { getChainByIdOrNetwork, Chain as HChain } from "@helixbridge/chains"; import { OnChainToken, Token } from "@helixbridge/sdk-core"; +import { fetchMsgportFeeAndParams } from "./utils"; interface Options { walletClient?: WalletClient; } export abstract class LnBridge { + readonly protocol: HelixProtocolName; private readonly sourceToken: Token; private readonly targetToken: Token; private readonly sourceChain: HChain; @@ -56,6 +68,7 @@ export abstract class LnBridge { this.sourceBridgeContract = bridgeContractSource; this.targetBridgeContract = couple.protocol.address as Address; + this.protocol = protocol; this.sourceToken = new Token( sourceChain.id, sourceTokenConf.address as Address, @@ -128,6 +141,117 @@ export abstract class LnBridge { ); } + /** + * @param relayer - The relayer to get the fee for + * @param amount - The amount to transfer + * @returns The total fee for the transfer in the source token + */ + async getTotalFee(relayer: Address, amount: bigint) { + return this.publicClientSource.readContract({ + address: this.sourceBridgeContract, + abi: (await import(`./abi/lnv2-default`)).default, + functionName: "totalFee", + args: [BigInt(this.targetChain.id), relayer, this.sourceToken.address, this.targetToken.address, amount], + }); + } + + protected async getLayerzeroFee(sendService: Address, remoteChain: Chain, localPublicClient: PublicClient) { + const [nativeFee] = await localPublicClient.readContract({ + address: sendService, + abi: (await import(`./abi/lnaccess-controller`)).default, + functionName: "fee", + args: [BigInt(remoteChain.id), bytesToHex(Uint8Array.from([123]), { size: 750 })], + }); + return [nativeFee]; + } + + protected async getMsgportFeeAndParams( + message: Hash, + refundAddress: Address, + localChain: Chain, + remoteChain: Chain, + localContract: Address, + remoteContract: Address, + localToken: Token, + remoteToken: Token, + ) { + const localMessager = HelixChain.get(localChain.id)?.messager("msgline")?.address as Address | undefined; + const rm = HelixChain.get(localChain.id)?.couples.find( + (c) => + c.chain.id === BigInt(remoteChain.id) && + c.symbol.from === localToken.symbol && + c.symbol.to === remoteToken.symbol && + c.protocol.name === this.protocol, + )?.messager; + const remoteMessager = rm?.name === "msgline" ? (rm.address as Address | undefined) : undefined; + + if (localMessager && remoteMessager) { + const payload = encodeFunctionData({ + abi: (await import("./abi/msgline-messager")).default, + functionName: "receiveMessage", + args: [BigInt(localChain.id), localContract, remoteContract, message], + }); + + return fetchMsgportFeeAndParams( + localChain.id, + remoteChain.id, + localMessager, + remoteMessager, + refundAddress, + payload, + ); + } + } + + /** + * @returns The total fee for the withdraw in the source native token + */ + async getLayerzeroWithdrawFee() { + const [sendService] = await this.publicClientSource.readContract({ + address: this.sourceBridgeContract, + abi: (await import(`./abi/lnv2-default`)).default, + functionName: "messagers", + args: [BigInt(this.targetChain.id)], + }); + const [nativeFee] = await this.getLayerzeroFee(sendService, this.targetChain, this.publicClientSource); + return nativeFee; + } + + /** + * @returns The total fee for the withdraw in the source native token + */ + async getMsgportWithdrawFeeAndParams(args: { + transferId: Hash; + withdrawNonce: string; + relayer: Address; + refundAddress: Address; + amount: bigint; + }) { + const message = encodeFunctionData({ + abi: (await import(`./abi/lnv2-default`)).default, + functionName: "withdraw", + args: [ + BigInt(this.sourceChain.id), + args.transferId, + BigInt(args.withdrawNonce), + args.relayer, + this.sourceToken.address, + this.targetToken.address, + args.amount, + ], + }); + return this.getMsgportFeeAndParams( + message, + args.refundAddress, + this.sourceChain, + this.targetChain, + this.sourceBridgeContract, + this.targetBridgeContract, + this.sourceToken, + this.targetToken, + ); + } + // eslint-disable-next-line no-unused-vars abstract transfer(amount: bigint, recipient: Address): Promise; } diff --git a/packages/sdk-bridge/src/utils/misc.ts b/packages/sdk-bridge/src/utils/misc.ts index 8fc0fe18..59754a8e 100644 --- a/packages/sdk-bridge/src/utils/misc.ts +++ b/packages/sdk-bridge/src/utils/misc.ts @@ -1,7 +1,28 @@ -import { Chain } from "viem"; +import { Address, Chain, Hash } from "viem"; import { MAINNET_INDEXER_ENDPOINT } from "../config"; import { TESTNET_INDEXER_ENDPOINT } from "../config"; export function getIndexerUrl(chain: Chain) { return chain.testnet ? TESTNET_INDEXER_ENDPOINT : MAINNET_INDEXER_ENDPOINT; } + +export async function fetchMsgportFeeAndParams( + fromChainId: number, + toChainId: number, + fromAddress: Address, + toAddress: Address, + refundAddress: Address, + payload: Hash, +) { + const endpoint = "https://api.msgport.xyz"; + + const feeRes = await fetch( + `${endpoint}/ormp/fee?from_chain_id=${fromChainId}&to_chain_id=${toChainId}&payload=${payload}&from_address=${fromAddress}&to_address=${toAddress}&refund_address=${refundAddress}`, + ); + const feeJson = (await feeRes.json()) as { code: number; data: { fee: string; params: Hash } }; + if (feeRes.ok && feeJson.code === 0) { + const fee = BigInt(feeJson.data.fee); // In native token + const params = feeJson.data.params; + return { fee, params }; + } +}