Skip to content

Commit 877c839

Browse files
authored
Evm: Update signer to produce well formed txs for Oasis (#535)
1 parent 18de04c commit 877c839

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

core/base/src/constants/rpc.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const rpcConfig = [[
5151
["Fantom", "https://rpc.ankr.com/fantom_testnet"],
5252
["Celo", "https://alfajores-forno.celo-testnet.org"],
5353
["Solana", "https://api.devnet.solana.com"],
54+
["Oasis", "https://testnet.emerald.oasis.io"],
5455
["Moonbeam", "https://rpc.api.moonbase.moonbeam.network"],
5556
["Sui", "https://fullnode.testnet.sui.io"],
5657
["Aptos", "https://fullnode.testnet.aptoslabs.com/v1"],

examples/src/createWrapped.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,16 @@ import { getSigner } from "./helpers/index.js";
99
const wh = await wormhole("Testnet", [evm, solana]);
1010

1111
// Original Token to Attest
12-
// const token: TokenId = Wormhole.chainAddress(
13-
// "Solana",
14-
// "9rU2jFrzA5zDDmt9yR7vEABvXCUNJ1YgGigdTb9oCaTv",
15-
// );
16-
const token: TokenId = Wormhole.chainAddress(
17-
"Avalanche",
18-
"0x3bE4bce46442F5E85c47257145578E724E40cF97",
19-
);
2012

2113
// grab context and signer
22-
const origChain = wh.getChain(token.chain);
14+
const origChain = wh.getChain("Oasis");
15+
const token = await origChain.getNativeWrappedTokenId();
2316
const { signer: origSigner } = await getSigner(origChain);
2417

2518
// Note: if the VAA is not produced before the attempt to retrieve it times out
2619
// you should set this value to the txid logged in the previous run
2720
let txid = undefined;
2821
// txid = "0x55127b9c8af46aaeea9ef28d8bf91e1aff920422fc1c9831285eb0f39ddca2fe";
29-
// txid = "FPNHIFFUZDVPT5SATZQZZ7DFGZMPCCHEFBCB5EZQJV4RRK3ZYTVA";
30-
// txid = "GWZU432ERFU3NES4MA7IAAP6DX73F5VRSSIWGJVC5JRHOH6UMWEQ";
3122

3223
if (!txid) {
3324
// create attestation from origin chain, the same VAA
@@ -57,7 +48,7 @@ import { getSigner } from "./helpers/index.js";
5748
// Check if its attested and if not
5849
// submit the attestation to the token bridge on the
5950
// destination chain
60-
const chain = "Algorand";
51+
const chain = "Sepolia";
6152
const destChain = wh.getChain(chain);
6253
const { signer } = await getSigner(destChain);
6354

@@ -94,4 +85,4 @@ import { getSigner } from "./helpers/index.js";
9485
}
9586

9687
console.log("Wrapped: ", await waitForIt());
97-
})();
88+
})().catch((e) => console.error(e));

examples/src/helpers/helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export async function getSigner<N extends Network, C extends Chain>(
5858
signer = await cosmwasm.getSigner(await chain.getRpc(), getEnv("COSMOS_MNEMONIC"));
5959
break;
6060
case "Evm":
61-
signer = await evm.getSigner(await chain.getRpc(), getEnv("ETH_PRIVATE_KEY"));
61+
signer = await evm.getSigner(await chain.getRpc(), getEnv("ETH_PRIVATE_KEY"), {
62+
debug: true,
63+
});
6264
break;
6365
case "Algorand":
6466
signer = await algorand.getSigner(await chain.getRpc(), getEnv("ALGORAND_MNEMONIC"));

examples/src/tokenBridge.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { SignerStuff, getSigner, waitLog } from "./helpers/index.js";
4141
// Note: The Token bridge will dedust past 8 decimals
4242
// this means any amount specified past that point will be returned
4343
// to the caller
44-
const amt = "0.001";
44+
const amt = "0.05";
4545

4646
// With automatic set to true, perform an automatic transfer. This will invoke a relayer
4747
// contract intermediary that knows to pick up the transfers

platforms/evm/src/signer.ts

+25-7
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,52 @@ export class EvmNativeSigner<N extends Network, C extends EvmChains = EvmChains>
8989
}
9090

9191
async sign(tx: UnsignedTransaction<N, C>[]): Promise<SignedTx[]> {
92+
const chain = this.chain();
93+
9294
const signed = [];
9395

9496
// default gas limit
9597
const gasLimit = this.opts?.maxGasLimit ?? 500_000n;
9698

99+
let gasPrice = 100_000_000_000n; // 100gwei
97100
let maxFeePerGas = 1_500_000_000n; // 1.5gwei
98101
let maxPriorityFeePerGas = 100_000_000n; // 0.1gwei
102+
99103
// Celo does not support this call
100-
if (this.chain() !== 'Celo') {
104+
if (chain !== 'Celo') {
101105
const feeData = await this._signer.provider!.getFeeData();
106+
gasPrice = feeData.gasPrice ?? gasPrice;
102107
maxFeePerGas = feeData.maxFeePerGas ?? maxFeePerGas;
103108
maxPriorityFeePerGas =
104109
feeData.maxPriorityFeePerGas ?? maxPriorityFeePerGas;
105110
}
106111

112+
// Oasis throws malformed errors unless we
113+
// set it to use legacy transaction parameters
114+
const gasOpts =
115+
chain === 'Oasis'
116+
? {
117+
gasLimit,
118+
gasPrice: gasPrice,
119+
// Hardcode type
120+
type: 0,
121+
}
122+
: {
123+
maxFeePerGas,
124+
maxPriorityFeePerGas,
125+
gasLimit,
126+
};
127+
107128
for (const txn of tx) {
108129
const { transaction, description } = txn;
109130
if (this.opts?.debug)
110131
console.log(`Signing: ${description} for ${this.address()}`);
111132

112133
const t: TransactionRequest = {
113134
...transaction,
114-
...{
115-
maxFeePerGas,
116-
maxPriorityFeePerGas,
117-
gasLimit,
118-
nonce: await this._signer.getNonce(),
119-
},
135+
...gasOpts,
136+
from: this.address(),
137+
nonce: await this._signer.getNonce(),
120138
};
121139

122140
// try {

0 commit comments

Comments
 (0)