Skip to content

Commit

Permalink
Add support for private transaction mode (#56)
Browse files Browse the repository at this point in the history
* Change private transaction type

* change example
  • Loading branch information
shahnami authored May 14, 2024
1 parent 062a96d commit d67d719
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/defender-test-project/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ resources:
- '0x0f06aB75c7DD497981b75CD82F6566e3a5CAd8f2'
# optional
eip1559-pricing: true
private-transactions: true
private-transactions: 'flashbots-fast'

secrets:
# optional - global secrets are not affected by stackName changes
Expand Down
40 changes: 26 additions & 14 deletions src/types/docs-schemas/definitions.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,37 @@
}
]
},
"flashbotTransactionMode": {
"title": "FlashbotTransactionMode",
"type": "string",
"description": "Fast mode has 2 key differences from the default Protect experience: \n1. Shared with all builders: By default, Protect transactions are only shared with the Flashbots Builder, which builds only a subset of all Ethereum blocks. In fast mode, transactions are shared with all registered builders to increase the number of blocks the user's transaction can be included in.\n2. Larger refund paid to validator: By default, only 10% of MEV-Share refunds are paid to validators. In fast mode, validators receive 50% of refunds which makes it more likely that the user’s transactions will be chosen in a given block.",
"enum": ["flashbots-normal", "flashbots-fast"]
},
"privateTransactionMode": {
"title": "PrivateTransactionMode",
"oneOf": [
{
"$ref": "definitions.schema.json#/definitions/flashbotTransactionMode"
}
]
},
"policy": {
"title": "Policy",
"type": "object",
"properties": {
"gas-price-cap": {
"type": "integer"
},
"whitelist-receivers": {
"title": "WhitelistReceivers",
"type": "array",
"items": {
"type": "string"
}
},
"eip1559-pricing": {
"type": "boolean"
},
"gas-price-cap": { "type": "integer" },
"whitelist-receivers": { "title": "WhitelistReceivers", "type": "array", "items": { "type": "string" } },
"eip1559-pricing": { "type": "boolean" },
"private-transactions": {
"type": "boolean"
"oneOf": [
{
"description": "Backwards compatibility with the old private transaction mode",
"type": "boolean"
},
{
"$ref": "definitions.schema.json#/definitions/privateTransactionMode"
}
]
}
}
},
Expand Down
12 changes: 12 additions & 0 deletions src/types/docs/definitions-definitions-flashbottransactionmode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 0 Type

`string` ([FlashbotTransactionMode](definitions-definitions-flashbottransactionmode.md))

## 0 Constraints

**enum**: the value of this property must be equal to one of the following values:

| Value | Explanation |
| :------------------- | :---------- |
| `"flashbots-normal"` | |
| `"flashbots-fast"` | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0 Type

`boolean`
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## private-transactions Type

`boolean`
merged type ([Details](definitions-definitions-policy-properties-private-transactions.md))

one (and only one) of

* [Untitled boolean in Definitions](definitions-definitions-policy-properties-private-transactions-oneof-0.md "check type definition")

* one (and only one) of

* [FlashbotTransactionMode](definitions-definitions-flashbottransactionmode.md "check type definition")
14 changes: 11 additions & 3 deletions src/types/docs/definitions-definitions-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| [gas-price-cap](#gas-price-cap) | `integer` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-gas-price-cap.md "definitions.schema.json#/definitions/policy/properties/gas-price-cap") |
| [whitelist-receivers](#whitelist-receivers) | `array` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-whitelistreceivers.md "definitions.schema.json#/definitions/policy/properties/whitelist-receivers") |
| [eip1559-pricing](#eip1559-pricing) | `boolean` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-eip1559-pricing.md "definitions.schema.json#/definitions/policy/properties/eip1559-pricing") |
| [private-transactions](#private-transactions) | `boolean` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-private-transactions.md "definitions.schema.json#/definitions/policy/properties/private-transactions") |
| [private-transactions](#private-transactions) | Merged | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-private-transactions.md "definitions.schema.json#/definitions/policy/properties/private-transactions") |

## gas-price-cap

Expand Down Expand Up @@ -77,12 +77,20 @@

* is optional

* Type: `boolean`
* Type: merged type ([Details](definitions-definitions-policy-properties-private-transactions.md))

* cannot be null

* defined in: [Definitions](definitions-definitions-policy-properties-private-transactions.md "definitions.schema.json#/definitions/policy/properties/private-transactions")

### private-transactions Type

`boolean`
merged type ([Details](definitions-definitions-policy-properties-private-transactions.md))

one (and only one) of

* [Untitled boolean in Definitions](definitions-definitions-policy-properties-private-transactions-oneof-0.md "check type definition")

* one (and only one) of

* [FlashbotTransactionMode](definitions-definitions-flashbottransactionmode.md "check type definition")
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 1 Type

merged type ([PrivateTransactionMode](definitions-definitions-privatetransactionmode.md))

one (and only one) of

* [FlashbotTransactionMode](definitions-definitions-flashbottransactionmode.md "check type definition")
36 changes: 33 additions & 3 deletions src/types/docs/definitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ Reference this group by using
| Property | Type | Required | Nullable | Defined by |
| :------- | :--- | :------- | :------- | :--------- |

## Definitions group flashbotTransactionMode

Reference this group by using

```json
{"$ref":"definitions.schema.json#/definitions/flashbotTransactionMode"}
```

| Property | Type | Required | Nullable | Defined by |
| :------- | :--- | :------- | :------- | :--------- |

## Definitions group privateTransactionMode

Reference this group by using

```json
{"$ref":"definitions.schema.json#/definitions/privateTransactionMode"}
```

| Property | Type | Required | Nullable | Defined by |
| :------- | :--- | :------- | :------- | :--------- |

## Definitions group policy

Reference this group by using
Expand All @@ -105,7 +127,7 @@ Reference this group by using
| [gas-price-cap](#gas-price-cap) | `integer` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-gas-price-cap.md "definitions.schema.json#/definitions/policy/properties/gas-price-cap") |
| [whitelist-receivers](#whitelist-receivers) | `array` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-whitelistreceivers.md "definitions.schema.json#/definitions/policy/properties/whitelist-receivers") |
| [eip1559-pricing](#eip1559-pricing) | `boolean` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-eip1559-pricing.md "definitions.schema.json#/definitions/policy/properties/eip1559-pricing") |
| [private-transactions](#private-transactions) | `boolean` | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-private-transactions.md "definitions.schema.json#/definitions/policy/properties/private-transactions") |
| [private-transactions](#private-transactions) | Merged | Optional | cannot be null | [Definitions](definitions-definitions-policy-properties-private-transactions.md "definitions.schema.json#/definitions/policy/properties/private-transactions") |

### gas-price-cap

Expand Down Expand Up @@ -169,15 +191,23 @@ Reference this group by using

* is optional

* Type: `boolean`
* Type: merged type ([Details](definitions-definitions-policy-properties-private-transactions.md))

* cannot be null

* defined in: [Definitions](definitions-definitions-policy-properties-private-transactions.md "definitions.schema.json#/definitions/policy/properties/private-transactions")

#### private-transactions Type

`boolean`
merged type ([Details](definitions-definitions-policy-properties-private-transactions.md))

one (and only one) of

* [Untitled boolean in Definitions](definitions-definitions-policy-properties-private-transactions-oneof-0.md "check type definition")

* one (and only one) of

* [FlashbotTransactionMode](definitions-definitions-privatetransactionmode-oneof-flashbottransactionmode.md "check type definition")

## Definitions group relayer

Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { JsonFragment } from 'ethers';

import { Network, SupportedNetwork } from '@openzeppelin/defender-sdk-base-client';
import { Contract } from '@openzeppelin/defender-sdk-proposal-client/lib/models/contract';
import { RelayerGetResponse, RelayerApiKey } from '@openzeppelin/defender-sdk-relay-client/lib/models';
import { RelayerGetResponse, RelayerApiKey, PrivateTransactionMode } from '@openzeppelin/defender-sdk-relay-client/lib/models';
import { DefenderApiResponseError } from '@openzeppelin/defender-sdk-base-client/lib/api/api-error';

import {
Expand Down Expand Up @@ -96,7 +96,7 @@ export type YPolicy = {
'gas-price-cap'?: number;
'whitelist-receivers'?: string[];
'eip1559-pricing'?: boolean;
'private-transactions'?: boolean;
'private-transactions'?: boolean | PrivateTransactionMode;
};

export type YRelayer = {
Expand Down
2 changes: 1 addition & 1 deletion src/types/schemas/definitions.schema.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/types/types/resources.schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export type CustomNetwork = 'x-dfk-avax-chain' | 'x-dfk-avax-chain-test' | 'x-se
export type TenantNetwork = string;
export type AddressFromRelayer = {} | string;
export type WhitelistReceivers = string[];
export type PrivateTransactionMode = FlashbotTransactionMode;
/**
* Fast mode has 2 key differences from the default Protect experience:
* 1. Shared with all builders: By default, Protect transactions are only shared with the Flashbots Builder, which builds only a subset of all Ethereum blocks. In fast mode, transactions are shared with all registered builders to increase the number of blocks the user's transaction can be included in.
* 2. Larger refund paid to validator: By default, only 10% of MEV-Share refunds are paid to validators. In fast mode, validators receive 50% of refunds which makes it more likely that the user’s transactions will be chosen in a given block.
*/
export type FlashbotTransactionMode = 'flashbots-normal' | 'flashbots-fast';
export type RelayerAPIKeys = string[];
export type DefenderID = string;
export type TriggerType = 'schedule' | 'webhook' | 'sentinel' | 'monitor-filter';
Expand Down Expand Up @@ -198,7 +205,7 @@ export interface Policy {
'gas-price-cap'?: number;
'whitelist-receivers'?: WhitelistReceivers;
'eip1559-pricing'?: boolean;
'private-transactions'?: boolean;
'private-transactions'?: boolean | PrivateTransactionMode;
}
export interface Trigger {
type: TriggerType;
Expand Down Expand Up @@ -275,7 +282,7 @@ export interface Policy1 {
'gas-price-cap'?: number;
'whitelist-receivers'?: WhitelistReceivers;
'eip1559-pricing'?: boolean;
'private-transactions'?: boolean;
'private-transactions'?: boolean | PrivateTransactionMode;
}
export interface Contracts {
[k: string]: ContractOrDefenderID;
Expand Down
2 changes: 1 addition & 1 deletion template/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ resources:
whitelist-receivers:
- '0x0f06aB75c7DD497981b75CD82F6566e3a5CAd8f2'
eip1559-pricing: true
private-transactions: true
private-transactions: 'flashbots-normal'

relayers:
relayer-1:
Expand Down

0 comments on commit d67d719

Please sign in to comment.