1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

merge v4 into v4-c2d

This commit is contained in:
Bogdan Fazakas 2022-03-03 17:45:47 +02:00
commit 2c05e1f945
23 changed files with 502 additions and 592 deletions

293
package-lock.json generated
View File

@ -13,7 +13,7 @@
"@coingecko/cryptoformat": "^0.4.4",
"@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^1.0.0-next.21",
"@oceanprotocol/lib": "^1.0.0-next.24",
"@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^4.0.6",
"@tippyjs/react": "^4.2.6",
@ -26,7 +26,6 @@
"decimal.js": "^10.3.1",
"dom-confetti": "^0.2.2",
"dotenv": "^15.0.0",
"ethereum-blockies": "github:MyEtherWallet/blockies",
"filesize": "^8.0.6",
"formik": "^2.2.9",
"gray-matter": "^4.0.3",
@ -35,6 +34,7 @@
"jwt-decode": "^3.1.2",
"lodash.debounce": "^4.0.8",
"lodash.omit": "^4.5.0",
"myetherwallet-blockies": "^0.1.1",
"next": "^12.1.0",
"query-string": "^7.1.0",
"react": "^17.0.2",
@ -2937,46 +2937,14 @@
},
"node_modules/@next/env": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/env/-/env-12.1.0.tgz",
"integrity": "sha512-nrIgY6t17FQ9xxwH3jj0a6EOiQ/WDHUos35Hghtr+SWN/ntHIQ7UpuvSi0vaLzZVHQWaDupKI+liO5vANcDeTQ=="
},
"node_modules/@next/swc-android-arm64": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-12.1.0.tgz",
"integrity": "sha512-/280MLdZe0W03stA69iL+v6I+J1ascrQ6FrXBlXGCsGzrfMaGr7fskMa0T5AhQIVQD4nA/46QQWxG//DYuFBcA==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-darwin-arm64": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-12.1.0.tgz",
"integrity": "sha512-R8vcXE2/iONJ1Unf5Ptqjk6LRW3bggH+8drNkkzH4FLEQkHtELhvcmJwkXcuipyQCsIakldAXhRbZmm3YN1vXg==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
"license": "MIT"
},
"node_modules/@next/swc-darwin-x64": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-12.1.0.tgz",
"integrity": "sha512-ieAz0/J0PhmbZBB8+EA/JGdhRHBogF8BWaeqR7hwveb6SYEIJaDNQy0I+ZN8gF8hLj63bEDxJAs/cEhdnTq+ug==",
"cpu": [
"x64"
],
"license": "MIT",
"optional": true,
"os": [
"darwin"
@ -2985,126 +2953,6 @@
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-arm-gnueabihf": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-12.1.0.tgz",
"integrity": "sha512-njUd9hpl6o6A5d08dC0cKAgXKCzm5fFtgGe6i0eko8IAdtAPbtHxtpre3VeSxdZvuGFh+hb0REySQP9T1ttkog==",
"cpu": [
"arm"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-arm64-gnu": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-12.1.0.tgz",
"integrity": "sha512-OqangJLkRxVxMhDtcb7Qn1xjzFA3s50EIxY7mljbSCLybU+sByPaWAHY4px97ieOlr2y4S0xdPKkQ3BCAwyo6Q==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-arm64-musl": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-12.1.0.tgz",
"integrity": "sha512-hB8cLSt4GdmOpcwRe2UzI5UWn6HHO/vLkr5OTuNvCJ5xGDwpPXelVkYW/0+C3g5axbDW2Tym4S+MQCkkH9QfWA==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-x64-gnu": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.1.0.tgz",
"integrity": "sha512-OKO4R/digvrVuweSw/uBM4nSdyzsBV5EwkUeeG4KVpkIZEe64ZwRpnFB65bC6hGwxIBnTv5NMSnJ+0K/WmG78A==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-linux-x64-musl": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.1.0.tgz",
"integrity": "sha512-JohhgAHZvOD3rQY7tlp7NlmvtvYHBYgY0x5ZCecUT6eCCcl9lv6iV3nfu82ErkxNk1H893fqH0FUpznZ/H3pSw==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-win32-arm64-msvc": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.1.0.tgz",
"integrity": "sha512-T/3gIE6QEfKIJ4dmJk75v9hhNiYZhQYAoYm4iVo1TgcsuaKLFa+zMPh4056AHiG6n9tn2UQ1CFE8EoybEsqsSw==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-win32-ia32-msvc": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.1.0.tgz",
"integrity": "sha512-iwnKgHJdqhIW19H9PRPM9j55V6RdcOo6rX+5imx832BCWzkDbyomWnlzBfr6ByUYfhohb8QuH4hSGEikpPqI0Q==",
"cpu": [
"ia32"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@next/swc-win32-x64-msvc": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.1.0.tgz",
"integrity": "sha512-aBvcbMwuanDH4EMrL2TthNJy+4nP59Bimn8egqv6GHMVj0a44cU6Au4PjOhLNqEh9l+IpRGBqMTzec94UdC5xg==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"dev": true,
@ -3162,8 +3010,9 @@
}
},
"node_modules/@oceanprotocol/lib": {
"version": "1.0.0-next.21",
"license": "Apache-2.0",
"version": "1.0.0-next.24",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0-next.24.tgz",
"integrity": "sha512-T46pU320AHLd9iSTYX5YGr6qFilf0+2oTzuuNaCXWNon1CF+9M+n2W5E+afSwqd6xHnEuX/IIFsQpc3RUzo55g==",
"dependencies": {
"@oceanprotocol/contracts": "1.0.0-alpha.21",
"bignumber.js": "^9.0.2",
@ -4668,8 +4517,6 @@
},
"node_modules/@truffle/abi-utils": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/@truffle/abi-utils/-/abi-utils-0.2.9.tgz",
"integrity": "sha512-Nv4MGsA2vdI7G34nI0DfR/eSd5pbAUu+5EafYNqzgrS46y0LWhbIrSZ1NcM7cbhIrkpUn6OfNk49AjNM67TkSg==",
"license": "MIT",
"dependencies": {
"change-case": "3.0.2",
@ -4683,8 +4530,6 @@
},
"node_modules/@truffle/codec": {
"version": "0.11.27",
"resolved": "https://registry.npmjs.org/@truffle/codec/-/codec-0.11.27.tgz",
"integrity": "sha512-zPlbrGSZ975jscoJ4NhQpaJGwJXkasnpSoUAEjzppr6FCLKtutxssy6yfz4EUHaQDTg1SqxlVBfBhqYcrCyjvw==",
"license": "MIT",
"dependencies": {
"@truffle/abi-utils": "^0.2.9",
@ -4754,8 +4599,6 @@
},
"node_modules/@truffle/compile-common": {
"version": "0.7.28",
"resolved": "https://registry.npmjs.org/@truffle/compile-common/-/compile-common-0.7.28.tgz",
"integrity": "sha512-mZCEQ6fkOqbKYCJDT82q0vZCxOEsKRQ0zrPfKuSJEb0gF9DXIQcnMkyJpBSWzmyvien9/A7/jPiGQoC7PmNEUg==",
"license": "MIT",
"dependencies": {
"@truffle/error": "^0.1.0",
@ -4764,8 +4607,6 @@
},
"node_modules/@truffle/contract": {
"version": "4.4.9",
"resolved": "https://registry.npmjs.org/@truffle/contract/-/contract-4.4.9.tgz",
"integrity": "sha512-LSIxnpFDr824wUp4tiw2UHmDPr8io5UnzjlZX/QKuNIq+BB+JPRmkzItjwtvWzzIG3QOAGiqjtIgp1U6Mab/bw==",
"license": "MIT",
"dependencies": {
"@ensdomains/ensjs": "^2.0.1",
@ -4786,8 +4627,6 @@
},
"node_modules/@truffle/contract-schema": {
"version": "3.4.5",
"resolved": "https://registry.npmjs.org/@truffle/contract-schema/-/contract-schema-3.4.5.tgz",
"integrity": "sha512-heaGV9QWqef259HaF+0is/tsmhlZIbUSWhqvj0iwKmxoN92fghKijWwdVYhPIbsmGlrQuwPTZHSCnaOlO+gsFg==",
"license": "MIT",
"dependencies": {
"ajv": "^6.10.0",
@ -5093,8 +4932,6 @@
},
"node_modules/@truffle/debug-utils": {
"version": "6.0.9",
"resolved": "https://registry.npmjs.org/@truffle/debug-utils/-/debug-utils-6.0.9.tgz",
"integrity": "sha512-CVKVsbEWE0TzmTdGcxEeQvNhTKxkojIRox3LWh2Z8ZARtPiWwYl/lmPqfugh1665xmc2NVLI9qyP4ygVFPkvIQ==",
"license": "MIT",
"dependencies": {
"@truffle/codec": "^0.11.27",
@ -5555,8 +5392,6 @@
},
"node_modules/@trufflesuite/chromafi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@trufflesuite/chromafi/-/chromafi-3.0.0.tgz",
"integrity": "sha512-oqWcOqn8nT1bwlPPfidfzS55vqcIDdpfzo3HbU9EnUmcSTX+I8z0UyUFI3tZQjByVJulbzxHxUGS3ZJPwK/GPQ==",
"license": "MIT",
"dependencies": {
"camelcase": "^4.1.0",
@ -11673,10 +11508,6 @@
"safe-buffer": "^5.1.1"
}
},
"node_modules/ethereum-blockies": {
"version": "0.1.1",
"license": "MIT"
},
"node_modules/ethereum-bloom-filters": {
"version": "1.0.10",
"license": "MIT",
@ -13465,8 +13296,6 @@
},
"node_modules/he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"license": "MIT",
"peer": true,
"bin": {
@ -16233,6 +16062,11 @@
"dev": true,
"license": "ISC"
},
"node_modules/myetherwallet-blockies": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/myetherwallet-blockies/-/myetherwallet-blockies-0.1.1.tgz",
"integrity": "sha512-2UPR88/+L7rTVLqTM1Fu3Er9+m6XLMGaanP5wyq5+dGyv9TFbB5ohXRJA0jeYf+30gtlOlhlvzAWtwB6BiHWxQ=="
},
"node_modules/nan": {
"version": "2.15.0",
"license": "MIT"
@ -16281,8 +16115,7 @@
},
"node_modules/next": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/next/-/next-12.1.0.tgz",
"integrity": "sha512-s885kWvnIlxsUFHq9UGyIyLiuD0G3BUC/xrH0CEnH5lHEWkwQcHOORgbDF0hbrW9vr/7am4ETfX4A7M6DjrE7Q==",
"license": "MIT",
"dependencies": {
"@next/env": "12.1.0",
"caniuse-lite": "^1.0.30001283",
@ -18760,8 +18593,6 @@
},
"node_modules/simple-get": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-2.8.1.tgz",
"integrity": "sha512-lSSHRSw3mQNUGPAYRqo7xy9dhKmxFXIjLjp4KHpf99GEH2VH7C3AM+Qfx6du6jhfUi6Vm7XnbEVEf7Wb6N8jRw==",
"license": "MIT",
"dependencies": {
"decompress-response": "^3.3.0",
@ -23578,74 +23409,10 @@
"version": "2.0.0"
},
"@next/env": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/env/-/env-12.1.0.tgz",
"integrity": "sha512-nrIgY6t17FQ9xxwH3jj0a6EOiQ/WDHUos35Hghtr+SWN/ntHIQ7UpuvSi0vaLzZVHQWaDupKI+liO5vANcDeTQ=="
},
"@next/swc-android-arm64": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-12.1.0.tgz",
"integrity": "sha512-/280MLdZe0W03stA69iL+v6I+J1ascrQ6FrXBlXGCsGzrfMaGr7fskMa0T5AhQIVQD4nA/46QQWxG//DYuFBcA==",
"optional": true
},
"@next/swc-darwin-arm64": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-12.1.0.tgz",
"integrity": "sha512-R8vcXE2/iONJ1Unf5Ptqjk6LRW3bggH+8drNkkzH4FLEQkHtELhvcmJwkXcuipyQCsIakldAXhRbZmm3YN1vXg==",
"optional": true
"version": "12.1.0"
},
"@next/swc-darwin-x64": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-12.1.0.tgz",
"integrity": "sha512-ieAz0/J0PhmbZBB8+EA/JGdhRHBogF8BWaeqR7hwveb6SYEIJaDNQy0I+ZN8gF8hLj63bEDxJAs/cEhdnTq+ug==",
"optional": true
},
"@next/swc-linux-arm-gnueabihf": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-12.1.0.tgz",
"integrity": "sha512-njUd9hpl6o6A5d08dC0cKAgXKCzm5fFtgGe6i0eko8IAdtAPbtHxtpre3VeSxdZvuGFh+hb0REySQP9T1ttkog==",
"optional": true
},
"@next/swc-linux-arm64-gnu": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-12.1.0.tgz",
"integrity": "sha512-OqangJLkRxVxMhDtcb7Qn1xjzFA3s50EIxY7mljbSCLybU+sByPaWAHY4px97ieOlr2y4S0xdPKkQ3BCAwyo6Q==",
"optional": true
},
"@next/swc-linux-arm64-musl": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-12.1.0.tgz",
"integrity": "sha512-hB8cLSt4GdmOpcwRe2UzI5UWn6HHO/vLkr5OTuNvCJ5xGDwpPXelVkYW/0+C3g5axbDW2Tym4S+MQCkkH9QfWA==",
"optional": true
},
"@next/swc-linux-x64-gnu": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.1.0.tgz",
"integrity": "sha512-OKO4R/digvrVuweSw/uBM4nSdyzsBV5EwkUeeG4KVpkIZEe64ZwRpnFB65bC6hGwxIBnTv5NMSnJ+0K/WmG78A==",
"optional": true
},
"@next/swc-linux-x64-musl": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.1.0.tgz",
"integrity": "sha512-JohhgAHZvOD3rQY7tlp7NlmvtvYHBYgY0x5ZCecUT6eCCcl9lv6iV3nfu82ErkxNk1H893fqH0FUpznZ/H3pSw==",
"optional": true
},
"@next/swc-win32-arm64-msvc": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.1.0.tgz",
"integrity": "sha512-T/3gIE6QEfKIJ4dmJk75v9hhNiYZhQYAoYm4iVo1TgcsuaKLFa+zMPh4056AHiG6n9tn2UQ1CFE8EoybEsqsSw==",
"optional": true
},
"@next/swc-win32-ia32-msvc": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.1.0.tgz",
"integrity": "sha512-iwnKgHJdqhIW19H9PRPM9j55V6RdcOo6rX+5imx832BCWzkDbyomWnlzBfr6ByUYfhohb8QuH4hSGEikpPqI0Q==",
"optional": true
},
"@next/swc-win32-x64-msvc": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.1.0.tgz",
"integrity": "sha512-aBvcbMwuanDH4EMrL2TthNJy+4nP59Bimn8egqv6GHMVj0a44cU6Au4PjOhLNqEh9l+IpRGBqMTzec94UdC5xg==",
"optional": true
},
"@nodelib/fs.scandir": {
@ -23689,7 +23456,9 @@
}
},
"@oceanprotocol/lib": {
"version": "1.0.0-next.21",
"version": "1.0.0-next.24",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0-next.24.tgz",
"integrity": "sha512-T46pU320AHLd9iSTYX5YGr6qFilf0+2oTzuuNaCXWNon1CF+9M+n2W5E+afSwqd6xHnEuX/IIFsQpc3RUzo55g==",
"requires": {
"@oceanprotocol/contracts": "1.0.0-alpha.21",
"bignumber.js": "^9.0.2",
@ -24653,8 +24422,6 @@
},
"@truffle/abi-utils": {
"version": "0.2.9",
"resolved": "https://registry.npmjs.org/@truffle/abi-utils/-/abi-utils-0.2.9.tgz",
"integrity": "sha512-Nv4MGsA2vdI7G34nI0DfR/eSd5pbAUu+5EafYNqzgrS46y0LWhbIrSZ1NcM7cbhIrkpUn6OfNk49AjNM67TkSg==",
"requires": {
"change-case": "3.0.2",
"faker": "^5.3.1",
@ -24666,8 +24433,6 @@
},
"@truffle/codec": {
"version": "0.11.27",
"resolved": "https://registry.npmjs.org/@truffle/codec/-/codec-0.11.27.tgz",
"integrity": "sha512-zPlbrGSZ975jscoJ4NhQpaJGwJXkasnpSoUAEjzppr6FCLKtutxssy6yfz4EUHaQDTg1SqxlVBfBhqYcrCyjvw==",
"requires": {
"@truffle/abi-utils": "^0.2.9",
"@truffle/compile-common": "^0.7.28",
@ -24727,8 +24492,6 @@
},
"@truffle/compile-common": {
"version": "0.7.28",
"resolved": "https://registry.npmjs.org/@truffle/compile-common/-/compile-common-0.7.28.tgz",
"integrity": "sha512-mZCEQ6fkOqbKYCJDT82q0vZCxOEsKRQ0zrPfKuSJEb0gF9DXIQcnMkyJpBSWzmyvien9/A7/jPiGQoC7PmNEUg==",
"requires": {
"@truffle/error": "^0.1.0",
"colors": "1.4.0"
@ -24736,8 +24499,6 @@
},
"@truffle/contract": {
"version": "4.4.9",
"resolved": "https://registry.npmjs.org/@truffle/contract/-/contract-4.4.9.tgz",
"integrity": "sha512-LSIxnpFDr824wUp4tiw2UHmDPr8io5UnzjlZX/QKuNIq+BB+JPRmkzItjwtvWzzIG3QOAGiqjtIgp1U6Mab/bw==",
"requires": {
"@ensdomains/ensjs": "^2.0.1",
"@truffle/blockchain-utils": "^0.1.0",
@ -24971,8 +24732,6 @@
},
"@truffle/contract-schema": {
"version": "3.4.5",
"resolved": "https://registry.npmjs.org/@truffle/contract-schema/-/contract-schema-3.4.5.tgz",
"integrity": "sha512-heaGV9QWqef259HaF+0is/tsmhlZIbUSWhqvj0iwKmxoN92fghKijWwdVYhPIbsmGlrQuwPTZHSCnaOlO+gsFg==",
"requires": {
"ajv": "^6.10.0",
"debug": "^4.3.1"
@ -24980,8 +24739,6 @@
},
"@truffle/debug-utils": {
"version": "6.0.9",
"resolved": "https://registry.npmjs.org/@truffle/debug-utils/-/debug-utils-6.0.9.tgz",
"integrity": "sha512-CVKVsbEWE0TzmTdGcxEeQvNhTKxkojIRox3LWh2Z8ZARtPiWwYl/lmPqfugh1665xmc2NVLI9qyP4ygVFPkvIQ==",
"requires": {
"@truffle/codec": "^0.11.27",
"@trufflesuite/chromafi": "^3.0.0",
@ -25349,8 +25106,6 @@
},
"@trufflesuite/chromafi": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@trufflesuite/chromafi/-/chromafi-3.0.0.tgz",
"integrity": "sha512-oqWcOqn8nT1bwlPPfidfzS55vqcIDdpfzo3HbU9EnUmcSTX+I8z0UyUFI3tZQjByVJulbzxHxUGS3ZJPwK/GPQ==",
"requires": {
"camelcase": "^4.1.0",
"chalk": "^2.3.2",
@ -29649,9 +29404,6 @@
}
}
},
"ethereum-blockies": {
"version": "0.1.1"
},
"ethereum-bloom-filters": {
"version": "1.0.10",
"requires": {
@ -30904,8 +30656,6 @@
},
"he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"peer": true
},
"header-case": {
@ -32687,6 +32437,11 @@
"version": "0.0.8",
"dev": true
},
"myetherwallet-blockies": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/myetherwallet-blockies/-/myetherwallet-blockies-0.1.1.tgz",
"integrity": "sha512-2UPR88/+L7rTVLqTM1Fu3Er9+m6XLMGaanP5wyq5+dGyv9TFbB5ohXRJA0jeYf+30gtlOlhlvzAWtwB6BiHWxQ=="
},
"nan": {
"version": "2.15.0"
},
@ -32715,8 +32470,6 @@
},
"next": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/next/-/next-12.1.0.tgz",
"integrity": "sha512-s885kWvnIlxsUFHq9UGyIyLiuD0G3BUC/xrH0CEnH5lHEWkwQcHOORgbDF0hbrW9vr/7am4ETfX4A7M6DjrE7Q==",
"requires": {
"@next/env": "12.1.0",
"@next/swc-android-arm64": "12.1.0",
@ -34271,8 +34024,6 @@
},
"simple-get": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-2.8.1.tgz",
"integrity": "sha512-lSSHRSw3mQNUGPAYRqo7xy9dhKmxFXIjLjp4KHpf99GEH2VH7C3AM+Qfx6du6jhfUi6Vm7XnbEVEf7Wb6N8jRw==",
"requires": {
"decompress-response": "^3.3.0",
"once": "^1.3.1",

View File

@ -21,7 +21,7 @@
"@coingecko/cryptoformat": "^0.4.4",
"@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^1.0.0-next.21",
"@oceanprotocol/lib": "^1.0.0-next.24",
"@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^4.0.6",
"@tippyjs/react": "^4.2.6",
@ -34,7 +34,6 @@
"decimal.js": "^10.3.1",
"dom-confetti": "^0.2.2",
"dotenv": "^15.0.0",
"ethereum-blockies": "github:MyEtherWallet/blockies",
"filesize": "^8.0.6",
"formik": "^2.2.9",
"gray-matter": "^4.0.3",
@ -43,6 +42,7 @@
"jwt-decode": "^3.1.2",
"lodash.debounce": "^4.0.8",
"lodash.omit": "^4.5.0",
"myetherwallet-blockies": "^0.1.1",
"next": "^12.1.0",
"query-string": "^7.1.0",
"react": "^17.0.2",

View File

@ -10,9 +10,9 @@ export const poolDataQuery = gql`
poolData: pool(id: $pool) {
id
totalShares
liquidityProviderFee
liquidityProviderSwapFee
opcFee
marketSwapFee
publishMarketSwapFee
spotPrice
baseToken {
address
@ -41,6 +41,14 @@ export const poolDataQuery = gql`
baseTokenLiquidity
datatokenLiquidity
swapVolume
baseToken {
address
symbol
}
datatoken {
address
symbol
}
}
}
`

View File

@ -5,12 +5,13 @@ import {
} from 'src/@types/subgraph/PoolData'
export interface PoolInfo {
poolFee: string
marketFee: string
opfFee: string
liquidityProviderSwapFee: string
publishMarketSwapFee: string
opcFee: string
weightBaseToken: string
weightDt: string
datatokenSymbol: string
datatokenAddress: string
baseTokenSymbol: string
baseTokenAddress: string
totalPoolTokens: string

View File

@ -118,11 +118,6 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
useEffect(() => {
if (!poolData) return
// Fees - this will be renamed again in subgraph
const poolFee = getFee(poolData.liquidityProviderFee)
const marketFee = getFee(poolData.marketSwapFee)
const opfFee = getFee(poolData.opcFee)
// Total Liquidity
const totalLiquidityInOcean = isValidNumber(poolData.spotPrice)
? new Decimal(poolData.baseTokenLiquidity).add(
@ -131,12 +126,13 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
: new Decimal(0)
const newPoolInfo = {
poolFee,
marketFee,
opfFee,
liquidityProviderSwapFee: getFee(poolData.liquidityProviderSwapFee),
publishMarketSwapFee: getFee(poolData.publishMarketSwapFee),
opcFee: getFee(poolData.opcFee),
weightBaseToken: getWeight(poolData.baseTokenWeight),
weightDt: getWeight(poolData.datatokenWeight),
datatokenSymbol: poolData.datatoken.symbol,
datatokenAddress: poolData.datatoken.address,
baseTokenSymbol: poolData.baseToken.symbol,
baseTokenAddress: poolData.baseToken.address,
totalPoolTokens: poolData.totalShares,
@ -193,6 +189,7 @@ function PoolProvider({ children }: { children: ReactNode }): ReactElement {
if (
!poolData ||
!poolInfo?.totalPoolTokens ||
!poolInfoUser?.poolShares ||
!asset?.chainId ||
!accountId ||
!poolInfoUser

View File

@ -1,3 +1,3 @@
declare module 'ethereum-blockies' {
declare module 'myetherwallet-blockies' {
export function toDataUrl(address: string): string
}

1
src/@utils/constants.ts Normal file
View File

@ -0,0 +1 @@
export const MAX_DECIMALS = 5

View File

@ -112,7 +112,6 @@ export async function setNftMetadata(
'0x' + metadataHash,
[]
)
const setMetadataTx = await nft.setMetadata(
asset.nftAddress,
accountId,

View File

@ -1,4 +1,4 @@
import { toDataUrl } from 'ethereum-blockies'
import { toDataUrl } from 'myetherwallet-blockies'
import React, { ReactElement } from 'react'
import styles from './Blockies.module.css'

View File

@ -13,7 +13,7 @@ import DebugOutput from '@shared/DebugOutput'
import { useWeb3 } from '@context/Web3'
import { useAsset } from '@context/Asset'
import content from '../../../../../../content/price.json'
import { LoggerInstance, Pool } from '@oceanprotocol/lib'
import { calcMaxExactIn, LoggerInstance, Pool } from '@oceanprotocol/lib'
export interface FormAddLiquidity {
amount: string
@ -73,11 +73,12 @@ export default function Add({
try {
const poolInstance = new Pool(web3)
const amountMaxPool = await poolInstance.getReserve(
const poolReserve = await poolInstance.getReserve(
poolAddress,
tokenInAddress
)
const amountMaxPool = calcMaxExactIn(poolReserve)
const amountMax =
Number(balance.ocean) > Number(amountMaxPool)
? amountMaxPool
@ -100,7 +101,7 @@ export default function Add({
// Submit
async function handleAddLiquidity(amount: string, resetForm: () => void) {
const poolInstance = new Pool(web3)
const minPoolAmountOut = '0' // ? TODO: how to get?
const minPoolAmountOut = '0' // ? how to get? : you would get this value by using `calcPoolOutGivenSingleIn` and substracting slippage from that , like we don in trade. it is ok to be 0 here. We can change after we implement global slippage
try {
const result = await poolInstance.joinswapExternAmountIn(

View File

@ -13,9 +13,9 @@ import {
defaults
} from 'chart.js'
export declare type GraphType = 'liquidity' | 'price' | 'volume'
export declare type GraphType = 'tvl' | 'price' | 'volume'
export const graphTypes = ['Liquidity', 'Price', 'Volume']
export const graphTypes = ['TVL', 'Price', 'Volume']
// Chart.js global defaults
ChartJS.register(

View File

@ -13,6 +13,7 @@ import Nav from './Nav'
import { getOptions } from './_utils'
import { PoolData_poolSnapshots as PoolDataPoolSnapshots } from 'src/@types/subgraph/PoolData'
import { usePrices } from '@context/Prices'
import { MAX_DECIMALS } from '@utils/constants'
export default function Graph({
poolSnapshots
@ -24,7 +25,7 @@ export default function Graph({
const darkMode = useDarkMode(false, darkModeConfig)
const [options, setOptions] = useState<ChartOptions<any>>()
const [graphType, setGraphType] = useState<GraphType>('liquidity')
const [graphType, setGraphType] = useState<GraphType>('tvl')
const [graphData, setGraphData] = useState<ChartData<any>>()
//
@ -35,11 +36,7 @@ export default function Graph({
LoggerInstance.log('[pool graph] Fired getOptions().')
const symbol =
graphType === 'liquidity'
? currency
: // TODO: remove any once baseToken works
// see https://github.com/oceanprotocol/ocean-subgraph/issues/312
(poolSnapshots[0] as any)?.baseToken?.symbol
graphType === 'tvl' ? currency : poolSnapshots[0]?.baseToken?.symbol
const options = getOptions(locale, darkMode.value, symbol)
setOptions(options)
}, [locale, darkMode.value, graphType, currency, poolSnapshots])
@ -52,32 +49,25 @@ export default function Graph({
const timestamps = poolSnapshots.map((item) => {
const date = new Date(item.date * 1000)
return `${date.toLocaleDateString(locale)} ${date.toLocaleTimeString(
locale,
{ hour: '2-digit', minute: '2-digit' }
)}`
return `${date.toLocaleDateString(locale)}`
})
let baseTokenLiquidityCumulative = '0'
const liquidityHistory = poolSnapshots.map((item) => {
const tvlHistory = poolSnapshots.map((item) => {
const conversionSpotPrice = prices[currency.toLowerCase()]
baseTokenLiquidityCumulative = new Decimal(baseTokenLiquidityCumulative)
.add(item.baseTokenLiquidity)
.mul(2) // double baseTokenLiquidity as we have 50/50 weight
const tvl = new Decimal(item.baseTokenLiquidity)
.mul(2)
.mul(conversionSpotPrice) // convert to user currency
.toString()
return baseTokenLiquidityCumulative
return tvl
})
const priceHistory = poolSnapshots.map((item) => item.spotPrice)
let volumeCumulative = '0'
const volumeHistory = poolSnapshots.map((item) => {
volumeCumulative = new Decimal(volumeCumulative)
.add(item.swapVolume)
const volume = new Decimal(item.swapVolume)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
return volumeCumulative
return volume
})
let data
@ -89,7 +79,7 @@ export default function Graph({
data = volumeHistory
break
default:
data = liquidityHistory
data = tvlHistory
break
}

View File

@ -9,11 +9,10 @@ import styles from './index.module.css'
import Header from '../Header'
import { toast } from 'react-toastify'
import Actions from '../Actions'
import { LoggerInstance, Pool } from '@oceanprotocol/lib'
import { LoggerInstance, Pool, calcMaxExactOut } from '@oceanprotocol/lib'
import Token from '../Token'
import FormHelp from '@shared/FormInput/Help'
import Button from '@shared/atoms/Button'
import { getMaxPercentRemove } from '../utils'
import debounce from 'lodash.debounce'
import UserLiquidity from '../../UserLiquidity'
import InputElement from '@shared/FormInput/InputElement'
@ -77,16 +76,27 @@ export default function Remove({
}
}
// TODO: Get and set max percentage
useEffect(() => {
if (!accountId || !poolTokens) return
async function getMax() {
// const amountMaxPercent = await getMaxPercentRemove(poolAddress, poolTokens)
// setAmountMaxPercent(amountMaxPercent)
const maxTokensToRemoveFromPool = calcMaxExactOut(totalPoolTokens)
const poolTokensDecimal = new Decimal(poolTokens)
const maxTokensToRemoveForUser = maxTokensToRemoveFromPool.greaterThan(
poolTokensDecimal
)
? poolTokensDecimal
: maxTokensToRemoveFromPool
const maxPercent = new Decimal(100)
.mul(maxTokensToRemoveForUser)
.div(poolTokensDecimal)
setAmountMaxPercent(
maxPercent.toDecimalPlaces(0, Decimal.ROUND_DOWN).toString()
)
}
getMax()
}, [accountId, poolAddress, poolTokens])
}, [accountId, poolAddress, poolTokens, totalPoolTokens])
const getValues = useRef(
debounce(async (newAmountPoolShares) => {
@ -188,7 +198,7 @@ export default function Remove({
</div> */}
</div>
<div className={styles.slippage}>
<strong>Expected price impact</strong>
<strong>Slippage Tolerance</strong>
<InputElement
name="slippage"
type="select"

View File

@ -46,7 +46,7 @@ export default function Pool(): ReactElement {
baseToken: new Decimal(poolData?.baseTokenLiquidity).toString(),
datatoken: new Decimal(poolData?.datatokenLiquidity).toString()
}}
swapFee={poolInfo?.poolFee}
swapFee={poolInfo?.liquidityProviderSwapFee}
datatokenSymbol={poolInfo?.datatokenSymbol}
tokenInAddress={poolInfo?.baseTokenAddress}
tokenInSymbol={poolInfo?.baseTokenSymbol}
@ -94,11 +94,11 @@ export default function Pool(): ReactElement {
<TokenList
title={
<>
Your Liquidity
Your Value Locked
<Tooltip
content={content.pool.tooltips.liquidity.replace(
'SWAPFEE',
poolInfo?.poolFee
poolInfo?.liquidityProviderSwapFee
)}
/>
{poolInfoUser?.poolShare && (

View File

@ -1,5 +1,11 @@
import React, { ReactElement, useState } from 'react'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import {
AmountsInMaxFee,
AmountsOutMaxFee,
LoggerInstance,
Pool,
TokenInOutMarket
} from '@oceanprotocol/lib'
import * as Yup from 'yup'
import { Formik } from 'formik'
import Actions from '../Pool/Actions'
@ -15,36 +21,33 @@ import { FormTradeData } from './_types'
import { initialValues } from './_constants'
import content from '../../../../../content/price.json'
import { AssetExtended } from 'src/@types/AssetExtended'
import { usePool } from '@context/Pool'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
export default function FormTrade({
asset,
balance,
maxDt,
maxOcean
balance
}: {
asset: AssetExtended
balance: PoolBalance
maxDt: string
maxOcean: string
}): ReactElement {
const { accountId } = useWeb3()
const { web3, accountId } = useWeb3()
const { isAssetNetwork } = useAsset()
const { debug } = useUserPreferences()
const { appConfig } = useSiteMetadata()
const { poolInfo } = usePool()
const [txId, setTxId] = useState<string>()
const [coinFrom, setCoinFrom] = useState<string>('OCEAN')
const [maximumOcean, setMaximumOcean] = useState(maxOcean)
const [maximumDt, setMaximumDt] = useState(maxDt)
const [maximumBaseToken, setMaximumBaseToken] = useState('0')
const [maximumDt, setMaximumDt] = useState('0')
const [isWarningAccepted, setIsWarningAccepted] = useState(false)
const tokenAddress = ''
const tokenSymbol = ''
const validationSchema: Yup.SchemaOf<FormTradeData> = Yup.object()
.shape({
ocean: Yup.number()
baseToken: Yup.number()
.max(
Number(maximumOcean),
Number(maximumBaseToken),
(param) => `Must be less or equal to ${param.max}`
)
.min(0.001, (param) => `Must be more or equal to ${param.min}`)
@ -64,32 +67,81 @@ export default function FormTrade({
.defined()
async function handleTrade(values: FormTradeData) {
if (!web3 || !asset || !poolInfo || !values) return
try {
const impact = new Decimal(
new Decimal(100).sub(new Decimal(values.slippage))
).div(100)
const precision = 15
// const tx =
// values.type === 'buy'
// ? await ocean.pool.buyDTWithExactOcean(
// accountId,
// price.address,
// new Decimal(values.datatoken)
// .mul(impact)
// .toFixed(precision)
// .toString(),
// new Decimal(values.ocean).toFixed(precision).toString()
// )
// : await ocean.pool.sellDT(
// accountId,
// price.address,
// new Decimal(values.datatoken).toFixed(precision).toString(),
// new Decimal(values.ocean)
// .mul(impact)
// .toFixed(precision)
// .toString()
// )
// setTxId(tx?.transactionHash)
const poolInstance = new Pool(web3)
let tx
if (values.output === 'exactIn') {
const tokenInOutMarket: TokenInOutMarket = {
tokenIn:
values.type === 'sell'
? poolInfo.datatokenAddress
: poolInfo.baseTokenAddress,
tokenOut:
values.type === 'sell'
? poolInfo.baseTokenAddress
: poolInfo.datatokenAddress,
marketFeeAddress: appConfig.marketFeeAddress
}
const amountsInOutMaxFee: AmountsInMaxFee = {
tokenAmountIn:
values.type === 'sell' ? values.datatoken : values.baseToken,
minAmountOut: new Decimal(
values.type === 'sell' ? values.baseToken : values.datatoken
)
.mul(
new Decimal(1)
.minus(new Decimal(values.slippage).div(new Decimal(100)))
.toString()
)
.toString(),
swapMarketFee: appConfig.consumeMarketPoolSwapFee
}
tx = await poolInstance.swapExactAmountIn(
accountId,
asset.accessDetails.addressOrId,
tokenInOutMarket,
amountsInOutMaxFee
)
}
if (values.output === 'exactOut') {
const tokenOutMarket: TokenInOutMarket = {
tokenIn:
values.type === 'sell'
? poolInfo.datatokenAddress
: poolInfo.baseTokenAddress,
tokenOut:
values.type === 'sell'
? poolInfo.baseTokenAddress
: poolInfo.datatokenAddress,
marketFeeAddress: appConfig.marketFeeAddress
}
const amountsOutMaxFee: AmountsOutMaxFee = {
maxAmountIn: new Decimal(
values.type === 'sell' ? values.datatoken : values.baseToken
)
.mul(
new Decimal(1)
.plus(new Decimal(values.slippage).div(new Decimal(100)))
.toString()
)
.toString(),
tokenAmountOut:
values.type === 'sell' ? values.baseToken : values.datatoken,
swapMarketFee: appConfig.consumeMarketPoolSwapFee
}
tx = await poolInstance.swapExactAmountOut(
accountId,
asset.accessDetails.addressOrId,
tokenOutMarket,
amountsOutMaxFee
)
}
setTxId(tx?.transactionHash)
} catch (error) {
LoggerInstance.error(error.message)
toast.error(error.message)
@ -112,10 +164,8 @@ export default function FormTrade({
<Swap
asset={asset}
balance={balance}
maxDt={maxDt}
maxOcean={maxOcean}
setCoin={setCoinFrom}
setMaximumOcean={setMaximumOcean}
setMaximumBaseToken={setMaximumBaseToken}
setMaximumDt={setMaximumDt}
/>
) : (
@ -154,8 +204,16 @@ export default function FormTrade({
}
action={submitForm}
txId={txId}
tokenAddress={tokenAddress}
tokenSymbol={tokenSymbol}
tokenAddress={
values.type === 'buy'
? poolInfo.baseTokenAddress
: poolInfo.datatokenAddress
}
tokenSymbol={
values.type === 'buy'
? poolInfo.baseTokenSymbol
: poolInfo.datatokenSymbol
}
setSubmitting={setSubmitting}
/>

View File

@ -4,73 +4,54 @@ import { useAsset } from '@context/Asset'
import Token from '../Pool/Token'
import styles from './Output.module.css'
import { isValidNumber } from '@utils/numbers'
import Decimal from 'decimal.js'
import { FormTradeData } from './_types'
import { usePool } from '@context/Pool'
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
export default function Output({
dtSymbol,
oceanSymbol,
poolAddress
poolAddress,
lpSwapFee
}: {
dtSymbol: string
oceanSymbol: string
poolAddress: string
lpSwapFee: string
}): ReactElement {
const { isAssetNetwork } = useAsset()
const [maxOutput, setMaxOutput] = useState<string>()
const [swapFee, setSwapFee] = useState<string>()
const [swapFeeValue, setSwapFeeValue] = useState<string>()
const { poolInfo } = usePool()
const [outputWithSlippage, setOutputWithSlippage] = useState<string>('0')
// Connect with form
const { values }: FormikContextType<FormTradeData> = useFormikContext()
// Get swap fee
useEffect(() => {
if (!poolAddress || !isAssetNetwork) return
async function getSwapFee() {
// const swapFee = await ocean.pool.getSwapFee(poolAddress)
// // swapFee is tricky: to get 0.1% you need to convert from 0.001
// setSwapFee(
// isValidNumber(swapFee) ? new Decimal(swapFee).mul(100).toString() : '0'
// )
const value =
values.type === 'buy'
? isValidNumber(swapFee) && isValidNumber(values.baseToken)
? new Decimal(swapFee).mul(new Decimal(values.baseToken))
: 0
: isValidNumber(swapFee) && isValidNumber(values.datatoken)
? new Decimal(swapFee).mul(new Decimal(values.datatoken))
: 0
setSwapFeeValue(value.toString())
}
getSwapFee()
}, [poolAddress, values, isAssetNetwork, swapFee])
// Get output values
useEffect(() => {
if (!poolAddress || !isAssetNetwork) return
async function getOutput() {
// Minimum received
// TODO: check if this here is redundant cause we call some of that already in Swap.tsx
const maxImpact = 1 - Number(values.slippage) / 100
const maxPrice =
values.type === 'buy'
? isValidNumber(values.datatoken) && isValidNumber(maxImpact)
? new Decimal(values.datatoken)
.mul(new Decimal(maxImpact))
.toString()
: '0'
: isValidNumber(values.baseToken) && isValidNumber(maxImpact)
? new Decimal(values.baseToken).mul(new Decimal(maxImpact)).toString()
: '0'
if (!values.baseToken || !values.datatoken || !values.output) return
setMaxOutput(maxPrice)
const output =
values.output === 'exactIn'
? new Decimal(
values.type === 'sell' ? values.baseToken : values.datatoken
)
.mul(
new Decimal(1)
.minus(new Decimal(values.slippage).div(new Decimal(100)))
.toString()
)
.toString()
: new Decimal(
values.type === 'sell' ? values.datatoken : values.baseToken
)
.mul(
new Decimal(1)
.plus(new Decimal(values.slippage).div(new Decimal(100)))
.toString()
)
.toString()
setOutputWithSlippage(output)
}
getOutput()
}, [poolAddress, values, isAssetNetwork])
@ -78,19 +59,35 @@ export default function Output({
return (
<div className={styles.output}>
<div>
<p>Minimum Received</p>
<p>
{values.output === 'exactIn' ? 'Minimum Received' : 'Maximum Sent'}
</p>
<Token
symbol={values.type === 'buy' ? dtSymbol : oceanSymbol}
balance={maxOutput}
symbol={
values.type === 'buy'
? values.output === 'exactIn'
? poolInfo.datatokenSymbol
: poolInfo.baseTokenSymbol
: values.output === 'exactIn'
? poolInfo.baseTokenSymbol
: poolInfo.datatokenSymbol
}
balance={outputWithSlippage}
/>
</div>
<div>
<p>Swap fee</p>
<Token
symbol={`${values.type === 'buy' ? oceanSymbol : dtSymbol} ${
swapFee ? `(${swapFee}%)` : ''
symbol={`${
values.type === 'buy'
? poolInfo.baseTokenSymbol
: poolInfo.datatokenSymbol
} ${
poolInfo.liquidityProviderSwapFee
? `(${poolInfo.liquidityProviderSwapFee}%)`
: ''
}`}
balance={swapFeeValue}
balance={lpSwapFee}
/>
</div>
</div>

View File

@ -7,44 +7,54 @@ import { FormikContextType, useFormikContext } from 'formik'
import Output from './Output'
import Slippage from './Slippage'
import PriceImpact from './PriceImpact'
import Decimal from 'decimal.js'
import { useAsset } from '@context/Asset'
import { useWeb3 } from '@context/Web3'
import { FormTradeData, TradeItem } from './_types'
import { Asset } from '@oceanprotocol/lib'
import {
calcMaxExactIn,
calcMaxExactOut,
LoggerInstance,
Pool,
PoolPriceAndFees
} from '@oceanprotocol/lib'
import { AssetExtended } from 'src/@types/AssetExtended'
import { usePool } from '@context/Pool'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import { MAX_DECIMALS } from '@utils/constants'
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
// Decimal.set({ toExpNeg: -15, precision: 5, rounding: Decimal.ROUND_DOWN })
export default function Swap({
asset,
maxDt,
maxOcean,
balance,
setMaximumDt,
setMaximumOcean,
setMaximumBaseToken,
setCoin
}: {
asset: AssetExtended
maxDt: string
maxOcean: string
balance: PoolBalance
setMaximumDt: (value: string) => void
setMaximumOcean: (value: string) => void
setMaximumBaseToken: (value: string) => void
setCoin: (value: string) => void
}): ReactElement {
const { isAssetNetwork } = useAsset()
const [oceanItem, setOceanItem] = useState<TradeItem>({
const { web3 } = useWeb3()
const { poolInfo, poolData } = usePool()
const { appConfig } = useSiteMetadata()
const [baseTokenItem, setBaseTokenItem] = useState<TradeItem>({
amount: '0',
token: asset.accessDetails.baseToken?.symbol,
maxAmount: '0'
token: poolInfo?.baseTokenSymbol,
maxAmount: '0',
address: poolInfo?.baseTokenAddress
})
const [dtItem, setDtItem] = useState<TradeItem>({
amount: '0',
token: asset.accessDetails.datatoken.symbol,
maxAmount: '0'
token: poolInfo?.datatokenSymbol,
maxAmount: '0',
address: poolInfo?.datatokenAddress
})
const {
setFieldValue,
values,
@ -56,148 +66,260 @@ export default function Swap({
const [spotPrice, setSpotPrice] = useState<string>()
const [totalValue, setTotalValue] = useState<string>()
const [tokenAmount, setTokenAmount] = useState<string>()
const [lpSwapFee, setLpSwapFee] = useState<string>()
useEffect(() => {
if (!asset || !balance || !values?.type) return
if (!asset || !balance || !values?.type || !web3) return
const poolInstance = new Pool(web3)
async function calculateMaximum() {
const maxDtFromPool =
values.type === 'buy'
? calcMaxExactIn(poolData.datatokenLiquidity)
: calcMaxExactOut(poolData.datatokenLiquidity)
const maxBaseTokenFromPool =
values.type === 'buy'
? calcMaxExactOut(poolData.baseTokenLiquidity)
: calcMaxExactIn(poolData.baseTokenLiquidity)
const amountDataToken =
values.type === 'buy'
? new Decimal(maxDt)
? maxDtFromPool
: new Decimal(balance.baseToken).greaterThan(
calcMaxExactIn(poolData.datatokenLiquidity)
)
? calcMaxExactIn(poolData.datatokenLiquidity)
: new Decimal(balance.datatoken)
const amountOcean =
const amountBaseToken =
values.type === 'buy'
? new Decimal(balance.baseToken)
: new Decimal(maxOcean)
? new Decimal(balance.baseToken).greaterThan(
calcMaxExactIn(poolData.baseTokenLiquidity)
)
? calcMaxExactIn(poolData.baseTokenLiquidity)
: new Decimal(balance.baseToken)
: maxBaseTokenFromPool
// const maxBuyOcean = await ocean.pool.getOceanReceived(
// price.address,
// `${amountDataToken.toString()}`
// )
// const maxBuyDt = await ocean.pool.getDTReceived(
// price.address,
// `${amountOcean.toString()}`
// )
try {
const maxBuyBaseToken: PoolPriceAndFees =
await poolInstance.getAmountOutExactIn(
asset.accessDetails.addressOrId,
poolInfo.datatokenAddress,
poolInfo.baseTokenAddress,
amountDataToken.toString(),
appConfig.consumeMarketPoolSwapFee
)
// const maximumDt =
// values.type === 'buy'
// ? amountDataToken.greaterThan(new Decimal(maxBuyDt))
// ? maxBuyDt
// : amountDataToken
// : amountDataToken.greaterThan(new Decimal(balance.datatoken))
// ? balance.datatoken
// : amountDataToken
const maxBuyDt: PoolPriceAndFees =
await poolInstance.getAmountOutExactIn(
asset.accessDetails?.addressOrId,
poolInfo.baseTokenAddress,
poolInfo.datatokenAddress,
amountBaseToken.toString(),
appConfig.consumeMarketPoolSwapFee
)
const maximumDt =
values.type === 'buy'
? amountDataToken.greaterThan(new Decimal(maxBuyDt.tokenAmount))
? maxBuyDt.tokenAmount
: amountDataToken.toDecimalPlaces(MAX_DECIMALS).toString()
: amountDataToken.greaterThan(new Decimal(balance.datatoken))
? balance.datatoken
: amountDataToken.toDecimalPlaces(MAX_DECIMALS).toString()
// const maximumOcean =
// values.type === 'sell'
// ? amountOcean.greaterThan(new Decimal(maxBuyOcean))
// ? maxBuyOcean
// : amountOcean
// : amountOcean.greaterThan(new Decimal(balance.ocean))
// ? balance.ocean
// : amountOcean
const maximumBaseToken =
values.type === 'sell'
? amountBaseToken.greaterThan(
new Decimal(maxBuyBaseToken.tokenAmount)
)
? maxBuyBaseToken.tokenAmount
: amountBaseToken.toDecimalPlaces(MAX_DECIMALS).toString()
: amountBaseToken.greaterThan(new Decimal(balance.baseToken))
? balance.baseToken
: amountBaseToken.toDecimalPlaces(MAX_DECIMALS).toString()
// setMaximumDt(maximumDt.toString())
// setMaximumOcean(maximumOcean.toString())
setMaximumDt(maximumDt)
setMaximumBaseToken(maximumBaseToken)
// setOceanItem((prevState) => ({
// ...prevState,
// amount: amountOcean.toString(),
// maxAmount: maximumOcean.toString()
// }))
setBaseTokenItem((prevState) => ({
...prevState,
amount: amountBaseToken.toDecimalPlaces(MAX_DECIMALS).toString(),
maxAmount: maximumBaseToken
}))
// setDtItem((prevState) => ({
// ...prevState,
// amount: amountDataToken.toString(),
// maxAmount: maximumDt.toString()
// }))
setDtItem((prevState) => ({
...prevState,
amount: amountDataToken.toDecimalPlaces(MAX_DECIMALS).toString(),
maxAmount: maximumDt
}))
} catch (error) {
LoggerInstance.error(error.message)
}
}
calculateMaximum()
}, [
asset,
maxOcean,
maxDt,
poolData,
balance,
values?.type,
values.type,
setMaximumDt,
setMaximumOcean
setMaximumBaseToken,
asset,
web3,
dtItem.token,
baseTokenItem.token,
poolInfo.liquidityProviderSwapFee,
poolInfo.datatokenAddress,
poolInfo.baseTokenAddress,
appConfig.consumeMarketPoolSwapFee
])
const switchTokens = () => {
setFieldValue('type', values.type === 'buy' ? 'sell' : 'buy')
setCoin(values.type === 'sell' ? 'OCEAN' : asset.datatokens[0].symbol)
setCoin(
values.type === 'sell'
? poolInfo.baseTokenSymbol
: poolInfo.datatokenSymbol
)
// don't reset form because we don't want to reset type
setFieldValue('datatoken', 0)
setFieldValue('ocean', 0)
setFieldValue('baseToken', 0)
setErrors({})
}
const handleValueChange = async (name: string, value: number) => {
const tokenIn = ''
const tokenOut = ''
let newValue
try {
let tokenIn = ''
let tokenOut = ''
const poolInstance = new Pool(web3)
let newValue: PoolPriceAndFees
// if (name === 'ocean') {
// if (values.type === 'sell') {
// newValue = await ocean.pool.getDTNeeded(price.address, value.toString())
if (name === 'baseToken') {
if (values.type === 'sell') {
newValue = await poolInstance.getAmountInExactOut(
asset.accessDetails.addressOrId,
dtItem.address,
baseTokenItem.address,
value.toString(),
appConfig.consumeMarketPoolSwapFee
)
// setTotalValue(newValue)
// setTokenAmount(value.toString())
setFieldValue('output', 'exactOut')
// tokenIn = ddo.services[0].datatokenAddress
// tokenOut = ocean.pool.oceanAddress
// } else {
// newValue = await ocean.pool.getDTReceived(
// price.address,
// value.toString()
// )
setTotalValue(
new Decimal(newValue.tokenAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
setLpSwapFee(
new Decimal(newValue.liquidityProviderSwapFeeAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
setTokenAmount(value.toString())
// setTotalValue(value.toString())
// setTokenAmount(newValue)
// tokenIn = ocean.pool.oceanAddress
// tokenOut = ddo.services[0].datatokenAddress
// }
// } else {
// if (values.type === 'sell') {
// newValue = await ocean.pool.getOceanReceived(
// price.address,
// value.toString()
// )
tokenIn = poolInfo.datatokenAddress
tokenOut = poolInfo.baseTokenAddress
} else {
newValue = await poolInstance.getAmountOutExactIn(
asset.accessDetails.addressOrId,
baseTokenItem.address,
dtItem.address,
value.toString(),
appConfig.consumeMarketPoolSwapFee
)
// setTotalValue(value.toString())
// setTokenAmount(newValue)
// tokenIn = ddo.services[0].datatokenAddress
// tokenOut = ocean.pool.oceanAddress
// } else {
// newValue = await ocean.pool.getOceanNeeded(
// price.address,
// value.toString()
// )
setFieldValue('output', 'exactIn')
setTotalValue(value.toString())
setTokenAmount(
new Decimal(newValue.tokenAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
setLpSwapFee(
new Decimal(newValue.liquidityProviderSwapFeeAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
tokenIn = poolInfo.baseTokenAddress
tokenOut = poolInfo.datatokenAddress
}
} else {
if (values.type === 'sell') {
newValue = await poolInstance.getAmountOutExactIn(
asset.accessDetails.addressOrId,
dtItem.address,
baseTokenItem.address,
value.toString(),
appConfig.consumeMarketPoolSwapFee
)
// setTotalValue(newValue)
// setTokenAmount(value.toString())
// tokenIn = ocean.pool.oceanAddress
// tokenOut = ddo.services[0].datatokenAddress
// }
// }
setFieldValue('output', 'exactIn')
setTotalValue(value.toString())
setTokenAmount(
new Decimal(newValue.tokenAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
setLpSwapFee(
new Decimal(newValue.liquidityProviderSwapFeeAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
tokenIn = poolInfo.datatokenAddress
tokenOut = poolInfo.baseTokenAddress
} else {
newValue = await poolInstance.getAmountInExactOut(
asset.accessDetails.addressOrId,
baseTokenItem.address,
dtItem.address,
value.toString(),
appConfig.consumeMarketPoolSwapFee
)
await setFieldValue(name === 'ocean' ? 'datatoken' : 'ocean', newValue)
setFieldValue('output', 'exactOut')
// const spotPrice = await ocean.pool.getSpotPrice(
// price.address,
// tokenIn,
// tokenOut
// )
setTotalValue(
new Decimal(newValue.tokenAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
setTokenAmount(value.toString())
setLpSwapFee(
new Decimal(newValue.liquidityProviderSwapFeeAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
tokenIn = poolInfo.baseTokenAddress
tokenOut = poolInfo.datatokenAddress
}
}
// setSpotPrice(spotPrice)
validateForm()
await setFieldValue(
name === 'baseToken' ? 'datatoken' : 'baseToken',
new Decimal(newValue.tokenAmount)
.toDecimalPlaces(MAX_DECIMALS)
.toString()
)
const spotPrice = await poolInstance.getSpotPrice(
asset.accessDetails.addressOrId,
tokenIn,
tokenOut,
appConfig.consumeMarketPoolSwapFee
)
setSpotPrice(spotPrice)
validateForm()
} catch (ex) {
LoggerInstance.error(ex)
}
}
return (
<div className={styles.swap}>
<TradeInput
name={values.type === 'sell' ? 'datatoken' : 'ocean'}
item={values.type === 'sell' ? dtItem : oceanItem}
name={values.type === 'sell' ? 'datatoken' : 'baseToken'}
item={values.type === 'sell' ? dtItem : baseTokenItem}
disabled={!isAssetNetwork}
handleValueChange={handleValueChange}
/>
@ -212,16 +334,15 @@ export default function Swap({
</Button>
<TradeInput
name={values.type === 'sell' ? 'ocean' : 'datatoken'}
item={values.type === 'sell' ? oceanItem : dtItem}
name={values.type === 'sell' ? 'baseToken' : 'datatoken'}
item={values.type === 'sell' ? baseTokenItem : dtItem}
disabled={!isAssetNetwork}
handleValueChange={handleValueChange}
/>
<Output
dtSymbol={dtItem.token}
oceanSymbol={oceanItem.token}
poolAddress={asset.accessDetails?.addressOrId}
lpSwapFee={lpSwapFee}
/>
<PriceImpact

View File

@ -16,7 +16,6 @@
.tradeInput div[class*='prefix'] {
min-width: 6.5rem;
width: fit-content;
justify-content: center;
}

View File

@ -34,7 +34,7 @@ export default function TradeInput({
}: FormikContextType<FormTradeData> = useFormikContext()
const isTopField =
(name === 'ocean' && values.type === 'buy') ||
(name === 'baseToken' && values.type === 'buy') ||
(name === 'datatoken' && values.type === 'sell')
const titleAvailable = isTopField ? `Balance` : `Available from pool`
const titleMaximum = isTopField ? `Maximum to spend` : `Maximum to receive`
@ -54,6 +54,7 @@ export default function TradeInput({
<Input
type="number"
max={`${item?.maxAmount}`}
min="0"
prefix={item?.token}
placeholder="0"
field={field}
@ -68,7 +69,8 @@ export default function TradeInput({
/>
)}
</Field>
{!isTopField && (
{/* {!isTopField && (
<Button
className={styles.buttonMax}
disabled={disabled}
@ -81,7 +83,7 @@ export default function TradeInput({
>
Use Max
</Button>
)}
)} */}
</section>
)
}

View File

@ -4,6 +4,7 @@ export const initialValues: FormTradeData = {
baseToken: undefined,
datatoken: undefined,
type: 'buy',
output: 'exactIn',
slippage: '5'
}

View File

@ -1,6 +1,8 @@
export interface FormTradeData extends PoolBalance {
// in reference to datatoken, buy = swap from ocean to dt ( buy dt) , sell = swap from dt to ocean (sell dt)
type: 'buy' | 'sell'
// based on what the user inputs, if he fill the top input it is 'exactIn'
output: 'exactIn' | 'exactOut'
slippage: string
}
@ -8,4 +10,5 @@ export interface TradeItem {
amount: string
token: string
maxAmount: string
address: string
}

View File

@ -2,8 +2,10 @@ import React, { ReactElement, useEffect, useState } from 'react'
import FormTrade from './FormTrade'
import { useAsset } from '@context/Asset'
import { useWeb3 } from '@context/Web3'
import { isValidNumber } from '@utils/numbers'
import Decimal from 'decimal.js'
import { Datatoken } from '@oceanprotocol/lib'
import { Datatoken, LoggerInstance, Pool } from '@oceanprotocol/lib'
import { usePool } from '@context/Pool'
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
@ -12,8 +14,7 @@ export default function Trade(): ReactElement {
const { isAssetNetwork } = useAsset()
const [tokenBalance, setTokenBalance] = useState<PoolBalance>()
const { asset } = useAsset()
const [maxDt, setMaxDt] = useState('0')
const [maxOcean, setMaxOcean] = useState('0')
const { poolInfo } = usePool()
// Get datatoken balance, and combine with OCEAN balance from hooks into one object
useEffect(() => {
@ -23,14 +24,14 @@ export default function Trade(): ReactElement {
!isAssetNetwork ||
!balance?.ocean ||
!accountId ||
!asset?.services[0].datatokenAddress
!poolInfo?.datatokenAddress
)
return
async function getTokenBalance() {
const datatokenInstance = new Datatoken(web3)
const dtBalance = await datatokenInstance.balance(
asset.services[0].datatokenAddress,
poolInfo.datatokenAddress,
accountId
)
setTokenBalance({
@ -39,44 +40,13 @@ export default function Trade(): ReactElement {
})
}
getTokenBalance()
}, [web3, balance.ocean, accountId, asset, isAssetNetwork])
}, [
web3,
balance.ocean,
accountId,
poolInfo?.datatokenAddress,
isAssetNetwork
])
// Get maximum amount for either OCEAN or datatoken
useEffect(() => {
if (
!isAssetNetwork ||
!asset.accessDetails ||
asset.accessDetails.price === 0
)
return
async function getMaximum() {
// const maxTokensInPool = await ocean.pool.getDTMaxBuyQuantity(
// price.address
// )
// setMaxDt(
// isValidNumber(maxTokensInPool)
// ? new Decimal(maxTokensInPool).toString()
// : '0'
// )
// const maxOceanInPool = await ocean.pool.getOceanMaxBuyQuantity(
// price.address
// )
// setMaxOcean(
// isValidNumber(maxOceanInPool)
// ? new Decimal(maxOceanInPool).toString()
// : '0'
// )
}
getMaximum()
}, [isAssetNetwork, balance.ocean, asset])
return (
<FormTrade
asset={asset}
balance={tokenBalance}
maxDt={maxDt}
maxOcean={maxOcean}
/>
)
return <FormTrade asset={asset} balance={tokenBalance} />
}

View File

@ -211,7 +211,8 @@ export async function createTokensAndPricing(
mpFeeAddress: appConfig.marketFeeAddress,
feeToken: config.oceanTokenAddress,
feeAmount: appConfig.publisherMarketOrderFee,
cap: '1000',
// max number
cap: '115792089237316195423570985008687907853269984665640564039457',
name: values.services[0].dataTokenOptions.name,
symbol: values.services[0].dataTokenOptions.symbol
}