Skip to content

Commit

Permalink
Merge pull request #3 from shipsgold/fix/approval-change
Browse files Browse the repository at this point in the history
Fix/approval change
  • Loading branch information
zcstarr authored Mar 31, 2022
2 parents ec3b9f1 + 0805d5b commit 8ecf6ec
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 53 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Changes to the protocol specification and standards are called NEAR Enhancement
|[0178](https://github.com/near/NEPs/blob/master/neps/nep-0178.md) | Non Fungible Token Approval Management | @chadoh @thor314 | Final |
|[0181](https://github.com/near/NEPs/blob/master/neps/nep-0181.md) | Non Fungible Token Enumeration | @chadoh @thor314 | Final |
|[0199](https://github.com/near/NEPs/blob/master/neps/nep-0199.md) | Non Fungible Token Royalties and Payouts | @thor314 @mattlockyer | Final |
|[0245](https://github.com/near/NEPs/blob/master/neps/nep-0245.md) | Multi Token Standard | @zcstarr @riqi @jriemann @marcos.sun | Draft |
|[0297](https://github.com/near/NEPs/blob/master/neps/nep-0297.md) | Contract Events Standard | @telezhnaya | Final |


Expand Down
65 changes: 45 additions & 20 deletions neps/nep-0245.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
NEP: 245
Title: Multi Token Standard
Author: Zane Starr <[email protected]>, @riqi, @marcos.sun
Author: Zane Starr <[email protected]>, @riqi, @jriemann, @marcos.sun
DiscussionsTo: https://github.com/near/NEPs/discussions/246
Status: Draft
Type: Standards Track
Expand Down Expand Up @@ -92,9 +92,11 @@ type Token = {
// * `amount`: the number of tokens to transfer, wrapped in quotes and treated
// like a string, although the number will be stored as an unsigned integer
// with 128 bits.
// * `approval_id`: expected approval ID. A number smaller than
// * `approval` (optional): is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer

Expand All @@ -103,7 +105,7 @@ function mt_transfer(
receiver_id: string,
token_id: string,
amount: string,
approval_id: number|null,
approval: [owner_id: string, approval_id: number]|null,
memo: string|null,
) {}

Expand All @@ -128,10 +130,14 @@ function mt_transfer(
// * `amounts`: the number of tokens to transfer, wrapped in quotes and treated
// like an array of strings, although the numbers will be stored as an array of unsigned integer
// with 128 bits.
// * `approval_ids`: expected approval IDs per `token_ids`. If a `token_id` does
// not have a corresponding approval id then the entry in the array must be marked null.
// The `approval_ids` are numbers smaller than 2^53, and therefore representable as JSON.
// See Approval Management standard for full explanation.
// * `approvals` (optional): is an array of expected `approval` per `token_ids`.
// If a `token_id` does not have a corresponding `approval` then the entry in the array
// must be marked null.
// `approval` is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer

Expand All @@ -140,7 +146,7 @@ function mt_batch_transfer(
receiver_id: string,
token_ids: string[],
amounts: string[],
approval_ids: (number | null)[] | null,
approvals: ([owner_id: string, approval_id: number]| null)[]| null,
memo: string|null,
) {}

Expand Down Expand Up @@ -174,9 +180,11 @@ function mt_batch_transfer(
// * `amount`: the number of tokens to transfer, wrapped in quotes and treated
// like a string, although the number will be stored as an unsigned integer
// with 128 bits.
// * `approval_id`: expected approval ID. A number smaller than
// * `owner_id`: the valid NEAR account that owns the token
// * `approval` (optional): is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer.
// * `msg`: specifies information needed by the receiving contract in
Expand All @@ -188,7 +196,7 @@ function mt_transfer_call(
receiver_id: string,
token_id: string,
amount: string,
approval_id: number|null,
approval: [owner_id: string, approval_id: number]|null,
memo: string|null,
msg: string,
): Promise {}
Expand Down Expand Up @@ -226,10 +234,14 @@ function mt_transfer_call(
// * `amounts`: the number of tokens to transfer, wrapped in quotes and treated
// like an array of string, although the numbers will be stored as an array of
// unsigned integer with 128 bits.
// * `approval_ids`: expected approval IDs per `token_ids`. If a `token_id` does
// not have a corresponding approval id then the entry in the array must be marked null.
// The `approval_ids` are numbers smaller than 2^53, and therefore representable as JSON.
// ApprovalId See Approval Management standard for full explanation.
// * `approvals` (optional): is an array of expected `approval` per `token_ids`.
// If a `token_id` does not have a corresponding `approval` then the entry in the array
// must be marked null.
// `approval` is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer.
// * `msg`: specifies information needed by the receiving contract in
Expand All @@ -241,7 +253,7 @@ function mt_batch_transfer_call(
receiver_id: string,
token_ids: string[],
amounts: string[],
approval_ids: (number|null)[] | null,
approvals: ([owner_id: string, approval_id: number]|null)[] | null,
memo: string|null,
msg: string,
): Promise {}
Expand Down Expand Up @@ -307,9 +319,22 @@ The following behavior is required, but contract authors may name this function
// * `receiver_id`: the `receiver_id` argument given to `mt_transfer_call`
// * `token_ids`: the `token_ids` argument given to `mt_transfer_call`
// * `amounts`: the `token_ids` argument given to `mt_transfer_call`
// * `approved_token_ids`: if using Approval Management, contract MUST provide
// set of original approved accounts in this argument, and restore these
// * `approvals (optional)`: if using Approval Management, contract MUST provide
// set of original approvals in this argument, and restore the
// approved accounts in case of revert.
// `approvals` is an array of expected `approval_list` per `token_ids`.
// If a `token_id` does not have a corresponding `approvals_list` then the entry in the
// array must be marked null.
// `approvals_list` is an array of triplets of [`owner_id`,`approval_id`,`amount`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// `amount`: the number of tokens to transfer, wrapped in quotes and treated
// like a string, although the number will be stored as an unsigned integer
// with 128 bits.
//
//
//
// Returns total amount spent by the `receiver_id`, corresponding to the `token_id`.
// The amounts returned, though wrapped in quotes and treated like strings,
Expand All @@ -323,7 +348,7 @@ function mt_resolve_transfer(
sender_id: string,
receiver_id: string,
token_ids: string[],
approved_account_ids: (null | string[])[] | null,
approvals: (null | [owner_id: string, approval_id: number, amount: string][]) []| null
):string[] {}
```

Expand Down
51 changes: 37 additions & 14 deletions specs/Standards/MultiToken/ApprovalManagement.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Multi Token Standard Approval Management([NEP-246](https://github.com/near/NEPs/discussions/246))
# Multi Token Standard Approval Management([NEP-245](https://github.com/near/NEPs/discussions/246))


Version `1.0.0`
Expand Down Expand Up @@ -222,26 +222,26 @@ Again, note that no previous approvers will get cross-contract calls in this cas

## Reference-level explanation

The `Token` structure returned by `mt_tokens` must include an `approved_account_ids` field, which is a map of account IDs to `Approval`. The `amount` field though wrapped in quotes and treated like strings, the number will be stored as an unsigned integer with 128 bits.
The `TokenApproval` structure returned by `mt_token_approvals` returns `approved_account_ids` field, which is a map of account IDs to `Approval` and `approval_owner_id` which is the associated account approved for removal from. The `amount` field though wrapped in quotes and treated like strings, the number will be stored as an unsigned integer with 128 bits.
in approval is Using TypeScript's [Record type](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeystype) notation:

```diff
+ type Approval = {
+ amount: string
+ approval_id: string
+ }
type Token = {
id: string,
owner_id: string,
+
+ type TokenApproval = {
+ approval_owner_id: string,
+ approved_account_ids: Record<string, Approval>,
};
+ };
```

Example token data:
Example token approval data:

```json
{
"id": "1",
[{
"approval_owner_id": "alice.near",
"approved_account_ids": {
"bob.near": {
"amount": "100",
Expand All @@ -252,7 +252,7 @@ Example token data:
"approval_id": 2,
}
}
}
}]
```

### What is an "approval ID"?
Expand All @@ -273,8 +273,7 @@ Keeping with the example above, say the initial approval of the second marketpla

```json
{
"id": "1",
"owner_id": "alice.near",
"approval_owner_id": "alice.near",
"approved_account_ids": {
"marketplace_1.near": {
"approval_id": 1,
Expand All @@ -291,8 +290,7 @@ But after the transfers and re-approval described above, the token might have `a

```json
{
"id": "1",
"owner_id": "alice.near",
"approval_owner_id": "alice.near",
"approved_account_ids": {
"marketplace_2.near": {
"approval_id": 3,
Expand Down Expand Up @@ -415,7 +413,32 @@ function mt_is_approved(
approval_ids: number[]|null
): boolean {}

// Get a the list of approvals for a given token_id and account_id
//
// Arguments:
// * `token_id`: the token for which to check an approval
// * `account_id`: the account to retrieve approvals for
//
// Returns a TokenApproval object, as described in Approval Management standard
function mt_token_approval(
token_id: string,
account_id: string,
): TokenApproval {}


// Get a list of all approvals for a given token_id
//
// Arguments:
// * `from_index`: a string representing an unsigned 128-bit integer,
// representing the starting index of tokens to return
// * `limit`: the maximum number of tokens to return
//
// Returns an array of TokenApproval objects, as described in Approval Management standard, and an empty array if there are no approvals
function mt_token_approvals(
token_id: string,
from_index: string|null, // default: "0"
limit: number|null,
): TokenApproval[] {}
```

### Why must `mt_approve` panic if `mt_revoke_all` would fail later?
Expand Down
64 changes: 45 additions & 19 deletions specs/Standards/MultiToken/Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Token = {
owner_id: string | null
}


/******************/
/* CHANGE METHODS */
/******************/
Expand All @@ -83,9 +84,11 @@ type Token = {
// * `amount`: the number of tokens to transfer, wrapped in quotes and treated
// like a string, although the number will be stored as an unsigned integer
// with 128 bits.
// * `approval_id`: expected approval ID. A number smaller than
// * `approval` (optional): is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer

Expand All @@ -94,7 +97,7 @@ function mt_transfer(
receiver_id: string,
token_id: string,
amount: string,
approval_id: number|null,
approval: [owner_id: string, approval_id: number]|null,
memo: string|null,
) {}

Expand All @@ -119,10 +122,14 @@ function mt_transfer(
// * `amounts`: the number of tokens to transfer, wrapped in quotes and treated
// like an array of strings, although the numbers will be stored as an array of unsigned integer
// with 128 bits.
// * `approval_ids`: expected approval IDs per `token_ids`. If a `token_id` does
// not have a corresponding approval id then the entry in the array must be marked null.
// The `approval_ids` are numbers smaller than 2^53, and therefore representable as JSON.
// See Approval Management standard for full explanation.
// * `approvals` (optional): is an array of expected `approval` per `token_ids`.
// If a `token_id` does not have a corresponding `approval` then the entry in the array
// must be marked null.
// `approval` is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer

Expand All @@ -131,7 +138,7 @@ function mt_batch_transfer(
receiver_id: string,
token_ids: string[],
amounts: string[],
approval_ids: (number | null)[] | null,
approvals: ([owner_id: string, approval_id: number]| null)[]| null,
memo: string|null,
) {}

Expand Down Expand Up @@ -165,9 +172,11 @@ function mt_batch_transfer(
// * `amount`: the number of tokens to transfer, wrapped in quotes and treated
// like a string, although the number will be stored as an unsigned integer
// with 128 bits.
// * `approval_id`: expected approval ID. A number smaller than
// * `owner_id`: the valid NEAR account that owns the token
// * `approval` (optional): is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer.
// * `msg`: specifies information needed by the receiving contract in
Expand All @@ -179,7 +188,7 @@ function mt_transfer_call(
receiver_id: string,
token_id: string,
amount: string,
approval_id: number|null,
approval: [owner_id: string, approval_id: number]|null,
memo: string|null,
msg: string,
): Promise {}
Expand Down Expand Up @@ -217,10 +226,14 @@ function mt_transfer_call(
// * `amounts`: the number of tokens to transfer, wrapped in quotes and treated
// like an array of string, although the numbers will be stored as an array of
// unsigned integer with 128 bits.
// * `approval_ids`: expected approval IDs per `token_ids`. If a `token_id` does
// not have a corresponding approval id then the entry in the array must be marked null.
// The `approval_ids` are numbers smaller than 2^53, and therefore representable as JSON.
// ApprovalId See Approval Management standard for full explanation.
// * `approvals` (optional): is an array of expected `approval` per `token_ids`.
// If a `token_id` does not have a corresponding `approval` then the entry in the array
// must be marked null.
// `approval` is a tuple of [`owner_id`,`approval_id`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// * `memo` (optional): for use cases that may benefit from indexing or
// providing information for a transfer.
// * `msg`: specifies information needed by the receiving contract in
Expand All @@ -232,7 +245,7 @@ function mt_batch_transfer_call(
receiver_id: string,
token_ids: string[],
amounts: string[],
approval_ids: (number|null)[] | null,
approvals: ([owner_id: string, approval_id: number]|null)[] | null,
memo: string|null,
msg: string,
): Promise {}
Expand Down Expand Up @@ -298,9 +311,22 @@ The following behavior is required, but contract authors may name this function
// * `receiver_id`: the `receiver_id` argument given to `mt_transfer_call`
// * `token_ids`: the `token_ids` argument given to `mt_transfer_call`
// * `amounts`: the `token_ids` argument given to `mt_transfer_call`
// * `approved_token_ids`: if using Approval Management, contract MUST provide
// set of original approved accounts in this argument, and restore these
// * `approvals (optional)`: if using Approval Management, contract MUST provide
// set of original approvals in this argument, and restore the
// approved accounts in case of revert.
// `approvals` is an array of expected `approval_list` per `token_ids`.
// If a `token_id` does not have a corresponding `approvals_list` then the entry in the
// array must be marked null.
// `approvals_list` is an array of triplets of [`owner_id`,`approval_id`,`amount`].
// `owner_id` is the valid Near account that owns the tokens.
// `approval_id` is the expected approval ID. A number smaller than
// 2^53, and therefore representable as JSON. See Approval Management
// standard for full explanation.
// `amount`: the number of tokens to transfer, wrapped in quotes and treated
// like a string, although the number will be stored as an unsigned integer
// with 128 bits.
//
//
//
// Returns total amount spent by the `receiver_id`, corresponding to the `token_id`.
// The amounts returned, though wrapped in quotes and treated like strings,
Expand All @@ -314,7 +340,7 @@ function mt_resolve_transfer(
sender_id: string,
receiver_id: string,
token_ids: string[],
approved_account_ids: (null | string[])[] | null,
approvals: (null | [owner_id: string, approval_id: number, amount: string][]) []| null
):string[] {}
```

Expand Down

0 comments on commit 8ecf6ec

Please sign in to comment.