UNPKG

amgi-ts

Version:

Typescript SDK for interacting with various AMGI Studios Eth Contracts.

131 lines (110 loc) 3.96 kB
import { AddressLike, ContractEventPayload, JsonRpcProvider, WebSocketProvider, } from "ethers"; import { AMGI } from "../src"; import { Token } from "../src/token"; const sleep = require("util").promisify(setTimeout); describe("AMGI TS SDK", () => { const govAddress = "0x692485A6a31cB893f5704F37C839a580BB6166Ce"; const tokenAddress = "0x2404cE9DDc3384A1a77954B3dE9AF2A7eD7489B3"; // Karrat Coin const usdcAddress = "0xd98B590ebE0a3eD8C144170bA4122D402182976f"; //USDC const tlAddress = "0x5b56F03B0D37f1877d818B50CcA63396D70000AC"; const marketplace = "0x09fDFf97d8d1C6F739e74eCe24AdC7fF30e6E8D0"; const hooligansAddress = "0x048D66a80fbC2A2F7ec9d78014c8a60591236154"; const alchemy_api_key = "s65osOQ2h6eC4QSFYNGW6UBc2m3C3b0X"; const rpcProvider = new JsonRpcProvider( `https://eth-sepolia.g.alchemy.com/v2/${alchemy_api_key}`, ); const wsProvider = new WebSocketProvider( `wss://eth-sepolia.g.alchemy.com/v2/${alchemy_api_key}`, ); // Example of using all of the subclasses via the main AMGI class. const amgi = new AMGI( govAddress, tokenAddress, tlAddress, marketplace, hooligansAddress, hooligansAddress, rpcProvider, ); // Example of using a specific subclass on it's own. const usdc = new Token(usdcAddress, rpcProvider); xit("Token: Get Approvals", async () => { let res = await amgi.karrat.fetch.approval(); console.log(res); }); xit("Token: Balance Of", async () => { let res = await amgi.karrat.fetch.balanceOf( "0x0930d3a334f4bcBea6e9FEC01f325f409220F50A", ); console.log(res); }); xit("Gov: Get Proposals Created.", async () => { let res = await amgi.winvote.fetch.proposalCreated(); console.log(res); }); xit("Gov: Voting Delay", async () => { let res = await amgi.karrat.fetch.totalSupply(); console.log(res); }); xit("Gov: ballot_typehash", async () => { let res = await amgi.winvote.fetch.countingMode(); console.log(res); }); xit("Timelock: Get Role Granted", async () => { let res = await amgi.timelock.fetch.roleGranted(); console.log(res); }); xit("NFT: Transfer event", async () => { let block = await rpcProvider.getBlockNumber(); let res = await amgi.hooligans.fetch.transfer(block - 1000); console.log(res); }); xit("NFT: Listen to transfer event", async () => { await amgi.hooligans.events.transfer((event) => { console.log(event); }); }); xit("Marketplace: Nft Bought event", async () => { await amgi.market.events.nftBought((event) => { console.log(event); }); }); //Use USDC as a test erc20 token since it sees more sepolia action. xit("USDC: Listen to transfer event", async () => { await usdc.events.transfer((event) => { console.log(event); }); }); it("Decode Proposal Calldatas", async () => { let targets = [ "0x5b56F03B0D37f1877d818B50CcA63396D70000AC", "0x692485A6a31cB893f5704F37C839a580BB6166Ce", ]; let calldatas = [ "0x64d623530000000000000000000000000000000000000000000000000000000000001388", "0x56781388f5f800776e40983a4c1dceee4acb1415cb6af2de353bd2de8fd139d9ce1f78540000000000000000000000000000000000000000000000000000000000000001", ]; let res = amgi.winvote.coder.decode(targets, calldatas); console.log(res); let res2 = amgi.karrat.coder.decode(targets, calldatas); console.log(res2); let res3 = amgi.timelock.coder.decode(targets, calldatas); console.log(res3); // Combine all decoded parameters const allResults = [...res, ...res2, ...res3]; // Sort by original index to maintain order const sortedResults = allResults.sort((a, b) => a.index - b.index); console.log(sortedResults); }); //Runners are currently disabled to test event listeners. xit("Destroy Runners", async () => { await sleep(1000); rpcProvider.destroy(); wsProvider.destroy(); }); });