@ar.io/sdk 3.24.0 → 4.0.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.
- package/README.md +682 -600
- package/lib/esm/cli/cli.js +188 -152
- package/lib/esm/cli/commands/antCommands.js +23 -58
- package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
- package/lib/esm/cli/commands/escrowCommands.js +221 -0
- package/lib/esm/cli/commands/gatewayWriteCommands.js +142 -23
- package/lib/esm/cli/commands/pruneCommands.js +150 -0
- package/lib/esm/cli/commands/readCommands.js +22 -3
- package/lib/esm/cli/commands/transfer.js +6 -6
- package/lib/esm/cli/options.js +124 -58
- package/lib/esm/cli/utils.js +280 -174
- package/lib/esm/common/ant-registry.js +17 -143
- package/lib/esm/common/ant.js +44 -1167
- package/lib/esm/common/faucet.js +11 -6
- package/lib/esm/common/index.js +0 -4
- package/lib/esm/common/io.js +25 -1412
- package/lib/esm/constants.js +13 -19
- package/lib/esm/solana/ant-readable.js +724 -0
- package/lib/esm/solana/ant-registry-readable.js +133 -0
- package/lib/esm/solana/ant-registry-writeable.js +472 -0
- package/lib/esm/solana/ant-writeable.js +384 -0
- package/lib/esm/solana/ata.js +70 -0
- package/lib/esm/solana/canonical-message.js +128 -0
- package/lib/esm/solana/clusters.js +111 -0
- package/lib/esm/solana/constants.js +146 -0
- package/lib/esm/solana/delegation-math.js +112 -0
- package/lib/esm/solana/deserialize.js +711 -0
- package/lib/esm/solana/escrow.js +839 -0
- package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
- package/lib/esm/solana/funding-plan.js +699 -0
- package/lib/esm/solana/index.js +126 -0
- package/lib/esm/solana/instruction.js +39 -0
- package/lib/esm/solana/io-readable.js +2182 -0
- package/lib/esm/solana/io-writeable.js +3196 -0
- package/lib/esm/solana/json-rpc.js +90 -0
- package/lib/esm/solana/metadata.js +81 -0
- package/lib/esm/solana/mpl-core.js +192 -0
- package/lib/esm/solana/pda.js +332 -0
- package/lib/esm/solana/predict-prescribed-observers.js +110 -0
- package/lib/esm/solana/retry.js +117 -0
- package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
- package/lib/esm/solana/send.js +372 -0
- package/lib/esm/solana/spawn-ant.js +224 -0
- package/lib/esm/solana/types.js +1 -0
- package/lib/esm/types/ant.js +27 -15
- package/lib/esm/types/io.js +8 -11
- package/lib/esm/utils/ant.js +0 -63
- package/lib/esm/utils/index.js +0 -3
- package/lib/esm/version.js +1 -1
- package/lib/types/cli/commands/antCommands.d.ts +5 -13
- package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
- package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
- package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
- package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
- package/lib/types/cli/commands/readCommands.d.ts +27 -22
- package/lib/types/cli/commands/transfer.d.ts +9 -9
- package/lib/types/cli/options.d.ts +76 -21
- package/lib/types/cli/types.d.ts +11 -13
- package/lib/types/cli/utils.d.ts +71 -31
- package/lib/types/common/ant-registry.d.ts +49 -47
- package/lib/types/common/ant.d.ts +54 -539
- package/lib/types/common/faucet.d.ts +20 -8
- package/lib/types/common/index.d.ts +0 -3
- package/lib/types/common/io.d.ts +51 -263
- package/lib/types/constants.d.ts +11 -18
- package/lib/types/solana/ant-readable.d.ts +180 -0
- package/lib/types/solana/ant-registry-readable.d.ts +105 -0
- package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
- package/lib/types/solana/ant-writeable.d.ts +177 -0
- package/lib/types/solana/ata.d.ts +44 -0
- package/lib/types/solana/canonical-message.d.ts +121 -0
- package/lib/types/solana/clusters.d.ts +109 -0
- package/lib/types/solana/constants.d.ts +119 -0
- package/lib/types/solana/delegation-math.d.ts +45 -0
- package/lib/types/solana/deserialize.d.ts +262 -0
- package/lib/types/solana/escrow.d.ts +480 -0
- package/lib/types/solana/events.d.ts +38 -0
- package/lib/types/solana/funding-plan.d.ts +225 -0
- package/lib/types/solana/index.d.ts +87 -0
- package/lib/types/solana/instruction.d.ts +39 -0
- package/lib/types/solana/io-readable.d.ts +499 -0
- package/lib/types/solana/io-writeable.d.ts +893 -0
- package/lib/types/solana/json-rpc.d.ts +47 -0
- package/lib/types/solana/metadata.d.ts +84 -0
- package/lib/types/solana/mpl-core.d.ts +120 -0
- package/lib/types/solana/pda.d.ts +95 -0
- package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
- package/lib/types/solana/retry.d.ts +62 -0
- package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
- package/lib/types/solana/send.d.ts +94 -0
- package/lib/types/solana/spawn-ant.d.ts +145 -0
- package/lib/types/solana/types.d.ts +82 -0
- package/lib/types/types/ant-registry.d.ts +43 -4
- package/lib/types/types/ant.d.ts +114 -96
- package/lib/types/types/common.d.ts +18 -74
- package/lib/types/types/faucet.d.ts +2 -2
- package/lib/types/types/io.d.ts +244 -158
- package/lib/types/types/token.d.ts +0 -12
- package/lib/types/utils/ant.d.ts +1 -12
- package/lib/types/utils/index.d.ts +0 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +36 -33
- package/lib/cjs/cli/cli.js +0 -822
- package/lib/cjs/cli/commands/antCommands.js +0 -113
- package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
- package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
- package/lib/cjs/cli/commands/readCommands.js +0 -215
- package/lib/cjs/cli/commands/transfer.js +0 -159
- package/lib/cjs/cli/options.js +0 -470
- package/lib/cjs/cli/types.js +0 -2
- package/lib/cjs/cli/utils.js +0 -639
- package/lib/cjs/common/ant-registry.js +0 -155
- package/lib/cjs/common/ant-versions.js +0 -93
- package/lib/cjs/common/ant.js +0 -1182
- package/lib/cjs/common/arweave.js +0 -27
- package/lib/cjs/common/contracts/ao-process.js +0 -224
- package/lib/cjs/common/error.js +0 -64
- package/lib/cjs/common/faucet.js +0 -150
- package/lib/cjs/common/hyperbeam/hb.js +0 -173
- package/lib/cjs/common/index.js +0 -42
- package/lib/cjs/common/io.js +0 -1423
- package/lib/cjs/common/logger.js +0 -83
- package/lib/cjs/common/loggers/winston.js +0 -68
- package/lib/cjs/common/marketplace.js +0 -731
- package/lib/cjs/common/turbo.js +0 -223
- package/lib/cjs/constants.js +0 -41
- package/lib/cjs/node/index.js +0 -39
- package/lib/cjs/package.json +0 -1
- package/lib/cjs/types/ant-registry.js +0 -2
- package/lib/cjs/types/ant.js +0 -168
- package/lib/cjs/types/common.js +0 -2
- package/lib/cjs/types/faucet.js +0 -2
- package/lib/cjs/types/index.js +0 -37
- package/lib/cjs/types/io.js +0 -51
- package/lib/cjs/types/token.js +0 -116
- package/lib/cjs/utils/ant.js +0 -108
- package/lib/cjs/utils/ao.js +0 -432
- package/lib/cjs/utils/arweave.js +0 -285
- package/lib/cjs/utils/base64.js +0 -62
- package/lib/cjs/utils/hash.js +0 -56
- package/lib/cjs/utils/index.js +0 -38
- package/lib/cjs/utils/processes.js +0 -173
- package/lib/cjs/utils/random.js +0 -30
- package/lib/cjs/utils/schema.js +0 -15
- package/lib/cjs/utils/url.js +0 -37
- package/lib/cjs/version.js +0 -20
- package/lib/cjs/web/index.js +0 -41
- package/lib/esm/common/ant-versions.js +0 -87
- package/lib/esm/common/arweave.js +0 -21
- package/lib/esm/common/contracts/ao-process.js +0 -220
- package/lib/esm/common/hyperbeam/hb.js +0 -169
- package/lib/esm/common/marketplace.js +0 -724
- package/lib/esm/common/turbo.js +0 -215
- package/lib/esm/node/index.js +0 -20
- package/lib/esm/utils/ao.js +0 -420
- package/lib/esm/utils/arweave.js +0 -271
- package/lib/esm/utils/processes.js +0 -167
- package/lib/esm/web/index.js +0 -20
- package/lib/types/common/ant-versions.d.ts +0 -39
- package/lib/types/common/arweave.d.ts +0 -17
- package/lib/types/common/contracts/ao-process.d.ts +0 -47
- package/lib/types/common/hyperbeam/hb.d.ts +0 -88
- package/lib/types/common/marketplace.d.ts +0 -568
- package/lib/types/common/turbo.d.ts +0 -61
- package/lib/types/node/index.d.ts +0 -20
- package/lib/types/utils/ao.d.ts +0 -80
- package/lib/types/utils/arweave.d.ts +0 -79
- package/lib/types/utils/processes.d.ts +0 -39
- package/lib/types/web/index.d.ts +0 -20
|
@@ -0,0 +1,711 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* Thin adapter layer over Codama-generated account decoders from
|
|
18
|
+
* `@ar.io/solana-contracts`. Each function accepts a raw `Buffer` (as
|
|
19
|
+
* returned by `fetchEncodedAccount(...).data`) and returns the same
|
|
20
|
+
* SDK-compatible plain-object shape the hand-rolled BorshReader
|
|
21
|
+
* implementations used to return.
|
|
22
|
+
*
|
|
23
|
+
* The Codama decoders return `Address` (branded string) and `bigint`
|
|
24
|
+
* for numeric fields. This module maps them to plain `string` and
|
|
25
|
+
* `number` so the SDK's public API contract doesn't change.
|
|
26
|
+
*/
|
|
27
|
+
import { getAddressDecoder, getAddressEncoder, } from '@solana/kit';
|
|
28
|
+
import { getAclConfigDecoder, getAclPageDecoder, getAntConfigDecoder, getAntControllersDecoder, getAntRecordDecoder, getAntRecordMetadataDecoder, } from '@ar.io/solana-contracts/ant';
|
|
29
|
+
import { PurchaseType, getArnsRecordDecoder, getDemandFactorDecoder, getReservedNameDecoder, getReturnedNameDecoder, } from '@ar.io/solana-contracts/arns';
|
|
30
|
+
import { getArioConfigDecoder, getPrimaryNameDecoder, getPrimaryNameRequestDecoder, getVaultDecoder, } from '@ar.io/solana-contracts/core';
|
|
31
|
+
import { GatewayStatus, getAllowlistEntryDecoder, getDelegationDecoder, getEpochDecoder, getEpochSettingsDecoder, getGatewaySettingsDecoder as getGarSettingsDecoder, getGatewayDecoder, getObservationDecoder, getRedelegationRecordDecoder, getWithdrawalDecoder, } from '@ar.io/solana-contracts/gar';
|
|
32
|
+
import { RATE_SCALE } from './constants.js';
|
|
33
|
+
const addressDecoder = getAddressDecoder();
|
|
34
|
+
const addressEncoder = getAddressEncoder();
|
|
35
|
+
function optionToValue(opt) {
|
|
36
|
+
return opt.__option === 'Some' ? opt.value : undefined;
|
|
37
|
+
}
|
|
38
|
+
function scaleToFloat(value, scale = RATE_SCALE) {
|
|
39
|
+
return value / scale;
|
|
40
|
+
}
|
|
41
|
+
// =========================================
|
|
42
|
+
// Buffer reader/writer helpers (kept for test fixtures that synthesize account data)
|
|
43
|
+
// =========================================
|
|
44
|
+
class BorshReader {
|
|
45
|
+
data;
|
|
46
|
+
offset;
|
|
47
|
+
constructor(data, startOffset = 0) {
|
|
48
|
+
this.data = data;
|
|
49
|
+
this.offset = startOffset;
|
|
50
|
+
}
|
|
51
|
+
readU8() {
|
|
52
|
+
const val = this.data.readUInt8(this.offset);
|
|
53
|
+
this.offset += 1;
|
|
54
|
+
return val;
|
|
55
|
+
}
|
|
56
|
+
readBool() {
|
|
57
|
+
return this.readU8() !== 0;
|
|
58
|
+
}
|
|
59
|
+
readU16() {
|
|
60
|
+
const val = this.data.readUInt16LE(this.offset);
|
|
61
|
+
this.offset += 2;
|
|
62
|
+
return val;
|
|
63
|
+
}
|
|
64
|
+
readU32() {
|
|
65
|
+
const val = this.data.readUInt32LE(this.offset);
|
|
66
|
+
this.offset += 4;
|
|
67
|
+
return val;
|
|
68
|
+
}
|
|
69
|
+
readU64() {
|
|
70
|
+
const val = this.data.readBigUInt64LE(this.offset);
|
|
71
|
+
this.offset += 8;
|
|
72
|
+
return val;
|
|
73
|
+
}
|
|
74
|
+
readU64AsNumber() {
|
|
75
|
+
return Number(this.readU64());
|
|
76
|
+
}
|
|
77
|
+
readI64() {
|
|
78
|
+
const val = this.data.readBigInt64LE(this.offset);
|
|
79
|
+
this.offset += 8;
|
|
80
|
+
return val;
|
|
81
|
+
}
|
|
82
|
+
readI64AsNumber() {
|
|
83
|
+
return Number(this.readI64());
|
|
84
|
+
}
|
|
85
|
+
readU128() {
|
|
86
|
+
const lo = this.data.readBigUInt64LE(this.offset);
|
|
87
|
+
const hi = this.data.readBigUInt64LE(this.offset + 8);
|
|
88
|
+
this.offset += 16;
|
|
89
|
+
return (hi << 64n) | lo;
|
|
90
|
+
}
|
|
91
|
+
readPubkey() {
|
|
92
|
+
const bytes = this.data.subarray(this.offset, this.offset + 32);
|
|
93
|
+
this.offset += 32;
|
|
94
|
+
return addressDecoder.decode(bytes);
|
|
95
|
+
}
|
|
96
|
+
readString() {
|
|
97
|
+
const len = this.readU32();
|
|
98
|
+
const str = this.data
|
|
99
|
+
.toString('utf8', this.offset, this.offset + len)
|
|
100
|
+
.replace(/\0/g, '');
|
|
101
|
+
this.offset += len;
|
|
102
|
+
return str;
|
|
103
|
+
}
|
|
104
|
+
readOptionI64() {
|
|
105
|
+
const tag = this.readU8();
|
|
106
|
+
if (tag === 0)
|
|
107
|
+
return undefined;
|
|
108
|
+
return this.readI64AsNumber();
|
|
109
|
+
}
|
|
110
|
+
readOptionU32() {
|
|
111
|
+
const tag = this.readU8();
|
|
112
|
+
if (tag === 0)
|
|
113
|
+
return undefined;
|
|
114
|
+
return this.readU32();
|
|
115
|
+
}
|
|
116
|
+
readOptionU16() {
|
|
117
|
+
const tag = this.readU8();
|
|
118
|
+
if (tag === 0)
|
|
119
|
+
return undefined;
|
|
120
|
+
return this.readU16();
|
|
121
|
+
}
|
|
122
|
+
skip(bytes) {
|
|
123
|
+
this.offset += bytes;
|
|
124
|
+
}
|
|
125
|
+
getOffset() {
|
|
126
|
+
return this.offset;
|
|
127
|
+
}
|
|
128
|
+
remaining() {
|
|
129
|
+
return this.data.length - this.offset;
|
|
130
|
+
}
|
|
131
|
+
readOptionPubkey() {
|
|
132
|
+
const tag = this.readU8();
|
|
133
|
+
if (tag === 0)
|
|
134
|
+
return undefined;
|
|
135
|
+
return this.readPubkey();
|
|
136
|
+
}
|
|
137
|
+
readOptionString() {
|
|
138
|
+
const tag = this.readU8();
|
|
139
|
+
if (tag === 0)
|
|
140
|
+
return undefined;
|
|
141
|
+
return this.readString();
|
|
142
|
+
}
|
|
143
|
+
readVecString() {
|
|
144
|
+
const count = this.readU32();
|
|
145
|
+
const result = [];
|
|
146
|
+
for (let i = 0; i < count; i++) {
|
|
147
|
+
result.push(this.readString());
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
readOptionVecString() {
|
|
152
|
+
const tag = this.readU8();
|
|
153
|
+
if (tag === 0)
|
|
154
|
+
return undefined;
|
|
155
|
+
return this.readVecString();
|
|
156
|
+
}
|
|
157
|
+
readVecPubkey() {
|
|
158
|
+
const count = this.readU32();
|
|
159
|
+
const result = [];
|
|
160
|
+
for (let i = 0; i < count; i++) {
|
|
161
|
+
result.push(this.readPubkey());
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
readFixedU64Array(count) {
|
|
166
|
+
const result = [];
|
|
167
|
+
for (let i = 0; i < count; i++) {
|
|
168
|
+
result.push(this.readU64AsNumber());
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
readFixedBytes(count) {
|
|
173
|
+
const buf = this.data.subarray(this.offset, this.offset + count);
|
|
174
|
+
this.offset += count;
|
|
175
|
+
return Buffer.from(buf);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
class BorshWriter {
|
|
179
|
+
buf;
|
|
180
|
+
offset;
|
|
181
|
+
constructor(size) {
|
|
182
|
+
this.buf = Buffer.alloc(size);
|
|
183
|
+
this.offset = 0;
|
|
184
|
+
}
|
|
185
|
+
writeU8(val) {
|
|
186
|
+
this.buf.writeUInt8(val, this.offset);
|
|
187
|
+
this.offset += 1;
|
|
188
|
+
}
|
|
189
|
+
writeBool(val) {
|
|
190
|
+
this.writeU8(val ? 1 : 0);
|
|
191
|
+
}
|
|
192
|
+
writeU16(val) {
|
|
193
|
+
this.buf.writeUInt16LE(val, this.offset);
|
|
194
|
+
this.offset += 2;
|
|
195
|
+
}
|
|
196
|
+
writeU32(val) {
|
|
197
|
+
this.buf.writeUInt32LE(val, this.offset);
|
|
198
|
+
this.offset += 4;
|
|
199
|
+
}
|
|
200
|
+
writeU64(val) {
|
|
201
|
+
this.buf.writeBigUInt64LE(BigInt(val), this.offset);
|
|
202
|
+
this.offset += 8;
|
|
203
|
+
}
|
|
204
|
+
writeI64(val) {
|
|
205
|
+
this.buf.writeBigInt64LE(BigInt(val), this.offset);
|
|
206
|
+
this.offset += 8;
|
|
207
|
+
}
|
|
208
|
+
writePubkey(key) {
|
|
209
|
+
const bytes = addressEncoder.encode(key);
|
|
210
|
+
for (let i = 0; i < 32; i++) {
|
|
211
|
+
this.buf[this.offset + i] = bytes[i];
|
|
212
|
+
}
|
|
213
|
+
this.offset += 32;
|
|
214
|
+
}
|
|
215
|
+
writeFixedBytes(data) {
|
|
216
|
+
for (let i = 0; i < data.length; i++) {
|
|
217
|
+
this.buf[this.offset + i] = data[i];
|
|
218
|
+
}
|
|
219
|
+
this.offset += data.length;
|
|
220
|
+
}
|
|
221
|
+
writeString(str) {
|
|
222
|
+
const encoded = Buffer.from(str, 'utf8');
|
|
223
|
+
this.writeU32(encoded.length);
|
|
224
|
+
encoded.copy(this.buf, this.offset);
|
|
225
|
+
this.offset += encoded.length;
|
|
226
|
+
}
|
|
227
|
+
writeOptionI64(val) {
|
|
228
|
+
if (val === undefined) {
|
|
229
|
+
this.writeU8(0);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.writeU8(1);
|
|
233
|
+
this.writeI64(val);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
writeOptionU32(val) {
|
|
237
|
+
if (val === undefined) {
|
|
238
|
+
this.writeU8(0);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
this.writeU8(1);
|
|
242
|
+
this.writeU32(val);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
writeOptionPubkey(key) {
|
|
246
|
+
if (key === undefined) {
|
|
247
|
+
this.writeU8(0);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.writeU8(1);
|
|
251
|
+
this.writePubkey(key);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
writeOptionString(val) {
|
|
255
|
+
if (val === undefined) {
|
|
256
|
+
this.writeU8(0);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
this.writeU8(1);
|
|
260
|
+
this.writeString(val);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
writeOptionStringVec(val) {
|
|
264
|
+
if (val === undefined) {
|
|
265
|
+
this.writeU8(0);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.writeU8(1);
|
|
269
|
+
this.writeU32(val.length);
|
|
270
|
+
for (const s of val)
|
|
271
|
+
this.writeString(s);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
toBuffer() {
|
|
275
|
+
return this.buf.subarray(0, this.offset);
|
|
276
|
+
}
|
|
277
|
+
getOffset() {
|
|
278
|
+
return this.offset;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// =========================================
|
|
282
|
+
// Gateway deserialization
|
|
283
|
+
// =========================================
|
|
284
|
+
export function deserializeGatewayWithAccumulator(data) {
|
|
285
|
+
const d = getGatewayDecoder().decode(new Uint8Array(data));
|
|
286
|
+
const stats = {
|
|
287
|
+
passedEpochCount: d.stats.passedEpochs,
|
|
288
|
+
failedEpochCount: d.stats.failedEpochs,
|
|
289
|
+
totalEpochCount: d.stats.totalEpochs,
|
|
290
|
+
prescribedEpochCount: d.stats.prescribedEpochs,
|
|
291
|
+
observedEpochCount: d.stats.observedEpochs,
|
|
292
|
+
passedConsecutiveEpochs: d.stats.passedConsecutive,
|
|
293
|
+
failedConsecutiveEpochs: d.stats.failedConsecutive,
|
|
294
|
+
};
|
|
295
|
+
const weights = {
|
|
296
|
+
stakeWeight: scaleToFloat(Number(d.weights.stakeWeight)),
|
|
297
|
+
tenureWeight: scaleToFloat(Number(d.weights.tenureWeight)),
|
|
298
|
+
gatewayPerformanceRatio: scaleToFloat(Number(d.weights.gatewayPerformanceRatio)),
|
|
299
|
+
observerPerformanceRatio: scaleToFloat(Number(d.weights.observerPerformanceRatio)),
|
|
300
|
+
gatewayRewardRatioWeight: scaleToFloat(Number(d.weights.gatewayPerformanceRatio)),
|
|
301
|
+
observerRewardRatioWeight: scaleToFloat(Number(d.weights.observerPerformanceRatio)),
|
|
302
|
+
compositeWeight: scaleToFloat(Number(d.weights.compositeWeight)),
|
|
303
|
+
normalizedCompositeWeight: scaleToFloat(Number(d.weights.normalizedCompositeWeight)),
|
|
304
|
+
};
|
|
305
|
+
const pendingRatioRaw = optionToValue(d.settings.pendingDelegateRewardShareRatio);
|
|
306
|
+
const pendingDelegateRewardShareRatio = pendingRatioRaw === undefined ? undefined : pendingRatioRaw / 100;
|
|
307
|
+
const delegationDisabledAt = optionToValue(d.settings.delegationDisabledAt);
|
|
308
|
+
const settings = {
|
|
309
|
+
allowDelegatedStaking: d.settings.allowlistEnabled
|
|
310
|
+
? 'allowlist'
|
|
311
|
+
: d.settings.allowDelegatedStaking,
|
|
312
|
+
delegateRewardShareRatio: d.settings.delegateRewardShareRatio / 100,
|
|
313
|
+
allowedDelegates: [],
|
|
314
|
+
minDelegatedStake: Number(d.settings.minDelegationAmount),
|
|
315
|
+
autoStake: false,
|
|
316
|
+
label: d.label,
|
|
317
|
+
note: d.note,
|
|
318
|
+
properties: d.properties,
|
|
319
|
+
fqdn: d.fqdn,
|
|
320
|
+
port: d.port,
|
|
321
|
+
protocol: 'https',
|
|
322
|
+
pendingDelegateRewardShareRatio,
|
|
323
|
+
delegationDisabledAt: delegationDisabledAt !== undefined
|
|
324
|
+
? Number(delegationDisabledAt)
|
|
325
|
+
: undefined,
|
|
326
|
+
};
|
|
327
|
+
const leaveTimestamp = optionToValue(d.leaveTimestamp);
|
|
328
|
+
return {
|
|
329
|
+
operator: d.operator,
|
|
330
|
+
settings,
|
|
331
|
+
stats,
|
|
332
|
+
totalDelegatedStake: Number(d.totalDelegatedStake),
|
|
333
|
+
startTimestamp: Number(d.startTimestamp),
|
|
334
|
+
endTimestamp: leaveTimestamp !== undefined ? Number(leaveTimestamp) : 0,
|
|
335
|
+
observerAddress: d.observerAddress,
|
|
336
|
+
operatorStake: Number(d.operatorStake),
|
|
337
|
+
status: d.status === GatewayStatus.Joined ? 'joined' : 'leaving',
|
|
338
|
+
weights,
|
|
339
|
+
cumulativeRewardPerToken: d.cumulativeRewardPerToken,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
export function deserializeGateway(data) {
|
|
343
|
+
const { cumulativeRewardPerToken: _unused, ...publicShape } = deserializeGatewayWithAccumulator(data);
|
|
344
|
+
return publicShape;
|
|
345
|
+
}
|
|
346
|
+
// =========================================
|
|
347
|
+
// ArNS Record deserialization
|
|
348
|
+
// =========================================
|
|
349
|
+
export function deserializeArnsRecord(data) {
|
|
350
|
+
const d = getArnsRecordDecoder().decode(new Uint8Array(data));
|
|
351
|
+
const endTimestamp = optionToValue(d.endTimestamp);
|
|
352
|
+
const baseData = {
|
|
353
|
+
name: d.name,
|
|
354
|
+
owner: d.owner,
|
|
355
|
+
processId: d.ant,
|
|
356
|
+
startTimestamp: Number(d.startTimestamp),
|
|
357
|
+
undernameLimit: d.undernameLimit,
|
|
358
|
+
purchasePrice: Number(d.purchasePrice),
|
|
359
|
+
};
|
|
360
|
+
if (d.purchaseType === PurchaseType.Lease && endTimestamp !== undefined) {
|
|
361
|
+
return {
|
|
362
|
+
...baseData,
|
|
363
|
+
type: 'lease',
|
|
364
|
+
endTimestamp: Number(endTimestamp),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
...baseData,
|
|
369
|
+
type: 'permabuy',
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
// =========================================
|
|
373
|
+
// Vault deserialization
|
|
374
|
+
// =========================================
|
|
375
|
+
export function deserializeVault(data) {
|
|
376
|
+
const d = getVaultDecoder().decode(new Uint8Array(data));
|
|
377
|
+
const controller = optionToValue(d.controller);
|
|
378
|
+
return {
|
|
379
|
+
owner: d.owner,
|
|
380
|
+
balance: Number(d.amount),
|
|
381
|
+
startTimestamp: Number(d.startTimestamp),
|
|
382
|
+
endTimestamp: Number(d.endTimestamp),
|
|
383
|
+
controller: controller,
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
export function deserializeDelegation(data) {
|
|
387
|
+
const d = getDelegationDecoder().decode(new Uint8Array(data));
|
|
388
|
+
return {
|
|
389
|
+
gateway: d.gateway,
|
|
390
|
+
delegator: d.delegator,
|
|
391
|
+
delegatedStake: Number(d.amount),
|
|
392
|
+
startTimestamp: Number(d.startTimestamp),
|
|
393
|
+
rewardDebt: d.rewardDebt,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
// =========================================
|
|
397
|
+
// Balance deserialization
|
|
398
|
+
// =========================================
|
|
399
|
+
export function deserializeBalance(data) {
|
|
400
|
+
const d = getBalanceDecoder().decode(new Uint8Array(data));
|
|
401
|
+
return {
|
|
402
|
+
owner: d.owner,
|
|
403
|
+
balance: Number(d.amount),
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
// Keep the import for deserializeBalance
|
|
407
|
+
import { getBalanceDecoder } from '@ar.io/solana-contracts/core';
|
|
408
|
+
// =========================================
|
|
409
|
+
// Epoch Settings deserialization
|
|
410
|
+
// =========================================
|
|
411
|
+
export function deserializeEpochSettings(data) {
|
|
412
|
+
const d = getEpochSettingsDecoder().decode(new Uint8Array(data));
|
|
413
|
+
return {
|
|
414
|
+
epochZeroStartTimestamp: Number(d.genesisTimestamp) * 1000,
|
|
415
|
+
durationMs: Number(d.epochDuration) * 1000,
|
|
416
|
+
prescribedNameCount: d.prescribedNameCount,
|
|
417
|
+
maxObservers: d.prescribedObserverCount,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
// =========================================
|
|
421
|
+
// ArIO Config deserialization
|
|
422
|
+
// =========================================
|
|
423
|
+
export function deserializeArioConfig(data) {
|
|
424
|
+
const d = getArioConfigDecoder().decode(new Uint8Array(data));
|
|
425
|
+
return {
|
|
426
|
+
totalSupply: Number(d.totalSupply),
|
|
427
|
+
protocolBalance: Number(d.protocolBalance),
|
|
428
|
+
circulatingSupply: Number(d.circulatingSupply),
|
|
429
|
+
lockedSupply: Number(d.lockedSupply),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
// =========================================
|
|
433
|
+
// Demand Factor deserialization
|
|
434
|
+
// =========================================
|
|
435
|
+
export function deserializeDemandFactor(data) {
|
|
436
|
+
const d = getDemandFactorDecoder().decode(new Uint8Array(data));
|
|
437
|
+
return {
|
|
438
|
+
currentDemandFactor: Number(d.currentDemandFactor) / RATE_SCALE,
|
|
439
|
+
currentPeriod: Number(d.currentPeriod),
|
|
440
|
+
periodZeroStartTimestamp: Number(d.periodZeroStartTimestamp),
|
|
441
|
+
consecutivePeriodsWithMinDemandFactor: d.consecutivePeriodsWithMinDemandFactor,
|
|
442
|
+
trailingPeriodPurchases: d.trailingPeriodPurchases.map(Number),
|
|
443
|
+
trailingPeriodRevenues: d.trailingPeriodRevenues.map(Number),
|
|
444
|
+
fees: d.fees.map(Number),
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
// =========================================
|
|
448
|
+
// Reserved Name deserialization
|
|
449
|
+
// =========================================
|
|
450
|
+
export function deserializeReservedName(data) {
|
|
451
|
+
const d = getReservedNameDecoder().decode(new Uint8Array(data));
|
|
452
|
+
const reservedFor = optionToValue(d.reservedFor);
|
|
453
|
+
const expiresAt = optionToValue(d.expiresAt);
|
|
454
|
+
return {
|
|
455
|
+
name: d.name,
|
|
456
|
+
target: reservedFor,
|
|
457
|
+
endTimestamp: expiresAt !== undefined ? Number(expiresAt) : undefined,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
// =========================================
|
|
461
|
+
// Returned Name deserialization
|
|
462
|
+
// =========================================
|
|
463
|
+
const RETURN_AUCTION_DURATION_SECONDS = 14 * 86_400;
|
|
464
|
+
export function deserializeReturnedName(data) {
|
|
465
|
+
const d = getReturnedNameDecoder().decode(new Uint8Array(data));
|
|
466
|
+
const returnedAt = Number(d.returnedAt);
|
|
467
|
+
return {
|
|
468
|
+
name: d.name,
|
|
469
|
+
startTimestamp: returnedAt,
|
|
470
|
+
endTimestamp: returnedAt + RETURN_AUCTION_DURATION_SECONDS,
|
|
471
|
+
initiator: d.initiator,
|
|
472
|
+
premiumMultiplier: 1,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
// =========================================
|
|
476
|
+
// Withdrawal deserialization
|
|
477
|
+
// =========================================
|
|
478
|
+
export function deserializeWithdrawal(data) {
|
|
479
|
+
const d = getWithdrawalDecoder().decode(new Uint8Array(data));
|
|
480
|
+
return {
|
|
481
|
+
owner: d.owner,
|
|
482
|
+
vaultId: String(Number(d.withdrawalId)),
|
|
483
|
+
gateway: d.gateway,
|
|
484
|
+
balance: Number(d.amount),
|
|
485
|
+
startTimestamp: Number(d.createdAt),
|
|
486
|
+
endTimestamp: Number(d.availableAt),
|
|
487
|
+
isDelegate: d.isDelegate,
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
// =========================================
|
|
491
|
+
// Redelegation Record deserialization
|
|
492
|
+
// =========================================
|
|
493
|
+
export function deserializeRedelegationRecord(data) {
|
|
494
|
+
const d = getRedelegationRecordDecoder().decode(new Uint8Array(data));
|
|
495
|
+
return {
|
|
496
|
+
delegator: d.delegator,
|
|
497
|
+
redelegationCount: d.redelegationCount,
|
|
498
|
+
lastRedelegationAt: Number(d.lastRedelegationAt),
|
|
499
|
+
feeResetAt: Number(d.feeResetAt),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
// =========================================
|
|
503
|
+
// Primary Name Request deserialization
|
|
504
|
+
// =========================================
|
|
505
|
+
export function deserializePrimaryNameRequest(data) {
|
|
506
|
+
const d = getPrimaryNameRequestDecoder().decode(new Uint8Array(data));
|
|
507
|
+
return {
|
|
508
|
+
name: d.name,
|
|
509
|
+
initiator: d.initiator,
|
|
510
|
+
startTimestamp: Number(d.createdAt),
|
|
511
|
+
endTimestamp: Number(d.expiresAt),
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
// =========================================
|
|
515
|
+
// GAR Settings deserialization
|
|
516
|
+
// =========================================
|
|
517
|
+
export function deserializeGarSettings(data) {
|
|
518
|
+
const d = getGarSettingsDecoder().decode(new Uint8Array(data));
|
|
519
|
+
const withdrawalPeriodMs = Number(d.withdrawalPeriod) * 1000;
|
|
520
|
+
return {
|
|
521
|
+
delegates: {
|
|
522
|
+
minStake: Number(d.minDelegateStake),
|
|
523
|
+
withdrawLengthMs: withdrawalPeriodMs,
|
|
524
|
+
},
|
|
525
|
+
observers: {
|
|
526
|
+
tenureWeightDurationMs: 15_552_000_000,
|
|
527
|
+
maxTenureWeight: 4,
|
|
528
|
+
},
|
|
529
|
+
operators: {
|
|
530
|
+
minStake: Number(d.minOperatorStake),
|
|
531
|
+
withdrawLengthMs: withdrawalPeriodMs,
|
|
532
|
+
leaveLengthMs: withdrawalPeriodMs,
|
|
533
|
+
maxDelegateRewardSharePct: 95,
|
|
534
|
+
failedEpochCountMax: 30,
|
|
535
|
+
failedGatewaySlashRate: 0,
|
|
536
|
+
},
|
|
537
|
+
redelegations: {
|
|
538
|
+
minRedelegationPenaltyRate: 0,
|
|
539
|
+
maxRedelegationPenaltyRate: 600_000,
|
|
540
|
+
minRedelegationAmount: 10_000_000,
|
|
541
|
+
redelegationFeeResetIntervalMs: 7 * 86_400 * 1000,
|
|
542
|
+
},
|
|
543
|
+
expeditedWithdrawals: {
|
|
544
|
+
minExpeditedWithdrawalPenaltyRate: Number(d.minExpeditedWithdrawalPenalty),
|
|
545
|
+
maxExpeditedWithdrawalPenaltyRate: Number(d.maxExpeditedWithdrawalPenalty),
|
|
546
|
+
minExpeditedWithdrawalAmount: Number(d.minExpeditedWithdrawalAmount),
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
export function deserializeGarSupplyCounters(data) {
|
|
551
|
+
const d = getGarSettingsDecoder().decode(new Uint8Array(data));
|
|
552
|
+
return {
|
|
553
|
+
totalStaked: Number(d.totalStaked),
|
|
554
|
+
totalDelegated: Number(d.totalDelegated),
|
|
555
|
+
totalWithdrawn: Number(d.totalWithdrawn),
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
// =========================================
|
|
559
|
+
// Epoch Settings Full deserialization
|
|
560
|
+
// =========================================
|
|
561
|
+
export function deserializeEpochSettingsFull(data) {
|
|
562
|
+
const d = getEpochSettingsDecoder().decode(new Uint8Array(data));
|
|
563
|
+
return {
|
|
564
|
+
currentEpochIndex: Number(d.currentEpochIndex),
|
|
565
|
+
genesisTimestamp: Number(d.genesisTimestamp),
|
|
566
|
+
epochDuration: Number(d.epochDuration),
|
|
567
|
+
enabled: d.enabled,
|
|
568
|
+
prescribedObserverCount: d.prescribedObserverCount,
|
|
569
|
+
prescribedNameCount: d.prescribedNameCount,
|
|
570
|
+
tenureWeightDuration: Number(d.tenureWeightDuration),
|
|
571
|
+
maxTenureWeight: Number(d.maxTenureWeight),
|
|
572
|
+
gatewayRewardRatio: Number(d.gatewayRewardRatio),
|
|
573
|
+
observerRewardRatio: Number(d.observerRewardRatio),
|
|
574
|
+
maxConsecutiveFailures: d.maxConsecutiveFailures,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
// =========================================
|
|
578
|
+
// Epoch deserialization
|
|
579
|
+
// =========================================
|
|
580
|
+
export function deserializeEpoch(data) {
|
|
581
|
+
const d = getEpochDecoder().decode(new Uint8Array(data));
|
|
582
|
+
return {
|
|
583
|
+
epochIndex: Number(d.epochIndex),
|
|
584
|
+
startTimestamp: Number(d.startTimestamp),
|
|
585
|
+
endTimestamp: Number(d.endTimestamp),
|
|
586
|
+
totalEligibleRewards: Number(d.totalEligibleRewards),
|
|
587
|
+
perGatewayReward: Number(d.perGatewayReward),
|
|
588
|
+
perObserverReward: Number(d.perObserverReward),
|
|
589
|
+
rewardRate: Number(d.rewardRate),
|
|
590
|
+
activeGatewayCount: d.activeGatewayCount,
|
|
591
|
+
distributionIndex: d.distributionIndex,
|
|
592
|
+
tallyIndex: d.tallyIndex,
|
|
593
|
+
observerCount: d.observerCount,
|
|
594
|
+
nameCount: d.nameCount,
|
|
595
|
+
observationsSubmitted: d.observationsSubmitted,
|
|
596
|
+
rewardsDistributed: d.rewardsDistributed,
|
|
597
|
+
weightsTallied: d.weightsTallied,
|
|
598
|
+
prescriptionsDone: d.prescriptionsDone,
|
|
599
|
+
failureCounts: Uint16Array.from(d.failureCounts),
|
|
600
|
+
prescribedObservers: d.prescribedObservers,
|
|
601
|
+
prescribedObserverGateways: d.prescribedObserverGateways,
|
|
602
|
+
prescribedNameHashes: d.prescribedNames.map((b) => Buffer.from(b)),
|
|
603
|
+
hasObserved: new Uint8Array(d.hasObserved),
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
// =========================================
|
|
607
|
+
// Observation deserialization
|
|
608
|
+
// =========================================
|
|
609
|
+
export function deserializeObservation(data) {
|
|
610
|
+
const d = getObservationDecoder().decode(new Uint8Array(data));
|
|
611
|
+
return {
|
|
612
|
+
epochIndex: Number(d.epochIndex),
|
|
613
|
+
observer: d.observer,
|
|
614
|
+
gatewayResults: Buffer.from(d.gatewayResults),
|
|
615
|
+
gatewayCount: d.gatewayCount,
|
|
616
|
+
reportTxId: Buffer.from(d.reportTxId).toString('base64url'),
|
|
617
|
+
submittedAt: Number(d.submittedAt),
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
// =========================================
|
|
621
|
+
// ANT Config deserialization
|
|
622
|
+
// =========================================
|
|
623
|
+
export function deserializeAntConfig(data) {
|
|
624
|
+
const d = getAntConfigDecoder().decode(new Uint8Array(data));
|
|
625
|
+
return {
|
|
626
|
+
mint: d.mint,
|
|
627
|
+
name: d.name,
|
|
628
|
+
ticker: d.ticker,
|
|
629
|
+
logo: d.logo,
|
|
630
|
+
description: d.description,
|
|
631
|
+
keywords: d.keywords,
|
|
632
|
+
owner: d.lastKnownOwner,
|
|
633
|
+
version: d.version.major,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
// =========================================
|
|
637
|
+
// ANT Controllers deserialization
|
|
638
|
+
// =========================================
|
|
639
|
+
export function deserializeAntControllers(data) {
|
|
640
|
+
const d = getAntControllersDecoder().decode(new Uint8Array(data));
|
|
641
|
+
return {
|
|
642
|
+
mint: d.mint,
|
|
643
|
+
controllers: d.controllers.map((c) => c),
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
// =========================================
|
|
647
|
+
// ANT Record deserialization
|
|
648
|
+
// =========================================
|
|
649
|
+
export function deserializeAntRecord(data) {
|
|
650
|
+
const d = getAntRecordDecoder().decode(new Uint8Array(data));
|
|
651
|
+
return {
|
|
652
|
+
mint: d.mint,
|
|
653
|
+
undername: d.undername,
|
|
654
|
+
transactionId: d.target,
|
|
655
|
+
targetProtocol: d.targetProtocol,
|
|
656
|
+
ttlSeconds: d.ttlSeconds,
|
|
657
|
+
priority: optionToValue(d.priority),
|
|
658
|
+
owner: optionToValue(d.owner),
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
export function deserializeAntRecordMetadata(data) {
|
|
662
|
+
const d = getAntRecordMetadataDecoder().decode(new Uint8Array(data));
|
|
663
|
+
return {
|
|
664
|
+
mint: d.mint,
|
|
665
|
+
displayName: optionToValue(d.displayName),
|
|
666
|
+
logo: optionToValue(d.recordLogo),
|
|
667
|
+
description: optionToValue(d.recordDescription),
|
|
668
|
+
keywords: optionToValue(d.recordKeywords),
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
export function deserializeAclConfig(data) {
|
|
672
|
+
const d = getAclConfigDecoder().decode(new Uint8Array(data));
|
|
673
|
+
return {
|
|
674
|
+
user: d.user,
|
|
675
|
+
pageCount: d.pageCount,
|
|
676
|
+
totalEntries: d.totalEntries,
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
export function deserializeAclPage(data) {
|
|
680
|
+
const d = getAclPageDecoder().decode(new Uint8Array(data));
|
|
681
|
+
return {
|
|
682
|
+
user: d.user,
|
|
683
|
+
pageIdx: d.pageIdx,
|
|
684
|
+
entries: d.entries.map((e) => ({
|
|
685
|
+
asset: e.asset,
|
|
686
|
+
role: e.role,
|
|
687
|
+
})),
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
// =========================================
|
|
691
|
+
// Primary Name deserialization
|
|
692
|
+
// =========================================
|
|
693
|
+
export function deserializePrimaryName(data) {
|
|
694
|
+
const d = getPrimaryNameDecoder().decode(new Uint8Array(data));
|
|
695
|
+
return {
|
|
696
|
+
owner: d.owner,
|
|
697
|
+
name: d.name,
|
|
698
|
+
startTimestamp: Number(d.setAt),
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
// =========================================
|
|
702
|
+
// Allowlist deserialization
|
|
703
|
+
// =========================================
|
|
704
|
+
export function deserializeAllowlist(data) {
|
|
705
|
+
const d = getAllowlistEntryDecoder().decode(new Uint8Array(data));
|
|
706
|
+
return {
|
|
707
|
+
gateway: d.gateway,
|
|
708
|
+
delegate: d.delegate,
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
export { BorshReader, BorshWriter };
|