anchor-protocol / anchor.js Goto Github PK
View Code? Open in Web Editor NEWThe JavaScript SDK for Anchor Protocol
License: Apache License 2.0
The JavaScript SDK for Anchor Protocol
License: Apache License 2.0
The current Readme is aligned with the previous version of the code. We need to update Readme and message fabricators' names. The following change must happen:
The terra.js SDK is currently listed as both a dependency and dev dependency.
I believe it should only be listed as a peer dependency, given that consumers of anchor.js are instructed to install terra.js with anchor.js. If developers are using a different version of terra.js this will likely cause conflicts and difficult to debug issues.
Hey! ๐
It would be cool if we can get the amount of ANC available as borrow rewards.
i create an borrow msg with api in anchor.js,
the message is :
{ coins:[], contract: "terra15dwd5mj8v59wpj0wvt233mf5efdff808c5tkal", execute_msg:{borrow_stable:{borrow_amount: "2155939304",to: "terra130pmlk768prw66rhszqj6qq02sdtf3mlchknap"}}, sender: "terra130pmlk768prw66rhszqj6qq02sdtf3mlchknap" }
when i running estimateFee, i get the error,
failed to execute message; message index: 0: Generic error: Querier contract error: Generic error: Price is too old: contract query failed: execute wasm contract failed: invalid request
Code
const address = 'terra1fpnt5t2094g3amcwdv3akl60jg9uafgtc38px8';
const borrowedValue = await anchor.borrow.getBorrowedValue({
market: MARKET_DENOMS.UUSD,
address,
});
const borrowLimit = await anchor.borrow.getBorrowLimit({
market: MARKET_DENOMS.UUSD,
address,
});
console.log(borrowedValue);
console.log(borrowLimit);
Output
0.000000000000000000
0.000000000000000000
It works but
Code
const address = 'terra1fpnt5t2094g3amcwdv3akl60jg9uafgtc38px8';
const collateralValue = await anchor.borrow.getCollateralValue({
market: MARKET_DENOMS.UUSD,
address,
});
console.log(collateralValue);
Output
TypeError: Cannot read property 'collateral' of null
at C:\Users\HSK\programming\anchor-command-tools\node_modules\@anchor-protocol\anchor.js\src\facade\borrow\borrow.ts:95:39
at Array.find (<anonymous>)
at C:\Users\HSK\programming\anchor-command-tools\node_modules\@anchor-protocol\anchor.js\src\facade\borrow\borrow.ts:94:50
at Array.reduce (<anonymous>)
at Borrow.<anonymous> (C:\Users\HSK\programming\anchor-command-tools\node_modules\@anchor-protocol\anchor.js\src\facade\borrow\borrow.ts:93:31)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\HSK\programming\anchor-command-tools\node_modules\@anchor-protocol\anchor.js\dist\facade\borrow\borrow.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
This code occurs an error.
I used a random address that were in my wallet history for test.
I changed the address to my wallet address. It worked well.
Are there addresses that can't get collateral value?
Hey there! ๐
We are missing the possibility to unstake
governance token.
The SDK only provide the stakeVotingTokens
methods.
Is there any JS example that shows how to use Anchor and Terra sdk to Bond LUNA for bLUNA (staking and unstaking)
Thanks
Hi
Some of useful API has been implemented in queries/terraswap/*, but it is not exported.
Is this intentional or bug?
https://docs.anchorprotocol.com/developers-terra/anchor-cli has an incorrect package name:
$ npm install -g @anchor-protocol/cli
The npm package page has the correct package:
$ npm install -g @anchor-protocol/anchorcli
I didn't find in this repo the docs, if you can point me to the repo location I can send a PR
I've noticed that https://api.extraterrestrial.money/v1/api/prices and Mirror have slightly different rates for aUST (as of right now as I type this 1.092843 vs 1.105404.)
Is it possible to calculate how much 1 aUST is in UST using anchor.js or terra.js, and if so, what's the best way?
Other functions return correct values, but getCollateralValue fails:
const main = async (): Promise<void> => {
const wallet = new Wallet(lcd, key)
const anchor = new Anchor(lcd, addressProvider)
const walletDenom = {
address: wallet.key.accAddress,
market: MARKET_DENOMS.UUSD,
}
try {
const totalDeposits = await anchor.earn.getTotalDeposit(walletDenom)
const borrowedValue = await anchor.borrow.getBorrowedValue(walletDenom)
const collateralValue = await anchor.borrow.getCollateralValue(walletDenom)
// console.log(totalDeposits) // returns correct value
// console.log(borrowedValue) // returns correct value
console.log(collateralValue) // data: { error: 'decoding bech32 failed: invalid separator index -1' }
} catch(error) {
console.log(error)
}
}
I was trying this :
import { Anchor, columbus5, AddressProviderFromJson, MARKET_DENOMS, OperationGasParameters } from '@anchor-protocol/anchor.js'
which has thrown me this error:
SyntaxError: Named export 'OperationGasParameters' not found. The requested module '@anchor-protocol/anchor.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@anchor-protocol/anchor.js';
const { Anchor, columbus5, AddressProviderFromJson, MARKET_DENOMS, OperationGasParameters } = pkg;
Any idea why it's happening?
Now that max/safe ltv is a value that can change and with eth potentially having a different LTV can we get a getMaxLTV and getSaveLTV function for borrow.
CurrentlyfabricateProvideCollateral
includes lock_collateral
for both collaterals (bluna and bEth), but there is no individual fabricator for bETH lock_collateral
/ unlock_collateral
. We need to introduce new fabricators for these two functions.
import { LCDClient } from '@terra-money/terra.js';
import {
Anchor,
columbus4,
AddressProviderFromJson,
MARKET_DENOMS,
} from '@anchor-protocol/anchor.js';
const walletAddress = '[my wallet address]';
const main = async () => {
const addressProvider = new AddressProviderFromJson(columbus4);
const lcd = new LCDClient({
URL: 'https://lcd.terra.dev',
chainID: 'columbus-4',
});
const anchor = new Anchor(lcd, addressProvider);
try {
const price = await anchor.anchorToken.getANCPrice();
const borrowedValue = await anchor.borrow.getBorrowedValue(
MARKET_DENOMS.UUSD,
walletAddress
);
console.log('price', price);
console.log('borrowedValue', borrowedValue);
} catch (err) {
console.error(err);
}
};
main();
The method getANCPrice works well. but
Calling a method 'getBorrowedValue' occurs an error.
contract query failed: parsing moneymarket::market::QueryMsg: unknown variant `loan_amount`, expected one of `config`, `state`, `epoch_state`, `borrower_info`, `borrower_infos`
I think I might've called in a wrong way. but I don't know why it doesn't work.
How should I call this function? (I don't want to use a mnemonic)
Anchor protocol introduced liquidation queue contract and anchor.js must have this feature.
Hey there! ๐
It seems that columbus-5 is around the corner.
Does the SDK already support Columbus 5 ? If not, how long would it take to make it compatible?
claim_liquidation
should be claim_liquidations
.
Currently:
interface Option {
lcd: LCDClient;
collateral_token: string;
start_after: number | undefined;
limit: number | undefined;
}
export interface BidPoolResponse {
sum_snapshot: string;
product_snapshot: string;
total_bid_amount: string;
premium_rate: string;
current_epoch: string;
current_scale: string;
}
export declare const queryLiquidationQueueBidPoolsByCollateral: ({ lcd, collateral_token, start_after, limit }: Option) => (addressProvider: AddressProvider) => Promise<BidPoolResponse[]>;
The return type of queryLiquidationQueueBidPoolsByCollateral
should be:
export interface BidPoolsByCollateralResponse {
bid_pools: BidPoolResponse[]
}
Version:
"@anchor-protocol/anchor.js": "^5.0.2"
Documentation: https://docs.anchorprotocol.com/smart-contracts/liquidations/liquidation-queue-contract#bidpoolsbycollateralresponse
Example response in documentation:
{
"bid_pools": [
{
"sum_snapshot": "1.0",
"product_snapshot": "1.0",
"total_bid_amount": "1000000",
"premium_rate": "0.1",
"current_epoch": "0",
"current_scale": "0"
},
{
"sum_snapshot": "1.0",
"product_snapshot": "1.0",
"total_bid_amount": "2000000",
"premium_rate": "0.2",
"current_epoch": "0",
"current_scale": "0"
}
]
}
Hello, not sure if this is the right place for this question.
I am trying to get borrowed amount of previous block heights to calculate the occurred loan fees over time.
WIthout previous knowledge, I just was trying within dev tools to change the request as follows but it always returns the current block height. Ideas?
height=5971055;
address="terra...";
(await (await fetch("https://mantle.terra.dev/?borrow--borrower", {
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"referrer": "https://app.anchorprotocol.com/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "{\"query\":\"{\\n marketBorrowerInfo: WasmContractsContractAddressStore(\\n ContractAddress: \\\"terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s\\\"\\n QueryMsg: \\\"{\\\\\\\"borrower_info\\\\\\\":{\\\\\\\"borrower\\\\\\\":\\\\\\\""+address+"\\\\\\\",\\\\\\\"block_height\\\\\\\":"+height+"}}\\\"\\n ) {\\n Result\\n Height\\n }\\n}\\n\",\"variables\":{}}",
"method": "POST",
"mode": "cors",
"credentials": "omit"
})).json()).data.marketBorrowerInfo
The current fabricate function has "active" instead of "activate" as stated in the docs (https://docs.anchorprotocol.com/smart-contracts/liquidations/liquidation-queue-contract). Activate represents what it does, after all.
The APY calculation in the webapp has been updated with epoch_period
(Anchor-Protocol/anchor-web-app#353)
This logic is not replicated in earn.getAPY
anchor.js/src/facade/earn/earn.ts
Line 83 in df76c7f
Hi,
I'm testing terra.js
and always getting an error:
I'm at https://soju-lcd.terra.dev
code: 'CERT_HAS_EXPIRED',
config: {
url: '/bank/balances/terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v',
method: 'get',
headers: { Accept: 'application/json', 'User-Agent': 'axios/0.21.1' },
...
Thanks for your assistance.
Kind regards!
A getBorrowedLTV function would also be nice to avoid relying on calculations by the developers to get the current LTV values.
I tried to install the package.
npm i @anchor-protocol/anchor.js
then I encountered messages.
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@anchor-protocol%2fanchor.js - Not found
npm ERR! 404
npm ERR! 404 '@anchor-protocol/anchor.js@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
When I access the package in npmjs.com, they ask me to login.
But even I logged in , there is a message '404 not found'.
How can I install the anchor.js package
Or Is it not possible yet? do I have to wait for v1.x version?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.