From 3e32e97f29a5ddc521aa6ac4f0a159985d7fb321 Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:42:17 +0200 Subject: [PATCH] Remove contracts related code (#66) * Remove contract related code * remove everything contract related * lint --- .env.example | 3 - .eslintrc.js | 10 +- Dockerfile | 6 - next.config.js | 3 - src/components/Elements/RegionCard/index.tsx | 4 +- .../Selectors/ChainSelector/index.tsx | 2 +- src/components/Modals/Purchase/index.tsx | 27 +- src/components/Modals/Sell/index.tsx | 61 +- src/components/Modals/Transfer/index.tsx | 42 +- src/components/Modals/Unlist/index.tsx | 29 +- src/components/Modals/WalletConnect/index.tsx | 2 +- src/components/Sidebar/index.tsx | 13 - src/contexts/apis/consts.ts | 3 - src/contexts/market/index.tsx | 153 +- src/contexts/regions/index.tsx | 72 +- src/contexts/regions/xc/index.ts | 172 -- src/contexts/tasks/index.tsx | 4 +- src/contracts/market.json | 1586 ------------- src/contracts/xc_regions.json | 1974 ----------------- src/models/consts.ts | 9 +- src/models/types.ts | 18 +- src/pages/_app.tsx | 4 +- src/pages/regions.tsx | 2 +- src/pages/transfer.tsx | 284 +-- src/utils/crossChain/consts.tsx | 15 +- src/utils/crossChain/transfer.tsx | 33 +- src/utils/functions.ts | 6 +- src/utils/native/approve.tsx | 81 - src/utils/native/init.tsx | 39 - src/utils/native/remove.tsx | 32 - src/utils/native/transfer.tsx | 33 +- 31 files changed, 97 insertions(+), 4625 deletions(-) delete mode 100644 src/contexts/regions/xc/index.ts delete mode 100644 src/contracts/market.json delete mode 100644 src/contracts/xc_regions.json delete mode 100644 src/utils/native/approve.tsx delete mode 100644 src/utils/native/init.tsx delete mode 100644 src/utils/native/remove.tsx diff --git a/.env.example b/.env.example index f1b4613d..5c2e725f 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,2 @@ WS_CORETIME_CHAIN="WSS endpoint of the coretime chain" WS_RELAY_CHAIN="WSS endpoint of the coretime relay chain" -WS_CONTRACTS_CHAIN="WSS endpoint of the contracts chain" -CONTRACT_XC_REGIONS="AddressOfXcRegionsContract" -CONTRACT_MARKET="AddressOfCoretimeMarketContract" \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js index e8ed0239..e10b8e98 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,7 +27,15 @@ module.exports = { '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-var-requires': 'off', 'react/display-name': 'off', - '@typescript-eslint/no-unused-vars': 'error', + '@typescript-eslint/no-unused-vars': [ + 'error', + { + vars: 'all', + varsIgnorePattern: '^_', + args: 'after-used', + argsIgnorePattern: '^_', + }, + ], //#region //*=========== Unused Import =========== 'unused-imports/no-unused-imports': 'error', 'unused-imports/no-unused-vars': [ diff --git a/Dockerfile b/Dockerfile index 7da5ea82..ec8f1dfc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,6 @@ COPY . . # Set the necessary environment variables ENV WS_CORETIME_CHAIN="ws://127.0.0.1:9910" ENV WS_RELAY_CHAIN="ws://127.0.0.1:9900" -ENV WS_CONTRACTS_CHAIN="ws://127.0.0.1:9920" - -# Given that Coretime-Mock deploys the contract with no salt we can be sure -# this is the address as long as it is not modified. -ENV CONTRACT_XC_REGIONS="bA3hAXgbErTUWg8uSkcPhuqqHyF1em6AfPbATH9g9QM4HJP" -ENV CONTRACT_MARKET="WdSbRZeLbQm1CqFwWhHoGTvH51Fs1rbQTLHhRDSqDpq4a2b" RUN apk add --no-cache libc6-compat diff --git a/next.config.js b/next.config.js index 13f06b0a..069ea9b1 100644 --- a/next.config.js +++ b/next.config.js @@ -7,9 +7,6 @@ const nextConfig = { env: { WS_CORETIME_CHAIN: process.env.WS_CORETIME_CHAIN || '', WS_RELAY_CHAIN: process.env.WS_RELAY_CHAIN, - WS_CONTRACTS_CHAIN: process.env.WS_CONTRACTS_CHAIN, - CONTRACT_XC_REGIONS: process.env.CONTRACT_XC_REGIONS, - CONTRACT_MARKET: process.env.CONTRACT_MARKET, }, }; diff --git a/src/components/Elements/RegionCard/index.tsx b/src/components/Elements/RegionCard/index.tsx index 4a0a285c..74244fd2 100644 --- a/src/components/Elements/RegionCard/index.tsx +++ b/src/components/Elements/RegionCard/index.tsx @@ -162,8 +162,8 @@ const RegionCardInner = ({ }; const locationToLabel = (location: RegionLocation): string => { - if (location === RegionLocation.CONTRACTS_CHAIN) { - return 'Contracts Chain'; + if (location === RegionLocation.REGIONX_CHAIN) { + return 'RegionX Chain'; } else if (location === RegionLocation.MARKET) { return 'Listed on Market'; } else { diff --git a/src/components/Elements/Selectors/ChainSelector/index.tsx b/src/components/Elements/Selectors/ChainSelector/index.tsx index 90eb8507..1787cb4b 100644 --- a/src/components/Elements/Selectors/ChainSelector/index.tsx +++ b/src/components/Elements/Selectors/ChainSelector/index.tsx @@ -17,7 +17,7 @@ export const ChainSelector = ({ chain, setChain }: ChainSelectorProps) => { onChange={(e) => setChain(e.target.value)} > Coretime Chain - Contracts Chain + RegionX Chain ); diff --git a/src/components/Modals/Purchase/index.tsx b/src/components/Modals/Purchase/index.tsx index 9c9f89d4..e601d5cd 100644 --- a/src/components/Modals/Purchase/index.tsx +++ b/src/components/Modals/Purchase/index.tsx @@ -6,14 +6,12 @@ import { DialogContent, Stack, } from '@mui/material'; -import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon'; +import { useInkathon } from '@scio-labs/use-inkathon'; import { useState } from 'react'; import { ListingCard } from '@/components/Elements/ListingCard'; -import { CONTRACT_MARKET } from '@/contexts/apis/consts'; import { useToast } from '@/contexts/toast'; -import MarketMetadata from '@/contracts/market.json'; import { Listing } from '@/models'; interface PurchaseModalProps { @@ -27,38 +25,21 @@ export const PurchaseModal = ({ onClose, listing, }: PurchaseModalProps) => { - const { activeAccount, api: contractsApi } = useInkathon(); - - const { contract: marketContract } = useContract( - MarketMetadata, - CONTRACT_MARKET - ); + const { activeAccount, api } = useInkathon(); const { toastError, toastSuccess } = useToast(); const [working, setWorking] = useState(false); const purchaseRegion = async () => { - if (!contractsApi || !activeAccount || !marketContract) { + if (!api || !activeAccount) { return; } try { setWorking(true); - const rawRegionId = listing.region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { - U128: rawRegionId.toString(), - }); - - await contractTx( - contractsApi, - activeAccount.address, - marketContract, - 'purchase_region', - { value: listing.currentPrice }, - [id, listing.region.getMetadataVersion()] - ); + // TODO toastSuccess(`Successfully purchased region from sale.`); onClose(); diff --git a/src/components/Modals/Sell/index.tsx b/src/components/Modals/Sell/index.tsx index e2986cd0..5550aac3 100644 --- a/src/components/Modals/Sell/index.tsx +++ b/src/components/Modals/Sell/index.tsx @@ -8,19 +8,16 @@ import { Stack, Typography, } from '@mui/material'; -import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon'; +import { useInkathon } from '@scio-labs/use-inkathon'; import { Region } from 'coretime-utils'; import { useEffect, useState } from 'react'; import { AmountInput, RegionCard } from '@/components/Elements'; import { RecipientSelector } from '@/components/Elements/Selectors/RecipientSelector'; -import { CONTRACT_MARKET, CONTRACT_XC_REGIONS } from '@/contexts/apis/consts'; import { useRegions } from '@/contexts/regions'; import { useToast } from '@/contexts/toast'; -import MarketMetadata from '@/contracts/market.json'; -import XcRegionsMetadata from '@/contracts/xc_regions.json'; -import { CONTRACT_DECIMALS, LISTING_DEPOSIT, RegionMetadata } from '@/models'; +import { RegionMetadata } from '@/models'; interface SellModalProps { open: boolean; @@ -33,16 +30,7 @@ export const SellModal = ({ onClose, regionMetadata, }: SellModalProps) => { - const { activeAccount, api: contractsApi } = useInkathon(); - - const { contract: xcRegionsContract } = useContract( - XcRegionsMetadata, - CONTRACT_XC_REGIONS - ); - const { contract: marketContract } = useContract( - MarketMetadata, - CONTRACT_MARKET - ); + const { activeAccount, api } = useInkathon(); const { fetchRegions } = useRegions(); const { toastError, toastSuccess } = useToast(); @@ -62,24 +50,15 @@ export const SellModal = ({ await listRegion(regionMetadata.region); }; - const approveXcRegion = async (region: Region) => { - if (!contractsApi || !activeAccount || !xcRegionsContract) { + const approveXcRegion = async (_region: Region) => { + if (!api || !activeAccount) { return; } try { setWorking(true); - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { U128: rawRegionId }); - - await contractTx( - contractsApi, - activeAccount.address, - xcRegionsContract, - 'PSP34::approve', - {}, - [CONTRACT_MARKET, id, true] - ); + + // TODO toastSuccess(`Successfully approved region to the market.`); setWorking(false); @@ -93,33 +72,15 @@ export const SellModal = ({ } }; - const listRegion = async (region: Region) => { - if (!contractsApi || !activeAccount || !marketContract) { + const listRegion = async (_region: Region) => { + if (!api || !activeAccount) { return; } try { setWorking(true); - const rawRegionId = region.getEncodedRegionId(contractsApi); - - const id = contractsApi.createType('Id', { - U128: rawRegionId.toString(), - }); - const regionDuration = region.getEnd() - region.getBegin(); - const timeslicePrice = ( - (Number(regionPrice) * Math.pow(10, CONTRACT_DECIMALS)) / - regionDuration / - region.coreOccupancy() - ).toFixed(0); - - await contractTx( - contractsApi, - activeAccount.address, - marketContract, - 'list_region', - { value: LISTING_DEPOSIT }, - [id, timeslicePrice, saleRecipient ? saleRecipient : null] - ); + + // TODO toastSuccess(`Successfully listed region on sale.`); onClose(); diff --git a/src/components/Modals/Transfer/index.tsx b/src/components/Modals/Transfer/index.tsx index 5f795ba8..0ecdaba3 100644 --- a/src/components/Modals/Transfer/index.tsx +++ b/src/components/Modals/Transfer/index.tsx @@ -9,22 +9,17 @@ import { TextField, Typography, } from '@mui/material'; -import { useContract, useInkathon } from '@scio-labs/use-inkathon'; +import { useInkathon } from '@scio-labs/use-inkathon'; import { Region } from 'coretime-utils'; import { useEffect, useState } from 'react'; -import { - transferRegionOnContractsChain, - transferRegionOnCoretimeChain, -} from '@/utils/native/transfer'; +import { transferRegionOnCoretimeChain } from '@/utils/native/transfer'; import { RegionCard } from '@/components/Elements'; import { useCoretimeApi } from '@/contexts/apis'; -import { CONTRACT_XC_REGIONS } from '@/contexts/apis/consts'; import { useRegions } from '@/contexts/regions'; import { useToast } from '@/contexts/toast'; -import XcRegionsMetadata from '@/contracts/xc_regions.json'; import { RegionLocation, RegionMetadata } from '@/models'; interface TransferModalProps { @@ -38,8 +33,7 @@ export const TransferModal = ({ onClose, regionMetadata, }: TransferModalProps) => { - const { activeAccount, activeSigner, api: contractsApi } = useInkathon(); - const { contract } = useContract(XcRegionsMetadata, CONTRACT_XC_REGIONS); + const { activeAccount, activeSigner } = useInkathon(); const { fetchRegions } = useRegions(); const { toastError, toastInfo, toastSuccess } = useToast(); @@ -53,8 +47,6 @@ export const TransferModal = ({ const onTransfer = () => { if (regionMetadata.location === RegionLocation.CORETIME_CHAIN) { transferCoretimeRegion(regionMetadata.region); - } else if (regionMetadata.location === RegionLocation.CONTRACTS_CHAIN) { - transferXcRegion(regionMetadata.region); } }; @@ -89,34 +81,6 @@ export const TransferModal = ({ ); }; - const transferXcRegion = async (region: Region) => { - if (!contractsApi || !activeAccount || !contract) { - return; - } - - setWorking(true); - transferRegionOnContractsChain( - { contractsApi, xcRegionsContract: contract, marketContract: undefined }, - region, - activeAccount.address, - newOwner, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => setWorking(false), - success: () => { - toastSuccess('Successfully transferred the region.'); - onClose(); - fetchRegions(); - }, - error: () => { - toastError(`Failed to transfer the region.`); - setWorking(false); - }, - } - ); - }; - useEffect(() => { setNewOwner(''); }, [open]); diff --git a/src/components/Modals/Unlist/index.tsx b/src/components/Modals/Unlist/index.tsx index 180773aa..2a201a8e 100644 --- a/src/components/Modals/Unlist/index.tsx +++ b/src/components/Modals/Unlist/index.tsx @@ -6,17 +6,15 @@ import { DialogContent, Stack, } from '@mui/material'; -import { contractTx, useContract, useInkathon } from '@scio-labs/use-inkathon'; +import { useInkathon } from '@scio-labs/use-inkathon'; import { Region } from 'coretime-utils'; import { useState } from 'react'; import { RegionCard } from '@/components/Elements'; -import { CONTRACT_MARKET } from '@/contexts/apis/consts'; import { useMarket } from '@/contexts/market'; import { useRegions } from '@/contexts/regions'; import { useToast } from '@/contexts/toast'; -import MarketMetadata from '@/contracts/market.json'; import { RegionMetadata } from '@/models'; interface UnlistModalProps { @@ -30,12 +28,7 @@ export const UnlistModal = ({ onClose, regionMetadata, }: UnlistModalProps) => { - const { activeAccount, api: contractsApi } = useInkathon(); - - const { contract: marketContract } = useContract( - MarketMetadata, - CONTRACT_MARKET - ); + const { activeAccount, api } = useInkathon(); const { fetchRegions } = useRegions(); const { fetchMarket } = useMarket(); @@ -43,27 +36,15 @@ export const UnlistModal = ({ const [working, setWorking] = useState(false); - const unlistRegion = async (region: Region) => { - if (!contractsApi || !activeAccount || !marketContract) { + const unlistRegion = async (_region: Region) => { + if (!api || !activeAccount) { return; } try { setWorking(true); - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { - U128: rawRegionId.toString(), - }); - - await contractTx( - contractsApi, - activeAccount.address, - marketContract, - 'unlist_region', - {}, - [id] - ); + // TODO toastSuccess(`Successfully unlisted region from sale.`); onClose(); diff --git a/src/components/Modals/WalletConnect/index.tsx b/src/components/Modals/WalletConnect/index.tsx index 92a4153f..3f210b86 100644 --- a/src/components/Modals/WalletConnect/index.tsx +++ b/src/components/Modals/WalletConnect/index.tsx @@ -7,7 +7,7 @@ import { List, ListItemButton, } from '@mui/material'; -import { isWalletInstalled,SubstrateWallet } from '@scio-labs/use-inkathon'; +import { isWalletInstalled, SubstrateWallet } from '@scio-labs/use-inkathon'; import { allSubstrateWallets, useInkathon } from '@scio-labs/use-inkathon'; import Image from 'next/image'; diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 0aaf53fe..72582254 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -3,12 +3,10 @@ import ExploreIcon from '@mui/icons-material/Explore'; import HomeIcon from '@mui/icons-material/Home'; import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; import { Box, useTheme } from '@mui/material'; -import { useInkathon } from '@scio-labs/use-inkathon'; import { useRouter } from 'next/router'; import React from 'react'; import { useCoretimeApi, useRelayApi } from '@/contexts/apis'; -import { ApiState } from '@/contexts/apis/types'; import { TransferIcon } from '@/icons'; import styles from './index.module.scss'; @@ -48,16 +46,6 @@ export const Sidebar = () => { const { state: { apiState: coretimeApiState }, } = useCoretimeApi(); - const { isConnected, isConnecting, error, api } = useInkathon(); - - const contractsApiState = - api && isConnected - ? ApiState.READY - : isConnecting - ? ApiState.CONNECTING - : error - ? ApiState.ERROR - : ApiState.DISCONNECTED; const menu = { general: [ @@ -120,7 +108,6 @@ export const Sidebar = () => {
-
); diff --git a/src/contexts/apis/consts.ts b/src/contexts/apis/consts.ts index ea3b64b4..bfaf616a 100644 --- a/src/contexts/apis/consts.ts +++ b/src/contexts/apis/consts.ts @@ -1,5 +1,2 @@ export const WS_RELAY_CHAIN = process.env.WS_RELAY_CHAIN ?? ''; export const WS_CORETIME_CHAIN = process.env.WS_CORETIME_CHAIN ?? ''; -export const WS_CONTRACTS_CHAIN = process.env.WS_CONTRACTS_CHAIN ?? ''; -export const CONTRACT_XC_REGIONS = process.env.CONTRACT_XC_REGIONS ?? ''; -export const CONTRACT_MARKET = process.env.CONTRACT_MARKET ?? ''; diff --git a/src/contexts/market/index.tsx b/src/contexts/market/index.tsx index 25d0a5e2..99d909e7 100644 --- a/src/contexts/market/index.tsx +++ b/src/contexts/market/index.tsx @@ -1,11 +1,3 @@ -import { BN } from '@polkadot/util'; -import { - contractQuery, - decodeOutput, - useContract, - useInkathon, -} from '@scio-labs/use-inkathon'; -import { CoreMask, Region } from 'coretime-utils'; import React, { createContext, useCallback, @@ -14,16 +6,8 @@ import React, { useState, } from 'react'; -import { parseHNStringToString } from '@/utils/functions'; - import { Listing } from '@/models'; -import { CONTRACT_MARKET, CONTRACT_XC_REGIONS } from '../apis/consts'; -import { useCommon } from '../common'; -import { useRegions } from '../regions'; -import MarketMetadata from '../../contracts/market.json'; -import XcRegionsMetadata from '../../contracts/xc_regions.json'; - interface MarketData { loading: boolean; listedRegions: Array; @@ -48,142 +32,13 @@ const MarketProvider = ({ children }: Props) => { const [loading, setLoading] = useState(true); const [listedRegions, setListedRegions] = useState>([]); - const { fetchRegion } = useRegions(); - const context = useCommon(); - - const { api: contractsApi } = useInkathon(); - - const { contract: xcRegionsContract } = useContract( - XcRegionsMetadata, - CONTRACT_XC_REGIONS - ); - const { contract: marketContract } = useContract( - MarketMetadata, - CONTRACT_MARKET - ); - const fetchMarket = useCallback(async () => { - setLoading(true); - if (!contractsApi || !marketContract || !xcRegionsContract) { - return []; - } - const result = await contractQuery( - contractsApi, - '', - marketContract, - 'listed_regions', - {}, - [null] - ); - const { output, isError } = decodeOutput( - result, - marketContract, - 'listed_regions' - ); - if (isError) return []; - const regionIds = output.map((regionId: string) => - parseHNStringToString(regionId) - ); - - const _listedRegions: Array = []; - - for await (const regionId of regionIds) { - const id = contractsApi.createType('Id', { U128: regionId }); - const listingResult = await contractQuery( - contractsApi, - '', - marketContract, - 'listed_region', - {}, - [id] - ); - const { output: listingOutput } = decodeOutput( - listingResult, - marketContract, - 'listed_region' - ); + // TODO - const regionResult = await contractQuery( - contractsApi, - '', - xcRegionsContract, - 'RegionMetadata::get_metadata', - {}, - [id] - ); - const { output: regionOutput } = decodeOutput( - regionResult, - xcRegionsContract, - 'RegionMetadata::get_metadata' - ); - - const region = new Region( - { - begin: regionOutput.Ok.region.begin, - core: regionOutput.Ok.region.core, - mask: new CoreMask(regionOutput.Ok.region.mask), - }, - { - end: regionOutput.Ok.region.end, - owner: listingOutput.Ok.seller, - paid: null, - }, - regionOutput.Ok.version - ); - - /* TODO: For now we will skip this, but this should be uncommented - if (!verifyMetadata(region)) { - continue; - } - */ - - // Skip expired regions. - if (region.consumed(context) > 1) { - continue; - } - - const priceResult = await contractQuery( - contractsApi, - '', - marketContract, - 'region_price', - {}, - [id] - ); - const { output: priceOutput } = decodeOutput( - priceResult, - marketContract, - 'region_price' - ); - - _listedRegions.push( - Listing.construct( - context, - region, - listingOutput.Ok.seller, - new BN(parseHNStringToString(listingOutput.Ok.timeslicePrice)), - new BN(parseHNStringToString(priceOutput.Ok)), - listingOutput.Ok.saleRecepient - ) - ); - } - - setListedRegions(_listedRegions); setLoading(false); - }, [contractsApi, marketContract, xcRegionsContract, context]); - - /// Returns true or false depending whether the metadata matches with the one stored - /// on the coreitme chain. - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const _verifyMetadata = async (region: Region): Promise => { - const actualRegion = await fetchRegion(region.getRegionId()); - - if (actualRegion) { - return actualRegion.getRegionRecord() == region.getRegionRecord(); - } else { - return false; - } - }; + setListedRegions([]); + return []; + }, []); useEffect(() => { fetchMarket(); diff --git a/src/contexts/regions/index.tsx b/src/contexts/regions/index.tsx index b71c02d7..89866899 100644 --- a/src/contexts/regions/index.tsx +++ b/src/contexts/regions/index.tsx @@ -1,4 +1,4 @@ -import { useContract, useInkathon } from '@scio-labs/use-inkathon'; +import { useInkathon } from '@scio-labs/use-inkathon'; import { Region, RegionId } from 'coretime-utils'; import React, { createContext, @@ -11,13 +11,9 @@ import React, { import { RegionLocation, RegionMetadata } from '@/models'; import * as NativeRegions from './native'; -import * as XcRegions from './xc'; import { useCoretimeApi } from '../apis'; -import { CONTRACT_MARKET, CONTRACT_XC_REGIONS } from '../apis/consts'; import { useCommon } from '../common'; import { useTasks } from '../tasks'; -import MarketMetadata from '../../contracts/market.json'; -import XcRegionsMetadata from '../../contracts/xc_regions.json'; interface RegionsData { regions: Array; @@ -50,16 +46,7 @@ const RegionDataProvider = ({ children }: Props) => { const { state: { api: coretimeApi }, } = useCoretimeApi(); - const { api: contractsApi, activeAccount } = useInkathon(); - - const { contract: xcRegionsContract } = useContract( - XcRegionsMetadata, - CONTRACT_XC_REGIONS - ); - const { contract: marketContract } = useContract( - MarketMetadata, - CONTRACT_MARKET - ); + const { api, activeAccount } = useInkathon(); const { fetchTasks } = useTasks(); @@ -77,36 +64,13 @@ const RegionDataProvider = ({ children }: Props) => { const tasks = await fetchTasks(); - const ctx = { - contractsApi, - xcRegionsContract, - marketContract, - }; - const xcRegionIds = await XcRegions.fetchOwnedRegionIds( - ctx, - activeAccount.address - ); - const listedRegionIds = await XcRegions.fetchListedRegionIds( - ctx, - activeAccount.address - ); - const xcRegions = await XcRegions.fetchOwnedRegions( - ctx, - xcRegionIds.concat(listedRegionIds), - activeAccount.address - ); - const brokerRegions = await NativeRegions.fetchRegions(coretimeApi); const _regions: Array = []; - for await (const region of [...brokerRegions, ...xcRegions]) { - const rawId = region.getEncodedRegionId(contractsApi); - const location = determineRegionLocation( - xcRegionIds, - listedRegionIds, - rawId.toString() - ); + for await (const region of [...brokerRegions]) { + const rawId = region.getEncodedRegionId(api); + const location = RegionLocation.CORETIME_CHAIN; const name = localStorage.getItem(`region-${rawId}`) ?? @@ -115,7 +79,7 @@ const RegionDataProvider = ({ children }: Props) => { _regions.push( RegionMetadata.construct( context, - region.getEncodedRegionId(contractsApi), + region.getEncodedRegionId(api), region, name, location, @@ -132,15 +96,7 @@ const RegionDataProvider = ({ children }: Props) => { ) ); setLoading(false); - }, [ - activeAccount, - context, - coretimeApi, - contractsApi, - marketContract, - xcRegionsContract, - fetchTasks, - ]); + }, [activeAccount, context, coretimeApi, api, fetchTasks]); useEffect(() => { fetchRegions(); @@ -153,20 +109,6 @@ const RegionDataProvider = ({ children }: Props) => { localStorage.setItem(`region-${_regions[index].rawId}`, name); }; - const determineRegionLocation = ( - xcRegionIds: string[], - listedRegionIds: string[], - regionId: string - ): RegionLocation => { - if (xcRegionIds.indexOf(regionId) >= 0) { - return RegionLocation.CONTRACTS_CHAIN; - } else if (listedRegionIds.indexOf(regionId) >= 0) { - return RegionLocation.MARKET; - } else { - return RegionLocation.CORETIME_CHAIN; - } - }; - return ( { - const { contractsApi, marketContract } = ctx; - if (!contractsApi || !marketContract || !address) { - return []; - } - - const result = await contractQuery( - contractsApi, - '', - marketContract, - 'listed_regions', - {}, - [address] - ); - - const { output } = decodeOutput(result, marketContract, 'listed_regions'); - - return output.map((regionId: string) => parseHNStringToString(regionId)); -}; - -// Get the region ids of all the regions that the user owns on the contracts chain. -export const fetchOwnedRegionIds = async ( - ctx: ContractContext, - address: string -): Promise> => { - const { contractsApi, xcRegionsContract } = ctx; - if (!contractsApi || !xcRegionsContract || !address) { - return []; - } - - const rawRegionIds = []; - let isError = false; - let index = 0; - - while (!isError) { - const result = await contractQuery( - contractsApi, - '', - xcRegionsContract, - 'PSP34Enumerable::owners_token_by_index', - {}, - [address, index] - ); - - const { - output, - isError: queryError, - decodedOutput, - } = decodeOutput( - result, - xcRegionsContract, - 'PSP34Enumerable::owners_token_by_index' - ); - - if (queryError || decodedOutput === 'TokenNotExists') { - isError = true; - } else { - rawRegionIds.push(parseHNStringToString(output.Ok.U128)); - index++; - } - } - - return rawRegionIds; -}; - -export const fetchOwnedRegions = async ( - ctx: ContractContext, - rawRegionIds: Array, - address: string -): Promise> => { - const regions: Array = []; - - for await (const regionId of rawRegionIds) { - const region = await fetchXcRegion(ctx, regionId, address); - if (region) regions.push(region); - } - - return regions; -}; - -export const fetchXcRegion = async ( - ctx: ContractContext, - rawRegionId: string, - owner: string -): Promise => { - const { contractsApi, xcRegionsContract } = ctx; - if (!contractsApi || !xcRegionsContract) { - return null; - } - - const id = contractsApi.createType('Id', { U128: rawRegionId }); - const result = await contractQuery( - contractsApi, - '', - xcRegionsContract, - 'RegionMetadata::get_metadata', - {}, - [id] - ); - - const { output, isError: queryError } = decodeOutput( - result, - xcRegionsContract, - 'RegionMetadata::get_metadata' - ); - - if (!queryError) { - const versionedRegion = output.Ok; - - // TODO: Once cross-chain region transfers are enabled from the broker pallet ensure - // metadata is correct. - - return new Region( - { - begin: parseHNString(versionedRegion.region.begin), - core: parseHNString(versionedRegion.region.core), - mask: new CoreMask(versionedRegion.region.mask), - }, - { - end: parseHNString(versionedRegion.region.end), - owner, - paid: null, - }, - versionedRegion.version - ); - } else { - return null; - } -}; - -export const getNonWrappedRegions = async ( - ctx: ContractContext, - coretimeApi: ApiPromise, - address: string -): Promise> => { - const { contractsApi } = ctx; - if (!contractsApi || !coretimeApi) return []; - - const nonWrappedRegionIds = await contractsApi.query.uniques.asset.entries(); - const nonWrappedRegions: Array = []; - for await (const entry of nonWrappedRegionIds) { - const rawRegionId = BigInt( - parseHNStringToString((entry[0] as any).toHuman()[1]) - ); - - const regionId = extractRegionIdFromRaw(rawRegionId); - const region = await fetchRegion(coretimeApi, regionId); - const xcRegion = await fetchXcRegion(ctx, rawRegionId.toString(), address); - - if (region && !xcRegion) nonWrappedRegions.push(region); - } - - return nonWrappedRegions; -}; diff --git a/src/contexts/tasks/index.tsx b/src/contexts/tasks/index.tsx index c89c211d..a853729b 100644 --- a/src/contexts/tasks/index.tsx +++ b/src/contexts/tasks/index.tsx @@ -43,7 +43,7 @@ const TaskDataProvider = ({ children }: Props) => { const { state: { api: coretimeApi, apiState: coretimeApiState }, } = useCoretimeApi(); - const { api: contractsApi } = useInkathon(); + const { api } = useInkathon(); const STORAGE_ITEM_KEY = 'tasks'; @@ -71,7 +71,7 @@ const TaskDataProvider = ({ children }: Props) => { { end: 0, owner: '', paid: null }, 0 ); - tasks[region.getEncodedRegionId(contractsApi).toString()] = taskId + tasks[region.getEncodedRegionId(api).toString()] = taskId ? parseHNString(taskId) : null; }); diff --git a/src/contracts/market.json b/src/contracts/market.json deleted file mode 100644 index f68305dc..00000000 --- a/src/contracts/market.json +++ /dev/null @@ -1,1586 +0,0 @@ -{ - "source": { - "hash": "0x9af27ef8c1c88b478dffa79ceede1e6aa73ec13db904ccdab2c42f09d1555d0e", - "language": "ink! 4.3.0", - "compiler": "rustc 1.76.0-nightly", - "build_info": { - "build_mode": "Debug", - "cargo_contract_version": "3.2.0", - "rust_toolchain": "nightly-aarch64-apple-darwin", - "wasm_opt_settings": { - "keep_debug_symbols": false, - "optimization_passes": "Z" - } - } - }, - "contract": { - "name": "coretime_market", - "version": "0.1.0", - "authors": [ - "RegionX " - ], - "description": "Secondary Coretime marketpalce contract." - }, - "spec": { - "constructors": [ - { - "args": [ - { - "label": "xc_regions_contract", - "type": { - "displayName": [ - "AccountId" - ], - "type": 0 - } - }, - { - "label": "listing_deposit", - "type": { - "displayName": [ - "Balance" - ], - "type": 3 - } - }, - { - "label": "timeslice_period", - "type": { - "displayName": [ - "BlockNumber" - ], - "type": 4 - } - } - ], - "default": false, - "docs": [], - "label": "new", - "payable": false, - "returnType": { - "displayName": [ - "ink_primitives", - "ConstructorResult" - ], - "type": 6 - }, - "selector": "0x9bae9d5e" - } - ], - "docs": [], - "environment": { - "accountId": { - "displayName": [ - "AccountId" - ], - "type": 0 - }, - "balance": { - "displayName": [ - "Balance" - ], - "type": 3 - }, - "blockNumber": { - "displayName": [ - "BlockNumber" - ], - "type": 4 - }, - "chainExtension": { - "displayName": [ - "ChainExtension" - ], - "type": 29 - }, - "hash": { - "displayName": [ - "Hash" - ], - "type": 28 - }, - "maxEventTopics": 4, - "timestamp": { - "displayName": [ - "Timestamp" - ], - "type": 14 - } - }, - "events": [ - { - "args": [ - { - "docs": [ - " The identifier of the region that got listed on sale." - ], - "indexed": true, - "label": "region_id", - "type": { - "displayName": [ - "RawRegionId" - ], - "type": 3 - } - }, - { - "docs": [ - " The per timeslice price of the listed region." - ], - "indexed": false, - "label": "timeslice_price", - "type": { - "displayName": [ - "Balance" - ], - "type": 3 - } - }, - { - "docs": [ - " The seller of the region" - ], - "indexed": false, - "label": "seller", - "type": { - "displayName": [ - "AccountId" - ], - "type": 0 - } - }, - { - "docs": [ - " The sale revenue recipient." - ], - "indexed": false, - "label": "sale_recepient", - "type": { - "displayName": [ - "AccountId" - ], - "type": 0 - } - }, - { - "docs": [ - " The metadata version of the region." - ], - "indexed": false, - "label": "metadata_version", - "type": { - "displayName": [ - "Version" - ], - "type": 4 - } - } - ], - "docs": [], - "label": "RegionListed" - }, - { - "args": [ - { - "docs": [ - " The identifier of the region that got unlisted from sale." - ], - "indexed": true, - "label": "region_id", - "type": { - "displayName": [ - "RawRegionId" - ], - "type": 3 - } - }, - { - "docs": [ - " The account that removed the region from sale." - ], - "indexed": false, - "label": "caller", - "type": { - "displayName": [ - "AccountId" - ], - "type": 0 - } - } - ], - "docs": [], - "label": "RegionUnlisted" - }, - { - "args": [ - { - "docs": [ - " The identifier of the region that got purchased." - ], - "indexed": true, - "label": "region_id", - "type": { - "displayName": [ - "RawRegionId" - ], - "type": 3 - } - }, - { - "docs": [ - " The buyer of the region" - ], - "indexed": false, - "label": "buyer", - "type": { - "displayName": [ - "AccountId" - ], - "type": 0 - } - }, - { - "docs": [ - " The total price paid for the listed region." - ], - "indexed": false, - "label": "total_price", - "type": { - "displayName": [ - "Balance" - ], - "type": 3 - } - } - ], - "docs": [], - "label": "RegionPurchased" - }, - { - "args": [ - { - "docs": [ - " The identifier of the region that got its price updated." - ], - "indexed": true, - "label": "region_id", - "type": { - "displayName": [ - "RawRegionId" - ], - "type": 3 - } - }, - { - "docs": [ - " The new per timeslice price." - ], - "indexed": false, - "label": "new_timeslice_price", - "type": { - "displayName": [ - "Balance" - ], - "type": 3 - } - } - ], - "docs": [], - "label": "RegionPriceUpdated" - } - ], - "lang_error": { - "displayName": [ - "ink", - "LangError" - ], - "type": 8 - }, - "messages": [ - { - "args": [], - "default": false, - "docs": [], - "label": "xc_regions_contract", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 9 - }, - "selector": "0xa4edc593" - }, - { - "args": [ - { - "label": "maybe_who", - "type": { - "displayName": [ - "Option" - ], - "type": 10 - } - } - ], - "default": false, - "docs": [], - "label": "listed_regions", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 11 - }, - "selector": "0xa2cf234e" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "Id" - ], - "type": 12 - } - } - ], - "default": false, - "docs": [], - "label": "listed_region", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 16 - }, - "selector": "0x67d48f4e" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "Id" - ], - "type": 12 - } - } - ], - "default": false, - "docs": [], - "label": "region_price", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 24 - }, - "selector": "0x6f91fe12" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "Id" - ], - "type": 12 - } - }, - { - "label": "timeslice_price", - "type": { - "displayName": [ - "Balance" - ], - "type": 3 - } - }, - { - "label": "sale_recepient", - "type": { - "displayName": [ - "Option" - ], - "type": 10 - } - } - ], - "default": false, - "docs": [ - " A function for listing a region on sale.", - "", - " ## Arguments:", - " - `region_id`: The `u128` encoded identifier of the region that the caller intends to", - " list for sale.", - " - `timeslice_price`: The price per a single timeslice.", - " - `sale_recepient`: The `AccountId` receiving the payment from the sale. If not", - " specified this will be the caller.", - "", - " Before making this call, the caller must first approve their region to the market", - " contract, as it will be transferred to the contract when listed for sale.", - "", - " This call is payable because listing a region requires a deposit from the user. This", - " deposit will be returned upon unlisting the region from sale. The rationale behind this", - " requirement is to prevent the contract state from becoming bloated with regions that", - " have expired." - ], - "label": "list_region", - "mutates": true, - "payable": true, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 26 - }, - "selector": "0xad229eb3" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "Id" - ], - "type": 12 - } - } - ], - "default": false, - "docs": [ - " A function for unlisting a region on sale.", - "", - " ## Arguments:", - " - `region_id`: The `u128` encoded identifier of the region that the caller intends to", - " unlist from sale.", - "", - " In case the region is expired, this is callable by anyone and the caller will receive", - " the listing deposit as a reward." - ], - "label": "unlist_region", - "mutates": true, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 26 - }, - "selector": "0x2cda3dc9" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "Id" - ], - "type": 12 - } - }, - { - "label": "new_timeslice_price", - "type": { - "displayName": [ - "Balance" - ], - "type": 3 - } - } - ], - "default": false, - "docs": [ - " A function for updating a listed region's price.", - "", - " ## Arguments:", - " - `region_id`: The `u128` encoded identifier of the region being listed for sale.", - " - `timeslice_price`: The new per timeslice price of the region." - ], - "label": "update_region_price", - "mutates": true, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 26 - }, - "selector": "0x90fd261d" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "Id" - ], - "type": 12 - } - }, - { - "label": "metadata_version", - "type": { - "displayName": [ - "Version" - ], - "type": 4 - } - } - ], - "default": false, - "docs": [ - " A function for purchasing a region listed on sale.", - "", - " ## Arguments:", - " - `region_id`: The `u128` encoded identifier of the region being listed for sale.", - " - `metadata_version`: The required metadata version for the region. If the", - " `metadata_version` does not match the current version stored in the xc-regions", - " contract the purchase will fail.", - "", - " IMPORTANT NOTE: The client is responsible for ensuring that the metadata of the listed", - " region is correct." - ], - "label": "purchase_region", - "mutates": true, - "payable": true, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 26 - }, - "selector": "0xa2f9e3b0" - } - ] - }, - "storage": { - "root": { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "root": { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x17f3ca29", - "ty": 0 - } - }, - "name": "seller" - }, - { - "layout": { - "leaf": { - "key": "0x17f3ca29", - "ty": 3 - } - }, - "name": "timeslice_price" - }, - { - "layout": { - "leaf": { - "key": "0x17f3ca29", - "ty": 0 - } - }, - "name": "sale_recepient" - }, - { - "layout": { - "leaf": { - "key": "0x17f3ca29", - "ty": 4 - } - }, - "name": "metadata_version" - } - ], - "name": "Listing" - } - }, - "root_key": "0x17f3ca29" - } - }, - "name": "listings" - }, - { - "layout": { - "leaf": { - "key": "0x00000000", - "ty": 5 - } - }, - "name": "listed_regions" - }, - { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x00000000", - "ty": 0 - } - }, - "name": "xc_regions_contract" - }, - { - "layout": { - "leaf": { - "key": "0x00000000", - "ty": 3 - } - }, - "name": "listing_deposit" - }, - { - "layout": { - "leaf": { - "key": "0x00000000", - "ty": 4 - } - }, - "name": "timeslice_period" - } - ], - "name": "Config" - } - }, - "name": "config" - } - ], - "name": "CoretimeMarket" - } - }, - "root_key": "0x00000000" - } - }, - "types": [ - { - "id": 0, - "type": { - "def": { - "composite": { - "fields": [ - { - "type": 1, - "typeName": "[u8; 32]" - } - ] - } - }, - "path": [ - "ink_primitives", - "types", - "AccountId" - ] - } - }, - { - "id": 1, - "type": { - "def": { - "array": { - "len": 32, - "type": 2 - } - } - } - }, - { - "id": 2, - "type": { - "def": { - "primitive": "u8" - } - } - }, - { - "id": 3, - "type": { - "def": { - "primitive": "u128" - } - } - }, - { - "id": 4, - "type": { - "def": { - "primitive": "u32" - } - } - }, - { - "id": 5, - "type": { - "def": { - "sequence": { - "type": 3 - } - } - } - }, - { - "id": 6, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 7 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 8 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 7 - }, - { - "name": "E", - "type": 8 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 7, - "type": { - "def": { - "tuple": [] - } - } - }, - { - "id": 8, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 1, - "name": "CouldNotReadInput" - } - ] - } - }, - "path": [ - "ink_primitives", - "LangError" - ] - } - }, - { - "id": 9, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 0 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 8 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 0 - }, - { - "name": "E", - "type": 8 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 10, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "None" - }, - { - "fields": [ - { - "type": 0 - } - ], - "index": 1, - "name": "Some" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 0 - } - ], - "path": [ - "Option" - ] - } - }, - { - "id": 11, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 5 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 8 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 5 - }, - { - "name": "E", - "type": 8 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 12, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 2, - "typeName": "u8" - } - ], - "index": 0, - "name": "U8" - }, - { - "fields": [ - { - "type": 13, - "typeName": "u16" - } - ], - "index": 1, - "name": "U16" - }, - { - "fields": [ - { - "type": 4, - "typeName": "u32" - } - ], - "index": 2, - "name": "U32" - }, - { - "fields": [ - { - "type": 14, - "typeName": "u64" - } - ], - "index": 3, - "name": "U64" - }, - { - "fields": [ - { - "type": 3, - "typeName": "u128" - } - ], - "index": 4, - "name": "U128" - }, - { - "fields": [ - { - "type": 15, - "typeName": "Vec" - } - ], - "index": 5, - "name": "Bytes" - } - ] - } - }, - "path": [ - "openbrush_contracts", - "traits", - "types", - "Id" - ] - } - }, - { - "id": 13, - "type": { - "def": { - "primitive": "u16" - } - } - }, - { - "id": 14, - "type": { - "def": { - "primitive": "u64" - } - } - }, - { - "id": 15, - "type": { - "def": { - "sequence": { - "type": 2 - } - } - } - }, - { - "id": 16, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 17 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 8 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 17 - }, - { - "name": "E", - "type": 8 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 17, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 18 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 20 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 18 - }, - { - "name": "E", - "type": 20 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 18, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "None" - }, - { - "fields": [ - { - "type": 19 - } - ], - "index": 1, - "name": "Some" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 19 - } - ], - "path": [ - "Option" - ] - } - }, - { - "id": 19, - "type": { - "def": { - "composite": { - "fields": [ - { - "name": "seller", - "type": 0, - "typeName": "AccountId" - }, - { - "name": "timeslice_price", - "type": 3, - "typeName": "Balance" - }, - { - "name": "sale_recepient", - "type": 0, - "typeName": "AccountId" - }, - { - "name": "metadata_version", - "type": 4, - "typeName": "Version" - } - ] - } - }, - "path": [ - "coretime_market", - "types", - "Listing" - ] - } - }, - { - "id": 20, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "ArithmeticError" - }, - { - "index": 1, - "name": "InvalidRegionId" - }, - { - "index": 2, - "name": "RegionExpired" - }, - { - "index": 3, - "name": "MissingDeposit" - }, - { - "index": 4, - "name": "RegionNotListed" - }, - { - "index": 5, - "name": "InsufficientFunds" - }, - { - "index": 6, - "name": "MetadataNotMatching" - }, - { - "index": 7, - "name": "TransferFailed" - }, - { - "index": 8, - "name": "NotAllowed" - }, - { - "fields": [ - { - "type": 21, - "typeName": "PSP34Error" - } - ], - "index": 9, - "name": "XcRegionsPsp34Error" - }, - { - "fields": [ - { - "type": 23, - "typeName": "XcRegionsError" - } - ], - "index": 10, - "name": "XcRegionsMetadataError" - } - ] - } - }, - "path": [ - "coretime_market", - "types", - "MarketError" - ] - } - }, - { - "id": 21, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 22, - "typeName": "String" - } - ], - "index": 0, - "name": "Custom" - }, - { - "index": 1, - "name": "SelfApprove" - }, - { - "index": 2, - "name": "NotApproved" - }, - { - "index": 3, - "name": "TokenExists" - }, - { - "index": 4, - "name": "TokenNotExists" - }, - { - "fields": [ - { - "type": 22, - "typeName": "String" - } - ], - "index": 5, - "name": "SafeTransferCheckFailed" - } - ] - } - }, - "path": [ - "openbrush_contracts", - "traits", - "errors", - "psp34", - "PSP34Error" - ] - } - }, - { - "id": 22, - "type": { - "def": { - "primitive": "str" - } - } - }, - { - "id": 23, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "InvalidRegionId" - }, - { - "index": 1, - "name": "CannotInitialize" - }, - { - "index": 2, - "name": "CannotRemove" - }, - { - "index": 3, - "name": "MetadataNotFound" - }, - { - "index": 4, - "name": "InvalidMetadata" - }, - { - "index": 5, - "name": "VersionNotFound" - }, - { - "index": 6, - "name": "RuntimeError" - }, - { - "fields": [ - { - "type": 21, - "typeName": "PSP34Error" - } - ], - "index": 7, - "name": "Psp34" - } - ] - } - }, - "path": [ - "xc_regions", - "types", - "XcRegionsError" - ] - } - }, - { - "id": 24, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 25 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 8 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 25 - }, - { - "name": "E", - "type": 8 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 25, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 3 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 20 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 3 - }, - { - "name": "E", - "type": 20 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 26, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 27 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 8 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 27 - }, - { - "name": "E", - "type": 8 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 27, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 7 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 20 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 7 - }, - { - "name": "E", - "type": 20 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 28, - "type": { - "def": { - "composite": { - "fields": [ - { - "type": 1, - "typeName": "[u8; 32]" - } - ] - } - }, - "path": [ - "ink_primitives", - "types", - "Hash" - ] - } - }, - { - "id": 29, - "type": { - "def": { - "composite": {} - }, - "path": [ - "extension", - "Extension" - ] - } - } - ], - "version": "4" -} \ No newline at end of file diff --git a/src/contracts/xc_regions.json b/src/contracts/xc_regions.json deleted file mode 100644 index 8deed385..00000000 --- a/src/contracts/xc_regions.json +++ /dev/null @@ -1,1974 +0,0 @@ -{ - "source": { - "hash": "0x895db9047b76049cc87dedcbd9640bed81af89b406f1402d0d70c6928b6b2151", - "language": "ink! 4.3.0", - "compiler": "rustc 1.76.0-nightly", - "build_info": { - "build_mode": "Debug", - "cargo_contract_version": "3.2.0", - "rust_toolchain": "nightly-aarch64-apple-darwin", - "wasm_opt_settings": { - "keep_debug_symbols": false, - "optimization_passes": "Z" - } - } - }, - "contract": { - "name": "xc_regions", - "version": "0.1.0", - "authors": [ - "RegionX " - ], - "description": "Cross-chain Regions contracts." - }, - "spec": { - "constructors": [ - { - "args": [], - "default": false, - "docs": [], - "label": "new", - "payable": false, - "returnType": { - "displayName": [ - "ink_primitives", - "ConstructorResult" - ], - "type": 9 - }, - "selector": "0x9bae9d5e" - } - ], - "docs": [], - "environment": { - "accountId": { - "displayName": [ - "AccountId" - ], - "type": 0 - }, - "balance": { - "displayName": [ - "Balance" - ], - "type": 5 - }, - "blockNumber": { - "displayName": [ - "BlockNumber" - ], - "type": 4 - }, - "chainExtension": { - "displayName": [ - "ChainExtension" - ], - "type": 36 - }, - "hash": { - "displayName": [ - "Hash" - ], - "type": 35 - }, - "maxEventTopics": 4, - "timestamp": { - "displayName": [ - "Timestamp" - ], - "type": 7 - } - }, - "events": [ - { - "args": [ - { - "docs": [ - " The identifier of the region that got initialized." - ], - "indexed": true, - "label": "region_id", - "type": { - "displayName": [ - "RawRegionId" - ], - "type": 5 - } - }, - { - "docs": [ - " The associated metadata." - ], - "indexed": false, - "label": "metadata", - "type": { - "displayName": [ - "Region" - ], - "type": 17 - } - }, - { - "docs": [ - " The version of the metadata. This is incremented by the contract each time the same", - " region is initialized." - ], - "indexed": false, - "label": "version", - "type": { - "displayName": [ - "Version" - ], - "type": 4 - } - } - ], - "docs": [], - "label": "RegionInitialized" - }, - { - "args": [ - { - "docs": [ - " The identifier of the region that got removed." - ], - "indexed": true, - "label": "region_id", - "type": { - "displayName": [ - "RawRegionId" - ], - "type": 5 - } - } - ], - "docs": [], - "label": "RegionRemoved" - } - ], - "lang_error": { - "displayName": [ - "ink", - "LangError" - ], - "type": 10 - }, - "messages": [ - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "regionmetadata_external", - "RemoveInput1" - ], - "type": 11 - } - } - ], - "default": false, - "docs": [ - " A function to return the region to its owner.", - "", - " This process involves burning the wrapped region and eliminating its associated", - " metadata.", - "", - " Only the owner of the wrapped region can call this function.", - "", - " ## Arguments:", - " - `raw_region_id` - The `u128` encoded region identifier.", - "", - " ## Events:", - " On success this ink message emits the `RegionRemoved` event." - ], - "label": "RegionMetadata::remove", - "mutates": true, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 12 - }, - "selector": "0xc1e3b44f" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "regionmetadata_external", - "InitInput1" - ], - "type": 11 - } - }, - { - "label": "metadata", - "type": { - "displayName": [ - "regionmetadata_external", - "InitInput2" - ], - "type": 17 - } - } - ], - "default": false, - "docs": [ - " A function for minting a wrapped xcRegion and initializing the metadata of it. It can", - " only be called if the specified region exists on this chain and the caller is the actual", - " owner of the region.", - "", - " ## Arguments:", - " - `raw_region_id` - The `u128` encoded region identifier.", - " - `region` - The corresponding region metadata.", - "", - " This function conducts a sanity check to verify that the metadata derived from the", - " `raw_region_id` aligns with the respective components of the metadata supplied through", - " the region argument.", - "", - " If this is not the first time that this region is inititalized, the metadata version", - " will get incremented.", - "", - " The underlying region will be transferred to this contract, and in response, a wrapped", - " token will be minted for the caller.", - "", - " NOTE: Prior to invoking this ink message, the caller must grant approval to the contract", - " for the region, enabling its transfer.", - "", - " ## Events:", - " On success this ink message emits the `RegionInitialized` event." - ], - "label": "RegionMetadata::init", - "mutates": true, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 12 - }, - "selector": "0xd8354645" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "regionmetadata_external", - "GetMetadataInput1" - ], - "type": 11 - } - } - ], - "default": false, - "docs": [ - " A function to retrieve all metadata associated with a specific region.", - "", - " The function returns a `VersionedRegion`, encompassing the version of the retrieved", - " metadata that is intended for client-side verification.", - "", - " ## Arguments:", - " - `raw_region_id` - The `u128` encoded region identifier." - ], - "label": "RegionMetadata::get_metadata", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 20 - }, - "selector": "0x22c5cfd4" - }, - { - "args": [ - { - "label": "to", - "type": { - "displayName": [ - "psp34_external", - "TransferInput1" - ], - "type": 0 - } - }, - { - "label": "id", - "type": { - "displayName": [ - "psp34_external", - "TransferInput2" - ], - "type": 11 - } - }, - { - "label": "data", - "type": { - "displayName": [ - "psp34_external", - "TransferInput3" - ], - "type": 8 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34::transfer", - "mutates": true, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 23 - }, - "selector": "0x3128d61b" - }, - { - "args": [], - "default": false, - "docs": [], - "label": "PSP34::total_supply", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 25 - }, - "selector": "0x628413fe" - }, - { - "args": [ - { - "label": "owner", - "type": { - "displayName": [ - "psp34_external", - "BalanceOfInput1" - ], - "type": 0 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34::balance_of", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 26 - }, - "selector": "0xcde7e55f" - }, - { - "args": [ - { - "label": "id", - "type": { - "displayName": [ - "psp34_external", - "OwnerOfInput1" - ], - "type": 11 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34::owner_of", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 27 - }, - "selector": "0x1168624d" - }, - { - "args": [], - "default": false, - "docs": [], - "label": "PSP34::collection_id", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 29 - }, - "selector": "0xffa27a5f" - }, - { - "args": [ - { - "label": "owner", - "type": { - "displayName": [ - "psp34_external", - "AllowanceInput1" - ], - "type": 0 - } - }, - { - "label": "operator", - "type": { - "displayName": [ - "psp34_external", - "AllowanceInput2" - ], - "type": 0 - } - }, - { - "label": "id", - "type": { - "displayName": [ - "psp34_external", - "AllowanceInput3" - ], - "type": 30 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34::allowance", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 31 - }, - "selector": "0x4790f55a" - }, - { - "args": [ - { - "label": "operator", - "type": { - "displayName": [ - "psp34_external", - "ApproveInput1" - ], - "type": 0 - } - }, - { - "label": "id", - "type": { - "displayName": [ - "psp34_external", - "ApproveInput2" - ], - "type": 30 - } - }, - { - "label": "approved", - "type": { - "displayName": [ - "psp34_external", - "ApproveInput3" - ], - "type": 32 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34::approve", - "mutates": true, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 23 - }, - "selector": "0x1932a8b0" - }, - { - "args": [ - { - "label": "index", - "type": { - "displayName": [ - "psp34enumerable_external", - "TokenByIndexInput1" - ], - "type": 5 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34Enumerable::token_by_index", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 33 - }, - "selector": "0xcd0340d0" - }, - { - "args": [ - { - "label": "owner", - "type": { - "displayName": [ - "psp34enumerable_external", - "OwnersTokenByIndexInput1" - ], - "type": 0 - } - }, - { - "label": "index", - "type": { - "displayName": [ - "psp34enumerable_external", - "OwnersTokenByIndexInput2" - ], - "type": 5 - } - } - ], - "default": false, - "docs": [], - "label": "PSP34Enumerable::owners_token_by_index", - "mutates": false, - "payable": false, - "returnType": { - "displayName": [ - "ink", - "MessageResult" - ], - "type": 33 - }, - "selector": "0x3bcfb511" - } - ] - }, - "storage": { - "root": { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0x252d8eda", - "ty": 0 - } - }, - "root_key": "0x252d8eda" - } - }, - "name": "token_owner" - }, - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0xcb1393da", - "ty": 3 - } - }, - "root_key": "0xcb1393da" - } - }, - "name": "operator_approvals" - }, - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0xf957bbd8", - "ty": 4 - } - }, - "root_key": "0xf957bbd8" - } - }, - "name": "owned_tokens_count" - }, - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0xe3d7d04e", - "ty": 5 - } - }, - "root_key": "0xe3d7d04e" - } - }, - "name": "total_supply" - } - ], - "name": "Data" - } - }, - "name": "psp34" - }, - { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0x2d2b79f3", - "ty": 0 - } - }, - "root_key": "0x2d2b79f3" - } - }, - "name": "token_owner" - }, - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0x5b0030d8", - "ty": 3 - } - }, - "root_key": "0x5b0030d8" - } - }, - "name": "operator_approvals" - }, - { - "layout": { - "root": { - "layout": { - "enum": { - "dispatchKey": "0x1bd7db1e", - "name": "Id", - "variants": { - "0": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x1bd7db1e", - "ty": 2 - } - }, - "name": "0" - } - ], - "name": "U8" - }, - "1": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x1bd7db1e", - "ty": 6 - } - }, - "name": "0" - } - ], - "name": "U16" - }, - "2": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x1bd7db1e", - "ty": 4 - } - }, - "name": "0" - } - ], - "name": "U32" - }, - "3": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x1bd7db1e", - "ty": 7 - } - }, - "name": "0" - } - ], - "name": "U64" - }, - "4": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x1bd7db1e", - "ty": 5 - } - }, - "name": "0" - } - ], - "name": "U128" - }, - "5": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x1bd7db1e", - "ty": 8 - } - }, - "name": "0" - } - ], - "name": "Bytes" - } - } - } - }, - "root_key": "0x1bd7db1e" - } - }, - "name": "balances" - } - ], - "name": "Data" - } - }, - "name": "enumerable" - }, - { - "layout": { - "root": { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "leaf": { - "key": "0x90333d95", - "ty": 4 - } - }, - "name": "begin" - }, - { - "layout": { - "leaf": { - "key": "0x90333d95", - "ty": 4 - } - }, - "name": "end" - }, - { - "layout": { - "leaf": { - "key": "0x90333d95", - "ty": 6 - } - }, - "name": "core" - }, - { - "layout": { - "struct": { - "fields": [ - { - "layout": { - "array": { - "layout": { - "leaf": { - "key": "0x90333d95", - "ty": 2 - } - }, - "len": 10, - "offset": "0x90333d95" - } - }, - "name": "0" - } - ], - "name": "CoreMask" - } - }, - "name": "mask" - } - ], - "name": "Region" - } - }, - "root_key": "0x90333d95" - } - }, - "name": "regions" - }, - { - "layout": { - "root": { - "layout": { - "leaf": { - "key": "0xb00e1336", - "ty": 4 - } - }, - "root_key": "0xb00e1336" - } - }, - "name": "metadata_versions" - } - ], - "name": "XcRegions" - } - }, - "root_key": "0x00000000" - } - }, - "types": [ - { - "id": 0, - "type": { - "def": { - "composite": { - "fields": [ - { - "type": 1, - "typeName": "[u8; 32]" - } - ] - } - }, - "path": [ - "ink_primitives", - "types", - "AccountId" - ] - } - }, - { - "id": 1, - "type": { - "def": { - "array": { - "len": 32, - "type": 2 - } - } - } - }, - { - "id": 2, - "type": { - "def": { - "primitive": "u8" - } - } - }, - { - "id": 3, - "type": { - "def": { - "tuple": [] - } - } - }, - { - "id": 4, - "type": { - "def": { - "primitive": "u32" - } - } - }, - { - "id": 5, - "type": { - "def": { - "primitive": "u128" - } - } - }, - { - "id": 6, - "type": { - "def": { - "primitive": "u16" - } - } - }, - { - "id": 7, - "type": { - "def": { - "primitive": "u64" - } - } - }, - { - "id": 8, - "type": { - "def": { - "sequence": { - "type": 2 - } - } - } - }, - { - "id": 9, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 3 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 3 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 10, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 1, - "name": "CouldNotReadInput" - } - ] - } - }, - "path": [ - "ink_primitives", - "LangError" - ] - } - }, - { - "id": 11, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 2, - "typeName": "u8" - } - ], - "index": 0, - "name": "U8" - }, - { - "fields": [ - { - "type": 6, - "typeName": "u16" - } - ], - "index": 1, - "name": "U16" - }, - { - "fields": [ - { - "type": 4, - "typeName": "u32" - } - ], - "index": 2, - "name": "U32" - }, - { - "fields": [ - { - "type": 7, - "typeName": "u64" - } - ], - "index": 3, - "name": "U64" - }, - { - "fields": [ - { - "type": 5, - "typeName": "u128" - } - ], - "index": 4, - "name": "U128" - }, - { - "fields": [ - { - "type": 8, - "typeName": "Vec" - } - ], - "index": 5, - "name": "Bytes" - } - ] - } - }, - "path": [ - "openbrush_contracts", - "traits", - "types", - "Id" - ] - } - }, - { - "id": 12, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 13 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 13 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 13, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 3 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 14 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 3 - }, - { - "name": "E", - "type": 14 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 14, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "InvalidRegionId" - }, - { - "index": 1, - "name": "CannotInitialize" - }, - { - "index": 2, - "name": "CannotRemove" - }, - { - "index": 3, - "name": "MetadataNotFound" - }, - { - "index": 4, - "name": "InvalidMetadata" - }, - { - "index": 5, - "name": "VersionNotFound" - }, - { - "index": 6, - "name": "RuntimeError" - }, - { - "fields": [ - { - "type": 15, - "typeName": "PSP34Error" - } - ], - "index": 7, - "name": "Psp34" - } - ] - } - }, - "path": [ - "xc_regions", - "types", - "XcRegionsError" - ] - } - }, - { - "id": 15, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 16, - "typeName": "String" - } - ], - "index": 0, - "name": "Custom" - }, - { - "index": 1, - "name": "SelfApprove" - }, - { - "index": 2, - "name": "NotApproved" - }, - { - "index": 3, - "name": "TokenExists" - }, - { - "index": 4, - "name": "TokenNotExists" - }, - { - "fields": [ - { - "type": 16, - "typeName": "String" - } - ], - "index": 5, - "name": "SafeTransferCheckFailed" - } - ] - } - }, - "path": [ - "openbrush_contracts", - "traits", - "errors", - "psp34", - "PSP34Error" - ] - } - }, - { - "id": 16, - "type": { - "def": { - "primitive": "str" - } - } - }, - { - "id": 17, - "type": { - "def": { - "composite": { - "fields": [ - { - "name": "begin", - "type": 4, - "typeName": "Timeslice" - }, - { - "name": "end", - "type": 4, - "typeName": "Timeslice" - }, - { - "name": "core", - "type": 6, - "typeName": "CoreIndex" - }, - { - "name": "mask", - "type": 18, - "typeName": "CoreMask" - } - ] - } - }, - "path": [ - "primitives", - "coretime", - "Region" - ] - } - }, - { - "id": 18, - "type": { - "def": { - "composite": { - "fields": [ - { - "type": 19, - "typeName": "[u8; 10]" - } - ] - } - }, - "path": [ - "primitives", - "coretime", - "CoreMask" - ] - } - }, - { - "id": 19, - "type": { - "def": { - "array": { - "len": 10, - "type": 2 - } - } - } - }, - { - "id": 20, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 21 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 21 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 21, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 22 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 14 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 22 - }, - { - "name": "E", - "type": 14 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 22, - "type": { - "def": { - "composite": { - "fields": [ - { - "name": "version", - "type": 4, - "typeName": "Version" - }, - { - "name": "region", - "type": 17, - "typeName": "Region" - } - ] - } - }, - "path": [ - "xc_regions", - "types", - "VersionedRegion" - ] - } - }, - { - "id": 23, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 24 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 24 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 24, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 3 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 15 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 3 - }, - { - "name": "E", - "type": 15 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 25, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 5 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 5 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 26, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 4 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 4 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 27, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 28 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 28 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 28, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "None" - }, - { - "fields": [ - { - "type": 0 - } - ], - "index": 1, - "name": "Some" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 0 - } - ], - "path": [ - "Option" - ] - } - }, - { - "id": 29, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 11 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 11 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 30, - "type": { - "def": { - "variant": { - "variants": [ - { - "index": 0, - "name": "None" - }, - { - "fields": [ - { - "type": 11 - } - ], - "index": 1, - "name": "Some" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 11 - } - ], - "path": [ - "Option" - ] - } - }, - { - "id": 31, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 32 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 32 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 32, - "type": { - "def": { - "primitive": "bool" - } - } - }, - { - "id": 33, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 34 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 10 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 34 - }, - { - "name": "E", - "type": 10 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 34, - "type": { - "def": { - "variant": { - "variants": [ - { - "fields": [ - { - "type": 11 - } - ], - "index": 0, - "name": "Ok" - }, - { - "fields": [ - { - "type": 15 - } - ], - "index": 1, - "name": "Err" - } - ] - } - }, - "params": [ - { - "name": "T", - "type": 11 - }, - { - "name": "E", - "type": 15 - } - ], - "path": [ - "Result" - ] - } - }, - { - "id": 35, - "type": { - "def": { - "composite": { - "fields": [ - { - "type": 1, - "typeName": "[u8; 32]" - } - ] - } - }, - "path": [ - "ink_primitives", - "types", - "Hash" - ] - } - }, - { - "id": 36, - "type": { - "def": { - "composite": {} - }, - "path": [ - "extension", - "Extension" - ] - } - } - ], - "version": "4" -} \ No newline at end of file diff --git a/src/models/consts.ts b/src/models/consts.ts index 4994bde9..0e293bbf 100644 --- a/src/models/consts.ts +++ b/src/models/consts.ts @@ -7,19 +7,18 @@ export const DAY = 24 * HOUR; export const RELAY_CHAIN_BLOCK_TIME = 6 * SECOND; export const CORETIME_DECIMALS = 12; -export const CONTRACT_DECIMALS = 18; +export const REGIONX_DECIMALS = 12; export const CORETIME_TOKEN_UNIT = Math.pow(10, CORETIME_DECIMALS); -export const CONTRACTS_TOKEN_UNIT = Math.pow(10, CONTRACT_DECIMALS); -export const LISTING_DEPOSIT = 0 * CONTRACTS_TOKEN_UNIT; +export const LISTING_DEPOSIT = 0; /// Given that a timeslice is 8 minutes; export const DAY_IN_TIMESLICES = 180; export const WEEK_IN_TIMESLICES = DAY_IN_TIMESLICES * 7; export const REGION_COLLECTION_ID = 42; -export const CORETIME_CHAIN_PARA_ID = 1005; -export const CONTRACTS_CHAIN_PARA_ID = 2000; +export const CORETIME_PARA_ID = 1005; +export const REGIONX_PARA_ID = 2000; export const SAFE_XCM_VERSION = 3; diff --git a/src/models/types.ts b/src/models/types.ts index b483c906..e53df5a7 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -1,5 +1,3 @@ -import { ApiPromise } from '@polkadot/api'; -import { ContractPromise } from '@polkadot/api-contract'; import { Signer } from '@polkadot/types/types'; import { BN } from '@polkadot/util'; import { @@ -23,12 +21,6 @@ export type Sender = { signer: Signer; }; -export type ContractContext = { - contractsApi: ApiPromise | undefined; - xcRegionsContract: ContractPromise | undefined; - marketContract: ContractPromise | undefined; -}; - export type TxStatusHandlers = { ready: () => void; inBlock: () => void; @@ -41,7 +33,7 @@ export enum RegionLocation { // eslint-disable-next-line no-unused-vars CORETIME_CHAIN, // eslint-disable-next-line no-unused-vars - CONTRACTS_CHAIN, + REGIONX_CHAIN, // eslint-disable-next-line no-unused-vars MARKET, } @@ -120,14 +112,14 @@ export type SaleConfig = { export class RegionMetadata { public region: Region; - // Indicates the location of the region. It can either be on the Coretime chain or on the contracts - // chain as an xc-region. + // Indicates the location of the region. It can either be on the Coretime chain, on the RegionX + // parachain or listed on the market. public location: RegionLocation; // u128 encoded RegionId. // - // This is used for interacting with the xc-regions contract or when conducting cross-chain transfers, - // where `regionId` needs to be represented as a u128. + // This is used for when conducting cross-chain transfers, where `regionId` needs to be represented + // as a u128. public rawId: RawRegionId; // A user set name for the region. diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 53bed76d..14c4db0f 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -18,7 +18,7 @@ import { CoretimeApiContextProvider, RelayApiContextProvider, } from '@/contexts/apis'; -import { WS_CONTRACTS_CHAIN } from '@/contexts/apis/consts'; +import { WS_CORETIME_CHAIN } from '@/contexts/apis/consts'; import { ContextDataProvider } from '@/contexts/common'; import { MarketProvider } from '@/contexts/market'; import { RegionDataProvider } from '@/contexts/regions'; @@ -57,7 +57,7 @@ export default function MyApp(props: MyAppProps) { defaultChain={{ network: '', name: '', - rpcUrls: [WS_CONTRACTS_CHAIN], + rpcUrls: [WS_CORETIME_CHAIN], }} apiOptions={{ types: { Id } }} > diff --git a/src/pages/regions.tsx b/src/pages/regions.tsx index 7d20362d..27285f09 100644 --- a/src/pages/regions.tsx +++ b/src/pages/regions.tsx @@ -97,7 +97,7 @@ const Dashboard = () => { // regions on the coretime chain cannot be listed on sale. They first have to be // transferred to the contacts chain. return action === 'sell' || action === 'unlist'; - } else if (selectedRegion.location === RegionLocation.CONTRACTS_CHAIN) { + } else if (selectedRegion.location === RegionLocation.REGIONX_CHAIN) { // XcRegions can only be transferred and listed on sale. return !(action === 'transfer' || action === 'sell'); } else { diff --git a/src/pages/transfer.tsx b/src/pages/transfer.tsx index 9e5502dd..0a539f61 100644 --- a/src/pages/transfer.tsx +++ b/src/pages/transfer.tsx @@ -9,24 +9,12 @@ import { Stack, Typography, } from '@mui/material'; -import { ApiPromise, Keyring } from '@polkadot/api'; -import { InjectedAccount } from '@polkadot/extension-inject/types'; -import { useContract, useInkathon } from '@scio-labs/use-inkathon'; +import { useInkathon } from '@scio-labs/use-inkathon'; import { Region } from 'coretime-utils'; -import { useCallback, useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; -import { - contractsToCoretimeTransfer, - coretimeToContractsTransfer, -} from '@/utils/crossChain/transfer'; import theme from '@/utils/muiTheme'; -import { approveNonWrappedRegion } from '@/utils/native/approve'; -import { initRegionMetadata } from '@/utils/native/init'; -import { removeXcRegionWrapper } from '@/utils/native/remove'; -import { - transferRegionOnContractsChain, - transferRegionOnCoretimeChain, -} from '@/utils/native/transfer'; +import { transferRegionOnCoretimeChain } from '@/utils/native/transfer'; import { ChainSelector, @@ -36,22 +24,18 @@ import { } from '@/components'; import { useCoretimeApi } from '@/contexts/apis'; -import { CONTRACT_XC_REGIONS } from '@/contexts/apis/consts'; import { useRegions } from '@/contexts/regions'; -import { getNonWrappedRegions } from '@/contexts/regions/xc'; import { useToast } from '@/contexts/toast'; -import XcRegionsMetadata from '@/contracts/xc_regions.json'; import { RegionLocation, RegionMetadata } from '@/models'; const TransferPage = () => { - const { activeAccount, activeSigner, api: contractsApi } = useInkathon(); - const { contract } = useContract(XcRegionsMetadata, CONTRACT_XC_REGIONS); + const { activeAccount, activeSigner } = useInkathon(); - const { toastError, toastInfo, toastSuccess } = useToast(); + const { toastError, toastInfo, toastWarning, toastSuccess } = useToast(); const { state: { api: coretimeApi }, } = useCoretimeApi(); - const { regions, fetchRegions } = useRegions(); + const { regions } = useRegions(); const [filteredRegions, setFilteredRegions] = useState>( [] @@ -61,7 +45,7 @@ const TransferPage = () => { const [newOwner, setNewOwner] = useState(''); const [originChain, setOriginChain] = useState(''); const [destinationChain, setDestinationChain] = useState(''); - const [statusLabel, setStatusLabel] = useState(''); + const [statusLabel, _setStatusLabel] = useState(''); const [selectedRegion, setSelectedRegion] = useState( null @@ -81,7 +65,7 @@ const TransferPage = () => { ); } else { setFilteredRegions( - regions.filter((r) => r.location == RegionLocation.CONTRACTS_CHAIN) + regions.filter((r) => r.location == RegionLocation.REGIONX_CHAIN) ); } }; @@ -95,11 +79,9 @@ const TransferPage = () => { if (originChain === destinationChain) { originChain === 'CoretimeChain' ? transferCoretimeRegion(selectedRegion.region) - : transferXcRegion(selectedRegion.region); + : toastWarning('Currently not supported'); } else { - originChain === 'CoretimeChain' - ? transferFromCoretimeChain(selectedRegion.region) - : transferFromContractsChain(selectedRegion.region); + toastWarning('Currently not supported'); } }; @@ -130,252 +112,6 @@ const TransferPage = () => { ); }; - const transferXcRegion = async (region: Region) => { - if (!contractsApi || !activeAccount || !contract) { - return; - } - - setWorking(true); - transferRegionOnContractsChain( - { contractsApi, xcRegionsContract: contract, marketContract: undefined }, - region, - activeAccount.address, - newOwner ? newOwner : activeAccount.address, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => setWorking(false), - success: () => toastSuccess('Successfully transferred the region.'), - error: () => { - toastError(`Failed to transfer the region.`); - setWorking(false); - }, - } - ); - }; - - const transferFromCoretimeChain = async (region: Region) => { - if (!coretimeApi || !activeAccount || !activeSigner) return; - - setStatusLabel('Initiating transfer from coretime chain'); - const receiverKeypair = new Keyring(); - receiverKeypair.addFromAddress(newOwner ? newOwner : activeAccount.address); - - const regionId = region.getEncodedRegionId(contractsApi); - setWorking(true); - coretimeToContractsTransfer( - coretimeApi, - { address: activeAccount.address, signer: activeSigner }, - regionId, - receiverKeypair.pairs[0].publicKey, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => setWorking(false), - success: () => { - toastSuccess('Successfully transferred the region.'); - setStatusLabel('Waiting to wrap the region...'); - }, - error: () => { - toastError(`Failed to transfer the region.`); - setWorking(false); - }, - } - ); - }; - - const transferFromContractsChain = async (region: Region) => { - if (!contractsApi || !activeAccount || !activeSigner) return; - - removeWrapper(region, () => { - setStatusLabel('Initiating transfer from contracts chain'); - const receiverKeypair = new Keyring(); - receiverKeypair.addFromAddress( - newOwner ? newOwner : activeAccount.address - ); - - const regionId = region.getEncodedRegionId(contractsApi); - setWorking(true); - contractsToCoretimeTransfer( - contractsApi, - { address: activeAccount.address, signer: activeSigner }, - regionId, - receiverKeypair.pairs[0].publicKey, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => setWorking(false), - success: () => { - toastSuccess('Successfully transferred the region.'); - setStatusLabel(''); - }, - error: () => { - toastError(`Failed to transfer the region.`); - setWorking(false); - }, - } - ); - }); - }; - - const removeWrapper = async (region: Region, onSuccess: () => void) => { - if (!activeAccount || !activeSigner) return; - - setStatusLabel('Unwrapping xc-region...'); - - setWorking(true); - removeXcRegionWrapper( - { - contractsApi, - xcRegionsContract: contract, - marketContract: undefined, - }, - { address: activeAccount.address, signer: activeSigner }, - region, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => { - /** */ - }, - success: () => { - toastSuccess('Successfully unwrapped the xc-region.'); - onSuccess(); - }, - error: () => { - toastError(`Failed to unwrap the xc-region.`); - setWorking(false); - }, - } - ); - }; - - const approveRegionToContract = useCallback( - async (region: Region, onSuccess: () => void) => { - if (!activeAccount || !activeSigner) return; - - setStatusLabel('Approving region to the xc-region contract...'); - setWorking(true); - approveNonWrappedRegion( - { - contractsApi, - xcRegionsContract: contract, - marketContract: undefined, - }, - { address: activeAccount.address, signer: activeSigner }, - region, - CONTRACT_XC_REGIONS, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => { - /** */ - }, - success: () => { - toastSuccess('Successfully approved the region.'); - onSuccess(); - }, - error: () => { - toastError(`Failed to approve the region.`); - setWorking(false); - }, - } - ); - }, - [ - activeAccount, - contractsApi, - activeSigner, - contract, - toastError, - toastInfo, - toastSuccess, - ] - ); - - const initMetadata = useCallback( - async (region: Region) => { - if (!activeAccount || !activeSigner) return; - - setStatusLabel('Initializing metadata...'); - setWorking(true); - initRegionMetadata( - { - contractsApi, - xcRegionsContract: contract, - marketContract: undefined, - }, - { address: activeAccount.address, signer: activeSigner }, - region, - { - ready: () => toastInfo('Transaction was initiated.'), - inBlock: () => toastInfo(`In Block`), - finalized: () => setWorking(false), - success: () => { - toastSuccess('Successfully initialized region metadata.'); - setStatusLabel(''); - fetchRegions(); - }, - error: () => { - toastError(`Failed to initialize the region metadata.`); - setWorking(false); - }, - } - ); - }, - [ - activeAccount, - activeSigner, - contractsApi, - contract, - toastError, - toastSuccess, - toastInfo, - fetchRegions, - ] - ); - - const startInitializationProcess = useCallback( - async (region: Region) => { - approveRegionToContract(region, () => initMetadata(region)); - }, - [approveRegionToContract, initMetadata] - ); - - const handleNonWrappedRegions = useCallback( - async (coretimeApi: ApiPromise, activeAccount: InjectedAccount) => { - const nonWrappedRegions = await getNonWrappedRegions( - { - contractsApi, - xcRegionsContract: contract, - marketContract: undefined, - }, - coretimeApi, - activeAccount.address - ); - nonWrappedRegions.forEach((region) => { - startInitializationProcess(region); - }); - }, - [contract, contractsApi, startInitializationProcess] - ); - - useEffect(() => { - let intervalId: any; - if (!working) { - intervalId = setInterval(() => { - coretimeApi && - activeAccount && - handleNonWrappedRegions(coretimeApi, activeAccount); - }, 5000); - } - return () => { - if (intervalId) { - clearInterval(intervalId); - } - }; - }, [working, activeAccount, coretimeApi, handleNonWrappedRegions]); - return ( diff --git a/src/utils/crossChain/consts.tsx b/src/utils/crossChain/consts.tsx index fd1f052d..5f508a6a 100644 --- a/src/utils/crossChain/consts.tsx +++ b/src/utils/crossChain/consts.tsx @@ -1,19 +1,19 @@ -import { BROKER_PALLET_ID, CORETIME_CHAIN_PARA_ID } from '@/models'; +import { BROKER_PALLET_ID, CORETIME_PARA_ID, REGIONX_PARA_ID } from '@/models'; export const CoretimeChain = { parents: 1, interior: { X1: { - Parachain: CORETIME_CHAIN_PARA_ID, + Parachain: CORETIME_PARA_ID, }, }, }; -export const ContractsChain = { +export const RegionXChain = { parents: 1, interior: { X1: { - Parachain: CORETIME_CHAIN_PARA_ID, + Parachain: REGIONX_PARA_ID, }, }, }; @@ -27,12 +27,9 @@ export const CoretimeRegionFromCoretimePerspective = { }, }; -export const CoretimeRegionFromContractsPerspective = { +export const CoretimeRegionFromRegionXPerspective = { parents: 1, interior: { - X2: [ - { Parachain: CORETIME_CHAIN_PARA_ID }, - { PalletInstance: BROKER_PALLET_ID }, - ], + X2: [{ Parachain: CORETIME_PARA_ID }, { PalletInstance: BROKER_PALLET_ID }], }, }; diff --git a/src/utils/crossChain/transfer.tsx b/src/utils/crossChain/transfer.tsx index 63185e19..d402be3c 100644 --- a/src/utils/crossChain/transfer.tsx +++ b/src/utils/crossChain/transfer.tsx @@ -4,14 +4,14 @@ import { BN } from '@polkadot/util'; import { Sender, TxStatusHandlers } from '@/models'; import { - ContractsChain, CoretimeChain, - CoretimeRegionFromContractsPerspective, CoretimeRegionFromCoretimePerspective, + CoretimeRegionFromRegionXPerspective, + RegionXChain, } from './consts'; import { versionedNonfungibleAssetWrap, versionedWrap } from './utils'; -export async function coretimeToContractsTransfer( +export async function coretimeToRegionXTransfer( coretimeApi: ApiPromise, sender: Sender, rawRegionId: BN, @@ -35,7 +35,7 @@ export async function coretimeToContractsTransfer( const reserveTransfer = coretimeApi.tx.polkadotXcm.limitedReserveTransferAssets( - versionedWrap(ContractsChain), + versionedWrap(RegionXChain), versionedWrap(beneficiary), versionedNonfungibleAssetWrap( CoretimeRegionFromCoretimePerspective, @@ -69,8 +69,8 @@ export async function coretimeToContractsTransfer( } } -export function contractsToCoretimeTransfer( - contractsApi: ApiPromise, +export function regionXToCoretimeTransfer( + api: ApiPromise, sender: Sender, rawRegionId: BN, receiver: Uint8Array, @@ -91,17 +91,16 @@ export function contractsToCoretimeTransfer( const feeAssetItem = 0; const weightLimit = 'Unlimited'; - const reserveTransfer = - contractsApi.tx.polkadotXcm.limitedReserveTransferAssets( - versionedWrap(CoretimeChain), - versionedWrap(beneficiary), - versionedNonfungibleAssetWrap( - CoretimeRegionFromContractsPerspective, - rawRegionId.toString() - ), - feeAssetItem, - weightLimit - ); + const reserveTransfer = api.tx.polkadotXcm.limitedReserveTransferAssets( + versionedWrap(CoretimeChain), + versionedWrap(beneficiary), + versionedNonfungibleAssetWrap( + CoretimeRegionFromRegionXPerspective, + rawRegionId.toString() + ), + feeAssetItem, + weightLimit + ); try { reserveTransfer.signAndSend( diff --git a/src/utils/functions.ts b/src/utils/functions.ts index ae51b442..61ab5954 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -4,8 +4,8 @@ import { CoreMask, RegionId } from 'coretime-utils'; import Decimal from 'decimal.js'; import { - CONTRACT_DECIMALS, CORETIME_DECIMALS, + REGIONX_DECIMALS, RELAY_CHAIN_BLOCK_TIME, } from '@/models'; @@ -79,9 +79,9 @@ export const timestampToTimeslice = async ( } }; -export const formatBalance = (balance: string, contractChain: boolean) => { +export const formatBalance = (balance: string, regionXChain: boolean) => { Decimal.config({ rounding: Decimal.ROUND_DOWN }); - const decimals = contractChain ? CONTRACT_DECIMALS : CORETIME_DECIMALS; + const decimals = regionXChain ? REGIONX_DECIMALS : CORETIME_DECIMALS; return polkadotFormatBalance(balance, { decimals, diff --git a/src/utils/native/approve.tsx b/src/utils/native/approve.tsx deleted file mode 100644 index d091561d..00000000 --- a/src/utils/native/approve.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import { contractTx } from '@scio-labs/use-inkathon'; -import { Region } from 'coretime-utils'; - -import { - ContractContext, - REGION_COLLECTION_ID, - Sender, - TxStatusHandlers, -} from '@/models'; - -export const approveNonWrappedRegion = async ( - ctx: ContractContext, - sender: Sender, - region: Region, - who: string, - handlers: TxStatusHandlers -) => { - const { contractsApi } = ctx; - if (!contractsApi) return; - - const approveTx = contractsApi.tx.uniques.approveTransfer( - REGION_COLLECTION_ID, - region.getEncodedRegionId(contractsApi), - who - ); - - try { - await approveTx.signAndSend( - sender.address, - { signer: sender.signer }, - ({ status, events }) => { - if (status.isReady) handlers.ready(); - else if (status.isInBlock) handlers.inBlock(); - else if (status.isFinalized) { - handlers.finalized(); - events.forEach(({ event: { method } }) => { - if (method === 'ExtrinsicSuccess') { - handlers.success(); - } else if (method === 'ExtrinsicFailed') { - handlers.error(); - } - }); - } - } - ); - } catch (e) { - handlers.error(); - } -}; - -export const approveXcRegion = async ( - ctx: ContractContext, - sender: Sender, - region: Region, - who: string, - handlers: TxStatusHandlers -) => { - const { contractsApi, xcRegionsContract } = ctx; - if (!contractsApi || !xcRegionsContract) { - return; - } - - try { - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { U128: rawRegionId }); - - await contractTx( - contractsApi, - sender.address, - xcRegionsContract, - 'PSP34::approve', - {}, - [who, id, true] - ); - - handlers.finalized(); - handlers.success(); - } catch (e: any) { - handlers.error(); - } -}; diff --git a/src/utils/native/init.tsx b/src/utils/native/init.tsx deleted file mode 100644 index 9f4a0637..00000000 --- a/src/utils/native/init.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { contractTx } from '@scio-labs/use-inkathon'; -import { Region } from 'coretime-utils'; - -import { ContractContext, Sender, TxStatusHandlers } from '@/models'; - -export async function initRegionMetadata( - contractsCtx: ContractContext, - sender: Sender, - region: Region, - handlers: TxStatusHandlers -) { - const { contractsApi, xcRegionsContract } = contractsCtx; - if (!contractsApi || !xcRegionsContract) return; - - try { - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { U128: rawRegionId.toString() }); - - const regionMetadata = { - begin: region.getBegin(), - end: region.getEnd(), - core: region.getCore(), - mask: region.getMask().toRawHex(), - }; - - await contractTx( - contractsApi, - sender.address, - xcRegionsContract, - 'regionMetadata::init', - {}, - [id, regionMetadata] - ); - handlers.finalized(); - handlers.success(); - } catch (e: any) { - handlers.error(); - } -} diff --git a/src/utils/native/remove.tsx b/src/utils/native/remove.tsx deleted file mode 100644 index 7d206cac..00000000 --- a/src/utils/native/remove.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { contractTx } from '@scio-labs/use-inkathon'; -import { Region } from 'coretime-utils'; - -import { ContractContext, Sender, TxStatusHandlers } from '@/models'; - -export async function removeXcRegionWrapper( - contractsCtx: ContractContext, - sender: Sender, - region: Region, - handlers: TxStatusHandlers -) { - const { contractsApi, xcRegionsContract } = contractsCtx; - if (!contractsApi || !xcRegionsContract) return; - - try { - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { U128: rawRegionId.toString() }); - - await contractTx( - contractsApi, - sender.address, - xcRegionsContract, - 'regionMetadata::remove', - {}, - [id] - ); - handlers.finalized(); - handlers.success(); - } catch (e: any) { - handlers.error(); - } -} diff --git a/src/utils/native/transfer.tsx b/src/utils/native/transfer.tsx index b2657160..852cc3e3 100644 --- a/src/utils/native/transfer.tsx +++ b/src/utils/native/transfer.tsx @@ -1,9 +1,8 @@ import { ApiPromise } from '@polkadot/api'; import { Signer } from '@polkadot/types/types'; -import { contractTx } from '@scio-labs/use-inkathon'; import { Region } from 'coretime-utils'; -import { ContractContext, TxStatusHandlers } from '@/models'; +import { TxStatusHandlers } from '@/models'; export const transferRegionOnCoretimeChain = async ( coretimeApi: ApiPromise, @@ -41,33 +40,3 @@ export const transferRegionOnCoretimeChain = async ( handlers.error(); } }; - -export const transferRegionOnContractsChain = async ( - contractCtx: ContractContext, - region: Region, - senderAddress: string, - newOwner: string, - handlers: TxStatusHandlers -) => { - const { contractsApi, xcRegionsContract } = contractCtx; - if (!contractsApi || !xcRegionsContract) return; - - try { - const rawRegionId = region.getEncodedRegionId(contractsApi); - const id = contractsApi.createType('Id', { U128: rawRegionId }); - - await contractTx( - contractsApi, - senderAddress, - xcRegionsContract, - 'PSP34::transfer', - {}, - [newOwner, id, []] - ); - - handlers.finalized(); - handlers.success(); - } catch (e: any) { - handlers.error(); - } -};