Skip to content

Commit 657bbce

Browse files
committed
fix: event emits
1 parent 7ef1da2 commit 657bbce

File tree

6 files changed

+89
-10
lines changed

6 files changed

+89
-10
lines changed

contracts/solana/programs/intent/src/connection.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ pub fn send_message<'info>(
1313
) -> Result<()> {
1414
let conn_sn = config.increment_conn_sn();
1515

16-
event::Message {
16+
emit!(event::Message {
1717
targetNetwork: to,
1818
sn: conn_sn,
1919
msg,
20-
};
20+
});
2121

2222
Ok(())
2323
}

contracts/solana/programs/intent/src/instructions/cancel.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ pub fn resolve_cancel<'info>(
6666
let order_msg = OrderMessage::new(MessageType::FILL, fill.encode());
6767

6868
connection::send_message(config, order.src_nid(), order_msg.encode())?;
69-
event::OrderCancelled {
69+
70+
emit!(event::OrderCancelled {
7071
id: order.id(),
7172
srcNID: order.src_nid(),
72-
};
73+
});
7374

7475
Ok(())
7576
}

contracts/solana/programs/intent/src/instructions/fill.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use crate::{
1515
recv_message::*,
1616
state::*,
1717
types::{
18+
misc::Resolve,
1819
order_fill::OrderFill,
1920
order_message::{MessageType, OrderMessage},
2021
swap_order::SwapOrder,
21-
misc::Resolve,
2222
},
2323
};
2424

@@ -109,10 +109,10 @@ pub fn order_fill<'info>(
109109
let order_msg = OrderMessage::new(MessageType::FILL, fill.encode());
110110
connection::send_message(config, order.dst_nid(), order_msg.encode())?;
111111

112-
event::OrderFilled {
112+
emit!(event::OrderFilled {
113113
id: order.id(),
114114
srcNID: order.src_nid(),
115-
};
115+
});
116116

117117
Ok(())
118118
}
@@ -167,7 +167,7 @@ pub fn resolve_fill(
167167
)?;
168168
}
169169

170-
event::OrderClosed { id: order.id() };
170+
emit!(event::OrderClosed { id: order.id() });
171171

172172
Ok(())
173173
}

contracts/solana/programs/intent/src/instructions/swap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn swap_order(ctx: Context<SwapCtx>, order: SwapOrder) -> Result<()> {
5858
)?;
5959
}
6060

61-
event::SwapIntent {
61+
emit!(event::SwapIntent {
6262
id: order.id(),
6363
emitter: order.emitter(),
6464
srcNID: order.src_nid(),
@@ -70,7 +70,7 @@ pub fn swap_order(ctx: Context<SwapCtx>, order: SwapOrder) -> Result<()> {
7070
toToken: order.to_token(),
7171
toAmount: order.to_amount(),
7272
data: order.data(),
73-
};
73+
});
7474

7575
Ok(())
7676
}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { PublicKey } from "@solana/web3.js";
2+
import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system";
3+
4+
import { TxnHelpers } from "./utils/transaction";
5+
import { IntentPda, intentProgram, wallet, connection } from "./setup";
6+
7+
const txnHelpers = new TxnHelpers(connection, wallet.payer);
8+
9+
const args = process.argv.slice(2);
10+
if (args.length != 2) throw new Error("Invalid arguments");
11+
12+
const networkId = args[0];
13+
const feeHandler = new PublicKey(args[1]);
14+
15+
const initializeContract = async () => {
16+
let config = await intentProgram.account.config.fetchNullable(
17+
IntentPda.config().pda
18+
);
19+
if (!config) {
20+
const initializeIx = await intentProgram.methods
21+
.initialize(networkId, feeHandler)
22+
.signers([wallet.payer])
23+
.accountsStrict({
24+
signer: wallet.publicKey,
25+
systemProgram: SYSTEM_PROGRAM_ID,
26+
config: IntentPda.config().pda,
27+
nativeVaultAccount: IntentPda.vaultNative().pda,
28+
})
29+
.instruction();
30+
31+
const tx = await txnHelpers.buildV0Txn([initializeIx], [wallet.payer]);
32+
const txSig = await connection.sendTransaction(tx);
33+
return txSig;
34+
}
35+
};
36+
37+
initializeContract()
38+
.then(async (res) => {
39+
console.log("Contract initializing");
40+
if (res) await txnHelpers.logParsedTx(res);
41+
console.log("Contract initialized successfully");
42+
})
43+
.catch((err) => {
44+
console.log(err);
45+
});
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { TxnHelpers } from "./utils/transaction";
2+
import { wallet, connection, getRecvMessageIx } from "./setup";
3+
4+
const txnHelpers = new TxnHelpers(connection, wallet.payer);
5+
6+
const args = process.argv.slice(2);
7+
if (args.length != 3) throw new Error("Invalid arguments");
8+
9+
const srcNetwork = args[0];
10+
const connSn = Number(args[1]);
11+
const msg = Buffer.from(args[2], "hex");
12+
13+
const recvMessage = async () => {
14+
const recvMessageIx = await getRecvMessageIx(
15+
srcNetwork,
16+
connSn,
17+
msg,
18+
wallet.publicKey
19+
);
20+
const tx = await txnHelpers.buildV0Txn([recvMessageIx], [wallet.payer]);
21+
const txSig = await connection.sendTransaction(tx);
22+
return txSig;
23+
};
24+
25+
recvMessage()
26+
.then(async (res) => {
27+
console.log("Receive Message");
28+
if (res) await txnHelpers.logParsedTx(res);
29+
console.log("Message received successfully");
30+
})
31+
.catch((err) => {
32+
console.log(err);
33+
});

0 commit comments

Comments
 (0)