@thru/programs 0.3.3 → 0.3.5
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 +123 -37
- package/dist/abi-manager/index.cjs +9568 -0
- package/dist/abi-manager/index.cjs.map +1 -0
- package/dist/abi-manager/index.d.cts +2169 -0
- package/dist/abi-manager/index.d.ts +2169 -0
- package/dist/abi-manager/index.js +4 -0
- package/dist/abi-manager/index.js.map +1 -0
- package/dist/amm/index.cjs +1 -3
- package/dist/amm/index.cjs.map +1 -1
- package/dist/amm/index.d.cts +1 -1
- package/dist/amm/index.d.ts +1 -1
- package/dist/amm/index.js +2 -2
- package/dist/amm/index.js.map +1 -1
- package/dist/chunk-6IC6CO5S.js +9443 -0
- package/dist/chunk-6IC6CO5S.js.map +1 -0
- package/dist/chunk-7DRJVAYI.js +8587 -0
- package/dist/chunk-7DRJVAYI.js.map +1 -0
- package/dist/chunk-7FBCBZIY.js +41 -0
- package/dist/chunk-7FBCBZIY.js.map +1 -0
- package/dist/chunk-BNYDH4ZP.js +4351 -0
- package/dist/chunk-BNYDH4ZP.js.map +1 -0
- package/dist/chunk-OODN6LJA.js +6567 -0
- package/dist/chunk-OODN6LJA.js.map +1 -0
- package/dist/chunk-YX7BLFQZ.js +81 -0
- package/dist/chunk-YX7BLFQZ.js.map +1 -0
- package/dist/clob/index.cjs +19361 -6851
- package/dist/clob/index.cjs.map +1 -1
- package/dist/clob/index.d.cts +1243 -63
- package/dist/clob/index.d.ts +1243 -63
- package/dist/clob/index.js +6826 -2818
- package/dist/clob/index.js.map +1 -1
- package/dist/deploy/index.cjs +24734 -0
- package/dist/deploy/index.cjs.map +1 -0
- package/dist/deploy/index.d.cts +180 -0
- package/dist/deploy/index.d.ts +180 -0
- package/dist/deploy/index.js +1846 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/helpers-DD7q61nr.d.cts +7 -0
- package/dist/helpers-DD7q61nr.d.ts +7 -0
- package/dist/manager/index.cjs +6680 -0
- package/dist/manager/index.cjs.map +1 -0
- package/dist/manager/index.d.cts +1279 -0
- package/dist/manager/index.d.ts +1279 -0
- package/dist/manager/index.js +4 -0
- package/dist/manager/index.js.map +1 -0
- package/dist/passkey-manager/index.cjs +4 -5
- package/dist/passkey-manager/index.cjs.map +1 -1
- package/dist/passkey-manager/index.js +2 -2
- package/dist/token/index.js +1 -8585
- package/dist/token/index.js.map +1 -1
- package/dist/uploader/index.cjs +4442 -0
- package/dist/uploader/index.cjs.map +1 -0
- package/dist/uploader/index.d.cts +761 -0
- package/dist/uploader/index.d.ts +761 -0
- package/dist/uploader/index.js +4 -0
- package/dist/uploader/index.js.map +1 -0
- package/package.json +22 -2
- package/src/abi-manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
- package/src/abi-manager/abi/thru/common/primitives/types.ts +2428 -0
- package/src/abi-manager/abi/thru/program/abi_manager/types.ts +7037 -0
- package/src/abi-manager/accounts.ts +91 -0
- package/src/abi-manager/constants.ts +19 -0
- package/src/abi-manager/derivation.ts +86 -0
- package/src/abi-manager/errors.ts +48 -0
- package/src/abi-manager/index.test.ts +136 -0
- package/src/abi-manager/index.ts +56 -0
- package/src/abi-manager/instructions.ts +573 -0
- package/src/abi-manager/types.ts +150 -0
- package/src/amm/index.test.ts +8 -2
- package/src/amm/index.ts +1 -1
- package/src/clob/abi/thru/program/clob/types.ts +6981 -3070
- package/src/clob/exchange-client.test.ts +592 -0
- package/src/clob/exchange-client.ts +953 -0
- package/src/clob/exchange.test.ts +18 -16
- package/src/clob/exchange.ts +4 -0
- package/src/clob/index.test.ts +134 -7
- package/src/clob/index.ts +303 -10
- package/src/clob/price.test.ts +32 -0
- package/src/clob/price.ts +77 -0
- package/src/deploy/accounts.ts +208 -0
- package/src/deploy/chain.ts +163 -0
- package/src/deploy/constants.ts +25 -0
- package/src/deploy/deploy.test.ts +349 -0
- package/src/deploy/errors.ts +72 -0
- package/src/deploy/index.ts +44 -0
- package/src/deploy/inspection.ts +146 -0
- package/src/deploy/seeds.ts +29 -0
- package/src/deploy/types.ts +178 -0
- package/src/deploy/uploader.test.ts +326 -0
- package/src/deploy/uploader.ts +558 -0
- package/src/deploy/validation-imports.test.ts +55 -0
- package/src/deploy/validation.ts +183 -0
- package/src/deploy/workflows.test.ts +422 -0
- package/src/deploy/workflows.ts +1088 -0
- package/src/helpers/bytes.test.ts +58 -0
- package/src/helpers/bytes.ts +28 -3
- package/src/manager/abi/thru/blockchain/state_proof/types.ts +1906 -0
- package/src/manager/abi/thru/common/primitives/types.ts +2428 -0
- package/src/manager/abi/thru/program/manager/types.ts +3814 -0
- package/src/manager/accounts.ts +44 -0
- package/src/manager/constants.ts +16 -0
- package/src/manager/derivation.ts +32 -0
- package/src/manager/errors.ts +47 -0
- package/src/manager/index.test.ts +108 -0
- package/src/manager/index.ts +68 -0
- package/src/manager/instructions.ts +281 -0
- package/src/manager/types.ts +95 -0
- package/src/manager/validation.ts +35 -0
- package/src/uploader/abi/thru/common/primitives/types.ts +2428 -0
- package/src/uploader/abi/thru/program/uploader/types.ts +3022 -0
- package/src/uploader/accounts.ts +38 -0
- package/src/uploader/constants.ts +14 -0
- package/src/uploader/derivation.ts +34 -0
- package/src/uploader/errors.ts +25 -0
- package/src/uploader/index.test.ts +107 -0
- package/src/uploader/index.ts +34 -0
- package/src/uploader/instructions.ts +163 -0
- package/src/uploader/types.ts +67 -0
- package/src/utils/helpers.ts +121 -0
- package/tsup.config.ts +4 -0
- package/dist/chunk-P5OABVJI.js +0 -28
- package/dist/chunk-P5OABVJI.js.map +0 -1
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbiManagerInstruction,
|
|
3
|
+
AbiManagerInstructionBuilder,
|
|
4
|
+
CloseAbiExternalArgsBuilder,
|
|
5
|
+
CloseAbiOfficialArgsBuilder,
|
|
6
|
+
CreateAbiExternalEphemeralArgsBuilder,
|
|
7
|
+
CreateAbiExternalPermanentArgsBuilder,
|
|
8
|
+
CreateAbiOfficialEphemeralArgsBuilder,
|
|
9
|
+
CreateAbiOfficialPermanentArgsBuilder,
|
|
10
|
+
CreateMetaExternalEphemeralArgsBuilder,
|
|
11
|
+
CreateMetaExternalPermanentArgsBuilder,
|
|
12
|
+
CreateMetaOfficialEphemeralArgsBuilder,
|
|
13
|
+
CreateMetaOfficialPermanentArgsBuilder,
|
|
14
|
+
FinalizeAbiExternalArgsBuilder,
|
|
15
|
+
FinalizeAbiOfficialArgsBuilder,
|
|
16
|
+
UpgradeAbiExternalArgsBuilder,
|
|
17
|
+
UpgradeAbiOfficialArgsBuilder,
|
|
18
|
+
} from './abi/thru/program/abi_manager/types';
|
|
19
|
+
import {
|
|
20
|
+
accountIndex,
|
|
21
|
+
assertU16,
|
|
22
|
+
assertU32,
|
|
23
|
+
exactBytes,
|
|
24
|
+
type AccountLookupContext,
|
|
25
|
+
type InstructionData,
|
|
26
|
+
} from '../utils/helpers';
|
|
27
|
+
import type {
|
|
28
|
+
ABIManagerInstructionArgs,
|
|
29
|
+
AccountCreationMode,
|
|
30
|
+
ExternalABIAccounts,
|
|
31
|
+
ExternalABIControlAccounts,
|
|
32
|
+
ExternalABIMetaAccounts,
|
|
33
|
+
OfficialABIAccounts,
|
|
34
|
+
OfficialABIControlAccounts,
|
|
35
|
+
OfficialABIMetaAccounts,
|
|
36
|
+
} from './types';
|
|
37
|
+
|
|
38
|
+
type ABIVariant =
|
|
39
|
+
(typeof AbiManagerInstruction.payloadVariantDescriptors)[number]['name'];
|
|
40
|
+
|
|
41
|
+
function envelope(variant: ABIVariant, payload: Uint8Array): Uint8Array {
|
|
42
|
+
return new AbiManagerInstructionBuilder()
|
|
43
|
+
.payload()
|
|
44
|
+
.select(variant)
|
|
45
|
+
.writePayload(payload)
|
|
46
|
+
.finish()
|
|
47
|
+
.build();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function validateIndex(value: number, label: string): number {
|
|
51
|
+
assertU16(value, label);
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function sourceOffset(value: number | undefined): number {
|
|
56
|
+
const offset = value ?? 0;
|
|
57
|
+
assertU32(offset, 'sourceOffset');
|
|
58
|
+
return offset;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function sourceSize(value: number): number {
|
|
62
|
+
assertU32(value, 'sourceSize');
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function buildABIManagerInstructionBytes(
|
|
67
|
+
args: ABIManagerInstructionArgs
|
|
68
|
+
): Uint8Array {
|
|
69
|
+
switch (args.kind) {
|
|
70
|
+
case 'createMetaOfficialPermanent':
|
|
71
|
+
return envelope(
|
|
72
|
+
'create_meta_official_permanent',
|
|
73
|
+
new CreateMetaOfficialPermanentArgsBuilder()
|
|
74
|
+
.set_abi_meta_account_idx(
|
|
75
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
76
|
+
)
|
|
77
|
+
.set_program_meta_account_idx(
|
|
78
|
+
validateIndex(args.programMetaAccountIdx, 'programMetaAccountIdx')
|
|
79
|
+
)
|
|
80
|
+
.set_authority_account_idx(
|
|
81
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
82
|
+
)
|
|
83
|
+
.set_state_proof(args.stateProof)
|
|
84
|
+
.build()
|
|
85
|
+
);
|
|
86
|
+
case 'createMetaOfficialEphemeral':
|
|
87
|
+
return envelope(
|
|
88
|
+
'create_meta_official_ephemeral',
|
|
89
|
+
new CreateMetaOfficialEphemeralArgsBuilder()
|
|
90
|
+
.set_abi_meta_account_idx(
|
|
91
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
92
|
+
)
|
|
93
|
+
.set_program_meta_account_idx(
|
|
94
|
+
validateIndex(args.programMetaAccountIdx, 'programMetaAccountIdx')
|
|
95
|
+
)
|
|
96
|
+
.set_authority_account_idx(
|
|
97
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
98
|
+
)
|
|
99
|
+
.build()
|
|
100
|
+
);
|
|
101
|
+
case 'createMetaExternalPermanent':
|
|
102
|
+
return envelope(
|
|
103
|
+
'create_meta_external_permanent',
|
|
104
|
+
new CreateMetaExternalPermanentArgsBuilder()
|
|
105
|
+
.set_abi_meta_account_idx(
|
|
106
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
107
|
+
)
|
|
108
|
+
.set_authority_account_idx(
|
|
109
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
110
|
+
)
|
|
111
|
+
.set_target_program(
|
|
112
|
+
exactBytes(args.targetProgram, 32, 'targetProgram')
|
|
113
|
+
)
|
|
114
|
+
.set_seed(exactBytes(args.seed, 32, 'external ABI seed'))
|
|
115
|
+
.set_state_proof(args.stateProof)
|
|
116
|
+
.build()
|
|
117
|
+
);
|
|
118
|
+
case 'createMetaExternalEphemeral':
|
|
119
|
+
return envelope(
|
|
120
|
+
'create_meta_external_ephemeral',
|
|
121
|
+
new CreateMetaExternalEphemeralArgsBuilder()
|
|
122
|
+
.set_abi_meta_account_idx(
|
|
123
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
124
|
+
)
|
|
125
|
+
.set_authority_account_idx(
|
|
126
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
127
|
+
)
|
|
128
|
+
.set_target_program(
|
|
129
|
+
exactBytes(args.targetProgram, 32, 'targetProgram')
|
|
130
|
+
)
|
|
131
|
+
.set_seed(exactBytes(args.seed, 32, 'external ABI seed'))
|
|
132
|
+
.build()
|
|
133
|
+
);
|
|
134
|
+
case 'createABIOfficialPermanent':
|
|
135
|
+
return envelope(
|
|
136
|
+
'create_abi_official_permanent',
|
|
137
|
+
new CreateAbiOfficialPermanentArgsBuilder()
|
|
138
|
+
.set_abi_meta_account_idx(
|
|
139
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
140
|
+
)
|
|
141
|
+
.set_program_meta_account_idx(
|
|
142
|
+
validateIndex(args.programMetaAccountIdx, 'programMetaAccountIdx')
|
|
143
|
+
)
|
|
144
|
+
.set_abi_account_idx(
|
|
145
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
146
|
+
)
|
|
147
|
+
.set_srcbuf_account_idx(
|
|
148
|
+
validateIndex(args.sourceBufferAccountIdx, 'sourceBufferAccountIdx')
|
|
149
|
+
)
|
|
150
|
+
.set_srcbuf_offset(sourceOffset(args.sourceOffset))
|
|
151
|
+
.set_srcbuf_size(sourceSize(args.sourceSize))
|
|
152
|
+
.set_authority_account_idx(
|
|
153
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
154
|
+
)
|
|
155
|
+
.set_state_proof(args.stateProof)
|
|
156
|
+
.build()
|
|
157
|
+
);
|
|
158
|
+
case 'createABIOfficialEphemeral':
|
|
159
|
+
return envelope(
|
|
160
|
+
'create_abi_official_ephemeral',
|
|
161
|
+
new CreateAbiOfficialEphemeralArgsBuilder()
|
|
162
|
+
.set_abi_meta_account_idx(
|
|
163
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
164
|
+
)
|
|
165
|
+
.set_program_meta_account_idx(
|
|
166
|
+
validateIndex(args.programMetaAccountIdx, 'programMetaAccountIdx')
|
|
167
|
+
)
|
|
168
|
+
.set_abi_account_idx(
|
|
169
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
170
|
+
)
|
|
171
|
+
.set_srcbuf_account_idx(
|
|
172
|
+
validateIndex(args.sourceBufferAccountIdx, 'sourceBufferAccountIdx')
|
|
173
|
+
)
|
|
174
|
+
.set_srcbuf_offset(sourceOffset(args.sourceOffset))
|
|
175
|
+
.set_srcbuf_size(sourceSize(args.sourceSize))
|
|
176
|
+
.set_authority_account_idx(
|
|
177
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
178
|
+
)
|
|
179
|
+
.build()
|
|
180
|
+
);
|
|
181
|
+
case 'createABIExternalPermanent':
|
|
182
|
+
return envelope(
|
|
183
|
+
'create_abi_external_permanent',
|
|
184
|
+
new CreateAbiExternalPermanentArgsBuilder()
|
|
185
|
+
.set_abi_meta_account_idx(
|
|
186
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
187
|
+
)
|
|
188
|
+
.set_abi_account_idx(
|
|
189
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
190
|
+
)
|
|
191
|
+
.set_srcbuf_account_idx(
|
|
192
|
+
validateIndex(args.sourceBufferAccountIdx, 'sourceBufferAccountIdx')
|
|
193
|
+
)
|
|
194
|
+
.set_srcbuf_offset(sourceOffset(args.sourceOffset))
|
|
195
|
+
.set_srcbuf_size(sourceSize(args.sourceSize))
|
|
196
|
+
.set_authority_account_idx(
|
|
197
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
198
|
+
)
|
|
199
|
+
.set_state_proof(args.stateProof)
|
|
200
|
+
.build()
|
|
201
|
+
);
|
|
202
|
+
case 'createABIExternalEphemeral':
|
|
203
|
+
return envelope(
|
|
204
|
+
'create_abi_external_ephemeral',
|
|
205
|
+
new CreateAbiExternalEphemeralArgsBuilder()
|
|
206
|
+
.set_abi_meta_account_idx(
|
|
207
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
208
|
+
)
|
|
209
|
+
.set_abi_account_idx(
|
|
210
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
211
|
+
)
|
|
212
|
+
.set_srcbuf_account_idx(
|
|
213
|
+
validateIndex(args.sourceBufferAccountIdx, 'sourceBufferAccountIdx')
|
|
214
|
+
)
|
|
215
|
+
.set_srcbuf_offset(sourceOffset(args.sourceOffset))
|
|
216
|
+
.set_srcbuf_size(sourceSize(args.sourceSize))
|
|
217
|
+
.set_authority_account_idx(
|
|
218
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
219
|
+
)
|
|
220
|
+
.build()
|
|
221
|
+
);
|
|
222
|
+
case 'upgradeABIOfficial':
|
|
223
|
+
return envelope(
|
|
224
|
+
'upgrade_abi_official',
|
|
225
|
+
new UpgradeAbiOfficialArgsBuilder()
|
|
226
|
+
.set_abi_meta_account_idx(
|
|
227
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
228
|
+
)
|
|
229
|
+
.set_program_meta_account_idx(
|
|
230
|
+
validateIndex(args.programMetaAccountIdx, 'programMetaAccountIdx')
|
|
231
|
+
)
|
|
232
|
+
.set_abi_account_idx(
|
|
233
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
234
|
+
)
|
|
235
|
+
.set_srcbuf_account_idx(
|
|
236
|
+
validateIndex(args.sourceBufferAccountIdx, 'sourceBufferAccountIdx')
|
|
237
|
+
)
|
|
238
|
+
.set_srcbuf_offset(sourceOffset(args.sourceOffset))
|
|
239
|
+
.set_srcbuf_size(sourceSize(args.sourceSize))
|
|
240
|
+
.set_authority_account_idx(
|
|
241
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
242
|
+
)
|
|
243
|
+
.build()
|
|
244
|
+
);
|
|
245
|
+
case 'upgradeABIExternal':
|
|
246
|
+
return envelope(
|
|
247
|
+
'upgrade_abi_external',
|
|
248
|
+
new UpgradeAbiExternalArgsBuilder()
|
|
249
|
+
.set_abi_meta_account_idx(
|
|
250
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
251
|
+
)
|
|
252
|
+
.set_abi_account_idx(
|
|
253
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
254
|
+
)
|
|
255
|
+
.set_srcbuf_account_idx(
|
|
256
|
+
validateIndex(args.sourceBufferAccountIdx, 'sourceBufferAccountIdx')
|
|
257
|
+
)
|
|
258
|
+
.set_srcbuf_offset(sourceOffset(args.sourceOffset))
|
|
259
|
+
.set_srcbuf_size(sourceSize(args.sourceSize))
|
|
260
|
+
.set_authority_account_idx(
|
|
261
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
262
|
+
)
|
|
263
|
+
.build()
|
|
264
|
+
);
|
|
265
|
+
case 'closeABIOfficial':
|
|
266
|
+
case 'finalizeABIOfficial': {
|
|
267
|
+
const builder =
|
|
268
|
+
args.kind === 'closeABIOfficial'
|
|
269
|
+
? new CloseAbiOfficialArgsBuilder()
|
|
270
|
+
: new FinalizeAbiOfficialArgsBuilder();
|
|
271
|
+
const payload = builder
|
|
272
|
+
.set_abi_meta_account_idx(
|
|
273
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
274
|
+
)
|
|
275
|
+
.set_program_meta_account_idx(
|
|
276
|
+
validateIndex(args.programMetaAccountIdx, 'programMetaAccountIdx')
|
|
277
|
+
)
|
|
278
|
+
.set_abi_account_idx(
|
|
279
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
280
|
+
)
|
|
281
|
+
.set_authority_account_idx(
|
|
282
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
283
|
+
)
|
|
284
|
+
.build();
|
|
285
|
+
return envelope(
|
|
286
|
+
args.kind === 'closeABIOfficial'
|
|
287
|
+
? 'close_abi_official'
|
|
288
|
+
: 'finalize_abi_official',
|
|
289
|
+
payload
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
case 'closeABIExternal':
|
|
293
|
+
case 'finalizeABIExternal': {
|
|
294
|
+
const builder =
|
|
295
|
+
args.kind === 'closeABIExternal'
|
|
296
|
+
? new CloseAbiExternalArgsBuilder()
|
|
297
|
+
: new FinalizeAbiExternalArgsBuilder();
|
|
298
|
+
const payload = builder
|
|
299
|
+
.set_abi_meta_account_idx(
|
|
300
|
+
validateIndex(args.abiMetaAccountIdx, 'abiMetaAccountIdx')
|
|
301
|
+
)
|
|
302
|
+
.set_abi_account_idx(
|
|
303
|
+
validateIndex(args.abiAccountIdx, 'abiAccountIdx')
|
|
304
|
+
)
|
|
305
|
+
.set_authority_account_idx(
|
|
306
|
+
validateIndex(args.authorityAccountIdx, 'authorityAccountIdx')
|
|
307
|
+
)
|
|
308
|
+
.build();
|
|
309
|
+
return envelope(
|
|
310
|
+
args.kind === 'closeABIExternal'
|
|
311
|
+
? 'close_abi_external'
|
|
312
|
+
: 'finalize_abi_external',
|
|
313
|
+
payload
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function officialMetaIndices(
|
|
320
|
+
context: AccountLookupContext,
|
|
321
|
+
args: OfficialABIMetaAccounts
|
|
322
|
+
): {
|
|
323
|
+
abiMetaAccountIdx: number;
|
|
324
|
+
programMetaAccountIdx: number;
|
|
325
|
+
authorityAccountIdx: number;
|
|
326
|
+
} {
|
|
327
|
+
return {
|
|
328
|
+
abiMetaAccountIdx: accountIndex(
|
|
329
|
+
context,
|
|
330
|
+
args.abiMetaAccount,
|
|
331
|
+
'abiMetaAccount'
|
|
332
|
+
),
|
|
333
|
+
programMetaAccountIdx: accountIndex(
|
|
334
|
+
context,
|
|
335
|
+
args.programMetaAccount,
|
|
336
|
+
'programMetaAccount'
|
|
337
|
+
),
|
|
338
|
+
authorityAccountIdx: accountIndex(
|
|
339
|
+
context,
|
|
340
|
+
args.authorityAccount,
|
|
341
|
+
'authorityAccount'
|
|
342
|
+
),
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function externalMetaIndices(
|
|
347
|
+
context: AccountLookupContext,
|
|
348
|
+
args: ExternalABIMetaAccounts
|
|
349
|
+
): {
|
|
350
|
+
abiMetaAccountIdx: number;
|
|
351
|
+
authorityAccountIdx: number;
|
|
352
|
+
targetProgram: Uint8Array;
|
|
353
|
+
seed: Uint8Array;
|
|
354
|
+
} {
|
|
355
|
+
return {
|
|
356
|
+
abiMetaAccountIdx: accountIndex(
|
|
357
|
+
context,
|
|
358
|
+
args.abiMetaAccount,
|
|
359
|
+
'abiMetaAccount'
|
|
360
|
+
),
|
|
361
|
+
authorityAccountIdx: accountIndex(
|
|
362
|
+
context,
|
|
363
|
+
args.authorityAccount,
|
|
364
|
+
'authorityAccount'
|
|
365
|
+
),
|
|
366
|
+
targetProgram: args.targetProgram,
|
|
367
|
+
seed: args.seed,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function officialABIIndices(
|
|
372
|
+
context: AccountLookupContext,
|
|
373
|
+
args: OfficialABIAccounts
|
|
374
|
+
) {
|
|
375
|
+
return {
|
|
376
|
+
...officialMetaIndices(context, args),
|
|
377
|
+
abiAccountIdx: accountIndex(context, args.abiAccount, 'abiAccount'),
|
|
378
|
+
sourceBufferAccountIdx: accountIndex(
|
|
379
|
+
context,
|
|
380
|
+
args.sourceBufferAccount,
|
|
381
|
+
'sourceBufferAccount'
|
|
382
|
+
),
|
|
383
|
+
sourceOffset: args.sourceOffset,
|
|
384
|
+
sourceSize: args.sourceSize,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function externalABIIndices(
|
|
389
|
+
context: AccountLookupContext,
|
|
390
|
+
args: ExternalABIAccounts
|
|
391
|
+
) {
|
|
392
|
+
return {
|
|
393
|
+
abiMetaAccountIdx: accountIndex(
|
|
394
|
+
context,
|
|
395
|
+
args.abiMetaAccount,
|
|
396
|
+
'abiMetaAccount'
|
|
397
|
+
),
|
|
398
|
+
abiAccountIdx: accountIndex(context, args.abiAccount, 'abiAccount'),
|
|
399
|
+
sourceBufferAccountIdx: accountIndex(
|
|
400
|
+
context,
|
|
401
|
+
args.sourceBufferAccount,
|
|
402
|
+
'sourceBufferAccount'
|
|
403
|
+
),
|
|
404
|
+
sourceOffset: args.sourceOffset,
|
|
405
|
+
sourceSize: args.sourceSize,
|
|
406
|
+
authorityAccountIdx: accountIndex(
|
|
407
|
+
context,
|
|
408
|
+
args.authorityAccount,
|
|
409
|
+
'authorityAccount'
|
|
410
|
+
),
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function createOfficialABIMetaInstruction(
|
|
415
|
+
args: OfficialABIMetaAccounts & AccountCreationMode
|
|
416
|
+
): InstructionData {
|
|
417
|
+
return async (context) => {
|
|
418
|
+
const indices = officialMetaIndices(context, args);
|
|
419
|
+
return args.ephemeral === true
|
|
420
|
+
? buildABIManagerInstructionBytes({
|
|
421
|
+
kind: 'createMetaOfficialEphemeral',
|
|
422
|
+
...indices,
|
|
423
|
+
})
|
|
424
|
+
: buildABIManagerInstructionBytes({
|
|
425
|
+
kind: 'createMetaOfficialPermanent',
|
|
426
|
+
...indices,
|
|
427
|
+
stateProof: args.stateProof,
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function createExternalABIMetaInstruction(
|
|
433
|
+
args: ExternalABIMetaAccounts & AccountCreationMode
|
|
434
|
+
): InstructionData {
|
|
435
|
+
return async (context) => {
|
|
436
|
+
const indices = externalMetaIndices(context, args);
|
|
437
|
+
return args.ephemeral === true
|
|
438
|
+
? buildABIManagerInstructionBytes({
|
|
439
|
+
kind: 'createMetaExternalEphemeral',
|
|
440
|
+
...indices,
|
|
441
|
+
})
|
|
442
|
+
: buildABIManagerInstructionBytes({
|
|
443
|
+
kind: 'createMetaExternalPermanent',
|
|
444
|
+
...indices,
|
|
445
|
+
stateProof: args.stateProof,
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function createOfficialABIInstruction(
|
|
451
|
+
args: OfficialABIAccounts & AccountCreationMode
|
|
452
|
+
): InstructionData {
|
|
453
|
+
return async (context) => {
|
|
454
|
+
const indices = officialABIIndices(context, args);
|
|
455
|
+
return args.ephemeral === true
|
|
456
|
+
? buildABIManagerInstructionBytes({
|
|
457
|
+
kind: 'createABIOfficialEphemeral',
|
|
458
|
+
...indices,
|
|
459
|
+
})
|
|
460
|
+
: buildABIManagerInstructionBytes({
|
|
461
|
+
kind: 'createABIOfficialPermanent',
|
|
462
|
+
...indices,
|
|
463
|
+
stateProof: args.stateProof,
|
|
464
|
+
});
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export function createExternalABIInstruction(
|
|
469
|
+
args: ExternalABIAccounts & AccountCreationMode
|
|
470
|
+
): InstructionData {
|
|
471
|
+
return async (context) => {
|
|
472
|
+
const indices = externalABIIndices(context, args);
|
|
473
|
+
return args.ephemeral === true
|
|
474
|
+
? buildABIManagerInstructionBytes({
|
|
475
|
+
kind: 'createABIExternalEphemeral',
|
|
476
|
+
...indices,
|
|
477
|
+
})
|
|
478
|
+
: buildABIManagerInstructionBytes({
|
|
479
|
+
kind: 'createABIExternalPermanent',
|
|
480
|
+
...indices,
|
|
481
|
+
stateProof: args.stateProof,
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export function createUpgradeOfficialABIInstruction(
|
|
487
|
+
args: OfficialABIAccounts
|
|
488
|
+
): InstructionData {
|
|
489
|
+
return async (context) =>
|
|
490
|
+
buildABIManagerInstructionBytes({
|
|
491
|
+
kind: 'upgradeABIOfficial',
|
|
492
|
+
...officialABIIndices(context, args),
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export function createUpgradeExternalABIInstruction(
|
|
497
|
+
args: ExternalABIAccounts
|
|
498
|
+
): InstructionData {
|
|
499
|
+
return async (context) =>
|
|
500
|
+
buildABIManagerInstructionBytes({
|
|
501
|
+
kind: 'upgradeABIExternal',
|
|
502
|
+
...externalABIIndices(context, args),
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function officialControlIndices(
|
|
507
|
+
context: AccountLookupContext,
|
|
508
|
+
args: OfficialABIControlAccounts
|
|
509
|
+
) {
|
|
510
|
+
return {
|
|
511
|
+
...officialMetaIndices(context, args),
|
|
512
|
+
abiAccountIdx: accountIndex(context, args.abiAccount, 'abiAccount'),
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function externalControlIndices(
|
|
517
|
+
context: AccountLookupContext,
|
|
518
|
+
args: ExternalABIControlAccounts
|
|
519
|
+
) {
|
|
520
|
+
return {
|
|
521
|
+
abiMetaAccountIdx: accountIndex(
|
|
522
|
+
context,
|
|
523
|
+
args.abiMetaAccount,
|
|
524
|
+
'abiMetaAccount'
|
|
525
|
+
),
|
|
526
|
+
abiAccountIdx: accountIndex(context, args.abiAccount, 'abiAccount'),
|
|
527
|
+
authorityAccountIdx: accountIndex(
|
|
528
|
+
context,
|
|
529
|
+
args.authorityAccount,
|
|
530
|
+
'authorityAccount'
|
|
531
|
+
),
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
export function createCloseOfficialABIInstruction(
|
|
536
|
+
args: OfficialABIControlAccounts
|
|
537
|
+
): InstructionData {
|
|
538
|
+
return async (context) =>
|
|
539
|
+
buildABIManagerInstructionBytes({
|
|
540
|
+
kind: 'closeABIOfficial',
|
|
541
|
+
...officialControlIndices(context, args),
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export function createCloseExternalABIInstruction(
|
|
546
|
+
args: ExternalABIControlAccounts
|
|
547
|
+
): InstructionData {
|
|
548
|
+
return async (context) =>
|
|
549
|
+
buildABIManagerInstructionBytes({
|
|
550
|
+
kind: 'closeABIExternal',
|
|
551
|
+
...externalControlIndices(context, args),
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
export function createFinalizeOfficialABIInstruction(
|
|
556
|
+
args: OfficialABIControlAccounts
|
|
557
|
+
): InstructionData {
|
|
558
|
+
return async (context) =>
|
|
559
|
+
buildABIManagerInstructionBytes({
|
|
560
|
+
kind: 'finalizeABIOfficial',
|
|
561
|
+
...officialControlIndices(context, args),
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export function createFinalizeExternalABIInstruction(
|
|
566
|
+
args: ExternalABIControlAccounts
|
|
567
|
+
): InstructionData {
|
|
568
|
+
return async (context) =>
|
|
569
|
+
buildABIManagerInstructionBytes({
|
|
570
|
+
kind: 'finalizeABIExternal',
|
|
571
|
+
...externalControlIndices(context, args),
|
|
572
|
+
});
|
|
573
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AccountLookupContext,
|
|
3
|
+
InstructionData,
|
|
4
|
+
} from '../utils/helpers';
|
|
5
|
+
|
|
6
|
+
export type { AccountLookupContext, InstructionData };
|
|
7
|
+
|
|
8
|
+
export interface ProgramABIAddresses {
|
|
9
|
+
abiMetaAccountAddress: string;
|
|
10
|
+
abiMetaAccountBytes: Uint8Array;
|
|
11
|
+
abiAccountAddress: string;
|
|
12
|
+
abiAccountBytes: Uint8Array;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface OfficialABIMetaAccountInfo {
|
|
16
|
+
kind: 'official';
|
|
17
|
+
version: number;
|
|
18
|
+
flags: number;
|
|
19
|
+
programAddress: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ExternalABIMetaAccountInfo {
|
|
23
|
+
kind: 'external';
|
|
24
|
+
version: number;
|
|
25
|
+
flags: number;
|
|
26
|
+
publisherAddress: string;
|
|
27
|
+
targetProgramAddress: string;
|
|
28
|
+
seed: Uint8Array;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ABIMetaAccountInfo =
|
|
32
|
+
| OfficialABIMetaAccountInfo
|
|
33
|
+
| ExternalABIMetaAccountInfo;
|
|
34
|
+
|
|
35
|
+
export interface ABIAccountInfo {
|
|
36
|
+
abiMetaAccountAddress: string;
|
|
37
|
+
revision: bigint;
|
|
38
|
+
state: number;
|
|
39
|
+
contents: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface MetaOfficialIndices {
|
|
43
|
+
abiMetaAccountIdx: number;
|
|
44
|
+
programMetaAccountIdx: number;
|
|
45
|
+
authorityAccountIdx: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface MetaExternalIndices {
|
|
49
|
+
abiMetaAccountIdx: number;
|
|
50
|
+
authorityAccountIdx: number;
|
|
51
|
+
targetProgram: Uint8Array;
|
|
52
|
+
seed: Uint8Array;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ABIOfficialIndices extends MetaOfficialIndices {
|
|
56
|
+
abiAccountIdx: number;
|
|
57
|
+
sourceBufferAccountIdx: number;
|
|
58
|
+
sourceOffset?: number;
|
|
59
|
+
sourceSize: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface ABIExternalIndices {
|
|
63
|
+
abiMetaAccountIdx: number;
|
|
64
|
+
abiAccountIdx: number;
|
|
65
|
+
sourceBufferAccountIdx: number;
|
|
66
|
+
sourceOffset?: number;
|
|
67
|
+
sourceSize: number;
|
|
68
|
+
authorityAccountIdx: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface OfficialControlIndices extends MetaOfficialIndices {
|
|
72
|
+
abiAccountIdx: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
interface ExternalControlIndices {
|
|
76
|
+
abiMetaAccountIdx: number;
|
|
77
|
+
abiAccountIdx: number;
|
|
78
|
+
authorityAccountIdx: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ABIManagerInstructionArgs =
|
|
82
|
+
| (MetaOfficialIndices & {
|
|
83
|
+
kind: 'createMetaOfficialPermanent';
|
|
84
|
+
stateProof: Uint8Array;
|
|
85
|
+
})
|
|
86
|
+
| (MetaOfficialIndices & { kind: 'createMetaOfficialEphemeral' })
|
|
87
|
+
| (MetaExternalIndices & {
|
|
88
|
+
kind: 'createMetaExternalPermanent';
|
|
89
|
+
stateProof: Uint8Array;
|
|
90
|
+
})
|
|
91
|
+
| (MetaExternalIndices & { kind: 'createMetaExternalEphemeral' })
|
|
92
|
+
| (ABIOfficialIndices & {
|
|
93
|
+
kind: 'createABIOfficialPermanent';
|
|
94
|
+
stateProof: Uint8Array;
|
|
95
|
+
})
|
|
96
|
+
| (ABIOfficialIndices & { kind: 'createABIOfficialEphemeral' })
|
|
97
|
+
| (ABIExternalIndices & {
|
|
98
|
+
kind: 'createABIExternalPermanent';
|
|
99
|
+
stateProof: Uint8Array;
|
|
100
|
+
})
|
|
101
|
+
| (ABIExternalIndices & { kind: 'createABIExternalEphemeral' })
|
|
102
|
+
| (ABIOfficialIndices & { kind: 'upgradeABIOfficial' })
|
|
103
|
+
| (ABIExternalIndices & { kind: 'upgradeABIExternal' })
|
|
104
|
+
| (OfficialControlIndices & { kind: 'closeABIOfficial' })
|
|
105
|
+
| (ExternalControlIndices & { kind: 'closeABIExternal' })
|
|
106
|
+
| (OfficialControlIndices & { kind: 'finalizeABIOfficial' })
|
|
107
|
+
| (ExternalControlIndices & { kind: 'finalizeABIExternal' });
|
|
108
|
+
|
|
109
|
+
export type AccountCreationMode =
|
|
110
|
+
| { ephemeral: true; stateProof?: never }
|
|
111
|
+
| { ephemeral?: false; stateProof: Uint8Array };
|
|
112
|
+
|
|
113
|
+
export interface OfficialABIMetaAccounts {
|
|
114
|
+
abiMetaAccount: Uint8Array;
|
|
115
|
+
programMetaAccount: Uint8Array;
|
|
116
|
+
authorityAccount: Uint8Array;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface ExternalABIMetaAccounts {
|
|
120
|
+
abiMetaAccount: Uint8Array;
|
|
121
|
+
authorityAccount: Uint8Array;
|
|
122
|
+
targetProgram: Uint8Array;
|
|
123
|
+
seed: Uint8Array;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface OfficialABIAccounts extends OfficialABIMetaAccounts {
|
|
127
|
+
abiAccount: Uint8Array;
|
|
128
|
+
sourceBufferAccount: Uint8Array;
|
|
129
|
+
sourceOffset?: number;
|
|
130
|
+
sourceSize: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ExternalABIAccounts {
|
|
134
|
+
abiMetaAccount: Uint8Array;
|
|
135
|
+
abiAccount: Uint8Array;
|
|
136
|
+
sourceBufferAccount: Uint8Array;
|
|
137
|
+
sourceOffset?: number;
|
|
138
|
+
sourceSize: number;
|
|
139
|
+
authorityAccount: Uint8Array;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface OfficialABIControlAccounts extends OfficialABIMetaAccounts {
|
|
143
|
+
abiAccount: Uint8Array;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface ExternalABIControlAccounts {
|
|
147
|
+
abiMetaAccount: Uint8Array;
|
|
148
|
+
abiAccount: Uint8Array;
|
|
149
|
+
authorityAccount: Uint8Array;
|
|
150
|
+
}
|