-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/WT-1585-InjectPassport
- Loading branch information
Showing
15 changed files
with
235 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/internal/dex/sdk-sample-app/src/components/FeeBreakdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Fee } from "@imtbl/dex-sdk" | ||
import { ethers } from "ethers" | ||
|
||
type mapping = { | ||
[address: string]: string; | ||
}; | ||
|
||
export const FeeBreakdown = ({fees, addressMap}: {fees: Fee[], addressMap: mapping}) => { | ||
return (<> | ||
<h2 className="mb-1 mt-4 text-lg font-extrabold leading-none tracking-tight text-gray-900 md:text-lg lg:text-lg dark:text-white">Fee Breakdown:</h2> | ||
{fees.map((fee, index) => { | ||
return (<div key={index}> | ||
<div>Fee Recipient: {fee.feeRecipient}</div> | ||
<div>Fee Basis Points: {fee.feeBasisPoints}</div> | ||
<div>Fee Amount: {ethers.utils.formatEther(fee.amount.value.toString())} {addressMap[fee.amount.token.address]}</div> | ||
</div>) | ||
})} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/internal/dex/sdk/src/constants/chains/immutable-testnet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export const IMMUTABLE_TESTNET_RPC_URL = 'https://rpc.testnet.immutable.com'; | ||
export const IMMUTABLE_TESTNET_CHAIN_ID = 13372; | ||
export const IMMUTABLE_TESTNET_CHAIN_ID = 13472; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,56 @@ | ||
import { BASIS_POINT_PRECISION } from 'constants/router'; | ||
import { ethers } from 'ethers'; | ||
import { SecondaryFee } from 'lib'; | ||
import { | ||
Fee, SecondaryFee, TokenInfo, newAmount, | ||
} from 'lib'; | ||
|
||
export function calculateFees(amount: ethers.BigNumber, secondaryFees: SecondaryFee[]) { | ||
let totalFees = ethers.BigNumber.from(0); | ||
export class Fees { | ||
private secondaryFees: SecondaryFee[]; | ||
|
||
for (let i = 0; i < secondaryFees.length; i++) { | ||
const feeAmount = amount.mul(secondaryFees[i].feeBasisPoints).div(BASIS_POINT_PRECISION); | ||
totalFees = totalFees.add(feeAmount); | ||
private token: TokenInfo; | ||
|
||
private amount: ethers.BigNumber = ethers.BigNumber.from(0); | ||
|
||
constructor(secondaryFees: SecondaryFee[], token: TokenInfo) { | ||
this.secondaryFees = secondaryFees; | ||
this.token = token; | ||
} | ||
|
||
addAmount(amount: ethers.BigNumber): void { | ||
this.amount = this.amount.add(amount); | ||
} | ||
|
||
amountWithFeesApplied(): ethers.BigNumber { | ||
return this.amount.add(this.total()); | ||
} | ||
|
||
amountLessFees(): ethers.BigNumber { | ||
return this.amount.sub(this.total()); | ||
} | ||
|
||
withAmounts(): Fee[] { | ||
return this.secondaryFees.map((fee) => { | ||
const feeAmount = this.amount | ||
.mul(fee.feeBasisPoints) | ||
.div(BASIS_POINT_PRECISION); | ||
|
||
return { | ||
...fee, | ||
amount: newAmount(feeAmount, this.token), | ||
}; | ||
}); | ||
} | ||
|
||
return totalFees; | ||
private total(): ethers.BigNumber { | ||
let totalFees = ethers.BigNumber.from(0); | ||
|
||
for (let i = 0; i < this.secondaryFees.length; i++) { | ||
const feeAmount = this.amount | ||
.mul(this.secondaryFees[i].feeBasisPoints) | ||
.div(BASIS_POINT_PRECISION); | ||
totalFees = totalFees.add(feeAmount); | ||
} | ||
|
||
return totalFees; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.