Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(svm): restructure utils into modular files under src folder #793

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/svm/addressToPublicKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { evmAddressToPublicKey } from "../../src/SvmUtils";
import { evmAddressToPublicKey } from "../../src/svm";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const argv = yargs(hideBin(process.argv)).option("address", {
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/closeRelayerPdas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PublicKey, SystemProgram } from "@solana/web3.js";
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { calculateRelayEventHashUint8Array, readProgramEvents } from "../../src/SvmUtils";
import { calculateRelayEventHashUint8Array, readProgramEvents } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
7 changes: 2 additions & 5 deletions scripts/svm/executeRebalanceToHubPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ import {

import { getNodeUrl, MerkleTree } from "@uma/common";
import { decodeMessageHeader, getMessages } from "../../test/svm/cctpHelpers";
import {
loadExecuteRelayerRefundLeafParams,
RelayerRefundLeafSolana,
RelayerRefundLeafType,
} from "../../test/svm/utils";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../src/types/svm";
import { loadExecuteRelayerRefundLeafParams } from "../../src/svm";

// Set up Solana provider.
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/executeRebalanceToSpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "../../utils/constants";
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { evmAddressToPublicKey } from "../../src/SvmUtils";
import { evmAddressToPublicKey } from "../../src/svm";
import { MessageTransmitter } from "../../target/types/message_transmitter";
import { TokenMessengerMinter } from "../../target/types/token_messenger_minter";
import { ethers, BigNumber } from "ethers";
Expand Down
6 changes: 3 additions & 3 deletions scripts/svm/fakeFillWithRandomDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
AcrossPlusMessageCoder,
MulticallHandlerCoder,
calculateRelayHashUint8Array,
loadFillV3RelayParams,
sendTransactionWithLookupTable,
} from "../../src/SvmUtils";
import { FillDataParams, FillDataValues } from "../../test/svm/SvmSpoke.common";
import { loadFillV3RelayParams } from "../../test/svm/utils";
} from "../../src/svm";
import { FillDataParams, FillDataValues } from "../../src/types/svm";

// Set up the provider and signer.
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PublicKey, SystemProgram } from "@solana/web3.js";
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { evmAddressToPublicKey } from "../../src/SvmUtils";
import { evmAddressToPublicKey } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/publicKeyToAddress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { publicKeyToEvmAddress } from "../../src/SvmUtils";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { publicKeyToEvmAddress } from "../../src/svm";

const argv = yargs(hideBin(process.argv)).option("publicKey", {
type: "string",
Expand Down
2 changes: 1 addition & 1 deletion scripts/svm/queryDeposits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PublicKey } from "@solana/web3.js";
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { readProgramEvents } from "../../src/SvmUtils";
import { readProgramEvents } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
26 changes: 14 additions & 12 deletions scripts/svm/queryFills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { PublicKey } from "@solana/web3.js";
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { readProgramEvents, strPublicKey } from "../../src/SvmUtils";
import { u8Array32ToInt } from "../../test/svm/utils";
import { readProgramEvents } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down Expand Up @@ -47,27 +46,30 @@ async function queryFills(): Promise<void> {
console.log("No fill events found for the given seed.");
return;
}

console.log("Fill events fetched successfully:");
fillEvents.forEach((event, index) => {
console.log(`Fill Event ${index + 1}:`);
console.table([
{ Property: "inputToken", Value: strPublicKey(event.data.inputToken) },
{ Property: "outputToken", Value: strPublicKey(event.data.outputToken) },
{ Property: "inputToken", Value: new PublicKey(event.data.inputToken).toString() },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why drop strPublicKey helper, we introduced this recently

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

{ Property: "outputToken", Value: new PublicKey(event.data.outputToken).toString() },
{ Property: "inputAmount", Value: event.data.inputAmount.toString() },
{ Property: "outputAmount", Value: event.data.outputAmount.toString() },
{ Property: "repaymentChainId", Value: event.data.repaymentChainId.toString() },
{ Property: "originChainId", Value: event.data.originChainId.toString() },
{ Property: "depositId", Value: event.data.depositId.toString() },
{ Property: "depositIdNum", Value: u8Array32ToInt(event.data.depositId).toString() },
{ Property: "fillDeadline", Value: event.data.fillDeadline.toString() },
{ Property: "exclusivityDeadline", Value: event.data.exclusivityDeadline.toString() },
{ Property: "exclusiveRelayer", Value: strPublicKey(event.data.exclusiveRelayer) },
{ Property: "relayer", Value: strPublicKey(event.data.relayer) },
{ Property: "depositor", Value: strPublicKey(event.data.depositor) },
{ Property: "recipient", Value: strPublicKey(event.data.recipient) },
{ Property: "messageHash", Value: event.data.messageHash.toString() },
{ Property: "updatedRecipient", Value: strPublicKey(event.data.relayExecutionInfo.updatedRecipient) },
{ Property: "updatedMessageHash", Value: event.data.relayExecutionInfo.updatedMessageHash.toString() },
{ Property: "exclusiveRelayer", Value: new PublicKey(event.data.exclusiveRelayer).toString() },
{ Property: "relayer", Value: new PublicKey(event.data.relayer).toString() },
{ Property: "depositor", Value: new PublicKey(event.data.depositor).toString() },
{ Property: "recipient", Value: new PublicKey(event.data.recipient).toString() },
{ Property: "message", Value: event.data.message.toString() },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fill events don't have full message anymore. instead its messageHash

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ye, this will be broken now if used. I think it could be due to a merge issue you had.

{
Property: "updatedRecipient",
Value: new PublicKey(event.data.relayExecutionInfo.updatedRecipient).toString(),
},
{ Property: "updatedMessage", Value: event.data.relayExecutionInfo.updatedMessage.toString() },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatedMessageHash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake when merging/solving conflicts. Fixed now.

{ Property: "updatedOutputAmount", Value: event.data.relayExecutionInfo.updatedOutputAmount.toString() },
{ Property: "fillType", Value: event.data.relayExecutionInfo.fillType },
]);
Expand Down
8 changes: 2 additions & 6 deletions scripts/svm/simpleFakeRelayerRepayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { MerkleTree } from "@uma/common/dist/MerkleTree";
import {
relayerRefundHashFn,
RelayerRefundLeafType,
RelayerRefundLeafSolana,
loadExecuteRelayerRefundLeafParams,
} from "../../test/svm/utils";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../src/types/svm";
import { loadExecuteRelayerRefundLeafParams, relayerRefundHashFn } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand Down
11 changes: 5 additions & 6 deletions scripts/svm/simpleFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
import { SvmSpoke } from "../../target/types/svm_spoke";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { calculateRelayHashUint8Array } from "../../src/SvmUtils";
import { intToU8Array32 } from "../../test/svm/utils";
import { calculateRelayHashUint8Array } from "../../src/svm";

// Set up the provider
const provider = AnchorProvider.env();
Expand All @@ -36,7 +35,7 @@ const argv = yargs(hideBin(process.argv))
.option("inputAmount", { type: "number", demandOption: true, describe: "Input amount" })
.option("outputAmount", { type: "number", demandOption: true, describe: "Output amount" })
.option("originChainId", { type: "string", demandOption: true, describe: "Origin chain ID" })
.option("depositId", { type: "string", demandOption: true, describe: "Deposit ID" })
.option("depositId", { type: "array", demandOption: true, describe: "Deposit ID" })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its too cumbersome to pass array in command line (need to repeat --depositId param for each byte. Better use string and parse it as hex (if it starts with 0x) or number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake when merging/solving conflicts. Fixed now.

.option("fillDeadline", { type: "number", demandOption: false, describe: "Fill deadline" })
.option("exclusivityDeadline", { type: "number", demandOption: false, describe: "Exclusivity deadline" }).argv;

Expand All @@ -50,7 +49,7 @@ async function fillV3Relay(): Promise<void> {
const inputAmount = new BN(resolvedArgv.inputAmount);
const outputAmount = new BN(resolvedArgv.outputAmount);
const originChainId = new BN(resolvedArgv.originChainId);
const depositId = intToU8Array32(new BN(resolvedArgv.depositId));
const depositId = resolvedArgv.depositId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same :) This was a mistake when merging/solving conflicts. Fixed now.

const fillDeadline = resolvedArgv.fillDeadline || Math.floor(Date.now() / 1000) + 60; // Current time + 1 minute
const exclusivityDeadline = resolvedArgv.exclusivityDeadline || Math.floor(Date.now() / 1000) + 30; // Current time + 30 seconds
const message = Buffer.from("");
Expand All @@ -65,7 +64,7 @@ async function fillV3Relay(): Promise<void> {
inputAmount,
outputAmount,
originChainId,
depositId,
depositId: depositId.map((id) => Number(id)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be based on old version. we had it fixed recently

fillDeadline,
exclusivityDeadline,
message,
Expand Down Expand Up @@ -155,7 +154,7 @@ async function fillV3Relay(): Promise<void> {
state: statePda,
signer: signer.publicKey,
instructionParams: program.programId,
mint: outputToken,
mintAccount: outputToken,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be mint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as before, likely due to a merge issue.

relayerTokenAccount: relayerTokenAccount,
recipientTokenAccount: recipientTokenAccount,
fillStatus: fillStatusPda,
Expand Down
3 changes: 2 additions & 1 deletion scripts/svm/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { utils as anchorUtils, BN } from "@coral-xyz/anchor";
import { relayerRefundHashFn, RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../test/svm/utils";
import { BigNumber, ethers } from "ethers";
import { PublicKey } from "@solana/web3.js";
import { MerkleTree } from "@uma/common";
import { RelayerRefundLeafSolana, RelayerRefundLeafType } from "../../../src/types/svm";
import { relayerRefundHashFn } from "../../../src/svm";

export const requireEnv = (name: string): string => {
if (!process.env[name]) throw new Error(`Environment variable ${name} is not set`);
Expand Down
Loading
Loading