GMX V2源码剖析2-Readme
August 8th, 2023

4看代码,先看README

GMX Synthetics

Contracts for GMX Synthetics.

General Overview

This section provides a general overview of how the system works.

本节提供了系统工作原理的总体概述。

For a Technical Overview, please see the section further below.

有关技术概述,请参阅下面的further部分。

Markets

Markets support both spot and perp trading, they are created by specifying a long collateral token, short collateral token and index token.

市场支持现货和期货交易,它们是通过指定“做多抵押代币”、“做空抵押代币”和“指数代币”来创建的。

Examples:

  • ETH/USD market with long collateral as ETH, short collateral as a stablecoin, index token as ETH

    ETH/USD市场的做多代币是ETH,做空代币是USD,指数代币是ETH

  • BTC/USD market with long collateral as WBTC, short collateral as a stablecoin, index token as BTC

  • SOL/USD market with long collateral as ETH, short collateral as a stablecoin, index token as SOL

    SOL/USD市场的做多代币是ETH,做空代币是USD,指数代币是SOL

Liquidity providers can deposit either the long or short collateral token or both to mint liquidity tokens.

LP可以存入做多或做空抵押品代币,也可以同时存入两者来制造流动性代币。

The long collateral token is used to back long positions, while the short collateral token is used to back short positions.

多头抵押品用于支持多头头寸,而空头抵押品令牌用于支持空头头寸。

Liquidity providers take on the profits and losses of traders for the market that they provide liquidity for.

LP赚取traders亏的钱,或者支付traders赚的钱。

Having separate markets allows for risk isolation, liquidity providers are only exposed to the markets that they deposit into, this potentially allow for permissionless listings.

单独的市场允许风险隔离,LP只承担他们存入市场的风险,这给将来开通允许未经许可的上币提供可能。。

Traders can use either the long or short token as collateral for the market.

交易者可以使用多头或空头代币作为市场的抵押品。

Features

The contracts support the following main features:

这些合约支持以下主要特性:

  • Deposit and withdrawal of liquidity

    流动性池的充值和提现

  • Spot Trading (Swaps)

    现货交易

  • Leverage Trading (Perps, Long / Short)

    杠杠交易

  • Market orders, limit orders, stop-loss, take-profit orders

    市价单、限价单、止盈止损单

Oracle System

To avoid front-running issues, most actions require two steps to execute:

为了避免抢先交易问题,大多数操作需要执行两个步骤:

  • User sends transaction with request details, e.g. deposit / withdraw liquidity, swap, increase / decrease position

    用户发送带有请详细信息的请求(上链),例如 充值/提现、swap、增加/减少仓位

  • Keepers listen for the transactions, include the prices for the request then send a transaction to execute the request

    Keepers 监听用户的请求,然后发送带有价格的交易来执行用户的请求

Prices are provided by an off-chain oracle system:

价格由链下预言机系统提供:

  • Oracle keepers continually check the latest blocks

    Oracle keepers 不断检查最新的块

  • When there is a new block, oracle keepers fetch the latest prices from reference exchanges

    当出现新区块时,Oracle keepers从参考交易所获取最新价格

  • Oracle keepers then sign the median price for each token together with the block hash

    然后,Oracle keepers将每个代币的中位价格与区块哈希值一起签名

  • Oracle keepers then send the data and signature to archive nodes

    然后 Oracle keepers 将数据和签名发送到存档节点

  • Archive nodes display this information for anyone to query

    归档节点显示此信息以供任何人查询

Example:

  • Block 100 is finalized on the blockchain

    链上最新的高度是100

  • Oracle keepers observe this block

    Oracle keepers 观察到这个块

  • Oracle keepers pull the latest prices from reference exchanges, token A: price 20,000, token B: price 80,000

    Oracle keepers 从参考的交易所拉取最新的价格,如token A的价格是20000, token B的价格是80000

  • Oracle keepers sign [chainId, blockhash(100), 20,000], [chainId, blockhash(100), 80,000]

    Oracle keepers 签署 [chainId, blockhash(100), 20,000], [chainId, blockhash(100), 80,000]

  • If in block 100, there was a market order to open a long position for token A, the market order would have a block number of 100

    如果在100这个块,有一个做多token A的市价单,那么这个市价单就有了一个编号100

  • The prices signed at block 100 can be used to execute this order

    在高度100的块中,已经签署的价格可以用户这个市价单。

  • Order keepers would bundle the signature and price data for token A then execute the order

    Oracle keepers 将token A 的签名和价格数据捆绑在一起,然后执行订单

The oracle system allows for both a minimum price and a maximum price to be signed, this allows information about bid-ask spreads to be included.

预言机系统允许签署最低价格和最高价格,这允许包含有关买卖价差的信息。

Fees and Pricing

费用和定价

Funding fees and price impact keep longs / shorts balanced while reducing the risk of price manipulation.

资金费和价格影响 保持多头/空头平衡,同时降低价格操纵的风险。

  • Funding fees: if there is an imbalance of longs / shorts, the larger side pays a funding fee to the smaller side

    资金费用:如果多头/空头不平衡,较大的一方向较小的一方支付资金费用

  • Borrowing fees: to avoid a user opening equal longs / shorts and unnecessarily taking up capacity

    借贷费用:避免用户开仓等量多头/空头,不必要地占用容量

  • Price impact: this allows the contracts to simulate a price impact similar to if the trader were trading using an aggregator for the reference exchanges, there is a negative price impact if an action reduces balance, and a positive price impact if an action improves balance

    价格影响:这允许合约模拟价格影响,类似于交易者使用参考交易所的聚合器进行交易,如果某项操作减少余额,则会产生负面价格影响,如果某项操作改善平衡,则会产生正面价格影响,todo 没解释清楚

Keepers

There are a few keepers and nodes in the system:

系统中有一些守护者和节点:

  • Oracle keepers: checks for latest finalized blocks, pull prices from reference exchanges, sign the information and publish it to Archive nodes

    Oracle keepers:检查最新最终确定的区块,从参考交易所获取价格,签署信息并将其发布到存档节点

  • Archive nodes: receives oracle keeper signatures and allows querying of this information

    Archive nodes:接收 oracle keeper 签名并允许查询此信息

  • Order keepers: checks for deposit / withdraw liquidity requests, order requests, bundles the signed oracle prices with the requests and executes them

    Order keepers:检查LP的存款/取款请求、交易订单请求,将签名的预言机价格与请求捆绑在一起并执行它们

Structure

There are a few main types of contracts:

合约主要有以下几种类型:

  • Bank contracts which hold funds

    1. 持有资金的银行合约

  • Data storage which stores data

    2. 数据存储 存储数据

  • *storeUtils utils to serialize, store and retrieve data for structs

    3. storeUtils 用于序列化、存储和检索结构数据的实用程序

  • Logic contracts which do not hold funds and do not have internal state

    4. 逻辑合约是不持有资金且没有内部状态的合约

  • *eventUtils utils to emit events

    5. eventUtils utils 发送事件

The contracts are separated into these types to allow for gradual upgradeability.

合约分为这些类型,以允许逐步升级。

Majority of data is stored using the DataStore contract.

大多数数据是使用 DataStore 合约存储的。

*storeUtils contracts store struct data using the DataStore, this allows new keys to be added to structs.

*storeUtils 合约使用 DataStore 存储结构数据,这允许将新key添加到结构中。

EnumberableSets are used to allow order lists and position lists to be easily queried by interfaces or keepers, this is used over indexers as there may be a lag for indexers to sync the latest block. Having the lists stored directly in the contract also helps to ensure that accurate data can be retrieved and verified when needed.

EnumberableSets 用于允许接口或keepers轻松查询订单列表和仓位列表,这在索引器上使用,因为索引器同步最新块可能会有延迟。将列表直接存储在合同中还有助于确保在需要时可以检索和验证准确的数据。

*eventUtils contracts emit events using the event emitter, the events are generalized to allow new key-values to be added to events without requiring an update of ABIs.

*eventUtils 合约使用事件发射器发出事件,这些事件被泛化为允许将新的键值添加到事件中,而不需要更新 ABI。

Technical Overview

This section provides a technical description of the contracts.

本节提供合同的技术描述。

Exchange Contracts

  • Router: approve token spending using this contract

    Router:授权此合约可以花费我的代币

  • ExchangeRouter: create requests for deposits, withdrawals, orders, tokens are transferred using the Router

    ExchangeRouter: 创建存款、取款、订单请求,使用Router传输代币

  • /exchange contracts: execute user requests

Markets

Markets are created using MarketFactory.createMarket, this creates a MarketToken and stores a Market.Props struct in the MarketStore.

市场是使用 MarketFactory.createMarket 创建的,这会创建一个 MarketToken 并将 Market.Props 结构存储在 MarketStore 中。

The MarketToken is used to keep track of liquidity providers share of the market pool and to store the tokens for each market.

MarketToken 用于跟踪LP在市场池中的份额,并每个市场都有自己的代币。

At any point in time, the price of a MarketToken is (worth of market pool) / MarketToken.totalSupply(), the function MarketUtils.getMarketTokenPrice can be used to retrieve this value.

在任何时间点,MarketToken 的价格都是(资金池的价值)/ MarketToken.totalSupply(),可以使用函数 MarketUtils.getMarketTokenPrice 来检索该值。

The worth of the market pool is the sum of

市场池的价值是

  • worth of all tokens deposited into the pool

    存入池中的所有代币的价值,todo 包含已平仓的pnl吗?如果包含,如果用户在ETH/USD市场支付的BTC是怎么存入pool中的?

  • total pending PnL of all open positions

    所有未平仓头寸的未决盈亏总额

  • total pending borrow fees of all open positions

    所有未平仓头寸的待借费用总额

Deposits

提供流动性

Deposits add long / short tokens to the market's pool and mints MarketTokens to the depositor.

存款将多头/空头代币添加到市场池中,并向存款人铸造 MarketTokens。todo 提供多头代币和空头代币得到的GM是一样的吗?怎么区分

Requests for deposits are created by calling ExchangeRouter.createDeposit, specifying:

存款请求是通过调用 ExchangeRouter.createDeposit 创建的,并指定:

  • the market to deposit into

    存入的市场

  • amount of long tokens to deposit

    存入的多头代币数量

  • amount of short tokens to deposit

    存入的空头代币数量

Deposit requests are executed using DepositHandler.executeDeposit, if the deposit was created at block n, it should be executed with the oracle prices at block n.

存款请求使用 DepositHandler.executeDeposit 执行,如果存款是在区块 n 创建的,则应使用区块 n 的预言机价格执行。

The amount of MarketTokens to be minted, before fees and price impact, is calculated as (worth of tokens deposited) / (worth of market pool) * MarketToken.totalSupply().

在费用和价格影响之前,要铸造的 MarketToken 数量的计算方式为(存入代币的价值)/(资金池的价值)* MarketToken.totalSupply()。

Withdrawals

撤出流动性

Withdrawals burn MarketTokens in exchange for the long / short tokens of a market's pool.

提款会燃烧 MarketTokens,以换取市场池中的多头/空头代币。

Requests for withdrawals are created by calling ExchangeRouter.createWithdrawal, specifying:

提款请求是通过调用 ExchangeRouter.createWithdrawal 创建的,并指定:

  • the market to withdraw from

    市场

  • the number of market tokens to burn for long tokens

    要燃烧的多头market token的数量

  • the number of market tokens to burn for short tokens

    要燃烧的空头market token的数量

Withdrawal requests are executed using WithdrawalHandler.executeWithdrawal, if the withdrawal was created at block n, it should be executed with the oracle prices at block n.

提款请求使用 WithdrawalHandler.executeWithdrawal 执行,如果提款是在第 n 块创建的,则应使用第 n 块的预言机价格执行。

The amount of long or short tokens to be redeemed, before fees and price impact, is calculated as (worth of market tokens) / (long / short token price).

在费用和价格影响之前,要赎回的多头或空头代币数量的计算方式为(market token价值)/(多头/空头代币价格)。

Market Swaps

市价现货交易

Long and short tokens of a market can be swapped for each other.

市场的多头和空头代币可以相互互换。

For example, if the ETH / USD market has WETH as the long token and USDC as the short token, WETH can be sent to the market to be swapped for USDC and USDC can be sent to the market to be swapped for WETH.

例如,如果 ETH/USD 市场有 WETH 作为多头,USDC 作为空头,则可以将 WETH 发送到市场兑换 USDC,将 USDC 发送到市场兑换 WETH。

Swap order requests are created by calling ExchangeRouter.createOrder, specifying:

现货订单请求是通过调用 ExchangeRouter.createOrder 创建的,并指定:

  • the initial collateral token

    初始抵押代币

  • the array of markets to swap through

    可交换的市场阵列

  • the minimum expected output amount

    最小预期产出量

The swap output amount, before fees and price impact, (amount of tokens in) * (token in price) / (token out price).

未计费用和价格影响的掉期输出金额,(代币流入量)*(代币流入价格)/(代币流出价格)。

Market swap order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with the oracle prices at block n.

市价现货订单请求使用 OrderHandler.executeOrder 执行,如果订单是在区块 n 创建的,则应使用区块 n 的预言机价格执行。

Limit Swaps

限价现货交易

Passive swap orders that should be executed when the output amount matches the minimum output amount specified by the user.

当输出金额与用户指定的最小输出金额匹配时应执行的被动现货订单。

Limit swap order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with oracle prices after block n.

限价现货订单请求使用 OrderHandler.executeOrder 执行,如果订单是在区块 n 创建的,则应在区块 n 之后使用预言机价格执行。

Market Increase

市价开仓

Open or increase a long / short perp position.

开立或增加多头/空头永续仓位。

Market increase order requests are created by calling ExchangeRouter.createOrder, specifying:

市价增加订单请求是通过调用 ExchangeRouter.createOrder 创建的,并指定:

  • the initial collateral token

    初始抵押代币

  • the array of markets to swap through to get the actual collateral token

    通过swap以获得实际抵押代币的一系列market?todo是不是指trader付出的代币要经过一系列的swap才能获得真正需要的抵押代币

  • the amount to increase the position by

    增加仓位的金额

  • whether it is a long or short position

    是多头还是空头

Market increase order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with the oracle prices at block n.

市价上涨订单请求使用 OrderHandler.executeOrder 执行,如果订单是在区块 n 创建的,则应使用区块 n 的预言机价格执行。

Limit Increase

限价单

Passive increase position orders that should be executed when the index token price matches the acceptable price specified by the user.

当指数代币价格与用户指定的可接受价格匹配时应执行的被动增仓订单。

Long position example: if the current index token price is $5000, a limit increase order can be created with acceptable price as $4990, the order can be executed when the index token price is <= $4990.

多仓示例:如果当前指数代币价格为$5000,可以创建一个限价上涨订单,可接受价格为$4990,当指数代币价格<=$4990时可以执行该订单。

Short position example: if the current index token price is $5000, a limit increase order can be created with acceptable price as $5010, the order can be executed when the index token price is >= $5010.

空仓示例:如果当前指数代币价格为$5000,可以创建一个限价上涨订单,可接受价格为$5010,当指数代币价格>=$5010时可以执行该订单。

Limit increase order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with the oracle prices after block n.

限价增加订单请求使用OrderHandler.executeOrder执行,如果订单是在第n块创建的,则应使用第n块之后的预言机价格执行。

Market Decrease

市价平仓

Close or decrease a long / short perp position.

平仓或减少多头/空头永久头寸。

Market decrease order requests are created by calling ExchangeRouter.createOrder, specifying:

市价平仓订单请求是通过调用 ExchangeRouter.createOrder 创建的,并指定:

  • the initial collateral token

    抵押token

  • the array of markets to swap through for the actual output token

    用于交换实际输出代币的市场数组

  • the amount to decrease the position by

    头寸减少量

Market decrease order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with the oracle prices at block n.

市价减价订单请求使用 OrderHandler.executeOrder 执行,如果订单是在区块 n 创建的,则应使用区块 n 的预言机价格执行。

Limit Decrease

限价平仓

Passive decrease position orders that should be executed when the index token price matches the acceptable price specified by the user.

当指数代币价格符合用户指定的可接受价格时应执行的被动减仓订单。

Long position example: if the current index token price is $5000, a limit decrease order can be created with acceptable price as $5010, the order can be executed when the index token price is >= $5010.

多仓示例:如果当前指数代币价格为$5000,可以创建一个限价跌价订单,可接受价格为$5010,当指数代币价格>=$5010时,该订单可以执行。

Short position example: if the current index token price is $5000, a limit decrease order can be created with acceptable price as $4990, the order can be executed when the index token price is <= $4990.

空仓示例:如果当前指数代币价格为$5000,可以创建一个限价跌价订单,可接受价格为$4990,当指数代币价格<=$4990时可以执行该订单。

Limit decrease order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with the oracle prices after block n.

限价减单请求使用 OrderHandler.executeOrder 执行,如果订单是在区块 n 创建的,则应使用区块 n 之后的预言机价格执行。

Stop-Loss Decrease

止损平仓

Passive decrease position orders that should be executed when the index token price crosses the acceptable price specified by the user.

当指数代币价格超过用户指定的可接受价格时应执行的被动减仓订单。

Long position example: if the current index token price is $5000, a stop-loss decrease order can be created with acceptable price as $4990, the order can be executed when the index token price is <= $4990.

多仓示例:如果当前指数代币价格为 5000 美元,可以创建止损减量订单,可接受价格为 4990 美元,当指数代币价格 <= 4990 美元时可以执行该订单。

Short position example: if the current index token price is $5000, a stop-loss decrease order can be created with acceptable price as $5010, the order can be executed when the index token price is >= $5010.

空仓示例:如果当前指数代币价格为$5000,可以创建止损减量订单,可接受价格为$5010,当指数代币价格>=$5010时可以执行该订单。

Stop-loss decrease order requests are executed using OrderHandler.executeOrder, if the order was created at block n, it should be executed with the oracle prices after block n.

止损减单请求使用 OrderHandler.executeOrder 执行,如果订单是在区块 n 创建的,则应使用区块 n 之后的预言机价格执行。

Order Pricing

订单定价

For limit swap, limit increase, limit decrease and stop-loss decrease orders, the order can be executed at the acceptable price if it is within the range of the validated oracle prices.

对于限价现货、限价开仓、限价平仓和止损平仓订单,如果订单在已验证的预言机价格范围内,则可以按可接受的价格执行。

For example, if the current index token price is $5000 and a user creates a limit long decrease order with acceptable price as $5010, the order can be executed with the index token price as $5010 if oracle prices $5008 and $5012 are validated, the blocks of the oracle prices must be after the order was updated and must be in ascending order.

例如,如果当前指数代币价格为 5000 美元,用户创建了一个可接受价格为 5010 美元的限价多头递减订单,如果预言机价格为 5008 美元和 5012 美元得到验证,该订单可以以指数代币价格为 5010 美元执行,区块预言机价格必须是订单更新后的价格,并且必须按升序排列。

Oracle Prices

预言机价格

Oracle prices are signed as a value together with a precision, this allows prices to be compacted as uint32 values.

Oracle 价格被签名为一个带有精度的值,这使得价格可以被压缩为 uint32 值。

The signed prices represent the price of one unit of the token using a value with 30 decimals of precision.

签名价格代表一个token的价格,使用精确到 30 位小数的值。

Representing the prices in this way allows for conversions between token amounts and fiat values to be simplified, e.g. to calculate the fiat value of a given number of tokens the calculation would just be: token amount * oracle price, to calculate the token amount for a fiat value it would be: fiat value / oracle price.

以这种方式表示价格可以简化代币金额和法定价值之间的转换,例如要计算给定数量代币的法币价值,计算结果为:代币数量 * 预言机价格,计算法币兑换代币数量为:法币价值 / 预言机价格。

The trade-off of this simplicity in calculation is that tokens with a small USD price and a lot of decimals may have precision issues it is also possible that a token's price changes significantly and results in requiring higher precision.

这种计算简单性的代价是,美元价格较小且小数点较多的代币可能存在精度问题,代币的价格也可能发生显着变化,导致需要更高的精度。

Example 1

The price of ETH is 5000, and ETH has 18 decimals.

ETH的价格是5000,ETH有1​​8位小数。

The price of one unit of ETH is 5000 / (10 ^ 18), 5 * (10 ^ -15).

一单位ETH的价格为5000/(10^18)=5*(10^-15)。

To handle the decimals, multiply the value by (10 ^ 30).

要处理小数,请将值乘以 (10 ^ 30)。

Price would be stored as 5000 / (10 ^ 18) * (10 ^ 30) => 5000 * (10 ^ 12).

价格将存储为 5000 / (10 ^ 18) * (10 ^ 30) => 5000 * (10 ^ 12)。

For gas optimization, these prices are sent to the oracle in the form of a uint8 decimal multiplier value and uint32 price value.

对于 Gas 优化,这些价格以 uint8 十进制乘数值和 uint32 价格值的形式发送到预言机。

If the decimal multiplier value is set to 8, the uint32 value would be 5000 * (10 ^ 12) / (10 ^ 8) => 5000 * (10 ^ 4).

如果十进制乘数值设置为 8,则 uint32 值将为 5000 * (10 ^ 12) / (10 ^ 8) => 5000 * (10 ^ 4)。

With this config, ETH prices can have a maximum value of (2 ^ 32) / (10 ^ 4) => 4,294,967,296 / (10 ^ 4) => 429,496.7296 with 4 decimals of precision.

使用此配置,ETH 价格的最大值可为 (2 ^ 32) / (10 ^ 4) => 4,294,967,296 / (10 ^ 4) => 429,496.7296,精度为 4 位小数。

Example 2

The price of BTC is 60,000, and BTC has 8 decimals.

BTC的价格是60000,BTC有8位小数。

The price of one unit of BTC is 60,000 / (10 ^ 8), 6 * (10 ^ -4).

一单位BTC的价格为60,000 / (10^8), 6 * (10^-4)

Price would be stored as 60,000 / (10 ^ 8) * (10 ^ 30) => 6 * (10 ^ 26) => 60,000 * (10 ^ 22).

BTC prices maximum value: (2 ^ 64) / (10 ^ 2) => 4,294,967,296 / (10 ^ 2) => 42,949,672.96.

BTC价格最大值:(2 ^ 64) / (10 ^ 2) => 4,294,967,296 / (10 ^ 2) => 42,949,672.96。

Decimals of precision: 2.

精度小数:2。

Example 3

The price of USDC is 1, and USDC has 6 decimals.

USDC的价格为1,USDC有6位小数。

The price of one unit of USDC is 1 / (10 ^ 6), 1 * (10 ^ -6).

一单位 USDC 的价格为 1 / (10 ^ 6), 1 * (10 ^ -6)。

Price would be stored as 1 / (10 ^ 6) * (10 ^ 30) => 1 * (10 ^ 24).

价格将存储为 1 / (10 ^ 6) * (10 ^ 30) => 1 * (10 ^ 24)。

USDC prices maximum value: (2 ^ 64) / (10 ^ 6) => 4,294,967,296 / (10 ^ 6) => 4294.967296.

USDC 价格最大值:(2 ^ 64) / (10 ^ 6) => 4,294,967,296 / (10 ^ 6) => 4294.967296。

Decimals of precision: 6.

精度小数:6

Example 4

The price of DG is 0.00000001, and DG has 18 decimals.

The price of one unit of DG is 0.00000001 / (10 ^ 18), 1 * (10 ^ -26).

Price would be stored as 1 * (10 ^ -26) * (10 ^ 30) => 1 * (10 ^ 3).

DG prices maximum value: (2 ^ 64) / (10 ^ 11) => 4,294,967,296 / (10 ^ 11) => 0.04294967296.

Decimals of precision: 11.

Decimal Multiplier

小数乘数

The formula to calculate what the decimal multiplier value should be set to:

计算小数乘数应设置为多少的公式:

Decimals: 30 - (token decimals) - (number of decimals desired for precision)

  • ETH: 30 - 18 - 4 => 8

  • BTC: 30 - 8 - 2 => 20

  • USDC: 30 - 6 - 6 => 18

  • DG: 30 - 18 - 11 => 1

Funding Fees

资金费用

Funding fees incentivise the balancing of long and short positions, the side with the larger open interest pays a funding fee to the side with the smaller open interest.

资金费用激励多头和空头头寸的平衡,持仓量较大的一方向持仓量较小的一方支付资金费用。

Funding fees for the larger side is calculated as (funding factor per second) * (open interest imbalance) ^ (funding exponent factor) / (total open interest).

较大一方的资金费用计算公式为(每秒资金因子)*(做多仓位-做空仓位)^(资金指数因子)/(做多仓位 + 做空仓位)。

For example if the funding factor per second is 1 / 50,000, and the funding exponent factor is 1, and the long open interest is $150,000 and the short open interest is $50,000 then the funding fee per second for longs would be (1 / 50,000) * 100,000 / 200,000 => 0.00001 => 0.001%.

例如,如果每秒的融资因子为 1 / 50,000,融资指数因子为 1,多头持仓量为 150,000 美元,空头持仓量为 50,000 美元,则多头每秒的融资费用将为 (1 / 50,000) * 100,000 / 200,000 => 0.00001 => 0.001%。

The funding fee per second for shorts would be -0.00001 * 150,000 / 50,000 => 0.00003 => -0.003%.

空头每秒的资金费用为 -0.00001 * 150,000 / 50,000 => 0.00003 => -0.003%。

It is also possible to set a stableFundingFactor, this would result in the specified funding factor being used instead of the dynamic funding factor.

还可以设置稳定的资金因子,这将导致使用指定的资金因子而不是动态资金因子。

Borrowing Fees

借款费用

There is a borrowing fee paid to liquidity providers, this helps prevent users from opening both long and short positions to take up pool capacity without paying any fees.

向LP支付借款费用,这有助于防止用户在不支付任何费用的情况下开设多头和空头头寸以占用资金池容量。

Borrowing fees are calculated as borrowing factor * (open interest in usd + pending pnl) ^ (borrowing exponent factor) / (pool usd) for longs and borrowing factor * (open interest in usd) ^ (borrowing exponent factor) / (pool usd) for shorts.

借款费用的计算方式为:

做多:借款系数 *(美元仓位 + 未决盈亏)^(借款指数系数)/(资金池美元)

做空:借款系数 *(美元仓位)^(借款指数系数)/(资金池美元)

For example if the borrowing factor per second is 1 / 50,000, and the borrowing exponent factor is 1, and the long open interest is $150,000 with +$50,000 of pending pnl, and the pool has $250,000 worth of tokens, the borrowing fee per second for longs would be (1 / 50,000) * (150,000 + 50,000) / 250,000 => 0.000016 => 0.0016%.

例如,如果每秒借款系数为 1 / 50,000,借款指数系数为 1,多头未平仓利息为 150,000 美元,待处理盈亏 + 50,000 美元,并且池中有价值 250,000 美元的代币,则多头每秒的借款费用为 (1 / 50,000) * (150,000 + 50,000) / 250,000 => 0.000016 => 0.0016%。

There is also an option to set a skipBorrowingFeeForSmallerSide flag, this would result in the borrowing fee for the smaller side being set to zero. For example, if there are more longs than shorts and skipBorrowingFeeForSmallerSide is true, then the borrowing fee for shorts would be zero.

还有一个选项可以设置 SkipBorrowingFeeForSmallerSide 标志,这将导致较小一侧的借贷费用设置为零。例如,如果多头多于空头,并且skipBorrowingFeeForSmallerSide为真,则空头的借入费用将为零。

Price Impact

价格影响

The code for price impact can be found in the /pricing contracts.

价格影响的代码可以在 /pricing 合同中找到。

Price impact is calculated as:

(initial USD difference) ^ (price impact exponent) * (price impact factor) - (next USD difference) ^ (price impact exponent) * (price impact factor)

价格影响计算如下:

(初始美元差额)^(价格影响指数)*(价格影响因子)-(下一个美元差额)^(价格影响指数)*(价格影响因子)

For swaps, imbalance is calculated as the difference in the worth of the long tokens and short tokens.

对于现货交易,不平衡度计算为多头代币和空头代币的价值差异。

For example:

  • A pool has 10 long tokens, each long token is worth $5000

    一个池子有10个多头代币,每个多头代币价值5000美元

  • The pool also has 50,000 short tokens, each short token is worth $1

    该池还有 50,000 个空头代币,每个空头代币价值 1 美元

  • The price impact exponent is set to 2 and price impact factor is set to 0.01 / 50,000

    价格影响指数设置为 2,价格影响因子设置为 0.01 / 50,000

  • The pool is equally balanced with $50,000 of long tokens and $50,000 of short tokens

    该池中的多头代币和空头代币分别为 50,000 美元和 50,000 美元。

  • If a user deposits 10 long tokens, the pool would now have $100,000 of long tokens and $50,000 of short tokens

    如果用户存入 10 个多头代币,池中现在将有 100,000 美元的多头代币和 50,000 美元的空头代币

  • The change in imbalance would be from $0 to -$50,000

    不平衡的变化将从 0 美元到 -50,000 美元

  • There would be negative price impact charged on the user's deposit, calculated as 0 ^ 2 * (0.01 / 50,000) - 50,000 ^ 2 * (0.01 / 50,000) => -$500

    将对用户的押金产生负面价格影响,计算公式为 0 ^ 2 * (0.01 / 50,000) - 50,000 ^ 2 * (0.01 / 50,000) => -$500

  • If the user now withdraws 5 long tokens, the balance would change from -$50,000 to -$25,000, a net change of +$25,000

    如果用户现在提取 5 个多头代币,余额将从 -$50,000 变为 -$25,000,净变化 +$25,000

  • There would be a positive price impact rebated to the user in the form of additional long tokens, calculated as 50,000 ^ 2 * (0.01 / 50,000) - 25,000 ^ 2 * (0.01 / 50,000) => $375

    用户将以额外多头代币的形式回扣积极的价格影响,计算公式为 50,000 ^ 2 * (0.01 / 50,000) - 25,000 ^ 2 * (0.01 / 50,000) => 375 美元

For position actions (increase / decrease position), imbalance is calculated as the difference in the long and short open interest.

对于头寸操作(增加/减少头寸),不平衡计算为多头和空头未平仓合约的差额。

price impact exponents and price impact factors are configured per market and can differ for spot and position actions.

价格影响指数和价格影响因子是根据市场配置的,并且对于现货和头寸操作可能有所不同。

Note that this calculation is the price impact for a user's trade not the price impact on the pool. For example, a user's trade may have a 0.25% price impact, the next trade for a very small amount may have a 0.5% price impact.

请注意,此计算是对用户交易的价格影响,而不是对池的价格影响。例如,用户的交易可能会产生 0.25% 的价格影响,下一笔非常小的交易可能会产生 0.5% 的价格影响。

The purpose of the price impact is to:

价格影响的目的是:

  • Incentivise balance of tokens in pools

    激励池中的代币余额

  • Incentivise balance of longs / shorts

    激励多头/空头平衡

  • Reduce risk of price manipulation

    降低价格操纵风险

Since the contracts use an oracle price which would be an average or median price of multiple reference exchanges. Without a price impact, it may be profitable to manipulate the prices on reference exchanges while executing orders on the contracts.

由于合约使用预言机价格,该价格将是多个参考交易所的平均或中值价格。在没有价格影响的情况下,在执行合约订单时操纵参考交易所的价格可能会有利可图。

This risk will also be present if the positive and negative price impact values are similar, for that reason the positive price impact should be set to a low value in times of volatility or irregular price movements.

如果正面和负面价格影响值相似,也会存在这种风险,因此在波动或不规则价格变动时,正面价格影响应设置为较低值。

For the price impact on position increases / decreases, if negative price impact is deducted as collateral from the position, this could lead to the position having a different leverage from what the user intended, so instead of deducting collateral the position's entry / exit price is adjusted based on the price impact.

对于仓位增加/减少的价格影响,如果从仓位中扣除抵押品的负面价格影响,这可能会导致仓位的杠杆率与用户预期的不同,因此仓位的进场/出场价格不是扣除抵押品,而是根据价格影响进行调整。

For example:

  • The oracle price of the index token is $5000

    指数代币的预言机价格为 5000 美元

  • A user opens a long position of size $50,000 with a negative price impact of 0.1%

    用户开设了规模为 50,000 美元的多头头寸,对价格的负面影响为 0.1%

  • The user's position size is in USD is $50,000 and the size in tokens is (50,000 / 5000) * (100 - 0.1)% => 9.99

    用户的美元仓位大小为 50,000 美元,代币大小为 (50,000 / 5000) * (100 - 0.1)% => 9.99

  • This gives the position an entry price of 50,000 / 9.99 => ~$5005

    这使得该仓位的入场价格为 50,000 / 9.99 => ~$5005

  • The negative price impact is tracked as a number of index tokens in the pool

    负面价格影响通过池中的指数代币数量来追踪??todo 池中有 index tokens 吗

  • In this case there would be 0.01 index tokens in the position impact pool

    在这种情况下,头寸影响池中将有 0.01 个指数代币

  • The pending PnL of the user at this point would be (50,000 - 9.99 * 5000) => $50

    此时用户的待处理盈亏将为 (50,000 - 9.99 * 5000) => $50

  • The tokens in the position impact pool should be accounted for when calculating the pool value to offset this pending PnL

    在计算池值时应考虑头寸影响池中的代币,以抵消该待处理的盈亏

  • The net impact on the pool is zero, +$50 from the pending negative PnL due to price impact and -$50 from the 0.01 index tokens in the position impact pool worth $50

    对池的净影响为零,+50 美元来自因价格影响而产生的待决负盈亏,-50 美元来自头寸影响池中价值 50 美元的 0.01 个指数代币

  • If the user closes the position at a negative price impact of 0.2%, the position impact pool would increase to 0.03 index tokens

    如果用户以 0.2% 的负价格影响平仓,持仓影响池将增加至 0.03 个指数代币

  • The user would receive (original position collateral - $150)

    用户将收到(原始头寸抵押品 - 150 美元)

  • The pool would have an extra $150 of collateral which continues to have a net zero impact on the pool value due to the 0.03 index tokens in the position impact pool

    该池将有额外的 150 美元抵押品,由于头寸影响池中有 0.03 个指数代币,该抵押品继续对池价值产生净零影响

If the index token is different from both the long and short token of the market, then it is possible that the pool value becomes significantly affected by the position impact pool, if the position impact pool is very large and the index token has a large price increase. An option to gradually reduce the size of the position impact pool may be added if this becomes an issue.

如果指数代币与市场的多头和空头代币都不同,那么如果头寸影响池非常大且指数代币价格较大,则池子价值可能会受到头寸影响池的显着影响增加。如果这成为一个问题,可以添加逐渐减小头寸影响池大小的选项。

Price impact is also tracked using a virtual inventory value for positions and swaps, this tracks the imbalance of tokens across similar markets, e.g. ETH/USDC, ETH/USDT.

还使用头寸和现货的虚拟库存价值来跟踪价格影响,这跟踪了类似市场中代币的不平衡情况,例如ETH/USDC、ETH/USDT。

In case of a large price movement, it is possible that a large amount of positions are decreased or liquidated on one side causing a significant imbalance between long and short open interest, this could lead to very high price impact values. To mitigate this, a max position impact factor value can be configured. If the current price impact exceeds the max negative price impact, then any excess collateral deducted beyond the max negative price impact would be held within the contract, if there was no price manipulation detected, this collateral can be released to the user. When the negative price impact is capped, it may be profitable to open and immediately close positions, since the positive price impact may now be more than the capped negative price impact. To avoid this, the max positive price impact should be configured to be below the max negative price impact.

如果价格大幅波动,一侧可能会出现大量头寸减仓或平仓,导致多头和空头持仓量严重失衡,这可能会导致非常高的价格影响值。为了缓解这种情况,可以配置最大位置影响因子值。如果当前价格影响超过最大负价格影响,则扣除最大负价格影响之外的任何超额抵押品将保留在合约内,如果没有检测到价格操纵,则该抵押品可以释放给用户。当负面价格影响受到限制时,开仓并立即平仓可能会有利可图,因为正面价格影响现在可能超过受限制的负面价格影响。为了避免这种情况,最大正价格影响应配置为低于最大负价格影响。

Fees

There are configurable swap fees and position fees and per market.

每个市场都有可配置的现货费用和杠杠费用。

Execution fees are also estimated and accounted for on creation of deposit, withdrawal, order requests so that keepers can execute transactions at a close to net zero cost.

执行费用也会在创建存款、取款、订单请求时进行估算和核算,以便keepers能够以接近零成本的方式执行交易。

Reserve Amounts

储备金额

If a market has stablecoins as the short collateral token it should be able to fully pay short profits if the max short open interest does not exceed the amount of stablecoins in the pool.

如果市场以稳定币作为空头抵押代币,且最大空头持仓量不超过池中稳定币的数量,则该市场应该能够全额支付空头利润。

If a market has a long collateral token that is different from the index token, the long profits may not be fully paid out if the price increase of the index token exceeds the price increase of the long collateral token.

如果市场存在与指数代币不同的多头抵押代币,如果指数代币的价格涨幅超过多头抵押品代币的价格涨幅,则多头利润可能无法完全支付。

Markets have a reserve factor that allows open interest to be capped to a percentage of the pool size, this reduces the impact of profits of short positions and reduces the risk that long positions cannot be fully paid out.

市场有一个准备金系数,允许未平仓头寸限制在资金池规模的一定百分比,这减少了空头头寸利润的影响,并降低了多头头寸无法完全支付的风险。

Parameters

参数

  • minCollateralFactor: This determines the minimum allowed ratio of (position collateral) / (position size)

    minCollat​​eralFactor:这决定了(头寸抵押品)/(头寸规模)的最小允许比率

  • maxPoolAmount: The maximum amount of tokens that can be deposited into a market

    maxPoolAmount:可以存入市场的最大代币数量

  • maxOpenInterest: The maximum open interest that can be opened for a market

    maxOpenInterest:市场可开仓的最大持仓量

  • reserveFactor: This determines the maximum allowed ratio of (worth of tokens reserved for positions) / (tokens in the pool)

    ReserveFactor:这决定了(为头寸保留的代币价值)/(池中的代币)的最大允许比率

  • maxPnlFactor: The maximum ratio of (PnL / worth of tokens in the pool)

    maxPnlFactor:(PnL / 池中代币价值)的最大比率

  • positionFeeFactor: This determines the percentage amount of fees to be deducted for position increase / decrease actions, the fee amount is based on the change in position size

    positionFeeFactor:决定增仓/减仓操作要扣除的费用百分比,费用金额根据仓位大小的变化而定

  • positionImpactFactor: This is the "price impact factor" for positions described in the "Price Impact" section

    positionImpactFactor:这是“价格影响”部分中描述的仓位的“价格影响因子”

  • maxPositionImpactFactor: This is the "max price impact" for positions described in the "Price Impact" section

    maxPositionImpactFactor:这是“价格影响”部分中描述的仓位的“最大价格影响”

  • positionImpactExponentFactor: This is the "price impact exponent" value for position actions, described in the "Price Impact" section

    positionImpactExponentFactor:这是仓位操作的“价格影响指数”值,如“价格影响”部分所述

  • swapFeeFactor: This determines the percentage amount of fees to be deducted for swaps, the fee amount is based on the swap amount

    swapFeeFactor:决定掉期要扣除的费用百分比,费用金额基于掉期金额

  • swapImpactFactor: This is the "price impact factor" described in the "Price Impact" section

    swapImpactFactor:这是“价格影响”部分中描述的“价格影响因子”

  • swapImpactExponentFactor: This is the "price impact exponent" value for deposits and swaps, described in the "Price Impact" section above

    swapImpactExponentFactor:这是存款和现货的“价格影响指数”值,如上面的“价格影响”部分所述

  • fundingFactor: This is the "funding factor per second" value described in the "Funding Fees" section

    fundingFactor:这是“资金费用”部分中描述的“每秒资金因素”值

  • borrowingFactorForLongs: This is the "borrowing factor" for long positions described in the "Borrowing Fees" section

    BorrowingFactorForLongs:这是“借款费用”部分中描述的多头头寸的“借款系数”

  • borrowingFactorForShorts: This is the "borrowing factor" for short positions described in the "Borrowing Fees" section

    BorrowingFactorForShorts:这是“借入费用”部分中描述的空头头寸的“借入系数”

  • borrowingExponentFactorForLongs: This is the "borrowing exponent factor" for long positions described in the "Borrowing Fees" section

    BorrowingExponentFactorForLongs:这是“借款费用”部分中描述的多头头寸的“借款指数因子”

  • borrowingExponentFactorForShorts: This is the "borrowing exponent factor" for long positions described in the "Borrowing Fees" section

    BorrowingExponentFactorForShorts:这是“借款费用”部分中描述的多头头寸的“借款指数因子”

Roles

角色

Roles are managed in the RoleStore, the RoleAdmin has access to grant and revoke any role.

角色在 RoleStore 中进行管理,RoleAdmin 有权授予和撤销任何角色。

The RoleAdmin will be the deployer initially, but this should be removed after roles have been setup.

RoleAdmin 最初将是部署者,但在角色设置后应将其删除。

After the initial setup:

初始设置后:

  • Only the Timelock contract should have the RoleAdmin role

    只有 Timelock 合约才应具有 RoleAdmin 角色

  • New roles can be granted by timelock admins with a time delay

    timelock管理员可以延迟授予新角色

  • System values should only be set using the Config contract

    系统值只能使用 Config 合约设置

  • No EOA should have a Controller role

    EOA 不应具有控制者角色

  • Config keepers and timelock admins could potentially disrupt regular operation through the disabling of features, incorrect setting of values, whitelisting malicious tokens, abusing the positive price impact value, etc

    配置管理员和时间锁管理员可能会通过禁用功能、错误设置值、将恶意代币列入白名单、滥用积极的价格影响值等来扰乱正常操作

  • It is expected that the timelock multisig should revoke the permissions of malicious or compromised accounts

    预计timelock多重签名应撤销恶意或受损帐户的权限

  • Order keepers and frozen order keepers could potentially extract value through transaction ordering, delayed transaction execution, ADL execution, etc, this will be partially mitigated with a keeper network

    订单守护者和冻结订单守护者可能通过交易排序、延迟交易执行、ADL 执行等来获取价值,这将通过守护者网络部分缓解

  • Oracle signers are expected to accurately report the price of tokens

    Oracle signers应准确报告代币的价格

Known Issues

已知的问题

  • Collateral tokens need to be whitelisted with a configured TOKEN_TRANSFER_GAS_LIMIT

    抵押代币需要通过配置的 TOKEN_TRANSFER_GAS_LIMIT 列入白名单

  • Rebasing tokens, tokens that change balance on transfer, with token burns, tokens with callbacks e.g. ERC-777 tokens, etc, are not compatible with the system and should not be whitelisted

    代币变基、改变转账余额的代币、代币销毁、带有回调的代币,例如ERC-777代币等与系统不兼容,不应列入白名单

  • Order keepers can use prices from different blocks for limit orders with a swap, which would lead to different output amounts

    Order keepers可以使用不同区块的价格进行具有掉期的限价订单,这将导致不同的输出金额

  • Order keepers are expected to validate whether a transaction will revert before sending the transaction to minimize gas wastage

    Order keepers应在发送交易之前验证交易是否会恢复,以最大程度地减少天然气浪费

  • Order keepers may cause requests to be cancelled instead of executed by executing the request with insufficient gas

    Order keepers可能会通过在 Gas 不足的情况下执行请求来导致请求被取消而不是执行

  • A user can reduce price impact by using high leverage positions, this is partially mitigated with the MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER value

    用户可以通过使用高杠杆头寸来减少价格影响,这可以通过 MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER 值部分缓解

  • Price impact can be reduced by using positions and swaps and trading across markets, chains, forks, other protocols, this is partially mitigated with virtual inventory tracking

    通过使用头寸和现货以及跨市场、链、分叉、其他协议的交易可以减少价格影响,虚拟库存跟踪可以部分缓解这一影响

  • Virtual IDs must be set before market creation / token whitelisting, if it is set after trading for the token / market is done, the tracking would not be accurate and may need to be adjusted

    虚拟ID必须在市场创建/代币白名单之前设置,如果在代币/市场交易完成后设置,跟踪将不准确,可能需要调整

  • If an execution transaction requires a large amount of gas that may be close to the maximum block gas limit, it may be possible to stuff blocks to prevent the transaction from being included in blocks

    如果执行交易需要大量的gas,可能接近最大区块gas限制,则可能会填充区块以防止交易被包含在区块中

  • In certain blockchains it is possible for the keeper to have control over the tx.gasprice used to execute a transaction which would affect the execution fee paid to the keeper

    在某些区块链中,守护者可以控制用于执行交易的 tx.gasprice,这将影响支付给守护者的执行费用

  • For L2s with sequencers, there is no contract validation to check if the L2 sequencer is active, oracle keepers should stop signing prices if no blocks are being created by the sequencer, if the sequencer resumes regular operation, the oracle keepers should sign prices for the latest blocks using the latest fetched prices

    对于带有定序器的 L2,没有合约验证来检查 L2 定序器是否处于活动状态,如果定序器没有创建区块,则预言机管理员应停止签署价格;如果定序器恢复正常运行,则预言机管理员应为使用最新获取价格的最新区块

  • In case an L2 sequencer is down, it may prevent deposits into positions to prevent liquidations

    如果 L2 定序器出现故障,它可能会阻止存款入仓以防止清算

  • For transactions that can be executed entirely using on-chain price feeds, it may be possible to take advantage of stale pricing due to price latency or the chain being down, usage of on-chain price feeds should be temporary and low latency feeds should be used instead once all tokens are supported

    对于可以完全使用链上价格源执行的交易,由于价格延迟或链关闭,可能可以利用过时的定价,链上价格源的使用应该是临时的,并且应该使用低延迟源一旦支持所有令牌,即可使用

  • Orders may be prevented from execution by a malicious user intentionally causing a market to be unbalanced resulting in a high price impact, this should be costly and difficult to benefit from

    恶意用户可能会故意阻止订单执行,导致市场不平衡,从而导致高价格影响,这应该是成本高昂且难以受益的

  • Block re-orgs could allow a user to retroactively cancel an order after it has been executed if price did not move favourably for the user, care should be taken to handle this case if using the contracts on chains where long re-orgs are possible

    如果价格走势对用户不利,则区块重组可以允许用户在订单执行后追溯取消订单,如果在可能进行长期重组的链上使用合约,则应注意处理这种情况

  • Updating and cancellation of orders could be front-run to prevent order execution, this should not be an issue if the probability of a successful front-running is less than or equal to 50%, if the probability is higher than 50%, fees and price impact should be adjusted to ensure that the strategy is not net profitable, adjusting the ui fee or referral discount could similarly be used to cause order cancellations

    更新和取消订单可以提前运行以防止订单执行,如果成功提前运行的概率小于或等于 50%,这应该不是问题,如果概率高于 50%,则费用和应调整价格影响以确保该策略不会实现净利润,调整 UI 费用或推荐折扣同样可用于导致订单取消

  • Decrease position orders could output two tokens instead of a single token, in case the decrease position swap fails, it is also possible that the output amount and collateral may not be sufficient to cover fees, causing the order to not be executed

    平仓订单可以输出两个代币而不是单个代币,如果减仓互换失败,也有可能输出金额和抵押品不足以支付费用,导致订单无法执行

  • If there is a large spread, it is possible that opening / closing a position can significantly change the min and max price of the market token, this should not be manipulatable in a profitable way

    如果价差较大,开仓/平仓可能会显着改变市场代币的最低和最高价格,这不应该以有利可图的方式进行操纵

  • Changes in config values such as FUNDING_FACTOR, STABLE_FUNDING_FACTOR, BORROWING_FACTOR, SKIP_BORROWING_FEE_FOR_SMALLER_SIDE, BORROWING_FEE_RECEIVER_FACTOR, could lead to additional charges for users, it could also result in a change in the price of market tokens

    FUNDING_FACTOR、STABLE_FUNDING_FACTOR、BORROWING_FACTOR、SKIP_BORROWING_FEE_FOR_SMALLER_SIDE、BORROWING_FEE_RECEIVER_FACTOR等配置值的更改可能会导致用户产生额外费用,也可能导致市场代币价格发生变化

  • Calculation of price impact values do not account for fees and the effects resulting from the price impact itself, for most cases the effect on the price impact calculation should be small

    价格影响值的计算不考虑费用以及价格影响本身产生的影响,在大多数情况下,对价格影响计算的影响应该很小

  • If trader PnL is capped, positions that are closed earlier may receive a lower PnL ratio compared to positions that are closed later

    如果交易者盈亏受到限制,则较早平仓的头寸可能会比较晚平仓的头寸获得更低的盈亏比率

  • Due to the difference in positive and negative position price impact, there can be a build up of virtual token amounts in the position impact pool which would affect the pricing of market tokens, the feature to gradually reduce these virtual tokens should be added if needed

    由于正负持仓价格影响的差异,持仓影响池中的虚拟代币数量可能会增加,从而影响市场代币的定价,如有需要,应添加逐步减少这些虚拟代币的功能

  • Contracts with the "CONTROLLER" role have access to important functions such as setting DataStore values, due to this, care should be taken to ensure that such contracts do not have generic functions or functions that can be intentionally used to change important values

    具有“CONTROLLER”角色的合约可以访问重要功能,例如设置DataStore值,因此,应注意确保此类合约不具有通用功能或可故意用于更改重要值的功能

  • If new contracts are added that may lead to a difference in pricing, e.g. of market tokens between the old and new contracts, then care should be taken to disable the old contracts before the new contracts are enabled

    如果添加新合同,可能会导致定价差异,例如新旧合约之间的市场代币数量,则应注意在启用新合约之前禁用旧合约

  • If the contracts are used to support equity synthetic markets, care should be taken to ensure that stock splits and similar changes can be handled

    如果合约用于支持股权合成市场,应注意确保可以处理股票分割和类似的变化

Feature Development

For the development of new features, a few things should be noted:

对于新功能的开发,需要注意以下几点:

  • tests should be added for the different market types, e.g. spot only markets, single token markets

    应针对不同的市场类型添加测试,例如仅限现货市场、单一代币市场

  • the ordering of values in the eventData for callbacks should not be modified unless strictly necessary, since callback contracts may reference the values by a fixed index

    除非绝对必要,否则不应修改回调的 eventData 中的值的顺序,因为回调合约可能通过固定索引引用这些值

Commands

To compile contracts:

npx hardhat compile

To run all tests:

npx hardhat test

To print code metrics:

npx ts-node metrics.ts

To print test coverage:

npx hardhat coverage
Subscribe to 大头菜不菜
Receive the latest updates directly to your inbox.
Nft graphic
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from 大头菜不菜

Skeleton

Skeleton

Skeleton