Skip to content

Commit

Permalink
Merge pull request #15 from smartcontractkit/gauntlet-erc20
Browse files Browse the repository at this point in the history
Gauntlet Starkgate ERC20 and Argent Account support
  • Loading branch information
RodrigoAD authored May 27, 2022
2 parents 7035f66 + 068e0a4 commit 0f68e02
Show file tree
Hide file tree
Showing 44 changed files with 675 additions and 139 deletions.
4 changes: 3 additions & 1 deletion docs/gauntlet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- [Basic Setup](./getting_started.md#basic-setup)
- [CLI](../../packages-ts/gauntlet-starknet-cli/README.md)
- [Example Contract](../../packages-ts/gauntlet-starknet-example/README.md)
- [Account Contract](../../packages-ts/gauntlet-starknet-account/README.md)
- [OZ Contracts](../../packages-ts/gauntlet-starknet-oz/README.md)
- [Starkgate Contracts](../../packages-ts/gauntlet-starknet-starkgate/README.md)
- [Argent Contracts](../../packages-ts/gauntlet-starknet-argent/README.md)
- [OCR2 Contracts](../../packages-ts/gauntlet-starknet-ocr2/README.md)
- Contribute
31 changes: 31 additions & 0 deletions packages-ts/gauntlet-starknet-argent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Gauntlet Starknet Commands for Argent Contracts

## Account

### Deploy

```
yarn gauntlet argent_account:deploy --network=<NETWORK>
```

Note the contract address. The contract is not configured yet. A signer needs to be specified in it:

### Initialize

```bash
yarn gauntlet argent_account:initialize --network=<NETWORK> <CONTRACT_ADDRESS>
# OR If you already have a private key
yarn gauntlet argent_account:initialize --network=<NETWORK> --publicKey=<PUBLIC_KEY> <CONTRACT_ADDRESS>
```

If no public key is provided, the command will generate a new Keypair and will give the details during the execution.

You need to pay some fee to call initialize, but as this could be the first account wallet you are deploying, use the `--noWallet` option to bypass the fee. This will be soon deprecated

At the end of the process, you will want to include the account contract and the private key to your `.env` configuration file.

```bash
# .env
PRIVATE_KEY=0x...
ACCOUNT=0x...
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@chainlink/gauntlet-starknet-account",
"name": "@chainlink/gauntlet-starknet-argent",
"version": "0.0.1",
"description": "Gauntlet Starknet Account",
"description": "Gauntlet Starknet Argent contracts",
"keywords": [
"typescript",
"cli"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
BeforeExecute,
ExecuteCommandConfig,
ExecutionContext,
makeExecuteCommand,
Validation,
} from '@chainlink/gauntlet-starknet'
import { CATEGORIES } from '../../lib/categories'
import { accountContractLoader } from '../../lib/contracts'

type UserInput = {}

type ContractInput = []

const makeUserInput = async (flags, args): Promise<UserInput> => ({})

const makeContractInput = async (input: UserInput, context: ExecutionContext): Promise<ContractInput> => {
return []
}

const beforeExecute: BeforeExecute<UserInput, ContractInput> = (context, input, deps) => async () => {
deps.logger.info(`About to deploy an Argent Account Contract`)
}

const commandConfig: ExecuteCommandConfig<UserInput, ContractInput> = {
ux: {
category: CATEGORIES.ACCOUNT,
function: 'deploy',
examples: [`${CATEGORIES.ACCOUNT}:deploy --network=<NETWORK>`],
},
makeUserInput,
makeContractInput,
validations: [],
loadContract: accountContractLoader,
hooks: {
beforeExecute,
},
}

export default makeExecuteCommand(commandConfig)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Deploy from './deploy'
import Initialize from './initialize'

export default [Deploy, Initialize]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
AfterExecute,
BeforeExecute,
ExecuteCommandConfig,
makeExecuteCommand,
Validation,
} from '@chainlink/gauntlet-starknet'
import { ec } from 'starknet'
import { CATEGORIES } from '../../lib/categories'
import { accountContractLoader } from '../../lib/contracts'

type UserInput = {
publicKey: string
privateKey?: string
}

type ContractInput = [string, 0]

const makeUserInput = async (flags, args): Promise<UserInput> => {
if (flags.input) return flags.input as UserInput

// If public key is not provided, generate a new address
const keypair = ec.genKeyPair()
const generatedPK = '0x' + keypair.getPrivate('hex')
const pubkey = flags.publicKey || ec.getStarkKey(ec.getKeyPair(generatedPK))
return {
publicKey: pubkey,
privateKey: !flags.publicKey && generatedPK,
}
}

const makeContractInput = async (input: UserInput): Promise<ContractInput> => {
return [input.publicKey, 0]
}

const beforeExecute: BeforeExecute<UserInput, ContractInput> = (context, input, deps) => async () => {
deps.logger.info(`About to deploy an Account Contract with public key ${input.contract[0]}`)
if (input.user.privateKey) {
await deps.prompt(`The generated private key will be shown next, continue?`)
deps.logger.line()

deps.logger.info(`To sign future transactions, store the Private Key`)
deps.logger.info(`PRIVATE_KEY: ${input.user.privateKey}`)

deps.logger.line()
}
}

const afterExecute: AfterExecute<UserInput, ContractInput> = (context, input, deps) => async (result) => {
deps.logger.success(`Account contract located at ${result.responses[0].tx.address}`)
return {
publicKey: input.user.publicKey,
privateKey: input.user.privateKey,
}
}

const commandConfig: ExecuteCommandConfig<UserInput, ContractInput> = {
ux: {
category: CATEGORIES.ACCOUNT,
function: 'initialize',
examples: [`${CATEGORIES.ACCOUNT}:initialize --network=<NETWORK> --publicKey=<ADDRESS> <CONTRACT_ADDRESS>`],
},
makeUserInput,
makeContractInput,
validations: [],
loadContract: accountContractLoader,
hooks: {
beforeExecute,
afterExecute,
},
}

export default makeExecuteCommand(commandConfig)
12 changes: 12 additions & 0 deletions packages-ts/gauntlet-starknet-argent/src/lib/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'fs'
import { CompiledContract, json } from 'starknet'

export enum CONTRACT_LIST {
ACCOUNT = 'argent_account',
}

export const loadContract = (name: CONTRACT_LIST): CompiledContract => {
return json.parse(fs.readFileSync(`${__dirname}/../../artifacts/abi/${name}.json`).toString('ascii'))
}

export const accountContractLoader = () => loadContract(CONTRACT_LIST.ACCOUNT)
5 changes: 4 additions & 1 deletion packages-ts/gauntlet-starknet-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
},
"dependencies": {
"@chainlink/gauntlet-core": "0.3.0",
"@chainlink/gauntlet-starknet-oz": "*",
"@chainlink/gauntlet-starknet-argent": "*",
"@chainlink/gauntlet-starknet-example": "*",
"@chainlink/gauntlet-starknet-ocr2": "*"
"@chainlink/gauntlet-starknet-ocr2": "*",
"@chainlink/gauntlet-starknet-starkgate": "*"
}
}
7 changes: 5 additions & 2 deletions packages-ts/gauntlet-starknet-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import OCR2Commands from '@chainlink/gauntlet-starknet-ocr2'
import ExampleCommands from '@chainlink/gauntlet-starknet-example'
import AccountCommands from '@chainlink/gauntlet-starknet-account'
import OZCommands from '@chainlink/gauntlet-starknet-oz'
import StarkgateCommands from '@chainlink/gauntlet-starknet-starkgate'
import ArgentCommands from '@chainlink/gauntlet-starknet-argent'

import { executeCLI } from '@chainlink/gauntlet-core'
import { existsSync } from 'fs'
import path from 'path'
import { io } from '@chainlink/gauntlet-core/dist/utils'

const commands = {
custom: [...OCR2Commands, ...ExampleCommands, ...AccountCommands],
custom: [...OCR2Commands, ...ExampleCommands, ...OZCommands, ...StarkgateCommands, ...ArgentCommands],
loadDefaultFlags: () => ({}),
abstract: {
findPolymorphic: () => undefined,
Expand Down
21 changes: 21 additions & 0 deletions packages-ts/gauntlet-starknet-oz/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 SmartContract ChainLink, Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Gauntlet Starknet Commands for the Account Contract
# Gauntlet Starknet Commands for the Open Zeppelin Contracts

## Setup an account
## Account

Run the following command:
### Deploy

```bash
yarn gauntlet account:deploy --network=<NETWORK>
Expand Down
32 changes: 32 additions & 0 deletions packages-ts/gauntlet-starknet-oz/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@chainlink/gauntlet-starknet-oz",
"version": "0.0.1",
"description": "Gauntlet Starknet Open Zeppelin Contracts",
"keywords": [
"typescript",
"cli"
],
"main": "./dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/**/*",
"!dist/**/*.test.js"
],
"scripts": {
"gauntlet": "ts-node ./src/index.ts",
"lint": "tsc",
"test": "SKIP_PROMPTS=true jest --runInBand",
"test:coverage": "yarn test --collectCoverage",
"test:ci": "yarn test --ci",
"lint:format": "yarn prettier --check ./src",
"format": "yarn prettier --write ./src",
"clean": "rm -rf ./dist/ ./bin/",
"build": "yarn clean && tsc -b",
"bundle": "yarn build && pkg ."
},
"dependencies": {
"@chainlink/gauntlet-core": "0.3.0",
"@chainlink/gauntlet-starknet": "*",
"starknet": "^3.11.0"
}
}
3 changes: 3 additions & 0 deletions packages-ts/gauntlet-starknet-oz/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Account from './account'

export default [...Account]
36 changes: 36 additions & 0 deletions packages-ts/gauntlet-starknet-oz/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import {
ExecuteCommandInstance,
CommandCtor,
makeWallet,
makeProvider,
Dependencies,
Env,
} from '@chainlink/gauntlet-starknet'

import Commands from './commands'

const registerExecuteCommand = <UI, CI>(
registerCommand: (deps: Dependencies) => CommandCtor<ExecuteCommandInstance<UI, CI>>,
) => {
const deps: Dependencies = {
logger: logger,
prompt: prompt,
makeEnv: (flags) => {
const env: Env = {
providerUrl: process.env.NODE_URL || 'https://alpha4.starknet.io',
pk: process.env.PRIVATE_KEY,
account: process.env.ACCOUNT,
}
return env
},
makeProvider: makeProvider,
makeWallet: makeWallet,
}
return registerCommand(deps)
}

const registeredCommands = Commands.map(registerExecuteCommand)

export { Commands }
export default [...registeredCommands]
5 changes: 5 additions & 0 deletions packages-ts/gauntlet-starknet-oz/src/lib/categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CONTRACT_LIST } from './contracts'

export const CATEGORIES = {
ACCOUNT: CONTRACT_LIST.ACCOUNT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import { CompiledContract, json } from 'starknet'

export enum CONTRACT_LIST {
ACCOUNT = 'account',
ACCOUNT = 'oz_account',
}

export const loadContract = (name: CONTRACT_LIST): CompiledContract => {
Expand Down
9 changes: 9 additions & 0 deletions packages-ts/gauntlet-starknet-oz/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["dist", "**/*.spec.ts", "**/*.test.ts"]
}
21 changes: 21 additions & 0 deletions packages-ts/gauntlet-starknet-starkgate/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 SmartContract ChainLink, Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions packages-ts/gauntlet-starknet-starkgate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Gauntlet Starknet Commands for Starkgate Contracts

## ERC20

### Deploy the contract

```bash
yarn gauntlet starkgate_erc20:deploy --network=<NETWORK> --name=<NAME> --symbol=<SYMBOL> --decimals=<DECIMALS> "--minter=<MINTER_ADDRESS>"
# --minter is optional. If not provided, your default account contract will be used as minter
```

If you want to deploy a LINK contract, just include the `--link` flag:

```bash
yarn gauntlet starkgate_erc20:deploy --network=testnet --link
```

### Mint

```bash
yarn gauntlet starkgate_erc20:mint --network=<NETWORK> --recipient=<RECPIENT_ACCOUNT> --amount=<AMOUNT> <ERC20_CONTRACT_ADDRESS>
```

### Transfer

```bash
yarn gauntlet starkgate_erc20:transfer --network=<NETWORK> --recipient=<RECPIENT_ACCOUNT> --amount=<AMOUNT> <ERC20_CONTRACT_ADDRESS>
```
Loading

0 comments on commit 0f68e02

Please sign in to comment.