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

Commit

Permalink
code updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Dec 10, 2021
1 parent 877dcfb commit 822be53
Show file tree
Hide file tree
Showing 26 changed files with 630 additions and 456 deletions.
38 changes: 19 additions & 19 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ NODE_MODE=deployed
DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL
DATABASE_URL_ONLINE=mongodb+srv://admin:[email protected]/V2-graphQL-backend-demo?retryWrites=true&w=majority

FACTORY_CONTRACT=A1536f887a6dFB2B2fa00C9beAc21324AaD0F880d36926010e355A1F4C1616ee
PAIR_CONTRACT=8A56313004fFa242eB9D197A232aFf6eE19507847F3151064e5ff334935cf02D
PAIR_CONTRACT_PACKAGE=57f8a52b960485c9c5111b33660cdF29FB543A754ec341caB5829CC49EB644c3
FACTORY_CONTRACT=46505F2A814CC8Ee77E963a9dB101bEE4C9f96b47acAD65eE1084588b3e8e822
PAIR_CONTRACT=83c4d036f0912794cfb5896210298E6E9F228BE41626ddcf74583D16a26D7eD6
PAIR_CONTRACT_PACKAGE=984C671dF3c19563B760AF45586e913ab3C3C649BD8AFddbfd60807325803EAD
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=39cc3cEE8D8Be3A1B0cDE77d857cAa1d28f3061A54c053da2585CfDFF486b0E1
TOKEN1_CONTRACT=464AB6d2Fad52DB31cD2e11D7F30Ce4E998bd37b4321243925D9846011e0b13B
TOKEN1_CONTRACT_PACKAGE=7D379F70A50458Bd1593E9c1317A7110B1AebBd926E331618f45bFbd4e119B0B
TOKEN0_CONTRACT=7387033a0A3619caf217d8dF5E78D0814Fe6e3fa5Bd5DCfCe98C201851a97725
TOKEN0_CONTRACT_PACKAGE=03356D719373cB3E5A83c10548fED58919E7B4AFF23C7449d97b17e89d7D8727
TOKEN1_CONTRACT=f2dF436817e881ca2D9e945FD62680C546591A6ecb4E3b9Ec05E6e4BC2385B23
TOKEN1_CONTRACT_PACKAGE=6c2Fe8b6728Ce1C0320bF92867236e9d94aC41FD6997492B25422e4baa0E3c3f

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
NODE_ADDRESS=http://159.65.118.250:7777/rpc
EVENT_STREAM_ADDRESS=http://159.65.118.250:9999/events/main
NODE_ADDRESS=http://65.21.237.153:7777/rpc
EVENT_STREAM_ADDRESS=http://65.21.237.153:9999/events/main
RECEIVER_ACCOUNT_ONE=017e82abcc9539a01cfd9d63ae8c9c8b3a752a6f75ba1ab148714eea03e9be69a7

ERC20_WASM_PATH=JsClients/ERC20/wasm/erc20-token.wasm
Expand All @@ -40,12 +41,12 @@ PAIR_TOTAL_SUPPLY=0

FACTORY_CONTRACT_NAME=Factory

ERC20_INSTALL_PAYMENT_AMOUNT=170000000000
ERC20_INSTALL_PAYMENT_AMOUNT=200000000000
FACTORY_INSTALL_PAYMENT_AMOUNT=110000000000
PAIR_INSTALL_PAYMENT_AMOUNT=300000000000
PAIR_INSTALL_PAYMENT_AMOUNT=350000000000

MINT_PAYMENT_AMOUNT=5000000000
MINT_AMOUNT=1000
MINT_AMOUNT=2000

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

FACTORY=A1536f887a6dFB2B2fa00C9beAc21324AaD0F880d36926010e355A1F4C1616ee
FACTORY=46505F2A814CC8Ee77E963a9dB101bEE4C9f96b47acAD65eE1084588b3e8e822
WCSPR=bA8f6a73B6D548E2CAe2d572aA2F824BC46A3C06a3BBA10e3d12B015931D3f85
LIBRARY=e0Dae7571C3dc5C957a36422c56BA0ccb8AECEC833F35e32874b75A8Ea8Ac4Db
CONTRACT_NAME=UniSwapRouter

CONTRACT_HASH=2634C8f75Db583C65b9Beb55aBf8339294F2728Cf05c478fe13B239E7916aa36
PACKAGE_HASH=B51E1CE9a31f948119e5699D24C943Bc16024C81caD1A7dFD9119aFD791eD5C5
CONTRACT_HASH=58e35630F1ef3797C28dc93a8e6Fb3F5980154e4793ee142D47eE95Cd48Feb62
PACKAGE_HASH=3b401aAfC1CCd3707DEaB6B39a3Bb42670487130c9EAB0b5BaCb2248900A88CA
INSTALL_PAYMENT_AMOUNT=200000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
Expand All @@ -96,13 +97,12 @@ MINT_COPIES_COUNT=20
MINT_MANY_META_SIZE=5
MINT_MANY_META_COUNT=5

TO = 39cc3cEE8D8Be3A1B0cDE77d857cAa1d28f3061A54c053da2585CfDFF486b0E1
DEADLINE = 1638974538161

TO = 7387033a0A3619caf217d8dF5E78D0814Fe6e3fa5Bd5DCfCe98C201851a97725
DEADLINE = 1699140435324
# add_liquidity

TOKEN_A = 39cc3cEE8D8Be3A1B0cDE77d857cAa1d28f3061A54c053da2585CfDFF486b0E1
TOKEN_B = 464AB6d2Fad52DB31cD2e11D7F30Ce4E998bd37b4321243925D9846011e0b13B
TOKEN_A = 7387033a0A3619caf217d8dF5E78D0814Fe6e3fa5Bd5DCfCe98C201851a97725
TOKEN_B = f2dF436817e881ca2D9e945FD62680C546591A6ecb4E3b9Ec05E6e4BC2385B23
AMOUNT_A_DESIRED = 500
AMOUNT_B_DESIRED = 600
AMOUNT_A_MIN = 250
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-----
MCowBQYDK2VwAyEA9iX2/XqEmzD9Oxj78Pgk5No8MMtqPOVslG73VeXB7wA=
MCowBQYDK2VwAyEA+Gwj5LQ3PmnfmVjkxFcmZnD6FktIUMI0JRu823ZRpnE=
-----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 @@
01f625f6fd7a849b30fd3b18fbf0f824e4da3c30cb6a3ce56c946ef755e5c1ef00
01f86c23e4b4373e69df9958e4c457266670fa164b4850c234251bbcdb7651a671
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-----
MC4CAQAwBQYDK2VwBCIEIN7jOxtBNk251SUMGNb3UScLr35+K9ehtphiKYPqaxDW
MC4CAQAwBQYDK2VwBCIEILXBMhV7E1w2R3bgTAbiYmAju2yKUF5ZUuS2I0moHO2I
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion JsClients/ERC20/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum ERC20Events {
Approval="approve",
Transfer="transfer"
Transfer="erc20_transfer"
}

37 changes: 33 additions & 4 deletions JsClients/ERC20/src/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,16 @@ class ERC20Client {
}
public async mint(
keys: Keys.AsymmetricKey,
to: string,
to: RecipientType,
amount: string,
paymentAmount: string
) {
const tobytearray = new CLByteArray(Uint8Array.from(Buffer.from(to, 'hex')));

const runtimeArgs = RuntimeArgs.fromMap({
to: CLValueBuilder.key(tobytearray),
to:utils.createRecipientAddress(to),
amount: CLValueBuilder.u256(amount)
});


const deployHash = await contractCall({
chainName: this.chainName,
contractHash: this.contractHash,
Expand All @@ -332,6 +331,36 @@ class ERC20Client {
throw Error("Invalid Deploy");
}
}
// public async mint(
// keys: Keys.AsymmetricKey,
// to: string,
// amount: string,
// paymentAmount: string
// ) {
// const tobytearray = new CLByteArray(Uint8Array.from(Buffer.from(to, 'hex')));
// const runtimeArgs = RuntimeArgs.fromMap({
// to: CLValueBuilder.key(tobytearray),
// amount: CLValueBuilder.u256(amount)
// });


// const deployHash = await contractCall({
// chainName: this.chainName,
// contractHash: this.contractHash,
// entryPoint: "mint",
// keys,
// nodeAddress: this.nodeAddress,
// paymentAmount,
// runtimeArgs,
// });

// if (deployHash !== null) {
// this.addPendingDeploy(ERC20Events.Transfer, deployHash);
// return deployHash;
// } else {
// throw Error("Invalid Deploy");
// }
// }
public async burn(
keys: Keys.AsymmetricKey,
from: RecipientType,
Expand Down
26 changes: 13 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 Down
52 changes: 30 additions & 22 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const {
PAIR_CONTRACT,
PACKAGE_HASH,
AMOUNT_A_DESIRED,
AMOUNT_B_DESIRED
AMOUNT_B_DESIRED,
MASTER_KEY_PAIR_PATH,
PAIR_CONTRACT_PACKAGE
} = process.env;


Expand All @@ -45,6 +47,11 @@ const KEYS = Keys.Ed25519.parseKeyFiles(
`${ERC20_MASTER_KEY_PAIR_PATH}/secret_key.pem`
);

const ROUTERKEYS = Keys.Ed25519.parseKeyFiles(
`${MASTER_KEY_PAIR_PATH}/public_key.pem`,
`${MASTER_KEY_PAIR_PATH}/secret_key.pem`
);

const erc20 = new ERC20Client(
NODE_ADDRESS!,
CHAIN_NAME!,
Expand Down Expand Up @@ -99,8 +106,8 @@ const test = async () => {
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(TOKEN0_CONTRACT!);
//await erc20.setContractHash(contractHash.slice(5));
await erc20.setContractHash(TOKEN1_CONTRACT!);

// // //name
// // const name = await erc20.name();
Expand Down Expand Up @@ -132,16 +139,17 @@ const test = async () => {
// // // console.log(`... Allowance: ${allowance}`);

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

// await getDeploy(NODE_ADDRESS!, mintDeployHash);
// console.log("... Token minted successfully.");

await getDeploy(NODE_ADDRESS!, mintDeployHash);

//balanceof
// let balance = await erc20.balanceOfcontract(PAIR_CONTRACT!);
// console.log(`... Balance: ${balance}`);
Expand All @@ -163,16 +171,16 @@ const test = async () => {
// // console.log(`... Total supply: ${totalSupply}`);

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

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

// // //transfer
// // const transferDeployHash = await erc20.transfer(
Expand Down Expand Up @@ -201,7 +209,7 @@ const test = async () => {

};

//test();
test();

export const getName = async (contractHash:string) => {

Expand Down
5 changes: 3 additions & 2 deletions JsClients/ERC20/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export const sleep = (ms: number) => {

export const getDeploy = async (NODE_URL: string, deployHash: string) => {
const client = new CasperClient(NODE_URL);
let i = 1000;
let i = 300;
while (i != 0) {
//console.log("i: ",i);
const [deploy, raw] = await client.getDeploy(deployHash);
if (raw.execution_results.length !== 0){
// @ts-ignore
if (raw.execution_results[0].result.Success) {

return [deploy.header.timestamp,deploy.header.gasPrice,raw.execution_results[0].block_hash];
return [deploy.header.timestamp,raw.execution_results[0].block_hash];
} else {
// @ts-ignore
throw Error("Contract execution: " + raw.execution_results[0].result.Failure.error_message);
Expand Down
Binary file modified JsClients/ERC20/wasm/erc20-token.wasm
Binary file not shown.
Binary file removed JsClients/ERC20/wasm/erc20-tokenevents.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion JsClients/FACTORY/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEA9iX2/XqEmzD9Oxj78Pgk5No8MMtqPOVslG73VeXB7wA=
MCowBQYDK2VwAyEATkKacKRbXO7m8cL0EqIk1eo8YV9QRtdhhKIATP8NkEY=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/FACTORY/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
01f625f6fd7a849b30fd3b18fbf0f824e4da3c30cb6a3ce56c946ef755e5c1ef00
014e429a70a45b5ceee6f1c2f412a224d5ea3c615f5046d76184a2004cff0d9046
2 changes: 1 addition & 1 deletion JsClients/FACTORY/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIN7jOxtBNk251SUMGNb3UScLr35+K9ehtphiKYPqaxDW
MC4CAQAwBQYDK2VwBCIEIN9+mOCy+hYO+yItDcRuHawnIUKq+HvOml4qExk8ITfT
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion JsClients/FACTORY/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const sleep = (ms: number) => {

export const getDeploy = async (NODE_URL: string, deployHash: string) => {
const client = new CasperClient(NODE_URL);
let i = 1000;
let i = 300;
while (i != 0) {

const [deploy, raw] = await client.getDeploy(deployHash);
Expand Down
2 changes: 1 addition & 1 deletion JsClients/PAIR/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAf7CfmFUXqAUKP1jtrY+nll9XKMTN+a5iJ7sWX+90Hqo=
MCowBQYDK2VwAyEAMfyQQNEYSp6VQcd9N2GpRmGcx+1+Wl6myTehyxbCLP4=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/PAIR/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
017fb09f985517a8050a3f58edad8fa7965f5728c4cdf9ae6227bb165fef741eaa
0131fc9040d1184a9e9541c77d3761a946619cc7ed7e5a5ea6c937a1cb16c22cfe
2 changes: 1 addition & 1 deletion JsClients/PAIR/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIAHoAFym+7OvRR4bQuiQqFrY8C7uninSLGgJk9rq6dCV
MC4CAQAwBQYDK2VwBCIEIO4zMC4Rx+Mnh5sCLc0E5jhAhLZDPmHN1JDC0NGTD8ti
-----END PRIVATE KEY-----
4 changes: 2 additions & 2 deletions JsClients/PAIR/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const sleep = (ms: number) => {

export const getDeploy = async (NODE_URL: string, deployHash: string) => {
const client = new CasperClient(NODE_URL);
let i = 1000;
let i = 300;
while (i != 0) {
console.log("i: ",i);
//console.log("i: ",i);
const [deploy, raw] = await client.getDeploy(deployHash);
if (raw.execution_results.length !== 0) {
// @ts-ignore
Expand Down
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-----
MCowBQYDK2VwAyEAthNmFRj3BJMomJHAxiMgeSxjVjCUIWeyYhJ7lmQAEVA=
MCowBQYDK2VwAyEAOx2Lh372bKru6Ob727qg2J+53UC1VQOAo3flgNWTXY8=
-----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 @@
01b613661518f70493289891c0c62320792c635630942167b262127b9664001150
013b1d8b877ef66caaeee8e6fbdbbaa0d89fb9dd40b5550380a377e580d5935d8f
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-----
MC4CAQAwBQYDK2VwBCIEIN8sMjQ9ZVBJcdk/Gvx/HK+pj14d/5XhrTYk8ZxrGB2J
MC4CAQAwBQYDK2VwBCIEINHgUlwQkPmO7tZIxmYxz0fUcSxJ9GpDl54v+YPm4zWy
-----END PRIVATE KEY-----
Loading

0 comments on commit 822be53

Please sign in to comment.