Skip to content

Conversation

@qapquiz
Copy link

@qapquiz qapquiz commented Nov 6, 2024

instructions

  • init_escrow
  • init_nft_data
  • update_escrow
  • update_new_data
  • capture
  • release

This pull request was created for https://app.gib.work/bounties/aeb1c1a9-9af0-4265-9501-8c9e469afd0b in an attempt to solve a bounty #152 . Payment for the bounty is immediately sent to the contributor after merge.

- init_escrow
- update_escrow
- capture
- release
@enzotar
Copy link
Contributor

enzotar commented Nov 6, 2024

Nice. Can you add the remaining instructions and tests. Here's an example command with a test:

@qapquiz
Copy link
Author

qapquiz commented Nov 6, 2024

Nice. Can you add the remaining instructions and tests. Here's an example command with a test:

Okay I will add. 🫡

@qapquiz
Copy link
Author

qapquiz commented Nov 7, 2024

@enzotar Do you have a proper way to setup token and nft collection for testing purpose?

@enzotar
Copy link
Contributor

enzotar commented Nov 7, 2024

@enzotar Do you have a proper way to setup token and nft collection for testing purpose?

Here you go, try these #163

@enzotar
Copy link
Contributor

enzotar commented Nov 7, 2024

You can import the jsons into Space Operator to edit the flows.
image
image

@qapquiz
Copy link
Author

qapquiz commented Nov 9, 2024

@enzotar Could you take a look at this first? Is it okay for you?

#[cfg(test)]
mod tests {
use crate::utils::ui_amount_to_amount;
use mpl_core::instructions::CreateCollectionV2Builder;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use super::*;
async fn create_mock_collection(
ctx: &Context,
collection: &Keypair,
payer: &Keypair,
name: String,
uri: String,
) {
let ix = CreateCollectionV2Builder::new()
.collection(collection.pubkey())
.payer(payer.pubkey())
.update_authority(Some(payer.pubkey()))
.name(name)
.uri(uri)
.instruction();
let (mut create_collection_tx, recent_blockhash) =
execute(&ctx.solana_client, &payer.pubkey(), &[ix])
.await
.unwrap();
try_sign_wallet(
&ctx,
&mut create_collection_tx,
&[&payer, &collection],
recent_blockhash,
)
.await
.unwrap();
let create_collection_signature =
submit_transaction(&ctx.solana_client, create_collection_tx)
.await
.unwrap();
dbg!(create_collection_signature);
}
#[test]
fn test_build() {
build().unwrap();
}
#[tokio::test]
async fn test_run() {
let ctx = Context::default();
// setup fee_payer
let fee_payer = Keypair::from_base58_string("4rQanLxTFvdgtLsGirizXejgYXACawB5ShoZgvz4wwXi4jnii7XHSyUFJbvAk4ojRiEAHvzK6Qnjq7UyJFNbydeQ");
let balance = ctx
.solana_client
.get_balance(&fee_payer.pubkey())
.await
.unwrap() as f64
/ LAMPORTS_PER_SOL as f64;
if balance < 0.1 {
let _ = ctx
.solana_client
.request_airdrop(&fee_payer.pubkey(), LAMPORTS_PER_SOL)
.await;
}
let token = solana_sdk::pubkey!("AdaQ1MKbeKDyXCSnuCtqs5MW9FaY1UMGtpCGbZnpbTbj");
let sol_amount_to_create_token_account = rust_decimal_macros::dec!(0.03);
let sol_decimals = 9;
let collection = Keypair::new();
create_mock_collection(
&ctx,
&collection,
&fee_payer,
String::from("Mock Collection"),
String::from("https://example.com"),
)
.await;
// setup SUT
let fee_token_decimals = 9_u8;
let authority = fee_payer.clone_keypair();
let fee_wallet = Keypair::new().pubkey();
let name = String::from("Escrow Name");
let uri = String::from("https://base.spaceoperator.com/storage/v1/object/public/blings_gg_nft/asset_metadata.json");
let max = 999_u64;
let min = 0_u64;
let path = 1;
// fund authority and fee_wallet for creating token account
let (mut transfer_tx, recent_blockhash) = execute(
&ctx.solana_client,
&fee_payer.pubkey(),
&[
solana_sdk::system_instruction::transfer(
&fee_payer.pubkey(),
&authority.pubkey(),
ui_amount_to_amount(sol_amount_to_create_token_account, sol_decimals).unwrap(),
),
],
)
.await
.unwrap();
try_sign_wallet(&ctx, &mut transfer_tx, &[&fee_payer], recent_blockhash)
.await
.unwrap();
let transfer_signature = submit_transaction(&ctx.solana_client, transfer_tx)
.await
.unwrap();
dbg!(transfer_signature);
// init escrow
let output = run(
ctx,
super::Input {
fee_payer,
fee_token_decimals,
authority,
collection: collection.pubkey(),
token,
fee_location: fee_wallet,
name,
uri,
max,
min,
amount: rust_decimal_macros::dec!(0.1),
fee_amount: rust_decimal_macros::dec!(0.1),
sol_fee_amount: rust_decimal_macros::dec!(0.1),
path,
submit: true,
},
)
.await
.unwrap();
dbg!(output.signature.unwrap());
}
}

@enzotar
Copy link
Contributor

enzotar commented Nov 9, 2024

@enzotar Could you take a look at this first? Is it okay for you?

#[cfg(test)]
mod tests {
use crate::utils::ui_amount_to_amount;
use mpl_core::instructions::CreateCollectionV2Builder;
use solana_sdk::native_token::LAMPORTS_PER_SOL;
use super::*;
async fn create_mock_collection(
ctx: &Context,
collection: &Keypair,
payer: &Keypair,
name: String,
uri: String,
) {
let ix = CreateCollectionV2Builder::new()
.collection(collection.pubkey())
.payer(payer.pubkey())
.update_authority(Some(payer.pubkey()))
.name(name)
.uri(uri)
.instruction();
let (mut create_collection_tx, recent_blockhash) =
execute(&ctx.solana_client, &payer.pubkey(), &[ix])
.await
.unwrap();
try_sign_wallet(
&ctx,
&mut create_collection_tx,
&[&payer, &collection],
recent_blockhash,
)
.await
.unwrap();
let create_collection_signature =
submit_transaction(&ctx.solana_client, create_collection_tx)
.await
.unwrap();
dbg!(create_collection_signature);
}
#[test]
fn test_build() {
build().unwrap();
}
#[tokio::test]
async fn test_run() {
let ctx = Context::default();
// setup fee_payer
let fee_payer = Keypair::from_base58_string("4rQanLxTFvdgtLsGirizXejgYXACawB5ShoZgvz4wwXi4jnii7XHSyUFJbvAk4ojRiEAHvzK6Qnjq7UyJFNbydeQ");
let balance = ctx
.solana_client
.get_balance(&fee_payer.pubkey())
.await
.unwrap() as f64
/ LAMPORTS_PER_SOL as f64;
if balance < 0.1 {
let _ = ctx
.solana_client
.request_airdrop(&fee_payer.pubkey(), LAMPORTS_PER_SOL)
.await;
}
let token = solana_sdk::pubkey!("AdaQ1MKbeKDyXCSnuCtqs5MW9FaY1UMGtpCGbZnpbTbj");
let sol_amount_to_create_token_account = rust_decimal_macros::dec!(0.03);
let sol_decimals = 9;
let collection = Keypair::new();
create_mock_collection(
&ctx,
&collection,
&fee_payer,
String::from("Mock Collection"),
String::from("https://example.com"),
)
.await;
// setup SUT
let fee_token_decimals = 9_u8;
let authority = fee_payer.clone_keypair();
let fee_wallet = Keypair::new().pubkey();
let name = String::from("Escrow Name");
let uri = String::from("https://base.spaceoperator.com/storage/v1/object/public/blings_gg_nft/asset_metadata.json");
let max = 999_u64;
let min = 0_u64;
let path = 1;
// fund authority and fee_wallet for creating token account
let (mut transfer_tx, recent_blockhash) = execute(
&ctx.solana_client,
&fee_payer.pubkey(),
&[
solana_sdk::system_instruction::transfer(
&fee_payer.pubkey(),
&authority.pubkey(),
ui_amount_to_amount(sol_amount_to_create_token_account, sol_decimals).unwrap(),
),
],
)
.await
.unwrap();
try_sign_wallet(&ctx, &mut transfer_tx, &[&fee_payer], recent_blockhash)
.await
.unwrap();
let transfer_signature = submit_transaction(&ctx.solana_client, transfer_tx)
.await
.unwrap();
dbg!(transfer_signature);
// init escrow
let output = run(
ctx,
super::Input {
fee_payer,
fee_token_decimals,
authority,
collection: collection.pubkey(),
token,
fee_location: fee_wallet,
name,
uri,
max,
min,
amount: rust_decimal_macros::dec!(0.1),
fee_amount: rust_decimal_macros::dec!(0.1),
sol_fee_amount: rust_decimal_macros::dec!(0.1),
path,
submit: true,
},
)
.await
.unwrap();
dbg!(output.signature.unwrap());
}
}

Looks good

@qapquiz
Copy link
Author

qapquiz commented Nov 10, 2024

@enzotar Done for all of the v1 instructions ❤️ (oh I just saw that there are more ix urgh)

@enzotar enzotar merged commit 9ee73fe into space-operator:gibwork-mpl-404 Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants