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

Fixed Token Selection #416

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
c289b9a
pipelines: commit to trigger cicd
cyrilevos Apr 21, 2023
6ac33cc
Added michelson files to repo for both mainnet and ghostnet
glottologist Apr 21, 2023
eed92a7
Merge branch 'main' of github.com:marigold-dev/batcher
glottologist Apr 21, 2023
f4c6dc5
Added metadata file
glottologist Apr 21, 2023
b797f98
Fixed issue with wallet disconnecting
glottologist Apr 23, 2023
53d4cb8
Correctly assigned wallet after reload
glottologist Apr 23, 2023
61bdc02
Corrected open and closed holdings
glottologist Apr 23, 2023
55a794d
Merge branch 'release-mainnet' into main
glottologist Apr 23, 2023
e9cc614
Corrected Network type and mainnet token hash
glottologist Apr 24, 2023
b461a1f
Merge branch 'release-mainnet' into main
glottologist Apr 24, 2023
c0ff625
Clear active account on disconnect
glottologist Apr 24, 2023
aa5d41d
Merge branch 'main' of github.com:marigold-dev/batcher
glottologist Apr 24, 2023
ef72a0f
Merge branch 'release-ghostnet' into main
glottologist Apr 24, 2023
00622a3
Merge branch 'release-mainnet' into main
glottologist Apr 24, 2023
f5be65b
Added interim connecting captions for wallet loading
glottologist Apr 24, 2023
8099a86
Merge branch 'main' of github.com:marigold-dev/batcher
glottologist Apr 24, 2023
3420f74
Merge branch 'release-mainnet' into main
glottologist Apr 24, 2023
a0d1aff
Merge branch 'release-ghostnet' into main
glottologist Apr 24, 2023
f5ca683
Fixed issue with button showing connecting
glottologist Apr 24, 2023
8144a3a
Fixed NaN issue in Holdings tab
glottologist Apr 24, 2023
23dce33
Merge branch 'release-ghostnet' into main
glottologist Apr 24, 2023
cd9d079
Merge branch 'release-mainnet' into main
glottologist Apr 24, 2023
5cb41a1
Fixed issue with token balances updating
glottologist Apr 25, 2023
1abd899
Merge branch 'release-ghostnet' into main
glottologist Apr 25, 2023
9e869d3
Merge branch 'release-mainnet' into main
glottologist Apr 25, 2023
e74260f
Check for null user address on token update to reduce errors to the c…
glottologist Apr 25, 2023
d08235d
Filtered out 204 responses from tzkt for volumes
glottologist Apr 25, 2023
b8f48bb
Merge branch 'main' of github.com:marigold-dev/batcher
glottologist Apr 25, 2023
64d974c
Updated About page
glottologist Apr 25, 2023
8ab2d38
Updated About page
glottologist Apr 25, 2023
800f583
Added nix flake for project
glottologist Apr 28, 2023
0e0498f
Added skeleton ts project
glottologist Apr 28, 2023
1343a2f
Added initial skeleton for tg bot
glottologist Apr 28, 2023
5ac163f
Added html formatting to rates messages
glottologist Apr 28, 2023
d5ac749
Added raw operation socker sub
glottologist May 1, 2023
8b05402
Added deposit op to bot
glottologist May 1, 2023
64b18ba
Corrected tick filter
glottologist May 1, 2023
711dc87
Corrected deposit format for TG bot
glottologist May 1, 2023
92c0ac5
Corrected deposit amount for TG bot
glottologist May 1, 2023
872fbba
Corrected deposit amount for TG bot
glottologist May 1, 2023
ef910a4
Scaled amount for TG bot
glottologist May 1, 2023
6539f44
Added sedning of raw big map
glottologist May 1, 2023
acc8609
Corrected pair naming
glottologist May 1, 2023
ee93cac
Corrected scaling from rates message
glottologist May 1, 2023
903ad45
Use all socket messages
glottologist May 1, 2023
3ce0d77
PArse non formated big maps to json
glottologist May 1, 2023
1079617
Filtered user_batch_ordertypes from big_map updates
glottologist May 1, 2023
212cda6
Expanded log message
glottologist May 1, 2023
c82a53c
Added additional logging for bot
glottologist May 1, 2023
a9ebc4f
Changed filters on socket messages
glottologist May 1, 2023
ce4c8eb
Changed filters on socket messages
glottologist May 1, 2023
815473c
Changed filters on socket messages
glottologist May 1, 2023
55921b2
Changed filters on socket messages
glottologist May 1, 2023
e9e9aaf
Filter for transaction that are contract calls
glottologist May 1, 2023
089ccc7
Filter for transaction that are contract calls
glottologist May 1, 2023
1664f59
Log ops received from socket
glottologist May 1, 2023
73eeefe
Corrected filter
glottologist May 2, 2023
70eee41
Added skeleton for batch updates
glottologist May 2, 2023
4fd085e
Added batch update formatter showing volumes
glottologist May 2, 2023
2b75fbd
Assisting compiler
glottologist May 2, 2023
bf4f02f
Corrected json path in batch change
glottologist May 2, 2023
ecfe4ea
Corrected html encoding for batch change
glottologist May 2, 2023
305fea7
Tidy up on logging
glottologist May 2, 2023
eb66a18
Corrected object path for cleared message
glottologist May 2, 2023
07f14e3
Added rate name into batch status message
glottologist May 2, 2023
f705816
Corrected closing message detail
glottologist May 2, 2023
706dd9f
Added filter on messages
glottologist May 9, 2023
c06fd21
remove node_modules folder from repo by rewriting history (squash thi…
cyrilevos May 11, 2023
103ecd3
Merge branch 'release-ghostnet' into main
cyrilevos May 11, 2023
557f615
telegram bot for mainnet version (#333)
cyrilevos May 11, 2023
55a425a
Merge branch 'release-mainnet' into main
cyrilevos May 11, 2023
41a7a5e
Corrected mainnet variables
glottologist May 12, 2023
f3aa20b
Merge branch 'release-ghostnet' into main
glottologist May 12, 2023
9adb8cc
Corrections for batcher notifications bot (mainnet) (#335)
glottologist May 12, 2023
296abab
Removed rate notifications from ghostnet nbot
glottologist May 18, 2023
42f35ea
Merge branch 'release-ghostnet' into main
glottologist May 18, 2023
23470b1
325 bot jit liquidity (#337)
glottologist May 19, 2023
69c80b2
pipelines: use more recent versions of action blocks before deprecation
cyrilevos May 22, 2023
39716fe
Disabled swap button if the batch is closed. Additionally added a wa…
glottologist May 24, 2023
f3e101e
Disabled redeem button if there are no cleared holdings (#341)
glottologist May 24, 2023
b747054
Fix merge issues and tidy up
glottologist May 24, 2023
b080a25
Added batch number in info panel (#342)
glottologist May 24, 2023
01f758e
Added current and last to batch prefix
glottologist May 26, 2023
d9cf127
Merge branch 'release-ghostnet' into main
glottologist May 26, 2023
f81e871
Merge branch 'release-mainnet' into main
glottologist May 26, 2023
6173b67
Changed to use a reduced swap structure (name only) to reduce duplica…
glottologist Jun 8, 2023
8495a5d
344 reduce duplication in contract storage (#351)
glottologist Jun 9, 2023
d895076
Fixed merge issues
glottologist Jun 9, 2023
a71b585
346 only open batches on first trade (#371)
glottologist Jun 20, 2023
80eea91
Moved burn from deposit. Allowed redemption to calculate how much of…
glottologist Jun 20, 2023
d6ccd0a
327-move-fees style suggestion (#373)
aguillon Jun 20, 2023
9cba481
345 remove batches from bigmap imp2 (#377)
glottologist Jul 11, 2023
60cf52f
380 add documentation (#381)
glottologist Jul 13, 2023
fa6bd9a
380 add documentation (#382)
glottologist Jul 13, 2023
d1f67d4
Cancellations (#375)
glottologist Jul 17, 2023
f6cc409
Revive tests (#384)
glottologist Aug 8, 2023
fa5ab1d
w
glottologist Aug 9, 2023
612c9b8
[1
glottologist Aug 9, 2023
e24bb8b
Added market maker doc
glottologist Aug 10, 2023
e737e4b
Added market maker doc
glottologist Aug 10, 2023
31d2879
Added Add Liquidity enpoint
glottologist Aug 14, 2023
ea94b98
Added test for adding liquidity
glottologist Aug 14, 2023
ee3d7cf
Add liquidity to market maker and test
glottologist Aug 22, 2023
8e2097b
Added add/remove liquidity and claim rewards tests. Added view for g…
glottologist Aug 30, 2023
43ebce3
Started splitting market maker off into own contract
glottologist Sep 7, 2023
7528a6a
Seperated out tests
glottologist Sep 7, 2023
5a60310
Merged makefile
glottologist Sep 7, 2023
7d5f7c3
Split out mm contract from Batcher and pulled out common code into sh…
glottologist Sep 7, 2023
3480734
Amended tests to work with new split contracts
glottologist Sep 8, 2023
4a8ceda
Populated ghostnet storage for marketmaker
glottologist Sep 12, 2023
71d5b8f
Added get market holdings mechanism
glottologist Sep 12, 2023
4686b2a
Added user holdings display and buttons for MM
glottologist Sep 13, 2023
bf30e3c
Added contract calls
glottologist Sep 14, 2023
85a1330
Added Batcher modifications to handle fee payouts and makring a batch…
glottologist Sep 18, 2023
ec93d7b
Added placeholders for market vault operations against batcher
glottologist Sep 18, 2023
620fe4c
Added rebalancing up to amount exchange
glottologist Sep 21, 2023
f73d70c
Added redemption of holdings
glottologist Sep 21, 2023
248f03d
Added operator and deposit ops to utils
glottologist Sep 22, 2023
655474f
Added approve, deposit and revoke operations to the market maker
glottologist Sep 25, 2023
e7a5f3e
Added liquidity injection for market maker
glottologist Sep 26, 2023
5d7c487
Added additional tokens
glottologist Oct 5, 2023
a9666bd
Set up new pairs in ghostnet storage
glottologist Oct 5, 2023
fe06661
Added new tokens and pairs into market maker
glottologist Oct 5, 2023
e16af2b
Added new ghostnet batcher contract to mm storage
glottologist Oct 5, 2023
d48eb01
Added new ghostnet mm address to batcher ghostnet storage
glottologist Oct 5, 2023
5696905
Added new ghhostnet addresses to the config
glottologist Oct 5, 2023
d6c815f
Fix issue cmm (#407)
quentin-burg Oct 5, 2023
c77cc8a
Added redeem by batch
glottologist Oct 5, 2023
83f7a11
Fix CMM UI (#408)
quentin-burg Oct 5, 2023
9c8c05f
Merge branch 'release-ghostnet-beta' into 389-community-market-maker-1
glottologist Oct 5, 2023
ef68ee8
Fixed merge issues, rebuilt to deploy
glottologist Oct 6, 2023
2c6cd69
Added measure for mm contract
glottologist Oct 6, 2023
2284c2b
Skeleton token manager
glottologist Oct 10, 2023
ecb47a7
Added vault contract and moved michelson output to own folder
glottologist Oct 13, 2023
b1959ca
Test types
glottologist Oct 17, 2023
895f627
Adjusted Batcher to support calling the token manager
glottologist Oct 17, 2023
c04dd01
Removed unused code in Batcher
glottologist Oct 17, 2023
2f6ea0c
Added fee map insteand of single market maker address
glottologist Oct 17, 2023
97dc418
Added liquidity injection to Vault
glottologist Oct 17, 2023
33d87c2
Added reward distribution in vaults
glottologist Oct 23, 2023
5467257
Amended clean mechanism in makefule
glottologist Oct 23, 2023
213dc1b
Added liquidity injection request into market maker
glottologist Oct 24, 2023
a763aed
Fixed getting native tokens view call from vaults
glottologist Oct 24, 2023
bdedb9c
Fixed bug in upsert methods
glottologist Oct 24, 2023
4a4c782
Added a build step to build all contracts
glottologist Oct 24, 2023
08834cc
Fixed issue on makefile and tzbtc vault storage
glottologist Oct 24, 2023
55ace34
Added new vault endpoint call into Batcher for adding rewards to the …
glottologist Oct 24, 2023
06a7181
Added vault balance requests after add or remove liquidity and liquid…
glottologist Oct 25, 2023
f571a33
Removed balance assertion from deposit for testing
glottologist Oct 25, 2023
01be131
Removed foreign token assertions for testing
glottologist Oct 26, 2023
a60de19
Fixed silly token standard parsing error
glottologist Oct 26, 2023
9bd5d79
Fixed silly token standard parsing error
glottologist Oct 26, 2023
a2aa960
Fixed silly token standard parsing error
glottologist Oct 26, 2023
49de0db
Compile all for ghostnet
glottologist Oct 26, 2023
e917111
Moved assert balances into its own entry
glottologist Oct 28, 2023
6b4c980
Added clause to test batch for liquidity
glottologist Oct 28, 2023
a4103f6
Removed todo clause
glottologist Oct 28, 2023
a9c1535
Added debug view to vault to test token balance endpoints
glottologist Oct 30, 2023
fa03d3d
Adjusted callback types
glottologist Oct 30, 2023
ff06943
Adjusted vault process response
glottologist Oct 30, 2023
f1a85c8
Adjusted vault process response
glottologist Oct 30, 2023
690531f
Adjusted getBalance endpoint call opt
glottologist Oct 30, 2023
5600f79
Adjusted type of getBlanace response for callback
glottologist Oct 30, 2023
6f43ef4
:wrench: rewrite config due to new contracts architecture
Oct 17, 2023
af5b877
:recycle: redirect tokens management to token manager contract
Oct 17, 2023
1980265
:recycle: refactor components && fetch token vault informations
Oct 18, 2023
2f2042f
Updated ghostnet contracts in config
glottologist Oct 31, 2023
385eaed
Updated contract error codes
glottologist Oct 31, 2023
821cd20
Changed UI to support new contract structure
glottologist Nov 6, 2023
28fc3a5
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 7, 2023
7e60c32
Adjusted tick script to tick more pairs and also tick the market maker
glottologist Nov 8, 2023
3bdbdd2
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 8, 2023
e69d2fd
Amended tick operation to pull rates for all pairs
glottologist Nov 10, 2023
886cfc1
Adjusted tick script to call new unified tick endpoint and re-pointed…
glottologist Nov 10, 2023
63f315d
Repointed UI to new ghostnet contract
glottologist Nov 10, 2023
33ec6e0
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 10, 2023
590bae7
new batcher contract hash for docker file
glottologist Nov 13, 2023
a1e350a
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 13, 2023
ac2dcb9
Added get_vaults view to marketmaker and removed no_batch error on UI
glottologist Nov 13, 2023
19a6437
Repointed to new marketmaker
glottologist Nov 13, 2023
c4f5bca
Use - instead of / for swap pairs i.e. tzBTC-USDT instead of tzBTC/USDT
glottologist Nov 13, 2023
f08ca8f
Use - instead of / for swap pairs i.e. tzBTC-USDT instead of tzBTC/US…
glottologist Nov 13, 2023
115a8e3
Repointed to new marketmaker
glottologist Nov 13, 2023
8210e42
corrected tick script calls
glottologist Nov 13, 2023
267b999
corrected tick script calls
glottologist Nov 13, 2023
dcd751a
corrected tick script calls
glottologist Nov 13, 2023
d1a0c5d
corrected tick script calls
glottologist Nov 13, 2023
8484fec
corrected tick script calls
glottologist Nov 13, 2023
2c100b0
Changed ghostnet oracles
glottologist Nov 13, 2023
4d7826f
Added tokens list to exchange state and fixed Volume display
glottologist Nov 14, 2023
0e7397b
Fixed holdings display
glottologist Nov 14, 2023
8f78c0d
Fixed holdings display
glottologist Nov 14, 2023
46edd4b
Fixed linting and type issues
glottologist Nov 14, 2023
5bda817
Fixed linting and type issues
glottologist Nov 14, 2023
76a7f58
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 14, 2023
0f1b5f6
Added swaps to state and fixed token selection
glottologist Nov 16, 2023
0421cc6
Merge branch '410-further-split-out-batcher-and-mm-contracts-to-avoid…
glottologist Nov 16, 2023
a4d69bd
Merge branch 'release-ghostnet-beta' into 410-further-split-out-batch…
glottologist Nov 16, 2023
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
23 changes: 21 additions & 2 deletions batcher-ui/src/actions/exchange.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { BatcherStatus, CurrentSwap, PriceStrategy, Token } from '@/types';
import {
BatcherStatus,
CurrentSwap,
PriceStrategy,
Token,
ValidSwap,
} from '@/types';

export const updatePriceStrategy = (priceStrategy: PriceStrategy) =>
({
Expand Down Expand Up @@ -119,6 +125,17 @@ export const getTokens = () =>
type: 'GET_TOKENS',
}) as const;

export const updateSwaps = (swaps: Map<string, ValidSwap>) =>
({
type: 'UPDATE_SWAPS',
payload: { swaps },
}) as const;

export const getSwaps = () =>
({
type: 'GET_SWAPS',
}) as const;

export type ExchangeActions =
| ReturnType<typeof updatePriceStrategy>
| ReturnType<typeof reverseSwap>
Expand All @@ -138,4 +155,6 @@ export type ExchangeActions =
| ReturnType<typeof getVolumes>
| ReturnType<typeof updateVolumes>
| ReturnType<typeof getTokens>
| ReturnType<typeof updateTokens>;
| ReturnType<typeof updateTokens>
| ReturnType<typeof getSwaps>
| ReturnType<typeof updateSwaps>;
36 changes: 34 additions & 2 deletions batcher-ui/src/commands/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getVolumes,
getTimeDifferenceInMs,
getTokens,
getSwaps,
} from '@/utils/utils';
import { getPairsInformation } from '@/utils/token-manager';
import {
Expand All @@ -19,8 +20,15 @@ import {
updateRemainingTime,
newError,
updateTokens,
updateSwaps,
} from '@/actions';
import { BatcherStatus, CurrentSwap, SwapNames, Token } from '@/types';
import {
BatcherStatus,
CurrentSwap,
SwapNames,
Token,
ValidSwap,
} from '@/types';

const fetchPairInfosCmd = (pair: string) =>
Cmd.run(
Expand Down Expand Up @@ -111,7 +119,10 @@ const fetchTokensCmd = () => {
return Cmd.run(
async () => {
const tokens = await getTokens();
const mapped: Map<string, Token> = ((tokens as unknown) as Map<string, Token>);
const mapped: Map<string, Token> = tokens as unknown as Map<
string,
Token
>;
console.info('Mapped tokens', mapped);
return mapped;
},
Expand All @@ -121,6 +132,26 @@ const fetchTokensCmd = () => {
}
);
};

const fetchSwapsCmd = () => {
return Cmd.run(
async () => {
const swaps = await getSwaps();
const mapped: Map<string, ValidSwap> = swaps as unknown as Map<
string,
ValidSwap
>;
console.info('Mapped swaps', mapped);
return mapped;
},
{
successActionCreator: updateSwaps,
failActionCreator: (e: string) => newError(e),
}
);
};


export {
fetchPairInfosCmd,
fetchCurrentBatchNumberCmd,
Expand All @@ -129,4 +160,5 @@ export {
fetchOraclePriceCmd,
fetchVolumesCmd,
fetchTokensCmd,
fetchSwapsCmd,
};
63 changes: 52 additions & 11 deletions batcher-ui/src/components/batcher/SelectPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import {
faChevronUp,
} from '@fortawesome/free-solid-svg-icons';
import { useSelector } from 'react-redux';
import { currentSwapSelector } from '@/reducers';
import { currentSwapSelector, tokensSelector, swapsSelector } from '@/reducers';
import { useDispatch } from 'react-redux';
import { changePair } from '@/actions';
import { changePair, newError } from '@/actions';
import { ValidSwap } from '@/types';
import Image from 'next/image';
import { getTokensMetadata } from '@/utils/token-manager';
import {
getLexicographicalPairName,
getTokensMetadata,
} from '@/utils/token-manager';
import { ensureMapTypeOnSwaps } from '@/utils/utils';

interface SelectPairProps {
isFrom: boolean;
Expand All @@ -21,8 +26,10 @@ const SelectPair = ({ isFrom }: SelectPairProps) => {
const { swap, isReverse } = useSelector(currentSwapSelector);
const dispatch = useDispatch();

//const tokens = useSelector(tokensSelector);
const tokens = useSelector(tokensSelector);
const swaps = useSelector(swapsSelector);
const [availableTokens, setAvailableTokens] = useState<any[]>([]);
const [availableSwaps, setAvailableSwaps] = useState<string[]>([]);

const displayValue = useCallback(() => {
if (isReverse && isFrom) return swap.to.name;
Expand All @@ -38,20 +45,54 @@ const SelectPair = ({ isFrom }: SelectPairProps) => {
tokens: { name: string; address: string; icon: string | undefined }[]
) => {
setAvailableTokens(tokens);
console.info('swaps - before', swaps);
const swapsAsMap: Map<string, ValidSwap> = ensureMapTypeOnSwaps(swaps);
console.info('swaps - dispatch', swapsAsMap);
console.info('swaps keys - dispatch', swapsAsMap.keys());
const swps: string[] = Array.from(swapsAsMap.keys());
console.info('swps - dispatch', swps);
setAvailableSwaps(swps);
}
);
}, []);
}, [dispatch, tokens, swaps]);

const isValidPair = (pair: string) => availableSwaps.includes(pair);

const invalidSwap = (pairName: string) => {
dispatch(
newError(
pairName +
' is not a valid pair. Only ' +
availableSwaps.join() +
'are supported.'
)
);
};

const is_reversed = (pair: string, to: string, from: string) => {
const swap = ensureMapTypeOnSwaps(swaps).get(pair);
return to === swap?.swap.to && from === swap?.swap.from;
};

return (
<Select.Root
value={displayValue()}
onValueChange={value => {
//const pair = isFrom ? `${value}-${swap.to.name}` : `${swap.from.name}-${value}`;
//const availableSwap = availableSwaps[pair];
// const reversed = (!isFrom && value === ${swap.from.name}) || (isFrom && value === ${swap.to.name});
const pair = 'tzBTC-USDT';
const reversed = false;
dispatch(changePair(pair, reversed));
console.info('availableSwaps', availableSwaps);
console.info('swaps', swaps);
console.info('swap', swap);
console.info('value', value);
console.info('isFrom', isFrom);
const from = isFrom ? `${swap.to.name}` : `${value}`;
const to = isFrom ? `${value}` : `${swap.from.token.name}`;
const pairName = getLexicographicalPairName(to, from);
const is_valid = isValidPair(pairName);
if (is_valid) {
const reversed = is_reversed(pairName, to, from);
dispatch(changePair(pairName, reversed));
} else {
invalidSwap(pairName);
}
}}
>
<Select.Trigger className="flex items-center text-dark w-[200px] justify-center rounded px-2 mr-1 text-base gap-2 bg-white hover:bg-hovergray outline-none">
Expand Down
7 changes: 3 additions & 4 deletions batcher-ui/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import BatcherInfo from '@/components/batcher/BatcherInfo';
import PriceStrategy from '@/components/batcher/PriceStrategy';

import { useSelector, useDispatch } from 'react-redux';
import {
currentPairSelector,
userAddressSelector,
} from '@/reducers';
import { currentPairSelector, userAddressSelector } from '@/reducers';
import {
getTokens,
getSwaps,
fetchUserBalances,
batcherUnsetup,
getPairsInfos,
Expand Down Expand Up @@ -38,6 +36,7 @@ const Swap = () => {

useEffect(() => {
dispatch(getTokens());
dispatch(getSwaps());
}, [dispatch]);

return (
Expand Down
9 changes: 9 additions & 0 deletions batcher-ui/src/reducers/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ExchangeState,
PriceStrategy,
Token,
ValidSwap,
} from '@/types';
import {
fetchBatcherStatusCmd,
Expand All @@ -21,6 +22,7 @@ import {
fetchOraclePriceCmd,
setupBatcherCmd,
fetchTokensCmd,
fetchSwapsCmd,
} from '@/commands/exchange';
import { getTimeDifference } from 'src/utils/utils';

Expand Down Expand Up @@ -61,6 +63,7 @@ const initialState: ExchangeState = {
batchNumber: 0,
oraclePrice: 0,
tokens: new Map<string, Token>(),
swaps: new Map<string, ValidSwap>(),
volumes: {
sell: Object.keys(PriceStrategy).reduce(
(acc, k) => ({ ...acc, [k]: 0 }),
Expand Down Expand Up @@ -205,6 +208,12 @@ const exchangeReducer = (
return { ...state, tokens: action.payload.tokens };
case 'GET_TOKENS':
return loop(state, fetchTokensCmd());
case 'UPDATE_SWAPS':
console.info('swaps', action.payload.swaps);
console.info('state', state);
return { ...state, swaps: action.payload.swaps };
case 'GET_SWAPS':
return loop(state, fetchSwapsCmd());
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions batcher-ui/src/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const oraclePriceSelector = (state: AppState) =>
state.exchange.oraclePrice;

export const tokensSelector = (state: AppState) => state.exchange.tokens;
export const swapsSelector = (state: AppState) => state.exchange.swaps;

export const volumesSelector = (state: AppState) => state.exchange.volumes;

Expand Down
3 changes: 2 additions & 1 deletion batcher-ui/src/types/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
PriceStrategy,
SwapNames,
} from '@/types/contracts/batcher';
import { ValidTokenAmount } from './contracts/token-manager';
import { ValidTokenAmount, ValidSwap } from './contracts/token-manager';

export type Token = {
address: string | undefined;
Expand Down Expand Up @@ -45,6 +45,7 @@ export type ExchangeState = {
oraclePrice: number;
volumes: VolumesState;
tokens: Map<string, Token>;
swaps: Map<string, ValidSwap>;
};

export type WalletState = {
Expand Down
27 changes: 26 additions & 1 deletion batcher-ui/src/utils/token-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const getLexicographicalPairName = (
to: string,
from: string
): string => {
if (to > from) {
const comp = to.localeCompare(from);
if (comp < 0)
return `${to}-${from}`;
} else {
return `${from}-${to}`;
Expand Down Expand Up @@ -197,3 +198,27 @@ export const getTokensFromStorage = async () => {
})
);
};

export const getSwapsFromStorage = async () => {
const storage = await getTokenManagerStorage();
const validSwaps = storage['valid_swaps'];
const names = validSwaps.keys;
return Promise.all(
names.map(async swap => {
const t = await getSwapFromBigmap(validSwaps.values, swap);

const swp = {
from: t.value.swap.from,
to: t.value.swap.to,
};

return {
swap: swp,
oracle_address: t.value.oracle_address,
oracle_asset_name: t.value.oracle_asset_name,
oracle_precision: t.value.oracle_precision,
is_disabled_for_deposits: t.value.is_disabled_for_deposits,
};
})
);
}
40 changes: 38 additions & 2 deletions batcher-ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import {
RatesCurrentBigmap,
Token,
ValidToken,
ValidSwap,
ValidTokenAmount,
} from '@/types';
import {
getTokenManagerStorage,
getTokensFromStorage,
getSwapsFromStorage,
getLexicographicalPairName,
} from '@/utils/token-manager';
import { NetworkType } from '@airgap/beacon-sdk';
import { getByKey } from '@/utils/local-storage';
Expand All @@ -38,6 +41,22 @@ export const getTokens = async () => {
};
};

export const getSwaps = async () => {
const swaps = await getSwapsFromStorage();
console.info('getSwaps swaps', swaps);
const swapsMap = new Map(
swaps.map((value, index) => [
getLexicographicalPairName(value.swap.to, value.swap.from),
value,
])<<<<<<< 410-further-split-out-batcher-and-mm-contracts-to-avoid-size-constraint
);
console.info('getSwaps swapMap', swapsMap);

return {
swaps: swapsMap,
};
};

export const scaleAmountDown = (amount: number, decimals: number) => {
const scale = 10 ** -decimals;
return amount * scale;
Expand Down Expand Up @@ -383,6 +402,23 @@ export const ensureMapTypeOnTokens = (
}
};

export const ensureMapTypeOnSwaps = (
swaps: Map<string, ValidSwap>
): Map<string, ValidSwap> => {
const typeOfSwaps = typeof swaps;
console.info('swaps type', typeOfSwaps);
if (swaps instanceof Map) {
return swaps;
} else {
let swps: Map<string, ValidSwap> = new Map<string, ValidSwap>();
Object.values(swaps).forEach(v => {
console.info('v', v);
swps = v as Map<string, ValidSwap>;
});
return swps;
}
};

export const getTimeDifferenceInMs = (
status: BatcherStatus,
startTime: string | null
Expand Down Expand Up @@ -484,8 +520,8 @@ const findTokensForBatch = (batch: BatchBigmap, toks: Map<string, Token>) => {
const buyToken = tokens.get(pair.string_0);
const sellToken = tokens.get(pair.string_1);
const tkns = {
to: { name: buyToken?.name || "", decimals: buyToken?.decimals || 0 },
from: { name: sellToken?.name || "", decimals: sellToken?.decimals || 0 },
to: { name: buyToken?.name || '', decimals: buyToken?.decimals || 0 },
from: { name: sellToken?.name || '', decimals: sellToken?.decimals || 0 },
};
return tkns;
};
Expand Down
Loading