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

Commit

Permalink
data has been collected from events , appoloclient added and tested ,…
Browse files Browse the repository at this point in the history
… code is not tested (handleNewPair,handleTransfer, handleMint,handleBurn , handleSync and handleSwap)
  • Loading branch information
Hammad-Mubeen committed Nov 1, 2021
1 parent 736f63a commit 6fd768a
Show file tree
Hide file tree
Showing 23 changed files with 560 additions and 346 deletions.
32 changes: 17 additions & 15 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ pair=11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59

CHAIN_NAME=casper-test
NODE_ADDRESS=http://159.65.118.250:7777/rpc
EVENT_STREAM_ADDRESS=http://159.65.118.250:7777/events/main
EVENT_STREAM_ADDRESS=http://159.65.118.250:9999/events/main
RECEIVER_ACCOUNT_ONE=017e82abcc9539a01cfd9d63ae8c9c8b3a752a6f75ba1ab148714eea03e9be69a7

ERC20_WASM_PATH=JsClients/ERC20/wasm/erc20-token.wasm
FACTORY_WASM_PATH=JsClients/FACTORY/wasm/factory-token.wasm
FACTORY_WASM_PATH=JsClients/FACTORY/wasm/factory.wasm
PAIR_WASM_PATH=JsClients/PAIR/wasm/pair-token.wasm

ERC20_MASTER_KEY_PAIR_PATH=JsClients/ERC20/keys/
Expand All @@ -36,32 +36,34 @@ FACTORY_CONTRACT_NAME=Factory

INSTALL_PAYMENT_AMOUNT=220000000000

MINT_PAYMENT_AMOUNT=70000000000
MINT_PAYMENT_AMOUNT=5000000000
MINT_AMOUNT=50

BURN_PAYMENT_AMOUNT=70000000000
BURN_PAYMENT_AMOUNT=5000000000
BURN_AMOUNT=10

APPROVE_PAYMENT_AMOUNT=7000000000
APPROVE_PAYMENT_AMOUNT=5000000000
APPROVE_AMOUNT=50

TRANSFER_PAYMENT_AMOUNT=7000000000
TRANSFER_PAYMENT_AMOUNT=5000000000
TRANSFER_AMOUNT=5

TRANSFER_FROM_PAYMENT_AMOUNT=7000000000
TRANSFER_FROM_PAYMENT_AMOUNT=5000000000
TRANSFER_FROM_AMOUNT=5

SKIM_PAYMENT_AMOUNT=70000000000
SKIM_PAYMENT_AMOUNT=5000000000

SYNC_PAYMENT_AMOUNT=70000000000
SYNC_PAYMENT_AMOUNT=5000000000

SWAP_PAYMENT_AMOUNT=70000000000
SWAP_PAYMENT_AMOUNT=5000000000

INITIALIZE_PAYMENT_AMOUNT=70000000000
INITIALIZE_PAYMENT_AMOUNT=5000000000

SET_TREASURY_FEE_PERCENT_PAYMENT_AMOUNT=70000000000
SET_TREASURY_FEE_PERCENT_PAYMENT_AMOUNT=5000000000

SET_FEE_TO_PAYMENT_AMOUNT=20000000000
SET_FEE_TO_SETTER_PAYMENT_AMOUNT=20000000000
CREATE_PAIR_PAYMENT_AMOUNT=20000000000
SET_FEE_TO_PAYMENT_AMOUNT=5000000000
SET_FEE_TO_SETTER_PAYMENT_AMOUNT=5000000000
CREATE_PAIR_PAYMENT_AMOUNT=5000000000

FACTORY_CONTRACT=c9d0268ecea8c57ed456bf56e4fba4bf285a4588fd817832230b8fd86b71c30f
PAIR_CONTRACT=11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59
Expand Down
12 changes: 2 additions & 10 deletions JsClients/ERC20/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
export enum ERC20Events {
MintOne = "erc20_mint_one",
TransferToken = "erc20_transfer_token",
BurnOne = "erc20_burn_one",
MetadataUpdate = 'erc20_metadata_update',
Approve = 'approve',
Transfer = 'transfer',
TransferFrom = 'transfer_from',
Mint = 'mint',
Burn = 'burn',
Permit = 'permit',
Approval="approve",
Transfer="transfer"
}
45 changes: 28 additions & 17 deletions JsClients/ERC20/src/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class ERC20Client {
private contractName: string = "erc20";
private contractHash: string= "erc20";
private contractPackageHash: string= "erc20";
// private namedKeys: {
// balances:string;
// metadata: string;
// nonces: string;
// allowances: string;
// ownedTokens: string;
// owners: string;
// paused: string;
private namedKeys: {
balances:string
metadata: string;
nonces: string;
allowances: string;
ownedTokens: string;
owners: string;
paused: string;

// };
};

private isListening = false;
private pendingDeploys: IPendingDeploy[] = [];
Expand All @@ -45,7 +45,18 @@ class ERC20Client {
private chainName: string,
private eventStreamAddress?: string,

) { }
)
{
this.namedKeys= {
balances:"null",
metadata: "null",
nonces: "null",
allowances: "null",
ownedTokens: "null",
owners: "null",
paused: "null"
};
}

public async install(
keys: Keys.AsymmetricKey,
Expand Down Expand Up @@ -146,7 +157,7 @@ class ERC20Client {
const result = await utils.contractDictionaryGetter(
this.nodeAddress,
accountHash,
'balances'
this.namedKeys.balances
);
const maybeValue = result.value().unwrap();
return maybeValue.value().toString();
Expand All @@ -157,7 +168,7 @@ class ERC20Client {
const result = await utils.contractDictionaryGetter(
this.nodeAddress,
accountHash,
'nonces'
this.namedKeys.nonces
);
const maybeValue = result.value().unwrap();
return maybeValue.value().toString();
Expand All @@ -170,7 +181,7 @@ class ERC20Client {
const result = await utils.contractDictionaryGetter(
this.nodeAddress,
accountHash,
'allowances'
this.namedKeys.allowances
);
const maybeValue = result.value().unwrap();
return maybeValue.value().toString();
Expand Down Expand Up @@ -209,7 +220,7 @@ class ERC20Client {
});

if (deployHash !== null) {
this.addPendingDeploy(ERC20Events.Approve, deployHash);
this.addPendingDeploy(ERC20Events.Approval, deployHash);
return deployHash;
} else {
throw Error("Invalid Deploy");
Expand Down Expand Up @@ -301,7 +312,7 @@ class ERC20Client {
});

if (deployHash !== null) {
this.addPendingDeploy(ERC20Events.Mint, deployHash);
this.addPendingDeploy(ERC20Events.Transfer, deployHash);
return deployHash;
} else {
throw Error("Invalid Deploy");
Expand Down Expand Up @@ -331,7 +342,7 @@ class ERC20Client {
});

if (deployHash !== null) {
this.addPendingDeploy(ERC20Events.Burn, deployHash);
this.addPendingDeploy(ERC20Events.Transfer, deployHash);
return deployHash;
} else {
throw Error("Invalid Deploy");
Expand Down Expand Up @@ -369,7 +380,7 @@ class ERC20Client {
});

if (deployHash !== null) {
this.addPendingDeploy(ERC20Events.Permit, deployHash);
this.addPendingDeploy(ERC20Events.Approval, deployHash);
return deployHash;
} else {
throw Error("Invalid Deploy");
Expand Down
1 change: 1 addition & 0 deletions JsClients/ERC20/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CLAccountHash, CLByteArray, CLPublicKey } from "casper-js-sdk";
import {ERC20Events} from "./constants";

export type RecipientType = CLPublicKey | CLAccountHash | CLByteArray;

Expand Down
167 changes: 91 additions & 76 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,40 @@ const erc20 = new ERC20Client(
EVENT_STREAM_ADDRESS!
);

const listener = erc20.onEvent(
[
ERC20Events.Approve,
ERC20Events.Transfer,
ERC20Events.TransferFrom,
ERC20Events.Mint,
],
(eventName, deploy, result) => {
if (deploy.success) {
console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
console.log(result.value());
} else {
console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`);
console.log(`Error: ${deploy.error}`);
const test = async () => {

const listener = erc20.onEvent(
[
ERC20Events.Approval,
ERC20Events.Transfer
],
async (eventName, deploy, result) => {
if (deploy.success) {
console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
console.log("... Deployhash: ", deploy.deployHash);
console.log("... Timestamp: ", timestamp);
//console.log("... GasPrice: ", gasPrice);
console.log("... Block hash: ", block_hash);

let newData = JSON.parse(JSON.stringify(result.value()));

console.log(eventName+ " Event result: ");
console.log(newData[0][0].data + " = " + newData[0][1].data);
console.log(newData[1][0].data + " = " + newData[1][1].data);
console.log(newData[2][0].data + " = " + newData[2][1].data);
console.log(newData[3][0].data + " = " + newData[3][1].data);
console.log(newData[4][0].data + " = " + newData[4][1].data);


} else {
console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`);
console.log(`Error: ${deploy.error}`);
}
}
}
);
);
console.log("listener: ",listener);

const test = async () => {

await sleep(5 * 1000);

let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey);
Expand Down Expand Up @@ -101,13 +115,13 @@ const test = async () => {
// console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`);
console.log(`... Balance: ${balance}`);

//balanceof
//nonce
let nonce = await erc20.nonce(KEYS.publicKey);
console.log(`... Nonce: ${nonce}`);

// //allowance
// let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey);
// console.log(`... Allowance: ${allowance}`);
// // //allowance
// // let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey);
// // console.log(`... Allowance: ${allowance}`);

//mint
const mintDeployHash = await erc20.mint(
Expand All @@ -119,60 +133,61 @@ const test = async () => {
console.log("... Mint deploy hash: ", mintDeployHash);

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

//burn
const burnDeployHash = await erc20.burn(
KEYS,
KEYS.publicKey,
BURN_AMOUNT!,
BURN_PAYMENT_AMOUNT!
);
console.log("... Burn deploy hash: ", burnDeployHash);

await getDeploy(NODE_ADDRESS!, burnDeployHash);
console.log("... Token burned successfully");

//totalsupply
totalSupply = await erc20.totalSupply();
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");

//transfer
const transferDeployHash = await erc20.transfer(
KEYS,
KEYS.publicKey,
TRANSFER_AMOUNT!,
TRANSFER_PAYMENT_AMOUNT!
);
console.log("... Transfer deploy hash: ", transferDeployHash);

await getDeploy(NODE_ADDRESS!, transferDeployHash);
console.log("... Token transfer successfully");

//transfer_from
const transferfromDeployHash = await erc20.transferFrom(
KEYS,
KEYS.publicKey,
KEYS.publicKey,
TRANSFER_FROM_AMOUNT!,
TRANSFER_FROM_PAYMENT_AMOUNT!
);
console.log("... TransferFrom deploy hash: ", transferfromDeployHash);

await getDeploy(NODE_ADDRESS!, transferfromDeployHash);
console.log("... Token transfer successfully");



// //burn
// const burnDeployHash = await erc20.burn(
// KEYS,
// KEYS.publicKey,
// BURN_AMOUNT!,
// BURN_PAYMENT_AMOUNT!
// );
// console.log("... Burn deploy hash: ", burnDeployHash);

// await getDeploy(NODE_ADDRESS!, burnDeployHash);
// console.log("... Token burned successfully");

// //totalsupply
// totalSupply = await erc20.totalSupply();
// 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");

// //transfer
// const transferDeployHash = await erc20.transfer(
// KEYS,
// KEYS.publicKey,
// TRANSFER_AMOUNT!,
// TRANSFER_PAYMENT_AMOUNT!
// );
// console.log("... Transfer deploy hash: ", transferDeployHash);

// await getDeploy(NODE_ADDRESS!, transferDeployHash);
// console.log("... Token transfer successfully");

// //transfer_from
// const transferfromDeployHash = await erc20.transferFrom(
// KEYS,
// KEYS.publicKey,
// KEYS.publicKey,
// TRANSFER_FROM_AMOUNT!,
// TRANSFER_FROM_PAYMENT_AMOUNT!
// );
// console.log("... TransferFrom deploy hash: ", transferfromDeployHash);

// await getDeploy(NODE_ADDRESS!, transferfromDeployHash);
// console.log("... Token transfer successfully");

};

Expand Down
3 changes: 2 additions & 1 deletion JsClients/ERC20/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const getDeploy = async (NODE_URL: string, deployHash: string) => {
if (raw.execution_results.length !== 0){
// @ts-ignore
if (raw.execution_results[0].result.Success) {
return deploy;

return [deploy.header.timestamp,deploy.header.gasPrice,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.
Loading

0 comments on commit 6fd768a

Please sign in to comment.