-
Notifications
You must be signed in to change notification settings - Fork 22
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' of https://github.com/CrocSwap/sdk into scroll-l1gas
- Loading branch information
Showing
10 changed files
with
238 additions
and
53 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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { BigNumber, ethers } from 'ethers'; | ||
import { CrocContext } from './context'; | ||
|
||
/* This is the main entry point for the Croc SDK. It provides a high-level interface | ||
* for interacting with CrocSwap smart contracts in an ergonomic way. */ | ||
export class CrocSlotReader { | ||
constructor (context: Promise<CrocContext>) { | ||
this.provider = context.then(p => p.provider) | ||
this.dex = context.then(c => c.dex.address) | ||
} | ||
|
||
async isHotPathOpen(): Promise<boolean> { | ||
const STATE_SLOT = 0 | ||
const HOT_OPEN_OFFSET = 22 | ||
|
||
const hotShiftBits = 8 * (32 - HOT_OPEN_OFFSET) | ||
const slotVal = this.readSlot(STATE_SLOT).then(BigNumber.from) | ||
return (await slotVal).shl(hotShiftBits).shr(255).gt(0) | ||
} | ||
|
||
async readSlot (slot: number): Promise<string> { | ||
return (await this.provider).getStorageAt(await this.dex, slot) | ||
} | ||
|
||
async proxyContract (proxyIdx: number): Promise<string> { | ||
const PROXY_SLOT_OFFSET = 1 | ||
|
||
const slotVal = await this.readSlot(PROXY_SLOT_OFFSET + proxyIdx) | ||
return "0x" + slotVal.slice(26) | ||
} | ||
|
||
readonly provider: Promise<ethers.providers.Provider> | ||
readonly dex: Promise<string> | ||
} |
Oops, something went wrong.