web: working transfers

This commit is contained in:
Hendrik Hofstadt 2020-08-21 12:45:24 +02:00
parent 1d960405d1
commit 8d4927cb4a
8 changed files with 10162 additions and 7206 deletions

File diff suppressed because one or more lines are too long

View File

@ -14865,4 +14865,4 @@
"methods": {},
"version": 1
}
}
}

View File

@ -2,31 +2,32 @@ import React, {useContext} from "react"
import {BalanceInfo, SolanaTokenContext} from "../providers/SolanaTokenContext";
import {Table} from "antd";
import {CHAIN_ID_SOLANA} from "../utils/bridge";
import {BigNumber} from "ethers/utils";
function SplBalances() {
let t = useContext(SolanaTokenContext);
const columns = [
{
title: 'Mint',
dataIndex: 'mint',
key: 'mint',
},
{
title: 'Account',
key: 'account',
render: (n: any, v: BalanceInfo) => v.account.toString()
},
{
title: 'Mint',
dataIndex: 'mint',
key: 'mint',
},
{
title: 'Balance',
key: 'balance',
render: (n: any, v: BalanceInfo) => v.balance.div(Math.pow(10, v.decimals)).toString()
render: (n: any, v: BalanceInfo) => v.balance.div(new BigNumber(10).pow(v.decimals)).toString()
},
{
title: 'Wrapped',
key: 'wrapped',
render: (n: any, v: BalanceInfo) => {
return v.assetMeta.chain != CHAIN_ID_SOLANA ? `Wrapped (${v.assetMeta.chain})` : "Native"
return v.assetMeta.chain != CHAIN_ID_SOLANA ? `Wrapped (${v.assetMeta.chain} - 0x${v.assetMeta.address.slice(12).toString("hex")})` : "Native"
}
},
];

View File

@ -1,6 +1,6 @@
import {PublicKey} from "@solana/web3.js";
const BRIDGE_ADDRESS = "0xac3eB48829fFC3C37437ce4459cE63F1F4d4E0b4";
const BRIDGE_ADDRESS = "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24";
const SOLANA_BRIDGE_PROGRAM = new PublicKey("Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o");
const TOKEN_PROGRAM = new PublicKey("TokenSVp5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o");

View File

@ -26,35 +26,36 @@ interface WormholeInterface extends Interface {
wrappedAssets: TypedFunctionDescription<{ encode([]: [Arrayish]): string }>;
getGuardianSet: TypedFunctionDescription<{
encode([idx]: [BigNumberish]): string;
}>;
submitVAA: TypedFunctionDescription<{ encode([vaa]: [Arrayish]): string }>;
lockAssets: TypedFunctionDescription<{
encode([asset, amount, recipient, target_chain]: [
encode([asset, amount, recipient, target_chain, nonce]: [
string,
BigNumberish,
Arrayish,
BigNumberish,
BigNumberish
]): string;
}>;
lockETH: TypedFunctionDescription<{
encode([recipient, target_chain]: [Arrayish, BigNumberish]): string;
encode([recipient, target_chain, nonce]: [
Arrayish,
BigNumberish,
BigNumberish
]): string;
}>;
};
events: {
LogGuardianSetChanged: TypedEventDescription<{
encodeTopics([oldGuardian, newGuardian]: [
{
x: BigNumberish;
parity: BigNumberish;
expiration_time: BigNumberish;
} | null,
{
x: BigNumberish;
parity: BigNumberish;
expiration_time: BigNumberish;
} | null
encodeTopics([oldGuardianIndex, newGuardianIndex]: [
null,
null
]): string[];
}>;
@ -65,8 +66,17 @@ interface WormholeInterface extends Interface {
token,
sender,
recipient,
amount
]: [null, null, Arrayish | null, Arrayish | null, null, null]): string[];
amount,
nonce
]: [
null,
null,
Arrayish | null,
Arrayish | null,
null,
null,
null
]): string[];
}>;
};
}
@ -92,26 +102,12 @@ export class Wormhole extends Contract {
guardian_sets(
arg0: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
x: BigNumber;
parity: number;
expiration_time: number;
0: BigNumber;
1: number;
2: number;
}>;
): Promise<number>;
"guardian_sets(uint32)"(
arg0: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
x: BigNumber;
parity: number;
expiration_time: number;
0: BigNumber;
1: number;
2: number;
}>;
): Promise<number>;
isWrappedAsset(
arg0: string,
@ -141,6 +137,26 @@ export class Wormhole extends Contract {
overrides?: TransactionOverrides
): Promise<string>;
getGuardianSet(
idx: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
keys: string[];
expiration_time: number;
0: string[];
1: number;
}>;
"getGuardianSet(uint32)"(
idx: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
keys: string[];
expiration_time: number;
0: string[];
1: number;
}>;
submitVAA(
vaa: Arrayish,
overrides?: TransactionOverrides
@ -156,26 +172,30 @@ export class Wormhole extends Contract {
amount: BigNumberish,
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
"lockAssets(address,uint256,bytes32,uint8)"(
"lockAssets(address,uint256,bytes32,uint8,uint32)"(
asset: string,
amount: BigNumberish,
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
lockETH(
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
"lockETH(bytes32,uint8)"(
"lockETH(bytes32,uint8,uint32)"(
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
};
@ -187,26 +207,12 @@ export class Wormhole extends Contract {
guardian_sets(
arg0: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
x: BigNumber;
parity: number;
expiration_time: number;
0: BigNumber;
1: number;
2: number;
}>;
): Promise<number>;
"guardian_sets(uint32)"(
arg0: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
x: BigNumber;
parity: number;
expiration_time: number;
0: BigNumber;
1: number;
2: number;
}>;
): Promise<number>;
isWrappedAsset(
arg0: string,
@ -236,6 +242,26 @@ export class Wormhole extends Contract {
overrides?: TransactionOverrides
): Promise<string>;
getGuardianSet(
idx: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
keys: string[];
expiration_time: number;
0: string[];
1: number;
}>;
"getGuardianSet(uint32)"(
idx: BigNumberish,
overrides?: TransactionOverrides
): Promise<{
keys: string[];
expiration_time: number;
0: string[];
1: number;
}>;
submitVAA(
vaa: Arrayish,
overrides?: TransactionOverrides
@ -251,41 +277,37 @@ export class Wormhole extends Contract {
amount: BigNumberish,
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
"lockAssets(address,uint256,bytes32,uint8)"(
"lockAssets(address,uint256,bytes32,uint8,uint32)"(
asset: string,
amount: BigNumberish,
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
lockETH(
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
"lockETH(bytes32,uint8)"(
"lockETH(bytes32,uint8,uint32)"(
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<ContractTransaction>;
filters: {
LogGuardianSetChanged(
oldGuardian: {
x: BigNumberish;
parity: BigNumberish;
expiration_time: BigNumberish;
} | null,
newGuardian: {
x: BigNumberish;
parity: BigNumberish;
expiration_time: BigNumberish;
} | null
oldGuardianIndex: null,
newGuardianIndex: null
): EventFilter;
LogTokensLocked(
@ -294,7 +316,8 @@ export class Wormhole extends Contract {
token: Arrayish | null,
sender: Arrayish | null,
recipient: null,
amount: null
amount: null,
nonce: null
): EventFilter;
};
@ -345,6 +368,16 @@ export class Wormhole extends Contract {
overrides?: TransactionOverrides
): Promise<BigNumber>;
getGuardianSet(
idx: BigNumberish,
overrides?: TransactionOverrides
): Promise<BigNumber>;
"getGuardianSet(uint32)"(
idx: BigNumberish,
overrides?: TransactionOverrides
): Promise<BigNumber>;
submitVAA(
vaa: Arrayish,
overrides?: TransactionOverrides
@ -360,26 +393,30 @@ export class Wormhole extends Contract {
amount: BigNumberish,
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<BigNumber>;
"lockAssets(address,uint256,bytes32,uint8)"(
"lockAssets(address,uint256,bytes32,uint8,uint32)"(
asset: string,
amount: BigNumberish,
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<BigNumber>;
lockETH(
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<BigNumber>;
"lockETH(bytes32,uint8)"(
"lockETH(bytes32,uint8,uint32)"(
recipient: Arrayish,
target_chain: BigNumberish,
nonce: BigNumberish,
overrides?: TransactionOverrides
): Promise<BigNumber>;
};

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,7 @@ import {BridgeContext} from "../providers/BridgeContext";
import {AssetMeta, SolanaBridge} from "../utils/bridge";
import KeyContext from "../providers/KeyContext";
import {FormInstance} from "antd/lib/form";
import SplBalances from "../components/SplBalances";
// @ts-ignore
@ -29,11 +30,12 @@ async function lockAssets(asset: string,
let wh = WormholeFactory.connect(BRIDGE_ADDRESS, signer);
try {
message.loading({content: "Signing transaction...", key: "eth_tx", duration: 1000},)
let res = await wh.lockAssets(asset, amount, recipient, target_chain)
let res = await wh.lockAssets(asset, amount, recipient, target_chain, 10)
message.loading({content: "Waiting for transaction to be mined...", key: "eth_tx", duration: 1000})
await res.wait(1);
message.success({content: "Transfer on ETH succeeded!", key: "eth_tx"})
} catch (e) {
console.log(e)
message.error({content: "Transfer failed", key: "eth_tx"})
}
}
@ -102,6 +104,8 @@ function Transfer() {
let [wrappedMint, setWrappedMint] = useState("")
let [recipient, setRecipient] = useState("")
let [transacting, setTransacting] = useState(false);
let formRef = React.createRef<FormInstance>();
useEffect(() => {
@ -137,7 +141,7 @@ function Transfer() {
}
}
fetchBalance(address)
}, [address])
}, [address, transacting])
useEffect(() => {
if (!addressValid) {
@ -184,10 +188,15 @@ function Transfer() {
<Form onFinish={(values) => {
let recipient = new solanaWeb3.PublicKey(values["recipient"]).toBuffer()
let transferAmount = new BigNumber(values["amount"]).mul(new BigNumber(10).pow(coinInfo.decimals));
setTransacting(true)
if (coinInfo.allowance.gte(amount) || coinInfo.isWrapped) {
lockAssets(values["address"], transferAmount, recipient, values["target_chain"])
lockAssets(values["address"], transferAmount, recipient, values["target_chain"]).finally(() => {
setTransacting(false)
})
} else {
approveAssets(values["address"], transferAmount)
approveAssets(values["address"], transferAmount).finally(() => {
setTransacting(false)
})
}
}} style={{width: "100%"}} ref={formRef} layout={"vertical"}>
<Form.Item name="address" validateStatus={addressValid ? "success" : "error"} label={"Token:"}>
@ -206,7 +215,7 @@ function Transfer() {
</Form.Item>
<Form.Item name="target_chain"
label={"Target Chain:"}>
<Select placeholder="Target Chain" defaultValue={1}>
<Select placeholder="Target Chain">
<Select.Option value={1}>
Solana
</Select.Option>
@ -220,7 +229,8 @@ function Transfer() {
}}/>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" style={{marginLeft:"auto"}}>
<Button type="primary" htmlType="submit" style={{marginLeft: "auto"}}
disabled={transacting}>
{coinInfo.allowance.gte(amount) || coinInfo.isWrapped ? "Transfer" : "Approve"}
</Button>
</Form.Item>
@ -264,6 +274,11 @@ function Transfer() {
</Card>
</Col>
</Row>
<Row>
<Col>
<SplBalances/>
</Col>
</Row>
</>
);
}

View File

@ -115,7 +115,7 @@ function TransferSolana() {
<Form.Item name="target_chain"
rules={[{required: true, message: "Please choose a target chain"}]}
label={"Target Chain:"}>
<Select placeholder="Target Chain" defaultValue={2}>
<Select placeholder="Target Chain">
<Select.Option value={2}>
Ethereum
</Select.Option>