iscmagic

package
v0.7.0-alpha.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

@iota/iscmagic

The Magic contract is an EVM contract deployed by default on every ISC chain, in the EVM genesis block, at address 0x1074000000000000000000000000000000000000. The implementation of the Magic contract is baked-in in the evm core contract; i.e. it is not a pure-Solidity contract.

The Magic contract has several methods, which are categorized into specialized interfaces: ISCSandbox, ISCAccounts, ISCUtil and so on. You can access these interfaces from any Solidity contract by importing this library.

The Magic contract also provides proxy ERC20 contracts to manipulate ISC base tokens and native tokens on L2.

Read more in the Wiki.

Installing @iota/iscmagic contracts

The @iota/iscmagic contracts are installable via NPM with

npm install @iota/iscmagic

After installing @iota/iscmagic you can use the functions by importing them as you normally would.

pragma solidity >=0.8.5;

import "@iota/iscmagic/ISC.sol";

contract MyEVMContract {
    event EntropyEvent(bytes32 entropy);

    // this will emit a "random" value taken from the ISC entropy value
    function emitEntropy() public {
        bytes32 e = ISC.sandbox.getEntropy();
        emit EntropyEvent(e);
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AddressPrefix = []byte{0x10, 0x74}
	Address       = packMagicAddress(addressKindISCMagic, nil)
)
View Source
var (
	//go:embed ISCSandbox.abi
	SandboxABI string

	//go:embed ISCUtil.abi
	UtilABI string

	//go:embed ISCAccounts.abi
	AccountsABI string

	//go:embed ISCPrivileged.abi
	PrivilegedABI string
)
View Source
var (
	//go:embed ERC20BaseTokens.abi
	ERC20BaseTokensABI string

	ERC20BaseTokensRuntimeBytecode = common.FromHex(strings.TrimSpace(erc20BaseRuntimeBytecodeHex))

	ERC20BaseTokensAddress = packMagicAddress(addressKindERC20BaseTokens, nil)
)
View Source
var (
	//go:embed ERC20NativeTokens.abi
	ERC20NativeTokensABI string

	ERC20NativeTokensRuntimeBytecode = common.FromHex(strings.TrimSpace(erc20NativeTokensRuntimeBytecodeHex))
)
View Source
var (
	//go:embed ERC20ExternalNativeTokens.abi
	ERC20ExternalNativeTokensABI string

	ERC20ExternalNativeTokensRuntimeBytecode = common.FromHex(strings.TrimSpace(erc20ExternalNativeTokensRuntimeBytecodeHex))
)
View Source
var (
	//go:embed ERC721NFTs.abi
	ERC721NFTsABI string

	ERC721NFTsRuntimeBytecode = common.FromHex(strings.TrimSpace(erc721NFTsBytecodeHex))

	ERC721NFTsAddress = packMagicAddress(addressKindERC721NFTs, nil)
)
View Source
var (
	//go:embed ERC721NFTCollection.abi
	ERC721NFTCollectionABI string

	ERC721NFTCollectionRuntimeBytecode = common.FromHex(strings.TrimSpace(erc721NFTCollectionBytecodeHex))
)

Functions

func ERC20ExternalNativeTokensAddress added in v1.0.3

func ERC20ExternalNativeTokensAddress(
	nativeTokenID iotago.NativeTokenID,
	isTaken func(common.Address) bool,
) (common.Address, error)

ERC20ExternalNativeTokensAddress creates an Ethereum address for an ERC20 contract for native tokens with an off-chain foundry. NOTE: since len(NativeTokenID) == 38 and len(Address) == 20, it is not possible to assign a unique address to every native token. This function tries to form the ERC20 address from the first 17 bytes of hash(nativeTokenID). In case of a collision, it reapplies the hash and checks for a collision again, repeating until it gives up.

func ERC20NativeTokensAddress added in v1.0.3

func ERC20NativeTokensAddress(foundrySN uint32) common.Address

ERC20NativeTokensAddress returns the Ethereum address of the ERC20 contract for native tokens with an on-chain foundry.

func ERC20NativeTokensFoundrySN added in v1.0.3

func ERC20NativeTokensFoundrySN(addr common.Address) (uint32, error)

func ERC721NFTCollectionAddress added in v1.0.3

func ERC721NFTCollectionAddress(collectionID iotago.NFTID) common.Address

Types

type IRC27NFT added in v1.0.3

type IRC27NFT struct {
	Nft      ISCNFT
	Metadata IRC27NFTMetadata
}

IRC27NFT matches the struct definition in ISCTypes.sol

type IRC27NFTMetadata added in v1.0.3

type IRC27NFTMetadata struct {
	Standard string
	Version  string
	MimeType string
	Uri      string //nolint:revive // false positive
	Name     string
}

IRC27NFTMetadata matches the struct definition in ISCTypes.sol

func WrapIRC27NFTMetadata added in v1.0.3

func WrapIRC27NFTMetadata(m *isc.IRC27NFTMetadata) IRC27NFTMetadata

type ISCAgentID

type ISCAgentID struct {
	Data []byte
}

ISCAgentID matches the struct definition in ISCTypes.sol

func WrapISCAgentID

func WrapISCAgentID(a isc.AgentID) ISCAgentID

func (ISCAgentID) MustUnwrap

func (a ISCAgentID) MustUnwrap() isc.AgentID

func (ISCAgentID) Unwrap

func (a ISCAgentID) Unwrap() (isc.AgentID, error)

type ISCAssets added in v1.0.3

type ISCAssets struct {
	BaseTokens   uint64
	NativeTokens []NativeToken
	Nfts         []NFTID
}

ISCAssets matches the struct definition in ISCTypes.sol

func WrapISCAssets added in v1.0.3

func WrapISCAssets(a *isc.Assets) ISCAssets

func (ISCAssets) Unwrap added in v1.0.3

func (a ISCAssets) Unwrap() *isc.Assets

type ISCChainID

type ISCChainID [isc.ChainIDLength]byte

ISCChainID matches the type definition in ISCTypes.sol

func WrapISCChainID

func WrapISCChainID(c isc.ChainID) (ret ISCChainID)

func (ISCChainID) MustUnwrap

func (c ISCChainID) MustUnwrap() isc.ChainID

func (ISCChainID) Unwrap

func (c ISCChainID) Unwrap() (isc.ChainID, error)

type ISCDict

type ISCDict struct {
	Items []ISCDictItem
}

ISCDict matches the struct definition in ISCTypes.sol

func WrapISCDict

func WrapISCDict(d dict.Dict) ISCDict

func (ISCDict) Unwrap

func (d ISCDict) Unwrap() dict.Dict

type ISCDictItem

type ISCDictItem struct {
	Key   []byte
	Value []byte
}

ISCDictItem matches the struct definition in ISCTypes.sol

type ISCExpiration

type ISCExpiration struct {
	Time          int64
	ReturnAddress L1Address
}

func (*ISCExpiration) Unwrap

func (i *ISCExpiration) Unwrap() *isc.Expiration

type ISCNFT

type ISCNFT struct {
	ID       NFTID
	Issuer   L1Address
	Metadata []byte
	Owner    ISCAgentID
}

ISCNFT matches the struct definition in ISCTypes.sol

func WrapISCNFT

func WrapISCNFT(n *isc.NFT) ISCNFT

func (ISCNFT) MustUnwrap

func (n ISCNFT) MustUnwrap() *isc.NFT

func (ISCNFT) Unwrap

func (n ISCNFT) Unwrap() (*isc.NFT, error)

type ISCRequestID added in v1.0.3

type ISCRequestID struct {
	Data []byte
}

ISCRequestID matches the struct definition in ISCTypes.sol

func WrapISCRequestID added in v1.0.3

func WrapISCRequestID(rid isc.RequestID) ISCRequestID

func (ISCRequestID) MustUnwrap added in v1.0.3

func (rid ISCRequestID) MustUnwrap() isc.RequestID

func (ISCRequestID) Unwrap added in v1.0.3

func (rid ISCRequestID) Unwrap() (isc.RequestID, error)

type ISCSendMetadata

type ISCSendMetadata struct {
	TargetContract uint32
	Entrypoint     uint32
	Params         ISCDict
	Allowance      ISCAssets
	GasBudget      uint64
}

func WrapISCSendMetadata

func WrapISCSendMetadata(metadata isc.SendMetadata) ISCSendMetadata

func (ISCSendMetadata) Unwrap

func (i ISCSendMetadata) Unwrap() *isc.SendMetadata

type ISCSendOptions

type ISCSendOptions struct {
	Timelock   int64
	Expiration ISCExpiration
}

func (*ISCSendOptions) Unwrap

func (i *ISCSendOptions) Unwrap() isc.SendOptions

type ISCTokenProperties added in v0.3.4

type ISCTokenProperties struct {
	Name         string
	TickerSymbol string
	Decimals     uint8
	TotalSupply  *big.Int
}

type L1Address

type L1Address struct {
	Data []byte
}

L1Address matches the struct definition in ISCTypes.sol

func WrapL1Address

func WrapL1Address(a iotago.Address) L1Address

func (L1Address) MustUnwrap

func (a L1Address) MustUnwrap() iotago.Address

func (L1Address) Unwrap

func (a L1Address) Unwrap() (iotago.Address, error)

type NFTID

type NFTID [iotago.NFTIDLength]byte

NFTID matches the type definition in ISCTypes.sol

func WrapNFTID

func WrapNFTID(c iotago.NFTID) (ret NFTID)

func (NFTID) TokenID added in v1.0.3

func (n NFTID) TokenID() *big.Int

TokenID returns the uint256 tokenID for ERC721

func (NFTID) Unwrap

func (n NFTID) Unwrap() (ret iotago.NFTID)

type NativeToken

type NativeToken struct {
	ID     NativeTokenID
	Amount *big.Int
}

NativeToken matches the struct definition in ISCTypes.sol

func WrapNativeToken

func WrapNativeToken(nativeToken *iotago.NativeToken) NativeToken

func (NativeToken) Unwrap

func (nt NativeToken) Unwrap() *iotago.NativeToken

type NativeTokenID

type NativeTokenID struct {
	Data []byte
}

NativeTokenID matches the struct definition in ISCTypes.sol

func WrapNativeTokenID

func WrapNativeTokenID(nativeTokenID iotago.NativeTokenID) NativeTokenID

func (NativeTokenID) MustUnwrap added in v1.0.3

func (a NativeTokenID) MustUnwrap() (ret iotago.NativeTokenID)

func (NativeTokenID) Unwrap

func (a NativeTokenID) Unwrap() (ret iotago.NativeTokenID)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL