diff --git a/package.json b/package.json index 7a20eae..2b65ae4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maticnetwork/lxlyjs", - "version": "2.2.1", + "version": "2.3.0-beta.2", "description": "Javascript developer library for interacting with Polygon LxLy Bridge", "main": "dist/lxly.node.js", "types": "dist/ts/index.d.ts", diff --git a/src/abis/mainnet/GasPorter.ts b/src/abis/mainnet/GasPorter.ts new file mode 100644 index 0000000..247276b --- /dev/null +++ b/src/abis/mainnet/GasPorter.ts @@ -0,0 +1 @@ +export default [{ "inputs": [{ "internalType": "address", "name": "lxlyBridge_", "type": "address" }, { "internalType": "address", "name": "dex_", "type": "address" }, { "internalType": "address", "name": "settlementToken_", "type": "address" }], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [], "name": "CannotDetermineConversionBecauseWrappedTokenDoesNotExist", "type": "error" }, { "inputs": [], "name": "CannotDetermineGassetBecauseWrappedTokenDoesNotExist", "type": "error" }, { "inputs": [], "name": "CannotDetermineGassetMakeSureDestinationNetworkParametersAreCorrect", "type": "error" }, { "inputs": [], "name": "CannotRefuelGas", "type": "error" }, { "inputs": [], "name": "CannotReturnExcessiveMessageValueToYou", "type": "error" }, { "inputs": [], "name": "DestinationAddressCannotBeAddressZero", "type": "error" }, { "inputs": [], "name": "DestinationNetworkCannotBeCurrentNetwork", "type": "error" }, { "inputs": [], "name": "ECDSAInvalidSignature", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "length", "type": "uint256" }], "name": "ECDSAInvalidSignatureLength", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "s", "type": "bytes32" }], "name": "ECDSAInvalidSignatureS", "type": "error" }, { "inputs": [], "name": "GasPorterOnCurrentNetworkDoesNotSupportDexSwapAsGassetSourceYet", "type": "error" }, { "inputs": [], "name": "GasPorterOnCurrentNetworkDoesNotSupportGassetConversionYet", "type": "error" }, { "inputs": [], "name": "GasPorterOnDestinationNetworkDoesNotSupportGassetConversionYet", "type": "error" }, { "inputs": [], "name": "GassetAmountCannotBeZero", "type": "error" }, { "inputs": [], "name": "GassetCannotBeDolphinAddressDidYouMeanAddressZero", "type": "error" }, { "inputs": [], "name": "GassetPermitDataMustBeEmptyWhenGassetIsNativeToken", "type": "error" }, { "inputs": [], "name": "GassetTypeCannotBeERC20TokenWhenNativeTokensAreTheSame", "type": "error" }, { "inputs": [], "name": "GassetTypeCannotBeNativeTokenWhenNativeTokensAreDifferent", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint256", "name": "minimumAmount", "type": "uint256" }], "name": "InsufficientAmountInERC20Permit", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint256", "name": "minimumAmount", "type": "uint256" }], "name": "InsufficientMessageValue", "type": "error" }, { "inputs": [], "name": "InvalidConversionNonce", "type": "error" }, { "inputs": [], "name": "InvalidGassetTypeAndGassetSourceCombination", "type": "error" }, { "inputs": [], "name": "InvalidInitialization", "type": "error" }, { "inputs": [], "name": "InvalidToken", "type": "error" }, { "inputs": [], "name": "NotInitializing", "type": "error" }, { "inputs": [], "name": "OriginNetworkCannotBeCurrentNetwork", "type": "error" }, { "inputs": [], "name": "SwapCalldataCannotBeEmptyWhenGassetSourceIsDexSwap", "type": "error" }, { "inputs": [], "name": "SwapCalldataMustBeEmptyWhenGassetSourceIsNotDexSwap", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "SwapFailedBecauseDexGaveInsufficientAmount", "type": "error" }, { "inputs": [{ "internalType": "bytes", "name": "reason", "type": "bytes" }], "name": "SwapFailedBecauseDexReverted", "type": "error" }, { "inputs": [], "name": "SwapFailedBecauseDexRevertedWithoutExplanation", "type": "error" }, { "inputs": [], "name": "ThisFunctionIsOnlyCallableByGasPorter", "type": "error" }, { "inputs": [], "name": "TokenAmountCannotBeZero", "type": "error" }, { "inputs": [], "name": "TokenPermitDataMustBeEmptyWhenAssetAndGassetAreTheSameAndGassetPermitDataIsProvided", "type": "error" }, { "inputs": [], "name": "TokenPermitDataMustBeEmptyWhenAssetIsNativeToken", "type": "error" }, { "inputs": [], "name": "UnknownFunctionSelectorInERC20Permit", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "indexed": true, "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "indexed": false, "internalType": "address", "name": "signer", "type": "address" }, { "indexed": true, "internalType": "address", "name": "msgSender", "type": "address" }, { "indexed": false, "internalType": "bytes", "name": "reason", "type": "bytes" }], "name": "ConversionFailed", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint32", "name": "destinationNetwork", "type": "uint32" }, { "indexed": false, "internalType": "address", "name": "destinationAddress", "type": "address" }, { "indexed": false, "internalType": "address", "name": "gasset", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "bridgedGassetAmount", "type": "uint256" }], "name": "ConversionRequested", "type": "event" }, { "anonymous": false, "inputs": [], "name": "EIP712DomainChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "indexed": true, "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "indexed": true, "internalType": "address", "name": "signer", "type": "address" }], "name": "GassetConverted", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint64", "name": "version", "type": "uint64" }], "name": "Initialized", "type": "event" }, { "inputs": [], "name": "WETHToken", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bool", "name": "requestConversion", "type": "bool" }, { "internalType": "bool", "name": "forceUpdateGlobalExitRoot", "type": "bool" }, { "internalType": "uint32", "name": "destinationNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationAddress", "type": "address" }, { "internalType": "address", "name": "gasset", "type": "address" }, { "internalType": "enum GasPorter.GassetSource", "name": "gassetSource", "type": "uint8" }, { "internalType": "bytes", "name": "gassetPermitData", "type": "bytes" }, { "internalType": "uint256", "name": "gassetAmount", "type": "uint256" }, { "internalType": "bytes", "name": "swapCalldata", "type": "bytes" }, { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "tokenAmount", "type": "uint256" }, { "internalType": "bytes", "name": "tokenPermitData", "type": "bytes" }], "name": "bridgeAssetAndGas", "outputs": [], "stateMutability": "payable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "user", "type": "address" }, { "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }], "name": "conversionNonce", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "internalType": "uint256", "name": "conversionNonce", "type": "uint256" }, { "internalType": "address", "name": "settlementTokenDestinationAddress", "type": "address" }, { "internalType": "bytes", "name": "settlementTokenDestinationPermitData", "type": "bytes" }, { "internalType": "uint256", "name": "settlementTokenDestinationAmount", "type": "uint256" }, { "internalType": "bytes", "name": "destinationSwapCalldata", "type": "bytes" }, { "internalType": "uint256", "name": "destinationNativeTokenMinimumAmount", "type": "uint256" }], "internalType": "struct GasPorter.ConversionAuthorizationData", "name": "authorizationData", "type": "tuple" }, { "internalType": "address", "name": "signer", "type": "address" }], "name": "convertGasset", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "components": [{ "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "internalType": "uint256", "name": "conversionNonce", "type": "uint256" }, { "internalType": "address", "name": "settlementTokenDestinationAddress", "type": "address" }, { "internalType": "bytes", "name": "settlementTokenDestinationPermitData", "type": "bytes" }, { "internalType": "uint256", "name": "settlementTokenDestinationAmount", "type": "uint256" }, { "internalType": "bytes", "name": "destinationSwapCalldata", "type": "bytes" }, { "internalType": "uint256", "name": "destinationNativeTokenMinimumAmount", "type": "uint256" }], "internalType": "struct GasPorter.ConversionAuthorizationData", "name": "data", "type": "tuple" }, { "internalType": "bytes", "name": "signature", "type": "bytes" }], "internalType": "struct GasPorter.ConversionAuthorization", "name": "authorization", "type": "tuple" }], "name": "convertGasset", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint32", "name": "destinationNetworkGasTokenNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationNetworkGasTokenAddress", "type": "address" }, { "internalType": "address", "name": "gasset", "type": "address" }], "name": "determineConversion", "outputs": [{ "internalType": "bool", "name": "conversionRequired", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint32", "name": "destinationNetworkGasTokenNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationNetworkGasTokenAddress", "type": "address" }, { "internalType": "enum GasPorter.GassetType", "name": "gassetType", "type": "uint8" }], "name": "determineGasset", "outputs": [{ "internalType": "address", "name": "gasset", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "dex", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "eip712Domain", "outputs": [{ "internalType": "bytes1", "name": "fields", "type": "bytes1" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "version", "type": "string" }, { "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "verifyingContract", "type": "address" }, { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, { "internalType": "uint256[]", "name": "extensions", "type": "uint256[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "gasTokenAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "gasTokenNetwork", "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "initialize", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "lxlyBridge", "outputs": [{ "internalType": "contract ILxlyBridge", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "networkID", "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "uint256", "name": "msgValue", "type": "uint256" }, { "internalType": "uint32", "name": "destinationNetwork", "type": "uint32" }, { "internalType": "uint32", "name": "destinationNetworkGasTokenNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationNetworkGasTokenAddress", "type": "address" }, { "internalType": "address", "name": "destinationAddress", "type": "address" }, { "internalType": "address", "name": "destinationGasPorterDex", "type": "address" }, { "internalType": "enum GasPorter.GassetType", "name": "gassetType", "type": "uint8" }, { "internalType": "enum GasPorter.GassetSource", "name": "gassetSource", "type": "uint8" }, { "internalType": "uint256", "name": "gassetAmount", "type": "uint256" }, { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "tokenAmount", "type": "uint256" }, { "internalType": "bytes", "name": "gassetPermitData", "type": "bytes" }, { "internalType": "bytes", "name": "swapCalldata", "type": "bytes" }, { "internalType": "bytes", "name": "tokenPermitData", "type": "bytes" }, { "internalType": "bool", "name": "forceUpdateGlobalExitRoot", "type": "bool" }], "internalType": "struct GasPorter.Cargo", "name": "cargo", "type": "tuple" }], "name": "plotRoute", "outputs": [{ "internalType": "uint256", "name": "msgValue", "type": "uint256" }, { "internalType": "bytes", "name": "callData", "type": "bytes" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "settlementToken", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "settlementTokenIsNativeToken", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "version", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "pure", "type": "function" }, { "stateMutability": "payable", "type": "receive" }] diff --git a/src/abis/mainnet/index.ts b/src/abis/mainnet/index.ts index 5eea53f..52f5f6e 100644 --- a/src/abis/mainnet/index.ts +++ b/src/abis/mainnet/index.ts @@ -5,8 +5,10 @@ import PolygonZkEVMGlobalExitRoot from "./PolygonZkEVMGlobalExitRoot"; import PolygonZkEVMGlobalExitRootL2 from "./PolygonZkEVMGlobalExitRootL2"; import ZkEVMBridgeAdapter from "./ZkEVMBridgeAdapter"; import ZkEVMWrapper from "./ZkEVMWrapper"; +import GasPorter from "./GasPorter"; export default { + GasPorter, ERC20, PolygonZkEVM, PolygonZkEVMBridge, diff --git a/src/abis/testnet/GasPorter.ts b/src/abis/testnet/GasPorter.ts new file mode 100644 index 0000000..247276b --- /dev/null +++ b/src/abis/testnet/GasPorter.ts @@ -0,0 +1 @@ +export default [{ "inputs": [{ "internalType": "address", "name": "lxlyBridge_", "type": "address" }, { "internalType": "address", "name": "dex_", "type": "address" }, { "internalType": "address", "name": "settlementToken_", "type": "address" }], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [], "name": "CannotDetermineConversionBecauseWrappedTokenDoesNotExist", "type": "error" }, { "inputs": [], "name": "CannotDetermineGassetBecauseWrappedTokenDoesNotExist", "type": "error" }, { "inputs": [], "name": "CannotDetermineGassetMakeSureDestinationNetworkParametersAreCorrect", "type": "error" }, { "inputs": [], "name": "CannotRefuelGas", "type": "error" }, { "inputs": [], "name": "CannotReturnExcessiveMessageValueToYou", "type": "error" }, { "inputs": [], "name": "DestinationAddressCannotBeAddressZero", "type": "error" }, { "inputs": [], "name": "DestinationNetworkCannotBeCurrentNetwork", "type": "error" }, { "inputs": [], "name": "ECDSAInvalidSignature", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "length", "type": "uint256" }], "name": "ECDSAInvalidSignatureLength", "type": "error" }, { "inputs": [{ "internalType": "bytes32", "name": "s", "type": "bytes32" }], "name": "ECDSAInvalidSignatureS", "type": "error" }, { "inputs": [], "name": "GasPorterOnCurrentNetworkDoesNotSupportDexSwapAsGassetSourceYet", "type": "error" }, { "inputs": [], "name": "GasPorterOnCurrentNetworkDoesNotSupportGassetConversionYet", "type": "error" }, { "inputs": [], "name": "GasPorterOnDestinationNetworkDoesNotSupportGassetConversionYet", "type": "error" }, { "inputs": [], "name": "GassetAmountCannotBeZero", "type": "error" }, { "inputs": [], "name": "GassetCannotBeDolphinAddressDidYouMeanAddressZero", "type": "error" }, { "inputs": [], "name": "GassetPermitDataMustBeEmptyWhenGassetIsNativeToken", "type": "error" }, { "inputs": [], "name": "GassetTypeCannotBeERC20TokenWhenNativeTokensAreTheSame", "type": "error" }, { "inputs": [], "name": "GassetTypeCannotBeNativeTokenWhenNativeTokensAreDifferent", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint256", "name": "minimumAmount", "type": "uint256" }], "name": "InsufficientAmountInERC20Permit", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint256", "name": "minimumAmount", "type": "uint256" }], "name": "InsufficientMessageValue", "type": "error" }, { "inputs": [], "name": "InvalidConversionNonce", "type": "error" }, { "inputs": [], "name": "InvalidGassetTypeAndGassetSourceCombination", "type": "error" }, { "inputs": [], "name": "InvalidInitialization", "type": "error" }, { "inputs": [], "name": "InvalidToken", "type": "error" }, { "inputs": [], "name": "NotInitializing", "type": "error" }, { "inputs": [], "name": "OriginNetworkCannotBeCurrentNetwork", "type": "error" }, { "inputs": [], "name": "SwapCalldataCannotBeEmptyWhenGassetSourceIsDexSwap", "type": "error" }, { "inputs": [], "name": "SwapCalldataMustBeEmptyWhenGassetSourceIsNotDexSwap", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "SwapFailedBecauseDexGaveInsufficientAmount", "type": "error" }, { "inputs": [{ "internalType": "bytes", "name": "reason", "type": "bytes" }], "name": "SwapFailedBecauseDexReverted", "type": "error" }, { "inputs": [], "name": "SwapFailedBecauseDexRevertedWithoutExplanation", "type": "error" }, { "inputs": [], "name": "ThisFunctionIsOnlyCallableByGasPorter", "type": "error" }, { "inputs": [], "name": "TokenAmountCannotBeZero", "type": "error" }, { "inputs": [], "name": "TokenPermitDataMustBeEmptyWhenAssetAndGassetAreTheSameAndGassetPermitDataIsProvided", "type": "error" }, { "inputs": [], "name": "TokenPermitDataMustBeEmptyWhenAssetIsNativeToken", "type": "error" }, { "inputs": [], "name": "UnknownFunctionSelectorInERC20Permit", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "indexed": true, "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "indexed": false, "internalType": "address", "name": "signer", "type": "address" }, { "indexed": true, "internalType": "address", "name": "msgSender", "type": "address" }, { "indexed": false, "internalType": "bytes", "name": "reason", "type": "bytes" }], "name": "ConversionFailed", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint32", "name": "destinationNetwork", "type": "uint32" }, { "indexed": false, "internalType": "address", "name": "destinationAddress", "type": "address" }, { "indexed": false, "internalType": "address", "name": "gasset", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "bridgedGassetAmount", "type": "uint256" }], "name": "ConversionRequested", "type": "event" }, { "anonymous": false, "inputs": [], "name": "EIP712DomainChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "indexed": true, "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "indexed": true, "internalType": "address", "name": "signer", "type": "address" }], "name": "GassetConverted", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint64", "name": "version", "type": "uint64" }], "name": "Initialized", "type": "event" }, { "inputs": [], "name": "WETHToken", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bool", "name": "requestConversion", "type": "bool" }, { "internalType": "bool", "name": "forceUpdateGlobalExitRoot", "type": "bool" }, { "internalType": "uint32", "name": "destinationNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationAddress", "type": "address" }, { "internalType": "address", "name": "gasset", "type": "address" }, { "internalType": "enum GasPorter.GassetSource", "name": "gassetSource", "type": "uint8" }, { "internalType": "bytes", "name": "gassetPermitData", "type": "bytes" }, { "internalType": "uint256", "name": "gassetAmount", "type": "uint256" }, { "internalType": "bytes", "name": "swapCalldata", "type": "bytes" }, { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "tokenAmount", "type": "uint256" }, { "internalType": "bytes", "name": "tokenPermitData", "type": "bytes" }], "name": "bridgeAssetAndGas", "outputs": [], "stateMutability": "payable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "user", "type": "address" }, { "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }], "name": "conversionNonce", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "internalType": "uint256", "name": "conversionNonce", "type": "uint256" }, { "internalType": "address", "name": "settlementTokenDestinationAddress", "type": "address" }, { "internalType": "bytes", "name": "settlementTokenDestinationPermitData", "type": "bytes" }, { "internalType": "uint256", "name": "settlementTokenDestinationAmount", "type": "uint256" }, { "internalType": "bytes", "name": "destinationSwapCalldata", "type": "bytes" }, { "internalType": "uint256", "name": "destinationNativeTokenMinimumAmount", "type": "uint256" }], "internalType": "struct GasPorter.ConversionAuthorizationData", "name": "authorizationData", "type": "tuple" }, { "internalType": "address", "name": "signer", "type": "address" }], "name": "convertGasset", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "components": [{ "internalType": "uint32", "name": "originNetworkID", "type": "uint32" }, { "internalType": "bytes32", "name": "originNetworkTxHash", "type": "bytes32" }, { "internalType": "uint256", "name": "conversionNonce", "type": "uint256" }, { "internalType": "address", "name": "settlementTokenDestinationAddress", "type": "address" }, { "internalType": "bytes", "name": "settlementTokenDestinationPermitData", "type": "bytes" }, { "internalType": "uint256", "name": "settlementTokenDestinationAmount", "type": "uint256" }, { "internalType": "bytes", "name": "destinationSwapCalldata", "type": "bytes" }, { "internalType": "uint256", "name": "destinationNativeTokenMinimumAmount", "type": "uint256" }], "internalType": "struct GasPorter.ConversionAuthorizationData", "name": "data", "type": "tuple" }, { "internalType": "bytes", "name": "signature", "type": "bytes" }], "internalType": "struct GasPorter.ConversionAuthorization", "name": "authorization", "type": "tuple" }], "name": "convertGasset", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint32", "name": "destinationNetworkGasTokenNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationNetworkGasTokenAddress", "type": "address" }, { "internalType": "address", "name": "gasset", "type": "address" }], "name": "determineConversion", "outputs": [{ "internalType": "bool", "name": "conversionRequired", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint32", "name": "destinationNetworkGasTokenNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationNetworkGasTokenAddress", "type": "address" }, { "internalType": "enum GasPorter.GassetType", "name": "gassetType", "type": "uint8" }], "name": "determineGasset", "outputs": [{ "internalType": "address", "name": "gasset", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "dex", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "eip712Domain", "outputs": [{ "internalType": "bytes1", "name": "fields", "type": "bytes1" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "version", "type": "string" }, { "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "verifyingContract", "type": "address" }, { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, { "internalType": "uint256[]", "name": "extensions", "type": "uint256[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "gasTokenAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "gasTokenNetwork", "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "initialize", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "lxlyBridge", "outputs": [{ "internalType": "contract ILxlyBridge", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "networkID", "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "uint256", "name": "msgValue", "type": "uint256" }, { "internalType": "uint32", "name": "destinationNetwork", "type": "uint32" }, { "internalType": "uint32", "name": "destinationNetworkGasTokenNetwork", "type": "uint32" }, { "internalType": "address", "name": "destinationNetworkGasTokenAddress", "type": "address" }, { "internalType": "address", "name": "destinationAddress", "type": "address" }, { "internalType": "address", "name": "destinationGasPorterDex", "type": "address" }, { "internalType": "enum GasPorter.GassetType", "name": "gassetType", "type": "uint8" }, { "internalType": "enum GasPorter.GassetSource", "name": "gassetSource", "type": "uint8" }, { "internalType": "uint256", "name": "gassetAmount", "type": "uint256" }, { "internalType": "address", "name": "token", "type": "address" }, { "internalType": "uint256", "name": "tokenAmount", "type": "uint256" }, { "internalType": "bytes", "name": "gassetPermitData", "type": "bytes" }, { "internalType": "bytes", "name": "swapCalldata", "type": "bytes" }, { "internalType": "bytes", "name": "tokenPermitData", "type": "bytes" }, { "internalType": "bool", "name": "forceUpdateGlobalExitRoot", "type": "bool" }], "internalType": "struct GasPorter.Cargo", "name": "cargo", "type": "tuple" }], "name": "plotRoute", "outputs": [{ "internalType": "uint256", "name": "msgValue", "type": "uint256" }, { "internalType": "bytes", "name": "callData", "type": "bytes" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "settlementToken", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "settlementTokenIsNativeToken", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "version", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "pure", "type": "function" }, { "stateMutability": "payable", "type": "receive" }] diff --git a/src/abis/testnet/index.ts b/src/abis/testnet/index.ts index 5eea53f..52f5f6e 100644 --- a/src/abis/testnet/index.ts +++ b/src/abis/testnet/index.ts @@ -5,8 +5,10 @@ import PolygonZkEVMGlobalExitRoot from "./PolygonZkEVMGlobalExitRoot"; import PolygonZkEVMGlobalExitRootL2 from "./PolygonZkEVMGlobalExitRootL2"; import ZkEVMBridgeAdapter from "./ZkEVMBridgeAdapter"; import ZkEVMWrapper from "./ZkEVMWrapper"; +import GasPorter from "./GasPorter"; export default { + GasPorter, ERC20, PolygonZkEVM, PolygonZkEVMBridge, diff --git a/src/interfaces/base_client_config.ts b/src/interfaces/base_client_config.ts index 374f5fe..88521e8 100644 --- a/src/interfaces/base_client_config.ts +++ b/src/interfaces/base_client_config.ts @@ -3,6 +3,7 @@ export interface IProviderConfig { configuration?: { bridgeAddress?: string, wrapperAddress?: string, + gasPorterAddress?: string, isEIP1559Supported?: boolean, }; defaultConfig?: { diff --git a/src/interfaces/contracts.ts b/src/interfaces/contracts.ts index 523b7f6..07b6840 100644 --- a/src/interfaces/contracts.ts +++ b/src/interfaces/contracts.ts @@ -1,7 +1,8 @@ -import { Bridge, BridgeUtil, Wrapper } from "../lxly"; +import { Bridge, BridgeUtil, GasPorter, Wrapper } from "../lxly"; export interface IContracts { bridge: Bridge; bridgeUtil: BridgeUtil; wrapper: Wrapper; + gasPorter: GasPorter; } diff --git a/src/interfaces/gas_porter.ts b/src/interfaces/gas_porter.ts new file mode 100644 index 0000000..8748215 --- /dev/null +++ b/src/interfaces/gas_porter.ts @@ -0,0 +1,46 @@ +export enum GassetType { + NATIVE_TOKEN, + ERC20_TOKEN, + SETTLEMENT_TOKEN +} + +export enum GassetSource { + MSG_VALUE, + ERC20_ALLOWANCE, + DEX_SWAP +} + +export interface ICargo { + // Call: + msgValue: string; + // Destination: + + destinationNetwork: number; + destinationNetworkGasTokenNetwork: number; + destinationNetworkGasTokenAddress: string; + destinationAddress: string; + destinationGasPorterDex: string; + // Gasset: + gassetType: GassetType; + gassetSource: GassetSource; + gassetAmount: string; + // Asset: + token: string; + tokenAmount: string; + // Enforced, but not verified: + gassetPermitData: string; + swapCalldata: string; + tokenPermitData: string; + forceUpdateGlobalExitRoot: boolean; +} + +export interface IConversionAuthorization { + originNetworkID: number; + originNetworkTxHash: string; + conversionNonce: number; + settlementTokenDestinationAddress: string; + settlementTokenDestinationPermitData: string; + settlementTokenDestinationAmount: string; + destinationSwapCalldata: string; + destinationNativeTokenMinimumAmount: string; +} diff --git a/src/interfaces/gas_porters.ts b/src/interfaces/gas_porters.ts new file mode 100644 index 0000000..515212a --- /dev/null +++ b/src/interfaces/gas_porters.ts @@ -0,0 +1,5 @@ +import { GasPorter } from "../lxly"; + +export interface IGasPorters { + [key: number]: GasPorter; +} diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 1f86d55..8301e90 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -19,4 +19,6 @@ export * from "./approve_transaction_option"; export * from "./contracts"; export * from "./bridge_transaction_option"; export * from "./bridge"; +export * from "./gas_porter"; +export * from "./gas_porters"; export * from "./wrappers"; diff --git a/src/lxly/erc20.ts b/src/lxly/erc20.ts index d52c770..cc555db 100644 --- a/src/lxly/erc20.ts +++ b/src/lxly/erc20.ts @@ -15,6 +15,9 @@ import { BaseContract, BaseWeb3Client, IClaimPayload, + ICargo, + GassetSource, + IConversionAuthorization, } from '..'; import { IAllowanceTransactionOption, @@ -770,4 +773,142 @@ export class ERC20 extends Token { return this.getPermitData_(amount, spenderAddress); } + + /** + * Get the plot route call data for bridge asset and gas + * @param {ICargo} cargo + * @param {ITransactionOption} option + * + * @returns + * @memberof ERC20 + */ + getPlotRoute(cargo: ICargo, option?: ITransactionOption) { + const client = this.client.providers[this.contractParam.networkId].provider; + return this.gasPorter.plotRoute(cargo, option).then((data: any) => { + const callDataParams = client.decodeParameters( + `0x${data.callData.slice(10)}`, + [ + 'bool', + 'bool', + 'uint32', + 'address', + 'address', + 'uint32', + 'bytes', + 'uint256', + 'bytes', + 'address', + 'uint256', + 'bytes' + ] + ); + return { + bridgeAssetAndGas: { + requestConversion: callDataParams[0], + forceUpdateGlobalExitRoot: callDataParams[1], + destinationNetwork: callDataParams[2], + destinationAddress: callDataParams[3], + gasset: callDataParams[4], + gassetSource: callDataParams[5], + gassetPermitData: callDataParams[6] || '0x', + gassetAmount: callDataParams[7], + swapCalldata: callDataParams[8] || '0x', + token: callDataParams[9], + tokenAmount: callDataParams[10], + tokenPermitData: callDataParams[11] || '0x' + }, + callData: data.callData, + msgValue: data.msgValue + }; + }); + } + + /** + * bridge asset and gas function + * @param {boolean} requestConversion - It tells if the conversion is required on destination chain or not + * @param {boolean} forceUpdateGlobalExitRoot + * @param {number} destinationNetwork - the network on which the funds needs to be bridged + * @param {string} destinationAddress - the address to which funds will be deposited + * @param {string} gasset - address of the gas token + * @param {GassetSource} gassetSource - the source of the gas token amount. it can be directly msg value, or dex swap or if user already has the ERC20 token then erc20. + * @param {string} gassetPermitData - Permit data required to give permit to gasPorter for the gas token. + * @param {string} gassetAmount - amount of gas token to be bridged + * @param {string} swapCalldata - swap call data if swapping is required on the source chain + * @param {string} token - token to be bridged + * @param {string} tokenAmount - amount of token to be bridged + * @param {string} tokenPermitData - Permit data required to give permit to gasPorter for the token to be bridged. + * @param {ITransactionOption} option + * + * @returns + * @memberof ERC20 + */ + bridgeAssetAndGas( + requestConversion: boolean, + forceUpdateGlobalExitRoot: boolean, + destinationNetwork: number, + destinationAddress: string, + gasset: string, + gassetSource: GassetSource, + gassetPermitData: string, + gassetAmount: string, + swapCalldata: string, + token: string, + tokenAmount: string, + tokenPermitData: string, + option?: ITransactionOption + ) { + return this.gasPorter.bridgeAssetAndGas( + requestConversion, + forceUpdateGlobalExitRoot, + destinationNetwork, + destinationAddress, + gasset, + gassetSource, + gassetPermitData, + gassetAmount, + swapCalldata, + token, + tokenAmount, + tokenPermitData, + option + ); + } + + /** + * Get the plot route call data for bridge asset and gas and then do the bridgeAssetAndGas transaction + * @param {ICargo} cargo + * @param {ITransactionOption} option + * + * @returns + * @memberof ERC20 + */ + bridgeAssetAndGasWithPlotRoute(cargo: ICargo, option?: ITransactionOption) { + return this.getPlotRoute(cargo, option).then(data => { + return this.gasPorter.bridgeAssetAndGas( + data.bridgeAssetAndGas.requestConversion, + data.bridgeAssetAndGas.forceUpdateGlobalExitRoot, + data.bridgeAssetAndGas.destinationNetwork, + data.bridgeAssetAndGas.destinationAddress, + data.bridgeAssetAndGas.gasset, + data.bridgeAssetAndGas.gassetSource, + data.bridgeAssetAndGas.gassetPermitData, + data.bridgeAssetAndGas.gassetAmount, + data.bridgeAssetAndGas.swapCalldata, + data.bridgeAssetAndGas.token, + data.bridgeAssetAndGas.tokenAmount, + data.bridgeAssetAndGas.tokenPermitData, + { + value: data.msgValue + } + ); + }); + } + + convertGasset( + data: IConversionAuthorization, + signature: string, + option?: ITransactionOption + ) { + return this.gasPorter.convertGasset(data, signature, option); + } } diff --git a/src/lxly/gas_porter.ts b/src/lxly/gas_porter.ts new file mode 100644 index 0000000..da4c67a --- /dev/null +++ b/src/lxly/gas_porter.ts @@ -0,0 +1,112 @@ +import { BaseToken, Web3SideChainClient } from "../utils"; +import { IBaseClientConfig, ITransactionOption, ICargo, GassetSource, GassetType, IConversionAuthorization } from "../interfaces"; + +export class GasPorter extends BaseToken { + + constructor(client_: Web3SideChainClient, address: string, networkId: number) { + super({ + address: address, + name: 'GasPorter', + networkId: networkId + }, client_); + } + + method(methodName: string, ...args) { + return this.getContract().then(contract => { + return contract.method(methodName, ...args); + }); + } + + plotRoute( + cargo: ICargo, + option?: ITransactionOption + ) { + return this.method( + "plotRoute", + cargo + ).then(method => { + return this.processRead(method, option); + }); + } + + bridgeAssetAndGas( + requestConversion: boolean, + forceUpdateGlobalExitRoot: boolean, + destinationNetwork: number, + destinationAddress: string, + gasset: string, + gassetSource: GassetSource, + gassetPermitData: string, + gassetAmount: string, + swapCalldata: string, + token: string, + tokenAmount: string, + tokenPermitData: string, + option?: ITransactionOption + ) { + return this.method( + "bridgeAssetAndGas", + requestConversion, + forceUpdateGlobalExitRoot, + destinationNetwork, + destinationAddress, + gasset, + gassetSource, + gassetPermitData, + gassetAmount, + swapCalldata, + token, + tokenAmount, + tokenPermitData + ).then(method => { + return this.processWrite(method, option); + }); + } + + convertGasset( + data: IConversionAuthorization, + signature: string, + option?: ITransactionOption + ) { + return this.method( + "convertGasset", + data, + signature + ).then(method => { + return this.processWrite(method, option); + }); + } + + determineGasset( + destinationNetworkGasTokenNetwork: number, + destinationNetworkGasTokenAddress: string, + gassetType: GassetType, + option?: ITransactionOption + ) { + return this.method( + "determineGasset", + destinationNetworkGasTokenNetwork, + destinationNetworkGasTokenAddress, + gassetType + ).then(method => { + return this.processRead(method, option); + }); + } + + determineConversion( + destinationNetworkGasTokenNetwork: number, + destinationNetworkGasTokenAddress: string, + gasset: string, + option?: ITransactionOption + ) { + return this.method( + "determineConversion", + destinationNetworkGasTokenNetwork, + destinationNetworkGasTokenAddress, + gasset + ).then(method => { + return this.processRead(method, option); + }); + } + +} diff --git a/src/lxly/index.ts b/src/lxly/index.ts index 9a53dc8..4512a27 100644 --- a/src/lxly/index.ts +++ b/src/lxly/index.ts @@ -3,19 +3,22 @@ import { Contract } from "./contract"; import { Bridge } from "./bridge"; import { BridgeUtil } from "./bridge_util"; import { BridgeClient, setProofApi } from "../utils"; -import { IBaseClientConfig, IContracts, IWrappers } from "../interfaces"; +import { IBaseClientConfig, IContracts, IWrappers, IGasPorters } from "../interfaces"; import { config as urlConfig } from "../config"; import { service } from "../services"; import { Wrapper } from "./wrapper"; import { AbiItem } from "../types"; +import { GasPorter } from "./gas_porter"; export * from "./bridge"; export * from "./bridge_util"; export * from "./wrapper"; +export * from "./gas_porter"; export class LxLyClient extends BridgeClient { wrappers: IWrappers = {}; + gasPorters: IGasPorters = {}; init(config: IBaseClientConfig) { const client = this.client; @@ -36,6 +39,14 @@ export class LxLyClient extends BridgeClient { Number(key) ); } + + if (value.configuration.gasPorterAddress) { + this.gasPorters[key] = new GasPorter( + this.client, + value.configuration.gasPorterAddress, + Number(key) + ); + } } if (!service.network) { @@ -93,7 +104,8 @@ export class LxLyClient extends BridgeClient { return { bridge: this.bridges[networkId], bridgeUtil: this.bridgeUtil, - wrapper: this.wrappers[networkId] + wrapper: this.wrappers[networkId], + gasPorter: this.gasPorters[networkId] } as IContracts; } } diff --git a/src/lxly/token.ts b/src/lxly/token.ts index 0fc9eb9..5da54c7 100644 --- a/src/lxly/token.ts +++ b/src/lxly/token.ts @@ -23,6 +23,10 @@ export class Token extends BaseToken { return this.contracts.wrapper; } + protected get gasPorter() { + return this.contracts.gasPorter; + } + protected get bridgeUtil() { return this.contracts.bridgeUtil; } diff --git a/test/debug_ethers.js b/test/debug_ethers.js index 565f010..5d4c1c9 100644 --- a/test/debug_ethers.js +++ b/test/debug_ethers.js @@ -121,4 +121,3 @@ execute().then(_ => { console.error(err); process.exit(0); }) - diff --git a/test/debug_web3.js b/test/debug_web3.js index 2057f18..1a36d4f 100644 --- a/test/debug_web3.js +++ b/test/debug_web3.js @@ -4,6 +4,7 @@ const { LxLyClient, use, Converter } = require("@maticnetwork/lxlyjs"); const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3"); const HDWalletProvider = require("@truffle/hdwallet-provider"); +const { GassetType } = require("@maticnetwork/lxlyjs"); use(Web3ClientPlugin); @@ -22,6 +23,7 @@ const execute = async () => { configuration: { bridgeAddress: configuration[0].bridgeAddress, wrapperAddress: configuration[0].wrapperAddress, + gasPorterAddress: "0x17B8Ee96E3bcB3b04b3e8334de4524520C51caB4", isEIP1559Supported: false }, defaultConfig: { @@ -41,6 +43,40 @@ const execute = async () => { } }); + console.log( + "determineGasset", await client.gasPorters[0].determineGasset( + 0, "0x0000000000000000000000000000000000000000", GassetType.NATIVE_TOKEN + ) + ) + + console.log( + "determineConversion", await client.gasPorters[0].determineConversion( + 0, "0x0000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000" + ) + ) + + const tokenWithGas = client.erc20('0x44499312f493F62f2DFd3C6435Ca3603EbFCeeBa', 0); + + console.log( + "plotRoute", await tokenWithGas.getPlotRoute({ + msgValue: '100', + destinationNetwork: 1, + destinationNetworkGasTokenNetwork: 0, + destinationNetworkGasTokenAddress: '0x0000000000000000000000000000000000000000', + destinationAddress: '0x222112d597336CB201221Bf3acC0a6230475aF99', + destinationGasPorterDex: '0x0000000000000000000000000000000000000000', + gassetType: 0, + gassetSource: 0, + gassetAmount: '100', + token: '0x44499312f493F62f2DFd3C6435Ca3603EbFCeeBa', + tokenAmount: '10000', + gassetPermitData: '0x', + swapCalldata: '0x', + tokenPermitData: '0x', + forceUpdateGlobalExitRoot: true + }) + ) + const N0ERC20Token = client.erc20(tokens[0].erc20, 0); const N0EtherToken = client.erc20(tokens[0].ether, 0); @@ -51,7 +87,7 @@ const execute = async () => { // console.log('balance of N0ERC20Token is', await N0ERC20Token.getBalance(from)); // getEtherBalance on network 0 - console.log('balance of N0EtherToken is', await N0EtherToken.getBalance(from)); + // console.log('balance of N0EtherToken is', await N0EtherToken.getBalance(from)); // // getBalance on network 1 // console.log('balance of N1ERC20Token is', await N1ERC20Token.getBalance(from)); @@ -90,7 +126,7 @@ const execute = async () => { // // Bridge ERC20 from 0 to 1 with gas // var tx = await N0ERC20Token.bridgeAssetWithGas("10000000000000000000", from, '100000000000000000', 1, {returnTransaction: false}); // return console.log("hash", await tx.getTransactionHash()); - + // // Bridge Ether from 1 to 0 // var tx = await N1EtherToken.bridgeAsset("1000000000000000", from, 0, {returnTransaction: false}); // return console.log("hash", await tx.getTransactionHash());