mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Update contracts and math (#1436)
* update contracts and math Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * change fee name Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * bump to ocean.js v1.0.0-next.44 * rename consumeFee to orderFee * prevent variable naming clash Co-authored-by: Matthias Kretschmann <m@kretschmann.io> Co-authored-by: Bogdan Fazakas <bogdan.fazakas@gmail.com>
This commit is contained in:
parent
593039f894
commit
4b6baa9cd5
30
package-lock.json
generated
30
package-lock.json
generated
@ -13,7 +13,7 @@
|
|||||||
"@coingecko/cryptoformat": "^0.4.4",
|
"@coingecko/cryptoformat": "^0.4.4",
|
||||||
"@loadable/component": "^5.15.2",
|
"@loadable/component": "^5.15.2",
|
||||||
"@oceanprotocol/art": "^3.2.0",
|
"@oceanprotocol/art": "^3.2.0",
|
||||||
"@oceanprotocol/lib": "^1.0.0-next.42",
|
"@oceanprotocol/lib": "^1.0.0-next.44",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@portis/web3": "^4.0.7",
|
"@portis/web3": "^4.0.7",
|
||||||
"@tippyjs/react": "^4.2.6",
|
"@tippyjs/react": "^4.2.6",
|
||||||
@ -4554,16 +4554,16 @@
|
|||||||
"integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA=="
|
"integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA=="
|
||||||
},
|
},
|
||||||
"node_modules/@oceanprotocol/contracts": {
|
"node_modules/@oceanprotocol/contracts": {
|
||||||
"version": "1.0.0-alpha.32",
|
"version": "1.0.0-alpha.34",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.32.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.34.tgz",
|
||||||
"integrity": "sha512-gCHw4ZVnNjSozzCVT/cQiDqLNP0Xvy4fe+g5PKy8rwMR/h2rRW65Txi6wkb4HfZiUPKCdHbzpUFOwYfJFbW0Jw=="
|
"integrity": "sha512-ZhNCakYbUpXrffpS98Hj0r5K70IzzTXNoYKBX4Ks3Qqc2T7mhXIxtakzygkM0lEk038ImWuzS2PAZKTATz+X2w=="
|
||||||
},
|
},
|
||||||
"node_modules/@oceanprotocol/lib": {
|
"node_modules/@oceanprotocol/lib": {
|
||||||
"version": "1.0.0-next.42",
|
"version": "1.0.0-next.44",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0-next.42.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0-next.44.tgz",
|
||||||
"integrity": "sha512-5me2upjrDBls4RfnMOwEMF4pTo225fFIl7TKuz1KH8+i44VnPtz0WXnqh8g6fKPcpthmIaYFc0krsF/sh9Y7Gg==",
|
"integrity": "sha512-TXrHvY7+t7WSJXAVkSip0hp5byE8G4citJGirB5qJt34VGA+ujd+CoLU1bB/5gFSYH3eM56K4pcUPfCHZjeN3w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "^1.0.0-alpha.32",
|
"@oceanprotocol/contracts": "^1.0.0-alpha.34",
|
||||||
"bignumber.js": "^9.0.2",
|
"bignumber.js": "^9.0.2",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
@ -41836,16 +41836,16 @@
|
|||||||
"integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA=="
|
"integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/contracts": {
|
"@oceanprotocol/contracts": {
|
||||||
"version": "1.0.0-alpha.32",
|
"version": "1.0.0-alpha.34",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.32.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.34.tgz",
|
||||||
"integrity": "sha512-gCHw4ZVnNjSozzCVT/cQiDqLNP0Xvy4fe+g5PKy8rwMR/h2rRW65Txi6wkb4HfZiUPKCdHbzpUFOwYfJFbW0Jw=="
|
"integrity": "sha512-ZhNCakYbUpXrffpS98Hj0r5K70IzzTXNoYKBX4Ks3Qqc2T7mhXIxtakzygkM0lEk038ImWuzS2PAZKTATz+X2w=="
|
||||||
},
|
},
|
||||||
"@oceanprotocol/lib": {
|
"@oceanprotocol/lib": {
|
||||||
"version": "1.0.0-next.42",
|
"version": "1.0.0-next.44",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0-next.42.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0-next.44.tgz",
|
||||||
"integrity": "sha512-5me2upjrDBls4RfnMOwEMF4pTo225fFIl7TKuz1KH8+i44VnPtz0WXnqh8g6fKPcpthmIaYFc0krsF/sh9Y7Gg==",
|
"integrity": "sha512-TXrHvY7+t7WSJXAVkSip0hp5byE8G4citJGirB5qJt34VGA+ujd+CoLU1bB/5gFSYH3eM56K4pcUPfCHZjeN3w==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@oceanprotocol/contracts": "^1.0.0-alpha.32",
|
"@oceanprotocol/contracts": "^1.0.0-alpha.34",
|
||||||
"bignumber.js": "^9.0.2",
|
"bignumber.js": "^9.0.2",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"@coingecko/cryptoformat": "^0.4.4",
|
"@coingecko/cryptoformat": "^0.4.4",
|
||||||
"@loadable/component": "^5.15.2",
|
"@loadable/component": "^5.15.2",
|
||||||
"@oceanprotocol/art": "^3.2.0",
|
"@oceanprotocol/art": "^3.2.0",
|
||||||
"@oceanprotocol/lib": "^1.0.0-next.42",
|
"@oceanprotocol/lib": "^1.0.0-next.44",
|
||||||
"@oceanprotocol/typographies": "^0.1.0",
|
"@oceanprotocol/typographies": "^0.1.0",
|
||||||
"@portis/web3": "^4.0.7",
|
"@portis/web3": "^4.0.7",
|
||||||
"@tippyjs/react": "^4.2.6",
|
"@tippyjs/react": "^4.2.6",
|
||||||
|
@ -16,7 +16,7 @@ import { AccessDetails, OrderPriceAndFees } from 'src/@types/Price'
|
|||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import { consumeMarketOrderFee } from '../../app.config'
|
import { consumeMarketOrderFee } from '../../app.config'
|
||||||
|
|
||||||
const TokensPriceQuery = gql`
|
const tokensPriceQuery = gql`
|
||||||
query TokensPriceQuery($datatokenIds: [ID!], $account: String) {
|
query TokensPriceQuery($datatokenIds: [ID!], $account: String) {
|
||||||
tokens(where: { id_in: $datatokenIds }) {
|
tokens(where: { id_in: $datatokenIds }) {
|
||||||
id
|
id
|
||||||
@ -81,7 +81,7 @@ const TokensPriceQuery = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
const TokenPriceQuery = gql`
|
const tokenPriceQuery = gql`
|
||||||
query TokenPriceQuery($datatokenId: ID!, $account: String) {
|
query TokenPriceQuery($datatokenId: ID!, $account: String) {
|
||||||
token(id: $datatokenId) {
|
token(id: $datatokenId) {
|
||||||
id
|
id
|
||||||
@ -298,11 +298,10 @@ export async function getOrderPriceAndFees(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} chain
|
* @param {number} chainId
|
||||||
* @param {string} datatokenAddress
|
* @param {string} datatokenAddress
|
||||||
* @param {number} timeout timout of the service, this is needed to return order details
|
* @param {number} timeout timout of the service, this is needed to return order details
|
||||||
* @param {string} account account that wants to buy, is needed to return order details
|
* @param {string} account account that wants to buy, is needed to return order details
|
||||||
* @param {bool} includeOrderPriceAndFees if false price will be spot price (pool) and rate (fre), if true you will get the order price including fees !! fees not yet done
|
|
||||||
* @returns {Promise<AccessDetails>}
|
* @returns {Promise<AccessDetails>}
|
||||||
*/
|
*/
|
||||||
export async function getAccessDetails(
|
export async function getAccessDetails(
|
||||||
@ -317,7 +316,7 @@ export async function getAccessDetails(
|
|||||||
TokenPriceQuery,
|
TokenPriceQuery,
|
||||||
{ datatokenId: string; account: string }
|
{ datatokenId: string; account: string }
|
||||||
> = await fetchData(
|
> = await fetchData(
|
||||||
TokenPriceQuery,
|
tokenPriceQuery,
|
||||||
{
|
{
|
||||||
datatokenId: datatokenAddress.toLowerCase(),
|
datatokenId: datatokenAddress.toLowerCase(),
|
||||||
account: account?.toLowerCase()
|
account: account?.toLowerCase()
|
||||||
@ -360,7 +359,7 @@ export async function getAccessDetailsForAssets(
|
|||||||
TokensPriceQuery,
|
TokensPriceQuery,
|
||||||
{ datatokenIds: [string]; account: string }
|
{ datatokenIds: [string]; account: string }
|
||||||
> = await fetchData(
|
> = await fetchData(
|
||||||
TokensPriceQuery,
|
tokensPriceQuery,
|
||||||
{
|
{
|
||||||
datatokenIds: chainAssetLists[chainKey],
|
datatokenIds: chainAssetLists[chainKey],
|
||||||
account: account?.toLowerCase()
|
account: account?.toLowerCase()
|
||||||
|
@ -144,17 +144,13 @@ export function calcSingleOutGivenPoolIn(
|
|||||||
): string {
|
): string {
|
||||||
const tokenLiquidityD = new Decimal(tokenLiquidity)
|
const tokenLiquidityD = new Decimal(tokenLiquidity)
|
||||||
const poolSupplyD = new Decimal(poolSupply)
|
const poolSupplyD = new Decimal(poolSupply)
|
||||||
const poolShareAmountD = new Decimal(poolShareAmount)
|
const poolShareAmountD = new Decimal(poolShareAmount).mul(2)
|
||||||
|
|
||||||
const newPoolSupply = poolSupplyD.sub(poolShareAmountD)
|
const newPoolSupply = poolSupplyD.sub(poolShareAmountD)
|
||||||
const poolRatio = newPoolSupply.div(poolSupplyD)
|
const poolRatio = newPoolSupply.div(poolSupplyD)
|
||||||
|
|
||||||
const tokenOutRatio = poolRatio.pow(2)
|
const tokenOutRatio = new Decimal(1).sub(poolRatio)
|
||||||
const newTokenBalanceOut = tokenLiquidityD.mul(tokenOutRatio)
|
const newTokenBalanceOut = tokenLiquidityD.mul(tokenOutRatio)
|
||||||
|
return newTokenBalanceOut.toString()
|
||||||
const tokensOut = tokenLiquidityD.sub(newTokenBalanceOut)
|
|
||||||
|
|
||||||
return tokensOut.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,7 +194,7 @@ const OpcFeesQuery = gql`
|
|||||||
opc(id: $id) {
|
opc(id: $id) {
|
||||||
swapOceanFee
|
swapOceanFee
|
||||||
swapNonOceanFee
|
swapNonOceanFee
|
||||||
consumeFee
|
orderFee
|
||||||
providerFee
|
providerFee
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user