Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat AMM #604

Merged
merged 104 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
d5ba331
wip: feat(amm): initial methods
peterslany Jan 3, 2023
03cced6
wip: feat(amm): start working on router
peterslany Jan 4, 2023
50cf899
wip: feat(amm): complete recursive search for best trading path, crea…
peterslany Jan 5, 2023
3f00c87
wip: feat(amm): complete stable pool and middle price computation, ad…
peterslany Jan 6, 2023
f3a3751
refactor: cleanup
peterslany Jan 6, 2023
0bf729e
feat(amm): add AMM to main api
peterslany Jan 9, 2023
1fb4afd
wip: feat(amm): add stable pool
peterslany Jan 9, 2023
b87c532
fix: fix imports
peterslany Jan 11, 2023
b6a1b30
wip: feat(amm): stable pools
peterslany Jan 11, 2023
94086ba
wip: feat(amm): stable pool
peterslany Jan 12, 2023
1fe7637
feat(amm): finalize trading pairs for stable pool
peterslany Jan 13, 2023
ffbb560
feat(amm): define methods to get all pool data
peterslany Jan 16, 2023
c84e31f
wip: feat(amm): initial methods
peterslany Jan 3, 2023
413fda1
wip: feat(amm): start working on router
peterslany Jan 4, 2023
f48571a
wip: feat(amm): complete recursive search for best trading path, crea…
peterslany Jan 5, 2023
7b8193e
chore: fix imports
peterslany Jan 16, 2023
c638c79
refactor: update according to code review
peterslany Jan 17, 2023
e59fe3a
Merge pull request #525 from peterslany/peter/amm-feat-pools-and-swap
peterslany Jan 17, 2023
f836570
chore: update types
peterslany Jan 18, 2023
722b093
chore: cleanup
peterslany Jan 18, 2023
3f6fa63
fix: rename lib LpToken -> LpCurrency
peterslany Jan 18, 2023
eeea777
Merge pull request #537 from peterslany/peter/amm-fix-lptoken-name
peterslany Jan 18, 2023
e1edfa1
feat(amm): add swap extrinsic
peterslany Jan 18, 2023
5621a19
fix: wait for tx inclusion only
peterslany Jan 18, 2023
15a09f2
refactor: move currency factories out from parachain modules
peterslany Jan 18, 2023
bbfe73b
wip: refactor currencies
peterslany Jan 18, 2023
9949484
feat(amm): add lp token currencies and refactor currencyIdToMonetaryC…
peterslany Jan 19, 2023
8d80e7a
refactor: strenghten types
peterslany Jan 19, 2023
30730c9
Merge pull request #539 from peterslany/peter/amm-feat-swap-extrinsic
peterslany Jan 19, 2023
2e3ffe4
Merge branch 'wip-feat-amm' into peter/amm-feat-add-lptoken-currency-…
peterslany Jan 19, 2023
4a339ec
feat(amm): implement or mock all methods for getting pool data
peterslany Jan 19, 2023
61c1193
refactor: change pool balance from transferable to free
peterslany Jan 20, 2023
e246136
fix: add proper NumberOrHex decoding for A parameter
peterslany Jan 20, 2023
3782d76
Merge pull request #541 from peterslany/peter/amm-implement-pool-methods
peterslany Jan 20, 2023
216121b
Merge branch 'wip-feat-amm' into peter/amm-feat-add-lptoken-currency-…
peterslany Jan 20, 2023
9edf0f8
wip feat(amm): add liquidity calculations to standard pool
peterslany Jan 20, 2023
ad84500
fix(amm): fix negated condition
peterslany Jan 20, 2023
fcf6ada
feat(amm): add unified liquidity deposit/withdrawal calculations
peterslany Jan 23, 2023
e098c02
Merge pull request #544 from peterslany/peter/amm-calculate-liquidity…
peterslany Jan 23, 2023
a39f555
Merge pull request #540 from peterslany/peter/amm-feat-add-lptoken-cu…
peterslany Jan 23, 2023
2d7de48
chore: fix imports
peterslany Jan 23, 2023
8f9400e
fix(amm): correct computation of getD
peterslany Jan 23, 2023
b5568a5
fix: hotfix getA
peterslany Jan 23, 2023
a5b9b9d
wip: feat: add liquidity extrinsic
peterslany Jan 23, 2023
9dc0115
feat(amm): add methods to add/remove liquidity, add metapools support
peterslany Jan 24, 2023
e614405
refactor(amm): check for empty values before unwrapping and rename A
peterslany Jan 24, 2023
5bb9e9c
Merge pull request #547 from peterslany/peter/amm-implement-liquidity…
peterslany Jan 24, 2023
1f5b006
refactor(amm): use futureA for stable pool amplification coefficient …
peterslany Jan 24, 2023
6294707
feat(amm): add getter for account owned liquidity
peterslany Jan 24, 2023
904725f
Merge pull request #548 from peterslany/peter/amm-get-account-liquidity
peterslany Jan 24, 2023
63235bd
Merge branch 'master' into wip-feat-amm
peterslany Jan 25, 2023
a1f6d29
chore: update types version
peterslany Jan 25, 2023
f9b8538
fix(amm): use correct type decoding
peterslany Jan 25, 2023
e9e6430
fix(amm): discard zero liquidity pools
peterslany Jan 25, 2023
0fac87f
fix(amm): correct error condition
peterslany Jan 25, 2023
bc5fa87
fix(amm): encode swap params atomic values to integers
peterslany Jan 25, 2023
7dd664e
chore: tag amm branch with version
peterslany Jan 26, 2023
3ed3fde
fix(amm): improve calculations for stable pools
peterslany Jan 27, 2023
13f1eea
fix(amm): use correct string decoding
peterslany Jan 30, 2023
8b43ff8
fix(amm): use price impact computation for stable pools based on curv…
peterslany Jan 31, 2023
994d11e
Merge pull request #555 from peterslany/peter/amm-fix-stable-pools-pr…
peterslany Feb 1, 2023
8fe5108
chore: parachain update to 1.21.5
peterslany Feb 2, 2023
c640a6c
fix(amm): correct decoding of fees and small cleanups
peterslany Feb 3, 2023
4a50970
Merge pull request #557 from peterslany/peter/chore-update-parachain-…
peterslany Feb 3, 2023
1449966
Merge pull request #558 from peterslany/peter/amm-fee-decoding
peterslany Feb 3, 2023
1501fdf
chore: bump lib -> 0.32.3
peterslany Feb 3, 2023
d51d252
chore: upgrade to parachain 1.21.7
peterslany Feb 7, 2023
5920748
Merge pull request #560 from peterslany/peter/chore-update-metadata-1…
peterslany Feb 7, 2023
bd56f74
wip
peterslany Feb 7, 2023
91c9801
feat(amm): add farming extrinsics and computation
peterslany Feb 7, 2023
e19c15e
chore: bump version
peterslany Feb 8, 2023
be0338f
Merge pull request #561 from peterslany/peter/amm-add-farming
peterslany Feb 8, 2023
96dd175
fix(amm): update standard pool fee denominator
peterslany Feb 8, 2023
45d1c2b
chore: update monetary to 0.7.2
peterslany Feb 8, 2023
67a3c67
fix(amm): fix farming computations
peterslany Feb 8, 2023
86efc53
fix: don't throw in farming rewards computation for pools without liq…
peterslany Feb 10, 2023
4942352
Merge branch 'master' into wip-feat-amm
peterslany Feb 16, 2023
f5647b5
feat(loans): add supply and borrow caps
peterslany Feb 15, 2023
d40a87a
Merge pull request #566 from peterslany/peter/loans-add-loan-caps
peterslany Feb 16, 2023
8519666
feat(loans): add price fetching from chain oracle
peterslany Feb 23, 2023
5971953
chore: bump version
peterslany Feb 23, 2023
0a00e7b
fix: handle wrapped currency exchange rate
peterslany Feb 28, 2023
49ef31e
feat(loans): add tests for collateral info and fix incorrect threshol…
peterslany Feb 28, 2023
8edb490
refactor: code review
peterslany Mar 2, 2023
12a62c6
refactor(loans): update with code review, fix conversion to btc amount
peterslany Mar 7, 2023
b94e22b
Merge pull request #571 from peterslany/peter/loans-feat-fetch-prices…
daniel-savu Mar 7, 2023
dd27d15
Merge branch 'master' into wip-feat-amm
peterslany Mar 8, 2023
2cf2b17
fix: change invalid import of newMonetaryAmount
peterslany Mar 9, 2023
bf8c2fc
refactor: code review
peterslany Mar 9, 2023
fb53f5a
Update test/utils/helpers.ts
peterslany Mar 9, 2023
e1c24eb
Merge branch 'master' into wip-feat-amm
peterslany Mar 9, 2023
1a1881c
fix: failing imports
daniel-savu Mar 10, 2023
6234771
chore: reuse docker-compose anchor
daniel-savu Mar 10, 2023
ce490c5
Merge branch 'master' into wip-feat-amm
daniel-savu Mar 10, 2023
8862ce9
fix(amm): fix imports in amm modules
peterslany Mar 13, 2023
4f0e9dd
chore: reuse docker-compose anchor
daniel-savu Mar 10, 2023
4c61256
chore: bump package version to 1.21.1
gregdhill Mar 9, 2023
8e6e8c1
chore: bump parachain to 1.22.0
gregdhill Mar 9, 2023
4dcea5f
chore: bump package version to 1.22.0
gregdhill Mar 9, 2023
bc2ab9f
chore: reduce or remove most extended timeouts
gregdhill Mar 10, 2023
9db4b9f
fix(amm): remove circular dependency in amm modules imports
peterslany Mar 13, 2023
ca79100
chore: remove duplicate wrapped currency getter
peterslany Mar 13, 2023
519ab0b
chore: bump to version 2.0.0
peterslany Mar 13, 2023
fbd3ff4
chore: fix amm files export
peterslany Mar 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ services:
- --auto-register=KINT=180000000000000
- --btc-parachain-url=ws://interbtc:9944
- --bitcoin-relay-start-height=1
environment: &client-env
BITCOIN_RPC_URL: http://bitcoind:18443
BITCOIN_RPC_USER: rpcuser
BITCOIN_RPC_PASS: rpcpassword
RUST_LOG: info
environment: *client-env
volumes:
- ./docker/vault_2-keyfile.json:/keyfile.json
vault_3:
Expand All @@ -107,10 +103,6 @@ services:
- --auto-register=KINT=180000000000000
- --btc-parachain-url=ws://interbtc:9944
- --bitcoin-relay-start-height=1
environment: &client-env
BITCOIN_RPC_URL: http://bitcoind:18443
BITCOIN_RPC_USER: rpcuser
BITCOIN_RPC_PASS: rpcpassword
RUST_LOG: info
environment: *client-env
volumes:
- ./docker/vault_3-keyfile.json:/keyfile.json
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/interbtc-api",
"version": "1.22.0",
"version": "2.0.0",
"description": "JavaScript library to interact with interBTC",
"main": "build/src/index.js",
"typings": "build/src/index.d.ts",
Expand Down Expand Up @@ -53,8 +53,8 @@
"engineStrict": true,
"dependencies": {
"@interlay/esplora-btc-api": "0.4.0",
"@interlay/interbtc-types": "1.11.2",
"@interlay/monetary-js": "0.7.0",
"@interlay/interbtc-types": "1.12.0",
"@interlay/monetary-js": "0.7.2",
"@polkadot/api": "9.11.1",
"big.js": "6.1.1",
"bitcoin-core": "^3.0.0",
Expand Down
36 changes: 16 additions & 20 deletions src/interbtc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import {
DefaultLoansAPI,
EscrowAPI,
LoansAPI,
tokenSymbolToCurrency,
} from ".";
import {
tokenSymbolToCurrency
} from "./utils";
import { AssetRegistryAPI } from "./parachain/asset-registry";
import { AMMAPI, DefaultAMMAPI } from "./parachain/amm";

export * from "./factory";
export * from "./parachain/transaction";
Expand Down Expand Up @@ -62,6 +65,7 @@ export interface InterBtcApi {
readonly escrow: EscrowAPI;
readonly assetRegistry: AssetRegistryAPI;
readonly loans: LoansAPI;
readonly amm: AMMAPI;
setAccount(account: AddressOrPair, signer?: Signer): void;
removeAccount(): void;
readonly account: AddressOrPair | undefined;
Expand Down Expand Up @@ -90,6 +94,7 @@ export class DefaultInterBtcApi implements InterBtcApi {
public readonly escrow: EscrowAPI;
public readonly assetRegistry: AssetRegistryAPI;
public readonly loans: LoansAPI;
public readonly amm: AMMAPI;
private transactionAPI: TransactionAPI;

constructor(
Expand All @@ -106,12 +111,12 @@ export class DefaultInterBtcApi implements InterBtcApi {
this.transactionAPI = new DefaultTransactionAPI(api, _account);

this.assetRegistry = new DefaultAssetRegistryAPI(api);
this.loans = new DefaultLoansAPI(api, wrappedCurrency, this.assetRegistry, this.transactionAPI);
this.oracle = new DefaultOracleAPI(api, wrappedCurrency, this.transactionAPI);
this.loans = new DefaultLoansAPI(api, wrappedCurrency, this.transactionAPI, this.oracle);
this.tokens = new DefaultTokensAPI(api, this.transactionAPI);
this.system = new DefaultSystemAPI(api, this.transactionAPI);
this.oracle = new DefaultOracleAPI(api, wrappedCurrency, this.transactionAPI);
this.fee = new DefaultFeeAPI(api, this.oracle, this.assetRegistry, this.loans);
this.rewards = new DefaultRewardsAPI(api, wrappedCurrency, this.transactionAPI, this.assetRegistry, this.loans);
this.fee = new DefaultFeeAPI(api, this.oracle);
this.rewards = new DefaultRewardsAPI(api, wrappedCurrency, this.transactionAPI);
this.escrow = new DefaultEscrowAPI(api, governanceCurrency, this.system, this.transactionAPI);

this.vaults = new DefaultVaultsAPI(
Expand All @@ -124,9 +129,7 @@ export class DefaultInterBtcApi implements InterBtcApi {
this.fee,
this.rewards,
this.system,
this.transactionAPI,
this.assetRegistry,
this.loans
this.transactionAPI
);
this.faucet = new FaucetClient(api, "");
this.btcRelay = new DefaultBTCRelayAPI(api);
Expand All @@ -137,9 +140,7 @@ export class DefaultInterBtcApi implements InterBtcApi {
this.electrsAPI,
wrappedCurrency,
this.fee,
this.transactionAPI,
this.assetRegistry,
this.loans
this.transactionAPI
);
this.issue = new DefaultIssueAPI(
api,
Expand All @@ -148,9 +149,7 @@ export class DefaultInterBtcApi implements InterBtcApi {
wrappedCurrency,
this.fee,
this.vaults,
this.transactionAPI,
this.assetRegistry,
this.loans
this.transactionAPI
);
this.redeem = new DefaultRedeemAPI(
api,
Expand All @@ -160,19 +159,16 @@ export class DefaultInterBtcApi implements InterBtcApi {
this.vaults,
this.oracle,
this.transactionAPI,
this.assetRegistry,
this.system,
this.loans
this.system
);
this.nomination = new DefaultNominationAPI(
api,
wrappedCurrency,
this.vaults,
this.rewards,
this.transactionAPI,
this.assetRegistry,
this.loans
this.transactionAPI
);
this.amm = new DefaultAMMAPI(api, this.tokens, this.transactionAPI);
}

setAccount(account: AddressOrPair, signer?: Signer): void {
Expand Down
2 changes: 1 addition & 1 deletion src/json/parachain.json

Large diffs are not rendered by default.

Loading