-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
- Loading branch information
1 parent
687c50c
commit 8455be9
Showing
5 changed files
with
170 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { PublicKey } from '@solana/web3.js'; | ||
import { Group } from '../src/accounts/group'; | ||
import { ZERO_I80F48 } from '../src/numbers/I80F48'; | ||
|
||
/** | ||
* scans mango group for all oracles that need updating | ||
* includes bank oracle, fallback oracle and perp market oracles | ||
*/ | ||
export function getOraclesForMangoGroup( | ||
group: Group, | ||
): { oraclePk: PublicKey; name: string }[] { | ||
// oracles for tokens | ||
const oracles1 = Array.from(group.banksMapByName.values()) | ||
.filter( | ||
(b) => | ||
!( | ||
b[0].nativeDeposits().eq(ZERO_I80F48()) && | ||
b[0].nativeBorrows().eq(ZERO_I80F48()) && | ||
b[0].reduceOnly == 1 | ||
), | ||
) | ||
.map((b) => { | ||
return { | ||
oraclePk: b[0].oracle, | ||
|
||
name: b[0].name, | ||
}; | ||
}); | ||
|
||
// oracles for perp markets | ||
const oracles2 = Array.from(group.perpMarketsMapByName.values()).map((pM) => { | ||
return { | ||
oraclePk: pM.oracle, | ||
|
||
name: pM.name, | ||
}; | ||
}); | ||
|
||
// fallback oracles for tokens | ||
const oracles3 = Array.from(group.banksMapByName.values()) | ||
.filter( | ||
(b) => | ||
!( | ||
b[0].nativeDeposits().eq(ZERO_I80F48()) && | ||
b[0].nativeBorrows().eq(ZERO_I80F48()) && | ||
b[0].reduceOnly == 1 | ||
), | ||
) | ||
.map((b) => { | ||
return { | ||
oraclePk: b[0].oracle, | ||
|
||
name: b[0].name, | ||
}; | ||
}) | ||
.filter((item) => !item.oraclePk.equals(PublicKey.default)); | ||
const oracles = oracles1.concat(oracles2).concat(oracles3); | ||
return oracles; | ||
} |
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