Skip to content

Commit

Permalink
Merge pull request #11 from MystenLabs/ml/authorize-bogo-app
Browse files Browse the repository at this point in the history
[Suins DayOne] Authorize / deauthorize actions for bogo deal
  • Loading branch information
manolisliolios authored Jul 24, 2023
2 parents 0cf7eaa + 18db2b8 commit d067c00
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 15 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/suins-build-tx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
type: choice
options:
- Main package upgrade
- Publish DayOne Package
- DayOne display transfer policy and setup script
- Enable BOGO App
- Disable BOGO App
sui_tools_image:
description: 'image reference of sui_tools'
default: 'mysten/sui-tools:2d985a342263ae224966e871b24beeafe11d782a'
Expand Down Expand Up @@ -111,7 +111,27 @@ jobs:
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm migrations::day_one::setup
cd scripts && pnpm migrations::day_one::setup
- name: Enable DayOne BOGO Deal
if: ${{ inputs.transaction_type == 'Enable BOGO App' }}
env:
NODE_ENV: production
GAS_OBJECT: ${{ inputs.gas_object_id }}
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm migrations::day_one::authorize
- name: Disable DayOne BOGO Deal
if: ${{ inputs.transaction_type == 'Disable BOGO App' }}
env:
NODE_ENV: production
GAS_OBJECT: ${{ inputs.gas_object_id }}
NETWORK: mainnet
ORIGIN: gh_action
run: |
cd scripts && pnpm migrations::day_one::deauthorize
- name: Show Transaction Data (To sign)
run: |
Expand Down
11 changes: 10 additions & 1 deletion packages/suins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ This directory contains the main suins package.
## Mainnet Addresses



- V2: `0xb7004c7914308557f7afbaf0dca8dd258e18e306cb7a45b28019f3d0a693f162`

V2 rev: 2d985a3
V2: `0xb7004c7914308557f7afbaf0dca8dd258e18e306cb7a45b28019f3d0a693f162`
Introduced `uid` & `uid_mut` for `SuinsRegistration` object.


V1 rev: (was testnet)
V1: `0xd22b24490e0bae52676651b4f56660a5ff8022a2576e0089f79b3c88d44e08f0`
Expand All @@ -17,6 +21,11 @@ V1: `0xd22b24490e0bae52676651b4f56660a5ff8022a2576e0089f79b3c88d44e08f0`



- V3: `0x7e1ed011b9e68f5144d9b12f756a3fb34a5a5d71f294629722214ffa92767487`
rev: `d9bcbb2`

Introduces `uid` & `uid_mut` for `SuinsRegistration` object.

rev: `a2af559`
- V2: `0x0cf216d6964d17c08e35bd85d3c57bee7413209c63f659567b7b44ce125bc44f`

Expand Down
33 changes: 33 additions & 0 deletions scripts/airdrop/authorize-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TransactionBlock } from "@mysten/sui.js";
import { executeTx, prepareSigner } from "./helper";
import { addressConfig, mainnetConfig } from "../config/day_one";
import { Network, mainPackage } from "../config/constants";

export const authorizeBogoApp = async (network: Network): Promise<TransactionBlock | void> => {

const suinsPackageConfig = mainPackage[network];
const airdropConfig = network === 'mainnet' ? mainnetConfig : addressConfig;
const tx = new TransactionBlock();

tx.moveCall({
target: `${suinsPackageConfig.packageId}::suins::authorize_app`,
arguments: [
tx.object(suinsPackageConfig.adminCap),
tx.object(suinsPackageConfig.suins),
],
typeArguments: [`${airdropConfig.packageId}::bogo::BogoApp`],
});

// return if we're on multisig execution.
if(airdropConfig.isMainnet) return tx;

const signer = prepareSigner(mainPackage[network].provider);
await executeTx(signer, tx);
}


/*
uncomment any of these when running locally.
*/

// authorizeBogoApp('mainnet');
33 changes: 33 additions & 0 deletions scripts/airdrop/deauthorize-app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TransactionBlock } from "@mysten/sui.js";
import { executeTx, prepareSigner } from "./helper";
import { addressConfig, mainnetConfig } from "../config/day_one";
import { Network, mainPackage } from "../config/constants";

export const deauthorizeBogoApp = async (network: Network): Promise<TransactionBlock | void> => {

const suinsPackageConfig = mainPackage[network];
const airdropConfig = network === 'mainnet' ? mainnetConfig : addressConfig;
const tx = new TransactionBlock();

tx.moveCall({
target: `${suinsPackageConfig.packageId}::suins::deauthorize_app`,
arguments: [
tx.object(suinsPackageConfig.adminCap),
tx.object(suinsPackageConfig.suins),
],
typeArguments: [`${airdropConfig.packageId}::bogo::BogoApp`],
});

// return if we're on multisig execution.
if(airdropConfig.isMainnet) return tx;

const signer = prepareSigner(mainPackage[network].provider);
await executeTx(signer, tx);
}


/*
uncomment any of these when running locally.
*/

// deauthorizeBogoApp('mainnet');
27 changes: 22 additions & 5 deletions scripts/airdrop/helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Connection, Ed25519Keypair, JsonRpcProvider, ObjectId, RawSigner, SuiAddress, SuiTransactionBlockResponse, TransactionArgument, TransactionBlock, bcs, getExecutionStatus, getExecutionStatusGasSummary, getExecutionStatusType, isValidSuiAddress, normalizeSuiAddress, testnetConnection, toB64 }
import { Connection, Ed25519Keypair, ExportedKeypair, JsonRpcProvider, ObjectId, RawSigner, SuiAddress, SuiTransactionBlockResponse, TransactionArgument, TransactionBlock, bcs, fromExportedKeypair, getExecutionStatus, getExecutionStatusGasSummary, getExecutionStatusType, isValidSuiAddress, normalizeSuiAddress, testnetConnection, toB64 }
from "@mysten/sui.js";

import * as blake2 from 'blake2';
import fs from "fs";
import { AirdropConfig, addressConfig, mainnetConfig } from "../config/day_one";
import { Network, mainPackage } from "../config/constants";
import { execSync } from 'child_process';
import { fromHEX } from "@mysten/bcs";

export const MAX_MINTS_PER_TRANSACTION = 2_000;
export const TOTAL_RANDOM_ADDRESSES = 48 * MAX_MINTS_PER_TRANSACTION; // attempt with 95K.
Expand All @@ -17,13 +18,17 @@ export const executeTx = async (signer: RawSigner, tx: TransactionBlock, options
chunkNum: number,
failedChunks: number[]
}) => {

const requestOptions = options?.isAirdropExecution ? {
showEffects: true
} : {
showObjectChanges: true,
showEffects: true
}
return signer
.signAndExecuteTransactionBlock({
transactionBlock: tx,
options: {
showObjectChanges: true,
showEffects: true,
},
options: requestOptions,
})
.then(function (res) {
if (!(options?.isAirdropExecution)) {
Expand Down Expand Up @@ -124,6 +129,18 @@ export const prepareSigner = (provider: JsonRpcProvider): RawSigner => {
return new RawSigner(keypair, provider);
}

export const prepareSignerFromPrivateKey = (network: Network) => {
const privateKey = process.env.PRIVATE_KEY || '';
if (!privateKey) throw new Error(`ERROR: Private key not exported or exported wrong! Please run 'export PRIVATE_KEY="<mnemonic>"'`);
const keyPair: ExportedKeypair = {
schema: 'ED25519',
privateKey: toB64(fromHEX(privateKey)),
};

const config = mainPackage[network];
return new RawSigner(fromExportedKeypair(keyPair), config.provider);
}

// converts an array of addresses to a buffer using the `buffer` module.
export const addressesToBuffer = (tx: TransactionBlock,
batch: string[], config: AirdropConfig): TransactionArgument => {
Expand Down
14 changes: 10 additions & 4 deletions scripts/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Connection, JsonRpcProvider, ObjectId, SuiAddress } from "@mysten/sui.js"
import { Connection, JsonRpcProvider, ObjectId, SuiAddress, testnetConnection } from "@mysten/sui.js"

export type Network = 'mainnet' | 'testnet'

Expand All @@ -10,6 +10,8 @@ export type PackageInfo = {
publisherId:ObjectId;
adminAddress: SuiAddress;
provider: JsonRpcProvider;
adminCap: ObjectId;
suins: ObjectId;
}

export const mainPackage: Config = {
Expand All @@ -18,15 +20,19 @@ export const mainPackage: Config = {
upgradeCap: '0x9cda28244a0d0de294d2b271e772a9c33eb47d316c59913d7369b545b4af098c',
publisherId: '0x7339f23f06df3601167d67a31752781d307136fd18304c48c928778e752caae1',
adminAddress: '0xa81a2328b7bbf70ab196d6aca400b5b0721dec7615bf272d95e0b0df04517e72',
adminCap: '0x3f8d702d90c572b60ac692fb5074f7a7ac350b80d9c59eab4f6b7692786cae0a',
suins: '0x6e0ddefc0ad98889c04bab9639e512c21766c5e6366f89e696956d9be6952871',
provider: new JsonRpcProvider(new Connection({
fullnode: 'https://suins-rpc.mainnet.sui.io'
}))

},
testnet: {
packageId: '0x48380438a54490534efcd9bea3c48038faf7f386f5a80b647314972a177a242a',
publisherId: '0xf9953e8250dc19d5455e037bbe40a21ecb605871442af23f7b0399076d90bc53',
adminAddress: '0xfe09cf0b3d77678b99250572624bf74fe3b12af915c5db95f0ed5d755612eb68',
packageId: '0x701b8ca1c40f11288a1ed2de0a9a2713e972524fbab748a7e6c137225361653f',
publisherId: '0xd12afb9b5e4a8dc875d22fc927e78952dc9bd84730b33c02e9fd30949c100e38',
adminAddress: '0x7bdfc33239bd05af27d6989cee5455da4bc69ed4cfab5d178434a96ff412514a',
adminCap: '0xadc8b4c3fa0cc022e995968e06fca1d4a47f782f7bb0e88c52730eca77cdae03',
suins: '0xedc672fadedee348108618da7555f771d4fec8d3331779a8411ff8184aded726',
provider: new JsonRpcProvider(new Connection({
fullnode: 'https://suins-rpc.testnet.sui.io:443'
}))
Expand Down
6 changes: 4 additions & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"transactions::main_package::upgrade": "ts-node transactions/main_package_upgrade.ts",
"transactions::day_one::publish": "ts-node transactions/publish_day_one.ts",
"migrations::day_one::setup": "ts-node transactions/setup_display_tp_and_mints.ts"
"migrations::day_one::authorize": "ts-node transactions/authorize_bogo_app.ts",
"migrations::day_one::deauthorize": "ts-node transactions/deauthorize_bogo_app.ts"

},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@mysten/bcs": "^0.7.3",
"@mysten/kiosk": "^0.3.3",
"@mysten/sui.js": "^0.37.1",
"@types/blake2": "^4.0.1",
Expand Down
3 changes: 3 additions & 0 deletions scripts/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions scripts/transactions/authorize_bogo_app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import dotenv from "dotenv";
dotenv.config();
import { prepareMultisigTx } from "../airdrop/helper";
import { authorizeBogoApp } from "../airdrop/authorize-app";

const authorizeApp = async () => {
// read addresses from file
// convert to batches.
const tx = await authorizeBogoApp('mainnet');

if(!tx) throw new Error("TX not defined");

prepareMultisigTx(tx, 'mainnet');
}

authorizeApp();
19 changes: 19 additions & 0 deletions scripts/transactions/deauthorize_bogo_app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import dotenv from "dotenv";
dotenv.config();
import { prepareMultisigTx } from "../airdrop/helper";
import { deauthorizeBogoApp } from "../airdrop/deauthorize-app";

const deauthorizeApp = async () => {
// read addresses from file
// convert to batches.
const tx = await deauthorizeBogoApp('mainnet');

if(!tx) throw new Error("TX not defined");

prepareMultisigTx(tx, 'mainnet');
}

deauthorizeApp();

0 comments on commit d067c00

Please sign in to comment.