@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.
Files changed (169) hide show
  1. package/README.md +682 -600
  2. package/lib/esm/cli/cli.js +188 -152
  3. package/lib/esm/cli/commands/antCommands.js +23 -58
  4. package/lib/esm/cli/commands/arnsPurchaseCommands.js +48 -30
  5. package/lib/esm/cli/commands/escrowCommands.js +221 -0
  6. package/lib/esm/cli/commands/gatewayWriteCommands.js +142 -23
  7. package/lib/esm/cli/commands/pruneCommands.js +150 -0
  8. package/lib/esm/cli/commands/readCommands.js +22 -3
  9. package/lib/esm/cli/commands/transfer.js +6 -6
  10. package/lib/esm/cli/options.js +124 -58
  11. package/lib/esm/cli/utils.js +280 -174
  12. package/lib/esm/common/ant-registry.js +17 -143
  13. package/lib/esm/common/ant.js +44 -1167
  14. package/lib/esm/common/faucet.js +11 -6
  15. package/lib/esm/common/index.js +0 -4
  16. package/lib/esm/common/io.js +25 -1412
  17. package/lib/esm/constants.js +13 -19
  18. package/lib/esm/solana/ant-readable.js +724 -0
  19. package/lib/esm/solana/ant-registry-readable.js +133 -0
  20. package/lib/esm/solana/ant-registry-writeable.js +472 -0
  21. package/lib/esm/solana/ant-writeable.js +384 -0
  22. package/lib/esm/solana/ata.js +70 -0
  23. package/lib/esm/solana/canonical-message.js +128 -0
  24. package/lib/esm/solana/clusters.js +111 -0
  25. package/lib/esm/solana/constants.js +146 -0
  26. package/lib/esm/solana/delegation-math.js +112 -0
  27. package/lib/esm/solana/deserialize.js +711 -0
  28. package/lib/esm/solana/escrow.js +839 -0
  29. package/lib/{cjs/utils/json.js → esm/solana/events.js} +15 -10
  30. package/lib/esm/solana/funding-plan.js +699 -0
  31. package/lib/esm/solana/index.js +126 -0
  32. package/lib/esm/solana/instruction.js +39 -0
  33. package/lib/esm/solana/io-readable.js +2182 -0
  34. package/lib/esm/solana/io-writeable.js +3196 -0
  35. package/lib/esm/solana/json-rpc.js +90 -0
  36. package/lib/esm/solana/metadata.js +81 -0
  37. package/lib/esm/solana/mpl-core.js +192 -0
  38. package/lib/esm/solana/pda.js +332 -0
  39. package/lib/esm/solana/predict-prescribed-observers.js +110 -0
  40. package/lib/esm/solana/retry.js +117 -0
  41. package/lib/esm/solana/rpc-circuit-breaker.js +258 -0
  42. package/lib/esm/solana/send.js +372 -0
  43. package/lib/esm/solana/spawn-ant.js +224 -0
  44. package/lib/esm/solana/types.js +1 -0
  45. package/lib/esm/types/ant.js +27 -15
  46. package/lib/esm/types/io.js +8 -11
  47. package/lib/esm/utils/ant.js +0 -63
  48. package/lib/esm/utils/index.js +0 -3
  49. package/lib/esm/version.js +1 -1
  50. package/lib/types/cli/commands/antCommands.d.ts +5 -13
  51. package/lib/types/cli/commands/arnsPurchaseCommands.d.ts +33 -7
  52. package/lib/types/cli/commands/escrowCommands.d.ts +68 -0
  53. package/lib/types/cli/commands/gatewayWriteCommands.d.ts +12 -11
  54. package/lib/types/cli/commands/pruneCommands.d.ts +31 -0
  55. package/lib/types/cli/commands/readCommands.d.ts +27 -22
  56. package/lib/types/cli/commands/transfer.d.ts +9 -9
  57. package/lib/types/cli/options.d.ts +76 -21
  58. package/lib/types/cli/types.d.ts +11 -13
  59. package/lib/types/cli/utils.d.ts +71 -31
  60. package/lib/types/common/ant-registry.d.ts +49 -47
  61. package/lib/types/common/ant.d.ts +54 -539
  62. package/lib/types/common/faucet.d.ts +20 -8
  63. package/lib/types/common/index.d.ts +0 -3
  64. package/lib/types/common/io.d.ts +51 -263
  65. package/lib/types/constants.d.ts +11 -18
  66. package/lib/types/solana/ant-readable.d.ts +180 -0
  67. package/lib/types/solana/ant-registry-readable.d.ts +105 -0
  68. package/lib/types/solana/ant-registry-writeable.d.ts +249 -0
  69. package/lib/types/solana/ant-writeable.d.ts +177 -0
  70. package/lib/types/solana/ata.d.ts +44 -0
  71. package/lib/types/solana/canonical-message.d.ts +121 -0
  72. package/lib/types/solana/clusters.d.ts +109 -0
  73. package/lib/types/solana/constants.d.ts +119 -0
  74. package/lib/types/solana/delegation-math.d.ts +45 -0
  75. package/lib/types/solana/deserialize.d.ts +262 -0
  76. package/lib/types/solana/escrow.d.ts +480 -0
  77. package/lib/types/solana/events.d.ts +38 -0
  78. package/lib/types/solana/funding-plan.d.ts +225 -0
  79. package/lib/types/solana/index.d.ts +87 -0
  80. package/lib/types/solana/instruction.d.ts +39 -0
  81. package/lib/types/solana/io-readable.d.ts +499 -0
  82. package/lib/types/solana/io-writeable.d.ts +893 -0
  83. package/lib/types/solana/json-rpc.d.ts +47 -0
  84. package/lib/types/solana/metadata.d.ts +84 -0
  85. package/lib/types/solana/mpl-core.d.ts +120 -0
  86. package/lib/types/solana/pda.d.ts +95 -0
  87. package/lib/types/solana/predict-prescribed-observers.d.ts +28 -0
  88. package/lib/types/solana/retry.d.ts +62 -0
  89. package/lib/types/solana/rpc-circuit-breaker.d.ts +78 -0
  90. package/lib/types/solana/send.d.ts +94 -0
  91. package/lib/types/solana/spawn-ant.d.ts +145 -0
  92. package/lib/types/solana/types.d.ts +82 -0
  93. package/lib/types/types/ant-registry.d.ts +43 -4
  94. package/lib/types/types/ant.d.ts +114 -96
  95. package/lib/types/types/common.d.ts +18 -74
  96. package/lib/types/types/faucet.d.ts +2 -2
  97. package/lib/types/types/io.d.ts +244 -158
  98. package/lib/types/types/token.d.ts +0 -12
  99. package/lib/types/utils/ant.d.ts +1 -12
  100. package/lib/types/utils/index.d.ts +0 -3
  101. package/lib/types/version.d.ts +1 -1
  102. package/package.json +36 -33
  103. package/lib/cjs/cli/cli.js +0 -822
  104. package/lib/cjs/cli/commands/antCommands.js +0 -113
  105. package/lib/cjs/cli/commands/arnsPurchaseCommands.js +0 -212
  106. package/lib/cjs/cli/commands/gatewayWriteCommands.js +0 -210
  107. package/lib/cjs/cli/commands/readCommands.js +0 -215
  108. package/lib/cjs/cli/commands/transfer.js +0 -159
  109. package/lib/cjs/cli/options.js +0 -470
  110. package/lib/cjs/cli/types.js +0 -2
  111. package/lib/cjs/cli/utils.js +0 -639
  112. package/lib/cjs/common/ant-registry.js +0 -155
  113. package/lib/cjs/common/ant-versions.js +0 -93
  114. package/lib/cjs/common/ant.js +0 -1182
  115. package/lib/cjs/common/arweave.js +0 -27
  116. package/lib/cjs/common/contracts/ao-process.js +0 -224
  117. package/lib/cjs/common/error.js +0 -64
  118. package/lib/cjs/common/faucet.js +0 -150
  119. package/lib/cjs/common/hyperbeam/hb.js +0 -173
  120. package/lib/cjs/common/index.js +0 -42
  121. package/lib/cjs/common/io.js +0 -1423
  122. package/lib/cjs/common/logger.js +0 -83
  123. package/lib/cjs/common/loggers/winston.js +0 -68
  124. package/lib/cjs/common/marketplace.js +0 -731
  125. package/lib/cjs/common/turbo.js +0 -223
  126. package/lib/cjs/constants.js +0 -41
  127. package/lib/cjs/node/index.js +0 -39
  128. package/lib/cjs/package.json +0 -1
  129. package/lib/cjs/types/ant-registry.js +0 -2
  130. package/lib/cjs/types/ant.js +0 -168
  131. package/lib/cjs/types/common.js +0 -2
  132. package/lib/cjs/types/faucet.js +0 -2
  133. package/lib/cjs/types/index.js +0 -37
  134. package/lib/cjs/types/io.js +0 -51
  135. package/lib/cjs/types/token.js +0 -116
  136. package/lib/cjs/utils/ant.js +0 -108
  137. package/lib/cjs/utils/ao.js +0 -432
  138. package/lib/cjs/utils/arweave.js +0 -285
  139. package/lib/cjs/utils/base64.js +0 -62
  140. package/lib/cjs/utils/hash.js +0 -56
  141. package/lib/cjs/utils/index.js +0 -38
  142. package/lib/cjs/utils/processes.js +0 -173
  143. package/lib/cjs/utils/random.js +0 -30
  144. package/lib/cjs/utils/schema.js +0 -15
  145. package/lib/cjs/utils/url.js +0 -37
  146. package/lib/cjs/version.js +0 -20
  147. package/lib/cjs/web/index.js +0 -41
  148. package/lib/esm/common/ant-versions.js +0 -87
  149. package/lib/esm/common/arweave.js +0 -21
  150. package/lib/esm/common/contracts/ao-process.js +0 -220
  151. package/lib/esm/common/hyperbeam/hb.js +0 -169
  152. package/lib/esm/common/marketplace.js +0 -724
  153. package/lib/esm/common/turbo.js +0 -215
  154. package/lib/esm/node/index.js +0 -20
  155. package/lib/esm/utils/ao.js +0 -420
  156. package/lib/esm/utils/arweave.js +0 -271
  157. package/lib/esm/utils/processes.js +0 -167
  158. package/lib/esm/web/index.js +0 -20
  159. package/lib/types/common/ant-versions.d.ts +0 -39
  160. package/lib/types/common/arweave.d.ts +0 -17
  161. package/lib/types/common/contracts/ao-process.d.ts +0 -47
  162. package/lib/types/common/hyperbeam/hb.d.ts +0 -88
  163. package/lib/types/common/marketplace.d.ts +0 -568
  164. package/lib/types/common/turbo.d.ts +0 -61
  165. package/lib/types/node/index.d.ts +0 -20
  166. package/lib/types/utils/ao.d.ts +0 -80
  167. package/lib/types/utils/arweave.d.ts +0 -79
  168. package/lib/types/utils/processes.d.ts +0 -39
  169. package/lib/types/web/index.d.ts +0 -20
@@ -0,0 +1,109 @@
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
+ * Cluster-specific deployment constants for AR.IO programs.
18
+ *
19
+ * The program-ID constants in `./constants.ts` (e.g. `ARIO_CORE_PROGRAM_ID`)
20
+ * are codama *placeholders* (`ARioCoreProgramXXX…`), not real on-chain
21
+ * addresses — consumers must pass real IDs via `ARIO.init({ programIds })`.
22
+ * This module exposes the deployed sets per cluster: `MAINNET_PROGRAM_IDS`
23
+ * and `DEVNET_PROGRAM_IDS`.
24
+ *
25
+ * Only root facts live here: program IDs, the RPC URL, and the ARIO mint.
26
+ * Everything else is derived rather than stored — config/settings PDAs come
27
+ * from the codama `find*Pda` helpers in `@ar.io/solana-contracts` (seeded by
28
+ * the program IDs below), and genesis-time token accounts (treasury / stake)
29
+ * are read on-chain from the ArioConfig / GarSettings accounts at runtime
30
+ * (see `io-writeable.ts` `getGarConfig`). Nothing to keep in sync, nothing to
31
+ * drift.
32
+ *
33
+ * Usage:
34
+ * ```ts
35
+ * import { ARIO } from '@ar.io/sdk';
36
+ * import { DEVNET_PROGRAM_IDS, DEVNET_RPC_URL } from '@ar.io/sdk/solana';
37
+ * import { createSolanaRpc, createSolanaRpcSubscriptions } from '@solana/kit';
38
+ *
39
+ * const rpc = createSolanaRpc(DEVNET_RPC_URL);
40
+ * const rpcSubscriptions = createSolanaRpcSubscriptions(
41
+ * DEVNET_RPC_URL.replace(/^https/, 'wss'),
42
+ * );
43
+ * const ario = ARIO.init({
44
+ * backend: 'solana',
45
+ * rpc,
46
+ * rpcSubscriptions,
47
+ * programIds: DEVNET_PROGRAM_IDS,
48
+ * });
49
+ * ```
50
+ */
51
+ import { type Address } from '@solana/kit';
52
+ /**
53
+ * Default JSON-RPC URL for Solana mainnet-beta.
54
+ *
55
+ * The public endpoint rate-limits aggressively — for production use a premium
56
+ * RPC (QuickNode / Helius / Triton). Derive the WS URL with
57
+ * `MAINNET_RPC_URL.replace(/^https/, 'wss')`.
58
+ */
59
+ export declare const MAINNET_RPC_URL = "https://api.mainnet-beta.solana.com";
60
+ /**
61
+ * Default JSON-RPC URL for the Solana devnet cluster.
62
+ *
63
+ * Public devnet rate-limits aggressively — for high-volume work, swap in
64
+ * a premium RPC (QuickNode / Helius / Triton). Derive the WS URL with
65
+ * `DEVNET_RPC_URL.replace(/^https/, 'wss')`.
66
+ */
67
+ export declare const DEVNET_RPC_URL = "https://api.devnet.solana.com";
68
+ /**
69
+ * AR.IO program IDs deployed on Solana mainnet-beta.
70
+ *
71
+ * Shape matches the `programIds` argument of
72
+ * `ARIO.init({ backend: 'solana', programIds, ... })`.
73
+ */
74
+ export declare const MAINNET_PROGRAM_IDS: {
75
+ readonly core: Address<"73YoECm6NKXpVRoe5f1Q9BcP5DJGPFUjnFy6AxBE5Nvh">;
76
+ readonly gar: Address<"89fNiiwgpFSPHKuqfNUkgYTYjtAJAhyqHjXmgXeppGpf">;
77
+ readonly arns: Address<"2yCUx5edFvUrkibYaUa2ZXWyx9kuJkS8CwyzsgHPWdZZ">;
78
+ readonly ant: Address<"2MWexMHfMhGJwMHv9Qm9YAVCqjUFUJwDJAysW4oCUGk5">;
79
+ readonly antEscrow: Address<"5HZhe9UqKL5zAsdz81nuuaxV41h8bFhudzxxBigAQndM">;
80
+ };
81
+ /**
82
+ * Mainnet attestor pubkey — the key that signs cross-protocol attestations
83
+ * (e.g. escrow recipient proofs). Deployment metadata; not consumed by the
84
+ * SDK, exposed here for reference/verification by downstream tooling.
85
+ */
86
+ export declare const MAINNET_ATTESTOR_PUBKEY: Address;
87
+ /**
88
+ * Mainnet upgrade/admin authority pubkey — holds the upgrade authority for
89
+ * the programs above. Deployment metadata; not consumed by the SDK, exposed
90
+ * here for reference.
91
+ */
92
+ export declare const MAINNET_AUTHORITY_PUBKEY: Address;
93
+ /** ARIO SPL Token mint on Solana mainnet-beta. */
94
+ export declare const MAINNET_ARIO_MINT: Address;
95
+ /**
96
+ * AR.IO program IDs deployed on Solana devnet (staging).
97
+ *
98
+ * Shape matches the `programIds` argument of
99
+ * `ARIO.init({ backend: 'solana', programIds, ... })`.
100
+ */
101
+ export declare const DEVNET_PROGRAM_IDS: {
102
+ readonly core: Address<"8Njx9wPkXiNzDCgjwVsJFRjpAEV34gGW3n8DzX3V23m1">;
103
+ readonly gar: Address<"7WsDTrtZBsfKtnP33XkjuqXCY69JE7n4QVYpynqJCFxz">;
104
+ readonly arns: Address<"6EZNezcg4rc5hnh8HG34vGquT3WpW5xXypzPb24uyEpp">;
105
+ readonly ant: Address<"DbHbRwUD1oAn1mrDSqtWtvwGcNrmhWdD2g8L4xmeQ7NX">;
106
+ readonly antEscrow: Address<"bttco5oAnBwCucG63iKokBJCZmNr493f3Ewe9LM3oTx">;
107
+ };
108
+ /** ARIO SPL Token mint on devnet (Staging v2). */
109
+ export declare const DEVNET_ARIO_MINT: Address;
@@ -0,0 +1,119 @@
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
+ * Solana program IDs and PDA seed constants for AR.IO programs.
18
+ *
19
+ * These must match the seeds defined in the Anchor programs under
20
+ * contracts/programs/{ario-core,ario-gar,ario-arns,ario-ant}/src/.
21
+ */
22
+ import { type Address } from '@solana/kit';
23
+ export declare const ARIO_CORE_PROGRAM_ID: Address;
24
+ export declare const ARIO_GAR_PROGRAM_ID: Address;
25
+ export declare const ARIO_ARNS_PROGRAM_ID: Address;
26
+ export declare const ARIO_ANT_PROGRAM_ID: Address;
27
+ export declare const ARIO_ANT_ESCROW_PROGRAM_ID: Address;
28
+ export declare const ARIO_TOKEN_MINT_ADDRESS: Address;
29
+ export declare const MPL_CORE_PROGRAM_ID: Address;
30
+ export declare const TOKEN_DECIMALS = 6;
31
+ export declare const ONE_TOKEN = 1000000;
32
+ export declare const RATE_SCALE = 1000000;
33
+ /**
34
+ * Scaling factor for the per-share reward accumulator
35
+ * `Gateway.cumulative_reward_per_token` in `ario-gar`. Must match the
36
+ * `REWARD_PRECISION` constant in `programs/ario-gar/src/state/mod.rs`.
37
+ */
38
+ export declare const REWARD_PRECISION = 1000000000000000000n;
39
+ export declare const ARIO_CONFIG_SEED: Buffer<ArrayBuffer>;
40
+ export declare const VAULT_SEED: Buffer<ArrayBuffer>;
41
+ export declare const VAULT_COUNTER_SEED: Buffer<ArrayBuffer>;
42
+ export declare const BALANCE_SEED: Buffer<ArrayBuffer>;
43
+ export declare const PRIMARY_NAME_SEED: Buffer<ArrayBuffer>;
44
+ export declare const PRIMARY_NAME_REQUEST_SEED: Buffer<ArrayBuffer>;
45
+ export declare const PRIMARY_NAME_REVERSE_SEED: Buffer<ArrayBuffer>;
46
+ export declare const GATEWAY_REGISTRY_SEED: Buffer<ArrayBuffer>;
47
+ export declare const GAR_SETTINGS_SEED: Buffer<ArrayBuffer>;
48
+ export declare const GATEWAY_SEED: Buffer<ArrayBuffer>;
49
+ export declare const DELEGATION_SEED: Buffer<ArrayBuffer>;
50
+ export declare const WITHDRAWAL_SEED: Buffer<ArrayBuffer>;
51
+ export declare const WITHDRAWAL_COUNTER_SEED: Buffer<ArrayBuffer>;
52
+ export declare const ALLOWLIST_SEED: Buffer<ArrayBuffer>;
53
+ export declare const EPOCH_SEED: Buffer<ArrayBuffer>;
54
+ export declare const EPOCH_SETTINGS_SEED: Buffer<ArrayBuffer>;
55
+ export declare const OBSERVATION_SEED: Buffer<ArrayBuffer>;
56
+ export declare const REDELEGATION_SEED: Buffer<ArrayBuffer>;
57
+ export declare const OBSERVER_LOOKUP_SEED: Buffer<ArrayBuffer>;
58
+ export declare const ARNS_REGISTRY_SEED: Buffer<ArrayBuffer>;
59
+ export declare const ARNS_SETTINGS_SEED: Buffer<ArrayBuffer>;
60
+ export declare const ARNS_RECORD_SEED: Buffer<ArrayBuffer>;
61
+ export declare const RESERVED_NAME_SEED: Buffer<ArrayBuffer>;
62
+ export declare const RETURNED_NAME_SEED: Buffer<ArrayBuffer>;
63
+ export declare const DEMAND_FACTOR_SEED: Buffer<ArrayBuffer>;
64
+ /**
65
+ * Byte offsets of fixed-size fields within an `ArnsRecord` account.
66
+ *
67
+ * Used as `memcmp` filter offsets for `getProgramAccounts` so callers
68
+ * can resolve "which ArNS record points at this ANT mint?" as a true
69
+ * point query instead of scanning every record. Mirrors the
70
+ * `ArnsRecord::ANT_OFFSET` / `OWNER_OFFSET` constants in
71
+ * `contracts/programs/ario-arns/src/state/mod.rs` — keep them in
72
+ * sync if the on-chain layout ever changes.
73
+ */
74
+ export declare const ARNS_RECORD_NAME_HASH_OFFSET = 8;
75
+ export declare const ARNS_RECORD_OWNER_OFFSET: number;
76
+ export declare const ARNS_RECORD_ANT_OFFSET: number;
77
+ export declare const ANT_CONFIG_VERSION = 1;
78
+ export declare const ANT_CONFIG_SEED: Buffer<ArrayBuffer>;
79
+ export declare const ANT_CONTROLLERS_SEED: Buffer<ArrayBuffer>;
80
+ export declare const ANT_RECORD_SEED: Buffer<ArrayBuffer>;
81
+ export declare const ANT_RECORD_META_SEED: Buffer<ArrayBuffer>;
82
+ export declare const ACL_CONFIG_SEED: Buffer<ArrayBuffer>;
83
+ export declare const ACL_PAGE_SEED: Buffer<ArrayBuffer>;
84
+ /**
85
+ * Maximum live entries per `AclPage` (must match the on-chain constant).
86
+ *
87
+ * Each entry is 33 bytes (`Pubkey + u8`). 256 entries = 8_448 bytes raw —
88
+ * fits the default 32 KiB BPF heap with margin and stays well under the
89
+ * 10 KiB per-tx realloc cap when allocated at full size.
90
+ */
91
+ export declare const MAX_ACL_PAGE_ENTRIES = 256;
92
+ /** ACL relationship roles (encoded as `u8` on each `AclEntry`). */
93
+ export declare const ACL_ROLE_OWNER = 0;
94
+ export declare const ACL_ROLE_CONTROLLER = 1;
95
+ export declare const ESCROW_ANT_SEED: Buffer<ArrayBuffer>;
96
+ export declare const ESCROW_TOKEN_SEED: Buffer<ArrayBuffer>;
97
+ export declare const ESCROW_VAULT_SEED: Buffer<ArrayBuffer>;
98
+ export declare const ESCROW_PROTOCOL_ARWEAVE = 0;
99
+ export declare const ESCROW_PROTOCOL_ETHEREUM = 1;
100
+ export declare const ESCROW_ARWEAVE_PUBKEY_LEN = 512;
101
+ export declare const ESCROW_ETHEREUM_PUBKEY_LEN = 20;
102
+ export declare const ESCROW_RECIPIENT_PUBKEY_MAX_LEN = 512;
103
+ export declare const ESCROW_ASSET_TYPE_TOKEN = 1;
104
+ export declare const ESCROW_ASSET_TYPE_VAULT = 2;
105
+ export declare const PROTOCOL_ARWEAVE = 0;
106
+ export declare const PROTOCOL_IPFS = 1;
107
+ export declare const MAX_TARGET_LENGTH = 128;
108
+ export declare const MAX_NAME_LENGTH = 51;
109
+ export declare const MIN_TTL_SECONDS = 60;
110
+ export declare const MAX_TTL_SECONDS = 86400;
111
+ export declare const MAX_CONTROLLERS = 10;
112
+ export declare const EPOCH_DURATION_SECONDS = 86400;
113
+ export declare const WITHDRAWAL_LOCK_PERIOD: number;
114
+ export declare const MIN_OPERATOR_STAKE: number;
115
+ export declare const MIN_DELEGATION_AMOUNT: number;
116
+ export declare const LEASE_GRACE_PERIOD: number;
117
+ export declare const PRIMARY_NAME_REQUEST_EXPIRY: number;
118
+ export declare const MAX_GATEWAYS = 3000;
119
+ export declare const MAX_NAMES = 50000;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Compute the live delegation balance: the last-settled principal plus any
3
+ * pending rewards accrued since the last settlement.
4
+ *
5
+ * Mirrors `settle_delegate_rewards` in
6
+ * `programs/ario-gar/src/state/mod.rs` — including the u128 overflow-safe
7
+ * quotient/remainder split and the saturating-to-`u64::MAX` cap at the end —
8
+ * so a value computed here matches what the on-chain instruction would write
9
+ * if it were called right now.
10
+ *
11
+ * @param delegatedStake - `Delegation.amount` (u64 → number).
12
+ * @param rewardDebt - `Delegation.reward_debt` (u128 → bigint).
13
+ * @param cumulativeRewardPerToken - `Gateway.cumulative_reward_per_token` (u128 → bigint).
14
+ * @returns The delegate's live balance in mARIO, saturating-capped at `u64::MAX`.
15
+ */
16
+ export declare function computeLiveDelegationBalance({ delegatedStake, rewardDebt, cumulativeRewardPerToken, }: {
17
+ delegatedStake: number;
18
+ rewardDebt: bigint;
19
+ cumulativeRewardPerToken: bigint;
20
+ }): number;
21
+ /**
22
+ * Select the delegations worth compounding, from decoded delegations + a map
23
+ * of their gateways' reward accumulators. Pure (no I/O) so it's unit-testable
24
+ * independently of RPC; `SolanaARIOReadable.getDelegationsToCompound` is just
25
+ * fetch+decode wrapped around this.
26
+ *
27
+ * A delegation is included when its pending reward (live balance − settled
28
+ * principal) exceeds `minPendingRewards`, EXCEPT when its gateway is `leaving`
29
+ * (those settle via `claim_delegate_from_leaving_gateway`, not compounding) or
30
+ * its gateway is missing/unreadable. Compounding sub-threshold dust only
31
+ * advances `reward_debt` for no balance gain, so it's filtered out.
32
+ */
33
+ export declare function selectCompoundableDelegations(delegations: Array<{
34
+ gateway: string;
35
+ delegator: string;
36
+ delegatedStake: number;
37
+ rewardDebt: bigint;
38
+ }>, gatewaysByOperator: Map<string, {
39
+ cumulativeRewardPerToken: bigint;
40
+ status: string;
41
+ }>, minPendingRewards?: number): Array<{
42
+ gatewayAddress: string;
43
+ delegatorAddress: string;
44
+ pendingRewards: number;
45
+ }>;
@@ -0,0 +1,262 @@
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 { type Address } from '@solana/kit';
28
+ import type { ArNSNameData, Gateway, GatewayRegistrySettings, VaultData } from '../types/io.js';
29
+ declare class BorshReader {
30
+ private data;
31
+ private offset;
32
+ constructor(data: Buffer, startOffset?: number);
33
+ readU8(): number;
34
+ readBool(): boolean;
35
+ readU16(): number;
36
+ readU32(): number;
37
+ readU64(): bigint;
38
+ readU64AsNumber(): number;
39
+ readI64(): bigint;
40
+ readI64AsNumber(): number;
41
+ readU128(): bigint;
42
+ readPubkey(): Address;
43
+ readString(): string;
44
+ readOptionI64(): number | undefined;
45
+ readOptionU32(): number | undefined;
46
+ readOptionU16(): number | undefined;
47
+ skip(bytes: number): void;
48
+ getOffset(): number;
49
+ remaining(): number;
50
+ readOptionPubkey(): Address | undefined;
51
+ readOptionString(): string | undefined;
52
+ readVecString(): string[];
53
+ readOptionVecString(): string[] | undefined;
54
+ readVecPubkey(): Address[];
55
+ readFixedU64Array(count: number): number[];
56
+ readFixedBytes(count: number): Buffer;
57
+ }
58
+ declare class BorshWriter {
59
+ private buf;
60
+ private offset;
61
+ constructor(size: number);
62
+ writeU8(val: number): void;
63
+ writeBool(val: boolean): void;
64
+ writeU16(val: number): void;
65
+ writeU32(val: number): void;
66
+ writeU64(val: bigint | number): void;
67
+ writeI64(val: bigint | number): void;
68
+ writePubkey(key: Address): void;
69
+ writeFixedBytes(data: Buffer | Uint8Array): void;
70
+ writeString(str: string): void;
71
+ writeOptionI64(val: number | undefined): void;
72
+ writeOptionU32(val: number | undefined): void;
73
+ writeOptionPubkey(key: Address | undefined): void;
74
+ writeOptionString(val: string | undefined): void;
75
+ writeOptionStringVec(val: string[] | undefined): void;
76
+ toBuffer(): Buffer;
77
+ getOffset(): number;
78
+ }
79
+ export declare function deserializeGatewayWithAccumulator(data: Buffer): Gateway & {
80
+ operator: string;
81
+ cumulativeRewardPerToken: bigint;
82
+ };
83
+ export declare function deserializeGateway(data: Buffer): Gateway & {
84
+ operator: string;
85
+ };
86
+ export declare function deserializeArnsRecord(data: Buffer): ArNSNameData & {
87
+ name: string;
88
+ owner: string;
89
+ };
90
+ export declare function deserializeVault(data: Buffer): VaultData & {
91
+ owner: string;
92
+ };
93
+ export type DeserializedDelegation = {
94
+ gateway: string;
95
+ delegator: string;
96
+ delegatedStake: number;
97
+ startTimestamp: number;
98
+ rewardDebt: bigint;
99
+ };
100
+ export declare function deserializeDelegation(data: Buffer): DeserializedDelegation;
101
+ export declare function deserializeBalance(data: Buffer): {
102
+ owner: string;
103
+ balance: number;
104
+ };
105
+ export declare function deserializeEpochSettings(data: Buffer): {
106
+ epochZeroStartTimestamp: number;
107
+ durationMs: number;
108
+ prescribedNameCount: number;
109
+ maxObservers: number;
110
+ };
111
+ export declare function deserializeArioConfig(data: Buffer): {
112
+ totalSupply: number;
113
+ protocolBalance: number;
114
+ circulatingSupply: number;
115
+ lockedSupply: number;
116
+ };
117
+ export declare function deserializeDemandFactor(data: Buffer): {
118
+ currentDemandFactor: number;
119
+ currentPeriod: number;
120
+ periodZeroStartTimestamp: number;
121
+ consecutivePeriodsWithMinDemandFactor: number;
122
+ trailingPeriodPurchases: number[];
123
+ trailingPeriodRevenues: number[];
124
+ fees: number[];
125
+ };
126
+ export declare function deserializeReservedName(data: Buffer): {
127
+ name: string;
128
+ target?: string;
129
+ endTimestamp?: number;
130
+ };
131
+ export declare function deserializeReturnedName(data: Buffer): {
132
+ name: string;
133
+ startTimestamp: number;
134
+ endTimestamp: number;
135
+ initiator: string;
136
+ premiumMultiplier: number;
137
+ };
138
+ export declare function deserializeWithdrawal(data: Buffer): {
139
+ owner: string;
140
+ vaultId: string;
141
+ gateway: string;
142
+ balance: number;
143
+ startTimestamp: number;
144
+ endTimestamp: number;
145
+ isDelegate: boolean;
146
+ };
147
+ export declare function deserializeRedelegationRecord(data: Buffer): {
148
+ delegator: string;
149
+ redelegationCount: number;
150
+ lastRedelegationAt: number;
151
+ feeResetAt: number;
152
+ };
153
+ export declare function deserializePrimaryNameRequest(data: Buffer): {
154
+ name: string;
155
+ initiator: string;
156
+ startTimestamp: number;
157
+ endTimestamp: number;
158
+ };
159
+ export declare function deserializeGarSettings(data: Buffer): GatewayRegistrySettings;
160
+ export declare function deserializeGarSupplyCounters(data: Buffer): {
161
+ totalStaked: number;
162
+ totalDelegated: number;
163
+ totalWithdrawn: number;
164
+ };
165
+ export declare function deserializeEpochSettingsFull(data: Buffer): {
166
+ currentEpochIndex: number;
167
+ genesisTimestamp: number;
168
+ epochDuration: number;
169
+ enabled: boolean;
170
+ prescribedObserverCount: number;
171
+ prescribedNameCount: number;
172
+ tenureWeightDuration: number;
173
+ maxTenureWeight: number;
174
+ gatewayRewardRatio: number;
175
+ observerRewardRatio: number;
176
+ maxConsecutiveFailures: number;
177
+ };
178
+ export declare function deserializeEpoch(data: Buffer): {
179
+ epochIndex: number;
180
+ startTimestamp: number;
181
+ endTimestamp: number;
182
+ totalEligibleRewards: number;
183
+ perGatewayReward: number;
184
+ perObserverReward: number;
185
+ rewardRate: number;
186
+ activeGatewayCount: number;
187
+ distributionIndex: number;
188
+ tallyIndex: number;
189
+ observerCount: number;
190
+ nameCount: number;
191
+ observationsSubmitted: number;
192
+ rewardsDistributed: number;
193
+ weightsTallied: number;
194
+ prescriptionsDone: number;
195
+ failureCounts: Uint16Array;
196
+ prescribedObservers: Address[];
197
+ prescribedObserverGateways: Address[];
198
+ prescribedNameHashes: Buffer[];
199
+ hasObserved: Uint8Array;
200
+ };
201
+ export declare function deserializeObservation(data: Buffer): {
202
+ epochIndex: number;
203
+ observer: string;
204
+ gatewayResults: Buffer;
205
+ gatewayCount: number;
206
+ reportTxId: string;
207
+ submittedAt: number;
208
+ };
209
+ export declare function deserializeAntConfig(data: Buffer): {
210
+ mint: string;
211
+ name: string;
212
+ ticker: string;
213
+ logo: string;
214
+ description: string;
215
+ keywords: string[];
216
+ owner: string;
217
+ version: number;
218
+ };
219
+ export declare function deserializeAntControllers(data: Buffer): {
220
+ mint: string;
221
+ controllers: string[];
222
+ };
223
+ export declare function deserializeAntRecord(data: Buffer): {
224
+ mint: string;
225
+ undername: string;
226
+ transactionId: string;
227
+ targetProtocol: number;
228
+ ttlSeconds: number;
229
+ priority?: number;
230
+ owner?: string;
231
+ };
232
+ export declare function deserializeAntRecordMetadata(data: Buffer): {
233
+ mint: string;
234
+ displayName?: string;
235
+ logo?: string;
236
+ description?: string;
237
+ keywords?: string[];
238
+ };
239
+ export type DeserializedAclEntry = {
240
+ asset: string;
241
+ role: number;
242
+ };
243
+ export declare function deserializeAclConfig(data: Buffer): {
244
+ user: string;
245
+ pageCount: bigint;
246
+ totalEntries: bigint;
247
+ };
248
+ export declare function deserializeAclPage(data: Buffer): {
249
+ user: string;
250
+ pageIdx: bigint;
251
+ entries: DeserializedAclEntry[];
252
+ };
253
+ export declare function deserializePrimaryName(data: Buffer): {
254
+ owner: string;
255
+ name: string;
256
+ startTimestamp: number;
257
+ };
258
+ export declare function deserializeAllowlist(data: Buffer): {
259
+ gateway: string;
260
+ delegate: string;
261
+ };
262
+ export { BorshReader, BorshWriter };