kit-squared 0.2.4 → 0.2.6
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 +3 -3
- package/dist/library/program.js +52 -45
- package/dist/library/utils.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[Skip to Contents](#contents)
|
|
8
8
|
|
|
9
|
-
[Skip to Example Project](https://github.com/AnAllergyToAnalogy/kit-squared/tree/main/
|
|
9
|
+
[Skip to Example Project](https://github.com/AnAllergyToAnalogy/kit-squared-example-site/tree/main/src)
|
|
10
10
|
|
|
11
11
|
## Initialising
|
|
12
12
|
|
|
@@ -194,7 +194,7 @@ The library requires no additional features or functionality for interacting wit
|
|
|
194
194
|
|
|
195
195
|
The [@solana-program/token-2022](https://www.npmjs.com/package/@solana-program/token-2022) package will be supported after its next release. It currently has outdated peer dependencies that I have patched with a PR. These are slow moving wheels beyond my control.
|
|
196
196
|
|
|
197
|
-
You can retreive the RPC of your
|
|
197
|
+
You can retreive the RPC of your Kit² instance with
|
|
198
198
|
```typescript
|
|
199
199
|
const rpc = (getConnection()).rpc;
|
|
200
200
|
```
|
|
@@ -227,5 +227,5 @@ Managing accounts included in instructions and transactions.
|
|
|
227
227
|
### [Utils](https://github.com/AnAllergyToAnalogy/kit-squared/blob/main/docs/utils/UTILS.md)
|
|
228
228
|
Various utilities, some relating specific to Solana, others that are more broadly used by this library.
|
|
229
229
|
|
|
230
|
-
### [Example](https://github.com/AnAllergyToAnalogy/kit-squared/tree/main/
|
|
230
|
+
### [Example](https://github.com/AnAllergyToAnalogy/kit-squared-example-site/tree/main/src)
|
|
231
231
|
An example repo showing basic usage of the Kit² library.
|
package/dist/library/program.js
CHANGED
|
@@ -116,14 +116,16 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
116
116
|
const _eventTranslation = {};
|
|
117
117
|
// Events
|
|
118
118
|
const _events = {};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
name
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
if (idl.events) {
|
|
120
|
+
for (let event of idl.events) {
|
|
121
|
+
const nameCamel = pascalToCamel(event.name);
|
|
122
|
+
_events[event.name] = {
|
|
123
|
+
name: nameCamel,
|
|
124
|
+
discriminator: event.discriminator,
|
|
125
|
+
codec: programClient[`get${event.name}Codec`](),
|
|
126
|
+
};
|
|
127
|
+
_eventTranslation[nameCamel] = Event();
|
|
128
|
+
}
|
|
127
129
|
}
|
|
128
130
|
// Set up an abort controller.
|
|
129
131
|
const abortController = new AbortController();
|
|
@@ -351,9 +353,10 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
351
353
|
// use [property] of that.
|
|
352
354
|
// Will need to infer type from the account
|
|
353
355
|
const accountData = await readAccount(seed.account, ixProps[parentName]);
|
|
356
|
+
const propertyCamel = snakeToCamel(property);
|
|
354
357
|
if (!accountData)
|
|
355
358
|
throw new Error(`Unable to read account relating to ${seed.account}: ${ixProps[parentName]}`);
|
|
356
|
-
const value = accountData[
|
|
359
|
+
const value = accountData[propertyCamel];
|
|
357
360
|
const propertyType = getAccountPropertyType(seed.account, property);
|
|
358
361
|
if (!propertyType)
|
|
359
362
|
throw new Error(`Unable to read property type relating to ${seed.account}: ${property}`);
|
|
@@ -400,44 +403,48 @@ export async function createProgram(programClient, idl, signer = null, noEvents
|
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
406
|
+
if (idl.instructions) {
|
|
407
|
+
for (let instruction of idl.instructions) {
|
|
408
|
+
const name = instruction.name;
|
|
409
|
+
const nameCamel = snakeToCamel(name);
|
|
410
|
+
const NamePascal = snakeToPascal(name);
|
|
411
|
+
const argTypes = instruction.args;
|
|
412
|
+
ixs[nameCamel] = async function () {
|
|
413
|
+
if (arguments.length !== argTypes.length) {
|
|
414
|
+
throw new Error(`Incorrect arguments provided for ${name}. Received ${arguments.length}, expected ${argTypes.length}.`);
|
|
415
|
+
}
|
|
416
|
+
let ixProps = {};
|
|
417
|
+
for (let account in addedAccounts) {
|
|
418
|
+
ixProps[account] = addedAccounts[account];
|
|
419
|
+
}
|
|
420
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
421
|
+
ixProps[snakeToCamel(argTypes[i].name)] = arguments[i];
|
|
422
|
+
}
|
|
423
|
+
await addIxAccounts(instruction, ixProps);
|
|
424
|
+
return programClient[`get${NamePascal}Instruction`](ixProps);
|
|
425
|
+
};
|
|
426
|
+
tx[nameCamel] = async function () {
|
|
427
|
+
let ix = await ixs[nameCamel](...arguments);
|
|
428
|
+
await transactSingle(ix, nameCamel);
|
|
429
|
+
};
|
|
430
|
+
}
|
|
426
431
|
}
|
|
427
432
|
let account = {};
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
433
|
+
if (idl.accounts) {
|
|
434
|
+
for (let a of idl.accounts) {
|
|
435
|
+
const nameCamel = pascalToCamel(a.name);
|
|
436
|
+
account[nameCamel] = async function (addressOrSeeds) {
|
|
437
|
+
if (Array.isArray(addressOrSeeds)) {
|
|
438
|
+
// it's array, assume it's seeds
|
|
439
|
+
const address = await pda(addressOrSeeds);
|
|
440
|
+
return await readAccount(nameCamel, address);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
// assume address
|
|
444
|
+
return await readAccount(nameCamel, addressOrSeeds);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
}
|
|
441
448
|
}
|
|
442
449
|
const returns = {
|
|
443
450
|
on,
|
package/dist/library/utils.js
CHANGED