@axis-markets/client 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import {Networks} from '@stellar/stellar-sdk'
1
+ import {Networks, contract} from '@stellar/stellar-sdk'
2
2
  import ContractClient from './contract-client.js'
3
3
  import {ContractErrors, processSimulationErrors} from './errors.js'
4
4
  import {AxisApiClient, AxisApiError} from './api-client.js'
5
+ import {collectOrderIds, ensureOrdersFootprint} from './footprint.js'
5
6
 
6
7
  export {ContractErrors, AxisApiClient, AxisApiError}
7
8
 
@@ -39,6 +40,20 @@ export class AxisContractClient {
39
40
  }
40
41
  this.client = new ContractClient(options)
41
42
  this.fee = params.fee || '100000'
43
+ this.autoFootprint = params.autoFootprint !== false
44
+ }
45
+
46
+ /**
47
+ * Declare all order ids of a simulated call in the read-write footprint (if enabled)
48
+ * @param {contract.AssembledTransaction} tx - Simulated transaction
49
+ * @param {...Array<bigint>} idLists - Order ids passed to the contract call
50
+ * @private
51
+ */
52
+ updateFootprint(tx, ...idLists) {
53
+ if (this.autoFootprint) {
54
+ const orderIds = collectOrderIds(...idLists)
55
+ ensureOrdersFootprint(tx, this.client.options.contractId, orderIds)
56
+ }
42
57
  }
43
58
 
44
59
  /**
@@ -87,6 +102,7 @@ export class AxisContractClient {
87
102
  async fill_order(trader, takerOrderId, orders) {
88
103
  const tx = await this.client.fill_order({trader, taker_order_id: takerOrderId, orders}, {fee: this.fee})
89
104
  processSimulationErrors(tx)
105
+ this.updateFootprint(tx, [takerOrderId], orders)
90
106
  const res = await tx.signAndSend()
91
107
  return [res.result.sold, res.result.bought]
92
108
  }
@@ -125,6 +141,7 @@ export class AxisContractClient {
125
141
  path: params.path.map(step => ({asset: step.asset, orders: step.orders}))
126
142
  }, {fee: this.fee})
127
143
  processSimulationErrors(tx)
144
+ this.updateFootprint(tx, ...params.path.map(step => step.orders))
128
145
  const res = await tx.signAndSend()
129
146
  return [res.result.sold, res.result.bought]
130
147
  }
@@ -143,6 +160,7 @@ async function execTrade(params, direction, context) {
143
160
  }
144
161
  const tx = await context.client.trade(payload, {fee: context.fee})
145
162
  processSimulationErrors(tx)
163
+ context.updateFootprint(tx, params.orders)
146
164
  const {result} = await tx.signAndSend()
147
165
  return [result[0], result[1], result[2]]
148
166
  }
@@ -155,6 +173,7 @@ async function execTrade(params, direction, context) {
155
173
  * @property {string} contractId - DEX contract ID
156
174
  * @property {string} [networkPassphrase] - Network passphrase (Pubnet passphrase by default)
157
175
  * @property {string} [fee] - Transaction fee (0.1 XLM by default)
176
+ * @property {boolean} [autoFootprint] - Declare every supplied order id in the read-write footprint of trading transactions (enabled by default)
158
177
  */
159
178
 
160
179
  /**