Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 fix: sol max native token transfer error OK-26434 #4327

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions packages/engine/src/vaults/impl/sol/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,39 +1165,48 @@ export default class Vault extends VaultBase {
return Promise.resolve(encodedTx);
}

const nativeTx = await this.helper.parseToNativeTx(encodedTx);
const nativeTx = (await this.helper.parseToNativeTx(
encodedTx,
)) as Transaction;

const nativeTxForUpdateTransfer = nativeTx as Transaction;
const [instruction] = nativeTxForUpdateTransfer.instructions;
// max native token transfer update
if (
options.type === 'transfer' &&
nativeTxForUpdateTransfer.instructions.length === 1 &&
instruction.programId.toString() === SystemProgram.programId.toString()
options.type === IEncodedTxUpdateType.transfer &&
nativeTx instanceof Transaction &&
nativeTx.instructions.length === 2
) {
const instructionType =
SystemInstruction.decodeInstructionType(instruction);
if (instructionType === 'Transfer') {
const { fromPubkey, toPubkey } =
SystemInstruction.decodeTransfer(instruction);
const nativeToken = await this.engine.getNativeTokenInfo(
this.networkId,
);
const { amount } = payload as IEncodedTxUpdatePayloadTransfer;
nativeTxForUpdateTransfer.instructions = [
SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: BigInt(
new BigNumber(amount).shiftedBy(nativeToken.decimals).toFixed(),
),
}),
];
return bs58.encode(
nativeTxForUpdateTransfer.serialize({ requireAllSignatures: false }),
);
for (let i = 0; i < nativeTx.instructions.length; i += 1) {
const instruction = nativeTx.instructions[i];
if (
instruction.programId.toString() ===
SystemProgram.programId.toString()
) {
const instructionType =
SystemInstruction.decodeInstructionType(instruction);
if (instructionType === 'Transfer') {
const { fromPubkey, toPubkey } =
SystemInstruction.decodeTransfer(instruction);
const nativeToken = await this.engine.getNativeTokenInfo(
this.networkId,
);
const { amount } = payload as IEncodedTxUpdatePayloadTransfer;
nativeTx.instructions[i] = SystemProgram.transfer({
fromPubkey,
toPubkey,
lamports: BigInt(
new BigNumber(amount).shiftedBy(nativeToken.decimals).toFixed(),
),
});
return bs58.encode(
nativeTx.serialize({
requireAllSignatures: false,
}),
);
}
}
}
}

return Promise.resolve(encodedTx);
}

Expand Down
Loading