UNPKG

loopso-bridge-sdk

Version:
2,394 lines (2,389 loc) 49.8 kB
// src/evm.ts import { ethers as ethers2 } from "ethers"; // src/constants.ts var ADDRESSES = { LOOPSO_LUKSO_CONTRACT_ADDRESS: "0x9Ef9dDaf6A02f2Ec5813c8746751D07E0c3CBe6c", LOOPSO_MUMBAI_CONTRACT_ADDRESS: "0x882ced5f17c5616eb242c263fefdf4c29b610bc5", LAJOS_TOKEN_ADDRESS_MUMBAI: "0x8cBF42B6590614AbE7AB5ffc89aF153F5d620fC3", LAJOS_NFT_ADDRESS_MUMBAI: "0xdc1C3734165aB9f0336eb6d10feCFD62c9CF28cc", WRAPPED_MATIC_ADDRESS_MUMBAI: "0xBAABeA853DD0BE32Df73083129070c65314cF0Ea", LAJOS_TOKEN_ADDRESS_WRAPPED_LUKSO: "0x4EFCc784eA3E259bdA3c6311D448416959B9bB9C", LAJOS_NFT_ADDRESS_WRAPPED_LUKSO: "0xf60b63DbA61F14647D9a146113548fB341A87d12", WRAPPED_LYX_ADDRESS_LUKSO: "0x5119A7Af90339D645ccdf9332d7813d4940DA19B" }; var LOOPSO_ABI = [ { inputs: [], stateMutability: "nonpayable", type: "constructor" }, { inputs: [], name: "AccessControlBadConfirmation", type: "error" }, { inputs: [ { internalType: "address", name: "account", type: "address" }, { internalType: "bytes32", name: "neededRole", type: "bytes32" } ], name: "AccessControlUnauthorizedAccount", type: "error" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "amount", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" } ], name: "NativeTokensReleased", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "bytes32", name: "attestationID", type: "bytes32" } ], name: "NonFungibleTokensBridgedBack", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "address", name: "token", type: "address" } ], name: "NonFungibleTokensReleased", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" }, { indexed: true, internalType: "bytes32", name: "previousAdminRole", type: "bytes32" }, { indexed: true, internalType: "bytes32", name: "newAdminRole", type: "bytes32" } ], name: "RoleAdminChanged", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" }, { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: true, internalType: "address", name: "sender", type: "address" } ], name: "RoleGranted", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" }, { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: true, internalType: "address", name: "sender", type: "address" } ], name: "RoleRevoked", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "bytes32", name: "attestationID", type: "bytes32" } ], name: "TokenAttested", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "bytes32", name: "transferID", type: "bytes32" }, { indexed: true, internalType: "enum ILoopso.TokenType", name: "tokenType", type: "uint8" } ], name: "TokensBridged", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "amount", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "bytes32", name: "attestationID", type: "bytes32" } ], name: "TokensBridgedBack", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "amount", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "address", name: "token", type: "address" } ], name: "TokensReleased", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "bytes32", name: "attestationID", type: "bytes32" } ], name: "WrappedNonFungibleTokensReleased", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "uint256", name: "amount", type: "uint256" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "bytes32", name: "attestationID", type: "bytes32" } ], name: "WrappedTokensReleased", type: "event" }, { inputs: [], name: "DEFAULT_ADMIN_ROLE", outputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "FEE_FUNGIBLE", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "FEE_NON_FUNGIBLE", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "RELAYER_ROLE", outputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], stateMutability: "view", type: "function" }, { inputs: [ { components: [ { internalType: "address", name: "tokenAddress", type: "address" }, { internalType: "uint256", name: "tokenChain", type: "uint256" }, { internalType: "enum ILoopso.TokenType", name: "tokenType", type: "uint8" }, { internalType: "uint8", name: "decimals", type: "uint8" }, { internalType: "string", name: "symbol", type: "string" }, { internalType: "string", name: "name", type: "string" }, { internalType: "address", name: "wrappedTokenAddress", type: "address" } ], internalType: "struct ILoopso.TokenAttestation", name: "attestation", type: "tuple" } ], name: "attestToken", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "", type: "uint256" } ], name: "attestationIds", outputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], name: "attestedTokens", outputs: [ { internalType: "address", name: "tokenAddress", type: "address" }, { internalType: "uint256", name: "tokenChain", type: "uint256" }, { internalType: "enum ILoopso.TokenType", name: "tokenType", type: "uint8" }, { internalType: "uint8", name: "decimals", type: "uint8" }, { internalType: "string", name: "symbol", type: "string" }, { internalType: "string", name: "name", type: "string" }, { internalType: "address", name: "wrappedTokenAddress", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "uint256", name: "_dstChain", type: "uint256" }, { internalType: "address", name: "_dstAddress", type: "address" } ], name: "bridgeNativeTokens", outputs: [], stateMutability: "payable", type: "function" }, { inputs: [ { internalType: "address", name: "_token", type: "address" }, { internalType: "uint256", name: "_tokenID", type: "uint256" }, { internalType: "string", name: "tokenURI", type: "string" }, { internalType: "uint256", name: "_dstChain", type: "uint256" }, { internalType: "address", name: "_dstAddress", type: "address" } ], name: "bridgeNonFungibleTokens", outputs: [], stateMutability: "payable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_tokenId", type: "uint256" }, { internalType: "address", name: "_to", type: "address" }, { internalType: "bytes32", name: "_attestationID", type: "bytes32" } ], name: "bridgeNonFungibleTokensBack", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "_token", type: "address" }, { internalType: "uint256", name: "_amount", type: "uint256" }, { internalType: "uint256", name: "_dstChain", type: "uint256" }, { internalType: "address", name: "_dstAddress", type: "address" } ], name: "bridgeTokens", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_amount", type: "uint256" }, { internalType: "address", name: "_to", type: "address" }, { internalType: "bytes32", name: "_attestationID", type: "bytes32" } ], name: "bridgeTokensBack", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [], name: "discountNft", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "feeReceiver", outputs: [ { internalType: "address", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "getAllSupportedTokens", outputs: [ { components: [ { internalType: "address", name: "tokenAddress", type: "address" }, { internalType: "uint256", name: "tokenChain", type: "uint256" }, { internalType: "enum ILoopso.TokenType", name: "tokenType", type: "uint8" }, { internalType: "uint8", name: "decimals", type: "uint8" }, { internalType: "string", name: "symbol", type: "string" }, { internalType: "string", name: "name", type: "string" }, { internalType: "address", name: "wrappedTokenAddress", type: "address" } ], internalType: "struct ILoopso.TokenAttestation[]", name: "", type: "tuple[]" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "bytes32", name: "role", type: "bytes32" } ], name: "getRoleAdmin", outputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "getSupportedTokensLength", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "bytes32", name: "role", type: "bytes32" }, { internalType: "address", name: "account", type: "address" } ], name: "grantRole", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "bytes32", name: "role", type: "bytes32" }, { internalType: "address", name: "account", type: "address" } ], name: "hasRole", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "_tokenAddress", type: "address" }, { internalType: "uint256", name: "_tokenChain", type: "uint256" } ], name: "isTokenSupported", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "_token", type: "address" } ], name: "isWrappedToken", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "", type: "address" }, { internalType: "address", name: "", type: "address" }, { internalType: "uint256", name: "", type: "uint256" }, { internalType: "bytes", name: "", type: "bytes" } ], name: "onERC721Received", outputs: [ { internalType: "bytes4", name: "", type: "bytes4" } ], stateMutability: "pure", type: "function" }, { inputs: [ { internalType: "uint256", name: "_amount", type: "uint256" }, { internalType: "address", name: "_to", type: "address" } ], name: "releaseNativeTokens", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_tokenId", type: "uint256" }, { internalType: "address", name: "_to", type: "address" }, { internalType: "address", name: "_token", type: "address" } ], name: "releaseNonFungibleTokens", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_amount", type: "uint256" }, { internalType: "address", name: "_to", type: "address" }, { internalType: "address", name: "_token", type: "address" } ], name: "releaseTokens", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_tokenId", type: "uint256" }, { internalType: "string", name: "_tokenURI", type: "string" }, { internalType: "address", name: "_to", type: "address" }, { internalType: "bytes32", name: "_attestationID", type: "bytes32" } ], name: "releaseWrappedNonFungibleTokens", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_amount", type: "uint256" }, { internalType: "address", name: "_to", type: "address" }, { internalType: "bytes32", name: "_attestationID", type: "bytes32" } ], name: "releaseWrappedTokens", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "bytes32", name: "role", type: "bytes32" }, { internalType: "address", name: "callerConfirmation", type: "address" } ], name: "renounceRole", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "bytes32", name: "role", type: "bytes32" }, { internalType: "address", name: "account", type: "address" } ], name: "revokeRole", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "_discountNft", type: "address" } ], name: "setDiscountNft", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "_feeReceiver", type: "address" } ], name: "setFeeReceiver", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_fee", type: "uint256" } ], name: "setFungibleFee", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "_fee", type: "uint256" } ], name: "setNonFungibleFee", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "contract ITokenFactory", name: "_tokenFactory", type: "address" } ], name: "setTokenFactory", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "bytes4", name: "interfaceId", type: "bytes4" } ], name: "supportsInterface", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "tokenFactory", outputs: [ { internalType: "contract ITokenFactory", name: "", type: "address" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], name: "tokenTransfers", outputs: [ { components: [ { internalType: "uint256", name: "timestamp", type: "uint256" }, { internalType: "uint256", name: "srcChain", type: "uint256" }, { internalType: "address", name: "srcAddress", type: "address" }, { internalType: "uint256", name: "dstChain", type: "uint256" }, { internalType: "address", name: "dstAddress", type: "address" }, { internalType: "address", name: "tokenAddress", type: "address" } ], internalType: "struct ILoopso.TokenTransferBase", name: "tokenTransfer", type: "tuple" }, { internalType: "uint256", name: "amount", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "bytes32", name: "", type: "bytes32" } ], name: "tokenTransfersNonFungible", outputs: [ { components: [ { internalType: "uint256", name: "timestamp", type: "uint256" }, { internalType: "uint256", name: "srcChain", type: "uint256" }, { internalType: "address", name: "srcAddress", type: "address" }, { internalType: "uint256", name: "dstChain", type: "uint256" }, { internalType: "address", name: "dstAddress", type: "address" }, { internalType: "address", name: "tokenAddress", type: "address" } ], internalType: "struct ILoopso.TokenTransferBase", name: "tokenTransfer", type: "tuple" }, { internalType: "uint256", name: "tokenID", type: "uint256" }, { internalType: "string", name: "tokenURI", type: "string" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "_wrappedToken", type: "address" } ], name: "wrappedTokenInfo", outputs: [ { components: [ { internalType: "address", name: "tokenAddress", type: "address" }, { internalType: "uint256", name: "tokenChain", type: "uint256" }, { internalType: "enum ILoopso.TokenType", name: "tokenType", type: "uint8" }, { internalType: "uint8", name: "decimals", type: "uint8" }, { internalType: "string", name: "symbol", type: "string" }, { internalType: "string", name: "name", type: "string" }, { internalType: "address", name: "wrappedTokenAddress", type: "address" } ], internalType: "struct ILoopso.TokenAttestation", name: "", type: "tuple" } ], stateMutability: "view", type: "function" } ]; var ERC20_ABI = [ { constant: true, inputs: [], name: "name", outputs: [ { name: "", type: "string" } ], payable: false, stateMutability: "view", type: "function" }, { constant: false, inputs: [ { name: "_spender", type: "address" }, { name: "_value", type: "uint256" } ], name: "approve", outputs: [ { name: "", type: "bool" } ], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: true, inputs: [], name: "totalSupply", outputs: [ { name: "", type: "uint256" } ], payable: false, stateMutability: "view", type: "function" }, { constant: false, inputs: [ { name: "_from", type: "address" }, { name: "_to", type: "address" }, { name: "_value", type: "uint256" } ], name: "transferFrom", outputs: [ { name: "", type: "bool" } ], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: true, inputs: [], name: "decimals", outputs: [ { name: "", type: "uint8" } ], payable: false, stateMutability: "view", type: "function" }, { constant: true, inputs: [ { name: "_owner", type: "address" } ], name: "balanceOf", outputs: [ { name: "balance", type: "uint256" } ], payable: false, stateMutability: "view", type: "function" }, { constant: true, inputs: [], name: "symbol", outputs: [ { name: "", type: "string" } ], payable: false, stateMutability: "view", type: "function" }, { constant: false, inputs: [ { name: "_to", type: "address" }, { name: "_value", type: "uint256" } ], name: "transfer", outputs: [ { name: "", type: "bool" } ], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: true, inputs: [ { name: "_owner", type: "address" }, { name: "_spender", type: "address" } ], name: "allowance", outputs: [ { name: "", type: "uint256" } ], payable: false, stateMutability: "view", type: "function" }, { payable: true, stateMutability: "payable", type: "fallback" }, { anonymous: false, inputs: [ { indexed: true, name: "owner", type: "address" }, { indexed: true, name: "spender", type: "address" }, { indexed: false, name: "value", type: "uint256" } ], name: "Approval", type: "event" }, { anonymous: false, inputs: [ { indexed: true, name: "from", type: "address" }, { indexed: true, name: "to", type: "address" }, { indexed: false, name: "value", type: "uint256" } ], name: "Transfer", type: "event" } ]; var ERC721_ABI = [ { constant: false, inputs: [ { internalType: "address", name: "to", type: "address" }, { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "approve", outputs: [], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: false, inputs: [ { internalType: "address", name: "to", type: "address" }, { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "mint", outputs: [], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: false, inputs: [ { internalType: "address", name: "from", type: "address" }, { internalType: "address", name: "to", type: "address" }, { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "safeTransferFrom", outputs: [], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: false, inputs: [ { internalType: "address", name: "from", type: "address" }, { internalType: "address", name: "to", type: "address" }, { internalType: "uint256", name: "tokenId", type: "uint256" }, { internalType: "bytes", name: "_data", type: "bytes" } ], name: "safeTransferFrom", outputs: [], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: false, inputs: [ { internalType: "address", name: "to", type: "address" }, { internalType: "bool", name: "approved", type: "bool" } ], name: "setApprovalForAll", outputs: [], payable: false, stateMutability: "nonpayable", type: "function" }, { constant: false, inputs: [ { internalType: "address", name: "from", type: "address" }, { internalType: "address", name: "to", type: "address" }, { internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "transferFrom", outputs: [], payable: false, stateMutability: "nonpayable", type: "function" }, { inputs: [], payable: false, stateMutability: "nonpayable", type: "constructor" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "from", type: "address" }, { indexed: true, internalType: "address", name: "to", type: "address" }, { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "Transfer", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: true, internalType: "address", name: "approved", type: "address" }, { indexed: true, internalType: "uint256", name: "tokenId", type: "uint256" } ], name: "Approval", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "owner", type: "address" }, { indexed: true, internalType: "address", name: "operator", type: "address" }, { indexed: false, internalType: "bool", name: "approved", type: "bool" } ], name: "ApprovalForAll", type: "event" }, { constant: true, inputs: [{ internalType: "address", name: "owner", type: "address" }], name: "balanceOf", outputs: [{ internalType: "uint256", name: "", type: "uint256" }], payable: false, stateMutability: "view", type: "function" }, { constant: true, inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }], name: "getApproved", outputs: [{ internalType: "address", name: "", type: "address" }], payable: false, stateMutability: "view", type: "function" }, { constant: true, inputs: [ { internalType: "address", name: "owner", type: "address" }, { internalType: "address", name: "operator", type: "address" } ], name: "isApprovedForAll", outputs: [{ internalType: "bool", name: "", type: "bool" }], payable: false, stateMutability: "view", type: "function" }, { constant: true, inputs: [{ internalType: "uint256", name: "tokenId", type: "uint256" }], name: "ownerOf", outputs: [{ internalType: "address", name: "", type: "address" }], payable: false, stateMutability: "view", type: "function" }, { constant: true, inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }], name: "supportsInterface", outputs: [{ internalType: "bool", name: "", type: "bool" }], payable: false, stateMutability: "view", type: "function" } ]; var WRAPPED_ABI = [ { inputs: [ { internalType: "string", name: "_name", type: "string" }, { internalType: "string", name: "_symbol", type: "string" }, { internalType: "uint8", name: "_decimals", type: "uint8" } ], stateMutability: "nonpayable", type: "constructor" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "src", type: "address" }, { indexed: true, internalType: "address", name: "guy", type: "address" }, { indexed: false, internalType: "uint256", name: "wad", type: "uint256" } ], name: "Approval", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "dst", type: "address" }, { indexed: false, internalType: "uint256", name: "wad", type: "uint256" } ], name: "Deposit", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "src", type: "address" }, { indexed: true, internalType: "address", name: "dst", type: "address" }, { indexed: false, internalType: "uint256", name: "wad", type: "uint256" } ], name: "Transfer", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "src", type: "address" }, { indexed: false, internalType: "uint256", name: "wad", type: "uint256" } ], name: "Withdrawal", type: "event" }, { inputs: [ { internalType: "address", name: "", type: "address" }, { internalType: "address", name: "", type: "address" } ], name: "allowance", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "guy", type: "address" }, { internalType: "uint256", name: "wad", type: "uint256" } ], name: "approve", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "", type: "address" } ], name: "balanceOf", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "decimals", outputs: [ { internalType: "uint8", name: "", type: "uint8" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "deposit", outputs: [], stateMutability: "payable", type: "function" }, { inputs: [], name: "name", outputs: [ { internalType: "string", name: "", type: "string" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "symbol", outputs: [ { internalType: "string", name: "", type: "string" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "totalSupply", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "dst", type: "address" }, { internalType: "uint256", name: "wad", type: "uint256" } ], name: "transfer", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address", name: "src", type: "address" }, { internalType: "address", name: "dst", type: "address" }, { internalType: "uint256", name: "wad", type: "uint256" } ], name: "transferFrom", outputs: [ { internalType: "bool", name: "", type: "bool" } ], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "uint256", name: "wad", type: "uint256" } ], name: "withdraw", outputs: [], stateMutability: "nonpayable", type: "function" }, { stateMutability: "payable", type: "receive" } ]; var FEE_ABI = [ "function FEE_NON_FUNGIBLE() external view returns (uint256 memory)", "function FEE_FUNGIBLE() external view returns (uint256 memory)" ]; // src/utils.ts import { ethers } from "ethers"; async function checkTokenAllowance(signer, tokenContract, contractAddressSrc, convertedAmount) { const currentAllowance = await tokenContract.allowance( await signer.getAddress(), contractAddressSrc ); if (currentAllowance < convertedAmount) { const approvalTx = await tokenContract.approve( contractAddressSrc, convertedAmount ); if (approvalTx) { const waitedTx = await approvalTx.wait(); return waitedTx; } else throw new Error("Approval transaction failed"); } } function getAttestationIDHash(wrappedTokenAddr, dstChainId) { const attestationID = ethers.solidityPackedKeccak256(["address", "uint256"], [wrappedTokenAddr, dstChainId]); return attestationID; } async function checkNftApproval(signer, erc721Contract, contractAddressSrc, tokenId) { const approvalTx = await erc721Contract.approve( contractAddressSrc, tokenId ); if (approvalTx) { const waitedTx = await approvalTx.wait(); return waitedTx; } else return null; } function getLoopsoContractFromChainId(chainId, signerOrProvider) { let contract = null; switch (chainId) { case 4201: contract = new ethers.Contract( ADDRESSES.LOOPSO_LUKSO_CONTRACT_ADDRESS, LOOPSO_ABI, signerOrProvider ); break; case 80001: contract = new ethers.Contract( ADDRESSES.LOOPSO_MUMBAI_CONTRACT_ADDRESS, LOOPSO_ABI, signerOrProvider ); break; default: break; } return contract; } function getLoopsoContractFromContractAddr(contractAddress, signerOrProvider) { let contract = null; switch (contractAddress) { case ADDRESSES.LOOPSO_LUKSO_CONTRACT_ADDRESS: contract = new ethers.Contract( contractAddress, LOOPSO_ABI, signerOrProvider ); break; case ADDRESSES.LOOPSO_MUMBAI_CONTRACT_ADDRESS: contract = new ethers.Contract( contractAddress, LOOPSO_ABI, signerOrProvider ); break; default: break; } return contract; } function getContractAddressFromChainId(chainId) { let contractAddress = null; switch (chainId) { case 4201: contractAddress = ADDRESSES.LOOPSO_LUKSO_CONTRACT_ADDRESS; break; case 80001: contractAddress = ADDRESSES.LOOPSO_MUMBAI_CONTRACT_ADDRESS; break; default: break; } if (contractAddress) { return contractAddress; } else { return null; } } // src/evm.ts async function bridgeTokens(contractAddressSrc, signer, tokenAddress, amount, dstAddress, dstChain) { const loopsoContractOnSrc = getLoopsoContractFromContractAddr( contractAddressSrc, signer ); const tokenContract = new ethers2.Contract(tokenAddress, ERC20_ABI, signer); const contractAddressDst = getContractAddressFromChainId(dstChain); await checkTokenAllowance( signer, tokenContract, contractAddressSrc, amount ); try { if (loopsoContractOnSrc && contractAddressDst) { const isWrappedTokenInfo = await getWrappedTokenInfo( contractAddressSrc, signer, tokenAddress ); const attestationId = getAttestationIDHash( isWrappedTokenInfo.tokenAddress, isWrappedTokenInfo.srcChain ); if (isWrappedTokenInfo.name) { const bridgeTx = await loopsoContractOnSrc.bridgeTokensBack( amount, dstAddress, attestationId ); if (bridgeTx) { const waitedTx = await bridgeTx.wait(); return waitedTx; } else { throw new Error("Bridge transaction failed"); } } else { const bridgeTx = await loopsoContractOnSrc.bridgeTokens( tokenAddress, amount, dstChain, dstAddress ); if (bridgeTx) { const waitedTx = await bridgeTx.wait(); return waitedTx; } else { throw new Error("Bridge transaction failed"); } } } else return null; } catch (error) { console.error("Error bridging tokens:", error); return null; } } async function bridgeNonFungibleTokens(contractAddressSrc, signer, tokenAddress, dstAddress, dstChain, tokenId, tokenUri) { const loopsoContractOnSrc = getLoopsoContractFromContractAddr( contractAddressSrc, signer ); const contractAddressDst = getContractAddressFromChainId(dstChain); const erc721Contract = new ethers2.Contract(tokenAddress, ERC721_ABI, signer); try { const approved = await checkNftApproval( signer, erc721Contract, contractAddressSrc, tokenId ); if (approved && loopsoContractOnSrc && contractAddressDst) { const isWrappedTokenInfo = await getWrappedTokenInfo( contractAddressSrc, signer, tokenAddress ); const attestationId = getAttestationIDHash( isWrappedTokenInfo.tokenAddress, isWrappedTokenInfo.srcChain ); if (isWrappedTokenInfo.name) { const bridgeTx = await loopsoContractOnSrc.bridgeNonFungibleTokensBack( tokenId, dstAddress, attestationId ); if (bridgeTx) { const waitedTx = await bridgeTx.wait(); return waitedTx; } else { throw new Error("Bridge transaction failed"); } } else { const bridgeTx = await loopsoContractOnSrc.bridgeNonFungibleTokens( tokenAddress, tokenId, tokenUri, dstChain, dstAddress, { value: 0 } ); if (bridgeTx) { const waitedTx = await bridgeTx.wait(); return waitedTx; } else { throw new Error("Bridge transaction failed"); } } } else throw new Error("Missing fields to perform bridge"); } catch (error) { console.error("Error bridging tokens:", error); return null; } } async function getAllSupportedTokens(contractAddress, signerOrProvider) { const loopsoContract = new ethers2.Contract( contractAddress, LOOPSO_ABI, signerOrProvider ); return loopsoContract.getAllSupportedTokens(); } async function getFee(contractAddress, signerOrProvider, isFungible) { const loopsoContract = new ethers2.Contract( contractAddress, LOOPSO_ABI, signerOrProvider ); if (isFungible) { const bpFee = await loopsoContract.FEE_FUNGIBLE(); const decimalFee = Number(bpFee) / 1e4; return decimalFee; } else { const etherFee = await loopsoContract.FEE_NON_FUNGIBLE(); return Number(etherFee); } } async function isTokenSupported(contractAddressDst, signerOrProvider, tokenAddress, srcChain) { const destLoopsoContract = new ethers2.Contract( contractAddressDst, LOOPSO_ABI, signerOrProvider ); return await destLoopsoContract.isTokenSupported(tokenAddress, srcChain); } async function getWrappedTokenInfo(contractAddressOnSrc, signerOrProvider, wrappedTokenAddress) { const loopsoContract = new ethers2.Contract( contractAddressOnSrc, LOOPSO_ABI, signerOrProvider ); const tokenInfo = await loopsoContract.wrappedTokenInfo(wrappedTokenAddress); const wrappedTokenInfo = { tokenAddress: tokenInfo[0], srcChain: tokenInfo[1], tokenType: tokenInfo[2], decimals: tokenInfo[3], symbol: tokenInfo[4], name: tokenInfo[5], wrappedTokenAddress: tokenInfo[6] }; return wrappedTokenInfo; } async function wrapNativeToken(signerOrProvider, chainId, amount) { let wrappedContract; amount = amount * BigInt(10 ** 18); switch (chainId) { case 80001: wrappedContract = new ethers2.Contract( ADDRESSES.WRAPPED_MATIC_ADDRESS_MUMBAI, WRAPPED_ABI, signerOrProvider ); break; case 4201: wrappedContract = new ethers2.Contract( ADDRESSES.WRAPPED_LYX_ADDRESS_LUKSO, WRAPPED_ABI, signerOrProvider ); break; default: return new Error("Invalid ChainId"); } const tx = await wrappedContract.deposit({ value: amount }); await tx.wait(); if (tx) { const waitedTx = await tx.wait(); return waitedTx; } else { throw new Error("Wrapping failed"); } } async function unwrapNativeToken(signerOrProvider, chainId, amount) { let wrappedContract; amount = amount * BigInt(10 ** 18); switch (chainId) { case 80001: wrappedContract = new ethers2.Contract( ADDRESSES.WRAPPED_MATIC_ADDRESS_MUMBAI, WRAPPED_ABI, signerOrProvider ); break; case 4201: wrappedContract = new ethers2.Contract( ADDRESSES.WRAPPED_LYX_ADDRESS_LUKSO, WRAPPED_ABI, signerOrProvider ); break; default: return new Error("Invalid ChainId"); } const tx = await wrappedContract.withdraw(amount); if (tx) { const waitedTx = await tx.wait(); return waitedTx; } else { throw new Error("Unwrapping failed"); } } // src/nfts.ts import fetch from "cross-fetch"; var getLuksoNftMetadata = async (filteredData) => { try { const metadataPromises = filteredData.map(async (item) => { console.log(item, "this is item"); const response = await fetch(`https://api.explorer.execution.testnet.lukso.network/api/v2/tokens/${item.address}/instances`, { method: "GET", headers: { "Accept": "application/json" } }); if (!response.ok) { throw new Error(`Failed to fetch data: ${response.statusText}`); } const allMetaData = await response.json(); const extractedMetadata = allMetaData.items.map((metadataItem) => { var _a, _b, _c; return { contractAddress: item.address, id: metadataItem.id, metadata: { description: (_a = metadataItem == null ? void 0 : metadataItem.metadata) == null ? void 0 : _a.description, image: (_b = metadataItem == null ? void 0 : metadataItem.metadata) == null ? void 0 : _b.image, name: (_c = metadataItem == null ? void 0 : metadataItem.metadata) == null ? void 0 : _c.name } }; }); console.log(extractedMetadata, "Extracted Metadata"); return extractedMetadata; }); const metadataArray = await Promise.all(metadataPromises); const flattenedMetadataArray = metadataArray.flat(); return flattenedMetadataArray; } catch (error) { console.error("Error fetching data:", error); return null; } }; var fetchLuksoNfts = async (searchText) => { try { const response = await fetch(`https://api.explorer.execution.testnet.lukso.network/api/v2/search?q=${searchText}`, { method: "GET", headers: { "Accept": "application/json" } }); if (!response.ok) { throw new Error(`Failed to fetch data: ${response.statusText}`); } const data = await response.json(); const filteredData = data.items.filter((item) => item.type === "token" && item.token_type === "ERC-721"); const nftMetaData = await getLuksoNftMetadata(filteredData); return nftMetaData; } catch (error) { console.error("Error fetching data:", error); return null; } }; export { ADDRESSES, ERC20_ABI, ERC721_ABI, FEE_ABI, LOOPSO_ABI, WRAPPED_ABI, bridgeNonFungibleTokens, bridgeTokens, checkNftApproval, checkTokenAllowance, fetchLuksoNfts, getAllSupportedTokens, getAttestationIDHash, getContractAddressFromChainId, getFee, getLoopsoContractFromChainId, getLoopsoContractFromContractAddr, getLuksoNftMetadata, getWrappedTokenInfo, isTokenSupported, unwrapNativeToken, wrapNativeToken };