@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,111 @@
|
|
|
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 { 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 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 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 const MAINNET_PROGRAM_IDS = {
|
|
75
|
+
core: address('73YoECm6NKXpVRoe5f1Q9BcP5DJGPFUjnFy6AxBE5Nvh'),
|
|
76
|
+
gar: address('89fNiiwgpFSPHKuqfNUkgYTYjtAJAhyqHjXmgXeppGpf'),
|
|
77
|
+
arns: address('2yCUx5edFvUrkibYaUa2ZXWyx9kuJkS8CwyzsgHPWdZZ'),
|
|
78
|
+
ant: address('2MWexMHfMhGJwMHv9Qm9YAVCqjUFUJwDJAysW4oCUGk5'),
|
|
79
|
+
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 const MAINNET_ATTESTOR_PUBKEY = address('7XtUnotZAeYZNzVSYV5nb7S9YH9qHXyVFM6NeNMu6efE');
|
|
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 const MAINNET_AUTHORITY_PUBKEY = address('45ZuEb1Jk7pbjshD1BVasBekAXhimdWuJjyswQzMyTB1');
|
|
93
|
+
// TODO(mainnet): placeholder — this reuses the devnet mint and is WRONG for
|
|
94
|
+
// mainnet. Replace with the real mainnet ARIO mint once it is known.
|
|
95
|
+
/** ARIO SPL Token mint on Solana mainnet-beta. */
|
|
96
|
+
export const MAINNET_ARIO_MINT = address('6vTw5CysRXQ4ybbHkDUiisHWVsBeMtUzYvJqs2iqHyaN');
|
|
97
|
+
/**
|
|
98
|
+
* AR.IO program IDs deployed on Solana devnet (staging).
|
|
99
|
+
*
|
|
100
|
+
* Shape matches the `programIds` argument of
|
|
101
|
+
* `ARIO.init({ backend: 'solana', programIds, ... })`.
|
|
102
|
+
*/
|
|
103
|
+
export const DEVNET_PROGRAM_IDS = {
|
|
104
|
+
core: address('8Njx9wPkXiNzDCgjwVsJFRjpAEV34gGW3n8DzX3V23m1'),
|
|
105
|
+
gar: address('7WsDTrtZBsfKtnP33XkjuqXCY69JE7n4QVYpynqJCFxz'),
|
|
106
|
+
arns: address('6EZNezcg4rc5hnh8HG34vGquT3WpW5xXypzPb24uyEpp'),
|
|
107
|
+
ant: address('DbHbRwUD1oAn1mrDSqtWtvwGcNrmhWdD2g8L4xmeQ7NX'),
|
|
108
|
+
antEscrow: address('bttco5oAnBwCucG63iKokBJCZmNr493f3Ewe9LM3oTx'),
|
|
109
|
+
};
|
|
110
|
+
/** ARIO SPL Token mint on devnet (Staging v2). */
|
|
111
|
+
export const DEVNET_ARIO_MINT = address('6vTw5CysRXQ4ybbHkDUiisHWVsBeMtUzYvJqs2iqHyaN');
|
|
@@ -0,0 +1,146 @@
|
|
|
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 { address } from '@solana/kit';
|
|
23
|
+
// Program IDs — placeholder addresses (replace with deployed program IDs)
|
|
24
|
+
export const ARIO_CORE_PROGRAM_ID = address('73YoECm6NKXpVRoe5f1Q9BcP5DJGPFUjnFy6AxBE5Nvh');
|
|
25
|
+
export const ARIO_GAR_PROGRAM_ID = address('89fNiiwgpFSPHKuqfNUkgYTYjtAJAhyqHjXmgXeppGpf');
|
|
26
|
+
export const ARIO_ARNS_PROGRAM_ID = address('2yCUx5edFvUrkibYaUa2ZXWyx9kuJkS8CwyzsgHPWdZZ');
|
|
27
|
+
export const ARIO_ANT_PROGRAM_ID = address('2MWexMHfMhGJwMHv9Qm9YAVCqjUFUJwDJAysW4oCUGk5');
|
|
28
|
+
export const ARIO_ANT_ESCROW_PROGRAM_ID = address('5HZhe9UqKL5zAsdz81nuuaxV41h8bFhudzxxBigAQndM');
|
|
29
|
+
export const ARIO_TOKEN_MINT_ADDRESS = address('DcNnMuFxwhgV4WY1HVSaSEgr92bv2b1vUvEKiNxWqHdF');
|
|
30
|
+
export const MPL_CORE_PROGRAM_ID = address('CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d');
|
|
31
|
+
// Token constants
|
|
32
|
+
export const TOKEN_DECIMALS = 6;
|
|
33
|
+
export const ONE_TOKEN = 1_000_000; // 1 ARIO = 1,000,000 mARIO
|
|
34
|
+
export const RATE_SCALE = 1_000_000;
|
|
35
|
+
/**
|
|
36
|
+
* Scaling factor for the per-share reward accumulator
|
|
37
|
+
* `Gateway.cumulative_reward_per_token` in `ario-gar`. Must match the
|
|
38
|
+
* `REWARD_PRECISION` constant in `programs/ario-gar/src/state/mod.rs`.
|
|
39
|
+
*/
|
|
40
|
+
export const REWARD_PRECISION = 1000000000000000000n; // 1e18
|
|
41
|
+
// =========================================
|
|
42
|
+
// PDA Seeds — ario-core
|
|
43
|
+
// =========================================
|
|
44
|
+
export const ARIO_CONFIG_SEED = Buffer.from('ario_config');
|
|
45
|
+
export const VAULT_SEED = Buffer.from('vault');
|
|
46
|
+
export const VAULT_COUNTER_SEED = Buffer.from('vault_counter');
|
|
47
|
+
export const BALANCE_SEED = Buffer.from('balance');
|
|
48
|
+
export const PRIMARY_NAME_SEED = Buffer.from('primary_name');
|
|
49
|
+
export const PRIMARY_NAME_REQUEST_SEED = Buffer.from('primary_name_request');
|
|
50
|
+
export const PRIMARY_NAME_REVERSE_SEED = Buffer.from('primary_name_reverse');
|
|
51
|
+
// =========================================
|
|
52
|
+
// PDA Seeds — ario-gar
|
|
53
|
+
// =========================================
|
|
54
|
+
export const GATEWAY_REGISTRY_SEED = Buffer.from('gateway_registry');
|
|
55
|
+
export const GAR_SETTINGS_SEED = Buffer.from('gar_settings');
|
|
56
|
+
export const GATEWAY_SEED = Buffer.from('gateway');
|
|
57
|
+
export const DELEGATION_SEED = Buffer.from('delegation');
|
|
58
|
+
export const WITHDRAWAL_SEED = Buffer.from('withdrawal');
|
|
59
|
+
export const WITHDRAWAL_COUNTER_SEED = Buffer.from('withdrawal_counter');
|
|
60
|
+
export const ALLOWLIST_SEED = Buffer.from('allowlist');
|
|
61
|
+
export const EPOCH_SEED = Buffer.from('epoch');
|
|
62
|
+
export const EPOCH_SETTINGS_SEED = Buffer.from('epoch_settings');
|
|
63
|
+
export const OBSERVATION_SEED = Buffer.from('observation');
|
|
64
|
+
export const REDELEGATION_SEED = Buffer.from('redelegation');
|
|
65
|
+
export const OBSERVER_LOOKUP_SEED = Buffer.from('observer_lookup');
|
|
66
|
+
// =========================================
|
|
67
|
+
// PDA Seeds — ario-arns
|
|
68
|
+
// =========================================
|
|
69
|
+
export const ARNS_REGISTRY_SEED = Buffer.from('name_registry');
|
|
70
|
+
export const ARNS_SETTINGS_SEED = Buffer.from('arns_config');
|
|
71
|
+
export const ARNS_RECORD_SEED = Buffer.from('arns_record');
|
|
72
|
+
export const RESERVED_NAME_SEED = Buffer.from('reserved_name');
|
|
73
|
+
export const RETURNED_NAME_SEED = Buffer.from('returned_name');
|
|
74
|
+
export const DEMAND_FACTOR_SEED = Buffer.from('demand_factor');
|
|
75
|
+
/**
|
|
76
|
+
* Byte offsets of fixed-size fields within an `ArnsRecord` account.
|
|
77
|
+
*
|
|
78
|
+
* Used as `memcmp` filter offsets for `getProgramAccounts` so callers
|
|
79
|
+
* can resolve "which ArNS record points at this ANT mint?" as a true
|
|
80
|
+
* point query instead of scanning every record. Mirrors the
|
|
81
|
+
* `ArnsRecord::ANT_OFFSET` / `OWNER_OFFSET` constants in
|
|
82
|
+
* `contracts/programs/ario-arns/src/state/mod.rs` — keep them in
|
|
83
|
+
* sync if the on-chain layout ever changes.
|
|
84
|
+
*/
|
|
85
|
+
export const ARNS_RECORD_NAME_HASH_OFFSET = 8;
|
|
86
|
+
export const ARNS_RECORD_OWNER_OFFSET = 8 + 32; // 40
|
|
87
|
+
export const ARNS_RECORD_ANT_OFFSET = 8 + 32 + 32; // 72
|
|
88
|
+
// =========================================
|
|
89
|
+
// PDA Seeds — ario-ant
|
|
90
|
+
// =========================================
|
|
91
|
+
export const ANT_CONFIG_VERSION = 1;
|
|
92
|
+
export const ANT_CONFIG_SEED = Buffer.from('ant_config');
|
|
93
|
+
export const ANT_CONTROLLERS_SEED = Buffer.from('ant_controllers');
|
|
94
|
+
export const ANT_RECORD_SEED = Buffer.from('ant_record');
|
|
95
|
+
export const ANT_RECORD_META_SEED = Buffer.from('ant_record_meta');
|
|
96
|
+
// Per-user paginated ACL (ADR-012). See `docs/ACCOUNT_SCALING_PATTERNS.md`
|
|
97
|
+
// Pattern C: a head `AclConfig` plus deterministically-addressed `AclPage`s
|
|
98
|
+
// indexed by `u64` little-endian page idx.
|
|
99
|
+
export const ACL_CONFIG_SEED = Buffer.from('acl_config');
|
|
100
|
+
export const ACL_PAGE_SEED = Buffer.from('acl_page');
|
|
101
|
+
/**
|
|
102
|
+
* Maximum live entries per `AclPage` (must match the on-chain constant).
|
|
103
|
+
*
|
|
104
|
+
* Each entry is 33 bytes (`Pubkey + u8`). 256 entries = 8_448 bytes raw —
|
|
105
|
+
* fits the default 32 KiB BPF heap with margin and stays well under the
|
|
106
|
+
* 10 KiB per-tx realloc cap when allocated at full size.
|
|
107
|
+
*/
|
|
108
|
+
export const MAX_ACL_PAGE_ENTRIES = 256;
|
|
109
|
+
/** ACL relationship roles (encoded as `u8` on each `AclEntry`). */
|
|
110
|
+
export const ACL_ROLE_OWNER = 0;
|
|
111
|
+
export const ACL_ROLE_CONTROLLER = 1;
|
|
112
|
+
// =========================================
|
|
113
|
+
// PDA Seeds — ario-ant-escrow
|
|
114
|
+
// =========================================
|
|
115
|
+
export const ESCROW_ANT_SEED = Buffer.from('escrow_ant');
|
|
116
|
+
export const ESCROW_TOKEN_SEED = Buffer.from('escrow_token');
|
|
117
|
+
export const ESCROW_VAULT_SEED = Buffer.from('escrow_vault');
|
|
118
|
+
// =========================================
|
|
119
|
+
// ario-ant-escrow protocol constants (must match Rust state.rs)
|
|
120
|
+
// =========================================
|
|
121
|
+
export const ESCROW_PROTOCOL_ARWEAVE = 0;
|
|
122
|
+
export const ESCROW_PROTOCOL_ETHEREUM = 1;
|
|
123
|
+
export const ESCROW_ARWEAVE_PUBKEY_LEN = 512;
|
|
124
|
+
export const ESCROW_ETHEREUM_PUBKEY_LEN = 20;
|
|
125
|
+
export const ESCROW_RECIPIENT_PUBKEY_MAX_LEN = 512;
|
|
126
|
+
export const ESCROW_ASSET_TYPE_TOKEN = 1;
|
|
127
|
+
export const ESCROW_ASSET_TYPE_VAULT = 2;
|
|
128
|
+
// =========================================
|
|
129
|
+
// Protocol constants (must match Rust)
|
|
130
|
+
// =========================================
|
|
131
|
+
// Multi-protocol target constants (must match ario-ant/src/state.rs)
|
|
132
|
+
export const PROTOCOL_ARWEAVE = 0;
|
|
133
|
+
export const PROTOCOL_IPFS = 1;
|
|
134
|
+
export const MAX_TARGET_LENGTH = 128;
|
|
135
|
+
export const MAX_NAME_LENGTH = 51;
|
|
136
|
+
export const MIN_TTL_SECONDS = 60;
|
|
137
|
+
export const MAX_TTL_SECONDS = 86_400;
|
|
138
|
+
export const MAX_CONTROLLERS = 10;
|
|
139
|
+
export const EPOCH_DURATION_SECONDS = 86_400;
|
|
140
|
+
export const WITHDRAWAL_LOCK_PERIOD = 30 * 86_400; // 30 days in seconds
|
|
141
|
+
export const MIN_OPERATOR_STAKE = 20_000 * ONE_TOKEN; // 20,000 ARIO
|
|
142
|
+
export const MIN_DELEGATION_AMOUNT = 10 * ONE_TOKEN; // 10 ARIO
|
|
143
|
+
export const LEASE_GRACE_PERIOD = 14 * 86_400; // 14 days
|
|
144
|
+
export const PRIMARY_NAME_REQUEST_EXPIRY = 7 * 86_400; // 7 days
|
|
145
|
+
export const MAX_GATEWAYS = 3000;
|
|
146
|
+
export const MAX_NAMES = 50_000;
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
* Delegation balance math.
|
|
18
|
+
*
|
|
19
|
+
* On-chain, `Delegation.amount` is the last-settled principal. Pending rewards
|
|
20
|
+
* are tracked separately via the gateway's per-share accumulator
|
|
21
|
+
* (`Gateway.cumulative_reward_per_token`) and the delegate's snapshot of that
|
|
22
|
+
* accumulator at the last settlement (`Delegation.reward_debt`). The
|
|
23
|
+
* `distribute_epoch` instruction advances the accumulator but does NOT touch
|
|
24
|
+
* per-`Delegation.amount` — that field is updated lazily on the next
|
|
25
|
+
* delegation interaction (or via the permissionless
|
|
26
|
+
* `compound_delegation_rewards` instruction).
|
|
27
|
+
*
|
|
28
|
+
* Off-chain readers (indexers, wallets, the network portal) that want to show
|
|
29
|
+
* a delegate's current balance must therefore compute the live value from the
|
|
30
|
+
* accumulator + reward_debt; reading `Delegation.amount` directly under-reports
|
|
31
|
+
* every epoch of pending rewards.
|
|
32
|
+
*
|
|
33
|
+
* This module mirrors the on-chain `settle_delegate_rewards` math from
|
|
34
|
+
* `programs/ario-gar/src/state/mod.rs` so the SDK can return live values from
|
|
35
|
+
* its read-side methods (`getGatewayDelegates`, `getDelegations`,
|
|
36
|
+
* `getAllDelegates`) without needing an on-chain settlement call.
|
|
37
|
+
*
|
|
38
|
+
* See `INVARIANTS.md` in the contracts repo for the broader stake-pool
|
|
39
|
+
* invariant context.
|
|
40
|
+
*/
|
|
41
|
+
import { REWARD_PRECISION } from './constants.js';
|
|
42
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
43
|
+
/**
|
|
44
|
+
* Compute the live delegation balance: the last-settled principal plus any
|
|
45
|
+
* pending rewards accrued since the last settlement.
|
|
46
|
+
*
|
|
47
|
+
* Mirrors `settle_delegate_rewards` in
|
|
48
|
+
* `programs/ario-gar/src/state/mod.rs` — including the u128 overflow-safe
|
|
49
|
+
* quotient/remainder split and the saturating-to-`u64::MAX` cap at the end —
|
|
50
|
+
* so a value computed here matches what the on-chain instruction would write
|
|
51
|
+
* if it were called right now.
|
|
52
|
+
*
|
|
53
|
+
* @param delegatedStake - `Delegation.amount` (u64 → number).
|
|
54
|
+
* @param rewardDebt - `Delegation.reward_debt` (u128 → bigint).
|
|
55
|
+
* @param cumulativeRewardPerToken - `Gateway.cumulative_reward_per_token` (u128 → bigint).
|
|
56
|
+
* @returns The delegate's live balance in mARIO, saturating-capped at `u64::MAX`.
|
|
57
|
+
*/
|
|
58
|
+
export function computeLiveDelegationBalance({ delegatedStake, rewardDebt, cumulativeRewardPerToken, }) {
|
|
59
|
+
// Fast paths matching the on-chain `if` guards: zero principal or no
|
|
60
|
+
// accumulator delta means no pending rewards to settle.
|
|
61
|
+
if (delegatedStake <= 0 || cumulativeRewardPerToken <= rewardDebt) {
|
|
62
|
+
return delegatedStake;
|
|
63
|
+
}
|
|
64
|
+
const amount = BigInt(delegatedStake);
|
|
65
|
+
const delta = cumulativeRewardPerToken - rewardDebt;
|
|
66
|
+
// Quotient / remainder split mirrors the on-chain `checked_mul ... unwrap_or_else`
|
|
67
|
+
// fallback. BigInt has no native overflow, so we always take the split path
|
|
68
|
+
// for parity; the result is identical either way.
|
|
69
|
+
const quot = delta / REWARD_PRECISION;
|
|
70
|
+
const rem = delta % REWARD_PRECISION;
|
|
71
|
+
const fromQuot = amount * quot; // saturating not needed — BigInt is unbounded
|
|
72
|
+
const fromRem = (amount * rem) / REWARD_PRECISION;
|
|
73
|
+
const pending = fromQuot + fromRem;
|
|
74
|
+
// Saturating cap at u64::MAX to match the on-chain `u64::try_from(...).unwrap_or(u64::MAX)`.
|
|
75
|
+
const live = amount + pending;
|
|
76
|
+
const capped = live > U64_MAX ? U64_MAX : live;
|
|
77
|
+
return Number(capped);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Select the delegations worth compounding, from decoded delegations + a map
|
|
81
|
+
* of their gateways' reward accumulators. Pure (no I/O) so it's unit-testable
|
|
82
|
+
* independently of RPC; `SolanaARIOReadable.getDelegationsToCompound` is just
|
|
83
|
+
* fetch+decode wrapped around this.
|
|
84
|
+
*
|
|
85
|
+
* A delegation is included when its pending reward (live balance − settled
|
|
86
|
+
* principal) exceeds `minPendingRewards`, EXCEPT when its gateway is `leaving`
|
|
87
|
+
* (those settle via `claim_delegate_from_leaving_gateway`, not compounding) or
|
|
88
|
+
* its gateway is missing/unreadable. Compounding sub-threshold dust only
|
|
89
|
+
* advances `reward_debt` for no balance gain, so it's filtered out.
|
|
90
|
+
*/
|
|
91
|
+
export function selectCompoundableDelegations(delegations, gatewaysByOperator, minPendingRewards = 0) {
|
|
92
|
+
const out = [];
|
|
93
|
+
for (const del of delegations) {
|
|
94
|
+
const gw = gatewaysByOperator.get(del.gateway);
|
|
95
|
+
if (!gw || gw.status === 'leaving')
|
|
96
|
+
continue;
|
|
97
|
+
const live = computeLiveDelegationBalance({
|
|
98
|
+
delegatedStake: del.delegatedStake,
|
|
99
|
+
rewardDebt: del.rewardDebt,
|
|
100
|
+
cumulativeRewardPerToken: gw.cumulativeRewardPerToken,
|
|
101
|
+
});
|
|
102
|
+
const pendingRewards = live - del.delegatedStake;
|
|
103
|
+
if (pendingRewards <= minPendingRewards)
|
|
104
|
+
continue;
|
|
105
|
+
out.push({
|
|
106
|
+
gatewayAddress: del.gateway,
|
|
107
|
+
delegatorAddress: del.delegator,
|
|
108
|
+
pendingRewards,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|