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

Move aptos cli/freeze and block cmds #1174

Open
wants to merge 4 commits into
base: goulding/krak/aptops-v2-examples
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions examples/oft-adapter-aptos-move/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ Window is the number of seconds over which the capacity is restored. If the rate
pnpm run lz:sdk:move:adapter-unset-rate-limit --oapp-config move.layerzero.config.ts --to-eid number
```

## Blocklist Wallet

To block or unblock a specific wallet address:

```bash
# To block a wallet
pnpm run lz:sdk:move:adapter-blocklist-wallet --oapp-config move.layerzero.config.ts --wallet-address <your-wallet-address> --block true
```

To unblock a wallet:

```bash
pnpm run lz:sdk:move:adapter-blocklist-wallet --oapp-config move.layerzero.config.ts --wallet-address <your-wallet-address> --block false
```

## Permanently Disable Blocklist

> ⚠️ **Warning**: This will permanently disable the blocklist for the OFT. It is for OFTs that want to demonstrate to their holders that they will never use blocklisting abilities.
Expand Down
1 change: 1 addition & 0 deletions examples/oft-adapter-aptos-move/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"lint:sol": "solhint 'contracts/**/*.sol'",
"lz:sdk:evm:wire": "ts-node scripts/cli.ts --vm evm --op wire",
"lz:sdk:help": "ts-node scripts/cli.ts --op help --filter all",
"lz:sdk:move:adapter-blocklist-wallet": "ts-node scripts/cli.ts --vm move --op adapter-blocklist-wallet",
"lz:sdk:move:adapter-permanently-disable-blocklist": "ts-node scripts/cli.ts --vm move --op adapter-permanently-disable-blocklist",
"lz:sdk:move:adapter-set-fee": "ts-node scripts/cli.ts --vm move --op adapter-set-fee",
"lz:sdk:move:adapter-set-rate-limit": "ts-node scripts/cli.ts --vm move --op adapter-set-rate-limit",
Expand Down
28 changes: 28 additions & 0 deletions examples/oft-aptos-move/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ Window is the number of seconds over which the capacity is restored. If the rate
pnpm run lz:sdk:move:unset-rate-limit --oapp-config move.layerzero.config.ts --to-eid number
```

## Blocklist Wallet

To block or unblock a specific wallet address:

```bash
pnpm run lz:sdk:move:blocklist-wallet --oapp-config move.layerzero.config.ts --wallet-address <wallet-address> --block true
```

To unblock a wallet:

```bash
pnpm run lz:sdk:move:blocklist-wallet --oapp-config move.layerzero.config.ts --wallet-address <wallet-address> --block false
```

This command allows you to add or remove addresses from the blocklist. Blocked addresses will not be able to send or receive tokens.

## Permanently Disable Blocklist

> ⚠️ **Warning**: This will permanently disable the blocklist for the OFT. It is for OFTs that want to demonstrate to their holders that they will never use blocklisting abilities.
Expand All @@ -165,6 +181,18 @@ pnpm run lz:sdk:move:unset-rate-limit --oapp-config move.layerzero.config.ts --t
pnpm run lz:sdk:move:permanently-disable-blocklist
```

## Freeze Wallet

```bash
pnpm run lz:sdk:move:freeze-wallet --oapp-config move.layerzero.config.ts --wallet-address <wallet-address> --freeze true
```

To unfreeze a wallet:

```bash
pnpm run lz:sdk:move:freeze-wallet --oapp-config move.layerzero.config.ts --wallet-address <wallet-address> --freeze false
```

## Permanently Disable Freezing

> ⚠️ **Warning**: This will permanently disable the freezing for the OFT. It is for OFTs that want to demonstrate to their holders that they will never use the freezing ability.
Expand Down
2 changes: 2 additions & 0 deletions examples/oft-aptos-move/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"lint:sol": "solhint 'contracts/**/*.sol'",
"lz:sdk:evm:wire": "ts-node scripts/cli.ts --vm evm --op wire",
"lz:sdk:help": "ts-node scripts/cli.ts --op help --filter all",
"lz:sdk:move:blocklist-wallet": "ts-node scripts/cli.ts --vm move --op blocklist-wallet",
"lz:sdk:move:build": "ts-node scripts/cli.ts --vm move --op build",
"lz:sdk:move:deploy": "ts-node scripts/cli.ts --vm move --op deploy",
"lz:sdk:move:freeze-wallet": "ts-node scripts/cli.ts --vm move --op freeze-wallet",
"lz:sdk:move:init-fa": "ts-node scripts/cli.ts --vm move --op init-fa",
"lz:sdk:move:mint-to-move-oft": "ts-node scripts/cli.ts --vm move --op mint-to-move-oft",
"lz:sdk:move:permanently-disable-blocklist": "ts-node scripts/cli.ts --vm move --op permanently-disable-blocklist",
Expand Down
38 changes: 38 additions & 0 deletions packages/devtools-move/sdk/oft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,44 @@ export class OFT {
}
}

setBlocklistPayload(walletAddress: string, block: boolean, oftType: OFTType): InputGenerateTransactionPayloadData {
return {
function: `${this.oft_address}::${oftType}::set_blocklist`,
functionArguments: [walletAddress, block],
}
}

async isBlocklisted(walletAddress: string, oftType: OFTType): Promise<boolean> {
const result = await this.moveVMConnection.view({
payload: {
function: `${this.oft_address}::${oftType}::is_blocklisted`,
functionArguments: [walletAddress],
},
})
return result[0] as boolean
}

setPrimaryFungibleStoreFrozenPayload(
account: string,
frozen: boolean,
oftType: OFTType
): InputGenerateTransactionPayloadData {
return {
function: `${this.oft_address}::${oftType}::set_primary_fungible_store_frozen`,
functionArguments: [account, frozen],
}
}

async isPrimaryFungibleStoreFrozen(account: string, oftType: OFTType): Promise<boolean> {
const result = await this.moveVMConnection.view({
payload: {
function: `${this.oft_address}::${oftType}::is_primary_fungible_store_frozen`,
functionArguments: [account],
},
})
return result[0] as boolean
}

async signSubmitAndWaitForTx(transaction: SimpleTransaction) {
const signedTransaction = await this.moveVMConnection.signAndSubmitTransaction({
signer: this.signer_account,
Expand Down
50 changes: 50 additions & 0 deletions packages/devtools-move/tasks/move/utils/moveVMOftConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,56 @@ export function createPermanentlyDisableFungibleStoreFreezingPayload(oft: OFT):
}
}

export async function createSetBlocklistPayload(
oft: OFT,
oftType: OFTType,
walletAddress: string,
block: boolean
): Promise<TransactionPayload | null> {
const isBlockListed = await oft.isBlocklisted(walletAddress, oftType)
if (isBlockListed === block) {
console.log(`Wallet ${walletAddress} is already ${block ? 'blocked' : 'unblocked'}`)
return null
}

const payload = oft.setBlocklistPayload(walletAddress, block, oftType)
diffPrinter(
`Set Blocklist for ${walletAddress} to ${block ? 'blocked' : 'unblocked'}`,
{ block: isBlockListed },
{ block: block }
)

return {
payload: payload,
description: `Set Blocklist for ${walletAddress} to ${block ? 'blocked' : 'unblocked'}`,
}
}

export async function createSetPrimaryFungibleStoreFrozenPayload(
oft: OFT,
oftType: OFTType,
account: string,
frozen: boolean
): Promise<TransactionPayload | null> {
const isFrozen = await oft.isPrimaryFungibleStoreFrozen(account, oftType)
if (isFrozen === frozen) {
console.log(`\n✅ Account ${account} is already ${frozen ? 'frozen' : 'unfrozen'}\n`)
return null
}

const payload = oft.setPrimaryFungibleStoreFrozenPayload(account, frozen, oftType)
diffPrinter(
`Set Primary Fungible Store Frozen for ${account} to ${frozen ? 'frozen' : 'unfrozen'}`,
{ frozen: isFrozen },
{ frozen: frozen }
)

return {
payload: payload,
description: `Set Primary Fungible Store Frozen for ${account} to ${frozen ? 'frozen' : 'unfrozen'}`,
}
}

function createSerializableExecutorConfig(executorConfig: Uln302ExecutorConfig): ExecutorConfig {
return {
max_message_size: executorConfig.maxMessageSize,
Expand Down
3 changes: 3 additions & 0 deletions packages/oft-move/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export async function attach_oft_move(sdk: AptosEVMCLI) {
await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-adapter-set-fee'))
await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-adapter-set-rate-limit'))
await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-adapter-unset-rate-limit'))
await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-blocklist'))
await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-adapter-blocklist'))
await sdk.extendOperationFromPath(path.join(__dirname, './operations/move-oft-freeze'))
}
36 changes: 36 additions & 0 deletions packages/oft-move/cli/operations/move-oft-adapter-blocklist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { INewOperation } from '@layerzerolabs/devtools-extensible-cli'

import { blocklistWallet } from '../../tasks/blocklistWallet'
import { OFTType } from '@layerzerolabs/devtools-move/sdk/oft'

class AdapterBlocklistWallet implements INewOperation {
vm = 'move'
operation = 'adapter-blocklist-wallet'
description =
'Set the blocklist status of a wallet for your OFT to either true or false, where true blocks the wallet and false unblocks it'
reqArgs = ['wallet_address', 'block']

addArgs = [
{
name: '--block',
arg: {
help: 'true to block, false to unblock',
required: false,
},
},
{
name: '--wallet-address',
arg: {
help: 'wallet address to block or unblock',
required: false,
},
},
]

async impl(args: any): Promise<void> {
await blocklistWallet(args.wallet_address, args.block, OFTType.OFT_ADAPTER_FA)
}
}

const NewOperation = new AdapterBlocklistWallet()
export { NewOperation }
37 changes: 37 additions & 0 deletions packages/oft-move/cli/operations/move-oft-blocklist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { INewOperation } from '@layerzerolabs/devtools-extensible-cli'

import { blocklistWallet } from '../../tasks/blocklistWallet'
import { OFTType } from '@layerzerolabs/devtools-move/sdk/oft'

class BlocklistWallet implements INewOperation {
vm = 'move'
operation = 'blocklist-wallet'
description =
'Set the blocklist status of a wallet for your OFT to either true or false, where true blocks the wallet and false unblocks it'
reqArgs = ['wallet_address', 'block']

addArgs = [
{
name: '--block',
arg: {
help: 'true to block, false to unblock',
required: false,
},
},
{
name: '--wallet-address',
arg: {
help: 'wallet address to block or unblock',
required: false,
},
},
]

async impl(args: any): Promise<void> {
const block = args.block === 'true'
await blocklistWallet(args.wallet_address, block, OFTType.OFT_FA)
}
}

const NewOperation = new BlocklistWallet()
export { NewOperation }
37 changes: 37 additions & 0 deletions packages/oft-move/cli/operations/move-oft-freeze.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { INewOperation } from '@layerzerolabs/devtools-extensible-cli'

import { freezeWallet } from '../../tasks/freezeWallet'
import { OFTType } from '@layerzerolabs/devtools-move/sdk/oft'

class FreezeWallet implements INewOperation {
vm = 'move'
operation = 'freeze-wallet'
description =
'Set the frozen status of a wallet for your OFT to either true or false, where true freezes the wallet and false unfreezes it'
reqArgs = ['wallet_address', 'freeze']

addArgs = [
{
name: '--freeze',
arg: {
help: 'true to freeze, false to unfreeze',
required: false,
},
},
{
name: '--wallet-address',
arg: {
help: 'wallet address to freeze or unfreeze',
required: false,
},
},
]

async impl(args: any): Promise<void> {
const freeze = args.freeze === 'true'
await freezeWallet(args.wallet_address, freeze, OFTType.OFT_FA)
}
}

const NewOperation = new FreezeWallet()
export { NewOperation }
28 changes: 28 additions & 0 deletions packages/oft-move/tasks/blocklistWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getChain, getConnection } from '@layerzerolabs/devtools-move/sdk/moveVMConnectionBuilder'
import { OFT, OFTType } from '@layerzerolabs/devtools-move/sdk/oft'

import { getLzNetworkStage, parseYaml } from '@layerzerolabs/devtools-move/tasks/move/utils/aptosNetworkParser'
import { createSetBlocklistPayload } from '@layerzerolabs/devtools-move/tasks/move/utils/moveVMOftConfigOps'
import { getMoveVMOftAddress, sendAllTxs } from '@layerzerolabs/devtools-move/tasks/move/utils/utils'

async function blocklistWallet(walletAddress: string, block: boolean, oftType: OFTType) {
const { account_address, private_key, network, fullnode, faucet } = await parseYaml()

const chain = getChain(fullnode)
const aptos = getConnection(chain, network, fullnode, faucet)

const lzNetworkStage = getLzNetworkStage(network)
const oftAddress = getMoveVMOftAddress(network, lzNetworkStage)

console.log(`\n🔒 Blocklisting Wallet for ${chain}-${lzNetworkStage} OFT`)
console.log(`\t📝 For: ${oftAddress}\n`)
console.log(`\t${block ? '🚫' : '✅'} Setting wallet ${walletAddress} to ${block ? 'blocked' : 'unblocked'}`)

const oft = new OFT(aptos, oftAddress, account_address, private_key)

const payload = await createSetBlocklistPayload(oft, oftType, walletAddress, block)

sendAllTxs(aptos, oft, account_address, [payload])
}

export { blocklistWallet }
28 changes: 28 additions & 0 deletions packages/oft-move/tasks/freezeWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { getChain, getConnection } from '@layerzerolabs/devtools-move/sdk/moveVMConnectionBuilder'
import { OFT, OFTType } from '@layerzerolabs/devtools-move/sdk/oft'

import { getLzNetworkStage, parseYaml } from '@layerzerolabs/devtools-move/tasks/move/utils/aptosNetworkParser'
import { createSetPrimaryFungibleStoreFrozenPayload } from '@layerzerolabs/devtools-move/tasks/move/utils/moveVMOftConfigOps'
import { getMoveVMOftAddress, sendAllTxs } from '@layerzerolabs/devtools-move/tasks/move/utils/utils'

async function freezeWallet(walletAddress: string, frozen: boolean, oftType: OFTType) {
const { account_address, private_key, network, fullnode, faucet } = await parseYaml()

const chain = getChain(fullnode)
const aptos = getConnection(chain, network, fullnode, faucet)

const lzNetworkStage = getLzNetworkStage(network)
const oftAddress = getMoveVMOftAddress(network, lzNetworkStage)

console.log(`\n🔒 Updating Freeze status of Wallet for ${chain}-${lzNetworkStage} OFT`)
console.log(`\t📝 For: ${oftAddress}\n`)
console.log(`\t${frozen ? '❄️' : '🌡️'} Setting wallet ${walletAddress} to ${frozen ? 'frozen' : 'unfrozen'}`)

const oft = new OFT(aptos, oftAddress, account_address, private_key)

const payload = await createSetPrimaryFungibleStoreFrozenPayload(oft, oftType, walletAddress, frozen)

sendAllTxs(aptos, oft, account_address, [payload])
}

export { freezeWallet }
Loading