Skip to content

Commit

Permalink
[Release] First action (#114)
Browse files Browse the repository at this point in the history
* Add user data in temp proxy, prepare for upgrade

* revert for this PR

* Adds upgrade command

* also add the action..

* Fix action
  • Loading branch information
manolisliolios authored May 13, 2024
1 parent ce9c4fb commit 91d1e53
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 58 deletions.
73 changes: 20 additions & 53 deletions .github/workflows/suins-build-tx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- Disable Free Claims
- Profits to Treasury
- Transfer Reserved Names
- Main package upgrade
- Subdomains V1
sui_tools_image:
description: 'image reference of sui_tools'
default: 'mysten/sui-tools:mainnet'
Expand All @@ -37,40 +37,17 @@ jobs:
run: |
echo ${{ inputs.transaction_type }}
- name: Check out code
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Create client.yaml and keystore
working-directory: .
env:
NETWORK: mainnet
RPC: ${{ inputs.rpc }}
run: |
mkdir sui_config
touch sui_config/sui.keystore
cat <<EOF > sui_config/sui.keystore
[
"AJJqjgjU5B9vG2xV2c5kd51eyLYJ0yuEcSYRjzCKIQhT"
]
EOF
cat <<EOF > sui_config/client.yaml
---
keystore:
File: $HOME/.sui/sui_config/sui.keystore
envs:
- alias: $NETWORK
rpc: "$RPC"
ws: ~
EOF
mkdir $HOME/.sui
cp -r sui_config $HOME/.sui/sui_config
- name: Set up sui environment
working-directory: .
- name: Install Homebrew
run: |
docker pull docker.io/${{ inputs.sui_tools_image }}
docker create --name tmp_cont docker.io/${{ inputs.sui_tools_image }}
docker cp tmp_cont:/usr/local/bin/sui sui
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo "/home/linuxbrew/.linuxbrew/bin" >> $GITHUB_PATH
- name: Install Sui using Homebrew
run: brew install sui

- name: NPM BUILD TX Environment
uses: actions/setup-node@v3
Expand All @@ -85,16 +62,6 @@ jobs:
run: |
pnpm install
- name: Main Package Upgrade
if: ${{ inputs.transaction_type == 'Main package upgrade' }}
env:
NODE_ENV: production
GAS_OBJECT: ${{ inputs.gas_object_id }}
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm transactions::main_package::upgrade
- name: Transfer Reserved Names
if: ${{ inputs.transaction_type == 'Transfer Reserved Names' }}
env:
Expand All @@ -115,16 +82,6 @@ jobs:
run: |
cd scripts && pnpm withdraw:profits
- name: Authorize Basecamp Free Claim
if: ${{ inputs.transaction_type == 'Authorize Basecamp Free Claim' }}
env:
NODE_ENV: production
GAS_OBJECT: ${{ inputs.gas_object_id }}
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm authorize-discounts
- name: Disable Free Claims
if: ${{ inputs.transaction_type == 'Disable Free Claims' }}
env:
Expand Down Expand Up @@ -155,6 +112,16 @@ jobs:
run: |
cd scripts && pnpm create-deepbook-pools
- name: Subdomains V1
if: ${{ inputs.transaction_type == 'Subdomains V1' }}
env:
NODE_ENV: production
GAS_OBJECT: ${{ inputs.gas_object_id }}
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm subdomains::01
- name: Show Transaction Data (To sign)
run: |
cat scripts/tx/tx-data.txt
Expand Down
3 changes: 2 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"eslint:check": "eslint --max-warnings=0 '**/*.{ts,tsx}'",
"eslint:fix": "pnpm run eslint:check --fix",
"lint": "pnpm run eslint:check && pnpm run prettier:check",
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix"
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
"subdomains::01": "pnpm ts-node transactions/subnames/01.ts"
},
"keywords": [],
"author": "",
Expand Down
45 changes: 45 additions & 0 deletions scripts/transactions/subnames/01.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { writeFileSync } from 'fs';
import path from 'path';
import { TransactionBlock } from '@mysten/sui.js/transactions';

import { mainPackage } from '../../config/constants';
import { prepareMultisigTx, upgradePackage } from '../../utils/utils';

const UPGRADE_MANIFEST = `[package]
name = "suins"
version = "0.0.2"
#mainnet
published-at="0xb7004c7914308557f7afbaf0dca8dd258e18e306cb7a45b28019f3d0a693f162"
edition = "2024.beta"
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }
[addresses]
#mainnet
suins = "0x0"
`;

// SPDX-License-Identifier: Apache-2.0
export const firstTransaction = async () => {
const constants = mainPackage.mainnet;
const contractsFolder = path.resolve(__dirname + '../../../../packages');
const txb = new TransactionBlock();

// // Prepares the manifest file for a `suins` package upgrade.
writeFileSync(contractsFolder + '/suins/Move.toml', UPGRADE_MANIFEST);
// upgrade the `suins` package.
upgradePackage(
txb,
contractsFolder + '/suins',
'0xb7004c7914308557f7afbaf0dca8dd258e18e306cb7a45b28019f3d0a693f162',
constants.upgradeCap!,
);

await prepareMultisigTx(txb, constants.adminAddress, 'mainnet');
};

firstTransaction();
44 changes: 40 additions & 4 deletions scripts/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { decodeSuiPrivateKey } from '@mysten/sui.js/cryptography';
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
import { Secp256k1Keypair } from '@mysten/sui.js/keypairs/secp256k1';
import { Secp256r1Keypair } from '@mysten/sui.js/keypairs/secp256r1';
import { TransactionBlock } from '@mysten/sui.js/transactions';
import { TransactionBlock, UpgradePolicy } from '@mysten/sui.js/transactions';
import { fromB64, toB64 } from '@mysten/sui.js/utils';

import { Network } from '../init/packages';
Expand All @@ -20,7 +20,7 @@ export const getActiveAddress = () => {
return execSync(`${SUI} client active-address`, { encoding: 'utf8' }).trim();
};

export const publishPackage = (txb: TransactionBlock, path: string, network: Network) => {
export const publishPackage = (txb: TransactionBlock, path: string) => {
const { modules, dependencies } = JSON.parse(
execFileSync(SUI, ['move', 'build', '--dump-bytecode-as-base64', '--path', path], {
encoding: 'utf-8',
Expand All @@ -40,6 +40,38 @@ export const publishPackage = (txb: TransactionBlock, path: string, network: Net
txb.transferObjects([cap], sender);
};

export const upgradePackage = (
txb: TransactionBlock,
path: string,
packageId: string,
upgradeCapId: string,
) => {
const { modules, dependencies, digest } = JSON.parse(
execFileSync(SUI, ['move', 'build', '--dump-bytecode-as-base64', '--path', path], {
encoding: 'utf-8',
}),
);

const cap = txb.object(upgradeCapId);

const ticket = txb.moveCall({
target: '0x2::package::authorize_upgrade',
arguments: [cap, txb.pure.u8(UpgradePolicy.COMPATIBLE), txb.pure(digest)],
});

const receipt = txb.upgrade({
modules,
dependencies,
packageId,
ticket,
});

txb.moveCall({
target: '0x2::package::commit_upgrade',
arguments: [cap, receipt],
});
};

/// Returns a signer based on the active address of system's sui.
export const getSigner = () => {
if (process.env.PRIVATE_KEY) {
Expand Down Expand Up @@ -96,8 +128,12 @@ export const signAndExecute = async (txb: TransactionBlock, network: Network) =>

/// Builds a transaction (unsigned) and saves it on `setup/tx/tx-data.txt` (on production)
/// or `setup/src/tx-data.local.txt` on mainnet.
export const prepareMultisigTx = async (tx: TransactionBlock, network: Network) => {
const adminAddress = getActiveAddress();
export const prepareMultisigTx = async (
tx: TransactionBlock,
address: string,
network: Network,
) => {
const adminAddress = address ?? getActiveAddress();
const client = getClient(network);
const gasObjectId = process.env.GAS_OBJECT;

Expand Down

0 comments on commit 91d1e53

Please sign in to comment.