Skip to content

Commit

Permalink
live test on avalanche
Browse files Browse the repository at this point in the history
  • Loading branch information
kuco23 committed Aug 29, 2024
1 parent 4bca6c7 commit 0bcf282
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 93 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ To deploy the contract and frontend, do the following:
- `yarn cli deploy <investmentInterestBips> <investmentPhaseStartUnix> <retractFeeBips> <retractPhaseEndUnix> --network <avalanche|fuji>`,
- `yarn cli init <liquidityKUCO> <liquidityAVAX> --network <avalanche|fuji>`,
- `yarn hardhat verify <kucocoin-address> <uniswap-address> <investmentInterestBips> <investmentPhaseStartUnix> <retractFeeBips> <retractPhaseEndUnix> --network <avalanche|fuji>`,
- replace `network-info.json` with relevant information about your deploy.
1. Move to `packages/frontend` and do:
- `yarn install`,
- replace the `packages/frontend/ts/config/network.ts` kucocoin address variable with the one from `packages/contracts/deploys.json`
- replace the `<investmentPhaseStartUnix>` and `<retractPhaseEndUnix>` variables inside `packages/frontend/src/ts/config/token.ts`,
- navigate to `src/ts/config/network.ts` and update `network` to the network you deployed on,
- `yarn serve` to see frontend on `localhost:1234`,
- `yarn deploy` to deploy frontend on `gh-pages` (need to set that up on github tho).

> **Note**
> If you change `<investmentInterestBips>` or `<retractFeeBips>` you have to manually find the places in `packages/frontend/index.html` where those values are used (in `kuconomics` section).
> If you change `<investmentInterestBips>` or `<retractFeeBips>` you have to manually find the sections in `packages/frontend/index.html` where those values are directly referenced (in `kuconomics` section).
## Testing

Expand All @@ -36,7 +36,6 @@ You can test the frontend on a locally run avalanche fork, which comes with a fu
1. Set up Metamask and import the `PRIVATE_KEY`. You may need to delete metamask nonce cache to avoid some future errors.
1. In frontend workspace:
- navigate to `src/ts/config/network.ts` and update `NETWORK` to `avalanchefork`,
- navigate to `src/ts/config/token.ts` and update `ADDRESS` to the one displayed after deploying `kucocoin` in step 1,
- run `yarn serve`.

To configure investment and retract periods, you have to also navigate to `src/ts/config/token.ts` and update `START_TRADING_TIME_UNIX` and `END_RETRACT_PERIOD_UNIX` to the values obtained by running
Expand Down
10 changes: 6 additions & 4 deletions packages/contracts/network-info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"avalanchefork": {
"address": "0x1780bCf4103D3F501463AD3414c7f4b654bb7aFd",
"params": ["0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24", "500", "1724364000", "1000", "1724450400"],
"kucocoin": {
"address": "0x1780bCf4103D3F501463AD3414c7f4b654bb7aFd",
"params": ["0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24", "500", "1724364000", "1000", "1724450400"]
},
"uniswapV2Router": {
"address": "0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24",
"params": ["", "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7"]
Expand All @@ -19,8 +21,8 @@
},
"avalanche": {
"kucocoin": {
"address": "",
"params": []
"address": "0x6323C8D0B431c5fAe077ad7f6Aac2724Da18C7Ba",
"params": ["0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24", "500", "1725645600", "1000", "1725991200"]
},
"uniswapV2Router": {
"address": "0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24",
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"fork-avalanche": "yarn hardhat node --fork https://api.avax.network/ext/bc/C/rpc",
"---------- live ----------": "---------- live ----------",
"cli": "yarn ts-node tools/cli.ts",
"kucocoin-deploy": "yarn cli deploy 500 1724788800 1000 1724875200",
"kucocoin-init": "yarn cli init 1000000000000000000000000 100000000000000000",
"verify": "yarn hardhat verify 0x75AF24D9E330984F718BeCa47742fb554b95F568 0xA9992b1Cc07C2338e325870ccFEE73127F3E2b71 500 1724090400 1000 1724176800"
"kucocoin-deploy": "yarn cli deploy 500 1725645600 1000 1725991200",
"kucocoin-init": "yarn cli init 1000000000000000000000000 10000000000000000",
"verify": "yarn hardhat verify 0x6323C8D0B431c5fAe077ad7f6Aac2724Da18C7Ba 0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24 500 1725645600 1000 1725991200"
},
"devDependencies": {
"@ethersproject/keccak256": "^5.7.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/frontend/src/ts/components/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { addKucoCoinToken, requestAccounts, switchNetworkIfNecessary, getAccount
import { popupSuccess, popupError } from './utils'
import { ethereum, globals } from '../shared'
import { walletSelector, refreshWalletInfo } from './wallet'
import { NETWORK } from '../config/network'
import { config } from '../config/main'


declare const window: any
Expand All @@ -21,7 +21,7 @@ export async function attachMetaMask(): Promise<void> {
async function initialMetaMaskStatus(): Promise<void> {
if (ethereum !== undefined) {
const chainId = await getChainId(ethereum)
if (chainId === NETWORK.metamask.chainId) {
if (chainId === config.metamask.chainId) {
const accounts = await getAccounts(ethereum)
if (accounts?.length) {
globals.connectedAccount = accounts[0]
Expand Down Expand Up @@ -67,7 +67,7 @@ function onMetaMaskChange(): void {
if (ethereum === undefined) return
ethereum.on('accountsChanged', async (accounts) => {
const chainId = await getChainId(ethereum!)
if (chainId === NETWORK.metamask.chainId) {
if (chainId === config.metamask.chainId) {
globals.connectedAccount = (accounts as string[])[0]
await updateConnectionDisplay(true)
} else {
Expand All @@ -77,7 +77,7 @@ function onMetaMaskChange(): void {
await refreshWalletInfo(ethereum!)
})
ethereum.on('chainChanged', async chainId => {
if (chainId === NETWORK.metamask.chainId) {
if (chainId === config.metamask.chainId) {
const accounts = await getAccounts(ethereum!)
globals.connectedAccount = accounts[0]
await updateConnectionDisplay(true)
Expand Down
135 changes: 135 additions & 0 deletions packages/frontend/src/ts/config/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
export const KUCOCOIN_ABI = [
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_receiver",
"type": "address"
}
],
"name": "claim",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_receiver",
"type": "address"
}
],
"name": "getInvestedNatOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getPoolReserves",
"outputs": [
{
"internalType": "uint256",
"name": "reserveKuco",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "reserveNat",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_receiver",
"type": "address"
}
],
"name": "invest",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
}
],
"name": "makeTransAction",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "nextPeriod",
"outputs": [
{
"internalType": "uint64",
"name": "",
"type": "uint64"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "reportPeriod",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_receiver",
"type": "address"
}
],
"name": "retract",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
]
6 changes: 3 additions & 3 deletions packages/frontend/src/ts/config/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export const UNDERLINE_CHECK_INTERVAL_MS = 1000
export const WALLET_SLIDE_DURATION_MS = 100

export const PRICE_UPDATE_INTERVAL_MS = 10_000
export const PRICE_PRECISION_DIGITS = 8
export const PRICE_PRECISION_DIGITS = 9
export const PRICE_PRECISION = BigInt(10 ** PRICE_PRECISION_DIGITS)

export const WALLET_INFO_UPDATE_INTERVAL_MS = 10_000
export const WALLET_INFO_UPDATE_OFFSET_S = 2

export const MAX_AVAX_DECIMALS_DISPLAY = 5
export const MAX_KUCOCOIN_DECIMALS_DISPLAY = 4
export const MAX_AVAX_DECIMALS_DISPLAY = 6
export const MAX_KUCOCOIN_DECIMALS_DISPLAY = 6

// dex
export const DEX_FACTOR_BIPS = BigInt(997)
Expand Down
22 changes: 22 additions & 0 deletions packages/frontend/src/ts/config/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { network } from "./network"
import { avalancheforkMetamask, fujiMetamask, avalancheMetamask } from "./metamask"
import { avalancheforkToken, fujiToken, avalancheToken } from "./token"

let metamask = avalancheMetamask
if (network === "fuji") {
metamask = fujiMetamask
} else if (network === "avalanchefork") {
metamask = avalancheforkMetamask
}

let token = avalancheToken
if (network === "fuji") {
token = fujiToken
} else if (network === "avalanchefork") {
token = avalancheforkToken
}

export const config = {
metamask: metamask,
token: token
}
32 changes: 32 additions & 0 deletions packages/frontend/src/ts/config/metamask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const avalancheforkMetamask = {
chainName: 'Avalanche Fork',
chainId: '0x7a69',
nativeCurrency: {
name: 'AvalancheFork',
decimals: 18,
symbol: 'FAVAX'
},
rpcUrls: ['http://127.0.0.1:8545/']
}

export const fujiMetamask = {
chainName: 'Fuji Network C-Chain',
chainId: '0xa869',
nativeCurrency: {
name: 'FUJI',
decimals: 18,
symbol: 'FUJI'
},
rpcUrls: ['https://api.avax-test.network/ext/bc/C/rpc']
}

export const avalancheMetamask = {
chainName: 'Avalanche Network C-Chain',
chainId: '0xa86a',
nativeCurrency: {
name: 'AVAX',
decimals: 18,
symbol: 'AVAX'
},
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc']
}
50 changes: 1 addition & 49 deletions packages/frontend/src/ts/config/network.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1 @@
const FUJI_KUCOCOIN_ADDRESS = "0x6424da4c62a3694CF8bE0Ec6cCd4144a9aBE6Ef4"
const FUJI_UNISWAP_ROUTER_ADDRESS = "0xA9992b1Cc07C2338e325870ccFEE73127F3E2b71"

const fuji = {
metamask: {
chainName: 'Fuji Network C-Chain',
chainId: '0xa869',
nativeCurrency: {
name: 'FUJI',
decimals: 18,
symbol: 'FUJI'
},
rpcUrls: ['https://api.avax-test.network/ext/bc/C/rpc']
},
kucocoin: FUJI_KUCOCOIN_ADDRESS,
snowtrace: `https://testnet.snowtrace.io/address/${FUJI_KUCOCOIN_ADDRESS}/contract/43113/writeContract?chainId=43113`,
uniswap: `https://testnet.snowtrace.io/address/${FUJI_UNISWAP_ROUTER_ADDRESS}/contract/43113/writeContract?chainId=43113#F10`
}

const avalanchefork = {
metamask: {
chainName: 'Avalanche Fork',
chainId: '0x7a69',
nativeCurrency: {
name: 'AvalancheFork',
decimals: 18,
symbol: 'FAVAX'
},
rpcUrls: ['http://127.0.0.1:8545/']
},
kucocoin: '0x1780bCf4103D3F501463AD3414c7f4b654bb7aFd',
snowtrace: '',
uniswap: ''
}

const avalanche = {
metamask: {
chainName: 'Avalanche Network C-Chain',
chainId: '0xa86a',
nativeCurrency: {
name: 'AVAX',
decimals: 18,
symbol: 'AVAX'
},
rpcUrls: ['https://avalanche-mainnet.infura.io']
}
}

export const NETWORK = fuji
export const network: "avalanchefork" | "fuji" | "avalanche" = "avalanche"
Loading

0 comments on commit 0bcf282

Please sign in to comment.