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

Commit

Permalink
code working with new listener flow , mutation sequence issue also re…
Browse files Browse the repository at this point in the history
…solved
  • Loading branch information
Hammad-Mubeen committed Dec 17, 2021
1 parent f9eeb03 commit 87a78ec
Show file tree
Hide file tree
Showing 26 changed files with 721 additions and 164 deletions.
29 changes: 15 additions & 14 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ 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=BE48B5C9cfb0901A57db92fCB1b97d31Bfe536439efdC54a94f4C8bd1508Fc3C
PAIR_CONTRACT=Cfc208B9cd2fb35918D621D4002e378579382131d9D3011ff5A47aF36e603b2F
PAIR_CONTRACT_PACKAGE=1A89d4cDC6735c6c68D206b1C6c5c5c62ED96954F893A028Fa33E54C556B99AB
FACTORY_CONTRACT=e135359661bd6F4D0A2f827e0e25F0B1E32bb44b538676c3aECBe543F93fc54F
FACTORY_CONTRACT_PACKAGE=9e00eE28318CDD9Ea3fc83eEad5EbEE916A798565d930b14638f196E725d537a
PAIR_CONTRACT=5B4C9719f6dac2F551bF0100Ff85B1469A1Ffd0F3b03Fd44125845404dF892a9
PAIR_CONTRACT_PACKAGE=9b0C92894Bb7E9C0E657B2ba505C69263e435082Ac37dF982827061B86966B24
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=E3F80775fddda7872185705BAAcc07aae66cFa5a07D5445D64D0C01642428D2d
TOKEN0_CONTRACT_PACKAGE=De0Ea05d65072DE515d6400f3Cf0FD2169A45938902C56B109BBAe62c4677955
TOKEN1_CONTRACT=f3c553Bed5D57B87FB1e7fDe02eC2a0355d64c0faD2fE872cB6DcC115197c1fe
TOKEN1_CONTRACT_PACKAGE=555282981d63c7fD7b66A4cDd747Ee30f9cdfC024b3bd2d918314e8b9A25b25C
TOKEN0_CONTRACT=20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2
TOKEN0_CONTRACT_PACKAGE=4DBe7c61F20d8FF91d8de2A70919235e2DF92d8C6212ffDc06989Ae59dA19059
TOKEN1_CONTRACT=ba446757a580880faCa3B9FB52a014AB3d61C88C8B175609c44e362749D871E8
TOKEN1_CONTRACT_PACKAGE=ec9518af5E73C169B20979cf44Dd582E69FD0b9044Fb60B041c438c56e778Ff1

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand Down Expand Up @@ -80,13 +81,13 @@ TOKEN_NAME=uniswap-router
TOKEN_SYMBOL=DRAG
TOKEN_META=origin fire,lifetime infinite

FACTORY=BE48B5C9cfb0901A57db92fCB1b97d31Bfe536439efdC54a94f4C8bd1508Fc3C
FACTORY=e135359661bd6F4D0A2f827e0e25F0B1E32bb44b538676c3aECBe543F93fc54F
WCSPR=bA8f6a73B6D548E2CAe2d572aA2F824BC46A3C06a3BBA10e3d12B015931D3f85
LIBRARY=e0Dae7571C3dc5C957a36422c56BA0ccb8AECEC833F35e32874b75A8Ea8Ac4Db
CONTRACT_NAME=UniSwapRouter

CONTRACT_HASH=10c1405f84E629D0678620BaFCbaf0EDdE598e8717007B33A401458224c46dE7
PACKAGE_HASH=C8B976d8d1e122B1baEc32dd06c9DAA89f5277C1eB11ADd2414a23a273741258
CONTRACT_HASH=28b10e242d640B1a549Be1Ed5597E81019C7C6F4C90c277ed605406FF47E5134
PACKAGE_HASH=17100D7fbb04140e9739fB5ba0D71AD7a00b6f370316329Ee0553CF83783693b
INSTALL_PAYMENT_AMOUNT=200000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
Expand All @@ -97,12 +98,12 @@ MINT_COPIES_COUNT=20
MINT_MANY_META_SIZE=5
MINT_MANY_META_COUNT=5

TO = E3F80775fddda7872185705BAAcc07aae66cFa5a07D5445D64D0C01642428D2d
DEADLINE = 1639403428465
TO = 20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2
DEADLINE = 1739598100811
# add_liquidity

TOKEN_A = E3F80775fddda7872185705BAAcc07aae66cFa5a07D5445D64D0C01642428D2d
TOKEN_B = f3c553Bed5D57B87FB1e7fDe02eC2a0355d64c0faD2fE872cB6DcC115197c1fe
TOKEN_A = 20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2
TOKEN_B = ba446757a580880faCa3B9FB52a014AB3d61C88C8B175609c44e362749D871E8
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-----
MCowBQYDK2VwAyEAs0KvzrC+3c3b48+M5hiTCBzTc1HVJZtYE+7n/r9r+dU=
MCowBQYDK2VwAyEA0g+BbrV8KHj7DLeH4ES/gjY2JXQLiZFW/sq0aq1hlgk=
-----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 @@
01b342afceb0beddcddbe3cf8ce61893081cd37351d5259b5813eee7febf6bf9d5
01d20f816eb57c2878fb0cb787e044bf82363625740b899156fecab46aad619609
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-----
MC4CAQAwBQYDK2VwBCIEIEAEVlLDzYh9hwBwLu3H2fsQVUrEZKJs+UblNZ9N0WhS
MC4CAQAwBQYDK2VwBCIEICzpVj2BiY8Hffjf6n5IM711VLDzBg3XBGzyw8myD6N6
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion JsClients/ERC20/test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const test = async () => {
`${ERC20_CONTRACT_NAME!}_package_hash`
);

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

//test();
18 changes: 9 additions & 9 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,16 @@ const test = async () => {
// // console.log(`... Total supply: ${totalSupply}`);

//approve
// const approveDeployHash = await erc20.approve(
// ROUTERKEYS,
// PACKAGE_HASH!,
// AMOUNT_A_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
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-----
MCowBQYDK2VwAyEA4Uucv/tdlBPn+RuHu0L5ihGGJlO2MwC85wbbjmCC1so=
MCowBQYDK2VwAyEAstkU0Ajtt7Fcn1TUQ8kTPQCuMMslDBVjPEjBvgEAWZk=
-----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 @@
01e14b9cbffb5d9413e7f91b87bb42f98a11862653b63300bce706db8e6082d6ca
01b2d914d008edb7b15c9f54d443c9133d00ae30cb250c15633c48c1be01005999
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-----
MC4CAQAwBQYDK2VwBCIEIBptGPvy3geNeR1+Ses6LnNP9+dYYRtSy9I2jnr2N+V7
MC4CAQAwBQYDK2VwBCIEIC5xV975frbrQNoTnw8WWSGZ6ZD08J94q9Ag6fvqGKmD
-----END PRIVATE KEY-----
8 changes: 8 additions & 0 deletions JsClients/FACTORY/test/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ const test = async () => {
);

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

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

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

};

//test();
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-----
MCowBQYDK2VwAyEAWCo4o5U2zNgRQan9mjlKj0AfjdVcyN1tigR0wnRMPTs=
MCowBQYDK2VwAyEAD1kE+NGCqK8ZWlbdHdZpydKs3WjAvRCjJsoK7AyLFCU=
-----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 @@
01582a38a39536ccd81141a9fd9a394a8f401f8dd55cc8dd6d8a0474c2744c3d3b
010f5904f8d182a8af195a56dd1dd669c9d2acdd68c0bd10a326ca0aec0c8b1425
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-----
MC4CAQAwBQYDK2VwBCIEIFCrU4+IUFtE+Clin5T6gCH05T11RteCOhbzNRzezBl9
MC4CAQAwBQYDK2VwBCIEIKLUePR5NlWUtM+/OGb5iQm4AkH8n2tlkUtUzSvRAVwA
-----END PRIVATE KEY-----
30 changes: 30 additions & 0 deletions JsClients/PAIR/src/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,36 @@ class PAIRClient {
throw Error("Invalid Deploy");
}
}
public async erc20Mint_router(
keys: Keys.AsymmetricKey,
to: RecipientType,
amount: string,
paymentAmount: string
) {

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


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

if (deployHash !== null) {
this.addPendingDeploy(PAIREvents.Transfer, deployHash);
return deployHash;
} else {
throw Error("Invalid Deploy");
}
}
public async erc20Mint(
keys: Keys.AsymmetricKey,
to: String,
Expand Down
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 Package Hash: ${packageHash}`);
console.log(`... Package Hash: ${packageHash}`);

};

Expand Down
44 changes: 30 additions & 14 deletions JsClients/PAIR/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const {
PAIR_CONTRACT_PACKAGE,
PAIR_CONTRACT_NAME,
GRAPHQL,
PAIR_CONTRACT
PAIR_CONTRACT,
MASTER_KEY_PAIR_PATH
} = process.env;

// const TOKEN_META = new Map(parseTokenMeta(process.env.TOKEN_META!));
Expand All @@ -47,7 +48,10 @@ const KEYS = Keys.Ed25519.parseKeyFiles(
`${PAIR_MASTER_KEY_PAIR_PATH}/public_key.pem`,
`${PAIR_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 pair = new PAIRClient(
NODE_ADDRESS!,
CHAIN_NAME!,
Expand Down Expand Up @@ -330,12 +334,12 @@ const test = async () => {
await pair.setContractHash(PAIR_CONTRACT!);

//name
const name = await pair.name();
console.log(`... Contract name: ${name}`);
// const name = await pair.name();
// console.log(`... Contract name: ${name}`);

//symbol
const symbol = await pair.symbol();
console.log(`... Contract symbol: ${symbol}`);
// //symbol
// const symbol = await pair.symbol();
// console.log(`... Contract symbol: ${symbol}`);

//initialize
// const initializeDeployHash = await pair.initialize(
Expand Down Expand Up @@ -398,9 +402,9 @@ const test = async () => {
// console.log(`... Total supply: ${totalSupply}`);

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

// //balanceof
// let nonce = await pair.nonce(KEYS.publicKey);
Expand All @@ -426,8 +430,20 @@ const test = async () => {
// //erc20mint
// const erc20mint1DeployHash = await pair.erc20Mint(
// KEYS,
// TOKEN1_CONTRACT!,
// "1000"!,
// PAIR_CONTRACT_PACKAGE!,
// "2000",
// MINT_PAYMENT_AMOUNT!
// );
// console.log("... Mint deploy hash: ", erc20mint1DeployHash);

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

//erc20mint
// const erc20mint1DeployHash = await pair.erc20Mint_router(
// KEYS,
// ROUTERKEYS.publicKey!,
// "2000",
// MINT_PAYMENT_AMOUNT!
// );
// console.log("... Mint deploy hash: ", erc20mint1DeployHash);
Expand Down Expand Up @@ -513,7 +529,7 @@ const test = async () => {
//erc20mint
// const erc20MintToken0DeployHash = await pair.erc20MintMethod(
// KEYS,
// TOKEN0_CONTRACT!,
// PAIR_CONTRACT_PACKAGE!,
// "1000"!,
// MINT_PAYMENT_AMOUNT!
// );
Expand Down Expand Up @@ -577,7 +593,7 @@ const test = async () => {

};

//test();
test();

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

Expand Down
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-----
MCowBQYDK2VwAyEAisk1o1Ahn6RwyosEG9ryFSjKyUPlZdBlAK1atB5zc54=
MCowBQYDK2VwAyEAz2L03zDo9qgBL8DwJwWFKkHTNy7tj2w/nvRG8CUISLs=
-----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 @@
018ac935a350219fa470ca8b041bdaf21528cac943e565d06500ad5ab41e73739e
01cf62f4df30e8f6a8012fc0f02705852a41d3372eed8f6c3f9ef446f0250848bb
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-----
MC4CAQAwBQYDK2VwBCIEIG6psKFljoJdMK/HvjRVt50w7+DrrivkvHf7ICB9KM3s
MC4CAQAwBQYDK2VwBCIEINSB9zUWCLJXgm2b5Z06zwzZek9651oGKGEC63nLgqdn
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion JsClients/ROUTER/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,4 @@ const test = async () => {

};

//test();
test();
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ app.use((req, res, next) => {
app.get("/", (req, res) => {
res.json({ msg: "Uniswap V2 GraphQL Server" });
});
app.use('/listener', listenerRouter);
app.use('/', listenerRouter);

app.use('/graphql', graphqlHTTP({
schema: schema,
Expand Down
Loading

0 comments on commit 87a78ec

Please sign in to comment.