Skip to content
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
3 changes: 3 additions & 0 deletions assets/logos/bnb_chain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions lib/abis/pancake_swap_infinity_cl_pool_manager.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[
{
"inputs": [
{
"internalType": "PoolId",
"name": "id",
"type": "bytes32"
}
],
"name": "getSlot0",
"outputs": [
{
"internalType": "uint160",
"name": "sqrtPriceX96",
"type": "uint160"
},
{
"internalType": "int24",
"name": "tick",
"type": "int24"
},
{
"internalType": "uint24",
"name": "protocolFee",
"type": "uint24"
},
{
"internalType": "uint24",
"name": "lpFee",
"type": "uint24"
}
],
"stateMutability": "view",
"type": "function"
}
]
24 changes: 12 additions & 12 deletions lib/app/create/deposit/deposit_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class _DepositPageState extends State<DepositPage>

final price = tickToPrice(
tick: _cubit.latestPoolTick!,
poolToken0Decimals: _cubit.selectedYield!.token0.decimals,
poolToken1Decimals: _cubit.selectedYield!.token1.decimals,
poolToken0Decimals: _cubit.selectedYield!.token0NetworkDecimals,
poolToken1Decimals: _cubit.selectedYield!.token1NetworkDecimals,
);

return areTokensReversed ? price.priceAsQuoteToken : price.priceAsBaseToken;
Expand Down Expand Up @@ -215,14 +215,14 @@ class _DepositPageState extends State<DepositPage>

final maxTickPrice = tickToPrice(
tick: V3V4PoolConstants.maxTick,
poolToken0Decimals: _cubit.selectedYield!.token0.decimals,
poolToken1Decimals: _cubit.selectedYield!.token1.decimals,
poolToken0Decimals: _cubit.selectedYield!.token0NetworkDecimals,
poolToken1Decimals: _cubit.selectedYield!.token1NetworkDecimals,
);

final minTickPrice = tickToPrice(
tick: V3V4PoolConstants.minTick,
poolToken0Decimals: _cubit.selectedYield!.token0.decimals,
poolToken1Decimals: _cubit.selectedYield!.token1.decimals,
poolToken0Decimals: _cubit.selectedYield!.token0NetworkDecimals,
poolToken1Decimals: _cubit.selectedYield!.token1NetworkDecimals,
);

double getMinPrice() {
Expand Down Expand Up @@ -756,8 +756,8 @@ class _DepositPageState extends State<DepositPage>
"1 ${baseToken.symbol} ≈ ${() {
final currentPrice = tickToPrice(
tick: poolTickSnapshot.data ?? BigInt.zero,
poolToken0Decimals: _cubit.selectedYield!.token0.decimals,
poolToken1Decimals: _cubit.selectedYield!.token1.decimals,
poolToken0Decimals: _cubit.selectedYield!.token0NetworkDecimals,
poolToken1Decimals: _cubit.selectedYield!.token1NetworkDecimals,
);

return areTokensReversed ? currentPrice.priceAsQuoteToken : currentPrice.priceAsBaseToken;
Expand Down Expand Up @@ -826,8 +826,8 @@ class _DepositPageState extends State<DepositPage>
});
},
initialPrice: minPrice,
poolToken0: _cubit.selectedYield!.token0,
poolToken1: _cubit.selectedYield!.token1,
poolToken0Decimals: _cubit.selectedYield!.token0NetworkDecimals,
poolToken1Decimals: _cubit.selectedYield!.token1NetworkDecimals,
isReversed: areTokensReversed,
displayBaseTokenSymbol: baseToken.symbol,
displayQuoteTokenSymbol: quoteToken.symbol,
Expand Down Expand Up @@ -873,8 +873,8 @@ class _DepositPageState extends State<DepositPage>
type: RangeSelectorType.maxPrice,
isInfinity: isMaxRangeInfinity,
initialPrice: maxPrice,
poolToken0: _cubit.selectedYield!.token0,
poolToken1: _cubit.selectedYield!.token1,
poolToken0Decimals: _cubit.selectedYield!.token0NetworkDecimals,
poolToken1Decimals: _cubit.selectedYield!.token1NetworkDecimals,
isReversed: areTokensReversed,
tickSpacing: _cubit.selectedYield!.tickSpacing,
rangeController: maxRangeController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ class _PreviewDepositModalState extends State<PreviewDepositModal> with V3PoolCo
double get quoteTokenAmount => isReversedLocal ? widget.token0DepositAmount : widget.token1DepositAmount;
PreviewDepositModalCubit get cubit => context.read<PreviewDepositModalCubit>();
BigInt get token0DepositAmount =>
widget.token0DepositAmount.parseTokenAmount(decimals: widget.currentYield.token0.decimals);
widget.token0DepositAmount.parseTokenAmount(decimals: widget.currentYield.token0NetworkDecimals);
BigInt get token1DepositAmount =>
widget.token1DepositAmount.parseTokenAmount(decimals: widget.currentYield.token1.decimals);
widget.token1DepositAmount.parseTokenAmount(decimals: widget.currentYield.token1NetworkDecimals);

double get currentPrice {
final currentTick = cubit.latestPoolTick;

final price = tickToPrice(
tick: currentTick,
poolToken0Decimals: widget.currentYield.token0.decimals,
poolToken1Decimals: widget.currentYield.token1.decimals,
poolToken0Decimals: widget.currentYield.token0NetworkDecimals,
poolToken1Decimals: widget.currentYield.token1NetworkDecimals,
);

return isReversedLocal ? price.priceAsQuoteToken : price.priceAsBaseToken;
Expand All @@ -142,16 +142,16 @@ class _PreviewDepositModalState extends State<PreviewDepositModal> with V3PoolCo

return priceToTick(
price: (widget.isReversed == !isReversedLocal) ? widget.maxPrice.price : widget.minPrice.price,
poolToken0Decimals: widget.currentYield.token0.decimals,
poolToken1Decimals: widget.currentYield.token1.decimals,
poolToken0Decimals: widget.currentYield.token0NetworkDecimals,
poolToken1Decimals: widget.currentYield.token1NetworkDecimals,
isReversed: widget.isReversed,
);
}

({double priceAsBaseToken, double priceAsQuoteToken}) price() => tickToPrice(
tick: tick(),
poolToken0Decimals: widget.currentYield.token0.decimals,
poolToken1Decimals: widget.currentYield.token1.decimals,
poolToken0Decimals: widget.currentYield.token0NetworkDecimals,
poolToken1Decimals: widget.currentYield.token1NetworkDecimals,
);

return isReversedLocal ? price().priceAsQuoteToken : price().priceAsBaseToken;
Expand All @@ -163,16 +163,16 @@ class _PreviewDepositModalState extends State<PreviewDepositModal> with V3PoolCo

return priceToTick(
price: (widget.isReversed == !isReversedLocal) ? widget.minPrice.price : widget.maxPrice.price,
poolToken0Decimals: widget.currentYield.token0.decimals,
poolToken1Decimals: widget.currentYield.token1.decimals,
poolToken0Decimals: widget.currentYield.token0NetworkDecimals,
poolToken1Decimals: widget.currentYield.token1NetworkDecimals,
isReversed: widget.isReversed,
);
}

({double priceAsBaseToken, double priceAsQuoteToken}) price() => tickToPrice(
tick: tick(),
poolToken0Decimals: widget.currentYield.token0.decimals,
poolToken1Decimals: widget.currentYield.token1.decimals,
poolToken0Decimals: widget.currentYield.token0NetworkDecimals,
poolToken1Decimals: widget.currentYield.token1NetworkDecimals,
);

return isReversedLocal ? price().priceAsQuoteToken : price().priceAsBaseToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ class PreviewDepositModalCubit extends Cubit<PreviewDepositModalState> with V3Po

return priceToTick(
price: isReversed ? maxPrice : minPrice,
poolToken0Decimals: _yield.token0.decimals,
poolToken1Decimals: _yield.token1.decimals,
poolToken0Decimals: _yield.token0NetworkDecimals,
poolToken1Decimals: _yield.token1NetworkDecimals,
isReversed: isReversed,
);
}
Expand All @@ -194,8 +194,8 @@ class PreviewDepositModalCubit extends Cubit<PreviewDepositModalState> with V3Po

return priceToTick(
price: isReversed ? minPrice : maxPrice,
poolToken0Decimals: _yield.token0.decimals,
poolToken1Decimals: _yield.token1.decimals,
poolToken0Decimals: _yield.token0NetworkDecimals,
poolToken1Decimals: _yield.token1NetworkDecimals,
isReversed: isReversed,
);
}
Expand Down Expand Up @@ -253,8 +253,8 @@ class PreviewDepositModalCubit extends Cubit<PreviewDepositModalState> with V3Po
emit(PreviewDepositModalState.depositSuccess(txId: tx.hash));
_zupAnalytics.logDeposit(
depositedYield: _yield,
amount0Formatted: amount0Desired.parseTokenAmount(decimals: _yield.token0.decimals),
amount1Formatted: amount1Desired.parseTokenAmount(decimals: _yield.token1.decimals),
amount0Formatted: amount0Desired.parseTokenAmount(decimals: _yield.token0NetworkDecimals),
amount1Formatted: amount1Desired.parseTokenAmount(decimals: _yield.token1NetworkDecimals),
walletAddress: recipient,
);
} catch (e) {
Expand Down
38 changes: 20 additions & 18 deletions lib/app/create/deposit/widgets/range_selector.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:zup_app/core/dtos/token_dto.dart';
import 'package:zup_app/core/extensions/num_extension.dart';
import 'package:zup_app/core/mixins/v3_pool_conversors_mixin.dart';
import 'package:zup_app/core/token_amount_input_formatter.dart';
Expand Down Expand Up @@ -55,8 +54,8 @@ class RangeController extends ChangeNotifier {
class RangeSelector extends StatefulWidget {
const RangeSelector({
super.key,
required this.poolToken0,
required this.poolToken1,
required this.poolToken0Decimals,
required this.poolToken1Decimals,
required this.displayBaseTokenSymbol,
required this.displayQuoteTokenSymbol,
required this.isReversed,
Expand All @@ -70,8 +69,8 @@ class RangeSelector extends StatefulWidget {
this.state = const RangeSelectorState(type: RangeSelectorStateType.regular),
});

final TokenDto poolToken0;
final TokenDto poolToken1;
final int poolToken0Decimals;
final int poolToken1Decimals;
final String displayBaseTokenSymbol;
final String displayQuoteTokenSymbol;
final bool isReversed;
Expand Down Expand Up @@ -116,8 +115,8 @@ class _RangeSelectorState extends State<RangeSelector> with V3PoolConversorsMixi
double getAdjustedPrice(double price) {
final adjustedPrice = priceToClosestValidPrice(
price: price,
poolToken0Decimals: widget.poolToken0.decimals,
poolToken1Decimals: widget.poolToken1.decimals,
poolToken0Decimals: widget.poolToken0Decimals,
poolToken1Decimals: widget.poolToken1Decimals,
tickSpacing: widget.tickSpacing,
isReversed: widget.isReversed,
);
Expand All @@ -131,22 +130,25 @@ class _RangeSelectorState extends State<RangeSelector> with V3PoolConversorsMixi
if (currentPrice == 0 && !increasing) return;

if ((currentPrice == 0 || widget.isInfinity) && increasing) {
final minimumPrice = tickToPrice(
tick: BigInt.from(widget.tickSpacing),
poolToken0Decimals: widget.poolToken0.decimals,
poolToken1Decimals: widget.poolToken1.decimals,
final minimumPrice = priceToClosestValidPrice(
price: 0.000000000000000001,
poolToken0Decimals: widget.poolToken0Decimals,
poolToken1Decimals: widget.poolToken1Decimals,
tickSpacing: widget.tickSpacing,
isReversed: widget.isReversed,
);

userTypedValue = minimumPrice.priceAsBaseToken.toString();
userTypedValue = minimumPrice.price.toString();

return adjustTypedAmountAndCallback();
}

BigInt nextTick() {
final BigInt currentTick = tickToClosestValidTick(
tick: priceToTick(
price: currentPrice,
poolToken0Decimals: widget.poolToken0.decimals,
poolToken1Decimals: widget.poolToken1.decimals,
poolToken0Decimals: widget.poolToken0Decimals,
poolToken1Decimals: widget.poolToken1Decimals,
isReversed: widget.isReversed,
),
tickSpacing: widget.tickSpacing,
Expand All @@ -163,8 +165,8 @@ class _RangeSelectorState extends State<RangeSelector> with V3PoolConversorsMixi
double nextPrice() {
final nextPrice = tickToPrice(
tick: nextTick(),
poolToken0Decimals: widget.poolToken0.decimals,
poolToken1Decimals: widget.poolToken1.decimals,
poolToken0Decimals: widget.poolToken0Decimals,
poolToken1Decimals: widget.poolToken1Decimals,
);

if (widget.isReversed) return nextPrice.priceAsQuoteToken;
Expand All @@ -179,8 +181,8 @@ class _RangeSelectorState extends State<RangeSelector> with V3PoolConversorsMixi
if (widget.initialPrice != null) {
final adjustedInitialPrice = priceToClosestValidPrice(
price: widget.initialPrice ?? 0,
poolToken0Decimals: widget.poolToken0.decimals,
poolToken1Decimals: widget.poolToken1.decimals,
poolToken0Decimals: widget.poolToken0Decimals,
poolToken1Decimals: widget.poolToken1Decimals,
tickSpacing: widget.tickSpacing,
isReversed: widget.isReversed,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class _ExchangesFilterDropdownButtonState extends State<ExchangesFilterDropdownB

num get allowedProtocolsCount => cubit!.protocols
.where(
(protocol) => !cache.blockedProtocolsIds.contains(protocol.id),
(protocol) => !cache.blockedProtocolsIds.contains(protocol.rawId),
)
.length;

Expand Down Expand Up @@ -122,10 +122,10 @@ class _ExchangesFilterDropdownButtonState extends State<ExchangesFilterDropdownB
items: protocols
.map(
(protocol) => ZupCheckboxItem(
id: protocol.id,
id: protocol.rawId,
title: protocol.name,
icon: zupCachedImage.build(protocol.logo, radius: 50),
isChecked: !cache.blockedProtocolsIds.contains(protocol.id),
isChecked: !cache.blockedProtocolsIds.contains(protocol.rawId),
isDisabled: false,
),
)
Expand Down
8 changes: 7 additions & 1 deletion lib/core/dtos/protocol_dto.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:zup_app/core/enums/protocol_id.dart';

part 'protocol_dto.freezed.dart';
part 'protocol_dto.g.dart';

String _readRawProtocolId(Map map, String key) => map['id'];

@freezed
class ProtocolDto with _$ProtocolDto {
const ProtocolDto._();

@JsonSerializable(explicitToJson: true)
const factory ProtocolDto({
@Default("") String id,
@Default("") @JsonKey(readValue: _readRawProtocolId) String rawId,
@Default(ProtocolId.unknown) @JsonKey(unknownEnumValue: ProtocolId.unknown) ProtocolId id,
@Default("") String name,
@Default("") String url,
@Default("") String logo,
Expand All @@ -18,6 +22,8 @@ class ProtocolDto with _$ProtocolDto {
factory ProtocolDto.fromJson(Map<String, dynamic> json) => _$ProtocolDtoFromJson(json);

factory ProtocolDto.fixture() => const ProtocolDto(
rawId: "1",
id: ProtocolId.unknown,
name: "Uniswap",
url: "https://app.uniswap.org/pool",
logo: "https://raw.githubusercontent.com/trustwallet/assets/master/dapps/app.uniswap.org.png",
Expand Down
9 changes: 8 additions & 1 deletion lib/core/dtos/token_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TokenDto with _$TokenDto {
@Default("") String name,
@Default("") String logoUrl,
@Default({}) Map<int, String?> addresses,
@Default(0) int decimals,
@Default({}) Map<int, int?> decimals,
}) = _TokenDto;

factory TokenDto.fromJson(Map<String, dynamic> json) => _$TokenDtoFromJson(json);
Expand All @@ -23,6 +23,13 @@ class TokenDto with _$TokenDto {
factory TokenDto.fixture() => TokenDto(
symbol: 'WETH',
name: 'Wrapped Ether',
decimals: Map.fromEntries(
AppNetworks.values.where((network) => !network.isAllNetworks).map(
(network) {
return MapEntry(network.chainId, 18);
},
),
),
addresses: Map.fromEntries(
AppNetworks.values.where((network) => !network.isAllNetworks).map(
(network) {
Expand Down
Loading