@ar.io/sdk 3.22.0 → 3.23.0-alpha.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.
@@ -278,6 +278,11 @@ export declare const optionMap: {
278
278
  description: string;
279
279
  type: string;
280
280
  };
281
+ removeControllers: {
282
+ alias: string;
283
+ description: string;
284
+ type: string;
285
+ };
281
286
  lockLengthMs: {
282
287
  alias: string;
283
288
  description: string;
@@ -238,14 +238,20 @@ export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite
238
238
  });
239
239
  /**
240
240
  * @param target @type {string} The address of the account you want to transfer the ANT to.
241
+ * @param removeControllers @type {boolean} Whether to remove the controllers of the ANT. Default is true.
242
+ * @example
243
+ * ```ts
244
+ * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk", removeControllers: false }); // will not remove the controllers of the ANT and just transfer ownership
245
+ * ```
241
246
  * @returns {Promise<AoMessageResult>} The result of the interaction.
242
247
  * @example
243
248
  * ```ts
244
249
  * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" });
245
250
  * ```
246
251
  */
247
- transfer({ target }: {
252
+ transfer({ target, removeControllers, }: {
248
253
  target: string;
254
+ removeControllers?: boolean;
249
255
  }, options?: WriteOptions): Promise<AoMessageResult>;
250
256
  /**
251
257
  * @param controller @type {string} The address of the account you want to set as a controller.
@@ -20,5 +20,6 @@ export * from './ant.js';
20
20
  export * from './ant-registry.js';
21
21
  export * from './ant-versions.js';
22
22
  export * from './faucet.js';
23
+ export * from './marketplace.js';
23
24
  export * from './io.js';
24
25
  export * from './contracts/ao-process.js';
@@ -0,0 +1,434 @@
1
+ /**
2
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { AOProcess, AoSigner, Logger } from '../node/index.js';
17
+ import { AoMessageResult, WalletAddress } from '../types/common.js';
18
+ import { AoARIOWrite, PaginationParams, PaginationResult } from '../types/io.js';
19
+ /**
20
+ * User-provided order parameters for intent-based order creation
21
+ * These are the user-configurable fields when creating an order via the intent workflow
22
+ */
23
+ export interface MarketplaceOrderIntentParams {
24
+ orderType?: 'fixed' | 'dutch' | 'english';
25
+ quantity?: string;
26
+ price?: string;
27
+ expirationTime?: string;
28
+ minimumPrice?: string;
29
+ decreaseInterval?: string;
30
+ }
31
+ /**
32
+ * Intent structure - matches Lua Intent type
33
+ */
34
+ export interface MarketplaceIntent {
35
+ intentId: string;
36
+ initiator: string;
37
+ action: string;
38
+ status: 'pending' | 'active' | 'settling' | 'completed' | 'resolved' | 'failed';
39
+ createdAt: number;
40
+ ttl?: number;
41
+ resolvedAt?: number;
42
+ completedAt?: number;
43
+ failureReason?: string;
44
+ orderParams: MarketplaceOrderIntentParams;
45
+ antProcessId: string;
46
+ }
47
+ /**
48
+ * Fee information structure for calculating order costs
49
+ */
50
+ export interface MarketplaceFeeInfo {
51
+ listingFeePerHour: string;
52
+ saleTaxNumerator: number;
53
+ saleTaxDenominator: number;
54
+ }
55
+ /**
56
+ * Intent statistics structure
57
+ */
58
+ export interface MarketplaceIntentStats {
59
+ total: number;
60
+ byStatus: Record<string, number>;
61
+ byType: Record<string, number>;
62
+ byAction: Record<string, number>;
63
+ }
64
+ /**
65
+ * Activity information structure
66
+ */
67
+ export interface MarketplaceActivityInfo {
68
+ totalOrders: number;
69
+ activeOrders: number;
70
+ readyForSettlement: number;
71
+ executedOrders: number;
72
+ cancelledOrders: number;
73
+ expiredOrders: number;
74
+ listedOrders: number;
75
+ }
76
+ /**
77
+ * marketplace information structure
78
+ */
79
+ export interface MarketplaceInfo {
80
+ totalPairs: number;
81
+ accruedFees: string;
82
+ arioTokenProcess: string;
83
+ }
84
+ /**
85
+ * Info response structure from the marketplace
86
+ */
87
+ export interface InfoResponse {
88
+ name: string;
89
+ processId: string;
90
+ activity: MarketplaceActivityInfo;
91
+ intents: MarketplaceIntentStats;
92
+ ucm: MarketplaceInfo;
93
+ whitelistedModules: string[];
94
+ fees: MarketplaceFeeInfo;
95
+ }
96
+ /**
97
+ * Parameters for creating an intent (Create-Order action is assumed)
98
+ */
99
+ export interface CreateIntentParams {
100
+ antId: string;
101
+ orderType: string;
102
+ quantity: string;
103
+ price: string;
104
+ expirationTime: string;
105
+ minimumPrice?: string;
106
+ decreaseInterval?: string;
107
+ }
108
+ /**
109
+ * Parameters for paginated intent queries
110
+ */
111
+ export interface GetPaginatedIntentsParams {
112
+ cursor?: string;
113
+ limit?: number;
114
+ sortBy?: string;
115
+ sortOrder?: 'asc' | 'desc';
116
+ filters?: Record<string, string>;
117
+ }
118
+ /**
119
+ * Parameters for creating an order using internal ARIO balance
120
+ */
121
+ export interface CreateOrderParams {
122
+ swapToken: string;
123
+ quantity: string;
124
+ orderType?: 'fixed' | 'dutch' | 'english';
125
+ price?: string;
126
+ expirationTime?: string;
127
+ minimumPrice?: string;
128
+ decreaseInterval?: string;
129
+ transferDenomination?: string;
130
+ }
131
+ /**
132
+ * Parameters for getting orders with flexible selectors
133
+ */
134
+ export interface GetOrdersParams extends GetPaginatedIntentsParams {
135
+ status?: 'all' | 'listed' | 'completed' | 'active' | 'ready-for-settlement' | 'executed' | 'cancelled' | 'expired';
136
+ ids?: string[];
137
+ dominantToken?: string;
138
+ swapToken?: string;
139
+ }
140
+ /**
141
+ * Individual order structure returned from Get-Orders and Get-Order handlers
142
+ */
143
+ export interface Order {
144
+ id: string;
145
+ creator: string;
146
+ quantity: string;
147
+ originalQuantity: string;
148
+ token: string;
149
+ dominantToken: string;
150
+ swapToken: string;
151
+ dateCreated: number;
152
+ price?: string;
153
+ expirationTime?: number;
154
+ orderType: 'fixed' | 'dutch' | 'english';
155
+ status: 'active' | 'executed' | 'cancelled' | 'ready-for-settlement' | 'expired';
156
+ minimumPrice?: string;
157
+ decreaseInterval?: string;
158
+ decreaseStep?: string;
159
+ sender?: string;
160
+ receiver?: string;
161
+ endedAt?: number;
162
+ bids?: Record<string, boolean>;
163
+ }
164
+ export interface MarketplaceBalance {
165
+ address: WalletAddress;
166
+ balance: string;
167
+ lockedBalance: string;
168
+ totalBalance: string;
169
+ orders: Record<string, string>;
170
+ }
171
+ export interface AoArNSMarketplaceRead {
172
+ getInfo(): Promise<InfoResponse>;
173
+ getPaginatedIntents(params: GetPaginatedIntentsParams): Promise<PaginationResult<MarketplaceIntent>>;
174
+ getIntent(intentId: string): Promise<MarketplaceIntent>;
175
+ getIntentByANTId(antId: string): Promise<MarketplaceIntent>;
176
+ getPaginatedOrders(params: GetOrdersParams): Promise<PaginationResult<Order>>;
177
+ getOrder(orderId: string): Promise<Order>;
178
+ getOrderByANTId(antId: string): Promise<Order>;
179
+ getPaginatedMarketplaceBalances(params: PaginationParams<MarketplaceBalance>): Promise<PaginationResult<MarketplaceBalance>>;
180
+ getMarketplaceBalance({ address, }: {
181
+ address: WalletAddress;
182
+ }): Promise<MarketplaceBalance>;
183
+ /**
184
+ * Get all user assets including intents, orders, balances, and ANT IDs
185
+ * @param params - Parameters including address and ARIO process ID
186
+ * @returns User assets including intents, orders, balances, and ANT IDs
187
+ */
188
+ getUserAssets({ address, arioProcessId, }: {
189
+ address: WalletAddress;
190
+ arioProcessId: string;
191
+ }): Promise<{
192
+ intents: MarketplaceIntent[];
193
+ orders: Order[];
194
+ balances: MarketplaceBalance;
195
+ antIds: string[];
196
+ }>;
197
+ }
198
+ export interface AoArNSMarketplaceWrite {
199
+ createIntent(params: CreateIntentParams): Promise<AoMessageResult<MarketplaceIntent>>;
200
+ cancelOrder(orderId: string): Promise<AoMessageResult>;
201
+ settleAuction(params: {
202
+ orderId: string;
203
+ dominantToken?: string;
204
+ swapToken?: string;
205
+ }): Promise<AoMessageResult>;
206
+ depositArIO(params: {
207
+ amount: string;
208
+ }): Promise<AoMessageResult>;
209
+ withdrawArIO(params: {
210
+ amount: string;
211
+ }): Promise<AoMessageResult>;
212
+ /**
213
+ * Push ANT intent resolution to the marketplace
214
+ * @param intentId - The intent ID to push resolution for
215
+ * @returns Message result
216
+ */
217
+ pushANTIntentResolution(intentId: string): Promise<AoMessageResult>;
218
+ /**
219
+ * List a name for sale on the marketplace
220
+ * @param params - Parameters including name, expiration time, price, type, wallet address, and optional auction parameters
221
+ * @returns Result containing intent, order, ANT transfer result, and any error
222
+ */
223
+ listNameForSale({ name, expirationTime, price, type, walletAddress, minimumPrice, decreaseInterval, }: {
224
+ name: string;
225
+ expirationTime: number;
226
+ price: string;
227
+ type: 'fixed' | 'dutch' | 'english';
228
+ walletAddress: WalletAddress;
229
+ minimumPrice?: string;
230
+ decreaseInterval?: string;
231
+ }): Promise<{
232
+ intent: MarketplaceIntent;
233
+ order: Order | null;
234
+ antTransferResult: AoMessageResult<Record<string, string | number | boolean | null>> | null;
235
+ error: Error | null;
236
+ }>;
237
+ /**
238
+ * Create an order using internal ARIO balance
239
+ * @param params - Order creation parameters
240
+ * @returns Message result with the created order
241
+ */
242
+ createOrder(params: CreateOrderParams): Promise<AoMessageResult<Order>>;
243
+ /**
244
+ * Buy a fixed price ANT
245
+ * @param params - Parameters including ANT ID
246
+ * @returns Message result with the order
247
+ */
248
+ buyFixedPriceANT(params: {
249
+ antId: string;
250
+ }): Promise<AoMessageResult<Order>>;
251
+ /**
252
+ * Buy a Dutch auction ANT
253
+ * @param params - Parameters including ANT ID
254
+ * @returns Message result with the order
255
+ */
256
+ buyDutchAuctionANT(params: {
257
+ antId: string;
258
+ }): Promise<AoMessageResult<Order>>;
259
+ /**
260
+ * Place a bid on an English auction
261
+ * @param params - Parameters including ANT ID and bid amount
262
+ * @returns Message result
263
+ */
264
+ bidOnANTEnglishAuction(params: {
265
+ antId: string;
266
+ bidAmount: string;
267
+ }): Promise<AoMessageResult>;
268
+ /**
269
+ * Settle an expired English auction
270
+ * @param params - Parameters including ANT ID
271
+ * @returns Message result
272
+ */
273
+ settleANTEnglishAuction(params: {
274
+ antId: string;
275
+ }): Promise<AoMessageResult>;
276
+ }
277
+ export declare class ArNSMarketplaceRead implements AoArNSMarketplaceRead {
278
+ protected process: AOProcess;
279
+ protected logger: Logger;
280
+ constructor({ process, logger, }: {
281
+ process: AOProcess;
282
+ logger?: Logger;
283
+ });
284
+ getInfo(): Promise<InfoResponse>;
285
+ getPaginatedIntents({ cursor, limit, sortBy, sortOrder, filters, }?: GetPaginatedIntentsParams): Promise<PaginationResult<MarketplaceIntent>>;
286
+ getIntent(intentId: string): Promise<MarketplaceIntent>;
287
+ getIntentByANTId(antId: string): Promise<MarketplaceIntent>;
288
+ /**
289
+ * Get orders with flexible selectors
290
+ * @param params - Parameters for filtering and pagination
291
+ * @returns Orders matching the criteria
292
+ */
293
+ getPaginatedOrders(params?: GetOrdersParams): Promise<PaginationResult<Order>>;
294
+ /**
295
+ * Get a single order by ID
296
+ * @param orderId - The order ID to fetch
297
+ * @returns The order if found
298
+ */
299
+ getOrder(orderId: string): Promise<Order>;
300
+ getOrderByANTId(antId: string): Promise<Order>;
301
+ getPaginatedMarketplaceBalances(params: PaginationParams<MarketplaceBalance>): Promise<PaginationResult<MarketplaceBalance>>;
302
+ /**
303
+ * Get ARIO balance for an address in the marketplace
304
+ */
305
+ getMarketplaceBalance({ address, }: {
306
+ address: WalletAddress;
307
+ }): Promise<MarketplaceBalance>;
308
+ getUserAssets({ address, arioProcessId, }: {
309
+ address: WalletAddress;
310
+ arioProcessId: string;
311
+ }): Promise<{
312
+ intents: MarketplaceIntent[];
313
+ orders: Order[];
314
+ balances: MarketplaceBalance;
315
+ antIds: string[];
316
+ }>;
317
+ }
318
+ export declare class ArNSMarketplaceWrite extends ArNSMarketplaceRead implements AoArNSMarketplaceWrite {
319
+ protected process: AOProcess;
320
+ protected signer: AoSigner;
321
+ protected ario: AoARIOWrite;
322
+ constructor({ process, signer, ario, logger, }: {
323
+ process: AOProcess;
324
+ signer: AoSigner;
325
+ ario: AoARIOWrite;
326
+ logger?: Logger;
327
+ });
328
+ /**
329
+ * Deposit ARIO to the marketplace (simulates Credit-Notice from ARIO token process)
330
+ * Returns the message ID for verification
331
+ */
332
+ depositArIO(params: {
333
+ amount: string;
334
+ }): Promise<AoMessageResult>;
335
+ /**
336
+ * Withdraw ARIO from the marketplace back to user
337
+ */
338
+ withdrawArIO(params: {
339
+ amount: string;
340
+ }): Promise<AoMessageResult>;
341
+ createIntent({ antId, orderType, quantity, price, expirationTime, minimumPrice, decreaseInterval, }: CreateIntentParams): Promise<AoMessageResult<MarketplaceIntent>>;
342
+ pushANTIntentResolution(intentId: string): Promise<AoMessageResult>;
343
+ settleAuction(params: {
344
+ orderId: string;
345
+ dominantToken?: string;
346
+ swapToken?: string;
347
+ }): Promise<AoMessageResult>;
348
+ listNameForSale({ name, expirationTime, price, type, walletAddress, minimumPrice, decreaseInterval, }: {
349
+ name: string;
350
+ expirationTime: number;
351
+ price: string;
352
+ type: 'fixed' | 'dutch' | 'english';
353
+ walletAddress: WalletAddress;
354
+ minimumPrice?: string;
355
+ decreaseInterval?: string;
356
+ }): Promise<{
357
+ intent: MarketplaceIntent;
358
+ order: Order | null;
359
+ antTransferResult: AoMessageResult<Record<string, string | number | boolean | null>> | null;
360
+ error: Error | null;
361
+ }>;
362
+ cancelOrder(orderId: string): Promise<AoMessageResult>;
363
+ createOrder({ swapToken, quantity, orderType, price, expirationTime, minimumPrice, decreaseInterval, transferDenomination, }: CreateOrderParams): Promise<AoMessageResult<Order>>;
364
+ buyFixedPriceANT(params: {
365
+ antId: string;
366
+ }): Promise<AoMessageResult<Order>>;
367
+ buyDutchAuctionANT(params: {
368
+ antId: string;
369
+ }): Promise<AoMessageResult<Order>>;
370
+ /**
371
+ * Place a bid on an English auction
372
+ * Note: This requires you to have sufficient ARIO balance in the marketplace
373
+ */
374
+ bidOnANTEnglishAuction(params: {
375
+ antId: string;
376
+ bidAmount: string;
377
+ }): Promise<AoMessageResult>;
378
+ /**
379
+ * Settle an expired English auction
380
+ * Can be called by anyone after the auction expires
381
+ * The highest bidder wins the ANT
382
+ */
383
+ settleANTEnglishAuction(params: {
384
+ antId: string;
385
+ }): Promise<AoMessageResult>;
386
+ }
387
+ /**
388
+ * Calculates the listing fee for an order based on the end timestamp.
389
+ * The fee is calculated by rounding up the hours until the end timestamp to the nearest hour.
390
+ *
391
+ * @param params - Parameters for calculating the listing fee
392
+ * @param params.listingFeePerHour - The listing fee per hour in mARIO (as a string)
393
+ * @param params.endTimestamp - Unix timestamp when the order expires
394
+ * @returns The listing fee in mARIO as a BigInt
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * const info = await marketplace.getInfo();
399
+ * const endTimestamp = Date.now() + 24 * 60 * 60 * 1000; // 24 hours from now
400
+ * const listingFee = calculateListingFee({
401
+ * listingFeePerHour: info.fees.listingFeePerHour,
402
+ * endTimestamp,
403
+ * });
404
+ * ```
405
+ */
406
+ export declare function calculateListingFee({ listingFeePerHour, endTimestamp, }: {
407
+ listingFeePerHour: string;
408
+ endTimestamp: number;
409
+ }): bigint;
410
+ /**
411
+ * Calculates the sale tax for an order based on the sale amount.
412
+ *
413
+ * @param params - Parameters for calculating the sale tax
414
+ * @param params.saleAmount - The sale amount in mARIO (as a string or number)
415
+ * @param params.saleTaxNumerator - The numerator for sale tax calculation
416
+ * @param params.saleTaxDenominator - The denominator for sale tax calculation
417
+ * @returns The sale tax in mARIO as a BigInt
418
+ *
419
+ * @example
420
+ * ```typescript
421
+ * const info = await marketplace.getInfo();
422
+ * const saleAmount = 100000000000; // 100 ARIO in mARIO
423
+ * const tax = calculateSaleTax({
424
+ * saleAmount,
425
+ * saleTaxNumerator: info.fees.saleTaxNumerator,
426
+ * saleTaxDenominator: info.fees.saleTaxDenominator,
427
+ * });
428
+ * ```
429
+ */
430
+ export declare function calculateSaleTax({ saleAmount, saleTaxNumerator, saleTaxDenominator, }: {
431
+ saleAmount: string | number;
432
+ saleTaxNumerator: number;
433
+ saleTaxDenominator: number;
434
+ }): bigint;
@@ -22,6 +22,7 @@ export declare const ARIO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddIC
22
22
  export declare const ARIO_MAINNET_PROCESS_ID = "qNvAoz0TgcH7DMg8BCVn8jF32QH5L6T29VjHxhHqqGE";
23
23
  export declare const ANT_REGISTRY_TESTNET_ID = "RR0vheYqtsKuJCWh6xj0beE35tjaEug5cejMw9n2aa8";
24
24
  export declare const ANT_REGISTRY_ID = "i_le_yKKPVstLTDSmkHRqf-wYphMnwB9OhleiTgMkWc";
25
+ export declare const MARKETPLACE_CONTRACT_ID = "wPh88ziUF4meLpHfffmgdA6IFtzmXHgdeg-epzBjkao";
25
26
  export declare const MARIO_PER_ARIO = 1000000;
26
27
  /**
27
28
  * @deprecated - use ANT.versions.getLatestANTVersion() to get latest ANT module
@@ -362,6 +362,7 @@ export interface AoANTRead {
362
362
  export interface AoANTWrite extends AoANTRead {
363
363
  transfer: AoWriteAction<{
364
364
  target: WalletAddress;
365
+ removeControllers?: boolean;
365
366
  }>;
366
367
  addController: AoWriteAction<{
367
368
  controller: WalletAddress;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.22.0-alpha.7";
16
+ export declare const version = "3.22.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.22.0",
3
+ "version": "3.23.0-alpha.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"
@@ -68,7 +68,7 @@
68
68
  "test:cjs": "yarn build:cjs && yarn link && cd ./tests/e2e/cjs && yarn && yarn test",
69
69
  "test:esm": "yarn build:esm && yarn link && cd ./tests/e2e/esm && yarn && yarn test",
70
70
  "test:web": "yarn build:esm && yarn link && cd ./tests/e2e/web && yarn && yarn test",
71
- "test:unit": "c8 node --import=./register.mjs --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
71
+ "test:unit": "c8 tsx --test --test-reporter=spec --enable-source-maps --trace-warnings 'src/**/*.test.ts'",
72
72
  "test:link": "yarn build && yarn link",
73
73
  "test:e2e": "yarn test:cjs && yarn test:esm && yarn test:web",
74
74
  "test:integration": "yarn build:esm && yarn link && cd ./tests/integration && yarn && yarn test",
@@ -96,11 +96,10 @@
96
96
  "@typescript-eslint/eslint-plugin": "^5.62.0",
97
97
  "@typescript-eslint/parser": "^6.4.0",
98
98
  "arconnect": "^1.0.3",
99
- "axios": "^1.13.2",
100
99
  "c8": "^10.1.3",
101
100
  "dotenv": "^16.4.5",
102
101
  "dotenv-cli": "^7.4.2",
103
- "esbuild": "^0.27.0",
102
+ "esbuild": "^0.27.1",
104
103
  "esbuild-plugin-polyfill-node": "^0.3.0",
105
104
  "eslint": "^8.47.0",
106
105
  "eslint-config-prettier": "^9.0.0",
@@ -122,12 +121,14 @@
122
121
  "sinon": "^15.2.0",
123
122
  "testcontainers": "^10.13.1",
124
123
  "ts-node": "^10.9.2",
124
+ "tsx": "^4.19.2",
125
125
  "typescript": "^5.1.6"
126
126
  },
127
127
  "dependencies": {
128
128
  "@dha-team/arbundles": "^1.0.1",
129
129
  "@permaweb/aoconnect": "0.0.68",
130
130
  "arweave": "1.15.5",
131
+ "axios": "^1.13.2",
131
132
  "commander": "^12.1.0",
132
133
  "eventemitter3": "^5.0.1",
133
134
  "prompts": "^2.4.2"