Skip to content

Commit

Permalink
require kyc account (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthontaylor authored Nov 21, 2024
1 parent 3abb2ab commit 120be25
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/etherfuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use solana_sdk::{
transaction::VersionedTransaction,
};
use stablebond_sdk::accounts::Issuance;
use stablebond_sdk::instructions::{InstantBondRedemption, InstantBondRedemptionInstructionArgs};
use stablebond_sdk::instructions::{
InstantBondRedemptionV2, InstantBondRedemptionV2InstructionArgs,
};
use std::str::FromStr;
use std::sync::Arc;

Expand All @@ -23,9 +25,9 @@ use std::collections::HashMap;

use stablebond_sdk::{
accounts::{Bond, PaymentFeed, SellLiquidity},
find_bond_pda, find_issuance_pda, find_payment_feed_pda, find_payment_pda,
find_bond_pda, find_issuance_pda, find_kyc_pda, find_payment_feed_pda, find_payment_pda,
find_sell_liquidity_pda,
instructions::{PurchaseBond, PurchaseBondInstructionArgs},
instructions::{PurchaseBondV2, PurchaseBondV2InstructionArgs},
};

use crate::{constants::USDC_MINT, field_as_string, transaction::build_and_sign_tx};
Expand Down Expand Up @@ -78,7 +80,7 @@ impl EtherfuseClient {
}

pub async fn purchase_ix(&self, amount: u64, stablebond_mint: Pubkey) -> Result<Instruction> {
let ix_args = PurchaseBondInstructionArgs { amount };
let ix_args = PurchaseBondV2InstructionArgs { amount };

let bond_account = find_bond_pda(stablebond_mint).0;
let data = self.rpc_client.get_account_data(&bond_account).await?;
Expand All @@ -100,7 +102,8 @@ impl EtherfuseClient {
payment_quote_price_feed_account = Some(payment_feed.quote_price_feed);
}

let ix = PurchaseBond {
let ix = PurchaseBondV2 {
kyc_account: find_kyc_pda(user_wallet.pubkey()).0,
user_wallet: user_wallet.pubkey(),
user_token_account: get_associated_token_address_with_program_id(
&user_wallet.pubkey(),
Expand Down Expand Up @@ -173,9 +176,10 @@ impl EtherfuseClient {
let sell_liquidity = SellLiquidity::from_bytes(&sell_liuqidity_data).unwrap();
let sell_liquidity_token_account =
get_associated_token_address(&sell_liquidity_account, &payment_feed.payment_mint);
let ix_args = InstantBondRedemptionInstructionArgs { amount };
let ix_args = InstantBondRedemptionV2InstructionArgs { amount };

let ix = InstantBondRedemption {
let ix = InstantBondRedemptionV2 {
kyc_account: find_kyc_pda(user_wallet.pubkey()).0,
user_wallet: user_wallet.pubkey(),
bond_account,
issuance_account,
Expand Down Expand Up @@ -288,6 +292,14 @@ impl EtherfuseClient {
let issuance = Issuance::from_bytes(&data)?;
Ok(issuance.liquidity)
}

pub async fn has_kyc_account(&self, user_wallet: &Pubkey) -> bool {
let kyc_account = find_kyc_pda(*user_wallet).0;
match self.rpc_client.get_account_data(&kyc_account).await {
Ok(_) => true,
Err(_) => false,
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ async fn main() -> Result<()> {
args.etherfuse_url.clone().unwrap(),
);

if !etherfuse_client
.has_kyc_account(&wallet_keypair.pubkey())
.await
{
println!("Etherfuse does not have a kyc account associated with this wallet. Exiting...");
std::process::exit(1);
}

let rate_limiter = RateLimiter::new(1, 1);

let jupiter_client = JupiterClient::new(
Expand Down

0 comments on commit 120be25

Please sign in to comment.