Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fungible token to 0.2.0 #80

Merged
merged 5 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions docs/Standards/Tokens/FungibleToken.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,17 @@ <h1 class="menu-title">NEAR Protocol Specification</h1>
<div id="content" class="content">
<main>
<h1><a class="header" href="#fungible-token" id="fungible-token">Fungible Token</a></h1>
<p>Version <code>0.2.0</code></p>
<h2><a class="header" href="#summary" id="summary">Summary</a></h2>
<p>A standard interface for fungible tokens allowing for ownership, escrow and transfer, specifically targeting third-party marketplace integration.</p>
<h2><a class="header" href="#changelog" id="changelog">Changelog</a></h2>
<h3><a class="header" href="#020" id="020"><code>0.2.0</code></a></h3>
<ul>
<li>Introduce storage deposits. Make every change method payable (able receive attached deposits with the function calls). It requires the caller to attach enough deposit to cover potential storage increase. See <a href="https://github.com/near/core-contracts/issues/47">core-contracts/#47</a></li>
<li>Replace <code>set_allowance</code> with <code>inc_allowance</code> and <code>dec_allowance</code> to address the issue of allowance front-running. See <a href="https://github.com/near/core-contracts/issues/49">core-contracts/#49</a></li>
<li>Validate <code>owner_id</code> account ID. See <a href="https://github.com/near/core-contracts/issues/54">core-contracts/#54</a></li>
<li>Enforce that the <code>new_owner_id</code> is different from the current <code>owner_id</code> for transfer. See <a href="https://github.com/near/core-contracts/issues/55">core-contracts/#55</a></li>
</ul>
<h2><a class="header" href="#motivation" id="motivation">Motivation</a></h2>
<p>NEAR Protocol uses an asynchronous sharded Runtime. This means the following:</p>
<ul>
Expand Down Expand Up @@ -196,6 +205,10 @@ <h2><a class="header" href="#guide-level-explanation" id="guide-level-explanatio
</ul>
<p>Note, that the precision is not part of the default standard, since it's not required to perform actions. The minimum
value is always 1 token.</p>
<p>The standard acknowledges NEAR storage staking model and accounts for the difference in storage that can be introduced
by actions on this contract. Since multiple users use the contract, the contract has to account for potential
storage increase. Thus every change method of the contract that can change the amount of storage must be payable.
See reference implementation for storage deposits and refunds.</p>
<h3><a class="header" href="#simple-transfer" id="simple-transfer">Simple transfer</a></h3>
<p>Alice wants to send 5 wBTC tokens to Bob.</p>
<p><strong>Assumptions</strong></p>
Expand Down Expand Up @@ -298,13 +311,23 @@ <h3><a class="header" href="#multi-token-swap-on-dex" id="multi-token-swap-on-de
</li>
</ol>
<h2><a class="header" href="#reference-level-explanation" id="reference-level-explanation">Reference-level explanation</a></h2>
<p>The full implementation in Rust can be found there: https://github.com/nearprotocol/near-sdk-rs/blob/master/examples/fungible-token/src/lib.rs</p>
<p>The full implementation in Rust can be found here: <a href="https://github.com/nearprotocol/near-sdk-rs/blob/master/examples/fungible-token/src/lib.rs">fungible-token</a></p>
<p><strong>NOTES:</strong></p>
<ul>
<li>All amounts, balances and allowance are limited by U128 (max value <code>2**128 - 1</code>).</li>
<li>All amounts, balances and allowance are limited by <code>U128</code> (max value <code>2**128 - 1</code>).</li>
<li>Token standard uses JSON for serialization of arguments and results.</li>
<li>Amounts in arguments and results have are serialized as Base-10 strings, e.g. <code>&quot;100&quot;</code>. This is done to avoid
JSON limitation of max integer value of <code>2**53</code>.</li>
<li>The contract tracks the change in storage before and after the call. If the storage increases,
the contract requires the caller of the contract to attach enough deposit to the function call
to cover the storage cost.
This is done to prevent a denial of service attack on the contract by taking all available storage.
It's because the gas cost of adding new escrow account is cheap, many escrow allowances can be added until the contract
runs out of storage.
If the storage decreases, the contract will issue a refund for the cost of the released storage.
The unused tokens from the attached deposit are also refunded, so it's safe to attach more deposit than required.</li>
<li>To prevent the deployed contract from being modified or deleted, it should not have any access
keys on its account.</li>
</ul>
<p>Interface:</p>
<pre><pre class="playpen"><code class="language-rust">
Expand All @@ -314,9 +337,21 @@ <h2><a class="header" href="#reference-level-explanation" id="reference-level-ex
/* CHANGE METHODS */
/******************/

/// Sets the `allowance` for `escrow_account_id` on the account of the caller of this contract
/// Increments the `allowance` for `escrow_account_id` by `amount` on the account of the caller of this contract
/// (`predecessor_id`) who is the balance owner.
pub fn set_allowance(&amp;mut self, escrow_account_id: AccountId, allowance: U128);
/// Requirements:
/// * Caller of the method has to attach deposit enough to cover storage difference at the
/// fixed storage price defined in the contract.
#[payable]
pub fn inc_allowance(&amp;mut self, escrow_account_id: AccountId, amount: U128);

/// Decrements the `allowance` for `escrow_account_id` by `amount` on the account of the caller of this contract
/// (`predecessor_id`) who is the balance owner.
/// Requirements:
/// * Caller of the method has to attach deposit enough to cover storage difference at the
/// fixed storage price defined in the contract.
#[payable]
pub fn dec_allowance(&amp;mut self, escrow_account_id: AccountId, amount: U128);

/// Transfers the `amount` of tokens from `owner_id` to the `new_owner_id`.
/// Requirements:
Expand All @@ -325,13 +360,20 @@ <h2><a class="header" href="#reference-level-explanation" id="reference-level-ex
/// * If this function is called by an escrow account (`owner_id != predecessor_account_id`),
/// then the allowance of the caller of the function (`predecessor_account_id`) on
/// the account of `owner_id` should be greater or equal than the transfer `amount`.
/// * Caller of the method has to attach deposit enough to cover storage difference at the
/// fixed storage price defined in the contract.
#[payable]
pub fn transfer_from(&amp;mut self, owner_id: AccountId, new_owner_id: AccountId, amount: U128);


/// Transfer `amount` of tokens from the caller of the contract (`predecessor_id`) to
/// `new_owner_id`.
/// Act the same was as `transfer_from` with `owner_id` equal to the caller of the contract
/// (`predecessor_id`).
/// Requirements:
/// * Caller of the method has to attach deposit enough to cover storage difference at the
/// fixed storage price defined in the contract.
#[payable]
pub fn transfer(&amp;mut self, new_owner_id: AccountId, amount: U128);

/****************/
Expand Down
79 changes: 69 additions & 10 deletions docs/print.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/searchindex.json

Large diffs are not rendered by default.

Loading