From 00c14eadbff99fa523dc97af2773bc758ab43479 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Sun, 2 Oct 2022 21:54:20 +0100 Subject: [PATCH 01/10] test: bulk withdraw silver --- eth/contracts/facets/DFCoreFacet.sol | 20 +++++++++++ eth/contracts/libraries/LibPlanet.sol | 24 +++++++++++++ eth/test/DFSilver.ts | 50 +++++++++++++++++++++++++-- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/eth/contracts/facets/DFCoreFacet.sol b/eth/contracts/facets/DFCoreFacet.sol index cd16c381..f334cccd 100644 --- a/eth/contracts/facets/DFCoreFacet.sol +++ b/eth/contracts/facets/DFCoreFacet.sol @@ -28,6 +28,8 @@ contract DFCoreFacet is WithStorage { event LocationRevealed(address revealer, uint256 loc, uint256 x, uint256 y); event PlanetSilverWithdrawn(address player, uint256 loc, uint256 amount); + // The difference here is that TokenSilver amount is divided by contract precision + event TokenSilverWithdrawn(address player, uint256 loc, uint256 amount); ////////////////////// /// ACCESS CONTROL /// @@ -213,4 +215,22 @@ contract DFCoreFacet is WithStorage { LibPlanet.withdrawSilver(locationId, amount); emit PlanetSilverWithdrawn(msg.sender, locationId, amount); } + + // withdraw silver + function withdrawSilverAsteroid(uint256 locationId) public notPaused { + refreshPlanet(locationId); + uint256 amount = LibPlanet.withdrawSilverAsteroid(locationId); + emit TokenSilverWithdrawn(msg.sender, locationId, amount); + } + + // withdraw silver + function bulkWithdrawSilverAsteroid(uint256[] memory locationIds) public notPaused { + uint256 amount = 0; + for (uint256 i = 0; i < locationIds.length; i++) { + refreshPlanet(locationIds[i]); + amount += LibPlanet.withdrawSilverAsteroid(locationIds[i]); + } + // Using 0 for locationId, bad pattern + emit TokenSilverWithdrawn(msg.sender, 0, amount); + } } diff --git a/eth/contracts/libraries/LibPlanet.sol b/eth/contracts/libraries/LibPlanet.sol index 50fda7a7..31adea3a 100644 --- a/eth/contracts/libraries/LibPlanet.sol +++ b/eth/contracts/libraries/LibPlanet.sol @@ -391,4 +391,28 @@ library LibPlanet { scoreGained = (scoreGained * gameConstants().SILVER_SCORE_VALUE) / 100; gs().players[msg.sender].score += scoreGained; } + + // Withdraw Max Silver + function withdrawSilverAsteroid(uint256 locationId) public returns (uint256) { + Planet storage planet = gs().planets[locationId]; + require(planet.owner == msg.sender, "you must own this planet"); + require( + planet.planetType == PlanetType.SILVER_MINE, + "can only withdraw silver from asteroids" + ); + require(!planet.destroyed, "planet is destroyed"); + // No op in case client is off + if (planet.silver == 0) return 0; + + uint256 silverId = LibSilver.create(); + // Divide by 1000 for precision + uint256 silverAmount = planet.silver / 1000; + planet.silver = 0; + DFTokenFacet(address(this)).mint(msg.sender, silverId, silverAmount); + + uint256 scoreGained = silverAmount; + scoreGained = (scoreGained * gameConstants().SILVER_SCORE_VALUE) / 100; + gs().players[msg.sender].score += scoreGained; + return silverAmount; + } } diff --git a/eth/test/DFSilver.ts b/eth/test/DFSilver.ts index 17a08413..11a006fb 100644 --- a/eth/test/DFSilver.ts +++ b/eth/test/DFSilver.ts @@ -1,8 +1,23 @@ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { conquerUnownedPlanet, feedSilverToCap, makeInitArgs } from './utils/TestUtils'; +import { + conquerUnownedPlanet, + feedSilverToCap, + increaseBlockchainTime, + makeInitArgs, +} from './utils/TestUtils'; import { defaultWorldFixture, World } from './utils/TestWorld'; -import { LVL1_ASTEROID_1, LVL3_SPACETIME_1, SPAWN_PLANET_1 } from './utils/WorldConstants'; +import { + LVL1_ASTEROID_1, + LVL1_ASTEROID_2, + LVL1_ASTEROID_DEEP_SPACE, + LVL1_ASTEROID_NEBULA, + LVL3_SPACETIME_1, + SPAWN_PLANET_1, +} from './utils/WorldConstants'; + +const CONTRACT_PRECISION = 1_000; +const SILVER_TOKEN_ID = '0x0300000000000000000000000000000000000000000000000000000000000000'; describe('DFSilver', async function () { // Bump the time out so that the test doesn't timeout during @@ -47,6 +62,37 @@ describe('DFSilver', async function () { ); }); + it('allows player to bulk withdraw silver from asteroids', async function () { + await conquerUnownedPlanet(world, world.user1Core, SPAWN_PLANET_1, LVL1_ASTEROID_2); + await conquerUnownedPlanet(world, world.user1Core, SPAWN_PLANET_1, LVL1_ASTEROID_NEBULA); + await conquerUnownedPlanet(world, world.user1Core, SPAWN_PLANET_1, LVL1_ASTEROID_DEEP_SPACE); + + // await feedSilverToCap(world, world.user1Core, LVL1_ASTEROID_1, LVL3_SPACETIME_2); + const ast1 = await world.contract.planets(LVL1_ASTEROID_1.id); + const ast2 = await world.contract.planets(LVL1_ASTEROID_2.id); + const ast3 = await world.contract.planets(LVL1_ASTEROID_NEBULA.id); + const ast4 = await world.contract.planets(LVL1_ASTEROID_DEEP_SPACE.id); + + // Let Asteroids fill up + await increaseBlockchainTime(); + + const tx = await world.user1Core.bulkWithdrawSilverAsteroid([ + LVL1_ASTEROID_1.id, + LVL1_ASTEROID_2.id, + LVL1_ASTEROID_NEBULA.id, + LVL1_ASTEROID_DEEP_SPACE.id, + ]); + const rct = await tx.wait(); + console.log(`bulk withdraw used ${rct.gasUsed.toNumber() / 4} gas per asteroid`); + + expect( + await (await world.contract.balanceOf(world.user1.address, SILVER_TOKEN_ID)).toNumber() + ).to.equal( + ast1.silverCap.add(ast2.silverCap).add(ast3.silverCap).add(ast4.silverCap).toNumber() / + CONTRACT_PRECISION + ); + }); + it("doesn't allow player to withdraw more silver than planet has", async function () { const withdrawnAmount = (await world.contract.planets(LVL3_SPACETIME_1.id)).silverCap.add(1000); From 4949cd4a42577822bcd4f47e3b6824f323b72e68 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 12:02:10 +0100 Subject: [PATCH 02/10] contracts: add silver withdraw and bulk silver withdraw from asteroid --- eth/contracts/libraries/LibPlanet.sol | 2 +- eth/test/DFSilver.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eth/contracts/libraries/LibPlanet.sol b/eth/contracts/libraries/LibPlanet.sol index 31adea3a..cf520956 100644 --- a/eth/contracts/libraries/LibPlanet.sol +++ b/eth/contracts/libraries/LibPlanet.sol @@ -392,7 +392,7 @@ library LibPlanet { gs().players[msg.sender].score += scoreGained; } - // Withdraw Max Silver + // Withdraws All Silver on Asteroid function withdrawSilverAsteroid(uint256 locationId) public returns (uint256) { Planet storage planet = gs().planets[locationId]; require(planet.owner == msg.sender, "you must own this planet"); diff --git a/eth/test/DFSilver.ts b/eth/test/DFSilver.ts index 11a006fb..8a2ce044 100644 --- a/eth/test/DFSilver.ts +++ b/eth/test/DFSilver.ts @@ -19,7 +19,7 @@ import { const CONTRACT_PRECISION = 1_000; const SILVER_TOKEN_ID = '0x0300000000000000000000000000000000000000000000000000000000000000'; -describe('DFSilver', async function () { +describe.only('DFSilver', async function () { // Bump the time out so that the test doesn't timeout during // initial fixture creation this.timeout(1000 * 60); From f9d3c38f9c7a413df6af6ef8fd133afcbd27dfca Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Sun, 2 Oct 2022 21:58:31 +0100 Subject: [PATCH 03/10] clean bulk silver test --- eth/test/DFSilver.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/eth/test/DFSilver.ts b/eth/test/DFSilver.ts index 8a2ce044..31cced1e 100644 --- a/eth/test/DFSilver.ts +++ b/eth/test/DFSilver.ts @@ -17,7 +17,6 @@ import { } from './utils/WorldConstants'; const CONTRACT_PRECISION = 1_000; -const SILVER_TOKEN_ID = '0x0300000000000000000000000000000000000000000000000000000000000000'; describe.only('DFSilver', async function () { // Bump the time out so that the test doesn't timeout during @@ -85,11 +84,11 @@ describe.only('DFSilver', async function () { const rct = await tx.wait(); console.log(`bulk withdraw used ${rct.gasUsed.toNumber() / 4} gas per asteroid`); - expect( - await (await world.contract.balanceOf(world.user1.address, SILVER_TOKEN_ID)).toNumber() - ).to.equal( + const expectedSilverMint = ast1.silverCap.add(ast2.silverCap).add(ast3.silverCap).add(ast4.silverCap).toNumber() / - CONTRACT_PRECISION + CONTRACT_PRECISION; + expect(await (await world.contract.getSilverBalance(world.user1.address)).toNumber()).to.equal( + expectedSilverMint ); }); From 90eed0966e49676af26796ad62497778cd1267d6 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Sun, 2 Oct 2022 22:04:05 +0100 Subject: [PATCH 04/10] test: confirm all silver is gone after bulk withdraw --- eth/test/DFSilver.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/eth/test/DFSilver.ts b/eth/test/DFSilver.ts index 31cced1e..af69cb52 100644 --- a/eth/test/DFSilver.ts +++ b/eth/test/DFSilver.ts @@ -67,10 +67,6 @@ describe.only('DFSilver', async function () { await conquerUnownedPlanet(world, world.user1Core, SPAWN_PLANET_1, LVL1_ASTEROID_DEEP_SPACE); // await feedSilverToCap(world, world.user1Core, LVL1_ASTEROID_1, LVL3_SPACETIME_2); - const ast1 = await world.contract.planets(LVL1_ASTEROID_1.id); - const ast2 = await world.contract.planets(LVL1_ASTEROID_2.id); - const ast3 = await world.contract.planets(LVL1_ASTEROID_NEBULA.id); - const ast4 = await world.contract.planets(LVL1_ASTEROID_DEEP_SPACE.id); // Let Asteroids fill up await increaseBlockchainTime(); @@ -81,13 +77,25 @@ describe.only('DFSilver', async function () { LVL1_ASTEROID_NEBULA.id, LVL1_ASTEROID_DEEP_SPACE.id, ]); + const rct = await tx.wait(); console.log(`bulk withdraw used ${rct.gasUsed.toNumber() / 4} gas per asteroid`); + const ast1 = await world.contract.planets(LVL1_ASTEROID_1.id); + const ast2 = await world.contract.planets(LVL1_ASTEROID_2.id); + const ast3 = await world.contract.planets(LVL1_ASTEROID_NEBULA.id); + const ast4 = await world.contract.planets(LVL1_ASTEROID_DEEP_SPACE.id); + + // Confirm all silver has been withdrawn + expect(ast1.silver).to.equal(0); + expect(ast2.silver).to.equal(0); + expect(ast3.silver).to.equal(0); + expect(ast4.silver).to.equal(0); + const expectedSilverMint = ast1.silverCap.add(ast2.silverCap).add(ast3.silverCap).add(ast4.silverCap).toNumber() / CONTRACT_PRECISION; - expect(await (await world.contract.getSilverBalance(world.user1.address)).toNumber()).to.equal( + expect((await world.contract.getSilverBalance(world.user1.address)).toNumber()).to.equal( expectedSilverMint ); }); From 88d7da56dabfe33ca696800e636d759da5e93ec9 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 12:59:03 +0100 Subject: [PATCH 05/10] contracts: fix tests --- eth/contracts/facets/DFCoreFacet.sol | 19 +++------ eth/contracts/libraries/LibPlanet.sol | 32 +-------------- eth/test/DFSilver.ts | 59 ++++++++------------------- 3 files changed, 24 insertions(+), 86 deletions(-) diff --git a/eth/contracts/facets/DFCoreFacet.sol b/eth/contracts/facets/DFCoreFacet.sol index f334cccd..3e2d2879 100644 --- a/eth/contracts/facets/DFCoreFacet.sol +++ b/eth/contracts/facets/DFCoreFacet.sol @@ -28,8 +28,6 @@ contract DFCoreFacet is WithStorage { event LocationRevealed(address revealer, uint256 loc, uint256 x, uint256 y); event PlanetSilverWithdrawn(address player, uint256 loc, uint256 amount); - // The difference here is that TokenSilver amount is divided by contract precision - event TokenSilverWithdrawn(address player, uint256 loc, uint256 amount); ////////////////////// /// ACCESS CONTROL /// @@ -210,27 +208,20 @@ contract DFCoreFacet is WithStorage { } // withdraw silver - function withdrawSilver(uint256 locationId, uint256 amount) public notPaused { + function withdrawSilver(uint256 locationId) public notPaused { refreshPlanet(locationId); - LibPlanet.withdrawSilver(locationId, amount); + uint256 amount = LibPlanet.withdrawSilver(locationId); emit PlanetSilverWithdrawn(msg.sender, locationId, amount); } // withdraw silver - function withdrawSilverAsteroid(uint256 locationId) public notPaused { - refreshPlanet(locationId); - uint256 amount = LibPlanet.withdrawSilverAsteroid(locationId); - emit TokenSilverWithdrawn(msg.sender, locationId, amount); - } - - // withdraw silver - function bulkWithdrawSilverAsteroid(uint256[] memory locationIds) public notPaused { + function bulkWithdrawSilver(uint256[] memory locationIds) public notPaused { uint256 amount = 0; for (uint256 i = 0; i < locationIds.length; i++) { refreshPlanet(locationIds[i]); - amount += LibPlanet.withdrawSilverAsteroid(locationIds[i]); + amount += LibPlanet.withdrawSilver(locationIds[i]); } // Using 0 for locationId, bad pattern - emit TokenSilverWithdrawn(msg.sender, 0, amount); + emit PlanetSilverWithdrawn(msg.sender, 0, amount); } } diff --git a/eth/contracts/libraries/LibPlanet.sol b/eth/contracts/libraries/LibPlanet.sol index cf520956..64dba81a 100644 --- a/eth/contracts/libraries/LibPlanet.sol +++ b/eth/contracts/libraries/LibPlanet.sol @@ -365,35 +365,8 @@ library LibPlanet { } } - function withdrawSilver(uint256 locationId, uint256 silverToWithdraw) public { - Planet storage planet = gs().planets[locationId]; - require(planet.owner == msg.sender, "you must own this planet"); - require( - planet.planetType == PlanetType.TRADING_POST, - "can only withdraw silver from trading posts" - ); - require(!planet.destroyed, "planet is destroyed"); - require( - planet.silver >= silverToWithdraw, - "tried to withdraw more silver than exists on planet" - ); - - planet.silver -= silverToWithdraw; - - // Energy and Silver are not stored as floats in the smart contracts, - // so any of those values coming from the contracts need to be divided by - // `CONTRACT_PRECISION` to get their true integer value. - uint256 scoreGained = silverToWithdraw / 1000; - // increase silver token count; - uint256 silverId = LibSilver.create(); - DFTokenFacet(address(this)).mint(msg.sender, silverId, scoreGained); - - scoreGained = (scoreGained * gameConstants().SILVER_SCORE_VALUE) / 100; - gs().players[msg.sender].score += scoreGained; - } - // Withdraws All Silver on Asteroid - function withdrawSilverAsteroid(uint256 locationId) public returns (uint256) { + function withdrawSilver(uint256 locationId) public returns (uint256) { Planet storage planet = gs().planets[locationId]; require(planet.owner == msg.sender, "you must own this planet"); require( @@ -410,9 +383,6 @@ library LibPlanet { planet.silver = 0; DFTokenFacet(address(this)).mint(msg.sender, silverId, silverAmount); - uint256 scoreGained = silverAmount; - scoreGained = (scoreGained * gameConstants().SILVER_SCORE_VALUE) / 100; - gs().players[msg.sender].score += scoreGained; return silverAmount; } } diff --git a/eth/test/DFSilver.ts b/eth/test/DFSilver.ts index af69cb52..5d565f57 100644 --- a/eth/test/DFSilver.ts +++ b/eth/test/DFSilver.ts @@ -1,27 +1,20 @@ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; import { expect } from 'chai'; -import { - conquerUnownedPlanet, - feedSilverToCap, - increaseBlockchainTime, - makeInitArgs, -} from './utils/TestUtils'; +import { conquerUnownedPlanet, increaseBlockchainTime, makeInitArgs } from './utils/TestUtils'; import { defaultWorldFixture, World } from './utils/TestWorld'; import { LVL1_ASTEROID_1, LVL1_ASTEROID_2, LVL1_ASTEROID_DEEP_SPACE, LVL1_ASTEROID_NEBULA, - LVL3_SPACETIME_1, SPAWN_PLANET_1, } from './utils/WorldConstants'; const CONTRACT_PRECISION = 1_000; -describe.only('DFSilver', async function () { +describe('DFSilver', async function () { // Bump the time out so that the test doesn't timeout during // initial fixture creation - this.timeout(1000 * 60); let world: World; async function worldFixture() { @@ -30,11 +23,11 @@ describe.only('DFSilver', async function () { // Conquer MINE_REGULAR and LVL3_SPACETIME_1 to accumulate silver await conquerUnownedPlanet(world, world.user1Core, SPAWN_PLANET_1, LVL1_ASTEROID_1); - await conquerUnownedPlanet(world, world.user1Core, SPAWN_PLANET_1, LVL3_SPACETIME_1); - // Fill up LVL3_SPACETIME_1 with silvers - await feedSilverToCap(world, world.user1Core, LVL1_ASTEROID_1, LVL3_SPACETIME_1); + await increaseBlockchainTime(); + // Wait for Asteroid to fill up + await world.contract.refreshPlanet(LVL1_ASTEROID_1.id); return world; } @@ -42,12 +35,12 @@ describe.only('DFSilver', async function () { world = await loadFixture(worldFixture); }); - it('allows player to withdraw silver from trading posts', async function () { - const withdrawnAmount = (await world.contract.planets(LVL3_SPACETIME_1.id)).silverCap; + it('allows player to withdraw silver from asteroid', async function () { + const withdrawnAmount = (await world.contract.planets(LVL1_ASTEROID_1.id)).silverCap.div(1000); - await expect(world.user1Core.withdrawSilver(LVL3_SPACETIME_1.id, withdrawnAmount)) + await expect(world.user1Core.withdrawSilver(LVL1_ASTEROID_1.id)) .to.emit(world.contract, 'PlanetSilverWithdrawn') - .withArgs(world.user1.address, LVL3_SPACETIME_1.id, withdrawnAmount); + .withArgs(world.user1.address, LVL1_ASTEROID_1.id, withdrawnAmount); // According to DarkForestPlanet.sol: // Energy and Silver are not stored as floats in the smart contracts, @@ -56,9 +49,7 @@ describe.only('DFSilver', async function () { // FIXME(blaine): This should have been done client-side because this type of // division isn't supposed to be done in the contract. That's the whole point of // `CONTRACT_PRECISION` - expect(await world.contract.getSilverBalance(world.user1.address)).to.equal( - withdrawnAmount.div(1000) - ); + expect(await world.contract.getSilverBalance(world.user1.address)).to.equal(withdrawnAmount); }); it('allows player to bulk withdraw silver from asteroids', async function () { @@ -71,7 +62,7 @@ describe.only('DFSilver', async function () { // Let Asteroids fill up await increaseBlockchainTime(); - const tx = await world.user1Core.bulkWithdrawSilverAsteroid([ + const tx = await world.user1Core.bulkWithdrawSilver([ LVL1_ASTEROID_1.id, LVL1_ASTEROID_2.id, LVL1_ASTEROID_NEBULA.id, @@ -100,32 +91,18 @@ describe.only('DFSilver', async function () { ); }); - it("doesn't allow player to withdraw more silver than planet has", async function () { - const withdrawnAmount = (await world.contract.planets(LVL3_SPACETIME_1.id)).silverCap.add(1000); - - await expect( - world.user1Core.withdrawSilver(LVL3_SPACETIME_1.id, withdrawnAmount) - ).to.be.revertedWith('tried to withdraw more silver than exists on planet'); - - expect(await world.contract.getSilverBalance(world.user1.address)).to.equal(0); - }); - - it("doesn't allow player to withdraw silver from non-trading post", async function () { - const withdrawnAmount = (await world.contract.planets(LVL1_ASTEROID_1.id)).silverCap; - - await expect( - world.user1Core.withdrawSilver(LVL1_ASTEROID_1.id, withdrawnAmount) - ).to.be.revertedWith('can only withdraw silver from trading posts'); + it("doesn't allow player to withdraw silver from non asteroid", async function () { + await expect(world.user1Core.withdrawSilver(SPAWN_PLANET_1.id)).to.be.revertedWith( + 'can only withdraw silver from asteroids' + ); expect(await world.contract.getSilverBalance(world.user1.address)).to.equal(0); }); it("doesn't allow player to withdraw silver from planet that is not theirs", async function () { - const withdrawnAmount = (await world.contract.planets(LVL3_SPACETIME_1.id)).silverCap; - - await expect( - world.user2Core.withdrawSilver(LVL3_SPACETIME_1.id, withdrawnAmount) - ).to.be.revertedWith('you must own this planet'); + await expect(world.user2Core.withdrawSilver(LVL1_ASTEROID_1.id)).to.be.revertedWith( + 'you must own this planet' + ); expect(await world.contract.getSilverBalance(world.user1.address)).to.equal(0); expect(await world.contract.getSilverBalance(world.user2.address)).to.equal(0); From 9f9437ec84059c0079580c460a6da23512d7c602 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 13:00:50 +0100 Subject: [PATCH 06/10] contracts: fix tests --- eth/test/DFSilver.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eth/test/DFSilver.ts b/eth/test/DFSilver.ts index 5d565f57..758cb6fb 100644 --- a/eth/test/DFSilver.ts +++ b/eth/test/DFSilver.ts @@ -36,7 +36,9 @@ describe('DFSilver', async function () { }); it('allows player to withdraw silver from asteroid', async function () { - const withdrawnAmount = (await world.contract.planets(LVL1_ASTEROID_1.id)).silverCap.div(1000); + const withdrawnAmount = (await world.contract.planets(LVL1_ASTEROID_1.id)).silverCap.div( + CONTRACT_PRECISION + ); await expect(world.user1Core.withdrawSilver(LVL1_ASTEROID_1.id)) .to.emit(world.contract, 'PlanetSilverWithdrawn') From ff1d18a852b781e77a090a57fe129c37a766a27f Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 13:52:05 +0100 Subject: [PATCH 07/10] client: extract button works --- client/src/Backend/GameLogic/GameManager.ts | 14 +- client/src/Backend/GameLogic/GameUIManager.ts | 14 +- .../Frontend/Components/OpenPaneButtons.tsx | 2 +- .../src/Frontend/Panes/PlanetContextPane.tsx | 11 +- .../src/Frontend/Utils/ShortcutConstants.ts | 1 + client/src/Frontend/Views/ArtifactRow.tsx | 33 ++-- client/src/Frontend/Views/SendResources.tsx | 158 +++++++++++------- client/src/Frontend/Views/TopBar.tsx | 19 ++- client/src/Frontend/Views/WithdrawSilver.tsx | 2 +- packages/types/src/transactions.ts | 1 - 10 files changed, 136 insertions(+), 119 deletions(-) diff --git a/client/src/Backend/GameLogic/GameManager.ts b/client/src/Backend/GameLogic/GameManager.ts index fe7be87e..a368211d 100644 --- a/client/src/Backend/GameLogic/GameManager.ts +++ b/client/src/Backend/GameLogic/GameManager.ts @@ -2429,7 +2429,6 @@ class GameManager extends EventEmitter { public async withdrawSilver( locationId: LocationId, - amount: number, bypassChecks = false ): Promise> { try { @@ -2442,8 +2441,8 @@ class GameManager extends EventEmitter { if (!planet) { throw new Error('tried to withdraw silver from an unknown planet'); } - if (planet.planetType !== PlanetType.TRADING_POST) { - throw new Error('can only withdraw silver from spacetime rips'); + if (planet.planetType !== PlanetType.SILVER_MINE) { + throw new Error('can only withdraw silver from asteroid'); } if (planet.owner !== this.account) { throw new Error('can only withdraw silver from a planet you own'); @@ -2451,12 +2450,6 @@ class GameManager extends EventEmitter { if (planet.transactions?.hasTransaction(isUnconfirmedWithdrawSilverTx)) { throw new Error('a withdraw silver action is already in progress for this planet'); } - if (amount > planet.silver) { - throw new Error('not enough silver to withdraw!'); - } - if (amount === 0) { - throw new Error('must withdraw more than 0 silver!'); - } if (planet.destroyed) { throw new Error("can't withdraw silver from a destroyed planet"); } @@ -2467,9 +2460,8 @@ class GameManager extends EventEmitter { const txIntent: UnconfirmedWithdrawSilver = { methodName: 'withdrawSilver', contract: this.contractsAPI.contract, - args: Promise.resolve([locationIdToDecStr(locationId), amount * CONTRACT_PRECISION]), + args: Promise.resolve([locationIdToDecStr(locationId)]), locationId, - amount, }; // Always await the submitTransaction so we can catch rejections diff --git a/client/src/Backend/GameLogic/GameUIManager.ts b/client/src/Backend/GameLogic/GameUIManager.ts index d9a50e28..02e822e4 100644 --- a/client/src/Backend/GameLogic/GameUIManager.ts +++ b/client/src/Backend/GameLogic/GameUIManager.ts @@ -397,18 +397,8 @@ class GameUIManager extends EventEmitter { this.gameManager.deactivateArtifact(locationId, artifactId); } - public withdrawSilver(locationId: LocationId, amount: number) { - const dontShowWarningStorageKey = `${this.getAccount()?.toLowerCase()}-withdrawnWarningAcked`; - - if (localStorage.getItem(dontShowWarningStorageKey) !== 'true') { - localStorage.setItem(dontShowWarningStorageKey, 'true'); - const confirmationText = - `Are you sure you want withdraw this silver? Once you withdraw it, you ` + - `cannot deposit it again. Your withdrawn silver amount will be added to your score. You'll only see this warning once!`; - if (!confirm(confirmationText)) return; - } - - this.gameManager.withdrawSilver(locationId, amount); + public withdrawSilver(locationId: LocationId) { + this.gameManager.withdrawSilver(locationId); } public startWormholeFrom(planet: LocatablePlanet): Promise { diff --git a/client/src/Frontend/Components/OpenPaneButtons.tsx b/client/src/Frontend/Components/OpenPaneButtons.tsx index 2e3bae31..15431e5a 100644 --- a/client/src/Frontend/Components/OpenPaneButtons.tsx +++ b/client/src/Frontend/Components/OpenPaneButtons.tsx @@ -133,7 +133,7 @@ export function OpenPlanetInfoButton({ return ( } helpContent={PlanetInfoHelpContent()} diff --git a/client/src/Frontend/Panes/PlanetContextPane.tsx b/client/src/Frontend/Panes/PlanetContextPane.tsx index ca079330..e8000190 100644 --- a/client/src/Frontend/Panes/PlanetContextPane.tsx +++ b/client/src/Frontend/Panes/PlanetContextPane.tsx @@ -6,8 +6,6 @@ import { CapturePlanetButton } from '../Components/CapturePlanetButton'; import { VerticalSplit } from '../Components/CoreUI'; import { MineArtifactButton } from '../Components/MineArtifactButton'; import { - OpenBroadcastPaneButton, - OpenHatPaneButton, OpenManagePlanetInventoryButton, OpenPlanetInfoButton, OpenUpgradeDetailsPaneButton, @@ -53,15 +51,10 @@ function PlanetContextPaneContent({ } let upgradeRow = null; - if (!p?.destroyed && owned) { + if (!p?.destroyed && owned && p?.planetType == PlanetType.PLANET) { upgradeRow = ; } - let hatRow = null; - if (!p?.destroyed && owned) { - hatRow = ; - } - let withdrawRow = null; if (!p?.destroyed && owned && p?.planetType === PlanetType.TRADING_POST) { withdrawRow = ; @@ -86,12 +79,10 @@ function PlanetContextPaneContent({ <> {upgradeRow} - <> - {hatRow} {withdrawRow} diff --git a/client/src/Frontend/Utils/ShortcutConstants.ts b/client/src/Frontend/Utils/ShortcutConstants.ts index ec8b6961..f810f7fb 100644 --- a/client/src/Frontend/Utils/ShortcutConstants.ts +++ b/client/src/Frontend/Utils/ShortcutConstants.ts @@ -14,6 +14,7 @@ export const TOGGLE_TRANSACTIONS_PANE = "'"; export const TOGGLE_PLANET_INVENTORY_PANE = 's'; export const TOGGLE_HAT_PANE = 'x'; export const TOGGLE_ABANDON = 'r'; +export const TOGGLE_WITHDRAW = ']'; export const INVADE = 'y'; export const MINE_ARTIFACT = 'f'; export const TOGGLE_BROADCAST_PANE = 'z'; diff --git a/client/src/Frontend/Views/ArtifactRow.tsx b/client/src/Frontend/Views/ArtifactRow.tsx index f142392b..24a800b6 100644 --- a/client/src/Frontend/Views/ArtifactRow.tsx +++ b/client/src/Frontend/Views/ArtifactRow.tsx @@ -104,18 +104,25 @@ export function SelectArtifactRow({ artifacts: Artifact[]; }) { return ( - - {artifacts.length > 0 && - artifacts.map((a) => ( - - - - - ))} - +
+ + {artifacts.length > 0 && + artifacts.map((a) => ( + + + + + ))} + +
); } diff --git a/client/src/Frontend/Views/SendResources.tsx b/client/src/Frontend/Views/SendResources.tsx index 28b9e36e..a054cd63 100644 --- a/client/src/Frontend/Views/SendResources.tsx +++ b/client/src/Frontend/Views/SendResources.tsx @@ -1,6 +1,10 @@ import { formatNumber } from '@dfdao/gamelogic'; import { nameOfArtifact, nameOfSpaceship } from '@dfdao/procedural'; -import { isUnconfirmedMoveTx, isUnconfirmedReleaseTx } from '@dfdao/serde'; +import { + isUnconfirmedMoveTx, + isUnconfirmedReleaseTx, + isUnconfirmedWithdrawSilverTx, +} from '@dfdao/serde'; import { Artifact, Planet, Spaceship, TooltipName } from '@dfdao/types'; import React, { useCallback } from 'react'; import styled from 'styled-components'; @@ -18,23 +22,24 @@ import dfstyles from '../Styles/dfstyles'; import { useAccount, usePlanetInactiveArtifacts, useUIManager } from '../Utils/AppHooks'; import { useEmitterValue } from '../Utils/EmitterHooks'; import { useOnUp } from '../Utils/KeyEmitters'; -import { TOGGLE_ABANDON, TOGGLE_SEND } from '../Utils/ShortcutConstants'; +import { TOGGLE_ABANDON, TOGGLE_SEND, TOGGLE_WITHDRAW } from '../Utils/ShortcutConstants'; import { SelectArtifactRow } from './ArtifactRow'; import { SelectSpaceshipRow } from './SpaceshipRow'; const StyledSendResources = styled.div` display: flex; flex-direction: column; - gap: 8px; + gap: 4px; `; const StyledShowPercent = styled.div` display: inline-block; + min-width: 35px; & > span:first-child { width: 3em; text-align: right; - margin-right: 1em; + margin-right: 0.5em; } & > span:last-child { @@ -54,8 +59,8 @@ const StyledShowPercent = styled.div` function ShowPercent({ value, setValue }: { value: number; setValue: (x: number) => void }) { return ( - {value}% - + {/* {value}% */} + setValue(value - 1)}> @@ -68,6 +73,7 @@ function ShowPercent({ value, setValue }: { value: number; setValue: (x: number) const ResourceRowDetails = styled.div` display: inline-flex; align-items: center; + justify-content: space-between; gap: 4px; `; @@ -95,26 +101,38 @@ function ResourceBar({ return ( <> - - - - {getResource(value)} - {isSilver ? 'silver' : 'energy'} - - - - ) => { - setValue(parseInt(e.target.value, 10)); - }} - /> + {isSilver ? ( + + Extract {getResource(value)} silver + + ) : ( +
+ +
+ + {getResource(value)} + + {' '} + ({value}%) {isSilver ? 'silver' : 'energy'} + +
+ +
+ + ) => { + setValue(parseInt(e.target.value, 10)); + }} + /> +
+ )} ); } @@ -153,6 +171,37 @@ function AbandonButton({ ); } +function ExtractButton({ + planet, + extracting, + disabled, +}: { + planet?: Planet; + extracting: boolean; + disabled?: boolean; +}) { + const uiManager = useUIManager(); + + if (!planet) return null; + + const silver = planet.silver; + + return ( + uiManager.withdrawSilver(planet.locationId)} + shortcutKey={TOGGLE_WITHDRAW} + shortcutText={TOGGLE_WITHDRAW} + disabled={planet.isHomePlanet || disabled} + > + {/* */} + {extracting ? 'Extracting' : `Extract all (${Math.floor(silver)}) silver`} + {/* */} + + ); +} + function SendRow({ toggleSending, artifact, @@ -215,9 +264,11 @@ export function SendResources({ const isSendingShip = uiManager.isSendingShip(locationId); const isAbandoning = useEmitterValue(uiManager.isAbandoning$, false); + const isExtracting = false; + const isSendingForces = useEmitterValue(uiManager.isSending$, false); const energySending = uiManager.getForcesSending(locationId); - const silverSending = uiManager.getSilverSending(locationId); + const silverSending = 100; const artifactSending = uiManager.getArtifactSending(locationId); const spaceshipSending = uiManager.getSpaceshipSending(locationId); @@ -230,15 +281,6 @@ export function SendResources({ }, [uiManager, locationId] ); - - const updateSilverSending = useCallback( - (silverPercent) => { - if (!locationId) return; - uiManager.setSilverSending(locationId, silverPercent); - }, - [uiManager, locationId] - ); - const updateArtifactSending = useCallback( (sendArtifact) => { if (!locationId) return; @@ -259,16 +301,11 @@ export function SendResources({ // that key is const energyShortcuts = '1234567890'.split(''); - // same as above, except for silver - const silverShortcuts = '!@#$%^&*()'.split(''); - // for each of the above keys, we set up a listener that is triggered whenever that key is // pressed, and sets the corresponding resource sending amount for (let i = 0; i < energyShortcuts.length; i++) { // eslint-disable-next-line react-hooks/rules-of-hooks useOnUp(energyShortcuts[i], () => updateEnergySending((i + 1) * 10), [updateEnergySending]); - // eslint-disable-next-line react-hooks/rules-of-hooks - useOnUp(silverShortcuts[i], () => updateSilverSending((i + 1) * 10), [updateSilverSending]); } useOnUp( @@ -285,20 +322,6 @@ export function SendResources({ }, [uiManager, locationId, updateEnergySending] ); - useOnUp( - '_', - () => { - updateSilverSending(uiManager.getSilverSending(locationId) - 10); - }, - [uiManager, locationId, updateSilverSending] - ); - useOnUp( - '+', - () => { - updateSilverSending(uiManager.getSilverSending(locationId) + 10); - }, - [uiManager, locationId, updateSilverSending] - ); const artifacts = usePlanetInactiveArtifacts(p); @@ -340,6 +363,19 @@ export function SendResources({ ); } + let extractRow; + if (p.value && p.value.transactions?.hasTransaction(isUnconfirmedWithdrawSilverTx)) { + extractRow = ( + + + + ); + } else if (p.value && !p.value.destroyed) { + extractRow = ( + + ); + } + return ( {owned && !p.value?.destroyed && ( @@ -350,17 +386,9 @@ export function SendResources({ setValue={updateEnergySending} disabled={disableSliders} /> - {p.value && p.value.silver > 0 && ( - - )} )} + {p.value && artifacts.length > 0 && ( 0 && extractRow} + {uiManager.getSpaceJunkEnabled() && owned ? abandonRow : null} ); diff --git a/client/src/Frontend/Views/TopBar.tsx b/client/src/Frontend/Views/TopBar.tsx index f4340c61..f6434edf 100644 --- a/client/src/Frontend/Views/TopBar.tsx +++ b/client/src/Frontend/Views/TopBar.tsx @@ -5,6 +5,7 @@ import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import { CaptureZonesGeneratedEvent } from '../../Backend/GameLogic/CaptureZoneGenerator'; import { Hook } from '../../_types/global/GlobalTypes'; +import { Btn } from '../Components/Btn'; import { AlignCenterHorizontally } from '../Components/CoreUI'; import { AccountLabel } from '../Components/Labels/Labels'; import { Gold, Red, Sub, Text, White } from '../Components/Text'; @@ -35,17 +36,23 @@ function BoardPlacement({ account }: { account: EthAddress | undefined }) { if (!player.value) { content = n/a; } else { - let formattedScore = 'n/a'; + let formattedScore = uiManager + .getGameManager() + .getContract() + .getSilverBalance(player.value.address); if (player.value.score !== undefined && player.value.score !== null) { formattedScore = player.value.score.toLocaleString(); } content = ( - - - score: {formattedScore} - - +
+ + + stockpile: {formattedScore} + + + Extract all +
); } diff --git a/client/src/Frontend/Views/WithdrawSilver.tsx b/client/src/Frontend/Views/WithdrawSilver.tsx index 2b3de3eb..cf283896 100644 --- a/client/src/Frontend/Views/WithdrawSilver.tsx +++ b/client/src/Frontend/Views/WithdrawSilver.tsx @@ -79,7 +79,7 @@ export function WithdrawSilver({ wrapper }: { wrapper: Wrapper Date: Wed, 5 Oct 2022 14:07:36 +0100 Subject: [PATCH 08/10] feat: working asteroid silver withdraw but bad implementation --- client/src/Backend/GameLogic/ContractsAPI.ts | 5 ++++- client/src/Frontend/Views/SendResources.tsx | 1 - client/src/Frontend/Views/TopBar.tsx | 7 ++----- eth/darkforest.toml | 8 ++++---- packages/serde/src/player.ts | 3 ++- packages/types/src/player.ts | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/client/src/Backend/GameLogic/ContractsAPI.ts b/client/src/Backend/GameLogic/ContractsAPI.ts index 033b1553..0cddaea5 100644 --- a/client/src/Backend/GameLogic/ContractsAPI.ts +++ b/client/src/Backend/GameLogic/ContractsAPI.ts @@ -666,7 +666,10 @@ export class ContractsAPI extends EventEmitter { public async getPlayerById(playerId: EthAddress): Promise { const rawPlayer = await this.makeCall(this.contract.players, [playerId]); if (!rawPlayer.isInitialized) return undefined; - const player = decodePlayer(rawPlayer); + // This is horrible and unsustainable. We need some way to get Player + Silver token balance for + // bulk players as well. + const balance = await this.makeCall(this.contract.getSilverBalance, [playerId]); + const player = decodePlayer(rawPlayer, balance.toNumber()); return player; } diff --git a/client/src/Frontend/Views/SendResources.tsx b/client/src/Frontend/Views/SendResources.tsx index a054cd63..694f3083 100644 --- a/client/src/Frontend/Views/SendResources.tsx +++ b/client/src/Frontend/Views/SendResources.tsx @@ -268,7 +268,6 @@ export function SendResources({ const isSendingForces = useEmitterValue(uiManager.isSending$, false); const energySending = uiManager.getForcesSending(locationId); - const silverSending = 100; const artifactSending = uiManager.getArtifactSending(locationId); const spaceshipSending = uiManager.getSpaceshipSending(locationId); diff --git a/client/src/Frontend/Views/TopBar.tsx b/client/src/Frontend/Views/TopBar.tsx index f6434edf..4523bf1e 100644 --- a/client/src/Frontend/Views/TopBar.tsx +++ b/client/src/Frontend/Views/TopBar.tsx @@ -36,12 +36,9 @@ function BoardPlacement({ account }: { account: EthAddress | undefined }) { if (!player.value) { content = n/a; } else { - let formattedScore = uiManager - .getGameManager() - .getContract() - .getSilverBalance(player.value.address); + let formattedScore = 'n/a'; if (player.value.score !== undefined && player.value.score !== null) { - formattedScore = player.value.score.toLocaleString(); + formattedScore = player.value.silver.toLocaleString(); } content = ( diff --git a/eth/darkforest.toml b/eth/darkforest.toml index d1d6cec8..3dc926d7 100644 --- a/eth/darkforest.toml +++ b/eth/darkforest.toml @@ -11,7 +11,7 @@ WORLD_RADIUS_MIN = 53000 ################################## # SNARK keys & Perlin parameters # ################################## -DISABLE_ZK_CHECKS = false +DISABLE_ZK_CHECKS = true PLANETHASH_KEY = 6279 SPACETYPE_KEY = 6280 BIOMEBASE_KEY = 6271 @@ -76,12 +76,12 @@ CAPTURE_ZONES_PER_5000_WORLD_RADIUS = 3 # Game configuration # ###################### MAX_NATURAL_PLANET_LEVEL = 9 -TIME_FACTOR_HUNDREDTHS = 100 # speedup/slowdown game +TIME_FACTOR_HUNDREDTHS = 1500 # speedup/slowdown game PERLIN_THRESHOLD_1 = 14 PERLIN_THRESHOLD_2 = 15 PERLIN_THRESHOLD_3 = 19 -INIT_PERLIN_MIN = 13 -INIT_PERLIN_MAX = 14 +INIT_PERLIN_MIN = 1 +INIT_PERLIN_MAX = 31 SPAWN_RIM_AREA = 0 BIOME_THRESHOLD_1 = 15 BIOME_THRESHOLD_2 = 17 diff --git a/packages/serde/src/player.ts b/packages/serde/src/player.ts index 18ec816f..7a9c1b5a 100644 --- a/packages/serde/src/player.ts +++ b/packages/serde/src/player.ts @@ -13,7 +13,7 @@ export type RawPlayer = Awaited>; * @param rawPlayer result of an ethers.js contract call which returns a raw * `PlayerTypes.Player` struct, typed with typechain. */ -export function decodePlayer(rawPlayer: RawPlayer): Player { +export function decodePlayer(rawPlayer: RawPlayer, silver: number): Player { return { address: address(rawPlayer.player), initTimestamp: rawPlayer.initTimestamp.toNumber(), @@ -26,5 +26,6 @@ export function decodePlayer(rawPlayer: RawPlayer): Player { claimedShips: rawPlayer.claimedShips, finalRank: rawPlayer.finalRank.toNumber(), claimedReward: rawPlayer.claimedReward, + silver: silver, }; } diff --git a/packages/types/src/player.ts b/packages/types/src/player.ts index 2b38db80..3b0a3867 100644 --- a/packages/types/src/player.ts +++ b/packages/types/src/player.ts @@ -18,7 +18,7 @@ export type Player = { lastRevealTimestamp: number; lastClaimTimestamp: number; score: number; - + silver: number; spaceJunk: number; spaceJunkLimit: number; claimedShips: boolean; From 8e399bfa77ef596fc4c91cc268148409f9ea3b1c Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 20:03:23 +0000 Subject: [PATCH 09/10] temp: bulk withdraw in client --- client/src/Backend/GameLogic/GameManager.ts | 65 +++++++++++++++++++++ client/src/Frontend/Views/TopBar.tsx | 10 +++- eth/contracts/facets/DFCoreFacet.sol | 5 +- packages/serde/src/transactions.ts | 13 +++++ packages/types/src/transactions.ts | 8 +++ 5 files changed, 97 insertions(+), 4 deletions(-) diff --git a/client/src/Backend/GameLogic/GameManager.ts b/client/src/Backend/GameLogic/GameManager.ts index a368211d..b1f32c52 100644 --- a/client/src/Backend/GameLogic/GameManager.ts +++ b/client/src/Backend/GameLogic/GameManager.ts @@ -70,6 +70,7 @@ import { Transaction, TxIntent, UnconfirmedActivateArtifact, + UnconfirmedBulkWithdrawSilver, UnconfirmedBuyHat, UnconfirmedCapturePlanet, UnconfirmedClaimReward, @@ -2474,6 +2475,70 @@ class GameManager extends EventEmitter { } } + public async bulkWithdrawSilver( + locationIds: LocationId[], + bypassChecks = false + ): Promise> { + const planets: Planet[] = []; + // Clean Ids + for (const locationId of locationIds) { + if (!bypassChecks) { + const planet = this.entityStore.getPlanetWithId(locationId); + if (!planet) { + continue; + } + if (planet.planetType !== PlanetType.SILVER_MINE) { + continue; + } + if (planet.owner !== this.account) { + continue; + } + if (planet.destroyed) { + continue; + } + planets.push(planet); + } + } + try { + if (!bypassChecks) { + if (!this.account) throw new Error('no account'); + if (this.checkGameHasEnded()) { + throw new Error('game has ended'); + } + } + + if (locationIds.length === 0) throw new Error('no asteriods found to withdraw'); + + const ids = planets.map((p) => `0x${p.locationId}`); + const txIntent: UnconfirmedBulkWithdrawSilver = { + methodName: 'bulkWithdrawSilver', + contract: this.contractsAPI.contract, + args: Promise.resolve([[...ids]]), + locationIds: planets.map((p) => p.locationId), + }; + + console.log(`clean args`, Promise.resolve([[...ids]])); + + // Always await the submitTransaction so we can catch rejections + const tx = await this.contractsAPI.submitTransaction(txIntent, { gasLimit: 15000000 }); + + return tx; + } catch (e) { + this.getNotificationsManager().txInitError('withdrawSilver', e.message); + throw e; + } + } + + public async withdrawFrom20Largest() { + const locationIds = this.getMyPlanets() + .filter((p) => p.planetType === PlanetType.SILVER_MINE) + .sort((a, b) => b.planetLevel - a.planetLevel) + .slice(0, 20) + .map((p) => p.locationId); + console.log(`withdrawing from`, locationIds); + return this.bulkWithdrawSilver(locationIds); + } + /** * We have two locations which planet state can live: on the server, and on the blockchain. We use * the blockchain for the 'physics' of the universe, and the webserver for optional 'add-on' diff --git a/client/src/Frontend/Views/TopBar.tsx b/client/src/Frontend/Views/TopBar.tsx index 4523bf1e..a7384ba0 100644 --- a/client/src/Frontend/Views/TopBar.tsx +++ b/client/src/Frontend/Views/TopBar.tsx @@ -48,7 +48,15 @@ function BoardPlacement({ account }: { account: EthAddress | undefined }) { stockpile: {formattedScore} - Extract all + { + console.log(`extract clicked`); + // uiManager.getGameManager().withdrawFrom20Largest(); + }} + > + Extract all + ); } diff --git a/eth/contracts/facets/DFCoreFacet.sol b/eth/contracts/facets/DFCoreFacet.sol index 3e2d2879..0404d80f 100644 --- a/eth/contracts/facets/DFCoreFacet.sol +++ b/eth/contracts/facets/DFCoreFacet.sol @@ -216,12 +216,11 @@ contract DFCoreFacet is WithStorage { // withdraw silver function bulkWithdrawSilver(uint256[] memory locationIds) public notPaused { - uint256 amount = 0; for (uint256 i = 0; i < locationIds.length; i++) { refreshPlanet(locationIds[i]); - amount += LibPlanet.withdrawSilver(locationIds[i]); + uint256 amount = LibPlanet.withdrawSilver(locationIds[i]); + emit PlanetSilverWithdrawn(msg.sender, locationIds[i], amount); } // Using 0 for locationId, bad pattern - emit PlanetSilverWithdrawn(msg.sender, 0, amount); } } diff --git a/packages/serde/src/transactions.ts b/packages/serde/src/transactions.ts index d1b81f1e..c8cf8d1d 100644 --- a/packages/serde/src/transactions.ts +++ b/packages/serde/src/transactions.ts @@ -2,6 +2,7 @@ import { Transaction, TxIntent, UnconfirmedActivateArtifact, + UnconfirmedBulkWithdrawSilver, UnconfirmedBuyHat, UnconfirmedCapturePlanet, UnconfirmedDeactivateArtifact, @@ -92,6 +93,12 @@ export function isUnconfirmedWithdrawSilver( return txIntent.methodName === 'withdrawSilver'; } +export function isUnconfirmedBulkWithdrawSilver( + txIntent: TxIntent +): txIntent is UnconfirmedBulkWithdrawSilver { + return txIntent.methodName === 'bulkWithdrawSilver'; +} + export function isUnconfirmedGetShips(txIntent: TxIntent): txIntent is UnconfirmedGetShips { return txIntent.methodName === 'giveSpaceShips'; } @@ -178,6 +185,12 @@ export function isUnconfirmedWithdrawSilverTx( return isUnconfirmedWithdrawSilver(tx.intent); } +export function isUnconfirmedBulkWithdrawSilverTx( + tx: Transaction +): tx is Transaction { + return isUnconfirmedBulkWithdrawSilver(tx.intent); +} + export function isUnconfirmedGetShipsTx(tx: Transaction): tx is Transaction { return isUnconfirmedGetShips(tx.intent); } diff --git a/packages/types/src/transactions.ts b/packages/types/src/transactions.ts index 6fcdf8e6..713d4e29 100644 --- a/packages/types/src/transactions.ts +++ b/packages/types/src/transactions.ts @@ -165,6 +165,14 @@ export type UnconfirmedWithdrawSilver = TxIntent & { locationId: LocationId; }; +/** + * @hidden + */ +export type UnconfirmedBulkWithdrawSilver = TxIntent & { + methodName: 'bulkWithdrawSilver'; + locationIds: LocationId[]; +}; + /** * @hidden */ From 609702f0ad4910526e63038e75e1f40ef78b9200 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 20:12:29 +0000 Subject: [PATCH 10/10] working demo of bulk withdraw button broken --- client/src/Backend/GameLogic/GameManager.ts | 1 + eth/darkforest.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/Backend/GameLogic/GameManager.ts b/client/src/Backend/GameLogic/GameManager.ts index b1f32c52..628264ec 100644 --- a/client/src/Backend/GameLogic/GameManager.ts +++ b/client/src/Backend/GameLogic/GameManager.ts @@ -2439,6 +2439,7 @@ class GameManager extends EventEmitter { throw new Error('game has ended'); } const planet = this.entityStore.getPlanetWithId(locationId); + console.log(`basic withdraw planet`, planet); if (!planet) { throw new Error('tried to withdraw silver from an unknown planet'); } diff --git a/eth/darkforest.toml b/eth/darkforest.toml index 3dc926d7..b354e5c6 100644 --- a/eth/darkforest.toml +++ b/eth/darkforest.toml @@ -102,7 +102,7 @@ PLANET_LEVEL_THRESHOLDS = [ 240, 48 ] -PLANET_RARITY = 16384 +PLANET_RARITY = 8192 # How much score silver gives when withdrawing. # Expressed as a percentage integer. # (100 is 100%)