-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
102 additions
and
17 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
packages/sdk/test/script/examples/router/onBlockPoolChange.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ApiPromise } from '@polkadot/api'; | ||
import { ApiUrl, PolkadotExecutor } from '../../executor'; | ||
import { PoolService } from '../../../../src/pool'; | ||
import { TradeRouter } from '../../../../src/api'; | ||
|
||
class GetOnBlockPoolChangeExample extends PolkadotExecutor { | ||
async script(api: ApiPromise): Promise<any> { | ||
const poolService = new PoolService(api); | ||
const router = new TradeRouter(poolService); | ||
|
||
const result = await Promise.all([ | ||
router.getBestSpotPrice('5', '0'), | ||
router.getBestSpotPrice('5', '0'), | ||
router.getBestSpotPrice('5', '0'), | ||
router.getBestSpotPrice('5', '0'), | ||
router.getBestSpotPrice('5', '0'), | ||
]); | ||
console.log('Call spot 5x simultaneously', result); | ||
|
||
api.rpc.chain.subscribeNewHeads(async (_lastHeader) => { | ||
console.log('=================='); | ||
router.getPools().then((p) => { | ||
p.forEach((o) => { | ||
o.tokens.forEach((t) => { | ||
if (t.id === '1') { | ||
// Checking LRNA balance change | ||
console.log(t.id, t.balance.toString()); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
return []; | ||
} | ||
} | ||
|
||
new GetOnBlockPoolChangeExample( | ||
ApiUrl.HydraDx, | ||
'Get on block change', | ||
true | ||
).run(); |