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

fix(IRO): added IRO creation event. updated settle event. fixed trade events #1316

Merged
merged 5 commits into from
Oct 13, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ replace (
// for collections
cosmossdk.io/api => cosmossdk.io/api v0.3.1
// use dymension forks
github.com/evmos/ethermint => github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20240625101522-b1506ae83050
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA2EjTY=
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20240625101522-b1506ae83050 h1:1mtlo6bDOdBihHWbDpOaai0NMC/4xHCkCHGCqdLT8WM=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20240625101522-b1506ae83050/go.mod h1:aokD0im7cUMMtR/khzNsmcGtINtxCpBfcgRvJdmLymA=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20241013112411-5ef491708a2d h1:UiPbek/78Cr0hUKJmCCtVt0VkfGop5zV39tnF08I6Qk=
github.com/dymensionxyz/ethermint v0.22.0-dymension-v0.4.1.0.20241013112411-5ef491708a2d/go.mod h1:aokD0im7cUMMtR/khzNsmcGtINtxCpBfcgRvJdmLymA=
github.com/dymensionxyz/gerr-cosmos v1.1.0 h1:IW/P7HCB/iP9kgk3VXaWUoMoyx3vD76YO6p1fnubHVc=
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=
Expand Down
28 changes: 17 additions & 11 deletions proto/dymensionxyz/dymension/iro/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ message EventUpdateParams {
Params old_params = 3 [ (gogoproto.nullable) = false ];
}


message EventNewIROPlan {
string creator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string plan_id = 2;
Plan plan = 3;
string rollapp_id = 3;
}


message EventBuy {
string buyer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string plan_id = 2;
string rollapp_id = 3;
string amount = 4[
string amount = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string cost = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string cost = 5[
string taker_fee = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
Expand All @@ -40,13 +42,17 @@ message EventSell {
string seller = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string plan_id = 2;
string rollapp_id = 3;
string amount = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

string amount = 4[
string revenue = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

string revenue = 5[
string taker_fee = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
Expand All @@ -56,16 +62,16 @@ message EventClaim {
string claimer = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string plan_id = 2;
string rollapp_id = 3;
string amount = 4[
string amount = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}



message EventSettle {
string plan_id = 1;
string rollapp_id = 2;
//FIXME: Add more fields, probably liquidity related
string IBC_denom = 3;
uint64 pool_id = 4;
uint64 gauge_id = 5;
}
10 changes: 10 additions & 0 deletions x/iro/keeper/create_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func (k Keeper) CreatePlan(ctx sdk.Context, allocatedAmount math.Int, start, pre
// Set the plan in the store
k.SetPlan(ctx, plan)

// Emit event
err = ctx.EventManager().EmitTypedEvent(&types.EventNewIROPlan{
Creator: rollapp.Owner,
PlanId: fmt.Sprintf("%d", plan.Id),
RollappId: rollapp.RollappId,
})
if err != nil {
return "", err
}

return fmt.Sprintf("%d", plan.Id), nil
}

Expand Down
21 changes: 12 additions & 9 deletions x/iro/keeper/settle.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,18 @@ func (k Keeper) Settle(ctx sdk.Context, rollappId, rollappIBCDenom string) error
k.SetPlan(ctx, plan)

// uses the raised DYM and unsold tokens to bootstrap the rollapp's liquidity pool
err = k.bootstrapLiquidityPool(ctx, plan)
poolID, gaugeID, err := k.bootstrapLiquidityPool(ctx, plan)
if err != nil {
return errors.Join(types.ErrFailedBootstrapLiquidityPool, err)
}

// Emit event
err = ctx.EventManager().EmitTypedEvent(&types.EventSettle{
RollappId: rollappId,
PlanId: fmt.Sprintf("%d", plan.Id),
RollappId: rollappId,
IBCDenom: rollappIBCDenom,
PoolId: poolID,
GaugeId: gaugeID,
})
if err != nil {
return err
Expand All @@ -82,14 +85,14 @@ func (k Keeper) Settle(ctx sdk.Context, rollappId, rollappIBCDenom string) error
// - Determines the required pool liquidity amounts to fulfill the last price.
// - Creates a balancer pool with the determined tokens and DYM.
// - Uses leftover tokens as incentives to the pool LP token holders.
func (k Keeper) bootstrapLiquidityPool(ctx sdk.Context, plan types.Plan) error {
func (k Keeper) bootstrapLiquidityPool(ctx sdk.Context, plan types.Plan) (poolID, gaugeID uint64, err error) {
unallocatedTokens := plan.TotalAllocation.Amount.Sub(plan.SoldAmt) // assumed > 0, as we enforce it in the Buy function
raisedDYM := k.BK.GetBalance(ctx, plan.GetAddress(), appparams.BaseDenom) // assumed > 0, as we enforce it by IRO creation fee

// send the raised DYM to the iro module as it will be used as the pool creator
err := k.BK.SendCoinsFromAccountToModule(ctx, plan.GetAddress(), types.ModuleName, sdk.NewCoins(raisedDYM))
err = k.BK.SendCoinsFromAccountToModule(ctx, plan.GetAddress(), types.ModuleName, sdk.NewCoins(raisedDYM))
if err != nil {
return err
return 0, 0, err
}

// find the tokens needed to bootstrap the pool, to fulfill last price
Expand All @@ -114,7 +117,7 @@ func (k Keeper) bootstrapLiquidityPool(ctx sdk.Context, plan types.Plan) error {
// we call the pool manager directly, instead of the gamm keeper, to avoid the pool creation fee
poolId, err := k.pm.CreatePool(ctx, balancerPool)
if err != nil {
return err
return 0, 0, err
}

// Add incentives
Expand All @@ -128,12 +131,12 @@ func (k Keeper) bootstrapLiquidityPool(ctx sdk.Context, plan types.Plan) error {
Denom: poolDenom,
Duration: k.ik.GetLockableDurations(ctx)[0],
}
_, err = k.ik.CreateGauge(ctx, false, k.AK.GetModuleAddress(types.ModuleName), incentives, distrTo, ctx.BlockTime().Add(plan.IncentivePlanParams.StartTimeAfterSettlement), plan.IncentivePlanParams.NumEpochsPaidOver)
gaugeID, err = k.ik.CreateGauge(ctx, false, k.AK.GetModuleAddress(types.ModuleName), incentives, distrTo, ctx.BlockTime().Add(plan.IncentivePlanParams.StartTimeAfterSettlement), plan.IncentivePlanParams.NumEpochsPaidOver)
if err != nil {
return err
return 0, 0, err
}

return nil
return poolID, gaugeID, nil
}

// calcLiquidityPoolTokens determines the tokens and DYM to be used for bootstrapping the liquidity pool.
Expand Down
4 changes: 4 additions & 0 deletions x/iro/keeper/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (k Keeper) Buy(ctx sdk.Context, planId string, buyer sdk.AccAddress, amount
PlanId: planId,
RollappId: plan.RollappId,
Amount: amountTokensToBuy,
Cost: cost.Amount,
TakerFee: takerFee.Amount,
})
if err != nil {
return err
Expand Down Expand Up @@ -154,6 +156,8 @@ func (k Keeper) Sell(ctx sdk.Context, planId string, seller sdk.AccAddress, amou
PlanId: planId,
RollappId: plan.RollappId,
Amount: amountTokensToSell,
Revenue: cost.Amount,
TakerFee: takerFee.Amount,
})
if err != nil {
return err
Expand Down
Loading
Loading