Skip to content

Commit 3db3a23

Browse files
authored
Merge pull request #149 from AbstractSDK/adair/abstraxion-utils
Abstraxion Utils for building on XION
2 parents 6c15e2b + 9d7e351 commit 3db3a23

39 files changed

+1408
-119
lines changed

.changeset/breezy-dodos-hear.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@abstract-money/actions-xion": patch
3+
"@abstract-money/core": patch
4+
"@abstract-money/cosmwasm-utils": patch
5+
"@abstract-money/provider-xion": patch
6+
---
7+
8+
Add Abtsraxion utils for building on xion, including new wallet and client actions. Publicize more types from core

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@
4242
"tsup": "^8.0.0",
4343
"turbo": "1.10.9",
4444
"tsx": "^4.7.1",
45-
4645
"typescript": "^5.0.4"
4746
},
4847
"simple-git-hooks": {
4948
"pre-commit": "pnpm format && pnpm lint:fix && git add -u"
5049
},
50+
"pnpm": {
51+
"patchedDependencies": {
52+
"@cosmjs/[email protected]": "patches/@[email protected]",
53+
"@cosmjs/[email protected]": "patches/@[email protected]",
54+
"@usecapsule/[email protected]": "patches/@[email protected]",
55+
"@cosmjs/[email protected]": "patches/@[email protected]"
56+
}
57+
},
5158
"packageManager": "[email protected]",
5259
"dependencies": {
5360
"happy-dom": "^13.3.8",

packages/actions-xion/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Generated file. Do not edit directly.
2+
actions/**
3+
decorators/**

packages/actions-xion/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @abstract-money/actions-xion

packages/actions-xion/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024, Abstract Money
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/actions-xion/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# XION Actions
2+
3+
> Abstract.js actions for interacting with XION
4+
5+
## Install
6+
7+
```bash
8+
npm install --save @abstract-money/actions-xion
9+
```
10+
11+
## Usage
12+
13+
## License
14+
15+
MIT © [adairrr](https://github.com/adairrr)

packages/actions-xion/package.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "@abstract-money/actions-xion",
3+
"version": "0.0.1",
4+
"description": "Abstraxion utils",
5+
"author": "adairrr <[email protected]>",
6+
"license": "MIT",
7+
"repository": "",
8+
"engines": {
9+
"node": ">=10"
10+
},
11+
"type": "module",
12+
"scripts": {
13+
"build": "tsup",
14+
"clean": "rimraf dist",
15+
"typecheck": "tsc --noEmit"
16+
},
17+
"dependencies": {
18+
"@cosmjs/encoding": "0.32.3",
19+
"@cosmjs/stargate": "0.32.3",
20+
"@cosmjs/proto-signing": "0.32.3",
21+
"@cosmjs/tendermint-rpc": "0.32.3",
22+
"@cosmjs/cosmwasm-stargate": "0.32.3",
23+
"@cosmjs/math": "0.32.3",
24+
"protobufjs": "^7.4.0",
25+
"long": "^5.2.3",
26+
"type-fest": "^4.2.6",
27+
"@abstract-money/core": "workspace:*"
28+
},
29+
"peerDependenciesMeta": {
30+
"typescript": {
31+
"optional": true
32+
}
33+
},
34+
"peerDependencies": {
35+
"typescript": ">=5.0.4"
36+
},
37+
"devDependencies": {
38+
"rimraf": "^3.0.0",
39+
"@types/node": "^20.0.0"
40+
},
41+
"main": "./dist/index.js",
42+
"types": "./dist/index.d.ts",
43+
"exports": {
44+
".": {
45+
"types": "./dist/index.d.ts",
46+
"default": "./dist/index.js"
47+
},
48+
"./actions": {
49+
"types": "./dist/actions/index.d.ts",
50+
"default": "./dist/actions/index.js"
51+
},
52+
"./decorators": {
53+
"types": "./dist/decorators/index.d.ts",
54+
"default": "./dist/decorators/index.js"
55+
},
56+
"./package.json": "./package.json"
57+
},
58+
"files": [
59+
"/actions",
60+
"/decorators",
61+
"/dist"
62+
],
63+
"sideEffects": false
64+
}

packages/actions-xion/src/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024, Abstract Money
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './public'
2+
export * from './wallet'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {
2+
AccountQueryClient,
3+
RegistryTypes,
4+
} from '@abstract-money/core/codegen/abstract'
5+
import { getRegistryQueryClientFromApi } from '@abstract-money/core/src/actions'
6+
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
7+
import { predictXionAccountIdByExternalOwner } from './predict-xion-account-id-by-external-owner'
8+
9+
interface XionAbstractAccountByOwner {
10+
cosmWasmClient: CosmWasmClient
11+
apiUrl: string
12+
owner: string
13+
}
14+
15+
/**
16+
* @unstable
17+
* @param cosmWasmClient
18+
* @param owner
19+
* @param apiUrl
20+
* @param rpcEndpoint
21+
*/
22+
export async function getXionAccountByExternalOwner({
23+
cosmWasmClient,
24+
owner,
25+
apiUrl,
26+
}: XionAbstractAccountByOwner): Promise<
27+
{ client: AccountQueryClient; accountId: RegistryTypes.AccountId } | undefined
28+
> {
29+
const registryQueryClient = await getRegistryQueryClientFromApi({
30+
cosmWasmClient,
31+
apiUrl,
32+
})
33+
34+
try {
35+
const accountId = await predictXionAccountIdByExternalOwner({
36+
owner,
37+
cosmWasmClient,
38+
})
39+
40+
const { accounts } = await registryQueryClient.accounts({
41+
accountIds: [accountId],
42+
})
43+
44+
if (accounts.length > 0) {
45+
const client = new AccountQueryClient(
46+
registryQueryClient.client,
47+
accounts[0]!,
48+
)
49+
return {
50+
client,
51+
accountId,
52+
}
53+
}
54+
} catch (e) {
55+
console.debug('Error getting account by owner', e)
56+
return undefined
57+
}
58+
return undefined
59+
}

0 commit comments

Comments
 (0)