Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code consistency #32

Merged
merged 7 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<p align="center">
<a href="https://github.com/nifty-oss/asset/actions/workflows/main.yml"><img src="https://img.shields.io/github/actions/workflow/status/nifty-oss/asset/main.yml?logo=GitHub" /></a>
<!--<a href="https://explorer.solana.com/address/AssetGtQBTSgm5s91d1RAQod5JmaZiJDxqsgtqrZud73"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnifty-oss%2Fasset%2Fmain%2Fidls%2Fasset_program.json&query=%24.version&label=program&logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iMzEzIiBoZWlnaHQ9IjI4MSIgdmlld0JveD0iMCAwIDMxMyAyODEiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF80NzZfMjQzMCkiPgo8cGF0aCBkPSJNMzExLjMxOCAyMjEuMDU3TDI1OS42NiAyNzYuNTU4QzI1OC41MzcgMjc3Ljc2NCAyNTcuMTc4IDI3OC43MjUgMjU1LjY2OSAyNzkuMzgyQzI1NC4xNTkgMjgwLjAzOSAyNTIuNTMgMjgwLjM3OCAyNTAuODg0IDI4MC4zNzdINS45OTcxOUM0LjgyODcgMjgwLjM3NyAzLjY4NTY4IDI4MC4wMzUgMi43MDg1NSAyNzkuMzkzQzEuNzMxNDMgMjc4Ljc1MSAwLjk2M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rZud73"><img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnifty-oss%2Fasset%2Fmain%2Fidls%2Fasset_program.json&query=%24.version&label=program&logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iMzEzIiBoZWlnaHQ9IjI4MSIgdmlld0JveD0iMCAwIDMxMyAyODEiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMF80NzZfMjQzMCkiPgo8cGF0aCBkPSJNMzExLjMxOCAyMjEuMDU3TDI1OS42NiAyNzYuNTU4QzI1OC41MzcgMjc3Ljc2NCAyNTcuMTc4IDI3OC43MjUgMjU1LjY2OSAyNzkuMzgyQzI1NC4xNTkgMjgwLjAzOSAyNTIuNTMgMjgwLjM3OCAyNTAuODg0IDI4MC4zNzdINS45OTcxOUM0LjgyODcgMjgwLjM3NyAzLjY4NTY4IDI4MC4wMzUgMi43MDg1NSAyNzkuMzkzQzEuNzMxNDMgMjc4Ljc1MSAwLjk2Mjc3MSAyNzcuODM3IDAuNDk3MDIgMjc2Ljc2NEMwLjAzMTI2OTEgMjc1LjY5IC0wLjExMTI4NiAyNzQuNTA0IDAuMDg2ODcxMiAyNzMuMzVDMC4yODUwMjggMjcyLjE5NiAwLjgxNTI2NSAyNzEuMTI2IDEuNjEyNDMgMjcwLjI3TDUzLjMwOTkgMjE0Ljc2OUM1NC40Mjk5IDIxMy41NjYgNTUuNzg0MyAyMTIuNjA3IDU3LjI4OTMgMjExLjk1QzU4Ljc5NDMgMjExLjI5MyA2MC40MTc4IDIxMC45NTMgNjIuMDU5NSAyMTAuOTVIMzA2LjkzM0MzMDguMTAxIDIxMC45NSAzMDkuMjQ0IDIxMS4yOTIgMzEwLjIyMSAyMTEuOTM0QzMxMS4xOTkgMjEyLjU3NiAzMTEuOTY3IDIxMy40OSAzMTIuNDMzIDIxNC41NjRDMzE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wIG9mZnNldD0iMC4wOCIgc3RvcC1jb2xvcj0iIzk5NDVGRiIvPgo8c3RvcCBvZmZzZXQ9IjAuMyIgc3RvcC1jb2xvcj0iIzg3NTJGMyIvPgo8c3RvcCBvZmZzZXQ9IjAuNSIgc3RvcC1jb2xvcj0iIzU0OTdENSIvPgo8c3RvcCBvZmZzZXQ9IjAuNiIgc3RvcC1jb2xvcj0iIzQzQjRDQSIvPgo8c3RvcCBvZmZzZXQ9IjAuNzIiIHN0b3AtY29sb3I9IiMyOEUwQjkiLz4KPHN0b3Agb2Zmc2V0PSIwLjk3IiBzdG9wLWNvbG9yPSIjMTlGQjlCIi8+CjwvbGluZWFyR3JhZGllbnQ+CjxjbGlwUGF0aCBpZD0iY2xpcDBfNDc2XzI0MzAiPgo8cmVjdCB3aWR0aD0iMzEyLjkzIiBoZWlnaHQ9IjI4MC4zNzciIGZpbGw9IndoaXRlIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==&color=9945FF" /></a>
<a href="https://www.npmjs.com/package/@nifty-oss/asset"><img src="https://img.shields.io/npm/v/%40nifty-oss%2Fasset?logo=npm&color=377CC0" /></a>
<a href="https://crates.io/crates/nifty-asset"><img src="https://img.shields.io/crates/v/nifty-asset?logo=rust" /></a>
</p>
Expand Down
8 changes: 4 additions & 4 deletions clients/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ pub enum Commands {
/// The asset to lock.
asset: Pubkey,

/// Path to the authority keypair file. Defaults to the signer.
authority_keypair_path: Option<PathBuf>,
/// Path to the signer keypair file. Defaults to the config keypair.
signer_keypair_path: Option<PathBuf>,
},
/// Revoke a delegate from an asset.
Revoke {
Expand Down Expand Up @@ -111,7 +111,7 @@ pub enum Commands {
/// The asset to unlock.
asset: Pubkey,

/// Path to the authority keypair file. Defaults to the signer.
authority_keypair_path: Option<PathBuf>,
/// Path to the signer keypair file. Defaults to the config keypair.
signer_keypair_path: Option<PathBuf>,
},
}
16 changes: 8 additions & 8 deletions clients/cli/src/commands/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ pub struct LockArgs {
pub keypair_path: Option<PathBuf>,
pub rpc_url: Option<String>,
pub asset: Pubkey,
pub authority_keypair_path: Option<PathBuf>,
pub signer_keypair_path: Option<PathBuf>,
}

pub fn handle_lock(args: LockArgs) -> Result<()> {
let config = CliConfig::new(args.keypair_path, args.rpc_url)?;

let payer_sk = Keypair::from_bytes(&config.keypair.to_bytes())?;

// Use provided authority keypair, or default to the signer.
let authority_sk = if let Some(authority) = args.authority_keypair_path {
read_keypair_file(authority)
.map_err(|err| anyhow!("Failed to read authority keypair file: {}", err))?
// Use provided signer keypair, or default to the config keypair.
let signer_sk = if let Some(signer) = args.signer_keypair_path {
read_keypair_file(signer)
.map_err(|err| anyhow!("Failed to read signer keypair file: {}", err))?
} else {
Keypair::from_bytes(&config.keypair.to_bytes())?
};

let authority = authority_sk.pubkey();
let signer = signer_sk.pubkey();
let asset = args.asset;

let ix = Lock { asset, authority }.instruction();
let ix = Lock { asset, signer }.instruction();

let sig = send_and_confirm_tx(&config.client, &[&payer_sk, &authority_sk], &[ix])?;
let sig = send_and_confirm_tx(&config.client, &[&payer_sk, &signer_sk], &[ix])?;

println!("Locking asset {asset} in tx: {sig}");

Expand Down
16 changes: 8 additions & 8 deletions clients/cli/src/commands/unlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ pub struct UnlockArgs {
pub keypair_path: Option<PathBuf>,
pub rpc_url: Option<String>,
pub asset: Pubkey,
pub authority_keypair_path: Option<PathBuf>,
pub signer_keypair_path: Option<PathBuf>,
}

pub fn handle_unlock(args: UnlockArgs) -> Result<()> {
let config = CliConfig::new(args.keypair_path, args.rpc_url)?;

let payer_sk = Keypair::from_bytes(&config.keypair.to_bytes())?;

// Use provided authority keypair, or default to the signer.
let authority_sk = if let Some(authority) = args.authority_keypair_path {
read_keypair_file(authority)
.map_err(|err| anyhow!("Failed to read authority keypair file: {}", err))?
// Use provided signer keypair, or default to the config keypair.
let signer_sk = if let Some(signer) = args.signer_keypair_path {
read_keypair_file(signer)
.map_err(|err| anyhow!("Failed to read signer keypair file: {}", err))?
} else {
Keypair::from_bytes(&config.keypair.to_bytes())?
};

let authority = authority_sk.pubkey();
let signer = signer_sk.pubkey();
let asset = args.asset;

let ix = Unlock { asset, authority }.instruction();
let ix = Unlock { asset, signer }.instruction();

let sig = send_and_confirm_tx(&config.client, &[&payer_sk, &authority_sk], &[ix])?;
let sig = send_and_confirm_tx(&config.client, &[&payer_sk, &signer_sk], &[ix])?;

println!("Unlocking asset {asset} in tx: {sig}");

Expand Down
8 changes: 4 additions & 4 deletions clients/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ async fn main() -> Result<()> {
}),
Commands::Lock {
asset,
authority_keypair_path,
signer_keypair_path,
} => handle_lock(LockArgs {
keypair_path,
rpc_url,
asset,
authority_keypair_path,
signer_keypair_path,
}),
Commands::Mint { asset_file_path } => {
handle_mint(MintArgs {
Expand All @@ -84,12 +84,12 @@ async fn main() -> Result<()> {
}),
Commands::Unlock {
asset,
authority_keypair_path,
signer_keypair_path,
} => handle_unlock(UnlockArgs {
keypair_path,
rpc_url,
asset,
authority_keypair_path,
signer_keypair_path,
}),
}
}
6 changes: 3 additions & 3 deletions clients/js/asset/src/generated/instructions/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type CloseInstructionAccounts = {
/** The unitialized buffer account */
buffer: Signer;
/** The account receiving refunded rent */
destination: PublicKey | Pda;
recipient: PublicKey | Pda;
};

// Data.
Expand Down Expand Up @@ -69,10 +69,10 @@ export function close(
isWritable: true as boolean,
value: input.buffer ?? null,
},
destination: {
recipient: {
index: 1,
isWritable: true as boolean,
value: input.destination ?? null,
value: input.recipient ?? null,
},
} satisfies ResolvedAccountsWithIndices;

Expand Down
13 changes: 4 additions & 9 deletions clients/js/asset/src/generated/instructions/lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type LockInstructionAccounts = {
/** Asset account */
asset: PublicKey | Pda;
/** Delegate or owner account */
authority?: Signer;
signer: Signer;
};

// Data.
Expand All @@ -53,7 +53,7 @@ export function getLockInstructionDataSerializer(): Serializer<

// Instruction.
export function lock(
context: Pick<Context, 'identity' | 'programs'>,
context: Pick<Context, 'programs'>,
input: LockInstructionAccounts
): TransactionBuilder {
// Program ID.
Expand All @@ -69,18 +69,13 @@ export function lock(
isWritable: true as boolean,
value: input.asset ?? null,
},
authority: {
signer: {
index: 1,
isWritable: false as boolean,
value: input.authority ?? null,
value: input.signer ?? null,
},
} satisfies ResolvedAccountsWithIndices;

// Default values.
if (!resolvedAccounts.authority.value) {
resolvedAccounts.authority.value = context.identity;
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
resolvedAccounts
Expand Down
13 changes: 4 additions & 9 deletions clients/js/asset/src/generated/instructions/unlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type UnlockInstructionAccounts = {
/** Asset account */
asset: PublicKey | Pda;
/** Delegate or owner account */
authority?: Signer;
signer: Signer;
};

// Data.
Expand All @@ -53,7 +53,7 @@ export function getUnlockInstructionDataSerializer(): Serializer<

// Instruction.
export function unlock(
context: Pick<Context, 'identity' | 'programs'>,
context: Pick<Context, 'programs'>,
input: UnlockInstructionAccounts
): TransactionBuilder {
// Program ID.
Expand All @@ -69,18 +69,13 @@ export function unlock(
isWritable: true as boolean,
value: input.asset ?? null,
},
authority: {
signer: {
index: 1,
isWritable: false as boolean,
value: input.authority ?? null,
value: input.signer ?? null,
},
} satisfies ResolvedAccountsWithIndices;

// Default values.
if (!resolvedAccounts.authority.value) {
resolvedAccounts.authority.value = context.identity;
}

// Accounts in order.
const orderedAccounts: ResolvedAccount[] = Object.values(
resolvedAccounts
Expand Down
4 changes: 2 additions & 2 deletions clients/js/asset/test/close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('it can close an uninitialized asset buffer account', async (t) => {
// When we close the asset buffer.
await close(umi, {
buffer: asset,
destination: umi.identity.publicKey,
recipient: umi.identity.publicKey,
}).sendAndConfirm(umi);

// Then the asset buffer account was closed.
Expand All @@ -44,7 +44,7 @@ test('it cannot close an initialized asset account', async (t) => {
// When we try to close the asset account.
const promise = close(umi, {
buffer: asset,
destination: umi.identity.publicKey,
recipient: umi.identity.publicKey,
}).sendAndConfirm(umi);

// Then we expect an error.
Expand Down
26 changes: 13 additions & 13 deletions clients/js/asset/test/lock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('it can lock an asset as an owner', async (t) => {
// When we lock the asset as an owner.
await lock(umi, {
asset: asset.publicKey,
authority: owner,
signer: owner,
}).sendAndConfirm(umi);

// Then the asset is locked.
Expand All @@ -55,11 +55,11 @@ test('it can lock an asset with a delegate', async (t) => {
}).sendAndConfirm(umi);

// And we set a delegate that can lock the asset.
const authority = generateSigner(umi);
const signer = generateSigner(umi);
await approve(umi, {
asset: asset.publicKey,
owner,
delegate: authority.publicKey,
delegate: signer.publicKey,
delegateInput: delegateInput('Some', {
roles: [DelegateRole.Lock],
}),
Expand All @@ -68,7 +68,7 @@ test('it can lock an asset with a delegate', async (t) => {
// When we lock the asset.
await lock(umi, {
asset: asset.publicKey,
authority,
signer,
}).sendAndConfirm(umi);

// Then the asset is locked.
Expand All @@ -93,11 +93,11 @@ test('it cannot transfer a locked asset', async (t) => {
}).sendAndConfirm(umi);

// And we set a delegate that can lock the asset.
const authority = generateSigner(umi);
const signer = generateSigner(umi);
await approve(umi, {
asset: asset.publicKey,
owner,
delegate: authority.publicKey,
delegate: signer.publicKey,
delegateInput: delegateInput('Some', {
roles: [DelegateRole.Lock],
}),
Expand All @@ -106,7 +106,7 @@ test('it cannot transfer a locked asset', async (t) => {
// And we lock the asset.
await lock(umi, {
asset: asset.publicKey,
authority,
signer,
}).sendAndConfirm(umi);

// When we try to transfer the asset
Expand Down Expand Up @@ -136,11 +136,11 @@ test('it cannot lock an asset without "Lock" role', async (t) => {
}).sendAndConfirm(umi);

// And we set a delegate that can lock the asset.
const authority = generateSigner(umi);
const signer = generateSigner(umi);
await approve(umi, {
asset: asset.publicKey,
owner,
delegate: authority.publicKey,
delegate: signer.publicKey,
delegateInput: delegateInput('Some', {
roles: [DelegateRole.Transfer],
}),
Expand All @@ -149,7 +149,7 @@ test('it cannot lock an asset without "Lock" role', async (t) => {
// When we lock the asset.
const promise = lock(umi, {
asset: asset.publicKey,
authority,
signer,
}).sendAndConfirm(umi);

// Then we get an error.
Expand All @@ -171,11 +171,11 @@ test('it cannot lock as an owner if delegate set', async (t) => {
}).sendAndConfirm(umi);

// And we set a delegate that can lock the asset.
const authority = generateSigner(umi);
const signer = generateSigner(umi);
await approve(umi, {
asset: asset.publicKey,
owner,
delegate: authority.publicKey,
delegate: signer.publicKey,
delegateInput: delegateInput('Some', {
roles: [DelegateRole.Lock, DelegateRole.Transfer],
}),
Expand All @@ -184,7 +184,7 @@ test('it cannot lock as an owner if delegate set', async (t) => {
// When we try to lock the asset as an owner.
const promise = lock(umi, {
asset: asset.publicKey,
authority: owner,
signer: owner,
}).sendAndConfirm(umi);

// Then we get an error.
Expand Down
Loading