Skip to content

Commit

Permalink
Merge pull request #6 from skip-mev/jw/deploy-instructions
Browse files Browse the repository at this point in the history
add deploy instructions for go fast gateway
  • Loading branch information
thal0x authored Dec 4, 2024
2 parents 5c41bd4 + beeaab6 commit 8421c15
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 25 deletions.
67 changes: 67 additions & 0 deletions DEPLOY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# How to deploy the Go Fast contracts

## Deploying the Cosmwasm contract

### 1. Create a `.env` file in the `cosmwasm` directory with the following:

```
DEPLOYER_MNEMONIC=<your_mnemonic>
```

### 2. Store the contract:

```
npx ts-node scripts/storeContract.ts
```

### 3. Instantiate the contract:

First, update the variables in `scripts/instantiateContract.ts` to match your configuration.

Then, run the following command:

```
npx ts-node scripts/instantiateContract.ts
```

This script will output the contract address, as well as the hex representation of the contract address. Save this hex address for use later.

## Deploying the Solidity contract

### 1. Update `Deploy.s.sol` configuration.

Most of the variables in `Deploy.s.sol` are constants and can be left as is. The only variable that you will need to update is `owner`.

### 2. Deploy the contract.

```
forge script ./script/Deploy.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast
```

## Setting the remote contract (EVM)

In order to submit and settle orders you must make the Solidity contract aware of the Cosmwasm deployment.

### 1. Update `SetRemote.s.sol` configuration.

In `script/SetRemote.s.sol`, update the `remoteContract` variable with the hex address that was logged when the Cosmwasm contract was instantiated. (You'll have to remove the `0x` prefix from the address.)

### 2. Set the remote contract.

```
forge script ./script/SetRemote.s.sol --rpc-url <RPC_URL> --private-key <PRIVATE_KEY> --broadcast
```

## Setting the remote contract (Cosmwasm)

In order to fill orders and request settlements you must make the Cosmwasm contract aware of the Solidity contract.

### 1. Update `setRemote.ts` configuration.

In `cosmwasm/scripts/setRemote.ts`, update the `CONTRACT_ADDRESS` variable with the address of the deployed Solidity contract.

### 2. Set the remote contract.

```
npx ts-node cosmwasm/scripts/setRemote.ts
```
1 change: 1 addition & 0 deletions cosmwasm/contracts/fast-transfer-gateway/src/fills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct FillIndexes<'a> {
pub filler: MultiIndex<'a, Addr, OrderFill, Vec<u8>>,
}

#[allow(clippy::needless_lifetimes)]
impl<'a> IndexList<OrderFill> for FillIndexes<'a> {
fn get_indexes(
&'_ self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from "@cosmjs/stargate";
import { fromBech32 } from "@cosmjs/encoding";
import { instantiateContract, storeContract } from "./lib";
import { instantiateContract } from "./lib";

const GAS_PRICE = GasPrice.fromString("0.025uosmo");
const CHAIN_PREFIX = "osmo";
const RPC_URL = "https://osmosis-rpc.polkachu.com";

const CODE_ID = 1000;

const tokenDenom =
"ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4";
const mailboxAddr =
"osmo1jjf788v9m5pcqghe0ky2hf4llxxe37dqz6609eychuwe3xzzq9eql969h3";
const hookAddr =
"osmo13yswqchwtmv2ln9uz4w3865sfy5k8x0wg9qrv4vxflxjg0kuwwyqqpvqxz";
const remoteDomain = 42161;
const remoteAddr =
"000000000000000000000000F7ceC3d387384bB6cE5792dAb161a65cFaCf8aB4";
"osmo13yswqchwtmv2ln9uz4w3865sfy5k8x0wg9qrv4vxflxjg0kuwwyqqpvqxz";
const localDomain = 875;

interface InstantiateMsg {
token_denom: string;
address_prefix: string;
mailbox_addr: string;
hook_addr: string,
remote_domain: number;
remote_addr: string;
hook_addr: string;
local_domain: number;
}

async function main() {
Expand All @@ -45,37 +44,25 @@ async function main() {

const client = await SigningCosmWasmClient.connectWithSigner(RPC_URL, signer);

// await storeContract(
// client,
// signerAddress,
// "../artifacts/go_fast_transfer_cw-aarch64.wasm",
// GAS_PRICE
// );

const codeId = BigInt(1000);

// console.log(`Code ID: ${codeId}`);

const initMsg: InstantiateMsg = {
token_denom: tokenDenom,
address_prefix: CHAIN_PREFIX,
mailbox_addr: mailboxAddr,
hook_addr: hookAddr,
remote_domain: remoteDomain,
remote_addr: remoteAddr,
local_domain: localDomain,
};

const { address } = await instantiateContract(
client,
signerAddress,
codeId,
BigInt(CODE_ID),
"fast-transfer",
initMsg,
GAS_PRICE
);

console.log(`Contract Address: ${address}`);
console.log(Buffer.from(fromBech32(address).data).toString("hex"));
console.log(`Hex: ${Buffer.from(fromBech32(address).data).toString("hex")}`);
}

main()
Expand Down
75 changes: 75 additions & 0 deletions cosmwasm/scripts/setRemote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import "dotenv/config";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { calculateFee, GasPrice } from "@cosmjs/stargate";
import { padHex } from "viem";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";

const GAS_PRICE = GasPrice.fromString("0.025uosmo");
const CHAIN_PREFIX = "osmo";
const RPC_URL = "https://osmosis-rpc.polkachu.com";

const DOMAIN = 42161;
const CONTRACT_ADDRESS = "0x23Cb6147E5600C23d1fb5543916D3D5457c9B54C";

interface MsgAddRemoteDomain {
domain: number;
address: string;
}

async function main() {
const DEPLOYER_MNEMONIC = process.env.DEPLOYER_MNEMONIC;
if (!DEPLOYER_MNEMONIC) {
throw new Error("DEPLOYER_MNEMONIC is not set");
}

const signer = await DirectSecp256k1HdWallet.fromMnemonic(DEPLOYER_MNEMONIC, {
prefix: CHAIN_PREFIX,
});

const accounts = await signer.getAccounts();
const signerAddress = accounts[0].address;

const client = await SigningCosmWasmClient.connectWithSigner(RPC_URL, signer);

const formattedContractAddress = padHex(CONTRACT_ADDRESS, {
dir: "left",
size: 32,
});

const msgAddRemoteDomain: MsgAddRemoteDomain = {
domain: DOMAIN,
address: formattedContractAddress,
};

const msg = {
typeUrl: MsgExecuteContract.typeUrl,
value: MsgExecuteContract.fromPartial({
sender: signerAddress,
contract: CONTRACT_ADDRESS,
msg: Buffer.from(
JSON.stringify({
add_remote_domain: msgAddRemoteDomain,
})
),
}),
};

const estimatedGas = await client.simulate(signerAddress, [msg], undefined);

const fee = calculateFee(
parseInt((estimatedGas * 1.5).toFixed(0)),
GAS_PRICE
);

const tx = await client.signAndBroadcast(
signerAddress,
[msg],
fee,
undefined
);

console.log("Tx Hash:", tx.transactionHash);
}

main().catch(console.error);
43 changes: 43 additions & 0 deletions cosmwasm/scripts/storeContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "dotenv/config";
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { GasPrice } from "@cosmjs/stargate";
import { storeContract } from "./lib";

const GAS_PRICE = GasPrice.fromString("0.025uosmo");
const CHAIN_PREFIX = "osmo";
const RPC_URL = "https://osmosis-rpc.polkachu.com";

async function main() {
const DEPLOYER_MNEMONIC = process.env.DEPLOYER_MNEMONIC;
if (!DEPLOYER_MNEMONIC) {
throw new Error("DEPLOYER_MNEMONIC is not set");
}

const signer = await DirectSecp256k1HdWallet.fromMnemonic(DEPLOYER_MNEMONIC, {
prefix: CHAIN_PREFIX,
});

const accounts = await signer.getAccounts();
const signerAddress = accounts[0].address;

console.log(`Signer Address: ${signerAddress}`);

const client = await SigningCosmWasmClient.connectWithSigner(RPC_URL, signer);

const { codeId } = await storeContract(
client,
signerAddress,
"../artifacts/go_fast_transfer_cw-aarch64.wasm",
GAS_PRICE
);

console.log(`Code ID: ${codeId}`);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
4 changes: 2 additions & 2 deletions solidity/script/SetRemote.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ contract DeployScript is Script {
function run() public {
vm.startBroadcast();

uint32 remoteDomain = 42161;
bytes32 remoteContract = TypeCasts.addressToBytes32(0x83eFe03da48cF12a258c5bb210097E8b0aB2F61F);
uint32 remoteDomain = 875;
bytes32 remoteContract = hex"000000000000000000000000F7ceC3d387384bB6cE5792dAb161a65cFaCf8aB4";

FastTransferGateway gateway = FastTransferGateway(0x80a428AEd33FeC3867850c75Ad8b6bB0Ec1270cA);

Expand Down

0 comments on commit 8421c15

Please sign in to comment.