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

Commit

Permalink
mint burn and swap tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Nov 9, 2021
1 parent 2dd2b57 commit 2c463ca
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 96 deletions.
15 changes: 8 additions & 7 deletions .env
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
NODE_MODE=developement
NODE_MODE=deployed
DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL
DATABASE_URL_ONLINE=mongodb+srv://admin:[email protected]/V2-graphQL?retryWrites=true&w=majority
FACTORY_CONTRACT=69bbb559dbe40b510121f5c90c0229cb7ccfd78e9e0420aacbe6b512c9ec964f
PAIR_CONTRACT=eb674a72a3d41470aa0eb4f9a4abdf86c38dd72669df542d5e04ed485676afe8
PAIR_CONTRACT_PACKAGE=eb674a72a3d41470aa0eb4f9a4abdf86c38dd72669df542d5e04ed485676afe8

FACTORY_CONTRACT=0c43750a82af3dfb01472b92c9c42011b3681d93632617e0fa2388752c4af869
PAIR_CONTRACT=7a9f9108bf97fc357aa33b6f7eb800ee66e15e7d9cc1b87e0cb5687b72e119e5
PAIR_CONTRACT_PACKAGE=aa5af779038d39c20c686058a698ac2138f395ae9f0c3c784b16bc17bdf2a9e2
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=689a96cb140fea597a133f3bf5585ecb45a15fbece059044a7e606b75446ad28
TOKEN1_CONTRACT=d33b01cad84042df1a318cdaeb4af13bdf52c8798e914929b8e203f5bf6901d6
TOKEN0_CONTRACT=fca1efeb1b2a642fb817680e48c57eb57043032cf3cb2edfe72ad5c698e01247
TOKEN1_CONTRACT=1c5aa6218dc7f5c90571c21098a961d727db1d307bbd317ebdc6c69d6ed27faa

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand All @@ -24,7 +25,7 @@ PAIR_MASTER_KEY_PAIR_PATH=JsClients/PAIR/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 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-----
MCowBQYDK2VwAyEAsM6KkoXfFG6zZsnjXNzG89FBe1oNhdJC4hxVkC2NgEs=
MCowBQYDK2VwAyEAxX4Fb333lBaLBmeZxz+1HbJHoNYEcGXW2xpnUcM819g=
-----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 @@
01b0ce8a9285df146eb366c9e35cdcc6f3d1417b5a0d85d242e21c55902d8d804b
01c57e056f7df794168b066799c73fb51db247a0d6047065d6db1a6751c33cd7d8
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-----
MC4CAQAwBQYDK2VwBCIEIIvA6DFWx1wZ5rt4OG4VsBMCsC3ytQ+Lzyh1aWuw+PsE
MC4CAQAwBQYDK2VwBCIEII18Vx8Js+yppefqqJVLjOGyaICCHfIYNMXV050reEYz
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion JsClients/PAIR/test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const test = async () => {
);

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

};

Expand Down
191 changes: 125 additions & 66 deletions JsClients/PAIR/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,28 @@ const test = async () => {
console.log(newData[5][0].data + " = " + newData[5][1].data);
console.log(newData[6][0].data + " = " + newData[6][1].data);

// request(GRAPHQL!,
// `mutation handleBurn( $amount0: Int!, $amount1: Int!, $sender: String!,$logIndex: Int!,$to: String!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){
// handleBurn( amount0: $amount0, amount1: $amount1, sender: $sender, logIndex: $logIndex, to:$to, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
// result
// }
var amount0=parseInt(newData[0][1].data);
var amount1=parseInt(newData[1][1].data);
var pair=splitdata(newData[4][1].data);
var sender=splitdata(newData[5][1].data);
var to=splitdata(newData[6][1].data);

console.log("amount0: ", amount0);
console.log("amount1: ", amount1);
console.log("pair: ",pair);
console.log("sender: ", sender);
console.log("to: ", to);

request(GRAPHQL!,
`mutation handleBurn( $amount0: Int!, $amount1: Int!, $sender: String!,$logIndex: Int!,$to: String!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){
handleBurn( amount0: $amount0, amount1: $amount1, sender: $sender, logIndex: $logIndex, to:$to, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
// }`,
// {amount0:amount0, amount1: amount1, sender: sender,logIndex:0, to:to,pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash})
// .then(data => console.log(data))
// .catch(error => console.error(error));
}`,
{amount0:amount0, amount1: amount1, sender: sender,logIndex:0, to:to,pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));
}
else if (eventName=="sync")
{
Expand All @@ -182,6 +194,11 @@ const test = async () => {
var reserve1=parseInt(newData[4][1].data);
var pair=splitdata(newData[2][1].data);

console.log("reserve0: ", reserve0);
console.log("reserve1: ", reserve1);
console.log("pair: ",pair);


request(GRAPHQL!,
`mutation handleSync( $reserve0: Int!, $reserve1: Int!, $pairAddress: String!){
handleSync( reserve0: $reserve0, reserve1: $reserve1, pairAddress: $pairAddress) {
Expand All @@ -208,16 +225,34 @@ const test = async () => {
console.log(newData[8][0].data + " = " + newData[8][1].data);
console.log(newData[9][0].data + " = " + newData[9][1].data);

// request(GRAPHQL!,
// `mutation handleSwap( $amount0In: Int!, $amount1In: Int!, $amount0Out: Int!, $amount1Out: Int!, $to: String!,$from: String!,$sender: String!,$logIndex: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){
// handleSwap( amount0In: $amount0In, amount1In: $amount1In, amount0Out: $amount0Out, amount1Out: $amount1Out, to:$to, from:$from,sender: $sender,logIndex: $logIndex, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
// result
// }
var amount0In=parseInt(newData[0][1].data);
var amount1In=parseInt(newData[1][1].data);
var amount0Out=parseInt(newData[2][1].data);
var amount1Out=parseInt(newData[3][1].data);
var from=splitdata(newData[6][1].data);
var pair=splitdata(newData[7][1].data);
var sender=splitdata(newData[8][1].data);
var to=splitdata(newData[9][1].data);

console.log("amount0In: ", amount0In);
console.log("amount1In: ", amount1In);
console.log("amount0Out: ", amount0Out);
console.log("amount1Out: ", amount1Out);
console.log("from: ",from);
console.log("pair: ",pair);
console.log("sender: ", sender);
console.log("to: ", to);

request(GRAPHQL!,
`mutation handleSwap( $amount0In: Int!, $amount1In: Int!, $amount0Out: Int!, $amount1Out: Int!, $to: String!,$from: String!,$sender: String!,$logIndex: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){
handleSwap( amount0In: $amount0In, amount1In: $amount1In, amount0Out: $amount0Out, amount1Out: $amount1Out, to:$to, from:$from,sender: $sender,logIndex: $logIndex, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
// }`,
// {amount0In:amount0In, amount1In: amount1In,amount0Out:amount0Out, amount1Out: amount1Out,to:to,from:from, sender: sender,logIndex:0,pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash})
// .then(data => console.log(data))
// .catch(error => console.error(error));
}`,
{amount0In:amount0In, amount1In: amount1In,amount0Out:amount0Out, amount1Out: amount1Out,to:to,from:from, sender: sender,logIndex:0,pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));
}


Expand Down Expand Up @@ -269,34 +304,34 @@ const test = async () => {


//erc20mint
const erc20MintToken0DeployHash = await pair.erc20MintMethod(
KEYS,
TOKEN0_CONTRACT!,
"1000"!,
MINT_PAYMENT_AMOUNT!
);
console.log("...ERC20 Mint deploy hash: ", erc20MintToken0DeployHash);
// const erc20MintToken0DeployHash = await pair.erc20MintMethod(
// KEYS,
// TOKEN0_CONTRACT!,
// "1000"!,
// MINT_PAYMENT_AMOUNT!
// );
// console.log("...ERC20 Mint deploy hash: ", erc20MintToken0DeployHash);


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

// //balanceof
// let balance = await pair.erc20balanceOf(KEYS.publicKey);
// console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`);
// console.log(`... Balance: ${balance}`);

//erc20mint
const erc20MintToken1DeployHash = await pair.erc20MintMethod(
KEYS,
TOKEN1_CONTRACT!,
"1000"!,
MINT_PAYMENT_AMOUNT!
);
console.log("...ERC20 Mint deploy hash: ", erc20MintToken1DeployHash);
// const erc20MintToken1DeployHash = await pair.erc20MintMethod(
// KEYS,
// TOKEN1_CONTRACT!,
// "1000"!,
// MINT_PAYMENT_AMOUNT!
// );
// console.log("...ERC20 Mint deploy hash: ", erc20MintToken1DeployHash);

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

// //token0
// const token0 = await pair.token0();
Expand Down Expand Up @@ -364,27 +399,16 @@ const test = async () => {
// console.log("... Sync functionality successfull");


// //mint
const mintDeployHash = await pair.mint(
KEYS,
PAIR_CONTRACT_PACKAGE!,
MINT_PAYMENT_AMOUNT!
);
console.log("... Mint deploy hash: ", mintDeployHash);

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

//burn
const burnDeployHash = await pair.burn(
KEYS,
KEYS.publicKey,
BURN_PAYMENT_AMOUNT!
);
console.log("... Burn deploy hash: ", burnDeployHash);
//mint
// const mintDeployHash = await pair.mint(
// KEYS,
// PAIR_CONTRACT_PACKAGE!,
// MINT_PAYMENT_AMOUNT!
// );
// console.log("... Mint deploy hash: ", mintDeployHash);

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

// // //totalsupply
// // totalSupply = await pair.totalSupply();
Expand Down Expand Up @@ -438,20 +462,55 @@ const test = async () => {
// await getDeploy(NODE_ADDRESS!, skimDeployHash);
// console.log("... Skim functionality successfull");

//erc20mint
const erc20MintToken0DeployHash = await pair.erc20MintMethod(
KEYS,
TOKEN0_CONTRACT!,
"1000"!,
MINT_PAYMENT_AMOUNT!
);
console.log("...ERC20 Mint deploy hash: ", erc20MintToken0DeployHash);


// //swap
const swapDeployHash = await pair.swap(
await getDeploy(NODE_ADDRESS!, erc20MintToken0DeployHash);
console.log("...ERC20 Token minted successfully");

//erc20mint
const erc20MintToken1DeployHash = await pair.erc20MintMethod(
KEYS,
TOKEN1_CONTRACT!,
"1000"!,
MINT_PAYMENT_AMOUNT!
);
console.log("...ERC20 Mint deploy hash: ", erc20MintToken1DeployHash);

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

//swap
// const swapDeployHash = await pair.swap(
// KEYS,
// "10",
// "20",
// KEYS.publicKey,
// "",
// SWAP_PAYMENT_AMOUNT!
// );
// console.log("... swap deploy hash: ", swapDeployHash);

// await getDeploy(NODE_ADDRESS!, swapDeployHash);
// console.log("... Swap functionality successfull");

//burn
const burnDeployHash = await pair.burn(
KEYS,
"10",
"20",
KEYS.publicKey,
"",
SWAP_PAYMENT_AMOUNT!
BURN_PAYMENT_AMOUNT!
);
console.log("... swap deploy hash: ", swapDeployHash);
console.log("... Burn deploy hash: ", burnDeployHash);

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

// //settreasuryfeepercent
// const settreasuryfeepercentDeployHash = await pair.setTreasuryFeePercent(
Expand All @@ -470,7 +529,7 @@ const test = async () => {

};

//test();
test();

export const balanceOf = async (contractHash:string, key:string) => {

Expand Down
2 changes: 1 addition & 1 deletion JsClients/PAIR/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getDeploy = async (NODE_URL: string, deployHash: string) => {
const client = new CasperClient(NODE_URL);
let i = 1000;
while (i != 0) {

console.log("i: ",i);
const [deploy, raw] = await client.getDeploy(deployHash);
if (raw.execution_results.length !== 0) {
// @ts-ignore
Expand Down
Loading

0 comments on commit 2c463ca

Please sign in to comment.