├── .commitlintrc
├── .eslintignore
├── .eslintrc
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── checks.yaml
│ └── tests.yaml
├── .gitignore
├── .gitmodules
├── .husky
├── commit-msg
└── pre-commit
├── .npmignore
├── .prettierignore
├── .prettierrc
├── .solcover.js
├── .solhint.json
├── .solhintignore
├── LICENSE
├── README.md
├── contracts
├── CrossChain
│ ├── SgInfo.sol
│ ├── WooCrossChainRouter.sol
│ ├── WooCrossChainRouterV2.sol
│ ├── WooCrossChainRouterV3.sol
│ ├── WooCrossChainRouterV4.sol
│ ├── WooCrossFee.sol
│ └── WooCrossRouterForWidget.sol
├── IntegrationHelper.sol
├── MasterChefReward.sol
├── MasterChefWoo.sol
├── Pauser.sol
├── WOOFiDex
│ ├── NonceCounter.sol
│ ├── WOOFiDexCrossChainRouter.sol
│ ├── WOOFiDexDepositor.sol
│ └── WOOFiDexTestVault.sol
├── WooAccessManager.sol
├── WooFeeManager.sol
├── WooPPV2.sol
├── WooPPV2_FS.sol
├── WooPPV3
│ ├── WooPPBase.sol
│ ├── WooPPV3.sol
│ ├── WooRouterV3.sol
│ ├── WooUsdOFT.sol
│ └── WooUsdOFTCrossRouter.sol
├── WooRebateManager.sol
├── WooRouterV2.sol
├── WooSimpleRewarder.sol
├── WooVaultManager.sol
├── earn
│ ├── DataProvider.sol
│ ├── VaultV2.sol
│ ├── WooLendingManager.sol
│ ├── WooLendingManagerV1_2.sol
│ ├── WooSuperChargerVaultV2.sol
│ ├── WooWithdrawManagerV2.sol
│ └── strategies
│ │ ├── Aave
│ │ ├── StrategyAave.sol
│ │ └── StrategyAaveBase.sol
│ │ ├── BaseStrategy.sol
│ │ └── VoidStrategy.sol
├── interfaces
│ ├── Aave
│ │ ├── IAaveDataProvider.sol
│ │ ├── IAavePool.sol
│ │ └── IAaveV3Incentives.sol
│ ├── AggregatorV3Interface.sol
│ ├── CrossChain
│ │ ├── ISgInfo.sol
│ │ ├── IWooCrossChainRouterV2.sol
│ │ ├── IWooCrossChainRouterV3.sol
│ │ ├── IWooCrossChainRouterV4.sol
│ │ ├── IWooCrossFee.sol
│ │ ├── IWooCrossRouterForWidget.sol
│ │ └── IWooUsdOFTCrossRouter.sol
│ ├── IDataProvider.sol
│ ├── IMasterChefReward.sol
│ ├── IMasterChefWoo.sol
│ ├── IPauser.sol
│ ├── IRewarder.sol
│ ├── IStrategy.sol
│ ├── IVaultV2.sol
│ ├── IWETH.sol
│ ├── IWooAccessManager.sol
│ ├── IWooFeeManager.sol
│ ├── IWooLendingManager.sol
│ ├── IWooPPV2.sol
│ ├── IWooPPV2ForTest.sol
│ ├── IWooPPV3.sol
│ ├── IWooRebateManager.sol
│ ├── IWooRouterV2.sol
│ ├── IWooRouterV3.sol
│ ├── IWooVaultManager.sol
│ ├── IWooracleV2.sol
│ ├── IWooracleV2_2.sol
│ ├── IWooracleV3.sol
│ ├── IXWoo.sol
│ ├── LayerZero
│ │ └── ILzApp.sol
│ ├── Stargate
│ │ ├── IStargateEthVault.sol
│ │ ├── IStargateReceiver.sol
│ │ └── IStargateRouter.sol
│ └── WOOFiDex
│ │ ├── INonceCounter.sol
│ │ ├── IWOOFiDexCrossChainRouter.sol
│ │ ├── IWOOFiDexDepositor.sol
│ │ └── IWOOFiDexVault.sol
├── libraries
│ └── TransferHelper.sol
├── test
│ ├── TestChainLink.sol
│ ├── TestERC20Token.sol
│ ├── TestUsdtToken.sol
│ └── WFTM.sol
└── wooracle
│ ├── WooracleV2.sol
│ ├── WooracleV2ZKSync.sol
│ ├── WooracleV2Zip.sol
│ ├── WooracleV2ZipInherit.sol
│ ├── WooracleV2_1.sol
│ ├── WooracleV2_1_ZKSync.sol
│ ├── WooracleV2_1_ZipInherit.sol
│ ├── WooracleV2_2.sol
│ ├── WooracleV3.sol
│ ├── WooracleV3ZKSync.sol
│ └── WooracleV3ZipInherit.sol
├── foundry.toml
├── funding.json
├── hardhat.config.ts
├── integration
└── WooPPV2.ts
├── package.json
├── scripts
├── DataProvider.ts
├── MasterChefReward.ts
├── MasterChefWoo.ts
├── WooAccessManager.ts
├── WooCrossChainRouter.ts
├── WooFeeManager.ts
├── WooPPV2.ts
├── WooRebateManager.ts
├── WooRouterV2.ts
├── WooSuperChargerVault.ts
├── WooVaultManager.ts
├── WooracleV2.ts
└── deploy.ts
├── test
├── foundry
│ ├── AMMTests.t.sol
│ ├── MockWETHOracle.t.sol
│ ├── MockWooOracle.t.sol
│ ├── SwapTests.sol
│ ├── TestDrainPool.t.sol
│ ├── TestHelpers.sol
│ └── TestWooracleV2_2.t.sol
└── typescript
│ ├── DataProvider.test.ts
│ ├── Integration_WooPP_Fee_Rebate_Vault.test.ts
│ ├── MasterChefWoo.test.ts
│ ├── WooAccessManager.test.ts
│ ├── WooCrossFee.test.ts
│ ├── WooFeeManager.test.ts
│ ├── WooPPv2.test.ts
│ ├── WooPPv3.test.ts
│ ├── WooRebateManager.test.ts
│ ├── WooRouterV2.test.ts
│ ├── WooRouterV3.test.ts
│ ├── WooSuperChargerVaultCornerCase.test.ts
│ ├── WooSuperChargerVaultIntegration1.test.ts
│ ├── WooSuperChargerVaultIntegration2.test.ts
│ ├── WooSuperChargerVaultIntegration3.test.ts
│ ├── WooSuperChargerVault_deposit.test.ts
│ ├── WooVaultManager.test.ts
│ ├── WooracleV2.test.ts
│ ├── WooracleV3.test.ts
│ ├── wooraclev2_zip_inherit.test.ts
│ ├── wooraclev2_zip_zksync.test.ts
│ ├── wooraclev3_zip_inherit.test.ts
│ └── wooraclev3_zip_zksync.test.ts
├── tsconfig.json
└── yarn.lock
/.commitlintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "@commitlint/config-conventional"
4 | ],
5 | "rules": {
6 | "subject-case": [
7 | 1,
8 | "always"
9 | ],
10 | "type-enum": [
11 | 2,
12 | "always",
13 | [
14 | "build",
15 | "ci",
16 | "chore",
17 | "docs",
18 | "feat",
19 | "fix",
20 | "perf",
21 | "refactor",
22 | "revert",
23 | "style",
24 | "test"
25 | ]
26 | ]
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | artifacts
3 | cache
4 | coverage*
5 | gasReporterOutput.json
6 | typechain
7 | lib*
8 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": false,
4 | "es2021": true,
5 | "mocha": true,
6 | "node": true
7 | },
8 | "plugins": ["@typescript-eslint"],
9 | "extends": [
10 | "standard",
11 | "plugin:@typescript-eslint/recommended",
12 | "plugin:prettier/recommended",
13 | "plugin:node/recommended"
14 | ],
15 | "parser": "@typescript-eslint/parser",
16 | "parserOptions": {
17 | "ecmaVersion": 12
18 | },
19 | "rules": {
20 | "node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }]
21 | },
22 | "settings": {
23 | "node": {
24 | "tryExtensions": [".js", ".json", ".ts", ".d.ts"]
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help improve this repo
4 | title: ""
5 | labels: ""
6 | assignees: ""
7 | ---
8 |
9 | - **Describe the bug**
10 | A clear and concise description of what the bug is.
11 |
12 | - **To reproduce**
13 | Steps to reproduce the behavior:
14 |
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | - **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | - **Additional context**
24 | Add any other context about the problem here.
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this repo
4 | title: ""
5 | labels: ""
6 | assignees: ""
7 | ---
8 |
9 | - **Is your feature request related to a problem? Please describe.**
10 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11 |
12 | - **Describe the solution you'd like**
13 | A clear and concise description of what you want to happen.
14 |
15 | - **Describe alternatives you've considered**
16 | A clear and concise description of any alternative solutions or features you've considered.
17 |
18 | - **Additional context**
19 | Add any other context or screenshots about the feature request here.
20 |
--------------------------------------------------------------------------------
/.github/workflows/checks.yaml:
--------------------------------------------------------------------------------
1 | name: Format and lint checks
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches:
7 | - main
8 |
9 | jobs:
10 | format:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Checkout code
14 | uses: actions/checkout@v2
15 | with:
16 | submodules: recursive
17 | - name: Setup Node
18 | uses: actions/setup-node@v3
19 | with:
20 | node-version: 14.x
21 | - name: Get yarn cache directory path
22 | id: yarn-cache-dir-path
23 | run: echo "::set-output name=dir::$(yarn cache dir)"
24 | - uses: actions/cache@v2
25 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
26 | with:
27 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
28 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
29 | restore-keys: |
30 | ${{ runner.os }}-yarn-
31 | - name: Install dependencies
32 | run: yarn install --frozen-lockfile
33 | - name: Compile code (Hardhat)
34 | run: yarn compile
35 | - name: Run format checks
36 | run: yarn format:check
37 |
--------------------------------------------------------------------------------
/.github/workflows/tests.yaml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches:
7 | - main
8 |
9 | jobs:
10 | tests:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - name: Checkout code
14 | uses: actions/checkout@v2
15 | with:
16 | submodules: recursive
17 | - name: Setup Node
18 | uses: actions/setup-node@v3
19 | with:
20 | node-version: 14.x
21 | - name: Get yarn cache directory path
22 | id: yarn-cache-dir-path
23 | run: echo "::set-output name=dir::$(yarn cache dir)"
24 | - uses: actions/cache@v2
25 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
26 | with:
27 | path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
28 | key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
29 | restore-keys: |
30 | ${{ runner.os }}-yarn-
31 | - name: Install dev dependencies
32 | run: yarn install --frozen-lockfile
33 | - name: Install Foundry
34 | uses: onbjerg/foundry-toolchain@v1
35 | with:
36 | version: nightly
37 | - name: Compile code (Hardhat)
38 | run: yarn compile:force
39 | - name: Run TypeScript/Waffle tests
40 | run: yarn test
41 | - name: Run Forge tests TestWooracleV2_2
42 | run: forge test --fork-url https://rpc.ankr.com/eth --match-contract TestWooracleV2_2 -vv
43 | - name: Run Forge tests SwapTests
44 | run: forge test --fork-url https://arb1.arbitrum.io/rpc --match-contract SwapTests -vv
45 | - name: Run Forge tests AMMTests
46 | run: forge test --fork-url https://arb1.arbitrum.io/rpc --match-contract AMMTests -vv
47 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .env
3 | .env*
4 | coverage
5 | coverage.json
6 | typechain
7 | .DS_Store
8 |
9 | # Hardhat files
10 | cache
11 | artifacts
12 | abis/
13 | artifacts-zk/
14 | cache-zk/
15 |
16 | package-lock.json
17 |
18 | .vscode
19 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "lib/forge-std"]
2 | path = lib/forge-std
3 | url = https://github.com/foundry-rs/forge-std
4 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | yarn commitlint --edit $1
5 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | # yarn lint
5 | # yarn format:check
6 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .env
3 | .env*
4 | coverage
5 | coverage.json
6 | typechain
7 |
8 | # Hardhat files
9 | cache
10 | artifacts
11 |
12 | hardhat.config.ts
13 | contracts/test
14 | test/
15 |
16 | # Others
17 | lib
18 | .DS_Store
19 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | artifacts
3 | cache
4 | coverage*
5 | gasReporterOutput.json
6 | typechain
7 | lib*
8 | test
9 |
10 | *.js
11 | *.ts
12 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 120
3 | }
4 |
--------------------------------------------------------------------------------
/.solcover.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | silent: true,
3 | measureStatementCoverage: true,
4 | measureFunctionCoverage: true,
5 | skipFiles: ["interfaces", "test"],
6 | configureYulOptimizer: true,
7 | };
8 |
--------------------------------------------------------------------------------
/.solhint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "solhint:recommended",
3 | "rules": {
4 | "compiler-version": ["error", "^0.8.0"],
5 | "func-visibility": [{ "ignoreConstructors": true }],
6 | "func-name-mixedcase": "off",
7 | "reason-string": "off",
8 | "var-name-mixedcase": "off"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/.solhintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | test
3 | demo.sol
4 | *.t.sol
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 WooTrade
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |

2 |
10 |
11 | ## WOOFi Swap V2.0
12 |
13 | This repository contains the smart contracts and solidity library for the WOOFi swap. WOOFi Swap is a decentralized exchange using a brand new on-chain market making algorithm called Synthetic Proactive Market Making version 2 (sPMM v2), which is designed for professional market makers to generate an on-chain orderbook simulating the price, spread and depth from centralized liquidity sources. Read more here.
14 |
15 | ## Security
16 |
17 | #### Bug Bounty
18 |
19 | Bug bounty for the smart contracts: [Bug Bounty](https://learn.woo.org/woofi/woofi-swap/bug-bounty).
20 |
21 | #### Security Audit
22 |
23 | 3rd party security audit: [Audit Report](https://learn.woo.org/woofi/woofi-swap/audits).
24 |
25 | #### Run
26 |
27 | ```shell
28 | yarn
29 | npx hardhat compile
30 | npx hardhat test
31 | ```
32 |
--------------------------------------------------------------------------------
/contracts/CrossChain/SgInfo.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5 | import "../interfaces/CrossChain/ISgInfo.sol";
6 |
7 | /// @title cross chain router implementation, version 3.
8 | /// @notice Router for stateless execution of cross chain swap against WOOFi or 1inch swap.
9 | /// @custom:stargate-contracts https://stargateprotocol.gitbook.io/stargate/developers/contract-addresses/mainnet
10 | contract SgInfo is ISgInfo, Ownable {
11 | mapping(uint16 => address) public sgETHs; // chainId => SGETH token address
12 |
13 | mapping(uint16 => mapping(address => uint256)) public sgPoolIds; // chainId => token address => Stargate poolId
14 |
15 | address public sgRouter;
16 | uint16 public sgChainIdLocal; // Stargate chainId on local chain
17 |
18 | constructor(address _sgRouter, uint16 _sgChainIdLocal) {
19 | sgRouter = _sgRouter;
20 | sgChainIdLocal = _sgChainIdLocal;
21 | _initSgETHs();
22 | _initSgPoolIds();
23 | }
24 |
25 | function _initSgETHs() internal {
26 | // Ethereum
27 | sgETHs[101] = 0x72E2F4830b9E45d52F80aC08CB2bEC0FeF72eD9c;
28 | // Arbitrum
29 | sgETHs[110] = 0x82CbeCF39bEe528B5476FE6d1550af59a9dB6Fc0;
30 | // Optimism
31 | sgETHs[111] = 0xb69c8CBCD90A39D8D3d3ccf0a3E968511C3856A0;
32 | // Linea
33 | sgETHs[183] = 0x224D8Fd7aB6AD4c6eb4611Ce56EF35Dec2277F03;
34 | // Base
35 | sgETHs[184] = 0x224D8Fd7aB6AD4c6eb4611Ce56EF35Dec2277F03;
36 | }
37 |
38 | function _initSgPoolIds() internal {
39 | // poolId > 0 means able to be bridge token
40 | // Ethereum
41 | sgPoolIds[101][0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48] = 1; // USDC
42 | sgPoolIds[101][0xdAC17F958D2ee523a2206206994597C13D831ec7] = 2; // USDT
43 | sgPoolIds[101][0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2] = 13; // WETH
44 | sgPoolIds[101][0x4691937a7508860F876c9c0a2a617E7d9E945D4B] = 20; // WOO
45 | // BNB Chain
46 | sgPoolIds[102][0x55d398326f99059fF775485246999027B3197955] = 2; // USDT
47 | sgPoolIds[102][0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56] = 5; // BUSD
48 | sgPoolIds[102][0x4691937a7508860F876c9c0a2a617E7d9E945D4B] = 20; // WOO
49 | // Avalanche
50 | sgPoolIds[106][0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E] = 1; // USDC
51 | sgPoolIds[106][0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7] = 2; // USDT
52 | sgPoolIds[106][0xaBC9547B534519fF73921b1FBA6E672b5f58D083] = 20; // WOO
53 | // Polygon
54 | sgPoolIds[109][0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174] = 1; // USDC
55 | sgPoolIds[109][0xc2132D05D31c914a87C6611C10748AEb04B58e8F] = 2; // USDT
56 | sgPoolIds[109][0x1B815d120B3eF02039Ee11dC2d33DE7aA4a8C603] = 20; // WOO
57 | // Arbitrum
58 | sgPoolIds[110][0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8] = 1; // USDC
59 | sgPoolIds[110][0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9] = 2; // USDT
60 | sgPoolIds[110][0x82aF49447D8a07e3bd95BD0d56f35241523fBab1] = 13; // WETH
61 | sgPoolIds[110][0xcAFcD85D8ca7Ad1e1C6F82F651fA15E33AEfD07b] = 20; // WOO
62 | // Optimism
63 | sgPoolIds[111][0x7F5c764cBc14f9669B88837ca1490cCa17c31607] = 1; // USDC
64 | sgPoolIds[111][0x4200000000000000000000000000000000000006] = 13; // WETH
65 | sgPoolIds[111][0x871f2F2ff935FD1eD867842FF2a7bfD051A5E527] = 20; // WOO
66 | // Fantom
67 | sgPoolIds[112][0x04068DA6C83AFCFA0e13ba15A6696662335D5B75] = 1; // USDC
68 | sgPoolIds[112][0x6626c47c00F1D87902fc13EECfaC3ed06D5E8D8a] = 20; // WOO
69 | // Linea
70 | sgPoolIds[183][0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f] = 13; // WETH
71 | // Base
72 | sgPoolIds[184][0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA] = 1; // USDC
73 | sgPoolIds[184][0x4200000000000000000000000000000000000006] = 13; // WETH
74 | }
75 |
76 | function setSgETH(uint16 chainId, address token) external onlyOwner {
77 | sgETHs[chainId] = token;
78 | }
79 |
80 | function setSgPoolId(
81 | uint16 chainId,
82 | address token,
83 | uint256 poolId
84 | ) external onlyOwner {
85 | sgPoolIds[chainId][token] = poolId;
86 | }
87 |
88 | function setSgRouter(address _sgRouter) external onlyOwner {
89 | sgRouter = _sgRouter;
90 | }
91 |
92 | function setSgChainIdLocal(uint16 _sgChainIdLocal) external onlyOwner {
93 | sgChainIdLocal = _sgChainIdLocal;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/contracts/IntegrationHelper.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | // OpenZeppelin Contracts
38 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
39 | import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
40 |
41 | contract IntegrationHelper is Ownable {
42 | using EnumerableSet for EnumerableSet.AddressSet;
43 |
44 | address public quoteToken;
45 | EnumerableSet.AddressSet private baseTokens;
46 |
47 | constructor(address _quoteToken, address[] memory _baseTokens) {
48 | quoteToken = _quoteToken;
49 |
50 | unchecked {
51 | for (uint256 i = 0; i < _baseTokens.length; ++i) {
52 | baseTokens.add(_baseTokens[i]);
53 | }
54 | }
55 | }
56 |
57 | function getSupportTokens() external view returns (address, address[] memory) {
58 | return (quoteToken, allBaseTokens());
59 | }
60 |
61 | function allBaseTokensLength() external view returns (uint256) {
62 | return baseTokens.length();
63 | }
64 |
65 | function allBaseTokens() public view returns (address[] memory) {
66 | uint256 length = baseTokens.length();
67 | address[] memory tokens = new address[](length);
68 | unchecked {
69 | for (uint256 i = 0; i < length; ++i) {
70 | tokens[i] = baseTokens.at(i);
71 | }
72 | }
73 | return tokens;
74 | }
75 |
76 | function setQutoeToken(address _quoteToken) external onlyOwner {
77 | quoteToken = _quoteToken;
78 | }
79 |
80 | function addBaseToken(address token) external onlyOwner {
81 | bool success = baseTokens.add(token);
82 | require(success, "IntegrationHelper: token exist");
83 | }
84 |
85 | function removeBaseToken(address token) external onlyOwner {
86 | bool success = baseTokens.remove(token);
87 | require(success, "IntegrationHelper: token not exist");
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/contracts/Pauser.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
38 |
39 | import {IPauser, IPauseContract} from "./interfaces/IPauser.sol";
40 |
41 | contract Pauser is IPauser, Ownable {
42 | mapping(address => bool) public isPauseRole;
43 | mapping(address => bool) public isUnpauseRole;
44 |
45 | modifier onlyPauseRole() {
46 | require(msg.sender == owner() || isPauseRole[msg.sender], "Pauser: not pause role");
47 | _;
48 | }
49 |
50 | modifier onlyUnpauseRole() {
51 | require(msg.sender == owner() || isUnpauseRole[msg.sender], "Pauser: not unpause role");
52 | _;
53 | }
54 |
55 | function pause(address pauseContract) external onlyPauseRole {
56 | IPauseContract(pauseContract).pause();
57 | }
58 |
59 | function unpause(address unpauseContract) external onlyUnpauseRole {
60 | IPauseContract(unpauseContract).unpause();
61 | }
62 |
63 | function setPauseRole(address addr, bool flag) external onlyOwner {
64 | isPauseRole[addr] = flag;
65 | emit PauseRoleUpdated(addr, flag);
66 | }
67 |
68 | function setUnpauseRole(address addr, bool flag) external onlyOwner {
69 | isUnpauseRole[addr] = flag;
70 | emit UnpauseRoleUpdated(addr, flag);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/contracts/WOOFiDex/NonceCounter.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5 |
6 | import {INonceCounter} from "../interfaces/WOOFiDex/INonceCounter.sol";
7 |
8 | contract NonceCounter is INonceCounter, Ownable {
9 | /* ----- State Variables ----- */
10 |
11 | mapping(address => bool) public isCrossChainRouter;
12 | mapping(uint16 => uint256) public outboundNonce;
13 |
14 | /* ----- Modifiers ----- */
15 |
16 | modifier onlyCrossChainRouter() {
17 | require(isCrossChainRouter[_msgSender()], "NonceCounter: not crossChainRouter");
18 | _;
19 | }
20 |
21 | /* ----- Functions ----- */
22 |
23 | function setCrossChainRouter(address crossChainRouter, bool flag) external onlyOwner {
24 | isCrossChainRouter[crossChainRouter] = flag;
25 | emit CrossChainRouterUpdated(crossChainRouter, flag);
26 | }
27 |
28 | function increment(uint16 dstChainId) external override onlyCrossChainRouter returns (uint256) {
29 | return ++outboundNonce[dstChainId];
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/contracts/WOOFiDex/WOOFiDexTestVault.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | // OpenZeppelin Contracts
5 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
7 | import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
8 |
9 | // Uniswap Periphery
10 | import {TransferHelper} from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
11 |
12 | // Local Contracts
13 | import {IWOOFiDexVault} from "../interfaces/WOOFiDex/IWOOFiDexVault.sol";
14 |
15 | contract WOOFiDexTestVault is IWOOFiDexVault, Ownable, Pausable {
16 | address public constant NATIVE_PLACEHOLDER = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
17 |
18 | address public token;
19 | uint64 public depositId;
20 |
21 | constructor(address _token) {
22 | token = _token;
23 | }
24 |
25 | function depositTo(address receiver, VaultDepositFE calldata data) external payable whenNotPaused {
26 | if (token == NATIVE_PLACEHOLDER) {
27 | TransferHelper.safeTransferETH(receiver, msg.value);
28 | } else {
29 | TransferHelper.safeTransferFrom(token, _msgSender(), receiver, data.tokenAmount);
30 | }
31 | _newDepositId();
32 | emit AccountDepositTo(data.accountId, receiver, depositId, data.tokenHash, data.tokenAmount);
33 | }
34 |
35 | function _newDepositId() internal returns (uint64) {
36 | return ++depositId;
37 | }
38 |
39 | function inCaseTokenGotStuck(address _token) external onlyOwner {
40 | address msgSender = _msgSender();
41 | if (_token == NATIVE_PLACEHOLDER) {
42 | TransferHelper.safeTransferETH(msgSender, address(this).balance);
43 | } else {
44 | uint256 bal = IERC20(_token).balanceOf(address(this));
45 | TransferHelper.safeTransfer(_token, msgSender, bal);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/contracts/WooAccessManager.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | import "./interfaces/IWooAccessManager.sol";
38 |
39 | import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
40 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
41 |
42 | contract WooAccessManager is IWooAccessManager, Ownable, Pausable {
43 | /* ----- State variables ----- */
44 |
45 | mapping(address => bool) public override isFeeAdmin;
46 | mapping(address => bool) public override isVaultAdmin;
47 | mapping(address => bool) public override isRebateAdmin;
48 | mapping(address => bool) public override isZeroFeeVault;
49 |
50 | /* ----- Admin Functions ----- */
51 |
52 | /// @inheritdoc IWooAccessManager
53 | function setFeeAdmin(address feeAdmin, bool flag) external override onlyOwner whenNotPaused {
54 | require(feeAdmin != address(0), "WooAccessManager: feeAdmin_ZERO_ADDR");
55 | isFeeAdmin[feeAdmin] = flag;
56 | emit FeeAdminUpdated(feeAdmin, flag);
57 | }
58 |
59 | /// @inheritdoc IWooAccessManager
60 | function setVaultAdmin(address vaultAdmin, bool flag) external override onlyOwner whenNotPaused {
61 | require(vaultAdmin != address(0), "WooAccessManager: vaultAdmin_ZERO_ADDR");
62 | isVaultAdmin[vaultAdmin] = flag;
63 | emit VaultAdminUpdated(vaultAdmin, flag);
64 | }
65 |
66 | /// @inheritdoc IWooAccessManager
67 | function setRebateAdmin(address rebateAdmin, bool flag) external override onlyOwner whenNotPaused {
68 | require(rebateAdmin != address(0), "WooAccessManager: rebateAdmin_ZERO_ADDR");
69 | isRebateAdmin[rebateAdmin] = flag;
70 | emit RebateAdminUpdated(rebateAdmin, flag);
71 | }
72 |
73 | /// @inheritdoc IWooAccessManager
74 | function setZeroFeeVault(address vault, bool flag) external override onlyOwner whenNotPaused {
75 | require(vault != address(0), "WooAccessManager: vault_ZERO_ADDR");
76 | isZeroFeeVault[vault] = flag;
77 | emit ZeroFeeVaultUpdated(vault, flag);
78 | }
79 |
80 | /// @notice Pause the contract.
81 | function pause() external onlyOwner {
82 | super._pause();
83 | }
84 |
85 | /// @notice Restart the contract.
86 | function unpause() external onlyOwner {
87 | super._unpause();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/contracts/WooPPV3/WooPPBase.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.4;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
38 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
39 | import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
40 | import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
41 |
42 | import {TransferHelper} from "../libraries/TransferHelper.sol";
43 |
44 | abstract contract WooPPBase is Pausable, Ownable, ReentrancyGuard {
45 | event AdminUpdated(address indexed addr, bool flag);
46 | event FeeAddrUpdated(address indexed newFeeAddr);
47 | event WooracleUpdated(address indexed newWooracle);
48 |
49 | address public constant ETH_PLACEHOLDER_ADDR = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
50 |
51 | mapping(address => bool) public isAdmin;
52 |
53 | address public wooracle;
54 | address public feeAddr;
55 |
56 | constructor(address _wooracle, address _feeAddr) {
57 | wooracle = _wooracle;
58 | feeAddr = _feeAddr;
59 | }
60 |
61 | modifier onlyAdmin() {
62 | require(_msgSender() == owner() || isAdmin[_msgSender()], "WooPPBase: !admin");
63 | _;
64 | }
65 |
66 | function setWooracle(address _wooracle) external onlyAdmin {
67 | wooracle = _wooracle;
68 | emit WooracleUpdated(_wooracle);
69 | }
70 |
71 | function setFeeAddr(address _feeAddr) external onlyAdmin {
72 | feeAddr = _feeAddr;
73 | emit FeeAddrUpdated(_feeAddr);
74 | }
75 |
76 | function pause() public onlyAdmin {
77 | _pause();
78 | }
79 |
80 | function unpause() public onlyAdmin {
81 | _unpause();
82 | }
83 |
84 | function setAdmin(address addr, bool flag) public onlyAdmin {
85 | isAdmin[addr] = flag;
86 | emit AdminUpdated(addr, flag);
87 | }
88 |
89 | /// @dev User pool balance (substracted unclaimed fee)
90 | function balance(address token) public view virtual returns (uint256) {
91 | // WooPP V2 code:
92 | // return token == quoteToken ? _rawBalance(token) - unclaimedFee : _rawBalance(token);
93 | return _rawBalance(token);
94 | }
95 |
96 | /// @dev Get the pool's balance of the specified token
97 | /// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize
98 | /// @dev forked and curtesy by Uniswap v3 core
99 | function _rawBalance(address token) internal view returns (uint256) {
100 | (bool success, bytes memory data) = token.staticcall(
101 | abi.encodeWithSelector(IERC20.balanceOf.selector, address(this))
102 | );
103 | require(success && data.length >= 32, "IWooPPV3: !BALANCE");
104 | return abi.decode(data, (uint256));
105 | }
106 |
107 | function inCaseTokenGotStuck(address stuckToken) external onlyOwner {
108 | if (stuckToken == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
109 | TransferHelper.safeTransferETH(_msgSender(), address(this).balance);
110 | } else {
111 | uint256 amount = IERC20(stuckToken).balanceOf(address(this));
112 | TransferHelper.safeTransfer(stuckToken, _msgSender(), amount);
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/contracts/WooPPV3/WooUsdOFT.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 | import {OFTV2} from "@layerzerolabs/solidity-examples/contracts/token/oft/v2/OFTV2.sol";
37 |
38 | /// @title Woo Cross Chain Router
39 | contract WooUsdOFT is OFTV2 {
40 | event WooPPUpdated(address indexed addr, bool flag);
41 |
42 | mapping(address => bool) public isWooPP;
43 |
44 | bool public mintAllowed;
45 | bool public burnAllowed;
46 |
47 | modifier onlyWooPPAllowed() {
48 | require(isWooPP[_msgSender()], "WooUsdOFT: !allowed");
49 | _;
50 | }
51 |
52 | constructor(
53 | string memory _name,
54 | string memory _symbol,
55 | address _lzEndpoint
56 | ) OFTV2(_name, _symbol, decimals(), _lzEndpoint) {
57 | mintAllowed = true;
58 | burnAllowed = true;
59 | }
60 |
61 | function decimals() public pure override returns (uint8) {
62 | return 6;
63 | }
64 |
65 | function mint(address _user, uint256 _amount) public onlyWooPPAllowed {
66 | require(mintAllowed, "WooUsdOFT: !mintAllowed");
67 | _mint(_user, _amount);
68 | }
69 |
70 | function burn(address _user, uint256 _amount) public onlyWooPPAllowed {
71 | require(burnAllowed, "WooUsdOFT: !burnAllowed");
72 | _burn(_user, _amount);
73 | }
74 |
75 | function setWooPP(address _wooPP, bool _flag) public onlyOwner {
76 | isWooPP[_wooPP] = _flag;
77 | emit WooPPUpdated(_wooPP, _flag);
78 | }
79 |
80 | function setMintAllowed(bool _mintAllowed) external onlyOwner {
81 | mintAllowed = _mintAllowed;
82 | }
83 |
84 | function setBurnAllowed(bool _burnAllowed) external onlyOwner {
85 | burnAllowed = _burnAllowed;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/contracts/earn/WooWithdrawManagerV2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 | * SOFTWARE.
36 | */
37 |
38 | import "../interfaces/IWETH.sol";
39 | import "../interfaces/IWooAccessManager.sol";
40 |
41 | import "../libraries/TransferHelper.sol";
42 |
43 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
44 | import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
45 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
46 | import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
47 |
48 | contract WooWithdrawManagerV2 is Ownable, ReentrancyGuard {
49 | // addedAmount: added withdrawal amount for this user
50 | // totalAmount: total withdrawal amount for this user
51 | event WithdrawAdded(address indexed user, uint256 addedAmount, uint256 totalAmount);
52 |
53 | event Withdraw(address indexed user, uint256 amount);
54 |
55 | address public want;
56 | address public weth;
57 | address public accessManager;
58 | address public superChargerVault;
59 |
60 | mapping(address => uint256) public withdrawAmount;
61 |
62 | address constant ETH_PLACEHOLDER_ADDR = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
63 |
64 | constructor() {}
65 |
66 | function init(
67 | address _weth,
68 | address _want,
69 | address _accessManager,
70 | address _superChargerVault
71 | ) external onlyOwner {
72 | weth = _weth;
73 | want = _want;
74 | accessManager = _accessManager;
75 | superChargerVault = _superChargerVault;
76 | }
77 |
78 | modifier onlyAdmin() {
79 | require(
80 | owner() == msg.sender || IWooAccessManager(accessManager).isVaultAdmin(msg.sender),
81 | "WooWithdrawManager: !owner"
82 | );
83 | _;
84 | }
85 |
86 | modifier onlySuperChargerVault() {
87 | require(superChargerVault == msg.sender, "WooWithdrawManager: !superChargerVault");
88 | _;
89 | }
90 |
91 | function setSuperChargerVault(address _superChargerVault) external onlyAdmin {
92 | superChargerVault = _superChargerVault;
93 | }
94 |
95 | function addWithdrawAmount(address user, uint256 amount) external onlySuperChargerVault {
96 | // NOTE: in V2, granular token transfer is avoided to save the gas consumption;
97 | // Do remember batch transfer the total amount of `want` tokens after calling this method.
98 |
99 | // TransferHelper.safeTransferFrom(want, msg.sender, address(this), amount);
100 | withdrawAmount[user] = withdrawAmount[user] + amount;
101 | emit WithdrawAdded(user, amount, withdrawAmount[user]);
102 | }
103 |
104 | function withdraw() external nonReentrant {
105 | uint256 amount = withdrawAmount[msg.sender];
106 | if (amount == 0) {
107 | return;
108 | }
109 | withdrawAmount[msg.sender] = 0;
110 | if (want == weth) {
111 | IWETH(weth).withdraw(amount);
112 | TransferHelper.safeTransferETH(msg.sender, amount);
113 | } else {
114 | TransferHelper.safeTransfer(want, msg.sender, amount);
115 | }
116 | emit Withdraw(msg.sender, amount);
117 | }
118 |
119 | function inCaseTokenGotStuck(address stuckToken) external onlyOwner {
120 | require(stuckToken != want);
121 | if (stuckToken == ETH_PLACEHOLDER_ADDR) {
122 | TransferHelper.safeTransferETH(msg.sender, address(this).balance);
123 | } else {
124 | uint256 amount = IERC20(stuckToken).balanceOf(address(this));
125 | TransferHelper.safeTransfer(stuckToken, msg.sender, amount);
126 | }
127 | }
128 |
129 | receive() external payable {}
130 | }
131 |
--------------------------------------------------------------------------------
/contracts/earn/strategies/Aave/StrategyAaveBase.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity 0.8.14;
3 |
4 | import "../BaseStrategy.sol";
5 | import "../../../libraries/TransferHelper.sol";
6 |
7 | import "../../../interfaces/Aave/IAavePool.sol";
8 | import "../../../interfaces/Aave/IAaveV3Incentives.sol";
9 | import "../../../interfaces/Aave/IAaveDataProvider.sol";
10 |
11 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
12 | import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
13 |
14 | contract StrategyAaveBase is BaseStrategy {
15 | using SafeERC20 for IERC20;
16 |
17 | /* ----- State Variables ----- */
18 |
19 | address[] public rewardAssets;
20 | address[] public aAssets = new address[](1);
21 | address public rewardTreasury;
22 | uint256 public lastHarvest;
23 |
24 | /* ----- Constant Variables ----- */
25 |
26 | address public constant aavePool = address(0xA238Dd80C259a72e81d7e4664a9801593F98d1c5); // Aave: Pool V3
27 | address public constant incentivesController = address(0xf9cc4F0D883F1a1eb2c253bdb46c254Ca51E1F44); // Aave: Incentives V3
28 | address public constant dataProvider = address(0x2d8A3C5677189723C4cB8873CfC9C8976FDF38Ac); // Aave: Pool Data Provider V3
29 |
30 | /* ----- Events ----- */
31 |
32 | event Deposit(uint256 tvl);
33 | event Withdraw(uint256 tvl);
34 |
35 | constructor(
36 | address _vault,
37 | address _accessManager,
38 | address _rewardTreasury
39 | ) BaseStrategy(_vault, _accessManager) {
40 | rewardAssets = IAaveV3Incentives(incentivesController).getRewardsList();
41 | (address aToken, , ) = IAaveDataProvider(dataProvider).getReserveTokensAddresses(want);
42 | aAssets[0] = aToken;
43 | rewardTreasury = _rewardTreasury;
44 |
45 | _giveAllowances();
46 | }
47 |
48 | /* ----- External Functions ----- */
49 |
50 | /* ----- Public Functions ----- */
51 |
52 | function harvest() public override whenNotPaused {
53 | require(msg.sender == tx.origin || msg.sender == address(vault), "StrategyAaveBase: EOA_or_vault");
54 |
55 | // claim all rewards to the vault
56 | IAaveV3Incentives(incentivesController).claimAllRewards(aAssets, rewardTreasury);
57 | }
58 |
59 | function deposit() public override whenNotPaused nonReentrant {
60 | uint256 wantBal = balanceOfWant();
61 |
62 | if (wantBal > 0) {
63 | IAavePool(aavePool).deposit(want, wantBal, address(this), 0);
64 | emit Deposit(balanceOf());
65 | }
66 | }
67 |
68 | function withdraw(uint256 amount) public override nonReentrant {
69 | require(msg.sender == vault, "StrategyAaveBase: !vault");
70 | require(amount > 0, "StrategyAaveBase: !amount");
71 |
72 | uint256 wantBal = balanceOfWant();
73 |
74 | if (wantBal < amount) {
75 | IAavePool(aavePool).withdraw(want, amount - wantBal, address(this));
76 | uint256 newWantBal = IERC20(want).balanceOf(address(this));
77 | require(newWantBal > wantBal, "StrategyAaveBase: !newWantBal");
78 | wantBal = newWantBal;
79 | }
80 |
81 | uint256 withdrawAmt = amount < wantBal ? amount : wantBal;
82 |
83 | uint256 fee = chargeWithdrawalFee(withdrawAmt);
84 | if (withdrawAmt > fee) {
85 | TransferHelper.safeTransfer(want, vault, withdrawAmt - fee);
86 | }
87 | emit Withdraw(balanceOf());
88 | }
89 |
90 | function userReserves() public view returns (uint256, uint256) {
91 | (uint256 supplyBal, , uint256 borrowBal, , , , , , ) = IAaveDataProvider(dataProvider).getUserReserveData(
92 | want,
93 | address(this)
94 | );
95 | return (supplyBal, borrowBal);
96 | }
97 |
98 | function balanceOfPool() public view override returns (uint256) {
99 | (uint256 supplyBal, uint256 borrowBal) = userReserves();
100 | return supplyBal - borrowBal;
101 | }
102 |
103 | /* ----- Internal Functions ----- */
104 |
105 | function _giveAllowances() internal override {
106 | TransferHelper.safeApprove(want, aavePool, type(uint256).max);
107 | }
108 |
109 | function _removeAllowances() internal override {
110 | TransferHelper.safeApprove(want, aavePool, 0);
111 | }
112 |
113 | function _withdrawAll() internal {
114 | if (balanceOfPool() > 0) {
115 | IAavePool(aavePool).withdraw(want, type(uint256).max, address(this));
116 | }
117 | }
118 |
119 | /* ----- Admin Functions ----- */
120 |
121 | function retireStrat() external override {
122 | require(msg.sender == vault, "StrategyAaveBase: !vault");
123 | _withdrawAll();
124 | uint256 wantBal = IERC20(want).balanceOf(address(this));
125 | if (wantBal > 0) {
126 | TransferHelper.safeTransfer(want, vault, wantBal);
127 | }
128 | }
129 |
130 | function emergencyExit() external override onlyAdminOrPauseRole {
131 | _withdrawAll();
132 | uint256 wantBal = IERC20(want).balanceOf(address(this));
133 | if (wantBal > 0) {
134 | TransferHelper.safeTransfer(want, vault, wantBal);
135 | }
136 | }
137 |
138 | function updateRewardTreasury(address addr) external onlyAdmin {
139 | require(addr != address(0), "StrategyAaveBase: !rewardTreasury");
140 | rewardTreasury = addr;
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/contracts/earn/strategies/VoidStrategy.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity 0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 | * SOFTWARE.
36 | */
37 |
38 | import "./BaseStrategy.sol";
39 |
40 | import {Address} from "@openzeppelin/contracts/utils/Address.sol";
41 |
42 | contract VoidStrategy is BaseStrategy {
43 | using Address for address;
44 |
45 | constructor(address _vault, address _accessManager) BaseStrategy(_vault, _accessManager) {
46 | _giveAllowances();
47 | }
48 |
49 | /* ----- External Functions ----- */
50 |
51 | function withdraw(uint256 amount) external override nonReentrant {
52 | require(msg.sender == vault, "VoidStrategy: !vault");
53 |
54 | uint256 wantBalance = IERC20(want).balanceOf(address(this));
55 | uint256 withdrawAmount = amount < wantBalance ? amount : wantBalance;
56 |
57 | uint256 fee = chargeWithdrawalFee(withdrawAmount);
58 | if (withdrawAmount > fee) {
59 | TransferHelper.safeTransfer(want, vault, withdrawAmount - fee);
60 | }
61 | }
62 |
63 | function harvest() public override whenNotPaused {
64 | require(!msg.sender.isContract() || msg.sender == vault, "VoidStrategy: EOA_OR_VAULT");
65 | deposit();
66 | }
67 |
68 | function deposit() public override whenNotPaused nonReentrant {}
69 |
70 | function balanceOfPool() public pure override returns (uint256) {
71 | return 0;
72 | }
73 |
74 | /* ----- Private Functions ----- */
75 |
76 | function _giveAllowances() internal override {}
77 |
78 | function _removeAllowances() internal override {}
79 |
80 | function retireStrat() external override {
81 | require(msg.sender == vault, "!vault");
82 | uint256 wantBalance = IERC20(want).balanceOf(address(this));
83 | if (wantBalance > 0) {
84 | TransferHelper.safeTransfer(want, vault, wantBalance);
85 | }
86 | }
87 |
88 | function emergencyExit() external override onlyAdmin {
89 | uint256 wantBalance = IERC20(want).balanceOf(address(this));
90 | if (wantBalance > 0) {
91 | TransferHelper.safeTransfer(want, vault, wantBalance);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/contracts/interfaces/Aave/IAaveDataProvider.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity 0.8.14;
3 |
4 | interface IAaveDataProvider {
5 | function getReserveTokensAddresses(address asset)
6 | external
7 | view
8 | returns (
9 | address aTokenAddress,
10 | address stableDebtTokenAddress,
11 | address variableDebtTokenAddress
12 | );
13 |
14 | function getUserReserveData(address asset, address user)
15 | external
16 | view
17 | returns (
18 | uint256 currentATokenBalance,
19 | uint256 currentStableDebt,
20 | uint256 currentVariableDebt,
21 | uint256 principalStableDebt,
22 | uint256 scaledVariableDebt,
23 | uint256 stableBorrowRate,
24 | uint256 liquidityRate,
25 | uint40 stableRateLastUpdated,
26 | bool usageAsCollateralEnabled
27 | );
28 | }
29 |
--------------------------------------------------------------------------------
/contracts/interfaces/Aave/IAavePool.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity 0.8.14;
3 |
4 | interface IAavePool {
5 | function deposit(
6 | address asset,
7 | uint256 amount,
8 | address onBehalfOf,
9 | uint16 referralCode
10 | ) external;
11 |
12 | function borrow(
13 | address asset,
14 | uint256 amount,
15 | uint256 interestRateMode,
16 | uint16 referralCode,
17 | address onBehalfOf
18 | ) external;
19 |
20 | function repay(
21 | address asset,
22 | uint256 amount,
23 | uint256 rateMode,
24 | address onBehalfOf
25 | ) external returns (uint256);
26 |
27 | function withdraw(
28 | address asset,
29 | uint256 amount,
30 | address to
31 | ) external returns (uint256);
32 |
33 | function getUserAccountData(address user)
34 | external
35 | view
36 | returns (
37 | uint256 totalCollateralETH,
38 | uint256 totalDebtETH,
39 | uint256 availableBorrowsETH,
40 | uint256 currentLiquidationThreshold,
41 | uint256 ltv,
42 | uint256 healthFactor
43 | );
44 |
45 | function setUserEMode(uint8 categoryId) external;
46 |
47 | function getUserEMode(address user) external view returns (uint256);
48 |
49 | function getEModeCategoryData(uint8 categoryId)
50 | external
51 | view
52 | returns (
53 | uint16 ltv,
54 | uint16 liquidationThreshold,
55 | uint16 liquidationBonus,
56 | address priceSource,
57 | string memory label
58 | );
59 | }
60 |
--------------------------------------------------------------------------------
/contracts/interfaces/Aave/IAaveV3Incentives.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity 0.8.14;
3 |
4 | interface IAaveV3Incentives {
5 | /**
6 | * @dev Returns the list of available reward addresses
7 | * @return List of rewards supported in this contract
8 | **/
9 | function getRewardsList() external view returns (address[] memory);
10 |
11 | /**
12 | * @dev Claims reward for a user to the desired address, on all the assets of the pool, accumulating the pending rewards
13 | * @param assets List of assets to check eligible distributions before claiming rewards
14 | * @param amount The amount of rewards to claim
15 | * @param to The address that will be receiving the rewards
16 | * @param reward The address of the reward token
17 | * @return The amount of rewards claimed
18 | **/
19 | function claimRewards(
20 | address[] calldata assets,
21 | uint256 amount,
22 | address to,
23 | address reward
24 | ) external returns (uint256);
25 |
26 | /**
27 | * @dev Claims all rewards for a user to the desired address, on all the assets of the pool, accumulating the pending rewards
28 | * @param assets The list of assets to check eligible distributions before claiming rewards
29 | * @param to The address that will be receiving the rewards
30 | * @return rewardsList List of addresses of the reward tokens
31 | * @return claimedAmounts List that contains the claimed amount per reward, following same order as "rewardList"
32 | **/
33 | function claimAllRewards(address[] calldata assets, address to)
34 | external
35 | returns (address[] memory rewardsList, uint256[] memory claimedAmounts);
36 | }
37 |
--------------------------------------------------------------------------------
/contracts/interfaces/AggregatorV3Interface.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface AggregatorV3Interface {
5 | function decimals() external view returns (uint8);
6 |
7 | function description() external view returns (string memory);
8 |
9 | function version() external view returns (uint256);
10 |
11 | /// getRoundData and latestRoundData should both raise "No data present"
12 | /// if they do not have data to report, instead of returning unset values
13 | /// which could be misinterpreted as actual reported values.
14 | function getRoundData(uint80 _roundId)
15 | external
16 | view
17 | returns (
18 | uint80 roundId,
19 | int256 answer,
20 | uint256 startedAt,
21 | uint256 updatedAt,
22 | uint80 answeredInRound
23 | );
24 |
25 | function latestRoundData()
26 | external
27 | view
28 | returns (
29 | uint80 roundId,
30 | int256 answer,
31 | uint256 startedAt,
32 | uint256 updatedAt,
33 | uint80 answeredInRound
34 | );
35 | }
36 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/ISgInfo.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title WOOFi cross fee.
38 | interface ISgInfo {
39 | /* ----- State Variables ----- */
40 |
41 | function sgRouter() external view returns (address sgRouter);
42 |
43 | function sgChainIdLocal() external view returns (uint16 sgChainIdLocal);
44 |
45 | function sgPoolIds(uint16 _chainId, address _addr) external view returns (uint256 sgPoolId);
46 |
47 | function sgETHs(uint16 _chainId) external view returns (address sgETH);
48 | }
49 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/IWooCrossChainRouterV2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title WOOFi cross chain router interface (version 2).
38 | /// @notice functions to interface with WOOFi cross chain swap.
39 | interface IWooCrossChainRouterV2 {
40 | /* ----- Structs ----- */
41 |
42 | struct SrcInfos {
43 | address fromToken;
44 | address bridgeToken;
45 | uint256 fromAmount;
46 | uint256 minBridgeAmount;
47 | }
48 |
49 | struct DstInfos {
50 | uint16 chainId;
51 | address toToken;
52 | address bridgeToken;
53 | uint256 minToAmount;
54 | uint256 airdropNativeAmount;
55 | }
56 |
57 | /* ----- Events ----- */
58 |
59 | event WooCrossSwapOnSrcChain(
60 | uint256 indexed refId,
61 | address indexed sender,
62 | address indexed to,
63 | address fromToken,
64 | uint256 fromAmount,
65 | uint256 minBridgeAmount,
66 | uint256 realBridgeAmount
67 | );
68 |
69 | event WooCrossSwapOnDstChain(
70 | uint256 indexed refId,
71 | address indexed sender,
72 | address indexed to,
73 | address bridgedToken,
74 | uint256 bridgedAmount,
75 | address toToken,
76 | address realToToken,
77 | uint256 minToAmount,
78 | uint256 realToAmount
79 | );
80 |
81 | /* ----- State Variables ----- */
82 |
83 | function weth() external view returns (address);
84 |
85 | function bridgeSlippage() external view returns (uint256);
86 |
87 | function dstGasForSwapCall() external view returns (uint256);
88 |
89 | function dstGasForNoSwapCall() external view returns (uint256);
90 |
91 | function sgChainIdLocal() external view returns (uint16);
92 |
93 | function wooCrossChainRouters(uint16 chainId) external view returns (address wooCrossChainRouter);
94 |
95 | function sgETHs(uint16 chainId) external view returns (address sgETH);
96 |
97 | function sgPoolIds(uint16 chainId, address token) external view returns (uint256 poolId);
98 |
99 | /* ----- Functions ----- */
100 |
101 | function crossSwap(
102 | uint256 refId,
103 | address payable to,
104 | SrcInfos memory srcInfos,
105 | DstInfos memory dstInfos
106 | ) external payable;
107 |
108 | function sgReceive(
109 | uint16 srcChainId,
110 | bytes memory srcAddress,
111 | uint256 nonce,
112 | address bridgedToken,
113 | uint256 amountLD,
114 | bytes memory payload
115 | ) external;
116 |
117 | function quoteLayerZeroFee(
118 | uint256 refId,
119 | address to,
120 | SrcInfos memory srcInfos,
121 | DstInfos memory dstInfos
122 | ) external view returns (uint256 nativeAmount, uint256 zroAmount);
123 |
124 | function allDirectBridgeTokens() external view returns (address[] memory tokens);
125 |
126 | function allDirectBridgeTokensLength() external view returns (uint256 length);
127 | }
128 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/IWooCrossChainRouterV3.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title WOOFi cross chain router interface (version 3, supporting WOOFi and 1inch).
38 | /// @notice functions to interface with WOOFi cross chain swap, and 1inch for local swap
39 | interface IWooCrossChainRouterV3 {
40 | /* ----- Structs ----- */
41 |
42 | struct SrcInfos {
43 | address fromToken;
44 | address bridgeToken;
45 | uint256 fromAmount;
46 | uint256 minBridgeAmount;
47 | }
48 |
49 | struct Src1inch {
50 | address swapRouter;
51 | bytes data;
52 | }
53 |
54 | struct DstInfos {
55 | uint16 chainId;
56 | address toToken;
57 | address bridgeToken;
58 | uint256 minToAmount;
59 | uint256 airdropNativeAmount;
60 | uint256 dstGasForCall;
61 | }
62 |
63 | struct Dst1inch {
64 | address swapRouter;
65 | bytes data;
66 | }
67 |
68 | /* ----- Events ----- */
69 |
70 | event WooCrossSwapOnSrcChain(
71 | uint256 indexed refId,
72 | address indexed sender,
73 | address indexed to,
74 | address fromToken,
75 | uint256 fromAmount,
76 | address bridgeToken,
77 | uint256 minBridgeAmount,
78 | uint256 realBridgeAmount,
79 | uint8 swapType,
80 | uint256 fee
81 | );
82 |
83 | event WooCrossSwapOnDstChain(
84 | uint256 indexed refId,
85 | address indexed sender,
86 | address indexed to,
87 | address bridgedToken,
88 | uint256 bridgedAmount,
89 | address toToken,
90 | address realToToken,
91 | uint256 minToAmount,
92 | uint256 realToAmount,
93 | uint8 swapType,
94 | uint256 fee
95 | );
96 |
97 | /* ----- State Variables ----- */
98 |
99 | function bridgeSlippage() external view returns (uint256);
100 |
101 | function wooCrossRouters(uint16 chainId) external view returns (address wooCrossRouter);
102 |
103 | /* ----- Functions ----- */
104 |
105 | function crossSwap(
106 | uint256 refId,
107 | address payable to,
108 | SrcInfos memory srcInfos,
109 | DstInfos calldata dstInfos,
110 | Src1inch calldata src1inch,
111 | Dst1inch calldata dst1inch
112 | ) external payable;
113 |
114 | function sgReceive(
115 | uint16 srcChainId,
116 | bytes memory srcAddress,
117 | uint256 nonce,
118 | address bridgedToken,
119 | uint256 amountLD,
120 | bytes memory payload
121 | ) external;
122 |
123 | function quoteLayerZeroFee(
124 | uint256 refId,
125 | address to,
126 | DstInfos calldata dstInfos,
127 | Dst1inch calldata dst1inch
128 | ) external view returns (uint256 nativeAmount, uint256 zroAmount);
129 | }
130 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/IWooCrossChainRouterV4.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title WOOFi cross chain router interface (version 4, supporting WOOFi and 1inch).
38 | /// @notice functions to interface with WOOFi cross chain swap, and 1inch for local swap
39 | interface IWooCrossChainRouterV4 {
40 | /* ----- Structs ----- */
41 |
42 | struct SrcInfos {
43 | address fromToken;
44 | address bridgeToken;
45 | uint256 fromAmount;
46 | uint256 minBridgeAmount;
47 | }
48 |
49 | struct Src1inch {
50 | address swapRouter;
51 | bytes data;
52 | }
53 |
54 | struct DstInfos {
55 | uint16 chainId;
56 | address toToken;
57 | address bridgeToken;
58 | uint256 minToAmount;
59 | uint256 airdropNativeAmount;
60 | uint256 dstGasForCall;
61 | }
62 |
63 | struct Dst1inch {
64 | address swapRouter;
65 | bytes data;
66 | }
67 |
68 | /* ----- Events ----- */
69 |
70 | event WooCrossSwapOnSrcChain(
71 | uint256 indexed refId,
72 | address indexed sender,
73 | address indexed to,
74 | address fromToken,
75 | uint256 fromAmount,
76 | address bridgeToken,
77 | uint256 minBridgeAmount,
78 | uint256 realBridgeAmount,
79 | uint8 swapType,
80 | uint256 fee
81 | );
82 |
83 | event WooCrossSwapOnDstChain(
84 | uint256 indexed refId,
85 | address indexed sender,
86 | address indexed to,
87 | address bridgedToken,
88 | uint256 bridgedAmount,
89 | address toToken,
90 | address realToToken,
91 | uint256 minToAmount,
92 | uint256 realToAmount,
93 | uint8 swapType,
94 | uint256 fee
95 | );
96 |
97 | /* ----- State Variables ----- */
98 |
99 | function bridgeSlippage() external view returns (uint256);
100 |
101 | function wooCrossRouters(uint16 chainId) external view returns (address wooCrossRouter);
102 |
103 | /* ----- Functions ----- */
104 |
105 | function crossSwap(
106 | uint256 refId,
107 | address payable to,
108 | SrcInfos memory srcInfos,
109 | DstInfos calldata dstInfos,
110 | Src1inch calldata src1inch,
111 | Dst1inch calldata dst1inch
112 | ) external payable;
113 |
114 | function sgReceive(
115 | uint16 srcChainId,
116 | bytes memory srcAddress,
117 | uint256 nonce,
118 | address bridgedToken,
119 | uint256 amountLD,
120 | bytes memory payload
121 | ) external;
122 |
123 | function quoteLayerZeroFee(
124 | uint256 refId,
125 | address to,
126 | DstInfos calldata dstInfos,
127 | Dst1inch calldata dst1inch
128 | ) external view returns (uint256 nativeAmount, uint256 zroAmount);
129 | }
130 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/IWooCrossFee.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title WOOFi cross fee.
38 | interface IWooCrossFee {
39 | /* ----- Events ----- */
40 |
41 | event TargetBalanceUpdated(
42 | uint256 prevTargetBalance, // previous target balance
43 | uint256 newTargetBalance // newly set target balance
44 | );
45 |
46 | /* ----- State Variables ----- */
47 |
48 | function targetBalance() external view returns (uint256 targetBalance);
49 |
50 | function feeBase() external pure returns (uint256 feeBase);
51 |
52 | /* ----- Functions ----- */
53 |
54 | function ingressFee(uint256 amount) external view returns (uint256 fee);
55 |
56 | function outgressFee(uint256 amount) external view returns (uint256 fee);
57 |
58 | function setTargetBalance(uint256 targetBalance) external;
59 | }
60 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/IWooCrossRouterForWidget.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | import {IWooCrossChainRouterV3} from "./IWooCrossChainRouterV3.sol";
38 |
39 | /// @title IWooCrossRouterForWidget
40 | /// @notice functions to interface for WOOFi swap & cross-swap for 3rd party widget
41 | interface IWooCrossRouterForWidget {
42 | /* ----- Structs ----- */
43 |
44 | struct FeeInfo {
45 | uint256 feeRate; // in 0.1 bps : 1/100000
46 | address feeAddr;
47 | }
48 |
49 | struct LocalSwapInfos {
50 | address fromToken;
51 | address toToken;
52 | uint256 fromAmount;
53 | uint256 minToAmount;
54 | address rebateTo;
55 | bytes payload;
56 | }
57 |
58 | /* ----- Functions ----- */
59 |
60 | function swap(
61 | address payable to,
62 | LocalSwapInfos memory infoWOOFi,
63 | IWooCrossChainRouterV3.Src1inch calldata info1inch,
64 | FeeInfo calldata feeInfo
65 | ) external payable returns (uint256 realToAmount);
66 |
67 | function crossSwap(
68 | address payable to,
69 | IWooCrossChainRouterV3.SrcInfos memory srcInfos,
70 | IWooCrossChainRouterV3.DstInfos calldata dstInfos,
71 | IWooCrossChainRouterV3.Src1inch calldata src1inch,
72 | IWooCrossChainRouterV3.Dst1inch calldata dst1inch,
73 | FeeInfo calldata feeInfo
74 | ) external payable;
75 |
76 | function quoteLayerZeroFee(
77 | address to,
78 | IWooCrossChainRouterV3.DstInfos calldata dstInfos,
79 | IWooCrossChainRouterV3.Dst1inch calldata dst1inch
80 | ) external view returns (uint256 nativeAmount, uint256 zroAmount);
81 | }
82 |
--------------------------------------------------------------------------------
/contracts/interfaces/CrossChain/IWooUsdOFTCrossRouter.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title WOOFi cross chain router interface (version 3) via WooUsd OFT
38 | /// @notice functions to interface with WOOFi cross chain swap.
39 | interface IWooUsdOFTCrossRouter {
40 | /* ----- Structs ----- */
41 |
42 | struct SrcInfos {
43 | address fromToken;
44 | address bridgeToken;
45 | uint256 fromAmount;
46 | uint256 minBridgeAmount;
47 | }
48 |
49 | struct DstInfos {
50 | uint16 chainId;
51 | address toToken;
52 | address bridgeToken;
53 | uint256 minToAmount;
54 | uint256 airdropNativeAmount;
55 | }
56 |
57 | /* ----- Events ----- */
58 |
59 | event WooCrossSwapOnSrcChain(
60 | uint256 indexed refId,
61 | address indexed sender,
62 | address indexed to,
63 | address fromToken,
64 | uint256 fromAmount,
65 | uint256 minBridgeAmount,
66 | uint256 realBridgeAmount,
67 | uint256 crossFee
68 | );
69 |
70 | event WooCrossSwapOnDstChain(
71 | uint256 indexed refId,
72 | address indexed sender,
73 | address indexed to,
74 | address bridgedToken,
75 | uint256 bridgedAmount,
76 | address toToken,
77 | address realToToken,
78 | uint256 minToAmount,
79 | uint256 realToAmount,
80 | uint256 crossFee
81 | );
82 |
83 | /* ----- State Variables ----- */
84 |
85 | function weth() external view returns (address);
86 |
87 | function dstGas() external view returns (uint256);
88 |
89 | function lzChainIdLocal() external view returns (uint16);
90 |
91 | function wooCrossChainRouters(uint16 chainId) external view returns (address wooCrossChainRouter);
92 |
93 | /* ----- Functions ----- */
94 |
95 | function crossSwap(
96 | uint256 refId,
97 | address payable to,
98 | SrcInfos memory srcInfos,
99 | DstInfos memory dstInfos
100 | ) external payable;
101 |
102 | function quoteCrossSwapFee(
103 | uint256 refId,
104 | address to,
105 | SrcInfos memory srcInfos,
106 | DstInfos memory dstInfos
107 | ) external view returns (uint256 nativeAmount, uint256 zroAmount);
108 | }
109 |
--------------------------------------------------------------------------------
/contracts/interfaces/IDataProvider.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface IVaultInfo {
5 | function costSharePrice(address user) external view returns (uint256 sharePrice);
6 |
7 | function getPricePerFullShare() external view returns (uint256 sharePrice);
8 | }
9 |
10 | interface ISuperChargerVaultInfo {
11 | function requestedWithdrawAmount(address user) external view returns (uint256 amount);
12 | }
13 |
14 | interface IWithdrawManagerInfo {
15 | function withdrawAmount(address user) external view returns (uint256 amount);
16 | }
17 |
18 | interface IMasterChefWooInfo {
19 | function userInfo(uint256 pid, address user) external view returns (uint256 amount, uint256 rewardDebt);
20 |
21 | function pendingXWoo(uint256 pid, address user)
22 | external
23 | view
24 | returns (uint256 pendingXWooAmount, uint256 pendingWooAmount);
25 |
26 | function pendingReward(uint256 pid, address user)
27 | external
28 | view
29 | returns (uint256 pendingRewardAmount, uint256 pendingRewarderTokens);
30 | }
31 |
32 | interface IWooSimpleRewarder {
33 | function pendingTokens(address user) external view returns (uint256 tokens);
34 | }
35 |
36 | interface IDataProvider {
37 | /* ----- Struct ----- */
38 |
39 | struct VaultInfos {
40 | uint256[] balancesOf;
41 | uint256[] sharePrices;
42 | uint256[] costSharePrices;
43 | }
44 |
45 | struct TokenInfos {
46 | uint256 nativeBalance;
47 | uint256[] balancesOf;
48 | }
49 |
50 | struct MasterChefWooInfos {
51 | uint256[] amounts;
52 | uint256[] rewardDebts;
53 | uint256[] pendingXWooAmounts;
54 | uint256[] pendingWooAmounts;
55 | uint256[] pendingTokens;
56 | }
57 |
58 | struct SuperChargerRelatedInfos {
59 | uint256[] requestedWithdrawAmounts;
60 | uint256[] withdrawAmounts;
61 | }
62 |
63 | /* ----- View Functions ----- */
64 |
65 | function infos(
66 | address user,
67 | address masterChefWoo,
68 | address[] memory wooSimpleRewarders,
69 | address[] memory vaults,
70 | address[] memory tokens,
71 | address[] memory superChargerVaults,
72 | address[] memory withdrawManagers,
73 | uint256[] memory pids
74 | )
75 | external
76 | view
77 | returns (
78 | VaultInfos memory vaultInfos,
79 | TokenInfos memory tokenInfos,
80 | MasterChefWooInfos memory masterChefWooInfos,
81 | SuperChargerRelatedInfos memory superChargerRelatedInfos
82 | );
83 |
84 | function balancesOf(address user, address[] memory tokens) external view returns (uint256[] memory results);
85 |
86 | function sharePrices(address[] memory vaults) external view returns (uint256[] memory results);
87 |
88 | function costSharePrices(address user, address[] memory vaults) external view returns (uint256[] memory results);
89 |
90 | function userInfos(
91 | address user,
92 | address masterChefWoo,
93 | uint256[] memory pids
94 | ) external view returns (uint256[] memory amounts, uint256[] memory rewardDebts);
95 |
96 | function pendingXWoos(
97 | address user,
98 | address masterChefWoo,
99 | uint256[] memory pids
100 | ) external view returns (uint256[] memory pendingXWooAmounts, uint256[] memory pendingWooAmounts);
101 |
102 | function pendingTokens(address user, address[] memory wooSimpleRewarders)
103 | external
104 | view
105 | returns (uint256[] memory results);
106 |
107 | function requestedWithdrawAmounts(address user, address[] memory superChargerVaults)
108 | external
109 | view
110 | returns (uint256[] memory results);
111 |
112 | function withdrawAmounts(address user, address[] memory withdrawManagers)
113 | external
114 | view
115 | returns (uint256[] memory results);
116 | }
117 |
--------------------------------------------------------------------------------
/contracts/interfaces/IMasterChefReward.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 |
3 | pragma solidity 0.8.14;
4 |
5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6 | import "./IRewarder.sol";
7 |
8 | interface IMasterChefReward {
9 | event PoolAdded(uint256 poolId, uint256 allocPoint, IERC20 weToken, IRewarder rewarder);
10 | event PoolSet(uint256 poolId, uint256 allocPoint, IRewarder rewarder);
11 | event PoolUpdated(uint256 poolId, uint256 lastRewardBlock, uint256 supply, uint256 accTokenPerShare);
12 | event RewardPerBlockUpdated(uint256 rewardPerBlock);
13 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
14 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
15 | event Harvest(address indexed user, uint256 indexed pid, uint256 amount);
16 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
17 |
18 | struct UserInfo {
19 | uint256 amount;
20 | uint256 rewardDebt;
21 | }
22 |
23 | struct PoolInfo {
24 | IERC20 weToken;
25 | uint256 allocPoint;
26 | uint256 lastRewardBlock;
27 | uint256 accTokenPerShare;
28 | IRewarder rewarder;
29 | }
30 |
31 | // System-level function
32 | function setRewardPerBlock(uint256 _rewardPerBlock) external;
33 |
34 | // Pool-related functions
35 | function poolLength() external view returns (uint256);
36 |
37 | function add(
38 | uint256 allocPoint,
39 | IERC20 weToken,
40 | IRewarder rewarder
41 | ) external;
42 |
43 | function set(
44 | uint256 pid,
45 | uint256 allocPoint,
46 | IRewarder rewarder
47 | ) external;
48 |
49 | function massUpdatePools() external;
50 |
51 | function updatePool(uint256 pid) external;
52 |
53 | // User-related functions
54 | function pendingReward(uint256 pid, address user)
55 | external
56 | view
57 | returns (uint256 pendingRewardAmount, uint256 pendingRewarderTokens);
58 |
59 | function deposit(uint256 pid, uint256 amount) external;
60 |
61 | function withdraw(uint256 pid, uint256 amount) external;
62 |
63 | function harvest(uint256 pid) external;
64 |
65 | function emergencyWithdraw(uint256 pid) external;
66 |
67 | function userInfo(uint256 pid, address user) external view returns (uint256 amount, uint256 rewardDebt);
68 |
69 | function poolInfo(uint256 pid)
70 | external
71 | view
72 | returns (
73 | IERC20 weToken,
74 | uint256 allocPoint,
75 | uint256 lastRewardBlock,
76 | uint256 accTokenPerShare,
77 | IRewarder rewarder
78 | );
79 | }
80 |
--------------------------------------------------------------------------------
/contracts/interfaces/IMasterChefWoo.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 |
3 | pragma solidity 0.8.14;
4 |
5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6 | import "./IRewarder.sol";
7 |
8 | interface IMasterChefWoo {
9 | event PoolAdded(uint256 poolId, uint256 allocPoint, IERC20 weToken, IRewarder rewarder);
10 | event PoolSet(uint256 poolId, uint256 allocPoint, IRewarder rewarder);
11 | event PoolUpdated(uint256 poolId, uint256 lastRewardBlock, uint256 supply, uint256 accTokenPerShare);
12 | event XWooPerBlockUpdated(uint256 xWooPerBlock);
13 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
14 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
15 | event Harvest(address indexed user, uint256 indexed pid, uint256 amount);
16 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
17 |
18 | struct UserInfo {
19 | uint256 amount;
20 | uint256 rewardDebt;
21 | }
22 |
23 | struct PoolInfo {
24 | IERC20 weToken;
25 | uint256 allocPoint;
26 | uint256 lastRewardBlock;
27 | uint256 accTokenPerShare;
28 | IRewarder rewarder;
29 | }
30 |
31 | // System-level function
32 | function setXWooPerBlock(uint256 _xWooPerBlock) external;
33 |
34 | // Pool-related functions
35 | function poolLength() external view returns (uint256);
36 |
37 | function add(
38 | uint256 allocPoint,
39 | IERC20 weToken,
40 | IRewarder rewarder
41 | ) external;
42 |
43 | function set(
44 | uint256 pid,
45 | uint256 allocPoint,
46 | IRewarder rewarder
47 | ) external;
48 |
49 | function massUpdatePools() external;
50 |
51 | function updatePool(uint256 pid) external;
52 |
53 | // User-related functions
54 | function pendingXWoo(uint256 pid, address user) external view returns (uint256, uint256);
55 |
56 | function deposit(uint256 pid, uint256 amount) external;
57 |
58 | function withdraw(uint256 pid, uint256 amount) external;
59 |
60 | function harvest(uint256 pid) external;
61 |
62 | function emergencyWithdraw(uint256 pid) external;
63 |
64 | function userInfo(uint256 pid, address user) external view returns (uint256 amount, uint256 rewardDebt);
65 |
66 | function poolInfo(uint256 pid)
67 | external
68 | view
69 | returns (
70 | IERC20 weToken,
71 | uint256 allocPoint,
72 | uint256 lastRewardBlock,
73 | uint256 accTokenPerShare,
74 | IRewarder rewarder
75 | );
76 | }
77 |
--------------------------------------------------------------------------------
/contracts/interfaces/IPauser.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | interface IPauser {
38 | /* ----- Events ----- */
39 |
40 | event PauseRoleUpdated(address indexed addr, bool flag);
41 | event UnpauseRoleUpdated(address indexed addr, bool flag);
42 |
43 | /* ----- External Functions ----- */
44 |
45 | function isPauseRole(address account) external view returns (bool);
46 |
47 | function isUnpauseRole(address account) external view returns (bool);
48 | }
49 |
50 | interface IPauseContract {
51 | /* ----- External Functions ----- */
52 |
53 | function pause() external;
54 |
55 | function unpause() external;
56 | }
57 |
--------------------------------------------------------------------------------
/contracts/interfaces/IRewarder.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 |
3 | pragma solidity 0.8.14;
4 |
5 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6 |
7 | interface IRewarder {
8 | event OnRewarded(address indexed user, uint256 amount);
9 | event RewardRateUpdated(uint256 oldRate, uint256 newRate);
10 |
11 | struct UserInfo {
12 | uint256 amount;
13 | uint256 rewardDebt;
14 | uint256 unpaidRewards;
15 | }
16 |
17 | struct PoolInfo {
18 | uint256 accTokenPerShare;
19 | uint256 lastRewardBlock;
20 | }
21 |
22 | function onRewarded(address user, uint256 amount) external;
23 |
24 | function pendingTokens(address user) external view returns (uint256);
25 | }
26 |
--------------------------------------------------------------------------------
/contracts/interfaces/IStrategy.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 | interface IStrategy {
37 | function vault() external view returns (address);
38 |
39 | function want() external view returns (address);
40 |
41 | function beforeDeposit() external;
42 |
43 | function beforeWithdraw() external;
44 |
45 | function deposit() external;
46 |
47 | function withdraw(uint256) external;
48 |
49 | function balanceOf() external view returns (uint256);
50 |
51 | function balanceOfWant() external view returns (uint256);
52 |
53 | function balanceOfPool() external view returns (uint256);
54 |
55 | function harvest() external;
56 |
57 | function retireStrat() external;
58 |
59 | function emergencyExit() external;
60 |
61 | function paused() external view returns (bool);
62 |
63 | function inCaseTokensGetStuck(address stuckToken) external;
64 | }
65 |
--------------------------------------------------------------------------------
/contracts/interfaces/IVaultV2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface IVaultV2 {
5 | function want() external view returns (address);
6 |
7 | function weth() external view returns (address);
8 |
9 | function deposit(uint256 amount) external payable;
10 |
11 | function withdraw(uint256 shares) external;
12 |
13 | function earn() external;
14 |
15 | function available() external view returns (uint256);
16 |
17 | function balance() external view returns (uint256);
18 |
19 | function getPricePerFullShare() external view returns (uint256);
20 | }
21 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWETH.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | /// @title Wrapped ETH.
5 | interface IWETH {
6 | /// @dev Deposit ETH into WETH
7 | function deposit() external payable;
8 |
9 | /// @dev Transfer WETH to receiver
10 | /// @param to address of WETH receiver
11 | /// @param value amount of WETH to transfer
12 | /// @return get true when succeed, else false
13 | function transfer(address to, uint256 value) external returns (bool);
14 |
15 | /// @dev Withdraw WETH to ETH
16 | function withdraw(uint256) external;
17 | }
18 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooAccessManager.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Reward manager interface for WooFi Swap.
38 | /// @notice this is for swap rebate or potential incentive program
39 | interface IWooAccessManager {
40 | /* ----- Events ----- */
41 |
42 | event FeeAdminUpdated(address indexed feeAdmin, bool flag);
43 |
44 | event VaultAdminUpdated(address indexed vaultAdmin, bool flag);
45 |
46 | event RebateAdminUpdated(address indexed rebateAdmin, bool flag);
47 |
48 | event ZeroFeeVaultUpdated(address indexed vault, bool flag);
49 |
50 | /* ----- External Functions ----- */
51 |
52 | function isFeeAdmin(address feeAdmin) external returns (bool);
53 |
54 | function isVaultAdmin(address vaultAdmin) external returns (bool);
55 |
56 | function isRebateAdmin(address rebateAdmin) external returns (bool);
57 |
58 | function isZeroFeeVault(address vault) external returns (bool);
59 |
60 | /* ----- Admin Functions ----- */
61 |
62 | /// @notice Sets feeAdmin
63 | function setFeeAdmin(address feeAdmin, bool flag) external;
64 |
65 | /// @notice Sets vaultAdmin
66 | function setVaultAdmin(address vaultAdmin, bool flag) external;
67 |
68 | /// @notice Sets rebateAdmin
69 | function setRebateAdmin(address rebateAdmin, bool flag) external;
70 |
71 | /// @notice Sets zeroFeeVault
72 | function setZeroFeeVault(address vault, bool flag) external;
73 | }
74 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooFeeManager.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2022 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Contract to collect transaction fee of Woo private pool.
38 | interface IWooFeeManager {
39 | /* ----- Events ----- */
40 |
41 | event FeeRateUpdated(address indexed token, uint256 newFeeRate);
42 | event Withdraw(address indexed token, address indexed to, uint256 amount);
43 |
44 | /* ----- External Functions ----- */
45 |
46 | /// @dev fee rate for the given base token:
47 | /// NOTE: fee rate decimal 18: 1e16 = 1%, 1e15 = 0.1%, 1e14 = 0.01%
48 | /// @param token the base token
49 | /// @return the fee rate
50 | function feeRate(address token) external view returns (uint256);
51 |
52 | /// @dev Sets the fee rate for the given token
53 | /// @param token the base token
54 | /// @param newFeeRate the new fee rate
55 | function setFeeRate(address token, uint256 newFeeRate) external;
56 |
57 | /// @dev Collects the swap fee to the given brokder address.
58 | /// @param amount the swap fee amount
59 | /// @param brokerAddr the broker address to rebate to
60 | function collectFee(uint256 amount, address brokerAddr) external;
61 |
62 | /// @dev get the quote token address
63 | /// @return address of quote token
64 | function quoteToken() external view returns (address);
65 |
66 | /// @dev Collects the fee and distribute to rebate and vault managers.
67 | function distributeFees() external;
68 |
69 | /// @dev Add the rebate amounts for the specified broker addresses.
70 | /// @param brokerAddrs the broker address for rebate
71 | /// @param amounts the rebate amount for each broker address
72 | function addRebates(address[] memory brokerAddrs, uint256[] memory amounts) external;
73 | }
74 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooLendingManager.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2022 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Interface for WooLendingManager
38 | interface IWooLendingManager {
39 | function want() external returns (address);
40 |
41 | function repayWeekly() external returns (uint256 repaidAmount);
42 |
43 | function repayAll() external returns (uint256 repaidAmount);
44 |
45 | function repay(uint256 amount) external;
46 |
47 | /// @notice Borrow the fund from super charger and then deposit directly into WooPP.
48 | /// @param amount the borrowing amount
49 | function borrow(uint256 amount) external;
50 |
51 | function accureInterest() external;
52 |
53 | function weeklyRepayment() external view returns (uint256 repayAmount);
54 |
55 | function weeklyRepaymentBreakdown()
56 | external
57 | view
58 | returns (
59 | uint256 repayAmount,
60 | uint256 principal,
61 | uint256 interest,
62 | uint256 perfFee
63 | );
64 |
65 | function borrowedInterest() external view returns (uint256);
66 |
67 | function perfRate() external view returns (uint256);
68 |
69 | function repayPrincipal(uint256 _principal) external returns (uint256 repaidAmount);
70 | }
71 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooPPV2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Woo private pool for swap.
38 | /// @notice Use this contract to directly interfact with woo's synthetic proactive
39 | /// marketing making pool.
40 | /// @author woo.network
41 | interface IWooPPV2 {
42 | /* ----- Events ----- */
43 |
44 | event Deposit(address indexed token, address indexed sender, uint256 amount);
45 | event Withdraw(address indexed token, address indexed receiver, uint256 amount);
46 | event Migrate(address indexed token, address indexed receiver, uint256 amount);
47 | event AdminUpdated(address indexed addr, bool flag);
48 | event PauseRoleUpdated(address indexed addr, bool flag);
49 | event FeeAddrUpdated(address indexed newFeeAddr);
50 | event WooracleUpdated(address indexed newWooracle);
51 | event WooSwap(
52 | address indexed fromToken,
53 | address indexed toToken,
54 | uint256 fromAmount,
55 | uint256 toAmount,
56 | address from,
57 | address indexed to,
58 | address rebateTo,
59 | uint256 swapVol,
60 | uint256 swapFee
61 | );
62 |
63 | /* ----- External Functions ----- */
64 |
65 | /// @notice The quote token address (immutable).
66 | /// @return address of quote token
67 | function quoteToken() external view returns (address);
68 |
69 | /// @notice Gets the pool size of the specified token (swap liquidity).
70 | /// @param token the token address
71 | /// @return the pool size
72 | function poolSize(address token) external view returns (uint256);
73 |
74 | /// @notice Query the amount to swap `fromToken` to `toToken`, without checking the pool reserve balance.
75 | /// @param fromToken the from token
76 | /// @param toToken the to token
77 | /// @param fromAmount the amount of `fromToken` to swap
78 | /// @return toAmount the swapped amount of `toToken`
79 | function tryQuery(
80 | address fromToken,
81 | address toToken,
82 | uint256 fromAmount
83 | ) external view returns (uint256 toAmount);
84 |
85 | /// @notice Query the amount to swap `fromToken` to `toToken`, with checking the pool reserve balance.
86 | /// @dev tx reverts when 'toToken' balance is insufficient.
87 | /// @param fromToken the from token
88 | /// @param toToken the to token
89 | /// @param fromAmount the amount of `fromToken` to swap
90 | /// @return toAmount the swapped amount of `toToken`
91 | function query(
92 | address fromToken,
93 | address toToken,
94 | uint256 fromAmount
95 | ) external view returns (uint256 toAmount);
96 |
97 | /// @notice Swap `fromToken` to `toToken`.
98 | /// @param fromToken the from token
99 | /// @param toToken the to token
100 | /// @param fromAmount the amount of `fromToken` to swap
101 | /// @param minToAmount the minimum amount of `toToken` to receive
102 | /// @param to the destination address
103 | /// @param rebateTo the rebate address (optional, can be address ZERO)
104 | /// @return realToAmount the amount of toToken to receive
105 | function swap(
106 | address fromToken,
107 | address toToken,
108 | uint256 fromAmount,
109 | uint256 minToAmount,
110 | address to,
111 | address rebateTo
112 | ) external returns (uint256 realToAmount);
113 |
114 | /// @notice Deposit the specified token into the liquidity pool of WooPPV2.
115 | /// @param token the token to deposit
116 | /// @param amount the deposit amount
117 | function deposit(address token, uint256 amount) external;
118 | }
119 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooPPV2ForTest.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | interface IWooPPV2ForTest {
38 | function balance(address token) external view returns (uint256);
39 | }
40 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooPPV3.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Woo private pool for swap.
38 | /// @notice Use this contract to directly interfact with woo's synthetic proactive
39 | /// marketing making pool.
40 | /// @author woo.network
41 | interface IWooPPV3 {
42 | /* ----- Type declarations ----- */
43 | struct DecimalInfo {
44 | uint64 priceDec; // 10**(price_decimal)
45 | uint64 quoteDec; // 10**(quote_decimal)
46 | uint64 baseDec; // 10**(base_decimal)
47 | }
48 |
49 | struct TokenInfo {
50 | uint192 reserve; // balance reserve
51 | uint16 feeRate; // 1 in 100000; 10 = 1bp = 0.01%; max = 65535
52 | uint192 capBal; // maximum balance cap in token amount
53 | uint16 shiftMax; // 1 in 100000, 0.1 bps max = 65535
54 | uint192 tgtBal; // target balance for swap fee
55 | }
56 |
57 | /* ----- Events ----- */
58 |
59 | event Deposit(address indexed token, address indexed sender, uint256 amount);
60 | event Withdraw(address indexed token, address indexed receiver, uint256 amount);
61 | event Migrate(address indexed token, address indexed receiver, uint256 amount);
62 | event WooSwap(
63 | address indexed fromToken,
64 | address indexed toToken,
65 | uint256 fromAmount,
66 | uint256 toAmount,
67 | address from,
68 | address indexed to,
69 | address rebateTo,
70 | uint256 swapVol,
71 | uint256 swapFee
72 | );
73 |
74 | /* ----- External Functions ----- */
75 |
76 | /// @notice Gets the woo USD OFT address
77 | /// @return the oft address
78 | function usdOFT() external view returns (address);
79 |
80 | /// @notice Gets the pool size of the specified token (swap liquidity).
81 | /// @param token the token address
82 | /// @return the pool size
83 | function poolSize(address token) external view returns (uint256);
84 |
85 | /// @notice Gets the decimal info of the given base token
86 | /// @param baseToken the base token address
87 | /// @return the struct of decimal info
88 | function decimalInfo(address baseToken) external view returns (DecimalInfo memory);
89 |
90 | /// @notice Query the amount to swap `fromToken` to `toToken`, without checking the pool reserve balance.
91 | /// @param fromToken the from token
92 | /// @param toToken the to token
93 | /// @param fromAmount the amount of `fromToken` to swap
94 | /// @return toAmount the swapped amount of `toToken`
95 | function tryQuery(
96 | address fromToken,
97 | address toToken,
98 | uint256 fromAmount
99 | ) external view returns (uint256 toAmount);
100 |
101 | /// @notice Query the amount to swap `fromToken` to `toToken`, with checking the pool reserve balance.
102 | /// @dev tx reverts when 'toToken' balance is insufficient.
103 | /// @param fromToken the from token
104 | /// @param toToken the to token
105 | /// @param fromAmount the amount of `fromToken` to swap
106 | /// @return toAmount the swapped amount of `toToken`
107 | function query(
108 | address fromToken,
109 | address toToken,
110 | uint256 fromAmount
111 | ) external view returns (uint256 toAmount);
112 |
113 | /// @notice Swap `fromToken` to `toToken`.
114 | /// @param fromToken the from token
115 | /// @param toToken the to token
116 | /// @param fromAmount the amount of `fromToken` to swap
117 | /// @param minToAmount the minimum amount of `toToken` to receive
118 | /// @param to the destination address
119 | /// @param rebateTo the rebate address (optional, can be address ZERO)
120 | /// @return realToAmount the amount of toToken to receive
121 | function swap(
122 | address fromToken,
123 | address toToken,
124 | uint256 fromAmount,
125 | uint256 minToAmount,
126 | address to,
127 | address rebateTo
128 | ) external returns (uint256 realToAmount);
129 |
130 | /// @notice Deposit the specified token into the liquidity pool of WooPPV2.
131 | /// @param token the token to deposit
132 | /// @param amount the deposit amount
133 | function deposit(address token, uint256 amount) external;
134 | }
135 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooRebateManager.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Rebate manager interface for WooFi Swap.
38 | /// @notice this is for swap rebate or potential incentive program
39 |
40 | interface IWooRebateManager {
41 | event Withdraw(address indexed token, address indexed to, uint256 amount);
42 | event RebateRateUpdated(address indexed brokerAddr, uint256 rate);
43 | event ClaimReward(address indexed brokerAddr, uint256 amount);
44 |
45 | /// @dev Gets the rebate rate for the given broker.
46 | /// Note: decimal: 18; 1e16 = 1%, 1e15 = 0.1%, 1e14 = 0.01%
47 | /// @param brokerAddr the address for rebate
48 | /// @return The rebate rate (decimal: 18; 1e16 = 1%, 1e15 = 0.1%, 1e14 = 0.01%)
49 | function rebateRate(address brokerAddr) external view returns (uint256);
50 |
51 | /// @dev set the rebate rate
52 | /// @param brokerAddr the rebate address
53 | /// @param rate the rebate rate
54 | function setRebateRate(address brokerAddr, uint256 rate) external;
55 |
56 | /// @dev adds the pending reward for the given user.
57 | /// @param brokerAddr the address for rebate
58 | /// @param amountInUSD the pending reward amount
59 | function addRebate(address brokerAddr, uint256 amountInUSD) external;
60 |
61 | /// @dev Pending amount in reward token (e.g. $woo).
62 | /// @param brokerAddr the address for rebate
63 | function pendingRebateInReward(address brokerAddr) external view returns (uint256);
64 |
65 | /// @dev Pending amount in quote token (e.g. usdc).
66 | /// @param brokerAddr the address for rebate
67 | function pendingRebateInQuote(address brokerAddr) external view returns (uint256);
68 |
69 | /// @dev Claims the reward ($woo token will be distributed)
70 | function claimRebate() external;
71 |
72 | /// @dev get the quote token address
73 | /// @return address of quote token
74 | function quoteToken() external view returns (address);
75 | }
76 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooRouterV2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | import "../interfaces/IWooPPV2.sol";
38 |
39 | /// @title Woo router interface (version 2)
40 | /// @notice functions to interface with WooFi swap
41 | interface IWooRouterV2 {
42 | /* ----- Type declarations ----- */
43 |
44 | enum SwapType {
45 | WooSwap,
46 | DodoSwap
47 | }
48 |
49 | /* ----- Events ----- */
50 |
51 | event WooRouterSwap(
52 | SwapType swapType,
53 | address indexed fromToken,
54 | address indexed toToken,
55 | uint256 fromAmount,
56 | uint256 toAmount,
57 | address from,
58 | address indexed to,
59 | address rebateTo
60 | );
61 |
62 | event WooPoolChanged(address newPool);
63 |
64 | /* ----- Router properties ----- */
65 |
66 | function WETH() external view returns (address);
67 |
68 | function wooPool() external view returns (IWooPPV2);
69 |
70 | /* ----- Main query & swap APIs ----- */
71 |
72 | /// @notice query the amount to swap fromToken -> toToken
73 | /// @param fromToken the from token
74 | /// @param toToken the to token
75 | /// @param fromAmount the amount of fromToken to swap
76 | /// @return toAmount the predicted amount to receive
77 | function querySwap(
78 | address fromToken,
79 | address toToken,
80 | uint256 fromAmount
81 | ) external view returns (uint256 toAmount);
82 |
83 | /// @notice query the amount to swap fromToken -> toToken,
84 | /// WITHOUT checking the reserve balance; so it
85 | /// always returns the quoted amount (for reference).
86 | /// @param fromToken the from token
87 | /// @param toToken the to token
88 | /// @param fromAmount the amount of fromToken to swap
89 | /// @return toAmount the predicted amount to receive
90 | function tryQuerySwap(
91 | address fromToken,
92 | address toToken,
93 | uint256 fromAmount
94 | ) external view returns (uint256 toAmount);
95 |
96 | /// @notice Swap `fromToken` to `toToken`.
97 | /// @param fromToken the from token
98 | /// @param toToken the to token
99 | /// @param fromAmount the amount of `fromToken` to swap
100 | /// @param minToAmount the minimum amount of `toToken` to receive
101 | /// @param to the destination address
102 | /// @param rebateTo the rebate address (optional, can be 0)
103 | /// @return realToAmount the amount of toToken to receive
104 | function swap(
105 | address fromToken,
106 | address toToken,
107 | uint256 fromAmount,
108 | uint256 minToAmount,
109 | address payable to,
110 | address rebateTo
111 | ) external payable returns (uint256 realToAmount);
112 |
113 | /* ----- 3rd party DEX swap ----- */
114 |
115 | /// @notice swap fromToken -> toToken via an external 3rd swap
116 | /// @param approveTarget the contract address for token transfer approval
117 | /// @param swapTarget the contract address for swap
118 | /// @param fromToken the from token
119 | /// @param toToken the to token
120 | /// @param fromAmount the amount of fromToken to swap
121 | /// @param minToAmount the min amount of swapped toToken
122 | /// @param to the destination address
123 | /// @param data call data for external call
124 | function externalSwap(
125 | address approveTarget,
126 | address swapTarget,
127 | address fromToken,
128 | address toToken,
129 | uint256 fromAmount,
130 | uint256 minToAmount,
131 | address payable to,
132 | bytes calldata data
133 | ) external payable returns (uint256 realToAmount);
134 | }
135 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooRouterV3.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | import "../interfaces/IWooPPV3.sol";
38 |
39 | /// @title Woo router interface (version 3)
40 | /// @notice functions to interface with WooFi swap
41 | interface IWooRouterV3 {
42 | /* ----- Type declarations ----- */
43 |
44 | enum SwapType {
45 | WooSwap,
46 | DodoSwap
47 | }
48 |
49 | /* ----- Events ----- */
50 |
51 | event WooRouterSwap(
52 | SwapType swapType,
53 | address indexed fromToken,
54 | address indexed toToken,
55 | uint256 fromAmount,
56 | uint256 toAmount,
57 | address from,
58 | address indexed to,
59 | address rebateTo
60 | );
61 |
62 | event wooPPChanged(address newPool);
63 |
64 | /* ----- Router properties ----- */
65 |
66 | function WETH() external view returns (address);
67 |
68 | function wooPP() external view returns (IWooPPV3);
69 |
70 | function usdOFT() external view returns (address);
71 |
72 | /* ----- Main query & swap APIs ----- */
73 |
74 | /// @notice query the amount to swap fromToken -> toToken
75 | /// @param fromToken the from token
76 | /// @param toToken the to token
77 | /// @param fromAmount the amount of fromToken to swap
78 | /// @return toAmount the predicted amount to receive
79 | function querySwap(
80 | address fromToken,
81 | address toToken,
82 | uint256 fromAmount
83 | ) external view returns (uint256 toAmount);
84 |
85 | /// @notice query the amount to swap fromToken -> toToken,
86 | /// WITHOUT checking the reserve balance; so it
87 | /// always returns the quoted amount (for reference).
88 | /// @param fromToken the from token
89 | /// @param toToken the to token
90 | /// @param fromAmount the amount of fromToken to swap
91 | /// @return toAmount the predicted amount to receive
92 | function tryQuerySwap(
93 | address fromToken,
94 | address toToken,
95 | uint256 fromAmount
96 | ) external view returns (uint256 toAmount);
97 |
98 | /// @notice Swap `fromToken` to `toToken`.
99 | /// @param fromToken the from token
100 | /// @param toToken the to token
101 | /// @param fromAmount the amount of `fromToken` to swap
102 | /// @param minToAmount the minimum amount of `toToken` to receive
103 | /// @param to the destination address
104 | /// @param rebateTo the rebate address (optional, can be 0)
105 | /// @return realToAmount the amount of toToken to receive
106 | function swap(
107 | address fromToken,
108 | address toToken,
109 | uint256 fromAmount,
110 | uint256 minToAmount,
111 | address payable to,
112 | address rebateTo
113 | ) external payable returns (uint256 realToAmount);
114 |
115 | /* ----- 3rd party DEX swap ----- */
116 |
117 | /// @notice swap fromToken -> toToken via an external 3rd swap
118 | /// @param approveTarget the contract address for token transfer approval
119 | /// @param swapTarget the contract address for swap
120 | /// @param fromToken the from token
121 | /// @param toToken the to token
122 | /// @param fromAmount the amount of fromToken to swap
123 | /// @param minToAmount the min amount of swapped toToken
124 | /// @param to the destination address
125 | /// @param data call data for external call
126 | function externalSwap(
127 | address approveTarget,
128 | address swapTarget,
129 | address fromToken,
130 | address toToken,
131 | uint256 fromAmount,
132 | uint256 minToAmount,
133 | address payable to,
134 | bytes calldata data
135 | ) external payable returns (uint256 realToAmount);
136 | }
137 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooVaultManager.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title Vault reward manager interface for WooFi Swap.
38 | interface IWooVaultManager {
39 | event VaultWeightUpdated(address indexed vaultAddr, uint256 weight);
40 | event RewardDistributed(address indexed vaultAddr, uint256 amount);
41 |
42 | /// @dev Gets the reward weight for the given vault.
43 | /// @param vaultAddr the vault address
44 | /// @return The weight of the given vault.
45 | function vaultWeight(address vaultAddr) external view returns (uint256);
46 |
47 | /// @dev Sets the reward weight for the given vault.
48 | /// @param vaultAddr the vault address
49 | /// @param weight the vault weight
50 | function setVaultWeight(address vaultAddr, uint256 weight) external;
51 |
52 | /// @dev Adds the reward quote amount.
53 | /// Note: The reward will be stored in this manager contract for
54 | /// further weight adjusted distribution.
55 | /// @param quoteAmount the reward amount in quote token.
56 | function addReward(uint256 quoteAmount) external;
57 |
58 | /// @dev Pending amount in quote token for the given vault.
59 | /// @param vaultAddr the vault address
60 | function pendingReward(address vaultAddr) external view returns (uint256);
61 |
62 | /// @dev All pending amount in quote token.
63 | /// @return the total pending reward
64 | function pendingAllReward() external view returns (uint256);
65 |
66 | /// @dev Distributes the reward to all the vaults based on the weights.
67 | function distributeAllReward() external;
68 |
69 | /// @dev All the vaults
70 | /// @return the vault address array
71 | function allVaults() external view returns (address[] memory);
72 |
73 | /// @dev get the quote token address
74 | /// @return address of quote token
75 | function quoteToken() external view returns (address);
76 | }
77 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooracleV2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title The oracle V2 interface by Woo.Network.
38 | /// @notice update and posted the latest price info by Woo.
39 | interface IWooracleV2 {
40 | struct State {
41 | uint128 price;
42 | uint64 spread;
43 | uint64 coeff;
44 | bool woFeasible;
45 | }
46 |
47 | /// @notice Wooracle spread value
48 | function woSpread(address base) external view returns (uint64);
49 |
50 | /// @notice Wooracle coeff value
51 | function woCoeff(address base) external view returns (uint64);
52 |
53 | /// @notice Wooracle state for the specified base token
54 | function woState(address base) external view returns (State memory);
55 |
56 | /// @notice Chainlink oracle address for the specified base token
57 | function cloAddress(address base) external view returns (address clo);
58 |
59 | /// @notice ChainLink price of the base token / quote token
60 | function cloPrice(address base) external view returns (uint256 price, uint256 timestamp);
61 |
62 | /// @notice Wooracle price of the base token
63 | function woPrice(address base) external view returns (uint128 price, uint256 timestamp);
64 |
65 | /// @notice Returns Woooracle price if available, otherwise fallback to ChainLink
66 | function price(address base) external view returns (uint256 priceNow, bool feasible);
67 |
68 | /// @notice Updates the Wooracle price for the specified base token
69 | function postPrice(address base, uint128 newPrice) external;
70 |
71 | function postState(
72 | address base,
73 | uint128 newPrice,
74 | uint64 newSpread,
75 | uint64 newCoeff
76 | ) external;
77 |
78 | /// @notice State of the specified base token.
79 | function state(address base) external view returns (State memory);
80 |
81 | /// @notice The price decimal for the specified base token (e.g. 8)
82 | function decimals(address base) external view returns (uint8);
83 |
84 | /// @notice The quote token for calculating WooPP query price
85 | function quoteToken() external view returns (address);
86 |
87 | /// @notice last updated timestamp
88 | function timestamp() external view returns (uint256);
89 |
90 | /// @notice Flag for Wooracle price feasible
91 | function isWoFeasible(address base) external view returns (bool);
92 |
93 | /// @notice Flag for account admin
94 | function isAdmin(address account) external view returns (bool);
95 | }
96 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooracleV2_2.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title The oracle V2.2 interface by Woo.Network.
38 | /// @notice update and posted the latest price info by Woo.
39 | interface IWooracleV2_2 {
40 | struct State {
41 | uint128 price;
42 | uint64 spread;
43 | uint64 coeff;
44 | bool woFeasible;
45 | }
46 |
47 | // /// @notice Wooracle spread value
48 | // function woSpread(address base) external view returns (uint64);
49 |
50 | // /// @notice Wooracle coeff value
51 | // function woCoeff(address base) external view returns (uint64);
52 |
53 | // /// @notice Wooracle state for the specified base token
54 | // function woState(address base) external view returns (State memory);
55 |
56 | // /// @notice Chainlink oracle address for the specified base token
57 | // function cloAddress(address base) external view returns (address clo);
58 |
59 | // /// @notice Wooracle price of the base token
60 | // function woPrice(address base) external view returns (uint128 price, uint256 timestamp);
61 |
62 | /// @notice ChainLink price of the base token / quote token
63 | function cloPrice(address base) external view returns (uint256 price, uint256 timestamp);
64 |
65 | /// @notice Returns Woooracle price if available, otherwise fallback to ChainLink
66 | function price(address base) external view returns (uint256 priceNow, bool feasible);
67 |
68 | /// @notice Updates the Wooracle price for the specified base token
69 | function postPrice(address base, uint128 _price) external;
70 |
71 | /// Updates the state of the given base token.
72 | /// @param _base baseToken address
73 | /// @param _price the new prices
74 | /// @param _spread the new spreads
75 | /// @param _coeff the new slippage coefficent
76 | function postState(
77 | address _base,
78 | uint128 _price,
79 | uint64 _spread,
80 | uint64 _coeff
81 | ) external;
82 |
83 | /// @notice State of the specified base token.
84 | function state(address base) external view returns (State memory);
85 |
86 | /// @notice The price decimal for the specified base token (e.g. 8)
87 | function decimals(address base) external view returns (uint8);
88 |
89 | /// @notice The quote token for calculating WooPP query price
90 | function quoteToken() external view returns (address);
91 |
92 | /// @notice last updated timestamp
93 | function timestamp() external view returns (uint256);
94 |
95 | /// @notice Flag for Wooracle price feasible
96 | function isWoFeasible(address base) external view returns (bool);
97 |
98 | // /// @notice Flag for account admin
99 | // function isAdmin(address account) external view returns (bool);
100 | }
101 |
--------------------------------------------------------------------------------
/contracts/interfaces/IWooracleV3.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | /*
5 |
6 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
7 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
8 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
9 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
10 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
11 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
12 |
13 | *
14 | * MIT License
15 | * ===========
16 | *
17 | * Copyright (c) 2020 WooTrade
18 | *
19 | * Permission is hereby granted, free of charge, to any person obtaining a copy
20 | * of this software and associated documentation files (the "Software"), to deal
21 | * in the Software without restriction, including without limitation the rights
22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23 | * copies of the Software, and to permit persons to whom the Software is
24 | * furnished to do so, subject to the following conditions:
25 | *
26 | * The above copyright notice and this permission notice shall be included in all
27 | * copies or substantial portions of the Software.
28 | *
29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 | */
36 |
37 | /// @title The oracle V2 interface by Woo.Network.
38 | /// @notice update and posted the latest price info by Woo.
39 | interface IWooracleV3 {
40 | struct State {
41 | uint128 price;
42 | uint64 spread;
43 | uint64 coeff;
44 | bool woFeasible;
45 | }
46 |
47 | /// @notice Wooracle spread value
48 | function woSpread(address base) external view returns (uint64);
49 |
50 | /// @notice Wooracle coeff value
51 | function woCoeff(address base) external view returns (uint64);
52 |
53 | /// @notice Wooracle state for the specified base token
54 | function woState(address base) external view returns (State memory);
55 |
56 | /// @notice Chainlink oracle address for the specified base token
57 | function cloAddress(address base) external view returns (address clo);
58 |
59 | /// @notice ChainLink price of the base token
60 | function cloPrice(address base) external view returns (uint256 price, uint256 timestamp);
61 |
62 | /// @notice Wooracle price of the base token
63 | function woPrice(address base) external view returns (uint128 price, uint256 timestamp);
64 |
65 | /// @notice Returns Woooracle price if available, otherwise fallback to ChainLink
66 | function price(address base) external view returns (uint256 priceNow, bool feasible);
67 |
68 | /// @notice Updates the Wooracle price for the specified base token
69 | function postPrice(address base, uint128 newPrice) external;
70 |
71 | function postState(
72 | address base,
73 | uint128 newPrice,
74 | uint64 newSpread,
75 | uint64 newCoeff
76 | ) external;
77 |
78 | /// @notice State of the specified base token.
79 | function state(address base) external view returns (State memory);
80 |
81 | /// @notice The price decimal for the specified base token (e.g. 8)
82 | function decimals(address base) external view returns (uint8);
83 |
84 | /// @notice last updated timestamp
85 | function timestamp() external view returns (uint256);
86 |
87 | /// @notice Flag for Wooracle price feasible
88 | function isWoFeasible(address base) external view returns (bool);
89 |
90 | /// @notice Flag for account admin
91 | function isAdmin(address account) external view returns (bool);
92 | }
93 |
--------------------------------------------------------------------------------
/contracts/interfaces/IXWoo.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 |
3 | pragma solidity 0.8.14;
4 |
5 | interface IXWoo {
6 | function getPricePerFullShare() external view returns (uint256);
7 | }
8 |
--------------------------------------------------------------------------------
/contracts/interfaces/LayerZero/ILzApp.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | /**
5 | * @dev Interface of the LzApp that functions not exist in the @layerzerolabs package
6 | */
7 | interface ILzApp {
8 | function minDstGasLookup(uint16 _dstChainId, uint16 _type) external view returns (uint256 _minGasLimit);
9 | }
10 |
--------------------------------------------------------------------------------
/contracts/interfaces/Stargate/IStargateEthVault.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | interface IStargateEthVault {
5 | function deposit() external payable;
6 |
7 | function transfer(address to, uint256 value) external returns (bool);
8 |
9 | function withdraw(uint256) external;
10 |
11 | function approve(address guy, uint256 wad) external returns (bool);
12 |
13 | function transferFrom(
14 | address src,
15 | address dst,
16 | uint256 wad
17 | ) external returns (bool);
18 | }
19 |
--------------------------------------------------------------------------------
/contracts/interfaces/Stargate/IStargateReceiver.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | interface IStargateReceiver {
5 | function sgReceive(
6 | uint16 _chainId,
7 | bytes memory _srcAddress,
8 | uint256 _nonce,
9 | address _token,
10 | uint256 amountLD,
11 | bytes memory payload
12 | ) external;
13 | }
14 |
--------------------------------------------------------------------------------
/contracts/interfaces/Stargate/IStargateRouter.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | interface IStargateRouter {
5 | struct lzTxObj {
6 | uint256 dstGasForCall;
7 | uint256 dstNativeAmount;
8 | bytes dstNativeAddr;
9 | }
10 |
11 | function addLiquidity(
12 | uint256 _poolId,
13 | uint256 _amountLD,
14 | address _to
15 | ) external;
16 |
17 | function swap(
18 | uint16 _dstChainId,
19 | uint256 _srcPoolId,
20 | uint256 _dstPoolId,
21 | address payable _refundAddress,
22 | uint256 _amountLD,
23 | uint256 _minAmountLD,
24 | lzTxObj memory _lzTxParams,
25 | bytes calldata _to,
26 | bytes calldata _payload
27 | ) external payable;
28 |
29 | function redeemRemote(
30 | uint16 _dstChainId,
31 | uint256 _srcPoolId,
32 | uint256 _dstPoolId,
33 | address payable _refundAddress,
34 | uint256 _amountLP,
35 | uint256 _minAmountLD,
36 | bytes calldata _to,
37 | lzTxObj memory _lzTxParams
38 | ) external payable;
39 |
40 | function instantRedeemLocal(
41 | uint16 _srcPoolId,
42 | uint256 _amountLP,
43 | address _to
44 | ) external returns (uint256);
45 |
46 | function redeemLocal(
47 | uint16 _dstChainId,
48 | uint256 _srcPoolId,
49 | uint256 _dstPoolId,
50 | address payable _refundAddress,
51 | uint256 _amountLP,
52 | bytes calldata _to,
53 | lzTxObj memory _lzTxParams
54 | ) external payable;
55 |
56 | function sendCredits(
57 | uint16 _dstChainId,
58 | uint256 _srcPoolId,
59 | uint256 _dstPoolId,
60 | address payable _refundAddress
61 | ) external payable;
62 |
63 | function quoteLayerZeroFee(
64 | uint16 _dstChainId,
65 | uint8 _functionType,
66 | bytes calldata _toAddress,
67 | bytes calldata _transferAndCallPayload,
68 | lzTxObj memory _lzTxParams
69 | ) external view returns (uint256, uint256);
70 | }
71 |
--------------------------------------------------------------------------------
/contracts/interfaces/WOOFiDex/INonceCounter.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface INonceCounter {
5 | /* ----- Events ----- */
6 |
7 | event CrossChainRouterUpdated(address crossChainRouter, bool flag);
8 |
9 | /* ----- Functions ----- */
10 |
11 | function outboundNonce(uint16 dstChainId) external view returns (uint256 nonce);
12 |
13 | function increment(uint16 dstChainId) external returns (uint256 nonce);
14 | }
15 |
--------------------------------------------------------------------------------
/contracts/interfaces/WOOFiDex/IWOOFiDexCrossChainRouter.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface IWOOFiDexCrossChainRouter {
5 | /* ----- Structs ----- */
6 |
7 | struct SrcInfos {
8 | address fromToken;
9 | uint256 fromAmount;
10 | address bridgeToken;
11 | uint256 minBridgeAmount;
12 | }
13 |
14 | struct DstInfos {
15 | uint16 chainId;
16 | address bridgedToken;
17 | address toToken;
18 | uint256 minToAmount;
19 | uint256 airdropNativeAmount;
20 | }
21 |
22 | struct DstVaultDeposit {
23 | bytes32 accountId;
24 | bytes32 brokerHash;
25 | bytes32 tokenHash;
26 | }
27 |
28 | struct PoolIds {
29 | uint256 src;
30 | uint256 dst;
31 | }
32 |
33 | /* ----- Events ----- */
34 |
35 | event WOOFiDexCrossSwapOnSrcChain(
36 | uint16 dstChainId,
37 | uint256 indexed nonce,
38 | address indexed sender,
39 | address indexed to,
40 | address fromToken,
41 | uint256 fromAmount,
42 | address bridgeToken,
43 | uint256 minBridgeAmount,
44 | uint256 bridgeAmount
45 | );
46 |
47 | event WOOFiDexCrossSwapOnDstChain(
48 | uint16 srcChainId,
49 | uint256 indexed nonce,
50 | address indexed sender,
51 | address indexed to,
52 | address bridgedToken,
53 | uint256 bridgedAmount,
54 | address toToken,
55 | uint256 minToAmount,
56 | address realToToken,
57 | uint256 realToAmount,
58 | bytes32 accountId,
59 | bytes32 brokerHash,
60 | bytes32 tokenHash,
61 | uint128 tokenAmount
62 | );
63 |
64 | /* ----- State Variables ----- */
65 |
66 | function weth() external view returns (address);
67 |
68 | function bridgeSlippage() external view returns (uint256);
69 |
70 | function dstGasForSwapCall() external view returns (uint256);
71 |
72 | function dstGasForNoSwapCall() external view returns (uint256);
73 |
74 | function sgChainIdLocal() external view returns (uint16);
75 |
76 | function woofiDexCrossChainRouters(uint16 chainId) external view returns (address wooCrossChainRouter);
77 |
78 | function woofiDexVaults(uint16 chainId, address token) external view returns (address woofiDexVault);
79 |
80 | function sgETHs(uint16 chainId) external view returns (address sgETH);
81 |
82 | function sgPoolIds(uint16 chainId, address token) external view returns (uint256 poolId);
83 |
84 | /* ----- Functions ----- */
85 |
86 | function crossSwap(
87 | address payable to,
88 | SrcInfos calldata srcInfos,
89 | DstInfos calldata dstInfos,
90 | DstVaultDeposit calldata dstVaultDeposit
91 | ) external payable;
92 |
93 | function sgReceive(
94 | uint16 srcChainId,
95 | bytes memory srcAddress,
96 | uint256 nonce,
97 | address bridgedToken,
98 | uint256 amountLD,
99 | bytes memory payload
100 | ) external;
101 |
102 | function quoteLayerZeroFee(
103 | address to,
104 | DstInfos memory dstInfos,
105 | DstVaultDeposit calldata dstVaultDeposit
106 | ) external view returns (uint256 nativeAmount, uint256 zroAmount);
107 |
108 | function allDirectBridgeTokens() external view returns (address[] memory tokens);
109 |
110 | function allDirectBridgeTokensLength() external view returns (uint256 length);
111 | }
112 |
--------------------------------------------------------------------------------
/contracts/interfaces/WOOFiDex/IWOOFiDexDepositor.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface IWOOFiDexDepositor {
5 | /* ----- Structs ----- */
6 |
7 | struct Infos {
8 | address fromToken;
9 | uint256 fromAmount;
10 | address toToken;
11 | uint256 minToAmount;
12 | }
13 |
14 | struct VaultDeposit {
15 | bytes32 accountId;
16 | bytes32 brokerHash;
17 | bytes32 tokenHash;
18 | }
19 |
20 | /* ----- Events ----- */
21 |
22 | event WOOFiDexSwap(
23 | address indexed sender,
24 | address indexed to,
25 | address fromToken,
26 | uint256 fromAmount,
27 | address toToken,
28 | uint256 minToAmount,
29 | uint256 toAmount,
30 | bytes32 accountId,
31 | bytes32 brokerHash,
32 | bytes32 tokenHash,
33 | uint128 tokenAmount
34 | );
35 |
36 | /* ----- State Variables ----- */
37 |
38 | function woofiDexVaults(address token) external view returns (address woofiDexVault);
39 |
40 | /* ----- Functions ----- */
41 |
42 | function swap(
43 | address payable to,
44 | Infos calldata infos,
45 | VaultDeposit calldata vaultDeposit
46 | ) external payable;
47 | }
48 |
--------------------------------------------------------------------------------
/contracts/interfaces/WOOFiDex/IWOOFiDexVault.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | interface IWOOFiDexVault {
5 | struct VaultDepositFE {
6 | bytes32 accountId;
7 | bytes32 brokerHash;
8 | bytes32 tokenHash;
9 | uint128 tokenAmount;
10 | }
11 |
12 | event AccountDepositTo(
13 | bytes32 indexed accountId,
14 | address indexed userAddress,
15 | uint64 indexed depositNonce,
16 | bytes32 tokenHash,
17 | uint128 tokenAmount
18 | );
19 |
20 | function depositTo(address receiver, VaultDepositFE calldata data) external payable;
21 | }
22 |
--------------------------------------------------------------------------------
/contracts/libraries/TransferHelper.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-or-later
2 | pragma solidity >=0.6.0;
3 |
4 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5 |
6 | /// @title TransferHelper
7 | /// @notice Contains helper methods for interacting with ERC20 and native tokens that do not consistently return true/false
8 | /// @dev implementation from https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/TransferHelper.sol
9 | library TransferHelper {
10 | /// @notice Transfers tokens from the targeted address to the given destination
11 | /// @notice Errors with 'STF' if transfer fails
12 | /// @param token The contract address of the token to be transferred
13 | /// @param from The originating address from which the tokens will be transferred
14 | /// @param to The destination address of the transfer
15 | /// @param value The amount to be transferred
16 | function safeTransferFrom(
17 | address token,
18 | address from,
19 | address to,
20 | uint256 value
21 | ) internal {
22 | (bool success, bytes memory data) =
23 | token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
24 | require(success && (data.length == 0 || abi.decode(data, (bool))), "STF");
25 | }
26 |
27 | /// @notice Transfers tokens from msg.sender to a recipient
28 | /// @dev Errors with ST if transfer fails
29 | /// @param token The contract address of the token which will be transferred
30 | /// @param to The recipient of the transfer
31 | /// @param value The value of the transfer
32 | function safeTransfer(
33 | address token,
34 | address to,
35 | uint256 value
36 | ) internal {
37 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
38 | require(success && (data.length == 0 || abi.decode(data, (bool))), "ST");
39 | }
40 |
41 | /// @notice Approves the stipulated contract to spend the given allowance in the given token
42 | /// @dev Errors with 'SA' if transfer fails
43 | /// @param token The contract address of the token to be approved
44 | /// @param to The target of the approval
45 | /// @param value The amount of the given token the target will be allowed to spend
46 | function safeApprove(
47 | address token,
48 | address to,
49 | uint256 value
50 | ) internal {
51 | (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
52 | require(success && (data.length == 0 || abi.decode(data, (bool))), "SA");
53 | }
54 |
55 | /// @notice Transfers ETH to the recipient address
56 | /// @dev Fails with `STE`
57 | /// @param to The destination of the transfer
58 | /// @param value The value to be transferred
59 | function safeTransferETH(address to, uint256 value) internal {
60 | (bool success, ) = to.call{value: value}(new bytes(0));
61 | require(success, "STE");
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/contracts/test/TestChainLink.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | import '../interfaces/AggregatorV3Interface.sol';
5 | import '@openzeppelin/contracts/access/Ownable.sol';
6 |
7 | contract TestChainLink is AggregatorV3Interface, Ownable {
8 | function decimals() external pure override returns (uint8) {
9 | return 8;
10 | }
11 |
12 | function description() external pure override returns (string memory) {
13 | return 'BTC / USD';
14 | }
15 |
16 | function version() external pure override returns (uint256) {
17 | return 1;
18 | }
19 |
20 | /// getRoundData and latestRoundData should both raise "No data present"
21 | /// if they do not have data to report, instead of returning unset values
22 | /// which could be misinterpreted as actual reported values.
23 | function getRoundData(
24 | uint80 /*_roundId*/
25 | )
26 | external
27 | pure
28 | override
29 | returns (
30 | uint80 roundId,
31 | int256 answer,
32 | uint256 startedAt,
33 | uint256 updatedAt,
34 | uint80 answeredInRound
35 | )
36 | {
37 | return (36893488147419375519, 2119577093131, 1661310103, 1661310103, 36893488147419375519);
38 | }
39 |
40 | function latestRoundData()
41 | external
42 | pure
43 | override
44 | returns (
45 | uint80 roundId,
46 | int256 answer,
47 | uint256 startedAt,
48 | uint256 updatedAt,
49 | uint80 answeredInRound
50 | )
51 | {
52 | return (36893488147419375519, 2119577093131, 1661310103, 1661310103, 36893488147419375519);
53 | }
54 | }
55 |
56 | contract TestQuoteChainLink is AggregatorV3Interface, Ownable {
57 | function decimals() external pure override returns (uint8) {
58 | return 8;
59 | }
60 |
61 | function description() external pure override returns (string memory) {
62 | return 'USDT / USD';
63 | }
64 |
65 | function version() external pure override returns (uint256) {
66 | return 1;
67 | }
68 |
69 | /// getRoundData and latestRoundData should both raise "No data present"
70 | /// if they do not have data to report, instead of returning unset values
71 | /// which could be misinterpreted as actual reported values.
72 | function getRoundData(
73 | uint80 /*_roundId*/
74 | )
75 | external
76 | pure
77 | override
78 | returns (
79 | uint80 roundId,
80 | int256 answer,
81 | uint256 startedAt,
82 | uint256 updatedAt,
83 | uint80 answeredInRound
84 | )
85 | {
86 | return (36893488147419109665, 99994997, 1661309776, 1661309776, 36893488147419109665);
87 | }
88 |
89 | function latestRoundData()
90 | external
91 | pure
92 | override
93 | returns (
94 | uint80 roundId,
95 | int256 answer,
96 | uint256 startedAt,
97 | uint256 updatedAt,
98 | uint80 answeredInRound
99 | )
100 | {
101 | return (36893488147419109665, 99994997, 1661309776, 1661309776, 36893488147419109665);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/contracts/test/TestERC20Token.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5 | import "@openzeppelin/contracts/access/Ownable.sol";
6 |
7 | contract TestERC20Token is ERC20("TestToken", "TT"), Ownable {
8 |
9 | function mint(address _to, uint256 _amount) public onlyOwner {
10 | _mint(_to, _amount);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/contracts/test/TestUsdtToken.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5 | import "@openzeppelin/contracts/access/Ownable.sol";
6 |
7 | contract TestUsdtToken is ERC20("Tether", "USDT"), Ownable {
8 |
9 | function decimals() public view virtual override returns (uint8) {
10 | return 6;
11 | }
12 |
13 | function mint(address _to, uint256 _amount) public onlyOwner {
14 | _mint(_to, _amount);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/contracts/test/WFTM.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity =0.8.14;
3 |
4 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5 |
6 | contract WFTM is Ownable {
7 |
8 | string public name = "Wrapped FTM";
9 | string public symbol = "WFTM";
10 | uint8 public decimals = 18;
11 |
12 | event Approval(address indexed src, address indexed guy, uint256 wad);
13 | event Transfer(address indexed src, address indexed dst, uint256 wad);
14 | event Deposit(address indexed dst, uint256 wad);
15 | event Withdrawal(address indexed src, uint256 wad);
16 |
17 | mapping(address => uint256) public balanceOf;
18 | mapping(address => mapping(address => uint256)) public allowance;
19 |
20 | receive() external payable {
21 | deposit();
22 | }
23 |
24 | function deposit() public payable {
25 | balanceOf[msg.sender] += msg.value;
26 | emit Deposit(msg.sender, msg.value);
27 | }
28 |
29 | function withdraw(uint256 wad) public {
30 | require(balanceOf[msg.sender] >= wad);
31 | balanceOf[msg.sender] -= wad;
32 | (bool success, ) = payable(msg.sender).call{value: wad}(new bytes(0));
33 | require(success);
34 | emit Withdrawal(msg.sender, wad);
35 | }
36 |
37 | function totalSupply() public view returns (uint256) {
38 | return address(this).balance;
39 | }
40 |
41 | function approve(address guy, uint256 wad) public returns (bool) {
42 | allowance[msg.sender][guy] = wad;
43 | emit Approval(msg.sender, guy, wad);
44 | return true;
45 | }
46 |
47 | function transfer(address dst, uint256 wad) public returns (bool) {
48 | return transferFrom(msg.sender, dst, wad);
49 | }
50 |
51 | function transferFrom(
52 | address src,
53 | address dst,
54 | uint256 wad
55 | ) public returns (bool) {
56 | require(balanceOf[src] >= wad);
57 |
58 | if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) {
59 | require(allowance[src][msg.sender] >= wad);
60 | allowance[src][msg.sender] -= wad;
61 | }
62 |
63 | balanceOf[src] -= wad;
64 | balanceOf[dst] += wad;
65 |
66 | emit Transfer(src, dst, wad);
67 |
68 | return true;
69 | }
70 |
71 | function mint(address _to, uint256 _amount) public onlyOwner {
72 | _mint(_to, _amount);
73 | }
74 |
75 | function _mint(address account, uint256 amount) internal {
76 | require(account != address(0), "ERC20: mint to the zero address");
77 | balanceOf[account] = balanceOf[account] + amount;
78 | emit Transfer(address(0), account, amount);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/foundry.toml:
--------------------------------------------------------------------------------
1 | [profile.default]
2 | auto_detect_solc = true
3 | block_base_fee_per_gas = 0
4 | block_coinbase = '0x0000000000000000000000000000000000000000'
5 | block_difficulty = 0
6 | block_number = 0
7 | block_timestamp = 0
8 | cache = true
9 | cache_path = 'cache'
10 | evm_version = 'london'
11 | extra_output = []
12 | extra_output_files = []
13 | ffi = false
14 | force = false
15 | fuzz_max_global_rejects = 65536
16 | fuzz_max_local_rejects = 1024
17 | fuzz_runs = 1000
18 | gas_limit = 9223372036854775807
19 | gas_price = 0
20 | gas_reports = ['*']
21 | ignored_error_codes = [1878]
22 | initial_balance = '0xffffffffffffffffffffffff'
23 | libraries = []
24 | libs = ["node_modules", "lib"]
25 | names = false
26 | offline = false
27 | optimizer = true
28 | optimizer_runs = 888888
29 | out = 'artifacts'
30 | sender = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
31 | sizes = false
32 | src = 'contracts'
33 | test = 'test/foundry'
34 | tx_origin = '0x00a329c0648769a73afac7f9381e08fb43dbea72'
35 | verbosity = 0
36 | via_ir = false
37 |
--------------------------------------------------------------------------------
/funding.json:
--------------------------------------------------------------------------------
1 | {
2 | "opRetro": {
3 | "projectId": "0x000c2ce4773defb3010a58d3800d0ec9d432189c574ba26d3103f1db44a5af6d"
4 | }
5 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "WooPP_V2",
3 | "version": "1.0.0",
4 | "description": "Woo private pool smart contract (version 2)",
5 | "main": "index.js",
6 | "author": "WooNetwork",
7 | "license": "MIT",
8 | "private": true,
9 | "keywords": [
10 | "woofi",
11 | "woo",
12 | "woo network"
13 | ],
14 | "homepage": "https://fi.woo.org/",
15 | "bugs": "https://github.com/woonetwork/WooPoolV2/issues",
16 | "repository": {
17 | "type": "git",
18 | "url": "https://github.com/woonetwork/WooPoolV2.git"
19 | },
20 | "scripts": {
21 | "compile": "hardhat compile",
22 | "compile:force": "hardhat compile --force",
23 | "format:check": "prettier --check '**/*.{js,jsx,ts,tsx,sol,json,yaml,md}'",
24 | "format:write": "prettier --write '**/*.{js,jsx,ts,tsx,sol,json,yaml,md}'",
25 | "lint": "eslint '**/*.{js,jsx,ts,tsx}'",
26 | "prepare": "husky install",
27 | "test": "hardhat test",
28 | "test:gas": "REPORT_GAS=true hardhat test",
29 | "test:forge": "forge test",
30 | "test:coverage": "hardhat coverage && hardhat compile --force"
31 | },
32 | "devDependencies": {
33 | "@commitlint/cli": "^16.2.3",
34 | "@commitlint/config-conventional": "^16.2.1",
35 | "@ethersproject/hash": "^5.7.0",
36 | "@ethersproject/web": "^5.7.1",
37 | "@matterlabs/hardhat-zksync-deploy": "^0.6.3",
38 | "@matterlabs/hardhat-zksync-solc": "^0.3.14",
39 | "@matterlabs/hardhat-zksync-verify": "^0.1.4",
40 | "@nomiclabs/hardhat-ethers": "^2.0.6",
41 | "@nomiclabs/hardhat-etherscan": "^3.1.3",
42 | "@nomiclabs/hardhat-waffle": "^2.0.3",
43 | "@typechain/ethers-v5": "^7.0.1",
44 | "@typechain/hardhat": "^2.3.0",
45 | "@types/chai": "^4.2.21",
46 | "@types/mocha": "^9.0.0",
47 | "@types/node": "^18.15.11",
48 | "@typescript-eslint/eslint-plugin": "^4.29.1",
49 | "@typescript-eslint/parser": "^4.29.1",
50 | "chai": "^4.2.0",
51 | "dotenv": "^10.0.0",
52 | "eslint": "^7.29.0",
53 | "eslint-config-prettier": "^8.3.0",
54 | "eslint-config-standard": "^16.0.3",
55 | "eslint-plugin-import": "^2.23.4",
56 | "eslint-plugin-node": "^11.1.0",
57 | "eslint-plugin-prettier": "^3.4.0",
58 | "eslint-plugin-promise": "^5.1.0",
59 | "ethereum-waffle": "^3.4.4",
60 | "ethers": "^5.7.2",
61 | "hardhat": "^2.13.0",
62 | "hardhat-abi-exporter": "^2.9.0",
63 | "hardhat-gas-reporter": "^1.0.8",
64 | "husky": "^7.0.4",
65 | "merkletreejs": "^0.2.31",
66 | "prettier": "^2.3.2",
67 | "prettier-plugin-solidity": "^1.0.0-beta.13",
68 | "release-it": "^15.0.0",
69 | "solhint": "^3.3.7",
70 | "solidity-coverage": "^0.7.21",
71 | "ts-node": "^10.9.1",
72 | "typechain": "^5.1.2",
73 | "typescript": "^5.0.3",
74 | "zksync-web3": "^0.14.3"
75 | },
76 | "dependencies": {
77 | "@layerzerolabs/solidity-examples": "^0.0.13",
78 | "@openzeppelin/contracts": "^4.9.3",
79 | "@uniswap/v3-periphery": "1.4.4"
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/scripts/DataProvider.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "DataProvider";
6 |
7 | async function main() {
8 | const factory = await ethers.getContractFactory(contractName);
9 | const contract = await factory.deploy();
10 | await contract.deployed();
11 | console.log(`${contractName} deployed to: ${contract.address}`);
12 |
13 | await new Promise((resolve) => setTimeout(resolve, 10000));
14 | try {
15 | await run("verify:verify", {
16 | address: contract.address,
17 | constructorArguments: [],
18 | });
19 | } catch (e) {
20 | if (typeof e === "string") {
21 | console.log(e.toUpperCase()); // works, `e` narrowed to string
22 | } else if (e instanceof Error) {
23 | console.log(e.message); // works, `e` narrowed to Error
24 | }
25 | }
26 | }
27 |
28 | main().catch((error) => {
29 | console.error(error);
30 | process.exitCode = 1;
31 | });
32 |
--------------------------------------------------------------------------------
/scripts/MasterChefReward.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "MasterChefReward";
6 |
7 | // Specify need before deploying contract
8 | const reward = "0x1B815d120B3eF02039Ee11dC2d33DE7aA4a8C603"; // Any ERC20 token
9 | const rewardPerBlock = 10000000000000;
10 |
11 | const ownerAddress = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
12 |
13 | async function main() {
14 | const args = [reward, rewardPerBlock];
15 | const factory = await ethers.getContractFactory(contractName);
16 | const contract = await factory.deploy(...args);
17 | await contract.deployed();
18 | console.log(`${contractName} deployed to: ${contract.address}`);
19 |
20 | // await contract.add(1000, weToken, '0x0000000000000000000000000000000000000000'); // Add pool for each weToken manually
21 |
22 | await new Promise((resolve) => setTimeout(resolve, 10000));
23 | await contract.transferOwnership(ownerAddress);
24 | await new Promise((resolve) => setTimeout(resolve, 10000));
25 | try {
26 | await run("verify:verify", {
27 | address: contract.address,
28 | constructorArguments: args,
29 | });
30 | } catch (e) {
31 | if (typeof e === "string") {
32 | console.log(e.toUpperCase()); // works, `e` narrowed to string
33 | } else if (e instanceof Error) {
34 | console.log(e.message); // works, `e` narrowed to Error
35 | }
36 | }
37 | }
38 |
39 | main().catch((error) => {
40 | console.error(error);
41 | process.exitCode = 1;
42 | });
43 |
--------------------------------------------------------------------------------
/scripts/MasterChefWoo.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "MasterChefWoo";
6 |
7 | // Specify need before deploying contract
8 | const xWoo = "0x9BCf8b0B62F220f3900e2dc42dEB85C3f79b405B"; // Only xWOO
9 | const xWooPerBlock = 10000000000000;
10 |
11 | const ownerAddress = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
12 |
13 | async function main() {
14 | const args = [xWoo, xWooPerBlock];
15 | const factory = await ethers.getContractFactory(contractName);
16 | const contract = await factory.deploy(...args);
17 | await contract.deployed();
18 | console.log(`${contractName} deployed to: ${contract.address}`);
19 |
20 | // await contract.add(1000, weToken, '0x0000000000000000000000000000000000000000'); // Add pool for each weToken manually
21 |
22 | await new Promise((resolve) => setTimeout(resolve, 10000));
23 | await contract.transferOwnership(ownerAddress);
24 | await new Promise((resolve) => setTimeout(resolve, 10000));
25 | try {
26 | await run("verify:verify", {
27 | address: contract.address,
28 | constructorArguments: args,
29 | });
30 | } catch (e) {
31 | if (typeof e === "string") {
32 | console.log(e.toUpperCase()); // works, `e` narrowed to string
33 | } else if (e instanceof Error) {
34 | console.log(e.message); // works, `e` narrowed to Error
35 | }
36 | }
37 | }
38 |
39 | main().catch((error) => {
40 | console.error(error);
41 | process.exitCode = 1;
42 | });
43 |
--------------------------------------------------------------------------------
/scripts/WooAccessManager.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooAccessManager";
6 |
7 | // Specify need before deploying contract
8 | const buybackAdmin = "0xb08Dc5670682658A77841Db446B226dd355527f2";
9 | const settleAdmin = "0x3668ba88A32332269483a0EB2406A7f8149b486D";
10 | const marketMaker = "0x4c298512e78C1FA8fc36c8f9c0a8B9522e5fB48c";
11 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
12 |
13 | async function main() {
14 | const factory = await ethers.getContractFactory(contractName);
15 | const contract = await factory.deploy();
16 | await contract.deployed();
17 | console.log(`${contractName} deployed to: ${contract.address}`);
18 |
19 | await new Promise((resolve) => setTimeout(resolve, 10000));
20 | await contract.setFeeAdmin(buybackAdmin, true);
21 |
22 | await new Promise((resolve) => setTimeout(resolve, 10000));
23 | await contract.setVaultAdmin(buybackAdmin, true);
24 |
25 | await new Promise((resolve) => setTimeout(resolve, 10000));
26 | await contract.setVaultAdmin(settleAdmin, true);
27 |
28 | await new Promise((resolve) => setTimeout(resolve, 10000));
29 | await contract.setVaultAdmin(marketMaker, true);
30 |
31 | // await contract.setRebateAdmin(wooFeeManager, true); // Set WooFeeManager as rebateAdmin manually
32 |
33 | await new Promise((resolve) => setTimeout(resolve, 10000));
34 | await contract.transferOwnership(owner);
35 |
36 | try {
37 | await run("verify:verify", {
38 | address: contract.address,
39 | constructorArguments: [],
40 | });
41 | } catch (e) {
42 | if (typeof e === "string") {
43 | console.log(e.toUpperCase()); // works, `e` narrowed to string
44 | } else if (e instanceof Error) {
45 | console.log(e.message); // works, `e` narrowed to Error
46 | }
47 | }
48 | }
49 |
50 | main().catch((error) => {
51 | console.error(error);
52 | process.exitCode = 1;
53 | });
54 |
--------------------------------------------------------------------------------
/scripts/WooCrossChainRouter.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooCrossChainRouter";
6 |
7 | // Specify need before deploying contract
8 | const weth = "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270";
9 | const wooRouter = "0x817Eb46D60762442Da3D931Ff51a30334CA39B74";
10 | const stargateRouter = "0x45A01E4e04F14f7A4a6702c74187c5F6222033cd";
11 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
12 |
13 | const sgChainIdMapping: {[key: number]: string} = {
14 | 102: "0xd12D239b781e34E0AAa106159940803A07E31a67",
15 | 106: "0x1E6bB552ac038c6AFB6EC5Db6B06fDd106e31e33",
16 | // 109: "0x574b9cec19553435B360803D8B4De2a5b2C008Fd", // Don't set the local chain that you're deploying
17 | 112: "0x28D2B949024FE50627f1EbC5f0Ca3Ca721148E40",
18 | 110: "0x44dF096D2600C6a6db77899dB3DE3AeCff746cb8",
19 | 111: "0x655e2FE03fe19327239b5294a556965192386a7b",
20 | }
21 |
22 | async function main() {
23 | const args = [weth, wooRouter, stargateRouter];
24 | const factory = await ethers.getContractFactory(contractName);
25 | const contract = await factory.deploy(...args);
26 | await contract.deployed();
27 | console.log(`${contractName} deployed to: ${contract.address}`);
28 |
29 | await new Promise((resolve) => setTimeout(resolve, 10000));
30 | // eslint-disable-next-line prefer-const
31 | for (let chainId in sgChainIdMapping) {
32 | await contract.setWooCrossChainRouter(chainId, sgChainIdMapping[chainId]);
33 | await new Promise((resolve) => setTimeout(resolve, 10000));
34 | }
35 |
36 | await contract.transferOwnership(owner);
37 |
38 | try {
39 | await run("verify:verify", {
40 | address: contract.address,
41 | constructorArguments: args,
42 | });
43 | } catch (e) {
44 | if (typeof e === "string") {
45 | console.log(e.toUpperCase()); // works, `e` narrowed to string
46 | } else if (e instanceof Error) {
47 | console.log(e.message); // works, `e` narrowed to Error
48 | }
49 | }
50 | }
51 |
52 | main().catch((error) => {
53 | console.error(error);
54 | process.exitCode = 1;
55 | });
56 |
57 |
--------------------------------------------------------------------------------
/scripts/WooFeeManager.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooFeeManager";
6 |
7 | // Specify need before deploying contract
8 | const quoteToken = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
9 | const wooRebateManager = "0x913E116cD0E279763B0419798c0bA18F9311B390";
10 | const wooVaultManager = "0x88748243DE01c4F3C103F2De2833f39F6807db17";
11 | const wooAccessManager = "0x925AFA2318825FCAC673Ef4eF551208b125dd965";
12 | const treasury = "0xBD9D33926Da514586201995cf20FEc9f21133166";
13 | const vaultRewardRate = ethers.utils.parseEther("0.8");
14 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
15 |
16 | async function main() {
17 | const args = [quoteToken, wooRebateManager, wooVaultManager, wooAccessManager, treasury]
18 | const factory = await ethers.getContractFactory(contractName);
19 | const contract = await factory.deploy(...args);
20 | await contract.deployed();
21 | console.log(`${contractName} deployed to: ${contract.address}`);
22 |
23 | await new Promise((resolve) => setTimeout(resolve, 10000));
24 | await contract.setVaultRewardRate(vaultRewardRate);
25 |
26 | await new Promise((resolve) => setTimeout(resolve, 10000));
27 | await contract.transferOwnership(owner);
28 |
29 | try {
30 | await run("verify:verify", {
31 | address: contract.address,
32 | constructorArguments: args,
33 | });
34 | } catch (e) {
35 | if (typeof e === "string") {
36 | console.log(e.toUpperCase()); // works, `e` narrowed to string
37 | } else if (e instanceof Error) {
38 | console.log(e.message); // works, `e` narrowed to Error
39 | }
40 | }
41 | }
42 |
43 | main().catch((error) => {
44 | console.error(error);
45 | process.exitCode = 1;
46 | });
47 |
--------------------------------------------------------------------------------
/scripts/WooPPV2.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooPPV2";
6 |
7 | // Specify need before deploying contract
8 | const quoteToken = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
9 | const wooracle = "0xeFF23B4bE1091b53205E35f3AfCD9C7182bf3062";
10 | const feeAddr = "0x938021351425dbfa606Ed2B81Fc66952283e0Dd5";
11 | const admin = "0xDe95557D3c243e116E40dD8e933c4c7A3939d515";
12 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
13 | const baseFeeRate = 25;
14 | const baseTokens = [
15 | "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", // WMATIC
16 | "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619", // WETH
17 | "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6", // WBTC
18 | "0x1B815d120B3eF02039Ee11dC2d33DE7aA4a8C603", // WOO
19 | ];
20 |
21 | async function main() {
22 | const args = [quoteToken];
23 | const factory = await ethers.getContractFactory(contractName);
24 | const contract = await factory.deploy(...args);
25 | await contract.deployed();
26 | console.log(`${contractName} deployed to: ${contract.address}`);
27 |
28 | await new Promise((resolve) => setTimeout(resolve, 10000));
29 | await contract.init(wooracle, feeAddr); // Set wooracle and feeAddr
30 |
31 | // await contract.setLendManager(wooLendingManager); // Set WooLendingManager for each underlying token manually
32 |
33 | await new Promise((resolve) => setTimeout(resolve, 10000));
34 | await contract.setAdmin(admin, true);
35 |
36 | // eslint-disable-next-line prefer-const
37 | for (let i in baseTokens) {
38 | await contract.setFeeRate(baseTokens[i], baseFeeRate);
39 | await new Promise((resolve) => setTimeout(resolve, 10000));
40 | }
41 |
42 | await contract.transferOwnership(owner);
43 |
44 | try {
45 | await run("verify:verify", {
46 | address: contract.address,
47 | constructorArguments: args,
48 | });
49 | } catch (e) {
50 | if (typeof e === "string") {
51 | console.log(e.toUpperCase()); // works, `e` narrowed to string
52 | } else if (e instanceof Error) {
53 | console.log(e.message); // works, `e` narrowed to Error
54 | }
55 | }
56 | }
57 |
58 | main().catch((error) => {
59 | console.error(error);
60 | process.exitCode = 1;
61 | });
62 |
--------------------------------------------------------------------------------
/scripts/WooRebateManager.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooRebateManager";
6 |
7 | // Specify need before deploying contract
8 | const quoteToken = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
9 | const rewardToken = quoteToken;
10 | const wooAccessManager = "0x925AFA2318825FCAC673Ef4eF551208b125dd965";
11 | const testRebateBroker = "0xea02DCC6fe3eC1F2a433fF8718677556a3bb3618";
12 | const testRebateRate = ethers.utils.parseEther("0.2");
13 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
14 |
15 | async function main() {
16 | const args = [quoteToken, rewardToken, wooAccessManager]
17 | const factory = await ethers.getContractFactory(contractName);
18 | const contract = await factory.deploy(...args);
19 | await contract.deployed();
20 | console.log(`${contractName} deployed to: ${contract.address}`);
21 |
22 | await new Promise((resolve) => setTimeout(resolve, 10000));
23 | await contract.setRebateRate(testRebateBroker, testRebateRate);
24 |
25 | // await contract.setWooRouter(wooRouterV2); // Set WooRouterV2 manually
26 |
27 | await new Promise((resolve) => setTimeout(resolve, 10000));
28 | await contract.transferOwnership(owner);
29 |
30 | try {
31 | await run("verify:verify", {
32 | address: contract.address,
33 | constructorArguments: args,
34 | });
35 | } catch (e) {
36 | if (typeof e === "string") {
37 | console.log(e.toUpperCase()); // works, `e` narrowed to string
38 | } else if (e instanceof Error) {
39 | console.log(e.message); // works, `e` narrowed to Error
40 | }
41 | }
42 | }
43 |
44 | main().catch((error) => {
45 | console.error(error);
46 | process.exitCode = 1;
47 | });
48 |
--------------------------------------------------------------------------------
/scripts/WooRouterV2.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooRouterV2";
6 |
7 | // Specify need before deploying contract
8 | const weth = "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270";
9 | const pool = "0x7081A38158BD050Ae4a86e38E0225Bc281887d7E";
10 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
11 |
12 | async function main() {
13 | const args = [weth, pool];
14 | const factory = await ethers.getContractFactory(contractName);
15 | const contract = await factory.deploy(...args);
16 | await contract.deployed();
17 | console.log(`${contractName} deployed to: ${contract.address}`);
18 |
19 | // await contract.setWhitelisted(target, true); // Set whitelisted to support externalSwap manually
20 |
21 | await new Promise((resolve) => setTimeout(resolve, 10000));
22 |
23 | await contract.transferOwnership(owner);
24 |
25 | try {
26 | await run("verify:verify", {
27 | address: contract.address,
28 | constructorArguments: args,
29 | });
30 | } catch (e) {
31 | if (typeof e === "string") {
32 | console.log(e.toUpperCase()); // works, `e` narrowed to string
33 | } else if (e instanceof Error) {
34 | console.log(e.message); // works, `e` narrowed to Error
35 | }
36 | }
37 | }
38 |
39 | main().catch((error) => {
40 | console.error(error);
41 | process.exitCode = 1;
42 | });
43 |
--------------------------------------------------------------------------------
/scripts/WooVaultManager.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooVaultManager";
6 |
7 | // Specify need before deploying contract
8 | const quoteToken = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
9 | const rewardToken = "0x1B815d120B3eF02039Ee11dC2d33DE7aA4a8C603";
10 | const wooAccessManager = "0x925AFA2318825FCAC673Ef4eF551208b125dd965";
11 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
12 |
13 | async function main() {
14 | const args = [quoteToken, rewardToken, wooAccessManager];
15 | const factory = await ethers.getContractFactory(contractName);
16 | const contract = await factory.deploy(...args);
17 | await contract.deployed();
18 | console.log(`${contractName} deployed to: ${contract.address}`);
19 |
20 | // await contract.setWooRouter(wooRouterV2); // Set WooRouterV2 manually
21 | // await contract.setVaultWeight(stakingVault, 100); // Set vault weight manually
22 |
23 | await new Promise((resolve) => setTimeout(resolve, 10000));
24 | await contract.transferOwnership(owner);
25 |
26 | try {
27 | await run("verify:verify", {
28 | address: contract.address,
29 | constructorArguments: args,
30 | });
31 | } catch (e) {
32 | if (typeof e === "string") {
33 | console.log(e.toUpperCase()); // works, `e` narrowed to string
34 | } else if (e instanceof Error) {
35 | console.log(e.message); // works, `e` narrowed to Error
36 | }
37 | }
38 | }
39 |
40 | main().catch((error) => {
41 | console.error(error);
42 | process.exitCode = 1;
43 | });
44 |
--------------------------------------------------------------------------------
/scripts/WooracleV2.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers, run } from "hardhat";
3 |
4 | // eslint-disable-next-line prefer-const
5 | let contractName = "WooracleV2";
6 |
7 | const quoteToken = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
8 | const owner = "0x7C8A5d20b22Ce9b369C043A3E0091b5575B732d9";
9 | const tokenToCLOracle: {[key: string]: string} = {
10 | "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270": "0xAB594600376Ec9fD91F8e885dADF0CE036862dE0", // WMATIC
11 | "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619": "0xF9680D99D6C9589e2a93a78A04A279e509205945", // WETH
12 | "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6": "0xDE31F8bFBD8c84b5360CFACCa3539B938dd78ae6", // WBTC
13 | "0x1B815d120B3eF02039Ee11dC2d33DE7aA4a8C603": "0x6a99EC84819FB7007dd5D032068742604E755c56", // WOO
14 | "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174": "0xfE4A8cc5b5B2366C1B58Bea3858e81843581b2F7", // USDC
15 | };
16 |
17 | async function main() {
18 | const factory = await ethers.getContractFactory(contractName);
19 | const contract = await factory.deploy();
20 | await contract.deployed();
21 | console.log(`${contractName} deployed to: ${contract.address}`);
22 |
23 | await new Promise((resolve) => setTimeout(resolve, 10000));
24 | await contract.setQuoteToken(quoteToken, tokenToCLOracle[quoteToken]);
25 |
26 | await new Promise((resolve) => setTimeout(resolve, 10000));
27 |
28 | for (let token in tokenToCLOracle) {
29 | await contract.setCLOracle(token, tokenToCLOracle[token], true);
30 | await new Promise((resolve) => setTimeout(resolve, 10000));
31 | }
32 |
33 | // await contract.setAdmin(wooPPV2, true); // Set WooPPV2 as admin manually
34 |
35 | await contract.transferOwnership(owner);
36 |
37 | try {
38 | await run("verify:verify", {
39 | address: contract.address,
40 | constructorArguments: [],
41 | });
42 | } catch (e) {
43 | if (typeof e === "string") {
44 | console.log(e.toUpperCase()); // works, `e` narrowed to string
45 | } else if (e instanceof Error) {
46 | console.log(e.message); // works, `e` narrowed to Error
47 | }
48 | }
49 | }
50 |
51 | main().catch((error) => {
52 | console.error(error);
53 | process.exitCode = 1;
54 | });
55 |
--------------------------------------------------------------------------------
/scripts/deploy.ts:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line node/no-unpublished-import
2 | import { ethers } from "hardhat";
3 |
4 | async function main() {
5 | const Greeter = await ethers.getContractFactory("Greeter");
6 | const greeter = await Greeter.deploy("Hello, Hardhat!");
7 | await greeter.deployed();
8 | console.log("Greeter deployed to:", greeter.address);
9 | }
10 |
11 | main().catch((error) => {
12 | console.error(error);
13 | process.exitCode = 1;
14 | });
15 |
--------------------------------------------------------------------------------
/test/foundry/AMMTests.t.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | // import {Greeter} from "../../contracts/Greeter.sol";
5 | import {TestHelpers} from "./TestHelpers.sol";
6 |
7 | import {WooPPV2} from "../../contracts/WooPPV2.sol";
8 | import {WooRouterV2} from "../../contracts/WooRouterV2.sol";
9 | import {WooracleV2_2} from "../../contracts/wooracle/WooracleV2_2.sol";
10 |
11 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
12 |
13 | import "forge-std/console.sol";
14 |
15 | contract AMMTests is TestHelpers {
16 |
17 | WooPPV2 public pool = WooPPV2(0xEd9e3f98bBed560e66B89AaC922E29D4596A9642);
18 | WooracleV2_2 public oracle = WooracleV2_2(0x2A375567f5E13F6bd74fDa7627Df3b1Af6BfA5a6);
19 |
20 | address private constant USDC_TOKEN = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831; // quote
21 | address private constant WBTC = 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f;
22 | address private constant OWNER = 0xDe95557D3c243e116E40dD8e933c4c7A3939d515;
23 | address private constant TAPIR = address(69);
24 |
25 | uint loopAm = 1000;
26 | uint amountToSell = 200_000 * 1e6;
27 |
28 | function setUp() public {
29 | deal(USDC_TOKEN, TAPIR, amountToSell * 10); // 1M USDC
30 | deal(WBTC, OWNER, 100 * 1e8); // 100 btc
31 |
32 | vm.prank(OWNER);
33 | IERC20(WBTC).approve(address(pool), type(uint256).max);
34 |
35 | vm.prank(OWNER);
36 | pool.deposit(WBTC, 100 * 1e8);
37 | }
38 |
39 | // run this command to run the test:
40 | // forge test --fork-url https://arb1.arbitrum.io/rpc --match-contract AMMTests -vv
41 | function test_Sell_Partial() public {
42 | // sell 100k-100k-100k....100k 10 times, up to 1M USDC
43 | vm.startPrank(TAPIR);
44 |
45 | uint received;
46 | for (uint i; i < loopAm; ++i) {
47 | IERC20(USDC_TOKEN).transfer(address(pool), amountToSell / loopAm);
48 | received += pool.swap(USDC_TOKEN, WBTC, amountToSell / loopAm, 0, payable(TAPIR), TAPIR);
49 | }
50 | vm.stopPrank();
51 | console.log("Received", received);
52 | }
53 |
54 | function test_Sell_One_Go() public {
55 | // sell 1M USDC directly
56 | vm.startPrank(TAPIR);
57 |
58 | IERC20(USDC_TOKEN).transfer(address(pool), amountToSell);
59 | uint received = pool.swap(USDC_TOKEN, WBTC, amountToSell, 0, payable(TAPIR), TAPIR);
60 |
61 | vm.stopPrank();
62 | console.log("Received", received);
63 | }
64 | }
--------------------------------------------------------------------------------
/test/foundry/MockWETHOracle.t.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5 | import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
6 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 |
8 | import "forge-std/console.sol";
9 |
10 | contract MockWETHOracle is Ownable, ReentrancyGuard {
11 |
12 | function decimals() external view returns (uint8 _decimals) {
13 | _decimals = 8;
14 | }
15 |
16 | function description() external view returns (string memory _desc) {
17 | _desc = "WETH";
18 | }
19 |
20 | //function version() external view returns (uint256);
21 |
22 | /// getRoundData and latestRoundData should both raise "No data present"
23 | /// if they do not have data to report, instead of returning unset values
24 | /// which could be misinterpreted as actual reported values.
25 | // function getRoundData(uint80 _roundId)
26 | // external
27 | // view
28 | // returns (
29 | // uint80 roundId,
30 | // int256 answer,
31 | // uint256 startedAt,
32 | // uint256 updatedAt,
33 | // uint80 answeredInRound
34 | // );
35 |
36 | function latestRoundData()
37 | external
38 | view
39 | returns (
40 | uint80 roundId,
41 | int256 answer,
42 | uint256 startedAt,
43 | uint256 updatedAt,
44 | uint80 answeredInRound
45 | ) {
46 | roundId = 18446744073710118040;
47 | answer = 320976000000;
48 | startedAt = 1712978791;
49 | updatedAt = 1712978791;
50 | answeredInRound = 18446744073710118040;
51 | }
52 | }
--------------------------------------------------------------------------------
/test/foundry/MockWooOracle.t.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5 | import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
6 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
7 |
8 | import "forge-std/console.sol";
9 |
10 | contract MockWooOracle is Ownable, ReentrancyGuard {
11 |
12 | function decimals() external view returns (uint8 _decimals) {
13 | _decimals = 8;
14 | }
15 |
16 | function description() external view returns (string memory _desc) {
17 | _desc = "WOO";
18 | }
19 |
20 | //function version() external view returns (uint256);
21 |
22 | /// getRoundData and latestRoundData should both raise "No data present"
23 | /// if they do not have data to report, instead of returning unset values
24 | /// which could be misinterpreted as actual reported values.
25 | // function getRoundData(uint80 _roundId)
26 | // external
27 | // view
28 | // returns (
29 | // uint80 roundId,
30 | // int256 answer,
31 | // uint256 startedAt,
32 | // uint256 updatedAt,
33 | // uint80 answeredInRound
34 | // );
35 |
36 | function latestRoundData()
37 | external
38 | view
39 | returns (
40 | uint80 roundId,
41 | int256 answer,
42 | uint256 startedAt,
43 | uint256 updatedAt,
44 | uint80 answeredInRound
45 | ) {
46 | roundId = 18446744073709567695;
47 | //answer = 40403876;
48 | answer = 100000000;
49 | startedAt = 1712759118;
50 | updatedAt = 1712759118;
51 | answeredInRound = 18446744073709567695;
52 | }
53 | }
--------------------------------------------------------------------------------
/test/foundry/TestHelpers.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | import {Test} from "../../lib/forge-std/src/Test.sol";
5 |
6 | abstract contract TestHelpers is Test {
7 | address public user1 = address(1);
8 | address public user2 = address(2);
9 | address public user3 = address(3);
10 | address public user4 = address(4);
11 |
12 | modifier asPrankedUser(address user) {
13 | vm.startPrank(user);
14 | _;
15 | vm.stopPrank();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/test/foundry/TestWooracleV2_2.t.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: MIT
2 | pragma solidity ^0.8.0;
3 |
4 | // import {Greeter} from "../../contracts/Greeter.sol";
5 | import {TestHelpers} from "./TestHelpers.sol";
6 |
7 | import {WooPPV2} from "../../contracts/WooPPV2.sol";
8 | import {WooRouterV2} from "../../contracts/WooRouterV2.sol";
9 | import {WooracleV2_2} from "../../contracts/wooracle/WooracleV2_2.sol";
10 |
11 | import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
12 |
13 | import "forge-std/console.sol";
14 |
15 | contract TestWooracleV2_2 is TestHelpers {
16 |
17 | WooPPV2 public pool;
18 | WooRouterV2 public router;
19 | WooracleV2_2 public oracle;
20 |
21 | address private constant ADMIN = address(1);
22 | address private constant ATTACKER = address(2);
23 | address private constant FEE_ADDR = address(4);
24 |
25 | // mainnet
26 | address private constant WBTC = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
27 | address private constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
28 | address private constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; // QUOTE TOKEN
29 | address private constant WOO = 0x4691937a7508860F876c9c0a2a617E7d9E945D4B;
30 | address private constant USDC_USD_ORACLE = 0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6;
31 | address private constant ETH_USD_ORACLE = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419;
32 |
33 | uint128 private constant MAX_NOTIONAL_USDC = 5000_000 * 1e18;
34 | uint128 private constant MAX_GAMMA = type(uint128).max;
35 |
36 | // deployed addresses
37 |
38 | function setUp() public {
39 | vm.startPrank(ADMIN);
40 | pool = new WooPPV2(USDC);
41 | router = new WooRouterV2(WETH, address(pool));
42 | oracle = new WooracleV2_2();
43 |
44 | oracle.setQuoteToken(USDC, USDC_USD_ORACLE);
45 | oracle.setCLOracle(WETH, ETH_USD_ORACLE, true);
46 | oracle.setWooPP(address(pool));
47 |
48 | oracle.postState(WETH, 346288977288, 363000000000000, 1000000000);
49 | oracle.setGuardian(ADMIN, true);
50 | oracle.setRange(WOO, 9000, 110000000);
51 | oracle.setAdmin(address(pool), true);
52 |
53 | pool.setWooracle(address(oracle));
54 | pool.setTokenInfo(WETH, 0, MAX_GAMMA, MAX_NOTIONAL_USDC);
55 | pool.setTokenInfo(WOO, 0, MAX_GAMMA, MAX_NOTIONAL_USDC);
56 | pool.setFeeAddr(FEE_ADDR);
57 | vm.stopPrank();
58 | }
59 |
60 | // forge test --fork-url https://rpc.ankr.com/eth --match-contract TestWooracleV2_2 -vvvv
61 | function test_Wooracle() public {
62 | vm.startPrank(ADMIN);
63 |
64 | oracle.woState(WETH);
65 | // (346288977288, 363000000000000, 1000000000, true)
66 |
67 | oracle.postState(WETH, 349833999632, 655000000000000, 1000000000);
68 | oracle.woState(WETH);
69 |
70 | //post (349833999632, 655000000000000, 1000000000)
71 | // (349833999632, 9773989383877141, 1000000000, true)
72 |
73 | oracle.postState(WETH, 348921000000, 566000000000000, 1000000000);
74 | oracle.woState(WETH);
75 |
76 | oracle.postState(WETH, 350021000000, 111000000000000, 1000000000);
77 | oracle.woState(WETH);
78 |
79 | oracle.postState(WETH, 351121000000, 111000000000000, 1000000000);
80 | oracle.woState(WETH);
81 |
82 | oracle.postState(WETH, 345420000000, 861000000000000, 1000000000);
83 | oracle.postState(WBTC, 6846630000000, 650000000000000, 1000000000);
84 | oracle.woState(WETH);
85 | oracle.woState(WBTC);
86 |
87 | oracle.postState(WETH, 345400000000, 0, 1000000000);
88 | oracle.woState(WETH);
89 |
90 | oracle.postState(WETH, 345820000000, 861000000000000, 1000000000);
91 | oracle.postState(WBTC, 6859100000000, 848000000000000, 1000000000);
92 | oracle.woState(WETH);
93 | oracle.woState(WBTC);
94 |
95 | oracle.postState(WETH, 345820000000, 111000000000000, 1000000000);
96 | oracle.woState(WETH);
97 |
98 | oracle.postState(WETH, 345820000000, 0, 0);
99 | oracle.woState(WETH);
100 |
101 | oracle.postState(WETH, 345830000000, 0, 0);
102 | oracle.woState(WETH);
103 |
104 | oracle.postState(WETH, 345820000000, 111000000000000, 1000000000);
105 | oracle.woState(WETH);
106 |
107 | vm.stopPrank();
108 | }
109 |
110 | }
--------------------------------------------------------------------------------
/test/typescript/MasterChefWoo.test.ts:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | ░██╗░░░░░░░██╗░█████╗░░█████╗░░░░░░░███████╗██╗
4 | ░██║░░██╗░░██║██╔══██╗██╔══██╗░░░░░░██╔════╝██║
5 | ░╚██╗████╗██╔╝██║░░██║██║░░██║█████╗█████╗░░██║
6 | ░░████╔═████║░██║░░██║██║░░██║╚════╝██╔══╝░░██║
7 | ░░╚██╔╝░╚██╔╝░╚█████╔╝╚█████╔╝░░░░░░██║░░░░░██║
8 | ░░░╚═╝░░░╚═╝░░░╚════╝░░╚════╝░░░░░░░╚═╝░░░░░╚═╝
9 |
10 | *
11 | * MIT License
12 | * ===========
13 | *
14 | * Copyright (c) 2020 WooTrade
15 | *
16 | * Permission is hereby granted, free of charge, to any person obtaining a copy
17 | * of this software and associated documentation files (the "Software"), to deal
18 | * in the Software without restriction, including without limitation the rights
19 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20 | * copies of the Software, and to permit persons to whom the Software is
21 | * furnished to do so, subject to the following conditions:
22 | *
23 | * The above copyright notice and this permission notice shall be included in all
24 | * copies or substantial portions of the Software.
25 | *
26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 | */
33 |
34 | import { use } from "chai";
35 | import { Contract } from "ethers";
36 | import { ethers } from "hardhat";
37 | import { deployContract, solidity } from "ethereum-waffle";
38 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
39 |
40 | import { MasterChefWoo, WooSimpleRewarder } from "../../typechain";
41 | import TestERC20TokenArtifact from "../../artifacts/contracts/test/TestERC20Token.sol/TestERC20Token.json";
42 | import MasterChefWooArtifact from "../../artifacts/contracts/MasterChefWoo.sol/MasterChefWoo.json";
43 | import WooSimpleRewarderArtifact from "../../artifacts/contracts/WooSimpleRewarder.sol/WooSimpleRewarder.json";
44 |
45 | use(solidity);
46 |
47 | const { BigNumber } = ethers;
48 |
49 | const ONE = BigNumber.from(10).pow(18);
50 | const TOKEN_100 = ONE.mul(100);
51 |
52 | describe("MasterChefWoo tests", () => {
53 | let owner: SignerWithAddress;
54 |
55 | let masterCW: MasterChefWoo;
56 | let wooSR: WooSimpleRewarder;
57 | let xWooToken: Contract;
58 | let weToken: Contract;
59 | let rewardToken: Contract;
60 |
61 | let ownerAddr: string;
62 |
63 | before("Deploy contracts", async () => {
64 | const signers = await ethers.getSigners();
65 | owner = signers[0];
66 | ownerAddr = owner.address;
67 |
68 | xWooToken = await deployContract(owner, TestERC20TokenArtifact, []);
69 | weToken = await deployContract(owner, TestERC20TokenArtifact, []);
70 | rewardToken = await deployContract(owner, TestERC20TokenArtifact, []);
71 |
72 | masterCW = (await deployContract(owner, MasterChefWooArtifact, [xWooToken.address, 10])) as MasterChefWoo;
73 | console.log("MasterChefWoo address: ", masterCW.address);
74 | wooSR = (await deployContract(owner, WooSimpleRewarderArtifact, [
75 | rewardToken.address,
76 | weToken.address,
77 | masterCW.address,
78 | 20,
79 | ])) as WooSimpleRewarder;
80 | console.log("WooSimpleRewarder address: ", wooSR.address);
81 |
82 | await xWooToken.mint(ownerAddr, TOKEN_100);
83 | await weToken.mint(ownerAddr, TOKEN_100);
84 | await rewardToken.mint(ownerAddr, TOKEN_100);
85 | });
86 |
87 | describe("MasterChefWoo", () => {
88 | beforeEach("Deploy MasterChefWoo", async () => {
89 | console.log("Deploy");
90 | });
91 |
92 | it("test MasterChefWoo", async () => {
93 | console.log("MasterChefWoo tests");
94 | });
95 |
96 | it("test WooSimpleRewarder", async () => {
97 | console.log("WooSimpleRewarder tests");
98 | });
99 | });
100 | });
101 |
--------------------------------------------------------------------------------
/test/typescript/wooraclev2_zip_inherit.test.ts:
--------------------------------------------------------------------------------
1 | import { expect } from "chai";
2 | import { BigNumber, utils } from "ethers";
3 | import { ethers } from "hardhat";
4 | import { deployContract } from "ethereum-waffle";
5 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
6 | import { WooracleV2ZipInherit, WooracleV2, TestChainLink, TestQuoteChainLink } from "../../typechain";
7 | import WooracleV2ZipArtifact from "../../artifacts/contracts/wooracle/WooracleV2ZipInherit.sol/WooracleV2ZipInherit.json";
8 | import TestChainLinkArtifact from "../../artifacts/contracts/test/TestChainLink.sol/TestChainLink.json";
9 | import TestQuoteChainLinkArtifact from "../../artifacts/contracts/test/TestChainLink.sol/TestQuoteChainLink.json";
10 | import TestERC20TokenArtifact from "../../artifacts/contracts/test/TestERC20Token.sol/TestERC20Token.json";
11 | import exp from "constants";
12 |
13 |
14 | const BN_1E18 = BigNumber.from(10).pow(18);
15 | const BN_2E18 = BN_1E18.mul(2);
16 | const BN_1E8 = BigNumber.from(10).pow(8);
17 |
18 | const BN_1E16 = BigNumber.from(10).pow(18);
19 | const BN_2E16 = BN_1E16.mul(2);
20 | const ZERO = 0;
21 |
22 | async function getCurrentBlockTimestamp() {
23 | const blockNum = await ethers.provider.getBlockNumber();
24 | const block = await ethers.provider.getBlock(blockNum);
25 | return block.timestamp;
26 | }
27 |
28 | async function checkWooracleTimestamp(wooracleV2Zip: WooracleV2) {
29 | const currentBlockTimestamp = await getCurrentBlockTimestamp();
30 | expect(await wooracleV2Zip.timestamp()).to.gte(currentBlockTimestamp);
31 | }
32 |
33 | describe("WooracleV2ZipInherit", () => {
34 | let owner: SignerWithAddress;
35 |
36 | let wethToken: Contract;
37 | let wooToken: Contract;
38 |
39 | let wooracleV2Zip: WooracleV2ZipInherit;
40 | let chainlinkOne: TestChainLink;
41 | let chainlinkTwo: TestQuoteChainLink;
42 |
43 | beforeEach(async () => {
44 | const signers = await ethers.getSigners();
45 | owner = signers[0];
46 |
47 | wethToken = await deployContract(owner, TestERC20TokenArtifact, []);
48 | wooToken = await deployContract(owner, TestERC20TokenArtifact, []);
49 |
50 | wooracleV2Zip = (await deployContract(owner, WooracleV2ZipArtifact, [])) as WooracleV2ZipInherit;
51 |
52 | chainlinkOne = (await deployContract(owner, TestChainLinkArtifact, [])) as TestChainLink;
53 | chainlinkTwo = (await deployContract(owner, TestQuoteChainLinkArtifact, [])) as TestQuoteChainLink;
54 |
55 | await wooracleV2Zip.setBase(5, wethToken.address);
56 | await wooracleV2Zip.setBase(6, wooToken.address);
57 | });
58 |
59 | it("Init states", async () => {
60 | expect(await wooracleV2Zip.owner()).to.eq(owner.address);
61 | expect(await wooracleV2Zip.getBase(0)).to.eq("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
62 | expect(await wooracleV2Zip.getBase(5)).to.eq(wethToken.address);
63 | expect(await wooracleV2Zip.getBase(6)).to.eq(wooToken.address);
64 |
65 | // console.log(await wooracleV2Zip.state(wooToken.address));
66 | // console.log(await wooracleV2Zip.price(wethToken.address));
67 |
68 | const wooState = await wooracleV2Zip.state(wooToken.address);
69 | expect(wooState.price).to.be.eq(0);
70 | expect(wooState.spread).to.be.eq(0);
71 | expect(wooState.coeff).to.be.eq(0);
72 | expect(wooState.woFeasible).to.be.eq(false);
73 |
74 | const price = await wooracleV2Zip.price(wethToken.address);
75 | expect(price.priceOut).to.be.eq(0);
76 | expect(price.feasible).to.be.eq(false);
77 | });
78 |
79 | it("Post prices", async () => {
80 | await owner.sendTransaction({
81 | to: wooracleV2Zip.address,
82 | data: _encode_woo_price()
83 | })
84 |
85 | console.log(await wooracleV2Zip.state(wooToken.address));
86 | const p_ret = await wooracleV2Zip.price(wooToken.address)
87 | console.log("price ", p_ret.priceOut.toNumber() / 1e8, p_ret.feasible);
88 |
89 | const ts = await wooracleV2Zip.timestamp();
90 | console.log("timestamp ", ts.toString(), p_ret.feasible);
91 |
92 | expect(p_ret.priceOut).to.be.eq(BigNumber.from("23020000"));
93 | expect(p_ret.feasible).to.be.eq(true);
94 | expect(ts).to.be.gt(0);
95 | });
96 |
97 | function _encode_woo_price() {
98 | /*
99 | op = 0
100 | len = 1
101 | (base, p)
102 | */
103 | let _calldata = new Uint8Array(1 + 5);
104 |
105 | // 0xC0 : 11000000
106 | // 0x3F : 00111111
107 | _calldata[0] = (0 << 6) + (1 & 0x3F);
108 | _calldata[1] = 6; // woo token
109 |
110 | // price: 0.23020
111 | // 23020000 (decimal = 8)
112 | let price = BigNumber.from(2302).shl(5).add(4);
113 | // console.log("woo price: ", price.toString());
114 | _calldata[2] = price.shr(24).mod(256).toNumber();
115 | _calldata[3] = price.shr(16).mod(256).toNumber();
116 | _calldata[4] = price.shr(8).mod(256).toNumber();
117 | _calldata[5] = price.shr(0).mod(256).toNumber();
118 |
119 | console.log("test woo calldata: ", _calldata);
120 |
121 | return _calldata;
122 | }
123 |
124 | async function _get_id(base:String) {
125 | for (let i = 0; i < 5 + 2; ++i) {
126 | if (base == await wooracleV2Zip.getBase(i))
127 | return i;
128 | }
129 | return 0;
130 | }
131 | });
132 |
--------------------------------------------------------------------------------
/test/typescript/wooraclev3_zip_inherit.test.ts:
--------------------------------------------------------------------------------
1 | import { expect } from "chai";
2 | import { BigNumber, utils } from "ethers";
3 | import { ethers } from "hardhat";
4 | import { deployContract } from "ethereum-waffle";
5 | import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
6 | import { WooracleV3ZipInherit, WooracleV3, TestChainLink, TestQuoteChainLink } from "../../typechain";
7 | import WooracleV3ZipArtifact from "../../artifacts/contracts/wooracle/WooracleV3ZipInherit.sol/WooracleV3ZipInherit.json";
8 | import TestChainLinkArtifact from "../../artifacts/contracts/test/TestChainLink.sol/TestChainLink.json";
9 | import TestQuoteChainLinkArtifact from "../../artifacts/contracts/test/TestChainLink.sol/TestQuoteChainLink.json";
10 | import TestERC20TokenArtifact from "../../artifacts/contracts/test/TestERC20Token.sol/TestERC20Token.json";
11 | import exp from "constants";
12 |
13 |
14 | const BN_1E18 = BigNumber.from(10).pow(18);
15 | const BN_2E18 = BN_1E18.mul(2);
16 | const BN_1E8 = BigNumber.from(10).pow(8);
17 |
18 | const BN_1E16 = BigNumber.from(10).pow(18);
19 | const BN_2E16 = BN_1E16.mul(2);
20 | const ZERO = 0;
21 |
22 | async function getCurrentBlockTimestamp() {
23 | const blockNum = await ethers.provider.getBlockNumber();
24 | const block = await ethers.provider.getBlock(blockNum);
25 | return block.timestamp;
26 | }
27 |
28 | describe("WooracleV3ZipInherit", () => {
29 | let owner: SignerWithAddress;
30 |
31 | let wethToken: Contract;
32 | let wooToken: Contract;
33 |
34 | let wooracleV3Zip: WooracleV3ZipInherit;
35 | let chainlinkOne: TestChainLink;
36 | let chainlinkTwo: TestQuoteChainLink;
37 |
38 | beforeEach(async () => {
39 | const signers = await ethers.getSigners();
40 | owner = signers[0];
41 |
42 | wethToken = await deployContract(owner, TestERC20TokenArtifact, []);
43 | wooToken = await deployContract(owner, TestERC20TokenArtifact, []);
44 |
45 | wooracleV3Zip = (await deployContract(owner, WooracleV3ZipArtifact, [])) as WooracleV3ZipInherit;
46 |
47 | chainlinkOne = (await deployContract(owner, TestChainLinkArtifact, [])) as TestChainLink;
48 | chainlinkTwo = (await deployContract(owner, TestQuoteChainLinkArtifact, [])) as TestQuoteChainLink;
49 |
50 | await wooracleV3Zip.setBase(5, wethToken.address);
51 | await wooracleV3Zip.setBase(6, wooToken.address);
52 | });
53 |
54 | it("Init states", async () => {
55 | expect(await wooracleV3Zip.owner()).to.eq(owner.address);
56 | expect(await wooracleV3Zip.getBase(0)).to.eq("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1");
57 | expect(await wooracleV3Zip.getBase(5)).to.eq(wethToken.address);
58 | expect(await wooracleV3Zip.getBase(6)).to.eq(wooToken.address);
59 |
60 | // console.log(await wooracleV3Zip.state(wooToken.address));
61 | // console.log(await wooracleV3Zip.price(wethToken.address));
62 |
63 | const wooState = await wooracleV3Zip.state(wooToken.address);
64 | expect(wooState.price).to.be.eq(0);
65 | expect(wooState.spread).to.be.eq(0);
66 | expect(wooState.coeff).to.be.eq(0);
67 | expect(wooState.woFeasible).to.be.eq(false);
68 |
69 | const price = await wooracleV3Zip.price(wethToken.address);
70 | expect(price.priceOut).to.be.eq(0);
71 | expect(price.feasible).to.be.eq(false);
72 | });
73 |
74 | it("Post prices", async () => {
75 | await owner.sendTransaction({
76 | to: wooracleV3Zip.address,
77 | data: _encode_woo_price()
78 | })
79 |
80 | console.log(await wooracleV3Zip.state(wooToken.address));
81 | const p_ret = await wooracleV3Zip.price(wooToken.address)
82 | console.log("price ", p_ret.priceOut.toNumber() / 1e8, p_ret.feasible);
83 |
84 | const ts = await wooracleV3Zip.timestamp();
85 | console.log("timestamp ", ts.toString(), p_ret.feasible);
86 |
87 | expect(p_ret.priceOut).to.be.eq(BigNumber.from("23020000"));
88 | expect(p_ret.feasible).to.be.eq(true);
89 | expect(ts).to.be.gt(0);
90 | });
91 |
92 | function _encode_woo_price() {
93 | /*
94 | op = 0
95 | len = 1
96 | (base, p)
97 | */
98 | let _calldata = new Uint8Array(1 + 5);
99 |
100 | // 0xC0 : 11000000
101 | // 0x3F : 00111111
102 | _calldata[0] = (0 << 6) + (1 & 0x3F);
103 | _calldata[1] = 6; // woo token
104 |
105 | // price: 0.23020
106 | // 23020000 (decimal = 8)
107 | let price = BigNumber.from(2302).shl(5).add(4);
108 | // console.log("woo price: ", price.toString());
109 | _calldata[2] = price.shr(24).mod(256).toNumber();
110 | _calldata[3] = price.shr(16).mod(256).toNumber();
111 | _calldata[4] = price.shr(8).mod(256).toNumber();
112 | _calldata[5] = price.shr(0).mod(256).toNumber();
113 |
114 | console.log("test woo calldata: ", _calldata);
115 |
116 | return _calldata;
117 | }
118 |
119 | async function _get_id(base:String) {
120 | for (let i = 0; i < 5 + 2; ++i) {
121 | if (base == await wooracleV3Zip.getBase(i))
122 | return i;
123 | }
124 | return 0;
125 | }
126 | });
127 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2018",
4 | "module": "commonjs",
5 | "strict": true,
6 | "esModuleInterop": true,
7 | "resolveJsonModule": true,
8 | "outDir": "dist",
9 | "declaration": true
10 | },
11 | "include": ["./scripts", "./test", "./typechain"],
12 | "files": ["./hardhat.config.ts"]
13 | }
14 |
--------------------------------------------------------------------------------