mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
pricing defaults changes, fixes
This commit is contained in:
parent
228b09098a
commit
235d8333eb
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,4 +13,4 @@ networks-metadata.json
|
|||||||
src/@types/apollo
|
src/@types/apollo
|
||||||
graphql.schema.json
|
graphql.schema.json
|
||||||
src/@types/graph.types.ts
|
src/@types/graph.types.ts
|
||||||
public
|
tsconfig.tsbuildinfo
|
||||||
|
@ -35,7 +35,7 @@ async function getBlockHead(config: ConfigHelperConfig) {
|
|||||||
// for ETH main, get block from graph fetch
|
// for ETH main, get block from graph fetch
|
||||||
if (config.network === 'mainnet') {
|
if (config.network === 'mainnet') {
|
||||||
const response: any = await fetchGraph(ethGraphUrl, ethGraphQuery)
|
const response: any = await fetchGraph(ethGraphUrl, ethGraphQuery)
|
||||||
return Number(response?.data?.blocks[0].number)
|
return Number(response?.data?.blocks[0]?.number)
|
||||||
}
|
}
|
||||||
|
|
||||||
// for everything else, create new web3 instance with infura
|
// for everything else, create new web3 instance with infura
|
||||||
|
@ -22,7 +22,7 @@ interface UsePricing {
|
|||||||
) => Promise<TransactionReceipt | string | void>
|
) => Promise<TransactionReceipt | string | void>
|
||||||
mint: (tokensToMint: string, ddo: DDO) => Promise<TransactionReceipt | void>
|
mint: (tokensToMint: string, ddo: DDO) => Promise<TransactionReceipt | void>
|
||||||
buyDT: (
|
buyDT: (
|
||||||
dtAmount: number | string,
|
amountDataToken: number | string,
|
||||||
price: BestPrice,
|
price: BestPrice,
|
||||||
ddo: DDO
|
ddo: DDO
|
||||||
) => Promise<TransactionReceipt | void>
|
) => Promise<TransactionReceipt | void>
|
||||||
@ -112,7 +112,7 @@ function usePricing(): UsePricing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function buyDT(
|
async function buyDT(
|
||||||
dtAmount: number | string,
|
amountDataToken: number | string,
|
||||||
price: BestPrice,
|
price: BestPrice,
|
||||||
ddo: DDO
|
ddo: DDO
|
||||||
): Promise<TransactionReceipt | void> {
|
): Promise<TransactionReceipt | void> {
|
||||||
@ -144,7 +144,7 @@ function usePricing(): UsePricing {
|
|||||||
tx = await ocean.pool.buyDT(
|
tx = await ocean.pool.buyDT(
|
||||||
accountId,
|
accountId,
|
||||||
price.address,
|
price.address,
|
||||||
String(dtAmount),
|
String(amountDataToken),
|
||||||
oceanAmmount,
|
oceanAmmount,
|
||||||
maxPrice
|
maxPrice
|
||||||
)
|
)
|
||||||
@ -171,7 +171,7 @@ function usePricing(): UsePricing {
|
|||||||
setStep(2, 'buy', ddo)
|
setStep(2, 'buy', ddo)
|
||||||
tx = await ocean.fixedRateExchange.buyDT(
|
tx = await ocean.fixedRateExchange.buyDT(
|
||||||
price.address,
|
price.address,
|
||||||
`${dtAmount}`,
|
`${amountDataToken}`,
|
||||||
accountId
|
accountId
|
||||||
)
|
)
|
||||||
setStep(3, 'buy', ddo)
|
setStep(3, 'buy', ddo)
|
||||||
@ -222,10 +222,10 @@ function usePricing(): UsePricing {
|
|||||||
|
|
||||||
if (!ocean || !accountId || !dtSymbol) return
|
if (!ocean || !accountId || !dtSymbol) return
|
||||||
|
|
||||||
const { type, oceanAmount, price, weightOnDataToken, swapFee } =
|
const { type, amountOcean, price, weightOnDataToken, swapFee } =
|
||||||
priceOptions
|
priceOptions
|
||||||
|
|
||||||
let { dtAmount } = priceOptions
|
let { amountDataToken } = priceOptions
|
||||||
const isPool = type === 'dynamic'
|
const isPool = type === 'dynamic'
|
||||||
|
|
||||||
if (!isPool && !config.fixedRateExchangeAddress) {
|
if (!isPool && !config.fixedRateExchangeAddress) {
|
||||||
@ -244,25 +244,25 @@ function usePricing(): UsePricing {
|
|||||||
await ocean.OceanDispenser.activate(dataToken, '1', '1', accountId)
|
await ocean.OceanDispenser.activate(dataToken, '1', '1', accountId)
|
||||||
} else {
|
} else {
|
||||||
// if fixedPrice set dt to max amount
|
// if fixedPrice set dt to max amount
|
||||||
if (!isPool) dtAmount = 1000
|
if (!isPool) amountDataToken = 1000
|
||||||
await mint(`${dtAmount}`, ddo)
|
await mint(`${amountDataToken}`, ddo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dtAmount for fixed price is set to max
|
// amountDataToken for fixed price is set to max
|
||||||
const tx = isPool
|
const tx = isPool
|
||||||
? await ocean.pool
|
? await ocean.pool
|
||||||
.create(
|
.create(
|
||||||
accountId,
|
accountId,
|
||||||
dataToken,
|
dataToken,
|
||||||
`${dtAmount}`,
|
`${amountDataToken}`,
|
||||||
weightOnDataToken,
|
weightOnDataToken,
|
||||||
`${oceanAmount}`,
|
`${amountOcean}`,
|
||||||
`${swapFee}`
|
`${swapFee}`
|
||||||
)
|
)
|
||||||
.next((step: number) => setStep(step, 'pool', ddo))
|
.next((step: number) => setStep(step, 'pool', ddo))
|
||||||
: type === 'fixed'
|
: type === 'fixed'
|
||||||
? await ocean.fixedRateExchange
|
? await ocean.fixedRateExchange
|
||||||
.create(dataToken, `${price}`, accountId, `${dtAmount}`)
|
.create(dataToken, `${price}`, accountId, `${amountDataToken}`)
|
||||||
.next((step: number) => setStep(step, 'exchange', ddo))
|
.next((step: number) => setStep(step, 'exchange', ddo))
|
||||||
: await ocean.OceanDispenser.makeMinter(dataToken, accountId).next(
|
: await ocean.OceanDispenser.makeMinter(dataToken, accountId).next(
|
||||||
(step: number) => setStep(step, 'free', ddo)
|
(step: number) => setStep(step, 'free', ddo)
|
||||||
|
4
src/@types/Price.d.ts
vendored
4
src/@types/Price.d.ts
vendored
@ -13,8 +13,8 @@ interface BestPrice {
|
|||||||
|
|
||||||
interface PriceOptions {
|
interface PriceOptions {
|
||||||
price: number
|
price: number
|
||||||
dtAmount: number
|
amountDataToken: number
|
||||||
oceanAmount: number
|
amountOcean: number
|
||||||
type: 'fixed' | 'dynamic' | 'free' | string
|
type: 'fixed' | 'dynamic' | 'free' | string
|
||||||
weightOnDataToken: string
|
weightOnDataToken: string
|
||||||
weightOnOcean: string
|
weightOnOcean: string
|
||||||
|
@ -22,7 +22,6 @@ export default function URLInput({
|
|||||||
<input
|
<input
|
||||||
className={styles.input}
|
className={styles.input}
|
||||||
{...props}
|
{...props}
|
||||||
{...field}
|
|
||||||
type="url"
|
type="url"
|
||||||
onBlur={(e: React.SyntheticEvent) => handleButtonClick(e, field.value)}
|
onBlur={(e: React.SyntheticEvent) => handleButtonClick(e, field.value)}
|
||||||
/>
|
/>
|
||||||
|
@ -64,54 +64,54 @@ export default function Swap({
|
|||||||
if (!ddo || !balance || !values?.type || !price) return
|
if (!ddo || !balance || !values?.type || !price) return
|
||||||
|
|
||||||
async function calculateMaximum() {
|
async function calculateMaximum() {
|
||||||
const dtAmount =
|
const amountDataToken =
|
||||||
values.type === 'buy'
|
values.type === 'buy'
|
||||||
? new Decimal(maxDt)
|
? new Decimal(maxDt)
|
||||||
: new Decimal(balance.datatoken)
|
: new Decimal(balance.datatoken)
|
||||||
const oceanAmount =
|
const amountOcean =
|
||||||
values.type === 'buy'
|
values.type === 'buy'
|
||||||
? new Decimal(balance.ocean)
|
? new Decimal(balance.ocean)
|
||||||
: new Decimal(maxOcean)
|
: new Decimal(maxOcean)
|
||||||
|
|
||||||
const maxBuyOcean = await ocean.pool.getOceanReceived(
|
const maxBuyOcean = await ocean.pool.getOceanReceived(
|
||||||
price.address,
|
price.address,
|
||||||
`${dtAmount.toString()}`
|
`${amountDataToken.toString()}`
|
||||||
)
|
)
|
||||||
const maxBuyDt = await ocean.pool.getDTReceived(
|
const maxBuyDt = await ocean.pool.getDTReceived(
|
||||||
price.address,
|
price.address,
|
||||||
`${oceanAmount.toString()}`
|
`${amountOcean.toString()}`
|
||||||
)
|
)
|
||||||
|
|
||||||
const maximumDt =
|
const maximumDt =
|
||||||
values.type === 'buy'
|
values.type === 'buy'
|
||||||
? dtAmount.greaterThan(new Decimal(maxBuyDt))
|
? amountDataToken.greaterThan(new Decimal(maxBuyDt))
|
||||||
? maxBuyDt
|
? maxBuyDt
|
||||||
: dtAmount
|
: amountDataToken
|
||||||
: dtAmount.greaterThan(new Decimal(balance.datatoken))
|
: amountDataToken.greaterThan(new Decimal(balance.datatoken))
|
||||||
? balance.datatoken
|
? balance.datatoken
|
||||||
: dtAmount
|
: amountDataToken
|
||||||
|
|
||||||
const maximumOcean =
|
const maximumOcean =
|
||||||
values.type === 'sell'
|
values.type === 'sell'
|
||||||
? oceanAmount.greaterThan(new Decimal(maxBuyOcean))
|
? amountOcean.greaterThan(new Decimal(maxBuyOcean))
|
||||||
? maxBuyOcean
|
? maxBuyOcean
|
||||||
: oceanAmount
|
: amountOcean
|
||||||
: oceanAmount.greaterThan(new Decimal(balance.ocean))
|
: amountOcean.greaterThan(new Decimal(balance.ocean))
|
||||||
? balance.ocean
|
? balance.ocean
|
||||||
: oceanAmount
|
: amountOcean
|
||||||
|
|
||||||
setMaximumDt(maximumDt.toString())
|
setMaximumDt(maximumDt.toString())
|
||||||
setMaximumOcean(maximumOcean.toString())
|
setMaximumOcean(maximumOcean.toString())
|
||||||
|
|
||||||
setOceanItem((prevState) => ({
|
setOceanItem((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
amount: oceanAmount.toString(),
|
amount: amountOcean.toString(),
|
||||||
maxAmount: maximumOcean.toString()
|
maxAmount: maximumOcean.toString()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
setDtItem((prevState) => ({
|
setDtItem((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
amount: dtAmount.toString(),
|
amount: amountDataToken.toString(),
|
||||||
maxAmount: maximumDt.toString()
|
maxAmount: maximumDt.toString()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -28,28 +28,28 @@ export default function Dynamic({ content }: { content: any }): ReactElement {
|
|||||||
weightOnDataToken,
|
weightOnDataToken,
|
||||||
weightOnOcean,
|
weightOnOcean,
|
||||||
swapFee,
|
swapFee,
|
||||||
dtAmount,
|
amountDataToken,
|
||||||
oceanAmount
|
amountOcean
|
||||||
} = values.pricing
|
} = values.pricing
|
||||||
|
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
|
|
||||||
// Calculate firstPrice whenever user values change
|
// Calculate firstPrice whenever user values change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (`${oceanAmount}` === '') return
|
if (`${amountOcean}` === '') return
|
||||||
|
|
||||||
const tokenAmountOut = 1
|
const tokenAmountOut = 1
|
||||||
const weightRatio = new Decimal(weightOnDataToken).div(
|
const weightRatio = new Decimal(weightOnDataToken).div(
|
||||||
new Decimal(weightOnOcean)
|
new Decimal(weightOnOcean)
|
||||||
)
|
)
|
||||||
const diff = new Decimal(dtAmount).minus(tokenAmountOut)
|
const diff = new Decimal(amountDataToken).minus(tokenAmountOut)
|
||||||
const y = new Decimal(dtAmount).div(diff)
|
const y = new Decimal(amountDataToken).div(diff)
|
||||||
const foo = y.pow(weightRatio).minus(new Decimal(1))
|
const foo = y.pow(weightRatio).minus(new Decimal(1))
|
||||||
const tokenAmountIn = new Decimal(oceanAmount)
|
const tokenAmountIn = new Decimal(amountOcean)
|
||||||
.times(foo)
|
.times(foo)
|
||||||
.div(new Decimal(1).minus(new Decimal(swapFee / 100)))
|
.div(new Decimal(1).minus(new Decimal(swapFee / 100)))
|
||||||
setFirstPrice(`${tokenAmountIn}`)
|
setFirstPrice(`${tokenAmountIn}`)
|
||||||
}, [swapFee, weightOnOcean, weightOnDataToken, dtAmount, oceanAmount])
|
}, [swapFee, weightOnOcean, weightOnDataToken, amountDataToken, amountOcean])
|
||||||
|
|
||||||
// Check: account, network & insufficient balance
|
// Check: account, network & insufficient balance
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -90,12 +90,12 @@ export default function Dynamic({ content }: { content: any }): ReactElement {
|
|||||||
|
|
||||||
<div className={styles.tokens}>
|
<div className={styles.tokens}>
|
||||||
<Coin
|
<Coin
|
||||||
name="oceanAmount"
|
name="amountOcean"
|
||||||
datatokenOptions={{ symbol: 'OCEAN', name: 'Ocean Token' }}
|
datatokenOptions={{ symbol: 'OCEAN', name: 'Ocean Token' }}
|
||||||
weight={`${Number(weightOnOcean) * 10}%`}
|
weight={`${Number(weightOnOcean) * 10}%`}
|
||||||
/>
|
/>
|
||||||
<Coin
|
<Coin
|
||||||
name="dtAmount"
|
name="amountDataToken"
|
||||||
datatokenOptions={{
|
datatokenOptions={{
|
||||||
symbol: dataTokenOptions.symbol,
|
symbol: dataTokenOptions.symbol,
|
||||||
name: dataTokenOptions.name
|
name: dataTokenOptions.name
|
||||||
|
@ -18,7 +18,7 @@ export default function PricingFields(): ReactElement {
|
|||||||
// Connect with main publish form
|
// Connect with main publish form
|
||||||
const { values, setFieldValue } = useFormikContext<FormPublishData>()
|
const { values, setFieldValue } = useFormikContext<FormPublishData>()
|
||||||
const { pricing } = values
|
const { pricing } = values
|
||||||
const { price, oceanAmount, weightOnOcean, weightOnDataToken, type } = pricing
|
const { price, amountOcean, weightOnOcean, weightOnDataToken, type } = pricing
|
||||||
|
|
||||||
console.log(pricing)
|
console.log(pricing)
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ export default function PricingFields(): ReactElement {
|
|||||||
function handleTabChange(tabName: string) {
|
function handleTabChange(tabName: string) {
|
||||||
const type = tabName.toLowerCase()
|
const type = tabName.toLowerCase()
|
||||||
setFieldValue('pricing.type', type)
|
setFieldValue('pricing.type', type)
|
||||||
type === 'fixed' && setFieldValue('pricing.dtAmount', 1000)
|
type === 'fixed' && setFieldValue('pricing.amountDataToken', 1000)
|
||||||
type === 'free' && price < 1 && setFieldValue('pricing.price', 1)
|
type === 'free' && price < 1 && setFieldValue('pricing.price', 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,19 +34,19 @@ export default function PricingFields(): ReactElement {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (type === 'fixed' || type === 'free') return
|
if (type === 'fixed' || type === 'free') return
|
||||||
|
|
||||||
const dtAmount =
|
const amountDataToken =
|
||||||
isValidNumber(oceanAmount) &&
|
isValidNumber(amountOcean) &&
|
||||||
isValidNumber(weightOnOcean) &&
|
isValidNumber(weightOnOcean) &&
|
||||||
isValidNumber(price) &&
|
isValidNumber(price) &&
|
||||||
isValidNumber(weightOnDataToken)
|
isValidNumber(weightOnDataToken)
|
||||||
? new Decimal(oceanAmount)
|
? new Decimal(amountOcean)
|
||||||
.dividedBy(new Decimal(weightOnOcean))
|
.dividedBy(new Decimal(weightOnOcean))
|
||||||
.dividedBy(new Decimal(price))
|
.dividedBy(new Decimal(price))
|
||||||
.mul(new Decimal(weightOnDataToken))
|
.mul(new Decimal(weightOnDataToken))
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
setFieldValue('pricing.dtAmount', dtAmount)
|
setFieldValue('pricing.amountDataToken', amountDataToken)
|
||||||
}, [price, oceanAmount, weightOnOcean, weightOnDataToken, type])
|
}, [price, amountOcean, weightOnOcean, weightOnDataToken, type])
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
appConfig.allowFixedPricing === 'true'
|
appConfig.allowFixedPricing === 'true'
|
||||||
|
@ -9,13 +9,13 @@ export const initialValues: Partial<FormPublishData> = {
|
|||||||
name: '',
|
name: '',
|
||||||
author: '',
|
author: '',
|
||||||
description: '',
|
description: '',
|
||||||
termsAndConditions: false,
|
tags: '',
|
||||||
tags: ''
|
termsAndConditions: false
|
||||||
},
|
},
|
||||||
services: [
|
services: [
|
||||||
{
|
{
|
||||||
files: '',
|
files: [],
|
||||||
links: '',
|
links: [],
|
||||||
dataTokenOptions: { name: '', symbol: '' },
|
dataTokenOptions: { name: '', symbol: '' },
|
||||||
timeout: 'Forever',
|
timeout: 'Forever',
|
||||||
access: '',
|
access: '',
|
||||||
@ -30,10 +30,10 @@ export const initialValues: Partial<FormPublishData> = {
|
|||||||
: allowFixedPricing === 'true'
|
: allowFixedPricing === 'true'
|
||||||
? 'fixed'
|
? 'fixed'
|
||||||
: 'free',
|
: 'free',
|
||||||
dtAmount: allowDynamicPricing === 'true' ? 9 : 1000,
|
amountDataToken: allowDynamicPricing === 'true' ? 50 : 1000,
|
||||||
oceanAmount: 21,
|
amountOcean: 50,
|
||||||
weightOnOcean: '7', // 70% on OCEAN
|
weightOnOcean: '5', // 50% on OCEAN
|
||||||
weightOnDataToken: '3', // 30% on datatoken
|
weightOnDataToken: '5', // 50% on datatoken
|
||||||
swapFee: 0.1 // in %
|
swapFee: 0.1 // in %
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,7 +42,9 @@ const validationMetadata = {
|
|||||||
name: Yup.string()
|
name: Yup.string()
|
||||||
.min(4, (param) => `Title must be at least ${param.min} characters`)
|
.min(4, (param) => `Title must be at least ${param.min} characters`)
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
description: Yup.string().min(10).required('Required'),
|
description: Yup.string()
|
||||||
|
.min(10, (param) => `Description must be at least ${param.min} characters`)
|
||||||
|
.required('Required'),
|
||||||
author: Yup.string().required('Required'),
|
author: Yup.string().required('Required'),
|
||||||
tags: Yup.string().nullable(),
|
tags: Yup.string().nullable(),
|
||||||
termsAndConditions: Yup.boolean().required('Required')
|
termsAndConditions: Yup.boolean().required('Required')
|
||||||
@ -60,6 +62,9 @@ const validationService = {
|
|||||||
})
|
})
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
timeout: Yup.string().required('Required'),
|
timeout: Yup.string().required('Required'),
|
||||||
|
type: Yup.string()
|
||||||
|
.matches(/Dataset|Algorithm/g, { excludeEmptyString: true })
|
||||||
|
.required('Required'),
|
||||||
access: Yup.string()
|
access: Yup.string()
|
||||||
.matches(/Compute|Download/g, { excludeEmptyString: true })
|
.matches(/Compute|Download/g, { excludeEmptyString: true })
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
@ -70,10 +75,10 @@ const validationPricing = {
|
|||||||
price: Yup.number()
|
price: Yup.number()
|
||||||
.min(1, (param) => `Must be more or equal to ${param.min}`)
|
.min(1, (param) => `Must be more or equal to ${param.min}`)
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
dtAmount: Yup.number()
|
amountDataToken: Yup.number()
|
||||||
.min(9, (param) => `Must be more or equal to ${param.min}`)
|
.min(9, (param) => `Must be more or equal to ${param.min}`)
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
oceanAmount: Yup.number()
|
amountOcean: Yup.number()
|
||||||
.min(21, (param) => `Must be more or equal to ${param.min}`)
|
.min(21, (param) => `Must be more or equal to ${param.min}`)
|
||||||
.required('Required'),
|
.required('Required'),
|
||||||
type: Yup.string()
|
type: Yup.string()
|
||||||
|
Loading…
Reference in New Issue
Block a user