Skip to content

Commit

Permalink
fix: can not remove LP on SpaceSwap OK-18748 (#2825)
Browse files Browse the repository at this point in the history
* fix: versioned tx error on hw

* fix: can't remove LP on space swap
  • Loading branch information
weatherstar authored Apr 10, 2023
1 parent ef3bbd0 commit 3990de9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
25 changes: 21 additions & 4 deletions packages/blockchain-libs/src/provider/chains/eth/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,27 @@ class Provider extends BaseProvider {
signer: Signer,
address?: string,
): Promise<string> => {
const messageHash = hashMessage(
message.type as MessageTypes,
message.message,
);
let finalMessage: any = message.message;

// Special temporary fix for attribute name error on SpaceSwap
// https://onekeyhq.atlassian.net/browse/OK-18748
try {
finalMessage = JSON.parse(message.message);
if (
finalMessage.message.value1 !== undefined &&
finalMessage.message.value === undefined
) {
finalMessage.message.value = finalMessage.message.value1;

finalMessage = JSON.stringify(finalMessage);
} else {
finalMessage = message.message;
}
} catch (e) {
finalMessage = message.message;
}

const messageHash = hashMessage(message.type as MessageTypes, finalMessage);
const [sig, recId] = await signer.sign(ethUtil.toBuffer(messageHash));
return ethUtil.addHexPrefix(
Buffer.concat([sig, Buffer.from([recId + 27])]).toString('hex'),
Expand Down
19 changes: 13 additions & 6 deletions packages/engine/src/vaults/impl/sol/KeyringHardware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint no-unused-vars: ["warn", { "argsIgnorePattern": "^_" }] */
/* eslint @typescript-eslint/no-unused-vars: ["warn", { "argsIgnorePattern": "^_" }] */

import { VersionedTransaction } from '@solana/web3.js';

import type { SignedTx, UnsignedTx } from '@onekeyhq/engine/src/types/provider';
import { convertDeviceError } from '@onekeyhq/shared/src/device/deviceErrorUtils';
import {
Expand All @@ -20,7 +22,8 @@ import type {
IPrepareHardwareAccountsParams,
ISignCredentialOptions,
} from '../../types';
import type { PublicKey, Transaction } from '@solana/web3.js';
import type { INativeTxSol } from './types';
import type { PublicKey } from '@solana/web3.js';

export class KeyringHardware extends KeyringHardwareBase {
override async signTransaction(
Expand All @@ -32,13 +35,17 @@ export class KeyringHardware extends KeyringHardwareBase {
const { connectId, deviceId } = await this.getHardwareInfo();
const passphraseState = await this.getWalletPassphraseState();
const { nativeTx: transaction, feePayer } = unsignedTx.payload as {
nativeTx: Transaction;
nativeTx: INativeTxSol;
feePayer: PublicKey;
};

const isVersionedTransaction = transaction instanceof VersionedTransaction;

const response = await HardwareSDK.solSignTransaction(connectId, deviceId, {
path: dbAccount.path,
rawTx: transaction.serializeMessage().toString('hex'),
rawTx: isVersionedTransaction
? Buffer.from(transaction.message.serialize()).toString('hex')
: transaction.serializeMessage().toString('hex'),
...passphraseState,
});

Expand All @@ -47,9 +54,9 @@ export class KeyringHardware extends KeyringHardwareBase {
transaction.addSignature(feePayer, Buffer.from(signature, 'hex'));
return {
txid: signature,
rawTx: transaction
.serialize({ requireAllSignatures: false })
.toString('base64'),
rawTx: Buffer.from(
transaction.serialize({ requireAllSignatures: false }),
).toString('base64'),
};
}

Expand Down

0 comments on commit 3990de9

Please sign in to comment.