Skip to content

Commit

Permalink
chore: use bn.js for uiPrice
Browse files Browse the repository at this point in the history
  • Loading branch information
mindrunner committed Mar 19, 2024
1 parent 035820c commit 7b653a8
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 66 deletions.
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 55 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
{
"name": "@staratlas/factory",
"version": "0.6.0",
"description": "Star Atlas Factory for constructing Transactions targeting Solana on-chain programs",
"repository": {
"type": "git",
"url": "git+https://github.com/staratlasmeta/factory.git"
},
"author": "ATMTA, Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/staratlasmeta/factory/issues"
},
"homepage": "https://github.com/staratlasmeta/factory#readme",
"main": "dist/index.js",
"source": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"prepare": "npm run build",
"lint": "eslint src --max-warnings=0",
"lint:fix": "npm run lint -- --fix",
"test": "jest --detectOpenHandles --no-cache --silent",
"start": "tsc --watch",
"docs": "npx typedoc --out docs src",
"ts-node": "ts-node"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@solana/spl-token": "^0.4.1",
"@solana/web3.js": "^1.91.1",
"lodash": "^4.17.21",
"mobx": "^6.12.0",
"mobx-utils": "^6.0.8"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/bn.js": "^5.1.5",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2"
},
"files": [
"dist"
]
"name": "@staratlas/factory",
"version": "0.6.0",
"description": "Star Atlas Factory for constructing Transactions targeting Solana on-chain programs",
"repository": {
"type": "git",
"url": "git+https://github.com/staratlasmeta/factory.git"
},
"author": "ATMTA, Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/staratlasmeta/factory/issues"
},
"homepage": "https://github.com/staratlasmeta/factory#readme",
"main": "dist/index.js",
"source": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rm -rf dist",
"prepare": "npm run build",
"lint": "eslint src --max-warnings=0",
"lint:fix": "npm run lint -- --fix",
"test": "jest --detectOpenHandles --no-cache --silent",
"start": "tsc --watch",
"docs": "npx typedoc --out docs src",
"ts-node": "ts-node"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@solana/spl-token": "^0.4.1",
"@solana/web3.js": "^1.91.1",
"big.js": "^6.2.1",
"lodash": "^4.17.21",
"mobx": "^6.12.0",
"mobx-utils": "^6.0.8"
},
"devDependencies": {
"@types/big.js": "^6.2.2",
"@types/jest": "^29.5.12",
"@types/bn.js": "^5.1.5",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"ts-jest": "^29.1.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2"
},
"files": [
"dist"
]
}
19 changes: 6 additions & 13 deletions src/marketplace/models/Order.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BN } from '@coral-xyz/anchor';
import BigNumber from 'big.js';
import { makeObservable, observable } from 'mobx';

export enum OrderSide {
Expand Down Expand Up @@ -59,20 +60,12 @@ export class Order implements OrderType {
});
}

protected get decimalDivisor(): BN {
return new BN(10).pow(new BN(this.currencyDecimals));
protected get decimalDivisor(): BigNumber {
return new BigNumber(10).pow(this.currencyDecimals);
}

protected get bigNumberPrice(): BN {
return new BN(this.price.toString());
}

get bnoPrice(): BN {
return this.bigNumberPrice;
}

get divisor(): BN {
return this.decimalDivisor;
protected get bigNumberPrice(): BigNumber {
return new BigNumber(this.price.toString());
}

get uiPrice(): number {
Expand All @@ -81,7 +74,7 @@ export class Order implements OrderType {

priceForQuantity(quantity = 1): number {
return this.bigNumberPrice
.mul(new BN(quantity))
.mul(quantity)
.div(this.decimalDivisor)
.toNumber();
}
Expand Down

0 comments on commit 7b653a8

Please sign in to comment.