Skip to content

Commit

Permalink
Merge pull request #80 from PaintSwap/beta
Browse files Browse the repository at this point in the history
Update attackable clans that include ones with the same MMR which don't count in the mmr attacking distance
  • Loading branch information
0xSamWitch authored Aug 30, 2024
2 parents 36187a4 + 15d667c commit 6a24995
Show file tree
Hide file tree
Showing 10 changed files with 5,315 additions and 50 deletions.
Empty file removed .gitmodules
Empty file.
2,208 changes: 2,208 additions & 0 deletions .openzeppelin/unknown-250-beta.json

Large diffs are not rendered by default.

2,794 changes: 2,791 additions & 3 deletions .openzeppelin/unknown-250.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ EggInstantVRFActionStrategy [0x7797fd3904fc399184d2a549dff025210d62e645](https:/
VRFRequestInfo [0x8c3dcf7b09ea620b265d9daab237f29f485f725b](https://ftmscan.com/address/0x8c3dcf7b09ea620b265d9daab237f29f485f725b)

LockedBankVaults [0x65e944795d00cc287bdace77d57571fc4deff3e0](https://ftmscan.com/address/0x65e944795d00cc287bdace77d57571fc4deff3e0)
LockedBankVaultsLibrary [0x31c248c2f2c867dfeaa8f03c50ddabc8f14d00c0](https://ftmscan.com/address/0x31c248c2f2c867dfeaa8f03c50ddabc8f14d00c0)
LockedBankVaultsLibrary [0xd5a209d7fa6bc485b3c4120aaec75b2912cfe4e8](https://ftmscan.com/address/0xd5a209d7fa6bc485b3c4120aaec75b2912cfe4e8)
Territories [0x2cfd3b9f8b595200d6b4b7f667b2a1bcc6d0c170](https://ftmscan.com/address/0x2cfd3b9f8b595200d6b4b7f667b2a1bcc6d0c170)
CombatantsHelper [0x8fedf83c55012acff7115b8fa164095721953c39](https://ftmscan.com/address/0x8fedf83c55012acff7115b8fa164095721953c39)
DecoratorProvider [0xba2f8cff9ea18f3687eb685f0c1bcd509b539963](https://ftmscan.com/address/0xba2f8cff9ea18f3687eb685f0c1bcd509b539963)

PetNFTLibrary [0xf842b81350e8ac973bf7c7f32183cc1e1545e76d](https://ftmscan.com/address/0xf842b81350e8ac973bf7c7f32183cc1e1545e76d)
PetNFTLibrary [0x5a134487df2d8e216e34bf9407bd63cd80e76957](https://ftmscan.com/address/0x5a134487df2d8e216e34bf9407bd63cd80e76957)
PetNFT [0x1681f593ac5cba407c2a190de0ca2beb4a69b5d3](https://ftmscan.com/address/0x1681f593ac5cba407c2a190de0ca2beb4a69b5d3)
PassiveActions [0xa3e3a69edaee89b8dbbd1ca37704cc574cb8e1d4](https://ftmscan.com/address/0xa3e3a69edaee89b8dbbd1ca37704cc574cb8e1d4)

Expand Down Expand Up @@ -131,7 +131,7 @@ GenericInstantVRFActionStrategy [0xc4c92d3987cc0bad3219e696653eb87eddda78c6](htt
EggInstantVRFActionStrategy [0x941369948CC8a4b5b8eFb1F688Eddfe26A736039](https://ftmscan.com/address/0x941369948CC8a4b5b8eFb1F688Eddfe26A736039)
VRFRequestInfo [0x9bcf94e6c067c575dd6a748e45330b4ae4dc0483](https://ftmscan.com/address/0x9bcf94e6c067c575dd6a748e45330b4ae4dc0483)

LockedBankVaultsLibrary [0xdac97bdf170929fbf2140ab63403cae49ada2bbc](https://ftmscan.com/address/0xdac97bdf170929fbf2140ab63403cae49ada2bbc)
LockedBankVaultsLibrary [0x4361e1825cf5c910d1589600df613322e0e704b0](https://ftmscan.com/address/0x4361e1825cf5c910d1589600df613322e0e704b0)
LockedBankVaults [0x40567ad9cd25c56422807ed67f0e66f1825bdb91](https://ftmscan.com/address/0x40567ad9cd25c56422807ed67f0e66f1825bdb91)
Territories [0xf31517db9f0987002f3a0fb4f787dfb9e892f184](https://ftmscan.com/address/0xf31517db9f0987002f3a0fb4f787dfb9e892f184)
CombatantsHelper [0xe8231ac805a88b3c72e9602c2ae14a5d3421bc7c](https://ftmscan.com/address/0xe8231ac805a88b3c72e9602c2ae14a5d3421bc7c)
Expand Down
56 changes: 48 additions & 8 deletions contracts/Clans/LockedBankVaultsLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ library LockedBankVaultsLibrary {
error NothingToClaim();
error NotALockedVaultDefenceItem();
error BlockAttacksCooldown();
error ClanDoesntExist(uint256 clanId);

function initializeMMR(
uint48[] storage _sortedClansByMMR,
Expand Down Expand Up @@ -266,40 +267,79 @@ library LockedBankVaultsLibrary {
(uint clanIndex, uint defendingClanIndex) = _getClanIndicesMemory(sortedClansByMMR, _clanId, _defendingClanId);

if (clanIndex == type(uint256).max) {
revert OutsideMMRRange();
revert ClanDoesntExist(_clanId);
}
if (defendingClanIndex == type(uint256).max) {
revert OutsideMMRRange();
revert ClanDoesntExist(_defendingClanId);
}

return _isWithinRange(sortedClansByMMR, clanIndex, defendingClanIndex, _mmrAttackDistance);
}

// Range is not taken into account for the attacker with the same MMR as surrounding clans.
// So with this array [400, 500, 500, 500, 600] with a range of 1, any attacker at 500 can attack the defender at 400 and 600
// If there are any duplicates at the edge of the range, then the attacker can attack any with that MMR
// So with the above array the 400 MMR clan can attack any 500 MMR clans with a range of 1
function _isWithinRange(
uint48[] memory _sortedClansByMMR,
uint256 _clanIdIndex,
uint256 _defendingClanIdIndex,
uint256 _mmrAttackDistance
) private pure returns (bool) {
// Calculate direct distance
// If they are within range then just return
uint256 directDistance = (_clanIdIndex > _defendingClanIdIndex)
? _clanIdIndex - _defendingClanIdIndex
: _defendingClanIdIndex - _clanIdIndex;

if (_mmrAttackDistance >= directDistance) {
return true;
}

// Have the same MMR
uint256 defenderMMR = _getMMR(_sortedClansByMMR[_defendingClanIdIndex]);
uint256 attackerMMR = _getMMR(_sortedClansByMMR[_clanIdIndex]);
if (defenderMMR == attackerMMR) {
return true;
}

// Find the lower and upper bounds of clans with the same MMR as the attacking clan so that
uint256 attackerLowerBound = _clanIdIndex;
uint256 attackerUpperBound = _clanIdIndex;

while (
attackerLowerBound > 0 &&
_getMMR(_sortedClansByMMR[attackerLowerBound - 1]) == _getMMR(_sortedClansByMMR[_clanIdIndex])
) {
--attackerLowerBound;
}

while (
attackerUpperBound < _sortedClansByMMR.length - 1 &&
_getMMR(_sortedClansByMMR[attackerUpperBound + 1]) == _getMMR(_sortedClansByMMR[_clanIdIndex])
) {
++attackerUpperBound;
}

uint256 boundDistance = _defendingClanIdIndex > _clanIdIndex
? _defendingClanIdIndex - attackerUpperBound
: attackerLowerBound - _defendingClanIdIndex;
if (_mmrAttackDistance >= boundDistance) {
return true;
}

// If outside range, check if MMR is the same as the MMR as that at the edge of the range
int256 rangeEdgeIndex = int256(
_defendingClanIdIndex > _clanIdIndex ? _clanIdIndex + _mmrAttackDistance : _clanIdIndex - _mmrAttackDistance
_defendingClanIdIndex > _clanIdIndex
? attackerUpperBound + _mmrAttackDistance
: attackerLowerBound - _mmrAttackDistance
);

if (rangeEdgeIndex < 0 || rangeEdgeIndex >= int256(_sortedClansByMMR.length)) {
return false;
if (rangeEdgeIndex < 0) {
rangeEdgeIndex = 0;
} else if (rangeEdgeIndex >= int256(_sortedClansByMMR.length)) {
rangeEdgeIndex = int256(_sortedClansByMMR.length - 1);
}

return _getMMR(_sortedClansByMMR[_defendingClanIdIndex]) == _getMMR(_sortedClansByMMR[uint256(rangeEdgeIndex)]);
return defenderMMR == _getMMR(_sortedClansByMMR[uint256(rangeEdgeIndex)]);
}

function blockAttacks(
Expand Down
11 changes: 11 additions & 0 deletions data/abi/LockedBankVaultsLibrary.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
"name": "ClanCombatantsChangeCooldown",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "clanId",
"type": "uint256"
}
],
"name": "ClanDoesntExist",
"type": "error"
},
{
"inputs": [],
"name": "ClanIsBlockingAttacks",
Expand Down
10 changes: 5 additions & 5 deletions scripts/contractAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ if (!isBeta) {
clans = "0x334caa8907bdf49470f7b085380c25431ef96f6d";
wishingWell = "0x0a8d80ce4855666b7d7121d75f2a49aac434a918";
bank = "0xe183a43881eac74808c55bdb2a073929602af4db"; // beacon
playersLibrary = "0x0DAbE42562B15614887C68fe486E9B81CB5DDbE9";
playersLibrary = "0xfd0145ef3585176345cf8f2c63e025049f689073";
playersImplQueueActions = "0xb86cadad55067e24540c6d781d16778f887bf62f";
playersImplProcessActions = "0xe2a9b8c9cee566ae94758510aeaca20476eff97f";
playersImplRewards = "0xfb2aa5afc0de399c76d570ac9bc446940367cfba";
playersImplRewards = "0x5c4e321eacba5499bd3e55b796cc3bea47adc473";
playersImplMisc = "0xddf2bf45e270c1cd624a6ad479974dff24113500";
playersImplMisc1 = "0xc62bdaebc179b3f9cc83ac978db834457aea893b";
players = "0x058ec56aba13f7fee3ae9c9b91b3bb03bc336143";
Expand All @@ -72,14 +72,14 @@ if (!isBeta) {
genericInstantVRFActionStrategy = "0x6270b82049724ff6d7a78b71f2273bba03bfcdfc";
eggInstantVRFActionStrategy = "0x7797fd3904fc399184d2a549dff025210d62e645";
lockedBankVaults = "0x65e944795d00cc287bdace77d57571fc4deff3e0";
lockedBankVaultsLibrary = "0x31c248c2f2c867dfeaa8f03c50ddabc8f14d00c0";
lockedBankVaultsLibrary = "0xd5a209d7fa6bc485b3c4120aaec75b2912cfe4e8";
territories = "0x2cfd3b9f8b595200d6b4b7f667b2a1bcc6d0c170";
combatantsHelper = "0x8fedf83c55012acff7115b8fa164095721953c39";
decoratorProvider = "0xba2f8cff9ea18f3687eb685f0c1bcd509b539963";
oracle = "0x28ade840602d0363a2ab675479f1b590b23b0490";
samWitchVRF = "0xeF5AC0489fc8ABC1085E8D1f5BEE85e74E6D2cC2";
bazaar = "0x6996c519dA4ac7815bEFbd836cf0b78Aa62fdBcE";
petNFTLibrary = "0xf842b81350e8ac973bf7c7f32183cc1e1545e76d";
petNFTLibrary = "0x5a134487df2d8e216e34bf9407bd63cd80e76957";
petNFT = "0x1681f593ac5cba407c2a190de0ca2beb4a69b5d3";
passiveActions = "0xa3e3a69edaee89b8dbbd1ca37704cc574cb8e1d4";
} else {
Expand Down Expand Up @@ -114,7 +114,7 @@ if (!isBeta) {
genericInstantVRFActionStrategy = "0xc4c92d3987cc0bad3219e696653eb87eddda78c6";
eggInstantVRFActionStrategy = "0x941369948CC8a4b5b8eFb1F688Eddfe26A736039";
lockedBankVaults = "0x40567ad9cd25c56422807ed67f0e66f1825bdb91";
lockedBankVaultsLibrary = "0xdac97bdf170929fbf2140ab63403cae49ada2bbc";
lockedBankVaultsLibrary = "0x4361e1825cf5c910d1589600df613322e0e704b0";
territories = "0xf31517db9f0987002f3a0fb4f787dfb9e892f184";
decoratorProvider = "0xea8c4d188eb8d9704bc36931d89ba4f8e935cee2";
combatantsHelper = "0xe8231ac805a88b3c72e9602c2ae14a5d3421bc7c";
Expand Down
21 changes: 10 additions & 11 deletions scripts/deployImpls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main() {
console.log(`Deploying player implementation contracts with the account: ${owner.address} on chain id ${chainId}`);

// Players
const newPlayersLibrary = true;
const newPlayersLibrary = false;
const PlayersLibrary = await ethers.getContractFactory("PlayersLibrary");
let playersLibrary: PlayersLibrary;
if (newPlayersLibrary) {
Expand All @@ -31,26 +31,25 @@ async function main() {
}
console.log(`playersLibrary = "${playersLibrary.address.toLowerCase()}"`);

// const {playersImplQueueActions, playersImplProcessActions, playersImplRewards, playersImplMisc, playersImplMisc1} =
// await deployPlayerImplementations(playersLibrary.address);

const {playersImplQueueActions, playersImplProcessActions, playersImplRewards, playersImplMisc, playersImplMisc1} =
await deployPlayerImplementations(playersLibrary.address);
/*
// Single
const playersImplRewards = await ethers.deployContract("PlayersImplRewards", {
libraries: {PlayersLibrary: playersLibrary.address},
});
await playersImplRewards.deployed();
console.log(`PlayersImplRewards = "${playersImplRewards.address.toLowerCase()}"`);

/*
*/
if (chainId == 250) {
await verifyContracts([
// playersImplQueueActions.address,
// playersImplProcessActions.address,
playersImplQueueActions.address,
playersImplProcessActions.address,
playersImplRewards.address,
// playersImplMisc.address,
// playersImplMisc1.address,
playersImplMisc.address,
playersImplMisc1.address,
]);
} */
}

/* Use these when keeping old implementations
PLAYERS_IMPL_QUEUE_ACTIONS_ADDRESS,
Expand Down
37 changes: 17 additions & 20 deletions scripts/deployUpgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function main() {
estforLibrary = await EstforLibrary.attach(ESTFOR_LIBRARY_ADDRESS);
}
console.log(`estforLibrary = "${estforLibrary.address.toLowerCase()}"`);
/*

// Players
const Players = (await ethers.getContractFactory("Players")).connect(owner);
const players = await upgrades.upgradeProxy(PLAYERS_ADDRESS, Players, {
Expand Down Expand Up @@ -132,7 +132,7 @@ async function main() {
});
await quests.deployed();
console.log(`quests = "${quests.address.toLowerCase()}"`);
*/

// Clan
const Clans = (
await ethers.getContractFactory("Clans", {
Expand All @@ -146,7 +146,7 @@ async function main() {
});
await clans.deployed();
console.log(`clans = "${clans.address.toLowerCase()}"`);
/*

// Bank Registry
const BankRegistry = (await ethers.getContractFactory("BankRegistry")).connect(owner);
const bankRegistry = await upgrades.upgradeProxy(BANK_REGISTRY_ADDRESS, BankRegistry, {
Expand All @@ -155,7 +155,7 @@ async function main() {
});
await bankRegistry.deployed();
console.log(`bankRegistry = "${bankRegistry.address.toLowerCase()}"`);
*/

// World
const newWorldLibrary = false;
const WorldLibrary = await ethers.getContractFactory("WorldLibrary");
Expand All @@ -167,7 +167,7 @@ async function main() {
worldLibrary = await WorldLibrary.attach(WORLD_LIBRARY_ADDRESS);
}
console.log(`worldLibrary = "${worldLibrary.address.toLowerCase()}"`);
/*

const World = (
await ethers.getContractFactory("World", {
libraries: {WorldLibrary: worldLibrary.address},
Expand Down Expand Up @@ -226,7 +226,6 @@ async function main() {
});
await instantActions.deployed();
console.log(`instantActions = "${instantActions.address.toLowerCase()}"`);
*/

// Instant VRF actions
const InstantVRFActions = (await ethers.getContractFactory("InstantVRFActions")).connect(owner);
Expand All @@ -251,7 +250,7 @@ async function main() {
);
await genericInstantVRFActionStrategy.deployed();
console.log(`genericInstantVRFActionStrategy = "${genericInstantVRFActionStrategy.address.toLowerCase()}"`);
/*

const EggInstantVRFActionStrategy = (await ethers.getContractFactory("EggInstantVRFActionStrategy")).connect(owner);
const eggInstantVRFActionStrategy = await upgrades.upgradeProxy(
EGG_INSTANT_VRF_ACTION_STRATEGY_ADDRESS,
Expand All @@ -263,8 +262,8 @@ async function main() {
);
await eggInstantVRFActionStrategy.deployed();
console.log(`eggInstantVRFActionStrategy = "${eggInstantVRFActionStrategy.address.toLowerCase()}"`);
*/
const newPetNFTLibrary = true;

const newPetNFTLibrary = false;
let petNFTLibrary: PetNFTLibrary;
if (newPetNFTLibrary) {
petNFTLibrary = (await ethers.deployContract("PetNFTLibrary")) as PetNFTLibrary;
Expand All @@ -286,7 +285,7 @@ async function main() {
});
await petNFT.deployed();
console.log(`petNFT = "${petNFT.address.toLowerCase()}"`);
/*

const VRFRequestInfo = (await ethers.getContractFactory("VRFRequestInfo")).connect(owner);
const vrfRequestInfo = await upgrades.upgradeProxy(VRF_REQUEST_INFO_ADDRESS, VRFRequestInfo, {
kind: "uups",
Expand Down Expand Up @@ -358,7 +357,6 @@ async function main() {
})) as RoyaltyReceiver;
await royaltyReceiver.deployed();
console.log(`royaltyReceiver = "${royaltyReceiver.address.toLowerCase()}"`);
*/

const PassiveActions = (
await ethers.getContractFactory("PassiveActions", {libraries: {WorldLibrary: worldLibrary.address}})
Expand All @@ -372,31 +370,30 @@ async function main() {
console.log(`passiveActions = "${passiveActions.address.toLowerCase()}"`);

if (network.chainId == 250) {
/*
await verifyContracts([players.address]);
await verifyContracts([players.address]);
await verifyContracts([playerNFT.address]);
await verifyContracts([itemNFT.address]);
await verifyContracts([shop.address]);
await verifyContracts([quests.address]); */
await verifyContracts([quests.address]);
await verifyContracts([clans.address]);
/* await verifyContracts([world.address]);
await verifyContracts([world.address]);
await verifyContracts([worldLibrary.address]);
await verifyContracts([estforLibrary.address]);
await verifyContracts([adminAccess.address]);
await verifyContracts([wishingWell.address]);
await verifyContracts([promotions.address]);
await verifyContracts([instantActions.address]);
await verifyContracts([vrfRequestInfo.address]); */
await verifyContracts([vrfRequestInfo.address]);
await verifyContracts([instantVRFActions.address]);
await verifyContracts([genericInstantVRFActionStrategy.address]);
// await verifyContracts([eggInstantVRFActionStrategy.address]);
await verifyContracts([eggInstantVRFActionStrategy.address]);
await verifyContracts([petNFT.address]);
await verifyContracts([petNFTLibrary.address]);
/* await verifyContracts([LOCKED_BANK_VAULTS_ADDRESS]);
await verifyContracts([LOCKED_BANK_VAULTS_LIBRARY_ADDRESS]);
await verifyContracts([lockedBankVaults.address]);
await verifyContracts([lockedBankVaultsLibrary.address]);
await verifyContracts([combatantsHelper.address]);
await verifyContracts([decoratorProvider.address]);
await verifyContracts([royaltyReceiver.address]); */
await verifyContracts([royaltyReceiver.address]);
await verifyContracts([passiveActions.address]);
}
}
Expand Down
Loading

0 comments on commit 6a24995

Please sign in to comment.