Gathering detailed insights and metrics for @anchor-protocol/anchor.js
Gathering detailed insights and metrics for @anchor-protocol/anchor.js
Gathering detailed insights and metrics for @anchor-protocol/anchor.js
Gathering detailed insights and metrics for @anchor-protocol/anchor.js
npm install @anchor-protocol/anchor.js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
46 Stars
163 Commits
37 Forks
8 Watching
5 Branches
13 Contributors
Updated on 09 Sept 2024
TypeScript (99.63%)
JavaScript (0.35%)
Shell (0.02%)
Cumulative downloads
Total Downloads
Last day
-81%
26
Compared to previous day
Last week
-41.2%
295
Compared to previous week
Last month
80.8%
1,839
Compared to previous month
Last year
-14.1%
14,909
Compared to previous year
Anchor.js is a client SDK for building applications that can interact with Anchor Protocol from within JavaScript runtimes, such as web browsers, server backends, and on mobile through React Native.
You can find a reference of the Anchor.js API here.
Anchor.js is available as a package on NPM and is intended to be used alongside Terra.js.
Add both:
@terra-money/terra.js
@anchor-protocol/anchor.js
To your JavaScript project's package.json
as dependencies using your preferred package manager:
1$ npm install -S @terra-money/terra.js @anchor-protocol/anchor.js
Anchor.js provides class wrapper facade for the usual operations available on webapp.
1import { LCDClient, MnemonicKey, Fee, Wallet } from '@terra-money/terra.js'
2import { Anchor, columbus5, AddressProviderFromJson, MARKET_DENOMS, OperationGasParameters } from '@anchor-protocol/anchor.js'
3
4const addressProvider = new AddressProviderFromJson(columbus5)
5const lcd = new LCDClient({ URL: 'https://lcd.terra.dev', chainID: 'columbus-5' })
6const key = new MnemonicKey({
7 mnemonic: 'your key'
8})
9const wallet = new Wallet(lcd, key)
10const anchor = new Anchor(lcd, addressProvider)
11
12// you can generate message only, using your wallet
13const msgs = anchor.earn.depositStable(MARKET_DENOMS.UUSD, "100.5000").generateWithWallet(wallet)
14
15// you can ALSO generate message only, using your address in string
16const msgs = anchor.earn.depositStable(MARKET_DENOMS.UUSD, "100.5000").generateWithAddress("terra1...")
17
18// or, you can broadcast the tx using your wallet
19// below is the recommended default setting for gas parameters.
20// of course you can tailor it to your needs
21const gasParameters: OperationGasParameters = {
22 gasAdjustment: 1.4,
23 gasPrices: "0.15uusd",
24
25 // or if you want to fixate gas, you can use `fee`
26 fee: new Fee(gasToSpend, "100000uusd")
27}
28const txResult = await anchor.earn.depositStable(MARKET_DENOMS.UUSD, "100.5000").execute(wallet, gasParameters)
When working with bAsset's, they can be loaded in one of two ways.
1import { LCDClient, MnemonicKey, Fee, Wallet } from '@terra-money/terra.js' 2import { Anchor, columbus5, bAssetColumbus5, AddressProviderFromJson, MARKET_DENOMS } from '@anchor-protocol/anchor.js' 3 4const addressProvider = new AddressProviderFromJson(columbus5) 5const lcd = new LCDClient({ URL: 'https://lcd.terra.dev', chainID: 'columbus-5' }) 6const key = new MnemonicKey({ 7 mnemonic: 'your key' 8}) 9const wallet = new Wallet(lcd, key) 10const anchor = new Anchor(lcd, addressProvider) 11 12// load the bAsset from the available whitelisted collateral 13const collaterals = await anchor.moneyMarket.getCollateralWhitelist({ 14 market: MARKET_DENOMS.UUSD, 15}); 16 17const [collateral] = collaterals.filter( 18 (collateral) => collateral.symbol === 'BETH', 19); 20 21const bAsset = await anchor.bAsset(collateral); 22 23// alternatively, the bAsset can be loaded with the symbol and market demons 24const bAsset = await anchor.bAsset({ symbol: 'BETH', market: MARKET_DENOMS.UUSD }); 25 26// once you have the bAsset, you can then perform operations 27const operation = bAsset.claim({ recipient: 'terra1...' });
Anchor.js provides facilities for 2 main use cases:
MsgExecuteContract
objects to be used in transactionsBoth of these functions are accessible through the Message Fabricators
.
To Use the message fabricators:
Note: Please note that market
is a different variable from the coin denom. The denomination for the coins in the example is set to be uusd
.
1import {fabricateRedeemStable, fabricateDepositStableCoin} from '@anchor-protocol/anchor.js'; 2import {AddressProviderFromJson} from "@anchor-protocol/anchor.js"; 3 4// default -- uses bombay core contract addresses 5const addressMap = somehowGetAddresses(); 6const addressProvider = new AddressProviderFromJson(addressMap); 7 const redeemMsg = fabricateRedeemStable({ 8 address: 'terra123...', 9 market: 'usd', 10 amount: '10000', 11 })(addressProvider); 12 13 const depositMsg = fabricateDepositStableCoin({ 14 address: 'terra123...', 15 market: 'usd', 16 amount: '10', 17 })(addressProvider);
A message fabricator contains functions for generating proper MsgExecuteContract
messages to be included in a transaction and broadcasted.
1import { LCDClient, Wallet, MnemonicKey, Fee} from '@terra-money/terra.js'; 2 3const anchor = new LCDClient({ URL: 'https://bombay-lcd.terra.dev', chainID:'bombay-12' }); 4const owner = new MnemonicKey({ mnemonic: "...."}); 5const wallet = new Wallet(anchor, owner); 6 7async function depositStable() { 8 const tx = await wallet.createAndSignTx({ 9 msgs: depositMsg, 10 fee: new Fee(2_000_000, { uluna: 2_000_000 }) 11 }); 12 return await anchor.tx.broadcast(tx); 13} 14 15async function main() { 16 await depositStable() 17 .then((result) => { 18 console.log(result); 19 }) 20 .catch(console.error); 21} 22 23main();
columbus-5
:
1{ 2 bLunaHub: 'terra1mtwph2juhj0rvjz7dy92gvl6xvukaxu8rfv8ts', 3 bLunaToken: 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp', 4 bLunaReward: 'terra17yap3mhph35pcwvhza38c2lkj7gzywzy05h7l0', 5 bLunaAirdrop: 'terra199t7hg7w5vymehhg834r6799pju2q3a0ya7ae9', 6 bEthReward: 'terra1939tzfn4hn960ychpcsjshu8jds3zdwlp8jed9', 7 bEthToken: 'terra1dzhzukyezv0etz22ud940z7adyv7xgcjkahuun', 8 mmInterestModel: 'terra1kq8zzq5hufas9t0kjsjc62t2kucfnx8txf547n', 9 mmOracle: 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t', 10 mmMarket: 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s', 11 mmOverseer: 'terra1tmnqgvg567ypvsvk6rwsga3srp7e3lg6u0elp8', 12 mmCustody: 'terra1ptjp2vfjrwh0j0faj9r6katm640kgjxnwwq9kn', 13 mmCustodyBEth: 'terra10cxuzggyvvv44magvrh3thpdnk9cmlgk93gmx2', 14 mmLiquidation: 'terra1w9ky73v4g7v98zzdqpqgf3kjmusnx4d4mvnac6', 15 mmDistributionModel: 'terra14mufqpr5mevdfn92p4jchpkxp7xr46uyknqjwq', 16 aTerra: 'terra1hzh9vpxhsk8253se0vv5jj6etdvxu3nv8z07zu', 17 terraswapblunaLunaPair: 'terra1jxazgm67et0ce260kvrpfv50acuushpjsz2y0p', 18 terraswapblunaLunaLPToken: 'terra1nuy34nwnsh53ygpc4xprlj263cztw7vc99leh2', 19 terraswapAncUstPair: 'terra1gm5p3ner9x9xpwugn9sp6gvhd0lwrtkyrecdn3', 20 terraswapAncUstLPToken: 'terra1gecs98vcuktyfkrve9czrpgtg0m3aq586x6gzm', 21 gov: 'terra1f32xyep306hhcxxxf7mlyh0ucggc00rm2s9da5', 22 distributor: 'terra1mxf7d5updqxfgvchd7lv6575ehhm8qfdttuqzz', 23 collector: 'terra14ku9pgw5ld90dexlyju02u4rn6frheexr5f96h', 24 community: 'terra12wk8dey0kffwp27l5ucfumczlsc9aned8rqueg', 25 staking: 'terra1897an2xux840p9lrh6py3ryankc6mspw49xse3', 26 ANC: 'terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76', 27 airdrop: 'terra146ahqn6d3qgdvmj8cj96hh03dzmeedhsf0kxqm', 28 team_vesting: 'terra1pm54pmw3ej0vfwn3gtn6cdmaqxt0x37e9jt0za', 29 investor_vesting: 'terra10evq9zxk2m86n3n3xnpw28jpqwp628c6dzuq42' 30}
bombay-12
:
1{ 2 bLunaHub: 'terra1fflas6wv4snv8lsda9knvq2w0cyt493r8puh2e', 3 bLunaToken: 'terra1u0t35drzyy0mujj8rkdyzhe264uls4ug3wdp3x', 4 bLunaReward: 'terra1ac24j6pdxh53czqyrkr6ygphdeftg7u3958tl2', 5 bLunaAirdrop: 'terra1334h20c9ewxguw9p9vdxzmr8994qj4qu77ux6q', 6 bEthReward: 'terra1ja3snkedk4t0zp7z3ljd064hcln8dsv5x004na', 7 bEthToken: 'terra19mkj9nec6e3y5754tlnuz4vem7lzh4n0lc2s3l', 8 mmInterestModel: 'terra1m25aqupscdw2kw4tnq5ql6hexgr34mr76azh5x', 9 mmOracle: 'terra1p4gg3p2ue6qy2qfuxtrmgv2ec3f4jmgqtazum8', 10 mmMarket: 'terra15dwd5mj8v59wpj0wvt233mf5efdff808c5tkal', 11 mmOverseer: 'terra1qljxd0y3j3gk97025qvl3lgq8ygup4gsksvaxv', 12 mmCustody: 'terra1ltnkx0mv7lf2rca9f8w740ashu93ujughy4s7p', 13 mmCustodyBEth: 'terra1j6fey5tl70k9fvrv7mea7ahfr8u2yv7l23w5e6', 14 mmLiquidation: 'terra16vc4v9hhntswzkuunqhncs9yy30mqql3gxlqfe', 15 mmDistributionModel: 'terra1u64cezah94sq3ye8y0ung28x3pxc37tv8fth7h', 16 aTerra: 'terra1ajt556dpzvjwl0kl5tzku3fc3p3knkg9mkv8jl', 17 terraswapblunaLunaPair: 'terra13e4jmcjnwrauvl2fnjdwex0exuzd8zrh5xk29v', 18 terraswapblunaLunaLPToken: 'terra1tj4pavqjqjfm0wh73sh7yy9m4uq3m2cpmgva6n', 19 terraswapAncUstPair: 'terra1wfvczps2865j0awnurk9m04u7wdmd6qv3fdnvz', 20 terraswapAncUstLPToken: 'terra1vg0qyq92ky9z9dp0j9fv5rmr2s80sg605dah6f', 21 gov: 'terra16ckeuu7c6ggu52a8se005mg5c0kd2kmuun63cu', 22 distributor: 'terra1z7nxemcnm8kp7fs33cs7ge4wfuld307v80gypj', 23 collector: 'terra1hlctcrrhcl2azxzcsns467le876cfuzam6jty4', 24 community: 'terra17g577z0pqt6tejhceh06y3lyeudfs3v90mzduy', 25 staking: 'terra19nxz35c8f7t3ghdxrxherym20tux8eccar0c3k', 26 ANC: 'terra1747mad58h0w4y589y3sk84r5efqdev9q4r02pc', 27 airdrop: 'terra1u5ywhlve3wugzqslqvm8ks2j0nsvrqjx0mgxpk', 28 investor_vesting: 'not available in testnet', 29 team_vesting: 'not available in testnet', 30}
This software is licensed under the Apache 2.0 license. Read more about it here.
© 2021 Anchor Protocol
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/26 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
27 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More