Skip to content

Commit

Permalink
native evm to solana + wsol to evm test cases (#58)
Browse files Browse the repository at this point in the history
* native evm to solana + wsol to evm cases

* update solana deployment

* update operating chains
  • Loading branch information
mat1asm authored Oct 1, 2024
1 parent 93c5a13 commit ea42384
Show file tree
Hide file tree
Showing 28 changed files with 986 additions and 91 deletions.
435 changes: 435 additions & 0 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 7 additions & 4 deletions deployment/config/testnet/contracts.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"TbrV3": [
{
"chainId": 10002,
"address": "0x07d3376F77139CBE24F39989A58221c8D16F1032",
"address": "0x3Bc865474FC34dEa988Fd46Af86F4d469F735eb1",
"constructorArgs": [
"0x000000000022D473030F116dDEE9F6B43aC78BA3",
"0xDB5492265f6038831E89f495670FF909aDe94bd9",
"0x466B4Daf328DE4C8b46b78a62867341ECBfA7bc6",
"0xC26b5b530F001e00F67ad7B4f7c33003fA72C65b",
"0x7b79995e5f793a07bc00c21412e50ecae098e7f9",
true
]
Expand Down Expand Up @@ -53,8 +53,11 @@
"TbrV3Proxies": [
{
"chainId": 10002,
"address": "0xb620f38B1211bDB96684576017F66bA9871eb6be",
"constructorArgs": []
"address": "0x77A70bCA55813ec70528184F7Cb02eFeD71D6031",
"constructorArgs": [
"0x3Bc865474FC34dEa988Fd46Af86F4d469F735eb1",
"0x6f9b66c711a46d9c37706396ec8444bf6c8e7b176f9b66c711a46d9c37706396ec8444bf6c8e7b176f9b66c711a46d9c37706396ec8444bf6c8e7b17"
]
},
{
"chainId": 10005,
Expand Down
2 changes: 1 addition & 1 deletion deployment/config/testnet/ecosystem.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"operatingChains": [1, 14, 10004, 10005],
"operatingChains": [1, 14, 10002, 10004, 10005],
"evm": {
"networks": [
{
Expand Down
4 changes: 4 additions & 0 deletions deployment/evm/sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ WALLET_KEY="" # testnet funds
# TBR V3 Deployer

ENV=testnet
WALLET_KEY=ledger # or pk if not using ledger


# Other scripts
SOLANA_RECIPIENT_ADDRESS=BaduLTMLeg5yMerBxrwb4wqbpEqWLgqMuJtKPYWNPn51
SOURCE_CHAIN=10002
INPUT_TOKEN=0x824cb8fc742f8d3300d29f16ca8bee94471169f5 # wsol
Expand Down
186 changes: 148 additions & 38 deletions deployment/evm/test-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getContractAddress,
getEnv,
LoggerFn,
TestTransfer,
} from '../helpers';
import { ethers } from 'ethers';
import { getProvider, runOnEvms, sendTx } from '../helpers/evm';
Expand All @@ -15,24 +16,36 @@ import { solanaOperatingChains } from '../helpers/solana';

const processName = 'att-evm-test-transfer';
const chains = evm.evmOperatingChains();
const targetChains = chains.concat(solanaOperatingChains());
const availableChains = chains.concat(solanaOperatingChains());
const usdcAddresses = {
OptimismSepolia: '0x5fd84259d66Cd46123540766Be93DFE6D43130D7',
Sepolia: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
Celo: ' 0x2F25deB3848C207fc8E0c34035B3Ba7fC157602B',
Solana: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU'
};

/**
* This script expects the following environment variables:
* - WALLET_KEY: private key of the wallet to use for sending transactions
* - SOLANA_RECIPIENT_ADDRESS: Solana address to send tokens to
*/


async function run() {
console.log(`Start ${processName}!`);
const start = process.hrtime.bigint();

await runOnEvms('send-test-transactions', async (chain, signer, logFn) => {
const promises = uniqueTestTransfers.map(async (testTransfer) => {
try {
if (testTransfer.skip) return;
const transfersFromChain = uniqueTestTransfers.filter((testTransfer) => !testTransfer.skip && testTransfer.fromChain === chain.name);
logFn(`Transfers from ${chain.name}: ${transfersFromChain.length}`);

const promises = transfersFromChain.map(async (testTransfer) => {
try {
await sendTestTransaction(
chain,
signer,
logFn,
BigInt(testTransfer.transferredAmount),
Number(testTransfer.gasDropoffAmount),
testTransfer.unwrapIntent === 'true',
testTransfer,
);
} catch (error) {
console.error(`Error executing script for test: ${inspect(testTransfer)}`, error);
Expand All @@ -49,26 +62,28 @@ async function sendTestTransaction(
chain: EvmChainInfo,
signer: ethers.Signer,
log: LoggerFn,
inputAmountInAtomic: bigint,
gasDropoff: number,
unwrapIntent: boolean,
testTransfer: TestTransfer,
): Promise<void> {
try {
const inputToken = getEnv('INPUT_TOKEN');
const inputToken = testTransfer.tokenAddress;
const gasDropoff = Number(testTransfer.gasDropoffAmount);
const inputAmountInAtomic = BigInt(testTransfer.transferredAmount);
const unwrapIntent = testTransfer.unwrapIntent;

console.log({
sourceChain: chain,
inputToken,
inputAmountInAtomic,
unwrapIntent,
gasDropoff,
unwrapIntent
});

console.log(`Operating chain: ${inspect(chain)}`);

const tbrv3ProxyAddress = getContractAddress('TbrV3Proxies', chain.chainId);
const provider = getProvider(chain);
const tbrv3 = new Tbrv3(provider, chain.network, tbrv3ProxyAddress);
const targetChains = availableChains.filter((c) => c.name === testTransfer.toChain);

const promises = await Promise.allSettled(
targetChains
Expand Down Expand Up @@ -107,7 +122,7 @@ async function sendTestTransaction(

return {
args: {
method: 'TransferTokenWithRelay',
method: inputToken ? 'TransferTokenWithRelay' : 'TransferGasTokenWithRelay',
acquireMode: { mode: 'Preapproved' },
inputAmountInAtomic,
gasDropoff,
Expand Down Expand Up @@ -157,43 +172,138 @@ async function sendTestTransaction(
}

run().then(() => console.log('Done!'));

const uniqueTestTransfers = [

const uniqueTestTransfers: TestTransfer[] = [
// EVM to Solana
{
transferredAmount: '1000',
// case A with no gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: 'false',
unwrapIntent: false,
tokenAddress: '0x5fd84259d66Cd46123540766Be93DFE6D43130D7', // USDC
tokenChain: "OptimismSepolia",
fromChain: "OptimismSepolia",
toChain: "Solana",
skip: false,
},
{
transferredAmount: '1000',
gasDropoffAmount: '0',
unwrapIntent: 'true',
skip: false,
// case A with gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0.00001',
unwrapIntent: false,
tokenAddress: '0x5fd84259d66Cd46123540766Be93DFE6D43130D7', // USDC
tokenChain: "OptimismSepolia",
fromChain: "OptimismSepolia",
toChain: "Solana",
skip: true,
},
{
transferredAmount: '1000',
gasDropoffAmount: '10',
unwrapIntent: 'false',
skip: false,
// case B gas token with no gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: false,
tokenChain: "Celo",
fromChain: "Celo",
toChain: "Solana",
skip: true,
},
{
transferredAmount: '1000',
gasDropoffAmount: '10',
unwrapIntent: 'true',
skip: false,
// case B gas token with gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0.00001',
unwrapIntent: false,
tokenChain: "Celo",
fromChain: "Celo",
toChain: "Solana",
skip: true,
},
// check if below cases makes sense
{
transferredAmount: '0',
gasDropoffAmount: '10',
unwrapIntent: 'true',
skip: false,
// case D (native solana token wrapped on evm)
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: false,
tokenAddress: '0x8e62ff4ba9944b4ddff5fc548deab4b22c6ea34e', // wrapped USDC
tokenChain: "Solana",
fromChain: "OptimismSepolia",
toChain: "Solana",
skip: true,
},
{
transferredAmount: '0',
gasDropoffAmount: '10',
unwrapIntent: 'false',
skip: false,
// case D (native solana token wrapped on evm with unwrap)
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: true,
tokenAddress: '0x8e62ff4ba9944b4ddff5fc548deab4b22c6ea34e', // wrapped USDC
tokenChain: "Solana",
fromChain: "OptimismSepolia",
toChain: "Solana",
skip: true,
},

// EVM to EVM
{
// case F with no gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: false,
tokenAddress: '0x5fd84259d66Cd46123540766Be93DFE6D43130D7', // USDC
tokenChain: "OptimismSepolia",
fromChain: "OptimismSepolia",
toChain: "Sepolia",
skip: true,
},
{
// case F with gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0.00001',
unwrapIntent: false,
tokenAddress: '0x5fd84259d66Cd46123540766Be93DFE6D43130D7', // USDC
tokenChain: "OptimismSepolia",
fromChain: "OptimismSepolia",
toChain: "Sepolia",
skip: true,
},
{
// case G gas token with no gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: false,
tokenChain: "Celo",
fromChain: "Celo",
toChain: "Sepolia",
skip: true,
},
{
// case G gas token with gas dropoff
transferredAmount: '1',
gasDropoffAmount: '0.00001',
unwrapIntent: false,
tokenChain: "Celo",
fromChain: "Celo",
toChain: "Sepolia",
skip: true,
},
{
// case H
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: false,
tokenAddress: '0x99d8471E68E67a5ED748Afa806bFcfD7C56Bf63c', // wrapped sepolia USDC on optimisim
tokenChain: "Sepolia",
fromChain: "OptimismSepolia",
toChain: "Sepolia",
skip: true,
},
{
// case H
transferredAmount: '1',
gasDropoffAmount: '0',
unwrapIntent: true,
tokenAddress: '0x99d8471E68E67a5ED748Afa806bFcfD7C56Bf63c', // wrapped sepolia USDC on optimisim
tokenChain: "Sepolia",
fromChain: "OptimismSepolia",
toChain: "Sepolia",
skip: true,
},

];
22 changes: 20 additions & 2 deletions deployment/helpers/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Commitment } from "@solana/web3.js";
import { ChainId } from "@wormhole-foundation/sdk-base";
import { Chain, ChainId } from "@wormhole-foundation/sdk-base";
import { ethers } from "ethers";
import { SolanaSigner } from "./solana";

Expand Down Expand Up @@ -83,4 +83,22 @@ export interface VerificationApiKeys extends ChainConfig {
testnet: string;
};
sourcify?: string;
}
}

export type TestTransfer = {
/**
* Amount to transfer in atomic units
*/
transferredAmount: string;
gasDropoffAmount: string;
unwrapIntent: boolean;
/**
* Optional token address for the transfer,
* if not present the script will call transfer gas token
*/
tokenAddress?: string;
tokenChain: Chain;
fromChain: Chain;
toChain: Chain;
skip: boolean;
};
1 change: 1 addition & 0 deletions deployment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1",
"@solana/spl-token": "^0.4.8",
"@solana/web3.js": "^1.95.3",
"@typechain/ethers-v6": "^0.5.1",
"@wormhole-foundation/sdk-base": "^0.10.7",
Expand Down
Loading

0 comments on commit ea42384

Please sign in to comment.