added code to track spl token mint
This commit is contained in:
parent
f2683ad0d9
commit
79abc6332c
|
@ -4,6 +4,7 @@ use anchor_lang::prelude::*;
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub owner: Pubkey,
|
pub owner: Pubkey,
|
||||||
pub nonce: u64,
|
pub nonce: u64,
|
||||||
|
pub mint: Pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
#[account]
|
#[account]
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub struct Initialize<'info>{
|
||||||
seeds=[b"config"],
|
seeds=[b"config"],
|
||||||
payer=owner,
|
payer=owner,
|
||||||
bump,
|
bump,
|
||||||
space=8+32+8+1
|
space=8+32+8+32+1
|
||||||
)]
|
)]
|
||||||
pub config: Account<'info, Config>,
|
pub config: Account<'info, Config>,
|
||||||
#[account(mut)]
|
#[account(mut)]
|
||||||
|
|
|
@ -17,9 +17,10 @@ declare_id!("BHz6MJGvo8PJaBFqaxyzgJYdY6o8h1rBgsRrUmnHCU9k");
|
||||||
pub mod solana {
|
pub mod solana {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
|
pub fn initialize(ctx: Context<Initialize>, mint:Pubkey) -> Result<()> {
|
||||||
ctx.accounts.config.owner = ctx.accounts.owner.key();
|
ctx.accounts.config.owner = ctx.accounts.owner.key();
|
||||||
ctx.accounts.config.nonce = 0;
|
ctx.accounts.config.nonce = 0;
|
||||||
|
ctx.accounts.config.mint = mint;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ export async function createWrapped(src:string, target: string, vaa:string){
|
||||||
srcNetwork.tokenBridgeAddress,
|
srcNetwork.tokenBridgeAddress,
|
||||||
signer,
|
signer,
|
||||||
targetNetwork.wormholeChainId,
|
targetNetwork.wormholeChainId,
|
||||||
tryNativeToUint8Array(targetDeployInfo.address, targetNetwork.wormholeChainId)
|
tryNativeToUint8Array(targetDeployInfo.tokenAddress, targetNetwork.wormholeChainId)
|
||||||
);
|
);
|
||||||
console.log(`${src} Network has new PortalWrappedToken for ${target} network at ${foreignAddress}`);
|
console.log(`${src} Network has new PortalWrappedToken for ${target} network at ${foreignAddress}`);
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ export async function balance(src:string, target: string) : Promise<string> {
|
||||||
srcNetwork.tokenBridgeAddress,
|
srcNetwork.tokenBridgeAddress,
|
||||||
signer,
|
signer,
|
||||||
targetNetwork.wormholeChainId,
|
targetNetwork.wormholeChainId,
|
||||||
tryNativeToUint8Array(targetDeploymentInfo.address, targetNetwork.wormholeChainId)
|
tryNativeToUint8Array(targetDeploymentInfo.tokenAddress, targetNetwork.wormholeChainId)
|
||||||
);
|
);
|
||||||
|
|
||||||
const TKN = new ethers.Contract(
|
const TKN = new ethers.Contract(
|
||||||
|
|
|
@ -48,7 +48,6 @@ export async function deploy(src: string){
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
|
|
||||||
// Also initalize the contract
|
// Also initalize the contract
|
||||||
await new Promise((r) => setTimeout(r, 15000)) // wait for the chain to recognize the program
|
|
||||||
//Initalize the Contract
|
//Initalize the Contract
|
||||||
const xmint = new anchor.Program<SolanaTypes>(
|
const xmint = new anchor.Program<SolanaTypes>(
|
||||||
IDL,
|
IDL,
|
||||||
|
@ -61,15 +60,6 @@ export async function deploy(src: string){
|
||||||
const [configAcc, _] = findProgramAddressSync([
|
const [configAcc, _] = findProgramAddressSync([
|
||||||
Buffer.from("config")
|
Buffer.from("config")
|
||||||
], xmint.programId);
|
], xmint.programId);
|
||||||
|
|
||||||
await xmint.methods
|
|
||||||
.initialize()
|
|
||||||
.accounts({
|
|
||||||
config: configAcc,
|
|
||||||
owner: xmint.provider.publicKey,
|
|
||||||
systemProgram: anchor.web3.SystemProgram.programId
|
|
||||||
})
|
|
||||||
.rpc();
|
|
||||||
|
|
||||||
// Deploy the SPL Token for Xmint
|
// Deploy the SPL Token for Xmint
|
||||||
const mint = await createMint(
|
const mint = await createMint(
|
||||||
|
@ -79,6 +69,18 @@ export async function deploy(src: string){
|
||||||
xmint.programId,
|
xmint.programId,
|
||||||
9 // We are using 9 to match the CLI decimal default exactly
|
9 // We are using 9 to match the CLI decimal default exactly
|
||||||
);
|
);
|
||||||
|
await new Promise((r) => setTimeout(r, 15000)) // wait for the chain to recognize the program
|
||||||
|
|
||||||
|
await xmint.methods
|
||||||
|
.initialize(
|
||||||
|
mint
|
||||||
|
)
|
||||||
|
.accounts({
|
||||||
|
config: configAcc,
|
||||||
|
owner: xmint.provider.publicKey,
|
||||||
|
systemProgram: anchor.web3.SystemProgram.programId
|
||||||
|
})
|
||||||
|
.rpc();
|
||||||
|
|
||||||
// Store deploy info
|
// Store deploy info
|
||||||
fs.writeFileSync(`./deployinfo/${src}.deploy.json`, JSON.stringify({
|
fs.writeFileSync(`./deployinfo/${src}.deploy.json`, JSON.stringify({
|
||||||
|
@ -106,7 +108,7 @@ export async function attest(src: string, target:string, address:string = null){
|
||||||
if(!address){
|
if(!address){
|
||||||
address = srcDeployInfo.tokenAddress;
|
address = srcDeployInfo.tokenAddress;
|
||||||
}
|
}
|
||||||
console.log(`Attesting ${address} from ${target} network onto ${src}`);
|
console.log(`Attesting ${address} from ${src} network onto ${target}`);
|
||||||
|
|
||||||
const tx = await attestFromSolana(
|
const tx = await attestFromSolana(
|
||||||
connection,
|
connection,
|
||||||
|
@ -114,9 +116,12 @@ export async function attest(src: string, target:string, address:string = null){
|
||||||
srcNetwork.tokenBridgeAddress,
|
srcNetwork.tokenBridgeAddress,
|
||||||
srcKey.publicKey.toString(),
|
srcKey.publicKey.toString(),
|
||||||
address
|
address
|
||||||
)
|
);
|
||||||
|
tx.partialSign(srcKey);
|
||||||
const attestVaa = await fetchVaa(src, tx, true);
|
const txid = await connection.sendRawTransaction(tx.serialize());
|
||||||
|
console.log("TXID: ", txid);
|
||||||
|
|
||||||
|
const attestVaa = await fetchVaa(src, txid, true);
|
||||||
switch(targetNetwork.type){
|
switch(targetNetwork.type){
|
||||||
case "evm":
|
case "evm":
|
||||||
await evm.createWrapped(target, src, attestVaa);
|
await evm.createWrapped(target, src, attestVaa);
|
||||||
|
@ -132,7 +137,7 @@ export async function attest(src: string, target:string, address:string = null){
|
||||||
* @param tx
|
* @param tx
|
||||||
* @param portal
|
* @param portal
|
||||||
*/
|
*/
|
||||||
async function fetchVaa(src:string, tx, portal:boolean=false):Promise<string>{
|
async function fetchVaa(src:string, tx:string, portal:boolean=false):Promise<string>{
|
||||||
const srcNetwork = config.networks[src];
|
const srcNetwork = config.networks[src];
|
||||||
const srcDeployInfo = JSON.parse(fs.readFileSync(`./deployinfo/${src}.deploy.json`).toString());
|
const srcDeployInfo = JSON.parse(fs.readFileSync(`./deployinfo/${src}.deploy.json`).toString());
|
||||||
const srcKey = anchor.web3.Keypair.fromSecretKey(Uint8Array.from(JSON.parse((fs.readFileSync(`keypairs/${src}.key`).toString())
|
const srcKey = anchor.web3.Keypair.fromSecretKey(Uint8Array.from(JSON.parse((fs.readFileSync(`keypairs/${src}.key`).toString())
|
||||||
|
@ -141,8 +146,16 @@ async function fetchVaa(src:string, tx, portal:boolean=false):Promise<string>{
|
||||||
|
|
||||||
setDefaultWasm("node");
|
setDefaultWasm("node");
|
||||||
const emitterAddr = portal ? await getEmitterAddressSolana(srcNetwork.tokenBridgeAddress) : await getEmitterAddressSolana(srcDeployInfo.address);
|
const emitterAddr = portal ? await getEmitterAddressSolana(srcNetwork.tokenBridgeAddress) : await getEmitterAddressSolana(srcDeployInfo.address);
|
||||||
const seq = parseSequenceFromLogSolana(await connection.getTransaction(tx));
|
let transaction = await connection.getTransaction(tx);
|
||||||
|
let timeElapsed = 0;
|
||||||
|
while (!transaction) {
|
||||||
|
await new Promise((r) => setTimeout(r, 1000)) // wait for the chain to recognize the program
|
||||||
|
transaction = await connection.getTransaction(tx);
|
||||||
|
timeElapsed += 1;
|
||||||
|
}
|
||||||
|
console.log(`VAA from TX(${tx}) found in ${timeElapsed}s`);
|
||||||
|
const seq = parseSequenceFromLogSolana(transaction);
|
||||||
|
console.log("Seq", seq);
|
||||||
await new Promise((r) => setTimeout(r, 5000)); //wait for gaurdian to pick up messsage
|
await new Promise((r) => setTimeout(r, 5000)); //wait for gaurdian to pick up messsage
|
||||||
console.log(
|
console.log(
|
||||||
"Searching for: ",
|
"Searching for: ",
|
||||||
|
@ -186,7 +199,7 @@ export async function createWrapped(src:string, target:string, vaa:string){
|
||||||
connection,
|
connection,
|
||||||
srcNetwork.tokenBridgeAddress,
|
srcNetwork.tokenBridgeAddress,
|
||||||
targetNetwork.wormholeChainId,
|
targetNetwork.wormholeChainId,
|
||||||
tryNativeToUint8Array(targetDeployInfo.address, targetNetwork.wormholeChainId)
|
tryNativeToUint8Array(targetDeployInfo.tokenAddress, targetNetwork.wormholeChainId)
|
||||||
);
|
);
|
||||||
console.log(`${src} Network has new PortalWrappedToken for ${target} network at ${foreignAddress}`);
|
console.log(`${src} Network has new PortalWrappedToken for ${target} network at ${foreignAddress}`);
|
||||||
}
|
}
|
||||||
|
@ -272,7 +285,7 @@ export async function balance(src: string, target: string) : Promise<string>{
|
||||||
connection,
|
connection,
|
||||||
srcNetwork.tokenBridgeAddress,
|
srcNetwork.tokenBridgeAddress,
|
||||||
targetNetwork.wormholeChainId,
|
targetNetwork.wormholeChainId,
|
||||||
tryNativeToUint8Array(targetDeployInfo.address, targetNetwork.wormholeChainId)
|
tryNativeToUint8Array(targetDeployInfo.tokenAddress, targetNetwork.wormholeChainId)
|
||||||
);
|
);
|
||||||
|
|
||||||
const tokenAccountAddress = await getOrCreateAssociatedTokenAccount(
|
const tokenAccountAddress = await getOrCreateAssociatedTokenAccount(
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# Install Deps
|
||||||
|
cd chains/evm && forge install --no-git --no-commit && cd ../../
|
||||||
|
|
||||||
# Deploy the code
|
# Deploy the code
|
||||||
ts-node orchestrator.ts deploy evm0
|
ts-node orchestrator.ts deploy evm0
|
||||||
ts-node orchestrator.ts deploy evm1
|
ts-node orchestrator.ts deploy evm1
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
# Build SOL code
|
# Build SOL code
|
||||||
cd chains/solana && anchor build && cd ../../
|
cd chains/solana && anchor build && cd ../../
|
||||||
|
cd chains/evm && forge install --no-git --no-commit && cd ../../
|
||||||
|
|
||||||
# Deploy the code on EVM0 and SOL0
|
# Deploy the code on EVM0 and SOL0
|
||||||
ts-node orchestrator.ts deploy evm0
|
ts-node orchestrator.ts deploy evm0
|
||||||
ts-node orchestrator.ts deploy sol0
|
ts-node orchestrator.ts deploy sol0
|
||||||
|
|
||||||
|
# Register Apps EVM<>SOL
|
||||||
|
ts-node orchestrator.ts register-app evm0 sol0
|
||||||
|
ts-node orchestrator.ts register-app sol0 evm0
|
||||||
|
|
||||||
# Print Balances for EVM0 and SOL0 Keypairs
|
# Print Balances for EVM0 and SOL0 Keypairs
|
||||||
ts-node orchestrator.ts balance evm0 evm0
|
ts-node orchestrator.ts balance evm0 evm0
|
||||||
ts-node orchestrator.ts balance evm0 sol0
|
ts-node orchestrator.ts balance evm0 sol0
|
||||||
ts-node orchestrator.ts balance sol0 sol0
|
ts-node orchestrator.ts balance sol0 sol0
|
||||||
ts-node orchestrator.ts balance sol0 evm0
|
ts-node orchestrator.ts balance sol0 evm0
|
||||||
|
|
||||||
# Register Apps EVM<>SOL
|
|
||||||
ts-node orchestrator.ts register-app evm0 sol0
|
|
||||||
ts-node orchestrator.ts register-app sol0 evm0
|
|
||||||
|
|
||||||
# Buy SOL0-TOKEN with eth
|
# Buy SOL0-TOKEN with eth
|
||||||
ts-node orchestrator.ts buy-token evm0 sol0 100
|
ts-node orchestrator.ts buy-token evm0 sol0 100
|
||||||
# Print SOL0 Balance
|
# Print SOL0 Balance
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
|
# Rerun solana validator
|
||||||
|
cd ../wormhole-local-validator && npm run solana && cd ../xmint
|
||||||
|
|
||||||
# Deploy the code on EVM0 and SOL0
|
# Deploy the code on EVM0 and SOL0
|
||||||
ts-node orchestrator.ts deploy evm0
|
ts-node orchestrator.ts deploy evm0
|
||||||
ts-node orchestrator.ts deploy sol0
|
ts-node orchestrator.ts deploy sol0
|
||||||
|
|
||||||
|
# Register Apps EVM<>SOL
|
||||||
|
ts-node orchestrator.ts register-app evm0 sol0
|
||||||
|
ts-node orchestrator.ts register-app sol0 evm0
|
||||||
|
|
||||||
# Print Balances for EVM0 and SOL0 Keypairs
|
# Print Balances for EVM0 and SOL0 Keypairs
|
||||||
ts-node orchestrator.ts balance evm0 evm0
|
ts-node orchestrator.ts balance evm0 evm0
|
||||||
ts-node orchestrator.ts balance evm0 sol0
|
ts-node orchestrator.ts balance evm0 sol0
|
||||||
ts-node orchestrator.ts balance sol0 sol0
|
ts-node orchestrator.ts balance sol0 sol0
|
||||||
ts-node orchestrator.ts balance sol0 evm0
|
ts-node orchestrator.ts balance sol0 evm0
|
||||||
|
|
||||||
# Register Apps EVM<>SOL
|
|
||||||
ts-node orchestrator.ts register-app evm0 sol0
|
|
||||||
ts-node orchestrator.ts register-app sol0 evm0
|
|
||||||
|
|
Loading…
Reference in New Issue