Skip to content

Commit

Permalink
Use - instead of / for swap pairs i.e. tzBTC-USDT instead of tzBTC/USDT
Browse files Browse the repository at this point in the history
  • Loading branch information
glottologist committed Nov 13, 2023
1 parent 19a6437 commit c4f5bca
Show file tree
Hide file tree
Showing 13 changed files with 575 additions and 85 deletions.
456 changes: 438 additions & 18 deletions batcher-ui/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions batcher-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@taquito/tzip12": "^17.3.0",
"@taquito/tzip16": "^17.3.0",
"@types/react-redux": "^7.1.25",
"@tzkt/sdk-api": "^2.2.1",
"date-fns": "^2.29.3",
"fp-ts": "^2.16.0",
"next": "^13.4.10",
Expand Down
1 change: 0 additions & 1 deletion batcher-ui/src/commands/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
updateVolumes,
batcherTimerId,
updateRemainingTime,
noBatchError,
newError,
} from '@/actions';
import { BatcherStatus, CurrentSwap, SwapNames } from '@/types';
Expand Down
19 changes: 13 additions & 6 deletions batcher-ui/src/components/batcher/SelectPair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { currentSwapSelector } from '@/reducers';
import { useDispatch } from 'react-redux';
import { changePair } from '@/actions';
import Image from 'next/image';
import { getTokensMetadata } from '@/utils/token-manager';
import { getTokensMetadata, getSwapsMetadata } from '@/utils/token-manager';

interface SelectPairProps {
isFrom: boolean;
Expand All @@ -22,6 +22,8 @@ const SelectPair = ({ isFrom }: SelectPairProps) => {
const dispatch = useDispatch();

const [availableTokens, setAvailableTokens] = useState<any[]>([]);
const [availableSwaps, setAvailableSwaps] = useState<any[]>([]);


const displayValue = useCallback(() => {
if (isReverse && isFrom) return swap.to.name;
Expand All @@ -39,17 +41,22 @@ const SelectPair = ({ isFrom }: SelectPairProps) => {
setAvailableTokens(tokens);
}
);
getSwapsMetadata().then(
(swaps: { name: string; to: string; from: string }[]) => {
setAvailableSwaps(swaps);
}
);
}, []);

return (
<Select.Root
value={displayValue()}
onValueChange={value => {
//TODO: change this when we had more pair
const pair =
value === 'tzBTC' ? `tzBTC/${swap.to.name}` : `tzBTC/${value}`;
const reversed =
(!isFrom && value === 'tzBTC') || (isFrom && value !== 'tzBTC');
//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));
}}
>
Expand Down
2 changes: 0 additions & 2 deletions batcher-ui/src/config/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const ghostnet = {
EURL_vault: 'KT1Gy8BPpJdAR6ZwgBaVeXrMW2pyX2NL8LSp',
};



const mainnet = {
batcher: 'KT1CoTu4CXcWoVk69Ukbgwx2iDK7ZA4FMSpJ',
market_maker: 'KT1TNX1YLCmPJN4rbwAUsUAdnqVYrZ5X5YNB',
Expand Down
19 changes: 19 additions & 0 deletions batcher-ui/src/types/contracts/token-manager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { boolean } from "fp-ts";

export type TokenManagerStorage = {
valid_swaps: {
/**
Expand Down Expand Up @@ -34,6 +36,19 @@ export type ValidToken = {
standard: string;
};

export type Swap = {
from: string;
to: string;
};

export type ValidSwap = {
swap: Swap;
oracle_address: string;
oracle_asset_name: string;
oracle_precision: number;
is_disabled_for_deposits: boolean;
};

export type ValidTokenAmount = {
token: ValidToken;
amount: number;
Expand All @@ -43,3 +58,7 @@ export type ValidTokensBigmapItem = {
key: string;
value: ValidToken;
};
export type ValidSwapsBigmapItem = {
key: string;
value: ValidSwap;
};
46 changes: 46 additions & 0 deletions batcher-ui/src/utils/token-manager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import {
TokenManagerStorage,
ValidTokensBigmapItem,
ValidSwapsBigmapItem,
CurrentSwap,
ValidToken,
ValidTokenAmount,
} from '@/types';
import { checkStatus, scaleAmountDown } from '@/utils/utils';
import * as api from '@tzkt/sdk-api';

api.defaults.baseUrl = `${process.env.NEXT_PUBLIC_TZKT_API_URI}`;

export const getTokenManagerStorage = (): Promise<TokenManagerStorage> =>
fetch(
Expand All @@ -20,6 +24,14 @@ const getTokenFromBigmap = (
`${process.env.NEXT_PUBLIC_TZKT_API_URI}/v1/bigmaps/${bigMapId}/keys/${tokenName}`
).then(checkStatus);

const getSwapFromBigmap = (
bigMapId: number,
swapName: string
): Promise<ValidSwapsBigmapItem> =>
fetch(
`${process.env.NEXT_PUBLIC_TZKT_API_URI}/v1/bigmaps/${bigMapId}/keys/${swapName}`
).then(checkStatus);

export const getTokensMetadata = async () => {
const storage = await getTokenManagerStorage();
const validTokens = storage['valid_tokens'];
Expand All @@ -46,6 +58,40 @@ export const getTokensMetadata = async () => {
);
};

export const getLexicographicalPairName = (
to: string,
from: string
): string => {
if (to > from) {
return `${to}/${from}`;
} else {
return `${from}/${to}`;
}
};

export const getSwapsMetadata = async () => {
const storage = await getTokenManagerStorage();
const validSwaps = storage['valid_swaps'];
const names = validSwaps.keys;
const bm = await api.bigMapsGetBigMapById(validSwaps.values);
console.info('DEBUG - validSwaps bm ', bm.value);
return Promise.all(
names.map(async swap => {
const escapedPair = encodeURIComponent(swap);
const t = await getSwapFromBigmap(validSwaps.values, escapedPair);
const swapname = getLexicographicalPairName(
t.value.swap.to,
t.value.swap.from
);
return {
name: swapname,
to: t.value.swap.to,
from: t.value.swap.from,
};
})
);
};

export const parseStandard = (standard: string) => {
if (standard == 'FA2 token') {
return standard as 'FA2 token';
Expand Down
64 changes: 32 additions & 32 deletions batcher/michelson/batcher-ghostnet.tz
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { DIG 2 ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } ;
IF { DIG 2 ; PUSH string "-" ; CONCAT ; DIG 2 ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; DIG 2 ; CONCAT } ;
GET ;
IF_NONE
{ DROP 4 ; PUSH nat 117 ; FAILWITH }
Expand Down Expand Up @@ -337,8 +337,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
GET ;
IF_NONE { PUSH nat 0 } {} ;
GET ;
Expand Down Expand Up @@ -394,8 +394,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DUP 9 ;
Expand Down Expand Up @@ -461,8 +461,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DIG 3 ; DIG 8 ; DROP 3 ; DUP 7 ; DIG 2 } }
Expand Down Expand Up @@ -521,8 +521,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DROP ; DUP 7 ; DIG 2 } } } ;
Expand Down Expand Up @@ -1091,8 +1091,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
GET ;
IF_NONE { PUSH nat 117 ; FAILWITH } {} ;
DUP ;
Expand Down Expand Up @@ -1164,8 +1164,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
GET ;
IF_NONE { PUSH nat 0 } {} ;
GET ;
Expand Down Expand Up @@ -1221,8 +1221,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DUP 6 ;
Expand Down Expand Up @@ -1288,8 +1288,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DIG 3 ; DROP 2 ; DIG 4 ; DIG 2 } }
Expand Down Expand Up @@ -1347,8 +1347,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DROP ; DIG 4 ; DIG 2 } } } ;
Expand All @@ -1370,8 +1370,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
DUP 4 ;
CDR ;
CDR ;
Expand Down Expand Up @@ -1617,8 +1617,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
MEM ;
IF {} { PUSH nat 110 ; FAILWITH } }
{ DIG 4 ; DROP 2 ; PUSH nat 110 ; FAILWITH } } } ;
Expand Down Expand Up @@ -3962,8 +3962,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
GET ;
IF_NONE { PUSH nat 0 } {} ;
GET ;
Expand Down Expand Up @@ -4054,8 +4054,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DIG 4 ; DROP 2 ; DIG 3 ; DIG 2 } }
Expand Down Expand Up @@ -4115,8 +4115,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DROP ; DIG 3 ; DIG 2 } } ;
Expand Down Expand Up @@ -4707,8 +4707,8 @@
DUP 3 ;
COMPARE ;
GT ;
IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
UPDATE ;
UPDATE 1 }
{ DIG 3 ; DROP 2 } ;
Expand Down
8 changes: 4 additions & 4 deletions batcher/michelson/marketmaker-ghostnet.tz
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@
DUP 2 ;
COMPARE ;
GT ;
IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
DUP 7 ;
DUP 2 ;
GET ;
Expand Down Expand Up @@ -702,8 +702,8 @@
DUP 2 ;
COMPARE ;
GT ;
IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT }
{ PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ;
IF { SWAP ; PUSH string "-" ; CONCAT ; SWAP ; CONCAT }
{ PUSH string "-" ; CONCAT ; SWAP ; CONCAT } ;
DUP 7 ;
DUP 2 ;
GET ;
Expand Down
Loading

0 comments on commit c4f5bca

Please sign in to comment.