Skip to content

Commit

Permalink
[feat]: Implement underwrite evaluation (#25)
Browse files Browse the repository at this point in the history
* feat: Update resolvers (match relayer)

* feat: Query underwrite reward fiat price from relayer

* feat: Implement `maxGasLimit` calculation logic

* fix: types

* feat: Implement 'gasEstimate' via the resolvers

* feat: Take into account fixed transaction costs

* chore: Remove unused code block

* feat: Consider swap relay costs on underwrite evaluation

* fix: relay delivery costs config loading

* chore: Improve underwrite evaluation logs

* chore: Improve swap profit query error logging

* fix: 'profitabilityFactor' incorrectly set on worker init

* feat: Effectively disable evaluation when profitabilityFactor is 0

* chore: Improve evaluation logging

* feat: make 'maxUnderwriteAllowed' be fiat based

* chore: Remove duplicated 'blockDelay' configuration

* chore: Add missing configuration to config.example.yaml
  • Loading branch information
jsanmigimeno committed Jul 24, 2024
1 parent ecf7b47 commit 5395d37
Show file tree
Hide file tree
Showing 19 changed files with 915 additions and 238 deletions.
26 changes: 24 additions & 2 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,26 @@ global:
0.05 # Extra buffer allowed on top of the calculated required funds for
# performing an underwrite.

maxUnderwriteAllowed: '10000000000000000000' # Maximum tokens to risk on a single underwrite
minUnderwriteReward: '10000000000' # Minimum acceptable token reward for an underwrite
maxUnderwriteAllowed: 500 # Maximum underwrite value (EXCLUDING THE COLLATERAL).
# In the 'pricingDenomination' specified on the Relayer.
minUnderwriteReward: 0.5 # Minimum underwrite reward desired.
# In the 'pricingDenomination' specified on the Relayer.
relativeMinUnderwriteReward: 0.1 # Minimum relative underwrite reward desired (w.r.t. the
# underwrite amount plus the tx cost).
profitabilityFactor: 1.0 # Profitiability evaluation adjustment factor. A larger
# factor implies a larger profitability guarantee.

lowTokenBalanceWarning: '1000000000000000000' # Token balance below which a 'low balance' warning is emitted.
tokenBalanceUpdateInterval:
50 # Number of transactions after which to update the
# Underwriter token balance from the rpc.

relayDeliveryCosts: # Average swap delivery costs for underwritten swaps. Used to estimate underwrites profitability
gasUsage: '21000' # The gas used.
# gasObserved: '21000' # The gas observed by the escrow contract.
# fee: '0' # The fee taken on transaction submission (relevant for L2 chains.)
# value: '0' # The value sent to the escrow as payment (e.g. to execute the return 'ack' cross-chain message).

# ! The following setting is here for illustrative purposes, but it MUST ALWAYS be applied on
# ! a per-chain basis as it is CRITICAL to prevent the underwriter from being stolen from.
# minMaxGasDelivery: 200000
Expand Down Expand Up @@ -105,6 +118,7 @@ chains:
# The tokens that are to be undewritten
tokens:
- name: 'Wrapped gas'
tokenId: "ethereum"
address: '0xE67ABDA0D43f7AC8f37876bBF00D1DFadbB93aaa'
allowanceBuffer:
'10000000000000000000' # Amount by which to 'buffer' the token approvals
Expand Down Expand Up @@ -138,6 +152,7 @@ chains:
minMaxGasDelivery: 200000
tokens:
- name: 'WETH'
tokenId: "ethereum"
address: '0x1BDD24840e119DC2602dCC587Dd182812427A5Cc'
allowanceBuffer: '10000000000000000000'

Expand All @@ -158,6 +173,7 @@ chains:
minMaxGasDelivery: 200000
tokens:
- name: 'WETH'
tokenId: "ethereum"
address: '0x4200000000000000000000000000000000000006'
allowanceBuffer: '10000000000000000000'

Expand All @@ -177,6 +193,12 @@ endpoints:
address: '0x0000000003b8C9BFeB9351933CFC301Eea92073F'
- name: 'Amplified'
address: '0x000000004aBe0D620b25b8B06B0712BDcff21899'
# Costs overrides (uncomment to enable)
# relayDeliveryCosts:
# gasUsage: '21000'
# gasObserved: '21000'
# fee: '0'
# value: '0'

- name: 'Optimism Sepolia Testnet'
amb: 'wormhole'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"pino": "^8.16.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"viem": "^2.16.2",
"ws": "^8.16.0"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 5395d37

Please sign in to comment.