txns/buy

Methods

# (async, static) makeCloseAlgoTxns(order) → {Promise.<Transactions>}

🏭 makeCloseAlgoTxns(order)

Transaction Factory for Closing Buy Orders

Closes a Buy Order. This will refund the amount sent to the Escrow account to the Creators account. Only the owner of the escrow can issue the closeout. The contract escrow closeout requires three transactions.

❌ Cancel Order Transactions:

Index Direction Type Description Signer
TXN 0 ESCROW TO ORDERBOOK algosdk.makeApplicationClearStateTxn Application call to order book contract for closeout algosdk.LogicSigAccount
TXN 1 ESCROW TO BUYER algosdk.makePaymentTxnWithSuggestedParams Payment txn close out call algosdk.LogicSigAccount
TXN 2 BUYER TO BUYER algosdk.makePaymentTxnWithSuggestedParams Send transaction for proof that closeout sender owns the escrow Wallet
Parameters:
Name Type Description
order Order

The Order Object

Returns:
Type
Promise.<Transactions>
Example
const myOrders =await api.fetchOrders('wallet', '<WALLET ADDRESS>')
const cancelableOrder = await compile(myOrders[0])
const signedOrderTxns = sdkSigner([cancelableOrder])

for (const group of signedOrderTxns) {
  const rawTxns = group.map((txn) => txn.blob);
  const {txId} = await client.sendRawTransaction(rawTxns).do();
  await algosdk.waitForConfirmation(client, txId, 10);
}

# (async, static) makeExecuteAlgoTxns(order, withCloseoutopt) → {Promise.<Transactions>}

🏭 makeExecuteAlgoTxns(order)

Transaction Factory for Executing Buy Orders

☠ Partial Order Execution:

Index Direction Type Description Signer
TXN 0 ESCROW TO ORDERBOOK algosdk.makeApplicationNoOpTxn Transaction must be a call to a stateful contract Wallet
TXN 1 ESCROW TO SELLER algosdk.makePaymentTxn Payment transaction from this escrow to seller algosdk.LogicSigAccount
TXN 2 SELLER TO BUYER algosdk.makeAssetTransferTxn Asset transfer from seller to owner of this escrow (buyer) Wallet
TXN 3 SELLER TO ESCROW algosdk.makePaymentTxn Pay fee refund transaction Wallet

☠️ Full Order Execution:

Index Direction Type Description Signer
TXN 0 ESCROW TO ORDERBOOK algosdk.makeApplicationCloseOutTxn Transaction must be a call to a stateful contract Wallet
TXN 1 ESCROW TO SELLER algosdk.makeAssetTransferTxn Payment transaction from this escrow to seller, with closeout to owner (buyer) Wallet
TXN 2 SELLER TO BUYER algosdk.makeAssetTransferTxn Asset transfer from seller to owner of this escrow (buyer) Wallet

Parameters:
Name Type Attributes Default Description
order Order

The Order

withCloseout boolean <optional>
false

Close Account

Returns:
Type
Promise.<Transactions>

# (async, static) makePlaceAlgoTxns(order, optInopt) → {Promise.<Transactions>}

🏭 makePlaceAlgoTxns(order)

Transaction Factory for Placing Buy Orders

Place a buy order into the Algodex Orderbook. This is referred to as a Maker order which is "Placed into the Orderbook". If the order has been previously placed it will have a contract key called "creator". This key determines if the order should call the ALGO delegate contract application opt in.

Once the initial transaction has been created and the contract.creator has been sent, the sdk reverts to regular payment transactions to the escrow account. These payment transactions should include a note that relates to the operation for indexing since they will not have the orderbook application call.

The transaction generator also supports bypassing the opt-in check by passing in the optIn flag

ALGO Delegate Contract Transactions

➕ Open Order Transactions:

Index Direction Type Description Signer
TXN 0 BUYER TO ESCROW algosdk.makePaymentTxn Pay from order creator to escrow account Wallet
TXN 1 ESCROW TO ORDERBOOK algosdk.makeApplicationOptInTxn Stateful app opt-in to order book algosdk.LogicSigAccount
TXN 2 BUYER TO BUYER algosdk.makeAssetTransferTxn (Optional) ASA opt-in for the order creator's original wallet account Wallet

💰 Add Funds to Order Escrow Transactions:

Index Direction Type Description Signer
TXN 0 BUYER TO ESCROW algosdk.makePaymentTxn Pay from order creator to escrow account Wallet
TXN 1 BUYER TO BUYER algosdk.makeAssetTransferTxn (Optional) ASA opt-in for the order creator's original wallet account Wallet

Parameters:
Name Type Attributes Default Description
order Order

The Order

optIn boolean <optional>
false

Flag for opting in

Returns:
Type
Promise.<Transactions>
Example
const {makePlaceAlgoTxns, compile} = require('@algodex/algodex-sdk')
const txns = makePlaceAlgoTxns( await compile({
   'asset': {
        'id': 15322902,
        'decimals': 6,
      },
      'address': 'WYWRYK42XADLY3O62N52BOLT27DMPRA3WNBT2OBRT65N6OEZQWD4OSH6PI',
      'price': 2,
      'amount': 1,
      'total': 2,
      'execution': 'maker',
      'type': 'buy',
      'appId': 22045503,
      'version': 6,
}))