File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed
Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff line change 11import {
2+ calculateRatio ,
23 direction2Symbol ,
34 reservedCKB ,
45 symbol2Direction ,
56 toText ,
67} from "./utils.ts" ;
78import { CKB , max , min , type I8Header } from "@ickb/lumos-utils" ;
8- import { ckb2Ickb , ickb2Ckb } from "@ickb/v1-core" ;
99import type { JSX } from "react" ;
1010
1111export default function Form ( {
@@ -132,10 +132,12 @@ function approxConversion(
132132 amount : bigint ,
133133 tipHeader : I8Header ,
134134) : string {
135- let convertedAmount = isCkb2Udt
136- ? ckb2Ickb ( amount , tipHeader )
137- : ickb2Ckb ( amount , tipHeader ) ;
138135 //Worst case scenario is a 0.1% fee for bot
139- convertedAmount -= convertedAmount / 1000n ;
136+ const { ckbMultiplier, udtMultiplier } = calculateRatio ( isCkb2Udt , tipHeader ) ;
137+
138+ const convertedAmount = isCkb2Udt
139+ ? ( amount * ckbMultiplier ) / udtMultiplier
140+ : ( amount * udtMultiplier ) / ckbMultiplier ;
141+
140142 return toText ( convertedAmount ) ;
141143}
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import {
1414 addWithdrawalRequestGroups ,
1515 ickb2Ckb ,
1616 ickbDeposit ,
17- ickbExchangeRatio ,
1817 ickbRequestWithdrawalFrom ,
1918 orderMelt ,
2019 orderMint ,
@@ -23,6 +22,7 @@ import {
2322 type OrderRatio ,
2423} from "@ickb/v1-core" ;
2524import {
25+ calculateRatio ,
2626 maxEpoch ,
2727 orderMaturityEstimate ,
2828 txInfoPadding ,
@@ -133,14 +133,7 @@ export function convert(
133133 }
134134 Object . freeze ( ickbPool ) ;
135135
136- const { ckbMultiplier, udtMultiplier } = ickbExchangeRatio ( tipHeader ) ;
137- const ratio : OrderRatio = {
138- ckbMultiplier,
139- // Pay 0.1% fee to bot
140- udtMultiplier :
141- udtMultiplier + ( isCkb2Udt ? 1n : - 1n ) * ( udtMultiplier / 1000n ) ,
142- } ;
143-
136+ const ratio = calculateRatio ( isCkb2Udt , tipHeader ) ;
144137 const depositAmount = ckbSoftCapPerDeposit ( tipHeader ) ;
145138 const N = isCkb2Udt ? Number ( amount / depositAmount ) : ickbPool . length ;
146139 const txCache = Array < TxInfo | undefined > ( N ) ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 type I8Script ,
1414} from "@ickb/lumos-utils" ;
1515import { parseEpoch , type EpochSinceValue } from "@ckb-lumos/base/lib/since" ;
16+ import { ickbExchangeRatio , type OrderRatio } from "@ickb/v1-core" ;
1617
1718export interface RootConfig extends ChainConfig {
1819 queryClient : QueryClient ;
@@ -132,3 +133,17 @@ export const txInfoPadding: TxInfo = Object.freeze({
132133
133134// reservedCKB are reserved for state rent in conversions
134135export const reservedCKB = 1000n * CKB ;
136+
137+ // Fix up ratio to pay 0.1% fee to bot
138+ export function calculateRatio (
139+ isCkb2Udt : boolean ,
140+ tipHeader : I8Header ,
141+ ) : OrderRatio {
142+ const { ckbMultiplier, udtMultiplier } = ickbExchangeRatio ( tipHeader ) ;
143+ return {
144+ ckbMultiplier,
145+ // Pay 0.1% fee to bot
146+ udtMultiplier :
147+ udtMultiplier + ( isCkb2Udt ? 1n : - 1n ) * ( udtMultiplier / 1000n ) ,
148+ } ;
149+ }
You can’t perform that action at this time.
0 commit comments