Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #2515

Merged
merged 19 commits into from
Dec 15, 2024
Merged

update #2515

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions client/public/resource_addresses/local/resource_addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"STONE": [1, "0x10b3d48c8f0cb6a3d009d3548ab3db455d7fa86407c8869c8525d7f977cfedd"],
"COAL": [2, "0x5dfd0869838aa5a19c54a28717322df1c29c8e0d41a5c6ef126c003f9c29c5d"],
"WOOD": [3, "0x76b8390d8ba5d26423ea5af6ad31b62639ca4a5238e74db1e41dc67b8f57bcd"],
"COPPER": [4, "0x11f4b77a1e0aa2642730a38b4cea40ad4bea984379234bdb60cc41d9ebcd17f"],
"IRONWOOD": [5, "0x453e4a8802c423877beaa3f1ca0fcc3fcfcb543ff92e8b1355381bda4775d48"],
"OBSIDIAN": [6, "0x2c155f2164b68657d0ea8206fcb8c852e91dd5168126437708138d679e31877"],
"GOLD": [7, "0x54a6240d12444353c78a7f64d91e4f8eabc947b760b9369a05b3b154b68b503"],
"SILVER": [8, "0x35e191ed0abcf8270e1b4ae5c7121669ebdc675424dc669f74f8f32a62a61b1"],
"MITHRAL": [9, "0x2925a949eee52af5820a6ba2bdd9aae082ef46082f9a4e1edeb376ce61278a8"],
"ALCHEMICALSILVER": [10, "0x22ae713a2c06f3687f8a50823a16a8e86f49ed1505c43902849fd251e0f5adf"],
"COLDIRON": [11, "0x14e6946dbe9b530bd04d1c347ed695e6f49a163985d8a3410a8a1e1628178a4"],
"DEEPCRYSTAL": [12, "0x30617a0b90f2b04fb1c3e4d5f9e8baca60bde357cdceaa1ea136b1ee7312807"],
"RUBY": [13, "0x47286cdb7554cef18df9eba041164b450fbd1b860825cfa3db2621e4dc7d303"],
"DIAMONDS": [14, "0x18159aba74ae56043f653e5971be4339b0ddc1acdded44d4d1d5373cf7f5534"],
"HARTWOOD": [15, "0x4c7d2035de503300081c41c10dbec1cb2059e6291c7c9fda86610b4b8ecd579"],
"IGNIUM": [16, "0x62d79c2f5f0a7e1485f1948145197dee7f1e35443999daf55016ae39cad7810"],
"TWILIGHTQUARTZ": [17, "0x6cb29e0530292656a0e8ecf73fc04e00c8b68c58ff44a69cca2919cd804c528"],
"TRUEICE": [18, "0x10bc643e2a16bc214c6d3e27972263828e8a137fc634099255b7302eaf38a23"],
"ADAMANTINE": [19, "0x6c4c97ecee863c57c978952ca271065704c3b5ac7010962bdc9c97944c0bd37"],
"SAPPHIRE": [20, "0x70b0dbcbfafd50a1bd7602fd02fc6fcdfc48ece068603a016ffdafb968e2587"],
"ETHEREALSILICA": [21, "0x72fb88593bd78eb19f1514f6a2537b943d23db15ad067e85678f6e9a52345c5"],
"DRAGONHIDE": [22, "0xbeaedcc84e52b9f6197ad5cb5b441fac304afdd036438c208ae3928dd30de0"],
"DEMONHIDE": [28, "0x3f7d97969da364fd2ac0da5b6a877e6c4d4bfade4b3db50561abe02aac3ea48"],
"ANCIENTFRAGMENT": [29, "0x10cb48622578710d600c1d8bf4942035f573d8f1ee95c8a4d3d242139441dbe"],
"DONKEY": [249, "0x1d1542407040c2dce32b3ea35b06c627d4c7c0c6b133972fb903a71fc96156d"],
"KNIGHT": [250, "0x25cebc9ae778dc52ba67b722406586cbabcfd752dda5c3aa541313189617806"],
"CROSSBOWMAN": [251, "0x32ffb922c07155cad08b60a98ce2f660d25b818945d111dc184c7da31cd118f"],
"PALADIN": [252, "0x6910caf9920622e1e0c1ae7b210204268b48146a717e83353a1cf307e42c635"],
"WHEAT": [254, "0x360a3d398a2164b8404a69b2c6f0527c3d6cef480d776b0cf38bb6f531473ab"],
"FISH": [255, "0x613688e2001af02f4181d76587f3e8bb90b516985087b64ec0eaa866ec3ae29"],
"LORDS": [253, "0x4b2162f4b591fbf2052f0600652655675471a850656468dc3ddf57ad4fdbf56"]
}
32 changes: 32 additions & 0 deletions client/public/resource_addresses/mainnet/resource_addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"STONE": [1, "0x439a1c010e3e1bb2d43d43411000893c0042bd88f6c701611a0ea914d426da4"],
"COAL": [2, "0xce635e3f241b0ae78c46a929d84a9101910188f9c4024eaa7559556503c31a"],
"WOOD": [3, "0x40d8907cec0f7ae9c364dfb12485a1314d84c129bf1898d2f3d4b7fcc7d44f4"],
"COPPER": [4, "0x66ed5c928ee027a9419ace1cbea8389885161db5572a7c5c4fef2310e9bf494"],
"IRONWOOD": [5, "0x1720cf6318bff45e62acc588680ae3cd4d5f8465b1d52cb710533c9299b031a"],
"OBSIDIAN": [6, "0x3b6448d09dcd023507376402686261f5d6739455fa02f804907b066e488da66"],
"GOLD": [7, "0xdff9dca192609c4e86ab3be22c7ec1e968876c992d21986f3c542be97fa2f"],
"SILVER": [8, "0x6fe21d2d4a8a05bdb70f09c9250af9870020d5dcc35f410b4a39d6605c3e353"],
"MITHRAL": [9, "0x67ba235c569c23877064b2ac6ebd4d79f32d3c00f5fab8e28a3b5700b957f6"],
"ALCHEMICALSILVER": [10, "0x3956a5301e99522038a2e7dcb9c2a89bf087ffa79310ee0a508b5538efd8ddd"],
"COLDIRON": [11, "0x555d713e59d4ff96b7960447e9bc9e79bfdeab5b0eea74e3df81bce61cfbc77"],
"DEEPCRYSTAL": [12, "0x1d655ac834d38df7921074fc1588411e202b1af83307cbd996983aff52db3a8"],
"RUBY": [13, "0x3d9b66720959d0e7687b898292c10e62e78626f2dba5e1909961a2ce3f86612"],
"DIAMONDS": [14, "0xe03ea8ae385f64754820af5c01c36abf1b8130dd6797d3fd9d430e4114e876"],
"HARTWOOD": [15, "0x5620aa7170cd66dbcbc37d03087bfe4633ffef91d3e4d97b501de906004f79b"],
"IGNIUM": [16, "0x625c1f789b03ebebc7a9322366f38ebad1f693b84b2abd8cb8f5b2748b0cdd5"],
"TWILIGHTQUARTZ": [17, "0x35e24c02409c3cfe8d5646399a62c4d102bb782938d5f5180e92c9c62d3faf7"],
"TRUEICE": [18, "0x4485f5a6e16562e1c761cd348e63256d00389e3ddf4f5d98afe7ab44c57c481"],
"ADAMANTINE": [19, "0x367f838f85a2f5e1580d6f011e4476f581083314cff8721ba3dda9706076eed"],
"SAPPHIRE": [20, "0x2f8dd022568af8f9f718aa37707a9b858529db56910633a160456838b6cbcbc"],
"ETHEREALSILICA": [21, "0x68b6e23cbbd58a644700f55e96c83580921e9f521b6e5175396b53ba7910e7d"],
"DRAGONHIDE": [22, "0x3bf856515bece3c93f5061b7941b8645f817a0acab93c758b8c7b4bc0afa3c6"],
"ANCIENTFRAGMENT": [29, "0x0695b08ecdfdd828c2e6267da62f59e6d7543e690ef56a484df25c8566b332a5"],
"DONKEY": [249, "0x264be95a4a2ace20add68cb321acdccd2f9f8440ee1c7abd85da44ddab01085"],
"KNIGHT": [250, "0xac965f9e67164723c16735a9da8dbc9eb8e43b1bd0323591e87c056badf606"],
"CROSSBOWMAN": [251, "0x67e4ac00a241be06ba6afc11fa2715ec7da0c42c05a67ef6ecfcfeda725aaa8"],
"PALADIN": [252, "0x3bc86299bee061c7c8d7546ccb62b9daf9bffc653b1508facb722c6593874bc"],
"WHEAT": [254, "0x57a3f1ee475e072ce3be41785c0e889b7295d7a0dcc22b992c5b9408dbeb280"],
"FISH": [255, "0x27719173cfe10f1aa38d2aaed0a075b6077290f1e817aa3485d2b828394f4d9"],
"LORDS": [253, "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"]
}
33 changes: 33 additions & 0 deletions client/public/resource_addresses/sepolia/resource_addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"STONE": [1, "0x6158648e6c53488e316a9f681623b9e0359240329a00e5d5f5e82da21453b4c"],
"COAL": [2, "0xeff1980a4f28877118e06aff65d8c972ccc69c7d699975194ae8e83978b116"],
"WOOD": [3, "0x1605f515516e0ea60df3ae92a8204037866c3b27199865133f9f9f35208d298"],
"COPPER": [4, "0x76c0ee15cd5e588f0fa6ffb7c9ce301f96d33cd9f6bf0760ed2e55407130e4"],
"IRONWOOD": [5, "0x9f9cb4a6cb392f2c8526ae6c1f48ddb1eb67598030afdcabe06a48c752b3c6"],
"OBSIDIAN": [6, "0x53d73cddd205f590bf93290fcce62cb1079bd440e7253bef50ce2d890583c09"],
"GOLD": [7, "0x45ee17873d009cb7f8ad88bdd01218b07ceb055a8b22d6a0795028b2aafd8d8"],
"SILVER": [8, "0x56defcf99c674db261f508b584537c760b9001df9a8cb13275afa564f600dbe"],
"MITHRAL": [9, "0x7613ec3c16e4cefc9c33bea2b7e16614a0c4b5237e26cf75f335e0f028da988"],
"ALCHEMICALSILVER": [10, "0x705f42f2a89bf32c504c19c618ca6738747871016bba0b3fc32f3cd73782160"],
"COLDIRON": [11, "0x22bc712f59ceefc7c7521c607eb5f48759ffd906ee6342ee80dad2973f58d8"],
"DEEPCRYSTAL": [12, "0x242f3bcca7f72b5ca034dfe9903bb73024353cec795dca1fd8e2f500d17a733"],
"RUBY": [13, "0x9c473b26f7df7897b517f3c9e1ce8f1f7236b67666983f5ddaf039ca4c46a9"],
"DIAMONDS": [14, "0x78d34a4af3742f6f3377e97dd69f95680bb0f08521ad935428e3b2c3c5ed01e"],
"HARTWOOD": [15, "0x3d3f23f4829b8fe343b00c44c63828f5a81e468fb30eb9504c7c44455cead7b"],
"IGNIUM": [16, "0x204f9596fa6f05c2de88f3a7fe42c0d11fb04cc96128f18fbe112e44f360696"],
"TWILIGHTQUARTZ": [17, "0x1a0f1b62ef495956532db0306d13c92c02604995178d3fc98b84c8b8fb8a18e"],
"TRUEICE": [18, "0x3e089cd9be6c251dae20c64649a770507750f4b4c9e65ebf30bdb63b541605d"],
"ADAMANTINE": [19, "0x55399ca187391f4cc03abb00a04e3b6974bc0d7757ad959ac2804e6c1c468d5"],
"SAPPHIRE": [20, "0x62feb496f301b27bbda2389463d1ca06ef9f22d4208aecef2e85da1e4c90c4f"],
"ETHEREALSILICA": [21, "0x25eb12bb5298a2b14ceb9109086d330810d55c5e9a8c17e60fc956453b30d14"],
"DRAGONHIDE": [22, "0x463ebcc1b9ac911930a471fb9b608e9e7ca07ed81aab66f8889dd45b41c28b2"],
"DEMONHIDE": [28, "0x9613c7e4c04929c616a81f150006bc1a96bb77426851d300ef3dfaf2d0c318"],
"ANCIENTFRAGMENT": [29, "0x403c764fd76f926eec43218f46f79cfb5fe86dfeb1ae76010027697f65733f1"],
"DONKEY": [249, "0x6b6c4437543e46a8a80835fa50643fbd32275d3836396d8cd9c1d7c987f4ea9"],
"KNIGHT": [250, "0x298cba6b152d04fd54195dbae0e74512ff740d14946d2d65f26d0c039feffe2"],
"CROSSBOWMAN": [251, "0x116ce3b8c4a70f61e0131cc8681bc50a5eb35276e7985c07e3a508c2eb25f8f"],
"PALADIN": [252, "0x63f2da6f023bb0f281daa4011beb62ef501207569654e01d9315673471b8839"],
"WHEAT": [254, "0x2cbcad77a7b2bdf87c128f035beef05e3a007c15b2e332b1f1fb04d19ffd1b4"],
"FISH": [255, "0x3da1d29652bf12f64366ca4e9b36ec046cc92f6dc3b4675d956db1c3d742f0f"],
"LORDS": [253, "0x342ad5cc14002c005a5cedcfce2bd3af98d5e7fb79e9bf949b3a91cf145d72e"]
}
11 changes: 9 additions & 2 deletions client/src/dojo/modelManager/MarketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class MarketManager {

public getOutputAmount(inputAmount: number, inputReserve: bigint, outputReserve: bigint, feeRateNum: number) {
// Ensure reserves are not zero and input amount is valid
if (inputReserve < 0n || outputReserve < 0n) {
if (inputReserve <= 0n || outputReserve < 0n) {
throw new Error("Reserves must be >= zero");
}
if (inputAmount < 0) {
Expand Down Expand Up @@ -137,7 +137,12 @@ export class MarketManager {
const market = this.getMarket();
if (!market) return 0;

let outputAmount = this.getOutputAmount(lordsAmount, market.lords_amount, market.resource_amount, feeRateNum);
let outputAmount = 0n;
try {
outputAmount = this.getOutputAmount(lordsAmount, market.lords_amount, market.resource_amount, feeRateNum);
} catch (e) {
console.log(e);
}
return Number(outputAmount);
};

Expand All @@ -157,6 +162,8 @@ export class MarketManager {

const numerator = BigInt(inputReserve) * BigInt(outputReserve);
const denominator = BigInt(outputReserve) - BigInt(resourceAmount);
if (denominator <= 0n) return 0;

const inputAmount = numerator / denominator - BigInt(inputReserve);

// Adjust for fees
Expand Down
2 changes: 1 addition & 1 deletion client/src/dojo/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const addMarketSubscription = async <S extends Schema>(
},
},
components,
30_000,
30_000,
false,
);
};
15 changes: 11 additions & 4 deletions client/src/hooks/context/starknet-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React, { useCallback } from "react";

import { getSeasonAddresses } from "@/ui/utils/utils";
import ControllerConnector from "@cartridge/connector/controller";
import { ColorMode } from "@cartridge/controller";
import { mainnet, sepolia } from "@starknet-react/chains";
import { Connector, StarknetConfig, jsonRpcProvider, voyager } from "@starknet-react/core";
import React, { useCallback } from "react";
import { env } from "../../../env";
import { policies } from "./policies";
import { signingPolicy } from "./signing-policy";

const resourceAddresses = await getSeasonAddresses();

const LORDS = resourceAddresses["LORDS"][1];
const otherResources = Object.entries(resourceAddresses)
.filter(([key]) => key !== "LORDS")
.map(([_, [__, address]]) => address);

const preset: string = "eternum";
const theme: string = "eternum";
const slot: string = env.VITE_PUBLIC_SLOT;
Expand All @@ -28,7 +35,7 @@ const controller =
slot,
preset,
tokens: {
erc20: ["0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"],
erc20: [LORDS, ...otherResources],
},
colorMode,
})
Expand All @@ -40,7 +47,7 @@ const controller =
policies: [...signingPolicy, ...policies, vrfPolicy],
theme,
tokens: {
erc20: ["0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"],
erc20: [LORDS, ...otherResources],
},
colorMode,
});
Expand Down
33 changes: 29 additions & 4 deletions client/src/hooks/helpers/useArmies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
} from "@bibliothecadao/eternum";
import { useEntityQuery } from "@dojoengine/react";
import {
type Component,
type ComponentValue,
type Entity,
Has,
HasValue,
Not,
NotValue,
getComponentValue,
runQuery,
type Component,
type ComponentValue,
type Entity,
} from "@dojoengine/recs";
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { useMemo } from "react";
Expand Down Expand Up @@ -63,6 +63,7 @@ const formatArmies = (
Owner: Component<ClientComponents["Owner"]["schema"]>,
Realm: Component<ClientComponents["Realm"]["schema"]>,
Stamina: Component<ClientComponents["Stamina"]["schema"]>,
Structure: Component<ClientComponents["Structure"]["schema"]>,
): ArmyInfo[] => {
return armies
.map((armyEntityId) => {
Expand Down Expand Up @@ -117,10 +118,15 @@ const formatArmies = (
const realm = entityOwner && getComponentValue(Realm, getEntityIdFromKeys([BigInt(entityOwner.entity_owner_id)]));
const homePosition = realm && getComponentValue(Position, getEntityIdFromKeys([BigInt(realm.entity_id)]));

const structure = getComponentValue(Structure, getEntityIdFromKeys([BigInt(entityOwner.entity_owner_id)]));

const structurePosition =
structure && getComponentValue(Position, getEntityIdFromKeys([BigInt(structure.entity_id)]));

const isMine = (owner?.address || 0n) === ContractAddress(playerAddress);
const isMercenary = owner === undefined;

const isHome = homePosition && position.x === homePosition.x && position.y === homePosition.y;
const isHome = structurePosition && position.x === structurePosition.x && position.y === structurePosition.y;

return {
...army,
Expand Down Expand Up @@ -166,6 +172,7 @@ export const useArmiesByEntityOwner = ({ entity_owner_entity_id }: { entity_owne
Protectee,
EntityName,
Stamina,
Structure,
},
},
account: { account },
Expand All @@ -191,6 +198,7 @@ export const useArmiesByEntityOwner = ({ entity_owner_entity_id }: { entity_owne
Owner,
Realm,
Stamina,
Structure,
);
}, [armies]);

Expand Down Expand Up @@ -221,6 +229,7 @@ export const useArmiesByEntityOwnerWithPositionAndQuantity = ({
Protectee,
EntityName,
Stamina,
Structure,
},
},
account: { account },
Expand Down Expand Up @@ -251,6 +260,7 @@ export const useArmiesByEntityOwnerWithPositionAndQuantity = ({
Owner,
Realm,
Stamina,
Structure,
);
}, [armies]);

Expand All @@ -277,6 +287,7 @@ export const getArmiesByBattleId = () => {
Protectee,
EntityName,
Stamina,
Structure,
},
},
account: { account },
Expand All @@ -301,6 +312,7 @@ export const getArmiesByBattleId = () => {
Owner,
Realm,
Stamina,
Structure,
);
};
return armiesByBattleId;
Expand All @@ -324,6 +336,7 @@ export const useArmyByArmyEntityId = (entityId: ID): ArmyInfo | undefined => {
Protectee,
EntityName,
Stamina,
Structure,
},
},
account: { account },
Expand All @@ -347,6 +360,7 @@ export const useArmyByArmyEntityId = (entityId: ID): ArmyInfo | undefined => {
Owner,
Realm,
Stamina,
Structure,
)[0];
};

Expand All @@ -369,6 +383,7 @@ export const getUserArmyInBattle = (battle_id: ID) => {
Protectee,
EntityName,
Stamina,
Structure,
},
},
} = useDojo();
Expand Down Expand Up @@ -398,6 +413,7 @@ export const getUserArmyInBattle = (battle_id: ID) => {
Owner,
Realm,
Stamina,
Structure,
)[0];
}, [battle_id]);

Expand Down Expand Up @@ -432,6 +448,7 @@ export const useOwnArmiesByPosition = ({
Protectee,
EntityName,
Stamina,
Structure,
},
},
} = useDojo();
Expand Down Expand Up @@ -461,6 +478,7 @@ export const useOwnArmiesByPosition = ({
Owner,
Realm,
Stamina,
Structure,
).filter((army) =>
playerStructures.some((structure) => structure.entity_id === army.entityOwner.entity_owner_id),
);
Expand Down Expand Up @@ -496,6 +514,7 @@ export const useEnemyArmiesByPosition = ({
Protectee,
EntityName,
Stamina,
Structure,
},
},
} = useDojo();
Expand Down Expand Up @@ -524,6 +543,7 @@ export const useEnemyArmiesByPosition = ({
Owner,
Realm,
Stamina,
Structure,
).filter((army) =>
playerStructures.every((structure) => structure.entity_id !== army.entityOwner.entity_owner_id),
);
Expand Down Expand Up @@ -551,6 +571,7 @@ export const getArmyByEntityId = () => {
Protectee,
EntityName,
Stamina,
Structure,
},
},
account: { account },
Expand All @@ -575,6 +596,7 @@ export const getArmyByEntityId = () => {
Owner,
Realm,
Stamina,
Structure,
)[0];
};

Expand All @@ -598,6 +620,7 @@ export const getArmyByEntityId = () => {
Owner,
Realm,
Stamina,
Structure,
)[0];
};

Expand All @@ -623,6 +646,7 @@ export const getArmiesByPosition = () => {
Protectee,
EntityName,
Stamina,
Structure,
},
},
} = useDojo();
Expand All @@ -646,6 +670,7 @@ export const getArmiesByPosition = () => {
Owner,
Realm,
Stamina,
Structure,
);
};

Expand Down
4 changes: 1 addition & 3 deletions client/src/hooks/helpers/useEntities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ export const useEntitiesUtils = () => {
const entityName = getComponentValue(EntityName, getEntityIdFromKeys([BigInt(entityId)]));
const realm = getComponentValue(Realm, getEntityIdFromKeys([BigInt(entityId)]));
const structure = getComponentValue(Structure, getEntityIdFromKeys([BigInt(entityId)]));

if (structure?.category === StructureType[StructureType.Realm] && realm) {
return getRealmName(realm);
}
Expand All @@ -272,9 +271,8 @@ export const useEntitiesUtils = () => {
if (abbr) {
return `${abbr} ${structure.entity_id}`;
}

return `${structure?.category} ${structure?.entity_id}`;
}
return `${structure?.category} ${structure?.entity_id}`;
};

const getAddressName = (address: ContractAddress) => {
Expand Down
Loading
Loading