Skip to content

Commit

Permalink
feat(iro,amm): adding closing price event attribute for trades (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Oct 30, 2024
1 parent 632c277 commit 084f756
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 73 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ replace (
github.com/evmos/ethermint => github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20241013112411-5ef491708a2d
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/osmosis-labs/osmosis/osmomath => github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43
github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43
github.com/osmosis-labs/osmosis/v15 => github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241030075435-24ccb7025a59

// broken goleveldb
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,8 @@ github.com/dymensionxyz/gerr-cosmos v1.1.0 h1:IW/P7HCB/iP9kgk3VXaWUoMoyx3vD76YO6
github.com/dymensionxyz/gerr-cosmos v1.1.0/go.mod h1:n+0olxPogzWqFKba45mCpvrHLGmeS8W9UZjggHnWk6c=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43 h1:EskhZ6ILN3vwJ6l8gPWPZ49RFSB52WghT5v+pmzrNCI=
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43/go.mod h1:SdGCL9CZb14twRAJUSzb7bRE0OoopRpF2Hnd1UhJpFU=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43 h1:ugbpHwwlckB4W/aNXUTEsxaakPFgXi+LAsCtvfJ200Q=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43/go.mod h1:2rsnXAdjYfXtyEw0mNwAdOiAccALYjAPvINGUf9Qg7Y=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241030075435-24ccb7025a59 h1:xuo5OCex6XT3HmL8O9l/+jsbT0D+Ib0LzTXQbNrDOOQ=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20241030075435-24ccb7025a59/go.mod h1:2rsnXAdjYfXtyEw0mNwAdOiAccALYjAPvINGUf9Qg7Y=
github.com/dymensionxyz/sdk-utils v0.2.10 h1:dvUVzIpsdWGr5Ex+ltl/x1Abi+7sliwsGM1xAx/0p0k=
github.com/dymensionxyz/sdk-utils v0.2.10/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
Expand Down
10 changes: 10 additions & 0 deletions proto/dymensionxyz/dymension/iro/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ message EventBuy {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

string closing_price = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message EventSell {
Expand All @@ -56,6 +61,11 @@ message EventSell {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

string closing_price = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message EventClaim {
Expand Down
39 changes: 21 additions & 18 deletions x/iro/keeper/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ func (k Keeper) Buy(ctx sdk.Context, planId string, buyer sdk.AccAddress, amount

// Emit event
err = uevent.EmitTypedEvent(ctx, &types.EventBuy{
Buyer: buyer.String(),
PlanId: planId,
RollappId: plan.RollappId,
Amount: amountTokensToBuy,
Cost: costAmt,
TakerFee: takerFeeAmt,
Buyer: buyer.String(),
PlanId: planId,
RollappId: plan.RollappId,
Amount: amountTokensToBuy,
Cost: costAmt,
TakerFee: takerFeeAmt,
ClosingPrice: plan.SpotPrice(),
})
if err != nil {
return err
Expand Down Expand Up @@ -179,12 +180,13 @@ func (k Keeper) BuyExactSpend(ctx sdk.Context, planId string, buyer sdk.AccAddre

// Emit event
err = uevent.EmitTypedEvent(ctx, &types.EventBuy{
Buyer: buyer.String(),
PlanId: planId,
RollappId: plan.RollappId,
Amount: tokensOutAmt,
Cost: toSpendMinusTakerFeeAmt,
TakerFee: takerFeeAmt,
Buyer: buyer.String(),
PlanId: planId,
RollappId: plan.RollappId,
Amount: tokensOutAmt,
Cost: toSpendMinusTakerFeeAmt,
TakerFee: takerFeeAmt,
ClosingPrice: plan.SpotPrice(),
})
if err != nil {
return err
Expand Down Expand Up @@ -238,12 +240,13 @@ func (k Keeper) Sell(ctx sdk.Context, planId string, seller sdk.AccAddress, amou

// Emit event
err = uevent.EmitTypedEvent(ctx, &types.EventSell{
Seller: seller.String(),
PlanId: planId,
RollappId: plan.RollappId,
Amount: amountTokensToSell,
Revenue: costAmt,
TakerFee: takerFeeAmt,
Seller: seller.String(),
PlanId: planId,
RollappId: plan.RollappId,
Amount: amountTokensToSell,
Revenue: costAmt,
TakerFee: takerFeeAmt,
ClosingPrice: plan.SpotPrice(),
})
if err != nil {
return err
Expand Down
197 changes: 146 additions & 51 deletions x/iro/types/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion x/rollapp/types/state_info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 084f756

Please sign in to comment.