Skip to content

Commit

Permalink
fix anchor version to 0.30.0
Browse files Browse the repository at this point in the history
as 0.30.1 fail to compile due to the #[program] macro.
  • Loading branch information
brewmaster012 committed Jun 20, 2024
1 parent c8a1186 commit cee00c1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolution = true
skip-lint = false

[programs.localnet]
protocol_contracts_solana = "9WSwbVLthCsJXABeDJcVcw4UQMYuoNLTJTLqueFXU5Q2"
protocol_contracts_solana = "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"

[registry]
url = "https://api.apr.dev"
Expand Down
53 changes: 32 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions programs/protocol-contracts-solana/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-spl = { version = "0.30.0" , features = ["idl-build"]}
solana-program = "1.18.15"
spl-associated-token-account = "3.0.2"
anchor-lang = { version = "=0.30.0" }
anchor-spl = { version = "=0.30.0" , features = ["idl-build"]}
anchor-syn = "=0.30.0"
spl-associated-token-account = "3.0.2"
solana-program = "=1.18.15"
10 changes: 6 additions & 4 deletions programs/protocol-contracts-solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use anchor_lang::system_program;
use anchor_spl::token::{transfer, Token, TokenAccount};
use solana_program::keccak::hash;
use solana_program::secp256k1_recover::secp256k1_recover;
use spl_associated_token_account;
use std::mem::size_of;
use spl_associated_token_account;

#[error_code]
pub enum Errors {
Expand All @@ -22,7 +22,7 @@ pub enum Errors {
MessageHashMismatch,
}

declare_id!("9WSwbVLthCsJXABeDJcVcw4UQMYuoNLTJTLqueFXU5Q2");
declare_id!("94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d");


#[program]
Expand Down Expand Up @@ -100,7 +100,7 @@ pub mod gateway {
let mut concatenated_buffer = Vec::new();
concatenated_buffer.extend_from_slice(&nonce.to_be_bytes());
concatenated_buffer.extend_from_slice(&amount.to_be_bytes());
concatenated_buffer.extend_from_slice(&ctx.accounts.signer.key().to_bytes());
concatenated_buffer.extend_from_slice(&ctx.accounts.to.key().to_bytes());
require!(message_hash == hash(&concatenated_buffer[..]).to_bytes(), Errors::MessageHashMismatch);

let address = recover_eth_address(&message_hash, recovery_id, &signature)?; // ethereum address is the last 20 Bytes of the hashed pubkey
Expand All @@ -112,7 +112,7 @@ pub mod gateway {

// transfer amount of SOL from PDA to the payer
pda.sub_lamports(amount)?;
ctx.accounts.signer.add_lamports(amount)?;
ctx.accounts.to.add_lamports(amount)?;

pda.nonce += 1;

Expand Down Expand Up @@ -228,6 +228,8 @@ pub struct Withdraw<'info> {

#[account(mut)]
pub pda: Account<'info, Pda>,
#[account(mut)]
pub to: SystemAccount<'info>,
}

#[derive(Accounts)]
Expand Down
6 changes: 5 additions & 1 deletion tests/protocol-contracts-solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ describe("some tests", () => {
// );
const nonce = pdaAccountData.nonce;
const amount = new anchor.BN(500000000);
const to = wallet.publicKey;
const buffer = Buffer.concat([
nonce.toArrayLike(Buffer, 'be', 8),
amount.toArrayLike(Buffer, 'be', 8),
wallet.publicKey.toBuffer(),
to.toBuffer(),
]);
const message_hash = keccak256(buffer);
const signature = keyPair.sign(message_hash, 'hex');
Expand All @@ -256,10 +257,13 @@ describe("some tests", () => {
amount, Array.from(signatureBuffer), Number(recoveryParam), Array.from(message_hash), nonce)
.accounts({
pda: pdaAccount,
to: to,
}).rpc();
let bal2 = await conn.getBalance(pdaAccount);
console.log("pda account balance", bal2);
expect(bal2).to.be.eq(bal1 - 500_000_000);
let bal3 = await conn.getBalance(to);
expect(bal3).to.be.gte(500_000_000);
})

it("update TSS address", async () => {
Expand Down
22 changes: 14 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
dependencies:
regenerator-runtime "^0.14.0"

"@coral-xyz/anchor-errors@^0.30.1":
version "0.30.1"
resolved "https://registry.npmjs.org/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz"
integrity sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ==

"@coral-xyz/anchor@^0.30.0":
version "0.30.0"
resolved "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.30.0.tgz"
integrity sha512-qreDh5ztiRHVnCbJ+RS70NJ6aSTPBYDAgFeQ7Z5QvaT5DcDIhNyt4onOciVz2ieIE1XWePOJDDu9SbNvPGBkvQ==
version "0.30.1"
resolved "https://registry.npmjs.org/@coral-xyz/anchor/-/anchor-0.30.1.tgz"
integrity sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ==
dependencies:
"@coral-xyz/borsh" "^0.30.0"
"@coral-xyz/anchor-errors" "^0.30.1"
"@coral-xyz/borsh" "^0.30.1"
"@noble/hashes" "^1.3.1"
"@solana/web3.js" "^1.68.0"
bn.js "^5.1.2"
Expand All @@ -29,10 +35,10 @@
superstruct "^0.15.4"
toml "^3.0.0"

"@coral-xyz/borsh@^0.30.0":
version "0.30.0"
resolved "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.30.0.tgz"
integrity sha512-OrcV+7N10cChhgDRUxM4iEIuwxUHHs52XD85R8cFCUqE0vbLYrcoPPPs+VF6kZ9DhdJGVW2I6DHJOp5TykyZog==
"@coral-xyz/borsh@^0.30.1":
version "0.30.1"
resolved "https://registry.npmjs.org/@coral-xyz/borsh/-/borsh-0.30.1.tgz"
integrity sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ==
dependencies:
bn.js "^5.1.2"
buffer-layout "^1.2.0"
Expand Down

0 comments on commit cee00c1

Please sign in to comment.