Skip to content

Commit

Permalink
Add freeze and unfreeze commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Leonard authored and Robert Leonard committed Jul 9, 2024
1 parent 82e699a commit cb496d4
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 1 deletion.
58 changes: 58 additions & 0 deletions gatekeeper-cli/src/commands/freeze-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
confirmationsFlag,
feesFlag, gatekeeperNetworkFlag,
gatewayTokenAddressFlag,
chainFlag, parseFlagsWithPrivateKey,
privateKeyFlag, gasLimitFlag,
gatewayNetworkAddressFlag,
} from '../utils/oclif/flags'
import {Args, Command, Flags} from '@oclif/core'
import {makeGatewayNetworkTs, makeGatewayTs} from '../utils/oclif/utils'
import { utils, Wallet } from 'ethers';

export default class FreezeToken extends Command {
static description = 'Gatekeeper can freeze tokens they issued';

static examples = [
`$ gateway-eth freeze-token 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
`,
];

static flags = {
help: Flags.help({char: 'h'}),
privateKey: privateKeyFlag(),
gatewayTokenAddress: gatewayTokenAddressFlag(),
gatekeeperNetwork: gatekeeperNetworkFlag(),
gatewayNetworkAddress: gatewayNetworkAddressFlag(),
chain: chainFlag(),
fees: feesFlag(),
gasLimit: gasLimitFlag(),
confirmations: confirmationsFlag(),
};

static args = {
tokenOwner: Args.string({name: 'tokenOwner', required: true, description: 'Owner of the specified gateway token'}),
networkName: Args.string({name: 'networkName', required: true, description: 'Name of the network'}),
}

async run(): Promise<void> {
const {args, flags} = await this.parse(FreezeToken)

const tokenOwner: string = args.tokenOwner
const parsedFlags = parseFlagsWithPrivateKey(flags)


const gatewayNetwork = await makeGatewayNetworkTs(parsedFlags)
const gatewayTokenTs = await makeGatewayTs(parsedFlags)

const networkId = await gatewayNetwork.getNetworkId(utils.formatBytes32String(args.networkName));
const sendableTransaction = await gatewayTokenTs.freeze(tokenOwner, networkId.valueOf() as bigint)

const receipt = await sendableTransaction.wait(flags.confirmations)

this.log(
`Froze gateway token. TxHash: ${receipt.transactionHash}`,
)
}
}

2 changes: 1 addition & 1 deletion gatekeeper-cli/src/commands/refresh-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { utils, Wallet } from 'ethers';

export default class RefreshToken extends Command {
static description = 'Gatekeepers can issue tokens on their respective networks';
static description = 'Gatekeepers can refresh tokens (such as setting a new expire time) on their respective networks';

static examples = [
`$ gateway-eth issue-token 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
Expand Down
58 changes: 58 additions & 0 deletions gatekeeper-cli/src/commands/revoke-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
confirmationsFlag,
feesFlag, gatekeeperNetworkFlag,
gatewayTokenAddressFlag,
chainFlag, parseFlagsWithPrivateKey,
privateKeyFlag, gasLimitFlag,
gatewayNetworkAddressFlag,
} from '../utils/oclif/flags'
import {Args, Command, Flags} from '@oclif/core'
import {makeGatewayNetworkTs, makeGatewayTs} from '../utils/oclif/utils'
import { utils, Wallet } from 'ethers';

export default class RevokeToken extends Command {
static description = 'Gatekeeper can revoke tokens they issued';

static examples = [
`$ gateway-eth revoke-token 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
`,
];

static flags = {
help: Flags.help({char: 'h'}),
privateKey: privateKeyFlag(),
gatewayTokenAddress: gatewayTokenAddressFlag(),
gatekeeperNetwork: gatekeeperNetworkFlag(),
gatewayNetworkAddress: gatewayNetworkAddressFlag(),
chain: chainFlag(),
fees: feesFlag(),
gasLimit: gasLimitFlag(),
confirmations: confirmationsFlag(),
};

static args = {
tokenOwner: Args.string({name: 'tokenOwner', required: true, description: 'Owner of the specified gateway token'}),
networkName: Args.string({name: 'networkName', required: true, description: 'Name of the network'}),
}

async run(): Promise<void> {
const {args, flags} = await this.parse(RevokeToken)

const tokenOwner: string = args.tokenOwner
const parsedFlags = parseFlagsWithPrivateKey(flags)


const gatewayNetwork = await makeGatewayNetworkTs(parsedFlags)
const gatewayTokenTs = await makeGatewayTs(parsedFlags)

const networkId = await gatewayNetwork.getNetworkId(utils.formatBytes32String(args.networkName));
const sendableTransaction = await gatewayTokenTs.revoke(tokenOwner, networkId.valueOf() as bigint)

const receipt = await sendableTransaction.wait(flags.confirmations)

this.log(
`Revoked gateway token. TxHash: ${receipt.transactionHash}`,
)
}
}

65 changes: 65 additions & 0 deletions gatekeeper-cli/src/commands/unfreeze-token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
confirmationsFlag,
feesFlag, gatekeeperNetworkFlag,
gatewayTokenAddressFlag,
chainFlag, parseFlagsWithPrivateKey,
privateKeyFlag, gasLimitFlag,
gatewayNetworkAddressFlag,
} from '../utils/oclif/flags'
import {Args, Command, Flags} from '@oclif/core'
import {makeGatewayNetworkTs, makeGatewayTs} from '../utils/oclif/utils'
import { utils, Wallet } from 'ethers';

export default class UnfreezeToken extends Command {
static description = 'Gatekeeper can unfreeze tokens they issued';

static examples = [
`$ gateway-eth unfreeze-token 0x893F4Be53274353CD3379C87C8fd1cb4f8458F94 -n 123
`,
];

static flags = {
help: Flags.help({char: 'h'}),
privateKey: privateKeyFlag(),
gatewayTokenAddress: gatewayTokenAddressFlag(),
gatekeeperNetwork: gatekeeperNetworkFlag(),
gatewayNetworkAddress: gatewayNetworkAddressFlag(),
chain: chainFlag(),
fees: feesFlag(),
gasLimit: gasLimitFlag(),
confirmations: confirmationsFlag(),
};

static args = {
tokenOwner: Args.string({name: 'tokenOwner', required: true, description: 'Owner of the specified gateway token'}),
networkName: Args.string({name: 'networkName', required: true, description: 'Name of the network'}),
feeSender: Args.string({name: 'feeSender', required: true, description: "Address that will be paying the fee"}),
}

async run(): Promise<void> {
const {args, flags} = await this.parse(UnfreezeToken)

const tokenOwner: string = args.tokenOwner
const parsedFlags = parseFlagsWithPrivateKey(flags)


const gatewayNetwork = await makeGatewayNetworkTs(parsedFlags)
const gatewayTokenTs = await makeGatewayTs(parsedFlags)

const networkId = await gatewayNetwork.getNetworkId(utils.formatBytes32String(args.networkName));
const feeRecipient = (new Wallet(parsedFlags.privateKey)).address

const sendableTransaction = await gatewayTokenTs.unfreeze(
tokenOwner,
networkId.valueOf() as bigint,
{feeRecipient , feeSender: args.feeSender}
)

const receipt = await sendableTransaction.wait(flags.confirmations)

this.log(
`Unfroze gateway token. TxHash: ${receipt.transactionHash}`,
)
}
}

0 comments on commit cb496d4

Please sign in to comment.