order/compile

Compile

Library for Compiling Smart Contracts. Includes three main exports

Examples
const compile = require('@algodex/algodex-sdk/lib/compile')
await compile({
  // Standard Order Shape
})
const {withUnits} = require('@algodex/algodex-sdk/lib/compile');
withUnits({
  // Standard Order Shape
})

Methods

# (async, static) compile(o) → {Promise.<Order>}

🏗 Compile Order

Takes an Order and compiles it into the required shape for the sdk. This includes converting floats to BaseUnits with Numerator and Denominator. The BaseUnits properties are used to compile the delegate template. Then it constructs a LogicSigAccount which is the main output of the compile step.

Parameters:
Name Type Description
o Order

The Order Object

Returns:

Returns a composed order with ContractState

Type
Promise.<Order>
Example
const {order: compile} = require('@algodex/sdk')
const order = compile({
  "client": new algosdk.Algodv2(),
  "asset": {
    "id": 15322902,
    "decimals": 6,
  },
  "address": "TJFFNUYWHPPIYDE4DGGYPGHWKGAPJEWP3DGE5THZS3B2M2XIAPQ2WY3X4I",
  "price": 2.22,
  "amount": 1,
  "total": 2,
  "execution": "maker",
  "type": "buy",
  "appId": 22045503,
  "version": 6
})
console.log(order.contract.lsig)
// Outputs LogicSigAccount

# (async, static) withLogicSigAccount(o) → {Promise.<Order>}

✏ With LogicSigAccount

Compose an Order with its template and create a LogicSigAccount.

Parameters:
Name Type Description
o Order

Algodex Order

Returns:
Type
Promise.<Order>
Example
const res = await withLogicSigAccount(withUnits(order));
console.log(res.contract.lsig)
// Outputs LogicSigAccount

# (static) withOrderbookEntry(o) → {Order}

🗃 With Orderbook Entry

Adds the orderbook entry to the order

Parameters:
Name Type Description
o Order

Order

Returns:

Order with Entry

Type
Order

# (static) withUnits(o) → {Order}

🧮 With Units

Compose the current order with it's converted units

Parameters:
Name Type Description
o Order

Algodex Order

Returns:

Order with Units

Type
Order
Example
const res = withUnits(order);
console.log(res.contract).
// Outputs {N,D,price,amount,total} in BaseUnits