accounts

package
v0.6.1-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: Apache-2.0 Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// MinimumBaseTokensOnCommonAccount can't harvest the minimum
	MinimumBaseTokensOnCommonAccount = uint64(3000)

	ParamAgentID                      = "a"
	ParamAccountNonce                 = "n"
	ParamForceMinimumBaseTokens       = "f"
	ParamFoundrySN                    = "s"
	ParamFoundryOutputBin             = "b"
	ParamTokenScheme                  = "t"
	ParamSupplyDeltaAbs               = "d"
	ParamDestroyTokens                = "y"
	ParamStorageDepositAssumptionsBin = "u"
	ParamNFTAmount                    = "A"
	ParamNFTIDs                       = "i"
	ParamNFTID                        = "z"
	ParamCollectionID                 = "C"
	ParamNFTData                      = "e"
	ParamBalance                      = "B"
	ParamNativeTokenID                = "N"
)
View Source
const ConstDepositFeeTmp = 1 * isc.Million

TODO this is just a temporary value, we need to make deposits fee constant across chains.

Variables

View Source
var (
	// Views
	ViewBalance                      = coreutil.ViewFunc("balance")
	ViewBalanceBaseToken             = coreutil.ViewFunc("balanceBaseToken")
	ViewBalanceNativeToken           = coreutil.ViewFunc("balanceNativeToken")
	ViewTotalAssets                  = coreutil.ViewFunc("totalAssets")
	ViewAccounts                     = coreutil.ViewFunc("accounts")
	ViewGetAccountNonce              = coreutil.ViewFunc("getAccountNonce")
	ViewGetNativeTokenIDRegistry     = coreutil.ViewFunc("getNativeTokenIDRegistry")
	ViewFoundryOutput                = coreutil.ViewFunc("foundryOutput")
	ViewAccountNFTs                  = coreutil.ViewFunc("accountNFTs")
	ViewAccountNFTAmount             = coreutil.ViewFunc("accountNFTAmount")
	ViewAccountNFTsInCollection      = coreutil.ViewFunc("accountNFTsInCollection")
	ViewAccountNFTAmountInCollection = coreutil.ViewFunc("accountNFTAmountInCollection")
	ViewAccountFoundries             = coreutil.ViewFunc("accountFoundries")
	ViewNFTData                      = coreutil.ViewFunc("nftData")

	// Funcs
	FuncDeposit             = coreutil.Func("deposit")
	FuncTransferAllowanceTo = coreutil.Func("transferAllowanceTo")
	FuncWithdraw            = coreutil.Func("withdraw")
	FuncHarvest             = coreutil.Func("harvest")
	FuncFoundryCreateNew    = coreutil.Func("foundryCreateNew")
	FuncFoundryDestroy      = coreutil.Func("foundryDestroy")
	FuncFoundryModifySupply = coreutil.Func("foundryModifySupply")
)
View Source
var (
	ErrNotEnoughFunds                       = coreerrors.Register("not enough funds").Create()
	ErrNotEnoughBaseTokensForStorageDeposit = coreerrors.Register("not enough base tokens for storage deposit").Create()
	ErrNotEnoughAllowance                   = coreerrors.Register("not enough allowance").Create()
	ErrBadAmount                            = coreerrors.Register("bad native asset amount").Create()
	ErrRepeatingFoundrySerialNumber         = coreerrors.Register("repeating serial number of the foundry").Create()
	ErrFoundryNotFound                      = coreerrors.Register("foundry not found").Create()
	ErrOverflow                             = coreerrors.Register("overflow in token arithmetics").Create()
	ErrInvalidNFTID                         = coreerrors.Register("invalid NFT ID").Create()
	ErrTooManyNFTsInAllowance               = coreerrors.Register("expected at most 1 NFT in allowance").Create()
	ErrNFTIDNotFound                        = coreerrors.Register("NFTID not found: %s")
)
View Source
var Contract = coreutil.NewContract(coreutil.CoreContractAccounts, "Chain account ledger contract")
View Source
var ErrStorageDepositAssumptionsWrong = errors.New("'storage deposit assumptions' parameter not specified or wrong")
View Source
var Processor = Contract.Processor(nil,

	FuncDeposit.WithHandler(deposit),
	FuncFoundryCreateNew.WithHandler(foundryCreateNew),
	FuncFoundryDestroy.WithHandler(foundryDestroy),
	FuncFoundryModifySupply.WithHandler(foundryModifySupply),
	FuncHarvest.WithHandler(harvest),
	FuncTransferAllowanceTo.WithHandler(transferAllowanceTo),
	FuncWithdraw.WithHandler(withdraw),

	ViewAccountNFTs.WithHandler(viewAccountNFTs),
	ViewAccountNFTAmount.WithHandler(viewAccountNFTAmount),
	ViewAccountNFTsInCollection.WithHandler(viewAccountNFTsInCollection),
	ViewAccountNFTAmountInCollection.WithHandler(viewAccountNFTAmountInCollection),
	ViewAccountFoundries.WithHandler(viewAccountFoundries),
	ViewAccounts.WithHandler(viewAccounts),
	ViewBalance.WithHandler(viewBalance),
	ViewBalanceBaseToken.WithHandler(viewBalanceBaseToken),
	ViewBalanceNativeToken.WithHandler(viewBalanceNativeToken),
	ViewFoundryOutput.WithHandler(viewFoundryOutput),
	ViewGetAccountNonce.WithHandler(viewGetAccountNonce),
	ViewGetNativeTokenIDRegistry.WithHandler(viewGetNativeTokenIDRegistry),
	ViewNFTData.WithHandler(viewNFTData),
	ViewTotalAssets.WithHandler(viewTotalAssets),
)

Functions

func AccountExists added in v0.3.0

func AccountExists(state kv.KVStoreReader, agentID isc.AgentID) bool

func AdjustAccountBaseTokens added in v0.3.0

func AdjustAccountBaseTokens(state kv.KVStore, account isc.AgentID, adjustment int64)

func CommonAccount added in v1.0.3

func CommonAccount() isc.AgentID

func CreditNFTToAccount added in v0.3.0

func CreditNFTToAccount(state kv.KVStore, agentID isc.AgentID, nft *isc.NFT)

CreditNFTToAccount credits an NFT to the on chain ledger

func CreditToAccount

func CreditToAccount(state kv.KVStore, agentID isc.AgentID, assets *isc.Assets)

CreditToAccount brings new funds to the on chain ledger NOTE: this function does not take NFTs into account

func DebitFromAccount

func DebitFromAccount(state kv.KVStore, agentID isc.AgentID, assets *isc.Assets)

DebitFromAccount takes out assets balance the on chain ledger. If not enough it panics NOTE: this function does not take NFTs into account

func DebitNFTFromAccount added in v0.3.0

func DebitNFTFromAccount(state kv.KVStore, agentID isc.AgentID, id iotago.NFTID)

DebitNFTFromAccount removes an NFT from an account. If the account does not own the nft, it panics.

func DeleteFoundryOutput added in v0.3.0

func DeleteFoundryOutput(state kv.KVStore, sn uint32)

DeleteFoundryOutput deletes foundry output from the map of all foundries

func DeleteNFTOutput added in v0.3.0

func DeleteNFTOutput(state kv.KVStore, id iotago.NFTID)

func DeleteNativeTokenOutput added in v0.3.0

func DeleteNativeTokenOutput(state kv.KVStore, nativeTokenID iotago.NativeTokenID)

func GetAccountFungibleTokens added in v1.0.3

func GetAccountFungibleTokens(state kv.KVStoreReader, agentID isc.AgentID) *isc.Assets

GetAccountFungibleTokens returns all fungible tokens belonging to the agentID on the state

func GetAccountNFTs added in v0.3.0

func GetAccountNFTs(state kv.KVStoreReader, agentID isc.AgentID) []iotago.NFTID

GetAccountNFTs returns all NFTs belonging to the agentID on the state

func GetBaseTokensBalance added in v0.3.0

func GetBaseTokensBalance(state kv.KVStoreReader, agentID isc.AgentID) uint64

func GetFoundryOutput added in v0.3.0

func GetFoundryOutput(state kv.KVStoreReader, sn uint32, chainID isc.ChainID) (*iotago.FoundryOutput, uint32, uint16)

GetFoundryOutput returns foundry output, its block number and output index

func GetMaxAssumedNonce added in v0.2.0

func GetMaxAssumedNonce(state kv.KVStoreReader, callerAgentID isc.AgentID) uint64

GetMaxAssumedNonce is maintained for each caller with the purpose of replay protection of off-ledger requests

func GetNFTData added in v0.3.0

func GetNFTData(state kv.KVStoreReader, id iotago.NFTID) (*isc.NFT, error)

func GetNFTOutput added in v0.3.0

func GetNFTOutput(state kv.KVStoreReader, id iotago.NFTID, chainID isc.ChainID) (*iotago.NFTOutput, uint32, uint16)

func GetNativeTokenBalance added in v0.3.0

func GetNativeTokenBalance(state kv.KVStoreReader, agentID isc.AgentID, nativeTokenID iotago.NativeTokenID) *big.Int

func GetNativeTokenBalanceTotal added in v0.3.0

func GetNativeTokenBalanceTotal(state kv.KVStoreReader, nativeTokenID iotago.NativeTokenID) *big.Int

func GetNativeTokenOutput added in v0.3.0

func GetNativeTokenOutput(state kv.KVStoreReader, nativeTokenID iotago.NativeTokenID, chainID isc.ChainID) (*iotago.BasicOutput, uint32, uint16)

func GetNativeTokens added in v1.0.3

func GetNativeTokens(state kv.KVStoreReader, agentID isc.AgentID) iotago.NativeTokens

func GetTotalL2FungibleTokens added in v1.0.3

func GetTotalL2FungibleTokens(state kv.KVStoreReader) *isc.Assets

func GetTotalL2NFTs added in v0.3.0

func GetTotalL2NFTs(state kv.KVStoreReader) []iotago.NFTID

func HasEnoughForAllowance added in v0.3.0

func HasEnoughForAllowance(state kv.KVStoreReader, agentID isc.AgentID, allowance *isc.Assets) bool

HasEnoughForAllowance checkes whether an account has enough balance to cover for the allowance

func MoveBetweenAccounts

func MoveBetweenAccounts(state kv.KVStore, fromAgentID, toAgentID isc.AgentID, assets *isc.Assets) error

MoveBetweenAccounts moves assets between on-chain accounts

func MoveFoundryBetweenAccounts added in v0.3.0

func MoveFoundryBetweenAccounts(state kv.KVStore, agentIDFrom, agentIDTo isc.AgentID, sn uint32)

MoveFoundryBetweenAccounts changes ownership of the foundry

func MustGetNFTData

func MustGetNFTData(state kv.KVStoreReader, id iotago.NFTID) *isc.NFT

func MustMoveBetweenAccounts added in v0.3.0

func MustMoveBetweenAccounts(state kv.KVStore, fromAgentID, toAgentID isc.AgentID, assets *isc.Assets)

func SaveFoundryOutput added in v0.3.0

func SaveFoundryOutput(state kv.KVStore, f *iotago.FoundryOutput, blockIndex uint32, outputIndex uint16)

SaveFoundryOutput stores foundry output into the map of all foundry outputs (compressed form)

func SaveMaxAssumedNonce added in v0.3.0

func SaveMaxAssumedNonce(state kv.KVStore, callerAgentID isc.AgentID, nonce uint64)

func SaveNFTOutput added in v0.3.0

func SaveNFTOutput(state kv.KVStore, out *iotago.NFTOutput, blockIndex uint32, outputIndex uint16)

SaveNFTOutput map tokenID -> foundryRec

func SaveNativeTokenOutput added in v0.3.0

func SaveNativeTokenOutput(state kv.KVStore, out *iotago.BasicOutput, blockIndex uint32, outputIndex uint16)

SaveNativeTokenOutput map nativeTokenID -> foundryRec

func SetInitialState added in v1.0.3

func SetInitialState(state kv.KVStore, baseTokensOnAnchor uint64)

this expects the origin amount minus SD

Types

type NFTOutputRec added in v0.3.0

type NFTOutputRec struct {
	Output      *iotago.NFTOutput
	BlockIndex  uint32
	OutputIndex uint16
}

func NFTOutputRecFromMarshalUtil added in v0.3.0

func NFTOutputRecFromMarshalUtil(mu *marshalutil.MarshalUtil) (*NFTOutputRec, error)

func (*NFTOutputRec) Bytes added in v0.3.0

func (r *NFTOutputRec) Bytes() []byte

func (*NFTOutputRec) String added in v0.3.0

func (r *NFTOutputRec) String() string

Jump to

Keyboard shortcuts

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