Skip to content

Commit

Permalink
Merge branch 'main' into 2024-09-03-watchlist-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
findolor authored Sep 6, 2024
2 parents 2299902 + 3b6f3a1 commit 62ef525
Show file tree
Hide file tree
Showing 26 changed files with 409 additions and 402 deletions.
10 changes: 10 additions & 0 deletions crates/subgraph/src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub type RainMetaV1 = Bytes;

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct Order {
pub id: Bytes,
pub order_bytes: Bytes,
Expand All @@ -50,6 +51,7 @@ pub struct Order {

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[cynic(graphql_type = "Order")]
#[serde(rename_all = "camelCase")]
#[typeshare]
pub struct OrderAsIO {
pub id: Bytes,
Expand All @@ -59,6 +61,7 @@ pub struct OrderAsIO {

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct Vault {
pub id: Bytes,
pub owner: Bytes,
Expand All @@ -82,6 +85,7 @@ pub struct VaultBalanceChangeVault {
#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
#[cynic(graphql_type = "VaultBalanceChange")]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct VaultBalanceChangeUnwrapped {
pub __typename: String,
pub amount: BigInt,
Expand All @@ -95,6 +99,7 @@ pub struct VaultBalanceChangeUnwrapped {

#[derive(cynic::InlineFragments, Debug, Clone, Serialize)]
#[serde(tag = "__typename", content = "data")]
#[serde(rename_all = "camelCase")]
#[typeshare]
pub enum VaultBalanceChange {
Withdrawal(Withdrawal),
Expand All @@ -106,6 +111,7 @@ pub enum VaultBalanceChange {

#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct Deposit {
pub id: Bytes,
pub __typename: String,
Expand All @@ -120,6 +126,7 @@ pub struct Deposit {

#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct Withdrawal {
pub id: Bytes,
pub __typename: String,
Expand All @@ -134,6 +141,7 @@ pub struct Withdrawal {

#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct TradeVaultBalanceChange {
pub id: Bytes,
pub __typename: String,
Expand All @@ -155,6 +163,7 @@ pub struct TradeEvent {

#[derive(cynic::QueryFragment, Debug, Clone, Serialize)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct Trade {
pub id: Bytes,
pub trade_event: TradeEvent,
Expand All @@ -178,6 +187,7 @@ pub struct Erc20 {

#[derive(cynic::QueryFragment, Debug, Serialize, Clone)]
#[typeshare]
#[serde(rename_all = "camelCase")]
pub struct Transaction {
pub id: Bytes,
pub from: Bytes,
Expand Down
2 changes: 1 addition & 1 deletion tauri-app/src/lib/components/ButtonVaultLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div>
<span class="text-gray-500 dark:text-gray-400">ID</span>
<span class="mb-1 break-all">
{bigintStringToHex(tokenVault.vault_id)}
{bigintStringToHex(tokenVault.vaultId)}
</span>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions tauri-app/src/lib/components/ModalVaultDeposit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
async function executeLedger() {
isSubmitting = true;
try {
await vaultDeposit(BigInt(vault.vault_id), vault.token.id, amount);
await vaultDeposit(BigInt(vault.vaultId), vault.token.id, amount);
} catch (e) {
reportErrorToSentry(e);
}
Expand All @@ -47,7 +47,7 @@
const allowance = await checkAllowance(vault.token.id, $orderbookAddress);
if (allowance.lt(amount)) {
const approveCalldata = (await vaultDepositApproveCalldata(
BigInt(vault.vault_id),
BigInt(vault.vaultId),
vault.token.id,
amount,
allowance.toBigInt(),
Expand All @@ -58,7 +58,7 @@
}
const depositCalldata = (await vaultDepositCalldata(
BigInt(vault.vault_id),
BigInt(vault.vaultId),
vault.token.id,
amount,
)) as Uint8Array;
Expand All @@ -81,7 +81,7 @@
Vault ID
</h5>
<p class="break-all font-normal leading-tight text-gray-700 dark:text-gray-400">
{bigintStringToHex(vault.vault_id)}
{bigintStringToHex(vault.vaultId)}
</p>
</div>

Expand Down
6 changes: 3 additions & 3 deletions tauri-app/src/lib/components/ModalVaultWithdraw.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
async function executeLedger() {
isSubmitting = true;
try {
await vaultWithdraw(BigInt(vault.vault_id), vault.token.id, amount);
await vaultWithdraw(BigInt(vault.vaultId), vault.token.id, amount);
} catch (e) {
reportErrorToSentry(e);
}
Expand All @@ -43,7 +43,7 @@
isSubmitting = true;
try {
const calldata = (await vaultWithdrawCalldata(
BigInt(vault.vault_id),
BigInt(vault.vaultId),
vault.token.id,
amount,
)) as Uint8Array;
Expand Down Expand Up @@ -72,7 +72,7 @@
Vault ID
</h5>
<p class="break-all font-normal leading-tight text-gray-700 dark:text-gray-400">
{bigintStringToHex(vault.vault_id)}
{bigintStringToHex(vault.vaultId)}
</p>
</div>

Expand Down
28 changes: 14 additions & 14 deletions tauri-app/src/lib/components/TakeOrdersTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,42 @@
{formatTimestampSecondsAsLocal(BigInt(item.timestamp))}
</TableBodyCell>
<TableBodyCell tdClass="break-all py-2 min-w-32">
<Hash type={HashType.Wallet} value={item.trade_event.transaction.from} />
<Hash type={HashType.Wallet} value={item.tradeEvent.transaction.from} />
</TableBodyCell>
<TableBodyCell tdClass="break-all py-2 min-w-32">
<Hash type={HashType.Transaction} value={item.trade_event.transaction.id} />
<Hash type={HashType.Transaction} value={item.tradeEvent.transaction.id} />
</TableBodyCell>
<TableBodyCell tdClass="break-all py-2">
{formatUnits(
BigInt(item.input_vault_balance_change.amount),
Number(item.input_vault_balance_change.vault.token.decimals ?? 0),
BigInt(item.inputVaultBalanceChange.amount),
Number(item.inputVaultBalanceChange.vault.token.decimals ?? 0),
)}
{item.input_vault_balance_change.vault.token.symbol}
{item.inputVaultBalanceChange.vault.token.symbol}
</TableBodyCell>
<TableBodyCell tdClass="break-all py-2">
{formatUnits(
BigInt(item.output_vault_balance_change.amount),
Number(item.output_vault_balance_change.vault.token.decimals ?? 0),
BigInt(item.outputVaultBalanceChange.amount),
Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0),
)}
{item.output_vault_balance_change.vault.token.symbol}
{item.outputVaultBalanceChange.vault.token.symbol}
</TableBodyCell>
<TableBodyCell tdClass="break-all py-2" data-testid="io-ratio">
{Math.abs(
Number(
formatUnits(
BigInt(item.input_vault_balance_change.amount),
Number(item.input_vault_balance_change.vault.token.decimals ?? 0),
BigInt(item.inputVaultBalanceChange.amount),
Number(item.inputVaultBalanceChange.vault.token.decimals ?? 0),
),
) /
Number(
formatUnits(
BigInt(item.output_vault_balance_change.amount),
Number(item.output_vault_balance_change.vault.token.decimals ?? 0),
BigInt(item.outputVaultBalanceChange.amount),
Number(item.outputVaultBalanceChange.vault.token.decimals ?? 0),
),
),
)}
{item.input_vault_balance_change.vault.token.symbol}/{item.output_vault_balance_change.vault
.token.symbol}
{item.inputVaultBalanceChange.vault.token.symbol}/{item.outputVaultBalanceChange.vault.token
.symbol}
</TableBodyCell>
</svelte:fragment>
</AppTable>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{query}
timeTransform={(d) => timestampSecondsToUTCTimestamp(BigInt(d.timestamp))}
valueTransform={(d) =>
bigintToFloat(BigInt(d.new_vault_balance), Number(vault.token.decimals ?? 0))}
bigintToFloat(BigInt(d.newVaultBalance), Number(vault.token.decimals ?? 0))}
emptyMessage="No deposits or withdrawals found"
/>
{/if}
38 changes: 19 additions & 19 deletions tauri-app/src/lib/components/charts/VaultBalanceChart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ vi.mock('lightweight-charts', async () => {

const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
{
__typename: 'Withdrawal',
typename: 'Withdrawal',
amount: '1000',
old_vault_balance: '5000',
new_vault_balance: '4000',
oldVaultBalance: '5000',
newVaultBalance: '4000',
vault: {
id: 'vault1',
token: {
Expand All @@ -67,17 +67,17 @@ const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
id: 'tx1',
from: '0xUser1',
timestamp: '0',
block_number: '0',
blockNumber: '0',
},
orderbook: {
id: '0x00',
},
},
{
__typename: 'TradeVaultBalanceChangeUnwrapped',
typename: 'TradeVaultBalanceChangeUnwrapped',
amount: '1500',
old_vault_balance: '4000',
new_vault_balance: '2500',
oldVaultBalance: '4000',
newVaultBalance: '2500',
vault: {
id: 'vault2',
token: {
Expand All @@ -93,17 +93,17 @@ const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
id: 'tx2',
from: '0xUser2',
timestamp: '0',
block_number: '0',
blockNumber: '0',
},
orderbook: {
id: '0x00',
},
},
{
__typename: 'Deposit',
typename: 'Deposit',
amount: '2000',
old_vault_balance: '2500',
new_vault_balance: '4500',
oldVaultBalance: '2500',
newVaultBalance: '4500',
vault: {
id: 'vault3',
token: {
Expand All @@ -119,7 +119,7 @@ const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [
id: 'tx3',
from: '0xUser3',
timestamp: '0',
block_number: '0',
blockNumber: '0',
},
orderbook: {
id: '0x00',
Expand All @@ -129,7 +129,7 @@ const mockVaultBalanceChangeUnwrappeds: VaultBalanceChangeUnwrapped[] = [

const mockVault: Vault = {
id: 'vault1',
vault_id: 'vault1',
vaultId: 'vault1',
token: {
id: 'token1',
address: '0xTokenAddress1',
Expand All @@ -138,9 +138,9 @@ const mockVault: Vault = {
decimals: '18',
},
owner: '0xOwnerAddress',
orders_as_output: [],
orders_as_input: [],
balance_changes: [],
ordersAsInput: [],
ordersAsOutput: [],
balanceChanges: [],
balance: '1000000000000000000',
orderbook: {
id: '0x00',
Expand Down Expand Up @@ -171,15 +171,15 @@ test('renders the chart with correct data and transformations', async () => {
await waitFor(() => {
expect(setDataMock).toHaveBeenCalledWith([
{
value: bigintToFloat(BigInt(mockVaultBalanceChangeUnwrappeds[0].new_vault_balance), 18),
value: bigintToFloat(BigInt(mockVaultBalanceChangeUnwrappeds[0].newVaultBalance), 18),
time: timestampSecondsToUTCTimestamp(BigInt(mockVaultBalanceChangeUnwrappeds[0].timestamp)),
},
{
value: bigintToFloat(BigInt(mockVaultBalanceChangeUnwrappeds[1].new_vault_balance), 18),
value: bigintToFloat(BigInt(mockVaultBalanceChangeUnwrappeds[1].newVaultBalance), 18),
time: timestampSecondsToUTCTimestamp(BigInt(mockVaultBalanceChangeUnwrappeds[1].timestamp)),
},
{
value: bigintToFloat(BigInt(mockVaultBalanceChangeUnwrappeds[2].new_vault_balance), 18),
value: bigintToFloat(BigInt(mockVaultBalanceChangeUnwrappeds[2].newVaultBalance), 18),
time: timestampSecondsToUTCTimestamp(BigInt(mockVaultBalanceChangeUnwrappeds[2].timestamp)),
},
]);
Expand Down
4 changes: 2 additions & 2 deletions tauri-app/src/lib/components/detail/OrderDetail.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<div class="flex gap-x-4 text-3xl font-medium dark:text-white">
<div class="flex gap-x-2">
<span class="font-light">Order</span>
<Hash shorten value={data.order.order_hash} />
<Hash shorten value={data.order.orderHash} />
</div>
<BadgeActive active={data.order.active} large />
</div>
Expand All @@ -61,7 +61,7 @@
<CardProperty>
<svelte:fragment slot="key">Created</svelte:fragment>
<svelte:fragment slot="value">
{formatTimestampSecondsAsLocal(BigInt(data.order.timestamp_added))}
{formatTimestampSecondsAsLocal(BigInt(data.order.timestampAdded))}
</svelte:fragment>
</CardProperty>

Expand Down
2 changes: 1 addition & 1 deletion tauri-app/src/lib/components/detail/OrderDetail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test('shows the correct data when the query returns data', async () => {
expect(screen.getByText('0x1111111111111111111111111111111111111111')).toBeInTheDocument();
expect(screen.getByText('Created')).toBeInTheDocument();
expect(
screen.getByText(formatTimestampSecondsAsLocal(BigInt(mockData.order.timestamp_added))),
screen.getByText(formatTimestampSecondsAsLocal(BigInt(mockData.order.timestampAdded))),
).toBeInTheDocument(); // Adjust this to match your date formatting
});
});
Expand Down
Loading

0 comments on commit 62ef525

Please sign in to comment.