@thru/programs 0.4.1 → 0.4.2
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/dist/abi-manager/index.cjs +39 -2
- package/dist/abi-manager/index.cjs.map +1 -1
- package/dist/abi-manager/index.js +2 -2
- package/dist/amm/index.cjs +39 -2
- package/dist/amm/index.cjs.map +1 -1
- package/dist/amm/index.js +1 -1
- package/dist/bootstrap-addresses/index.cjs +41 -2
- package/dist/bootstrap-addresses/index.cjs.map +1 -1
- package/dist/bootstrap-addresses/index.d.cts +8 -1
- package/dist/bootstrap-addresses/index.d.ts +8 -1
- package/dist/bootstrap-addresses/index.js +1 -1
- package/dist/{chunk-TRPUGPZJ.js → chunk-2FFCNXCE.js} +58 -5
- package/dist/chunk-2FFCNXCE.js.map +1 -0
- package/dist/{chunk-QCJFKBAS.js → chunk-I3DLOUB4.js} +3 -3
- package/dist/{chunk-QCJFKBAS.js.map → chunk-I3DLOUB4.js.map} +1 -1
- package/dist/clob/index.cjs +41 -2
- package/dist/clob/index.cjs.map +1 -1
- package/dist/clob/index.d.cts +7 -1
- package/dist/clob/index.d.ts +7 -1
- package/dist/clob/index.js +3 -2
- package/dist/clob/index.js.map +1 -1
- package/dist/deploy/index.cjs +39 -2
- package/dist/deploy/index.cjs.map +1 -1
- package/dist/deploy/index.js +3 -3
- package/dist/oracle/index.cjs +39 -2
- package/dist/oracle/index.cjs.map +1 -1
- package/dist/oracle/index.js +1 -1
- package/dist/passkey-manager/index.cjs +42 -5
- package/dist/passkey-manager/index.cjs.map +1 -1
- package/dist/passkey-manager/index.js +1 -1
- package/dist/perp/index.cjs +1785 -162
- package/dist/perp/index.cjs.map +1 -1
- package/dist/perp/index.d.cts +558 -13
- package/dist/perp/index.d.ts +558 -13
- package/dist/perp/index.js +1749 -163
- package/dist/perp/index.js.map +1 -1
- package/dist/ratelimit/index.cjs +4757 -0
- package/dist/ratelimit/index.cjs.map +1 -0
- package/dist/ratelimit/index.d.cts +171 -0
- package/dist/ratelimit/index.d.ts +171 -0
- package/dist/ratelimit/index.js +4527 -0
- package/dist/ratelimit/index.js.map +1 -0
- package/package.json +7 -2
- package/src/bootstrap-addresses/index.test.ts +17 -0
- package/src/bootstrap-addresses/index.ts +12 -0
- package/src/clob/index.ts +7 -0
- package/src/perp/abi/thru/program/perp/types.ts +1949 -149
- package/src/perp/index.test.ts +189 -3
- package/src/perp/index.ts +316 -3
- package/src/ratelimit/abi/thru/program/ratelimit/types.ts +5448 -0
- package/src/ratelimit/accounts.ts +105 -0
- package/src/ratelimit/constants.ts +49 -0
- package/src/ratelimit/derivation.ts +93 -0
- package/src/ratelimit/index.test.ts +185 -0
- package/src/ratelimit/index.ts +30 -0
- package/src/ratelimit/instructions.ts +244 -0
- package/tsup.config.ts +1 -0
- package/dist/chunk-TRPUGPZJ.js.map +0 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
declare const RATELIMIT_INSTRUCTION_CALL = 4;
|
|
2
|
+
declare const RATELIMIT_ERRORS: Readonly<{
|
|
3
|
+
readonly INVALID_INSTRUCTION: 20993n;
|
|
4
|
+
readonly INVALID_ACCOUNT: 20994n;
|
|
5
|
+
readonly INVALID_CONFIG: 20995n;
|
|
6
|
+
readonly UNAUTHORIZED: 20996n;
|
|
7
|
+
readonly CREATE_FAILED: 20997n;
|
|
8
|
+
readonly WRITE_FAILED: 20998n;
|
|
9
|
+
readonly PAUSED: 20999n;
|
|
10
|
+
readonly TARGET_MISMATCH: 21000n;
|
|
11
|
+
readonly INSTRUCTION_REJECTED: 21001n;
|
|
12
|
+
readonly AMOUNT_PER_CALL_EXCEEDED: 21002n;
|
|
13
|
+
readonly BUCKET_MISMATCH: 21003n;
|
|
14
|
+
readonly ATTESTER_REQUIRED: 21004n;
|
|
15
|
+
readonly CALL_LIMIT_EXCEEDED: 21005n;
|
|
16
|
+
readonly AMOUNT_LIMIT_EXCEEDED: 21006n;
|
|
17
|
+
readonly TARGET_FAILED: 21007n;
|
|
18
|
+
readonly GATE_NOT_RATE_LIMITED: 21153n;
|
|
19
|
+
}>;
|
|
20
|
+
declare const RATELIMIT_POLICY_MAGIC = 8241996802156358705n;
|
|
21
|
+
declare const RATELIMIT_BUCKET_MAGIC = 8241996801920690993n;
|
|
22
|
+
declare const RATELIMIT_RULE_MAX = 4;
|
|
23
|
+
declare const RATELIMIT_CONSTRAINT_MAX = 4;
|
|
24
|
+
declare const RATELIMIT_NO_ACCOUNT = 65535;
|
|
25
|
+
declare const RATELIMIT_POLICY_FLAG_PAUSED = 1;
|
|
26
|
+
declare const RATELIMIT_POLICY_FLAG_VERIFIED = 128;
|
|
27
|
+
declare const RATELIMIT_KEY_GLOBAL = 0;
|
|
28
|
+
declare const RATELIMIT_KEY_FEE_PAYER = 1;
|
|
29
|
+
declare const RATELIMIT_KEY_INSTR_ACCOUNT = 2;
|
|
30
|
+
declare const RATELIMIT_KEY_ATTESTED = 3;
|
|
31
|
+
declare const RATELIMIT_CLOCK_SLOT = 0;
|
|
32
|
+
declare const RATELIMIT_CLOCK_UNIX_SECONDS = 1;
|
|
33
|
+
declare const RATELIMIT_CONFIG_SIZE = 309;
|
|
34
|
+
declare const RATELIMIT_POLICY_SIZE = 390;
|
|
35
|
+
declare const RATELIMIT_BUCKET_SIZE = 113;
|
|
36
|
+
declare const RATELIMIT_CALL_ARGS_SIZE = 8;
|
|
37
|
+
declare const RATELIMIT_CALL_BUCKET_SIZE = 36;
|
|
38
|
+
|
|
39
|
+
type AddressInput$1 = string | Uint8Array;
|
|
40
|
+
interface RatelimitDerivedAddress {
|
|
41
|
+
address: string;
|
|
42
|
+
bytes: Uint8Array;
|
|
43
|
+
seed: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
/** Seed of a policy: sha256("tn_ratelimit_verified_policy_v1" || target ||
|
|
46
|
+
* policy_id) when verified, else sha256("tn_ratelimit_policy_v1" || admin ||
|
|
47
|
+
* target || policy_id). A VERIFIED policy is created with the target's
|
|
48
|
+
* manager meta account and its address does not depend on the admin. */
|
|
49
|
+
declare function ratelimitPolicySeed(options: {
|
|
50
|
+
target: AddressInput$1;
|
|
51
|
+
policyId: bigint | number;
|
|
52
|
+
verified: boolean;
|
|
53
|
+
admin?: AddressInput$1;
|
|
54
|
+
}): Uint8Array;
|
|
55
|
+
declare function deriveRatelimitPolicyAddress(programAddress: AddressInput$1, options: Parameters<typeof ratelimitPolicySeed>[0]): RatelimitDerivedAddress;
|
|
56
|
+
/** Bucket key for GLOBAL rules. */
|
|
57
|
+
declare const RATELIMIT_GLOBAL_KEY: Uint8Array;
|
|
58
|
+
/** sha256("tn_ratelimit_bucket_v1" || policy || rule_idx(u8) || key). */
|
|
59
|
+
declare function deriveRatelimitBucketAddress(programAddress: AddressInput$1, policy: AddressInput$1, ruleIdx: number, key: AddressInput$1): RatelimitDerivedAddress;
|
|
60
|
+
/** sha256("tn_ratelimit_authority_v1" || policy). */
|
|
61
|
+
declare function deriveRatelimitAuthorityAddress(programAddress: AddressInput$1, policy: AddressInput$1): RatelimitDerivedAddress;
|
|
62
|
+
|
|
63
|
+
type AddressInput = string | Uint8Array;
|
|
64
|
+
interface RatelimitRuleConfig {
|
|
65
|
+
/** RATELIMIT_KEY_* */
|
|
66
|
+
keyKind: number;
|
|
67
|
+
/** RATELIMIT_CLOCK_* */
|
|
68
|
+
clock: number;
|
|
69
|
+
/** INSTR_ACCOUNT only: offset of a u16 account index in the forwarded instruction. */
|
|
70
|
+
keyOffset?: number;
|
|
71
|
+
window: bigint;
|
|
72
|
+
/** 0 = unlimited */
|
|
73
|
+
maxCalls: bigint;
|
|
74
|
+
/** 0 = unlimited */
|
|
75
|
+
maxAmount: bigint;
|
|
76
|
+
}
|
|
77
|
+
interface RatelimitConstraintConfig {
|
|
78
|
+
idxOffset: number;
|
|
79
|
+
expected: AddressInput;
|
|
80
|
+
}
|
|
81
|
+
/** The admin-controlled policy configuration (tn_ratelimit_config_t).
|
|
82
|
+
* rule_cnt and constraint_cnt are the array lengths. */
|
|
83
|
+
interface RatelimitPolicyConfig {
|
|
84
|
+
/** Only RATELIMIT_POLICY_FLAG_PAUSED may be set. */
|
|
85
|
+
flags?: number;
|
|
86
|
+
selectorSz: number;
|
|
87
|
+
selectorOffset: number;
|
|
88
|
+
selectorValue: bigint;
|
|
89
|
+
instrSzMin: number;
|
|
90
|
+
instrSzMax: number;
|
|
91
|
+
amountSz: number;
|
|
92
|
+
amountOffset: number;
|
|
93
|
+
/** 0 = unlimited */
|
|
94
|
+
maxAmountPerCall: bigint;
|
|
95
|
+
attester?: AddressInput;
|
|
96
|
+
constraints?: readonly RatelimitConstraintConfig[];
|
|
97
|
+
rules: readonly RatelimitRuleConfig[];
|
|
98
|
+
}
|
|
99
|
+
/** Encodes the 309-byte packed tn_ratelimit_config_t. Unused rule and
|
|
100
|
+
* constraint slots are zero. */
|
|
101
|
+
declare function encodeRatelimitConfig(config: RatelimitPolicyConfig): Uint8Array;
|
|
102
|
+
interface CreateRatelimitPolicyOptions {
|
|
103
|
+
policyAccountIdx: number;
|
|
104
|
+
/** The target's manager meta account index for a VERIFIED policy, or
|
|
105
|
+
* omitted (NO_ACCOUNT) for an unverified policy. */
|
|
106
|
+
metaAccountIdx?: number;
|
|
107
|
+
admin: AddressInput;
|
|
108
|
+
target: AddressInput;
|
|
109
|
+
policyId: bigint;
|
|
110
|
+
config: RatelimitPolicyConfig;
|
|
111
|
+
/** Creation state proof of the policy account. */
|
|
112
|
+
proof: Uint8Array;
|
|
113
|
+
}
|
|
114
|
+
/** CREATE_POLICY (0): u32 tag || CreatePolicyArgs || proof. */
|
|
115
|
+
declare function buildCreateRatelimitPolicyInstruction(options: CreateRatelimitPolicyOptions): Uint8Array;
|
|
116
|
+
/** UPDATE_POLICY (1): replaces the config. */
|
|
117
|
+
declare function buildUpdateRatelimitPolicyInstruction(policyAccountIdx: number, config: RatelimitPolicyConfig): Uint8Array;
|
|
118
|
+
/** SET_ADMIN (2). */
|
|
119
|
+
declare function buildSetRatelimitAdminInstruction(policyAccountIdx: number, newAdmin: AddressInput): Uint8Array;
|
|
120
|
+
/** CREATE_AUTHORITY (3): u32 tag || CreateAuthorityArgs || proof. */
|
|
121
|
+
declare function buildCreateRatelimitAuthorityInstruction(policyAccountIdx: number, authorityAccountIdx: number, proof: Uint8Array): Uint8Array;
|
|
122
|
+
interface RatelimitCallBucket {
|
|
123
|
+
bucketAccountIdx: number;
|
|
124
|
+
/** Creation proof when the bucket does not exist yet. */
|
|
125
|
+
proof?: Uint8Array;
|
|
126
|
+
/** ATTESTED rules only; must be omitted (zero) for every other key kind. */
|
|
127
|
+
key?: AddressInput;
|
|
128
|
+
}
|
|
129
|
+
interface RatelimitCallOptions {
|
|
130
|
+
policyAccountIdx: number;
|
|
131
|
+
targetAccountIdx: number;
|
|
132
|
+
/** The policy's authority PDA to sign for, or omitted. */
|
|
133
|
+
authorityAccountIdx?: number;
|
|
134
|
+
/** One entry per policy rule, in rule order. */
|
|
135
|
+
buckets: readonly RatelimitCallBucket[];
|
|
136
|
+
/** The instruction forwarded to the target. */
|
|
137
|
+
inner: Uint8Array;
|
|
138
|
+
}
|
|
139
|
+
/** CALL (4): u32 tag || CallArgs || CallBucket[rule_cnt] || proofs of the
|
|
140
|
+
* buckets with a proof, in rule order || inner. The ABI only describes the
|
|
141
|
+
* fixed CallArgs header, because rule_cnt lives in the policy account. */
|
|
142
|
+
declare function buildRatelimitCallInstruction(options: RatelimitCallOptions): Uint8Array;
|
|
143
|
+
|
|
144
|
+
interface RatelimitPolicyAccount {
|
|
145
|
+
admin: string;
|
|
146
|
+
target: string;
|
|
147
|
+
policyId: bigint;
|
|
148
|
+
/** RATELIMIT_POLICY_FLAG_* */
|
|
149
|
+
stateFlags: number;
|
|
150
|
+
config: RatelimitPolicyConfig;
|
|
151
|
+
/** Raw 309-byte config, for exact comparison with encodeRatelimitConfig. */
|
|
152
|
+
configBytes: Uint8Array;
|
|
153
|
+
}
|
|
154
|
+
interface RatelimitBucketAccount {
|
|
155
|
+
policy: string;
|
|
156
|
+
key: Uint8Array;
|
|
157
|
+
ruleIdx: number;
|
|
158
|
+
windowStart: bigint;
|
|
159
|
+
calls: bigint;
|
|
160
|
+
amount: bigint;
|
|
161
|
+
totalCalls: bigint;
|
|
162
|
+
totalAmount: bigint;
|
|
163
|
+
}
|
|
164
|
+
/** Parses policy account data; returns null on a size or magic mismatch. */
|
|
165
|
+
declare function parseRatelimitPolicyAccount(data: Uint8Array): RatelimitPolicyAccount | null;
|
|
166
|
+
/** Parses bucket account data; returns null on a size or magic mismatch. */
|
|
167
|
+
declare function parseRatelimitBucketAccount(data: Uint8Array): RatelimitBucketAccount | null;
|
|
168
|
+
|
|
169
|
+
declare const RATELIMIT_PROGRAM_ADDRESS: string;
|
|
170
|
+
|
|
171
|
+
export { type CreateRatelimitPolicyOptions, RATELIMIT_BUCKET_MAGIC, RATELIMIT_BUCKET_SIZE, RATELIMIT_CALL_ARGS_SIZE, RATELIMIT_CALL_BUCKET_SIZE, RATELIMIT_CLOCK_SLOT, RATELIMIT_CLOCK_UNIX_SECONDS, RATELIMIT_CONFIG_SIZE, RATELIMIT_CONSTRAINT_MAX, RATELIMIT_ERRORS, RATELIMIT_GLOBAL_KEY, RATELIMIT_INSTRUCTION_CALL, RATELIMIT_KEY_ATTESTED, RATELIMIT_KEY_FEE_PAYER, RATELIMIT_KEY_GLOBAL, RATELIMIT_KEY_INSTR_ACCOUNT, RATELIMIT_NO_ACCOUNT, RATELIMIT_POLICY_FLAG_PAUSED, RATELIMIT_POLICY_FLAG_VERIFIED, RATELIMIT_POLICY_MAGIC, RATELIMIT_POLICY_SIZE, RATELIMIT_PROGRAM_ADDRESS, RATELIMIT_RULE_MAX, type RatelimitBucketAccount, type RatelimitCallBucket, type RatelimitCallOptions, type RatelimitConstraintConfig, type RatelimitDerivedAddress, type RatelimitPolicyAccount, type RatelimitPolicyConfig, type RatelimitRuleConfig, buildCreateRatelimitAuthorityInstruction, buildCreateRatelimitPolicyInstruction, buildRatelimitCallInstruction, buildSetRatelimitAdminInstruction, buildUpdateRatelimitPolicyInstruction, deriveRatelimitAuthorityAddress, deriveRatelimitBucketAddress, deriveRatelimitPolicyAddress, encodeRatelimitConfig, parseRatelimitBucketAccount, parseRatelimitPolicyAccount };
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
declare const RATELIMIT_INSTRUCTION_CALL = 4;
|
|
2
|
+
declare const RATELIMIT_ERRORS: Readonly<{
|
|
3
|
+
readonly INVALID_INSTRUCTION: 20993n;
|
|
4
|
+
readonly INVALID_ACCOUNT: 20994n;
|
|
5
|
+
readonly INVALID_CONFIG: 20995n;
|
|
6
|
+
readonly UNAUTHORIZED: 20996n;
|
|
7
|
+
readonly CREATE_FAILED: 20997n;
|
|
8
|
+
readonly WRITE_FAILED: 20998n;
|
|
9
|
+
readonly PAUSED: 20999n;
|
|
10
|
+
readonly TARGET_MISMATCH: 21000n;
|
|
11
|
+
readonly INSTRUCTION_REJECTED: 21001n;
|
|
12
|
+
readonly AMOUNT_PER_CALL_EXCEEDED: 21002n;
|
|
13
|
+
readonly BUCKET_MISMATCH: 21003n;
|
|
14
|
+
readonly ATTESTER_REQUIRED: 21004n;
|
|
15
|
+
readonly CALL_LIMIT_EXCEEDED: 21005n;
|
|
16
|
+
readonly AMOUNT_LIMIT_EXCEEDED: 21006n;
|
|
17
|
+
readonly TARGET_FAILED: 21007n;
|
|
18
|
+
readonly GATE_NOT_RATE_LIMITED: 21153n;
|
|
19
|
+
}>;
|
|
20
|
+
declare const RATELIMIT_POLICY_MAGIC = 8241996802156358705n;
|
|
21
|
+
declare const RATELIMIT_BUCKET_MAGIC = 8241996801920690993n;
|
|
22
|
+
declare const RATELIMIT_RULE_MAX = 4;
|
|
23
|
+
declare const RATELIMIT_CONSTRAINT_MAX = 4;
|
|
24
|
+
declare const RATELIMIT_NO_ACCOUNT = 65535;
|
|
25
|
+
declare const RATELIMIT_POLICY_FLAG_PAUSED = 1;
|
|
26
|
+
declare const RATELIMIT_POLICY_FLAG_VERIFIED = 128;
|
|
27
|
+
declare const RATELIMIT_KEY_GLOBAL = 0;
|
|
28
|
+
declare const RATELIMIT_KEY_FEE_PAYER = 1;
|
|
29
|
+
declare const RATELIMIT_KEY_INSTR_ACCOUNT = 2;
|
|
30
|
+
declare const RATELIMIT_KEY_ATTESTED = 3;
|
|
31
|
+
declare const RATELIMIT_CLOCK_SLOT = 0;
|
|
32
|
+
declare const RATELIMIT_CLOCK_UNIX_SECONDS = 1;
|
|
33
|
+
declare const RATELIMIT_CONFIG_SIZE = 309;
|
|
34
|
+
declare const RATELIMIT_POLICY_SIZE = 390;
|
|
35
|
+
declare const RATELIMIT_BUCKET_SIZE = 113;
|
|
36
|
+
declare const RATELIMIT_CALL_ARGS_SIZE = 8;
|
|
37
|
+
declare const RATELIMIT_CALL_BUCKET_SIZE = 36;
|
|
38
|
+
|
|
39
|
+
type AddressInput$1 = string | Uint8Array;
|
|
40
|
+
interface RatelimitDerivedAddress {
|
|
41
|
+
address: string;
|
|
42
|
+
bytes: Uint8Array;
|
|
43
|
+
seed: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
/** Seed of a policy: sha256("tn_ratelimit_verified_policy_v1" || target ||
|
|
46
|
+
* policy_id) when verified, else sha256("tn_ratelimit_policy_v1" || admin ||
|
|
47
|
+
* target || policy_id). A VERIFIED policy is created with the target's
|
|
48
|
+
* manager meta account and its address does not depend on the admin. */
|
|
49
|
+
declare function ratelimitPolicySeed(options: {
|
|
50
|
+
target: AddressInput$1;
|
|
51
|
+
policyId: bigint | number;
|
|
52
|
+
verified: boolean;
|
|
53
|
+
admin?: AddressInput$1;
|
|
54
|
+
}): Uint8Array;
|
|
55
|
+
declare function deriveRatelimitPolicyAddress(programAddress: AddressInput$1, options: Parameters<typeof ratelimitPolicySeed>[0]): RatelimitDerivedAddress;
|
|
56
|
+
/** Bucket key for GLOBAL rules. */
|
|
57
|
+
declare const RATELIMIT_GLOBAL_KEY: Uint8Array;
|
|
58
|
+
/** sha256("tn_ratelimit_bucket_v1" || policy || rule_idx(u8) || key). */
|
|
59
|
+
declare function deriveRatelimitBucketAddress(programAddress: AddressInput$1, policy: AddressInput$1, ruleIdx: number, key: AddressInput$1): RatelimitDerivedAddress;
|
|
60
|
+
/** sha256("tn_ratelimit_authority_v1" || policy). */
|
|
61
|
+
declare function deriveRatelimitAuthorityAddress(programAddress: AddressInput$1, policy: AddressInput$1): RatelimitDerivedAddress;
|
|
62
|
+
|
|
63
|
+
type AddressInput = string | Uint8Array;
|
|
64
|
+
interface RatelimitRuleConfig {
|
|
65
|
+
/** RATELIMIT_KEY_* */
|
|
66
|
+
keyKind: number;
|
|
67
|
+
/** RATELIMIT_CLOCK_* */
|
|
68
|
+
clock: number;
|
|
69
|
+
/** INSTR_ACCOUNT only: offset of a u16 account index in the forwarded instruction. */
|
|
70
|
+
keyOffset?: number;
|
|
71
|
+
window: bigint;
|
|
72
|
+
/** 0 = unlimited */
|
|
73
|
+
maxCalls: bigint;
|
|
74
|
+
/** 0 = unlimited */
|
|
75
|
+
maxAmount: bigint;
|
|
76
|
+
}
|
|
77
|
+
interface RatelimitConstraintConfig {
|
|
78
|
+
idxOffset: number;
|
|
79
|
+
expected: AddressInput;
|
|
80
|
+
}
|
|
81
|
+
/** The admin-controlled policy configuration (tn_ratelimit_config_t).
|
|
82
|
+
* rule_cnt and constraint_cnt are the array lengths. */
|
|
83
|
+
interface RatelimitPolicyConfig {
|
|
84
|
+
/** Only RATELIMIT_POLICY_FLAG_PAUSED may be set. */
|
|
85
|
+
flags?: number;
|
|
86
|
+
selectorSz: number;
|
|
87
|
+
selectorOffset: number;
|
|
88
|
+
selectorValue: bigint;
|
|
89
|
+
instrSzMin: number;
|
|
90
|
+
instrSzMax: number;
|
|
91
|
+
amountSz: number;
|
|
92
|
+
amountOffset: number;
|
|
93
|
+
/** 0 = unlimited */
|
|
94
|
+
maxAmountPerCall: bigint;
|
|
95
|
+
attester?: AddressInput;
|
|
96
|
+
constraints?: readonly RatelimitConstraintConfig[];
|
|
97
|
+
rules: readonly RatelimitRuleConfig[];
|
|
98
|
+
}
|
|
99
|
+
/** Encodes the 309-byte packed tn_ratelimit_config_t. Unused rule and
|
|
100
|
+
* constraint slots are zero. */
|
|
101
|
+
declare function encodeRatelimitConfig(config: RatelimitPolicyConfig): Uint8Array;
|
|
102
|
+
interface CreateRatelimitPolicyOptions {
|
|
103
|
+
policyAccountIdx: number;
|
|
104
|
+
/** The target's manager meta account index for a VERIFIED policy, or
|
|
105
|
+
* omitted (NO_ACCOUNT) for an unverified policy. */
|
|
106
|
+
metaAccountIdx?: number;
|
|
107
|
+
admin: AddressInput;
|
|
108
|
+
target: AddressInput;
|
|
109
|
+
policyId: bigint;
|
|
110
|
+
config: RatelimitPolicyConfig;
|
|
111
|
+
/** Creation state proof of the policy account. */
|
|
112
|
+
proof: Uint8Array;
|
|
113
|
+
}
|
|
114
|
+
/** CREATE_POLICY (0): u32 tag || CreatePolicyArgs || proof. */
|
|
115
|
+
declare function buildCreateRatelimitPolicyInstruction(options: CreateRatelimitPolicyOptions): Uint8Array;
|
|
116
|
+
/** UPDATE_POLICY (1): replaces the config. */
|
|
117
|
+
declare function buildUpdateRatelimitPolicyInstruction(policyAccountIdx: number, config: RatelimitPolicyConfig): Uint8Array;
|
|
118
|
+
/** SET_ADMIN (2). */
|
|
119
|
+
declare function buildSetRatelimitAdminInstruction(policyAccountIdx: number, newAdmin: AddressInput): Uint8Array;
|
|
120
|
+
/** CREATE_AUTHORITY (3): u32 tag || CreateAuthorityArgs || proof. */
|
|
121
|
+
declare function buildCreateRatelimitAuthorityInstruction(policyAccountIdx: number, authorityAccountIdx: number, proof: Uint8Array): Uint8Array;
|
|
122
|
+
interface RatelimitCallBucket {
|
|
123
|
+
bucketAccountIdx: number;
|
|
124
|
+
/** Creation proof when the bucket does not exist yet. */
|
|
125
|
+
proof?: Uint8Array;
|
|
126
|
+
/** ATTESTED rules only; must be omitted (zero) for every other key kind. */
|
|
127
|
+
key?: AddressInput;
|
|
128
|
+
}
|
|
129
|
+
interface RatelimitCallOptions {
|
|
130
|
+
policyAccountIdx: number;
|
|
131
|
+
targetAccountIdx: number;
|
|
132
|
+
/** The policy's authority PDA to sign for, or omitted. */
|
|
133
|
+
authorityAccountIdx?: number;
|
|
134
|
+
/** One entry per policy rule, in rule order. */
|
|
135
|
+
buckets: readonly RatelimitCallBucket[];
|
|
136
|
+
/** The instruction forwarded to the target. */
|
|
137
|
+
inner: Uint8Array;
|
|
138
|
+
}
|
|
139
|
+
/** CALL (4): u32 tag || CallArgs || CallBucket[rule_cnt] || proofs of the
|
|
140
|
+
* buckets with a proof, in rule order || inner. The ABI only describes the
|
|
141
|
+
* fixed CallArgs header, because rule_cnt lives in the policy account. */
|
|
142
|
+
declare function buildRatelimitCallInstruction(options: RatelimitCallOptions): Uint8Array;
|
|
143
|
+
|
|
144
|
+
interface RatelimitPolicyAccount {
|
|
145
|
+
admin: string;
|
|
146
|
+
target: string;
|
|
147
|
+
policyId: bigint;
|
|
148
|
+
/** RATELIMIT_POLICY_FLAG_* */
|
|
149
|
+
stateFlags: number;
|
|
150
|
+
config: RatelimitPolicyConfig;
|
|
151
|
+
/** Raw 309-byte config, for exact comparison with encodeRatelimitConfig. */
|
|
152
|
+
configBytes: Uint8Array;
|
|
153
|
+
}
|
|
154
|
+
interface RatelimitBucketAccount {
|
|
155
|
+
policy: string;
|
|
156
|
+
key: Uint8Array;
|
|
157
|
+
ruleIdx: number;
|
|
158
|
+
windowStart: bigint;
|
|
159
|
+
calls: bigint;
|
|
160
|
+
amount: bigint;
|
|
161
|
+
totalCalls: bigint;
|
|
162
|
+
totalAmount: bigint;
|
|
163
|
+
}
|
|
164
|
+
/** Parses policy account data; returns null on a size or magic mismatch. */
|
|
165
|
+
declare function parseRatelimitPolicyAccount(data: Uint8Array): RatelimitPolicyAccount | null;
|
|
166
|
+
/** Parses bucket account data; returns null on a size or magic mismatch. */
|
|
167
|
+
declare function parseRatelimitBucketAccount(data: Uint8Array): RatelimitBucketAccount | null;
|
|
168
|
+
|
|
169
|
+
declare const RATELIMIT_PROGRAM_ADDRESS: string;
|
|
170
|
+
|
|
171
|
+
export { type CreateRatelimitPolicyOptions, RATELIMIT_BUCKET_MAGIC, RATELIMIT_BUCKET_SIZE, RATELIMIT_CALL_ARGS_SIZE, RATELIMIT_CALL_BUCKET_SIZE, RATELIMIT_CLOCK_SLOT, RATELIMIT_CLOCK_UNIX_SECONDS, RATELIMIT_CONFIG_SIZE, RATELIMIT_CONSTRAINT_MAX, RATELIMIT_ERRORS, RATELIMIT_GLOBAL_KEY, RATELIMIT_INSTRUCTION_CALL, RATELIMIT_KEY_ATTESTED, RATELIMIT_KEY_FEE_PAYER, RATELIMIT_KEY_GLOBAL, RATELIMIT_KEY_INSTR_ACCOUNT, RATELIMIT_NO_ACCOUNT, RATELIMIT_POLICY_FLAG_PAUSED, RATELIMIT_POLICY_FLAG_VERIFIED, RATELIMIT_POLICY_MAGIC, RATELIMIT_POLICY_SIZE, RATELIMIT_PROGRAM_ADDRESS, RATELIMIT_RULE_MAX, type RatelimitBucketAccount, type RatelimitCallBucket, type RatelimitCallOptions, type RatelimitConstraintConfig, type RatelimitDerivedAddress, type RatelimitPolicyAccount, type RatelimitPolicyConfig, type RatelimitRuleConfig, buildCreateRatelimitAuthorityInstruction, buildCreateRatelimitPolicyInstruction, buildRatelimitCallInstruction, buildSetRatelimitAdminInstruction, buildUpdateRatelimitPolicyInstruction, deriveRatelimitAuthorityAddress, deriveRatelimitBucketAddress, deriveRatelimitPolicyAddress, encodeRatelimitConfig, parseRatelimitBucketAccount, parseRatelimitPolicyAccount };
|