Skip to content
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
11 changes: 11 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
LOCAL_DEPLOYMENT_ACCOUNT_PRIVATE_KEY=your_account_pk
BAOBAB_DEPLOYMENT_ACCOUNT_PRIVATE_KEY=your_account_pk
CYPRESS_DEPLOYMENT_ACCOUNT_PRIVATE_KEY=your_account_pk

# Credentials for KAS Klaytn Node API
KAS_ACCESS_KEY=your_access_key
KAS_SECRET_ACCESS_KEY=your_secret_access_key

# URLs for alternative Klaytn Node API
BAOBAB_NODE_URL=http://your.baobab.en:8551
CYPRESS_NODE_URL=http://your.cypress.en:8551
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
.env
privateKeys.js
package-lock.json
test/local-klaytn-deploy
build
build
102 changes: 33 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ If you find any security problems in the source code, please report it to develo

The following packages should be installed before using this source code.

* jq
* git
* docker
* Node v10.21.0
* Truffle v5.1.61
* ganache-cli v6.12.1
* Node v16.11.0

# Package Installation

Please install node packages first.

```bash
$ npm install
$ npm install -g truffle@v5.1.61
$ npm install -g ganache-cli@v6.12.1
```

# How to run Ganache
Expand Down Expand Up @@ -66,97 +63,64 @@ $ npm run test:ganache
$ npm run test:ganache -- ./test/token/KIP7/KIP7.test.js

# To run a test on a local klaytn network, execute the below.
$ npm run test:klaytn
$ npm run test:klaytn -- ./test/token/KIP7/KIP7.test.js
$ npm run test:local
$ npm run test:local -- ./test/token/KIP7/KIP7.test.js
```

# How to Deploy Contracts

Deployment script is in [2_contract_migration.js](./contracts/migrations/2_contract_migration.js) which needs to be
updated in case of adding any additional contracts that supposed to be deployed.

## Deploying a contract to the local network

1. To deploy a contract, please modify [2_contract_migration.js](./contracts/migrations/2_contract_migration.js). The file deploys a KIP7 contract currently.
2. Execute the following command to deploy the local network.
Add `LOCAL_DEPLOYMENT_ACCOUNT_PRIVATE_KEY` into `.env` file (see `.env.sample` for example) and run:

```bash
$ npm run deploy:klaytn
$ npm run deploy:local
```

## Deploying a contract to Baobab

Add `BAOBAB_DEPLOYMENT_ACCOUNT_PRIVATE_KEY` into `.env` file (see `.env.sample` for example).

### Using an EN

Update `privateKey` and `EN URL` in `baobab` of [truffle-config.js](./truffle-config.js).

```js
baobab: {
provider: () => {
return new HDWalletProvider(privateKey, "https://your.baobab.en:8651");
},
network_id: '1001', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice: null
},
Add `BAOBAB_NODE_URL` into `.env` file (see `.env.sample` for example) and run:
```bash
$ npm run deploy:baobab
```

### Using KAS

Also, you can use [KAS](http://www.klaytnapi.com) instead of your own EN. Please refer to `kasBaobab` as shown below.
In this case, you need to update `privateKey`, `accessKeyId`, and `secretAccessKey`.

**NOTE**: As of Feb 2021, "Using KAS" is not supported yet.

```js
const accessKeyId = "ACCESS_KEY";
const secretAccessKey = "SECRET_KEY";
### Using KAS

...
Also, you can use [KAS](http://www.klaytnapi.com) instead of your own EN. You need to create the `.env` file (see
`.env.sample` for example) and fill in the following environmental variables: `BAOBAB_DEPLOYMENT_ACCOUNT_PRIVATE_KEY`,
`KAS_ACCESS_KEY` and `KAS_SECRET_ACCESS_KEY`.

kasBaobab: {
provider: () => {
option.headers['x-chain-id'] = '1001';
return new HDWalletProvider(privateKey, new Caver.providers.HttpProvider("https://node-api.klaytnapi.com/v1/klaytn", option))
},
network_id: '1001', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice:'25000000000'
},
```bash
$ npm run deploy:kasBaobab
```

## Deploying a contract to Cypress

Add `CYPRESS_DEPLOYMENT_ACCOUNT_PRIVATE_KEY` into `.env` file (see `.env.sample` for example).

### Using an EN
Update `privateKey` and `EN URL` in `baobab` of [truffle-config.js](./truffle-config.js).

```js
cypress: {
provider: () => new HDWalletProvider(privateKey, "https://your.cypress.en:8651"),
network_id: '8217', //Klaytn mainnet's network id
gas: '8500000',
gasPrice: null
}
Add `CYPRESS_NODE_URL` into `.env` file (see `.env.sample` for example) and run:
```bash
$ npm run deploy:cypress
```

### Using KAS

Also, you can use [KAS](http://www.klaytnapi.com) instead of your own EN. Please refer to `kasBaobab` as shown below.
In this case, you need to update `privateKey`, `accessKeyId`, and `secretAccessKey`.

**NOTE**: As of Feb 2021, "Using KAS" is not supported yet.
Also, you can use [KAS](http://www.klaytnapi.com) instead of your own EN. Add `KAS_ACCESS_KEY` and
`KAS_SECRET_ACCESS_KEY` into `.env` file (see `.env.sample` for example) and run:

```js
const accessKeyId = "ACCESS_KEY";
const secretAccessKey = "SECRET_KEY";

...
```bash
$ npm run deploy:kasCypress
```

kasCypress: {
provider: () => {
option.headers['x-chain-id'] = '8217';
return new HDWalletProvider(privateKey, new Caver.providers.HttpProvider("https://node-api.klaytnapi.com/v1/klaytn", option))
},
network_id: '8217', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice:'25000000000'
},
```
# How to verify contracts
Submit a request on KlaytnScope support page:
* for Baobab: https://baobab.scope.klaytn.com/contract/submission
* for Cypress: https://scope.klaytn.com/contract/submission
12 changes: 6 additions & 6 deletions migrations/2_contract_migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var forwarder = artifacts.require('Forwarder')
var libAssetData = artifacts.require('LibAssetData')
var libDydxBalance = artifacts.require('LibDydxBalance')
var libOrderTransferSimulation = artifacts.require('LibOrderTransferSimulation')
var libTransactionDecoder = artifacts.require('libTransactionDecoder')
var libTransactionDecoder = artifacts.require('LibTransactionDecoder')
var libFillResults = artifacts.require('LibFillResults')
var libSafeMath = artifacts.require('LibSafeMath')
var libMath = artifacts.require('LibMath')
Expand Down Expand Up @@ -87,12 +87,12 @@ module.exports = async function(deployer) {

await deployer.deploy(forwarder, exchange.address, "0x0000000000000000000000000000000000000000", wklay.address)

console.log({exchange:exchange.address,
erc20Proxy:erc20Proxy.address,
erc721Proxy:erc721Proxy.address,
erc1155Proxy:erc1155Proxy.address,
console.log({exchange:exchange.address,
erc20Proxy:erc20Proxy.address,
erc721Proxy:erc721Proxy.address,
erc1155Proxy:erc1155Proxy.address,
staticCallProxy:staticCallProxy.address,
multiAssetProxy:multiAssetProxy.address,
multiAssetProxy:multiAssetProxy.address,
coordinatorRegistry:coordinatorRegistry.address,
coordinator:coordinator.address,
devUtils:devUtils.address,
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@
"run:klaytn:cleanlog": "find -s ./test -name tee.*.log -delete",
"test:ganache": "truffle test",
"test:klaytn": "truffle test --network klaytn",
"deploy:klaytn": "truffle deploy --network klaytn",
"deploy:local": "truffle deploy --network local",
"deploy:baobab": "truffle deploy --network baobab",
"deploy:cypress": "truffle deploy --network cypress"
"deploy:cypress": "truffle deploy --network cypress",
"deploy:kasCypress": "truffle deploy --network kasCypress",
"deploy:kasBaobab": "truffle deploy --network kasBaobab"
},
"dependencies": {
"caver-js": "^1.5.0",
"caver-js-ext-kas": "^1.0.1",
"dotenv": "^10.0.0",
"truffle-hdwallet-provider-klaytn": "^1.0.13-a"
},
"devDependencies": {
"concurrently": "^5.3.0",
"ganache-cli": "^6.12.1",
"truffle": "^5.1.23",
"openzeppelin-test-helpers": "^0.3.2",
"truffle": "^5.1.61",
"truffle-assertions": "^0.9.2"
}
}
95 changes: 30 additions & 65 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,11 @@
*
*/

// const HDWalletProvider = require('@truffle/hdwallet-provider');
// const infuraKey = "fj4jll3k.....";
//
const fs = require('fs');
const path = require("path");
const HDWalletProvider = require('truffle-hdwallet-provider-klaytn')
const Caver = require('caver-js')
// const mnemonic = fs.readFileSync(".secret").toString().trim();
const dotenv = require('dotenv')

const accessKeyId = "ACCESS_KEY";
const secretAccessKey = "SECRET_KEY";

const HDWalletProvider = require("truffle-hdwallet-provider-klaytn");
const privateKey = "0x123";
const cypressPrivateKey = "0x456";
dotenv.config()

module.exports = {
/**
Expand All @@ -53,16 +44,14 @@ module.exports = {
//
// for ganache
development: {
host: "127.0.0.1", // Localhost (default: none)
host: '127.0.0.1', // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
network_id: '*', // Any network (default: none)
gas: 80000000
},
klaytn: {
local: {
provider: () => {
const pks = JSON.parse(fs.readFileSync(path.resolve(__dirname)+'/privateKeys.js'))

return new HDWalletProvider(pks, "http://localhost:8551", 0, pks.length)
return new HDWalletProvider(process.env.LOCAL_DEPLOYMENT_ACCOUNT_PRIVATE_KEY, 'http://localhost:8551')
},
network_id: '203', //Klaytn baobab testnet's network id
gas: '8500000',
Expand All @@ -72,78 +61,54 @@ module.exports = {
provider: () => {
const option = {
headers: [
{ name: 'Authorization', value: 'Basic ' + Buffer.from(accessKeyId + ':' + secretAccessKey).toString('base64') },
{
name: 'Authorization',
value: 'Basic ' + Buffer.from(process.env.KAS_ACCESS_KEY + ':' + process.env.KAS_SECRET_ACCESS_KEY).toString('base64')
},
{ name: 'x-chain-id', value: '1001' }
],
keepAlive: false,
keepAlive: false
}
return new HDWalletProvider(privateKey, new Caver.providers.HttpProvider("https://node-api.klaytnapi.com/v1/klaytn", option))
return new HDWalletProvider(process.env.BAOBAB_DEPLOYMENT_ACCOUNT_PRIVATE_KEY, new Caver.providers.HttpProvider('https://node-api.klaytnapi.com/v1/klaytn', option))
},
network_id: '1001', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice:'25000000000'
gasPrice: '25000000000'
},
kasCypress: {
provider: () => {
const option = {
headers: [
{ name: 'Authorization', value: 'Basic ' + Buffer.from(accessKeyId + ':' + secretAccessKey).toString('base64') },
{
name: 'Authorization',
value: 'Basic ' + Buffer.from(process.env.KAS_ACCESS_KEY + ':' + process.env.KAS_SECRET_ACCESS_KEY).toString('base64')
},
{ name: 'x-chain-id', value: '8217' }
],
keepAlive: false,
keepAlive: false
}
return new HDWalletProvider(cypressPrivateKey, new Caver.providers.HttpProvider("https://node-api.klaytnapi.com/v1/klaytn", option))
return new HDWalletProvider(process.env.CYPRESS_DEPLOYMENT_ACCOUNT_PRIVATE_KEY, new Caver.providers.HttpProvider('https://node-api.klaytnapi.com/v1/klaytn', option))
},
network_id: '8217', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice:'25000000000'
gasPrice: '25000000000'
},
baobab: {
provider: () => { return new HDWalletProvider(privateKey, "http://your.baobab.en:8551") },
provider: () => {
return new HDWalletProvider(process.env.BAOBAB_DEPLOYMENT_ACCOUNT_PRIVATE_KEY, process.env.BAOBAB_NODE_URL)
},
network_id: '1001', //Klaytn baobab testnet's network id
gas: '8500000',
gasPrice: null
},
cypress: {
provider: () => { return new HDWalletProvider(privateKey, "http://your.cypress.en:8551") },
provider: () => {
return new HDWalletProvider(process.env.CYPRESS_DEPLOYMENT_ACCOUNT_PRIVATE_KEY, process.env.CYPRESS_NODE_URL)
},
network_id: '8217', //Klaytn mainnet's network id
gas: '8500000',
gasPrice: null
}

// development: {
// host: "127.0.0.1", // Localhost (default: none)
// port: 8545, // Standard Ethereum port (default: none)
// network_id: "*", // Any network (default: none)
// },

// Another network with more advanced options...
// advanced: {
// port: 8777, // Custom port
// network_id: 1342, // Custom network
// gas: 8500000, // Gas sent with each transaction (default: ~6700000)
// gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei)
// from: <address>, // Account to send txs from (default: accounts[0])
// websockets: true // Enable EventEmitter interface for web3 (default: false)
// },

// Useful for deploying to a public network.
// NB: It's important to wrap the provider as a function.
// ropsten: {
// provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
// network_id: 3, // Ropsten's id
// gas: 5500000, // Ropsten has a lower block limit than mainnet
// confirmations: 2, // # of confs to wait between deployments. (default: 0)
// timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
// skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
// },

// Useful for private networks
// private: {
// provider: () => new HDWalletProvider(mnemonic, `https://network.io`),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// }
},

// Set default mocha options here, use special reporters etc.
Expand All @@ -154,15 +119,15 @@ module.exports = {
// Configure your compilers
compilers: {
solc: {
version: "0.5.16", // Fetch exact version from solc-bin (default: truffle's version)
version: '0.5.16', // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
settings: { // See the solidity docs for advice about optimization and evmVersion
optimizer: {
enabled: true,
runs: 1000000,
details: { yul: true, deduplicate: true, cse: true, constantOptimizer: true },
details: { yul: true, deduplicate: true, cse: true, constantOptimizer: true }
},
evmVersion: "constantinople"
evmVersion: 'constantinople'
}
}
}
Expand Down