@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/README.md +41 -9
- package/lib/axis-client.cjs +1 -1
- package/lib/axis-client.cjs.map +1 -1
- package/lib/footprint.cjs +2 -0
- package/lib/footprint.cjs.map +1 -0
- package/package.json +9 -2
- package/src/footprint.d.ts +32 -0
- package/src/footprint.js +123 -0
- package/src/index.d.ts +523 -521
- package/src/index.js +20 -1
package/README.md
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
JavaScript SDK for [AXIS](https://axis.markets) Stellar DEX.
|
|
4
4
|
|
|
5
|
-
- **`AxisContractClient`** — wraps the on-chain AXIS smart contract for order management and trading (sign & send
|
|
6
|
-
|
|
5
|
+
- **`AxisContractClient`** — wraps the on-chain AXIS smart contract for order management and trading (sign & send
|
|
6
|
+
transactions, read orders).
|
|
7
|
+
- **`AxisApiClient`** — a dependency-free HTTP client for the AXIS Aggregator and Indexer REST API (quotes, orderbook
|
|
8
|
+
depth, candles, ticker, market/order/trade data).
|
|
7
9
|
|
|
8
10
|
## Installation
|
|
9
11
|
|
|
@@ -48,7 +50,8 @@ const [sold, bought, newOrderId] = await client.sell({
|
|
|
48
50
|
await client.cancel([lastId], 'G...')
|
|
49
51
|
```
|
|
50
52
|
|
|
51
|
-
See [`src/index.d.ts`](src/index.d.ts) for the full typed API (`buy`, `sell`, `swap`, `fill_order`, `cancel`, `order`,
|
|
53
|
+
See [`src/index.d.ts`](src/index.d.ts) for the full typed API (`buy`, `sell`, `swap`, `fill_order`, `cancel`, `order`,
|
|
54
|
+
`last`).
|
|
52
55
|
|
|
53
56
|
### Methods
|
|
54
57
|
|
|
@@ -95,12 +98,14 @@ Parameters passed to the `AxisContractClient` constructor.
|
|
|
95
98
|
| `contractId` | `string` | DEX contract id. |
|
|
96
99
|
| `networkPassphrase?` | `string` | Network passphrase (Pubnet passphrase by default). |
|
|
97
100
|
| `fee?` | `string` | Transaction fee (0.1 XLM by default). |
|
|
101
|
+
| `autoFootprint?` | `boolean` | Declare every supplied order id in the read-write footprint of trading transactions (enabled by default). |
|
|
98
102
|
|
|
99
103
|
#### `SignTransactionCallback`
|
|
100
104
|
|
|
101
105
|
`(tx: string, context: {network, networkPassphrase, accountToSign}) => Promise<{signedTxXdr, signerAddress?}>`
|
|
102
106
|
|
|
103
|
-
Callback for signing transactions generated by the client. Receives the transaction XDR to sign plus the signing
|
|
107
|
+
Callback for signing transactions generated by the client. Receives the transaction XDR to sign plus the signing
|
|
108
|
+
context, and resolves to the signed transaction response.
|
|
104
109
|
|
|
105
110
|
#### `TradeArguments`
|
|
106
111
|
|
|
@@ -200,7 +205,6 @@ Orderbook swap event emitted by the contract.
|
|
|
200
205
|
| `sold` | `bigint` | Amount of `selling` tokens sold. |
|
|
201
206
|
| `bought` | `bigint` | Amount of `buying` tokens received. |
|
|
202
207
|
|
|
203
|
-
|
|
204
208
|
## AxisApiClient
|
|
205
209
|
|
|
206
210
|
HTTP client for the AXIS Aggregator REST API. Uses the standard `fetch` API - no extra dependencies.
|
|
@@ -249,8 +253,8 @@ const {ticker} = await api.getTicker24h()
|
|
|
249
253
|
| `getOrderHistory({owner?, pair?, cursor?, limit?})` | Archived/historical orders (`pair` = `[base, quote]` contract ids). |
|
|
250
254
|
| `getTrades({trader?, pair?, cursor?, limit?})` | Recent trades (`pair` = `[base, quote]` contract ids). |
|
|
251
255
|
|
|
252
|
-
Assets accept Soroban contract id or classic asset string formats like `XLM`, `CODE:Issuer`, `CODE-Issuer`.
|
|
253
|
-
|
|
256
|
+
Assets accept Soroban contract id or classic asset string formats like `XLM`, `CODE:Issuer`, `CODE-Issuer`. Markets use
|
|
257
|
+
`BASE/QUOTE` convention. Amounts are expressed in stroops on input and returned as strings.
|
|
254
258
|
|
|
255
259
|
### Error handling
|
|
256
260
|
|
|
@@ -267,16 +271,44 @@ try {
|
|
|
267
271
|
}
|
|
268
272
|
```
|
|
269
273
|
|
|
274
|
+
## Order footprint
|
|
275
|
+
|
|
276
|
+
Soroban RPC simulation records only the ledger entries the contract actually touched against the state at simulation
|
|
277
|
+
time. The orderbook matching loop stops as soon as the taker is filled, and orders it skipped are recorded read-only. If
|
|
278
|
+
somebody else fills part of the matched orders before the transaction lands, the contract has to read and write orders
|
|
279
|
+
that are missing from the footprint, resulting in a rejection.
|
|
280
|
+
|
|
281
|
+
To make trading transactions resilient to such concurrent fills, `buy`, `sell`, `fill_order` and `swap` patch the
|
|
282
|
+
simulated transaction before signing: every order id passed in `orders` (plus the taker order id for `fill_order`, and
|
|
283
|
+
every path step for `swap`) is declared in the read-write footprint, and the declared instructions, write bytes and
|
|
284
|
+
resource fee are increased for each order simulation did not match. The surplus resource fee is refundable, so unused
|
|
285
|
+
orders cost only the extra ledger entry declaration. Pass `autoFootprint: false` to the constructor to opt out.
|
|
286
|
+
|
|
287
|
+
The helpers exported for custom pipelines:
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
import {collectOrderIds, ensureOrdersFootprint, orderLedgerKey} from '@axis-markets/client/footprint'
|
|
291
|
+
|
|
292
|
+
const tx = await client.client.trade(payload, {fee})
|
|
293
|
+
ensureOrdersFootprint(tx, contractId, collectOrderIds(payload.orders))
|
|
294
|
+
await tx.signAndSend()
|
|
295
|
+
```
|
|
296
|
+
|
|
270
297
|
## Development
|
|
271
298
|
|
|
299
|
+
Run tests:
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
pnpm test
|
|
303
|
+
```
|
|
304
|
+
|
|
272
305
|
Bundling script:
|
|
273
306
|
|
|
274
307
|
```
|
|
275
308
|
npm run prepare
|
|
276
309
|
```
|
|
277
310
|
|
|
278
|
-
Bundles the ESM source (`src/`) into a UMD
|
|
279
|
-
Type definitions are published from `src/index.d.ts`.
|
|
311
|
+
Bundles the ESM source (`src/`) into a UMD library (`lib/`) via webpack. Type definitions located in `src/index.d.ts`.
|
|
280
312
|
|
|
281
313
|
## License
|
|
282
314
|
|
package/lib/axis-client.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(A,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@stellar/stellar-sdk")):"function"==typeof define&&define.amd?define(["@stellar/stellar-sdk"],t):"object"==typeof exports?exports.axisClient=t(require("@stellar/stellar-sdk")):A.axisClient=t(A["@stellar/stellar-sdk"])}(this,A=>(()=>{"use strict";var t={346(t){t.exports=A}},l={};function c(A){var e=l[A];if(void 0!==e)return e.exports;var r=l[A]={exports:{}};return t[A](r,r.exports,c),r.exports}c.d=(A,t)=>{for(var l in t)c.o(t,l)&&!c.o(A,l)&&Object.defineProperty(A,l,{enumerable:!0,get:t[l]})},c.o=(A,t)=>Object.prototype.hasOwnProperty.call(A,t);var e={};c.d(e,{default:()=>g});var r=c(346);class G extends r.contract.Client{options;constructor(A){super(new r.contract.Spec(["AAAAAAAAADJHZXQgbGF0IG9yZGVyIGlkCgojIFJldHVybnMKCkxhc3QgY3JlYXRlZCBvcmRlciBpZAAAAAAABGxhc3QAAAAAAAAAAQAAAAY=","AAAAAAAAA4ZTd2FwIHRva2VucyBhY3Jvc3Mgc2V2ZXJhbCBtYXJrZXRzLgpUaGUgc3dhcCBleGVjdXRlcyB3aXRoaW4gdGhlIGJvdW5kYXJpZXMsIG90aGVyd2lzZSB0cmFkZSBnZXQgY2FuY2VsZWQ6CiogYFNlbGxgOiBleGFjdGx5IGBzZWxsaW5nX2Ftb3VudGAgc29sZCwgdGhlIHJlY2VpdmVkIGFtb3VudCBpcyBgPj0gYnV5aW5nX2Ftb3VudGAKKiBgQnV5YDogZXhhY3RseSBgYnV5aW5nX2Ftb3VudGAgcmVjZWl2ZWQsIHRoZSBzcGVudCBhbW91bnQgaXMgYDw9IHNlbGxpbmdfYW1vdW50YAoKCiMgQXJndW1lbnRzCiogYGRpcmVjdGlvbmAgLSBUcmFkZSBkaXJlY3Rpb246IGBTZWxsYCBvciBgQnV5YAoqIGB0cmF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AAABAAAADVRyYWRlIGRldGFpbHMAAAAAAAAFdHJhZGUAAAAAAAfQAAAABVRyYWRlAAAAAAAAAAAAAAA="]),A),this.options=A}fromJSON={last:this.txFromJSON,order:this.txFromJSON,cancel:this.txFromJSON,trade:this.txFromJSON,swap:this.txFromJSON,fill_order:this.txFromJSON}}const s={701:{message:"NotAuthorized"},702:{message:"InsufficientBalance"},703:{message:"OrderNotFound"},704:{message:"Overflow"},705:{message:"InvalidMatch"},706:{message:"InvalidPrice"}};function Z(A){if(A.simulation.error){const t=/HostError: Error\(Contract, #(\d+)\)/.exec(A.simulation.error);if(t){const A=t[1],l=s[A];if(l)throw new Error(`Contract execution error: #${A} ${l.message} `)}throw A.simulation.error}}class B extends Error{constructor(A,t){super(A),this.name="AxisApiError",this.status=t}status}const a={Sell:1,Buy:2};async function d(A,t,l){const c={direction:t,kind:A.kind,trader:A.trader,amount:A.amount,selling:A.selling,buying:A.buying,price:A.price,orders:A.orders},e=await l.client.trade(c,{fee:l.fee});Z(e);const{result:r}=await e.signAndSend();return[r[0],r[1],r[2]]}const g={AxisContractClient:class{constructor(A){const t={publicKey:A.publicKey,signTransaction:A.signTransaction,rpcUrl:A.rpcUrl,allowHttp:!0,networkPassphrase:A.networkPassphrase||r.Networks.PUBLIC,contractId:A.contractId};this.client=new G(t),this.fee=A.fee||"100000"}async last(){const A=await this.client.last();return Z(A),A.result}async order(A){const t=await this.client.order({id:A});return Z(t),t.result}async cancel(A,t){const l=await this.client.cancel({ids:A,trader:t},{fee:this.fee});Z(l),await l.signAndSend()}async fill_order(A,t,l){const c=await this.client.fill_order({trader:A,taker_order_id:t,orders:l},{fee:this.fee});Z(c);const e=await c.signAndSend();return[e.result.sold,e.result.bought]}async buy(A){return await d(A,a.Buy,this)}async sell(A){return await d(A,a.Sell,this)}async swap(A){const t=await this.client.swap({direction:A.direction,trader:A.trader,selling:A.selling,selling_amount:A.sellingAmount,buying_amount:A.buyingAmount,path:A.path.map(A=>({asset:A.asset,orders:A.orders}))},{fee:this.fee});Z(t);const l=await t.signAndSend();return[l.result.sold,l.result.bought]}},ContractErrors:s,TradeDirection:a,OrderKind:{Limit:1,Fill:2,FillOrKill:3},AxisApiClient:class{constructor(A){if(!A||"string"!=typeof A)throw new TypeError("Aggregator server URL is required");this.serverUrl=A.replace(/\/+$/,"")}serverUrl;async quoteSell(A){return this.quote(A,"strict_send")}async quoteBuy(A){return this.quote(A,"strict_receive")}async quote({sellingAsset:A,buyingAsset:t,amount:l,direct:c},e){return this.request("/quote",{sellingAsset:A,buyingAsset:t,amount:l,direction:e,direct:c})}async getDepth({market:A,depth:t}){return this.request("/depth",{market:A,depth:t})}async getCandles({market:A,from:t,to:l,resolution:c,order:e}){return this.request("/candles",{market:A,from:t,to:l,resolution:c,order:e})}async getTicker24h(){return this.request("/ticker/24h")}async getMarkets({cursor:A,limit:t}={}){return this.request("/markets",{cursor:A,limit:t})}async getOrders({owner:A,asset:t,cursor:l,limit:c}={}){return this.request("/order",{owner:A,asset:t,cursor:l,limit:c})}async getOrder(A){return this.request(`/order/${encodeURIComponent(A.toString())}`)}async getOrderHistory({owner:A,pair:t,cursor:l,limit:c}={}){return this.request("/order-history",{owner:A,pair:t,cursor:l,limit:c})}async getTrades({trader:A,pair:t,cursor:l,limit:c}={}){return this.request("/trades",{trader:A,pair:t,cursor:l,limit:c})}async request(A,t){let l=this.serverUrl+A;if(t){const A=new URLSearchParams;for(const[l,c]of Object.entries(t))if(null!=c)if(Array.isArray(c))for(const t of c)A.append(l,t);else A.append(l,c);const c=A.toString();c&&(l+="?"+c)}const c=await fetch(l);let e;try{e=await c.json()}catch(A){e=null}if(!c.ok)throw new B(e?.error||c.statusText,e?.status||c.status);return e}},AxisApiError:B};return e.default})());
|
|
1
|
+
!function(A,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@stellar/stellar-sdk")):"function"==typeof define&&define.amd?define(["@stellar/stellar-sdk"],t):"object"==typeof exports?exports.axisClient=t(require("@stellar/stellar-sdk")):A.axisClient=t(A["@stellar/stellar-sdk"])}(this,A=>(()=>{"use strict";var t={346(t){t.exports=A}},e={};function r(A){var c=e[A];if(void 0!==c)return c.exports;var l=e[A]={exports:{}};return t[A](l,l.exports,r),l.exports}r.d=(A,t)=>{for(var e in t)r.o(t,e)&&!r.o(A,e)&&Object.defineProperty(A,e,{enumerable:!0,get:t[e]})},r.o=(A,t)=>Object.prototype.hasOwnProperty.call(A,t);var c={};r.d(c,{default:()=>B});var l=r(346);class s extends l.contract.Client{options;constructor(A){super(new l.contract.Spec(["AAAAAAAAADJHZXQgbGF0IG9yZGVyIGlkCgojIFJldHVybnMKCkxhc3QgY3JlYXRlZCBvcmRlciBpZAAAAAAABGxhc3QAAAAAAAAAAQAAAAY=","AAAAAAAAA4ZTd2FwIHRva2VucyBhY3Jvc3Mgc2V2ZXJhbCBtYXJrZXRzLgpUaGUgc3dhcCBleGVjdXRlcyB3aXRoaW4gdGhlIGJvdW5kYXJpZXMsIG90aGVyd2lzZSB0cmFkZSBnZXQgY2FuY2VsZWQ6CiogYFNlbGxgOiBleGFjdGx5IGBzZWxsaW5nX2Ftb3VudGAgc29sZCwgdGhlIHJlY2VpdmVkIGFtb3VudCBpcyBgPj0gYnV5aW5nX2Ftb3VudGAKKiBgQnV5YDogZXhhY3RseSBgYnV5aW5nX2Ftb3VudGAgcmVjZWl2ZWQsIHRoZSBzcGVudCBhbW91bnQgaXMgYDw9IHNlbGxpbmdfYW1vdW50YAoKCiMgQXJndW1lbnRzCiogYGRpcmVjdGlvbmAgLSBUcmFkZSBkaXJlY3Rpb246IGBTZWxsYCBvciBgQnV5YAoqIGB0cmFkZXJgIC0gVHJhZGVyIGFkZHJlc3MKKiBgc2VsbGluZ2AgLSBUb2tlbiBhZGRyZXNzIHNlbnQgYnkgdGhlIHRyYWRlcgoqIGBzZWxsaW5nX2Ftb3VudGAgLSBNYXhpbXVtIGFtb3VudCBvZiBzZWxsaW5nIHRva2VucyB0byBzZW5kCiogYGJ1eWluZ19hbW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nZhbGlkTWF0Y2gAAALBAAAAAAAAAAxJbnZhbGlkUHJpY2UAAALC","AAAABQAAAAAAAAAAAAAACVN3YXBFdmVudAAAAAAAAAIAAAAEQVhJUwAAAARzd2FwAAAAAwAAABhBc3NldCBzb2xkIGJ5IHRoZSB0cmFkZXIAAAAHc2VsbGluZwAAAAATAAAAAQAAABxBc3NldCByZWNlaXZlZCBieSB0aGUgdHJhZGVyAAAABmJ1eWluZwAAAAAAEwAAAAEAAAAMU3dhcCBkZXRhaWxzAAAABHN3YXAAAAfQAAAABFN3YXAAAAAAAAAAAA==","AAAABQAAAAAAAAAAAAAACk9yZGVyRXZlbnQAAAAAAAIAAAAEQVhJUwAAAAVvcmRlcgAAAAAAAAQAAAAwT3JkZXIgY2hhbmdlIHR5cGU6ICJjcmVhdGVkInwidXBkYXRlZCJ8InJlbW92ZWQiAAAABmFjdGlvbgAAAAAAEQAAAAEAAAAVU2VsbGluZyBhc3NldCBhZGRyZXNzAAAAAAAAB3NlbGxpbmcAAAAAEwAAAAEAAAAUQnV5aW5nIGFzc2V0IGFkZHJlc3MAAAAGYnV5aW5nAAAAAAATAAAAAQAAAA1PcmRlciBkZXRhaWxzAAAAAAAABW9yZGVyAAAAAAAH0AAAAAVPcmRlcgAAAAAAAAAAAAAA","AAAABQAAAAAAAAAAAAAAClRyYWRlRXZlbnQAAAAAAAIAAAAEQVhJUwAAAAV0cmFkZQAAAAAAAAMAAAASU29sZCBhc3NldCBhZGRyZXNzAAAAAAAHc2VsbGluZwAAAAATAAAAAQAAABRCb3VnaHQgYXNzZXQgYWRkcmVzcwAAAAZidXlpbmcAAAAAABMAAAABAAAADVRyYWRlIGRldGFpbHMAAAAAAAAFdHJhZGUAAAAAAAfQAAAABVRyYWRlAAAAAAAAAAAAAAA="]),A),this.options=A}fromJSON={last:this.txFromJSON,order:this.txFromJSON,cancel:this.txFromJSON,trade:this.txFromJSON,swap:this.txFromJSON,fill_order:this.txFromJSON}}const n={701:{message:"NotAuthorized"},702:{message:"InsufficientBalance"},703:{message:"OrderNotFound"},704:{message:"Overflow"},705:{message:"InvalidMatch"},706:{message:"InvalidPrice"}};function i(A){if(A.simulation.error){const t=/HostError: Error\(Contract, #(\d+)\)/.exec(A.simulation.error);if(t){const A=t[1],e=n[A];if(e)throw new Error(`Contract execution error: #${A} ${e.message} `)}throw A.simulation.error}}class a extends Error{constructor(A,t){super(A),this.name="AxisApiError",this.status=t}status}function d(...A){const t=new Set,e=[];for(const r of A)if(r)for(const A of r){if(null==A)continue;const r=BigInt(A),c=r.toString();t.has(c)||(t.add(c),e.push(r))}return e}function o(A,t){return l.xdr.LedgerKey.contractData(new l.xdr.LedgerKeyContractData({contract:l.Address.fromString(A).toScAddress(),key:l.xdr.ScVal.scvU64(new l.xdr.Uint64(BigInt(t))),durability:l.xdr.ContractDataDurability.persistent()}))}const G={Sell:1,Buy:2};async function Z(A,t,e){const r={direction:t,kind:A.kind,trader:A.trader,amount:A.amount,selling:A.selling,buying:A.buying,price:A.price,orders:A.orders},c=await e.client.trade(r,{fee:e.fee});i(c),e.updateFootprint(c,A.orders);const{result:l}=await c.signAndSend();return[l[0],l[1],l[2]]}const B={AxisContractClient:class{constructor(A){const t={publicKey:A.publicKey,signTransaction:A.signTransaction,rpcUrl:A.rpcUrl,allowHttp:!0,networkPassphrase:A.networkPassphrase||l.Networks.PUBLIC,contractId:A.contractId};this.client=new s(t),this.fee=A.fee||"100000",this.autoFootprint=!1!==A.autoFootprint}updateFootprint(A,...t){if(this.autoFootprint){const e=d(...t);!function(A,t,e){const r=A.simulation;if(!r||r.error||r.restorePreamble||!A.built||!e?.length)return 0;const c=r.transactionData,s=c.getReadOnly(),n=c.getReadWrite(),i=new Map(s.map((A,t)=>[A.toXDR("base64"),t])),a=new Set(n.map(A=>A.toXDR("base64"))),G=new Set;let Z=0;for(const A of d(e)){const e=o(t,A),r=e.toXDR("base64");a.has(r)||(i.has(r)&&G.add(i.get(r)),n.push(e),a.add(r),Z++)}if(0===Z)return 0;const B=s.filter((A,t)=>!G.has(t));c.setFootprint(B,n);const g=c.build().resources(),b=Math.min(g.instructions()+2e6*Z,1e8);c.setResources(b,g.diskReadBytes(),g.writeBytes()+512*Z);const u=c.build().resourceFee().toBigInt()+100000n*BigInt(Z);c.setResourceFee(u.toString()),delete A.simulationTransactionData;const I=A.options?.timeoutInSeconds??300;A.built=l.TransactionBuilder.cloneFrom(A.built,{sorobanData:c.build(),timebounds:void 0}).setTimeout(I).build()}(A,this.client.options.contractId,e)}}async last(){const A=await this.client.last();return i(A),A.result}async order(A){const t=await this.client.order({id:A});return i(t),t.result}async cancel(A,t){const e=await this.client.cancel({ids:A,trader:t},{fee:this.fee});i(e),await e.signAndSend()}async fill_order(A,t,e){const r=await this.client.fill_order({trader:A,taker_order_id:t,orders:e},{fee:this.fee});i(r),this.updateFootprint(r,[t],e);const c=await r.signAndSend();return[c.result.sold,c.result.bought]}async buy(A){return await Z(A,G.Buy,this)}async sell(A){return await Z(A,G.Sell,this)}async swap(A){const t=await this.client.swap({direction:A.direction,trader:A.trader,selling:A.selling,selling_amount:A.sellingAmount,buying_amount:A.buyingAmount,path:A.path.map(A=>({asset:A.asset,orders:A.orders}))},{fee:this.fee});i(t),this.updateFootprint(t,...A.path.map(A=>A.orders));const e=await t.signAndSend();return[e.result.sold,e.result.bought]}},ContractErrors:n,TradeDirection:G,OrderKind:{Limit:1,Fill:2,FillOrKill:3},AxisApiClient:class{constructor(A){if(!A||"string"!=typeof A)throw new TypeError("Aggregator server URL is required");this.serverUrl=A.replace(/\/+$/,"")}serverUrl;async quoteSell(A){return this.quote(A,"strict_send")}async quoteBuy(A){return this.quote(A,"strict_receive")}async quote({sellingAsset:A,buyingAsset:t,amount:e,direct:r},c){return this.request("/quote",{sellingAsset:A,buyingAsset:t,amount:e,direction:c,direct:r})}async getDepth({market:A,depth:t}){return this.request("/depth",{market:A,depth:t})}async getCandles({market:A,from:t,to:e,resolution:r,order:c}){return this.request("/candles",{market:A,from:t,to:e,resolution:r,order:c})}async getTicker24h(){return this.request("/ticker/24h")}async getMarkets({cursor:A,limit:t}={}){return this.request("/markets",{cursor:A,limit:t})}async getOrders({owner:A,asset:t,cursor:e,limit:r}={}){return this.request("/order",{owner:A,asset:t,cursor:e,limit:r})}async getOrder(A){return this.request(`/order/${encodeURIComponent(A.toString())}`)}async getOrderHistory({owner:A,pair:t,cursor:e,limit:r}={}){return this.request("/order-history",{owner:A,pair:t,cursor:e,limit:r})}async getTrades({trader:A,pair:t,cursor:e,limit:r}={}){return this.request("/trades",{trader:A,pair:t,cursor:e,limit:r})}async request(A,t){let e=this.serverUrl+A;if(t){const A=new URLSearchParams;for(const[e,r]of Object.entries(t))if(null!=r)if(Array.isArray(r))for(const t of r)A.append(e,t);else A.append(e,r);const r=A.toString();r&&(e+="?"+r)}const r=await fetch(e);let c;try{c=await r.json()}catch(A){c=null}if(!r.ok)throw new a(c?.error||r.statusText,c?.status||r.status);return c}},AxisApiError:a};return c.default})());
|
|
2
2
|
//# sourceMappingURL=axis-client.cjs.map
|
package/lib/axis-client.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axis-client.cjs","mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,yBACA,mBAAAC,QAAAA,OAAAC,IACAD,OAAA,yBAAAJ,GACA,iBAAAC,QACAA,QAAA,WAAAD,EAAAG,QAAA,yBAEAJ,EAAA,WAAAC,EAAAD,EAAA,wBACC,CATD,CASCO,KAAAC,oCCTDL,EAAAD,QAAAM,ICCAC,EAAA,GAGA,SAAAC,EAAAC,GAEA,IAAAC,EAAAH,EAAAE,GACA,QAAAE,IAAAD,EACA,OAAAA,EAAAV,QAGA,IAAAC,EAAAM,EAAAE,GAAA,CAGAT,QAAA,IAOA,OAHAY,EAAAH,GAAAR,EAAAA,EAAAD,QAAAQ,GAGAP,EAAAD,OACA,CCrBAQ,EAAAK,EAAA,CAAAb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EAAKkI,QAEvBN,EAAOO,OAAOnI,EAAK8H,GAG3B,MAAMM,EAAKR,EAAON,WACdc,IACAT,GAAO,IAAMS,EACrB,CACA,MAAMC,QAAiBC,MAAMX,GAC7B,IAAIY,EACJ,IACIA,QAAaF,EAASG,MAC1B,CAAE,MAAOC,GAELF,EAAO,IACX,CACA,IAAKF,EAASK,GACV,MAAM,IAAIpG,EAAaiG,GAAMvG,OAASqG,EAASM,WAAYJ,GAAMhG,QAAU8F,EAAS9F,QACxF,OAAOgG,CACX,GEpL8FjG,aAAYA","sources":["webpack://axisClient/webpack/universalModuleDefinition","webpack://axisClient/external umd \"@stellar/stellar-sdk\"","webpack://axisClient/webpack/bootstrap","webpack://axisClient/webpack/runtime/define property getters","webpack://axisClient/webpack/runtime/hasOwnProperty shorthand","webpack://axisClient/./src/contract-client.js","webpack://axisClient/./src/errors.js","webpack://axisClient/./src/api-client.js","webpack://axisClient/./src/index.js","webpack://axisClient/./src/cjs.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@stellar/stellar-sdk\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@stellar/stellar-sdk\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"axisClient\"] = factory(require(\"@stellar/stellar-sdk\"));\n\telse\n\t\troot[\"axisClient\"] = factory(root[\"@stellar/stellar-sdk\"]);\n})(this, (__WEBPACK_EXTERNAL_MODULE__346__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__346__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import {contract} from '@stellar/stellar-sdk'\r\n\r\nexport default class ContractClient extends contract.Client {\r\n options\r\n\r\n constructor(options) {\r\n super(new contract.Spec([\r\n \"AAAAAAAAADJHZXQgbGF0IG9yZGVyIGlkCgojIFJldHVybnMKCkxhc3QgY3JlYXRlZCBvcmRlciBpZAAAAAAABGxhc3QAAAAAAAAAAQAAAAY=\",\r\n \"AAAAAAAAA4ZTd2FwIHRva2VucyBhY3Jvc3Mgc2V2ZXJhbCBtYXJrZXRzLgpUaGUgc3dhcCBleGVjdXRlcyB3aXRoaW4gdGhlIGJvdW5kYXJpZXMsIG90aGVyd2lzZSB0cmFkZSBnZXQgY2FuY2VsZWQ6CiogYFNlbGxgOiBleGFjdGx5IGBzZWxsaW5nX2Ftb3VudGAgc29sZCwgdGhlIHJlY2VpdmVkIGFtb3VudCBpcyBgPj0gYnV5aW5nX2Ftb3VudGAKKiBgQnV5YDogZXhhY3RseSBgYnV5aW5nX2Ftb3VudGAgcmVjZWl2ZWQsIHRoZSBzcGVudCBhbW91bnQgaXMgYDw9IHNlbGxpbmdfYW1vdW50YAoKCiMgQXJndW1lbnRzCiogYGRpcmVjdGlvbmAgLSBUcmFkZSBkaXJlY3Rpb246IGBTZWxsYCBvciBgQnV5YAoqIGB0cmFkZXJgIC0gVHJhZGVyIGFkZHJlc3MKKiBgc2VsbGluZ2AgLSBUb2tlbiBhZGRyZXNzIHNlbnQgYnkgdGhlIHRyYWRlcgo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AAAABMAAAABAAAADVRyYWRlIGRldGFpbHMAAAAAAAAFdHJhZGUAAAAAAAfQAAAABVRyYWRlAAAAAAAAAAAAAAA=\"\r\n ]), options)\r\n this.options = options\r\n }\r\n\r\n fromJSON = {\r\n last: this.txFromJSON,\r\n order: this.txFromJSON,\r\n cancel: this.txFromJSON,\r\n trade: this.txFromJSON,\r\n swap: this.txFromJSON,\r\n fill_order: this.txFromJSON\r\n }\r\n}","/**\r\n * Standard contract errors\r\n */\r\nexport const ContractErrors = {\r\n 701: {message: \"NotAuthorized\"},\r\n 702: {message: \"InsufficientBalance\"},\r\n 703: {message: \"OrderNotFound\"},\r\n 704: {message: \"Overflow\"},\r\n 705: {message: \"InvalidMatch\"},\r\n 706: {message: \"InvalidPrice\"}\r\n}\r\n/**\r\n * Handle simulation errors if any\r\n * @param {AssembledTransaction} tx\r\n * @internal\r\n */\r\nexport function processSimulationErrors(tx) {\r\n if (tx.simulation.error) {\r\n const contractErrorMatch = /HostError: Error\\(Contract, #(\\d+)\\)/.exec(tx.simulation.error)\r\n if (contractErrorMatch) {\r\n const code = contractErrorMatch[1]\r\n const err = ContractErrors[code]\r\n if (err) {\r\n throw new Error(`Contract execution error: #${code} ${err.message} `)\r\n }\r\n }\r\n throw tx.simulation.error\r\n }\r\n}","/**\n * Error thrown when the Aggregator API responds with a non-success HTTP status\n */\nexport class AxisApiError extends Error {\n /**\n * @param {string} message - Error message returned by the API\n * @param {number} status - HTTP status code\n */\n constructor(message, status) {\n super(message)\n this.name = 'AxisApiError'\n this.status = status\n }\n\n /**\n * HTTP status code associated with the error\n * @type {number}\n * @readonly\n */\n status\n}\n\n/**\n * HTTP client for the AXIS Aggregator REST API\n */\nexport class AxisApiClient {\n /**\n * @param {string} serverUrl - Base URL of the Aggregator server\n */\n constructor(serverUrl) {\n if (!serverUrl || typeof serverUrl !== 'string')\n throw new TypeError('Aggregator server URL is required')\n //trim trailing slashes to avoid double slashes when building request paths\n this.serverUrl = serverUrl.replace(/\\/+$/, '')\n }\n\n /**\n * Base URL of the Aggregator server\n * @type {string}\n * @readonly\n */\n serverUrl\n\n /**\n * Price quote and candidate trade routes for selling a fixed amount of the source asset\n * @param {QuoteParams} params - Quote request parameters\n * @return {Promise<QuoteResult>} - Best routes ranked by profitability\n * @throws {AxisApiError} - If the server is not ready or there is not enough liquidity\n */\n async quoteSell(params) {\n return this.quote(params, 'strict_send')\n }\n\n /**\n * Price quote and candidate trade routes for buying a fixed amount of the destination asset\n * @param {QuoteParams} params - Quote request parameters\n * @return {Promise<QuoteResult>} - Best routes ranked by profitability\n * @throws {AxisApiError} - If the server is not ready or there is not enough liquidity\n */\n async quoteBuy(params) {\n return this.quote(params, 'strict_receive')\n }\n\n /**\n * Find viable multi-hop paths between two assets, simulate trades on each path, and return the best routes\n * @param {QuoteParams} params - Quote request parameters\n * @param {'strict_send'|'strict_receive'} direction - Trade direction\n * @return {Promise<QuoteResult>}\n * @private\n */\n async quote({sellingAsset, buyingAsset, amount, direct}, direction) {\n return this.request('/quote', {sellingAsset, buyingAsset, amount, direction, direct})\n }\n\n /**\n * Order book depth aggregated into price buckets around the mid price\n * @param {DepthParams} params - Depth request parameters\n * @return {Promise<OrderbookDepth>} - Aggregated bids and asks\n */\n async getDepth({market, depth}) {\n return this.request('/depth', {market, depth})\n }\n\n /**\n * OHLCVT candlestick data (open, high, low, close, base volume, quote volume, trade count)\n * @param {CandlesParams} params - Candles request parameters\n * @return {Promise<Candle[]>} - Time-bucketed candles, max 200 per response\n */\n async getCandles({market, from, to, resolution, order}) {\n return this.request('/candles', {market, from, to, resolution, order})\n }\n\n /**\n * 24-hour ticker statistics for every available market\n * @return {Promise<Ticker24hResult>} - Aggregated 24h stats per market\n */\n async getTicker24h() {\n return this.request('/ticker/24h')\n }\n\n /**\n * List all active markets with pagination\n * @param {MarketsParams} [params] - Pagination parameters\n * @return {Promise<MarketInfo[]>} - Active markets\n */\n async getMarkets({cursor, limit} = {}) {\n return this.request('/markets', {cursor, limit})\n }\n\n /**\n * Retrieve active orders, filterable by owner or asset\n * @param {OrdersParams} [params] - Filter parameters\n * @return {Promise<ApiOrder[]>} - Active orders matching the filter\n */\n async getOrders({owner, asset, cursor, limit} = {}) {\n return this.request('/order', {owner, asset, cursor, limit})\n }\n\n /**\n * Retrieve a single order by ID\n * @param {bigint|string|number} id - Order ID\n * @return {Promise<ApiOrder|null>} - Order, or null if not found\n */\n async getOrder(id) {\n return this.request(`/order/${encodeURIComponent(id.toString())}`)\n }\n\n /**\n * Retrieve archived/historical orders\n * @param {OrderHistoryParams} [params] - Filter parameters\n * @return {Promise<ApiOrder[]>} - Archived orders matching the filter\n */\n async getOrderHistory({owner, pair, cursor, limit} = {}) {\n return this.request('/order-history', {owner, pair, cursor, limit})\n }\n\n /**\n * Retrieve recent trades\n * @param {TradesParams} [params] - Filter parameters\n * @return {Promise<ApiTrade[]>} - Recent trades matching the filter\n */\n async getTrades({trader, pair, cursor, limit} = {}) {\n return this.request('/trades', {trader, pair, cursor, limit})\n }\n\n /**\n * Execute a GET request against the Aggregator API\n * @param {string} path - Relative route path\n * @param {object} [query] - Query parameters (undefined/null values skipped, arrays expanded to repeated params)\n * @return {Promise<*>} - Parsed JSON response\n * @throws {AxisApiError} - If the API responds with a non-success status\n * @private\n */\n async request(path, query) {\n let url = this.serverUrl + path\n if (query) {\n const search = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null)\n continue\n if (Array.isArray(value)) {\n for (const item of value)\n search.append(key, item)\n } else {\n search.append(key, value)\n }\n }\n const qs = search.toString()\n if (qs)\n url += '?' + qs\n }\n const response = await fetch(url)\n let body\n try {\n body = await response.json()\n } catch (e) {\n //non-JSON response (e.g. proxy/gateway error) - fall back to status text\n body = null\n }\n if (!response.ok)\n throw new AxisApiError(body?.error || response.statusText, body?.status || response.status)\n return body\n }\n}\n\n/**\n * @typedef {{}} QuoteParams\n * @property {string} sellingAsset - Asset to sell (`XLM` | `CODE:Issuer` | `CODE-Issuer` | contractId)\n * @property {string} buyingAsset - Asset to buy (same format as `sellingAsset`)\n * @property {string|number} amount - Trade amount in stroops (1 unit = 10,000,000 stroops)\n * @property {boolean} [direct] - Restrict to the direct market only (no intermediate-asset routes)\n */\n\n/**\n * @typedef {{}} QuoteResult\n * @property {string} id - Base58-encoded quote id\n * @property {'success'|'unfeasible'|'rejected'} status - Quote status\n * @property {'strict_send'|'strict_receive'} direction - Trade direction\n * @property {string} sellingAsset - Selling asset contract id\n * @property {string} buyingAsset - Buying asset contract id\n * @property {number} ledger - Ledger sequence the quote was computed for\n * @property {QuotePath[]} paths - Candidate routes ranked by profitability (up to 10)\n * @property {string} [error] - Error message (present only if status is not `success`)\n */\n\n/**\n * @typedef {{}} QuotePath\n * @property {string} sold - Amount sold, in stroops\n * @property {string} bought - Amount bought, in stroops\n * @property {QuotePathStep[]} path - Ordered list of hops in the route\n */\n\n/**\n * @typedef {{}} QuotePathStep\n * @property {string} selling - Selling asset contract id at this hop\n * @property {string} buying - Buying asset contract id at this hop\n * @property {string[]} orders - Maker order IDs matched at this hop\n */\n\n/**\n * @typedef {{}} DepthParams\n * @property {string} market - Market identifier `BASE/QUOTE`\n * @property {number} [depth] - Percentage band (±) around the center price (0 < depth ≤ 100, default 20)\n */\n\n/**\n * @typedef {{}} OrderbookDepth\n * @property {number} ledger - Ledger sequence\n * @property {number} timestamp - UNIX timestamp (seconds)\n * @property {Array<[string, string]>} bids - `[price, quantity]` pairs sorted descending by price\n * @property {Array<[string, string]>} asks - `[price, quantity]` pairs sorted ascending by price\n */\n\n/**\n * @typedef {{}} CandlesParams\n * @property {string} market - Market identifier `BASE/QUOTE`\n * @property {number} [from] - Lower boundary (UNIX seconds, default 0)\n * @property {number} [to] - Upper boundary (UNIX seconds, defaults to `from + resolution * 200`)\n * @property {number|string} [resolution] - Resolution in seconds or alias (`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`12h`,`1d`,`3d`,`1w`,`2w`, default `auto`)\n * @property {'asc'|'desc'} [order] - Sort order (default `desc`)\n */\n\n/**\n * OHLCVT candle row: `[timestamp, open, high, low, close, baseVolume, quoteVolume, tradeCount]`\n * @typedef {[number, string, string, string, string, string, string, number]} Candle\n */\n\n/**\n * @typedef {{}} Ticker24hResult\n * @property {number} ledger - Ledger sequence\n * @property {number} timestamp - UNIX timestamp (seconds)\n * @property {TickerEntry[]} ticker - Per-market 24h stats, sorted by trade count descending\n */\n\n/**\n * @typedef {{}} TickerEntry\n * @property {string} symbol - Market symbol `BASE/QUOTE`\n * @property {string} openPrice - Opening price 24h ago\n * @property {string} highPrice - Highest price in the 24h window\n * @property {string} lowPrice - Lowest price in the 24h window\n * @property {string} lastPrice - Most recent trade price\n * @property {string} volume - 24h base asset volume\n * @property {string} quoteVolume - 24h quote asset volume\n * @property {number} change - 24h price change (percent)\n * @property {string} avgPrice - Volume-weighted average price\n * @property {number} trades - 24h trade count\n */\n\n/**\n * @typedef {{}} MarketsParams\n * @property {string} [cursor] - Pagination cursor (`baseAsset-quoteAsset`)\n * @property {number|string} [limit] - Max markets to return\n */\n\n/**\n * @typedef {{}} MarketInfo\n * @property {string} baseAsset - Base asset contract id\n * @property {string} quoteAsset - Quote asset contract id\n * @property {string} cursor - Pagination cursor for this market\n * @property {string[]} orderTypes - Supported order types\n */\n\n/**\n * @typedef {{}} OrdersParams\n * @property {string} [owner] - Filter by order owner address\n * @property {string|string[]} [asset] - Filter by asset(s) - matches orders selling or buying any of them\n * @property {string|bigint} [cursor] - Pagination cursor (order id)\n * @property {number|string} [limit] - Max orders to return\n */\n\n/**\n * @typedef {{}} OrderHistoryParams\n * @property {string} [owner] - Filter by order owner address\n * @property {string[]} [pair] - Asset pair `[base, quote]` (contract ids)\n * @property {string|bigint} [cursor] - Pagination cursor (order id)\n * @property {number|string} [limit] - Max orders to return\n */\n\n/**\n * @typedef {{}} TradesParams\n * @property {string} [trader] - Filter by trader address\n * @property {string[]} [pair] - Asset pair `[base, quote]` (contract ids)\n * @property {string|bigint} [cursor] - Pagination cursor (trade id)\n * @property {number|string} [limit] - Max trades to return\n */\n\n/**\n * @typedef {{}} ApiOrder - Serialized order returned by the API\n * @property {string} id - Order ID\n * @property {string} status - Order status (`ACTIVE`|`FILLED`|`CANCELED`)\n * @property {string} kind - Order kind (`LIMIT`)\n * @property {string} buying - Buying asset contract id\n * @property {string} selling - Selling asset contract id\n * @property {string} price - Order price\n * @property {string} rprice - Rational price representation\n * @property {string} quote - Total quote amount\n * @property {string} amount - Amount left to sell/buy\n * @property {string} owner - Maker address\n * @property {string} [expires] - Expiration timestamp (UTC)\n * @property {string} [iceberg] - Iceberg amount\n * @property {string} [stop] - Stop price\n * @property {string} [created] - Creation timestamp (UTC)\n * @property {string} [updated] - Last update timestamp (UTC)\n * @property {string} [cursor] - Pagination cursor\n */\n\n/**\n * @typedef {{}} ApiTrade - Serialized trade returned by the API\n * @property {string} id - Trade ID\n * @property {string} order - Matched order ID\n * @property {string} taker - Taker account address\n * @property {string} maker - Maker account address\n * @property {string} soldAsset - Sold asset contract id\n * @property {string} boughtAsset - Bought asset contract id\n * @property {string} sold - Sold tokens amount\n * @property {string} bought - Bought tokens amount\n * @property {string} price - Approximate trade price\n * @property {string} [cursor] - Pagination cursor\n * @property {string} timestamp - Trade timestamp (UTC)\n */\n","import {Networks} from '@stellar/stellar-sdk'\r\nimport ContractClient from './contract-client.js'\r\nimport {ContractErrors, processSimulationErrors} from './errors.js'\r\nimport {AxisApiClient, AxisApiError} from './api-client.js'\r\n\r\nexport {ContractErrors, AxisApiClient, AxisApiError}\r\n\r\n/** Trading order type - instructions to contract how to execute the trade */\r\nexport const OrderKind = {\r\n /** Execute trade, create a limit order if not executed in full */\r\n Limit: 1,\r\n /** Execute trade without creating a limit order */\r\n Fill: 2,\r\n /** Execute trade, cancel if was not executed in full */\r\n FillOrKill: 3\r\n}\r\n\r\n/** Trade direction instructions */\r\nexport const TradeDirection = {\r\n Sell: 1,\r\n Buy: 2\r\n}\r\n\r\n/**\r\n * Smart contract client for trading with AXIS DEX\r\n */\r\nexport class AxisContractClient {\r\n /**\r\n * @param {ClientInitializationParams} params\r\n */\r\n constructor(params) {\r\n const options = {\r\n publicKey: params.publicKey,\r\n signTransaction: params.signTransaction,\r\n rpcUrl: params.rpcUrl,\r\n allowHttp: true,\r\n networkPassphrase: params.networkPassphrase || Networks.PUBLIC,\r\n contractId: params.contractId\r\n }\r\n this.client = new ContractClient(options)\r\n this.fee = params.fee || '100000'\r\n }\r\n\r\n /**\r\n * Retrieve last order id\r\n * @return {Promise<bigint>} - Last created order id\r\n */\r\n async last() {\r\n const tx = await this.client.last()\r\n processSimulationErrors(tx)\r\n return tx.result\r\n }\r\n\r\n /**\r\n * @param {bigint} id - ID of the order to fetch\r\n * @return {Promise<Order>} - Order fetched from the storage\r\n */\r\n async order(id) {\r\n const tx = await this.client.order({id})\r\n processSimulationErrors(tx)\r\n return tx.result\r\n }\r\n\r\n /**\r\n * Cancel existing order\r\n * @param {bigint[]} ids - ID of the order to cancel\r\n * @param {string} trader - Trader address\r\n * @return {Promise<void>}\r\n * @throws {Error} - If trader is not the owner of the order\r\n */\r\n async cancel(ids, trader) {\r\n const tx = await this.client.cancel({ids, trader}, {fee: this.fee})\r\n processSimulationErrors(tx)\r\n await tx.signAndSend()\r\n }\r\n\r\n /**\r\n * Fill existing orders using another matching order from the orderbook\r\n * @param {string} trader - Trader address\r\n * @param {bigint} takerOrderId - ID of the order that serves as a taker\r\n * @param {bigint[]} orders - List of order IDs to match before creating the order on chain\r\n * @return {Promise<[bigint, bigint]>} - Amount of sold and bought tokens\r\n * @throws {Error} - If the taker order was not found\r\n * @throws {Error} - If any of the orders provided do not match selling/buying asset\r\n * @throws {Error} - If the trade causes an overflow\r\n */\r\n async fill_order(trader, takerOrderId, orders) {\r\n const tx = await this.client.fill_order({trader, taker_order_id: takerOrderId, orders}, {fee: this.fee})\r\n processSimulationErrors(tx)\r\n const res = await tx.signAndSend()\r\n return [res.result.sold, res.result.bought]\r\n }\r\n\r\n /**\r\n * Trade with DEX and create buy limit order if quote not executed in full\r\n * @param {BuyTradeArguments} params\r\n * @return {Promise<[bigint, bigint, bigint]>} - Amount of sold and bought tokens, ID of the newly created order if any\r\n * @throws {Error} - If the trader has insufficient balance\r\n * @throws {Error} - If any of the orders provided do not match selling/buying asset\r\n * @throws {Error} - If the trade causes an overflow\r\n */\r\n async buy(params) {\r\n return await execTrade(params, TradeDirection.Buy, this)\r\n }\r\n\r\n /**\r\n * Trade with DEX and create sell limit order if quote not executed in full\r\n * @param {SellTradeArguments} params\r\n * @return {Promise<[bigint, bigint, bigint]>} - Amount of sold and bought tokens, ID of the newly created order if any\r\n * @throws {Error} - If the trader has insufficient balance\r\n * @throws {Error} - If any of the orders provided do not match selling/buying asset\r\n * @throws {Error} - If the trade causes an overflow\r\n */\r\n async sell(params) {\r\n return await execTrade(params, TradeDirection.Sell, this)\r\n }\r\n\r\n async swap(params) {\r\n const tx = await this.client.swap({\r\n direction: params.direction,\r\n trader: params.trader,\r\n selling: params.selling,\r\n selling_amount: params.sellingAmount,\r\n buying_amount: params.buyingAmount,\r\n path: params.path.map(step => ({asset: step.asset, orders: step.orders}))\r\n }, {fee: this.fee})\r\n processSimulationErrors(tx)\r\n const res = await tx.signAndSend()\r\n return [res.result.sold, res.result.bought]\r\n }\r\n}\r\n\r\nasync function execTrade(params, direction, context) {\r\n const payload = {\r\n direction: direction,\r\n kind: params.kind,\r\n trader: params.trader,\r\n amount: params.amount,\r\n selling: params.selling,\r\n buying: params.buying,\r\n price: params.price,\r\n orders: params.orders\r\n }\r\n const tx = await context.client.trade(payload, {fee: context.fee})\r\n processSimulationErrors(tx)\r\n const {result} = await tx.signAndSend()\r\n return [result[0], result[1], result[2]]\r\n}\r\n\r\n/**\r\n * @typedef {{}} ClientInitializationParams\r\n * @property {string} publicKey - Public key of the account that will interact with the contract\r\n * @property {SignTransactionCallback} signTransaction - Callback for signing transactions generated by the client\r\n * @property {string} rpcUrl - URL of the RPC server\r\n * @property {string} contractId - DEX contract ID\r\n * @property {string} [networkPassphrase] - Network passphrase (Pubnet passphrase by default)\r\n * @property {string} [fee] - Transaction fee (0.1 XLM by default)\r\n */\r\n\r\n/**\r\n * @callback SignTransactionCallback - Callback for signing transactions generated by the client\r\n * @param {string} tx - Transaction XDR to sign\r\n * @param {{network: string, networkPassphrase: string, accountToSign: string}} context - Signing context\r\n * @return {Promise<{signedTxXdr: string, [signerAddress]: string}>} - Signed transaction response\r\n */\r\n\r\n/**\r\n * @typedef {{}} TradeArguments\r\n * @property {OrderKind} kind - Trading order behavior\r\n * @property {string} trader - Trader address\r\n * @property {bigint} amount - Tokens amount\r\n * @property {string} selling - Selling token address\r\n * @property {string} buying - Buying token address\r\n * @property {bigint} price - Price a trader willing to accept\r\n * @property {Array<bigint>} orders - List of order IDs to match before creating the order on-chain\r\n */\r\n\r\n/**\r\n * @typedef {{}} SellTradeArguments\r\n * @extends TradeArguments\r\n * @property {bigint} amount - Amount of `selling` tokens to sell\r\n * @property {bigint} price - Price a trader willing to accept, minimum `buying` tokens per 1 `selling`\r\n */\r\n\r\n/**\r\n * @typedef {{}} BuyTradeArguments\r\n * @extends TradeArguments\r\n * @property {bigint} amount - Amount of `buying` tokens to acquire\r\n * @property {bigint} price - Price a trader willing to accept, maximum `selling` tokens per 1 `buying`\r\n */\r\n\r\n/**\r\n * @typedef {{}} TradeStep - A trade step in a multi-market swap path\r\n * @property {string} asset - Asset to buy at this step\r\n * @property {Array<bigint>} orders - Maker order IDs to match\r\n */\r\n\r\n/**\r\n * @typedef {{}} SwapArguments\r\n * @property {TradeDirection} direction - Trade direction: `Sell` or `Buy`\r\n * @property {string} trader - Trader address\r\n * @property {string} selling - Token address sent by the trader\r\n * @property {bigint} selling_amount - Maximum amount of selling tokens to send\r\n * @property {bigint} buying_amount - Minimum amount of buying tokens to receive\r\n * @property {Array<TradeStep>} path - Ordered list of the trade route steps\r\n */\r\n\r\n/**\r\n * @typedef {{}} MethodOptions\r\n * @property {string} [fee] - Transaction fee (0.1 XLM by default)\r\n */\r\n\r\n/**\r\n * @typedef {{}} Order - Order properties, stored on-chain\r\n * @property {bigint} id - Order ID\r\n * @property {OrderKind} kind - Trading behavior\r\n * @property {string} owner - Owner of the order\r\n * @property {string} selling - Selling token address\r\n * @property {string} buying - Buying token address\r\n * @property {bigint} amount - Amount of tokens to sell\r\n * @property {bigint} price - Price of the order\r\n * @property {bigint} quote - Total amount of tokens to buy\r\n * @property {bigint} expires - Expiration time of the order\r\n */\r\n\r\n/**\r\n* @typedef {object} TradeContractEvent - Orderbook trade event\r\n* @property {bigint} bought - Bought tokens amount\r\n* @property {string} buying - Bought asset address\r\n* @property {bigint} id - Unique trade id\r\n* @property {string} maker - Seller account address\r\n* @property {bigint} order - Order id\r\n* @property {string} selling - Sold asset address\r\n* @property {bigint} sold - Sold tokens amount\r\n* @property {string} taker - Trader account address\r\n*/\r\n\r\n/**\r\n * @typedef {object} SwapContractEvent - Orderbook swap event\r\n * @property {bigint} id - Unique swap id (last trade id assigned while settling the swap legs)\r\n * @property {string} trader - Trader account address\r\n * @property {string} selling - Sold asset address\r\n * @property {string} buying - Bought asset address\r\n * @property {bigint} sold - Amount of `selling` tokens sold\r\n * @property {bigint} bought - Amount of `buying` tokens received\r\n */","import {AxisContractClient, ContractErrors, TradeDirection, OrderKind, AxisApiClient, AxisApiError} from './index.js'\r\n\r\nconst axisClient = {AxisContractClient, ContractErrors, TradeDirection, OrderKind, AxisApiClient, AxisApiError}\r\n\r\nexport default axisClient"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__346__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","ContractClient","stellar_sdk_","contract","Client","options","constructor","super","Spec","fromJSON","last","txFromJSON","order","cancel","trade","swap","fill_order","ContractErrors","message","processSimulationErrors","tx","simulation","error","contractErrorMatch","exec","code","err","Error","AxisApiError","status","name","TradeDirection","Sell","Buy","async","execTrade","params","direction","context","payload","kind","trader","amount","selling","buying","price","orders","client","fee","result","signAndSend","cjs","AxisContractClient","publicKey","signTransaction","rpcUrl","allowHttp","networkPassphrase","Networks","PUBLIC","contractId","id","ids","takerOrderId","taker_order_id","res","sold","bought","buy","sell","selling_amount","sellingAmount","buying_amount","buyingAmount","path","map","step","asset","OrderKind","Limit","Fill","FillOrKill","AxisApiClient","serverUrl","TypeError","replace","quoteSell","quote","quoteBuy","sellingAsset","buyingAsset","direct","request","getDepth","market","depth","getCandles","from","to","resolution","getTicker24h","getMarkets","cursor","limit","getOrders","owner","getOrder","encodeURIComponent","toString","getOrderHistory","pair","getTrades","query","url","search","URLSearchParams","value","entries","Array","isArray","item","append","qs","response","fetch","body","json","e","ok","statusText"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"axis-client.cjs","mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,yBACA,mBAAAC,QAAAA,OAAAC,IACAD,OAAA,yBAAAJ,GACA,iBAAAC,QACAA,QAAA,WAAAD,EAAAG,QAAA,yBAEAJ,EAAA,WAAAC,EAAAD,EAAA,wBACC,CATD,CASCO,KAAAC,oCCTDL,EAAAD,QAAAM,ICCAC,EAAA,GAGA,SAAAC,EAAAC,GAEA,IAAAC,EAAAH,EAAAE,GACA,QAAAE,IAAAD,EACA,OAAAA,EAAAV,QAGA,IAAAC,EAAAM,EAAAE,GAAA,CAGAT,QAAA,IAOA,OAHAY,EAAAH,GAAAR,EAAAA,EAAAD,QAAAQ,GAGAP,EAAAD,OACA,CCrBAQ,EAAAK,EAAA,CAAAb,EAAAc,KACA,QAAAC,KAAAD,EACAN,EAAAQ,EAAAF,EAAAC,KAAAP,EAAAQ,EAAAhB,EAAAe,IACAE,OAAAC,eAAAlB,EAAAe,EAAA,CAAyCI,YAAA,EAAAC,IAAAN,EAAAC,MCJzCP,EAAAQ,EAAA,CAAAK,EA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universalModuleDefinition","webpack://@axis-markets/client/external umd \"@stellar/stellar-sdk\"","webpack://@axis-markets/client/webpack/bootstrap","webpack://@axis-markets/client/webpack/runtime/define property getters","webpack://@axis-markets/client/webpack/runtime/hasOwnProperty shorthand","webpack://@axis-markets/client/./src/contract-client.js","webpack://@axis-markets/client/./src/errors.js","webpack://@axis-markets/client/./src/api-client.js","webpack://@axis-markets/client/./src/footprint.js","webpack://@axis-markets/client/./src/index.js","webpack://@axis-markets/client/./src/cjs.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@stellar/stellar-sdk\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@stellar/stellar-sdk\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"axisClient\"] = factory(require(\"@stellar/stellar-sdk\"));\n\telse\n\t\troot[\"axisClient\"] = factory(root[\"@stellar/stellar-sdk\"]);\n})(this, (__WEBPACK_EXTERNAL_MODULE__346__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__346__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import {contract} from '@stellar/stellar-sdk'\r\n\r\nexport default class ContractClient extends contract.Client {\r\n options\r\n\r\n constructor(options) {\r\n super(new contract.Spec([\r\n \"AAAAAAAAADJHZXQgbGF0IG9yZGVyIGlkCgojIFJldHVybnMKCkxhc3QgY3JlYXRlZCBvcmRlciBpZAAAAAAABGxhc3QAAAAAAAAAAQAAAAY=\",\r\n \"AAAAAAAAA4ZTd2FwIHRva2VucyBhY3Jvc3Mgc2V2ZXJhbCBtYXJrZXRzLgpUaGUgc3dhcCBleGVjdXRlcyB3aXRoaW4gdGhlIGJvdW5kYXJpZXMsIG90aGVyd2lzZSB0cmFkZSBnZXQgY2FuY2VsZWQ6CiogYFNlbGxgOiBleGFjdGx5IGBzZWxsaW5nX2Ftb3VudGAgc29sZCwgdGhlIHJlY2VpdmVkIGFtb3VudCBpcyBgPj0gYnV5aW5nX2Ftb3VudGAKKiBgQnV5YDogZXhhY3RseSBgYnV5aW5nX2Ftb3VudGAgcmVjZWl2ZWQsIHRoZSBzcGVudCBhbW91bnQgaXMgYDw9IHNlbGxpbmdfYW1vdW50YAoKCiMgQXJndW1lbnRzCiogYGRpcmVjdGlvbmAgLSBUcmFkZSBkaXJlY3Rpb246IGBTZWxsYCBvciBgQnV5YAoqIGB0cmFkZXJgIC0gVHJhZGVyIGFkZHJlc3MKKiBgc2VsbGluZ2AgLSBUb2tlbiBhZGRyZXNzIHNlbnQgYnkgdGhlIHRyYWRlcgoqIGBzZWxsaW5nX2Ftb3VudGAgLSBNYXhpbXVtIGFtb3VudCBvZiBzZWxsaW5nIHRva2VucyB0byBzZW5kCiogYGJ1eWluZ19hbW91bnRgIC0gTWluaW11bSBhbW91bnQgb2YgYnV5aW5nIHRva2VucyB0byByZWNlaXZlCiogYHBhdGhgIC0gT3JkZXJlZCBsaXN0IG9mIHRoZSB0cmFkZSByb3V0ZSBzdGVwcwoKIyBSZXR1cm5zCgoqIEFtb3VudC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AAAACVN3YXBFdmVudAAAAAAAAAIAAAAEQVhJUwAAAARzd2FwAAAAAwAAABhBc3NldCBzb2xkIGJ5IHRoZSB0cmFkZXIAAAAHc2VsbGluZwAAAAATAAAAAQAAABxBc3NldCByZWNlaXZlZCBieSB0aGUgdHJhZGVyAAAABmJ1eWluZwAAAAAAEwAAAAEAAAAMU3dhcCBkZXRhaWxzAAAABHN3YXAAAAfQAAAABFN3YXAAAAAAAAAAAA==\",\r\n \"AAAABQAAAAAAAAAAAAAACk9yZGVyRXZlbnQAAAAAAAIAAAAEQVhJUwAAAAVvcmRlcgAAAAAAAAQAAAAwT3JkZXIgY2hhbmdlIHR5cGU6ICJjcmVhdGVkInwidXBkYXRlZCJ8InJlbW92ZWQiAAAABmFjdGlvbgAAAAAAEQAAAAEAAAAVU2VsbGluZyBhc3NldCBhZGRyZXNzAAAAAAAAB3NlbGxpbmcAAAAAEwAAAAEAAAAUQnV5aW5nIGFzc2V0IGFkZHJlc3MAAAAGYnV5aW5nAAAAAAATAAAAAQAAAA1PcmRlciBkZXRhaWxzAAAAAAAABW9yZGVyAAAAAAAH0AAAAAVPcmRlcgAAAAAAAAAAAAAA\",\r\n \"AAAABQAAAAAAAAAAAAAAClRyYWRlRXZlbnQAAAAAAAIAAAAEQVhJUwAAAAV0cmFkZQAAAAAAAAMAAAASU29sZCBhc3NldCBhZGRyZXNzAAAAAAAHc2VsbGluZwAAAAATAAAAAQAAABRCb3VnaHQgYXNzZXQgYWRkcmVzcwAAAAZidXlpbmcAAAAAABMAAAABAAAADVRyYWRlIGRldGFpbHMAAAAAAAAFdHJhZGUAAAAAAAfQAAAABVRyYWRlAAAAAAAAAAAAAAA=\"\r\n ]), options)\r\n this.options = options\r\n }\r\n\r\n fromJSON = {\r\n last: this.txFromJSON,\r\n order: this.txFromJSON,\r\n cancel: this.txFromJSON,\r\n trade: this.txFromJSON,\r\n swap: this.txFromJSON,\r\n fill_order: this.txFromJSON\r\n }\r\n}","/**\r\n * Standard contract errors\r\n */\r\nexport const ContractErrors = {\r\n 701: {message: \"NotAuthorized\"},\r\n 702: {message: \"InsufficientBalance\"},\r\n 703: {message: \"OrderNotFound\"},\r\n 704: {message: \"Overflow\"},\r\n 705: {message: \"InvalidMatch\"},\r\n 706: {message: \"InvalidPrice\"}\r\n}\r\n/**\r\n * Handle simulation errors if any\r\n * @param {AssembledTransaction} tx\r\n * @internal\r\n */\r\nexport function processSimulationErrors(tx) {\r\n if (tx.simulation.error) {\r\n const contractErrorMatch = /HostError: Error\\(Contract, #(\\d+)\\)/.exec(tx.simulation.error)\r\n if (contractErrorMatch) {\r\n const code = contractErrorMatch[1]\r\n const err = ContractErrors[code]\r\n if (err) {\r\n throw new Error(`Contract execution error: #${code} ${err.message} `)\r\n }\r\n }\r\n throw tx.simulation.error\r\n }\r\n}","/**\n * Error thrown when the Aggregator API responds with a non-success HTTP status\n */\nexport class AxisApiError extends Error {\n /**\n * @param {string} message - Error message returned by the API\n * @param {number} status - HTTP status code\n */\n constructor(message, status) {\n super(message)\n this.name = 'AxisApiError'\n this.status = status\n }\n\n /**\n * HTTP status code associated with the error\n * @type {number}\n * @readonly\n */\n status\n}\n\n/**\n * HTTP client for the AXIS Aggregator REST API\n */\nexport class AxisApiClient {\n /**\n * @param {string} serverUrl - Base URL of the Aggregator server\n */\n constructor(serverUrl) {\n if (!serverUrl || typeof serverUrl !== 'string')\n throw new TypeError('Aggregator server URL is required')\n //trim trailing slashes to avoid double slashes when building request paths\n this.serverUrl = serverUrl.replace(/\\/+$/, '')\n }\n\n /**\n * Base URL of the Aggregator server\n * @type {string}\n * @readonly\n */\n serverUrl\n\n /**\n * Price quote and candidate trade routes for selling a fixed amount of the source asset\n * @param {QuoteParams} params - Quote request parameters\n * @return {Promise<QuoteResult>} - Best routes ranked by profitability\n * @throws {AxisApiError} - If the server is not ready or there is not enough liquidity\n */\n async quoteSell(params) {\n return this.quote(params, 'strict_send')\n }\n\n /**\n * Price quote and candidate trade routes for buying a fixed amount of the destination asset\n * @param {QuoteParams} params - Quote request parameters\n * @return {Promise<QuoteResult>} - Best routes ranked by profitability\n * @throws {AxisApiError} - If the server is not ready or there is not enough liquidity\n */\n async quoteBuy(params) {\n return this.quote(params, 'strict_receive')\n }\n\n /**\n * Find viable multi-hop paths between two assets, simulate trades on each path, and return the best routes\n * @param {QuoteParams} params - Quote request parameters\n * @param {'strict_send'|'strict_receive'} direction - Trade direction\n * @return {Promise<QuoteResult>}\n * @private\n */\n async quote({sellingAsset, buyingAsset, amount, direct}, direction) {\n return this.request('/quote', {sellingAsset, buyingAsset, amount, direction, direct})\n }\n\n /**\n * Order book depth aggregated into price buckets around the mid price\n * @param {DepthParams} params - Depth request parameters\n * @return {Promise<OrderbookDepth>} - Aggregated bids and asks\n */\n async getDepth({market, depth}) {\n return this.request('/depth', {market, depth})\n }\n\n /**\n * OHLCVT candlestick data (open, high, low, close, base volume, quote volume, trade count)\n * @param {CandlesParams} params - Candles request parameters\n * @return {Promise<Candle[]>} - Time-bucketed candles, max 200 per response\n */\n async getCandles({market, from, to, resolution, order}) {\n return this.request('/candles', {market, from, to, resolution, order})\n }\n\n /**\n * 24-hour ticker statistics for every available market\n * @return {Promise<Ticker24hResult>} - Aggregated 24h stats per market\n */\n async getTicker24h() {\n return this.request('/ticker/24h')\n }\n\n /**\n * List all active markets with pagination\n * @param {MarketsParams} [params] - Pagination parameters\n * @return {Promise<MarketInfo[]>} - Active markets\n */\n async getMarkets({cursor, limit} = {}) {\n return this.request('/markets', {cursor, limit})\n }\n\n /**\n * Retrieve active orders, filterable by owner or asset\n * @param {OrdersParams} [params] - Filter parameters\n * @return {Promise<ApiOrder[]>} - Active orders matching the filter\n */\n async getOrders({owner, asset, cursor, limit} = {}) {\n return this.request('/order', {owner, asset, cursor, limit})\n }\n\n /**\n * Retrieve a single order by ID\n * @param {bigint|string|number} id - Order ID\n * @return {Promise<ApiOrder|null>} - Order, or null if not found\n */\n async getOrder(id) {\n return this.request(`/order/${encodeURIComponent(id.toString())}`)\n }\n\n /**\n * Retrieve archived/historical orders\n * @param {OrderHistoryParams} [params] - Filter parameters\n * @return {Promise<ApiOrder[]>} - Archived orders matching the filter\n */\n async getOrderHistory({owner, pair, cursor, limit} = {}) {\n return this.request('/order-history', {owner, pair, cursor, limit})\n }\n\n /**\n * Retrieve recent trades\n * @param {TradesParams} [params] - Filter parameters\n * @return {Promise<ApiTrade[]>} - Recent trades matching the filter\n */\n async getTrades({trader, pair, cursor, limit} = {}) {\n return this.request('/trades', {trader, pair, cursor, limit})\n }\n\n /**\n * Execute a GET request against the Aggregator API\n * @param {string} path - Relative route path\n * @param {object} [query] - Query parameters (undefined/null values skipped, arrays expanded to repeated params)\n * @return {Promise<*>} - Parsed JSON response\n * @throws {AxisApiError} - If the API responds with a non-success status\n * @private\n */\n async request(path, query) {\n let url = this.serverUrl + path\n if (query) {\n const search = new URLSearchParams()\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined || value === null)\n continue\n if (Array.isArray(value)) {\n for (const item of value)\n search.append(key, item)\n } else {\n search.append(key, value)\n }\n }\n const qs = search.toString()\n if (qs)\n url += '?' + qs\n }\n const response = await fetch(url)\n let body\n try {\n body = await response.json()\n } catch (e) {\n //non-JSON response (e.g. proxy/gateway error) - fall back to status text\n body = null\n }\n if (!response.ok)\n throw new AxisApiError(body?.error || response.statusText, body?.status || response.status)\n return body\n }\n}\n\n/**\n * @typedef {{}} QuoteParams\n * @property {string} sellingAsset - Asset to sell (`XLM` | `CODE:Issuer` | `CODE-Issuer` | contractId)\n * @property {string} buyingAsset - Asset to buy (same format as `sellingAsset`)\n * @property {string|number} amount - Trade amount in stroops (1 unit = 10,000,000 stroops)\n * @property {boolean} [direct] - Restrict to the direct market only (no intermediate-asset routes)\n */\n\n/**\n * @typedef {{}} QuoteResult\n * @property {string} id - Base58-encoded quote id\n * @property {'success'|'unfeasible'|'rejected'} status - Quote status\n * @property {'strict_send'|'strict_receive'} direction - Trade direction\n * @property {string} sellingAsset - Selling asset contract id\n * @property {string} buyingAsset - Buying asset contract id\n * @property {number} ledger - Ledger sequence the quote was computed for\n * @property {QuotePath[]} paths - Candidate routes ranked by profitability (up to 10)\n * @property {string} [error] - Error message (present only if status is not `success`)\n */\n\n/**\n * @typedef {{}} QuotePath\n * @property {string} sold - Amount sold, in stroops\n * @property {string} bought - Amount bought, in stroops\n * @property {QuotePathStep[]} path - Ordered list of hops in the route\n */\n\n/**\n * @typedef {{}} QuotePathStep\n * @property {string} selling - Selling asset contract id at this hop\n * @property {string} buying - Buying asset contract id at this hop\n * @property {string[]} orders - Maker order IDs matched at this hop\n */\n\n/**\n * @typedef {{}} DepthParams\n * @property {string} market - Market identifier `BASE/QUOTE`\n * @property {number} [depth] - Percentage band (±) around the center price (0 < depth ≤ 100, default 20)\n */\n\n/**\n * @typedef {{}} OrderbookDepth\n * @property {number} ledger - Ledger sequence\n * @property {number} timestamp - UNIX timestamp (seconds)\n * @property {Array<[string, string]>} bids - `[price, quantity]` pairs sorted descending by price\n * @property {Array<[string, string]>} asks - `[price, quantity]` pairs sorted ascending by price\n */\n\n/**\n * @typedef {{}} CandlesParams\n * @property {string} market - Market identifier `BASE/QUOTE`\n * @property {number} [from] - Lower boundary (UNIX seconds, default 0)\n * @property {number} [to] - Upper boundary (UNIX seconds, defaults to `from + resolution * 200`)\n * @property {number|string} [resolution] - Resolution in seconds or alias (`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`12h`,`1d`,`3d`,`1w`,`2w`, default `auto`)\n * @property {'asc'|'desc'} [order] - Sort order (default `desc`)\n */\n\n/**\n * OHLCVT candle row: `[timestamp, open, high, low, close, baseVolume, quoteVolume, tradeCount]`\n * @typedef {[number, string, string, string, string, string, string, number]} Candle\n */\n\n/**\n * @typedef {{}} Ticker24hResult\n * @property {number} ledger - Ledger sequence\n * @property {number} timestamp - UNIX timestamp (seconds)\n * @property {TickerEntry[]} ticker - Per-market 24h stats, sorted by trade count descending\n */\n\n/**\n * @typedef {{}} TickerEntry\n * @property {string} symbol - Market symbol `BASE/QUOTE`\n * @property {string} openPrice - Opening price 24h ago\n * @property {string} highPrice - Highest price in the 24h window\n * @property {string} lowPrice - Lowest price in the 24h window\n * @property {string} lastPrice - Most recent trade price\n * @property {string} volume - 24h base asset volume\n * @property {string} quoteVolume - 24h quote asset volume\n * @property {number} change - 24h price change (percent)\n * @property {string} avgPrice - Volume-weighted average price\n * @property {number} trades - 24h trade count\n */\n\n/**\n * @typedef {{}} MarketsParams\n * @property {string} [cursor] - Pagination cursor (`baseAsset-quoteAsset`)\n * @property {number|string} [limit] - Max markets to return\n */\n\n/**\n * @typedef {{}} MarketInfo\n * @property {string} baseAsset - Base asset contract id\n * @property {string} quoteAsset - Quote asset contract id\n * @property {string} cursor - Pagination cursor for this market\n * @property {string[]} orderTypes - Supported order types\n */\n\n/**\n * @typedef {{}} OrdersParams\n * @property {string} [owner] - Filter by order owner address\n * @property {string|string[]} [asset] - Filter by asset(s) - matches orders selling or buying any of them\n * @property {string|bigint} [cursor] - Pagination cursor (order id)\n * @property {number|string} [limit] - Max orders to return\n */\n\n/**\n * @typedef {{}} OrderHistoryParams\n * @property {string} [owner] - Filter by order owner address\n * @property {string[]} [pair] - Asset pair `[base, quote]` (contract ids)\n * @property {string|bigint} [cursor] - Pagination cursor (order id)\n * @property {number|string} [limit] - Max orders to return\n */\n\n/**\n * @typedef {{}} TradesParams\n * @property {string} [trader] - Filter by trader address\n * @property {string[]} [pair] - Asset pair `[base, quote]` (contract ids)\n * @property {string|bigint} [cursor] - Pagination cursor (trade id)\n * @property {number|string} [limit] - Max trades to return\n */\n\n/**\n * @typedef {{}} ApiOrder - Serialized order returned by the API\n * @property {string} id - Order ID\n * @property {string} status - Order status (`ACTIVE`|`FILLED`|`CANCELED`)\n * @property {string} kind - Order kind (`LIMIT`)\n * @property {string} buying - Buying asset contract id\n * @property {string} selling - Selling asset contract id\n * @property {string} price - Order price\n * @property {string} rprice - Rational price representation\n * @property {string} quote - Total quote amount\n * @property {string} amount - Amount left to sell/buy\n * @property {string} owner - Maker address\n * @property {string} [expires] - Expiration timestamp (UTC)\n * @property {string} [iceberg] - Iceberg amount\n * @property {string} [stop] - Stop price\n * @property {string} [created] - Creation timestamp (UTC)\n * @property {string} [updated] - Last update timestamp (UTC)\n * @property {string} [cursor] - Pagination cursor\n */\n\n/**\n * @typedef {{}} ApiTrade - Serialized trade returned by the API\n * @property {string} id - Trade ID\n * @property {string} order - Matched order ID\n * @property {string} taker - Taker account address\n * @property {string} maker - Maker account address\n * @property {string} soldAsset - Sold asset contract id\n * @property {string} boughtAsset - Bought asset contract id\n * @property {string} sold - Sold tokens amount\n * @property {string} bought - Bought tokens amount\n * @property {string} price - Approximate trade price\n * @property {string} [cursor] - Pagination cursor\n * @property {string} timestamp - Trade timestamp (UTC)\n */\n","import {xdr, Address, TransactionBuilder, contract} from '@stellar/stellar-sdk'\n\n/**\n * Upper bound of a serialized `Order` ledger entry in bytes.\n * (u64 id/expires, u32 kind, three 32-byte addresses, three i128 amounts = 428 bytes, rounded up to 512).\n * @type {number}\n */\nexport const ORDER_ENTRY_SIZE = 512\n\n/**\n * CPU instructions added to the declared budget for every order that was not matched at simulation time.\n * @type {number}\n */\nexport const ORDER_INSTRUCTIONS = 2_000_000\n\n/**\n * Resource fee (stroops) added for every order that was not matched at simulation time.\n * (write entry ~10k, read entry ~6k, writes ~12k, 2M instructions ~5k, trade/order events ~10k).\n * @type {bigint}\n */\nexport const ORDER_RESOURCE_FEE = 100_000n\n\n/**\n * Network-wide per-transaction instructions limit.\n * @type {number}\n */\nconst MAX_TX_INSTRUCTIONS = 100_000_000\n\n/**\n * Flatten and deduplicate order ids from several lists, coercing them to bigint.\n * @param {...(Array<bigint|number|string>|undefined|null)} idLists - Lists of order ids\n * @return {bigint[]} - Unique order ids in the order of first appearance\n */\nexport function collectOrderIds(...idLists) {\n const seen = new Set()\n const res = []\n for (const list of idLists) {\n if (!list)\n continue\n for (const id of list) {\n if (id === undefined || id === null)\n continue\n const value = BigInt(id)\n const key = value.toString()\n if (seen.has(key))\n continue\n seen.add(key)\n res.push(value)\n }\n }\n return res\n}\n\n/**\n * Build persistent contract data ledger key of an order.\n * @param {string} contractId - DEX contract address\n * @param {bigint|number|string} orderId - Order id\n * @return {xdr.LedgerKey}\n */\nexport function orderLedgerKey(contractId, orderId) {\n return xdr.LedgerKey.contractData(new xdr.LedgerKeyContractData({\n contract: Address.fromString(contractId).toScAddress(),\n key: xdr.ScVal.scvU64(new xdr.Uint64(BigInt(orderId))),\n durability: xdr.ContractDataDurability.persistent()\n }))\n}\n\n/**\n * Make sure every supplied order id declared in the read-write footprint of a simulated transaction.\n * @param {contract.AssembledTransaction} tx - Simulated transaction\n * @param {string} contractId - DEX contract address\n * @param {Array<bigint|number|string>} orderIds - Order ids passed to the contract call\n * @return {number} - Number of order entries added to the read-write footprint\n */\nexport function ensureOrdersFootprint(tx, contractId, orderIds) {\n const simulation = tx.simulation\n if (!simulation || simulation.error || simulation.restorePreamble || !tx.built || !orderIds?.length)\n return 0\n /** @type {SorobanDataBuilder} */\n const data = simulation.transactionData\n const readOnly = data.getReadOnly()\n const readWrite = data.getReadWrite()\n const roIndex = new Map(readOnly.map((key, i) => [key.toXDR('base64'), i]))\n const rwIndex = new Set(readWrite.map(key => key.toXDR('base64')))\n const dropFromReadOnly = new Set()\n let added = 0\n for (const id of collectOrderIds(orderIds)) {\n const key = orderLedgerKey(contractId, id)\n const encoded = key.toXDR('base64')\n if (rwIndex.has(encoded))\n continue\n //a key can't be listed in both parts of the footprint\n if (roIndex.has(encoded)) {\n dropFromReadOnly.add(roIndex.get(encoded))\n }\n readWrite.push(key)\n rwIndex.add(encoded)\n added++\n }\n if (added === 0)\n return 0\n const newReadOnly = readOnly.filter((_, i) => !dropFromReadOnly.has(i))\n data.setFootprint(newReadOnly, readWrite)\n\n //declare resources for the orders that may get matched at execution time\n const resources = data.build().resources()\n const instructions = Math.min(resources.instructions() + added * ORDER_INSTRUCTIONS, MAX_TX_INSTRUCTIONS)\n data.setResources(instructions, resources.diskReadBytes(), resources.writeBytes() + added * ORDER_ENTRY_SIZE)\n const resourceFee = data.build().resourceFee().toBigInt() + BigInt(added) * ORDER_RESOURCE_FEE\n data.setResourceFee(resourceFee.toString())\n\n //drop cached simulation data so the SDK picks up the patched builder when signing\n delete tx.simulationTransactionData\n //keep the built transaction consistent with the patched footprint and fee\n const timeout = tx.options?.timeoutInSeconds ?? 300\n tx.built = TransactionBuilder.cloneFrom(tx.built, {\n sorobanData: data.build(),\n timebounds: undefined\n })\n .setTimeout(timeout)\n .build()\n return added\n}\n","import {Networks, contract} from '@stellar/stellar-sdk'\r\nimport ContractClient from './contract-client.js'\r\nimport {ContractErrors, processSimulationErrors} from './errors.js'\r\nimport {AxisApiClient, AxisApiError} from './api-client.js'\r\nimport {collectOrderIds, ensureOrdersFootprint} from './footprint.js'\r\n\r\nexport {ContractErrors, AxisApiClient, AxisApiError}\r\n\r\n/** Trading order type - instructions to contract how to execute the trade */\r\nexport const OrderKind = {\r\n /** Execute trade, create a limit order if not executed in full */\r\n Limit: 1,\r\n /** Execute trade without creating a limit order */\r\n Fill: 2,\r\n /** Execute trade, cancel if was not executed in full */\r\n FillOrKill: 3\r\n}\r\n\r\n/** Trade direction instructions */\r\nexport const TradeDirection = {\r\n Sell: 1,\r\n Buy: 2\r\n}\r\n\r\n/**\r\n * Smart contract client for trading with AXIS DEX\r\n */\r\nexport class AxisContractClient {\r\n /**\r\n * @param {ClientInitializationParams} params\r\n */\r\n constructor(params) {\r\n const options = {\r\n publicKey: params.publicKey,\r\n signTransaction: params.signTransaction,\r\n rpcUrl: params.rpcUrl,\r\n allowHttp: true,\r\n networkPassphrase: params.networkPassphrase || Networks.PUBLIC,\r\n contractId: params.contractId\r\n }\r\n this.client = new ContractClient(options)\r\n this.fee = params.fee || '100000'\r\n this.autoFootprint = params.autoFootprint !== false\r\n }\r\n\r\n /**\r\n * Declare all order ids of a simulated call in the read-write footprint (if enabled)\r\n * @param {contract.AssembledTransaction} tx - Simulated transaction\r\n * @param {...Array<bigint>} idLists - Order ids passed to the contract call\r\n * @private\r\n */\r\n updateFootprint(tx, ...idLists) {\r\n if (this.autoFootprint) {\r\n const orderIds = collectOrderIds(...idLists)\r\n ensureOrdersFootprint(tx, this.client.options.contractId, orderIds)\r\n }\r\n }\r\n\r\n /**\r\n * Retrieve last order id\r\n * @return {Promise<bigint>} - Last created order id\r\n */\r\n async last() {\r\n const tx = await this.client.last()\r\n processSimulationErrors(tx)\r\n return tx.result\r\n }\r\n\r\n /**\r\n * @param {bigint} id - ID of the order to fetch\r\n * @return {Promise<Order>} - Order fetched from the storage\r\n */\r\n async order(id) {\r\n const tx = await this.client.order({id})\r\n processSimulationErrors(tx)\r\n return tx.result\r\n }\r\n\r\n /**\r\n * Cancel existing order\r\n * @param {bigint[]} ids - ID of the order to cancel\r\n * @param {string} trader - Trader address\r\n * @return {Promise<void>}\r\n * @throws {Error} - If trader is not the owner of the order\r\n */\r\n async cancel(ids, trader) {\r\n const tx = await this.client.cancel({ids, trader}, {fee: this.fee})\r\n processSimulationErrors(tx)\r\n await tx.signAndSend()\r\n }\r\n\r\n /**\r\n * Fill existing orders using another matching order from the orderbook\r\n * @param {string} trader - Trader address\r\n * @param {bigint} takerOrderId - ID of the order that serves as a taker\r\n * @param {bigint[]} orders - List of order IDs to match before creating the order on chain\r\n * @return {Promise<[bigint, bigint]>} - Amount of sold and bought tokens\r\n * @throws {Error} - If the taker order was not found\r\n * @throws {Error} - If any of the orders provided do not match selling/buying asset\r\n * @throws {Error} - If the trade causes an overflow\r\n */\r\n async fill_order(trader, takerOrderId, orders) {\r\n const tx = await this.client.fill_order({trader, taker_order_id: takerOrderId, orders}, {fee: this.fee})\r\n processSimulationErrors(tx)\r\n this.updateFootprint(tx, [takerOrderId], orders)\r\n const res = await tx.signAndSend()\r\n return [res.result.sold, res.result.bought]\r\n }\r\n\r\n /**\r\n * Trade with DEX and create buy limit order if quote not executed in full\r\n * @param {BuyTradeArguments} params\r\n * @return {Promise<[bigint, bigint, bigint]>} - Amount of sold and bought tokens, ID of the newly created order if any\r\n * @throws {Error} - If the trader has insufficient balance\r\n * @throws {Error} - If any of the orders provided do not match selling/buying asset\r\n * @throws {Error} - If the trade causes an overflow\r\n */\r\n async buy(params) {\r\n return await execTrade(params, TradeDirection.Buy, this)\r\n }\r\n\r\n /**\r\n * Trade with DEX and create sell limit order if quote not executed in full\r\n * @param {SellTradeArguments} params\r\n * @return {Promise<[bigint, bigint, bigint]>} - Amount of sold and bought tokens, ID of the newly created order if any\r\n * @throws {Error} - If the trader has insufficient balance\r\n * @throws {Error} - If any of the orders provided do not match selling/buying asset\r\n * @throws {Error} - If the trade causes an overflow\r\n */\r\n async sell(params) {\r\n return await execTrade(params, TradeDirection.Sell, this)\r\n }\r\n\r\n async swap(params) {\r\n const tx = await this.client.swap({\r\n direction: params.direction,\r\n trader: params.trader,\r\n selling: params.selling,\r\n selling_amount: params.sellingAmount,\r\n buying_amount: params.buyingAmount,\r\n path: params.path.map(step => ({asset: step.asset, orders: step.orders}))\r\n }, {fee: this.fee})\r\n processSimulationErrors(tx)\r\n this.updateFootprint(tx, ...params.path.map(step => step.orders))\r\n const res = await tx.signAndSend()\r\n return [res.result.sold, res.result.bought]\r\n }\r\n}\r\n\r\nasync function execTrade(params, direction, context) {\r\n const payload = {\r\n direction: direction,\r\n kind: params.kind,\r\n trader: params.trader,\r\n amount: params.amount,\r\n selling: params.selling,\r\n buying: params.buying,\r\n price: params.price,\r\n orders: params.orders\r\n }\r\n const tx = await context.client.trade(payload, {fee: context.fee})\r\n processSimulationErrors(tx)\r\n context.updateFootprint(tx, params.orders)\r\n const {result} = await tx.signAndSend()\r\n return [result[0], result[1], result[2]]\r\n}\r\n\r\n/**\r\n * @typedef {{}} ClientInitializationParams\r\n * @property {string} publicKey - Public key of the account that will interact with the contract\r\n * @property {SignTransactionCallback} signTransaction - Callback for signing transactions generated by the client\r\n * @property {string} rpcUrl - URL of the RPC server\r\n * @property {string} contractId - DEX contract ID\r\n * @property {string} [networkPassphrase] - Network passphrase (Pubnet passphrase by default)\r\n * @property {string} [fee] - Transaction fee (0.1 XLM by default)\r\n * @property {boolean} [autoFootprint] - Declare every supplied order id in the read-write footprint of trading transactions (enabled by default)\r\n */\r\n\r\n/**\r\n * @callback SignTransactionCallback - Callback for signing transactions generated by the client\r\n * @param {string} tx - Transaction XDR to sign\r\n * @param {{network: string, networkPassphrase: string, accountToSign: string}} context - Signing context\r\n * @return {Promise<{signedTxXdr: string, [signerAddress]: string}>} - Signed transaction response\r\n */\r\n\r\n/**\r\n * @typedef {{}} TradeArguments\r\n * @property {OrderKind} kind - Trading order behavior\r\n * @property {string} trader - Trader address\r\n * @property {bigint} amount - Tokens amount\r\n * @property {string} selling - Selling token address\r\n * @property {string} buying - Buying token address\r\n * @property {bigint} price - Price a trader willing to accept\r\n * @property {Array<bigint>} orders - List of order IDs to match before creating the order on-chain\r\n */\r\n\r\n/**\r\n * @typedef {{}} SellTradeArguments\r\n * @extends TradeArguments\r\n * @property {bigint} amount - Amount of `selling` tokens to sell\r\n * @property {bigint} price - Price a trader willing to accept, minimum `buying` tokens per 1 `selling`\r\n */\r\n\r\n/**\r\n * @typedef {{}} BuyTradeArguments\r\n * @extends TradeArguments\r\n * @property {bigint} amount - Amount of `buying` tokens to acquire\r\n * @property {bigint} price - Price a trader willing to accept, maximum `selling` tokens per 1 `buying`\r\n */\r\n\r\n/**\r\n * @typedef {{}} TradeStep - A trade step in a multi-market swap path\r\n * @property {string} asset - Asset to buy at this step\r\n * @property {Array<bigint>} orders - Maker order IDs to match\r\n */\r\n\r\n/**\r\n * @typedef {{}} SwapArguments\r\n * @property {TradeDirection} direction - Trade direction: `Sell` or `Buy`\r\n * @property {string} trader - Trader address\r\n * @property {string} selling - Token address sent by the trader\r\n * @property {bigint} selling_amount - Maximum amount of selling tokens to send\r\n * @property {bigint} buying_amount - Minimum amount of buying tokens to receive\r\n * @property {Array<TradeStep>} path - Ordered list of the trade route steps\r\n */\r\n\r\n/**\r\n * @typedef {{}} MethodOptions\r\n * @property {string} [fee] - Transaction fee (0.1 XLM by default)\r\n */\r\n\r\n/**\r\n * @typedef {{}} Order - Order properties, stored on-chain\r\n * @property {bigint} id - Order ID\r\n * @property {OrderKind} kind - Trading behavior\r\n * @property {string} owner - Owner of the order\r\n * @property {string} selling - Selling token address\r\n * @property {string} buying - Buying token address\r\n * @property {bigint} amount - Amount of tokens to sell\r\n * @property {bigint} price - Price of the order\r\n * @property {bigint} quote - Total amount of tokens to buy\r\n * @property {bigint} expires - Expiration time of the order\r\n */\r\n\r\n/**\r\n* @typedef {object} TradeContractEvent - Orderbook trade event\r\n* @property {bigint} bought - Bought tokens amount\r\n* @property {string} buying - Bought asset address\r\n* @property {bigint} id - Unique trade id\r\n* @property {string} maker - Seller account address\r\n* @property {bigint} order - Order id\r\n* @property {string} selling - Sold asset address\r\n* @property {bigint} sold - Sold tokens amount\r\n* @property {string} taker - Trader account address\r\n*/\r\n\r\n/**\r\n * @typedef {object} SwapContractEvent - Orderbook swap event\r\n * @property {bigint} id - Unique swap id (last trade id assigned while settling the swap legs)\r\n * @property {string} trader - Trader account address\r\n * @property {string} selling - Sold asset address\r\n * @property {string} buying - Bought asset address\r\n * @property {bigint} sold - Amount of `selling` tokens sold\r\n * @property {bigint} bought - Amount of `buying` tokens received\r\n */","import {AxisContractClient, ContractErrors, TradeDirection, OrderKind, AxisApiClient, AxisApiError} from './index.js'\r\n\r\nconst axisClient = {AxisContractClient, ContractErrors, TradeDirection, OrderKind, AxisApiClient, AxisApiError}\r\n\r\nexport default axisClient"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__346__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","ContractClient","stellar_sdk_","contract","Client","options","constructor","super","Spec","fromJSON","last","txFromJSON","order","cancel","trade","swap","fill_order","ContractErrors","message","processSimulationErrors","tx","simulation","error","contractErrorMatch","exec","code","err","Error","AxisApiError","status","name","collectOrderIds","idLists","seen","Set","res","list","id","value","BigInt","toString","has","add","push","orderLedgerKey","contractId","orderId","xdr","LedgerKey","contractData","LedgerKeyContractData","Address","fromString","toScAddress","ScVal","scvU64","Uint64","durability","ContractDataDurability","persistent","TradeDirection","Sell","Buy","async","execTrade","params","direction","context","payload","kind","trader","amount","selling","buying","price","orders","client","fee","updateFootprint","result","signAndSend","cjs","AxisContractClient","publicKey","signTransaction","rpcUrl","allowHttp","networkPassphrase","Networks","PUBLIC","autoFootprint","orderIds","restorePreamble","built","length","data","transactionData","readOnly","getReadOnly","readWrite","getReadWrite","roIndex","Map","map","i","toXDR","rwIndex","dropFromReadOnly","added","encoded","newReadOnly","filter","_","setFootprint","resources","build","instructions","Math","min","setResources","diskReadBytes","writeBytes","resourceFee","toBigInt","setResourceFee","simulationTransactionData","timeout","timeoutInSeconds","TransactionBuilder","cloneFrom","sorobanData","timebounds","setTimeout","ensureOrdersFootprint","ids","takerOrderId","taker_order_id","sold","bought","buy","sell","selling_amount","sellingAmount","buying_amount","buyingAmount","path","step","asset","OrderKind","Limit","Fill","FillOrKill","AxisApiClient","serverUrl","TypeError","replace","quoteSell","quote","quoteBuy","sellingAsset","buyingAsset","direct","request","getDepth","market","depth","getCandles","from","to","resolution","getTicker24h","getMarkets","cursor","limit","getOrders","owner","getOrder","encodeURIComponent","getOrderHistory","pair","getTrades","query","url","search","URLSearchParams","entries","Array","isArray","item","append","qs","response","fetch","body","json","e","ok","statusText"],"sourceRoot":""}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@stellar/stellar-sdk")):"function"==typeof define&&define.amd?define(["@stellar/stellar-sdk"],e):"object"==typeof exports?exports.axisFootprint=e(require("@stellar/stellar-sdk")):t.axisFootprint=e(t["@stellar/stellar-sdk"])}(this,t=>(()=>{"use strict";var e={346(e){e.exports=t}},r={};function o(t){var n=r[t];if(void 0!==n)return n.exports;var s=r[t]={exports:{}};return e[t](s,s.exports,o),s.exports}o.d=(t,e)=>{for(var r in e)o.o(e,r)&&!o.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};o.d(n,{default:()=>l});var s=o(346);const a=2e6,i=100000n;function d(...t){const e=new Set,r=[];for(const o of t)if(o)for(const t of o){if(null==t)continue;const o=BigInt(t),n=o.toString();e.has(n)||(e.add(n),r.push(o))}return r}function c(t,e){return s.xdr.LedgerKey.contractData(new s.xdr.LedgerKeyContractData({contract:s.Address.fromString(t).toScAddress(),key:s.xdr.ScVal.scvU64(new s.xdr.Uint64(BigInt(e))),durability:s.xdr.ContractDataDurability.persistent()}))}const l={collectOrderIds:d,ensureOrdersFootprint:function(t,e,r){const o=t.simulation;if(!o||o.error||o.restorePreamble||!t.built||!r?.length)return 0;const n=o.transactionData,l=n.getReadOnly(),u=n.getReadWrite(),f=new Map(l.map((t,e)=>[t.toXDR("base64"),e])),p=new Set(u.map(t=>t.toXDR("base64"))),b=new Set;let R=0;for(const t of d(r)){const r=c(e,t),o=r.toXDR("base64");p.has(o)||(f.has(o)&&b.add(f.get(o)),u.push(r),p.add(o),R++)}if(0===R)return 0;const x=l.filter((t,e)=>!b.has(e));n.setFootprint(x,u);const y=n.build().resources(),g=Math.min(y.instructions()+R*a,1e8);n.setResources(g,y.diskReadBytes(),y.writeBytes()+512*R);const m=n.build().resourceFee().toBigInt()+BigInt(R)*i;n.setResourceFee(m.toString()),delete t.simulationTransactionData;const D=t.options?.timeoutInSeconds??300;return t.built=s.TransactionBuilder.cloneFrom(t.built,{sorobanData:n.build(),timebounds:void 0}).setTimeout(D).build(),R},orderLedgerKey:c,ORDER_ENTRY_SIZE:512,ORDER_INSTRUCTIONS:a,ORDER_RESOURCE_FEE:i};return n.default})());
|
|
2
|
+
//# sourceMappingURL=footprint.cjs.map
|
|
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EAAKoB,QAAQO,cAAcC,WAAa5D,OAAO6C,GAAStD,EAC5EyC,EAAK6B,eAAeF,EAAY1D,mBAGzBwB,EAAGqC,0BAEV,MAAMC,EAAUtC,EAAGuC,SAASC,kBAAoB,IAOhD,OANAxC,EAAGK,MAAQtB,EAAA0D,mBAAmBC,UAAU1C,EAAGK,MAAO,CAC9CsC,YAAapC,EAAKoB,QAClBiB,gBAAY9F,IAEX+F,WAAWP,GACXX,QACEP,CACX,EC9GIxC,eAAcA,EACdkE,iBDN4B,ICO5BjF,mBAAkBA,EAClBC,mBAAkBA","sources":["webpack://@axis-markets/client/webpack/universalModuleDefinition","webpack://@axis-markets/client/external umd \"@stellar/stellar-sdk\"","webpack://@axis-markets/client/webpack/bootstrap","webpack://@axis-markets/client/webpack/runtime/define property getters","webpack://@axis-markets/client/webpack/runtime/hasOwnProperty shorthand","webpack://@axis-markets/client/./src/footprint.js","webpack://@axis-markets/client/./src/footprint-cjs.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"@stellar/stellar-sdk\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"@stellar/stellar-sdk\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"axisFootprint\"] = factory(require(\"@stellar/stellar-sdk\"));\n\telse\n\t\troot[\"axisFootprint\"] = factory(root[\"@stellar/stellar-sdk\"]);\n})(this, (__WEBPACK_EXTERNAL_MODULE__346__) => {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__346__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import {xdr, Address, TransactionBuilder, contract} from '@stellar/stellar-sdk'\n\n/**\n * Upper bound of a serialized `Order` ledger entry in bytes.\n * (u64 id/expires, u32 kind, three 32-byte addresses, three i128 amounts = 428 bytes, rounded up to 512).\n * @type {number}\n */\nexport const ORDER_ENTRY_SIZE = 512\n\n/**\n * CPU instructions added to the declared budget for every order that was not matched at simulation time.\n * @type {number}\n */\nexport const ORDER_INSTRUCTIONS = 2_000_000\n\n/**\n * Resource fee (stroops) added for every order that was not matched at simulation time.\n * (write entry ~10k, read entry ~6k, writes ~12k, 2M instructions ~5k, trade/order events ~10k).\n * @type {bigint}\n */\nexport const ORDER_RESOURCE_FEE = 100_000n\n\n/**\n * Network-wide per-transaction instructions limit.\n * @type {number}\n */\nconst MAX_TX_INSTRUCTIONS = 100_000_000\n\n/**\n * Flatten and deduplicate order ids from several lists, coercing them to bigint.\n * @param {...(Array<bigint|number|string>|undefined|null)} idLists - Lists of order ids\n * @return {bigint[]} - Unique order ids in the order of first appearance\n */\nexport function collectOrderIds(...idLists) {\n const seen = new Set()\n const res = []\n for (const list of idLists) {\n if (!list)\n continue\n for (const id of list) {\n if (id === undefined || id === null)\n continue\n const value = BigInt(id)\n const key = value.toString()\n if (seen.has(key))\n continue\n seen.add(key)\n res.push(value)\n }\n }\n return res\n}\n\n/**\n * Build persistent contract data ledger key of an order.\n * @param {string} contractId - DEX contract address\n * @param {bigint|number|string} orderId - Order id\n * @return {xdr.LedgerKey}\n */\nexport function orderLedgerKey(contractId, orderId) {\n return xdr.LedgerKey.contractData(new xdr.LedgerKeyContractData({\n contract: Address.fromString(contractId).toScAddress(),\n key: xdr.ScVal.scvU64(new xdr.Uint64(BigInt(orderId))),\n durability: xdr.ContractDataDurability.persistent()\n }))\n}\n\n/**\n * Make sure every supplied order id declared in the read-write footprint of a simulated transaction.\n * @param {contract.AssembledTransaction} tx - Simulated transaction\n * @param {string} contractId - DEX contract address\n * @param {Array<bigint|number|string>} orderIds - Order ids passed to the contract call\n * @return {number} - Number of order entries added to the read-write footprint\n */\nexport function ensureOrdersFootprint(tx, contractId, orderIds) {\n const simulation = tx.simulation\n if (!simulation || simulation.error || simulation.restorePreamble || !tx.built || !orderIds?.length)\n return 0\n /** @type {SorobanDataBuilder} */\n const data = simulation.transactionData\n const readOnly = data.getReadOnly()\n const readWrite = data.getReadWrite()\n const roIndex = new Map(readOnly.map((key, i) => [key.toXDR('base64'), i]))\n const rwIndex = new Set(readWrite.map(key => key.toXDR('base64')))\n const dropFromReadOnly = new Set()\n let added = 0\n for (const id of collectOrderIds(orderIds)) {\n const key = orderLedgerKey(contractId, id)\n const encoded = key.toXDR('base64')\n if (rwIndex.has(encoded))\n continue\n //a key can't be listed in both parts of the footprint\n if (roIndex.has(encoded)) {\n dropFromReadOnly.add(roIndex.get(encoded))\n }\n readWrite.push(key)\n rwIndex.add(encoded)\n added++\n }\n if (added === 0)\n return 0\n const newReadOnly = readOnly.filter((_, i) => !dropFromReadOnly.has(i))\n data.setFootprint(newReadOnly, readWrite)\n\n //declare resources for the orders that may get matched at execution time\n const resources = data.build().resources()\n const instructions = Math.min(resources.instructions() + added * ORDER_INSTRUCTIONS, MAX_TX_INSTRUCTIONS)\n data.setResources(instructions, resources.diskReadBytes(), resources.writeBytes() + added * ORDER_ENTRY_SIZE)\n const resourceFee = data.build().resourceFee().toBigInt() + BigInt(added) * ORDER_RESOURCE_FEE\n data.setResourceFee(resourceFee.toString())\n\n //drop cached simulation data so the SDK picks up the patched builder when signing\n delete tx.simulationTransactionData\n //keep the built transaction consistent with the patched footprint and fee\n const timeout = tx.options?.timeoutInSeconds ?? 300\n tx.built = TransactionBuilder.cloneFrom(tx.built, {\n sorobanData: data.build(),\n timebounds: undefined\n })\n .setTimeout(timeout)\n .build()\n return added\n}\n","import {\n collectOrderIds,\n ensureOrdersFootprint,\n orderLedgerKey,\n ORDER_ENTRY_SIZE,\n ORDER_INSTRUCTIONS,\n ORDER_RESOURCE_FEE\n} from './footprint.js'\n\nconst axisFootprint = {\n collectOrderIds,\n ensureOrdersFootprint,\n orderLedgerKey,\n ORDER_ENTRY_SIZE,\n ORDER_INSTRUCTIONS,\n ORDER_RESOURCE_FEE\n}\n\nexport default axisFootprint\n"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE__346__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","ORDER_INSTRUCTIONS","ORDER_RESOURCE_FEE","collectOrderIds","idLists","seen","Set","res","list","id","value","BigInt","toString","has","add","push","orderLedgerKey","contractId","orderId","stellar_sdk_","xdr","LedgerKey","contractData","LedgerKeyContractData","contract","Address","fromString","toScAddress","ScVal","scvU64","Uint64","durability","ContractDataDurability","persistent","footprint_cjs","ensureOrdersFootprint","tx","orderIds","simulation","error","restorePreamble","built","length","data","transactionData","readOnly","getReadOnly","readWrite","getReadWrite","roIndex","Map","map","i","toXDR","rwIndex","dropFromReadOnly","added","encoded","newReadOnly","filter","_","setFootprint","resources","build","instructions","Math","min","setResources","diskReadBytes","writeBytes","resourceFee","toBigInt","setResourceFee","simulationTransactionData","timeout","options","timeoutInSeconds","TransactionBuilder","cloneFrom","sorobanData","timebounds","setTimeout","ORDER_ENTRY_SIZE"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axis-markets/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "AXIS contract and API client",
|
|
5
5
|
"author": "team@stellar.expert",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"import": "./src/index.js",
|
|
15
15
|
"require": "./lib/axis-client.cjs"
|
|
16
16
|
},
|
|
17
|
+
"./footprint": {
|
|
18
|
+
"types": "./src/footprint.d.ts",
|
|
19
|
+
"import": "./src/footprint.js",
|
|
20
|
+
"require": "./lib/footprint.cjs"
|
|
21
|
+
},
|
|
17
22
|
"./package.json": "./package.json"
|
|
18
23
|
},
|
|
19
24
|
"homepage": "https://axis.markets",
|
|
@@ -23,6 +28,7 @@
|
|
|
23
28
|
},
|
|
24
29
|
"bugs": "https://github.com/axis-markets/js-client/issues",
|
|
25
30
|
"scripts": {
|
|
31
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
26
32
|
"prepare": "webpack --mode=production --config webpack.config.cjs"
|
|
27
33
|
},
|
|
28
34
|
"peerDependencies": {
|
|
@@ -43,6 +49,7 @@
|
|
|
43
49
|
"files": [
|
|
44
50
|
"src/",
|
|
45
51
|
"lib/",
|
|
46
|
-
"!src/cjs.js"
|
|
52
|
+
"!src/cjs.js",
|
|
53
|
+
"!src/footprint-cjs.js"
|
|
47
54
|
]
|
|
48
55
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {xdr} from "@stellar/stellar-sdk";
|
|
2
|
+
|
|
3
|
+
/** Upper bound of a serialized `Order` ledger entry in bytes */
|
|
4
|
+
export declare const ORDER_ENTRY_SIZE: number;
|
|
5
|
+
/** CPU instructions added to the declared budget per order not matched at simulation time */
|
|
6
|
+
export declare const ORDER_INSTRUCTIONS: number;
|
|
7
|
+
/** Resource fee (stroops) added per order not matched at simulation time */
|
|
8
|
+
export declare const ORDER_RESOURCE_FEE: bigint;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Flatten and deduplicate order ids from several lists, coercing them to bigint
|
|
12
|
+
* @param idLists - Lists of order ids
|
|
13
|
+
* @return Unique order ids in the order of first appearance
|
|
14
|
+
*/
|
|
15
|
+
export declare function collectOrderIds(...idLists: Array<Array<bigint | number | string> | undefined | null>): bigint[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Build the persistent contract data ledger key of an order
|
|
19
|
+
* @param contractId - DEX contract address
|
|
20
|
+
* @param orderId - Order id
|
|
21
|
+
*/
|
|
22
|
+
export declare function orderLedgerKey(contractId: string, orderId: bigint | number | string): xdr.LedgerKey;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Make sure every supplied order id is declared in the read-write footprint of a simulated transaction.
|
|
26
|
+
* Patches the simulation data (footprint, resources, resource fee) in place and rebuilds `tx.built`.
|
|
27
|
+
* @param tx - Simulated `AssembledTransaction` from `@stellar/stellar-sdk/contract`
|
|
28
|
+
* @param contractId - DEX contract address
|
|
29
|
+
* @param orderIds - Order ids passed to the contract call
|
|
30
|
+
* @return Number of order entries added to the read-write footprint
|
|
31
|
+
*/
|
|
32
|
+
export declare function ensureOrdersFootprint(tx: any, contractId: string, orderIds: Array<bigint | number | string>): number;
|