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 issues: OK-26297 OK-26296 OK-26295 OK-26252 #4294

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/components/src/locale/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "سعر",
"form__price_volatility": "تقلب الأسعار",
"form__price_volatility_desc": "تلقي إخطار تقلب أسعار الرموز الخاصة بك",
"form__prioritization_fee_sol": "رسوم الأولوية",
"form__priority_fee": "رسوم الأولوية",
"form__priority_fee_booster": "🚀 أولوية دفع الرسوم",
"form__priority_fee_gwei": "رسوم الأولوية (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PRICE",
"form__price_volatility": "মূল্য অবিশ্বাস",
"form__price_volatility_desc": "আপনার টোকেনগুলির জন্য মূল্যের অস্থিরতার বিজ্ঞপ্তি পান",
"form__prioritization_fee_sol": "অগ্রাধিকার ফি",
"form__priority_fee": "অগ্রাধিকার ফি",
"form__priority_fee_booster": "🚀 অগ্রাধিকার ফি বুস্টার",
"form__priority_fee_gwei": "অগ্রাধিকার ফি (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PREIS",
"form__price_volatility": "Preisvolatilität",
"form__price_volatility_desc": "Erhalten Sie Benachrichtigungen zur Preisvolatilität für Ihre Token",
"form__prioritization_fee_sol": "Gebühr für die Priorisierung",
"form__priority_fee": "Prioritätsgebühr",
"form__priority_fee_booster": "🚀 Priority Fee Booster",
"form__priority_fee_gwei": "Prioritätsgebühr (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PRICE",
"form__price_volatility": "Price Volatility",
"form__price_volatility_desc": "Receive price volatility notification for your tokens",
"form__prioritization_fee_sol": "Prioritization Fee",
"form__priority_fee": "Priority Fee",
"form__priority_fee_booster": "🚀 Priority Fee Booster",
"form__priority_fee_gwei": "Priority Fee (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PRECIO",
"form__price_volatility": "Volatilidad de los precios",
"form__price_volatility_desc": "Recibe notificaciones de la volatilidad de los precios para tus tokens",
"form__prioritization_fee_sol": "Tarifa de priorización",
"form__priority_fee": "Tarifa de prioridad",
"form__priority_fee_booster": "🚀 Refuerzo de tarifa prioritaria",
"form__priority_fee_gwei": "Tarifa de prioridad (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/fil.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PRICE",
"form__price_volatility": "Pagkasumpungin ng Presyo",
"form__price_volatility_desc": "Makatanggap ng abiso sa pagbabago ng presyo para sa iyong mga token",
"form__prioritization_fee_sol": "Bayarin sa Priyoridad",
"form__priority_fee": "Priority Fee",
"form__priority_fee_booster": "🚀 Priority Fee Booster",
"form__priority_fee_gwei": "Priority Fee (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "LE PRIX",
"form__price_volatility": "Volatilité des prix",
"form__price_volatility_desc": "Recevez une notification de volatilité des prix pour vos jetons",
"form__prioritization_fee_sol": "Frais de priorisation",
"form__priority_fee": "Frais de priorité",
"form__priority_fee_booster": "🚀 Booster de frais de priorité",
"form__priority_fee_gwei": "Frais de priorité (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/hi_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "कीमत",
"form__price_volatility": "कीमतो में अस्थिरता",
"form__price_volatility_desc": "अपने टोकन के लिए मूल्य अस्थिरता सूचना प्राप्त करें",
"form__prioritization_fee_sol": "प्राथमिकता शुल्क",
"form__priority_fee": "प्राथमिकता शुल्क",
"form__priority_fee_booster": "🚀 प्राथमिकता शुल्क बूस्टर",
"form__priority_fee_gwei": "प्राथमिकता शुल्क (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "HARGA",
"form__price_volatility": "Volatilitas Harga",
"form__price_volatility_desc": "Terima pemberitahuan volatilitas harga untuk token Anda",
"form__prioritization_fee_sol": "Biaya Prioritas",
"form__priority_fee": "Biaya Prioritas",
"form__priority_fee_booster": "🚀 Penguat Biaya Prioritas",
"form__priority_fee_gwei": "Biaya Prioritas (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PREZZO",
"form__price_volatility": "Volatilità del prezzo",
"form__price_volatility_desc": "Ricevi una notifica sulla volatilità dei prezzi per i tuoi token",
"form__prioritization_fee_sol": "Commissione di priorità",
"form__priority_fee": "Commissione prioritaria",
"form__priority_fee_booster": "🚀 Amplificatore tariffa prioritaria",
"form__priority_fee_gwei": "Commissione prioritaria (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "価格",
"form__price_volatility": "価格変動性",
"form__price_volatility_desc": "トークンの価格ボラティリティ通知を受け取る",
"form__prioritization_fee_sol": "優先料",
"form__priority_fee": "優先料金",
"form__priority_fee_booster": "🚀 優先料金ブースター",
"form__priority_fee_gwei": "優先料金 (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/ko_KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "가격",
"form__price_volatility": "가격 변동성",
"form__price_volatility_desc": "토큰에 대한 가격 변동성 알림 수신",
"form__prioritization_fee_sol": "우선 수수료",
"form__priority_fee": "우선 수수료",
"form__priority_fee_booster": "🚀 우선 수수료 부스터",
"form__priority_fee_gwei": "우선 수수료(Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/mn_MN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "ҮНЭ",
"form__price_volatility": "Үнийн хэлбэлзэл",
"form__price_volatility_desc": "Токенуудын үнийн хэлбэлзлийн мэдэгдлийг хүлээн авна уу",
"form__prioritization_fee_sol": "Тэргүүлэх хураамж",
"form__priority_fee": "Тэргүүлэх хураамж",
"form__priority_fee_booster": "🚀 Тэргүүлэх хураамжийн нэмэгдэл",
"form__priority_fee_gwei": "Тэргүүлэх хураамж (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PREÇO",
"form__price_volatility": "Volatilidade dos preços",
"form__price_volatility_desc": "Receba notificações de volatilidade de preços para seus tokens",
"form__prioritization_fee_sol": "Taxa de priorização",
"form__priority_fee": "Taxa prioritária",
"form__priority_fee_booster": "🚀 Reforço de taxa prioritária",
"form__priority_fee_gwei": "Taxa prioritária (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "PREÇO",
"form__price_volatility": "Volatilidade de preços",
"form__price_volatility_desc": "Receba notificações de volatilidade de preço para seus tokens.",
"form__prioritization_fee_sol": "Taxa de priorização",
"form__priority_fee": "Taxa de prioridade",
"form__priority_fee_booster": "Aumento da taxa de prioridade",
"form__priority_fee_gwei": "Taxa de prioridade (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "ЦЕНА",
"form__price_volatility": "Волатильность цен",
"form__price_volatility_desc": "Получайте уведомления о волатильности цен на ваши токены",
"form__prioritization_fee_sol": "Плата за определение приоритета",
"form__priority_fee": "Плата за приоритет",
"form__priority_fee_booster": "🚀 Усилитель приоритетного платежа",
"form__priority_fee_gwei": "Плата за приоритет (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/th_TH.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "ราคา",
"form__price_volatility": "ความผันผวนของราคา",
"form__price_volatility_desc": "รับการแจ้งเตือนความผันผวนของราคาสำหรับโทเค็นของคุณ",
"form__prioritization_fee_sol": "ค่าธรรมเนียมการจัดลำดับความสำคัญ",
"form__priority_fee": "ค่าธรรมเนียมการจัดลำดับความสำคัญ",
"form__priority_fee_booster": "🚀 ผู้สนับสนุนค่าธรรมเนียมลำดับความสำคัญ",
"form__priority_fee_gwei": "ค่าธรรมเนียมสิทธิพิเศษ (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/uk_UA.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "ЦІНА",
"form__price_volatility": "Волатильність цін",
"form__price_volatility_desc": "Отримуйте сповіщення про нестабільність цін на ваші токени",
"form__prioritization_fee_sol": "Комісія за пріоритетність",
"form__priority_fee": "Плата за пріоритет",
"form__priority_fee_booster": "🚀 Підвищення плати за пріоритет",
"form__priority_fee_gwei": "Плата за пріоритет (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "GIÁ BÁN",
"form__price_volatility": "Biến động giá",
"form__price_volatility_desc": "Nhận thông báo biến động giá cho các mã thông báo của bạn",
"form__prioritization_fee_sol": "Phí ưu tiên",
"form__priority_fee": "Phí ưu tiên",
"form__priority_fee_booster": "🚀 Tăng phí ưu tiên",
"form__priority_fee_gwei": "Phí ưu tiên (Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "价格",
"form__price_volatility": "价格波动",
"form__price_volatility_desc": "接收代币的价格波动通知",
"form__prioritization_fee_sol": "优先费用",
"form__priority_fee": "矿工小费",
"form__priority_fee_booster": "🚀 矿工费推进器",
"form__priority_fee_gwei": "矿工小费(Gwei)",
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/locale/zh_HK.json
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,7 @@
"form__price_uppercase": "價格",
"form__price_volatility": "價格波動",
"form__price_volatility_desc": "接收代幣價格波動通知",
"form__prioritization_fee_sol": "優先費用",
"form__priority_fee": "礦工小費",
"form__priority_fee_booster": "🚀 礦工費推進器",
"form__priority_fee_gwei": "礦工小費(Gwei)",
Expand Down
161 changes: 87 additions & 74 deletions packages/engine/src/vaults/impl/sol/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import {
ComputeBudgetInstruction,
ComputeBudgetProgram,
MessageAccountKeys,
PublicKey,
SYSVAR_INSTRUCTIONS_PUBKEY,
SystemInstruction,
Expand Down Expand Up @@ -434,7 +433,8 @@ export default class Vault extends VaultBase {
const publicKey = new PublicKey(address);
if (
PublicKey.isOnCurve(address) ||
PublicKey.isOnCurve(publicKey.encode())
PublicKey.isOnCurve(publicKey.encode()) ||
bs58.decode(address).length === 32
) {
return Promise.resolve(address);
}
Expand Down Expand Up @@ -487,12 +487,45 @@ export default class Vault extends VaultBase {
}

// Account related methods

override attachFeeInfoToEncodedTx(params: {
override async attachFeeInfoToEncodedTx(params: {
encodedTx: IEncodedTx;
feeInfoValue: IFeeInfoUnit;
}): Promise<IEncodedTx> {
return Promise.resolve(params.encodedTx);
const { encodedTx, feeInfoValue } = params;
const { computeUnitPrice } = feeInfoValue;

if (isNil(computeUnitPrice)) {
return Promise.resolve(encodedTx);
}

let isComputeUnitPriceExist = false;
const nativeTx: Transaction = await this.helper.parseToNativeTx(encodedTx);
const prioritizationFeeInstruction =
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Number(computeUnitPrice),
});

for (let i = 0; i < nativeTx.instructions.length; i += 1) {
const instruction = nativeTx.instructions[i];
if (
instruction.programId.toString() ===
ComputeBudgetProgram.programId.toString()
) {
const { microLamports } =
ComputeBudgetInstruction.decodeSetComputeUnitPrice(instruction);
if (!isNil(microLamports)) {
nativeTx.instructions[i] = prioritizationFeeInstruction;
isComputeUnitPriceExist = true;
break;
}
}
}

if (!isComputeUnitPriceExist) {
nativeTx.add(prioritizationFeeInstruction);
}

return bs58.encode(nativeTx.serialize({ requireAllSignatures: false }));
}

override async decodeTx(
Expand Down Expand Up @@ -1042,65 +1075,6 @@ export default class Vault extends VaultBase {

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

// add priority fees to DApp tx by default
try {
if (options.type === IEncodedTxUpdateType.priorityFees) {
const isVersionedTransaction = nativeTx instanceof VersionedTransaction;
let instructions: TransactionInstruction[] = [];
let unitPrice;
let transactionMessage;
if (isVersionedTransaction) {
transactionMessage = TransactionMessage.decompile(nativeTx.message);
instructions = transactionMessage.instructions;
} else {
instructions = nativeTx.instructions;
}

// try to find if the transaction has already set the compute unit price(priority fee)
try {
for (const instruction of instructions) {
unitPrice =
ComputeBudgetInstruction.decodeSetComputeUnitPrice(instruction);
}
} catch {
// pass
}

// if not set, add the compute unit price(priority fee) to the transaction
if (isNil(unitPrice)) {
const client = await this.getClient();
const accountAddress = await this.getAccountAddress();
const prioritizationFee = await client.getRecentMaxPrioritizationFees(
[accountAddress],
);

const addPriorityFee = ComputeBudgetProgram.setComputeUnitPrice({
microLamports: Math.max(MIN_PRIORITY_FEE, prioritizationFee),
});

if (isVersionedTransaction) {
transactionMessage?.instructions.push(addPriorityFee);
} else {
(nativeTx as Transaction).add(addPriorityFee);
}
}

if (isVersionedTransaction) {
return bs58.encode(
new VersionedTransaction(
(transactionMessage as TransactionMessage).compileToV0Message(),
).serialize(),
);
}

return bs58.encode(
(nativeTx as Transaction).serialize({ requireAllSignatures: false }),
);
}
} catch (e) {
return encodedTx;
}

const nativeTxForUpdateTransfer = nativeTx as Transaction;
const [instruction] = nativeTxForUpdateTransfer.instructions;
// max native token transfer update
Expand Down Expand Up @@ -1258,7 +1232,6 @@ export default class Vault extends VaultBase {
const nativeTx = (await this.helper.parseToNativeTx(
encodedTx,
)) as Transaction;
const client = await this.getClient();

return {
inputs: [],
Expand Down Expand Up @@ -1317,19 +1290,58 @@ export default class Vault extends VaultBase {
return client.getFeePricePerUnit();
}

override async fetchFeeInfo(encodedTx: IEncodedTxSol): Promise<IFeeInfo> {
override async fetchFeeInfo(
encodedTx: IEncodedTxSol,
_: boolean | undefined,
specifiedFeeRate: string,
): Promise<IFeeInfo> {
const client = await this.getClient();
const nativeTx = await this.helper.parseToNativeTx(encodedTx);
let nativeTx: INativeTxSol = await this.helper.parseToNativeTx(encodedTx);
const isVersionedTransaction = nativeTx instanceof VersionedTransaction;
let message = '';
if (isVersionedTransaction) {
message = Buffer.from(nativeTx.message.serialize()).toString('base64');
let instructions: TransactionInstruction[] = [];
let transactionMessage;
let computeUnitPrice = '0';
if (isNil(specifiedFeeRate)) {
try {
if (isVersionedTransaction) {
nativeTx = nativeTx as VersionedTransaction;
message = Buffer.from(nativeTx.message.serialize()).toString(
'base64',
);
transactionMessage = TransactionMessage.decompile(nativeTx.message);
instructions = transactionMessage.instructions;
} else {
nativeTx = nativeTx as Transaction;
message = nativeTx.compileMessage().serialize().toString('base64');
instructions = nativeTx.instructions;
}

for (const instruction of instructions) {
if (
instruction.programId.toString() ===
ComputeBudgetProgram.programId.toString()
) {
const { microLamports } =
ComputeBudgetInstruction.decodeSetComputeUnitPrice(instruction);
computeUnitPrice = microLamports.toString();
break;
}
}
} catch {
// pass
}
} else {
message = (nativeTx as Transaction)
.compileMessage()
.serialize()
.toString('base64');
const encodedTxWithFee = await this.attachFeeInfoToEncodedTx({
encodedTx,
feeInfoValue: { computeUnitPrice: specifiedFeeRate },
});
nativeTx = (await this.helper.parseToNativeTx(
encodedTxWithFee,
)) as Transaction;
message = nativeTx.compileMessage().serialize().toString('base64');
}

const [network, feePerSig] = await Promise.all([
this.getNetwork(),
client.getFeesForMessage(message),
Expand All @@ -1340,6 +1352,7 @@ export default class Vault extends VaultBase {
];

return {
isSolChain: true,
nativeSymbol: network.symbol,
nativeDecimals: network.decimals,
feeSymbol: network.feeSymbol,
Expand All @@ -1349,7 +1362,7 @@ export default class Vault extends VaultBase {
limit: (nativeTx as Transaction).signatures.length.toString(),
prices,
defaultPresetIndex: '0',

computeUnitPrice,
tx: null, // Must be null if network not support feeInTx
};
}
Expand Down
Loading
Loading