-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #585 from balancer/develop
Release 1.1.6
- Loading branch information
Showing
46 changed files
with
3,866 additions
and
1,533 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ jobs: | |
echo -n "$SIGNING_KEY" | base64 --decode | gpg --import | ||
git config --global user.name "johngrantuk" | ||
git config --global user.email "[email protected]" | ||
git config user.signingkey 0B86E3F46D321811DC4330D1376AF1CD2A15D127 | ||
git config user.signingkey 5D1644BB7D087635E36B06C1ABCBFFAEE5EAEE77 | ||
git config gpg.program /usr/bin/gpg | ||
yarn version --prerelease --preid beta --no-git-tag-version | ||
export NEW_VERSION=$(jq -r '.version' package.json) | ||
|
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Balancer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,25 @@ | ||
/** | ||
* Display APRs for pool ids hardcoded under `const ids` | ||
* Run command: yarn example ./examples/data/token-prices.ts | ||
*/ | ||
import { ApiTokenPriceService } from '@/modules/sor/token-price/apiTokenPriceService'; | ||
|
||
const dai = '0x6b175474e89094c44da98b954eedeac495271d0f'; | ||
const weth = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'; | ||
const ohm = '0X64AA3364F17A4D01C6F1751FD97C2BD3D7E7F1D5'; | ||
|
||
(async () => { | ||
const apiTokenPriceService = new ApiTokenPriceService(1); | ||
const daiPriceInEth = await apiTokenPriceService.getNativeAssetPriceInToken( | ||
dai | ||
); | ||
console.log('Dai Price In ETH: ' + daiPriceInEth); | ||
const wethPriceInEth = await apiTokenPriceService.getNativeAssetPriceInToken( | ||
weth | ||
); | ||
console.log('WETH Price In ETH: ' + wethPriceInEth); | ||
const ohmPriceInEth = await apiTokenPriceService.getNativeAssetPriceInToken( | ||
ohm | ||
); | ||
console.log('OHM Price In ETH: ' + ohmPriceInEth); | ||
})(); |
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,44 @@ | ||
/** | ||
* Display APRs for pool ids hardcoded under `const ids` | ||
* | ||
* Run command | ||
* yarn example ./examples/pools/aprs/aprs.arbitrum.ts | ||
*/ | ||
import { BalancerSDK, Pool } from '@balancer-labs/sdk'; | ||
|
||
const sdk = new BalancerSDK({ | ||
network: 8453, | ||
rpcUrl: 'https://rpc.ankr.com/base', | ||
}); | ||
|
||
const { pools } = sdk; | ||
|
||
const main = async () => { | ||
const id = | ||
'0xfb4c2e6e6e27b5b4a07a36360c89ede29bb3c9b6000000000000000000000026'; | ||
const pool = (await pools.find(id)) as Pool; | ||
const apr = await pools.apr(pool); | ||
console.log(pool.id, apr); | ||
|
||
// const list = ( | ||
// await pools.where( | ||
// (pool) => | ||
// pool.poolType != 'Element' && | ||
// pool.poolType != 'AaveLinear' && | ||
// pool.poolType != 'LiquidityBootstrapping' | ||
// ) | ||
// ) | ||
// .sort((a, b) => parseFloat(b.totalLiquidity) - parseFloat(a.totalLiquidity)) | ||
// .slice(0, 30) | ||
|
||
// list.forEach(async (pool) => { | ||
// try { | ||
// const apr = await pools.apr(pool) | ||
// console.log(pool.id, apr) | ||
// } catch (e) { | ||
// console.log(e) | ||
// } | ||
// }); | ||
}; | ||
|
||
main(); |
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,23 @@ | ||
import { BalancerSDK } from '@balancer-labs/sdk'; | ||
|
||
const sdk = new BalancerSDK({ | ||
network: 1, | ||
rpcUrl: 'https://rpc.ankr.com/eth', | ||
coingecko: { | ||
coingeckoApiKey: 'CG-ViHyrfvtLz2WSCJzm59TfGow', | ||
isDemoApiKey: true, | ||
}, | ||
}); | ||
|
||
const bptPriceExample = async () => { | ||
const poolId = | ||
'0x26cc136e9b8fd65466f193a8e5710661ed9a98270002000000000000000005ad'; | ||
const pool = await sdk.pools.find(poolId); | ||
if (!pool) { | ||
throw new Error('Pool not found'); | ||
} | ||
const bptPrice = await sdk.pools.bptPrice(pool); | ||
console.log('bpt price: ', bptPrice); | ||
}; | ||
|
||
bptPriceExample().catch((error) => console.error(error)); |
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,104 @@ | ||
/** | ||
* Helper example to facilitate swap debugging within the SDK | ||
* | ||
* How to run: | ||
* yarn example examples/swaps/swapDebug.ts | ||
*/ | ||
import { ADDRESSES } from '@/test/lib/constants'; | ||
import { FORK_NODES, RPC_URLS, forkSetup } from '@/test/lib/utils'; | ||
import { BalancerSDK, Network } from '@balancer-labs/sdk'; | ||
import { formatFixed } from '@ethersproject/bignumber'; | ||
|
||
const network = Network.MAINNET; | ||
const rpcUrl = RPC_URLS[network]; | ||
const sdk = new BalancerSDK({ | ||
network, | ||
rpcUrl, | ||
}); | ||
|
||
const tokenIn = ADDRESSES[network].BAL8020BPT; | ||
const tokenOut = ADDRESSES[network].auraBal; | ||
const amount = String(BigInt(1000e18)); // 1000 eth | ||
|
||
const { swaps } = sdk; | ||
const erc20Out = sdk.contracts.ERC20(tokenOut.address, sdk.provider); | ||
|
||
async function swap() { | ||
const signer = sdk.provider.getSigner(); | ||
const account = await signer.getAddress(); | ||
|
||
await forkSetup( | ||
signer, | ||
[tokenIn.address], | ||
[tokenIn.slot], | ||
[amount], | ||
FORK_NODES[network] | ||
); | ||
|
||
// Finding a trading route rely on on-chain data. | ||
// fetchPools will fetch the current data from the subgraph. | ||
// Let's fetch just 5 pools with highest liquidity of tokenOut. | ||
await swaps.fetchPools({ | ||
first: 5, | ||
where: { | ||
swapEnabled: { | ||
eq: true, | ||
}, | ||
tokensList: { | ||
contains: [tokenOut.address], | ||
}, | ||
}, | ||
orderBy: 'totalLiquidity', | ||
orderDirection: 'desc', | ||
}); | ||
|
||
// Set exectution deadline to 60 seconds from now | ||
const deadline = String(Math.ceil(Date.now() / 1000) + 60); | ||
|
||
// Avoid getting rekt by setting low slippage from expected amounts out, 10 bsp = 0.1% | ||
const maxSlippage = 10; | ||
|
||
// Building the route payload | ||
const payload = await swaps.buildRouteExactIn( | ||
account, | ||
account, | ||
tokenIn.address, | ||
tokenOut.address, | ||
amount, | ||
{ | ||
maxSlippage, | ||
deadline, | ||
} | ||
); | ||
|
||
// Extract parameters required for sendTransaction | ||
const { to, data, value } = payload; | ||
|
||
// Execution with ethers.js | ||
try { | ||
const balanceBefore = await erc20Out.balanceOf(account); | ||
|
||
await ( | ||
await signer.sendTransaction({ | ||
to, | ||
data, | ||
value, | ||
gasLimit: 8e6, | ||
}) | ||
).wait(); | ||
|
||
// check delta | ||
const balanceAfter = await erc20Out.balanceOf(account); | ||
|
||
console.log( | ||
`Amount of tokenOut received: ${formatFixed( | ||
balanceAfter.sub(balanceBefore), | ||
tokenOut.decimals | ||
)}` | ||
); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
swap(); |
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
Oops, something went wrong.