Skip to content

Commit

Permalink
Merge pull request #3674 from osmosis-labs/stage
Browse files Browse the repository at this point in the history
Publish Stage
  • Loading branch information
jonator authored Aug 5, 2024
2 parents bde9d93 + 580ffdc commit 5c61de7
Show file tree
Hide file tree
Showing 37 changed files with 835 additions and 26 deletions.
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
14 changes: 10 additions & 4 deletions packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,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 @@ -439,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 @@ -494,7 +500,7 @@ export class SkipBridgeProvider implements BridgeProvider {
// is an ibc transfer

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

const { typeUrl, value } = cosmosMsgOpts.ibcTransfer.messageComposer({
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/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 5c61de7

Please sign in to comment.