Skip to content

add cw20s section; add config for SEASY cw20 token from Juno to Scrt #22

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@babel/core": "^7.0.0",
"@cosmjs/cosmwasm-stargate": "^0.29.4",
"@cosmjs/stargate": "0.26.5",
"@emotion/react": "11.6.0",
"@emotion/styled": "11.6.0",
Expand Down
Binary file added public/seasy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import { Breakpoint, BreakpointProvider } from "react-socks";
import { SecretNetworkClient } from "secretjs";
import { chains, tokens, snips } from "./config";
import { chains, tokens, snips, cw20s } from "./config";
import { faucetURL } from "./commons";
import "./index.css";
import { KeplrPanel } from "./KeplrStuff";
Expand Down Expand Up @@ -110,7 +110,7 @@ export default function App() {

const denoms = Array.from(
new Set(
tokens.map((t) => t.withdrawals.map((w) => w.from_denom)).flat()
(tokens.concat(cw20s)).map((t) => t.withdrawals.map((w) => w.from_denom)).flat(),
)
);

Expand Down Expand Up @@ -298,6 +298,29 @@ export default function App() {
/>
</ErrorBoundary>
))}
<Divider variant="middle"/>
<Typography
component="div"
align="center"
sx={{
marginBottom: "0.5rem",
}}
>
CW20s via IBC from JUNO
</Typography>
{cw20s.map((t) => (
<ErrorBoundary key={t.name}>
<TokenRow
token={t}
loadingCoinBalances={loadingCoinBalances}
secretAddress={secretAddress}
secretjs={secretjs}
balances={balances}
price={prices.get(t.name) || 0}
useFeegrant = {useFeegrant}
/>
</ErrorBoundary>
))}

<Breakpoint medium up>
<ToastContainer
Expand Down
124 changes: 87 additions & 37 deletions src/Deposit.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { SigningStargateClient } from "@cosmjs/stargate";
import LoadingButton from "@mui/lab/LoadingButton";
import {
Expand Down Expand Up @@ -51,8 +52,8 @@ export default function Deposit({
const [sourceAddress, setSourceAddress] = useState<string>("");
const [availableBalance, setAvailableBalance] = useState<string>("");
const [loadingTx, setLoading] = useState<boolean>(false);
const [sourceCosmJs, setSourceCosmJs] =
useState<SigningStargateClient | null>(null);
const sourceCosmJsRef = useRef<
SigningCosmWasmClient | SigningStargateClient | null>(null);
const [selectedChainIndex, setSelectedChainIndex] = useState<number>(0);
const [fetchBalanceInterval, setFetchBalanceInterval] = useState<any>(null);
const inputRef = useRef<any>();
Expand All @@ -67,18 +68,32 @@ export default function Deposit({
chains[token.deposits[selectedChainIndex].source_chain_name].lcd
}/cosmos/bank/v1beta1/balances/${sourceAddress}`;
try {
const {
balances,
}: {
balances: Array<{ denom: string; amount: string }>;
} = await (await fetch(url)).json();

const balance =
balances.find(
(c) => c.denom === token.deposits[selectedChainIndex].from_denom
)?.amount || "0";

setAvailableBalance(balance);
if ((token.deposits[selectedChainIndex].from_denom).startsWith('juno1')) {
if (!sourceCosmJsRef.current) {
return;
}

const result = await (sourceCosmJsRef.current as SigningCosmWasmClient).queryContractSmart(
token.deposits[selectedChainIndex].from_denom,
{
balance: { address: sourceAddress },
}
);
setAvailableBalance(result.balance);
} else {
const {
balances,
}: {
balances: Array<{ denom: string; amount: string }>;
} = await (await fetch(url)).json();

const balance =
balances.find(
(c) => c.denom === token.deposits[selectedChainIndex].from_denom
)?.amount || "0";

setAvailableBalance(balance);
}
} catch (e) {
console.error(`Error while trying to query ${url}:`, e);
setAvailableBalance("Error");
Expand All @@ -99,7 +114,7 @@ export default function Deposit({
fetchSourceBalance(sourceAddress);
const interval = setInterval(
() => fetchSourceBalance(sourceAddress),
10_000
2_000
);
setFetchBalanceInterval(interval);

Expand Down Expand Up @@ -135,12 +150,22 @@ export default function Deposit({
const sourceOfflineSigner = window.getOfflineSignerOnlyAmino(chain_id);
const depositFromAccounts = await sourceOfflineSigner.getAccounts();
setSourceAddress(depositFromAccounts[0].address);
const cosmjs = await SigningStargateClient.connectWithSigner(
rpc,
sourceOfflineSigner,
{ prefix: bech32_prefix, broadcastPollIntervalMs: 10_000 }
);
setSourceCosmJs(cosmjs);

if ((token.deposits[selectedChainIndex].from_denom).startsWith('juno1')) {
const cosmjs = await SigningCosmWasmClient.connectWithSigner(
rpc,
sourceOfflineSigner,
{ prefix: bech32_prefix, broadcastPollIntervalMs: 10_000 }
);
sourceCosmJsRef.current = cosmjs;
} else {
const cosmjs = await SigningStargateClient.connectWithSigner(
rpc,
sourceOfflineSigner,
{ prefix: bech32_prefix, broadcastPollIntervalMs: 10_000 }
);
sourceCosmJsRef.current = cosmjs;
}
})();
}, [selectedChainIndex]);

Expand Down Expand Up @@ -343,7 +368,7 @@ export default function Deposit({
}}
loading={loadingTx}
onClick={async () => {
if (!sourceCosmJs) {
if (!sourceCosmJsRef.current) {
console.error("No cosmjs");
return;
}
Expand Down Expand Up @@ -398,20 +423,45 @@ export default function Deposit({
)
) {
// Regular cosmos chain (not ethermint signing)
const txResponse = await sourceCosmJs.sendIbcTokens(
sourceAddress,
secretAddress,
{
amount,
denom: token.deposits[selectedChainIndex].from_denom,
},
"transfer",
deposit_channel_id,
undefined,
Math.floor(Date.now() / 1000) + 10 * 60, // 10 minute timeout (sec)
gasToFee(deposit_gas)
);
transactionHash = txResponse.transactionHash;
if ((token.deposits[selectedChainIndex].from_denom).startsWith('juno1')) {
if (!sourceCosmJsRef.current) {
return;
}

const txResponse = await (sourceCosmJsRef.current as SigningCosmWasmClient).execute(
sourceAddress,
token.deposits[selectedChainIndex].from_denom,
{
send: {
contract: "juno105pfttgc76dcrw44jl5067we23q7he85k5893aaaek09rdz0srlqydutp0", // ics20 on Juno (Juno<>Scrt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this contract value can move to somewhere in the config?

amount: amount,
msg: Buffer.from(JSON.stringify({
channel: deposit_channel_id,
remote_address: secretAddress,
// 15 min
timeout: 900,
})).toString("base64"),
},
},
gasToFee(deposit_gas)
);
transactionHash = txResponse.transactionHash;
} else {
const txResponse = await (sourceCosmJsRef.current as SigningStargateClient).sendIbcTokens(
sourceAddress,
secretAddress,
{
amount,
denom: token.deposits[selectedChainIndex].from_denom,
},
"transfer",
deposit_channel_id,
undefined,
Math.floor(Date.now() / 1000) + 10 * 60, // 10 minute timeout (sec)
gasToFee(deposit_gas)
);
transactionHash = txResponse.transactionHash;
}
} else {
// Handle IBC transfers from Ethermint chains like Evmos & Injective

Expand Down Expand Up @@ -513,7 +563,7 @@ export default function Deposit({
// cosmjs can broadcast to Ethermint but cannot handle the response

// Broadcast the tx to Evmos
sourceCosmJs.broadcastTx(txBytes);
sourceCosmJsRef.current.broadcastTx(txBytes);
transactionHash = toHex(sha256(txBytes));
}

Expand Down
34 changes: 34 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export type Token = {
name: string;
/** a snip20 token that's originated from Secret Network */
is_snip20?: boolean;
/** a cw20 token that's originated from Juno Network */
is_cw20?: boolean;
/** secret contract address of the token */
address: string;
/** secret contract code hash of the token */
Expand Down Expand Up @@ -798,6 +800,38 @@ export const snips: Token[] = [
}
];

// These are cw20 tokens that are IBC compatible originating from Juno
export const cw20s: Token[] = [
{
name: "SEASY",
is_cw20: true,
address: "secret17gg8xcx04ldqkvkrd7r9w60rdae4ck8aslt9cf", // TODO: update this
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolve this comment once you deploy the new contract

code_hash:
"5a085bd8ed89de92b35134ddd12505a602c7759ea25fb5c089ba03c8535b3042", // TODO: update this
image: "/seasy.png",
decimals: 6,
coingecko_id: "seasy",
deposits: [
{
source_chain_name: "Juno",
from_denom:
"juno19rqljkh95gh40s7qdx40ksx3zq5tm4qsmsrdz9smw668x9zdr3lqtg33mf", // SEASY cw20 address on Juno
channel_id: "channel-161",
gas: 350_000,
}
],
withdrawals: [
{
target_chain_name: "Juno",
from_denom:
"ibc/70FF6A895E39F2EF8C679684215830B138B97222C615DADB8D8B0EDF9A27966F", // SEASY IBC asset denom on Secret
channel_id: "channel-40",
gas: 130_000,
},
],
},
];

export type Chain = {
/** display name of the chain */
chain_name: string;
Expand Down