Skip to content

Commit

Permalink
Cede store new implementation (#1804)
Browse files Browse the repository at this point in the history
* feat: cede store new implementation

* fix: version fix and changing mocked chain to the existing one

* feat: cede-store-provider-upgrade-1.0.3

* fix: remove yarn.lock files

* Format and yarn it

* Revert deletion of yarn.lock from demo

---------

Co-authored-by: Mathieu <[email protected]>
Co-authored-by: Nikita TEREKHOV <[email protected]>
Co-authored-by: Adam Carpenter <[email protected]>
  • Loading branch information
4 people authored Jul 13, 2023
1 parent 894d886 commit 2f3fd79
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 34 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"type": "module",
"dependencies": {
"@web3-onboard/blocto": "^2.0.0",
"@web3-onboard/cede-store": "^2.0.2",
"@web3-onboard/cede-store": "^2.1.0-alpha.1",
"@web3-onboard/coinbase": "^2.2.5-alpha.1",
"@web3-onboard/core": "^2.20.4",
"@web3-onboard/dcent": "^2.2.7",
Expand Down
26 changes: 15 additions & 11 deletions packages/cede-store/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ console.log(connectedWallets)

## Vault management

Vaults allow creating bundles of CEX accounts. The extension connects with CEX through CEX API keys and everything is stored in the Local Storage of the browser, on a mobile or on a Ledger (more coming soon...). We can compare Vaults with the [Keyring concept](https://www.wispwisp.com/index.php/2020/12/25/how-metamask-stores-your-wallet-secret/) of Metamask.
Vaults allow creating bundles of CEX accounts. The extension connects with CEX through CEX API keys and everything is stored in the Local Storage of the browser. Mobile and Ledger storage are coming soon.
We can compare Vaults with the [Keyring concept](https://www.wispwisp.com/index.php/2020/12/25/how-metamask-stores-your-wallet-secret/) of
Metamask.

A user can have multiple vaults with different CEX accounts inside.
This system allows the user to give a dApp custom access to his accounts depending on the degree of trust he has in the dApp in question.
A user can have multiple vaults with different CEX accounts inside. This system allows the user to give a dApp custom
access to his accounts depending on the degree of trust he has in the dApp in question.

Let's say the user has three vaults: a main one with full access (track, trade, withdraw) to all his CEX, one just for tracking and one just for trading.
If the user does not know the reputation of the dApp he is using, the most logical solution would be to give access
only to the tracking vault so the dApp will not be able to initiate trade requests.
Let's say the user has three vaults: a main one with full access (track, trade, withdraw) to all his CEX, one just for
tracking and one just for trading. If the user does not know the reputation of the dApp he is using, the most logical
solution would be to give access only to the tracking vault so the dApp will not be able to initiate trade requests.

## CEX connection

Expand All @@ -47,17 +49,19 @@ All requests are divided into two categories:
- private requests
- public requests

All public data, such as prices, volumes, historical data are collected from different exchanges and
provided with our API.
All public data, such as prices, volumes, historical data are collected from different exchanges and streamed in real
time through our API.

All private requests, such as user balances, trades, open positions are coming from cede.store (from the user's machine).
All private requests, such as user balances, trades, open positions are coming from cede.store (from the user's
machine).

You can access both public and private data through the extension's API. cede.store handles all exchanges requests, as well as API keys secure storage.
You can access both public and private data through the extension's API. Cede.store handles all exchanges requests, as
well as API keys secure storage.

## Example of a workflow (fetch user's balances and transactions)

```typescript
// get available vaults and accounts
// Get available vaults and accounts
const { vaultPreview } = provider.getVaultPreviews()
console.log(vaultPreview)

Expand Down
4 changes: 2 additions & 2 deletions packages/cede-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/cede-store",
"version": "2.0.2",
"version": "2.1.0-alpha.1",
"description": "cede.store SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
"keywords": [
"Ethereum",
Expand Down Expand Up @@ -69,7 +69,7 @@
"window": "^4.2.7"
},
"dependencies": {
"@cedelabs/providers": "^0.0.7",
"@cedelabs/providers": "^1.1.0",
"@web3-onboard/common": "^2.3.3"
}
}
22 changes: 12 additions & 10 deletions packages/cede-store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { detectCedeProvider } from '@cedelabs/providers'
import { CedeProvider, detectCedeProvider } from '@cedelabs/providers'
import type { WalletInit } from '@web3-onboard/common'
import { createEIP1193Provider } from '@web3-onboard/common'
import { CustomWindow } from './types'
declare const window: CustomWindow

type CustomWindow = typeof window & {
cede: CedeProvider
}

function cedeStoreWallet(): WalletInit {
if (typeof window === 'undefined') return () => null
Expand All @@ -12,7 +14,7 @@ function cedeStoreWallet(): WalletInit {
checkProviderIdentity: () => (window as CustomWindow).cede,
getIcon: async () => (await import('./icon.js')).default,
getInterface: async () => {
const provider: any = await detectCedeProvider()
const provider = await detectCedeProvider()
if (!provider) {
window.open('https://cede.store', '_blank')
throw new Error('Please, install cede.store to use this wallet')
Expand All @@ -24,24 +26,24 @@ function cedeStoreWallet(): WalletInit {
})

return Promise.resolve({
provider: createEIP1193Provider(window.cede, {
eth_requestAccounts: async ({ baseRequest }) => {
const accounts = (await baseRequest({
provider: createEIP1193Provider(provider, {
eth_requestAccounts: async () => {
const accounts = await provider.request({
method: 'connect'
})) as any[]
})

if (!accounts.length) {
return []
}

const activeVault = accounts.find(account => account.isActive)

return [activeVault?.name || accounts[0].name] as string[]
return [activeVault?.name || accounts[0].name]
},
eth_chainId: () => Promise.resolve('0x1'), // cede.store doesn't support chains, but we have to provide a value to complete the connection
wallet_switchEthereumChain: null,
wallet_addEthereumChain: null,
eth_getBalance: null,
eth_getBalance: () => Promise.resolve('0x0'),
eth_selectAccounts: null
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cede-store/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ExternalProvider } from '@ethersproject/providers'
export interface CustomWindow extends Window {
cede: ExternalProvider
}
}
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"webpack-dev-server": "4.7.4"
},
"dependencies": {
"@web3-onboard/cede-store": "^2.0.2",
"@web3-onboard/cede-store": "^2.1.0-alpha.1",
"@web3-onboard/blocto": "2.0.0",
"@web3-onboard/coinbase": "^2.2.5",
"@web3-onboard/core": "^2.20.4",
Expand Down
109 changes: 101 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,23 @@
web3 "^1.3.1"

"@blocto/sdk@^0.4.6":
version "0.4.6"
resolved "https://registry.yarnpkg.com/@blocto/sdk/-/sdk-0.4.6.tgz#7f18baa33fb9eb0ebc2ad3c00cf3a8d99ff20c9a"
integrity sha512-LekO1+ESAdUvQjOxEVyIhdr47/ZFWZCy9mVGFrIcEd8FsxbO5jScATl+rYpE7gZ0WlPbA03u8irg8eOLGp+gsA==
version "0.4.9"
resolved "https://registry.yarnpkg.com/@blocto/sdk/-/sdk-0.4.9.tgz#646cfea7737d8e5bb4c57885c0bb26d132185826"
integrity sha512-fscOaN4oux/7ySaNCQtltKLIefcZ7J85TpW/LKgAqfbEniBQ3z6SYxkG8ud6SPJs/camfljr+5hRdvcjTZCgGw==
dependencies:
bs58 "^5.0.0"
buffer "^6.0.3"
eip1193-provider "^1.0.1"
js-sha3 "^0.8.0"

"@cedelabs/providers@^0.0.7":
version "0.0.7"
resolved "https://registry.yarnpkg.com/@cedelabs/providers/-/providers-0.0.7.tgz#859070c5cf0a86841ce98d32c1599cc8de9b7869"
integrity sha512-rjOcEff5dnuKif+dJmEygCC/mp05oztkFYAmGEcGa1HW9EcVP3id1PTjBEYZLieVBNwJdg4kcl8Jh1dboG8pCA==
"@cedelabs/providers@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@cedelabs/providers/-/providers-1.1.0.tgz#94bb25a7010454c7ca5a486dc9644cbaeb87fada"
integrity sha512-A7r7Y3Ful69yDc674SCA/TxsjzO0zq2+Qlhr01QNnorNSoZdqEpwIfuLKiZD5PUFOAMxC8osTd0swyh+1IkGSg==
dependencies:
"@metamask/providers" "^8.1.1"
"@metamask/safe-event-emitter" "^3.0.0"
json-rpc-engine "^6.1.0"

"@chainsafe/as-sha256@^0.3.1":
version "0.3.1"
Expand Down Expand Up @@ -1618,6 +1622,15 @@
tweetnacl "^1.0.3"
tweetnacl-util "^0.15.1"

"@metamask/object-multiplex@^1.1.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@metamask/object-multiplex/-/object-multiplex-1.2.0.tgz#38fc15c142f61939391e1b9a8eed679696c7e4f4"
integrity sha512-hksV602d3NWE2Q30Mf2Np1WfVKaGqfJRy9vpHAmelbaD0OkDt06/0KQkRR6UVYdMbTbkuEu8xN5JDUU80inGwQ==
dependencies:
end-of-stream "^1.4.4"
once "^1.4.0"
readable-stream "^2.3.3"

"@metamask/obs-store@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@metamask/obs-store/-/obs-store-7.0.0.tgz#6cae5f28306bb3e83a381bc9ae22682316095bd3"
Expand All @@ -1626,6 +1639,24 @@
"@metamask/safe-event-emitter" "^2.0.0"
through2 "^2.0.3"

"@metamask/providers@^8.1.1":
version "8.1.1"
resolved "https://registry.yarnpkg.com/@metamask/providers/-/providers-8.1.1.tgz#7b0dbb54700c949aafba24c9b98e6f4e9d81f325"
integrity sha512-CG1sAuD6Mp4MZ5U90anf1FT0moDbStGXT+80TQFYXJbBeTQjhp321WgC/F2IgIJ3mFqOiByC3MQHLuunEVMQOA==
dependencies:
"@metamask/object-multiplex" "^1.1.0"
"@metamask/safe-event-emitter" "^2.0.0"
"@types/chrome" "^0.0.136"
detect-browser "^5.2.0"
eth-rpc-errors "^4.0.2"
extension-port-stream "^2.0.1"
fast-deep-equal "^2.0.1"
is-stream "^2.0.0"
json-rpc-engine "^6.1.0"
json-rpc-middleware-stream "^3.0.0"
pump "^3.0.0"
webextension-polyfill-ts "^0.25.0"

"@metamask/[email protected]", "@metamask/safe-event-emitter@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@metamask/safe-event-emitter/-/safe-event-emitter-2.0.0.tgz#af577b477c683fad17c619a78208cede06f9605c"
Expand Down Expand Up @@ -2801,6 +2832,14 @@
"@types/node" "*"
"@types/responselike" "^1.0.0"

"@types/chrome@^0.0.136":
version "0.0.136"
resolved "https://registry.yarnpkg.com/@types/chrome/-/chrome-0.0.136.tgz#7c011b9f997b0156f25a140188a0c5689d3f368f"
integrity sha512-XDEiRhLkMd+SB7Iw3ZUIj/fov3wLd4HyTdLltVszkgl1dBfc3Rb7oPMVZ2Mz2TLqnF7Ow+StbR8E7r9lqpb4DA==
dependencies:
"@types/filesystem" "*"
"@types/har-format" "*"

"@types/connect-history-api-fallback@^1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.3.5.tgz#d1f7a8a09d0ed5a57aee5ae9c18ab9b803205dae"
Expand Down Expand Up @@ -2868,6 +2907,18 @@
"@types/qs" "*"
"@types/serve-static" "*"

"@types/filesystem@*":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@types/filesystem/-/filesystem-0.0.32.tgz#307df7cc084a2293c3c1a31151b178063e0a8edf"
integrity sha512-Yuf4jR5YYMR2DVgwuCiP11s0xuVRyPKmz8vo6HBY3CGdeMj8af93CFZX+T82+VD1+UqHOxTq31lO7MI7lepBtQ==
dependencies:
"@types/filewriter" "*"

"@types/filewriter@*":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/filewriter/-/filewriter-0.0.29.tgz#a48795ecadf957f6c0d10e0c34af86c098fa5bee"
integrity sha512-BsPXH/irW0ht0Ji6iw/jJaK8Lj3FJemon2gvEqHKpCdDCeemHa+rI3WBGq5z7cDMZgoLjY40oninGxqk+8NzNQ==

"@types/glob-parent@^5.1.1":
version "5.1.1"
resolved "https://registry.yarnpkg.com/@types/glob-parent/-/glob-parent-5.1.1.tgz#eb83d64824374495437b450d45e24ec53a7ce844"
Expand All @@ -2881,6 +2932,11 @@
"@types/minimatch" "*"
"@types/node" "*"

"@types/har-format@*":
version "1.2.11"
resolved "https://registry.yarnpkg.com/@types/har-format/-/har-format-1.2.11.tgz#26aff34e9c782b2648cc45778abadcd930f7db43"
integrity sha512-T232/TneofqK30AD1LRrrf8KnjLvzrjWDp7eWST5KoiSzrBfRsLrWDPk4STQPW4NZG6v2MltnduBVmakbZOBIQ==

"@types/http-cache-semantics@*":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz#0ea7b61496902b95890dc4c3a116b60cb8dae812"
Expand Down Expand Up @@ -6018,7 +6074,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/detect-browser/-/detect-browser-5.2.0.tgz#c9cd5afa96a6a19fda0bbe9e9be48a6b6e1e9c97"
integrity sha512-tr7XntDAu50BVENgQfajMLzacmSe34D+qZc4zjnniz0ZVuw/TZcLcyxHQjYpJTM36sGEkZZlYLnIM1hH7alTMA==

[email protected]:
[email protected], detect-browser@^5.2.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/detect-browser/-/detect-browser-5.3.0.tgz#9705ef2bddf46072d0f7265a1fe300e36fe7ceca"
integrity sha512-53rsFbGdwMwlF7qvCt0ypLM5V5/Mbl0szB7GPN8y9NCcbknYOeVVXdrXEq+90IwAfrrzt6Hd+u2E2ntakICU8w==
Expand Down Expand Up @@ -7248,6 +7304,13 @@ extend@~3.0.2:
resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.2.tgz#f8b1136b4071fbd8eb140aff858b1019ec2915fa"
integrity sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==

extension-port-stream@^2.0.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/extension-port-stream/-/extension-port-stream-2.1.1.tgz#ec11f2a5ed95655d8c40805d7cb0c39939ee9ef4"
integrity sha512-qknp5o5rj2J9CRKfVB8KJr+uXQlrojNZzdESUPhKYLXf97TPcGf6qWWKmpsNNtUyOdzFhab1ON0jzouNxHHvow==
dependencies:
webextension-polyfill ">=0.10.0 <1.0"

[email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
Expand All @@ -7270,6 +7333,11 @@ fake-merkle-patricia-tree@^1.0.1:
dependencies:
checkpoint-store "^1.1.0"

fast-deep-equal@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==

fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
Expand Down Expand Up @@ -8582,6 +8650,14 @@ json-rpc-engine@^5.3.0:
eth-rpc-errors "^3.0.0"
safe-event-emitter "^1.0.1"

json-rpc-middleware-stream@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/json-rpc-middleware-stream/-/json-rpc-middleware-stream-3.0.0.tgz#8540331d884f36b9e0ad31054cc68ac6b5a89b52"
integrity sha512-JmZmlehE0xF3swwORpLHny/GvW3MZxCsb2uFNBrn8TOqMqivzCfz232NSDLLOtIQlrPlgyEjiYpyzyOPFOzClw==
dependencies:
"@metamask/safe-event-emitter" "^2.0.0"
readable-stream "^2.3.3"

json-rpc-random-id@^1.0.0, json-rpc-random-id@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-rpc-random-id/-/json-rpc-random-id-1.0.1.tgz#ba49d96aded1444dbb8da3d203748acbbcdec8c8"
Expand Down Expand Up @@ -12974,13 +13050,30 @@ web3@^1.3.1:
web3-shh "1.10.0"
web3-utils "1.10.0"

webextension-polyfill-ts@^0.25.0:
version "0.25.0"
resolved "https://registry.yarnpkg.com/webextension-polyfill-ts/-/webextension-polyfill-ts-0.25.0.tgz#fff041626365dbd0e29c40b197e989a55ec221ca"
integrity sha512-ikQhwwHYkpBu00pFaUzIKY26I6L87DeRI+Q6jBT1daZUNuu8dSrg5U9l/ZbqdaQ1M/TTSPKeAa3kolP5liuedw==
dependencies:
webextension-polyfill "^0.7.0"

webextension-polyfill-ts@^0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/webextension-polyfill-ts/-/webextension-polyfill-ts-0.26.0.tgz#80b7063ddaf99abaa1ca73aad0cec09f306612d3"
integrity sha512-XEFL+aYVEsm/d4RajVwP75g56c/w2aSHnPwgtUv8/nCzbLNSzRQIix6aj1xqFkA5yr7OIDkk3OD/QTnPp8ThYA==
dependencies:
webextension-polyfill "^0.8.0"

"webextension-polyfill@>=0.10.0 <1.0":
version "0.10.0"
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.10.0.tgz#ccb28101c910ba8cf955f7e6a263e662d744dbb8"
integrity sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g==

webextension-polyfill@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.7.0.tgz#0df1120ff0266056319ce1a622b09ad8d4a56505"
integrity sha512-su48BkMLxqzTTvPSE1eWxKToPS2Tv5DLGxKexLEVpwFd6Po6N8hhSLIvG6acPAg7qERoEaDL+Y5HQJeJeml5Aw==

webextension-polyfill@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/webextension-polyfill/-/webextension-polyfill-0.8.0.tgz#f80e9f4b7f81820c420abd6ffbebfa838c60e041"
Expand Down

0 comments on commit 2f3fd79

Please sign in to comment.