Skip to content

Types

Enums are written the way NEAR contracts usually write them in JSON: a variant without fields is a string ("OutputOfLastIn"), a variant with fields is an object with one key ({ "ExactIn": "1000" }). Optional fields can be null or left out.

Type Format Example
U128 Integer string, in the asset’s smallest unit "1000000000000000000000000"
AccountId NEAR account ID "alice.near"
Base64 Base64 string of bytes "AQIDBA=="

A string:

Format Asset
near Native NEAR
nep141:<contract> NEP-141 fungible token, for example nep141:usdt.tether-token.near
nep171:<contract>:<token id> NEP-171 NFT. Its balance is "0" or "1"
nep245:<contract>:<token id> NEP-245 multi token

These are the same IDs the DEX Aggregator uses after intear-dex:.

A string, <deployer>/<name>, for example "slimedragon.near/xyk".

An owner of inner balances:

{ "Account": "alice.near" }
{ "Dex": "slimedragon.near/xyk" }
Value Meaning
{ "ExactIn": "<U128>" } Pay exactly this much asset_in
{ "ExactOut": "<U128>" } Receive exactly this much asset_out

The amount of a SwapSimple operation:

Value Meaning
{ "Amount": SwapRequestAmount } A fixed amount, for example { "Amount": { "ExactIn": "1000" } }
"OutputOfLastIn" Exact input of the output of the last SwapSimple in the list. Its asset_out must match this asset_in
"EntireBalanceIn" Exact input of everything available of asset_in

The amount of the withdraw method:

Value Meaning
{ "Exact": "<U128>" } A fixed amount
{ "Full": { "at_least": "<U128>" | null } } The whole balance. Fails if it’s less than at_least

The amount of a Withdraw operation: the same as DirectWithdrawAmount, plus:

Value Meaning
"PreviousSwapOutput" The output of the last SwapSimple in the list. Its asset_out must match this asset_id

One step of execute_operations or of a deposit message.

{
"SwapSimple": {
"dex_id": "slimedragon.near/xyk",
"message": "<base64>",
"asset_in": "near",
"asset_out": "nep141:usdt.tether-token.near",
"amount": "EntireBalanceIn",
"constraint": "4800000"
}
}
Operation Fields What it does
SwapSimple dex_id: DexId, message: Base64, asset_in: AssetId, asset_out: AssetId, amount: SwapOperationAmount, constraint?: U128 A swap. constraint is the minimum output for an exact input, or the maximum input for an exact output
Withdraw asset_id: AssetId, amount: WithdrawAmount, to?: AccountId, rescue_address?: AccountId Sends the asset to to (default: you). rescue_address is only used in deposit messages, see Withdrawing from a deposit
TransferAsset to: AccountOrDexId, asset_id: AssetId, amount: U128 Moves the asset to another inner balance
DexCall dex_id: DexId, method: string, args: Base64, attached_assets: { [AssetId]: U128 } Calls a DEX method
StorageDeposit amount: U128, for: AccountOrDexId Turns NEAR into a storage balance of for. At least 0.005 NEAR. for is required
RegisterAssets asset_ids: AssetId[], for?: AccountOrDexId Registers assets. Only in execute_operations
DeployDexCode last_part_of_id: string, code_base64: Base64 Deploys DEX code. Only in execute_operations

The msg of a token transfer to the engine, as a JSON string, or operations of deposit_near. Either a list of operations:

[{ "SwapSimple": { ... } }, { "Withdraw": { ... } }]

or an object with a referrer:

{ "operations": [{ "SwapSimple": { ... } }], "referrer": "myapp.near" }
{ "total": "10000000000000000000000", "available": "9000000000000000000000" }

total is everything deposited, available is the part not used for storage yet. Both in yoctoNEAR.

DEXs read and write Borsh, so DEX messages, arguments, responses and dex_events_borsh are Borsh. In Borsh:

  • AssetId is an enum: Near (0), Nep141(AccountId) (1), Nep245(AccountId, String) (2), Nep171(AccountId, String) (3).
  • DexId is a struct of deployer: AccountId and id: String.
  • AccountId is a string.

In Rust, these types and the request and response types of DEXs are in the intear-dex-types crate.