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

Commit

Permalink
coding saving for backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Dec 8, 2021
1 parent 4ceb0ce commit 877dcfb
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 117 deletions.
40 changes: 21 additions & 19 deletions .env
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
NODE_MODE=deployed
DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL
DATABASE_URL_ONLINE=mongodb+srv://admin:[email protected]/V2-graphQL-backend?retryWrites=true&w=majority
DATABASE_URL_ONLINE=mongodb+srv://admin:[email protected]/V2-graphQL-backend-demo?retryWrites=true&w=majority

FACTORY_CONTRACT=735edd4bb553cb8ef4408becbce9e5564a92d97094245c9d2d6ff2bbe6ceda43
PAIR_CONTRACT=c667c7c29947b3500406a79ec47947d7eb320e92a00c68351eaa7c7bc96e3d31
PAIR_CONTRACT_PACKAGE=106dbf09aac7eb0ed2d41f4026fe2d8cd5f492b17c5050db9c519591c6dd7d7c
FACTORY_CONTRACT=A1536f887a6dFB2B2fa00C9beAc21324AaD0F880d36926010e355A1F4C1616ee
PAIR_CONTRACT=8A56313004fFa242eB9D197A232aFf6eE19507847F3151064e5ff334935cf02D
PAIR_CONTRACT_PACKAGE=57f8a52b960485c9c5111b33660cdF29FB543A754ec341caB5829CC49EB644c3
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=f5b45ffd5273c94befa572ca4b3f05a57892611aa7c668a021eed2be93e9b76e
TOKEN1_CONTRACT=c5afe9ac0deddaf3090603b1cc1b71b9c030218ff97f7c4067a48402803fea16
TOKEN0_CONTRACT=39cc3cEE8D8Be3A1B0cDE77d857cAa1d28f3061A54c053da2585CfDFF486b0E1
TOKEN1_CONTRACT=464AB6d2Fad52DB31cD2e11D7F30Ce4E998bd37b4321243925D9846011e0b13B
TOKEN1_CONTRACT_PACKAGE=7D379F70A50458Bd1593E9c1317A7110B1AebBd926E331618f45bFbd4e119B0B

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand All @@ -26,7 +27,7 @@ PAIR_MASTER_KEY_PAIR_PATH=JsClients/PAIR/keys/
MASTER_KEY_PAIR_PATH=JsClients/ROUTER/keys/

ERC20_CONTRACT_NAME=erc20
ERC20_TOKEN_NAME=token0
ERC20_TOKEN_NAME=token1
ERC20_TOKEN_SYMBOL=erc
ERC20_DECIMALS=18
ERC20_TOTAL_SUPPLY=0
Expand All @@ -41,10 +42,10 @@ FACTORY_CONTRACT_NAME=Factory

ERC20_INSTALL_PAYMENT_AMOUNT=170000000000
FACTORY_INSTALL_PAYMENT_AMOUNT=110000000000
PAIR_INSTALL_PAYMENT_AMOUNT=230000000000
PAIR_INSTALL_PAYMENT_AMOUNT=300000000000

MINT_PAYMENT_AMOUNT=5000000000
MINT_AMOUNT=100
MINT_AMOUNT=1000

BURN_PAYMENT_AMOUNT=5000000000
BURN_AMOUNT=5
Expand Down Expand Up @@ -78,12 +79,13 @@ TOKEN_NAME=uniswap-router
TOKEN_SYMBOL=DRAG
TOKEN_META=origin fire,lifetime infinite

FACTORY=c2b7c5cd223a6bdf18ac363ff0d808c92cf3eb95ca3f54264d7285a0aa1a74fe
WCSPR=f08f486ae224a551e0a383e195fa9504d0a70686a11c462f0a8599a75a45bc04
LIBRARY=301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
CONTRACT_NAME=UniswapRouter
FACTORY=A1536f887a6dFB2B2fa00C9beAc21324AaD0F880d36926010e355A1F4C1616ee
WCSPR=bA8f6a73B6D548E2CAe2d572aA2F824BC46A3C06a3BBA10e3d12B015931D3f85
LIBRARY=e0Dae7571C3dc5C957a36422c56BA0ccb8AECEC833F35e32874b75A8Ea8Ac4Db
CONTRACT_NAME=UniSwapRouter

CONTRACT_HASH=8ce941b03b71dfbf65261e662fd5b47c78e9156ed4b048acdd33ef1934b26e79
CONTRACT_HASH=2634C8f75Db583C65b9Beb55aBf8339294F2728Cf05c478fe13B239E7916aa36
PACKAGE_HASH=B51E1CE9a31f948119e5699D24C943Bc16024C81caD1A7dFD9119aFD791eD5C5
INSTALL_PAYMENT_AMOUNT=200000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
Expand All @@ -94,13 +96,13 @@ MINT_COPIES_COUNT=20
MINT_MANY_META_SIZE=5
MINT_MANY_META_COUNT=5

TO = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
DEADLINE = 1642699999000
TO = 39cc3cEE8D8Be3A1B0cDE77d857cAa1d28f3061A54c053da2585CfDFF486b0E1
DEADLINE = 1638974538161

# add_liquidity

TOKEN_A = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
TOKEN_B = 301167268ec00eeb7edf7d12d9419921e15dbd7b145e454d94540aa91c260edb
TOKEN_A = 39cc3cEE8D8Be3A1B0cDE77d857cAa1d28f3061A54c053da2585CfDFF486b0E1
TOKEN_B = 464AB6d2Fad52DB31cD2e11D7F30Ce4E998bd37b4321243925D9846011e0b13B
AMOUNT_A_DESIRED = 500
AMOUNT_B_DESIRED = 600
AMOUNT_A_MIN = 250
Expand All @@ -113,7 +115,7 @@ AMOUNT_TOKEN_DESIRED = 500
AMOUNT_CSPR_DESIRED = 600
AMOUNT_TOKEN_MIN = 250
AMOUNT_CSPR_MIN = 300

ADD_LIQUIDITY_PAYMENT_AMOUNT=20000000000


# remove_liquidiy
Expand Down
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAmYl/IwN4hACVTqvQyFqUb6Xz3ewXk8Kkvq+pnmMtLLw=
MCowBQYDK2VwAyEA9iX2/XqEmzD9Oxj78Pgk5No8MMtqPOVslG73VeXB7wA=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0199897f2303788400954eabd0c85a946fa5f3ddec1793c2a4beafa99e632d2cbc
01f625f6fd7a849b30fd3b18fbf0f824e4da3c30cb6a3ce56c946ef755e5c1ef00
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIHNb3AdH407fuI6D2jQSVh4xwPIl5V2RNr2hB5Ynd3ST
MC4CAQAwBQYDK2VwBCIEIN7jOxtBNk251SUMGNb3UScLr35+K9ehtphiKYPqaxDW
-----END PRIVATE KEY-----
7 changes: 5 additions & 2 deletions JsClients/ERC20/src/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ class ERC20Client {

public async approve(
keys: Keys.AsymmetricKey,
spender: RecipientType,
spender: string,
amount: string,
paymentAmount: string
) {

const _spender = new CLByteArray(
Uint8Array.from(Buffer.from(spender, "hex"))
);
const runtimeArgs = RuntimeArgs.fromMap({
spender: utils.createRecipientAddress(spender),
spender: utils.createRecipientAddress(_spender),
amount: CLValueBuilder.u256(amount)
});

Expand Down
32 changes: 19 additions & 13 deletions JsClients/ERC20/test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ const test = async () => {
EVENT_STREAM_ADDRESS!
);

const installDeployHash = await erc20.install(
KEYS,
ERC20_TOKEN_NAME!,
ERC20_TOKEN_SYMBOL!,
ERC20_DECIMALS!,
ERC20_TOTAL_SUPPLY!,
ERC20_CONTRACT_NAME!,
ERC20_INSTALL_PAYMENT_AMOUNT!,
ERC20_WASM_PATH!
);
// const installDeployHash = await erc20.install(
// KEYS,
// ERC20_TOKEN_NAME!,
// ERC20_TOKEN_SYMBOL!,
// ERC20_DECIMALS!,
// ERC20_TOTAL_SUPPLY!,
// ERC20_CONTRACT_NAME!,
// ERC20_INSTALL_PAYMENT_AMOUNT!,
// ERC20_WASM_PATH!
// );

console.log(`... Contract installation deployHash: ${installDeployHash}`);
// console.log(`... Contract installation deployHash: ${installDeployHash}`);

await getDeploy(NODE_ADDRESS!, installDeployHash);
// await getDeploy(NODE_ADDRESS!, installDeployHash);

console.log(`... Contract installed successfully.`);
// console.log(`... Contract installed successfully.`);

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

Expand All @@ -62,6 +62,12 @@ const test = async () => {

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

const packageHash = await utils.getAccountNamedKeyValue(
accountInfo,
`${ERC20_CONTRACT_NAME!}_package_hash`
);

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

//test();
50 changes: 27 additions & 23 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const {
TRANSFER_FROM_AMOUNT,
TOKEN0_CONTRACT,
TOKEN1_CONTRACT,
PAIR_CONTRACT
TOKEN1_CONTRACT_PACKAGE,
PAIR_CONTRACT,
PACKAGE_HASH,
AMOUNT_A_DESIRED,
AMOUNT_B_DESIRED
} = process.env;


Expand Down Expand Up @@ -127,20 +131,20 @@ const test = async () => {
// // // let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey);
// // // console.log(`... Allowance: ${allowance}`);

// //mint
// // const mintDeployHash = await erc20.mint(
// // KEYS,
// // PAIR_CONTRACT!,
// // MINT_AMOUNT!,
// // MINT_PAYMENT_AMOUNT!
// // );
// // console.log("... Mint deploy hash: ", mintDeployHash);
//mint
const mintDeployHash = await erc20.mint(
KEYS,
PACKAGE_HASH!,
MINT_AMOUNT!,
MINT_PAYMENT_AMOUNT!
);
console.log("... Mint deploy hash: ", mintDeployHash);

// // await getDeploy(NODE_ADDRESS!, mintDeployHash);
await getDeploy(NODE_ADDRESS!, mintDeployHash);

// // //balanceof
// // let balance = await erc20.balanceOfcontract(PAIR_CONTRACT!);
// // console.log(`... Balance: ${balance}`);
//balanceof
// let balance = await erc20.balanceOfcontract(PAIR_CONTRACT!);
// console.log(`... Balance: ${balance}`);

// // //burn
// // const burnDeployHash = await erc20.burn(
Expand All @@ -159,16 +163,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,
// PACKAGE_HASH!,
// AMOUNT_B_DESIRED!,
// 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 modified JsClients/FACTORY/wasm/factory.wasm
Binary file not shown.
Binary file modified JsClients/PAIR/wasm/pair-token.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion JsClients/ROUTER/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAwrapZ6QuZF+X1hsNluiXmdCWRAc+syfKTmQ9Tau9NPE=
MCowBQYDK2VwAyEAthNmFRj3BJMomJHAxiMgeSxjVjCUIWeyYhJ7lmQAEVA=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/ROUTER/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
01c2b6a967a42e645f97d61b0d96e89799d09644073eb327ca4e643d4dabbd34f1
01b613661518f70493289891c0c62320792c635630942167b262127b9664001150
2 changes: 1 addition & 1 deletion JsClients/ROUTER/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIH+6suzRo2fHjw2YK+ffdBcIxoFYrugGW6smkIxCFNH0
MC4CAQAwBQYDK2VwBCIEIN8sMjQ9ZVBJcdk/Gvx/HK+pj14d/5XhrTYk8ZxrGB2J
-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions JsClients/ROUTER/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum RouterEvents {
PairCreated="pair_created",
Approval = 'approve',
Erc20Transfer='erc20_transfer',
Transfer = 'transfer',
Mint = 'mint',
Burn = 'burn',
Expand Down
25 changes: 21 additions & 4 deletions JsClients/ROUTER/src/uniswap-router-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
CLKeyType,
CLList,
CLBoolBytesParser,
CLOption,
CLOptionType
} from "casper-js-sdk";
import { Some, None } from "ts-results";
import { RouterEvents } from "./constants";
Expand All @@ -29,8 +31,8 @@ const axios = require("axios").default;

class UniswapRouterClient {
private contractName: string = "uniswap_router";
private contractHash: string; // Hash type is string
private contractPackageHash: string;
private contractHash: string= "uniswap_router"; // Hash type is string
private contractPackageHash: string= "uniswap_router";
private namedKeys: {
balances: string;
metadata: string;
Expand All @@ -45,7 +47,15 @@ class UniswapRouterClient {
private nodeAddress: string,
private chainName: string,
private eventStreamAddress?: string
) {}
) {
this.namedKeys= {
balances:"null",
metadata: "null",
ownedTokens: "null",
owners: "null",
paused: "null"
};
}

public async install(
keys: Keys.AsymmetricKey, // Have Public/Private Key Pair
Expand Down Expand Up @@ -130,6 +140,7 @@ class UniswapRouterClient {
amount_b_min: string,
to: string,
deadline: string,
pair_hash:string,
paymentAmount: string
) {
const _token_a = new CLByteArray(
Expand All @@ -140,6 +151,10 @@ class UniswapRouterClient {
);
const _to = new CLByteArray(Uint8Array.from(Buffer.from(to, "hex")));

const pair = new CLByteArray(
Uint8Array.from(Buffer.from(pair_hash, "hex"))
);

const runtimeArgs = RuntimeArgs.fromMap({
token_a: new CLKey(_token_a),
token_b: new CLKey(_token_b),
Expand All @@ -149,12 +164,13 @@ class UniswapRouterClient {
amount_b_min: CLValueBuilder.u256(amount_b_min),
to: utils.createRecipientAddress(_to),
deadline: CLValueBuilder.u256(deadline),
pair: new CLOption(Some(new CLKey(pair)))
});

const deployHash = await contractCall({
chainName: this.chainName,
contractHash: this.contractHash,
entryPoint: "add_liquidity",
entryPoint: "add_liquidity_js_client",
keys,
nodeAddress: this.nodeAddress,
paymentAmount,
Expand All @@ -163,6 +179,7 @@ class UniswapRouterClient {

if (deployHash !== null) {
this.addPendingDeploy(RouterEvents.PairCreated, deployHash);
this.addPendingDeploy(RouterEvents.Erc20Transfer, deployHash);
this.addPendingDeploy(RouterEvents.Transfer, deployHash);
this.addPendingDeploy(RouterEvents.Sync, deployHash);
this.addPendingDeploy(RouterEvents.Mint, deployHash);
Expand Down
9 changes: 8 additions & 1 deletion JsClients/ROUTER/test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,17 @@ const test = async () => {

const contractHash = await utils.getAccountNamedKeyValue(
accountInfo,
`${TOKEN_NAME!}_contract`
`${CONTRACT_NAME!}_contract_hash`
);

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

const packageHash = await utils.getAccountNamedKeyValue(
accountInfo,
`${CONTRACT_NAME!}_package_hash`
);

console.log(`... Package Hash: ${packageHash}`);
};

//test();
Loading

0 comments on commit 877dcfb

Please sign in to comment.