Skip to content

Commit

Permalink
fix: benfen max transaction (#6381)
Browse files Browse the repository at this point in the history
Co-authored-by: Leon <[email protected]>
  • Loading branch information
wabicai and originalix authored Dec 20, 2024
1 parent 80cc134 commit efc8a9c
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions packages/kit-bg/src/vaults/impls/bfc/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export default class Vault extends VaultBase {
const client = await this.getClient();
const { unsignedTx, nativeAmountInfo, feeInfo } = params;
const encodedTx = unsignedTx.encodedTx as IEncodedTxSui;
let newTx: TransactionBlock;

// max send
if (nativeAmountInfo?.maxSendAmount) {
Expand All @@ -329,36 +330,29 @@ export default class Vault extends VaultBase {

const transactionType = transactionUtils.analyzeTransactionType(oldTx);
if (transactionType !== EBfcTransactionType.TokenTransfer) {
return Promise.resolve(unsignedTx);
return unsignedTx;
}

if (!unsignedTx.transfersInfo?.[0]?.to) {
throw new OneKeyInternalError('Invalid transfer object');
}

// max send logic
const newTx = await transactionUtils.createTokenTransaction({
newTx = await transactionUtils.createTokenTransaction({
client,
sender: oldTx.blockData.sender ?? (await this.getAccountAddress()),
recipient: unsignedTx.transfersInfo[0].to,
amount: nativeAmountInfo.maxSendAmount,
coinType: BFC_TYPE_ARG,
maxSendNativeToken: true,
});
const newEncodedTx = {
...encodedTx,
rawTx: newTx.serialize(),
};
return {
...unsignedTx,
encodedTx: newEncodedTx,
};
} else {
newTx = TransactionBlock.from(encodedTx.rawTx);
}

// sui and benfen use the same model
// Apply fee settings for both normal and max send transactions
if (feeInfo?.feeBudget) {
const network = await this.getNetwork();
const newTx = TransactionBlock.from(encodedTx.rawTx);
newTx.setGasPrice(
Number(
new BigNumber(feeInfo.feeBudget.gasPrice)
Expand All @@ -367,20 +361,17 @@ export default class Vault extends VaultBase {
),
);

// Convert gasLimit to integer by ceiling the value
const gasBudget = new BigNumber(feeInfo.feeBudget.budget).toNumber();
newTx.setGasBudget(gasBudget);
const newEncodedTx = {
...encodedTx,
rawTx: newTx.serialize(),
};
return {
...unsignedTx,
encodedTx: newEncodedTx,
};
}

return Promise.resolve(unsignedTx);
return {
...unsignedTx,
encodedTx: {
...encodedTx,
rawTx: newTx.serialize(),
},
};
}

override async broadcastTransaction(
Expand Down

0 comments on commit efc8a9c

Please sign in to comment.