mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Change datatoken template and ensure compatibility with both (#1728)
* change template * fix build * add template config * test fixes * Update app.config.js Co-authored-by: Alex Coseru <alex.coseru@gmail.com> Co-authored-by: Matthias Kretschmann <m@kretschmann.io> Co-authored-by: Alex Coseru <alex.coseru@gmail.com>
This commit is contained in:
parent
8225775828
commit
131f1f15e3
@ -3,6 +3,7 @@ import { assetAquarius } from './assetAquarius'
|
|||||||
export const asset: AssetExtended = {
|
export const asset: AssetExtended = {
|
||||||
...assetAquarius,
|
...assetAquarius,
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
|
@ -73,6 +73,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
type: 'NOT_SUPPORTED'
|
type: 'NOT_SUPPORTED'
|
||||||
} as any
|
} as any
|
||||||
},
|
},
|
||||||
@ -159,6 +160,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -252,6 +254,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -345,6 +348,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -444,6 +448,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -468,6 +473,7 @@ export const assets: AssetExtended[] = [
|
|||||||
{
|
{
|
||||||
'@context': ['https://w3id.org/did/v1'],
|
'@context': ['https://w3id.org/did/v1'],
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -660,6 +666,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -753,6 +760,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -843,6 +851,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'free',
|
type: 'free',
|
||||||
addressOrId: '0x0a81f1c69e5428067e6124817c7affe8bc0adf9f',
|
addressOrId: '0x0a81f1c69e5428067e6124817c7affe8bc0adf9f',
|
||||||
@ -927,6 +936,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 1,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -1015,6 +1025,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'free',
|
type: 'free',
|
||||||
addressOrId: '0x772224c2c2bddb88a55b3905aaaf8c7188b02ce3',
|
addressOrId: '0x772224c2c2bddb88a55b3905aaaf8c7188b02ce3',
|
||||||
@ -1099,6 +1110,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'free',
|
type: 'free',
|
||||||
addressOrId: '0x89a0170556bb80438081d69f43d8c07a90e9aa24',
|
addressOrId: '0x89a0170556bb80438081d69f43d8c07a90e9aa24',
|
||||||
@ -1181,6 +1193,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'free',
|
type: 'free',
|
||||||
addressOrId: '0xad42c7afee47140b5cd87f05d5846c418145f43a',
|
addressOrId: '0xad42c7afee47140b5cd87f05d5846c418145f43a',
|
||||||
@ -1335,6 +1348,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
@ -1423,6 +1437,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'free',
|
type: 'free',
|
||||||
addressOrId: '0x23c1fd10dadcaf558fb7173b79cfd0d867568a3d',
|
addressOrId: '0x23c1fd10dadcaf558fb7173b79cfd0d867568a3d',
|
||||||
@ -1514,6 +1529,7 @@ export const assets: AssetExtended[] = [
|
|||||||
},
|
},
|
||||||
version: '4.1.0',
|
version: '4.1.0',
|
||||||
accessDetails: {
|
accessDetails: {
|
||||||
|
templateId: 2,
|
||||||
publisherMarketOrderFee: '0',
|
publisherMarketOrderFee: '0',
|
||||||
type: 'fixed',
|
type: 'fixed',
|
||||||
addressOrId:
|
addressOrId:
|
||||||
|
@ -18,6 +18,7 @@ module.exports = {
|
|||||||
|
|
||||||
infuraProjectId: process.env.NEXT_PUBLIC_INFURA_PROJECT_ID || 'xxx',
|
infuraProjectId: process.env.NEXT_PUBLIC_INFURA_PROJECT_ID || 'xxx',
|
||||||
|
|
||||||
|
defaultDatatokenTemplateIndex: 2,
|
||||||
// The ETH address the marketplace fee will be sent to.
|
// The ETH address the marketplace fee will be sent to.
|
||||||
marketFeeAddress:
|
marketFeeAddress:
|
||||||
process.env.NEXT_PUBLIC_MARKET_FEE_ADDRESS ||
|
process.env.NEXT_PUBLIC_MARKET_FEE_ADDRESS ||
|
||||||
|
@ -10,6 +10,7 @@ export interface AppConfig {
|
|||||||
infuraProjectId: string
|
infuraProjectId: string
|
||||||
chainIds: number[]
|
chainIds: number[]
|
||||||
chainIdsSupported: number[]
|
chainIdsSupported: number[]
|
||||||
|
defaultDatatokenTemplateIndex: number
|
||||||
marketFeeAddress: string
|
marketFeeAddress: string
|
||||||
publisherMarketOrderFee: string
|
publisherMarketOrderFee: string
|
||||||
publisherMarketFixedSwapFee: string
|
publisherMarketFixedSwapFee: string
|
||||||
|
1
src/@types/Price.d.ts
vendored
1
src/@types/Price.d.ts
vendored
@ -39,6 +39,7 @@ declare global {
|
|||||||
interface AccessDetails {
|
interface AccessDetails {
|
||||||
type: 'fixed' | 'free' | 'NOT_SUPPORTED'
|
type: 'fixed' | 'free' | 'NOT_SUPPORTED'
|
||||||
price: string
|
price: string
|
||||||
|
templateId: number
|
||||||
addressOrId: string
|
addressOrId: string
|
||||||
baseToken: TokenInfo
|
baseToken: TokenInfo
|
||||||
datatoken: TokenInfo
|
datatoken: TokenInfo
|
||||||
|
@ -30,6 +30,7 @@ const tokensPriceQuery = gql`
|
|||||||
publishMarketFeeAddress
|
publishMarketFeeAddress
|
||||||
publishMarketFeeToken
|
publishMarketFeeToken
|
||||||
publishMarketFeeAmount
|
publishMarketFeeAmount
|
||||||
|
templateId
|
||||||
orders(
|
orders(
|
||||||
where: { payer: $account }
|
where: { payer: $account }
|
||||||
orderBy: createdTimestamp
|
orderBy: createdTimestamp
|
||||||
@ -84,6 +85,7 @@ const tokenPriceQuery = gql`
|
|||||||
id
|
id
|
||||||
symbol
|
symbol
|
||||||
name
|
name
|
||||||
|
templateId
|
||||||
publishMarketFeeAddress
|
publishMarketFeeAddress
|
||||||
publishMarketFeeToken
|
publishMarketFeeToken
|
||||||
publishMarketFeeAmount
|
publishMarketFeeAmount
|
||||||
@ -160,7 +162,7 @@ function getAccessDetailsFromTokenPrice(
|
|||||||
// the last valid order should be the last reuse order tx id if there is one
|
// the last valid order should be the last reuse order tx id if there is one
|
||||||
accessDetails.validOrderTx = reusedOrder?.tx || order?.tx
|
accessDetails.validOrderTx = reusedOrder?.tx || order?.tx
|
||||||
}
|
}
|
||||||
|
accessDetails.templateId = tokenPrice.templateId
|
||||||
// TODO: fetch order fee from sub query
|
// TODO: fetch order fee from sub query
|
||||||
accessDetails.publisherMarketOrderFee = tokenPrice?.publishMarketFeeAmount
|
accessDetails.publisherMarketOrderFee = tokenPrice?.publishMarketFeeAmount
|
||||||
|
|
||||||
@ -169,6 +171,7 @@ function getAccessDetailsFromTokenPrice(
|
|||||||
const dispenser = tokenPrice.dispensers[0]
|
const dispenser = tokenPrice.dispensers[0]
|
||||||
accessDetails.type = 'free'
|
accessDetails.type = 'free'
|
||||||
accessDetails.addressOrId = dispenser.token.id
|
accessDetails.addressOrId = dispenser.token.id
|
||||||
|
|
||||||
accessDetails.price = '0'
|
accessDetails.price = '0'
|
||||||
accessDetails.isPurchasable = dispenser.active
|
accessDetails.isPurchasable = dispenser.active
|
||||||
accessDetails.datatoken = {
|
accessDetails.datatoken = {
|
||||||
|
@ -3,6 +3,8 @@ import {
|
|||||||
approve,
|
approve,
|
||||||
approveWei,
|
approveWei,
|
||||||
Datatoken,
|
Datatoken,
|
||||||
|
Dispenser,
|
||||||
|
FixedRateExchange,
|
||||||
FreOrderParams,
|
FreOrderParams,
|
||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
OrderParams,
|
OrderParams,
|
||||||
@ -83,22 +85,6 @@ export async function order(
|
|||||||
switch (asset.accessDetails?.type) {
|
switch (asset.accessDetails?.type) {
|
||||||
case 'fixed': {
|
case 'fixed': {
|
||||||
// this assumes all fees are in ocean
|
// this assumes all fees are in ocean
|
||||||
const txApprove = await approve(
|
|
||||||
web3,
|
|
||||||
config,
|
|
||||||
accountId,
|
|
||||||
asset.accessDetails.baseToken.address,
|
|
||||||
asset.accessDetails.datatoken.address,
|
|
||||||
await amountToUnits(
|
|
||||||
web3,
|
|
||||||
asset?.accessDetails?.baseToken?.address,
|
|
||||||
orderPriceAndFees.price
|
|
||||||
),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
if (!txApprove) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const freParams = {
|
const freParams = {
|
||||||
exchangeContract: config.fixedRateExchangeAddress,
|
exchangeContract: config.fixedRateExchangeAddress,
|
||||||
@ -109,23 +95,96 @@ export async function order(
|
|||||||
swapMarketFee: consumeMarketFixedSwapFee,
|
swapMarketFee: consumeMarketFixedSwapFee,
|
||||||
marketFeeAddress
|
marketFeeAddress
|
||||||
} as FreOrderParams
|
} as FreOrderParams
|
||||||
const tx = await datatoken.buyFromFreAndOrder(
|
|
||||||
asset.accessDetails.datatoken.address,
|
|
||||||
accountId,
|
|
||||||
orderParams,
|
|
||||||
freParams
|
|
||||||
)
|
|
||||||
|
|
||||||
return tx
|
if (asset.accessDetails.templateId === 1) {
|
||||||
|
// buy datatoken
|
||||||
|
const txApprove = await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
accountId,
|
||||||
|
asset.accessDetails.baseToken.address,
|
||||||
|
config.fixedRateExchangeAddress,
|
||||||
|
await amountToUnits(
|
||||||
|
web3,
|
||||||
|
asset?.accessDetails?.baseToken?.address,
|
||||||
|
orderPriceAndFees.price
|
||||||
|
),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
if (!txApprove) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const fre = new FixedRateExchange(config.fixedRateExchangeAddress, web3)
|
||||||
|
const freTx = await fre.buyDatatokens(
|
||||||
|
accountId,
|
||||||
|
asset.accessDetails?.addressOrId,
|
||||||
|
'1',
|
||||||
|
orderPriceAndFees.price,
|
||||||
|
marketFeeAddress,
|
||||||
|
consumeMarketFixedSwapFee
|
||||||
|
)
|
||||||
|
|
||||||
|
return await datatoken.startOrder(
|
||||||
|
asset.accessDetails.datatoken.address,
|
||||||
|
accountId,
|
||||||
|
orderParams.consumer,
|
||||||
|
orderParams.serviceIndex,
|
||||||
|
orderParams._providerFee,
|
||||||
|
orderParams._consumeMarketFee
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (asset.accessDetails.templateId === 2) {
|
||||||
|
const txApprove = await approve(
|
||||||
|
web3,
|
||||||
|
config,
|
||||||
|
accountId,
|
||||||
|
asset.accessDetails.baseToken.address,
|
||||||
|
asset.accessDetails.datatoken.address,
|
||||||
|
await amountToUnits(
|
||||||
|
web3,
|
||||||
|
asset?.accessDetails?.baseToken?.address,
|
||||||
|
orderPriceAndFees.price
|
||||||
|
),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
if (!txApprove) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return await datatoken.buyFromFreAndOrder(
|
||||||
|
asset.accessDetails.datatoken.address,
|
||||||
|
accountId,
|
||||||
|
orderParams,
|
||||||
|
freParams
|
||||||
|
)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case 'free': {
|
case 'free': {
|
||||||
const tx = await datatoken.buyFromDispenserAndOrder(
|
if (asset.accessDetails.templateId === 1) {
|
||||||
asset.services[0].datatokenAddress,
|
const dispenser = new Dispenser(config.dispenserAddress, web3)
|
||||||
accountId,
|
const dispenserTx = await dispenser.dispense(
|
||||||
orderParams,
|
asset.accessDetails?.datatoken.address,
|
||||||
config.dispenserAddress
|
accountId,
|
||||||
)
|
'1',
|
||||||
return tx
|
accountId
|
||||||
|
)
|
||||||
|
return await datatoken.startOrder(
|
||||||
|
asset.accessDetails.datatoken.address,
|
||||||
|
accountId,
|
||||||
|
orderParams.consumer,
|
||||||
|
orderParams.serviceIndex,
|
||||||
|
orderParams._providerFee,
|
||||||
|
orderParams._consumeMarketFee
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (asset.accessDetails.templateId === 2) {
|
||||||
|
return await datatoken.buyFromDispenserAndOrder(
|
||||||
|
asset.services[0].datatokenAddress,
|
||||||
|
accountId,
|
||||||
|
orderParams,
|
||||||
|
config.dispenserAddress
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ export default function Preview(): ReactElement {
|
|||||||
asset.accessDetails = {
|
asset.accessDetails = {
|
||||||
type: values.pricing.type,
|
type: values.pricing.type,
|
||||||
addressOrId: ZERO_ADDRESS,
|
addressOrId: ZERO_ADDRESS,
|
||||||
|
templateId: 1,
|
||||||
price: `${values.pricing.price}`,
|
price: `${values.pricing.price}`,
|
||||||
baseToken: {
|
baseToken: {
|
||||||
address: ZERO_ADDRESS,
|
address: ZERO_ADDRESS,
|
||||||
|
@ -23,7 +23,8 @@ import { FormPublishData, MetadataAlgorithmContainer } from './_types'
|
|||||||
import {
|
import {
|
||||||
marketFeeAddress,
|
marketFeeAddress,
|
||||||
publisherMarketOrderFee,
|
publisherMarketOrderFee,
|
||||||
publisherMarketFixedSwapFee
|
publisherMarketFixedSwapFee,
|
||||||
|
defaultDatatokenTemplateIndex
|
||||||
} from '../../../app.config'
|
} from '../../../app.config'
|
||||||
import { sanitizeUrl } from '@utils/url'
|
import { sanitizeUrl } from '@utils/url'
|
||||||
import { getContainerChecksum } from '@utils/docker'
|
import { getContainerChecksum } from '@utils/docker'
|
||||||
@ -211,7 +212,7 @@ export async function createTokensAndPricing(
|
|||||||
|
|
||||||
// TODO: cap is hardcoded for now to 1000, this needs to be discussed at some point
|
// TODO: cap is hardcoded for now to 1000, this needs to be discussed at some point
|
||||||
const ercParams: DatatokenCreateParams = {
|
const ercParams: DatatokenCreateParams = {
|
||||||
templateIndex: 2,
|
templateIndex: defaultDatatokenTemplateIndex,
|
||||||
minter: accountId,
|
minter: accountId,
|
||||||
paymentCollector: accountId,
|
paymentCollector: accountId,
|
||||||
mpFeeAddress: marketFeeAddress,
|
mpFeeAddress: marketFeeAddress,
|
||||||
|
Loading…
Reference in New Issue
Block a user