@ar.io/sdk 3.1.0-alpha.9 → 3.1.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.
@@ -37,6 +37,7 @@ class ARIO {
37
37
  exports.ARIO = ARIO;
38
38
  class ARIOReadable {
39
39
  process;
40
+ epochSettings;
40
41
  constructor(config) {
41
42
  if (!config) {
42
43
  this.process = new ao_process_js_1.AOProcess({
@@ -65,35 +66,32 @@ class ARIOReadable {
65
66
  tags: [{ name: 'Action', value: 'Total-Token-Supply' }],
66
67
  });
67
68
  }
68
- async getEpochSettings(params) {
69
- const allTags = [
70
- { name: 'Action', value: 'Epoch-Settings' },
71
- {
72
- name: 'Timestamp',
73
- value: params?.timestamp?.toString() ??
74
- Date.now().toString(),
75
- },
76
- {
77
- name: 'Epoch-Index',
78
- value: params?.epochIndex?.toString(),
79
- },
80
- ];
81
- return this.process.read({
82
- tags: (0, arweave_js_1.pruneTags)(allTags),
83
- });
69
+ async computeEpochIndexForTimestamp(timestamp) {
70
+ const epochSettings = await this.getEpochSettings();
71
+ const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
72
+ const epochLengthMs = epochSettings.durationMs;
73
+ return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
74
+ }
75
+ async computeEpochIndex(params) {
76
+ const epochIndex = params?.epochIndex;
77
+ if (epochIndex !== undefined) {
78
+ return epochIndex.toString();
79
+ }
80
+ const timestamp = params?.timestamp;
81
+ if (timestamp !== undefined) {
82
+ return (await this.computeEpochIndexForTimestamp(timestamp)).toString();
83
+ }
84
+ return undefined;
85
+ }
86
+ async getEpochSettings() {
87
+ return (this.epochSettings ??= await this.process.read({
88
+ tags: [{ name: 'Action', value: 'Epoch-Settings' }],
89
+ }));
84
90
  }
85
91
  async getEpoch(epoch) {
86
92
  const allTags = [
87
93
  { name: 'Action', value: 'Epoch' },
88
- {
89
- name: 'Timestamp',
90
- value: epoch?.timestamp?.toString() ??
91
- Date.now().toString(),
92
- },
93
- {
94
- name: 'Epoch-Index',
95
- value: epoch?.epochIndex?.toString(),
96
- },
94
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
97
95
  ];
98
96
  return this.process.read({
99
97
  tags: (0, arweave_js_1.pruneTags)(allTags),
@@ -206,15 +204,7 @@ class ARIOReadable {
206
204
  async getPrescribedObservers(epoch) {
207
205
  const allTags = [
208
206
  { name: 'Action', value: 'Epoch-Prescribed-Observers' },
209
- {
210
- name: 'Timestamp',
211
- value: epoch?.timestamp?.toString() ??
212
- Date.now().toString(),
213
- },
214
- {
215
- name: 'Epoch-Index',
216
- value: epoch?.epochIndex?.toString(),
217
- },
207
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
218
208
  ];
219
209
  return this.process.read({
220
210
  tags: (0, arweave_js_1.pruneTags)(allTags),
@@ -223,15 +213,7 @@ class ARIOReadable {
223
213
  async getPrescribedNames(epoch) {
224
214
  const allTags = [
225
215
  { name: 'Action', value: 'Epoch-Prescribed-Names' },
226
- {
227
- name: 'Timestamp',
228
- value: epoch?.timestamp?.toString() ??
229
- Date.now().toString(),
230
- },
231
- {
232
- name: 'Epoch-Index',
233
- value: epoch?.epochIndex?.toString(),
234
- },
216
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
235
217
  ];
236
218
  return this.process.read({
237
219
  tags: (0, arweave_js_1.pruneTags)(allTags),
@@ -240,15 +222,7 @@ class ARIOReadable {
240
222
  async getObservations(epoch) {
241
223
  const allTags = [
242
224
  { name: 'Action', value: 'Epoch-Observations' },
243
- {
244
- name: 'Timestamp',
245
- value: epoch?.timestamp?.toString() ??
246
- Date.now().toString(),
247
- },
248
- {
249
- name: 'Epoch-Index',
250
- value: epoch?.epochIndex?.toString(),
251
- },
225
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
252
226
  ];
253
227
  return this.process.read({
254
228
  tags: (0, arweave_js_1.pruneTags)(allTags),
@@ -257,15 +231,7 @@ class ARIOReadable {
257
231
  async getDistributions(epoch) {
258
232
  const allTags = [
259
233
  { name: 'Action', value: 'Epoch-Distributions' },
260
- {
261
- name: 'Timestamp',
262
- value: epoch?.timestamp?.toString() ??
263
- Date.now().toString(),
264
- },
265
- {
266
- name: 'Epoch-Index',
267
- value: epoch?.epochIndex?.toString(),
268
- },
234
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
269
235
  ];
270
236
  return this.process.read({
271
237
  tags: (0, arweave_js_1.pruneTags)(allTags),
@@ -17,4 +17,4 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.version = void 0;
19
19
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
20
- exports.version = '3.1.0-alpha.9';
20
+ exports.version = '3.1.0';
@@ -33,6 +33,7 @@ export class ARIO {
33
33
  }
34
34
  export class ARIOReadable {
35
35
  process;
36
+ epochSettings;
36
37
  constructor(config) {
37
38
  if (!config) {
38
39
  this.process = new AOProcess({
@@ -61,35 +62,32 @@ export class ARIOReadable {
61
62
  tags: [{ name: 'Action', value: 'Total-Token-Supply' }],
62
63
  });
63
64
  }
64
- async getEpochSettings(params) {
65
- const allTags = [
66
- { name: 'Action', value: 'Epoch-Settings' },
67
- {
68
- name: 'Timestamp',
69
- value: params?.timestamp?.toString() ??
70
- Date.now().toString(),
71
- },
72
- {
73
- name: 'Epoch-Index',
74
- value: params?.epochIndex?.toString(),
75
- },
76
- ];
77
- return this.process.read({
78
- tags: pruneTags(allTags),
79
- });
65
+ async computeEpochIndexForTimestamp(timestamp) {
66
+ const epochSettings = await this.getEpochSettings();
67
+ const epochZeroStartTimestamp = epochSettings.epochZeroStartTimestamp;
68
+ const epochLengthMs = epochSettings.durationMs;
69
+ return Math.floor((timestamp - epochZeroStartTimestamp) / epochLengthMs);
70
+ }
71
+ async computeEpochIndex(params) {
72
+ const epochIndex = params?.epochIndex;
73
+ if (epochIndex !== undefined) {
74
+ return epochIndex.toString();
75
+ }
76
+ const timestamp = params?.timestamp;
77
+ if (timestamp !== undefined) {
78
+ return (await this.computeEpochIndexForTimestamp(timestamp)).toString();
79
+ }
80
+ return undefined;
81
+ }
82
+ async getEpochSettings() {
83
+ return (this.epochSettings ??= await this.process.read({
84
+ tags: [{ name: 'Action', value: 'Epoch-Settings' }],
85
+ }));
80
86
  }
81
87
  async getEpoch(epoch) {
82
88
  const allTags = [
83
89
  { name: 'Action', value: 'Epoch' },
84
- {
85
- name: 'Timestamp',
86
- value: epoch?.timestamp?.toString() ??
87
- Date.now().toString(),
88
- },
89
- {
90
- name: 'Epoch-Index',
91
- value: epoch?.epochIndex?.toString(),
92
- },
90
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
93
91
  ];
94
92
  return this.process.read({
95
93
  tags: pruneTags(allTags),
@@ -202,15 +200,7 @@ export class ARIOReadable {
202
200
  async getPrescribedObservers(epoch) {
203
201
  const allTags = [
204
202
  { name: 'Action', value: 'Epoch-Prescribed-Observers' },
205
- {
206
- name: 'Timestamp',
207
- value: epoch?.timestamp?.toString() ??
208
- Date.now().toString(),
209
- },
210
- {
211
- name: 'Epoch-Index',
212
- value: epoch?.epochIndex?.toString(),
213
- },
203
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
214
204
  ];
215
205
  return this.process.read({
216
206
  tags: pruneTags(allTags),
@@ -219,15 +209,7 @@ export class ARIOReadable {
219
209
  async getPrescribedNames(epoch) {
220
210
  const allTags = [
221
211
  { name: 'Action', value: 'Epoch-Prescribed-Names' },
222
- {
223
- name: 'Timestamp',
224
- value: epoch?.timestamp?.toString() ??
225
- Date.now().toString(),
226
- },
227
- {
228
- name: 'Epoch-Index',
229
- value: epoch?.epochIndex?.toString(),
230
- },
212
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
231
213
  ];
232
214
  return this.process.read({
233
215
  tags: pruneTags(allTags),
@@ -236,15 +218,7 @@ export class ARIOReadable {
236
218
  async getObservations(epoch) {
237
219
  const allTags = [
238
220
  { name: 'Action', value: 'Epoch-Observations' },
239
- {
240
- name: 'Timestamp',
241
- value: epoch?.timestamp?.toString() ??
242
- Date.now().toString(),
243
- },
244
- {
245
- name: 'Epoch-Index',
246
- value: epoch?.epochIndex?.toString(),
247
- },
221
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
248
222
  ];
249
223
  return this.process.read({
250
224
  tags: pruneTags(allTags),
@@ -253,15 +227,7 @@ export class ARIOReadable {
253
227
  async getDistributions(epoch) {
254
228
  const allTags = [
255
229
  { name: 'Action', value: 'Epoch-Distributions' },
256
- {
257
- name: 'Timestamp',
258
- value: epoch?.timestamp?.toString() ??
259
- Date.now().toString(),
260
- },
261
- {
262
- name: 'Epoch-Index',
263
- value: epoch?.epochIndex?.toString(),
264
- },
230
+ { name: 'Epoch-Index', value: await this.computeEpochIndex(epoch) },
265
231
  ];
266
232
  return this.process.read({
267
233
  tags: pruneTags(allTags),
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.1.0-alpha.9';
17
+ export const version = '3.1.0';
@@ -23,6 +23,7 @@ export declare class ARIO {
23
23
  }
24
24
  export declare class ARIOReadable implements AoARIORead {
25
25
  protected process: AOProcess;
26
+ protected epochSettings: AoEpochSettings | undefined;
26
27
  constructor(config?: ProcessConfiguration);
27
28
  getInfo(): Promise<{
28
29
  Name: string;
@@ -33,7 +34,9 @@ export declare class ARIOReadable implements AoARIORead {
33
34
  LastTickedEpochIndex: number;
34
35
  }>;
35
36
  getTokenSupply(): Promise<AoTokenSupplyData>;
36
- getEpochSettings(params?: EpochInput): Promise<AoEpochSettings>;
37
+ private computeEpochIndexForTimestamp;
38
+ private computeEpochIndex;
39
+ getEpochSettings(): Promise<AoEpochSettings>;
37
40
  getEpoch(epoch?: EpochInput): Promise<AoEpochData>;
38
41
  getArNSRecord({ name, }: {
39
42
  name: string;
@@ -105,6 +105,8 @@ export type AoEpochSettings = {
105
105
  rewardPercentage: number;
106
106
  maxObservers: number;
107
107
  distributionDelayMs: number;
108
+ epochZeroTimestamp: Timestamp;
109
+ pruneEpochsCount: number;
108
110
  };
109
111
  export type AoEpochData = {
110
112
  epochIndex: AoEpochIndex;
@@ -277,7 +279,7 @@ export type AoFundingPlan = {
277
279
  address: WalletAddress;
278
280
  balance: number;
279
281
  stakes: Record<WalletAddress, {
280
- vaults: string[];
282
+ vaults: Record<string, number>[];
281
283
  delegatedStake: number;
282
284
  }>;
283
285
  /** Any remaining shortfall will indicate an insufficient balance for the action */
@@ -351,7 +353,7 @@ export interface AoARIORead {
351
353
  LastTickedEpochIndex: number;
352
354
  }>;
353
355
  getTokenSupply(): Promise<AoTokenSupplyData>;
354
- getEpochSettings(params?: EpochInput): Promise<AoEpochSettings>;
356
+ getEpochSettings(): Promise<AoEpochSettings>;
355
357
  getGateway({ address }: AoAddressParams): Promise<AoGateway | undefined>;
356
358
  getGatewayDelegates({ address, ...pageParams }: AoAddressParams & PaginationParams<AoGatewayDelegateWithAddress>): Promise<PaginationResult<AoGatewayDelegateWithAddress>>;
357
359
  getGatewayDelegateAllowList(params: AoPaginatedAddressParams): Promise<PaginationResult<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.1.0-alpha.8";
16
+ export declare const version = "3.1.0-alpha.11";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/sdk",
3
- "version": "3.1.0-alpha.9",
3
+ "version": "3.1.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ar-io/ar-io-sdk.git"