Skip to content

Commit e4f92c5

Browse files
committed
♻️ Code Refactor
1 parent 9f2d328 commit e4f92c5

29 files changed

+545
-526
lines changed

.prettierignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ignore all files in the generated types directory
2+
clients/bolt-sdk/src/generated/types/world.ts
3+
4+
# You can add more patterns here
5+
node_modules
6+
dist
7+
8+
clients/bolt-sdk/idl/world.ts
9+
.anchor
10+
target

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"printWidth": 80,
6+
"tabWidth": 2
7+
}

cli/npm-package/bolt.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env node
2-
import fs from "fs";
3-
import { spawn, spawnSync } from "child_process";
4-
import path from "path";
5-
import { arch, platform } from "os";
6-
import { version } from "./package.json";
2+
import fs from 'fs';
3+
import { spawn, spawnSync } from 'child_process';
4+
import path from 'path';
5+
import { arch, platform } from 'os';
6+
import { version } from './package.json';
77

88
const PACKAGE_VERSION = `bolt-cli ${version}`;
99

1010
function getBinaryVersion(location: string): [string | null, string | null] {
11-
const result = spawnSync(location, ["--version"]);
11+
const result = spawnSync(location, ['--version']);
1212
const error: string | null =
1313
(result.error && result.error.toString()) ||
1414
(result.stderr.length > 0 && result.stderr.toString().trim()) ||
@@ -18,26 +18,26 @@ function getBinaryVersion(location: string): [string | null, string | null] {
1818

1919
function getExePath(): string {
2020
let os: string = platform();
21-
let extension = "";
22-
if (["win32", "cygwin"].includes(os)) {
23-
os = "windows";
24-
extension = ".exe";
21+
let extension = '';
22+
if (['win32', 'cygwin'].includes(os)) {
23+
os = 'windows';
24+
extension = '.exe';
2525
}
2626
const binaryName = `@magicblock-labs/bolt-cli-${os}-${arch()}/bin/bolt${extension}`;
2727
try {
2828
return require.resolve(binaryName);
2929
} catch (e) {
3030
throw new Error(
31-
`Couldn't find application binary inside node_modules for ${os}-${arch()}`
31+
`Couldn't find application binary inside node_modules for ${os}-${arch()}`,
3232
);
3333
}
3434
}
3535

3636
function runBolt(location: string): void {
3737
const args = process.argv.slice(2);
38-
const bolt = spawn(location, args, { stdio: "inherit" });
39-
bolt.on("exit", (code: number | null, signal: NodeJS.Signals | null) => {
40-
process.on("exit", () => {
38+
const bolt = spawn(location, args, { stdio: 'inherit' });
39+
bolt.on('exit', (code: number | null, signal: NodeJS.Signals | null) => {
40+
process.on('exit', () => {
4141
if (signal) {
4242
process.kill(process.pid, signal);
4343
} else if (code !== null) {
@@ -46,9 +46,9 @@ function runBolt(location: string): void {
4646
});
4747
});
4848

49-
process.on("SIGINT", () => {
50-
bolt.kill("SIGINT");
51-
bolt.kill("SIGTERM");
49+
process.on('SIGINT', () => {
50+
bolt.kill('SIGINT');
51+
bolt.kill('SIGTERM');
5252
});
5353
}
5454

@@ -59,8 +59,8 @@ function tryPackageBolt(): boolean {
5959
return true;
6060
} catch (e) {
6161
console.error(
62-
"Failed to run bolt from package:",
63-
e instanceof Error ? e.message : e
62+
'Failed to run bolt from package:',
63+
e instanceof Error ? e.message : e,
6464
);
6565
return false;
6666
}
@@ -80,7 +80,7 @@ function trySystemBolt(): void {
8080

8181
if (!absolutePath) {
8282
console.error(
83-
`Could not find globally installed bolt, please install with cargo.`
83+
`Could not find globally installed bolt, please install with cargo.`,
8484
);
8585
process.exit(1);
8686
}
@@ -94,7 +94,7 @@ function trySystemBolt(): void {
9494
}
9595
if (binaryVersion !== PACKAGE_VERSION) {
9696
console.error(
97-
`Globally installed bolt version is not correct. Expected "${PACKAGE_VERSION}", found "${binaryVersion}".`
97+
`Globally installed bolt version is not correct. Expected "${PACKAGE_VERSION}", found "${binaryVersion}".`,
9898
);
9999
return;
100100
}

clients/bolt-sdk/.solitarc.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const path = require("path");
2-
const programDir = path.join(__dirname, "../../", "programs", "world");
3-
const idlDir = path.join(__dirname, "idl");
4-
const sdkDir = path.join(__dirname, "src", "generated");
5-
const binaryInstallDir = path.join(__dirname, ".crates");
1+
const path = require('path');
2+
const programDir = path.join(__dirname, '../../', 'programs', 'world');
3+
const idlDir = path.join(__dirname, 'idl');
4+
const sdkDir = path.join(__dirname, 'src', 'generated');
5+
const binaryInstallDir = path.join(__dirname, '.crates');
66

77
module.exports = {
8-
idlGenerator: "anchor",
9-
programName: "world",
10-
programId: "WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n",
8+
idlGenerator: 'anchor',
9+
programName: 'world',
10+
programId: 'WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n',
1111
removeExistingIdl: false,
1212
idlDir,
1313
sdkDir,

clients/bolt-sdk/src/delegation/allow_undelegation.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import * as beet from "@metaplex-foundation/beet";
2-
import * as web3 from "@solana/web3.js";
1+
import * as beet from '@metaplex-foundation/beet';
2+
import * as web3 from '@solana/web3.js';
33
import {
44
DelegateAccounts,
55
DELEGATION_PROGRAM_ID,
6-
} from "@magicblock-labs/ephemeral-rollups-sdk";
6+
} from '@magicblock-labs/ephemeral-rollups-sdk';
77

88
export const allowUndelegationStruct = new beet.BeetArgsStruct<{
99
instructionDiscriminator: number[] /* size: 8 */;
1010
}>(
11-
[["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)]],
12-
"allowUndelegationInstructionArgs"
11+
[['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)]],
12+
'allowUndelegationInstructionArgs',
1313
);
1414

1515
export interface AllowUndelegationInstructionAccounts {
@@ -27,15 +27,15 @@ export const allowUndelegateInstructionDiscriminator = [
2727
*/
2828

2929
export function createAllowUndelegationInstruction(
30-
accounts: AllowUndelegationInstructionAccounts
30+
accounts: AllowUndelegationInstructionAccounts,
3131
) {
3232
const [data] = allowUndelegationStruct.serialize({
3333
instructionDiscriminator: allowUndelegateInstructionDiscriminator,
3434
});
3535

3636
const { delegationPda, delegationMetadata, bufferPda } = DelegateAccounts(
3737
accounts.delegatedAccount,
38-
accounts.ownerProgram
38+
accounts.ownerProgram,
3939
);
4040

4141
const keys: web3.AccountMeta[] = [

clients/bolt-sdk/src/delegation/delegate.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import * as beet from "@metaplex-foundation/beet";
2-
import * as web3 from "@solana/web3.js";
1+
import * as beet from '@metaplex-foundation/beet';
2+
import * as web3 from '@solana/web3.js';
33
import {
44
DelegateAccounts,
55
DELEGATION_PROGRAM_ID,
6-
} from "@magicblock-labs/ephemeral-rollups-sdk";
7-
import { FindComponentPda } from "../index";
6+
} from '@magicblock-labs/ephemeral-rollups-sdk';
7+
import { FindComponentPda } from '../index';
88
import {
99
type PublicKey,
1010
Transaction,
1111
type TransactionInstruction,
12-
} from "@solana/web3.js";
12+
} from '@solana/web3.js';
1313

1414
export interface DelegateInstructionArgs {
1515
validUntil: beet.bignum;
@@ -22,11 +22,11 @@ export const delegateStruct = new beet.FixableBeetArgsStruct<
2222
}
2323
>(
2424
[
25-
["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
26-
["validUntil", beet.i64],
27-
["commitFrequencyMs", beet.u32],
25+
['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
26+
['validUntil', beet.i64],
27+
['commitFrequencyMs', beet.u32],
2828
],
29-
"DelegateInstructionArgs"
29+
'DelegateInstructionArgs',
3030
);
3131

3232
/**
@@ -58,7 +58,7 @@ export function createDelegateInstruction(
5858
accounts: DelegateInstructionAccounts,
5959
validUntil: beet.bignum = 0,
6060
commitFrequencyMs: number = 30000,
61-
programId = accounts.ownerProgram
61+
programId = accounts.ownerProgram,
6262
) {
6363
const [data] = delegateStruct.serialize({
6464
instructionDiscriminator: delegateInstructionDiscriminator,
@@ -68,7 +68,7 @@ export function createDelegateInstruction(
6868

6969
const { delegationPda, delegationMetadata, bufferPda } = DelegateAccounts(
7070
accounts.account,
71-
accounts.ownerProgram
71+
accounts.ownerProgram,
7272
);
7373

7474
const keys: web3.AccountMeta[] = [
@@ -144,7 +144,7 @@ export async function DelegateComponent({
144144
payer,
145145
entity,
146146
componentId,
147-
seed = "",
147+
seed = '',
148148
buffer,
149149
delegationRecord,
150150
delegationMetadata,

clients/bolt-sdk/src/delegation/undelegate.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import * as beet from "@metaplex-foundation/beet";
2-
import * as web3 from "@solana/web3.js";
1+
import * as beet from '@metaplex-foundation/beet';
2+
import * as web3 from '@solana/web3.js';
33
import {
44
MAGIC_CONTEXT_ID,
55
MAGIC_PROGRAM_ID,
6-
} from "@magicblock-labs/ephemeral-rollups-sdk";
6+
} from '@magicblock-labs/ephemeral-rollups-sdk';
77

88
export const undelegateStruct = new beet.BeetArgsStruct<{
99
instructionDiscriminator: number[] /* size: 8 */;
1010
}>(
11-
[["instructionDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)]],
12-
"undelegateInstructionArgs"
11+
[['instructionDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)]],
12+
'undelegateInstructionArgs',
1313
);
1414

1515
export interface UndelegateInstructionAccounts {
@@ -26,7 +26,7 @@ export const undelegateInstructionDiscriminator = [
2626
* Creates an Undelegate instruction.
2727
*/
2828
export function createUndelegateInstruction(
29-
accounts: UndelegateInstructionAccounts
29+
accounts: UndelegateInstructionAccounts,
3030
) {
3131
const [data] = undelegateStruct.serialize({
3232
instructionDiscriminator: undelegateInstructionDiscriminator,

clients/bolt-sdk/src/generated/accounts/Entity.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* See: https://github.com/metaplex-foundation/solita
66
*/
77

8-
import * as beet from "@metaplex-foundation/beet";
9-
import * as web3 from "@solana/web3.js";
10-
import * as beetSolana from "@metaplex-foundation/beet-solana";
8+
import * as beet from '@metaplex-foundation/beet';
9+
import * as web3 from '@solana/web3.js';
10+
import * as beetSolana from '@metaplex-foundation/beet-solana';
1111

1212
/**
1313
* Arguments used to create {@link Entity}
@@ -42,7 +42,7 @@ export class Entity implements EntityArgs {
4242
*/
4343
static fromAccountInfo(
4444
accountInfo: web3.AccountInfo<Buffer>,
45-
offset = 0
45+
offset = 0,
4646
): [Entity, number] {
4747
return Entity.deserialize(accountInfo.data, offset);
4848
}
@@ -56,11 +56,11 @@ export class Entity implements EntityArgs {
5656
static async fromAccountAddress(
5757
connection: web3.Connection,
5858
address: web3.PublicKey,
59-
commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig
59+
commitmentOrConfig?: web3.Commitment | web3.GetAccountInfoConfig,
6060
): Promise<Entity> {
6161
const accountInfo = await connection.getAccountInfo(
6262
address,
63-
commitmentOrConfig
63+
commitmentOrConfig,
6464
);
6565
if (accountInfo == null) {
6666
throw new Error(`Unable to find Entity account at ${address}`);
@@ -76,8 +76,8 @@ export class Entity implements EntityArgs {
7676
*/
7777
static gpaBuilder(
7878
programId: web3.PublicKey = new web3.PublicKey(
79-
"WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n"
80-
)
79+
'WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n',
80+
),
8181
) {
8282
return beetSolana.GpaBuilder.fromStruct(programId, entityBeet);
8383
}
@@ -117,11 +117,11 @@ export class Entity implements EntityArgs {
117117
*/
118118
static async getMinimumBalanceForRentExemption(
119119
connection: web3.Connection,
120-
commitment?: web3.Commitment
120+
commitment?: web3.Commitment,
121121
): Promise<number> {
122122
return connection.getMinimumBalanceForRentExemption(
123123
Entity.byteSize,
124-
commitment
124+
commitment,
125125
);
126126
}
127127

@@ -141,7 +141,7 @@ export class Entity implements EntityArgs {
141141
return {
142142
id: (() => {
143143
const x = this.id as { toNumber: () => number };
144-
if (typeof x.toNumber === "function") {
144+
if (typeof x.toNumber === 'function') {
145145
try {
146146
return x.toNumber();
147147
} catch (_) {
@@ -165,9 +165,9 @@ export const entityBeet = new beet.BeetStruct<
165165
}
166166
>(
167167
[
168-
["accountDiscriminator", beet.uniformFixedSizeArray(beet.u8, 8)],
169-
["id", beet.u64],
168+
['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
169+
['id', beet.u64],
170170
],
171171
Entity.fromArgs,
172-
"Entity"
172+
'Entity',
173173
);

0 commit comments

Comments
 (0)