# Methods

> Every method of the Intear DEX engine contract (dex.intear.near): arguments, attached deposit, return values, and who can call it.

This page is part of the Intear DEX docs. Intear DEX is the `dex.intear.near` contract. https://docs.intear.tech/intear-dex/llms-full.txt has all of its pages in one file, and https://docs.intear.tech/llms.txt lists every page of the Intear docs.

All methods are on `dex.intear.near`, with JSON arguments. Types like `AssetId` and `AccountOrDexId` are described in [Types](https://docs.intear.tech/intear-dex/reference/types.md). Amounts (`U128`) are integer strings.

Methods marked **1 yocto** need exactly 1 yoctoNEAR attached, which also means they must be signed with a full access key.

When the contract is [paused](#pause), every change method fails with `Contract is paused`, and so does `simulate_swap_simple`. `pause`, `unpause` and `set_trusted_code_deployer` still work, and so do views and the callbacks of withdrawals. [`rescue`](#rescue) works only while paused, and `storage_unregister` always fails with its own message.

## Change methods

### Balances

| Method | Deposit | Arguments | Returns |
| --- | --- | --- | --- |
| `register_assets` | 1 yocto | `asset_ids: AssetId[]`, `for?: AccountOrDexId` | nothing |
| `deposit_near` | The NEAR to deposit | `operations?: DepositMessage` | nothing |
| `transfer_asset` | 1 yocto | `to: AccountOrDexId`, `asset_id: AssetId`, `amount: U128` | nothing |
| `withdraw` | 1 yocto | `asset_id: AssetId`, `amount: DirectWithdrawAmount`, `withdraw_to?: AccountId` | `bool` |

- `register_assets`: registers assets for `for` (default: the caller), paid from the caller's storage balance. See [Register assets](https://docs.intear.tech/intear-dex/guides/inner-balances.md#register-assets).
- `deposit_near`: without `operations`, adds the attached NEAR to the caller's inner balance. With `operations`, runs them on the attached NEAR. See [Operations in a deposit](https://docs.intear.tech/intear-dex/guides/operations.md#operations-in-a-deposit).
- `transfer_asset`: moves assets from the caller's inner balance to another inner balance. A transfer of 0 does nothing.
- `withdraw`: sends assets out of the engine. Returns `true` if the transfer succeeded, `false` if it failed and the assets were refunded to an inner balance. A withdrawal of 0, such as `Full` of an empty balance, returns `true` without a transfer. See [Withdraw](https://docs.intear.tech/intear-dex/guides/inner-balances.md#withdraw).

### Swaps and DEX calls

| Method | Deposit | Arguments | Returns |
| --- | --- | --- | --- |
| `swap_simple` | 1 yocto | `dex_id: DexId`, `message: Base64`, `asset_in: AssetId`, `asset_out: AssetId`, `amount: SwapRequestAmount`, `referrer?: AccountId`, `referral_fees?: ReferralFees`, `constraint?: U128` | `[amount_in, amount_out]` |
| `dex_call` | 1 yocto | `dex_id: DexId`, `method: string`, `args: Base64`, `attached_assets: { [AssetId]: U128 }`, `referrer?: AccountId` | `Base64` |
| `execute_operations` | At least 1 yocto | `operations: Operation[]`, `referrer?: AccountId`, `referral_fees?: ReferralFees` | nothing |

- `swap_simple`: see [Swaps](https://docs.intear.tech/intear-dex/guides/swaps.md). `referral_fees` are the [referral fees](https://docs.intear.tech/intear-dex/guides/referral-fees.md) the swap pays out of its input, and `amount_in` includes them.
- `dex_call`: see [Calling a DEX](https://docs.intear.tech/intear-dex/guides/dexes.md#calling-a-dex).
- `execute_operations`: if more than 1 yoctoNEAR is attached, the whole deposit is added to the caller's NEAR inner balance first. `referral_fees` are paid by the first swap only. See [Operations](https://docs.intear.tech/intear-dex/guides/operations.md).

### Token receivers

Token contracts call these when you transfer tokens to `dex.intear.near` with `*_transfer_call`. Don't call them yourself.

| Method | Standard | `msg` |
| --- | --- | --- |
| `ft_on_transfer` | NEP-141 | `""` or a JSON `DepositMessage` |
| `nft_on_transfer` | NEP-171 | `""` or a JSON `DepositMessage` |
| `mt_on_transfer` | NEP-245 | `""` or a JSON `DepositMessage` |

With an empty `msg` the tokens go to the owner's inner balance: `sender_id` for NEP-141, `previous_owner_id` for NFTs, and each of `previous_owner_ids` for multi tokens. Otherwise the operations in `msg` run on them. The engine keeps all tokens it accepts, and fails the call (so the token contract refunds them) if anything goes wrong.

### Storage

| Method | Deposit | Arguments | Returns |
| --- | --- | --- | --- |
| `storage_deposit` | At least 0.005 NEAR | `account_id?: AccountId`, `registration_only?: bool` | `StorageBalance` |
| `storage_withdraw` | 1 yocto | `amount?: U128` | `StorageBalance` |
| `storage_unregister` | 1 yocto | `force?: bool` | Always fails: not supported |
| `dex_storage_deposit` | At least 0.005 NEAR | `dex_id: DexId`, `registration_only?: bool` | `StorageBalance` |
| `dex_storage_withdraw` | 1 yocto | `dex_id: DexId`, `amount?: U128` | `StorageBalance`. Only the DEX's deployer can call it |

See [Storage](https://docs.intear.tech/intear-dex/guides/storage.md).

### DEX code

| Method | Deposit | Arguments | Returns |
| --- | --- | --- | --- |
| `deploy_dex_code` | 1 yocto | `last_part_of_id: string`, `code_base64: Base64` | nothing |
| `set_trusted_code_deployer` | 1 yocto | `account_id: AccountId` | nothing |

- `deploy_dex_code`: deploys or upgrades the DEX `<caller>/<last_part_of_id>`. Only the trusted code deployer can call it. See [Deploying](https://docs.intear.tech/intear-dex/guides/dexes.md#deploying).
- `set_trusted_code_deployer`: hands the permission to deploy DEX code to another account. Only the current trusted code deployer can call it.

### Pause

| Method | Deposit | Arguments | Returns |
| --- | --- | --- | --- |
| `pause` | 1 yocto | none | nothing |
| `unpause` | 1 yocto | none | nothing |

Only `slimedragon.near` and `pause.slimedragon.near` can pause and unpause. Pausing stops deposits, swaps, calls, transfers, withdrawals and storage changes. Withdrawals already in flight still finish or get refunded.

### Rescue

`rescue(asset_id: AssetId, amount?: U128, to: AccountId)` sends out assets that the contract holds but doesn't track, such as tokens sent with `ft_transfer` instead of `ft_transfer_call`. Only the engine's own account can call it, and only while the contract is paused. Without `amount`, everything untracked is sent. It can never send assets that belong to users or DEXs.

## View methods

| Method | Arguments | Returns |
| --- | --- | --- |
| `asset_balance_of` | `of: AccountOrDexId`, `asset_id: AssetId` | `U128`, or `null` if not registered |
| `registered_assets_of` | `account_id?: AccountId`, `dex_id?: DexId`, `from_index: u32`, `limit: u32` | `[AssetId, U128][]` |
| `are_assets_registered` | `asset_ids: AssetId[]`, `for: AccountOrDexId` | `bool`: `true` if all of them are registered |
| `simulate_swap_simple` | `dex_id: DexId`, `message: Base64`, `trader: AccountId`, `asset_in: AssetId`, `asset_out: AssetId`, `amount: SwapRequestAmount`, `referrer?: AccountId`, `referral_fees?: ReferralFees` | `[amount_in, amount_out]` |
| `dex_view` | `dex_id: DexId`, `method: string`, `args: Base64` | `Base64` |
| `dex_code` | `dex_id: DexId` | `Base64`: the DEX's WebAssembly code. Fails with `Dex code not found` if there's no such DEX |
| `storage_balance_of` | `account_id: AccountId` | `StorageBalance`, or `null` |
| `storage_balance_bounds` | none | `{ "min": "5000000000000000000000", "max": null }` |
| `dex_storage_balance_of` | `dex_id: DexId` | `StorageBalance`, or `null` |
| `dex_storage_balance_bounds` | none | `{ "min": "5000000000000000000000", "max": null }` |
| `total_storage_balances` | none | `{ "users": StorageBalance, "dexes": StorageBalance }` |
| `total_in_custody` | `asset_id: AssetId` | `U128`: the total of the asset held for all users and DEXs, or `null` if nobody ever registered it |
| `untracked_near` | none | `U128`: NEAR on the contract's account that isn't owed to anyone |
| `is_paused` | none | `bool` |
| `get_trusted_code_deployer` | none | `AccountId` |
| `contract_source_metadata` | none | [NEP-330](https://github.com/near/NEPs/blob/master/neps/nep-0330.md) metadata: the `version`, and a `link` to the source code of the deployed build |

In `registered_assets_of`, pass exactly one of `account_id` and `dex_id`. Assets come in the order they were registered.
