mirror of https://github.com/certusone/oyster.git
feat: transfer
This commit is contained in:
parent
a9fc4dbf8d
commit
b0ae8b4c88
|
@ -95,50 +95,68 @@ export const Transfer = () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const bridgeAddress = programIds().wormhole.bridge;
|
|
||||||
|
|
||||||
let signer = provider.getSigner();
|
if(request.from === ASSET_CHAIN.Solana) {
|
||||||
let e = WrappedAssetFactory.connect(asset, provider);
|
const bridgeAddress = programIds().wormhole.bridge;
|
||||||
let addr = await signer.getAddress();
|
|
||||||
let balance = await e.balanceOf(addr);
|
|
||||||
let decimals = await e.decimals();
|
|
||||||
let symbol = await e.symbol();
|
|
||||||
|
|
||||||
let allowance = await e.allowance(addr, bridgeAddress);
|
let signer = provider.getSigner();
|
||||||
|
let e = WrappedAssetFactory.connect(asset, provider);
|
||||||
|
let addr = await signer.getAddress();
|
||||||
|
let balance = await e.balanceOf(addr);
|
||||||
|
let decimals = await e.decimals();
|
||||||
|
let symbol = await e.symbol();
|
||||||
|
|
||||||
let info = {
|
let allowance = await e.allowance(addr, bridgeAddress);
|
||||||
address: asset,
|
|
||||||
name: symbol,
|
|
||||||
balance: balance,
|
|
||||||
balanceAsNumber:
|
|
||||||
new BN(balance.toString())
|
|
||||||
.div(new BN(10).pow(new BN(decimals - 2)))
|
|
||||||
.toNumber() / 100,
|
|
||||||
allowance: allowance,
|
|
||||||
decimals: decimals,
|
|
||||||
isWrapped: false,
|
|
||||||
chainID: ASSET_CHAIN.Ethereum,
|
|
||||||
assetAddress: Buffer.from(asset.slice(2), 'hex'),
|
|
||||||
mint: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
let b = WormholeFactory.connect(bridgeAddress, provider);
|
let info = {
|
||||||
|
address: asset,
|
||||||
|
name: symbol,
|
||||||
|
balance: balance,
|
||||||
|
balanceAsNumber:
|
||||||
|
new BN(balance.toString())
|
||||||
|
.div(new BN(10).pow(new BN(decimals - 2)))
|
||||||
|
.toNumber() / 100,
|
||||||
|
allowance: allowance,
|
||||||
|
decimals: decimals,
|
||||||
|
isWrapped: false,
|
||||||
|
chainID: ASSET_CHAIN.Ethereum,
|
||||||
|
assetAddress: Buffer.from(asset.slice(2), 'hex'),
|
||||||
|
mint: '',
|
||||||
|
};
|
||||||
|
|
||||||
let isWrapped = await b.isWrappedAsset(asset);
|
let b = WormholeFactory.connect(bridgeAddress, provider);
|
||||||
if (isWrapped) {
|
|
||||||
info.chainID = await e.assetChain();
|
let isWrapped = await b.isWrappedAsset(asset);
|
||||||
info.assetAddress = Buffer.from(
|
if (isWrapped) {
|
||||||
(await e.assetAddress()).slice(2),
|
info.chainID = await e.assetChain();
|
||||||
'hex',
|
info.assetAddress = Buffer.from(
|
||||||
);
|
(await e.assetAddress()).slice(2),
|
||||||
info.isWrapped = true;
|
'hex',
|
||||||
|
);
|
||||||
|
info.isWrapped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRequest({
|
||||||
|
...request,
|
||||||
|
asset,
|
||||||
|
info,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(asset);
|
||||||
|
// let info = {
|
||||||
|
// address: fromAddress,
|
||||||
|
// name: "",
|
||||||
|
// balance: acc.balance,
|
||||||
|
// allowance: 0,
|
||||||
|
// decimals: acc.assetMeta.decimals,
|
||||||
|
// isWrapped: acc.assetMeta.chain != ChainID.SOLANA,
|
||||||
|
// chainID: acc.assetMeta.chain,
|
||||||
|
// assetAddress: acc.assetMeta.address,
|
||||||
|
|
||||||
|
// // Solana specific
|
||||||
|
// mint: acc.mint,
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
||||||
setRequest({
|
|
||||||
...request,
|
|
||||||
asset,
|
|
||||||
info,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.toString());
|
console.error(e.toString());
|
||||||
notify({
|
notify({
|
||||||
|
|
|
@ -17,10 +17,10 @@ const WormholeCanvas = ({
|
||||||
rotate?: boolean;
|
rotate?: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<Canvas onCreated={onCreated}>
|
<Canvas onCreated={onCreated} style={{ opacity: 0.4 }}>
|
||||||
<Camera />
|
<Camera />
|
||||||
<React.Suspense fallback={null}>
|
<React.Suspense fallback={null}>
|
||||||
<WormholeGeometry rotate={rotate} />
|
<WormholeGeometry rotate={rotate}/>
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
);
|
);
|
||||||
|
|
|
@ -15,15 +15,8 @@ import { ASSET_CHAIN } from '../../../utils/assets';
|
||||||
import { BigNumber } from 'ethers/utils';
|
import { BigNumber } from 'ethers/utils';
|
||||||
import { Erc20Factory } from '../../../contracts/Erc20Factory';
|
import { Erc20Factory } from '../../../contracts/Erc20Factory';
|
||||||
import { WormholeFactory } from '../../../contracts/WormholeFactory';
|
import { WormholeFactory } from '../../../contracts/WormholeFactory';
|
||||||
import { AssetMeta, createWrappedAssetInstruction } from './../meta';
|
import { bridgeAuthorityKey } from './../helpers';
|
||||||
import { bridgeAuthorityKey, wrappedAssetMintKey } from './../helpers';
|
import { Connection, PublicKey, SystemProgram } from '@solana/web3.js';
|
||||||
import {
|
|
||||||
Account,
|
|
||||||
Connection,
|
|
||||||
PublicKey,
|
|
||||||
SystemProgram,
|
|
||||||
TransactionInstruction,
|
|
||||||
} from '@solana/web3.js';
|
|
||||||
import { Token } from '@solana/spl-token';
|
import { Token } from '@solana/spl-token';
|
||||||
import { ProgressUpdate, TransferRequest } from './interface';
|
import { ProgressUpdate, TransferRequest } from './interface';
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
|
|
Loading…
Reference in New Issue