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

Commit

Permalink
pricing file uncommented and stable coins deployed and added in the f…
Browse files Browse the repository at this point in the history
…low...(testing is in progress)
  • Loading branch information
Hammad-Mubeen committed Dec 17, 2021
1 parent 87a78ec commit 5ebbcf9
Show file tree
Hide file tree
Showing 44 changed files with 493 additions and 400 deletions.
64 changes: 43 additions & 21 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,37 @@ 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=e135359661bd6F4D0A2f827e0e25F0B1E32bb44b538676c3aECBe543F93fc54F
FACTORY_CONTRACT_PACKAGE=9e00eE28318CDD9Ea3fc83eEad5EbEE916A798565d930b14638f196E725d537a
PAIR_CONTRACT=5B4C9719f6dac2F551bF0100Ff85B1469A1Ffd0F3b03Fd44125845404dF892a9
PAIR_CONTRACT_PACKAGE=9b0C92894Bb7E9C0E657B2ba505C69263e435082Ac37dF982827061B86966B24
FACTORY_CONTRACT=202dffe0821C291870c864378c38fCE0BC4Fe7EA571341c62243e92608005BEe
FACTORY_CONTRACT_PACKAGE=6fb092b2Da2Dc4C7Eb238E3770933A6C1Cd8B6bEcf7c0F7ABc89ecCB91682ffF
PAIR_CONTRACT=93855DECcfcD71b5d181ECf71e1987E353EE8eF75C25ED226172a2770d38d328
PAIR_CONTRACT_PACKAGE=1D1b6671a573dFa566F75231eb058031DEf09C5c34E4Ac82C34a35fAf42cC6bf
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2
TOKEN0_CONTRACT_PACKAGE=4DBe7c61F20d8FF91d8de2A70919235e2DF92d8C6212ffDc06989Ae59dA19059
TOKEN1_CONTRACT=ba446757a580880faCa3B9FB52a014AB3d61C88C8B175609c44e362749D871E8
TOKEN1_CONTRACT_PACKAGE=ec9518af5E73C169B20979cf44Dd582E69FD0b9044Fb60B041c438c56e778Ff1
TOKEN0_CONTRACT=a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0
TOKEN0_CONTRACT_PACKAGE=B9F554b50D64bed3AbBD50dc11D368B5682ceC62faC5b235b190b05d4be16158
TOKEN1_CONTRACT=2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A
TOKEN1_CONTRACT_PACKAGE=d59E12EEdeC37CCC70b3b58d85828B020b8311AE8D423Ab0f7da02b1fEd55B8A

WETH_CONTRACT=2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A
WETH_CONTRACT_PACKAGE=d59E12EEdeC37CCC70b3b58d85828B020b8311AE8D423Ab0f7da02b1fEd55B8A

DAI_CONTRACT=a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0
DAI_CONTRACT_PACKAGE=B9F554b50D64bed3AbBD50dc11D368B5682ceC62faC5b235b190b05d4be16158

USDC_CONTRACT=EE26EFaD06408306D167fD2DB83bf00fEef8268C50a8AAbEA8cfDF18A2C4EFB8
USDC_CONTRACT_PACKAGE=6E3390030139474Acc0c461ab8Ddf7416A8E1112DDaB90E3A6a337B7929571E3

USDT_CONTRACT=077075BD6876a372cC2A60B078aD95C8B49Bd953C9C76d1b90D437Bf9c0369c3
USDT_CONTRACT_PACKAGE=57b3af09CC84B8233CE3dDe6B16db2612e2E03fc885DFeA4626A4c56FB1C5a8E

WETH_DAI_CONTRACT=93855DECcfcD71b5d181ECf71e1987E353EE8eF75C25ED226172a2770d38d328
WETH_DAI_CONTRACT_PACKAGE=1D1b6671a573dFa566F75231eb058031DEf09C5c34E4Ac82C34a35fAf42cC6bf

WETH_USDC_CONTRACT=D1aAfd97D233249aab1F8a8Bd7a9D30f411ADd645bD29Dd02fe4610300e80A31
WETH_USDC_CONTRACT_PACKAGE=03733EECb9a6c0701c47B1B5c4926D445CE087FeFf2AE4d3d226b82C6468C7DA

WETH_USDT_CONTRACT=e40798524C0d6F7c7a82B74Bc097e8daC114e30b1daC9CDfF91a1bCB6FDC02c1
WETH_USDT_CONTRACT_PACKAGE=81f7788FAd812C0bCE553B38F30a279a769d712cB01a9C052C6d99959DBD6F33


GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand All @@ -29,9 +51,9 @@ PAIR_MASTER_KEY_PAIR_PATH=JsClients/PAIR/keys/
MASTER_KEY_PAIR_PATH=JsClients/ROUTER/keys/

ERC20_CONTRACT_NAME=erc20
ERC20_TOKEN_NAME=token1
ERC20_TOKEN_SYMBOL=erc
ERC20_DECIMALS=18
ERC20_TOKEN_NAME=USDT
ERC20_TOKEN_SYMBOL=USDT
ERC20_DECIMALS=6
ERC20_TOTAL_SUPPLY=0

PAIR_CONTRACT_NAME=pair
Expand All @@ -43,8 +65,8 @@ PAIR_TOTAL_SUPPLY=0
FACTORY_CONTRACT_NAME=Factory

ERC20_INSTALL_PAYMENT_AMOUNT=200000000000
FACTORY_INSTALL_PAYMENT_AMOUNT=110000000000
PAIR_INSTALL_PAYMENT_AMOUNT=250000000000
FACTORY_INSTALL_PAYMENT_AMOUNT=150000000000
PAIR_INSTALL_PAYMENT_AMOUNT=300000000000

MINT_PAYMENT_AMOUNT=5000000000
MINT_AMOUNT=2000
Expand Down Expand Up @@ -81,13 +103,13 @@ TOKEN_NAME=uniswap-router
TOKEN_SYMBOL=DRAG
TOKEN_META=origin fire,lifetime infinite

FACTORY=e135359661bd6F4D0A2f827e0e25F0B1E32bb44b538676c3aECBe543F93fc54F
WCSPR=bA8f6a73B6D548E2CAe2d572aA2F824BC46A3C06a3BBA10e3d12B015931D3f85
LIBRARY=e0Dae7571C3dc5C957a36422c56BA0ccb8AECEC833F35e32874b75A8Ea8Ac4Db
FACTORY=202dffe0821C291870c864378c38fCE0BC4Fe7EA571341c62243e92608005BEe
WCSPR=Dd511B90c7f6eacd2F74f8A1B25305a2902e3554f7489e30ca0b19247AEAb031
LIBRARY=a1f2C4107B70AcefDf2A7A56A9F0B3B0839880CEF70869DBf829a8b5d25C0Bf7
CONTRACT_NAME=UniSwapRouter

CONTRACT_HASH=28b10e242d640B1a549Be1Ed5597E81019C7C6F4C90c277ed605406FF47E5134
PACKAGE_HASH=17100D7fbb04140e9739fB5ba0D71AD7a00b6f370316329Ee0553CF83783693b
CONTRACT_HASH=16031d08B9C92c20F9c702b2913091b701140371555f28323e031629F8298015
PACKAGE_HASH=66308522273D7Bc35bB99BD7cC4fB9156A2d2B2d4B3C846762BA8FDc44A9c89a
INSTALL_PAYMENT_AMOUNT=200000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
Expand All @@ -98,12 +120,12 @@ MINT_COPIES_COUNT=20
MINT_MANY_META_SIZE=5
MINT_MANY_META_COUNT=5

TO = 20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2
TO = a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0
DEADLINE = 1739598100811
# add_liquidity

TOKEN_A = 20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2
TOKEN_B = ba446757a580880faCa3B9FB52a014AB3d61C88C8B175609c44e362749D871E8
TOKEN_A = a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0
TOKEN_B = 2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A
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-----
MCowBQYDK2VwAyEA0g+BbrV8KHj7DLeH4ES/gjY2JXQLiZFW/sq0aq1hlgk=
MCowBQYDK2VwAyEAyIk/KQZh7OKw6ssepaTb25zoOvP6M2T5W4JP5IcOgiY=
-----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 @@
01d20f816eb57c2878fb0cb787e044bf82363625740b899156fecab46aad619609
01c8893f290661ece2b0eacb1ea5a4dbdb9ce83af3fa3364f95b824fe4870e8226
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-----
MC4CAQAwBQYDK2VwBCIEICzpVj2BiY8Hffjf6n5IM711VLDzBg3XBGzyw8myD6N6
MC4CAQAwBQYDK2VwBCIEIIB/afg6EcaiWg+RLrYRuJ8WZ0a2GuqvQwvUSjDwJ6mG
-----END PRIVATE KEY-----
Binary file modified JsClients/ERC20/wasm/erc20-token.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-----
MCowBQYDK2VwAyEAstkU0Ajtt7Fcn1TUQ8kTPQCuMMslDBVjPEjBvgEAWZk=
MCowBQYDK2VwAyEAsLAS66aiHSfOFII7qfF/qrlaDL3ds2ERZkmAVnuU2aE=
-----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 @@
01b2d914d008edb7b15c9f54d443c9133d00ae30cb250c15633c48c1be01005999
01b0b012eba6a21d27ce14823ba9f17faab95a0cbdddb36111664980567b94d9a1
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-----
MC4CAQAwBQYDK2VwBCIEIC5xV975frbrQNoTnw8WWSGZ6ZD08J94q9Ag6fvqGKmD
MC4CAQAwBQYDK2VwBCIEIJOWsLA4eBrtuReW6+06TpsPYEk1a409ChBTQoTzzpw2
-----END PRIVATE KEY-----
31 changes: 30 additions & 1 deletion JsClients/FACTORY/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,36 @@ class FACTORYClient {
throw Error("Invalid Deploy");
}
}

public async set_white_list(
keys: Keys.AsymmetricKey,
whitelist:string,
paymentAmount: string
) {

const white_list = new CLByteArray(
Uint8Array.from(Buffer.from(whitelist, "hex"))
);

const runtimeArgs = RuntimeArgs.fromMap({
white_list: new CLKey(white_list),
});

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

if (deployHash !== null) {
return deployHash;
} else {
throw Error("Invalid Deploy");
}
}
public async createPair(
keys: Keys.AsymmetricKey,
tokenA: String,
Expand Down
131 changes: 70 additions & 61 deletions JsClients/FACTORY/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const {
TOKEN1_CONTRACT,
PAIR_CONTRACT,
FACTORY_CONTRACT,
PACKAGE_HASH,
GRAPHQL
} = process.env;

Expand All @@ -50,54 +51,54 @@ function splitdata(data:string)

const test = async () => {

const listener = factory.onEvent(
[
FACTORYEvents.PairCreated
],
async (eventName, deploy, result) => {
if (deploy.success) {
console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
const [timestamp,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
console.log("... Timestamp: ", timestamp);
console.log("... Block hash: ", block_hash);
console.log("result.value(): ", result.value());
let newData = JSON.parse(JSON.stringify(result.value()));
// const listener = factory.onEvent(
// [
// FACTORYEvents.PairCreated
// ],
// async (eventName, deploy, result) => {
// if (deploy.success) {
// console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
// const [timestamp,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
// console.log("... Timestamp: ", timestamp);
// console.log("... Block hash: ", block_hash);
// console.log("result.value(): ", result.value());
// 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);
console.log(newData[5][0].data + " = " + newData[5][1].data);
// 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);
// console.log(newData[5][0].data + " = " + newData[5][1].data);

var allpairslength=parseInt(newData[0][1].data);
var pair=splitdata(newData[3][1].data);
var token0=splitdata(newData[4][1].data);
var token1=splitdata(newData[5][1].data);
// var allpairslength=parseInt(newData[0][1].data);
// var pair=splitdata(newData[3][1].data);
// var token0=splitdata(newData[4][1].data);
// var token1=splitdata(newData[5][1].data);

console.log("allpairslength: ", allpairslength);
console.log("pair splited: ", pair);
console.log("token0 splited: ", token0);
console.log("token1 splited: ", token1);

request(GRAPHQL!,
`mutation handleNewPair( $token0: String!, $token1: String!, $pair: String!, $all_pairs_length: Int!, $timeStamp: String!, $blockHash: String!){
handleNewPair( token0: $token0, token1: $token1, pair: $pair, all_pairs_length: $all_pairs_length, timeStamp: $timeStamp, blockHash: $blockHash) {
result
}
// console.log("allpairslength: ", allpairslength);
// console.log("pair splited: ", pair);
// console.log("token0 splited: ", token0);
// console.log("token1 splited: ", token1);

// request(GRAPHQL!,
// `mutation handleNewPair( $token0: String!, $token1: String!, $pair: String!, $all_pairs_length: Int!, $timeStamp: String!, $blockHash: String!){
// handleNewPair( token0: $token0, token1: $token1, pair: $pair, all_pairs_length: $all_pairs_length, timeStamp: $timeStamp, blockHash: $blockHash) {
// result
// }

}`,
{token0:token0, token1:token1, pair: pair, all_pairs_length: allpairslength, timeStamp:timestamp.toString(), blockHash:block_hash})
.then(data => console.log(data))
.catch(error => console.error(error));

} else {
console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`);
console.log(`Error: ${deploy.error}`);
}
}
);
// }`,
// {token0:token0, token1:token1, pair: pair, all_pairs_length: allpairslength, timeStamp:timestamp.toString(), blockHash:block_hash})
// .then(data => console.log(data))
// .catch(error => console.error(error));

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

await sleep(5 * 1000);

Expand Down Expand Up @@ -126,18 +127,26 @@ const test = async () => {
// console.log(`... Contract allpairs: ${allpairs}`);

//createpair
const createpairDeployHash = await factory.createPair(
// const createpairDeployHash = await factory.createPair(
// KEYS,
// TOKEN0_CONTRACT!,
// TOKEN1_CONTRACT!,
// PAIR_CONTRACT!,
// CREATE_PAIR_PAYMENT_AMOUNT!
// );
// console.log("... CreatePair deploy hash: ", createpairDeployHash);

// await getDeploy(NODE_ADDRESS!, createpairDeployHash);
// console.log("... Pair created successfully");
const set_white_list_deployHash = await factory.set_white_list(
KEYS,
TOKEN0_CONTRACT!,
TOKEN1_CONTRACT!,
PAIR_CONTRACT!,
PACKAGE_HASH!,
CREATE_PAIR_PAYMENT_AMOUNT!
);
console.log("... CreatePair deploy hash: ", createpairDeployHash);

await getDeploy(NODE_ADDRESS!, createpairDeployHash);
console.log("... Pair created successfully");
console.log("... Set WhiteList deploy hash: ", set_white_list_deployHash);

await getDeploy(NODE_ADDRESS!, set_white_list_deployHash);
console.log("... Router is whitelisted successfully.");

// //allpairs
// const allPairs = await factory.allPairs();
Expand Down Expand Up @@ -200,18 +209,18 @@ const test = async () => {

// };

// export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => {
export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => {

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

// // We don't need hash- prefix so i'm removing it
// await factory.setContractHash(contractHash);
// We don't need hash- prefix so i'm removing it
await factory.setContractHash(contractHash);

// //pair
// let pair = await factory.getPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT);
// console.log(`... Pair: ${pair}`);
//pair
let pair = await factory.getPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT);
console.log(`... Pair: ${pair}`);

// return pair;
return pair;

// };
};

Binary file modified JsClients/FACTORY/wasm/factory.wasm
Binary file not shown.
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-----
MCowBQYDK2VwAyEAD1kE+NGCqK8ZWlbdHdZpydKs3WjAvRCjJsoK7AyLFCU=
MCowBQYDK2VwAyEA8NpIG/A3BM4sTwBpvzwd2lLSbxkOwV9EgB2zNyF+jGE=
-----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 @@
010f5904f8d182a8af195a56dd1dd669c9d2acdd68c0bd10a326ca0aec0c8b1425
01f0da481bf03704ce2c4f0069bf3c1dda52d26f190ec15f44801db337217e8c61
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-----
MC4CAQAwBQYDK2VwBCIEIKLUePR5NlWUtM+/OGb5iQm4AkH8n2tlkUtUzSvRAVwA
MC4CAQAwBQYDK2VwBCIEICkMp/OULXfRk3vNYWtqMsfTC4YGuhtFGZd/pBCCy0G+
-----END PRIVATE KEY-----
14 changes: 12 additions & 2 deletions JsClients/PAIR/src/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,19 @@ class PAIRClient {
);
return result.value();
}

public async balanceOf_router(account: CLPublicKey) {
const accountHash = Buffer.from(account.toAccountHash()).toString("hex");
console.log("accoutnHash: ",accountHash);
const result = await utils.contractDictionaryGetter(
this.nodeAddress,
accountHash,
this.namedKeys.balances
);
const maybeValue = result.value().unwrap();
return maybeValue.value().toString();
}
public async balanceOf(accountHash: string) {
//const accountHash = Buffer.from(account.toAccountHash()).toString("hex");
console.log("accoutnHash: ",accountHash);
const result = await utils.contractDictionaryGetter(
this.nodeAddress,
accountHash,
Expand Down
7 changes: 0 additions & 7 deletions JsClients/PAIR/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,10 @@ export const getAccountInfo = async (
nodeAddress: string,
publicKey: CLPublicKey
) => {
// console.log("nodeAddress", nodeAddress);
// console.log("publicKey", publicKey);

const stateRootHash = await getStateRootHash(nodeAddress);
// console.log("stateRootHash", stateRootHash);
const client = new CasperServiceByJsonRPC(nodeAddress);
// console.log("client", client);
const accountHash = publicKey.toAccountHashStr();
// console.log("accountHash", accountHash);
const blockState = await client.getBlockState(stateRootHash, accountHash, []);
// console.log("blockState", blockState);
return blockState.Account;
};

Expand Down
Loading

0 comments on commit 5ebbcf9

Please sign in to comment.