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 = {
|
||||
...assetAquarius,
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
|
@ -73,6 +73,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
type: 'NOT_SUPPORTED'
|
||||
} as any
|
||||
},
|
||||
@ -159,6 +160,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -252,6 +254,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -345,6 +348,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -444,6 +448,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -468,6 +473,7 @@ export const assets: AssetExtended[] = [
|
||||
{
|
||||
'@context': ['https://w3id.org/did/v1'],
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -660,6 +666,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -753,6 +760,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -843,6 +851,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'free',
|
||||
addressOrId: '0x0a81f1c69e5428067e6124817c7affe8bc0adf9f',
|
||||
@ -927,6 +936,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 1,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -1015,6 +1025,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'free',
|
||||
addressOrId: '0x772224c2c2bddb88a55b3905aaaf8c7188b02ce3',
|
||||
@ -1099,6 +1110,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'free',
|
||||
addressOrId: '0x89a0170556bb80438081d69f43d8c07a90e9aa24',
|
||||
@ -1181,6 +1193,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'free',
|
||||
addressOrId: '0xad42c7afee47140b5cd87f05d5846c418145f43a',
|
||||
@ -1335,6 +1348,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
@ -1423,6 +1437,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'free',
|
||||
addressOrId: '0x23c1fd10dadcaf558fb7173b79cfd0d867568a3d',
|
||||
@ -1514,6 +1529,7 @@ export const assets: AssetExtended[] = [
|
||||
},
|
||||
version: '4.1.0',
|
||||
accessDetails: {
|
||||
templateId: 2,
|
||||
publisherMarketOrderFee: '0',
|
||||
type: 'fixed',
|
||||
addressOrId:
|
||||
|
@ -18,6 +18,7 @@ module.exports = {
|
||||
|
||||
infuraProjectId: process.env.NEXT_PUBLIC_INFURA_PROJECT_ID || 'xxx',
|
||||
|
||||
defaultDatatokenTemplateIndex: 2,
|
||||
// The ETH address the marketplace fee will be sent to.
|
||||
marketFeeAddress:
|
||||
process.env.NEXT_PUBLIC_MARKET_FEE_ADDRESS ||
|
||||
|
@ -10,6 +10,7 @@ export interface AppConfig {
|
||||
infuraProjectId: string
|
||||
chainIds: number[]
|
||||
chainIdsSupported: number[]
|
||||
defaultDatatokenTemplateIndex: number
|
||||
marketFeeAddress: string
|
||||
publisherMarketOrderFee: 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 {
|
||||
type: 'fixed' | 'free' | 'NOT_SUPPORTED'
|
||||
price: string
|
||||
templateId: number
|
||||
addressOrId: string
|
||||
baseToken: TokenInfo
|
||||
datatoken: TokenInfo
|
||||
|
@ -30,6 +30,7 @@ const tokensPriceQuery = gql`
|
||||
publishMarketFeeAddress
|
||||
publishMarketFeeToken
|
||||
publishMarketFeeAmount
|
||||
templateId
|
||||
orders(
|
||||
where: { payer: $account }
|
||||
orderBy: createdTimestamp
|
||||
@ -84,6 +85,7 @@ const tokenPriceQuery = gql`
|
||||
id
|
||||
symbol
|
||||
name
|
||||
templateId
|
||||
publishMarketFeeAddress
|
||||
publishMarketFeeToken
|
||||
publishMarketFeeAmount
|
||||
@ -160,7 +162,7 @@ function getAccessDetailsFromTokenPrice(
|
||||
// the last valid order should be the last reuse order tx id if there is one
|
||||
accessDetails.validOrderTx = reusedOrder?.tx || order?.tx
|
||||
}
|
||||
|
||||
accessDetails.templateId = tokenPrice.templateId
|
||||
// TODO: fetch order fee from sub query
|
||||
accessDetails.publisherMarketOrderFee = tokenPrice?.publishMarketFeeAmount
|
||||
|
||||
@ -169,6 +171,7 @@ function getAccessDetailsFromTokenPrice(
|
||||
const dispenser = tokenPrice.dispensers[0]
|
||||
accessDetails.type = 'free'
|
||||
accessDetails.addressOrId = dispenser.token.id
|
||||
|
||||
accessDetails.price = '0'
|
||||
accessDetails.isPurchasable = dispenser.active
|
||||
accessDetails.datatoken = {
|
||||
|
@ -3,6 +3,8 @@ import {
|
||||
approve,
|
||||
approveWei,
|
||||
Datatoken,
|
||||
Dispenser,
|
||||
FixedRateExchange,
|
||||
FreOrderParams,
|
||||
LoggerInstance,
|
||||
OrderParams,
|
||||
@ -83,22 +85,6 @@ export async function order(
|
||||
switch (asset.accessDetails?.type) {
|
||||
case 'fixed': {
|
||||
// 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 = {
|
||||
exchangeContract: config.fixedRateExchangeAddress,
|
||||
@ -109,23 +95,96 @@ export async function order(
|
||||
swapMarketFee: consumeMarketFixedSwapFee,
|
||||
marketFeeAddress
|
||||
} 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': {
|
||||
const tx = await datatoken.buyFromDispenserAndOrder(
|
||||
asset.services[0].datatokenAddress,
|
||||
accountId,
|
||||
orderParams,
|
||||
config.dispenserAddress
|
||||
)
|
||||
return tx
|
||||
if (asset.accessDetails.templateId === 1) {
|
||||
const dispenser = new Dispenser(config.dispenserAddress, web3)
|
||||
const dispenserTx = await dispenser.dispense(
|
||||
asset.accessDetails?.datatoken.address,
|
||||
accountId,
|
||||
'1',
|
||||
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 = {
|
||||
type: values.pricing.type,
|
||||
addressOrId: ZERO_ADDRESS,
|
||||
templateId: 1,
|
||||
price: `${values.pricing.price}`,
|
||||
baseToken: {
|
||||
address: ZERO_ADDRESS,
|
||||
|
@ -23,7 +23,8 @@ import { FormPublishData, MetadataAlgorithmContainer } from './_types'
|
||||
import {
|
||||
marketFeeAddress,
|
||||
publisherMarketOrderFee,
|
||||
publisherMarketFixedSwapFee
|
||||
publisherMarketFixedSwapFee,
|
||||
defaultDatatokenTemplateIndex
|
||||
} from '../../../app.config'
|
||||
import { sanitizeUrl } from '@utils/url'
|
||||
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
|
||||
const ercParams: DatatokenCreateParams = {
|
||||
templateIndex: 2,
|
||||
templateIndex: defaultDatatokenTemplateIndex,
|
||||
minter: accountId,
|
||||
paymentCollector: accountId,
|
||||
mpFeeAddress: marketFeeAddress,
|
||||
|
Loading…
Reference in New Issue
Block a user