templates

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDynamicFeeTransactions deprecated added in v1.3.0

func GetDynamicFeeTransactions(txn types.Transaction, lsig types.LogicSig, privateKey ed25519.PrivateKey, fee uint64) ([]byte, error)

GetDynamicFeeTransactions creates and signs the secondary dynamic fee transaction, updates transaction fields, and signs as the fee payer; it returns both transactions as bytes suitable for sendRaw. Parameters: txn - main transaction from payer lsig - the signed logic received from the payer privateKey - the private key for the account that pays the fee fee - fee per byte for both transactions firstValid - first protocol round on which both transactions will be valid lastValid - last protocol round on which both transactions will be valid

Deprecated: Use TealCompile source compilation instead.

func GetPeriodicPaymentWithdrawalTransaction deprecated added in v1.3.0

func GetPeriodicPaymentWithdrawalTransaction(contract []byte, firstValid, fee uint64, genesisHash []byte) ([]byte, error)

GetPeriodicPaymentWithdrawalTransaction returns a signed transaction extracting funds from the contract contract: the bytearray defining the contract, received from the payer firstValid: the first round on which the txn will be valid fee: the fee in microalgos per byte of the payment txn genesisHash: the hash representing the network for the txn

Deprecated: Use TealCompile source compilation instead.

func GetSplitFundsTransaction deprecated added in v1.3.0

func GetSplitFundsTransaction(contract []byte, amount uint64, params types.SuggestedParams) ([]byte, error)

GetSplitFundsTransaction returns a group transaction array which transfer funds according to the contract's ratio the returned byte array is suitable for passing to SendRawTransaction contract: the bytecode of the contract to be used amount: uint64 total number of algos to be transferred (payment1_amount + payment2_amount) params: is typically received from algod, it defines common-to-all-txns arguments like fee and validity period

Deprecated: Use TealCompile source compilation instead.

func SignDynamicFee deprecated added in v1.3.0

func SignDynamicFee(contract []byte, privateKey ed25519.PrivateKey, genesisHash []byte) (txn types.Transaction, lsig types.LogicSig, err error)

SignDynamicFee takes in the contract bytes and returns the main transaction and signed logic needed to complete the transfer. These should be sent to the fee payer, who can use GetDynamicFeeTransactions() to update fields and create the auxiliary transaction. Parameters: contract - the bytearray representing the contract in question genesisHash - the bytearray representing the network for the txns

Deprecated: Use TealCompile source compilation instead.

func SignTransactionWithHTLCUnlock deprecated added in v1.3.0

func SignTransactionWithHTLCUnlock(program []byte, txn types.Transaction, preImageAsBase64 string) (txid string, stx []byte, err error)

SignTransactionWithHTLCUnlock accepts a transaction, such as a payment, and builds the HTLC-unlocking signature around that transaction

Deprecated: Use TealCompile source compilation instead.

Types

type ContractTemplate deprecated

type ContractTemplate struct {
	// contains filtered or unexported fields
}

ContractTemplate template representation

Deprecated: Use TealCompile source compilation instead.

func (ContractTemplate) GetAddress

func (contract ContractTemplate) GetAddress() string

GetAddress returns the contract address

func (ContractTemplate) GetProgram

func (contract ContractTemplate) GetProgram() []byte

GetProgram returns the program bytes

type DynamicFee added in v1.3.0

type DynamicFee struct {
	ContractTemplate
}

DynamicFee template representation

func MakeDynamicFee deprecated added in v1.3.0

func MakeDynamicFee(receiver, closeRemainder string, amount, firstValid, lastValid uint64) (DynamicFee, error)

MakeDynamicFee contract allows you to create a transaction without specifying the fee. The fee will be determined at the moment of transfer.

Parameters:

  • receiver: address which is authorized to receive withdrawals
  • closeRemainder: address which will receive the balance of funds
  • amount: the maximum number of funds allowed for a single withdrawal
  • withdrawWindow: the duration of a withdrawal period
  • period: the time between a pair of withdrawal periods
  • expiryRound: the round at which the account expires
  • maxFee: maximum fee used by the withdrawal transaction

Deprecated: Use TealCompile source compilation instead.

type HTLC

type HTLC struct {
	ContractTemplate
}

HTLC template representation

func MakeHTLC deprecated

func MakeHTLC(owner, receiver, hashFunction, hashImage string, expiryRound, maxFee uint64) (HTLC, error)

MakeHTLC allows a user to receive the Algo prior to a deadline (in terms of a round) by proving a knowledge of a special value or to forfeit the ability to claim, returning it to the payer. This contract is usually used to perform cross-chained atomic swaps

More formally - Algos can be transferred under only two circumstances: 1. To receiver if hash_function(arg_0) = hash_value 2. To owner if txn.FirstValid > expiry_round ...

Parameters: - owner : string an address that can receive the asset after the expiry round - receiver: string address to receive Algos - hashFunction : string the hash function to be used (must be either sha256 or keccak256) - hashImage : string the hash image in base64 - expiryRound : uint64 the round on which the assets can be transferred back to owner - maxFee : uint64 the maximum fee that can be paid to the network by the account

Deprecated: Use TealCompile source compilation instead.

type LimitOrder deprecated added in v1.3.0

type LimitOrder struct {
	ContractTemplate
	// contains filtered or unexported fields
}

LimitOrder represents a swap between Algos and an Asset at some ratio or better.

Deprecated: Use TealCompile source compilation instead.

func MakeLimitOrder deprecated added in v1.3.0

func MakeLimitOrder(owner string, assetID, ratn, ratd, expiryRound, minTrade, maxFee uint64) (LimitOrder, error)

MakeLimitOrder allows a user to exchange some number of assets for some number of algos. Fund the contract with some number of Algos to limit the maximum number of Algos you're willing to trade for some other asset.

Works on two cases: * trading Algos for some other asset * closing out Algos back to the originator after a timeout

trade case, a 2 transaction group: gtxn[0] (this txn) Algos from Me to Other gtxn[1] asset from Other to Me

We want to get _at least_ some amount of the other asset per our Algos gtxn[1].AssetAmount / gtxn[0].Amount >= N / D === gtxn[1].AssetAmount * D >= gtxn[0].Amount * N

close-out case: txn alone, close out value after timeout

Parameters:

  • owner: the address to refund funds to on timeout
  • assetID: ID of the transferred asset
  • ratn: exchange rate (N asset per D Algos, or better)
  • ratd: exchange rate (N asset per D Algos, or better)
  • expiryRound: the round at which the account expires
  • minTrade: the minimum amount (of Algos) to be traded away
  • maxFee: maximum fee used by the limit order transaction

Deprecated: Use TealCompile source compilation instead.

func (LimitOrder) GetSwapAssetsTransaction deprecated added in v1.3.0

func (lo LimitOrder) GetSwapAssetsTransaction(assetAmount uint64, microAlgoAmount uint64, contract, secretKey []byte, params types.SuggestedParams) ([]byte, error)

GetSwapAssetsTransaction returns a group transaction array which transfer funds according to the contract's ratio assetAmount: amount of assets to be sent contract: byteform of the contract from the payer secretKey: secret key for signing transactions microAlgoAmount: number of microAlgos to transfer params: txn params for the transactions the first payment sends money (Algos) from contract to the recipient (we'll call him Buyer), closing the rest of the account to Owner the second payment sends money (the asset) from Buyer to the Owner these transactions will be rejected if they do not meet the restrictions set by the contract

Deprecated: Use TealCompile source compilation instead.

type PeriodicPayment deprecated added in v1.3.0

type PeriodicPayment struct {
	ContractTemplate
}

PeriodicPayment template representation

Deprecated: Use TealCompile source compilation instead.

func MakePeriodicPayment deprecated added in v1.3.0

func MakePeriodicPayment(receiver string, amount, withdrawWindow, period, expiryRound, maxFee uint64) (PeriodicPayment, error)

MakePeriodicPayment allows some account to execute periodic withdrawal of funds. This is a contract account.

This allows receiver to withdraw amount every period rounds for withdrawWindow after every multiple of period.

After expiryRound, all remaining funds in the escrow are available to receiver.

Parameters:

  • receiver: address which is authorized to receive withdrawals
  • amount: the maximum number of funds allowed for a single withdrawal
  • withdrawWindow: the duration of a withdrawal period
  • period: the time between a pair of withdrawal periods
  • expiryRound: the round at which the account expires
  • maxFee: maximum fee used by the withdrawal transaction

Deprecated: Use TealCompile source compilation instead.

type Split deprecated

type Split struct {
	ContractTemplate
	// contains filtered or unexported fields
}

Split template representation

Deprecated: Use TealCompile source compilation instead.

func MakeSplit deprecated

func MakeSplit(owner, receiverOne, receiverTwo string, rat1, rat2, expiryRound, minPay, maxFee uint64) (Split, error)

MakeSplit splits money sent to some account to two recipients at some ratio. This is a contract account.

This allows either a two-transaction group, for executing a split, or single transaction, for closing the account.

Withdrawals from this account are allowed as a group transaction which sends receiverOne and receiverTwo amounts with exactly the ratio of rat1/rat2. At least minPay must be sent to receiverOne. (CloseRemainderTo must be zero.)

After expiryRound passes, all funds can be refunded to owner.

Split ratio: firstRecipient_amount * rat2 == secondRecipient_amount * rat1 or phrased another way firstRecipient_amount == secondRecipient_amount * (rat1/rat2)

Parameters:

  • owner: the address to refund funds to on timeout
  • receiverOne: the first recipient in the split account
  • receiverTwo: the second recipient in the split account
  • rat1: fraction determines resource split ratio
  • rat2: fraction determines resource split ratio
  • expiryRound: the round at which the account expires
  • minPay: minimum amount to be paid out of the account to receiverOne
  • maxFee: half of the maximum fee used by each split forwarding group transaction

Deprecated: Use TealCompile source compilation instead.

Jump to

Keyboard shortcuts

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