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

v1 #8

Merged
merged 57 commits into from
Nov 19, 2022
Merged

v1 #8

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
1c5d6c9
vercel tab animation
zkSoju Nov 14, 2022
a3de88d
add decimals to mint
zkSoju Nov 14, 2022
b2ce233
useBalance hook
zkSoju Nov 14, 2022
931c1ad
fix padding
zkSoju Nov 14, 2022
37856d4
wip setup l2 sync
zkSoju Nov 14, 2022
47305f2
hardcode lz fees and chainid
zkSoju Nov 14, 2022
458b843
add l1 sync hooks
zkSoju Nov 14, 2022
aab034a
equal size tabs
zkSoju Nov 14, 2022
05ddf8e
cap at 6 decimals
zkSoju Nov 14, 2022
099ab60
Update InteractButton.tsx
zkSoju Nov 14, 2022
85f7fc3
add insufficient balance error handling
zkSoju Nov 14, 2022
ae5bbca
add error handling to swap tab
zkSoju Nov 14, 2022
ff9f70a
dove supremacy
zkSoju Nov 14, 2022
80adc06
hide slider on mouse leave
zkSoju Nov 14, 2022
641a7aa
damm:provide: adapats amount0/1 depending on the other
exp-table Nov 14, 2022
2e9b32e
damm: providing liquidity works
exp-table Nov 14, 2022
0a1ff31
damm:withdraw: halfway
exp-table Nov 14, 2022
c4c40bc
fix types ?
zkSoju Nov 14, 2022
2933814
damm: display correct reserves
exp-table Nov 14, 2022
640027d
damm: withdraw hook + function works
exp-table Nov 14, 2022
6142b1d
amm: supports swapping
exp-table Nov 15, 2022
f711bff
amm: burn vouchers tab
exp-table Nov 15, 2022
695b6ef
useApproveToken hook and use BigNumberish for hooks (#2)
zkSoju Nov 15, 2022
27b8c3e
Update SwapTabContent.tsx
zkSoju Nov 15, 2022
df7a17d
fix stirng | number ambiguity
exp-table Nov 15, 2022
af218a8
Fixed input with balance + renamed useAMM + WIP for correct LP withdr…
exp-table Nov 15, 2022
a3c4c42
damm: withdrawing handles decimals
exp-table Nov 15, 2022
f0d657f
fix swap tokens and approvals
zkSoju Nov 15, 2022
90a7f6d
hide approval if no amount entered
zkSoju Nov 15, 2022
165b292
toast + trigger toast for core hooks
zkSoju Nov 16, 2022
83bfea3
fixed swap inversion
exp-table Nov 16, 2022
c7262b7
voucher toast + watch for new blocks
zkSoju Nov 16, 2022
eec0930
add block explorer redirect for toast
zkSoju Nov 16, 2022
5fb267f
shorten toast msg
zkSoju Nov 16, 2022
ec25c76
polygon amm replacing avax
exp-table Nov 16, 2022
aa6444d
bug executes swap auto
exp-table Nov 16, 2022
ca81759
updated wagmi and rainbowkit version
exp-table Nov 16, 2022
2d27dea
add sdk entities (#3)
zkSoju Nov 16, 2022
0979525
Burn sync check
exp-table Nov 16, 2022
a8835b3
added reserves for amm
exp-table Nov 17, 2022
6f1accd
Merge pull request #5 from exp-table/polygon
exp-table Nov 17, 2022
5e1515f
temporary convert wrapper for vouchers burn
exp-table Nov 17, 2022
6fb51d0
amm: shows available marked tokens on damm
exp-table Nov 17, 2022
4ec5ba7
updated contracts.ts
exp-table Nov 17, 2022
e9c688b
Overhaul state and hooks with SDK types/constants and zustand (#4)
zkSoju Nov 18, 2022
8004e94
clear fields after chain change
zkSoju Nov 18, 2022
26b20c2
don't need to format independent fields
zkSoju Nov 18, 2022
4770990
fix withdraw field
zkSoju Nov 18, 2022
cbfdd6d
Make callback hooks async and trigger toasts (#6)
zkSoju Nov 19, 2022
f3b5a07
view virt reserves from any tab
zkSoju Nov 19, 2022
0dc02f1
Merge branch 'damn-hooks' of https://github.com/exp-table/damm-fronte…
zkSoju Nov 19, 2022
0d7d200
swap: hardcode routing to match swap args
zkSoju Nov 19, 2022
b21e404
restyle
zkSoju Nov 19, 2022
eb7ce80
advance slider
zkSoju Nov 19, 2022
591cbb6
Update globals.css
zkSoju Nov 19, 2022
b820019
move tabs
zkSoju Nov 19, 2022
2d0f445
Single tab (#7)
zkSoju Nov 19, 2022
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
Prev Previous commit
Next Next commit
add sdk entities (#3)
* shorten toast msg

* add sdk/entities
  • Loading branch information
zkSoju committed Nov 16, 2022
commit 2d27dea4245095027be459a00bedeecebaa37201
2 changes: 1 addition & 1 deletion hooks/useAMMSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function ({
});
} else if (isError) {
trigger({
description: "Swap failed",
description: "Transaction failed",
title: "Error",
txid: swapTxData?.hash || "",
type: "error",
Expand Down
2 changes: 1 addition & 1 deletion hooks/useBurnVouchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function ({
});
} else if (isError) {
trigger({
description: `Burn failed`,
description: `Transaction failed`,
title: "Error",
txid: burnTxData?.hash || "",
type: "error",
Expand Down
4 changes: 2 additions & 2 deletions hooks/usedAMMProvide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export default function ({
useEffect(() => {
if (txData && !isError && !isLoading) {
trigger({
description: "You have successfully provided liquidity!",
description: "Liquidity provided",
title: "Success",
txid: provideTxData?.hash || "",
type: "success",
});
} else if (isError) {
trigger({
description: "Something went wrong. Please try again.",
description: "Transaction failed",
title: "Error",
txid: provideTxData?.hash || "",
type: "error",
Expand Down
4 changes: 2 additions & 2 deletions hooks/usedAMMWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export default function ({ amount }: { amount: BigNumberish }): {
useEffect(() => {
if (txData && !isError && !isLoading) {
trigger({
description: "You have successfully withdrawn liquidity!",
description: "Liquidity withdrawn",
title: "Success",
txid: withdrawTxData?.hash || "",
type: "success",
});
} else if (isError) {
trigger({
description: "Something went wrong. Please try again.",
description: "Transaction failed",
title: "Error",
txid: withdrawTxData?.hash || "",
type: "error",
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,28 @@
"@rainbow-me/rainbowkit": "^0.8.0",
"@types/node": "^17.0.21",
"@types/react": "^17.0.39",
"big.js": "^6.2.1",
"decimal.js-light": "^2.5.1",
"eslint-config-next": "^13.0.1",
"ethers": "^5.6.9",
"framer-motion": "^6.2.8",
"graphql": "^16.6.0",
"immer": "^9.0.12",
"jsbi": "^4.3.0",
"next": "^13.0.1",
"next-seo": "^5.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.3.1",
"tailwindcss-radix": "^2.6.1",
"tiny-invariant": "^1.3.1",
"toformat": "^2.0.0",
"typescript": "^4.5.5",
"wagmi": "^0.8.4",
"zustand": "^3.7.0"
},
"devDependencies": {
"@types/big.js": "^6.1.6",
"autoprefixer": "^10.4.4",
"postcss": "^8.4.12",
"prettier": "^2.6.2",
Expand Down
39 changes: 39 additions & 0 deletions sdk/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import JSBI from "jsbi";

export enum SupportedChainId {
MAINNET = 1,
ROPSTEN = 3,
RINKEBY = 4,
GOERLI = 5,
KOVAN = 42,

ARBITRUM_ONE = 42161,
ARBITRUM_RINKEBY = 421611,

OPTIMISM = 10,
OPTIMISM_GOERLI = 420,

POLYGON = 137,
POLYGON_MUMBAI = 80001,

CELO = 42220,
CELO_ALFAJORES = 44787,
}

// exports for external consumption
export type BigintIsh = JSBI | string | number;

export enum TradeType {
EXACT_INPUT,
EXACT_OUTPUT,
}

export enum Rounding {
ROUND_DOWN,
ROUND_HALF_UP,
ROUND_UP,
}

export const MaxUint256 = JSBI.BigInt(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
1 change: 1 addition & 0 deletions sdk/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "toformat";
71 changes: 71 additions & 0 deletions sdk/entities/baseCurrency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import invariant from "tiny-invariant";
import { Currency } from "./currency";
import { Token } from "./token";

/**
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
*/
export abstract class BaseCurrency {
/**
* Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
*/
public abstract readonly isNative: boolean;
/**
* Returns whether the currency is a token that is usable in Uniswap without wrapping
*/
public abstract readonly isToken: boolean;

/**
* The chain ID on which this currency resides
*/
public readonly chainId: number;
/**
* The decimals used in representing currency amounts
*/
public readonly decimals: number;
/**
* The symbol of the currency, i.e. a short textual non-unique identifier
*/
public readonly symbol?: string;
/**
* The name of the currency, i.e. a descriptive textual non-unique identifier
*/
public readonly name?: string;

/**
* Constructs an instance of the base class `BaseCurrency`.
* @param chainId the chain ID on which this currency resides
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
protected constructor(
chainId: number,
decimals: number,
symbol?: string,
name?: string
) {
invariant(Number.isSafeInteger(chainId), "CHAIN_ID");
invariant(
decimals >= 0 && decimals < 255 && Number.isInteger(decimals),
"DECIMALS"
);

this.chainId = chainId;
this.decimals = decimals;
this.symbol = symbol;
this.name = name;
}

/**
* Returns whether this currency is functionally equivalent to the other currency
* @param other the other currency
*/
public abstract equals(other: Currency): boolean;

/**
* Return the wrapped version of this currency that can be used with the Uniswap contracts. Currencies must
* implement this to be used in Uniswap
*/
public abstract get wrapped(): Token;
}
4 changes: 4 additions & 0 deletions sdk/entities/currency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { NativeCurrency } from "./nativeCurrency";
import { Token } from "./token";

export type Currency = NativeCurrency | Token;
131 changes: 131 additions & 0 deletions sdk/entities/fractions/currencyAmount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import invariant from "tiny-invariant";
import JSBI from "jsbi";
import { Currency } from "../currency";
import { Token } from "../token";
import { Fraction } from "./fraction";
import _Big from "big.js";

import toFormat from "toformat";
import { BigintIsh, Rounding, MaxUint256 } from "../../constants";

const Big = toFormat(_Big);

export class CurrencyAmount<T extends Currency> extends Fraction {
public readonly currency: T;
public readonly decimalScale: JSBI;

/**
* Returns a new currency amount instance from the unitless amount of token, i.e. the raw amount
* @param currency the currency in the amount
* @param rawAmount the raw token or ether amount
*/
public static fromRawAmount<T extends Currency>(
currency: T,
rawAmount: BigintIsh
): CurrencyAmount<T> {
return new CurrencyAmount(currency, rawAmount);
}

/**
* Construct a currency amount with a denominator that is not equal to 1
* @param currency the currency
* @param numerator the numerator of the fractional token amount
* @param denominator the denominator of the fractional token amount
*/
public static fromFractionalAmount<T extends Currency>(
currency: T,
numerator: BigintIsh,
denominator: BigintIsh
): CurrencyAmount<T> {
return new CurrencyAmount(currency, numerator, denominator);
}

protected constructor(
currency: T,
numerator: BigintIsh,
denominator?: BigintIsh
) {
super(numerator, denominator);
invariant(JSBI.lessThanOrEqual(this.quotient, MaxUint256), "AMOUNT");
this.currency = currency;
this.decimalScale = JSBI.exponentiate(
JSBI.BigInt(10),
JSBI.BigInt(currency.decimals)
);
}

public add(other: CurrencyAmount<T>): CurrencyAmount<T> {
invariant(this.currency.equals(other.currency), "CURRENCY");
const added = super.add(other);
return CurrencyAmount.fromFractionalAmount(
this.currency,
added.numerator,
added.denominator
);
}

public subtract(other: CurrencyAmount<T>): CurrencyAmount<T> {
invariant(this.currency.equals(other.currency), "CURRENCY");
const subtracted = super.subtract(other);
return CurrencyAmount.fromFractionalAmount(
this.currency,
subtracted.numerator,
subtracted.denominator
);
}

public multiply(other: Fraction | BigintIsh): CurrencyAmount<T> {
const multiplied = super.multiply(other);
return CurrencyAmount.fromFractionalAmount(
this.currency,
multiplied.numerator,
multiplied.denominator
);
}

public divide(other: Fraction | BigintIsh): CurrencyAmount<T> {
const divided = super.divide(other);
return CurrencyAmount.fromFractionalAmount(
this.currency,
divided.numerator,
divided.denominator
);
}

public toSignificant(
significantDigits: number = 6,
format?: object,
rounding: Rounding = Rounding.ROUND_DOWN
): string {
return super
.divide(this.decimalScale)
.toSignificant(significantDigits, format, rounding);
}

public toFixed(
decimalPlaces: number = this.currency.decimals,
format?: object,
rounding: Rounding = Rounding.ROUND_DOWN
): string {
invariant(decimalPlaces <= this.currency.decimals, "DECIMALS");
return super
.divide(this.decimalScale)
.toFixed(decimalPlaces, format, rounding);
}

public toExact(format: object = { groupSeparator: "" }): string {
Big.DP = this.currency.decimals;
return new Big(this.quotient.toString())
.div(this.decimalScale.toString())
.toFormat(format);
}

public get wrapped(): CurrencyAmount<Token> {
if (this.currency.isToken) return this as CurrencyAmount<Token>;
return CurrencyAmount.fromFractionalAmount(
this.currency.wrapped,
this.numerator,
this.denominator
);
}
}
Loading