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: StableSwap Algorithm #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .ralph-lsp/ralph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contractPath": ""
}
13 changes: 13 additions & 0 deletions stableswap/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EditorConfig is awesome: https://EditorConfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = false

[*.ral]
indent_size = 4
1 change: 1 addition & 0 deletions stableswap/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ral linguist-language=Rust
3 changes: 3 additions & 0 deletions stableswap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/

.ralph-lsp
62 changes: 62 additions & 0 deletions stableswap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# My React dApp

This template monorepo was designed to provide a developer-friendly experience to Alephium ecosystem newcomers. It is split into 2 parts:

- app: contains the React frontend part of the dApp
- contracts: contains the dApp contracts

It uses **yarn workspaces** to manage both app and contract projects from the monorepo root.

## Local development

To get started quickly, follow these steps:

### Set up a devnet

Start a local devnet for testing and development. Please refer to the [Getting Started documentation](https://docs.alephium.org/full-node/getting-started#devnet).

### Install dependencies

```
yarn install
```

### Compile the contracts

```
yarn compile
```

### Deploy the contracts

```
yarn deploy
```

### Build the contracts package

```
yarn build:contracts
```

### Run the app

```
yarn start
```

### Install an Alephium wallet

Download an [Alephium wallet](https://alephium.org/#wallets), and connect it to your devnet dApp.

## Testnet, Mainnet, and More

You could use yarn workspace to run commands in the contracts or app directory.

```
yarn <my-contracts|my-dapp> <command>
```

You could also get some testnet tokens from the [Faucet](https://docs.alephium.org/infrastructure/public-services/#testnet-faucet).

To learn more about smart contract development on Alephium, take a look at the [documentation](https://docs.alephium.org/dapps/).
2 changes: 2 additions & 0 deletions stableswap/contracts/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/dist/
**/templates/
16 changes: 16 additions & 0 deletions stableswap/contracts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": [
"prettier",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"header/header": ["off"]
},
"parserOptions": {
"project": "tsconfig.json",
"ecmaVersion": 2020,
"sourceType": "module"
},
"parser": "@typescript-eslint/parser"
}
15 changes: 15 additions & 0 deletions stableswap/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# misc
.DS_Store
*.pem

.ralph-lsp

dist/
21 changes: 21 additions & 0 deletions stableswap/contracts/.project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"fullNodeVersion": "v3.8.5",
"compilerOptionsUsed": {
"ignoreUnusedConstantsWarnings": false,
"ignoreUnusedVariablesWarnings": false,
"ignoreUnusedFieldsWarnings": false,
"ignoreUnusedPrivateFunctionsWarnings": false,
"ignoreUpdateFieldsCheckWarnings": false,
"ignoreCheckExternalCallerWarnings": false,
"ignoreUnusedFunctionReturnWarnings": false,
"skipAbstractContractCheck": false
},
"infos": {
"StableSwap": {
"sourceFile": "token.ral",
"sourceCodeHash": "ff5df47d3ff020aab77153a2a34a9769102d343c96ab5e36279abd1f1d2cb402",
"bytecodeDebugPatch": "",
"codeHashDebug": "f2e7f01c2c27781486310a479aa6977e1af238f4be92e4810bc3ce84ade5b24b"
}
}
}
3 changes: 3 additions & 0 deletions stableswap/contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# My dApp Template

This package contains the contracts for the dApp.
34 changes: 34 additions & 0 deletions stableswap/contracts/alephium.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Configuration } from '@alephium/cli'
import { Number256 } from '@alephium/web3'

// Settings are usually for configuring
export type Settings = {
issueTokenAmount: Number256
}
const defaultSettings: Settings = { issueTokenAmount: 100n }

const configuration: Configuration<Settings> = {
networks: {
devnet: {
nodeUrl: 'http://127.0.0.1:22973',
privateKeys: [
'a642942e67258589cd2b1822c631506632db5a12aabcf413604e785300d762a5', // group 0
],
settings: defaultSettings
},

testnet: {
nodeUrl: (process.env.NODE_URL as string) ?? 'https://node.testnet.alephium.org',
privateKeys: process.env.PRIVATE_KEYS === undefined ? [] : process.env.PRIVATE_KEYS.split(','),
settings: defaultSettings
},

mainnet: {
nodeUrl: (process.env.NODE_URL as string) ?? 'https://node.mainnet.alephium.org',
privateKeys: process.env.PRIVATE_KEYS === undefined ? [] : process.env.PRIVATE_KEYS.split(','),
settings: defaultSettings
}
}
}

export default configuration
156 changes: 156 additions & 0 deletions stableswap/contracts/artifacts/StableSwap.ral.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"version": "v3.8.5",
"name": "StableSwap",
"bytecode": "0a054059411642304281437001000004014031d317baf705ce031700ce011701561600314c4026ce001702ce02170316011602334c0f1602160116022b5616032b2c160016032b2d2a024a0e1602160216012b5616032b2c160016032b2d2b024a021601020000040c0140780c17040c170516050f314c0e160416057a0f314d782a170416050d2a17054a2e16040c2f4c020c020c17061604170716030f2c17080c170916091340ff314c404c1607170a0c170b160b0f314c12160a16072c160b7a0f314d780f2c2d170a160b0d2a170b4a2a16071706160816042c160a0f2c2a16072c16080d2b16072c0f0d2a160a2c2a2d170716071606334c09160716062b0d324c021607024a08160616072b0d324c0216070216090d2a17094a7fb0160702010006110140acd3bc14be25160016013116001601331b0d7b16010c340d7b16010f310d7b16000c340d7b16000f310d7b00001706160316041605160600011707160717080c170916060f2c170a0c170b0c170c160c0f314c4032160c16002f4c0f1602170b1609160b2a1709160816072c160b0f2c2d17084a1a160c1601304c16160c7a0f314d0f2a78170b1609160b2a1709160816072c160b0f2c2d17084a00160c0d2a170c4a7fca160816072c160a0f2c2d170816091607160a2d2a170d0c170e1607170f0c171016101340ff314c402a160f170e160f160f2c16082a0e160f2c160d2a16072b2d170f160f160e334c09160f160e2b0d324c02160f024a08160e160f2b0d324c02160f0216100d2a17104a7fd2160f020000030703402ece04ce05ce061705170417030c170616060f314c1e16067a0f314d0f2a7816067a0f314d782c13c40de0b6b3a76400002d16067a0f314d0f2a7916060d2a17064a7fde160316041605020100041301408bd34df2a033130a1307831704a000a001a0021707170617051605160616070003170a170917081602170b16007a0f314d13082a78160b16007a0f314d102acf2c13c40de0b6b3a76400002d2a170c16001601160c16081609160a0002170d16017a0f314d13082a78160d2b0d2b170e160e16042c13c102540be4002d170f160e160f2b13c40de0b6b3a76400002c16017a0f314d102acf2d170e160e1603340d7b16051606160717121711171016007a0f314d112a78160b2a16007a0f314d13102a7916017a0f314d112a78160e2b16017a0f314d13102a79161016111612a102a101a100160e02",
"codeHash": "f2e7f01c2c27781486310a479aa6977e1af238f4be92e4810bc3ce84ade5b24b",
"fieldsSig": {
"names": [
"initialA",
"futureA",
"initialATime",
"futureATime",
"balances",
"rates"
],
"types": [
"U256",
"U256",
"U256",
"U256",
"[U256;3]",
"[U256;3]"
],
"isMutable": [
false,
false,
false,
false,
true,
false
]
},
"eventsSig": [],
"functions": [
{
"name": "getA",
"paramNames": [],
"paramTypes": [],
"paramIsMutable": [],
"returnTypes": [
"U256"
]
},
{
"name": "getD",
"paramNames": [
"xp",
"amp"
],
"paramTypes": [
"[U256;3]",
"U256"
],
"paramIsMutable": [
false,
false
],
"returnTypes": [
"U256"
]
},
{
"name": "getY",
"paramNames": [
"i",
"j",
"x",
"xp"
],
"paramTypes": [
"U256",
"U256",
"U256",
"[U256;3]"
],
"paramIsMutable": [
false,
false,
false,
false
],
"returnTypes": [
"U256"
]
},
{
"name": "xp",
"paramNames": [
"pBalances"
],
"paramTypes": [
"[U256;3]"
],
"paramIsMutable": [
false
],
"returnTypes": [
"[U256;3]"
]
},
{
"name": "exchange",
"paramNames": [
"i",
"j",
"dx",
"min_dy"
],
"paramTypes": [
"U256",
"U256",
"U256",
"U256"
],
"paramIsMutable": [
false,
false,
false,
false
],
"returnTypes": [
"U256"
]
}
],
"constants": [
{
"name": "N_COINS",
"value": {
"type": "U256",
"value": "3"
}
},
{
"name": "FEE_DENOMINATOR",
"value": {
"type": "U256",
"value": "10000000000"
}
},
{
"name": "LENDING_PRECISION",
"value": {
"type": "U256",
"value": "1000000000000000000"
}
},
{
"name": "PRECISION",
"value": {
"type": "U256",
"value": "1000000000000000000"
}
}
],
"enums": []
}
Loading