Skip to content

Commit

Permalink
osmosis liquidity support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed May 6, 2024
1 parent f3c4b7f commit 5578430
Show file tree
Hide file tree
Showing 98 changed files with 4,018 additions and 52 deletions.
38 changes: 20 additions & 18 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
// final provider = TendermintProvider(
// TendermintHTTPProvider(url: "https://rpc.testnet.osmosis.zone/"));

// final message = MsgSend(
// fromAddress: publickey.toAddresss(hrp: CosmosAddrConst.osmosis),
// toAddress:
// CosmosBaseAddress("osmo1wqzpmju4gl0kcajhjls6ufrqecaedxm9udt80k"),
// amount: [
// Coin(
// denom: "factory/osmo1htg7dmhelazdsmuwm9ngtg0tpe82006ugka49q/MRT",
// amount: BigInt.from(100))
// ]);
// final message = OsmosisValidatorPreferenceMsgDelegateToValidatorSet(
// delegator: publickey.toAddresss(hrp: CosmosAddrConst.osmosis).address,
// coin: Coin(denom: "uosmo", amount: BigInt.from(10000000)));
// // print(
// // "address ${publickey.toAddresss(hrp: CosmosAddrConst.osmosis).address}");

// final all = await provider.request(TendermintRequestAbciQuery(
// request: const OsmosisSuperfluidAllIntermediaryAccountsRequest()));

// /// OsmosisGammQueryPoolsRequest
// print("balances $all");
// return;

// /// Querying account info from the blockchain
// final accountInfo = await provider.request(TendermintRequestAbciQuery(
// request: QueryAccountInfoRequest(
Expand All @@ -50,7 +51,8 @@
// request: QueryAllBalancesRequest(
// address: publickey.toAddresss(hrp: CosmosAddrConst.osmosis))));

// // print("balances $accountBalances");
// /// OsmosisGammQueryPoolsRequest
// print("balances $accountBalances");
// // return;

// /// Creating authentication info for transaction
Expand Down Expand Up @@ -85,15 +87,15 @@
// authInfoBytes: authInfo.toBuffer(),
// signatures: [sign]);

// // final txForSimulate =
// // Tx(body: txbody, authInfo: authInfo, signatures: [sign]);
// final txForSimulate =
// Tx(body: txbody, authInfo: authInfo, signatures: [sign]);

// // final simulateRequest = await provider.request(TendermintRequestAbciQuery(
// // request: SimulateRequest(txForSimulate.toBuffer())));
// // print("simulate $simulateRequest");
// final resp = await provider.request(TendermintRequestBroadcastTxCommit(
// BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
// print("resp $resp");
// final simulateRequest = await provider.request(TendermintRequestAbciQuery(
// request: SimulateRequest(txForSimulate.toBuffer())));
// print("simulate $simulateRequest");
// // final resp = await provider.request(TendermintRequestBroadcastTxCommit(
// // BytesUtils.toHexString(txRaw.toBuffer(), prefix: "0x")));
// // print("resp $resp");

// /// https://celatone.osmosis.zone/osmo-test-5/txs/7C66B231A02BE52E2E42127A6BAAC35C24AEC35519E3FED4545982BEE781EBA8
// }
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:blockchain_utils/numbers/numbers.dart';
import 'package:cosmos_sdk/src/models/sdk_v1beta1/cosmos_base_query_v1beta1/messages/page_request.dart';
import 'package:cosmos_sdk/src/models/ibc/ibc_core_channel_v1/query/query_packet_acknowledgements_response.dart';

Expand Down Expand Up @@ -33,7 +34,11 @@ class QueryPacketAcknowledgementsRequest extends CosmosMessage
pagination: decode
.getResult(3)
?.to<PageRequest, List<int>>((e) => PageRequest.deserialize(e)),
packetCommitmentSequences: decode.getFields<BigInt>(4));
packetCommitmentSequences: decode
.getResult<ProtocolBufferDecoderResult?>(4)
?.to<List<BigInt>, List<int>>(
(e) => e.map((e) => BigintUtils.parse(e)).toList()) ??
<BigInt>[]);
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:blockchain_utils/numbers/numbers.dart';
import 'package:cosmos_sdk/src/models/ibc/ibc_core_channel_v1/query/query_unreceived_acks_response.dart';

import 'package:cosmos_sdk/src/models/ibc/types/types.dart';
Expand All @@ -23,7 +24,11 @@ class QueryUnreceivedAcksRequest extends CosmosMessage
return QueryUnreceivedAcksRequest(
portId: decode.getField(1),
channelId: decode.getField(2),
packetAckSequences: decode.getFields<BigInt>(3));
packetAckSequences: decode
.getResult<ProtocolBufferDecoderResult?>(3)
?.to<List<BigInt>, List<int>>(
(e) => e.map((e) => BigintUtils.parse(e)).toList()) ??
<BigInt>[]);
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:blockchain_utils/numbers/numbers.dart';
import 'package:cosmos_sdk/src/models/ibc/ibc_core_client_v1/messages/height.dart';
import 'package:cosmos_sdk/src/models/ibc/types/types.dart';
import 'package:cosmos_sdk/src/protobuf/protobuf.dart';
Expand All @@ -15,7 +16,11 @@ class QueryUnreceivedAcksResponse extends CosmosMessage {
factory QueryUnreceivedAcksResponse.deserialize(List<int> bytes) {
final decode = CosmosProtocolBuffer.decode(bytes);
return QueryUnreceivedAcksResponse(
sequences: decode.getFields<BigInt>(1),
sequences: decode
.getResult<ProtocolBufferDecoderResult?>(1)
?.to<List<BigInt>, List<int>>(
(e) => e.map((e) => BigintUtils.parse(e)).toList()) ??
<BigInt>[],
height: IbcClientHeight.deserialize(decode.getField(2)));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:blockchain_utils/numbers/numbers.dart';
import 'package:cosmos_sdk/src/models/ibc/ibc_core_channel_v1/query/query_unreceived_packets_response.dart';

import 'package:cosmos_sdk/src/models/ibc/types/types.dart';
Expand All @@ -23,7 +24,11 @@ class QueryUnreceivedPacketsRequest extends CosmosMessage
return QueryUnreceivedPacketsRequest(
portId: decode.getField(1),
channelId: decode.getField(2),
packetCommitmentSequences: decode.getFields<BigInt>(3));
packetCommitmentSequences: decode
.getResult<ProtocolBufferDecoderResult?>(3)
?.to<List<BigInt>, List<int>>(
(e) => e.map((e) => BigintUtils.parse(e)).toList()) ??
<BigInt>[]);
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:blockchain_utils/numbers/numbers.dart';
import 'package:cosmos_sdk/src/models/ibc/ibc_core_client_v1/messages/height.dart';
import 'package:cosmos_sdk/src/models/ibc/types/types.dart';
import 'package:cosmos_sdk/src/protobuf/protobuf.dart';
Expand All @@ -16,7 +17,11 @@ class QueryUnreceivedPacketsResponse extends CosmosMessage {
factory QueryUnreceivedPacketsResponse.deserialize(List<int> bytes) {
final decode = CosmosProtocolBuffer.decode(bytes);
return QueryUnreceivedPacketsResponse(
sequences: decode.getFields<BigInt>(1),
sequences: decode
.getResult<ProtocolBufferDecoderResult?>(1)
?.to<List<BigInt>, List<int>>(
(e) => e.map((e) => BigintUtils.parse(e)).toList()) ??
<BigInt>[],
height: IbcClientHeight.deserialize(decode.getField(2)));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/networks/osmosis/omosis.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'omosis_epochs_v1beta1/omosis_epochs_v1beta1.dart';
export 'osmosis_epochs_v1beta1/omosis_epochs_v1beta1.dart';
export 'osmosis_gamm_pool_models_balancer_v1beta1/osmosis_gamm_pool_models_balancer_v1beta1.dart';
export 'osmosis_gamm_poolmodels_stableswap_v1beta1/osmosis_gamm_poolmodels_stableswap_v1beta1.dart';
export 'osmosis_gamm_v1beta1/osmosis_gamm_v1beta1.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:cosmos_sdk/src/models/networks/osmosis/osmosis_accum_v1beta1/types/types.dart';
import 'package:cosmos_sdk/src/models/sdk_v1beta1/cosmos_base_v1beta1/messages/dec_coin.dart';
import 'package:cosmos_sdk/src/protobuf/protobuf.dart';
import 'package:cosmos_sdk/src/utils/quick_extensions.dart';

/// AccumulatorContent is the state-entry for the global accumulator.
/// It contains the name of the global accumulator and the total value of shares belonging to it from all positions.
class OsmosisAccumAccumulatorContent extends CosmosMessage {
final List<DecCoin> accumValue;
final String totalShares;
OsmosisAccumAccumulatorContent(
{required List<DecCoin> accumValue, required this.totalShares})
: accumValue = accumValue.mutable;
factory OsmosisAccumAccumulatorContent.deserialize(List<int> bytes) {
final decode = CosmosProtocolBuffer.decode(bytes);
return OsmosisAccumAccumulatorContent(
accumValue:
decode.getFields(1).map((e) => DecCoin.deserialize(e)).toList(),
totalShares: decode.getField(2),
);
}
factory OsmosisAccumAccumulatorContent.fromRpc(Map<String, dynamic> json) {
return OsmosisAccumAccumulatorContent(
accumValue: (json["accum_value"] as List?)
?.map((e) => DecCoin.fromRpc(e))
.toList() ??
<DecCoin>[],
totalShares: json["total_shares"],
);
}

@override
List<int> get fieldIds => [1, 2];

@override
Map<String, dynamic> toJson() {
return {
"accum_value": accumValue.map((e) => e.toJson()).toList(),
"total_shares": totalShares,
};
}

@override
String get typeUrl => OsmosisAccumV1beta1Types.accumulatorContent.typeUrl;

@override
List get values => [accumValue, totalShares];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:cosmos_sdk/src/models/networks/osmosis/osmosis_accum_v1beta1/types/types.dart';
import 'package:cosmos_sdk/src/protobuf/protobuf.dart';

class OsmosisAccumOptions extends CosmosMessage {
OsmosisAccumOptions();
factory OsmosisAccumOptions.deserialize(List<int> bytes) {
return OsmosisAccumOptions();
}

@override
List<int> get fieldIds => [];

@override
Map<String, dynamic> toJson() {
return {};
}

@override
String get typeUrl => OsmosisAccumV1beta1Types.options.typeUrl;

@override
List get values => [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:cosmos_sdk/src/models/networks/osmosis/osmosis_accum_v1beta1/types/types.dart';
import 'package:cosmos_sdk/src/models/sdk_v1beta1/cosmos_base_v1beta1/messages/dec_coin.dart';
import 'package:cosmos_sdk/src/protobuf/protobuf.dart';
import 'package:cosmos_sdk/src/utils/quick_extensions.dart';

/// Record corresponds to an individual position value belonging to the global accumulator.
class OsmosisAccumRecord extends CosmosMessage {
/// num_shares is the number of shares belonging to the position associated
/// with this record.
final String numShares;

/// accum_value_per_share is the subset of coins per shar of the global
/// accumulator value that allows to infer how much a position is entitled to
/// per share that it owns.
///
/// In the default case with no intervals, this value equals to the global
/// accumulator value at the time of the position creation, the last update or
/// reward claim.
///
/// In the interval case such as concentrated liquidity, this value equals to
/// the global growth of rewards inside the interval during one of: the time of
/// the position creation, the last update or reward claim. Note, that
// immediately prior to claiming or updating rewards, this value must be
/// updated to "the growth inside at the time of last update + the growth
/// outside at the time of the current block". This is so that the claiming
/// logic can subtract this updated value from the global accumulator value to
/// get the growth inside the interval from the time of last update up until
/// the current block time.
final List<DecCoin> accumValuePerShare;

/// unclaimed_rewards_total is the total amount of unclaimed rewards that the
/// position is entitled to. This value is updated whenever shares are added or
/// removed from an existing position. We also expose API for manually updating
/// this value for some custom use cases such as merging pre-existing positions
/// into a single one.s
final List<DecCoin> unclaimedRewardsTotal;
OsmosisAccumRecord({
required this.numShares,
required List<DecCoin> accumValuePerShare,
required List<DecCoin> unclaimedRewardsTotal,
}) : accumValuePerShare = accumValuePerShare.mutable,
unclaimedRewardsTotal = unclaimedRewardsTotal.mutable;
factory OsmosisAccumRecord.deserialize(List<int> bytes) {
final decode = CosmosProtocolBuffer.decode(bytes);
return OsmosisAccumRecord(
numShares: decode.getField(1),
accumValuePerShare:
decode.getFields(2).map((e) => DecCoin.deserialize(e)).toList(),
unclaimedRewardsTotal:
decode.getFields(3).map((e) => DecCoin.deserialize(e)).toList(),
);
}
factory OsmosisAccumRecord.fromRpc(Map<String, dynamic> json) {
return OsmosisAccumRecord(
numShares: json["num_shares"],
accumValuePerShare: (json["accum_value_per_share"] as List?)
?.map((e) => DecCoin.deserialize(e))
.toList() ??
<DecCoin>[],
unclaimedRewardsTotal: (json["unclaimed_rewards_total"] as List?)
?.map((e) => DecCoin.deserialize(e))
.toList() ??
<DecCoin>[]);
}

@override
List<int> get fieldIds => [1, 2, 3];

@override
Map<String, dynamic> toJson() {
return {
"num_shares": numShares,
"accum_value_per_share":
accumValuePerShare.map((e) => e.toJson()).toList(),
"unclaimed_rewards_total":
unclaimedRewardsTotal.map((e) => e.toJson()).toList()
};
}

@override
String get typeUrl => OsmosisAccumV1beta1Types.record.typeUrl;

@override
List get values => [numShares, accumValuePerShare, unclaimedRewardsTotal];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'messages/accumulator_content.dart';
export 'messages/options.dart';
export 'messages/record_msg.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:cosmos_sdk/src/models/core/type_url/type_url.dart';

class OsmosisAccumV1beta1Types extends TypeUrl {
@override
final String typeUrl;
@override
final String? rpc = null;
const OsmosisAccumV1beta1Types._(this.typeUrl);
static const OsmosisAccumV1beta1Types accumulatorContent =
OsmosisAccumV1beta1Types._("/osmosis.accum.v1beta1.AccumulatorContent");
static const OsmosisAccumV1beta1Types options =
OsmosisAccumV1beta1Types._("/osmosis.accum.v1beta1.Options");
static const OsmosisAccumV1beta1Types record =
OsmosisAccumV1beta1Types._("/osmosis.accum.v1beta1.Record");
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:cosmos_sdk/src/models/networks/osmosis/osmosis_accum_v1beta1/osmosis_accum_v1beta1.dart';
import 'package:cosmos_sdk/src/models/networks/osmosis/osmosis_concentrated_liquidity_v1beta1/types/types.dart';
import 'package:cosmos_sdk/src/protobuf/protobuf.dart';

class OsmosisConcentratedLiquidityAccumObject extends CosmosMessage {
/// Accumulator's name (pulled from AccumulatorContent)
final String? name;
final OsmosisAccumAccumulatorContent? accumContent;
OsmosisConcentratedLiquidityAccumObject({this.name, this.accumContent});
factory OsmosisConcentratedLiquidityAccumObject.deserialize(List<int> bytes) {
final decode = CosmosProtocolBuffer.decode(bytes);
return OsmosisConcentratedLiquidityAccumObject(
name: decode.getField(1),
accumContent: decode
.getResult(2)
?.to<OsmosisAccumAccumulatorContent, List<int>>(
(e) => OsmosisAccumAccumulatorContent.deserialize(e)));
}
factory OsmosisConcentratedLiquidityAccumObject.fromRpc(
Map<String, dynamic> json) {
return OsmosisConcentratedLiquidityAccumObject(
name: json["name"],
accumContent: json["accum_content"] == null
? null
: OsmosisAccumAccumulatorContent.fromRpc(json["accum_content"]));
}

@override
List<int> get fieldIds => [1, 2];

@override
Map<String, dynamic> toJson() {
return {"name": name, "accum_content": accumContent?.toJson()};
}

@override
List get values => [name, accumContent];

@override
String get typeUrl =>
OsmosisConcentratedLiquidityV1beta1Types.accumObject.typeUrl;
}
Loading

0 comments on commit 5578430

Please sign in to comment.