Skip to content

Commit

Permalink
switch from ethers to viem; remove bridgeworld endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Sep 12, 2024
1 parent a11fd94 commit 2b636e4
Show file tree
Hide file tree
Showing 21 changed files with 4,865 additions and 2,690 deletions.
10 changes: 0 additions & 10 deletions .eslintrc.json

This file was deleted.

28 changes: 28 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FlatCompat } from "@eslint/eslintrc";
import js from "@eslint/js";
import jest from "eslint-plugin-jest";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
...compat.extends("prettier"),
{
plugins: {
jest,
},

languageOptions: {
globals: {},
ecmaVersion: "latest",
sourceType: "script",
},
},
];
7,100 changes: 4,712 additions & 2,388 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
"prepare": "husky"
},
"dependencies": {
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/contracts": "^5.6.2",
"@ethersproject/providers": "^5.6.8",
"@ethersproject/units": "^5.6.1",
"axios": "^1.1.3"
"axios": "^1.1.3",
"viem": "^2.21.6"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"eslint": "^8.9.0",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.0.4",
"eslint-plugin-jest": "^28.8.3",
"husky": "^9.0.11",
"jest": "^29.0.1",
"lint-staged": "^15.2.2",
Expand Down
21 changes: 0 additions & 21 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ functions:
path: /upbit-feed
method: get
# /bridgeworld
getCorruption:
handler: src/handlers/bridgeworld.getCorruption
events:
- httpApi:
path: /bridgeworld/corruption
method: get
getMines:
handler: src/handlers/bridgeworld.getMines
events:
- httpApi:
path: /mines
method: get
- httpApi:
path: /bridgeworld/mines
method: get
getLegionHolders:
handler: src/handlers/bridgeworld.getLegionHolders
verifyGenesisLegionHolders:
Expand All @@ -82,12 +67,6 @@ functions:
- httpApi:
path: /bridgeworld/legions/verify
method: post
verifyHarvesterAccess:
handler: src/handlers/bridgeworld.verifyHarvesterAccess
events:
- httpApi:
path: /bridgeworld/harvesters/{id}/verify
method: post
# /beacon
verifyBeaconHolders:
handler: src/handlers/beacon.verifyBeaconHolders
Expand Down
5 changes: 0 additions & 5 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
module.exports = {
// Addresses
BURN_ADDRESS: "0x0000000000000000000000000000000000000000",
CONTRACT_ADVANCED_QUESTING: "0x737eaf14061fe68f04ff4ca8205acf538555fcc8",
CONTRACT_BEACON: "0x990eb28e378659b93a29d46ff41f08dc6316dd98",
CONTRACT_BEACON_PETS_STAKING_RULES:
"0x2c6c166832a4b5a501dd7a4b7acc8e13fb6968ec",
CONTRACT_BEACON_QUESTING: "0xd58d40a9a1aaeebd48a90bbb8197e0772d0e9b51",
CONTRACT_BEACON_WRIT_OF_PASSAGE: "0x5d541b55763a9277f61a739f40b6021a16c2d3d8",
CONTRACT_CORRUPTION: "0x6b66d774a862539f84128f171db1940302c4671e",
CONTRACT_CRAFTING: "0xb9c9ed651eb173ca7fbc3a094da9ce33ec145a29",
CONTRACT_MAGIC: "0x539bde0d7dbd336b79148aa742883198bbf60342",
CONTRACT_MAGIC_L1: "0xB0c7a3Ba49C7a6EaBa6cD4a96C55a1391070Ac9A",
CONTRACT_MAGIC_WETH_LP: "0xb7e50106a5bd3cf21af210a755f9c8740890a8c9",
CONTRACT_MASTER_OF_COIN: "0x3563590E19d2B9216E7879D269a04ec67Ed95A87",
CONTRACT_MIDDLEMAN: "0x3ea9ceaebdeb702fcbc576710084c464431584c8",
CONTRACT_SUSHISWAP_ROUTER: "0x1b02da8cb0d097eb8d57a175b88c7d8b47997506",
CONTRACT_WETH_USDC_LP: "0x905dfcd5649217c42684f23958568e533c711aa3",
CIRCULATING_SUPPLY_EXCLUDED: {
Expand Down
20 changes: 12 additions & 8 deletions src/contracts/beaconPetsStakingRules.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const { Contract } = require("@ethersproject/contracts");
const { CONTRACT_BEACON_PETS_STAKING_RULES } = require("../constants");
const { arbitrumProvider } = require("../utils/provider");
const { arbitrumClient } = require("../utils/provider");
const { parseAbi } = require("viem");

const beaconPetsStakingRules = new Contract(
CONTRACT_BEACON_PETS_STAKING_RULES,
["function beaconPetsAmountStaked(address) view returns (uint256)"],
arbitrumProvider
);
const abi = parseAbi([
"function beaconPetsAmountStaked(address) view returns (uint256)",
]);

module.exports = beaconPetsStakingRules;
exports.getBeaconPetsAmountStaked = async (address) =>
arbitrumClient.readContract({
address: CONTRACT_BEACON_PETS_STAKING_RULES,
abi,
functionName: "beaconPetsAmountStaked",
args: [address],
});
20 changes: 12 additions & 8 deletions src/contracts/beaconQuesting.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const { Contract } = require("@ethersproject/contracts");
const { CONTRACT_BEACON_QUESTING } = require("../constants");
const { arbitrumProvider } = require("../utils/provider");
const { arbitrumClient } = require("../utils/provider");
const { parseAbi } = require("viem");

const beaconQuesting = new Contract(
CONTRACT_BEACON_QUESTING,
["function getUserQuests(address) view returns (uint128,uint128,uint128)"],
arbitrumProvider
);
const abi = parseAbi([
"function getUserQuests(address) view returns (uint128,uint128,uint128)",
]);

module.exports = beaconQuesting;
exports.getUserQuests = async (address) =>
arbitrumClient.readContract({
address: CONTRACT_BEACON_QUESTING,
abi,
functionName: "getUserQuests",
args: [address],
});
18 changes: 10 additions & 8 deletions src/contracts/beaconWritOfPassage.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const { Contract } = require("@ethersproject/contracts");
const { CONTRACT_BEACON_WRIT_OF_PASSAGE } = require("../constants");
const { arbitrumProvider } = require("../utils/provider");
const { arbitrumClient } = require("../utils/provider");
const { parseAbi } = require("viem");

const beaconWritOfPassage = new Contract(
CONTRACT_BEACON_WRIT_OF_PASSAGE,
["function balanceOf(address) view returns (uint256)"],
arbitrumProvider
);
const abi = parseAbi(["function balanceOf(address) view returns (uint256)"]);

module.exports = beaconWritOfPassage;
exports.getWritOfPassageBalance = async (address) =>
arbitrumClient.readContract({
address: CONTRACT_BEACON_WRIT_OF_PASSAGE,
abi,
functionName: "balanceOf",
args: [address],
});
31 changes: 0 additions & 31 deletions src/contracts/corruption.js

This file was deleted.

37 changes: 23 additions & 14 deletions src/contracts/magic.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
const { Contract } = require("@ethersproject/contracts");
const { CONTRACT_MAGIC, CONTRACT_MAGIC_L1 } = require("../constants");
const { erc20Abi } = require("viem");
const { CONTRACT_MAGIC_L1, CONTRACT_MAGIC } = require("../constants");
const { parseNumber } = require("../utils/number");
const { arbitrumProvider, ethereumProvider } = require("../utils/provider");

const erc20Abi = [
"function balanceOf(address) view returns (uint256)",
"function totalSupply() view returns (uint256)",
];

const magic = new Contract(CONTRACT_MAGIC, erc20Abi, arbitrumProvider);

const magicL1 = new Contract(CONTRACT_MAGIC_L1, erc20Abi, ethereumProvider);
const { arbitrumClient, ethereumClient } = require("../utils/provider");

exports.getMagicTotalSupply = async () =>
parseNumber(await magicL1.totalSupply());
parseNumber(
await ethereumClient.readContract({
address: CONTRACT_MAGIC_L1,
abi: erc20Abi,
functionName: "totalSupply",
})
);

exports.getMagicBalanceOf = async (address, isL1 = false) =>
parseNumber(
isL1 ? await magicL1.balanceOf(address) : await magic.balanceOf(address)
isL1
? await ethereumClient.readContract({
address: CONTRACT_MAGIC_L1,
abi: erc20Abi,
functionName: "balanceOf",
args: [address],
})
: await arbitrumClient.readContract({
address: CONTRACT_MAGIC,
abi: erc20Abi,
functionName: "balanceOf",
args: [address],
})
);
13 changes: 0 additions & 13 deletions src/contracts/masterOfCoin.js

This file was deleted.

22 changes: 0 additions & 22 deletions src/contracts/middleman.js

This file was deleted.

34 changes: 17 additions & 17 deletions src/contracts/uniswapV2Pair.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const { Contract } = require("@ethersproject/contracts");
const { arbitrumProvider } = require("../utils/provider");
const { arbitrumClient } = require("../utils/provider");
const { parseAbi } = require("viem");

exports.createPairContract = (address) =>
new Contract(
address,
[
"function getReserves() view returns (uint112,uint112,uint32)",
"function totalSupply() view returns (uint256)",
],
arbitrumProvider
);
const abi = parseAbi([
"function getReserves() view returns (uint112,uint112,uint32)",
"function totalSupply() view returns (uint256)",
]);

exports.getPairReserves = async (address) => {
const [reserve0, reserve1] =
await this.createPairContract(address).getReserves();
const [reserve0, reserve1] = await arbitrumClient.readContract({
address,
abi,
functionName: "getReserves",
});
return {
reserve0,
reserve1,
};
};

exports.getPairTotalSupply = async (address) => {
const totalSupply = await this.createPairContract(address).totalSupply();
return totalSupply;
};
exports.getPairTotalSupply = async (address) =>
arbitrumClient.readContract({
address,
abi,
functionName: "totalSupply",
});
20 changes: 11 additions & 9 deletions src/contracts/uniswapV2Router.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const { Contract } = require("@ethersproject/contracts");
const { arbitrumProvider } = require("../utils/provider");
const { parseAbi } = require("viem");
const { arbitrumClient } = require("../utils/provider");

exports.createRouterContract = (address) =>
new Contract(
address,
["function quote(uint256,uint256,uint256) view returns (uint256)"],
arbitrumProvider
);
const abi = parseAbi([
"function quote(uint256,uint256,uint256) view returns (uint256)",
]);

exports.getQuote = async (address, amount0, reserve0, reserve1) =>
await this.createRouterContract(address).quote(amount0, reserve0, reserve1);
arbitrumClient.readContract({
address,
abi,
functionName: "quote",
args: [amount0, reserve0, reserve1],
});
16 changes: 0 additions & 16 deletions src/handlers/bridgeworld.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
const {
getCorruption,
getMines,
getLegionHolders,
hasGenesisLegion,
hasHarvesterAccess,
} = require("../services/bridgeworld");
const { parseVulcanWallets } = require("../utils/vulcan");

exports.getCorruption = getCorruption;

exports.getMines = getMines;

exports.getLegionHolders = getLegionHolders;

exports.verifyGenesisLegionHolders = async (event) => {
Expand All @@ -20,12 +13,3 @@ exports.verifyGenesisLegionHolders = async (event) => {
success: await hasGenesisLegion(wallets),
};
};

exports.verifyHarvesterAccess = async (event) => {
const wallets = parseVulcanWallets(event);
const id = event.pathParameters.id.toLowerCase();
console.log("Querying Harvester access for wallets:", id, wallets);
return {
success: await hasHarvesterAccess(id, wallets),
};
};
Loading

0 comments on commit 2b636e4

Please sign in to comment.