Skip to content

Commit

Permalink
Update chaintypes with new format for Basilisk (#47)
Browse files Browse the repository at this point in the history
* Update types for basilisk

* Update chaintypes with new format for Basilisk

* NOVA_3665: switch <action>.multi to multiQuery (#40)

* Fix typo
  • Loading branch information
Asmadek authored Jan 31, 2022
1 parent 7be8ebc commit 900941f
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 121 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
DB_PASS: postgres
DB_DATABASE: postgres
DB_HOST: postgres
DB_POST: 5432
DB_PORT: 5432
volumes:
- ./:/app
command:
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"typescript": "^4.1.3",
"@subql/cli": "^0.16.2",
"@kiltprotocol/type-definitions": "^0.1.23"
},
"exports": {
"chaintypes": "./src/chaintypes.ts"
}
}
4 changes: 2 additions & 2 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ network:
genesisHash: '0xa85cfb9b9fd4d622a5b28289a02347af987d8f73fa3108450e2b4a11c1ce5755'
endpoint: wss://basilisk.api.onfinality.io/public-ws
chaintypes:
file: './src/types.json'
file: ./dist/chaintypes.js

dataSources:
- name: main
kind: substrate/Runtime
startBlock: 1
startBlock: 129442
mapping:
file: ./dist/index.js
handlers:
Expand Down
94 changes: 94 additions & 0 deletions src/chaintypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type { OverrideBundleDefinition } from '@polkadot/types/types';

/* eslint-disable sort-keys */

const definitions: OverrideBundleDefinition = {
alias: { tokens: { AccountData: 'OrmlAccountData' } },
types: [
{
// on all versions
minmax: [0, undefined],
types: {
AssetPair: { asset_in: 'AssetId', asset_out: 'AssetId' },
Amount: 'i128',
AmountOf: 'Amount',
Address: 'AccountId',
OrmlAccountData: { free: 'Balance', frozen: 'Balance', reserved: 'Balance' },
Fee: { numerator: 'u32', denominator: 'u32' },
BalanceInfo: { amount: 'Balance', assetId: 'AssetId' },
Chain: { genesisHash: 'Vec<u8>', lastBlockHash: 'Vec<u8>' },
Currency: 'AssetId',
CurrencyId: 'AssetId',
CurrencyIdOf: 'AssetId',
Intention: {
who: 'AccountId',
asset_sell: 'AssetId',
asset_buy: 'AssetId',
amount: 'Balance',
discount: 'bool',
sell_or_buy: 'IntentionType'
},
IntentionId: 'Hash',
IntentionType: { _enum: ['SELL', 'BUY'] },
LookupSource: 'AccountId',
Price: 'Balance',
ClassId: 'u64',
TokenId: 'u64',
ClassData: { is_pool: 'bool' },
TokenData: { locked: 'bool' },
ClassInfo: { metadata: 'Vec<u8>', total_issuance: 'TokenId', owner: 'AccountId', data: 'ClassData' },
TokenInfo: { metadata: 'Vec<u8>', owner: 'AccountId', data: 'TokenData' },
ClassInfoOf: 'ClassInfo',
TokenInfoOf: 'TokenInfo',
ClassIdOf: 'ClassId',
TokenIdOf: 'TokenId',
OrderedSet: 'Vec<AssetId>',
VestingSchedule: {
start: 'BlockNumber',
period: 'BlockNumber',
period_count: 'u32',
per_period: 'Compact<Balance>'
},
VestingScheduleOf: 'VestingSchedule',
LBPWeight: 'u32',
WeightCurveType: { _enum: ['Linear'] },
PoolId: 'AccountId',
BalanceOf: 'Balance',
AssetType: {
_enum: {
Token: 'Null',
PoolShare: '(AssetId,AssetId)'
}
},
Pool: {
owner: 'AccountId',
start: 'BlockNumber',
end: 'BlockNumber',
assets: 'AssetPair',
initial_weights: 'LBPWeight',
final_weights: 'LBPWeight',
weight_curve: 'WeightCurveType',
pausable: 'bool',
paused: 'bool',
fee: 'Fee',
fee_receiver: 'AccountId'
},
AssetDetails: {
name: 'Vec<u8>',
asset_type: 'AssetType',
existential_deposit: 'Balance',
locked: 'bool'
},
AssetDetailsT: 'AssetDetails',
AssetMetadata: { symbol: 'Vec<u8>', decimals: 'u8' },
AssetInstance: 'AssetInstanceV1',
MultiLocation: 'MultiLocationV1',
MultiAsset: 'MultiAssetV1',
Xcm: 'XcmV1',
XcmOrder: 'XcmOrderV1'
}
}
]
};

export default { typesBundle: { spec: { basilisk : definitions }}};
9 changes: 7 additions & 2 deletions src/mappings/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export async function cachedRewardDestination(accountAddress: string, event: Sub
return await api.query.staking.payee(accountAddress)
}

const payees = await api.query.staking.payee.multi(allAccountsInBlock);
// TODO: Commented code doesn't work now, may be fixed later
// const payees = await api.query.staking.payee.multi(allAccountsInBlock);
const payees = await api.queryMulti(allAccountsInBlock.map(account => ([api.query.staking.payee, account])));

const rewardDestinations = payees.map(payee => { return payee as RewardDestination });

let destinationByAddress: {[address: string]: RewardDestination} = {}
Expand Down Expand Up @@ -94,7 +97,9 @@ export async function cachedController(accountAddress: string, event: SubstrateE
return accountId.toString()
}

const bonded = await api.query.staking.bonded.multi(controllerNeedAccounts);
// TODO: Commented code doesn't work now, may be fixed later
// const bonded = await api.query.staking.bonded.multi(controllerNeedAccounts);
const bonded = await api.queryMulti(controllerNeedAccounts.map(account => ([api.query.staking.bonded, account])));
const controllers = bonded.map(bonded => { return bonded.toString() });

let bondedByAddress: {[address: string]: string} = {}
Expand Down
228 changes: 112 additions & 116 deletions src/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,122 +7,118 @@
},
"types": [
{
"minmax": [0, null],
"types": {
"AssetPair": {
"asset_in": "AssetId",
"asset_out": "AssetId"
},
"Amount": "i128",
"AmountOf": "Amount",
"Address": "AccountId",
"OrmlAccountData": {
"free": "Balance",
"frozen": "Balance",
"reserved": "Balance"
},
"Fee": {
"numerator": "u32",
"denominator": "u32"
},
"BalanceInfo": {
"amount": "Balance",
"assetId": "AssetId"
},
"Chain": {
"genesisHash": "Vec<u8>",
"lastBlockHash": "Vec<u8>"
},
"Currency": "AssetId",
"CurrencyId": "AssetId",
"CurrencyIdOf": "AssetId",
"Intention": {
"who": "AccountId",
"asset_sell": "AssetId",
"asset_buy": "AssetId",
"amount": "Balance",
"discount": "bool",
"sell_or_buy": "IntentionType"
},
"IntentionId": "Hash",
"IntentionType": {
"_enum": ["SELL", "BUY"]
},
"LookupSource": "AccountId",
"Price": "Balance",
"ClassId": "u64",
"TokenId": "u64",
"ClassData": {
"is_pool": "bool"
},
"TokenData": {
"locked": "bool"
},
"ClassInfo": {
"metadata": "Vec<u8>",
"total_issuance": "TokenId",
"owner": "AccountId",
"data": "ClassData"
},
"TokenInfo": {
"metadata": "Vec<u8>",
"owner": "AccountId",
"data": "TokenData"
},
"ClassInfoOf": "ClassInfo",
"TokenInfoOf": "TokenInfo",
"ClassIdOf": "ClassId",
"TokenIdOf": "TokenId",
"OrderedSet": "Vec<AssetId>",
"VestingSchedule": {
"start": "BlockNumber",
"period": "BlockNumber",
"period_count": "u32",
"per_period": "Compact<Balance>"
},
"VestingScheduleOf": "VestingSchedule",
"LBPWeight": "u32",
"WeightCurveType": {
"_enum": ["Linear"]
},
"PoolId": "AccountId",
"BalanceOf": "Balance",
"AssetType": {
"_enum": {
"Token": "Null",
"PoolShare": "(AssetId,AssetId)"
}
},
"Pool": {
"owner": "AccountId",
"start": "BlockNumber",
"end": "BlockNumber",
"assets": "AssetPair",
"initial_weights": "LBPWeight",
"final_weights": "LBPWeight",
"weight_curve": "WeightCurveType",
"pausable": "bool",
"paused": "bool",
"fee": "Fee",
"fee_receiver": "AccountId"
},
"AssetDetails": {
"name": "Vec<u8>",
"asset_type": "AssetType",
"existential_deposit": "Balance",
"locked": "bool"
},
"AssetDetailsT": "AssetDetails",
"AssetMetadata": {
"symbol": "Vec<u8>",
"decimals": "u8"
},
"AssetInstance": "AssetInstanceV1",
"MultiLocation": "MultiLocationV1",
"MultiAsset": "MultiAssetV1",
"Xcm": "XcmV1",
"XcmOrder": "XcmOrderV1"
}
"AssetPair": {
"asset_in": "AssetId",
"asset_out": "AssetId"
},
"Amount": "i128",
"AmountOf": "Amount",
"Address": "AccountId",
"OrmlAccountData": {
"free": "Balance",
"frozen": "Balance",
"reserved": "Balance"
},
"Fee": {
"numerator": "u32",
"denominator": "u32"
},
"BalanceInfo": {
"amount": "Balance",
"assetId": "AssetId"
},
"Chain": {
"genesisHash": "Vec<u8>",
"lastBlockHash": "Vec<u8>"
},
"Currency": "AssetId",
"CurrencyId": "AssetId",
"CurrencyIdOf": "AssetId",
"Intention": {
"who": "AccountId",
"asset_sell": "AssetId",
"asset_buy": "AssetId",
"amount": "Balance",
"discount": "bool",
"sell_or_buy": "IntentionType"
},
"IntentionId": "Hash",
"IntentionType": {
"_enum": ["SELL", "BUY"]
},
"LookupSource": "AccountId",
"Price": "Balance",
"ClassId": "u64",
"TokenId": "u64",
"ClassData": {
"is_pool": "bool"
},
"TokenData": {
"locked": "bool"
},
"ClassInfo": {
"metadata": "Vec<u8>",
"total_issuance": "TokenId",
"owner": "AccountId",
"data": "ClassData"
},
"TokenInfo": {
"metadata": "Vec<u8>",
"owner": "AccountId",
"data": "TokenData"
},
"ClassInfoOf": "ClassInfo",
"TokenInfoOf": "TokenInfo",
"ClassIdOf": "ClassId",
"TokenIdOf": "TokenId",
"OrderedSet": "Vec<AssetId>",
"VestingSchedule": {
"start": "BlockNumber",
"period": "BlockNumber",
"period_count": "u32",
"per_period": "Compact<Balance>"
},
"VestingScheduleOf": "VestingSchedule",
"LBPWeight": "u32",
"WeightCurveType": {
"_enum": ["Linear"]
},
"PoolId": "AccountId",
"BalanceOf": "Balance",
"AssetType": {
"_enum": {
"Token": "Null",
"PoolShare": "(AssetId,AssetId)"
}
},
"Pool": {
"owner": "AccountId",
"start": "BlockNumber",
"end": "BlockNumber",
"assets": "AssetPair",
"initial_weight": "LBPWeight",
"final_weight": "LBPWeight",
"weight_curve": "WeightCurveType",
"fee": "Fee",
"fee_collector": "AccountId"
},
"AssetDetails": {
"name": "Vec<u8>",
"asset_type": "AssetType",
"existential_deposit": "Balance",
"locked": "bool"
},
"AssetDetailsT": "AssetDetails",
"AssetMetadata": {
"symbol": "Vec<u8>",
"decimals": "u8"
},
"AssetInstance": "AssetInstanceV1",
"MultiLocation": "MultiLocationV1",
"AssetNativeLocation": "MultiLocation",
"MultiAsset": "MultiAssetV1",
"Xcm": "XcmV1",
"XcmOrder": "XcmOrderV1"
}
]
}
Expand Down

0 comments on commit 900941f

Please sign in to comment.