Skip to content

Commit

Permalink
Added Batcher modifications to handle fee payouts and makring a batch…
Browse files Browse the repository at this point in the history
… as having been given liquidity by the market maker
  • Loading branch information
glottologist committed Sep 18, 2023
1 parent bf30e3c commit 85a1330
Show file tree
Hide file tree
Showing 15 changed files with 5,005 additions and 1,035 deletions.
5 changes: 4 additions & 1 deletion batcher-ui/src/commands/marketholdings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ const fetchMarketHoldingsCmd = (
) => {
return Cmd.run(
async () => {
const vaultArray = await getMarketHoldings(contractAddress, userAddress);
const usrAddress = !userAddress
? 'tz1WfhZiKXiy7zVMxBzMFrdaNJ5nhPM5W2Ef'
: userAddress;
const vaultArray = await getMarketHoldings(contractAddress, usrAddress);
const vaults = new Map(vaultArray.map(i => [i.global.native.name, i]));
console.info('vaults');
console.info(vaults);
Expand Down
44 changes: 34 additions & 10 deletions batcher-ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,12 @@ export const getOrdersBook = async (address: string, userAddress: string) => {
const getDepositAmount = (depositAmount: number, decimals: number) =>
Math.floor(depositAmount) / 10 ** decimals;

const getUserVault = async (userAddress: string, key: string, userVaultId: number) => {
const getUserVault = async (
userAddress: string,
key: string,
userVaultId: number,
holdingsVaultId: number
) => {
if (!userAddress) {
console.info('No user address ');
console.info(userAddress);
Expand All @@ -628,14 +633,22 @@ const getUserVault = async (userAddress: string, key: string, userVaultId: numbe
return userVault;
}

const u = await getBigMapByIdAndKey(userVaultId, key);
const ukey = await getBigMapByIdAndKey(userVaultId, key);
console.info(holdingsVaultId);
console.info(ukey);
const h = await getBigMapByIdAndKey(holdingsVaultId, ukey);
console.info('userVault');
console.info(u);
console.info(userVaultId);
console.info(key);
console.info(h);
if (!h) {
const userVault: UserVault = {
shares: 0,
unclaimed: 0,
};
return userVault;
}
const uv: UserVault = {
shares: 0,
unclaimed: 0,
shares: h.shares,
unclaimed: h.unclaimed,
};
return uv;
};
Expand All @@ -644,14 +657,20 @@ export const getVaultFromBigMap = async (
vaultId: number,
token: any,
userVaultId: number,
userAddress: string
userAddress: string,
holdingsVaultId: number
): Promise<MVault> => {
const b = await getBigMapByIdAndKey(vaultId, token.name);
const rtk = b.native_token;
const scaleAmount = scaleAmountDown(rtk.amount, token.decimals);
const key: string = `{"string":"${token.name}","address":"${userAddress}"}`;
console.info(key);
const userVault = await getUserVault(userAddress, key, userVaultId);
const userVault = await getUserVault(
userAddress,
key,
userVaultId,
holdingsVaultId
);
const globalVault: GlobalVault = {
total_shares: b.total_shares,
native: {
Expand Down Expand Up @@ -679,14 +698,19 @@ export const getMarketHoldings = async (
const storage = await getStorageByAddress(marketMakerAddress);
console.log('Vaults id', storage.vaults);
console.log('MMStorage', storage);
const usrAddress = !userAddress
? 'tz1WfhZiKXiy7zVMxBzMFrdaNJ5nhPM5W2Ef'
: userAddress;
console.log('usrAddress', usrAddress);
return Promise.all(
Object.values(storage.valid_tokens).map(
async token =>
await getVaultFromBigMap(
storage.vaults,
token,
storage.user_holdings,
userAddress
usrAddress,
storage.vault_holdings
)
)
);
Expand Down
Loading

0 comments on commit 85a1330

Please sign in to comment.