Skip to content

Commit

Permalink
Add partner fee meta-data (#53)
Browse files Browse the repository at this point in the history
* docs: improve docs

* Add partner fee

* Add new schema exported types

* Add unit tests

* Assert decimal values are not allowed

* Fix issue with versions

* Use bips definition for the slippage too

* Use the new bips definition also for the `slippageBips` in the quote

* Add new breaking changes

* chore: pretend 0.12.0 never existed

* chore: rename BIPS to BPS

* chore: change version
  • Loading branch information
anxolin authored Feb 22, 2024
1 parent 2498710 commit 8cc394c
Show file tree
Hide file tree
Showing 20 changed files with 559 additions and 52 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const appDataDoc = await metadataApi.generateAppDataDoc({
metadata: {
referrer,
quote,
orderClass
orderClass,
},
})

Expand Down Expand Up @@ -152,16 +152,19 @@ Fork the repo so you can create a new PR. Then:
- Version it using the [semver](https://semver.org/) convention
- You will need to create the new file for the meta-data schema: `<meta-data-name>/<new-version>.json`
- Update it in the main schema you just created in step 1: Set it to `"<meta-data-name>": { "$ref": "<meta-data-name>/<new-version>.json#" }`
- 🚨 IMPORTANT: Don't forget to add the exported constant with the latest version in:
- https://github.com/cowprotocol/app-data/blob/widget-metadata/src/scripts/compile.ts#L68

4. Modify the `compile.ts` script

- Add the exported constant with the latest version in, and the new metadata:
- For example: https://github.com/cowprotocol/app-data/pull/44/commits/aeef8a58e7bbd2a53664ce396011cb157a18406d

4. Generate the typescript types

- Run `yarn build`

4. Make a test focusing on the new or modified meta-data:
5. Make a test focusing on the new or modified meta-data:

- https://github.com/cowprotocol/app-data/pull/44/files#diff-e755a2ecce42f09829d5c7dc1de8853d1d00ef56eaadc2709601c87b9be8ddfbR556
- Don't forget to use the right version of the schema in your test: https://github.com/cowprotocol/app-data/pull/44/files#diff-e755a2ecce42f09829d5c7dc1de8853d1d00ef56eaadc2709601c87b9be8ddfbR11

5. Create the PR and document it together with the motivation for the changes
6. Create the PR and document it together with the motivation for the changes
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/app-data",
"version": "1.2.2",
"version": "2.0.0",
"description": "CowProtocol AppData schema definitions",
"type": "module",
"source": "src/index.ts",
Expand Down
12 changes: 8 additions & 4 deletions src/generatedTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import * as v0_6_0 from './v0.6.0'
import * as v0_7_0 from './v0.7.0'
import * as v0_8_0 from './v0.8.0'
import * as v0_9_0 from './v0.9.0'
import * as v1_0_0 from './v1.0.0'

export * as latest from './v0.11.0'
export * as latest from './v1.0.0'

export const LATEST_APP_DATA_VERSION = '0.11.0'
export const LATEST_QUOTE_METADATA_VERSION = '0.3.0'
export const LATEST_APP_DATA_VERSION = '1.0.0'
export const LATEST_QUOTE_METADATA_VERSION = '1.0.0'
export const LATEST_REFERRER_METADATA_VERSION = '0.2.0'
export const LATEST_ORDER_CLASS_METADATA_VERSION = '0.3.0'
export const LATEST_UTM_METADATA_VERSION = '0.2.0'
export const LATEST_HOOKS_METADATA_VERSION = '0.1.0'
export const LATEST_SIGNER_METADATA_VERSION = '0.1.0'
export const LATEST_WIDGET_METADATA_VERSION = '0.1.0'
export const LATEST_PARTNER_FEE_METADATA_VERSION = '0.1.0'

export type LatestAppDataDocVersion = v0_11_0.AppDataRootSchema
export type LatestAppDataDocVersion = v1_0_0.AppDataRootSchema
export type AnyAppDataDocVersion =
| v1_0_0.AppDataRootSchema
| v0_11_0.AppDataRootSchema
| v0_10_0.AppDataRootSchema
| v0_9_0.AppDataRootSchema
Expand All @@ -38,6 +41,7 @@ export type AnyAppDataDocVersion =
| v0_1_0.AppDataRootSchema

export {
v1_0_0,
v0_11_0,
v0_10_0,
v0_9_0,
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.10.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type UTMContent = string;
*/
export type UTMKeywordTerm = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.11.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type UTMContent = string;
*/
export type UTMKeywordTerm = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.4.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type ReferrerAddress = string;
*/
export type Version2 = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;

Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.5.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type ReferrerAddress = string;
*/
export type Version2 = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.6.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type UTMKeywordTerm = string;
*/
export type Version2 = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.7.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type UTMKeywordTerm = string;
*/
export type Version2 = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.8.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type UTMContent = string;
*/
export type UTMKeywordTerm = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
2 changes: 1 addition & 1 deletion src/generatedTypes/v0.9.0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type UTMContent = string;
*/
export type UTMKeywordTerm = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)
*/
export type SlippageBips = string;
/**
Expand Down
154 changes: 154 additions & 0 deletions src/generatedTypes/v1.0.0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* tslint:disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/

/**
* Semantic versioning of document.
*/
export type Version = string;
/**
* The code identifying the CLI, UI, service generating the order.
*/
export type AppCode = string;
/**
* Environment from which the order came from.
*/
export type Environment = string;
/**
* The address of the trader who signs the CoW Swap order. This field should normally be omitted; it is recommended to use it if the signer is a smart-contract wallet using EIP-1271 signatures.
*/
export type Signer = string;
export type ReferrerAddress = string;
/**
* Tracks in which medium the traffic originated from (twitter, facebook, etc.)
*/
export type UTMSource = string;
/**
* Tracks in which medium the traffic originated from (mail, CPC, social, etc.)
*/
export type UTMMedium = string;
/**
* Track the performance of a specific campaign
*/
export type UTMCampaign = string;
/**
* Track which link was clicked
*/
export type UTMContent = string;
/**
* Track which keyword term a website visitor came from
*/
export type UTMKeywordTerm = string;
/**
* Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS). One basis point is equivalent to 0.01% (1/100th of a percent)
*/
export type SlippageBips = number;
/**
* Indicator of the order class.
*/
export type OrderClass1 = "market" | "limit" | "liquidity" | "twap";
/**
* Semantic versioning of document.
*/
export type Version1 = string;
/**
* The contract to call for the hook
*/
export type HookTarget = string;
/**
* The calldata to use when calling the hook
*/
export type HookCallData = string;
/**
* The gas limit (in gas units) for the hook
*/
export type HookGasLimit = string;
/**
* CoW Hooks to call before an order executes
*/
export type PreHooks = CoWHook[];
/**
* CoW Hooks to call after an order executes
*/
export type PostHooks = CoWHook[];
/**
* The code identifying the UI powering the widget
*/
export type AppCode1 = string;
/**
* Environment from which the order came from.
*/
export type Environment1 = string;
/**
* The fee in basis points (BPS) to be paid to the partner. One basis point is equivalent to 0.01% (1/100th of a percent)
*/
export type BasisPointBPS = number;
/**
* The Ethereum address of the partner to receive the fee.
*/
export type PartnerAccount = string;

/**
* Metadata JSON document for adding information to orders.
*/
export interface AppDataRootSchema {
version: Version;
appCode?: AppCode;
environment?: Environment;
metadata: Metadata;
}
/**
* Each metadata will specify one aspect of the order.
*/
export interface Metadata {
signer?: Signer;
referrer?: Referrer;
utm?: UTMCodes;
quote?: Quote;
orderClass?: OrderClass;
hooks?: OrderInteractionHooks;
widget?: Widget;
partnerFee?: PartnerFee;
}
export interface Referrer {
address: ReferrerAddress;
}
export interface UTMCodes {
utmSource?: UTMSource;
utmMedium?: UTMMedium;
utmCampaign?: UTMCampaign;
utmContent?: UTMContent;
utmTerm?: UTMKeywordTerm;
}
export interface Quote {
slippageBips: SlippageBips;
}
export interface OrderClass {
orderClass: OrderClass1;
}
/**
* Optional Pre and Post order interaction hooks attached to a single order
*/
export interface OrderInteractionHooks {
version?: Version1;
pre?: PreHooks;
post?: PostHooks;
}
export interface CoWHook {
target: HookTarget;
callData: HookCallData;
gasLimit: HookGasLimit;
}
export interface Widget {
appCode: AppCode1;
environment?: Environment1;
[k: string]: unknown;
}
export interface PartnerFee {
bps: BasisPointBPS;
recipient: PartnerAccount;
[k: string]: unknown;
}
24 changes: 12 additions & 12 deletions src/schemas/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@
"$id": "#/definitions/version",
"description": "Semantic versioning of document.",
"readOnly": true,
"examples": [
"1.0.0",
"1.2.3"
],
"examples": ["1.0.0", "1.2.3"],
"title": "Version",
"type": "string"
},
"ethereumAddress": {
"$id": "#/definitions/ethereumAddress",
"pattern": "^0x[a-fA-F0-9]{40}$",
"title": "Ethereum compatible address",
"examples": [
"0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9"
],
"examples": ["0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9"],
"type": "string"
},
"bigNumber": {
"$id": "#/definitions/bigNumber",
"pattern": "^\\d+$",
"title": "BigNumber",
"examples": [
"90741097240912730913",
"0",
"75891372"
],
"examples": ["90741097240912730913", "0", "75891372"],
"type": "string"
},
"bps": {
"$id": "#/definitions/bps",
"title": "Basis Point (BPS)",
"description": "One basis point is equivalent to 0.01% (1/100th of a percent)",
"examples": [0, 10, 50],
"type": "integer",
"maximum": 10000,
"minimum": 0
}
}
}
19 changes: 19 additions & 0 deletions src/schemas/partnerFee/v0.1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$id": "#partnerFee/v0.1.0.json",
"$schema": "http://json-schema.org/draft-07/schema",
"required": ["bps", "recipient"],
"title": "Partner fee",
"type": "object",
"properties": {
"bps": {
"title": "Basis Point (BPS)",
"description": "The fee in basis points (BPS) to be paid to the partner. One basis point is equivalent to 0.01% (1/100th of a percent)",
"$ref": "../definitions.json#/definitions/bps"
},
"recipient": {
"title": "Partner account",
"description": "The Ethereum address of the partner to receive the fee.",
"$ref": "../definitions.json#/definitions/ethereumAddress"
}
}
}
14 changes: 3 additions & 11 deletions src/schemas/quote/v0.2.0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"$id": "#quote/v0.2.0.json",
"$schema": "http://json-schema.org/draft-07/schema",
"required": [
"version",
"slippageBips"
],
"required": ["version", "slippageBips"],
"title": "Quote",
"type": "object",
"properties": {
Expand All @@ -16,13 +13,8 @@
"slippageBips": {
"$id": "#/properties/slippageBips",
"title": "Slippage Bips",
"description": "Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BIPS)",
"examples": [
"5",
"10",
"20",
"100"
],
"description": "Slippage tolerance that was applied to the order to get the limit price. Expressed in Basis Points (BPS)",
"examples": ["5", "10", "20", "100"],
"pattern": "^\\d+(\\.\\d+)?$",
"type": "string"
}
Expand Down
Loading

0 comments on commit 8cc394c

Please sign in to comment.