Giter Club home page Giter Club logo

solana-escrow's Introduction

solana-escrow's People

Contributors

0xnilsolav avatar paul-schaaf avatar qpwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

solana-escrow's Issues

unresolved imports `crate::error`, `crate::instruction`

unresolved imports `crate::error`, `crate::instruction`

unresolved import

help: a similar path exists: `solana_program::instruction`

I get this error in processor.rs with use crate::{error::EscrowError, instruction::EscrowInstruction, state::Escrow};

Error processing Instruction 0

It seems that I created everything correctly. Created all needed accounts. Escrow init was ok:

Escrow account: Aaoz8PEUppzV9mP5D22kXZmvu7PGQDEB3MmYAmuEQ6JC
Decoded State
Is initialized: true
Initializer account: 6xBPTVQpxcfR7eDkmzLg1LVzs9ULgk1hFVLArFcH3JkQ
X token temp account: BHJt5LbyfY8U3HpdPLrbT5BX7xzQm8bu5cfzJ7cXs4h3
Initializer Y token account: 9epPAbwZKkQFRaGrDJgiYHbr9fmDgpwemCN8La9pVZW4
ExpectedAmount: 4

But when I try to proceed with Bob's transaction, I always receive "Error processing Instruction 0: custom program error: 0x2".

failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x2

Please help me.

XTokenMintAccountPubkey Isn't Defined nor Commented On At All

In the tutorial, XTokenMintAccountPubkey is used in the following line:

const initTempAccountIx = Token.createInitAccountInstruction(TOKEN_PROGRAM_ID, XTokenMintAccountPubkey, tempTokenAccount.publicKey, feePayerAcc.publicKey);

The only mention of XTokenMintAccountPubkey in the tutorial is on this line where it's used. Trying to run the example is difficult because of this (and many other examples like it). In the repository, I see const XTokenMintPubkey = getPublicKey("mint_x"); which should be referring to a file, mint_x, which file doesn't exist in the repo.

Besides that, I think I understand that if I want a spl token on my test validator, I have to add the bpf program (--bpf-program) when I launch the test validator, but the tutorial doesn't say anything about this.

  • Explain how to add token code to the test validator so that the example can run

Only Solana coins support?

The project supports Solana coins, or the ones built on Solana blockchain, only. And only with those. Right?

Info on the js side

Hello, going through the article, you have not provided any info wrt the js side of the code. Can you pls do so?

Failde while requesting SOL for Alice...

E:\BlockchainWallet\Rust\solana-escrow\scripts>npm run setup

[email protected] setup E:\BlockchainWallet\Rust\solana-escrow\scripts
npm run compile && node --trace-warnings build/setup.js

[email protected] compile E:\BlockchainWallet\Rust\solana-escrow\scripts
tsc -p ./tsconfig.json

Requesting SOL for Alice...
(node:145032) UnhandledPromiseRejectionWarning: SolanaJSONRPCError: airdrop to 56soKhmhDDx9A4BUqVZmr7ENqBxroFZmtrNTzw47S5Dr failed: Internal error
at Connection.requestAirdrop (E:\BlockchainWallet\Rust\solana-escrow\scripts\node_modules@solana\web3.js\lib\index.cjs.js:7330:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:96:32)
(node:145032) SolanaJSONRPCError: airdrop to 56soKhmhDDx9A4BUqVZmr7ENqBxroFZmtrNTzw47S5Dr failed: Internal error
at Connection.requestAirdrop (E:\BlockchainWallet\Rust\solana-escrow\scripts\node_modules@solana\web3.js\lib\index.cjs.js:7330:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:145032) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:96:32)

Deploy solana program Failed

I build-bpf , and deploy program on devnet , but failed
$ solana program deploy /home/bc_code/solana-escrow/program/target/deploy/solana_escrow.so --keypair solana-wallet/keypair.json

Proposed Solution
Blockhash expired. 5 retries remaining
Blockhash expired. 4 retries remaining
Blockhash expired. 3 retries remaining
Blockhash expired. 2 retries remaining
Blockhash expired. 1 retries remaining
Recover the intermediate account's ephemeral keypair file with
solana-keygen recover and the following 12-word seed phrase:
chaos shrug glance blame output appear kitten angry jacket hurry narrow stumble
To resume a deploy, pass the recovered keypair as the
[BUFFER_SIGNER] to solana program deploy or solana write-buffer'. Or to recover the account's lamports, pass it as the [BUFFER_ACCOUNT_ADDRESS] argument to solana program close`.
Error: Data writes to account failed: Custom error: Max retries exceeded

node build/setup.js fails

src/setup.ts:67:35 - error TS2552: Cannot find name 'IdPublicKey'. Did you mean 'PublicKey'?

67   await connection.requestAirdrop(IdPublicKey, LAMPORTS_PER_SOL * 10);

Bob script fails

Running Bob script fails with below error. Any pointers for a fix?

Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
Program 4yBTZXsuz7c1X3PJF4PPCJr8G6HnNAgRvzAWVoFZMncH invoke [1]
Program 4yBTZXsuz7c1X3PJF4PPCJr8G6HnNAgRvzAWVoFZMncH consumed 1830 of 200000 compute units
Program 4yBTZXsuz7c1X3PJF4PPCJr8G6HnNAgRvzAWVoFZMncH failed: custom program error: 0x0
solana-escrow-master/scripts/node_modules/@solana/web3.js/lib/index.cjs.js:4964
throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
^

SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: custom program error: 0x0
at Connection.sendEncodedTransaction (solana-escrow-master/scripts/node_modules/@solana/web3.js/lib/index.cjs.js:4964:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Connection.sendRawTransaction (solana-escrow-master/scripts/node_modules/@solana/web3.js/lib/index.cjs.js:4923:20)
at async Connection.sendTransaction (solana-escrow-master/scripts/node_modules/@solana/web3.js/lib/index.cjs.js:4913:12) {
logs: [
'Program 4yBTZXsuz7c1X3PJF4PPCJr8G6HnNAgRvzAWVoFZMncH invoke [1]',
'Program 4yBTZXsuz7c1X3PJF4PPCJr8G6HnNAgRvzAWVoFZMncH consumed 1830 of 200000 compute units',
'Program 4yBTZXsuz7c1X3PJF4PPCJr8G6HnNAgRvzAWVoFZMncH failed: custom program error: 0x0'
]
}

Possible to frontrun with `escrow_info.amount`?

Hey there!

Thanks for this tutorial. It's been super helpful. I'm trying to understand whether it's possible to do the same frontrunning attack you describe but on token Y instead of token X:

In process_exchange we check that the number of tokens in the pdas_temp_token_account match the amount_expected_by_taker so that Alice can't frontrun by cancelling, making a new escrow account with the same address, and filling pdas_temp_token_account with fewer tokens than in the original escrow account.

However, if Bob passes a takers_sending_token_account for token Y that holds more than escrow_info.expected_amount(ex: all his holdings of Y, 200 tokens when escrow_info.expected_amount is only 100), couldn't Alice do the same frontrun technique, creating a new escrow account with the same number of tokens in pdas_temp_token_account, but this time setting a new escrow_info.expected_amount (increasing it to, say, 200), in order to take all of Bob's token Y?

Putting the amount bob expects to send out of takers_sending_token_account would fix this, no? Is the responsibility on Bob to make his own 'temp token Y account' that holds only what he reads in escrow_info.expected_amount or is this something that should really be baked into the program?

Again, thank you for the wonderful tutorial.

Setup script fails due to `id` balance 0

Currently the setup script is failing with the following log output:

Requesting SOL for Alice...
Requesting SOL for Bob...
Creating Mint X...
Transaction simulation failed: Attempt to debit an account but found no record of a prior credit.

Script runs successfully after airdropping sol to the id public key address, so think the fix is to add another requestAirdrop to that address before creating the mint.

socket hang up

 # npm run all

> [email protected] all
> npm run compile && node build/setup.js && node build/alice.js && node build/bob.js
> [email protected] compile
> tsc -p ./tsconfig.json

Requesting SOL for Alice...
Requesting SOL for Bob...
Requesting SOL for Client...
Creating Mint X...

/Users/binnz/cplus/solana-escrow/scripts/node_modules/node-fetch/lib/index.js:1461
                        reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                               ^
FetchError: request to http://localhost:8899/ failed, reason: socket hang up
    at ClientRequest.<anonymous> (/Users/binnz/cplus/solana-escrow/scripts/node_modules/node-fetch/lib/index.js:1461:11)
    at ClientRequest.emit (node:events:390:28)
    at Socket.socketOnEnd (node:_http_client:471:9)
    at Socket.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET'
}

after i run npm run setup-validator <EXECUTABLE_LOCATION>, the node is work well, port 8899 is open, this error occurs, how to fix this,thanks.

Account Signature

Hi :-)
first off, thanks for the wonderful work, your code and blog post helped out a bunch.
There's just one thing that is not entirely clear: in your code you don't check whether the signature is valid. Is it that you forgot about it, or is it because the Solana runtime checks it automatically?
Thanks a lot!

How to deploy and run it?

There's no instruction of how to deploy and run it, not locally, not on a real server.

How to make UI interract with it? It's not described anywhere.

Connection refused when attempting to connect to test validator.

Getting the following error when I run npm run setup-alice:

Screen Shot 2022-03-24 at 12 55 34 AM

I think it's trying to connect to the test validator, but for some reason the connectionis being refused. Any ideas on a fix?

I followed the instructions in the README, and ran this command after running npm run setup-validator <EXECUTABLE_LOCATION> with the executable location.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.