Skip to content

Commit

Permalink
Merge branch 'stage' into roman/remove-pools-prices
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Aug 6, 2024
2 parents e47181b + 22b353a commit a11e9e8
Show file tree
Hide file tree
Showing 64 changed files with 1,922 additions and 494 deletions.
2 changes: 1 addition & 1 deletion packages/bridge/src/axelar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ export class AxelarBridgeProvider implements BridgeProvider {
});

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: depositAddress,
chainId: toChain.chainId.toString(),
});

const ibcAsset = getAssetFromAssetList({
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/src/ibc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class IbcBridgeProvider implements BridgeProvider {
const { sourceChannel, sourcePort, address } = this.getIbcSource(params);

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: params.toAddress,
chainId: params.toChain.chainId.toString(),
});

const { typeUrl, value: msg } = cosmosMsgOpts.ibcTransfer.messageComposer({
Expand Down
5 changes: 2 additions & 3 deletions packages/bridge/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export interface BridgeProviderContext {
assetLists: AssetList[];
chainList: Chain[];

/** Provides current timeout height for a chain of the ID
* parsed from the bech32 config of the given destinationAddress. */
getTimeoutHeight(params: { destinationAddress: string }): Promise<{
/** Provides current timeout height for a chain of given chainId. */
getTimeoutHeight(params: { chainId: string }): Promise<{
revisionNumber: string | undefined;
revisionHeight: string;
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ describe("SkipBridgeProvider", () => {

const txRequest = (await provider.createTransaction(
"1",
"osmosis-1",
"0xabc",
messages
)) as EvmBridgeTransactionRequest;
Expand Down
17 changes: 12 additions & 5 deletions packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export class SkipBridgeProvider implements BridgeProvider {
if (
msg.includes(
"no single-tx routes found, to enable multi-tx routes set allow_multi_tx to true"
)
) ||
msg.includes("no routes found")
) {
throw new BridgeQuoteError({
bridgeId: SkipBridgeProvider.ID,
Expand Down Expand Up @@ -211,6 +212,7 @@ export class SkipBridgeProvider implements BridgeProvider {

const transactionRequest = await this.createTransaction(
fromChain.chainId.toString(),
toChain.chainId.toString(),
fromAddress as Address,
msgs
);
Expand Down Expand Up @@ -438,26 +440,31 @@ export class SkipBridgeProvider implements BridgeProvider {
}

async createTransaction(
chainID: string,
fromChainId: string,
toChainId: string,
address: Address,
messages: SkipMsg[]
) {
for (const message of messages) {
if ("evm_tx" in message) {
return await this.createEvmTransaction(
chainID,
fromChainId,
address,
message.evm_tx
);
}

if ("multi_chain_msg" in message) {
return await this.createCosmosTransaction(message.multi_chain_msg);
return await this.createCosmosTransaction(
toChainId,
message.multi_chain_msg
);
}
}
}

async createCosmosTransaction(
toChainId: string,
message: SkipMultiChainMsg
): Promise<CosmosBridgeTransactionRequest & { fallbackGasLimit?: number }> {
const messageData = JSON.parse(message.msg);
Expand Down Expand Up @@ -493,7 +500,7 @@ export class SkipBridgeProvider implements BridgeProvider {
// is an ibc transfer

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: messageData.receiver,
chainId: toChainId,
});

const { typeUrl, value } = cosmosMsgOpts.ibcTransfer.messageComposer({
Expand Down
4 changes: 3 additions & 1 deletion packages/bridge/src/squid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export class SquidBridgeProvider implements BridgeProvider {
: await this.createCosmosTransaction(
transactionRequest.data,
fromAddress,
toChain.chainId.toString(),
{ denom: fromAsset.address, amount: fromAmount }
// TODO: uncomment when we're able to find a way to get gas limit from Squid
// or get it ourselves
Expand Down Expand Up @@ -494,6 +495,7 @@ export class SquidBridgeProvider implements BridgeProvider {
async createCosmosTransaction(
data: string,
fromAddress: string,
toChainId: string,
fromCoin: {
denom: string;
amount: string;
Expand Down Expand Up @@ -532,7 +534,7 @@ export class SquidBridgeProvider implements BridgeProvider {
};

const timeoutHeight = await this.ctx.getTimeoutHeight({
destinationAddress: ibcData.msg.receiver,
chainId: toChainId,
});

const { typeUrl, value: msg } =
Expand Down
2 changes: 1 addition & 1 deletion packages/pools/src/weighted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class WeightedPool implements SharePool, RoutablePool {

/** LBP pool */
get smoothWeightChange(): SmoothWeightChangeParams | undefined {
if (this.raw.pool_params.smooth_weight_change_params !== null) {
if (this.raw.pool_params.smooth_weight_change_params != null) {
const {
start_time,
duration,
Expand Down
1 change: 1 addition & 0 deletions packages/server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ module.exports = {
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname",
],
maxWorkers: 1,
};
1 change: 1 addition & 0 deletions packages/server/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const INDEXER_DATA_URL =
export const NUMIA_BASE_URL =
process.env.NEXT_PUBLIC_NUMIA_BASE_URL ??
"https://public-osmosis-api.numia.xyz";
export const NUMIA_API_KEY = process.env.NUMIA_API_KEY;

// sqs
export const SIDECAR_BASE_URL =
Expand Down
5 changes: 1 addition & 4 deletions packages/server/src/queries/complex/get-timeout-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import { queryRPCStatus } from "../../queries/cosmos";
export async function getTimeoutHeight({
chainList,
chainId,
destinationAddress,
}: {
chainList: Chain[];
chainId?: string;
destinationAddress?: string;
chainId: string;
}) {
const destinationCosmosChain = getChain({
chainList,
chainId,
destinationAddress,
});

if (!destinationCosmosChain) {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/queries/complex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./earn";
export * from "./get-timeout-height";
export * from "./osmosis";
export * from "./pools";
export * from "./portfolio";
export * from "./staking";
export * from "./swap-routers";
export * from "./transactions";
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import { AssetLists as assetLists } from "../../../../queries/__tests__/mock-asset-lists";
import { AllocationResponse } from "../../../sidecar/allocation";
import { calculatePercentAndFiatValues, getAll } from "../allocation";

const MOCK_DATA: AllocationResponse = {
categories: {
"in-locks": {
capitalization: "5.000000000000000000",
is_best_effort: false,
},
pooled: {
capitalization: "5.000000000000000000",
is_best_effort: false,
},
staked: {
capitalization: "5.000000000000000000",
is_best_effort: false,
},
"total-assets": {
capitalization: "60.000000000000000000",
account_coins_result: [
{
coin: {
denom: "factory/osmo1pfyxruwvtwk00y8z06dh2lqjdj82ldvy74wzm3/WOSMO",
amount: "789",
},
cap_value: "10.000000000000000000",
},
{
coin: {
denom:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail",
amount: "456",
},
cap_value: "20.000000000000000000",
},
{
coin: {
denom:
"ibc/7ED954CFFFC06EE8419387F3FC688837FF64EF264DE14219935F724EEEDBF8D3",
amount: "123",
},
cap_value: "30.000000000000000000",
},
],
is_best_effort: false,
},
"unclaimed-rewards": {
capitalization: "5.000000000000000000",
is_best_effort: false,
},
unstaking: {
capitalization: "5.000000000000000000",
is_best_effort: false,
},
"user-balances": {
capitalization: "10.000000000000000000",
account_coins_result: [
{
coin: {
denom: "factory/osmo1pfyxruwvtwk00y8z06dh2lqjdj82ldvy74wzm3/WOSMO",
amount: "789",
},
cap_value: "10.000000000000000000",
},
{
coin: {
denom:
"factory/osmo1rckme96ptawr4zwexxj5g5gej9s2dmud8r2t9j0k0prn5mch5g4snzzwjv/sail",
amount: "456",
},
cap_value: "20.000000000000000000",
},
],
is_best_effort: false,
},
},
};

describe("Allocation Functions", () => {
describe("getAll", () => {
it("should calculate the correct allocation percentages and fiat values", () => {
const result = getAll(MOCK_DATA.categories).map((allocation) => ({
...allocation,
percentage: allocation.percentage.toString(),
fiatValue: allocation.fiatValue.toString(),
}));

expect(result).toEqual([
{
key: "available",
percentage: "33.333%",
fiatValue: "$10",
},
{
key: "staked",
percentage: "16.666%",
fiatValue: "$5",
},
{
key: "unstaking",
percentage: "16.666%",
fiatValue: "$5",
},
{
key: "unclaimedRewards",
percentage: "16.666%",
fiatValue: "$5",
},
{
key: "pooled",
percentage: "16.666%",
fiatValue: "$5",
},
]);
});
});

describe("calculatePercentAndFiatValues", () => {
it("should calculate the correct asset percentages and fiat values", async () => {
const result = await calculatePercentAndFiatValues(
MOCK_DATA.categories,
assetLists,
"total-assets",
5
).map((allocation) => ({
...allocation,
percentage: allocation.percentage.toString(),
fiatValue: allocation.fiatValue.toString(),
}));

expect(result).toEqual([
{
key: "CTK",
percentage: "50%",
fiatValue: "$30",
},
{
key: "SAIL",
percentage: "33.333%",
fiatValue: "$20",
},
{
key: "WOSMO",
percentage: "16.666%",
fiatValue: "$10",
},
{
key: "Other",
percentage: "0%",
fiatValue: "$0",
},
]);
});

it("should calculate the correct asset percentages and fiat values", async () => {
const result = await calculatePercentAndFiatValues(
MOCK_DATA.categories,
assetLists,
"user-balances",
5
).map((allocation) => ({
...allocation,
percentage: allocation.percentage.toString(),
fiatValue: allocation.fiatValue.toString(),
}));

expect(result).toEqual([
{
key: "SAIL",
percentage: "200%",
fiatValue: "$20",
},
{
key: "WOSMO",
percentage: "100%",
fiatValue: "$10",
},
{
key: "Other",
percentage: "0%",
fiatValue: "$0",
},
]);
});
});
});
Loading

0 comments on commit a11e9e8

Please sign in to comment.