Skip to content

Commit

Permalink
Merge pull request #131 from axelarnetwork/develop
Browse files Browse the repository at this point in the history
0.1.4
  • Loading branch information
canhtrinh authored Oct 2, 2022
2 parents 48a2321 + f7c822a commit 7dd5258
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 11 deletions.
19 changes: 19 additions & 0 deletions components/swap/states/parts/CosmosWalletTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { SwapStatus } from "../../../../utils/enums";
import { SpinnerRoundFilled } from "spinners-react";
import { renderGasFee } from "../../../../utils/renderGasFee";
import { evmosSignDirect } from "../../../../hooks/kepler/evmos/evmosSignDirect";

export const CosmosWalletTransfer = () => {
const allAssets = useSwapStore((state) => state.allAssets);
Expand Down Expand Up @@ -205,6 +206,24 @@ export const CosmosWalletTransfer = () => {
} catch (error: any) {
throw new Error(error);
}
} else if (srcChain.chainName.toLowerCase() === "evmos") {
const sendCoin = {
denom: currentAsset?.ibcDenom as string,
amount: utils
.parseUnits(tokensToTransfer, currentAsset?.decimals)
.toString(),
};
evmosSignDirect(sendCoin.amount, sendCoin.denom, sourceAddress, depositAddress)
.then((res: any) => {
console.log("CosmosWalletTransfer: IBC transfer for EvmosJS",res);

setTxInfo({
sourceTxHash: res.transactionHash,
});

setIsTxOngoing(true);
})
.catch((error) => console.log(error));
} else {
result = await cosmjs
.sendIbcTokens(
Expand Down
2 changes: 1 addition & 1 deletion config/web3/cosmos/mainnet/evmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CosmosChain } from "../interface";

export default {
rpc: "https://mainnet-rpc-router.axelar-dev.workers.dev/?chain=evmos",
rest: "https://rest-evmos.ecostake.com",
rest: "https://rest.bd.evmos.org:1317", //"https://mainnet-lcd-router.axelar-dev.workers.dev", TODO - get LCD router to work so that we can retry
chainId: "evmos_9001-2",
chainName: "Evmos",
stakeCurrency: {
Expand Down
93 changes: 93 additions & 0 deletions hooks/kepler/evmos/evmosSignDirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { createTxRaw } from "@evmos/proto";
import {
createTxIBCMsgTransfer,
MessageIBCMsgTransfer,
} from "@evmos/transactions";
import {
generateEndpointBroadcast,
generatePostBodyBroadcast,
} from "@evmos/provider";
import Long from "long";
import { getCosmosChains } from "../../../config/web3";
import { CosmosChain } from "../../../config/web3/cosmos/interface";

export const evmosSignDirect = async (
amount: string,
denom: string,
senderAddress: string,
depositAddress: string
) => {
const keplrConfig: CosmosChain = getCosmosChains([]).find(
(chain) => chain.chainIdentifier === "evmos"
) as CosmosChain;
const { chainId: keplrChainId, rest, chainToAxelarChannelId } = keplrConfig;
const chain = {
chainId: Number(keplrChainId.split("_")[1].split("-")[0]),
cosmosChainId: keplrChainId,
};

const fetchSenderResults = await fetch(
`${rest}/cosmos/auth/v1beta1/accounts/${senderAddress}?chain=evmos`
).then((res) => res.json());
const { account } = fetchSenderResults;
const { base_account } = account;
const { address, pub_key, account_number, sequence } = base_account;
const pubKeyType = pub_key["@type"];
const pubKeyKey = pub_key.key;
const sender = {
accountAddress: address,
sequence: sequence,
accountNumber: account_number,
pubkey: pubKeyKey,
};

const fee = {
amount: "20",
denom: "aevmos",
gas: "200000",
};
const memo = "";
const params: MessageIBCMsgTransfer = {
sourcePort: "transfer",
sourceChannel: chainToAxelarChannelId,
amount,
denom,
receiver: depositAddress,
revisionNumber: 10,
revisionHeight: 10,
timeoutTimestamp: "0",
};
const msg = createTxIBCMsgTransfer(chain, sender, fee, memo, params);

let sign = await window?.keplr?.signDirect(
chain.cosmosChainId,
sender.accountAddress,
{
bodyBytes: msg.signDirect.body.serializeBinary(),
authInfoBytes: msg.signDirect.authInfo.serializeBinary(),
chainId: chain.cosmosChainId,
accountNumber: new Long(sender.accountNumber),
},
// @ts-expect-error the types are not updated on Keplr side
{ isEthereum: true }
);

if (sign !== undefined) {
let rawTx = createTxRaw(sign.signed.bodyBytes, sign.signed.authInfoBytes, [
new Uint8Array(Buffer.from(sign.signature.signature, "base64")),
]);

// Broadcast it
const postOptions = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: generatePostBodyBroadcast(rawTx),
};

let broadcastPost = await fetch(
`${rest}${generateEndpointBroadcast()}?chain=evmos`,
postOptions
);
return await broadcastPost.json().then(res => ({ transactionHash: res?.tx_response?.txhash }));
}
};
7 changes: 6 additions & 1 deletion hooks/useGetAssetBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export const useGetAssetBalance = () => {
setBalance(balance);
} catch (e: any) {
setBalance("0");
const msg = `RPC query failure for ${fullChainConfig.chainName}. Please let us know.`;
let msg;
if (e?.toString()?.includes("Ledger is not compatible")) {
msg = e?.toString();
} else {
msg = `RPC query failure for ${fullChainConfig.chainName}. Please let us know.`;
}
toast.error(msg);
}
setLoading(false);
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axelar-satellite",
"version": "0.1.3",
"version": "0.1.4",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -12,6 +12,9 @@
"dependencies": {
"@axelar-network/axelarjs-sdk": "0.9.1",
"@cosmjs/stargate": "^0.28.11",
"@evmos/proto": "^0.1.22",
"@evmos/provider": "^0.2.6",
"@evmos/transactions": "^0.2.8",
"@keplr-wallet/cosmos": "^0.10.13",
"animate.css": "^4.1.1",
"bech32": "^2.0.0",
Expand Down
Loading

1 comment on commit 7dd5258

@vercel
Copy link

@vercel vercel bot commented on 7dd5258 Oct 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.