Skip to content

Commit

Permalink
Remove Gas Budget From Contract Calls (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahabro authored Sep 24, 2023
1 parent 3d26402 commit 4e0a397
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bluefin-exchange/bluefin-v2-client",
"version": "3.2.0",
"version": "3.2.1",
"description": "The Bluefin client Library allows traders to sign, create, retrieve and listen to orders on Bluefin Exchange.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -56,7 +56,7 @@
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@firefly-exchange/library-sui": "^0.1.57",
"@firefly-exchange/library-sui": "^0.1.61",
"@mysten/sui.js": "^0.35.0",
"@noble/hashes": "^1.2.0",
"@noble/secp256k1": "^1.7.1",
Expand Down
2 changes: 1 addition & 1 deletion public/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "tsc"
},
"dependencies": {
"@bluefin-exchange/bluefin-v2-client": "^2.5.0"
"@bluefin-exchange/bluefin-v2-client": "^3.2.1"
},
"devDependencies": {
"typescript": "^5.2.2"
Expand Down
4 changes: 0 additions & 4 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,5 @@ export const Networks = {
},
};

export const DEFAULT_PRECISION = 6;
export const SUI_NETWROK = "sui";

export const EXTRA_FEES = 10000;

export const POST_ORDER_BASE = 18;
38 changes: 7 additions & 31 deletions src/exchange/contractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export class ContractCalls {

marginBankId: string | undefined;

defaultGas: number = 100000000;

constructor(signer: RawSigner, rpc: JsonRpcProvider, deployment: any) {
this.signer = signer;
const signerWithProvider = this.signer.signData;
Expand All @@ -34,20 +32,17 @@ export class ContractCalls {

/**
* @param amount the amount to withdraw
* @param gasLimit (optional) the gas limit for the transaction
* @returns ResponseSchema
* @description
* Withdraws funds from the margin bank contract
* */
withdrawFromMarginBankContractCall = async (
amount: Number,
gasLimit?: number
amount: Number
): Promise<ResponseSchema> => {
return TransformToResponseSchema(async () => {
const tx = await this.onChainCalls.withdrawFromBank(
{
amount: toBigNumberStr(amount.toString(), 6),
gasBudget: gasLimit || this.defaultGas,
},
this.signer
);
Expand All @@ -59,34 +54,26 @@ export class ContractCalls {
};

/**
* @param gasLimit (optional) the gas limit for the transaction
* @returns ResponseSchema
* @description
* Withdraws all funds from the margin bank contract
* */
withdrawAllFromMarginBankContractCall = async (
gasLimit?: number
): Promise<ResponseSchema> => {
withdrawAllFromMarginBankContractCall = async (): Promise<ResponseSchema> => {
return TransformToResponseSchema(async () => {
return await this.onChainCalls.withdrawAllMarginFromBank(
this.signer,
gasLimit || this.defaultGas
);
return await this.onChainCalls.withdrawAllMarginFromBank(this.signer);
}, interpolate(SuccessMessages.withdrawMargin, { amount: "all" }));
};

/**
* @param amount the amount to deposit
* @param coinID the coinID to deposit
* @param gasLimit (optional) the gas limit for the transaction
* @returns ResponseSchema
* @description
* Deposits funds to the margin bank contract
* */
depositToMarginBankContractCall = async (
amount: number,
coinID: string,
gasLimit?: number
coinID: string
): Promise<ResponseSchema> => {
return TransformToResponseSchema(async () => {
const tx = await this.onChainCalls.depositToBank(
Expand All @@ -95,7 +82,6 @@ export class ContractCalls {
coinID,
bankID: this.onChainCalls.getBankID(),
accountAddress: await this.signer.getAddress(),
gasBudget: gasLimit || this.defaultGas,
},
this.signer
);
Expand All @@ -109,7 +95,6 @@ export class ContractCalls {
/**
* @param leverage the leverage to set
* @param symbol the position's market symbol
* @param gasLimit (optional) the gas limit for the transaction
* @returns ResponseSchema
* @description
* adjusts the leverage of the desiered position
Expand All @@ -118,8 +103,7 @@ export class ContractCalls {
adjustLeverageContractCall = async (
leverage: number,
symbol: string,
parentAddress?: string,
gasLimit?: number
parentAddress?: string
): Promise<ResponseSchema> => {
const perpId = this.onChainCalls.getPerpetualID(symbol);
return TransformToResponseSchema(async () => {
Expand All @@ -128,7 +112,6 @@ export class ContractCalls {
leverage,
perpID: perpId,
account: parentAddress || (await this.signer.getAddress()),
gasBudget: gasLimit || this.defaultGas,
market: symbol,
},
this.signer
Expand All @@ -139,23 +122,20 @@ export class ContractCalls {
/**
* @param publicAddress the sub account's public address
* @param status the status to set for sub account true = add, false = remove
* @param gasLimit (optional) the gas limit for the transaction
* @returns ResponseSchema
* @description
* closes the desiered position
* */

setSubAccount = async (
publicAddress: address,
status: boolean,
gasLimit?: number
status: boolean
): Promise<ResponseSchema> => {
return TransformToResponseSchema(async () => {
return await this.onChainCalls.setSubAccount(
{
account: publicAddress,
status,
gasBudget: gasLimit || this.defaultGas,
},
this.signer
);
Expand All @@ -166,16 +146,14 @@ export class ContractCalls {
* @param symbol the position's market symbol
* @operationType the operation type to perform (add or remove)
* @amount the amount to add or remove
* @param gasLimit (optional) the gas limit for the transaction
* @returns Response Schemea
* @description
* adjusts the margin of the desiered position
* */
adjustMarginContractCall = async (
symbol: string,
operationType: ADJUST_MARGIN,
amount: number,
gasLimit?: number
amount: number
): Promise<ResponseSchema> => {
const perpId = this.onChainCalls.getPerpetualID(symbol);
const msg =
Expand All @@ -188,7 +166,6 @@ export class ContractCalls {
{
amount,
perpID: perpId,
gasBudget: gasLimit || this.defaultGas,
market: symbol,
},
this.signer
Expand All @@ -197,7 +174,6 @@ export class ContractCalls {
return await this.onChainCalls.removeMargin(
{
amount,
gasBudget: gasLimit,
perpID: perpId,
market: symbol,
},
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,10 @@
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.44.0.tgz#961a5903c74139390478bdc808bcde3fc45ab7af"
integrity sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw==

"@firefly-exchange/library-sui@^0.1.57":
version "0.1.59"
resolved "https://registry.yarnpkg.com/@firefly-exchange/library-sui/-/library-sui-0.1.59.tgz#c09c389baefb07cdf35fff6c8bdef843b0418ef0"
integrity sha512-vQvOBW4sshucWpyq47brlWINZ6WLGZd/PZSTJJHS7qeYDlxXDbbHQm6Prt066S/iSaDp0wNfEBEEEGqQSCLrgw==
"@firefly-exchange/library-sui@^0.1.61":
version "0.1.61"
resolved "https://registry.yarnpkg.com/@firefly-exchange/library-sui/-/library-sui-0.1.61.tgz#7da987ae672e183c79439e610e83c0629b198b22"
integrity sha512-2j/v9wEkWtZObg8/2DCKRb+/HewDI7A+WiNdosus2DNUuulTnozEVxcXUyuuh80KdV+SPc2eqk7u6OyVleVBaw==
dependencies:
"@mysten/sui.js" "^0.35.0"
"@noble/hashes" "^1.2.0"
Expand Down

0 comments on commit 4e0a397

Please sign in to comment.