Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
code reverted backed to previous commit(listener and mutation for tha…
Browse files Browse the repository at this point in the history
…t removed from backend), router Js client code added

adjusted according to backend setup requirement, listener added of erc20, pair and factory events, figured out all events according all router functions and code added (everything is without testing)
  • Loading branch information
Hammad-Mubeen committed Dec 6, 2021
1 parent b499459 commit 4ceb0ce
Show file tree
Hide file tree
Showing 29 changed files with 3,371 additions and 636 deletions.
137 changes: 135 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ PAIR_CONTRACT_PACKAGE=106dbf09aac7eb0ed2d41f4026fe2d8cd5f492b17c5050db9c519591c6
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=f5b45ffd5273c94befa572ca4b3f05a57892611aa7c668a021eed2be93e9b76e
TOKEN1_CONTRACT=c5afe9ac0deddaf3090603b1cc1b71b9c030218ff97f7c4067a48402803fea16
EXTERNAL_CONTRACT=0A01Dd10Ef3562112818F91af977f10EA12BB4417AdFd9aF0ff4f3824862E3CC

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand All @@ -19,11 +18,12 @@ RECEIVER_ACCOUNT_ONE=017e82abcc9539a01cfd9d63ae8c9c8b3a752a6f75ba1ab148714eea03e
ERC20_WASM_PATH=JsClients/ERC20/wasm/erc20-token.wasm
FACTORY_WASM_PATH=JsClients/FACTORY/wasm/factory.wasm
PAIR_WASM_PATH=JsClients/PAIR/wasm/pair-token.wasm
WASM_PATH=JsClients/ROUTER/wasm/uniswap-v2-router.wasm

ERC20_MASTER_KEY_PAIR_PATH=JsClients/ERC20/keys/
FACTORY_MASTER_KEY_PAIR_PATH=JsClients/FACTORY/keys/
PAIR_MASTER_KEY_PAIR_PATH=JsClients/PAIR/keys/

MASTER_KEY_PAIR_PATH=JsClients/ROUTER/keys/

ERC20_CONTRACT_NAME=erc20
ERC20_TOKEN_NAME=token0
Expand Down Expand Up @@ -71,3 +71,136 @@ SET_TREASURY_FEE_PERCENT_PAYMENT_AMOUNT=5000000000
SET_FEE_TO_PAYMENT_AMOUNT=5000000000
SET_FEE_TO_SETTER_PAYMENT_AMOUNT=5000000000
CREATE_PAIR_PAYMENT_AMOUNT=5000000000



TOKEN_NAME=uniswap-router
TOKEN_SYMBOL=DRAG
TOKEN_META=origin fire,lifetime infinite

FACTORY=c2b7c5cd223a6bdf18ac363ff0d808c92cf3eb95ca3f54264d7285a0aa1a74fe
WCSPR=f08f486ae224a551e0a383e195fa9504d0a70686a11c462f0a8599a75a45bc04
LIBRARY=301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
CONTRACT_NAME=UniswapRouter

CONTRACT_HASH=8ce941b03b71dfbf65261e662fd5b47c78e9156ed4b048acdd33ef1934b26e79
INSTALL_PAYMENT_AMOUNT=200000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
BURN_ONE_PAYMENT_AMOUNT=12000000000
MINT_ONE_META_SIZE=1
MINT_COPIES_META_SIZE=10
MINT_COPIES_COUNT=20
MINT_MANY_META_SIZE=5
MINT_MANY_META_COUNT=5

TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
DEADLINE = 1642699999000

# add_liquidity

TOKEN_A = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
TOKEN_B = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
AMOUNT_A_DESIRED = 500
AMOUNT_B_DESIRED = 600
AMOUNT_A_MIN = 250
AMOUNT_B_MIN = 300


# add_liquidity_cspr
TOKEN = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
AMOUNT_TOKEN_DESIRED = 500
AMOUNT_CSPR_DESIRED = 600
AMOUNT_TOKEN_MIN = 250
AMOUNT_CSPR_MIN = 300



# remove_liquidiy
RL_TOKEN_A = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RL_TOKEN_B = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RL_LIQUIDITY = 500
RL_AMOUNT_A_MIN = 550
RL_AMOUNT_B_MIN = 550
RL_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# remove_liquidiy_cspr
RLC_TOKEN = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RLC_LIQUIDITY = 500
RLC_AMOUNT_TOKEN_MIN = 250
RLC_AMOUNT_CSPR_MIN = 300
RLC_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# remove_liquidity_with_permit

RLWP_TOKEN_A = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RLWP_TOKEN_B = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RLWP_LIQUIDITY = 500
RLWP_AMOUNT_A_MIN = 250
RLWP_AMOUNT_B_MIN = 250
RLWP_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RLWP_APPROVE_MAX = false
RLWP_V = 10
RLWP_R = 100
RLWP_S = 100



# remove_liquidity_cspr_with_permit

RLCWP_TOKEN = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RLCWP_LIQUIDITY = 500
RLCWP_AMOUNT_TOKEN_MIN = 250
RLCWP_AMOUNT_CSPR_MIN = 250
RLCWP_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
RLCWP_APPROVE_MAX = false
RLCWP_V = 10
RLCWP_R = 100
RLCWP_S = 100


# swap_exact_tokens_for_tokens

SETFT_AMOUNT_IN = 500
SETFT_AMOUNT_OUT_MIN = 600

# comma seperated list of paths
SETFT_PATH = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
SETFT_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# swap_tokens_for_exact_tokens
STFET_AMOUNT_OUT = 500
STFET_AMOUNT_IN_MAX = 600
STFET_PATH = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
STFET_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# swap_exact_cspr_for_tokens
SECFT_AMOUNT_OUT_MIN = 250
SECFT_AMOUNT_IN = 400
SECFT_PATH = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
SECFT_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# swap_tokens_for_exact_cspr
STFEC_AMOUNT_OUT = 250
STFEC_AMOUNT_IN_MAX = 300
STFEC_PATH = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
STFEC_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# swap_exact_tokens_for_cspr
SETFC_AMOUNT_IN = 250
SETFC_AMOUNT_OUT_MIN = 350
SETFC_PATH = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
SETFC_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb


# swap_cspr_for_exact_tokens
SCFET_AMOUNT_OUT = 250
SCFET_AMOUNT_IN_MAX = 300
SCFET_PATH = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb,301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
SCFET_TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
46 changes: 23 additions & 23 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CLPublicKey,
CLAccountHash,
CLPublicKeyType,
Contracts,
} from "casper-js-sdk";

const { ERC20Events } = constants;
Expand All @@ -31,7 +32,6 @@ const {
TRANSFER_FROM_AMOUNT,
TOKEN0_CONTRACT,
TOKEN1_CONTRACT,
EXTERNAL_CONTRACT,
PAIR_CONTRACT
} = process.env;

Expand Down Expand Up @@ -80,23 +80,23 @@ const test = async () => {
);
console.log("listener: ",listener);

// await sleep(5 * 1000);
await sleep(5 * 1000);

// let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey);
let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey);

// console.log(`... Account Info: `);
// console.log(JSON.stringify(accountInfo, null, 2));
console.log(`... Account Info: `);
console.log(JSON.stringify(accountInfo, null, 2));

// const contractHash = await utils.getAccountNamedKeyValue(
// accountInfo,
// `${ERC20_CONTRACT_NAME!}_contract_hash`
// );
const contractHash = await utils.getAccountNamedKeyValue(
accountInfo,
`${ERC20_CONTRACT_NAME!}_contract_hash`
);

// console.log(`... Contract Hash: ${contractHash}`);
console.log(`... Contract Hash: ${contractHash}`);

// // // We don't need hash- prefix so i'm removing it
// // //await erc20.setContractHash(contractHash.slice(5));
// await erc20.setContractHash(EXTERNAL_CONTRACT!);
// // We don't need hash- prefix so i'm removing it
// //await erc20.setContractHash(contractHash.slice(5));
await erc20.setContractHash(TOKEN0_CONTRACT!);

// // //name
// // const name = await erc20.name();
Expand Down Expand Up @@ -159,16 +159,16 @@ const test = async () => {
// // console.log(`... Total supply: ${totalSupply}`);

//approve
// const approveDeployHash = await erc20.approve(
// KEYS,
// KEYS.publicKey,
// APPROVE_AMOUNT!,
// APPROVE_PAYMENT_AMOUNT!
// );
// console.log("... Approve deploy hash: ", approveDeployHash);

// await getDeploy(NODE_ADDRESS!, approveDeployHash);
// console.log("... Token approved successfully");
const approveDeployHash = await erc20.approve(
KEYS,
KEYS.publicKey,
APPROVE_AMOUNT!,
APPROVE_PAYMENT_AMOUNT!
);
console.log("... Approve deploy hash: ", approveDeployHash);

await getDeploy(NODE_ADDRESS!, approveDeployHash);
console.log("... Token approved successfully");

// // //transfer
// // const transferDeployHash = await erc20.transfer(
Expand Down
Binary file modified JsClients/ERC20/wasm/erc20-token.wasm
Binary file not shown.
Binary file added JsClients/ERC20/wasm/erc20-tokenevents.wasm
Binary file not shown.
Loading

0 comments on commit 4ceb0ce

Please sign in to comment.