diff --git a/.changeset/fifty-spiders-wave.md b/.changeset/fifty-spiders-wave.md new file mode 100644 index 0000000..8b68b58 --- /dev/null +++ b/.changeset/fifty-spiders-wave.md @@ -0,0 +1,5 @@ +--- +'@protocolink/logics': minor +--- + +add StargateV2 diff --git a/src/logics/index.ts b/src/logics/index.ts index b7ec934..af5166a 100644 --- a/src/logics/index.ts +++ b/src/logics/index.ts @@ -12,6 +12,7 @@ export * as radiantv2 from './radiant-v2'; export * as sonne from './sonne'; export * as spark from './spark'; export * as stargate from './stargate'; +export * as stargatev2 from './stargate-v2'; export * as syncswap from './syncswap'; export * as uniswapv3 from './uniswap-v3'; export * as utility from './utility'; diff --git a/src/logics/stargate-v2/abis/StargatePool.json b/src/logics/stargate-v2/abis/StargatePool.json new file mode 100644 index 0000000..c138023 --- /dev/null +++ b/src/logics/stargate-v2/abis/StargatePool.json @@ -0,0 +1,911 @@ +[ + { + "inputs": [ + { "internalType": "string", "name": "_lpTokenName", "type": "string" }, + { "internalType": "string", "name": "_lpTokenSymbol", "type": "string" }, + { "internalType": "address", "name": "_token", "type": "address" }, + { "internalType": "uint8", "name": "_tokenDecimals", "type": "uint8" }, + { "internalType": "uint8", "name": "_sharedDecimals", "type": "uint8" }, + { "internalType": "address", "name": "_endpoint", "type": "address" }, + { "internalType": "address", "name": "_owner", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "InvalidLocalDecimals", "type": "error" }, + { "inputs": [], "name": "Path_AlreadyHasCredit", "type": "error" }, + { "inputs": [], "name": "Path_InsufficientCredit", "type": "error" }, + { "inputs": [], "name": "Path_UnlimitedCredit", "type": "error" }, + { + "inputs": [ + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" } + ], + "name": "SlippageExceeded", + "type": "error" + }, + { "inputs": [], "name": "StargatePoolUSDC_BurnAmountExceedsBalance", "type": "error" }, + { "inputs": [], "name": "Stargate_InsufficientFare", "type": "error" }, + { "inputs": [], "name": "Stargate_InvalidAmount", "type": "error" }, + { "inputs": [], "name": "Stargate_InvalidPath", "type": "error" }, + { "inputs": [], "name": "Stargate_InvalidTokenDecimals", "type": "error" }, + { "inputs": [], "name": "Stargate_LzTokenUnavailable", "type": "error" }, + { "inputs": [], "name": "Stargate_OnlyTaxi", "type": "error" }, + { "inputs": [], "name": "Stargate_OutflowFailed", "type": "error" }, + { "inputs": [], "name": "Stargate_Paused", "type": "error" }, + { "inputs": [], "name": "Stargate_RecoverTokenUnsupported", "type": "error" }, + { "inputs": [], "name": "Stargate_ReentrantCall", "type": "error" }, + { "inputs": [], "name": "Stargate_SlippageTooHigh", "type": "error" }, + { "inputs": [], "name": "Stargate_Unauthorized", "type": "error" }, + { "inputs": [], "name": "Stargate_UnreceivedTokenNotFound", "type": "error" }, + { "inputs": [], "name": "Transfer_ApproveFailed", "type": "error" }, + { "inputs": [], "name": "Transfer_TransferFailed", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { "internalType": "address", "name": "feeLib", "type": "address" }, + { "internalType": "address", "name": "planner", "type": "address" }, + { "internalType": "address", "name": "treasurer", "type": "address" }, + { "internalType": "address", "name": "tokenMessaging", "type": "address" }, + { "internalType": "address", "name": "creditMessaging", "type": "address" }, + { "internalType": "address", "name": "lzToken", "type": "address" } + ], + "indexed": false, + "internalType": "struct StargateBase.AddressConfig", + "name": "config", + "type": "tuple" + } + ], + "name": "AddressConfigSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "uint64", "name": "amount", "type": "uint64" } + ], + "indexed": false, + "internalType": "struct Credit[]", + "name": "credits", + "type": "tuple[]" + } + ], + "name": "CreditsReceived", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "uint64", "name": "amount", "type": "uint64" } + ], + "indexed": false, + "internalType": "struct Credit[]", + "name": "credits", + "type": "tuple[]" + } + ], + "name": "CreditsSent", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "receiver", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amountLD", "type": "uint256" } + ], + "name": "Deposited", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "indexed": false, "internalType": "bool", "name": "oft", "type": "bool" } + ], + "name": "OFTPathSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "indexed": false, "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "indexed": true, "internalType": "address", "name": "toAddress", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" } + ], + "name": "OFTReceived", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "indexed": false, "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "indexed": true, "internalType": "address", "name": "fromAddress", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amountSentLD", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" } + ], + "name": "OFTSent", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint64", "name": "amountSD", "type": "uint64" }], + "name": "Path_CreditBurned", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "bool", "name": "paused", "type": "bool" }], + "name": "PauseSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], + "name": "PlannerFeeWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "payer", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "receiver", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amountLD", "type": "uint256" } + ], + "name": "Redeemed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": false, "internalType": "uint64", "name": "amountSD", "type": "uint64" }], + "name": "TreasuryFeeAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint64", "name": "amountSD", "type": "uint64" } + ], + "name": "TreasuryFeeWithdrawn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": false, "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "indexed": false, "internalType": "uint8", "name": "index", "type": "uint8" }, + { "indexed": false, "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "indexed": false, "internalType": "address", "name": "receiver", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "indexed": false, "internalType": "bytes", "name": "composeMsg", "type": "bytes" } + ], + "name": "UnreceivedTokenCached", + "type": "event" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_amountLD", "type": "uint256" }], + "name": "addTreasuryFee", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_burnAdmin", "type": "address" }, + { "internalType": "uint64", "name": "_burnAllowanceSD", "type": "uint64" } + ], + "name": "allowBurn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "approvalRequired", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "burnAdmin", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "burnAllowanceSD", + "outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "burnLockedUSDC", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "deficitOffset", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_receiver", "type": "address" }, + { "internalType": "uint256", "name": "_amountLD", "type": "uint256" } + ], + "name": "deposit", + "outputs": [{ "internalType": "uint256", "name": "amountLD", "type": "uint256" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "endpoint", + "outputs": [{ "internalType": "contract ILayerZeroEndpointV2", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAddressConfig", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "feeLib", "type": "address" }, + { "internalType": "address", "name": "planner", "type": "address" }, + { "internalType": "address", "name": "treasurer", "type": "address" }, + { "internalType": "address", "name": "tokenMessaging", "type": "address" }, + { "internalType": "address", "name": "creditMessaging", "type": "address" }, + { "internalType": "address", "name": "lzToken", "type": "address" } + ], + "internalType": "struct StargateBase.AddressConfig", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTransferGasLimit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "localEid", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lpToken", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oftVersion", + "outputs": [ + { "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }, + { "internalType": "uint64", "name": "version", "type": "uint64" } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint32", "name": "eid", "type": "uint32" }], + "name": "paths", + "outputs": [{ "internalType": "uint64", "name": "credit", "type": "uint64" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "plannerFee", + "outputs": [{ "internalType": "uint256", "name": "available", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "poolBalance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "to", "type": "bytes32" }, + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "extraOptions", "type": "bytes" }, + { "internalType": "bytes", "name": "composeMsg", "type": "bytes" }, + { "internalType": "bytes", "name": "oftCmd", "type": "bytes" } + ], + "internalType": "struct SendParam", + "name": "_sendParam", + "type": "tuple" + } + ], + "name": "quoteOFT", + "outputs": [ + { + "components": [ + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "maxAmountLD", "type": "uint256" } + ], + "internalType": "struct OFTLimit", + "name": "limit", + "type": "tuple" + }, + { + "components": [ + { "internalType": "int256", "name": "feeAmountLD", "type": "int256" }, + { "internalType": "string", "name": "description", "type": "string" } + ], + "internalType": "struct OFTFeeDetail[]", + "name": "oftFeeDetails", + "type": "tuple[]" + }, + { + "components": [ + { "internalType": "uint256", "name": "amountSentLD", "type": "uint256" }, + { "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" } + ], + "internalType": "struct OFTReceipt", + "name": "receipt", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "to", "type": "bytes32" }, + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "extraOptions", "type": "bytes" }, + { "internalType": "bytes", "name": "composeMsg", "type": "bytes" }, + { "internalType": "bytes", "name": "oftCmd", "type": "bytes" } + ], + "internalType": "struct SendParam", + "name": "_sendParam", + "type": "tuple" + }, + { "internalType": "bool", "name": "_payInLzToken", "type": "bool" } + ], + "name": "quoteRedeemSend", + "outputs": [ + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "fee", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "to", "type": "bytes32" }, + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "extraOptions", "type": "bytes" }, + { "internalType": "bytes", "name": "composeMsg", "type": "bytes" }, + { "internalType": "bytes", "name": "oftCmd", "type": "bytes" } + ], + "internalType": "struct SendParam", + "name": "_sendParam", + "type": "tuple" + }, + { "internalType": "bool", "name": "_payInLzToken", "type": "bool" } + ], + "name": "quoteSend", + "outputs": [ + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "fee", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "_srcEid", "type": "uint32" }, + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "uint64", "name": "amount", "type": "uint64" } + ], + "internalType": "struct Credit[]", + "name": "_credits", + "type": "tuple[]" + } + ], + "name": "receiveCredits", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "sender", "type": "bytes32" }, + { "internalType": "uint64", "name": "nonce", "type": "uint64" } + ], + "internalType": "struct Origin", + "name": "_origin", + "type": "tuple" + }, + { "internalType": "bytes32", "name": "_guid", "type": "bytes32" }, + { "internalType": "uint8", "name": "_seatNumber", "type": "uint8" }, + { "internalType": "address", "name": "_receiver", "type": "address" }, + { "internalType": "uint64", "name": "_amountSD", "type": "uint64" } + ], + "name": "receiveTokenBus", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "sender", "type": "bytes32" }, + { "internalType": "uint64", "name": "nonce", "type": "uint64" } + ], + "internalType": "struct Origin", + "name": "_origin", + "type": "tuple" + }, + { "internalType": "bytes32", "name": "_guid", "type": "bytes32" }, + { "internalType": "address", "name": "_receiver", "type": "address" }, + { "internalType": "uint64", "name": "_amountSD", "type": "uint64" }, + { "internalType": "bytes", "name": "_composeMsg", "type": "bytes" } + ], + "name": "receiveTokenTaxi", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_token", "type": "address" }, + { "internalType": "address", "name": "_to", "type": "address" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "recoverToken", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_amountLD", "type": "uint256" }, + { "internalType": "address", "name": "_receiver", "type": "address" } + ], + "name": "redeem", + "outputs": [{ "internalType": "uint256", "name": "amountLD", "type": "uint256" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "to", "type": "bytes32" }, + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "extraOptions", "type": "bytes" }, + { "internalType": "bytes", "name": "composeMsg", "type": "bytes" }, + { "internalType": "bytes", "name": "oftCmd", "type": "bytes" } + ], + "internalType": "struct SendParam", + "name": "_sendParam", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "_fee", + "type": "tuple" + }, + { "internalType": "address", "name": "_refundAddress", "type": "address" } + ], + "name": "redeemSend", + "outputs": [ + { + "components": [ + { "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "internalType": "uint64", "name": "nonce", "type": "uint64" }, + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "fee", + "type": "tuple" + } + ], + "internalType": "struct MessagingReceipt", + "name": "msgReceipt", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "amountSentLD", "type": "uint256" }, + { "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" } + ], + "internalType": "struct OFTReceipt", + "name": "oftReceipt", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "_owner", "type": "address" }], + "name": "redeemable", + "outputs": [{ "internalType": "uint256", "name": "amountLD", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "renounceOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "bytes32", "name": "_guid", "type": "bytes32" }, + { "internalType": "uint8", "name": "_index", "type": "uint8" }, + { "internalType": "uint32", "name": "_srcEid", "type": "uint32" }, + { "internalType": "address", "name": "_receiver", "type": "address" }, + { "internalType": "uint256", "name": "_amountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "_composeMsg", "type": "bytes" } + ], + "name": "retryReceiveToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "to", "type": "bytes32" }, + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "extraOptions", "type": "bytes" }, + { "internalType": "bytes", "name": "composeMsg", "type": "bytes" }, + { "internalType": "bytes", "name": "oftCmd", "type": "bytes" } + ], + "internalType": "struct SendParam", + "name": "_sendParam", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "_fee", + "type": "tuple" + }, + { "internalType": "address", "name": "_refundAddress", "type": "address" } + ], + "name": "send", + "outputs": [ + { + "components": [ + { "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "internalType": "uint64", "name": "nonce", "type": "uint64" }, + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "fee", + "type": "tuple" + } + ], + "internalType": "struct MessagingReceipt", + "name": "msgReceipt", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "amountSentLD", "type": "uint256" }, + { "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" } + ], + "internalType": "struct OFTReceipt", + "name": "oftReceipt", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "_dstEid", "type": "uint32" }, + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "uint64", "name": "amount", "type": "uint64" }, + { "internalType": "uint64", "name": "minAmount", "type": "uint64" } + ], + "internalType": "struct TargetCredit[]", + "name": "_credits", + "type": "tuple[]" + } + ], + "name": "sendCredits", + "outputs": [ + { + "components": [ + { "internalType": "uint32", "name": "srcEid", "type": "uint32" }, + { "internalType": "uint64", "name": "amount", "type": "uint64" } + ], + "internalType": "struct Credit[]", + "name": "", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "uint32", "name": "dstEid", "type": "uint32" }, + { "internalType": "bytes32", "name": "to", "type": "bytes32" }, + { "internalType": "uint256", "name": "amountLD", "type": "uint256" }, + { "internalType": "uint256", "name": "minAmountLD", "type": "uint256" }, + { "internalType": "bytes", "name": "extraOptions", "type": "bytes" }, + { "internalType": "bytes", "name": "composeMsg", "type": "bytes" }, + { "internalType": "bytes", "name": "oftCmd", "type": "bytes" } + ], + "internalType": "struct SendParam", + "name": "_sendParam", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "_fee", + "type": "tuple" + }, + { "internalType": "address", "name": "_refundAddress", "type": "address" } + ], + "name": "sendToken", + "outputs": [ + { + "components": [ + { "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "internalType": "uint64", "name": "nonce", "type": "uint64" }, + { + "components": [ + { "internalType": "uint256", "name": "nativeFee", "type": "uint256" }, + { "internalType": "uint256", "name": "lzTokenFee", "type": "uint256" } + ], + "internalType": "struct MessagingFee", + "name": "fee", + "type": "tuple" + } + ], + "internalType": "struct MessagingReceipt", + "name": "msgReceipt", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint256", "name": "amountSentLD", "type": "uint256" }, + { "internalType": "uint256", "name": "amountReceivedLD", "type": "uint256" } + ], + "internalType": "struct OFTReceipt", + "name": "oftReceipt", + "type": "tuple" + }, + { + "components": [ + { "internalType": "uint72", "name": "ticketId", "type": "uint72" }, + { "internalType": "bytes", "name": "passengerBytes", "type": "bytes" } + ], + "internalType": "struct Ticket", + "name": "ticket", + "type": "tuple" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { "internalType": "address", "name": "feeLib", "type": "address" }, + { "internalType": "address", "name": "planner", "type": "address" }, + { "internalType": "address", "name": "treasurer", "type": "address" }, + { "internalType": "address", "name": "tokenMessaging", "type": "address" }, + { "internalType": "address", "name": "creditMessaging", "type": "address" }, + { "internalType": "address", "name": "lzToken", "type": "address" } + ], + "internalType": "struct StargateBase.AddressConfig", + "name": "_config", + "type": "tuple" + } + ], + "name": "setAddressConfig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_deficitOffsetLD", "type": "uint256" }], + "name": "setDeficitOffset", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint32", "name": "_dstEid", "type": "uint32" }, + { "internalType": "bool", "name": "_oft", "type": "bool" } + ], + "name": "setOFTPath", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bool", "name": "_paused", "type": "bool" }], + "name": "setPause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "uint256", "name": "_gasLimit", "type": "uint256" }], + "name": "setTransferGasLimit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "sharedDecimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "stargateType", + "outputs": [{ "internalType": "enum StargateType", "name": "", "type": "uint8" }], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "status", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryFee", + "outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "tvl", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes32", "name": "guid", "type": "bytes32" }, + { "internalType": "uint8", "name": "index", "type": "uint8" } + ], + "name": "unreceivedTokens", + "outputs": [{ "internalType": "bytes32", "name": "hash", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { "inputs": [], "name": "withdrawPlannerFee", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "_to", "type": "address" }, + { "internalType": "uint64", "name": "_amountSD", "type": "uint64" } + ], + "name": "withdrawTreasuryFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/logics/stargate-v2/configs.ts b/src/logics/stargate-v2/configs.ts new file mode 100644 index 0000000..d7395b3 --- /dev/null +++ b/src/logics/stargate-v2/configs.ts @@ -0,0 +1,433 @@ +import * as common from '@protocolink/common'; +import { mainnetTokens, metisTokens } from './tokens'; + +export enum EndpointId { + ETHEREUM = 30101, + BNB = 30102, + AVALANCHE = 30106, + ARBITRUM = 30110, + OPTIMISM = 30111, + POLYGON = 30109, + METIS = 30151, + BASE = 30184, + IOTA = 30284, +} + +export enum PoolId { + USDC = 1, + USDT = 2, + ETH = 13, + METIS = 17, +} + +export interface Pool { + id: number; + token: common.Token; + address: string; + destinations: { chainId: number; endpointId: number }[]; +} + +export interface PoolConfig extends Pool { + chainId: number; +} + +export interface Config { + eid: number; + chainId: number; + pools: Pool[]; +} + +export const configs: Config[] = [ + { + eid: EndpointId.ETHEREUM, + chainId: common.ChainId.mainnet, + pools: [ + { + id: PoolId.ETH, + token: common.mainnetTokens.ETH, + address: '0x77b2043768d28E9C9aB44E1aBfC95944bcE57931', + destinations: [ + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + { + id: PoolId.USDC, + token: common.mainnetTokens.USDC, + address: '0xc026395860Db2d07ee33e05fE50ed7bD583189C7', + destinations: [ + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + { + id: PoolId.USDT, + token: common.mainnetTokens.USDT, + address: '0x933597a323Eb81cAe705C5bC29985172fd5A3973', + destinations: [ + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + { + id: PoolId.METIS, + token: mainnetTokens.Metis, + address: '0xcDafB1b2dB43f366E48e6F614b8DCCBFeeFEEcD3', + destinations: [{ chainId: common.ChainId.metis, endpointId: EndpointId.METIS }], + }, + ], + }, + { + eid: EndpointId.BNB, + chainId: common.ChainId.bnb, + pools: [ + { + id: PoolId.USDT, + token: common.bnbTokens.USDT, + address: '0x138EB30f73BC423c6455C53df6D89CB01d9eBc63', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, + { + eid: EndpointId.AVALANCHE, + chainId: common.ChainId.avalanche, + pools: [ + { + id: PoolId.USDC, + token: common.avalancheTokens.USDC, + address: '0x5634c4a5FEd09819E3c46D86A965Dd9447d86e47', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + { + id: PoolId.USDT, + token: common.avalancheTokens.USDt, + address: '0x12dC9256Acc9895B076f6638D628382881e62CeE', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + ], + }, + { + eid: EndpointId.POLYGON, + chainId: common.ChainId.polygon, + pools: [ + { + id: PoolId.USDC, + token: common.polygonTokens.USDC, + address: '0x9Aa02D4Fae7F58b8E8f34c66E756cC734DAc7fe4', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + { + id: PoolId.USDT, + token: common.polygonTokens.USDT, + address: '0xd47b03ee6d86Cf251ee7860FB2ACf9f91B9fD4d7', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, + { + eid: EndpointId.ARBITRUM, + chainId: common.ChainId.arbitrum, + pools: [ + { + id: PoolId.ETH, + token: common.arbitrumTokens.ETH, + address: '0xA45B5130f36CDcA45667738e2a258AB09f4A5f7F', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + ], + }, + { + id: PoolId.USDC, + token: common.arbitrumTokens.USDC, + address: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + { + id: PoolId.USDT, + token: common.arbitrumTokens.USDT, + address: '0xcE8CcA271Ebc0533920C83d39F417ED6A0abB7D0', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, + { + eid: EndpointId.OPTIMISM, + chainId: common.ChainId.optimism, + pools: [ + { + id: PoolId.ETH, + token: common.optimismTokens.ETH, + address: '0xe8CDF27AcD73a434D661C84887215F7598e7d0d3', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + { + id: PoolId.USDC, + token: common.optimismTokens.USDC, + address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + { + id: PoolId.USDT, + token: common.optimismTokens.USDT, + address: '0x19cFCE47eD54a88614648DC3f19A5980097007dD', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, + { + eid: EndpointId.METIS, + chainId: common.ChainId.metis, + pools: [ + { + id: PoolId.METIS, + token: metisTokens.Metis, + address: '0xD9050e7043102a0391F81462a3916326F86331F0', + destinations: [{ chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }], + }, + { + id: PoolId.ETH, + token: common.metisTokens.WETH, + address: '0x36ed193dc7160D3858EC250e69D12B03Ca087D08', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + { + id: PoolId.USDT, + token: common.metisTokens['m.USDT'], + address: '0x4dCBFC0249e8d5032F89D6461218a9D2eFff5125', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, + { + eid: EndpointId.BASE, + chainId: common.ChainId.base, + pools: [ + { + id: PoolId.ETH, + token: common.baseTokens.ETH, + address: '0xdc181Bd607330aeeBEF6ea62e03e5e1Fb4B6F7C7', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + { + id: PoolId.USDC, + token: common.baseTokens.USDC, + address: '0x27a16dc786820B16E5c9028b75B99F6f604b5d26', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.iota, endpointId: EndpointId.IOTA }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, + { + eid: EndpointId.IOTA, + chainId: common.ChainId.iota, + pools: [ + { + id: PoolId.ETH, + token: common.iotaTokens.WETH, + address: '0xdc181Bd607330aeeBEF6ea62e03e5e1Fb4B6F7C7', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.base, endpointId: EndpointId.BASE }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + ], + }, + { + id: PoolId.USDC, + token: common.iotaTokens['USDC.e'], + address: '0x8e8539e4CcD69123c623a106773F2b0cbbc58746', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + { + id: PoolId.USDT, + token: common.iotaTokens.USDT, + address: '0x77C71633C34C3784ede189d74223122422492a0f', + destinations: [ + { chainId: common.ChainId.mainnet, endpointId: EndpointId.ETHEREUM }, + { chainId: common.ChainId.optimism, endpointId: EndpointId.OPTIMISM }, + { chainId: common.ChainId.bnb, endpointId: EndpointId.BNB }, + { chainId: common.ChainId.polygon, endpointId: EndpointId.POLYGON }, + { chainId: common.ChainId.metis, endpointId: EndpointId.METIS }, + { chainId: common.ChainId.arbitrum, endpointId: EndpointId.ARBITRUM }, + { chainId: common.ChainId.avalanche, endpointId: EndpointId.AVALANCHE }, + ], + }, + ], + }, +]; + +export const [supportedChainIds, configMap, configMapById, tokensMap, poolConfigMapById, poolConfigMapByToken] = + configs.reduce( + (accumulator, config) => { + accumulator[0].push(config.chainId); + accumulator[1][config.chainId] = config; + accumulator[2][config.eid] = config; + accumulator[3][config.chainId] = new Set(); + accumulator[4][config.chainId] = {}; + accumulator[5][config.chainId] = {}; + for (const pool of config.pools) { + accumulator[3][config.chainId].add(pool.token); + accumulator[4][config.chainId][pool.id] = { chainId: config.chainId, ...pool }; + accumulator[5][config.chainId][pool.token.address] = { chainId: config.chainId, ...pool }; + } + + return accumulator; + }, + [[], {}, {}, {}, {}, {}] as [ + number[], + Record, + Record, + Record>, + Record>, + Record> + ] + ); + +export function getMarkets(chainId: number) { + return configMap[chainId].pools; +} + +export function getEndpointId(chainId: number) { + return configMap[chainId].eid; +} + +export function getTokens(chainId: number) { + return [...tokensMap[chainId]]; +} + +export function getPoolByTokenAddress(chainId: number, tokenAddress: string) { + return poolConfigMapByToken[chainId][tokenAddress].address; +} + +export function getDestChainIds(srcChainId: number, srcToken: common.Token) { + const destChainIds = new Set(); + const srcPoolConfig = poolConfigMapByToken[srcChainId][srcToken.address] ?? []; + for (const destination of srcPoolConfig.destinations) { + destChainIds.add(destination.chainId); + } + return [...destChainIds]; +} diff --git a/src/logics/stargate-v2/contracts/StargatePool.ts b/src/logics/stargate-v2/contracts/StargatePool.ts new file mode 100644 index 0000000..f008709 --- /dev/null +++ b/src/logics/stargate-v2/contracts/StargatePool.ts @@ -0,0 +1,1560 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PayableOverrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result, EventFragment } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export type CreditStruct = { srcEid: BigNumberish; amount: BigNumberish }; + +export type CreditStructOutput = [number, BigNumber] & { + srcEid: number; + amount: BigNumber; +}; + +export type SendParamStruct = { + dstEid: BigNumberish; + to: BytesLike; + amountLD: BigNumberish; + minAmountLD: BigNumberish; + extraOptions: BytesLike; + composeMsg: BytesLike; + oftCmd: BytesLike; +}; + +export type SendParamStructOutput = [number, string, BigNumber, BigNumber, string, string, string] & { + dstEid: number; + to: string; + amountLD: BigNumber; + minAmountLD: BigNumber; + extraOptions: string; + composeMsg: string; + oftCmd: string; +}; + +export type OFTLimitStruct = { + minAmountLD: BigNumberish; + maxAmountLD: BigNumberish; +}; + +export type OFTLimitStructOutput = [BigNumber, BigNumber] & { + minAmountLD: BigNumber; + maxAmountLD: BigNumber; +}; + +export type OFTFeeDetailStruct = { + feeAmountLD: BigNumberish; + description: string; +}; + +export type OFTFeeDetailStructOutput = [BigNumber, string] & { + feeAmountLD: BigNumber; + description: string; +}; + +export type OFTReceiptStruct = { + amountSentLD: BigNumberish; + amountReceivedLD: BigNumberish; +}; + +export type OFTReceiptStructOutput = [BigNumber, BigNumber] & { + amountSentLD: BigNumber; + amountReceivedLD: BigNumber; +}; + +export type MessagingFeeStruct = { + nativeFee: BigNumberish; + lzTokenFee: BigNumberish; +}; + +export type MessagingFeeStructOutput = [BigNumber, BigNumber] & { + nativeFee: BigNumber; + lzTokenFee: BigNumber; +}; + +export type OriginStruct = { + srcEid: BigNumberish; + sender: BytesLike; + nonce: BigNumberish; +}; + +export type OriginStructOutput = [number, string, BigNumber] & { + srcEid: number; + sender: string; + nonce: BigNumber; +}; + +export type MessagingReceiptStruct = { + guid: BytesLike; + nonce: BigNumberish; + fee: MessagingFeeStruct; +}; + +export type MessagingReceiptStructOutput = [string, BigNumber, MessagingFeeStructOutput] & { + guid: string; + nonce: BigNumber; + fee: MessagingFeeStructOutput; +}; + +export type TargetCreditStruct = { + srcEid: BigNumberish; + amount: BigNumberish; + minAmount: BigNumberish; +}; + +export type TargetCreditStructOutput = [number, BigNumber, BigNumber] & { + srcEid: number; + amount: BigNumber; + minAmount: BigNumber; +}; + +export type TicketStruct = { + ticketId: BigNumberish; + passengerBytes: BytesLike; +}; + +export type TicketStructOutput = [BigNumber, string] & { + ticketId: BigNumber; + passengerBytes: string; +}; + +export declare namespace StargateBase { + export type AddressConfigStruct = { + feeLib: string; + planner: string; + treasurer: string; + tokenMessaging: string; + creditMessaging: string; + lzToken: string; + }; + + export type AddressConfigStructOutput = [string, string, string, string, string, string] & { + feeLib: string; + planner: string; + treasurer: string; + tokenMessaging: string; + creditMessaging: string; + lzToken: string; + }; +} + +export interface StargatePoolInterface extends utils.Interface { + functions: { + 'addTreasuryFee(uint256)': FunctionFragment; + 'allowBurn(address,uint64)': FunctionFragment; + 'approvalRequired()': FunctionFragment; + 'burnAdmin()': FunctionFragment; + 'burnAllowanceSD()': FunctionFragment; + 'burnLockedUSDC()': FunctionFragment; + 'deficitOffset()': FunctionFragment; + 'deposit(address,uint256)': FunctionFragment; + 'endpoint()': FunctionFragment; + 'getAddressConfig()': FunctionFragment; + 'getTransferGasLimit()': FunctionFragment; + 'localEid()': FunctionFragment; + 'lpToken()': FunctionFragment; + 'oftVersion()': FunctionFragment; + 'owner()': FunctionFragment; + 'paths(uint32)': FunctionFragment; + 'plannerFee()': FunctionFragment; + 'poolBalance()': FunctionFragment; + 'quoteOFT((uint32,bytes32,uint256,uint256,bytes,bytes,bytes))': FunctionFragment; + 'quoteRedeemSend((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),bool)': FunctionFragment; + 'quoteSend((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),bool)': FunctionFragment; + 'receiveCredits(uint32,(uint32,uint64)[])': FunctionFragment; + 'receiveTokenBus((uint32,bytes32,uint64),bytes32,uint8,address,uint64)': FunctionFragment; + 'receiveTokenTaxi((uint32,bytes32,uint64),bytes32,address,uint64,bytes)': FunctionFragment; + 'recoverToken(address,address,uint256)': FunctionFragment; + 'redeem(uint256,address)': FunctionFragment; + 'redeemSend((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)': FunctionFragment; + 'redeemable(address)': FunctionFragment; + 'renounceOwnership()': FunctionFragment; + 'retryReceiveToken(bytes32,uint8,uint32,address,uint256,bytes)': FunctionFragment; + 'send((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)': FunctionFragment; + 'sendCredits(uint32,(uint32,uint64,uint64)[])': FunctionFragment; + 'sendToken((uint32,bytes32,uint256,uint256,bytes,bytes,bytes),(uint256,uint256),address)': FunctionFragment; + 'setAddressConfig((address,address,address,address,address,address))': FunctionFragment; + 'setDeficitOffset(uint256)': FunctionFragment; + 'setOFTPath(uint32,bool)': FunctionFragment; + 'setPause(bool)': FunctionFragment; + 'setTransferGasLimit(uint256)': FunctionFragment; + 'sharedDecimals()': FunctionFragment; + 'stargateType()': FunctionFragment; + 'status()': FunctionFragment; + 'token()': FunctionFragment; + 'transferOwnership(address)': FunctionFragment; + 'treasuryFee()': FunctionFragment; + 'tvl()': FunctionFragment; + 'unreceivedTokens(bytes32,uint8)': FunctionFragment; + 'withdrawPlannerFee()': FunctionFragment; + 'withdrawTreasuryFee(address,uint64)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'addTreasuryFee' + | 'allowBurn' + | 'approvalRequired' + | 'burnAdmin' + | 'burnAllowanceSD' + | 'burnLockedUSDC' + | 'deficitOffset' + | 'deposit' + | 'endpoint' + | 'getAddressConfig' + | 'getTransferGasLimit' + | 'localEid' + | 'lpToken' + | 'oftVersion' + | 'owner' + | 'paths' + | 'plannerFee' + | 'poolBalance' + | 'quoteOFT' + | 'quoteRedeemSend' + | 'quoteSend' + | 'receiveCredits' + | 'receiveTokenBus' + | 'receiveTokenTaxi' + | 'recoverToken' + | 'redeem' + | 'redeemSend' + | 'redeemable' + | 'renounceOwnership' + | 'retryReceiveToken' + | 'send' + | 'sendCredits' + | 'sendToken' + | 'setAddressConfig' + | 'setDeficitOffset' + | 'setOFTPath' + | 'setPause' + | 'setTransferGasLimit' + | 'sharedDecimals' + | 'stargateType' + | 'status' + | 'token' + | 'transferOwnership' + | 'treasuryFee' + | 'tvl' + | 'unreceivedTokens' + | 'withdrawPlannerFee' + | 'withdrawTreasuryFee' + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'addTreasuryFee', values: [BigNumberish]): string; + encodeFunctionData(functionFragment: 'allowBurn', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'approvalRequired', values?: undefined): string; + encodeFunctionData(functionFragment: 'burnAdmin', values?: undefined): string; + encodeFunctionData(functionFragment: 'burnAllowanceSD', values?: undefined): string; + encodeFunctionData(functionFragment: 'burnLockedUSDC', values?: undefined): string; + encodeFunctionData(functionFragment: 'deficitOffset', values?: undefined): string; + encodeFunctionData(functionFragment: 'deposit', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'endpoint', values?: undefined): string; + encodeFunctionData(functionFragment: 'getAddressConfig', values?: undefined): string; + encodeFunctionData(functionFragment: 'getTransferGasLimit', values?: undefined): string; + encodeFunctionData(functionFragment: 'localEid', values?: undefined): string; + encodeFunctionData(functionFragment: 'lpToken', values?: undefined): string; + encodeFunctionData(functionFragment: 'oftVersion', values?: undefined): string; + encodeFunctionData(functionFragment: 'owner', values?: undefined): string; + encodeFunctionData(functionFragment: 'paths', values: [BigNumberish]): string; + encodeFunctionData(functionFragment: 'plannerFee', values?: undefined): string; + encodeFunctionData(functionFragment: 'poolBalance', values?: undefined): string; + encodeFunctionData(functionFragment: 'quoteOFT', values: [SendParamStruct]): string; + encodeFunctionData(functionFragment: 'quoteRedeemSend', values: [SendParamStruct, boolean]): string; + encodeFunctionData(functionFragment: 'quoteSend', values: [SendParamStruct, boolean]): string; + encodeFunctionData(functionFragment: 'receiveCredits', values: [BigNumberish, CreditStruct[]]): string; + encodeFunctionData( + functionFragment: 'receiveTokenBus', + values: [OriginStruct, BytesLike, BigNumberish, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: 'receiveTokenTaxi', + values: [OriginStruct, BytesLike, string, BigNumberish, BytesLike] + ): string; + encodeFunctionData(functionFragment: 'recoverToken', values: [string, string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'redeem', values: [BigNumberish, string]): string; + encodeFunctionData(functionFragment: 'redeemSend', values: [SendParamStruct, MessagingFeeStruct, string]): string; + encodeFunctionData(functionFragment: 'redeemable', values: [string]): string; + encodeFunctionData(functionFragment: 'renounceOwnership', values?: undefined): string; + encodeFunctionData( + functionFragment: 'retryReceiveToken', + values: [BytesLike, BigNumberish, BigNumberish, string, BigNumberish, BytesLike] + ): string; + encodeFunctionData(functionFragment: 'send', values: [SendParamStruct, MessagingFeeStruct, string]): string; + encodeFunctionData(functionFragment: 'sendCredits', values: [BigNumberish, TargetCreditStruct[]]): string; + encodeFunctionData(functionFragment: 'sendToken', values: [SendParamStruct, MessagingFeeStruct, string]): string; + encodeFunctionData(functionFragment: 'setAddressConfig', values: [StargateBase.AddressConfigStruct]): string; + encodeFunctionData(functionFragment: 'setDeficitOffset', values: [BigNumberish]): string; + encodeFunctionData(functionFragment: 'setOFTPath', values: [BigNumberish, boolean]): string; + encodeFunctionData(functionFragment: 'setPause', values: [boolean]): string; + encodeFunctionData(functionFragment: 'setTransferGasLimit', values: [BigNumberish]): string; + encodeFunctionData(functionFragment: 'sharedDecimals', values?: undefined): string; + encodeFunctionData(functionFragment: 'stargateType', values?: undefined): string; + encodeFunctionData(functionFragment: 'status', values?: undefined): string; + encodeFunctionData(functionFragment: 'token', values?: undefined): string; + encodeFunctionData(functionFragment: 'transferOwnership', values: [string]): string; + encodeFunctionData(functionFragment: 'treasuryFee', values?: undefined): string; + encodeFunctionData(functionFragment: 'tvl', values?: undefined): string; + encodeFunctionData(functionFragment: 'unreceivedTokens', values: [BytesLike, BigNumberish]): string; + encodeFunctionData(functionFragment: 'withdrawPlannerFee', values?: undefined): string; + encodeFunctionData(functionFragment: 'withdrawTreasuryFee', values: [string, BigNumberish]): string; + + decodeFunctionResult(functionFragment: 'addTreasuryFee', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'allowBurn', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'approvalRequired', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'burnAdmin', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'burnAllowanceSD', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'burnLockedUSDC', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deficitOffset', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deposit', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'endpoint', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getAddressConfig', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'getTransferGasLimit', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'localEid', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'lpToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'oftVersion', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'paths', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'plannerFee', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'poolBalance', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'quoteOFT', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'quoteRedeemSend', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'quoteSend', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'receiveCredits', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'receiveTokenBus', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'receiveTokenTaxi', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'recoverToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'redeem', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'redeemSend', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'redeemable', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'renounceOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'retryReceiveToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'send', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendCredits', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sendToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setAddressConfig', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setDeficitOffset', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setOFTPath', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setPause', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setTransferGasLimit', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'sharedDecimals', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'stargateType', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'status', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'token', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'transferOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'treasuryFee', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'tvl', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'unreceivedTokens', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdrawPlannerFee', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdrawTreasuryFee', data: BytesLike): Result; + + events: { + 'AddressConfigSet(tuple)': EventFragment; + 'CreditsReceived(uint32,tuple[])': EventFragment; + 'CreditsSent(uint32,tuple[])': EventFragment; + 'Deposited(address,address,uint256)': EventFragment; + 'OFTPathSet(uint32,bool)': EventFragment; + 'OFTReceived(bytes32,uint32,address,uint256)': EventFragment; + 'OFTSent(bytes32,uint32,address,uint256,uint256)': EventFragment; + 'OwnershipTransferred(address,address)': EventFragment; + 'Path_CreditBurned(uint64)': EventFragment; + 'PauseSet(bool)': EventFragment; + 'PlannerFeeWithdrawn(uint256)': EventFragment; + 'Redeemed(address,address,uint256)': EventFragment; + 'TreasuryFeeAdded(uint64)': EventFragment; + 'TreasuryFeeWithdrawn(address,uint64)': EventFragment; + 'UnreceivedTokenCached(bytes32,uint8,uint32,address,uint256,bytes)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'AddressConfigSet'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'CreditsReceived'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'CreditsSent'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Deposited'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'OFTPathSet'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'OFTReceived'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'OFTSent'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Path_CreditBurned'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'PauseSet'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'PlannerFeeWithdrawn'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'Redeemed'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'TreasuryFeeAdded'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'TreasuryFeeWithdrawn'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'UnreceivedTokenCached'): EventFragment; +} + +export interface AddressConfigSetEventObject { + config: StargateBase.AddressConfigStructOutput; +} +export type AddressConfigSetEvent = TypedEvent<[StargateBase.AddressConfigStructOutput], AddressConfigSetEventObject>; + +export type AddressConfigSetEventFilter = TypedEventFilter; + +export interface CreditsReceivedEventObject { + srcEid: number; + credits: CreditStructOutput[]; +} +export type CreditsReceivedEvent = TypedEvent<[number, CreditStructOutput[]], CreditsReceivedEventObject>; + +export type CreditsReceivedEventFilter = TypedEventFilter; + +export interface CreditsSentEventObject { + dstEid: number; + credits: CreditStructOutput[]; +} +export type CreditsSentEvent = TypedEvent<[number, CreditStructOutput[]], CreditsSentEventObject>; + +export type CreditsSentEventFilter = TypedEventFilter; + +export interface DepositedEventObject { + payer: string; + receiver: string; + amountLD: BigNumber; +} +export type DepositedEvent = TypedEvent<[string, string, BigNumber], DepositedEventObject>; + +export type DepositedEventFilter = TypedEventFilter; + +export interface OFTPathSetEventObject { + dstEid: number; + oft: boolean; +} +export type OFTPathSetEvent = TypedEvent<[number, boolean], OFTPathSetEventObject>; + +export type OFTPathSetEventFilter = TypedEventFilter; + +export interface OFTReceivedEventObject { + guid: string; + srcEid: number; + toAddress: string; + amountReceivedLD: BigNumber; +} +export type OFTReceivedEvent = TypedEvent<[string, number, string, BigNumber], OFTReceivedEventObject>; + +export type OFTReceivedEventFilter = TypedEventFilter; + +export interface OFTSentEventObject { + guid: string; + dstEid: number; + fromAddress: string; + amountSentLD: BigNumber; + amountReceivedLD: BigNumber; +} +export type OFTSentEvent = TypedEvent<[string, number, string, BigNumber, BigNumber], OFTSentEventObject>; + +export type OFTSentEventFilter = TypedEventFilter; + +export interface OwnershipTransferredEventObject { + previousOwner: string; + newOwner: string; +} +export type OwnershipTransferredEvent = TypedEvent<[string, string], OwnershipTransferredEventObject>; + +export type OwnershipTransferredEventFilter = TypedEventFilter; + +export interface Path_CreditBurnedEventObject { + amountSD: BigNumber; +} +export type Path_CreditBurnedEvent = TypedEvent<[BigNumber], Path_CreditBurnedEventObject>; + +export type Path_CreditBurnedEventFilter = TypedEventFilter; + +export interface PauseSetEventObject { + paused: boolean; +} +export type PauseSetEvent = TypedEvent<[boolean], PauseSetEventObject>; + +export type PauseSetEventFilter = TypedEventFilter; + +export interface PlannerFeeWithdrawnEventObject { + amount: BigNumber; +} +export type PlannerFeeWithdrawnEvent = TypedEvent<[BigNumber], PlannerFeeWithdrawnEventObject>; + +export type PlannerFeeWithdrawnEventFilter = TypedEventFilter; + +export interface RedeemedEventObject { + payer: string; + receiver: string; + amountLD: BigNumber; +} +export type RedeemedEvent = TypedEvent<[string, string, BigNumber], RedeemedEventObject>; + +export type RedeemedEventFilter = TypedEventFilter; + +export interface TreasuryFeeAddedEventObject { + amountSD: BigNumber; +} +export type TreasuryFeeAddedEvent = TypedEvent<[BigNumber], TreasuryFeeAddedEventObject>; + +export type TreasuryFeeAddedEventFilter = TypedEventFilter; + +export interface TreasuryFeeWithdrawnEventObject { + to: string; + amountSD: BigNumber; +} +export type TreasuryFeeWithdrawnEvent = TypedEvent<[string, BigNumber], TreasuryFeeWithdrawnEventObject>; + +export type TreasuryFeeWithdrawnEventFilter = TypedEventFilter; + +export interface UnreceivedTokenCachedEventObject { + guid: string; + index: number; + srcEid: number; + receiver: string; + amountLD: BigNumber; + composeMsg: string; +} +export type UnreceivedTokenCachedEvent = TypedEvent< + [string, number, number, string, BigNumber, string], + UnreceivedTokenCachedEventObject +>; + +export type UnreceivedTokenCachedEventFilter = TypedEventFilter; + +export interface StargatePool extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: StargatePoolInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + addTreasuryFee( + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + allowBurn( + _burnAdmin: string, + _burnAllowanceSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + approvalRequired(overrides?: CallOverrides): Promise<[boolean]>; + + burnAdmin(overrides?: CallOverrides): Promise<[string]>; + + burnAllowanceSD(overrides?: CallOverrides): Promise<[BigNumber]>; + + burnLockedUSDC(overrides?: Overrides & { from?: string }): Promise; + + deficitOffset(overrides?: CallOverrides): Promise<[BigNumber]>; + + deposit( + _receiver: string, + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + endpoint(overrides?: CallOverrides): Promise<[string]>; + + getAddressConfig(overrides?: CallOverrides): Promise<[StargateBase.AddressConfigStructOutput]>; + + getTransferGasLimit(overrides?: CallOverrides): Promise<[BigNumber]>; + + localEid(overrides?: CallOverrides): Promise<[number]>; + + lpToken(overrides?: CallOverrides): Promise<[string]>; + + oftVersion(overrides?: CallOverrides): Promise<[string, BigNumber] & { interfaceId: string; version: BigNumber }>; + + owner(overrides?: CallOverrides): Promise<[string]>; + + paths(eid: BigNumberish, overrides?: CallOverrides): Promise<[BigNumber] & { credit: BigNumber }>; + + plannerFee(overrides?: CallOverrides): Promise<[BigNumber] & { available: BigNumber }>; + + poolBalance(overrides?: CallOverrides): Promise<[BigNumber]>; + + quoteOFT( + _sendParam: SendParamStruct, + overrides?: CallOverrides + ): Promise< + [OFTLimitStructOutput, OFTFeeDetailStructOutput[], OFTReceiptStructOutput] & { + limit: OFTLimitStructOutput; + oftFeeDetails: OFTFeeDetailStructOutput[]; + receipt: OFTReceiptStructOutput; + } + >; + + quoteRedeemSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise<[MessagingFeeStructOutput] & { fee: MessagingFeeStructOutput }>; + + quoteSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise<[MessagingFeeStructOutput] & { fee: MessagingFeeStructOutput }>; + + receiveCredits( + _srcEid: BigNumberish, + _credits: CreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenBus( + _origin: OriginStruct, + _guid: BytesLike, + _seatNumber: BigNumberish, + _receiver: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenTaxi( + _origin: OriginStruct, + _guid: BytesLike, + _receiver: string, + _amountSD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + recoverToken( + _token: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + redeem( + _amountLD: BigNumberish, + _receiver: string, + overrides?: Overrides & { from?: string } + ): Promise; + + redeemSend( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + redeemable(_owner: string, overrides?: CallOverrides): Promise<[BigNumber] & { amountLD: BigNumber }>; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + retryReceiveToken( + _guid: BytesLike, + _index: BigNumberish, + _srcEid: BigNumberish, + _receiver: string, + _amountLD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + send( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendCredits( + _dstEid: BigNumberish, + _credits: TargetCreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + sendToken( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setAddressConfig( + _config: StargateBase.AddressConfigStruct, + overrides?: Overrides & { from?: string } + ): Promise; + + setDeficitOffset( + _deficitOffsetLD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setOFTPath( + _dstEid: BigNumberish, + _oft: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(_paused: boolean, overrides?: Overrides & { from?: string }): Promise; + + setTransferGasLimit( + _gasLimit: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + sharedDecimals(overrides?: CallOverrides): Promise<[number]>; + + stargateType(overrides?: CallOverrides): Promise<[number]>; + + status(overrides?: CallOverrides): Promise<[number]>; + + token(overrides?: CallOverrides): Promise<[string]>; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + treasuryFee(overrides?: CallOverrides): Promise<[BigNumber]>; + + tvl(overrides?: CallOverrides): Promise<[BigNumber]>; + + unreceivedTokens( + guid: BytesLike, + index: BigNumberish, + overrides?: CallOverrides + ): Promise<[string] & { hash: string }>; + + withdrawPlannerFee(overrides?: Overrides & { from?: string }): Promise; + + withdrawTreasuryFee( + _to: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + }; + + addTreasuryFee( + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + allowBurn( + _burnAdmin: string, + _burnAllowanceSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + approvalRequired(overrides?: CallOverrides): Promise; + + burnAdmin(overrides?: CallOverrides): Promise; + + burnAllowanceSD(overrides?: CallOverrides): Promise; + + burnLockedUSDC(overrides?: Overrides & { from?: string }): Promise; + + deficitOffset(overrides?: CallOverrides): Promise; + + deposit( + _receiver: string, + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + endpoint(overrides?: CallOverrides): Promise; + + getAddressConfig(overrides?: CallOverrides): Promise; + + getTransferGasLimit(overrides?: CallOverrides): Promise; + + localEid(overrides?: CallOverrides): Promise; + + lpToken(overrides?: CallOverrides): Promise; + + oftVersion(overrides?: CallOverrides): Promise<[string, BigNumber] & { interfaceId: string; version: BigNumber }>; + + owner(overrides?: CallOverrides): Promise; + + paths(eid: BigNumberish, overrides?: CallOverrides): Promise; + + plannerFee(overrides?: CallOverrides): Promise; + + poolBalance(overrides?: CallOverrides): Promise; + + quoteOFT( + _sendParam: SendParamStruct, + overrides?: CallOverrides + ): Promise< + [OFTLimitStructOutput, OFTFeeDetailStructOutput[], OFTReceiptStructOutput] & { + limit: OFTLimitStructOutput; + oftFeeDetails: OFTFeeDetailStructOutput[]; + receipt: OFTReceiptStructOutput; + } + >; + + quoteRedeemSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise; + + quoteSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise; + + receiveCredits( + _srcEid: BigNumberish, + _credits: CreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenBus( + _origin: OriginStruct, + _guid: BytesLike, + _seatNumber: BigNumberish, + _receiver: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenTaxi( + _origin: OriginStruct, + _guid: BytesLike, + _receiver: string, + _amountSD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + recoverToken( + _token: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + redeem( + _amountLD: BigNumberish, + _receiver: string, + overrides?: Overrides & { from?: string } + ): Promise; + + redeemSend( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + redeemable(_owner: string, overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + retryReceiveToken( + _guid: BytesLike, + _index: BigNumberish, + _srcEid: BigNumberish, + _receiver: string, + _amountLD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + send( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendCredits( + _dstEid: BigNumberish, + _credits: TargetCreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + sendToken( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setAddressConfig( + _config: StargateBase.AddressConfigStruct, + overrides?: Overrides & { from?: string } + ): Promise; + + setDeficitOffset( + _deficitOffsetLD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setOFTPath( + _dstEid: BigNumberish, + _oft: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(_paused: boolean, overrides?: Overrides & { from?: string }): Promise; + + setTransferGasLimit(_gasLimit: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + sharedDecimals(overrides?: CallOverrides): Promise; + + stargateType(overrides?: CallOverrides): Promise; + + status(overrides?: CallOverrides): Promise; + + token(overrides?: CallOverrides): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + treasuryFee(overrides?: CallOverrides): Promise; + + tvl(overrides?: CallOverrides): Promise; + + unreceivedTokens(guid: BytesLike, index: BigNumberish, overrides?: CallOverrides): Promise; + + withdrawPlannerFee(overrides?: Overrides & { from?: string }): Promise; + + withdrawTreasuryFee( + _to: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + callStatic: { + addTreasuryFee(_amountLD: BigNumberish, overrides?: CallOverrides): Promise; + + allowBurn(_burnAdmin: string, _burnAllowanceSD: BigNumberish, overrides?: CallOverrides): Promise; + + approvalRequired(overrides?: CallOverrides): Promise; + + burnAdmin(overrides?: CallOverrides): Promise; + + burnAllowanceSD(overrides?: CallOverrides): Promise; + + burnLockedUSDC(overrides?: CallOverrides): Promise; + + deficitOffset(overrides?: CallOverrides): Promise; + + deposit(_receiver: string, _amountLD: BigNumberish, overrides?: CallOverrides): Promise; + + endpoint(overrides?: CallOverrides): Promise; + + getAddressConfig(overrides?: CallOverrides): Promise; + + getTransferGasLimit(overrides?: CallOverrides): Promise; + + localEid(overrides?: CallOverrides): Promise; + + lpToken(overrides?: CallOverrides): Promise; + + oftVersion(overrides?: CallOverrides): Promise<[string, BigNumber] & { interfaceId: string; version: BigNumber }>; + + owner(overrides?: CallOverrides): Promise; + + paths(eid: BigNumberish, overrides?: CallOverrides): Promise; + + plannerFee(overrides?: CallOverrides): Promise; + + poolBalance(overrides?: CallOverrides): Promise; + + quoteOFT( + _sendParam: SendParamStruct, + overrides?: CallOverrides + ): Promise< + [OFTLimitStructOutput, OFTFeeDetailStructOutput[], OFTReceiptStructOutput] & { + limit: OFTLimitStructOutput; + oftFeeDetails: OFTFeeDetailStructOutput[]; + receipt: OFTReceiptStructOutput; + } + >; + + quoteRedeemSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise; + + quoteSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise; + + receiveCredits(_srcEid: BigNumberish, _credits: CreditStruct[], overrides?: CallOverrides): Promise; + + receiveTokenBus( + _origin: OriginStruct, + _guid: BytesLike, + _seatNumber: BigNumberish, + _receiver: string, + _amountSD: BigNumberish, + overrides?: CallOverrides + ): Promise; + + receiveTokenTaxi( + _origin: OriginStruct, + _guid: BytesLike, + _receiver: string, + _amountSD: BigNumberish, + _composeMsg: BytesLike, + overrides?: CallOverrides + ): Promise; + + recoverToken(_token: string, _to: string, _amount: BigNumberish, overrides?: CallOverrides): Promise; + + redeem(_amountLD: BigNumberish, _receiver: string, overrides?: CallOverrides): Promise; + + redeemSend( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: CallOverrides + ): Promise< + [MessagingReceiptStructOutput, OFTReceiptStructOutput] & { + msgReceipt: MessagingReceiptStructOutput; + oftReceipt: OFTReceiptStructOutput; + } + >; + + redeemable(_owner: string, overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: CallOverrides): Promise; + + retryReceiveToken( + _guid: BytesLike, + _index: BigNumberish, + _srcEid: BigNumberish, + _receiver: string, + _amountLD: BigNumberish, + _composeMsg: BytesLike, + overrides?: CallOverrides + ): Promise; + + send( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: CallOverrides + ): Promise< + [MessagingReceiptStructOutput, OFTReceiptStructOutput] & { + msgReceipt: MessagingReceiptStructOutput; + oftReceipt: OFTReceiptStructOutput; + } + >; + + sendCredits( + _dstEid: BigNumberish, + _credits: TargetCreditStruct[], + overrides?: CallOverrides + ): Promise; + + sendToken( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: CallOverrides + ): Promise< + [MessagingReceiptStructOutput, OFTReceiptStructOutput, TicketStructOutput] & { + msgReceipt: MessagingReceiptStructOutput; + oftReceipt: OFTReceiptStructOutput; + ticket: TicketStructOutput; + } + >; + + setAddressConfig(_config: StargateBase.AddressConfigStruct, overrides?: CallOverrides): Promise; + + setDeficitOffset(_deficitOffsetLD: BigNumberish, overrides?: CallOverrides): Promise; + + setOFTPath(_dstEid: BigNumberish, _oft: boolean, overrides?: CallOverrides): Promise; + + setPause(_paused: boolean, overrides?: CallOverrides): Promise; + + setTransferGasLimit(_gasLimit: BigNumberish, overrides?: CallOverrides): Promise; + + sharedDecimals(overrides?: CallOverrides): Promise; + + stargateType(overrides?: CallOverrides): Promise; + + status(overrides?: CallOverrides): Promise; + + token(overrides?: CallOverrides): Promise; + + transferOwnership(newOwner: string, overrides?: CallOverrides): Promise; + + treasuryFee(overrides?: CallOverrides): Promise; + + tvl(overrides?: CallOverrides): Promise; + + unreceivedTokens(guid: BytesLike, index: BigNumberish, overrides?: CallOverrides): Promise; + + withdrawPlannerFee(overrides?: CallOverrides): Promise; + + withdrawTreasuryFee(_to: string, _amountSD: BigNumberish, overrides?: CallOverrides): Promise; + }; + + filters: { + 'AddressConfigSet(tuple)'(config?: null): AddressConfigSetEventFilter; + AddressConfigSet(config?: null): AddressConfigSetEventFilter; + + 'CreditsReceived(uint32,tuple[])'(srcEid?: null, credits?: null): CreditsReceivedEventFilter; + CreditsReceived(srcEid?: null, credits?: null): CreditsReceivedEventFilter; + + 'CreditsSent(uint32,tuple[])'(dstEid?: null, credits?: null): CreditsSentEventFilter; + CreditsSent(dstEid?: null, credits?: null): CreditsSentEventFilter; + + 'Deposited(address,address,uint256)'( + payer?: string | null, + receiver?: string | null, + amountLD?: null + ): DepositedEventFilter; + Deposited(payer?: string | null, receiver?: string | null, amountLD?: null): DepositedEventFilter; + + 'OFTPathSet(uint32,bool)'(dstEid?: null, oft?: null): OFTPathSetEventFilter; + OFTPathSet(dstEid?: null, oft?: null): OFTPathSetEventFilter; + + 'OFTReceived(bytes32,uint32,address,uint256)'( + guid?: BytesLike | null, + srcEid?: null, + toAddress?: string | null, + amountReceivedLD?: null + ): OFTReceivedEventFilter; + OFTReceived( + guid?: BytesLike | null, + srcEid?: null, + toAddress?: string | null, + amountReceivedLD?: null + ): OFTReceivedEventFilter; + + 'OFTSent(bytes32,uint32,address,uint256,uint256)'( + guid?: BytesLike | null, + dstEid?: null, + fromAddress?: string | null, + amountSentLD?: null, + amountReceivedLD?: null + ): OFTSentEventFilter; + OFTSent( + guid?: BytesLike | null, + dstEid?: null, + fromAddress?: string | null, + amountSentLD?: null, + amountReceivedLD?: null + ): OFTSentEventFilter; + + 'OwnershipTransferred(address,address)'( + previousOwner?: string | null, + newOwner?: string | null + ): OwnershipTransferredEventFilter; + OwnershipTransferred(previousOwner?: string | null, newOwner?: string | null): OwnershipTransferredEventFilter; + + 'Path_CreditBurned(uint64)'(amountSD?: null): Path_CreditBurnedEventFilter; + Path_CreditBurned(amountSD?: null): Path_CreditBurnedEventFilter; + + 'PauseSet(bool)'(paused?: null): PauseSetEventFilter; + PauseSet(paused?: null): PauseSetEventFilter; + + 'PlannerFeeWithdrawn(uint256)'(amount?: null): PlannerFeeWithdrawnEventFilter; + PlannerFeeWithdrawn(amount?: null): PlannerFeeWithdrawnEventFilter; + + 'Redeemed(address,address,uint256)'( + payer?: string | null, + receiver?: string | null, + amountLD?: null + ): RedeemedEventFilter; + Redeemed(payer?: string | null, receiver?: string | null, amountLD?: null): RedeemedEventFilter; + + 'TreasuryFeeAdded(uint64)'(amountSD?: null): TreasuryFeeAddedEventFilter; + TreasuryFeeAdded(amountSD?: null): TreasuryFeeAddedEventFilter; + + 'TreasuryFeeWithdrawn(address,uint64)'(to?: null, amountSD?: null): TreasuryFeeWithdrawnEventFilter; + TreasuryFeeWithdrawn(to?: null, amountSD?: null): TreasuryFeeWithdrawnEventFilter; + + 'UnreceivedTokenCached(bytes32,uint8,uint32,address,uint256,bytes)'( + guid?: null, + index?: null, + srcEid?: null, + receiver?: null, + amountLD?: null, + composeMsg?: null + ): UnreceivedTokenCachedEventFilter; + UnreceivedTokenCached( + guid?: null, + index?: null, + srcEid?: null, + receiver?: null, + amountLD?: null, + composeMsg?: null + ): UnreceivedTokenCachedEventFilter; + }; + + estimateGas: { + addTreasuryFee(_amountLD: BigNumberish, overrides?: PayableOverrides & { from?: string }): Promise; + + allowBurn( + _burnAdmin: string, + _burnAllowanceSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + approvalRequired(overrides?: CallOverrides): Promise; + + burnAdmin(overrides?: CallOverrides): Promise; + + burnAllowanceSD(overrides?: CallOverrides): Promise; + + burnLockedUSDC(overrides?: Overrides & { from?: string }): Promise; + + deficitOffset(overrides?: CallOverrides): Promise; + + deposit( + _receiver: string, + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + endpoint(overrides?: CallOverrides): Promise; + + getAddressConfig(overrides?: CallOverrides): Promise; + + getTransferGasLimit(overrides?: CallOverrides): Promise; + + localEid(overrides?: CallOverrides): Promise; + + lpToken(overrides?: CallOverrides): Promise; + + oftVersion(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + paths(eid: BigNumberish, overrides?: CallOverrides): Promise; + + plannerFee(overrides?: CallOverrides): Promise; + + poolBalance(overrides?: CallOverrides): Promise; + + quoteOFT(_sendParam: SendParamStruct, overrides?: CallOverrides): Promise; + + quoteRedeemSend(_sendParam: SendParamStruct, _payInLzToken: boolean, overrides?: CallOverrides): Promise; + + quoteSend(_sendParam: SendParamStruct, _payInLzToken: boolean, overrides?: CallOverrides): Promise; + + receiveCredits( + _srcEid: BigNumberish, + _credits: CreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenBus( + _origin: OriginStruct, + _guid: BytesLike, + _seatNumber: BigNumberish, + _receiver: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenTaxi( + _origin: OriginStruct, + _guid: BytesLike, + _receiver: string, + _amountSD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + recoverToken( + _token: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + redeem(_amountLD: BigNumberish, _receiver: string, overrides?: Overrides & { from?: string }): Promise; + + redeemSend( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + redeemable(_owner: string, overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + retryReceiveToken( + _guid: BytesLike, + _index: BigNumberish, + _srcEid: BigNumberish, + _receiver: string, + _amountLD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + send( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendCredits( + _dstEid: BigNumberish, + _credits: TargetCreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + sendToken( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setAddressConfig( + _config: StargateBase.AddressConfigStruct, + overrides?: Overrides & { from?: string } + ): Promise; + + setDeficitOffset(_deficitOffsetLD: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + setOFTPath(_dstEid: BigNumberish, _oft: boolean, overrides?: Overrides & { from?: string }): Promise; + + setPause(_paused: boolean, overrides?: Overrides & { from?: string }): Promise; + + setTransferGasLimit(_gasLimit: BigNumberish, overrides?: Overrides & { from?: string }): Promise; + + sharedDecimals(overrides?: CallOverrides): Promise; + + stargateType(overrides?: CallOverrides): Promise; + + status(overrides?: CallOverrides): Promise; + + token(overrides?: CallOverrides): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + treasuryFee(overrides?: CallOverrides): Promise; + + tvl(overrides?: CallOverrides): Promise; + + unreceivedTokens(guid: BytesLike, index: BigNumberish, overrides?: CallOverrides): Promise; + + withdrawPlannerFee(overrides?: Overrides & { from?: string }): Promise; + + withdrawTreasuryFee( + _to: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + }; + + populateTransaction: { + addTreasuryFee( + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + allowBurn( + _burnAdmin: string, + _burnAllowanceSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + approvalRequired(overrides?: CallOverrides): Promise; + + burnAdmin(overrides?: CallOverrides): Promise; + + burnAllowanceSD(overrides?: CallOverrides): Promise; + + burnLockedUSDC(overrides?: Overrides & { from?: string }): Promise; + + deficitOffset(overrides?: CallOverrides): Promise; + + deposit( + _receiver: string, + _amountLD: BigNumberish, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + endpoint(overrides?: CallOverrides): Promise; + + getAddressConfig(overrides?: CallOverrides): Promise; + + getTransferGasLimit(overrides?: CallOverrides): Promise; + + localEid(overrides?: CallOverrides): Promise; + + lpToken(overrides?: CallOverrides): Promise; + + oftVersion(overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + paths(eid: BigNumberish, overrides?: CallOverrides): Promise; + + plannerFee(overrides?: CallOverrides): Promise; + + poolBalance(overrides?: CallOverrides): Promise; + + quoteOFT(_sendParam: SendParamStruct, overrides?: CallOverrides): Promise; + + quoteRedeemSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise; + + quoteSend( + _sendParam: SendParamStruct, + _payInLzToken: boolean, + overrides?: CallOverrides + ): Promise; + + receiveCredits( + _srcEid: BigNumberish, + _credits: CreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenBus( + _origin: OriginStruct, + _guid: BytesLike, + _seatNumber: BigNumberish, + _receiver: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + receiveTokenTaxi( + _origin: OriginStruct, + _guid: BytesLike, + _receiver: string, + _amountSD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + recoverToken( + _token: string, + _to: string, + _amount: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + redeem( + _amountLD: BigNumberish, + _receiver: string, + overrides?: Overrides & { from?: string } + ): Promise; + + redeemSend( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + redeemable(_owner: string, overrides?: CallOverrides): Promise; + + renounceOwnership(overrides?: Overrides & { from?: string }): Promise; + + retryReceiveToken( + _guid: BytesLike, + _index: BigNumberish, + _srcEid: BigNumberish, + _receiver: string, + _amountLD: BigNumberish, + _composeMsg: BytesLike, + overrides?: Overrides & { from?: string } + ): Promise; + + send( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + sendCredits( + _dstEid: BigNumberish, + _credits: TargetCreditStruct[], + overrides?: Overrides & { from?: string } + ): Promise; + + sendToken( + _sendParam: SendParamStruct, + _fee: MessagingFeeStruct, + _refundAddress: string, + overrides?: PayableOverrides & { from?: string } + ): Promise; + + setAddressConfig( + _config: StargateBase.AddressConfigStruct, + overrides?: Overrides & { from?: string } + ): Promise; + + setDeficitOffset( + _deficitOffsetLD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + setOFTPath( + _dstEid: BigNumberish, + _oft: boolean, + overrides?: Overrides & { from?: string } + ): Promise; + + setPause(_paused: boolean, overrides?: Overrides & { from?: string }): Promise; + + setTransferGasLimit( + _gasLimit: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + + sharedDecimals(overrides?: CallOverrides): Promise; + + stargateType(overrides?: CallOverrides): Promise; + + status(overrides?: CallOverrides): Promise; + + token(overrides?: CallOverrides): Promise; + + transferOwnership(newOwner: string, overrides?: Overrides & { from?: string }): Promise; + + treasuryFee(overrides?: CallOverrides): Promise; + + tvl(overrides?: CallOverrides): Promise; + + unreceivedTokens(guid: BytesLike, index: BigNumberish, overrides?: CallOverrides): Promise; + + withdrawPlannerFee(overrides?: Overrides & { from?: string }): Promise; + + withdrawTreasuryFee( + _to: string, + _amountSD: BigNumberish, + overrides?: Overrides & { from?: string } + ): Promise; + }; +} diff --git a/src/logics/stargate-v2/contracts/common.ts b/src/logics/stargate-v2/contracts/common.ts new file mode 100644 index 0000000..6cfb104 --- /dev/null +++ b/src/logics/stargate-v2/contracts/common.ts @@ -0,0 +1,30 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { Listener } from '@ethersproject/providers'; +import type { Event, EventFilter } from 'ethers'; + +export interface TypedEvent = any, TArgsObject = any> extends Event { + args: TArgsArray & TArgsObject; +} + +export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} + +export interface TypedListener { + (...listenerArg: [...__TypechainArgsArray, TEvent]): void; +} + +type __TypechainArgsArray = T extends TypedEvent ? U : never; + +export interface OnEvent { + (eventFilter: TypedEventFilter, listener: TypedListener): TRes; + (eventName: string, listener: Listener): TRes; +} + +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; + +export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; diff --git a/src/logics/stargate-v2/contracts/factories/StargatePool__factory.ts b/src/logics/stargate-v2/contracts/factories/StargatePool__factory.ts new file mode 100644 index 0000000..50c8c91 --- /dev/null +++ b/src/logics/stargate-v2/contracts/factories/StargatePool__factory.ts @@ -0,0 +1,2020 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { StargatePool, StargatePoolInterface } from '../StargatePool'; + +const _abi = [ + { + inputs: [ + { + internalType: 'string', + name: '_lpTokenName', + type: 'string', + }, + { + internalType: 'string', + name: '_lpTokenSymbol', + type: 'string', + }, + { + internalType: 'address', + name: '_token', + type: 'address', + }, + { + internalType: 'uint8', + name: '_tokenDecimals', + type: 'uint8', + }, + { + internalType: 'uint8', + name: '_sharedDecimals', + type: 'uint8', + }, + { + internalType: 'address', + name: '_endpoint', + type: 'address', + }, + { + internalType: 'address', + name: '_owner', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + inputs: [], + name: 'InvalidLocalDecimals', + type: 'error', + }, + { + inputs: [], + name: 'Path_AlreadyHasCredit', + type: 'error', + }, + { + inputs: [], + name: 'Path_InsufficientCredit', + type: 'error', + }, + { + inputs: [], + name: 'Path_UnlimitedCredit', + type: 'error', + }, + { + inputs: [ + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + ], + name: 'SlippageExceeded', + type: 'error', + }, + { + inputs: [], + name: 'StargatePoolUSDC_BurnAmountExceedsBalance', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_InsufficientFare', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_InvalidAmount', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_InvalidPath', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_InvalidTokenDecimals', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_LzTokenUnavailable', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_OnlyTaxi', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_OutflowFailed', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_Paused', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_RecoverTokenUnsupported', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_ReentrantCall', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_SlippageTooHigh', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_Unauthorized', + type: 'error', + }, + { + inputs: [], + name: 'Stargate_UnreceivedTokenNotFound', + type: 'error', + }, + { + inputs: [], + name: 'Transfer_ApproveFailed', + type: 'error', + }, + { + inputs: [], + name: 'Transfer_TransferFailed', + type: 'error', + }, + { + anonymous: false, + inputs: [ + { + components: [ + { + internalType: 'address', + name: 'feeLib', + type: 'address', + }, + { + internalType: 'address', + name: 'planner', + type: 'address', + }, + { + internalType: 'address', + name: 'treasurer', + type: 'address', + }, + { + internalType: 'address', + name: 'tokenMessaging', + type: 'address', + }, + { + internalType: 'address', + name: 'creditMessaging', + type: 'address', + }, + { + internalType: 'address', + name: 'lzToken', + type: 'address', + }, + ], + indexed: false, + internalType: 'struct StargateBase.AddressConfig', + name: 'config', + type: 'tuple', + }, + ], + name: 'AddressConfigSet', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'uint64', + name: 'amount', + type: 'uint64', + }, + ], + indexed: false, + internalType: 'struct Credit[]', + name: 'credits', + type: 'tuple[]', + }, + ], + name: 'CreditsReceived', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'uint64', + name: 'amount', + type: 'uint64', + }, + ], + indexed: false, + internalType: 'struct Credit[]', + name: 'credits', + type: 'tuple[]', + }, + ], + name: 'CreditsSent', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'payer', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + ], + name: 'Deposited', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + indexed: false, + internalType: 'bool', + name: 'oft', + type: 'bool', + }, + ], + name: 'OFTPathSet', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + indexed: true, + internalType: 'address', + name: 'toAddress', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amountReceivedLD', + type: 'uint256', + }, + ], + name: 'OFTReceived', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + indexed: true, + internalType: 'address', + name: 'fromAddress', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amountSentLD', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amountReceivedLD', + type: 'uint256', + }, + ], + name: 'OFTSent', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint64', + name: 'amountSD', + type: 'uint64', + }, + ], + name: 'Path_CreditBurned', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'bool', + name: 'paused', + type: 'bool', + }, + ], + name: 'PauseSet', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'PlannerFeeWithdrawn', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'payer', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + ], + name: 'Redeemed', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'uint64', + name: 'amountSD', + type: 'uint64', + }, + ], + name: 'TreasuryFeeAdded', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint64', + name: 'amountSD', + type: 'uint64', + }, + ], + name: 'TreasuryFeeWithdrawn', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + indexed: false, + internalType: 'uint8', + name: 'index', + type: 'uint8', + }, + { + indexed: false, + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + indexed: false, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + indexed: false, + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + ], + name: 'UnreceivedTokenCached', + type: 'event', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_amountLD', + type: 'uint256', + }, + ], + name: 'addTreasuryFee', + outputs: [], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_burnAdmin', + type: 'address', + }, + { + internalType: 'uint64', + name: '_burnAllowanceSD', + type: 'uint64', + }, + ], + name: 'allowBurn', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'approvalRequired', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'burnAdmin', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'burnAllowanceSD', + outputs: [ + { + internalType: 'uint64', + name: '', + type: 'uint64', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'burnLockedUSDC', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'deficitOffset', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_receiver', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amountLD', + type: 'uint256', + }, + ], + name: 'deposit', + outputs: [ + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [], + name: 'endpoint', + outputs: [ + { + internalType: 'contract ILayerZeroEndpointV2', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getAddressConfig', + outputs: [ + { + components: [ + { + internalType: 'address', + name: 'feeLib', + type: 'address', + }, + { + internalType: 'address', + name: 'planner', + type: 'address', + }, + { + internalType: 'address', + name: 'treasurer', + type: 'address', + }, + { + internalType: 'address', + name: 'tokenMessaging', + type: 'address', + }, + { + internalType: 'address', + name: 'creditMessaging', + type: 'address', + }, + { + internalType: 'address', + name: 'lzToken', + type: 'address', + }, + ], + internalType: 'struct StargateBase.AddressConfig', + name: '', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'getTransferGasLimit', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'localEid', + outputs: [ + { + internalType: 'uint32', + name: '', + type: 'uint32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'lpToken', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'oftVersion', + outputs: [ + { + internalType: 'bytes4', + name: 'interfaceId', + type: 'bytes4', + }, + { + internalType: 'uint64', + name: 'version', + type: 'uint64', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: 'eid', + type: 'uint32', + }, + ], + name: 'paths', + outputs: [ + { + internalType: 'uint64', + name: 'credit', + type: 'uint64', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'plannerFee', + outputs: [ + { + internalType: 'uint256', + name: 'available', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'poolBalance', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'to', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'extraOptions', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'oftCmd', + type: 'bytes', + }, + ], + internalType: 'struct SendParam', + name: '_sendParam', + type: 'tuple', + }, + ], + name: 'quoteOFT', + outputs: [ + { + components: [ + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'maxAmountLD', + type: 'uint256', + }, + ], + internalType: 'struct OFTLimit', + name: 'limit', + type: 'tuple', + }, + { + components: [ + { + internalType: 'int256', + name: 'feeAmountLD', + type: 'int256', + }, + { + internalType: 'string', + name: 'description', + type: 'string', + }, + ], + internalType: 'struct OFTFeeDetail[]', + name: 'oftFeeDetails', + type: 'tuple[]', + }, + { + components: [ + { + internalType: 'uint256', + name: 'amountSentLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'amountReceivedLD', + type: 'uint256', + }, + ], + internalType: 'struct OFTReceipt', + name: 'receipt', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'to', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'extraOptions', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'oftCmd', + type: 'bytes', + }, + ], + internalType: 'struct SendParam', + name: '_sendParam', + type: 'tuple', + }, + { + internalType: 'bool', + name: '_payInLzToken', + type: 'bool', + }, + ], + name: 'quoteRedeemSend', + outputs: [ + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: 'fee', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'to', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'extraOptions', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'oftCmd', + type: 'bytes', + }, + ], + internalType: 'struct SendParam', + name: '_sendParam', + type: 'tuple', + }, + { + internalType: 'bool', + name: '_payInLzToken', + type: 'bool', + }, + ], + name: 'quoteSend', + outputs: [ + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: 'fee', + type: 'tuple', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: '_srcEid', + type: 'uint32', + }, + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'uint64', + name: 'amount', + type: 'uint64', + }, + ], + internalType: 'struct Credit[]', + name: '_credits', + type: 'tuple[]', + }, + ], + name: 'receiveCredits', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'sender', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'nonce', + type: 'uint64', + }, + ], + internalType: 'struct Origin', + name: '_origin', + type: 'tuple', + }, + { + internalType: 'bytes32', + name: '_guid', + type: 'bytes32', + }, + { + internalType: 'uint8', + name: '_seatNumber', + type: 'uint8', + }, + { + internalType: 'address', + name: '_receiver', + type: 'address', + }, + { + internalType: 'uint64', + name: '_amountSD', + type: 'uint64', + }, + ], + name: 'receiveTokenBus', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'sender', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'nonce', + type: 'uint64', + }, + ], + internalType: 'struct Origin', + name: '_origin', + type: 'tuple', + }, + { + internalType: 'bytes32', + name: '_guid', + type: 'bytes32', + }, + { + internalType: 'address', + name: '_receiver', + type: 'address', + }, + { + internalType: 'uint64', + name: '_amountSD', + type: 'uint64', + }, + { + internalType: 'bytes', + name: '_composeMsg', + type: 'bytes', + }, + ], + name: 'receiveTokenTaxi', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_token', + type: 'address', + }, + { + internalType: 'address', + name: '_to', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amount', + type: 'uint256', + }, + ], + name: 'recoverToken', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_amountLD', + type: 'uint256', + }, + { + internalType: 'address', + name: '_receiver', + type: 'address', + }, + ], + name: 'redeem', + outputs: [ + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'to', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'extraOptions', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'oftCmd', + type: 'bytes', + }, + ], + internalType: 'struct SendParam', + name: '_sendParam', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: '_fee', + type: 'tuple', + }, + { + internalType: 'address', + name: '_refundAddress', + type: 'address', + }, + ], + name: 'redeemSend', + outputs: [ + { + components: [ + { + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'nonce', + type: 'uint64', + }, + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: 'fee', + type: 'tuple', + }, + ], + internalType: 'struct MessagingReceipt', + name: 'msgReceipt', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'amountSentLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'amountReceivedLD', + type: 'uint256', + }, + ], + internalType: 'struct OFTReceipt', + name: 'oftReceipt', + type: 'tuple', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_owner', + type: 'address', + }, + ], + name: 'redeemable', + outputs: [ + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'renounceOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: '_guid', + type: 'bytes32', + }, + { + internalType: 'uint8', + name: '_index', + type: 'uint8', + }, + { + internalType: 'uint32', + name: '_srcEid', + type: 'uint32', + }, + { + internalType: 'address', + name: '_receiver', + type: 'address', + }, + { + internalType: 'uint256', + name: '_amountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: '_composeMsg', + type: 'bytes', + }, + ], + name: 'retryReceiveToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'to', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'extraOptions', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'oftCmd', + type: 'bytes', + }, + ], + internalType: 'struct SendParam', + name: '_sendParam', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: '_fee', + type: 'tuple', + }, + { + internalType: 'address', + name: '_refundAddress', + type: 'address', + }, + ], + name: 'send', + outputs: [ + { + components: [ + { + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'nonce', + type: 'uint64', + }, + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: 'fee', + type: 'tuple', + }, + ], + internalType: 'struct MessagingReceipt', + name: 'msgReceipt', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'amountSentLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'amountReceivedLD', + type: 'uint256', + }, + ], + internalType: 'struct OFTReceipt', + name: 'oftReceipt', + type: 'tuple', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: '_dstEid', + type: 'uint32', + }, + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'uint64', + name: 'amount', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'minAmount', + type: 'uint64', + }, + ], + internalType: 'struct TargetCredit[]', + name: '_credits', + type: 'tuple[]', + }, + ], + name: 'sendCredits', + outputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'srcEid', + type: 'uint32', + }, + { + internalType: 'uint64', + name: 'amount', + type: 'uint64', + }, + ], + internalType: 'struct Credit[]', + name: '', + type: 'tuple[]', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'uint32', + name: 'dstEid', + type: 'uint32', + }, + { + internalType: 'bytes32', + name: 'to', + type: 'bytes32', + }, + { + internalType: 'uint256', + name: 'amountLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'minAmountLD', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'extraOptions', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'composeMsg', + type: 'bytes', + }, + { + internalType: 'bytes', + name: 'oftCmd', + type: 'bytes', + }, + ], + internalType: 'struct SendParam', + name: '_sendParam', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: '_fee', + type: 'tuple', + }, + { + internalType: 'address', + name: '_refundAddress', + type: 'address', + }, + ], + name: 'sendToken', + outputs: [ + { + components: [ + { + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + internalType: 'uint64', + name: 'nonce', + type: 'uint64', + }, + { + components: [ + { + internalType: 'uint256', + name: 'nativeFee', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'lzTokenFee', + type: 'uint256', + }, + ], + internalType: 'struct MessagingFee', + name: 'fee', + type: 'tuple', + }, + ], + internalType: 'struct MessagingReceipt', + name: 'msgReceipt', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint256', + name: 'amountSentLD', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'amountReceivedLD', + type: 'uint256', + }, + ], + internalType: 'struct OFTReceipt', + name: 'oftReceipt', + type: 'tuple', + }, + { + components: [ + { + internalType: 'uint72', + name: 'ticketId', + type: 'uint72', + }, + { + internalType: 'bytes', + name: 'passengerBytes', + type: 'bytes', + }, + ], + internalType: 'struct Ticket', + name: 'ticket', + type: 'tuple', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + components: [ + { + internalType: 'address', + name: 'feeLib', + type: 'address', + }, + { + internalType: 'address', + name: 'planner', + type: 'address', + }, + { + internalType: 'address', + name: 'treasurer', + type: 'address', + }, + { + internalType: 'address', + name: 'tokenMessaging', + type: 'address', + }, + { + internalType: 'address', + name: 'creditMessaging', + type: 'address', + }, + { + internalType: 'address', + name: 'lzToken', + type: 'address', + }, + ], + internalType: 'struct StargateBase.AddressConfig', + name: '_config', + type: 'tuple', + }, + ], + name: 'setAddressConfig', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_deficitOffsetLD', + type: 'uint256', + }, + ], + name: 'setDeficitOffset', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint32', + name: '_dstEid', + type: 'uint32', + }, + { + internalType: 'bool', + name: '_oft', + type: 'bool', + }, + ], + name: 'setOFTPath', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bool', + name: '_paused', + type: 'bool', + }, + ], + name: 'setPause', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'uint256', + name: '_gasLimit', + type: 'uint256', + }, + ], + name: 'setTransferGasLimit', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'sharedDecimals', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'stargateType', + outputs: [ + { + internalType: 'enum StargateType', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'pure', + type: 'function', + }, + { + inputs: [], + name: 'status', + outputs: [ + { + internalType: 'uint8', + name: '', + type: 'uint8', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'token', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'treasuryFee', + outputs: [ + { + internalType: 'uint64', + name: '', + type: 'uint64', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'tvl', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes32', + name: 'guid', + type: 'bytes32', + }, + { + internalType: 'uint8', + name: 'index', + type: 'uint8', + }, + ], + name: 'unreceivedTokens', + outputs: [ + { + internalType: 'bytes32', + name: 'hash', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'withdrawPlannerFee', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '_to', + type: 'address', + }, + { + internalType: 'uint64', + name: '_amountSD', + type: 'uint64', + }, + ], + name: 'withdrawTreasuryFee', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, +] as const; + +export class StargatePool__factory { + static readonly abi = _abi; + static createInterface(): StargatePoolInterface { + return new utils.Interface(_abi) as StargatePoolInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): StargatePool { + return new Contract(address, _abi, signerOrProvider) as StargatePool; + } +} diff --git a/src/logics/stargate-v2/contracts/factories/index.ts b/src/logics/stargate-v2/contracts/factories/index.ts new file mode 100644 index 0000000..45dfa0f --- /dev/null +++ b/src/logics/stargate-v2/contracts/factories/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { StargatePool__factory } from './StargatePool__factory'; diff --git a/src/logics/stargate-v2/contracts/index.ts b/src/logics/stargate-v2/contracts/index.ts new file mode 100644 index 0000000..9755f0b --- /dev/null +++ b/src/logics/stargate-v2/contracts/index.ts @@ -0,0 +1,6 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { StargatePool } from './StargatePool'; +export * as factories from './factories'; +export { StargatePool__factory } from './factories/StargatePool__factory'; diff --git a/src/logics/stargate-v2/index.ts b/src/logics/stargate-v2/index.ts new file mode 100644 index 0000000..6906b86 --- /dev/null +++ b/src/logics/stargate-v2/index.ts @@ -0,0 +1,2 @@ +export * from './configs'; +export * from './logic.swap-token'; diff --git a/src/logics/stargate-v2/logic.swap-token.test.ts b/src/logics/stargate-v2/logic.swap-token.test.ts new file mode 100644 index 0000000..3ab12b0 --- /dev/null +++ b/src/logics/stargate-v2/logic.swap-token.test.ts @@ -0,0 +1,88 @@ +import { LogicTestCase } from 'test/types'; +import { StargatePool__factory } from './contracts'; +import { SwapTokenLogic, SwapTokenLogicFields, SwapTokenLogicOptions } from './logic.swap-token'; +import * as common from '@protocolink/common'; +import { constants, utils } from 'ethers'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import { getPoolByTokenAddress } from './configs'; + +describe('StargateV2 SwapTokenLogic', function () { + context('Test getTokenList', async function () { + SwapTokenLogic.supportedChainIds.forEach((chainId) => { + it(`network: ${common.toNetworkId(chainId)}`, async function () { + const logic = new SwapTokenLogic(chainId); + const tokenList = await logic.getTokenList(); + expect(tokenList).to.have.lengthOf.above(0); + }); + }); + }); + + context('Test build', function () { + const chainId = common.ChainId.mainnet; + const logic = new SwapTokenLogic(chainId); + const stgIface = StargatePool__factory.createInterface(); + const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; + + const testCases: LogicTestCase[] = [ + { + fields: { + input: new common.TokenAmount(common.mainnetTokens.ETH, '1'), + output: new common.TokenAmount(common.optimismTokens.ETH, '1'), + receiver: account, + fee: '0', + lzTokenFee: '0', + }, + options: { account }, + }, + { + fields: { + input: new common.TokenAmount(common.mainnetTokens.USDC, '1'), + output: new common.TokenAmount(common.optimismTokens.USDC, '1'), + receiver: account, + fee: '0.01', + lzTokenFee: '0.01', + }, + options: { account }, + }, + { + fields: { + input: new common.TokenAmount(common.mainnetTokens.USDC, '1'), + output: new common.TokenAmount(common.optimismTokens.USDC, '1'), + receiver: account, + fee: '0.01', + lzTokenFee: '0.01', + balanceBps: 5000, + }, + options: { account }, + }, + ]; + + testCases.forEach(({ fields, options }) => { + it(`${fields.input.token.symbol} to ${fields.output.token.symbol}`, async function () { + const routerLogic = await logic.build(fields, options); + const sig = routerLogic.data.substring(0, 10); + const { input, balanceBps, fee } = fields; + const poolAddress = getPoolByTokenAddress(chainId, input.token.address); + + expect(routerLogic.to).to.eq(poolAddress); + expect(sig).to.eq(stgIface.getSighash('sendToken')); + expect(routerLogic.inputs[0].token).to.eq(input.token.elasticAddress); + expect(routerLogic.inputs[1].token).to.eq(common.mainnetTokens.ETH.elasticAddress); + expect(routerLogic.inputs[1].amountOrOffset).to.eq(common.toSmallUnit(fee, common.mainnetTokens.ETH.decimals)); + expect(utils.isBytesLike(routerLogic.data)).to.be.true; + + if (balanceBps) { + expect(routerLogic.inputs[0].balanceBps).to.eq(balanceBps); + expect(routerLogic.inputs[0].amountOrOffset).to.eq(common.getParamOffset(2)); + } else { + expect(routerLogic.inputs[0].balanceBps).to.eq(core.BPS_NOT_USED); + expect(routerLogic.inputs[0].amountOrOffset).eq(input.amountWei); + } + expect(routerLogic.wrapMode).to.eq(core.WrapMode.none); + expect(routerLogic.approveTo).to.eq(constants.AddressZero); + expect(routerLogic.callback).to.eq(constants.AddressZero); + }); + }); + }); +}); diff --git a/src/logics/stargate-v2/logic.swap-token.ts b/src/logics/stargate-v2/logic.swap-token.ts new file mode 100644 index 0000000..b325dc6 --- /dev/null +++ b/src/logics/stargate-v2/logic.swap-token.ts @@ -0,0 +1,129 @@ +import { StargatePool__factory } from './contracts'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { getDestChainIds, getEndpointId, getMarkets, getPoolByTokenAddress, supportedChainIds } from './configs'; +import { getNativeToken } from '@protocolink/common'; +import { utils } from 'ethers'; + +export type SwapTokenLogicTokenList = { + srcToken: common.Token; + destChainIds: number[]; +}[]; + +export type SwapTokenLogicParams = core.TokenToTokenExactInParams<{ + receiver: string; +}>; + +export type SwapTokenLogicFields = core.TokenToTokenExactInFields<{ + receiver: string; + fee: string; + lzTokenFee: string; +}>; + +export type SwapTokenLogicOptions = Pick; + +export class SwapTokenLogic extends core.Logic implements core.LogicBuilderInterface { + static id = 'swap-token'; + static protocolId = 'stargate-v2'; + static readonly supportedChainIds = supportedChainIds; + + async getTokenList() { + const tokenList: SwapTokenLogicTokenList = []; + const srcTokens = []; + + const markets = getMarkets(this.chainId); + for (const market of markets) { + srcTokens.push(market.token); + } + + // find destination chain ids + for (const srcToken of srcTokens) { + const destChainIds = getDestChainIds(this.chainId, srcToken); + tokenList.push({ srcToken, destChainIds }); + } + + return tokenList; + } + + public async quote(params: SwapTokenLogicParams) { + const { input, tokenOut, receiver } = params; + const dstEid = getEndpointId(tokenOut.chainId); + const to = utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32); + const poolAddress = getPoolByTokenAddress(this.chainId, input.token.address); + const amountLD = input.amountWei; + const sendParam = { + dstEid, + to, + amountLD, + minAmountLD: amountLD, + extraOptions: utils.solidityPack(['string'], ['']), + composeMsg: utils.solidityPack(['string'], ['']), + oftCmd: utils.solidityPack(['string'], ['']), + }; + + const stargate = StargatePool__factory.connect(poolAddress, this.provider); + const [, , receipt] = await stargate.quoteOFT(sendParam); + sendParam.minAmountLD = receipt.amountReceivedLD; + + const messagingFee = await stargate.quoteSend(sendParam, false); + const fee = messagingFee.nativeFee; + const lzTokenFee = messagingFee.lzTokenFee; + + const output = new common.TokenAmount(tokenOut).setWei(receipt.amountReceivedLD); + + return { + input, + output, + fee: common.toBigUnit(fee, getNativeToken(this.chainId).decimals), + lzTokenFee: common.toBigUnit(lzTokenFee, getNativeToken(this.chainId).decimals), + receiver, + }; + } + + async build(fields: SwapTokenLogicFields, options: SwapTokenLogicOptions) { + const { input, output, fee, lzTokenFee, receiver, balanceBps } = fields; + const { account } = options; + const refundAddress = account; + + const to = getPoolByTokenAddress(this.chainId, input.token.address); + const dstEid = getEndpointId(output.token.chainId); + const amountLD = input.amountWei; + const minAmountLD = output.amountWei; + const sendParam = { + dstEid, + to: utils.hexZeroPad(utils.solidityPack(['address'], [receiver]), 32), + amountLD, + minAmountLD, + extraOptions: utils.solidityPack(['string'], ['']), + composeMsg: utils.solidityPack(['string'], ['']), + oftCmd: utils.solidityPack(['string'], ['']), + }; + + const nativeToken = getNativeToken(this.chainId); + const messagingFee = { + nativeFee: new common.TokenAmount(nativeToken, fee).amountWei, + lzTokenFee: new common.TokenAmount(nativeToken, lzTokenFee).amountWei, + }; + + const data = StargatePool__factory.createInterface().encodeFunctionData('sendToken', [ + sendParam, + messagingFee, + refundAddress, + ]); + + const amountOffset = balanceBps ? common.getParamOffset(2) : undefined; + + const inputs = [ + core.newLogicInput({ + input: new common.TokenAmount(input.token, input.amount), + balanceBps, + amountOffset, + }), + core.newLogicInput({ input: new common.TokenAmount(getNativeToken(this.chainId), fee) }), + ]; + + // does not support unwrapBefore so users need to unwrap wrapped native token first + const wrapMode = core.WrapMode.none; + return core.newLogic({ to, data, inputs, wrapMode }); + } +} diff --git a/src/logics/stargate-v2/tokens/data/mainnet.json b/src/logics/stargate-v2/tokens/data/mainnet.json new file mode 100644 index 0000000..f57373e --- /dev/null +++ b/src/logics/stargate-v2/tokens/data/mainnet.json @@ -0,0 +1,9 @@ +{ + "Metis": { + "chainId": 1, + "address": "0x9E32b13ce7f2E80A01932B42553652E053D6ed8e", + "decimals": 18, + "symbol": "Metis", + "name": "Metis Token" + } +} diff --git a/src/logics/stargate-v2/tokens/data/metis.json b/src/logics/stargate-v2/tokens/data/metis.json new file mode 100644 index 0000000..2b68bb1 --- /dev/null +++ b/src/logics/stargate-v2/tokens/data/metis.json @@ -0,0 +1,9 @@ +{ + "Metis": { + "chainId": 1088, + "address": "0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000", + "decimals": 18, + "symbol": "Metis", + "name": "Metis Token" + } +} diff --git a/src/logics/stargate-v2/tokens/index.ts b/src/logics/stargate-v2/tokens/index.ts new file mode 100644 index 0000000..aaf219a --- /dev/null +++ b/src/logics/stargate-v2/tokens/index.ts @@ -0,0 +1,11 @@ +import * as common from '@protocolink/common'; +import mainnetTokensJSON from './data/mainnet.json'; +import metisTokensJSON from './data/metis.json'; + +type MainnetTokenSymbols = keyof typeof mainnetTokensJSON; + +export const mainnetTokens = { ...common.toTokenMap(mainnetTokensJSON) }; + +type MetisTokenSymbols = keyof typeof metisTokensJSON; + +export const metisTokens = { ...common.toTokenMap(metisTokensJSON) }; diff --git a/test/logics/stargate-v2/swap-token.test.ts b/test/logics/stargate-v2/swap-token.test.ts new file mode 100644 index 0000000..91af81d --- /dev/null +++ b/test/logics/stargate-v2/swap-token.test.ts @@ -0,0 +1,90 @@ +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; +import { claimToken, getChainId, snapshotAndRevertEach } from '@protocolink/test-helpers'; +import * as common from '@protocolink/common'; +import * as core from '@protocolink/core'; +import { expect } from 'chai'; +import { getNativeToken } from '@protocolink/common'; +import hre from 'hardhat'; +import * as stargate from 'src/logics/stargate-v2'; +import * as utils from 'test/utils'; + +describe('mainnet: Test StargateV2 SwapToken Logic', function () { + let chainId: number; + let user: SignerWithAddress; + + before(async function () { + chainId = await getChainId(); + [, user] = await hre.ethers.getSigners(); + await claimToken(chainId, user.address, common.mainnetTokens.USDC, '5000'); + }); + + snapshotAndRevertEach(); + + const testCases = [ + { + params: { + input: new common.TokenAmount(common.mainnetTokens.ETH, '1'), + tokenOut: common.optimismTokens.ETH, + }, + }, + { + params: { + input: new common.TokenAmount(common.mainnetTokens.USDC, '100'), + tokenOut: common.optimismTokens.USDC, + }, + }, + { + params: { + input: new common.TokenAmount(common.mainnetTokens.USDC, '100'), + tokenOut: common.optimismTokens.USDC, + }, + balanceBps: 5000, + }, + ]; + + testCases.forEach(({ params, balanceBps }, i) => { + it(`case ${i + 1}`, async function () { + // 1. get input or output + const stargateSwapTokenLogic = new stargate.SwapTokenLogic(chainId); + const quotation = await stargateSwapTokenLogic.quote({ receiver: user.address, ...params }); + const { input, fee } = quotation; + + // 2. build funds, tokensReturn + const feeTokenAmount = new common.TokenAmount(getNativeToken(chainId), fee); + const funds = new common.TokenAmounts([feeTokenAmount]); + const tokensReturn = [input.token.elasticAddress]; + if (balanceBps) { + funds.add(utils.calcRequiredAmountByBalanceBps(input, balanceBps)); + tokensReturn.push(input.token.elasticAddress); + } else { + funds.add(input); + } + + // 3. build router logics + const routerLogics: core.DataType.LogicStruct[] = []; + routerLogics.push(await stargateSwapTokenLogic.build(quotation, { account: user.address })); + + // 4. get router permit2 datas + let permit2Datas; + if (!input.token.isNative) { + permit2Datas = await utils.getRouterPermit2Datas(chainId, user, funds.erc20); + } + // 5. send router tx + const routerKit = new core.RouterKit(chainId); + const transactionRequest = routerKit.buildExecuteTransactionRequest({ + permit2Datas, + routerLogics, + tokensReturn, + value: funds.native?.amountWei ?? 0, + }); + + await expect(user.sendTransaction(transactionRequest)).to.not.be.reverted; + if (input.token.isNative) { + await expect(user.address).to.changeBalance(getNativeToken(chainId), -input.add(fee).amount, 1); + } else { + await expect(user.address).to.changeBalance(input.token, -input.amount); + await expect(user.address).to.changeBalance(getNativeToken(chainId), -fee); + } + }); + }); +});