From 80b1aec803de7aec8c168b2ba43bca1f4096976c Mon Sep 17 00:00:00 2001 From: William Poulin Date: Sun, 19 Jun 2022 18:09:20 -0400 Subject: [PATCH] feat: migrated sushiswap-bentobox to studio --- .../sushiswap-bentobox.balance-fetcher.ts | 34 + ...entobox.vault.contract-position-fetcher.ts | 29 + .../sushiswap-bentobox.balance-fetcher.ts | 34 + ...entobox.vault.contract-position-fetcher.ts | 29 + .../contracts/abis/sushiswap-bentobox.json | 471 ++++++ .../contracts/ethers/SushiswapBentobox.ts | 1270 +++++++++++++++++ .../contracts/ethers/common.ts | 30 + .../factories/SushiswapBentobox__factory.ts | 1172 +++++++++++++++ .../contracts/ethers/factories/index.ts | 4 + .../contracts/ethers/index.ts | 6 + .../sushiswap-bentobox/contracts/index.ts | 23 + .../sushiswap-bentobox.balance-fetcher.ts | 34 + ...entobox.vault.contract-position-fetcher.ts | 29 + ....vault.contract-position-balance-helper.ts | 32 + ...bentobox.vault.contract-position-helper.ts | 103 ++ .../sushiswap-bentobox.balance-fetcher.ts | 34 + ...entobox.vault.contract-position-fetcher.ts | 30 + .../sushiswap-bentobox.definition.ts | 39 + .../sushiswap-bentobox.module.ts | 38 + 19 files changed, 3441 insertions(+) create mode 100644 src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.balance-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.vault.contract-position-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.balance-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.vault.contract-position-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/contracts/abis/sushiswap-bentobox.json create mode 100644 src/apps/sushiswap-bentobox/contracts/ethers/SushiswapBentobox.ts create mode 100644 src/apps/sushiswap-bentobox/contracts/ethers/common.ts create mode 100644 src/apps/sushiswap-bentobox/contracts/ethers/factories/SushiswapBentobox__factory.ts create mode 100644 src/apps/sushiswap-bentobox/contracts/ethers/factories/index.ts create mode 100644 src/apps/sushiswap-bentobox/contracts/ethers/index.ts create mode 100644 src/apps/sushiswap-bentobox/contracts/index.ts create mode 100644 src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.balance-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.vault.contract-position-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-balance-helper.ts create mode 100644 src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-helper.ts create mode 100644 src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.balance-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.vault.contract-position-fetcher.ts create mode 100644 src/apps/sushiswap-bentobox/sushiswap-bentobox.definition.ts create mode 100644 src/apps/sushiswap-bentobox/sushiswap-bentobox.module.ts diff --git a/src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.balance-fetcher.ts b/src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.balance-fetcher.ts new file mode 100644 index 000000000..5a5c7ad67 --- /dev/null +++ b/src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.balance-fetcher.ts @@ -0,0 +1,34 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present'; +import { BalanceFetcher } from '~balance/balance-fetcher.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionBalanceHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-balance-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const network = Network.ARBITRUM_MAINNET; + +@Register.BalanceFetcher(SUSHISWAP_BENTOBOX_DEFINITION.id, network) +export class ArbitrumSushiSwapBentoBoxBalanceFetcher implements BalanceFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionBalanceHelper) + private readonly balanceHelper: SushiSwapBentoBoxContractPositionBalanceHelper, + ) {} + + async getBalances(address: string) { + const balances = await this.balanceHelper.getBalances({ + address, + network, + bentoBoxAddress: '0x74c764d41b77dbbb4fe771dab1939b00b146894a', + }); + + return presentBalanceFetcherResponse([ + { + label: 'SushiSwap BentoBox', + assets: balances, + }, + ]); + } +} diff --git a/src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.vault.contract-position-fetcher.ts b/src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.vault.contract-position-fetcher.ts new file mode 100644 index 000000000..ecef9c5a2 --- /dev/null +++ b/src/apps/sushiswap-bentobox/arbitrum/sushiswap-bentobox.vault.contract-position-fetcher.ts @@ -0,0 +1,29 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { PositionFetcher } from '~position/position-fetcher.interface'; +import { ContractPosition } from '~position/position.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const appId = SUSHISWAP_BENTOBOX_DEFINITION.id; +const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id; +const network = Network.ARBITRUM_MAINNET; + +@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } }) +export class ArbitrumSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionHelper) + private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper, + ) {} + + async getPositions() { + return this.positionHelper.getPositions({ + bentoBoxAddress: '0x74c764d41b77dbbb4fe771dab1939b00b146894a', + network, + subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/arbitrum-bentobox', + }); + } +} diff --git a/src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.balance-fetcher.ts b/src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.balance-fetcher.ts new file mode 100644 index 000000000..4f3280942 --- /dev/null +++ b/src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.balance-fetcher.ts @@ -0,0 +1,34 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present'; +import { BalanceFetcher } from '~balance/balance-fetcher.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionBalanceHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-balance-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const network = Network.BINANCE_SMART_CHAIN_MAINNET; + +@Register.BalanceFetcher(SUSHISWAP_BENTOBOX_DEFINITION.id, network) +export class BscSushiSwapBentoBoxBalanceFetcher implements BalanceFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionBalanceHelper) + private readonly balanceHelper: SushiSwapBentoBoxContractPositionBalanceHelper, + ) {} + + async getBalances(address: string) { + const balances = await this.balanceHelper.getBalances({ + address, + network, + bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966', + }); + + return presentBalanceFetcherResponse([ + { + label: 'SushiSwap BentoBox', + assets: balances, + }, + ]); + } +} diff --git a/src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.vault.contract-position-fetcher.ts b/src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.vault.contract-position-fetcher.ts new file mode 100644 index 000000000..b444c7231 --- /dev/null +++ b/src/apps/sushiswap-bentobox/binance-smart-chain/sushiswap-bentobox.vault.contract-position-fetcher.ts @@ -0,0 +1,29 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { PositionFetcher } from '~position/position-fetcher.interface'; +import { ContractPosition } from '~position/position.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const appId = SUSHISWAP_BENTOBOX_DEFINITION.id; +const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id; +const network = Network.BINANCE_SMART_CHAIN_MAINNET; + +@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } }) +export class BscSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionHelper) + private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper, + ) {} + + async getPositions() { + return this.positionHelper.getPositions({ + bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966', + network, + subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/bsc-bentobox', + }); + } +} diff --git a/src/apps/sushiswap-bentobox/contracts/abis/sushiswap-bentobox.json b/src/apps/sushiswap-bentobox/contracts/abis/sushiswap-bentobox.json new file mode 100644 index 000000000..8f637f215 --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/abis/sushiswap-bentobox.json @@ -0,0 +1,471 @@ +[ + { + "inputs": [{ "internalType": "contract IERC20", "name": "wethToken_", "type": "address" }], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "masterContract", "type": "address" }, + { "indexed": false, "internalType": "bytes", "name": "data", "type": "bytes" }, + { "indexed": true, "internalType": "address", "name": "cloneAddress", "type": "address" } + ], + "name": "LogDeploy", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "share", "type": "uint256" } + ], + "name": "LogDeposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "borrower", "type": "address" }, + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "feeAmount", "type": "uint256" }, + { "indexed": true, "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "LogFlashLoan", + "type": "event" + }, + { + "anonymous": false, + "inputs": [{ "indexed": true, "internalType": "address", "name": "protocol", "type": "address" }], + "name": "LogRegisterProtocol", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "masterContract", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "user", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "LogSetMasterContractApproval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "LogStrategyDivest", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "LogStrategyInvest", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "LogStrategyLoss", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "LogStrategyProfit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": true, "internalType": "contract IStrategy", "name": "strategy", "type": "address" } + ], + "name": "LogStrategyQueued", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": true, "internalType": "contract IStrategy", "name": "strategy", "type": "address" } + ], + "name": "LogStrategySet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "targetPercentage", "type": "uint256" } + ], + "name": "LogStrategyTargetPercentage", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "share", "type": "uint256" } + ], + "name": "LogTransfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "masterContract", "type": "address" }, + { "indexed": false, "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "LogWhiteListMasterContract", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "to", "type": "address" }, + { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "indexed": false, "internalType": "uint256", "name": "share", "type": "uint256" } + ], + "name": "LogWithdraw", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, + { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "bytes[]", "name": "calls", "type": "bytes[]" }, + { "internalType": "bool", "name": "revertOnFail", "type": "bool" } + ], + "name": "batch", + "outputs": [ + { "internalType": "bool[]", "name": "successes", "type": "bool[]" }, + { "internalType": "bytes[]", "name": "results", "type": "bytes[]" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IBatchFlashBorrower", "name": "borrower", "type": "address" }, + { "internalType": "address[]", "name": "receivers", "type": "address[]" }, + { "internalType": "contract IERC20[]", "name": "tokens", "type": "address[]" }, + { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "batchFlashLoan", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [], "name": "claimOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "masterContract", "type": "address" }, + { "internalType": "bytes", "name": "data", "type": "bytes" }, + { "internalType": "bool", "name": "useCreate2", "type": "bool" } + ], + "name": "deploy", + "outputs": [{ "internalType": "address", "name": "cloneAddress", "type": "address" }], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token_", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "share", "type": "uint256" } + ], + "name": "deposit", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, + { "internalType": "uint256", "name": "shareOut", "type": "uint256" } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IFlashBorrower", "name": "borrower", "type": "address" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "flashLoan", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "bool", "name": "balance", "type": "bool" }, + { "internalType": "uint256", "name": "maxChangeAmount", "type": "uint256" } + ], + "name": "harvest", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "masterContractApproved", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "masterContractOf", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "name": "pendingStrategy", + "outputs": [{ "internalType": "contract IStrategy", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permitToken", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { "inputs": [], "name": "registerProtocol", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { "internalType": "address", "name": "user", "type": "address" }, + { "internalType": "address", "name": "masterContract", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "setMasterContractApproval", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "contract IStrategy", "name": "newStrategy", "type": "address" } + ], + "name": "setStrategy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "uint64", "name": "targetPercentage_", "type": "uint64" } + ], + "name": "setStrategyTargetPercentage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "name": "strategy", + "outputs": [{ "internalType": "contract IStrategy", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "name": "strategyData", + "outputs": [ + { "internalType": "uint64", "name": "strategyStartDate", "type": "uint64" }, + { "internalType": "uint64", "name": "targetPercentage", "type": "uint64" }, + { "internalType": "uint128", "name": "balance", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "share", "type": "uint256" }, + { "internalType": "bool", "name": "roundUp", "type": "bool" } + ], + "name": "toAmount", + "outputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bool", "name": "roundUp", "type": "bool" } + ], + "name": "toShare", + "outputs": [{ "internalType": "uint256", "name": "share", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], + "name": "totals", + "outputs": [ + { "internalType": "uint128", "name": "elastic", "type": "uint128" }, + { "internalType": "uint128", "name": "base", "type": "uint128" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "share", "type": "uint256" } + ], + "name": "transfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address[]", "name": "tos", "type": "address[]" }, + { "internalType": "uint256[]", "name": "shares", "type": "uint256[]" } + ], + "name": "transferMultiple", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newOwner", "type": "address" }, + { "internalType": "bool", "name": "direct", "type": "bool" }, + { "internalType": "bool", "name": "renounce", "type": "bool" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "masterContract", "type": "address" }, + { "internalType": "bool", "name": "approved", "type": "bool" } + ], + "name": "whitelistMasterContract", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "whitelistedMasterContracts", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "contract IERC20", "name": "token_", "type": "address" }, + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "uint256", "name": "share", "type": "uint256" } + ], + "name": "withdraw", + "outputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, + { "internalType": "uint256", "name": "shareOut", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { "stateMutability": "payable", "type": "receive" } +] diff --git a/src/apps/sushiswap-bentobox/contracts/ethers/SushiswapBentobox.ts b/src/apps/sushiswap-bentobox/contracts/ethers/SushiswapBentobox.ts new file mode 100644 index 000000000..1e9c1af33 --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/ethers/SushiswapBentobox.ts @@ -0,0 +1,1270 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { + BaseContract, + BigNumber, + BigNumberish, + BytesLike, + CallOverrides, + ContractTransaction, + Overrides, + PayableOverrides, + PopulatedTransaction, + Signer, + utils, +} from 'ethers'; +import type { FunctionFragment, Result, EventFragment } from '@ethersproject/abi'; +import type { Listener, Provider } from '@ethersproject/providers'; +import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent } from './common'; + +export interface SushiswapBentoboxInterface extends utils.Interface { + functions: { + 'DOMAIN_SEPARATOR()': FunctionFragment; + 'balanceOf(address,address)': FunctionFragment; + 'batch(bytes[],bool)': FunctionFragment; + 'batchFlashLoan(address,address[],address[],uint256[],bytes)': FunctionFragment; + 'claimOwnership()': FunctionFragment; + 'deploy(address,bytes,bool)': FunctionFragment; + 'deposit(address,address,address,uint256,uint256)': FunctionFragment; + 'flashLoan(address,address,address,uint256,bytes)': FunctionFragment; + 'harvest(address,bool,uint256)': FunctionFragment; + 'masterContractApproved(address,address)': FunctionFragment; + 'masterContractOf(address)': FunctionFragment; + 'nonces(address)': FunctionFragment; + 'owner()': FunctionFragment; + 'pendingOwner()': FunctionFragment; + 'pendingStrategy(address)': FunctionFragment; + 'permitToken(address,address,address,uint256,uint256,uint8,bytes32,bytes32)': FunctionFragment; + 'registerProtocol()': FunctionFragment; + 'setMasterContractApproval(address,address,bool,uint8,bytes32,bytes32)': FunctionFragment; + 'setStrategy(address,address)': FunctionFragment; + 'setStrategyTargetPercentage(address,uint64)': FunctionFragment; + 'strategy(address)': FunctionFragment; + 'strategyData(address)': FunctionFragment; + 'toAmount(address,uint256,bool)': FunctionFragment; + 'toShare(address,uint256,bool)': FunctionFragment; + 'totals(address)': FunctionFragment; + 'transfer(address,address,address,uint256)': FunctionFragment; + 'transferMultiple(address,address,address[],uint256[])': FunctionFragment; + 'transferOwnership(address,bool,bool)': FunctionFragment; + 'whitelistMasterContract(address,bool)': FunctionFragment; + 'whitelistedMasterContracts(address)': FunctionFragment; + 'withdraw(address,address,address,uint256,uint256)': FunctionFragment; + }; + + getFunction( + nameOrSignatureOrTopic: + | 'DOMAIN_SEPARATOR' + | 'balanceOf' + | 'batch' + | 'batchFlashLoan' + | 'claimOwnership' + | 'deploy' + | 'deposit' + | 'flashLoan' + | 'harvest' + | 'masterContractApproved' + | 'masterContractOf' + | 'nonces' + | 'owner' + | 'pendingOwner' + | 'pendingStrategy' + | 'permitToken' + | 'registerProtocol' + | 'setMasterContractApproval' + | 'setStrategy' + | 'setStrategyTargetPercentage' + | 'strategy' + | 'strategyData' + | 'toAmount' + | 'toShare' + | 'totals' + | 'transfer' + | 'transferMultiple' + | 'transferOwnership' + | 'whitelistMasterContract' + | 'whitelistedMasterContracts' + | 'withdraw', + ): FunctionFragment; + + encodeFunctionData(functionFragment: 'DOMAIN_SEPARATOR', values?: undefined): string; + encodeFunctionData(functionFragment: 'balanceOf', values: [string, string]): string; + encodeFunctionData(functionFragment: 'batch', values: [BytesLike[], boolean]): string; + encodeFunctionData( + functionFragment: 'batchFlashLoan', + values: [string, string[], string[], BigNumberish[], BytesLike], + ): string; + encodeFunctionData(functionFragment: 'claimOwnership', values?: undefined): string; + encodeFunctionData(functionFragment: 'deploy', values: [string, BytesLike, boolean]): string; + encodeFunctionData(functionFragment: 'deposit', values: [string, string, string, BigNumberish, BigNumberish]): string; + encodeFunctionData(functionFragment: 'flashLoan', values: [string, string, string, BigNumberish, BytesLike]): string; + encodeFunctionData(functionFragment: 'harvest', values: [string, boolean, BigNumberish]): string; + encodeFunctionData(functionFragment: 'masterContractApproved', values: [string, string]): string; + encodeFunctionData(functionFragment: 'masterContractOf', values: [string]): string; + encodeFunctionData(functionFragment: 'nonces', values: [string]): string; + encodeFunctionData(functionFragment: 'owner', values?: undefined): string; + encodeFunctionData(functionFragment: 'pendingOwner', values?: undefined): string; + encodeFunctionData(functionFragment: 'pendingStrategy', values: [string]): string; + encodeFunctionData( + functionFragment: 'permitToken', + values: [string, string, string, BigNumberish, BigNumberish, BigNumberish, BytesLike, BytesLike], + ): string; + encodeFunctionData(functionFragment: 'registerProtocol', values?: undefined): string; + encodeFunctionData( + functionFragment: 'setMasterContractApproval', + values: [string, string, boolean, BigNumberish, BytesLike, BytesLike], + ): string; + encodeFunctionData(functionFragment: 'setStrategy', values: [string, string]): string; + encodeFunctionData(functionFragment: 'setStrategyTargetPercentage', values: [string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'strategy', values: [string]): string; + encodeFunctionData(functionFragment: 'strategyData', values: [string]): string; + encodeFunctionData(functionFragment: 'toAmount', values: [string, BigNumberish, boolean]): string; + encodeFunctionData(functionFragment: 'toShare', values: [string, BigNumberish, boolean]): string; + encodeFunctionData(functionFragment: 'totals', values: [string]): string; + encodeFunctionData(functionFragment: 'transfer', values: [string, string, string, BigNumberish]): string; + encodeFunctionData(functionFragment: 'transferMultiple', values: [string, string, string[], BigNumberish[]]): string; + encodeFunctionData(functionFragment: 'transferOwnership', values: [string, boolean, boolean]): string; + encodeFunctionData(functionFragment: 'whitelistMasterContract', values: [string, boolean]): string; + encodeFunctionData(functionFragment: 'whitelistedMasterContracts', values: [string]): string; + encodeFunctionData( + functionFragment: 'withdraw', + values: [string, string, string, BigNumberish, BigNumberish], + ): string; + + decodeFunctionResult(functionFragment: 'DOMAIN_SEPARATOR', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'balanceOf', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'batch', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'batchFlashLoan', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'claimOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deploy', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'deposit', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'flashLoan', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'harvest', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'masterContractApproved', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'masterContractOf', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'nonces', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'owner', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'pendingOwner', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'pendingStrategy', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'permitToken', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'registerProtocol', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setMasterContractApproval', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setStrategy', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'setStrategyTargetPercentage', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'strategy', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'strategyData', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'toAmount', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'toShare', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'totals', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'transfer', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'transferMultiple', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'transferOwnership', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'whitelistMasterContract', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'whitelistedMasterContracts', data: BytesLike): Result; + decodeFunctionResult(functionFragment: 'withdraw', data: BytesLike): Result; + + events: { + 'LogDeploy(address,bytes,address)': EventFragment; + 'LogDeposit(address,address,address,uint256,uint256)': EventFragment; + 'LogFlashLoan(address,address,uint256,uint256,address)': EventFragment; + 'LogRegisterProtocol(address)': EventFragment; + 'LogSetMasterContractApproval(address,address,bool)': EventFragment; + 'LogStrategyDivest(address,uint256)': EventFragment; + 'LogStrategyInvest(address,uint256)': EventFragment; + 'LogStrategyLoss(address,uint256)': EventFragment; + 'LogStrategyProfit(address,uint256)': EventFragment; + 'LogStrategyQueued(address,address)': EventFragment; + 'LogStrategySet(address,address)': EventFragment; + 'LogStrategyTargetPercentage(address,uint256)': EventFragment; + 'LogTransfer(address,address,address,uint256)': EventFragment; + 'LogWhiteListMasterContract(address,bool)': EventFragment; + 'LogWithdraw(address,address,address,uint256,uint256)': EventFragment; + 'OwnershipTransferred(address,address)': EventFragment; + }; + + getEvent(nameOrSignatureOrTopic: 'LogDeploy'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogDeposit'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogFlashLoan'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogRegisterProtocol'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogSetMasterContractApproval'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategyDivest'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategyInvest'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategyLoss'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategyProfit'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategyQueued'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategySet'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogStrategyTargetPercentage'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogTransfer'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogWhiteListMasterContract'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'LogWithdraw'): EventFragment; + getEvent(nameOrSignatureOrTopic: 'OwnershipTransferred'): EventFragment; +} + +export interface LogDeployEventObject { + masterContract: string; + data: string; + cloneAddress: string; +} +export type LogDeployEvent = TypedEvent<[string, string, string], LogDeployEventObject>; + +export type LogDeployEventFilter = TypedEventFilter; + +export interface LogDepositEventObject { + token: string; + from: string; + to: string; + amount: BigNumber; + share: BigNumber; +} +export type LogDepositEvent = TypedEvent<[string, string, string, BigNumber, BigNumber], LogDepositEventObject>; + +export type LogDepositEventFilter = TypedEventFilter; + +export interface LogFlashLoanEventObject { + borrower: string; + token: string; + amount: BigNumber; + feeAmount: BigNumber; + receiver: string; +} +export type LogFlashLoanEvent = TypedEvent<[string, string, BigNumber, BigNumber, string], LogFlashLoanEventObject>; + +export type LogFlashLoanEventFilter = TypedEventFilter; + +export interface LogRegisterProtocolEventObject { + protocol: string; +} +export type LogRegisterProtocolEvent = TypedEvent<[string], LogRegisterProtocolEventObject>; + +export type LogRegisterProtocolEventFilter = TypedEventFilter; + +export interface LogSetMasterContractApprovalEventObject { + masterContract: string; + user: string; + approved: boolean; +} +export type LogSetMasterContractApprovalEvent = TypedEvent< + [string, string, boolean], + LogSetMasterContractApprovalEventObject +>; + +export type LogSetMasterContractApprovalEventFilter = TypedEventFilter; + +export interface LogStrategyDivestEventObject { + token: string; + amount: BigNumber; +} +export type LogStrategyDivestEvent = TypedEvent<[string, BigNumber], LogStrategyDivestEventObject>; + +export type LogStrategyDivestEventFilter = TypedEventFilter; + +export interface LogStrategyInvestEventObject { + token: string; + amount: BigNumber; +} +export type LogStrategyInvestEvent = TypedEvent<[string, BigNumber], LogStrategyInvestEventObject>; + +export type LogStrategyInvestEventFilter = TypedEventFilter; + +export interface LogStrategyLossEventObject { + token: string; + amount: BigNumber; +} +export type LogStrategyLossEvent = TypedEvent<[string, BigNumber], LogStrategyLossEventObject>; + +export type LogStrategyLossEventFilter = TypedEventFilter; + +export interface LogStrategyProfitEventObject { + token: string; + amount: BigNumber; +} +export type LogStrategyProfitEvent = TypedEvent<[string, BigNumber], LogStrategyProfitEventObject>; + +export type LogStrategyProfitEventFilter = TypedEventFilter; + +export interface LogStrategyQueuedEventObject { + token: string; + strategy: string; +} +export type LogStrategyQueuedEvent = TypedEvent<[string, string], LogStrategyQueuedEventObject>; + +export type LogStrategyQueuedEventFilter = TypedEventFilter; + +export interface LogStrategySetEventObject { + token: string; + strategy: string; +} +export type LogStrategySetEvent = TypedEvent<[string, string], LogStrategySetEventObject>; + +export type LogStrategySetEventFilter = TypedEventFilter; + +export interface LogStrategyTargetPercentageEventObject { + token: string; + targetPercentage: BigNumber; +} +export type LogStrategyTargetPercentageEvent = TypedEvent<[string, BigNumber], LogStrategyTargetPercentageEventObject>; + +export type LogStrategyTargetPercentageEventFilter = TypedEventFilter; + +export interface LogTransferEventObject { + token: string; + from: string; + to: string; + share: BigNumber; +} +export type LogTransferEvent = TypedEvent<[string, string, string, BigNumber], LogTransferEventObject>; + +export type LogTransferEventFilter = TypedEventFilter; + +export interface LogWhiteListMasterContractEventObject { + masterContract: string; + approved: boolean; +} +export type LogWhiteListMasterContractEvent = TypedEvent<[string, boolean], LogWhiteListMasterContractEventObject>; + +export type LogWhiteListMasterContractEventFilter = TypedEventFilter; + +export interface LogWithdrawEventObject { + token: string; + from: string; + to: string; + amount: BigNumber; + share: BigNumber; +} +export type LogWithdrawEvent = TypedEvent<[string, string, string, BigNumber, BigNumber], LogWithdrawEventObject>; + +export type LogWithdrawEventFilter = TypedEventFilter; + +export interface OwnershipTransferredEventObject { + previousOwner: string; + newOwner: string; +} +export type OwnershipTransferredEvent = TypedEvent<[string, string], OwnershipTransferredEventObject>; + +export type OwnershipTransferredEventFilter = TypedEventFilter; + +export interface SushiswapBentobox extends BaseContract { + connect(signerOrProvider: Signer | Provider | string): this; + attach(addressOrName: string): this; + deployed(): Promise; + + interface: SushiswapBentoboxInterface; + + queryFilter( + event: TypedEventFilter, + fromBlockOrBlockhash?: string | number | undefined, + toBlock?: string | number | undefined, + ): Promise>; + + listeners(eventFilter?: TypedEventFilter): Array>; + listeners(eventName?: string): Array; + removeAllListeners(eventFilter: TypedEventFilter): this; + removeAllListeners(eventName?: string): this; + off: OnEvent; + on: OnEvent; + once: OnEvent; + removeListener: OnEvent; + + functions: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise<[string]>; + + balanceOf(arg0: string, arg1: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + batch( + calls: BytesLike[], + revertOnFail: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + batchFlashLoan( + borrower: string, + receivers: string[], + tokens: string[], + amounts: BigNumberish[], + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + claimOwnership(overrides?: Overrides & { from?: string | Promise }): Promise; + + deploy( + masterContract: string, + data: BytesLike, + useCreate2: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + deposit( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + flashLoan( + borrower: string, + receiver: string, + token: string, + amount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + harvest( + token: string, + balance: boolean, + maxChangeAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + masterContractApproved(arg0: string, arg1: string, overrides?: CallOverrides): Promise<[boolean]>; + + masterContractOf(arg0: string, overrides?: CallOverrides): Promise<[string]>; + + nonces(arg0: string, overrides?: CallOverrides): Promise<[BigNumber]>; + + owner(overrides?: CallOverrides): Promise<[string]>; + + pendingOwner(overrides?: CallOverrides): Promise<[string]>; + + pendingStrategy(arg0: string, overrides?: CallOverrides): Promise<[string]>; + + permitToken( + token: string, + from: string, + to: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + registerProtocol(overrides?: Overrides & { from?: string | Promise }): Promise; + + setMasterContractApproval( + user: string, + masterContract: string, + approved: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategy( + token: string, + newStrategy: string, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategyTargetPercentage( + token: string, + targetPercentage_: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + strategy(arg0: string, overrides?: CallOverrides): Promise<[string]>; + + strategyData( + arg0: string, + overrides?: CallOverrides, + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + strategyStartDate: BigNumber; + targetPercentage: BigNumber; + balance: BigNumber; + } + >; + + toAmount( + token: string, + share: BigNumberish, + roundUp: boolean, + overrides?: CallOverrides, + ): Promise<[BigNumber] & { amount: BigNumber }>; + + toShare( + token: string, + amount: BigNumberish, + roundUp: boolean, + overrides?: CallOverrides, + ): Promise<[BigNumber] & { share: BigNumber }>; + + totals( + arg0: string, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { elastic: BigNumber; base: BigNumber }>; + + transfer( + token: string, + from: string, + to: string, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferMultiple( + token: string, + from: string, + tos: string[], + shares: BigNumberish[], + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferOwnership( + newOwner: string, + direct: boolean, + renounce: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistMasterContract( + masterContract: string, + approved: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistedMasterContracts(arg0: string, overrides?: CallOverrides): Promise<[boolean]>; + + withdraw( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + }; + + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + balanceOf(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + batch( + calls: BytesLike[], + revertOnFail: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + batchFlashLoan( + borrower: string, + receivers: string[], + tokens: string[], + amounts: BigNumberish[], + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + claimOwnership(overrides?: Overrides & { from?: string | Promise }): Promise; + + deploy( + masterContract: string, + data: BytesLike, + useCreate2: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + deposit( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + flashLoan( + borrower: string, + receiver: string, + token: string, + amount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + harvest( + token: string, + balance: boolean, + maxChangeAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + masterContractApproved(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + masterContractOf(arg0: string, overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + pendingOwner(overrides?: CallOverrides): Promise; + + pendingStrategy(arg0: string, overrides?: CallOverrides): Promise; + + permitToken( + token: string, + from: string, + to: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + registerProtocol(overrides?: Overrides & { from?: string | Promise }): Promise; + + setMasterContractApproval( + user: string, + masterContract: string, + approved: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategy( + token: string, + newStrategy: string, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategyTargetPercentage( + token: string, + targetPercentage_: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + strategy(arg0: string, overrides?: CallOverrides): Promise; + + strategyData( + arg0: string, + overrides?: CallOverrides, + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + strategyStartDate: BigNumber; + targetPercentage: BigNumber; + balance: BigNumber; + } + >; + + toAmount(token: string, share: BigNumberish, roundUp: boolean, overrides?: CallOverrides): Promise; + + toShare(token: string, amount: BigNumberish, roundUp: boolean, overrides?: CallOverrides): Promise; + + totals( + arg0: string, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { elastic: BigNumber; base: BigNumber }>; + + transfer( + token: string, + from: string, + to: string, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferMultiple( + token: string, + from: string, + tos: string[], + shares: BigNumberish[], + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferOwnership( + newOwner: string, + direct: boolean, + renounce: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistMasterContract( + masterContract: string, + approved: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistedMasterContracts(arg0: string, overrides?: CallOverrides): Promise; + + withdraw( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + callStatic: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + balanceOf(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + batch( + calls: BytesLike[], + revertOnFail: boolean, + overrides?: CallOverrides, + ): Promise<[boolean[], string[]] & { successes: boolean[]; results: string[] }>; + + batchFlashLoan( + borrower: string, + receivers: string[], + tokens: string[], + amounts: BigNumberish[], + data: BytesLike, + overrides?: CallOverrides, + ): Promise; + + claimOwnership(overrides?: CallOverrides): Promise; + + deploy(masterContract: string, data: BytesLike, useCreate2: boolean, overrides?: CallOverrides): Promise; + + deposit( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { amountOut: BigNumber; shareOut: BigNumber }>; + + flashLoan( + borrower: string, + receiver: string, + token: string, + amount: BigNumberish, + data: BytesLike, + overrides?: CallOverrides, + ): Promise; + + harvest(token: string, balance: boolean, maxChangeAmount: BigNumberish, overrides?: CallOverrides): Promise; + + masterContractApproved(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + masterContractOf(arg0: string, overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + pendingOwner(overrides?: CallOverrides): Promise; + + pendingStrategy(arg0: string, overrides?: CallOverrides): Promise; + + permitToken( + token: string, + from: string, + to: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: CallOverrides, + ): Promise; + + registerProtocol(overrides?: CallOverrides): Promise; + + setMasterContractApproval( + user: string, + masterContract: string, + approved: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: CallOverrides, + ): Promise; + + setStrategy(token: string, newStrategy: string, overrides?: CallOverrides): Promise; + + setStrategyTargetPercentage( + token: string, + targetPercentage_: BigNumberish, + overrides?: CallOverrides, + ): Promise; + + strategy(arg0: string, overrides?: CallOverrides): Promise; + + strategyData( + arg0: string, + overrides?: CallOverrides, + ): Promise< + [BigNumber, BigNumber, BigNumber] & { + strategyStartDate: BigNumber; + targetPercentage: BigNumber; + balance: BigNumber; + } + >; + + toAmount(token: string, share: BigNumberish, roundUp: boolean, overrides?: CallOverrides): Promise; + + toShare(token: string, amount: BigNumberish, roundUp: boolean, overrides?: CallOverrides): Promise; + + totals( + arg0: string, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { elastic: BigNumber; base: BigNumber }>; + + transfer(token: string, from: string, to: string, share: BigNumberish, overrides?: CallOverrides): Promise; + + transferMultiple( + token: string, + from: string, + tos: string[], + shares: BigNumberish[], + overrides?: CallOverrides, + ): Promise; + + transferOwnership(newOwner: string, direct: boolean, renounce: boolean, overrides?: CallOverrides): Promise; + + whitelistMasterContract(masterContract: string, approved: boolean, overrides?: CallOverrides): Promise; + + whitelistedMasterContracts(arg0: string, overrides?: CallOverrides): Promise; + + withdraw( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: CallOverrides, + ): Promise<[BigNumber, BigNumber] & { amountOut: BigNumber; shareOut: BigNumber }>; + }; + + filters: { + 'LogDeploy(address,bytes,address)'( + masterContract?: string | null, + data?: null, + cloneAddress?: string | null, + ): LogDeployEventFilter; + LogDeploy(masterContract?: string | null, data?: null, cloneAddress?: string | null): LogDeployEventFilter; + + 'LogDeposit(address,address,address,uint256,uint256)'( + token?: string | null, + from?: string | null, + to?: string | null, + amount?: null, + share?: null, + ): LogDepositEventFilter; + LogDeposit( + token?: string | null, + from?: string | null, + to?: string | null, + amount?: null, + share?: null, + ): LogDepositEventFilter; + + 'LogFlashLoan(address,address,uint256,uint256,address)'( + borrower?: string | null, + token?: string | null, + amount?: null, + feeAmount?: null, + receiver?: string | null, + ): LogFlashLoanEventFilter; + LogFlashLoan( + borrower?: string | null, + token?: string | null, + amount?: null, + feeAmount?: null, + receiver?: string | null, + ): LogFlashLoanEventFilter; + + 'LogRegisterProtocol(address)'(protocol?: string | null): LogRegisterProtocolEventFilter; + LogRegisterProtocol(protocol?: string | null): LogRegisterProtocolEventFilter; + + 'LogSetMasterContractApproval(address,address,bool)'( + masterContract?: string | null, + user?: string | null, + approved?: null, + ): LogSetMasterContractApprovalEventFilter; + LogSetMasterContractApproval( + masterContract?: string | null, + user?: string | null, + approved?: null, + ): LogSetMasterContractApprovalEventFilter; + + 'LogStrategyDivest(address,uint256)'(token?: string | null, amount?: null): LogStrategyDivestEventFilter; + LogStrategyDivest(token?: string | null, amount?: null): LogStrategyDivestEventFilter; + + 'LogStrategyInvest(address,uint256)'(token?: string | null, amount?: null): LogStrategyInvestEventFilter; + LogStrategyInvest(token?: string | null, amount?: null): LogStrategyInvestEventFilter; + + 'LogStrategyLoss(address,uint256)'(token?: string | null, amount?: null): LogStrategyLossEventFilter; + LogStrategyLoss(token?: string | null, amount?: null): LogStrategyLossEventFilter; + + 'LogStrategyProfit(address,uint256)'(token?: string | null, amount?: null): LogStrategyProfitEventFilter; + LogStrategyProfit(token?: string | null, amount?: null): LogStrategyProfitEventFilter; + + 'LogStrategyQueued(address,address)'(token?: string | null, strategy?: string | null): LogStrategyQueuedEventFilter; + LogStrategyQueued(token?: string | null, strategy?: string | null): LogStrategyQueuedEventFilter; + + 'LogStrategySet(address,address)'(token?: string | null, strategy?: string | null): LogStrategySetEventFilter; + LogStrategySet(token?: string | null, strategy?: string | null): LogStrategySetEventFilter; + + 'LogStrategyTargetPercentage(address,uint256)'( + token?: string | null, + targetPercentage?: null, + ): LogStrategyTargetPercentageEventFilter; + LogStrategyTargetPercentage(token?: string | null, targetPercentage?: null): LogStrategyTargetPercentageEventFilter; + + 'LogTransfer(address,address,address,uint256)'( + token?: string | null, + from?: string | null, + to?: string | null, + share?: null, + ): LogTransferEventFilter; + LogTransfer(token?: string | null, from?: string | null, to?: string | null, share?: null): LogTransferEventFilter; + + 'LogWhiteListMasterContract(address,bool)'( + masterContract?: string | null, + approved?: null, + ): LogWhiteListMasterContractEventFilter; + LogWhiteListMasterContract(masterContract?: string | null, approved?: null): LogWhiteListMasterContractEventFilter; + + 'LogWithdraw(address,address,address,uint256,uint256)'( + token?: string | null, + from?: string | null, + to?: string | null, + amount?: null, + share?: null, + ): LogWithdrawEventFilter; + LogWithdraw( + token?: string | null, + from?: string | null, + to?: string | null, + amount?: null, + share?: null, + ): LogWithdrawEventFilter; + + 'OwnershipTransferred(address,address)'( + previousOwner?: string | null, + newOwner?: string | null, + ): OwnershipTransferredEventFilter; + OwnershipTransferred(previousOwner?: string | null, newOwner?: string | null): OwnershipTransferredEventFilter; + }; + + estimateGas: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + balanceOf(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + batch( + calls: BytesLike[], + revertOnFail: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + batchFlashLoan( + borrower: string, + receivers: string[], + tokens: string[], + amounts: BigNumberish[], + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + claimOwnership(overrides?: Overrides & { from?: string | Promise }): Promise; + + deploy( + masterContract: string, + data: BytesLike, + useCreate2: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + deposit( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + flashLoan( + borrower: string, + receiver: string, + token: string, + amount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + harvest( + token: string, + balance: boolean, + maxChangeAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + masterContractApproved(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + masterContractOf(arg0: string, overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + pendingOwner(overrides?: CallOverrides): Promise; + + pendingStrategy(arg0: string, overrides?: CallOverrides): Promise; + + permitToken( + token: string, + from: string, + to: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + registerProtocol(overrides?: Overrides & { from?: string | Promise }): Promise; + + setMasterContractApproval( + user: string, + masterContract: string, + approved: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategy( + token: string, + newStrategy: string, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategyTargetPercentage( + token: string, + targetPercentage_: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + strategy(arg0: string, overrides?: CallOverrides): Promise; + + strategyData(arg0: string, overrides?: CallOverrides): Promise; + + toAmount(token: string, share: BigNumberish, roundUp: boolean, overrides?: CallOverrides): Promise; + + toShare(token: string, amount: BigNumberish, roundUp: boolean, overrides?: CallOverrides): Promise; + + totals(arg0: string, overrides?: CallOverrides): Promise; + + transfer( + token: string, + from: string, + to: string, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferMultiple( + token: string, + from: string, + tos: string[], + shares: BigNumberish[], + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferOwnership( + newOwner: string, + direct: boolean, + renounce: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistMasterContract( + masterContract: string, + approved: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistedMasterContracts(arg0: string, overrides?: CallOverrides): Promise; + + withdraw( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + }; + + populateTransaction: { + DOMAIN_SEPARATOR(overrides?: CallOverrides): Promise; + + balanceOf(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + batch( + calls: BytesLike[], + revertOnFail: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + batchFlashLoan( + borrower: string, + receivers: string[], + tokens: string[], + amounts: BigNumberish[], + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + claimOwnership(overrides?: Overrides & { from?: string | Promise }): Promise; + + deploy( + masterContract: string, + data: BytesLike, + useCreate2: boolean, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + deposit( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: PayableOverrides & { from?: string | Promise }, + ): Promise; + + flashLoan( + borrower: string, + receiver: string, + token: string, + amount: BigNumberish, + data: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + harvest( + token: string, + balance: boolean, + maxChangeAmount: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + masterContractApproved(arg0: string, arg1: string, overrides?: CallOverrides): Promise; + + masterContractOf(arg0: string, overrides?: CallOverrides): Promise; + + nonces(arg0: string, overrides?: CallOverrides): Promise; + + owner(overrides?: CallOverrides): Promise; + + pendingOwner(overrides?: CallOverrides): Promise; + + pendingStrategy(arg0: string, overrides?: CallOverrides): Promise; + + permitToken( + token: string, + from: string, + to: string, + amount: BigNumberish, + deadline: BigNumberish, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + registerProtocol(overrides?: Overrides & { from?: string | Promise }): Promise; + + setMasterContractApproval( + user: string, + masterContract: string, + approved: boolean, + v: BigNumberish, + r: BytesLike, + s: BytesLike, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategy( + token: string, + newStrategy: string, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + setStrategyTargetPercentage( + token: string, + targetPercentage_: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + strategy(arg0: string, overrides?: CallOverrides): Promise; + + strategyData(arg0: string, overrides?: CallOverrides): Promise; + + toAmount( + token: string, + share: BigNumberish, + roundUp: boolean, + overrides?: CallOverrides, + ): Promise; + + toShare( + token: string, + amount: BigNumberish, + roundUp: boolean, + overrides?: CallOverrides, + ): Promise; + + totals(arg0: string, overrides?: CallOverrides): Promise; + + transfer( + token: string, + from: string, + to: string, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferMultiple( + token: string, + from: string, + tos: string[], + shares: BigNumberish[], + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + transferOwnership( + newOwner: string, + direct: boolean, + renounce: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistMasterContract( + masterContract: string, + approved: boolean, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + + whitelistedMasterContracts(arg0: string, overrides?: CallOverrides): Promise; + + withdraw( + token_: string, + from: string, + to: string, + amount: BigNumberish, + share: BigNumberish, + overrides?: Overrides & { from?: string | Promise }, + ): Promise; + }; +} diff --git a/src/apps/sushiswap-bentobox/contracts/ethers/common.ts b/src/apps/sushiswap-bentobox/contracts/ethers/common.ts new file mode 100644 index 000000000..6cfb10425 --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/ethers/common.ts @@ -0,0 +1,30 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +import type { Listener } from '@ethersproject/providers'; +import type { Event, EventFilter } from 'ethers'; + +export interface TypedEvent = any, TArgsObject = any> extends Event { + args: TArgsArray & TArgsObject; +} + +export interface TypedEventFilter<_TEvent extends TypedEvent> extends EventFilter {} + +export interface TypedListener { + (...listenerArg: [...__TypechainArgsArray, TEvent]): void; +} + +type __TypechainArgsArray = T extends TypedEvent ? U : never; + +export interface OnEvent { + (eventFilter: TypedEventFilter, listener: TypedListener): TRes; + (eventName: string, listener: Listener): TRes; +} + +export type MinEthersFactory = { + deploy(...a: ARGS[]): Promise; +}; + +export type GetContractTypeFromFactory = F extends MinEthersFactory ? C : never; + +export type GetARGsTypeFromFactory = F extends MinEthersFactory ? Parameters : never; diff --git a/src/apps/sushiswap-bentobox/contracts/ethers/factories/SushiswapBentobox__factory.ts b/src/apps/sushiswap-bentobox/contracts/ethers/factories/SushiswapBentobox__factory.ts new file mode 100644 index 000000000..087a479d2 --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/ethers/factories/SushiswapBentobox__factory.ts @@ -0,0 +1,1172 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ + +import { Contract, Signer, utils } from 'ethers'; +import type { Provider } from '@ethersproject/providers'; +import type { SushiswapBentobox, SushiswapBentoboxInterface } from '../SushiswapBentobox'; + +const _abi = [ + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'wethToken_', + type: 'address', + }, + ], + stateMutability: 'nonpayable', + type: 'constructor', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'masterContract', + type: 'address', + }, + { + indexed: false, + internalType: 'bytes', + name: 'data', + type: 'bytes', + }, + { + indexed: true, + internalType: 'address', + name: 'cloneAddress', + type: 'address', + }, + ], + name: 'LogDeploy', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + name: 'LogDeposit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'borrower', + type: 'address', + }, + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'feeAmount', + type: 'uint256', + }, + { + indexed: true, + internalType: 'address', + name: 'receiver', + type: 'address', + }, + ], + name: 'LogFlashLoan', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'protocol', + type: 'address', + }, + ], + name: 'LogRegisterProtocol', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'masterContract', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'user', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'LogSetMasterContractApproval', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'LogStrategyDivest', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'LogStrategyInvest', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'LogStrategyLoss', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + name: 'LogStrategyProfit', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: true, + internalType: 'contract IStrategy', + name: 'strategy', + type: 'address', + }, + ], + name: 'LogStrategyQueued', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: true, + internalType: 'contract IStrategy', + name: 'strategy', + type: 'address', + }, + ], + name: 'LogStrategySet', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'targetPercentage', + type: 'uint256', + }, + ], + name: 'LogStrategyTargetPercentage', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + name: 'LogTransfer', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'masterContract', + type: 'address', + }, + { + indexed: false, + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'LogWhiteListMasterContract', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'from', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'to', + type: 'address', + }, + { + indexed: false, + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + indexed: false, + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + name: 'LogWithdraw', + type: 'event', + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: 'address', + name: 'previousOwner', + type: 'address', + }, + { + indexed: true, + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + ], + name: 'OwnershipTransferred', + type: 'event', + }, + { + inputs: [], + name: 'DOMAIN_SEPARATOR', + outputs: [ + { + internalType: 'bytes32', + name: '', + type: 'bytes32', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: '', + type: 'address', + }, + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'balanceOf', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'bytes[]', + name: 'calls', + type: 'bytes[]', + }, + { + internalType: 'bool', + name: 'revertOnFail', + type: 'bool', + }, + ], + name: 'batch', + outputs: [ + { + internalType: 'bool[]', + name: 'successes', + type: 'bool[]', + }, + { + internalType: 'bytes[]', + name: 'results', + type: 'bytes[]', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IBatchFlashBorrower', + name: 'borrower', + type: 'address', + }, + { + internalType: 'address[]', + name: 'receivers', + type: 'address[]', + }, + { + internalType: 'contract IERC20[]', + name: 'tokens', + type: 'address[]', + }, + { + internalType: 'uint256[]', + name: 'amounts', + type: 'uint256[]', + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes', + }, + ], + name: 'batchFlashLoan', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'claimOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'masterContract', + type: 'address', + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes', + }, + { + internalType: 'bool', + name: 'useCreate2', + type: 'bool', + }, + ], + name: 'deploy', + outputs: [ + { + internalType: 'address', + name: 'cloneAddress', + type: 'address', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token_', + type: 'address', + }, + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + name: 'deposit', + outputs: [ + { + internalType: 'uint256', + name: 'amountOut', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'shareOut', + type: 'uint256', + }, + ], + stateMutability: 'payable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IFlashBorrower', + name: 'borrower', + type: 'address', + }, + { + internalType: 'address', + name: 'receiver', + type: 'address', + }, + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'bytes', + name: 'data', + type: 'bytes', + }, + ], + name: 'flashLoan', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'bool', + name: 'balance', + type: 'bool', + }, + { + internalType: 'uint256', + name: 'maxChangeAmount', + type: 'uint256', + }, + ], + name: 'harvest', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'masterContractApproved', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'masterContractOf', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'nonces', + outputs: [ + { + internalType: 'uint256', + name: '', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'owner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [], + name: 'pendingOwner', + outputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: '', + type: 'address', + }, + ], + name: 'pendingStrategy', + outputs: [ + { + internalType: 'contract IStrategy', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'deadline', + type: 'uint256', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'permitToken', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [], + name: 'registerProtocol', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'user', + type: 'address', + }, + { + internalType: 'address', + name: 'masterContract', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + { + internalType: 'uint8', + name: 'v', + type: 'uint8', + }, + { + internalType: 'bytes32', + name: 'r', + type: 'bytes32', + }, + { + internalType: 'bytes32', + name: 's', + type: 'bytes32', + }, + ], + name: 'setMasterContractApproval', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'contract IStrategy', + name: 'newStrategy', + type: 'address', + }, + ], + name: 'setStrategy', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'uint64', + name: 'targetPercentage_', + type: 'uint64', + }, + ], + name: 'setStrategyTargetPercentage', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: '', + type: 'address', + }, + ], + name: 'strategy', + outputs: [ + { + internalType: 'contract IStrategy', + name: '', + type: 'address', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: '', + type: 'address', + }, + ], + name: 'strategyData', + outputs: [ + { + internalType: 'uint64', + name: 'strategyStartDate', + type: 'uint64', + }, + { + internalType: 'uint64', + name: 'targetPercentage', + type: 'uint64', + }, + { + internalType: 'uint128', + name: 'balance', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + { + internalType: 'bool', + name: 'roundUp', + type: 'bool', + }, + ], + name: 'toAmount', + outputs: [ + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'bool', + name: 'roundUp', + type: 'bool', + }, + ], + name: 'toShare', + outputs: [ + { + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: '', + type: 'address', + }, + ], + name: 'totals', + outputs: [ + { + internalType: 'uint128', + name: 'elastic', + type: 'uint128', + }, + { + internalType: 'uint128', + name: 'base', + type: 'uint128', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + name: 'transfer', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token', + type: 'address', + }, + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address[]', + name: 'tos', + type: 'address[]', + }, + { + internalType: 'uint256[]', + name: 'shares', + type: 'uint256[]', + }, + ], + name: 'transferMultiple', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'newOwner', + type: 'address', + }, + { + internalType: 'bool', + name: 'direct', + type: 'bool', + }, + { + internalType: 'bool', + name: 'renounce', + type: 'bool', + }, + ], + name: 'transferOwnership', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: 'masterContract', + type: 'address', + }, + { + internalType: 'bool', + name: 'approved', + type: 'bool', + }, + ], + name: 'whitelistMasterContract', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }, + { + inputs: [ + { + internalType: 'address', + name: '', + type: 'address', + }, + ], + name: 'whitelistedMasterContracts', + outputs: [ + { + internalType: 'bool', + name: '', + type: 'bool', + }, + ], + stateMutability: 'view', + type: 'function', + }, + { + inputs: [ + { + internalType: 'contract IERC20', + name: 'token_', + type: 'address', + }, + { + internalType: 'address', + name: 'from', + type: 'address', + }, + { + internalType: 'address', + name: 'to', + type: 'address', + }, + { + internalType: 'uint256', + name: 'amount', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'share', + type: 'uint256', + }, + ], + name: 'withdraw', + outputs: [ + { + internalType: 'uint256', + name: 'amountOut', + type: 'uint256', + }, + { + internalType: 'uint256', + name: 'shareOut', + type: 'uint256', + }, + ], + stateMutability: 'nonpayable', + type: 'function', + }, + { + stateMutability: 'payable', + type: 'receive', + }, +]; + +export class SushiswapBentobox__factory { + static readonly abi = _abi; + static createInterface(): SushiswapBentoboxInterface { + return new utils.Interface(_abi) as SushiswapBentoboxInterface; + } + static connect(address: string, signerOrProvider: Signer | Provider): SushiswapBentobox { + return new Contract(address, _abi, signerOrProvider) as SushiswapBentobox; + } +} diff --git a/src/apps/sushiswap-bentobox/contracts/ethers/factories/index.ts b/src/apps/sushiswap-bentobox/contracts/ethers/factories/index.ts new file mode 100644 index 000000000..1ac9a3bad --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/ethers/factories/index.ts @@ -0,0 +1,4 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export { SushiswapBentobox__factory } from './SushiswapBentobox__factory'; diff --git a/src/apps/sushiswap-bentobox/contracts/ethers/index.ts b/src/apps/sushiswap-bentobox/contracts/ethers/index.ts new file mode 100644 index 000000000..814b4361f --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/ethers/index.ts @@ -0,0 +1,6 @@ +/* Autogenerated file. Do not edit manually. */ +/* tslint:disable */ +/* eslint-disable */ +export type { SushiswapBentobox } from './SushiswapBentobox'; +export * as factories from './factories'; +export { SushiswapBentobox__factory } from './factories/SushiswapBentobox__factory'; diff --git a/src/apps/sushiswap-bentobox/contracts/index.ts b/src/apps/sushiswap-bentobox/contracts/index.ts new file mode 100644 index 000000000..c4c17ef97 --- /dev/null +++ b/src/apps/sushiswap-bentobox/contracts/index.ts @@ -0,0 +1,23 @@ +import { Injectable, Inject } from '@nestjs/common'; + +import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; +import { ContractFactory } from '~contract/contracts'; +import { Network } from '~types/network.interface'; + +import { SushiswapBentobox__factory } from './ethers'; + +// eslint-disable-next-line +type ContractOpts = { address: string; network: Network }; + +@Injectable() +export class SushiswapBentoboxContractFactory extends ContractFactory { + constructor(@Inject(APP_TOOLKIT) protected readonly appToolkit: IAppToolkit) { + super((network: Network) => appToolkit.getNetworkProvider(network)); + } + + sushiswapBentobox({ address, network }: ContractOpts) { + return SushiswapBentobox__factory.connect(address, this.appToolkit.getNetworkProvider(network)); + } +} + +export type { SushiswapBentobox } from './ethers'; diff --git a/src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.balance-fetcher.ts b/src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.balance-fetcher.ts new file mode 100644 index 000000000..f11ea340a --- /dev/null +++ b/src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.balance-fetcher.ts @@ -0,0 +1,34 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present'; +import { BalanceFetcher } from '~balance/balance-fetcher.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionBalanceHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-balance-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const network = Network.ETHEREUM_MAINNET; + +@Register.BalanceFetcher(SUSHISWAP_BENTOBOX_DEFINITION.id, network) +export class EthereumSushiSwapBentoBoxBalanceFetcher implements BalanceFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionBalanceHelper) + private readonly balanceHelper: SushiSwapBentoBoxContractPositionBalanceHelper, + ) {} + + async getBalances(address: string) { + const balances = await this.balanceHelper.getBalances({ + address, + network, + bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966', + }); + + return presentBalanceFetcherResponse([ + { + label: 'SushiSwap BentoBox', + assets: balances, + }, + ]); + } +} diff --git a/src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.vault.contract-position-fetcher.ts b/src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.vault.contract-position-fetcher.ts new file mode 100644 index 000000000..188b44fa7 --- /dev/null +++ b/src/apps/sushiswap-bentobox/ethereum/sushiswap-bentobox.vault.contract-position-fetcher.ts @@ -0,0 +1,29 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { PositionFetcher } from '~position/position-fetcher.interface'; +import { ContractPosition } from '~position/position.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const appId = SUSHISWAP_BENTOBOX_DEFINITION.id; +const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id; +const network = Network.ETHEREUM_MAINNET; + +@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } }) +export class EthereumSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionHelper) + private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper, + ) {} + + async getPositions() { + return this.positionHelper.getPositions({ + bentoBoxAddress: '0xf5bce5077908a1b7370b9ae04adc565ebd643966', + network, + subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/bentobox', + }); + } +} diff --git a/src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-balance-helper.ts b/src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-balance-helper.ts new file mode 100644 index 000000000..fe2d657b6 --- /dev/null +++ b/src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-balance-helper.ts @@ -0,0 +1,32 @@ +import { Inject, Injectable } from '@nestjs/common'; + +import { ContractPositionBalanceHelper } from '~app-toolkit/helpers/balance/contract-position-balance.helper'; +import { drillBalance } from '~app-toolkit/helpers/balance/token-balance.helper'; +import { Network } from '~types/network.interface'; + +import { SushiswapBentoboxContractFactory } from '../contracts'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +@Injectable() +export class SushiSwapBentoBoxContractPositionBalanceHelper { + constructor( + @Inject(SushiswapBentoboxContractFactory) private readonly contractFactory: SushiswapBentoboxContractFactory, + @Inject(ContractPositionBalanceHelper) + private readonly contractPositionBalanceHelper: ContractPositionBalanceHelper, + ) {} + + getBalances({ address, bentoBoxAddress, network }: { address: string; network: Network; bentoBoxAddress: string }) { + return this.contractPositionBalanceHelper.getContractPositionBalances({ + network, + appId: SUSHISWAP_BENTOBOX_DEFINITION.id, + groupId: SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id, + address, + resolveBalances: async ({ address, multicall, contractPosition }) => { + const contract = this.contractFactory.sushiswapBentobox({ address: bentoBoxAddress, network }); + const [token] = contractPosition.tokens; + const balance = await multicall.wrap(contract).balanceOf(token.address, address); + return [drillBalance(token, balance.toString())]; + }, + }); + } +} diff --git a/src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-helper.ts b/src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-helper.ts new file mode 100644 index 000000000..6cbe65bd4 --- /dev/null +++ b/src/apps/sushiswap-bentobox/helpers/sushiswap-bentobox.vault.contract-position-helper.ts @@ -0,0 +1,103 @@ +import { Inject, Injectable } from '@nestjs/common'; +import request, { gql } from 'graphql-request'; +import _ from 'lodash'; +import moment from 'moment'; + +import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface'; +import { buildDollarDisplayItem } from '~app-toolkit/helpers/presentation/display-item.present'; +import { getTokenImg } from '~app-toolkit/helpers/presentation/image.present'; +import { Cache } from '~cache/cache.decorator'; +import { ContractType } from '~position/contract.interface'; +import { ContractPosition } from '~position/position.interface'; +import { supplied } from '~position/position.utils'; +import { Network } from '~types/network.interface'; + +import { SushiswapBentoboxContractFactory } from '../contracts'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +type TokensResponse = { + tokens?: { + id: string; + }[]; +}; + +const allTokensQuery = gql` + { + tokens(first: 500) { + id + } + } +`; + +type SushiswapBentoBoxGetPositionParams = { + bentoBoxAddress: string; + network: Network; + subgraphUrl: string; +}; + +const appId = SUSHISWAP_BENTOBOX_DEFINITION.id; +const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id; + +@Injectable() +export class SushiSwapBentoBoxContractPositionHelper { + constructor( + @Inject(SushiswapBentoboxContractFactory) + private readonly sushiSwapBentoBoxContractFactory: SushiswapBentoboxContractFactory, + @Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit, + ) {} + + @Cache({ + instance: 'business', + key: ({ network }: { url: string; network: Network }) => + `apps-v3:${SUSHISWAP_BENTOBOX_DEFINITION.id}:${network}:api-data`, + ttl: moment.duration(1, 'hour').asSeconds(), + }) + private async getBentoBoxTokens(opts: { url: string; network: Network }) { + const response = await request(opts.url, allTokensQuery, {}); + return response.tokens ?? []; + } + + async getPositions({ bentoBoxAddress, network, subgraphUrl }: SushiswapBentoBoxGetPositionParams) { + const multicall = this.appToolkit.getMulticall(network); + const prices = await this.appToolkit.getBaseTokenPrices(network); + + // Get all configured tokens in this Bentobox + const bentoBoxTokens = await this.getBentoBoxTokens({ url: subgraphUrl, network }); + + const positions = await Promise.all( + bentoBoxTokens.map(async token => { + const tokenAddress = token.id.toLowerCase(); + + const baseToken = prices.find(p => p.address === tokenAddress); + if (!baseToken) return null; + + const tokenContract = this.sushiSwapBentoBoxContractFactory.erc20({ address: tokenAddress, network }); + const balanceOfRaw = await multicall.wrap(tokenContract).balanceOf(bentoBoxAddress); + const balanceOf = Number(balanceOfRaw) / 10 ** baseToken.decimals; + const liquidity = balanceOf * baseToken.price; + + const position: ContractPosition = { + type: ContractType.POSITION, + network, + address: baseToken.address, + appId, + groupId, + tokens: [supplied(baseToken)], + dataProps: { + liquidity, + }, + displayProps: { + statsItems: [{ label: 'Liquidity', value: buildDollarDisplayItem(liquidity) }], + label: `${baseToken.symbol} Vault`, + secondaryLabel: buildDollarDisplayItem(baseToken.price), + images: [getTokenImg(baseToken.address, network)], + }, + }; + + return position; + }), + ); + + return _.compact(positions); + } +} diff --git a/src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.balance-fetcher.ts b/src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.balance-fetcher.ts new file mode 100644 index 000000000..2b7751647 --- /dev/null +++ b/src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.balance-fetcher.ts @@ -0,0 +1,34 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { presentBalanceFetcherResponse } from '~app-toolkit/helpers/presentation/balance-fetcher-response.present'; +import { BalanceFetcher } from '~balance/balance-fetcher.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionBalanceHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-balance-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const network = Network.POLYGON_MAINNET; + +@Register.BalanceFetcher(SUSHISWAP_BENTOBOX_DEFINITION.id, network) +export class PolygonSushiSwapBentoBoxBalanceFetcher implements BalanceFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionBalanceHelper) + private readonly balanceHelper: SushiSwapBentoBoxContractPositionBalanceHelper, + ) {} + + async getBalances(address: string) { + const balances = await this.balanceHelper.getBalances({ + address, + network, + bentoBoxAddress: '0x0319000133d3ada02600f0875d2cf03d442c3367', + }); + + return presentBalanceFetcherResponse([ + { + label: 'SushiSwap BentoBox', + assets: balances, + }, + ]); + } +} diff --git a/src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.vault.contract-position-fetcher.ts b/src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.vault.contract-position-fetcher.ts new file mode 100644 index 000000000..29914e3d2 --- /dev/null +++ b/src/apps/sushiswap-bentobox/polygon/sushiswap-bentobox.vault.contract-position-fetcher.ts @@ -0,0 +1,30 @@ +import { Inject } from '@nestjs/common'; + +import { Register } from '~app-toolkit/decorators'; +import { PositionFetcher } from '~position/position-fetcher.interface'; +import { ContractPosition } from '~position/position.interface'; +import { Network } from '~types/network.interface'; + +import { SushiSwapBentoBoxContractPositionHelper } from '../helpers/sushiswap-bentobox.vault.contract-position-helper'; +import { SUSHISWAP_BENTOBOX_DEFINITION } from '../sushiswap-bentobox.definition'; + +const appId = SUSHISWAP_BENTOBOX_DEFINITION.id; +const groupId = SUSHISWAP_BENTOBOX_DEFINITION.groups.vault.id; +const network = Network.POLYGON_MAINNET; + +@Register.ContractPositionFetcher({ appId, groupId, network, options: { includeInTvl: true } }) +export class PolygonSushiSwapBentoBoxContractPositionFetcher implements PositionFetcher { + constructor( + @Inject(SushiSwapBentoBoxContractPositionHelper) + private readonly positionHelper: SushiSwapBentoBoxContractPositionHelper, + ) {} + + async getPositions() { + return this.positionHelper.getPositions({ + bentoBoxAddress: '0x0319000133d3ada02600f0875d2cf03d442c3367', + network, + subgraphUrl: 'https://api.thegraph.com/subgraphs/name/matthewlilley/bentobox-polygon', + //subgraphUrl: 'https://api.thegraph.com/subgraphs/name/sushiswap/matic-bentobox', - currently failling to sync + }); + } +} diff --git a/src/apps/sushiswap-bentobox/sushiswap-bentobox.definition.ts b/src/apps/sushiswap-bentobox/sushiswap-bentobox.definition.ts new file mode 100644 index 000000000..6767fc4ed --- /dev/null +++ b/src/apps/sushiswap-bentobox/sushiswap-bentobox.definition.ts @@ -0,0 +1,39 @@ +import { Register } from '~app-toolkit/decorators'; +import { AppDefinition, appDefinition } from '~app/app.definition'; +import { AppAction, AppTag, GroupType } from '~app/app.interface'; +import { Network } from '~types/network.interface'; + +export const SUSHISWAP_BENTOBOX_DEFINITION = appDefinition({ + id: 'sushiswap-bentobox', + name: 'SushiSwap BentoBox', + description: `BentoBox is a token vault that generates yield for the capital deposited into it`, + groups: { + vault: { id: 'vault', type: GroupType.POSITION, label: 'SushiSwap BentoBox', groupLabel: 'Farms' }, + }, + url: 'https://sushi.com', + tags: [AppTag.YIELD_AGGREGATOR], + links: { + github: 'https://github.com/sushiswap', + twitter: 'https://twitter.com/sushiswap', + discord: 'https://discord.com/invite/NVPXN4e', + medium: 'https://sushichef.medium.com/', + }, + supportedNetworks: { + [Network.ARBITRUM_MAINNET]: [AppAction.VIEW], + [Network.BINANCE_SMART_CHAIN_MAINNET]: [AppAction.VIEW], + [Network.ETHEREUM_MAINNET]: [AppAction.VIEW], + [Network.POLYGON_MAINNET]: [AppAction.VIEW], + }, + primaryColor: '#887eb3', + token: { + address: '0x6b3595068778dd592e39a122f4f5a5cf09c90fe2', + network: Network.ETHEREUM_MAINNET, + }, +}); + +@Register.AppDefinition(SUSHISWAP_BENTOBOX_DEFINITION.id) +export class SushiSwapBentoBoxAppDefinition extends AppDefinition { + constructor() { + super(SUSHISWAP_BENTOBOX_DEFINITION); + } +} diff --git a/src/apps/sushiswap-bentobox/sushiswap-bentobox.module.ts b/src/apps/sushiswap-bentobox/sushiswap-bentobox.module.ts new file mode 100644 index 000000000..af9819ac5 --- /dev/null +++ b/src/apps/sushiswap-bentobox/sushiswap-bentobox.module.ts @@ -0,0 +1,38 @@ +import { Register } from '~app-toolkit/decorators'; +import { AbstractApp } from '~app/app.dynamic-module'; + +import { ArbitrumSushiSwapBentoBoxBalanceFetcher } from './arbitrum/sushiswap-bentobox.balance-fetcher'; +import { ArbitrumSushiSwapBentoBoxContractPositionFetcher } from './arbitrum/sushiswap-bentobox.vault.contract-position-fetcher'; +import { BscSushiSwapBentoBoxBalanceFetcher } from './binance-smart-chain/sushiswap-bentobox.balance-fetcher'; +import { BscSushiSwapBentoBoxContractPositionFetcher } from './binance-smart-chain/sushiswap-bentobox.vault.contract-position-fetcher'; +import { SushiswapBentoboxContractFactory } from './contracts'; +import { EthereumSushiSwapBentoBoxBalanceFetcher } from './ethereum/sushiswap-bentobox.balance-fetcher'; +import { EthereumSushiSwapBentoBoxContractPositionFetcher } from './ethereum/sushiswap-bentobox.vault.contract-position-fetcher'; +import { SushiSwapBentoBoxContractPositionBalanceHelper } from './helpers/sushiswap-bentobox.vault.contract-position-balance-helper'; +import { SushiSwapBentoBoxContractPositionHelper } from './helpers/sushiswap-bentobox.vault.contract-position-helper'; +import { PolygonSushiSwapBentoBoxBalanceFetcher } from './polygon/sushiswap-bentobox.balance-fetcher'; +import { PolygonSushiSwapBentoBoxContractPositionFetcher } from './polygon/sushiswap-bentobox.vault.contract-position-fetcher'; +import { SushiSwapBentoBoxAppDefinition, SUSHISWAP_BENTOBOX_DEFINITION } from './sushiswap-bentobox.definition'; + +@Register.AppModule({ + appId: SUSHISWAP_BENTOBOX_DEFINITION.id, + providers: [ + SushiSwapBentoBoxAppDefinition, + SushiswapBentoboxContractFactory, + SushiSwapBentoBoxContractPositionBalanceHelper, + SushiSwapBentoBoxContractPositionHelper, + // Arbitrum + ArbitrumSushiSwapBentoBoxContractPositionFetcher, + ArbitrumSushiSwapBentoBoxBalanceFetcher, + // Binance Smart Chain + BscSushiSwapBentoBoxContractPositionFetcher, + BscSushiSwapBentoBoxBalanceFetcher, + // Ethereum + EthereumSushiSwapBentoBoxContractPositionFetcher, + EthereumSushiSwapBentoBoxBalanceFetcher, + // Polygon + PolygonSushiSwapBentoBoxContractPositionFetcher, + PolygonSushiSwapBentoBoxBalanceFetcher, + ], +}) +export class SushiSwapBentoBoxAppModule extends AbstractApp() {}