Skip to content

Latest commit

 

History

History
778 lines (517 loc) · 19 KB

README.md

File metadata and controls

778 lines (517 loc) · 19 KB

🧰 Functions

⚙️ calcTakingAmount

Calculates taker amount by linear proportion

Function Type
calcTakingAmount (swapMakerAmount: bigint, orderMakerAmount: bigint, orderTakerAmount: bigint) => bigint

⚙️ calMakingAmount

Calculates maker amount by linear proportion

Function Type
calMakingAmount (swapTakerAmount: bigint, orderMakerAmount: bigint, orderTakerAmount: bigint) => bigint

🏭 Extension

Methods

⚙️ decode

Method Type
decode (bytes: string) => Extension

⚙️ default

Method Type
default () => Extension

⚙️ keccak256

Method Type
keccak256 () => bigint

⚙️ isEmpty

Method Type
isEmpty () => boolean

⚙️ encode

Hex string with 0x

Method Type
encode () => string

🏭 Interaction

Methods

⚙️ encode

Hex string with 0x. First 20 bytes are target, then data

Method Type
encode () => string

🏭 ExtensionBuilder

Methods

⚙️ withMakerAssetSuffix

Method Type
withMakerAssetSuffix (suffix: string) => this

⚙️ withTakerAssetSuffix

Method Type
withTakerAssetSuffix (suffix: string) => this

⚙️ withMakingAmountData

Method Type
withMakingAmountData (address: Address, data: string) => this

Parameters:

  • address: Address of contract which will be called with data to calculate making amount

⚙️ withTakingAmountData

Method Type
withTakingAmountData (address: Address, data: string) => this

Parameters:

  • address: Address of contract which will be called with data to calculate taking amount

⚙️ withPredicate

Method Type
withPredicate (predicate: string) => this

⚙️ withMakerPermit

Method Type
withMakerPermit (tokenFrom: Address, permitData: string) => this

⚙️ withPreInteraction

Method Type
withPreInteraction (interaction: Interaction) => this

⚙️ withPostInteraction

Method Type
withPostInteraction (interaction: Interaction) => this

⚙️ withCustomData

Method Type
withCustomData (data: string) => this

⚙️ build

Method Type
build () => Extension

🏭 MakerTraits

The MakerTraits type is an uint256, and different parts of the number are used to encode different traits. High bits are used for flags 255 bit NO_PARTIAL_FILLS_FLAG - if set, the order does not allow partial fills 254 bit ALLOW_MULTIPLE_FILLS_FLAG - if set, the order permits multiple fills 253 bit - unused 252 bit PRE_INTERACTION_CALL_FLAG - if set, the order requires pre-interaction call 251 bit POST_INTERACTION_CALL_FLAG - if set, the order requires post-interaction call 250 bit NEED_CHECK_EPOCH_MANAGER_FLAG - if set, the order requires to check the epoch manager 249 bit HAS_EXTENSION_FLAG - if set, the order has extension(s) 248 bit USE_PERMIT2_FLAG - if set, the order uses permit2 247 bit UNWRAP_WETH_FLAG - if set, the order requires to unwrap WETH

Low 200 bits are used for allowed sender, expiration, nonceOrEpoch, and series uint80 last 10 bytes of allowed sender address (0 if any) uint40 expiration timestamp (0 if none) uint40 nonce or epoch uint40 series

Methods

⚙️ default

Method Type
default () => MakerTraits

⚙️ allowedSender

Last 10bytes of address

Method Type
allowedSender () => string

⚙️ isPrivate

Method Type
isPrivate () => boolean

⚙️ withAllowedSender

Method Type
withAllowedSender (sender: Address) => this

⚙️ withAnySender

Removes sender check on contract

Method Type
withAnySender () => this

⚙️ expiration

If null is return than order has no expiration

Method Type
expiration () => bigint

⚙️ withExpiration

Set order expiration time

Method Type
withExpiration (expiration: bigint) => this

Parameters:

  • expiration: expiration timestamp in sec

⚙️ nonceOrEpoch

Returns epoch in case isEpochManagerEnabled() and nonce otherwise

Method Type
nonceOrEpoch () => bigint

⚙️ withNonce

Set nonce Note: nonce and epoch share the same field, so they cant be set together

Method Type
withNonce (nonce: bigint) => this

⚙️ withEpoch

Enable epoch manager check

If set, the contract will check that order epoch equals to epoch on SeriesEpochManager contract Note: epoch manager can be used only when partialFills AND multipleFills allowed Note: nonce and epoch share the same field, so they cant be set together

Method Type
withEpoch (series: bigint, epoch: bigint) => this

Parameters:

  • series: subgroup for epoch
  • epoch: unique order id inside series

⚙️ series

Get current series

Method Type
series () => bigint

⚙️ hasExtension

Returns true if order has an extension and false otherwise

Method Type
hasExtension () => boolean

⚙️ withExtension

Mark that order has an extension

Method Type
withExtension () => this

⚙️ isPartialFillAllowed

Is partial fills allowed for order

Method Type
isPartialFillAllowed () => boolean

⚙️ disablePartialFills

Disable partial fills for order

Method Type
disablePartialFills () => this

⚙️ allowPartialFills

Allow partial fills for order

Method Type
allowPartialFills () => this

⚙️ setPartialFills

Set partial fill flag to passed value

Method Type
setPartialFills (val: boolean) => this

⚙️ isMultipleFillsAllowed

Returns true if order allowing more than one fill and false otherwise

Method Type
isMultipleFillsAllowed () => boolean

⚙️ allowMultipleFills

Allow many fills for order

Method Type
allowMultipleFills () => this

⚙️ disableMultipleFills

Allow at max 1 fill for order

Method Type
disableMultipleFills () => this

⚙️ setMultipleFills

If val is true, then multiple fills allowed, otherwise disallowed

Method Type
setMultipleFills (val: boolean) => this

⚙️ hasPreInteraction

Returns true if maker has pre-interaction and false otherwise

Method Type
hasPreInteraction () => boolean

⚙️ enablePreInteraction

Enable maker pre-interaction

Method Type
enablePreInteraction () => this

⚙️ disablePreInteraction

Disable maker pre-interaction

Method Type
disablePreInteraction () => this

⚙️ hasPostInteraction

Returns true if maker has post-interaction and false otherwise

Method Type
hasPostInteraction () => boolean

⚙️ enablePostInteraction

Enable maker post-interaction

Method Type
enablePostInteraction () => this

⚙️ disablePostInteraction

Disable maker post-interaction

Method Type
disablePostInteraction () => this

⚙️ isEpochManagerEnabled

Returns true if epoch manager enabled

Method Type
isEpochManagerEnabled () => boolean

⚙️ isPermit2

Returns true if permit2 enabled for maker funds transfer

Method Type
isPermit2 () => boolean

⚙️ enablePermit2

Use permit2 to transfer maker funds to contract

Method Type
enablePermit2 () => this

⚙️ disablePermit2

Do not use permit2 to transfer maker funds to contract

Method Type
disablePermit2 () => this

⚙️ isNativeUnwrapEnabled

Is WRAPPED token will be unwrapped to NATIVE before sending to maker

Method Type
isNativeUnwrapEnabled () => boolean

⚙️ enableNativeUnwrap

Unwrap WRAPPED token to NATIVE before sending it to maker

Method Type
enableNativeUnwrap () => this

⚙️ disableNativeUnwrap

Do not unwrap WRAPPED token to NATIVE before sending it to maker

Method Type
disableNativeUnwrap () => this

⚙️ asBigInt

Method Type
asBigInt () => bigint

⚙️ isBitInvalidatorMode

Returns true if bit invalidator mode is used to invalidate order (cancel/mark as filled)

Bit invalidator is cheaper in terms of gas, but can be used only when partial fills OR multiple fills are disabled

Method Type
isBitInvalidatorMode () => boolean

🏭 LimitOrder

Methods

⚙️ buildSalt

Build correct salt for order

If order has extension - it is crucial to build correct salt otherwise order won't be ever filled

Method Type
buildSalt (extension: Extension, baseSalt?: bigint) => bigint

⚙️ fromCalldata

Method Type
fromCalldata (bytes: string) => LimitOrder

⚙️ toCalldata

Method Type
toCalldata () => string

⚙️ build

Method Type
build () => LimitOrderV4Struct

⚙️ getTypedData

Method Type
getTypedData (chainId: number) => EIP712TypedData

⚙️ getOrderHash

Method Type
getOrderHash (chainId: number) => string

⚙️ isPrivate

Returns true if only a specific address can fill order

Method Type
isPrivate () => boolean

🏭 TakerTraits

TakerTraitsLib This class defines TakerTraits, which are used to encode the taker's preferences for an order in a single uint256.

The TakerTraits are structured as follows: High bits are used for flags 255 bit _MAKER_AMOUNT_FLAG - If set, the taking amount is calculated based on making amount, otherwise making amount is calculated based on taking amount. 254 bit _UNWRAP_WETH_FLAG - If set, the WETH will be unwrapped into ETH before sending to taker. 253 bit _SKIP_ORDER_PERMIT_FLAG - If set, the order skips maker's permit execution. 252 bit _USE_PERMIT2_FLAG - If set, the order uses the permit2 function for authorization. 251 bit _ARGS_HAS_TARGET - If set, then first 20 bytes of args are treated as receiver address for maker’s funds transfer. 224-247 bits ARGS_EXTENSION_LENGTH - The length of the extension calldata in the args. 200-223 bits ARGS_INTERACTION_LENGTH - The length of the interaction calldata in the args. 0-184 bits - The threshold amount (the maximum amount a taker agrees to give in exchange for a making amount).

Methods

⚙️ default

Method Type
default () => TakerTraits

⚙️ getAmountMode

Returns enabled amount mode, it defines how to treat passed amount in fillContractOrderArgs function

Method Type
getAmountMode () => AmountMode

⚙️ setAmountMode

Method Type
setAmountMode (mode: AmountMode) => this

⚙️ isNativeUnwrapEnabled

Is the Wrapped native currency will be unwrapped into Native currency before sending to taker

Method Type
isNativeUnwrapEnabled () => boolean

⚙️ enableNativeUnwrap

Wrapped native currency will be unwrapped into Native currency before sending to taker

Method Type
enableNativeUnwrap () => this

⚙️ disableNativeUnwrap

Wrapped native currency will NOT be unwrapped into Native currency before sending to taker

Method Type
disableNativeUnwrap () => this

⚙️ isOrderPermitSkipped

If true, then maker's permit execution is skipped

Method Type
isOrderPermitSkipped () => boolean

⚙️ skipOrderPermit

The order skips maker's permit execution

Method Type
skipOrderPermit () => this

⚙️ isPermit2Enabled

Should use permit2 function for authorization or not

Method Type
isPermit2Enabled () => boolean

⚙️ enablePermit2

Use permit2 function for authorization

Method Type
enablePermit2 () => this

⚙️ disablePermit2

NOT use permit2 function for authorization

Method Type
disablePermit2 () => this

⚙️ setReceiver

Sets address where order filled to, msg.sender used if not set

Method Type
setReceiver (receiver: Address) => this

⚙️ removeReceiver

Set order receiver as msg.sender

Method Type
removeReceiver () => this

⚙️ setExtension

Sets extension, it is required to provide same extension as in order creation (if any)

Method Type
setExtension (ext: Extension) => this

⚙️ removeExtension

Method Type
removeExtension () => this

⚙️ setAmountThreshold

Set threshold amount

In taker amount mode: the minimum amount a taker agrees to receive in exchange for a taking amount. In maker amount mode: the maximum amount a taker agrees to give in exchange for a making amount.

Method Type
setAmountThreshold (threshold: bigint) => this

⚙️ removeAmountThreshold

Method Type
removeAmountThreshold () => this

⚙️ setInteraction

Sets taker interaction

interaction.target should implement ITakerInteraction interface

Method Type
setInteraction (interaction: Interaction) => this

⚙️ removeInteraction

Method Type
removeInteraction () => this

⚙️ encode

Method Type
encode () => { trait: bigint; args: string; }