owned this note
owned this note
Published
Linked with GitHub
# SALP apis
###### tags: `后端` `External`
## Extrinsics
### Cross-chain transact from Kusama to Bifrost (Contributors have to cross their KSM to Bifrost for using SALP)
#### Example
```ts
const theAmount = new BigNumber(amount)
.multipliedBy(new BigNumber(1000000000000))
.toNumber()
.toFixed();
const paras = [
{
V1: {
parents: 0,
interior: {
X1: {
Parachain: getEnvs().PARACHAIN_ID,
},
},
},
},
{
V1: {
parents: 0,
interior: {
X1: {
AccountId32: {
network: 'Any',
id: u8aToHex(decodeAddress(sender)),
},
},
},
},
},
{
V1: [
{
id: {
Concrete: {
parents: 0,
interior: 'Here',
},
},
fun: {
Fungible: theAmount,
},
},
],
},
0,
];
const transferHandle = await api.tx.xcmPallet.reserveTransferAssets(...paras);
const info = await api.tx.xcmPallet.reserveTransferAssets(...paras).paymentInfo(sender);
```
### Cross-chain transact from Bifrost to Kusama (for users who want to transfer KSM back to the relay-chain)
- **api.tx.polkadotXcm.xTokens.transfer**
#### Example
```ts
const theAmount = new BigNumber(amount)
.multipliedBy(new BigNumber(1000000000000))
.toNumber()
.toFixed();
const paras = [
{
Token: 'KSM',
},
theAmount,
{
V1: {
parents: 1,
interior: {
X1: {
AccountId32: {
network: 'Any',
id: u8aToHex(decodeAddress(receiver)),
},
},
},
},
},
4000000000,
];
const transferHandle = await api.tx.xTokens.transfer(...paras);
const info = await api.tx.xTokens.transfer(...paras).paymentInfo(sender);
```
### Bifrost call `contribute`
- **api.tx.salp.contribute**:
- Authentication: User's signature address
- Parameter:
- index: ParaId; // Contribute to a paraid
- value: Balance; // The amount of `contribution`
- Description: The user calls this function to contribute to a `fund` (ongoing).
#### Example
```js=
const keyring = new Keyring({type: 'sr25519'});
const provider = new WsProvider(BIFROST_END_POINT);
const api = await ApiPromise.create(options({provider: provider}));
const sudo = keyring.addFromUri(BIFROST_SUDO_PHRASE);
const extrinsic = api.tx.salp.contribute(PARA_ID, BALANCE);
const ext_hash = await extrinsic.signAndSend(sudo);
```
### Parachain auction fail, call `refund` function manually
- **api.tx.salp.refund**:
- Authentication: User's signature address
- Parameter:
- index: ParaId; // The paraId needs to refund
- Description: When the `fund` fails and the funds have been withdrawable, the user can redeem the contributed funds with the locked `vsToken/vsBond`.
#### Example
![](https://hackmd.io/_uploads/HJrodvgft.png)
### Call the `redeem` function when parachain fund retired.
- **api.tx.salp.redeem**:
- Authentication: User's signature address
- Parameter:
- index: ParaId; // vsbond Parameter: paraId
- value: Balance; // redeem amount
- Description: When the user holds the `vsbond` that reaches the redemption period, the combination of `vsbond` + `vsToken` can be used to redeem the underlaying KSM, which will be sent to the user's address on relay chain.
#### Example
![](https://hackmd.io/_uploads/rydaOvxzY.png)
## Storage
### Query for Bifrost `assets`
- **api.query.tokens.accounts**:
- Parameter:
- 0: AccountId; // query the address
- 1: CurrencyId; // type of assets
- Description: Query an address's assets amount.
### Query vsKSM,vsBond total issuance
- **api.query.tokens.totalIssuance**:
- Parameter:
- 0: CurrencyId; // type of assets
- Description: Query assets amount of a paraId.
### Query a specific fund info
- **api.query.salp.funds**:
- Parameter:
- 0: ParaId; // Parachain ID
- Description: Query the fund info of a paraId.
### Query the contribution info of a user
- rpc interface
- Parameter:
- 0: ParaId; // Parachain ID
- 1: AccountId; //ss58 account address
- Description: Query the contribution info of an user.
```
curl http://localhost:29999 -H "Content-Type:application/json;charset=utf-8" -d '{"jsonrpc":"2.0","id":1,"method":"salp_getContribution","params": [2001, "Hsjp321vR7quo4ETVyuUFbrJMddW7K7qPndtxCZHzY1CCHA"]}'`
```
# bifrost-service
>https://bifrost-service.bifrost.finance/graphql
### salp_contributed
- graphql API
- Parameter:
- account; //ss58 bifrost account address
- para_id; //ParaId
- Description:Query the contribution details, help to distribute crowdloan reward.
**Kusama SALP Quary**
```graphql=
query {
salp_contributed(
para_id:"2088"
){
para_id
balance
account
block_timestamp
block_height
event_id
extrinsic_id
extrinsic_hash
}
}
```
**Polkadot SALP Quary**
```graphql=
query b{
polkadot_contribute_reward(
para_id:"2004"
)
{
para_id
contribution
account
block_timestamp
block_height
inviter
invitee
total_reward
invitation_reward
basic_reward
eth_address
}
}
```