diff --git a/scripts/abigen.sh b/scripts/abigen.sh index 04b5416f..f0937f2b 100755 --- a/scripts/abigen.sh +++ b/scripts/abigen.sh @@ -44,4 +44,6 @@ process_abi "contracts/bridge/SynapseBridge.sol" "SynapseBridge" process_abi "contracts/bridge/SynapseERC20.sol" "SynapseERC20" process_abi "contracts/bridge/wrappers/L2BridgeZap.sol" "L2BridgeZap" process_abi "contracts/bridge/wrappers/L1BridgeZap.sol" "L1BridgeZap" -process_abi "contracts/bridge/BridgeConfig.sol" "BridgeConfig" \ No newline at end of file +process_abi "contracts/bridge/BridgeConfig.sol" "BridgeConfig" +process_abi "contracts/bridge/PoolConfig.sol" "PoolConfig" +process_abi "contracts/amm/SwapFlashLoan.sol" "SwapFlashLoan" \ No newline at end of file diff --git a/src/abis/PoolConfig.ts b/src/abis/PoolConfig.ts new file mode 100644 index 00000000..80419f7d --- /dev/null +++ b/src/abis/PoolConfig.ts @@ -0,0 +1,386 @@ +const ABI = { + "abi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "previousAdminRole", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "newAdminRole", + "type": "bytes32" + } + ], + "name": "RoleAdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleGranted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "RoleRevoked", + "type": "event" + }, + { + "inputs": [], + "name": "BRIDGEMANAGER_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DEFAULT_ADMIN_ROLE", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "chainID", + "type": "uint256" + } + ], + "name": "getPoolConfig", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "poolAddress", + "type": "address" + }, + { + "internalType": "bool", + "name": "metaswap", + "type": "bool" + } + ], + "internalType": "struct PoolConfig.Pool", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "getRoleAdmin", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "getRoleMember", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + } + ], + "name": "getRoleMemberCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "hasRole", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "renounceRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "role", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeRole", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "chainID", + "type": "uint256" + }, + { + "internalType": "address", + "name": "poolAddress", + "type": "address" + }, + { + "internalType": "bool", + "name": "metaswap", + "type": "bool" + } + ], + "name": "setPoolConfig", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "poolAddress", + "type": "address" + }, + { + "internalType": "bool", + "name": "metaswap", + "type": "bool" + } + ], + "internalType": "struct PoolConfig.Pool", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "devdoc": { + "kind": "dev", + "methods": { + "getRoleAdmin(bytes32)": { + "details": "Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}." + }, + "getRoleMember(bytes32,uint256)": { + "details": "Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information." + }, + "getRoleMemberCount(bytes32)": { + "details": "Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role." + }, + "grantRole(bytes32,address)": { + "details": "Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role." + }, + "hasRole(bytes32,address)": { + "details": "Returns `true` if `account` has been granted `role`." + }, + "renounceRole(bytes32,address)": { + "details": "Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`." + }, + "revokeRole(bytes32,address)": { + "details": "Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role." + } + }, + "version": 1 + }, + "userdoc": { + "kind": "user", + "methods": {}, + "version": 1 + } +} + +export default ABI diff --git a/src/abis/SwapFlashLoan.ts b/src/abis/SwapFlashLoan.ts new file mode 100644 index 00000000..e75dcae2 --- /dev/null +++ b/src/abis/SwapFlashLoan.ts @@ -0,0 +1,1286 @@ +const ABI = { + "abi": [ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "tokenAmounts", + "type": "uint256[]" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "fees", + "type": "uint256[]" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "invariant", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "lpTokenSupply", + "type": "uint256" + } + ], + "name": "AddLiquidity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "tokenIndex", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountFee", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "protocolFee", + "type": "uint256" + } + ], + "name": "FlashLoan", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "newAdminFee", + "type": "uint256" + } + ], + "name": "NewAdminFee", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "newSwapFee", + "type": "uint256" + } + ], + "name": "NewSwapFee", + "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": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "oldA", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newA", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "initialTime", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "futureTime", + "type": "uint256" + } + ], + "name": "RampA", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "tokenAmounts", + "type": "uint256[]" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "lpTokenSupply", + "type": "uint256" + } + ], + "name": "RemoveLiquidity", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "tokenAmounts", + "type": "uint256[]" + }, + { + "indexed": false, + "internalType": "uint256[]", + "name": "fees", + "type": "uint256[]" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "invariant", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "lpTokenSupply", + "type": "uint256" + } + ], + "name": "RemoveLiquidityImbalance", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "provider", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "lpTokenAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "lpTokenSupply", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "boughtId", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokensBought", + "type": "uint256" + } + ], + "name": "RemoveLiquidityOne", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "currentA", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "StopRampA", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "buyer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokensSold", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "tokensBought", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "soldId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "boughtId", + "type": "uint128" + } + ], + "name": "TokenSwap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "MAX_BPS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "minToMint", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "addLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "calculateRemoveLiquidity", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "tokenIndex", + "type": "uint8" + } + ], + "name": "calculateRemoveLiquidityOneToken", + "outputs": [ + { + "internalType": "uint256", + "name": "availableTokenAmount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "tokenIndexFrom", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "tokenIndexTo", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "dx", + "type": "uint256" + } + ], + "name": "calculateSwap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + }, + { + "internalType": "bool", + "name": "deposit", + "type": "bool" + } + ], + "name": "calculateTokenAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "params", + "type": "bytes" + } + ], + "name": "flashLoan", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "flashLoanFeeBPS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getA", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAPrecise", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "index", + "type": "uint256" + } + ], + "name": "getAdminBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "index", + "type": "uint8" + } + ], + "name": "getToken", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "index", + "type": "uint8" + } + ], + "name": "getTokenBalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "tokenAddress", + "type": "address" + } + ], + "name": "getTokenIndex", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVirtualPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20[]", + "name": "_pooledTokens", + "type": "address[]" + }, + { + "internalType": "uint8[]", + "name": "decimals", + "type": "uint8[]" + }, + { + "internalType": "string", + "name": "lpTokenName", + "type": "string" + }, + { + "internalType": "string", + "name": "lpTokenSymbol", + "type": "string" + }, + { + "internalType": "uint256", + "name": "_a", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_adminFee", + "type": "uint256" + }, + { + "internalType": "address", + "name": "lpTokenTargetAddress", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "protocolFeeShareBPS", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "futureA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "futureTime", + "type": "uint256" + } + ], + "name": "rampA", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "minAmounts", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidity", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "amounts", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "maxBurnAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidityImbalance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmount", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "tokenIndex", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "minAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "removeLiquidityOneToken", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "newAdminFee", + "type": "uint256" + } + ], + "name": "setAdminFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "newFlashLoanFeeBPS", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "newProtocolFeeShareBPS", + "type": "uint256" + } + ], + "name": "setFlashLoanFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "newSwapFee", + "type": "uint256" + } + ], + "name": "setSwapFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "stopRampA", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "tokenIndexFrom", + "type": "uint8" + }, + { + "internalType": "uint8", + "name": "tokenIndexTo", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "dx", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minDy", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + } + ], + "name": "swap", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "swapStorage", + "outputs": [ + { + "internalType": "uint256", + "name": "initialA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "futureA", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "initialATime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "futureATime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "swapFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "adminFee", + "type": "uint256" + }, + { + "internalType": "contract LPToken", + "name": "lpToken", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawAdminFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "devdoc": { + "details": "Most of the logic is stored as a library `SwapUtils` for the sake of reducing contract's deployment size.", + "kind": "dev", + "methods": { + "addLiquidity(uint256[],uint256,uint256)": { + "params": { + "amounts": "the amounts of each token to add, in their native precision", + "deadline": "latest timestamp to accept this transaction", + "minToMint": "the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation" + }, + "returns": { + "_0": "amount of LP token user minted and received" + } + }, + "calculateRemoveLiquidity(uint256)": { + "params": { + "amount": "the amount of LP tokens that would be burned on withdrawal" + }, + "returns": { + "_0": "array of token balances that the user will receive" + } + }, + "calculateRemoveLiquidityOneToken(uint256,uint8)": { + "params": { + "tokenAmount": "the amount of LP token to burn", + "tokenIndex": "index of which token will be withdrawn" + }, + "returns": { + "availableTokenAmount": "calculated amount of underlying token available to withdraw" + } + }, + "calculateSwap(uint8,uint8,uint256)": { + "params": { + "dx": "the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee.", + "tokenIndexFrom": "the token the user wants to sell", + "tokenIndexTo": "the token the user wants to buy" + }, + "returns": { + "_0": "amount of tokens the user will receive" + } + }, + "calculateTokenAmount(uint256[],bool)": { + "details": "This shouldn't be used outside frontends for user estimates.", + "params": { + "amounts": "an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee.", + "deposit": "whether this is a deposit or a withdrawal" + }, + "returns": { + "_0": "token amount the user will receive" + } + }, + "flashLoan(address,address,uint256,bytes)": { + "params": { + "amount": "the total amount to borrow in this transaction", + "params": "optional data to pass along to the callback function", + "receiver": "the address of the receiver of the token. This address must implement the IFlashLoanReceiver interface and the callback function `executeOperation`.", + "token": "the protocol fee in bps to be applied on the total flash loan fee" + } + }, + "getA()": { + "details": "See the StableSwap paper for details", + "returns": { + "_0": "A parameter" + } + }, + "getAPrecise()": { + "details": "See the StableSwap paper for details", + "returns": { + "_0": "A parameter in its raw precision form" + } + }, + "getAdminBalance(uint256)": { + "params": { + "index": "Index of the pooled token" + }, + "returns": { + "_0": "admin's token balance in the token's precision" + } + }, + "getToken(uint8)": { + "params": { + "index": "the index of the token" + }, + "returns": { + "_0": "address of the token at given index" + } + }, + "getTokenBalance(uint8)": { + "params": { + "index": "the index of the token" + }, + "returns": { + "_0": "current balance of the pooled token at given index with token's native precision" + } + }, + "getTokenIndex(address)": { + "params": { + "tokenAddress": "address of the token" + }, + "returns": { + "_0": "the index of the given token address" + } + }, + "getVirtualPrice()": { + "returns": { + "_0": "the virtual price, scaled to the POOL_PRECISION_DECIMALS" + } + }, + "initialize(address[],uint8[],string,string,uint256,uint256,uint256,address)": { + "params": { + "_a": "the amplification coefficient * n * (n - 1). See the StableSwap paper for details", + "_adminFee": "default adminFee to be initialized with", + "_fee": "default swap fee to be initialized with", + "_pooledTokens": "an array of ERC20s this pool will accept", + "decimals": "the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS", + "lpTokenName": "the long-form name of the token to be deployed", + "lpTokenSymbol": "the short symbol for the token to be deployed", + "lpTokenTargetAddress": "the address of an existing LPToken contract to use as a target" + } + }, + "owner()": { + "details": "Returns the address of the current owner." + }, + "paused()": { + "details": "Returns true if the contract is paused, and false otherwise." + }, + "rampA(uint256,uint256)": { + "params": { + "futureA": "the new A to ramp towards", + "futureTime": "timestamp when the new A should be reached" + } + }, + "removeLiquidity(uint256,uint256[],uint256)": { + "details": "Liquidity can always be removed, even when the pool is paused.", + "params": { + "amount": "the amount of LP tokens to burn", + "deadline": "latest timestamp to accept this transaction", + "minAmounts": "the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation" + }, + "returns": { + "_0": "amounts of tokens user received" + } + }, + "removeLiquidityImbalance(uint256[],uint256,uint256)": { + "params": { + "amounts": "how much of each token to withdraw", + "deadline": "latest timestamp to accept this transaction", + "maxBurnAmount": "the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation." + }, + "returns": { + "_0": "amount of LP tokens burned" + } + }, + "removeLiquidityOneToken(uint256,uint8,uint256,uint256)": { + "params": { + "deadline": "latest timestamp to accept this transaction", + "minAmount": "the minimum amount to withdraw, otherwise revert", + "tokenAmount": "the amount of the token you want to receive", + "tokenIndex": "the index of the token you want to receive" + }, + "returns": { + "_0": "amount of chosen token user received" + } + }, + "renounceOwnership()": { + "details": "Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner." + }, + "setAdminFee(uint256)": { + "params": { + "newAdminFee": "new admin fee to be applied on future transactions" + } + }, + "setFlashLoanFees(uint256,uint256)": { + "params": { + "newFlashLoanFeeBPS": "the total fee in bps to be applied on future flash loans", + "newProtocolFeeShareBPS": "the protocol fee in bps to be applied on the total flash loan fee" + } + }, + "setSwapFee(uint256)": { + "params": { + "newSwapFee": "new swap fee to be applied on future transactions" + } + }, + "swap(uint8,uint8,uint256,uint256,uint256)": { + "params": { + "deadline": "latest timestamp to accept this transaction", + "dx": "the amount of tokens the user wants to swap from", + "minDy": "the min amount the user would like to receive, or revert.", + "tokenIndexFrom": "the token the user wants to swap from", + "tokenIndexTo": "the token the user wants to swap to" + } + }, + "transferOwnership(address)": { + "details": "Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner." + } + }, + "title": "Swap - A StableSwap implementation in solidity.", + "version": 1 + }, + "userdoc": { + "kind": "user", + "methods": { + "addLiquidity(uint256[],uint256,uint256)": { + "notice": "Add liquidity to the pool with the given amounts of tokens" + }, + "calculateRemoveLiquidity(uint256)": { + "notice": "A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens" + }, + "calculateRemoveLiquidityOneToken(uint256,uint8)": { + "notice": "Calculate the amount of underlying token available to withdraw when withdrawing via only single token" + }, + "calculateSwap(uint8,uint8,uint256)": { + "notice": "Calculate amount of tokens you receive on swap" + }, + "calculateTokenAmount(uint256[],bool)": { + "notice": "A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various \"min\" parameters on calls to fight front-running" + }, + "flashLoan(address,address,uint256,bytes)": { + "notice": "Borrow the specified token from this pool for this transaction only. This function will call `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token and the associated fee by the end of the callback transaction. If the conditions are not met, this call is reverted." + }, + "getA()": { + "notice": "Return A, the amplification coefficient * n * (n - 1)" + }, + "getAPrecise()": { + "notice": "Return A in its raw precision form" + }, + "getAdminBalance(uint256)": { + "notice": "This function reads the accumulated amount of admin fees of the token with given index" + }, + "getToken(uint8)": { + "notice": "Return address of the pooled token at given index. Reverts if tokenIndex is out of range." + }, + "getTokenBalance(uint8)": { + "notice": "Return current balance of the pooled token at given index" + }, + "getTokenIndex(address)": { + "notice": "Return the index of the given token address. Reverts if no matching token is found." + }, + "getVirtualPrice()": { + "notice": "Get the virtual price, to help calculate profit" + }, + "initialize(address[],uint8[],string,string,uint256,uint256,uint256,address)": { + "notice": "Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens." + }, + "pause()": { + "notice": "Pause the contract. Revert if already paused." + }, + "rampA(uint256,uint256)": { + "notice": "Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range." + }, + "removeLiquidity(uint256,uint256[],uint256)": { + "notice": "Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply." + }, + "removeLiquidityImbalance(uint256[],uint256,uint256)": { + "notice": "Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply." + }, + "removeLiquidityOneToken(uint256,uint8,uint256,uint256)": { + "notice": "Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply." + }, + "setAdminFee(uint256)": { + "notice": "Update the admin fee. Admin fee takes portion of the swap fee." + }, + "setFlashLoanFees(uint256,uint256)": { + "notice": "Updates the flash loan fee parameters. This function can only be called by the owner." + }, + "setSwapFee(uint256)": { + "notice": "Update the swap fee to be applied on swaps" + }, + "stopRampA()": { + "notice": "Stop ramping A immediately. Reverts if ramp A is already stopped." + }, + "swap(uint8,uint8,uint256,uint256,uint256)": { + "notice": "Swap two tokens using this pool" + }, + "unpause()": { + "notice": "Unpause the contract. Revert if already unpaused." + }, + "withdrawAdminFees()": { + "notice": "Withdraw all admin fees to the contract owner" + } + }, + "notice": "This contract is responsible for custody of closely pegged assets (eg. group of stablecoins) and automatic market making system. Users become an LP (Liquidity Provider) by depositing their tokens in desired ratios for an exchange of the pool token that represents their share of the pool. Users can burn pool tokens and withdraw their share of token(s). Each time a swap between the pooled tokens happens, a set fee incurs which effectively gets distributed to the LPs. In case of emergencies, admin can pause additional deposits, swaps, or single-asset withdraws - which stops the ratio of the tokens in the pool from changing. Users can always withdraw their tokens via multi-asset withdraws.", + "version": 1 + } +} + +export default ABI diff --git a/src/bridge/bridge.ts b/src/bridge/bridge.ts index ac4bde4b..696aa93a 100644 --- a/src/bridge/bridge.ts +++ b/src/bridge/bridge.ts @@ -13,6 +13,8 @@ import { Tokens, } from "../tokens"; +import {TokenSwap} from "../tokenswap"; + import type {Token} from "../token"; import {SwapPools} from "../swappools"; @@ -30,8 +32,6 @@ import {formatUnits} from "@ethersproject/units"; import {BigNumber, BigNumberish} from "@ethersproject/bignumber"; import {ContractTransaction, PopulatedTransaction} from "@ethersproject/contracts"; -import {UnsupportedSwapReason} from "./errors"; - import { ERC20, MAX_APPROVAL_AMOUNT @@ -157,34 +157,9 @@ export namespace Bridge { tokenTo: Token chainIdTo: number, }): [boolean, string] { - let {tokenFrom, tokenTo, chainIdTo} = args; - - if (!this.network.supportsToken(tokenFrom)) { - return [false, UnsupportedSwapReason.TokenNotSupported_From] - } - - if (!Networks.networkSupportsToken(chainIdTo, tokenTo)) { - return [false, UnsupportedSwapReason.TokenNotSupported_To] - } - - if (tokenFrom.swapType !== tokenTo.swapType) { - return [false, UnsupportedSwapReason.NonmatchingSwapTypes] - } - - let - isEthFromBoba = (this.chainId === ChainId.BOBA) && (tokenFrom.swapType === SwapType.ETH), - isEthToBoba = (chainIdTo === ChainId.BOBA) && (tokenTo.swapType === SwapType.ETH); - - if (isEthFromBoba || isEthToBoba) { - return [false, UnsupportedSwapReason.ETHOnBOBA] - } - // if ((this.chainId === ChainId.BOBA) && (tokenFrom.swapType === SwapType.ETH)) { - // if ((chainIdTo === ChainId.ETH) && (tokenTo.isETH)) { - // return [false, UnsupportedSwapReason.BOBAToL1] - // } - // } + const {swapSupported, reasonNotSupported} = TokenSwap.bridgeSwapSupported({...args, chainIdFrom: this.chainId}); - return [true, ""] + return [swapSupported, reasonNotSupported?.reason || ""] } /** @@ -420,27 +395,11 @@ export namespace Bridge { } private async checkSwapSupported(args: BridgeParams): Promise { - const - {chainIdTo, tokenFrom, tokenTo} = args, - networkTo = Networks.fromChainId(chainIdTo); - return new Promise((resolve, reject) => { - let [swapSupported, errReason] = this.swapSupported({tokenFrom, chainIdTo, tokenTo}); + let [swapSupported, errReason] = this.swapSupported(args); if (!swapSupported) { - switch (errReason) { - case UnsupportedSwapReason.TokenNotSupported_From: - reject(`Network '${this.network.name}' does not support token ${tokenFrom.name} (param: tokenFrom)`); - break; - case UnsupportedSwapReason.TokenNotSupported_To: - reject(`Network '${networkTo.name}' (param: chainIdTo) does not support token ${tokenTo.name} (param: tokenTo)`); - break; - case UnsupportedSwapReason.NonmatchingSwapTypes: - reject(`param tokenFrom with swapType '${tokenFrom.swapType}' cannot be bridge to param tokenTo with swapType '${tokenTo.swapType}'`); - break; - default: - reject(errReason); - break; - } + reject(errReason); + return } resolve(true); @@ -459,47 +418,10 @@ export namespace Bridge { fromChainTokens } = this.makeBridgeTokenArgs(args); - const mintBurnSwapTypes = [ - SwapType.HIGH, SwapType.DOG, SwapType.JUMP, - SwapType.NFD, SwapType.OHM, SwapType.SOLAR, - SwapType.GMX, - ]; - let [intermediateToken, bridgeConfigIntermediateToken] = ((): [Token, Token] => { - if (mintBurnSwapTypes.includes(tokenFrom.swapType)) { - return [tokenFrom, tokenFrom] - } - - switch (tokenFrom.swapType) { - case SwapType.SYN: - return [Tokens.SYN, Tokens.SYN] - case SwapType.FRAX: - if (chainIdTo === ChainId.ETH) { - return [null, Tokens.FRAX] - } else { - return [null, Tokens.SYN_FRAX] - } - case SwapType.ETH: - let intermediate: Token; - if (chainIdTo === ChainId.ETH) { - intermediate = Tokens.WETH; - } else { - intermediate = Tokens.NETH; - } - - return [Tokens.NETH, intermediate] - case SwapType.AVAX: - return [Tokens.WAVAX, Tokens.WAVAX] - case SwapType.MOVR: - return [Tokens.WMOVR, Tokens.WMOVR] - default: - return [Tokens.NUSD, Tokens.NUSD] - } - })(); + let {intermediateToken, bridgeConfigIntermediateToken} = TokenSwap.intermediateTokens(chainIdTo, tokenFrom); const bigNumTen = BigNumber.from(10); - - bridgeConfigIntermediateToken = bridgeConfigIntermediateToken ?? intermediateToken; const bridgeFeeRequest = this.bridgeConfigInstance.calculateSwapFee( bridgeConfigIntermediateToken.address(chainIdTo), chainIdTo, diff --git a/src/bridge/errors.ts b/src/bridge/errors.ts deleted file mode 100644 index cc6c0f86..00000000 --- a/src/bridge/errors.ts +++ /dev/null @@ -1,8 +0,0 @@ -export namespace UnsupportedSwapReason { - export const - TokenNotSupported_From = "Token not supported on 'from' network", - TokenNotSupported_To = "Token not suppoorted on 'to' network", - NonmatchingSwapTypes = "Token swap types don't match", - BOBAToL1 = "Bridging ETH from Boba Mainnet to L1 not currently supported", - ETHOnBOBA = "Currently, the SDK only supports bridging Stablecoins to and from BOBA"; -} \ No newline at end of file diff --git a/src/bridge/index.ts b/src/bridge/index.ts index b5838adc..c495390e 100644 --- a/src/bridge/index.ts +++ b/src/bridge/index.ts @@ -1,5 +1,3 @@ export * from "./bridge"; export * from "./slippages"; - -export {UnsupportedSwapReason} from "./errors"; \ No newline at end of file diff --git a/src/contracts/gen/BridgeConfig.ts b/src/contracts/gen/BridgeConfig.ts index 2b5f74b0..d21f16f0 100644 --- a/src/contracts/gen/BridgeConfig.ts +++ b/src/contracts/gen/BridgeConfig.ts @@ -1,67 +1,63 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ - import { - ethers, - EventFilter, - Signer, + BaseContract, BigNumber, BigNumberish, - PopulatedTransaction, - BaseContract, + BytesLike, + CallOverrides, ContractTransaction, Overrides, - CallOverrides, + PopulatedTransaction, + Signer, + utils, } from "ethers"; -import { BytesLike } from "@ethersproject/bytes"; +import { FunctionFragment, Result, EventFragment } from "@ethersproject/abi"; import { Listener, Provider } from "@ethersproject/providers"; -import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from "./common"; - -export type TokenStruct = { - chainId: BigNumberish; - tokenAddress: string; - tokenDecimals: BigNumberish; - maxSwap: BigNumberish; - minSwap: BigNumberish; - swapFee: BigNumberish; - maxSwapFee: BigNumberish; - minSwapFee: BigNumberish; - hasUnderlying: boolean; - isUnderlying: boolean; -}; - -export type TokenStructOutput = [ - BigNumber, - string, - number, - BigNumber, - BigNumber, - BigNumber, - BigNumber, - BigNumber, - boolean, - boolean -] & { - chainId: BigNumber; - tokenAddress: string; - tokenDecimals: number; - maxSwap: BigNumber; - minSwap: BigNumber; - swapFee: BigNumber; - maxSwapFee: BigNumber; - minSwapFee: BigNumber; - hasUnderlying: boolean; - isUnderlying: boolean; -}; - -export interface BridgeConfigInterface extends ethers.utils.Interface { +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export declare namespace BridgeConfig { + export type TokenStruct = { + chainId: BigNumberish; + tokenAddress: string; + tokenDecimals: BigNumberish; + maxSwap: BigNumberish; + minSwap: BigNumberish; + swapFee: BigNumberish; + maxSwapFee: BigNumberish; + minSwapFee: BigNumberish; + hasUnderlying: boolean; + isUnderlying: boolean; + }; + + export type TokenStructOutput = [ + BigNumber, + string, + number, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + boolean, + boolean + ] & { + chainId: BigNumber; + tokenAddress: string; + tokenDecimals: number; + maxSwap: BigNumber; + minSwap: BigNumber; + swapFee: BigNumber; + maxSwapFee: BigNumber; + minSwapFee: BigNumber; + hasUnderlying: boolean; + isUnderlying: boolean; + }; +} + +export interface BridgeConfigInterface extends utils.Interface { + contractName: "BridgeConfig"; functions: { "BRIDGEMANAGER_ROLE()": FunctionFragment; "DEFAULT_ADMIN_ROLE()": FunctionFragment; @@ -251,6 +247,7 @@ export type RoleRevokedEvent = TypedEvent< export type RoleRevokedEventFilter = TypedEventFilter; export interface BridgeConfig extends BaseContract { + contractName: "BridgeConfig"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; @@ -333,7 +330,11 @@ export interface BridgeConfig extends BaseContract { tokenID: string, chainID: BigNumberish, overrides?: CallOverrides - ): Promise<[TokenStructOutput] & { token: TokenStructOutput }>; + ): Promise< + [BridgeConfig.TokenStructOutput] & { + token: BridgeConfig.TokenStructOutput; + } + >; /** * Returns token config struct, given an address and chainID @@ -344,7 +345,11 @@ export interface BridgeConfig extends BaseContract { tokenAddress: string, chainID: BigNumberish, overrides?: CallOverrides - ): Promise<[TokenStructOutput] & { token: TokenStructOutput }>; + ): Promise< + [BridgeConfig.TokenStructOutput] & { + token: BridgeConfig.TokenStructOutput; + } + >; /** * Returns the token ID (string) of the cross-chain token inputted @@ -364,7 +369,11 @@ export interface BridgeConfig extends BaseContract { getUnderlyingToken( tokenID: string, overrides?: CallOverrides - ): Promise<[TokenStructOutput] & { token: TokenStructOutput }>; + ): Promise< + [BridgeConfig.TokenStructOutput] & { + token: BridgeConfig.TokenStructOutput; + } + >; /** * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. @@ -503,7 +512,7 @@ export interface BridgeConfig extends BaseContract { tokenID: string, chainID: BigNumberish, overrides?: CallOverrides - ): Promise; + ): Promise; /** * Returns token config struct, given an address and chainID @@ -514,7 +523,7 @@ export interface BridgeConfig extends BaseContract { tokenAddress: string, chainID: BigNumberish, overrides?: CallOverrides - ): Promise; + ): Promise; /** * Returns the token ID (string) of the cross-chain token inputted @@ -534,7 +543,7 @@ export interface BridgeConfig extends BaseContract { getUnderlyingToken( tokenID: string, overrides?: CallOverrides - ): Promise; + ): Promise; /** * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. @@ -670,7 +679,7 @@ export interface BridgeConfig extends BaseContract { tokenID: string, chainID: BigNumberish, overrides?: CallOverrides - ): Promise; + ): Promise; /** * Returns token config struct, given an address and chainID @@ -681,7 +690,7 @@ export interface BridgeConfig extends BaseContract { tokenAddress: string, chainID: BigNumberish, overrides?: CallOverrides - ): Promise; + ): Promise; /** * Returns the token ID (string) of the cross-chain token inputted @@ -701,7 +710,7 @@ export interface BridgeConfig extends BaseContract { getUnderlyingToken( tokenID: string, overrides?: CallOverrides - ): Promise; + ): Promise; /** * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. diff --git a/src/contracts/gen/ERC20.ts b/src/contracts/gen/ERC20.ts index 53d153f4..486dfa27 100644 --- a/src/contracts/gen/ERC20.ts +++ b/src/contracts/gen/ERC20.ts @@ -1,30 +1,24 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ - import { - ethers, - EventFilter, - Signer, + BaseContract, BigNumber, BigNumberish, - PopulatedTransaction, - BaseContract, + BytesLike, + CallOverrides, ContractTransaction, Overrides, - CallOverrides, + PopulatedTransaction, + Signer, + utils, } from "ethers"; -import { BytesLike } from "@ethersproject/bytes"; +import { FunctionFragment, Result, EventFragment } from "@ethersproject/abi"; import { Listener, Provider } from "@ethersproject/providers"; -import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from "./common"; - -export interface ERC20Interface extends ethers.utils.Interface { +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export interface ERC20Interface extends utils.Interface { + contractName: "ERC20"; functions: { "name()": FunctionFragment; "approve(address,uint256)": FunctionFragment; @@ -102,6 +96,7 @@ export type TransferEvent = TypedEvent< export type TransferEventFilter = TypedEventFilter; export interface ERC20 extends BaseContract { + contractName: "ERC20"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; diff --git a/src/contracts/gen/L1BridgeZap.ts b/src/contracts/gen/L1BridgeZap.ts index d55736fb..057b844c 100644 --- a/src/contracts/gen/L1BridgeZap.ts +++ b/src/contracts/gen/L1BridgeZap.ts @@ -1,31 +1,25 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ - import { - ethers, - EventFilter, - Signer, + BaseContract, BigNumber, BigNumberish, - PopulatedTransaction, - BaseContract, + BytesLike, + CallOverrides, ContractTransaction, Overrides, PayableOverrides, - CallOverrides, + PopulatedTransaction, + Signer, + utils, } from "ethers"; -import { BytesLike } from "@ethersproject/bytes"; +import { FunctionFragment, Result } from "@ethersproject/abi"; import { Listener, Provider } from "@ethersproject/providers"; -import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from "./common"; - -export interface L1BridgeZapInterface extends ethers.utils.Interface { +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export interface L1BridgeZapInterface extends utils.Interface { + contractName: "L1BridgeZap"; functions: { "WETH_ADDRESS()": FunctionFragment; "baseTokens(uint256)": FunctionFragment; @@ -157,6 +151,7 @@ export interface L1BridgeZapInterface extends ethers.utils.Interface { } export interface L1BridgeZap extends BaseContract { + contractName: "L1BridgeZap"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; diff --git a/src/contracts/gen/L2BridgeZap.ts b/src/contracts/gen/L2BridgeZap.ts index 037bff45..89cc862c 100644 --- a/src/contracts/gen/L2BridgeZap.ts +++ b/src/contracts/gen/L2BridgeZap.ts @@ -1,31 +1,25 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ - import { - ethers, - EventFilter, - Signer, + BaseContract, BigNumber, BigNumberish, - PopulatedTransaction, - BaseContract, + BytesLike, + CallOverrides, ContractTransaction, Overrides, PayableOverrides, - CallOverrides, + PopulatedTransaction, + Signer, + utils, } from "ethers"; -import { BytesLike } from "@ethersproject/bytes"; +import { FunctionFragment, Result } from "@ethersproject/abi"; import { Listener, Provider } from "@ethersproject/providers"; -import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from "./common"; - -export interface L2BridgeZapInterface extends ethers.utils.Interface { +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export interface L2BridgeZapInterface extends utils.Interface { + contractName: "L2BridgeZap"; functions: { "WETH_ADDRESS()": FunctionFragment; "calculateSwap(address,uint8,uint8,uint256)": FunctionFragment; @@ -219,6 +213,7 @@ export interface L2BridgeZapInterface extends ethers.utils.Interface { } export interface L2BridgeZap extends BaseContract { + contractName: "L2BridgeZap"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; diff --git a/src/contracts/gen/PoolConfig.ts b/src/contracts/gen/PoolConfig.ts new file mode 100644 index 00000000..687fe6ca --- /dev/null +++ b/src/contracts/gen/PoolConfig.ts @@ -0,0 +1,625 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import { FunctionFragment, Result, EventFragment } from "@ethersproject/abi"; +import { Listener, Provider } from "@ethersproject/providers"; +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export declare namespace PoolConfig { + export type PoolStruct = { + tokenAddress: string; + chainId: BigNumberish; + poolAddress: string; + metaswap: boolean; + }; + + export type PoolStructOutput = [string, BigNumber, string, boolean] & { + tokenAddress: string; + chainId: BigNumber; + poolAddress: string; + metaswap: boolean; + }; +} + +export interface PoolConfigInterface extends utils.Interface { + contractName: "PoolConfig"; + functions: { + "BRIDGEMANAGER_ROLE()": FunctionFragment; + "DEFAULT_ADMIN_ROLE()": FunctionFragment; + "getPoolConfig(address,uint256)": FunctionFragment; + "getRoleAdmin(bytes32)": FunctionFragment; + "getRoleMember(bytes32,uint256)": FunctionFragment; + "getRoleMemberCount(bytes32)": FunctionFragment; + "grantRole(bytes32,address)": FunctionFragment; + "hasRole(bytes32,address)": FunctionFragment; + "renounceRole(bytes32,address)": FunctionFragment; + "revokeRole(bytes32,address)": FunctionFragment; + "setPoolConfig(address,uint256,address,bool)": FunctionFragment; + }; + + encodeFunctionData( + functionFragment: "BRIDGEMANAGER_ROLE", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "DEFAULT_ADMIN_ROLE", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getPoolConfig", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getRoleAdmin", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "getRoleMember", + values: [BytesLike, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getRoleMemberCount", + values: [BytesLike] + ): string; + encodeFunctionData( + functionFragment: "grantRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "hasRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "renounceRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "revokeRole", + values: [BytesLike, string] + ): string; + encodeFunctionData( + functionFragment: "setPoolConfig", + values: [string, BigNumberish, string, boolean] + ): string; + + decodeFunctionResult( + functionFragment: "BRIDGEMANAGER_ROLE", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "DEFAULT_ADMIN_ROLE", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getPoolConfig", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getRoleAdmin", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getRoleMember", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getRoleMemberCount", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "grantRole", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "hasRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "renounceRole", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "revokeRole", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "setPoolConfig", + data: BytesLike + ): Result; + + events: { + "RoleAdminChanged(bytes32,bytes32,bytes32)": EventFragment; + "RoleGranted(bytes32,address,address)": EventFragment; + "RoleRevoked(bytes32,address,address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "RoleAdminChanged"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleGranted"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RoleRevoked"): EventFragment; +} + +export type RoleAdminChangedEvent = TypedEvent< + [string, string, string], + { role: string; previousAdminRole: string; newAdminRole: string } +>; + +export type RoleAdminChangedEventFilter = + TypedEventFilter; + +export type RoleGrantedEvent = TypedEvent< + [string, string, string], + { role: string; account: string; sender: string } +>; + +export type RoleGrantedEventFilter = TypedEventFilter; + +export type RoleRevokedEvent = TypedEvent< + [string, string, string], + { role: string; account: string; sender: string } +>; + +export type RoleRevokedEventFilter = TypedEventFilter; + +export interface PoolConfig extends BaseContract { + contractName: "PoolConfig"; + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: PoolConfigInterface; + + 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: { + BRIDGEMANAGER_ROLE(overrides?: CallOverrides): Promise<[string]>; + + DEFAULT_ADMIN_ROLE(overrides?: CallOverrides): Promise<[string]>; + + getPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + overrides?: CallOverrides + ): Promise<[PoolConfig.PoolStructOutput]>; + + /** + * Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}. + */ + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise<[string]>; + + /** + * Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information. + */ + getRoleMember( + role: BytesLike, + index: BigNumberish, + overrides?: CallOverrides + ): Promise<[string]>; + + /** + * Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role. + */ + getRoleMemberCount( + role: BytesLike, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + /** + * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. + */ + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns `true` if `account` has been granted `role`. + */ + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise<[boolean]>; + + /** + * Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. + */ + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. + */ + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + poolAddress: string, + metaswap: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + BRIDGEMANAGER_ROLE(overrides?: CallOverrides): Promise; + + DEFAULT_ADMIN_ROLE(overrides?: CallOverrides): Promise; + + getPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}. + */ + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + /** + * Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information. + */ + getRoleMember( + role: BytesLike, + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role. + */ + getRoleMemberCount( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + /** + * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. + */ + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns `true` if `account` has been granted `role`. + */ + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + /** + * Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. + */ + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. + */ + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + poolAddress: string, + metaswap: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + callStatic: { + BRIDGEMANAGER_ROLE(overrides?: CallOverrides): Promise; + + DEFAULT_ADMIN_ROLE(overrides?: CallOverrides): Promise; + + getPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}. + */ + getRoleAdmin(role: BytesLike, overrides?: CallOverrides): Promise; + + /** + * Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information. + */ + getRoleMember( + role: BytesLike, + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role. + */ + getRoleMemberCount( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + /** + * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. + */ + grantRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + /** + * Returns `true` if `account` has been granted `role`. + */ + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + /** + * Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. + */ + renounceRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + /** + * Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. + */ + revokeRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + setPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + poolAddress: string, + metaswap: boolean, + overrides?: CallOverrides + ): Promise; + }; + + filters: { + "RoleAdminChanged(bytes32,bytes32,bytes32)"( + role?: BytesLike | null, + previousAdminRole?: BytesLike | null, + newAdminRole?: BytesLike | null + ): RoleAdminChangedEventFilter; + RoleAdminChanged( + role?: BytesLike | null, + previousAdminRole?: BytesLike | null, + newAdminRole?: BytesLike | null + ): RoleAdminChangedEventFilter; + + "RoleGranted(bytes32,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): RoleGrantedEventFilter; + RoleGranted( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): RoleGrantedEventFilter; + + "RoleRevoked(bytes32,address,address)"( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): RoleRevokedEventFilter; + RoleRevoked( + role?: BytesLike | null, + account?: string | null, + sender?: string | null + ): RoleRevokedEventFilter; + }; + + estimateGas: { + BRIDGEMANAGER_ROLE(overrides?: CallOverrides): Promise; + + DEFAULT_ADMIN_ROLE(overrides?: CallOverrides): Promise; + + getPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}. + */ + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + /** + * Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information. + */ + getRoleMember( + role: BytesLike, + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role. + */ + getRoleMemberCount( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + /** + * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. + */ + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns `true` if `account` has been granted `role`. + */ + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + /** + * Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. + */ + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. + */ + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + poolAddress: string, + metaswap: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + populateTransaction: { + BRIDGEMANAGER_ROLE( + overrides?: CallOverrides + ): Promise; + + DEFAULT_ADMIN_ROLE( + overrides?: CallOverrides + ): Promise; + + getPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the admin role that controls `role`. See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}. + */ + getRoleAdmin( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + /** + * Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive. Role bearers are not sorted in any particular way, and their ordering may change at any point. WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] for more information. + */ + getRoleMember( + role: BytesLike, + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role. + */ + getRoleMemberCount( + role: BytesLike, + overrides?: CallOverrides + ): Promise; + + /** + * Grants `role` to `account`. If `account` had not been already granted `role`, emits a {RoleGranted} event. Requirements: - the caller must have ``role``'s admin role. + */ + grantRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns `true` if `account` has been granted `role`. + */ + hasRole( + role: BytesLike, + account: string, + overrides?: CallOverrides + ): Promise; + + /** + * Revokes `role` from the calling account. Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced). If the calling account had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must be `account`. + */ + renounceRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Revokes `role` from `account`. If `account` had been granted `role`, emits a {RoleRevoked} event. Requirements: - the caller must have ``role``'s admin role. + */ + revokeRole( + role: BytesLike, + account: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + setPoolConfig( + tokenAddress: string, + chainID: BigNumberish, + poolAddress: string, + metaswap: boolean, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; +} diff --git a/src/contracts/gen/SwapFlashLoan.ts b/src/contracts/gen/SwapFlashLoan.ts new file mode 100644 index 00000000..39e89c43 --- /dev/null +++ b/src/contracts/gen/SwapFlashLoan.ts @@ -0,0 +1,2192 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PopulatedTransaction, + Signer, + utils, +} from "ethers"; +import { FunctionFragment, Result, EventFragment } from "@ethersproject/abi"; +import { Listener, Provider } from "@ethersproject/providers"; +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export interface SwapFlashLoanInterface extends utils.Interface { + contractName: "SwapFlashLoan"; + functions: { + "MAX_BPS()": FunctionFragment; + "addLiquidity(uint256[],uint256,uint256)": FunctionFragment; + "calculateRemoveLiquidity(uint256)": FunctionFragment; + "calculateRemoveLiquidityOneToken(uint256,uint8)": FunctionFragment; + "calculateSwap(uint8,uint8,uint256)": FunctionFragment; + "calculateTokenAmount(uint256[],bool)": FunctionFragment; + "flashLoan(address,address,uint256,bytes)": FunctionFragment; + "flashLoanFeeBPS()": FunctionFragment; + "getA()": FunctionFragment; + "getAPrecise()": FunctionFragment; + "getAdminBalance(uint256)": FunctionFragment; + "getToken(uint8)": FunctionFragment; + "getTokenBalance(uint8)": FunctionFragment; + "getTokenIndex(address)": FunctionFragment; + "getVirtualPrice()": FunctionFragment; + "initialize(address[],uint8[],string,string,uint256,uint256,uint256,address)": FunctionFragment; + "owner()": FunctionFragment; + "pause()": FunctionFragment; + "paused()": FunctionFragment; + "protocolFeeShareBPS()": FunctionFragment; + "rampA(uint256,uint256)": FunctionFragment; + "removeLiquidity(uint256,uint256[],uint256)": FunctionFragment; + "removeLiquidityImbalance(uint256[],uint256,uint256)": FunctionFragment; + "removeLiquidityOneToken(uint256,uint8,uint256,uint256)": FunctionFragment; + "renounceOwnership()": FunctionFragment; + "setAdminFee(uint256)": FunctionFragment; + "setFlashLoanFees(uint256,uint256)": FunctionFragment; + "setSwapFee(uint256)": FunctionFragment; + "stopRampA()": FunctionFragment; + "swap(uint8,uint8,uint256,uint256,uint256)": FunctionFragment; + "swapStorage()": FunctionFragment; + "transferOwnership(address)": FunctionFragment; + "unpause()": FunctionFragment; + "withdrawAdminFees()": FunctionFragment; + }; + + encodeFunctionData(functionFragment: "MAX_BPS", values?: undefined): string; + encodeFunctionData( + functionFragment: "addLiquidity", + values: [BigNumberish[], BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "calculateRemoveLiquidity", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "calculateRemoveLiquidityOneToken", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "calculateSwap", + values: [BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "calculateTokenAmount", + values: [BigNumberish[], boolean] + ): string; + encodeFunctionData( + functionFragment: "flashLoan", + values: [string, string, BigNumberish, BytesLike] + ): string; + encodeFunctionData( + functionFragment: "flashLoanFeeBPS", + values?: undefined + ): string; + encodeFunctionData(functionFragment: "getA", values?: undefined): string; + encodeFunctionData( + functionFragment: "getAPrecise", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "getAdminBalance", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getToken", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getTokenBalance", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "getTokenIndex", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "getVirtualPrice", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "initialize", + values: [ + string[], + BigNumberish[], + string, + string, + BigNumberish, + BigNumberish, + BigNumberish, + string + ] + ): string; + encodeFunctionData(functionFragment: "owner", values?: undefined): string; + encodeFunctionData(functionFragment: "pause", values?: undefined): string; + encodeFunctionData(functionFragment: "paused", values?: undefined): string; + encodeFunctionData( + functionFragment: "protocolFeeShareBPS", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "rampA", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "removeLiquidity", + values: [BigNumberish, BigNumberish[], BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "removeLiquidityImbalance", + values: [BigNumberish[], BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "removeLiquidityOneToken", + values: [BigNumberish, BigNumberish, BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "renounceOwnership", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "setAdminFee", + values: [BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setFlashLoanFees", + values: [BigNumberish, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "setSwapFee", + values: [BigNumberish] + ): string; + encodeFunctionData(functionFragment: "stopRampA", values?: undefined): string; + encodeFunctionData( + functionFragment: "swap", + values: [ + BigNumberish, + BigNumberish, + BigNumberish, + BigNumberish, + BigNumberish + ] + ): string; + encodeFunctionData( + functionFragment: "swapStorage", + values?: undefined + ): string; + encodeFunctionData( + functionFragment: "transferOwnership", + values: [string] + ): string; + encodeFunctionData(functionFragment: "unpause", values?: undefined): string; + encodeFunctionData( + functionFragment: "withdrawAdminFees", + values?: undefined + ): string; + + decodeFunctionResult(functionFragment: "MAX_BPS", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "addLiquidity", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "calculateRemoveLiquidity", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "calculateRemoveLiquidityOneToken", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "calculateSwap", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "calculateTokenAmount", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "flashLoan", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "flashLoanFeeBPS", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getA", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getAPrecise", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getAdminBalance", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "getToken", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "getTokenBalance", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getTokenIndex", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "getVirtualPrice", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "pause", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "paused", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "protocolFeeShareBPS", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "rampA", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "removeLiquidity", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "removeLiquidityImbalance", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "removeLiquidityOneToken", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "renounceOwnership", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setAdminFee", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "setFlashLoanFees", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "setSwapFee", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "stopRampA", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "swap", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "swapStorage", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "transferOwnership", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "unpause", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "withdrawAdminFees", + data: BytesLike + ): Result; + + events: { + "AddLiquidity(address,uint256[],uint256[],uint256,uint256)": EventFragment; + "FlashLoan(address,uint8,uint256,uint256,uint256)": EventFragment; + "NewAdminFee(uint256)": EventFragment; + "NewSwapFee(uint256)": EventFragment; + "OwnershipTransferred(address,address)": EventFragment; + "Paused(address)": EventFragment; + "RampA(uint256,uint256,uint256,uint256)": EventFragment; + "RemoveLiquidity(address,uint256[],uint256)": EventFragment; + "RemoveLiquidityImbalance(address,uint256[],uint256[],uint256,uint256)": EventFragment; + "RemoveLiquidityOne(address,uint256,uint256,uint256,uint256)": EventFragment; + "StopRampA(uint256,uint256)": EventFragment; + "TokenSwap(address,uint256,uint256,uint128,uint128)": EventFragment; + "Unpaused(address)": EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: "AddLiquidity"): EventFragment; + getEvent(nameOrSignatureOrTopic: "FlashLoan"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewAdminFee"): EventFragment; + getEvent(nameOrSignatureOrTopic: "NewSwapFee"): EventFragment; + getEvent(nameOrSignatureOrTopic: "OwnershipTransferred"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Paused"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RampA"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RemoveLiquidity"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RemoveLiquidityImbalance"): EventFragment; + getEvent(nameOrSignatureOrTopic: "RemoveLiquidityOne"): EventFragment; + getEvent(nameOrSignatureOrTopic: "StopRampA"): EventFragment; + getEvent(nameOrSignatureOrTopic: "TokenSwap"): EventFragment; + getEvent(nameOrSignatureOrTopic: "Unpaused"): EventFragment; +} + +export type AddLiquidityEvent = TypedEvent< + [string, BigNumber[], BigNumber[], BigNumber, BigNumber], + { + provider: string; + tokenAmounts: BigNumber[]; + fees: BigNumber[]; + invariant: BigNumber; + lpTokenSupply: BigNumber; + } +>; + +export type AddLiquidityEventFilter = TypedEventFilter; + +export type FlashLoanEvent = TypedEvent< + [string, number, BigNumber, BigNumber, BigNumber], + { + receiver: string; + tokenIndex: number; + amount: BigNumber; + amountFee: BigNumber; + protocolFee: BigNumber; + } +>; + +export type FlashLoanEventFilter = TypedEventFilter; + +export type NewAdminFeeEvent = TypedEvent< + [BigNumber], + { newAdminFee: BigNumber } +>; + +export type NewAdminFeeEventFilter = TypedEventFilter; + +export type NewSwapFeeEvent = TypedEvent< + [BigNumber], + { newSwapFee: BigNumber } +>; + +export type NewSwapFeeEventFilter = TypedEventFilter; + +export type OwnershipTransferredEvent = TypedEvent< + [string, string], + { previousOwner: string; newOwner: string } +>; + +export type OwnershipTransferredEventFilter = + TypedEventFilter; + +export type PausedEvent = TypedEvent<[string], { account: string }>; + +export type PausedEventFilter = TypedEventFilter; + +export type RampAEvent = TypedEvent< + [BigNumber, BigNumber, BigNumber, BigNumber], + { + oldA: BigNumber; + newA: BigNumber; + initialTime: BigNumber; + futureTime: BigNumber; + } +>; + +export type RampAEventFilter = TypedEventFilter; + +export type RemoveLiquidityEvent = TypedEvent< + [string, BigNumber[], BigNumber], + { provider: string; tokenAmounts: BigNumber[]; lpTokenSupply: BigNumber } +>; + +export type RemoveLiquidityEventFilter = TypedEventFilter; + +export type RemoveLiquidityImbalanceEvent = TypedEvent< + [string, BigNumber[], BigNumber[], BigNumber, BigNumber], + { + provider: string; + tokenAmounts: BigNumber[]; + fees: BigNumber[]; + invariant: BigNumber; + lpTokenSupply: BigNumber; + } +>; + +export type RemoveLiquidityImbalanceEventFilter = + TypedEventFilter; + +export type RemoveLiquidityOneEvent = TypedEvent< + [string, BigNumber, BigNumber, BigNumber, BigNumber], + { + provider: string; + lpTokenAmount: BigNumber; + lpTokenSupply: BigNumber; + boughtId: BigNumber; + tokensBought: BigNumber; + } +>; + +export type RemoveLiquidityOneEventFilter = + TypedEventFilter; + +export type StopRampAEvent = TypedEvent< + [BigNumber, BigNumber], + { currentA: BigNumber; time: BigNumber } +>; + +export type StopRampAEventFilter = TypedEventFilter; + +export type TokenSwapEvent = TypedEvent< + [string, BigNumber, BigNumber, BigNumber, BigNumber], + { + buyer: string; + tokensSold: BigNumber; + tokensBought: BigNumber; + soldId: BigNumber; + boughtId: BigNumber; + } +>; + +export type TokenSwapEventFilter = TypedEventFilter; + +export type UnpausedEvent = TypedEvent<[string], { account: string }>; + +export type UnpausedEventFilter = TypedEventFilter; + +export interface SwapFlashLoan extends BaseContract { + contractName: "SwapFlashLoan"; + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: SwapFlashLoanInterface; + + 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: { + MAX_BPS(overrides?: CallOverrides): Promise<[BigNumber]>; + + /** + * Add liquidity to the pool with the given amounts of tokens + * @param amounts the amounts of each token to add, in their native precision + * @param deadline latest timestamp to accept this transaction + * @param minToMint the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation + */ + addLiquidity( + amounts: BigNumberish[], + minToMint: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens + * @param amount the amount of LP tokens that would be burned on withdrawal + */ + calculateRemoveLiquidity( + amount: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber[]]>; + + /** + * Calculate the amount of underlying token available to withdraw when withdrawing via only single token + * @param tokenAmount the amount of LP token to burn + * @param tokenIndex index of which token will be withdrawn + */ + calculateRemoveLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber] & { availableTokenAmount: BigNumber }>; + + /** + * Calculate amount of tokens you receive on swap + * @param dx the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param tokenIndexFrom the token the user wants to sell + * @param tokenIndexTo the token the user wants to buy + */ + calculateSwap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + /** + * This shouldn't be used outside frontends for user estimates. + * A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running + * @param amounts an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param deposit whether this is a deposit or a withdrawal + */ + calculateTokenAmount( + amounts: BigNumberish[], + deposit: boolean, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + /** + * Borrow the specified token from this pool for this transaction only. This function will call `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token and the associated fee by the end of the callback transaction. If the conditions are not met, this call is reverted. + * @param amount the total amount to borrow in this transaction + * @param params optional data to pass along to the callback function + * @param receiver the address of the receiver of the token. This address must implement the IFlashLoanReceiver interface and the callback function `executeOperation`. + * @param token the protocol fee in bps to be applied on the total flash loan fee + */ + flashLoan( + receiver: string, + token: string, + amount: BigNumberish, + params: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashLoanFeeBPS(overrides?: CallOverrides): Promise<[BigNumber]>; + + /** + * See the StableSwap paper for details + * Return A, the amplification coefficient * n * (n - 1) + */ + getA(overrides?: CallOverrides): Promise<[BigNumber]>; + + /** + * See the StableSwap paper for details + * Return A in its raw precision form + */ + getAPrecise(overrides?: CallOverrides): Promise<[BigNumber]>; + + /** + * This function reads the accumulated amount of admin fees of the token with given index + * @param index Index of the pooled token + */ + getAdminBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + /** + * Return address of the pooled token at given index. Reverts if tokenIndex is out of range. + * @param index the index of the token + */ + getToken(index: BigNumberish, overrides?: CallOverrides): Promise<[string]>; + + /** + * Return current balance of the pooled token at given index + * @param index the index of the token + */ + getTokenBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber]>; + + /** + * Return the index of the given token address. Reverts if no matching token is found. + * @param tokenAddress address of the token + */ + getTokenIndex( + tokenAddress: string, + overrides?: CallOverrides + ): Promise<[number]>; + + /** + * Get the virtual price, to help calculate profit + */ + getVirtualPrice(overrides?: CallOverrides): Promise<[BigNumber]>; + + /** + * Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens. + * @param _a the amplification coefficient * n * (n - 1). See the StableSwap paper for details + * @param _adminFee default adminFee to be initialized with + * @param _fee default swap fee to be initialized with + * @param _pooledTokens an array of ERC20s this pool will accept + * @param decimals the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS + * @param lpTokenName the long-form name of the token to be deployed + * @param lpTokenSymbol the short symbol for the token to be deployed + * @param lpTokenTargetAddress the address of an existing LPToken contract to use as a target + */ + initialize( + _pooledTokens: string[], + decimals: BigNumberish[], + lpTokenName: string, + lpTokenSymbol: string, + _a: BigNumberish, + _fee: BigNumberish, + _adminFee: BigNumberish, + lpTokenTargetAddress: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns the address of the current owner. + */ + owner(overrides?: CallOverrides): Promise<[string]>; + + /** + * Pause the contract. Revert if already paused. + */ + pause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns true if the contract is paused, and false otherwise. + */ + paused(overrides?: CallOverrides): Promise<[boolean]>; + + protocolFeeShareBPS(overrides?: CallOverrides): Promise<[BigNumber]>; + + /** + * Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range. + * @param futureA the new A to ramp towards + * @param futureTime timestamp when the new A should be reached + */ + rampA( + futureA: BigNumberish, + futureTime: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Liquidity can always be removed, even when the pool is paused. + * Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amount the amount of LP tokens to burn + * @param deadline latest timestamp to accept this transaction + * @param minAmounts the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation + */ + removeLiquidity( + amount: BigNumberish, + minAmounts: BigNumberish[], + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amounts how much of each token to withdraw + * @param deadline latest timestamp to accept this transaction + * @param maxBurnAmount the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation. + */ + removeLiquidityImbalance( + amounts: BigNumberish[], + maxBurnAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param deadline latest timestamp to accept this transaction + * @param minAmount the minimum amount to withdraw, otherwise revert + * @param tokenAmount the amount of the token you want to receive + * @param tokenIndex the index of the token you want to receive + */ + removeLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + minAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner. + */ + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the admin fee. Admin fee takes portion of the swap fee. + * @param newAdminFee new admin fee to be applied on future transactions + */ + setAdminFee( + newAdminFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Updates the flash loan fee parameters. This function can only be called by the owner. + * @param newFlashLoanFeeBPS the total fee in bps to be applied on future flash loans + * @param newProtocolFeeShareBPS the protocol fee in bps to be applied on the total flash loan fee + */ + setFlashLoanFees( + newFlashLoanFeeBPS: BigNumberish, + newProtocolFeeShareBPS: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the swap fee to be applied on swaps + * @param newSwapFee new swap fee to be applied on future transactions + */ + setSwapFee( + newSwapFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Stop ramping A immediately. Reverts if ramp A is already stopped. + */ + stopRampA( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Swap two tokens using this pool + * @param deadline latest timestamp to accept this transaction + * @param dx the amount of tokens the user wants to swap from + * @param minDy the min amount the user would like to receive, or revert. + * @param tokenIndexFrom the token the user wants to swap from + * @param tokenIndexTo the token the user wants to swap to + */ + swap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + minDy: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + swapStorage( + overrides?: CallOverrides + ): Promise< + [ + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + string + ] & { + initialA: BigNumber; + futureA: BigNumber; + initialATime: BigNumber; + futureATime: BigNumber; + swapFee: BigNumber; + adminFee: BigNumber; + lpToken: string; + } + >; + + /** + * Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner. + */ + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Unpause the contract. Revert if already unpaused. + */ + unpause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Withdraw all admin fees to the contract owner + */ + withdrawAdminFees( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + MAX_BPS(overrides?: CallOverrides): Promise; + + /** + * Add liquidity to the pool with the given amounts of tokens + * @param amounts the amounts of each token to add, in their native precision + * @param deadline latest timestamp to accept this transaction + * @param minToMint the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation + */ + addLiquidity( + amounts: BigNumberish[], + minToMint: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens + * @param amount the amount of LP tokens that would be burned on withdrawal + */ + calculateRemoveLiquidity( + amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate the amount of underlying token available to withdraw when withdrawing via only single token + * @param tokenAmount the amount of LP token to burn + * @param tokenIndex index of which token will be withdrawn + */ + calculateRemoveLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate amount of tokens you receive on swap + * @param dx the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param tokenIndexFrom the token the user wants to sell + * @param tokenIndexTo the token the user wants to buy + */ + calculateSwap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * This shouldn't be used outside frontends for user estimates. + * A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running + * @param amounts an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param deposit whether this is a deposit or a withdrawal + */ + calculateTokenAmount( + amounts: BigNumberish[], + deposit: boolean, + overrides?: CallOverrides + ): Promise; + + /** + * Borrow the specified token from this pool for this transaction only. This function will call `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token and the associated fee by the end of the callback transaction. If the conditions are not met, this call is reverted. + * @param amount the total amount to borrow in this transaction + * @param params optional data to pass along to the callback function + * @param receiver the address of the receiver of the token. This address must implement the IFlashLoanReceiver interface and the callback function `executeOperation`. + * @param token the protocol fee in bps to be applied on the total flash loan fee + */ + flashLoan( + receiver: string, + token: string, + amount: BigNumberish, + params: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashLoanFeeBPS(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A, the amplification coefficient * n * (n - 1) + */ + getA(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A in its raw precision form + */ + getAPrecise(overrides?: CallOverrides): Promise; + + /** + * This function reads the accumulated amount of admin fees of the token with given index + * @param index Index of the pooled token + */ + getAdminBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return address of the pooled token at given index. Reverts if tokenIndex is out of range. + * @param index the index of the token + */ + getToken(index: BigNumberish, overrides?: CallOverrides): Promise; + + /** + * Return current balance of the pooled token at given index + * @param index the index of the token + */ + getTokenBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return the index of the given token address. Reverts if no matching token is found. + * @param tokenAddress address of the token + */ + getTokenIndex( + tokenAddress: string, + overrides?: CallOverrides + ): Promise; + + /** + * Get the virtual price, to help calculate profit + */ + getVirtualPrice(overrides?: CallOverrides): Promise; + + /** + * Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens. + * @param _a the amplification coefficient * n * (n - 1). See the StableSwap paper for details + * @param _adminFee default adminFee to be initialized with + * @param _fee default swap fee to be initialized with + * @param _pooledTokens an array of ERC20s this pool will accept + * @param decimals the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS + * @param lpTokenName the long-form name of the token to be deployed + * @param lpTokenSymbol the short symbol for the token to be deployed + * @param lpTokenTargetAddress the address of an existing LPToken contract to use as a target + */ + initialize( + _pooledTokens: string[], + decimals: BigNumberish[], + lpTokenName: string, + lpTokenSymbol: string, + _a: BigNumberish, + _fee: BigNumberish, + _adminFee: BigNumberish, + lpTokenTargetAddress: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns the address of the current owner. + */ + owner(overrides?: CallOverrides): Promise; + + /** + * Pause the contract. Revert if already paused. + */ + pause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns true if the contract is paused, and false otherwise. + */ + paused(overrides?: CallOverrides): Promise; + + protocolFeeShareBPS(overrides?: CallOverrides): Promise; + + /** + * Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range. + * @param futureA the new A to ramp towards + * @param futureTime timestamp when the new A should be reached + */ + rampA( + futureA: BigNumberish, + futureTime: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Liquidity can always be removed, even when the pool is paused. + * Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amount the amount of LP tokens to burn + * @param deadline latest timestamp to accept this transaction + * @param minAmounts the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation + */ + removeLiquidity( + amount: BigNumberish, + minAmounts: BigNumberish[], + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amounts how much of each token to withdraw + * @param deadline latest timestamp to accept this transaction + * @param maxBurnAmount the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation. + */ + removeLiquidityImbalance( + amounts: BigNumberish[], + maxBurnAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param deadline latest timestamp to accept this transaction + * @param minAmount the minimum amount to withdraw, otherwise revert + * @param tokenAmount the amount of the token you want to receive + * @param tokenIndex the index of the token you want to receive + */ + removeLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + minAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner. + */ + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the admin fee. Admin fee takes portion of the swap fee. + * @param newAdminFee new admin fee to be applied on future transactions + */ + setAdminFee( + newAdminFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Updates the flash loan fee parameters. This function can only be called by the owner. + * @param newFlashLoanFeeBPS the total fee in bps to be applied on future flash loans + * @param newProtocolFeeShareBPS the protocol fee in bps to be applied on the total flash loan fee + */ + setFlashLoanFees( + newFlashLoanFeeBPS: BigNumberish, + newProtocolFeeShareBPS: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the swap fee to be applied on swaps + * @param newSwapFee new swap fee to be applied on future transactions + */ + setSwapFee( + newSwapFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Stop ramping A immediately. Reverts if ramp A is already stopped. + */ + stopRampA( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Swap two tokens using this pool + * @param deadline latest timestamp to accept this transaction + * @param dx the amount of tokens the user wants to swap from + * @param minDy the min amount the user would like to receive, or revert. + * @param tokenIndexFrom the token the user wants to swap from + * @param tokenIndexTo the token the user wants to swap to + */ + swap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + minDy: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + swapStorage( + overrides?: CallOverrides + ): Promise< + [ + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + string + ] & { + initialA: BigNumber; + futureA: BigNumber; + initialATime: BigNumber; + futureATime: BigNumber; + swapFee: BigNumber; + adminFee: BigNumber; + lpToken: string; + } + >; + + /** + * Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner. + */ + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Unpause the contract. Revert if already unpaused. + */ + unpause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Withdraw all admin fees to the contract owner + */ + withdrawAdminFees( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + callStatic: { + MAX_BPS(overrides?: CallOverrides): Promise; + + /** + * Add liquidity to the pool with the given amounts of tokens + * @param amounts the amounts of each token to add, in their native precision + * @param deadline latest timestamp to accept this transaction + * @param minToMint the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation + */ + addLiquidity( + amounts: BigNumberish[], + minToMint: BigNumberish, + deadline: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens + * @param amount the amount of LP tokens that would be burned on withdrawal + */ + calculateRemoveLiquidity( + amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate the amount of underlying token available to withdraw when withdrawing via only single token + * @param tokenAmount the amount of LP token to burn + * @param tokenIndex index of which token will be withdrawn + */ + calculateRemoveLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate amount of tokens you receive on swap + * @param dx the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param tokenIndexFrom the token the user wants to sell + * @param tokenIndexTo the token the user wants to buy + */ + calculateSwap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * This shouldn't be used outside frontends for user estimates. + * A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running + * @param amounts an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param deposit whether this is a deposit or a withdrawal + */ + calculateTokenAmount( + amounts: BigNumberish[], + deposit: boolean, + overrides?: CallOverrides + ): Promise; + + /** + * Borrow the specified token from this pool for this transaction only. This function will call `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token and the associated fee by the end of the callback transaction. If the conditions are not met, this call is reverted. + * @param amount the total amount to borrow in this transaction + * @param params optional data to pass along to the callback function + * @param receiver the address of the receiver of the token. This address must implement the IFlashLoanReceiver interface and the callback function `executeOperation`. + * @param token the protocol fee in bps to be applied on the total flash loan fee + */ + flashLoan( + receiver: string, + token: string, + amount: BigNumberish, + params: BytesLike, + overrides?: CallOverrides + ): Promise; + + flashLoanFeeBPS(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A, the amplification coefficient * n * (n - 1) + */ + getA(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A in its raw precision form + */ + getAPrecise(overrides?: CallOverrides): Promise; + + /** + * This function reads the accumulated amount of admin fees of the token with given index + * @param index Index of the pooled token + */ + getAdminBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return address of the pooled token at given index. Reverts if tokenIndex is out of range. + * @param index the index of the token + */ + getToken(index: BigNumberish, overrides?: CallOverrides): Promise; + + /** + * Return current balance of the pooled token at given index + * @param index the index of the token + */ + getTokenBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return the index of the given token address. Reverts if no matching token is found. + * @param tokenAddress address of the token + */ + getTokenIndex( + tokenAddress: string, + overrides?: CallOverrides + ): Promise; + + /** + * Get the virtual price, to help calculate profit + */ + getVirtualPrice(overrides?: CallOverrides): Promise; + + /** + * Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens. + * @param _a the amplification coefficient * n * (n - 1). See the StableSwap paper for details + * @param _adminFee default adminFee to be initialized with + * @param _fee default swap fee to be initialized with + * @param _pooledTokens an array of ERC20s this pool will accept + * @param decimals the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS + * @param lpTokenName the long-form name of the token to be deployed + * @param lpTokenSymbol the short symbol for the token to be deployed + * @param lpTokenTargetAddress the address of an existing LPToken contract to use as a target + */ + initialize( + _pooledTokens: string[], + decimals: BigNumberish[], + lpTokenName: string, + lpTokenSymbol: string, + _a: BigNumberish, + _fee: BigNumberish, + _adminFee: BigNumberish, + lpTokenTargetAddress: string, + overrides?: CallOverrides + ): Promise; + + /** + * Returns the address of the current owner. + */ + owner(overrides?: CallOverrides): Promise; + + /** + * Pause the contract. Revert if already paused. + */ + pause(overrides?: CallOverrides): Promise; + + /** + * Returns true if the contract is paused, and false otherwise. + */ + paused(overrides?: CallOverrides): Promise; + + protocolFeeShareBPS(overrides?: CallOverrides): Promise; + + /** + * Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range. + * @param futureA the new A to ramp towards + * @param futureTime timestamp when the new A should be reached + */ + rampA( + futureA: BigNumberish, + futureTime: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Liquidity can always be removed, even when the pool is paused. + * Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amount the amount of LP tokens to burn + * @param deadline latest timestamp to accept this transaction + * @param minAmounts the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation + */ + removeLiquidity( + amount: BigNumberish, + minAmounts: BigNumberish[], + deadline: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amounts how much of each token to withdraw + * @param deadline latest timestamp to accept this transaction + * @param maxBurnAmount the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation. + */ + removeLiquidityImbalance( + amounts: BigNumberish[], + maxBurnAmount: BigNumberish, + deadline: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param deadline latest timestamp to accept this transaction + * @param minAmount the minimum amount to withdraw, otherwise revert + * @param tokenAmount the amount of the token you want to receive + * @param tokenIndex the index of the token you want to receive + */ + removeLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + minAmount: BigNumberish, + deadline: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner. + */ + renounceOwnership(overrides?: CallOverrides): Promise; + + /** + * Update the admin fee. Admin fee takes portion of the swap fee. + * @param newAdminFee new admin fee to be applied on future transactions + */ + setAdminFee( + newAdminFee: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Updates the flash loan fee parameters. This function can only be called by the owner. + * @param newFlashLoanFeeBPS the total fee in bps to be applied on future flash loans + * @param newProtocolFeeShareBPS the protocol fee in bps to be applied on the total flash loan fee + */ + setFlashLoanFees( + newFlashLoanFeeBPS: BigNumberish, + newProtocolFeeShareBPS: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Update the swap fee to be applied on swaps + * @param newSwapFee new swap fee to be applied on future transactions + */ + setSwapFee( + newSwapFee: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Stop ramping A immediately. Reverts if ramp A is already stopped. + */ + stopRampA(overrides?: CallOverrides): Promise; + + /** + * Swap two tokens using this pool + * @param deadline latest timestamp to accept this transaction + * @param dx the amount of tokens the user wants to swap from + * @param minDy the min amount the user would like to receive, or revert. + * @param tokenIndexFrom the token the user wants to swap from + * @param tokenIndexTo the token the user wants to swap to + */ + swap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + minDy: BigNumberish, + deadline: BigNumberish, + overrides?: CallOverrides + ): Promise; + + swapStorage( + overrides?: CallOverrides + ): Promise< + [ + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + string + ] & { + initialA: BigNumber; + futureA: BigNumber; + initialATime: BigNumber; + futureATime: BigNumber; + swapFee: BigNumber; + adminFee: BigNumber; + lpToken: string; + } + >; + + /** + * Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner. + */ + transferOwnership( + newOwner: string, + overrides?: CallOverrides + ): Promise; + + /** + * Unpause the contract. Revert if already unpaused. + */ + unpause(overrides?: CallOverrides): Promise; + + /** + * Withdraw all admin fees to the contract owner + */ + withdrawAdminFees(overrides?: CallOverrides): Promise; + }; + + filters: { + "AddLiquidity(address,uint256[],uint256[],uint256,uint256)"( + provider?: string | null, + tokenAmounts?: null, + fees?: null, + invariant?: null, + lpTokenSupply?: null + ): AddLiquidityEventFilter; + AddLiquidity( + provider?: string | null, + tokenAmounts?: null, + fees?: null, + invariant?: null, + lpTokenSupply?: null + ): AddLiquidityEventFilter; + + "FlashLoan(address,uint8,uint256,uint256,uint256)"( + receiver?: string | null, + tokenIndex?: null, + amount?: null, + amountFee?: null, + protocolFee?: null + ): FlashLoanEventFilter; + FlashLoan( + receiver?: string | null, + tokenIndex?: null, + amount?: null, + amountFee?: null, + protocolFee?: null + ): FlashLoanEventFilter; + + "NewAdminFee(uint256)"(newAdminFee?: null): NewAdminFeeEventFilter; + NewAdminFee(newAdminFee?: null): NewAdminFeeEventFilter; + + "NewSwapFee(uint256)"(newSwapFee?: null): NewSwapFeeEventFilter; + NewSwapFee(newSwapFee?: null): NewSwapFeeEventFilter; + + "OwnershipTransferred(address,address)"( + previousOwner?: string | null, + newOwner?: string | null + ): OwnershipTransferredEventFilter; + OwnershipTransferred( + previousOwner?: string | null, + newOwner?: string | null + ): OwnershipTransferredEventFilter; + + "Paused(address)"(account?: null): PausedEventFilter; + Paused(account?: null): PausedEventFilter; + + "RampA(uint256,uint256,uint256,uint256)"( + oldA?: null, + newA?: null, + initialTime?: null, + futureTime?: null + ): RampAEventFilter; + RampA( + oldA?: null, + newA?: null, + initialTime?: null, + futureTime?: null + ): RampAEventFilter; + + "RemoveLiquidity(address,uint256[],uint256)"( + provider?: string | null, + tokenAmounts?: null, + lpTokenSupply?: null + ): RemoveLiquidityEventFilter; + RemoveLiquidity( + provider?: string | null, + tokenAmounts?: null, + lpTokenSupply?: null + ): RemoveLiquidityEventFilter; + + "RemoveLiquidityImbalance(address,uint256[],uint256[],uint256,uint256)"( + provider?: string | null, + tokenAmounts?: null, + fees?: null, + invariant?: null, + lpTokenSupply?: null + ): RemoveLiquidityImbalanceEventFilter; + RemoveLiquidityImbalance( + provider?: string | null, + tokenAmounts?: null, + fees?: null, + invariant?: null, + lpTokenSupply?: null + ): RemoveLiquidityImbalanceEventFilter; + + "RemoveLiquidityOne(address,uint256,uint256,uint256,uint256)"( + provider?: string | null, + lpTokenAmount?: null, + lpTokenSupply?: null, + boughtId?: null, + tokensBought?: null + ): RemoveLiquidityOneEventFilter; + RemoveLiquidityOne( + provider?: string | null, + lpTokenAmount?: null, + lpTokenSupply?: null, + boughtId?: null, + tokensBought?: null + ): RemoveLiquidityOneEventFilter; + + "StopRampA(uint256,uint256)"( + currentA?: null, + time?: null + ): StopRampAEventFilter; + StopRampA(currentA?: null, time?: null): StopRampAEventFilter; + + "TokenSwap(address,uint256,uint256,uint128,uint128)"( + buyer?: string | null, + tokensSold?: null, + tokensBought?: null, + soldId?: null, + boughtId?: null + ): TokenSwapEventFilter; + TokenSwap( + buyer?: string | null, + tokensSold?: null, + tokensBought?: null, + soldId?: null, + boughtId?: null + ): TokenSwapEventFilter; + + "Unpaused(address)"(account?: null): UnpausedEventFilter; + Unpaused(account?: null): UnpausedEventFilter; + }; + + estimateGas: { + MAX_BPS(overrides?: CallOverrides): Promise; + + /** + * Add liquidity to the pool with the given amounts of tokens + * @param amounts the amounts of each token to add, in their native precision + * @param deadline latest timestamp to accept this transaction + * @param minToMint the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation + */ + addLiquidity( + amounts: BigNumberish[], + minToMint: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens + * @param amount the amount of LP tokens that would be burned on withdrawal + */ + calculateRemoveLiquidity( + amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate the amount of underlying token available to withdraw when withdrawing via only single token + * @param tokenAmount the amount of LP token to burn + * @param tokenIndex index of which token will be withdrawn + */ + calculateRemoveLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate amount of tokens you receive on swap + * @param dx the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param tokenIndexFrom the token the user wants to sell + * @param tokenIndexTo the token the user wants to buy + */ + calculateSwap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * This shouldn't be used outside frontends for user estimates. + * A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running + * @param amounts an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param deposit whether this is a deposit or a withdrawal + */ + calculateTokenAmount( + amounts: BigNumberish[], + deposit: boolean, + overrides?: CallOverrides + ): Promise; + + /** + * Borrow the specified token from this pool for this transaction only. This function will call `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token and the associated fee by the end of the callback transaction. If the conditions are not met, this call is reverted. + * @param amount the total amount to borrow in this transaction + * @param params optional data to pass along to the callback function + * @param receiver the address of the receiver of the token. This address must implement the IFlashLoanReceiver interface and the callback function `executeOperation`. + * @param token the protocol fee in bps to be applied on the total flash loan fee + */ + flashLoan( + receiver: string, + token: string, + amount: BigNumberish, + params: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashLoanFeeBPS(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A, the amplification coefficient * n * (n - 1) + */ + getA(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A in its raw precision form + */ + getAPrecise(overrides?: CallOverrides): Promise; + + /** + * This function reads the accumulated amount of admin fees of the token with given index + * @param index Index of the pooled token + */ + getAdminBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return address of the pooled token at given index. Reverts if tokenIndex is out of range. + * @param index the index of the token + */ + getToken( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return current balance of the pooled token at given index + * @param index the index of the token + */ + getTokenBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return the index of the given token address. Reverts if no matching token is found. + * @param tokenAddress address of the token + */ + getTokenIndex( + tokenAddress: string, + overrides?: CallOverrides + ): Promise; + + /** + * Get the virtual price, to help calculate profit + */ + getVirtualPrice(overrides?: CallOverrides): Promise; + + /** + * Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens. + * @param _a the amplification coefficient * n * (n - 1). See the StableSwap paper for details + * @param _adminFee default adminFee to be initialized with + * @param _fee default swap fee to be initialized with + * @param _pooledTokens an array of ERC20s this pool will accept + * @param decimals the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS + * @param lpTokenName the long-form name of the token to be deployed + * @param lpTokenSymbol the short symbol for the token to be deployed + * @param lpTokenTargetAddress the address of an existing LPToken contract to use as a target + */ + initialize( + _pooledTokens: string[], + decimals: BigNumberish[], + lpTokenName: string, + lpTokenSymbol: string, + _a: BigNumberish, + _fee: BigNumberish, + _adminFee: BigNumberish, + lpTokenTargetAddress: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns the address of the current owner. + */ + owner(overrides?: CallOverrides): Promise; + + /** + * Pause the contract. Revert if already paused. + */ + pause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns true if the contract is paused, and false otherwise. + */ + paused(overrides?: CallOverrides): Promise; + + protocolFeeShareBPS(overrides?: CallOverrides): Promise; + + /** + * Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range. + * @param futureA the new A to ramp towards + * @param futureTime timestamp when the new A should be reached + */ + rampA( + futureA: BigNumberish, + futureTime: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Liquidity can always be removed, even when the pool is paused. + * Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amount the amount of LP tokens to burn + * @param deadline latest timestamp to accept this transaction + * @param minAmounts the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation + */ + removeLiquidity( + amount: BigNumberish, + minAmounts: BigNumberish[], + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amounts how much of each token to withdraw + * @param deadline latest timestamp to accept this transaction + * @param maxBurnAmount the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation. + */ + removeLiquidityImbalance( + amounts: BigNumberish[], + maxBurnAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param deadline latest timestamp to accept this transaction + * @param minAmount the minimum amount to withdraw, otherwise revert + * @param tokenAmount the amount of the token you want to receive + * @param tokenIndex the index of the token you want to receive + */ + removeLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + minAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner. + */ + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the admin fee. Admin fee takes portion of the swap fee. + * @param newAdminFee new admin fee to be applied on future transactions + */ + setAdminFee( + newAdminFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Updates the flash loan fee parameters. This function can only be called by the owner. + * @param newFlashLoanFeeBPS the total fee in bps to be applied on future flash loans + * @param newProtocolFeeShareBPS the protocol fee in bps to be applied on the total flash loan fee + */ + setFlashLoanFees( + newFlashLoanFeeBPS: BigNumberish, + newProtocolFeeShareBPS: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the swap fee to be applied on swaps + * @param newSwapFee new swap fee to be applied on future transactions + */ + setSwapFee( + newSwapFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Stop ramping A immediately. Reverts if ramp A is already stopped. + */ + stopRampA( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Swap two tokens using this pool + * @param deadline latest timestamp to accept this transaction + * @param dx the amount of tokens the user wants to swap from + * @param minDy the min amount the user would like to receive, or revert. + * @param tokenIndexFrom the token the user wants to swap from + * @param tokenIndexTo the token the user wants to swap to + */ + swap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + minDy: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + swapStorage(overrides?: CallOverrides): Promise; + + /** + * Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner. + */ + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Unpause the contract. Revert if already unpaused. + */ + unpause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Withdraw all admin fees to the contract owner + */ + withdrawAdminFees( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; + + populateTransaction: { + MAX_BPS(overrides?: CallOverrides): Promise; + + /** + * Add liquidity to the pool with the given amounts of tokens + * @param amounts the amounts of each token to add, in their native precision + * @param deadline latest timestamp to accept this transaction + * @param minToMint the minimum LP tokens adding this amount of liquidity should mint, otherwise revert. Handy for front-running mitigation + */ + addLiquidity( + amounts: BigNumberish[], + minToMint: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * A simple method to calculate amount of each underlying tokens that is returned upon burning given amount of LP tokens + * @param amount the amount of LP tokens that would be burned on withdrawal + */ + calculateRemoveLiquidity( + amount: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate the amount of underlying token available to withdraw when withdrawing via only single token + * @param tokenAmount the amount of LP token to burn + * @param tokenIndex index of which token will be withdrawn + */ + calculateRemoveLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Calculate amount of tokens you receive on swap + * @param dx the amount of tokens the user wants to sell. If the token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param tokenIndexFrom the token the user wants to sell + * @param tokenIndexTo the token the user wants to buy + */ + calculateSwap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * This shouldn't be used outside frontends for user estimates. + * A simple method to calculate prices from deposits or withdrawals, excluding fees but including slippage. This is helpful as an input into the various "min" parameters on calls to fight front-running + * @param amounts an array of token amounts to deposit or withdrawal, corresponding to pooledTokens. The amount should be in each pooled token's native precision. If a token charges a fee on transfers, use the amount that gets transferred after the fee. + * @param deposit whether this is a deposit or a withdrawal + */ + calculateTokenAmount( + amounts: BigNumberish[], + deposit: boolean, + overrides?: CallOverrides + ): Promise; + + /** + * Borrow the specified token from this pool for this transaction only. This function will call `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token and the associated fee by the end of the callback transaction. If the conditions are not met, this call is reverted. + * @param amount the total amount to borrow in this transaction + * @param params optional data to pass along to the callback function + * @param receiver the address of the receiver of the token. This address must implement the IFlashLoanReceiver interface and the callback function `executeOperation`. + * @param token the protocol fee in bps to be applied on the total flash loan fee + */ + flashLoan( + receiver: string, + token: string, + amount: BigNumberish, + params: BytesLike, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + flashLoanFeeBPS(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A, the amplification coefficient * n * (n - 1) + */ + getA(overrides?: CallOverrides): Promise; + + /** + * See the StableSwap paper for details + * Return A in its raw precision form + */ + getAPrecise(overrides?: CallOverrides): Promise; + + /** + * This function reads the accumulated amount of admin fees of the token with given index + * @param index Index of the pooled token + */ + getAdminBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return address of the pooled token at given index. Reverts if tokenIndex is out of range. + * @param index the index of the token + */ + getToken( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return current balance of the pooled token at given index + * @param index the index of the token + */ + getTokenBalance( + index: BigNumberish, + overrides?: CallOverrides + ): Promise; + + /** + * Return the index of the given token address. Reverts if no matching token is found. + * @param tokenAddress address of the token + */ + getTokenIndex( + tokenAddress: string, + overrides?: CallOverrides + ): Promise; + + /** + * Get the virtual price, to help calculate profit + */ + getVirtualPrice(overrides?: CallOverrides): Promise; + + /** + * Initializes this Swap contract with the given parameters. This will also clone a LPToken contract that represents users' LP positions. The owner of LPToken will be this contract - which means only this contract is allowed to mint/burn tokens. + * @param _a the amplification coefficient * n * (n - 1). See the StableSwap paper for details + * @param _adminFee default adminFee to be initialized with + * @param _fee default swap fee to be initialized with + * @param _pooledTokens an array of ERC20s this pool will accept + * @param decimals the decimals to use for each pooled token, eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS + * @param lpTokenName the long-form name of the token to be deployed + * @param lpTokenSymbol the short symbol for the token to be deployed + * @param lpTokenTargetAddress the address of an existing LPToken contract to use as a target + */ + initialize( + _pooledTokens: string[], + decimals: BigNumberish[], + lpTokenName: string, + lpTokenSymbol: string, + _a: BigNumberish, + _fee: BigNumberish, + _adminFee: BigNumberish, + lpTokenTargetAddress: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns the address of the current owner. + */ + owner(overrides?: CallOverrides): Promise; + + /** + * Pause the contract. Revert if already paused. + */ + pause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Returns true if the contract is paused, and false otherwise. + */ + paused(overrides?: CallOverrides): Promise; + + protocolFeeShareBPS( + overrides?: CallOverrides + ): Promise; + + /** + * Start ramping up or down A parameter towards given futureA and futureTime Checks if the change is too rapid, and commits the new A value only when it falls under the limit range. + * @param futureA the new A to ramp towards + * @param futureTime timestamp when the new A should be reached + */ + rampA( + futureA: BigNumberish, + futureTime: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Liquidity can always be removed, even when the pool is paused. + * Burn LP tokens to remove liquidity from the pool. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amount the amount of LP tokens to burn + * @param deadline latest timestamp to accept this transaction + * @param minAmounts the minimum amounts of each token in the pool acceptable for this burn. Useful as a front-running mitigation + */ + removeLiquidity( + amount: BigNumberish, + minAmounts: BigNumberish[], + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool, weighted differently than the pool's current balances. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param amounts how much of each token to withdraw + * @param deadline latest timestamp to accept this transaction + * @param maxBurnAmount the max LP token provider is willing to pay to remove liquidity. Useful as a front-running mitigation. + */ + removeLiquidityImbalance( + amounts: BigNumberish[], + maxBurnAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Remove liquidity from the pool all in one token. Withdraw fee that decays linearly over period of 4 weeks since last deposit will apply. + * @param deadline latest timestamp to accept this transaction + * @param minAmount the minimum amount to withdraw, otherwise revert + * @param tokenAmount the amount of the token you want to receive + * @param tokenIndex the index of the token you want to receive + */ + removeLiquidityOneToken( + tokenAmount: BigNumberish, + tokenIndex: BigNumberish, + minAmount: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner. + */ + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the admin fee. Admin fee takes portion of the swap fee. + * @param newAdminFee new admin fee to be applied on future transactions + */ + setAdminFee( + newAdminFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Updates the flash loan fee parameters. This function can only be called by the owner. + * @param newFlashLoanFeeBPS the total fee in bps to be applied on future flash loans + * @param newProtocolFeeShareBPS the protocol fee in bps to be applied on the total flash loan fee + */ + setFlashLoanFees( + newFlashLoanFeeBPS: BigNumberish, + newProtocolFeeShareBPS: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Update the swap fee to be applied on swaps + * @param newSwapFee new swap fee to be applied on future transactions + */ + setSwapFee( + newSwapFee: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Stop ramping A immediately. Reverts if ramp A is already stopped. + */ + stopRampA( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Swap two tokens using this pool + * @param deadline latest timestamp to accept this transaction + * @param dx the amount of tokens the user wants to swap from + * @param minDy the min amount the user would like to receive, or revert. + * @param tokenIndexFrom the token the user wants to swap from + * @param tokenIndexTo the token the user wants to swap to + */ + swap( + tokenIndexFrom: BigNumberish, + tokenIndexTo: BigNumberish, + dx: BigNumberish, + minDy: BigNumberish, + deadline: BigNumberish, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + swapStorage(overrides?: CallOverrides): Promise; + + /** + * Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner. + */ + transferOwnership( + newOwner: string, + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Unpause the contract. Revert if already unpaused. + */ + unpause( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + + /** + * Withdraw all admin fees to the contract owner + */ + withdrawAdminFees( + overrides?: Overrides & { from?: string | Promise } + ): Promise; + }; +} diff --git a/src/contracts/gen/SynapseBridge.ts b/src/contracts/gen/SynapseBridge.ts index b6bb79ce..78b9632f 100644 --- a/src/contracts/gen/SynapseBridge.ts +++ b/src/contracts/gen/SynapseBridge.ts @@ -1,30 +1,24 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ - import { - ethers, - EventFilter, - Signer, + BaseContract, BigNumber, BigNumberish, - PopulatedTransaction, - BaseContract, + BytesLike, + CallOverrides, ContractTransaction, Overrides, - CallOverrides, + PopulatedTransaction, + Signer, + utils, } from "ethers"; -import { BytesLike } from "@ethersproject/bytes"; +import { FunctionFragment, Result, EventFragment } from "@ethersproject/abi"; import { Listener, Provider } from "@ethersproject/providers"; -import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from "./common"; - -export interface SynapseBridgeInterface extends ethers.utils.Interface { +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export interface SynapseBridgeInterface extends utils.Interface { + contractName: "SynapseBridge"; functions: { "DEFAULT_ADMIN_ROLE()": FunctionFragment; "GOVERNANCE_ROLE()": FunctionFragment; @@ -541,6 +535,7 @@ export type UnpausedEvent = TypedEvent<[string], { account: string }>; export type UnpausedEventFilter = TypedEventFilter; export interface SynapseBridge extends BaseContract { + contractName: "SynapseBridge"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; diff --git a/src/contracts/gen/SynapseERC20.ts b/src/contracts/gen/SynapseERC20.ts index 2471c308..2cbbe65b 100644 --- a/src/contracts/gen/SynapseERC20.ts +++ b/src/contracts/gen/SynapseERC20.ts @@ -1,30 +1,24 @@ /* Autogenerated file. Do not edit manually. */ /* tslint:disable */ /* eslint-disable */ - import { - ethers, - EventFilter, - Signer, + BaseContract, BigNumber, BigNumberish, - PopulatedTransaction, - BaseContract, + BytesLike, + CallOverrides, ContractTransaction, Overrides, - CallOverrides, + PopulatedTransaction, + Signer, + utils, } from "ethers"; -import { BytesLike } from "@ethersproject/bytes"; +import { FunctionFragment, Result, EventFragment } from "@ethersproject/abi"; import { Listener, Provider } from "@ethersproject/providers"; -import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi"; -import type { - TypedEventFilter, - TypedEvent, - TypedListener, - OnEvent, -} from "./common"; - -export interface SynapseERC20Interface extends ethers.utils.Interface { +import { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from "./common"; + +export interface SynapseERC20Interface extends utils.Interface { + contractName: "SynapseERC20"; functions: { "DEFAULT_ADMIN_ROLE()": FunctionFragment; "DOMAIN_SEPARATOR()": FunctionFragment; @@ -267,6 +261,7 @@ export type TransferEvent = TypedEvent< export type TransferEventFilter = TypedEventFilter; export interface SynapseERC20 extends BaseContract { + contractName: "SynapseERC20"; connect(signerOrProvider: Signer | Provider | string): this; attach(addressOrName: string): this; deployed(): Promise; diff --git a/src/contracts/gen/factories/PoolConfig__factory.ts b/src/contracts/gen/factories/PoolConfig__factory.ts new file mode 100644 index 00000000..6b5e0a15 --- /dev/null +++ b/src/contracts/gen/factories/PoolConfig__factory.ts @@ -0,0 +1,371 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { PoolConfig, PoolConfigInterface } from "../PoolConfig"; + +const _abi = [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + indexed: true, + internalType: "bytes32", + name: "previousAdminRole", + type: "bytes32", + }, + { + indexed: true, + internalType: "bytes32", + name: "newAdminRole", + type: "bytes32", + }, + ], + name: "RoleAdminChanged", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleGranted", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + indexed: true, + internalType: "address", + name: "account", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "RoleRevoked", + type: "event", + }, + { + inputs: [], + name: "BRIDGEMANAGER_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "DEFAULT_ADMIN_ROLE", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "tokenAddress", + type: "address", + }, + { + internalType: "uint256", + name: "chainID", + type: "uint256", + }, + ], + name: "getPoolConfig", + outputs: [ + { + components: [ + { + internalType: "address", + name: "tokenAddress", + type: "address", + }, + { + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + internalType: "address", + name: "poolAddress", + type: "address", + }, + { + internalType: "bool", + name: "metaswap", + type: "bool", + }, + ], + internalType: "struct PoolConfig.Pool", + name: "", + type: "tuple", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + ], + name: "getRoleAdmin", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + ], + name: "getRoleMember", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + ], + name: "getRoleMemberCount", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "grantRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "hasRole", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "renounceRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes32", + name: "role", + type: "bytes32", + }, + { + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "revokeRole", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "tokenAddress", + type: "address", + }, + { + internalType: "uint256", + name: "chainID", + type: "uint256", + }, + { + internalType: "address", + name: "poolAddress", + type: "address", + }, + { + internalType: "bool", + name: "metaswap", + type: "bool", + }, + ], + name: "setPoolConfig", + outputs: [ + { + components: [ + { + internalType: "address", + name: "tokenAddress", + type: "address", + }, + { + internalType: "uint256", + name: "chainId", + type: "uint256", + }, + { + internalType: "address", + name: "poolAddress", + type: "address", + }, + { + internalType: "bool", + name: "metaswap", + type: "bool", + }, + ], + internalType: "struct PoolConfig.Pool", + name: "", + type: "tuple", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, +]; + +export class PoolConfig__factory { + static readonly abi = _abi; + static createInterface(): PoolConfigInterface { + return new utils.Interface(_abi) as PoolConfigInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): PoolConfig { + return new Contract(address, _abi, signerOrProvider) as PoolConfig; + } +} diff --git a/src/contracts/gen/factories/SwapFlashLoan__factory.ts b/src/contracts/gen/factories/SwapFlashLoan__factory.ts new file mode 100644 index 00000000..308b6bd1 --- /dev/null +++ b/src/contracts/gen/factories/SwapFlashLoan__factory.ts @@ -0,0 +1,1019 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from "ethers"; +import { Provider } from "@ethersproject/providers"; +import type { SwapFlashLoan, SwapFlashLoanInterface } from "../SwapFlashLoan"; + +const _abi = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: false, + internalType: "uint256[]", + name: "tokenAmounts", + type: "uint256[]", + }, + { + indexed: false, + internalType: "uint256[]", + name: "fees", + type: "uint256[]", + }, + { + indexed: false, + internalType: "uint256", + name: "invariant", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "lpTokenSupply", + type: "uint256", + }, + ], + name: "AddLiquidity", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address", + }, + { + indexed: false, + internalType: "uint8", + name: "tokenIndex", + type: "uint8", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "amountFee", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "protocolFee", + type: "uint256", + }, + ], + name: "FlashLoan", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "newAdminFee", + type: "uint256", + }, + ], + name: "NewAdminFee", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "newSwapFee", + type: "uint256", + }, + ], + name: "NewSwapFee", + 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: "address", + name: "account", + type: "address", + }, + ], + name: "Paused", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "oldA", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "newA", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "initialTime", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "futureTime", + type: "uint256", + }, + ], + name: "RampA", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: false, + internalType: "uint256[]", + name: "tokenAmounts", + type: "uint256[]", + }, + { + indexed: false, + internalType: "uint256", + name: "lpTokenSupply", + type: "uint256", + }, + ], + name: "RemoveLiquidity", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: false, + internalType: "uint256[]", + name: "tokenAmounts", + type: "uint256[]", + }, + { + indexed: false, + internalType: "uint256[]", + name: "fees", + type: "uint256[]", + }, + { + indexed: false, + internalType: "uint256", + name: "invariant", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "lpTokenSupply", + type: "uint256", + }, + ], + name: "RemoveLiquidityImbalance", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "provider", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "lpTokenAmount", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "lpTokenSupply", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "boughtId", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "tokensBought", + type: "uint256", + }, + ], + name: "RemoveLiquidityOne", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "currentA", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "time", + type: "uint256", + }, + ], + name: "StopRampA", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "tokensSold", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "tokensBought", + type: "uint256", + }, + { + indexed: false, + internalType: "uint128", + name: "soldId", + type: "uint128", + }, + { + indexed: false, + internalType: "uint128", + name: "boughtId", + type: "uint128", + }, + ], + name: "TokenSwap", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "account", + type: "address", + }, + ], + name: "Unpaused", + type: "event", + }, + { + inputs: [], + name: "MAX_BPS", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256[]", + name: "amounts", + type: "uint256[]", + }, + { + internalType: "uint256", + name: "minToMint", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + ], + name: "addLiquidity", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + name: "calculateRemoveLiquidity", + outputs: [ + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "tokenAmount", + type: "uint256", + }, + { + internalType: "uint8", + name: "tokenIndex", + type: "uint8", + }, + ], + name: "calculateRemoveLiquidityOneToken", + outputs: [ + { + internalType: "uint256", + name: "availableTokenAmount", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint8", + name: "tokenIndexFrom", + type: "uint8", + }, + { + internalType: "uint8", + name: "tokenIndexTo", + type: "uint8", + }, + { + internalType: "uint256", + name: "dx", + type: "uint256", + }, + ], + name: "calculateSwap", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256[]", + name: "amounts", + type: "uint256[]", + }, + { + internalType: "bool", + name: "deposit", + type: "bool", + }, + ], + name: "calculateTokenAmount", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "receiver", + type: "address", + }, + { + internalType: "contract IERC20", + name: "token", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "bytes", + name: "params", + type: "bytes", + }, + ], + name: "flashLoan", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "flashLoanFeeBPS", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getA", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getAPrecise", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "index", + type: "uint256", + }, + ], + name: "getAdminBalance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint8", + name: "index", + type: "uint8", + }, + ], + name: "getToken", + outputs: [ + { + internalType: "contract IERC20", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint8", + name: "index", + type: "uint8", + }, + ], + name: "getTokenBalance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "tokenAddress", + type: "address", + }, + ], + name: "getTokenIndex", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getVirtualPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "contract IERC20[]", + name: "_pooledTokens", + type: "address[]", + }, + { + internalType: "uint8[]", + name: "decimals", + type: "uint8[]", + }, + { + internalType: "string", + name: "lpTokenName", + type: "string", + }, + { + internalType: "string", + name: "lpTokenSymbol", + type: "string", + }, + { + internalType: "uint256", + name: "_a", + type: "uint256", + }, + { + internalType: "uint256", + name: "_fee", + type: "uint256", + }, + { + internalType: "uint256", + name: "_adminFee", + type: "uint256", + }, + { + internalType: "address", + name: "lpTokenTargetAddress", + type: "address", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "owner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "pause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "paused", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "protocolFeeShareBPS", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "futureA", + type: "uint256", + }, + { + internalType: "uint256", + name: "futureTime", + type: "uint256", + }, + ], + name: "rampA", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + internalType: "uint256[]", + name: "minAmounts", + type: "uint256[]", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + ], + name: "removeLiquidity", + outputs: [ + { + internalType: "uint256[]", + name: "", + type: "uint256[]", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256[]", + name: "amounts", + type: "uint256[]", + }, + { + internalType: "uint256", + name: "maxBurnAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + ], + name: "removeLiquidityImbalance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "tokenAmount", + type: "uint256", + }, + { + internalType: "uint8", + name: "tokenIndex", + type: "uint8", + }, + { + internalType: "uint256", + name: "minAmount", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + ], + name: "removeLiquidityOneToken", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "renounceOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "newAdminFee", + type: "uint256", + }, + ], + name: "setAdminFee", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "newFlashLoanFeeBPS", + type: "uint256", + }, + { + internalType: "uint256", + name: "newProtocolFeeShareBPS", + type: "uint256", + }, + ], + name: "setFlashLoanFees", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "newSwapFee", + type: "uint256", + }, + ], + name: "setSwapFee", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "stopRampA", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint8", + name: "tokenIndexFrom", + type: "uint8", + }, + { + internalType: "uint8", + name: "tokenIndexTo", + type: "uint8", + }, + { + internalType: "uint256", + name: "dx", + type: "uint256", + }, + { + internalType: "uint256", + name: "minDy", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + ], + name: "swap", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "swapStorage", + outputs: [ + { + internalType: "uint256", + name: "initialA", + type: "uint256", + }, + { + internalType: "uint256", + name: "futureA", + type: "uint256", + }, + { + internalType: "uint256", + name: "initialATime", + type: "uint256", + }, + { + internalType: "uint256", + name: "futureATime", + type: "uint256", + }, + { + internalType: "uint256", + name: "swapFee", + type: "uint256", + }, + { + internalType: "uint256", + name: "adminFee", + type: "uint256", + }, + { + internalType: "contract LPToken", + name: "lpToken", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "transferOwnership", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "unpause", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "withdrawAdminFees", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, +]; + +export class SwapFlashLoan__factory { + static readonly abi = _abi; + static createInterface(): SwapFlashLoanInterface { + return new utils.Interface(_abi) as SwapFlashLoanInterface; + } + static connect( + address: string, + signerOrProvider: Signer | Provider + ): SwapFlashLoan { + return new Contract(address, _abi, signerOrProvider) as SwapFlashLoan; + } +} diff --git a/src/contracts/gen/index.ts b/src/contracts/gen/index.ts index d0479dad..b496be46 100644 --- a/src/contracts/gen/index.ts +++ b/src/contracts/gen/index.ts @@ -5,6 +5,8 @@ export type { BridgeConfig } from "./BridgeConfig"; export type { ERC20 } from "./ERC20"; export type { L1BridgeZap } from "./L1BridgeZap"; export type { L2BridgeZap } from "./L2BridgeZap"; +export type { PoolConfig } from "./PoolConfig"; +export type { SwapFlashLoan } from "./SwapFlashLoan"; export type { SynapseBridge } from "./SynapseBridge"; export type { SynapseERC20 } from "./SynapseERC20"; @@ -12,5 +14,7 @@ export { BridgeConfig__factory } from "./factories/BridgeConfig__factory"; export { ERC20__factory } from "./factories/ERC20__factory"; export { L1BridgeZap__factory } from "./factories/L1BridgeZap__factory"; export { L2BridgeZap__factory } from "./factories/L2BridgeZap__factory"; +export { PoolConfig__factory } from "./factories/PoolConfig__factory"; +export { SwapFlashLoan__factory } from "./factories/SwapFlashLoan__factory"; export { SynapseBridge__factory } from "./factories/SynapseBridge__factory"; export { SynapseERC20__factory } from "./factories/SynapseERC20__factory"; diff --git a/src/contracts/index.ts b/src/contracts/index.ts index 5d44a6bc..02b06ab9 100644 --- a/src/contracts/index.ts +++ b/src/contracts/index.ts @@ -3,7 +3,9 @@ import type { L1BridgeZap as L1BridgeZapContract, L2BridgeZap as L2BridgeZapContract, SynapseERC20 as SynapseERC20Contract, + SwapFlashLoan as SwapContract, BridgeConfig as BridgeConfigContract, + PoolConfig as PoolConfigContract, ERC20 as ERC20Contract } from "./gen"; @@ -14,7 +16,9 @@ export type { L1BridgeZapContract, L2BridgeZapContract, SynapseERC20Contract, + SwapContract, BridgeConfigContract, + PoolConfigContract, GenericZapBridgeContract, ERC20Contract } @@ -24,6 +28,8 @@ export { L1BridgeZap__factory as L1BridgeZapFactory, L2BridgeZap__factory as L2BridgeZapFactory, SynapseERC20__factory as SynapseERC20Factory, + SwapFlashLoan__factory as SwapFactory, BridgeConfig__factory as BridgeConfigFactory, + PoolConfig__factory as PoolConfigFactory, ERC20__factory as ERC20Factory } from "./gen"; \ No newline at end of file diff --git a/src/entities/synapse_entities.ts b/src/entities/synapse_entities.ts index 3f40af47..b24df272 100644 --- a/src/entities/synapse_entities.ts +++ b/src/entities/synapse_entities.ts @@ -1,14 +1,20 @@ import {contractAddressFor} from "../common/utils"; -import { +import type { SynapseBridgeContract, - SynapseBridgeFactory, L1BridgeZapContract, - L1BridgeZapFactory, L2BridgeZapContract, - L2BridgeZapFactory, + GenericZapBridgeContract, BridgeConfigContract, - BridgeConfigFactory, GenericZapBridgeContract, + PoolConfigContract, +} from "../contracts"; + +import { + SynapseBridgeFactory, + L1BridgeZapFactory, + L2BridgeZapFactory, + BridgeConfigFactory, + PoolConfigFactory, } from "../contracts"; import type {SignerOrProvider} from "../common"; @@ -19,8 +25,9 @@ import {newProviderForNetwork} from "../internal/rpcproviders"; export namespace SynapseEntities { - export const bridgeConfigAddress: string = "0x7fd806049608b7d04076b8187dd773343e0589e6"; - // export const bridgeConfigAddress: string = "0xAE908bb4905bcA9BdE0656CC869d0F23e77875E7" + const + bridgeConfigAddress: string = "0x7fd806049608b7d04076b8187dd773343e0589e6", + poolConfigAddress: string = "0xB34C67DB5F0Fd8D3D4238FD0A1cBbfD50a72e177"; export function synapseBridge(params: { chainId: number, @@ -61,6 +68,11 @@ export namespace SynapseEntities { export function bridgeConfig(): BridgeConfigContract { const provider = newProviderForNetwork(ChainId.ETH); - return BridgeConfigFactory.connect(bridgeConfigAddress, provider); + return BridgeConfigFactory.connect(bridgeConfigAddress, provider) + } + + export function poolConfig(): PoolConfigContract { + const provider = newProviderForNetwork(ChainId.ETH); + return PoolConfigFactory.connect(poolConfigAddress, provider) } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index b2d13807..2c3f778b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,11 +12,11 @@ export const { l2BridgeZap, } = SynapseEntities; -import {Bridge, Slippages, UnsupportedSwapReason} from "./bridge"; +import {Bridge, Slippages} from "./bridge"; export type BridgeOutputEstimate = Bridge.BridgeOutputEstimate; -export {Bridge, Slippages, UnsupportedSwapReason} +export {Bridge, Slippages} export { ChainId, @@ -37,15 +37,15 @@ export { SwapPools, networkSwapTokensMap, allNetworksSwapTokensMap, - detailedTokenSwapMap, swappableTokens, swappableTokensAllNetworks, } from "./swappools"; export type { - DetailedTokenSwapMap, NetworkSwappableTokensMap } from "./swappools"; +export {TokenSwap, UnsupportedSwapErrors} from "./tokenswap"; + export type { SynapseBridgeContract, GenericZapBridgeContract, diff --git a/src/swappools/swappools.ts b/src/swappools/swappools.ts index b91d28fb..c5742850 100644 --- a/src/swappools/swappools.ts +++ b/src/swappools/swappools.ts @@ -614,6 +614,50 @@ export namespace SwapPools { } export const swapGroupsForNetwork = (chainId: number): string[] => Object.keys(bridgeSwappableTokensByType[chainId]) + + export function stableswapPoolForNetwork(chainId: number): SwapPoolToken { + switch (chainId) { + case ChainId.ETH: + return ETH_POOL_SWAP_TOKEN + case ChainId.BSC: + return BSC_POOL_SWAP_TOKEN + case ChainId.POLYGON: + return POLYGON_POOL_SWAP_TOKEN + case ChainId.FANTOM: + return FANTOM_POOL_SWAP_TOKEN + case ChainId.BOBA: + return BOBA_POOL_SWAP_TOKEN + case ChainId.ARBITRUM: + return ARBITRUM_POOL_SWAP_TOKEN + case ChainId.AVALANCHE: + return AVALANCHE_POOL_SWAP_TOKEN + case ChainId.AURORA: + return AURORA_POOL_SWAP_TOKEN + case ChainId.HARMONY: + return HARMONY_POOL_SWAP_TOKEN + } + + return undefined + } + + export function ethSwapPoolForNetwork(chainId: number): SwapPoolToken { + switch (chainId) { + case ChainId.OPTIMISM: + return OPTIMISM_ETH_SWAP_TOKEN + case ChainId.FANTOM: + return FANTOM_ETH_SWAP_TOKEN + case ChainId.BOBA: + return BOBA_ETH_SWAP_TOKEN + case ChainId.ARBITRUM: + return ARBITRUM_ETH_SWAP_TOKEN + case ChainId.AVALANCHE: + return AVALANCHE_ETH_SWAP_TOKEN + case ChainId.HARMONY: + return HARMONY_ONEETH_TOKEN + } + + return undefined + } } export interface NetworkSwappableTokensMap { @@ -697,49 +741,5 @@ export function allNetworksSwapTokensMap(): AllNetworksSwappableTokensMap { res[chainIdA] = swapGroupsLoop(chainIdA, swapGrpsA); }) - return res -} - -export interface DetailedTokenSwapMap { - [chainId: number]: { - token: Token, - [chainId: number]: Token[], - }[], -} - -interface TokenSwapMap { - token: Token, - [chainId: number]: Token[], -} - -export function detailedTokenSwapMap(): DetailedTokenSwapMap { - let res: DetailedTokenSwapMap = {}; - - const allChainIds = ChainId.supportedChainIds(); - - for (const c1 of allChainIds) { - let n1: Networks.Network = Networks.fromChainId(c1); - let networkTokens: Token[] = n1.tokens; - - res[c1] = networkTokens.map((t: Token) => { - let swapType = t.swapType; - - let tokSwapMap: TokenSwapMap = { - token: t, - } - - for (const c2 of allChainIds) { - if (c1 === c2) continue - - let outToks: Token[] = SwapPools.bridgeSwappableTypePoolsByChain[c2][swapType]?.poolTokens || []; - if (outToks.length === 0) continue - - tokSwapMap[c2] = outToks; - } - - return tokSwapMap - }) - } - return res } \ No newline at end of file diff --git a/src/tokenswap/index.ts b/src/tokenswap/index.ts new file mode 100644 index 00000000..c0f9521a --- /dev/null +++ b/src/tokenswap/index.ts @@ -0,0 +1,2 @@ +export * from "./tokenswap"; +export * from "./unsupportedSwapErrors"; \ No newline at end of file diff --git a/src/tokenswap/tokenswap.ts b/src/tokenswap/tokenswap.ts new file mode 100644 index 00000000..cacd429d --- /dev/null +++ b/src/tokenswap/tokenswap.ts @@ -0,0 +1,296 @@ +import {Token} from "../token"; +import {Tokens} from "../tokens"; +import {SwapPools} from "../swappools"; +import { + ChainId, + Networks, +} from "../common"; +import {rejectPromise} from "../common/utils"; + +import {SynapseEntities} from "../entities"; +import {SwapContract, SwapFactory} from "../contracts"; + +import {SwapType} from "../internal/swaptype"; +import {newProviderForNetwork} from "../internal/rpcproviders"; + +import {UnsupportedSwapErrors} from "./unsupportedSwapErrors"; + +import {PopulatedTransaction} from "@ethersproject/contracts"; +import {BigNumber, BigNumberish} from "@ethersproject/bignumber"; + + +export namespace TokenSwap { + export interface SwapParams { + chainId: number, + tokenFrom: Token, + tokenTo: Token, + amountIn: BigNumberish, + } + + export interface SwapTokensParams extends SwapParams { + minAmountOut: BigNumberish, + deadline?: number, + } + + export interface BridgeSwapSupportedParams { + tokenFrom: Token, + tokenTo: Token, + chainIdFrom: number, + chainIdTo: number, + } + + export interface EstimatedSwapRate { + amountOut: BigNumber + } + + export interface IntermediateSwapTokens { + intermediateToken?: Token, + bridgeConfigIntermediateToken: Token + } + + export interface SwapSupportedResult { + swapSupported: boolean, + reasonNotSupported?: UnsupportedSwapErrors.UnsupportedSwapError, + } + + export interface DetailedTokenSwapMap { + [chainId: number]: { + token: Token, + [chainId: number]: Token[], + }[], + } + + interface TokenSwapMap { + token: Token, + [chainId: number]: Token[], + } + + export function swapSupported(args: SwapParams): SwapSupportedResult { + const {tokenFrom, tokenTo, chainId} = args; + + return checkCanSwap(tokenFrom, tokenTo, chainId) + } + + export function bridgeSwapSupported(args: BridgeSwapSupportedParams): SwapSupportedResult { + const {tokenFrom, tokenTo, chainIdFrom, chainIdTo} = args; + + let + swapSupported: boolean = true, + reasonNotSupported: UnsupportedSwapErrors.UnsupportedSwapError; + + const canSwap = checkCanSwap(tokenFrom, tokenTo, chainIdFrom, chainIdTo); + if (!canSwap.swapSupported) { + return canSwap + } + + const checkBoba = (c: number, t: Token): boolean => c === ChainId.BOBA && t.swapType === SwapType.ETH; + const + isEthFromBoba = checkBoba(chainIdFrom, tokenFrom), + isEthToBoba = checkBoba(chainIdTo, tokenTo); + + if (isEthFromBoba || isEthToBoba) { + swapSupported = false; + reasonNotSupported = UnsupportedSwapErrors.ethOnBoba(); + } + + return {swapSupported, reasonNotSupported} + } + + export async function calculateSwapRate(args: SwapParams): Promise { + const {swapSupported: canSwap, reasonNotSupported} = swapSupported(args); + if (!canSwap) { + return rejectPromise(reasonNotSupported) + } + + const {swapInstance, tokenIndexFrom, tokenIndexTo} = await swapSetup(args.tokenFrom, args.tokenTo, args.chainId); + + return swapInstance.calculateSwap(tokenIndexFrom, tokenIndexTo, args.amountIn) + .then((res): EstimatedSwapRate => ({amountOut: res})) + } + + export async function buildSwapTokensTransaction(args: SwapTokensParams): Promise { + const {swapSupported: canSwap, reasonNotSupported} = swapSupported(args); + if (!canSwap) { + return rejectPromise(reasonNotSupported) + } + + const {swapInstance, tokenIndexFrom, tokenIndexTo} = await swapSetup(args.tokenFrom, args.tokenTo, args.chainId); + + let {deadline} = args; + deadline = deadline ?? Math.round((new Date().getTime() / 1000) + 60 * 10) + + const overrides: any = args.tokenFrom.isEqual(Tokens.ETH) ? {value:args.amountIn} : {}; + + return swapInstance.populateTransaction.swap( + tokenIndexFrom, + tokenIndexTo, + args.amountIn, + args.minAmountOut, + deadline, + overrides + ) + } + + export function intermediateTokens(chainId: number, token: Token): IntermediateSwapTokens { + if (mintBurnSwapTypes.includes(token.swapType)) { + return {intermediateToken: token, bridgeConfigIntermediateToken: token} + } + + let + intermediateToken: Token, + bridgeConfigIntermediateToken: Token; + + switch (token.swapType) { + case SwapType.SYN: + intermediateToken = Tokens.SYN; + break; + case SwapType.FRAX: + bridgeConfigIntermediateToken = chainId === ChainId.ETH ? Tokens.FRAX : Tokens.SYN_FRAX; + break; + case SwapType.ETH: + intermediateToken = Tokens.NETH; + bridgeConfigIntermediateToken = chainId === ChainId.ETH ? Tokens.WETH : Tokens.NETH; + break; + case SwapType.AVAX: + intermediateToken = Tokens.WAVAX; + break; + case SwapType.MOVR: + intermediateToken = Tokens.WMOVR; + break; + default: + intermediateToken = Tokens.NUSD; + break; + } + + bridgeConfigIntermediateToken = bridgeConfigIntermediateToken ?? intermediateToken; + + return {intermediateToken, bridgeConfigIntermediateToken} + } + + export function detailedTokenSwapMap(): DetailedTokenSwapMap { + let res: DetailedTokenSwapMap = {}; + + const allChainIds = ChainId.supportedChainIds(); + + for (const c1 of allChainIds) { + let n1: Networks.Network = Networks.fromChainId(c1); + let networkTokens: Token[] = n1.tokens; + + res[c1] = networkTokens.map((t: Token) => { + let swapType = t.swapType; + + let tokSwapMap: TokenSwapMap = { + token: t, + } + + for (const c2 of allChainIds) { + if (c1 === c2) continue + + let outToks: Token[] = SwapPools.bridgeSwappableTypePoolsByChain[c2][swapType]?.poolTokens || []; + if (outToks.length === 0) continue + + tokSwapMap[c2] = outToks; + } + + return tokSwapMap + }) + } + + return res + } + + interface SwapSetup { + swapInstance: SwapContract, + tokenIndexFrom: number, + tokenIndexTo: number, + } + + async function swapContract(token: Token, chainId: number): Promise { + const + poolConfigInstance = SynapseEntities.poolConfig(), + lpToken = intermediateToken(token, chainId), + {poolAddress} = await poolConfigInstance.getPoolConfig(lpToken.address(chainId), chainId); + + return SwapFactory.connect(poolAddress, newProviderForNetwork(chainId)) + } + + async function swapSetup(tokenFrom: Token, tokenTo: Token, chainId: number): Promise { + const + swapInstance = await swapContract(tokenFrom, chainId), + tokenIndexFrom = await swapInstance.getTokenIndex(tokenFrom.address(chainId)), + tokenIndexTo = await swapInstance.getTokenIndex(tokenTo.address(chainId)); + + return { + swapInstance, + tokenIndexFrom, + tokenIndexTo, + } + } + + function intermediateToken(token: Token, chainId: number): Token { + const {intermediateToken, bridgeConfigIntermediateToken} = intermediateTokens(chainId, token); + + return intermediateToken ?? bridgeConfigIntermediateToken + } + + const mintBurnSwapTypes = [ + SwapType.HIGH, SwapType.DOG, SwapType.JUMP, + SwapType.NFD, SwapType.OHM, SwapType.SOLAR, + SwapType.GMX, + ]; + + function checkCanSwap(tokenFrom: Token, tokenTo: Token, chainFrom: number, chainTo?: number): SwapSupportedResult { + const + tokensCanSwap = checkTokensCanSwap(tokenFrom, tokenTo), + tokensSupported = checkTokensSupported(tokenFrom, tokenTo, chainFrom, chainTo); + + if (!tokensSupported.swapSupported) { + return tokensSupported + } else if (!tokensCanSwap.swapSupported) { + return tokensCanSwap + } + + return {swapSupported: true} + } + + function checkTokensCanSwap(tokenFrom: Token, tokenTo: Token): SwapSupportedResult { + let + swapSupported: boolean = true, + reasonNotSupported: UnsupportedSwapErrors.UnsupportedSwapError; + + if (tokenFrom.swapType !== tokenTo.swapType) { + swapSupported = false; + reasonNotSupported = UnsupportedSwapErrors.nonMatchingSwapTypes(tokenFrom.swapType, tokenTo.swapType); + } + + return {swapSupported, reasonNotSupported} + } + + function checkTokensSupported(tokenFrom: Token, tokenTo: Token, chainIdFrom: number, chainIdTo?: number): SwapSupportedResult { + const + unsupportedFromFunc = (typeof chainIdTo !== "undefined" + ? UnsupportedSwapErrors.tokenNotSupportedNetFrom + : UnsupportedSwapErrors.tokenNotSupported), + unsupportedToFunc = (typeof chainIdTo !== "undefined" + ? UnsupportedSwapErrors.tokenNotSupportedNetTo + : UnsupportedSwapErrors.tokenNotSupported); + + const + netFrom = Networks.fromChainId(chainIdFrom), + netTo = (typeof chainIdTo !== "undefined" ? Networks.fromChainId(chainIdTo) : netFrom); + + let + swapSupported: boolean = true, + reasonNotSupported: UnsupportedSwapErrors.UnsupportedSwapError; + + if (!netFrom.supportsToken(tokenFrom)) { + swapSupported = false; + reasonNotSupported = unsupportedFromFunc(tokenFrom, netFrom.name); + } else if (!netTo.supportsToken(tokenTo)) { + swapSupported = false; + reasonNotSupported = unsupportedToFunc(tokenTo, netTo.name); + } + + return {swapSupported, reasonNotSupported} + } +} \ No newline at end of file diff --git a/src/tokenswap/unsupportedSwapErrors.ts b/src/tokenswap/unsupportedSwapErrors.ts new file mode 100644 index 00000000..cf9b7b24 --- /dev/null +++ b/src/tokenswap/unsupportedSwapErrors.ts @@ -0,0 +1,47 @@ +export namespace UnsupportedSwapErrors { + interface Tok {symbol: string} + + export enum UnsupportedSwapErrorKind { + UnsupportedToken, + UnsupportedTokenNetFrom, + UnsupportedTokenNetTo, + NonmatchingSwapTypes, + BobaToL1, + ETHOnBoba, + } + + export interface UnsupportedSwapError { + errorKind: UnsupportedSwapErrorKind, + reason: string, + } + + export const tokenNotSupported = (t: Tok, netName: string): UnsupportedSwapError => ({ + errorKind: UnsupportedSwapErrorKind.UnsupportedToken, + reason: `Token ${t.symbol} not supported on network ${netName}`, + }) + + export const tokenNotSupportedNetFrom = (t: Tok, netName: string): UnsupportedSwapError => ({ + errorKind: UnsupportedSwapErrorKind.UnsupportedTokenNetFrom, + reason: `Token ${t.symbol} not supported on 'from' network ${netName}`, + }) + + export const tokenNotSupportedNetTo = (t: Tok, netName: string): UnsupportedSwapError => ({ + errorKind: UnsupportedSwapErrorKind.UnsupportedTokenNetTo, + reason: `Token ${t.symbol} not supported on 'to' network ${netName}`, + }) + + export const nonMatchingSwapTypes = (st1: string, st2: string): UnsupportedSwapError => ({ + errorKind: UnsupportedSwapErrorKind.NonmatchingSwapTypes, + reason: "Token swap types don't match", + }) + + export const ethOnBoba = (): UnsupportedSwapError => ({ + errorKind: UnsupportedSwapErrorKind.ETHOnBoba, + reason: "Currently, the SDK only supports bridging Stablecoins to and from BOBA", + }) + + export const bobaToL1 = (): UnsupportedSwapError => ({ + errorKind: UnsupportedSwapErrorKind.BobaToL1, + reason: "Bridging ETH from Boba Mainnet to L1 not currently supported", + }) +} \ No newline at end of file diff --git a/test/bridge/SynapseBridge-test.ts b/test/bridge/SynapseBridge-test.ts index 60768472..abcec5a7 100644 --- a/test/bridge/SynapseBridge-test.ts +++ b/test/bridge/SynapseBridge-test.ts @@ -40,7 +40,8 @@ import { PROVIDER_AURORA, PROVIDER_HARMONY, makeWalletSignerWithProvider, - getActualWei + getActualWei, + getTestAmount, } from "../helpers"; @@ -59,7 +60,7 @@ const EXECUTORS_TEST_TIMEOUT = makeTimeout(180); -describe("SynapseBridge", function() { +describe("SynapseBridge", function(this: Mocha.Suite) { describe("read-only wrapper functions", function(this: Mocha.Suite) { describe(".bridgeVersion()", function(this: Mocha.Suite) { const expected = 6; @@ -294,11 +295,6 @@ describe("SynapseBridge", function() { noAddrTo: boolean, } - const testAmounts: string[] = [ - "420", "1337", "31337", - "669", "555", - ] - const makeTestCase = ( t1: Token, t2: Token, c1: number, c2: number, @@ -313,10 +309,7 @@ describe("SynapseBridge", function() { chainIdFrom: c1, tokenTo: t2, chainIdTo: c2, - amountFrom: t1.valueToWei( - amt ?? _.shuffle(testAmounts)[0], - c1 - ), + amountFrom: getTestAmount(t1, c1, amt), }, notZero: notZero ?? true, wantError: wantErr ?? false, diff --git a/test/helpers/index.ts b/test/helpers/index.ts index 00aa3c67..da0a903e 100644 --- a/test/helpers/index.ts +++ b/test/helpers/index.ts @@ -1,16 +1,26 @@ import "./chaisetup"; +import _ from "lodash"; + import {expect} from "chai"; import {Wallet} from "@ethersproject/wallet"; import {JsonRpcProvider} from "@ethersproject/providers"; import {BigNumber, BigNumberish} from "@ethersproject/bignumber"; -import {ChainId} from "../../src"; +import {Token, ChainId} from "../../src"; import {newProviderForNetwork} from "../../src/internal/rpcproviders"; + const TEN_BN: BigNumber = BigNumber.from(10); +const testAmounts: string[] = [ + "420", "1337", "31337", + "669", "555", +]; + +export const getTestAmount = (t: Token, c: number, amt?: BigNumberish): BigNumber => t.valueToWei(amt ?? _.shuffle(testAmounts)[0], c) + export function makeWalletSignerWithProvider(chainId: number, privKey: string): Wallet { const provider = newProviderForNetwork(chainId); diff --git a/test/tokenswap/TokenSwap-test.ts b/test/tokenswap/TokenSwap-test.ts new file mode 100644 index 00000000..5932b43e --- /dev/null +++ b/test/tokenswap/TokenSwap-test.ts @@ -0,0 +1,123 @@ +import "../helpers/chaisetup"; + +import {expect} from "chai"; +import {Context, Done} from "mocha"; + +import {step} from "mocha-steps"; + +import {Zero} from "@ethersproject/constants"; +import {BigNumber} from "@ethersproject/bignumber"; + +import { + ChainId, + Networks, + Token, + Tokens, + TokenSwap, +} from "../../src"; + +import {getTestAmount} from "../helpers"; +import {PopulatedTransaction} from "ethers"; + +describe("TokenSwap tests", function(this: Mocha.Suite) { + describe("Swap Rate tests", function(this: Mocha.Suite) { + interface TestCase { + chainId: number, + tokenFrom: Token, + tokenTo: Token, + amountIn: BigNumber, + wantError: boolean, + } + + const makeTestCase = (c: number, t1: Token, t2: Token, amt?: string, wantError?: boolean): TestCase => + ({ + chainId: c, + tokenFrom: t1, + tokenTo: t2, + amountIn: getTestAmount(t1, c, amt), + wantError: wantError ?? false, + }) + + const testCases: TestCase[] = [ + makeTestCase(ChainId.ETH, Tokens.DAI, Tokens.USDC), + makeTestCase(ChainId.ETH, Tokens.ETH, Tokens.NETH, null, true), + makeTestCase(ChainId.OPTIMISM, Tokens.WETH, Tokens.NETH), + makeTestCase(ChainId.AVALANCHE, Tokens.MIM, Tokens.USDT, null, true), + makeTestCase(ChainId.BSC, Tokens.BUSD, Tokens.USDT), + makeTestCase(ChainId.BSC, Tokens.NUSD, Tokens.BUSD), + ] + + for (const tc of testCases) { + const + netName: string = Networks.fromChainId(tc.chainId).name, + titleSuffix: string = tc.wantError ? "should fail" : "should pass", + tokFrom: string = tc.tokenFrom.symbol, + tokTo: string = tc.tokenTo.symbol, + testTitle: string = `for ${tokFrom} => ${tokTo} on ${netName} ${titleSuffix}`, + testTitle1: string = `calculateSwapRate ${testTitle}`, + testTitle2: string = `buildSwapTokensTransaction ${testTitle}`; + + let amountOut: BigNumber; + + step(testTitle1, function(this: Context, done: Done) { + this.timeout(10*1000); + + let prom: Promise = TokenSwap.calculateSwapRate({ + chainId: tc.chainId, + tokenFrom: tc.tokenFrom, + tokenTo: tc.tokenTo, + amountIn: tc.amountIn, + }); + + Promise.resolve(prom).then((res) => amountOut = res.amountOut); + + tc.wantError + ? expect(prom).to.eventually.be.rejected.notify(done) + : expect(prom).to.eventually.have.property('amountOut').that.is.gt(Zero).notify(done); + }) + + step(testTitle2, function(this: Context, done: Done) { + this.timeout(10*1000); + + if (!tc.wantError) { + const args: TokenSwap.SwapTokensParams = { + ...tc, + minAmountOut: amountOut, + }; + + let prom: Promise = TokenSwap.buildSwapTokensTransaction(args); + expect(prom).to.eventually.be.fulfilled.notify(done); + return + } + + done(); + }) + } + }) + + describe("detailedTokenSwapMap test", function(this: Mocha.Suite) { + const + allChains = ChainId.supportedChainIds(), + detailedMap = TokenSwap.detailedTokenSwapMap(); + + it(`should have ${allChains.length} entries`, function() { + expect(Object.keys(detailedMap)).to.have.length(allChains.length); + }) + + const + bscToksMap = detailedMap[ChainId.BSC], + ethToksMap = detailedMap[ChainId.ETH]; + + it("BSC tokens map should have certain results", function(this: Context) { + let bscUSDT = bscToksMap.find((sm) => sm.token.isEqual(Tokens.USDT)); + expect(bscUSDT).to.not.be.undefined; + + expect(bscUSDT).to.have.property(ChainId.ETH); + }) + + it("ETH tokens map should have certain results", function(this: Context) { + let ethGOHM = ethToksMap.find((sm) => sm.token.isEqual(Tokens.GOHM)); + expect(ethGOHM).to.not.be.undefined; + }) + }) +}) \ No newline at end of file