App data generation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { Web3Provider } from '@ethersproject/providers'
import { MetadataApi } from '@cowprotocol/app-data'
export async function run(provider: Web3Provider): Promise<unknown> {
const metadataApi = new MetadataApi()
const appCode = '<YOUR_APP_CODE>'
const environment = 'prod'
const referrer = { address: `0x360Ba61Bc799edfa01e306f1eCCb2F6e0C3C8c8e` }
const quote = { slippageBips: '0' } // Slippage percent, it's 0 to 100
const orderClass = { orderClass: 'limit' } // "market" | "limit" | "liquidity"
const appDataDoc = await metadataApi.generateAppDataDoc({
appCode,
environment,
metadata: {
referrer,
quote,
orderClass
},
})
const { cid, appDataHex, appDataContent } = await metadataApi.appDataToCid(appDataDoc)
return { appDataDoc, cid, appDataHex, appDataContent }
}