-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from smartcontractkit/gauntlet-erc20
Gauntlet Starkgate ERC20 and Argent Account support
- Loading branch information
Showing
44 changed files
with
675 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... | ||
``` |
4 changes: 2 additions & 2 deletions
4
...ts/gauntlet-starknet-account/package.json → ...-ts/gauntlet-starknet-argent/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages-ts/gauntlet-starknet-argent/src/commands/account/deploy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
4 changes: 4 additions & 0 deletions
4
packages-ts/gauntlet-starknet-argent/src/commands/account/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
73 changes: 73 additions & 0 deletions
73
packages-ts/gauntlet-starknet-argent/src/commands/account/initialize.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
6 changes: 3 additions & 3 deletions
6
...es-ts/gauntlet-starknet-account/README.md → packages-ts/gauntlet-starknet-oz/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Account from './account' | ||
|
||
export default [...Account] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
Oops, something went wrong.