Methods
All methods are on dex.intear.near, with JSON arguments. Types like AssetId and AccountOrDexId are described in Types. 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, every change method fails with Contract is paused, and so does simulate_swap_simple. Views and the callbacks of withdrawals still work.
Change methods
Section titled “Change methods”Balances
Section titled “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 forfor(default: the caller), paid from the caller’s storage balance. See Register assets.deposit_near: withoutoperations, adds the attached NEAR to the caller’s inner balance. Withoperations, runs them on the attached NEAR. See 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. Returnstrueif the transfer succeeded,falseif it failed and the assets were refunded to an inner balance. See Withdraw.
Swaps and DEX calls
Section titled “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, 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 |
nothing |
swap_simple: see Swaps.dex_call: see 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. See Operations.
Token receivers
Section titled “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 sender’s inner balance. 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
Section titled “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.
DEX code
Section titled “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.set_trusted_code_deployer: hands the permission to deploy DEX code to another account. Only the current trusted code deployer can call it.
| 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
Section titled “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
Section titled “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 |
[amount_in, amount_out] |
dex_view |
dex_id: DexId, method: string, args: Base64 |
Base64 |
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 |
In registered_assets_of, pass exactly one of account_id and dex_id. Assets come in the order they were registered.