Methods
This page is also Markdown, for agents: /intear-dex/reference/methods.md, and /llms.txt lists every page.
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. pause, unpause, set_trusted_code_deployer, translate_dex_codes, oracle_respond, remove_oracle_key, the admin methods, views and the callbacks of withdrawals still work. Operations that wait for an oracle fail if it responds while the contract is paused: the oracle is still paid, and a deposit is refunded. rescue works only while paused, and storage_unregister always fails with its own message.
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. A withdrawal of 0, such asFullof an empty balance, returnstruewithout a transfer. 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, referral_fees?: ReferralFees, constraint?: U128, quote_improvement_fee?: QuoteImprovementFee, fee_discount?: SignedFeeDiscount |
[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, fee_discount?: SignedFeeDiscount |
nothing |
swap_simple: see Swaps.referral_feesare the referral fees the swap pays out of its input,quote_improvement_feea quote improvement fee it pays, andfee_discounta fee discount on the DEX’s fees. It returns what the trader paid and got:amount_inincludes the referral fees and, for anExactOutswap, the quote improvement fee, andamount_outis without the quote improvement fee of anExactInswap.constraintapplies to these amounts.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.referral_feesare paid by the first swap only, not counting theswapof anOracleRequest.fee_discountapplies to every swap of the operations. Operations that start with anOracleRequestfinish in a later receipt, see Oracles. 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 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. Operations that start with an OracleRequest are different: the engine keeps the whole deposit and holds it until the oracle responds, and if the operations after the request don’t run, it refunds the deposit by withdrawing it to the sender.
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, call_after_deploy?: DexCallAfterDeploy |
nothing |
translate_dex_codes |
none | dex_ids: DexId[] |
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. The engine sends the code totranslator.dex.intear.near, which validates it and translates it for the engine’s WebAssembly interpreter, then stores the code and its translation in the next receipt, paid by the DEX’s storage balance. In that receipt it makes thecall_after_deploy, if there is one: if that call fails, nothing is stored. See Deploying.translate_dex_codes: translates the code of DEXs again. The engine only runs translations of the interpreter version it has, so after an engine upgrade that changes it, calls to a DEX fail withFailed to load the code of <dex id>, which translate_dex_codes translates againuntil someone calls this. Anyone can call it, and the storage balance of each DEX pays for its new translation.set_trusted_code_deployer: hands the permission to deploy DEX code to another account. Only the current trusted code deployer can call it.
Oracles
Section titled “Oracles”An oracle responds to requests of DEXs, like the prices of assets, that operations make with an OracleRequest. Its key is a gas key on the engine’s account, which can only call oracle_respond and remove_oracle_key. See Oracles.
| Method | Deposit | Arguments | Returns |
|---|---|---|---|
create_oracle_key |
The storage of the key, and the key’s gas balance | oracle_key: PublicKey |
nothing |
set_oracle_fees |
1 yocto | oracle_key: PublicKey, fees: { [AssetId]: U128 } |
nothing |
top_up_oracle_key |
The NEAR to add | oracle_key: PublicKey |
nothing |
oracle_respond |
none | request_hash: string, response: Base64, nonces: Base64[] |
nothing |
remove_oracle_key |
none | receiver_id: AccountId |
nothing |
create_oracle_key: adds the oracle’s key. The transaction must be signed withoracle_key, as a full access key of the caller, who becomes the oracle’s fee receiver. The deposit pays for the storage of the key, and the rest is its gas balance. The fee receiver’s storage balance pays for the records of the oracle and its fees.set_oracle_fees: sets what the oracle takes for a request in each asset, and replaces its fees in all other assets. Only its fee receiver can call it, and it must have each asset registered. Fees are paid to its inner balance.top_up_oracle_key: adds the attached NEAR to the gas balance of the key. Anyone can call it.oracle_respond: signed with the oracle’s key, responds to the request whose SHA-256 isrequest_hash, in base58, for the operations that wait with each ofnonces, fromoracle_requestevents. The response is at most 1024 bytes. Nonces that no operations wait with are skipped.remove_oracle_key: signed with the oracle’s key, deletes it with its fee receiver and fees, and sends the NEAR that paid for its storage toreceiver_id. Deleting a gas key burns its gas balance, and fails if that’s more than 1 NEAR.
Operations wait for 200 blocks. If the oracle responds in time, it’s paid even when the operations after the request fail. If it doesn’t, its fee is refunded. When the operations of execute_operations don’t run, the transaction fails in the receipt of fail_after_oracle_operations, with Oracle didn't respond in time or Operations after the oracle request failed.
| 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.
set_fee_discount_signer(fee_discount_signer: PublicKey | null), with 1 yocto, sets the key that signs fee discounts, or turns them off. store_code_chunk and deploy_code_chunks upload new code of the engine in chunks and deploy it, with Borsh arguments. deploy_code_chunks calls a method of the new code in the same receipt, so if the code doesn’t work or that call fails, the old code stays. Only the engine’s own account can call these.
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, referral_fees?: ReferralFees, quote_improvement_fee?: QuoteImprovementFee, oracle_response?: UnsignedOracleResponse, fee_discount?: u32 |
[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 |
oracle_fee_receiver |
oracle_key: PublicKey |
AccountId, or null if there’s no such oracle |
oracle_fees |
oracle_key: PublicKey |
{ [AssetId]: U128 }: what the oracle takes for a request in each asset |
get_fee_discount_signer |
none | PublicKey, or null if fee discounts are off |
contract_source_metadata |
none | NEP-330 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.
simulate_swap_simple returns the same amounts as swap_simple. A DEX that needs an oracle reads oracle_response as if the oracle had responded with it, and fee_discount is a discount that doesn’t need a signature, where 1000000 waives the fees.