@orderly.network/default-evm-adapter
Version:
2 lines • 6.17 kB
JavaScript
var T=Object.defineProperty,R=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable;var M=(i,s,e)=>s in i?T(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e,g=(i,s)=>{for(var e in s||(s={}))O.call(s,e)&&M(i,e,s[e]);if(D)for(var e of D(s))x.call(s,e)&&M(i,e,s[e]);return i},u=(i,s)=>R(i,_(s));var I=(i,s,e)=>(M(i,typeof s!="symbol"?s+"":s,e),e);var m=(i,s,e)=>new Promise((t,n)=>{var a=o=>{try{c(e.next(o))}catch(d){n(d)}},r=o=>{try{c(e.throw(o))}catch(d){n(d)}},c=o=>o.done?t(o.value):Promise.resolve(o.value).then(a,r);c((e=e.apply(i,s)).next())});typeof window!="undefined"&&(window.__ORDERLY_VERSION__=window.__ORDERLY_VERSION__||{},window.__ORDERLY_VERSION__["@orderly.network/default-evm-adapter"]="2.7.2");var A="2.7.2";import*as C from"@noble/ed25519";import{encode as K}from"bs58";import{BaseWalletAdapter as V}from"@orderly.network/core";import{ChainNamespace as k}from"@orderly.network/types";import{DEFAUL_ORDERLY_KEY_SCOPE as N,definedTypes as p}from"@orderly.network/types";function w(i){return m(this,null,function*(){let{chainId:s,receiver:e,token:t,amount:n,nonce:a,brokerId:r,domain:c}=i,o="Withdraw",d=Date.now(),y={EIP712Domain:p.EIP712Domain,[o]:p[o]},h={brokerId:r,chainId:s,receiver:e,token:t,amount:n,timestamp:d,withdrawNonce:a};return[h,{domain:c,message:h,primaryType:o,types:y}]})}function v(i){return m(this,null,function*(){let{chainId:s,receiver:e,token:t,amount:n,nonce:a,domain:r}=i,c="InternalTransfer",o={EIP712Domain:p.EIP712Domain,[c]:p[c]},d={chainId:s,receiver:e,token:t,amount:n,transferNonce:a};return[d,{domain:r,message:d,primaryType:c,types:o}]})}function P(i){return m(this,null,function*(){let{publicKey:s,chainId:e,brokerId:t,expiration:n=365,timestamp:a=Date.now(),scope:r,tag:c,domain:o,subAccountId:d}=i,y="AddOrderlyKey",h=g(g({brokerId:t,orderlyKey:s,scope:r||N,chainId:e,timestamp:a,expiration:a+1e3*60*60*24*n},typeof c!="undefined"?{tag:c}:{}),typeof d!="undefined"?{subAccountId:d}:{}),l={EIP712Domain:p.EIP712Domain,[y]:p[y]};return[h,{domain:o,message:h,primaryType:y,types:l}]})}function S(i){return m(this,null,function*(){let{chainId:s,domain:e,registrationNonce:t,brokerId:n,timestamp:a}=i,r="Registration",c={brokerId:n,chainId:s,timestamp:a,registrationNonce:t},o={EIP712Domain:p.EIP712Domain,[r]:p[r]};return[c,{domain:e,message:c,primaryType:r,types:o}]})}function b(i){return m(this,null,function*(){let{settlePnlNonce:s,brokerId:e,chainId:t,timestamp:n,domain:a}=i,r="SettlePnl",c={EIP712Domain:p.EIP712Domain,[r]:p[r]},o={brokerId:e,chainId:t,timestamp:n,settleNonce:s};return[o,{domain:a,message:o,primaryType:r,types:c}]})}function E(i){return m(this,null,function*(){let{payloadType:s,nonce:e,receiver:t,amount:n,vaultId:a,token:r,dexBrokerId:c,domain:o}=i,d="DexRequest",y={EIP712Domain:p.EIP712Domain,[d]:p[d]},h={payloadType:s,nonce:e,receiver:t,amount:n,vaultId:a,token:r,dexBrokerId:c};return[h,{domain:o,message:h,primaryType:d,types:y}]})}var f=class extends V{constructor(e){super();this.web3Provider=e;I(this,"chainNamespace",k.evm);I(this,"_address");I(this,"_chainId");I(this,"contractManager")}get address(){return this._address}get chainId(){return this._chainId}set chainId(e){this._chainId=e}setConfig(e){if(this._address=e.address,this._chainId=e.chain.id,e.provider&&(this.web3Provider.provider=e.provider),e.contractManager)this.contractManager=e.contractManager;else throw new Error("Please provide contract manager class")}active(e){this.setConfig(e),this.lifecycleName("active",e)}deactivate(){this.lifecycleName("deactivate",{})}update(e){this.lifecycleName("update",e),this.setConfig(e)}generateSecretKey(){let e,t;do e=C.utils.randomPrivateKey(),t=K(e);while(t.length!==44);return t}lifecycleName(e,t){console.log("lifecycle",e,t)}signTypedData(e){return m(this,null,function*(){return console.log("toSignatureMessage",this.address),yield this.web3Provider.signTypedData(this.address,JSON.stringify(e))})}generateRegisterAccountMessage(e){return m(this,null,function*(){let[t,n]=yield S(u(g({},e),{chainId:this.chainId,domain:this.getDomain()})),a=yield this.signTypedData(n);return{message:u(g({},t),{chainType:"EVM"}),signatured:a}})}generateAddOrderlyKeyMessage(e){return m(this,null,function*(){let[t,n]=yield P(u(g({},e),{chainId:this.chainId,domain:this.getDomain()})),a=yield this.signTypedData(n);return{message:u(g({},t),{chainType:"EVM"}),signatured:a}})}generateWithdrawMessage(e){return m(this,null,function*(){let t=this.getDomain(!0),[n,a]=yield w(u(g({},e),{chainId:this.chainId,domain:t})),r=yield this.signTypedData(a);return{message:u(g({},n),{chainType:"EVM"}),signatured:r,domain:t}})}generateInternalTransferMessage(e){return m(this,null,function*(){let t=this.getDomain(!0),[n,a]=yield v(u(g({},e),{chainId:this.chainId,domain:t})),r=yield this.signTypedData(a);return{message:u(g({},n),{chainType:"EVM"}),signatured:r,domain:t}})}generateSettleMessage(e){return m(this,null,function*(){let t=this.getDomain(!0),[n,a]=yield b(u(g({},e),{chainId:this.chainId,domain:t})),r=yield this.signTypedData(a);return{message:u(g({},n),{chainType:"EVM"}),signatured:r,domain:t}})}generateDexRequestMessage(e){return m(this,null,function*(){let[t,n]=yield E(u(g({},e),{chainId:this.chainId})),a=yield this.signTypedData(n);return{message:u(g({},t),{chainType:"EVM"}),signatured:a,domain:e.domain}})}getBalance(){return this.web3Provider.getBalance(this.address)}call(e,t,n,a){return this.web3Provider.call(e,t,n,a)}sendTransaction(e,t,n,a){return this.web3Provider.sendTransaction(e,t,n,a)}callOnChain(e,t,n,a,r){return this.web3Provider.callOnChain(e,t,n,a,r)}getDomain(e){if(!this.web3Provider)throw new Error("web3Provider is undefined");return{name:"Orderly",version:"1",chainId:this.chainId,verifyingContract:e?this.contractManager.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}pollTransactionReceiptWithBackoff(e,t,n,a){return this.web3Provider.pollTransactionReceiptWithBackoff(e,t,n,a)}};export{f as DefaultEVMWalletAdapter,A as version};
//# sourceMappingURL=index.mjs.map