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

Osmosis v12 upgrade - frontend changes #860

Merged
merged 5 commits into from
Sep 30, 2022
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
46 changes: 25 additions & 21 deletions packages/pools/src/weighted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import * as WeightedPoolMath from "@osmosis-labs/math";
/** Raw query response representation of pool. */
export interface WeightedPoolRaw {
id: string;
poolParams: {
pool_params: {
lock: boolean;
// Dec
swapFee: string;
swap_fee: string;
// Dec
exitFee: string;
smoothWeightChangeParams: {
exit_fee: string;
smooth_weight_change_params: {
// Timestamp
start_time: string;
// Seconds with s suffix. Ex) 3600s
duration: string;
initialPoolWeights: {
initial_pool_weights: {
token: {
denom: string;
// Int
Expand All @@ -25,7 +25,7 @@ export interface WeightedPoolRaw {
// Int
weight: string;
}[];
targetPoolWeights: {
target_pool_weights: {
token: {
denom: string;
// Int
Expand All @@ -37,13 +37,13 @@ export interface WeightedPoolRaw {
} | null;
};
// Int
totalWeight: string;
totalShares: {
total_weight: string;
total_shares: {
denom: string;
// Int
amount: string;
};
poolAssets: [
pool_assets: [
{
// Int
weight: string;
Expand All @@ -61,15 +61,15 @@ export class WeightedPool implements Pool {
constructor(public readonly raw: WeightedPoolRaw) {}

get exitFee(): Dec {
return new Dec(this.raw.poolParams.exitFee);
return new Dec(this.raw.pool_params.exit_fee);
}

get id(): string {
return this.raw.id;
}

get poolAssets(): { denom: string; amount: Int; weight: Int }[] {
return this.raw.poolAssets.map((asset) => {
return this.raw.pool_assets.map((asset) => {
return {
denom: asset.token.denom,
amount: new Int(asset.token.amount),
Expand All @@ -79,30 +79,34 @@ export class WeightedPool implements Pool {
}

get poolAssetDenoms(): string[] {
return this.raw.poolAssets.map((asset) => asset.token.denom);
return this.raw.pool_assets.map((asset) => asset.token.denom);
}

get shareDenom(): string {
return this.raw.totalShares.denom;
return this.raw.total_shares.denom;
}

get swapFee(): Dec {
return new Dec(this.raw.poolParams.swapFee);
return new Dec(this.raw.pool_params.swap_fee);
}

get totalShare(): Int {
return new Int(this.raw.totalShares.amount);
return new Int(this.raw.total_shares.amount);
}

get smoothWeightChange(): SmoothWeightChangeParams | undefined {
if (this.raw.poolParams.smoothWeightChangeParams !== null) {
const { start_time, duration, initialPoolWeights, targetPoolWeights } =
this.raw.poolParams.smoothWeightChangeParams;
if (this.raw.pool_params.smooth_weight_change_params !== null) {
const {
start_time,
duration,
initial_pool_weights,
target_pool_weights,
} = this.raw.pool_params.smooth_weight_change_params;
return {
startTime: start_time,
duration,
initialPoolWeights,
targetPoolWeights,
initialPoolWeights: initial_pool_weights,
targetPoolWeights: target_pool_weights,
};
}
}
Expand All @@ -124,7 +128,7 @@ export class WeightedPool implements Pool {
}

get totalWeight(): Int {
return new Int(this.raw.totalWeight);
return new Int(this.raw.total_weight);
}

getSpotPriceInOverOut(tokenInDenom: string, tokenOutDenom: string): Dec {
Expand Down
18 changes: 9 additions & 9 deletions packages/pools/types/weighted.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import { Dec, Int } from "@keplr-wallet/unit";
/** Raw query response representation of pool. */
export interface WeightedPoolRaw {
id: string;
poolParams: {
pool_params: {
lock: boolean;
swapFee: string;
exitFee: string;
smoothWeightChangeParams: {
swap_fee: string;
exit_fee: string;
smooth_weight_change_params: {
start_time: string;
duration: string;
initialPoolWeights: {
initial_pool_weights: {
token: {
denom: string;
amount: string;
};
weight: string;
}[];
targetPoolWeights: {
target_pool_weights: {
token: {
denom: string;
amount: string;
Expand All @@ -26,12 +26,12 @@ export interface WeightedPoolRaw {
}[];
} | null;
};
totalWeight: string;
totalShares: {
total_weight: string;
total_shares: {
denom: string;
amount: string;
};
poolAssets: [
pool_assets: [
{
weight: string;
token: {
Expand Down
78 changes: 39 additions & 39 deletions packages/stores/src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class OsmosisAccountImpl {
onFulfill?: (tx: any) => void
) {
const poolParams = {
swapFee: new Dec(swapFee)
swap_fee: new Dec(swapFee)
.quo(DecUtils.getTenExponentNInPrecisionRange(2))
.toString(),
exitFee: new Dec(0).toString(),
exit_fee: new Dec(0).toString(),
};

const poolAssets: {
Expand Down Expand Up @@ -123,8 +123,8 @@ export class OsmosisAccountImpl {
type: this._msgOpts.createPool.type,
value: {
sender: this.base.bech32Address,
poolParams,
poolAssets,
pool_params: poolParams,
pool_assets: poolAssets,
future_pool_governor: "24h",
},
};
Expand All @@ -143,13 +143,13 @@ export class OsmosisAccountImpl {
sender: msg.value.sender,
poolParams: {
swapFee: this.changeDecStringToProtoBz(
msg.value.poolParams.swapFee
msg.value.pool_params.swap_fee
),
exitFee: this.changeDecStringToProtoBz(
msg.value.poolParams.exitFee
msg.value.pool_params.exit_fee
),
},
poolAssets: msg.value.poolAssets,
poolAssets: msg.value.pool_assets,
futurePoolGovernor: msg.value.future_pool_governor,
}
).finish(),
Expand Down Expand Up @@ -259,16 +259,16 @@ export class OsmosisAccountImpl {
type: this._msgOpts.joinPool.type,
value: {
sender: this.base.bech32Address,
poolId,
shareOutAmount: new Dec(shareOutAmount)
pool_id: poolId,
share_out_amount: new Dec(shareOutAmount)
.mul(
DecUtils.getTenExponentNInPrecisionRange(
this._msgOpts.joinPool.shareCoinDecimals
)
)
.truncate()
.toString(),
tokenInMaxs,
token_in_maxs: tokenInMaxs,
},
};

Expand All @@ -279,9 +279,9 @@ export class OsmosisAccountImpl {
typeUrl: "/osmosis.gamm.v1beta1.MsgJoinPool",
value: osmosis.gamm.v1beta1.MsgJoinPool.encode({
sender: msg.value.sender,
poolId: Long.fromString(msg.value.poolId),
shareOutAmount: msg.value.shareOutAmount,
tokenInMaxs: msg.value.tokenInMaxs,
poolId: Long.fromString(msg.value.pool_id),
shareOutAmount: msg.value.share_out_amount,
tokenInMaxs: msg.value.token_in_maxs,
}).finish(),
},
],
Expand Down Expand Up @@ -380,12 +380,12 @@ export class OsmosisAccountImpl {
type: this._msgOpts.joinSwapExternAmountIn.type,
value: {
sender: this.base.bech32Address,
poolId,
tokenIn: {
pool_id: poolId,
token_in: {
denom: coin.denom,
amount: coin.amount.toString(),
},
shareOutMinAmount: shareOutMinAmount.toString(),
share_out_min_amount: shareOutMinAmount.toString(),
},
};

Expand All @@ -396,9 +396,9 @@ export class OsmosisAccountImpl {
typeUrl: "/osmosis.gamm.v1beta1.MsgJoinSwapExternAmountIn",
value: osmosis.gamm.v1beta1.MsgJoinSwapExternAmountIn.encode({
sender: msg.value.sender,
poolId: Long.fromString(msg.value.poolId),
tokenIn: msg.value.tokenIn,
shareOutMinAmount: msg.value.shareOutMinAmount,
poolId: Long.fromString(msg.value.pool_id),
tokenIn: msg.value.token_in,
shareOutMinAmount: msg.value.share_out_min_amount,
}).finish(),
},
],
Expand Down Expand Up @@ -526,12 +526,12 @@ export class OsmosisAccountImpl {
sender: msg.value.sender,
routes: msg.value.routes.map((route) => {
return {
poolId: Long.fromString(route.poolId),
tokenOutDenom: route.tokenOutDenom,
poolId: Long.fromString(route.pool_id),
tokenOutDenom: route.token_out_denom,
};
}),
tokenIn: msg.value.tokenIn,
tokenOutMinAmount: msg.value.tokenOutMinAmount,
tokenIn: msg.value.token_in,
tokenOutMinAmount: msg.value.token_out_min_amount,
}).finish(),
},
],
Expand Down Expand Up @@ -649,15 +649,15 @@ export class OsmosisAccountImpl {
value: osmosis.gamm.v1beta1.MsgSwapExactAmountIn.encode({
sender: msg.value.sender,
routes: msg.value.routes.map(
(route: { poolId: string; tokenOutDenom: string }) => {
(route: { pool_id: string; token_out_denom: string }) => {
return {
poolId: Long.fromString(route.poolId),
tokenOutDenom: route.tokenOutDenom,
poolId: Long.fromString(route.pool_id),
tokenOutDenom: route.token_out_denom,
};
}
),
tokenIn: msg.value.tokenIn,
tokenOutMinAmount: msg.value.tokenOutMinAmount,
tokenIn: msg.value.token_in,
tokenOutMinAmount: msg.value.token_out_min_amount,
}).finish(),
},
],
Expand Down Expand Up @@ -766,15 +766,15 @@ export class OsmosisAccountImpl {
value: osmosis.gamm.v1beta1.MsgSwapExactAmountOut.encode({
sender: msg.value.sender,
routes: msg.value.routes.map(
(route: { poolId: string; tokenInDenom: string }) => {
(route: { pool_id: string; token_in_denom: string }) => {
return {
poolId: Long.fromString(route.poolId),
tokenInDenom: route.tokenInDenom,
poolId: Long.fromString(route.pool_id),
tokenInDenom: route.token_in_denom,
};
}
),
tokenOut: msg.value.tokenOut,
tokenInMaxAmount: msg.value.tokenInMaxAmount,
tokenOut: msg.value.token_out,
tokenInMaxAmount: msg.value.token_in_max_amount,
}).finish(),
},
],
Expand Down Expand Up @@ -878,16 +878,16 @@ export class OsmosisAccountImpl {
type: this._msgOpts.exitPool.type,
value: {
sender: this.base.bech32Address,
poolId: pool.id,
shareInAmount: new Dec(shareInAmount)
pool_id: pool.id,
share_in_amount: new Dec(shareInAmount)
.mul(
DecUtils.getTenExponentNInPrecisionRange(
this._msgOpts.exitPool.shareCoinDecimals
)
)
.truncate()
.toString(),
tokenOutMins,
token_out_mins: tokenOutMins,
},
};

Expand All @@ -898,9 +898,9 @@ export class OsmosisAccountImpl {
typeUrl: "/osmosis.gamm.v1beta1.MsgExitPool",
value: osmosis.gamm.v1beta1.MsgExitPool.encode({
sender: msg.value.sender,
poolId: Long.fromString(msg.value.poolId),
shareInAmount: msg.value.shareInAmount,
tokenOutMins: msg.value.tokenOutMins,
poolId: Long.fromString(msg.value.pool_id),
shareInAmount: msg.value.share_in_amount,
tokenOutMins: msg.value.token_out_mins,
}).finish(),
},
],
Expand Down
Loading