ault-sdk-ts 0.16.0 → 0.16.1
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 +49 -21
- package/dist/index.cjs +19 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -25
- package/dist/index.js.map +1 -1
- package/dist/rest/clob.d.ts +3 -1
- package/dist/rest/margin.d.ts +2 -2
- package/dist/rest/market-id.d.ts +13 -0
- package/dist/rest/market.d.ts +3 -1
- package/dist/rest/perpetual.d.ts +5 -2
- package/dist/rest/reward.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -326,10 +326,11 @@ const operators = await client.miner.getOperators();
|
|
|
326
326
|
const delegation = await client.miner.getLicenseDelegation("123");
|
|
327
327
|
const emission = await client.miner.getEmissionInfo();
|
|
328
328
|
|
|
329
|
-
// Market and CLOB queries
|
|
329
|
+
// Market and CLOB queries. A market id can be bytes, a MarketId, or a hex
|
|
330
|
+
// (as the dex-api returns it, with or without 0x) or base64 string.
|
|
330
331
|
const markets = await client.market.getMarkets();
|
|
331
|
-
const market = await client.market.getMarket(
|
|
332
|
-
const orders = await client.clob.getOrders({
|
|
332
|
+
const market = await client.market.getMarket(marketIdHex);
|
|
333
|
+
const orders = await client.clob.getOrders({ marketId: marketIdHex });
|
|
333
334
|
|
|
334
335
|
// Reward queries
|
|
335
336
|
const rewardParams = await client.reward.getParams();
|
|
@@ -365,6 +366,7 @@ collateral denom. The chain accepts limit orders only, so a "market order" is
|
|
|
365
366
|
an immediate-or-cancel limit priced through the book:
|
|
366
367
|
|
|
367
368
|
```typescript
|
|
369
|
+
import { parseUnits } from "viem";
|
|
368
370
|
import { iocLimitPrice } from "ault-sdk-ts";
|
|
369
371
|
|
|
370
372
|
const dex = client._lowLevel.rest.dex;
|
|
@@ -381,7 +383,7 @@ await client.placeLimitOrder({
|
|
|
381
383
|
marketId,
|
|
382
384
|
isBuy: true,
|
|
383
385
|
price,
|
|
384
|
-
quantity: "
|
|
386
|
+
quantity: parseUnits("0.01", 18).toString(), // 0.01 BTC
|
|
385
387
|
deadline: new Date(Date.now() + 60_000),
|
|
386
388
|
timeInForce: "ioc",
|
|
387
389
|
reduceOnly: false,
|
|
@@ -400,10 +402,12 @@ and leverage are set per market and cannot change while a position or resting
|
|
|
400
402
|
order exists:
|
|
401
403
|
|
|
402
404
|
```typescript
|
|
403
|
-
|
|
405
|
+
// Base units with 18 decimals, like every bank denom.
|
|
406
|
+
await client.depositPerpCollateral({ amount: parseUnits("1000", 18).toString() });
|
|
404
407
|
await client.setMarginConfig({ marketId, leverage: 10, cross: true });
|
|
405
|
-
|
|
406
|
-
await client.
|
|
408
|
+
// Isolated only.
|
|
409
|
+
await client.modifyPositionMargin({ marketId, marginDelta: parseUnits("-50", 18).toString() });
|
|
410
|
+
await client.withdrawPerpCollateral({ amount: parseUnits("250", 18).toString() });
|
|
407
411
|
```
|
|
408
412
|
|
|
409
413
|
A perpetual TWAP (`placeTwapOrder` with `reduceOnly`) is sized in base and
|
|
@@ -431,8 +435,9 @@ move the signer's own funds, so they are wallet-signed only (never by an
|
|
|
431
435
|
agent).
|
|
432
436
|
|
|
433
437
|
```typescript
|
|
434
|
-
|
|
435
|
-
const
|
|
438
|
+
// Bank denoms have 18 decimals, so 1000 USDC is 1000 * 10^18 base units.
|
|
439
|
+
const usdc = { denom: "erc20:0xd157...", amount: "1000000000000000000000" };
|
|
440
|
+
const weth = { denom: "erc20:0xcC4a...", amount: "500000000000000000" }; // 0.5 WETH
|
|
436
441
|
|
|
437
442
|
await client.lendingSupply({ poolId: 1, coin: usdc }); // earns the supply rate
|
|
438
443
|
await client.lendingSupplyCollateral({ poolId: 1, coin: weth }); // backs borrows, earns nothing
|
|
@@ -470,6 +475,7 @@ account per market, both derived from the owner's address, and their
|
|
|
470
475
|
collateral and debt live in the margin Lending pool.
|
|
471
476
|
|
|
472
477
|
```typescript
|
|
478
|
+
import { parseUnits } from "viem";
|
|
473
479
|
import { marginAccountAddress } from "ault-sdk-ts";
|
|
474
480
|
|
|
475
481
|
// Fund the isolated account of a market (omit marketId for the cross account).
|
|
@@ -481,7 +487,7 @@ await client.placeLimitOrder({
|
|
|
481
487
|
marketId,
|
|
482
488
|
isBuy: true,
|
|
483
489
|
price: "3500",
|
|
484
|
-
quantity: "0.5",
|
|
490
|
+
quantity: parseUnits("0.5", 18).toString(),
|
|
485
491
|
deadline: new Date(Date.now() + 3_600_000),
|
|
486
492
|
margin: { autoBorrow: true },
|
|
487
493
|
});
|
|
@@ -492,7 +498,7 @@ await client.placeLimitOrder({
|
|
|
492
498
|
marketId,
|
|
493
499
|
isBuy: false,
|
|
494
500
|
price: "3600",
|
|
495
|
-
quantity: "0.5",
|
|
501
|
+
quantity: parseUnits("0.5", 18).toString(),
|
|
496
502
|
deadline: new Date(Date.now() + 3_600_000),
|
|
497
503
|
margin: { autoRepay: true },
|
|
498
504
|
});
|
|
@@ -606,6 +612,8 @@ of vault:
|
|
|
606
612
|
Parent vaults belong to x/gov, so only a governance proposal can create one.
|
|
607
613
|
|
|
608
614
|
```typescript
|
|
615
|
+
import { parseUnits } from "viem";
|
|
616
|
+
|
|
609
617
|
const lendingVault = client.attachVaultManager({ vaultAddress, agentPrivateKey: managerKey });
|
|
610
618
|
await lendingVault.reallocateVault({ sourcePoolId: 1, destinationPoolId: 2, amount: usdc });
|
|
611
619
|
|
|
@@ -616,7 +624,13 @@ const parent = client.attachVaultManager({
|
|
|
616
624
|
});
|
|
617
625
|
await parent.transferChildVault({ childVault, amount: usdc, isDeposit: true });
|
|
618
626
|
const child = client.attachVaultManager({ vaultAddress: childVault, agentPrivateKey: managerKey });
|
|
619
|
-
await child.placeLimitOrder({
|
|
627
|
+
await child.placeLimitOrder({
|
|
628
|
+
marketId,
|
|
629
|
+
isBuy: true,
|
|
630
|
+
price: "3500",
|
|
631
|
+
quantity: parseUnits("1", 18).toString(),
|
|
632
|
+
deadline,
|
|
633
|
+
});
|
|
620
634
|
```
|
|
621
635
|
|
|
622
636
|
Status changes and config updates come from the vault's owner, not its
|
|
@@ -1084,18 +1098,32 @@ await client.updateOperatorInfo({
|
|
|
1084
1098
|
|
|
1085
1099
|
### Market And CLOB Transactions
|
|
1086
1100
|
|
|
1101
|
+
Order amounts are integers in base units. Every bank denom has 18 decimals on
|
|
1102
|
+
the chain, including tokens bridged from 6-decimal ERC20s, so `quantity` and a
|
|
1103
|
+
market order's `deposit` are the token amount times 10^18. `price` is a plain
|
|
1104
|
+
decimal of quote per base. A market order's `deposit` is quote on a buy and
|
|
1105
|
+
base on a sell. The chain rejects an order whose quote notional is below a
|
|
1106
|
+
minimum. On chain v3 that is `min_order_quote_amount` from
|
|
1107
|
+
`client.spot.getParams()` for spot orders and `client.perpetual.getParams()`
|
|
1108
|
+
for perpetual orders. On a chain before v3 (mainnet today) it is in
|
|
1109
|
+
`client.clob.getParams()`. It is currently `10000000000000000000`, or 10 quote
|
|
1110
|
+
tokens, and can change.
|
|
1111
|
+
|
|
1087
1112
|
```typescript
|
|
1113
|
+
import { parseUnits } from "viem";
|
|
1088
1114
|
import { base64ToBytes } from "ault-sdk-ts";
|
|
1089
1115
|
|
|
1090
1116
|
const marketId = base64ToBytes("base64MarketId...");
|
|
1117
|
+
const units = (amount: string) => parseUnits(amount, 18).toString();
|
|
1091
1118
|
|
|
1092
1119
|
// Place a limit order (broadcast-only: returns once CheckTx accepts it).
|
|
1120
|
+
// 100 base at 1.5 is a notional of 150 quote.
|
|
1093
1121
|
await client.placeLimitOrder({
|
|
1094
1122
|
marketId,
|
|
1095
1123
|
isBuy: true,
|
|
1096
1124
|
price: "1.5",
|
|
1097
|
-
quantity: "100",
|
|
1098
|
-
|
|
1125
|
+
quantity: units("100"),
|
|
1126
|
+
deadline: new Date(Date.now() + 3_600_000), // 1 hour
|
|
1099
1127
|
});
|
|
1100
1128
|
|
|
1101
1129
|
// Pass `wait: true` to poll for DeliverTx and read back the order ID.
|
|
@@ -1103,17 +1131,17 @@ const placed = await client.placeLimitOrder({
|
|
|
1103
1131
|
marketId,
|
|
1104
1132
|
isBuy: true,
|
|
1105
1133
|
price: "1.5",
|
|
1106
|
-
quantity: "100",
|
|
1107
|
-
|
|
1134
|
+
quantity: units("100"),
|
|
1135
|
+
deadline: new Date(Date.now() + 3_600_000),
|
|
1108
1136
|
wait: true,
|
|
1109
1137
|
});
|
|
1110
1138
|
console.log(placed.orderId);
|
|
1111
1139
|
|
|
1112
|
-
// Place a market order
|
|
1140
|
+
// Place a market order: buy with 100 quote.
|
|
1113
1141
|
await client.placeMarketOrder({
|
|
1114
1142
|
marketId,
|
|
1115
1143
|
isBuy: true,
|
|
1116
|
-
deposit: "100",
|
|
1144
|
+
deposit: units("100"),
|
|
1117
1145
|
});
|
|
1118
1146
|
|
|
1119
1147
|
// Cancel specific orders. With `wait: true` the result lists which IDs
|
|
@@ -1129,7 +1157,7 @@ const withCloid = await client.placeLimitOrder({
|
|
|
1129
1157
|
marketId,
|
|
1130
1158
|
isBuy: true,
|
|
1131
1159
|
price: "1.5",
|
|
1132
|
-
quantity: "100",
|
|
1160
|
+
quantity: units("100"),
|
|
1133
1161
|
deadline: new Date(Date.now() + 3600_000),
|
|
1134
1162
|
cloid,
|
|
1135
1163
|
wait: true,
|
|
@@ -1247,7 +1275,7 @@ const placed = await client.asAgent!.placeLimitOrder({
|
|
|
1247
1275
|
isBuy: true,
|
|
1248
1276
|
price: "1.0",
|
|
1249
1277
|
quantity: "1000000000000000000",
|
|
1250
|
-
|
|
1278
|
+
deadline: new Date(Date.now() + 3_600_000),
|
|
1251
1279
|
wait: true,
|
|
1252
1280
|
});
|
|
1253
1281
|
console.log(placed.orderId);
|
|
@@ -1267,7 +1295,7 @@ await client.asAgent!.placeScaleOrder({
|
|
|
1267
1295
|
highPrice: "1.1",
|
|
1268
1296
|
totalQuantity: "10000000000000000000",
|
|
1269
1297
|
weights: [3333, 3334, 3333],
|
|
1270
|
-
|
|
1298
|
+
deadline: new Date(Date.now() + 3_600_000),
|
|
1271
1299
|
});
|
|
1272
1300
|
```
|
|
1273
1301
|
|
package/dist/index.cjs
CHANGED
|
@@ -635,7 +635,7 @@ __export(index_exports, {
|
|
|
635
635
|
module.exports = __toCommonJS(index_exports);
|
|
636
636
|
|
|
637
637
|
// src/core/user-agent.ts
|
|
638
|
-
var SDK_VERSION = "0.16.
|
|
638
|
+
var SDK_VERSION = "0.16.1";
|
|
639
639
|
var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
|
|
640
640
|
function isServerRuntime() {
|
|
641
641
|
if (typeof document !== "undefined") return false;
|
|
@@ -22220,6 +22220,14 @@ function compareBytes(a, b) {
|
|
|
22220
22220
|
return a.length - b.length;
|
|
22221
22221
|
}
|
|
22222
22222
|
|
|
22223
|
+
// src/rest/market-id.ts
|
|
22224
|
+
var MARKET_ID_HEX_RE = /^(0[xX])?([0-9a-fA-F]{2})+$/;
|
|
22225
|
+
function marketIdToBase64(marketId) {
|
|
22226
|
+
if (marketId instanceof MarketId) return marketId.toBase64();
|
|
22227
|
+
if (typeof marketId !== "string") return bytesToBase64(marketId);
|
|
22228
|
+
return MARKET_ID_HEX_RE.test(marketId) ? MarketId.fromHex(marketId).toBase64() : marketId;
|
|
22229
|
+
}
|
|
22230
|
+
|
|
22223
22231
|
// src/proto/gen/ault/clob/v1/query.ts
|
|
22224
22232
|
var import_wire45 = require("@bufbuild/protobuf/wire");
|
|
22225
22233
|
|
|
@@ -23210,9 +23218,6 @@ function normalizeOrderId(orderId) {
|
|
|
23210
23218
|
if (typeof orderId !== "string") return bytesToBase64(orderId);
|
|
23211
23219
|
return ORDER_ID_HEX_RE.test(orderId) ? OrderId.fromHex(orderId).toBase64() : orderId;
|
|
23212
23220
|
}
|
|
23213
|
-
function normalizeMarketId(marketId) {
|
|
23214
|
-
return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
|
|
23215
|
-
}
|
|
23216
23221
|
var LIMIT_TYPE_URL = "/ault.clob.v1.MsgPlaceLimitOrder";
|
|
23217
23222
|
var MARKET_TYPE_URL = "/ault.clob.v1.MsgPlaceMarketOrder";
|
|
23218
23223
|
var OPTION_CODECS = {
|
|
@@ -23304,7 +23309,7 @@ function createClobApi(context) {
|
|
|
23304
23309
|
},
|
|
23305
23310
|
async getOrders(params = {}) {
|
|
23306
23311
|
const query = buildQuery({
|
|
23307
|
-
market_id: params.marketId ?
|
|
23312
|
+
market_id: params.marketId ? marketIdToBase64(params.marketId) : void 0,
|
|
23308
23313
|
...params.pagination
|
|
23309
23314
|
});
|
|
23310
23315
|
return fetchProtoJson(
|
|
@@ -25731,10 +25736,6 @@ function isSet46(value) {
|
|
|
25731
25736
|
}
|
|
25732
25737
|
|
|
25733
25738
|
// src/rest/margin.ts
|
|
25734
|
-
function marketIdParam(marketId) {
|
|
25735
|
-
if (marketId instanceof MarketId) return marketId.toBase64();
|
|
25736
|
-
return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
|
|
25737
|
-
}
|
|
25738
25739
|
var enc2 = encodeURIComponent;
|
|
25739
25740
|
function createMarginApi(context) {
|
|
25740
25741
|
return {
|
|
@@ -25751,7 +25752,7 @@ function createMarginApi(context) {
|
|
|
25751
25752
|
},
|
|
25752
25753
|
async getMarginAccount(owner, marketId) {
|
|
25753
25754
|
const query = buildQuery({
|
|
25754
|
-
market_id: marketId === void 0 ? void 0 :
|
|
25755
|
+
market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
|
|
25755
25756
|
});
|
|
25756
25757
|
return fetchProtoJson(
|
|
25757
25758
|
context,
|
|
@@ -26141,9 +26142,6 @@ function isSet48(value) {
|
|
|
26141
26142
|
}
|
|
26142
26143
|
|
|
26143
26144
|
// src/rest/market.ts
|
|
26144
|
-
function normalizeMarketId2(marketId) {
|
|
26145
|
-
return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
|
|
26146
|
-
}
|
|
26147
26145
|
function createMarketApi(context) {
|
|
26148
26146
|
return {
|
|
26149
26147
|
async getParams() {
|
|
@@ -26156,7 +26154,7 @@ function createMarketApi(context) {
|
|
|
26156
26154
|
async getMarket(marketId) {
|
|
26157
26155
|
return fetchProtoJson(
|
|
26158
26156
|
context,
|
|
26159
|
-
`/ault/market/v1/markets/${encodeURIComponent(
|
|
26157
|
+
`/ault/market/v1/markets/${encodeURIComponent(marketIdToBase64(marketId))}`,
|
|
26160
26158
|
QueryMarketResponse
|
|
26161
26159
|
);
|
|
26162
26160
|
}
|
|
@@ -29371,10 +29369,6 @@ function isSet53(value) {
|
|
|
29371
29369
|
}
|
|
29372
29370
|
|
|
29373
29371
|
// src/rest/perpetual.ts
|
|
29374
|
-
function normalizeMarketId3(marketId) {
|
|
29375
|
-
if (marketId instanceof MarketId) return marketId.toBase64();
|
|
29376
|
-
return typeof marketId === "string" ? marketId : bytesToBase64(marketId);
|
|
29377
|
-
}
|
|
29378
29372
|
function createPerpetualApi(context) {
|
|
29379
29373
|
return {
|
|
29380
29374
|
async getParams() {
|
|
@@ -29389,7 +29383,7 @@ function createPerpetualApi(context) {
|
|
|
29389
29383
|
},
|
|
29390
29384
|
async getAccount(owner, marketId) {
|
|
29391
29385
|
const query = buildQuery({
|
|
29392
|
-
market_id: marketId === void 0 ? void 0 :
|
|
29386
|
+
market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
|
|
29393
29387
|
});
|
|
29394
29388
|
return fetchProtoJson(
|
|
29395
29389
|
context,
|
|
@@ -29398,7 +29392,7 @@ function createPerpetualApi(context) {
|
|
|
29398
29392
|
);
|
|
29399
29393
|
},
|
|
29400
29394
|
async getPosition(owner, marketId, cross) {
|
|
29401
|
-
const query = buildQuery({ market_id:
|
|
29395
|
+
const query = buildQuery({ market_id: marketIdToBase64(marketId), cross });
|
|
29402
29396
|
return fetchProtoJson(
|
|
29403
29397
|
context,
|
|
29404
29398
|
`/ault/perpetual/v1/position/${encodeURIComponent(normalizeAddress(owner))}${query}`,
|
|
@@ -29407,7 +29401,7 @@ function createPerpetualApi(context) {
|
|
|
29407
29401
|
},
|
|
29408
29402
|
async getAccountRisk(owner, marketId) {
|
|
29409
29403
|
const query = buildQuery({
|
|
29410
|
-
market_id: marketId === void 0 ? void 0 :
|
|
29404
|
+
market_id: marketId === void 0 ? void 0 : marketIdToBase64(marketId)
|
|
29411
29405
|
});
|
|
29412
29406
|
return fetchProtoJson(
|
|
29413
29407
|
context,
|
|
@@ -29416,11 +29410,11 @@ function createPerpetualApi(context) {
|
|
|
29416
29410
|
);
|
|
29417
29411
|
},
|
|
29418
29412
|
async getFunding(marketId) {
|
|
29419
|
-
const query = buildQuery({ market_id:
|
|
29413
|
+
const query = buildQuery({ market_id: marketIdToBase64(marketId) });
|
|
29420
29414
|
return fetchProtoJson(context, `/ault/perpetual/v1/funding${query}`, QueryFundingResponse);
|
|
29421
29415
|
},
|
|
29422
29416
|
async getPrices(marketId) {
|
|
29423
|
-
const id = encodeURIComponent(
|
|
29417
|
+
const id = encodeURIComponent(marketIdToBase64(marketId));
|
|
29424
29418
|
return fetchProtoJson(
|
|
29425
29419
|
context,
|
|
29426
29420
|
`/ault/perpetual/v1/markets/${id}/prices`,
|
|
@@ -29428,7 +29422,7 @@ function createPerpetualApi(context) {
|
|
|
29428
29422
|
);
|
|
29429
29423
|
},
|
|
29430
29424
|
async getImpactPrices(marketId) {
|
|
29431
|
-
const id = encodeURIComponent(
|
|
29425
|
+
const id = encodeURIComponent(marketIdToBase64(marketId));
|
|
29432
29426
|
return fetchProtoJson(
|
|
29433
29427
|
context,
|
|
29434
29428
|
`/ault/perpetual/v1/markets/${id}/impact_prices`,
|
|
@@ -30162,7 +30156,7 @@ function createRewardApi(context) {
|
|
|
30162
30156
|
);
|
|
30163
30157
|
},
|
|
30164
30158
|
async getDeployerShare(marketId) {
|
|
30165
|
-
const encoded =
|
|
30159
|
+
const encoded = marketIdToBase64(marketId);
|
|
30166
30160
|
return fetchProtoJson(
|
|
30167
30161
|
context,
|
|
30168
30162
|
`/ault/reward/v1/deployer_share/${encodeURIComponent(encoded)}`,
|