From 5b6e61caee5cb7b6f0511d825a47a87bccceb003 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Thu, 22 Jul 2021 19:50:34 +0300 Subject: [PATCH 1/6] Update selectors according PSP22 naming of interface(previous selectors where generated for PSP20) --- PSPs/drafts/psp-22.md | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/PSPs/drafts/psp-22.md b/PSPs/drafts/psp-22.md index b1dcaed..04fa7f3 100644 --- a/PSPs/drafts/psp-22.md +++ b/PSPs/drafts/psp-22.md @@ -48,6 +48,7 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not #### PSP22 is an interface of Fungible Token Standard ##### **total_supply**() -> Balance +Selector: `0x162df8c2` - first 4 bytes of `blake2b_256("PSP22::total_supply")` ```json { "args": [], @@ -66,11 +67,12 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "type": "Balance" }, - "selector": "0xd1ff92bd" + "selector": "0x162df8c2" } ``` ##### **balance_of**(owner: AccountId) -> Balance +Selector: `0x6568382f` - first 4 bytes of `blake2b_256("PSP22::balance_of")` ```json { "args": [ @@ -101,11 +103,12 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "type": "Balance" }, - "selector": "0x936205de" + "selector": "0x6568382f" } ``` ##### **allowance**(owner: AccountId, spender: AccountId) -> Balance +Selector: `0x4d47d921` - first 4 bytes of `blake2b_256("PSP22::allowance")` ```json { "args": [ @@ -145,11 +148,12 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "type": "Balance" }, - "selector": "0x467e8bff" + "selector": "0x4d47d921" } ``` ##### **transfer**(to: AccountId, value: Balance, data: [u8]) +Selector: `0xdb20f9f5` - first 4 bytes of `blake2b_256("PSP22::transfer")` ```json { "args": [ @@ -203,11 +207,12 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "payable": false, "returnType": null, - "selector": "0x18532c7c" + "selector": "0xdb20f9f5" } ``` ##### **transfer_from**(from: AccountId, to: AccountId, value: Balance, data: [u8]) +Selector: `0x54b3c76e` - first 4 bytes of `blake2b_256("PSP22::transfer_from")` ```json { "args": [ @@ -276,11 +281,12 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "payable": false, "returnType": null, - "selector": "0x9eb3870e" + "selector": "0x54b3c76e" } ``` ##### **approve**(spender: AccountId, value: Balance) +Selector: `0xb20f1bbd` - first 4 bytes of `blake2b_256("PSP22::approve")` ```json { "args": [ @@ -324,12 +330,13 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "payable": false, "returnType": null, - "selector": "0xf229fa2f" + "selector": "0xb20f1bbd" } ``` ##### **increase_allowance**(spender: AccountId, delta_value: Balance) +Selector: `0x96d6b57a` - first 4 bytes of `blake2b_256("PSP22::increase_allowance")` ```json { "args": [ @@ -370,11 +377,12 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "payable": false, "returnType": null, - "selector": "0xf43f7266" + "selector": "0x96d6b57a" } ``` ##### **decrease_allowance**(spender: AccountId, delta_value: Balance) +Selector: `0xfecb57d5` - first 4 bytes of `blake2b_256("PSP22::decrease_allowance")` ```json { "args": [ @@ -418,7 +426,7 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not ], "payable": false, "returnType": null, - "selector": "0x1f86d882" + "selector": "0xfecb57d5" } ``` @@ -426,6 +434,7 @@ As `pallet-contract` in Substrate can execute any WASM contracts, we should not PSP22Metadata is an optional interface of metadata for Fungible Token Standard ##### **token_name**() -> Option +Selector: `0x3d261bd4` - first 4 bytes of `blake2b_256("PSP22Metadata::token_name")` ```json { "args": [], @@ -444,11 +453,12 @@ PSP22Metadata is an optional interface of metadata for Fungible Token Standard ], "type": "Option" }, - "selector": "0x9c994fe4" + "selector": "0x3d261bd4" } ``` ##### **token_symbol**() -> Option +Selector: `0x34205be5` - first 4 bytes of `blake2b_256("PSP22Metadata::token_symbol")` ```json { "args": [], @@ -467,11 +477,12 @@ PSP22Metadata is an optional interface of metadata for Fungible Token Standard ], "type": "Option" }, - "selector": "0x10972330" + "selector": "0x34205be5" } ``` ##### **token_decimals**() -> u8 +Selector: `0x7271b782` - first 4 bytes of `blake2b_256("PSP22Metadata::token_decimals")` ```json { "args": [], @@ -490,7 +501,7 @@ PSP22Metadata is an optional interface of metadata for Fungible Token Standard ], "type": "u8" }, - "selector": "0x997ad16c" + "selector": "0x7271b782" } ``` @@ -499,6 +510,7 @@ PSP22Receiver is an interface for any contract that wants to support safe transf This method is called before transfer to ensure the recipient of the tokens acknowledges receipt. ##### **before_received**(&mut self, operator: AccountId, from: AccountId, value: Balance, data: [u8]) -> Result<(), PSP22ReceiverError> +Selector: `0xfda6f1a9` - first 4 bytes of `blake2b_256("PSP22Receiver::before_received")` ```json { "args": [ @@ -560,7 +572,7 @@ This method is called before transfer to ensure the recipient of the tokens ackn ], "type": "Result" }, - "selector": "0xa9504238" + "selector": "0xfda6f1a9" } ``` From 36bf5bd295ed1440cf463d30c20c90aa1db0a562 Mon Sep 17 00:00:00 2001 From: Pierre Ossun Date: Tue, 10 Aug 2021 10:17:02 +0200 Subject: [PATCH 2/6] Updated return types --- PSPs/drafts/psp-22.md | 165 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 158 insertions(+), 7 deletions(-) diff --git a/PSPs/drafts/psp-22.md b/PSPs/drafts/psp-22.md index 04fa7f3..e90dcfb 100644 --- a/PSPs/drafts/psp-22.md +++ b/PSPs/drafts/psp-22.md @@ -35,7 +35,7 @@ Another difference is that it has `PSP22Receiver` interface, and `before_receive # This standard is at ABI level -As `pallet-contract` in Substrate can execute any WASM contracts, we should not restrain this standard to only Rust & ink! Framework, so that it can be use by any language/framework that compile to WASM. +As `pallet-contract` in Substrate can execute any WASM contracts, we should not restrain this standard to only Rust & ink! Framework, so that it can be used by any language/framework that compile to WASM. ## Specification 1. [Interface](#Interface) @@ -206,7 +206,12 @@ Selector: `0xdb20f9f5` - first 4 bytes of `blake2b_256("PSP22::transfer")` "transfer" ], "payable": false, - "returnType": null, + "returnType": { + "displayName": [ + "Result" + ], + "type": 1 + }, "selector": "0xdb20f9f5" } ``` @@ -280,7 +285,12 @@ Selector: `0x54b3c76e` - first 4 bytes of `blake2b_256("PSP22::transfer_from")` "transfer_from" ], "payable": false, - "returnType": null, + "returnType": { + "displayName": [ + "Result" + ], + "type": 1 + }, "selector": "0x54b3c76e" } ``` @@ -329,7 +339,12 @@ Selector: `0xb20f1bbd` - first 4 bytes of `blake2b_256("PSP22::approve")` "approve" ], "payable": false, - "returnType": null, + "returnType": { + "displayName": [ + "Result" + ], + "type": 1 + }, "selector": "0xb20f1bbd" } @@ -376,7 +391,12 @@ Selector: `0x96d6b57a` - first 4 bytes of `blake2b_256("PSP22::increase_allowanc "increase_allowance" ], "payable": false, - "returnType": null, + "returnType": { + "displayName": [ + "Result" + ], + "type": 1 + }, "selector": "0x96d6b57a" } ``` @@ -425,7 +445,12 @@ Selector: `0xfecb57d5` - first 4 bytes of `blake2b_256("PSP22::decrease_allowanc "decrease_allowance" ], "payable": false, - "returnType": null, + "returnType": { + "displayName": [ + "Result" + ], + "type": 1 + }, "selector": "0xfecb57d5" } ``` @@ -570,7 +595,7 @@ Selector: `0xfda6f1a9` - first 4 bytes of `blake2b_256("PSP22Receiver::before_re "displayName": [ "Result" ], - "type": "Result" + "type": 2 }, "selector": "0xfda6f1a9" } @@ -678,6 +703,132 @@ type AccountId = [u8; 32]; // u128 must be enough to cover most of the use cases of standard token. type Balance = u128; ``` +#### Return types +```json +{ + "types": { + "1": { + "def": { + "variant": { + "variants": [ + { + "fields": [ + { + "type": { + "def": { + "tuple": [] + } + }, + "typeName": "T" + } + ], + "name": "Ok" + }, + { + "fields": [ + { + "type": { + "def": { + "variant": { + "variants": [ + { + "fields": [ + { + "type": "string", + "typeName": "String" + } + ], + "name": "Custom" + }, + { + "name": "InsufficientBalance" + }, + { + "name": "InsufficientAllowance" + }, + { + "name": "ZeroRecipientAddress" + }, + { + "name": "ZeroSenderAddress" + }, + { + "fields": [ + { + "type": "string", + "typeName": "String" + } + ], + "name": "SafeTransferCheckFailed" + } + ] + } + }, + "path": [ + "PSP22Error" + ] + }, + "typeName": "E" + } + ], + "name": "Err" + } + ] + } + } + }, + "2": { + "def": { + "variant": { + "variants": [ + { + "fields": [ + { + "type": { + "def": { + "tuple": [] + } + }, + "typeName": "T" + } + ], + "name": "Ok" + }, + { + "fields": [ + { + "type": { + "def": { + "variant": { + "variants": [ + { + "fields": [ + { + "type": "string", + "typeName": "String" + } + ], + "name": "TransferRejected" + } + ] + } + }, + "path": [ + "PSP22ReceiverError" + ] + }, + "typeName": "E" + } + ], + "name": "Err" + } + ] + } + } + } + } +} +``` ### Errors Suggested methods don't return `Result` (except `before_received`). Instead, they panic. From 91b99134329249821fed5445a49b6867b867bc43 Mon Sep 17 00:00:00 2001 From: Pierre Ossun Date: Tue, 10 Aug 2021 11:34:54 +0200 Subject: [PATCH 3/6] Updated descriptions & signatures --- PSPs/drafts/psp-22.md | 54 +++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/PSPs/drafts/psp-22.md b/PSPs/drafts/psp-22.md index e90dcfb..3941b55 100644 --- a/PSPs/drafts/psp-22.md +++ b/PSPs/drafts/psp-22.md @@ -60,7 +60,6 @@ Selector: `0x162df8c2` - first 4 bytes of `blake2b_256("PSP22::total_supply")` "PSP22", "total_supply" ], - "payable": false, "returnType": { "displayName": [ "Balance" @@ -96,7 +95,6 @@ Selector: `0x6568382f` - first 4 bytes of `blake2b_256("PSP22::balance_of")` "PSP22", "balance_of" ], - "payable": false, "returnType": { "displayName": [ "Balance" @@ -141,7 +139,6 @@ Selector: `0x4d47d921` - first 4 bytes of `blake2b_256("PSP22::allowance")` "PSP22", "allowance" ], - "payable": false, "returnType": { "displayName": [ "Balance" @@ -152,7 +149,7 @@ Selector: `0x4d47d921` - first 4 bytes of `blake2b_256("PSP22::allowance")` } ``` -##### **transfer**(to: AccountId, value: Balance, data: [u8]) +##### **transfer**(to: AccountId, value: Balance, data: [u8]) -> Result<(), PSP22Error> Selector: `0xdb20f9f5` - first 4 bytes of `blake2b_256("PSP22::transfer")` ```json { @@ -193,19 +190,18 @@ Selector: `0xdb20f9f5` - first 4 bytes of `blake2b_256("PSP22::transfer")` "", " # Errors", "", - " Reverts with message `InsufficientBalance` if there are not enough tokens on", + " Reverts with error `InsufficientBalance` if there are not enough tokens on", " the caller's account Balance.", "", - " Reverts with message `ZeroSenderAddress` if sender's address is zero.", + " Reverts with error `ZeroSenderAddress` if sender's address is zero.", "", - " Reverts with message `ZeroRecipientAddress` if recipient's address is zero." + " Reverts with error `ZeroRecipientAddress` if recipient's address is zero." ], "mutates": true, "name": [ "PSP22", "transfer" ], - "payable": false, "returnType": { "displayName": [ "Result" @@ -216,7 +212,7 @@ Selector: `0xdb20f9f5` - first 4 bytes of `blake2b_256("PSP22::transfer")` } ``` -##### **transfer_from**(from: AccountId, to: AccountId, value: Balance, data: [u8]) +##### **transfer_from**(from: AccountId, to: AccountId, value: Balance, data: [u8]) -> Result<(), PSP22Error> Selector: `0x54b3c76e` - first 4 bytes of `blake2b_256("PSP22::transfer_from")` ```json { @@ -269,22 +265,21 @@ Selector: `0x54b3c76e` - first 4 bytes of `blake2b_256("PSP22::transfer_from")` "", " # Errors", "", - " Reverts with message `InsufficientAllowance` if there are not enough tokens allowed", + " Reverts with error `InsufficientAllowance` if there are not enough tokens allowed", " for the caller to withdraw from `from`.", "", - " Reverts with message `InsufficientBalance` if there are not enough tokens on", + " Reverts with error `InsufficientBalance` if there are not enough tokens on", " the the account Balance of `from`.", "", - " Reverts with message `ZeroSenderAddress` if sender's address is zero.", + " Reverts with error `ZeroSenderAddress` if sender's address is zero.", "", - " Reverts with message `ZeroRecipientAddress` if recipient's address is zero." + " Reverts with error `ZeroRecipientAddress` if recipient's address is zero." ], "mutates": true, "name": [ "PSP22", "transfer_from" ], - "payable": false, "returnType": { "displayName": [ "Result" @@ -295,7 +290,7 @@ Selector: `0x54b3c76e` - first 4 bytes of `blake2b_256("PSP22::transfer_from")` } ``` -##### **approve**(spender: AccountId, value: Balance) +##### **approve**(spender: AccountId, value: Balance) -> Result<(), PSP22Error> Selector: `0xb20f1bbd` - first 4 bytes of `blake2b_256("PSP22::approve")` ```json { @@ -329,16 +324,15 @@ Selector: `0xb20f1bbd` - first 4 bytes of `blake2b_256("PSP22::approve")` "", " # Errors", "", - " Reverts with message `ZeroSenderAddress` if sender's address is zero.", + " Reverts with error `ZeroSenderAddress` if sender's address is zero.", "", - " Reverts with message `ZeroRecipientAddress` if recipient's address is zero." + " Reverts with error `ZeroRecipientAddress` if recipient's address is zero." ], "mutates": true, "name": [ "PSP22", "approve" ], - "payable": false, "returnType": { "displayName": [ "Result" @@ -350,7 +344,7 @@ Selector: `0xb20f1bbd` - first 4 bytes of `blake2b_256("PSP22::approve")` ``` -##### **increase_allowance**(spender: AccountId, delta_value: Balance) +##### **increase_allowance**(spender: AccountId, delta_value: Balance) -> Result<(), PSP22Error> Selector: `0x96d6b57a` - first 4 bytes of `blake2b_256("PSP22::increase_allowance")` ```json { @@ -381,16 +375,15 @@ Selector: `0x96d6b57a` - first 4 bytes of `blake2b_256("PSP22::increase_allowanc "", " # Errors", "", - " Reverts with message `ZeroSenderAddress` if sender's address is zero.", + " Reverts with error `ZeroSenderAddress` if sender's address is zero.", "", - " Reverts with message `ZeroRecipientAddress` if recipient's address is zero." + " Reverts with error `ZeroRecipientAddress` if recipient's address is zero." ], "mutates": true, "name": [ "PSP22", "increase_allowance" ], - "payable": false, "returnType": { "displayName": [ "Result" @@ -401,7 +394,7 @@ Selector: `0x96d6b57a` - first 4 bytes of `blake2b_256("PSP22::increase_allowanc } ``` -##### **decrease_allowance**(spender: AccountId, delta_value: Balance) +##### **decrease_allowance**(spender: AccountId, delta_value: Balance) -> Result<(), PSP22Error> Selector: `0xfecb57d5` - first 4 bytes of `blake2b_256("PSP22::decrease_allowance")` ```json { @@ -432,19 +425,18 @@ Selector: `0xfecb57d5` - first 4 bytes of `blake2b_256("PSP22::decrease_allowanc "", " # Errors", "", - " Reverts with message `InsufficientAllowance` if there are not enough tokens allowed", + " Reverts with error `InsufficientAllowance` if there are not enough tokens allowed", " by owner for `spender`.", "", - " Reverts with message `ZeroSenderAddress` if sender's address is zero.", + " Reverts with error `ZeroSenderAddress` if sender's address is zero.", "", - " Reverts with message `ZeroRecipientAddress` if recipient's address is zero." + " Reverts with error `ZeroRecipientAddress` if recipient's address is zero." ], "mutates": true, "name": [ "PSP22", "decrease_allowance" ], - "payable": false, "returnType": { "displayName": [ "Result" @@ -471,7 +463,6 @@ Selector: `0x3d261bd4` - first 4 bytes of `blake2b_256("PSP22Metadata::token_nam "PSP22Metadata", "token_name" ], - "payable": false, "returnType": { "displayName": [ "Option" @@ -495,7 +486,6 @@ Selector: `0x34205be5` - first 4 bytes of `blake2b_256("PSP22Metadata::token_sym "PSP22Metadata", "token_symbol" ], - "payable": false, "returnType": { "displayName": [ "Option" @@ -519,7 +509,6 @@ Selector: `0x7271b782` - first 4 bytes of `blake2b_256("PSP22Metadata::token_dec "PSP22Metadata", "token_decimals" ], - "payable": false, "returnType": { "displayName": [ "u8" @@ -590,7 +579,6 @@ Selector: `0xfda6f1a9` - first 4 bytes of `blake2b_256("PSP22Receiver::before_re "PSP22Receiver", "before_received" ], - "payable": false, "returnType": { "displayName": [ "Result" @@ -831,8 +819,8 @@ type Balance = u128; ``` ### Errors -Suggested methods don't return `Result` (except `before_received`). Instead, they panic. -This panic must be "revert with message" and can contain one of the following messages: +Suggested methods returns `Result`. +Methods will revert the transaction and return Result with Error from this list: ```rust /// PSP22Error From 7003b3003e7f3a75fc82a3001d922207fed92e8a Mon Sep 17 00:00:00 2001 From: Pierre Ossun Date: Tue, 10 Aug 2021 12:12:07 +0200 Subject: [PATCH 4/6] Updated descriptions --- PSPs/drafts/psp-22.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PSPs/drafts/psp-22.md b/PSPs/drafts/psp-22.md index 3941b55..9879721 100644 --- a/PSPs/drafts/psp-22.md +++ b/PSPs/drafts/psp-22.md @@ -819,8 +819,7 @@ type Balance = u128; ``` ### Errors -Suggested methods returns `Result`. -Methods will revert the transaction and return Result with Error from this list: +Suggested methods reverts the transaction and return Result with Error from this list: ```rust /// PSP22Error From c961e7649f4ff9ffa70edd60c5f4e27de505e49e Mon Sep 17 00:00:00 2001 From: Pierre Ossun Date: Tue, 10 Aug 2021 12:12:22 +0200 Subject: [PATCH 5/6] Updated descriptions --- PSPs/drafts/psp-22.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSPs/drafts/psp-22.md b/PSPs/drafts/psp-22.md index 9879721..988094c 100644 --- a/PSPs/drafts/psp-22.md +++ b/PSPs/drafts/psp-22.md @@ -819,7 +819,7 @@ type Balance = u128; ``` ### Errors -Suggested methods reverts the transaction and return Result with Error from this list: +Suggested methods revert the transaction and return Result with Error from this list: ```rust /// PSP22Error From 54e133079002eecc29720c55b737af41c3fbd092 Mon Sep 17 00:00:00 2001 From: Pierre Ossun Date: Tue, 10 Aug 2021 12:28:40 +0200 Subject: [PATCH 6/6] Removed typename --- PSPs/drafts/psp-22.md | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/PSPs/drafts/psp-22.md b/PSPs/drafts/psp-22.md index 988094c..52653ff 100644 --- a/PSPs/drafts/psp-22.md +++ b/PSPs/drafts/psp-22.md @@ -706,8 +706,7 @@ type Balance = u128; "def": { "tuple": [] } - }, - "typeName": "T" + } } ], "name": "Ok" @@ -722,8 +721,7 @@ type Balance = u128; { "fields": [ { - "type": "string", - "typeName": "String" + "type": "string" } ], "name": "Custom" @@ -743,8 +741,7 @@ type Balance = u128; { "fields": [ { - "type": "string", - "typeName": "String" + "type": "string" } ], "name": "SafeTransferCheckFailed" @@ -755,8 +752,7 @@ type Balance = u128; "path": [ "PSP22Error" ] - }, - "typeName": "E" + } } ], "name": "Err" @@ -776,8 +772,7 @@ type Balance = u128; "def": { "tuple": [] } - }, - "typeName": "T" + } } ], "name": "Ok" @@ -792,8 +787,7 @@ type Balance = u128; { "fields": [ { - "type": "string", - "typeName": "String" + "type": "string" } ], "name": "TransferRejected" @@ -804,8 +798,7 @@ type Balance = u128; "path": [ "PSP22ReceiverError" ] - }, - "typeName": "E" + } } ], "name": "Err"