git.delta.rocks / unique-network / refs/commits / c2a34edb0dd4

difftreelog

Merge pull request #413 from UniqueNetwork/feature/erc20-for-refungible

Yaroslav Bolyukin2022-07-22parents: #5ffdcf0 #1792b24.patch.diff
in: master
ERC20 API for refungible tokens

15 files changed

modifiedCargo.lockdiffbeforeafterboth
63206320
6321[[package]]6321[[package]]
6322name = "pallet-refungible"6322name = "pallet-refungible"
6323version = "0.1.1"6323version = "0.1.2"
6324dependencies = [6324dependencies = [
6325 "ethereum",
6326 "evm-coder",
6325 "frame-benchmarking",6327 "frame-benchmarking",
6326 "frame-support",6328 "frame-support",
6327 "frame-system",6329 "frame-system",
6328 "pallet-common",6330 "pallet-common",
6329 "pallet-evm",6331 "pallet-evm",
6332 "pallet-evm-coder-substrate",
6330 "pallet-structure",6333 "pallet-structure",
6331 "parity-scale-codec 3.1.5",6334 "parity-scale-codec 3.1.5",
6332 "scale-info",6335 "scale-info",
modifiedMakefilediffbeforeafterboth
12NONFUNGIBLE_EVM_STUBS=./pallets/nonfungible/src/stubs12NONFUNGIBLE_EVM_STUBS=./pallets/nonfungible/src/stubs
13NONFUNGIBLE_EVM_ABI=./tests/src/eth/nonFungibleAbi.json13NONFUNGIBLE_EVM_ABI=./tests/src/eth/nonFungibleAbi.json
14
15REFUNGIBLE_EVM_STUBS=./pallets/refungible/src/stubs
16RENFUNGIBLE_EVM_ABI=./tests/src/eth/reFungibleAbi.json
17RENFUNGIBLE_TOKEN_EVM_ABI=./tests/src/eth/reFungibleTokenAbi.json
1418
15CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/19CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/
16CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json20CONTRACT_HELPERS_ABI=./tests/src/eth/util/contractHelpersAbi.json
21TESTS_API=./tests/src/eth/api/25TESTS_API=./tests/src/eth/api/
2226
23.PHONY: regenerate_solidity27.PHONY: regenerate_solidity
24regenerate_solidity: UniqueFungible.sol UniqueNFT.sol ContractHelpers.sol CollectionHelpers.sol28regenerate_solidity: UniqueFungible.sol UniqueNFT.sol UniqueRefungibleToken.sol ContractHelpers.sol CollectionHelpers.sol
2529
26UniqueFungible.sol:30UniqueFungible.sol:
27 PACKAGE=pallet-fungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh31 PACKAGE=pallet-fungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
30UniqueNFT.sol:34UniqueNFT.sol:
31 PACKAGE=pallet-nonfungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh35 PACKAGE=pallet-nonfungible NAME=erc::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
32 PACKAGE=pallet-nonfungible NAME=erc::gen_impl OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh36 PACKAGE=pallet-nonfungible NAME=erc::gen_impl OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
37
38UniqueRefungibleToken.sol:
39 PACKAGE=pallet-refungible NAME=erc_token::gen_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
40 PACKAGE=pallet-refungible NAME=erc_token::gen_impl OUTPUT=$(REFUNGIBLE_EVM_STUBS)/$@ ./.maintain/scripts/generate_sol.sh
3341
34ContractHelpers.sol:42ContractHelpers.sol:
35 PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh43 PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=$(TESTS_API)/$@ ./.maintain/scripts/generate_sol.sh
47 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/UniqueNFT.raw ./.maintain/scripts/compile_stub.sh55 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_STUBS)/UniqueNFT.raw ./.maintain/scripts/compile_stub.sh
48 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_ABI) ./.maintain/scripts/generate_abi.sh56 INPUT=$(NONFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(NONFUNGIBLE_EVM_ABI) ./.maintain/scripts/generate_abi.sh
57
58UniqueRefungibleToken: UniqueRefungibleToken.sol
59 INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(REFUNGIBLE_EVM_STUBS)/UniqueRefungibleToken.raw ./.maintain/scripts/compile_stub.sh
60 INPUT=$(REFUNGIBLE_EVM_STUBS)/$< OUTPUT=$(RENFUNGIBLE_TOKEN_EVM_ABI) ./.maintain/scripts/generate_abi.sh
4961
50ContractHelpers: ContractHelpers.sol62ContractHelpers: ContractHelpers.sol
51 INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw ./.maintain/scripts/compile_stub.sh63 INPUT=$(CONTRACT_HELPERS_STUBS)/$< OUTPUT=$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw ./.maintain/scripts/compile_stub.sh
55 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelpers.raw ./.maintain/scripts/compile_stub.sh67 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_STUBS)/CollectionHelpers.raw ./.maintain/scripts/compile_stub.sh
56 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh68 INPUT=$(COLLECTION_HELPER_STUBS)/$< OUTPUT=$(COLLECTION_HELPER_ABI) ./.maintain/scripts/generate_abi.sh
5769
58evm_stubs: UniqueFungible UniqueNFT ContractHelpers CollectionHelpers70evm_stubs: UniqueFungible UniqueNFT UniqueRefungibleToken ContractHelpers CollectionHelpers
5971
60.PHONY: _bench72.PHONY: _bench
61_bench:73_bench:
addedpallets/refungible/CHANGELOG.mddiffbeforeafterboth

no changes

modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
1[package]1[package]
2name = "pallet-refungible"2name = "pallet-refungible"
3version = "0.1.1"3version = "0.1.2"
4license = "GPLv3"4license = "GPLv3"
5edition = "2021"5edition = "2021"
66
11version = '3.1.2'11version = '3.1.2'
1212
13[dependencies]13[dependencies]
14evm-coder = { default-features = false, path = '../../crates/evm-coder' }
15pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
16pallet-common = { default-features = false, path = '../common' }
17pallet-structure = { default-features = false, path = '../structure' }
18struct-versioning = { path = "../../crates/struct-versioning" }
19up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
20
21ethereum = { version = "0.12.0", default-features = false }
22scale-info = { version = "2.0.1", default-features = false, features = ["derive",] }
23
24frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
14frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }25frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
15frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }26frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
27pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }
28sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
16sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }29sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
17sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }30sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
18sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
19pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.24" }
20pallet-common = { default-features = false, path = '../common' }
21pallet-structure = { default-features = false, path = '../structure' }
22up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
23frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.24" }
24scale-info = { version = "2.0.1", default-features = false, features = [
25 "derive",
26] }
27struct-versioning = { path = "../../crates/struct-versioning" }
2831
29[features]32[features]
30default = ["std"]33default = ["std"]
31std = [34std = [
35 "ethereum/std",
36 "evm-coder/std",
37 'frame-benchmarking/std',
32 "frame-support/std",38 "frame-support/std",
33 "frame-system/std",39 "frame-system/std",
34 "sp-runtime/std",40 "pallet-common/std",
35 "sp-std/std",41 "pallet-evm/std",
36 "up-data-structs/std",
37 "pallet-common/std",42 "pallet-evm-coder-substrate/std",
38 "pallet-structure/std",43 "pallet-structure/std",
39 'frame-benchmarking/std',44 "sp-runtime/std",
40 "pallet-evm/std",45 "sp-std/std",
46 "up-data-structs/std",
41]47]
42runtime-benchmarks = [48runtime-benchmarks = [
43 'frame-benchmarking',49 'frame-benchmarking',
44 'frame-support/runtime-benchmarks',50 'frame-support/runtime-benchmarks',
45 'frame-system/runtime-benchmarks',51 'frame-system/runtime-benchmarks',
52 'up-data-structs/runtime-benchmarks',
46]53]
4754
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17extern crate alloc;
17use up_data_structs::TokenId;18use evm_coder::{generate_stubgen, solidity_interface, types::*};
19
18use pallet_common::erc::CommonEvmHandler;20use pallet_common::{CollectionHandle, erc::CollectionCall, erc::CommonEvmHandler};
21
19use pallet_evm::PrecompileHandle;22use pallet_evm::PrecompileHandle;
23use pallet_evm_coder_substrate::call;
2024
21use crate::{Config, RefungibleHandle};25use crate::{Config, RefungibleHandle};
2226
27#[solidity_interface(
28 name = "UniqueRFT",
29 is(via("CollectionHandle<T>", common_mut, Collection),)
30)]
23impl<T: Config> CommonEvmHandler for RefungibleHandle<T> {31impl<T: Config> RefungibleHandle<T> where T::AccountId: From<[u8; 32]> {}
24 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");32
2533// Not a tests, but code generators
26 fn call(34generate_stubgen!(gen_impl, UniqueRFTCall<()>, true);
27 self,
28 _handle: &mut impl PrecompileHandle,
29 ) -> Option<pallet_common::erc::PrecompileResult> {
30 // TODO: Implement RFT variant of ERC721
31 None
32 }
33}
34
35pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);35generate_stubgen!(gen_iface, UniqueRFTCall<()>, false);
3636
37impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T> {37impl<T: Config> CommonEvmHandler for RefungibleHandle<T>
38where
39 T::AccountId: From<[u8; 32]>,
40{
38 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");41 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungible.raw");
39
40 fn call(42 fn call(
41 self,43 self,
42 _handle: &mut impl PrecompileHandle,44 handle: &mut impl PrecompileHandle,
43 ) -> Option<pallet_common::erc::PrecompileResult> {45 ) -> Option<pallet_common::erc::PrecompileResult> {
44 // TODO: Implement RFT variant of ERC2046 call::<T, UniqueRFTCall<T>, _, _>(handle, self)
45 None
46 }47 }
47}48}
4849
addedpallets/refungible/src/erc_token.rsdiffbeforeafterboth

no changes

modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
8787
88#![cfg_attr(not(feature = "std"), no_std)]88#![cfg_attr(not(feature = "std"), no_std)]
8989
90use crate::erc_token::ERC20Events;
91
92use codec::{Encode, Decode, MaxEncodedLen};
93use core::ops::Deref;
94use evm_coder::ToLog;
90use frame_support::{ensure, fail, BoundedVec, transactional, storage::with_transaction};95use frame_support::{BoundedVec, ensure, fail, storage::with_transaction, transactional};
91use up_data_structs::{96use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
92 AccessMode, CollectionId, CustomDataLimit, MAX_REFUNGIBLE_PIECES, TokenId,
93 CreateCollectionData, CreateRefungibleExData, mapping::TokenAddressMapping, budget::Budget,
94 Property, PropertyScope, TrySetProperty, PropertyKey, PropertyValue, PropertyPermission,
95 PropertyKeyPermission,
96};
97use pallet_evm::account::CrossAccountId;97use pallet_evm_coder_substrate::WithRecorder;
98use pallet_common::{98use pallet_common::{
99 Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,99 CommonCollectionOperations, Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
100 CommonCollectionOperations as _,
101};100};
102use pallet_structure::Pallet as PalletStructure;101use pallet_structure::Pallet as PalletStructure;
102use scale_info::TypeInfo;
103use sp_core::H160;
103use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};104use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
104use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};105use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
105use core::ops::Deref;
106use codec::{Encode, Decode, MaxEncodedLen};106use up_data_structs::{
107use scale_info::TypeInfo;107 AccessMode, budget::Budget, CollectionId, CreateCollectionData, CreateRefungibleExData,
108 CustomDataLimit, mapping::TokenAddressMapping, MAX_REFUNGIBLE_PIECES, TokenId, Property,
109 PropertyKey, PropertyKeyPermission, PropertyPermission, PropertyScope, PropertyValue,
110 TrySetProperty,
111};
108112
109pub use pallet::*;113pub use pallet::*;
110#[cfg(feature = "runtime-benchmarks")]114#[cfg(feature = "runtime-benchmarks")]
111pub mod benchmarking;115pub mod benchmarking;
112pub mod common;116pub mod common;
113pub mod erc;117pub mod erc;
118pub mod erc_token;
114pub mod weights;119pub mod weights;
115pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;120pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;
116121
271 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {276 pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {
272 self.0277 self.0
273 }278 }
279 pub fn common_mut(&mut self) -> &mut pallet_common::CollectionHandle<T> {
280 &mut self.0
281 }
274}282}
283
275impl<T: Config> Deref for RefungibleHandle<T> {284impl<T: Config> Deref for RefungibleHandle<T> {
280 }289 }
281}290}
291
292impl<T: Config> WithRecorder<T> for RefungibleHandle<T> {
293 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {
294 self.0.recorder()
295 }
296 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {
297 self.0.into_recorder()
298 }
299}
282300
283impl<T: Config> Pallet<T> {301impl<T: Config> Pallet<T> {
284 /// Get number of RFT tokens in collection302 /// Get number of RFT tokens in collection
460 <Balance<T>>::insert((collection.id, token, owner), balance);478 <Balance<T>>::insert((collection.id, token, owner), balance);
461 }479 }
462 <TotalSupply<T>>::insert((collection.id, token), total_supply);480 <TotalSupply<T>>::insert((collection.id, token), total_supply);
463 // TODO: ERC20 transfer event481
482 <PalletEvm<T>>::deposit_log(
483 ERC20Events::Transfer {
484 from: *owner.as_eth(),
485 to: H160::default(),
486 value: amount.into(),
487 }
488 .to_log(T::EvmTokenAddressMapping::token_to_address(
489 collection.id,
490 token,
491 )),
492 );
464 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(493 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
465 collection.id,494 collection.id,
466 token,495 token,
736 }765 }
737 }766 }
738767
739 // TODO: ERC20 transfer event768 <PalletEvm<T>>::deposit_log(
769 ERC20Events::Transfer {
770 from: *from.as_eth(),
771 to: *to.as_eth(),
772 value: amount.into(),
773 }
774 .to_log(T::EvmTokenAddressMapping::token_to_address(
775 collection.id,
776 token,
777 )),
778 );
740 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(779 <PalletCommon<T>>::deposit_event(CommonEvent::Transfer(
741 collection.id,780 collection.id,
742 token,781 token,
889 continue;928 continue;
890 }929 }
891930
892 // TODO: ERC20 transfer event931 <PalletEvm<T>>::deposit_log(
932 ERC20Events::Transfer {
933 from: H160::default(),
934 to: *user.as_eth(),
935 value: amount.into(),
936 }
937 .to_log(T::EvmTokenAddressMapping::token_to_address(
938 collection.id,
939 TokenId(token_id),
940 )),
941 );
893 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(942 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
894 collection.id,943 collection.id,
895 TokenId(token_id),944 TokenId(token_id),
913 } else {962 } else {
914 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);963 <Allowance<T>>::insert((collection.id, token, sender, spender), amount);
915 }964 }
916 // TODO: ERC20 approval event965
966 <PalletEvm<T>>::deposit_log(
967 ERC20Events::Approval {
968 owner: *sender.as_eth(),
969 spender: *spender.as_eth(),
970 value: amount.into(),
971 }
972 .to_log(T::EvmTokenAddressMapping::token_to_address(
973 collection.id,
974 token,
975 )),
976 );
917 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(977 <PalletCommon<T>>::deposit_event(CommonEvent::Approved(
918 collection.id,978 collection.id,
919 token,979 token,
1092 <Balance<T>>::insert((collection.id, token, owner), amount);1152 <Balance<T>>::insert((collection.id, token, owner), amount);
1093 <TotalSupply<T>>::insert((collection.id, token), amount);1153 <TotalSupply<T>>::insert((collection.id, token), amount);
1154
1155 if amount > total_pieces {
1156 let mint_amount = amount - total_pieces;
1157 <PalletEvm<T>>::deposit_log(
1158 ERC20Events::Transfer {
1159 from: H160::default(),
1160 to: *owner.as_eth(),
1161 value: mint_amount.into(),
1162 }
1163 .to_log(T::EvmTokenAddressMapping::token_to_address(
1164 collection.id,
1165 token,
1166 )),
1167 );
1168 <PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(
1169 collection.id,
1170 token,
1171 owner.clone(),
1172 mint_amount,
1173 ));
1174 } else if total_pieces > amount {
1175 let burn_amount = total_pieces - amount;
1176 <PalletEvm<T>>::deposit_log(
1177 ERC20Events::Transfer {
1178 from: *owner.as_eth(),
1179 to: H160::default(),
1180 value: burn_amount.into(),
1181 }
1182 .to_log(T::EvmTokenAddressMapping::token_to_address(
1183 collection.id,
1184 token,
1185 )),
1186 );
1187 <PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(
1188 collection.id,
1189 token,
1190 owner.clone(),
1191 burn_amount,
1192 ));
1193 }
1194
1094 Ok(())1195 Ok(())
1095 }1196 }
modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterboth

binary blob — no preview

addedpallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth

no changes

modifiedruntime/common/src/dispatch.rsdiffbeforeafterboth
25pub use pallet_common::dispatch::CollectionDispatch;25pub use pallet_common::dispatch::CollectionDispatch;
26use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};26use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};
27use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};27use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};
28use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle, erc::RefungibleTokenHandle};28use pallet_refungible::{
29 Pallet as PalletRefungible, RefungibleHandle, erc_token::RefungibleTokenHandle,
30};
29use up_data_structs::{31use up_data_structs::{
30 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,32 CollectionMode, CreateCollectionData, MAX_DECIMAL_POINTS, mapping::TokenAddressMapping,
addedtests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth

no changes

addedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth

no changes

addedtests/src/eth/reFungibleTokenAbi.jsondiffbeforeafterboth

no changes

modifiedtests/src/refungible.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {default as usingApi, executeTransaction} from './substrate/substrate-api';17import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {19import {
20 createCollectionExpectSuccess,20 createCollectionExpectSuccess,
32 repartitionRFT,32 repartitionRFT,
33 createCollectionWithPropsExpectSuccess,33 createCollectionWithPropsExpectSuccess,
34 getDetailedCollectionInfo,34 getDetailedCollectionInfo,
35 getCreateItemsResult,
36 getDestroyItemsResult,
35} from './util/helpers';37} from './util/helpers';
3638
37import chai from 'chai';39import chai from 'chai';
189 });191 });
190 });192 });
193
194 it('Repartition with increased amount', async () => {
195 await usingApi(async api => {
196 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
197 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
198
199 const tx = api.tx.unique.repartition(collectionId, tokenId, 200n);
200 const events = await submitTransactionAsync(alice, tx);
201 const substrateEvents = getCreateItemsResult(events);
202 expect(substrateEvents).to.include.deep.members([
203 {
204 success: true,
205 collectionId,
206 itemId: tokenId,
207 recipient: {Substrate: alice.address},
208 amount: 100,
209 },
210 ]);
211 });
212 });
213
214 it('Repartition with decreased amount', async () => {
215 await usingApi(async api => {
216 const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
217 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
218
219 const tx = api.tx.unique.repartition(collectionId, tokenId, 50n);
220 const events = await submitTransactionAsync(alice, tx);
221 const substrateEvents = getDestroyItemsResult(events);
222 expect(substrateEvents).to.include.deep.members([
223 {
224 success: true,
225 collectionId,
226 itemId: tokenId,
227 owner: {Substrate: alice.address},
228 amount: 50,
229 },
230 ]);
231 });
232 });
191});233});
192234
193describe('Test Refungible properties:', () => {235describe('Test Refungible properties:', () => {
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
103 collectionId: number;103 collectionId: number;
104 itemId: number;104 itemId: number;
105 recipient?: CrossAccountId;105 recipient?: CrossAccountId;
106 amount?: number;
106}107}
108
109interface DestroyItemResult {
110 success: boolean;
111 collectionId: number;
112 itemId: number;
113 owner: CrossAccountId;
114 amount: number;
115}
107116
108interface TransferResult {117interface TransferResult {
109 collectionId: number;118 collectionId: number;
220 const collectionId = parseInt(data[0].toString(), 10);229 const collectionId = parseInt(data[0].toString(), 10);
221 const itemId = parseInt(data[1].toString(), 10);230 const itemId = parseInt(data[1].toString(), 10);
222 const recipient = normalizeAccountId(data[2].toJSON() as any);231 const recipient = normalizeAccountId(data[2].toJSON() as any);
232 const amount = parseInt(data[3].toString(), 10);
223233
224 const itemRes: CreateItemResult = {234 const itemRes: CreateItemResult = {
225 success: true,235 success: true,
226 collectionId,236 collectionId,
227 itemId,237 itemId,
228 recipient,238 recipient,
239 amount,
229 };240 };
230241
231 results.push(itemRes);242 results.push(itemRes);
255 return result;266 return result;
256}267}
268
269export function getDestroyItemsResult(events: EventRecord[]): DestroyItemResult[] {
270 const results: DestroyItemResult[] = [];
271
272 const genericResult = getGenericResult<DestroyItemResult[]>(events, 'common', 'ItemDestroyed', (data) => {
273 const collectionId = parseInt(data[0].toString(), 10);
274 const itemId = parseInt(data[1].toString(), 10);
275 const owner = normalizeAccountId(data[2].toJSON() as any);
276 const amount = parseInt(data[3].toString(), 10);
277
278 const itemRes: DestroyItemResult = {
279 success: true,
280 collectionId,
281 itemId,
282 owner,
283 amount,
284 };
285
286 results.push(itemRes);
287 return results;
288 });
289
290 if (!genericResult.success) return [];
291 return results;
292}
257293
258export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {294export function getTransferResult(api: ApiPromise, events: EventRecord[]): TransferResult {
259 for (const {event} of events) {295 for (const {event} of events) {