Skip to main content

Registration and storage

This document describes functions related to managing storage deposits on Veax. Users can create an account, deposit NEAR tokens to cover storage costs and manage their storage balance. The document provides details about the arguments, prerequisites, and possible errors for each function. Examples are also provided to help you understand how to interact with these functions.

storage_deposit (transaction)

Create a user's account on Veax if it did not exist yet, and deposit NEAR on it to cover the storage of all user data in further operations. The account to be created and to receive the deposit is specified by account_id. If this argument isn't specified, then the caller's account is optionally created and receives the deposit. If registration_only is true then only as much NEAR as required for covering the account creation is deposited, whereas the rest is refunded, otherwise all attached NEAR is deposited.

If registration_only is true then only as much NEAR as required for covering the account creation is deposited, whereas the rest is refunded, otherwise all attached NEAR is deposited.

Arguments

  • Optional: account_id: AccountId: account to be optionally created and to receive the NEAR deposit or its accepted part.
  • registration_only: boolean: whether to accept and deposit all attached NEAR or only as much as required for the registration.

Attached NEAR

Any non-zero amount.

If the user's account doesn't exist on Veax, the attached NEAR amount must be sufficient to cover the account creation.

Returns

StorageBalance {
total: U128,
available: U128
}

Where:

  • StorageBalance.total: total user's storage deposit in YoctoNear after the deposit.
  • StorageBalance.available: user's storage deposit in YoctoNear available for further use after the deposit.

Prerequisites

If registration_only is true, the user's must not exist on Veax. Othewise, the non-critical error is logged.

Errors

DepositLessThanMinStorage: the user was not registered on Veax, and the attached NEAR isn't sufficient to cover the account creation.

Example

near call --account_id trader1.test.near veax.test.near storage_deposit --args '{"registration_only": true}' --amount 0.01
near call --account_id trader1.test.near veax.test.near storage_deposit --args '{"registration_only": true}' --amount 0.01
Scheduling a call: veax.test.near.storage_deposit({"registration_only": true}) with attached 0.01 NEAR
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
Doing account.functionCall()
Receipts: 6aAcg2jDXKyB52UypFEo9SytBcX5idNfpAenW9XnVLAV, 6zwbdiwbCMFnJLSecC9PMLUFgxDzpQnwezhjwy4kDChS
Log [veax.test.near]: EVENT_JSON:{"standard":"veax","version":"1.0.0","event":"storage_balance","data":{"user":"trader1.test.near","available":"0","total":"900000000000000000000"}}
Transaction Id CkJfNCx54SbgaTFy7ozjavL4ADptSY56ZaMtzjAo6i8z
To see the transaction in the transaction explorer, please open this url in your browser
http://127.0.0.1:8331/transactions/CkJfNCx54SbgaTFy7ozjavL4ADptSY56ZaMtzjAo6i8z
{ total: '900000000000000000000', available: '0' }

storage_withdraw (transaction)

Withdraw storage deposit from the caller's account on Veax and transfer it to the caller's Near account.

If amount is specified, then such amount is withdrawn, providing it is available, otherwise all available amount is withdrawn.

Arguments

Optional: amount: Amount: amount to withdraw.

Attached NEAR

Exactly one YoctoNEAR.

Returns

StorageBalance {
total: U128,
available: U128
}

Where:

  • StorageBalance.total: total user's storage deposit in YoctoNear after the withdrawal.
  • StorageBalance.available: user's storage deposit in YoctoNear available for further use after the withdrawal.

Prerequisites

  • A caller must be registered on Veax.
  • The caller's storage balance must be non-zero.
  • If amount is specified, this or larger storage deposit amount must be available on the caller's Veax account.

Errors

  • AccountNotRegistered: the caller isn't registered on Veax.
  • NoStorageCanWithdraw: user doesn't have deposited tokens for storage.
  • StorageWithdrawTooMuch: amount exceeds the available storage balance.
  • Requires attached deposit of exactly 1 yoctoNEAR: the attached NEAR amount differs from one YoctoNEAR.

Example

$ near call --account_id trader1.test.near veax.test.near storage_withdraw --args '{"amount": "2700000000000000000000000" }' --depositYocto 1
Scheduling a call: veax.test.near.storage_withdraw({"amount": "2700000000000000000000000" }) with attached 0.000000000000000000000001 NEAR
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
Doing account.functionCall()
Receipts: GRKyVF1PQ35haCtozQQ7coi4XDRMDEoKLCkjjTx6DErg, 4LaBrgNPwSqEJWe3Fc4iQBEo5fn4TF7Ab43CBJFntDNH
Log [veax.test.near]: EVENT_JSON:{"standard":"veax","version":"1.0.0","event":"storage_balance","data":{"user":"trader1.test.near","available":"2300000000000000000000000","total":"2300900000000000000000000"}}
Transaction Id 776ofjJNUZNiejyAwpch8ZEyQ72peGsuDkNsE5Dybdco
To see the transaction in the transaction explorer, please open this url in your browser
http://127.0.0.1:8331/transactions/776ofjJNUZNiejyAwpch8ZEyQ72peGsuDkNsE5Dybdco
{
total: '2300900000000000000000000',
available: '2300000000000000000000000'
}

storage_unregister (transaction)

Unregister a caller's Veax account and withdraw all storage deposit. The withdrawn storage deposit is transferred to the caller's Near account.

Arguments

Optional: force: boolean: this parameter is currently ignored

Attached NEAR

Exactly one YoctoNEAR.

Returns

boolean:

  • true: an account was successfully unregistered.
  • false: the caller did not have a Veax account.

Prerequisites

  • If a caller has a Veax account, there must be no tokens registered on this account. This implies that the caller must have no open positions and no tokens on Veax.
  • No async withdraw is in progress.

Errors

  • TokensStorageNotEmpty: the caller has an account with some tokens on Veax.
  • UserHasPositions: user has open positions.
  • WithdrawInProgress: asynchronous withdraw is in progress.
  • Requires attached deposit of exactly 1 yoctoNEAR: the attached NEAR amount differs from one YoctoNEAR.

Example

$ near call --account_id trader1.test.near veax.test.near storage_unregister --depositYocto 1
Scheduling a call: veax.test.near.storage_unregister() with attached 0.000000000000000000000001 NEAR
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
Doing account.functionCall()
Transaction Id 8CSnKZJ7h2wxPKkdhw9QUmEqzrwPh42bKhLgrUZvqrNm
To see the transaction in the transaction explorer, please open this url in your browser
http://127.0.0.1:8331/transactions/8CSnKZJ7h2wxPKkdhw9QUmEqzrwPh42bKhLgrUZvqrNm
true

storage_balance_bounds (query)

Returns limits on storage deposit.

Arguments

None.

Returns

StorageBalanceBounds {
min: U128,
max: Option<U128>
}

Where:

  • StorageBalanceBounds.min: minimum allowed storage deposit.
  • StorageBalanceBounds.max: maximum allowed storage deposit, if any. Currently, no limit is set.

Prerequisites

None.

Errors

None.

Example

$ near view veax.test.near storage_balance_bounds
View call: veax.test.near.storage_balance_bounds()
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
{ min: '900000000000000000000', max: null }

storage_balance_of (query)

Returns storage balance of account_id, if it is specified, or of the caller otherwise.

Arguments

account_id: AccountId: account to get the storage balance of.

Returns

Option<StorageBalance>

Where:

StorageBalance {
total: U128,
available: U128
}

Where:

  • StorageBalance.total: the total user's storage deposit in YoctoNear.
  • StorageBalance.available: the user's storage deposit in YoctoNear available for further use.

None means account isn't registered

Prerequisites

None.

Errors

None.

Example

$ near view veax.test.near storage_balance_of  --args '{"account_id": "trader1.test.near"}'
View call: veax.test.near.storage_balance_of({"account_id": "trader1.test.near"})
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
{
total: '5000000000000000000000000',
available: '4999100000000000000000000'
}

storage_constants (query)

Returns storage usage by each of the entries

Arguments

None.

Returns

struct StorageConstants {
min_bytes: U128,
bytes_per_token: U128,
bytes_per_pool: U128,
bytes_per_position: U128,
}

Where:

  • StorageConstants.min_bytes: minimum amount of storage for each new entry
  • StorageConstants.bytes_per_token: bytes usage per each registered tokens
  • StorageConstants.bytes_per_pool: bytes usage per each registered pool.
  • StorageConstants.bytes_per_position: bytes usage per each opened position

Prerequisites

None.

Errors

None.

Example

$ near view veax.test.near storage_constants
View call: veax.test.near.storage_constants()
{
min_bytes: '366',
bytes_per_token: '284',
bytes_per_pool: '4457',
bytes_per_position: '1087'
}

register_tokens (transaction)

Register tokens under the caller's account on Veax.

Arguments

  • token_ids: [TokenId]: an array of tokens to register.

Attached NEAR

Exactly one YoctoNEAR

Returns

Nothing.

Prerequisites

  • A caller is registered on Veax.
  • A caller has sufficient available storage deposit.

Errors

  • AccountNotRegistered: a caller isn't registered on Veax.
  • InsufficientStorage: insufficient storage deposit.
  • Requires attached deposit of exactly 1 yoctoNEAR: attached NEAR amount differs from one YoctoNEAR.

Example

$ near call --account_id trader1.test.near veax.test.near register_tokens --args '{"token_ids": ["usdt_demo.test.near", "wnear_demo.test.near", "wbtc_demo.test.near"]}' --depositYocto 1
Scheduling a call: veax.test.near.register_tokens({"token_ids": ["usdt_demo.test.near", "wnear_demo.test.near", "wbtc_demo.test.near"]}) with attached 0.000000000000000000000001 NEAR
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
Doing account.functionCall()
Receipt: CDa7mEewEShS6DkoYPzHeGeLPvpLkuXpU1jhAD7RbZya
Log [veax.test.near]: EVENT_JSON:{"standard":"veax","version":"1.0.0","event":"storage_balance","data":{"user":"trader1.test.near","available":"4994660000000000000000000","total":"5000000000000000000000000"}}
Transaction Id FBbzc7C7VURK94L8aQMbxLBpdLjquLycu78jtB98ghwr
To see the transaction in the transaction explorer, please open this url in your browser
http://127.0.0.1:8331/transactions/FBbzc7C7VURK94L8aQMbxLBpdLjquLycu78jtB98ghwr
''

unregister_tokens (transaction)

Unregister tokens under caller's account on Veax.

Arguments

token_ids: [AccountId]: an array of tokens to unregister.

Attached NEAR

Exactly one YoctoNEAR

Returns

Nothing.

Prerequisites

  • A caller is registered on Veax.
  • The balance of each token to be removed is zero.
  • No async withdraw is in progress.

Errors

  • AccountNotRegistered: the caller isn't registered on Veax.
  • NonZeroTokenBalance: the balance of one of the tokens to be removed is non-zero.
  • WithdrawInProgress: asynchronous withdraw is in progress.
  • Requires attached deposit of exactly 1 yoctoNEAR: attached NEAR amount differs from one YoctoNEAR.

Example

near call --account_id trader1.test.near veax.test.near unregister_tokens --args '{"token_ids": ["wbtc_demo.test.near"]}' --depositYocto 1
Scheduling a call: veax.test.near.unregister_tokens({"token_ids": ["wbtc_demo.test.near"]}) with attached 0.000000000000000000000001 NEAR
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
Doing account.functionCall()
Receipt: 8sMegTzoDXerUmRy7AXNXYGPsPD4vdTWZAsXux2x7chV
Log [veax.test.near]: EVENT_JSON:{"standard":"veax","version":"1.0.0","event":"storage_balance","data":{"user":"trader1.test.near","available":"4996140000000000000000000","total":"5000000000000000000000000"}}
Transaction Id 2XsRDAWdUNjMhroqtETu1sZcXoidNfwHkSEWDM6Pv6c7
To see the transaction in the transaction explorer, please open this url in your browser
http://127.0.0.1:8331/transactions/2XsRDAWdUNjMhroqtETu1sZcXoidNfwHkSEWDM6Pv6c7
''

token_register_of (query)

Check whether token_id is registered under account_id.

Arguments

  • account_id: AccountId: an account to query.
  • token_id: AccountId: a token to query.

Returns

boolean:

  • true: token_id is registered under account_id.
  • false: token_id isn't registered under account_id, or there is no account_id account.

Prerequisites

None.

Errors

None.

Example

$ near view veax.test.near token_register_of --args '{"account_id": "trader1.test.near", "token_id": "wnear_demo.test.near"}'
View call: veax.test.near.token_register_of({"account_id": "trader1.test.near", "token_id": "wnear_demo.test.near"})
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
true

withdraw (transaction)

Withdraw amount of token token_id from Veax account of the caller, and optionally unregister token token_id from the caller's account.

amount may be zero, which means to withdraw all available amount.

Arguments

  • token_id: AccountId: a token to withdraw.
  • amount: U128: an amount to withdraw.
  • Optional: unregister: boolean—whether to unregister token_id from the caller's account after withdrawal.

Attached NEAR

Exactly one YoctoNEAR

Returns

Promise: a promise, which client can execute to perform withdraw operation

Prerequisites

  • A caller is registered on Veax.
  • token_id is registered under the caller's account on Veax.
  • A caller has at least amount of token_id available, that is, not locked in positions.
  • In case unregister is true, there must be no tokens token_id locked in positions, and amount must be either zero or equal to the available amount.

Errors

  • AccountNotRegistered: a caller isn't registered on Veax.
  • TokenNotRegistered: token_id isn't registered under the caller's account on Veax.
  • NotEnoughTokens: a caller has zero balance of token_id.
  • NonZeroTokenBalance: unregister is true but the remaining balance is non-zero.
  • Requires attached deposit of exactly 1 yoctoNEAR: attached NEAR amount differs from one YoctoNEAR.

Example

$ near call --account_id trader1.test.near veax.test.near withdraw --args '{"token_id": "wnear_demo.test.near", "amount": "270"}' --depositYocto 1 --gas 100000000000000
Scheduling a call: veax.test.near.withdraw({"token_id": "wnear_demo.test.near", "amount": "270"}) with attached 0.000000000000000000000001 NEAR
Loaded master account test.near key from /home/user/.neartosis/validator-key.json with public key = ed25519:3Kuyi2DUXdoHgoaNEvCxa1m6G8xqc6Xs7WGajaqLhNmW
Doing account.functionCall()
Receipts: D6qusHC8K3h2ktjeNqNByxJ4uLxbKonwNHQ43Fi2aLQH, Bj36Ug1xLwnRp5y9XM3BkwGdbZkxmzum5FgJiq9NDEiZ, J73UJJig6AsCz2mafEpEoxaYQGGPRxfCdRu1zJjXrTZc
Log [veax.test.near]: EVENT_JSON:{"standard":"veax","version":"1.0.0","event":"storage_balance","data":{"user":"trader1.test.near","available":"4996140000000000000000000","total":"5000000000000000000000000"}}
Log [veax.test.near]: EVENT_JSON:{"standard":"veax","version":"1.0.0","event":"withdraw","data":{"user":"trader1.test.near","token_id":"wnear_demo.test.near","amount":"270","balance":"230"}}
Receipt: GSAA6arn7HxYTAA8Cc57K5Swy2eVPjhh5Dne4M2Kjf74
Log [veax.test.near]: EVENT_JSON:{"standard":"nep141","version":"1.0.0","event":"ft_transfer","data":[{"old_owner_id":"veax.test.near","new_owner_id":"trader1.test.near","amount":"270"}]}
Transaction Id EmX5LN3eNjaefUaJaeEf9GZsDm1eaUWSzMh2nhstZURD
To see the transaction in the transaction explorer, please open this url in your browser
http://127.0.0.1:8331/transactions/EmX5LN3eNjaefUaJaeEf9GZsDm1eaUWSzMh2nhstZURD
''

ft_on_transfer (transaction)

Through this function NEP-141 tokens notify Veax about token deposition.

Must not be called directly by Veax users.

The balance of the token calling this function under sernder_id Veax account is increased by amount.

Arguments

  • sender_id: AccountId: a Veax user to receive the deposit.
  • amount: U128: an amount to be received.
  • msg: string: must be empty (currently no messages are supported).

Attached NEAR

Non-payable.

Returns

enum PromiseOrValue {
Promise(Promise),
Value(U128),
}

Where:

  • PromiseOrValue::Value(refund): transaction is a single deposit, where refund is the refunded amount if deposit succeeded.
  • PromiseOrValue::Promise: transaction contains a set of async operations.

Errors

  • WrongMsgFormat: msg is non-empty.
  • AccountNotRegistered: sender_id isn't registered on Veax.
  • TokenNotRegistered: a token calling this function isn't registered under the sender_id account on Veax.
  • RegisterAccountNotAllowedOnDeposit: actions contain RegisterAccount action, which isn't allowed during token transfer * no way to provide storage deposit.