diff --git a/.github/workflows/assembly-production-deployment-automation.yml b/.github/workflows/assembly-production-deployment-automation.yml new file mode 100644 index 0000000..22ef5b6 --- /dev/null +++ b/.github/workflows/assembly-production-deployment-automation.yml @@ -0,0 +1,27 @@ +name: production-deployment-automation + +on: + push: + branches: + - 'master' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Deploy to Server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.REMOTE_HOST }} + username: ${{ secrets.REMOTE_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + port: 22 + script: | + cd ${{ secrets.REMOTE_TARGET }} && \ + git reset --hard && git clean -df && \ + git pull && \ + npm i && \ + npm run build --if-present && \ + npm run generate --if-present && \ + pm2 restart assembly --update-env diff --git a/assets/icons/1inch.svg b/assets/icons/1inch.svg new file mode 100644 index 0000000..ffc89e0 --- /dev/null +++ b/assets/icons/1inch.svg @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/components/common/input/InputPercent.vue b/components/common/input/InputPercent.vue new file mode 100644 index 0000000..278a03b --- /dev/null +++ b/components/common/input/InputPercent.vue @@ -0,0 +1,85 @@ + + + diff --git a/components/common/input/ToggleButton.vue b/components/common/input/ToggleButton.vue index a54ad8b..e7c8625 100644 --- a/components/common/input/ToggleButton.vue +++ b/components/common/input/ToggleButton.vue @@ -11,10 +11,10 @@ @click="toggle" >
- +
{{ label }}
diff --git a/components/common/list/List.vue b/components/common/list/List.vue index d0aada6..5c74ad2 100644 --- a/components/common/list/List.vue +++ b/components/common/list/List.vue @@ -5,7 +5,13 @@
-
+
@@ -27,6 +33,10 @@ export default defineComponent({ type: Array, default: () => [], }, + itemsWrapperClasses: { + type: String, + default: '' + }, divided: { type: Boolean, default: false, diff --git a/components/common/menu/Menu.vue b/components/common/menu/Menu.vue index 1b74af4..67a64f1 100644 --- a/components/common/menu/Menu.vue +++ b/components/common/menu/Menu.vue @@ -14,7 +14,7 @@
diff --git a/components/swap/SwapCard.vue b/components/swap/SwapCard.vue new file mode 100644 index 0000000..bbf5398 --- /dev/null +++ b/components/swap/SwapCard.vue @@ -0,0 +1,496 @@ + + + diff --git a/composables/swap/use1InchSwap.ts b/composables/swap/use1InchSwap.ts new file mode 100644 index 0000000..43a9846 --- /dev/null +++ b/composables/swap/use1InchSwap.ts @@ -0,0 +1,60 @@ +import { useBigNumber } from "../useBigNumber"; +import { useDSA } from "../useDSA"; +import { useFormatting } from "../useFormatting"; +import { useMath } from "../useMath"; +import { Network, useNetwork } from "../useNetwork"; + +export const use1InchSwap = () => { + const { divWithDec } = useMath(); + const { activeNetworkId } = useNetwork(); + const { dsa, activeAccount } = useDSA(); + const { isZero, ensureValue, gt, minus, times, plus, toBN } = useBigNumber(); + const { formatPercent, getFractionDigits } = useFormatting(); + + /** + * @dev Get different sell spell, based on simulation mode on/offand account network . + * Shared params: + * @param {string} params.buyAddr - buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param {string} params.sellAddr - selling token amount.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) + * @param {number} params.sellAmt - selling token amount. + * @param {number} params.unitAmt - unit amount of buyAmt/sellAmt with slippage. + * @param {number} params.setId - set token amount at this ID in `InstaMemory` Contract. + * + * 1Inch related params: + * @param {string} params.calldata - data from 1inch API. + * + * 1Split related params(using in simulation mode): + * @param {number[]} params.distribution - distribution of swap across different dex. + * @param {number} params.disableDexes - disable a dex. (To disable none: 0) + * @param {number} params.getId - get token amount at this ID from `InstaMemory` Contract. + */ + function getSellSpell({ + buyAddr, + sellAddr, + sellAmt, + unitAmt, + calldata, + setId + }) { + if ( + activeNetworkId.value === Network.Polygon || + activeAccount.value.version == 2 + ) { + return { + connector: "1INCH-A", + method: "sell", + args: [buyAddr, sellAddr, sellAmt, unitAmt, calldata, setId] + }; + } + + return { + connector: "oneInch", + method: "sellThree", + args: [buyAddr, sellAddr, sellAmt, unitAmt, calldata, setId] + }; + } + + return { + getSellSpell + }; +}; diff --git a/composables/useMath.ts b/composables/useMath.ts new file mode 100644 index 0000000..09a9c08 --- /dev/null +++ b/composables/useMath.ts @@ -0,0 +1,66 @@ +import { useBigNumber } from './useBigNumber' + +const { pow, div, toBN, lt, isZero } = useBigNumber() + +export function useMath() { + // Convert bigNumber in string (use to save us from big number error on web3) + // TODO - start using big number library for it? + function bigNumInString(x) { + if (Math.abs(x) < 1.0) { + const e = parseInt(x.toString().split('e-')[1]) + if (e) { + x *= Math.pow(10, e - 1) + x = '0.' + new Array(e).join('0') + x.toString().substring(2) + } + } else { + let e = parseInt(x.toString().split('+')[1]) + if (e > 20) { + e -= 20 + x /= Math.pow(10, e) + x += new Array(e + 1).join('0') + } + } + return x + } + + // Use to convert large decimal into small. Eg:- number 321.242312 with power 3 = 321.242 + function cleanDecimal(num, power) { + let MUL_DIV = 100 + if (power || power === 0) { + MUL_DIV = 10 ** power + } else { + if (num < 0.01) MUL_DIV = 10 ** 6 + if (num < 1) MUL_DIV = 10 ** 4 + } + return Math.floor(Number(num) * MUL_DIV) / MUL_DIV + } + + function roundDecimals(value) { + if (isZero(value)) return 0.0 + if (lt(value, '0.001')) return cleanDecimal(toBN(value).toNumber(), 6) + if (lt(value, '0.01')) return cleanDecimal(toBN(value).toNumber(), 5) + if (lt(value, '0.1')) return cleanDecimal(toBN(value).toNumber(), 4) + if (lt(value, '1')) return cleanDecimal(toBN(value).toNumber(), 3) + return cleanDecimal(toBN(value).toNumber(), 3) + } + + function divWithDec(num, power) { + power = typeof power !== 'undefined' ? power : 0 + const divider = pow('10', power) + return div(num, divider).toFixed() + } + + /** + * Checks divisor for 0. Returns 0 instead of NaN. + * + * @param {number} divident Divident. + * @param {number} divisor Divisor. + */ + function safeDivide(divident, divisor) { + if (!divisor) return 0 + + return divident / divisor + } + + return { bigNumInString, divWithDec, cleanDecimal, safeDivide, roundDecimals } +} diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 0000000..5ed647c --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,21 @@ +module.exports = { + apps: [ + { + name: 'assembly', + exec_mode: 'cluster', + instances: 'max', + script: './node_modules/nuxt/bin/nuxt.js', + args: 'start', + env: { + NODE_ENV: 'production', + HOST: 'localhost', + PORT: 4000, + }, + env_production: { + NODE_ENV: 'production', + PORT: '4000', + HOST: 'localhost' + }, + }, + ], +} diff --git a/package.json b/package.json index 23b0e95..8c6631a 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "v-tooltip": "^2.1.3", "vue-clipboard2": "^0.3.1", "vue-composable": "^1.0.0-beta.23", + "waait": "^1.0.5", "walletlink": "^2.1.6", "web3": "^1.4.0", "web3modal": "^1.9.3" diff --git a/pages/1inch.vue b/pages/1inch.vue new file mode 100644 index 0000000..387cf0e --- /dev/null +++ b/pages/1inch.vue @@ -0,0 +1,189 @@ + + + diff --git a/pages/index.vue b/pages/index.vue index 1069ee5..ff0288c 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -35,6 +35,7 @@ import { useNetwork } from "~/composables/useNetwork"; import AaveIcon from "~/assets/icons/aave.svg?inline"; import CompoundIcon from "~/assets/icons/compound.svg?inline"; import MakerIcon from "~/assets/icons/makerdao.svg?inline"; +import OneInchIcon from "~/assets/icons/1inch.svg?inline"; const appsPerNetwork = { mainnet: [ @@ -58,6 +59,13 @@ const appsPerNetwork = { name: "MakerDAO", url: "/mainnet/maker", description: "Collateralized Debt" + }, + { + id: "1inch", + icon: OneInchIcon, + name: "1inch", + url: "/1inch", + description: "DEX Aggregator" } ], polygon: [ @@ -67,6 +75,13 @@ const appsPerNetwork = { name: "Aave v2", url: "/polygon/aave-v2", description: "Lend and borrow straight from your Gnosis Safe" + }, + { + id: "1inch", + icon: OneInchIcon, + name: "1inch", + url: "/1inch", + description: "DEX Aggregator" } ] }; diff --git a/yarn.lock b/yarn.lock index 87924f9..b5275a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11642,6 +11642,11 @@ vuex@^3.6.2: resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.6.2.tgz#236bc086a870c3ae79946f107f16de59d5895e71" integrity sha512-ETW44IqCgBpVomy520DT5jf8n0zoCac+sxWnn+hMe/CzaSejb/eVw2YToiXYX+Ex/AuHHia28vWTq4goAexFbw== +waait@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/waait/-/waait-1.0.5.tgz#6a3c7aaa88bd0a1a545e9d47890b9595bebf9aa7" + integrity sha512-wp+unA4CpqxvBUKHHv8D86fK4jWByHAWyhEXXVHfVUZfK+16ylpj7hjQ58Z8j9ntu8XNukRQT8Fi5qbyJ8rkyw== + walletlink@^2.1.6: version "2.1.6" resolved "https://registry.yarnpkg.com/walletlink/-/walletlink-2.1.6.tgz#4e48310af09bb0c940a156c26c1d0b1b9506ddb9"