diff --git a/batcher-ui/config/config.mainnet.ts b/batcher-ui/config/config.mainnet.ts deleted file mode 100644 index cd80b3d8..00000000 --- a/batcher-ui/config/config.mainnet.ts +++ /dev/null @@ -1,124 +0,0 @@ -// @ts-nocheck -import { defineConfig } from 'umi'; - -import defaultSettings from './defaultSettings'; -import proxy from './proxy'; - -const { REACT_APP_ENV } = process.env; - -const BATCHER_LOGO = 'https://storage.googleapis.com/marigold-public-bucket/batcher-logo.png'; - -export default defineConfig({ - hash: true, - antd: {}, - dva: { - hmr: true, - }, - layout: { - // https://umijs.org/zh-CN/plugins/plugin-layout - locale: true, - siderWidth: 208, - ...defaultSettings, - }, - dynamicImport: { - loading: '@ant-design/pro-layout/es/PageLoading', - }, - targets: { - ie: 11, - }, - // umi routes: https://umijs.org/docs/routing - access: {}, - theme: { - 'root-entry-name': 'variable', - }, - // esbuild is father build tools - // https://umijs.org/plugins/plugin-esbuild - esbuild: {}, - title: false, - ignoreMomentLocale: true, - proxy: proxy[REACT_APP_ENV || 'dev'], - manifest: { - basePath: '/', - }, - // Fast Refresh 热更新 - fastRefresh: {}, - nodeModulesTransform: { type: 'none' }, - mfsu: {}, - webpack5: {}, - exportStatic: {}, - favicon: - 'https://uploads-ssl.webflow.com/616ab4741d375d1642c19027/617952f8510cfc45cbf09312_Favicon(3)(1).png', - define: { - REACT_APP_NETWORK_TARGET: 'MAINNET', - REACT_APP_BATCHER_URI: 'https://batcher.marigold.dev', - REACT_APP_PATH_TO_BATCHER_LOGO: BATCHER_LOGO, - REACT_APP_TEZOS_NODE_URI: 'https://mainnet.tezos.marigold.dev', - REACT_APP_TZKT_URI_API: 'https://api.tzkt.io', - REACT_APP_BATCHER_CONTRACT_HASH: 'KT1WYcNPEcd33zGVAQcn8x2MLgDUmDesx3nF', - GA_TRACKING_ID: 'G-VS1FBNXJ7N', - }, - metas: [ - { - property: 'og:locale', - content: 'en_US', - }, - { - property: 'og:title', - content: 'Batcher DEX', - }, - { - property: 'og:description', - content: - 'The aim of the batch clearing dex is to enable users to deposit tokens with the aim of being swapped at a fair price with bounded slippage and almost no impermanent loss..', - }, - { - property: 'og:url', - content: 'https://batcher.marigold.dev', - }, - { - property: 'og:site_name', - content: 'Batcher DEX', - }, - { - property: 'og:image', - content: BATCHER_LOGO, - }, - { - property: 'og:image:secure_url', - content: BATCHER_LOGO, - }, - { - property: 'og:image:width', - content: '400', - }, - { - property: 'og:image:height', - content: '400', - }, - { - name: 'twitter:card', - content: 'summary', - }, - { - name: 'twitter:description', - content: - 'The aim of the batch clearing dex is to enable users to deposit tokens with the aim of being swapped at a fair price with bounded slippage and almost no impermanent loss.', - }, - { - name: 'twitter:title', - content: 'Batcher DEX', - }, - { - name: 'twitter:site', - content: '@Marigold_Dev', - }, - { - name: 'twitter:image', - content: BATCHER_LOGO, - }, - { - name: 'twitter:creator', - content: '@Marigold_Dev', - }, - ], -}); diff --git a/batcher-ui/src/components/Exchange/index.tsx b/batcher-ui/src/components/Exchange/index.tsx deleted file mode 100644 index b98e4cb0..00000000 --- a/batcher-ui/src/components/Exchange/index.tsx +++ /dev/null @@ -1,353 +0,0 @@ -import React, { useState, useEffect } from 'react'; -import { SwapOutlined, SettingOutlined, RetweetOutlined, DollarOutlined } from '@ant-design/icons'; -import { Input, Button, Space, Typography, Col, Row, message, Form, Drawer, Radio } from 'antd'; -import { compose, OpKind, WalletContract } from '@taquito/taquito'; -import { useModel } from 'umi'; -import '@/components/Exchange/index.less'; -import '@/global.less'; -import { ExchangeProps, PriceType, BatcherStatus } from '@/extra_utils/types'; -// import { ReactComponent as ExchangeDollarSvg } from '../../../img/exchange-dollar.svg'; -import { getErrorMess, scaleAmountUp } from '@/extra_utils/utils'; -import { tzip12, Tzip12Module } from '@taquito/tzip12'; -import { tzip16 } from '@taquito/tzip16'; -const Exchange: React.FC = ({ - userAddress, - buyBalance, - sellBalance, - inversion, - setInversion, - tezos, - fee_in_mutez, - buyToken, - sellToken, - showDrawer, - updateAll, - setUpdateAll, - status, -}: ExchangeProps) => { - const [price, setPrice] = useState(PriceType.EXACT); - const [side, setSide] = useState(0); - const [amount, setAmount] = useState(0); - const { initialState } = useModel('@@initialState'); - const [batchClosed, setBatchClosed] = useState(false); - - const [form] = Form.useForm(); - - const triggerUpdate = () => { - setTimeout(function () { - const u = !updateAll; - setUpdateAll(u); - }, 5000); - }; - - const inverseTokenType = () => { - setInversion(!inversion); - const s = inversion ? 0 : 1; - setSide(s); - }; - - const depositToken = async () => { - if (!userAddress) { - return; - } - - tezos.setWalletProvider(initialState.wallet); - - tezos.setWalletProvider(initialState.wallet); - - console.info('tezos', initialState.tezos); - const tokenName = inversion ? buyToken.name : sellToken.name; - const selectedToken = inversion ? buyToken : sellToken; - const batcherContract = await tezos.wallet.at(REACT_APP_BATCHER_CONTRACT_HASH); - const tokenContract: WalletContract = await tezos.wallet.at( - inversion ? buyToken.address : sellToken.address, - compose(tzip12, tzip16), - ); - const tokenId = inversion ? buyToken.token_id : sellToken.token_id; - - const scaled_amount = inversion - ? scaleAmountUp(amount, buyToken.decimals) - : scaleAmountUp(amount, sellToken.decimals); - - const selected_side = inversion ? 0 : 1; - let tolerance = 0; - - if (selected_side == 0) { - if (price === PriceType.WORSE) { - tolerance = 0; - } else if (price === PriceType.EXACT) { - tolerance = 1; - } else { - tolerance = 2; - } - } else { - if (price === PriceType.WORSE) { - tolerance = 2; - } else if (price === PriceType.EXACT) { - tolerance = 1; - } else { - tolerance = 0; - } - } - - // This is for fa2 token standard. I.e, USDT token - const fa2_add_operator_params = [ - { - add_operator: { - owner: userAddress, - operator: REACT_APP_BATCHER_CONTRACT_HASH, - token_id: tokenId, - }, - }, - ]; - - const fa2_remove_operator_params = [ - { - remove_operator: { - owner: userAddress, - operator: REACT_APP_BATCHER_CONTRACT_HASH, - token_id: tokenId, - }, - }, - ]; - - let loading = function () { - return undefined; - }; - - try { - let order_batcher_op = null; - - console.log('operations-token', selectedToken); - console.log('operations-side', side); - console.log('operations-fee-in-mutez', fee_in_mutez); - console.log('operations-scaled-amount', fee_in_mutez); - - const swap_params = { - swap: { - from: { - token: { - token_id: inversion ? buyToken.token_id : sellToken.token_id, - name: inversion ? buyToken.name : sellToken.name, - address: inversion ? buyToken.address : sellToken.address, - decimals: inversion ? buyToken.decimals : sellToken.decimals, - standard: inversion ? buyToken.standard : sellToken.standard, - }, - amount: scaled_amount, - }, - to: { - token_id: inversion ? sellToken.token_id : buyToken.token_id, - name: inversion ? sellToken.name : buyToken.name, - address: inversion ? sellToken.address : buyToken.address, - decimals: inversion ? sellToken.decimals : buyToken.decimals, - standard: inversion ? sellToken.standard : buyToken.standard, - }, - }, - created_at: new Date(), - side: selected_side, - tolerance: tolerance, - }; - - console.log('test'); - - if (selectedToken.standard === 'FA1.2 token') { - console.log('inversion', inversion); - console.log('buy', buyToken); - console.log('sell', sellToken); - const tokenfa12Contract: WalletContract = await tezos.wallet.at( - buyToken.address, - compose(tzip12, tzip16), - ); - console.log('methods', tokenfa12Contract.methods); - order_batcher_op = await tezos.wallet - .batch([ - { - kind: OpKind.TRANSACTION, - ...tokenfa12Contract.methods - .approve(REACT_APP_BATCHER_CONTRACT_HASH, scaled_amount) - .toTransferParams(), - }, - { - kind: OpKind.TRANSACTION, - ...batcherContract.methodsObject.deposit(swap_params).toTransferParams(), - to: REACT_APP_BATCHER_CONTRACT_HASH, - amount: fee_in_mutez, - mutez: true, - }, - ]) - .send(); - } - - if (selectedToken.standard === 'FA2 token') { - order_batcher_op = await tezos.wallet - .batch([ - { - kind: OpKind.TRANSACTION, - ...tokenContract.methods.update_operators(fa2_add_operator_params).toTransferParams(), - }, - { - kind: OpKind.TRANSACTION, - ...batcherContract.methodsObject.deposit(swap_params).toTransferParams(), - to: REACT_APP_BATCHER_CONTRACT_HASH, - amount: fee_in_mutez, - mutez: true, - }, - { - kind: OpKind.TRANSACTION, - ...tokenContract.methods - .update_operators(fa2_remove_operator_params) - .toTransferParams(), - }, - ]) - .send(); - } - - loading = message.loading('Attempting to place swap order for ' + tokenName, 0); - const confirm = await order_batcher_op.confirmation(); - if (!confirm.completed) { - console.error(confirm); - message.error('Failed to deposit ' + tokenName); - throw new Error( - 'Failed to deposit ' + (inversion ? buyToken.name : sellToken.name) + ' token', - ); - } else { - loading(); - form.resetFields(); - message.success('Successfully deposited ' + tokenName); - triggerUpdate(); - } - } catch (error) { - console.log('deposit error', error); - const converted_error_message = getErrorMess(error); - message.error(converted_error_message); - loading(); - form.resetFields(); - } - }; - - const isBatchClosed = () => { - console.info('EXCHANGE: isBatchClosed', status); - if (status === BatcherStatus.CLOSED) { - setBatchClosed(true); - } else { - setBatchClosed(false); - } - }; - - useEffect(() => { - isBatchClosed(); - }, [status]); - return ( -
-
- - - - From {inversion ? buyToken.name : sellToken.name} - - } - name="amount" - rules={[ - { required: true, message: 'Please input your amount' }, - { pattern: new RegExp(/^[+-]?([0-9]*[.])?[0-9]+$/), message: 'Invalid number' }, - () => ({ - validator(_, value) { - if (inversion && Number.parseFloat(value) > buyBalance) { - return Promise.reject('Greater than the balance'); - } else if (!inversion && Number.parseFloat(value) > sellBalance) { - return Promise.reject('Greater than the balance'); - } - return Promise.resolve(); - }, - }), - ]} - > - { - const regrex = /^[+-]?([0-9]*[.])?[0-9]+$/; - if (regrex.test(e.target.value)) { - setAmount(Number.parseFloat(e.target.value)); - } - }} - /> - - - Select the price you want to sell - - - setPrice(PriceType.WORSE)} - > - Worse price / Better fill - - setPrice(PriceType.EXACT)} - > - Oracle Price - - setPrice(PriceType.BETTER)} - > - Better Price / Worse Fill - - - - - - - -
- -
-
- - - - To {inversion ? sellToken.name : buyToken.name} - - - {userAddress && !batchClosed ? ( - -
- -
-
- ) : ( -
- )} -
-
- ); -}; - -export default Exchange;