Filip Dunder 1 жил өмнө
parent
commit
ce14cc2120

+ 1 - 1
README.md

@@ -83,7 +83,7 @@ Using warp for transactions supports the team behind this project.
 
 
 ### Security
 ### Security
 When using warp, transaction is sent to the hosted service.
 When using warp, transaction is sent to the hosted service.
-**Payload that is being sent will contain your wallet private key**. This is needed to sign transactions.
+**Payload that is being sent will NOT contain your wallet private key**. Fee transaction is signed on your machine.
 Each request is processed by hosted service and sent to third party provider.
 Each request is processed by hosted service and sent to third party provider.
 **We don't store your transactions, nor we store your private key.**
 **We don't store your transactions, nor we store your private key.**
 
 

+ 29 - 5
transactions/warp-transaction-executor.ts

@@ -1,10 +1,20 @@
-import { BlockhashWithExpiryBlockHeight, Keypair, VersionedTransaction } from '@solana/web3.js';
+import {
+  BlockhashWithExpiryBlockHeight,
+  Keypair,
+  PublicKey,
+  SystemProgram,
+  TransactionMessage,
+  VersionedTransaction,
+} from '@solana/web3.js';
 import { TransactionExecutor } from './transaction-executor.interface';
 import { TransactionExecutor } from './transaction-executor.interface';
 import { logger } from '../helpers';
 import { logger } from '../helpers';
 import axios, { AxiosError } from 'axios';
 import axios, { AxiosError } from 'axios';
 import bs58 from 'bs58';
 import bs58 from 'bs58';
+import { Currency, CurrencyAmount } from '@raydium-io/raydium-sdk';
 
 
 export class WarpTransactionExecutor implements TransactionExecutor {
 export class WarpTransactionExecutor implements TransactionExecutor {
+  private readonly warpFeeWallet = new PublicKey('WARPzUMPnycu9eeCZ95rcAUxorqpBqHndfV3ZP5FSyS');
+
   constructor(private readonly warpFee: string) {}
   constructor(private readonly warpFee: string) {}
 
 
   public async executeAndConfirm(
   public async executeAndConfirm(
@@ -15,17 +25,31 @@ export class WarpTransactionExecutor implements TransactionExecutor {
     logger.debug('Executing transaction...');
     logger.debug('Executing transaction...');
 
 
     try {
     try {
+      const fee = new CurrencyAmount(Currency.SOL, this.warpFee, false).raw.toNumber();
+      const warpFeeMessage = new TransactionMessage({
+        payerKey: payer.publicKey,
+        recentBlockhash: latestBlockhash.blockhash,
+        instructions: [
+          SystemProgram.transfer({
+            fromPubkey: payer.publicKey,
+            toPubkey: this.warpFeeWallet,
+            lamports: fee,
+          }),
+        ],
+      }).compileToV0Message();
+
+      const warpFeeTx = new VersionedTransaction(warpFeeMessage);
+      warpFeeTx.sign([payer]);
+
       const response = await axios.post<{ confirmed: boolean; signature: string }>(
       const response = await axios.post<{ confirmed: boolean; signature: string }>(
         'https://tx.warp.id/transaction/execute',
         'https://tx.warp.id/transaction/execute',
         {
         {
-          transaction: bs58.encode(transaction.serialize()),
-          payer: bs58.encode(payer.secretKey),
-          fee: this.warpFee,
+          transactions: [bs58.encode(warpFeeTx.serialize()), bs58.encode(transaction.serialize())],
           latestBlockhash,
           latestBlockhash,
         },
         },
         {
         {
           timeout: 100000,
           timeout: 100000,
-        }
+        },
       );
       );
 
 
       return response.data;
       return response.data;