From 3f2e483d4161ce10460789ef572e9b89d80d33ae Mon Sep 17 00:00:00 2001 From: Henry Caron Date: Fri, 7 Oct 2022 15:08:23 +0100 Subject: [PATCH] feat: prettier --- contracts/DFArenaInitialize.sol | 13 +- contracts/DFInitialize.sol | 14 +- contracts/DFTypes.sol | 52 +- contracts/Verifier.sol | 571 ++++++++++---- contracts/arena/DFArenaCoreFacet.sol | 7 +- contracts/arena/DFArenaFaucet.sol | 6 +- contracts/arena/DFSpaceShipConfigFacet.sol | 20 +- contracts/facets/DFAdminFacet.sol | 12 +- contracts/facets/DFArtifactFacet.sol | 36 +- contracts/facets/DFCaptureFacet.sol | 7 +- contracts/facets/DFCoreFacet.sol | 13 +- contracts/facets/DFGetterFacet.sol | 18 +- contracts/facets/DFMoveFacet.sol | 110 ++- contracts/facets/DFStartFacet.sol | 821 ++++++++++----------- contracts/facets/DFWhitelistFacet.sol | 4 +- contracts/libraries/LibArenaStorage.sol | 38 +- contracts/libraries/LibArtifactUtils.sol | 104 ++- contracts/libraries/LibGameUtils.sol | 85 +-- contracts/libraries/LibLazyUpdate.sol | 72 +- contracts/libraries/LibPlanet.sol | 41 +- contracts/libraries/LibStorage.sol | 13 +- facets.json | 18 +- hardhat.config.ts | 4 +- package.json | 2 +- subgraph/oldschema.graphql | 2 +- subgraph/schema.graphql | 4 +- subgraph/src/arena.ts | 10 +- subgraph/src/helpers/constants.ts | 2 +- subgraph/src/helpers/elo.ts | 30 +- subgraph/src/mapping.ts | 10 +- tasks/arena-deploy.ts | 10 +- tasks/arena-upgrade.ts | 44 +- tasks/compile.ts | 9 +- tasks/deploy.ts | 12 +- test/DFArena.test.ts | 68 +- test/DFArenaUpgrade.test.ts | 26 +- test/utils/TestUtils.ts | 27 +- test/utils/TestWorld.ts | 33 +- test/utils/WorldConstants.ts | 38 +- utils/deploy.ts | 21 +- 40 files changed, 1274 insertions(+), 1153 deletions(-) diff --git a/contracts/DFArenaInitialize.sol b/contracts/DFArenaInitialize.sol index 9c4628f..4600a74 100644 --- a/contracts/DFArenaInitialize.sol +++ b/contracts/DFArenaInitialize.sol @@ -36,7 +36,7 @@ import {WithStorage} from "./libraries/LibStorage.sol"; import {WithArenaStorage} from "./libraries/LibArenaStorage.sol"; import {LibGameUtils} from "./libraries/LibGameUtils.sol"; -// Contract imports +// Contract imports import {DFWhitelistFacet} from "./facets/DFWhitelistFacet.sol"; // Type imports @@ -47,10 +47,7 @@ contract DFArenaInitialize is WithStorage, WithArenaStorage { // You can add parameters to this function in order to pass in // data to set initialize state variables - function init( - InitArgs calldata initArgs, - AuxiliaryArgs calldata auxArgs - ) external { + function init(InitArgs calldata initArgs, AuxiliaryArgs calldata auxArgs) external { // adding ERC165 data LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); ds.supportedInterfaces[type(IERC165).interfaceId] = true; @@ -80,8 +77,10 @@ contract DFArenaInitialize is WithStorage, WithArenaStorage { /* Transferring ownership here is necessary because contract owner needs to do it. */ - if(initArgs.NO_ADMIN) { - (bool success, bytes memory returndata) = address(this).delegatecall(abi.encodeWithSignature("transferOwnership(address)", address(0))); + if (initArgs.NO_ADMIN) { + (bool success, bytes memory returndata) = address(this).delegatecall( + abi.encodeWithSignature("transferOwnership(address)", address(0)) + ); require(success, "transfer ownership did not succeed"); } } diff --git a/contracts/DFInitialize.sol b/contracts/DFInitialize.sol index 5a24f81..f296566 100644 --- a/contracts/DFInitialize.sol +++ b/contracts/DFInitialize.sol @@ -25,14 +25,10 @@ import {IERC173} from "./vendor/interfaces/IERC173.sol"; import {IERC165} from "@solidstate/contracts/introspection/IERC165.sol"; import {IERC721} from "@solidstate/contracts/token/ERC721/IERC721.sol"; import {IERC721Metadata} from "@solidstate/contracts/token/ERC721/metadata/IERC721Metadata.sol"; -import { - IERC721Enumerable -} from "@solidstate/contracts/token/ERC721/enumerable/IERC721Enumerable.sol"; +import {IERC721Enumerable} from "@solidstate/contracts/token/ERC721/enumerable/IERC721Enumerable.sol"; // Inherited storage -import { - ERC721MetadataStorage -} from "@solidstate/contracts/token/ERC721/metadata/ERC721MetadataStorage.sol"; +import {ERC721MetadataStorage} from "@solidstate/contracts/token/ERC721/metadata/ERC721MetadataStorage.sol"; // Library imports import {LibDiamond} from "./vendor/libraries/LibDiamond.sol"; @@ -115,16 +111,12 @@ struct AuxiliaryArgs { address[] allowedAddresses; } - contract DFInitialize is WithStorage { using ERC721MetadataStorage for ERC721MetadataStorage.Layout; // You can add parameters to this function in order to pass in // data to set initialize state variables - function init( - InitArgs memory initArgs, - AuxiliaryArgs memory auxArgs - ) external { + function init(InitArgs memory initArgs, AuxiliaryArgs memory auxArgs) external { // adding ERC165 data LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); ds.supportedInterfaces[type(IERC165).interfaceId] = true; diff --git a/contracts/DFTypes.sol b/contracts/DFTypes.sol index 164f6d9..9f80caa 100644 --- a/contracts/DFTypes.sol +++ b/contracts/DFTypes.sol @@ -1,10 +1,27 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.0; -enum PlanetType {PLANET, SILVER_MINE, RUINS, TRADING_POST, SILVER_BANK} -enum PlanetEventType {ARRIVAL} -enum SpaceType {NEBULA, SPACE, DEEP_SPACE, DEAD_SPACE} -enum UpgradeBranch {DEFENSE, RANGE, SPEED} +enum PlanetType { + PLANET, + SILVER_MINE, + RUINS, + TRADING_POST, + SILVER_BANK +} +enum PlanetEventType { + ARRIVAL +} +enum SpaceType { + NEBULA, + SPACE, + DEEP_SPACE, + DEAD_SPACE +} +enum UpgradeBranch { + DEFENSE, + RANGE, + SPEED +} struct Player { bool isInitialized; @@ -88,7 +105,12 @@ struct PlanetEventMetadata { uint256 timeAdded; } -enum ArrivalType {Unknown, Normal, Photoid, Wormhole} +enum ArrivalType { + Unknown, + Normal, + Photoid, + Wormhole +} struct DFPInitPlanetArgs { uint256 location; @@ -195,7 +217,14 @@ enum ArtifactType { ShipTitan } -enum ArtifactRarity {Unknown, Common, Rare, Epic, Legendary, Mythic} +enum ArtifactRarity { + Unknown, + Common, + Rare, + Epic, + Legendary, + Mythic +} // for NFTs struct Artifact { @@ -287,7 +316,7 @@ enum Mod { barbarianPercentage } // # Mothership, Whale, Crescent, Gear, Titan -struct Spaceships{ +struct Spaceships { bool mothership; bool whale; bool crescent; @@ -296,13 +325,13 @@ struct Spaceships{ } struct RevealProofArgs { - uint256[2] _a; + uint256[2] _a; uint256[2][2] _b; uint256[2] _c; uint256[9] _input; } -// Values that are critical for determining if a match is valid. +// Values that are critical for determining if a match is valid. struct InitArgs { bool START_PAUSED; bool ADMIN_CAN_ADD_PLANETS; @@ -373,17 +402,15 @@ struct InitArgs { uint256 CLAIM_VICTORY_ENERGY_PERCENT; // Manual Spawn bool MANUAL_SPAWN; - uint256[8] MODIFIERS; bool[5] SPACESHIPS; - bool RANDOM_ARTIFACTS; bool NO_ADMIN; ArenaCreateRevealPlanetArgs[] INIT_PLANETS; bool CONFIRM_START; uint256 TARGETS_REQUIRED_FOR_VICTORY; bool BLOCK_MOVES; - bool BLOCK_CAPTURE; + bool BLOCK_CAPTURE; bool TEAMS_ENABLED; uint256 NUM_TEAMS; bool RANKED; @@ -395,4 +422,3 @@ struct AuxiliaryArgs { string artifactBaseURI; address[] allowedAddresses; } - diff --git a/contracts/Verifier.sol b/contracts/Verifier.sol index f5c6a1e..9114a03 100644 --- a/contracts/Verifier.sol +++ b/contracts/Verifier.sol @@ -60,9 +60,7 @@ library Pairing { function negate(G1Point memory p) internal pure returns (G1Point memory r) { // The prime q in the base field F_q for G1 - - uint256 q - = 21888242871839275222246405745257275088696311157297823662689037894645226208583; + uint256 q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; if (p.X == 0 && p.Y == 0) return G1Point(0, 0); return G1Point(p.X, q - (p.Y % q)); } @@ -84,20 +82,16 @@ library Pairing { success := staticcall(sub(gas(), 2000), 6, input, 0xc0, r, 0x60) // Use "invalid" to make gas estimation work switch success - case 0 { - invalid() - } + case 0 { + invalid() + } } require(success, "pairing-add-failed"); } /// @return r the product of a point on G1 and a scalar, i.e. /// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p. - function scalar_mul(G1Point memory p, uint256 s) - internal - view - returns (G1Point memory r) - { + function scalar_mul(G1Point memory p, uint256 s) internal view returns (G1Point memory r) { uint256[3] memory input; input[0] = p.X; input[1] = p.Y; @@ -108,9 +102,9 @@ library Pairing { success := staticcall(sub(gas(), 2000), 7, input, 0x80, r, 0x60) // Use "invalid" to make gas estimation work switch success - case 0 { - invalid() - } + case 0 { + invalid() + } } require(success, "pairing-mul-failed"); } @@ -119,11 +113,7 @@ library Pairing { /// e(p1[0], p2[0]) * .... * e(p1[n], p2[n]) == 1 /// For example pairing([P1(), P1().negate()], [P2(), P2()]) should /// return true. - function pairing(G1Point[] memory p1, G2Point[] memory p2) - internal - view - returns (bool) - { + function pairing(G1Point[] memory p1, G2Point[] memory p2) internal view returns (bool) { require(p1.length == p2.length, "pairing-lengths-failed"); uint256 elements = p1.length; uint256 inputSize = elements * 6; @@ -150,9 +140,9 @@ library Pairing { ) // Use "invalid" to make gas estimation work switch success - case 0 { - invalid() - } + case 0 { + invalid() + } } require(success, "pairing-opcode-failed"); return out[0] != 0; @@ -281,151 +271,422 @@ library Verifier { } } - - function initVerifyingKey() internal pure returns (VerifyingKey memory vk) { - vk.alfa1 = Pairing.G1Point(19642524115522290447760970021746675789341356000653265441069630957431566301675,15809037446102219312954435152879098683824559980020626143453387822004586242317); - vk.beta2 = Pairing.G2Point([6402738102853475583969787773506197858266321704623454181848954418090577674938,3306678135584565297353192801602995509515651571902196852074598261262327790404], [15158588411628049902562758796812667714664232742372443470614751812018801551665,4983765881427969364617654516554524254158908221590807345159959200407712579883]); - vk.gamma2 = Pairing.G2Point([11559732032986387107991004021392285783925812861821192530917403151452391805634,10857046999023057135944570762232829481370756359578518086990519993285655852781], [4082367875863433681332203403145435568316851327593401208105741076214120093531,8495653923123431417604973247489272438418190587263600148770280649306958101930]); - vk.delta2 = Pairing.G2Point([18267704662828490175857468095653635008950340494304706656025046218264421563470,2344071320818146231168716836162040432802924935602348858857549685326622158243], [18280538512709951070623464540045307031729718125195477913044570781581265388283,233828825626173034438586707816663535745733998365219870127731933977019917043]); + function initVerifyingKey() internal pure returns (VerifyingKey memory vk) { + vk.alfa1 = Pairing.G1Point( + 19642524115522290447760970021746675789341356000653265441069630957431566301675, + 15809037446102219312954435152879098683824559980020626143453387822004586242317 + ); + vk.beta2 = Pairing.G2Point( + [ + 6402738102853475583969787773506197858266321704623454181848954418090577674938, + 3306678135584565297353192801602995509515651571902196852074598261262327790404 + ], + [ + 15158588411628049902562758796812667714664232742372443470614751812018801551665, + 4983765881427969364617654516554524254158908221590807345159959200407712579883 + ] + ); + vk.gamma2 = Pairing.G2Point( + [ + 11559732032986387107991004021392285783925812861821192530917403151452391805634, + 10857046999023057135944570762232829481370756359578518086990519993285655852781 + ], + [ + 4082367875863433681332203403145435568316851327593401208105741076214120093531, + 8495653923123431417604973247489272438418190587263600148770280649306958101930 + ] + ); + vk.delta2 = Pairing.G2Point( + [ + 18267704662828490175857468095653635008950340494304706656025046218264421563470, + 2344071320818146231168716836162040432802924935602348858857549685326622158243 + ], + [ + 18280538512709951070623464540045307031729718125195477913044570781581265388283, + 233828825626173034438586707816663535745733998365219870127731933977019917043 + ] + ); vk.IC = new Pairing.G1Point[](9); - vk.IC[0] = Pairing.G1Point(17531213578870235445718883684233562304976213708477288992445998995601376804507,11020007233017347104228643788817224118449073620845859789404325309032346635189); - vk.IC[1] = Pairing.G1Point(20499131076683505661494774638998616986151955176355080163949571604145778145907,11199768197049668769039416971682820189684401646017949531487588200258263715008); - vk.IC[2] = Pairing.G1Point(20408326271140367608672136152128760754133561937507915180833539060059805102425,4573138649309563910746580019567350445616466905314595084059417064174176672326); - vk.IC[3] = Pairing.G1Point(1390123752446624466985441837885207966126142213166475679534781257937527362271,2477117188078022006762746849663630771207930566747726542436455627903828846195); - vk.IC[4] = Pairing.G1Point(1380358322317867368984079981108702667445211555533944812633854630683942334417,14452726077517889078508372210502051159533887617614000784130530005646617155884); - vk.IC[5] = Pairing.G1Point(2527425257475364369568539252489728055557101173716838767348784643906658305833,11239201095333311529402459316436960460484719548492091523663743451587349887713); - vk.IC[6] = Pairing.G1Point(8674626569442579055599461530412632067246932666970150281567126715483683396422,7349022829265644263275340613944031094294893683582054378004315090072534142708); - vk.IC[7] = Pairing.G1Point(3205668335204479636441669254269222007401906089492288246101646699663647979718,15904183509437572481726186560860814119942679479207916171971399768096833464679); - vk.IC[8] = Pairing.G1Point(10501577456003533178704100847639497199937874321449394776764077435933507319074,21726106362316052916572056534611914847151474733695688801050519777777573030539); + vk.IC[0] = Pairing.G1Point( + 17531213578870235445718883684233562304976213708477288992445998995601376804507, + 11020007233017347104228643788817224118449073620845859789404325309032346635189 + ); + vk.IC[1] = Pairing.G1Point( + 20499131076683505661494774638998616986151955176355080163949571604145778145907, + 11199768197049668769039416971682820189684401646017949531487588200258263715008 + ); + vk.IC[2] = Pairing.G1Point( + 20408326271140367608672136152128760754133561937507915180833539060059805102425, + 4573138649309563910746580019567350445616466905314595084059417064174176672326 + ); + vk.IC[3] = Pairing.G1Point( + 1390123752446624466985441837885207966126142213166475679534781257937527362271, + 2477117188078022006762746849663630771207930566747726542436455627903828846195 + ); + vk.IC[4] = Pairing.G1Point( + 1380358322317867368984079981108702667445211555533944812633854630683942334417, + 14452726077517889078508372210502051159533887617614000784130530005646617155884 + ); + vk.IC[5] = Pairing.G1Point( + 2527425257475364369568539252489728055557101173716838767348784643906658305833, + 11239201095333311529402459316436960460484719548492091523663743451587349887713 + ); + vk.IC[6] = Pairing.G1Point( + 8674626569442579055599461530412632067246932666970150281567126715483683396422, + 7349022829265644263275340613944031094294893683582054378004315090072534142708 + ); + vk.IC[7] = Pairing.G1Point( + 3205668335204479636441669254269222007401906089492288246101646699663647979718, + 15904183509437572481726186560860814119942679479207916171971399768096833464679 + ); + vk.IC[8] = Pairing.G1Point( + 10501577456003533178704100847639497199937874321449394776764077435933507319074, + 21726106362316052916572056534611914847151474733695688801050519777777573030539 + ); + } - } + function verifyInitProof( + uint256[2] memory a, + uint256[2][2] memory b, + uint256[2] memory c, + uint256[8] memory input + ) public view returns (bool) { + uint256[] memory inputValues = new uint256[](input.length); + for (uint256 i = 0; i < input.length; i++) { + inputValues[i] = input[i]; + } + return verifyProof(a, b, c, inputValues, initVerifyingKey()); + } - function verifyInitProof( - uint256[2] memory a, - uint256[2][2] memory b, - uint256[2] memory c, - uint256[8] memory input - ) public view returns (bool) { - uint256[] memory inputValues = new uint256[](input.length); - for (uint256 i = 0; i < input.length; i++) { - inputValues[i] = input[i]; - } - return verifyProof(a, b, c, inputValues, initVerifyingKey()); - } - function moveVerifyingKey() internal pure returns (VerifyingKey memory vk) { - vk.alfa1 = Pairing.G1Point(19642524115522290447760970021746675789341356000653265441069630957431566301675,15809037446102219312954435152879098683824559980020626143453387822004586242317); - vk.beta2 = Pairing.G2Point([6402738102853475583969787773506197858266321704623454181848954418090577674938,3306678135584565297353192801602995509515651571902196852074598261262327790404], [15158588411628049902562758796812667714664232742372443470614751812018801551665,4983765881427969364617654516554524254158908221590807345159959200407712579883]); - vk.gamma2 = Pairing.G2Point([11559732032986387107991004021392285783925812861821192530917403151452391805634,10857046999023057135944570762232829481370756359578518086990519993285655852781], [4082367875863433681332203403145435568316851327593401208105741076214120093531,8495653923123431417604973247489272438418190587263600148770280649306958101930]); - vk.delta2 = Pairing.G2Point([13513455172708837202974957688358262638643071517447653096840094011533626306516,12263036478059246982308043591535844083658286053233696445630647200185003180289], [12319181360002940907629087107963980562929965851305156399443912154228365837241,12465820389359595186726122667960410362503131421477157176194488613645867328381]); + function moveVerifyingKey() internal pure returns (VerifyingKey memory vk) { + vk.alfa1 = Pairing.G1Point( + 19642524115522290447760970021746675789341356000653265441069630957431566301675, + 15809037446102219312954435152879098683824559980020626143453387822004586242317 + ); + vk.beta2 = Pairing.G2Point( + [ + 6402738102853475583969787773506197858266321704623454181848954418090577674938, + 3306678135584565297353192801602995509515651571902196852074598261262327790404 + ], + [ + 15158588411628049902562758796812667714664232742372443470614751812018801551665, + 4983765881427969364617654516554524254158908221590807345159959200407712579883 + ] + ); + vk.gamma2 = Pairing.G2Point( + [ + 11559732032986387107991004021392285783925812861821192530917403151452391805634, + 10857046999023057135944570762232829481370756359578518086990519993285655852781 + ], + [ + 4082367875863433681332203403145435568316851327593401208105741076214120093531, + 8495653923123431417604973247489272438418190587263600148770280649306958101930 + ] + ); + vk.delta2 = Pairing.G2Point( + [ + 13513455172708837202974957688358262638643071517447653096840094011533626306516, + 12263036478059246982308043591535844083658286053233696445630647200185003180289 + ], + [ + 12319181360002940907629087107963980562929965851305156399443912154228365837241, + 12465820389359595186726122667960410362503131421477157176194488613645867328381 + ] + ); vk.IC = new Pairing.G1Point[](11); - vk.IC[0] = Pairing.G1Point(6112961102539311426682217827529916715374586533174921870934839790814150942410,19832499160025763511612785763178830119066603032122370836700086205383257629813); - vk.IC[1] = Pairing.G1Point(19020822680538417052021711254564080336598015500380007743723716108047673111153,1737570045479653024335849889049326835429067901260130611872360074074649019753); - vk.IC[2] = Pairing.G1Point(9465491379133831592115179312559626717037051591961775118019401711612357311584,18815895037272530547607134472463323340486425412539380034115915066722157939734); - vk.IC[3] = Pairing.G1Point(17473463729589101996022080985081317673952548433781824674800583439259513914653,15262701639810731437167049366368968938858127002839773369488840747106893765344); - vk.IC[4] = Pairing.G1Point(20062280434692958558268779812498960547553969285367667905779275073208759239342,10391294399407849580585245301693348125148952463746344961603693273572050002507); - vk.IC[5] = Pairing.G1Point(18957214402356060333900384336668073277292736051544504411950117391115522534813,12543034207805142839236045319774292404371241797893394345311332639138009076054); - vk.IC[6] = Pairing.G1Point(12748785046579304908986099916420623206823127411719531589626370926157904715390,21697711772767372590638424475303598434392402087988387650156972557893475637431); - vk.IC[7] = Pairing.G1Point(18061526719171057671654257875043391314527940280204502558473401655291978835364,14642432079014837552748289612197160601335905317632373427977868711108652763899); - vk.IC[8] = Pairing.G1Point(1773034170153579753051197178732529211466207075799828958257119483568980042429,3790744436499428832627793943948641318032767743023445111184665882525652941409); - vk.IC[9] = Pairing.G1Point(8886266839882441195882407287274373599262258039089773156476647342172750353291,8036388664516210353181626393234983546707599381232011673073763042417037779484); - vk.IC[10] = Pairing.G1Point(10099770477633851396481536337022227284106179163512535221580168131727400661198,8731657967091546617770736100532428855186128617365872617464904973874210644495); + vk.IC[0] = Pairing.G1Point( + 6112961102539311426682217827529916715374586533174921870934839790814150942410, + 19832499160025763511612785763178830119066603032122370836700086205383257629813 + ); + vk.IC[1] = Pairing.G1Point( + 19020822680538417052021711254564080336598015500380007743723716108047673111153, + 1737570045479653024335849889049326835429067901260130611872360074074649019753 + ); + vk.IC[2] = Pairing.G1Point( + 9465491379133831592115179312559626717037051591961775118019401711612357311584, + 18815895037272530547607134472463323340486425412539380034115915066722157939734 + ); + vk.IC[3] = Pairing.G1Point( + 17473463729589101996022080985081317673952548433781824674800583439259513914653, + 15262701639810731437167049366368968938858127002839773369488840747106893765344 + ); + vk.IC[4] = Pairing.G1Point( + 20062280434692958558268779812498960547553969285367667905779275073208759239342, + 10391294399407849580585245301693348125148952463746344961603693273572050002507 + ); + vk.IC[5] = Pairing.G1Point( + 18957214402356060333900384336668073277292736051544504411950117391115522534813, + 12543034207805142839236045319774292404371241797893394345311332639138009076054 + ); + vk.IC[6] = Pairing.G1Point( + 12748785046579304908986099916420623206823127411719531589626370926157904715390, + 21697711772767372590638424475303598434392402087988387650156972557893475637431 + ); + vk.IC[7] = Pairing.G1Point( + 18061526719171057671654257875043391314527940280204502558473401655291978835364, + 14642432079014837552748289612197160601335905317632373427977868711108652763899 + ); + vk.IC[8] = Pairing.G1Point( + 1773034170153579753051197178732529211466207075799828958257119483568980042429, + 3790744436499428832627793943948641318032767743023445111184665882525652941409 + ); + vk.IC[9] = Pairing.G1Point( + 8886266839882441195882407287274373599262258039089773156476647342172750353291, + 8036388664516210353181626393234983546707599381232011673073763042417037779484 + ); + vk.IC[10] = Pairing.G1Point( + 10099770477633851396481536337022227284106179163512535221580168131727400661198, + 8731657967091546617770736100532428855186128617365872617464904973874210644495 + ); + } - } + function verifyMoveProof( + uint256[2] memory a, + uint256[2][2] memory b, + uint256[2] memory c, + uint256[10] memory input + ) public view returns (bool) { + uint256[] memory inputValues = new uint256[](input.length); + for (uint256 i = 0; i < input.length; i++) { + inputValues[i] = input[i]; + } + return verifyProof(a, b, c, inputValues, moveVerifyingKey()); + } - function verifyMoveProof( - uint256[2] memory a, - uint256[2][2] memory b, - uint256[2] memory c, - uint256[10] memory input - ) public view returns (bool) { - uint256[] memory inputValues = new uint256[](input.length); - for (uint256 i = 0; i < input.length; i++) { - inputValues[i] = input[i]; - } - return verifyProof(a, b, c, inputValues, moveVerifyingKey()); - } - function biomebaseVerifyingKey() internal pure returns (VerifyingKey memory vk) { - vk.alfa1 = Pairing.G1Point(19642524115522290447760970021746675789341356000653265441069630957431566301675,15809037446102219312954435152879098683824559980020626143453387822004586242317); - vk.beta2 = Pairing.G2Point([6402738102853475583969787773506197858266321704623454181848954418090577674938,3306678135584565297353192801602995509515651571902196852074598261262327790404], [15158588411628049902562758796812667714664232742372443470614751812018801551665,4983765881427969364617654516554524254158908221590807345159959200407712579883]); - vk.gamma2 = Pairing.G2Point([11559732032986387107991004021392285783925812861821192530917403151452391805634,10857046999023057135944570762232829481370756359578518086990519993285655852781], [4082367875863433681332203403145435568316851327593401208105741076214120093531,8495653923123431417604973247489272438418190587263600148770280649306958101930]); - vk.delta2 = Pairing.G2Point([15094463650099294984515946413167988450372708490309144960837169145984456153410,10845002970072379152489321833267477123506269748101428941575193315961703601974], [8816164595955441273703312349532155943504904110210151922720097723036191148048,11421170772921084341073486500856950265655597370440433344362840085946941715978]); + function biomebaseVerifyingKey() internal pure returns (VerifyingKey memory vk) { + vk.alfa1 = Pairing.G1Point( + 19642524115522290447760970021746675789341356000653265441069630957431566301675, + 15809037446102219312954435152879098683824559980020626143453387822004586242317 + ); + vk.beta2 = Pairing.G2Point( + [ + 6402738102853475583969787773506197858266321704623454181848954418090577674938, + 3306678135584565297353192801602995509515651571902196852074598261262327790404 + ], + [ + 15158588411628049902562758796812667714664232742372443470614751812018801551665, + 4983765881427969364617654516554524254158908221590807345159959200407712579883 + ] + ); + vk.gamma2 = Pairing.G2Point( + [ + 11559732032986387107991004021392285783925812861821192530917403151452391805634, + 10857046999023057135944570762232829481370756359578518086990519993285655852781 + ], + [ + 4082367875863433681332203403145435568316851327593401208105741076214120093531, + 8495653923123431417604973247489272438418190587263600148770280649306958101930 + ] + ); + vk.delta2 = Pairing.G2Point( + [ + 15094463650099294984515946413167988450372708490309144960837169145984456153410, + 10845002970072379152489321833267477123506269748101428941575193315961703601974 + ], + [ + 8816164595955441273703312349532155943504904110210151922720097723036191148048, + 11421170772921084341073486500856950265655597370440433344362840085946941715978 + ] + ); vk.IC = new Pairing.G1Point[](8); - vk.IC[0] = Pairing.G1Point(16438977116044210568911832155009671321569754101732371369040679924055714282875,1387395354588441400215512468955932063195789410431230847009054545565653156562); - vk.IC[1] = Pairing.G1Point(14484893046252390986527916211706461731133486387290975738886221050301483957569,8006201431631175745028619968386424725033878733036498861014720412734125526854); - vk.IC[2] = Pairing.G1Point(7623464521121094103924956882249637001170638470884875916997964677173978257989,15448592974943659658055044318073513031677732947129539703195511120071385479046); - vk.IC[3] = Pairing.G1Point(21148935882014724541533118849605439458228920487877897760633808560783611587098,21883925494573839036138166845808148943036438299806087750697769034235309640946); - vk.IC[4] = Pairing.G1Point(21080122785507774031606964733493844965148202843756463850578399867012641758735,14607884522389665628990991538956866054616479735655596075019198065598892145833); - vk.IC[5] = Pairing.G1Point(3390828870247908556188337166895419437446883148279645682669811050816763178781,21145895878480728973707707871006183391220297705690366155517176340207154059016); - vk.IC[6] = Pairing.G1Point(8295807940057136679452070308364735524064995575844346423776265899757441378421,776898978830289146443482912681858994949239685614035624816824961055941198055); - vk.IC[7] = Pairing.G1Point(18103058483239813176004908688252632744367582002552441456225759051603597716025,11597959820219897330678226535792647106349376107700787288297495010553604338822); + vk.IC[0] = Pairing.G1Point( + 16438977116044210568911832155009671321569754101732371369040679924055714282875, + 1387395354588441400215512468955932063195789410431230847009054545565653156562 + ); + vk.IC[1] = Pairing.G1Point( + 14484893046252390986527916211706461731133486387290975738886221050301483957569, + 8006201431631175745028619968386424725033878733036498861014720412734125526854 + ); + vk.IC[2] = Pairing.G1Point( + 7623464521121094103924956882249637001170638470884875916997964677173978257989, + 15448592974943659658055044318073513031677732947129539703195511120071385479046 + ); + vk.IC[3] = Pairing.G1Point( + 21148935882014724541533118849605439458228920487877897760633808560783611587098, + 21883925494573839036138166845808148943036438299806087750697769034235309640946 + ); + vk.IC[4] = Pairing.G1Point( + 21080122785507774031606964733493844965148202843756463850578399867012641758735, + 14607884522389665628990991538956866054616479735655596075019198065598892145833 + ); + vk.IC[5] = Pairing.G1Point( + 3390828870247908556188337166895419437446883148279645682669811050816763178781, + 21145895878480728973707707871006183391220297705690366155517176340207154059016 + ); + vk.IC[6] = Pairing.G1Point( + 8295807940057136679452070308364735524064995575844346423776265899757441378421, + 776898978830289146443482912681858994949239685614035624816824961055941198055 + ); + vk.IC[7] = Pairing.G1Point( + 18103058483239813176004908688252632744367582002552441456225759051603597716025, + 11597959820219897330678226535792647106349376107700787288297495010553604338822 + ); + } - } + function verifyBiomebaseProof( + uint256[2] memory a, + uint256[2][2] memory b, + uint256[2] memory c, + uint256[7] memory input + ) public view returns (bool) { + uint256[] memory inputValues = new uint256[](input.length); + for (uint256 i = 0; i < input.length; i++) { + inputValues[i] = input[i]; + } + return verifyProof(a, b, c, inputValues, biomebaseVerifyingKey()); + } - function verifyBiomebaseProof( - uint256[2] memory a, - uint256[2][2] memory b, - uint256[2] memory c, - uint256[7] memory input - ) public view returns (bool) { - uint256[] memory inputValues = new uint256[](input.length); - for (uint256 i = 0; i < input.length; i++) { - inputValues[i] = input[i]; - } - return verifyProof(a, b, c, inputValues, biomebaseVerifyingKey()); - } - function revealVerifyingKey() internal pure returns (VerifyingKey memory vk) { - vk.alfa1 = Pairing.G1Point(19642524115522290447760970021746675789341356000653265441069630957431566301675,15809037446102219312954435152879098683824559980020626143453387822004586242317); - vk.beta2 = Pairing.G2Point([6402738102853475583969787773506197858266321704623454181848954418090577674938,3306678135584565297353192801602995509515651571902196852074598261262327790404], [15158588411628049902562758796812667714664232742372443470614751812018801551665,4983765881427969364617654516554524254158908221590807345159959200407712579883]); - vk.gamma2 = Pairing.G2Point([11559732032986387107991004021392285783925812861821192530917403151452391805634,10857046999023057135944570762232829481370756359578518086990519993285655852781], [4082367875863433681332203403145435568316851327593401208105741076214120093531,8495653923123431417604973247489272438418190587263600148770280649306958101930]); - vk.delta2 = Pairing.G2Point([375260485459814241581208907498866213370059450575498116547889312992123969120,5047854880936622981818302102067707777491036823696932983606702949346245264229], [9925594050676855793895193190329681818801838159348245653558720059559178771457,9853674502223763427949155594110810410025314948074019900239333649732776668448]); + function revealVerifyingKey() internal pure returns (VerifyingKey memory vk) { + vk.alfa1 = Pairing.G1Point( + 19642524115522290447760970021746675789341356000653265441069630957431566301675, + 15809037446102219312954435152879098683824559980020626143453387822004586242317 + ); + vk.beta2 = Pairing.G2Point( + [ + 6402738102853475583969787773506197858266321704623454181848954418090577674938, + 3306678135584565297353192801602995509515651571902196852074598261262327790404 + ], + [ + 15158588411628049902562758796812667714664232742372443470614751812018801551665, + 4983765881427969364617654516554524254158908221590807345159959200407712579883 + ] + ); + vk.gamma2 = Pairing.G2Point( + [ + 11559732032986387107991004021392285783925812861821192530917403151452391805634, + 10857046999023057135944570762232829481370756359578518086990519993285655852781 + ], + [ + 4082367875863433681332203403145435568316851327593401208105741076214120093531, + 8495653923123431417604973247489272438418190587263600148770280649306958101930 + ] + ); + vk.delta2 = Pairing.G2Point( + [ + 375260485459814241581208907498866213370059450575498116547889312992123969120, + 5047854880936622981818302102067707777491036823696932983606702949346245264229 + ], + [ + 9925594050676855793895193190329681818801838159348245653558720059559178771457, + 9853674502223763427949155594110810410025314948074019900239333649732776668448 + ] + ); vk.IC = new Pairing.G1Point[](10); - vk.IC[0] = Pairing.G1Point(20093472258310322960739439648707491987443989096296948034681187650752042939884,16094055134004625675552510687375284665938322950082541408974822166631762506105); - vk.IC[1] = Pairing.G1Point(15613310779361931296860291462885028822970431828832092274076544662729641075378,6820134408459575965728414354055628487605554970982706733513419053044278182929); - vk.IC[2] = Pairing.G1Point(9641096846292368249837540669037858187538239808484216262328261172793750007799,1292168461170339312912849581331780224132671422174877925049477019150795129472); - vk.IC[3] = Pairing.G1Point(7199456138807451939343928984153078074333209524299193713281755330465496370404,16762131771346764604148838074782338338520946340314905124779049158350465472801); - vk.IC[4] = Pairing.G1Point(8065090940887248582715706505113119382610538254281902450004487240363764487237,1555152351075046267748132262267725780201149237485996679238352383066254522793); - vk.IC[5] = Pairing.G1Point(7978903730682349542886516888109781918266113433876588438804003689034261038511,7530842648008542871388133563979955199987945870880334895073616180363635208724); - vk.IC[6] = Pairing.G1Point(20173715045467795617612642270292828720547787867971775503576652143436754462454,13640318698507230510131913881638008090701453372282276417981442789294007735617); - vk.IC[7] = Pairing.G1Point(7759318135384781626243568976698299102805218759281300176892837194569774215664,12707154976334745667337335013740171180797054690728328553817015568797059587177); - vk.IC[8] = Pairing.G1Point(13973539454090053620118121905092992239093913753699337636173705484436044517605,16802138494314836212895215000120377194363546637024043815012810890341047029389); - vk.IC[9] = Pairing.G1Point(19970370126575575396619220429929433360566643245463462951823310948831733438627,19965383054205356227338761946081677701672047359406495394037105881538177084230); + vk.IC[0] = Pairing.G1Point( + 20093472258310322960739439648707491987443989096296948034681187650752042939884, + 16094055134004625675552510687375284665938322950082541408974822166631762506105 + ); + vk.IC[1] = Pairing.G1Point( + 15613310779361931296860291462885028822970431828832092274076544662729641075378, + 6820134408459575965728414354055628487605554970982706733513419053044278182929 + ); + vk.IC[2] = Pairing.G1Point( + 9641096846292368249837540669037858187538239808484216262328261172793750007799, + 1292168461170339312912849581331780224132671422174877925049477019150795129472 + ); + vk.IC[3] = Pairing.G1Point( + 7199456138807451939343928984153078074333209524299193713281755330465496370404, + 16762131771346764604148838074782338338520946340314905124779049158350465472801 + ); + vk.IC[4] = Pairing.G1Point( + 8065090940887248582715706505113119382610538254281902450004487240363764487237, + 1555152351075046267748132262267725780201149237485996679238352383066254522793 + ); + vk.IC[5] = Pairing.G1Point( + 7978903730682349542886516888109781918266113433876588438804003689034261038511, + 7530842648008542871388133563979955199987945870880334895073616180363635208724 + ); + vk.IC[6] = Pairing.G1Point( + 20173715045467795617612642270292828720547787867971775503576652143436754462454, + 13640318698507230510131913881638008090701453372282276417981442789294007735617 + ); + vk.IC[7] = Pairing.G1Point( + 7759318135384781626243568976698299102805218759281300176892837194569774215664, + 12707154976334745667337335013740171180797054690728328553817015568797059587177 + ); + vk.IC[8] = Pairing.G1Point( + 13973539454090053620118121905092992239093913753699337636173705484436044517605, + 16802138494314836212895215000120377194363546637024043815012810890341047029389 + ); + vk.IC[9] = Pairing.G1Point( + 19970370126575575396619220429929433360566643245463462951823310948831733438627, + 19965383054205356227338761946081677701672047359406495394037105881538177084230 + ); + } - } + function verifyRevealProof( + uint256[2] memory a, + uint256[2][2] memory b, + uint256[2] memory c, + uint256[9] memory input + ) public view returns (bool) { + uint256[] memory inputValues = new uint256[](input.length); + for (uint256 i = 0; i < input.length; i++) { + inputValues[i] = input[i]; + } + return verifyProof(a, b, c, inputValues, revealVerifyingKey()); + } - function verifyRevealProof( - uint256[2] memory a, - uint256[2][2] memory b, - uint256[2] memory c, - uint256[9] memory input - ) public view returns (bool) { - uint256[] memory inputValues = new uint256[](input.length); - for (uint256 i = 0; i < input.length; i++) { - inputValues[i] = input[i]; - } - return verifyProof(a, b, c, inputValues, revealVerifyingKey()); - } - function whitelistVerifyingKey() internal pure returns (VerifyingKey memory vk) { - vk.alfa1 = Pairing.G1Point(19642524115522290447760970021746675789341356000653265441069630957431566301675,15809037446102219312954435152879098683824559980020626143453387822004586242317); - vk.beta2 = Pairing.G2Point([6402738102853475583969787773506197858266321704623454181848954418090577674938,3306678135584565297353192801602995509515651571902196852074598261262327790404], [15158588411628049902562758796812667714664232742372443470614751812018801551665,4983765881427969364617654516554524254158908221590807345159959200407712579883]); - vk.gamma2 = Pairing.G2Point([11559732032986387107991004021392285783925812861821192530917403151452391805634,10857046999023057135944570762232829481370756359578518086990519993285655852781], [4082367875863433681332203403145435568316851327593401208105741076214120093531,8495653923123431417604973247489272438418190587263600148770280649306958101930]); - vk.delta2 = Pairing.G2Point([5937324452265082694994079059241282955809587298129288028220551683857908477420,20193126291439324067855570349087139332759249767626415139734155586330544806931], [20511021038180955968672836821991916481702435917128211030586041791747308087254,4825495667610898300284773277835226666829724669887302495853279321794443468464]); + function whitelistVerifyingKey() internal pure returns (VerifyingKey memory vk) { + vk.alfa1 = Pairing.G1Point( + 19642524115522290447760970021746675789341356000653265441069630957431566301675, + 15809037446102219312954435152879098683824559980020626143453387822004586242317 + ); + vk.beta2 = Pairing.G2Point( + [ + 6402738102853475583969787773506197858266321704623454181848954418090577674938, + 3306678135584565297353192801602995509515651571902196852074598261262327790404 + ], + [ + 15158588411628049902562758796812667714664232742372443470614751812018801551665, + 4983765881427969364617654516554524254158908221590807345159959200407712579883 + ] + ); + vk.gamma2 = Pairing.G2Point( + [ + 11559732032986387107991004021392285783925812861821192530917403151452391805634, + 10857046999023057135944570762232829481370756359578518086990519993285655852781 + ], + [ + 4082367875863433681332203403145435568316851327593401208105741076214120093531, + 8495653923123431417604973247489272438418190587263600148770280649306958101930 + ] + ); + vk.delta2 = Pairing.G2Point( + [ + 5937324452265082694994079059241282955809587298129288028220551683857908477420, + 20193126291439324067855570349087139332759249767626415139734155586330544806931 + ], + [ + 20511021038180955968672836821991916481702435917128211030586041791747308087254, + 4825495667610898300284773277835226666829724669887302495853279321794443468464 + ] + ); vk.IC = new Pairing.G1Point[](3); - vk.IC[0] = Pairing.G1Point(17090106865544016169649801204752202247083129013270491555521198841473080041238,15065980597515084559860077870742922078916767487317684783582391086408942818065); - vk.IC[1] = Pairing.G1Point(8913742937555365648248402998792870367517256074228029563567168738837907881227,21383428510659794652837132325863891590781235269282443805635223826232789767789); - vk.IC[2] = Pairing.G1Point(5769673517202855981370378834388169432488818791880269268228263741092764941222,20765377592965078228481490563799127565985878224902794144540908553153853061842); - - } + vk.IC[0] = Pairing.G1Point( + 17090106865544016169649801204752202247083129013270491555521198841473080041238, + 15065980597515084559860077870742922078916767487317684783582391086408942818065 + ); + vk.IC[1] = Pairing.G1Point( + 8913742937555365648248402998792870367517256074228029563567168738837907881227, + 21383428510659794652837132325863891590781235269282443805635223826232789767789 + ); + vk.IC[2] = Pairing.G1Point( + 5769673517202855981370378834388169432488818791880269268228263741092764941222, + 20765377592965078228481490563799127565985878224902794144540908553153853061842 + ); + } - function verifyWhitelistProof( - uint256[2] memory a, - uint256[2][2] memory b, - uint256[2] memory c, - uint256[2] memory input - ) public view returns (bool) { - uint256[] memory inputValues = new uint256[](input.length); - for (uint256 i = 0; i < input.length; i++) { - inputValues[i] = input[i]; - } - return verifyProof(a, b, c, inputValues, whitelistVerifyingKey()); - } + function verifyWhitelistProof( + uint256[2] memory a, + uint256[2][2] memory b, + uint256[2] memory c, + uint256[2] memory input + ) public view returns (bool) { + uint256[] memory inputValues = new uint256[](input.length); + for (uint256 i = 0; i < input.length; i++) { + inputValues[i] = input[i]; + } + return verifyProof(a, b, c, inputValues, whitelistVerifyingKey()); + } } diff --git a/contracts/arena/DFArenaCoreFacet.sol b/contracts/arena/DFArenaCoreFacet.sol index fa91a91..3fd5288 100644 --- a/contracts/arena/DFArenaCoreFacet.sol +++ b/contracts/arena/DFArenaCoreFacet.sol @@ -165,17 +165,16 @@ contract DFArenaCoreFacet is WithStorage, WithArenaStorage { require(arenaConstants().MANUAL_SPAWN, "admin cannot create spawn planets"); arenaStorage().spawnPlanetIds.push(args.location); } - + arenaStorage().arenaPlanetInfo[args.location] = ArenaPlanetInfo( args.isSpawnPlanet, args.isTargetPlanet, args.blockedPlanetIds ); - for(uint i = 0; i < args.blockedPlanetIds.length; i++) { + for (uint256 i = 0; i < args.blockedPlanetIds.length; i++) { arenaStorage().blocklist[args.location][args.blockedPlanetIds[i]] = true; - } - + } SpaceType spaceType = LibGameUtils.spaceTypeFromPerlin(args.perlin); LibPlanet._initializePlanet( diff --git a/contracts/arena/DFArenaFaucet.sol b/contracts/arena/DFArenaFaucet.sol index 26f560e..f53b8d9 100644 --- a/contracts/arena/DFArenaFaucet.sol +++ b/contracts/arena/DFArenaFaucet.sol @@ -55,7 +55,9 @@ contract DFArenaFaucet { function canWithdraw(address _address) public view returns (bool) { /* Admin can always withdraw. Can withdraw if have not received drip or allowed to access again */ - return (_address == _owner || nextAccessTime[_address] == 0 || block.timestamp >= nextAccessTime[_address]); + return (_address == _owner || + nextAccessTime[_address] == 0 || + block.timestamp >= nextAccessTime[_address]); } function drip(address _address) public onlyOwner { @@ -99,4 +101,4 @@ contract DFArenaFaucet { } receive() external payable {} -} \ No newline at end of file +} diff --git a/contracts/arena/DFSpaceShipConfigFacet.sol b/contracts/arena/DFSpaceShipConfigFacet.sol index 5c9f036..1c48514 100644 --- a/contracts/arena/DFSpaceShipConfigFacet.sol +++ b/contracts/arena/DFSpaceShipConfigFacet.sol @@ -11,7 +11,7 @@ import {WithStorage} from "../libraries/LibStorage.sol"; import {LibGameUtils} from "../libraries/LibGameUtils.sol"; import {LibDiamond} from "../vendor/libraries/LibDiamond.sol"; // Type imports -import { ArtifactType, DFTCreateArtifactArgs, ArtifactRarity, Artifact, Biome, Spaceships} from "../DFTypes.sol"; +import {ArtifactType, DFTCreateArtifactArgs, ArtifactRarity, Artifact, Biome, Spaceships} from "../DFTypes.sol"; contract DFSpaceshipConfigFacet is WithStorage, WithArenaStorage { event ArtifactFound(address player, uint256 artifactId, uint256 loc); @@ -48,11 +48,7 @@ contract DFSpaceshipConfigFacet is WithStorage, WithArenaStorage { } if (arenaConstants().SPACESHIPS.whale) { - uint256 whale = createAndPlaceSpaceship( - locationId, - owner, - ArtifactType.ShipWhale - ); + uint256 whale = createAndPlaceSpaceship(locationId, owner, ArtifactType.ShipWhale); emit ArtifactFound(msg.sender, whale, locationId); } @@ -66,20 +62,12 @@ contract DFSpaceshipConfigFacet is WithStorage, WithArenaStorage { } if (arenaConstants().SPACESHIPS.gear) { - uint256 gear = createAndPlaceSpaceship( - locationId, - owner, - ArtifactType.ShipGear - ); + uint256 gear = createAndPlaceSpaceship(locationId, owner, ArtifactType.ShipGear); emit ArtifactFound(msg.sender, gear, locationId); } if (arenaConstants().SPACESHIPS.titan) { - uint256 titan = createAndPlaceSpaceship( - locationId, - owner, - ArtifactType.ShipTitan - ); + uint256 titan = createAndPlaceSpaceship(locationId, owner, ArtifactType.ShipTitan); emit ArtifactFound(msg.sender, titan, locationId); } diff --git a/contracts/facets/DFAdminFacet.sol b/contracts/facets/DFAdminFacet.sol index a0301e1..05c3c9c 100644 --- a/contracts/facets/DFAdminFacet.sol +++ b/contracts/facets/DFAdminFacet.sol @@ -11,17 +11,7 @@ import {LibArtifactUtils} from "../libraries/LibArtifactUtils.sol"; import {WithStorage} from "../libraries/LibStorage.sol"; // Type imports -import { - SpaceType, - DFPInitPlanetArgs, - AdminCreatePlanetArgs, - Artifact, - ArtifactType, - Player, - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2 -} from "../DFTypes.sol"; +import {SpaceType, DFPInitPlanetArgs, AdminCreatePlanetArgs, Artifact, ArtifactType, Player, Planet, PlanetExtendedInfo, PlanetExtendedInfo2} from "../DFTypes.sol"; contract DFAdminFacet is WithStorage { event AdminOwnershipChanged(uint256 loc, address newOwner); diff --git a/contracts/facets/DFArtifactFacet.sol b/contracts/facets/DFArtifactFacet.sol index 1cbcce1..b4cdaa3 100644 --- a/contracts/facets/DFArtifactFacet.sol +++ b/contracts/facets/DFArtifactFacet.sol @@ -73,22 +73,21 @@ contract DFArtifactFacet is WithStorage, ERC721 { _mint(args.owner, args.tokenId); - Artifact memory newArtifact = - Artifact( - true, - args.tokenId, - args.planetId, - args.rarity, - args.biome, - block.timestamp, - args.discoverer, - args.artifactType, - 0, - 0, - 0, - 0, - args.controller - ); + Artifact memory newArtifact = Artifact( + true, + args.tokenId, + args.planetId, + args.rarity, + args.biome, + block.timestamp, + args.discoverer, + args.artifactType, + 0, + 0, + 0, + 0, + args.controller + ); gs().artifacts[args.tokenId] = newArtifact; @@ -158,8 +157,9 @@ contract DFArtifactFacet is WithStorage, ERC721 { ); } - uint256 foundArtifactId = - LibArtifactUtils.findArtifact(DFPFindArtifactArgs(planetId, biomebase, address(this))); + uint256 foundArtifactId = LibArtifactUtils.findArtifact( + DFPFindArtifactArgs(planetId, biomebase, address(this)) + ); emit ArtifactFound(msg.sender, foundArtifactId, planetId); } diff --git a/contracts/facets/DFCaptureFacet.sol b/contracts/facets/DFCaptureFacet.sol index 107a8ae..412971f 100644 --- a/contracts/facets/DFCaptureFacet.sol +++ b/contracts/facets/DFCaptureFacet.sol @@ -117,8 +117,8 @@ contract DFCaptureFacet is WithStorage { function planetInCaptureZone(uint256 x, uint256 y) public returns (bool) { setNextGenerationBlock(); - uint256 generationBlock = - gs().nextChangeBlock - gameConstants().CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL; + uint256 generationBlock = gs().nextChangeBlock - + gameConstants().CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL; bytes32 generationBlockHash = blockhash(generationBlock); int256 planetX = getIntFromUInt(x); @@ -182,8 +182,7 @@ contract DFCaptureFacet is WithStorage { } function getIntFromUInt(uint256 n) public pure returns (int256) { - uint256 LOCATION_ID_UB = - 21888242871839275222246405745257275088548364400416034343698204186575808495617; + uint256 LOCATION_ID_UB = 21888242871839275222246405745257275088548364400416034343698204186575808495617; require(n < LOCATION_ID_UB, "Number outside of AbsoluteModP Range"); if (n > (LOCATION_ID_UB / 2)) { return 0 - int256(LOCATION_ID_UB - n); diff --git a/contracts/facets/DFCoreFacet.sol b/contracts/facets/DFCoreFacet.sol index 8b8702a..6723421 100644 --- a/contracts/facets/DFCoreFacet.sol +++ b/contracts/facets/DFCoreFacet.sol @@ -16,18 +16,7 @@ import {LibPlanet} from "../libraries/LibPlanet.sol"; import {WithStorage} from "../libraries/LibStorage.sol"; // Type imports -import { - SpaceType, - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2, - Player, - ArtifactType, - DFPInitPlanetArgs, - DFPMoveArgs, - DFPFindArtifactArgs, - AdminCreatePlanetArgs -} from "../DFTypes.sol"; +import {SpaceType, Planet, PlanetExtendedInfo, PlanetExtendedInfo2, Player, ArtifactType, DFPInitPlanetArgs, DFPMoveArgs, DFPFindArtifactArgs, AdminCreatePlanetArgs} from "../DFTypes.sol"; contract DFCoreFacet is WithStorage { using ABDKMath64x64 for *; diff --git a/contracts/facets/DFGetterFacet.sol b/contracts/facets/DFGetterFacet.sol index 7b78bcc..3fa33db 100644 --- a/contracts/facets/DFGetterFacet.sol +++ b/contracts/facets/DFGetterFacet.sol @@ -12,21 +12,7 @@ import {LibGameUtils} from "../libraries/LibGameUtils.sol"; import {WithStorage, SnarkConstants, GameConstants} from "../libraries/LibStorage.sol"; // Type imports -import { - RevealedCoords, - ArrivalData, - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2, - PlanetEventType, - PlanetEventMetadata, - PlanetDefaultStats, - PlanetData, - Player, - ArtifactWithMetadata, - Upgrade, - Artifact -} from "../DFTypes.sol"; +import {RevealedCoords, ArrivalData, Planet, PlanetExtendedInfo, PlanetExtendedInfo2, PlanetEventType, PlanetEventMetadata, PlanetDefaultStats, PlanetData, Player, ArtifactWithMetadata, Upgrade, Artifact} from "../DFTypes.sol"; contract DFGetterFacet is WithStorage { // FIRST-LEVEL GETTERS - mirrors the solidity autogenerated toplevel getters, but for GameStorage @@ -500,4 +486,4 @@ contract DFGetterFacet is WithStorage { }); } } -} \ No newline at end of file +} diff --git a/contracts/facets/DFMoveFacet.sol b/contracts/facets/DFMoveFacet.sol index f1e3ee9..01e7012 100644 --- a/contracts/facets/DFMoveFacet.sol +++ b/contracts/facets/DFMoveFacet.sol @@ -13,21 +13,7 @@ import {WithStorage} from "../libraries/LibStorage.sol"; import {WithArenaStorage} from "../libraries/LibArenaStorage.sol"; // Type imports -import { - ArrivalData, - ArrivalType, - Artifact, - ArtifactType, - DFPCreateArrivalArgs, - DFPMoveArgs, - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2, - PlanetEventMetadata, - PlanetEventType, - Upgrade, - ArenaPlayerInfo -} from "../DFTypes.sol"; +import {ArrivalData, ArrivalType, Artifact, ArtifactType, DFPCreateArrivalArgs, DFPMoveArgs, Planet, PlanetExtendedInfo, PlanetExtendedInfo2, PlanetEventMetadata, PlanetEventType, Upgrade, ArenaPlayerInfo} from "../DFTypes.sol"; contract DFMoveFacet is WithStorage, WithArenaStorage { modifier notPaused() { @@ -57,17 +43,16 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { false ); - DFPMoveArgs memory args = - DFPMoveArgs({ - oldLoc: _input[0], - newLoc: _input[1], - maxDist: _input[4], - popMoved: _input[10], - silverMoved: _input[11], - movedArtifactId: _input[12], - abandoning: _input[13], - sender: msg.sender - }); + DFPMoveArgs memory args = DFPMoveArgs({ + oldLoc: _input[0], + newLoc: _input[1], + maxDist: _input[4], + popMoved: _input[10], + silverMoved: _input[11], + movedArtifactId: _input[12], + abandoning: _input[13], + sender: msg.sender + }); if (_isSpaceshipMove(args)) { // If spaceships moves are not address(0) @@ -79,19 +64,18 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { uint256 newRadius = _input[3]; if (!snarkConstants().DISABLE_ZK_CHECKS) { - uint256[10] memory _proofInput = - [ - args.oldLoc, - args.newLoc, - newPerlin, - newRadius, - args.maxDist, - _input[5], - _input[6], - _input[7], - _input[8], - _input[9] - ]; + uint256[10] memory _proofInput = [ + args.oldLoc, + args.newLoc, + newPerlin, + newRadius, + args.maxDist, + _input[5], + _input[6], + _input[7], + _input[8], + _input[9] + ]; require(Verifier.verifyMoveProof(_a, _b, _c, _proofInput), "Failed move proof check"); } @@ -113,11 +97,10 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { } _executeMove(args); - - - if(!(arenaConstants().CONFIRM_START) && arenaStorage().startTime == 0) { - arenaStorage().startTime = block.timestamp; - emit GameStarted(msg.sender, block.timestamp); + + if (!(arenaConstants().CONFIRM_START) && arenaStorage().startTime == 0) { + arenaStorage().startTime = block.timestamp; + emit GameStarted(msg.sender, block.timestamp); } arenaStorage().arenaPlayerInfo[msg.sender].moves++; @@ -247,7 +230,7 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { ); } - if(arenaConstants().BLOCK_MOVES) { + if (arenaConstants().BLOCK_MOVES) { uint256 playerHomePlanet = gs().players[msg.sender].homePlanetId; bool blocked = arenaStorage().blocklist[args.newLoc][playerHomePlanet]; require(!blocked, "you cannot move to a blocked planet"); @@ -258,8 +241,6 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { "Tried to move more silver than what exists" ); - - if (args.movedArtifactId != 0) { require( gs().planetArtifacts[args.newLoc].length < 5, @@ -409,17 +390,12 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { remainingOriginPlanetPopulation = LibGameUtils ._defaultPlanet( - args - .oldLoc, - gs().planets[args.oldLoc] - .planetLevel, - gs().planets[args.oldLoc] - .planetType, - gs().planetsExtendedInfo[args.oldLoc] - .spaceType, - gameConstants() - .TIME_FACTOR_HUNDREDTHS - ) + args.oldLoc, + gs().planets[args.oldLoc].planetLevel, + gs().planets[args.oldLoc].planetType, + gs().planetsExtendedInfo[args.oldLoc].spaceType, + gameConstants().TIME_FACTOR_HUNDREDTHS + ) .population * 2; temporaryUpgrade = LibGameUtils.abandoningUpgrade(); @@ -465,15 +441,15 @@ contract DFMoveFacet is WithStorage, WithArenaStorage { function _createArrival(DFPCreateArrivalArgs memory args) private { // enter the arrival data for event id Planet memory planet = gs().planets[args.oldLoc]; - uint256 popArriving = - _getDecayedPop( - args.popMoved, - args.effectiveDistTimesHundred, - planet.range, - planet.populationCap - ); - bool isSpaceship = - LibArtifactUtils.isSpaceship(gs().artifacts[args.movedArtifactId].artifactType); + uint256 popArriving = _getDecayedPop( + args.popMoved, + args.effectiveDistTimesHundred, + planet.range, + planet.populationCap + ); + bool isSpaceship = LibArtifactUtils.isSpaceship( + gs().artifacts[args.movedArtifactId].artifactType + ); // space ship moves are implemented as 0-energy moves require(popArriving > 0 || isSpaceship, "Not enough forces to make move"); require(isSpaceship ? args.popMoved == 0 : true, "spaceship moves must be 0 energy moves"); diff --git a/contracts/facets/DFStartFacet.sol b/contracts/facets/DFStartFacet.sol index f69384d..785cdc3 100644 --- a/contracts/facets/DFStartFacet.sol +++ b/contracts/facets/DFStartFacet.sol @@ -26,441 +26,398 @@ import {DFWhitelistFacet} from "./DFWhitelistFacet.sol"; import {PlanetDefaultStats, Upgrade, UpgradeBranch, Modifiers, Mod, ArenaCreateRevealPlanetArgs, Spaceships} from "../DFTypes.sol"; contract DFStartFacet is WithStorage, WithArenaStorage { - event ArenaInitialized(address ownerAddress, address lobbyAddress); - - function start() public { - gs().diamondAddress = address(this); - - ws().enabled = ai().auxArgs.allowListEnabled; - uint256 allowedAddressesLength = ai().auxArgs.allowedAddresses.length; - - if (ws().enabled && allowedAddressesLength > 0) { - // delegating call here because msg.sender must remain intact. - (bool success, bytes memory returndata) = (address(this)).delegatecall( - abi.encodeWithSignature( - "bulkAddToWhitelist(address[])", - ai().auxArgs.allowedAddresses - ) - ); - require(success, "whitelisting ownership did not succeed"); + event ArenaInitialized(address ownerAddress, address lobbyAddress); + + function start() public { + gs().diamondAddress = address(this); + + ws().enabled = ai().auxArgs.allowListEnabled; + uint256 allowedAddressesLength = ai().auxArgs.allowedAddresses.length; + + if (ws().enabled && allowedAddressesLength > 0) { + // delegating call here because msg.sender must remain intact. + (bool success, bytes memory returndata) = (address(this)).delegatecall( + abi.encodeWithSignature( + "bulkAddToWhitelist(address[])", + ai().auxArgs.allowedAddresses + ) + ); + require(success, "whitelisting ownership did not succeed"); + } + + ws().drip = 0.05 ether; + + gs().planetLevelsCount = 10; + gs().planetLevelThresholds = ai().initArgs.PLANET_LEVEL_THRESHOLDS; + + snarkConstants().DISABLE_ZK_CHECKS = ai().initArgs.DISABLE_ZK_CHECKS; + snarkConstants().PLANETHASH_KEY = ai().initArgs.PLANETHASH_KEY; + snarkConstants().SPACETYPE_KEY = ai().initArgs.SPACETYPE_KEY; + snarkConstants().BIOMEBASE_KEY = ai().initArgs.BIOMEBASE_KEY; + snarkConstants().PERLIN_MIRROR_X = ai().initArgs.PERLIN_MIRROR_X; + snarkConstants().PERLIN_MIRROR_Y = ai().initArgs.PERLIN_MIRROR_Y; + snarkConstants().PERLIN_LENGTH_SCALE = ai().initArgs.PERLIN_LENGTH_SCALE; + + gameConstants().PLANET_LEVEL_THRESHOLDS = ai().initArgs.PLANET_LEVEL_THRESHOLDS; + gameConstants().ADMIN_CAN_ADD_PLANETS = ai().initArgs.ADMIN_CAN_ADD_PLANETS; + gameConstants().WORLD_RADIUS_LOCKED = ai().initArgs.WORLD_RADIUS_LOCKED; + gameConstants().WORLD_RADIUS_MIN = ai().initArgs.WORLD_RADIUS_MIN; + gameConstants().MAX_NATURAL_PLANET_LEVEL = ai().initArgs.MAX_NATURAL_PLANET_LEVEL; + gameConstants().TIME_FACTOR_HUNDREDTHS = ai().initArgs.TIME_FACTOR_HUNDREDTHS; + gameConstants().PERLIN_THRESHOLD_1 = ai().initArgs.PERLIN_THRESHOLD_1; + gameConstants().PERLIN_THRESHOLD_2 = ai().initArgs.PERLIN_THRESHOLD_2; + gameConstants().PERLIN_THRESHOLD_3 = ai().initArgs.PERLIN_THRESHOLD_3; + gameConstants().INIT_PERLIN_MIN = ai().initArgs.INIT_PERLIN_MIN; + gameConstants().INIT_PERLIN_MAX = ai().initArgs.INIT_PERLIN_MAX; + gameConstants().SPAWN_RIM_AREA = ai().initArgs.SPAWN_RIM_AREA; + gameConstants().BIOME_THRESHOLD_1 = ai().initArgs.BIOME_THRESHOLD_1; + gameConstants().BIOME_THRESHOLD_2 = ai().initArgs.BIOME_THRESHOLD_2; + gameConstants().PLANET_RARITY = ai().initArgs.PLANET_RARITY; + gameConstants().PLANET_TRANSFER_ENABLED = ai().initArgs.PLANET_TRANSFER_ENABLED; + gameConstants().PHOTOID_ACTIVATION_DELAY = ai().initArgs.PHOTOID_ACTIVATION_DELAY; + gameConstants().LOCATION_REVEAL_COOLDOWN = ai().initArgs.LOCATION_REVEAL_COOLDOWN; + gameConstants().PLANET_TYPE_WEIGHTS = ai().initArgs.PLANET_TYPE_WEIGHTS; + gameConstants().SILVER_SCORE_VALUE = ai().initArgs.SILVER_SCORE_VALUE; + gameConstants().ARTIFACT_POINT_VALUES = ai().initArgs.ARTIFACT_POINT_VALUES; + // Space Junk + gameConstants().SPACE_JUNK_ENABLED = ai().initArgs.SPACE_JUNK_ENABLED; + gameConstants().SPACE_JUNK_LIMIT = ai().initArgs.SPACE_JUNK_LIMIT; + gameConstants().PLANET_LEVEL_JUNK = ai().initArgs.PLANET_LEVEL_JUNK; + gameConstants().ABANDON_SPEED_CHANGE_PERCENT = ai().initArgs.ABANDON_SPEED_CHANGE_PERCENT; + gameConstants().ABANDON_RANGE_CHANGE_PERCENT = ai().initArgs.ABANDON_RANGE_CHANGE_PERCENT; + // Capture Zones + gameConstants().GAME_START_BLOCK = block.number; + gameConstants().CAPTURE_ZONES_ENABLED = ai().initArgs.CAPTURE_ZONES_ENABLED; + gameConstants().CAPTURE_ZONE_COUNT = ai().initArgs.CAPTURE_ZONE_COUNT; + gameConstants().CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL = ai() + .initArgs + .CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL; + gameConstants().CAPTURE_ZONE_RADIUS = ai().initArgs.CAPTURE_ZONE_RADIUS; + gameConstants().CAPTURE_ZONE_PLANET_LEVEL_SCORE = ai() + .initArgs + .CAPTURE_ZONE_PLANET_LEVEL_SCORE; + gameConstants().CAPTURE_ZONE_HOLD_BLOCKS_REQUIRED = ai() + .initArgs + .CAPTURE_ZONE_HOLD_BLOCKS_REQUIRED; + gameConstants().CAPTURE_ZONES_PER_5000_WORLD_RADIUS = ai() + .initArgs + .CAPTURE_ZONES_PER_5000_WORLD_RADIUS; + + gs().nextChangeBlock = block.number + ai().initArgs.CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL; + + gs().worldRadius = ai().initArgs.WORLD_RADIUS_MIN; // will be overridden by `LibGameUtils.updateWorldRadius()` if !WORLD_RADIUS_LOCKED + + gs().paused = ai().initArgs.START_PAUSED || ai().initArgs.CONFIRM_START; + + gs().TOKEN_MINT_END_TIMESTAMP = ai().initArgs.TOKEN_MINT_END_TIMESTAMP; + + gs().initializedPlanetCountByLevel = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + for (uint256 i = 0; i < gs().planetLevelThresholds.length; i += 1) { + gs().cumulativeRarities.push( + (2**24 / gs().planetLevelThresholds[i]) * ai().initArgs.PLANET_RARITY + ); + } + + //arenaMode initialization + arenaStorage().gameover = false; + arenaConstants().TARGET_PLANETS = ai().initArgs.TARGET_PLANETS; + arenaConstants().CLAIM_VICTORY_ENERGY_PERCENT = ai().initArgs.CLAIM_VICTORY_ENERGY_PERCENT; + arenaConstants().MANUAL_SPAWN = ai().initArgs.MANUAL_SPAWN; + arenaConstants().RANDOM_ARTIFACTS = ai().initArgs.RANDOM_ARTIFACTS; + + arenaConstants().MODIFIERS.popCap = ai().initArgs.MODIFIERS[uint256(Mod.popCap)]; + arenaConstants().MODIFIERS.popGrowth = ai().initArgs.MODIFIERS[uint256(Mod.popGrowth)]; + arenaConstants().MODIFIERS.silverCap = ai().initArgs.MODIFIERS[uint256(Mod.silverCap)]; + arenaConstants().MODIFIERS.silverGrowth = ai().initArgs.MODIFIERS[ + uint256(Mod.silverGrowth) + ]; + arenaConstants().MODIFIERS.range = ai().initArgs.MODIFIERS[uint256(Mod.range)]; + arenaConstants().MODIFIERS.speed = ai().initArgs.MODIFIERS[uint256(Mod.speed)]; + arenaConstants().MODIFIERS.defense = ai().initArgs.MODIFIERS[uint256(Mod.defense)]; + arenaConstants().MODIFIERS.barbarianPercentage = ai().initArgs.MODIFIERS[ + uint256(Mod.barbarianPercentage) + ]; + + arenaConstants().SPACESHIPS = Spaceships( + ai().initArgs.SPACESHIPS[0], + ai().initArgs.SPACESHIPS[1], + ai().initArgs.SPACESHIPS[2], + ai().initArgs.SPACESHIPS[3], + ai().initArgs.SPACESHIPS[4] + ); + + arenaConstants().NO_ADMIN = ai().initArgs.NO_ADMIN; + arenaConstants().CONFIG_HASH = keccak256(abi.encode(ai().initArgs)); + arenaConstants().CONFIRM_START = ai().initArgs.CONFIRM_START; + arenaConstants().START_PAUSED = ai().initArgs.START_PAUSED; + + uint256 initLength = ai().initArgs.INIT_PLANETS.length; + + /* each planet costs about 50k gas */ + for (uint256 i = 0; i < initLength; i++) { + ArenaCreateRevealPlanetArgs memory initPlanet = ai().initArgs.INIT_PLANETS[i]; + + bytes32 initHash = LibGameUtils._hashInitPlanet(initPlanet); + + arenaStorage().initPlanetHashes[initHash] = true; + + /* Store planet ids for retrieval later */ + arenaConstants().INIT_PLANET_HASHES.push(initHash); + } + + arenaConstants().TARGETS_REQUIRED_FOR_VICTORY = ai().initArgs.TARGETS_REQUIRED_FOR_VICTORY; + arenaConstants().BLOCK_MOVES = ai().initArgs.BLOCK_MOVES; + arenaConstants().BLOCK_CAPTURE = ai().initArgs.BLOCK_CAPTURE; + arenaConstants().TEAMS_ENABLED = ai().initArgs.TEAMS_ENABLED; + arenaConstants().NUM_TEAMS = ai().initArgs.NUM_TEAMS; + arenaConstants().RANKED = ai().initArgs.RANKED; + + initializeDefaults(); + initializeUpgrades(); + LibGameUtils.updateWorldRadius(); + + emit ArenaInitialized(IERC173(address(this)).owner(), address(this)); } - ws().drip = 0.05 ether; - - gs().planetLevelsCount = 10; - gs().planetLevelThresholds = ai().initArgs.PLANET_LEVEL_THRESHOLDS; - - snarkConstants().DISABLE_ZK_CHECKS = ai().initArgs.DISABLE_ZK_CHECKS; - snarkConstants().PLANETHASH_KEY = ai().initArgs.PLANETHASH_KEY; - snarkConstants().SPACETYPE_KEY = ai().initArgs.SPACETYPE_KEY; - snarkConstants().BIOMEBASE_KEY = ai().initArgs.BIOMEBASE_KEY; - snarkConstants().PERLIN_MIRROR_X = ai().initArgs.PERLIN_MIRROR_X; - snarkConstants().PERLIN_MIRROR_Y = ai().initArgs.PERLIN_MIRROR_Y; - snarkConstants().PERLIN_LENGTH_SCALE = ai().initArgs.PERLIN_LENGTH_SCALE; - - gameConstants().PLANET_LEVEL_THRESHOLDS = ai().initArgs.PLANET_LEVEL_THRESHOLDS; - gameConstants().ADMIN_CAN_ADD_PLANETS = ai().initArgs.ADMIN_CAN_ADD_PLANETS; - gameConstants().WORLD_RADIUS_LOCKED = ai().initArgs.WORLD_RADIUS_LOCKED; - gameConstants().WORLD_RADIUS_MIN = ai().initArgs.WORLD_RADIUS_MIN; - gameConstants().MAX_NATURAL_PLANET_LEVEL = ai() - .initArgs - .MAX_NATURAL_PLANET_LEVEL; - gameConstants().TIME_FACTOR_HUNDREDTHS = ai() - .initArgs - .TIME_FACTOR_HUNDREDTHS; - gameConstants().PERLIN_THRESHOLD_1 = ai().initArgs.PERLIN_THRESHOLD_1; - gameConstants().PERLIN_THRESHOLD_2 = ai().initArgs.PERLIN_THRESHOLD_2; - gameConstants().PERLIN_THRESHOLD_3 = ai().initArgs.PERLIN_THRESHOLD_3; - gameConstants().INIT_PERLIN_MIN = ai().initArgs.INIT_PERLIN_MIN; - gameConstants().INIT_PERLIN_MAX = ai().initArgs.INIT_PERLIN_MAX; - gameConstants().SPAWN_RIM_AREA = ai().initArgs.SPAWN_RIM_AREA; - gameConstants().BIOME_THRESHOLD_1 = ai().initArgs.BIOME_THRESHOLD_1; - gameConstants().BIOME_THRESHOLD_2 = ai().initArgs.BIOME_THRESHOLD_2; - gameConstants().PLANET_RARITY = ai().initArgs.PLANET_RARITY; - gameConstants().PLANET_TRANSFER_ENABLED = ai() - .initArgs - .PLANET_TRANSFER_ENABLED; - gameConstants().PHOTOID_ACTIVATION_DELAY = ai() - .initArgs - .PHOTOID_ACTIVATION_DELAY; - gameConstants().LOCATION_REVEAL_COOLDOWN = ai() - .initArgs - .LOCATION_REVEAL_COOLDOWN; - gameConstants().PLANET_TYPE_WEIGHTS = ai().initArgs.PLANET_TYPE_WEIGHTS; - gameConstants().SILVER_SCORE_VALUE = ai().initArgs.SILVER_SCORE_VALUE; - gameConstants().ARTIFACT_POINT_VALUES = ai().initArgs.ARTIFACT_POINT_VALUES; - // Space Junk - gameConstants().SPACE_JUNK_ENABLED = ai().initArgs.SPACE_JUNK_ENABLED; - gameConstants().SPACE_JUNK_LIMIT = ai().initArgs.SPACE_JUNK_LIMIT; - gameConstants().PLANET_LEVEL_JUNK = ai().initArgs.PLANET_LEVEL_JUNK; - gameConstants().ABANDON_SPEED_CHANGE_PERCENT = ai() - .initArgs - .ABANDON_SPEED_CHANGE_PERCENT; - gameConstants().ABANDON_RANGE_CHANGE_PERCENT = ai() - .initArgs - .ABANDON_RANGE_CHANGE_PERCENT; - // Capture Zones - gameConstants().GAME_START_BLOCK = block.number; - gameConstants().CAPTURE_ZONES_ENABLED = ai().initArgs.CAPTURE_ZONES_ENABLED; - gameConstants().CAPTURE_ZONE_COUNT = ai().initArgs.CAPTURE_ZONE_COUNT; - gameConstants().CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL = ai() - .initArgs - .CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL; - gameConstants().CAPTURE_ZONE_RADIUS = ai().initArgs.CAPTURE_ZONE_RADIUS; - gameConstants().CAPTURE_ZONE_PLANET_LEVEL_SCORE = ai() - .initArgs - .CAPTURE_ZONE_PLANET_LEVEL_SCORE; - gameConstants().CAPTURE_ZONE_HOLD_BLOCKS_REQUIRED = ai() - .initArgs - .CAPTURE_ZONE_HOLD_BLOCKS_REQUIRED; - gameConstants().CAPTURE_ZONES_PER_5000_WORLD_RADIUS = ai() - .initArgs - .CAPTURE_ZONES_PER_5000_WORLD_RADIUS; - - gs().nextChangeBlock = - block.number + - ai().initArgs.CAPTURE_ZONE_CHANGE_BLOCK_INTERVAL; - - gs().worldRadius = ai().initArgs.WORLD_RADIUS_MIN; // will be overridden by `LibGameUtils.updateWorldRadius()` if !WORLD_RADIUS_LOCKED - - gs().paused = ai().initArgs.START_PAUSED || ai().initArgs.CONFIRM_START; - - gs().TOKEN_MINT_END_TIMESTAMP = ai().initArgs.TOKEN_MINT_END_TIMESTAMP; - - gs().initializedPlanetCountByLevel = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (uint256 i = 0; i < gs().planetLevelThresholds.length; i += 1) { - gs().cumulativeRarities.push( - (2**24 / gs().planetLevelThresholds[i]) * ai().initArgs.PLANET_RARITY - ); + function initializeDefaults() public { + PlanetDefaultStats[] storage planetDefaultStats = planetDefaultStats(); + require( + ((75 * arenaConstants().MODIFIERS.speed) / 100) > 0, + "cannot initialize planets with 0 speed" + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Asteroid", + populationCap: (100000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (417 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (99 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (400 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (0 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (0 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: 0 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Brown Dwarf", + populationCap: (400000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (833 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (177 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (400 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (56 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (100000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (1 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Red Dwarf", + populationCap: (1600000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (1250 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (315 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (300 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (167 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (500000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (2 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "White Dwarf", + populationCap: (6000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (1667 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (591 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (300 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (417 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (2500000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (3 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Yellow Star", + populationCap: (25000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (2083 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (1025 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (300 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (833 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (12000000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (4 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Blue Star", + populationCap: (100000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (2500 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (1734 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (200 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (1667 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (50000000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (5 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Giant", + populationCap: (300000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (2917 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (2838 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (200 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (100000000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (7 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Supergiant", + populationCap: (500000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (3333 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (4414 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (200 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (200000000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (10 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Unlabeled1", + populationCap: (700000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (3750 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (6306 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (200 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (300000000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (20 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); + + planetDefaultStats.push( + PlanetDefaultStats({ + label: "Unlabeled2", + populationCap: (800000000 * arenaConstants().MODIFIERS.popCap) / 100, + populationGrowth: (4167 * arenaConstants().MODIFIERS.popGrowth) / 100, + range: (8829 * arenaConstants().MODIFIERS.range) / 100, + speed: (75 * arenaConstants().MODIFIERS.speed) / 100, + defense: (200 * arenaConstants().MODIFIERS.defense) / 100, + silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, + silverCap: (400000000 * arenaConstants().MODIFIERS.silverCap) / 100, + barbarianPercentage: (25 * arenaConstants().MODIFIERS.barbarianPercentage) / 100 + }) + ); } - //arenaMode initialization - arenaStorage().gameover = false; - arenaConstants().TARGET_PLANETS = ai().initArgs.TARGET_PLANETS; - arenaConstants().CLAIM_VICTORY_ENERGY_PERCENT = ai() - .initArgs - .CLAIM_VICTORY_ENERGY_PERCENT; - arenaConstants().MANUAL_SPAWN = ai().initArgs.MANUAL_SPAWN; - arenaConstants().RANDOM_ARTIFACTS = ai().initArgs.RANDOM_ARTIFACTS; - - arenaConstants().MODIFIERS.popCap = ai().initArgs.MODIFIERS[ - uint256(Mod.popCap) - ]; - arenaConstants().MODIFIERS.popGrowth = ai().initArgs.MODIFIERS[ - uint256(Mod.popGrowth) - ]; - arenaConstants().MODIFIERS.silverCap = ai().initArgs.MODIFIERS[ - uint256(Mod.silverCap) - ]; - arenaConstants().MODIFIERS.silverGrowth = ai().initArgs.MODIFIERS[ - uint256(Mod.silverGrowth) - ]; - arenaConstants().MODIFIERS.range = ai().initArgs.MODIFIERS[ - uint256(Mod.range) - ]; - arenaConstants().MODIFIERS.speed = ai().initArgs.MODIFIERS[ - uint256(Mod.speed) - ]; - arenaConstants().MODIFIERS.defense = ai().initArgs.MODIFIERS[ - uint256(Mod.defense) - ]; - arenaConstants().MODIFIERS.barbarianPercentage = ai().initArgs.MODIFIERS[ - uint256(Mod.barbarianPercentage) - ]; - - arenaConstants().SPACESHIPS = Spaceships( - ai().initArgs.SPACESHIPS[0], - ai().initArgs.SPACESHIPS[1], - ai().initArgs.SPACESHIPS[2], - ai().initArgs.SPACESHIPS[3], - ai().initArgs.SPACESHIPS[4] - ); - - arenaConstants().NO_ADMIN = ai().initArgs.NO_ADMIN; - arenaConstants().CONFIG_HASH = keccak256(abi.encode(ai().initArgs)); - arenaConstants().CONFIRM_START = ai().initArgs.CONFIRM_START; - arenaConstants().START_PAUSED = ai().initArgs.START_PAUSED; - - uint256 initLength = ai().initArgs.INIT_PLANETS.length; - - /* each planet costs about 50k gas */ - for (uint256 i = 0; i < initLength; i++) { - ArenaCreateRevealPlanetArgs memory initPlanet = ai() - .initArgs - .INIT_PLANETS[i]; - - bytes32 initHash = LibGameUtils._hashInitPlanet(initPlanet); - - arenaStorage().initPlanetHashes[initHash] = true; - - /* Store planet ids for retrieval later */ - arenaConstants().INIT_PLANET_HASHES.push(initHash); + function initializeUpgrades() public { + Upgrade[4][3] storage upgrades = upgrades(); + + // defense + upgrades[uint256(UpgradeBranch.DEFENSE)][0] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 100, + defMultiplier: 120 + }); + upgrades[uint256(UpgradeBranch.DEFENSE)][1] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 100, + defMultiplier: 120 + }); + upgrades[uint256(UpgradeBranch.DEFENSE)][2] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 100, + defMultiplier: 120 + }); + upgrades[uint256(UpgradeBranch.DEFENSE)][3] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 100, + defMultiplier: 120 + }); + + // range + upgrades[uint256(UpgradeBranch.RANGE)][0] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 125, + speedMultiplier: 100, + defMultiplier: 100 + }); + upgrades[uint256(UpgradeBranch.RANGE)][1] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 125, + speedMultiplier: 100, + defMultiplier: 100 + }); + upgrades[uint256(UpgradeBranch.RANGE)][2] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 125, + speedMultiplier: 100, + defMultiplier: 100 + }); + upgrades[uint256(UpgradeBranch.RANGE)][3] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 125, + speedMultiplier: 100, + defMultiplier: 100 + }); + + // speed + upgrades[uint256(UpgradeBranch.SPEED)][0] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 175, + defMultiplier: 100 + }); + upgrades[uint256(UpgradeBranch.SPEED)][1] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 175, + defMultiplier: 100 + }); + upgrades[uint256(UpgradeBranch.SPEED)][2] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 175, + defMultiplier: 100 + }); + upgrades[uint256(UpgradeBranch.SPEED)][3] = Upgrade({ + popCapMultiplier: 120, + popGroMultiplier: 120, + rangeMultiplier: 100, + speedMultiplier: 175, + defMultiplier: 100 + }); } - - arenaConstants().TARGETS_REQUIRED_FOR_VICTORY = ai() - .initArgs - .TARGETS_REQUIRED_FOR_VICTORY; - arenaConstants().BLOCK_MOVES = ai().initArgs.BLOCK_MOVES; - arenaConstants().BLOCK_CAPTURE = ai().initArgs.BLOCK_CAPTURE; - arenaConstants().TEAMS_ENABLED = ai().initArgs.TEAMS_ENABLED; - arenaConstants().NUM_TEAMS = ai().initArgs.NUM_TEAMS; - arenaConstants().RANKED = ai().initArgs.RANKED; - - initializeDefaults(); - initializeUpgrades(); - LibGameUtils.updateWorldRadius(); - - emit ArenaInitialized(IERC173(address(this)).owner(), address(this)); - } - - function initializeDefaults() public { - PlanetDefaultStats[] storage planetDefaultStats = planetDefaultStats(); - require( - ((75 * arenaConstants().MODIFIERS.speed) / 100) > 0, - "cannot initialize planets with 0 speed" - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Asteroid", - populationCap: (100000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (417 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (99 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (400 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (0 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (0 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: 0 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Brown Dwarf", - populationCap: (400000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (833 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (177 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (400 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (56 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (100000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (1 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Red Dwarf", - populationCap: (1600000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (1250 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (315 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (300 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (167 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (500000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (2 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "White Dwarf", - populationCap: (6000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (1667 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (591 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (300 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (417 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (2500000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (3 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Yellow Star", - populationCap: (25000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (2083 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (1025 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (300 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (833 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (12000000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (4 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Blue Star", - populationCap: (100000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (2500 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (1734 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (200 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (1667 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (50000000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (5 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Giant", - populationCap: (300000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (2917 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (2838 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (200 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (100000000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (7 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Supergiant", - populationCap: (500000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (3333 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (4414 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (200 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (200000000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (10 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Unlabeled1", - populationCap: (700000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (3750 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (6306 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (200 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (300000000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (20 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - - planetDefaultStats.push( - PlanetDefaultStats({ - label: "Unlabeled2", - populationCap: (800000000 * arenaConstants().MODIFIERS.popCap) / 100, - populationGrowth: (4167 * arenaConstants().MODIFIERS.popGrowth) / 100, - range: (8829 * arenaConstants().MODIFIERS.range) / 100, - speed: (75 * arenaConstants().MODIFIERS.speed) / 100, - defense: (200 * arenaConstants().MODIFIERS.defense) / 100, - silverGrowth: (2778 * arenaConstants().MODIFIERS.silverGrowth) / 100, - silverCap: (400000000 * arenaConstants().MODIFIERS.silverCap) / 100, - barbarianPercentage: (25 * - arenaConstants().MODIFIERS.barbarianPercentage) / 100 - }) - ); - } - - function initializeUpgrades() public { - Upgrade[4][3] storage upgrades = upgrades(); - - // defense - upgrades[uint256(UpgradeBranch.DEFENSE)][0] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 100, - defMultiplier: 120 - }); - upgrades[uint256(UpgradeBranch.DEFENSE)][1] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 100, - defMultiplier: 120 - }); - upgrades[uint256(UpgradeBranch.DEFENSE)][2] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 100, - defMultiplier: 120 - }); - upgrades[uint256(UpgradeBranch.DEFENSE)][3] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 100, - defMultiplier: 120 - }); - - // range - upgrades[uint256(UpgradeBranch.RANGE)][0] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 125, - speedMultiplier: 100, - defMultiplier: 100 - }); - upgrades[uint256(UpgradeBranch.RANGE)][1] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 125, - speedMultiplier: 100, - defMultiplier: 100 - }); - upgrades[uint256(UpgradeBranch.RANGE)][2] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 125, - speedMultiplier: 100, - defMultiplier: 100 - }); - upgrades[uint256(UpgradeBranch.RANGE)][3] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 125, - speedMultiplier: 100, - defMultiplier: 100 - }); - - // speed - upgrades[uint256(UpgradeBranch.SPEED)][0] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 175, - defMultiplier: 100 - }); - upgrades[uint256(UpgradeBranch.SPEED)][1] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 175, - defMultiplier: 100 - }); - upgrades[uint256(UpgradeBranch.SPEED)][2] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 175, - defMultiplier: 100 - }); - upgrades[uint256(UpgradeBranch.SPEED)][3] = Upgrade({ - popCapMultiplier: 120, - popGroMultiplier: 120, - rangeMultiplier: 100, - speedMultiplier: 175, - defMultiplier: 100 - }); - } } diff --git a/contracts/facets/DFWhitelistFacet.sol b/contracts/facets/DFWhitelistFacet.sol index b133c95..08c3095 100644 --- a/contracts/facets/DFWhitelistFacet.sol +++ b/contracts/facets/DFWhitelistFacet.sol @@ -82,7 +82,7 @@ contract DFWhitelistFacet is WithStorage { // xDAI ONLY payable(recipient).transfer(ws().drip); } - + function addToWhitelist(address toAdd) public onlyAdmin { require(!ws().allowedAccounts[toAdd], "player is already allowed"); @@ -91,7 +91,7 @@ contract DFWhitelistFacet is WithStorage { } function bulkAddToWhitelist(address[] memory addresses) public onlyAdmin { - for(uint256 i = 0; i < addresses.length; i++) { + for (uint256 i = 0; i < addresses.length; i++) { addToWhitelist(addresses[i]); } } diff --git a/contracts/libraries/LibArenaStorage.sol b/contracts/libraries/LibArenaStorage.sol index aa73b78..a80d09e 100644 --- a/contracts/libraries/LibArenaStorage.sol +++ b/contracts/libraries/LibArenaStorage.sol @@ -2,25 +2,7 @@ pragma solidity ^0.8.0; // Type imports -import { - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2, - PlanetEventMetadata, - PlanetDefaultStats, - Upgrade, - RevealedCoords, - Player, - ArrivalData, - Artifact, - ArenaPlanetInfo, - ArenaPlayerInfo, - Modifiers, - ArenaCreateRevealPlanetArgs, - Spaceships, - InitArgs, - AuxiliaryArgs -} from "../DFTypes.sol"; +import {Planet, PlanetExtendedInfo, PlanetExtendedInfo2, PlanetEventMetadata, PlanetDefaultStats, Upgrade, RevealedCoords, Player, ArrivalData, Artifact, ArenaPlanetInfo, ArenaPlayerInfo, Modifiers, ArenaCreateRevealPlanetArgs, Spaceships, InitArgs, AuxiliaryArgs} from "../DFTypes.sol"; /* Remember! Only add new storage variables at the end of structs !! */ @@ -40,7 +22,6 @@ struct ArenaStorage { mapping(uint256 => ArenaPlanetInfo) arenaPlanetInfo; uint256[] spawnPlanetIds; uint256[] targetPlanetIds; - uint256 moveCap; mapping(address => ArenaPlayerInfo) arenaPlayerInfo; uint256 endTime; @@ -54,17 +35,13 @@ struct ArenaStorage { struct ArenaConstants { bool TARGET_PLANETS; bool MANUAL_SPAWN; - bytes32 CONFIG_HASH; - Modifiers MODIFIERS; Spaceships SPACESHIPS; uint256 CLAIM_VICTORY_ENERGY_PERCENT; - bool RANDOM_ARTIFACTS; - bool NO_ADMIN; - bytes32 [] INIT_PLANET_HASHES; // This won't mess up Diamond storage + bytes32[] INIT_PLANET_HASHES; // This won't mess up Diamond storage bool CONFIRM_START; uint256 TARGETS_REQUIRED_FOR_VICTORY; bool BLOCK_MOVES; @@ -82,7 +59,6 @@ library LibArenaStorage { bytes32 constant ARENA_CONSTANTS_POSITION = keccak256("darkforest.constants.arena"); bytes32 constant TOURNAMENT_STORAGE_POSITION = keccak256("darkforest.storage.tournament"); - function arenaStorage() internal pure returns (ArenaStorage storage gs) { bytes32 position = ARENA_STORAGE_POSITION; assembly { @@ -90,22 +66,21 @@ library LibArenaStorage { } } - function arenaConstants() internal pure returns (ArenaConstants storage gs) { + function arenaConstants() internal pure returns (ArenaConstants storage gs) { bytes32 position = ARENA_CONSTANTS_POSITION; assembly { gs.slot := position } } - function tournamentStorage() internal pure returns (TournamentStorage storage ts) { + function tournamentStorage() internal pure returns (TournamentStorage storage ts) { bytes32 position = TOURNAMENT_STORAGE_POSITION; assembly { ts.slot := position } } - - function arenaInitializers() internal pure returns (Initializers storage ai) { + function arenaInitializers() internal pure returns (Initializers storage ai) { bytes32 position = ARENA_INITIALIZERS_POSITION; assembly { ai.slot := position @@ -117,10 +92,11 @@ contract WithArenaStorage { function arenaStorage() internal pure returns (ArenaStorage storage) { return LibArenaStorage.arenaStorage(); } + function arenaConstants() internal pure returns (ArenaConstants storage) { return LibArenaStorage.arenaConstants(); } - + function tournamentStorage() internal pure returns (TournamentStorage storage) { return LibArenaStorage.tournamentStorage(); } diff --git a/contracts/libraries/LibArtifactUtils.sol b/contracts/libraries/LibArtifactUtils.sol index 71785c2..fd6c30e 100644 --- a/contracts/libraries/LibArtifactUtils.sol +++ b/contracts/libraries/LibArtifactUtils.sol @@ -12,17 +12,7 @@ import {LibStorage, GameStorage, GameConstants} from "./LibStorage.sol"; import {LibArenaStorage, ArenaConstants} from "./LibArenaStorage.sol"; // Type imports -import { - Biome, - Planet, - PlanetExtendedInfo, - PlanetType, - Artifact, - ArtifactType, - ArtifactRarity, - DFPFindArtifactArgs, - DFTCreateArtifactArgs -} from "../DFTypes.sol"; +import {Biome, Planet, PlanetExtendedInfo, PlanetType, Artifact, ArtifactType, ArtifactRarity, DFPFindArtifactArgs, DFTCreateArtifactArgs} from "../DFTypes.sol"; library LibArtifactUtils { function gs() internal pure returns (GameStorage storage) { @@ -75,20 +65,20 @@ library LibArtifactUtils { uint256 id = uint256(keccak256(abi.encodePacked(planetId, gs().miscNonce++))); - DFTCreateArtifactArgs memory createArtifactArgs = - DFTCreateArtifactArgs( - id, - msg.sender, - planetId, - ArtifactRarity.Unknown, - Biome.Unknown, - shipType, - address(this), - owner - ); + DFTCreateArtifactArgs memory createArtifactArgs = DFTCreateArtifactArgs( + id, + msg.sender, + planetId, + ArtifactRarity.Unknown, + Biome.Unknown, + shipType, + address(this), + owner + ); - Artifact memory foundArtifact = - DFArtifactFacet(address(this)).createArtifact(createArtifactArgs); + Artifact memory foundArtifact = DFArtifactFacet(address(this)).createArtifact( + createArtifactArgs + ); LibGameUtils._putArtifactOnPlanet(foundArtifact.id, planetId); return id; @@ -102,36 +92,28 @@ library LibArtifactUtils { Biome biome = LibGameUtils._getBiome(info.spaceType, args.biomebase); bytes memory randomness = ""; - if(arenaConstants().RANDOM_ARTIFACTS) { + if (arenaConstants().RANDOM_ARTIFACTS) { randomness = abi.encodePacked(args.coreAddress, blockhash(info.prospectedBlockNumber)); } - uint256 artifactSeed = - uint256( - keccak256( - abi.encodePacked( - args.planetId, - randomness - ) - ) - ); - - (ArtifactType artifactType, uint256 levelBonus) = - LibGameUtils._randomArtifactTypeAndLevelBonus(artifactSeed, biome, info.spaceType); - - DFTCreateArtifactArgs memory createArtifactArgs = - DFTCreateArtifactArgs( - artifactSeed, - msg.sender, - args.planetId, - LibGameUtils.artifactRarityFromPlanetLevel(levelBonus + planet.planetLevel), - biome, - artifactType, - args.coreAddress, - address(0) - ); + uint256 artifactSeed = uint256(keccak256(abi.encodePacked(args.planetId, randomness))); + + (ArtifactType artifactType, uint256 levelBonus) = LibGameUtils + ._randomArtifactTypeAndLevelBonus(artifactSeed, biome, info.spaceType); + + DFTCreateArtifactArgs memory createArtifactArgs = DFTCreateArtifactArgs( + artifactSeed, + msg.sender, + args.planetId, + LibGameUtils.artifactRarityFromPlanetLevel(levelBonus + planet.planetLevel), + biome, + artifactType, + args.coreAddress, + address(0) + ); - Artifact memory foundArtifact = - DFArtifactFacet(address(this)).createArtifact(createArtifactArgs); + Artifact memory foundArtifact = DFArtifactFacet(address(this)).createArtifact( + createArtifactArgs + ); LibGameUtils._putArtifactOnPlanet(foundArtifact.id, args.planetId); @@ -189,14 +171,13 @@ library LibArtifactUtils { if (planet.silver == 0) { planet.silver = 1; - Planet memory defaultPlanet = - LibGameUtils._defaultPlanet( - locationId, - planet.planetLevel, - PlanetType.SILVER_MINE, - extendedInfo.spaceType, - gameConstants().TIME_FACTOR_HUNDREDTHS - ); + Planet memory defaultPlanet = LibGameUtils._defaultPlanet( + locationId, + planet.planetLevel, + PlanetType.SILVER_MINE, + extendedInfo.spaceType, + gameConstants().TIME_FACTOR_HUNDREDTHS + ); planet.silverGrowth = defaultPlanet.silverGrowth; } @@ -304,9 +285,8 @@ library LibArtifactUtils { emit ArtifactDeactivated(msg.sender, artifact.id, locationId); DFArtifactFacet(address(this)).updateArtifact(artifact); - bool shouldBurn = - artifact.artifactType == ArtifactType.PlanetaryShield || - artifact.artifactType == ArtifactType.PhotoidCannon; + bool shouldBurn = artifact.artifactType == ArtifactType.PlanetaryShield || + artifact.artifactType == ArtifactType.PhotoidCannon; if (shouldBurn) { // burn it after use. will be owned by contract but not on a planet anyone can control LibGameUtils._takeArtifactOffPlanet(artifact.id, locationId); diff --git a/contracts/libraries/LibGameUtils.sol b/contracts/libraries/LibGameUtils.sol index 5854a0b..4f9000e 100644 --- a/contracts/libraries/LibGameUtils.sol +++ b/contracts/libraries/LibGameUtils.sol @@ -10,19 +10,7 @@ import {ABDKMath64x64} from "../vendor/libraries/ABDKMath64x64.sol"; // Storage imports import {LibStorage, GameStorage, GameConstants, SnarkConstants} from "./LibStorage.sol"; -import { - Biome, - SpaceType, - Planet, - PlanetType, - PlanetEventType, - Artifact, - ArtifactType, - ArtifactRarity, - Upgrade, - ArenaCreateRevealPlanetArgs, - PlanetDefaultStats -} from "../DFTypes.sol"; +import {Biome, SpaceType, Planet, PlanetType, PlanetEventType, Artifact, ArtifactType, ArtifactRarity, Upgrade, ArenaCreateRevealPlanetArgs, PlanetDefaultStats} from "../DFTypes.sol"; library LibGameUtils { function gs() internal pure returns (GameStorage storage) { @@ -48,29 +36,32 @@ library LibGameUtils { } } - function _hashInitPlanet(ArenaCreateRevealPlanetArgs memory planet) public pure returns (bytes32) { - return( - keccak256(abi.encode( - planet.location, - planet.x, - planet.y, - planet.perlin, - planet.planetType, - planet.requireValidLocationId, - planet.isTargetPlanet, - planet.isSpawnPlanet, - planet.blockedPlanetIds - )) + function _hashInitPlanet(ArenaCreateRevealPlanetArgs memory planet) + public + pure + returns (bytes32) + { + return ( + keccak256( + abi.encode( + planet.location, + planet.x, + planet.y, + planet.perlin, + planet.planetType, + planet.requireValidLocationId, + planet.isTargetPlanet, + planet.isSpawnPlanet, + planet.blockedPlanetIds + ) + ) ); } function _locationIdValid(uint256 _loc) public view returns (bool) { - return ( - (_loc < + return ((_loc < (21888242871839275222246405745257275088548364400416034343698204186575808495617 / - gameConstants().PLANET_RARITY)) - && _planetLevelBelowLevel0Threshold(_loc) - ); + gameConstants().PLANET_RARITY)) && _planetLevelBelowLevel0Threshold(_loc)); } function _planetLevelBelowLevel0Threshold(uint256 _loc) public view returns (bool) { @@ -185,8 +176,9 @@ library LibGameUtils { uint256 worldRadiusMin = gameConstants().WORLD_RADIUS_MIN; uint256 target4 = gs().initializedPlanetCountByLevel[4] + 20 * nPlayers; uint256 targetRadiusSquared4 = (target4 * gs().cumulativeRarities[4] * 100) / 314; - uint256 r4 = - ABDKMath64x64.toUInt(ABDKMath64x64.sqrt(ABDKMath64x64.fromUInt(targetRadiusSquared4))); + uint256 r4 = ABDKMath64x64.toUInt( + ABDKMath64x64.sqrt(ABDKMath64x64.fromUInt(targetRadiusSquared4)) + ); if (r4 < worldRadiusMin) { return worldRadiusMin; } else { @@ -342,14 +334,13 @@ library LibGameUtils { }); } - Upgrade memory ret = - Upgrade({ - popCapMultiplier: 100, - popGroMultiplier: 100, - rangeMultiplier: 100, - speedMultiplier: 100, - defMultiplier: 100 - }); + Upgrade memory ret = Upgrade({ + popCapMultiplier: 100, + popGroMultiplier: 100, + rangeMultiplier: 100, + speedMultiplier: 100, + defMultiplier: 100 + }); if (artifact.artifactType == ArtifactType.Monolith) { ret.popCapMultiplier += 5; @@ -439,8 +430,9 @@ library LibGameUtils { for (uint256 i = 0; i < artifactsOnThisPlanet; i++) { if (gs().planetArtifacts[locationId][i] == artifactId) { - Artifact memory artifact = - DFArtifactFacet(address(this)).getArtifact(gs().planetArtifacts[locationId][i]); + Artifact memory artifact = DFArtifactFacet(address(this)).getArtifact( + gs().planetArtifacts[locationId][i] + ); require( !isActivated(artifact), @@ -499,8 +491,9 @@ library LibGameUtils { // otherwise, return a 'null artifact' function getActiveArtifact(uint256 locationId) public view returns (Artifact memory) { for (uint256 i; i < gs().planetArtifacts[locationId].length; i++) { - Artifact memory artifact = - DFArtifactFacet(address(this)).getArtifact(gs().planetArtifacts[locationId][i]); + Artifact memory artifact = DFArtifactFacet(address(this)).getArtifact( + gs().planetArtifacts[locationId][i] + ); if (isActivated(artifact)) { return artifact; @@ -746,4 +739,4 @@ library LibGameUtils { _planet.populationGrowth = (_planet.populationGrowth * TIME_FACTOR_HUNDREDTHS) / 100; _planet.silverGrowth = (_planet.silverGrowth * TIME_FACTOR_HUNDREDTHS) / 100; } -} \ No newline at end of file +} diff --git a/contracts/libraries/LibLazyUpdate.sol b/contracts/libraries/LibLazyUpdate.sol index dc49b7d..b8202fa 100644 --- a/contracts/libraries/LibLazyUpdate.sol +++ b/contracts/libraries/LibLazyUpdate.sol @@ -9,17 +9,7 @@ import {LibStorage, GameStorage} from "./LibStorage.sol"; import {ArenaStorage, ArenaConstants, LibArenaStorage} from "./LibArenaStorage.sol"; // Type imports -import { - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2, - PlanetType, - PlanetEventMetadata, - PlanetEventType, - ArrivalData, - ArrivalType, - Artifact -} from "../DFTypes.sol"; +import {Planet, PlanetExtendedInfo, PlanetExtendedInfo2, PlanetType, PlanetEventMetadata, PlanetEventType, ArrivalData, ArrivalType, Artifact} from "../DFTypes.sol"; library LibLazyUpdate { function gs() internal pure returns (GameStorage storage) { @@ -72,44 +62,41 @@ library LibLazyUpdate { return; } - int128 _timeElapsed = - ABDKMath64x64.sub( - ABDKMath64x64.fromUInt(updateToTime), - ABDKMath64x64.fromUInt(planetExtendedInfo.lastUpdated) - ); + int128 _timeElapsed = ABDKMath64x64.sub( + ABDKMath64x64.fromUInt(updateToTime), + ABDKMath64x64.fromUInt(planetExtendedInfo.lastUpdated) + ); int128 _one = ABDKMath64x64.fromUInt(1); - int128 _denominator = - ABDKMath64x64.add( - ABDKMath64x64.mul( - ABDKMath64x64.exp( - ABDKMath64x64.div( + int128 _denominator = ABDKMath64x64.add( + ABDKMath64x64.mul( + ABDKMath64x64.exp( + ABDKMath64x64.div( + ABDKMath64x64.mul( ABDKMath64x64.mul( - ABDKMath64x64.mul( - ABDKMath64x64.fromInt(-4), - ABDKMath64x64.fromUInt(planet.populationGrowth) - ), - _timeElapsed + ABDKMath64x64.fromInt(-4), + ABDKMath64x64.fromUInt(planet.populationGrowth) ), - ABDKMath64x64.fromUInt(planet.populationCap) - ) - ), - ABDKMath64x64.sub( - ABDKMath64x64.div( - ABDKMath64x64.fromUInt(planet.populationCap), - ABDKMath64x64.fromUInt(planet.population) + _timeElapsed ), - _one + ABDKMath64x64.fromUInt(planet.populationCap) ) ), - _one - ); + ABDKMath64x64.sub( + ABDKMath64x64.div( + ABDKMath64x64.fromUInt(planet.populationCap), + ABDKMath64x64.fromUInt(planet.population) + ), + _one + ) + ), + _one + ); - uint256 newPopulation = - ABDKMath64x64.toUInt( - ABDKMath64x64.div(ABDKMath64x64.fromUInt(planet.populationCap), _denominator) - ); + uint256 newPopulation = ABDKMath64x64.toUInt( + ABDKMath64x64.div(ABDKMath64x64.fromUInt(planet.populationCap), _denominator) + ); // If paused, no energy growth if (planetExtendedInfo2.pausers > 0 && newPopulation > planet.population) { @@ -161,7 +148,10 @@ library LibLazyUpdate { uint256 sendingTeam = arenaStorage().arenaPlayerInfo[arrival.player].team; uint256 planetOwnerTeam = arenaStorage().arenaPlayerInfo[planet.owner].team; // checks whether the planet is owned by the player sending ships - if (arrival.player == planet.owner || (arenaConstants().TEAMS_ENABLED && sendingTeam == planetOwnerTeam)) { + if ( + arrival.player == planet.owner || + (arenaConstants().TEAMS_ENABLED && sendingTeam == planetOwnerTeam) + ) { // simply increase the population if so planet.population = planet.population + arrival.popArriving; } else { diff --git a/contracts/libraries/LibPlanet.sol b/contracts/libraries/LibPlanet.sol index 6139562..06e7524 100644 --- a/contracts/libraries/LibPlanet.sol +++ b/contracts/libraries/LibPlanet.sol @@ -10,20 +10,7 @@ import {Verifier} from "../Verifier.sol"; import {LibStorage, GameStorage, GameConstants, SnarkConstants} from "./LibStorage.sol"; // Type imports -import { - Artifact, - ArtifactType, - DFPInitPlanetArgs, - Planet, - PlanetEventMetadata, - PlanetExtendedInfo, - PlanetExtendedInfo2, - PlanetType, - RevealedCoords, - SpaceType, - Upgrade, - UpgradeBranch -} from "../DFTypes.sol"; +import {Artifact, ArtifactType, DFPInitPlanetArgs, Planet, PlanetEventMetadata, PlanetExtendedInfo, PlanetExtendedInfo2, PlanetType, RevealedCoords, SpaceType, Upgrade, UpgradeBranch} from "../DFTypes.sol"; library LibPlanet { function gs() internal pure returns (GameStorage storage) { @@ -73,8 +60,8 @@ library LibPlanet { uint256 _perlin, bool _isHomePlanet ) public view returns (DFPInitPlanetArgs memory) { - (uint256 level, PlanetType planetType, SpaceType spaceType) = - LibGameUtils._getPlanetLevelTypeAndSpaceType(_location, _perlin); + (uint256 level, PlanetType planetType, SpaceType spaceType) = LibGameUtils + ._getPlanetLevelTypeAndSpaceType(_location, _perlin); if (_isHomePlanet) { require(level == 0, "Can only initialize on planet level 0"); @@ -126,8 +113,11 @@ library LibPlanet { ) public { require(LibGameUtils._locationIdValid(_location), "Not a valid planet location"); - DFPInitPlanetArgs memory initArgs = - getDefaultInitPlanetArgs(_location, _perlin, _isHomePlanet); + DFPInitPlanetArgs memory initArgs = getDefaultInitPlanetArgs( + _location, + _perlin, + _isHomePlanet + ); _initializePlanet(initArgs); gs().planetIds.push(_location); @@ -144,14 +134,13 @@ library LibPlanet { // planet initialize should set the planet to default state, including having the owner be adress 0x0 // then it's the responsibility for the mechanics to set the owner to the player - Planet memory defaultPlanet = - LibGameUtils._defaultPlanet( - args.location, - args.level, - args.planetType, - args.spaceType, - args.TIME_FACTOR_HUNDREDTHS - ); + Planet memory defaultPlanet = LibGameUtils._defaultPlanet( + args.location, + args.level, + args.planetType, + args.spaceType, + args.TIME_FACTOR_HUNDREDTHS + ); _planet.owner = defaultPlanet.owner; _planet.isHomePlanet = defaultPlanet.isHomePlanet; _planet.range = defaultPlanet.range; diff --git a/contracts/libraries/LibStorage.sol b/contracts/libraries/LibStorage.sol index 2f2f28a..21d8508 100644 --- a/contracts/libraries/LibStorage.sol +++ b/contracts/libraries/LibStorage.sol @@ -2,18 +2,7 @@ pragma solidity ^0.8.0; // Type imports -import { - Planet, - PlanetExtendedInfo, - PlanetExtendedInfo2, - PlanetEventMetadata, - PlanetDefaultStats, - Upgrade, - RevealedCoords, - Player, - ArrivalData, - Artifact -} from "../DFTypes.sol"; +import {Planet, PlanetExtendedInfo, PlanetExtendedInfo2, PlanetEventMetadata, PlanetDefaultStats, Upgrade, RevealedCoords, Player, ArrivalData, Artifact} from "../DFTypes.sol"; struct WhitelistStorage { bool enabled; diff --git a/facets.json b/facets.json index c5060e2..93d95ce 100644 --- a/facets.json +++ b/facets.json @@ -1 +1,17 @@ -[{"facetAddress":"0x0000000000000000000000000000000000000000","action":2,"functionSelectors":["0x188caf8a","0x69dd7a89","0xd8d5fc87","0xbadaad2a","0x43c614ed","0x18178ad4","0xf743af90","0x71746141","0xe3d607a9"]}] \ No newline at end of file +[ + { + "facetAddress": "0x0000000000000000000000000000000000000000", + "action": 2, + "functionSelectors": [ + "0x188caf8a", + "0x69dd7a89", + "0xd8d5fc87", + "0xbadaad2a", + "0x43c614ed", + "0x18178ad4", + "0xf743af90", + "0x71746141", + "0xe3d607a9" + ] + } +] diff --git a/hardhat.config.ts b/hardhat.config.ts index b71c105..74804ec 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -47,7 +47,7 @@ const AbiItemsToIgnore = [ }, { facet: 'DFAdminFacet', - events: ['AdminPlanetCreated','PauseStateChanged'], + events: ['AdminPlanetCreated', 'PauseStateChanged'], }, // { // facet: 'DFArenaGetterFacet', @@ -60,7 +60,7 @@ const AbiItemsToIgnore = [ { facet: 'DFMoveFacet', events: ['GameStarted'], - } + }, ]; // Warning: If the facet is not in the `facets` directory, getFullyQualifiedFacetName will not work. diff --git a/package.json b/package.json index cd8f92c..99ba5ff 100644 --- a/package.json +++ b/package.json @@ -93,4 +93,4 @@ "hardhat:deploy:arena": "run-s wait:node \"deploy:arena {@}\" --", "start:arena": "run-p hardhat:node \"arena:deploy {@}\" --" } -} \ No newline at end of file +} diff --git a/subgraph/oldschema.graphql b/subgraph/oldschema.graphql index db953f3..7794663 100644 --- a/subgraph/oldschema.graphql +++ b/subgraph/oldschema.graphql @@ -247,7 +247,7 @@ type Arena @entity { type ArenaPlayer @entity { id: ID! - address: ID! + address: ID! initTimestamp: Int! winner: Boolean! arena: Arena! diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 08ca099..f2254e2 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -87,8 +87,8 @@ type Badge @entity { id: ID! configPlayer: ConfigPlayer! startYourEngine: Boolean! - nice: Boolean!, - based: Boolean!, + nice: Boolean! + based: Boolean! ouch: Boolean! } diff --git a/subgraph/src/arena.ts b/subgraph/src/arena.ts index e28a078..b89ebc2 100644 --- a/subgraph/src/arena.ts +++ b/subgraph/src/arena.ts @@ -59,10 +59,10 @@ function updatePlayerElo(configHash: string, p1Id: string, p2Id: string, winner: p2.elo = p2NewRating as i32; // We increment the gamesFinished in the GameOver for the winner no matter what. // Here, we only increment for the player who didn't win. - if(p1.address != winner) { + if (p1.address != winner) { p1.gamesFinished += p1.gamesFinished + 1; } - if(p2.address != winner) { + if (p2.address != winner) { p2.gamesFinished += p2.gamesFinished + 1; } @@ -75,7 +75,6 @@ function updatePlayerElo(configHash: string, p1Id: string, p2Id: string, winner: } p1.save(); p2.save(); - } function updateTeamElo( @@ -341,11 +340,10 @@ export function handleGameover(event: Gameover): void { // Update Badges let badges = p1.badge; const winningPlayer = loadArenaPlayer(arenaId(winnerAddress)); - if(badges) { + if (badges) { const allTimeBadges = loadBadge(p1.badge!); updateBadge(allTimeBadges, arena, winningPlayer, p1); - } - else { + } else { const newBadges = new Badge(configPlayerIdString); newBadges.configPlayer = p1.id; newBadges.startYourEngine = false; diff --git a/subgraph/src/helpers/constants.ts b/subgraph/src/helpers/constants.ts index 12678c9..e520521 100644 --- a/subgraph/src/helpers/constants.ts +++ b/subgraph/src/helpers/constants.ts @@ -6,4 +6,4 @@ export const MAX_INT_32 = 2147483647 - 1; export const NICE = 69; export const BASED = 420; export const OUCH = 24 * 60 * 60; -export const START_ENGINE = 1; \ No newline at end of file +export const START_ENGINE = 1; diff --git a/subgraph/src/helpers/elo.ts b/subgraph/src/helpers/elo.ts index ecc2627..57ba24a 100644 --- a/subgraph/src/helpers/elo.ts +++ b/subgraph/src/helpers/elo.ts @@ -1,27 +1,27 @@ // Credit to https://github.com/dmamills/elo-rank // License: MIT -import { K_FACTOR } from "./constants"; +import { K_FACTOR } from './constants'; function getExpectedProb(p1Rating: number, p2Rating: number): number { return 1 / (1 + Math.pow(10, (p2Rating - p1Rating) / 400)); } function updateRating(expected: number, actual: number, current: number): number { - return Math.round(current + (K_FACTOR * (actual - expected))); + return Math.round(current + K_FACTOR * (actual - expected)); } -export function updateElo(p1Rating: number, p2Rating: number, p1Win: bool): Array { - const expectedProbP1Win = getExpectedProb(p1Rating, p2Rating); - const expectedProbP2Win = getExpectedProb(p1Rating, p2Rating); +export function updateElo(p1Rating: number, p2Rating: number, p1Win: bool): Array { + const expectedProbP1Win = getExpectedProb(p1Rating, p2Rating); + const expectedProbP2Win = getExpectedProb(p1Rating, p2Rating); - let p1NewRating: number, p2NewRating: number; - if (p1Win) { - p1NewRating = updateRating(expectedProbP1Win, 1, p1Rating); - p2NewRating = updateRating(expectedProbP2Win, 0, p2Rating); - } else { - p1NewRating = updateRating(expectedProbP1Win, 0, p1Rating); - p2NewRating = updateRating(expectedProbP2Win, 1, p2Rating); - } + let p1NewRating: number, p2NewRating: number; + if (p1Win) { + p1NewRating = updateRating(expectedProbP1Win, 1, p1Rating); + p2NewRating = updateRating(expectedProbP2Win, 0, p2Rating); + } else { + p1NewRating = updateRating(expectedProbP1Win, 0, p1Rating); + p2NewRating = updateRating(expectedProbP2Win, 1, p2Rating); + } - return [p1NewRating, p2NewRating]; - } \ No newline at end of file + return [p1NewRating, p2NewRating]; +} diff --git a/subgraph/src/mapping.ts b/subgraph/src/mapping.ts index 60be80e..641f3e1 100644 --- a/subgraph/src/mapping.ts +++ b/subgraph/src/mapping.ts @@ -49,7 +49,7 @@ import { refreshSpaceshipFromContractData, refreshVoyageFromContractData, } from './helpers/decoders'; -import { DarkForest as DFDiamond } from '../generated/templates' +import { DarkForest as DFDiamond } from '../generated/templates'; // NOTE: the timestamps within are all unix epoch in seconds NOT MILLISECONDS // like in all the JS code where youll see divided by contractPrecision. As a @@ -376,12 +376,12 @@ export function handleLobbyCreated(event: LobbyCreated): void { arena.lobbyAddress = event.params.lobbyAddress.toHexString(); arena.gameOver = false; // arena.players = []; - arena.winners = new Array() + arena.winners = new Array(); arena.save(); - // /* new data source */ - DFDiamond.create(event.params.lobbyAddress) -} + // /* new data source */ + DFDiamond.create(event.params.lobbyAddress); +} function processScheduledArrivalsSinceLastBlock(meta: Meta, current: i32): void { // process last+1 up to and including current diff --git a/tasks/arena-deploy.ts b/tasks/arena-deploy.ts index 13287f2..14d9841 100644 --- a/tasks/arena-deploy.ts +++ b/tasks/arena-deploy.ts @@ -141,7 +141,7 @@ export async function deployAndCutArena( { ownerAddress, allowListEnabled, - allowedAddresses=[], + allowedAddresses = [], initializers, save = true, }: { @@ -240,11 +240,7 @@ export async function deployAndCutArena( calldata: '0x', }; - const diamondInit = await deployContract( - 'DFArenaInitialize', - { }, - hre - ); + const diamondInit = await deployContract('DFArenaInitialize', {}, hre); // EIP-2535 specifies that the `diamondCut` function takes two optional // arguments: address _init and bytes calldata _calldata @@ -257,7 +253,7 @@ export async function deployAndCutArena( { allowListEnabled, artifactBaseURI: tokenBaseUri, - allowedAddresses + allowedAddresses, }, ]); diff --git a/tasks/arena-upgrade.ts b/tasks/arena-upgrade.ts index bd9edc6..584946d 100644 --- a/tasks/arena-upgrade.ts +++ b/tasks/arena-upgrade.ts @@ -14,16 +14,16 @@ import { deployMoveFacet, deployWhitelistFacet, } from './deploy'; -import * as fs from "fs"; -import * as path from "path"; +import * as fs from 'fs'; +import * as path from 'path'; import { remove } from 'lodash'; import { deployArenaStarterFacet } from './arena-deploy'; const DEPLOY_PATH = './facets.json'; task('arena:upgrade', 'upgrade contracts and replace in the diamond') -.addParam('load', 'load deployed facet addresses from file', false, types.boolean) -.setAction(upgrade); + .addParam('load', 'load deployed facet addresses from file', false, types.boolean) + .setAction(upgrade); async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) { await hre.run('utils:assertChainId'); @@ -41,13 +41,12 @@ async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) var toCut: FacetCut[] = []; - if(args.load) { + if (args.load) { console.log(`loading contracts from ${DEPLOY_PATH}`); const cutsFromFile: FacetCut[] = JSON.parse(fs.readFileSync(DEPLOY_PATH, 'utf-8')); console.log('cuts from file', cutsFromFile); toCut = cutsFromFile; - } - else { + } else { const libraries = await deployLibraries({}, hre); // Dark Forest facets @@ -63,10 +62,18 @@ async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) const adminFacet = await deployAdminFacet({}, libraries, hre); // const lobbyFacet = await deployLobbyFacet({}, libraries, hre); const captureFacet = await deployCaptureFacet({}, libraries, hre); - + const arenaGetterFacet = await deployContract('DFArenaGetterFacet', {}, hre); - const arenaCoreFacet = await deployContract('DFArenaCoreFacet', { LibGameUtils: libraries.LibGameUtils, LibPlanet: libraries.LibPlanet }, hre); - const spaceshipConfigFacet = await deployContract('DFSpaceshipConfigFacet', { LibGameUtils: libraries.LibGameUtils }, hre); + const arenaCoreFacet = await deployContract( + 'DFArenaCoreFacet', + { LibGameUtils: libraries.LibGameUtils, LibPlanet: libraries.LibPlanet }, + hre + ); + const spaceshipConfigFacet = await deployContract( + 'DFSpaceshipConfigFacet', + { LibGameUtils: libraries.LibGameUtils }, + hre + ); const tournamentFacet = await deployContract('DFArenaTournamentFacet', {}, hre); const startFacet = await deployArenaStarterFacet({}, libraries, hre); @@ -76,10 +83,8 @@ async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) ...changes.getFacetCuts('DFSpaceshipConfigFacet', spaceshipConfigFacet), ...changes.getFacetCuts('DFTournamentFacet', tournamentFacet), ...changes.getFacetCuts('DFStartFacet', startFacet), - ]; - - + // The `cuts` to perform for Dark Forest facets const darkForestCuts = [ ...changes.getFacetCuts('DFCoreFacet', coreFacet), @@ -91,18 +96,17 @@ async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) // ...changes.getFacetCuts('DFLobbyFacet', lobbyFacet), ...changes.getFacetCuts('DFCaptureFacet', captureFacet), ]; - + if (isDev) { const debugFacet = await deployDebugFacet({}, libraries, hre); darkForestCuts.push(...changes.getFacetCuts('DFDebugFacet', debugFacet)); } - + // The `cuts` to remove any old, unused functions // const removeCuts = changes.getRemoveCuts(darkForestCuts).concat(changes.getRemoveCuts(arenaDiamondCuts)); // ...removeCuts - - toCut = [...darkForestCuts, ...arenaDiamondCuts]; + toCut = [...darkForestCuts, ...arenaDiamondCuts]; } fs.writeFileSync(DEPLOY_PATH, JSON.stringify(toCut)); @@ -114,8 +118,6 @@ async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) return; } - - // As mentioned in the `deploy` task, EIP-2535 specifies that the `diamondCut` // function takes two optional arguments: address _init and bytes calldata _calldata // However, in a standard upgrade, no state modifications are done, so the 0x0 address @@ -125,7 +127,9 @@ async function upgrade(args: { load: boolean }, hre: HardhatRuntimeEnvironment) const initAddress = hre.ethers.constants.AddressZero; const initFunctionCall = '0x'; - const upgradeTx = await diamond.diamondCut(toCut, initAddress, initFunctionCall, {gasLimit: 15000000}); + const upgradeTx = await diamond.diamondCut(toCut, initAddress, initFunctionCall, { + gasLimit: 15000000, + }); const upgradeReceipt = await upgradeTx.wait(); if (!upgradeReceipt.status) { throw Error(`Diamond cut failed: ${upgradeTx.hash}`); diff --git a/tasks/compile.ts b/tasks/compile.ts index e169189..ee31dfa 100644 --- a/tasks/compile.ts +++ b/tasks/compile.ts @@ -69,7 +69,6 @@ function abiFilter(item: any) { if (component.internalType.includes('][')) { return false; } - } } } @@ -81,13 +80,13 @@ function copyAbiNoPlanetTypeWeights(abi: any): any { console.log('abi length', abi.length); for (var h = 0; h < abi.length; h++) { var abiItem = abi[h]; - if(abiItem.name == 'getInitializers') { + if (abiItem.name == 'getInitializers') { // Position of gameConstants in getAllConstantsABI var gameConstantsComponents = abiItem.outputs[0].components[0].components; - for(var i = 0; i < gameConstantsComponents.length; i++) { + for (var i = 0; i < gameConstantsComponents.length; i++) { var res = gameConstantsComponents[i]; - if(res.name == 'PLANET_TYPE_WEIGHTS') { - gameConstantsComponents = gameConstantsComponents.splice(i,1); + if (res.name == 'PLANET_TYPE_WEIGHTS') { + gameConstantsComponents = gameConstantsComponents.splice(i, 1); } } } diff --git a/tasks/deploy.ts b/tasks/deploy.ts index 7f46b36..e60d416 100644 --- a/tasks/deploy.ts +++ b/tasks/deploy.ts @@ -208,7 +208,7 @@ export async function deployAndCut( }: { ownerAddress: string; allowListEnabled: boolean; - allowedAddresses?: string[] + allowedAddresses?: string[]; initializers: HardhatRuntimeEnvironment['initializers']; }, hre: HardhatRuntimeEnvironment @@ -296,8 +296,8 @@ export async function deployAndCut( { allowListEnabled, artifactBaseURI: tokenBaseUri, - allowedAddresses - } + allowedAddresses, + }, ]); const initTx = await diamondCut.diamondCut(toCut, initAddress, initFunctionCall); @@ -480,7 +480,11 @@ export async function deployCaptureFacet( return contract; } -export async function deployDiamondCutFacet({}, libraries: Libraries, hre: HardhatRuntimeEnvironment) { +export async function deployDiamondCutFacet( + {}, + libraries: Libraries, + hre: HardhatRuntimeEnvironment +) { const factory = await hre.ethers.getContractFactory('DiamondCutFacet'); const contract = await factory.deploy(); await contract.deployTransaction.wait(); diff --git a/test/DFArena.test.ts b/test/DFArena.test.ts index 19709d9..24e32c8 100644 --- a/test/DFArena.test.ts +++ b/test/DFArena.test.ts @@ -87,7 +87,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }); await world.contract.revealLocation(...makeRevealArgs(ADMIN_PLANET_CLOAKED, x, y)); @@ -116,7 +116,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }); await world.contract.revealLocation(...makeRevealArgs(ADMIN_PLANET_CLOAKED, x, y)); @@ -149,7 +149,7 @@ describe('Arena Functions', function () { requireValidLocationId: true, isTargetPlanet: false, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: ADMIN_PLANET_CLOAKED.id, @@ -161,7 +161,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL1_PLANET_SPACE.id, @@ -173,7 +173,7 @@ describe('Arena Functions', function () { requireValidLocationId: true, isTargetPlanet: false, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }, ]; await world.contract.bulkCreatePlanet(planets); @@ -210,7 +210,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }); const createRevealReceipt = await createReveal.wait(); @@ -243,7 +243,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }; planetArgList.push(planetArgs); @@ -290,7 +290,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }); const toPlanetExtended = await world.contract.planetsExtendedInfo(ADMIN_PLANET_CLOAKED.id); @@ -319,7 +319,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }); const toPlanetExtended = await world.contract.planetsExtendedInfo(ADMIN_PLANET_CLOAKED.id); @@ -346,7 +346,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }); await world.contract.revealLocation(...makeRevealArgs(ADMIN_PLANET_CLOAKED, x, y)); @@ -376,7 +376,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }); await world.contract.revealLocation(...makeRevealArgs(LVL2_PLANET_DEEP_SPACE, x, y)); @@ -415,7 +415,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }) ).to.be.revertedWith('admin cannot create target planets'); }); @@ -495,7 +495,7 @@ describe('Arena Functions', function () { requireValidLocationId: true, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }); // await increaseBlockchainTime(); @@ -516,23 +516,23 @@ describe('Arena Functions', function () { ); }); it('needs to have enough energy', async function () { - await expect( - world.user1Core.claimVictory() - ).to.be.revertedWith('victory condition not met'); + await expect(world.user1Core.claimVictory()).to.be.revertedWith( + 'victory condition not met' + ); }); describe('time elapsed', async function () { beforeEach(async function () { await increaseBlocks(); }); it('cannot claim victory with a non-target planet', async function () { - await expect( - world.user1Core.claimVictory() - ).to.be.revertedWith('victory condition not met'); + await expect(world.user1Core.claimVictory()).to.be.revertedWith( + 'victory condition not met' + ); }); it('must own planet to claim victory', async function () { - await expect( - world.user2Core.claimVictory() - ).to.be.revertedWith('victory condition not met'); + await expect(world.user2Core.claimVictory()).to.be.revertedWith( + 'victory condition not met' + ); }); it('gameover event emitted after claim victory', async function () { await increaseBlockchainTime(); @@ -579,7 +579,7 @@ describe('Arena Functions', function () { requireValidLocationId: true, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }); return world; } @@ -609,9 +609,9 @@ describe('Arena Functions', function () { }%` ); - await expect( - world.user1Core.claimVictory() - ).to.be.revertedWith('victory condition not met'); + await expect(world.user1Core.claimVictory()).to.be.revertedWith( + 'victory condition not met' + ); }); it('get round duration 0 if round not over', async function () { @@ -651,7 +651,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }; await defaultWorld.contract.createArenaPlanet(planet); @@ -1078,7 +1078,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }; planetArgList.push(planetArgs); @@ -1142,7 +1142,7 @@ describe('Arena Functions', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }; planetArgList.push(planetArgs); @@ -1256,7 +1256,6 @@ describe('Arena Functions', function () { expect(await world.contract.getGameover()).to.equal(true); }); - }); describe('Blocklist', function () { @@ -1290,13 +1289,10 @@ describe('Arena Functions', function () { await world.user1Core.initializePlayer(...makeInitArgs(ADMIN_PLANET_CLOAKED)); const constants = await world.user1Core.getArenaConstants(); - // there are three planets owned by the player, a spawn planet and two target planets. // the minimum planet threshold is 2. one target planet has been blocked from the player's spawn location. - // we should expect to see that there are - await expect( - world.user1Core.claimVictory() - ).to.be.revertedWith('victory condition not met'); + // we should expect to see that there are + await expect(world.user1Core.claimVictory()).to.be.revertedWith('victory condition not met'); }); it('Confirms that move to target from spawn IS blocked', async function () { // HARD CODED LMAO. @@ -1392,7 +1388,7 @@ describe('Arena Functions', function () { requireValidLocationId: true, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }); return world; diff --git a/test/DFArenaUpgrade.test.ts b/test/DFArenaUpgrade.test.ts index c4116f3..05c50ac 100644 --- a/test/DFArenaUpgrade.test.ts +++ b/test/DFArenaUpgrade.test.ts @@ -1,7 +1,14 @@ import { expect } from 'chai'; import { fixtureLoader, makeInitArgs, makeMoveArgs, makeRevealArgs } from './utils/TestUtils'; import { defaultWorldFixture, World } from './utils/TestWorld'; -import { ADMIN_PLANET_CLOAKED, arenaWorldInitializers, initializers, LVL2_PLANET_SPACE, SPAWN_PLANET_1, VALID_INIT_PERLIN } from './utils/WorldConstants'; +import { + ADMIN_PLANET_CLOAKED, + arenaWorldInitializers, + initializers, + LVL2_PLANET_SPACE, + SPAWN_PLANET_1, + VALID_INIT_PERLIN, +} from './utils/WorldConstants'; import hre from 'hardhat'; import { DarkForest, LobbyCreatedEvent } from '@darkforest_eth/contracts/typechain/DarkForest'; // Note: The deployed addresses are written to the contracts package on any deploy, including for testing @@ -36,9 +43,9 @@ describe.skip('Arena Upgrade', function () { requireValidLocationId: false, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [] + blockedPlanetIds: [], }) - ).to.be.revertedWith('Diamond: Function does not exist'); + ).to.be.revertedWith('Diamond: Function does not exist'); }); it('Creates a new lobby with msg.sender as owner', async function () { @@ -76,8 +83,11 @@ describe.skip('Arena Upgrade', function () { const Verifier = (await deployContract('Verifier', {}, hre)).address; const LibGameUtils = (await deployContract('LibGameUtils', {}, hre)).address; const LibLazyUpdate = (await deployContract('LibLazyUpdate', {}, hre)).address; - const LibArtifactUtils = (await deployContract('LibArtifactUtils', {LibGameUtils}, hre)).address; - const LibPlanet = (await deployContract('LibPlanet', {LibGameUtils, LibLazyUpdate, Verifier}, hre)).address; + const LibArtifactUtils = (await deployContract('LibArtifactUtils', { LibGameUtils }, hre)) + .address; + const LibPlanet = ( + await deployContract('LibPlanet', { LibGameUtils, LibLazyUpdate, Verifier }, hre) + ).address; const diamondInit = await deployContract('DFArenaInitialize', { LibGameUtils }, hre); @@ -86,9 +96,9 @@ describe.skip('Arena Upgrade', function () { { LibGameUtils, LibPlanet }, hre ); - + const arenaGetterFacet = await deployContract('DFArenaGetterFacet', {}, hre); - + const arenaDiamondCuts = [ // Note: The `diamondCut` is omitted because it is cut upon deployment ...changes.getFacetCuts('DFArenaCoreFacet', arenaCoreFacet), @@ -129,7 +139,7 @@ describe.skip('Arena Upgrade', function () { requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }); await lobby.revealLocation(...makeRevealArgs(ADMIN_PLANET_CLOAKED, x, y)); diff --git a/test/utils/TestUtils.ts b/test/utils/TestUtils.ts index 2f20f53..7b70570 100644 --- a/test/utils/TestUtils.ts +++ b/test/utils/TestUtils.ts @@ -94,14 +94,13 @@ export function getInitPlanetHash(initPlanet: { initPlanet.requireValidLocationId, initPlanet.isTargetPlanet, initPlanet.isSpawnPlanet, - initPlanet.blockedPlanetIds.map(x => BigInt(x)) + initPlanet.blockedPlanetIds.map((x) => BigInt(x)), ] ) ); } export function getDeterministicArtifact(planet: TestLocation, initializers: Initializers) { - const abiCoder = ethers.utils.defaultAbiCoder; const artifactSeed = ethers.utils.keccak256( @@ -114,17 +113,25 @@ export function getDeterministicArtifact(planet: TestLocation, initializers: Ini const lastByteOfSeed = seed.mod(BigNumber.from('0xff')).toNumber(); const bigLastByte = BigNumber.from(lastByteOfSeed); - const secondLastByteOfSeed = ((seed.sub(bigLastByte)).div(BigNumber.from(256))).mod(BigNumber.from('0xff')).toNumber(); + const secondLastByteOfSeed = seed + .sub(bigLastByte) + .div(BigNumber.from(256)) + .mod(BigNumber.from('0xff')) + .toNumber(); const perlin = BigNumber.from(planet.perlin).toNumber(); const biome = getBiome({ perlin, biomebase: initializers.BIOMEBASE_KEY, initializers }); console.log(`seed hash ${seed.toHexString()}`); console.log(`seed string ${seed.toString()}`); - console.log('mod', BigNumber.from('0xff').toNumber()) + console.log('mod', BigNumber.from('0xff').toNumber()); console.log('lastByte', lastByteOfSeed); console.log('secondLastByte', secondLastByteOfSeed); - console.log(`hex representations: last byte: ${bigLastByte.toHexString()} second last: ${BigNumber.from(secondLastByteOfSeed).toHexString()}`); + console.log( + `hex representations: last byte: ${bigLastByte.toHexString()} second last: ${BigNumber.from( + secondLastByteOfSeed + ).toHexString()}` + ); console.log('biome', biome); console.log('js artifact seed hex', artifactSeed); @@ -174,7 +181,9 @@ export function getDeterministicArtifact(planet: TestLocation, initializers: Ini bonus = 1; } - const rarity = artifactRarityFromPlanetLevel(planetLevelFromHexPerlin(planet.id.toHexString(), perlin, initializers) + bonus); + const rarity = artifactRarityFromPlanetLevel( + planetLevelFromHexPerlin(planet.id.toHexString(), perlin, initializers) + bonus + ); console.log('artifactType', artifactType, 'rarity', rarity); @@ -256,7 +265,6 @@ export function makeInitArgs( BigNumberish ], BigNumberish - ] { return [ [BN_ZERO, BN_ZERO], @@ -275,7 +283,7 @@ export function makeInitArgs( PERLIN_MIRROR_X ? '1' : '0', PERLIN_MIRROR_Y ? '1' : '0', ], - team + team, ]; } @@ -555,9 +563,8 @@ function planetLevelFromHexPerlin(hex: string, perlin: number, initializers: Ini ret = PlanetLevel.FIVE; } if (ret > initializers.MAX_NATURAL_PLANET_LEVEL) { - ret = initializers.MAX_NATURAL_PLANET_LEVEL as PlanetLevel; } return ret as number; -} \ No newline at end of file +} diff --git a/test/utils/TestWorld.ts b/test/utils/TestWorld.ts index dc0943d..1799df1 100644 --- a/test/utils/TestWorld.ts +++ b/test/utils/TestWorld.ts @@ -54,7 +54,6 @@ export function defaultWorldFixture(): Promise { }); } - export function growingWorldFixture(): Promise { return initializeWorld({ initializers: target4Initializers, @@ -89,16 +88,26 @@ export function testGasLimitInitFixture(): Promise { initializers: initPlanetsInitializers, allowListEnabled: false, allowedAddresses: [ - "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "0x70997970c51812dc3a010c7d01b50e0d17dc79c8", - "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc", "0x90f79bf6eb2c4f870365e785982e1f101e93b906", - "0x15d34aaf54267db7d7c367839aaf71a00a2c6a65", "0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc", - "0x976ea74026e726554db657fa54763abd0c3a0aa9", "0x14dc79964da2c08b23698b3d3cc7ca32193d9955", - "0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f", "0xa0ee7a142d267c1f36714e4a8f75612f20a79720", - "0xbcd4042de499d14e55001ccbb24a551f3b954096", "0x71be63f3384f5fb98995898a86b02fb2426c5788", - "0xfabb0ac9d68b0b445fb7357272ff202c5651694a", "0x1cbd3b2770909d4e10f157cabc84c7264073c9ec", - "0xdf3e18d64bc6a983f673ab319ccae4f1a57c7097", "0xcd3b766ccdd6ae721141f452c550ca635964ce71", - "0x2546bcd3c84621e976d8185a91a922ae77ecec30", "0xbda5747bfd65f08deb54cb465eb87d40e51b197e", - "0xdd2fd4581271e230360230f9337d5c0430bf44c0", "0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199", + '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', + '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', + '0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc', + '0x90f79bf6eb2c4f870365e785982e1f101e93b906', + '0x15d34aaf54267db7d7c367839aaf71a00a2c6a65', + '0x9965507d1a55bcc2695c58ba16fb37d819b0a4dc', + '0x976ea74026e726554db657fa54763abd0c3a0aa9', + '0x14dc79964da2c08b23698b3d3cc7ca32193d9955', + '0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f', + '0xa0ee7a142d267c1f36714e4a8f75612f20a79720', + '0xbcd4042de499d14e55001ccbb24a551f3b954096', + '0x71be63f3384f5fb98995898a86b02fb2426c5788', + '0xfabb0ac9d68b0b445fb7357272ff202c5651694a', + '0x1cbd3b2770909d4e10f157cabc84c7264073c9ec', + '0xdf3e18d64bc6a983f673ab319ccae4f1a57c7097', + '0xcd3b766ccdd6ae721141f452c550ca635964ce71', + '0x2546bcd3c84621e976d8185a91a922ae77ecec30', + '0xbda5747bfd65f08deb54cb465eb87d40e51b197e', + '0xdd2fd4581271e230360230f9337d5c0430bf44c0', + '0x8626f6940e2eb28930efb4cef49b2d1f2c9c1199', ], arena: true, }); @@ -209,7 +218,7 @@ export function teamsFixture(): Promise { return initializeWorld({ initializers: teamsInitializers, allowListEnabled: false, - arena: true + arena: true, }); } diff --git a/test/utils/WorldConstants.ts b/test/utils/WorldConstants.ts index 25740f6..453ca2e 100644 --- a/test/utils/WorldConstants.ts +++ b/test/utils/WorldConstants.ts @@ -64,7 +64,7 @@ export const confirmStartInitializers = settings.parse(decodeInitializers, { INIT_PERLIN_MAX: 31, TARGET_PLANETS: true, CLAIM_VICTORY_ENERGY_PERCENT: 50, - CONFIRM_START: true + CONFIRM_START: true, }); export const allowListInitializers = settings.parse(decodeInitializers, { @@ -74,10 +74,9 @@ export const allowListInitializers = settings.parse(decodeInitializers, { INIT_PERLIN_MAX: 31, TARGET_PLANETS: true, CLAIM_VICTORY_ENERGY_PERCENT: 50, - CONFIRM_START: true + CONFIRM_START: true, }); - export const noAdminInitializers = settings.parse(decodeInitializers, { ...defaultInitializerValues, NO_ADMIN: true, @@ -90,7 +89,7 @@ export const planetLevelThresholdInitializer = settings.parse(decodeInitializers export const deterministicArtifactInitializers = settings.parse(decodeInitializers, { ...defaultInitializerValues, - RANDOM_ARTIFACTS: false + RANDOM_ARTIFACTS: false, }); export const teamsInitializers = settings.parse(decodeInitializers, { @@ -400,7 +399,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: ARTIFACT_PLANET_1.id.toHexString(), @@ -412,7 +411,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL1_ASTEROID_2.id.toHexString(), @@ -424,7 +423,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [ADMIN_PLANET_CLOAKED.id.toHexString()] + blockedPlanetIds: [ADMIN_PLANET_CLOAKED.id.toHexString()], }, { location: LVL1_PLANET_SPACE.id.toHexString(), @@ -436,7 +435,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [ADMIN_PLANET_CLOAKED.id.toHexString()] + blockedPlanetIds: [ADMIN_PLANET_CLOAKED.id.toHexString()], }, { location: LVL0_PLANET_DEEP_SPACE.id.toHexString(), @@ -448,7 +447,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: true, isSpawnPlanet: false, - blockedPlanetIds: [ADMIN_PLANET_CLOAKED.id.toHexString()] + blockedPlanetIds: [ADMIN_PLANET_CLOAKED.id.toHexString()], }, { location: LVL0_PLANET_POPCAP_BOOSTED.id.toHexString(), @@ -460,7 +459,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL1_ASTEROID_DEEP_SPACE.id.toHexString(), @@ -472,7 +471,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL1_PLANET_DEEP_SPACE.id.toHexString(), @@ -484,7 +483,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL0_PLANET_POPCAP_BOOSTED.id.toHexString(), @@ -496,7 +495,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL3_UNOWNED_DEEP_SPACE.id.toHexString(), @@ -508,7 +507,7 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, { location: LVL3_SPACETIME_2.id.toHexString(), @@ -520,16 +519,16 @@ const INIT_PLANETS: ArenaPlanets = [ requireValidLocationId: false, isTargetPlanet: false, isSpawnPlanet: true, - blockedPlanetIds: [] + blockedPlanetIds: [], }, -] +]; export const initPlanetsInitializers = settings.parse(decodeInitializers, { ...defaultInitializerValues, NO_ADMIN: true, MANUAL_SPAWN: true, TARGET_PLANETS: true, - INIT_PLANETS: INIT_PLANETS.slice(0,10) + INIT_PLANETS: INIT_PLANETS.slice(0, 10), }); export const multipleTargetPlanetVictoryInitializers = settings.parse(decodeInitializers, { @@ -537,7 +536,7 @@ export const multipleTargetPlanetVictoryInitializers = settings.parse(decodeInit TARGETS_REQUIRED_FOR_VICTORY: 2, MANUAL_SPAWN: true, TARGET_PLANETS: true, - INIT_PLANETS: INIT_PLANETS.slice(0,5) + INIT_PLANETS: INIT_PLANETS.slice(0, 5), }); export const blockListInitializers = settings.parse(decodeInitializers, { @@ -545,8 +544,7 @@ export const blockListInitializers = settings.parse(decodeInitializers, { TARGETS_REQUIRED_FOR_VICTORY: 2, MANUAL_SPAWN: true, TARGET_PLANETS: true, - INIT_PLANETS: [INIT_PLANETS[0], INIT_PLANETS[2],INIT_PLANETS[3], INIT_PLANETS[4]], + INIT_PLANETS: [INIT_PLANETS[0], INIT_PLANETS[2], INIT_PLANETS[3], INIT_PLANETS[4]], BLOCK_MOVES: true, BLOCK_CAPTURE: true, }); - diff --git a/utils/deploy.ts b/utils/deploy.ts index d55c273..3b7f5f7 100644 --- a/utils/deploy.ts +++ b/utils/deploy.ts @@ -37,7 +37,11 @@ export async function deployContract( return contract; } -export function writeToContractsPackage(hre: HardhatRuntimeEnvironment, tsContents: string, append = false) { +export function writeToContractsPackage( + hre: HardhatRuntimeEnvironment, + tsContents: string, + append = false +) { const { jsContents, dtsContents } = tscompile(tsContents); const contractsFileTS = path.join(hre.packageDirs['@darkforest_eth/contracts'], 'index.ts'); @@ -46,7 +50,7 @@ export function writeToContractsPackage(hre: HardhatRuntimeEnvironment, tsConten const options = prettier.resolveConfig.sync(contractsFileTS); - if(append) { + if (append) { fs.appendFileSync( contractsFileTS, prettier.format(tsContents, { ...options, parser: 'babel-ts' }) @@ -58,9 +62,8 @@ export function writeToContractsPackage(hre: HardhatRuntimeEnvironment, tsConten fs.appendFileSync( contractsFileDTS, prettier.format(dtsContents, { ...options, parser: 'babel-ts' }) - ); - } - else { + ); + } else { fs.writeFileSync( contractsFileTS, prettier.format(tsContents, { ...options, parser: 'babel-ts' }) @@ -72,7 +75,7 @@ export function writeToContractsPackage(hre: HardhatRuntimeEnvironment, tsConten fs.writeFileSync( contractsFileDTS, prettier.format(dtsContents, { ...options, parser: 'babel-ts' }) - ); + ); } } @@ -160,7 +163,7 @@ export async function saveDeploy( export const LIB_ARTIFACT_UTILS_ADDRESS = '${args.libraries.LibArtifactUtils}'; `; - writeToContractsPackage(hre, tsContents); + writeToContractsPackage(hre, tsContents); } export async function createLobby( @@ -177,8 +180,8 @@ export async function createLobby( initializers, { allowListEnabled: false, - artifactBaseURI: "", - allowedAddresses: [] + artifactBaseURI: '', + allowedAddresses: [], }, ]);